summaryrefslogtreecommitdiff
path: root/boot/arch/amd64/mbr
diff options
context:
space:
mode:
Diffstat (limited to 'boot/arch/amd64/mbr')
-rw-r--r--boot/arch/amd64/mbr/mbr.S40
1 files changed, 36 insertions, 4 deletions
diff --git a/boot/arch/amd64/mbr/mbr.S b/boot/arch/amd64/mbr/mbr.S
index e6c84fa..1ce1da1 100644
--- a/boot/arch/amd64/mbr/mbr.S
+++ b/boot/arch/amd64/mbr/mbr.S
@@ -5,6 +5,8 @@
/* Constants */
#define RDAR_MAGIC ">RDAR!"
#define RDAR_MAGIC_LEN 6
+#define BOOT_PATH "boot/biosboot.bin"
+#define BOOT_PATH_LEN 17
.code16
_start:
@@ -54,16 +56,12 @@ reloc:
/* 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
@@ -72,6 +70,7 @@ find_stage2:
/* Verify that magic is correct */
mov $BOOT_SEG, %ax
mov %ax, %ds
+ xor %bx, %bx /* Tracks %SI */
xor %si, %si
mov $BOOT_RELOC_SEG, %ax
mov %ax, %es
@@ -80,9 +79,40 @@ find_stage2:
rep cmpsb
jne .bad_magic
+ /* Iterate every data descriptor */
+ clc /* Carry set if found */
+1: movw %ds:6, %cx /* Add data descriptor size */
+ mov %bx, %si
+ mov %si, %dx
+ add %cx, %bx
+ mov $rdar_magic, %di
+ mov $RDAR_MAGIC_LEN, %cx
+ rep cmpsb
+ jne .not_found
+
+ /* Does the path match? */
+ mov %dx, %si
+ add $8, %si
+ mov $stage2_path, %di
+ mov $BOOT_PATH_LEN, %cx
+ rep cmpsb
+ jne 1b
+
+ stc
pop %es
pop %ds
+ jnc .not_found
+
+ /* TODO: On found, return the offset to the data in %CX */
ret
+.not_found:
+ pop %ds
+ mov $not_found_msg, %si
+ call putstr
+1: cli
+ hlt
+ jmp 1b
+
.bad_magic:
/* Restore %DS */
mov $BOOT_RELOC_SEG, %ax
@@ -157,8 +187,10 @@ dap_lba_high:
drive_num: .byte 0x00
boot_msg: .ascii "booting\r\n\0"
bad_magic_msg: .ascii "bad RDAR magic\r\n\0"
+not_found_msg: .ascii "stage 2 not found\r\n\0"
disk_err_msg: .ascii "\r\n!!!disk error!!!\r\n\0"
rdar_magic: .ascii RDAR_MAGIC
+stage2_path: .ascii BOOT_PATH
.org 510
.byte 0x55