Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
698c4a2
boot32, boot32lb: avoid big file overlap with FAT sector [fixes #127]
ecm-pushbx Feb 6, 2024
b4f9e7a
boot: rename FATBUF to CLUSTLIST to better reflect use (oemboot pick)
ecm-pushbx Feb 6, 2024
be92d83
boot: move cluster list to 1FE0h:2200h (128 KiB file, up to /L 0x200)
ecm-pushbx Feb 6, 2024
7273291
boot32, boot32lb: fix and update memory layout maps
ecm-pushbx Feb 6, 2024
71896f5
boot: fix and update memory layout map
ecm-pushbx Feb 6, 2024
c94fc07
boot: move READBUF and READADDR_OFF/SEG to allow 8 KiB sector size
ecm-pushbx Feb 6, 2024
1a781ab
sys: check default content of all magic offset patchsites
ecm-pushbx Feb 6, 2024
dc4d155
sys: update magic offset of OEM FAT12 jmp offset
ecm-pushbx Feb 6, 2024
556ef4c
boot: display new magic offset (but in decimal)
ecm-pushbx Feb 6, 2024
4314014
boot: extract magicoffset macro
ecm-pushbx Feb 6, 2024
47981f6
boot: display new magic offset in hexadecimal
ecm-pushbx Feb 6, 2024
e4a4355
sys, boot: mark additional magic offsets
ecm-pushbx Feb 6, 2024
4e845a8
magic.mac: extract from boot.asm
ecm-pushbx Feb 6, 2024
b335031
makefile: list magic.mac for boot
ecm-pushbx Feb 6, 2024
11bb394
magic: prepare for FAT32 use
ecm-pushbx Feb 6, 2024
96c7072
boot32, boot32lb: mark magic offsets with macro
ecm-pushbx Feb 6, 2024
3dfe3e7
sys: correct a magic offset (problem: odd offsets won't work)
ecm-pushbx Feb 6, 2024
81e2712
oemboot: use magic offsets macro
ecm-pushbx Feb 6, 2024
3d12085
sys: fix, allow odd magic offsets to work as expected
ecm-pushbx Feb 6, 2024
35d77e0
boot: fix boot loader assembly listing files [fixes #97]
ecm-pushbx Feb 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 66 additions & 51 deletions boot/boot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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 | PARAMS live here
; |LBA PKT| LBA disk packet
; |-------| 1FE0h:7BC0h = 279C0h (158 KiB)
; | gap | READADDR_* live here
; |-------| 1FE0h:7BA0h = 279A0h (158 KiB)
; | STACK | below relocated loader, above sector buffer (size 5.9 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.
; | 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
Expand All @@ -67,6 +88,10 @@
%error Must select one FS
%endif

; NOTE: sys must be updated if magic offsets change
%assign ISFAT1216DUAL 1
%include "magic.mac"


segment .text

Expand Down Expand Up @@ -99,8 +124,8 @@ Entry: jmp short real_start

%define LOADSEG 0x0060

%define FATBUF 0x2000 ; offset of temporary buffer for FAT
; chain
%define CLUSTLIST 0x2200 ; offset of temporary buffer for FAT
; chain cluster list

; Some extra variables

Expand Down Expand Up @@ -134,9 +159,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
Expand Down Expand Up @@ -178,6 +203,7 @@ real_start:
jmp word 0x1FE0:cont

loadseg_off dw 0
magicoffset "loadseg", 5Ch, 5Ch
loadseg_seg dw LOADSEG

cont:
Expand All @@ -190,6 +216,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
Expand Down Expand Up @@ -294,7 +321,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
Expand Down Expand Up @@ -351,7 +378,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?
Expand Down Expand Up @@ -426,20 +453,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
%error Must update constant offset (LBA_TEST_OFFSET) to test dl,dl here and in sys.c for FATFS
%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
Expand Down Expand Up @@ -543,6 +557,7 @@ do_int13_read:

times 0x01f1-$+$$ db 0

magicoffset "kernel name", 1F1h, 1F1h
filename db "KERNEL SYS",0,0

sign dw 0xAA55
Expand Down
64 changes: 35 additions & 29 deletions boot/boot32.asm
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
; +--------+
; | |
; | |
; |--------| 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

; NOTE: sys must be updated if magic offsets change
%assign ISFAT1216DUAL 0
%include "magic.mac"


segment .text

Expand Down Expand Up @@ -66,7 +69,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

Expand Down Expand Up @@ -97,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
Expand Down Expand Up @@ -402,6 +407,7 @@ no_incr_es:

times 0x01f1-$+$$ db 0

magicoffset "kernel name", 1F1h
filename db "KERNEL SYS",0,0

sign dw 0xAA55
43 changes: 28 additions & 15 deletions boot/boot32lb.asm
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,36 @@


; 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.

; NOTE: sys must be updated if magic offsets change
%assign ISFAT1216DUAL 0
%include "magic.mac"


segment .text

Expand Down Expand Up @@ -85,7 +94,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)
Expand Down Expand Up @@ -125,14 +134,17 @@ 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

; -------------

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
Expand Down Expand Up @@ -409,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
Expand Down
Loading