Checked RISC-V SMP assembly offsets at build time
This commit is contained in:
1 parent
cf9ac8b56f
commit
f3dc14193c
5 files changed
+24
-65
No files matched your search
@@ -14,6 +14,7 @@ set(THREADX_SMP_CUSTOM_INC
|
|||||||
set(THREADX_SMP_CUSTOM_SRC
|
set(THREADX_SMP_CUSTOM_SRC
|
||||||
src/trap_entry.S
|
src/trap_entry.S
|
||||||
src/tx_initialize_low_level.c
|
src/tx_initialize_low_level.c
|
||||||
|
src/tx_port_offset_check.c
|
||||||
src/tx_thread_context_restore.S
|
src/tx_thread_context_restore.S
|
||||||
src/tx_thread_context_save.S
|
src/tx_thread_context_save.S
|
||||||
src/tx_thread_interrupt_control.S
|
src/tx_thread_interrupt_control.S
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
if(NOT DEFINED COMPILER)
|
|
||||||
message(FATAL_ERROR "COMPILER is required")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT DEFINED SOURCE)
|
|
||||||
message(FATAL_ERROR "SOURCE is required")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT DEFINED ASM_OUTPUT)
|
|
||||||
message(FATAL_ERROR "ASM_OUTPUT is required")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT DEFINED HEADER_OUTPUT)
|
|
||||||
message(FATAL_ERROR "HEADER_OUTPUT is required")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT DEFINED GENERATE_SCRIPT)
|
|
||||||
message(FATAL_ERROR "GENERATE_SCRIPT is required")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND "${COMPILER}" ${COMPILER_ARG1} ${CFLAG_ARGS} ${INCLUDE_ARGS} ${DEFINE_ARGS} -S -o "${ASM_OUTPUT}" "${SOURCE}"
|
|
||||||
RESULT_VARIABLE compile_result
|
|
||||||
OUTPUT_VARIABLE compile_stdout
|
|
||||||
ERROR_VARIABLE compile_stderr
|
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT compile_result EQUAL 0)
|
|
||||||
message(FATAL_ERROR "failed to compile asm offsets source\n${compile_stdout}${compile_stderr}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND "${CMAKE_COMMAND}" -DINPUT="${ASM_OUTPUT}" -DOUTPUT="${HEADER_OUTPUT}" -P "${GENERATE_SCRIPT}"
|
|
||||||
RESULT_VARIABLE generate_result
|
|
||||||
OUTPUT_VARIABLE generate_stdout
|
|
||||||
ERROR_VARIABLE generate_stderr
|
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT generate_result EQUAL 0)
|
|
||||||
message(FATAL_ERROR "failed to generate asm offsets header\n${generate_stdout}${generate_stderr}")
|
|
||||||
endif()
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
if(NOT DEFINED INPUT)
|
|
||||||
message(FATAL_ERROR "INPUT is required")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT DEFINED OUTPUT)
|
|
||||||
message(FATAL_ERROR "OUTPUT is required")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
file(STRINGS "${INPUT}" OFFSET_LINES REGEX "->")
|
|
||||||
|
|
||||||
set(OFFSET_CONTENT "/* Generated by GenerateAsmOffsets.cmake. */\n")
|
|
||||||
|
|
||||||
foreach(LINE IN LISTS OFFSET_LINES)
|
|
||||||
string(REGEX MATCH "-->([A-Za-z0-9_]+)[^0-9-]*(-?[0-9]+)" _ "${LINE}")
|
|
||||||
if(NOT CMAKE_MATCH_1)
|
|
||||||
continue()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
string(APPEND OFFSET_CONTENT "#define ${CMAKE_MATCH_1} ${CMAKE_MATCH_2}\n")
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
file(WRITE "${OUTPUT}" "${OFFSET_CONTENT}")
|
|
||||||
@@ -54,6 +54,16 @@
|
|||||||
#ifndef TX_PORT_H
|
#ifndef TX_PORT_H
|
||||||
#define TX_PORT_H
|
#define TX_PORT_H
|
||||||
|
|
||||||
|
/* Assembly uses this byte displacement for atomic accesses to
|
||||||
|
TX_THREAD.tx_thread_smp_core_control. Changes to ULONG, the control block,
|
||||||
|
or thread and timer extensions can move the field. Recheck the layout with
|
||||||
|
the target compiler when changing it. See tx_port_offset_check.c. */
|
||||||
|
#if __riscv_xlen == 64
|
||||||
|
#define TX_THREAD_SMP_LOCK_READY_BIT_OFFSET 280
|
||||||
|
#else
|
||||||
|
#define TX_THREAD_SMP_LOCK_READY_BIT_OFFSET 152
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __ASSEMBLER__
|
#ifdef __ASSEMBLER__
|
||||||
|
|
||||||
#if __riscv_xlen == 64
|
#if __riscv_xlen == 64
|
||||||
@@ -64,7 +74,6 @@
|
|||||||
#define AMOSWAP_AQ amoswap.d.aq
|
#define AMOSWAP_AQ amoswap.d.aq
|
||||||
#define AMOSWAP_RL amoswap.d.rl
|
#define AMOSWAP_RL amoswap.d.rl
|
||||||
#define LOG_REGBYTES 3
|
#define LOG_REGBYTES 3
|
||||||
#define TX_THREAD_SMP_LOCK_READY_BIT_OFFSET 312 // This changes if thread or timer internal extensions are used
|
|
||||||
#else
|
#else
|
||||||
#define SLL32 sll
|
#define SLL32 sll
|
||||||
#define STORE sw
|
#define STORE sw
|
||||||
@@ -73,7 +82,6 @@
|
|||||||
#define AMOSWAP_AQ amoswap.w.aq
|
#define AMOSWAP_AQ amoswap.w.aq
|
||||||
#define AMOSWAP_RL amoswap.w.rl
|
#define AMOSWAP_RL amoswap.w.rl
|
||||||
#define LOG_REGBYTES 2
|
#define LOG_REGBYTES 2
|
||||||
#define TX_THREAD_SMP_LOCK_READY_BIT_OFFSET 168 // This changes if thread or timer internal extensions are used
|
|
||||||
#endif
|
#endif
|
||||||
#define REGBYTES (1 << LOG_REGBYTES)
|
#define REGBYTES (1 << LOG_REGBYTES)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "tx_api.h"
|
||||||
|
|
||||||
|
/* Use C99 typedefs so stale assembly layout assumptions fail the build. */
|
||||||
|
typedef char tx_port_assert_ready_token_offset[
|
||||||
|
offsetof(TX_THREAD, tx_thread_smp_core_control) == TX_THREAD_SMP_LOCK_READY_BIT_OFFSET ? 1 : -1];
|
||||||
|
|
||||||
|
typedef char tx_port_assert_ready_token_atomic_width_and_alignment[
|
||||||
|
sizeof(((TX_THREAD *) 0)->tx_thread_smp_core_control) == __riscv_xlen / 8 &&
|
||||||
|
TX_THREAD_SMP_LOCK_READY_BIT_OFFSET % (__riscv_xlen / 8) == 0 ? 1 : -1];
|
||||||
Reference in new issue
Block a user