From e846d07238fc93747de0c530be7f63834bff2811 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Wed, 1 Apr 2020 08:54:01 -0400 Subject: [PATCH] forth: simplify build process Make LATEST configurable through a value in the binary instead of through a ZASM constant. This enables the simple concatenation of compiled dicts and simplifies the build process. --- emul/Makefile | 6 +++--- emul/forth/forth.c | 6 ++++++ emul/forth/stage.c | 7 +++++++ emul/forth/stage0.asm | 6 ++---- emul/forth/stage1.asm | 6 ------ emul/forth/stagec.asm | 4 ---- forth/forth.asm | 19 +++++++++---------- 7 files changed, 27 insertions(+), 27 deletions(-) delete mode 100644 emul/forth/stage1.asm delete mode 100644 emul/forth/stagec.asm diff --git a/emul/Makefile b/emul/Makefile index b6ee35a..0ebdaa1 100644 --- a/emul/Makefile +++ b/emul/Makefile @@ -30,7 +30,7 @@ shell/shell: shell/shell.c $(SHELLOBJS) shell/shell-bin.h # z80c.bin is not in the prerequisites because its a bootstrap binary that # should be updated manually through make fbootstrap. forth/forth0.bin: forth/stage0.asm $(ZASMBIN) - $(ZASMBIN) $(KERNEL) ../forth forth/z80c.bin forth/stagec.asm < forth/stage0.asm | tee $@ > /dev/null + $(ZASMBIN) $(KERNEL) ../forth < forth/stage0.asm | cat - forth/z80c.bin | tee $@ > /dev/null forth/forth0-bin.h: forth/forth0.bin ./bin2c.sh KERNEL < forth/forth0.bin | tee $@ > /dev/null @@ -44,8 +44,8 @@ forth/stage1dbg: forth/stage.c $(OBJS) forth/forth0-bin.h forth/core.bin: $(FORTHSRC_PATHS) forth/stage1 cat $(FORTHSRC_PATHS) | ./forth/stage1 | tee $@ > /dev/null -forth/forth1.bin: forth/stage1.asm forth/forth0.bin forth/core.bin $(ZASMBIN) - $(ZASMBIN) $(KERNEL) ../forth forth/z80c.bin forth/core.bin forth/stagec.asm < forth/stage1.asm | tee $@ > /dev/null +forth/forth1.bin: forth/forth0.bin forth/core.bin + cat forth/forth0.bin forth/core.bin > $@ forth/forth1-bin.h: forth/forth1.bin ./bin2c.sh KERNEL < forth/forth1.bin | tee $@ > /dev/null diff --git a/emul/forth/forth.c b/emul/forth/forth.c index 873b4c1..5225e40 100644 --- a/emul/forth/forth.c +++ b/emul/forth/forth.c @@ -76,6 +76,12 @@ int main(int argc, char *argv[]) for (int i=0; imem[i] = KERNEL[i]; } + + // Our binaries don't have their LATEST offset set yet. We do this + // on the fly, which is the simplest way to proceed ( bash script to update + // LATEST after compilation is too simplicated ) + m->mem[0x08] = sizeof(KERNEL) & 0xff; + m->mem[0x09] = sizeof(KERNEL) >> 8; // Run! running = 1; diff --git a/emul/forth/stage.c b/emul/forth/stage.c index 523c9c1..8d81a60 100644 --- a/emul/forth/stage.c +++ b/emul/forth/stage.c @@ -79,6 +79,13 @@ int main(int argc, char *argv[]) for (int i=0; imem[i] = KERNEL[i]; } + + // Our binaries don't have their LATEST offset set yet. We do this + // on the fly, which is the simplest way to proceed ( bash script to update + // LATEST after compilation is too simplicated ) + m->mem[0x08] = sizeof(KERNEL) & 0xff; + m->mem[0x09] = sizeof(KERNEL) >> 8; + // Run! running = 1; diff --git a/emul/forth/stage0.asm b/emul/forth/stage0.asm index c896d1f..6870f0a 100644 --- a/emul/forth/stage0.asm +++ b/emul/forth/stage0.asm @@ -1,5 +1,3 @@ -.inc "stagec.asm" +.equ RAMSTART 0xe800 +.equ STDIO_PORT 0x00 .inc "forth.asm" - -.bin "z80c.bin" -CODE_END: diff --git a/emul/forth/stage1.asm b/emul/forth/stage1.asm deleted file mode 100644 index 56de03d..0000000 --- a/emul/forth/stage1.asm +++ /dev/null @@ -1,6 +0,0 @@ -.inc "stagec.asm" -.inc "forth.asm" - -.bin "z80c.bin" -.bin "core.bin" -CODE_END: diff --git a/emul/forth/stagec.asm b/emul/forth/stagec.asm deleted file mode 100644 index 9beac71..0000000 --- a/emul/forth/stagec.asm +++ /dev/null @@ -1,4 +0,0 @@ -.equ RAMSTART 0xe800 -.equ HERE_INITIAL CODE_END ; override -.equ LATEST CODE_END ; override -.equ STDIO_PORT 0x00 diff --git a/forth/forth.asm b/forth/forth.asm index 6f2e1a6..1148482 100644 --- a/forth/forth.asm +++ b/forth/forth.asm @@ -38,10 +38,6 @@ .equ SYSVNXT @+WORD_BUFSIZE .equ RAMEND @+SYSV_BUFSIZE+2 -; (HERE) usually starts at RAMEND, but in certain situations, such as in stage0, -; (HERE) will begin at a strategic place. -.equ HERE_INITIAL RAMEND - ; *** Stable ABI *** ; Those jumps below are supposed to stay at these offsets, always. If they ; change bootstrap binaries have to be adjusted because they rely on them. @@ -53,7 +49,9 @@ ; 3 jp find nop \ nop ; unused - nop \ nop \ nop ; unused +; 8 + nop \ nop ; Placeholder for LATEST + nop ; unused ; 11 jp cellWord jp compiledWord @@ -158,12 +156,12 @@ forthMain: ld sp, 0xfffa ld (INITIAL_SP), sp ld ix, RS_ADDR - ; LATEST is a label to the latest entry of the dict. This can be - ; overridden if a binary dict has been grafted to the end of this - ; binary - ld hl, LATEST + ; LATEST is a label to the latest entry of the dict. It is written at + ; offset 0x08 by the process or person building Forth. + ld hl, (0x08) ld (CURRENT), hl - ld hl, HERE_INITIAL + ; For now, we'll always make HERE start right after LATEST. This will + ; not work on ROM-based system, but I'll adjust later. ld (HERE), hl ld hl, .bootName call find @@ -400,6 +398,7 @@ litWord: ld (IP), hl jp next +.fill 3 ; *** Dict hook *** ; This dummy dictionary entry serves two purposes: ; 1. Allow binary grafting. Because each binary dict always end with a dummy