refactor(amd64): use CPU helpers

This commit is contained in:
Loïc Grégoire
2026-03-29 21:25:47 -04:00
parent 6efee3aec3
commit 84500e2ff3
3 changed files with 21 additions and 9 deletions
+12 -8
View File
@@ -1,5 +1,7 @@
const b = @import("base");
const ke = b.ke;
const pl = b.pl;
const amd64 = pl.impl;
const std = @import("std");
@@ -118,19 +120,21 @@ pub inline fn percpu_ptr(variable: anytype) @TypeOf(variable) {
return percpu_ptr_for(variable, curcpu());
}
pub inline fn set_hardware_ipl(_: ke.Ipl) void {}
pub inline fn set_hardware_ipl(ipl: ke.Ipl) void {
asm volatile ("mov %[ipl], %%cr8"
:
: [ipl] "r" (@as(u64, @intFromEnum(ipl))),
);
}
pub inline fn enable_interrupts() void {
asm volatile ("sti");
amd64.cpu.sti();
}
pub inline fn disable_interrupts() bool {
const rflags = asm volatile (
\\cli
\\pushfq
\\popq %[rflags]
: [rflags] "=r" (-> usize),
);
const rflags = amd64.cpu.rflags();
amd64.cpu.cli();
return rflags & (1 << 9) != 0;
}
+8
View File
@@ -127,6 +127,14 @@ pub inline fn hlt() void {
asm volatile ("hlt");
}
pub inline fn rflags() u64 {
var flags: u64 = undefined;
asm volatile ("pushfq; pop %[flags]"
: [flags] "=r" (flags),
);
return flags;
}
pub inline fn rdtsc() u64 {
var low: u32 = undefined;
var high: u32 = undefined;
+1 -1
View File
@@ -1,5 +1,5 @@
const b = @import("base");
const cpu = @import("cpu.zig");
pub const cpu = @import("cpu.zig");
const ki = b.ke.private;
const std = @import("std");