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 6b97f0c..ca07d06 100644 Binary files a/cvm/forth.bin and b/cvm/stage.bin differ diff --git a/cvm/stage.c b/cvm/stage.c index 0b1015e..1fba4d2 100644 --- a/cvm/stage.c +++ b/cvm/stage.c @@ -6,6 +6,9 @@ #ifndef BLKFS_PATH #error BLKFS_PATH needed #endif +#ifndef FBIN_PATH +#error FBIN_PATH needed +#endif #define RAMSTART 0 #define STDIO_PORT 0x00 // To know which part of RAM to dump, we listen to port 2, which at the end of @@ -45,9 +48,9 @@ static void iowr_here(uint8_t val) int main(int argc, char *argv[]) { if (argc < 2) { - vm = VM_init(BLKFS_PATH); + vm = VM_init(FBIN_PATH, BLKFS_PATH); } else { - vm = VM_init(argv[1]); + vm = VM_init(FBIN_PATH, argv[1]); } if (vm == NULL) { return 1; diff --git a/cvm/stage.fs b/cvm/stage.fs new file mode 100644 index 0000000..1c84fe1 --- /dev/null +++ b/cvm/stage.fs @@ -0,0 +1,11 @@ +: (emit) 0 PC! ; +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/vm.c b/cvm/vm.c index abb2391..c07ed0f 100644 --- a/cvm/vm.c +++ b/cvm/vm.c @@ -12,10 +12,6 @@ // 5 - dest addr LSB #define BLK_PORT 0x03 -#ifndef FBIN_PATH -#error FBIN_PATH needed -#endif - static VM vm; static uint64_t blkop = 0; // 5 bytes static FILE *blkfp; @@ -295,7 +291,8 @@ static void native(NativeWord func) { vm.nativew[vm.nativew_count++] = func; } -VM* VM_init(char *blkfs_path) { +VM* VM_init(char *bin_path, char *blkfs_path) +{ fprintf(stderr, "Using blkfs %s\n", blkfs_path); blkfp = fopen(blkfs_path, "r+"); if (!blkfp) { @@ -309,7 +306,7 @@ VM* VM_init(char *blkfs_path) { return NULL; } fseek(blkfp, 0, SEEK_SET); - FILE *bfp = fopen(FBIN_PATH, "r"); + FILE *bfp = fopen(bin_path, "r"); if (!bfp) { fprintf(stderr, "Can't open forth.bin\n"); return NULL; diff --git a/cvm/vm.h b/cvm/vm.h index 2046f90..21b577e 100644 --- a/cvm/vm.h +++ b/cvm/vm.h @@ -47,7 +47,7 @@ typedef struct { bool oflw; } VM; -VM* VM_init(char *blkfs_path); +VM* VM_init(char *bin_path, char *blkfs_path); void VM_deinit(); bool VM_steps(int n); void VM_memdump(); diff --git a/runtests.sh b/runtests.sh index 1c6a990..2173532 100755 --- a/runtests.sh +++ b/runtests.sh @@ -4,8 +4,8 @@ git clean -fxd make -C tests -# verify that forth.bin is stable -cp cvm/forth.bin ref.bin +# verify that stage.bin is stable +cp cvm/stage.bin ref.bin make -C cvm updatebootstrap -cmp cvm/forth.bin ref.bin +cmp cvm/stage.bin ref.bin rm ref.bin