44 lines
850 B
C++
44 lines
850 B
C++
|
#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;
|
||
|
}
|