Skip to content
Open
3 changes: 3 additions & 0 deletions cmake/CMRX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ else()
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/arch/${CMRX_ARCH}/${CMRX_HAL}/CMRX.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/arch/${CMRX_ARCH}/${CMRX_HAL}/CMRX.cmake)
endif()
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/arch/${CMRX_ARCH}/platform/${CMRX_PLATFORM}/CMRX.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/arch/${CMRX_ARCH}/platform/${CMRX_PLATFORM}/CMRX.cmake)
endif()
endif()


Expand Down
3 changes: 3 additions & 0 deletions cmake/arch/arm/platform/rp2xxx/CMRX.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(CMRX_CUSTOM_FLASH_RANGE TRUE)
set(CMRX_CUSTOM_FLASH_START 0x0)
set(CMRX_CUSTOM_FLASH_SIZE 0x20000000)
24 changes: 21 additions & 3 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
option(CMRX_ARCH_SMP_SUPPORTED "Architecture supports SMP and project is using it" OFF)
option(CMRX_OS_NUM_CORES "Amount of cores present in CPU package" INT:1)
option(CMRX_UNIT_TESTS "Enable build of kernel unit tests" OFF)
set(CMRX_OS_NUM_CORES 1 CACHE STRING "Amount of cores present in CPU package")
if (CMAKE_HOST_WIN32)
set(UNIT_TESTS_DEFAULT OFF)
else()
set(UNIT_TESTS_DEFAULT ON)
endif()

if (NOT CMRX_PLATFORM)
set(CMRX_PLATFORM "generic" CACHE STRING "Specific platform within architecture to build for")
endif()

option(CMRX_UNIT_TESTS "Enable build of kernel unit tests" ${UNIT_TESTS_DEFAULT})
option(CMRX_KERNEL_TRACING "Enable tracing of kernel events" OFF)
option(CMRX_CLANG_TIDY "Enable linting using Clang-tidy" ON)
option(CMRX_KERNEL_TRANSACTION_VERIFICATION "Enable checking for nested transaction commits" OFF)
option(CMRX_IDLE_THREAD_SHUTDOWN_CPU "Idle thread stops CPU" OFF)

option(CMRX_CUSTOM_FLASH_RANGE "If set to ON then developer SHALL provide custom range that covers all readable and executable area. If set to OFF then kernel will determine this automatically based on linker file, if possible" OFF)
set(CMRX_CUSTOM_FLASH_START 0 CACHE STRING "Custom start address of FLASH region. FLASH region includes this address")
set(CMRX_CUSTOM_FLASH_SIZE 0 CACHE STRING "Custom size of FLASH region")

option(CMRX_RPC_CANARY "Enable RPC canaries" OFF)
option(CMRX_MAP_FILE_WITH_EXTENSION "MAP file contains full name of binary with ELF extension (.elf.map)" OFF)
option(CMRX_CLANG_TIDY_LIBC_PATH "Path to standard C library used while linting" /usr/include)
set(CMRX_CLANG_TIDY_LIBC_PATH /usr/include CACHE STRING "Path to standard C library used while linting")
option(CMRX_HIL_TESTING "Enable build of HIL tests and sanity check of HIL infrastructure configuration." OFF)
option(CMRX_INTEGRATION_TESTS "Enable build of integration tests. Implies CMRX_HIL_TESTING=ON!" OFF)
option(CMRX_HIL_TESTING_SKIP_OPENOCD "Skip OpenOCD initialization during integration tests." OFF)
Expand All @@ -23,6 +38,9 @@ set(CMRX_ALL_OPTIONS
CMRX_ARCH_SMP_SUPPORTED
CMRX_OS_NUM_CORES
CMRX_KERNEL_TRACING
CMRX_CUSTOM_FLASH_RANGE
CMRX_CUSTOM_FLASH_START
CMRX_CUSTOM_FLASH_SIZE
OS_STACK_SIZE
OS_THREADS
OS_PROCESSES
Expand Down
14 changes: 13 additions & 1 deletion conf/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define KERNEL_HAS_MEMORY_PROTECTION

/** How many MPU regions are saved per thread */
#define MPU_STATE_SIZE 7
#define MPU_STATE_SIZE 6

/** How many MPU regions are always used based on in which process thread is hosted */
#define MPU_HOSTED_STATE_SIZE 4
Expand Down Expand Up @@ -89,4 +89,16 @@
* There is no functional change.
*/
#cmakedefine CMRX_VERBOSE_API_NAMES

/** Enable / disable customized flash ranges.
* If this option is enabled then "flash" stard and end address can be supplied
* externally and it is not inferred from linker script.
*/
#cmakedefine CMRX_CUSTOM_FLASH_RANGE

#ifdef CMRX_CUSTOM_FLASH_RANGE
# define CMRX_CUSTOM_FLASH_START @CMRX_CUSTOM_FLASH_START@
# define CMRX_CUSTOM_FLASH_SIZE @CMRX_CUSTOM_FLASH_SIZE@
#endif

/** @} */
9 changes: 9 additions & 0 deletions src/os/arch/arm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ target_sources(os PRIVATE ${cmrx_arm_SRCS})
if (NOT ${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
target_compile_options(os PRIVATE -mgeneral-regs-only)
endif()

message(STATUS "Target platform: ${CMRX_PLATFORM}")
if (CMRX_PLATFORM)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${CMRX_PLATFORM}")
add_subdirectory(${CMRX_PLATFORM})
else()
message(FATAL_ERROR "Unable to include platform ${CMRX_PLATFORM} as it doesn't exist!")
endif()
endif()
9 changes: 9 additions & 0 deletions src/os/arch/arm/cmsis/arch/memory.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include <conf/kernel.h>

#ifndef CMRX_CUSTOM_FLASH_RANGE
/** This symbol is placed exactly at the address where FLASH starts by the linker script */
extern void * __cmrx_flash_origin;

Expand All @@ -12,4 +15,10 @@ extern void * __cmrx_flash_length;
/** Obtain size of all the .text in the flash image */
#define code_size() ((int)(&__cmrx_flash_length))

#else

#define code_base() (CMRX_CUSTOM_FLASH_START)
#define code_size() (CMRX_CUSTOM_FLASH_SIZE)

#endif

6 changes: 3 additions & 3 deletions src/os/arch/arm/cmsis/arch/mpu_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@
#define OS_MPU_REGION_MMIO2 3
/// Currently unused region (reserved)
#define OS_MPU_REGION_SHARED 4
/// Currently unused region (reserved)
#define OS_MPU_REGION_UNUSED2 5
/// Region covering thread's stack
#define OS_MPU_REGION_STACK 6
#define OS_MPU_REGION_STACK 5
/// Currently unused region (reserved)
#define OS_MPU_REGION_UNUSED2 6
/// Region covering executable RAM (?)
#define OS_MPU_REGION_EXECUTABLE 7

Expand Down
1 change: 1 addition & 0 deletions src/os/arch/arm/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target_include_directories(os PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
10 changes: 10 additions & 0 deletions src/os/arch/arm/generic/platform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

/* The default ARM platform does not use any of these
* thus they are defined as empty macros. This is
* intentional
*/

#define os_thread_initialize_platform(x)
#define os_init_platform(x)

2 changes: 2 additions & 0 deletions src/os/arch/arm/mpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ static const uint32_t __MPU_flags[] = {
MPU_RASR_ATTR_XN | MPU_RASR_ATTR_AP_PRW_URW,
};

_Static_assert(sizeof(__MPU_flags)/sizeof(__MPU_flags[0]) == MPU_FLAGS_COUNT, "Missing or extra entries in MPU flag mapping table");

#else

/** MPU region access rights for ARMv8M.
Expand Down
6 changes: 6 additions & 0 deletions src/os/arch/arm/rp2xxx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set(rp2xxx_SRCS
rp2xxx.c
)

target_sources(os PRIVATE ${rp2xxx_SRCS})
target_include_directories(os PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
6 changes: 6 additions & 0 deletions src/os/arch/arm/rp2xxx/platform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

struct OS_thread_t;

#define os_thread_initialize_platform(x)
void os_init_platform(void);
13 changes: 13 additions & 0 deletions src/os/arch/arm/rp2xxx/rp2xxx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "platform.h"

#include <kernel/mpu.h>
#include <arch/mpu_priv.h>

extern char __rp2xxx_platform_custom_start;
extern char __rp2xxx_platform_custom_end;

void os_init_platform(void)
{
// We can do this now because MPU region setup remains unchanged
mpu_set_region(OS_MPU_REGION_UNUSED2, (const void *) &__rp2xxx_platform_custom_start, &__rp2xxx_platform_custom_end - &__rp2xxx_platform_custom_start, MPU_RX);
}
1 change: 1 addition & 0 deletions src/os/arch/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ set(cmrx_testing_SRCS
)
target_sources(os PRIVATE ${cmrx_testing_SRCS})
target_link_libraries(os PRIVATE ctest)
target_include_directories(os PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
4 changes: 4 additions & 0 deletions src/os/arch/testing/platform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

#define os_thread_initialize_platform(x)
#define os_init_platform()
8 changes: 5 additions & 3 deletions src/os/kernel/mpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
*/
enum MPU_Flags {
/// Region cannot be accesses. Any attempt to access addresses from this region will result in hard fault
MPU_NONE,
MPU_NONE = 0,
/// Region can be read and executed. Attempt to write will result in hard fault
MPU_RX,
/// Region can be read, written and executed. No attempt to access region can result in hard fault
MPU_RWX,
/// Region can be read. Attempt to write into region, or execute out of it will result in hard fault
MPU_R,
MPU_RO,
/// Region can be read and written but cannot be executed. Attempt to execute code will result in hard fault
MPU_RW
MPU_RW,
/// Region can be read. Attempt to either write into region or execute it will result in hard fault
MPU_FLAGS_COUNT
};

/** @} */
3 changes: 3 additions & 0 deletions src/os/kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cmrx/sys/syscalls.h>
#include <cmrx/sys/notify.h>
#include <cmrx/clock.h>
#include <platform.h>
#include <string.h>

#define STACK_ALIGN
Expand Down Expand Up @@ -466,6 +467,7 @@ int os_thread_construct(Thread_t tid, entrypoint_t * entrypoint, void * data, ui
{
new_thread->stack_id = stack_id;
os_thread_initialize_arch(new_thread, OS_STACK_DWORD, entrypoint, data);
os_thread_initialize_platform(&os_threads[thread_id]);
new_thread->core_id = core_id;

new_thread->state = THREAD_STATE_READY;
Expand Down Expand Up @@ -554,6 +556,7 @@ void _os_start(uint8_t start_core)
kernel_structs_initialized = KERNEL_STRUCTS_INITIALIZED_SIGNATURE;
memset(&os_threads, 0, sizeof(os_threads)); // NOLINT - count is a compile-time constant
os_init_arch();
os_init_platform();
os_timer_init();
os_notify_init();
}
Expand Down
Loading