I am working on my first stage bootloader. I am having a problem loading a sector from the hard drive. Specifically, when I call "int 0x13", the code hangs. Code listing of the important part of the bootloader:
Code: Select all
[BITS 16]
[ORG 0x7C00]
jmp main
%include "../asm_helpers/print.asm"
%include "print_level1.asm"
; PRINT 3 is a macro that prints given a string, text color, and background color
%macro PRINT1 3 ; print a level 1 text (i.e. something like "Bootloader level 1: <text>")
call print_level1
PRINT %1, %2, %3
%endmacro
%macro PRINTI 1 ; print an info line (i.e. PRINT1, but without having to specify a dark grey color)
mov esi, %1
call print_info
%endmacro
%macro FAIL 2 ; a failure condition--print an error and hang
mov esi, %2
%1 fail
%endmacro
main:
;Code is loaded to 0x0000:0x7C00, so CS=0x7C00/16=0x7C0
;Setup segment registers
; Setup stack
mov ax, cs
mov ss, ax
mov sp, ax ; Stack grows down from offset 0x7C0 toward 0x0000.
; Setup ES to point to text video memory
mov ax, 0xB800
mov es, ax
;Print splash info
PRINT str_ss_1, 0x0, 0x2
CURSOR_ADD_Y 2
;Enable A20 line
mov ax, 0x2401 ; 0x2400 to disable
int 0x15
FAIL jc, str_f_a20
;Load kernel
PRINTI str_lk_1
; Check support INT13h extensions for LBA addressing
mov ah, 0x41
mov bx, 0x55AA
mov dl, 0x80
int 0x13
FAIL jc, str_f_int13
PRINTI str_lk_2
; Do the transfer. See http://en.wikipedia.org/wiki/INT_13H#INT_13h_AH.3D42h:_Extended_Read_Sectors_From_Drive
mov si, DAP
mov ah, 0x42
mov dl, 0x80
PRINTI str_lk_3
int 0x13
PRINTI str_lk_4 ;NEVER HAPPENS!!!
FAIL jc, str_f_load
;Kernel returned
FAIL jmp, str_f_kr
print_info:
push esi
call print_level1
pop esi
SET_COLOR_L(0x8,0x0)
call print_string
ret
fail:
push esi
call print_level1
pop esi
SET_COLOR_L(0x4,0x0)
call print_string
jmp $
DAP: ; Disk Address Packet
;Size of DAP
db 0x10
;Unused
db 0
;Number of sectors to read
dw 1 ; int 13 resets this to # of blocks actually read/written
;Offset and segment of destination
dw 0x0000 ; offset
dw 0x0000 ; segment
;LBA of start
dd 1 ; lower 4 bytes
dd 0 ; upper 4 bytes
;ASCII 13 is \r, ASCII 10 is \n
str_ss_1 db "Bootloader 1",13,10,"Ian Mallett",13,10,0
str_lk_1 db "load level 2:",13,10,0
str_lk_2 db "INT13 supported!",13,10,0
str_lk_3 db "load start:",13,10,0
str_lk_4 db "load done!",13,10,0
str_f_kr db "kernel returned!",0
str_f_a20 db "no A20!",0
str_f_int13 db "no INT13!",0
str_f_load db "load failed!",0
;Fill the rest of sector with 0
TIMES 510 - ($ - $$) db 0
;Add boot signature at the end of bootloader
DW 0xAA55
Thanks,