Calling a function to a memory location (API implementation)
Posted: Sun Jan 02, 2011 7:12 pm
Hey everyone,
It's been a long time since I last posted here, but I'm back messing with OS design and I have a question:
I'm writing my kernel in C, and now it's time to implement a simple "API" for third party binaries to use the system functions. My basic idea is that I'll know the address of each of my kernel functions (I'll keep them at the beginning of the code, never changing it). In asm this idea works very well, because I can easily call a a procedure by a memory address (or by a constant which points to that address, to make things easier), but I don't know how to do something similar in C.
In assembly, for example, I'll add some something like this at a specific location of my kernel:
As this piece of code will always be at the same location, I know the the address of each function (os_function_one would be 0x400, os_function_two would be 0x404, etc), so I could simple create a .inc file like the one below and make it available to third party developers, in asm:
This way, the developer would just need to add this include to his project and call the functions, which would be translated into fixed address that would lead to that "call table" at the beginning of my kernel that redirects to the correct place.
It's a simple concept, by I'm having a hard time thinking on how to implement this to use with C development, not asm. Any ideas?
Thanks in advance,
Fergo.
It's been a long time since I last posted here, but I'm back messing with OS design and I have a question:
I'm writing my kernel in C, and now it's time to implement a simple "API" for third party binaries to use the system functions. My basic idea is that I'll know the address of each of my kernel functions (I'll keep them at the beginning of the code, never changing it). In asm this idea works very well, because I can easily call a a procedure by a memory address (or by a constant which points to that address, to make things easier), but I don't know how to do something similar in C.
In assembly, for example, I'll add some something like this at a specific location of my kernel:
Code: Select all
call os_function_one
ret
call os_function_two
ret
call os_function_three
ret
Code: Select all
os_function_one equ 0x0400
os_function_two equ 0x0404
os_function_three equ 0x0408
It's a simple concept, by I'm having a hard time thinking on how to implement this to use with C development, not asm. Any ideas?
Thanks in advance,
Fergo.