OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 12:27 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Using GRUB2 modules in the kernel
PostPosted: Fri Sep 27, 2019 7:06 am 
Offline

Joined: Wed Feb 15, 2017 8:29 am
Posts: 17
Hi! I read the multiboot documentation, and I saw that it was possible for the bootloader to load boot modules in RAM for the kernel. Because I want to create a microkernel I find this awesome, I searched in the documentation of GRUB how it was possible to do that and I finally find the "module" command to load GRUB module in RAM for the kernel.

What I would like to do is to use a GRUB module to load the disk driver and process management program of my kernel, and then use them to load the rest. I was able to find the GRUB modules in RAM, but now I struggle on how to use them. They are a relocatable elf, so they need to be linked with something. Does this mean that I should know where the executable code of the core image of GRUB has been load in memory and write a small linker in my kernel? I think there is another way.

Does somebody know how to use GRUB modules as executable for the kernel? I can't find any info. Or maybe I can just call functions from the elf file of the GRUB module?


Top
 Profile  
 
 Post subject: Re: Using GRUB2 modules in the kernel
PostPosted: Fri Sep 27, 2019 7:26 am 
Offline
Member
Member

Joined: Wed Sep 19, 2012 3:43 am
Posts: 91
Location: The Netherlands
"GRUB modules" are simply files that are loaded into memory and are pointed to by the "module" struct in the multiboot struct.
After they are loaded into memory they have nothing to do with GRUB whatsoever. So yes, you'll need to link the ELF executable to your kernel at runtime and jump to the entrypoint.


Top
 Profile  
 
 Post subject: Re: Using GRUB2 modules in the kernel
PostPosted: Fri Sep 27, 2019 8:05 am 
Offline

Joined: Wed Feb 15, 2017 8:29 am
Posts: 17
Ok, so this means that if I want to use the GRUB module I have to embed the core image of GRUB into the kernel? I don't think it's a good solution (but I am curious to test it, it should be possible to have a small image with everything inside). The other option I see is to create something like ramfs.

Thanks for the reply


Top
 Profile  
 
 Post subject: Re: Using GRUB2 modules in the kernel
PostPosted: Fri Sep 27, 2019 9:11 am 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
There is a difference between kernel modules loaded by GRUB (you control the contents entirely, GRUB only loads them from disk and passes a pointer to the module via the Multiboot info struct) and modules for GRUB (i.e., extensions of GRUB that are loaded/compiled into GRUB.

_________________
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].


Top
 Profile  
 
 Post subject: Re: Using GRUB2 modules in the kernel
PostPosted: Fri Sep 27, 2019 12:46 pm 
Offline

Joined: Wed Feb 15, 2017 8:29 am
Posts: 17
Korona wrote:
There is a difference between kernel modules loaded by GRUB (you control the contents entirely, GRUB only loads them from disk and passes a pointer to the module via the Multiboot info struct) and modules for GRUB (i.e., extensions of GRUB that are loaded/compiled into GRUB.


Oooh thank you, I thought it was only possible to load GRUB module with the command module, but I can load whatever file I want. This is exactly what I wanted, I am so happy right now :D!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], ebeneEinHalb, Google [Bot] and 125 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group