From e9eb93ced36628f2c111b96c4916bb649636e71c Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 6 Mar 2026 05:54:15 +0100 Subject: [CHORE] Source code level refactors and improvements. Signed-off-by: Amlal El Mahrouss --- src/neboot-bootnet.c | 2 +- src/neboot-cpu-api.c | 2 +- src/neboot-cxx-abi.cc | 76 ---------------------------------------- src/neboot-cxx-abi.cpp | 76 ++++++++++++++++++++++++++++++++++++++++ src/neboot-partition-map-parse.c | 4 +-- src/neboot-partition-map.c | 2 +- src/neboot-pci-tree.c | 2 +- src/neboot-print-name.c | 2 +- src/neboot-start.c | 2 +- src/neboot-string.c | 2 +- src/rv64/makefile | 2 +- 11 files changed, 86 insertions(+), 86 deletions(-) delete mode 100644 src/neboot-cxx-abi.cc create mode 100644 src/neboot-cxx-abi.cpp (limited to 'src') diff --git a/src/neboot-bootnet.c b/src/neboot-bootnet.c index 63b1262..5bfd046 100644 --- a/src/neboot-bootnet.c +++ b/src/neboot-bootnet.c @@ -1,4 +1,4 @@ -// Copyright 2025, Amlal El Mahrouss (amlal@nekernel.org) +// Copyright 2025-2026, Amlal El Mahrouss (amlal@nekernel.org) // Distributed under the Apache Software License, Version 2.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.apache.org/licenses/LICENSE-2.0) // Official repository: https://github.com/ne-foss-org/neboot diff --git a/src/neboot-cpu-api.c b/src/neboot-cpu-api.c index 4d8d758..cd28bdc 100644 --- a/src/neboot-cpu-api.c +++ b/src/neboot-cpu-api.c @@ -1,4 +1,4 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) // Distributed under the Apache Software License, Version 2.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.apache.org/licenses/LICENSE-2.0) // Official repository: https://github.com/ne-foss-org/neboot diff --git a/src/neboot-cxx-abi.cc b/src/neboot-cxx-abi.cc deleted file mode 100644 index a1d9f12..0000000 --- a/src/neboot-cxx-abi.cc +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) -// Distributed under the Apache Software License, Version 2.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.apache.org/licenses/LICENSE-2.0) -// Official repository: https://github.com/ne-foss-org/neboot - -#include - -/// BUGS: 0 - -extern "C" __SIZE_TYPE__ nb_put_string(const char* text); -extern "C" void nb_panic(const char* reason); - -extern "C" void __stack_chk_fail() { - nb_put_string("[stack-canary] Buffer overflow detected, halting...\n"); - nb_panic("stack_canary_fail"); -} - -void* __dso_handle; - -extern "C" __SIZE_TYPE__ nb_put_string(const char* text); -extern "C" void nb_panic(const char* reason); - -atexit_func_entry_t __atexit_funcs[DSO_MAX_OBJECTS]; -uarch_t __atexit_func_count; - -extern "C" void __cxa_pure_virtual() { - nb_put_string("[__cxa_pure_virtual] Placeholder\n"); -} - -extern "C" int __cxa_atexit(void (*f)(void*), void* arg, void* dso) { - if (__atexit_func_count >= DSO_MAX_OBJECTS) return -1; - - __atexit_funcs[__atexit_func_count].destructor_func = f; - __atexit_funcs[__atexit_func_count].obj_ptr = arg; - __atexit_funcs[__atexit_func_count].dso_handle = dso; - - __atexit_func_count++; - - return 0; -} - -extern "C" void __cxa_finalize(void* f) { - uarch_t i = __atexit_func_count; - if (!f) { - while (i--) { - if (__atexit_funcs[i].destructor_func) { - (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr); - }; - } - - return; - } - - while (i--) { - if (__atexit_funcs[i].destructor_func) { - (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr); - __atexit_funcs[i].destructor_func = 0; - }; - } -} - -namespace cxxabiv1 { -extern "C" int __cxa_guard_acquire(__guard* g) { - (void) g; - return 0; -} - -extern "C" int __cxa_guard_release(__guard* g) { - *(char*) g = 1; - return 0; -} - -extern "C" void __cxa_guard_abort(__guard* g) { - (void) g; -} -} // namespace cxxabiv1 diff --git a/src/neboot-cxx-abi.cpp b/src/neboot-cxx-abi.cpp new file mode 100644 index 0000000..a630f3e --- /dev/null +++ b/src/neboot-cxx-abi.cpp @@ -0,0 +1,76 @@ +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) +// Distributed under the Apache Software License, Version 2.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.apache.org/licenses/LICENSE-2.0) +// Official repository: https://github.com/ne-foss-org/neboot + +#include + +/// BUGS: 0 + +extern "C" __SIZE_TYPE__ nb_put_string(const char* text); +extern "C" void nb_panic(const char* reason); + +extern "C" void __stack_chk_fail() { + nb_put_string("[stack-canary] Buffer overflow detected, halting...\n"); + nb_panic("stack_canary_fail"); +} + +void* __dso_handle; + +extern "C" __SIZE_TYPE__ nb_put_string(const char* text); +extern "C" void nb_panic(const char* reason); + +atexit_func_entry_t __atexit_funcs[DSO_MAX_OBJECTS]; +uarch_t __atexit_func_count; + +extern "C" void __cxa_pure_virtual() { + nb_put_string("[__cxa_pure_virtual] Placeholder\n"); +} + +extern "C" int __cxa_atexit(void (*f)(void*), void* arg, void* dso) { + if (__atexit_func_count >= DSO_MAX_OBJECTS) return -1; + + __atexit_funcs[__atexit_func_count].destructor_func = f; + __atexit_funcs[__atexit_func_count].obj_ptr = arg; + __atexit_funcs[__atexit_func_count].dso_handle = dso; + + __atexit_func_count++; + + return 0; +} + +extern "C" void __cxa_finalize(void* f) { + uarch_t i = __atexit_func_count; + if (!f) { + while (i--) { + if (__atexit_funcs[i].destructor_func) { + (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr); + }; + } + + return; + } + + while (i--) { + if (__atexit_funcs[i].destructor_func) { + (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr); + __atexit_funcs[i].destructor_func = 0; + }; + } +} + +namespace cxxabiv1 { +extern "C" int __cxa_guard_acquire(__guard* g) { + (void) g; + return 0; +} + +extern "C" int __cxa_guard_release(__guard* g) { + *(char*) g = 1; + return 0; +} + +extern "C" void __cxa_guard_abort(__guard* g) { + (void) g; +} +} // namespace cxxabiv1 diff --git a/src/neboot-partition-map-parse.c b/src/neboot-partition-map-parse.c index a3639be..c6926bf 100644 --- a/src/neboot-partition-map-parse.c +++ b/src/neboot-partition-map-parse.c @@ -1,4 +1,4 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) // Distributed under the Apache Software License, Version 2.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.apache.org/licenses/LICENSE-2.0) // Official repository: https://github.com/ne-foss-org/neboot @@ -38,4 +38,4 @@ part_block_t* nb_parse_partition_block_at(voidptr_t blob, size_t blob_sz, size_t } return block; -} \ No newline at end of file +} diff --git a/src/neboot-partition-map.c b/src/neboot-partition-map.c index f3b25a9..70df32e 100644 --- a/src/neboot-partition-map.c +++ b/src/neboot-partition-map.c @@ -1,4 +1,4 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) // Distributed under the Apache Software License, Version 2.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.apache.org/licenses/LICENSE-2.0) // Official repository: https://github.com/ne-foss-org/neboot diff --git a/src/neboot-pci-tree.c b/src/neboot-pci-tree.c index 79fa23c..c50fbb6 100644 --- a/src/neboot-pci-tree.c +++ b/src/neboot-pci-tree.c @@ -1,4 +1,4 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) // Distributed under the Apache Software License, Version 2.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.apache.org/licenses/LICENSE-2.0) // Official repository: https://github.com/ne-foss-org/neboot diff --git a/src/neboot-print-name.c b/src/neboot-print-name.c index 7204bc2..5ffae24 100644 --- a/src/neboot-print-name.c +++ b/src/neboot-print-name.c @@ -1,4 +1,4 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) // Distributed under the Apache Software License, Version 2.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.apache.org/licenses/LICENSE-2.0) // Official repository: https://github.com/ne-foss-org/neboot diff --git a/src/neboot-start.c b/src/neboot-start.c index 869f43d..abb83d9 100644 --- a/src/neboot-start.c +++ b/src/neboot-start.c @@ -1,4 +1,4 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) // Distributed under the Apache Software License, Version 2.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.apache.org/licenses/LICENSE-2.0) // Official repository: https://github.com/ne-foss-org/neboot diff --git a/src/neboot-string.c b/src/neboot-string.c index aedecaf..6f0e177 100644 --- a/src/neboot-string.c +++ b/src/neboot-string.c @@ -1,4 +1,4 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) // Distributed under the Apache Software License, Version 2.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.apache.org/licenses/LICENSE-2.0) // Official repository: https://github.com/ne-foss-org/neboot diff --git a/src/rv64/makefile b/src/rv64/makefile index d524fee..0ac2ade 100644 --- a/src/rv64/makefile +++ b/src/rv64/makefile @@ -14,7 +14,7 @@ FLAGS=-D__COMPILE_RISCV__ -I../../ -Wall -c -nostdlib -ffreestanding -fno-builti C_SRC= $(wildcard *.s) $(wildcard *.c) $(wildcard ../*.c) -c CXX=riscv64-unknown-elf-g++ -CXX_SRC= $(wildcard *.cc) $(wildcard ../*.cc) -c +CXX_SRC= $(wildcard *.cpp) $(wildcard ../*.cpp) -c LD=riscv64-unknown-elf-ld OBJ=*.o -- cgit v1.2.3