[OpenBIOS] r638 - in trunk/openbios-devel/forth: bootstrap device

svn at openbios.org svn at openbios.org
Thu Dec 3 16:47:39 CET 2009


Author: mcayland
Date: 2009-12-03 16:47:39 +0100 (Thu, 03 Dec 2009)
New Revision: 638

Modified:
   trunk/openbios-devel/forth/bootstrap/bootstrap.fs
   trunk/openbios-devel/forth/device/fcode.fs
Log:
Fix backwards Fcode branches (bbranch and b?branch). 

According to the specification, the destination for a backwards Fcode branch must be resolved from the bottom rather than the 
top of the cstack. The existing version of the code was simply doing a swap, and so nesting any branches within a backward branch 
would fail since the wrong destination would be resolved from the stack.

This patch adds a new cstack-startdepth variable to keep track of the cstack base location within an execution context 
(setup-tmp-comp and execute-tmp-comp) and alters the backward branches to make use of it.

With this patch in place, Milax under Qemu doesn't crash anymore but sits in an infinite loop reading sectors from the CDROM.


Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at siriusit.co.uk>



Modified: trunk/openbios-devel/forth/bootstrap/bootstrap.fs
===================================================================
--- trunk/openbios-devel/forth/bootstrap/bootstrap.fs	2009-12-02 10:44:35 UTC (rev 637)
+++ trunk/openbios-devel/forth/bootstrap/bootstrap.fs	2009-12-03 15:47:39 UTC (rev 638)
@@ -166,6 +166,8 @@
 variable tmp-comp-depth -1 tmp-comp-depth !
 variable tmp-comp-buf 0 tmp-comp-buf !
 
+variable cstack-startdepth -1 cstack-startdepth ! \ start depth of the cstack
+
 : setup-tmp-comp ( -- )
   state @ 0 = (if)
     here tmp-comp-buf @ here! ,     \ save here and switch to tmp directory
@@ -173,9 +175,20 @@
     depth tmp-comp-depth !          \ save control depth
     ]
   (then)
+
+  \ If start of new execution context, record the location of the bottom
+  \ of the new cstack (required for backwards Fcode branches)
+  cstack-startdepth @ -1 = (if)
+    depth cstack-startdepth !
+  (then)
 ;
 
 : execute-tmp-comp ( -- )
+  \ If at the end of this execution context, reset cstack location
+  depth cstack-startdepth @ = (if)
+    -1 cstack-startdepth !
+  (then)
+
   depth tmp-comp-depth @ =
   (if)
     -1 tmp-comp-depth !

Modified: trunk/openbios-devel/forth/device/fcode.fs
===================================================================
--- trunk/openbios-devel/forth/device/fcode.fs	2009-12-02 10:44:35 UTC (rev 637)
+++ trunk/openbios-devel/forth/device/fcode.fs	2009-12-03 15:47:39 UTC (rev 638)
@@ -451,7 +451,8 @@
 : bbranch
   fcode-offset 0< if \ if we jump backwards, we can forsee where it goes
     ['] dobranch ,
-    swap
+    \ Backwards branches are resolved from the bottom of the cstack
+    depth cstack-startdepth @ 1+ - roll
     resolve-dest
     execute-tmp-comp
   else
@@ -469,6 +470,8 @@
 : b?branch
   fcode-offset 0< if \ if we jump backwards, we can forsee where it goes
     ['] do?branch ,
+    \ Backwards branches are resolved from the bottom of the cstack
+    depth cstack-startdepth @ 1+ - roll
     resolve-dest
     execute-tmp-comp
   else




More information about the OpenBIOS mailing list