Fix page table compilation issues

This commit is contained in:
Lorenzo Torres 2026-04-16 12:47:47 +02:00
parent 8e160782ec
commit 8fc3dc237f
2 changed files with 10 additions and 17 deletions

View file

@ -5,20 +5,8 @@ const Console = @import("drivers/Console.zig");
const debug = @import("debug.zig"); const debug = @import("debug.zig");
const mem = @import("mem.zig"); const mem = @import("mem.zig");
const UART_BASE: usize = 0x10000000;
const MEMORY_START = @extern([*]u8, .{.name = "__memory_start"}); 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; pub const panic = debug.KernelPanic;
export fn _start() linksection(".text.init") callconv(.naked) noreturn { 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 { 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)), table.load(mmu_type);
.mode = mmu_type,
});
debug.print("loaded kernel page table.\n", .{}); debug.print("loaded kernel page table.\n", .{});
while (true) { while (true) {

View file

@ -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 { pub fn map(self: *PageTable, allocator: Allocator, virtual: u64, physical: u64, flags: EntryFlags, mode: isa.Satp.Mode) !void {
const PAGE_SIZE = 4096; const PAGE_SIZE = 4096;
@ -76,7 +83,7 @@ pub fn map(self: *PageTable, allocator: Allocator, virtual: u64, physical: u64,
while (level > 0) : (level -= 1) { while (level > 0) : (level -= 1) {
const index = vpn[level]; const index = vpn[level];
var entry = &current_table.entries[index]; const entry = &current_table.entries[index];
if (entry.flags.valid == 0) { if (entry.flags.valid == 0) {
const new_table = try PageTable.init(allocator); const new_table = try PageTable.init(allocator);