Memory::get_system and Memory::get_usable

This commit is contained in:
apio 2022-09-05 17:13:12 +02:00
parent 1367e88d88
commit 6a6be3292d
3 changed files with 55 additions and 12 deletions

View File

@ -0,0 +1,8 @@
#pragma once
#include <stdint.h>
namespace Memory
{
uint64_t get_system();
uint64_t get_usable();
}

View File

@ -13,6 +13,7 @@
#include "io/Serial.h"
#include "log/Log.h"
#include "memory/KernelHeap.h"
#include "memory/Memory.h"
#include "panic/hang.h"
#include "render/BBRenderer.h"
#include "render/Draw.h"
@ -65,24 +66,14 @@ extern "C" void _start()
kinfoln("Prepared PIT");
uint64_t mmap_entries = (bootboot.size - 128) / 16;
MMapEnt* entry = (&bootboot.mmap);
for (uint64_t i = 0; i < mmap_entries; i++)
{
if (MMapEnt_IsFree(entry))
{
printf("Free region at 0x%zx, of size 0x%zx\n", MMapEnt_Ptr(entry), MMapEnt_Size(entry));
}
else { printf("Used region at 0x%zx, of size 0x%zx\n", MMapEnt_Ptr(entry), MMapEnt_Size(entry)); }
entry++;
}
Debug::DebugStatus::the()->StartBootStage(Color::Yellow);
Interrupts::enable();
Debug::DebugStatus::the()->PassBootStage(Color::Yellow);
kinfoln("Interrupts enabled");
printf("%d KB of system memory, %d KB available\n", Memory::get_system() / 1024, Memory::get_usable() / 1024);
Debug::DebugStatus::the()->StartBootStage(Color{0x33, 0x33, 0x00, 0xFF});
ACPI::SDTHeader* rootSDT = ACPI::GetRSDTOrXSDT();
bool isXSDT = false;

View File

@ -0,0 +1,44 @@
#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;
}