blob: 3fd9f8cf28a6f8e248868184bef9f45b4bdc4b74 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
// this just grabs a contiguous chunk of frams from the PMM and then
// hands out a bump allocator, this just gives std.mem.Allocator which
// we'll pass to the revo VM later. FixedBufferAllocator never reclaims
// freed space unless you free in reverse order which is ehhhhh, fine ig
// for bootstrapping.
//
// TODO: swap fixed buffer allocator for a free list allocator
const std = @import("std");
const pmm = @import("pmm.zig");
const serial = @import("serial.zig");
// 32 MiB.
// NOTE: bump if the VM needs more
const HEAP_PAGES: usize = 8192;
var fba: std.heap.FixedBufferAllocator = undefined;
pub fn init() void {
const phys = pmm.allocContig(HEAP_PAGES) orelse @panic("heap: no contiguous frames for the heap");
const virt = pmm.physToVirt(phys);
const buf: [*]u8 = @ptrFromInt(virt);
fba = std.heap.FixedBufferAllocator.init(buf[0 .. HEAP_PAGES * pmm.PAGE_SIZE]);
serial.write("heap: ");
serial.writeDec((HEAP_PAGES * pmm.PAGE_SIZE) / (1024 * 1024));
serial.write(" MiB at ");
serial.writeHex(virt);
serial.write("\r\n");
}
pub fn allocator() std.mem.Allocator {
return fba.allocator();
}
|