Luna/kernel/src/memory/Memory.cpp

54 lines
1.0 KiB
C++
Raw Normal View History

#include "memory/Memory.h"
#include "bootboot.h"
extern BOOTBOOT bootboot;
uint64_t Memory::get_system()
{
static uint64_t result = 0;
static bool cached = false;
if (cached) return result;
MMapEnt* ptr = &bootboot.mmap;
uint64_t mmap_entries = (bootboot.size - 128) / 16;
for (uint64_t i = 0; i < mmap_entries; i++)
{
result += MMapEnt_Size(ptr);
ptr++;
}
cached = true;
return result;
}
uint64_t Memory::get_usable()
{
static uint64_t result = 0;
static bool cached = false;
if (cached) return result;
MMapEnt* ptr = &bootboot.mmap;
uint64_t mmap_entries = (bootboot.size - 128) / 16;
for (uint64_t i = 0; i < mmap_entries; i++)
{
if (MMapEnt_IsFree(ptr)) result += MMapEnt_Size(ptr);
ptr++;
}
cached = true;
return result;
}
bool Memory::is_kernel_address(uintptr_t address)
{
return address >= 0xfffffffff8000000;
}
bool Memory::is_user_address(uintptr_t address)
{
return address && address < 0xfffffffff8000000;
}