1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-30 20:58:05 +11:00

boot: make HERE point to RAMEND instead of CURRENT

The former was only used in the peculiar context of "/emul". The
regular case is actually HERE pointing to RAMEND on boot.
This commit is contained in:
Virgil Dupras 2020-04-13 11:35:47 -04:00
parent 509972b08c
commit d08a9711c5
9 changed files with 28 additions and 21 deletions

View File

@ -29,7 +29,7 @@ $(BIN2C):
forth/forth0.bin: $(SLATEST) forth/forth0.bin: $(SLATEST)
cp forth/z80c.bin $@ cp forth/z80c.bin $@
$(SLATEST) $@ $(SLATEST) $@
cat forth/emul.fs >> $@ cat forth/pre.fs forth/emul.fs >> $@
forth/forth0-bin.h: forth/forth0.bin $(BIN2C) forth/forth0-bin.h: forth/forth0.bin $(BIN2C)
$(BIN2C) KERNEL < forth/forth0.bin | tee $@ > /dev/null $(BIN2C) KERNEL < forth/forth0.bin | tee $@ > /dev/null
@ -43,14 +43,14 @@ forth/stage1dbg: forth/stage.c $(OBJS) forth/forth0-bin.h
# We don't really need to use stripfc, but we do it anyway to test that we # We don't really need to use stripfc, but we do it anyway to test that we
# don't mistakenly break our code with that tool. It's easier to debug here. # don't mistakenly break our code with that tool. It's easier to debug here.
forth/core.bin: $(FORTHSRC_PATHS) forth/stage1 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 > $@
forth/forth1.bin: forth/core.bin $(SLATEST) forth/forth1.bin: forth/core.bin $(SLATEST)
cat 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)
$(BIN2C) KERNEL < forth/forth1.bin | tee $@ > /dev/null $(BIN2C) KERNEL < forth/forth1.bin > $@
forth/stage2: forth/stage.c $(OBJS) forth/forth1-bin.h forth/stage2: forth/stage.c $(OBJS) forth/forth1-bin.h
$(CC) -DSTAGE2 forth/stage.c $(OBJS) -o $@ $(CC) -DSTAGE2 forth/stage.c $(OBJS) -o $@

2
emul/forth/pre.fs Normal file
View File

@ -0,0 +1,2 @@
CURRENT @ HERE !

View File

@ -1 +1 @@
: INIT RDLN$ Z80A$ INTERPRET ; : INIT CURRENT @ HERE ! RDLN$ Z80A$ INTERPRET ;

Binary file not shown.

View File

@ -118,12 +118,14 @@ PC ORG @ 1 + ! ( main )
SP 0xfffa LDddnn, SP 0xfffa LDddnn,
RAMSTART SP LD(nn)dd, ( RAM+00 == INITIAL_SP ) RAMSTART SP LD(nn)dd, ( RAM+00 == INITIAL_SP )
IX RS_ADDR LDddnn, IX RS_ADDR LDddnn,
( HERE begins at RAMEND )
HL RAMSTART 0x80 + LDddnn,
RAMSTART 0x04 + LD(nn)HL, ( RAM+04 == HERE )
( 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),
RAMSTART 0x02 + LD(nn)HL, ( RAM+02 == CURRENT ) RAMSTART 0x02 + LD(nn)HL, ( RAM+02 == CURRENT )
RAMSTART 0x04 + LD(nn)HL, ( RAM+04 == HERE )
EXDEHL, EXDEHL,
HL L1 @ LDddnn, HL L1 @ LDddnn,
0x03 CALLnn, ( 03 == find ) 0x03 CALLnn, ( 03 == find )

View File

@ -170,8 +170,11 @@ advanced to the address following the null.
*** Initialization sequence *** Initialization sequence
On boot, we jump to the "main" routine in boot.fs which does very few things. On boot, we jump to the "main" routine in boot.fs which does very few things.
It sets up the SP register, CURRENT and HERE to LATEST (saved in stable ABI),
then look for the BOOT word and calls it. 1. Set SP to 0x10000-6
2. Sets HERE to RAMEND (RAMSTART+0x80).
3. Sets CURRENT to value of LATEST field in stable ABI.
4. Look for the word "BOOT" and calls it.
In a normal system, BOOT is in icore and does a few things: In a normal system, BOOT is in icore and does a few things:
@ -192,9 +195,9 @@ as such until you set a new (c<).
Note that there is no EMIT in a bare system. You have to take care of supplying Note that there is no EMIT in a bare system. You have to take care of supplying
one before your load core.fs and its higher levels. one before your load core.fs and its higher levels.
Also note that this initialization code is fighting for space with HERE: New In the "/emul" binaries, "HERE" is readjusted to "CURRENT @" so that we don't
entries to the dict will overwrite that code! Also, because we're barebone, we have to relocate compiled dicts. Note that in this context, the initialization
can't have comments. This leads to peculiar code in this area. If you see weird code is fighting for space with HERE: New entries to the dict will overwrite
whitespace usage, it's probably because not using those whitespace would result that code! Also, because we're barebone, we can't have comments. This can lead
in dict entry creation overwriting the code before it has the chance to be to peculiar code in this area where we try to "waste" space in initialization
interpreted. code.

View File

@ -1,4 +1,4 @@
TARGET = os.bin TARGET = stage1.bin
BASEDIR = ../.. BASEDIR = ../..
FDIR = $(BASEDIR)/forth FDIR = $(BASEDIR)/forth
EDIR = $(BASEDIR)/emul/forth EDIR = $(BASEDIR)/emul/forth
@ -13,7 +13,7 @@ BOOTSRCS = conf.fs \
$(FDIR)/icore.fs \ $(FDIR)/icore.fs \
$(EDIR)/xstop.fs $(EDIR)/xstop.fs
PATHS = pre.fs \ PATHS = \
$(FDIR)/core.fs \ $(FDIR)/core.fs \
$(FDIR)/cmp.fs \ $(FDIR)/cmp.fs \
$(FDIR)/str.fs \ $(FDIR)/str.fs \

View File

@ -202,9 +202,9 @@ using our hex editor.
Now are we ready yet? ALMOST! There's one last thing we need to do: add runtime Now are we ready yet? ALMOST! There's one last thing we need to do: add runtime
source. In our case, because we have a compiled dict, the only source we need source. In our case, because we have a compiled dict, the only source we need
to include is `pre.fs` and `run.fs`: to include is `run.fs`:
cat stage2.bin pre.fs run.fs > stage2r.bin cat stage2.bin run.fs > stage2r.bin
That's it! our binary is ready to run! That's it! our binary is ready to run!
@ -212,7 +212,8 @@ That's it! our binary is ready to run!
And there you have it, a stage2 binary that you've assembled yourself. Now, And there you have it, a stage2 binary that you've assembled yourself. Now,
here's for your homework: use the same technique to add the contents of here's for your homework: use the same technique to add the contents of
`readln.fs` to stage2 so that you have a full-featured interpreter. `readln.fs` and `adev.fs` to stage2 so that you have a full-featured
interpreter.
Name it `stage3.bin` (the version without any source code appended and no Name it `stage3.bin` (the version without any source code appended and no
`INIT` word defined), you'll need this binary for sub-recipes written for the `INIT` word defined), you'll need this binary for sub-recipes written for the
@ -221,8 +222,8 @@ RC2014.
Here's a little cheatsheet, but seriously, you should figure most of it Here's a little cheatsheet, but seriously, you should figure most of it
yourself. Tough love they call it. yourself. Tough love they call it.
* `cat stage2.bin pre.fs ../../forth/readln.fs run.fs > stage2r.bin` * `cat stage2.bin ../../forth/readln.fs ../../forth/adev.fs run.fs > stage2r.bin`
* Don't forget `(c<$)`. * Don't forget `RDLN$` and `ADEV$`.
* `RLDICT` is like `RLCORE` but with a chosen target. * `RLDICT` is like `RLCORE` but with a chosen target.
[rc2014]: https://rc2014.co.uk [rc2014]: https://rc2014.co.uk

View File

@ -1 +0,0 @@
128 RAM+ HERE !