From d08a9711c55acfdef3b71663ff50cf18abadbf26 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 13 Apr 2020 11:35:47 -0400 Subject: [PATCH] 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. --- emul/Makefile | 6 +++--- emul/forth/pre.fs | 2 ++ emul/forth/run.fs | 2 +- emul/forth/z80c.bin | Bin 2169 -> 2172 bytes forth/boot.fs | 4 +++- notes.txt | 19 +++++++++++-------- recipes/rc2014/Makefile | 4 ++-- recipes/rc2014/README.md | 11 ++++++----- recipes/rc2014/pre.fs | 1 - 9 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 emul/forth/pre.fs delete mode 100644 recipes/rc2014/pre.fs diff --git a/emul/Makefile b/emul/Makefile index 4046335..5b57d05 100644 --- a/emul/Makefile +++ b/emul/Makefile @@ -29,7 +29,7 @@ $(BIN2C): forth/forth0.bin: $(SLATEST) cp forth/z80c.bin $@ $(SLATEST) $@ - cat forth/emul.fs >> $@ + cat forth/pre.fs forth/emul.fs >> $@ forth/forth0-bin.h: forth/forth0.bin $(BIN2C) $(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 # don't mistakenly break our code with that tool. It's easier to debug here. 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) cat forth/z80c.bin forth/core.bin > $@ $(SLATEST) $@ 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 $(CC) -DSTAGE2 forth/stage.c $(OBJS) -o $@ diff --git a/emul/forth/pre.fs b/emul/forth/pre.fs new file mode 100644 index 0000000..f3e7ed1 --- /dev/null +++ b/emul/forth/pre.fs @@ -0,0 +1,2 @@ +CURRENT @ HERE ! + diff --git a/emul/forth/run.fs b/emul/forth/run.fs index 15a4fdf..de051f0 100644 --- a/emul/forth/run.fs +++ b/emul/forth/run.fs @@ -1 +1 @@ -: INIT RDLN$ Z80A$ INTERPRET ; +: INIT CURRENT @ HERE ! RDLN$ Z80A$ INTERPRET ; diff --git a/emul/forth/z80c.bin b/emul/forth/z80c.bin index 8dac3ddc393f4fe615f164ea7599eaf7f7ff70ee..543f4722974c933756f302fc75aa12830fd16a67 100644 GIT binary patch delta 1074 zcmY*XO-NKx6#njgKQm+XoGe7l;3-9pIo76y<r3Q`T#E?yq6pC=O;J&4iDTKuZLm5Mi?8qgZ9Gg((-&qtN~#L>jLn0GMBWVGoS~6Gm*d;)xNpE`_9q}(XfKtC-iB1hP3A^( zNf(+?7VB^@FqqA`7nz%(HyRFlBM=sn`Zn?Ish(|ADrt)Kol-Fy0(@60=3-}A#lCo? z?Tc+$Ao32~Y{V(4SU@w%bP?E-tAhACDy#F&!)94^Q);8iNI&3%@bgZ_oXBg=5&zZ2WtQBNIxPLwoHxuZwgxQ7Om4s z?Ngq1c}Gug7DA0hc9Ch-W@4j@IJ0+y*{pj(iIfB#64+KN3D;Wbgy(7FNGWL#h4VNdlV`3$`~lNe;GX~h delta 1074 zcmYLHK}-`-5Pkpeb}6V!1vH2zt_?&Miot^<0+qm0>n6}*yM%%-qRQG4dK7u8F(4(iy|(+$Mv0$8=|LtQ}heB{7@{4z7L;7 zRo*_54(?8kr}M3dn6MDVmhPap_-OsfN}t_^D1$8_crTSpna~-~u~n|<9VO;Ev$3xC$!+FJfae+ zY#^j;wBE1RL?BedhCcf(TeTTc(nd(PGa7?rU(b@!X^nkIwDM?&^lwPxUkj2HAChlG zPjoT;P%ovm`O_%RqoQ;9vCGi7+BNb`Nn-cB>|8cC*~we!H!9+((Xgf_3OK1d;P4f- zA(M2J4Jn7HFIQFxMWV469CeU)W=iu3<}0Tc!h#05%T97u0pF->@5lP2w`E36pB)14wY!*yfV&k zGcI3okwmZn_F=lo!IbM|7F2Z$Nh4`EaHpqJlVfeX2==K;$710*inODVcDyjrP5Vz8 qUp01eIJ|>1P3(HoP}5%|$1g>x)77w*PJsg5pqgEes_7SRLHq^S+1`%; diff --git a/forth/boot.fs b/forth/boot.fs index 8a6eb5e..714369a 100644 --- a/forth/boot.fs +++ b/forth/boot.fs @@ -118,12 +118,14 @@ PC ORG @ 1 + ! ( main ) SP 0xfffa LDddnn, RAMSTART SP LD(nn)dd, ( RAM+00 == INITIAL_SP ) 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 written at offset 0x08 by the process or person building Forth. ) 0x08 LDHL(nn), RAMSTART 0x02 + LD(nn)HL, ( RAM+02 == CURRENT ) - RAMSTART 0x04 + LD(nn)HL, ( RAM+04 == HERE ) EXDEHL, HL L1 @ LDddnn, 0x03 CALLnn, ( 03 == find ) diff --git a/notes.txt b/notes.txt index 49041f5..25774f2 100644 --- a/notes.txt +++ b/notes.txt @@ -170,8 +170,11 @@ advanced to the address following the null. *** Initialization sequence 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: @@ -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 one before your load core.fs and its higher levels. -Also note that this initialization code is fighting for space with HERE: New -entries to the dict will overwrite that code! Also, because we're barebone, we -can't have comments. This leads to peculiar code in this area. If you see weird -whitespace usage, it's probably because not using those whitespace would result -in dict entry creation overwriting the code before it has the chance to be -interpreted. +In the "/emul" binaries, "HERE" is readjusted to "CURRENT @" so that we don't +have to relocate compiled dicts. Note that in this context, the initialization +code is fighting for space with HERE: New entries to the dict will overwrite +that code! Also, because we're barebone, we can't have comments. This can lead +to peculiar code in this area where we try to "waste" space in initialization +code. diff --git a/recipes/rc2014/Makefile b/recipes/rc2014/Makefile index daf1bc1..64e6696 100644 --- a/recipes/rc2014/Makefile +++ b/recipes/rc2014/Makefile @@ -1,4 +1,4 @@ -TARGET = os.bin +TARGET = stage1.bin BASEDIR = ../.. FDIR = $(BASEDIR)/forth EDIR = $(BASEDIR)/emul/forth @@ -13,7 +13,7 @@ BOOTSRCS = conf.fs \ $(FDIR)/icore.fs \ $(EDIR)/xstop.fs -PATHS = pre.fs \ +PATHS = \ $(FDIR)/core.fs \ $(FDIR)/cmp.fs \ $(FDIR)/str.fs \ diff --git a/recipes/rc2014/README.md b/recipes/rc2014/README.md index 856fc61..540ca81 100644 --- a/recipes/rc2014/README.md +++ b/recipes/rc2014/README.md @@ -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 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! @@ -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, 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 `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 yourself. Tough love they call it. -* `cat stage2.bin pre.fs ../../forth/readln.fs run.fs > stage2r.bin` -* Don't forget `(c<$)`. +* `cat stage2.bin ../../forth/readln.fs ../../forth/adev.fs run.fs > stage2r.bin` +* Don't forget `RDLN$` and `ADEV$`. * `RLDICT` is like `RLCORE` but with a chosen target. [rc2014]: https://rc2014.co.uk diff --git a/recipes/rc2014/pre.fs b/recipes/rc2014/pre.fs deleted file mode 100644 index 7aac20a..0000000 --- a/recipes/rc2014/pre.fs +++ /dev/null @@ -1 +0,0 @@ -128 RAM+ HERE !