Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion so3/kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions so3/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ static uint32_t pid_current = 1;
static pcb_t *root_process = NULL; /* root process */

/* only the following sections are supported */
#define SUPPORTED_SECTION_COUNT 10
static const char *supported_section_names[SUPPORTED_SECTION_COUNT] = {
".init", ".text", ".rodata", ".data", ".sbss", ".bss", ".scommon", ".fini", ".init_array", ".fini_array",
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.
Expand Down
2 changes: 1 addition & 1 deletion usr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion usr/aarch64-linux-musl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
3 changes: 1 addition & 2 deletions usr/arm-linux-musl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
30 changes: 30 additions & 0 deletions usr/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -120,4 +147,7 @@ install_directory_root out

install_file_elf

strip_debug_info "$PLATFORM"


exit 0
2 changes: 1 addition & 1 deletion usr/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}

5 changes: 5 additions & 0 deletions usr/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,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()

11 changes: 11 additions & 0 deletions usr/src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.16)

add_executable(hello-world.elf hello_world.cpp)
add_executable(class-test.elf class_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)
add_executable(threads-test.elf threads_test.cpp)
add_executable(files-test.elf files_test.cpp)


35 changes: 35 additions & 0 deletions usr/src/tests/allocation_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2025 Jean-Pierre Miceli <jean-pierre.miceli@heig-vd.ch>
*
* 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 <new>
#include <iostream>

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;
}
53 changes: 53 additions & 0 deletions usr/src/tests/class_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2025 Jean-Pierre Miceli <jean-pierre.miceli@heig-vd.ch>
*
* 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 <iostream>
#include <string>

class Person {
private:
std::string _name;
int _age;

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;
}

// 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();

return 0;
}
28 changes: 28 additions & 0 deletions usr/src/tests/exception_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2025 Jean-Pierre Miceli <jean-pierre.miceli@heig-vd.ch>
*
* 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 <iostream>

int main()
{
try {
throw 42;
} catch (int x) {
std::cout << "caught: " << x << std::endl;
}
}
17 changes: 17 additions & 0 deletions usr/src/tests/files_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


#include <fstream>
#include <iostream>

int main()
{
std::ofstream file("example.txt");
if (!file) {
std::cerr << "Failed to open file\n";
return 1;
}

file << "Hello from C++\n";
// file closes automatically
return 0;
}
26 changes: 26 additions & 0 deletions usr/src/tests/hello_world.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2025 Jean-Pierre Miceli <jean-pierre.miceli@heig-vd.ch>
*
* 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 <iostream>

int main()
{
std::cout << "Hello World!" << std::endl;

return 0;
}
63 changes: 63 additions & 0 deletions usr/src/tests/stdlib_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2025 Jean-Pierre Miceli <jean-pierre.miceli@heig-vd.ch>
*
* 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 <iostream>
#include <vector>
#include <map>

void vector_test()
{
// Create and initialize a vector with 3 integer values
std::vector<int> numbers = { 10, 20, 30 };

// Compute the sum
int sum = 0;
for (int value : numbers) {
sum += value;
}

// 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;
}

void map_test()
{
std::map<int, int> m;

m[1] = 2;

std::cout << "Map m[1]: " << m[1] << std::endl;
}

int main()
{
vector_test();

string_test();

map_test();

return 0;
}
Loading