From 9cfb010116cf735a136bcac1ad7720994a825157 Mon Sep 17 00:00:00 2001 From: Ry Date: Sat, 4 Mar 2023 18:14:14 -0800 Subject: [PATCH] Check for magic bytes before booting a disk's boot sector --- boot.asm | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/boot.asm b/boot.asm index 56fca6e..a56f08c 100644 --- a/boot.asm +++ b/boot.asm @@ -1,14 +1,26 @@ ; disk booting routines -; these are only used during booting, they are not exposed via the jump table ; load the boot sector of disk 0 to 0x00000800 and jump to it ; inputs: ; none ; outputs: -; none (doesn't return) +; none (returns if disk 0 is not bootable) start_boot_process: - mov r0, 0x80003000 ; command to read a sector from disk 0 into memory - mov r1, 0x80002000 ; command to set the location of the buffer + ; read sector 0 to 0x800 + mov r0, 0 + mov r1, 0 + mov r2, 0x00000800 + call read_sector + + ; check for the bootable magic bytes + cmp [0x000009FC], 0x523C334C + ifnz ret + + ; now clean up and jump to the loaded binary + call boot_cleanup + mov rsp, SYSTEM_STACK ; reset stack pointer + mov r0, 0 ; booting from disk id 0 + jmp 0x00000800 ; read sector 0 to 0x800 out r1, 0x00000800 @@ -28,4 +40,37 @@ boot_cleanup: mov r0, BACKGROUND_COLOR call fill_background + movz.8 r0, 0 + movz.8 r1, 0 + movz.8 r2, 0 + movz.8 r3, 0 + movz.8 r4, 0 + movz.8 r5, 0 + movz.8 r6, 0 + movz.8 r7, 0 + movz.8 r8, 0 + movz.8 r9, 0 + movz.8 r10, 0 + movz.8 r11, 0 + movz.8 r12, 0 + movz.8 r13, 0 + movz.8 r14, 0 + movz.8 r15, 0 + movz.8 r16, 0 + movz.8 r17, 0 + movz.8 r18, 0 + movz.8 r19, 0 + movz.8 r20, 0 + movz.8 r21, 0 + movz.8 r22, 0 + movz.8 r23, 0 + movz.8 r24, 0 + movz.8 r25, 0 + movz.8 r26, 0 + movz.8 r27, 0 + movz.8 r28, 0 + movz.8 r29, 0 + movz.8 r30, 0 + movz.8 r31, 0 + ret