From 532bcc7e783f2e8ae165ff40cdd065e0d71b13ef Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 14 Nov 2020 14:50:14 -0500 Subject: [PATCH] cvm: split stage and forth xcomp units I wanted to make CVM's forth use the Grid subsystem, but doing so would break the stage binary. Hence, this split. --- cvm/.gitignore | 1 + cvm/Makefile | 19 +++++++++++-------- cvm/README.md | 12 ++++++------ cvm/{xcomp.fs => common.fs} | 17 +++-------------- cvm/forth.c | 5 ++++- cvm/forth.fs | 15 +++++++++++++++ cvm/{forth.bin => stage.bin} | Bin 5132 -> 5080 bytes cvm/stage.c | 7 +++++-- cvm/stage.fs | 11 +++++++++++ cvm/vm.c | 9 +++------ cvm/vm.h | 2 +- runtests.sh | 6 +++--- 12 files changed, 63 insertions(+), 41 deletions(-) rename cvm/{xcomp.fs => common.fs} (84%) create mode 100644 cvm/forth.fs rename cvm/{forth.bin => stage.bin} (83%) create mode 100644 cvm/stage.fs diff --git a/cvm/.gitignore b/cvm/.gitignore index 41d74cd..121b82f 100644 --- a/cvm/.gitignore +++ b/cvm/.gitignore @@ -1,3 +1,4 @@ /blkfs /forth /stage +/forth.bin diff --git a/cvm/Makefile b/cvm/Makefile index 528845a..3117643 100644 --- a/cvm/Makefile +++ b/cvm/Makefile @@ -13,22 +13,25 @@ $(BLKPACK): $(BLKUNPACK): $(BLKPACK) stage: stage.c $(OBJS) blkfs - $(CC) -DBLKFS_PATH=\"`pwd`/blkfs\" stage.c $(OBJS) -o $@ + $(CC) -DFBIN_PATH=\"`pwd`/stage.bin\" -DBLKFS_PATH=\"`pwd`/blkfs\" stage.c $(OBJS) -o $@ blkfs: $(BLKPACK) $(BLKPACK) ../blk > $@ -forth: forth.c $(OBJS) - $(CC) -DBLKFS_PATH=\"`pwd`/blkfs\" forth.c $(OBJS) -lcurses -o $@ +forth.bin: stage common.fs forth.fs blkfs + cat common.fs forth.fs | ./stage > $@ + +forth: forth.c $(OBJS) forth.bin + $(CC) -DFBIN_PATH=\"`pwd`/forth.bin\" -DBLKFS_PATH=\"`pwd`/blkfs\" forth.c $(OBJS) -lcurses -o $@ vm.o: vm.c blkfs - $(CC) -DFBIN_PATH=\"`pwd`/forth.bin\" -c -o vm.o vm.c + $(CC) -c -o vm.o vm.c .PHONY: updatebootstrap -updatebootstrap: stage xcomp.fs pack - ./stage < xcomp.fs > new.bin - mv new.bin forth.bin +updatebootstrap: stage common.fs stage.fs pack + cat common.fs stage.fs | ./stage > new.bin + mv new.bin stage.bin .PHONY: pack pack: @@ -40,4 +43,4 @@ unpack: .PHONY: clean clean: - rm -f $(TARGETS) *.o blkfs + rm -f $(TARGETS) *.o forth.bin blkfs diff --git a/cvm/README.md b/cvm/README.md index a94b619..d26949c 100644 --- a/cvm/README.md +++ b/cvm/README.md @@ -13,11 +13,12 @@ Running `make` will yield `forth` and `stage` executables. ## Usage -To play around Collapse OS, you'll want to run `./forth`. Type `0 LIST` for -help. +To play around Collapse OS, you'll want to run `./forth`. Refer to +`doc/intro.txt` for help. The program is a curses interface with a limited, fixed size so that it can -provide a AT-XY interface. +provide a AT-XY interface. If you wish to change the size of that screen, you +need to modify COLS and LINES in both `forth.c` and `forth.fs`. You can get a REPL by launching the program with [`rlwrap(1)`][rlwrap] like this: @@ -29,7 +30,7 @@ this: If the `forth` executable works badly (hangs, spew garbage, etc.), it's probably because you've broken your bootstrap binary. It's easy to mistakenly break. To verify if you've done that, look at your git status. If -`forth.bin` is modified, try resetting it and then run `make clean all`. Things +`stage.bin` is modified, try resetting it and then run `make clean all`. Things should go better afterwards. A modified `blkfs` can also break things (although even with a completely broken @@ -40,7 +41,6 @@ If that doesn't work, there's also the nuclear option of `git reset --hard` and `git clean -fxd`. If that still doesn't work, it might be because the current commit you're on -is broken, but that is rather rare: the repo on Github is plugged on Travis -and it checks that everything is smooth. +is broken, but that is rather rare. [rlwrap]: https://linux.die.net/man/1/rlwrap diff --git a/cvm/xcomp.fs b/cvm/common.fs similarity index 84% rename from cvm/xcomp.fs rename to cvm/common.fs index af50a31..8d46f2d 100644 --- a/cvm/xcomp.fs +++ b/cvm/common.fs @@ -1,3 +1,5 @@ +( This is xcomp code that is common to both stage and forth + binaries. ) 0xff00 CONSTANT RS_ADDR 0xfffa CONSTANT PS_ADDR RS_ADDR 0x80 - CONSTANT SYSVARS @@ -71,7 +73,6 @@ H@ 4 + XCURRENT ! ( make next CODE have 0 prev field ) 0x37 CODE TICKS 0x38 CODE ROT> 353 LOAD ( xcomp core ) -: (emit) 0 PC! ; : (key) 0 PC@ ; : EFS@ 1 3 PC! ( read ) @@ -83,16 +84,4 @@ H@ 4 + XCURRENT ! ( make next CODE have 0 prev field ) 256 /MOD 3 PC! 3 PC! ( blkid ) BLK( 256 /MOD 3 PC! 3 PC! ( dest ) ; -: COLS 80 ; : LINES 32 ; -: AT-XY 6 PC! ( y ) 5 PC! ( x ) ; - -390 LOAD ( xcomp core high ) -(entry) _ -( Update LATEST ) -PC ORG @ 8 + ! -," BLK$ " -," ' EFS@ BLK@* ! " -," ' EFS! BLK!* ! " -EOT, -ORG @ 256 /MOD 2 PC! 2 PC! -H@ 256 /MOD 2 PC! 2 PC! +( fork between stage and forth begins here ) diff --git a/cvm/forth.c b/cvm/forth.c index aedc48a..6f7bfd2 100644 --- a/cvm/forth.c +++ b/cvm/forth.c @@ -8,6 +8,9 @@ #ifndef BLKFS_PATH #error BLKFS_PATH needed #endif +#ifndef FBIN_PATH +#error FBIN_PATH needed +#endif #define WCOLS 80 #define WLINES 32 #define STDIO_PORT 0x00 @@ -77,7 +80,7 @@ static void iowr_sety(uint8_t val) int main(int argc, char *argv[]) { - VM *vm = VM_init(BLKFS_PATH); + VM *vm = VM_init(FBIN_PATH, BLKFS_PATH); if (!vm) { return 1; } diff --git a/cvm/forth.fs b/cvm/forth.fs new file mode 100644 index 0000000..04f19a6 --- /dev/null +++ b/cvm/forth.fs @@ -0,0 +1,15 @@ +: (emit) 0 PC! ; +: COLS 80 ; : LINES 32 ; +: AT-XY 6 PC! ( y ) 5 PC! ( x ) ; + +390 LOAD ( xcomp core high ) +(entry) _ +( Update LATEST ) +PC ORG @ 8 + ! +," BLK$ " +," ' EFS@ BLK@* ! " +," ' EFS! BLK!* ! " +EOT, +ORG @ 256 /MOD 2 PC! 2 PC! +H@ 256 /MOD 2 PC! 2 PC! + diff --git a/cvm/forth.bin b/cvm/stage.bin similarity index 83% rename from cvm/forth.bin rename to cvm/stage.bin index 6b97f0c26f0522d7cb87080fe6fe1691d0bb61d7..ca07d0691838bd9b08a46505d3c4bdc89e5b1a7d 100644 GIT binary patch delta 193 zcmeCtxS`I;00dfs>a1Hfa#jhjW~WwaN==?2P%W;JnwwdoY01FGIGNFsQHDVyH!(9$ zlXtS8pfNX(pcBJl7HJkIhOWsyf=P@rliv%LFufL>oGO&WXfyeQkcRYY!TAhYKy9u* z!LGs#EsRbKstl9aXEM65Y@N(4Y$*Cv$cbSC%Vc&L21h6Vpb#ZNhBij_$$`R}K%L8h kqM?2vo<3p>tw4?XK#h(}9E?EorwXeA&EE|s9|~&&07--}aR2}S delta 226 zcmcbi-lM_E00eP@>Z~s|a#jh5rsigrXi77%F-~T*WRzjh$WE=)g=4pyfmJ&4P?iO%j zSj-~L;>0j(a)e+KW5DFyf+bAyLX!=Jk{AmnPZ81parOyGFut68UC2;WQrL-M1IuJ~ zpy5vbK_N