diff --git a/src/kern/cpu.zig b/src/kern/cpu.zig index bf49b74..33bc898 100644 --- a/src/kern/cpu.zig +++ b/src/kern/cpu.zig @@ -28,18 +28,13 @@ pub fn current() u32 { return id.local().*; } -comptime { - if (!@hasDecl(ki.impl, "percpu_ptr")) @compileError("impl must provide percpu_ptr()"); - if (!@hasDecl(ki.impl, "percpu_ptr_other")) @compileError("impl must provide percpu_ptr_other()"); -} - /// Wraps around CPU-local data. pub fn CpuLocal(comptime T: type, comptime init: T) type { return struct { var storage: T linksection(".data.percpu") = init; /// Return a pointer to local CPU data. - pub fn local() @TypeOf(ki.impl.percpu_ptr(&storage)) { + pub fn local() *T { return ki.impl.percpu_ptr(&storage); } diff --git a/src/kern/ipl.zig b/src/kern/ipl.zig index 0b0f1de..f0e6767 100644 --- a/src/kern/ipl.zig +++ b/src/kern/ipl.zig @@ -83,10 +83,6 @@ pub fn lower(new: Ipl) void { } } -comptime { - if (!@hasDecl(ki.impl, "set_hardware_ipl")) @compileError("impl must provide set_hardware_ipl()"); -} - /// Set the hardware IPL to `new`. pub fn set_hardware(new: Ipl) Ipl { var cpu = percpu.local(); diff --git a/src/kern/private.zig b/src/kern/private.zig index 7ca18d1..4897d2c 100644 --- a/src/kern/private.zig +++ b/src/kern/private.zig @@ -1,6 +1,7 @@ +const r = @import("root"); const std = @import("std"); +const rtl = @import("rtl"); const config = @import("config"); - const init_mod = @import("init.zig"); pub const impl = switch (config.arch) { @@ -9,6 +10,63 @@ pub const impl = switch (config.arch) { else => @compileError("unsupported architecture"), }; +const ImplSchema = struct { + pub const ThreadContext = struct {}; + + /// Set the hardware interrupt priority level. + pub fn set_hardware_ipl(level: ipl.Ipl) void { + _ = level; + } + + /// Read a per-cpu pointer on another CPU. + pub fn percpu_ptr_other(variable: anytype, id: u32) @TypeOf(variable) { + _ = id; + } + + /// Read a per-cpu pointer on the current CPU. + pub fn percpu_ptr(variable: anytype) @TypeOf(variable) {} + + /// Send a rescheduling inter-processor interrupt (IPI) + /// on the target CPU. + pub fn send_resched_ipi(target: u32) void { + _ = target; + } + + /// Send a TLB shootdown IPI on the target CPU. + pub fn send_tlb_ipi(target: u32) void { + _ = target; + } + + /// Flush the entire TLB on the current CPU. + pub fn flush_full_tlb() void {} + + /// Flush the TLB entry matching `va` on the current CPU. + pub fn flush_tlb(va: r.VAddr) void { + _ = va; + } + + /// Enable interrupts. + pub fn enable_interrupts() void {} + + /// Disable interrupts. + /// Return the previous interrupt state. + pub fn disable_interrupts() bool { + return false; + } + + /// Restore the state of interrupts. + pub fn restore_interrupts(state: bool) void { + _ = state; + } + + /// Implementation-defined early initialization. + pub fn early_init() void {} +}; + +comptime { + rtl.assert_interface(impl, ImplSchema); +} + pub const init = init_mod.init; // === Exported Modules === diff --git a/src/kern/sched.zig b/src/kern/sched.zig index 02dbdfa..8e0ad46 100644 --- a/src/kern/sched.zig +++ b/src/kern/sched.zig @@ -88,10 +88,6 @@ const r = @import("root"); const ke = r.ke; const ki = ke.private; -comptime { - if (!@hasDecl(ki.impl, "send_resched_ipi")) @compileError("impl must provide send_resched_ipi"); -} - const runqueues_n = 64; const interactivity_threshold = 30; const scaling_factor = 50; diff --git a/src/kern/shootdown.zig b/src/kern/shootdown.zig index 3a29da1..479620b 100644 --- a/src/kern/shootdown.zig +++ b/src/kern/shootdown.zig @@ -8,12 +8,6 @@ const ke = r.ke; const ki = ke.private; const mm = r.mm; -comptime { - if (!@hasDecl(ki.impl, "send_tlb_ipi")) @compileError("impl must provide send_tlb_ipi"); - if (!@hasDecl(ki.impl, "flush_full_tlb")) @compileError("impl must provide flush_full_tlb"); - if (!@hasDecl(ki.impl, "flush_tlb")) @compileError("impl must provide flush_tlb"); -} - /// Structure representing a single shootdown request. pub const ShootdownState = struct { /// State of the request. diff --git a/src/kern/thread.zig b/src/kern/thread.zig index 9f9b3b0..5eb70d5 100644 --- a/src/kern/thread.zig +++ b/src/kern/thread.zig @@ -167,8 +167,3 @@ pub const Thread = struct { return self.priority >= Priority.low_interactive and self.priority <= Priority.high_interactive; } }; - -comptime { - if (!@hasDecl(ki.impl, "ThreadContext")) @compileError("impl must provide ThreadContext"); - if (!@hasDecl(ki.impl.ThreadContext, "init")) @compileError("ThreadContext must have init()"); -}