const std = @import("std"); const multiboot = @import("../../../src/kernel/multiboot.zig"); pub const Module = struct { region: Range, name: []const u8, }; pub const Map = struct { virtual: Range, physical: ?Range, }; pub const Range = struct { start: usize, end: usize, }; pub const MemProfile = struct { vaddr_end: [*]u8, vaddr_start: [*]u8, physaddr_end: [*]u8, physaddr_start: [*]u8, mem_kb: u32, modules: []Module, virtual_reserved: []Map, physical_reserved: []Range, fixed_allocator: std.heap.FixedBufferAllocator, }; pub var fixed_buffer_allocator: std.heap.FixedBufferAllocator = undefined; const FIXED_ALLOC_SIZE = 1024 * 1024; const ADDR_OFFSET: usize = 100; pub fn virtToPhys(virt: anytype) @TypeOf(virt) { const T = @TypeOf(virt); return switch (@typeInfo(T)) { .Pointer => @intToPtr(T, @ptrToInt(virt) - ADDR_OFFSET), .Int => virt - ADDR_OFFSET, else => @compileError("Only pointers and integers are supported"), }; } pub fn physToVirt(phys: anytype) @TypeOf(phys) { const T = @TypeOf(phys); return switch (@typeInfo(T)) { .Pointer => @intToPtr(T, @ptrToInt(phys) + ADDR_OFFSET), .Int => phys + ADDR_OFFSET, else => @compileError("Only pointers and integers are supported"), }; }