mirror of
https://github.com/rdmsr/zag.git
synced 2026-10-29 14:38:21 +00:00
feat(mm/phys): implement alloc and free
This commit is contained in:
+15
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user