OSDev.org
https://forum.osdev.org/

Linking the kernel tips?
https://forum.osdev.org/viewtopic.php?f=1&t=33003
Page 1 of 1

Author:  BootSector [ Wed Jun 13, 2018 6:51 pm ]
Post subject:  Linking the kernel tips?

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!

Author:  nullplan [ Wed Jun 13, 2018 11:21 pm ]
Post subject:  Re: Linking the kernel tips?

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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/