2020-03-16 18:24:39 +01:00
|
|
|
; Bootsector for FAT32 filesystems
|
|
|
|
org 0x0800
|
2020-03-30 22:41:32 +02:00
|
|
|
cpu 8086
|
2020-03-25 22:19:40 +01:00
|
|
|
jmp short init
|
|
|
|
nop
|
2020-03-16 18:24:39 +01:00
|
|
|
|
2020-03-31 22:03:05 +02:00
|
|
|
%include "inc/bpb.asm"
|
2020-03-30 17:07:09 +02:00
|
|
|
|
2020-03-31 22:03:05 +02:00
|
|
|
bpb: equ 0x080B
|
2020-03-16 18:24:39 +01:00
|
|
|
|
|
|
|
; Area for BPB
|
2020-03-31 22:03:05 +02:00
|
|
|
times ( 0x5A - ($-$$) ) db 0
|
2020-03-16 18:24:39 +01:00
|
|
|
|
|
|
|
init: xor ax, ax
|
|
|
|
mov ss, ax
|
|
|
|
mov sp, 0x7C00
|
|
|
|
|
2020-03-30 22:41:32 +02:00
|
|
|
; save potential partition table entry
|
|
|
|
push ds
|
|
|
|
push si
|
|
|
|
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
|
|
|
|
mov si, 0x7C00
|
2020-03-16 18:24:39 +01:00
|
|
|
mov di, 0x0800
|
|
|
|
mov cx, 0x0100
|
|
|
|
rep movsw
|
|
|
|
jmp 0x0:main
|
|
|
|
|
|
|
|
msg: pop si
|
|
|
|
mloop: lodsb
|
|
|
|
test al, al
|
|
|
|
jz mend
|
|
|
|
mov ah, 0x0e
|
|
|
|
mov bx, 7
|
|
|
|
int 0x10
|
|
|
|
jmp mloop
|
|
|
|
mend: push si
|
|
|
|
ret
|
|
|
|
|
2020-03-30 20:50:17 +02:00
|
|
|
dskerr: call msg
|
|
|
|
db "DISK", 0
|
2020-03-16 18:24:39 +01:00
|
|
|
err: call msg
|
2020-03-30 17:07:09 +02:00
|
|
|
db "ERR", 0x0A, 0x0D, 0
|
2020-03-16 18:24:39 +01:00
|
|
|
hlt: hlt
|
|
|
|
jmp hlt
|
|
|
|
|
2020-03-30 17:07:09 +02:00
|
|
|
; offsets relative to FS
|
2020-03-30 20:50:17 +02:00
|
|
|
readd: ; add offset of cluster data area to DX:AX
|
2020-03-30 17:07:09 +02:00
|
|
|
push cx
|
2020-03-31 22:03:05 +02:00
|
|
|
mov di, [bp+bpb_rde]
|
2020-03-30 17:07:09 +02:00
|
|
|
mov cl, 4
|
|
|
|
shr di, cl ; 32 bytes per entry
|
|
|
|
add ax, di
|
|
|
|
adc dx, 0
|
|
|
|
pop cx
|
2020-03-30 20:50:17 +02:00
|
|
|
readr: ; add offset to rootdir to DX:AX (FAT12/FAT16 only)
|
2020-03-16 18:24:39 +01:00
|
|
|
push cx
|
2020-03-30 17:07:09 +02:00
|
|
|
xor ch, ch
|
2020-03-31 22:03:05 +02:00
|
|
|
mov cl, byte [bp+bpb_fn]
|
|
|
|
fatlp: add ax, [bp+bpb7_lsf]
|
|
|
|
adc dx, [bp+bpb7_lsf+2]
|
2020-03-30 17:07:09 +02:00
|
|
|
loop fatlp
|
|
|
|
pop cx
|
2020-03-30 20:50:17 +02:00
|
|
|
readf: ; add offset to FAT table to DX:AX
|
2020-03-31 22:03:05 +02:00
|
|
|
add ax, word [bp+bpb_rsc]
|
2020-03-30 17:07:09 +02:00
|
|
|
adc dx, 0
|
|
|
|
readp: ; read sector DX:AX from partition
|
2020-03-31 22:03:05 +02:00
|
|
|
add ax, word [bp+bpb_po]
|
|
|
|
adc dx, word [bp+bpb_po+2]
|
2020-03-30 17:07:09 +02:00
|
|
|
jc err
|
2020-03-30 20:50:17 +02:00
|
|
|
read_: ; read sector DX:AX from disk
|
2020-03-30 17:07:09 +02:00
|
|
|
; qword sector number DX:AX
|
|
|
|
push cs
|
|
|
|
push cs
|
|
|
|
push dx
|
2020-03-16 18:24:39 +01:00
|
|
|
push ax
|
2020-03-30 17:07:09 +02:00
|
|
|
|
|
|
|
; dword target buffer: BX:0
|
|
|
|
push bx
|
|
|
|
push cs
|
|
|
|
|
|
|
|
; word sector number
|
|
|
|
push cx
|
|
|
|
|
|
|
|
; size & passing
|
2020-03-31 22:03:05 +02:00
|
|
|
mov di, 0x10
|
|
|
|
push di
|
2020-03-30 17:07:09 +02:00
|
|
|
|
|
|
|
mov si, sp
|
2020-03-16 18:24:39 +01:00
|
|
|
mov ah, 0x42
|
2020-03-31 22:03:05 +02:00
|
|
|
mov dl, [bp+bpb7_dn]
|
2020-03-30 17:07:09 +02:00
|
|
|
stc
|
2020-03-16 18:24:39 +01:00
|
|
|
int 0x13
|
2020-03-30 20:50:17 +02:00
|
|
|
jc dskerr
|
2020-03-16 18:24:39 +01:00
|
|
|
|
2020-03-31 22:03:05 +02:00
|
|
|
add sp, di
|
2020-03-16 18:24:39 +01:00
|
|
|
|
2020-03-30 17:07:09 +02:00
|
|
|
ret
|
2020-03-16 18:24:39 +01:00
|
|
|
|
2020-03-30 20:50:17 +02:00
|
|
|
next: ; Advances DX:AX to next FAT entry
|
|
|
|
push ax
|
|
|
|
push bx
|
2020-03-16 18:24:39 +01:00
|
|
|
|
2020-03-25 22:19:40 +01:00
|
|
|
; shift 2 left for dword-sized FAT entries
|
|
|
|
; shift 9 right for sector size
|
2020-03-16 18:24:39 +01:00
|
|
|
mov cl, 7
|
|
|
|
shftl: clc
|
|
|
|
rcr dx, 1
|
|
|
|
rcr ax, 1
|
|
|
|
loop shftl
|
|
|
|
|
2020-03-30 17:07:09 +02:00
|
|
|
mov bx, 0xA0
|
2020-03-16 18:24:39 +01:00
|
|
|
mov cx, 1
|
2020-03-30 20:50:17 +02:00
|
|
|
call readf
|
|
|
|
|
|
|
|
pop bx
|
2020-03-16 18:24:39 +01:00
|
|
|
|
2020-03-30 20:50:17 +02:00
|
|
|
; get lower part of cluster number
|
|
|
|
pop si
|
2020-03-25 22:19:40 +01:00
|
|
|
; multiply with 4
|
2020-03-16 18:24:39 +01:00
|
|
|
sal si, 1
|
|
|
|
sal si, 1
|
2020-03-25 22:19:40 +01:00
|
|
|
; make sure its within sector range
|
2020-03-16 18:24:39 +01:00
|
|
|
and si, 0x1FF
|
|
|
|
add si, buf
|
2020-03-30 20:50:17 +02:00
|
|
|
; load dword from FAT
|
|
|
|
lodsw
|
|
|
|
mov dx, [si]
|
2020-03-16 18:24:39 +01:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
2020-03-25 22:19:40 +01:00
|
|
|
; reads current cluster into [dest]
|
|
|
|
readc: ; load cluster number
|
2020-03-30 20:50:17 +02:00
|
|
|
push ax
|
|
|
|
push dx
|
2020-03-25 22:19:40 +01:00
|
|
|
|
|
|
|
; subtract the two dummy entries from FAT start
|
|
|
|
sub ax, 2
|
|
|
|
sbb dx, 0
|
|
|
|
|
|
|
|
; convert cluster number to sector number
|
|
|
|
; this is some cheapo multiplication with 2^n
|
2020-03-31 22:03:05 +02:00
|
|
|
mov cl, [bp+bpb_sc]
|
2020-03-25 22:19:40 +01:00
|
|
|
l02: shr cl, 1
|
|
|
|
jz l02e
|
|
|
|
clc
|
|
|
|
rcl ax, 1
|
2020-03-30 20:50:17 +02:00
|
|
|
rcl dx, 1
|
2020-03-25 22:19:40 +01:00
|
|
|
jmp l02
|
|
|
|
l02e:
|
|
|
|
; dx:ax is now sector num in data area
|
2020-03-31 22:03:05 +02:00
|
|
|
mov cx, [bp+bpb_sc]
|
2020-03-25 22:19:40 +01:00
|
|
|
xor ch, ch
|
|
|
|
|
2020-03-30 20:50:17 +02:00
|
|
|
call readd
|
2020-03-25 22:19:40 +01:00
|
|
|
|
2020-03-31 22:03:05 +02:00
|
|
|
xchg di, cx
|
2020-03-28 18:36:52 +01:00
|
|
|
mov cl, 5
|
2020-03-31 22:03:05 +02:00
|
|
|
sal di, cl
|
|
|
|
add bx, di
|
2020-03-30 20:50:17 +02:00
|
|
|
|
|
|
|
pop dx
|
|
|
|
pop ax
|
2020-03-28 18:36:52 +01:00
|
|
|
|
2020-03-25 22:19:40 +01:00
|
|
|
ret
|
|
|
|
|
2020-03-30 20:50:17 +02:00
|
|
|
; load cluster chain DX:AX to [dest]:0
|
|
|
|
load: mov bx, 0x07C0
|
|
|
|
lloop: call readc
|
2020-03-28 18:36:52 +01:00
|
|
|
call next
|
2020-03-30 20:50:17 +02:00
|
|
|
cmp word dx, 0x0FFF
|
|
|
|
jne lloop
|
2020-03-28 18:36:52 +01:00
|
|
|
ret
|
2020-03-25 22:19:40 +01:00
|
|
|
|
2020-03-30 20:50:17 +02:00
|
|
|
; Search for first entry with matching fsattr
|
|
|
|
search: mov si, (0x7C00-0x20)
|
|
|
|
loop: add si, 0x20
|
|
|
|
; check if entry is valid
|
|
|
|
mov al, [si]
|
|
|
|
; unallocated direntry
|
|
|
|
test al, al
|
|
|
|
jz end
|
|
|
|
; deleted files
|
|
|
|
cmp al, 0xE2
|
|
|
|
je loop
|
|
|
|
; check attr
|
|
|
|
mov al, [si+11]
|
|
|
|
and al, 0x5C
|
|
|
|
cmp al, ah
|
|
|
|
jne loop
|
|
|
|
ret
|
2020-03-16 18:24:39 +01:00
|
|
|
|
2020-03-30 21:43:07 +02:00
|
|
|
loadr: mov ax, 2
|
2020-03-30 20:50:17 +02:00
|
|
|
xor dx, dx
|
2020-03-30 21:43:07 +02:00
|
|
|
jmp load
|
2020-03-30 20:50:17 +02:00
|
|
|
|
2020-03-30 21:43:07 +02:00
|
|
|
loadf: call search
|
2020-03-30 20:50:17 +02:00
|
|
|
jne end
|
|
|
|
mov ax, [si+0x1A]
|
|
|
|
mov dx, [si+0x14]
|
2020-03-30 21:43:07 +02:00
|
|
|
jmp load
|
2020-03-30 20:50:17 +02:00
|
|
|
|
2020-03-31 22:03:05 +02:00
|
|
|
main: mov bp, bpb
|
|
|
|
mov [bp+bpb7_dn], dl
|
2020-03-30 22:41:32 +02:00
|
|
|
; load root directory
|
2020-03-30 21:43:07 +02:00
|
|
|
call loadr
|
|
|
|
; search for first system directory
|
|
|
|
mov ah, 0x14
|
|
|
|
call loadf
|
|
|
|
; search for first system file
|
2020-03-30 20:50:17 +02:00
|
|
|
mov ah, 0x04
|
2020-03-30 21:43:07 +02:00
|
|
|
call loadf
|
|
|
|
; jump
|
2020-03-30 22:41:32 +02:00
|
|
|
xor ax, ax
|
|
|
|
xor cx, cx
|
|
|
|
xor dx, dx
|
|
|
|
xor bx, bx
|
|
|
|
xor di, di
|
|
|
|
|
|
|
|
; restore drive number
|
2020-03-31 22:03:05 +02:00
|
|
|
mov dl, [bp+bpb7_dn]
|
2020-03-30 22:41:32 +02:00
|
|
|
|
|
|
|
; restore potential partition table
|
|
|
|
pop si
|
|
|
|
pop ds
|
|
|
|
|
2020-03-30 20:50:17 +02:00
|
|
|
jmp 0:0x7C00
|
2020-03-16 18:24:39 +01:00
|
|
|
|
2020-03-30 20:50:17 +02:00
|
|
|
end: call msg
|
|
|
|
db "DIR", 0
|
|
|
|
jmp err
|
2020-03-28 18:36:52 +01:00
|
|
|
|
2020-03-16 18:24:39 +01:00
|
|
|
; Padding and signature
|
|
|
|
times (0x1FE - ($-$$)) db 0
|
|
|
|
dw 0xAA55
|
|
|
|
buf:
|