diff --git a/kernel/src/Common/Panic.hpp b/kernel/src/Common/Panic.hpp index b342b4d..62182a5 100644 --- a/kernel/src/Common/Panic.hpp +++ b/kernel/src/Common/Panic.hpp @@ -1,5 +1,5 @@ #pragma once -#include +#include #include void Panic(const char *meditationString, System::Registers registers); \ No newline at end of file diff --git a/kernel/src/CppLib/Alloc.cpp b/kernel/src/CppLib/Alloc.cpp index 82fbfb6..df4dca3 100644 --- a/kernel/src/CppLib/Alloc.cpp +++ b/kernel/src/CppLib/Alloc.cpp @@ -9,10 +9,10 @@ void* operator new(std::size_t size) { - return Memory::g_allocator->Request(size); + return Memory::g_heap->Request(size); } void operator delete(void* block) { - Memory::g_allocator->Free(block); + Memory::g_heap->Free(block); } \ No newline at end of file diff --git a/kernel/src/CppLib/Stream.cpp b/kernel/src/CppLib/Stream.cpp index 10fafe1..de163ad 100644 --- a/kernel/src/CppLib/Stream.cpp +++ b/kernel/src/CppLib/Stream.cpp @@ -21,7 +21,7 @@ kcp::cstringstream::~cstringstream() } kcp::cstringstream& kcp::cstringstream::operator<<(char c) { - this->string = (const char *)Memory::g_allocator->Realloc((void *)this->string, this->size + 1); + this->string = (const char *)Memory::g_heap->Realloc((void *)this->string, this->size + 1); if (!this->string) { diff --git a/kernel/src/CppLib/Vector.hpp b/kernel/src/CppLib/Vector.hpp index 56e7fab..5118015 100644 --- a/kernel/src/CppLib/Vector.hpp +++ b/kernel/src/CppLib/Vector.hpp @@ -41,7 +41,7 @@ namespace kcp } void push_back(T value) { - array = (T *)Memory::g_allocator->Realloc(array, sizeof(T) * (sz + 1)); + array = (T *)Memory::g_heap->Realloc(array, sizeof(T) * (sz + 1)); array[sz++] = value; } diff --git a/kernel/src/Memory/Heap.cpp b/kernel/src/Memory/Heap.cpp index a445c7c..8231c3b 100644 --- a/kernel/src/Memory/Heap.cpp +++ b/kernel/src/Memory/Heap.cpp @@ -19,7 +19,7 @@ namespace Memory #error Sorry, Unimplemented! #endif - Allocator::Allocator(LargestSection section) + HeapAllocator::HeapAllocator(LargestSection section) { g_section = section; @@ -36,22 +36,21 @@ namespace Memory current_ref->next = start_block_ptr; - kout << "[Mem] Allocator created for memory section starting at 0x" << base::hex << section.address << Kt::newline; + kout << "[Mem] HeapAllocator object created for memory section starting at 0x" << base::hex << section.address << Kt::newline; } - int i = 1; - void* Allocator::Request(size_t size, bool phys) { + void* HeapAllocator::Request(size_t size, bool phys) { Block* current_block_ptr{head.next}; Block* current_prev_ptr{(Block *)&head}; while (true) { if (current_block_ptr == nullptr) { - kerr << "An allocator was forced to return a Null pointer. (1)" << Kt::newline; + kerr << "A HeapAllocator was forced to return a Null pointer. (1)" << Kt::newline; return nullptr; } if (current_prev_ptr == nullptr) { - kerr << "An allocator was forced to return a Null pointer. (2)" << Kt::newline; + kerr << "An HeapAllocator was forced to return a Null pointer. (2)" << Kt::newline; return nullptr; } @@ -88,21 +87,21 @@ namespace Memory continue; } else { - kerr << "An allocator was forced to return a Null pointer. (3)" << Kt::newline; + kerr << "An HeapAllocator was forced to return a Null pointer. (3)" << Kt::newline; return nullptr; } } if (current_block_ptr != nullptr) { if (current_block_ptr->next == nullptr) { - kerr << "An allocator was forced to return a Null pointer. (4)" << Kt::newline; + kerr << "An HeapAllocator was forced to return a Null pointer. (4)" << Kt::newline; return nullptr; } current_block_ptr = current_block_ptr->next; } else { - kerr << "An allocator was forced to return a Null pointer. (5)" << Kt::newline; + kerr << "An HeapAllocator was forced to return a Null pointer. (5)" << Kt::newline; return nullptr; } } @@ -110,7 +109,7 @@ namespace Memory return nullptr; } - void* Allocator::Realloc(void* ptr, size_t size) { + void* HeapAllocator::Realloc(void* ptr, size_t size) { void *new_block = this->Request(size); if (ptr == nullptr) { @@ -118,7 +117,7 @@ namespace Memory } if (new_block == nullptr) { - kerr << "Reallocation failed due to memory starvation" << Kt::newline; + kerr << "HeapAllocator: Reallocation failed due to memory starvation" << Kt::newline; return nullptr; } @@ -131,7 +130,7 @@ namespace Memory return new_block; } - void Allocator::Free(void *pagePtr) { + void HeapAllocator::Free(void *pagePtr) { if (!IsHDDMVirtAddr((uint64_t)pagePtr)) { pagePtr = (void *)HHDM(pagePtr); } @@ -152,16 +151,9 @@ namespace Memory // Attach the merged block to the structure head.next->next = fmrNext; } - - void Allocator::Stress() { - // ~410 MiB - for (size_t i = 0; i < 100000; i++) { - kout << "[Mem] Stress allocation " << base::dec << i << ": " << "0x" << base::hex << (uint64_t)this->Request(PAGE_SIZE, false) << Kt::newline; - } - } // Traverses the Allocator's linked list for debugging - void Allocator::Walk() { + void HeapAllocator::Walk() { Block* current = {head.next}; size_t i{0}; diff --git a/kernel/src/Memory/Heap.hpp b/kernel/src/Memory/Heap.hpp index 641e7fe..dcdc0cd 100644 --- a/kernel/src/Memory/Heap.hpp +++ b/kernel/src/Memory/Heap.hpp @@ -2,7 +2,7 @@ #include "Memmap.hpp" namespace Memory { - class Allocator { + class HeapAllocator { LargestSection g_section; struct Block { @@ -16,14 +16,12 @@ namespace Memory { Block head; public: - Allocator(LargestSection section); + HeapAllocator(LargestSection section); void* Request(size_t size, bool phys = false); void* Realloc(void* ptr, size_t size); void Free(void *pagePtr); - - void Stress(); void Walk(); }; - extern Allocator* g_allocator; + extern HeapAllocator* g_heap; }; \ No newline at end of file diff --git a/kernel/src/System/Registers.hpp b/kernel/src/Platform/Registers.hpp similarity index 100% rename from kernel/src/System/Registers.hpp rename to kernel/src/Platform/Registers.hpp diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index 93eacd4..6634449 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -22,7 +22,7 @@ using namespace Kt; namespace Memory { - Allocator* g_allocator; + HeapAllocator* g_heap; uint64_t HHDMBase; }; @@ -215,14 +215,6 @@ extern "C" void kmain() { Hal::BridgeLoadGDT(); #endif - // RGB lines - for (std::size_t i = 500; i < 800; i++) { - volatile std::uint32_t *fb_ptr = static_cast(framebuffer->address); - fb_ptr[i * (framebuffer->pitch / 4) + (i - 5*5)] = 0xFF0000; // Red - fb_ptr[i * (framebuffer->pitch / 4) + (i - 10*5)] = 0x00FF00; // Green - fb_ptr[i * (framebuffer->pitch / 4) + (i - 15*5)] = 0x0000FF; // Blue - } - uint64_t hhdm_offset = hhdm_request.response->offset; kout << "[Mem] HHDM offset: 0x" << base::hex << hhdm_offset << newline; @@ -230,8 +222,9 @@ extern "C" void kmain() { Memory::HHDMBase = hhdm_offset; if (!system_table_request. response || !system_table_request.response->address) { - kerr << "[Efi] EFI System Table not supported" << newline; + kout << "[Mp] Firmware type: PC BIOS" << newline; } else { + kout << "[Mp] Firmware type: EFI" << newline; kout << "[Efi] EFI system table at 0x" << base::hex << (uint64_t)system_table_request.response->address << newline; } @@ -239,9 +232,9 @@ extern "C" void kmain() { kout << "[Mem] Creating Allocator for system conventional memory" << newline; auto result = Memory::Scan(memmap_request.response); - auto allocator = Memory::Allocator(result); + auto allocator = Memory::HeapAllocator(result); - Memory::g_allocator = &allocator; + Memory::g_heap = &allocator; } else { Panic("Guru Meditation Error: System memory map missing!", System::Registers{}); }