Move PMM and VMM initialization into MemoryManager::init
This commit is contained in:
parent
0858db73bd
commit
a078a11dde
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
namespace MemoryManager
|
namespace MemoryManager
|
||||||
{
|
{
|
||||||
|
void init();
|
||||||
|
|
||||||
void* get_mapping(void* physicalAddress, int flags = MAP_READ_WRITE);
|
void* get_mapping(void* physicalAddress, int flags = MAP_READ_WRITE);
|
||||||
void release_mapping(void* mapping);
|
void release_mapping(void* mapping);
|
||||||
|
|
||||||
|
@ -40,8 +40,7 @@ void Init::early_init()
|
|||||||
framebuffer0.init((void*)bootboot.fb_ptr, bootboot.fb_type, bootboot.fb_scanline, bootboot.fb_width,
|
framebuffer0.init((void*)bootboot.fb_ptr, bootboot.fb_type, bootboot.fb_scanline, bootboot.fb_width,
|
||||||
bootboot.fb_height);
|
bootboot.fb_height);
|
||||||
|
|
||||||
PMM::init();
|
MemoryManager::init();
|
||||||
kernelVMM.init();
|
|
||||||
|
|
||||||
InitRD::init();
|
InitRD::init();
|
||||||
|
|
||||||
|
@ -9,6 +9,12 @@
|
|||||||
#include "memory/PMM.h"
|
#include "memory/PMM.h"
|
||||||
#include "memory/VMM.h"
|
#include "memory/VMM.h"
|
||||||
|
|
||||||
|
void MemoryManager::init()
|
||||||
|
{
|
||||||
|
PMM::init();
|
||||||
|
kernelVMM.init();
|
||||||
|
}
|
||||||
|
|
||||||
void* MemoryManager::get_mapping(void* physicalAddress, int flags)
|
void* MemoryManager::get_mapping(void* physicalAddress, int flags)
|
||||||
{
|
{
|
||||||
uint64_t virtualAddress = KernelHeap::request_virtual_page();
|
uint64_t virtualAddress = KernelHeap::request_virtual_page();
|
||||||
@ -40,6 +46,8 @@ void* MemoryManager::get_unaligned_mapping(void* physicalAddress, int flags)
|
|||||||
|
|
||||||
void* MemoryManager::get_unaligned_mappings(void* physicalAddress, uint64_t count, int flags)
|
void* MemoryManager::get_unaligned_mappings(void* physicalAddress, uint64_t count, int flags)
|
||||||
{
|
{
|
||||||
|
if (!count) return 0;
|
||||||
|
if (count == 1) return get_unaligned_mapping(physicalAddress, flags);
|
||||||
uint64_t offset = (uint64_t)physicalAddress % 4096;
|
uint64_t offset = (uint64_t)physicalAddress % 4096;
|
||||||
uint64_t virtualAddress = KernelHeap::request_virtual_pages(count);
|
uint64_t virtualAddress = KernelHeap::request_virtual_pages(count);
|
||||||
if (!virtualAddress)
|
if (!virtualAddress)
|
||||||
@ -67,13 +75,8 @@ void MemoryManager::release_unaligned_mapping(void* mapping)
|
|||||||
|
|
||||||
void MemoryManager::release_unaligned_mappings(void* mapping, uint64_t count)
|
void MemoryManager::release_unaligned_mappings(void* mapping, uint64_t count)
|
||||||
{
|
{
|
||||||
if (!count)
|
if (!count) return;
|
||||||
{
|
if (count == 1) return release_unaligned_mapping(mapping);
|
||||||
#ifdef MM_DEBUG
|
|
||||||
kwarnln("weird... got asked to free 0 pages of virtual memory");
|
|
||||||
#endif
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
uint64_t offset = (uint64_t)mapping % 4096;
|
uint64_t offset = (uint64_t)mapping % 4096;
|
||||||
KernelHeap::free_virtual_pages((uint64_t)mapping - offset, count);
|
KernelHeap::free_virtual_pages((uint64_t)mapping - offset, count);
|
||||||
for (uint64_t i = 0; i < count; i++) { kernelVMM.unmap(((uint64_t)mapping - offset) + (i * 4096)); }
|
for (uint64_t i = 0; i < count; i++) { kernelVMM.unmap(((uint64_t)mapping - offset) + (i * 4096)); }
|
||||||
@ -117,6 +120,8 @@ void MemoryManager::release_page(void* page)
|
|||||||
|
|
||||||
void* MemoryManager::get_pages(uint64_t count, int flags)
|
void* MemoryManager::get_pages(uint64_t count, int flags)
|
||||||
{
|
{
|
||||||
|
if (!count) return 0;
|
||||||
|
if (count == 1) return get_page(flags);
|
||||||
#ifdef MM_DEBUG
|
#ifdef MM_DEBUG
|
||||||
kdbgln("allocating several pages (%ld)", count);
|
kdbgln("allocating several pages (%ld)", count);
|
||||||
#endif
|
#endif
|
||||||
@ -152,6 +157,8 @@ void* MemoryManager::get_pages(uint64_t count, int flags)
|
|||||||
|
|
||||||
void MemoryManager::release_pages(void* pages, uint64_t count)
|
void MemoryManager::release_pages(void* pages, uint64_t count)
|
||||||
{
|
{
|
||||||
|
if (!count) return;
|
||||||
|
if (count == 1) return release_page(pages);
|
||||||
#ifdef MM_DEBUG
|
#ifdef MM_DEBUG
|
||||||
kdbgln("releasing several pages (%ld)", count);
|
kdbgln("releasing several pages (%ld)", count);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user