Page 1 of 1

runing modules

Posted: Tue Apr 27, 2010 11:54 am
by psnix
hi

how can i run modules (loaded with GRUB)?, for example i want to execute "InitModule" function.

for example i worte this module :

Code: Select all

void InitModule ()
{
     printf("hi\n")l
}
1. how can i compile it with gcc?

2. how can i get address of InitModule function (in kernel)

sorry for my bad english

Re: runing modules

Posted: Tue Apr 27, 2010 12:12 pm
by StephanvanSchaik

Re: runing modules

Posted: Tue Apr 27, 2010 12:23 pm
by gravaera
It...depends. GRUB's 'modules' are just files it loads along with your kernel. The format of the file is determined by none other than you, so you can, for example, create your own 'mini-custom-FS', or 'ramdisk', or whatever you so choose to call it, and have it loaded along with your kernel. I'm only aware of you being able to tell GRUB whether or not to page align modules. I don't think GRUB guarantees anything else about placement in RAM.

If you decide to compile object modules separately from the kernel, and load them as objects, you would have to parse the executable header, etc, and determine your own private method of finding the procedures you wish to use. Maybe you could generate a table at runtime with jump offsets to procedure addresses in RAM which correspond to addresses of routines in your accompanying code modules.

How to compile them? Depends. Do you want them to be relocatable modules, or full-blown executables? Or maybe you could do some hackery with PIC and load them as position independent shared libs which are treated as if they're like...jump-to routines, or something.

How do you run them? Well, in the Multiboot Info Structure, GRUB passes a table of info about loaded modules. You parse the GRUB table to find your modules, then you parse your modules, whatever parsing the modules may mean to your kernel.

EDIT: Stephan already provided good links.