jump from bootloader to kernel
Posted: Tue Jun 14, 2011 6:07 am
Hello everyone! can anyone show an example how to jump from bootloader to kernel? i have this code:
Loader.asm:
Kernel.asm:
Kernel.c:
Loader.asm compiles by "nasm -f bin -o Loader.bin Loader.asm" to Loader.bin and i add it to CD as bootloader... VirtualBox shows all strings which in the end of Loader.asm. Kernel.asm and Kernel.c compiles to Kernel.bin but i cannot understand how to jump from Loader.bin to Kernel.bin... help please
Loader.asm:
Code: Select all
[BITS 16]
[ORG 0]
entry:
cli
xor cx, cx ;set stack
mov ds, cx
mov es, cx
mov ss, cx
mov sp, start
sti
mov ax, 0x07c0
mov ds, ax
mov ax, 0x9000
mov es, ax
xor si, si
xor di, di
mov cx, 128
rep movsd
jmp 0x9000:start ;go to bootloader
start:
mov ax, cs
mov ds, ax
mov ss, ax
mov si, msg_loading ;show start message
call printsi
mov si, msg_enable_gdt
call printsi
lgdt [gd_reg] ;load gdt
mov si, msg_enable_a20
call printsi
in al, 0x92 ;enable A20
or al, 2
out 0x92, al
mov si, msg_enter_pm
call printsi
mov eax, cr0 ;enter protected mode
or al, 1
mov cr0, eax
jmp 0x8:protectedmode
[BITS 32]
protectedmode:
mov ax, 0x10
mov ds, ax
mov es, ax
mov ss, ax
printsi:
pusha
.loop:
lodsb
test al, al
jz .quit
mov ah, 0x0e
int 0x10
jmp short .loop
.quit:
popa
ret
gdt:
dw 0, 0, 0, 0
db 0xFF
db 0xFF
db 0x00
db 0x00
db 0x00
db 10011010b
db 0xCF
db 0x00
dw 0, 0, 0, 0
db 0xFF
db 0xFF
db 0x00
db 0x00
db 0x00
db 10011010b
db 0xCF
db 0x00
gd_reg:
dw 8192
dd gdt
msg_loading: db "Operating system is loading...", 0x0A, 0x0D, 0
msg_enable_gdt: db "Loading GDT...", 0x0A, 0x0D, 0
msg_enable_a20: db "Enabling A20 Line...", 0x0A, 0x0D, 0
msg_enter_pm: db "Entering protected mode...", 0x0A, 0x0D, 0
TIMES 510 - ($ - $$) db 0
db 0xAA, 0x55
Code: Select all
[BITS 32]
[GLOBAL _invoke_main]
[EXTERN _kernel_main]
_invoke_main:
mov esp, 0x200000 - 4
call _kernel_main
Code: Select all
void kernel_main()
{
for (;;);
}