can't jump to kernel
Posted: Mon Jun 08, 2009 1:20 am
edit: I'm sorry, I misread the interrupt list somehow and my error checking code was all wrong (it seems to be loading properly after all).
I managed to switch over to bochs from qeme.
with this code it endlessly restarts.
boot.asm
linker file
my other question was whether or not their is any benefit to using bochs over qemu? (ease of use, easier to debug?) I'm jsut wondering because the only reason I used qemu was because bochs seemed to be a pain to configure and there are plenty of helpful pages for qemu and ubuntu.
I managed to switch over to bochs from qeme.
with this code it endlessly restarts.
boot.asm
Code: Select all
[BITS 16]
[ORG 07c00h] ;start at 0x7c00
start:
xor ax, ax
mov ah, 00h
mov al, 03h
int 10h
xor ax, ax
mov ds, ax
reset_disks: ;reset the hard drive before reading
pusha
mov ah, 0
int 13h
or ah, ah
jnz reset_disks
read_in: ;read in 10 sectors starting at sector 2
xor eax, eax
mov ax, 01000h ; setup storage area
mov es, ax ; segment 01000
xor bx, bx ; offset 0
xor eax, eax
mov ah, 02h ; read
mov al, 14h ; read 20 sectors
xor ecx, ecx
mov ch, 0 ;cylinder 0
mov cl, 00000010b ; cylinder 0, start at sector 2 (first is bootloader)
mov dh, 0 ;
mov dl, 80h
int 13h
cmp al, 14h
jne error_loading
or ah, ah
jnz reset_disks
cli
lGDT [gdtr] ; load global descriptor table
xor eax, eax ; clear out eax and enter protected mode
mov eax, cr0
or eax, 1
mov cr0, eax
jmp 08h:protected ;jump
error_loading:
mov si, error_msg
errloop:
lodsb
cmp al, 0
je enderr
mov ah, 0eh
int 10h
jmp errloop
enderr:
jmp enderr
gdt: dq 0
db 0xFF, 0xFF, 0, 0, 0, 9Ah, 0xCF, 0
db 0xFF, 0xFF, 0, 0, 0, 92h, 0xCF, 0
end_gdt:
gdtr: dw end_gdt-gdt-1
dd gdt
error_msg: db "Unable to load needed sectors", 10, 0
[BITS 32]
protected:
xor eax, eax ;reset segments
mov ax, 10h
mov ds, ax
mov es, ax
mov ss, ax
mov esp, 090000h ;setup a stack
mov dword [0xb8000], 0x07690748
jmp 08h:010000h ;jump to kernel
times 510-($-$$) db 0 ;fill to 512
dw 0xAA55
Code: Select all
[BITS 16]
[ORG 07c00h] ;start at 0x7c00
cli
start:
xor ax, ax
mov ah, 00h
mov al, 03h
int 10h
xor ax, ax
mov ds, ax
reset_disks: ;reset the hard drive before reading
pusha
mov ah, 0
int 13h
or ah, ah
jnz reset_disks
read_in: ;read in 10 sectors starting at sector 2
xor eax, eax
mov ax, 01000h ; setup storage area
mov es, ax ; segment 01000
xor bx, bx ; offset 0
xor eax, eax
mov ah, 02h ; read
mov al, 1h ; read 20 sectors
xor ecx, ecx
mov ch, 0 ;cylinder 0
mov cl, 00000010b ; cylinder 0, start at sector 2 (first is bootloader)
mov dh, 0 ;
mov dl, 80h
int 13h
cmp cl, al
jne error_loading
or ah, ah
jnz reset_disks
lGDT [gdtr] ; load global descriptor table
xor eax, eax ; clear out eax and enter protected mode
mov eax, cr0
or eax, 1
mov cr0, eax
jmp 08h:protected ;jump
error_loading:
mov si, error_msg
errloop:
lodsb
cmp al, 0
je enderr
mov ah, 0eh
int 10h
jmp errloop
enderr:
hlt
gdt: dq 0
db 0xFF, 0xFF, 0, 0, 0, 9Ah, 0xCF, 0
db 0xFF, 0xFF, 0, 0, 0, 92h, 0xCF, 0
end_gdt:
gdtr: dw end_gdt-gdt-1
dd gdt
error_msg: db "Unable to load needed sectors", 10, 0
[BITS 32]
protected:
xor eax, eax ;reset segments
mov ax, 10h
mov ds, ax
mov es, ax
mov ss, ax
mov esp, 090000h ;setup a stack
;mov dword [0xb8000], 0x07690748
jmp 08h:010000h ;jump to kernel
times 510-($-$$) db 0 ;fill to 512
dw 0xAA55
Code: Select all
ENTRY (kmain)
phys = 0x010000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
*(.rodata)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}