From e8a1df103cc28419dd7d4439c0b1d1739d110f78 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Tue, 9 Jul 2024 22:12:27 +0300 Subject: start working on tests + Current setup will likely not last long, just a stopgap until I figure out how I want to build each testcase etc. Probably dir based, but I'll probably add some scripts that generate the build rules for each test case (or binary?). Also, should probably put ouput files in a build directory and keep the source clean, but again, good enough for now. Will have to start implementing more extensive tests, and probably come up with some way to compare textual output etc. --- tests/common/arch/riscv64/syscall.h | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/common/arch/riscv64/syscall.h (limited to 'tests/common/arch/riscv64/syscall.h') diff --git a/tests/common/arch/riscv64/syscall.h b/tests/common/arch/riscv64/syscall.h new file mode 100644 index 0000000..aafda82 --- /dev/null +++ b/tests/common/arch/riscv64/syscall.h @@ -0,0 +1,50 @@ +#ifndef KMI_TESTS_ARCH_RISCV64_SYSCALL_H +#define KMI_TESTS_ARCH_RISCV64_SYSCALL_H + +#include +#include + +static inline struct sys_ret syscall(size_t n, + long arg0, long arg1, long arg2, long arg3, + long arg4, + long arg5) +{ + register long a0 __asm__ ("a0") = arg0; + register long a1 __asm__ ("a1") = arg1; + register long a2 __asm__ ("a2") = arg2; + register long a3 __asm__ ("a3") = arg3; + register long a4 __asm__ ("a4") = arg4; + register long a5 __asm__ ("a5") = arg5; + +#define OUTPUTS "+r" (a0), "=r" (a1), "=r" (a2), "=r" (a3), "=r" (a4), "=r" (a5) + + if (n == 1) + __asm__ volatile ("ecall" : OUTPUTS : "r" (a0)); + + else if (n == 2) + __asm__ volatile ("ecall" : OUTPUTS : "r" (a0), "r" (a1)); + + else if (n == 3) + __asm__ volatile ("ecall" : OUTPUTS : "r" (a0), "r" (a1), + "r" (a2)); + + else if (n == 4) + __asm__ volatile ("ecall" : OUTPUTS + : "r" (a0), "r" (a1), "r" (a2), "r" (a3)); + + else if (n == 5) + __asm__ volatile ("ecall" : OUTPUTS + : "r" (a0), "r" (a1), "r" (a2), "r" (a3), + "r" (a4)); + + else if (n == 6) + __asm__ volatile ("ecall" : OUTPUTS + : "r" (a0), "r" (a1), "r" (a2), "r" (a3), + "r" (a4), "r" (a5)); + +#undef OUTPUTS + + return (struct sys_ret){a0, a1, a2, a3, a4, a5}; +} + +#endif /* KMI_TESTS_ARCH_RISCV64_SYSCALL_H */ -- cgit v1.3