commit 948ebcb66aa26133c806c2cddd7adcbae22f66e9
parent 445e576f33ebe6b1b89a221691935eb6c6374001
Author: Brian Swetland <swetland@frotz.net>
Date: Fri, 3 Jan 2014 16:28:12 -0800
handle syscall arguments in 64bit mode
The AMD64 ABI passes the first six arguments in the registers
RDI, RSI, RDX, RCX, R8, R9, not on the stack like the IA32
ABI does.
Diffstat:
1 file changed, 30 insertions(+), 0 deletions(-)
diff --git a/kernel/syscall.c b/kernel/syscall.c
@@ -50,6 +50,35 @@ fetchstr(uintp addr, char **pp)
return -1;
}
+#if X64
+// arguments passed in registers on x64
+static uintp
+fetcharg(int n)
+{
+ switch (n) {
+ case 0: return proc->tf->rdi;
+ case 1: return proc->tf->rsi;
+ case 2: return proc->tf->rdx;
+ case 3: return proc->tf->rcx;
+ case 4: return proc->tf->r8;
+ case 5: return proc->tf->r9;
+ }
+}
+
+int
+argint(int n, int *ip)
+{
+ *ip = fetcharg(n);
+ return 0;
+}
+
+int
+arguintp(int n, uintp *ip)
+{
+ *ip = fetcharg(n);
+ return 0;
+}
+#else
// Fetch the nth 32-bit system call argument.
int
argint(int n, int *ip)
@@ -62,6 +91,7 @@ arguintp(int n, uintp *ip)
{
return fetchuintp(proc->tf->esp + sizeof(uintp) + sizeof(uintp)*n, ip);
}
+#endif
// Fetch the nth word-sized system call argument as a pointer
// to a block of memory of size n bytes. Check that the pointer