diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-04-21 23:21:47 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-04-21 23:21:47 +0800 |
| commit | 510f295124f7c8e51ec66f59be61a9e9aa8f9d25 (patch) | |
| tree | 04e72eb4da8ace182f419599e2d6a06f87113209 | |
| parent | 1768a553c054b3e4774daaeda6c44f511ca7077a (diff) | |
| download | lume-510f295124f7c8e51ec66f59be61a9e9aa8f9d25.tar.gz lume-510f295124f7c8e51ec66f59be61a9e9aa8f9d25.tar.xz | |
feat: add minimal C++ ABI stubs for freestanding kernel
| -rw-r--r-- | na/lib/cxx_abi.cc | 37 | ||||
| -rw-r--r-- | na/lib/panic.cc | 16 |
2 files changed, 39 insertions, 14 deletions
diff --git a/na/lib/cxx_abi.cc b/na/lib/cxx_abi.cc new file mode 100644 index 0000000..1ad9d4d --- /dev/null +++ b/na/lib/cxx_abi.cc @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Copyright (C) 2026 Richard Qin */ + +/* + * cxx_abi.cc — Minimal C++ ABI stubs for freestanding kernel + * + * Provides symbols that the compiler/linker expects from the C++ + * runtime library. All error paths are fatal (kernel_panic). + * + * Reference: docs/specs/cpp_runtime.md + */ + +#include <lume/panic.h> + +/* Pure virtual function call trap. + * Generated by the compiler in vtable entries for pure virtual methods. + * Reaching this means a derived class failed to implement a pure virtual. */ +extern "C" void __cxa_pure_virtual() +{ + kernel_panic("pure virtual function call"); +} + +/* Global destructor registration. + * The kernel does not support global object destruction — all global + * objects use Placement New with explicit lifetime management. + * If the compiler emits a call to this, it indicates a code violation. */ +extern "C" int __cxa_atexit(void (*)(void*), void*, void*) +{ + kernel_panic("__cxa_atexit called in kernel"); + return 0; // unreachable +} + +/* DSO handle — required by __cxa_atexit ABI. + * The kernel is statically linked; this symbol just needs to exist. */ +extern "C" { +void* __dso_handle __attribute__((visibility("hidden"))) = nullptr; +} diff --git a/na/lib/panic.cc b/na/lib/panic.cc index 4745272..753f910 100644 --- a/na/lib/panic.cc +++ b/na/lib/panic.cc @@ -11,21 +11,9 @@ */ #include <lume/types.h> +#include <lume/addr.h> #include <arch/cpu.h> - -// Minimal direct UART output (same as main.cc early boot) -// This can be used by other early-boot code before console_init() - -constexpr uint64 kUart0VA = 0x10000000UL + 0xFFFFFFC000000000ULL; - -extern "C" void early_putc(char c) { - volatile auto* uart = reinterpret_cast<volatile uint8*>(kUart0VA); - *uart = static_cast<uint8>(c); -} - -extern "C" void early_puts(const char* s) { - while (*s) early_putc(*s++); -} +#include <lume/console.h> extern "C" [[noreturn]] void kernel_panic(const char* msg, const char* detail) { arch::cpu::intr_off(); |
