From c2a40a81041fda772de51b78cd6262d3ca2e55b7 Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Sat, 3 Feb 2024 01:05:26 +0100 Subject: [PATCH] Added exit() function and renamed stdlib file to libc.a so GCC is happy. --- targets/_any/kernel/include/os/syscall.hpp | 2 +- targets/_any/stdlib/SConscript | 2 +- targets/_any/stdlib/src/stdlib.cpp | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/targets/_any/kernel/include/os/syscall.hpp b/targets/_any/kernel/include/os/syscall.hpp index 157186c..60c887b 100644 --- a/targets/_any/kernel/include/os/syscall.hpp +++ b/targets/_any/kernel/include/os/syscall.hpp @@ -18,7 +18,7 @@ enum class Syscall : std::uint64_t void setupSyscall() noexcept; -template +template inline void doSyscall(Syscall cmd, TParam0 param0 = 0, TParam1 param1 = 0, TParam2 param2 = 0) noexcept { register std::uint64_t r8 asm("r8") = param2; diff --git a/targets/_any/stdlib/SConscript b/targets/_any/stdlib/SConscript index c240239..88bbb07 100644 --- a/targets/_any/stdlib/SConscript +++ b/targets/_any/stdlib/SConscript @@ -28,7 +28,7 @@ if env['BUILD_TARGET'] == 'stdlib': stdlib_env.Append(CPPPATH = ['#targets/_any/bastl/include', '#targets/_any/stdlib/include', '#targets/_any/kernel/include']) lib_stdlib = stdlib_env.StaticLibrary( - target = stdlib_env.File('#stdlib/stdlib.a'), + target = stdlib_env.File('#stdlib/libc.a'), source = stdlib_sources ) crti_o = stdlib_env.Object(target = '#stdlib/crti.o', source = stdlib_env['CRTI_PATH']) diff --git a/targets/_any/stdlib/src/stdlib.cpp b/targets/_any/stdlib/src/stdlib.cpp index 09920a6..25cb100 100644 --- a/targets/_any/stdlib/src/stdlib.cpp +++ b/targets/_any/stdlib/src/stdlib.cpp @@ -3,6 +3,7 @@ #include #include "os/memory.hpp" +#include "os/syscall.hpp" #include "os/tty.hpp" namespace @@ -44,6 +45,15 @@ void abort() __builtin_unreachable(); } +void exit(int exitCode) noexcept +{ +#if !defined(__baos_kernel_source__) + baos::doSyscall(baos::Syscall::EXIT, exitCode); +#else + abort(); // no exit in kernel! +#endif +} + void* malloc(size_t size) noexcept { if (size == 0)