Re:Call gates
Posted: Wed Aug 11, 2004 9:01 pm
What exactly is the difference between Call Gates and Trap Gates?
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?
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.
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.
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?
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?
Excellent question.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.
Makes sense to me, thanks.Dreamsmith wrote:Excellent question.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.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.
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.