Linking the kernel tips?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
BootSector
Posts: 3
Joined: Wed Jun 13, 2018 6:40 pm
Libera.chat IRC: BootSector

Linking the kernel tips?

Post by BootSector »

I've started writing an OS and so far I have a boot loader which moves into Protected Mode, however now I wish to start using C for a kernel over Assembly. I am wondering if anyone can provide pointers on linking the C to the boot loader.

-I see lots of people using GCC... Are there any other available choices?
-What is the typically preferred ways of linking a C kernel to the boot loader?
-I'm using VMWare

Thank you very much all!
nullplan
Member
Member
Posts: 1801
Joined: Wed Aug 30, 2017 8:24 am

Re: Linking the kernel tips?

Post by nullplan »

Hi,

GCC is not the only choice. Clang also exists; I don't know if it can produce code for "no OS", though. Some people also use Visual Studio, but then some people are just masochists (VS is optimized for C++ development on Windows. You have to bend it over backwards to make it produce freestanding code).

Regarding the bootloader: That generally isn't linked to the kernel in any way. Most bootloaders just load the kernel from disk using BIOS commands, and using either a blocklist (e.g. LILO) or using the actual filesystem (e.g. GRUB). Which way you prefer is up to you, and probably depends on your choice of FS. For instance, FAT is sufficiently simple to parse its root directory from within the boot loader (and the superblock being part of the boot loader certainly doesn't hurt), whereas with something like ext2, you might just want to go with the blocklist idea (or else you have to load the superblock, validate the superblock, open inode 2, find the directory entry for your kernel, open its inode, and load that into memory).

In general, though, try to explore the existing bootloaders before writing your own one. It is a miserable experience others have already gone through, so you don't have to.

Finally, you're using VMware. Good for you. Personally, I'd use qemu or bochs, the former being able to display a serial console (which means you can send debug output even if the screen is in graphical mode) and the latter having an awesome debugger.

Ciao,
Markus
Carpe diem!
Post Reply