I wanted to share what I found out. If I remove the '\r' to '\n' patch that allows Mac OS 9 to boot, the boot script will stop executing at a r> word. This is the position:
<BOOT-SCRIPT> here >r dev / cr ." Checkpoint 1" cr " model" active-package get-package-property abort" can't find MODEL" decode-string 2swap 2drop " iMac,1" $= ?dup 0= if " compatible" active-package get-package-property abort" can't find COMPATIBLE" false >r ." checkpoint 1.5" cr begin dup while decode-string here over 2swap bounds ?do i c@ dup [char] A [char] Z between if h# 20 xor then c, loop 2dup " macrisc" $= r> or >r 2drop repeat ." checkpoint 1.7" cr 2drop r> ." checkpoint 1.7.1" cr then ." checkpoint 1.7.2" cr
r> <--------------- This is where execution stops
." Checkpoint 1.7.3" cr here ." Checkpoint 1.7.4" cr - allot ." checkpoint 1.8" cr 0= abort" this image is not for this platform" decimal 1 ." Checkpoint2" cr load-base load-size 14 - adler32 load-base load-size + 12 - 12 ['] eval catch if 2drop ." , bad checksum value" -1 then <> if ." , checksum error" cr \ abort ." Problem ignored :)" cr then hex dev /openprom 0 0 " supports-bootinfo" property device-end " /chosen" find-package 0= abort" can't find '/chosen'" constant /chosen " memory" /chosen get-package-property abort" memory??" decode-int constant xmem 2drop " mmu" /chosen get-package-property abort" mmu??" decode-int constant xmmu 2drop " AAPL,debug" " /" find-package 0= abort" can't find '/'" get-package-property if false else 2drop true then ." Checkpoint 3" cr constant debug? debug? if cr ." checking for RELEASE-LOAD-AREA" then " release-load-area" $find 0= if 2drop false then constant 'release-load-area debug? if 'release-load-area if ." , found it" else ." , not found" then then : do-translate " translate" xmmu $call-method ; : do-map " map" xmmu $call-method ; : do-unmap " unmap" xmmu $call-method ; : claim-mem " claim" xmem $call-method ; : release-mem " release" xmem $call-method ; : claim-virt " claim" xmmu $call-method ; : release-virt " release" xmmu $call-method ; 1000 constant pagesz pagesz 1- constant pagesz-1 -1000 constant pagemask h# 005000 constant elf-offset h# 017008 constant elf-size elf-size pagesz-1 + pagemask and constant elf-pages h# 01C008 ." Checkpoint 4" cr constant parcels-offset h# 2617C4 constant parcels-size parcels-size pagesz-1 + pagemask and constant parcels-pages h# 27D7CC constant info-size info-size pagesz-1 + pagemask and constant info-pages 0 value load-base-claim 0 value info-base 'release-load-area if load-base to info-base else load-base info-pages 0 ['] claim-mem catch if 3drop 0 then to load-base-claim info-pages 1000 claim-virt to info-base load-base info-base info-pages 10 do-map then \ allocate room for both images parcels-pages 400000 claim-mem constant ." Checkpoint 5" cr rom-phys parcels-pages 1000 claim-virt constant rom-virt rom-phys rom-virt parcels-pages 10 do-map elf-pages 1000 claim-mem constant elf-phys elf-pages 1000 claim-virt constant elf-virt elf-phys elf-virt elf-pages 10 do-map info-base elf-offset + elf-virt elf-size move debug? if cr ." elf-phys,elf-virt,elf-pages: " elf-phys u. ." , " elf-virt u. ." , " elf-pages u. then \ copy the compressed image debug? if cr ." copying compressed ROM image" then rom-virt parcels-pages 0 fill info-base parcels-offset ." Checkpoint 6" cr + rom-virt parcels-size move 'release-load-area 0= if info-base info-pages do-unmap load-base-claim ?dup if info-pages release-mem then then debug? if cr ." MacOS-ROM phys,virt,size: " rom-phys u. ." , " rom-virt u. ." , " parcels-size u. then \ create the actual property debug? if cr ." finding/creating '/rom/macos' package" then device-end 0 to my-self " /rom" find-device " macos" ['] find-device catch if 2drop new-device " macos" device-name finish-device then " /rom/macos" find-device debug? if cr ." creating 'AAPL,toolbox-parcels' property" then rom-virt encode-int ." Checkpoint 7" cr parcels-size encode-int encode+ " AAPL,toolbox-parcels" property device-end debug? if cr ." copying MacOS.elf to load-base" then 'release-load-area if load-base elf-pages + 'release-load-area execute else load-base elf-pages 0 claim-mem load-base dup elf-pages 0 do-map then elf-virt ." Checkpoint 9" cr load-base elf-size move elf-virt elf-pages do-unmap elf-virt elf-pages release-virt elf-phys elf-pages release-mem debug? if cr ." init-program" then init-program debug? if cr ." .registers" .registers then debug? ." REACHED THE END" CR if cr ." go" cr then go cr ." end of BOOT-SCRIPT" </BOOT-SCRIPT>
This boot script was taken from the Mac OS 9 file "Mac OS ROM".
Does anyone have any idea why removing '\r' characters from the script makes it work?
On 2016-Apr-16 12:48 , Programmingkid wrote:
I wanted to share what I found out. If I remove the '\r' to '\n' patch that allows Mac OS 9 to boot, the boot script will stop executing at a r> word. This is the position:
<BOOT-SCRIPT> here >r dev / cr ." Checkpoint 1" cr " model" active-package get-package-property abort" can't find MODEL" [...]
r> <--------------- This is where execution stops
[...] This boot script was taken from the Mac OS 9 file "Mac OS ROM".
Does anyone have any idea why removing '\r' characters from the script makes it work?
I'm baffled. There are two other lines above which are end-of-line sensitive, using the "dev" word:
dev ( "device-specifier<eol>" -- ) Make the specified device node the active package.
Parse device-specifier delimited by end of line. Perform the equivalent of find-device with device-specifier as its argument.
Used as: ok dev device-specifier <eol>
You could try replacing the two lines with the equivalent find-device operations:
" /" find-device " /openprom" find-device
which aren't end-of-line sensitive, but if that were the problem, we wouldn't be seeing the checkpoint 1 message.
Usually when something blows up on a r>, that means the return stack has been clobbered - and I don't see anything there that looks like it would clobber it based on an eol. Microsoft Word - 1275.DOC
On 16/04/16 17:48, Programmingkid wrote:
I wanted to share what I found out. If I remove the '\r' to '\n' patch that allows Mac OS 9 to boot, the boot script will stop executing at a r> word. This is the position:
<BOOT-SCRIPT> here >r dev / cr ." Checkpoint 1" cr " model" active-package get-package-property abort" can't find MODEL" decode-string 2swap 2drop " iMac,1" $= ?dup 0= if " compatible" active-package get-package-property abort" can't find COMPATIBLE" false >r ." checkpoint 1.5" cr begin dup while decode-string here over 2swap bounds ?do i c@ dup [char] A [char] Z between if h# 20 xor then c, loop 2dup " macrisc" $= r> or >r 2drop repeat ." checkpoint 1.7" cr 2drop r> ." checkpoint 1.7.1" cr then ." checkpoint 1.7.2" cr
r> <--------------- This is where execution stops
Right, this is exactly the same issue. The Forth interpreter executes the boot script in interpret mode so as soon as it hits a command to alter the r-stack in boot script (which is not supposed to happen outside of a Forth word) then the interpreter itself gets confused and execution stops.
It just so happens that if you feed the chunks into the Forth interpreter in chunks between newlines then it works, but this is really just a lucky coincidence that things work out in this way.
ATB,
Mark.
On Apr 16, 2016, at 2:49 PM, Mark Cave-Ayland wrote:
On 16/04/16 17:48, Programmingkid wrote:
I wanted to share what I found out. If I remove the '\r' to '\n' patch that allows Mac OS 9 to boot, the boot script will stop executing at a r> word. This is the position:
<BOOT-SCRIPT> here >r dev / cr ." Checkpoint 1" cr " model" active-package get-package-property abort" can't find MODEL" decode-string 2swap 2drop " iMac,1" $= ?dup 0= if " compatible" active-package get-package-property abort" can't find COMPATIBLE" false >r ." checkpoint 1.5" cr begin dup while decode-string here over 2swap bounds ?do i c@ dup [char] A [char] Z between if h# 20 xor then c, loop 2dup " macrisc" $= r> or >r 2drop repeat ." checkpoint 1.7" cr 2drop r> ." checkpoint 1.7.1" cr then ." checkpoint 1.7.2" cr
r> <--------------- This is where execution stops
Right, this is exactly the same issue. The Forth interpreter executes the boot script in interpret mode so as soon as it hits a command to alter the r-stack in boot script (which is not supposed to happen outside of a Forth word) then the interpreter itself gets confused and execution stops.
Do you have any documentation that states r> can't be used outside of a word? In my book "Forth Programmer's Handbook", it doesn't say anything having to be ran inside of a word.
Maybe Apple's implementation of r> is a little different.
It just so happens that if you feed the chunks into the Forth interpreter in chunks between newlines then it works, but this is really just a lucky coincidence that things work out in this way.
Maybe it is a word somewhere that doesn't consider '\r' to be a whitespace character. Words that might be a problem could be any word that gets its input from the boot script. dev, abort", active-package, and [char] come to mind.