Next: , Previous: , Up: Examples   [Contents][Index]


4.4 Example OS code

In this distribution, the example Multiboot2 kernel kernel is included. The kernel just prints out the Multiboot2 information structure on the screen, so you can make use of the kernel to test a Multiboot2-compliant boot loader and for reference to how to implement a Multiboot2 kernel. The source files can be found under the directory doc in the Multiboot2 source distribution.

The kernel kernel consists of only three files: boot.S, kernel.c and multiboot2.h. The assembly source boot.S is written in GAS (see GNU assembler in The GNU assembler), and contains the Multiboot2 information structure to comply with the specification. When a Multiboot2-compliant boot loader loads and execute it, it initialize the stack pointer and EFLAGS, and then call the function cmain defined in kernel.c. If cmain returns to the callee, then it shows a message to inform the user of the halt state and stops forever until you push the reset key. The file kernel.c contains the function cmain, which checks if the magic number passed by the boot loader is valid and so on, and some functions to print messages on the screen. The file multiboot2.h defines some macros, such as the magic number for the Multiboot2 header, the Multiboot2 header structure and the Multiboot2 information structure.