From 73a32d6c6aade98be73bcbcc8c73ada96bb2204f Mon Sep 17 00:00:00 2001 From: Talon Kettuso <105325988+TalonFloof@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:29:13 -0600 Subject: [PATCH] just some changes --- kobold/hal/x86_64/timer.zig | 9 ++++++--- kobold/kernel/{semaphore.zig => eventqueue.zig} | 2 +- kobold/kernel/main.zig | 2 +- kobold/kernel/thread.zig | 2 +- kobold/perLib/spinlock.zig | 3 ++- 5 files changed, 11 insertions(+), 7 deletions(-) rename kobold/kernel/{semaphore.zig => eventqueue.zig} (90%) diff --git a/kobold/hal/x86_64/timer.zig b/kobold/hal/x86_64/timer.zig index c48658c..9ae957b 100644 --- a/kobold/hal/x86_64/timer.zig +++ b/kobold/hal/x86_64/timer.zig @@ -47,7 +47,6 @@ pub fn init() void { apic.write(0x320, 0x10000); const count = 0xffffffff - apic.read(0x390); ticksPerSecond = count; - std.log.info("{} APIC Ticks/s", .{count}); } else { std.log.info("PIT @ 100 Hz for APIC Timer Calibration", .{}); var speakerControlByte = io.inb(0x61); @@ -68,8 +67,8 @@ pub fn init() void { apic.write(0x320, 0x10000); const count = 0xffffffff - apic.read(0x390); ticksPerSecond = count * 100; - std.log.info("{} APIC Ticks/s", .{count * 100}); } + std.log.info("{} APIC Ticks/s", .{ticksPerSecond}); } apic.write(0x3e0, 0xb); apic.write(0x320, 0x20); @@ -78,7 +77,11 @@ pub fn init() void { pub fn setDeadline(microsecs: u64) void { const t: u64 = @intFromFloat(@as(f64, @floatFromInt(ticksPerSecond)) * (@as(f64, @floatFromInt(microsecs)) / 1000000.0)); - apic.write(0x380, t); + if(t > 0xffffffff) { + apic.write(0x380,0xffffffff); + } else { + apic.write(0x380, t); + } } pub fn getRemainingUs() u64 { diff --git a/kobold/kernel/semaphore.zig b/kobold/kernel/eventqueue.zig similarity index 90% rename from kobold/kernel/semaphore.zig rename to kobold/kernel/eventqueue.zig index d9a39a7..0e3dda2 100644 --- a/kobold/kernel/semaphore.zig +++ b/kobold/kernel/eventqueue.zig @@ -1,7 +1,7 @@ const std = @import("std"); const thread = @import("thread.zig"); -pub const Semaphore = struct { +pub const EventQueue = struct { semID: i64 = 0, // 0 id semaphores are special anonymous semaphores used in internal kernel structures like ports teamID: i64, name: [32]u8 = [_]u8{0} ** 32, diff --git a/kobold/kernel/main.zig b/kobold/kernel/main.zig index 445638b..a26fbf0 100644 --- a/kobold/kernel/main.zig +++ b/kobold/kernel/main.zig @@ -56,7 +56,7 @@ pub fn panic(msg: []const u8, stacktrace: ?*std.builtin.StackTrace, retAddr: ?us pub export fn KoboldInit() void { _ = hal.AlignDown(u32, 0, 4096); // Prevents release builds from failing - std.log.info("Schedling Started", .{}); + std.log.info("Scheduling Started", .{}); while (true) { hal.arch.waitForInt(); } diff --git a/kobold/kernel/thread.zig b/kobold/kernel/thread.zig index bf086cd..c0c7ab1 100644 --- a/kobold/kernel/thread.zig +++ b/kobold/kernel/thread.zig @@ -20,7 +20,7 @@ pub const Thread = struct { semaphoreNode: ThreadList.Node, team: *team.Team, name: [32]u8 = [_]u8{0} ** 32, - state: ThreadState = .Embryo, + state: ThreadState = .Runnable, shouldKill: bool = false, priority: usize = 16, kstack: []u8, diff --git a/kobold/perLib/spinlock.zig b/kobold/perLib/spinlock.zig index 197cf3a..5bd8c06 100644 --- a/kobold/perLib/spinlock.zig +++ b/kobold/perLib/spinlock.zig @@ -12,7 +12,8 @@ pub const Spinlock = enum(u8) { } std.atomic.spinLoopHint(); } - @panic("Deadlock detected"); + std.log.err("Deadlock @ 0x{x}", .{@intFromPtr(spinlock)}); + @panic("Deadlock"); } pub inline fn release(spinlock: *volatile Spinlock) void {