Bootloader: parse cmdline field

This commit is contained in:
Nero 2019-09-15 17:26:09 +00:00
parent 4c9086e365
commit 567e09f7e9

View File

@ -3,15 +3,22 @@
%define self 0x00800 ; 1 sector
%define fattab 0x01000 ; variable size
%define rootdir 0x06000 ; variable size
%define psp 0x07B00 ; 0x100 bytes
%define prog 0x07C00 ; 64k - psp
%define psp (prog - 0x100)
%define prog 0x07C00
%define filename (psp + 0x5C + 1)
%define arguments (psp + 0x81)
org self
fdc:
.jmp:
jmp short main
jmp short init
cluster_offset:
dw 0
times (0x0B - ($-$$)) db 0
fdc:
.ss:
dw 0x200 ; sector size
.sc:
@ -49,7 +56,7 @@ fdc:
db "FAT12"
times (62 - ($-$$)) db " "
main:
init:
cli
; Stack grows down from PSP + 64k
@ -66,10 +73,9 @@ main:
mov cx, 0x100
rep movsw
; Jump into relocated code
jmp 0:.relocated
.relocated:
jmp 0:main
main:
mov [fdc.drv], dl ; save drive number in fd
sti
@ -98,26 +104,12 @@ main:
; clusters start after rootdir
mov [cluster_offset], ax
call parse_cmdline
call load_file
mov bp, 0x0032
mov bp, 0x3332
jc error
; get length of arguments
mov cx, 0x007F
mov di, arguments
xor ax, ax
repne scasb
dec di
sub di, arguments
mov cx, di
; setup arguments field
mov [psp+0x080], cl
mov di, 0x081
mov si, arguments
rep movsb
mov BYTE [di], 0x0D
; setup int 19h call at 0000, and push its address to stack
mov WORD [psp], 0x19CD
push sp
@ -142,7 +134,7 @@ main:
load_sectors:
; fail instantly if reading sectors > 16 bit
test dx, dx
mov bp, 0x0030
mov bp, 0x3330
jnz error
.loop:
@ -162,7 +154,7 @@ load_sectors:
mov dl, [cs:fdc.drv] ; driver number
mov ax, 0x0201 ; ah=0x02 al=0x01
int 0x13
mov bp, 0x0031
mov bp, 0x3331
jc error
pop dx
@ -186,6 +178,7 @@ load_file:
je read_clusters
add si, 0x20
loop .loop
stc
ret
; Compares the FAT dirent against [filename]
@ -252,14 +245,47 @@ error:
int 0x16
int 0x19
cluster_offset:
dw 0
parse_cmdline:
mov si, cmdline
mov di, filename
.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 .args_start
stosb
jmp .base_loop
.ext_start:
mov di, (filename + 8)
.ext_loop:
call .read
cmp al, 0x20
je .args_start
stosb
jmp .ext_loop
.args_start:
mov di, (psp + 0x81)
.args_loop:
call .read
stosb
jmp .args_loop
.read:
lodsb
test al, al
jnz .ret
pop ax
.ret:
ret
filename:
db "KERNEL COM"
arguments:
db "", 0
cmdline:
db "KERNEL.COM /?", 0
times (0x1FE - ($-$$)) db 0