Ver código fonte

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.
master
Virgil Dupras 3 anos atrás
pai
commit
532bcc7e78
12 arquivos alterados com 63 adições e 41 exclusões
  1. +1
    -0
      cvm/.gitignore
  2. +11
    -8
      cvm/Makefile
  3. +6
    -6
      cvm/README.md
  4. +3
    -14
      cvm/common.fs
  5. +4
    -1
      cvm/forth.c
  6. +15
    -0
      cvm/forth.fs
  7. BIN
      cvm/stage.bin
  8. +5
    -2
      cvm/stage.c
  9. +11
    -0
      cvm/stage.fs
  10. +3
    -6
      cvm/vm.c
  11. +1
    -1
      cvm/vm.h
  12. +3
    -3
      runtests.sh

+ 1
- 0
cvm/.gitignore Ver arquivo

@@ -1,3 +1,4 @@
/blkfs
/forth
/stage
/forth.bin

+ 11
- 8
cvm/Makefile Ver arquivo

@@ -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

+ 6
- 6
cvm/README.md Ver arquivo

@@ -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

cvm/xcomp.fs → cvm/common.fs Ver arquivo

@@ -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 )

+ 4
- 1
cvm/forth.c Ver arquivo

@@ -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;
}


+ 15
- 0
cvm/forth.fs Ver arquivo

@@ -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!


BIN
cvm/forth.bin → cvm/stage.bin Ver arquivo


+ 5
- 2
cvm/stage.c Ver arquivo

@@ -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;


+ 11
- 0
cvm/stage.fs Ver arquivo

@@ -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!

+ 3
- 6
cvm/vm.c Ver arquivo

@@ -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;


+ 1
- 1
cvm/vm.h Ver arquivo

@@ -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();


+ 3
- 3
runtests.sh Ver arquivo

@@ -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

Carregando…
Cancelar
Salvar