I'm encountering an issue with my bootloader code where it fails to load the kernel beyond a certain memory location, specifically at KERNEL_LOCATION equ 0x100000. When attempting to boot using QEMU, I receive the error message "boot failed: could not read the boot disk."
Here's the relevant part of my bootloader code:
[org 0x7c00]
KERNEL_LOCATION equ 0x100000
BOOT_DISK equ 0
xor ax, ax
mov es, ax
mov ds, ax
mov bp, 0x9000
mov sp, bp
call read_disk
init_pm:
mov ax, 0x0003
int 10h
cli
lgdt [GDT_descriptor]
mov eax, cr0
or eax, 1
mov cr0, eax
jmp CODE_SEG:start_protected_mode
%include "gdt.asm"
%include "read_disk.asm"
[bits 32]
start_protected_mode:
mov eax, DATA_SEG
mov ds, eax
mov ss, eax
mov es, eax
mov fs, eax
mov gs, eax
mov ebp, KERNEL_LOCATION ; 32 bit stack base pointer
mov esp, ebp
jmp dword KERNEL_LOCATION ; Jump to the kernel's entry point
times 510-($-$$) db 0
dw 0xaa55
here is the read disk function:
read_disk:
; bios read functions
mov ah, 0x02
; reading just one sector
mov al, 10
; chs addressing
mov ch, 0x00 ; cylender
mov dh, 0x00 ; head
mov cl, 0x02 ; sector (reading the first sector after the boot sector sectors start at 1)
; setting the bx to the address we want to load our read disk
mov bx, KERNEL_LOCATION
mov dl, BOOT_DISK
int 0x13
; jump to error handler if c flag is one
; jc disk_error
; returning to the caller address
ret
; error handler
disk_error:
mov bx, error_msg
;call print_string
jmp $
error_msg:
; null terminating string :)
db "error reading disk",0
The read_disk function seems to be functioning properly, as it loads the boot sector correctly. However, when trying to load the kernel at 0x100000, it fails.
Notably, if I specify a lower memory location, such as 0x1000, the bootloader boots properly.
Any insights into why the bootloader fails to load the kernel beyond 0x100000 would be greatly appreciated. Thanks!