aboutsummaryrefslogtreecommitdiff
path: root/src/interrupts.zig
diff options
context:
space:
mode:
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,