diff --git a/CMakeLists.txt b/CMakeLists.txt index ea01580..fc8e32c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,7 @@ add_executable(skl_tunnel app/src/app_logging.cpp main.cpp + syscalls.c ) target_include_directories(skl_tunnel diff --git a/arm-none-eabi.cmake b/arm-none-eabi.cmake index 5550eda..662327b 100644 --- a/arm-none-eabi.cmake +++ b/arm-none-eabi.cmake @@ -34,9 +34,9 @@ set(CMAKE_CXX_COMPILER arm-none-eabi-g++) set(CMAKE_ASM_COMPILER arm-none-eabi-as) set(CMAKE_RANLIB arm-none-eabi-ranlib) -set(COMMON_C_FLAGS "-mcpu=cortex-m0plus -mfloat-abi=soft -mthumb -mlong-calls -fdata-sections -ffunction-sections -Wall -Wextra -O2") +set(COMMON_C_FLAGS "-mcpu=cortex-m0plus -mfloat-abi=soft -mthumb -mlong-calls -fdata-sections -ffunction-sections -Wall -Wextra -Wswitch-enum -Og") set(CMAKE_C_FLAGS_INIT "${COMMON_C_FLAGS}") -set(CMAKE_CXX_FLAGS_INIT "${COMMON_C_FLAGS} -fno-exceptions -fno-rtti") +set(CMAKE_CXX_FLAGS_INIT "${COMMON_C_FLAGS} -fno-exceptions -fno-rtti -fno-use-cxa-atexit") set(CMAKE_ASM_FLAGS_INIT "${COMMON_C_FLAGS}") -set(CMAKE_EXE_LINKER_FLAGS_INIT "${COMMON_C_FLAGS} -specs=nosys.specs") +set(CMAKE_EXE_LINKER_FLAGS_INIT "${COMMON_C_FLAGS} -specs=nano.specs -specs=nosys.specs") diff --git a/syscalls.c b/syscalls.c new file mode 100644 index 0000000..85741f5 --- /dev/null +++ b/syscalls.c @@ -0,0 +1,38 @@ +// +// Created by erki on 10.07.22. +// + +#include +#include +#include +#include +#include +#include +#include +#include + +extern int __io_putchar(int ch) __attribute__((weak)); +extern int __io_getchar(void) __attribute__((weak)); + +__attribute__((weak)) int _read(int file, char *ptr, int len) +{ + int DataIdx; + + for (DataIdx = 0; DataIdx < len; DataIdx++) + { + *ptr++ = __io_getchar(); + } + + return len; +} + +__attribute__((weak)) int _write(int file, char *ptr, int len) +{ + int DataIdx; + + for (DataIdx = 0; DataIdx < len; DataIdx++) + { + __io_putchar(*ptr++); + } + return len; +}