refactor: use root instead of base

This commit is contained in:
Loïc Grégoire
2026-04-17 20:58:25 -04:00
parent c68a93b302
commit 1aa6743f43
45 changed files with 199 additions and 229 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
const b = @import("base");
const b = @import("root");
const std = @import("std");
const acpi = b.pl.acpi;
const mm = b.mm;
+1 -1
View File
@@ -1,5 +1,5 @@
const std = @import("std");
const b = @import("base");
const b = @import("root");
const acpi = b.pl.acpi;
pub var madt_ptr: ?*acpi.Madt = null;
+1 -1
View File
@@ -1,4 +1,4 @@
const b = @import("base");
const b = @import("root");
const mm = b.mm;
const pl = b.pl;
const arch = @import("arch");
+1 -1
View File
@@ -1,4 +1,4 @@
const b = @import("base");
const b = @import("root");
const std = @import("std");
const acpi = b.pl.acpi;
const ke = b.ke;
+7 -7
View File
@@ -1,9 +1,9 @@
const std = @import("std");
const amd64 = @import("arch");
const b = @import("base");
const acpi = b.pl.acpi;
const mm = b.mm;
const ke = b.ke;
const r = @import("root");
const acpi = r.pl.acpi;
const mm = r.mm;
const ke = r.ke;
const MadtLapic = extern struct {
header: acpi.MadtEntryHeader,
@@ -79,12 +79,12 @@ const log = std.log.scoped(.apic);
fn xapic_write(register: ApicRegisters, value: u32) void {
const lapic_base = xapic_address orelse return;
b.mmio_write(u32, lapic_base + @intFromEnum(register), value);
r.mmio_write(u32, lapic_base + @intFromEnum(register), value);
}
fn xapic_read(register: ApicRegisters) u32 {
const lapic_base = xapic_address orelse return 0;
return b.mmio_read(u32, lapic_base + @intFromEnum(register));
return r.mmio_read(u32, lapic_base + @intFromEnum(register));
}
fn x2apic_write(register: ApicRegisters, value: u64) void {
@@ -154,7 +154,7 @@ pub fn send_ipi(apic_id: u32, vector: u8, delivery_mode: u8) void {
}
}
pub fn init() linksection(b.init) void {
pub fn init() linksection(r.init) void {
var iter = acpi.madt.iterator();
const cur_cpu_id = get_id();
+7 -7
View File
@@ -1,13 +1,13 @@
const b = @import("base");
const pl = b.pl;
const amd64 = b.arch;
const r = @import("root");
const pl = r.pl;
const amd64 = r.arch;
const std = @import("std");
const tsc = @import("tsc.zig");
const pvclock = @import("pvclock.zig");
const apic = @import("apic.zig");
const smp = @import("smp.zig");
const ki = b.ke.private;
const ki = r.ke.private;
pub const name = "PC";
@@ -15,7 +15,7 @@ const com1 = 0x3F8;
const log = std.log.scoped(.@"amd64/pc");
fn com1_init() linksection(b.init) void {
fn com1_init() linksection(r.init) void {
amd64.outb(com1 + 0x3, 0x80);
amd64.outb(com1 + 0x0, 0x0c);
amd64.outb(com1 + 0x1, 0x00);
@@ -32,7 +32,7 @@ fn com1_write(c: u8) void {
amd64.outb(com1, c);
}
pub fn early_init(boot_info: *pl.BootInfo) linksection(b.init) void {
pub fn early_init(boot_info: *pl.BootInfo) linksection(r.init) void {
com1_init();
const f = amd64.cpu_features;
@@ -79,7 +79,7 @@ pub fn init_ap() void {
apic.init_local();
}
pub fn late_init(boot_info: *pl.BootInfo) linksection(b.init) void {
pub fn late_init(boot_info: *pl.BootInfo) linksection(r.init) void {
pl.acpi.init(boot_info);
if (amd64.hypervisor.info) |hv| {
+4 -4
View File
@@ -1,9 +1,9 @@
const amd64 = @import("arch");
const kvm = amd64.hypervisor.kvm;
const b = @import("base");
const r = @import("root");
const std = @import("std");
const mm = b.mm;
const ke = b.ke;
const mm = r.mm;
const ke = r.ke;
var pvclock_src: kvm.PVClockSource = undefined;
var pvclock_tc: ke.TimeCounter = .{
@@ -16,7 +16,7 @@ var pvclock_tc: ke.TimeCounter = .{
.n = 0,
};
pub fn init() linksection(b.init) void {
pub fn init() linksection(r.init) void {
const page = mm.phys.alloc();
pvclock_src = kvm.PVClockSource.init(page, mm.p2v(page));
ke.time.register_source(&pvclock_tc);
+5 -5
View File
@@ -1,10 +1,10 @@
const apic = @import("apic.zig");
const b = @import("base");
const r = @import("root");
const std = @import("std");
const rtl = @import("rtl");
const config = @import("config");
const mm = b.mm;
const ke = b.ke;
const mm = r.mm;
const ke = r.ke;
const ki = ke.private;
const amd64 = @import("arch");
@@ -36,7 +36,7 @@ fn ap_entry(cpu_id: u32) callconv(.c) noreturn {
ki.impl.init.ap_entry(cpu_id);
}
pub fn init() linksection(b.init) void {
pub fn init() linksection(r.init) void {
const trampoline_start = @intFromPtr(&AP_TRAMPOLINE_START);
const trampoline_size = @intFromPtr(&AP_TRAMPOLINE_END) - trampoline_start;
@@ -91,7 +91,7 @@ pub fn init() linksection(b.init) void {
ki.impl.cpu_offsets[cpu_id] = @intFromPtr(cpu_data.ptr) -% @intFromPtr(&__percpu_start);
const stack_top = @intFromPtr(mm.heap.alloc(b.kib(16)) catch @panic("Failed to allocate AP stack")) + b.kib(16);
const stack_top = @intFromPtr(mm.heap.alloc(r.kib(16)) catch @panic("Failed to allocate AP stack")) + r.kib(16);
start_stack.remote(@intCast(cpu_id)).* = stack_top & ~@as(usize, 15);
+3 -3
View File
@@ -1,8 +1,8 @@
// Not sure if this should be in platform/pc or in kern/
const std = @import("std");
const amd64 = @import("arch");
const b = @import("base");
const ke = b.ke;
const r = @import("root");
const ke = r.ke;
const log = std.log.scoped(.@"amd64/tsc");
@@ -16,7 +16,7 @@ var tsc_timer: ke.TimeCounter = .{
.n = 0,
};
pub fn init() linksection(b.init) void {
pub fn init() linksection(r.init) void {
const features = amd64.cpu_features;
if (!features.invariant_tsc) {
+9 -9
View File
@@ -1,7 +1,7 @@
const b = @import("base");
const r = @import("root");
pub const std_options = b.std_options;
pub const panic = b.panic;
pub const std_options = r.std_options;
pub const panic = r.panic;
const c = @cImport({
@cInclude("SDL.h");
@@ -10,10 +10,10 @@ const c = @cImport({
});
const std = @import("std");
const ke = b.ke;
const pl = b.pl;
const ke = r.ke;
const pl = r.pl;
const default_mem_size = b.gib(1);
const default_mem_size = r.gib(1);
fn parse_mem_size(str: []const u8) !usize {
if (str.len == 0) return default_mem_size;
@@ -21,9 +21,9 @@ fn parse_mem_size(str: []const u8) !usize {
const last = str[str.len - 1];
const mul: usize = switch (std.ascii.toLower(last)) {
'k' => b.kib(1),
'm' => b.mib(1),
'g' => b.gib(1),
'k' => r.kib(1),
'm' => r.mib(1),
'g' => r.gib(1),
else => 1,
};
+17 -15
View File
@@ -1,11 +1,13 @@
const std = @import("std");
const linux = std.os.linux;
const b = @import("base");
const pl = b.pl;
const ke = b.ke;
const ki = b.ke.private;
const r = @import("root");
const pl = r.pl;
const ke = r.ke;
const ki = r.ke.private;
const posix = std.posix;
pub const entry = @import("entry.zig");
const timer = @import("timer.zig");
pub const c = @cImport({
@@ -61,7 +63,7 @@ pub fn check_function(fn_name: []const u8, ret: usize) void {
pub var cpu_offsets: []usize = undefined;
pub fn early_init(_: *pl.BootInfo) linksection(b.init) void {
pub fn early_init(_: *pl.BootInfo) linksection(r.init) void {
percpu.local().pthread = c.pthread_self();
my_cpu_id = 0;
@@ -82,16 +84,16 @@ pub fn early_init(_: *pl.BootInfo) linksection(b.init) void {
global_state.phys_memory_memfd = memfd;
global_state.phys_base = phys_base;
const pfndb_base = linux.mmap(null, b.tib(1), .{}, .{ .ANONYMOUS = true, .TYPE = .PRIVATE }, -1, 0);
const pfndb_base = linux.mmap(null, r.tib(1), .{}, .{ .ANONYMOUS = true, .TYPE = .PRIVATE }, -1, 0);
check_function("mmap", pfndb_base);
const heap_base = linux.mmap(null, b.gib(8), .{}, .{ .ANONYMOUS = true, .TYPE = .PRIVATE }, -1, 0);
const heap_base = linux.mmap(null, r.gib(8), .{}, .{ .ANONYMOUS = true, .TYPE = .PRIVATE }, -1, 0);
check_function("mmap", heap_base);
b.kernel_pfndb_base = pfndb_base;
b.kernel_heap_base = heap_base;
r.kernel_pfndb_base = pfndb_base;
r.kernel_heap_base = heap_base;
std.log.info("um: kernel heap lives at {X}", .{heap_base});
}
@@ -102,10 +104,10 @@ fn sigusr1_handler(_: posix.SIG, _: *const posix.siginfo_t, _: ?*anyopaque) call
}
}
fn make_thread(entry: *const fn (?*anyopaque) void, td: *ke.Thread) void {
fn make_thread(entrypoint: *const fn (?*anyopaque) void, td: *ke.Thread) void {
const stack = std.heap.page_allocator.alloc(u8, 16384) catch @panic("wtf");
td.init(@intFromPtr(stack.ptr), 16384, entry, null);
td.init(@intFromPtr(stack.ptr), 16384, entrypoint, null);
td.priority = 0;
td.priority_class = .Idle;
@@ -127,14 +129,14 @@ fn other_cpu_entry(_: ?*anyopaque) callconv(.c) ?*anyopaque {
return null;
}
var cpu: ke.Cpu linksection(b.percpu) = undefined;
var cpu: ke.Cpu linksection(r.percpu) = undefined;
fn idle(_: ?*anyopaque) void {}
extern var __percpu_start: u8;
extern var __percpu_end: u8;
pub fn late_init(_: *pl.BootInfo) linksection(b.init) void {
pub fn late_init(_: *pl.BootInfo) linksection(r.init) void {
timer.init();
timer.init_cpu();
@@ -180,14 +182,14 @@ pub fn late_init(_: *pl.BootInfo) linksection(b.init) void {
cpuset.__bits[i / 64] |= @as(c_ulong, 1) << @intCast(i % 64);
_ = c.pthread_attr_setaffinity_np(&attr, @sizeOf(c.cpu_set_t), &cpuset);
const r = c.pthread_create(
const ret = c.pthread_create(
&other_threads[i - 1],
&attr,
other_cpu_entry,
null,
);
if (r != 0) {
if (ret != 0) {
@panic("pthread_create() failed");
}
}
+4 -4
View File
@@ -1,9 +1,9 @@
const b = @import("base");
const r = @import("root");
const std = @import("std");
const posix = std.posix;
const linux = std.os.linux;
const c = b.pl.impl.c;
const ke = b.ke;
const c = r.pl.impl.c;
const ke = r.ke;
const ki = ke.private;
threadlocal var timerid: c.timer_t = undefined;
@@ -20,7 +20,7 @@ fn timer_handler(_: posix.SIG, _: *const posix.siginfo_t, _: ?*anyopaque) callco
}
}
pub fn arm_timer(ns: b.Nanoseconds) void {
pub fn arm_timer(ns: r.Nanoseconds) void {
const value: c.struct_itimerspec = .{ .it_value = .{
.tv_sec = @intCast(ns / std.time.ns_per_s),
.tv_nsec = @intCast(ns % std.time.ns_per_s),