Files
Zag/src/mm/root.zig
T
2026-06-25 21:33:14 -04:00

65 lines
1.6 KiB
Zig

pub const private = @import("private.zig");
const std = @import("std");
pub const page_size = 4096;
pub const init = private.init.init;
pub const late_init = private.init.late_init;
pub const vmem = private.vmem;
pub const phys = private.phys;
pub const zone = private.zone;
pub const heap = private.heap;
pub const Space = private.Space;
// 16 TB of maximum physical memory.
// This should be fine on consumer hardware for at least a decade :^)
pub const Pfn = u32;
pub const null_pfn: Pfn = std.math.maxInt(Pfn);
pub const Page = extern union {
free: extern struct {
// Fields used when the page is free.
next_pfn: Pfn,
batch_next: Pfn,
batch_count: u8,
},
alloced: extern struct {
slab_data: zone.Page,
},
};
pub const MapFlags = packed struct {
read: bool = true,
write: bool = false,
user: bool = false,
execute: bool = false,
global: bool = false,
write_through: bool = false,
cache_disable: bool = false,
};
pub const Error = error{ OutOfMemory, InvalidAddress, InvalidSize };
pub inline fn page_to_pfn(addr: usize) Pfn {
return @intCast(addr >> 12);
}
pub inline fn pfn_to_page(pfn: Pfn) usize {
return @as(usize, pfn) << 12;
}
pub inline fn struct_page_to_pfn(page: *Page) Pfn {
return @intCast((@intFromPtr(page) - private.impl.pfndb_base) / @sizeOf(Page));
}
pub inline fn pfn_to_struct_page(pfn: Pfn) *Page {
return @ptrFromInt(private.impl.pfndb_base + (@as(usize, @intCast(pfn)) * @sizeOf(Page)));
}
pub var pfndb: [*]Page = @ptrFromInt(private.impl.pfndb_base);
pub const p2v = private.impl.phys_to_virt;
pub const v2p = private.impl.virt_to_phys;