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
1 changed files with 35 additions and 17 deletions

View File

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