Use SYS extension for kernel

This commit is contained in:
Nero 2019-09-23 22:05:01 +00:00
parent 0b7d141af7
commit df4d3a90e3
3 changed files with 68 additions and 79 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@
*.lst
*.exe
*.log
*.sys

View File

@ -1,7 +1,7 @@
FLOPPY = 360
PROGRAMS = $(patsubst %.asm,%.com,$(wildcard programs/*.asm))
DISTFILES = kernel.com $(PROGRAMS)
DISTFILES = rdos.sys $(PROGRAMS)
ROMS =
QEMU_ARCH = $(shell uname -m)
@ -23,9 +23,9 @@ endif
.PHONY: default clean qemu-rom qemu-floppy
default: kernel.rom
default: rdos.sys
kernel.com: kernel/*.asm lib/*.asm
rdos.sys: kernel/*.asm lib/*.asm
nasm -s -o $@ -l kernel.lst -I lib -I kernel kernel/main.asm
debug.rom: debug/*.asm lib/*.asm

View File

@ -107,19 +107,11 @@ main:
; clusters start after rootdir
mov [cluster_offset], ax
mov ax, filename
call load_file
mov bp, 0x3332
jc error
; setup int 19h call if prog returns
mov WORD [psp], 0x19CD
; clean registers
xor ax, ax
xor cx, cx
xor dx, dx
xor bx, bx
; restore boot drive number
mov dl, [fdc.drv]
@ -132,6 +124,68 @@ main:
; jump into target
jmp 0x07B0:0x0100
; Load a file into memory
; IN AX pointer to 8.3 filename
; ES:BX pointer to target area
; OUT CF flag set if error
load_file:
mov si, rootdir
mov cx, [fdc.rde]
.search:
push cx
push si
mov di, ax
mov cx, 11
repe cmpsb
pop si
pop cx
je .read
add si, 0x20
loop .search
stc
ret
.read:
add si, 0x1A
lodsw
mov bx, prog
jmp read_clusters
; Read the file given by cluster number
; into the target program area
; in ax cluster number
read_clusters:
; read cluster into area for target file
push ax
sub ax, 2
mul BYTE [fdc.sc]
add ax, [cluster_offset]
xor dx, dx
mov cx, [fdc.sc]
xor ch, ch
call load_sectors
pop ax
; calculate index in FAT
mov si, ax
shr si, 1
add si, ax
add si, fattab
; load entry from FAT, truncate to 12 bit
mov dx, [si]
test ax, 1
jz .noshift
mov cl, 4
shr dx, 4
.noshift:
mov ax, dx
and ax, 0x0FFF
cmp ax, 0x0FF8
jc read_clusters
ret
; Read sectors from disk
; Does not return on error
; ax and bx will be incremented, cx decremented
@ -182,72 +236,6 @@ load_sectors:
loop .loop
ret
; Load the file in [filename]
; or exit with carry set
load_file:
mov si, rootdir
mov cx, [fdc.rde]
.loop:
call file_match
je read_clusters
add si, 0x20
loop .loop
stc
ret
; Compares the FAT dirent against [filename]
; in ds:si filename
; out ZF zero flag set if equal
file_match:
push cx
push si
mov di, filename
mov cx, 11
repe cmpsb
pop si
pop cx
ret
; Read the file given by cluster number
; into the target program area
; in ax cluster number
read_clusters:
add si, 0x1A
lodsw
mov bx, prog
.loop:
; read cluster into area for target file
push ax
sub ax, 2
mul BYTE [fdc.sc]
add ax, [cluster_offset]
xor dx, dx
mov cx, [fdc.sc]
xor ch, ch
call load_sectors
pop ax
; calculate index in FAT
mov si, ax
shr si, 1
add si, ax
add si, fattab
; load entry from FAT, truncate to 12 bit
mov dx, [si]
test ax, 1
jz .noshift
mov cl, 4
shr dx, 4
.noshift:
mov ax, dx
and ax, 0x0FFF
cmp ax, 0x0FF8
jc .loop
ret
error:
mov ax, bp
mov ah, 0x0e
@ -260,7 +248,7 @@ error:
int 0x19
filename:
db "KERNEL COM"
db "RDOS SYS"
times (0x1FE - ($-$$)) db 0