boot/fat: Use segmentation to allow up to 64Kb fat/kernel size

This commit is contained in:
Nero 2020-09-27 10:40:42 +00:00
parent adf67d9723
commit 2dc6970721

View File

@ -1,7 +1,11 @@
; Bootsector for FAT12/FAT16 filesystems ; Bootsector for FAT12/FAT16 filesystems
; Takes defines: ; Memory layout
; FAT12 FAT has 1.5 bytes per entry ourself: equ 0x0800 ; 1 sector, this code
; FAT16 FAT has WORD per entry cluslist: equ 0x0A00 ; up-growing list of words
stack: equ 0x7C00 ; growing down
bootsect: equ 0x7C00 ; our origin before reloc
; default buffer for reads
cpu 8086 cpu 8086
org 0x0800 org 0x0800
@ -19,7 +23,7 @@ params: times bpb_size db 0
init: xor ax, ax init: xor ax, ax
mov ss, ax mov ss, ax
mov sp, ax mov sp, stack
; save potential partition table entry ; save potential partition table entry
push ds push ds
@ -28,8 +32,8 @@ init: xor ax, ax
mov ds, ax mov ds, ax
mov es, ax mov es, ax
mov si, 0x7C00 mov si, bootsect
mov di, 0x0800 mov di, ourself
mov cx, 0x0100 mov cx, 0x0100
rep movsw rep movsw
jmp 0x0:main jmp 0x0:main
@ -106,9 +110,16 @@ offset_part: ; add partition offset
add dx, [bp+bpb.sectoroffset+2] add dx, [bp+bpb.sectoroffset+2]
ret ret
resetbuf: xor ax, ax resetbuf: ; DS = ES
mov dx, ax push es
mov di, buf pop ds
; ES:DI = 07C0:0000
mov ax, ( bootsect >> 4 )
mov es, ax
xor di, di
; AX,CX = 0
xor ax, ax
xor cx, cx
ret ret
main: mov bp, params main: mov bp, params
@ -116,13 +127,14 @@ main: mov bp, params
; load root directory ; load root directory
call resetbuf call resetbuf
push di
call offset_rootdir call offset_rootdir
call rootdirsects call rootdirsects
mov cx, bx mov cx, bx
call read call read
; search for file ; search for file
mov bx, buf pop bx
mov cx, [bp+bpb.direntries] mov cx, [bp+bpb.direntries]
.loop: push cx .loop: push cx
mov si, filename mov si, filename
@ -133,23 +145,28 @@ main: mov bp, params
pop cx pop cx
loopne .loop loopne .loop
jne err_not_found jne err_not_found
push word [bx-0x20+0x1A] push word [es:bx-0x20+0x1A]
; load fat table ; load fat table
call resetbuf call resetbuf
push di
call offset_fat call offset_fat
mov cx, [bp+bpb.fatsectors] mov cx, [bp+bpb.fatsectors]
call read call read
; fetch cluster numbers (FAT12-specific) ; fetch cluster numbers (FAT12-specific)
mov di, 0x0500 call resetbuf
pop ax mov es, ax
mov di, cluslist
pop si ; buffer offset
pop ax ; clus num
push di ; save list for later
readfat: stosw readfat: stosw
mov bx, ax mov bx, ax
shr bx, 1 shr bx, 1
pushf pushf
add bx, ax add bx, ax
mov ax, [buf+bx] mov ax, [bx]
popf ; CF: 0=even, 1=odd entry popf ; CF: 0=even, 1=odd entry
jc .odd jc .odd
and ax, 0x0FFF and ax, 0x0FFF
@ -162,8 +179,8 @@ readfat: stosw
stosw stosw
; load clusters ; load clusters
mov si, 0x500 pop si
mov di, 0x7C00 call resetbuf
loadclus: lodsw loadclus: lodsw
sub ax, 2 sub ax, 2
jc .jump jc .jump
@ -174,7 +191,8 @@ loadclus: lodsw
call read call read
jmp loadclus jmp loadclus
.jump: pop si .jump: mov dl, [bp+bpb.drivenum]
pop si
pop ds pop ds
jmp 0x7C00 jmp 0x7C00