The following code is for the use of local variables in OpenBIOS. I was able to successfully make a word that used local variables. The work isn't complete. There is still work to be done with the INTERPRET word. The LFIND word has be implemented in the INTERPRET word for local variables to be recognized during the compile state. I just need a C-like CONTINUE word to go back to the start of a loop to fix all my problems with INTERPRET. Maybe someone knows a better way of adding LFIND to INTERPRET.
I would appreciate any comments, suggestions, or advice for the following code.
\ Creates an array variable
: ARRAY ( cellCount - )
DEPTH 0= IF
CR ." Please specify an array size." CR
EXIT
THEN
\ Compile-time behavior
CREATE CELL * ALLOT \ creates and initializes the instance
DOES>
\ Run-time behavior
DEPTH 2 < IF
CR ." Please specify an index number." CR
drop \ removes the address of the array instance
-1 throw \ stop normal execution after error
THEN
SWAP CELL * + \ Calculates address to return
; immediate
\ Declare the local-base-address VALUE
0 VALUE local-base-address
\ returns the base address used for the local words
: getBaseAddress ( - addr )
local-base-address
;
\ sets the base address used for the local words
: setBaseAddress ( addr - )
TO local-base-address
;
\ Sets the first local variable's value
: Local0! ( x - )
0 CELL * getBaseAddress + !
;
\ Sets the second local variable's value
: Local1! ( x - )
1 CELL * getBaseAddress + !
;
\ Sets the third local variable's value
: Local2! ( x - )
2 CELL * getBaseAddress + !
;
\ Sets the fourth local variable's value
: Local3! ( x - )
3 CELL * getBaseAddress + !
;
\ Sets the fifth local variable's value
: Local4! ( x - )
4 CELL * getBaseAddress + !
;
\ Sets the sixth local variable's value
: Local5! ( x - )
5 CELL * getBaseAddress + !
;
\ Sets the seventh local variable's value
: Local6! ( x - )
6 CELL * getBaseAddress + !
;
\ Sets the eighth local variable's value
: Local7! ( x - )
7 CELL * getBaseAddress + !
;
\ Sets the ninth local variable's value
: Local8! ( x - )
8 CELL * getBaseAddress + !
;
\ Sets the tenth local variable's value
: Local9! ( x - )
9 CELL * getBaseAddress + !
;
\ Sets the eleventh local variable's value
: Local10! ( x - )
10 CELL * getBaseAddress + !
;
\ Sets the twelfth local variable's value
: Local11! ( x - )
11 CELL * getBaseAddress + !
;
\ **** Calculates the needed amount of memory for local variables ****
0 value variableCount
: calculateNeededMemory ( "char" - n )
0 TO variableCount
>in @ \ keep track of where the pointer was
begin
parse-word
0= if \ if there is no more text to parse
drop
true
else
dup " ;" comp
0= if \ if the semicolon is encountered
drop \ drop the duplicated address
false
else
" }" comp
0= if \ if '}' character is encountered
true \ end loop because '}' marks end of local variables
else
variableCount 1 + TO variableCount
false
then
then
then
until
>in ! \ reset the pointer
variableCount CELL *
;
\ **** allocates the memory for local variables ****
: allocateMemory ( n - addr )
alloc-mem dup 0= if
drop
cr cr 10 spaces abort" Failed to allocate memory for local variables!" cr cr
then
;
\ Declares the size of the local variable table
48 CONSTANT localTableSize
\ Declare the local variable table
localTableSize ARRAY localVariableTable
\ Keeps track of end of array
0 VALUE arrayCount
\ gets the number of records in the local variable table
: getLocalRecordCount
arrayCount 4 /
;
\ Clears the local variable table
: initLocalTable ( - )
\ free all the dynamically allocated memory
arrayCount 0 ?do
I 3 + localVariableTable @ ( addr )
free-mem ( )
4 +loop
0 localVariableTable localTableSize erase
0 TO arrayCount
;
\ Adds a local variable symbol to the local variable table
: addLocal ( addr len order initflag - )
depth 4 < if
cr ." The stack needs at least 4 values to add a local variable." cr
exit
then
\ add to the table
arrayCount 0 + localVariableTable ! \ initflag
arrayCount 1 + localVariableTable ! \ order
arrayCount 2 + localVariableTable ! \ len
arrayCount 3 + localVariableTable ! \ addr
\ allocate memory for the symbol
arrayCount 2 + localVariableTable @ ( length )
alloc-mem ( memaddr )
dup ( memaddr memaddr )
dup ( memaddr memaddr memaddr )
\ called only when memaddr = 0
0= ( memaddr memaddr flag )
if
cr ." Failed to allocate memory in addLocal!" cr ( memaddr memaddr )
then
\ copy local variable name to a safe location
arrayCount 3 + localVariableTable @ ( memaddr memaddr addr )
swap ( memaddr addr memaddr )
arrayCount 2 + localVariableTable @ ( memaddr addr memaddr length )
move ( memaddr )
arrayCount 3 + localVariableTable ! ( )
\ increment arrayCount
arrayCount 4 + TO arrayCount
;
\ prints the local variable table
: printLocalTable
arrayCount 0= if
cr ." No variables loaded" cr
exit
then
arrayCount 0 ?do
cr ." Variable name: "
I 3 + localVariableTable @
I 2 + localVariableTable @
type
." Order: "
I 1 + localVariableTable @ .
." Init Flag: "
I 0 + localVariableTable @ .
4
+loop
;
\ Finds a local variable symbol in the local variable table
\ Returns its order or -1 on failure
: getOrder ( addr len - order )
\ if the address and length are missing
depth 2 < if
cr ." Address and length are required on the stack to use getOrder!" cr
-1 throw \ ends execution
then
arrayCount 0 ?do
over ( addr len addr )
I 3 + ( addr len addr addrindex )
localVariableTable @ ( addr len addr addr1 )
2 pick ( addr len addr addr1 len )
comp ( addr len n )
0= ( addr len flag )
if \ if the symbol is found
2drop ( addr len - )
I 1 + localVariableTable @
unloop
exit
then
4 \ increment the index by 4
+loop
2drop ( addr len - )
-1 \ returns -1 for the order if the symbol is not found
;
\ **** read the local variables in the input stream ****
0 VALUE useTopStackValue
0 VALUE index
0 VALUE localVariableMemory
: readLocalVariables ( "char" - )
0 TO index
true TO useTopStackValue
begin
parse-word ( addr len )
dup ( addr len len )
0> ( addr len flag )
while ( addr len )
2dup ( addr len addr len )
drop ( addr len addr )
" }" ( addr len addr addr len )
comp ( addr len flag )
0= ( addr len flag )
if ( addr len ) \ if end of local variables
drop ( addr )
drop ( )
exit ( )
then
2dup ( addr len addr len )
drop ( addr len addr )
" ;" ( addr len addr addr len )
comp ( addr len flag )
0= ( addr len flag )
if ( addr len ) \ if not using top stack value for local variables
false TO useTopStackValue ( addr len )
else \ add local variable to table
index useTopStackValue ( addr len order useTopStackValue )
addLocal ( )
index 1 + TO index \ increment index
then
repeat
drop ( addr )
drop ( )
;
\ FALSE VALUE usingLocals \ not needed because it is in the interpreter.fs file
\ declare the local stack
1000 ARRAY localStack
\ declare the stack top pointer
0 VALUE localStackTop
\ Adds to the top of the local stack
: pushLocalStack ( x - L:x )
localStackTop localStack ! ( x - )
localStackTop 1 + TO localStackTop
;
\ Removes the top local stack value and places it into the data stack
: popLocalStack ( L:x - x )
localStackTop localStack @
localStackTop 1 - TO localStackTop
;
12 CONSTANT localVariableLimit
\ ***** sets up local variables ******
: { ( "char" - )
initLocalTable
\ localVariableLimit CELL * ( memorySize )
calculateNeededMemory ( memorySize )
allocateMemory ( memorySize - addr )
TO localVariableMemory ( )
readLocalVariables ( )
TRUE TO usingLocals
\ add code to the current definition
\ saves the old base address
postpone getBaseAddress
postpone pushLocalStack
\ sets the base address to this definition's reserved memory
localVariableMemory
postpone literal
postpone setBaseAddress
\ add code to initialize the variables if needed
arrayCount 0 ?do
I 0 + localVariableTable @ ( flag ) \ get the init flag
true ( flag true )
= ( flag1 )
if
I 4 / ( variable number )
case
0 of ['] Local0! , endof
1 of ['] Local1! , endof
2 of ['] Local2! , endof
3 of ['] Local3! , endof
4 of ['] Local4! , endof
5 of ['] Local5! , endof
6 of ['] Local6! , endof
7 of ['] Local7! , endof
8 of ['] Local8! , endof
9 of ['] Local9! , endof
10 of ['] Local10! , endof
11 of ['] Local11! , endof
cr ." Can't save to local variable! " cr
exit
endcase
then
4
+loop
; immediate \ declares this word as a compiler directive
\ sets values for local variables
: -> ( - )
parse-word ( addr len )
getOrder ( order )
dup ( order order )
-1 = ( order flag )
if \ if the symbol isn't found
cr ." Symbol is not a local variable! " cr
drop ( )
exit
then
case
0 of ['] Local0! , endof
1 of ['] Local1! , endof
2 of ['] Local2! , endof
3 of ['] Local3! , endof
4 of ['] Local4! , endof
5 of ['] Local5! , endof
6 of ['] Local6! , endof
7 of ['] Local7! , endof
8 of ['] Local8! , endof
9 of ['] Local9! , endof
10 of ['] Local10! , endof
11 of ['] Local11! , endof
cr ." Can't save to local variable! " cr
exit
endcase
; immediate
\ returns the first local variable's value
: Local0@
CELL 0 * getBaseAddress + @
;
\ returns the second local variable's value
: Local1@
CELL 1 * getBaseAddress + @
;
\ returns the third local variable's value
: Local2@
CELL 2 * getBaseAddress + @
;
\ returns the fourth local variable's value
: Local3@
CELL 3 * getBaseAddress + @
;
\ returns the fifth local variable's value
: Local4@
CELL 4 * getBaseAddress + @
;
\ returns the sixth local variable's value
: Local5@
CELL 5 * getBaseAddress + @
;
\ returns the seventh local variable's value
: Local6@
CELL 6 * getBaseAddress + @
;
\ returns the eighth local variable's value
: Local7@
CELL 7 * getBaseAddress + @
;
\ returns the ninth local variable's value
: Local8@
CELL 8 * getBaseAddress + @
;
\ returns the tenth local variable's value
: Local9@
CELL 9 * getBaseAddress + @
;
\ returns the eleventh local variable's value
: Local10@
CELL 10 * getBaseAddress + @
;
\ returns the twelfth local variable's value
: Local11@
CELL 11 * getBaseAddress + @
;
\ determines if a symbol is a local variable
: LFIND ( addr len - )
depth 2 < if \ if the address and length are not on the stack
exit
then
2dup ( addr len addr len )
getOrder ( addr len addr len - addr len n )
dup ( addr len n - addr len n n )
-1 = if \ if the symbol isn't a local variable
drop ( addr len n - addr len )
else \ if the symbol is a local variable
case
0 of ['] Local0@ , endof
1 of ['] Local1@ , endof
2 of ['] Local2@ , endof
3 of ['] Local3@ , endof
4 of ['] Local4@ , endof
5 of ['] Local5@ , endof
6 of ['] Local6@ , endof
7 of ['] Local7@ , endof
8 of ['] Local8@ , endof
9 of ['] Local9@ , endof
10 of ['] Local10@ , endof
11 of ['] Local11@ , endof
\ default case
2drop ( addr len - )
cr ." Could not compile local variable!" cr
TRUE
exit
endcase
2drop ( addr len - )
." compiled" \ display this text when entering a local variable symbol
FALSE
then
;
\ Redefine colon to clean up after {
: ;
usingLocals TRUE =
if
FALSE TO usingLocals
postpone popLocalStack
postpone setBaseAddress
then
postpone ;
; immediate
' lfind is mydefer \ makes lfind work in INTERPRET
\ ************ OVERWRITE THESE WORDS IN interpreter.fs ***************
Defer mydefer
: interpret
0 >in !
begin
parse-word dup 0> \ was there a word at all?
while
usingLocals if
mydefer
\ need to add a code to continue to the next iteration right here
then
$find
if
dup flags? 0<> state @ 0= or if
execute
else
, \ compile mode && !immediate
then
else \ word is not known. maybe it's a number
2dup $number
if
span @ >in ! \ if we encountered an error, don't continue parsing
type 3a emit
-13 throw
else
-rot 2drop 1 handle-lit
then
then
depth 200 >= if -3 throw then
depth 0< if -4 throw then
rdepth 200 >= if -5 throw then
rdepth 0< if -6 throw then
repeat
2drop
;
: print-status ( exception -- )
space
?dup if
dup sys-debug \ system debug hook
case
-1 of s" Aborted." type endof
-2 of s" Aborted." type endof
-3 of s" Stack Overflow." type 0 depth! endof
-4 of s" Stack Underflow." type 0 depth! endof
-5 of s" Return Stack Overflow." type endof
-6 of s" Return Stack Underflow." type endof
-13 of s" undefined word." type endof
-15 of s" out of memory." type endof
-21 of s" undefined method." type endof
-22 of s" no such device." type endof
-100 of endof \ local variable being used
dup s" Exception #" type .
0 state !
endcase
else
state @ 0= if
s" ok"
else
s" compiled"
then
type
then
cr
;
Current trunk (1075) lists some files and doesn't boot at all
Welcome to OpenBIOS v1.0 built on Nov 30 2012 19:55
Trying hd:,\\:tbxi...
Trying hd:,\ppc\bootinfo.txt...
No valid state has been set by load or init-program
0 > boot cd:,\\:tbxi >> Not a bootable ELF image
No valid state has been set by load or init-program
ok
0 > dir cd:9,\
73728 2002-07-18 08:21:48 Desktop DB
0 2002-07-18 08:21:49 Desktop DF
0 2002-07-18 08:21:49 Finder
0 2002-07-18 08:21:49 OSXBoot!
0 2002-07-18 08:21:50 System
1778 2002-07-18 08:21:49 Where_have_all_my_files_gone?
ok
0 > boot cd:9,\\:tbxi No valid state has been set by load or init-program
ok
0 >
After testing with this patch:
http://lists.openbios.org/pipermail/openbios/2011-August/006618.html
I have better results
Welcome to OpenBIOS v1.0 built on Nov 30 2012 20:00
Trying hd:,\\:tbxi...
Trying hd:,\ppc\bootinfo.txt...
No valid state has been set by load or init-program
0 > boot cd:,\\:tbxi >> Not a bootable ELF image
No valid state has been set by load or init-program
ok
0 > dir cd:9,\
82 2002-07-24 17:47:43 ._Welcome to Mac OS X
6148 2002-07-31 23:59:42 .DS_Store
0 2002-07-31 23:59:37 .Trashes\
0 2002-07-29 03:06:27 .vol\
0 2002-07-30 10:00:25 Applications\
0 2002-07-31 23:43:08 bin\
5120 2002-07-31 23:59:40 Desktop DB
25410 2002-07-31 23:59:40 Desktop DF
0 2002-07-15 06:20:41 dev\
11 2002-07-31 23:57:11 etc
0 2002-07-30 10:14:44 Library\
11 2002-07-31 23:57:11 mach
3678188 2002-07-28 20:19:43 mach_kernel
0 2002-07-30 10:57:00 private\
0 2002-07-31 23:41:16 sbin\
0 2002-07-30 10:57:38 System\
11 2002-07-31 23:58:55 tmp
0 2002-07-30 10:03:14 usr\
11 2002-07-31 23:58:58 var
0 2002-07-29 03:06:27 Volumes\
0 2002-07-30 11:07:00 Welcome to Mac OS X\
0 2002-07-19 08:21:48 HFS+ Private Data\
ok
0 > boot cd:9,\\:tbxi call-method slw_update_keymap: exception -21
Here is also a listing of partitions on mine boot disk,
# mac-fdisk /home/amade/emu/Mac\ OS\ 10.2\ \(Disc\ 1\).img
/home/amade/emu/Mac OS 10.2 (Disc 1).img
Command (? for help): p
/home/amade/emu/Mac OS 10.2 (Disc 1).img
# type name length base ( size ) system
/home/amade/emu/Mac OS 10.2 (Disc 1).img1 Apple_partition_map Apple 63 @ 1 ( 31.5k) Partition map
/home/amade/emu/Mac OS 10.2 (Disc 1).img2 Apple_Driver43 Macintosh 56 @ 64 ( 28.0k) Driver 4.3
/home/amade/emu/Mac OS 10.2 (Disc 1).img3 Apple_Driver43_CD Macintosh 140 @ 120 ( 70.0k) Unknown
/home/amade/emu/Mac OS 10.2 (Disc 1).img4 Apple_Void 0 @ 0 ( 0.0k) Unknown
/home/amade/emu/Mac OS 10.2 (Disc 1).img5 Apple_Driver_ATAPI Macintosh 56 @ 260 ( 28.0k) Unknown
/home/amade/emu/Mac OS 10.2 (Disc 1).img6 Apple_Driver_ATAPI Macintosh 140 @ 316 ( 70.0k) Unknown
/home/amade/emu/Mac OS 10.2 (Disc 1).img7 Apple_Patches Patch Partition 512 @ 456 (256.0k) Unknown
/home/amade/emu/Mac OS 10.2 (Disc 1).img8 Apple_Void 0 @ 0 ( 0.0k) Unknown
/home/amade/emu/Mac OS 10.2 (Disc 1).img9 Apple_HFS Mac_OS_X 1278432 @ 968 (624.2M) HFS
/home/amade/emu/Mac OS 10.2 (Disc 1).img10 Apple_Free 45656 @ 1279400 ( 22.3M) Free space
Block size=2048, Number of Blocks=331264
DeviceType=0x1, DeviceId=0x1
Drivers-
1: @ 16 for 5, type=0x1
2: @ 30 for 25, type=0xffff
3: @ 65 for 5, type=0x701
4: @ 79 for 31, type=0xf8ff
Command (? for help):
Two similar (to me) things which probably still need fixing in filesystem handling are
1. "boot cd:,\\:tbxi" should do some kind of search through partitions
2. later in boot process it goes through partitions 0,1,2 seemingly from
comments on GSOC patches expecting some of them to be ignored
(http://asmblr.net/scrot/2012-11-30-211915_1366x768_scrot.png)
screenshot is from bios with gsoc patches
Also I wonder if "Still waiting for root device" problem which I have
with gsoc patches, isn't caused by not going properly through partitions
or even expecting them to be numbered differently (but those are just
speculations)
Amadeusz
This patch adds the get-key-map word to the keyboard node. This patch is an improvement on the last get-key-map patch. It adds a keyboard node to /aliases and fixes a bug with the getKeyMap() function. If you wish to test out this patch, the program below will show you what key you pushed. The output will display hex values and text. The hex values in the middle tells you which key is being pushed.
: myword { ; keyboardDevice }
" keyboard" open-dev -> keyboardDevice
begin
" get-key-map" keyboardDevice $call-method
32 dump
10000 ms \ update speed
again
;
signed-off-by: John Arbuckle <programmingkidx(a)gmail.com>
---
drivers/adb_kbd.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 82 insertions(+), 4 deletions(-)
diff --git a/drivers/adb_kbd.c b/drivers/adb_kbd.c
index e38798a..e799704 100644
--- a/drivers/adb_kbd.c
+++ b/drivers/adb_kbd.c
@@ -42,11 +42,13 @@ keyboard_close(int *idx)
}
static void keyboard_read(void);
+void getKeyMap(void);
NODE_METHODS( keyboard ) = {
- { "open", keyboard_open },
- { "close", keyboard_close },
- { "read", keyboard_read },
+ { "open", keyboard_open },
+ { "close", keyboard_close },
+ { "read", keyboard_read },
+ { "get-key-map", getKeyMap },
};
/* VT100 escape sequences */
@@ -545,7 +547,8 @@ void *adb_kbd_new (char *path, void *private)
set_property(ph, "reg", (char *)&props, sizeof(props));
aliases = find_dev("/aliases");
- set_property(aliases, "adb-keyboard", buf, strlen(buf) + 1);
+ set_property(aliases, "adb-keyboard", buf, strlen(buf) + 1);
+ set_property(aliases, "keyboard", buf, strlen(buf) + 1);
return kbd;
}
@@ -566,3 +569,78 @@ static void keyboard_read(void)
}
PUSH(i);
}
+
+
+// Returns the base to the exponent power
+static int pow(int base, int exponent)
+{
+ int index, answer;
+ answer = base;
+ for(index = 1; index < exponent; index++)
+ {
+ answer = answer * base;
+ }
+ return answer;
+}
+
+// The implementation of the get-key-map word.
+// Returns an array of 32 bytes. Certain bits
+// are used to determine which keys are being
+// held down.
+
+void getKeyMap(void)
+{
+ int keyPushed, *keyMapArray, offset;
+ const int sizeOfArray = 8;
+ const int modifierKeyIndex = 7;
+ const int commandKeyValue = pow(2,28);
+ const int shiftKeyValue = pow(2,30);
+ const int theAKeyValue = pow(2,27);
+
+ keyMapArray = (int *) malloc(sizeOfArray);
+ if(!keyMapArray) // if failed to allocate memory
+ {
+ printk("Failed to allocate memory for keyMapArray!\n");
+ PUSH(0);
+ return;
+ }
+
+ // Set all the elements to zero
+ int index;
+ for(index = 0; index < sizeOfArray; index++)
+ {
+ keyMapArray[index] = 0;
+ }
+
+ feval("key?");
+ if(POP() != -1) // if no key was pushed
+ {
+ PUSH((int)keyMapArray); // returns the address of keyMapArray
+ return;
+ }
+
+ feval("key");
+ keyPushed = POP();
+
+ if(keyPushed > 0 && keyPushed < 27) // control key combination
+ {
+ offset = 1;
+ keyMapArray[modifierKeyIndex] = commandKeyValue;
+ }
+
+ else if(keyPushed > 64 && keyPushed < 91) // shift key combination
+ {
+ offset = 65;
+ keyMapArray[modifierKeyIndex] = shiftKeyValue;
+ }
+
+ else // just a letter is being held down
+ {
+ offset = 97;
+ }
+
+ // Determines the value and location of a bit in the array.
+ *keyMapArray = theAKeyValue >> (keyPushed - offset);
+
+ PUSH((int) keyMapArray);
+}
\ No newline at end of file
--
1.7.5.4
On Nov 30, 2012, at 9:13 AM, Mark Cave-Ayland wrote:
> On 21/11/12 12:57, Programmingkid wrote:
>
>> Here is the CIF output I captured after adding FILLL.
>
> Thanks for this - the last RFC patch I just posted was because of this:
>
> of_client_interface: interpret 056136e4 00000001 00000640 fff73ed0
> interpret value depthbytes value rowbytes to active-package frame-buffer-adr value this-frame-buffer-adr : rect-setup >r >r rowbytes * swap depthbytes * + this-frame-buffer-adr + r> depthbytes * -rot r> ; : DRAW-RECTANGLE rect-setup 0 ?do 2dup 4 pick move 2 pick rowbytes d+ loop 3drop ; : FILL-RECTANGLE rect-setup rot depthbytes case 1 of dup 8 << or dup 10 << or endof 2 of dup 10 << or endof endcase -rot 0 ?do dup 3 pick 3 pick filll rowbytes + loop 3drop ; : READ-RECTANGLE rect-setup >r swap r> 0 ?do 2dup 4 pick move rowbytes 3 pick d+ loop 3drop ; this-frame-buffer-adr 0 to active-package ([4] -- [2])
>
> ^^^^^^^^^^^^^^^^^^^
>
> With this patch applied, do you get any further?
I tried to compile the source code, but I saw this error:
cc target/arch/x86/multiboot.o
/bin/sh: i486-eabi-gcc: command not found
It looks like a file is being included with the PPC target that shouldn't be included.
BootX appears to be able to want to change the current package phandle by
executing Forth statements in the form "<value> to active-package". This won't
work correctly in OpenBIOS, since changing packages requires calling the
active-package! word to perform additional housekeeping such as changing
wordlists.
The proposed solution here is to redefine "to" at the end of device.fs so that if
package support is included, we perform an additional check on the destination xt
to see if it matches that of active-package. If it does, then we manually invoke
the active-package! word to select the new package.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland(a)ilande.co.uk>
---
openbios-devel/forth/bootstrap/bootstrap.fs | 12 ++++++++----
openbios-devel/forth/device/device.fs | 11 +++++++++++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/openbios-devel/forth/bootstrap/bootstrap.fs b/openbios-devel/forth/bootstrap/bootstrap.fs
index f295e4e..6878449 100644
--- a/openbios-devel/forth/bootstrap/bootstrap.fs
+++ b/openbios-devel/forth/bootstrap/bootstrap.fs
@@ -1052,17 +1052,21 @@ variable #instance
3 /n* + !
then
;
-
-: to
- ['] ' execute
+
+: (to-xt) ( xt -- )
dup @ instance-cfa?
state @ if
swap ['] (lit) , , if ['] (ito) else ['] (to) then ,
else
if (ito) else /n + ! then
then
- ; immediate
+;
+: to
+ ['] ' execute
+ (to-xt)
+ ; immediate
+
: is ( xt "wordname<>" -- )
parse-word $find if
(to)
diff --git a/openbios-devel/forth/device/device.fs b/openbios-devel/forth/device/device.fs
index 4e025b9..562c919 100644
--- a/openbios-devel/forth/device/device.fs
+++ b/openbios-devel/forth/device/device.fs
@@ -189,3 +189,14 @@ variable device-tree
free-mem
then
;
+
+\ Redefine to word so that statements of the form "0 to active-package"
+\ are supported for bootloaders that require it
+: to
+ ['] ' execute
+ dup ['] active-package = if
+ drop active-package!
+ else
+ (to-xt)
+ then
+; immediate
--
1.7.10.4
Author: mcayland
Date: Fri Nov 30 00:02:22 2012
New Revision: 1074
URL: http://tracker.coreboot.org/trac/openbios/changeset/1074
Log:
Add a default "decode-unit" word for devices that don't implement their own.
When a device does not implement its own "encode-unit" word, OpenBIOS
currently supplies a default implementation that encodes a hex string
to a single cell.
This commit does the same for "decode-unit" ensuring that it is also
possible to open a device path containing a unit address generated by
a device that doesn't implement its own "encode-unit" word.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland(a)ilande.co.uk>
Modified:
trunk/openbios-devel/forth/device/pathres.fs
Modified: trunk/openbios-devel/forth/device/pathres.fs
==============================================================================
--- trunk/openbios-devel/forth/device/pathres.fs Sat Nov 24 15:43:11 2012 (r1073)
+++ trunk/openbios-devel/forth/device/pathres.fs Fri Nov 30 00:02:22 2012 (r1074)
@@ -177,28 +177,33 @@
\ 4.3.3 match child node
\
+\ used if package lacks a decode-unit method
+: def-decode-unit ( str len -- unitaddr ... )
+ parse-hex
+;
+
+: get-decode-unit-xt ( phandle -- xt )
+ " decode-unit" rot find-method
+ 0= if ['] def-decode-unit then
+;
+
: find-child ( sinfo -- phandle )
>r
\ decode unit address string
r@ >si.unit_addr 2@ dup if
( str len )
- " decode-unit" active-package find-method
- if
- depth 3 - >r execute depth r@ - r> swap
- ( ... a_lo ... a_hi olddepth n )
- 4 min 0 max
- dup r@ >si.unit_phys_len !
- ( ... a_lo ... a_hi olddepth n )
- r@ >si.unit_phys >r
- begin 1- dup 0>= while
- rot r> dup la1+ >r l!-be
- repeat
- r> 2drop
- depth!
- else
- \ no decode-unit method... failure
- -99 throw
- then
+ active-package get-decode-unit-xt
+ depth 3 - >r execute depth r@ - r> swap
+ ( ... a_lo ... a_hi olddepth n )
+ 4 min 0 max
+ dup r@ >si.unit_phys_len !
+ ( ... a_lo ... a_hi olddepth n )
+ r@ >si.unit_phys >r
+ begin 1- dup 0>= while
+ rot r> dup la1+ >r l!-be
+ repeat
+ r> 2drop
+ depth!
else
2drop
\ clear unit_phys