Page 1 of 1

Device init

Posted: Sun Mar 18, 2007 11:15 am
by salil_bhagurkar
I have my kernel in which after all the baisic init it does the hardware init like fdc,hdd,lpt etc.. Whenever i write code for a new hardware i have to make an entry into the inits if that code requires an init. Though not an optimal solution and not required i came up with a solution for this problem.

I defined a macro called DEVICE_INIT that declares a global string "devinit" earlier to the init function of the device. My init manager searches for the string in the kernel on physical memory and when it finds it computes the init function pointer by adding 8 to the string pointer (length of "devinit" + null). It then calls the function.

I know this is a stupid idea and it never worked except for some cases where no local string inside the function was declared. Could there be any other alternative solution?

Posted: Sun Mar 18, 2007 4:10 pm
by Combuster
put a function pointer into a separate section of your binary, like .ctors

Posted: Tue Mar 20, 2007 6:03 pm
by iammisc
you should have some way for the kernel to be able to read in real executable format files which contain symbol info. then just search for something like "device_init" in the symbol table and call the address specified by the executable file. Using this method you can easily create many kernel<->device callbacks.