Creating a modular monolithic kernel
-
- Member
- Posts: 76
- Joined: Sun Dec 14, 2008 1:53 pm
Creating a modular monolithic kernel
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++?
- piranha
- 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
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
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
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: Creating a modular monolithic kernel
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?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.
- piranha
- 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
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
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
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
- Combuster
- 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
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)
-
- Member
- Posts: 76
- Joined: Sun Dec 14, 2008 1:53 pm
Re: Creating a modular monolithic kernel
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?