From 8fc3dc237f732c7cbd5df8c1f87780966929c4d8 Mon Sep 17 00:00:00 2001 From: Lorenzo Torres Date: Thu, 16 Apr 2026 12:47:47 +0200 Subject: [PATCH] Fix page table compilation issues --- src/main.zig | 18 ++---------------- src/riscv/PageTable.zig | 9 ++++++++- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/main.zig b/src/main.zig index 1e9fc1f..7bd4a12 100644 --- a/src/main.zig +++ b/src/main.zig @@ -5,20 +5,8 @@ const Console = @import("drivers/Console.zig"); const debug = @import("debug.zig"); const mem = @import("mem.zig"); -const UART_BASE: usize = 0x10000000; const MEMORY_START = @extern([*]u8, .{.name = "__memory_start"}); -fn uart_put(c: u8) void { - const uart: *volatile u8 = @ptrFromInt(UART_BASE); - uart.* = c; -} - -fn print(s: []const u8) void { - for (s) |c| { - uart_put(c); - } -} - pub const panic = debug.KernelPanic; export fn _start() linksection(".text.init") callconv(.naked) noreturn { @@ -61,10 +49,8 @@ export fn kmain(hartid: u64, fdt_ptr: *const anyopaque) callconv(.c) noreturn { table.map(allocator, @intFromPtr(console.mmio), @intFromPtr(console.mmio), .{.read = 1, .write = 1, .execute = 1}, mmu_type) catch { }; - isa.write_satp(.{ - .ppn = @as(u44, @intCast(@intFromPtr(table) >> 12)), - .mode = mmu_type, - }); + + table.load(mmu_type); debug.print("loaded kernel page table.\n", .{}); while (true) { diff --git a/src/riscv/PageTable.zig b/src/riscv/PageTable.zig index d702eae..1edf701 100644 --- a/src/riscv/PageTable.zig +++ b/src/riscv/PageTable.zig @@ -50,6 +50,13 @@ pub fn identityMap(self: *PageTable, allocator: Allocator, memory_end: u64, mode } } +pub fn load(self: *const PageTable, mmu_type: isa.Satp.Mode) void { + isa.write_satp(.{ + .ppn = @as(u44, @intCast(@intFromPtr(self) >> 12)), + .mode = mmu_type, + }); +} + pub fn map(self: *PageTable, allocator: Allocator, virtual: u64, physical: u64, flags: EntryFlags, mode: isa.Satp.Mode) !void { const PAGE_SIZE = 4096; @@ -76,7 +83,7 @@ pub fn map(self: *PageTable, allocator: Allocator, virtual: u64, physical: u64, while (level > 0) : (level -= 1) { const index = vpn[level]; - var entry = ¤t_table.entries[index]; + const entry = ¤t_table.entries[index]; if (entry.flags.valid == 0) { const new_table = try PageTable.init(allocator);