1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-02 10:20:55 +11:00

Compare commits

..

3 Commits

Author SHA1 Message Date
Virgil Dupras
f62376bd0a boot: remove _bend
It's not needed anymore now that the boot binary is built in one pass.
2020-04-10 09:59:45 -04:00
Virgil Dupras
7aa1be070b emul: build boot binary in one pass
... instead of building boot.fs, and then z80c.fs/icore.fs in separate
passes. This strengten xcomp by making it support 2 completely separate
dicts (that is, the X dict is *not* connected to the system dict. The chain
now stops at EXIT def in boot.fs).
2020-04-10 09:55:58 -04:00
Virgil Dupras
c8c337fd58 xcomp: widen scope
We can now cross-compile core.fs.
2020-04-10 07:53:41 -04:00
6 changed files with 77 additions and 42 deletions

View File

@ -15,10 +15,10 @@ $(SLATEST):
$(BIN2C): $(BIN2C):
$(MAKE) -C ../tools $(MAKE) -C ../tools
# z80c.bin and boot.bin are not in the prerequisites because they're bootstrap # z80c.bin is not in the prerequisites because it's a bootstrap
# binaries that should be updated manually through make updatebootstrap. # binary that should be updated manually through make updatebootstrap.
forth/forth0.bin: $(SLATEST) forth/forth0.bin: $(SLATEST)
cat forth/boot.bin forth/z80c.bin > $@ cp forth/z80c.bin $@
$(SLATEST) $@ $(SLATEST) $@
cat forth/emul.fs >> $@ cat forth/emul.fs >> $@
@ -37,7 +37,7 @@ forth/core.bin: $(FORTHSRC_PATHS) forth/stage1
cat $(FORTHSRC_PATHS) ./forth/stop.fs | $(STRIPFC) | ./forth/stage1 | tee $@ > /dev/null cat $(FORTHSRC_PATHS) ./forth/stop.fs | $(STRIPFC) | ./forth/stage1 | tee $@ > /dev/null
forth/forth1.bin: forth/core.bin $(SLATEST) forth/forth1.bin: forth/core.bin $(SLATEST)
cat forth/boot.bin forth/z80c.bin forth/core.bin > $@ cat forth/z80c.bin forth/core.bin > $@
$(SLATEST) $@ $(SLATEST) $@
forth/forth1-bin.h: forth/forth1.bin $(BIN2C) forth/forth1-bin.h: forth/forth1.bin $(BIN2C)
@ -60,10 +60,11 @@ emul.o: emul.c
$(CC) -c -o emul.o emul.c $(CC) -c -o emul.o emul.c
forth/z80c.bin: forth/stage2
cat ./forth/conf.fs ../forth/xcomp.fs ./forth/xcomp.fs ../forth/boot.fs ../forth/z80c.fs ../forth/icore.fs | ./forth/stage2 | tee $@ > /dev/null
.PHONY: updatebootstrap .PHONY: updatebootstrap
updatebootstrap: forth/stage2 updatebootstrap: forth/z80c.bin
cat ./forth/conf.fs ../forth/boot.fs | ./forth/stage2 | tee forth/boot.bin > /dev/null
cat ./forth/conf.fs ../forth/xcomp.fs ./forth/xcomp.fs ../forth/z80c.fs ../forth/icore.fs | ./forth/stage2 | tee forth/z80c.bin > /dev/null
.PHONY: clean .PHONY: clean
clean: clean:

Binary file not shown.

View File

@ -1,11 +1,18 @@
: _
['] EXIT ,
R> DROP ( exit : )
XCOFF
; IMMEDIATE
';' CURRENT @ 4 - C!
: (find) (xfind) ;
: ['] X['] ; IMMEDIATE
: COMPILE XCOMPILE ; IMMEDIATE
: CODE XCODE ; : CODE XCODE ;
: IMMEDIATE XIMM ; : IMMEDIATE XIMM ;
: : [ ' X: , ] ; : : [ ' X: , ] ;
CURRENT @ XCURRENT ! CURRENT @ XCURRENT !
H@ ' _bend - 4 + XOFF !
( dummy entry for dict hook )
(xentry) _
H@ 256 /MOD 2 PC! 2 PC! H@ 256 /MOD 2 PC! 2 PC!
H@ XOFF !

Binary file not shown.

View File

@ -87,6 +87,7 @@ L1 BSET ( CBR )
'E' A, 'X' A, 'E' A, 'C' A, 'U' A, 'T' A, 'E' A, 'E' A, 'X' A, 'E' A, 'C' A, 'U' A, 'T' A, 'E' A,
PC L1 @ - A,, ( prev ) PC L1 @ - A,, ( prev )
7 A, 7 A,
H@ XCURRENT ! ( set current tip of dict )
L2 BSET ( used frequently below ) L2 BSET ( used frequently below )
0x17 A,, ( nativeWord ) 0x17 A,, ( nativeWord )
IY POPqq, ( is a wordref ) IY POPqq, ( is a wordref )
@ -366,20 +367,3 @@ PC ORG @ 0x22 + ! ( litWord )
want... ) want... )
RAMSTART 0x06 + LD(nn)HL, ( RAMSTART+0x06 == IP ) RAMSTART 0x06 + LD(nn)HL, ( RAMSTART+0x06 == IP )
JPNEXT, JPNEXT,
( filler )
NOP, NOP, NOP, NOP, NOP,
( DICT HOOK )
( This dummy dictionary entry serves two purposes:
1. Allow binary grafting. Because each binary dict always
end with a dummy entry, we always have a predictable
prev offset for the grafter's first entry.
2. Tell icore's "_c" routine where the boot binary ends.
See comment there.
)
'_' A, 'b' A, 'e' A, 'n' A, 'd' A,
PC L2 @ - A,, ( prev )
5 A,
H@ 256 /MOD 2 PC! 2 PC!

View File

@ -14,18 +14,29 @@
"'" and friends will *not* find words you're about to "'" and friends will *not* find words you're about to
define. Only (xfind) will. define. Only (xfind) will.
Words ":", "IMMEDIATE" and "CODE" are not automatically Words overrides like ":", "IMMEDIATE" and "CODE" are not
shadowed to allow the harmless inclusion of this unit. This automatically shadowed to allow the harmless inclusion of
shadowing has to take place in your xcomp configuration. this unit. This shadowing has to take place in your xcomp
configuration.
See example in /emul/forth/xcomp.fs See example in /emul/forth/xcomp.fs
Note that this cross compilation unit is far from foolproof
and cannot cross compile any kind of code. Cross compliation
of Forth dicts is *tricky*. This unit is designed to cross
compile the core full interpreter, that is, the contents
of the "/forth" folder of the project.
Cross compiling anything else might work, but as soon as
you start defining immediates and using them on-the-fly,
things get icky.
) )
VARIABLE XCURRENT VARIABLE XCURRENT
VARIABLE XOFF VARIABLE XOFF
: XCON XCURRENT CURRENT* ! ; : XCON XCURRENT CURRENT* ! ;
: XCOFF CURRENT CURRENT* ! ; : XCOFF 0x02 RAM+ CURRENT* ! ;
: (xentry) XCON (entry) XCOFF ; : (xentry) XCON (entry) XCOFF ;
@ -33,15 +44,37 @@ VARIABLE XOFF
: XIMM XCON IMMEDIATE XCOFF ; : XIMM XCON IMMEDIATE XCOFF ;
: XAPPLY
DUP XOFF @ > IF XOFF @ - THEN
;
( Run find in XCURRENT and apply XOFF )
: (xfind)
XCURRENT @ SWAP ( xcur w )
_find ( a f )
IF ( a )
( apply XOFF )
XAPPLY 1
ELSE
0
THEN
;
: X' XCON ' XCOFF XAPPLY ;
: X['] X' LITN ;
( TODO: am I making the word "," stable here? )
: XCOMPILE X' LITN ['] , , ;
: X: : X:
XCON (xentry)
(entry)
( 0e == compiledWord ) ( 0e == compiledWord )
[ 0x0e LITN ] , [ 0x0e LITN ] ,
BEGIN BEGIN
( DUP is because we need a copy in case it's IMMED ) ( DUP is because we need a copy in case it's IMMED )
WORD DUP WORD DUP
(find) ( w a f ) ( cross compile CURRENT )
XCURRENT @ SWAP ( w xcur w )
_find ( w a f )
IF IF
( is word ) ( is word )
DUP IMMED? DUP IMMED?
@ -49,23 +82,33 @@ VARIABLE XOFF
( When encountering IMMEDIATE, we exec the *host* ( When encountering IMMEDIATE, we exec the *host*
word. ) word. )
DROP ( w ) DROP ( w )
( hardcoded system CURRENT ) ( system CURRENT )
0x02 RAM+ @ SWAP ( cur w ) 0x02 RAM+ @ SWAP ( cur w )
_find ( a f ) _find ( a f )
NOT IF ABORT THEN ( a ) NOT IF ABORT THEN ( a )
EXECUTE XCON EXECUTE XCOFF
ELSE ELSE
( not an immed. drop backup w and write, with ( not an immed. drop backup w and write, with
offset. ) offset. )
SWAP DROP ( a ) SWAP DROP ( a )
DUP 0x100 > IF XOFF @ - THEN XAPPLY
, ,
THEN THEN
ELSE ( w a ) ELSE ( w a )
( maybe number ) ( not found? it might be an immediate that isn't yet defined in our
DROP ( w ) cross-compiled dict. It's alright, we can find-and-execute it. )
(parse*) @ EXECUTE LITN DROP ( w )
( system CURRENT )
0x02 RAM+ @ SWAP ( cur w )
_find ( a f )
IF
( found. It *must* be an IMMED )
DUP IMMED? NOT IF ABORT THEN
EXECUTE
ELSE
( not found. maybe number )
(parse*) @ EXECUTE LITN
THEN
THEN THEN
AGAIN AGAIN
XCOFF
; ;