fix: Various general fixes and changes
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <System/Registers.hpp>
|
#include <Platform/Registers.hpp>
|
||||||
#include <Terminal/terminal.hpp>
|
#include <Terminal/terminal.hpp>
|
||||||
|
|
||||||
void Panic(const char *meditationString, System::Registers registers);
|
void Panic(const char *meditationString, System::Registers registers);
|
||||||
@@ -9,10 +9,10 @@
|
|||||||
|
|
||||||
void* operator new(std::size_t size)
|
void* operator new(std::size_t size)
|
||||||
{
|
{
|
||||||
return Memory::g_allocator->Request(size);
|
return Memory::g_heap->Request(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator delete(void* block)
|
void operator delete(void* block)
|
||||||
{
|
{
|
||||||
Memory::g_allocator->Free(block);
|
Memory::g_heap->Free(block);
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@ kcp::cstringstream::~cstringstream()
|
|||||||
}
|
}
|
||||||
|
|
||||||
kcp::cstringstream& kcp::cstringstream::operator<<(char c) {
|
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)
|
if (!this->string)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace kcp
|
|||||||
}
|
}
|
||||||
|
|
||||||
void push_back(T value) {
|
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;
|
array[sz++] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-20
@@ -19,7 +19,7 @@ namespace Memory
|
|||||||
#error Sorry, Unimplemented!
|
#error Sorry, Unimplemented!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Allocator::Allocator(LargestSection section)
|
HeapAllocator::HeapAllocator(LargestSection section)
|
||||||
{
|
{
|
||||||
g_section = section;
|
g_section = section;
|
||||||
|
|
||||||
@@ -36,22 +36,21 @@ namespace Memory
|
|||||||
|
|
||||||
current_ref->next = start_block_ptr;
|
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* HeapAllocator::Request(size_t size, bool phys) {
|
||||||
void* Allocator::Request(size_t size, bool phys) {
|
|
||||||
Block* current_block_ptr{head.next};
|
Block* current_block_ptr{head.next};
|
||||||
Block* current_prev_ptr{(Block *)&head};
|
Block* current_prev_ptr{(Block *)&head};
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (current_block_ptr == nullptr) {
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_prev_ptr == 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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,21 +87,21 @@ namespace Memory
|
|||||||
|
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} 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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_block_ptr != nullptr) {
|
if (current_block_ptr != nullptr) {
|
||||||
if (current_block_ptr->next == 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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_block_ptr = current_block_ptr->next;
|
current_block_ptr = current_block_ptr->next;
|
||||||
} else
|
} 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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,7 +109,7 @@ namespace Memory
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Allocator::Realloc(void* ptr, size_t size) {
|
void* HeapAllocator::Realloc(void* ptr, size_t size) {
|
||||||
void *new_block = this->Request(size);
|
void *new_block = this->Request(size);
|
||||||
|
|
||||||
if (ptr == nullptr) {
|
if (ptr == nullptr) {
|
||||||
@@ -118,7 +117,7 @@ namespace Memory
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (new_block == nullptr) {
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +130,7 @@ namespace Memory
|
|||||||
return new_block;
|
return new_block;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Allocator::Free(void *pagePtr) {
|
void HeapAllocator::Free(void *pagePtr) {
|
||||||
if (!IsHDDMVirtAddr((uint64_t)pagePtr)) {
|
if (!IsHDDMVirtAddr((uint64_t)pagePtr)) {
|
||||||
pagePtr = (void *)HHDM(pagePtr);
|
pagePtr = (void *)HHDM(pagePtr);
|
||||||
}
|
}
|
||||||
@@ -152,16 +151,9 @@ namespace Memory
|
|||||||
// Attach the merged block to the structure
|
// Attach the merged block to the structure
|
||||||
head.next->next = fmrNext;
|
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
|
// Traverses the Allocator's linked list for debugging
|
||||||
void Allocator::Walk() {
|
void HeapAllocator::Walk() {
|
||||||
Block* current = {head.next};
|
Block* current = {head.next};
|
||||||
size_t i{0};
|
size_t i{0};
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "Memmap.hpp"
|
#include "Memmap.hpp"
|
||||||
|
|
||||||
namespace Memory {
|
namespace Memory {
|
||||||
class Allocator {
|
class HeapAllocator {
|
||||||
LargestSection g_section;
|
LargestSection g_section;
|
||||||
|
|
||||||
struct Block {
|
struct Block {
|
||||||
@@ -16,14 +16,12 @@ namespace Memory {
|
|||||||
|
|
||||||
Block head;
|
Block head;
|
||||||
public:
|
public:
|
||||||
Allocator(LargestSection section);
|
HeapAllocator(LargestSection section);
|
||||||
void* Request(size_t size, bool phys = false);
|
void* Request(size_t size, bool phys = false);
|
||||||
void* Realloc(void* ptr, size_t size);
|
void* Realloc(void* ptr, size_t size);
|
||||||
void Free(void *pagePtr);
|
void Free(void *pagePtr);
|
||||||
|
|
||||||
void Stress();
|
|
||||||
void Walk();
|
void Walk();
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Allocator* g_allocator;
|
extern HeapAllocator* g_heap;
|
||||||
};
|
};
|
||||||
+5
-12
@@ -22,7 +22,7 @@
|
|||||||
using namespace Kt;
|
using namespace Kt;
|
||||||
|
|
||||||
namespace Memory {
|
namespace Memory {
|
||||||
Allocator* g_allocator;
|
HeapAllocator* g_heap;
|
||||||
uint64_t HHDMBase;
|
uint64_t HHDMBase;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -215,14 +215,6 @@ extern "C" void kmain() {
|
|||||||
Hal::BridgeLoadGDT();
|
Hal::BridgeLoadGDT();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// RGB lines
|
|
||||||
for (std::size_t i = 500; i < 800; i++) {
|
|
||||||
volatile std::uint32_t *fb_ptr = static_cast<volatile std::uint32_t *>(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;
|
uint64_t hhdm_offset = hhdm_request.response->offset;
|
||||||
|
|
||||||
kout << "[Mem] HHDM offset: 0x" << base::hex << hhdm_offset << newline;
|
kout << "[Mem] HHDM offset: 0x" << base::hex << hhdm_offset << newline;
|
||||||
@@ -230,8 +222,9 @@ extern "C" void kmain() {
|
|||||||
Memory::HHDMBase = hhdm_offset;
|
Memory::HHDMBase = hhdm_offset;
|
||||||
|
|
||||||
if (!system_table_request. response || !system_table_request.response->address) {
|
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 {
|
} else {
|
||||||
|
kout << "[Mp] Firmware type: EFI" << newline;
|
||||||
kout << "[Efi] EFI system table at 0x" << base::hex << (uint64_t)system_table_request.response->address << 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;
|
kout << "[Mem] Creating Allocator for system conventional memory" << newline;
|
||||||
|
|
||||||
auto result = Memory::Scan(memmap_request.response);
|
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 {
|
} else {
|
||||||
Panic("Guru Meditation Error: System memory map missing!", System::Registers{});
|
Panic("Guru Meditation Error: System memory map missing!", System::Registers{});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user