From f86617e750146f454fcca1d2b324c36f2dbc0020 Mon Sep 17 00:00:00 2001 From: pantonshire Date: Thu, 4 Jul 2024 09:54:17 +0100 Subject: [PATCH] bounds check gpt starting lba --- boot0.s | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/boot0.s b/boot0.s index 79109c7..847b8c4 100644 --- a/boot0.s +++ b/boot0.s @@ -86,14 +86,22 @@ bits 16 repe cmpsb jne .panic - ; 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 + ; Ensure the 8-byte starting LBA fits in 16 bits + mov di, 0x7e00 ; the rep increments di so we need to reset it + xor bx, bx + mov ax, [di + 0x4a] + or bx, ax + mov ax, [di + 0x4c] + or bx, ax + mov ax, [di + 0x4e] + or bx, ax + jnz .panic + + mov ax, [di + 0x48] + + mov word fs:[0x0000], 0xc048 + mov word fs:[0x0002], 0xc069 + hlt .panic: