Providing Kernel Services

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
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Providing Kernel Services

Post by AJ »

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
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 »

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? :wink:
"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 ]
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

Combuster wrote:As for the down-to-earth remark: why bother with ~4 cycles for every kernel call? :wink:
4 cycles per kernel call, for applications performing a few thousand a second, running for years and on millions of computers... yep, that's at least billions of cycles saved each second.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Thanks for the ideas. I'm going to play around with the kernel code now and see what happens :)

Adam
Post Reply