mirror of
https://github.com/rdmsr/zag.git
synced 2026-10-27 13:58:20 +00:00
mm: add Space
This commit is contained in:
@@ -100,9 +100,9 @@ pub fn init_kernel() void {
|
||||
const higher_half_start = phys_to_virt(0);
|
||||
const higher_half_size: usize = 256 * (1 << 39);
|
||||
|
||||
mi.kernel_pmap.impl.root_pa = mi.phys.alloc();
|
||||
const table_ptr: [*]u64 = @ptrFromInt(mm.p2v(mi.kernel_pmap.impl.root_pa));
|
||||
mi.kernel_space.pmap.impl.root_pa = mi.phys.alloc();
|
||||
const table_ptr: [*]u64 = @ptrFromInt(mm.p2v(mi.kernel_space.pmap.impl.root_pa));
|
||||
@memset(table_ptr[0..512], 0);
|
||||
|
||||
mi.kernel_pmap.impl.preallocate(higher_half_start, higher_half_size, 2);
|
||||
mi.kernel_space.pmap.impl.preallocate(higher_half_start, higher_half_size, 2);
|
||||
}
|
||||
|
||||
+5
-8
@@ -3,20 +3,17 @@ const ke = r.ke;
|
||||
const mm = r.mm;
|
||||
const mi = mm.private;
|
||||
|
||||
var heap_lock: ke.QSpinLock = .init();
|
||||
var heap_arena: mm.vmem.Arena = undefined;
|
||||
|
||||
pub fn init() void {
|
||||
heap_arena.init("kernel heap", mi.impl.kernel_heap_base, r.tib(16), mm.page_size) catch @panic("failed to initialize kernel heap arena");
|
||||
mi.kernel_space.arena.init("kernel heap", mi.impl.kernel_heap_base, r.tib(16), mm.page_size) catch @panic("failed to initialize kernel heap arena");
|
||||
}
|
||||
|
||||
pub fn alloc(size: usize) mm.Error!*anyopaque {
|
||||
const ipl = heap_lock.acquire();
|
||||
defer heap_lock.release(ipl);
|
||||
const ipl = mi.kernel_space.lock.acquire();
|
||||
defer mi.kernel_space.lock.release(ipl);
|
||||
|
||||
const addr = try heap_arena.alloc(size, .{});
|
||||
const addr = try mi.kernel_space.arena.alloc(size, .{});
|
||||
|
||||
mi.kernel_pmap.map_range_allocating(addr, size, .{
|
||||
mi.kernel_space.pmap.map_range_allocating(addr, size, .{
|
||||
.read = true,
|
||||
.write = true,
|
||||
.global = true,
|
||||
|
||||
+7
-7
@@ -29,30 +29,30 @@ fn map_kernel(boot_info: *pl.BootInfo) void {
|
||||
const start_virt = kaddr.virtual_base;
|
||||
const until_size = text_start - start_virt;
|
||||
|
||||
mi.kernel_pmap.map_contiguous_range(start_virt, start_phys, until_size, .{
|
||||
mi.kernel_space.pmap.map_contiguous_range(start_virt, start_phys, until_size, .{
|
||||
.read = true,
|
||||
.write = true,
|
||||
.global = true,
|
||||
});
|
||||
|
||||
mi.kernel_pmap.map_contiguous_range(text_start, kaddr.physical_base + (text_start - kaddr.virtual_base), text_size, .{
|
||||
mi.kernel_space.pmap.map_contiguous_range(text_start, kaddr.physical_base + (text_start - kaddr.virtual_base), text_size, .{
|
||||
.read = true,
|
||||
.execute = true,
|
||||
.global = true,
|
||||
});
|
||||
|
||||
mi.kernel_pmap.map_contiguous_range(rodata_start, kaddr.physical_base + (rodata_start - kaddr.virtual_base), rodata_size, .{
|
||||
mi.kernel_space.pmap.map_contiguous_range(rodata_start, kaddr.physical_base + (rodata_start - kaddr.virtual_base), rodata_size, .{
|
||||
.read = true,
|
||||
.global = true,
|
||||
});
|
||||
|
||||
mi.kernel_pmap.map_contiguous_range(data_start, kaddr.physical_base + (data_start - kaddr.virtual_base), data_size, .{
|
||||
mi.kernel_space.pmap.map_contiguous_range(data_start, kaddr.physical_base + (data_start - kaddr.virtual_base), data_size, .{
|
||||
.read = true,
|
||||
.write = true,
|
||||
.global = true,
|
||||
});
|
||||
|
||||
mi.kernel_pmap.map_contiguous_range(mm.p2v(0), 0, mi.impl.hhdm_minimum_max_address, .{
|
||||
mi.kernel_space.pmap.map_contiguous_range(mm.p2v(0), 0, mi.impl.hhdm_minimum_max_address, .{
|
||||
.read = true,
|
||||
.write = true,
|
||||
.global = true,
|
||||
@@ -81,7 +81,7 @@ fn map_kernel(boot_info: *pl.BootInfo) void {
|
||||
entry_size -= adjust;
|
||||
}
|
||||
|
||||
mi.kernel_pmap.map_contiguous_range(mm.p2v(entry_start), entry_start, entry_size, .{
|
||||
mi.kernel_space.pmap.map_contiguous_range(mm.p2v(entry_start), entry_start, entry_size, .{
|
||||
.read = true,
|
||||
.write = true,
|
||||
.global = true,
|
||||
@@ -94,7 +94,7 @@ pub fn init(boot_info: *pl.BootInfo) linksection(r.init) void {
|
||||
if (config.arch != .um) {
|
||||
map_kernel(boot_info);
|
||||
}
|
||||
mi.kernel_pmap.activate();
|
||||
mi.kernel_space.pmap.activate();
|
||||
mi.phys.init_pfndb();
|
||||
mi.zone.early_init();
|
||||
mi.vmem.init();
|
||||
|
||||
+1
-1
@@ -256,7 +256,7 @@ pub fn init(boot_info: *pl.BootInfo) linksection(r.init) void {
|
||||
const map_end = std.mem.alignForward(usize, exact_end, mm.page_size);
|
||||
|
||||
// 3. Map the virtual pages.
|
||||
mi.kernel_pmap.map_range_allocating(map_start, map_end - map_start, .{
|
||||
mi.kernel_space.pmap.map_range_allocating(map_start, map_end - map_start, .{
|
||||
.read = true,
|
||||
.write = true,
|
||||
.global = true,
|
||||
|
||||
+9
-1
@@ -8,10 +8,18 @@ pub const heap = @import("heap.zig");
|
||||
pub const zone = @import("zone.zig");
|
||||
pub const PMap = pmap.PMap;
|
||||
|
||||
const ke = @import("root").ke;
|
||||
|
||||
pub const Space = struct {
|
||||
pmap: PMap,
|
||||
arena: vmem.Arena,
|
||||
lock: ke.QSpinLock,
|
||||
};
|
||||
|
||||
pub const impl = switch (config.arch) {
|
||||
.amd64 => @import("amd64/impl.zig"),
|
||||
.um => @import("um/impl.zig"),
|
||||
else => @compileError("unsupported architecture"),
|
||||
};
|
||||
|
||||
pub var kernel_pmap: PMap = undefined;
|
||||
pub var kernel_space: Space = undefined;
|
||||
|
||||
@@ -10,6 +10,7 @@ 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 :^)
|
||||
|
||||
+2
-2
@@ -522,7 +522,7 @@ pub const Zone = struct {
|
||||
// Find the slab for the buffer.
|
||||
const slab: *Slab = if (self.obj_size > small_slab_size) blk: {
|
||||
const page_va = std.mem.alignBackward(usize, @intFromPtr(obj), mm.page_size);
|
||||
const phys = mi.kernel_pmap.query(page_va).?;
|
||||
const phys = mi.kernel_space.pmap.query(page_va).?;
|
||||
const page = mm.pfn_to_struct_page(mm.page_to_pfn(phys));
|
||||
break :blk page.alloced.slab_data.slab;
|
||||
} else blk: {
|
||||
@@ -627,7 +627,7 @@ pub const Zone = struct {
|
||||
ret.refcount = 0;
|
||||
|
||||
for (0..self.slab_size / mm.page_size) |i| {
|
||||
const phys_page = mi.kernel_pmap.query(@intFromPtr(buf) + i * mm.page_size) orelse @panic("Could not query page");
|
||||
const phys_page = mi.kernel_space.pmap.query(@intFromPtr(buf) + i * mm.page_size) orelse @panic("Could not query page");
|
||||
const page = mm.pfn_to_struct_page(mm.page_to_pfn(phys_page));
|
||||
page.alloced.slab_data.slab = ret;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ pub fn init() linksection(r.init) void {
|
||||
const trampoline_size = @intFromPtr(&AP_TRAMPOLINE_END) - trampoline_start;
|
||||
|
||||
// Map the trampoline page.
|
||||
mm.private.kernel_pmap.map_contiguous_range(0x8000, 0x8000, 0x1000, .{
|
||||
mm.private.kernel_space.pmap.map_contiguous_range(0x8000, 0x8000, 0x1000, .{
|
||||
.read = true,
|
||||
.write = true,
|
||||
.execute = true,
|
||||
|
||||
Reference in New Issue
Block a user