diff --git a/boot0.s b/boot0.s index 34e32a5..16a60cc 100644 --- a/boot0.s +++ b/boot0.s @@ -46,22 +46,48 @@ bits 16 mov di, 0x00 mov ah, 0x08 int 0x13 - jb panic - and cl, 0x3f + jc panic + and cl, 0x3f ; sectors per track mov [bp + 1], cl - movzx ax, dh - add ax, 1 - mov [bp + 2], ax - + movzx bx, dh + inc bx ; number of heads + mov [bp + 2], bx + + ; Load LBA 1. + cmp cl, 1 ; division of 1 by nonzero can be done with cmp + sete al ; temp = LBA / (sectors per track) + setne cl ; sector - 1 = LBA % (sectors per track) + inc cl + xor ah, ah ; zero-extend temp + xor dx, dx ; TODO: explain why this is needed for div + div bx ; ah = mod (head), al = div (cylinder) + mov dh, ah ; head + mov ch, al ; cylinder + ; we already have sector in cl + mov ah, 2 ; read disk + mov al, 1 ; load one sector + mov bx, 0x7e00 + mov dl, [bp] ; drive number + int 0x13 + jc panic + + ; head = temp % number of heads + ; cylinder = temp / number of heads ; Set VGA mode ; https://mendelson.org/wpdos/videomodes.txt mov ax, 0x0003 int 0x10 - mov word fs:[0x0000], 0xc048 - mov word fs:[0x0002], 0xc069 + ; mov word fs:[0x0000], 0xc048 + ; mov word fs:[0x0002], 0xc069 + mov al, [0x7e00] + mov byte fs:[0x0000], al + mov al, [0x7e01] + mov byte fs:[0x0002], al + mov al, [0x7e02] + mov byte fs:[0x0004], al hlt panic: diff --git a/justfile b/justfile index e3cec88..6308638 100644 --- a/justfile +++ b/justfile @@ -13,4 +13,5 @@ partition_disk: parted --script disk.bin type 1 0fc63daf-8483-4772-8e79-3d69d8477de4 write_stage0: + dd if=/dev/zero of=disk.bin bs=440 count=1 conv=notrunc dd if=boot0.bin of=disk.bin conv=notrunc