2020-04-30 20:22:14 +02:00
|
|
|
; blah dont judge me, i miss 8080
|
|
|
|
%macro retnz 0
|
|
|
|
jz short ($+2+1)
|
2020-04-21 23:23:37 +02:00
|
|
|
ret
|
2020-04-30 20:22:14 +02:00
|
|
|
%endmacro
|
|
|
|
%macro callc 1
|
|
|
|
jnc short ($+2+3)
|
2020-04-21 23:23:37 +02:00
|
|
|
call %1
|
2020-04-30 20:22:14 +02:00
|
|
|
%endmacro
|
|
|
|
|
|
|
|
%include "inc/bpb.asm"
|
|
|
|
|
2020-09-19 10:22:50 +02:00
|
|
|
%define params bs+0x0B
|
2020-04-21 23:23:37 +02:00
|
|
|
|
|
|
|
cpu 8086
|
|
|
|
org 0x0600
|
|
|
|
bs: equ 0x7C00
|
|
|
|
|
|
|
|
init: cli
|
|
|
|
xor ax, ax
|
|
|
|
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
|
|
|
|
|
|
|
|
jmp 0:main
|
|
|
|
|
|
|
|
%include "inc/booterr.asm"
|
|
|
|
|
|
|
|
; 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
|
|
|
|
|
|
|
|
; FAT bpb has "bytes per sector" at this place
|
|
|
|
; we support only 512 byte sectors anyways
|
2020-09-19 10:22:50 +02:00
|
|
|
cmp word [params+bpb.sectorsize], 512
|
2020-04-21 23:23:37 +02:00
|
|
|
jne chain
|
|
|
|
|
|
|
|
; Media descriptor byte is never smaller than 0xF0
|
2020-09-19 10:22:50 +02:00
|
|
|
cmp byte [params+bpb.mediadesc], 0xF0
|
2020-04-21 23:23:37 +02:00
|
|
|
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
|
2020-09-19 10:22:50 +02:00
|
|
|
mov [params+bpb.tracksectors], ax
|
2020-04-21 23:23:37 +02:00
|
|
|
|
|
|
|
; update number of sides
|
|
|
|
xor ax, ax
|
|
|
|
mov al, dh
|
2020-09-19 10:22:50 +02:00
|
|
|
mov [params+bpb.heads], ax
|
2020-04-21 23:23:37 +02:00
|
|
|
|
|
|
|
; update partition offset
|
|
|
|
push si
|
|
|
|
add si, 0x08
|
2020-09-19 10:22:50 +02:00
|
|
|
mov di, params+bpb.sectoroffset
|
2020-04-21 23:23:37 +02:00
|
|
|
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
|
2020-03-01 13:03:35 +01:00
|
|
|
|
|
|
|
dap:
|
2020-04-21 23:23:37 +02:00
|
|
|
.size: db 0
|
|
|
|
db 0
|
|
|
|
.count: dw 1
|
|
|
|
.buf: dw bs
|
|
|
|
dw 0
|
|
|
|
.num: dq 0
|
|
|
|
|
|
|
|
times (0x1BE - ($-$$)) db 0
|
|
|
|
|
|
|
|
part1: db 0x80
|
|
|
|
db 0xFF, 0xFF, 0xFF
|
|
|
|
db 0x01
|
|
|
|
db 0xFF, 0xFF, 0xFF
|
|
|
|
dd 1
|
2020-09-17 07:57:46 +02:00
|
|
|
dd (1440 * 2)
|
2020-04-21 23:23:37 +02:00
|
|
|
|
|
|
|
times (0x1FE - ($-$$)) db 0
|
|
|
|
|
|
|
|
; Boot signature
|
|
|
|
dw 0xAA55
|