From 7eca245badf5aeff9819c9395a8e69202e1b44c5 Mon Sep 17 00:00:00 2001 From: lpproj Date: Mon, 13 Apr 2015 00:03:25 +0900 Subject: [PATCH] Fix broken decompression on loading FAT16 kernel (compressed in dos/sys) --- utils/exeflat.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/utils/exeflat.c b/utils/exeflat.c index c21d254..9f291b4 100644 --- a/utils/exeflat.c +++ b/utils/exeflat.c @@ -53,7 +53,7 @@ large portions copied from task.c #define BUFSIZE 32768u -#define KERNEL_START 0x10 /* the kernel code really starts here at 60:10 */ +#define KERNEL_START 0x16 /* the kernel code really starts here at 60:16 */ typedef struct { UWORD off, seg; @@ -97,6 +97,7 @@ static int exeflat(const char *srcfile, const char *dstfile, FILE *src, *dest; short silentdone = 0; int compress_sys_file; + UWORD realentry; if ((src = fopen(srcfile, "rb")) == NULL) { @@ -198,6 +199,16 @@ static int exeflat(const char *srcfile, const char *dstfile, printf("\nProcessed %d relocations, %d not shown\n", header->exRelocItems, silentdone); + realentry = KERNEL_START; + if (buffers[0][0] == 0xeb /* jmp short */) + { + realentry = buffers[0][1] + 2; + } + else if (buffers[0][0] == 0xe9 /* jmp near */) + { + realentry = ((UWORD)(buffers[0][2]) << 8) + buffers[0][1] + 3; + } + if ((dest = fopen(dstfile, "wb+")) == NULL) { printf("Destination file %s could not be created\n", dstfile); @@ -250,8 +261,9 @@ static int exeflat(const char *srcfile, const char *dstfile, for (i = 0; i < 3; i++) dhdr[i] = 0xffff; /* strategy will jump to us, interrupt never called */ - dhdr[3] = KERNEL_START; + dhdr[3] = realentry; /* KERNEL_START; */ fwrite(dhdr, sizeof(dhdr), 1, dest); + printf("KERNEL_START = 0x%04x\n", realentry); } fclose(dest); return compress_sys_file;