diff --git a/.github/workflows/ci_cortex_m.yml b/.github/workflows/ci_cortex_m.yml index 933c950fb..f3f98fa00 100644 --- a/.github/workflows/ci_cortex_m.yml +++ b/.github/workflows/ci_cortex_m.yml @@ -34,6 +34,12 @@ on: - 'ports/cortex_m3/gnu/**' - 'ports/cortex_m4/gnu/**' - 'ports/cortex_m7/gnu/**' + - 'ports_module/cortex_m0+/gnu/**' + - 'ports_module/cortex_m3/gnu/**' + - 'ports_module/cortex_m4/gnu/**' + - 'ports_module/cortex_m7/gnu/**' + - 'common_modules/**' + - 'CMakeLists.txt' jobs: build: @@ -111,3 +117,11 @@ jobs: - name: Compile and link run: cmake --build ./build + + - name: Prepare build system (module manager) + run: cmake -Bbuild-mm -DCMAKE_TOOLCHAIN_FILE=./cmake/cortex_m${{ matrix.port }}.cmake -DTHREADX_MODULE_MANAGER=ON -GNinja . + + - name: Compile and link (module manager) + run: | + cmake --build ./build-mm + cmake --build ./build-mm --target threadx-module-manager-consumer-check diff --git a/CMakeLists.txt b/CMakeLists.txt index 940717df9..05784383a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ if(NOT ((THREADX_ARCH STREQUAL "win32") OR (THREADX_ARCH STREQUAL "win64"))) endif() option(THREADX_SMP "Build ThreadX SMP version" OFF) +option(THREADX_MODULE_MANAGER "Build ThreadX kernel with module manager support" OFF) # Enable testing at the top level so that tests registered by ports and # example builds further down the tree are discoverable with ctest from the @@ -31,7 +32,33 @@ option(THREADX_SMP "Build ThreadX SMP version" OFF) # "ctest --test-dir " reports no tests at all. enable_testing() -if(THREADX_SMP) +if(THREADX_MODULE_MANAGER) + set(TX_PORT_DIR "ports_module") + if(THREADX_SMP) + set(TX_COMMON_DIR "common_smp") + if(THREADX_ARCH MATCHES "_smp$") + set(TX_ARCH_DIR "${THREADX_ARCH}") + else() + set(TX_ARCH_DIR "${THREADX_ARCH}_smp") + endif() + message(STATUS "Building ThreadX module manager SMP version") + else() + set(TX_COMMON_DIR "common") + set(TX_ARCH_DIR "${THREADX_ARCH}") + if(THREADX_ARCH STREQUAL "cortex_m0" AND NOT IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/${TX_PORT_DIR}/${TX_ARCH_DIR}") + set(TX_ARCH_DIR "cortex_m0+") + endif() + if(THREADX_ARCH MATCHES "_smp$") + message(FATAL_ERROR "ThreadX module manager SMP port '${THREADX_ARCH}' requires THREADX_SMP=ON") + endif() + message(STATUS "Building ThreadX module manager version") + endif() + + set(TX_PORT_PATH "${CMAKE_CURRENT_LIST_DIR}/${TX_PORT_DIR}/${TX_ARCH_DIR}/${THREADX_TOOLCHAIN}") + if(NOT IS_DIRECTORY "${TX_PORT_PATH}/module_manager/src") + message(FATAL_ERROR "ThreadX module manager is not supported for architecture '${THREADX_ARCH}' with toolchain '${THREADX_TOOLCHAIN}' (SMP=${THREADX_SMP})") + endif() +elseif(THREADX_SMP) set(TX_PORT_DIR "ports_smp") set(TX_COMMON_DIR "common_smp") set(TX_ARCH_DIR "${THREADX_ARCH}_smp") @@ -43,11 +70,13 @@ if(THREADX_SMP) set(TX_ARCH_DIR "${THREADX_ARCH}") endif() message(STATUS "Building ThreadX SMP version") + set(TX_PORT_PATH "${CMAKE_CURRENT_LIST_DIR}/${TX_PORT_DIR}/${TX_ARCH_DIR}/${THREADX_TOOLCHAIN}") else() set(TX_PORT_DIR "ports") set(TX_COMMON_DIR "common") set(TX_ARCH_DIR "${THREADX_ARCH}") message(STATUS "Building standard ThreadX version") + set(TX_PORT_PATH "${CMAKE_CURRENT_LIST_DIR}/${TX_PORT_DIR}/${TX_ARCH_DIR}/${THREADX_TOOLCHAIN}") endif() message(STATUS "THREADX_ARCH: ${THREADX_ARCH}") @@ -63,12 +92,39 @@ set(CUSTOM_INC_DIR ${CMAKE_CURRENT_BINARY_DIR}/custom_inc) # Pick up the port specific variables and apply them if(DEFINED THREADX_CUSTOM_PORT) add_subdirectory(${THREADX_CUSTOM_PORT} threadx_port) +elseif(EXISTS "${TX_PORT_PATH}/CMakeLists.txt") + add_subdirectory(${TX_PORT_PATH}) +elseif(THREADX_MODULE_MANAGER) + file(GLOB TX_PORT_SOURCES + "${TX_PORT_PATH}/module_manager/src/*.c" + "${TX_PORT_PATH}/module_manager/src/*.S" + "${TX_PORT_PATH}/module_manager/src/*.s" + ) + if(THREADX_ARCH STREQUAL "cortex_r52") + file(GLOB TX_R52_BASE_SOURCES + "${CMAKE_CURRENT_LIST_DIR}/ports/cortex_r52/gnu/src/tx_thread_fiq_*.S" + "${CMAKE_CURRENT_LIST_DIR}/ports/cortex_r52/gnu/src/tx_thread_irq_*.S" + "${CMAKE_CURRENT_LIST_DIR}/ports/cortex_r52/gnu/src/tx_thread_interrupt_*.S" + "${CMAKE_CURRENT_LIST_DIR}/ports/cortex_r52/gnu/src/tx_thread_vectored_context_save.S" + "${CMAKE_CURRENT_LIST_DIR}/ports/cortex_r52/gnu/src/tx_timer_interrupt.S" + ) + list(APPEND TX_PORT_SOURCES ${TX_R52_BASE_SOURCES}) + endif() + target_sources(${PROJECT_NAME} PRIVATE ${TX_PORT_SOURCES}) + target_include_directories(${PROJECT_NAME} + SYSTEM + PUBLIC + ${TX_PORT_PATH}/inc + ) else() - add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${TX_PORT_DIR}/${TX_ARCH_DIR}/${THREADX_TOOLCHAIN}) + add_subdirectory(${TX_PORT_PATH}) endif() # Pick up the common stuff add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${TX_COMMON_DIR}) +if(THREADX_MODULE_MANAGER) + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/common_modules/module_manager) +endif() # Define the FreeRTOS adaptation layer add_library(freertos-threadx EXCLUDE_FROM_ALL) @@ -118,6 +174,9 @@ target_compile_definitions(${PROJECT_NAME} PUBLIC "TX_INCLUDE_USER_DEFINE_FILE" if(THREADX_SMP) target_compile_definitions(${PROJECT_NAME} PUBLIC "TX_MPCORE" ) endif() +if(THREADX_MODULE_MANAGER) + target_compile_definitions(${PROJECT_NAME} PUBLIC "TXM_MODULE_MANAGER" ) +endif() # Optional: build for S-mode (Supervisor mode) instead of M-mode (Machine mode). # Required when running after OpenSBI, e.g. booted from U-Boot. diff --git a/README.md b/README.md index 256162ae4..a12d61c6c 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,17 @@ Instruction for building the ThreadX as static library using Arm GNU Toolchain a $ cmake --build ./build ``` + To build ThreadX with module manager support, enable `THREADX_MODULE_MANAGER`: + + ```bash + $ cmake -Bbuild-mm -GNinja -DCMAKE_TOOLCHAIN_FILE=cmake/cortex_m4.cmake -DTHREADX_MODULE_MANAGER=ON . + + $ cmake --build ./build-mm + ``` + + When enabled, the `azrtos::threadx` target includes the module manager kernel sources and public include headers (`txm_module.h`) for downstream targets. + + ## Licensing License terms for using Eclipse ThreadX are defined in the LICENSE.txt file of this repo. Please refer to this file for all definitive licensing information for all content, incl. the history of this repo. diff --git a/common_modules/module_manager/CMakeLists.txt b/common_modules/module_manager/CMakeLists.txt new file mode 100644 index 000000000..f6dce7a4d --- /dev/null +++ b/common_modules/module_manager/CMakeLists.txt @@ -0,0 +1,47 @@ +# Copyright (c) 2026 Eclipse ThreadX contributors +# SPDX-License-Identifier: MIT + +target_sources(${PROJECT_NAME} + PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_absolute_load.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_absolute_load_extended.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_application_request.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_callback_request.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_event_flags_notify_trampoline.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_file_load.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_in_place_load.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_initialize.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_internal_load.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_kernel_dispatch.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_maximum_module_priority_set.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_memory_load.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_object_allocate.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_object_deallocate.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_object_pointer_get.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_object_pointer_get_extended.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_object_pool_create.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_properties_get.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_queue_notify_trampoline.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_semaphore_notify_trampoline.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_start.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_stop.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_thread_create.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_thread_notify_trampoline.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_thread_reset.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_timer_notify_trampoline.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_unload.c + ${CMAKE_CURRENT_LIST_DIR}/src/txm_module_manager_util.c +) + +target_include_directories(${PROJECT_NAME} + SYSTEM + PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/inc + ${CMAKE_CURRENT_LIST_DIR}/../inc +) + +# Define consumer check demonstrating compilation against the module-manager API +add_library(threadx-module-manager-consumer-check OBJECT EXCLUDE_FROM_ALL + ${CMAKE_CURRENT_LIST_DIR}/consumer_check.c +) +target_link_libraries(threadx-module-manager-consumer-check PRIVATE azrtos::threadx) diff --git a/common_modules/module_manager/consumer_check.c b/common_modules/module_manager/consumer_check.c new file mode 100644 index 000000000..a94bd0c5b --- /dev/null +++ b/common_modules/module_manager/consumer_check.c @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ +// Portions of this file were generated with AI assistance. + +#include "tx_api.h" +#include "txm_module.h" + +static TX_THREAD module_manager_thread; +static ULONG module_manager_stack[1024 / sizeof(ULONG)]; +static UCHAR object_memory_pool[16384]; +static UCHAR module_data_area[32768]; +static TXM_MODULE_INSTANCE test_module; + +static VOID module_manager_entry(ULONG input) +{ + (VOID) input; + txm_module_manager_initialize((VOID *) module_data_area, sizeof(module_data_area)); + txm_module_manager_object_pool_create(object_memory_pool, sizeof(object_memory_pool)); + txm_module_manager_maximum_module_priority_set(&test_module, 5); + txm_module_manager_start(&test_module); + txm_module_manager_stop(&test_module); + txm_module_manager_unload(&test_module); +} + +VOID tx_application_define(VOID *first_unused_memory) +{ + (VOID) first_unused_memory; + tx_thread_create(&module_manager_thread, "Module Manager", + module_manager_entry, 0, + module_manager_stack, sizeof(module_manager_stack), + 1, 1, TX_NO_TIME_SLICE, TX_AUTO_START); +} + +int main(void) +{ + tx_kernel_enter(); + return 0; +} diff --git a/ports/cortex_r52/gnu/inc/tx_port.h b/ports/cortex_r52/gnu/inc/tx_port.h index 52b2edd64..fc317407e 100644 --- a/ports/cortex_r52/gnu/inc/tx_port.h +++ b/ports/cortex_r52/gnu/inc/tx_port.h @@ -286,12 +286,10 @@ typedef unsigned short USHORT; build therefore keeps the portable loop on purpose. (On this core it is moot: the R52 toolchain file builds -marm.) - Two deliberate deviations, per AGENTS.md: + Two deliberate MISRA C:2023 deviations: - - Rule 1.2, language extensions. Inline assembly is the entire point of the - macro; there is no conforming way to reach CLZ. Spelled __asm__ and not - asm, because the asm keyword is rejected under -std=c99 -- verified, it is - an "'asm' undeclared" error -- and AGENTS.md requires C99 compatibility. + - Rule 1.2 and Directive 4.3. Inline assembly accesses the CLZ instruction. + The __asm__ spelling supports GCC builds in strict C99 mode. - Rule 10.1 / 10.3 on the isolation step, which is why it is respelled. Upstream isolates the lowest set bit with (ULONG) (-((LONG) m)): that diff --git a/ports_module/cortex_a7/gnu/inc/tx_port.h b/ports_module/cortex_a7/gnu/inc/tx_port.h index 7d0731fba..d32a9ca86 100644 --- a/ports_module/cortex_a7/gnu/inc/tx_port.h +++ b/ports_module/cortex_a7/gnu/inc/tx_port.h @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -257,7 +258,7 @@ typedef unsigned short USHORT; /* Redefine the macro for calculating the lowest bit set. */ #define TX_LOWEST_SET_BIT_CALCULATE(m, b) m = m & ((ULONG) (-((LONG) m))); \ - asm volatile (" CLZ %0,%1 ": "=r" (b) : "r" (m) ); \ + __asm__ volatile (" CLZ %0,%1 ": "=r" (b) : "r" (m) ); \ b = 31 - b; /* Define ThreadX interrupt lockout and restore macros for protection on @@ -273,15 +274,15 @@ typedef unsigned short USHORT; #define TX_DISABLE \ { \ - asm volatile (" MRS %0,CPSR": "=r" (interrupt_save)); \ - asm volatile (" CPSID if"); \ + __asm__ volatile (" MRS %0,CPSR": "=r" (interrupt_save)); \ + __asm__ volatile (" CPSID if"); \ } #define TX_RESTORE \ { \ if ((interrupt_save & 0x40) == 0) \ - asm volatile (" CPSIE f"); \ + __asm__ volatile (" CPSIE f"); \ if ((interrupt_save & 0x80) == 0) \ - asm volatile (" CPSIE i"); \ + __asm__ volatile (" CPSIE i"); \ } @@ -289,13 +290,13 @@ typedef unsigned short USHORT; #define TX_DISABLE \ { \ - asm volatile (" MRS %0,CPSR": "=r" (interrupt_save)); \ - asm volatile (" CPSID i"); \ + __asm__ volatile (" MRS %0,CPSR": "=r" (interrupt_save)); \ + __asm__ volatile (" CPSID i"); \ } #define TX_RESTORE \ { \ if ((interrupt_save & 0x80) == 0) \ - asm volatile (" CPSIE i"); \ + __asm__ volatile (" CPSIE i"); \ } #endif diff --git a/ports_module/cortex_m23/gnu/module_manager/src/tx_thread_secure_stack.c b/ports_module/cortex_m23/gnu/module_manager/src/tx_thread_secure_stack.c index 684366aed..928178cf9 100644 --- a/ports_module/cortex_m23/gnu/module_manager/src/tx_thread_secure_stack.c +++ b/ports_module/cortex_m23/gnu/module_manager/src/tx_thread_secure_stack.c @@ -144,7 +144,7 @@ ULONG ipsr; INT index; /* Make sure function is called from interrupt (threads should not call). */ - asm volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ + __asm__ volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ if (ipsr == 0) { status = TX_CALLER_ERROR; @@ -152,14 +152,14 @@ INT index; else { /* Set secure mode to use PSP. */ - asm volatile("MRS %0, CONTROL" : "=r" (control)); /* Get CONTROL register. */ + __asm__ volatile("MRS %0, CONTROL" : "=r" (control)); /* Get CONTROL register. */ control |= 2; /* Use PSP. */ - asm volatile("MSR CONTROL, %0" :: "r" (control)); /* Set CONTROL register. */ + __asm__ volatile("MSR CONTROL, %0" :: "r" (control)); /* Set CONTROL register. */ /* Set process stack pointer and stack limit to 0 to throw exception when a thread without a secure stack calls a secure function that tries to use secure stack. */ - asm volatile("MSR PSPLIM, %0" :: "r" (0)); - asm volatile("MSR PSP, %0" :: "r" (0)); + __asm__ volatile("MSR PSPLIM, %0" :: "r" (0)); + __asm__ volatile("MSR PSP, %0" :: "r" (0)); for (index = 0; index < TX_MAX_SECURE_CONTEXTS; index++) { @@ -249,7 +249,7 @@ INT secure_context_index; status = TX_SUCCESS; /* Make sure function is called from interrupt (threads should not call). */ - asm volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ + __asm__ volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ if (ipsr == 0) { status = TX_CALLER_ERROR; @@ -312,12 +312,12 @@ INT secure_context_index; thread_ptr -> tx_thread_secure_stack_context = (VOID *)(secure_context_index + 1); /* Check if this thread is running by looking at its stack start and PSPLIM_NS */ - asm volatile("MRS %0, PSPLIM_NS" : "=r" (psplim_ns)); /* Get PSPLIM_NS register. */ + __asm__ volatile("MRS %0, PSPLIM_NS" : "=r" (psplim_ns)); /* Get PSPLIM_NS register. */ if(((ULONG) thread_ptr -> tx_thread_stack_start & 0xFFFFFFF8) == psplim_ns) { /* If this thread is running, set Secure PSP and PSPLIM. */ - asm volatile("MSR PSPLIM, %0" :: "r" ((ULONG)(info_ptr -> tx_thread_secure_stack_limit))); - asm volatile("MSR PSP, %0" :: "r" ((ULONG)(info_ptr -> tx_thread_secure_stack_ptr))); + __asm__ volatile("MSR PSPLIM, %0" :: "r" ((ULONG)(info_ptr -> tx_thread_secure_stack_limit))); + __asm__ volatile("MSR PSP, %0" :: "r" ((ULONG)(info_ptr -> tx_thread_secure_stack_ptr))); } } @@ -405,7 +405,7 @@ INT secure_context_index; status = TX_SUCCESS; /* Make sure function is called from interrupt (threads should not call). */ - asm volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ + __asm__ volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ if (ipsr == 0) { status = TX_CALLER_ERROR; @@ -520,7 +520,7 @@ ULONG ipsr; INT secure_context_index; /* This function should be called from scheduler only. */ - asm volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ + __asm__ volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ if (ipsr == 0) { return; @@ -552,7 +552,7 @@ INT secure_context_index; } /* Check that stack pointer is in range */ - asm volatile("MRS %0, PSP" : "=r" (sp)); /* Get PSP register. */ + __asm__ volatile("MRS %0, PSP" : "=r" (sp)); /* Get PSP register. */ if ((sp < (ULONG)info_ptr -> tx_thread_secure_stack_limit) || (sp > (ULONG)info_ptr -> tx_thread_secure_stack_start)) { @@ -564,8 +564,8 @@ INT secure_context_index; /* Set process stack pointer and stack limit to 0 to throw exception when a thread without a secure stack calls a secure function that tries to use secure stack. */ - asm volatile("MSR PSPLIM, %0" :: "r" (0)); - asm volatile("MSR PSP, %0" :: "r" (0)); + __asm__ volatile("MSR PSPLIM, %0" :: "r" (0)); + __asm__ volatile("MSR PSP, %0" :: "r" (0)); return; } @@ -625,7 +625,7 @@ ULONG ipsr; INT secure_context_index; /* This function should be called from scheduler only. */ - asm volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ + __asm__ volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ if (ipsr == 0) { return; @@ -657,8 +657,8 @@ INT secure_context_index; } /* Set stack pointer and limit. */ - asm volatile("MSR PSPLIM, %0" :: "r" ((ULONG)info_ptr -> tx_thread_secure_stack_limit)); - asm volatile("MSR PSP, %0" :: "r" ((ULONG)info_ptr -> tx_thread_secure_stack_ptr)); + __asm__ volatile("MSR PSPLIM, %0" :: "r" ((ULONG)info_ptr -> tx_thread_secure_stack_limit)); + __asm__ volatile("MSR PSP, %0" :: "r" ((ULONG)info_ptr -> tx_thread_secure_stack_ptr)); return; } diff --git a/ports_module/cortex_m33/gnu/module_manager/src/tx_thread_secure_stack.c b/ports_module/cortex_m33/gnu/module_manager/src/tx_thread_secure_stack.c index 0d7f4833e..f0492cfa2 100644 --- a/ports_module/cortex_m33/gnu/module_manager/src/tx_thread_secure_stack.c +++ b/ports_module/cortex_m33/gnu/module_manager/src/tx_thread_secure_stack.c @@ -144,7 +144,7 @@ ULONG ipsr; INT index; /* Make sure function is called from interrupt (threads should not call). */ - asm volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ + __asm__ volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ if (ipsr == 0) { status = TX_CALLER_ERROR; @@ -152,14 +152,14 @@ INT index; else { /* Set secure mode to use PSP. */ - asm volatile("MRS %0, CONTROL" : "=r" (control)); /* Get CONTROL register. */ + __asm__ volatile("MRS %0, CONTROL" : "=r" (control)); /* Get CONTROL register. */ control |= 2; /* Use PSP. */ - asm volatile("MSR CONTROL, %0" :: "r" (control)); /* Set CONTROL register. */ + __asm__ volatile("MSR CONTROL, %0" :: "r" (control)); /* Set CONTROL register. */ /* Set process stack pointer and stack limit to 0 to throw exception when a thread without a secure stack calls a secure function that tries to use secure stack. */ - asm volatile("MSR PSPLIM, %0" :: "r" (0)); - asm volatile("MSR PSP, %0" :: "r" (0)); + __asm__ volatile("MSR PSPLIM, %0" :: "r" (0)); + __asm__ volatile("MSR PSP, %0" :: "r" (0)); for (index = 0; index < TX_MAX_SECURE_CONTEXTS; index++) { @@ -247,7 +247,7 @@ INT secure_context_index; status = TX_SUCCESS; /* Make sure function is called from interrupt (threads should not call). */ - asm volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ + __asm__ volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ if (ipsr == 0) { status = TX_CALLER_ERROR; @@ -310,12 +310,12 @@ INT secure_context_index; thread_ptr -> tx_thread_secure_stack_context = (VOID *)(secure_context_index + 1); /* Check if this thread is running by looking at its stack start and PSPLIM_NS */ - asm volatile("MRS %0, PSPLIM_NS" : "=r" (psplim_ns)); /* Get PSPLIM_NS register. */ + __asm__ volatile("MRS %0, PSPLIM_NS" : "=r" (psplim_ns)); /* Get PSPLIM_NS register. */ if(((ULONG) thread_ptr -> tx_thread_stack_start & 0xFFFFFFF8) == psplim_ns) { /* If this thread is running, set Secure PSP and PSPLIM. */ - asm volatile("MSR PSPLIM, %0" :: "r" ((ULONG)(info_ptr -> tx_thread_secure_stack_limit))); - asm volatile("MSR PSP, %0" :: "r" ((ULONG)(info_ptr -> tx_thread_secure_stack_ptr))); + __asm__ volatile("MSR PSPLIM, %0" :: "r" ((ULONG)(info_ptr -> tx_thread_secure_stack_limit))); + __asm__ volatile("MSR PSP, %0" :: "r" ((ULONG)(info_ptr -> tx_thread_secure_stack_ptr))); } } @@ -400,7 +400,7 @@ INT secure_context_index; status = TX_SUCCESS; /* Make sure function is called from interrupt (threads should not call). */ - asm volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ + __asm__ volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ if (ipsr == 0) { status = TX_CALLER_ERROR; @@ -512,7 +512,7 @@ ULONG ipsr; INT secure_context_index; /* This function should be called from scheduler only. */ - asm volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ + __asm__ volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ if (ipsr == 0) { return; @@ -544,7 +544,7 @@ INT secure_context_index; } /* Check that stack pointer is in range */ - asm volatile("MRS %0, PSP" : "=r" (sp)); /* Get PSP register. */ + __asm__ volatile("MRS %0, PSP" : "=r" (sp)); /* Get PSP register. */ if ((sp < (ULONG)info_ptr -> tx_thread_secure_stack_limit) || (sp > (ULONG)info_ptr -> tx_thread_secure_stack_start)) { @@ -556,8 +556,8 @@ INT secure_context_index; /* Set process stack pointer and stack limit to 0 to throw exception when a thread without a secure stack calls a secure function that tries to use secure stack. */ - asm volatile("MSR PSPLIM, %0" :: "r" (0)); - asm volatile("MSR PSP, %0" :: "r" (0)); + __asm__ volatile("MSR PSPLIM, %0" :: "r" (0)); + __asm__ volatile("MSR PSP, %0" :: "r" (0)); return; } @@ -614,7 +614,7 @@ ULONG ipsr; INT secure_context_index; /* This function should be called from scheduler only. */ - asm volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ + __asm__ volatile("MRS %0, IPSR" : "=r" (ipsr)); /* Get IPSR register. */ if (ipsr == 0) { return; @@ -646,8 +646,8 @@ INT secure_context_index; } /* Set stack pointer and limit. */ - asm volatile("MSR PSPLIM, %0" :: "r" ((ULONG)info_ptr -> tx_thread_secure_stack_limit)); - asm volatile("MSR PSP, %0" :: "r" ((ULONG)info_ptr -> tx_thread_secure_stack_ptr)); + __asm__ volatile("MSR PSPLIM, %0" :: "r" ((ULONG)info_ptr -> tx_thread_secure_stack_limit)); + __asm__ volatile("MSR PSP, %0" :: "r" ((ULONG)info_ptr -> tx_thread_secure_stack_ptr)); return; } diff --git a/ports_module/cortex_r52/gnu/inc/tx_port.h b/ports_module/cortex_r52/gnu/inc/tx_port.h index bd489f199..06acc8d23 100644 --- a/ports_module/cortex_r52/gnu/inc/tx_port.h +++ b/ports_module/cortex_r52/gnu/inc/tx_port.h @@ -335,12 +335,10 @@ typedef unsigned short USHORT; build therefore keeps the portable loop on purpose. (On this core it is moot: the R52 toolchain file builds -marm.) - Two deliberate deviations, per AGENTS.md: + Two deliberate MISRA C:2023 deviations: - - Rule 1.2, language extensions. Inline assembly is the entire point of the - macro; there is no conforming way to reach CLZ. Spelled __asm__ and not - asm, because the asm keyword is rejected under -std=c99 -- verified, it is - an "'asm' undeclared" error -- and AGENTS.md requires C99 compatibility. + - Rule 1.2 and Directive 4.3. Inline assembly accesses the CLZ instruction. + The __asm__ spelling supports GCC builds in strict C99 mode. - Rule 10.1 / 10.3 on the isolation step, which is why it is respelled. Upstream isolates the lowest set bit with (ULONG) (-((LONG) m)): that @@ -408,12 +406,12 @@ unsigned int _tx_thread_interrupt_restore(UINT old_posture); #define TX_INTERRUPT_SAVE_AREA UINT interrupt_save; #ifdef TX_ENABLE_FIQ_SUPPORT -#define TX_DISABLE asm volatile (" MRS %0,CPSR; CPSID if ": "=r" (interrupt_save) ); +#define TX_DISABLE __asm__ volatile (" MRS %0,CPSR; CPSID if ": "=r" (interrupt_save) ); #else -#define TX_DISABLE asm volatile (" MRS %0,CPSR; CPSID i ": "=r" (interrupt_save) ); +#define TX_DISABLE __asm__ volatile (" MRS %0,CPSR; CPSID i ": "=r" (interrupt_save) ); #endif -#define TX_RESTORE asm volatile (" MSR CPSR_c,%0 "::"r" (interrupt_save) ); +#define TX_RESTORE __asm__ volatile (" MSR CPSR_c,%0 "::"r" (interrupt_save) ); #endif