From e288f35b5b252d0a1221af1052890b3779455684 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Wed, 3 Dec 2025 14:28:19 +0100 Subject: [PATCH 01/12] fixes to correct bug introduced by the MUSL support --- so3/arch/arm32/context.S | 1 - so3/arch/arm64/context.S | 1 - so3/arch/arm64/exception.S | 7 ++++--- so3/arch/arm64/traps.c | 2 +- so3/fs/vfs.c | 23 +++++++++++++---------- so3/include/vfs.h | 2 +- so3/kernel/process.c | 4 ++-- so3/kernel/syscalls.c | 5 ++--- so3/kernel/timer.c | 8 ++++---- usr/src/time.c | 5 +---- 10 files changed, 28 insertions(+), 30 deletions(-) diff --git a/so3/arch/arm32/context.S b/so3/arch/arm32/context.S index d49488436..21f0700f8 100644 --- a/so3/arch/arm32/context.S +++ b/so3/arch/arm32/context.S @@ -34,7 +34,6 @@ .global __exec_prologue_user .globl __get_syscall_args_ext -.globl __get_syscall_arg .global __mmu_switch_ttbr0 .global __exec diff --git a/so3/arch/arm64/context.S b/so3/arch/arm64/context.S index 05f34506c..a51490df5 100644 --- a/so3/arch/arm64/context.S +++ b/so3/arch/arm64/context.S @@ -31,7 +31,6 @@ .global __exec_prologue_user .globl __get_syscall_args_ext -.globl __get_syscall_arg .global __mmu_switch .global __exec diff --git a/so3/arch/arm64/exception.S b/so3/arch/arm64/exception.S index b47e9f8e4..4dadb33a4 100644 --- a/so3/arch/arm64/exception.S +++ b/so3/arch/arm64/exception.S @@ -495,13 +495,14 @@ __prepare_sig_handler: ldr x1, [x0, #OFFSET_SYS_SIGNUM] str x1, [sp, #OFFSET_X0] + // Set the handler to the PC ldr x1, [x0, #OFFSET_SYS_SA] ldr x2, [x1, #OFFSET_SA_HANDLER] - str x2, [sp, #OFFSET_X1] + str x2, [sp, #OFFSET_PC] - // Set the handler to the PC + // Set restorer to LR so the handler return to it. ldr x2, [x1, #OFFSET_SA_RESTORER] - str x2, [sp, #OFFSET_PC] + str x2, [sp, #OFFSET_LR] ret diff --git a/so3/arch/arm64/traps.c b/so3/arch/arm64/traps.c index 17ab61407..3289dbf92 100644 --- a/so3/arch/arm64/traps.c +++ b/so3/arch/arm64/traps.c @@ -247,7 +247,7 @@ void trap_handle(cpu_regs_t *regs) default: lprintk("### On CPU %d: ESR_Elx_EC(esr): 0x%lx\n", smp_processor_id(), ESR_ELx_EC(esr)); - trap_handle_error(regs->lr); + trap_handle_error(regs->pc); kernel_panic(); } } diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 5f7f76dff..45328218c 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -467,7 +467,7 @@ static int do_write(int fd, const void *buffer, size_t count) } /* Low Level mmap */ -static int do_mmap(int fd, addr_t virt_addr, uint32_t page_count, off_t offset) +static long do_mmap(int fd, addr_t virt_addr, uint32_t page_count, off_t offset) { int gfd; struct file_operations *fops; @@ -499,7 +499,7 @@ static int do_mmap(int fd, addr_t virt_addr, uint32_t page_count, off_t offset) } /* Low Level mmap - Anonymous case */ -static int do_mmap_anon(int fd, addr_t virt_addr, uint32_t page_count, off_t offset) +static long do_mmap_anon(int fd, addr_t virt_addr, uint32_t page_count, off_t offset) { uint32_t page; pcb_t *pcb; @@ -526,7 +526,7 @@ static int do_mmap_anon(int fd, addr_t virt_addr, uint32_t page_count, off_t off memset((void *) virt_addr, 0, page_count * PAGE_SIZE); - /* WARNIMG - This is a simple/basic way to set the start virtual address: + /* WARNING - This is a simple/basic way to set the start virtual address: It only increment the start address after each mmap call, no algorithm to search for available spaces. */ @@ -1045,15 +1045,18 @@ SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec *, vec, unsigned l int total = 0; for (i = 0; i < vlen; i++) { - ret = do_write(fd, (const void *) vec[i].iov_base, vec[i].iov_len); - if (ret < 0) { - break; - } else if ((ret >= 0) && (ret < vec[i].iov_len)) { + /* Do nothing for empty buffer */ + if (vec[i].iov_len != 0) { + ret = do_write(fd, (const void *) vec[i].iov_base, vec[i].iov_len); + if (ret < 0) { + break; + } else if ((ret >= 0) && (ret < vec[i].iov_len)) { + total += ret; + break; + } + total += ret; - break; } - - total += ret; } if (total == 0) diff --git a/so3/include/vfs.h b/so3/include/vfs.h index 5c72e7208..d4e7b7a6d 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -92,7 +92,7 @@ #define DT_SOCK 12 /* Socket device */ /* mmap flags options */ -#define MAP_ANONYMOUS 0x10 /* don't use a file */ +#define MAP_ANONYMOUS 0x20 /* don't use a file */ /* Special value for dirfd used to indicate openat should use the current working directory. */ diff --git a/so3/kernel/process.c b/so3/kernel/process.c index c05540775..8fe002d94 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -74,9 +74,9 @@ static uint32_t pid_current = 1; static pcb_t *root_process = NULL; /* root process */ /* only the following sections are supported */ -#define SUPPORTED_SECTION_COUNT 6 +#define SUPPORTED_SECTION_COUNT 8 static const char *supported_section_names[SUPPORTED_SECTION_COUNT] = { - ".text", ".rodata", ".data", ".sbss", ".bss", ".scommon", + ".init", ".text", ".rodata", ".data", ".sbss", ".bss", ".scommon", ".fini", }; /* diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index 251dc1430..c661bd40b 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -31,8 +31,7 @@ #include #include -extern void __get_syscall_args_ext(uint32_t *syscall_no); -extern uint32_t __get_syscall_stack_arg(uint32_t nr); +extern void __get_syscall_args_ext(long *syscall_no); extern void test_malloc(int test_no); @@ -49,7 +48,7 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { long syscall_handle(syscall_args_t *syscall_args) { - uint32_t syscall_no; + long syscall_no; /* Get addtional args of the syscall according to the ARM & SO3 ABI */ __get_syscall_args_ext(&syscall_no); diff --git a/so3/kernel/timer.c b/so3/kernel/timer.c index 075b39c70..a6e34a17b 100644 --- a/so3/kernel/timer.c +++ b/so3/kernel/timer.c @@ -436,8 +436,8 @@ SYSCALL_DEFINE2(gettimeofday, struct timeval *, ts, void *, tz) time = NOW(); - ts->tv_sec = time / (time_t) 1000000000; - ts->tv_usec = time / (time_t) 1000; + ts->tv_sec = time / SECONDS(1); + ts->tv_usec = (time % SECONDS(1)) / MICROSECS(1); return 0; } @@ -475,8 +475,8 @@ SYSCALL_DEFINE2(clock_gettime, int, clk_id, struct timespec *, ts) time = NOW(); - ts->tv_sec = time / (time_t) 1000000000; - ts->tv_nsec = time; + ts->tv_sec = time / SECONDS(1); + ts->tv_nsec = time % SECONDS(1); return 0; } diff --git a/usr/src/time.c b/usr/src/time.c index a45acbf40..47141b241 100644 --- a/usr/src/time.c +++ b/usr/src/time.c @@ -8,14 +8,11 @@ int main(int argc, char *argv[]) { - time_t t; struct timeval tv; while (true) { gettimeofday(&tv, NULL); - time(&t); - - printf("# time(s) : %lu time(us) : %lu\n", t, tv.tv_usec); + printf("# time(s) : %lu time(us) : %lu\n", tv.tv_sec, tv.tv_usec); } } From 5ed629389d366d387670b5590be740f90c5a3154 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Wed, 3 Dec 2025 16:11:59 +0100 Subject: [PATCH 02/12] rename rt_kill into kill in syscall.tbl --- so3/syscall.tbl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/so3/syscall.tbl b/so3/syscall.tbl index b60972a7c..f64496b0b 100644 --- a/so3/syscall.tbl +++ b/so3/syscall.tbl @@ -41,7 +41,7 @@ futex pipe IPC_PIPE pipe2 IPC_PIPE rt_sigaction IPC_SIGNAL -rt_kill IPC_SIGNAL +kill IPC_SIGNAL sigreturn IPC_SIGNAL rt_sigreturn IPC_SIGNAL rt_sigprocmask IPC_SIGNAL From 493ca91960cb84bbc641efc33c091458e2b756fb Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Wed, 3 Dec 2025 16:15:37 +0100 Subject: [PATCH 03/12] rename thread_yield to sched_yield --- so3/include/thread.h | 2 +- so3/kernel/thread.c | 2 +- so3/syscall.tbl | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/so3/include/thread.h b/so3/include/thread.h index 78c7bdb8e..1091f2262 100644 --- a/so3/include/thread.h +++ b/so3/include/thread.h @@ -138,7 +138,7 @@ tcb_t *user_thread(clone_args_t *args); int thread_join(tcb_t *tcb); void thread_exit(int exit_status); void clean_thread(tcb_t *tcb); -SYSCALL_DECLARE(thread_yield, void); +SYSCALL_DECLARE(sched_yield, void); void *thread_idle(void *dummy); diff --git a/so3/kernel/thread.c b/so3/kernel/thread.c index 3c449106b..121140c55 100644 --- a/so3/kernel/thread.c +++ b/so3/kernel/thread.c @@ -339,7 +339,7 @@ void *thread_idle(void *dummy) /* * Yield to another thread, i.e. simply invoke a call to schedule() */ -SYSCALL_DEFINE0(thread_yield) +SYSCALL_DEFINE0(sched_yield) { schedule(); return 0; diff --git a/so3/syscall.tbl b/so3/syscall.tbl index f64496b0b..e72744194 100644 --- a/so3/syscall.tbl +++ b/so3/syscall.tbl @@ -38,6 +38,7 @@ mmap mmap2 nanosleep futex +sched_yield pipe IPC_PIPE pipe2 IPC_PIPE rt_sigaction IPC_SIGNAL From 41d17e147e34701378e69cd396a4c71eb4c84d70 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Wed, 10 Dec 2025 13:57:10 +0100 Subject: [PATCH 04/12] add missing fix on process --- so3/kernel/process.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/so3/kernel/process.c b/so3/kernel/process.c index 8fe002d94..d3bee955a 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -446,7 +446,7 @@ addr_t preserve_args_and_env(int argc, char **argv, char **envp) /* Save env strings and count how many there are */ saved->envc = 0; if (envp) { - do { + while (envp[saved->envc]) { str_len = strlen(envp[saved->envc]) + 1; /* Ensure the newly copied string will not exceed the buffer size. */ @@ -459,7 +459,9 @@ addr_t preserve_args_and_env(int argc, char **argv, char **envp) strcpy(&saved->arg_env[saved->strings_size], envp[saved->envc]); saved->strings_size += str_len; - } while (envp[saved->envc++]); + + saved->envc++; + } } return (addr_t) saved; @@ -477,11 +479,12 @@ void post_setup_image(args_env_t *args_env, elf_img_info_t *elf_img_info) args_base = (char *) arch_get_args_base(); /* Save argc as first arguments */ - *((int *) args_base) = args_env->argc; + *((long *) args_base) = args_env->argc; /* Get the base address for the array of pointer for args, env and aux */ - argv_p_base = (char **) (args_base + sizeof(int)); - env_p_base = (char **) ((addr_t) argv_p_base + args_env->argc * sizeof(char *)); + argv_p_base = (char **) (args_base + sizeof(long)); + /* Add one to account for the null termination of env */ + env_p_base = (char **) ((addr_t) argv_p_base + (args_env->argc + 1) * sizeof(char *)); /* Add one to account for the null termination of env */ aux_elf = (elf_addr_t *) ((addr_t) env_p_base + (args_env->envc + 1) * sizeof(char *)); From 492c6cbf3884beda3a96d49538337532e72a92c3 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Wed, 10 Dec 2025 18:03:52 +0100 Subject: [PATCH 05/12] [c++] Add basic C++ apps The apps are: hello-world, simple class & use of std::vector Signed-off-by: Jean-Pierre Miceli --- usr/CMakeLists.txt | 2 +- usr/src/tests/CMakeLists.txt | 5 ++++ usr/src/tests/class_test.cpp | 48 +++++++++++++++++++++++++++++++++++ usr/src/tests/hello_world.cpp | 27 ++++++++++++++++++++ usr/src/tests/vector_test.cpp | 36 ++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 usr/src/tests/CMakeLists.txt create mode 100644 usr/src/tests/class_test.cpp create mode 100644 usr/src/tests/hello_world.cpp create mode 100644 usr/src/tests/vector_test.cpp diff --git a/usr/CMakeLists.txt b/usr/CMakeLists.txt index 387abe07c..f30cd284f 100644 --- a/usr/CMakeLists.txt +++ b/usr/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.16) -project(so3-usr LANGUAGES C ASM) +project(so3-usr LANGUAGES C CXX ASM) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/usr/src/tests/CMakeLists.txt b/usr/src/tests/CMakeLists.txt new file mode 100644 index 000000000..63e4efad7 --- /dev/null +++ b/usr/src/tests/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.16) + +add_executable(hello-world.elf hello_world.cpp) +add_executable(class-test.elf class_test.cpp) +add_executable(vector-test.elf vector_test.cpp) diff --git a/usr/src/tests/class_test.cpp b/usr/src/tests/class_test.cpp new file mode 100644 index 000000000..b01eb3864 --- /dev/null +++ b/usr/src/tests/class_test.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2025 Jean-Pierre Miceli + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include + +class Person { +private: + std::string _name; + int _age; + +public: + // Constructor + Person(const std::string& name, int age) + : _name(name), _age(age) {} + + // Method to print info + void hello() const { + // std::cout << "Hi, I'm " << _name + // << " and I'm " << _age + // << " years old." << std::endl; + + printf("Hi, I'm %s and I'm %d years old.\n"); + } +}; + +int main() +{ + Person p("Jean-Pierre", 30); + p.hello(); + + return 0; +} diff --git a/usr/src/tests/hello_world.cpp b/usr/src/tests/hello_world.cpp new file mode 100644 index 000000000..b4a87e6c8 --- /dev/null +++ b/usr/src/tests/hello_world.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2025 Jean-Pierre Miceli + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include + +int main() +{ + // printf("JMI\n"); + std::cout << "Hello World!" << std::endl; + + return 0; +} \ No newline at end of file diff --git a/usr/src/tests/vector_test.cpp b/usr/src/tests/vector_test.cpp new file mode 100644 index 000000000..0f429b362 --- /dev/null +++ b/usr/src/tests/vector_test.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2025 Jean-Pierre Miceli + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include + +int main() { + // Create and initialize a vector with 3 integer values + std::vector numbers = {10, 20, 30}; + + // Compute the sum + int sum = 0; + for (int value : numbers) { + sum += value; + } + + // Output the result + printf("Sum of vector entries: %d\n", sum); + + return 0; +} \ No newline at end of file From 7c8ff54da3d2f56a49b6024d863f68099e3fb177 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Wed, 10 Dec 2025 18:05:23 +0100 Subject: [PATCH 06/12] [c++] udpate of CMakeList of usr/scr to compile test c++ apps Signed-off-by: Jean-Pierre Miceli --- usr/src/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/usr/src/CMakeLists.txt b/usr/src/CMakeLists.txt index f388b89b1..18376148e 100644 --- a/usr/src/CMakeLists.txt +++ b/usr/src/CMakeLists.txt @@ -28,3 +28,8 @@ if (MICROPYTHON AND (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")) add_subdirectory(micropython) endif() +option(WITH_TESTS "Build the test/example apps" ON) +if (WITH_TESTS) + add_subdirectory(tests) +endif() + From 4dbcc4aaa298d51d1656dc2c0e717a1e80f70ac7 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Wed, 10 Dec 2025 18:06:33 +0100 Subject: [PATCH 07/12] [c++] Add section used by C++ apps to so3 Signed-off-by: Jean-Pierre Miceli --- so3/kernel/main.c | 2 +- so3/kernel/process.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/so3/kernel/main.c b/so3/kernel/main.c index 8858c2447..1bf429d99 100644 --- a/so3/kernel/main.c +++ b/so3/kernel/main.c @@ -98,7 +98,7 @@ void kernel_start(void) { lprintk("%s", SO3_BANNER); - LOG_INFO("Now bootstraping the kernel ..."); + LOG_INFO("Now bootstraping the kernel ...\n"); /* Memory manager subsystem initialization */ memory_init(); diff --git a/so3/kernel/process.c b/so3/kernel/process.c index d3bee955a..e7c5e21e4 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -74,10 +74,11 @@ static uint32_t pid_current = 1; static pcb_t *root_process = NULL; /* root process */ /* only the following sections are supported */ -#define SUPPORTED_SECTION_COUNT 8 -static const char *supported_section_names[SUPPORTED_SECTION_COUNT] = { +static const char *supported_section_names[] = { ".init", ".text", ".rodata", ".data", ".sbss", ".bss", ".scommon", ".fini", + ".eh_frame", ".gcc_except_table", ".init_array", ".fini_array", ".data.rel.ro", ".got", ".got.plt", }; +#define SUPPORTED_SECTION_COUNT (sizeof(supported_section_names) / sizeof(supported_section_names[0])) /* * Find a process (pcb_t) from its pid. From 7bf88dae2fb25846b8ec8219a6114b2ddab8343d Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Thu, 11 Dec 2025 15:47:27 +0100 Subject: [PATCH 08/12] [c++] Add 'no-rtti' flag in the musl toolchains Signed-off-by: Jean-Pierre Miceli --- usr/aarch64-linux-musl.cmake | 2 +- usr/arm-linux-musl.cmake | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/usr/aarch64-linux-musl.cmake b/usr/aarch64-linux-musl.cmake index a36f89037..f7c353062 100644 --- a/usr/aarch64-linux-musl.cmake +++ b/usr/aarch64-linux-musl.cmake @@ -26,4 +26,4 @@ set(CMAKE_ASM_FLAGS "-D__ARM64__ -D__ASSEMBLY__") set(CMAKE_LINKER "aarch64-linux-musl-ld") -set(CMAKE_EXE_LINKER_FLAGS "-Os -static" CACHE STRING "SO3 usr LDFLAGS for executables") +set(CMAKE_EXE_LINKER_FLAGS "-Os -static -fno-rtti" CACHE STRING "SO3 usr LDFLAGS for executables") diff --git a/usr/arm-linux-musl.cmake b/usr/arm-linux-musl.cmake index 4d38558df..f148c3542 100644 --- a/usr/arm-linux-musl.cmake +++ b/usr/arm-linux-musl.cmake @@ -26,5 +26,4 @@ set(CMAKE_ASM_FLAGS "-D__ARM__ -D__ASSEMBLY__") set(CMAKE_LINKER "arm-linux-musleabihf-ld") - -set(CMAKE_EXE_LINKER_FLAGS "-Os -static" CACHE STRING "SO3 usr LDFLAGS for executables") +set(CMAKE_EXE_LINKER_FLAGS "-Os -static -fno-rtti" CACHE STRING "SO3 usr LDFLAGS for executables") From 074a605c379803487c5094666421dc1c3f40d82f Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Thu, 11 Dec 2025 15:48:23 +0100 Subject: [PATCH 09/12] [usr] Move the '.debug_*' sections in a separated file The '.debug_*' sections of the usr apps are move in a seperated file ('app.elf.debug'). The apps is then much lighter. For example, C++ hello-world shrink form 8.2MB to 884K. For debug, the app.elf.debug is linked with the app.elf. Signed-off-by: Jean-Pierre Miceli --- usr/build.sh | 30 ++++++++++++++++++++++++++++++ usr/deploy.sh | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/usr/build.sh b/usr/build.sh index 747697471..d596d04dc 100755 --- a/usr/build.sh +++ b/usr/build.sh @@ -11,6 +11,33 @@ usage() { echo " -h Print this help" } +# Place the debug info of the applications in a separate file +strip_debug_info() +{ + # retrieve the correct objcop tool + # if [ "$1" == "virt32" -o "$1" == "rpi4" ]; then + if [ "$1" = "virt32" ] || [ "$1" = "rpi4" ]; then + OBJCOPY="arm-linux-musleabihf-objcopy" + else + OBJCOPY="aarch64-linux-musl-objcopy" + fi + + for app in build/deploy/*.elf; do + [ -e "$app" ] || continue + + # 1. Create a file with only '.debug_*' sections + $OBJCOPY --only-keep-debug $app $app.debug + + # 2. remove/strip debug info + $OBJCOPY --strip-all $app + + # 3. Connect the two files + $OBJCOPY --add-gnu-debuglink=$app.debug $app + + done +} + + install_file_elf() { if [ -f $1 ] ; then for subfolder_app in $(find build/src -type f -iname "*.elf"); do @@ -120,4 +147,7 @@ install_directory_root out install_file_elf +strip_debug_info "$PLATFORM" + + exit 0 diff --git a/usr/deploy.sh b/usr/deploy.sh index 8ab92c9b5..c3c2bffd0 100755 --- a/usr/deploy.sh +++ b/usr/deploy.sh @@ -18,6 +18,6 @@ echo Deploying user apps into the ramfs partition cd ../rootfs ./mount.sh ${PLATFORM} sudo cp -r ../usr/out/* fs -sudo cp -r ../usr/build/deploy/* fs +sudo cp -r ../usr/build/deploy/*.elf fs ./umount.sh ${PLATFORM} From 9ee77db1194e314869026d28b805668a7a68cc72 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Tue, 16 Dec 2025 10:56:34 +0100 Subject: [PATCH 10/12] [c++] Add some more basic tests Signed-off-by: Jean-Pierre Miceli --- usr/src/tests/CMakeLists.txt | 4 ++- usr/src/tests/allocation_test.cpp | 34 +++++++++++++++++++ usr/src/tests/class_test.cpp | 15 ++++---- usr/src/tests/exception_test.cpp | 28 +++++++++++++++ usr/src/tests/hello_world.cpp | 1 - .../{vector_test.cpp => stdlib_test.cpp} | 33 ++++++++++++++++-- 6 files changed, 104 insertions(+), 11 deletions(-) create mode 100644 usr/src/tests/allocation_test.cpp create mode 100644 usr/src/tests/exception_test.cpp rename usr/src/tests/{vector_test.cpp => stdlib_test.cpp} (72%) diff --git a/usr/src/tests/CMakeLists.txt b/usr/src/tests/CMakeLists.txt index 63e4efad7..95e4e692f 100644 --- a/usr/src/tests/CMakeLists.txt +++ b/usr/src/tests/CMakeLists.txt @@ -2,4 +2,6 @@ cmake_minimum_required(VERSION 3.16) add_executable(hello-world.elf hello_world.cpp) add_executable(class-test.elf class_test.cpp) -add_executable(vector-test.elf vector_test.cpp) +add_executable(stdlib-test.elf stdlib_test.cpp) +add_executable(exception-test.elf exception_test.cpp) +add_executable(allocation-test.elf allocation_test.cpp) diff --git a/usr/src/tests/allocation_test.cpp b/usr/src/tests/allocation_test.cpp new file mode 100644 index 000000000..9113b0c56 --- /dev/null +++ b/usr/src/tests/allocation_test.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2025 Jean-Pierre Miceli + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include + +struct Aligned { alignas(64) int x; }; + +int main() +{ + void* p = ::operator new(1024); + ::operator delete(p); + + Aligned* a = new Aligned; + delete a; + + std::cout << "Test OK" << std::endl; +} + diff --git a/usr/src/tests/class_test.cpp b/usr/src/tests/class_test.cpp index b01eb3864..af1d43ec9 100644 --- a/usr/src/tests/class_test.cpp +++ b/usr/src/tests/class_test.cpp @@ -25,17 +25,18 @@ class Person { int _age; public: - // Constructor Person(const std::string& name, int age) - : _name(name), _age(age) {} + : _name(name), _age(age) { + std::cout << "Person constructor" << std::endl; + } + + ~Person() { + std::cout << "Person Destructor" << std::endl; + } // Method to print info void hello() const { - // std::cout << "Hi, I'm " << _name - // << " and I'm " << _age - // << " years old." << std::endl; - - printf("Hi, I'm %s and I'm %d years old.\n"); + std::cout << "Hi, I'm " << _name << " and I'm " << _age << " years old." << std::endl; } }; diff --git a/usr/src/tests/exception_test.cpp b/usr/src/tests/exception_test.cpp new file mode 100644 index 000000000..8945b01c2 --- /dev/null +++ b/usr/src/tests/exception_test.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2025 Jean-Pierre Miceli + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include + +int main() +{ + try { + throw 42; + } catch (int x) { + std::cout << "caught: " << x << std::endl; + } +} diff --git a/usr/src/tests/hello_world.cpp b/usr/src/tests/hello_world.cpp index b4a87e6c8..c37c206be 100644 --- a/usr/src/tests/hello_world.cpp +++ b/usr/src/tests/hello_world.cpp @@ -20,7 +20,6 @@ int main() { - // printf("JMI\n"); std::cout << "Hello World!" << std::endl; return 0; diff --git a/usr/src/tests/vector_test.cpp b/usr/src/tests/stdlib_test.cpp similarity index 72% rename from usr/src/tests/vector_test.cpp rename to usr/src/tests/stdlib_test.cpp index 0f429b362..1926217ec 100644 --- a/usr/src/tests/vector_test.cpp +++ b/usr/src/tests/stdlib_test.cpp @@ -18,8 +18,10 @@ #include #include +#include -int main() { +void vector_test() +{ // Create and initialize a vector with 3 integer values std::vector numbers = {10, 20, 30}; @@ -30,7 +32,34 @@ int main() { } // Output the result - printf("Sum of vector entries: %d\n", sum); + std::cout << "Sum of vector entries: " << sum << std::endl; +} + + +void string_test() +{ + std::string s = "abc"; + s += "def"; + std::cout << "String: " << s << std::endl; +} + +void map_test() +{ + std::map m; + + m[1] = 2; + + std::cout << "Map m[1]: " << m[1] << std::endl; +} + + +int main() { + + vector_test(); + + string_test(); + + map_test(); return 0; } \ No newline at end of file From 314b7ea8f7a2d6d2f2c75a06fa8609d3be910e82 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Tue, 16 Dec 2025 11:13:09 +0100 Subject: [PATCH 11/12] [c++] Fix clang-format Signed-off-by: Jean-Pierre Miceli --- usr/src/tests/allocation_test.cpp | 15 ++++++----- usr/src/tests/class_test.cpp | 40 +++++++++++++++------------- usr/src/tests/exception_test.cpp | 6 ++--- usr/src/tests/hello_world.cpp | 4 +-- usr/src/tests/stdlib_test.cpp | 44 +++++++++++++++---------------- 5 files changed, 56 insertions(+), 53 deletions(-) diff --git a/usr/src/tests/allocation_test.cpp b/usr/src/tests/allocation_test.cpp index 9113b0c56..dca56f86a 100644 --- a/usr/src/tests/allocation_test.cpp +++ b/usr/src/tests/allocation_test.cpp @@ -19,16 +19,17 @@ #include #include -struct Aligned { alignas(64) int x; }; +struct Aligned { + alignas(64) int x; +}; int main() { - void* p = ::operator new(1024); - ::operator delete(p); + void *p = ::operator new(1024); + ::operator delete(p); - Aligned* a = new Aligned; - delete a; + Aligned *a = new Aligned; + delete a; - std::cout << "Test OK" << std::endl; + std::cout << "Test OK" << std::endl; } - diff --git a/usr/src/tests/class_test.cpp b/usr/src/tests/class_test.cpp index af1d43ec9..eef30af66 100644 --- a/usr/src/tests/class_test.cpp +++ b/usr/src/tests/class_test.cpp @@ -20,30 +20,34 @@ #include class Person { -private: - std::string _name; - int _age; + private: + std::string _name; + int _age; -public: - Person(const std::string& name, int age) - : _name(name), _age(age) { - std::cout << "Person constructor" << std::endl; - } + public: + Person(const std::string &name, int age) + : _name(name) + , _age(age) + { + std::cout << "Person constructor" << std::endl; + } - ~Person() { - std::cout << "Person Destructor" << std::endl; - } + ~Person() + { + std::cout << "Person Destructor" << std::endl; + } - // Method to print info - void hello() const { - std::cout << "Hi, I'm " << _name << " and I'm " << _age << " years old." << std::endl; - } + // Method to print info + void hello() const + { + std::cout << "Hi, I'm " << _name << " and I'm " << _age << " years old." << std::endl; + } }; int main() { - Person p("Jean-Pierre", 30); - p.hello(); + Person p("Jean-Pierre", 30); + p.hello(); - return 0; + return 0; } diff --git a/usr/src/tests/exception_test.cpp b/usr/src/tests/exception_test.cpp index 8945b01c2..6026dea25 100644 --- a/usr/src/tests/exception_test.cpp +++ b/usr/src/tests/exception_test.cpp @@ -22,7 +22,7 @@ int main() { try { throw 42; - } catch (int x) { - std::cout << "caught: " << x << std::endl; - } + } catch (int x) { + std::cout << "caught: " << x << std::endl; + } } diff --git a/usr/src/tests/hello_world.cpp b/usr/src/tests/hello_world.cpp index c37c206be..4ef192cd0 100644 --- a/usr/src/tests/hello_world.cpp +++ b/usr/src/tests/hello_world.cpp @@ -20,7 +20,7 @@ int main() { - std::cout << "Hello World!" << std::endl; + std::cout << "Hello World!" << std::endl; - return 0; + return 0; } \ No newline at end of file diff --git a/usr/src/tests/stdlib_test.cpp b/usr/src/tests/stdlib_test.cpp index 1926217ec..a450971be 100644 --- a/usr/src/tests/stdlib_test.cpp +++ b/usr/src/tests/stdlib_test.cpp @@ -22,44 +22,42 @@ void vector_test() { - // Create and initialize a vector with 3 integer values - std::vector numbers = {10, 20, 30}; + // Create and initialize a vector with 3 integer values + std::vector numbers = { 10, 20, 30 }; - // Compute the sum - int sum = 0; - for (int value : numbers) { - sum += value; - } + // Compute the sum + int sum = 0; + for (int value : numbers) { + sum += value; + } - // Output the result - std::cout << "Sum of vector entries: " << sum << std::endl; + // Output the result + std::cout << "Sum of vector entries: " << sum << std::endl; } - void string_test() { - std::string s = "abc"; - s += "def"; - std::cout << "String: " << s << std::endl; + std::string s = "abc"; + s += "def"; + std::cout << "String: " << s << std::endl; } void map_test() { - std::map m; + std::map m; - m[1] = 2; + m[1] = 2; - std::cout << "Map m[1]: " << m[1] << std::endl; + std::cout << "Map m[1]: " << m[1] << std::endl; } +int main() +{ + vector_test(); -int main() { - - vector_test(); - - string_test(); + string_test(); - map_test(); + map_test(); - return 0; + return 0; } \ No newline at end of file From c64f6c49c42edbb24f542454ed9d90c6846f2f6a Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Tue, 16 Dec 2025 11:18:58 +0100 Subject: [PATCH 12/12] [c++] clang-format / again Signed-off-by: Jean-Pierre Miceli --- so3/kernel/process.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/so3/kernel/process.c b/so3/kernel/process.c index e7c5e21e4..ccc61a5f4 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -75,8 +75,9 @@ static pcb_t *root_process = NULL; /* root process */ /* only the following sections are supported */ static const char *supported_section_names[] = { - ".init", ".text", ".rodata", ".data", ".sbss", ".bss", ".scommon", ".fini", - ".eh_frame", ".gcc_except_table", ".init_array", ".fini_array", ".data.rel.ro", ".got", ".got.plt", + ".init", ".text", ".rodata", ".data", ".sbss", + ".bss", ".scommon", ".fini", ".eh_frame", ".gcc_except_table", + ".init_array", ".fini_array", ".data.rel.ro", ".got", ".got.plt", }; #define SUPPORTED_SECTION_COUNT (sizeof(supported_section_names) / sizeof(supported_section_names[0]))