runing modules

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
psnix
Member
Member
Posts: 50
Joined: Fri Oct 24, 2008 12:34 pm

runing modules

Post 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
StephanvanSchaik
Member
Member
Posts: 127
Joined: Sat Sep 29, 2007 5:43 pm
Location: Amsterdam, The Netherlands

Re: runing modules

Post by StephanvanSchaik »

User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: runing modules

Post 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.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
Post Reply