Clean init() up

This commit is contained in:
apio 2022-11-30 16:30:42 +01:00
parent f8ed74fda5
commit fe47e0d5cb
3 changed files with 10 additions and 43 deletions

View File

@ -17,47 +17,15 @@ Result<void> 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<int>());
*(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);
to_dynamic_unit(MemoryManager::used(), buffer, sizeof(buffer));
@ -65,13 +33,6 @@ Result<void> init()
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 {};
}

View File

@ -272,4 +272,9 @@ namespace MemoryManager
{
return reserved_mem;
}
u64 total()
{
return free_mem + used_mem + reserved_mem;
}
}

View File

@ -30,4 +30,5 @@ namespace MemoryManager
u64 free();
u64 used();
u64 reserved();
u64 total();
}