Re-add support for booting from qemu harddisk
This commit is contained in:
parent
84b754551c
commit
8131db9b29
9
Makefile
9
Makefile
@ -64,6 +64,12 @@ fd%.img: $(DISTFILES) $(SYS)
|
||||
mcopy -i $@ $(DISTFILES) ::
|
||||
$(SYS) $@ @rdos.com
|
||||
|
||||
hdd.img: mbr.bs @rdos.com fd1440.img
|
||||
dd if=mbr.bs bs=512 count=1 of=$@
|
||||
dd if=@rdos.com bs=512 seek=1 of=$@
|
||||
dd if=fd1440.img bs=512 seek=63 of=$@
|
||||
dd if=/dev/zero bs=512 seek=$$(( 63 * 23 )) count=63 of=$@
|
||||
|
||||
clean:
|
||||
rm -f *.com *.bs *.0 *.lst *.img *.bin *.rom
|
||||
rm -f host/*.elf
|
||||
@ -73,3 +79,6 @@ qemu-floppy3: fd1440.img $(ROMS)
|
||||
|
||||
qemu-floppy5: fd360.img $(ROMS)
|
||||
$(QEMU) $(QEMU_ARGS) -boot a -fda fd360.img
|
||||
|
||||
qemu-hdd: hdd.img $(ROMS)
|
||||
$(QEMU) $(QEMU_ARGS) -boot c -hda hdd.img
|
||||
|
141
boot/mbr.asm
141
boot/mbr.asm
@ -1,139 +1,42 @@
|
||||
; blah dont judge me, i miss 8080
|
||||
%macro retnz 0
|
||||
jz short ($+2+1)
|
||||
ret
|
||||
%endmacro
|
||||
%macro callc 1
|
||||
jnc short ($+2+3)
|
||||
call %1
|
||||
%endmacro
|
||||
|
||||
%include "inc/bpb.asm"
|
||||
|
||||
%define bpb bs+0x0B
|
||||
|
||||
cpu 8086
|
||||
org 0x0600
|
||||
bs: equ 0x7C00
|
||||
|
||||
%define seg 0x060
|
||||
|
||||
org 0x7C00 - (seg << 4)
|
||||
|
||||
init: cli
|
||||
xor ax, ax
|
||||
mov ax, seg
|
||||
mov ss, ax
|
||||
xor sp, sp
|
||||
|
||||
; save driver number
|
||||
push dx
|
||||
|
||||
; save PnP ptr
|
||||
push es
|
||||
push di
|
||||
|
||||
; Relocate away from bootsector loading area
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov si, bs
|
||||
mov di, $$
|
||||
mov cx, 0x100
|
||||
rep movsw
|
||||
xor sp, sp
|
||||
|
||||
jmp 0:main
|
||||
.retry: mov bx, 7
|
||||
mov ax, 0x0e2e
|
||||
int 0x10
|
||||
|
||||
%include "inc/booterr.asm"
|
||||
mov ax, 0x0210
|
||||
mov cx, 2
|
||||
mov dh, 0
|
||||
mov bx, 0x100
|
||||
|
||||
; find active partition or bail out
|
||||
; result in si
|
||||
findp: mov si, part1
|
||||
mov cx, 4
|
||||
.loop: test BYTE [si], 0x80
|
||||
retnz
|
||||
add si, 0x10
|
||||
loop .loop
|
||||
call errcll
|
||||
|
||||
main: ; find active partition
|
||||
call findp
|
||||
|
||||
; transfer starting address into DAP
|
||||
push si
|
||||
add si, 0x08
|
||||
mov di, dap.num
|
||||
movsw
|
||||
movsw
|
||||
pop si
|
||||
|
||||
; load sector
|
||||
push si
|
||||
mov si, dap
|
||||
mov ah, 0x42
|
||||
stc
|
||||
int 0x13
|
||||
callc errcll
|
||||
pop si
|
||||
jc .retry
|
||||
|
||||
; FAT bpb has "bytes per sector" at this place
|
||||
; we support only 512 byte sectors anyways
|
||||
cmp word [bpb+BPBSS], 512
|
||||
jne chain
|
||||
|
||||
; Media descriptor byte is never smaller than 0xF0
|
||||
cmp byte [bpb+BPBMD], 0xF0
|
||||
jc chain
|
||||
|
||||
; ask BIOS what our disk geometry is
|
||||
mov ah, 0x08
|
||||
stc
|
||||
int 0x13
|
||||
jc chain
|
||||
|
||||
; ES might be messed up from int 13h, fix it
|
||||
push cs
|
||||
pop es
|
||||
|
||||
; update sectors per track
|
||||
xor ax, ax
|
||||
mov al, cl
|
||||
mov [bpb+BPBSPT], ax
|
||||
|
||||
; update number of sides
|
||||
xor ax, ax
|
||||
mov al, dh
|
||||
mov [bpb+BPBNOS], ax
|
||||
|
||||
; update partition offset
|
||||
push si
|
||||
add si, 0x08
|
||||
mov di, bpb+BPBHS
|
||||
movsw
|
||||
movsw
|
||||
pop si
|
||||
|
||||
chain: ; restore PnP structure
|
||||
pop di
|
||||
pop es
|
||||
pop dx
|
||||
xor cx, cx
|
||||
mov bp, si
|
||||
; chain into partition boot sector
|
||||
jmp 0:bs
|
||||
|
||||
dap:
|
||||
.size: db 0x10
|
||||
db 0
|
||||
.count: dw 1
|
||||
.buf: dw bs
|
||||
dw 0
|
||||
.num: dq 0
|
||||
jmp seg:0x100
|
||||
|
||||
times (0x1BE - ($-$$)) db 0
|
||||
|
||||
; assumes 16 heads, 63 sectors per track
|
||||
; image of 1.44 MB floppy starting on 2nd track
|
||||
part1: db 0x80
|
||||
db 1, 1, 0
|
||||
db 1
|
||||
db 0xFF, 0xFF, 0xFF
|
||||
db 0x01
|
||||
db 0xFF, 0xFF, 0xFF
|
||||
dd 1
|
||||
dd (1440 * 2)
|
||||
dd 63
|
||||
dd 0xb40
|
||||
|
||||
times (0x1FE - ($-$$)) db 0
|
||||
|
||||
; Boot signature
|
||||
dw 0xAA55
|
||||
sig: dw 0xAA55
|
||||
|
Loading…
Reference in New Issue
Block a user