From ad584403952c38254fb71021fd20d7fc2d9d20b0 Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Sat, 26 May 2007 20:03:51 +0000 Subject: [PATCH] Process relocations before compressing kernel.sys. This shaves about 130 bytes off the compressed kernel.sys. git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1328 6ac86273-5f31-0410-b378-82cca8765d1b --- kernel/makefile | 7 ++++--- utils/exeflat.c | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/kernel/makefile b/kernel/makefile index a0bd51c..cc58dfe 100644 --- a/kernel/makefile +++ b/kernel/makefile @@ -37,9 +37,10 @@ production: ..\bin\$(TARGET).sys copy kernel.map ..\bin\$(TARGET).map kernel.sys: kernel.exe ..\utils\exeflat.exe - dir kernel.exe - $(XUPX) kernel.exe - ..\utils\exeflat kernel.exe kernel.sys 0x60 -S0x10 -S0x8B $(UPXOPT) + ..\utils\exeflat kernel.exe kernelf.exe 0x60 -S0x10 -S0x74 -E + $(XUPX) kernelf.exe + ..\utils\exeflat kernelf.exe kernel.sys 0x60 $(UPXOPT) + -$(RM) kernelf.exe kernel.exe: $(TARGET).lnk $(OBJS) $(LIBS) $(LINK) @$(TARGET).lnk; diff --git a/utils/exeflat.c b/utils/exeflat.c index 110d848..e9e6e4a 100644 --- a/utils/exeflat.c +++ b/utils/exeflat.c @@ -92,7 +92,7 @@ int main(int argc, char **argv) UBYTE **curbuf; FILE *src, *dest; short silentSegments[20], silentcount = 0, silentdone = 0; - int UPX = FALSE; + int UPX = FALSE, flat_exe = FALSE; /* if no arguments provided, show usage and exit */ if (argc < 4) usage(); @@ -112,6 +112,9 @@ int main(int argc, char **argv) case 'U': UPX = TRUE; break; + case 'E': + flat_exe = TRUE; + break; case 'S': if (silentcount >= LENGTH(silentSegments)) { @@ -265,6 +268,23 @@ int main(int argc, char **argv) fwrite(JumpBehindCode, 1, 0x20, dest); } + if (flat_exe) { + /* write header without relocations to file */ + exe_header nheader = header; + nheader.exRelocItems = 0; + nheader.exHeaderSize = 2; + size += 32; + nheader.exPages = (UWORD)(size >> 9); + nheader.exExtraBytes = (UWORD)size & 511; + if (nheader.exExtraBytes) + nheader.exPages++; + if (fwrite(&nheader, sizeof(nheader), 1, dest) != 1) { + printf("Destination file write error\n"); + exit(1); + } + fseek(dest, 32UL, SEEK_SET); + } + /* write dest file from memory chunks */ bufsize = BUFSIZE; for (to_xfer = size, curbuf = buffers; to_xfer > 0;