Page 1 of 1

Calling Functions in Drivers/Libarys

Posted: Wed Jul 11, 2007 12:36 pm
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?

Posted: Wed Jul 11, 2007 1:20 pm
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).