diff options
author | Himbeer <himbeer@disroot.org> | 2024-07-30 12:52:53 +0200 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2024-07-30 12:52:53 +0200 |
commit | f8db981dfc4aa0ed90c81979a2487934ea3edbe2 (patch) | |
tree | b8a447df221c5ea65782ae3ddb0da6bfc0bd0963 | |
parent | 270c8f02867bf959fa86a44fcb76bb0680571695 (diff) |
syscall: Provide HWI devices by kind
Closes #59.
-rw-r--r-- | src/lib/syscall.zig | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/syscall.zig b/src/lib/syscall.zig index 8d42e7a..b618979 100644 --- a/src/lib/syscall.zig +++ b/src/lib/syscall.zig @@ -5,6 +5,7 @@ const std = @import("std"); const Console = @import("Console.zig"); const TrapFrame = @import("TrapFrame.zig"); +const hwinfo = @import("hwinfo.zig"); const mem = @import("mem.zig"); const paging = @import("paging.zig"); const process = @import("process.zig"); @@ -29,6 +30,7 @@ pub fn handler(proc: *process.Info, trap_frame: *TrapFrame) !void { 100005 => trap_frame.setReturnValue(processId(proc)), 100006 => trap_frame.setReturnValue(threadId(proc)), 100007 => trap_frame.setReturnValue(rawUserinit(trap_frame)), + 100008 => trap_frame.setReturnValue(devicesByKind(trap_frame)), else => return HandleError.UnknownSyscall, } } @@ -147,3 +149,21 @@ fn rawUserinit(trap_frame: *const TrapFrame) usize { ptr.* = userinit.tarball; return userinit.tarball.len; } + +// devicesByKind(kind: hwinfo.DevKind, devices: [*]hwinfo.Dev, len: usize) !usize +fn devicesByKind(trap_frame: *const TrapFrame) !usize { + const kind: hwinfo.DevKind = @enumFromInt(trap_frame.general_purpose_registers[10]); + const devices: [*]hwinfo.Dev = @ptrFromInt(trap_frame.general_purpose_registers[11]); + const len = trap_frame.general_purpose_registers[12]; + + var i: usize = 0; + var devs = try hwinfo.byKind(kind); + while (try devs.next()) |dev| { + if (i >= len) break; + + devices[i] = dev; + i += 1; + } + + return i; +} |