1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 14:18:06 +11:00

Refer to stable wordref by direct offset in "hot zone" immediates

Previously, it was impossible to cross-compile Collapse OS from a
binary-offsetted Collapse OS because stable ABI wordrefs would have
a wrongly offsetted address.

This solves the problem by replacing those wordrefs by direct,
hardcoded stable ABI offset references.
This commit is contained in:
Virgil Dupras 2020-07-05 07:09:11 -04:00
parent 2111f694f6
commit 94cb76520a
9 changed files with 47 additions and 12 deletions

View File

@ -3,4 +3,4 @@ Implementation notes
71 Execution model 73 Executing a word 71 Execution model 73 Executing a word
75 Stack management 77 Dictionary 75 Stack management 77 Dictionary
80 System variables 85 Word types 80 System variables 85 Word types
89 Initialization sequence 89 Initialization sequence 91 Stable ABI

16
blk/091 Normal file
View File

@ -0,0 +1,16 @@
Stable ABI
Across all architectures, some offset are referred to by off-
sets that don't change (well, not without some binary manipu-
lation). Here's the complete list of these references:
04 BOOT addr 06 (uflw) addr 08 LATEST
42 EXIT wordref 53 (br) wordref 67 (?br) wordref
80 (loop) wordref a9 2>R wordref bf (n) wordref
d4 (s) wordref
BOOT and (uflw) exist because they are referred to before those
words are defined (in core words). LATEST is a critical part
of the initialization sequence.
(cont.)

16
blk/092 Normal file
View File

@ -0,0 +1,16 @@
Stable wordrefs are there for more complicated reasons. When
cross-compiling Collapse OS, we use immediate words from the
host and some of them compile wordrefs (IF compiles (?br),
LOOP compiles (loop), etc.). These compiled wordref need to
be stable across binaries, so they're part of the stable ABI.
Another layer of complexity is the fact that some binaries
don't begin at offset 0. In that case, the stable ABI doesn't
begin at 0 either. The EXECUTE word has a special handling of
those case where any wordref < 0x100 has the binary offset
applied to it.
But that's not the end of our problems. If an offsetted binary
cross compiles a binary with a different offset, stable ABI
references will be > 0x100 and be broken.
(cont.)

3
blk/093 Normal file
View File

@ -0,0 +1,3 @@
For this reason, any stable wordref compiled in the "hot zone"
(B397-B400) has to be compiled by direct offset reference to
avoid having any binary offset applied to it.

View File

@ -1,9 +1,9 @@
( Now we have "as late as possible" stuff ) ( Now we have "as late as possible" stuff. See B70 and B270. )
: _bchk DUP 0x7f + 0xff > IF LIT< br-ovfl (print) ABORT THEN ; : _bchk DUP 0x7f + 0xff > IF LIT< br-ovfl (print) ABORT THEN ;
: DO COMPILE 2>R H@ ; IMMEDIATE : DO 0xa9 ( 2>R ) , H@ ; IMMEDIATE
: LOOP COMPILE (loop) H@ - _bchk , ; IMMEDIATE : LOOP 0x80 ( loop ) , H@ - _bchk , ; IMMEDIATE
( LEAVE is implemented in low xcomp ) ( LEAVE is implemented in low xcomp )
: LITN COMPILE (n) , ; : LITN 0xbf ( n ) , , ;
( gets its name at the very end. can't comment afterwards ) ( gets its name at the very end. can't comment afterwards )
: _ BEGIN LIT< ) WORD S= UNTIL ; IMMEDIATE : _ BEGIN LIT< ) WORD S= UNTIL ; IMMEDIATE
: _ ( : will get its name almost at the very end ) : _ ( : will get its name almost at the very end )

View File

@ -1,11 +1,11 @@
: IF ( -- a | a: br cell addr ) : IF ( -- a | a: br cell addr )
COMPILE (?br) H@ 2 ALLOT ( br cell allot ) 0x67 ( ?br ) , H@ 2 ALLOT ( br cell allot )
; IMMEDIATE ; IMMEDIATE
: THEN ( a -- | a: br cell addr ) : THEN ( a -- | a: br cell addr )
DUP H@ -^ _bchk SWAP ( a-H a ) ! DUP H@ -^ _bchk SWAP ( a-H a ) !
; IMMEDIATE ; IMMEDIATE
: ELSE ( a1 -- a2 | a1: IF cell a2: ELSE cell ) : ELSE ( a1 -- a2 | a1: IF cell a2: ELSE cell )
COMPILE (br) 0x53 ( br ) ,
2 ALLOT 2 ALLOT
[COMPILE] THEN [COMPILE] THEN
H@ 2- ( push a. -2 for allot offset ) H@ 2- ( push a. -2 for allot offset )

View File

@ -1,8 +1,9 @@
: LIT< COMPILE (s) WORD DUP C@ 1+ MOVE, ; IMMEDIATE : LIT< 0xd4 ( s ) , WORD DUP C@ 1+ MOVE, ; IMMEDIATE
: BEGIN H@ ; IMMEDIATE : BEGIN H@ ; IMMEDIATE
: AGAIN COMPILE (br) H@ - _bchk , ; IMMEDIATE : AGAIN 0x53 ( br ) , H@ - _bchk , ; IMMEDIATE
: UNTIL COMPILE (?br) H@ - _bchk , ; IMMEDIATE : UNTIL 0x67 ( ?br ) , H@ - _bchk , ; IMMEDIATE
: [ INTERPRET ; IMMEDIATE : [ INTERPRET ; IMMEDIATE
: ] R> DROP ; : ] R> DROP ;
: COMPILE ' LITN ['] , , ; IMMEDIATE : COMPILE ' LITN ['] , , ; IMMEDIATE
: [COMPILE] ' , ; IMMEDIATE : [COMPILE] ' , ; IMMEDIATE
: ['] ' LITN ; IMMEDIATE

View File

@ -2,10 +2,9 @@
is not an IMMEDIATE yet and will not be treated properly by is not an IMMEDIATE yet and will not be treated properly by
xcomp. ) xcomp. )
: _ : _
['] EXIT , 0x42 ( EXIT ) ,
R> DROP ( exit : ) R> DROP ( exit : )
; IMMEDIATE ; IMMEDIATE
: ['] ' LITN ; IMMEDIATE
';' X' _ 4 - C! ( give ; its name ) ';' X' _ 4 - C! ( give ; its name )
':' X' _ 4 - C! ( give : its name ) ':' X' _ 4 - C! ( give : its name )
'(' X' _ 4 - C! '(' X' _ 4 - C!

Binary file not shown.