Implement FCB parsing in kernel

This commit is contained in:
Nero 2019-09-29 12:23:39 +00:00
parent 56f9df5773
commit 1ae3c7a0b9
3 changed files with 102 additions and 6 deletions

14
kernel/exec.asm Normal file
View File

@ -0,0 +1,14 @@
; Exec the cmdline at SI or 0x81
exec_chain:
mov si, 0x81
exec:
push bx
sub sp, 36
mov bx, sp
call fcb_parse
call fcb_print
add sp, 36
pop bx
ret

68
kernel/fcb.asm Normal file
View File

@ -0,0 +1,68 @@
; Parse ASCIIZ string into FCB
; IN SI ptr to filename
; BX ptr to FCB
fcb_parse:
push si
push di
push ax
mov di, bx
inc di
.cleanout:
push di
mov cx, 0x0A
mov al, 0x20
rep stosb
pop di
.base_loop:
call .read
cmp al, 0x2E
je .ext_start
cmp al, 0x20
je .ret
stosb
jmp .base_loop
.ext_start:
mov di, bx
add di, 9
.ext_loop:
call .read
cmp al, 0x20
je .ret
stosb
jmp .ext_loop
.read:
lodsb
test al, al
jz .eret
cmp al, 0x0D
je .eret
ret
.eret:
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
ret

View File

@ -2,8 +2,18 @@ cpu 8086
; Memory layout (starting from top) ; Memory layout (starting from top)
%define self 0xF000 %define self 0xF000
; A single sector for disk i/o
%define diskbuf (self-0x200) %define diskbuf (self-0x200)
%define stack (diskbuf) ; end addr, grows down
; 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 stack (parttab)
org self org self
jmp init jmp init
@ -28,13 +38,18 @@ init:
mov sp, stack mov sp, stack
call print_banner call print_banner
int3
mov si, init_program
call exec
cli cli
.halt: .halt:
hlt hlt
jmp .halt jmp .halt
init_program:
db "HELLO.COM", 0
cpm_syscall: cpm_syscall:
cmp cl, 0x02 cmp cl, 0x02
je putc je putc
@ -52,6 +67,5 @@ putc:
pop ax pop ax
ret ret
%include "string.asm" %include "exec.asm"
%include "fcb.asm"
kernel_end: