mirror of
https://github.com/FDOS/kernel.git
synced 2025-04-08 17:15:17 +02:00
Use dos/sys compression if the uncompressed kernel is less than 64K. That
makes the compressed kernel about 2K smaller. git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1329 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
parent
ad58440395
commit
29d6eb79f1
@ -38,9 +38,10 @@ production: ..\bin\$(TARGET).sys
|
|||||||
|
|
||||||
kernel.sys: kernel.exe ..\utils\exeflat.exe
|
kernel.sys: kernel.exe ..\utils\exeflat.exe
|
||||||
..\utils\exeflat kernel.exe kernelf.exe 0x60 -S0x10 -S0x74 -E
|
..\utils\exeflat kernel.exe kernelf.exe 0x60 -S0x10 -S0x74 -E
|
||||||
$(XUPX) kernelf.exe
|
if exist kernelf.exe $(XUPX) kernelf.exe
|
||||||
|
if exist kernelf.sys $(XUPX) kernelf.sys
|
||||||
..\utils\exeflat kernelf.exe kernel.sys 0x60 $(UPXOPT)
|
..\utils\exeflat kernelf.exe kernel.sys 0x60 $(UPXOPT)
|
||||||
-$(RM) kernelf.exe
|
-$(RM) kernelf.exe kernelf.sys
|
||||||
|
|
||||||
kernel.exe: $(TARGET).lnk $(OBJS) $(LIBS)
|
kernel.exe: $(TARGET).lnk $(OBJS) $(LIBS)
|
||||||
$(LINK) @$(TARGET).lnk;
|
$(LINK) @$(TARGET).lnk;
|
||||||
|
@ -48,10 +48,13 @@ large portions copied from task.c
|
|||||||
#include "exe.h"
|
#include "exe.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#define BUFSIZE 32768u
|
#define BUFSIZE 32768u
|
||||||
|
|
||||||
|
#define KERNEL_START 0x10 /* the kernel code really starts here at 60:10 */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UWORD off, seg;
|
UWORD off, seg;
|
||||||
} farptr;
|
} farptr;
|
||||||
@ -82,7 +85,7 @@ void usage(void)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
exe_header header;
|
static exe_header header; /* must be initialized to zero */
|
||||||
int i, j;
|
int i, j;
|
||||||
size_t bufsize;
|
size_t bufsize;
|
||||||
farptr *reloc;
|
farptr *reloc;
|
||||||
@ -92,7 +95,7 @@ int main(int argc, char **argv)
|
|||||||
UBYTE **curbuf;
|
UBYTE **curbuf;
|
||||||
FILE *src, *dest;
|
FILE *src, *dest;
|
||||||
short silentSegments[20], silentcount = 0, silentdone = 0;
|
short silentSegments[20], silentcount = 0, silentdone = 0;
|
||||||
int UPX = FALSE, flat_exe = FALSE;
|
int UPX = FALSE, flat_exe = FALSE, compress_sys_file = FALSE;
|
||||||
|
|
||||||
/* if no arguments provided, show usage and exit */
|
/* if no arguments provided, show usage and exit */
|
||||||
if (argc < 4) usage();
|
if (argc < 4) usage();
|
||||||
@ -134,11 +137,23 @@ int main(int argc, char **argv)
|
|||||||
/* arguments left :
|
/* arguments left :
|
||||||
infile outfile relocation offset */
|
infile outfile relocation offset */
|
||||||
|
|
||||||
|
if ((src = fopen(argv[1], "rb")) == NULL)
|
||||||
|
{
|
||||||
|
if (UPX && strlen(argv[1]) > 3)
|
||||||
|
{
|
||||||
|
strcpy(argv[1] + strlen(argv[1]) - 3, "sys");
|
||||||
if ((src = fopen(argv[1], "rb")) == NULL)
|
if ((src = fopen(argv[1], "rb")) == NULL)
|
||||||
{
|
{
|
||||||
printf("Source file %s could not be opened\n", argv[1]);
|
printf("Source file %s could not be opened\n", argv[1]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
compress_sys_file = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (compress_sys_file) {
|
||||||
|
fseek(src, 0, SEEK_END);
|
||||||
|
size = ftell(src);
|
||||||
|
} else {
|
||||||
if (fread(&header, sizeof(header), 1, src) != 1)
|
if (fread(&header, sizeof(header), 1, src) != 1)
|
||||||
{
|
{
|
||||||
printf("Error reading header from %s\n", argv[1]);
|
printf("Error reading header from %s\n", argv[1]);
|
||||||
@ -151,11 +166,6 @@ int main(int argc, char **argv)
|
|||||||
fclose(src);
|
fclose(src);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if ((dest = fopen(argv[2], "wb+")) == NULL)
|
|
||||||
{
|
|
||||||
printf("Destination file %s could not be created\n", argv[2]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
start_seg = (UWORD)strtol(argv[3], NULL, 0);
|
start_seg = (UWORD)strtol(argv[3], NULL, 0);
|
||||||
if (header.exExtraBytes == 0)
|
if (header.exExtraBytes == 0)
|
||||||
header.exExtraBytes = 0x200;
|
header.exExtraBytes = 0x200;
|
||||||
@ -167,6 +177,7 @@ int main(int argc, char **argv)
|
|||||||
printf("image size (less header) = %lu = 0x%lx\n", size, size);
|
printf("image size (less header) = %lu = 0x%lx\n", size, size);
|
||||||
printf("first relocation offset = %u = 0x%u\n", header.exOverlay,
|
printf("first relocation offset = %u = 0x%u\n", header.exOverlay,
|
||||||
header.exOverlay);
|
header.exOverlay);
|
||||||
|
}
|
||||||
|
|
||||||
/* first read file into memory chunks */
|
/* first read file into memory chunks */
|
||||||
fseek(src, header.exHeaderSize * 16UL, SEEK_SET);
|
fseek(src, header.exHeaderSize * 16UL, SEEK_SET);
|
||||||
@ -194,6 +205,8 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (header.exRelocTable && header.exRelocItems)
|
||||||
|
{
|
||||||
fseek(src, header.exRelocTable, SEEK_SET);
|
fseek(src, header.exRelocTable, SEEK_SET);
|
||||||
reloc = malloc(header.exRelocItems * sizeof(farptr));
|
reloc = malloc(header.exRelocItems * sizeof(farptr));
|
||||||
if (reloc == NULL)
|
if (reloc == NULL)
|
||||||
@ -207,6 +220,7 @@ int main(int argc, char **argv)
|
|||||||
printf("Source file read error\n");
|
printf("Source file read error\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fclose(src);
|
fclose(src);
|
||||||
qsort(reloc, header.exRelocItems, sizeof(reloc[0]), compReloc);
|
qsort(reloc, header.exRelocItems, sizeof(reloc[0]), compReloc);
|
||||||
for (i = 0; i < header.exRelocItems; i++)
|
for (i = 0; i < header.exRelocItems; i++)
|
||||||
@ -233,6 +247,17 @@ int main(int argc, char **argv)
|
|||||||
*spot1 = segment >> 8;
|
*spot1 = segment >> 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flat_exe) {
|
||||||
|
compress_sys_file = size < 0x10000L;
|
||||||
|
if (compress_sys_file && strlen(argv[2]) > 3)
|
||||||
|
strcpy(argv[2] + strlen(argv[2]) - 3, "sys");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((dest = fopen(argv[2], "wb+")) == NULL)
|
||||||
|
{
|
||||||
|
printf("Destination file %s could not be created\n", argv[2]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
if (UPX)
|
if (UPX)
|
||||||
{
|
{
|
||||||
/* UPX HEADER jump $+2+size */
|
/* UPX HEADER jump $+2+size */
|
||||||
@ -268,7 +293,7 @@ int main(int argc, char **argv)
|
|||||||
fwrite(JumpBehindCode, 1, 0x20, dest);
|
fwrite(JumpBehindCode, 1, 0x20, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flat_exe) {
|
if (flat_exe && !compress_sys_file) {
|
||||||
/* write header without relocations to file */
|
/* write header without relocations to file */
|
||||||
exe_header nheader = header;
|
exe_header nheader = header;
|
||||||
nheader.exRelocItems = 0;
|
nheader.exRelocItems = 0;
|
||||||
@ -335,8 +360,22 @@ int main(int argc, char **argv)
|
|||||||
*(short *)&trailer[1] = (short)size + 0x20;
|
*(short *)&trailer[1] = (short)size + 0x20;
|
||||||
*(short *)&trailer[23] = header.exInitSS;
|
*(short *)&trailer[23] = header.exInitSS;
|
||||||
*(short *)&trailer[28] = header.exInitSP;
|
*(short *)&trailer[28] = header.exInitSP;
|
||||||
|
if (compress_sys_file)
|
||||||
|
/* replace by jmp word ptr [6]: ff 26 06 00
|
||||||
|
(the .SYS strategy handler which will unpack) */
|
||||||
|
*(long *)&trailer[30] = 0x000626ffL;
|
||||||
fwrite(trailer, 1, sizeof trailer, dest);
|
fwrite(trailer, 1, sizeof trailer, dest);
|
||||||
}
|
}
|
||||||
|
if (flat_exe && compress_sys_file) {
|
||||||
|
/* overwrite first 8 bytes with SYS header */
|
||||||
|
UWORD dhdr[4];
|
||||||
|
fseek(dest, 0, SEEK_SET);
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
dhdr[i] = 0xffff;
|
||||||
|
/* strategy will jump to us, interrupt never called */
|
||||||
|
dhdr[3] = KERNEL_START;
|
||||||
|
fwrite(dhdr, sizeof(dhdr), 1, dest);
|
||||||
|
}
|
||||||
fclose(dest);
|
fclose(dest);
|
||||||
printf("\nProcessed %d relocations, %d not shown\n",
|
printf("\nProcessed %d relocations, %d not shown\n",
|
||||||
header.exRelocItems, silentdone);
|
header.exRelocItems, silentdone);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user