Implement boot based on reserved sectors

This commit is contained in:
Nero 2019-10-28 10:38:18 +00:00
parent 74fce7191f
commit 47630b2c03
3 changed files with 23 additions and 135 deletions

View File

@ -2,8 +2,11 @@ FLOPPY = 360
RAM = 0x10000
BDOSIMG = bdos.bin
BIOSIMG = bios8086.bin
PROGRAMS = $(patsubst %.asm,%.com,$(wildcard com/*.asm))
DISTFILES = bdos.bin $(PROGRAMS)
DISTFILES = $(PROGRAMS)
ROMS =
QEMU_ARCH = $(shell uname -m)
@ -52,8 +55,10 @@ com/%.com: com/%.asm
bios%.bin: bios/%.asm
$(NASM) $(NASM_ARGS) -o $@ $<
fdimage.img: boot/fat.bs $(DISTFILES)
mformat -C -i $@ -f $(FLOPPY) -B boot/fat.bs ::
fdimage.img: boot/fat.bs $(BDOSIMG) $(BIOSIMG) $(DISTFILES)
mformat -R 9 -C -i $@ -f $(FLOPPY) -B boot/fat.bs ::
dd if=$(BDOSIMG) bs=512 seek=1 count=4 conv=notrunc of=$@
dd if=$(BIOSIMG) bs=512 seek=5 count=4 conv=notrunc of=$@
mcopy -i $@ $(DISTFILES) ::
hdimage.img: boot/mbr.bs fdimage.img

View File

@ -23,13 +23,12 @@ JMP NEAR WRITE
JMP NEAR LISTST
BOOT:
MOV AL, 0x19
MOV AL, 0x86
CALL MSG
DB "BIOS 8086", 0
RET
DB "BIOS", 0
WBOOT:
STC
JMP (RAM - 0x1000)
RET
; CHAR I/O

View File

@ -1,18 +1,11 @@
; Memory layout:
%define segment 0x00100
%define self (0x7C00-(segment<<4)) ; 1 sector
%define fattab (self+0x200) ; variable size
%define rootdir 0x00100 ; variable size
%define prog 0x0F000 ; 4K at the end for OS
%define prog (RAM-0x1000) ; 4K at the end for OS
cpu 8086
org self
jmp short init
cluster_offset:
dw 0
times (0x0B - ($-$$)) db 0
fdc:
@ -70,122 +63,11 @@ main:
mov es, ax
mov [fdc.drv], dl ; save drive number in fd
sti
; load fat table into memory
mov ax, [fdc.rsc]
mov cx, [fdc.sf]
xor dx, dx
mov bx, fattab
call load_sectors
; calculate length of rootdir
mov ax, [fdc.rde]
mov cl, 4
shr ax, cl ; 32 bytes per entry
mov cx, ax
; load root dir
xor dx, dx
mov ax, [fdc.sf]
mul byte [fdc.fn]
add ax, [fdc.rsc]
mov bx, rootdir
call load_sectors
; remember where we left off
; clusters start after rootdir
mov [cluster_offset], ax
; Load kernel
mov ax, 1
mov cx, 8
mov dx, 0
mov bx, prog
mov ax, kernel_name
call load_file
mov bp, 0x3332
jc error
mov dl, [fdc.drv]
; jump into kernel
jmp segment:prog
; Load a file into memory
; IN AX pointer to 8.3 filename
; ES:BX pointer to target area
; OUT CF flag set if error
; DI file size in bytes (<64K)
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
xor di, di
stc
ret
.read:
mov ax, [si+0x1A]
mov di, [si+0x1C]
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
; in dx:ax sector number
; es:bx buffer
; cx number of sectors to read
; out dx:ax next sector to read
; es:bx next free buffer
; cx zero
load_sectors:
; fail instantly if reading sectors > 16 bit
test dx, dx
mov bp, 0x3330
jnz error
.loop:
push ax
@ -217,10 +99,15 @@ load_sectors:
; count up for next sector
add bx, 0x0200
inc ax
add ax, 1
adc dx, 0
loop .loop
ret
mov dl, [fdc.drv]
; jump into kernel
jmp segment:(prog+0x0800)
error:
mov ax, bp
@ -233,9 +120,6 @@ error:
int 0x16
int 0x19
kernel_name:
db "BDOS BIN"
times (0x1FE - ($-$$)) db 0
dw 0xAA55