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