vbr: implement file searching in rootdir
This commit is contained in:
parent
cb3c977286
commit
97fe07a210
174
boot/vbr.asm
174
boot/vbr.asm
@ -1,4 +1,4 @@
|
||||
org 0
|
||||
org 0x0500
|
||||
|
||||
fdc: ; FDC Descriptor as per ECMA-107
|
||||
jmp _startup
|
||||
@ -47,23 +47,21 @@ _startup:
|
||||
xor ax, ax
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov ss, ax
|
||||
xor sp, sp
|
||||
mov cx, 0x0100
|
||||
mov si, 0x7C00
|
||||
mov di, 0x0500
|
||||
rep movsw
|
||||
jmp 0x0050:.lowstart
|
||||
.lowstart:
|
||||
mov ax, cs
|
||||
mov ds, ax
|
||||
mov ss, ax
|
||||
xor sp, sp
|
||||
rep movsw ; relocate
|
||||
jmp 0x0000:main
|
||||
|
||||
main:
|
||||
mov [fdc.drv], dl ; backup drive number
|
||||
|
||||
chs_bios:
|
||||
adjustchs:
|
||||
mov ah, 0x08
|
||||
int 0x13 ; required, QEMU detects 360kB as 1200kB with CHS 80 2 15
|
||||
jc chs_print ; skip if function does not exist
|
||||
jc loaddir ; skip if function does not exist
|
||||
inc dh
|
||||
mov [fdc.nos], dh
|
||||
mov ax, cx
|
||||
@ -77,72 +75,54 @@ chs_bios:
|
||||
mul word [fdc.nos] ; number of tracks = number of cylinders * heads
|
||||
mul word [fdc.spt] ; number of sectors = number of tracks * sectors per track
|
||||
mov [fdc.ts], ax
|
||||
jmp chs_print
|
||||
|
||||
chs_print:
|
||||
call print_inline
|
||||
db "CHS ", 0
|
||||
|
||||
mov ax, [fdc.ts]
|
||||
div word [fdc.nos]
|
||||
div word [fdc.spt]
|
||||
call print_number
|
||||
|
||||
call print_inline
|
||||
db ",", 0
|
||||
|
||||
mov ax, [fdc.nos]
|
||||
call print_number
|
||||
|
||||
call print_inline
|
||||
db ",", 0
|
||||
|
||||
mov ax, [fdc.spt]
|
||||
call print_number
|
||||
|
||||
call print_inline
|
||||
db 0x0A, 0x0D, 0
|
||||
|
||||
mov ax, 0x0070
|
||||
mov es, ax
|
||||
xor bx, bx
|
||||
call loadrootdir
|
||||
|
||||
call dump
|
||||
|
||||
.end:
|
||||
hlt
|
||||
jmp .end
|
||||
|
||||
; Load root directory into memory
|
||||
; in es data segment
|
||||
loadrootdir:
|
||||
push bx
|
||||
push cx
|
||||
loaddir:
|
||||
mov bx, [fdc.ss] ; bytes per sector
|
||||
mov cl, 5
|
||||
shr bx, cl ; div by 2^5, 32 bytes per directory entity
|
||||
mov ax, [fdc.rde] ; number of root directory entities
|
||||
xor dx, dx
|
||||
div bx
|
||||
mov cx, ax
|
||||
|
||||
mov ax, [fdc.sf]
|
||||
mul byte [fdc.fn]
|
||||
add ax, [fdc.rsc]
|
||||
|
||||
xor bx, bx ; load at beginning of es
|
||||
mov cx, ax ; cx = number of rootdir sectors
|
||||
mov ax, [fdc.sf] ; sectors per fat
|
||||
mul byte [fdc.fn] ; number of fats
|
||||
add ax, [fdc.rsc] ; ax = starting sector of rootdir
|
||||
mov bx, buffer
|
||||
.loop:
|
||||
call loadblk
|
||||
add bx, buffer
|
||||
add ax, 1
|
||||
loop .loop
|
||||
|
||||
scandir:
|
||||
mov cx, [fdc.rde]
|
||||
mov bx, buffer
|
||||
.loop:
|
||||
push cx
|
||||
mov cx, 0x000B
|
||||
mov si, bx
|
||||
mov di, bootfilename
|
||||
repe cmpsb
|
||||
pop cx
|
||||
pop bx
|
||||
ret
|
||||
jz found
|
||||
add bx, 0x0020 ; 32 bytes per directory entry
|
||||
loop .loop
|
||||
call print_inline
|
||||
db "File not found", 0x0A, 0x0D, 0
|
||||
jmp hlt
|
||||
found:
|
||||
add bx, 26
|
||||
mov ax, [bx]
|
||||
call print16
|
||||
jmp hlt
|
||||
|
||||
hlt:
|
||||
hlt
|
||||
jmp hlt
|
||||
|
||||
; Load a single block into memory
|
||||
; in ax sector number
|
||||
; es:bx buffer
|
||||
; bx buffer
|
||||
; out al error code,
|
||||
; carry set if error
|
||||
loadblk:
|
||||
@ -165,79 +145,41 @@ loadblk:
|
||||
pop dx
|
||||
pop cx
|
||||
pop ax
|
||||
inc ax
|
||||
add bx, 0x0200
|
||||
ret
|
||||
.error:
|
||||
xor al, al
|
||||
xchg al, ah
|
||||
call print_inline
|
||||
db "disk error ", 0
|
||||
call print_number
|
||||
call print8
|
||||
call print_inline
|
||||
db 0x0A, 0x0D, 0
|
||||
.hlt:
|
||||
hlt
|
||||
jmp .hlt
|
||||
|
||||
print_number:
|
||||
mov cx, 0x000A
|
||||
xor dx, dx
|
||||
div cx ; ax = dx:ax / 10, dx = dx:ax % 10
|
||||
and ax, ax
|
||||
jz .print
|
||||
push dx
|
||||
call print_number
|
||||
pop dx
|
||||
.print:
|
||||
mov al, dl
|
||||
add al, 0x30
|
||||
mov ah, 0x0e
|
||||
int 0x10
|
||||
ret
|
||||
|
||||
print_inline:
|
||||
pop si
|
||||
push ax
|
||||
push bx
|
||||
.loop:
|
||||
lodsb
|
||||
cmp al, 0x00
|
||||
je .end
|
||||
mov bx, 0x0000
|
||||
mov ah, 0x0e
|
||||
int 0x10
|
||||
cmp al, 0x0D
|
||||
jmp .loop
|
||||
.end:
|
||||
pop bx
|
||||
pop ax
|
||||
push si
|
||||
ret
|
||||
jmp hlt
|
||||
|
||||
; in si
|
||||
dump:
|
||||
mov si, bx
|
||||
mov cx, 0x10
|
||||
.nextline:
|
||||
mov ax, si
|
||||
call print16
|
||||
mov al, 0x3A
|
||||
call printc
|
||||
mov al, 0x20
|
||||
call printc
|
||||
|
||||
push si
|
||||
call print_inline
|
||||
db 0x3A, 0x20, 0
|
||||
pop si
|
||||
|
||||
push cx
|
||||
mov cx, 0x0020
|
||||
.words:
|
||||
es lodsb
|
||||
.bytes:
|
||||
lodsb
|
||||
call print8
|
||||
loop .words
|
||||
loop .bytes
|
||||
pop cx
|
||||
|
||||
mov al, 0x0A
|
||||
call printc
|
||||
mov al, 0x0D
|
||||
call printc
|
||||
push si
|
||||
call print_inline
|
||||
db 0x0A, 0x0D, 0
|
||||
pop si
|
||||
|
||||
loop .nextline
|
||||
|
||||
@ -247,7 +189,7 @@ dump:
|
||||
|
||||
times (0x1F0 - ($-$$)) db 0
|
||||
|
||||
str_bootfile:
|
||||
bootfilename:
|
||||
db "BOOT"
|
||||
times (0x1F8 - ($-$$)) db " "
|
||||
db "BIN"
|
||||
@ -255,3 +197,5 @@ str_bootfile:
|
||||
times (0x1FE - ($-$$)) db 0
|
||||
|
||||
dw 0xAA55
|
||||
|
||||
buffer:
|
||||
|
66
lib/print.asm
Normal file
66
lib/print.asm
Normal file
@ -0,0 +1,66 @@
|
||||
; important functions in this file: kprintf
|
||||
|
||||
; write a character to kernel output
|
||||
; in: al
|
||||
printc:
|
||||
push ax
|
||||
push bx
|
||||
mov bx, 0x0000
|
||||
mov ah, 0x0e
|
||||
int 0x10
|
||||
pop bx
|
||||
pop ax
|
||||
ret
|
||||
|
||||
; prints a nibble in hex
|
||||
; in: al
|
||||
print4:
|
||||
and al, 0x0F
|
||||
add al, 0x30
|
||||
cmp al, 0x3a
|
||||
jl printc
|
||||
add al, 0x07
|
||||
jmp printc
|
||||
|
||||
; print a byte
|
||||
; in: al
|
||||
print8:
|
||||
push ax ; avoid destroying ah
|
||||
aam 16 ; high nibble moved into ah
|
||||
xchg ah,al ; high nibble first
|
||||
call print4
|
||||
xchg ah,al
|
||||
call print4
|
||||
pop ax
|
||||
ret
|
||||
|
||||
; print a word
|
||||
; in: ax
|
||||
print16:
|
||||
xchg ah,al
|
||||
call print8
|
||||
xchg ah,al
|
||||
call print8
|
||||
ret
|
||||
|
||||
; print a inline following its call opcode
|
||||
; the string ends with a nullbyte
|
||||
; trashes si
|
||||
print_inline:
|
||||
pop si
|
||||
push ax
|
||||
push bx
|
||||
mov bx, 0x0000
|
||||
.loop:
|
||||
lodsb
|
||||
cmp al, 0x00
|
||||
je .end
|
||||
mov ah, 0x0e
|
||||
int 0x10
|
||||
cmp al, 0x0D
|
||||
jmp .loop
|
||||
.end:
|
||||
pop bx
|
||||
pop ax
|
||||
push si
|
||||
ret
|
Loading…
Reference in New Issue
Block a user