WIP on loading files from disk
This commit is contained in:
parent
0896c77ae6
commit
a0f2a71066
16
kernel/bpb.asm
Normal file
16
kernel/bpb.asm
Normal 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
|
||||
|
@ -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
48
kernel/drive.asm
Normal 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
|
@ -3,12 +3,12 @@ exec_chain:
|
||||
mov si, 0x81
|
||||
exec:
|
||||
push bx
|
||||
sub sp, 36
|
||||
sub sp, fcb_size
|
||||
mov bx, sp
|
||||
|
||||
call fcb_parse
|
||||
call fcb_print
|
||||
call fcb_open
|
||||
|
||||
add sp, 36
|
||||
add sp, fcb_size
|
||||
pop bx
|
||||
ret
|
||||
|
@ -2,11 +2,11 @@
|
||||
; IN SI ptr to filename
|
||||
; BX ptr to FCB
|
||||
fcb_parse:
|
||||
push si
|
||||
push di
|
||||
push ax
|
||||
mov di, bx
|
||||
inc di
|
||||
xor ax, ax
|
||||
stosb
|
||||
.cleanout:
|
||||
push di
|
||||
mov cx, 0x0A
|
||||
@ -38,31 +38,33 @@ fcb_parse:
|
||||
je .eret
|
||||
ret
|
||||
.eret:
|
||||
dec si
|
||||
pop ax
|
||||
.ret:
|
||||
pop ax
|
||||
pop di
|
||||
pop si
|
||||
ret
|
||||
|
||||
; Print a FCB (for debugging)
|
||||
; IN BX ptr FCB
|
||||
fcb_print:
|
||||
push dx
|
||||
push cx
|
||||
push si
|
||||
mov si, bx
|
||||
inc si
|
||||
mov cx, 11
|
||||
.loop:
|
||||
lodsb
|
||||
mov dl, al
|
||||
call putc
|
||||
loop .loop
|
||||
mov dl, 0x26
|
||||
call putc
|
||||
.ret:
|
||||
pop si
|
||||
pop cx
|
||||
pop dx
|
||||
fcb_open:
|
||||
cmp byte [bx], 0
|
||||
jne .drivedone
|
||||
mov al, default_drive
|
||||
inc al
|
||||
mov [bx], al
|
||||
.drivedone:
|
||||
push bp
|
||||
sub sp, bpb_size
|
||||
mov bp, sp
|
||||
|
||||
mov dl, [bx]
|
||||
dec dl
|
||||
|
||||
call bpb_load
|
||||
mov ax, [bp]
|
||||
mov cx, [bp+2]
|
||||
mov dx, [bp+4]
|
||||
mov bx, [bp+6]
|
||||
|
||||
add sp, bpb_size
|
||||
pop bp
|
||||
ret
|
||||
|
@ -6,15 +6,16 @@ cpu 8086
|
||||
; A single sector for disk i/o
|
||||
%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:
|
||||
%define parttab (chstab - (2*4))
|
||||
%define parttab (diskbuf - (2*4))
|
||||
|
||||
%define stack (parttab)
|
||||
|
||||
%define default_drive BYTE [0x5B]
|
||||
|
||||
%define fcb_size 16
|
||||
%define bpb_size 18
|
||||
|
||||
org self
|
||||
jmp init
|
||||
|
||||
@ -69,3 +70,5 @@ putc:
|
||||
|
||||
%include "exec.asm"
|
||||
%include "fcb.asm"
|
||||
%include "bpb.asm"
|
||||
%include "drive.asm"
|
||||
|
Loading…
Reference in New Issue
Block a user