Calling Functions in Drivers/Libarys

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
xarnze
Posts: 19
Joined: Thu Nov 02, 2006 4:45 pm
Location: United Kingdom
Contact:

Calling Functions in Drivers/Libarys

Post by xarnze »

I can get grub to load in drivers at boot time but how do i then call a function from that driver without knowing the exact location of the code in memory? Could i link it directly into the kernel if so how would i do this, i know i have to merge symbol tables and relocate it but how would i go about this?

and would the procedure be any differnt for a dynamic libary that had been loaded by a executable?
Andrew275
Member
Member
Posts: 30
Joined: Tue Feb 27, 2007 2:29 pm
Contact:

Post by Andrew275 »

Dynamic linking for drivers and usermode libraries is quite similar, at least the way I implemented it. It's not an easy task though. If you're using ELF, try to read through the ELF specification. There's a lot of stuff you're going to have to become familiar with, and the spec isn't exactly written in a way that will make it easy. Expect to be frustrated for a while. It's worth it though; getting loadable libraries and loadable drivers working were two of the most exciting accomplishments I've had so far in my OS.

Disregard if you've already gotten usermode linking working, of course. :)

When I build my kernel, I produce two files. One is a static executable, which is what actually gets loaded and run as the kernel. The other is a dynamic library, whose sole purpose is to link drivers against. Then, when my kernel loads a driver, it reads through its symbol table. I then look up each of those symbols in the currently running kernel, and patch the driver's symbol table to point to those functions. Once this is complete, I use the information I've read to build a pointer table that points to specific driver functions (i.e. find out where the InitializeDriver function lives, and then call it).
My operating system: Desktop OS
Content management system/forum: Deluxe Portal
Post Reply