From 698c4a2ea128d0cc6ea82f97a41f1828c62b1b50 Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Tue, 6 Feb 2024 20:00:52 +0100 Subject: [PATCH 01/20] boot32, boot32lb: avoid big file overlap with FAT sector [fixes #127] --- boot/boot32.asm | 2 +- boot/boot32lb.asm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/boot/boot32.asm b/boot/boot32.asm index d195e66e..19f6d9da 100644 --- a/boot/boot32.asm +++ b/boot/boot32.asm @@ -66,7 +66,7 @@ Entry: jmp short real_start %define LOADSEG 0x0060 -%define FATSEG 0x2000 +%define FATSEG 0x2200 %define fat_sector bp+0x48 ; last accessed sector of the FAT diff --git a/boot/boot32lb.asm b/boot/boot32lb.asm index da3224ca..fdffdb13 100644 --- a/boot/boot32lb.asm +++ b/boot/boot32lb.asm @@ -85,7 +85,7 @@ Entry: jmp short real_start %define LOADSEG 0x0060 -%define FATSEG 0x2000 +%define FATSEG 0x2200 %define fat_secshift fat_afterss-1 ; each fat sector describes 2^?? ; clusters (db) (selfmodifying) From b4f9e7aa55c35337bfbc576d824e29d6a5cea590 Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Tue, 6 Feb 2024 20:07:59 +0100 Subject: [PATCH 02/20] boot: rename FATBUF to CLUSTLIST to better reflect use (oemboot pick) --- boot/boot.asm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/boot/boot.asm b/boot/boot.asm index 29f458f0..b2ae64fe 100644 --- a/boot/boot.asm +++ b/boot/boot.asm @@ -99,8 +99,8 @@ Entry: jmp short real_start %define LOADSEG 0x0060 -%define FATBUF 0x2000 ; offset of temporary buffer for FAT - ; chain +%define CLUSTLIST 0x2000 ; offset of temporary buffer for FAT + ; chain cluster list ; Some extra variables @@ -294,7 +294,7 @@ ffDone: push ds pop es mov ds, [loadseg_60] - mov di, FATBUF + mov di, CLUSTLIST next_clust: stosw ; store cluster number mov si, ax ; SI = cluster number @@ -351,7 +351,7 @@ finished: ; Mark end of FAT chain with 0, so we have a single les bx, [loadsegoff_60] ; set ES:BX to load address 60:0 - mov si, FATBUF ; set DS:SI to the FAT chain + mov si, CLUSTLIST ; set DS:SI to the FAT chain cluster_next: lodsw ; AX = next cluster to read or ax, ax ; EOF? From be92d833ce6270084a01f91bcda5ab72b086a8c5 Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Tue, 6 Feb 2024 20:14:04 +0100 Subject: [PATCH 03/20] boot: move cluster list to 1FE0h:2200h (128 KiB file, up to /L 0x200) 1FE0h:2200h happens to be linear 22000h. Like the memory map update to the FAT32 loaders for #127 this allows to load a file of up to 128 KiB (rounded to cluster size) with an /L parameter for SYS of up to 0x200. --- boot/boot.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot/boot.asm b/boot/boot.asm index b2ae64fe..9f425ce6 100644 --- a/boot/boot.asm +++ b/boot/boot.asm @@ -99,7 +99,7 @@ Entry: jmp short real_start %define LOADSEG 0x0060 -%define CLUSTLIST 0x2000 ; offset of temporary buffer for FAT +%define CLUSTLIST 0x2200 ; offset of temporary buffer for FAT ; chain cluster list ; Some extra variables From 72732916e3fbfb0599ff5ac82bdbb3a197c4ce32 Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Tue, 6 Feb 2024 20:36:09 +0100 Subject: [PATCH 04/20] boot32, boot32lb: fix and update memory layout maps --- boot/boot32.asm | 55 +++++++++++++++++++++++------------------------ boot/boot32lb.asm | 30 +++++++++++++++----------- 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/boot/boot32.asm b/boot/boot32.asm index 19f6d9da..cd5327c7 100644 --- a/boot/boot32.asm +++ b/boot/boot32.asm @@ -1,31 +1,30 @@ -; +--------+ -; | | -; | | -; |--------| 4000:0000 -; | | -; | FAT | -; | | -; |--------| 2000:0000 -; |BOOT SEC| -; |RELOCATE| -; |--------| 1FE0:0000 -; | | -; | | -; | | -; | | -; |--------| -; |BOOT SEC| -; |ORIGIN | 07C0:0000 -; |--------| -; | | -; | | -; | | -; |--------| -; |KERNEL | -; |LOADED | -; |--------| 0060:0000 -; | | -; +--------+ + +; Memory layout for the FreeDOS FAT32 single stage boot process: +; +; ... +; |-------| 1FE0h:7E00h = 27C00h (159 KiB) +; |BOOTSEC| loader relocates itself here first thing, +; |RELOC. | before loading root directory/FAT/kernel file +; |-------| 1FE0h:7C00h = 27A00h (158 KiB) +; | STACK | below relocated loader, above FAT sector (size 22 KiB) +; ... +; |-------| 2200h:2000h = 24000h (144 KiB) +; | FAT | (only 1 sector buffered, maximum sector size 8 KiB) +; |-------| 2200h:0000h = 22000h (136 KiB) +; ... +; |-------| 0000h:7E00h = 07E00h (31.5 KiB) +; |BOOTSEC| overwritten by the kernel, so the +; |ORIGIN | bootsector relocates itself up... +; |-------| 0000h:7C00h = 07C00h (31 KiB) +; ... +; |-------| +; |KERNEL | maximum size 128 KiB (overwrites bootsec origin) +; |LOADED | (holds 1 sector directory buffer before kernel file load) +; |-------| 0060h:0000h = 00600h (1.5 KiB) +; ... +; The kernel load segment may be patched using the SYS /L switch. +; We support values between 0x60 and 0x200 here, with file size +; of up to 128 KiB (rounded to cluster size). Default is 0x60. ;%define MULTI_SEC_READ 1 diff --git a/boot/boot32lb.asm b/boot/boot32lb.asm index fdffdb13..708861a6 100644 --- a/boot/boot32lb.asm +++ b/boot/boot32lb.asm @@ -27,27 +27,31 @@ ; Memory layout for the FreeDOS FAT32 single stage boot process: - +; ; ... -; |-------| 1FE0:7E00 -; |BOOTSEC| -; |RELOC. | -; |-------| 1FE0:7C00 +; |-------| 1FE0h:7E00h = 27C00h (159 KiB) +; |BOOTSEC| loader relocates itself here first thing, +; |RELOC. | before loading root directory/FAT/kernel file +; |-------| 1FE0h:7C00h = 27A00h (158 KiB) +; | STACK | below relocated loader, above FAT sector (size 22 KiB) ; ... -; |-------| 2000:0200 -; | FAT | (only 1 sector buffered) -; |-------| 2000:0000 +; |-------| 2200h:2000h = 24000h (144 KiB) +; | FAT | (only 1 sector buffered, maximum sector size 8 KiB) +; |-------| 2200h:0000h = 22000h (136 KiB) ; ... -; |-------| 0000:7E00 +; |-------| 0000h:7E00h = 07E00h (31.5 KiB) ; |BOOTSEC| overwritten by the kernel, so the ; |ORIGIN | bootsector relocates itself up... -; |-------| 0000:7C00 +; |-------| 0000h:7C00h = 07C00h (31 KiB) ; ... ; |-------| -; |KERNEL | maximum size 134k (overwrites bootsec origin) -; |LOADED | (holds 1 sector directory buffer before kernel load) -; |-------| 0060:0000 +; |KERNEL | maximum size 128 KiB (overwrites bootsec origin) +; |LOADED | (holds 1 sector directory buffer before kernel file load) +; |-------| 0060h:0000h = 00600h (1.5 KiB) ; ... +; The kernel load segment may be patched using the SYS /L switch. +; We support values between 0x60 and 0x200 here, with file size +; of up to 128 KiB (rounded to cluster size). Default is 0x60. segment .text From 71896f58b36d58d54186624335c7860c453f0e81 Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Tue, 6 Feb 2024 21:21:40 +0100 Subject: [PATCH 05/20] boot: fix and update memory layout map --- boot/boot.asm | 81 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 30 deletions(-) diff --git a/boot/boot.asm b/boot/boot.asm index 9f425ce6..f085837f 100644 --- a/boot/boot.asm +++ b/boot/boot.asm @@ -24,38 +24,59 @@ ; License along with DOS-C; see the file COPYING. If not, ; write to the Free Software Foundation, 675 Mass Ave, ; Cambridge, MA 02139, USA. -; -; -; +--------+ 1FE0:7E00 -; |BOOT SEC| -; |RELOCATE| -; |--------| 1FE0:7C00 -; |LBA PKT | -; |--------| 1FE0:7BC0 -; |--------| 1FE0:7BA0 -; |BS STACK| -; |--------| -; |4KBRDBUF| used to avoid crossing 64KB DMA boundary -; |--------| 1FE0:63A0 -; | | -; |--------| 1FE0:3000 -; | CLUSTER| -; | LIST | -; |--------| 1FE0:2000 -; | | -; |--------| 0000:7E00 -; |BOOT SEC| overwritten by max 128k FAT buffer -; |ORIGIN | and later by max 134k loaded kernel -; |--------| 0000:7C00 -; | | -; |--------| -; |KERNEL | also used as max 128k FAT buffer -; |LOADED | before kernel loading starts -; |--------| 0060:0000 -; | | -; +--------+ +; Memory layout for the FreeDOS FAT12/FAT16 boot process: +; +; ... +; |-------| 1FE0h:7E00h = 27C00h (159 KiB) +; |BOOTSEC| loader relocates itself here first thing, +; |RELOC. | before loading root directory/FAT/kernel file +; |-------| 1FE0h:7C00h = 27A00h (158 KiB) +; | gap | +; |LBA PKT| LBA disk packet +; |-------| 1FE0h:7BC0h = 279C0h (158 KiB) +; | gap | +; |-------| 1FE0h:7BA0h = 279A0h (158 KiB) +; | STACK | below relocated loader, above sector buffer (size 2 KiB) +; ... +; |-------| +; |SEC.BUF| sector buffer, used to avoid crossing 64 KiB DMA boundary +; |-------| 1FE0h:63A0h = 261A0h (152 KiB) +; ... +; |-------| 1FE0h:4380h = 24182h (144 KiB) +; |CLUSTER| built from FAT, listing every cluster of the kernel file. +; | LIST | file <= 134 KiB, cluster >= 32 Byte, hence <= 8578 B list. +; |-------| 1FE0h:2200h = 22000h (136 KiB) +; ... +; |-------| 0000h:7E00h = 07E00h (31.5 KiB) +; |BOOTSEC| possibly overwritten by the FAT (<= 128 KiB) and the kernel, +; |ORIGIN | so the bootsector relocates itself up... +; |-------| 0000h:7C00h = 07C00h (31 KiB) +; ... +; |-------| +; |KERNEL | maximum size 128 KiB (overwrites bootsec origin) +; |LOADED | (holds directory then FAT before kernel file load) +; |-------| 0060h:0000h = 00600h (1.5 KiB) +; ... +; The entire root directory is loaded to the kernel load address +; to scan for the kernel file. It is assumed to fit into 128 KiB. +; Typical root directory size is up to 512 entries = 16 KiB. +; Further, it is assumed that at least one root directory entry +; starts with a NUL byte to signify the end of the directory. +; After the directory entry is found, the entire FAT is loaded to +; the kernel load address. It is assumed that the size of the FAT +; in sectPerFat will not lead to a FAT larger than 128 KiB, which +; is the maximum size a FAT16 may fully utilise. +; The kernel load segment may be patched using the SYS /L switch. +; We support values between 0x60 and 0x200 here, with file size +; of up to 128 KiB (rounded to cluster size). Default is 0x60. +; This loader traditionally supports file sizes up to 134 KiB, +; assuming the default segment of 0x60. This does require a +; cluster size of 4 KiB (leads to maximum 132 KiB) or 2 KiB or +; lower (maximum 134 KiB). A more portable maximum is 128 KiB, +; which works with cluster sizes up to 128 KiB. + ;%define ISFAT12 1 ;%define ISFAT16 1 ;verify one and only one of ISFAT12 or ISFAT16 is defined From c94fc072dcfe86dfe6bee8c87a9c4715c477981f Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Tue, 6 Feb 2024 22:01:22 +0100 Subject: [PATCH 06/20] boot: move READBUF and READADDR_OFF/SEG to allow 8 KiB sector size --- boot/boot.asm | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/boot/boot.asm b/boot/boot.asm index f085837f..16381338 100644 --- a/boot/boot.asm +++ b/boot/boot.asm @@ -33,16 +33,16 @@ ; |BOOTSEC| loader relocates itself here first thing, ; |RELOC. | before loading root directory/FAT/kernel file ; |-------| 1FE0h:7C00h = 27A00h (158 KiB) -; | gap | +; | gap | PARAMS live here ; |LBA PKT| LBA disk packet ; |-------| 1FE0h:7BC0h = 279C0h (158 KiB) -; | gap | +; | gap | READADDR_* live here ; |-------| 1FE0h:7BA0h = 279A0h (158 KiB) -; | STACK | below relocated loader, above sector buffer (size 2 KiB) +; | STACK | below relocated loader, above sector buffer (size 5.9 KiB) ; ... -; |-------| -; |SEC.BUF| sector buffer, used to avoid crossing 64 KiB DMA boundary -; |-------| 1FE0h:63A0h = 261A0h (152 KiB) +; |-------| 1FE0h:6400h = 26200h (152 KiB) +; |SEC.BUF| sector buffer, to avoid crossing 64 KiB DMA boundary (size 8 KiB) +; |-------| 1FE0h:4400h = 24200h (144 KiB) ; ... ; |-------| 1FE0h:4380h = 24182h (144 KiB) ; |CLUSTER| built from FAT, listing every cluster of the kernel file. @@ -155,9 +155,9 @@ Entry: jmp short real_start %define LBA_SECTOR_32 word [LBA_PACKET+12] %define LBA_SECTOR_48 word [LBA_PACKET+14] -%define READBUF 0x63A0 ; max 4KB buffer (min 2KB stack), == stacktop-0x1800 -%define READADDR_OFF BP-0x60-0x1804 ; pointer within user buffer -%define READADDR_SEG BP-0x60-0x1802 +%define READBUF 0x4400 ; max 8 KiB buffer +%define READADDR_OFF word BP-0x60 ; pointer within user buffer +%define READADDR_SEG word BP-0x60+2 %define PARAMS LBA_PACKET+0x10 ;%define RootDirSecs PARAMS+0x0 ; # of sectors root dir uses From 1a781abbfd092d7fe648e4f624bd6123a787af76 Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Tue, 6 Feb 2024 23:19:26 +0100 Subject: [PATCH 07/20] sys: check default content of all magic offset patchsites --- sys/sys.c | 52 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/sys/sys.c b/sys/sys.c index 120636af..95f2a267 100644 --- a/sys/sys.c +++ b/sys/sys.c @@ -1579,6 +1579,7 @@ void put_boot(SYSOptions *opts) /* !!! if boot sector changes then update these locations !!! */ { + /* magic offset: LBA detection */ unsigned offset; offset = (fs == FAT16) ? 0x178 : 0x17B; @@ -1598,7 +1599,8 @@ void put_boot(SYSOptions *opts) } else { - printf("%s : fat boot sector does not match expected layout\n", pgm); + printf("%s: Internal error: FAT1%c LBA detect unexpected content\n", + pgm, fs == FAT12 ? '2' : '6'); exit(1); } } @@ -1653,8 +1655,14 @@ void put_boot(SYSOptions *opts) */ if (opts->kernel.stdbs) { + /* magic offset: loadsegoff_60 */ + int defaultload = ((int *)newboot)[0x78/sizeof(int)]; + 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; - bsBiosMovOff = 0x82; + bsBiosMovOff = 0x82; /* magic offset: mov byte [bp + 40h], dl */ } else /* compatible bs */ { @@ -1693,35 +1701,53 @@ void put_boot(SYSOptions *opts) */ if (opts->kernel.stdbs) { + /* magic offset: loadsegoff_60 */ + int defaultload = ((int *)newboot)[0x5C/sizeof(int)]; + 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; - bsBiosMovOff = 0x66; + bsBiosMovOff = 0x66; /* magic offset: mov byte [bp + 24h], dl */ } else { + int defaultload; /* load segment hard coded to 0x70 in oem compatible boot sector, */ /* this however changes the offset jumped to default 0x70:0 */ - if (fs == FAT12) + if (fs == FAT12) { + /* magic offset: jmp LOADSEG:xxxxh */ + defaultload = ((int *)newboot)[0x11c/sizeof(int)]; ((int *)newboot)[0x11c/sizeof(int)] = opts->kernel.loadaddr; - else + } else { + /* magic offset: jmp LOADSEG:xxxxh */ + defaultload = ((int *)newboot)[0x119/sizeof(int)]; ((int *)newboot)[0x119/sizeof(int)] = opts->kernel.loadaddr; - bsBiosMovOff = 0x4F; + } + if (defaultload != 0x0 && defaultload != 0x200) { + printf("%s: Internal error: OEM FAT1%c load ofs unexpected content\n", + pgm, fs == FAT12 ? '2' : '6'); + exit(1); + } + bsBiosMovOff = 0x4F; /* magic offset: mov byte [bp + 24h], dl */ } } - if (opts->ignoreBIOS) + if ( (newboot[bsBiosMovOff]==0x88) && (newboot[bsBiosMovOff+1]==0x56) ) { - if ( (newboot[bsBiosMovOff]==0x88) && (newboot[bsBiosMovOff+1]==0x56) ) + if (opts->ignoreBIOS) { newboot[bsBiosMovOff] = 0x90; /* NOP */ ++bsBiosMovOff; newboot[bsBiosMovOff] = 0x90; /* NOP */ ++bsBiosMovOff; newboot[bsBiosMovOff] = 0x90; /* NOP */ ++bsBiosMovOff; } - else - { - printf("%s : fat boot sector does not match expected layout\n", pgm); - exit(1); - } + } + else + { + printf("%s: Internal error: Unit save unexpected content\n", pgm); + exit(1); } if (opts->verbose) /* display information about filesystem */ From dc4d1554515614d4ca554d35db249fb678da5b5a Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Tue, 6 Feb 2024 23:22:01 +0100 Subject: [PATCH 08/20] sys: update magic offset of OEM FAT12 jmp offset --- sys/sys.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/sys.c b/sys/sys.c index 95f2a267..eb6d0dc7 100644 --- a/sys/sys.c +++ b/sys/sys.c @@ -1719,8 +1719,8 @@ 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)[0x11c/sizeof(int)]; - ((int *)newboot)[0x11c/sizeof(int)] = opts->kernel.loadaddr; + defaultload = ((int *)newboot)[0x11A/sizeof(int)]; + ((int *)newboot)[0x11A/sizeof(int)] = opts->kernel.loadaddr; } else { /* magic offset: jmp LOADSEG:xxxxh */ defaultload = ((int *)newboot)[0x119/sizeof(int)]; From 556ef4c9a82bc14d3425b5663ea23cc94cf13e79 Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Tue, 6 Feb 2024 23:27:13 +0100 Subject: [PATCH 09/20] boot: display new magic offset (but in decimal) --- boot/boot.asm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/boot/boot.asm b/boot/boot.asm index 16381338..387e28f8 100644 --- a/boot/boot.asm +++ b/boot/boot.asm @@ -459,7 +459,8 @@ read_next: ; of the ISFATx defines. %endif %if ($ - Entry) != LBA_TEST_OFFSET - %error Must update constant offset (LBA_TEST_OFFSET) to test dl,dl here and in sys.c for FATFS + %assign NEWOFFSET $ - Entry + %error Magic offset to LBA detection changed for FATFS, old=LBA_TEST_OFFSET, new=NEWOFFSET %endif test dl,dl ; don't use LBA addressing on A: jz read_normal_BIOS ; might be a (buggy) From 4314014fd532bf632a259065b98497ace988971b Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Tue, 6 Feb 2024 23:48:35 +0100 Subject: [PATCH 10/20] boot: extract magicoffset macro --- boot/boot.asm | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/boot/boot.asm b/boot/boot.asm index 387e28f8..a10c244f 100644 --- a/boot/boot.asm +++ b/boot/boot.asm @@ -88,6 +88,24 @@ %error Must select one FS %endif + ; NOTE: sys must be updated if magic offsets change + %macro magicoffset 3.nolist +%ifdef ISFAT12 + %define SYSOFFSET %2 +%elifdef ISFAT16 + %define SYSOFFSET %3 +%else + %define SYSOFFSET 0 + ; Just a placeholder, so the proper error message + ; will be shown when assembling without either + ; of the ISFATx defines. +%endif +%assign NEWOFFSET $ - Entry +%if NEWOFFSET != SYSOFFSET + %error Magic offset %1 changed for FATFS, old=SYSOFFSET, new=NEWOFFSET +%endif + %endmacro + segment .text @@ -447,21 +465,7 @@ read_next: mov bx,055aah ; mov dl, [drive] - ; NOTE: sys must be updated if location changes!!! -%ifdef ISFAT12 - %define LBA_TEST_OFFSET 17Bh -%elifdef ISFAT16 - %define LBA_TEST_OFFSET 178h -%else - %define LBA_TEST_OFFSET 0 - ; Just a placeholder, so the proper error message - ; will be shown when assembling without either - ; of the ISFATx defines. -%endif -%if ($ - Entry) != LBA_TEST_OFFSET - %assign NEWOFFSET $ - Entry - %error Magic offset to LBA detection changed for FATFS, old=LBA_TEST_OFFSET, new=NEWOFFSET -%endif + magicoffset "LBA detection", 17Bh, 178h test dl,dl ; don't use LBA addressing on A: jz read_normal_BIOS ; might be a (buggy) ; CDROM-BOOT floppy emulation From 47981f652740b35cd423b9e41f75ad58e6d546bc Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Tue, 6 Feb 2024 23:51:33 +0100 Subject: [PATCH 11/20] boot: display new magic offset in hexadecimal --- boot/boot.asm | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/boot/boot.asm b/boot/boot.asm index a10c244f..6b94d48f 100644 --- a/boot/boot.asm +++ b/boot/boot.asm @@ -88,6 +88,50 @@ %error Must select one FS %endif + +%macro _appenddigitstrdef 2.nolist +%substr %%ii "0123456789ABCDEF" (%2) + 1 +%strcat _%1 _%1,%%ii +%endmacro + + ; %1 = name of single-line macro to set. will be prefixed by underscore + ; %2 = number to write + ; %3 = minimal number of hexits, 0..8. defaults to 1 + ; (setting it to 0 with a number of 0 defines macro to "") +%macro _autohexitsstrdef 2-3.nolist 1 +%if %3 > 8 + %error Minimal number of hexits 9 or more: %3 +%endif +%define _%1 "" +%if (%2) >= 1_0000_0000h + %error Number has to use 9 or more hexits: %2 +%endif +%if (%2) >= 1000_0000h || %3 >= 8 +_appenddigitstrdef %1, (%2 >> (7 * 4)) & 0Fh +%endif +%if (%2) >= 100_0000h || %3 >= 7 +_appenddigitstrdef %1, (%2 >> (6 * 4)) & 0Fh +%endif +%if (%2) >= 10_0000h || %3 >= 6 +_appenddigitstrdef %1, (%2 >> (5 * 4)) & 0Fh +%endif +%if (%2) >= 1_0000h || %3 >= 5 +_appenddigitstrdef %1, (%2 >> (4 * 4)) & 0Fh +%endif +%if (%2) >= 1000h || %3 >= 4 +_appenddigitstrdef %1, (%2 >> (3 * 4)) & 0Fh +%endif +%if (%2) >= 100h || %3 >= 3 +_appenddigitstrdef %1, (%2 >> (2 * 4)) & 0Fh +%endif +%if (%2) >= 10h || %3 >= 2 +_appenddigitstrdef %1, (%2 >> (1 * 4)) & 0Fh +%endif +%if (%2) >= 1h || %3 >= 1 +_appenddigitstrdef %1, (%2 >> (0 * 4)) & 0Fh +%endif +%endmacro + ; NOTE: sys must be updated if magic offsets change %macro magicoffset 3.nolist %ifdef ISFAT12 @@ -102,6 +146,9 @@ %endif %assign NEWOFFSET $ - Entry %if NEWOFFSET != SYSOFFSET + _autohexitsstrdef NEWOFFSETHEX, NEWOFFSET + %strcat _NEWOFFSETHEX _NEWOFFSETHEX,'h' + %deftok NEWOFFSET _NEWOFFSETHEX %error Magic offset %1 changed for FATFS, old=SYSOFFSET, new=NEWOFFSET %endif %endmacro From e4a43558c2661d01f84f5bc96e054b1952cf11e5 Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Tue, 6 Feb 2024 23:58:10 +0100 Subject: [PATCH 12/20] sys, boot: mark additional magic offsets --- boot/boot.asm | 3 +++ sys/sys.c | 1 + 2 files changed, 4 insertions(+) diff --git a/boot/boot.asm b/boot/boot.asm index 6b94d48f..a52bb522 100644 --- a/boot/boot.asm +++ b/boot/boot.asm @@ -264,6 +264,7 @@ real_start: jmp word 0x1FE0:cont loadseg_off dw 0 + magicoffset "loadseg", 5Ch, 5Ch loadseg_seg dw LOADSEG cont: @@ -276,6 +277,7 @@ cont: ; in DL, however we work around this in SYS.COM by NOP'ing out the use of DL ; (formerly we checked for [drive]==0xff; update sys.c if code moves) ; + magicoffset "set unit", 66h, 66h mov [drive], dl ; rely on BIOS drive number in DL mov LBA_SIZE, 10h @@ -616,6 +618,7 @@ do_int13_read: times 0x01f1-$+$$ db 0 + magicoffset "kernel name", 1F1h, 1F1h filename db "KERNEL SYS",0,0 sign dw 0xAA55 diff --git a/sys/sys.c b/sys/sys.c index eb6d0dc7..3cffcc69 100644 --- a/sys/sys.c +++ b/sys/sys.c @@ -1762,6 +1762,7 @@ void put_boot(SYSOptions *opts) { int i = 0; + /* magic offset: (first) kernel filename */ memset(&newboot[0x1f1], ' ', 11); while (opts->kernel.kernel[i] && opts->kernel.kernel[i] != '.') { From 4e845a8b5d256924ed497c4850ad496c6bf21a90 Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Wed, 7 Feb 2024 00:05:45 +0100 Subject: [PATCH 13/20] magic.mac: extract from boot.asm --- boot/boot.asm | 65 ++------------------------------------------------ boot/magic.mac | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 63 deletions(-) create mode 100644 boot/magic.mac diff --git a/boot/boot.asm b/boot/boot.asm index a52bb522..1c427d25 100644 --- a/boot/boot.asm +++ b/boot/boot.asm @@ -88,70 +88,9 @@ %error Must select one FS %endif - -%macro _appenddigitstrdef 2.nolist -%substr %%ii "0123456789ABCDEF" (%2) + 1 -%strcat _%1 _%1,%%ii -%endmacro - - ; %1 = name of single-line macro to set. will be prefixed by underscore - ; %2 = number to write - ; %3 = minimal number of hexits, 0..8. defaults to 1 - ; (setting it to 0 with a number of 0 defines macro to "") -%macro _autohexitsstrdef 2-3.nolist 1 -%if %3 > 8 - %error Minimal number of hexits 9 or more: %3 -%endif -%define _%1 "" -%if (%2) >= 1_0000_0000h - %error Number has to use 9 or more hexits: %2 -%endif -%if (%2) >= 1000_0000h || %3 >= 8 -_appenddigitstrdef %1, (%2 >> (7 * 4)) & 0Fh -%endif -%if (%2) >= 100_0000h || %3 >= 7 -_appenddigitstrdef %1, (%2 >> (6 * 4)) & 0Fh -%endif -%if (%2) >= 10_0000h || %3 >= 6 -_appenddigitstrdef %1, (%2 >> (5 * 4)) & 0Fh -%endif -%if (%2) >= 1_0000h || %3 >= 5 -_appenddigitstrdef %1, (%2 >> (4 * 4)) & 0Fh -%endif -%if (%2) >= 1000h || %3 >= 4 -_appenddigitstrdef %1, (%2 >> (3 * 4)) & 0Fh -%endif -%if (%2) >= 100h || %3 >= 3 -_appenddigitstrdef %1, (%2 >> (2 * 4)) & 0Fh -%endif -%if (%2) >= 10h || %3 >= 2 -_appenddigitstrdef %1, (%2 >> (1 * 4)) & 0Fh -%endif -%if (%2) >= 1h || %3 >= 1 -_appenddigitstrdef %1, (%2 >> (0 * 4)) & 0Fh -%endif -%endmacro - ; NOTE: sys must be updated if magic offsets change - %macro magicoffset 3.nolist -%ifdef ISFAT12 - %define SYSOFFSET %2 -%elifdef ISFAT16 - %define SYSOFFSET %3 -%else - %define SYSOFFSET 0 - ; Just a placeholder, so the proper error message - ; will be shown when assembling without either - ; of the ISFATx defines. -%endif -%assign NEWOFFSET $ - Entry -%if NEWOFFSET != SYSOFFSET - _autohexitsstrdef NEWOFFSETHEX, NEWOFFSET - %strcat _NEWOFFSETHEX _NEWOFFSETHEX,'h' - %deftok NEWOFFSET _NEWOFFSETHEX - %error Magic offset %1 changed for FATFS, old=SYSOFFSET, new=NEWOFFSET -%endif - %endmacro +%assign ISFAT1216DUAL 1 + %include "magic.mac" segment .text diff --git a/boot/magic.mac b/boot/magic.mac new file mode 100644 index 00000000..a3438559 --- /dev/null +++ b/boot/magic.mac @@ -0,0 +1,65 @@ + +; Public Domain 2024 by E. C. Masloch + +%macro _appenddigitstrdef 2.nolist +%substr %%ii "0123456789ABCDEF" (%2) + 1 +%strcat _%1 _%1,%%ii +%endmacro + + ; %1 = name of single-line macro to set. will be prefixed by underscore + ; %2 = number to write + ; %3 = minimal number of hexits, 0..8. defaults to 1 + ; (setting it to 0 with a number of 0 defines macro to "") +%macro _autohexitsstrdef 2-3.nolist 1 +%if %3 > 8 + %error Minimal number of hexits 9 or more: %3 +%endif +%define _%1 "" +%if (%2) >= 1_0000_0000h + %error Number has to use 9 or more hexits: %2 +%endif +%if (%2) >= 1000_0000h || %3 >= 8 +_appenddigitstrdef %1, (%2 >> (7 * 4)) & 0Fh +%endif +%if (%2) >= 100_0000h || %3 >= 7 +_appenddigitstrdef %1, (%2 >> (6 * 4)) & 0Fh +%endif +%if (%2) >= 10_0000h || %3 >= 6 +_appenddigitstrdef %1, (%2 >> (5 * 4)) & 0Fh +%endif +%if (%2) >= 1_0000h || %3 >= 5 +_appenddigitstrdef %1, (%2 >> (4 * 4)) & 0Fh +%endif +%if (%2) >= 1000h || %3 >= 4 +_appenddigitstrdef %1, (%2 >> (3 * 4)) & 0Fh +%endif +%if (%2) >= 100h || %3 >= 3 +_appenddigitstrdef %1, (%2 >> (2 * 4)) & 0Fh +%endif +%if (%2) >= 10h || %3 >= 2 +_appenddigitstrdef %1, (%2 >> (1 * 4)) & 0Fh +%endif +%if (%2) >= 1h || %3 >= 1 +_appenddigitstrdef %1, (%2 >> (0 * 4)) & 0Fh +%endif +%endmacro + + %macro magicoffset 3.nolist +%ifdef ISFAT12 + %define SYSOFFSET %2 +%elifdef ISFAT16 + %define SYSOFFSET %3 +%else + %define SYSOFFSET 0 + ; Just a placeholder, so the proper error message + ; will be shown when assembling without either + ; of the ISFATx defines. +%endif +%assign NEWOFFSET $ - Entry +%if NEWOFFSET != SYSOFFSET + _autohexitsstrdef NEWOFFSETHEX, NEWOFFSET + %strcat _NEWOFFSETHEX _NEWOFFSETHEX,'h' + %deftok NEWOFFSET _NEWOFFSETHEX + %error Magic offset %1 changed for FATFS, old=SYSOFFSET, new=NEWOFFSET +%endif + %endmacro From b3350314fcf2622939fae3610f58301a08870689 Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Wed, 7 Feb 2024 00:10:28 +0100 Subject: [PATCH 14/20] makefile: list magic.mac for boot --- boot/makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boot/makefile b/boot/makefile index f36e5146..e8c4a7e6 100644 --- a/boot/makefile +++ b/boot/makefile @@ -7,10 +7,10 @@ production: fat12com.bin fat16com.bin fat32chs.bin fat32lba.bin oemfat12.bin oemfat16.bin -fat12com.bin: boot.asm +fat12com.bin: boot.asm magic.mac $(NASM) -dISFAT12 $(NASMBOOTFLAGS) boot.asm -l$*.lst -ofat12com.bin -fat16com.bin: boot.asm +fat16com.bin: boot.asm magic.mac $(NASM) -dISFAT16 $(NASMBOOTFLAGS) boot.asm -l$*.lst -ofat16com.bin fat32chs.bin: boot32.asm From 11bb39422d524dd1f9c1c15f83d9efa3307ff717 Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Wed, 7 Feb 2024 00:17:40 +0100 Subject: [PATCH 15/20] magic: prepare for FAT32 use --- boot/magic.mac | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/boot/magic.mac b/boot/magic.mac index a3438559..8580f484 100644 --- a/boot/magic.mac +++ b/boot/magic.mac @@ -44,22 +44,33 @@ _appenddigitstrdef %1, (%2 >> (0 * 4)) & 0Fh %endif %endmacro - %macro magicoffset 3.nolist -%ifdef ISFAT12 + %macro magicoffset 2-3.nolist +%if ISFAT1216DUAL + %ifdef ISFAT12 %define SYSOFFSET %2 -%elifdef ISFAT16 + %elifdef ISFAT16 %define SYSOFFSET %3 -%else + %else %define SYSOFFSET 0 ; Just a placeholder, so the proper error message ; will be shown when assembling without either ; of the ISFATx defines. + %endif +%else + %define SYSOFFSET %2 + %ifnempty %3 + %error Not in dual mode + %endif %endif %assign NEWOFFSET $ - Entry %if NEWOFFSET != SYSOFFSET _autohexitsstrdef NEWOFFSETHEX, NEWOFFSET %strcat _NEWOFFSETHEX _NEWOFFSETHEX,'h' %deftok NEWOFFSET _NEWOFFSETHEX - %error Magic offset %1 changed for FATFS, old=SYSOFFSET, new=NEWOFFSET + %if ISFAT1216DUAL + %error Magic offset %1 changed for FATFS, old=SYSOFFSET, new=NEWOFFSET + %else + %error Magic offset %1 changed, old=SYSOFFSET, new=NEWOFFSET + %endif %endif %endmacro From 96c7072a102e704c33eded5454af54642f2aef01 Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Wed, 7 Feb 2024 00:18:22 +0100 Subject: [PATCH 16/20] boot32, boot32lb: mark magic offsets with macro --- boot/boot32.asm | 7 +++++++ boot/boot32lb.asm | 11 ++++++++++- boot/makefile | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/boot/boot32.asm b/boot/boot32.asm index cd5327c7..5f726907 100644 --- a/boot/boot32.asm +++ b/boot/boot32.asm @@ -28,6 +28,10 @@ ;%define MULTI_SEC_READ 1 + ; NOTE: sys must be updated if magic offsets change +%assign ISFAT1216DUAL 0 + %include "magic.mac" + segment .text @@ -96,12 +100,14 @@ real_start: cld jmp word 0x1FE0:cont loadseg_off dw 0 + magicoffset "loadseg", 78h loadseg_seg dw LOADSEG cont: mov ds, ax mov ss, ax lea sp, [bp-0x20] sti + magicoffset "set unit", 82h mov [drive], dl ; BIOS passes drive number in DL ; call print @@ -401,6 +407,7 @@ no_incr_es: times 0x01f1-$+$$ db 0 + magicoffset "kernel name", 1F1h filename db "KERNEL SYS",0,0 sign dw 0xAA55 diff --git a/boot/boot32lb.asm b/boot/boot32lb.asm index 708861a6..7f0e48b8 100644 --- a/boot/boot32lb.asm +++ b/boot/boot32lb.asm @@ -53,6 +53,11 @@ ; We support values between 0x60 and 0x200 here, with file size ; of up to 128 KiB (rounded to cluster size). Default is 0x60. + ; NOTE: sys must be updated if magic offsets change +%assign ISFAT1216DUAL 0 + %include "magic.mac" + + segment .text org 0x7c00 ; this is a boot sector @@ -129,7 +134,9 @@ real_start: cld rep movsw ; move boot code to the 0x1FE0:0x0000 jmp word 0x1FE0:cont -loadseg_off dw 0, LOADSEG +loadseg_off dw 0 + magicoffset "loadseg", 78h + dw LOADSEG ; ------------- @@ -137,6 +144,7 @@ cont: mov ds, ax mov ss, ax ; stack and BP-relative moves up, too lea sp, [bp-0x20] sti + magicoffset "set unit", 82h mov [drive], dl ; BIOS passes drive number in DL %ifndef QUIET @@ -413,6 +421,7 @@ msg_BootError db "No " ; currently, only "kernel.sys not found" gives a message, ; but read errors in data or root or fat sectors do not. + magicoffset "kernel name", 1F1h filename db "KERNEL SYS" sign dw 0, 0xAA55 diff --git a/boot/makefile b/boot/makefile index e8c4a7e6..6bd7f689 100644 --- a/boot/makefile +++ b/boot/makefile @@ -13,10 +13,10 @@ fat12com.bin: boot.asm magic.mac fat16com.bin: boot.asm magic.mac $(NASM) -dISFAT16 $(NASMBOOTFLAGS) boot.asm -l$*.lst -ofat16com.bin -fat32chs.bin: boot32.asm +fat32chs.bin: boot32.asm magic.mac $(NASM) $(NASMBOOTFLAGS) boot32.asm -l$*.lst -ofat32chs.bin -fat32lba.bin: boot32lb.asm +fat32lba.bin: boot32lb.asm magic.mac $(NASM) $(NASMBOOTFLAGS) boot32lb.asm -l$*.lst -ofat32lba.bin oemfat12.bin: oemboot.asm From 3dfe3e7febf3a61b1d136199e19a3a3c8737641f Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Wed, 7 Feb 2024 00:39:09 +0100 Subject: [PATCH 17/20] sys: correct a magic offset (problem: odd offsets won't work) --- sys/sys.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/sys.c b/sys/sys.c index 3cffcc69..5edebcc3 100644 --- a/sys/sys.c +++ b/sys/sys.c @@ -1723,8 +1723,8 @@ void put_boot(SYSOptions *opts) ((int *)newboot)[0x11A/sizeof(int)] = opts->kernel.loadaddr; } else { /* magic offset: jmp LOADSEG:xxxxh */ - defaultload = ((int *)newboot)[0x119/sizeof(int)]; - ((int *)newboot)[0x119/sizeof(int)] = opts->kernel.loadaddr; + defaultload = ((int *)newboot)[0x118/sizeof(int)]; + ((int *)newboot)[0x118/sizeof(int)] = opts->kernel.loadaddr; } if (defaultload != 0x0 && defaultload != 0x200) { printf("%s: Internal error: OEM FAT1%c load ofs unexpected content\n", From 81e27129db88ca9d54729df93e4c5acaf03a38fb Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Wed, 7 Feb 2024 00:39:37 +0100 Subject: [PATCH 18/20] oemboot: use magic offsets macro --- boot/magic.mac | 4 ++-- boot/makefile | 4 ++-- boot/oemboot.asm | 15 +++++++++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/boot/magic.mac b/boot/magic.mac index 8580f484..c97aa01c 100644 --- a/boot/magic.mac +++ b/boot/magic.mac @@ -44,7 +44,7 @@ _appenddigitstrdef %1, (%2 >> (0 * 4)) & 0Fh %endif %endmacro - %macro magicoffset 2-3.nolist + %macro magicoffset 2-4.nolist ,0 %if ISFAT1216DUAL %ifdef ISFAT12 %define SYSOFFSET %2 @@ -62,7 +62,7 @@ _appenddigitstrdef %1, (%2 >> (0 * 4)) & 0Fh %error Not in dual mode %endif %endif -%assign NEWOFFSET $ - Entry +%assign NEWOFFSET $ + %4 - Entry %if NEWOFFSET != SYSOFFSET _autohexitsstrdef NEWOFFSETHEX, NEWOFFSET %strcat _NEWOFFSETHEX _NEWOFFSETHEX,'h' diff --git a/boot/makefile b/boot/makefile index 6bd7f689..9be6f788 100644 --- a/boot/makefile +++ b/boot/makefile @@ -19,10 +19,10 @@ fat32chs.bin: boot32.asm magic.mac fat32lba.bin: boot32lb.asm magic.mac $(NASM) $(NASMBOOTFLAGS) boot32lb.asm -l$*.lst -ofat32lba.bin -oemfat12.bin: oemboot.asm +oemfat12.bin: oemboot.asm magic.mac $(NASM) -dISFAT12 $(NASMBOOTFLAGS) oemboot.asm -l$*.lst -ooemfat12.bin -oemfat16.bin: oemboot.asm +oemfat16.bin: oemboot.asm magic.mac $(NASM) -dISFAT16 $(NASMBOOTFLAGS) oemboot.asm -l$*.lst -ooemfat16.bin clobber: clean diff --git a/boot/oemboot.asm b/boot/oemboot.asm index 66eb8059..5b1de2e6 100644 --- a/boot/oemboot.asm +++ b/boot/oemboot.asm @@ -116,6 +116,11 @@ ; |IVT | Interrupt Vector Table ; +--------+ 0000:0000 + ; NOTE: sys must be updated if magic offsets change +%assign ISFAT1216DUAL 1 + %include "magic.mac" + + CPU 8086 ; enable assembler warnings to limit instruction set ;%define ISFAT12 1 ; only 1 of these should be set, @@ -227,15 +232,17 @@ Entry: jmp short real_start ; The filesystem ID is used by lDOS's instsect (by ecm) ; by default to validate that the filesystem matches. %ifdef ISFAT12 - db "FAT12" ; filesystem id + %define FATFS "FAT12" %ifdef ISFAT16 %error Must select one FS %endif %elifdef ISFAT16 - db "FAT16" + %define FATFS "FAT16" %else + %define FATFS "unknown" %error Must select one FS %endif + db FATFS ; filesystem id times 3Eh - ($ - $$) db 32 ;----------------------------------------------------------------------- @@ -282,6 +289,7 @@ real_start: ; in DL, however we work around this in SYS.COM by NOP'ing out the use of DL ; (formerly we checked for [drive]==0xff; update sys.c if code moves) ; + magicoffset "set unit", 4Fh, 4Fh mov [drive], dl ; rely on BIOS drive number in DL @@ -470,6 +478,7 @@ cluster_next: lodsw ; AX = next cluster to read %else jmp LOADSEG:0000 ; yes, pass control to kernel %endif + magicoffset "load jump ofs", 11Ah, 118h, -4 ; failed to boot @@ -655,6 +664,8 @@ read_skip: ret times 0x01f1-$+$$ db 0 + + magicoffset "kernel name", 1F1h, 1F1h %ifdef MSCOMPAT filename db "IO SYS" %else From 3d120856d8da51f35b0299a8956c0c57b1d7953c Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Wed, 7 Feb 2024 00:53:30 +0100 Subject: [PATCH 19/20] 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 5edebcc3..5ad0b48e 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", From 35d77e037a526fd022ce25c496db5d39f1870ca1 Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Wed, 7 Feb 2024 01:03:08 +0100 Subject: [PATCH 20/20] boot: fix boot loader assembly listing files [fixes #97] --- boot/makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/boot/makefile b/boot/makefile index 9be6f788..01ea832a 100644 --- a/boot/makefile +++ b/boot/makefile @@ -8,22 +8,22 @@ production: fat12com.bin fat16com.bin fat32chs.bin fat32lba.bin oemfat12.bin oemfat16.bin fat12com.bin: boot.asm magic.mac - $(NASM) -dISFAT12 $(NASMBOOTFLAGS) boot.asm -l$*.lst -ofat12com.bin + $(NASM) -dISFAT12 $(NASMBOOTFLAGS) boot.asm -lfat12com.lst -ofat12com.bin fat16com.bin: boot.asm magic.mac - $(NASM) -dISFAT16 $(NASMBOOTFLAGS) boot.asm -l$*.lst -ofat16com.bin + $(NASM) -dISFAT16 $(NASMBOOTFLAGS) boot.asm -lfat16com.lst -ofat16com.bin fat32chs.bin: boot32.asm magic.mac - $(NASM) $(NASMBOOTFLAGS) boot32.asm -l$*.lst -ofat32chs.bin + $(NASM) $(NASMBOOTFLAGS) boot32.asm -lfat32chs.lst -ofat32chs.bin fat32lba.bin: boot32lb.asm magic.mac - $(NASM) $(NASMBOOTFLAGS) boot32lb.asm -l$*.lst -ofat32lba.bin + $(NASM) $(NASMBOOTFLAGS) boot32lb.asm -lfat32lba.lst -ofat32lba.bin oemfat12.bin: oemboot.asm magic.mac - $(NASM) -dISFAT12 $(NASMBOOTFLAGS) oemboot.asm -l$*.lst -ooemfat12.bin + $(NASM) -dISFAT12 $(NASMBOOTFLAGS) oemboot.asm -loemfat12.lst -ooemfat12.bin oemfat16.bin: oemboot.asm magic.mac - $(NASM) -dISFAT16 $(NASMBOOTFLAGS) oemboot.asm -l$*.lst -ooemfat16.bin + $(NASM) -dISFAT16 $(NASMBOOTFLAGS) oemboot.asm -loemfat16.lst -ooemfat16.bin clobber: clean -$(RM) *.bin status.me