History

using the memory map used by Starting Forth

9ferno committed 4 years ago

Commit 4b789891 parent 0644f162 files · +79 −59Browse files

Unified · Split

2 files
  1. os/pc64/forth.s +78 −58
  2. os/pc64/mem.h +1 −1
os/pc64/forth.s+78−58
@@ -40,24 +40,32 @@ coding standard · 39 unmodified lines
40 .. fn ;40 .. fn ;
41 41
42Heap memory map: uses 8 pages at the start, will increase by *2 when filled up42Heap memory map: uses 8 pages at the start, will increase by *2 when filled up
43Variables43H0: variables
44 system variables
45 heap start, heapstart, also in H044 heap start, heapstart, also in H0
46 heap size, heapsize45 heap size, heapsize
47 forth stack pointer, forthsp46 forth stack pointer, forthsp
48 dictionary top, dtop47 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 bytes51 error string buffer 128 bytes
50 word buffer 512 bytes52 word buffer 512 bytes
51 tib, text input buffer 1024 bytes (until the next page?)53User dictionary upto pages from the start
52User dictionary upto 6 pages from the start
53Return 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 |
57Parameter stack 1 page (BY2PG, 512 entries) at FFEND-409660Parameter stack 1 page (BY2PG, 512 entries) at FFEND-4096
61tib, 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 |
68Return stack 1 page (4096 bytes, BY2PG, 512 entries) at FFSTART
61SSTACK_END = FORTHEND69SSTACK_END = FORTHEND
62*/70*/
63 71
@@ -71,36 +79,45 @@ SSTACK_END = FORTHEND · 7 unmodified lines
71#define PSTACK_SIZE BY2PG79#define PSTACK_SIZE BY2PG
72#define RSTACK_SIZE BY2PG80#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_END117#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 FORTHEND121#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, RSP142 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, PSP145 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, TOP149 MOVQ H0, TOP
132 ADDQ $HEAPSTART, TOP150 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), TOP152 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), IP161 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, PSP184 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 NEXT190 NEXT
167 191
168TEXT reset(SB), 1, $-4192TEXT reset(SB), 1, $-4
169 MOVQ H0, RSP193 MOVQ H0, RSP
170 ADDQ $RSTACK, RSP194 ADDQ $RSTACK_END, RSP
171 NEXT195 NEXT
172 196
173TEXT clear(SB), 1, $-4197TEXT clear(SB), 1, $-4
174 MOVQ H0, PSP198 MOVQ H0, PSP
175 ADDQ $FFEND, PSP199 ADDQ $PSTACK_END, PSP
176 NEXT200 NEXT
177 201
178TEXT colon(SB), 1, $-4202TEXT colon(SB), 1, $-4
179 MOVQ IP,(RSP)203 RPUSH(IP)
180 ADDQ $8, RSP
181 LEAQ 8(W), IP204 LEAQ 8(W), IP
182 NEXT205 NEXT
183 206
184TEXT exitcolon(SB), 1, $-4207TEXT exitcolon(SB), 1, $-4
185 SUBQ $8, RSP208 RPOP(IP)
186 MOVQ (RSP), IP
187 NEXT209 NEXT
188 210
189TEXT dodoes(SB), 1, $-4 /* ( -- a ) */211TEXT dodoes(SB), 1, $-4 /* ( -- a ) */
190 MOVQ IP,(RSP)212 RPUSH(IP)
191 ADDQ $8,RSP
192 MOVQ 8(W),IP213 MOVQ 8(W),IP
193 PUSH(TOP)214 PUSH(TOP)
194 LEAQ 16(W), TOP215 LEAQ 16(W), TOP
@@ -306,25 +327,23 @@ doloop1: · 111 unmodified lines
306 NEXT327 NEXT
307 328
308TEXT doploop(SB), 1, $-4 /* ( n -- ) */329TEXT doploop(SB), 1, $-4 /* ( n -- ) */
309 ADDQ TOP, -16(RSP)330 ADDQ TOP, 16(RSP)
310 POP(TOP)331 POP(TOP)
311 JMP doloop1332 JMP doloop1
312 333
313TEXT rfetch(SB), 1, $-4 /* ( -- n ) */334TEXT rfetch(SB), 1, $-4 /* ( -- n ) no change in RSP */
314 PUSH(TOP)335 PUSH(TOP)
315 MOVQ -8(RSP), TOP336 MOVQ (RSP), TOP
316 NEXT
317
318TEXT rpush(SB), 1, $-4 /* ( n -- ) */
319 MOVQ TOP,(RSP)
320 POP(TOP)
321 ADDQ $8,RSP
322 NEXT337 NEXT
323 338
324TEXT rpop(SB), 1, $-4 /* ( -- n ) */339TEXT rpop(SB), 1, $-4 /* ( -- n ) */
325 PUSH(TOP)340 PUSH(TOP)
326 SUBQ $8, RSP341 RPOP(TOP)
327 MOVQ (RSP), TOP342 NEXT
343
344TEXT rpush(SB), 1, $-4 /* ( n -- ) */
345 RPUSH(TOP)
346 POP(TOP)
328 NEXT347 NEXT
329 348
330TEXT i(SB), 1, $-4 /* ( -- n ) */349TEXT i(SB), 1, $-4 /* ( -- n ) */
@@ -526,7 +545,7 @@ TEXT cas(SB), 1, $-4 /* ( a old new -- f ) */ · 195 unmodified lines
526 545
527TEXT s0(SB), 1, $-4 /* S0 needs a calculation to come up with the value */546TEXT s0(SB), 1, $-4 /* S0 needs a calculation to come up with the value */
528 MOVQ H0, TOP547 MOVQ H0, TOP
529 ADDQ $FORTHEND, TOP548 ADDQ $PSTACK_END, TOP
530 NEXT549 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
545VARIABLE(Tib, $TIB)564VARIABLE(Tib, $TIB)
546VARIABLE(Wordb, $WORDB)565VARIABLE(Wordb, $WORDB)
547VARIABLE(Hzero, $HEAPSTART)566VARIABLE(Hzero, $HEAPSTART)
548VARIABLE(Dp, $DTOP)567VARIABLE(Dp, $DP)
568VARIABLE(Dtop, $DTOP)
549VARIABLE(toIn, $TOIN)569VARIABLE(toIn, $TOIN)
550VARIABLE(toLimit, $TOLIMIT)570VARIABLE(toLimit, $TOLIMIT)
551VARIABLE(Findadr, $FINDADR)571VARIABLE(Findadr, $FINDADR)
os/pc64/mem.h+1−1
@@ -206,4 +206,4 @@ · 205 unmodified lines
206#define RMACH R15 /* m-> */206#define RMACH R15 /* m-> */
207#define RUSER R14 /* up-> */207#define RUSER R14 /* up-> */
208 208
209#define FORTHHEAPSIZE (8*BY2PG)209#define FORTHHEAPSIZE (9*BY2PG)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t