aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-07-31 13:49:19 +0200
committerHimbeer <himbeer@disroot.org>2024-07-31 13:50:21 +0200
commit2fa9f57e125912672ec24514d9cc8e71f9e0fea7 (patch)
tree48e73b8ad17469ec62e672d3e0661c8a50c36f13 /src
parent710185dfab1e104e799ed23d9ab5ecb7f77f9190 (diff)
root: Add basic internal syscall helper
Diffstat (limited to 'src')
-rw-r--r--src/root.zig40
1 files changed, 32 insertions, 8 deletions
diff --git a/src/root.zig b/src/root.zig
index 636452c..7a8ce3a 100644
--- a/src/root.zig
+++ b/src/root.zig
@@ -1,14 +1,38 @@
-// SPDX-FileCopyrightText: Zig contributors
+// SPDX-FileCopyrightText: 2024 Himbeer <himbeer@disroot.org>
//
-// SPDX-License-Identifier: MIT
+// SPDX-License-Identifier: AGPL-3.0-or-later
const std = @import("std");
-const testing = std.testing;
-export fn add(a: i32, b: i32) i32 {
- return a + b;
-}
+pub const max_args = 6;
+
+const Result = struct {
+ value: usize,
+ error_code: usize,
+};
+
+fn ecall(number: usize, args: anytype) Result {
+ comptime var registers = [max_args]usize{0};
+ inline for (args, 0..) |arg, i| {
+ if (i >= max_args) @compileError("Too many arguments to system call");
+ registers[i] = @bitCast(arg);
+ }
-test "basic add functionality" {
- try testing.expect(add(3, 7) == 10);
+ var result: Result = undefined;
+ asm volatile (
+ \\ ecall
+ \\ sw a0, 0(%[value])
+ \\ sw a1, 0(%[error_code])
+ :
+ : [value] "r" (&result.value),
+ [error_code] "r" (&result.error_code),
+ [a0] "{a0}" (registers[0]),
+ [a1] "{a1}" (registers[1]),
+ [a2] "{a2}" (registers[2]),
+ [a3] "{a3}" (registers[3]),
+ [a4] "{a4}" (registers[4]),
+ [a5] "{a5}" (registers[5]),
+ [number] "{a7}" (number),
+ );
+ return result;
}