hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/boot/boot.zig
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-11 02:38:27 +0200
committerhachem <im@hachem.wtf>2026-09-11 02:38:27 +0200
commitc34524767c9eac650f16dbe9059c24af2acd1397 (patch)
treee01f2fccd6dedfd1158a0666c12b7c8e9cfc12dd /boot/boot.zig
parent8fc9aa8d84486c561776cda8f94e4dfa897a5d4d (diff)
feat: pmm + kernel heap
Diffstat (limited to 'boot/boot.zig')
-rw-r--r--boot/boot.zig37
1 files changed, 37 insertions, 0 deletions
diff --git a/boot/boot.zig b/boot/boot.zig
index 6cc3d12..933065c 100644
--- a/boot/boot.zig
+++ b/boot/boot.zig
@@ -4,6 +4,8 @@ const serial = @import("serial.zig");
const framebuffer = @import("framebuffer.zig");
const gdt = @import("gdt.zig");
const idt = @import("idt.zig");
+const pmm = @import("pmm.zig");
+const heap = @import("heap.zig");
// We need a panic handler otherwise zig won't be happy,
// std usually formats a message through std.Io.Writer which
@@ -24,6 +26,11 @@ export var base_revision: limine.BaseRevision linksection(".limine_requests") =
export var requests_start: limine.RequestsStartMarker linksection(".limine_requests_start") = .{};
export var requests_end: limine.RequestsEndMarker linksection(".limine_requests_end") = .{};
+// the loader fills these before we run so we read them through volatile pointers or
+// the optimizer assumes they're still the null we initialized them to
+export var hhdm_request: limine.HhdmRequest linksection(".limine_requests") = .{};
+export var memmap_request: limine.MemoryMapRequest linksection(".limine_requests") = .{};
+
// ENTRY(_start)
export fn _start() callconv(.c) noreturn {
serial.init();
@@ -31,8 +38,38 @@ export fn _start() callconv(.c) noreturn {
gdt.load();
idt.init();
+
+
serial.write("gdt + idt loaded\r\n");
+ // HHDM + memory map -> physical frame allocator -> kernel heap
+ const hhdm_req: *volatile limine.HhdmRequest = &hhdm_request;
+ const memmap_req: *volatile limine.MemoryMapRequest = &memmap_request;
+ const hhdm = hhdm_req.response orelse @panic("limine gave us no HHDM");
+ const memmap = memmap_req.response orelse @panic("limine gave us no memory map");
+
+ pmm.init(hhdm, memmap);
+ pmm.dump(memmap);
+ heap.init();
+
+ // NOTE: this is a sanity check
+ // two allocations should be distinct and non-overlapping,
+ // and a freed frame should come straight back on the next alloc.
+ const a = pmm.alloc().?;
+ const b = pmm.alloc().?;
+ serial.write("pmm test: a=");
+ serial.writeHex(a);
+ serial.write(" b=");
+ serial.writeHex(b);
+ serial.write("\r\n");
+ pmm.free(a);
+ const c = pmm.alloc().?;
+ serial.write("pmm test: freed a, realloc=");
+ serial.writeHex(c);
+ serial.write(if (c == a) " (reused, good)\r\n" else " (mismatch!)\r\n");
+ pmm.free(b);
+ pmm.free(c);
+
if (framebuffer.get()) |screen| {
// XOR texture
var y: usize = 0;