diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-05-03 01:47:15 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-05-03 01:47:15 +0800 |
| commit | 2b237b24c4db5513f8046e15d24501257e7feeaa (patch) | |
| tree | 7b5fcbe3e00d30056064801594b899eb3db5c88b /na/drivers/uart.cc | |
| parent | 4b1b9912caf41fa52818e5d84130016ce00888cc (diff) | |
| download | lume-2b237b24c4db5513f8046e15d24501257e7feeaa.tar.gz lume-2b237b24c4db5513f8046e15d24501257e7feeaa.tar.xz | |
feat: implement KASLR support and runtime address mapping for RISC-V architecture
Co-authored-by: Copilot <copilot@github.com>
Diffstat (limited to 'na/drivers/uart.cc')
| -rw-r--r-- | na/drivers/uart.cc | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/na/drivers/uart.cc b/na/drivers/uart.cc index 6a35588..2e553d6 100644 --- a/na/drivers/uart.cc +++ b/na/drivers/uart.cc @@ -15,10 +15,21 @@ static uint64 g_uart_pa = 0; static uint64 g_uart_size = 0; +static bool g_runtime_mapping_ready = false; extern "C" void early_putc(char c) { if (!g_uart_pa) return; - volatile auto* uart = reinterpret_cast<volatile uint8*>(pa_to_va(phys_addr(g_uart_pa)).raw); + + /* + * Before vmm_init() activates the final page table, UART MMIO is only + * reachable via the bootstrap fixed direct map from entry.S. + * After activation, switch to the runtime (possibly KASLR-slid) base. + */ + uint64 uart_va = g_runtime_mapping_ready + ? pa_to_va(phys_addr(g_uart_pa)).raw + : boot_pa_to_va(phys_addr(g_uart_pa)).raw; + + volatile auto* uart = reinterpret_cast<volatile uint8*>(uart_va); *uart = static_cast<uint8>(c); } @@ -45,3 +56,7 @@ void console_init() { vmm_map_kernel_mmio(g_uart_pa, g_uart_size); } } + +void console_use_runtime_mapping() { + g_runtime_mapping_ready = true; +} |
