[SOLVED] Bootloader fails on a real pc
Posted: Sun May 08, 2011 4:38 pm
Hello there,
I'm developping a bootloader and everythings goes quit well. I use bochs or kvm to test. Today I tried to boot from a real computer, and that failed. I used an USB harddrive (pendrive) and my first sector gets loaded perfectly the disk reader doesn't show errors either but when i try to far jump it fails.
I can't figure out why it works with bochs or kvm but fails with a real pc..
My first stage:
loadimage.asm
And sector 2 (which will be read)
Does any of you see, why the far jump does what I want in real mode but does not in a real PC. Oh and my linker makes sure the second stage is at 0x7E00
It just hangs there after displaying the first message.. why kvm loads the entire bootloader..
Thanks in advance.
I'm developping a bootloader and everythings goes quit well. I use bochs or kvm to test. Today I tried to boot from a real computer, and that failed. I used an USB harddrive (pendrive) and my first sector gets loaded perfectly the disk reader doesn't show errors either but when i try to far jump it fails.
I can't figure out why it works with bochs or kvm but fails with a real pc..
My first stage:
Code: Select all
[BITS 16]
[ORG 0x7C00]
main: ; entry point
mov [bootdisk], dl
mov si, booted
call println
call loadimage
shr ax, 8
or al, al
jz .loaded
.bailout:
mov si, failed
call println
xor ax, ax
int 0x16
int 0x19
cli
jmp $
.loaded:
mov dl, [bootdisk]
jmp 0x7C0:0x200
mov si, failed
call println
cli
jmp $
;
; Image loader
;
%include 'boot/x86/stage1/loadimage.asm'
;
; Print routines
;
%include 'boot/x86/println.asm'
;
; Since flat binary is one big heap of code without sections, is the code below some sort of data section.
;
bootdisk db 0
booted db 'GEBL has been loaded by the bios! Executing...', 0x0
failed db '(0x0) Failed to load the next stage.. ready to reboot. Press any key.', 0x0
times 510 - ($ - $$) db 0
dw 0xAA55
Code: Select all
loadimage:
.checkextensions:
mov ah, 0x41 ; check ext
mov dl, [bootdisk] ; HDD0
mov bx, 0x55AA
int 0x13
jc .checkextensions
.extread:
mov ah,0x42
mov dl,[bootdisk]
lea si,[lbar]
int 0x13
jnc .return
.oldway:
xor ah, ah ; function 0 = reset
mov dl, [bootdisk]
int 0x13
jc .oldway
.oldload:
mov bx, 0x7C0 ; segment
mov es, bx
mov bx, 0x200 ; offset
mov ah, 0x2 ; function 2
mov al, 0x1 ; read 1 sector
xor ch, ch ; track
mov cl, 0x2 ; sector to read
xor dh, dh ; head number
mov dl, [bootdisk] ; drive number
int 0x13 ; call BIOS - Read the sector
.return:
ret
;
; LBA register
;
; Loading a sector with this seg:off will place it right after the mbr
;
lbar:
db 0x10 ; register size
db 0 ; reserved, must be 0
dw 0x1 ; sectors to read
dw 0x200 ; memory offset
dw 0x7C0 ; memory segment
dq 0x1 ; starting sector (sector to read)
Code: Select all
main:
mov [diskid], dl
call enable_A20
jnc .loadstage2
mov si, a20fail
.bailout:
call println
xor ah, ah
int 0x16
int 0x19
cli
jmp $
.loadstage2:
mov si, a20ok
call println
call getmemorymap
mov si, a20fail
jc .bailout
mov ax, word [mmr+4]
or ax, ax
jz .bailout ; we are not here to bully our user with al zero-length memory map.
call dynamicloader
shr ax, 8
or al, al
mov si, nostage2
jnz .bailout
jmp 0x7E0:0x400
jmp .bailout
;
; Dynamic disk reader
;
%include 'boot/x86/stage1/stage1.5/dynamicloader.asm'
;
; Memory map
;
%include 'boot/x86/stage1/stage1.5/getmemorymap.asm'
;
; A20 Gate
;
%include 'boot/x86/stage1/stage1.5/enable_A20.asm'
;
; Print routines
;
%include 'boot/x86/println.asm'
diskid db 0
a20ok db 'The A20 line has been enabled.', 0x0
a20fail db '(0x1) The A20 gate couldn`t be opened. Press a key to reboot.', 0x0
nostage2 db '(0x2) Failed to load the second stage.. Press a key to reboot.', 0x0
times 1024 - ($ - $$) db 0
Code: Select all
SECTIONS
{
.boot 0x7E00:
{
*(.stage1)
*(.stage2)
*(.pmode)
}
.text :
{
*(.text)
}
.rodata :
{
*(.rodata)
}
.data :
{
*(.data)
}
.bss :
{
*(.bss)
}
.end ALIGN(2) :
{
*(.end)
}
}
Thanks in advance.