title: Call C kernel from assembly bootloader
body: <p>EDIT: plz jump to my second post below...</p>
  
  <p>I'm looking for a minimalist way to enter to my kernel from my bootloader.
  Do you have any workable example to do so ? </p>
  
  <p>Here is the bootloader which enters protected mode :
  "boot.asm"</p>
  
  <pre><code>[org 0x7C00]
  
  mov bp , 0x9000
  mov sp , bp
  
  cli
  lgdt [gdt_descriptor] 
  
  ; Enter PM
  mov eax, cr0
  or  eax, 0x1
  mov cr0, eax
  
  jmp 0x8:init_pm 
  
  
  [bits 32]
  init_pm :
      mov ax, 0x10
      mov ds, ax
      mov ss, ax
      mov es, ax
      mov fs, ax
      mov gs, ax
  
      ;Tried to call my C function from here 
      call 0x8000      ; Kernel entry point       
  
      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
  </code></pre>
  
  <p>Here my kernel entry point I would like to call from the bootloader :
  "kernel.c"</p>
  
  <pre><code>void main() {
      char * vga = (char *) 0xb8000 ;
      *vga = "X";
  }
  </code></pre>
  
  <p>Thanks for your help,</p>
  
  <p>So far, this is what I tried to do, but it doesn't work :
  I just put the kernel to 0x8000 with ld and concatenate with cat, then jump from the bootloader to 0x8000</p>
  
  <pre><code>nasm boot.asm -f bin -o boot.bin
  gcc -ffreestanding -c kernel.c -o kernel.o
  ld -o kernel.bin -Ttext 0x8000 kernel.o --oformat binary
  cat boot.bin kernel.bin &gt; os-image
  </code></pre>