From dbc5a9c3ba947728e261552f4b63fd82e0dc37ec Mon Sep 17 00:00:00 2001 From: Mark Cave-Ayland Date: Thu, 3 Dec 2009 15:47:39 +0000 Subject: [PATCH] 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 git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@638 f158a5a8-5612-0410-a976-696ce0be7e32 --- forth/bootstrap/bootstrap.fs | 13 +++++++++++++ forth/device/fcode.fs | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/forth/bootstrap/bootstrap.fs b/forth/bootstrap/bootstrap.fs index 0957922..1173469 100644 --- a/forth/bootstrap/bootstrap.fs +++ b/forth/bootstrap/bootstrap.fs @@ -166,6 +166,8 @@ defer environment? 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 @@ variable tmp-comp-buf 0 tmp-comp-buf ! 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 ! diff --git a/forth/device/fcode.fs b/forth/device/fcode.fs index e4f9f4e..3c8c830 100644 --- a/forth/device/fcode.fs +++ b/forth/device/fcode.fs @@ -451,7 +451,8 @@ defer fcode-c@ \ get byte : 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 @@ defer fcode-c@ \ get byte : 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