pluto/src/kernel/mem.zig

32 lines
1.1 KiB
Zig
Raw Normal View History

2019-05-23 18:50:37 +02:00
const multiboot = @import("multiboot.zig");
pub const MemProfile = struct {
vaddr_end: [*]u8,
vaddr_start: [*]u8,
physaddr_end: [*]u8,
physaddr_start: [*]u8,
mem_kb: u32,
fixed_alloc_size: u32,
2019-05-23 18:50:37 +02:00
};
// The virtual/physical start/end of the kernel code
extern var KERNEL_VADDR_END: *u32;
extern var KERNEL_VADDR_START: *u32;
extern var KERNEL_PHYSADDR_END: *u32;
extern var KERNEL_PHYSADDR_START: *u32;
// The size of the fixed allocator used before the heap is set up. Set to 1MiB.
const FIXED_ALLOC_SIZE = 1024 * 1024;
pub fn init(mb_info: *multiboot.multiboot_info_t) MemProfile {
return MemProfile{
.vaddr_end = @ptrCast([*]u8, &KERNEL_VADDR_END),
.vaddr_start = @ptrCast([*]u8, &KERNEL_VADDR_START),
.physaddr_end = @ptrCast([*]u8, &KERNEL_PHYSADDR_END),
.physaddr_start = @ptrCast([*]u8, &KERNEL_PHYSADDR_START),
// Total memory available including the initial 1MiB that grub doesn't include
.mem_kb = mb_info.mem_upper + mb_info.mem_lower + 1024,
.fixed_alloc_size = FIXED_ALLOC_SIZE,
};
}