mirror of
https://github.com/rdmsr/zag.git
synced 2026-10-31 15:28:21 +00:00
refactor: use root instead of base
This commit is contained in:
+10
-10
@@ -1,15 +1,15 @@
|
||||
const amd64 = @import("arch");
|
||||
const b = @import("base");
|
||||
const mm = b.mm;
|
||||
const r = @import("root");
|
||||
const mm = r.mm;
|
||||
const mi = mm.private;
|
||||
|
||||
pub const hhdm_minimum_max_address = b.gib(4);
|
||||
pub const hhdm_minimum_max_address = r.gib(4);
|
||||
|
||||
pub fn phys_to_virt(addr: b.PAddr) b.VAddr {
|
||||
pub fn phys_to_virt(addr: r.PAddr) r.VAddr {
|
||||
return addr + 0xffff800000000000;
|
||||
}
|
||||
|
||||
pub fn virt_to_phys(vaddr: b.VAddr) usize {
|
||||
pub fn virt_to_phys(vaddr: r.VAddr) usize {
|
||||
return vaddr - 0xffff800000000000;
|
||||
}
|
||||
|
||||
@@ -42,12 +42,12 @@ pub const PagingImpl = struct {
|
||||
ignored_2: u11,
|
||||
nx: bool,
|
||||
|
||||
pub fn address(self: Pte) b.PAddr {
|
||||
return @as(b.PAddr, self.addr) << 12;
|
||||
pub fn address(self: Pte) r.PAddr {
|
||||
return @as(r.PAddr, self.addr) << 12;
|
||||
}
|
||||
};
|
||||
|
||||
pub inline fn make_table_pte(pa: b.PAddr) Pte {
|
||||
pub inline fn make_table_pte(pa: r.PAddr) Pte {
|
||||
return Pte{
|
||||
.present = true,
|
||||
.writable = true,
|
||||
@@ -65,7 +65,7 @@ pub const PagingImpl = struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn make_leaf_pte(pa: b.PAddr, flags: mm.MapFlags, level: usize) Pte {
|
||||
pub inline fn make_leaf_pte(pa: r.PAddr, flags: mm.MapFlags, level: usize) Pte {
|
||||
return Pte{
|
||||
.present = true,
|
||||
.writable = flags.write,
|
||||
@@ -83,7 +83,7 @@ pub const PagingImpl = struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn activate(root_pa: b.PAddr) void {
|
||||
pub inline fn activate(root_pa: r.PAddr) void {
|
||||
amd64.write_cr(3, root_pa);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -1,13 +1,13 @@
|
||||
const b = @import("base");
|
||||
const ke = b.ke;
|
||||
const mm = b.mm;
|
||||
const r = @import("root");
|
||||
const ke = r.ke;
|
||||
const mm = r.mm;
|
||||
const mi = mm.private;
|
||||
|
||||
var heap_lock: ke.SpinLock = .init();
|
||||
var heap_arena: mm.vmem.Arena = undefined;
|
||||
|
||||
pub fn init() void {
|
||||
heap_arena.init("kernel heap", mi.impl.kernel_heap_base, b.tib(16), mm.page_size) catch @panic("failed to initialize kernel heap arena");
|
||||
heap_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 {
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
const b = @import("base");
|
||||
const pl = b.pl;
|
||||
const mm = b.mm;
|
||||
const r = @import("root");
|
||||
const pl = r.pl;
|
||||
const mm = r.mm;
|
||||
const mi = mm.private;
|
||||
const config = @import("config");
|
||||
|
||||
@@ -87,7 +87,7 @@ else
|
||||
pub fn call(_: *pl.BootInfo) void {}
|
||||
}.call;
|
||||
|
||||
pub fn init(boot_info: *pl.BootInfo) linksection(b.init) void {
|
||||
pub fn init(boot_info: *pl.BootInfo) linksection(r.init) void {
|
||||
mi.phys.init(boot_info);
|
||||
map_kernel(boot_info);
|
||||
mi.kernel_pmap.activate();
|
||||
|
||||
+7
-7
@@ -6,13 +6,13 @@
|
||||
//! When freeing pages, they are added to the active batch until it reaches capacity,
|
||||
//! at which point the full batch is moved to the local depot.
|
||||
//! If the depot is full when trying to add a new batch, one batch is pushed back to the global stack to make room.
|
||||
const b = @import("base");
|
||||
const r = @import("root");
|
||||
const std = @import("std");
|
||||
const rtl = @import("rtl");
|
||||
const pl = b.pl;
|
||||
const mm = b.mm;
|
||||
const pl = r.pl;
|
||||
const mm = r.mm;
|
||||
const mi = mm.private;
|
||||
const ke = b.ke;
|
||||
const ke = r.ke;
|
||||
|
||||
const log = std.log.scoped(.@"mm/phys");
|
||||
|
||||
@@ -113,7 +113,7 @@ fn early_alloc() usize {
|
||||
}
|
||||
|
||||
/// Allocate a page of physical memory.
|
||||
pub fn alloc() b.PAddr {
|
||||
pub fn alloc() r.PAddr {
|
||||
if (!bootstrapped) {
|
||||
return early_alloc();
|
||||
}
|
||||
@@ -160,7 +160,7 @@ pub fn alloc() b.PAddr {
|
||||
}
|
||||
|
||||
/// Free a page of physical memory.
|
||||
pub fn free(addr: b.PAddr) void {
|
||||
pub fn free(addr: r.PAddr) void {
|
||||
const ipl = ke.ipl.raise(.High);
|
||||
defer ke.ipl.lower(ipl);
|
||||
|
||||
@@ -200,7 +200,7 @@ pub fn free(addr: b.PAddr) void {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(boot_info: *pl.BootInfo) linksection(b.init) void {
|
||||
pub fn init(boot_info: *pl.BootInfo) linksection(r.init) void {
|
||||
memory_map = &boot_info.memory_map;
|
||||
|
||||
var total_usable_memory: usize = 0;
|
||||
|
||||
+9
-9
@@ -20,13 +20,13 @@
|
||||
//! cases (contiguous PA range and on-demand allocation); custom sources can
|
||||
//! be passed directly to `map_from` for other needs such as file-backed or
|
||||
//! scatter-gather mappings.
|
||||
const b = @import("base");
|
||||
const mm = b.mm;
|
||||
const r = @import("root");
|
||||
const mm = r.mm;
|
||||
const mi = mm.private;
|
||||
|
||||
/// Describes a contiguous region of physical memory to be mapped at a given virtual address.
|
||||
pub const MapItem = struct {
|
||||
pa: b.PAddr,
|
||||
pa: r.PAddr,
|
||||
len: usize,
|
||||
flags: mm.MapFlags,
|
||||
};
|
||||
@@ -40,7 +40,7 @@ const ContiguousSource = struct {
|
||||
base_va: usize,
|
||||
base_pa: usize,
|
||||
|
||||
pub fn next(self: *const ContiguousSource, _: b.VAddr) MapItem {
|
||||
pub fn next(self: *const ContiguousSource, _: r.VAddr) MapItem {
|
||||
return .{
|
||||
.pa = self.base_pa,
|
||||
.len = self.size,
|
||||
@@ -54,7 +54,7 @@ const ContiguousSource = struct {
|
||||
const AllocatingSource = struct {
|
||||
flags: mm.MapFlags,
|
||||
|
||||
pub fn next(self: *const AllocatingSource, _: b.VAddr) MapItem {
|
||||
pub fn next(self: *const AllocatingSource, _: r.VAddr) MapItem {
|
||||
const pa = mi.phys.alloc();
|
||||
return .{
|
||||
.pa = pa,
|
||||
@@ -72,7 +72,7 @@ pub const PMap = struct {
|
||||
impl: mi.impl.PMap,
|
||||
|
||||
/// Map a virtual address range to physical addresses provided by the source.
|
||||
pub fn map_from(self: *Self, va_start: b.VAddr, size: usize, source: anytype) void {
|
||||
pub fn map_from(self: *Self, va_start: r.VAddr, size: usize, source: anytype) void {
|
||||
const Source = @TypeOf(source);
|
||||
|
||||
comptime {
|
||||
@@ -83,7 +83,7 @@ pub const PMap = struct {
|
||||
}
|
||||
|
||||
/// Map a contiguous virtual address range to a contiguous physical address range.
|
||||
pub fn map_contiguous_range(self: *Self, va: b.VAddr, pa: b.PAddr, size: usize, flags: mm.MapFlags) void {
|
||||
pub fn map_contiguous_range(self: *Self, va: r.VAddr, pa: r.PAddr, size: usize, flags: mm.MapFlags) void {
|
||||
const src = ContiguousSource{
|
||||
.flags = flags,
|
||||
.size = size,
|
||||
@@ -95,7 +95,7 @@ pub const PMap = struct {
|
||||
}
|
||||
|
||||
/// Map a virtual address range to physical addresses allocated on demand.
|
||||
pub fn map_range_allocating(self: *Self, va: b.VAddr, size: usize, flags: mm.MapFlags) void {
|
||||
pub fn map_range_allocating(self: *Self, va: r.VAddr, size: usize, flags: mm.MapFlags) void {
|
||||
const src = AllocatingSource{
|
||||
.flags = flags,
|
||||
};
|
||||
@@ -104,7 +104,7 @@ pub const PMap = struct {
|
||||
}
|
||||
|
||||
/// Map a single page. Convenience wrapper around map_contiguous_range.
|
||||
pub fn map_page(self: *Self, va: b.VAddr, pa: b.PAddr, flags: mm.MapFlags) void {
|
||||
pub fn map_page(self: *Self, va: r.VAddr, pa: r.PAddr, flags: mm.MapFlags) void {
|
||||
self.map_contiguous_range(va, pa, mm.page_size, flags);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
//! - `activate(root_pa: PAddr) void`: install the root page table into
|
||||
//! the CPU (e.g. write CR3 or satp).
|
||||
|
||||
const b = @import("base");
|
||||
const mm = b.mm;
|
||||
const r = @import("root");
|
||||
const mm = r.mm;
|
||||
const mi = mm.private;
|
||||
const std = @import("std");
|
||||
|
||||
@@ -42,7 +42,7 @@ pub fn RadixPmap(comptime Impl: type) type {
|
||||
const entries_per_table = 512;
|
||||
const index_mask = entries_per_table - 1;
|
||||
|
||||
root_pa: b.PAddr,
|
||||
root_pa: r.PAddr,
|
||||
|
||||
fn level_shift(level: usize) u6 {
|
||||
return Impl.levels[level].shift;
|
||||
@@ -79,7 +79,7 @@ pub fn RadixPmap(comptime Impl: type) type {
|
||||
Impl.activate(self.root_pa);
|
||||
}
|
||||
|
||||
pub fn map_from(self: *Self, va: b.VAddr, size: usize, source: anytype) void {
|
||||
pub fn map_from(self: *Self, va: r.VAddr, size: usize, source: anytype) void {
|
||||
var c = self.cursor(va);
|
||||
var remain = size;
|
||||
|
||||
@@ -94,7 +94,7 @@ pub fn RadixPmap(comptime Impl: type) type {
|
||||
/// the given virtual address range, allocating them as needed. Useful for
|
||||
/// pre-populating a shared region (e.g. the kernel half of a user pmap)
|
||||
/// before any leaf mappings are installed.
|
||||
pub fn preallocate(self: *Self, va: b.VAddr, size: usize, target_level: usize) void {
|
||||
pub fn preallocate(self: *Self, va: r.VAddr, size: usize, target_level: usize) void {
|
||||
var c = self.cursor(va);
|
||||
var remain = size;
|
||||
|
||||
@@ -112,7 +112,7 @@ pub fn RadixPmap(comptime Impl: type) type {
|
||||
|
||||
pub const Cursor = struct {
|
||||
pmap: *Self,
|
||||
va: b.VAddr,
|
||||
va: r.VAddr,
|
||||
/// Cached pointers to each level's page table, filled as the cursor
|
||||
/// descends. Only indices in `[0, top_level]` are valid.
|
||||
tables: [num_levels][*]Impl.Pte,
|
||||
@@ -176,7 +176,7 @@ pub fn RadixPmap(comptime Impl: type) type {
|
||||
@panic("no leaf level can map current alignment/size");
|
||||
}
|
||||
|
||||
pub fn map_range(self: *Cursor, pa: b.PAddr, size: usize, flags: mm.MapFlags) void {
|
||||
pub fn map_range(self: *Cursor, pa: r.PAddr, size: usize, flags: mm.MapFlags) void {
|
||||
var remain = size;
|
||||
var current_pa = pa;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
pub const private = @import("private.zig");
|
||||
|
||||
const b = @import("base");
|
||||
const std = @import("std");
|
||||
|
||||
pub const page_size = 4096;
|
||||
|
||||
+9
-9
@@ -1,4 +1,4 @@
|
||||
const b = @import("base");
|
||||
const r = @import("root");
|
||||
const std = @import("std");
|
||||
const linux = std.os.linux;
|
||||
|
||||
@@ -9,39 +9,39 @@ pub const hhdm_minimum_max_address: usize = 0;
|
||||
pub fn init_kernel() void {
|
||||
kernel_heap_base = linux.mmap(
|
||||
null,
|
||||
b.gib(8),
|
||||
r.gib(8),
|
||||
.{ .READ = true, .WRITE = true },
|
||||
.{ .ANONYMOUS = true, .TYPE = .PRIVATE },
|
||||
-1,
|
||||
0,
|
||||
);
|
||||
|
||||
b.pl.impl.check_function("mmap", kernel_heap_base);
|
||||
r.pl.impl.check_function("mmap", kernel_heap_base);
|
||||
|
||||
pfndb_base = linux.mmap(
|
||||
null,
|
||||
b.gib(1),
|
||||
r.gib(1),
|
||||
.{ .READ = true, .WRITE = true },
|
||||
.{ .ANONYMOUS = true, .TYPE = .PRIVATE },
|
||||
-1,
|
||||
0,
|
||||
);
|
||||
|
||||
b.pl.impl.check_function("mmap", pfndb_base);
|
||||
r.pl.impl.check_function("mmap", pfndb_base);
|
||||
}
|
||||
|
||||
pub fn phys_to_virt(pa: usize) usize {
|
||||
return b.pl.impl.global_state.phys_base + pa;
|
||||
return r.pl.impl.global_state.phys_base + pa;
|
||||
}
|
||||
|
||||
pub fn virt_to_phys(va: usize) usize {
|
||||
return va - b.pl.impl.global_state.phys_base;
|
||||
return va - r.pl.impl.global_state.phys_base;
|
||||
}
|
||||
|
||||
pub const PMap = struct {
|
||||
const Self = @This();
|
||||
|
||||
pub fn map_from(_: *Self, va: b.VAddr, size: usize, source: anytype) void {
|
||||
pub fn map_from(_: *Self, va: r.VAddr, size: usize, source: anytype) void {
|
||||
var remain = size;
|
||||
|
||||
while (remain > 0) {
|
||||
@@ -58,7 +58,7 @@ pub const PMap = struct {
|
||||
size,
|
||||
posix_flags,
|
||||
.{ .FIXED = true, .TYPE = .PRIVATE },
|
||||
b.pl.impl.global_state.phys_memory_memfd,
|
||||
r.pl.impl.global_state.phys_memory_memfd,
|
||||
@bitCast(item.pa),
|
||||
);
|
||||
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@
|
||||
//! complexity.
|
||||
const std = @import("std");
|
||||
const rtl = @import("rtl");
|
||||
const mm = @import("base").mm;
|
||||
const mm = @import("root").mm;
|
||||
const mi = mm.private;
|
||||
|
||||
pub const Policy = enum {
|
||||
|
||||
+4
-4
@@ -2,11 +2,11 @@
|
||||
//! As described in Bonwick's "The Slab Allocator: An Object-Caching Kernel Memory Allocator"
|
||||
//! and "Magazines and Vmem: Extending the Slab Allocator to Many CPUs and Arbitrary Resources".
|
||||
const rtl = @import("rtl");
|
||||
const b = @import("base");
|
||||
const r = @import("root");
|
||||
const config = @import("config");
|
||||
const std = @import("std");
|
||||
const ke = b.ke;
|
||||
const mm = b.mm;
|
||||
const ke = r.ke;
|
||||
const mm = r.mm;
|
||||
const mi = mm.private;
|
||||
|
||||
// TODO: when SMP is setup, do proper magazine initialization.
|
||||
@@ -714,7 +714,7 @@ pub fn TypedZone(comptime T: type) type {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn early_init() linksection(b.init) void {
|
||||
pub fn early_init() linksection(r.init) void {
|
||||
bufctl_zone.init("bufctl", .{});
|
||||
slab_zone.init("slab", .{});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user