2023-02-13 18:23:33 -06:00
|
|
|
; This boots the active partition.
|
|
|
|
; Relocates self to 0x7E00, loads the
|
|
|
|
; first sector of active partition
|
|
|
|
; to 0x7C00 and jumps
|
|
|
|
[ORG 0x7C00]
|
2022-09-14 16:50:44 -05:00
|
|
|
[BITS 16]
|
|
|
|
xor ax, ax
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
2023-02-06 00:01:48 -06:00
|
|
|
mov ax, 0x8000
|
|
|
|
mov ss, ax
|
|
|
|
mov sp, 0xFF00
|
2023-02-13 18:23:33 -06:00
|
|
|
; Relocate self
|
|
|
|
mov di, 0x7E00
|
|
|
|
mov si, 0x7C00
|
|
|
|
mov cx, 512
|
|
|
|
rep movsw
|
|
|
|
jmp 0:relocated
|
|
|
|
; TODO Make this calculated, somehow
|
|
|
|
[SECTION RELOC vstart=0x7E20]
|
|
|
|
relocated:
|
2023-02-07 18:52:17 -06:00
|
|
|
mov ah, 0x41 ; int 13 extensions check
|
|
|
|
mov bx, 0x55AA
|
|
|
|
int 0x13
|
2023-02-13 18:23:33 -06:00
|
|
|
jc no_int13
|
|
|
|
; Find active partition
|
|
|
|
xor cx, cx
|
|
|
|
mov si, 0x7E00+0x1BE
|
|
|
|
.find_active:
|
|
|
|
lodsb
|
|
|
|
bt ax, 7
|
|
|
|
jc read
|
|
|
|
add si, 15
|
|
|
|
inc cl
|
|
|
|
cmp cl, 4
|
|
|
|
jl .find_active
|
|
|
|
jmp err
|
|
|
|
read:
|
|
|
|
; Put partition start LBA in disk address packet
|
|
|
|
add si, 7
|
|
|
|
mov di, addr_packet_start_block
|
|
|
|
movsw
|
|
|
|
movsw
|
|
|
|
; Load the first sector of the partition
|
2023-02-06 00:01:48 -06:00
|
|
|
xor ax, ax
|
2022-09-14 16:50:44 -05:00
|
|
|
mov ah, 0x42
|
|
|
|
mov si, addr_packet
|
|
|
|
int 0x13
|
2023-02-06 00:01:48 -06:00
|
|
|
jc err
|
2023-02-13 18:23:33 -06:00
|
|
|
; Jump to partition boot
|
|
|
|
jmp 0:0x7C00
|
|
|
|
|
|
|
|
no_int13:
|
|
|
|
mov si, no_exten_str
|
|
|
|
mov cx, no_exten_str_end - no_exten_str
|
|
|
|
jmp print
|
2023-02-06 00:01:48 -06:00
|
|
|
err:
|
2023-02-07 18:52:17 -06:00
|
|
|
mov bx, ax
|
|
|
|
mov si, string
|
|
|
|
mov cx, string_end - string
|
|
|
|
print:
|
2022-09-14 16:50:44 -05:00
|
|
|
push 0xb800
|
|
|
|
pop es
|
|
|
|
xor di, di
|
|
|
|
mov ah, 0x7
|
|
|
|
err_print:
|
|
|
|
lodsb
|
|
|
|
stosw
|
|
|
|
loop err_print
|
|
|
|
hlt_loop:
|
|
|
|
hlt
|
|
|
|
jmp hlt_loop
|
|
|
|
string: db 'DISK ERROR'
|
2023-02-07 18:52:17 -06:00
|
|
|
string_end:
|
2023-02-13 18:23:33 -06:00
|
|
|
no_exten_str: db 'NO INT13 EXTEN'
|
|
|
|
no_exten_str_end:
|
2022-09-14 16:50:44 -05:00
|
|
|
|
|
|
|
addr_packet:
|
|
|
|
db 0x10, 0x00 ; size, reserved
|
2023-02-13 18:23:33 -06:00
|
|
|
dw 1 ; blocks
|
|
|
|
addr_packet_transfer_buff_off: dw 0x7C00 ; transfer buffer offset
|
|
|
|
addr_packet_transfer_buff_seg: dw 0x0000 ; transfer buffer segment
|
|
|
|
addr_packet_start_block: dq 0 ; start block
|