coco2: add the bits needed to convert the decb
authorAlan Cox <alan@linux.intel.com>
Wed, 7 Oct 2015 20:26:45 +0000 (21:26 +0100)
committerAlan Cox <alan@linux.intel.com>
Wed, 7 Oct 2015 20:26:45 +0000 (21:26 +0100)
Turn it into a binary memory image, then apply shuffle the high 4K so the loader
unpacks it off the disk image properly.

Kernel/Makefile
Kernel/cpu-6809/image.mk
Kernel/cpu-6809/rules.mk
Kernel/platform-coco2/Makefile
Kernel/platform-coco2/fuzix.link
Kernel/tools/decb-image.c [new file with mode: 0644]

index 5c277f0..ed27064 100644 (file)
@@ -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
index 460b4eb..0add73c 100644 (file)
@@ -1,2 +1,2 @@
-fuzix.bin: target $(OBJS) tools/decbdragon
+fuzix.bin: target $(OBJS) tools/decbdragon tools/decb-image
        +make -C platform-$(TARGET) image
index 098126b..bee4510 100644 (file)
@@ -15,3 +15,5 @@ export BINEXT = .o
 export BITS=16
 
 tools/decbdragon: tools/decbdragon.c
+tools/decb-image: tools/decb-image.c
+
index 7ee229b..fb675dc 100644 (file)
@@ -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
index 9674fcb..8988da6 100644 (file)
@@ -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 (file)
index 0000000..f135560
--- /dev/null
@@ -0,0 +1,127 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+/*
+ *     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);
+}