Device init

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
User avatar
salil_bhagurkar
Member
Member
Posts: 261
Joined: Mon Feb 19, 2007 10:40 am
Location: India

Device init

Post 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?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

put a function pointer into a separate section of your binary, like .ctors
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
iammisc
Member
Member
Posts: 269
Joined: Thu Nov 09, 2006 6:23 pm

Post 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.
Post Reply