feat(mm/phys): implement alloc and free

This commit is contained in:
Loïc Grégoire
2026-04-03 21:16:53 -04:00
parent 5b60f08db5
commit d2bc8f2bf8
6 changed files with 185 additions and 15 deletions
+15 -1
View File
@@ -28,9 +28,23 @@ pub const MapFlags = packed struct {
cache_disable: bool = false,
};
pub fn page_to_pfn(addr: usize) Pfn {
pub inline fn page_to_pfn(addr: usize) Pfn {
return @intCast(addr >> 12);
}
pub inline fn pfn_to_page(pfn: Pfn) usize {
return @intCast(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;