Start to Finish: Calling kmain

From XOmB wiki

Jump to: navigation, search
This page is part of a series on XBB From Start to Finish.

For reference: kmain.d.


[edit] Inside of kmain

Congratulations! You're finally free of all of that legacy crap and actually kmain is a little different than your usual main() function. Instead of argc and argv, you get the bootloader id and data points to a structure that the bootloader hands over. In our case, we're using GRUB, so in this specific instance, the id is a magic number. It should always be '0x2BADB002', which is defined in multiboot.h as MUTIBOOT_BOOTLOADER_MAGIC. This means that you can verify if all is well by testing this number. If it's the correct one, you know that everything has gone according to plan. The data structure points to a multiboot_info. Its layout is described here, and the values are described here, here, and here. The linked articles explain how these headers are used to verify that things are running correctly. This is probably a good idea, but in XBB we've left that as an exercise. It'll do you some good.

[edit] And They're Off!!!

Anyway, now you're home free! This is where we let off, and you start. You can code in D itself in kmain. However, you only have access to the kernel runtime, and so you can't do everything that you could with normal D. Most of it is there, however. With XBB, we just print to the screen and then loop into infinity. This is where all of the logic of your kernel will go. What you do with the rest of kmain is up to you.

Personal tools