Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I build a kernel image using Visual Studio?

I'd like to build an embedded kernel for an x86 machine using Visual C++. I have some C and assembly code files to compile and I'd like to link them all together in a way that is compatible with a Multiboot bootloader like GRUB.

like image 438
Frank Miller Avatar asked Mar 20 '09 22:03

Frank Miller


1 Answers

OSDev has a wiki entry on Visual Studio, that may provide some insight, especially with the links to Kaushik Srenevasan's blog entries on the subject of PE kernels designed to be loaded by multiboot-based bootloaders (like GRUB).

A couple of large, broad-strokes things you should know:

  • In the multiboot header, you need to use the AOUT kludge.
  • You need to specify the /BASE:0x100000 argument to the linker, so the final binary code is based to where the bootloader is going to put it.
  • Your kernel's entry point (usually called 'kmain') needs to have __declspec(noreturn) on it, and you will need to do an __asm { hlt } instead of returning.
like image 68
Alex Lyman Avatar answered Sep 18 '22 18:09

Alex Lyman