I am interested in creating loadable modules for my OS something similar to Windows DLL, how do I go about letting other programs and kernel code use these modules without having to link them, which is what I mean by loadable. The reason is that I want to be able to create parts of the core OS that are not part of the actual kernel, but can be loaded later on when created and used as normal.
What I dont understand is how to call a procedure from one of these modules when the actual name of the procedure is lost at compile time, do I have to keep track of the addresses of these procedures and jump to that address to use the procedure? any help is appreciated.
Thanks.
Loadable Modules...
Re:Loadable Modules...
In your module file, provide a list of names and function addresses. When the kernel wants to call a function it looks up the name of the function and calls its address. Read up on formats such as COFF, ELF and PE; they all provide this functionality automatically (a COFF symbol table is probably the simplest way of doing it).
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Loadable Modules...
rule #1 : your core kernel should not need functions from modules but be self-consistent.
rule #2 : your core kernel must keep a kind of "symbols table" where functions names from modules are registered (i.e. "vfat_alloc_sectors" -> 0x12345678)
rule #3 : your modules files must include informations about the functions they export (i.e. what they will write to the symbol table) and what functions they import from other modules (i.e. a list of (function name, (list of places where the address is to be stored)).
The module loader will be responsible to resolve names for importation from the symbols table, store the values at each requested address, and then write the exported symbols to the table. Another wanted feature is tracking the modules dependencies and automatically remove the symbols from the table when their "owner" is removed.
This is the biggest part of my own O.S. (see KDS tutorial), but i admit i made it very high-level ...
good luck for your mod loader
rule #2 : your core kernel must keep a kind of "symbols table" where functions names from modules are registered (i.e. "vfat_alloc_sectors" -> 0x12345678)
rule #3 : your modules files must include informations about the functions they export (i.e. what they will write to the symbol table) and what functions they import from other modules (i.e. a list of (function name, (list of places where the address is to be stored)).
The module loader will be responsible to resolve names for importation from the symbols table, store the values at each requested address, and then write the exported symbols to the table. Another wanted feature is tracking the modules dependencies and automatically remove the symbols from the table when their "owner" is removed.
This is the biggest part of my own O.S. (see KDS tutorial), but i admit i made it very high-level ...
good luck for your mod loader