mtgos-kernel/kernel/hw/pc/pmm/pmm.cpp

37 lines
1.3 KiB
C++
Raw Normal View History

2017-07-20 16:48:44 +00:00
#include "pmm.hpp"
PMM_MB::PMM_MB(multiboot_info_t *mb_info): PMM(0x1000), mb_info(mb_info) {
auto mmap = (multiboot_memory_map_t*)((uintptr_t)(mb_info->mmap_addr));
uint32_t count = mb_info->mmap_length / sizeof(mmap[0]);
for(uint32_t i=0;i<count;i++) {
if(mmap[i].type != MULTIBOOT_MEMORY_AVAILABLE)
continue;
if((phys_t)mmap[i].addr < lowest_page)
lowest_page = (phys_t)mmap[i].addr;
if((phys_t)(mmap[i].addr + mmap[i].len) > highest_page)
highest_page = (phys_t)(mmap[i].addr + mmap[i].len);
}
fill();
}
2017-07-20 16:48:44 +00:00
PMM_MB::~PMM_MB() {}
auto PMM_MB::isFree(phys_t addr) -> bool {
auto mmap = (multiboot_memory_map_t*)((uintptr_t)(mb_info->mmap_addr));
bool free=false;
uint32_t count = mb_info->mmap_length / sizeof(mmap[0]);
for(uint32_t i=0;i<count;i++) {
2017-07-20 16:48:44 +00:00
if((mmap[i].addr > addr) || (mmap[i].addr + mmap[i].len < addr))
continue;
if(mmap[i].type != MULTIBOOT_MEMORY_AVAILABLE)
return false;
free=true;
}
if(!free)
return false;
2017-09-03 08:56:58 +00:00
if((addr >= (phys_t)((uintptr_t)mb_info)) && (addr < (phys_t)((uintptr_t)mb_info)+0x1000))
2017-07-20 16:48:44 +00:00
return false;
if(addr <= 0x100000)
return false;
2017-07-20 16:48:44 +00:00
return PMM::isFree(addr);
}