Creating a modular monolithic kernel

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
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Creating a modular monolithic kernel

Post by computafreak »

At the moment, I have a 'pure' monolithic kernel; that is, everything is stored in a single ELF file. I'm not really happy with this - it sounds like it will be fairly difficult to add to. So I've decided to move over to a modular monolithic kernel. I'll load the modules via GrUB until I have a working file system. However, this seems like it will complicate my build process. Currently, I just have to use a single makefile, which finds and compiles every source file, linking them together, copying the kernel executable and running genisoimage. How would this change? Additionally, it seems as though I simply dynamically link the kernel and module together. Now presumably, I just have to give the module the necessary kernel header files (and vice versa). Does this approach still work with C++?
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Re: Creating a modular monolithic kernel

Post by piranha »

My method is fairly simple. I load my modules with grub, however I load all of them inside one initrd. Pretty simple, see JamesM's Initrd tutorial for this. I use his initrd format and creator.

Then my OS loads all of the modules, also fairly simple.

This doesn't complicate the build process that much, as I make a different file extension for modules. Instead of .c -> .o its .c -> .m. So Make compiles and links the modules they way I want them. Then, I add the module name to $(MODS). This is used to add the module to the initrd.

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Creating a modular monolithic kernel

Post by NickJohnson »

piranha wrote:My method is fairly simple. I load my modules with grub, however I load all of them inside one initrd. Pretty simple, see JamesM's Initrd tutorial for this. I use his initrd format and creator.

Then my OS loads all of the modules, also fairly simple.

This doesn't complicate the build process that much, as I make a different file extension for modules. Instead of .c -> .o its .c -> .m. So Make compiles and links the modules they way I want them. Then, I add the module name to $(MODS). This is used to add the module to the initrd.
But don't the modules have to be both relocatable and anonymous to get the advantages of a modular monolithic design? How can you do that if the modules require linking to the kernel ,even if they aren't in the kernel at bootup? Or are the modules just semi-dynamically linked like shared libraries?
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Re: Creating a modular monolithic kernel

Post by piranha »

The kernel links the unresolved dependencies when it loads the module. Thats done with kernel symbols.

The modules are linked with the -r flag in ld.

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Creating a modular monolithic kernel

Post by Combuster »

I have a exokernel with makefiles (with lots of binaries, libs, and object files all over). Feel free to poke around there for build system ideas (link in signature)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: Creating a modular monolithic kernel

Post by computafreak »

Thanks for all of the helpful suggestions. I've downloaded and read the ELF specification, and am writing my ELF loader now. I do, however have a final question. All of my modules are written in C++, and as such are just classes. Do I need to provide an entry point, or do I just link it into the main kernel and expect the constructor and method calls to work automatically?
Post Reply