From fe47e0d5cb04c0e36df2001430dd6b439504f25a Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 30 Nov 2022 16:30:42 +0100 Subject: [PATCH] Clean init() up --- kernel/src/main.cpp | 47 +++-------------------------- kernel/src/memory/MemoryManager.cpp | 5 +++ kernel/src/memory/MemoryManager.h | 1 + 3 files changed, 10 insertions(+), 43 deletions(-) diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index 25d8c2fc..135a0078 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -17,61 +17,22 @@ Result init() Serial::println(TRY(CPU::identify())); - const u64 address = 0xfffffffff8000000; - - Serial::printf("Mapping address 0x%lx\n", address); - - TRY(MemoryManager::alloc_at(address, 1, MMU::ReadWrite)); - - TRY(MMU::remap(address, MMU::ReadWrite | MMU::User)); - - int flags = TRY(MMU::get_flags(address)); - - if (flags & MMU::ReadWrite) Serial::println("Mapping is now writable"); - if (flags & MMU::User) Serial::println("Mapping is now user accessible"); - - u64 old = TRY(MMU::unmap(address)); - - Serial::printf("Unmapped page, was pointing to %#lx\n", old); - - TextConsole::set_foreground(0xff000055); - TextConsole::set_background(0xff88ff00); - - TextConsole::printf("Hello from Moon for the %s architecture!\n", CPU::platform_string()); - Timer::init(); - kinfoln("Hello, world!"); - kwarnln("THIS IS A WARNING"); - kerrorln("ERROR: Please do something."); - CPU::platform_finish_init(); CPU::enable_interrupts(); - usize start = 0; - - int* mem = TRY(make()); - *(volatile int*)mem = 6; - Serial::printf("Read %d from memory\n", *mem); - - TRY(destroy(mem)); - char buffer[64]; + to_dynamic_unit(MemoryManager::total(), buffer, sizeof(buffer)); + kinfoln("Total memory: %s", buffer); to_dynamic_unit(MemoryManager::free(), buffer, sizeof(buffer)); - kinfoln("Free memory: %s", buffer); + kinfoln("Free memory: %s", buffer); to_dynamic_unit(MemoryManager::used(), buffer, sizeof(buffer)); - kinfoln("Used memory: %s", buffer); + kinfoln("Used memory: %s", buffer); to_dynamic_unit(MemoryManager::reserved(), buffer, sizeof(buffer)); kinfoln("Reserved memory: %s", buffer); - while (1) - { - while ((Timer::ticks_ms() - start) < 100) { CPU::wait_for_interrupt(); } - start = Timer::ticks_ms(); - kdbgln("%8zu milliseconds have passed!", start); - } - return {}; } diff --git a/kernel/src/memory/MemoryManager.cpp b/kernel/src/memory/MemoryManager.cpp index ebfb7b0e..54561743 100644 --- a/kernel/src/memory/MemoryManager.cpp +++ b/kernel/src/memory/MemoryManager.cpp @@ -272,4 +272,9 @@ namespace MemoryManager { return reserved_mem; } + + u64 total() + { + return free_mem + used_mem + reserved_mem; + } } \ No newline at end of file diff --git a/kernel/src/memory/MemoryManager.h b/kernel/src/memory/MemoryManager.h index 17bf0136..f311f412 100644 --- a/kernel/src/memory/MemoryManager.h +++ b/kernel/src/memory/MemoryManager.h @@ -30,4 +30,5 @@ namespace MemoryManager u64 free(); u64 used(); u64 reserved(); + u64 total(); } \ No newline at end of file