aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-07-27 16:59:53 +0200
committerHimbeer <himbeer@disroot.org>2024-07-27 16:59:53 +0200
commit599fde1a25b9990c5758ddb3e1e5e0a44de3315e (patch)
tree0fd492062c215bcce21aec6f2e35129ebf080696
parentd38a787c3b4cea11b5386b5cb5143c77c042656f (diff)
Move sysexchange frame return logic to trap.Frame methods
-rw-r--r--src/lib/process.zig1
-rw-r--r--src/lib/syscall.zig14
-rw-r--r--src/lib/sysexchange.zig34
-rw-r--r--src/lib/trap.zig27
4 files changed, 33 insertions, 43 deletions
diff --git a/src/lib/process.zig b/src/lib/process.zig
index 70ac9a2..8aaf972 100644
--- a/src/lib/process.zig
+++ b/src/lib/process.zig
@@ -8,7 +8,6 @@ const std = @import("std");
const instructions = @import("instructions.zig");
const paging = @import("paging.zig");
const rethooks = @import("rethooks.zig");
-const sysexchange = @import("sysexchange.zig");
const time = @import("sbi/time.zig");
const trap = @import("trap.zig");
diff --git a/src/lib/syscall.zig b/src/lib/syscall.zig
index 4fed39b..db2136f 100644
--- a/src/lib/syscall.zig
+++ b/src/lib/syscall.zig
@@ -8,7 +8,6 @@ const instructions = @import("instructions.zig");
const mem = @import("mem.zig");
const paging = @import("paging.zig");
const process = @import("process.zig");
-const sysexchange = @import("sysexchange.zig");
const trap = @import("trap.zig");
pub const Error = error{
@@ -20,14 +19,13 @@ pub const HandleError = error{
};
pub fn handler(proc: *process.Info, trap_frame: *trap.Frame) !void {
- const ret = sysexchange.frameReturn;
switch (trap_frame.general_purpose_registers[17]) {
- 100000 => ret(trap_frame, uprint(trap_frame)),
- 100001 => ret(trap_frame, launch(trap_frame)),
- 100002 => ret(trap_frame, end(proc)),
- 100003 => ret(trap_frame, terminate(proc, trap_frame)),
- 100004 => ret(trap_frame, processId(proc)),
- 100005 => ret(trap_frame, threadId(proc)),
+ 100000 => trap_frame.setReturnValue(uprint(trap_frame)),
+ 100001 => trap_frame.setReturnValue(launch(trap_frame)),
+ 100002 => trap_frame.setReturnValue(end(proc)),
+ 100003 => trap_frame.setReturnValue(terminate(proc, trap_frame)),
+ 100004 => trap_frame.setReturnValue(processId(proc)),
+ 100005 => trap_frame.setReturnValue(threadId(proc)),
else => return HandleError.UnknownSyscall,
}
}
diff --git a/src/lib/sysexchange.zig b/src/lib/sysexchange.zig
deleted file mode 100644
index dd96f3b..0000000
--- a/src/lib/sysexchange.zig
+++ /dev/null
@@ -1,34 +0,0 @@
-// SPDX-FileCopyrightText: 2024 Himbeer <himbeer@disroot.org>
-//
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-const std = @import("std");
-
-const trap = @import("trap.zig");
-
-pub fn frameReturn(trap_frame: *trap.Frame, value: anytype) void {
- switch (@typeInfo(@TypeOf(value))) {
- .ErrorUnion => returnErrorUnion(trap_frame, value),
- .ErrorSet => returnError(trap_frame, value),
- else => returnValue(trap_frame, value),
- }
-}
-
-fn returnErrorUnion(trap_frame: *trap.Frame, error_union: anytype) void {
- if (error_union) |value| {
- returnValue(trap_frame, value);
- } else |err| {
- returnError(trap_frame, err);
- }
-}
-
-fn returnError(trap_frame: *trap.Frame, err: anyerror) void {
- trap_frame.general_purpose_registers[11] = @intFromError(err);
-}
-
-fn returnValue(trap_frame: *trap.Frame, value: anytype) void {
- trap_frame.general_purpose_registers[11] = 0;
- if (@typeInfo(@TypeOf(value)) != .Void) {
- trap_frame.general_purpose_registers[10] = @bitCast(value);
- }
-}
diff --git a/src/lib/trap.zig b/src/lib/trap.zig
index 4460cfd..99db8ba 100644
--- a/src/lib/trap.zig
+++ b/src/lib/trap.zig
@@ -8,4 +8,31 @@ pub const Frame = extern struct {
satp: usize, // Offset: 512
stack_pointer: *allowzero u8, // Offset: 520
hart_id: usize, // Offset: 528
+
+ pub fn setReturnValue(self: *Frame, value: anytype) void {
+ switch (@typeInfo(@TypeOf(value))) {
+ .ErrorUnion => self.returnErrorUnion(value),
+ .ErrorSet => self.returnError(value),
+ else => self.returnValue(value),
+ }
+ }
+
+ fn returnErrorUnion(self: *Frame, error_union: anytype) void {
+ if (error_union) |value| {
+ self.returnValue(value);
+ } else |err| {
+ self.returnError(err);
+ }
+ }
+
+ fn returnError(self: *Frame, err: anyerror) void {
+ self.general_purpose_registers[11] = @intFromError(err);
+ }
+
+ fn returnValue(self: *Frame, value: anytype) void {
+ self.general_purpose_registers[11] = 0;
+ if (@typeInfo(@TypeOf(value)) != .Void) {
+ self.general_purpose_registers[10] = @bitCast(value);
+ }
+ }
};