#include "Log.h" #include "arch/CPU.h" #include "arch/MMU.h" #include "arch/Serial.h" #include "arch/Timer.h" #include "boot/Init.h" #include "memory/Heap.h" #include "memory/MemoryManager.h" #include "video/TextConsole.h" #include Result init() { Serial::println("Hello, world!"); Serial::printf("Current platform: %s\n", CPU::platform_string()); 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::free(), buffer, sizeof(buffer)); kinfoln("Free memory: %s", buffer); to_dynamic_unit(MemoryManager::used(), buffer, sizeof(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 {}; } extern "C" [[noreturn]] void _start() { Init::check_magic(); Init::early_init(); auto rc = init(); rc.release_value(); CPU::efficient_halt(); }