1
0
mirror of https://github.com/mgcaret/of816.git synced 2024-12-26 13:31:54 +00:00

Initial Open Firmware

This commit is contained in:
mgcaret 2020-11-05 17:43:47 -08:00
parent b196f2eb3b
commit c15c67f8dc
17 changed files with 2898 additions and 3 deletions

4
.gitignore vendored
View File

@ -16,4 +16,6 @@ platforms/GoSXB/rom
platforms/GoSXB/romfs
platforms/GoSXB/romfs_files/OF
cov.yml
of/out
platforms/GoSXB/romfs_files/bench
platforms/GoSXB/romfs_files/of.fs

16
ofw/README.md Normal file
View File

@ -0,0 +1,16 @@
# Open Firmware for OF816
This directory contains Forth source implementing Open Firmware on top of
OF816. It is based on IBM's [Slimline Open Firmware](https://github.com/aik/SLOF)
that is notably used in IBM POWER systems and QEMU.
**There are Bugs**
The build script borrows tricks from SLOF to incorporate the C preprocessor
and remove comments and extra lines from the code, producing a single file
that can be used with EVALUATE.
SLOF is licensed under a BSD license, and since the files in this directory
are a derivative work, the license is reproduced in this directory as
SLOF-LICENSE.

8
ofw/SLOF-LICENSE Normal file
View File

@ -0,0 +1,8 @@
Copyright (c) 2004, 2008 IBM Corporation
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

14
ofw/build.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
set -ex
cd `dirname $0`
mkdir -p out
cpp -w -nostdinc -traditional-cpp -undef -P -C -I. of.fs > out/of-blob.tmp
sed -e 's/^[ ]*//' < out/of-blob.tmp \
| sed -e '/^\\[ ]/d' \
| sed -e '/^([ ][^)]*[ ])[ ]*$$/d' \
| sed -e '/^$$/d' \
| cat -s > out/of-blob.fs
rm -f out/of-blob.tmp

9
ofw/of.fs Normal file
View File

@ -0,0 +1,9 @@
also forth definitions
#include <of/base.fs>
#include <of/of-words.fs>
#include <of/node.fs>
#include <of/root.fs>
previous definitions
banner

109
ofw/of/base.fs Normal file
View File

@ -0,0 +1,109 @@
true value of-verbose?
\ For some debug output...
: dbexec ( ... xt - ... ) of-verbose? if execute else drop then ;
: dbcr ( - ) of-verbose? if cr then ;
: dbtype ( addr u - ) of-verbose? if type else 2drop then ;
: db" ( string<"> ) ascii " parse dbtype cr ; immediate
db" OF base"
\ Reverse engineer the leading JSLs for these words
: (function) ;
defer (defer)
0 value (value)
0 constant (constant)
variable (variable)
create (create)
alias (alias) (function)
/n buffer: (buffer:)
\ Note OF816 xts are 1 less than the address of the code
\ All of these should have 0x22 in the low byte, except ; and ALIAS
\ ALIAS will have 5C in the low byte, and we maybe need to fix that...
\ in SLOF most of these are only used by the debug.fs
\ except the ones needed to support instance values
' (function) 1+ @ \ ( <colon> )
' (function) 1+ /n + @ \ ( ... <semicolon> )
' (defer) 1+ @ \ ( ... <defer> )
' (value) 1+ @ \ ( ... <value> )
' (constant) 1+ @ \ ( ... <constant> )
' (variable) 1+ @ \ ( ... <variable> )
' (create) 1+ @ \ ( ... <create> )
' (alias) 1+ @ \ ( ... <alias> )
' (buffer:) 1+ @ \ ( ... <buffer:> )
\ now clean up the test functions
forget (function)
\ and remember the constants
constant <buffer:>
constant <alias>
constant <create>
constant <variable>
constant <constant>
constant <value>
constant <defer>
constant <semicolon>
constant <colon>
: 2variable create 2 cells allot ;
: cell- /n - ;
\ Dictionary helpers
: lfa>name cell+ dup 1+ swap c@ 7f and ;
: lfa>xt lfa>name + ;
: xt>lfa begin 1- dup c@ 80 and until cell- ;
: 4drop 2drop 2drop ;
: c@+ ( adr -- c adr' ) dup c@ swap char+ ;
: 4c@ ( adr -- c1 c2 c3 c4 ) c@+ c@+ c@+ c@ ;
\ clever hack
defer voc-find
' search-wordlist 1+ cell+ @ to voc-find
: 0.r 0 swap <# 0 ?DO # LOOP #> type ;
CREATE $catpad 400 allot
: $cat ( str1 len1 str2 len2 -- str3 len3 )
>r >r dup >r $catpad swap move
r> dup $catpad + r> swap r@ move
r> + $catpad swap ;
\ WARNING: The following $cat-space is dirty in a sense that it adds one
\ character to str1 before executing $cat.
\ The ASSUMPTION is that str1 buffer provides that extra space and it is
\ responsibility of the code owner to ensure that
: $cat-space ( str2 len2 str1 len1 -- "str1 str2" len1+len2+1 )
2dup + bl swap c! 1+ 2swap $cat
;
: $cathex ( str len val -- str len' )
(u.) $cat
;
: str= ( str len str len )
2 pick over = if
drop swap comp 0=
else
2drop 2drop false
then
;
: string=ci ( str len str len )
2 pick over = if
drop swap cicomp 0=
else
2drop 2drop false
then
;
: strdup ( str len -- dupstr len ) here over allot swap 2dup 2>r move 2r> ;
: findchar left-parse-string nip nip swap if true else drop false then ;
#include <of/preprocessor.fs>

197
ofw/of/instance.fs Normal file
View File

@ -0,0 +1,197 @@
\ *****************************************************************************
\ * Copyright (c) 2004, 2011 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ * IBM Corporation - initial implementation
\ ****************************************************************************/
db" OF instance support (c) IBM"
\ Support for device node instances.
0 VALUE my-self
100 CONSTANT max-instance-size \ MAG: originally 400
STRUCT
/n FIELD instance>node
/n FIELD instance>parent
/n FIELD instance>args
/n FIELD instance>args-len
/n FIELD instance>size
/n FIELD instance>#units
/n FIELD instance>unit1 \ For instance-specific "my-unit"
/n FIELD instance>unit2
/n FIELD instance>unit3
/n FIELD instance>unit4
CONSTANT /instance-header
: >instance ( offset -- myself+offset )
my-self 0= ABORT" No instance!"
dup my-self instance>size @ >= ABORT" Instance access out of bounds!"
my-self +
;
: (create-instance-var) ( initial-value -- )
get-node
dup node>instance-size @ cell+ max-instance-size
>= ABORT" Instance is bigger than max-instance-size!"
dup node>instance-template @ ( iv phandle tmp-ih )
swap node>instance-size dup @ ( iv tmp-ih *instance-size instance-size )
dup , \ compile current instance ptr
swap 1 cells swap +! ( iv tmp-ih instance-size )
+ !
;
: create-instance-var ( "name" initial-value -- )
CREATE (create-instance-var) PREVIOUS
;
: (create-instance-buf) ( buffersize -- )
aligned \ align size to multiples of cells
dup get-node node>instance-size @ + ( buffersize' newinstancesize )
max-instance-size > ABORT" Instance is bigger than max-instance-size!"
get-node node>instance-template @ get-node node>instance-size @ +
over erase \ clear according to IEEE 1275
get-node node>instance-size @ ( buffersize' old-instance-size )
dup , \ compile current instance ptr
+ get-node node>instance-size ! \ store new size
;
: create-instance-buf ( "name" buffersize -- )
CREATE (create-instance-buf) PREVIOUS
;
VOCABULARY instance-words ALSO instance-words DEFINITIONS
: VARIABLE 0 create-instance-var DOES> [ here ] @ >instance ;
: VALUE create-instance-var DOES> [ here ] @ >instance @ ;
: DEFER 0 create-instance-var DOES> [ here ] @ >instance @ execute ;
: BUFFER: create-instance-buf DOES> [ here ] @ >instance ;
PREVIOUS DEFINITIONS
\ Save XTs of the above instance-words (put on the stack with "[ here ]")
CONSTANT <instancebuffer>
CONSTANT <instancedefer>
CONSTANT <instancevalue>
CONSTANT <instancevariable>
\ check whether a value or a defer word is an
\ instance word: It must be a CREATE word and
\ the DOES> part must do >instance as first thing
\ rewritten for OF816 by MAG
: (instance?) ( xt -- xt true|false )
dup 1+ @ dup ff and
22 = IF
8 rshift 3 na+ @ ['] >instance =
ELSE
drop false
THEN
;
\ This word does instance values in compile mode.
\ It corresponds to DOTO from engine.in
\ MAG: 1+ added because OF816 XTs and return addresses are one less...
: (doito) ( value R:*CFA -- )
r> cell+ dup >r 1+ ( MAG )
@ cell+ cell+ @ >instance !
;
' (doito) CONSTANT <(doito)>
\ Modified by MAG
: to ( value wordname<> -- )
' (instance?)
IF ( value xt )
state @ IF
['] (doito) , , \ compile mode handling instance value
ELSE
cell+ cell+ @ >instance ! \ interp mode instance value
THEN EXIT
ELSE
state @ IF ( value xt )
postpone literal compile (to)
ELSE
(to)
THEN
THEN
; IMMEDIATE
: behavior ( defer-xt -- contents-xt )
dup cell+ @ <instancedefer> = IF \ Is defer-xt an INSTANCE DEFER ?
2 cells + @ >instance @
ELSE
behavior
THEN
;
: INSTANCE ALSO instance-words ;
: my-parent my-self instance>parent @ ;
: my-args my-self instance>args 2@ swap ;
\ copy args from original instance to new created
: set-my-args ( old-addr len -- )
dup alloc-mem \ allocate space for new args ( old-addr len new-addr )
2dup my-self instance>args 2! \ write into instance struct ( old-addr len new-addr )
swap move \ and copy the args ( )
;
\ Current node has already been set, when this is called.
: create-instance-data ( -- instance )
get-node dup node>instance-template @ ( phandle instance-template )
swap node>instance-size @ ( instance-template instance-size )
dup >r
dup alloc-mem dup >r swap move r> ( instance )
dup instance>size r> swap ! \ Store size for destroy-instance
dup instance>#units 0 swap ! \ Use node unit by default
;
: create-instance ( -- )
my-self create-instance-data
dup to my-self instance>parent !
get-node my-self instance>node !
;
: destroy-instance ( instance -- )
dup instance>args @ ?dup IF \ Free instance args?
over instance>args-len @ free-mem
THEN
dup instance>size @ free-mem
;
: ihandle>phandle ( ihandle -- phandle )
dup 0= ABORT" no current instance" instance>node @
;
: push-my-self ( ihandle -- ) r> my-self >r >r to my-self ;
: pop-my-self ( -- ) r> r> to my-self >r ;
: call-package push-my-self execute pop-my-self ;
: $call-static ( ... str len node -- ??? )
\ cr ." call for " 3dup -rot type ." on node " .
find-method IF execute ELSE -1 throw THEN
;
: $call-my-method ( str len -- )
my-self ihandle>phandle $call-static
;
: $call-method ( str len ihandle -- )
push-my-self
['] $call-my-method CATCH ?dup IF
pop-my-self THROW
THEN
pop-my-self
;
0 VALUE calling-child
: $call-parent
my-self ihandle>phandle TO calling-child
my-parent $call-method
0 TO calling-child
;

774
ofw/of/node.fs Normal file
View File

@ -0,0 +1,774 @@
\ Derived from IBM SLOF, modified by Michael Guidero
\ *****************************************************************************
\ * Copyright (c) 2004, 2008 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ * IBM Corporation - initial implementation
\ ****************************************************************************/
db" OF device node support (c) IBM"
false VALUE debug-find-component?
VARIABLE device-tree
VARIABLE current-node
: get-node current-node @ dup 0= ABORT" No active device tree node" ;
STRUCT
/n FIELD node>peer
/n FIELD node>parent
/n FIELD node>child
/n FIELD node>properties \ points to wid (grep wid>names)
/n FIELD node>words
/n FIELD node>instance-template
/n FIELD node>instance-size
/n FIELD node>space?
/n FIELD node>space
/n FIELD node>addr1
/n FIELD node>addr2
/n FIELD node>addr3
constant (node-size)
\ Original:
\ : find-method ( str len phandle -- false | xt true )
\ node>words @ voc-find dup IF link> true THEN ;
\ : find-method ( str len phandle -- false | xt true )
\ node>words @ search-wordlist IF true THEN ;
: find-method ( str len phandle -- false | xt true )
node>words @ voc-find dup IF true THEN ;
\ Instances.
#include <of/instance.fs>
db" OF - back to device tree"
: create-node ( parent -- new )
max-instance-size alloc-mem ( parent instance-mem )
dup max-instance-size erase >r ( parent R: instance-mem )
align wordlist >r $empty-wl >r ( parent R: instance-mem wl wl )
here ( parent new R: instance-mem wl wl )
0 , swap , 0 , \ Set node>peer, node>parent & node>child
r> , r> , \ Set node>properties & node>words to wl
r> , /instance-header , \ Set instance-template & instance-size
FALSE , 0 , \ Set node>space? and node>space
0 , 0 , 0 , \ Set node>addr*
;
: peer node>peer @ ;
: parent node>parent @ ;
: child node>child @ ;
: peer dup IF peer ELSE drop device-tree @ THEN ;
: link ( new head -- ) \ link a new node at the end of a linked list
BEGIN dup @ WHILE @ REPEAT ! ;
: link-node ( parent child -- )
swap dup IF node>child link ELSE drop device-tree ! THEN ;
\ Set a node as active node.
: set-node ( phandle -- )
current-node @ IF previous THEN
dup current-node !
?dup IF node>words @ also context ! THEN
definitions ;
: get-parent get-node parent ;
: new-node ( -- phandle ) \ active node becomes new node's parent;
\ new node becomes active node
\ XXX: change to get-node, handle root node creation specially
current-node @ dup create-node
tuck link-node dup set-node ;
: finish-node ( -- )
\ TODO: maybe resize the instance template buffer here (or in finish-device)?
get-node parent set-node
;
: device-end ( -- ) 0 set-node ;
\ Properties.
CREATE $indent 100 allot VARIABLE indent 0 indent !
#include <of/property.fs>
db" OF - back to device tree"
\ Unit address.
: #address-cells s" #address-cells" rot parent get-property
ABORT" parent doesn't have a #address-cells property!"
decode-int nip nip
;
\ my-#address-cells returns the #address-cells property of the parent node.
\ child-#address-cells returns the #address-cells property of the current node.
\ This is confusing in several ways: Remember that a node's address is always
\ described in the parent's address space, thus the parent's property is taken
\ into regard, rather than the own.
\ Also, an address-cell here is always a 32bit cell, no matter whether the
\ "real" cell size is 32bit or 64bit.
: my-#address-cells ( -- #address-cells )
get-node #address-cells
;
: child-#address-cells ( -- #address-cells )
s" #address-cells" get-node get-property
ABORT" node doesn't have a #address-cells property!"
decode-int nip nip
;
: child-#size-cells ( -- #address-cells )
s" #size-cells" get-node get-property
ABORT" node doesn't have a #size-cells property!"
decode-int nip nip
;
: encode-phys ( phys.hi ... phys.low -- prop len )
encode-first? IF encode-start ELSE here 0 THEN
my-#address-cells 0 ?DO rot encode-int+ LOOP
;
: encode-child-phys ( phys.hi ... phys.low -- prop len )
encode-first? IF encode-start ELSE here 0 THEN
child-#address-cells 0 ?DO rot encode-int+ LOOP
;
: encode-child-size ( size.hi ... size.low -- prop len )
encode-first? IF encode-start ELSE here 0 THEN
child-#size-cells 0 ?DO rot encode-int+ LOOP
;
: decode-phys
my-#address-cells BEGIN dup WHILE 1- >r decode-int r> swap >r REPEAT drop
my-#address-cells BEGIN dup WHILE 1- r> swap REPEAT drop ;
: decode-phys-and-drop
my-#address-cells BEGIN dup WHILE 1- >r decode-int r> swap >r REPEAT 3drop
my-#address-cells BEGIN dup WHILE 1- r> swap REPEAT drop ;
: reg >r encode-phys r> encode-int+ s" reg" property ;
: >space node>space @ ;
: >space? node>space? @ ;
: >address dup >r #address-cells dup 3 > IF r@ node>addr3 @ swap THEN
dup 2 > IF r@ node>addr2 @ swap THEN
1 > IF r@ node>addr1 @ THEN r> drop ;
: >unit dup >r >address r> >space ;
: (my-phandle) ( -- phandle )
my-self ?dup IF
ihandle>phandle
ELSE
get-node dup 0= ABORT" no active node"
THEN
;
: my-space ( -- phys.hi )
(my-phandle) >space
;
: my-address (my-phandle) >address ;
\ my-unit returns the unit address of the current _instance_ - that means
\ it returns the same values as my-space and my-address together _or_ it
\ returns a unit address that has been set manually while opening the node.
: my-unit
my-self instance>#units @ IF
0 my-self instance>#units @ 1- DO
my-self instance>unit1 i cells + @
-1 +LOOP
ELSE
my-self ihandle>phandle >unit
THEN
;
\ Return lower 64 bit of address
: my-unit-64 ( -- phys.lo+1|phys.lo )
my-unit ( phys.lo ... phys.hi )
(my-phandle) #address-cells ( phys.lo ... phys.hi #ad-cells )
CASE
1 OF EXIT ENDOF
\ 2 OF lxjoin EXIT ENDOF
\ 3 OF drop lxjoin EXIT ENDOF
\ dup OF 2drop lxjoin EXIT ENDOF
ENDCASE
;
: set-space get-node dup >r node>space ! true r> node>space? ! ;
: set-address my-#address-cells 1 ?DO
get-node node>space i cells + ! LOOP ;
: set-unit set-space set-address ;
\ : set-unit-64 ( phys.lo|phys.hi -- )
\ my-#address-cells 2 <> IF
\ ." set-unit-64: #address-cells <> 2 " abort
\ THEN
\ xlsplit set-unit
\ ;
\ Never ever use this in actual code, only when debugging interactively.
\ Thank you.
: set-args ( arg-str len unit-str len -- )
s" decode-unit" get-parent $call-static set-unit set-my-args
;
: $cat-unit
dup parent 0= IF drop EXIT THEN
dup >space? not IF drop EXIT THEN
dup >r >unit s" encode-unit" r> parent $call-static
dup IF
dup >r here swap move s" @" $cat here r> $cat
ELSE
2drop
THEN
;
: $cat-instance-unit
dup parent 0= IF drop EXIT THEN
\ No instance unit, use node unit
dup instance>#units @ 0= IF
ihandle>phandle $cat-unit
EXIT
THEN
dup >r push-my-self
['] my-unit CATCH IF pop-my-self r> drop EXIT THEN
pop-my-self
s" encode-unit"
r> ihandle>phandle parent
$call-static
dup IF
dup >r here swap move s" @" $cat here r> $cat
ELSE
2drop
THEN
;
\ Getting basic info about a node.
: node>name dup >r s" name" rot get-property IF r> (u.) ELSE 1- r> drop THEN ;
: node>qname dup node>name rot ['] $cat-unit CATCH IF drop THEN ;
: node>path
here 0 rot
BEGIN dup WHILE dup parent REPEAT
2drop
dup 0= IF [char] / c, THEN
BEGIN
dup
WHILE
[char] / c, node>qname here over allot swap move
REPEAT
drop here 2dup - allot over -
;
: interposed? ( ihandle -- flag )
\ We cannot actually detect if an instance is interposed; instead, we look
\ if an instance is part of the "normal" chain that would be opened by
\ open-dev and friends, if there were no interposition.
dup instance>parent @ dup 0= IF 2drop false EXIT THEN
ihandle>phandle swap ihandle>phandle parent <> ;
: instance>qname
dup >r interposed? IF s" %" ELSE 0 0 THEN
r@ dup ihandle>phandle node>name
rot ['] $cat-instance-unit CATCH IF drop THEN
$cat r> instance>args 2@ swap
dup IF 2>r s" :" $cat 2r> $cat ELSE 2drop THEN
;
: instance>qpath \ With interposed nodes.
here 0 rot BEGIN dup WHILE dup instance>parent @ REPEAT 2drop
dup 0= IF [char] / c, THEN
BEGIN dup WHILE [char] / c, instance>qname here over allot swap move
REPEAT drop here 2dup - allot over - ;
: instance>path \ Without interposed nodes.
here 0 rot BEGIN dup WHILE
dup interposed? 0= IF dup THEN instance>parent @ REPEAT 2drop
dup 0= IF [char] / c, THEN
BEGIN dup WHILE [char] / c, instance>qname here over allot swap move
REPEAT drop here 2dup - allot over - ;
: .node node>path type ;
: pwd get-node .node ;
: .instance instance>qpath type ;
: .chain dup instance>parent @ ?dup IF recurse THEN
cr dup . instance>qname type ;
\ Alias helper
defer find-node
: set-alias ( alias-name len device-name len -- )
encode-string
2swap s" /aliases" find-node ?dup IF
set-property
ELSE
4drop
THEN
;
: find-alias ( alias-name len -- false | dev-path len )
s" /aliases" find-node dup IF
get-property 0= IF 1- dup 0= IF nip THEN ELSE false THEN
THEN
;
: .alias ( alias-name len -- )
find-alias dup IF type ELSE ." no alias available" THEN ;
: (.print-alias) ( lfa -- )
dup >name
\ Don't print name property
2dup s" name" string=ci IF 2drop drop
ELSE cr type space ." : " execute type
THEN ;
: (.list-alias) ( phandle -- )
node>properties @ cell+ @ BEGIN dup WHILE dup (.print-alias) @ REPEAT drop ;
: list-alias ( -- )
s" /aliases" find-node dup IF (.list-alias) THEN ;
\ return next available name for aliasing or
\ false if more than MAX-ALIAS aliases found
d# 10 CONSTANT MAX-ALIAS
1 VALUE alias-ind
: get-next-alias ( $alias-name -- $next-alias-name|FALSE )
2dup find-alias IF
drop
1 TO alias-ind
BEGIN
2dup alias-ind $cathex 2dup find-alias
WHILE
drop 2drop
alias-ind 1 + TO alias-ind
alias-ind MAX-ALIAS = IF
2drop FALSE EXIT
THEN
REPEAT
strdup 2swap 2drop
THEN
;
: devalias ( "{alias-name}<>{device-specifier}<cr>" -- )
parse-word parse-word dup IF set-alias
ELSE 2drop dup IF .alias
ELSE 2drop list-alias THEN THEN ;
\ sub-alias does a single iteration of an alias at the beginning od dev path
\ expression. de-alias will repeat this until all indirect alising is resolved
: sub-alias ( arg-str arg-len -- arg' len' | false )
2dup
2dup [char] / findchar ?dup IF ELSE 2dup [char] : findchar THEN
( a l a l [p] -1|0 ) IF nip dup ELSE 2drop 0 THEN >r
( a l l p -- R:p | a l -- R:0 )
find-alias ?dup IF ( a l a' p' -- R:p | a' l' -- R:0 )
r@ IF
2swap r@ - swap r> + swap $cat strdup ( a" l-p+p' -- )
ELSE
( a' l' -- R:0 ) r> drop ( a' l' -- )
THEN
ELSE
( a l -- R:p | -- R:0 ) r> IF 2drop THEN
false ( 0 -- )
THEN
;
: de-alias ( arg-str arg-len -- arg' len' )
BEGIN
over c@ [char] / <> dup IF drop 2dup sub-alias ?dup THEN
WHILE
2swap 2drop
REPEAT
;
\ Display the device tree.
: +indent ( not-last? -- )
IF s" | " ELSE s" " THEN $indent indent @ + swap move 4 indent +! ;
: -indent ( -- ) -4 indent +! ;
: ls-phandle ( node -- ) . ." : " ;
: ls-node ( node -- )
cr dup ls-phandle
$indent indent @ type
dup peer IF ." |-- " ELSE ." +-- " THEN
node>qname type
;
: (ls) ( node -- )
child BEGIN dup WHILE dup ls-node dup child IF
dup peer +indent dup recurse -indent THEN peer REPEAT drop ;
: ls ( -- )
get-node cr
dup ls-phandle
dup node>path type
(ls)
0 indent !
;
: show-devs ( {device-specifier}<eol> -- )
parse-word dup IF de-alias ELSE 2drop s" /" THEN ( str len )
find-node dup 0= ABORT" No such device path" (ls)
;
VARIABLE interpose-node
2VARIABLE interpose-args
: interpose ( arg len phandle -- ) interpose-node ! interpose-args 2! ;
0 VALUE user-instance-#units
CREATE user-instance-units 4 cells allot
\ Copy the unit information (specified by the user) that we've found during
\ "find-component" into the current instance data structure
: copy-instance-unit ( -- )
user-instance-#units IF
user-instance-#units my-self instance>#units !
user-instance-units my-self instance>unit1 user-instance-#units cells move
0 to user-instance-#units
THEN
;
: open-node ( arg len phandle -- ihandle|0 )
current-node @ >r my-self >r \ Save current node and instance
set-node create-instance set-my-args
copy-instance-unit
\ Execute "open" method if available, and assume default of
\ success (=TRUE) for nodes without open method:
s" open" get-node find-method IF execute ELSE TRUE THEN
0= IF
my-self destroy-instance 0 to my-self
THEN
my-self ( ihandle|0 )
r> to my-self r> set-node \ Restore current node and instance
\ Handle interposition:
interpose-node @ IF
my-self >r to my-self
interpose-args 2@ interpose-node @
interpose-node off recurse
r> to my-self
THEN
;
: close-node ( ihandle -- )
my-self >r to my-self
s" close" ['] $call-my-method CATCH IF 2drop THEN
my-self destroy-instance r> to my-self ;
: close-dev ( ihandle -- )
my-self >r to my-self
BEGIN my-self WHILE my-parent my-self close-node to my-self REPEAT
r> to my-self ;
: new-device ( -- )
[: ." New device: " ;] dbexec \ OF816 debug
my-self new-node ( parent-ihandle phandle )
node>instance-template @ ( parent-ihandle ihandle )
dup to my-self ( parent-ihanlde ihandle )
instance>parent !
get-node my-self instance>node !
max-instance-size my-self instance>size !
;
: finish-device ( -- )
\ Set unit address to first entry of reg property if it has not been set yet
get-node >space? 0= IF
s" reg" get-node get-property 0= IF
decode-int set-space 2drop
THEN
THEN
finish-node my-parent to my-self
;
\ Set the instance template as current instance for extending it
\ (i.e. to be able to declare new INSTANCE VARIABLEs etc. there)
: extend-device ( phandle -- )
my-self >r
dup set-node
node>instance-template @
dup to my-self
r> swap instance>parent !
;
: split ( str len char -- left len right len )
>r 2dup r> findchar IF >r over r@ 2swap r> 1+ /string ELSE 0 0 THEN ;
: generic-decode-unit ( str len ncells -- addr.lo ... addr.hi )
dup >r -rot BEGIN r@ WHILE r> 1- >r [char] , split 2swap
$number IF 0 THEN r> swap >r >r REPEAT r> 3drop
BEGIN dup WHILE 1- r> swap REPEAT drop ;
: generic-encode-unit ( addr.lo ... addr.hi ncells -- str len )
0 0 rot ?dup IF 0 ?DO rot (u.) $cat s" ," $cat LOOP 1- THEN ;
: hex-decode-unit ( str len ncells -- addr.lo ... addr.hi )
base @ >r hex generic-decode-unit r> base ! ;
: hex-encode-unit ( addr.lo ... addr.hi ncells -- str len )
base @ >r hex generic-encode-unit r> base ! ;
\ : hex64-decode-unit ( str len ncells -- addr.lo ... addr.hi )
\ dup 2 <> IF
\ hex-decode-unit
\ ELSE
\ drop
\ base @ >r hex
\ $number IF 0 0 ELSE xlsplit THEN
\ r> base !
\ THEN
\ ;
\ : hex64-encode-unit ( addr.lo ... addr.hi ncells -- str len )
\ dup 2 <> IF
\ hex-encode-unit
\ ELSE
\ drop
\ base @ >r hex
\ lxjoin (u.)
\ r> base !
\ THEN
\ ;
: handle-leading-/ ( path len -- path' len' )
dup IF over c@ [char] / = IF 1 /string device-tree @ set-node THEN THEN ;
: match-name ( name len node -- match? )
over 0= IF 3drop true EXIT THEN
s" name" rot get-property IF 2drop false EXIT THEN
1- string=ci ; \ XXX should use decode-string
0 VALUE #search-unit
CREATE search-unit 4 cells allot
: match-unit ( node -- match? )
\ A node with no space is a wildcard and will always match
dup >space? IF
node>space search-unit #search-unit 0 ?DO 2dup @ swap @ <> IF
2drop false UNLOOP EXIT THEN cell+ swap cell+ swap LOOP 2drop true
ELSE drop true THEN
;
: match-node ( name len node -- match? )
dup >r match-name r> match-unit and ; \ XXX e3d
: find-kid ( name len -- node|0 )
dup -1 = IF \ are we supposed to stay in the same node? -> resolve-relatives
2drop get-node
ELSE
get-node child >r BEGIN r@ WHILE 2dup r@ match-node
IF 2drop r> EXIT THEN r> peer >r REPEAT
r> 3drop false
THEN ;
: set-search-unit ( unit len -- )
0 to #search-unit
0 to user-instance-#units
dup 0= IF 2drop EXIT THEN
s" #address-cells" get-node get-property THROW
decode-int to #search-unit 2drop
s" decode-unit" get-node $call-static
( ) #search-unit 0 ?DO search-unit i cells + ! LOOP
;
: resolve-relatives ( path len -- path' len' )
\ handle ..
2dup 2 = swap s" .." comp 0= and IF
get-node parent ?dup IF
set-node drop -1
ELSE
s" Already in root node." type
THEN
THEN
\ handle .
2dup 1 = swap c@ [CHAR] . = and IF
drop -1
THEN
;
\ XXX This is an old hack that allows wildcard nodes to work
\ by not having a #address-cells in the parent and no
\ decode unit. This should be removed.
\ (It appears to be still used on js2x)
: set-instance-unit ( unitaddr len -- )
dup 0= IF 2drop 0 to user-instance-#units EXIT THEN
2dup 0 -rot bounds ?DO
i c@ [char] , = IF 1+ THEN \ Count the commas
LOOP
1+ dup to user-instance-#units
hex-decode-unit
user-instance-#units 0 ?DO
user-instance-units i cells + !
LOOP
;
: split-component ( path. -- path'. args. name. unit. )
[char] / split 2swap ( path'. component. )
[char] : split 2swap ( path'. args. name@unit. )
[char] @ split ( path'. args. name. unit. )
;
: find-component ( path len -- path' len' args len node|0 )
debug-find-component? IF
." find-component for " 2dup type cr
THEN
split-component ( path'. args. name. unit. )
debug-find-component? IF
." -> unit =" 2dup type cr
." -> stack =" .s cr
THEN
['] set-search-unit CATCH IF
\ XXX: See comment in set-instance-unit
." WARNING: Obsolete old wildcard hack " .s cr
set-instance-unit
THEN
resolve-relatives find-kid ( path' len' args len node|0 )
\ If resolve returned a wildcard node, and we haven't hit
\ the above gross hack then copy the unit
dup IF dup >space? not #search-unit 0 > AND user-instance-#units 0= AND IF
( ) #search-unit dup to user-instance-#units 0 ?DO
search-unit i cells + @ user-instance-units i cells + !
LOOP
THEN THEN
\ XXX This can go away with the old wildcard hack
dup IF dup >space? user-instance-#units 0 > AND IF
\ User supplied a unit value, but node also has different physical unit
cr ." find-component with unit mismatch!" .s cr
drop 0
THEN THEN
;
: .find-node ( path len -- phandle|0 )
current-node @ >r
handle-leading-/ current-node @ 0= IF 2drop r> set-node 0 EXIT THEN
BEGIN dup WHILE \ handle one component:
find-component ( path len args len node ) dup 0= IF
3drop 2drop r> set-node 0 EXIT THEN
set-node 2drop REPEAT 2drop
get-node r> set-node ;
' .find-node to find-node
: find-node ( path len -- phandle|0 ) de-alias find-node ;
: delete-node ( phandle -- )
dup node>instance-template @ max-instance-size free-mem
dup node>parent @ node>child @ ( phandle 1st peer )
2dup = IF
node>peer @ swap node>parent @ node>child !
EXIT
THEN
dup node>peer @
BEGIN
2 pick 2dup <>
WHILE
drop
nip dup node>peer @
dup 0= IF 2drop drop unloop EXIT THEN
REPEAT
drop
node>peer @ swap node>peer !
drop
;
: open-dev ( path len -- ihandle|0 )
0 to user-instance-#units
de-alias current-node @ >r
handle-leading-/ current-node @ 0= IF 2drop r> set-node 0 EXIT THEN
my-self >r
0 to my-self
0 0 >r >r
BEGIN
dup
WHILE \ handle one component:
( arg len ) r> r> get-node open-node to my-self
find-component ( path len args len node ) dup 0= IF
3drop 2drop my-self close-dev
r> to my-self
r> set-node
0 EXIT
THEN
set-node
>r >r
REPEAT
2drop
\ open final node
r> r> get-node open-node to my-self
my-self r> to my-self r> set-node
;
: select-dev open-dev dup to my-self ihandle>phandle set-node ;
: unselect-dev my-self close-dev 0 to my-self device-end ;
: find-device ( str len -- ) \ set as active node
find-node dup 0= ABORT" No such device path" set-node ;
: dev parse-word find-device ;
: (lsprop) ( node --)
dup cr $indent indent @ type ." node: " node>qname type
false +indent (.properties) cr -indent
;
: (show-children) ( node -- )
child BEGIN
dup
WHILE
dup (lsprop) dup child IF false +indent dup recurse -indent THEN peer
REPEAT
drop
;
: lsprop ( {device-specifier}<eol> -- )
parse-word dup IF de-alias ELSE 2drop s" /" THEN
find-device get-node dup dup
cr ." node: " node>path type (.properties) cr (show-children)
0 indent !
;
\ node>path does not allot the memory, since it is internally only used
\ for typing.
\ The external variant needs to allot memory !
: (node>path) node>path ;
: node>path ( phandle -- str len )
node>path dup allot
;
\ Support for support packages.
\ The /packages node.
0 VALUE packages
\ Find a support package (or arbitrary nodes when name is absolute)
: find-package ( name len -- false | phandle true )
dup 0 <= IF
2drop FALSE EXIT
THEN
\ According to IEEE 1275 Proposal 215 (Extensible Client Services Package),
\ the find-package method can be used to get the phandle of arbitrary nodes
\ (i.e. not only support packages) when the name starts with a slash.
\ Some FCODE programs depend on this behavior so let's support this, too!
over c@ [char] / = IF
find-node dup IF TRUE THEN EXIT
THEN
\ Ok, let's look for support packages instead. We can't use the standard
\ find-node stuff, as we are required to find the newest (i.e., last in our
\ tree) matching package, not just any.
0 >r packages child
BEGIN
dup
WHILE
dup >r node>name 2over string=ci r> swap IF
r> drop dup >r
THEN
peer
REPEAT
3drop
r> dup IF true THEN
;
: open-package ( arg len phandle -- ihandle | 0 ) open-node ;
: close-package ( ihandle -- ) close-node ;
: $open-package ( arg len name len -- ihandle | 0 )
find-package IF open-package ELSE 2drop false THEN ;
\ device tree translate-address
\ #include <translate.fs>

80
ofw/of/of-words.fs Normal file
View File

@ -0,0 +1,80 @@
hex
: $banner
." Open Firmware for OF816 by Michael Guidero" cr
." Portions (c) IBM Corp. (https://github.com/aik/SLOF)"
;
db" OF words and values"
810000 value load-base
0 0 2value boot-device
0 0 2value boot-file
0 0 2value diag-device
0 0 2value diag-file
0 0 2value boot-command
false value diag-switch?
: diagnostic-mode? diag-switch? ;
false value auto-boot?
0 0 2value use-nvramrc
false value use-nvramrc?
0 0 2value input-device
0 0 2value output-device
variable stdin
variable stdout
d# 80 value screen-#columns
d# 25 value screen-#rows
0 value security-mode
0 0 2value security-password
0 value security-#badlogins
0 value selftest-#megs
false value $did-banner?
false value oem-logo?
0 0 2value oem-logo
false value oem-banner?
0 0 2value oem-banner
: help ." Please visit https://github.com/mgcaret/of816 " cr ;
: (unsup) ." (unsup) feature" cr d# -21 throw ;
\ All TODO
: boot (unsup) ;
: setenv (unsup) ;
: $setenv (unsup) ;
: printenv (unsup) ;
: set-default (unsup) ;
: set-defaults (unsup) ;
: nodefault-butes (unsup) ;
\ All TODO
: nvedit (unsup) ;
: nvstore (unsup) ;
: nvquit (unsup) ;
: nvrecover (unsup) ;
: nvrun (unsup) ;
\ All TODO
: install-console ( unsup ) ;
: input (unsup) ;
: output (unsup) ;
: io (unsup) ;
\ TODO
: password (unsup) ;
\ TODO
: test parse-word 2drop ;
: test-all parse-word 2drop ;
\ TODO
: callback (unsup) ;
: $callback (unsup) ;
: banner oem-banner? if oem-banner type else $banner then cr true to $did-banner? ;
: suppress-banner true to $did-banner? ;

55
ofw/of/packages.fs Normal file
View File

@ -0,0 +1,55 @@
\ *****************************************************************************
\ * Copyright (c) 2004, 2015 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ * IBM Corporation - initial implementation
\ ****************************************************************************/
\ =============================================================================
\ SUPPORT PACKAGES
\ =============================================================================
s" packages" device-name
get-node to packages
new-device
#include "packages/filler.fs"
finish-device
#if 0
new-device
#include "packages/deblocker.fs"
finish-device
new-device
#include "packages/disk-label.fs"
finish-device
new-device
#include "packages/fat-files.fs"
finish-device
new-device
#include "packages/rom-files.fs"
finish-device
new-device
#include "packages/ext2-files.fs"
finish-device
new-device
#include "packages/obp-tftp.fs"
finish-device
new-device
#include "packages/iso-9660.fs"
finish-device
#endif

48
ofw/of/preprocessor.fs Normal file
View File

@ -0,0 +1,48 @@
\ *****************************************************************************
\ * Copyright (c) 2004, 2008 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ * IBM Corporation - initial implementation
\ ****************************************************************************/
\ OF816 Changes: case-insensitive comparision
\ Modified by MAG for OF816
: ([IF])
BEGIN
BEGIN parse-word dup 0= WHILE
2drop refill
REPEAT
2dup s" [IF]" string=ci IF 1 throw THEN
2dup s" [ELSE]" string=ci IF 2 throw THEN
2dup s" [THEN]" string=ci IF 3 throw THEN
s" \" str= IF ['] \ execute THEN
AGAIN
;
: [IF] ( flag -- )
IF exit THEN
1 BEGIN
['] ([IF]) catch
CASE
1 OF 1+ ENDOF
2 OF dup 1 = if 1- then ENDOF
3 OF 1- ENDOF
ENDCASE
dup 0 <=
UNTIL drop
; immediate
: [ELSE] 0 [COMPILE] [IF] ; immediate
: [THEN] ; immediate
\ Added by MG
: [IFDEF] parse-word $search dup 0<> if nip then postpone [IF] ; immediate
: [IFNDEF] parse-word $search dup 0<> if nip then 0= postpone [IF] ; immediate

199
ofw/of/property.fs Normal file
View File

@ -0,0 +1,199 @@
\ *****************************************************************************
\ * Copyright (c) 2004, 2008 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ * IBM Corporation - initial implementation
\ ****************************************************************************/
db" OF properties (c) IBM"
\ Properties 5.3.5
\ Modified for OF816 by MG
\ OF816 TODOs: maybe make case-sensitive, fix search, etc.
\ Words on the property list for a node are actually executable words,
\ that return the address and length of the property's data. Special
\ nodes like /options can have their properties use specialized code to
\ dynamically generate their data; most nodes just use a 2CONSTANT.
\ Put the type as byte before the property
\ { int = 1, bytes = 2, string = 3 }
\ This is used by .properties for pretty print
\ Flag for type encoding, encode-* resets, set-property set the flag
true value encode-first?
: decode-int over >r 4 /string r> 4c@ swap 2swap swap bljoin ;
: decode-string ( prop-addr1 prop-len1 -- prop-addr2 prop-len2 str len )
dup 0= IF 2dup EXIT THEN \ string properties with zero length
over BEGIN dup c@ 0= IF 1+ -rot swap 2 pick over - rot over - -rot 1-
EXIT THEN 1+ AGAIN ;
\ Remove a word from a wordlist.
\ : (prune) ( name len head -- )
\ dup >r (find) ?dup IF r> BEGIN dup @ WHILE 2dup @ = IF
\ >r @ r> ! EXIT THEN @ REPEAT 2drop ELSE r> drop THEN ;
\ : prune ( name len -- ) last (prune) ;
\ OF816: just smudge it, hopefully properties don't change that often
: prune ( name len -- ) context @ search-wordlist 0= if exit then
dup c@ 20 and if
drop \ protected
else
dup c@ 8 or swap c!
then
;
: set-property ( data dlen name nlen phandle -- )
true to encode-first?
get-current >r node>properties @ set-current
2dup prune $2VALUE ( $2CONSTANT ) r> set-current ;
: delete-property ( name nlen -- )
get-node get-current >r node>properties @ set-current
prune r> set-current ;
: property ( data dlen name nlen -- ) get-node set-property ;
: get-property ( str len phandle -- true | data dlen false )
?dup 0= IF cr cr cr ." get-property for " type ." on zero phandle"
cr cr true EXIT THEN
node>properties @ voc-find dup IF execute false ELSE drop true THEN ;
: get-package-property ( str len phandle -- true | data dlen false )
get-property ;
: get-my-property ( str len -- true | data dlen false )
my-self ihandle>phandle get-property ;
: get-parent-property ( str len -- true | data dlen false )
my-parent ihandle>phandle get-property ;
: get-inherited-property ( str len -- true | data dlen false )
my-self ihandle>phandle
BEGIN
3dup get-property 0= IF
\ Property found
rot drop rot drop rot drop false EXIT
THEN
parent dup 0= IF
\ Root node has been reached, but property has not been found
3drop true EXIT
THEN
AGAIN
;
\ Print out properties.
20 CONSTANT indent-prop
: .prop-int ( str len -- )
space
400 min 0
?DO
i over + dup ( str act-addr act-addr )
c@ 2 0.r 1+ dup c@ 2 0.r 1+ dup c@ 2 0.r 1+ c@ 2 0.r ( str )
i c and c = IF \ check for multipleof 16 bytes
cr indent @ indent-prop + 1+ 0 \ linefeed + indent
DO
space \ print spaces
LOOP
ELSE
space space \ print two spaces
THEN
4 +LOOP
drop
;
: .prop-bytes ( str len -- )
2dup -4 and .prop-int ( str len )
dup 3 and dup IF ( str len len%4 )
>r -4 and + r> ( str' len%4 )
bounds ( str' str'+len%4 )
DO
i c@ 2 0.r \ Print last 3 bytes
LOOP
ELSE
3drop
THEN
;
: .prop-string ( str len )
2dup space type
cr indent @ indent-prop + 0 DO space LOOP \ Linefeed
.prop-bytes
;
: .propbytes ( xt -- )
execute dup
IF
over cell- @ execute
ELSE
2drop
THEN
;
: .property ( lfa -- )
dup cr indent @ 0 ?do space loop
lfa>name 2dup type nip
indent-prop swap -
dup 0< IF drop 0 THEN 0 ?do space loop
lfa>xt .propbytes
;
: (.properties) ( phandle -- )
node>properties @ @ BEGIN dup WHILE dup .property @ REPEAT drop ;
: .properties ( -- )
get-node (.properties) ;
: next-property ( str len phandle -- false | str' len' true )
?dup 0= IF device-tree @ THEN \ XXX: is this line required?
node>properties @
>r 2dup 0= swap 0= or IF 2drop r> @ ELSE r> voc-find xt>lfa @ THEN
dup IF lfa>name true THEN ;
\ encode-* words and all helpers
\ Start a encoded property string
: encode-start ( -- prop 0 )
['] .prop-int compile,
false to encode-first?
here 0
;
: encode-int ( val -- prop prop-len )
encode-first? IF
['] .prop-int compile, \ Execution token for print
false to encode-first?
THEN
here swap lbsplit c, c, c, c, /l
;
: encode-bytes ( str len -- prop-addr prop-len )
encode-first? IF
['] .prop-bytes compile, \ Execution token for print
false to encode-first?
THEN
here over 2dup 2>r allot swap move 2r>
;
: encode-string ( str len -- prop-addr prop-len )
encode-first? IF
['] .prop-string compile, \ Execution token for print
false to encode-first?
THEN
encode-bytes 0 c, char+
;
: encode+ ( prop1-addr prop1-len prop2-addr prop2-len -- prop-addr prop-len )
nip + ;
: encode-int+ encode-int encode+ ;
\ Helpers for common nodes. Should perhaps remove "compatible", as it's
\ not typically a single string.
: device-name [: ." Device name: " 2dup type cr ;] dbexec encode-string s" name" property ;
: device-type encode-string s" device_type" property ;
: model encode-string s" model" property ;
: compatible encode-string s" compatible" property ;

97
ofw/of/root.fs Normal file
View File

@ -0,0 +1,97 @@
\ *****************************************************************************
\ * Copyright (c) 2004, 2008 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ * IBM Corporation - initial implementation
\ ****************************************************************************/
db" OF root device node (c) IBM"
\ this creates the root and common branches of the device tree
defer (client-exec)
defer client-exec
\ defined in slof/fs/client.fs
defer callback
defer continue-client
0 VALUE chosen-node
: chosen
chosen-node dup 0= IF
drop s" /chosen" find-node dup to chosen-node
THEN
;
: set-chosen ( prop len name len -- )
chosen set-property ;
: get-chosen ( name len -- [ prop len ] success )
chosen get-property 0= ;
\ Do not assume that cpu0 is available
VARIABLE chosen-cpu-ihandle
: set-chosen-cpu ( -- )
s" /cpus" find-node dup 0= ABORT" /cpus not found"
child dup 0= ABORT" /cpus/cpu not found"
0 0 rot open-node
dup chosen-cpu-ihandle ! encode-int s" cpu" set-chosen
;
: chosen-cpu-unit ( -- ret ) chosen-cpu-ihandle @ ihandle>phandle >unit ;
\ Look for an exising root, create one if needed
" /" find-node dup 0= IF
drop
new-device
s" /" device-name
ELSE
extend-device
THEN
\ Create /chosen if it doesn't exist
" /chosen" find-node dup 0= IF
drop
new-device
s" chosen" device-name
s" " encode-string s" bootargs" property
s" " encode-string s" bootpath" property
finish-device
ELSE
drop
THEN
\ Create /aliases
new-device
s" aliases" device-name
: open true ;
: close ;
finish-device
\ Create /options
new-device
s" options" device-name
finish-device
\ Create /openprom
new-device
s" openprom" device-name
0 0 s" relative-addressing" property
finish-device
\ Create /packages
new-device
#include <of/packages.fs>
finish-device
: open true ;
: close ;
\ Finish root
finish-device

1262
ofw/out/of-blob.fs Normal file

File diff suppressed because it is too large Load Diff

21
ofw/packages/filler.fs Normal file
View File

@ -0,0 +1,21 @@
\ *****************************************************************************
\ * Copyright (c) 2004, 2008 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ * IBM Corporation - initial implementation
\ ****************************************************************************/
s" filler" device-name
: block-size s" block-size" $call-parent ;
: seek s" seek" $call-parent ;
: read s" read" $call-parent ;
: open true ;
: close ;

View File

@ -5,6 +5,8 @@ if [ -r fcode/romfs.fs ]; then
toke fcode/romfs.fs
fi
if [ -d romfs_files ]; then
../../ofw/build.sh
cp ../../ofw/out/of-blob.fs romfs_files/of.fs
cd romfs_files
../mkromfs.rb ../romfs * */**
cd ..

View File

@ -1,8 +1,10 @@
also romfs
also romfs also forth definitions
\ : #include ascii < parse 2drop ascii > parse 2dup type cr included ;
: #include parse-word swap 1+ swap 2- dup 0 u<= if 2drop exit then
2dup type cr included ;
." ROMfs bootstrap by M.G." cr
s" message.fs" ?romfs-run
s" board.fs" ?romfs-run
s" of.fs" ?romfs-run
forth only definitions