Files
MontaukOS/kernel/src/Memory/Memmap.cpp
T

37 lines
961 B
C++

#include "Memmap.hpp"
#include <Terminal/Terminal.hpp>
#include <Common/Panic.hpp>
#include "Heap.hpp"
using namespace Kt;
namespace Memory {
LargestSection Scan(const montauk::boot::MemoryMap& mmap) {
LargestSection currentLargestSection{};
for (size_t i = 0; i < mmap.count; i++) {
const auto& entry = mmap.regions[i];
if (entry.base == 0) {
continue;
}
if (entry.kind == montauk::boot::MemoryKind::Usable) {
if (entry.length > currentLargestSection.size) {
currentLargestSection = {
.address = entry.base,
.size = entry.length
};
}
}
}
[[unlikely]] if (currentLargestSection.address == 0) {
Panic("Couldn't find a usable memory section.", nullptr);
}
return currentLargestSection;
}
};