feat(pl/ke): initial amd64 support

This commit is contained in:
2026-03-28 19:14:17 +01:00
committed by rdmsr
parent 2e82a695e1
commit c6e63ed2bf
18 changed files with 279 additions and 87 deletions
-3
View File
@@ -1,3 +0,0 @@
const b = @import("base");
pub fn first_init() linksection(b.init) void {}
+21 -2
View File
@@ -1,6 +1,25 @@
const entry = @import("entry.zig");
const b = @import("base");
const ki = b.ke.private;
pub const first_init = entry.first_init;
pub const name = "AMD64";
pub fn first_init() void {}
pub fn early_init() void {
const impl_cpu = &ki.bootstrap_cpu.impl;
impl_cpu.self_ptr = impl_cpu;
impl_cpu.percpu_offset = 0;
const impl_cpu_ptr = @intFromPtr(impl_cpu);
asm volatile ("wrmsr"
:
: [_] "{eax}" (@as(u32, @intCast(impl_cpu_ptr & 0xFFFFFFFF))),
[_] "{edx}" (@as(u32, @truncate(impl_cpu_ptr >> 32))),
[_] "{ecx}" (0xC000_0101),
);
}
pub fn late_init() void {}
pub fn devices_init() void {}
+31
View File
@@ -0,0 +1,31 @@
const b = @import("base");
const ksyms = @import("ksyms");
const pl = b.pl;
const ke = b.ke;
pub const std_options = b.std_options;
pub const panic = b.panic;
pub const rtl = @import("rtl");
const std = @import("std");
var boot_info: pl.BootInfo = undefined;
export fn kmain() callconv(.c) void {
std.log.info("hello from kernel!", .{});
for (ksyms.ksyms) |sym| {
std.log.info(" 0x{x:0>16} {s}", .{ sym.addr, sym.name });
}
boot_info.memory_map.entry_count = 0;
var cpus: [1]*ke.Cpu = .{&ke.private.bootstrap_cpu};
ke.ncpus = 1;
ke.cpus = &cpus;
ke.private.init(&boot_info);
}
+4
View File
@@ -10,6 +10,10 @@ else if (@hasDecl(config, "CONFIG_ARCH_UM"))
else
@compileError("unsupported architecture");
pub inline fn first_init() void {
return impl.first_init();
}
/// Early platform-specific initialization, called before anything else.
pub inline fn early_init() void {
return impl.early_init();
+1
View File
@@ -1,6 +1,7 @@
const b = @import("base");
pub const std_options = b.std_options;
pub const panic = b.panic;
pub const rtl = @import("rtl");
+2 -2
View File
@@ -27,7 +27,7 @@ pub fn arm_timer(ns: b.Nanoseconds) void {
}, .it_interval = .{ .tv_sec = 0, .tv_nsec = 0 } };
if (c.timer_settime(timerid, 0, &value, null) == -1) {
ke.panic("timer_settime failed", .{});
@panic("timer_settime failed");
}
}
@@ -68,6 +68,6 @@ pub fn init_cpu() void {
sev._sigev_un._tid = linux.gettid();
if (c.timer_create(c.CLOCK_MONOTONIC, &sev, &timerid) == -1) {
ke.panic("timer_create failed", .{});
@panic("timer_create failed");
}
}