Page 1 of 1

Syscalls

Posted: Sun Jun 19, 2005 6:24 am
by dc0d32
hey there
what is the difference between an "interrupt" type syscall system and "386 call gate" based syscall system wrt. implementation time and performance? which one is usu. preferred?

thanx

Re:Syscalls

Posted: Sun Jun 19, 2005 6:45 am
by AR
Interrupts are more common, they're more portable across platforms, call gates are faster (according to Brendan at least :) but I'll take his word for it), call gates are created in the GDT are called using a far call, creating GDT entries may feel more fiddily then IDT entries but that's about the only difficulty in implementation.

Re:Syscalls

Posted: Sun Jun 19, 2005 7:23 am
by dc0d32
can Brendan please elaborate this a bit more then?
and one more thing, isn't there a limitation on the number of params passed in the interrupt driven syscall as compared to the call gate with infinite [not literally] args? on the other hand, interrupt driven system's args are in the registers, while those in a call gate system are usu. on the stack. wont that make a speed difference? by the way, what are the number of 'T's will each one [ie a software interupt generation vs. long call to the call gate with all those segment registers and tss validations done by the 386]?
I am really stuck here :'(
thanks.

Re:Syscalls

Posted: Sun Jun 19, 2005 8:14 am
by AR
Call gates can use the stack and the registers at the same time, I imagine that it would be slower copying the stack parameters (unless you treat it like an interrupt and only use general registers), both approaches require reading the TSS and reloading the CS and SS segments. Approximate timings are 20 clocks for an interrupt and somewhere between 10-15 for a call gate (SYSENTER instruction is about 8, SYSCALL instruction is about 5) < All values are approximate and from memory, but the order of efficency is correct.

Re:Syscalls

Posted: Mon Jun 20, 2005 2:01 am
by Pype.Clicker
i'd also add that another advantage of call gates is that they don't necessarily invoke DPL0 code while (iirc) interrupts don't have much choice about this (or is it only for IRQs and exceptions ? )

So basically, if you assume your code should be able to call kernel or user-level emulation library the same way, you might prefer call gates. (that may not be relevant for many of us, anyway)