On Dec 20, 2017, at 12:45 PM, Programmingkid programmingkidx@gmail.com wrote:
On Dec 20, 2017, at 8:53 AM, Jd Lyons lyons_dj@yahoo.com wrote:
I’ve run into trouble with b?branch not working as expected by the nVidia Option Rom Fcode.
What Openbios does now for b?branch is:
From fcode.fs:
\ b?branch ( continue? -- ) \ Conditional branch FCode. Followed by FCode-offset.
: b?branch fcode-offset 0< if \ if we jump backwards, we can forsee where it goes ['] do?branch , resolve-dest execute-tmp-comp else setup-tmp-comp ['] do?branch , here 0 0 , then- ; immediate ===
I fond some code from SLOF that may work a little better:
: b?branch ( flag -- ) ?compile-mode IF read-fcode-offset ?negative IF dest-on-top postpone until ELSE postpone if THEN ELSE ( flag ) IF fcode-offset jump-n-ip \ Skip over offset value ELSE read-fcode-offset ?jump-direction jump-n-ip THEN THEN ; immediate
Unfortunately it’s not just a simple copy and paste, I get errors when trying to compile Openbios with this code.
When you have time, could you help me step though it and figure out where it is failing, and how to fix it, I’m just not very good at C and could really use some help from someone that understands what the code is trying to do, and what I need to port over from SLOF to get it to compile.
Thanks, James
I tried copying and pasting into OpenBIOS and saw these errors: ?compile-mode: undefined word. read-fcode-offset: undefined word. dest-on-top: undefined word. ?jump-direction: undefined word.
I could not find these words in my openfirmware specification pdf document. My guess is they only exist on SLOF. In general the definition of words tend not to be so portable.
OpenBIOS does come with a built-in debugger that would allow you to see exactly what is executing.
https://docs.oracle.com/cd/E19620-01/805-4436/6j4719ca7/index.html
- Webpage on how to use the forth debugger
Here is a quick tutorial:
Lets say you want to debug this simple word:
: myword 1 2 3 4 ;
To indicate that a word is to be debugged type this: debug myword
Then run the word myword by just typing myword and pushing return at the prompt.
You will see something like this next: : myword ( Empty )
To step thru each instruction in myword, push the return key.
You will see this each time the return key is pushed: <adddress>: 1 ( 1 ) <adddress>: 2 ( 1 2 ) <adddress>: 3 ( 1 2 3 ) <adddress>: (lit) (1 2 3 4) <adddress>: (semis) [ Finished myword ] ok
The values in the parentheses indicate what is going into the stack.
I suggest familiarizing yourself with the debugger first before starting on the b?branch word.
One question to answer is are we experiencing problems at compile time or at run-time.
Like Segher said, it’s tricky.
I shamelessly hacked it together, but now it hangs on b?branch around here:
(offset) 1b 400b092 : (compile) [ 0xcfa ] 400b093 : (compile) b(lit) [ 0x10 ] 400b098 : (compile) < [ 0x3a ] 400b099 : (compile) b?branch [ 0x14 ] (offset) f 400b09c : (compile) b(lit) [ 0x10 ] 400b0a1 : (compile) b(lit) [ 0x10 ] 400b0a7 : (compile) [ 0xbd2 ] 400b0a8 : (compile) b(>resolve) [ 0xb2 ] 400b0a9 : (compile) b(>resolve) [ 0xb2 ]
After hanging for 10 min or so, Openbios reboots.diff --git a/Makefile.target b/Makefile.target
So I’m still not getting it right, everyone have a look and see if you can find anything that doesn’t look ok.
diff --git a/Makefile.target b/Makefile.target index 4c54105..4f10714 100644 --- a/Makefile.target +++ b/Makefile.target @@ -29,7 +29,7 @@ CFLAGS+= -Os -g -DNATIVE_BITWIDTH_EQUALS_HOST_BITWIDTH -USWAP_ENDIANNESS CFLAGS+= -Wall -Wredundant-decls -Wshadow -Wpointer-arith CFLAGS+= -Wstrict-prototypes -Wmissing-declarations -Wundef -Wendif-labels CFLAGS+= -Wstrict-aliasing -Wwrite-strings -Wmissing-prototypes -Wnested-externs -CFLAGS+= -Werror +CFLAGS+= # Flags for dependency generation CFLAGS+= -MMD -MP -MT $@ -MF '$(*D)/$(*F).d' INCLUDES := -I$(SRCDIR)/include -I$(SRCDIR)/kernel/include -I$(ODIR)/target/include diff --git a/forth/device/fcode.fs b/forth/device/fcode.fs index 9083ed0..9035654 100644 --- a/forth/device/fcode.fs +++ b/forth/device/fcode.fs @@ -6,7 +6,25 @@ \ \ See the file "COPYING" for further information about \ the copyright and warranty status of this work. -\ +\ + +\ ***************************************************************************** +\ * 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 +\ ****************************************************************************/ + + +variable ip +variable fcode-end +variable fcode-num +
hex
@@ -460,24 +478,114 @@ defer fcode-c@ \ get byte 2swap then ; immediate - + + + + + + : get-ip ( -- n ) + ip @ + ; + + : set-ip ( n -- ) + ip ! + ; + + : next-ip ( -- ) + get-ip 1+ set-ip + ; + + : ?compile-mode ( -- on|off ) + state @ + ; + + : ?offset16 ( -- true|false ) + fcode-offset 2 = + ; + + : read-byte ( -- n ) + get-ip + ; + + : ?arch64 ( -- true|false ) + cell 8 = + ; + + + + : read-fcode-num16 ( -- n ) + 0 fcode-num ! + ?arch64 IF + read-byte fcode-num 7 + C! + next-ip + read-byte fcode-num 6 + C! + ELSE + read-byte fcode-num 1 + C! + next-ip + read-byte fcode-num 0 + C! + THEN + fcode-num @ + ; + + : read-fcode# ( -- FCode# ) + read-byte + dup 01 0F between IF drop read-fcode-num16 THEN + ; + + : read-fcode-offset + next-ip + ?offset16 IF + read-fcode-num16 + ELSE + read-byte + dup 80 and IF FF00 or THEN \ Fake 16-bit signed offset + THEN + ; + + : dest-on-top + 0 >r BEGIN dup @ 0= WHILE >r REPEAT + BEGIN r> dup WHILE swap REPEAT + drop + ; + + : ?negative + 8000 and + ; + + : jump-n-ip ( n -- ) + get-ip + set-ip + ; + + : ?jump-direction ( n -- ) + dup 8000 >= IF + 10000 - \ Create cell-sized negative value + THEN + fcode-offset - \ IP is already behind offset, so subtract offset size + ;
\ b?branch ( continue? -- ) \ Conditional branch FCode. Followed by FCode-offset.
-: b?branch - fcode-offset 0< if \ if we jump backwards, we can forsee where it goes - ['] do?branch , - resolve-dest - execute-tmp-comp - else - setup-tmp-comp ['] do?branch , - here 0 - 0 , - then - ; immediate +: b?branch ( flag -- ) + ?compile-mode IF + read-fcode-offset ?negative IF + dest-on-top postpone until + ELSE + postpone if + THEN + ELSE + ( flag ) IF + fcode-offset jump-n-ip \ Skip over offset value + ELSE + read-fcode-offset + ?jump-direction jump-n-ip + THEN + THEN + ; immediate
+ + \ b(<mark) ( -- ) \ Target of backward branches.
-- OpenBIOS http://openbios.org/ Mailinglist: http://lists.openbios.org/mailman/listinfo Free your System - May the Forth be with you