WIP on loading files from disk

This commit is contained in:
Nero 2019-09-29 21:25:29 +00:00
parent 0896c77ae6
commit a0f2a71066
6 changed files with 100 additions and 51 deletions

16
kernel/bpb.asm Normal file
View File

@ -0,0 +1,16 @@
; IN DL drive number
; BP ptr to bpb_size'd buffer
bpb_load:
mov [bp+(bpb_size-1)], dl
xor dx, dx
xor ax, ax
call drive_read
mov si, (diskbuf+0x0B)
mov di, bp
mov cx, (bpb_size-1)
rep movsb
ret

View File

@ -1,20 +0,0 @@
config_tokens:
.buffers:
db 8, "BUFFERS="
.drives:
db 7, "DRIVES="
.files:
db 6, "FILES="
.none:
db 0
config_parse_int:
ret
; IN BX offset to config data
config_first_run:
mov si, bx
mov di, config_tokens
call string_search_token
int3
ret

48
kernel/drive.asm Normal file
View File

@ -0,0 +1,48 @@
; Load a sector from drive.
; IN DX:AX sector number
; BP ptr to BPB
drive_read:
push ax
push cx
push dx
push bx
push si
mov cx, dx
or cx, ax
jz .fast
div word [bp+13] ; ax:temp = (lba / spt)
inc dx ; dx:sector = (lba % spt) + 1
mov cl, dl ; sector number
div word [bp+15] ; ax:cylinder = (tmp / heads)
; dx:head = (tmp % heads)
mov ch, al ; cylinder number
mov dh, dl ; head number
mov si, 5 ; retry count
.try:
mov dl, [bp+(bpb_size-1)] ; drive number
mov bx, diskbuf
mov ax, 0x0201
int 0x13
.giveup:
pop si
pop bx
pop dx
pop cx
pop ax
ret
.fast: ; fast lane for boot sector
inc cl
jmp .try
.fail:
; reset disk
mov ah, 0x00
int 0x13
; loop with si
dec si
test si, si
jnz .try
stc
jmp .giveup

View File

@ -3,12 +3,12 @@ exec_chain:
mov si, 0x81 mov si, 0x81
exec: exec:
push bx push bx
sub sp, 36 sub sp, fcb_size
mov bx, sp mov bx, sp
call fcb_parse call fcb_parse
call fcb_print call fcb_open
add sp, 36 add sp, fcb_size
pop bx pop bx
ret ret

View File

@ -2,11 +2,11 @@
; IN SI ptr to filename ; IN SI ptr to filename
; BX ptr to FCB ; BX ptr to FCB
fcb_parse: fcb_parse:
push si
push di push di
push ax push ax
mov di, bx mov di, bx
inc di xor ax, ax
stosb
.cleanout: .cleanout:
push di push di
mov cx, 0x0A mov cx, 0x0A
@ -38,31 +38,33 @@ fcb_parse:
je .eret je .eret
ret ret
.eret: .eret:
dec si
pop ax pop ax
.ret: .ret:
pop ax pop ax
pop di pop di
pop si
ret ret
; Print a FCB (for debugging) fcb_open:
; IN BX ptr FCB cmp byte [bx], 0
fcb_print: jne .drivedone
push dx mov al, default_drive
push cx inc al
push si mov [bx], al
mov si, bx .drivedone:
inc si push bp
mov cx, 11 sub sp, bpb_size
.loop: mov bp, sp
lodsb
mov dl, al mov dl, [bx]
call putc dec dl
loop .loop
mov dl, 0x26 call bpb_load
call putc mov ax, [bp]
.ret: mov cx, [bp+2]
pop si mov dx, [bp+4]
pop cx mov bx, [bp+6]
pop dx
add sp, bpb_size
pop bp
ret ret

View File

@ -6,15 +6,16 @@ cpu 8086
; A single sector for disk i/o ; A single sector for disk i/o
%define diskbuf (self-0x200) %define diskbuf (self-0x200)
; BYTE sectors/track and BYTE number of sides
; 4 times for A: B: C: and D:
%define chstab (diskbuf - (4*2))
; DWORD partition offset for C: and D: ; DWORD partition offset for C: and D:
%define parttab (chstab - (2*4)) %define parttab (diskbuf - (2*4))
%define stack (parttab) %define stack (parttab)
%define default_drive BYTE [0x5B]
%define fcb_size 16
%define bpb_size 18
org self org self
jmp init jmp init
@ -69,3 +70,5 @@ putc:
%include "exec.asm" %include "exec.asm"
%include "fcb.asm" %include "fcb.asm"
%include "bpb.asm"
%include "drive.asm"