1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-23 15:58:05 +11:00

emul: don't embed forth.bin in emul binaries

Read the contents of forth.bin at runtime. This allows us to get
rid of the bin2c tooling.
This commit is contained in:
Virgil Dupras 2020-05-23 09:54:26 -04:00
parent 8d3da4c0de
commit 93c6d150e2
5 changed files with 44 additions and 89 deletions

View File

@ -1,6 +1,5 @@
TARGETS = forth stage blkfs
OBJS = emul.o libz80/libz80.o
BIN2C = ../tools/bin2c
BLKPACK = ../tools/blkpack
BLKUNPACK = ../tools/blkunpack
@ -10,22 +9,17 @@ all: $(TARGETS)
$(BLKPACK):
$(MAKE) -C ../tools
.PHONY: $(BIN2C) $(BLKUNPACK)
$(BIN2C): $(BLKPACK)
.PHONY: $(BLKUNPACK)
$(BLKUNPACK): $(BLKPACK)
# not dependent on forth.bin to avoid circular deps.
forth-bin.h: $(BIN2C)
$(BIN2C) KERNEL < forth.bin > $@
stage: stage.c $(OBJS) forth-bin.h
$(CC) stage.c -DBLKFS_PATH=\"`pwd`/blkfs\" $(OBJS) -o $@
stage: stage.c $(OBJS)
$(CC) stage.c -DFBIN_PATH=\"`pwd`/forth.bin\" -DBLKFS_PATH=\"`pwd`/blkfs\" $(OBJS) -o $@
blkfs: $(BLKPACK)
$(BLKPACK) ../blk > $@
forth: forth.c $(OBJS) forth-bin.h
$(CC) forth.c -DBLKFS_PATH=\"`pwd`/blkfs\" $(OBJS) -lncurses -o $@
forth: forth.c $(OBJS)
$(CC) forth.c -DFBIN_PATH=\"`pwd`/forth.bin\" -DBLKFS_PATH=\"`pwd`/blkfs\" $(OBJS) -lncurses -o $@
libz80/libz80.o: libz80/z80.c
$(MAKE) -C libz80/codegen opcodes
@ -37,7 +31,7 @@ emul.o: emul.c
.PHONY: updatebootstrap
updatebootstrap: stage xcomp.fs pack
./stage < xcomp.fs > forth.bin
./stage < xcomp.fs | tee forth.bin > /dev/null
.PHONY: pack
pack:

View File

@ -4,7 +4,12 @@
#include <curses.h>
#include <termios.h>
#include "emul.h"
#include "forth-bin.h"
#ifndef FBIN_PATH
#error FBIN_PATH needed
#endif
#ifndef BLKFS_PATH
#error BLKFS_PATH needed
#endif
// in sync with glue.asm
#define RAMSTART 0x900
@ -56,41 +61,32 @@ static void iowr_blk(uint8_t val)
{
blkid <<= 8;
blkid |= val;
if (blkfp != NULL) {
fseek(blkfp, blkid*1024, SEEK_SET);
}
fseek(blkfp, blkid*1024, SEEK_SET);
}
static uint8_t iord_blkdata()
{
uint8_t res = 0;
if (blkfp != NULL) {
int c = getc(blkfp);
if (c != EOF) {
res = c;
}
int c = getc(blkfp);
if (c != EOF) {
res = c;
}
return res;
}
static void iowr_blkdata(uint8_t val)
{
if (blkfp != NULL) {
putc(val, blkfp);
}
putc(val, blkfp);
}
int run()
{
#ifdef BLKFS_PATH
fprintf(stderr, "Using blkfs %s\n", BLKFS_PATH);
blkfp = fopen(BLKFS_PATH, "r+");
if (!blkfp) {
fprintf(stderr, "Can't open\n");
return 1;
}
#else
blkfp = NULL;
#endif
Machine *m = emul_init();
m->ramstart = RAMSTART;
m->iord[STDIO_PORT] = iord_stdio;
@ -100,10 +96,18 @@ int run()
m->iord[BLKDATA_PORT] = iord_blkdata;
m->iowr[BLKDATA_PORT] = iowr_blkdata;
// initialize memory
for (int i=0; i<sizeof(KERNEL); i++) {
m->mem[i] = KERNEL[i];
FILE *bfp = fopen(FBIN_PATH, "r");
if (!bfp) {
fprintf(stderr, "Can't open forth.bin\n");
return 1;
}
int i = 0;
int c = getc(bfp);
while (c != EOF) {
m->mem[i++] = c;
c = getc(bfp);
}
fclose(bfp);
// Run!
while (emul_step());

View File

@ -2,8 +2,9 @@
#include <stdio.h>
#include <unistd.h>
#include "emul.h"
#include "forth-bin.h"
#ifndef FBIN_PATH
#error FBIN_PATH needed
#endif
#ifndef BLKFS_PATH
#error BLKFS_PATH needed
#endif
@ -92,10 +93,18 @@ int main(int argc, char *argv[])
m->iowr[BLK_PORT] = iowr_blk;
m->iord[BLKDATA_PORT] = iord_blkdata;
// initialize memory
for (int i=0; i<sizeof(KERNEL); i++) {
m->mem[i] = KERNEL[i];
FILE *bfp = fopen(FBIN_PATH, "r");
if (!bfp) {
fprintf(stderr, "Can't open forth.bin\n");
return 1;
}
int i = 0;
int c = getc(bfp);
while (c != EOF) {
m->mem[i++] = c;
c = getc(bfp);
}
fclose(bfp);
// Run!
running = 1;

View File

@ -2,13 +2,12 @@ MEMDUMP_TGT = memdump
UPLOAD_TGT = upload
TTYSAFE_TGT = ttysafe
PINGPONG_TGT = pingpong
BIN2C_TGT = bin2c
EXEC_TGT = exec
BLKPACK_TGT = blkpack
BLKUNPACK_TGT = blkunpack
BLKUP_TGT = blkup
TARGETS = $(MEMDUMP_TGT) $(UPLOAD_TGT) \
$(TTYSAFE_TGT) $(PINGPONG_TGT) $(BIN2C_TGT) $(EXEC_TGT) $(BLKPACK_TGT) \
$(TTYSAFE_TGT) $(PINGPONG_TGT) $(EXEC_TGT) $(BLKPACK_TGT) \
$(BLKUNPACK_TGT) $(BLKUP_TGT)
OBJS = common.o
@ -22,7 +21,6 @@ $(MEMDUMP_TGT): $(MEMDUMP_TGT).c
$(UPLOAD_TGT): $(UPLOAD_TGT).c
$(TTYSAFE_TGT): $(TTYSAFE_TGT).c
$(PINGPONG_TGT): $(PINGPONG_TGT).c
$(BIN2C_TGT): $(BIN2C_TGT).c
$(EXEC_TGT): $(EXEC_TGT).c
$(BLKPACK_TGT): $(BLKPACK_TGT).c
$(BLKUNPACK_TGT): $(BLKUNPACK_TGT).c

View File

@ -1,50 +0,0 @@
/*
* Copyright (c) 2020 Byron Grobe
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define BUFSZ 32
static const char intro[] = "static const unsigned char %s[] = {\n ";
int main(int argc, char **argv) {
int n;
int col = 0;
uint8_t buf[BUFSZ];
if (argc < 2) {
fprintf(stderr, "Specify a name for the data structure...\n");
return 1;
}
printf(intro, argv[1]);
while(!feof(stdin)) {
n = fread(buf, 1, BUFSZ, stdin);
for(int i = 0; i < n; ++i) {
if (col+4 >= 76) {
printf("\n ");
col = 0;
}
printf("0x%.2x, ", buf[i]);
col += 6;
}
}
printf("};\n");
}