Rename KernelMemoryManager to MemoryManager
Kind of a more catchy name, isn't it?
This commit is contained in:
parent
57b330e907
commit
3891d0c52e
@ -5,7 +5,7 @@
|
||||
#define MAP_USER 1 << 1
|
||||
#define MAP_EXEC 1 << 2
|
||||
|
||||
namespace KernelMemoryManager
|
||||
namespace MemoryManager
|
||||
{
|
||||
void* get_mapping(void* physicalAddress, int flags = MAP_READ_WRITE);
|
||||
void release_mapping(void* mapping);
|
@ -3,7 +3,7 @@
|
||||
#include "acpi/RSDT.h"
|
||||
#include "bootboot.h"
|
||||
#include "log/Log.h"
|
||||
#include "memory/KernelMemoryManager.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "std/stdio.h"
|
||||
#include "std/string.h"
|
||||
|
||||
@ -17,14 +17,14 @@ ACPI::SDTHeader* ACPI::GetRSDTOrXSDT()
|
||||
void* physical = (void*)bootboot.arch.x86_64.acpi_ptr;
|
||||
uint64_t offset = (uint64_t)physical % 4096;
|
||||
kdbgln("RSDT/XSDT physical address: %lx", (uint64_t)physical);
|
||||
cache = KernelMemoryManager::get_unaligned_mapping(physical);
|
||||
cache = MemoryManager::get_unaligned_mapping(physical);
|
||||
uint64_t numPages = 1;
|
||||
while ((offset + ((SDTHeader*)cache)->Length) > (numPages * 4096))
|
||||
{
|
||||
kwarnln("RSDT/XSDT extends beyond the mapped page, mapping one more page");
|
||||
KernelMemoryManager::release_unaligned_mappings(cache, numPages);
|
||||
MemoryManager::release_unaligned_mappings(cache, numPages);
|
||||
numPages++;
|
||||
cache = KernelMemoryManager::get_unaligned_mappings(cache, numPages);
|
||||
cache = MemoryManager::get_unaligned_mappings(cache, numPages);
|
||||
}
|
||||
kdbgln("Mapped RSDT/XSDT to virtual address %lx, uses %ld pages", (uint64_t)cache, numPages);
|
||||
SDTHeader* result = (SDTHeader*)cache;
|
||||
@ -86,12 +86,12 @@ void* ACPI::FindTable(ACPI::SDTHeader* rootSDT, const char* signature)
|
||||
continue;
|
||||
}
|
||||
kdbgln("Physical address of entry: %lx", (uint64_t)h);
|
||||
SDTHeader* realHeader = (SDTHeader*)KernelMemoryManager::get_unaligned_mapping(h);
|
||||
SDTHeader* realHeader = (SDTHeader*)MemoryManager::get_unaligned_mapping(h);
|
||||
kdbgln("Mapped entry to virtual address %lx", (uint64_t)realHeader);
|
||||
if (!ValidateSDTHeader(realHeader))
|
||||
{
|
||||
kwarnln("Header of entry %d is not valid, skipping this entry", i);
|
||||
KernelMemoryManager::release_unaligned_mapping(realHeader);
|
||||
MemoryManager::release_unaligned_mapping(realHeader);
|
||||
continue;
|
||||
}
|
||||
char tableSignature[5];
|
||||
@ -104,7 +104,7 @@ void* ACPI::FindTable(ACPI::SDTHeader* rootSDT, const char* signature)
|
||||
return (void*)realHeader;
|
||||
}
|
||||
kdbgln("Signatures do not match, unmapping entry and continuing");
|
||||
KernelMemoryManager::release_unaligned_mapping(realHeader);
|
||||
MemoryManager::release_unaligned_mapping(realHeader);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "gdt/GDT.h"
|
||||
#include "assert.h"
|
||||
#include "log/Log.h"
|
||||
#include "memory/KernelMemoryManager.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "std/string.h"
|
||||
#include <stdint.h>
|
||||
|
||||
@ -84,8 +84,7 @@ void GDT::load()
|
||||
gdtr.offset = (uint64_t)&internal_gdt;
|
||||
gdtr.size = sizeof(InternalGDT);
|
||||
memset(&main_tss, 0, sizeof(TSS));
|
||||
main_tss.rsp[0] =
|
||||
(uint64_t)KernelMemoryManager::get_pages(4) + (4096 * 4) - 8; // allocate 16KB for the syscall stack
|
||||
main_tss.rsp[0] = (uint64_t)MemoryManager::get_pages(4) + (4096 * 4) - 8; // allocate 16KB for the syscall stack
|
||||
set_base(&internal_gdt.tss, (uint64_t)&main_tss & 0xffffffff);
|
||||
internal_gdt.tss2.base_high = (uint64_t)&main_tss >> 32;
|
||||
set_limit(&internal_gdt.tss, sizeof(TSS) - 1);
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "interrupts/Interrupts.h"
|
||||
#include "io/Serial.h"
|
||||
#include "log/Log.h"
|
||||
#include "memory/KernelMemoryManager.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "memory/PMM.h"
|
||||
#include "memory/VMM.h"
|
||||
#include "misc/hang.h"
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "bootboot.h"
|
||||
#include "io/Serial.h"
|
||||
#include "log/Log.h"
|
||||
#include "memory/KernelMemoryManager.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "std/stdlib.h"
|
||||
#include <string.h>
|
||||
|
||||
@ -107,8 +107,7 @@ void InitRD::for_each(void (*callback)(File& f))
|
||||
|
||||
void InitRD::init()
|
||||
{
|
||||
initrd_base =
|
||||
KernelMemoryManager::get_unaligned_mappings((void*)bootboot.initrd_ptr, bootboot.initrd_size / 4096 + 1);
|
||||
initrd_base = MemoryManager::get_unaligned_mappings((void*)bootboot.initrd_ptr, bootboot.initrd_size / 4096 + 1);
|
||||
kdbgln("physical base at %lx, size %lx, mapped to %lx", bootboot.initrd_ptr, bootboot.initrd_size,
|
||||
(uint64_t)initrd_base);
|
||||
}
|
@ -14,8 +14,8 @@
|
||||
#include "io/PIC.h"
|
||||
#include "io/Serial.h"
|
||||
#include "log/Log.h"
|
||||
#include "memory/KernelMemoryManager.h"
|
||||
#include "memory/Memory.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "memory/MemoryMap.h"
|
||||
#include "memory/PMM.h"
|
||||
#include "memory/VMM.h"
|
||||
|
@ -1,17 +1,17 @@
|
||||
#include "memory/KernelMemoryManager.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "assert.h"
|
||||
#include "memory/KernelHeap.h"
|
||||
#include "memory/PMM.h"
|
||||
#include "memory/VMM.h"
|
||||
|
||||
void* KernelMemoryManager::get_mapping(void* physicalAddress, int flags)
|
||||
void* MemoryManager::get_mapping(void* physicalAddress, int flags)
|
||||
{
|
||||
uint64_t virtualAddress = KernelHeap::request_virtual_page();
|
||||
kernelVMM.map(virtualAddress, (uint64_t)physicalAddress, flags);
|
||||
return (void*)virtualAddress;
|
||||
}
|
||||
|
||||
void* KernelMemoryManager::get_unaligned_mapping(void* physicalAddress, int flags)
|
||||
void* MemoryManager::get_unaligned_mapping(void* physicalAddress, int flags)
|
||||
{
|
||||
uint64_t offset = (uint64_t)physicalAddress % 4096;
|
||||
uint64_t virtualAddress = KernelHeap::request_virtual_page();
|
||||
@ -19,7 +19,7 @@ void* KernelMemoryManager::get_unaligned_mapping(void* physicalAddress, int flag
|
||||
return (void*)(virtualAddress + offset);
|
||||
}
|
||||
|
||||
void* KernelMemoryManager::get_unaligned_mappings(void* physicalAddress, uint64_t count, int flags)
|
||||
void* MemoryManager::get_unaligned_mappings(void* physicalAddress, uint64_t count, int flags)
|
||||
{
|
||||
uint64_t offset = (uint64_t)physicalAddress % 4096;
|
||||
uint64_t virtualAddress = KernelHeap::request_virtual_pages(count);
|
||||
@ -30,27 +30,27 @@ void* KernelMemoryManager::get_unaligned_mappings(void* physicalAddress, uint64_
|
||||
return (void*)(virtualAddress + offset);
|
||||
}
|
||||
|
||||
void KernelMemoryManager::release_unaligned_mapping(void* mapping)
|
||||
void MemoryManager::release_unaligned_mapping(void* mapping)
|
||||
{
|
||||
uint64_t offset = (uint64_t)mapping % 4096;
|
||||
kernelVMM.unmap((uint64_t)mapping - offset);
|
||||
KernelHeap::free_virtual_page((uint64_t)mapping - offset);
|
||||
}
|
||||
|
||||
void KernelMemoryManager::release_unaligned_mappings(void* mapping, uint64_t count)
|
||||
void MemoryManager::release_unaligned_mappings(void* mapping, uint64_t count)
|
||||
{
|
||||
uint64_t offset = (uint64_t)mapping % 4096;
|
||||
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)); }
|
||||
}
|
||||
|
||||
void KernelMemoryManager::release_mapping(void* mapping)
|
||||
void MemoryManager::release_mapping(void* mapping)
|
||||
{
|
||||
kernelVMM.unmap((uint64_t)mapping);
|
||||
KernelHeap::free_virtual_page((uint64_t)mapping);
|
||||
}
|
||||
|
||||
void* KernelMemoryManager::get_page(int flags)
|
||||
void* MemoryManager::get_page(int flags)
|
||||
{
|
||||
void* physicalAddress = PMM::request_page();
|
||||
uint64_t virtualAddress = KernelHeap::request_virtual_page();
|
||||
@ -58,7 +58,7 @@ void* KernelMemoryManager::get_page(int flags)
|
||||
return (void*)virtualAddress;
|
||||
}
|
||||
|
||||
void KernelMemoryManager::release_page(void* page)
|
||||
void MemoryManager::release_page(void* page)
|
||||
{
|
||||
uint64_t physicalAddress = kernelVMM.getPhysical((uint64_t)page);
|
||||
ASSERT(physicalAddress != UINT64_MAX);
|
||||
@ -66,7 +66,7 @@ void KernelMemoryManager::release_page(void* page)
|
||||
PMM::free_page((void*)physicalAddress);
|
||||
}
|
||||
|
||||
void* KernelMemoryManager::get_pages(uint64_t count, int flags)
|
||||
void* MemoryManager::get_pages(uint64_t count, int flags)
|
||||
{
|
||||
uint64_t virtualAddress = KernelHeap::request_virtual_pages(count);
|
||||
for (uint64_t i = 0; i < count; i++)
|
||||
@ -77,7 +77,7 @@ void* KernelMemoryManager::get_pages(uint64_t count, int flags)
|
||||
return (void*)virtualAddress;
|
||||
}
|
||||
|
||||
void KernelMemoryManager::release_pages(void* pages, uint64_t count)
|
||||
void MemoryManager::release_pages(void* pages, uint64_t count)
|
||||
{
|
||||
for (uint64_t i = 0; i < count; i++)
|
||||
{
|
@ -3,8 +3,8 @@
|
||||
#include "memory/PMM.h"
|
||||
#include "assert.h"
|
||||
#include "bootboot.h"
|
||||
#include "memory/KernelMemoryManager.h"
|
||||
#include "memory/Memory.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "std/string.h"
|
||||
|
||||
extern BOOTBOOT bootboot;
|
||||
@ -47,7 +47,8 @@ void PMM::init()
|
||||
}
|
||||
|
||||
bitmap_addr = (char*)biggest_chunk;
|
||||
virtual_bitmap_addr = bitmap_addr;
|
||||
virtual_bitmap_addr =
|
||||
bitmap_addr; // FIXME: map this to a virtual address (ideally in the kernel heap between -128M and -64M)
|
||||
ASSERT((total_mem / 4096 / 8) < biggest_chunk_size);
|
||||
bitmap_size = total_mem / 4096 / 8 + 1;
|
||||
memset(bitmap_addr, 0xFF, bitmap_size);
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "assert.h"
|
||||
#include "interrupts/Interrupts.h"
|
||||
#include "log/Log.h"
|
||||
#include "memory/KernelMemoryManager.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "memory/VMM.h"
|
||||
#include "misc/hang.h"
|
||||
#include "std/string.h"
|
||||
@ -34,7 +34,7 @@ void Scheduler::init()
|
||||
memset(&idle_task, 0, sizeof(Task));
|
||||
idle_task.id = free_tid++;
|
||||
idle_task.regs.rip = (uint64_t)&idle_task_function;
|
||||
idle_task.regs.rsp = (uint64_t)KernelMemoryManager::get_page();
|
||||
idle_task.regs.rsp = (uint64_t)MemoryManager::get_page();
|
||||
idle_task.regs.cs = 0x08;
|
||||
idle_task.regs.ss = 0x10;
|
||||
asm volatile("pushfq; movq (%%rsp), %%rax; movq %%rax, %0; popfq;" : "=m"(idle_task.regs.rflags)::"%rax");
|
||||
@ -42,7 +42,7 @@ void Scheduler::init()
|
||||
idle_task.task_sleep = 1000;
|
||||
idle_task.state = idle_task.Idle;
|
||||
|
||||
base_task = (Task*)KernelMemoryManager::get_page();
|
||||
base_task = (Task*)MemoryManager::get_page();
|
||||
memset(base_task, 0, sizeof(Task));
|
||||
end_task = base_task;
|
||||
sched_current_task = base_task;
|
||||
@ -59,12 +59,12 @@ void Scheduler::init()
|
||||
|
||||
void Scheduler::add_kernel_task(void (*task)(void))
|
||||
{
|
||||
Task* new_task = (Task*)KernelMemoryManager::get_page(); // FIXME: allocate memory the size of Task, not 4 KB for
|
||||
// each task (YES, I know, I need malloc)
|
||||
Task* new_task = (Task*)MemoryManager::get_page(); // FIXME: allocate memory the size of Task, not 4 KB for
|
||||
// each task (YES, I know, I need malloc)
|
||||
memset(new_task, 0, sizeof(Task));
|
||||
new_task->id = free_tid++;
|
||||
new_task->regs.rip = (uint64_t)task;
|
||||
new_task->allocated_stack = (uint64_t)KernelMemoryManager::get_pages(4); // 16 KB is enough for everyone, right?
|
||||
new_task->allocated_stack = (uint64_t)MemoryManager::get_pages(4); // 16 KB is enough for everyone, right?
|
||||
new_task->regs.rsp = new_task->allocated_stack + (4096 * 4) - sizeof(uintptr_t);
|
||||
new_task->regs.cs = 0x08;
|
||||
new_task->regs.ss = 0x10;
|
||||
@ -86,11 +86,11 @@ void Scheduler::add_kernel_task(void (*task)(void))
|
||||
void Scheduler::add_user_task(void* task)
|
||||
{
|
||||
Task* new_task =
|
||||
(Task*)KernelMemoryManager::get_page(); // FIXME: allocate memory the size of Task, not 4 KB for each task
|
||||
(Task*)MemoryManager::get_page(); // FIXME: allocate memory the size of Task, not 4 KB for each task
|
||||
new_task->id = free_tid++;
|
||||
new_task->regs.rip = (uint64_t)task;
|
||||
new_task->allocated_stack =
|
||||
(uint64_t)KernelMemoryManager::get_pages(4, MAP_READ_WRITE | MAP_USER); // 16 KB is enough for everyone, right?
|
||||
(uint64_t)MemoryManager::get_pages(4, MAP_READ_WRITE | MAP_USER); // 16 KB is enough for everyone, right?
|
||||
new_task->regs.rsp = new_task->allocated_stack + (4096 * 4) - sizeof(uintptr_t);
|
||||
new_task->regs.cs = 0x18 | 0x03;
|
||||
new_task->regs.ss = 0x20 | 0x03;
|
||||
@ -114,8 +114,8 @@ void Scheduler::reap_task(Task* task)
|
||||
task_num--;
|
||||
Task* exiting_task = task;
|
||||
kinfoln("reaping task %ld", exiting_task->id);
|
||||
if (exiting_task->allocated_stack) KernelMemoryManager::release_pages((void*)exiting_task->allocated_stack, 4);
|
||||
KernelMemoryManager::release_page((void*)exiting_task);
|
||||
if (exiting_task->allocated_stack) MemoryManager::release_pages((void*)exiting_task->allocated_stack, 4);
|
||||
MemoryManager::release_page((void*)exiting_task);
|
||||
}
|
||||
|
||||
void Scheduler::task_exit(Context* context)
|
||||
|
Loading…
Reference in New Issue
Block a user