diff --git a/kernel/include/memory/Memory.h b/kernel/include/memory/Memory.h new file mode 100644 index 00000000..e7663dcd --- /dev/null +++ b/kernel/include/memory/Memory.h @@ -0,0 +1,8 @@ +#pragma once +#include + +namespace Memory +{ + uint64_t get_system(); + uint64_t get_usable(); +} \ No newline at end of file diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index 293297eb..2268494a 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -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; diff --git a/kernel/src/memory/Memory.cpp b/kernel/src/memory/Memory.cpp new file mode 100644 index 00000000..81e8b046 --- /dev/null +++ b/kernel/src/memory/Memory.cpp @@ -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; +} \ No newline at end of file