From 1cd4a75e981c3f0f09cce3cac52200d80dc1aa12 Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Wed, 7 Feb 2024 00:53:30 +0100 Subject: [PATCH] sys: fix, allow odd magic offsets to work as expected Created using this scriptlet: sed -i -re 's/\(\(int \*\)newboot\)\[([0-9A-Fa-fxX]+)\/sizeof\(int\)\]/\*\(int \*\)\(\&newboot\[\1\]\)/g' sys/sys.c --- sys/sys.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sys/sys.c b/sys/sys.c index 5edebcc..5ad0b48 100644 --- a/sys/sys.c +++ b/sys/sys.c @@ -1656,12 +1656,12 @@ void put_boot(SYSOptions *opts) if (opts->kernel.stdbs) { /* magic offset: loadsegoff_60 */ - int defaultload = ((int *)newboot)[0x78/sizeof(int)]; + int defaultload = *(int *)(&newboot[0x78]); if (defaultload != 0x60 && defaultload != 0x70) { printf("%s: Internal error: FAT32 load seg unexpected content\n", pgm); exit(1); } - ((int *)newboot)[0x78/sizeof(int)] = opts->kernel.loadaddr; + *(int *)(&newboot[0x78]) = opts->kernel.loadaddr; bsBiosMovOff = 0x82; /* magic offset: mov byte [bp + 40h], dl */ } else /* compatible bs */ @@ -1702,14 +1702,14 @@ void put_boot(SYSOptions *opts) if (opts->kernel.stdbs) { /* magic offset: loadsegoff_60 */ - int defaultload = ((int *)newboot)[0x5C/sizeof(int)]; + int defaultload = *(int *)(&newboot[0x5C]); if (defaultload != 0x60 && defaultload != 0x70) { printf("%s: Internal error: FAT1%c load seg unexpected content\n", pgm, fs == FAT12 ? '2' : '6'); exit(1); } /* this sets the segment we load the kernel to, default is 0x60:0 */ - ((int *)newboot)[0x5c/sizeof(int)] = opts->kernel.loadaddr; + *(int *)(&newboot[0x5C]) = opts->kernel.loadaddr; bsBiosMovOff = 0x66; /* magic offset: mov byte [bp + 24h], dl */ } else @@ -1719,12 +1719,12 @@ void put_boot(SYSOptions *opts) /* this however changes the offset jumped to default 0x70:0 */ if (fs == FAT12) { /* magic offset: jmp LOADSEG:xxxxh */ - defaultload = ((int *)newboot)[0x11A/sizeof(int)]; - ((int *)newboot)[0x11A/sizeof(int)] = opts->kernel.loadaddr; + defaultload = *(int *)(&newboot[0x11A]); + *(int *)(&newboot[0x11A]) = opts->kernel.loadaddr; } else { /* magic offset: jmp LOADSEG:xxxxh */ - defaultload = ((int *)newboot)[0x118/sizeof(int)]; - ((int *)newboot)[0x118/sizeof(int)] = opts->kernel.loadaddr; + defaultload = *(int *)(&newboot[0x118]); + *(int *)(&newboot[0x118]) = opts->kernel.loadaddr; } if (defaultload != 0x0 && defaultload != 0x200) { printf("%s: Internal error: OEM FAT1%c load ofs unexpected content\n",