From 94cb76520a77c2021fd558567ea5f3f5dbb2de3a Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sun, 5 Jul 2020 07:09:11 -0400 Subject: [PATCH] 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. --- blk/070 | 2 +- blk/091 | 16 ++++++++++++++++ blk/092 | 16 ++++++++++++++++ blk/093 | 3 +++ blk/397 | 8 ++++---- blk/398 | 4 ++-- blk/399 | 7 ++++--- blk/400 | 3 +-- cvm/forth.bin | Bin 5418 -> 5418 bytes 9 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 blk/091 create mode 100644 blk/092 create mode 100644 blk/093 diff --git a/blk/070 b/blk/070 index e4ed657..2fb7318 100644 --- a/blk/070 +++ b/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 diff --git a/blk/091 b/blk/091 new file mode 100644 index 0000000..df0e280 --- /dev/null +++ b/blk/091 @@ -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.) diff --git a/blk/092 b/blk/092 new file mode 100644 index 0000000..045008c --- /dev/null +++ b/blk/092 @@ -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.) diff --git a/blk/093 b/blk/093 new file mode 100644 index 0000000..1ff427d --- /dev/null +++ b/blk/093 @@ -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. diff --git a/blk/397 b/blk/397 index 9773573..26160bf 100644 --- a/blk/397 +++ b/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 ) diff --git a/blk/398 b/blk/398 index 123c6b6..b7a80c9 100644 --- a/blk/398 +++ b/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 ) diff --git a/blk/399 b/blk/399 index a7e6f1b..ce35bbc 100644 --- a/blk/399 +++ b/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 diff --git a/blk/400 b/blk/400 index 28dce6e..3aded5f 100644 --- a/blk/400 +++ b/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! diff --git a/cvm/forth.bin b/cvm/forth.bin index adfae3798c966f2c72d18aa563d57485066239ee..f2e912933487c284c00cedb41de124483d781c65 100644 GIT binary patch delta 44 zcmZ3bwMuKl6A^`I^;j;3X2x3_+k~AMtT`AO8TT_dF(|V?Vvt~TVu