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
4040 .. fn ;
4141
4242 Heap memory map: uses 8 pages at the start, will increase by *2 when filled up
43−Variables
44− system variables
43+H0: variables
4544 heap start, heapstart, also in H0
4645 heap size, heapsize
4746 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
4951 error string buffer 128 bytes
5052 word buffer 512 bytes
51− tib, text input buffer 1024 bytes (until the next page?)
52−User dictionary upto 6 pages from the start
53−Return stack 1 page (4096 bytes, BY2PG, 512 entries) at FFSTART
53+User dictionary upto pages from the start
5454 |
5555 |
5656 v (grows downwards)
57+ ^ (grows upwards)
58+ |
59+ |
5760 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)
5865 ^ (grows upwards)
5966 |
6067 |
68+Return stack 1 page (4096 bytes, BY2PG, 512 entries) at FFSTART
6169 SSTACK_END = FORTHEND
6270 */
6371
@@ -71,36 +79,45 @@ SSTACK_END = FORTHEND · 7 unmodified lines
7179 #define PSTACK_SIZE BY2PG
7280 #define RSTACK_SIZE BY2PG
7381
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+ */
7486 #define HEAPSTART (0ull)
75−#define HEAPEND (HEAPSTART+8)
76−#define FORTHSP (HEAPSTART+16)
77−#define DTOP (HEAPSTART+24)
87+#define HEAPEND (HEAPSTART+(BY2WD*1))
88+#define FORTHSP (HEAPSTART+(BY2WD*2))
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))
7892 /* variables used by the core words */
79−#define TOIN (HEAPSTART+32)
80−#define TOLIMIT (HEAPSTART+40)
81−#define FINDADR (HEAPSTART+48)
82−#define BLK (HEAPSTART+56)
83−#define ARGS (HEAPSTART+64)
84−#define IOBUF (HEAPSTART+72)
85−#define SEARCHLEN (HEAPSTART+80)
86−#define BASE (HEAPSTART+88)
87−#define TONUM (HEAPSTART+96)
88−#define STATE (HEAPSTART+104)
89−#define ABORTVEC (HEAPSTART+112)
90−#define SOURCEBUF (HEAPSTART+120)
91−#define WORDBUF (HEAPSTART+128)
92−#define INFD (HEAPSTART+136)
93−#define OUTFD (HEAPSTART+144)
94−#define ERRFD (HEAPSTART+152)
95−
96−#define ERRSTR (HEAPSTART+160)
97−#define WORDB (HEAPSTART+288) /* word buffer */
98−#define TIB (HEAPSTART+792) /* text input buffer */
99−#define DICTIONARY (HEAPSTART+2048)
93+#define TOIN (HEAPSTART+(BY2WD*5))
94+#define TOLIMIT (HEAPSTART+(BY2WD*6))
95+#define FINDADR (HEAPSTART+(BY2WD*7))
96+#define BLK (HEAPSTART+(BY2WD*8))
97+#define ARGS (HEAPSTART+(BY2WD*9))
98+#define IOBUF (HEAPSTART+(BY2WD*10))
99+#define SEARCHLEN (HEAPSTART+(BY2WD*11))
100+#define BASE (HEAPSTART+(BY2WD*12))
101+#define TONUM (HEAPSTART+(BY2WD*13))
102+#define STATE (HEAPSTART+(BY2WD*14))
103+#define ABORTVEC (HEAPSTART+(BY2WD*15))
104+#define SOURCEBUF (HEAPSTART+(BY2WD*16))
105+#define WORDBUF (HEAPSTART+(BY2WD*17))
106+#define INFD (HEAPSTART+(BY2WD*18))
107+#define OUTFD (HEAPSTART+(BY2WD*19))
108+#define ERRFD (HEAPSTART+(BY2WD*20))
109+
110+#define ERRSTR (HEAPSTART+(BY2WD*32))
111+#define WORDB (HEAPSTART+(BY2WD*160)) /* word buffer */
112+
113+#define DICTIONARY (HEAPSTART+2048) /* dictionary */
100114 #define DICTIONARY_END (HEAPSTART+(6*BY2PG))
101−#define RSTACK (HEAPSTART+(6*BY2PG))
102−#define PSTACK_END (RSTACK+(2*BY2PG))
103−#define FORTHEND PSTACK_END
115+#define PSTACK (HEAPSTART+(6*BY2PG))
116+#define PSTACK_END (HEAPSTART+(7*BY2PG))
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
104121 #define HEAPSIZE FORTHEND
105122
106123 #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
123140 MOVQ RARG, H0 /* start of heap memory */
124141
125142 MOVQ H0, RSP
126− ADDQ $RSTACK, RSP /* return stack pointer, reset */
143+ ADDQ $RSTACK_END, RSP /* return stack pointer, reset */
127144
128145 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 */
130148
131149 MOVQ H0, TOP
132150 ADDQ $HEAPSTART, TOP
@@ -134,8 +152,10 @@ TEXT forthmain(SB), 1, $-4 /* _main(SB), 1, $-4 without the libc */ · 1 unmodified line
134152 ADDQ $(HEAPSIZE-1), TOP
135153 MOVQ TOP, 8(H0) /* heap end */
136154
137− MOVQ PSP, 16(H0) /* parameter stack pointer */
138− MOVQ $centry_c_boot(SB), 24(H0) /* Last dictionary entry address */
155+ MOVQ H0, TOP
156+ ADDQ $DICTIONARY, TOP
157+ MOVQ TOP, 24(H0) /* dictionary pointer */
158+ MOVQ $centry_c_boot(SB), 24(H0) /* Latest dictionary entry address */
139159
140160 /* execute boot */
141161 MOVQ $centry_c_boot(SB), IP
@@ -162,33 +182,34 @@ Assume IP = 8 · 20 unmodified lines
162182 MOVQ r, (PSP)
163183 #define POP(r) MOVQ (PSP), r; \
164184 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
165189
166190 NEXT
167191
168192 TEXT reset(SB), 1, $-4
169193 MOVQ H0, RSP
170− ADDQ $RSTACK, RSP
194+ ADDQ $RSTACK_END, RSP
171195 NEXT
172196
173197 TEXT clear(SB), 1, $-4
174198 MOVQ H0, PSP
175− ADDQ $FFEND, PSP
199+ ADDQ $PSTACK_END, PSP
176200 NEXT
177201
178202 TEXT colon(SB), 1, $-4
179− MOVQ IP,(RSP)
180− ADDQ $8, RSP
203+ RPUSH(IP)
181204 LEAQ 8(W), IP
182205 NEXT
183206
184207 TEXT exitcolon(SB), 1, $-4
185− SUBQ $8, RSP
186− MOVQ (RSP), IP
208+ RPOP(IP)
187209 NEXT
188210
189211 TEXT dodoes(SB), 1, $-4 /* ( -- a ) */
190− MOVQ IP,(RSP)
191− ADDQ $8,RSP
212+ RPUSH(IP)
192213 MOVQ 8(W),IP
193214 PUSH(TOP)
194215 LEAQ 16(W), TOP
@@ -306,25 +327,23 @@ doloop1: · 111 unmodified lines
306327 NEXT
307328
308329 TEXT doploop(SB), 1, $-4 /* ( n -- ) */
309− ADDQ TOP, -16(RSP)
330+ ADDQ TOP, 16(RSP)
310331 POP(TOP)
311332 JMP doloop1
312333
313−TEXT rfetch(SB), 1, $-4 /* ( -- n ) */
334+TEXT rfetch(SB), 1, $-4 /* ( -- n ) no change in RSP */
314335 PUSH(TOP)
315− MOVQ -8(RSP), TOP
316− NEXT
317−
318−TEXT rpush(SB), 1, $-4 /* ( n -- ) */
319− MOVQ TOP,(RSP)
320− POP(TOP)
321− ADDQ $8,RSP
336+ MOVQ (RSP), TOP
322337 NEXT
323338
324339 TEXT rpop(SB), 1, $-4 /* ( -- n ) */
325340 PUSH(TOP)
326− SUBQ $8, RSP
327− MOVQ (RSP), TOP
341+ RPOP(TOP)
342+ NEXT
343+
344+TEXT rpush(SB), 1, $-4 /* ( n -- ) */
345+ RPUSH(TOP)
346+ POP(TOP)
328347 NEXT
329348
330349 TEXT i(SB), 1, $-4 /* ( -- n ) */
@@ -526,7 +545,7 @@ TEXT cas(SB), 1, $-4 /* ( a old new -- f ) */ · 195 unmodified lines
526545
527546 TEXT s0(SB), 1, $-4 /* S0 needs a calculation to come up with the value */
528547 MOVQ H0, TOP
529− ADDQ $FORTHEND, TOP
548+ ADDQ $PSTACK_END, TOP
530549 NEXT
531550
532551 /* store the forth sp here when going to C */
@@ -545,7 +564,8 @@ TEXT forthsp(SB), 1, $-4 · 12 unmodified lines
545564 VARIABLE(Tib, $TIB)
546565 VARIABLE(Wordb, $WORDB)
547566 VARIABLE(Hzero, $HEAPSTART)
548−VARIABLE(Dp, $DTOP)
567+VARIABLE(Dp, $DP)
568+VARIABLE(Dtop, $DTOP)
549569 VARIABLE(toIn, $TOIN)
550570 VARIABLE(toLimit, $TOLIMIT)
551571 VARIABLE(Findadr, $FINDADR)
os/pc64/mem.h+1−1
@@ -206,4 +206,4 @@ · 205 unmodified lines
206206 #define RMACH R15 /* m-> */
207207 #define RUSER R14 /* up-> */
208208
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