vbr: implement file searching in rootdir

This commit is contained in:
Nero 2019-03-29 23:48:18 +00:00
parent cb3c977286
commit 97fe07a210
2 changed files with 128 additions and 118 deletions

View File

@ -1,4 +1,4 @@
org 0 org 0x0500
fdc: ; FDC Descriptor as per ECMA-107 fdc: ; FDC Descriptor as per ECMA-107
jmp _startup jmp _startup
@ -47,23 +47,21 @@ _startup:
xor ax, ax xor ax, ax
mov ds, ax mov ds, ax
mov es, ax mov es, ax
mov ss, ax
xor sp, sp
mov cx, 0x0100 mov cx, 0x0100
mov si, 0x7C00 mov si, 0x7C00
mov di, 0x0500 mov di, 0x0500
rep movsw rep movsw ; relocate
jmp 0x0050:.lowstart jmp 0x0000:main
.lowstart:
mov ax, cs
mov ds, ax
mov ss, ax
xor sp, sp
main:
mov [fdc.drv], dl ; backup drive number mov [fdc.drv], dl ; backup drive number
chs_bios: adjustchs:
mov ah, 0x08 mov ah, 0x08
int 0x13 ; required, QEMU detects 360kB as 1200kB with CHS 80 2 15 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 inc dh
mov [fdc.nos], dh mov [fdc.nos], dh
mov ax, cx mov ax, cx
@ -77,72 +75,54 @@ chs_bios:
mul word [fdc.nos] ; number of tracks = number of cylinders * heads mul word [fdc.nos] ; number of tracks = number of cylinders * heads
mul word [fdc.spt] ; number of sectors = number of tracks * sectors per track mul word [fdc.spt] ; number of sectors = number of tracks * sectors per track
mov [fdc.ts], ax mov [fdc.ts], ax
jmp chs_print
chs_print: loaddir:
call print_inline mov bx, [fdc.ss] ; bytes per sector
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
mov bx, [fdc.ss] ; bytes per sector
mov cl, 5 mov cl, 5
shr bx, cl ; div by 2^5, 32 bytes per directory entity shr bx, cl ; div by 2^5, 32 bytes per directory entity
mov ax, [fdc.rde] ; number of root directory entities mov ax, [fdc.rde] ; number of root directory entities
xor dx, dx xor dx, dx
div bx div bx
mov cx, ax mov cx, ax ; cx = number of rootdir sectors
mov ax, [fdc.sf] ; sectors per fat
mov ax, [fdc.sf] mul byte [fdc.fn] ; number of fats
mul byte [fdc.fn] add ax, [fdc.rsc] ; ax = starting sector of rootdir
add ax, [fdc.rsc] mov bx, buffer
xor bx, bx ; load at beginning of es
.loop: .loop:
call loadblk call loadblk
add bx, buffer
add ax, 1
loop .loop 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 cx
pop bx jz found
ret 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 ; Load a single block into memory
; in ax sector number ; in ax sector number
; es:bx buffer ; bx buffer
; out al error code, ; out al error code,
; carry set if error ; carry set if error
loadblk: loadblk:
@ -165,79 +145,41 @@ loadblk:
pop dx pop dx
pop cx pop cx
pop ax pop ax
inc ax
add bx, 0x0200
ret ret
.error: .error:
xor al, al
xchg al, ah xchg al, ah
call print_inline call print_inline
db "disk error ", 0 db "disk error ", 0
call print_number call print8
call print_inline call print_inline
db 0x0A, 0x0D, 0 db 0x0A, 0x0D, 0
.hlt: jmp 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
; in si
dump: dump:
mov si, bx mov si, bx
mov cx, 0x10 mov cx, 0x10
.nextline: .nextline:
mov ax, si mov ax, si
call print16 call print16
mov al, 0x3A
call printc push si
mov al, 0x20 call print_inline
call printc db 0x3A, 0x20, 0
pop si
push cx push cx
mov cx, 0x0020 mov cx, 0x0020
.words: .bytes:
es lodsb lodsb
call print8 call print8
loop .words loop .bytes
pop cx pop cx
mov al, 0x0A push si
call printc call print_inline
mov al, 0x0D db 0x0A, 0x0D, 0
call printc pop si
loop .nextline loop .nextline
@ -247,7 +189,7 @@ dump:
times (0x1F0 - ($-$$)) db 0 times (0x1F0 - ($-$$)) db 0
str_bootfile: bootfilename:
db "BOOT" db "BOOT"
times (0x1F8 - ($-$$)) db " " times (0x1F8 - ($-$$)) db " "
db "BIN" db "BIN"
@ -255,3 +197,5 @@ str_bootfile:
times (0x1FE - ($-$$)) db 0 times (0x1FE - ($-$$)) db 0
dw 0xAA55 dw 0xAA55
buffer:

66
lib/print.asm Normal file
View 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