From 23334004a5b28b7543282f9a35d6df59df33ed54 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Mon, 24 Feb 2025 19:18:51 +0100 Subject: [PATCH] init: Calculate the number of threads loaded This will be quite useful in the future. --- system/init/main.zig | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/system/init/main.zig b/system/init/main.zig index f813e78..05121c3 100644 --- a/system/init/main.zig +++ b/system/init/main.zig @@ -25,22 +25,22 @@ fn setTokens() void { syscalls.setTokens(syscalls.getThreadId(), tokens) catch {}; } +fn discoverThreadLimit() u64 { + var pid: u64 = 1; + while (true) { + _ = syscalls.getPriority(pid) catch return (pid - 1); + pid += 1; + } +} + export fn _start(base: u64, address: u64) callconv(.C) noreturn { setTokens(); const mapper = vm.MemoryMapper.create(.{ .address = address }, base); + _ = mapper; - syscalls.print(base); - syscalls.print(address); - syscalls.print(@intFromPtr(mapper.directory)); - - const phys = syscalls.allocFrame() catch { - while (true) {} - }; - - vm.map(&mapper, 0x6000000, .{ .address = phys }, @intFromEnum(vm.Flags.ReadWrite) | @intFromEnum(vm.Flags.User)) catch { - while (true) {} - }; + const threads = discoverThreadLimit(); + syscalls.print(threads); const event_queue = setupKernelRingBuffer(base) catch { while (true) {}