Urbs
Urbs

Reputation: 131

Bootloader not working, error: "int13_harddisk: function 42. LBA out of range"

I'm attempting to load my loader assembly (loader.asm):

[BITS 16]
[ORG 0x7e00]

start:
; printing message to show that loader is working
mov ah, 0x13
mov al, 1
mov bx, 0xa
xor dx, dx
mov bp, Message
mov cx, MessageLen
int 0x10

End:
hlt
jmp End

Message: db "Loader sucessfually loaded"
MessageLen: equ $-Message

And this is the code i boot with (boot.asm):

[BITS 16]
[ORG 0x7c00]

; Initialize the segment registers
start:
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0x7c00

TestDiskExtension:
mov [DriveId],dl
mov ah, 0x41
mov bx, 0x55aa
int 0x13
jc NotSupported
cmp bx, 0xaa55
jne NotSupported

LoadLoader:
mov si, ReadPacket
mov word[si], 0x10
mov word[si + 2], 5
mov word[si + 4], 0x7e00
mov word[si + 6], 0
mov dword[si + 8], 1
mov dword[si + 0xc], 0
mov dl, [DriveId]
mov ah, 0x42
int 0x13
jc ReadError

mov dl, [DriveId]
jmp 0x7e00

ReadError:
NotSupported:
; print error message
mov ah, 0x13
mov al, 1
mov bx, 0xa
xor dx, dx
mov bp, Message
mov cx, MessageLen
int 0x10

End:
hlt ; halts the processor until an interrupt fires
jmp End ; we jump to end to halt again

DriveId: db 0
Message: db "Error in boot process"
MessageLen: equ $-Message
ReadPacket: times 16 db 0

times (0x1be-($-$$)) db 0
db 80h ; boot indicator
db 0,2,0 ; starting CHS
db 0f0h ; type
db 0ffh, 0ffh, 0ffh ; ending CHS
dd 1 ; starting sector
dd (20*16*63-1) ; size

times (16*3) db 0

db 0x55
db 0xaa

This is how i build the image which i boot from:

nasm -f bin -o boot.bin boot.asm
nasm -f bin -o loader.bin loader.asm
dd if=boot.bin of=boot.img bs=512 count=1 conv=notrunc
dd if=loader.bin of=boot.img bs=512 count=5 seek=1 conv=notrunc

The build result message:

1+0 records in
1+0 records out
512 bytes copied, 0.0015849 s, 323 kB/s
0+1 records in
0+1 records out
46 bytes copied, 0.0113783 s, 4.0 kB/s

Here's my bochs config file: https://pastebin.com/LuJRfwny

The error message from bochs:

00018043857i[BIOS  ] Booting from 0000:7c00
00018047038i[BIOS  ] int13_harddisk: function 42. LBA out of range
00018062202i[CPU0  ] WARNING: HLT instruction with IF=0!

The goal is to get into the loader code and see the message "Loader successfully loaded". The "TestDiskExtension" part of the boot.asm works fine and does not jump to the error message. The part where i attempt to load the loader.asm binary into memory seems to be the problem.

All the mentioned files and binaries can also be downloaded here.

Upvotes: 4

Views: 304

Answers (1)

Urbs
Urbs

Reputation: 131

The solution is to use an image file created by the "bximage" tool provided from the bochs emulator.

Creating the image from scratch with the dd command will result in an image file with the wrong size and format and that is why the system is not able to handle that.

Upvotes: 4

Related Questions