Hello,
I am just about implementing some kernel services now, using software interrupt 0x30. The idea is to build this hand in hand with my libc and basic API.
When servicing the interrupt, I use eax as a function selector, which seems fairly standard and I can see 2 main ways to interpret which function I am calling:
1. A massive switch() statement calling functions or doing the actual implementation as necessary.
2. An array of function pointers, so that eax is simply an index in to this array, which is kmalloc'd and filled at boot-time.
My gut feeling is that the second of these implementations should be both neater and faster. Any thoughts?
Cheers,
Adam
Providing Kernel Services
- Combuster
- 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:
A decent C compiler will create a jump table for a large switch statement automatically. And since it doesnt involve another function call, a switch statement is under these conditions faster than using function pointers.
The disadvantages of the switch statement is that its _huge_, and you can not dynamically change entries, which you can with function pointers.
If you want both the advantages, You'll have to get down to assembly level.
Regarding the third option: if you want you can save your custom jumptable in the data area: no need for extra memory management when you'll always be using it.
As for the down-to-earth remark: why bother with ~4 cycles for every kernel call?
The disadvantages of the switch statement is that its _huge_, and you can not dynamically change entries, which you can with function pointers.
If you want both the advantages, You'll have to get down to assembly level.
Regarding the third option: if you want you can save your custom jumptable in the data area: no need for extra memory management when you'll always be using it.
As for the down-to-earth remark: why bother with ~4 cycles for every kernel call?