| @@ -40,24 +40,32 @@ coding standard · 39 unmodified lines |
| 40 | .. fn ; | 40 | .. fn ; |
| 41 | | 41 | |
| 42 | Heap memory map: uses 8 pages at the start, will increase by *2 when filled up | 42 | Heap memory map: uses 8 pages at the start, will increase by *2 when filled up |
| 43 | Variables | 43 | H0: variables |
| 44 | system variables | | |
| 45 | heap start, heapstart, also in H0 | 44 | heap start, heapstart, also in H0 |
| 46 | heap size, heapsize | 45 | heap size, heapsize |
| 47 | forth stack pointer, forthsp | 46 | forth stack pointer, forthsp |
| 48 | dictionary top, dtop | 47 | dictionary pointer, Dp |
| | 48 | latest dictionary entry, Dtop |
| | 49 | need this as the system definitions and |
| | 50 | user definitions are not continuous |
| 49 | error string buffer 128 bytes | 51 | error string buffer 128 bytes |
| 50 | word buffer 512 bytes | 52 | word buffer 512 bytes |
| 51 | tib, text input buffer 1024 bytes (until the next page?) | 53 | User dictionary upto pages from the start |
| 52 | User dictionary upto 6 pages from the start | | |
| 53 | Return stack 1 page (4096 bytes, BY2PG, 512 entries) at FFSTART | | |
| 54 | | | 54 | | |
| 55 | | | 55 | | |
| 56 | v (grows downwards) | 56 | v (grows downwards) |
| | 57 | ^ (grows upwards) |
| | 58 | | |
| | 59 | | |
| 57 | Parameter stack 1 page (BY2PG, 512 entries) at FFEND-4096 | 60 | Parameter stack 1 page (BY2PG, 512 entries) at FFEND-4096 |
| | 61 | tib, text input buffer 1024 bytes (until the next page?) |
| | 62 | | |
| | 63 | | |
| | 64 | v (grows downwards) |
| 58 | ^ (grows upwards) | 65 | ^ (grows upwards) |
| 59 | | | 66 | | |
| 60 | | | 67 | | |
| | 68 | Return stack 1 page (4096 bytes, BY2PG, 512 entries) at FFSTART |
| 61 | SSTACK_END = FORTHEND | 69 | SSTACK_END = FORTHEND |
| 62 | */ | 70 | */ |
| 63 | | 71 | |
| @@ -71,36 +79,45 @@ SSTACK_END = FORTHEND · 7 unmodified lines |
| 71 | #define PSTACK_SIZE BY2PG | 79 | #define PSTACK_SIZE BY2PG |
| 72 | #define RSTACK_SIZE BY2PG | 80 | #define RSTACK_SIZE BY2PG |
| 73 | | 81 | |
| | 82 | /* |
| | 83 | * user table at the start unlike in Starting Forth as it will be |
| | 84 | * easy to get to the variables with an offset |
| | 85 | */ |
| 74 | #define HEAPSTART (0ull) | 86 | #define HEAPSTART (0ull) |
| 75 | #define HEAPEND (HEAPSTART+8) | 87 | #define HEAPEND (HEAPSTART+(BY2WD*1)) |
| 76 | #define FORTHSP (HEAPSTART+16) | 88 | #define FORTHSP (HEAPSTART+(BY2WD*2)) |
| 77 | #define DTOP (HEAPSTART+24) | 89 | #define DP (HEAPSTART+(BY2WD*3)) /* cannot use H as it is nil in inferno |
| | 90 | next available cell for the dictionary */ |
| | 91 | #define DTOP (HEAPSTART+(BY2WD*4)) |
| 78 | /* variables used by the core words */ | 92 | /* variables used by the core words */ |
| 79 | #define TOIN (HEAPSTART+32) | 93 | #define TOIN (HEAPSTART+(BY2WD*5)) |
| 80 | #define TOLIMIT (HEAPSTART+40) | 94 | #define TOLIMIT (HEAPSTART+(BY2WD*6)) |
| 81 | #define FINDADR (HEAPSTART+48) | 95 | #define FINDADR (HEAPSTART+(BY2WD*7)) |
| 82 | #define BLK (HEAPSTART+56) | 96 | #define BLK (HEAPSTART+(BY2WD*8)) |
| 83 | #define ARGS (HEAPSTART+64) | 97 | #define ARGS (HEAPSTART+(BY2WD*9)) |
| 84 | #define IOBUF (HEAPSTART+72) | 98 | #define IOBUF (HEAPSTART+(BY2WD*10)) |
| 85 | #define SEARCHLEN (HEAPSTART+80) | 99 | #define SEARCHLEN (HEAPSTART+(BY2WD*11)) |
| 86 | #define BASE (HEAPSTART+88) | 100 | #define BASE (HEAPSTART+(BY2WD*12)) |
| 87 | #define TONUM (HEAPSTART+96) | 101 | #define TONUM (HEAPSTART+(BY2WD*13)) |
| 88 | #define STATE (HEAPSTART+104) | 102 | #define STATE (HEAPSTART+(BY2WD*14)) |
| 89 | #define ABORTVEC (HEAPSTART+112) | 103 | #define ABORTVEC (HEAPSTART+(BY2WD*15)) |
| 90 | #define SOURCEBUF (HEAPSTART+120) | 104 | #define SOURCEBUF (HEAPSTART+(BY2WD*16)) |
| 91 | #define WORDBUF (HEAPSTART+128) | 105 | #define WORDBUF (HEAPSTART+(BY2WD*17)) |
| 92 | #define INFD (HEAPSTART+136) | 106 | #define INFD (HEAPSTART+(BY2WD*18)) |
| 93 | #define OUTFD (HEAPSTART+144) | 107 | #define OUTFD (HEAPSTART+(BY2WD*19)) |
| 94 | #define ERRFD (HEAPSTART+152) | 108 | #define ERRFD (HEAPSTART+(BY2WD*20)) |
| 95 | | 109 | |
| 96 | #define ERRSTR (HEAPSTART+160) | 110 | #define ERRSTR (HEAPSTART+(BY2WD*32)) |
| 97 | #define WORDB (HEAPSTART+288) /* word buffer */ | 111 | #define WORDB (HEAPSTART+(BY2WD*160)) /* word buffer */ |
| 98 | #define TIB (HEAPSTART+792) /* text input buffer */ | 112 | |
| 99 | #define DICTIONARY (HEAPSTART+2048) | 113 | #define DICTIONARY (HEAPSTART+2048) /* dictionary */ |
| 100 | #define DICTIONARY_END (HEAPSTART+(6*BY2PG)) | 114 | #define DICTIONARY_END (HEAPSTART+(6*BY2PG)) |
| 101 | #define RSTACK (HEAPSTART+(6*BY2PG)) | 115 | #define PSTACK (HEAPSTART+(6*BY2PG)) |
| 102 | #define PSTACK_END (RSTACK+(2*BY2PG)) | 116 | #define PSTACK_END (HEAPSTART+(7*BY2PG)) |
| 103 | #define FORTHEND PSTACK_END | 117 | #define TIB (HEAPSTART+(7*BY2PG)) /* text input buffer */ |
| | 118 | #define RSTACK (HEAPSTART+(8*BY2PG)) |
| | 119 | #define RSTACK_END (HEAPSTART+(9*BY2PG)) |
| | 120 | #define FORTHEND RSTACK_END |
| 104 | #define HEAPSIZE FORTHEND | 121 | #define HEAPSIZE FORTHEND |
| 105 | | 122 | |
| 106 | #define LAST $centry_c_boot(SB) /* last defined word, should generate this */ | 123 | #define LAST $centry_c_boot(SB) /* last defined word, should generate this */ |
| @@ -123,10 +140,11 @@ TEXT forthmain(SB), 1, $-4 /* _main(SB), 1, $-4 without the libc */ · 16 unmodified lines |
| 123 | MOVQ RARG, H0 /* start of heap memory */ | 140 | MOVQ RARG, H0 /* start of heap memory */ |
| 124 | | 141 | |
| 125 | MOVQ H0, RSP | 142 | MOVQ H0, RSP |
| 126 | ADDQ $RSTACK, RSP /* return stack pointer, reset */ | 143 | ADDQ $RSTACK_END, RSP /* return stack pointer, reset */ |
| 127 | | 144 | |
| 128 | MOVQ H0, PSP | 145 | MOVQ H0, PSP |
| 129 | ADDQ $FORTHEND, PSP /* parameter stack pointer - stack setup, clear */ | 146 | ADDQ $PSTACK_END, PSP /* parameter stack pointer - stack setup, clear */ |
| | 147 | MOVQ PSP, 16(H0) /* parameter stack pointer store, for forth to c */ |
| 130 | | 148 | |
| 131 | MOVQ H0, TOP | 149 | MOVQ H0, TOP |
| 132 | ADDQ $HEAPSTART, TOP | 150 | ADDQ $HEAPSTART, TOP |
| @@ -134,8 +152,10 @@ TEXT forthmain(SB), 1, $-4 /* _main(SB), 1, $-4 without the libc */ · 1 unmodified line |
| 134 | ADDQ $(HEAPSIZE-1), TOP | 152 | ADDQ $(HEAPSIZE-1), TOP |
| 135 | MOVQ TOP, 8(H0) /* heap end */ | 153 | MOVQ TOP, 8(H0) /* heap end */ |
| 136 | | 154 | |
| 137 | MOVQ PSP, 16(H0) /* parameter stack pointer */ | 155 | MOVQ H0, TOP |
| 138 | MOVQ $centry_c_boot(SB), 24(H0) /* Last dictionary entry address */ | 156 | ADDQ $DICTIONARY, TOP |
| | 157 | MOVQ TOP, 24(H0) /* dictionary pointer */ |
| | 158 | MOVQ $centry_c_boot(SB), 24(H0) /* Latest dictionary entry address */ |
| 139 | | 159 | |
| 140 | /* execute boot */ | 160 | /* execute boot */ |
| 141 | MOVQ $centry_c_boot(SB), IP | 161 | MOVQ $centry_c_boot(SB), IP |
| @@ -162,33 +182,34 @@ Assume IP = 8 · 20 unmodified lines |
| 162 | MOVQ r, (PSP) | 182 | MOVQ r, (PSP) |
| 163 | #define POP(r) MOVQ (PSP), r; \ | 183 | #define POP(r) MOVQ (PSP), r; \ |
| 164 | ADDQ $8, PSP | 184 | ADDQ $8, PSP |
| | 185 | #define RPUSH(r) SUBQ $8, RSP; \ |
| | 186 | MOVQ r, (RSP) |
| | 187 | #define RPOP(r) MOVQ (RSP), r; \ |
| | 188 | ADDQ $8, RSP |
| 165 | | 189 | |
| 166 | NEXT | 190 | NEXT |
| 167 | | 191 | |
| 168 | TEXT reset(SB), 1, $-4 | 192 | TEXT reset(SB), 1, $-4 |
| 169 | MOVQ H0, RSP | 193 | MOVQ H0, RSP |
| 170 | ADDQ $RSTACK, RSP | 194 | ADDQ $RSTACK_END, RSP |
| 171 | NEXT | 195 | NEXT |
| 172 | | 196 | |
| 173 | TEXT clear(SB), 1, $-4 | 197 | TEXT clear(SB), 1, $-4 |
| 174 | MOVQ H0, PSP | 198 | MOVQ H0, PSP |
| 175 | ADDQ $FFEND, PSP | 199 | ADDQ $PSTACK_END, PSP |
| 176 | NEXT | 200 | NEXT |
| 177 | | 201 | |
| 178 | TEXT colon(SB), 1, $-4 | 202 | TEXT colon(SB), 1, $-4 |
| 179 | MOVQ IP,(RSP) | 203 | RPUSH(IP) |
| 180 | ADDQ $8, RSP | | |
| 181 | LEAQ 8(W), IP | 204 | LEAQ 8(W), IP |
| 182 | NEXT | 205 | NEXT |
| 183 | | 206 | |
| 184 | TEXT exitcolon(SB), 1, $-4 | 207 | TEXT exitcolon(SB), 1, $-4 |
| 185 | SUBQ $8, RSP | 208 | RPOP(IP) |
| 186 | MOVQ (RSP), IP | | |
| 187 | NEXT | 209 | NEXT |
| 188 | | 210 | |
| 189 | TEXT dodoes(SB), 1, $-4 /* ( -- a ) */ | 211 | TEXT dodoes(SB), 1, $-4 /* ( -- a ) */ |
| 190 | MOVQ IP,(RSP) | 212 | RPUSH(IP) |
| 191 | ADDQ $8,RSP | | |
| 192 | MOVQ 8(W),IP | 213 | MOVQ 8(W),IP |
| 193 | PUSH(TOP) | 214 | PUSH(TOP) |
| 194 | LEAQ 16(W), TOP | 215 | LEAQ 16(W), TOP |
| @@ -306,25 +327,23 @@ doloop1: · 111 unmodified lines |
| 306 | NEXT | 327 | NEXT |
| 307 | | 328 | |
| 308 | TEXT doploop(SB), 1, $-4 /* ( n -- ) */ | 329 | TEXT doploop(SB), 1, $-4 /* ( n -- ) */ |
| 309 | ADDQ TOP, -16(RSP) | 330 | ADDQ TOP, 16(RSP) |
| 310 | POP(TOP) | 331 | POP(TOP) |
| 311 | JMP doloop1 | 332 | JMP doloop1 |
| 312 | | 333 | |
| 313 | TEXT rfetch(SB), 1, $-4 /* ( -- n ) */ | 334 | TEXT rfetch(SB), 1, $-4 /* ( -- n ) no change in RSP */ |
| 314 | PUSH(TOP) | 335 | PUSH(TOP) |
| 315 | MOVQ -8(RSP), TOP | 336 | MOVQ (RSP), TOP |
| 316 | NEXT | | |
| 317 | | | |
| 318 | TEXT rpush(SB), 1, $-4 /* ( n -- ) */ | | |
| 319 | MOVQ TOP,(RSP) | | |
| 320 | POP(TOP) | | |
| 321 | ADDQ $8,RSP | | |
| 322 | NEXT | 337 | NEXT |
| 323 | | 338 | |
| 324 | TEXT rpop(SB), 1, $-4 /* ( -- n ) */ | 339 | TEXT rpop(SB), 1, $-4 /* ( -- n ) */ |
| 325 | PUSH(TOP) | 340 | PUSH(TOP) |
| 326 | SUBQ $8, RSP | 341 | RPOP(TOP) |
| 327 | MOVQ (RSP), TOP | 342 | NEXT |
| | 343 | |
| | 344 | TEXT rpush(SB), 1, $-4 /* ( n -- ) */ |
| | 345 | RPUSH(TOP) |
| | 346 | POP(TOP) |
| 328 | NEXT | 347 | NEXT |
| 329 | | 348 | |
| 330 | TEXT i(SB), 1, $-4 /* ( -- n ) */ | 349 | TEXT i(SB), 1, $-4 /* ( -- n ) */ |
| @@ -526,7 +545,7 @@ TEXT cas(SB), 1, $-4 /* ( a old new -- f ) */ · 195 unmodified lines |
| 526 | | 545 | |
| 527 | TEXT s0(SB), 1, $-4 /* S0 needs a calculation to come up with the value */ | 546 | TEXT s0(SB), 1, $-4 /* S0 needs a calculation to come up with the value */ |
| 528 | MOVQ H0, TOP | 547 | MOVQ H0, TOP |
| 529 | ADDQ $FORTHEND, TOP | 548 | ADDQ $PSTACK_END, TOP |
| 530 | NEXT | 549 | NEXT |
| 531 | | 550 | |
| 532 | /* store the forth sp here when going to C */ | 551 | /* store the forth sp here when going to C */ |
| @@ -545,7 +564,8 @@ TEXT forthsp(SB), 1, $-4 · 12 unmodified lines |
| 545 | VARIABLE(Tib, $TIB) | 564 | VARIABLE(Tib, $TIB) |
| 546 | VARIABLE(Wordb, $WORDB) | 565 | VARIABLE(Wordb, $WORDB) |
| 547 | VARIABLE(Hzero, $HEAPSTART) | 566 | VARIABLE(Hzero, $HEAPSTART) |
| 548 | VARIABLE(Dp, $DTOP) | 567 | VARIABLE(Dp, $DP) |
| | 568 | VARIABLE(Dtop, $DTOP) |
| 549 | VARIABLE(toIn, $TOIN) | 569 | VARIABLE(toIn, $TOIN) |
| 550 | VARIABLE(toLimit, $TOLIMIT) | 570 | VARIABLE(toLimit, $TOLIMIT) |
| 551 | VARIABLE(Findadr, $FINDADR) | 571 | VARIABLE(Findadr, $FINDADR) |