aboutsummaryrefslogtreecommitdiff
path: root/src/interrupts.zig
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-05-13 16:52:59 +0200
committerHimbeer <himbeer@disroot.org>2024-05-13 16:52:59 +0200
commit6e3abbeaa324a1d68c806998dbe5cec4e6624c53 (patch)
tree2ea24422da60e08712d6bf739056631eb8dd6291 /src/interrupts.zig
parent17b4d61fb3a3692203b124926ee84fa099fe3e38 (diff)
process: Use simple rotating scheduler
Diffstat (limited to 'src/interrupts.zig')
-rw-r--r--src/interrupts.zig10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/interrupts.zig b/src/interrupts.zig
index a2233aa..de03337 100644
--- a/src/interrupts.zig
+++ b/src/interrupts.zig
@@ -7,6 +7,7 @@ const std = @import("std");
const debug_console = @import("sbi/debug_console.zig");
const instructions = @import("instructions.zig");
const plic = @import("plic.zig");
+const process = @import("process.zig");
const syscall = @import("syscall.zig");
const time = @import("sbi/time.zig");
const trap = @import("trap.zig");
@@ -101,6 +102,7 @@ export fn handleTrap(epc: usize, tval: usize, cause_bits: usize, hart_id: usize,
.supervisor_software => w.print("Hart {d}: Software interrupt\r\n", .{hart_id}) catch while (true) {},
.supervisor_timer => {
time.interruptInSeconds(null, 1) catch while (true) {};
+ schedule() catch while (true) {};
},
.supervisor_external => {
const context: u14 = @intCast(2 * hart_id + 1);
@@ -266,6 +268,14 @@ export fn supervisorTrapVector() align(4) callconv(.Naked) noreturn {
);
}
+fn schedule() noreturn {
+ if (process.next()) |next| {
+ process.switchTo(next);
+ }
+
+ while (true) asm volatile ("wfi");
+}
+
pub fn init() void {
trap_frame = .{
.general_purpose_registers = [_]usize{0} ** 32,