Call C function from bootloader
Posted: Thu Nov 20, 2014 4:20 pm
Hi,
I'm looking for a minimalist way to call a C function from my own bootloader (here from protected mode).
I give you here my bootloader, do you have any workable example to do so ?
Bootloader :
Here my simple kernel code :
Many thanks for your solution.
NB: I rode the GRUB tutorial to load a C kernel, but I don't get a thing...!
I'm looking for a minimalist way to call a C function from my own bootloader (here from protected mode).
I give you here my bootloader, do you have any workable example to do so ?
Bootloader :
Code: Select all
[org 0x7C00]
cli
lgdt [gdt_descriptor]
; Enter PM
mov eax, cr0
or eax, 0x1
mov cr0, eax
jmp 0x8:init_pm ;jmp to the GDT code descriptor
[bits 32]
init_pm :
mov ax, 0x10 ;load the GDT data descriptor
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax
;Any idea how to call my C function from here ?
jmp $
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[bits 16]
GDT:
;null :
dd 0x0
dd 0x0
;code :
dw 0xffff ;Limit
dw 0x0 ;Base
db 0x0 ;Base
db 0b10011010 ;1st flag, Type flag
db 0b11001111 ;2nd flag, Limit
db 0x0 ;Base
;data :
dw 0xffff
dw 0x0
db 0x0
db 0b10010010
db 0b11001111
db 0x0
gdt_descriptor :
dw $ - GDT - 1 ;16-bit size
dd GDT ;32-bit start address
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Bootsector padding
times 510-($-$$) db 0
dw 0xaa55
Here my simple kernel code :
Code: Select all
void main() {
char * vga = (char *) 0xb8000 ;
*vga = "X";
}
NB: I rode the GRUB tutorial to load a C kernel, but I don't get a thing...!