1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-23 23:38:06 +11:00

forth: Remove RAM offsets from stable ABI

Doing this was a bit stupid. These offsets are constants. Moreover,
having them in stable ABI had us construct the boot binary from the
stable ABI of the host, making it very difficult to change RAMSTART
for a new system.
This commit is contained in:
Virgil Dupras 2020-04-02 09:58:02 -04:00
parent d0c5d3a741
commit 68a7be3707
6 changed files with 72 additions and 41 deletions

Binary file not shown.

Binary file not shown.

View File

@ -25,17 +25,17 @@ JP(IY), NOP, ( 17, nativeWord )
0 JPnn, ( 1d, chkPS ) 0 JPnn, ( 1d, chkPS )
NOP, NOP, ( 20, numberWord ) NOP, NOP, ( 20, numberWord )
NOP, NOP, ( 22, litWord ) NOP, NOP, ( 22, litWord )
RAMSTART , ( 24, INITIAL_SP ) RAMSTART , ( 24, RAMSTART )
RAMSTART 0x0e + , ( 26, WORDBUF ) NOP, NOP, ( 26, unused )
0 JPnn, ( 28, flagsToBC ) 0 JPnn, ( 28, flagsToBC )
0 JPnn, ( 2b, doesWord ) 0 JPnn, ( 2b, doesWord )
RS_ADDR , ( 2e, RS_ADDR ) RS_ADDR , ( 2e, RS_ADDR )
RAMSTART 0x0c + , ( 30, CINPTR ) NOP, NOP, ( 30, unused )
RAMSTART 0x2e + , ( 32, SYSVNXT ) NOP, NOP, ( 32, unused )
RAMSTART 0x08 + , ( 34, FLAGS ) NOP, NOP, ( 34, unused )
RAMSTART 0x0a + , ( 36, PARSEPTR ) NOP, NOP, ( 36, unused )
RAMSTART 0x04 + , ( 38, HERE ) NOP, NOP, ( 38, unused )
RAMSTART 0x02 + , ( 3a, CURRENT ) NOP, NOP, ( 3a, unused )
( BOOT DICT ( BOOT DICT
There are only 5 words in the boot dict, but these words' There are only 5 words in the boot dict, but these words'
@ -116,14 +116,14 @@ PC ORG @ 1 + ! ( main )
stack underflow. stack underflow.
) )
SP 0xfffa LDddnn, SP 0xfffa LDddnn,
0x24 @ SP LD(nn)dd, ( 24 == INITIAL_SP ) RAMSTART SP LD(nn)dd, ( RAM+00 == INITIAL_SP )
IX RS_ADDR LDddnn, IX RS_ADDR LDddnn,
( LATEST is a label to the latest entry of the dict. It is ( LATEST is a label to the latest entry of the dict. It is
written at offset 0x08 by the process or person building written at offset 0x08 by the process or person building
Forth. ) Forth. )
0x08 LDHL(nn), 0x08 LDHL(nn),
0x3a @ LD(nn)HL, ( 3a == CURRENT ) RAMSTART 0x02 + LD(nn)HL, ( RAM+02 == CURRENT )
0x38 @ LD(nn)HL, ( 38 == HERE ) RAMSTART 0x04 + LD(nn)HL, ( RAM+04 == HERE )
HL L1 @ LDddnn, HL L1 @ LDddnn,
0x03 CALLnn, ( 03 == find ) 0x03 CALLnn, ( 03 == find )
DE PUSHqq, DE PUSHqq,
@ -155,7 +155,7 @@ PC ORG @ 4 + ! ( find )
adjust. Because the compare loop pre-decrements, instead adjust. Because the compare loop pre-decrements, instead
of DECing HL twice, we DEC it once. ) of DECing HL twice, we DEC it once. )
HL DECss, HL DECss,
DE 0x3a @ LDdd(nn), ( 3a == CURRENT ) DE RAMSTART 0x02 + LDdd(nn), ( RAM+02 == CURRENT )
L3 BSET ( inner ) L3 BSET ( inner )
( DE is a wordref, first step, do our len correspond? ) ( DE is a wordref, first step, do our len correspond? )
HL PUSHqq, ( --> lvl 1 ) HL PUSHqq, ( --> lvl 1 )
@ -249,7 +249,7 @@ L1 BSET ( abortUnderflow )
PC ORG @ 0x1e + ! ( chkPS ) PC ORG @ 0x1e + ! ( chkPS )
HL PUSHqq, HL PUSHqq,
0x24 @ LDHL(nn), ( 24 == INITIAL_SP ) RAMSTART LDHL(nn), ( RAM+00 == INITIAL_SP )
( We have the return address for this very call on the stack ( We have the return address for this very call on the stack
and protected registers. Let's compensate ) and protected registers. Let's compensate )
HL DECss, HL DECss,

View File

@ -106,16 +106,16 @@
: (sysv) : (sysv)
( Get new sysv addr ) ( Get new sysv addr )
( 50 == SYSVNXT ) ( RAM+46 (2e) == SYSVNXT )
50 @ @ 46 RAM+ @
CONSTANT CONSTANT
( increase current sysv counter ) ( increase current sysv counter )
2 50 @ +! 2 46 RAM+ +!
; ;
( Set up initial SYSVNXT value, which is 2 bytes after its ( Set up initial SYSVNXT value, which is 2 bytes after its
own address ) own address )
50 @ DUP 2 + SWAP ! 46 RAM+ DUP 2 + SWAP !
: ." : ."
LIT LIT

View File

@ -55,25 +55,15 @@
, ( write! ) , ( write! )
; IMMEDIATE ; IMMEDIATE
: FLAGS : RAM+
( 52 == FLAGS ) ( 0x24 == RAMSTART )
[ 52 @ LITN ] [ 0x24 @ LITN ] _c +
; ;
: (parse*) : FLAGS 0x08 _c RAM+ ;
( 54 == PARSEPTR ) : (parse*) 0x0a _c RAM+ ;
[ 54 @ LITN ] : HERE 0x04 _c RAM+ ;
; : CURRENT 0x02 _c RAM+ ;
: HERE
( 56 == HERE )
[ 56 @ LITN ]
;
: CURRENT
( 58 == CURRENT )
[ 58 @ LITN ]
;
: QUIT : QUIT
0 _c FLAGS _c ! _c (resRS) 0 _c FLAGS _c ! _c (resRS)
@ -142,8 +132,8 @@
; ;
: C< : C<
( 48 == CINPTR ) ( 0c == CINPTR )
[ 48 @ LITN ] _c @ EXECUTE 0x0c _c RAM+ _c @ EXECUTE
; ;
: , : ,
@ -170,8 +160,8 @@
( Read word from C<, copy to WORDBUF, null-terminate, and ( Read word from C<, copy to WORDBUF, null-terminate, and
return, make HL point to WORDBUF. ) return, make HL point to WORDBUF. )
: WORD : WORD
( 38 == WORDBUF ) ( 0e == WORDBUF )
[ 38 @ LITN ] ( a ) 0x0e _c RAM+ ( a )
_c TOWORD ( a c ) _c TOWORD ( a c )
BEGIN BEGIN
( We take advantage of the fact that char MSB is ( We take advantage of the fact that char MSB is
@ -184,7 +174,7 @@
( a this point, PS is: a WS ) ( a this point, PS is: a WS )
( null-termination is already written ) ( null-termination is already written )
_c 2DROP _c 2DROP
[ 38 @ LITN ] 0x0e _c RAM+
; ;
: (entry) : (entry)
@ -220,8 +210,8 @@
LIT< (parse) _c (find) _c DROP _c (parse*) _c ! LIT< (parse) _c (find) _c DROP _c (parse*) _c !
LIT< (c<) _c (find) _c LIT< (c<) _c (find) _c
NOT IF LIT< KEY _c (find) _c DROP THEN NOT IF LIT< KEY _c (find) _c DROP THEN
( 48 == CINPTR ) ( 0c == CINPTR )
[ 48 @ LITN ] _c ! 0x0c _c RAM+ _c !
LIT< (c<$) _c (find) IF EXECUTE ELSE _c DROP THEN LIT< (c<$) _c (find) IF EXECUTE ELSE _c DROP THEN
_c INTERPRET _c INTERPRET
; ;

View File

@ -66,3 +66,44 @@ also "special words", for example NUMBER, LIT, FBR, that have a slightly
different structure. They're also a pointer to an executable, but as for the different structure. They're also a pointer to an executable, but as for the
other fields, the only one they have is the "flags" field. other fields, the only one they have is the "flags" field.
*** System variables
There are some core variables in the core system that are referred to directly
by their address in memory throughout the code. The place where they live is
configurable by the RAMSTART constant in conf.fs, but their relative offset is
not. In fact, they're mostlly referred to directly as their numerical offset
along with a comment indicating what this offset refers to.
This system is a bit fragile because every time we change those offsets, we
have to be careful to adjust all system variables offsets, but thankfully,
there aren't many system variables. Here's a list of them:
RAMSTART INITIAL_SP
+02 CURRENT
+04 HERE
+06 IP
+08 FLAGS
+0a PARSEPTR
+0c CINPTR
+0e WORDBUF
+2e SYSVNXT
+4e RAMEND
INITIAL_SP holds the initial Stack Pointer value so that we know where to reset
it on ABORT
CURRENT points to the last dict entry.
HERE points to current write offset.
IP is the Interpreter Pointer
FLAGS holds global flags. Only used for prompt output control for now.
PARSEPTR holds routine address called on (parse)
CINPTR holds routine address called on C<
WORDBUF is the buffer used by WORD
SYSVNXT is the buffer+tracker used by (sysv)