1 /* Kyle C. Hale 2011 */
3 #include "syscall_decode.h"
7 /* Because SYSCALL doesn't put a kernel stack in place for us, we have to jump
8 * through some hoops. Linux uses the nifty swapgs instruction to pull
9 * a pointer to its data structures and replace it with the user gs (hence the
10 * name). The problem is that the kernel stack is at a fixed offset from the
11 * kernel gs, but in this module we don't have access to that offset (unless we
12 * can maybe find it through a symbol lookup, but I wanted to keep things
13 * compact). So, this module allocates 2 pages to use as a personal kernel stack.
14 * This should be enough because interrupts are off and since the code is small,
15 * I only expect a few page faults.
18 /* You might be wondering, "he said interrupts are off, but I don't see a cli!"
19 * Well, it's because Linux sets the SFMask MSR such that when SYSCALL
20 * is invoked (how we got here), the IF flag is cleared. The linux SYSCALL
21 * entry point later enables them. We won't bother. It's just asking for trouble.
25 pushq %rdi; /* this is bad, shouldn't be using user-stack, any ideas? */
26 movq state_save_area, %rdi;
28 pushq SYSCALL_ENTRY_OFFSET(%rdi);
30 leaq SYSCALL_ENTRY_OFFSET(%rdi), %rsp; /* create our own little kernel stack*/
32 movq syscall_map, %rsi;
33 leaq (%rsi,%rax,1), %rsi;
36 mov $SYSCALL_DISPATCH_HCALL, %eax;