mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-23 19:28: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:
parent
2111f694f6
commit
94cb76520a
2
blk/070
2
blk/070
@ -3,4 +3,4 @@ Implementation notes
|
||||
71 Execution model 73 Executing a word
|
||||
75 Stack management 77 Dictionary
|
||||
80 System variables 85 Word types
|
||||
89 Initialization sequence
|
||||
89 Initialization sequence 91 Stable ABI
|
||||
|
16
blk/091
Normal file
16
blk/091
Normal 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
16
blk/092
Normal 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
3
blk/093
Normal 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.
|
8
blk/397
8
blk/397
@ -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 ;
|
||||
: DO COMPILE 2>R H@ ; IMMEDIATE
|
||||
: LOOP COMPILE (loop) H@ - _bchk , ; IMMEDIATE
|
||||
: DO 0xa9 ( 2>R ) , H@ ; IMMEDIATE
|
||||
: LOOP 0x80 ( loop ) , H@ - _bchk , ; IMMEDIATE
|
||||
( LEAVE is implemented in low xcomp )
|
||||
: LITN COMPILE (n) , ;
|
||||
: LITN 0xbf ( n ) , , ;
|
||||
( gets its name at the very end. can't comment afterwards )
|
||||
: _ BEGIN LIT< ) WORD S= UNTIL ; IMMEDIATE
|
||||
: _ ( : will get its name almost at the very end )
|
||||
|
4
blk/398
4
blk/398
@ -1,11 +1,11 @@
|
||||
: IF ( -- a | a: br cell addr )
|
||||
COMPILE (?br) H@ 2 ALLOT ( br cell allot )
|
||||
0x67 ( ?br ) , H@ 2 ALLOT ( br cell allot )
|
||||
; IMMEDIATE
|
||||
: THEN ( a -- | a: br cell addr )
|
||||
DUP H@ -^ _bchk SWAP ( a-H a ) !
|
||||
; IMMEDIATE
|
||||
: ELSE ( a1 -- a2 | a1: IF cell a2: ELSE cell )
|
||||
COMPILE (br)
|
||||
0x53 ( br ) ,
|
||||
2 ALLOT
|
||||
[COMPILE] THEN
|
||||
H@ 2- ( push a. -2 for allot offset )
|
||||
|
7
blk/399
7
blk/399
@ -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
|
||||
: AGAIN COMPILE (br) H@ - _bchk , ; IMMEDIATE
|
||||
: UNTIL COMPILE (?br) H@ - _bchk , ; IMMEDIATE
|
||||
: AGAIN 0x53 ( br ) , H@ - _bchk , ; IMMEDIATE
|
||||
: UNTIL 0x67 ( ?br ) , H@ - _bchk , ; IMMEDIATE
|
||||
: [ INTERPRET ; IMMEDIATE
|
||||
: ] R> DROP ;
|
||||
: COMPILE ' LITN ['] , , ; IMMEDIATE
|
||||
: [COMPILE] ' , ; IMMEDIATE
|
||||
: ['] ' LITN ; IMMEDIATE
|
||||
|
3
blk/400
3
blk/400
@ -2,10 +2,9 @@
|
||||
is not an IMMEDIATE yet and will not be treated properly by
|
||||
xcomp. )
|
||||
: _
|
||||
['] EXIT ,
|
||||
0x42 ( EXIT ) ,
|
||||
R> DROP ( exit : )
|
||||
; IMMEDIATE
|
||||
: ['] ' LITN ; IMMEDIATE
|
||||
';' X' _ 4 - C! ( give ; its name )
|
||||
':' X' _ 4 - C! ( give : its name )
|
||||
'(' X' _ 4 - C!
|
||||
|
BIN
cvm/forth.bin
BIN
cvm/forth.bin
Binary file not shown.
Loading…
Reference in New Issue
Block a user