I'm reworking my OS (which is based on Borealis by Chris Giese) and have come upon a question that will decide how I write a fair amount of the OS.
Chris' LibC functions that use the kernel (eg, read, write) use an interrupt (with parameters given and received).
I'm wondering if instead of using an interrupt all the time, would it be faster to have the interrupt called once, save the address of the required function, and from then on use that function call (which is in kernel space.)
Would this be faster, or better?
Just a note that this is a 32-Bit Protected Mode OS, and that the interrupt looks at EAX, and decides which function to call/return using a switch statement.
Thus to me, it would seem that using a function call instead would be quicker, and such functions in libc would be pointers which would change their own address, eg:
Code: Select all
/* Simple example */
int (*close) (unsigned handle)
{
int (*fn_address)(unsigned handle);
/* Call int SYSCALL_INT, with EAX being SYS_CLOSE_ADDRESS */
/* Address of kernel function close will be moved to fn_address */
__asm__ __volatile__(
"int %1\n"
: "=a"(fn_address)
: "i"(SYSCALL_INT), "a"(SYS_CLOSE_ADDRESS));
close = fn_address;
return close(handle);
}