From: Kasper V. L. <ve...@da...> - 2000-02-17 14:00:50
|
> > We still need to work on PCT (protected control transfer) - anyone? > > [snip] I've lost my Insight CD (damm!) but can you explain how the upcalling works? I've only used TSS before. > > popl %eax > popl %eax > movl %cr3,%eax > iret > > I think that's the code (from memory), it sets up the page tables but does the iret pop stuff off the argument stack? And does that drop the privelage level? The code is correct. It doesn't set up any page tables, but it does change the page directory. The assembly code you've included in your posting is the implementation of a function with the following prototype: extern void _process_run(uint32_t cr3, uint32_t eip, uint32_t cs, uint32_t eflags, uint32_t esp, uint32_t ss) __attribute__ ((noreturn)); The compiler will push the arguments from right to left leaving the stack something like this: [...:ss:esp:eflags:cs:eip:cr3:ret] ^ stack top The first instruction (popl %eax) just removes the return address, because we don't need it. The stack is now: [...:ss:esp:eflags:cs:eip:cr3] ^ stack top Next we pop the physical address of the page directory we want to switch to from the stack (popl %eax) and do the context switch. The stack now looks something like: [...:ss:esp:eflags:cs:eip] ^ stack top When we issue the 'iret' instruction the CPU will remove the eip, cs, and eflags from the stack. The CPU can tell by code segment selector that we're returning to user-level. This will make the CPU pop the ss and esp from the stack as well. We're now running in user-space at address eip with a stack specified by ss:esp. Hope this helps! /Kasper -- ------------------------------------------------------------------- Kasper Verdich Lund, Computer Science Department, Aarhus University Office: 34P.218 | Phone: (+45) 8942 5680 Email: ve...@da... | WWW: http://www.daimi.au.dk/~verdich |