boot/mbr.s (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
.code16
.section .text
.global find_bootable_part
find_bootable_part:
movw $0x0000, %ax
movw %ax, %ds
movw $0x0000, %cx
find_part_loop:
movw $mbr_partition_msg, %si
call print
movw %cx, %ax
call print_hex_int16
movw $newline, %si
call print
movw $PART_TABLE_START, %si
xor %ax, %ax
movb (%si), %al
cmp $0x80, %al
je find_part_loop_end
# TODO: loop over partitions
jmp find_part_loop_fail
find_part_loop_end:
movw $mbr_bootable_msg, %si
call print
movw %cx, %ax
call print_hex_int16
movw $newline, %si
call print
# load partition size from MBR
movw $PART_TABLE_START, %si
add $0x0C, %si
movw (%si), %cx
movw $mbr_size_msg, %si
call print
movw %cx, %ax
call print_hex_int16
movw $newline, %si
call print
# load partition start from MBR
movw $PART_TABLE_START, %si
add $0x08, %si
movw (%si), %ax
movw $mbr_start_msg, %si
call print
call print_hex_int16
movw $newline, %si
call print
add %ax, %cx
ret
find_part_loop_fail:
jmp error
.section .data
mbr_partition_msg:
.ascii " Checking partition 0x"
.byte
mbr_bootable_msg:
.ascii " bootable partition found: 0x"
.byte 0
mbr_start_msg:
.ascii " Start sector: 0x"
.byte 0
mbr_size_msg:
.ascii " Number of sectors: 0x"
.byte 0
newline:
.byte 13
.byte 10
.byte 0