From: Alan Cox Date: Wed, 7 Oct 2015 20:26:45 +0000 (+0100) Subject: coco2: add the bits needed to convert the decb X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=6b2d863451ea10b6fe43bec88e0b0f7514152800;p=FUZIX.git coco2: add the bits needed to convert the decb Turn it into a binary memory image, then apply shuffle the high 4K so the loader unpacks it off the disk image properly. --- diff --git a/Kernel/Makefile b/Kernel/Makefile index 5c277f07..ed270642 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -146,7 +146,7 @@ font4x6.c: tools/make4x6 tools/make4x6 >font4x6.c clean: - rm -f $(OBJS) $(JUNK) fuzix.cdb fuzix.com fuzix.tmp platform fuzix.bin fuzix.map fuzix.noi fuzix.ihx common.ihx common.bin relocs.dat core *~ include/*~ version.c tools/make4x6 tools/analysemap tools/memhogs tools/binman tools/bihx tools/bintomdv tools/chkmdv tools/decbdragon hogs.txt hogs.txt.old tools/*~ + rm -f $(OBJS) $(JUNK) fuzix.cdb fuzix.com fuzix.tmp platform fuzix.bin fuzix.map fuzix.noi fuzix.ihx common.ihx common.bin relocs.dat core *~ include/*~ version.c tools/make4x6 tools/analysemap tools/memhogs tools/binman tools/bihx tools/bintomdv tools/chkmdv tools/decbdragon tools/decb-image hogs.txt hogs.txt.old tools/*~ +$(MAKE) -C platform-$(TARGET) clean +$(MAKE) -C cpm-loader clean +$(MAKE) -C tools/bankld clean diff --git a/Kernel/cpu-6809/image.mk b/Kernel/cpu-6809/image.mk index 460b4eb1..0add73c1 100644 --- a/Kernel/cpu-6809/image.mk +++ b/Kernel/cpu-6809/image.mk @@ -1,2 +1,2 @@ -fuzix.bin: target $(OBJS) tools/decbdragon +fuzix.bin: target $(OBJS) tools/decbdragon tools/decb-image +make -C platform-$(TARGET) image diff --git a/Kernel/cpu-6809/rules.mk b/Kernel/cpu-6809/rules.mk index 098126b2..bee45108 100644 --- a/Kernel/cpu-6809/rules.mk +++ b/Kernel/cpu-6809/rules.mk @@ -15,3 +15,5 @@ export BINEXT = .o export BITS=16 tools/decbdragon: tools/decbdragon.c +tools/decb-image: tools/decb-image.c + diff --git a/Kernel/platform-coco2/Makefile b/Kernel/platform-coco2/Makefile index 7ee229b5..fb675dc2 100644 --- a/Kernel/platform-coco2/Makefile +++ b/Kernel/platform-coco2/Makefile @@ -56,7 +56,10 @@ image: bootfuz.bin ../syscall_proc.o ../syscall_other.o ../mm.o ../swap.o \ ../tty.o ../devsys.o ../usermem.o ../syscall_fs2.o ../syscall_exec16.o \ devtty.o libc.o ../vt.o -# FIXME: need to then convert the decb into an image for the IDE disk booter + ../tools/decb-image <../fuzix.bin fuzix.img + # Repack the high 4K where the loader wants it + dd if=fuzix.img of=fuzix.tmp bs=1024 skip=60 + dd if=fuzix.tmp of=fuzix.img bs=1024 seek=32 conv=notrunc bootfuz.bin: bootloader.s lwasm -r -b -obootfuz.bin bootloader.s diff --git a/Kernel/platform-coco2/fuzix.link b/Kernel/platform-coco2/fuzix.link index 9674fcb7..8988da61 100644 --- a/Kernel/platform-coco2/fuzix.link +++ b/Kernel/platform-coco2/fuzix.link @@ -2,7 +2,6 @@ define basesympat __sectionbase_%s__ define lensympat __sectionlen_%s__ section .istack load 0x0000 section .vectors load 0x0100 -section .udata load 0xFD00 section .start load 0x0400 section .text section .text2 @@ -13,4 +12,5 @@ section .videodata section .common section .text3 section .discard load 0x9000 +section .udata load 0xFD00 entry start diff --git a/Kernel/tools/decb-image.c b/Kernel/tools/decb-image.c new file mode 100644 index 00000000..f135560f --- /dev/null +++ b/Kernel/tools/decb-image.c @@ -0,0 +1,127 @@ +#include +#include +#include +#include + +/* + * Turn a DECB file into a 64K raw memory dump + */ + +static enum { + NEW_BLOCK, + PREAMBLE_1, + PREAMBLE_2, + PREAMBLE_3, + PREAMBLE_4, + POSTAMBLE_1, + POSTAMBLE_2, + POSTAMBLE_3, + POSTAMBLE_4, + DONE, + BYTESTREAM +} state = NEW_BLOCK; + +static unsigned char image[65536]; + +static void write_image(char *path) +{ + int fd = creat(path, 0666); + if (fd == -1) { + perror(path); + exit(1); + } + if (write(fd, image, 65536) != 65536) { + perror(path); + exit(1); + } + if (close(fd) != 0) { + perror(path); + exit(1); + } +} + +int main(int argc, char *argv[]) +{ + unsigned int c; + unsigned int base, size; + + if (argc != 2) { + fprintf(stderr, "%s [image]\n", argv[0]); + exit(1); + } + while(state != DONE && (c = getchar()) != EOF) { + switch(state) { + case NEW_BLOCK: + if (c == 0xFF) { + state = POSTAMBLE_1; + break; + } + if (c == 0x00) { + state = PREAMBLE_1; + break; + } + fprintf(stderr, "Corrupt DECB (%d)\n", c); + exit(1); + break; + + case POSTAMBLE_1: + if (c != 0x00) { + fprintf(stderr, "DECB postamble byte 0 not 0x00\n"); + exit(1); + } + state = POSTAMBLE_2; + break; + case POSTAMBLE_2: + if (c != 0x00) { + fprintf(stderr, "DECB postamble byte 2 not 0x00\n"); + exit(1); + } + state = POSTAMBLE_3; + break; + case POSTAMBLE_3: + state = POSTAMBLE_4; + break; + case POSTAMBLE_4: + state = DONE; + break; + + case PREAMBLE_1: + size = c << 8; + state = PREAMBLE_2; + break; + case PREAMBLE_2: + size += c; + state = PREAMBLE_3; + break; + case PREAMBLE_3: + base = c << 8; + state = PREAMBLE_4; + break; + case PREAMBLE_4: + base += c; + state = BYTESTREAM; + if (base + size > 65535) { + fprintf(stderr, "Oversized image\n"); + exit(1); + } + break; + case BYTESTREAM: + if (image[base]) + fprintf(stderr, "Overwrite at 0x%X\n", base); + image[base++] = c; + size--; + if (size == 0) + state = NEW_BLOCK; + break; + default: + fprintf(stderr, "State machine horked.\n"); + exit(1); + } + } + if (state != DONE) { + fprintf(stderr, "Unexpected EOF in state %d\n", state); + exit(1); + } + write_image(argv[1]); + exit(0); +}