aboutsummaryrefslogtreecommitdiff
path: root/tests/common/arch
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-09 22:12:27 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-09 22:12:27 +0300
commite8a1df103cc28419dd7d4439c0b1d1739d110f78 (patch)
tree2b4646f262a9008d80ca58fb2ecab2b5bf897873 /tests/common/arch
parent89d7cf197b2cae130565467bdfad5d5ef5fed2dd (diff)
downloadkmi-e8a1df103cc28419dd7d4439c0b1d1739d110f78.tar.gz
kmi-e8a1df103cc28419dd7d4439c0b1d1739d110f78.zip
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.
Diffstat (limited to 'tests/common/arch')
-rw-r--r--tests/common/arch/riscv64/syscall.h50
1 files changed, 50 insertions, 0 deletions
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 <kmi/syscalls.h>
+#include <kmi/attrs.h>
+
+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 */