This patchset fixes up the r-stack in interpret mode and the evaluate word so OpenBIOS can boot OS 9 without r-stack corruption or introducing any regressions.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk
v2: - Move r-stack commands to a separate rstack.fs file - Minor tweaks suggested by Segher
Cormac O'Brien (1): interpreter.fs: allow evaluate to split words on CR as well as LF
Mark Cave-Ayland (2): rstack.fs: add pseudo r-stack implementation for interpret mode interpreter.fs: don't clobber stack across evaluate strings split on newlines
forth/bootstrap/interpreter.fs | 4 +++- forth/lib/build.xml | 1 + forth/lib/rstack.fs | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 forth/lib/rstack.fs
The OS 9 boot loader uses the r-stack outside of a word in interpret mode. Provide an r-stack implementation which allows r-stack accesses in interpret mode using a separate pseudo stack.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- forth/lib/build.xml | 1 + forth/lib/rstack.fs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 forth/lib/rstack.fs
diff --git a/forth/lib/build.xml b/forth/lib/build.xml index 34eee40..f1c9a45 100644 --- a/forth/lib/build.xml +++ b/forth/lib/build.xml @@ -8,6 +8,7 @@ -->
<dictionary name="openbios" target="forth"> + <object source="rstack.fs"/> <object source="vocabulary.fs"/> <object source="string.fs"/> <object source="preprocessor.fs"/> diff --git a/forth/lib/rstack.fs b/forth/lib/rstack.fs new file mode 100644 index 0000000..c095a9e --- /dev/null +++ b/forth/lib/rstack.fs @@ -0,0 +1,21 @@ +\ tag: pseudo r-stack implementation for openbios +\ +\ Copyright (C) 2016 Mark Cave-Ayland +\ +\ See the file "COPYING" for further information about +\ the copyright and warranty status of this work. +\ + +\ +\ Pseudo r-stack implementation for interpret mode +\ + +create prstack h# 20 cells allot +variable #prstack 0 #prstack ! + +: prstack-push prstack #prstack @ cells + ! 1 #prstack +! ; +: prstack-pop -1 #prstack +! prstack #prstack @ cells + @ ; + +: >r state @ if ['] >r , exit then r> swap prstack-push >r ; immediate +: r> state @ if ['] r> , exit then r> prstack-pop swap >r ; immediate +: r@ state @ if ['] r@ , exit then r> prstack-pop dup prstack-push swap >r ; immediate
When an evaluate string is split across a newline, the current string position is assumed to be the top-most item on the stack. However in the case of yaboot, items are left on the stack to be used by a subsequent line within the same evaluate statement and so subsequent lines are parsed incorrectly.
Fix this by saving the current string position on the r-stack across calls to (evaluate) so the stack remains correct for subsequent lines.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- forth/bootstrap/interpreter.fs | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/forth/bootstrap/interpreter.fs b/forth/bootstrap/interpreter.fs index 5187058..b66e95e 100644 --- a/forth/bootstrap/interpreter.fs +++ b/forth/bootstrap/interpreter.fs @@ -165,7 +165,9 @@ defer outer-interpreter over + over do i c@ 0a = if i over - + rot >r (evaluate) + r> i 1+ then loop
From: Cormac O'Brien cormac@c-obrien.org
Otherwise the Forth intepreter fails due to lack of buffer space when trying to execute large boot scripts on platforms that use CR instead of LF for line endings (particularly MacOS 9).
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk Signed-off-by: Cormac O'Brien cormac@c-obrien.org Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- forth/bootstrap/interpreter.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/forth/bootstrap/interpreter.fs b/forth/bootstrap/interpreter.fs index b66e95e..f02000f 100644 --- a/forth/bootstrap/interpreter.fs +++ b/forth/bootstrap/interpreter.fs @@ -163,7 +163,7 @@ defer outer-interpreter : evaluate ( str len -- ?? ) 2dup + -rot over + over do - i c@ 0a = if + i c@ dup 0a = swap 0d = or if i over - rot >r (evaluate)
On Jul 17, 2016, at 5:31 PM, Mark Cave-Ayland wrote:
This patchset fixes up the r-stack in interpret mode and the evaluate word so OpenBIOS can boot OS 9 without r-stack corruption or introducing any regressions.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk
v2:
- Move r-stack commands to a separate rstack.fs file
- Minor tweaks suggested by Segher
Cormac O'Brien (1): interpreter.fs: allow evaluate to split words on CR as well as LF
Mark Cave-Ayland (2): rstack.fs: add pseudo r-stack implementation for interpret mode interpreter.fs: don't clobber stack across evaluate strings split on newlines
forth/bootstrap/interpreter.fs | 4 +++- forth/lib/build.xml | 1 + forth/lib/rstack.fs | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 forth/lib/rstack.fs
-- 1.7.10.4
These patches work. They boot Debian Linux, Mac OS 10.4.0, and Mac OS 9.0.4. Excellent job!
On 17/07/16 23:09, Programmingkid wrote:
On Jul 17, 2016, at 5:31 PM, Mark Cave-Ayland wrote:
This patchset fixes up the r-stack in interpret mode and the evaluate word so OpenBIOS can boot OS 9 without r-stack corruption or introducing any regressions.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk
v2:
- Move r-stack commands to a separate rstack.fs file
- Minor tweaks suggested by Segher
Cormac O'Brien (1): interpreter.fs: allow evaluate to split words on CR as well as LF
Mark Cave-Ayland (2): rstack.fs: add pseudo r-stack implementation for interpret mode interpreter.fs: don't clobber stack across evaluate strings split on newlines
forth/bootstrap/interpreter.fs | 4 +++- forth/lib/build.xml | 1 + forth/lib/rstack.fs | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 forth/lib/rstack.fs
-- 1.7.10.4
These patches work. They boot Debian Linux, Mac OS 10.4.0, and Mac OS 9.0.4. Excellent job!
Thanks for the test. I've done a very comprehensive boot test across all architectures and I don't see any regressions, so I've pushed this to the main repository.
ATB,
Mark.