#include "Framebuffer.h" #include "Init.h" #include "MemoryManager.h" #include "arch/MMU.h" #include "arch/Serial.h" extern u8 fb[1]; void hang() { for (;;) ; } extern "C" void _start() { Init::check_magic(); Init::early_init(); Serial::println("Hello, world!"); Framebuffer::rect(0, 0, 200, 200, 0xFF00FF00); Serial::println(MMU::get_physical((u64)fb).has_error() ? "fb is not mapped" : "fb is mapped!!"); const u64 address = 0xfffffffff8000000; u64 physical = MemoryManager::alloc_physical_page().release_value(); auto rc = MMU::map(address, physical, MMU::ReadWrite); bool success = !rc.has_error(); int flags; u8* ptr; if (success) Serial::println("Mapped page :)"); else { Serial::println("Failed to map page"); hang(); } if (MMU::get_physical(address).release_value() == physical) Serial::println("Mapping is active ;)"); else { Serial::println("Mapping is not active"); hang(); } flags = MMU::get_flags(address).release_value(); if (flags & MMU::ReadWrite) Serial::println("Mapping is writable"); if (flags & MMU::NoExecute) Serial::println("Mapping is not executable"); ptr = (u8*)address; *ptr = 8; Serial::println("Can write to pointer"); auto urc = MMU::unmap(address); if (urc.has_error()) { Serial::println("Failed to unmap page"); hang(); } if (urc.release_value() != physical) { Serial::println("unmap returned a different address than the one we mapped"); hang(); } Serial::println("Unmapped memory, writing to it should crash"); *ptr = 16; Serial::println("ERROR: we should have crashed by this point"); for (;;) ; }