add entry_threadx.s
This commit is contained in:
@@ -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}")
|
||||
|
||||
53
test_fw/entry_threadx.S
Normal file
53
test_fw/entry_threadx.S
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user