Call gates
Re:Call gates
Hi,
Another difference is that trap gates belong in the IDT, while call gates go in the GDT or LDT.
Cheers,
Brendan
The main difference is that call gates allow parameters to be transferred on the stack (e.g. the top N dwords from the user level stack can be automatically copied to the kernel's stack). This is intended for the calling conventions in high level languages. With trap gates all parameters must be passed in registers.chris wrote: What exactly is the difference between Call Gates and Trap Gates?
Another difference is that trap gates belong in the IDT, while call gates go in the GDT or LDT.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re:Call gates
Actually, that's not true. I use trap gates for my OS system calls, and I pass all parameters on the stack. A more accurate statement would be, call gates automatically copy parameters to the new stack for you, whereas trap gates do not.Brendan wrote:The main difference is that call gates allow parameters to be transferred on the stack (e.g. the top N dwords from the user level stack can be automatically copied to the kernel's stack). This is intended for the calling conventions in high level languages. With trap gates all parameters must be passed in registers.
Re:Call gates
Then why not simply use call gates?Dreamsmith wrote: Actually, that's not true. I use trap gates for my OS system calls, and I pass all parameters on the stack. A more accurate statement would be, call gates automatically copy parameters to the new stack for you, whereas trap gates do not.
Re:Call gates
A new stack? I thought there was only one stack, what?s up with the new stack?
Re:Call gates
Each thread has its own stack, each thread also has its own kernel stack. Using some tricks you can avoid having two stacks (such as my OS will do when it gets to userlevel stuff), but usually you have both a kernel stack and a userlevel stack.RedMan wrote: A new stack? I thought there was only one stack, what?s up with the new stack?
Re:Call gates
Oh, is this something "special magic autmaticlly" or I decide if I?d like to have that by changing the stack pointer by myself?
Re:Call gates
no, this is fully automatic. You specify them all in your TSS (you must have one of those too), and then you always swap them, using Intels methods at least.RedMan wrote: Oh, is this something "special magic autmaticlly" or I decide if I?d like to have that by changing the stack pointer by myself?
In AMD64 this is fixed, you can choose whether to swap the stack, and using SYSCALL/RET the default is NOT to. Upon interrupt one of a number of stacks can be used, all specified in the new-style TSS (which doesn't hold the task info but more the system state, such as the stacks).
Re:Call gates
Excellent question. The answer would be, because trap gates take less space and are faster. Now, if I was using a trap gate, then manually copying the parameters between stacks, that would be silly, might as well use a call gate in that case. But I don't copy parameters between stacks. Instead, I just look at them in place on the old stack. I don't use a call gate because I don't want to waste time copying parameters between stacks when I don't need to.chris wrote:Then why not simply use call gates?Dreamsmith wrote: Actually, that's not true. I use trap gates for my OS system calls, and I pass all parameters on the stack. A more accurate statement would be, call gates automatically copy parameters to the new stack for you, whereas trap gates do not.
Of course, for this to work, you need access to the caller's stack, but for my kernel that's a given. It would only be an issue if you're just routing the request to some user-thread, ala a microkernel approach, in which case you would need to copy the parameters.
Re:Call gates
Stupid question, but how does the CPU know how many arguments to pass to the new stack?
Re:Call gates
You specify that when you create the call gate. Note, varargs is not an option...
Re:Call gates
Makes sense to me, thanks.Dreamsmith wrote:Excellent question. The answer would be, because trap gates take less space and are faster. Now, if I was using a trap gate, then manually copying the parameters between stacks, that would be silly, might as well use a call gate in that case. But I don't copy parameters between stacks. Instead, I just look at them in place on the old stack. I don't use a call gate because I don't want to waste time copying parameters between stacks when I don't need to.chris wrote:Then why not simply use call gates?Dreamsmith wrote: Actually, that's not true. I use trap gates for my OS system calls, and I pass all parameters on the stack. A more accurate statement would be, call gates automatically copy parameters to the new stack for you, whereas trap gates do not.
Of course, for this to work, you need access to the caller's stack, but for my kernel that's a given. It would only be an issue if you're just routing the request to some user-thread, ala a microkernel approach, in which case you would need to copy the parameters.