mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-27 12:58:09 +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:
parent
8d3da4c0de
commit
93c6d150e2
@ -1,6 +1,5 @@
|
|||||||
TARGETS = forth stage blkfs
|
TARGETS = forth stage blkfs
|
||||||
OBJS = emul.o libz80/libz80.o
|
OBJS = emul.o libz80/libz80.o
|
||||||
BIN2C = ../tools/bin2c
|
|
||||||
BLKPACK = ../tools/blkpack
|
BLKPACK = ../tools/blkpack
|
||||||
BLKUNPACK = ../tools/blkunpack
|
BLKUNPACK = ../tools/blkunpack
|
||||||
|
|
||||||
@ -10,22 +9,17 @@ all: $(TARGETS)
|
|||||||
$(BLKPACK):
|
$(BLKPACK):
|
||||||
$(MAKE) -C ../tools
|
$(MAKE) -C ../tools
|
||||||
|
|
||||||
.PHONY: $(BIN2C) $(BLKUNPACK)
|
.PHONY: $(BLKUNPACK)
|
||||||
$(BIN2C): $(BLKPACK)
|
|
||||||
$(BLKUNPACK): $(BLKPACK)
|
$(BLKUNPACK): $(BLKPACK)
|
||||||
|
|
||||||
# not dependent on forth.bin to avoid circular deps.
|
stage: stage.c $(OBJS)
|
||||||
forth-bin.h: $(BIN2C)
|
$(CC) stage.c -DFBIN_PATH=\"`pwd`/forth.bin\" -DBLKFS_PATH=\"`pwd`/blkfs\" $(OBJS) -o $@
|
||||||
$(BIN2C) KERNEL < forth.bin > $@
|
|
||||||
|
|
||||||
stage: stage.c $(OBJS) forth-bin.h
|
|
||||||
$(CC) stage.c -DBLKFS_PATH=\"`pwd`/blkfs\" $(OBJS) -o $@
|
|
||||||
|
|
||||||
blkfs: $(BLKPACK)
|
blkfs: $(BLKPACK)
|
||||||
$(BLKPACK) ../blk > $@
|
$(BLKPACK) ../blk > $@
|
||||||
|
|
||||||
forth: forth.c $(OBJS) forth-bin.h
|
forth: forth.c $(OBJS)
|
||||||
$(CC) forth.c -DBLKFS_PATH=\"`pwd`/blkfs\" $(OBJS) -lncurses -o $@
|
$(CC) forth.c -DFBIN_PATH=\"`pwd`/forth.bin\" -DBLKFS_PATH=\"`pwd`/blkfs\" $(OBJS) -lncurses -o $@
|
||||||
|
|
||||||
libz80/libz80.o: libz80/z80.c
|
libz80/libz80.o: libz80/z80.c
|
||||||
$(MAKE) -C libz80/codegen opcodes
|
$(MAKE) -C libz80/codegen opcodes
|
||||||
@ -37,7 +31,7 @@ emul.o: emul.c
|
|||||||
|
|
||||||
.PHONY: updatebootstrap
|
.PHONY: updatebootstrap
|
||||||
updatebootstrap: stage xcomp.fs pack
|
updatebootstrap: stage xcomp.fs pack
|
||||||
./stage < xcomp.fs > forth.bin
|
./stage < xcomp.fs | tee forth.bin > /dev/null
|
||||||
|
|
||||||
.PHONY: pack
|
.PHONY: pack
|
||||||
pack:
|
pack:
|
||||||
|
32
emul/forth.c
32
emul/forth.c
@ -4,7 +4,12 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include "emul.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
|
// in sync with glue.asm
|
||||||
#define RAMSTART 0x900
|
#define RAMSTART 0x900
|
||||||
@ -56,41 +61,32 @@ static void iowr_blk(uint8_t val)
|
|||||||
{
|
{
|
||||||
blkid <<= 8;
|
blkid <<= 8;
|
||||||
blkid |= val;
|
blkid |= val;
|
||||||
if (blkfp != NULL) {
|
|
||||||
fseek(blkfp, blkid*1024, SEEK_SET);
|
fseek(blkfp, blkid*1024, SEEK_SET);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t iord_blkdata()
|
static uint8_t iord_blkdata()
|
||||||
{
|
{
|
||||||
uint8_t res = 0;
|
uint8_t res = 0;
|
||||||
if (blkfp != NULL) {
|
|
||||||
int c = getc(blkfp);
|
int c = getc(blkfp);
|
||||||
if (c != EOF) {
|
if (c != EOF) {
|
||||||
res = c;
|
res = c;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void iowr_blkdata(uint8_t val)
|
static void iowr_blkdata(uint8_t val)
|
||||||
{
|
{
|
||||||
if (blkfp != NULL) {
|
|
||||||
putc(val, blkfp);
|
putc(val, blkfp);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int run()
|
int run()
|
||||||
{
|
{
|
||||||
#ifdef BLKFS_PATH
|
|
||||||
fprintf(stderr, "Using blkfs %s\n", BLKFS_PATH);
|
fprintf(stderr, "Using blkfs %s\n", BLKFS_PATH);
|
||||||
blkfp = fopen(BLKFS_PATH, "r+");
|
blkfp = fopen(BLKFS_PATH, "r+");
|
||||||
if (!blkfp) {
|
if (!blkfp) {
|
||||||
fprintf(stderr, "Can't open\n");
|
fprintf(stderr, "Can't open\n");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
blkfp = NULL;
|
|
||||||
#endif
|
|
||||||
Machine *m = emul_init();
|
Machine *m = emul_init();
|
||||||
m->ramstart = RAMSTART;
|
m->ramstart = RAMSTART;
|
||||||
m->iord[STDIO_PORT] = iord_stdio;
|
m->iord[STDIO_PORT] = iord_stdio;
|
||||||
@ -100,10 +96,18 @@ int run()
|
|||||||
m->iord[BLKDATA_PORT] = iord_blkdata;
|
m->iord[BLKDATA_PORT] = iord_blkdata;
|
||||||
m->iowr[BLKDATA_PORT] = iowr_blkdata;
|
m->iowr[BLKDATA_PORT] = iowr_blkdata;
|
||||||
// initialize memory
|
// initialize memory
|
||||||
for (int i=0; i<sizeof(KERNEL); i++) {
|
FILE *bfp = fopen(FBIN_PATH, "r");
|
||||||
m->mem[i] = KERNEL[i];
|
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!
|
// Run!
|
||||||
while (emul_step());
|
while (emul_step());
|
||||||
|
|
||||||
|
19
emul/stage.c
19
emul/stage.c
@ -2,8 +2,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "emul.h"
|
#include "emul.h"
|
||||||
#include "forth-bin.h"
|
#ifndef FBIN_PATH
|
||||||
|
#error FBIN_PATH needed
|
||||||
|
#endif
|
||||||
#ifndef BLKFS_PATH
|
#ifndef BLKFS_PATH
|
||||||
#error BLKFS_PATH needed
|
#error BLKFS_PATH needed
|
||||||
#endif
|
#endif
|
||||||
@ -92,10 +93,18 @@ int main(int argc, char *argv[])
|
|||||||
m->iowr[BLK_PORT] = iowr_blk;
|
m->iowr[BLK_PORT] = iowr_blk;
|
||||||
m->iord[BLKDATA_PORT] = iord_blkdata;
|
m->iord[BLKDATA_PORT] = iord_blkdata;
|
||||||
// initialize memory
|
// initialize memory
|
||||||
for (int i=0; i<sizeof(KERNEL); i++) {
|
FILE *bfp = fopen(FBIN_PATH, "r");
|
||||||
m->mem[i] = KERNEL[i];
|
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!
|
// Run!
|
||||||
running = 1;
|
running = 1;
|
||||||
|
|
||||||
|
@ -2,13 +2,12 @@ MEMDUMP_TGT = memdump
|
|||||||
UPLOAD_TGT = upload
|
UPLOAD_TGT = upload
|
||||||
TTYSAFE_TGT = ttysafe
|
TTYSAFE_TGT = ttysafe
|
||||||
PINGPONG_TGT = pingpong
|
PINGPONG_TGT = pingpong
|
||||||
BIN2C_TGT = bin2c
|
|
||||||
EXEC_TGT = exec
|
EXEC_TGT = exec
|
||||||
BLKPACK_TGT = blkpack
|
BLKPACK_TGT = blkpack
|
||||||
BLKUNPACK_TGT = blkunpack
|
BLKUNPACK_TGT = blkunpack
|
||||||
BLKUP_TGT = blkup
|
BLKUP_TGT = blkup
|
||||||
TARGETS = $(MEMDUMP_TGT) $(UPLOAD_TGT) \
|
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)
|
$(BLKUNPACK_TGT) $(BLKUP_TGT)
|
||||||
OBJS = common.o
|
OBJS = common.o
|
||||||
|
|
||||||
@ -22,7 +21,6 @@ $(MEMDUMP_TGT): $(MEMDUMP_TGT).c
|
|||||||
$(UPLOAD_TGT): $(UPLOAD_TGT).c
|
$(UPLOAD_TGT): $(UPLOAD_TGT).c
|
||||||
$(TTYSAFE_TGT): $(TTYSAFE_TGT).c
|
$(TTYSAFE_TGT): $(TTYSAFE_TGT).c
|
||||||
$(PINGPONG_TGT): $(PINGPONG_TGT).c
|
$(PINGPONG_TGT): $(PINGPONG_TGT).c
|
||||||
$(BIN2C_TGT): $(BIN2C_TGT).c
|
|
||||||
$(EXEC_TGT): $(EXEC_TGT).c
|
$(EXEC_TGT): $(EXEC_TGT).c
|
||||||
$(BLKPACK_TGT): $(BLKPACK_TGT).c
|
$(BLKPACK_TGT): $(BLKPACK_TGT).c
|
||||||
$(BLKUNPACK_TGT): $(BLKUNPACK_TGT).c
|
$(BLKUNPACK_TGT): $(BLKUNPACK_TGT).c
|
||||||
|
@ -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");
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user