From cf04ba62e86c19f7eb59bb9abfdd44dfdbc7edb8 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Sun, 5 Nov 2023 10:40:12 +0900 Subject: [PATCH] syscall: Change x86-64 syscall register ABI --- base/usr/include/sys/uregs.h | 8 ++++---- base/usr/include/syscall.h | 13 ++++++++----- kernel/arch/x86_64/user.c | 8 ++++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/base/usr/include/sys/uregs.h b/base/usr/include/sys/uregs.h index 31498bc9..f55c2dc3 100644 --- a/base/usr/include/sys/uregs.h +++ b/base/usr/include/sys/uregs.h @@ -9,11 +9,11 @@ _Begin_C_Header # include # define uregs_syscall_result(r) ((r)->rax) # define uregs_syscall_num(r) ((r)->rax) -# define uregs_syscall_arg1(r) ((r)->rbx) -# define uregs_syscall_arg2(r) ((r)->rcx) +# define uregs_syscall_arg1(r) ((r)->rdi) +# define uregs_syscall_arg2(r) ((r)->rsi) # define uregs_syscall_arg3(r) ((r)->rdx) -# define uregs_syscall_arg4(r) ((r)->rsi) -# define uregs_syscall_arg5(r) ((r)->rdi) +# define uregs_syscall_arg4(r) ((r)->r10) +# define uregs_syscall_arg5(r) ((r)->r8) # define uregs_ip(r) ((r)->rip) # define uregs_bp(r) ((r)->rbp) # define UREGS_FMT \ diff --git a/base/usr/include/syscall.h b/base/usr/include/syscall.h index 2585bb83..f13d9340 100644 --- a/base/usr/include/syscall.h +++ b/base/usr/include/syscall.h @@ -24,7 +24,7 @@ _Begin_C_Header long syscall_##fn(P1 p1) { \ long __res = num; __asm__ __volatile__("int $0x7F" \ : "=a" (__res) \ - : "a" (__res), "b" ((long)(p1))); \ + : "a" (__res), "D" ((long)(p1))); \ return __res; \ } @@ -32,7 +32,7 @@ _Begin_C_Header long syscall_##fn(P1 p1, P2 p2) { \ long __res = num; __asm__ __volatile__("int $0x7F" \ : "=a" (__res) \ - : "a" (__res), "b" ((long)(p1)), "c"((long)(p2))); \ + : "a" (__res), "D" ((long)(p1)), "S"((long)(p2))); \ return __res; \ } @@ -40,23 +40,26 @@ _Begin_C_Header long syscall_##fn(P1 p1, P2 p2, P3 p3) { \ long __res = num; __asm__ __volatile__("int $0x7F" \ : "=a" (__res) \ - : "a" (__res), "b" ((long)(p1)), "c"((long)(p2)), "d"((long)(p3))); \ + : "a" (__res), "D" ((long)(p1)), "S"((long)(p2)), "d"((long)(p3))); \ return __res; \ } #define DEFN_SYSCALL4(fn, num, P1, P2, P3, P4) \ long syscall_##fn(P1 p1, P2 p2, P3 p3, P4 p4) { \ + register long p4_ __asm__("r10") = (long)p4; \ long __res = num; __asm__ __volatile__("int $0x7F" \ : "=a" (__res) \ - : "a" (__res), "b" ((long)(p1)), "c"((long)(p2)), "d"((long)(p3)), "S"((long)(p4))); \ + : "a" (__res), "D" ((long)(p1)), "S"((long)(p2)), "d"((long)(p3)), "r"((long)(p4_))); \ return __res; \ } #define DEFN_SYSCALL5(fn, num, P1, P2, P3, P4, P5) \ long syscall_##fn(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { \ + register long p4_ __asm__("r10") = (long)p4; \ + register long p5_ __asm__("r8") = (long)p5; \ long __res = num; __asm__ __volatile__("int $0x7F" \ : "=a" (__res) \ - : "a" (__res), "b" ((long)(p1)), "c"((long)(p2)), "d"((long)(p3)), "S"((long)(p4)), "D"((long)(p5))); \ + : "a" (__res), "D" ((long)(p1)), "S"((long)(p2)), "d"((long)(p3)), "r"((long)(p4_)), "r"((long)(p5_))); \ return __res; \ } #elif defined(__aarch64__) diff --git a/kernel/arch/x86_64/user.c b/kernel/arch/x86_64/user.c index 880af670..4fe95ea5 100644 --- a/kernel/arch/x86_64/user.c +++ b/kernel/arch/x86_64/user.c @@ -281,10 +281,10 @@ long arch_reboot(void) { /* Syscall parameter accessors */ void arch_syscall_return(struct regs * r, long retval) { r->rax = retval; } long arch_syscall_number(struct regs * r) { return (unsigned long)r->rax; } -long arch_syscall_arg0(struct regs * r) { return r->rbx; } -long arch_syscall_arg1(struct regs * r) { return r->rcx; } +long arch_syscall_arg0(struct regs * r) { return r->rdi; } +long arch_syscall_arg1(struct regs * r) { return r->rsi; } long arch_syscall_arg2(struct regs * r) { return r->rdx; } -long arch_syscall_arg3(struct regs * r) { return r->rsi; } -long arch_syscall_arg4(struct regs * r) { return r->rdi; } +long arch_syscall_arg3(struct regs * r) { return r->r10; } +long arch_syscall_arg4(struct regs * r) { return r->r8; } long arch_stack_pointer(struct regs * r) { return r->rsp; } long arch_user_ip(struct regs * r) { return r->rip; }