Get MBR ready, add hdimage target

This commit is contained in:
Nero 2019-09-17 22:41:39 +00:00
parent 7c4a618385
commit c70f388548
3 changed files with 79 additions and 7 deletions

View File

@ -29,18 +29,27 @@ kernel.com: kernel/*.asm lib/*.inc
debug.rom: debug/*.asm lib/*.inc
nasm -s -o $@ -I lib -I debug debug/main.asm && scripts/fix-rom.sh $@
floppy.bs: boot/fatvbr.asm
boot/floppy.bs: boot/fatvbr.asm
nasm -s -DCMDLINE='"KERNEL.COM"' -o $@ $<
boot/mbr.bs: boot/mbr.asm
nasm -s -DFLOPPY=$(FLOPPY) -o $@ $<
programs/%.com: programs/%.asm
nasm -s -I lib -o $@ $<
fdimage.img: floppy.bs $(DISTFILES)
mformat -C -i $@ -f $(FLOPPY) -B floppy.bs ::
fdimage.img: boot/floppy.bs $(DISTFILES)
mformat -C -i $@ -f $(FLOPPY) -B boot/floppy.bs ::
mcopy -i $@ $(DISTFILES) ::
hdimage.img: boot/mbr.bs fdimage.img
cat boot/mbr.bs fdimage.img >$@
clean:
rm -f *.com *.bin *.rom *.img *.log *.bs *.lst programs/*.com
qemu-floppy: fdimage.img $(DEBUGROM)
$(QEMU) $(QEMU_ARGS) -boot c -fda fdimage.img
qemu-hdd: hdimage.img $(DEBUGROM)
$(QEMU) $(QEMU_ARGS) -boot c -hda hdimage.img

View File

@ -151,6 +151,10 @@ load_sectors:
push cx
push dx
; add partition offset (required for HDD)
add ax, [fdc.po]
adc dx, [fdc.po+2]
; calculate CHS data
div word [cs:fdc.spt] ; ax:temp = (lba / spt)
inc dx ; dx:sector = (lba % spt) + 1

View File

@ -2,6 +2,11 @@
%define self 0x00600 ; 1 sector
%define prog 0x07C00 ; 1 sector
; FDC fields in VBR
%define spt (prog + 0x18)
%define nos (prog + 0x1A)
%define po (prog + 0x1C)
org self
cpu 8086
@ -26,15 +31,69 @@ init:
jmp 0:main
main:
mov bp, 0x0035
mov WORD [dap.blocknum], 1
mov bp, 0x3335
mov si, part1
mov cx, 4
.loop:
test BYTE [si], 0x80
jnz loadpart
add si, 0x10
loop .loop
jmp error
loadpart:
; transfer starting address into DAP
push si
add si, 0x08
mov di, dap.blocknum
movsw
movsw
pop si
; load sector
push si
mov si, dap
mov bp, 0x3336
mov ah, 0x42
stc
int 0x13
jc error
mov cx, [dap.blocknum]
int3
pop si
cmp BYTE [si+4], 0x01
jne jump
adjust:
push dx
mov bp, 0x3337
mov ah, 0x08
stc
int 0x13
jc error
; update sectors per track
xor ax, ax
mov al, cl
mov [spt], ax
; update number of sides
xor ax, ax
mov al, dh
mov [nos], ax
; update partition offset
push si
add si, 0x08
mov di, po
movsw
movsw
pop si
pop dx
jump:
jmp 0:prog
error:
mov ax, bp