2022-11-13 10:25:15 +00:00
|
|
|
#include "Framebuffer.h"
|
2022-11-13 11:20:53 +00:00
|
|
|
#include "Init.h"
|
2022-11-13 14:33:53 +00:00
|
|
|
#include "MemoryManager.h"
|
2022-11-15 18:10:32 +00:00
|
|
|
#include "arch/CPU.h"
|
2022-11-13 13:29:15 +00:00
|
|
|
#include "arch/MMU.h"
|
2022-11-13 09:30:10 +00:00
|
|
|
#include "arch/Serial.h"
|
2022-10-16 13:31:58 +00:00
|
|
|
|
2022-11-13 13:29:15 +00:00
|
|
|
extern u8 fb[1];
|
|
|
|
|
2022-11-15 18:10:32 +00:00
|
|
|
extern "C" [[noreturn]] void _start()
|
2022-09-05 14:13:51 +00:00
|
|
|
{
|
2022-11-13 11:20:53 +00:00
|
|
|
Init::check_magic();
|
|
|
|
Init::early_init();
|
2022-11-13 09:30:10 +00:00
|
|
|
|
2022-11-13 11:20:53 +00:00
|
|
|
Serial::println("Hello, world!");
|
2022-11-13 10:25:15 +00:00
|
|
|
|
2022-11-19 11:30:36 +00:00
|
|
|
Serial::printf("Current platform: %s\n", CPU::platform_string());
|
|
|
|
|
2022-11-13 10:25:15 +00:00
|
|
|
Framebuffer::rect(0, 0, 200, 200, 0xFF00FF00);
|
|
|
|
|
2022-11-15 18:10:32 +00:00
|
|
|
auto cpu_name_or_error = CPU::identify();
|
|
|
|
|
|
|
|
Serial::println(cpu_name_or_error.has_error() ? "Unable to determine CPU name" : cpu_name_or_error.release_value());
|
|
|
|
|
2022-11-13 13:29:15 +00:00
|
|
|
Serial::println(MMU::get_physical((u64)fb).has_error() ? "fb is not mapped" : "fb is mapped!!");
|
|
|
|
|
2022-11-13 14:33:53 +00:00
|
|
|
const u64 address = 0xfffffffff8000000;
|
|
|
|
|
2022-11-19 12:15:13 +00:00
|
|
|
Serial::printf("Mapping address 0x%lx\n", address);
|
|
|
|
|
2022-11-13 14:33:53 +00:00
|
|
|
u64 physical = MemoryManager::alloc_physical_page().release_value();
|
|
|
|
|
2022-11-13 15:31:32 +00:00
|
|
|
auto rc = MMU::map(address, physical, MMU::ReadWrite);
|
|
|
|
bool success = !rc.has_error();
|
|
|
|
|
|
|
|
int flags;
|
2022-11-15 18:10:32 +00:00
|
|
|
volatile u8* ptr;
|
2022-11-13 14:33:53 +00:00
|
|
|
|
|
|
|
if (success) Serial::println("Mapped page :)");
|
|
|
|
else
|
2022-11-13 15:31:32 +00:00
|
|
|
{
|
2022-11-13 14:33:53 +00:00
|
|
|
Serial::println("Failed to map page");
|
2022-11-15 18:10:32 +00:00
|
|
|
CPU::efficient_halt();
|
2022-11-13 15:31:32 +00:00
|
|
|
}
|
2022-11-13 14:33:53 +00:00
|
|
|
|
|
|
|
if (MMU::get_physical(address).release_value() == physical) Serial::println("Mapping is active ;)");
|
|
|
|
else
|
2022-11-13 15:31:32 +00:00
|
|
|
{
|
2022-11-13 14:33:53 +00:00
|
|
|
Serial::println("Mapping is not active");
|
2022-11-15 18:10:32 +00:00
|
|
|
CPU::efficient_halt();
|
2022-11-13 15:31:32 +00:00
|
|
|
}
|
2022-11-13 14:33:53 +00:00
|
|
|
|
2022-11-13 15:31:32 +00:00
|
|
|
flags = MMU::get_flags(address).release_value();
|
2022-11-13 14:33:53 +00:00
|
|
|
|
|
|
|
if (flags & MMU::ReadWrite) Serial::println("Mapping is writable");
|
2022-11-15 18:10:32 +00:00
|
|
|
if (flags & MMU::User) Serial::println("Mapping is user accessible");
|
|
|
|
|
|
|
|
auto rrc = MMU::remap(address, MMU::ReadWrite | MMU::User);
|
|
|
|
if (rrc.has_error())
|
|
|
|
{
|
|
|
|
Serial::println("Failed to change flags of mapping");
|
|
|
|
CPU::efficient_halt();
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = MMU::get_flags(address).release_value();
|
2022-11-13 14:33:53 +00:00
|
|
|
|
2022-11-15 18:10:32 +00:00
|
|
|
if (flags & MMU::ReadWrite) Serial::println("Mapping is now writable");
|
|
|
|
if (flags & MMU::User) Serial::println("Mapping is now user accessible");
|
|
|
|
|
|
|
|
ptr = (volatile u8*)address;
|
2022-11-13 14:33:53 +00:00
|
|
|
|
|
|
|
*ptr = 8;
|
|
|
|
|
|
|
|
Serial::println("Can write to pointer");
|
|
|
|
|
2022-11-13 15:51:21 +00:00
|
|
|
auto urc = MMU::unmap(address);
|
|
|
|
if (urc.has_error())
|
|
|
|
{
|
|
|
|
Serial::println("Failed to unmap page");
|
2022-11-15 18:10:32 +00:00
|
|
|
CPU::efficient_halt();
|
2022-11-13 15:51:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (urc.release_value() != physical)
|
|
|
|
{
|
|
|
|
Serial::println("unmap returned a different address than the one we mapped");
|
2022-11-15 18:10:32 +00:00
|
|
|
CPU::efficient_halt();
|
2022-11-13 15:51:21 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 18:10:32 +00:00
|
|
|
Serial::println("Successfully unmapped address");
|
2022-11-13 15:31:32 +00:00
|
|
|
|
2022-11-18 19:51:25 +00:00
|
|
|
*ptr = 16;
|
2022-11-16 16:37:18 +00:00
|
|
|
|
2022-11-18 19:51:25 +00:00
|
|
|
Serial::println("ERROR: Still here after page fault");
|
2022-11-15 18:36:50 +00:00
|
|
|
|
2022-11-15 18:10:32 +00:00
|
|
|
CPU::efficient_halt();
|
2022-09-05 14:13:51 +00:00
|
|
|
}
|