mirror of
https://github.com/rdmsr/zag.git
synced 2026-11-01 15:48:21 +00:00
refactor(amd64): use CPU helpers
This commit is contained in:
+12
-8
@@ -1,5 +1,7 @@
|
|||||||
const b = @import("base");
|
const b = @import("base");
|
||||||
const ke = b.ke;
|
const ke = b.ke;
|
||||||
|
const pl = b.pl;
|
||||||
|
const amd64 = pl.impl;
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
@@ -118,19 +120,21 @@ pub inline fn percpu_ptr(variable: anytype) @TypeOf(variable) {
|
|||||||
return percpu_ptr_for(variable, curcpu());
|
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 {
|
pub inline fn enable_interrupts() void {
|
||||||
asm volatile ("sti");
|
amd64.cpu.sti();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn disable_interrupts() bool {
|
pub inline fn disable_interrupts() bool {
|
||||||
const rflags = asm volatile (
|
const rflags = amd64.cpu.rflags();
|
||||||
\\cli
|
|
||||||
\\pushfq
|
amd64.cpu.cli();
|
||||||
\\popq %[rflags]
|
|
||||||
: [rflags] "=r" (-> usize),
|
|
||||||
);
|
|
||||||
|
|
||||||
return rflags & (1 << 9) != 0;
|
return rflags & (1 << 9) != 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,6 +127,14 @@ pub inline fn hlt() void {
|
|||||||
asm volatile ("hlt");
|
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 {
|
pub inline fn rdtsc() u64 {
|
||||||
var low: u32 = undefined;
|
var low: u32 = undefined;
|
||||||
var high: u32 = undefined;
|
var high: u32 = undefined;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const b = @import("base");
|
const b = @import("base");
|
||||||
const cpu = @import("cpu.zig");
|
pub const cpu = @import("cpu.zig");
|
||||||
const ki = b.ke.private;
|
const ki = b.ke.private;
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user