[OpenBIOS] [PATCH] libopenbios/bootinfo_load.c: Implement Mac OS 9.2 boot script support

Programmingkid programmingkidx at gmail.com
Mon May 2 02:27:59 CEST 2016


On May 1, 2016, at 6:28 AM, Mark Cave-Ayland wrote:

> On 27/04/16 11:14, BALATON Zoltan wrote:
> 
>> On Tue, 26 Apr 2016, Programmingkid wrote:
>>> On Apr 26, 2016, at 4:11 PM, BALATON Zoltan wrote:
>>>> On Tue, 26 Apr 2016, Programmingkid wrote:
>>>>> This patch makes booting Mac OS 9.2 possible. It replaces all
>>>>> occurrences of
>>>>>> r and r> with sub_>r and sub_r>. This allows for the return stack
>>>>>> to be left
>>>>> alone.
>>>> 
>>>> Can we have Segher's Forth version of this instead:
>>>> 
>>>> https://www.coreboot.org/pipermail/openbios/2016-April/009338.html
>>>> 
>>>> That should be equivalent and would make the C code much simpler and
>>>> allow dropping most of these patches.
>>> 
>>> That code doesn't work. It causes a "Dictionary space overflow" message
>>> to be printed. My code does work.
>> 
>> Maybe you need to increase the available cells to have enough space? I
>> don't know much about Forth to understand the code better.
> 
> I think Segher's version is closer to what we are trying to achieve -
> there is a lot of extra code added for something where the end result
> isn't excessively context. Can you find out with the Forth debugger
> exactly why Segher's patch is failing?

I decided to recreate his patch. Here it is below:

Index: forth/lib/vocabulary.fs
===================================================================
--- forth/lib/vocabulary.fs	(revision 1395)
+++ forth/lib/vocabulary.fs	(working copy)
@@ -151,3 +151,46 @@
   ;
  
 true to vocabularies?
+
+VARIABLE max-stack-size
+100 max-stack-size !
+CREATE stash-stack max-stack-size @ CELLS ALLOT \ make a stack that can hold CELL values
+VARIABLE stash-stack-pointer    \ Keeps track of top of stack
+0 stash-stack-pointer !         \ Set initial value to zero
+
+
+\ pushes a value on the stash stack
+: stash-push ( n -- ) 
+    \ check for overflow before pushing value
+    stash-stack-pointer @
+    max-stack-size @ 1-
+    >
+    if ." Warning: stack limit reached" cr EXIT then
+
+    \ ." current stack pointer value = " stash-stack-pointer @ .
+    stash-stack stash-stack-pointer @ CELLS + !  \ calculate address then store value
+    stash-stack-pointer @ 1 +     \ calculate new value for stack pointer
+    stash-stack-pointer !   \ increment the stack pointer
+;   
+
+\ pops a value from the stash stack
+: stash-pop ( -- n )
+    stash-stack-pointer @ 1 -   \ calculate new value for the stack pointer
+    dup ( new-stack-pointer new-stack-pointer )
+    0 ( new-stack-pointer new-stack-pointer 0)
+    < ( new-stack-pointer boolean )
+    if ( new-stack-pointer )
+        drop 0 ( 0 )
+        ." Warning: stack underflow detected" cr 
+    else 
+        ( new-stack-pointer )
+    then
+    stash-stack-pointer !   \ store new value in stack pointer
+    stash-stack-pointer @   \ get the value of stash-stack-pointer
+    CELLS stash-stack + @ \ calculate address then return value
+    \ ." current stack pointer value = " stash-stack-pointer @ .
+;
+
+: >r  state @ IF postpone >r EXIT THEN  stash-push ; IMMEDIATE
+: r>  state @ IF postpone r> EXIT THEN  stash-pop ; IMMEDIATE
+: r@  state @ IF postpone r@ EXIT THEN  stash-pop dup stash-push ; IMMEDIATE

The stash-push and stash-pop words do work. A simple test I did is this:

0 > 100 stash-push  ok
0 > 200 stash-push  ok
0 > 300 stash-push  ok
0 > stash-pop  ok
1 > showstack  ok
300 < 1 > stash-pop  ok
300 200 < 2 > stash-pop  ok
300 200 100 < 3 >

The end result was OpenBIOS not being able to boot Mac OS 9.2. Running the boot script one line at a time does work. 





More information about the OpenBIOS mailing list