diff options
| author | Chloe M. <chloe@aptel.org> | 2026-08-20 08:23:06 +0000 |
|---|---|---|
| committer | Chloe M. <chloe@aptel.org> | 2026-08-20 08:23:06 +0000 |
| commit | a85b624c0698873155668ff91fc8edc39fb1c33e (patch) | |
| tree | 83c9652e53e3f9af53fd8c4547ad6bc94d611a55 /boot/arch/amd64/mbr/mbr.S | |
| parent | ea4447ad8760466702035886af4bf2d1ff509ec4 (diff) | |
boot/amd64: mbr: Verify RDAR image
Signed-off-by: Chloe M. <chloe@aptel.org>
Diffstat (limited to 'boot/arch/amd64/mbr/mbr.S')
| -rw-r--r-- | boot/arch/amd64/mbr/mbr.S | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/boot/arch/amd64/mbr/mbr.S b/boot/arch/amd64/mbr/mbr.S index ee58525..e6c84fa 100644 --- a/boot/arch/amd64/mbr/mbr.S +++ b/boot/arch/amd64/mbr/mbr.S @@ -2,6 +2,10 @@ #define BOOT_SEG 0x7C0 /* Segment we reside on startup */ #define BOOT_RELOC_SEG 0x7A0 /* Relocation segment */ +/* Constants */ +#define RDAR_MAGIC ">RDAR!" +#define RDAR_MAGIC_LEN 6 + .code16 _start: /* Normalize CS + other selectors */ @@ -29,6 +33,10 @@ _start: /* Jump to our relocated self */ ljmp $BOOT_RELOC_SEG,$reloc reloc: + /* Load %DS with our new segment */ + mov $BOOT_RELOC_SEG, %ax + mov %ax, %ds + /* Save the drive number */ mov %dl, drive_num @@ -44,11 +52,50 @@ reloc: movl $1, dap_lba_low call disk_read_lba + /* Get stage2 */ + call find_stage2 + 1: cli hlt jmp 1b /* + * Locate stage2 on the disk + * + * TODO: This only verifies the magic number is correct, this should + * be completed. + */ +find_stage2: + push %ds + push %es + + /* Verify that magic is correct */ + mov $BOOT_SEG, %ax + mov %ax, %ds + xor %si, %si + mov $BOOT_RELOC_SEG, %ax + mov %ax, %es + mov $rdar_magic, %di + mov $RDAR_MAGIC_LEN, %cx + rep cmpsb + jne .bad_magic + + pop %es + pop %ds + ret +.bad_magic: + /* Restore %DS */ + mov $BOOT_RELOC_SEG, %ax + mov %ax, %ds + + mov $bad_magic_msg, %si + call putstr +1: cli + hlt + jmp 1b + + +/* * Read sectors from the disk */ disk_read_lba: @@ -109,7 +156,9 @@ dap_lba_high: drive_num: .byte 0x00 boot_msg: .ascii "booting\r\n\0" +bad_magic_msg: .ascii "bad RDAR magic\r\n\0" disk_err_msg: .ascii "\r\n!!!disk error!!!\r\n\0" +rdar_magic: .ascii RDAR_MAGIC .org 510 .byte 0x55 |
