Page 1 of 1
Creating a modular monolithic kernel
Posted: Sun Jun 21, 2009 11:21 am
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++?
Re: Creating a modular monolithic kernel
Posted: Sun Jun 21, 2009 12:11 pm
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
Re: Creating a modular monolithic kernel
Posted: Sun Jun 21, 2009 2:29 pm
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?
Re: Creating a modular monolithic kernel
Posted: Sun Jun 21, 2009 3:47 pm
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
Re: Creating a modular monolithic kernel
Posted: Sun Jun 21, 2009 3:54 pm
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)
Re: Creating a modular monolithic kernel
Posted: Tue Jun 23, 2009 12:25 am
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?