From 7cc6e316884f9d7a2aea82a40c9c4b8ee75a3b47 Mon Sep 17 00:00:00 2001 From: Hongyu Liu Date: Thu, 27 Nov 2025 15:41:56 +0100 Subject: [PATCH] add entry_threadx.s --- test_fw/CMakeLists.txt | 29 +++++++++++++++++++++- test_fw/entry_threadx.S | 53 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 test_fw/entry_threadx.S diff --git a/test_fw/CMakeLists.txt b/test_fw/CMakeLists.txt index 2988b7c..07cff21 100644 --- a/test_fw/CMakeLists.txt +++ b/test_fw/CMakeLists.txt @@ -2,12 +2,39 @@ cmake_minimum_required(VERSION 3.21) project(test_fw C) set(TARGET test_fw) add_executable(${TARGET} test_fw.c) +# Paths to ThreadX +set(THREADX_DIR "/scratch/hongyu/workarea/ThreadX/threadx/") # change to where ThreadX is located + + +set(THREADX_LIB "${THREADX_DIR}/build_liu/libthreadx.a") + + set(BOARD "iss" CACHE STRING "Target board") +target_compile_options(test_fw PRIVATE + -msmall-data-limit=0 +) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../bare-metal-bsp bsp) -target_link_libraries(${TARGET} PRIVATE bsp) +target_link_libraries(${TARGET} PRIVATE + -Wl,--start-group + startup + runtime + wrap + ${THREADX_LIB} + -Wl,--end-group +) target_link_options(${TARGET} PRIVATE LINKER:-Map=${TARGET}.map) + + +#target_link_libraries(${TARGET} PRIVATE ${THREADX_LIB}) + +target_include_directories(${TARGET} PRIVATE + ${THREADX_DIR}/common/inc + ${THREADX_DIR}/ports/risc-v64/gnu/inc +) + add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJDUMP} -S ${TARGET}.elf > ${TARGET}.dis COMMENT "Creating disassembly for ${TARGET}") diff --git a/test_fw/entry_threadx.S b/test_fw/entry_threadx.S new file mode 100644 index 0000000..a599d5c --- /dev/null +++ b/test_fw/entry_threadx.S @@ -0,0 +1,53 @@ +// See LICENSE for license details + +#ifndef ENTRY_S +#define ENTRY_S + +#include "encoding.h" +#include "bits.h" + +msg: + .string "enter trap_entry of entry_threadx!\n" + .section .text.entry + .align 2 + .global trap_entry + .extern _tx_thread_context_save + .extern _tx_thread_context_restore + +trap_entry: + + + + +#if defined(__riscv_float_abi_single) || defined(__riscv_float_abi_double) + addi sp, sp, -65*REGBYTES // Allocate space for all registers - with floating point enabled +#else + addi sp, sp, -32*REGBYTES // Allocate space for all registers - without floating point enabled +#endif + + STORE x1, 28*REGBYTES(sp) // Store RA, 28*REGBYTES(because call will override ra [ra is a calle register in riscv]) + +#la a0, msg # a0 = pointer to string +#jal ra, puts # call puts(msg) + + call _tx_thread_context_save + +# la a0, msg # a0 = pointer to string +# jal ra, puts # call puts(msg) + + csrr a0, mcause + csrr a1, mepc + mv a2, sp // which sp is needed? sp of interrupted context or the sp of _tx_thread_context_save??? + addi sp, sp, -8 + sd ra, 0(sp) + call handle_trap + ld ra, 0(sp) + addi sp, sp, 8 + call _tx_thread_context_restore + +//.weak handle_trap +//handle_trap: +//1: + // j 1b + +#endif