Compare commits
14
Commits
bd5fbd22c2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07b2647267 | ||
|
|
ce002998c4 | ||
|
|
e40900bfc0 | ||
|
|
3e25331f43 | ||
|
|
2bd4a9d33f | ||
|
|
054251f810 | ||
|
|
f3dc14193c | ||
|
|
cf9ac8b56f | ||
|
|
0028d1d5cb | ||
|
|
de264a9185 | ||
|
|
fdb9ff7cfb | ||
|
|
608c4e0b0d | ||
|
|
d404e17e5a | ||
|
|
26fd407a1e |
No files matched your search
+4
-6
@@ -4,6 +4,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
|
|||||||
# we are building embedded, so no shared libs
|
# we are building embedded, so no shared libs
|
||||||
set(BUILD_SHARED_LIBS OFF)
|
set(BUILD_SHARED_LIBS OFF)
|
||||||
include(${CMAKE_TOOLCHAIN_FILE})
|
include(${CMAKE_TOOLCHAIN_FILE})
|
||||||
|
project(threadx_demo C CXX ASM)
|
||||||
###############################################################################
|
###############################################################################
|
||||||
add_subdirectory(port/moonlight)
|
add_subdirectory(port/moonlight)
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -17,9 +18,7 @@ target_link_libraries(c PUBLIC moonlight gcc)
|
|||||||
target_link_libraries(moonlight PRIVATE c)
|
target_link_libraries(moonlight PRIVATE c)
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Adds threadx
|
# Adds threadx
|
||||||
set(THREADX_CUSTOM_PORT ${CMAKE_CURRENT_LIST_DIR}/port/threadx)
|
add_subdirectory(port/threadx)
|
||||||
add_subdirectory(third-party/threadx)
|
|
||||||
target_link_libraries(threadx PUBLIC c moonlight)
|
|
||||||
#Adds threadx_smp
|
#Adds threadx_smp
|
||||||
add_subdirectory(port/threadx_smp)
|
add_subdirectory(port/threadx_smp)
|
||||||
target_link_libraries(threadx_smp PUBLIC c moonlight)
|
target_link_libraries(threadx_smp PUBLIC c moonlight)
|
||||||
@@ -41,7 +40,6 @@ endif()
|
|||||||
target_include_directories(netxduo PRIVATE ${CMAKE_CURRENT_LIST_DIR}/port/moonlight)
|
target_include_directories(netxduo PRIVATE ${CMAKE_CURRENT_LIST_DIR}/port/moonlight)
|
||||||
target_link_libraries(netxduo PUBLIC threadx c)
|
target_link_libraries(netxduo PUBLIC threadx c)
|
||||||
###############################################################################
|
###############################################################################
|
||||||
project(threadx_demo C CXX ASM)
|
|
||||||
set(TARGET_MEM "ram" CACHE STRING "memory map to use")
|
set(TARGET_MEM "ram" CACHE STRING "memory map to use")
|
||||||
option(NX_DEBUG "compile netxduo debug output in" OFF)
|
option(NX_DEBUG "compile netxduo debug output in" OFF)
|
||||||
option(NX_DEBUG_PACKET "compile netxduo debug output for ethernet packets in" OFF)
|
option(NX_DEBUG_PACKET "compile netxduo debug output for ethernet packets in" OFF)
|
||||||
@@ -88,6 +86,6 @@ function(setup_target TARGET)
|
|||||||
)
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
setup_target(thread_demo LIBRARIES threadx SOURCES src/thread_demo/main.c)
|
setup_target(thread_demo LIBRARIES moonlight_threadx SOURCES src/thread_demo/main.c)
|
||||||
setup_target(tcp_demo LIBRARIES netxduo threadx SOURCES src/tcp_demo/main.c)
|
setup_target(tcp_demo LIBRARIES netxduo moonlight_threadx SOURCES src/tcp_demo/main.c)
|
||||||
setup_target(smp_demo LIBRARIES threadx_smp SOURCES src/thread_demo/main.c)
|
setup_target(smp_demo LIBRARIES threadx_smp SOURCES src/thread_demo/main.c)
|
||||||
+1
-1
@@ -22,7 +22,7 @@
|
|||||||
"name": "Debug32",
|
"name": "Debug32",
|
||||||
"binaryDir": "${sourceDir}/build/${presetName}",
|
"binaryDir": "${sourceDir}/build/${presetName}",
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/rv32imac_gnu.cmake",
|
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/rv32gc_gnu.cmake",
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
"CMAKE_BUILD_TYPE": "Debug",
|
||||||
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
|
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+5
-4
@@ -6,6 +6,7 @@ def threadxTestSimulator = '/usr/local/bin/riscv-vp'
|
|||||||
def runOneRegression(String suite, String preset, String simulatorPath) {
|
def runOneRegression(String suite, String preset, String simulatorPath) {
|
||||||
def suiteDir = "test/${suite}"
|
def suiteDir = "test/${suite}"
|
||||||
def buildDir = "../../build/${preset}/test/${suite}"
|
def buildDir = "../../build/${preset}/test/${suite}"
|
||||||
|
def testSelection = preset.startsWith('Context') ? "--preset \"${preset}\"" : "--test-dir \"${buildDir}\""
|
||||||
|
|
||||||
stage("${suite}-${preset}") {
|
stage("${suite}-${preset}") {
|
||||||
dir(suiteDir) {
|
dir(suiteDir) {
|
||||||
@@ -16,10 +17,9 @@ def runOneRegression(String suite, String preset, String simulatorPath) {
|
|||||||
cmake --fresh --preset "${preset}" \\
|
cmake --fresh --preset "${preset}" \\
|
||||||
-DTHREADX_TEST_SIMULATOR="${simulatorPath}"
|
-DTHREADX_TEST_SIMULATOR="${simulatorPath}"
|
||||||
cmake --build --preset "${preset}" --parallel "\$(nproc)"
|
cmake --build --preset "${preset}" --parallel "\$(nproc)"
|
||||||
ctest \\
|
ctest ${testSelection} \\
|
||||||
--test-dir "${buildDir}" \\
|
|
||||||
--output-on-failure \\
|
--output-on-failure \\
|
||||||
--output-junit "${buildDir}/ctest-results.xml" \\
|
--output-junit "\$PWD/${buildDir}/ctest-results.xml" \\
|
||||||
--parallel "4"
|
--parallel "4"
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,8 @@ def runRegressionLane(String image, String simulatorPath, boolean allowFailure,
|
|||||||
def suiteName = suite
|
def suiteName = suite
|
||||||
def parallelTasks = [:]
|
def parallelTasks = [:]
|
||||||
|
|
||||||
for (String preset : presetNames) {
|
def suitePresets = suiteName == 'smp' ? presetNames + ['Context32', 'Context64'] : presetNames
|
||||||
|
for (String preset : suitePresets) {
|
||||||
def presetName = preset
|
def presetName = preset
|
||||||
def taskName = "${suiteName}-${presetName}"
|
def taskName = "${suiteName}-${presetName}"
|
||||||
parallelTasks[taskName] = {
|
parallelTasks[taskName] = {
|
||||||
|
|||||||
@@ -33,10 +33,23 @@ Examples:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
cmake -S test/threadx --preset Debug32 -DTHREADX_TEST_SIMULATOR=/opt/riscv-vp/bin/riscv-vp
|
cmake -S test/threadx --preset Debug32 -DTHREADX_TEST_SIMULATOR=/opt/riscv-vp/bin/riscv-vp
|
||||||
cmake --build --preset Debug32 --parallel
|
cmake --build build/Debug32/test/threadx/ --parallel
|
||||||
ctest --test-dir ../../build/Debug32/test/threadx --output-on-failure --parallel 4
|
ctest --test-dir build/Debug32/test/threadx --output-on-failure --parallel 4
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For SMP, use `test/smp` and the corresponding `build/Debug32/test/smp` directory
|
||||||
|
in the same commands. The regular SMP presets exercise integer builds.
|
||||||
|
|
||||||
|
Use `Context32` or `Context64` for a focused hard-float test on four-hart system.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd test/smp
|
||||||
|
cmake --preset Context64 -DTHREADX_TEST_SIMULATOR=/opt/riscv-vp/bin/riscv-vp
|
||||||
|
cmake --build --preset Context64 --parallel
|
||||||
|
ctest --preset Context64
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Demo Applications
|
## Demo Applications
|
||||||
|
|
||||||
The repository currently provides three demo applications:
|
The repository currently provides three demo applications:
|
||||||
|
|||||||
@@ -10,3 +10,12 @@ target_include_directories(${PROJECT_NAME}
|
|||||||
PUBLIC
|
PUBLIC
|
||||||
${CMAKE_CURRENT_LIST_DIR}/inc
|
${CMAKE_CURRENT_LIST_DIR}/inc
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# These upstream clients use strtoul() or abs() without including stdlib.h.
|
||||||
|
set_property(SOURCE
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/../../third-party/netxduo/addons/pop3/nxd_pop3_client.c
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/../../third-party/netxduo/addons/smtp/nxd_smtp_client.c
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/../../third-party/netxduo/addons/sntp/nxd_sntp_client.c
|
||||||
|
TARGET_DIRECTORY ${PROJECT_NAME}
|
||||||
|
APPEND PROPERTY COMPILE_OPTIONS -include stdlib.h
|
||||||
|
)
|
||||||
+37
-24
@@ -56,13 +56,41 @@
|
|||||||
|
|
||||||
#include "nx_user.h"
|
#include "nx_user.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* The upstream RAM driver relies on the port for debug stdio declarations. */
|
||||||
|
#if defined(NX_DEBUG) || defined(NX_DEBUG_PACKET)
|
||||||
|
#include <stdio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "tx_port.h"
|
#include "tx_port.h"
|
||||||
#if __riscv_xlen == 64
|
_Static_assert(sizeof(ULONG) == 4, "NetX Duo requires a 32-bit ULONG");
|
||||||
typedef unsigned int UINT32;
|
|
||||||
#else
|
#ifdef TX_TIMER_EXTENSION_PTR_DEFINED
|
||||||
typedef unsigned long UINT32;
|
/* ThreadX callbacks take a 32-bit argument on RV64. Keep the NetX context
|
||||||
|
pointers in the thread and timer control blocks. */
|
||||||
|
#define NX_THREAD_EXTENSION_PTR_SET(thread, context) \
|
||||||
|
{ (thread)->tx_thread_extension_ptr = (context); }
|
||||||
|
|
||||||
|
#define NX_THREAD_EXTENSION_PTR_GET(context, type, input) \
|
||||||
|
{ \
|
||||||
|
(void)(input); \
|
||||||
|
TX_THREAD *current_thread = tx_thread_identify(); \
|
||||||
|
while (current_thread->tx_thread_extension_ptr == TX_NULL) \
|
||||||
|
tx_thread_sleep(1); \
|
||||||
|
(context) = (type *)current_thread->tx_thread_extension_ptr; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define NX_TIMER_EXTENSION_PTR_SET(timer, context) \
|
||||||
|
{ (timer)->tx_timer_internal.tx_timer_internal_extension_ptr = (context); }
|
||||||
|
|
||||||
|
#define NX_TIMER_EXTENSION_PTR_GET(context, type, input) \
|
||||||
|
{ \
|
||||||
|
(void)(input); \
|
||||||
|
if (_tx_timer_expired_timer_ptr->tx_timer_internal_extension_ptr == TX_NULL) \
|
||||||
|
return; \
|
||||||
|
(context) = (type *)_tx_timer_expired_timer_ptr->tx_timer_internal_extension_ptr; \
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
_Static_assert(sizeof(UINT32) == 4, "UINT32 must be 4 bytes");
|
|
||||||
|
|
||||||
/* Default to little endian, since this is what most RISC-V targets are. */
|
/* Default to little endian, since this is what most RISC-V targets are. */
|
||||||
|
|
||||||
@@ -70,30 +98,15 @@ _Static_assert(sizeof(UINT32) == 4, "UINT32 must be 4 bytes");
|
|||||||
|
|
||||||
/* Define macros that swap the endian for little endian ports. */
|
/* Define macros that swap the endian for little endian ports. */
|
||||||
#ifdef NX_LITTLE_ENDIAN
|
#ifdef NX_LITTLE_ENDIAN
|
||||||
#define NX_CHANGE_UINT32_ENDIAN(arg) \
|
#define NX_CHANGE_ULONG_ENDIAN(arg) ((arg) = __builtin_bswap32((ULONG)(arg)))
|
||||||
{ \
|
|
||||||
UINT32 _i; \
|
|
||||||
UINT32 _tmp; \
|
|
||||||
_i = (UINT)arg; \
|
|
||||||
/* _i = A, B, C, D */ \
|
|
||||||
_tmp = _i ^ (((_i) >> 16) | (_i << 16)); \
|
|
||||||
/* _tmp = _i ^ (_i ROR 16) = A^C, B^D, C^A, D^B */ \
|
|
||||||
_tmp &= 0xff00ffff; \
|
|
||||||
/* _tmp = A^C, 0, C^A, D^B */ \
|
|
||||||
_i = ((_i) >> 8) | (_i << 24); \
|
|
||||||
/* _i = D, A, B, C */ \
|
|
||||||
_i = _i ^ ((_tmp) >> 8); \
|
|
||||||
/* _i = D, C, B, A */ \
|
|
||||||
arg = _i; \
|
|
||||||
}
|
|
||||||
#define NX_CHANGE_USHORT_ENDIAN(a) (a = (((a >> 8) | (a << 8)) & 0xFFFF))
|
#define NX_CHANGE_USHORT_ENDIAN(a) (a = (((a >> 8) | (a << 8)) & 0xFFFF))
|
||||||
|
|
||||||
#ifndef htonl
|
#ifndef htonl
|
||||||
#define htonl(val) NX_CHANGE_UINT32_ENDIAN(val)
|
#define htonl(val) NX_CHANGE_ULONG_ENDIAN(val)
|
||||||
#endif /* htonl */
|
#endif /* htonl */
|
||||||
|
|
||||||
#ifndef ntohl
|
#ifndef ntohl
|
||||||
#define ntohl(val) NX_CHANGE_UINT32_ENDIAN(val)
|
#define ntohl(val) NX_CHANGE_ULONG_ENDIAN(val)
|
||||||
#endif /* ntohl */
|
#endif /* ntohl */
|
||||||
|
|
||||||
#ifndef htons
|
#ifndef htons
|
||||||
@@ -106,7 +119,7 @@ _Static_assert(sizeof(UINT32) == 4, "UINT32 must be 4 bytes");
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define NX_CHANGE_UINT32_ENDIAN(a)
|
#define NX_CHANGE_ULONG_ENDIAN(a)
|
||||||
#define NX_CHANGE_USHORT_ENDIAN(a)
|
#define NX_CHANGE_USHORT_ENDIAN(a)
|
||||||
|
|
||||||
#ifndef htons
|
#ifndef htons
|
||||||
|
|||||||
@@ -761,21 +761,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C" {
|
||||||
{
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int rand(void);
|
int rand(void);
|
||||||
void srand(unsigned seed);
|
void srand(unsigned int seed);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NX_RAND rand
|
|
||||||
#define NX_SRAND srand
|
|
||||||
#endif
|
|
||||||
// hacky workaround for missing include in netxduo/common/src/nx_ram_network_driver.c
|
|
||||||
#ifdef NX_DEBUG
|
|
||||||
#include <stdio.h>
|
|
||||||
#endif
|
#endif
|
||||||
@@ -66,8 +66,8 @@ extern int register_irq_handler(unsigned irq_num, void (*handler)());
|
|||||||
/* For the ethernet driver, physical addresses are allocated starting
|
/* For the ethernet driver, physical addresses are allocated starting
|
||||||
at the preset value and then incremented before the next allocation. */
|
at the preset value and then incremented before the next allocation. */
|
||||||
// Locally Administered Addresses that can be assigned by network, range is 02-00-00 to 02-00-5E
|
// Locally Administered Addresses that can be assigned by network, range is 02-00-00 to 02-00-5E
|
||||||
const UINT32 mnrs_mac_address_msw = 0x0200;
|
const ULONG mnrs_mac_address_msw = 0x0200;
|
||||||
const UINT32 mnrs_mac_address_lsw = 0x00334450;
|
const ULONG mnrs_mac_address_lsw = 0x00334450;
|
||||||
|
|
||||||
/* Define driver prototypes. */
|
/* Define driver prototypes. */
|
||||||
VOID nx_mnrs_network_driver(NX_IP_DRIVER* driver_req_ptr);
|
VOID nx_mnrs_network_driver(NX_IP_DRIVER* driver_req_ptr);
|
||||||
@@ -81,8 +81,8 @@ static VOID _nx_mnrs_eth_recv_packet_eth1(VOID);
|
|||||||
#define NX_MNRS_DRIVER_MAX_MCAST_ADDRESSES 3
|
#define NX_MNRS_DRIVER_MAX_MCAST_ADDRESSES 3
|
||||||
typedef struct MAC_ADDRESS_STRUCT
|
typedef struct MAC_ADDRESS_STRUCT
|
||||||
{
|
{
|
||||||
UINT32 nx_mac_address_msw;
|
ULONG nx_mac_address_msw;
|
||||||
UINT32 nx_mac_address_lsw;
|
ULONG nx_mac_address_lsw;
|
||||||
} MAC_ADDRESS;
|
} MAC_ADDRESS;
|
||||||
|
|
||||||
/* Define an application-specific data structure that holds internal
|
/* Define an application-specific data structure that holds internal
|
||||||
@@ -173,7 +173,7 @@ VOID nx_mnrs_network_driver(NX_IP_DRIVER* driver_req_ptr)
|
|||||||
UINT interface_index;
|
UINT interface_index;
|
||||||
USHORT ether_type;
|
USHORT ether_type;
|
||||||
#ifndef NX_ENABLE_VLAN
|
#ifndef NX_ENABLE_VLAN
|
||||||
UINT32* ethernet_frame_ptr;
|
ULONG* ethernet_frame_ptr;
|
||||||
#endif /* NX_ENABLE_VLAN */
|
#endif /* NX_ENABLE_VLAN */
|
||||||
|
|
||||||
/* Setup the IP pointer from the driver request. */
|
/* Setup the IP pointer from the driver request. */
|
||||||
@@ -275,7 +275,7 @@ VOID nx_mnrs_network_driver(NX_IP_DRIVER* driver_req_ptr)
|
|||||||
/* Device driver shall initialize the Ethernet Controller here. */
|
/* Device driver shall initialize the Ethernet Controller here. */
|
||||||
#ifdef NX_DEBUG
|
#ifdef NX_DEBUG
|
||||||
printf("NetX MNRS ETH Driver Initialization - %s\n", ip_ptr->nx_ip_name);
|
printf("NetX MNRS ETH Driver Initialization - %s\n", ip_ptr->nx_ip_name);
|
||||||
printf(" IP Address =%08X\n", ip_ptr->nx_ip_address);
|
printf(" IP Address =%08lX\n", (unsigned long)ip_ptr->nx_ip_address);
|
||||||
#endif
|
#endif
|
||||||
// enable TX & RX path
|
// enable TX & RX path
|
||||||
set_ethmac_mac_ctrl(nx_mnrs_driver[i].ethmac,
|
set_ethmac_mac_ctrl(nx_mnrs_driver[i].ethmac,
|
||||||
@@ -408,7 +408,7 @@ VOID nx_mnrs_network_driver(NX_IP_DRIVER* driver_req_ptr)
|
|||||||
/* Setup the ethernet frame pointer to build the ethernet frame. Backup another 2
|
/* Setup the ethernet frame pointer to build the ethernet frame. Backup another 2
|
||||||
bytes to get 32-bit word alignment. */
|
bytes to get 32-bit word alignment. */
|
||||||
/*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */
|
/*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */
|
||||||
ethernet_frame_ptr = (UINT32*)(packet_ptr->nx_packet_prepend_ptr - 2);
|
ethernet_frame_ptr = (ULONG*)(packet_ptr->nx_packet_prepend_ptr - 2);
|
||||||
/* Build the ethernet frame. */
|
/* Build the ethernet frame. */
|
||||||
*ethernet_frame_ptr = driver_req_ptr->nx_ip_driver_physical_address_msw;
|
*ethernet_frame_ptr = driver_req_ptr->nx_ip_driver_physical_address_msw;
|
||||||
*(ethernet_frame_ptr + 1) = driver_req_ptr->nx_ip_driver_physical_address_lsw;
|
*(ethernet_frame_ptr + 1) = driver_req_ptr->nx_ip_driver_physical_address_lsw;
|
||||||
@@ -416,10 +416,10 @@ VOID nx_mnrs_network_driver(NX_IP_DRIVER* driver_req_ptr)
|
|||||||
(interface_ptr->nx_interface_physical_address_lsw >> 16);
|
(interface_ptr->nx_interface_physical_address_lsw >> 16);
|
||||||
*(ethernet_frame_ptr + 3) = (interface_ptr->nx_interface_physical_address_lsw << 16) | ether_type;
|
*(ethernet_frame_ptr + 3) = (interface_ptr->nx_interface_physical_address_lsw << 16) | ether_type;
|
||||||
/* Endian swapping if NX_LITTLE_ENDIAN is defined. */
|
/* Endian swapping if NX_LITTLE_ENDIAN is defined. */
|
||||||
NX_CHANGE_UINT32_ENDIAN(*(ethernet_frame_ptr));
|
NX_CHANGE_ULONG_ENDIAN(*(ethernet_frame_ptr));
|
||||||
NX_CHANGE_UINT32_ENDIAN(*(ethernet_frame_ptr + 1));
|
NX_CHANGE_ULONG_ENDIAN(*(ethernet_frame_ptr + 1));
|
||||||
NX_CHANGE_UINT32_ENDIAN(*(ethernet_frame_ptr + 2));
|
NX_CHANGE_ULONG_ENDIAN(*(ethernet_frame_ptr + 2));
|
||||||
NX_CHANGE_UINT32_ENDIAN(*(ethernet_frame_ptr + 3));
|
NX_CHANGE_ULONG_ENDIAN(*(ethernet_frame_ptr + 3));
|
||||||
#endif /* NX_ENABLE_VLAN */
|
#endif /* NX_ENABLE_VLAN */
|
||||||
#ifdef NX_DEBUG_PACKET
|
#ifdef NX_DEBUG_PACKET
|
||||||
printf("NetX MNRS ETH Driver Packet Send - %s\n", ip_ptr->nx_ip_name);
|
printf("NetX MNRS ETH Driver Packet Send - %s\n", ip_ptr->nx_ip_name);
|
||||||
@@ -840,11 +840,10 @@ void _nx_mnrs_network_driver_receive(NX_IP* ip_ptr, NX_PACKET* packet_ptr, UINT
|
|||||||
|
|
||||||
UINT _nx_mnrs_eth_send_packet(NX_PACKET* packet_ptr, volatile ethmac_t* ethmac)
|
UINT _nx_mnrs_eth_send_packet(NX_PACKET* packet_ptr, volatile ethmac_t* ethmac)
|
||||||
{
|
{
|
||||||
UINT32 size = 0;
|
ULONG size = 0;
|
||||||
UCHAR* data;
|
UCHAR* data;
|
||||||
UINT i;
|
UINT i;
|
||||||
UINT32 buffer;
|
ULONG buffer;
|
||||||
UINT32 words;
|
|
||||||
|
|
||||||
/* Make sure the data length is less than MTU. */
|
/* Make sure the data length is less than MTU. */
|
||||||
if (packet_ptr->nx_packet_length > NX_MAX_PACKET_SIZE)
|
if (packet_ptr->nx_packet_length > NX_MAX_PACKET_SIZE)
|
||||||
@@ -854,7 +853,6 @@ UINT _nx_mnrs_eth_send_packet(NX_PACKET* packet_ptr, volatile ethmac_t* ethmac)
|
|||||||
/* get data pointer to be transmitted. */
|
/* get data pointer to be transmitted. */
|
||||||
data = packet_ptr->nx_packet_prepend_ptr;
|
data = packet_ptr->nx_packet_prepend_ptr;
|
||||||
size = packet_ptr->nx_packet_length;
|
size = packet_ptr->nx_packet_length;
|
||||||
words = (size + 3) / 4;
|
|
||||||
/* wait until ethmac is ready to receive packets */
|
/* wait until ethmac is ready to receive packets */
|
||||||
while (get_ethmac_mac_ctrl_tx_ready(ethmac) == 0)
|
while (get_ethmac_mac_ctrl_tx_ready(ethmac) == 0)
|
||||||
;
|
;
|
||||||
@@ -967,7 +965,7 @@ VOID _nx_mnrs_eth_recv_packet(UINT i)
|
|||||||
|
|
||||||
VOID _nx_mnrs_eth_recv_packet_eth0(VOID)
|
VOID _nx_mnrs_eth_recv_packet_eth0(VOID)
|
||||||
{
|
{
|
||||||
UINT32 old_threshold;
|
UINT old_threshold;
|
||||||
|
|
||||||
if (get_ethmac_mac_ctrl_rx_pending(ethmac0))
|
if (get_ethmac_mac_ctrl_rx_pending(ethmac0))
|
||||||
{
|
{
|
||||||
@@ -986,7 +984,7 @@ VOID _nx_mnrs_eth_recv_packet_eth0(VOID)
|
|||||||
|
|
||||||
VOID _nx_mnrs_eth_recv_packet_eth1(VOID)
|
VOID _nx_mnrs_eth_recv_packet_eth1(VOID)
|
||||||
{
|
{
|
||||||
UINT32 old_threshold;
|
UINT old_threshold;
|
||||||
|
|
||||||
if (get_ethmac_mac_ctrl_rx_pending(ethmac1))
|
if (get_ethmac_mac_ctrl_rx_pending(ethmac1))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,25 +1,11 @@
|
|||||||
#required for tests to hook into the ISR path
|
set(TX_USER_FILE ${CMAKE_CURRENT_LIST_DIR}/inc/tx_user.h)
|
||||||
if(NOT DEFINED THREADX_LOW_LEVEL_INIT_SOURCE)
|
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../third-party/threadx upstream)
|
||||||
set(THREADX_LOW_LEVEL_INIT_SOURCE
|
target_link_libraries(threadx PUBLIC c moonlight)
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/tx_initialize_low_level.c)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
target_sources(${PROJECT_NAME}
|
# Link these objects directly into each executable so the board initialization
|
||||||
PRIVATE
|
# takes precedence over the upstream weak default.
|
||||||
# {{BEGIN_TARGET_SOURCES}}
|
add_library(moonlight_threadx OBJECT
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/trap_entry.S
|
src/trap_entry.S
|
||||||
${THREADX_LOW_LEVEL_INIT_SOURCE}
|
src/tx_initialize_low_level.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_context_restore.S
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_context_save.S
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_interrupt_control.S
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_schedule.S
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_stack_build.S
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_system_return.S
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/tx_timer_interrupt.c
|
|
||||||
# {{END_TARGET_SOURCES}}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME}
|
|
||||||
PUBLIC
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/inc
|
|
||||||
)
|
)
|
||||||
|
target_link_libraries(moonlight_threadx PUBLIC threadx)
|
||||||
@@ -1,371 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
#ifndef CSR_H
|
|
||||||
#define CSR_H
|
|
||||||
|
|
||||||
// Machine Status Register, mstatus
|
|
||||||
#define MSTATUS_MPP_MASK (3L << 11) // previous mode.
|
|
||||||
#define MSTATUS_MPP_M (3L << 11)
|
|
||||||
#define MSTATUS_MPP_S (1L << 11)
|
|
||||||
#define MSTATUS_MPP_U (0L << 11)
|
|
||||||
#define MSTATUS_MIE (1L << 3) // machine-mode interrupt enable.
|
|
||||||
#define MSTATUS_MPIE (1L << 7)
|
|
||||||
#define MSTATUS_FS (1L << 13)
|
|
||||||
|
|
||||||
// Machine-mode Interrupt Enable
|
|
||||||
#define MIE_MTIE (1L << 7)
|
|
||||||
#define MIE_MSIE (1L << 3)
|
|
||||||
#define MIE_MEIE (1L << 11)
|
|
||||||
#define MIE_STIE (1L << 5) // supervisor timer
|
|
||||||
#define MIE_SSIE (1L << 1)
|
|
||||||
#define MIE_SEIE (1L << 9)
|
|
||||||
|
|
||||||
// Supervisor Status Register, sstatus
|
|
||||||
#define SSTATUS_SPP (1L << 8) // Previous mode, 1=Supervisor, 0=User
|
|
||||||
#define SSTATUS_SPIE (1L << 5) // Supervisor Previous Interrupt Enable
|
|
||||||
#define SSTATUS_UPIE (1L << 4) // User Previous Interrupt Enable
|
|
||||||
#define SSTATUS_SIE (1L << 1) // Supervisor Interrupt Enable
|
|
||||||
#define SSTATUS_UIE (1L << 0) // User Interrupt Enable
|
|
||||||
#define SSTATUS_SPIE (1L << 5)
|
|
||||||
#define SSTATUS_UPIE (1L << 4)
|
|
||||||
|
|
||||||
// Supervisor Interrupt Enable
|
|
||||||
#define SIE_SEIE (1L << 9) // external
|
|
||||||
#define SIE_STIE (1L << 5) // timer
|
|
||||||
#define SIE_SSIE (1L << 1) // software
|
|
||||||
|
|
||||||
#ifndef __ASSEMBLER__
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_core()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, mhartid" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_mstatus()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, mstatus" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_mstatus(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw mstatus, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// machine exception program counter, holds the
|
|
||||||
// instruction address to which a return from
|
|
||||||
// exception will go.
|
|
||||||
static inline void riscv_writ_mepc(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw mepc, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_sstatus()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, sstatus" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_sstatus(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw sstatus, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supervisor Interrupt Pending
|
|
||||||
static inline uint64_t riscv_get_sip()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, sip" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_sip(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw sip, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_sie()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, sie" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_sie(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw sie, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_mie()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, mie" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_mie(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw mie, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// supervisor exception program counter, holds the
|
|
||||||
// instruction address to which a return from
|
|
||||||
// exception will go.
|
|
||||||
static inline void riscv_writ_sepc(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw sepc, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_sepc()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, sepc" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Machine Exception Delegation
|
|
||||||
static inline uint64_t riscv_get_medeleg()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, medeleg" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_medeleg(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw medeleg, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Machine Interrupt Delegation
|
|
||||||
static inline uint64_t riscv_get_mideleg()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, mideleg" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_mideleg(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw mideleg, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supervisor Trap-Vector Base Address
|
|
||||||
// low two bits are mode.
|
|
||||||
static inline void riscv_writ_stvec(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw stvec, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_stvec()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, stvec" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supervisor Timer Comparison Register
|
|
||||||
static inline uint64_t riscv_get_stimecmp()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
// asm volatile("csrr %0, stimecmp" : "=r" (x) );
|
|
||||||
asm volatile("csrr %0, 0x14d" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_stimecmp(uint64_t x)
|
|
||||||
{
|
|
||||||
// asm volatile("csrw stimecmp, %0" : : "r" (x));
|
|
||||||
asm volatile("csrw 0x14d, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Machine Environment Configuration Register
|
|
||||||
static inline uint64_t riscv_get_menvcfg()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
// asm volatile("csrr %0, menvcfg" : "=r" (x) );
|
|
||||||
asm volatile("csrr %0, 0x30a" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_menvcfg(uint64_t x)
|
|
||||||
{
|
|
||||||
// asm volatile("csrw menvcfg, %0" : : "r" (x));
|
|
||||||
asm volatile("csrw 0x30a, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Physical Memory Protection
|
|
||||||
static inline void riscv_writ_pmpcfg0(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw pmpcfg0, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_pmpaddr0(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw pmpaddr0, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// supervisor address translation and protection;
|
|
||||||
// holds the address of the page table.
|
|
||||||
static inline void riscv_writ_satp(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw satp, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_satp()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, satp" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supervisor Trap Cause
|
|
||||||
static inline uint64_t riscv_get_scause()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, scause" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supervisor Trap Value
|
|
||||||
static inline uint64_t riscv_get_stval()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, stval" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Machine-mode Counter-Enable
|
|
||||||
static inline void riscv_writ_mcounteren(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw mcounteren, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_mcounteren()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, mcounteren" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// machine-mode cycle counter
|
|
||||||
static inline uint64_t riscv_get_time()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, time" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable device interrupts
|
|
||||||
static inline void riscv_sintr_on()
|
|
||||||
{
|
|
||||||
uint64_t sstatus = riscv_get_sstatus();
|
|
||||||
sstatus |= SSTATUS_SIE;
|
|
||||||
riscv_writ_sstatus(sstatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
// disable device interrupts
|
|
||||||
static inline void riscv_sintr_off()
|
|
||||||
{
|
|
||||||
uint64_t sstatus = riscv_get_sstatus();
|
|
||||||
sstatus &= (~SSTATUS_SIE);
|
|
||||||
riscv_writ_sstatus(sstatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
// are device interrupts enabled?
|
|
||||||
static inline int riscv_sintr_get()
|
|
||||||
{
|
|
||||||
uint64_t x = riscv_get_sstatus();
|
|
||||||
return (x & SSTATUS_SIE) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_sintr_restore(int x)
|
|
||||||
{
|
|
||||||
if (x)
|
|
||||||
riscv_sintr_on();
|
|
||||||
else
|
|
||||||
riscv_sintr_off();
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable device interrupts
|
|
||||||
static inline void riscv_mintr_on()
|
|
||||||
{
|
|
||||||
uint64_t mstatus = riscv_get_mstatus();
|
|
||||||
mstatus |= MSTATUS_MIE;
|
|
||||||
riscv_writ_mstatus(mstatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
// disable device interrupts
|
|
||||||
static inline void riscv_mintr_off()
|
|
||||||
{
|
|
||||||
uint64_t mstatus = riscv_get_mstatus();
|
|
||||||
mstatus &= (~MSTATUS_MIE);
|
|
||||||
riscv_writ_mstatus(mstatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
// are device interrupts enabled?
|
|
||||||
static inline int riscv_mintr_get()
|
|
||||||
{
|
|
||||||
uint64_t x = riscv_get_mstatus();
|
|
||||||
return (x & MSTATUS_MIE) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_mintr_restore(int x)
|
|
||||||
{
|
|
||||||
if (x)
|
|
||||||
riscv_mintr_on();
|
|
||||||
else
|
|
||||||
riscv_mintr_off();
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_sp()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("mv %0, sp" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// read and write tp, the thread pointer, which xv6 uses to hold
|
|
||||||
// this core's hartid (core number), the index into cpus[].
|
|
||||||
static inline uint64_t riscv_get_tp()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("mv %0, tp" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_tp(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("mv tp, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_ra()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("mv %0, ra" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// flush the TLB.
|
|
||||||
static inline void sfence_vma()
|
|
||||||
{
|
|
||||||
// the zero, zero means flush all TLB entries.
|
|
||||||
asm volatile("sfence.vma zero, zero");
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // __ASSEMBLER__
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,425 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Port Specific */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* PORT SPECIFIC C INFORMATION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* tx_port.h RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Scott Larson, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This file contains data type definitions that make the ThreadX */
|
|
||||||
/* real-time kernel function identically on a variety of different */
|
|
||||||
/* processor architectures. For example, the size or number of bits */
|
|
||||||
/* in an "int" data type vary between microprocessor architectures and */
|
|
||||||
/* even C compilers for the same microprocessor. ThreadX does not */
|
|
||||||
/* directly use native C data types. Instead, ThreadX creates its */
|
|
||||||
/* own special types that can be mapped to actual data types by this */
|
|
||||||
/* file to guarantee consistency in the interface and functionality. */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
#ifndef TX_PORT_H
|
|
||||||
#define TX_PORT_H
|
|
||||||
|
|
||||||
#ifdef __ASSEMBLER__
|
|
||||||
|
|
||||||
#if __riscv_xlen == 64
|
|
||||||
#define SLL32 sllw
|
|
||||||
#define STORE sd
|
|
||||||
#define LOAD ld
|
|
||||||
#define LWU lwu
|
|
||||||
#define LOG_REGBYTES 3
|
|
||||||
#else
|
|
||||||
#define SLL32 sll
|
|
||||||
#define STORE sw
|
|
||||||
#define LOAD lw
|
|
||||||
#define LWU lw
|
|
||||||
#define LOG_REGBYTES 2
|
|
||||||
#endif
|
|
||||||
#define REGBYTES (1 << LOG_REGBYTES)
|
|
||||||
|
|
||||||
#define TX_CONTEXT_ALIGN(size) (((size) + 15) & -16)
|
|
||||||
|
|
||||||
/* Keep the existing hard-float enable policy. Save the full hardware register
|
|
||||||
* width, even when the calling convention uses narrower floating-point values.
|
|
||||||
*/
|
|
||||||
#if defined(__riscv_float_abi_single) || defined(__riscv_float_abi_double)
|
|
||||||
#define TX_CONTEXT_FP_ENABLED 1
|
|
||||||
#if __riscv_flen == 64
|
|
||||||
#define TX_FP_BYTES 8
|
|
||||||
#define TX_FP_LOAD fld
|
|
||||||
#define TX_FP_STORE fsd
|
|
||||||
#elif __riscv_flen == 32
|
|
||||||
#define TX_FP_BYTES 4
|
|
||||||
#define TX_FP_LOAD flw
|
|
||||||
#define TX_FP_STORE fsw
|
|
||||||
#else
|
|
||||||
#error "Unsupported RISC-V floating-point register width"
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define TX_CONTEXT_FP_ENABLED 0
|
|
||||||
#define TX_FP_BYTES 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Integer slots 0..30 contain the interrupt context; slot 31 is padding.
|
|
||||||
* Voluntary switches use slots 0..14; slot 15 is padding. Starting the FP
|
|
||||||
* areas at these boundaries aligns double registers on RV32 as well as RV64.
|
|
||||||
*/
|
|
||||||
#define TX_INTERRUPT_FP_BASE (32 * REGBYTES)
|
|
||||||
#define TX_SOLICITED_FP_BASE (16 * REGBYTES)
|
|
||||||
#define TX_INTERRUPT_FP_OFFSET(n) (TX_INTERRUPT_FP_BASE + (n) * TX_FP_BYTES)
|
|
||||||
/* Solicited FP indices: fs0, fs1, fs2, ... fs11 (not architectural numbers). */
|
|
||||||
#define TX_SOLICITED_FP_OFFSET(n) (TX_SOLICITED_FP_BASE + (n) * TX_FP_BYTES)
|
|
||||||
#define TX_INTERRUPT_FCSR_OFFSET TX_INTERRUPT_FP_OFFSET(32)
|
|
||||||
#define TX_SOLICITED_FCSR_OFFSET TX_SOLICITED_FP_OFFSET(12)
|
|
||||||
|
|
||||||
/* fcsr follows the FP registers and occupies one REGBYTES slot because
|
|
||||||
* it is accessed with integer LOAD/STORE. Round the complete frame up to
|
|
||||||
* 16 bytes so allocating or releasing it preserves stack alignment. Without
|
|
||||||
* FP support, the frame contains only the integer slots and their padding.
|
|
||||||
*/
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
#define TX_INTERRUPT_FRAME_SIZE TX_CONTEXT_ALIGN(TX_INTERRUPT_FCSR_OFFSET + REGBYTES)
|
|
||||||
#define TX_SOLICITED_FRAME_SIZE TX_CONTEXT_ALIGN(TX_SOLICITED_FCSR_OFFSET + REGBYTES)
|
|
||||||
#else
|
|
||||||
#define TX_INTERRUPT_FRAME_SIZE TX_INTERRUPT_FP_BASE
|
|
||||||
#define TX_SOLICITED_FRAME_SIZE TX_SOLICITED_FP_BASE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#else /*not __ASSEMBLER__ */
|
|
||||||
|
|
||||||
/* Determine if the optional ThreadX user define file should be used. */
|
|
||||||
|
|
||||||
#ifdef TX_INCLUDE_USER_DEFINE_FILE
|
|
||||||
|
|
||||||
/* Yes, include the user defines in tx_user.h. The defines in this file may
|
|
||||||
alternately be defined on the command line. */
|
|
||||||
|
|
||||||
#include "tx_user.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define compiler library include files. */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
/* Define ThreadX basic types for this port. */
|
|
||||||
|
|
||||||
#define VOID void
|
|
||||||
typedef char CHAR;
|
|
||||||
typedef unsigned char UCHAR;
|
|
||||||
typedef int INT;
|
|
||||||
typedef unsigned int UINT;
|
|
||||||
typedef long LONG;
|
|
||||||
typedef unsigned long ULONG;
|
|
||||||
typedef unsigned long long ULONG64;
|
|
||||||
typedef short SHORT;
|
|
||||||
typedef unsigned short USHORT;
|
|
||||||
#define ULONG64_DEFINED
|
|
||||||
|
|
||||||
/* Define the priority levels for ThreadX. Legal values range
|
|
||||||
from 32 to 1024 and MUST be evenly divisible by 32. */
|
|
||||||
|
|
||||||
#ifndef TX_MAX_PRIORITIES
|
|
||||||
#define TX_MAX_PRIORITIES 32
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define the minimum stack for a ThreadX thread on this processor. If the size supplied during
|
|
||||||
thread creation is less than this value, the thread create call will return an error. */
|
|
||||||
|
|
||||||
#ifndef TX_MINIMUM_STACK
|
|
||||||
#define TX_MINIMUM_STACK 1024 /* Minimum stack size for this port */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define the system timer thread's default stack size and priority. These are only applicable
|
|
||||||
if TX_TIMER_PROCESS_IN_ISR is not defined. */
|
|
||||||
|
|
||||||
#ifndef TX_TIMER_THREAD_STACK_SIZE
|
|
||||||
#define TX_TIMER_THREAD_STACK_SIZE 1024 /* Default timer thread stack size */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef TX_TIMER_THREAD_PRIORITY
|
|
||||||
#define TX_TIMER_THREAD_PRIORITY 0 /* Default timer thread priority */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define various constants for the ThreadX RISC-V port. */
|
|
||||||
|
|
||||||
#define TX_INT_DISABLE 0x00000000 /* Disable interrupts value */
|
|
||||||
#define TX_INT_ENABLE 0x00000008 /* Enable interrupt value */
|
|
||||||
|
|
||||||
/* Define the clock source for trace event entry time stamp. The following two item are port specific.
|
|
||||||
For example, if the time source is at the address 0x0a800024 and is 16-bits in size, the clock
|
|
||||||
source constants would be:
|
|
||||||
|
|
||||||
#define TX_TRACE_TIME_SOURCE *((ULONG *) 0x0a800024)
|
|
||||||
#define TX_TRACE_TIME_MASK 0x0000FFFFUL
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TX_TRACE_TIME_SOURCE
|
|
||||||
#define TX_TRACE_TIME_SOURCE ++_tx_trace_simulated_time
|
|
||||||
#endif
|
|
||||||
#ifndef TX_TRACE_TIME_MASK
|
|
||||||
#define TX_TRACE_TIME_MASK 0xFFFFFFFFUL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define the port specific options for the _tx_build_options variable. This variable indicates
|
|
||||||
how the ThreadX library was built. */
|
|
||||||
|
|
||||||
#define TX_PORT_SPECIFIC_BUILD_OPTIONS 0
|
|
||||||
|
|
||||||
/* Define the in-line initialization constant so that modules with in-line
|
|
||||||
initialization capabilities can prevent their initialization from being
|
|
||||||
a function call. */
|
|
||||||
|
|
||||||
#define TX_INLINE_INITIALIZATION
|
|
||||||
|
|
||||||
/* Determine whether or not stack checking is enabled. By default, ThreadX stack checking is
|
|
||||||
disabled. When the following is defined, ThreadX thread stack checking is enabled. If stack
|
|
||||||
checking is enabled (TX_ENABLE_STACK_CHECKING is defined), the TX_DISABLE_STACK_FILLING
|
|
||||||
define is negated, thereby forcing the stack fill which is necessary for the stack checking
|
|
||||||
logic. */
|
|
||||||
|
|
||||||
#ifdef TX_ENABLE_STACK_CHECKING
|
|
||||||
#undef TX_DISABLE_STACK_FILLING
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define the TX_THREAD control block extensions for this port. The main reason
|
|
||||||
for the multiple macros is so that backward compatibility can be maintained with
|
|
||||||
existing ThreadX kernel awareness modules. */
|
|
||||||
|
|
||||||
#define TX_THREAD_EXTENSION_0
|
|
||||||
#define TX_THREAD_EXTENSION_1
|
|
||||||
#define TX_THREAD_EXTENSION_2
|
|
||||||
#define TX_THREAD_EXTENSION_3
|
|
||||||
|
|
||||||
/* Define the port extensions of the remaining ThreadX objects. */
|
|
||||||
|
|
||||||
#define TX_BLOCK_POOL_EXTENSION
|
|
||||||
#define TX_BYTE_POOL_EXTENSION
|
|
||||||
#define TX_EVENT_FLAGS_GROUP_EXTENSION
|
|
||||||
#define TX_MUTEX_EXTENSION
|
|
||||||
#define TX_QUEUE_EXTENSION
|
|
||||||
#define TX_SEMAPHORE_EXTENSION
|
|
||||||
#define TX_TIMER_EXTENSION
|
|
||||||
|
|
||||||
/* Define the user extension field of the thread control block. Nothing
|
|
||||||
additional is needed for this port so it is defined as white space. */
|
|
||||||
|
|
||||||
#ifndef TX_THREAD_USER_EXTENSION
|
|
||||||
#define TX_THREAD_USER_EXTENSION
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define the macros for processing extensions in tx_thread_create, tx_thread_delete,
|
|
||||||
tx_thread_shell_entry, and tx_thread_terminate. */
|
|
||||||
|
|
||||||
#define TX_THREAD_CREATE_EXTENSION(thread_ptr)
|
|
||||||
#define TX_THREAD_DELETE_EXTENSION(thread_ptr)
|
|
||||||
#define TX_THREAD_COMPLETED_EXTENSION(thread_ptr)
|
|
||||||
#define TX_THREAD_TERMINATED_EXTENSION(thread_ptr)
|
|
||||||
|
|
||||||
/* Define automated regression test extensions. These are required for the
|
|
||||||
ThreadX regression tests. */
|
|
||||||
|
|
||||||
typedef unsigned int TEST_FLAG;
|
|
||||||
extern TEST_FLAG threadx_byte_allocate_loop_test;
|
|
||||||
extern TEST_FLAG threadx_byte_release_loop_test;
|
|
||||||
extern TEST_FLAG threadx_mutex_suspension_put_test;
|
|
||||||
extern TEST_FLAG threadx_mutex_suspension_priority_test;
|
|
||||||
#ifndef TX_TIMER_PROCESS_IN_ISR
|
|
||||||
extern TEST_FLAG threadx_delete_timer_thread;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern void abort_and_resume_byte_allocating_thread(void);
|
|
||||||
extern void abort_all_threads_suspended_on_mutex(void);
|
|
||||||
extern void suspend_lowest_priority(void);
|
|
||||||
#ifndef TX_TIMER_PROCESS_IN_ISR
|
|
||||||
extern void delete_timer_thread(void);
|
|
||||||
#endif
|
|
||||||
extern TEST_FLAG test_stack_analyze_flag;
|
|
||||||
extern TEST_FLAG test_initialize_flag;
|
|
||||||
extern TEST_FLAG test_forced_mutex_timeout;
|
|
||||||
|
|
||||||
#ifdef TX_REGRESSION_TEST
|
|
||||||
|
|
||||||
/* Define extension macros for automated coverage tests. */
|
|
||||||
|
|
||||||
#define TX_BYTE_ALLOCATE_EXTENSION \
|
|
||||||
if (threadx_byte_allocate_loop_test == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
pool_ptr->tx_byte_pool_owner = TX_NULL; \
|
|
||||||
threadx_byte_allocate_loop_test = ((TEST_FLAG)0); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TX_BYTE_RELEASE_EXTENSION \
|
|
||||||
if (threadx_byte_release_loop_test == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
threadx_byte_release_loop_test = ((TEST_FLAG)0); \
|
|
||||||
abort_and_resume_byte_allocating_thread(); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TX_MUTEX_PUT_EXTENSION_1 \
|
|
||||||
if (threadx_mutex_suspension_put_test == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
threadx_mutex_suspension_put_test = ((TEST_FLAG)0); \
|
|
||||||
abort_all_threads_suspended_on_mutex(); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TX_MUTEX_PUT_EXTENSION_2 \
|
|
||||||
if (test_forced_mutex_timeout == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
test_forced_mutex_timeout = ((TEST_FLAG)0); \
|
|
||||||
_tx_thread_wait_abort(mutex_ptr->tx_mutex_suspension_list); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TX_MUTEX_PRIORITY_CHANGE_EXTENSION \
|
|
||||||
if (threadx_mutex_suspension_priority_test == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
threadx_mutex_suspension_priority_test = ((TEST_FLAG)0); \
|
|
||||||
suspend_lowest_priority(); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef TX_TIMER_PROCESS_IN_ISR
|
|
||||||
|
|
||||||
#define TX_TIMER_INITIALIZE_EXTENSION(a) \
|
|
||||||
if (threadx_delete_timer_thread == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
threadx_delete_timer_thread = ((TEST_FLAG)0); \
|
|
||||||
delete_timer_thread(); \
|
|
||||||
(a) = ((UINT)1); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define TX_THREAD_STACK_ANALYZE_EXTENSION \
|
|
||||||
if (test_stack_analyze_flag == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
thread_ptr->tx_thread_id = ((TEST_FLAG)0); \
|
|
||||||
test_stack_analyze_flag = ((TEST_FLAG)0); \
|
|
||||||
} \
|
|
||||||
else if (test_stack_analyze_flag == ((TEST_FLAG)2)) \
|
|
||||||
{ \
|
|
||||||
stack_ptr = thread_ptr->tx_thread_stack_start; \
|
|
||||||
test_stack_analyze_flag = ((TEST_FLAG)0); \
|
|
||||||
} \
|
|
||||||
else if (test_stack_analyze_flag == ((TEST_FLAG)3)) \
|
|
||||||
{ \
|
|
||||||
*stack_ptr = TX_STACK_FILL; \
|
|
||||||
test_stack_analyze_flag = ((TEST_FLAG)0); \
|
|
||||||
} \
|
|
||||||
else \
|
|
||||||
{ \
|
|
||||||
test_stack_analyze_flag = ((TEST_FLAG)0); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TX_INITIALIZE_KERNEL_ENTER_EXTENSION \
|
|
||||||
if (test_initialize_flag == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
test_initialize_flag = ((TEST_FLAG)0); \
|
|
||||||
return; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define the ThreadX object creation extensions for the remaining objects. */
|
|
||||||
|
|
||||||
#define TX_BLOCK_POOL_CREATE_EXTENSION(pool_ptr)
|
|
||||||
#define TX_BYTE_POOL_CREATE_EXTENSION(pool_ptr)
|
|
||||||
#define TX_EVENT_FLAGS_GROUP_CREATE_EXTENSION(group_ptr)
|
|
||||||
#define TX_MUTEX_CREATE_EXTENSION(mutex_ptr)
|
|
||||||
#define TX_QUEUE_CREATE_EXTENSION(queue_ptr)
|
|
||||||
#define TX_SEMAPHORE_CREATE_EXTENSION(semaphore_ptr)
|
|
||||||
#define TX_TIMER_CREATE_EXTENSION(timer_ptr)
|
|
||||||
|
|
||||||
/* Define the ThreadX object deletion extensions for the remaining objects. */
|
|
||||||
|
|
||||||
#define TX_BLOCK_POOL_DELETE_EXTENSION(pool_ptr)
|
|
||||||
#define TX_BYTE_POOL_DELETE_EXTENSION(pool_ptr)
|
|
||||||
#define TX_EVENT_FLAGS_GROUP_DELETE_EXTENSION(group_ptr)
|
|
||||||
#define TX_MUTEX_DELETE_EXTENSION(mutex_ptr)
|
|
||||||
#define TX_QUEUE_DELETE_EXTENSION(queue_ptr)
|
|
||||||
#define TX_SEMAPHORE_DELETE_EXTENSION(semaphore_ptr)
|
|
||||||
#define TX_TIMER_DELETE_EXTENSION(timer_ptr)
|
|
||||||
|
|
||||||
/* Define ThreadX interrupt lockout and restore macros for protection on
|
|
||||||
access of critical kernel information. The restore interrupt macro must
|
|
||||||
restore the interrupt posture of the running thread prior to the value
|
|
||||||
present prior to the disable macro. In most cases, the save area macro
|
|
||||||
is used to define a local function save area for the disable and restore
|
|
||||||
macros. */
|
|
||||||
|
|
||||||
#ifdef TX_DISABLE_INLINE
|
|
||||||
|
|
||||||
ULONG _tx_thread_interrupt_control(unsigned int new_posture);
|
|
||||||
|
|
||||||
#define TX_INTERRUPT_SAVE_AREA register ULONG tx_saved_posture;
|
|
||||||
|
|
||||||
#define TX_DISABLE tx_saved_posture = _tx_thread_interrupt_control(TX_INT_DISABLE);
|
|
||||||
#define TX_RESTORE _tx_thread_interrupt_control(tx_saved_posture);
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define TX_INTERRUPT_SAVE_AREA ULONG tx_saved_posture;
|
|
||||||
/* Atomically read mstatus into tx_saved_posture and clear bit 3 of mstatus. */
|
|
||||||
#define TX_DISABLE \
|
|
||||||
{ \
|
|
||||||
__asm__ volatile("csrrci %0, mstatus, 0x08" : "=r"(tx_saved_posture) : : "memory"); \
|
|
||||||
};
|
|
||||||
/* We only care about mstatus.mie (bit 3), so mask tx_saved_posture and write to mstatus. */
|
|
||||||
#define TX_RESTORE \
|
|
||||||
{ \
|
|
||||||
register ULONG __tempmask = tx_saved_posture & 0x08; \
|
|
||||||
__asm__ volatile("csrrs x0, mstatus, %0" : : "r"(__tempmask) : "memory"); \
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define the interrupt lockout macros for each ThreadX object. */
|
|
||||||
|
|
||||||
#define TX_BLOCK_POOL_DISABLE TX_DISABLE
|
|
||||||
#define TX_BYTE_POOL_DISABLE TX_DISABLE
|
|
||||||
#define TX_EVENT_FLAGS_GROUP_DISABLE TX_DISABLE
|
|
||||||
#define TX_MUTEX_DISABLE TX_DISABLE
|
|
||||||
#define TX_QUEUE_DISABLE TX_DISABLE
|
|
||||||
#define TX_SEMAPHORE_DISABLE TX_DISABLE
|
|
||||||
|
|
||||||
/* Define the version ID of ThreadX. This may be utilized by the application. */
|
|
||||||
|
|
||||||
#ifdef TX_THREAD_INIT
|
|
||||||
CHAR _tx_version_id[] = "Copyright (c) 2024 Microsoft Corporation. * ThreadX RISC-V64/GNU Version 6.4.2 *";
|
|
||||||
#else
|
|
||||||
extern CHAR _tx_version_id[];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*not __ASSEMBLER__ */
|
|
||||||
#endif
|
|
||||||
@@ -69,6 +69,11 @@
|
|||||||
#ifndef TX_USER_H
|
#ifndef TX_USER_H
|
||||||
#define TX_USER_H
|
#define TX_USER_H
|
||||||
|
|
||||||
|
#if __riscv_xlen == 64 && !defined(__ASSEMBLER__)
|
||||||
|
/* NetX Duo uses this field to pass pointers to IP helper threads. */
|
||||||
|
#define TX_THREAD_USER_EXTENSION void *tx_thread_extension_ptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Define various build options for the ThreadX port. The application should either make changes
|
/* Define various build options for the ThreadX port. The application should either make changes
|
||||||
here by commenting or un-commenting the conditional compilation defined OR supply the defines
|
here by commenting or un-commenting the conditional compilation defined OR supply the defines
|
||||||
though the compiler's equivalent of the -D option.
|
though the compiler's equivalent of the -D option.
|
||||||
|
|||||||
@@ -7,79 +7,37 @@
|
|||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
.section .text
|
|
||||||
.align 4
|
|
||||||
#include "tx_port.h"
|
#include "tx_port.h"
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* trap_entry RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Jer6y , luojun@oerv.isrc.iscas.ac.cn */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function is responsible for riscv processor trap handle */
|
|
||||||
/* It will do the contex save and call c trap_handler and do contex */
|
|
||||||
/* load */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* trap_handler */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* hardware exception */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 10-25-2024 Jerry Luo */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
#if __riscv_xlen == 64
|
||||||
|
#define REG_STORE sd
|
||||||
|
#define REG_LOAD ld
|
||||||
|
#define REG_BYTES 8
|
||||||
|
#else
|
||||||
|
#define REG_STORE sw
|
||||||
|
#define REG_LOAD lw
|
||||||
|
#define REG_BYTES 4
|
||||||
|
#endif
|
||||||
|
|
||||||
/**************************************************************************/
|
.section .text
|
||||||
/**************************************************************************/
|
.balign 4
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Initialize */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
.global trap_entry
|
.global trap_entry
|
||||||
.extern _tx_thread_context_restore
|
.type trap_entry, @function
|
||||||
trap_entry:
|
trap_entry:
|
||||||
addi sp, sp, -TX_INTERRUPT_FRAME_SIZE
|
addi sp, sp, -TX_RISCV_TRAP_FRAME_SIZE
|
||||||
|
REG_STORE ra, (28 * REG_BYTES)(sp)
|
||||||
STORE x1, 28*REGBYTES(sp) // Store RA, 28*REGBYTES(because call will override ra [ra is a calle register in riscv])
|
|
||||||
|
|
||||||
call _tx_thread_context_save
|
call _tx_thread_context_save
|
||||||
|
|
||||||
csrr a0, mcause
|
csrr a0, mcause
|
||||||
csrr a1, mepc
|
csrr a1, mepc
|
||||||
csrr a2, mtval
|
csrr a2, mtval
|
||||||
addi sp, sp, -16 // Keep the C handler stack aligned
|
addi sp, sp, -TX_RISCV_TRAP_CALL_FRAME_SIZE
|
||||||
STORE ra, 0(sp)
|
REG_STORE ra, 0(sp)
|
||||||
call trap_handler
|
call trap_handler
|
||||||
LOAD ra, 0(sp)
|
REG_LOAD ra, 0(sp)
|
||||||
addi sp, sp, 16
|
addi sp, sp, TX_RISCV_TRAP_CALL_FRAME_SIZE
|
||||||
|
|
||||||
call _tx_thread_context_restore
|
call _tx_thread_context_restore
|
||||||
// it will nerver return
|
1: j 1b
|
||||||
.weak trap_handler
|
.size trap_entry, .-trap_entry
|
||||||
trap_handler:
|
|
||||||
1:
|
|
||||||
j 1b
|
|
||||||
.section .text
|
|
||||||
@@ -1,24 +1,32 @@
|
|||||||
|
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "csr.h"
|
#include "csr.h"
|
||||||
#include "hwtimer.h"
|
#include "hwtimer.h"
|
||||||
#include "riscv-traps.h"
|
#include "riscv-traps.h"
|
||||||
#include "tx_port.h"
|
#include "tx_api.h"
|
||||||
|
#include "tx_initialize.h"
|
||||||
|
#include "tx_thread.h"
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
extern CHAR __heap_start;
|
extern CHAR __heap_start[];
|
||||||
extern void trap_entry(void);
|
extern void trap_entry(void);
|
||||||
extern void _tx_timer_interrupt(void);
|
extern void _tx_timer_interrupt(void);
|
||||||
|
|
||||||
extern ULONG* _tx_thread_system_stack_ptr;
|
#ifdef TX_REGRESSION_TEST
|
||||||
extern ULONG* _tx_initialize_unused_memory;
|
extern void test_interrupt_dispatch(void) __attribute__((weak));
|
||||||
|
#endif
|
||||||
|
|
||||||
void handle_RISCV_INT_MTI(void)
|
static void handle_RISCV_INT_MTI(void)
|
||||||
{
|
{
|
||||||
hwtimer_handler();
|
hwtimer_handler();
|
||||||
|
#ifdef TX_REGRESSION_TEST
|
||||||
|
if (test_interrupt_dispatch)
|
||||||
|
test_interrupt_dispatch();
|
||||||
|
#endif
|
||||||
_tx_timer_interrupt();
|
_tx_timer_interrupt();
|
||||||
}
|
}
|
||||||
void handle_RISCV_INT_MEI()
|
|
||||||
|
static void handle_RISCV_INT_MEI(void)
|
||||||
{
|
{
|
||||||
puts("[INTERRUPT]: handler ext irq error!\n");
|
puts("[INTERRUPT]: handler ext irq error!\n");
|
||||||
while (1)
|
while (1)
|
||||||
@@ -27,19 +35,19 @@ void handle_RISCV_INT_MEI()
|
|||||||
|
|
||||||
VOID _tx_initialize_low_level(VOID)
|
VOID _tx_initialize_low_level(VOID)
|
||||||
{
|
{
|
||||||
_tx_thread_system_stack_ptr = (VOID*)(ULONG)riscv_get_sp();
|
_tx_thread_system_stack_ptr = (VOID*)(uintptr_t)riscv_get_sp();
|
||||||
_tx_initialize_unused_memory = (VOID*)&__heap_start;
|
_tx_initialize_unused_memory = __heap_start;
|
||||||
|
|
||||||
// disable interrupts
|
// disable interrupts
|
||||||
asm volatile("csrrc zero, mstatus, %0" : : "r"(MSTATUS_MIE));
|
csr_clr_bits_mstatus(MSTATUS_MIE);
|
||||||
// set previous interrupt enable and previous priv mode to be set when executing "mret"
|
// set previous interrupt enable and previous priv mode to be set when executing "mret"
|
||||||
asm volatile("csrrs zero, mstatus, %0" : : "r"(MSTATUS_MPP_M | MSTATUS_MPIE));
|
csr_set_bits_mstatus(MSTATUS_MPP_M | MSTATUS_MPIE);
|
||||||
// enable timer, software and external interrupts
|
// enable timer, software and external interrupts
|
||||||
asm volatile("csrrs zero, mie, %0" : : "r"(MIE_MTIE | MIE_MSIE | MIE_MEIE));
|
csr_set_bits_mie(MIE_MTIE | MIE_MSIE | MIE_MEIE);
|
||||||
|
|
||||||
#ifdef __riscv_flen
|
#ifdef __riscv_flen
|
||||||
// enable f extension and reset state
|
// enable f extension and reset state
|
||||||
asm volatile("csrrs zero, mstatus, %0" : : "r"(MSTATUS_FS));
|
csr_set_bits_mstatus(MSTATUS_FS);
|
||||||
asm volatile("fscsr x0");
|
asm volatile("fscsr x0");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -47,5 +55,5 @@ VOID _tx_initialize_low_level(VOID)
|
|||||||
register_irq_handler(RISCV_INT_MTI, handle_RISCV_INT_MTI);
|
register_irq_handler(RISCV_INT_MTI, handle_RISCV_INT_MTI);
|
||||||
register_irq_handler(RISCV_INT_MEI, handle_RISCV_INT_MEI);
|
register_irq_handler(RISCV_INT_MEI, handle_RISCV_INT_MEI);
|
||||||
|
|
||||||
asm volatile("csrw mtvec, %0" : : "r"((uintptr_t)trap_entry));
|
csr_write_mtvec((uintptr_t)trap_entry);
|
||||||
}
|
}
|
||||||
@@ -1,315 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Thread */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_context_restore RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Scott Larson, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function restores the interrupt context if it is processing a */
|
|
||||||
/* nested interrupt. If not, it returns to the interrupt thread if no */
|
|
||||||
/* preemption is necessary. Otherwise, if preemption is necessary or */
|
|
||||||
/* if no thread was running, the function returns to the scheduler. */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_schedule Thread scheduling routine */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* ISRs Interrupt Service Routines */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
/* VOID _tx_thread_context_restore(VOID)
|
|
||||||
{ */
|
|
||||||
.global _tx_thread_context_restore
|
|
||||||
_tx_thread_context_restore:
|
|
||||||
|
|
||||||
/* Lockout interrupts. */
|
|
||||||
|
|
||||||
csrci mstatus, 0x08 // Disable interrupts
|
|
||||||
|
|
||||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
|
||||||
call _tx_execution_isr_exit // Call the ISR execution exit function
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Determine if interrupts are nested. */
|
|
||||||
/* if (--_tx_thread_system_state)
|
|
||||||
{ */
|
|
||||||
|
|
||||||
la t0, _tx_thread_system_state // Pickup addr of nested interrupt count
|
|
||||||
LOAD t1, 0(t0) // Pickup nested interrupt count
|
|
||||||
addi t1, t1, -1 // Decrement the nested interrupt counter
|
|
||||||
STORE t1, 0(t0) // Store new nested count
|
|
||||||
beqz t1, _tx_thread_not_nested_restore // If 0, not nested restore
|
|
||||||
|
|
||||||
/* Interrupts are nested. */
|
|
||||||
|
|
||||||
/* Just recover the saved registers and return to the point of
|
|
||||||
interrupt. */
|
|
||||||
|
|
||||||
/* Recover floating point registers. */
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_LOAD f0, TX_INTERRUPT_FP_OFFSET(0)(sp) // Recover ft0
|
|
||||||
TX_FP_LOAD f1, TX_INTERRUPT_FP_OFFSET(1)(sp) // Recover ft1
|
|
||||||
TX_FP_LOAD f2, TX_INTERRUPT_FP_OFFSET(2)(sp) // Recover ft2
|
|
||||||
TX_FP_LOAD f3, TX_INTERRUPT_FP_OFFSET(3)(sp) // Recover ft3
|
|
||||||
TX_FP_LOAD f4, TX_INTERRUPT_FP_OFFSET(4)(sp) // Recover ft4
|
|
||||||
TX_FP_LOAD f5, TX_INTERRUPT_FP_OFFSET(5)(sp) // Recover ft5
|
|
||||||
TX_FP_LOAD f6, TX_INTERRUPT_FP_OFFSET(6)(sp) // Recover ft6
|
|
||||||
TX_FP_LOAD f7, TX_INTERRUPT_FP_OFFSET(7)(sp) // Recover ft7
|
|
||||||
TX_FP_LOAD f10, TX_INTERRUPT_FP_OFFSET(10)(sp) // Recover fa0
|
|
||||||
TX_FP_LOAD f11, TX_INTERRUPT_FP_OFFSET(11)(sp) // Recover fa1
|
|
||||||
TX_FP_LOAD f12, TX_INTERRUPT_FP_OFFSET(12)(sp) // Recover fa2
|
|
||||||
TX_FP_LOAD f13, TX_INTERRUPT_FP_OFFSET(13)(sp) // Recover fa3
|
|
||||||
TX_FP_LOAD f14, TX_INTERRUPT_FP_OFFSET(14)(sp) // Recover fa4
|
|
||||||
TX_FP_LOAD f15, TX_INTERRUPT_FP_OFFSET(15)(sp) // Recover fa5
|
|
||||||
TX_FP_LOAD f16, TX_INTERRUPT_FP_OFFSET(16)(sp) // Recover fa6
|
|
||||||
TX_FP_LOAD f17, TX_INTERRUPT_FP_OFFSET(17)(sp) // Recover fa7
|
|
||||||
TX_FP_LOAD f28, TX_INTERRUPT_FP_OFFSET(28)(sp) // Recover ft8
|
|
||||||
TX_FP_LOAD f29, TX_INTERRUPT_FP_OFFSET(29)(sp) // Recover ft9
|
|
||||||
TX_FP_LOAD f30, TX_INTERRUPT_FP_OFFSET(30)(sp) // Recover ft10
|
|
||||||
TX_FP_LOAD f31, TX_INTERRUPT_FP_OFFSET(31)(sp) // Recover ft11
|
|
||||||
LOAD t0, TX_INTERRUPT_FCSR_OFFSET(sp) // Recover fcsr
|
|
||||||
csrw fcsr, t0 //
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Recover standard registers. */
|
|
||||||
|
|
||||||
/* Restore registers,
|
|
||||||
Skip global pointer because that does not change.
|
|
||||||
Also skip the saved registers since they have been restored by any function we called,
|
|
||||||
except s0 since we use it ourselves. */
|
|
||||||
|
|
||||||
LOAD t0, 30*REGBYTES(sp) // Recover mepc
|
|
||||||
csrw mepc, t0 // Setup mepc
|
|
||||||
li t0, 0x1880 // Prepare MPIP
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
li t1, 1<<13
|
|
||||||
or t0, t1, t0
|
|
||||||
#endif
|
|
||||||
csrw mstatus, t0 // Enable MPIP
|
|
||||||
|
|
||||||
LOAD x1, 28*REGBYTES(sp) // Recover RA
|
|
||||||
LOAD x5, 19*REGBYTES(sp) // Recover t0
|
|
||||||
LOAD x6, 18*REGBYTES(sp) // Recover t1
|
|
||||||
LOAD x7, 17*REGBYTES(sp) // Recover t2
|
|
||||||
LOAD x8, 12*REGBYTES(sp) // Recover s0
|
|
||||||
LOAD x10, 27*REGBYTES(sp) // Recover a0
|
|
||||||
LOAD x11, 26*REGBYTES(sp) // Recover a1
|
|
||||||
LOAD x12, 25*REGBYTES(sp) // Recover a2
|
|
||||||
LOAD x13, 24*REGBYTES(sp) // Recover a3
|
|
||||||
LOAD x14, 23*REGBYTES(sp) // Recover a4
|
|
||||||
LOAD x15, 22*REGBYTES(sp) // Recover a5
|
|
||||||
LOAD x16, 21*REGBYTES(sp) // Recover a6
|
|
||||||
LOAD x17, 20*REGBYTES(sp) // Recover a7
|
|
||||||
LOAD x28, 16*REGBYTES(sp) // Recover t3
|
|
||||||
LOAD x29, 15*REGBYTES(sp) // Recover t4
|
|
||||||
LOAD x30, 14*REGBYTES(sp) // Recover t5
|
|
||||||
LOAD x31, 13*REGBYTES(sp) // Recover t6
|
|
||||||
|
|
||||||
addi sp, sp, TX_INTERRUPT_FRAME_SIZE
|
|
||||||
mret // Return to point of interrupt
|
|
||||||
|
|
||||||
/* } */
|
|
||||||
_tx_thread_not_nested_restore:
|
|
||||||
/* Determine if a thread was interrupted and no preemption is required. */
|
|
||||||
/* else if (((_tx_thread_current_ptr) && (_tx_thread_current_ptr == _tx_thread_execute_ptr)
|
|
||||||
|| (_tx_thread_preempt_disable))
|
|
||||||
{ */
|
|
||||||
|
|
||||||
LOAD t1, _tx_thread_current_ptr // Pickup current thread pointer
|
|
||||||
beqz t1, _tx_thread_idle_system_restore // If NULL, idle system restore
|
|
||||||
|
|
||||||
LWU t2, _tx_thread_preempt_disable // Pickup preempt disable flag
|
|
||||||
bgtz t2, _tx_thread_no_preempt_restore // If set, restore interrupted thread
|
|
||||||
|
|
||||||
LOAD t2, _tx_thread_execute_ptr // Pickup thread execute pointer
|
|
||||||
bne t1, t2, _tx_thread_preempt_restore // If higher-priority thread is ready, preempt
|
|
||||||
|
|
||||||
|
|
||||||
_tx_thread_no_preempt_restore:
|
|
||||||
/* Restore interrupted thread or ISR. */
|
|
||||||
|
|
||||||
/* Pickup the saved stack pointer. */
|
|
||||||
/* SP = _tx_thread_current_ptr -> tx_thread_stack_ptr; */
|
|
||||||
|
|
||||||
LOAD sp, 2*REGBYTES(t1) // Switch back to thread's stack
|
|
||||||
|
|
||||||
/* Recover floating point registers. */
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_LOAD f0, TX_INTERRUPT_FP_OFFSET(0)(sp) // Recover ft0
|
|
||||||
TX_FP_LOAD f1, TX_INTERRUPT_FP_OFFSET(1)(sp) // Recover ft1
|
|
||||||
TX_FP_LOAD f2, TX_INTERRUPT_FP_OFFSET(2)(sp) // Recover ft2
|
|
||||||
TX_FP_LOAD f3, TX_INTERRUPT_FP_OFFSET(3)(sp) // Recover ft3
|
|
||||||
TX_FP_LOAD f4, TX_INTERRUPT_FP_OFFSET(4)(sp) // Recover ft4
|
|
||||||
TX_FP_LOAD f5, TX_INTERRUPT_FP_OFFSET(5)(sp) // Recover ft5
|
|
||||||
TX_FP_LOAD f6, TX_INTERRUPT_FP_OFFSET(6)(sp) // Recover ft6
|
|
||||||
TX_FP_LOAD f7, TX_INTERRUPT_FP_OFFSET(7)(sp) // Recover ft7
|
|
||||||
TX_FP_LOAD f10, TX_INTERRUPT_FP_OFFSET(10)(sp) // Recover fa0
|
|
||||||
TX_FP_LOAD f11, TX_INTERRUPT_FP_OFFSET(11)(sp) // Recover fa1
|
|
||||||
TX_FP_LOAD f12, TX_INTERRUPT_FP_OFFSET(12)(sp) // Recover fa2
|
|
||||||
TX_FP_LOAD f13, TX_INTERRUPT_FP_OFFSET(13)(sp) // Recover fa3
|
|
||||||
TX_FP_LOAD f14, TX_INTERRUPT_FP_OFFSET(14)(sp) // Recover fa4
|
|
||||||
TX_FP_LOAD f15, TX_INTERRUPT_FP_OFFSET(15)(sp) // Recover fa5
|
|
||||||
TX_FP_LOAD f16, TX_INTERRUPT_FP_OFFSET(16)(sp) // Recover fa6
|
|
||||||
TX_FP_LOAD f17, TX_INTERRUPT_FP_OFFSET(17)(sp) // Recover fa7
|
|
||||||
TX_FP_LOAD f28, TX_INTERRUPT_FP_OFFSET(28)(sp) // Recover ft8
|
|
||||||
TX_FP_LOAD f29, TX_INTERRUPT_FP_OFFSET(29)(sp) // Recover ft9
|
|
||||||
TX_FP_LOAD f30, TX_INTERRUPT_FP_OFFSET(30)(sp) // Recover ft10
|
|
||||||
TX_FP_LOAD f31, TX_INTERRUPT_FP_OFFSET(31)(sp) // Recover ft11
|
|
||||||
LOAD t0, TX_INTERRUPT_FCSR_OFFSET(sp) // Recover fcsr
|
|
||||||
csrw fcsr, t0 //
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Recover the saved context and return to the point of interrupt. */
|
|
||||||
|
|
||||||
/* Recover standard registers. */
|
|
||||||
/* Restore registers,
|
|
||||||
Skip global pointer because that does not change */
|
|
||||||
|
|
||||||
LOAD t0, 30*REGBYTES(sp) // Recover mepc
|
|
||||||
csrw mepc, t0 // Setup mepc
|
|
||||||
li t0, 0x1880 // Prepare MPIP
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
li t1, 1<<13
|
|
||||||
or t0, t1, t0
|
|
||||||
#endif
|
|
||||||
csrw mstatus, t0 // Enable MPIP
|
|
||||||
|
|
||||||
LOAD x1, 28*REGBYTES(sp) // Recover RA
|
|
||||||
LOAD x5, 19*REGBYTES(sp) // Recover t0
|
|
||||||
LOAD x6, 18*REGBYTES(sp) // Recover t1
|
|
||||||
LOAD x7, 17*REGBYTES(sp) // Recover t2
|
|
||||||
LOAD x8, 12*REGBYTES(sp) // Recover s0
|
|
||||||
LOAD x10, 27*REGBYTES(sp) // Recover a0
|
|
||||||
LOAD x11, 26*REGBYTES(sp) // Recover a1
|
|
||||||
LOAD x12, 25*REGBYTES(sp) // Recover a2
|
|
||||||
LOAD x13, 24*REGBYTES(sp) // Recover a3
|
|
||||||
LOAD x14, 23*REGBYTES(sp) // Recover a4
|
|
||||||
LOAD x15, 22*REGBYTES(sp) // Recover a5
|
|
||||||
LOAD x16, 21*REGBYTES(sp) // Recover a6
|
|
||||||
LOAD x17, 20*REGBYTES(sp) // Recover a7
|
|
||||||
LOAD x28, 16*REGBYTES(sp) // Recover t3
|
|
||||||
LOAD x29, 15*REGBYTES(sp) // Recover t4
|
|
||||||
LOAD x30, 14*REGBYTES(sp) // Recover t5
|
|
||||||
LOAD x31, 13*REGBYTES(sp) // Recover t6
|
|
||||||
|
|
||||||
addi sp, sp, TX_INTERRUPT_FRAME_SIZE
|
|
||||||
mret // Return to point of interrupt
|
|
||||||
|
|
||||||
/* }
|
|
||||||
else
|
|
||||||
{ */
|
|
||||||
_tx_thread_preempt_restore:
|
|
||||||
/* Instead of directly activating the thread again, ensure we save the
|
|
||||||
entire stack frame by saving the remaining registers. */
|
|
||||||
|
|
||||||
LOAD t0, 2*REGBYTES(t1) // Pickup thread's stack pointer
|
|
||||||
ori t3, x0, 1 // Build interrupt stack type
|
|
||||||
STORE t3, 0(t0) // Store stack type
|
|
||||||
|
|
||||||
/* Store floating point preserved registers. */
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_STORE f8, TX_INTERRUPT_FP_OFFSET(8)(t0) // Store fs0
|
|
||||||
TX_FP_STORE f9, TX_INTERRUPT_FP_OFFSET(9)(t0) // Store fs1
|
|
||||||
TX_FP_STORE f18, TX_INTERRUPT_FP_OFFSET(18)(t0) // Store fs2
|
|
||||||
TX_FP_STORE f19, TX_INTERRUPT_FP_OFFSET(19)(t0) // Store fs3
|
|
||||||
TX_FP_STORE f20, TX_INTERRUPT_FP_OFFSET(20)(t0) // Store fs4
|
|
||||||
TX_FP_STORE f21, TX_INTERRUPT_FP_OFFSET(21)(t0) // Store fs5
|
|
||||||
TX_FP_STORE f22, TX_INTERRUPT_FP_OFFSET(22)(t0) // Store fs6
|
|
||||||
TX_FP_STORE f23, TX_INTERRUPT_FP_OFFSET(23)(t0) // Store fs7
|
|
||||||
TX_FP_STORE f24, TX_INTERRUPT_FP_OFFSET(24)(t0) // Store fs8
|
|
||||||
TX_FP_STORE f25, TX_INTERRUPT_FP_OFFSET(25)(t0) // Store fs9
|
|
||||||
TX_FP_STORE f26, TX_INTERRUPT_FP_OFFSET(26)(t0) // Store fs10
|
|
||||||
TX_FP_STORE f27, TX_INTERRUPT_FP_OFFSET(27)(t0) // Store fs11
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Store standard preserved registers. */
|
|
||||||
|
|
||||||
STORE x9, 11*REGBYTES(t0) // Store s1
|
|
||||||
STORE x18, 10*REGBYTES(t0) // Store s2
|
|
||||||
STORE x19, 9*REGBYTES(t0) // Store s3
|
|
||||||
STORE x20, 8*REGBYTES(t0) // Store s4
|
|
||||||
STORE x21, 7*REGBYTES(t0) // Store s5
|
|
||||||
STORE x22, 6*REGBYTES(t0) // Store s6
|
|
||||||
STORE x23, 5*REGBYTES(t0) // Store s7
|
|
||||||
STORE x24, 4*REGBYTES(t0) // Store s8
|
|
||||||
STORE x25, 3*REGBYTES(t0) // Store s9
|
|
||||||
STORE x26, 2*REGBYTES(t0) // Store s10
|
|
||||||
STORE x27, 1*REGBYTES(t0) // Store s11
|
|
||||||
// Note: s0 is already stored!
|
|
||||||
|
|
||||||
/* Save the remaining time-slice and disable it. */
|
|
||||||
/* if (_tx_timer_time_slice)
|
|
||||||
{ */
|
|
||||||
|
|
||||||
la t0, _tx_timer_time_slice // Pickup time slice variable address
|
|
||||||
LOAD t2, 0(t0) // Pickup time slice
|
|
||||||
beqz t2, _tx_thread_dont_save_ts // If 0, skip time slice processing
|
|
||||||
|
|
||||||
/* _tx_thread_current_ptr -> tx_thread_time_slice = _tx_timer_time_slice
|
|
||||||
_tx_timer_time_slice = 0; */
|
|
||||||
|
|
||||||
STORE t2, 6*REGBYTES(t1) // Save current time slice
|
|
||||||
STORE x0, 0(t0) // Clear global time slice
|
|
||||||
|
|
||||||
|
|
||||||
/* } */
|
|
||||||
_tx_thread_dont_save_ts:
|
|
||||||
/* Clear the current task pointer. */
|
|
||||||
/* _tx_thread_current_ptr = TX_NULL; */
|
|
||||||
|
|
||||||
/* Return to the scheduler. */
|
|
||||||
/* _tx_thread_schedule(); */
|
|
||||||
|
|
||||||
STORE x0, _tx_thread_current_ptr, t0 // Clear current thread pointer*/
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
_tx_thread_idle_system_restore:
|
|
||||||
/* Just return back to the scheduler! */
|
|
||||||
j _tx_thread_schedule // Return to scheduler
|
|
||||||
|
|
||||||
/* } */
|
|
||||||
@@ -1,233 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Thread */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_context_save RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Scott Larson, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function saves the context of an executing thread in the */
|
|
||||||
/* beginning of interrupt processing. The function also ensures that */
|
|
||||||
/* the system stack is used upon return to the calling ISR. */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* ISRs */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
/* VOID _tx_thread_context_save(VOID)
|
|
||||||
{ */
|
|
||||||
.global _tx_thread_context_save
|
|
||||||
_tx_thread_context_save:
|
|
||||||
|
|
||||||
/* Upon entry to this routine, it is assumed that interrupts are locked
|
|
||||||
out and the interrupt stack fame has been allocated and x1 (ra) has
|
|
||||||
been saved on the stack. */
|
|
||||||
|
|
||||||
STORE t0, 19*REGBYTES(sp) // First store t0 and t1
|
|
||||||
STORE t1, 18*REGBYTES(sp)
|
|
||||||
|
|
||||||
la t0, _tx_thread_system_state // Pickup address of system state
|
|
||||||
LOAD t1, 0(t0) // Pickup system state
|
|
||||||
|
|
||||||
/* Check for a nested interrupt condition. */
|
|
||||||
/* if (_tx_thread_system_state++)
|
|
||||||
{ */
|
|
||||||
beqz t1, _tx_thread_not_nested_save // If 0, first interrupt condition
|
|
||||||
addi t1, t1, 1 // Increment the interrupt counter
|
|
||||||
STORE t1, 0(t0) // Store the interrupt counter
|
|
||||||
|
|
||||||
/* Nested interrupt condition.
|
|
||||||
Save the reset of the scratch registers on the stack and return to the
|
|
||||||
calling ISR. */
|
|
||||||
|
|
||||||
STORE x7, 17*REGBYTES(sp) // Store t2
|
|
||||||
STORE x8, 12*REGBYTES(sp) // Store s0
|
|
||||||
STORE x10, 27*REGBYTES(sp) // Store a0
|
|
||||||
STORE x11, 26*REGBYTES(sp) // Store a1
|
|
||||||
STORE x12, 25*REGBYTES(sp) // Store a2
|
|
||||||
STORE x13, 24*REGBYTES(sp) // Store a3
|
|
||||||
STORE x14, 23*REGBYTES(sp) // Store a4
|
|
||||||
STORE x15, 22*REGBYTES(sp) // Store a5
|
|
||||||
STORE x16, 21*REGBYTES(sp) // Store a6
|
|
||||||
STORE x17, 20*REGBYTES(sp) // Store a7
|
|
||||||
STORE x28, 16*REGBYTES(sp) // Store t3
|
|
||||||
STORE x29, 15*REGBYTES(sp) // Store t4
|
|
||||||
STORE x30, 14*REGBYTES(sp) // Store t5
|
|
||||||
STORE x31, 13*REGBYTES(sp) // Store t6
|
|
||||||
csrr t0, mepc // Load exception program counter
|
|
||||||
STORE t0, 30*REGBYTES(sp) // Save it on the stack
|
|
||||||
|
|
||||||
/* Save floating point scratch registers. */
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_STORE f0, TX_INTERRUPT_FP_OFFSET(0)(sp) // Store ft0
|
|
||||||
TX_FP_STORE f1, TX_INTERRUPT_FP_OFFSET(1)(sp) // Store ft1
|
|
||||||
TX_FP_STORE f2, TX_INTERRUPT_FP_OFFSET(2)(sp) // Store ft2
|
|
||||||
TX_FP_STORE f3, TX_INTERRUPT_FP_OFFSET(3)(sp) // Store ft3
|
|
||||||
TX_FP_STORE f4, TX_INTERRUPT_FP_OFFSET(4)(sp) // Store ft4
|
|
||||||
TX_FP_STORE f5, TX_INTERRUPT_FP_OFFSET(5)(sp) // Store ft5
|
|
||||||
TX_FP_STORE f6, TX_INTERRUPT_FP_OFFSET(6)(sp) // Store ft6
|
|
||||||
TX_FP_STORE f7, TX_INTERRUPT_FP_OFFSET(7)(sp) // Store ft7
|
|
||||||
TX_FP_STORE f10, TX_INTERRUPT_FP_OFFSET(10)(sp) // Store fa0
|
|
||||||
TX_FP_STORE f11, TX_INTERRUPT_FP_OFFSET(11)(sp) // Store fa1
|
|
||||||
TX_FP_STORE f12, TX_INTERRUPT_FP_OFFSET(12)(sp) // Store fa2
|
|
||||||
TX_FP_STORE f13, TX_INTERRUPT_FP_OFFSET(13)(sp) // Store fa3
|
|
||||||
TX_FP_STORE f14, TX_INTERRUPT_FP_OFFSET(14)(sp) // Store fa4
|
|
||||||
TX_FP_STORE f15, TX_INTERRUPT_FP_OFFSET(15)(sp) // Store fa5
|
|
||||||
TX_FP_STORE f16, TX_INTERRUPT_FP_OFFSET(16)(sp) // Store fa6
|
|
||||||
TX_FP_STORE f17, TX_INTERRUPT_FP_OFFSET(17)(sp) // Store fa7
|
|
||||||
TX_FP_STORE f28, TX_INTERRUPT_FP_OFFSET(28)(sp) // Store ft8
|
|
||||||
TX_FP_STORE f29, TX_INTERRUPT_FP_OFFSET(29)(sp) // Store ft9
|
|
||||||
TX_FP_STORE f30, TX_INTERRUPT_FP_OFFSET(30)(sp) // Store ft10
|
|
||||||
TX_FP_STORE f31, TX_INTERRUPT_FP_OFFSET(31)(sp) // Store ft11
|
|
||||||
csrr t0, fcsr
|
|
||||||
STORE t0, TX_INTERRUPT_FCSR_OFFSET(sp) // Store fcsr
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
|
||||||
call _tx_execution_isr_enter // Call the ISR execution enter function
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ret // Return to calling ISR
|
|
||||||
|
|
||||||
_tx_thread_not_nested_save:
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
/* Otherwise, not nested, check to see if a thread was running. */
|
|
||||||
/* else if (_tx_thread_current_ptr)
|
|
||||||
{ */
|
|
||||||
addi t1, t1, 1 // Increment the interrupt counter
|
|
||||||
sw t1, 0(t0) // Store the interrupt counter
|
|
||||||
|
|
||||||
/* Not nested: Find the user thread that was running and load our SP */
|
|
||||||
|
|
||||||
LOAD t0, _tx_thread_current_ptr // Pickup current thread pointer
|
|
||||||
beqz t0, _tx_thread_idle_system_save // If NULL, idle system was interrupted
|
|
||||||
|
|
||||||
/* Save the standard scratch registers. */
|
|
||||||
|
|
||||||
STORE x7, 17*REGBYTES(sp) // Store t2
|
|
||||||
STORE x8, 12*REGBYTES(sp) // Store s0
|
|
||||||
STORE x10, 27*REGBYTES(sp) // Store a0
|
|
||||||
STORE x11, 26*REGBYTES(sp) // Store a1
|
|
||||||
STORE x12, 25*REGBYTES(sp) // Store a2
|
|
||||||
STORE x13, 24*REGBYTES(sp) // Store a3
|
|
||||||
STORE x14, 23*REGBYTES(sp) // Store a4
|
|
||||||
STORE x15, 22*REGBYTES(sp) // Store a5
|
|
||||||
STORE x16, 21*REGBYTES(sp) // Store a6
|
|
||||||
STORE x17, 20*REGBYTES(sp) // Store a7
|
|
||||||
STORE x28, 16*REGBYTES(sp) // Store t3
|
|
||||||
STORE x29, 15*REGBYTES(sp) // Store t4
|
|
||||||
STORE x30, 14*REGBYTES(sp) // Store t5
|
|
||||||
STORE x31, 13*REGBYTES(sp) // Store t6
|
|
||||||
|
|
||||||
csrr t0, mepc // Load exception program counter
|
|
||||||
STORE t0, 30*REGBYTES(sp) // Save it on the stack
|
|
||||||
|
|
||||||
/* Save floating point scratch registers. */
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_STORE f0, TX_INTERRUPT_FP_OFFSET(0)(sp) // Store ft0
|
|
||||||
TX_FP_STORE f1, TX_INTERRUPT_FP_OFFSET(1)(sp) // Store ft1
|
|
||||||
TX_FP_STORE f2, TX_INTERRUPT_FP_OFFSET(2)(sp) // Store ft2
|
|
||||||
TX_FP_STORE f3, TX_INTERRUPT_FP_OFFSET(3)(sp) // Store ft3
|
|
||||||
TX_FP_STORE f4, TX_INTERRUPT_FP_OFFSET(4)(sp) // Store ft4
|
|
||||||
TX_FP_STORE f5, TX_INTERRUPT_FP_OFFSET(5)(sp) // Store ft5
|
|
||||||
TX_FP_STORE f6, TX_INTERRUPT_FP_OFFSET(6)(sp) // Store ft6
|
|
||||||
TX_FP_STORE f7, TX_INTERRUPT_FP_OFFSET(7)(sp) // Store ft7
|
|
||||||
TX_FP_STORE f10, TX_INTERRUPT_FP_OFFSET(10)(sp) // Store fa0
|
|
||||||
TX_FP_STORE f11, TX_INTERRUPT_FP_OFFSET(11)(sp) // Store fa1
|
|
||||||
TX_FP_STORE f12, TX_INTERRUPT_FP_OFFSET(12)(sp) // Store fa2
|
|
||||||
TX_FP_STORE f13, TX_INTERRUPT_FP_OFFSET(13)(sp) // Store fa3
|
|
||||||
TX_FP_STORE f14, TX_INTERRUPT_FP_OFFSET(14)(sp) // Store fa4
|
|
||||||
TX_FP_STORE f15, TX_INTERRUPT_FP_OFFSET(15)(sp) // Store fa5
|
|
||||||
TX_FP_STORE f16, TX_INTERRUPT_FP_OFFSET(16)(sp) // Store fa6
|
|
||||||
TX_FP_STORE f17, TX_INTERRUPT_FP_OFFSET(17)(sp) // Store fa7
|
|
||||||
TX_FP_STORE f28, TX_INTERRUPT_FP_OFFSET(28)(sp) // Store ft8
|
|
||||||
TX_FP_STORE f29, TX_INTERRUPT_FP_OFFSET(29)(sp) // Store ft9
|
|
||||||
TX_FP_STORE f30, TX_INTERRUPT_FP_OFFSET(30)(sp) // Store ft10
|
|
||||||
TX_FP_STORE f31, TX_INTERRUPT_FP_OFFSET(31)(sp) // Store ft11
|
|
||||||
csrr t0, fcsr
|
|
||||||
STORE t0, TX_INTERRUPT_FCSR_OFFSET(sp) // Store fcsr
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Save the current stack pointer in the thread's control block. */
|
|
||||||
/* _tx_thread_current_ptr -> tx_thread_stack_ptr = sp; */
|
|
||||||
|
|
||||||
/* Switch to the system stack. */
|
|
||||||
/* sp = _tx_thread_system_stack_ptr; */
|
|
||||||
|
|
||||||
LOAD t1, _tx_thread_current_ptr // Pickup current thread pointer
|
|
||||||
STORE sp, 2*REGBYTES(t1) // Save stack pointer
|
|
||||||
|
|
||||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
|
||||||
/* _tx_execution_isr_enter is called with thread stack pointer */
|
|
||||||
call _tx_execution_isr_enter // Call the ISR execution enter function
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
LOAD sp, _tx_thread_system_stack_ptr // Switch to system stack
|
|
||||||
ret // Return to calling ISR
|
|
||||||
|
|
||||||
/* }
|
|
||||||
else
|
|
||||||
{ */
|
|
||||||
|
|
||||||
_tx_thread_idle_system_save:
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
|
||||||
call _tx_execution_isr_enter // Call the ISR execution enter function
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Interrupt occurred in the scheduling loop. */
|
|
||||||
|
|
||||||
/* }
|
|
||||||
} */
|
|
||||||
addi sp, sp, TX_INTERRUPT_FRAME_SIZE
|
|
||||||
ret // Return to calling ISR
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Thread */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
RETURN_MASK = 0x000000000000000F
|
|
||||||
SET_SR_MASK = 0xFFFFFFFFFFFFFFF0
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_interrupt_control RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Scott Larson, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function is responsible for changing the interrupt lockout */
|
|
||||||
/* posture of the system. */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* new_posture New interrupt lockout posture */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* old_posture Old interrupt lockout posture */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* Application Code */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
/* UINT _tx_thread_interrupt_control(UINT new_posture)
|
|
||||||
{ */
|
|
||||||
.global _tx_thread_interrupt_control
|
|
||||||
_tx_thread_interrupt_control:
|
|
||||||
/* Pickup current interrupt lockout posture. */
|
|
||||||
|
|
||||||
csrr t0, mstatus
|
|
||||||
mv t1, t0 // Save original mstatus for return
|
|
||||||
|
|
||||||
/* Apply the new interrupt posture. */
|
|
||||||
|
|
||||||
li t2, SET_SR_MASK // Build set SR mask
|
|
||||||
and t0, t0, t2 // Isolate interrupt lockout bits
|
|
||||||
or t0, t0, a0 // Put new lockout bits in
|
|
||||||
csrw mstatus, t0
|
|
||||||
andi a0, t1, RETURN_MASK // Return original mstatus.
|
|
||||||
ret
|
|
||||||
/* } */
|
|
||||||
@@ -1,250 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Thread */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_schedule RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Scott Larson, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function waits for a thread control block pointer to appear in */
|
|
||||||
/* the _tx_thread_execute_ptr variable. Once a thread pointer appears */
|
|
||||||
/* in the variable, the corresponding thread is resumed. */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* _tx_initialize_kernel_enter ThreadX entry function */
|
|
||||||
/* _tx_thread_system_return Return to system from thread */
|
|
||||||
/* _tx_thread_context_restore Restore thread's context */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
/* VOID _tx_thread_schedule(VOID)
|
|
||||||
{ */
|
|
||||||
.global _tx_thread_schedule
|
|
||||||
_tx_thread_schedule:
|
|
||||||
|
|
||||||
/* Enable interrupts. */
|
|
||||||
csrsi mstatus, 0x08 // Enable interrupts
|
|
||||||
|
|
||||||
/* Wait for a thread to execute. */
|
|
||||||
/* do
|
|
||||||
{ */
|
|
||||||
|
|
||||||
la t0, _tx_thread_execute_ptr // Pickup address of execute ptr
|
|
||||||
_tx_thread_schedule_loop:
|
|
||||||
LOAD t1, 0(t0) // Pickup next thread to execute
|
|
||||||
beqz t1, _tx_thread_schedule_loop // If NULL, wait for thread to execute
|
|
||||||
|
|
||||||
/* }
|
|
||||||
while(_tx_thread_execute_ptr == TX_NULL); */
|
|
||||||
|
|
||||||
scheduler_found_thread:
|
|
||||||
/* Yes! We have a thread to execute. Lockout interrupts and
|
|
||||||
transfer control to it. */
|
|
||||||
csrci mstatus, 0x08 // Lockout interrupts
|
|
||||||
|
|
||||||
/* Setup the current thread pointer. */
|
|
||||||
/* _tx_thread_current_ptr = _tx_thread_execute_ptr; */
|
|
||||||
|
|
||||||
la t0, _tx_thread_current_ptr // Pickup current thread pointer address
|
|
||||||
STORE t1, 0(t0) // Set current thread pointer
|
|
||||||
|
|
||||||
/* Increment the run count for this thread. */
|
|
||||||
/* _tx_thread_current_ptr -> tx_thread_run_count++; */
|
|
||||||
|
|
||||||
LOAD t2, 1*REGBYTES(t1) // Pickup run count
|
|
||||||
LOAD t3, 6*REGBYTES(t1) // Pickup time slice value
|
|
||||||
addi t2, t2, 1 // Increment run count
|
|
||||||
STORE t2, 1*REGBYTES(t1) // Store new run count
|
|
||||||
|
|
||||||
/* Setup time-slice, if present. */
|
|
||||||
/* _tx_timer_time_slice = _tx_thread_current_ptr -> tx_thread_time_slice; */
|
|
||||||
|
|
||||||
la t2, _tx_timer_time_slice // Pickup time-slice variable address
|
|
||||||
STORE t3, 0(t2) // Store new time-slice*/
|
|
||||||
|
|
||||||
/* Switch to the thread's stack. */
|
|
||||||
/* SP = _tx_thread_execute_ptr -> tx_thread_stack_ptr; */
|
|
||||||
|
|
||||||
LOAD sp, 2*REGBYTES(t1) // Switch to thread's stack
|
|
||||||
|
|
||||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
|
||||||
|
|
||||||
call _tx_execution_thread_enter // Call the thread execution enter function
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Determine if an interrupt frame or a synchronous task suspension frame
|
|
||||||
is present. */
|
|
||||||
|
|
||||||
LOAD t2, 0(sp) // Pickup stack type
|
|
||||||
beqz t2, _tx_thread_synch_return // If 0, solicited thread return
|
|
||||||
|
|
||||||
/* Determine if floating point registers need to be recovered. */
|
|
||||||
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_LOAD f0, TX_INTERRUPT_FP_OFFSET(0)(sp) // Recover ft0
|
|
||||||
TX_FP_LOAD f1, TX_INTERRUPT_FP_OFFSET(1)(sp) // Recover ft1
|
|
||||||
TX_FP_LOAD f2, TX_INTERRUPT_FP_OFFSET(2)(sp) // Recover ft2
|
|
||||||
TX_FP_LOAD f3, TX_INTERRUPT_FP_OFFSET(3)(sp) // Recover ft3
|
|
||||||
TX_FP_LOAD f4, TX_INTERRUPT_FP_OFFSET(4)(sp) // Recover ft4
|
|
||||||
TX_FP_LOAD f5, TX_INTERRUPT_FP_OFFSET(5)(sp) // Recover ft5
|
|
||||||
TX_FP_LOAD f6, TX_INTERRUPT_FP_OFFSET(6)(sp) // Recover ft6
|
|
||||||
TX_FP_LOAD f7, TX_INTERRUPT_FP_OFFSET(7)(sp) // Recover ft7
|
|
||||||
TX_FP_LOAD f8, TX_INTERRUPT_FP_OFFSET(8)(sp) // Recover fs0
|
|
||||||
TX_FP_LOAD f9, TX_INTERRUPT_FP_OFFSET(9)(sp) // Recover fs1
|
|
||||||
TX_FP_LOAD f10, TX_INTERRUPT_FP_OFFSET(10)(sp) // Recover fa0
|
|
||||||
TX_FP_LOAD f11, TX_INTERRUPT_FP_OFFSET(11)(sp) // Recover fa1
|
|
||||||
TX_FP_LOAD f12, TX_INTERRUPT_FP_OFFSET(12)(sp) // Recover fa2
|
|
||||||
TX_FP_LOAD f13, TX_INTERRUPT_FP_OFFSET(13)(sp) // Recover fa3
|
|
||||||
TX_FP_LOAD f14, TX_INTERRUPT_FP_OFFSET(14)(sp) // Recover fa4
|
|
||||||
TX_FP_LOAD f15, TX_INTERRUPT_FP_OFFSET(15)(sp) // Recover fa5
|
|
||||||
TX_FP_LOAD f16, TX_INTERRUPT_FP_OFFSET(16)(sp) // Recover fa6
|
|
||||||
TX_FP_LOAD f17, TX_INTERRUPT_FP_OFFSET(17)(sp) // Recover fa7
|
|
||||||
TX_FP_LOAD f18, TX_INTERRUPT_FP_OFFSET(18)(sp) // Recover fs2
|
|
||||||
TX_FP_LOAD f19, TX_INTERRUPT_FP_OFFSET(19)(sp) // Recover fs3
|
|
||||||
TX_FP_LOAD f20, TX_INTERRUPT_FP_OFFSET(20)(sp) // Recover fs4
|
|
||||||
TX_FP_LOAD f21, TX_INTERRUPT_FP_OFFSET(21)(sp) // Recover fs5
|
|
||||||
TX_FP_LOAD f22, TX_INTERRUPT_FP_OFFSET(22)(sp) // Recover fs6
|
|
||||||
TX_FP_LOAD f23, TX_INTERRUPT_FP_OFFSET(23)(sp) // Recover fs7
|
|
||||||
TX_FP_LOAD f24, TX_INTERRUPT_FP_OFFSET(24)(sp) // Recover fs8
|
|
||||||
TX_FP_LOAD f25, TX_INTERRUPT_FP_OFFSET(25)(sp) // Recover fs9
|
|
||||||
TX_FP_LOAD f26, TX_INTERRUPT_FP_OFFSET(26)(sp) // Recover fs10
|
|
||||||
TX_FP_LOAD f27, TX_INTERRUPT_FP_OFFSET(27)(sp) // Recover fs11
|
|
||||||
TX_FP_LOAD f28, TX_INTERRUPT_FP_OFFSET(28)(sp) // Recover ft8
|
|
||||||
TX_FP_LOAD f29, TX_INTERRUPT_FP_OFFSET(29)(sp) // Recover ft9
|
|
||||||
TX_FP_LOAD f30, TX_INTERRUPT_FP_OFFSET(30)(sp) // Recover ft10
|
|
||||||
TX_FP_LOAD f31, TX_INTERRUPT_FP_OFFSET(31)(sp) // Recover ft11
|
|
||||||
LOAD t0, TX_INTERRUPT_FCSR_OFFSET(sp) // Recover fcsr
|
|
||||||
csrw fcsr, t0 //
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Recover standard registers. */
|
|
||||||
|
|
||||||
LOAD t0, 30*REGBYTES(sp) // Recover mepc
|
|
||||||
csrw mepc, t0 // Store mepc
|
|
||||||
li t0, 0x1880 // Prepare MPIP
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
li t1, 1<<13
|
|
||||||
or t0, t1, t0
|
|
||||||
#endif
|
|
||||||
csrw mstatus, t0 // Enable MPIP
|
|
||||||
|
|
||||||
LOAD x1, 28*REGBYTES(sp) // Recover RA
|
|
||||||
LOAD x5, 19*REGBYTES(sp) // Recover t0
|
|
||||||
LOAD x6, 18*REGBYTES(sp) // Recover t1
|
|
||||||
LOAD x7, 17*REGBYTES(sp) // Recover t2
|
|
||||||
LOAD x8, 12*REGBYTES(sp) // Recover s0
|
|
||||||
LOAD x9, 11*REGBYTES(sp) // Recover s1
|
|
||||||
LOAD x10, 27*REGBYTES(sp) // Recover a0
|
|
||||||
LOAD x11, 26*REGBYTES(sp) // Recover a1
|
|
||||||
LOAD x12, 25*REGBYTES(sp) // Recover a2
|
|
||||||
LOAD x13, 24*REGBYTES(sp) // Recover a3
|
|
||||||
LOAD x14, 23*REGBYTES(sp) // Recover a4
|
|
||||||
LOAD x15, 22*REGBYTES(sp) // Recover a5
|
|
||||||
LOAD x16, 21*REGBYTES(sp) // Recover a6
|
|
||||||
LOAD x17, 20*REGBYTES(sp) // Recover a7
|
|
||||||
LOAD x18, 10*REGBYTES(sp) // Recover s2
|
|
||||||
LOAD x19, 9*REGBYTES(sp) // Recover s3
|
|
||||||
LOAD x20, 8*REGBYTES(sp) // Recover s4
|
|
||||||
LOAD x21, 7*REGBYTES(sp) // Recover s5
|
|
||||||
LOAD x22, 6*REGBYTES(sp) // Recover s6
|
|
||||||
LOAD x23, 5*REGBYTES(sp) // Recover s7
|
|
||||||
LOAD x24, 4*REGBYTES(sp) // Recover s8
|
|
||||||
LOAD x25, 3*REGBYTES(sp) // Recover s9
|
|
||||||
LOAD x26, 2*REGBYTES(sp) // Recover s10
|
|
||||||
LOAD x27, 1*REGBYTES(sp) // Recover s11
|
|
||||||
LOAD x28, 16*REGBYTES(sp) // Recover t3
|
|
||||||
LOAD x29, 15*REGBYTES(sp) // Recover t4
|
|
||||||
LOAD x30, 14*REGBYTES(sp) // Recover t5
|
|
||||||
LOAD x31, 13*REGBYTES(sp) // Recover t6
|
|
||||||
|
|
||||||
addi sp, sp, TX_INTERRUPT_FRAME_SIZE
|
|
||||||
mret // Return to point of interrupt
|
|
||||||
|
|
||||||
_tx_thread_synch_return:
|
|
||||||
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_LOAD f8, TX_SOLICITED_FP_OFFSET(0)(sp) // Recover fs0
|
|
||||||
TX_FP_LOAD f9, TX_SOLICITED_FP_OFFSET(1)(sp) // Recover fs1
|
|
||||||
TX_FP_LOAD f18, TX_SOLICITED_FP_OFFSET(2)(sp) // Recover fs2
|
|
||||||
TX_FP_LOAD f19, TX_SOLICITED_FP_OFFSET(3)(sp) // Recover fs3
|
|
||||||
TX_FP_LOAD f20, TX_SOLICITED_FP_OFFSET(4)(sp) // Recover fs4
|
|
||||||
TX_FP_LOAD f21, TX_SOLICITED_FP_OFFSET(5)(sp) // Recover fs5
|
|
||||||
TX_FP_LOAD f22, TX_SOLICITED_FP_OFFSET(6)(sp) // Recover fs6
|
|
||||||
TX_FP_LOAD f23, TX_SOLICITED_FP_OFFSET(7)(sp) // Recover fs7
|
|
||||||
TX_FP_LOAD f24, TX_SOLICITED_FP_OFFSET(8)(sp) // Recover fs8
|
|
||||||
TX_FP_LOAD f25, TX_SOLICITED_FP_OFFSET(9)(sp) // Recover fs9
|
|
||||||
TX_FP_LOAD f26, TX_SOLICITED_FP_OFFSET(10)(sp) // Recover fs10
|
|
||||||
TX_FP_LOAD f27, TX_SOLICITED_FP_OFFSET(11)(sp) // Recover fs11
|
|
||||||
LOAD t0, TX_SOLICITED_FCSR_OFFSET(sp) // Recover fcsr
|
|
||||||
csrw fcsr, t0 //
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Recover standard preserved registers. */
|
|
||||||
/* Recover standard registers. */
|
|
||||||
|
|
||||||
LOAD x1, 13*REGBYTES(sp) // Recover RA
|
|
||||||
LOAD x8, 12*REGBYTES(sp) // Recover s0
|
|
||||||
LOAD x9, 11*REGBYTES(sp) // Recover s1
|
|
||||||
LOAD x18, 10*REGBYTES(sp) // Recover s2
|
|
||||||
LOAD x19, 9*REGBYTES(sp) // Recover s3
|
|
||||||
LOAD x20, 8*REGBYTES(sp) // Recover s4
|
|
||||||
LOAD x21, 7*REGBYTES(sp) // Recover s5
|
|
||||||
LOAD x22, 6*REGBYTES(sp) // Recover s6
|
|
||||||
LOAD x23, 5*REGBYTES(sp) // Recover s7
|
|
||||||
LOAD x24, 4*REGBYTES(sp) // Recover s8
|
|
||||||
LOAD x25, 3*REGBYTES(sp) // Recover s9
|
|
||||||
LOAD x26, 2*REGBYTES(sp) // Recover s10
|
|
||||||
LOAD x27, 1*REGBYTES(sp) // Recover s11
|
|
||||||
LOAD t0, 14*REGBYTES(sp) // Recover mstatus
|
|
||||||
csrw mstatus, t0 // Store mstatus, enables interrupt
|
|
||||||
addi sp, sp, TX_SOLICITED_FRAME_SIZE
|
|
||||||
synch_return_exit_label:
|
|
||||||
ret // Return to thread
|
|
||||||
|
|
||||||
/* } */
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Thread */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_stack_build RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Scott Larson, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function builds a stack frame on the supplied thread's stack. */
|
|
||||||
/* The stack frame results in a fake interrupt return to the supplied */
|
|
||||||
/* function pointer. */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* thread_ptr Pointer to thread control blk */
|
|
||||||
/* function_ptr Pointer to return function */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_create Create thread service */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
/* VOID _tx_thread_stack_build(TX_THREAD *thread_ptr, VOID (*function_ptr)(VOID))
|
|
||||||
{ */
|
|
||||||
.global _tx_thread_stack_build
|
|
||||||
_tx_thread_stack_build:
|
|
||||||
|
|
||||||
/* Build a fake interrupt frame using this port's inc/tx_context_layout.h,
|
|
||||||
included through tx_port.h. Integer slot indices below are multiplied
|
|
||||||
by REGBYTES to obtain byte offsets from the saved stack pointer.
|
|
||||||
Reg Integer slot
|
|
||||||
Stack Top: 1 0 Interrupt stack frame type
|
|
||||||
x27 1 Initial s11
|
|
||||||
x26 2 Initial s10
|
|
||||||
x25 3 Initial s9
|
|
||||||
x24 4 Initial s8
|
|
||||||
x23 5 Initial s7
|
|
||||||
x22 6 Initial s6
|
|
||||||
x21 7 Initial s5
|
|
||||||
x20 8 Initial s4
|
|
||||||
x19 9 Initial s3
|
|
||||||
x18 10 Initial s2
|
|
||||||
x9 11 Initial s1
|
|
||||||
x8 12 Initial s0
|
|
||||||
x31 13 Initial t6
|
|
||||||
x30 14 Initial t5
|
|
||||||
x29 15 Initial t4
|
|
||||||
x28 16 Initial t3
|
|
||||||
x7 17 Initial t2
|
|
||||||
x6 18 Initial t1
|
|
||||||
x5 19 Initial t0
|
|
||||||
x17 20 Initial a7
|
|
||||||
x16 21 Initial a6
|
|
||||||
x15 22 Initial a5
|
|
||||||
x14 23 Initial a4
|
|
||||||
x13 24 Initial a3
|
|
||||||
x12 25 Initial a2
|
|
||||||
x11 26 Initial a1
|
|
||||||
x10 27 Initial a0
|
|
||||||
x1 28 Initial ra
|
|
||||||
-- 29 reserved
|
|
||||||
mepc 30 Initial mepc
|
|
||||||
-- 31 Alignment padding
|
|
||||||
|
|
||||||
With FP support, f0..f31 follow at TX_INTERRUPT_FP_BASE. Each register
|
|
||||||
occupies TX_FP_BYTES bytes; fN is at TX_INTERRUPT_FP_OFFSET(N). The
|
|
||||||
fcsr slot is at TX_INTERRUPT_FCSR_OFFSET and occupies REGBYTES bytes.
|
|
||||||
Trailing padding rounds the frame size up to a multiple of 16 bytes.
|
|
||||||
Without FP support, the frame ends after integer slot 31.
|
|
||||||
|
|
||||||
Stack Bottom: saved stack pointer + TX_INTERRUPT_FRAME_SIZE
|
|
||||||
(higher memory address) */
|
|
||||||
|
|
||||||
LOAD t0, 4*REGBYTES(a0) // Pickup end of stack area
|
|
||||||
andi t0, t0, -16 // Ensure 16-byte alignment
|
|
||||||
|
|
||||||
/* Actually build the stack frame. */
|
|
||||||
|
|
||||||
addi t0, t0, -TX_INTERRUPT_FRAME_SIZE
|
|
||||||
/* Clear the whole frame, including both halves of RV32D FP slots. */
|
|
||||||
mv t1, t0
|
|
||||||
addi t2, t0, TX_INTERRUPT_FRAME_SIZE
|
|
||||||
.Lclear_initial_context:
|
|
||||||
STORE x0, 0(t1)
|
|
||||||
addi t1, t1, REGBYTES
|
|
||||||
bltu t1, t2, .Lclear_initial_context
|
|
||||||
|
|
||||||
li t1, 1 // Build stack type
|
|
||||||
STORE t1, 0*REGBYTES(t0) // Place stack type on the top
|
|
||||||
STORE a1, 30*REGBYTES(t0) // Initial mepc
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
csrr a1, fcsr
|
|
||||||
STORE a1, TX_INTERRUPT_FCSR_OFFSET(t0) // Initial fcsr
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Setup stack pointer. */
|
|
||||||
/* thread_ptr -> tx_thread_stack_ptr = t0; */
|
|
||||||
|
|
||||||
STORE t0, 2*REGBYTES(a0) // Save stack pointer in thread's
|
|
||||||
ret // control block and return
|
|
||||||
/* } */
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Thread */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_system_return RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Scott Larson, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function is target processor specific. It is used to transfer */
|
|
||||||
/* control from a thread back to the system. Only a minimal context */
|
|
||||||
/* is saved since the compiler assumes temp registers are going to get */
|
|
||||||
/* slicked by a function call anyway. */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_schedule Thread scheduling loop */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* ThreadX components */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
/* VOID _tx_thread_system_return(VOID)
|
|
||||||
{ */
|
|
||||||
.global _tx_thread_system_return
|
|
||||||
_tx_thread_system_return:
|
|
||||||
|
|
||||||
/* Save minimal context on the stack. */
|
|
||||||
|
|
||||||
addi sp, sp, -TX_SOLICITED_FRAME_SIZE
|
|
||||||
|
|
||||||
/* Store floating point preserved registers. */
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_STORE f8, TX_SOLICITED_FP_OFFSET(0)(sp) // Store fs0
|
|
||||||
TX_FP_STORE f9, TX_SOLICITED_FP_OFFSET(1)(sp) // Store fs1
|
|
||||||
TX_FP_STORE f18, TX_SOLICITED_FP_OFFSET(2)(sp) // Store fs2
|
|
||||||
TX_FP_STORE f19, TX_SOLICITED_FP_OFFSET(3)(sp) // Store fs3
|
|
||||||
TX_FP_STORE f20, TX_SOLICITED_FP_OFFSET(4)(sp) // Store fs4
|
|
||||||
TX_FP_STORE f21, TX_SOLICITED_FP_OFFSET(5)(sp) // Store fs5
|
|
||||||
TX_FP_STORE f22, TX_SOLICITED_FP_OFFSET(6)(sp) // Store fs6
|
|
||||||
TX_FP_STORE f23, TX_SOLICITED_FP_OFFSET(7)(sp) // Store fs7
|
|
||||||
TX_FP_STORE f24, TX_SOLICITED_FP_OFFSET(8)(sp) // Store fs8
|
|
||||||
TX_FP_STORE f25, TX_SOLICITED_FP_OFFSET(9)(sp) // Store fs9
|
|
||||||
TX_FP_STORE f26, TX_SOLICITED_FP_OFFSET(10)(sp) // Store fs10
|
|
||||||
TX_FP_STORE f27, TX_SOLICITED_FP_OFFSET(11)(sp) // Store fs11
|
|
||||||
csrr t0, fcsr
|
|
||||||
STORE t0, TX_SOLICITED_FCSR_OFFSET(sp) // Store fcsr
|
|
||||||
#endif
|
|
||||||
|
|
||||||
STORE x0, 0(sp) // Solicited stack type
|
|
||||||
STORE x1, 13*REGBYTES(sp) // Save RA
|
|
||||||
STORE x8, 12*REGBYTES(sp) // Save s0
|
|
||||||
STORE x9, 11*REGBYTES(sp) // Save s1
|
|
||||||
STORE x18, 10*REGBYTES(sp) // Save s2
|
|
||||||
STORE x19, 9*REGBYTES(sp) // Save s3
|
|
||||||
STORE x20, 8*REGBYTES(sp) // Save s4
|
|
||||||
STORE x21, 7*REGBYTES(sp) // Save s5
|
|
||||||
STORE x22, 6*REGBYTES(sp) // Save s6
|
|
||||||
STORE x23, 5*REGBYTES(sp) // Save s7
|
|
||||||
STORE x24, 4*REGBYTES(sp) // Save s8
|
|
||||||
STORE x25, 3*REGBYTES(sp) // Save s9
|
|
||||||
STORE x26, 2*REGBYTES(sp) // Save s10
|
|
||||||
STORE x27, 1*REGBYTES(sp) // Save s11
|
|
||||||
csrr t0, mstatus // Pickup mstatus
|
|
||||||
STORE t0, 14*REGBYTES(sp) // Save mstatus
|
|
||||||
|
|
||||||
|
|
||||||
/* Lockout interrupts. - will be enabled in _tx_thread_schedule */
|
|
||||||
|
|
||||||
csrci mstatus, 0xF
|
|
||||||
|
|
||||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
|
||||||
|
|
||||||
call _tx_execution_thread_exit // Call the thread execution exit function
|
|
||||||
#endif
|
|
||||||
|
|
||||||
la t0, _tx_thread_current_ptr // Pickup address of pointer
|
|
||||||
LOAD t1, 0(t0) // Pickup current thread pointer
|
|
||||||
la t2,_tx_thread_system_stack_ptr // Pickup stack pointer address
|
|
||||||
|
|
||||||
/* Save current stack and switch to system stack. */
|
|
||||||
/* _tx_thread_current_ptr -> tx_thread_stack_ptr = SP;
|
|
||||||
SP = _tx_thread_system_stack_ptr; */
|
|
||||||
|
|
||||||
STORE sp, 2*REGBYTES(t1) // Save stack pointer
|
|
||||||
LOAD sp, 0(t2) // Switch to system stack
|
|
||||||
|
|
||||||
/* Determine if the time-slice is active. */
|
|
||||||
/* if (_tx_timer_time_slice)
|
|
||||||
{ */
|
|
||||||
|
|
||||||
la t4, _tx_timer_time_slice // Pickup time slice variable addr
|
|
||||||
LOAD t3, 0(t4) // Pickup time slice value
|
|
||||||
la t2, _tx_thread_schedule // Pickup address of scheduling loop
|
|
||||||
beqz t3, _tx_thread_dont_save_ts // If no time-slice, don't save it
|
|
||||||
|
|
||||||
/* Save time-slice for the thread and clear the current time-slice. */
|
|
||||||
/* _tx_thread_current_ptr -> tx_thread_time_slice = _tx_timer_time_slice;
|
|
||||||
_tx_timer_time_slice = 0; */
|
|
||||||
|
|
||||||
STORE t3, 6*REGBYTES(t1) // Save current time-slice for thread
|
|
||||||
STORE x0, 0(t4) // Clear time-slice variable
|
|
||||||
|
|
||||||
/* } */
|
|
||||||
_tx_thread_dont_save_ts:
|
|
||||||
|
|
||||||
/* Clear the current thread pointer. */
|
|
||||||
/* _tx_thread_current_ptr = TX_NULL; */
|
|
||||||
|
|
||||||
STORE x0, 0(t0) // Clear current thread pointer
|
|
||||||
jr t2 // Return to thread scheduler
|
|
||||||
|
|
||||||
/* } */
|
|
||||||
@@ -1,134 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Timer */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
#define TX_SOURCE_CODE
|
|
||||||
|
|
||||||
/* Include necessary system files. */
|
|
||||||
|
|
||||||
#include "tx_api.h"
|
|
||||||
#include "tx_timer.h"
|
|
||||||
#include "tx_thread.h"
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* _tx_timer_interrupt RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Scott Larson, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function processes the hardware timer interrupt. This */
|
|
||||||
/* processing includes incrementing the system clock and checking for */
|
|
||||||
/* time slice and/or timer expiration. If either is found, the */
|
|
||||||
/* interrupt context save/restore functions are called along with the */
|
|
||||||
/* expiration functions. */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* _tx_timer_expiration_process Timer expiration processing */
|
|
||||||
/* _tx_thread_time_slice Time slice interrupted thread */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* interrupt vector */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
VOID _tx_timer_interrupt(VOID)
|
|
||||||
{
|
|
||||||
/* Increment system clock. */
|
|
||||||
_tx_timer_system_clock++;
|
|
||||||
|
|
||||||
/* Test for time-slice expiration. */
|
|
||||||
if (_tx_timer_time_slice)
|
|
||||||
{
|
|
||||||
/* Decrement the time_slice. */
|
|
||||||
_tx_timer_time_slice--;
|
|
||||||
|
|
||||||
/* Check for expiration. */
|
|
||||||
if (_tx_timer_time_slice == 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Set the time-slice expired flag. */
|
|
||||||
_tx_timer_expired_time_slice = TX_TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test for timer expiration. */
|
|
||||||
if (*_tx_timer_current_ptr)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Set expiration flag. */
|
|
||||||
_tx_timer_expired = TX_TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
/* No timer expired, increment the timer pointer. */
|
|
||||||
_tx_timer_current_ptr++;
|
|
||||||
|
|
||||||
/* Check for wrap-around. */
|
|
||||||
if (_tx_timer_current_ptr == _tx_timer_list_end)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Wrap to beginning of list. */
|
|
||||||
_tx_timer_current_ptr = _tx_timer_list_start;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* See if anything has expired. */
|
|
||||||
if ((_tx_timer_expired_time_slice) || (_tx_timer_expired))
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Did a timer expire? */
|
|
||||||
if (_tx_timer_expired)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Process timer expiration. */
|
|
||||||
_tx_timer_expiration_process();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Did time slice expire? */
|
|
||||||
if (_tx_timer_expired_time_slice)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Time slice interrupted thread. */
|
|
||||||
_tx_thread_time_slice();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+14
-239
@@ -1,246 +1,21 @@
|
|||||||
cmake_minimum_required(VERSION 3.24)
|
cmake_minimum_required(VERSION 3.24)
|
||||||
project(smp_demo LANGUAGES C ASM)
|
project(threadx_smp LANGUAGES C ASM)
|
||||||
|
|
||||||
set(THREADX_COMMON_SMP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../third-party/threadx/common_smp)
|
get_filename_component(THREADX_SMP_SUBMODULE_DIR
|
||||||
if(NOT EXISTS "${THREADX_COMMON_SMP_DIR}")
|
"${CMAKE_CURRENT_LIST_DIR}/../../third-party/threadx" ABSOLUTE)
|
||||||
message(FATAL_ERROR "could not find ThreadX SMP sources, is the submodule checked out?")
|
set(THREADX_COMMON_SMP_DIR "${THREADX_SMP_SUBMODULE_DIR}/common_smp")
|
||||||
endif()
|
set(THREADX_SMP_GNU_PORT "${THREADX_SMP_SUBMODULE_DIR}/ports_smp/${THREADX_ARCH}_smp/gnu")
|
||||||
|
|
||||||
set(THREADX_SMP_CUSTOM_INC
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/inc
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../moonlight/inc # needed for Moonlight SMP support headers
|
|
||||||
)
|
|
||||||
|
|
||||||
#required for tests to hook into the ISR path
|
|
||||||
if(NOT DEFINED THREADX_LOW_LEVEL_INIT_SOURCE)
|
|
||||||
set(THREADX_LOW_LEVEL_INIT_SOURCE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/tx_initialize_low_level.c)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(THREADX_SMP_CUSTOM_SRC
|
|
||||||
src/trap_entry.S
|
|
||||||
${THREADX_LOW_LEVEL_INIT_SOURCE}
|
|
||||||
src/tx_thread_context_restore.S
|
|
||||||
src/tx_thread_context_save.S
|
|
||||||
src/tx_thread_interrupt_control.S
|
|
||||||
src/tx_thread_schedule.S
|
|
||||||
src/tx_thread_smp_core_get.S
|
|
||||||
src/tx_thread_smp_core_preempt.c
|
|
||||||
src/tx_thread_smp_current_state_get.S
|
|
||||||
src/tx_thread_smp_current_thread_get.S
|
|
||||||
src/tx_thread_smp_initialize_wait.S
|
|
||||||
src/tx_thread_smp_low_level_initialize.S
|
|
||||||
src/tx_thread_smp_protect.S
|
|
||||||
src/tx_thread_smp_unprotect.S
|
|
||||||
src/tx_thread_stack_build.S
|
|
||||||
src/tx_thread_system_return.S
|
|
||||||
src/tx_timer_interrupt.c
|
|
||||||
)
|
|
||||||
|
|
||||||
set(THREADX_SMP_SOURCES
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_block_allocate.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_block_pool_cleanup.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_block_pool_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_block_pool_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_block_pool_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_block_pool_initialize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_block_pool_performance_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_block_pool_performance_system_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_block_pool_prioritize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_block_release.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_byte_allocate.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_byte_pool_cleanup.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_byte_pool_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_byte_pool_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_byte_pool_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_byte_pool_initialize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_byte_pool_performance_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_byte_pool_performance_system_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_byte_pool_prioritize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_byte_pool_search.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_byte_release.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_block_allocate.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_block_pool_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_block_pool_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_block_pool_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_block_pool_prioritize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_block_release.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_byte_allocate.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_byte_pool_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_byte_pool_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_byte_pool_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_byte_pool_prioritize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_byte_release.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_event_flags_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_event_flags_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_event_flags_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_event_flags_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_event_flags_set.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_event_flags_set_notify.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_mutex_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_mutex_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_mutex_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_mutex_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_mutex_prioritize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_mutex_put.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_queue_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_queue_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_queue_flush.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_queue_front_send.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_queue_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_queue_prioritize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_queue_receive.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_queue_send.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_queue_send_notify.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_semaphore_ceiling_put.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_semaphore_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_semaphore_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_semaphore_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_semaphore_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_semaphore_prioritize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_semaphore_put.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_semaphore_put_notify.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_thread_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_thread_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_thread_entry_exit_notify.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_thread_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_thread_preemption_change.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_thread_priority_change.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_thread_relinquish.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_thread_reset.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_thread_resume.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_thread_suspend.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_thread_terminate.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_thread_time_slice_change.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_thread_wait_abort.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_timer_activate.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_timer_change.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_timer_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_timer_deactivate.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_timer_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/txe_timer_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_event_flags_cleanup.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_event_flags_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_event_flags_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_event_flags_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_event_flags_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_event_flags_initialize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_event_flags_performance_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_event_flags_performance_system_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_event_flags_set.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_event_flags_set_notify.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_initialize_high_level.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_initialize_kernel_enter.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_initialize_kernel_setup.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_misra.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_mutex_cleanup.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_mutex_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_mutex_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_mutex_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_mutex_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_mutex_initialize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_mutex_performance_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_mutex_performance_system_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_mutex_prioritize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_mutex_priority_change.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_mutex_put.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_queue_cleanup.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_queue_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_queue_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_queue_flush.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_queue_front_send.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_queue_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_queue_initialize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_queue_performance_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_queue_performance_system_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_queue_prioritize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_queue_receive.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_queue_send.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_queue_send_notify.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_semaphore_ceiling_put.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_semaphore_cleanup.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_semaphore_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_semaphore_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_semaphore_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_semaphore_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_semaphore_initialize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_semaphore_performance_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_semaphore_performance_system_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_semaphore_prioritize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_semaphore_put.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_semaphore_put_notify.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_entry_exit_notify.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_identify.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_initialize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_performance_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_performance_system_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_preemption_change.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_priority_change.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_relinquish.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_reset.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_resume.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_shell_entry.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_sleep.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_smp_core_exclude.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_smp_core_exclude_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_smp_current_state_set.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_smp_debug_entry_insert.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_smp_high_level_initialize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_smp_rebalance_execute_list.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_smp_utilities.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_stack_analyze.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_stack_error_handler.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_stack_error_notify.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_suspend.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_system_preempt_check.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_system_resume.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_system_suspend.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_terminate.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_timeout.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_time_slice.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_time_slice_change.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_thread_wait_abort.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_time_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_timer_activate.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_timer_change.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_timer_create.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_timer_deactivate.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_timer_delete.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_timer_expiration_process.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_timer_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_timer_initialize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_timer_performance_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_timer_performance_system_info_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_timer_smp_core_exclude.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_timer_smp_core_exclude_get.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_timer_system_activate.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_timer_system_deactivate.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_timer_thread_entry.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_time_set.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_trace_buffer_full_notify.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_trace_disable.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_trace_enable.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_trace_event_filter.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_trace_event_unfilter.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_trace_initialize.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_trace_interrupt_control.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_trace_isr_enter_insert.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_trace_isr_exit_insert.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_trace_object_register.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_trace_object_unregister.c
|
|
||||||
${THREADX_COMMON_SMP_DIR}/src/tx_trace_user_event_insert.c
|
|
||||||
)
|
|
||||||
|
|
||||||
add_library(threadx_smp STATIC)
|
add_library(threadx_smp STATIC)
|
||||||
target_sources(threadx_smp PRIVATE
|
target_sources(threadx_smp PRIVATE
|
||||||
${THREADX_SMP_SOURCES}
|
../threadx/src/trap_entry.S
|
||||||
${THREADX_SMP_CUSTOM_SRC}
|
src/tx_initialize_low_level.c
|
||||||
)
|
)
|
||||||
target_include_directories(threadx_smp PUBLIC
|
target_include_directories(threadx_smp
|
||||||
${THREADX_COMMON_SMP_DIR}/inc
|
PUBLIC "${CMAKE_CURRENT_LIST_DIR}/inc"
|
||||||
${THREADX_SMP_CUSTOM_INC}
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../moonlight/inc"
|
||||||
)
|
)
|
||||||
target_compile_definitions(threadx_smp PRIVATE TX_QUEUE_MESSAGE_MAX_SIZE=16) #This is addressed in PR #503
|
target_compile_definitions(threadx_smp PUBLIC TX_INCLUDE_USER_DEFINE_FILE TX_MPCORE)
|
||||||
|
|
||||||
|
add_subdirectory("${THREADX_SMP_GNU_PORT}" upstream_port)
|
||||||
|
add_subdirectory("${THREADX_COMMON_SMP_DIR}" upstream_common)
|
||||||
@@ -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}")
|
|
||||||
@@ -1,371 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
#ifndef CSR_H
|
|
||||||
#define CSR_H
|
|
||||||
|
|
||||||
// Machine Status Register, mstatus
|
|
||||||
#define MSTATUS_MPP_MASK (3L << 11) // previous mode.
|
|
||||||
#define MSTATUS_MPP_M (3L << 11)
|
|
||||||
#define MSTATUS_MPP_S (1L << 11)
|
|
||||||
#define MSTATUS_MPP_U (0L << 11)
|
|
||||||
#define MSTATUS_MIE (1L << 3) // machine-mode interrupt enable.
|
|
||||||
#define MSTATUS_MPIE (1L << 7)
|
|
||||||
#define MSTATUS_FS (1L << 13)
|
|
||||||
|
|
||||||
// Machine-mode Interrupt Enable
|
|
||||||
#define MIE_MTIE (1L << 7)
|
|
||||||
#define MIE_MSIE (1L << 3)
|
|
||||||
#define MIE_MEIE (1L << 11)
|
|
||||||
#define MIE_STIE (1L << 5) // supervisor timer
|
|
||||||
#define MIE_SSIE (1L << 1)
|
|
||||||
#define MIE_SEIE (1L << 9)
|
|
||||||
|
|
||||||
// Supervisor Status Register, sstatus
|
|
||||||
#define SSTATUS_SPP (1L << 8) // Previous mode, 1=Supervisor, 0=User
|
|
||||||
#define SSTATUS_SPIE (1L << 5) // Supervisor Previous Interrupt Enable
|
|
||||||
#define SSTATUS_UPIE (1L << 4) // User Previous Interrupt Enable
|
|
||||||
#define SSTATUS_SIE (1L << 1) // Supervisor Interrupt Enable
|
|
||||||
#define SSTATUS_UIE (1L << 0) // User Interrupt Enable
|
|
||||||
#define SSTATUS_SPIE (1L << 5)
|
|
||||||
#define SSTATUS_UPIE (1L << 4)
|
|
||||||
|
|
||||||
// Supervisor Interrupt Enable
|
|
||||||
#define SIE_SEIE (1L << 9) // external
|
|
||||||
#define SIE_STIE (1L << 5) // timer
|
|
||||||
#define SIE_SSIE (1L << 1) // software
|
|
||||||
|
|
||||||
#ifndef __ASSEMBLER__
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_core()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, mhartid" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_mstatus()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, mstatus" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_mstatus(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw mstatus, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// machine exception program counter, holds the
|
|
||||||
// instruction address to which a return from
|
|
||||||
// exception will go.
|
|
||||||
static inline void riscv_writ_mepc(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw mepc, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_sstatus()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, sstatus" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_sstatus(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw sstatus, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supervisor Interrupt Pending
|
|
||||||
static inline uint64_t riscv_get_sip()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, sip" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_sip(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw sip, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_sie()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, sie" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_sie(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw sie, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_mie()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, mie" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_mie(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw mie, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// supervisor exception program counter, holds the
|
|
||||||
// instruction address to which a return from
|
|
||||||
// exception will go.
|
|
||||||
static inline void riscv_writ_sepc(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw sepc, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_sepc()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, sepc" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Machine Exception Delegation
|
|
||||||
static inline uint64_t riscv_get_medeleg()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, medeleg" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_medeleg(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw medeleg, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Machine Interrupt Delegation
|
|
||||||
static inline uint64_t riscv_get_mideleg()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, mideleg" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_mideleg(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw mideleg, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supervisor Trap-Vector Base Address
|
|
||||||
// low two bits are mode.
|
|
||||||
static inline void riscv_writ_stvec(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw stvec, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_stvec()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, stvec" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supervisor Timer Comparison Register
|
|
||||||
static inline uint64_t riscv_get_stimecmp()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
// asm volatile("csrr %0, stimecmp" : "=r" (x) );
|
|
||||||
asm volatile("csrr %0, 0x14d" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_stimecmp(uint64_t x)
|
|
||||||
{
|
|
||||||
// asm volatile("csrw stimecmp, %0" : : "r" (x));
|
|
||||||
asm volatile("csrw 0x14d, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Machine Environment Configuration Register
|
|
||||||
static inline uint64_t riscv_get_menvcfg()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
// asm volatile("csrr %0, menvcfg" : "=r" (x) );
|
|
||||||
asm volatile("csrr %0, 0x30a" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_menvcfg(uint64_t x)
|
|
||||||
{
|
|
||||||
// asm volatile("csrw menvcfg, %0" : : "r" (x));
|
|
||||||
asm volatile("csrw 0x30a, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Physical Memory Protection
|
|
||||||
static inline void riscv_writ_pmpcfg0(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw pmpcfg0, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_pmpaddr0(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw pmpaddr0, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// supervisor address translation and protection;
|
|
||||||
// holds the address of the page table.
|
|
||||||
static inline void riscv_writ_satp(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw satp, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_satp()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, satp" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supervisor Trap Cause
|
|
||||||
static inline uint64_t riscv_get_scause()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, scause" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supervisor Trap Value
|
|
||||||
static inline uint64_t riscv_get_stval()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, stval" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Machine-mode Counter-Enable
|
|
||||||
static inline void riscv_writ_mcounteren(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("csrw mcounteren, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_mcounteren()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, mcounteren" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// machine-mode cycle counter
|
|
||||||
static inline uint64_t riscv_get_time()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("csrr %0, time" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable device interrupts
|
|
||||||
static inline void riscv_sintr_on()
|
|
||||||
{
|
|
||||||
uint64_t sstatus = riscv_get_sstatus();
|
|
||||||
sstatus |= SSTATUS_SIE;
|
|
||||||
riscv_writ_sstatus(sstatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
// disable device interrupts
|
|
||||||
static inline void riscv_sintr_off()
|
|
||||||
{
|
|
||||||
uint64_t sstatus = riscv_get_sstatus();
|
|
||||||
sstatus &= (~SSTATUS_SIE);
|
|
||||||
riscv_writ_sstatus(sstatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
// are device interrupts enabled?
|
|
||||||
static inline int riscv_sintr_get()
|
|
||||||
{
|
|
||||||
uint64_t x = riscv_get_sstatus();
|
|
||||||
return (x & SSTATUS_SIE) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_sintr_restore(int x)
|
|
||||||
{
|
|
||||||
if (x)
|
|
||||||
riscv_sintr_on();
|
|
||||||
else
|
|
||||||
riscv_sintr_off();
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable device interrupts
|
|
||||||
static inline void riscv_mintr_on()
|
|
||||||
{
|
|
||||||
uint64_t mstatus = riscv_get_mstatus();
|
|
||||||
mstatus |= MSTATUS_MIE;
|
|
||||||
riscv_writ_mstatus(mstatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
// disable device interrupts
|
|
||||||
static inline void riscv_mintr_off()
|
|
||||||
{
|
|
||||||
uint64_t mstatus = riscv_get_mstatus();
|
|
||||||
mstatus &= (~MSTATUS_MIE);
|
|
||||||
riscv_writ_mstatus(mstatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
// are device interrupts enabled?
|
|
||||||
static inline int riscv_mintr_get()
|
|
||||||
{
|
|
||||||
uint64_t x = riscv_get_mstatus();
|
|
||||||
return (x & MSTATUS_MIE) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_mintr_restore(int x)
|
|
||||||
{
|
|
||||||
if (x)
|
|
||||||
riscv_mintr_on();
|
|
||||||
else
|
|
||||||
riscv_mintr_off();
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_sp()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("mv %0, sp" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// read and write tp, the thread pointer, which xv6 uses to hold
|
|
||||||
// this core's hartid (core number), the index into cpus[].
|
|
||||||
static inline uint64_t riscv_get_tp()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("mv %0, tp" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void riscv_writ_tp(uint64_t x)
|
|
||||||
{
|
|
||||||
asm volatile("mv tp, %0" : : "r"(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t riscv_get_ra()
|
|
||||||
{
|
|
||||||
uint64_t x;
|
|
||||||
asm volatile("mv %0, ra" : "=r"(x));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// flush the TLB.
|
|
||||||
static inline void sfence_vma()
|
|
||||||
{
|
|
||||||
// the zero, zero means flush all TLB entries.
|
|
||||||
asm volatile("sfence.vma zero, zero");
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // __ASSEMBLER__
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,500 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Port Specific */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* PORT SPECIFIC C INFORMATION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* tx_port.h ARMv8-A-SMP */
|
|
||||||
/* 6.1.10 */
|
|
||||||
/* */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* William E. Lamie, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This file contains data type definitions that make the ThreadX */
|
|
||||||
/* real-time kernel function identically on a variety of different */
|
|
||||||
/* processor architectures. For example, the size or number of bits */
|
|
||||||
/* in an "int" data type vary between microprocessor architectures and */
|
|
||||||
/* even C compilers for the same microprocessor. ThreadX does not */
|
|
||||||
/* directly use native C data types. Instead, ThreadX creates its */
|
|
||||||
/* own special types that can be mapped to actual data types by this */
|
|
||||||
/* file to guarantee consistency in the interface and functionality. */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
|
|
||||||
/* 01-31-2022 Bhupendra Naphade Modified comment(s),updated */
|
|
||||||
/* macro definition, */
|
|
||||||
/* resulting in version 6.1.10 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
#ifndef TX_PORT_H
|
|
||||||
#define TX_PORT_H
|
|
||||||
|
|
||||||
#ifdef __ASSEMBLER__
|
|
||||||
|
|
||||||
#if __riscv_xlen == 64
|
|
||||||
#define SLL32 sllw
|
|
||||||
#define STORE sd
|
|
||||||
#define LOAD ld
|
|
||||||
#define LWU lwu
|
|
||||||
#define AMOSWAP_AQ amoswap.d.aq
|
|
||||||
#define AMOSWAP_RL amoswap.d.rl
|
|
||||||
#define LOG_REGBYTES 3
|
|
||||||
#define TX_THREAD_SMP_LOCK_READY_BIT_OFFSET 312 // This changes if thread or timer internal extensions are used
|
|
||||||
#else
|
|
||||||
#define SLL32 sll
|
|
||||||
#define STORE sw
|
|
||||||
#define LOAD lw
|
|
||||||
#define LWU lw
|
|
||||||
#define AMOSWAP_AQ amoswap.w.aq
|
|
||||||
#define AMOSWAP_RL amoswap.w.rl
|
|
||||||
#define LOG_REGBYTES 2
|
|
||||||
#define TX_THREAD_SMP_LOCK_READY_BIT_OFFSET 168 // This changes if thread or timer internal extensions are used
|
|
||||||
#endif
|
|
||||||
#define REGBYTES (1 << LOG_REGBYTES)
|
|
||||||
|
|
||||||
#define TX_CONTEXT_ALIGN(size) (((size) + 15) & -16)
|
|
||||||
|
|
||||||
/* Keep the existing hard-float enable policy. Save the full hardware register
|
|
||||||
* width, even when the calling convention uses narrower floating-point values.
|
|
||||||
*/
|
|
||||||
#if defined(__riscv_float_abi_single) || defined(__riscv_float_abi_double)
|
|
||||||
#define TX_CONTEXT_FP_ENABLED 1
|
|
||||||
#if __riscv_flen == 64
|
|
||||||
#define TX_FP_BYTES 8
|
|
||||||
#define TX_FP_LOAD fld
|
|
||||||
#define TX_FP_STORE fsd
|
|
||||||
#elif __riscv_flen == 32
|
|
||||||
#define TX_FP_BYTES 4
|
|
||||||
#define TX_FP_LOAD flw
|
|
||||||
#define TX_FP_STORE fsw
|
|
||||||
#else
|
|
||||||
#error "Unsupported RISC-V floating-point register width"
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define TX_CONTEXT_FP_ENABLED 0
|
|
||||||
#define TX_FP_BYTES 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Integer slots 0..30 contain the interrupt context; slot 31 is padding.
|
|
||||||
* Voluntary switches use slots 0..14; slot 15 is padding. Starting the FP
|
|
||||||
* areas at these boundaries aligns double registers on RV32 as well as RV64.
|
|
||||||
*/
|
|
||||||
#define TX_INTERRUPT_FP_BASE (32 * REGBYTES)
|
|
||||||
#define TX_SOLICITED_FP_BASE (16 * REGBYTES)
|
|
||||||
#define TX_INTERRUPT_FP_OFFSET(n) (TX_INTERRUPT_FP_BASE + (n) * TX_FP_BYTES)
|
|
||||||
/* Solicited FP indices: fs0, fs1, fs2, ... fs11 (not architectural numbers). */
|
|
||||||
#define TX_SOLICITED_FP_OFFSET(n) (TX_SOLICITED_FP_BASE + (n) * TX_FP_BYTES)
|
|
||||||
#define TX_INTERRUPT_FCSR_OFFSET TX_INTERRUPT_FP_OFFSET(32)
|
|
||||||
#define TX_SOLICITED_FCSR_OFFSET TX_SOLICITED_FP_OFFSET(12)
|
|
||||||
|
|
||||||
/* fcsr follows the FP registers and occupies one REGBYTES slot because
|
|
||||||
* it is accessed with integer LOAD/STORE. Round the complete frame up to
|
|
||||||
* 16 bytes so allocating or releasing it preserves stack alignment. Without
|
|
||||||
* FP support, the frame contains only the integer slots and their padding.
|
|
||||||
*/
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
#define TX_INTERRUPT_FRAME_SIZE TX_CONTEXT_ALIGN(TX_INTERRUPT_FCSR_OFFSET + REGBYTES)
|
|
||||||
#define TX_SOLICITED_FRAME_SIZE TX_CONTEXT_ALIGN(TX_SOLICITED_FCSR_OFFSET + REGBYTES)
|
|
||||||
#else
|
|
||||||
#define TX_INTERRUPT_FRAME_SIZE TX_INTERRUPT_FP_BASE
|
|
||||||
#define TX_SOLICITED_FRAME_SIZE TX_SOLICITED_FP_BASE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#else /*not __ASSEMBLER__ */
|
|
||||||
|
|
||||||
/************* Define ThreadX SMP constants. *************/
|
|
||||||
|
|
||||||
#define TX_DISABLE_INLINE
|
|
||||||
|
|
||||||
/* Define the ThreadX SMP maximum number of cores. */
|
|
||||||
|
|
||||||
#ifndef TX_THREAD_SMP_MAX_CORES
|
|
||||||
#define TX_THREAD_SMP_MAX_CORES 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define the ThreadX SMP core mask. */
|
|
||||||
|
|
||||||
#ifndef TX_THREAD_SMP_CORE_MASK
|
|
||||||
#define TX_THREAD_SMP_CORE_MASK 0xF /* Where bit 0 represents Core 0, bit 1 represents Core 1, etc. */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Declare ThreadX to discover the cores dynamically. The ceiling is given by TX_THREAD_SMP_MAX_CORES */
|
|
||||||
/*
|
|
||||||
The current implementation does not support dynamic discovery, but simply set the runtime determined number to
|
|
||||||
TX_THREAD_SMP_MAX_CORES. See tx_thread_smp_low_level_initialize.S
|
|
||||||
#define TX_THREAD_SMP_DYNAMIC_CORE_MAX
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Define INLINE_DECLARE */
|
|
||||||
|
|
||||||
#define INLINE_DECLARE inline
|
|
||||||
|
|
||||||
/* Define ThreadX SMP initialization macro. */
|
|
||||||
|
|
||||||
#define TX_PORT_SPECIFIC_PRE_INITIALIZATION
|
|
||||||
|
|
||||||
/* Define ThreadX SMP pre-scheduler initialization. */
|
|
||||||
|
|
||||||
#define TX_PORT_SPECIFIC_PRE_SCHEDULER_INITIALIZATION
|
|
||||||
|
|
||||||
/* Enable the inter-core interrupt logic. */
|
|
||||||
|
|
||||||
#define TX_THREAD_SMP_INTER_CORE_INTERRUPT
|
|
||||||
|
|
||||||
/* Use default wakeup logic*/
|
|
||||||
|
|
||||||
#define TX_THREAD_SMP_DEFAULT_WAKEUP_LOGIC
|
|
||||||
|
|
||||||
/* Determine if there is customer-specific wakeup logic needed. */
|
|
||||||
|
|
||||||
#ifdef TX_THREAD_SMP_WAKEUP_LOGIC
|
|
||||||
|
|
||||||
/* Include customer-specific wakeup code. */
|
|
||||||
|
|
||||||
#include "tx_thread_smp_core_wakeup.h"
|
|
||||||
#else
|
|
||||||
|
|
||||||
#ifdef TX_THREAD_SMP_DEFAULT_WAKEUP_LOGIC
|
|
||||||
|
|
||||||
/* Default wakeup code. */
|
|
||||||
#define TX_THREAD_SMP_WAKEUP_LOGIC
|
|
||||||
#define TX_THREAD_SMP_WAKEUP(i) _tx_thread_smp_core_preempt(i)
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Ensure that the in-line resume/suspend define is not allowed. */
|
|
||||||
|
|
||||||
#ifdef TX_INLINE_THREAD_RESUME_SUSPEND
|
|
||||||
#undef TX_INLINE_THREAD_RESUME_SUSPEND
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/************* End ThreadX SMP constants. *************/
|
|
||||||
|
|
||||||
/* Determine if the optional ThreadX user define file should be used. */
|
|
||||||
|
|
||||||
#ifdef TX_INCLUDE_USER_DEFINE_FILE
|
|
||||||
|
|
||||||
/* Yes, include the user defines in tx_user.h. The defines in this file may
|
|
||||||
alternately be defined on the command line. */
|
|
||||||
|
|
||||||
#include "tx_user.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define compiler library include files. */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
/* Define ThreadX basic types for this port. */
|
|
||||||
|
|
||||||
#define VOID void
|
|
||||||
typedef char CHAR;
|
|
||||||
typedef unsigned char UCHAR;
|
|
||||||
typedef int INT;
|
|
||||||
typedef unsigned int UINT;
|
|
||||||
typedef int LONG;
|
|
||||||
typedef unsigned long ULONG;
|
|
||||||
typedef unsigned long long ULONG64;
|
|
||||||
typedef short SHORT;
|
|
||||||
typedef unsigned short USHORT;
|
|
||||||
#define ULONG64_DEFINED
|
|
||||||
|
|
||||||
/* Define the priority levels for ThreadX. Legal values range
|
|
||||||
from 32 to 1024 and MUST be evenly divisible by 32. */
|
|
||||||
|
|
||||||
#ifndef TX_MAX_PRIORITIES
|
|
||||||
#define TX_MAX_PRIORITIES 32
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define the minimum stack for a ThreadX thread on this processor. If the size supplied during
|
|
||||||
thread creation is less than this value, the thread create call will return an error. */
|
|
||||||
|
|
||||||
#ifndef TX_MINIMUM_STACK
|
|
||||||
#define TX_MINIMUM_STACK 1024 /* Minimum stack size for this port */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define the system timer thread's default stack size and priority. These are only applicable
|
|
||||||
if TX_TIMER_PROCESS_IN_ISR is not defined. */
|
|
||||||
|
|
||||||
#ifndef TX_TIMER_THREAD_STACK_SIZE
|
|
||||||
#define TX_TIMER_THREAD_STACK_SIZE 1024 /* Default timer thread stack size */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef TX_TIMER_THREAD_PRIORITY
|
|
||||||
#define TX_TIMER_THREAD_PRIORITY 0 /* Default timer thread priority */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define various constants for the ThreadX RISC-V port. */
|
|
||||||
|
|
||||||
#define TX_INT_DISABLE 0x00000000 /* Disable interrupts value */
|
|
||||||
#define TX_INT_ENABLE 0x00000008 /* Enable interrupt value */
|
|
||||||
|
|
||||||
/* Define the clock source for trace event entry time stamp. The following two item are port specific.
|
|
||||||
For example, if the time source is at the address 0x0a800024 and is 16-bits in size, the clock
|
|
||||||
source constants would be:
|
|
||||||
|
|
||||||
#define TX_TRACE_TIME_SOURCE *((ULONG *) 0x0a800024)
|
|
||||||
#define TX_TRACE_TIME_MASK 0x0000FFFFUL
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TX_TRACE_TIME_SOURCE
|
|
||||||
#define TX_TRACE_TIME_SOURCE ++_tx_trace_simulated_time
|
|
||||||
#endif
|
|
||||||
#ifndef TX_TRACE_TIME_MASK
|
|
||||||
#define TX_TRACE_TIME_MASK 0xFFFFFFFFUL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define the port specific options for the _tx_build_options variable. This variable indicates
|
|
||||||
how the ThreadX library was built. */
|
|
||||||
|
|
||||||
#define TX_PORT_SPECIFIC_BUILD_OPTIONS 0
|
|
||||||
|
|
||||||
/* Define the in-line initialization constant so that modules with in-line
|
|
||||||
initialization capabilities can prevent their initialization from being
|
|
||||||
a function call. */
|
|
||||||
|
|
||||||
#define TX_INLINE_INITIALIZATION
|
|
||||||
|
|
||||||
/* Determine whether or not stack checking is enabled. By default, ThreadX stack checking is
|
|
||||||
disabled. When the following is defined, ThreadX thread stack checking is enabled. If stack
|
|
||||||
checking is enabled (TX_ENABLE_STACK_CHECKING is defined), the TX_DISABLE_STACK_FILLING
|
|
||||||
define is negated, thereby forcing the stack fill which is necessary for the stack checking
|
|
||||||
logic. */
|
|
||||||
|
|
||||||
#ifdef TX_ENABLE_STACK_CHECKING
|
|
||||||
#undef TX_DISABLE_STACK_FILLING
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define the TX_THREAD control block extensions for this port. The main reason
|
|
||||||
for the multiple macros is so that backward compatibility can be maintained with
|
|
||||||
existing ThreadX kernel awareness modules. */
|
|
||||||
|
|
||||||
#define TX_THREAD_EXTENSION_0
|
|
||||||
#define TX_THREAD_EXTENSION_1
|
|
||||||
#define TX_THREAD_EXTENSION_2
|
|
||||||
#define TX_THREAD_EXTENSION_3
|
|
||||||
|
|
||||||
/* Define the port extensions of the remaining ThreadX objects. */
|
|
||||||
|
|
||||||
#define TX_BLOCK_POOL_EXTENSION
|
|
||||||
#define TX_BYTE_POOL_EXTENSION
|
|
||||||
#define TX_EVENT_FLAGS_GROUP_EXTENSION
|
|
||||||
#define TX_MUTEX_EXTENSION
|
|
||||||
#define TX_QUEUE_EXTENSION
|
|
||||||
#define TX_SEMAPHORE_EXTENSION
|
|
||||||
#define TX_TIMER_EXTENSION
|
|
||||||
|
|
||||||
/* Define the user extension field of the thread control block. Nothing
|
|
||||||
additional is needed for this port so it is defined as white space. */
|
|
||||||
|
|
||||||
#ifndef TX_THREAD_USER_EXTENSION
|
|
||||||
#define TX_THREAD_USER_EXTENSION
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define the macros for processing extensions in tx_thread_create, tx_thread_delete,
|
|
||||||
tx_thread_shell_entry, and tx_thread_terminate. */
|
|
||||||
|
|
||||||
#define TX_THREAD_CREATE_EXTENSION(thread_ptr)
|
|
||||||
#define TX_THREAD_DELETE_EXTENSION(thread_ptr)
|
|
||||||
#define TX_THREAD_COMPLETED_EXTENSION(thread_ptr)
|
|
||||||
#define TX_THREAD_TERMINATED_EXTENSION(thread_ptr)
|
|
||||||
|
|
||||||
/* Define automated regression test extensions. These are required for the
|
|
||||||
ThreadX regression tests. */
|
|
||||||
|
|
||||||
typedef unsigned int TEST_FLAG;
|
|
||||||
extern TEST_FLAG threadx_byte_allocate_loop_test;
|
|
||||||
extern TEST_FLAG threadx_byte_release_loop_test;
|
|
||||||
extern TEST_FLAG threadx_mutex_suspension_put_test;
|
|
||||||
extern TEST_FLAG threadx_mutex_suspension_priority_test;
|
|
||||||
#ifndef TX_TIMER_PROCESS_IN_ISR
|
|
||||||
extern TEST_FLAG threadx_delete_timer_thread;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern void abort_and_resume_byte_allocating_thread(void);
|
|
||||||
extern void abort_all_threads_suspended_on_mutex(void);
|
|
||||||
extern void suspend_lowest_priority(void);
|
|
||||||
#ifndef TX_TIMER_PROCESS_IN_ISR
|
|
||||||
extern void delete_timer_thread(void);
|
|
||||||
#endif
|
|
||||||
extern TEST_FLAG test_stack_analyze_flag;
|
|
||||||
extern TEST_FLAG test_initialize_flag;
|
|
||||||
extern TEST_FLAG test_forced_mutex_timeout;
|
|
||||||
|
|
||||||
#ifdef TX_REGRESSION_TEST
|
|
||||||
|
|
||||||
/* Define extension macros for automated coverage tests. */
|
|
||||||
|
|
||||||
#define TX_BYTE_ALLOCATE_EXTENSION \
|
|
||||||
if (threadx_byte_allocate_loop_test == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
pool_ptr->tx_byte_pool_owner = TX_NULL; \
|
|
||||||
threadx_byte_allocate_loop_test = ((TEST_FLAG)0); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TX_BYTE_RELEASE_EXTENSION \
|
|
||||||
if (threadx_byte_release_loop_test == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
threadx_byte_release_loop_test = ((TEST_FLAG)0); \
|
|
||||||
abort_and_resume_byte_allocating_thread(); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TX_MUTEX_PUT_EXTENSION_1 \
|
|
||||||
if (threadx_mutex_suspension_put_test == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
threadx_mutex_suspension_put_test = ((TEST_FLAG)0); \
|
|
||||||
abort_all_threads_suspended_on_mutex(); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TX_MUTEX_PUT_EXTENSION_2 \
|
|
||||||
if (test_forced_mutex_timeout == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
test_forced_mutex_timeout = ((TEST_FLAG)0); \
|
|
||||||
_tx_thread_wait_abort(mutex_ptr->tx_mutex_suspension_list); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TX_MUTEX_PRIORITY_CHANGE_EXTENSION \
|
|
||||||
if (threadx_mutex_suspension_priority_test == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
threadx_mutex_suspension_priority_test = ((TEST_FLAG)0); \
|
|
||||||
suspend_lowest_priority(); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef TX_TIMER_PROCESS_IN_ISR
|
|
||||||
|
|
||||||
#define TX_TIMER_INITIALIZE_EXTENSION(a) \
|
|
||||||
if (threadx_delete_timer_thread == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
threadx_delete_timer_thread = ((TEST_FLAG)0); \
|
|
||||||
delete_timer_thread(); \
|
|
||||||
(a) = ((UINT)1); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define TX_THREAD_STACK_ANALYZE_EXTENSION \
|
|
||||||
if (test_stack_analyze_flag == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
thread_ptr->tx_thread_id = ((TEST_FLAG)0); \
|
|
||||||
test_stack_analyze_flag = ((TEST_FLAG)0); \
|
|
||||||
} \
|
|
||||||
else if (test_stack_analyze_flag == ((TEST_FLAG)2)) \
|
|
||||||
{ \
|
|
||||||
stack_ptr = thread_ptr->tx_thread_stack_start; \
|
|
||||||
test_stack_analyze_flag = ((TEST_FLAG)0); \
|
|
||||||
} \
|
|
||||||
else if (test_stack_analyze_flag == ((TEST_FLAG)3)) \
|
|
||||||
{ \
|
|
||||||
*stack_ptr = TX_STACK_FILL; \
|
|
||||||
test_stack_analyze_flag = ((TEST_FLAG)0); \
|
|
||||||
} \
|
|
||||||
else \
|
|
||||||
{ \
|
|
||||||
test_stack_analyze_flag = ((TEST_FLAG)0); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TX_INITIALIZE_KERNEL_ENTER_EXTENSION \
|
|
||||||
if (test_initialize_flag == ((TEST_FLAG)1)) \
|
|
||||||
{ \
|
|
||||||
test_initialize_flag = ((TEST_FLAG)0); \
|
|
||||||
return; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define the ThreadX object creation extensions for the remaining objects. */
|
|
||||||
|
|
||||||
#define TX_BLOCK_POOL_CREATE_EXTENSION(pool_ptr)
|
|
||||||
#define TX_BYTE_POOL_CREATE_EXTENSION(pool_ptr)
|
|
||||||
#define TX_EVENT_FLAGS_GROUP_CREATE_EXTENSION(group_ptr)
|
|
||||||
#define TX_MUTEX_CREATE_EXTENSION(mutex_ptr)
|
|
||||||
#define TX_QUEUE_CREATE_EXTENSION(queue_ptr)
|
|
||||||
#define TX_SEMAPHORE_CREATE_EXTENSION(semaphore_ptr)
|
|
||||||
#define TX_TIMER_CREATE_EXTENSION(timer_ptr)
|
|
||||||
|
|
||||||
/* Define the ThreadX object deletion extensions for the remaining objects. */
|
|
||||||
|
|
||||||
#define TX_BLOCK_POOL_DELETE_EXTENSION(pool_ptr)
|
|
||||||
#define TX_BYTE_POOL_DELETE_EXTENSION(pool_ptr)
|
|
||||||
#define TX_EVENT_FLAGS_GROUP_DELETE_EXTENSION(group_ptr)
|
|
||||||
#define TX_MUTEX_DELETE_EXTENSION(mutex_ptr)
|
|
||||||
#define TX_QUEUE_DELETE_EXTENSION(queue_ptr)
|
|
||||||
#define TX_SEMAPHORE_DELETE_EXTENSION(semaphore_ptr)
|
|
||||||
#define TX_TIMER_DELETE_EXTENSION(timer_ptr)
|
|
||||||
|
|
||||||
/************* Define ThreadX SMP data types and function prototypes. *************/
|
|
||||||
|
|
||||||
struct TX_THREAD_STRUCT;
|
|
||||||
|
|
||||||
/* Define the ThreadX SMP protection structure. */
|
|
||||||
|
|
||||||
typedef struct TX_THREAD_SMP_PROTECT_STRUCT
|
|
||||||
{
|
|
||||||
ULONG tx_thread_smp_protect_in_force;
|
|
||||||
ULONG tx_thread_smp_protect_core;
|
|
||||||
ULONG tx_thread_smp_protect_count;
|
|
||||||
ULONG tx_thread_smp_protect_pad_0;
|
|
||||||
ULONG tx_thread_smp_protect_pad_1;
|
|
||||||
ULONG tx_thread_smp_protect_pad_2;
|
|
||||||
ULONG tx_thread_smp_protect_pad_3;
|
|
||||||
} TX_THREAD_SMP_PROTECT;
|
|
||||||
|
|
||||||
/* Define ThreadX interrupt lockout and restore macros for protection on
|
|
||||||
access of critical kernel information. The restore interrupt macro must
|
|
||||||
restore the interrupt posture of the running thread prior to the value
|
|
||||||
present prior to the disable macro. In most cases, the save area macro
|
|
||||||
is used to define a local function save area for the disable and restore
|
|
||||||
macros. */
|
|
||||||
|
|
||||||
#define TX_INTERRUPT_SAVE_AREA ULONG tx_saved_posture;
|
|
||||||
|
|
||||||
#define TX_DISABLE tx_saved_posture = _tx_thread_smp_protect();
|
|
||||||
#define TX_RESTORE _tx_thread_smp_unprotect(tx_saved_posture);
|
|
||||||
|
|
||||||
/************* End ThreadX SMP data type and function prototype definitions. *************/
|
|
||||||
|
|
||||||
/* Define the interrupt lockout macros for each ThreadX object. */
|
|
||||||
|
|
||||||
#define TX_BLOCK_POOL_DISABLE TX_DISABLE
|
|
||||||
#define TX_BYTE_POOL_DISABLE TX_DISABLE
|
|
||||||
#define TX_EVENT_FLAGS_GROUP_DISABLE TX_DISABLE
|
|
||||||
#define TX_MUTEX_DISABLE TX_DISABLE
|
|
||||||
#define TX_QUEUE_DISABLE TX_DISABLE
|
|
||||||
#define TX_SEMAPHORE_DISABLE TX_DISABLE
|
|
||||||
|
|
||||||
/* Define the version ID of ThreadX. This may be utilized by the application. */
|
|
||||||
|
|
||||||
#ifdef TX_THREAD_INIT
|
|
||||||
CHAR _tx_version_id[] = "Copyright (c) 2024 Microsoft Corporation. * ThreadX RISC-V64/GNU Version 6.4.2 *";
|
|
||||||
#else
|
|
||||||
extern CHAR _tx_version_id[];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*not __ASSEMBLER__ */
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,304 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present 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. */
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/**************************************************************************/
|
||||||
|
/** */
|
||||||
|
/** ThreadX Component */
|
||||||
|
/** */
|
||||||
|
/** User Specific */
|
||||||
|
/** */
|
||||||
|
/**************************************************************************/
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* PORT SPECIFIC C INFORMATION RELEASE */
|
||||||
|
/* */
|
||||||
|
/* tx_user.h PORTABLE C */
|
||||||
|
/* 6.3.0 */
|
||||||
|
/* */
|
||||||
|
/* AUTHOR */
|
||||||
|
/* */
|
||||||
|
/* William E. Lamie, Microsoft Corporation */
|
||||||
|
/* */
|
||||||
|
/* DESCRIPTION */
|
||||||
|
/* */
|
||||||
|
/* This file contains user defines for configuring ThreadX in specific */
|
||||||
|
/* ways. This file will have an effect only if the application and */
|
||||||
|
/* ThreadX library are built with TX_INCLUDE_USER_DEFINE_FILE defined. */
|
||||||
|
/* Note that all the defines in this file may also be made on the */
|
||||||
|
/* command line when building ThreadX library and application objects. */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
#ifndef TX_USER_H
|
||||||
|
#define TX_USER_H
|
||||||
|
|
||||||
|
/* Moonlight SMP configuration based on common_smp/inc/tx_user_sample.h.
|
||||||
|
Moonlight and its HERE VP tests use four harts starting at hart 0. */
|
||||||
|
#ifndef TX_THREAD_SMP_MAX_CORES
|
||||||
|
#define TX_THREAD_SMP_MAX_CORES 4
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Define various build options for the ThreadX port. The application should either make changes
|
||||||
|
here by commenting or un-commenting the conditional compilation defined OR supply the defines
|
||||||
|
though the compiler's equivalent of the -D option.
|
||||||
|
|
||||||
|
For maximum speed, the following should be defined:
|
||||||
|
|
||||||
|
TX_MAX_PRIORITIES 32
|
||||||
|
TX_DISABLE_PREEMPTION_THRESHOLD
|
||||||
|
TX_DISABLE_REDUNDANT_CLEARING
|
||||||
|
TX_DISABLE_NOTIFY_CALLBACKS
|
||||||
|
TX_NOT_INTERRUPTABLE
|
||||||
|
TX_TIMER_PROCESS_IN_ISR
|
||||||
|
TX_REACTIVATE_INLINE
|
||||||
|
TX_DISABLE_STACK_FILLING
|
||||||
|
TX_INLINE_THREAD_RESUME_SUSPEND
|
||||||
|
|
||||||
|
For minimum size, the following should be defined:
|
||||||
|
|
||||||
|
TX_MAX_PRIORITIES 32
|
||||||
|
TX_DISABLE_PREEMPTION_THRESHOLD
|
||||||
|
TX_DISABLE_REDUNDANT_CLEARING
|
||||||
|
TX_DISABLE_NOTIFY_CALLBACKS
|
||||||
|
TX_NO_FILEX_POINTER
|
||||||
|
TX_NOT_INTERRUPTABLE
|
||||||
|
TX_TIMER_PROCESS_IN_ISR
|
||||||
|
|
||||||
|
Of course, many of these defines reduce functionality and/or change the behavior of the
|
||||||
|
system in ways that may not be worth the trade-off. For example, the TX_TIMER_PROCESS_IN_ISR
|
||||||
|
results in faster and smaller code, however, it increases the amount of processing in the ISR.
|
||||||
|
In addition, some services that are available in timers are not available from ISRs and will
|
||||||
|
therefore return an error if this option is used. This may or may not be desirable for a
|
||||||
|
given application. */
|
||||||
|
|
||||||
|
|
||||||
|
/* Override various options with default values already assigned in tx_port.h. Please also refer
|
||||||
|
to tx_port.h for descriptions on each of these options. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_MAX_PRIORITIES 32
|
||||||
|
#define TX_MINIMUM_STACK ????
|
||||||
|
#define TX_THREAD_USER_EXTENSION ????
|
||||||
|
#define TX_TIMER_THREAD_STACK_SIZE ????
|
||||||
|
#define TX_TIMER_THREAD_PRIORITY ????
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define the common timer tick reference for use by other middleware components. The default
|
||||||
|
value is 10ms (i.e. 100 ticks, defined in tx_api.h), but may be replaced by a port-specific
|
||||||
|
version in tx_port.h or here.
|
||||||
|
Note: the actual hardware timer value may need to be changed (usually in tx_initialize_low_level). */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_TIMER_TICKS_PER_SECOND (100UL)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define this option to qualify object names as pointers to const. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_ENABLE_CONST_NAMES
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine if there is a FileX pointer in the thread control block.
|
||||||
|
By default, the pointer is there for legacy/backwards compatibility.
|
||||||
|
The pointer must also be there for applications using FileX.
|
||||||
|
Define this to save space in the thread control block.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_NO_FILEX_POINTER
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine if timer expirations (application timers, timeouts, and tx_thread_sleep calls
|
||||||
|
should be processed within the a system timer thread or directly in the timer ISR.
|
||||||
|
By default, the timer thread is used. When the following is defined, the timer expiration
|
||||||
|
processing is done directly from the timer ISR, thereby eliminating the timer thread control
|
||||||
|
block, stack, and context switching to activate it. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_TIMER_PROCESS_IN_ISR
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine if in-line timer reactivation should be used within the timer expiration processing.
|
||||||
|
By default, this is disabled and a function call is used. When the following is defined,
|
||||||
|
reactivating is performed in-line resulting in faster timer processing but slightly larger
|
||||||
|
code size. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_REACTIVATE_INLINE
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine is stack filling is enabled. By default, ThreadX stack filling is enabled,
|
||||||
|
which places an 0xEF pattern in each byte of each thread's stack. This is used by
|
||||||
|
debuggers with ThreadX-awareness and by the ThreadX run-time stack checking feature. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_DISABLE_STACK_FILLING
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine whether or not stack checking is enabled. By default, ThreadX stack checking is
|
||||||
|
disabled. When the following is defined, ThreadX thread stack checking is enabled. If stack
|
||||||
|
checking is enabled (TX_ENABLE_STACK_CHECKING is defined), the TX_DISABLE_STACK_FILLING
|
||||||
|
define is negated, thereby forcing the stack fill which is necessary for the stack checking
|
||||||
|
logic. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_ENABLE_STACK_CHECKING
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine if random number is used for stack filling. By default, ThreadX uses a fixed
|
||||||
|
pattern for stack filling. When the following is defined, ThreadX uses a random number
|
||||||
|
for stack filling. This is effective only when TX_ENABLE_STACK_CHECKING is defined. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_ENABLE_RANDOM_NUMBER_STACK_FILLING
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine if preemption-threshold should be disabled. By default, preemption-threshold is
|
||||||
|
enabled. If the application does not use preemption-threshold, it may be disabled to reduce
|
||||||
|
code size and improve performance. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_DISABLE_PREEMPTION_THRESHOLD
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine if global ThreadX variables should be cleared. If the compiler startup code clears
|
||||||
|
the .bss section prior to ThreadX running, the define can be used to eliminate unnecessary
|
||||||
|
clearing of ThreadX global variables. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_DISABLE_REDUNDANT_CLEARING
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine if no timer processing is required. This option will help eliminate the timer
|
||||||
|
processing when not needed. The user will also have to comment out the call to
|
||||||
|
tx_timer_interrupt, which is typically made from assembly language in
|
||||||
|
tx_initialize_low_level. Note: if TX_NO_TIMER is used, the define TX_TIMER_PROCESS_IN_ISR
|
||||||
|
must also be used and tx_timer_initialize must be removed from ThreadX library. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_NO_TIMER
|
||||||
|
#ifndef TX_TIMER_PROCESS_IN_ISR
|
||||||
|
#define TX_TIMER_PROCESS_IN_ISR
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine if the notify callback option should be disabled. By default, notify callbacks are
|
||||||
|
enabled. If the application does not use notify callbacks, they may be disabled to reduce
|
||||||
|
code size and improve performance. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_DISABLE_NOTIFY_CALLBACKS
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* Determine if the tx_thread_resume and tx_thread_suspend services should have their internal
|
||||||
|
code in-line. This results in a larger image, but improves the performance of the thread
|
||||||
|
resume and suspend services. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_INLINE_THREAD_RESUME_SUSPEND
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* Determine if the internal ThreadX code is non-interruptable. This results in smaller code
|
||||||
|
size and less processing overhead, but increases the interrupt lockout time. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_NOT_INTERRUPTABLE
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* Determine if the trace event logging code should be enabled. This causes slight increases in
|
||||||
|
code size and overhead, but provides the ability to generate system trace information which
|
||||||
|
is available for viewing in TraceX. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_ENABLE_EVENT_TRACE
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* Determine if block pool performance gathering is required by the application. When the following is
|
||||||
|
defined, ThreadX gathers various block pool performance information. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_BLOCK_POOL_ENABLE_PERFORMANCE_INFO
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine if byte pool performance gathering is required by the application. When the following is
|
||||||
|
defined, ThreadX gathers various byte pool performance information. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_BYTE_POOL_ENABLE_PERFORMANCE_INFO
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine if event flags performance gathering is required by the application. When the following is
|
||||||
|
defined, ThreadX gathers various event flags performance information. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_EVENT_FLAGS_ENABLE_PERFORMANCE_INFO
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine if mutex performance gathering is required by the application. When the following is
|
||||||
|
defined, ThreadX gathers various mutex performance information. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_MUTEX_ENABLE_PERFORMANCE_INFO
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine if queue performance gathering is required by the application. When the following is
|
||||||
|
defined, ThreadX gathers various queue performance information. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_QUEUE_ENABLE_PERFORMANCE_INFO
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine if semaphore performance gathering is required by the application. When the following is
|
||||||
|
defined, ThreadX gathers various semaphore performance information. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_SEMAPHORE_ENABLE_PERFORMANCE_INFO
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine if thread performance gathering is required by the application. When the following is
|
||||||
|
defined, ThreadX gathers various thread performance information. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_THREAD_ENABLE_PERFORMANCE_INFO
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine if timer performance gathering is required by the application. When the following is
|
||||||
|
defined, ThreadX gathers various timer performance information. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_TIMER_ENABLE_PERFORMANCE_INFO
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Override options for byte pool searches of multiple blocks. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_BYTE_POOL_MULTIPLE_BLOCK_SEARCH 20
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Override options for byte pool search delay to avoid thrashing. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define TX_BYTE_POOL_DELAY_VALUE 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
.section .text
|
|
||||||
.align 4
|
|
||||||
#include "tx_port.h"
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* trap_entry RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Jer6y , luojun@oerv.isrc.iscas.ac.cn */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function is responsible for riscv processor trap handle */
|
|
||||||
/* It will do the contex save and call c trap_handler and do contex */
|
|
||||||
/* load */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* trap_handler */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* hardware exception */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 10-25-2024 Jerry Luo */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Initialize */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
.global trap_entry
|
|
||||||
.extern _tx_thread_context_restore
|
|
||||||
trap_entry:
|
|
||||||
addi sp, sp, -TX_INTERRUPT_FRAME_SIZE
|
|
||||||
|
|
||||||
STORE x1, 28*REGBYTES(sp) // Store RA, 28*REGBYTES(because call will override ra [ra is a calle register in riscv])
|
|
||||||
|
|
||||||
call _tx_thread_context_save
|
|
||||||
|
|
||||||
csrr a0, mcause
|
|
||||||
csrr a1, mepc
|
|
||||||
csrr a2, mtval
|
|
||||||
addi sp, sp, -16 // Keep the C handler stack aligned
|
|
||||||
STORE ra, 0(sp)
|
|
||||||
call trap_handler
|
|
||||||
LOAD ra, 0(sp)
|
|
||||||
addi sp, sp, 16
|
|
||||||
call _tx_thread_context_restore
|
|
||||||
// it will nerver return
|
|
||||||
.weak trap_handler
|
|
||||||
trap_handler:
|
|
||||||
1:
|
|
||||||
j 1b
|
|
||||||
.section .text
|
|
||||||
@@ -1,25 +1,31 @@
|
|||||||
|
|
||||||
#include "aclint.h"
|
|
||||||
#include "aclint_ipi.h"
|
#include "aclint_ipi.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "csr.h"
|
#include "csr.h"
|
||||||
#include "hwtimer.h"
|
#include "hwtimer.h"
|
||||||
#include "riscv-csr.h"
|
#include "riscv-csr.h"
|
||||||
#include "riscv-traps.h"
|
#include "riscv-traps.h"
|
||||||
#include "tx_port.h"
|
#include "tx_api.h"
|
||||||
|
#include "tx_initialize.h"
|
||||||
|
#include "tx_thread.h"
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
extern CHAR __heap_start;
|
extern CHAR __heap_start[];
|
||||||
extern void trap_entry(void);
|
extern void trap_entry(void);
|
||||||
extern void _tx_timer_interrupt(void);
|
extern void _tx_timer_interrupt(void);
|
||||||
|
void _tx_riscv_smp_hart_initialize(void);
|
||||||
|
|
||||||
extern ULONG* _tx_thread_system_stack_ptr;
|
#ifdef TX_REGRESSION_TEST
|
||||||
extern ULONG* _tx_initialize_unused_memory;
|
extern void test_interrupt_dispatch(void) __attribute__((weak));
|
||||||
extern void _tx_thread_smp_initialize_wait(void) __attribute__((noreturn));
|
#endif
|
||||||
|
|
||||||
void handle_RISCV_INT_MTI(void)
|
void handle_RISCV_INT_MTI(void)
|
||||||
{
|
{
|
||||||
hwtimer_handler();
|
hwtimer_handler();
|
||||||
|
#ifdef TX_REGRESSION_TEST
|
||||||
|
if (test_interrupt_dispatch)
|
||||||
|
test_interrupt_dispatch();
|
||||||
|
#endif
|
||||||
_tx_timer_interrupt();
|
_tx_timer_interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +63,7 @@ void _secondary_initialize(void)
|
|||||||
csr_clr_bits_mstatus(MSTATUS_MIE_BIT_MASK);
|
csr_clr_bits_mstatus(MSTATUS_MIE_BIT_MASK);
|
||||||
|
|
||||||
_tx_thread_smp_initialize_wait();
|
_tx_thread_smp_initialize_wait();
|
||||||
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _secondary_ipi_trap(void)
|
void _secondary_ipi_trap(void)
|
||||||
@@ -85,23 +92,15 @@ void bootup_wake_secondary_cores(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _tx_thread_smp_core_preempt(UINT target_core)
|
||||||
|
{
|
||||||
|
send_ipi(target_core);
|
||||||
|
}
|
||||||
|
|
||||||
VOID _tx_initialize_low_level(VOID)
|
VOID _tx_initialize_low_level(VOID)
|
||||||
{
|
{
|
||||||
_tx_thread_system_stack_ptr = (VOID*)(ULONG)riscv_get_sp();
|
_tx_thread_system_stack_ptr[0] = (VOID *)(uintptr_t)riscv_get_sp();
|
||||||
_tx_initialize_unused_memory = (VOID*)&__heap_start;
|
_tx_initialize_unused_memory = __heap_start;
|
||||||
|
|
||||||
// disable interrupts
|
|
||||||
asm volatile("csrrc zero, mstatus, %0" : : "r"(MSTATUS_MIE));
|
|
||||||
// set previous interrupt enable and previous priv mode to be set when executing "mret"
|
|
||||||
asm volatile("csrrs zero, mstatus, %0" : : "r"(MSTATUS_MPP_M | MSTATUS_MPIE));
|
|
||||||
// enable timer, software and external interrupts
|
|
||||||
asm volatile("csrrs zero, mie, %0" : : "r"(MIE_MTIE | MIE_MSIE | MIE_MEIE));
|
|
||||||
|
|
||||||
#ifdef __riscv_flen
|
|
||||||
// enable f extension and reset state
|
|
||||||
asm volatile("csrrs zero, mstatus, %0" : : "r"(MSTATUS_FS));
|
|
||||||
asm volatile("fscsr x0");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
board_init();
|
board_init();
|
||||||
register_irq_handler(RISCV_INT_MTI, handle_RISCV_INT_MTI);
|
register_irq_handler(RISCV_INT_MTI, handle_RISCV_INT_MTI);
|
||||||
@@ -109,5 +108,20 @@ VOID _tx_initialize_low_level(VOID)
|
|||||||
#ifdef TX_THREAD_SMP_INTER_CORE_INTERRUPT
|
#ifdef TX_THREAD_SMP_INTER_CORE_INTERRUPT
|
||||||
register_irq_handler(RISCV_INT_MSI, handle_RISCV_INT_MSI);
|
register_irq_handler(RISCV_INT_MSI, handle_RISCV_INT_MSI);
|
||||||
#endif
|
#endif
|
||||||
asm volatile("csrw mtvec, %0" : : "r"((uintptr_t)trap_entry));
|
_tx_riscv_smp_hart_initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Install the local trap entry after the kernel has synchronized this hart. */
|
||||||
|
void _tx_riscv_smp_hart_initialize(void)
|
||||||
|
{
|
||||||
|
csr_clr_bits_mstatus(MSTATUS_MIE);
|
||||||
|
csr_set_bits_mstatus(MSTATUS_MPP_M | MSTATUS_MPIE);
|
||||||
|
csr_set_bits_mie(MIE_MTIE | MIE_MSIE | MIE_MEIE);
|
||||||
|
|
||||||
|
#ifdef __riscv_flen
|
||||||
|
csr_set_bits_mstatus(MSTATUS_FS);
|
||||||
|
asm volatile("fscsr x0");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
csr_write_mtvec((uintptr_t)trap_entry);
|
||||||
}
|
}
|
||||||
@@ -1,335 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Thread */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_context_restore RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Scott Larson, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function restores the interrupt context if it is processing a */
|
|
||||||
/* nested interrupt. If not, it returns to the interrupt thread if no */
|
|
||||||
/* preemption is necessary. Otherwise, if preemption is necessary or */
|
|
||||||
/* if no thread was running, the function returns to the scheduler. */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_schedule Thread scheduling routine */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* ISRs Interrupt Service Routines */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
/* VOID _tx_thread_context_restore(VOID)
|
|
||||||
{ */
|
|
||||||
.global _tx_thread_context_restore
|
|
||||||
_tx_thread_context_restore:
|
|
||||||
|
|
||||||
/* Lockout interrupts. */
|
|
||||||
|
|
||||||
csrci mstatus, 0x08 // Disable interrupts
|
|
||||||
|
|
||||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
|
||||||
call _tx_execution_isr_exit // Call the ISR execution exit function
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Determine if interrupts are nested. */
|
|
||||||
/* if (--_tx_thread_system_state)
|
|
||||||
{ */
|
|
||||||
|
|
||||||
csrr t3, mhartid // Pickup current hart ID
|
|
||||||
slli t4, t3, LOG_REGBYTES // Build per-hart ULONG offset
|
|
||||||
slli t5, t3, LOG_REGBYTES // Build per-hart pointer offset
|
|
||||||
la t0, _tx_thread_system_state // Pickup base of system-state array
|
|
||||||
add t0, t0, t4 // Select this hart's system-state slot
|
|
||||||
LOAD t1, 0(t0) // Pickup nested interrupt count
|
|
||||||
addi t1, t1, -1 // Decrement the nested interrupt counter
|
|
||||||
STORE t1, 0(t0) // Store new nested count
|
|
||||||
beqz t1, _tx_thread_not_nested_restore // If 0, not nested restore
|
|
||||||
|
|
||||||
/* Interrupts are nested. */
|
|
||||||
|
|
||||||
/* Just recover the saved registers and return to the point of
|
|
||||||
interrupt. */
|
|
||||||
|
|
||||||
/* Recover floating point registers. */
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_LOAD f0, TX_INTERRUPT_FP_OFFSET(0)(sp) // Recover ft0
|
|
||||||
TX_FP_LOAD f1, TX_INTERRUPT_FP_OFFSET(1)(sp) // Recover ft1
|
|
||||||
TX_FP_LOAD f2, TX_INTERRUPT_FP_OFFSET(2)(sp) // Recover ft2
|
|
||||||
TX_FP_LOAD f3, TX_INTERRUPT_FP_OFFSET(3)(sp) // Recover ft3
|
|
||||||
TX_FP_LOAD f4, TX_INTERRUPT_FP_OFFSET(4)(sp) // Recover ft4
|
|
||||||
TX_FP_LOAD f5, TX_INTERRUPT_FP_OFFSET(5)(sp) // Recover ft5
|
|
||||||
TX_FP_LOAD f6, TX_INTERRUPT_FP_OFFSET(6)(sp) // Recover ft6
|
|
||||||
TX_FP_LOAD f7, TX_INTERRUPT_FP_OFFSET(7)(sp) // Recover ft7
|
|
||||||
TX_FP_LOAD f10, TX_INTERRUPT_FP_OFFSET(10)(sp) // Recover fa0
|
|
||||||
TX_FP_LOAD f11, TX_INTERRUPT_FP_OFFSET(11)(sp) // Recover fa1
|
|
||||||
TX_FP_LOAD f12, TX_INTERRUPT_FP_OFFSET(12)(sp) // Recover fa2
|
|
||||||
TX_FP_LOAD f13, TX_INTERRUPT_FP_OFFSET(13)(sp) // Recover fa3
|
|
||||||
TX_FP_LOAD f14, TX_INTERRUPT_FP_OFFSET(14)(sp) // Recover fa4
|
|
||||||
TX_FP_LOAD f15, TX_INTERRUPT_FP_OFFSET(15)(sp) // Recover fa5
|
|
||||||
TX_FP_LOAD f16, TX_INTERRUPT_FP_OFFSET(16)(sp) // Recover fa6
|
|
||||||
TX_FP_LOAD f17, TX_INTERRUPT_FP_OFFSET(17)(sp) // Recover fa7
|
|
||||||
TX_FP_LOAD f28, TX_INTERRUPT_FP_OFFSET(28)(sp) // Recover ft8
|
|
||||||
TX_FP_LOAD f29, TX_INTERRUPT_FP_OFFSET(29)(sp) // Recover ft9
|
|
||||||
TX_FP_LOAD f30, TX_INTERRUPT_FP_OFFSET(30)(sp) // Recover ft10
|
|
||||||
TX_FP_LOAD f31, TX_INTERRUPT_FP_OFFSET(31)(sp) // Recover ft11
|
|
||||||
LOAD t0, TX_INTERRUPT_FCSR_OFFSET(sp) // Recover fcsr
|
|
||||||
csrw fcsr, t0 //
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Recover standard registers. */
|
|
||||||
|
|
||||||
/* Restore registers,
|
|
||||||
Skip global pointer because that does not change.
|
|
||||||
Also skip the saved registers since they have been restored by any function we called,
|
|
||||||
except s0 since we use it ourselves. */
|
|
||||||
|
|
||||||
LOAD t0, 30*REGBYTES(sp) // Recover mepc
|
|
||||||
csrw mepc, t0 // Setup mepc
|
|
||||||
li t0, 0x1880 // Prepare MPIP
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
li t1, 1<<13
|
|
||||||
or t0, t1, t0
|
|
||||||
#endif
|
|
||||||
csrw mstatus, t0 // Enable MPIP
|
|
||||||
|
|
||||||
LOAD x1, 28*REGBYTES(sp) // Recover RA
|
|
||||||
LOAD x5, 19*REGBYTES(sp) // Recover t0
|
|
||||||
LOAD x6, 18*REGBYTES(sp) // Recover t1
|
|
||||||
LOAD x7, 17*REGBYTES(sp) // Recover t2
|
|
||||||
LOAD x8, 12*REGBYTES(sp) // Recover s0
|
|
||||||
LOAD x10, 27*REGBYTES(sp) // Recover a0
|
|
||||||
LOAD x11, 26*REGBYTES(sp) // Recover a1
|
|
||||||
LOAD x12, 25*REGBYTES(sp) // Recover a2
|
|
||||||
LOAD x13, 24*REGBYTES(sp) // Recover a3
|
|
||||||
LOAD x14, 23*REGBYTES(sp) // Recover a4
|
|
||||||
LOAD x15, 22*REGBYTES(sp) // Recover a5
|
|
||||||
LOAD x16, 21*REGBYTES(sp) // Recover a6
|
|
||||||
LOAD x17, 20*REGBYTES(sp) // Recover a7
|
|
||||||
LOAD x28, 16*REGBYTES(sp) // Recover t3
|
|
||||||
LOAD x29, 15*REGBYTES(sp) // Recover t4
|
|
||||||
LOAD x30, 14*REGBYTES(sp) // Recover t5
|
|
||||||
LOAD x31, 13*REGBYTES(sp) // Recover t6
|
|
||||||
|
|
||||||
addi sp, sp, TX_INTERRUPT_FRAME_SIZE
|
|
||||||
mret // Return to point of interrupt
|
|
||||||
|
|
||||||
/* } */
|
|
||||||
_tx_thread_not_nested_restore:
|
|
||||||
/* Determine if a thread was interrupted and no preemption is required. */
|
|
||||||
/* else if (((_tx_thread_current_ptr) && (_tx_thread_current_ptr == _tx_thread_execute_ptr)
|
|
||||||
|| (_tx_thread_preempt_disable))
|
|
||||||
{ */
|
|
||||||
|
|
||||||
la t0, _tx_thread_current_ptr // Pickup base of current-thread array
|
|
||||||
add t0, t0, t5 // Select this hart's current-thread slot
|
|
||||||
LOAD t1, 0(t0) // Pickup current thread pointer
|
|
||||||
beqz t1, _tx_thread_idle_system_restore // If NULL, idle system restore
|
|
||||||
|
|
||||||
la t0, _tx_thread_execute_ptr // Pickup base of execute-thread array
|
|
||||||
add t0, t0, t5 // Select this hart's execute-thread slot
|
|
||||||
LOAD t2, 0(t0) // Pickup thread execute pointer
|
|
||||||
beq t1, t2, _tx_thread_no_preempt_restore // Same thread selected, no preemption
|
|
||||||
|
|
||||||
la t0, _tx_thread_smp_protection // Pickup protection structure
|
|
||||||
LOAD t2, 1*REGBYTES(t0) // Pickup owning hart
|
|
||||||
bne t2, t3, _tx_thread_preempt_restore // If owned by another hart, preempt
|
|
||||||
|
|
||||||
LWU t2, _tx_thread_preempt_disable // Pickup preempt disable flag
|
|
||||||
bgtz t2, _tx_thread_no_preempt_restore // If set, restore interrupted thread
|
|
||||||
|
|
||||||
|
|
||||||
_tx_thread_no_preempt_restore:
|
|
||||||
/* Restore interrupted thread or ISR. */
|
|
||||||
|
|
||||||
/* Pickup the saved stack pointer. */
|
|
||||||
/* SP = _tx_thread_current_ptr -> tx_thread_stack_ptr; */
|
|
||||||
|
|
||||||
LOAD sp, 2*REGBYTES(t1) // Switch back to thread's stack
|
|
||||||
|
|
||||||
/* Recover floating point registers. */
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_LOAD f0, TX_INTERRUPT_FP_OFFSET(0)(sp) // Recover ft0
|
|
||||||
TX_FP_LOAD f1, TX_INTERRUPT_FP_OFFSET(1)(sp) // Recover ft1
|
|
||||||
TX_FP_LOAD f2, TX_INTERRUPT_FP_OFFSET(2)(sp) // Recover ft2
|
|
||||||
TX_FP_LOAD f3, TX_INTERRUPT_FP_OFFSET(3)(sp) // Recover ft3
|
|
||||||
TX_FP_LOAD f4, TX_INTERRUPT_FP_OFFSET(4)(sp) // Recover ft4
|
|
||||||
TX_FP_LOAD f5, TX_INTERRUPT_FP_OFFSET(5)(sp) // Recover ft5
|
|
||||||
TX_FP_LOAD f6, TX_INTERRUPT_FP_OFFSET(6)(sp) // Recover ft6
|
|
||||||
TX_FP_LOAD f7, TX_INTERRUPT_FP_OFFSET(7)(sp) // Recover ft7
|
|
||||||
TX_FP_LOAD f10, TX_INTERRUPT_FP_OFFSET(10)(sp) // Recover fa0
|
|
||||||
TX_FP_LOAD f11, TX_INTERRUPT_FP_OFFSET(11)(sp) // Recover fa1
|
|
||||||
TX_FP_LOAD f12, TX_INTERRUPT_FP_OFFSET(12)(sp) // Recover fa2
|
|
||||||
TX_FP_LOAD f13, TX_INTERRUPT_FP_OFFSET(13)(sp) // Recover fa3
|
|
||||||
TX_FP_LOAD f14, TX_INTERRUPT_FP_OFFSET(14)(sp) // Recover fa4
|
|
||||||
TX_FP_LOAD f15, TX_INTERRUPT_FP_OFFSET(15)(sp) // Recover fa5
|
|
||||||
TX_FP_LOAD f16, TX_INTERRUPT_FP_OFFSET(16)(sp) // Recover fa6
|
|
||||||
TX_FP_LOAD f17, TX_INTERRUPT_FP_OFFSET(17)(sp) // Recover fa7
|
|
||||||
TX_FP_LOAD f28, TX_INTERRUPT_FP_OFFSET(28)(sp) // Recover ft8
|
|
||||||
TX_FP_LOAD f29, TX_INTERRUPT_FP_OFFSET(29)(sp) // Recover ft9
|
|
||||||
TX_FP_LOAD f30, TX_INTERRUPT_FP_OFFSET(30)(sp) // Recover ft10
|
|
||||||
TX_FP_LOAD f31, TX_INTERRUPT_FP_OFFSET(31)(sp) // Recover ft11
|
|
||||||
LOAD t0, TX_INTERRUPT_FCSR_OFFSET(sp) // Recover fcsr
|
|
||||||
csrw fcsr, t0 //
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Recover the saved context and return to the point of interrupt. */
|
|
||||||
|
|
||||||
/* Recover standard registers. */
|
|
||||||
/* Restore registers,
|
|
||||||
Skip global pointer because that does not change */
|
|
||||||
|
|
||||||
LOAD t0, 30*REGBYTES(sp) // Recover mepc
|
|
||||||
csrw mepc, t0 // Setup mepc
|
|
||||||
li t0, 0x1880 // Prepare MPIP
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
li t1, 1<<13
|
|
||||||
or t0, t1, t0
|
|
||||||
#endif
|
|
||||||
csrw mstatus, t0 // Enable MPIP
|
|
||||||
|
|
||||||
LOAD x1, 28*REGBYTES(sp) // Recover RA
|
|
||||||
LOAD x5, 19*REGBYTES(sp) // Recover t0
|
|
||||||
LOAD x6, 18*REGBYTES(sp) // Recover t1
|
|
||||||
LOAD x7, 17*REGBYTES(sp) // Recover t2
|
|
||||||
LOAD x8, 12*REGBYTES(sp) // Recover s0
|
|
||||||
LOAD x10, 27*REGBYTES(sp) // Recover a0
|
|
||||||
LOAD x11, 26*REGBYTES(sp) // Recover a1
|
|
||||||
LOAD x12, 25*REGBYTES(sp) // Recover a2
|
|
||||||
LOAD x13, 24*REGBYTES(sp) // Recover a3
|
|
||||||
LOAD x14, 23*REGBYTES(sp) // Recover a4
|
|
||||||
LOAD x15, 22*REGBYTES(sp) // Recover a5
|
|
||||||
LOAD x16, 21*REGBYTES(sp) // Recover a6
|
|
||||||
LOAD x17, 20*REGBYTES(sp) // Recover a7
|
|
||||||
LOAD x28, 16*REGBYTES(sp) // Recover t3
|
|
||||||
LOAD x29, 15*REGBYTES(sp) // Recover t4
|
|
||||||
LOAD x30, 14*REGBYTES(sp) // Recover t5
|
|
||||||
LOAD x31, 13*REGBYTES(sp) // Recover t6
|
|
||||||
|
|
||||||
addi sp, sp, TX_INTERRUPT_FRAME_SIZE
|
|
||||||
mret // Return to point of interrupt
|
|
||||||
|
|
||||||
/* }
|
|
||||||
else
|
|
||||||
{ */
|
|
||||||
_tx_thread_preempt_restore:
|
|
||||||
/* Instead of directly activating the thread again, ensure we save the
|
|
||||||
entire stack frame by saving the remaining registers. */
|
|
||||||
|
|
||||||
LOAD t0, 2*REGBYTES(t1) // Pickup thread's stack pointer
|
|
||||||
ori t3, x0, 1 // Build interrupt stack type
|
|
||||||
STORE t3, 0(t0) // Store stack type
|
|
||||||
|
|
||||||
/* Store floating point preserved registers. */
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_STORE f8, TX_INTERRUPT_FP_OFFSET(8)(t0) // Store fs0
|
|
||||||
TX_FP_STORE f9, TX_INTERRUPT_FP_OFFSET(9)(t0) // Store fs1
|
|
||||||
TX_FP_STORE f18, TX_INTERRUPT_FP_OFFSET(18)(t0) // Store fs2
|
|
||||||
TX_FP_STORE f19, TX_INTERRUPT_FP_OFFSET(19)(t0) // Store fs3
|
|
||||||
TX_FP_STORE f20, TX_INTERRUPT_FP_OFFSET(20)(t0) // Store fs4
|
|
||||||
TX_FP_STORE f21, TX_INTERRUPT_FP_OFFSET(21)(t0) // Store fs5
|
|
||||||
TX_FP_STORE f22, TX_INTERRUPT_FP_OFFSET(22)(t0) // Store fs6
|
|
||||||
TX_FP_STORE f23, TX_INTERRUPT_FP_OFFSET(23)(t0) // Store fs7
|
|
||||||
TX_FP_STORE f24, TX_INTERRUPT_FP_OFFSET(24)(t0) // Store fs8
|
|
||||||
TX_FP_STORE f25, TX_INTERRUPT_FP_OFFSET(25)(t0) // Store fs9
|
|
||||||
TX_FP_STORE f26, TX_INTERRUPT_FP_OFFSET(26)(t0) // Store fs10
|
|
||||||
TX_FP_STORE f27, TX_INTERRUPT_FP_OFFSET(27)(t0) // Store fs11
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Store standard preserved registers. */
|
|
||||||
|
|
||||||
STORE x9, 11*REGBYTES(t0) // Store s1
|
|
||||||
STORE x18, 10*REGBYTES(t0) // Store s2
|
|
||||||
STORE x19, 9*REGBYTES(t0) // Store s3
|
|
||||||
STORE x20, 8*REGBYTES(t0) // Store s4
|
|
||||||
STORE x21, 7*REGBYTES(t0) // Store s5
|
|
||||||
STORE x22, 6*REGBYTES(t0) // Store s6
|
|
||||||
STORE x23, 5*REGBYTES(t0) // Store s7
|
|
||||||
STORE x24, 4*REGBYTES(t0) // Store s8
|
|
||||||
STORE x25, 3*REGBYTES(t0) // Store s9
|
|
||||||
STORE x26, 2*REGBYTES(t0) // Store s10
|
|
||||||
STORE x27, 1*REGBYTES(t0) // Store s11
|
|
||||||
// Note: s0 is already stored!
|
|
||||||
|
|
||||||
/* Save the remaining time-slice and disable it. */
|
|
||||||
/* if (_tx_timer_time_slice)
|
|
||||||
{ */
|
|
||||||
|
|
||||||
la t0, _tx_timer_time_slice // Pickup base of time-slice array
|
|
||||||
add t0, t0, t4 // Select this hart's time-slice slot
|
|
||||||
LOAD t2, 0(t0) // Pickup time slice
|
|
||||||
beqz t2, _tx_thread_dont_save_ts // If 0, skip time slice processing
|
|
||||||
|
|
||||||
/* _tx_thread_current_ptr -> tx_thread_time_slice = _tx_timer_time_slice
|
|
||||||
_tx_timer_time_slice = 0; */
|
|
||||||
|
|
||||||
STORE t2, 6*REGBYTES(t1) // Save current time slice
|
|
||||||
STORE x0, 0(t0) // Clear global time slice
|
|
||||||
|
|
||||||
|
|
||||||
/* } */
|
|
||||||
_tx_thread_dont_save_ts:
|
|
||||||
/* Clear the current task pointer. */
|
|
||||||
/* _tx_thread_current_ptr = TX_NULL; */
|
|
||||||
|
|
||||||
/* Return to the scheduler. */
|
|
||||||
/* _tx_thread_schedule(); */
|
|
||||||
|
|
||||||
la t0, _tx_thread_current_ptr // Pickup base of current-thread array
|
|
||||||
add t0, t0, t5 // Select this hart's current-thread slot
|
|
||||||
STORE x0, 0(t0) // Clear current thread pointer
|
|
||||||
|
|
||||||
fence rw, rw // Publish current-thread clear before ready token
|
|
||||||
addi t0, t1, TX_THREAD_SMP_LOCK_READY_BIT_OFFSET // Pickup lock/ready-bit address
|
|
||||||
li t2, 1 // Rebuild ready token
|
|
||||||
AMOSWAP_RL x0, t2, (t0) // Set thread ready token for reschedule
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
_tx_thread_idle_system_restore:
|
|
||||||
/* Just return back to the scheduler! */
|
|
||||||
j _tx_thread_schedule // Return to scheduler
|
|
||||||
|
|
||||||
/* } */
|
|
||||||
@@ -1,239 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Thread */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_context_save RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Scott Larson, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function saves the context of an executing thread in the */
|
|
||||||
/* beginning of interrupt processing. The function also ensures that */
|
|
||||||
/* the system stack is used upon return to the calling ISR. */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* ISRs */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
/* VOID _tx_thread_context_save(VOID)
|
|
||||||
{ */
|
|
||||||
.global _tx_thread_context_save
|
|
||||||
_tx_thread_context_save:
|
|
||||||
|
|
||||||
/* Upon entry to this routine, it is assumed that interrupts are locked
|
|
||||||
out and the interrupt stack fame has been allocated and x1 (ra) has
|
|
||||||
been saved on the stack. */
|
|
||||||
|
|
||||||
STORE t0, 19*REGBYTES(sp) // Save t0
|
|
||||||
STORE t1, 18*REGBYTES(sp) // Save t1
|
|
||||||
STORE x7, 17*REGBYTES(sp) // Save t2 before reusing it
|
|
||||||
STORE x28, 16*REGBYTES(sp) // Save t3 before reusing it
|
|
||||||
STORE x29, 15*REGBYTES(sp) // Save t4 before reusing it
|
|
||||||
|
|
||||||
csrr t2, mhartid // Pickup current hart ID
|
|
||||||
slli t3, t2, LOG_REGBYTES // Build per-hart ULONG offset
|
|
||||||
slli t4, t2, LOG_REGBYTES // Build per-hart pointer offset
|
|
||||||
la t1, _tx_thread_system_state // Pickup base of system state array
|
|
||||||
add t0, t1, t3 // Select this hart's system-state slot
|
|
||||||
LOAD t1, 0(t0) // Pickup system state
|
|
||||||
|
|
||||||
/* Check for a nested interrupt condition. */
|
|
||||||
/* if (_tx_thread_system_state++)
|
|
||||||
{ */
|
|
||||||
beqz t1, _tx_thread_not_nested_save // If 0, first interrupt condition
|
|
||||||
addi t1, t1, 1 // Increment the interrupt counter
|
|
||||||
STORE t1, 0(t0) // Store the interrupt counter
|
|
||||||
|
|
||||||
/* Nested interrupt condition.
|
|
||||||
Save the reset of the scratch registers on the stack and return to the
|
|
||||||
calling ISR. */
|
|
||||||
|
|
||||||
STORE x8, 12*REGBYTES(sp) // Store s0
|
|
||||||
STORE x10, 27*REGBYTES(sp) // Store a0
|
|
||||||
STORE x11, 26*REGBYTES(sp) // Store a1
|
|
||||||
STORE x12, 25*REGBYTES(sp) // Store a2
|
|
||||||
STORE x13, 24*REGBYTES(sp) // Store a3
|
|
||||||
STORE x14, 23*REGBYTES(sp) // Store a4
|
|
||||||
STORE x15, 22*REGBYTES(sp) // Store a5
|
|
||||||
STORE x16, 21*REGBYTES(sp) // Store a6
|
|
||||||
STORE x17, 20*REGBYTES(sp) // Store a7
|
|
||||||
STORE x30, 14*REGBYTES(sp) // Store t5
|
|
||||||
STORE x31, 13*REGBYTES(sp) // Store t6
|
|
||||||
csrr t0, mepc // Load exception program counter
|
|
||||||
STORE t0, 30*REGBYTES(sp) // Save it on the stack
|
|
||||||
|
|
||||||
/* Save floating point scratch registers. */
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_STORE f0, TX_INTERRUPT_FP_OFFSET(0)(sp) // Store ft0
|
|
||||||
TX_FP_STORE f1, TX_INTERRUPT_FP_OFFSET(1)(sp) // Store ft1
|
|
||||||
TX_FP_STORE f2, TX_INTERRUPT_FP_OFFSET(2)(sp) // Store ft2
|
|
||||||
TX_FP_STORE f3, TX_INTERRUPT_FP_OFFSET(3)(sp) // Store ft3
|
|
||||||
TX_FP_STORE f4, TX_INTERRUPT_FP_OFFSET(4)(sp) // Store ft4
|
|
||||||
TX_FP_STORE f5, TX_INTERRUPT_FP_OFFSET(5)(sp) // Store ft5
|
|
||||||
TX_FP_STORE f6, TX_INTERRUPT_FP_OFFSET(6)(sp) // Store ft6
|
|
||||||
TX_FP_STORE f7, TX_INTERRUPT_FP_OFFSET(7)(sp) // Store ft7
|
|
||||||
TX_FP_STORE f10, TX_INTERRUPT_FP_OFFSET(10)(sp) // Store fa0
|
|
||||||
TX_FP_STORE f11, TX_INTERRUPT_FP_OFFSET(11)(sp) // Store fa1
|
|
||||||
TX_FP_STORE f12, TX_INTERRUPT_FP_OFFSET(12)(sp) // Store fa2
|
|
||||||
TX_FP_STORE f13, TX_INTERRUPT_FP_OFFSET(13)(sp) // Store fa3
|
|
||||||
TX_FP_STORE f14, TX_INTERRUPT_FP_OFFSET(14)(sp) // Store fa4
|
|
||||||
TX_FP_STORE f15, TX_INTERRUPT_FP_OFFSET(15)(sp) // Store fa5
|
|
||||||
TX_FP_STORE f16, TX_INTERRUPT_FP_OFFSET(16)(sp) // Store fa6
|
|
||||||
TX_FP_STORE f17, TX_INTERRUPT_FP_OFFSET(17)(sp) // Store fa7
|
|
||||||
TX_FP_STORE f28, TX_INTERRUPT_FP_OFFSET(28)(sp) // Store ft8
|
|
||||||
TX_FP_STORE f29, TX_INTERRUPT_FP_OFFSET(29)(sp) // Store ft9
|
|
||||||
TX_FP_STORE f30, TX_INTERRUPT_FP_OFFSET(30)(sp) // Store ft10
|
|
||||||
TX_FP_STORE f31, TX_INTERRUPT_FP_OFFSET(31)(sp) // Store ft11
|
|
||||||
csrr t0, fcsr
|
|
||||||
STORE t0, TX_INTERRUPT_FCSR_OFFSET(sp) // Store fcsr
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
|
||||||
call _tx_execution_isr_enter // Call the ISR execution enter function
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ret // Return to calling ISR
|
|
||||||
|
|
||||||
_tx_thread_not_nested_save:
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
/* Otherwise, not nested, check to see if a thread was running. */
|
|
||||||
/* else if (_tx_thread_current_ptr)
|
|
||||||
{ */
|
|
||||||
addi t1, t1, 1 // Increment the interrupt counter
|
|
||||||
STORE t1, 0(t0) // Store the interrupt counter
|
|
||||||
|
|
||||||
/* Not nested: Find the user thread that was running and load our SP */
|
|
||||||
|
|
||||||
la t1, _tx_thread_current_ptr // Pickup base of current-thread array
|
|
||||||
add t0, t1, t4 // Select this hart's current-thread slot
|
|
||||||
LOAD t0, 0(t0) // Pickup current thread pointer
|
|
||||||
beqz t0, _tx_thread_idle_system_save // If NULL, idle system was interrupted
|
|
||||||
|
|
||||||
/* Save the standard scratch registers. */
|
|
||||||
|
|
||||||
STORE x8, 12*REGBYTES(sp) // Store s0
|
|
||||||
STORE x10, 27*REGBYTES(sp) // Store a0
|
|
||||||
STORE x11, 26*REGBYTES(sp) // Store a1
|
|
||||||
STORE x12, 25*REGBYTES(sp) // Store a2
|
|
||||||
STORE x13, 24*REGBYTES(sp) // Store a3
|
|
||||||
STORE x14, 23*REGBYTES(sp) // Store a4
|
|
||||||
STORE x15, 22*REGBYTES(sp) // Store a5
|
|
||||||
STORE x16, 21*REGBYTES(sp) // Store a6
|
|
||||||
STORE x17, 20*REGBYTES(sp) // Store a7
|
|
||||||
STORE x30, 14*REGBYTES(sp) // Store t5
|
|
||||||
STORE x31, 13*REGBYTES(sp) // Store t6
|
|
||||||
|
|
||||||
csrr t0, mepc // Load exception program counter
|
|
||||||
STORE t0, 30*REGBYTES(sp) // Save it on the stack
|
|
||||||
|
|
||||||
/* Save floating point scratch registers. */
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_STORE f0, TX_INTERRUPT_FP_OFFSET(0)(sp) // Store ft0
|
|
||||||
TX_FP_STORE f1, TX_INTERRUPT_FP_OFFSET(1)(sp) // Store ft1
|
|
||||||
TX_FP_STORE f2, TX_INTERRUPT_FP_OFFSET(2)(sp) // Store ft2
|
|
||||||
TX_FP_STORE f3, TX_INTERRUPT_FP_OFFSET(3)(sp) // Store ft3
|
|
||||||
TX_FP_STORE f4, TX_INTERRUPT_FP_OFFSET(4)(sp) // Store ft4
|
|
||||||
TX_FP_STORE f5, TX_INTERRUPT_FP_OFFSET(5)(sp) // Store ft5
|
|
||||||
TX_FP_STORE f6, TX_INTERRUPT_FP_OFFSET(6)(sp) // Store ft6
|
|
||||||
TX_FP_STORE f7, TX_INTERRUPT_FP_OFFSET(7)(sp) // Store ft7
|
|
||||||
TX_FP_STORE f10, TX_INTERRUPT_FP_OFFSET(10)(sp) // Store fa0
|
|
||||||
TX_FP_STORE f11, TX_INTERRUPT_FP_OFFSET(11)(sp) // Store fa1
|
|
||||||
TX_FP_STORE f12, TX_INTERRUPT_FP_OFFSET(12)(sp) // Store fa2
|
|
||||||
TX_FP_STORE f13, TX_INTERRUPT_FP_OFFSET(13)(sp) // Store fa3
|
|
||||||
TX_FP_STORE f14, TX_INTERRUPT_FP_OFFSET(14)(sp) // Store fa4
|
|
||||||
TX_FP_STORE f15, TX_INTERRUPT_FP_OFFSET(15)(sp) // Store fa5
|
|
||||||
TX_FP_STORE f16, TX_INTERRUPT_FP_OFFSET(16)(sp) // Store fa6
|
|
||||||
TX_FP_STORE f17, TX_INTERRUPT_FP_OFFSET(17)(sp) // Store fa7
|
|
||||||
TX_FP_STORE f28, TX_INTERRUPT_FP_OFFSET(28)(sp) // Store ft8
|
|
||||||
TX_FP_STORE f29, TX_INTERRUPT_FP_OFFSET(29)(sp) // Store ft9
|
|
||||||
TX_FP_STORE f30, TX_INTERRUPT_FP_OFFSET(30)(sp) // Store ft10
|
|
||||||
TX_FP_STORE f31, TX_INTERRUPT_FP_OFFSET(31)(sp) // Store ft11
|
|
||||||
csrr t0, fcsr
|
|
||||||
STORE t0, TX_INTERRUPT_FCSR_OFFSET(sp) // Store fcsr
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Save the current stack pointer in the thread's control block. */
|
|
||||||
/* _tx_thread_current_ptr -> tx_thread_stack_ptr = sp; */
|
|
||||||
|
|
||||||
/* Switch to the system stack. */
|
|
||||||
/* sp = _tx_thread_system_stack_ptr; */
|
|
||||||
|
|
||||||
la t0, _tx_thread_current_ptr // Pickup base of current-thread array
|
|
||||||
add t0, t0, t4 // Select this hart's current-thread slot
|
|
||||||
LOAD t1, 0(t0) // Pickup current thread pointer
|
|
||||||
STORE sp, 2*REGBYTES(t1) // Save stack pointer
|
|
||||||
|
|
||||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
|
||||||
/* _tx_execution_isr_enter is called with thread stack pointer */
|
|
||||||
call _tx_execution_isr_enter // Call the ISR execution enter function
|
|
||||||
#endif
|
|
||||||
|
|
||||||
la t0, _tx_thread_system_stack_ptr // Pickup base of system-stack array
|
|
||||||
add t0, t0, t4 // Select this hart's system-stack slot
|
|
||||||
LOAD sp, 0(t0) // Switch to system stack
|
|
||||||
ret // Return to calling ISR
|
|
||||||
|
|
||||||
/* }
|
|
||||||
else
|
|
||||||
{ */
|
|
||||||
|
|
||||||
_tx_thread_idle_system_save:
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
|
||||||
call _tx_execution_isr_enter // Call the ISR execution enter function
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Interrupt occurred in the scheduling loop. */
|
|
||||||
|
|
||||||
/* }
|
|
||||||
} */
|
|
||||||
addi sp, sp, TX_INTERRUPT_FRAME_SIZE
|
|
||||||
ret // Return to calling ISR
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Thread */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
RETURN_MASK = 0x000000000000000F
|
|
||||||
SET_SR_MASK = 0xFFFFFFFFFFFFFFF0
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_interrupt_control RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Scott Larson, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function is responsible for changing the interrupt lockout */
|
|
||||||
/* posture of the system. */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* new_posture New interrupt lockout posture */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* old_posture Old interrupt lockout posture */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* Application Code */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
/* UINT _tx_thread_interrupt_control(UINT new_posture)
|
|
||||||
{ */
|
|
||||||
.global _tx_thread_interrupt_control
|
|
||||||
_tx_thread_interrupt_control:
|
|
||||||
/* Pickup current interrupt lockout posture. */
|
|
||||||
|
|
||||||
csrr t0, mstatus
|
|
||||||
mv t1, t0 // Save original mstatus for return
|
|
||||||
|
|
||||||
/* Apply the new interrupt posture. */
|
|
||||||
|
|
||||||
li t2, SET_SR_MASK // Build set SR mask
|
|
||||||
and t0, t0, t2 // Isolate interrupt lockout bits
|
|
||||||
or t0, t0, a0 // Put new lockout bits in
|
|
||||||
csrw mstatus, t0
|
|
||||||
andi a0, t1, RETURN_MASK // Return original mstatus.
|
|
||||||
ret
|
|
||||||
/* } */
|
|
||||||
@@ -1,277 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Thread */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_schedule RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Scott Larson, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function waits for a thread control block pointer to appear in */
|
|
||||||
/* the _tx_thread_execute_ptr variable. Once a thread pointer appears */
|
|
||||||
/* in the variable, the corresponding thread is resumed. */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* _tx_initialize_kernel_enter ThreadX entry function */
|
|
||||||
/* _tx_thread_system_return Return to system from thread */
|
|
||||||
/* _tx_thread_context_restore Restore thread's context */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
/* VOID _tx_thread_schedule(VOID)
|
|
||||||
{ */
|
|
||||||
.global _tx_thread_schedule
|
|
||||||
_tx_thread_schedule:
|
|
||||||
|
|
||||||
/* Enable interrupts. */
|
|
||||||
csrsi mstatus, 0x08 // Enable interrupts
|
|
||||||
csrr t4, mhartid // Pickup the current hart ID
|
|
||||||
slli t4, t4, LOG_REGBYTES // Build per-hart byte offset
|
|
||||||
|
|
||||||
/* Wait for a thread to execute. */
|
|
||||||
/* do
|
|
||||||
{ */
|
|
||||||
|
|
||||||
la t0, _tx_thread_execute_ptr // Pickup address of execute ptr
|
|
||||||
add t0, t0, t4 // Select this hart's execute slot
|
|
||||||
_tx_thread_schedule_loop:
|
|
||||||
csrci mstatus, 0x08 // Lockout interrupts
|
|
||||||
LOAD t1, 0(t0) // Pickup next thread to execute
|
|
||||||
bnez t1, _tx_thread_schedule_thread // If non-NULL, continue
|
|
||||||
csrsi mstatus, 0x08 // Enable interrupts
|
|
||||||
#ifdef TX_ENABLE_WFI
|
|
||||||
wfi // Wait for interrupt
|
|
||||||
#endif
|
|
||||||
j _tx_thread_schedule_loop // Keep looking for a thread
|
|
||||||
|
|
||||||
_tx_thread_schedule_thread:
|
|
||||||
|
|
||||||
/* Atomically claim the thread's ready token so only one hart can
|
|
||||||
dispatch this TCB at a time. */
|
|
||||||
addi t2, t1, TX_THREAD_SMP_LOCK_READY_BIT_OFFSET // Pickup lock/ready-bit address
|
|
||||||
AMOSWAP_AQ t3, x0, (t2) // Clear it and fetch prior state
|
|
||||||
beqz t3, _tx_thread_schedule // If not ready, retry scheduling
|
|
||||||
|
|
||||||
/* }
|
|
||||||
while(_tx_thread_execute_ptr == TX_NULL); */
|
|
||||||
scheduler_found_thread:
|
|
||||||
|
|
||||||
/* Publish the current thread pointer for this hart, then re-check the
|
|
||||||
execute slot to avoid missing a concurrent execute-pointer update. */
|
|
||||||
|
|
||||||
la t5, _tx_thread_current_ptr // Pickup current thread pointer address
|
|
||||||
add t5, t5, t4 // Select this hart's current slot
|
|
||||||
STORE t1, 0(t5) // Set current thread pointer
|
|
||||||
fence rw, rw // Publish current thread pointer before re-check
|
|
||||||
LOAD t6, 0(t0) // Reload execute pointer for this hart
|
|
||||||
beq t1, t6, _execute_pointer_did_not_change // If unchanged, continue
|
|
||||||
|
|
||||||
/* Another core changed the execute slot after this hart claimed the
|
|
||||||
thread but before current-thread publication completed. Roll back
|
|
||||||
and restart so the new selection is not missed. */
|
|
||||||
STORE x0, 0(t5) // Clear current thread pointer
|
|
||||||
li t3, 1 // Rebuild ready token
|
|
||||||
AMOSWAP_RL x0, t3, (t2) // Restore ready token with release ordering
|
|
||||||
j _tx_thread_schedule_loop // Restart scheduling
|
|
||||||
|
|
||||||
_execute_pointer_did_not_change:
|
|
||||||
|
|
||||||
/* Increment the run count for this thread. */
|
|
||||||
/* _tx_thread_current_ptr -> tx_thread_run_count++; */
|
|
||||||
|
|
||||||
LOAD t2, 1*REGBYTES(t1) // Pickup run count
|
|
||||||
LOAD t3, 6*REGBYTES(t1) // Pickup time slice value
|
|
||||||
addi t2, t2, 1 // Increment run count
|
|
||||||
STORE t2, 1*REGBYTES(t1) // Store new run count
|
|
||||||
|
|
||||||
/* Setup time-slice for this hart, if present. */
|
|
||||||
|
|
||||||
la t2, _tx_timer_time_slice // Pickup time-slice variable address
|
|
||||||
add t2, t2, t4 // Select this hart's time-slice slot
|
|
||||||
|
|
||||||
/* Switch to the thread's stack. */
|
|
||||||
/* SP = _tx_thread_execute_ptr -> tx_thread_stack_ptr; */
|
|
||||||
|
|
||||||
LOAD sp, 2*REGBYTES(t1) // Switch to thread's stack
|
|
||||||
STORE t3, 0(t2) // Store new time-slice
|
|
||||||
|
|
||||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
|
||||||
|
|
||||||
call _tx_execution_thread_enter // Call the thread execution enter function
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Determine if an interrupt frame or a synchronous task suspension frame
|
|
||||||
is present. */
|
|
||||||
|
|
||||||
LOAD t2, 0(sp) // Pickup stack type
|
|
||||||
beqz t2, _tx_thread_synch_return // If 0, solicited thread return
|
|
||||||
|
|
||||||
/* Determine if floating point registers need to be recovered. */
|
|
||||||
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_LOAD f0, TX_INTERRUPT_FP_OFFSET(0)(sp) // Recover ft0
|
|
||||||
TX_FP_LOAD f1, TX_INTERRUPT_FP_OFFSET(1)(sp) // Recover ft1
|
|
||||||
TX_FP_LOAD f2, TX_INTERRUPT_FP_OFFSET(2)(sp) // Recover ft2
|
|
||||||
TX_FP_LOAD f3, TX_INTERRUPT_FP_OFFSET(3)(sp) // Recover ft3
|
|
||||||
TX_FP_LOAD f4, TX_INTERRUPT_FP_OFFSET(4)(sp) // Recover ft4
|
|
||||||
TX_FP_LOAD f5, TX_INTERRUPT_FP_OFFSET(5)(sp) // Recover ft5
|
|
||||||
TX_FP_LOAD f6, TX_INTERRUPT_FP_OFFSET(6)(sp) // Recover ft6
|
|
||||||
TX_FP_LOAD f7, TX_INTERRUPT_FP_OFFSET(7)(sp) // Recover ft7
|
|
||||||
TX_FP_LOAD f8, TX_INTERRUPT_FP_OFFSET(8)(sp) // Recover fs0
|
|
||||||
TX_FP_LOAD f9, TX_INTERRUPT_FP_OFFSET(9)(sp) // Recover fs1
|
|
||||||
TX_FP_LOAD f10, TX_INTERRUPT_FP_OFFSET(10)(sp) // Recover fa0
|
|
||||||
TX_FP_LOAD f11, TX_INTERRUPT_FP_OFFSET(11)(sp) // Recover fa1
|
|
||||||
TX_FP_LOAD f12, TX_INTERRUPT_FP_OFFSET(12)(sp) // Recover fa2
|
|
||||||
TX_FP_LOAD f13, TX_INTERRUPT_FP_OFFSET(13)(sp) // Recover fa3
|
|
||||||
TX_FP_LOAD f14, TX_INTERRUPT_FP_OFFSET(14)(sp) // Recover fa4
|
|
||||||
TX_FP_LOAD f15, TX_INTERRUPT_FP_OFFSET(15)(sp) // Recover fa5
|
|
||||||
TX_FP_LOAD f16, TX_INTERRUPT_FP_OFFSET(16)(sp) // Recover fa6
|
|
||||||
TX_FP_LOAD f17, TX_INTERRUPT_FP_OFFSET(17)(sp) // Recover fa7
|
|
||||||
TX_FP_LOAD f18, TX_INTERRUPT_FP_OFFSET(18)(sp) // Recover fs2
|
|
||||||
TX_FP_LOAD f19, TX_INTERRUPT_FP_OFFSET(19)(sp) // Recover fs3
|
|
||||||
TX_FP_LOAD f20, TX_INTERRUPT_FP_OFFSET(20)(sp) // Recover fs4
|
|
||||||
TX_FP_LOAD f21, TX_INTERRUPT_FP_OFFSET(21)(sp) // Recover fs5
|
|
||||||
TX_FP_LOAD f22, TX_INTERRUPT_FP_OFFSET(22)(sp) // Recover fs6
|
|
||||||
TX_FP_LOAD f23, TX_INTERRUPT_FP_OFFSET(23)(sp) // Recover fs7
|
|
||||||
TX_FP_LOAD f24, TX_INTERRUPT_FP_OFFSET(24)(sp) // Recover fs8
|
|
||||||
TX_FP_LOAD f25, TX_INTERRUPT_FP_OFFSET(25)(sp) // Recover fs9
|
|
||||||
TX_FP_LOAD f26, TX_INTERRUPT_FP_OFFSET(26)(sp) // Recover fs10
|
|
||||||
TX_FP_LOAD f27, TX_INTERRUPT_FP_OFFSET(27)(sp) // Recover fs11
|
|
||||||
TX_FP_LOAD f28, TX_INTERRUPT_FP_OFFSET(28)(sp) // Recover ft8
|
|
||||||
TX_FP_LOAD f29, TX_INTERRUPT_FP_OFFSET(29)(sp) // Recover ft9
|
|
||||||
TX_FP_LOAD f30, TX_INTERRUPT_FP_OFFSET(30)(sp) // Recover ft10
|
|
||||||
TX_FP_LOAD f31, TX_INTERRUPT_FP_OFFSET(31)(sp) // Recover ft11
|
|
||||||
LOAD t0, TX_INTERRUPT_FCSR_OFFSET(sp) // Recover fcsr
|
|
||||||
csrw fcsr, t0 //
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Recover standard registers. */
|
|
||||||
|
|
||||||
LOAD t0, 30*REGBYTES(sp) // Recover mepc
|
|
||||||
csrw mepc, t0 // Store mepc
|
|
||||||
li t0, 0x1880 // Prepare MPIP
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
li t1, 1<<13
|
|
||||||
or t0, t1, t0
|
|
||||||
#endif
|
|
||||||
csrw mstatus, t0 // Enable MPIP
|
|
||||||
|
|
||||||
LOAD x1, 28*REGBYTES(sp) // Recover RA
|
|
||||||
LOAD x5, 19*REGBYTES(sp) // Recover t0
|
|
||||||
LOAD x6, 18*REGBYTES(sp) // Recover t1
|
|
||||||
LOAD x7, 17*REGBYTES(sp) // Recover t2
|
|
||||||
LOAD x8, 12*REGBYTES(sp) // Recover s0
|
|
||||||
LOAD x9, 11*REGBYTES(sp) // Recover s1
|
|
||||||
LOAD x10, 27*REGBYTES(sp) // Recover a0
|
|
||||||
LOAD x11, 26*REGBYTES(sp) // Recover a1
|
|
||||||
LOAD x12, 25*REGBYTES(sp) // Recover a2
|
|
||||||
LOAD x13, 24*REGBYTES(sp) // Recover a3
|
|
||||||
LOAD x14, 23*REGBYTES(sp) // Recover a4
|
|
||||||
LOAD x15, 22*REGBYTES(sp) // Recover a5
|
|
||||||
LOAD x16, 21*REGBYTES(sp) // Recover a6
|
|
||||||
LOAD x17, 20*REGBYTES(sp) // Recover a7
|
|
||||||
LOAD x18, 10*REGBYTES(sp) // Recover s2
|
|
||||||
LOAD x19, 9*REGBYTES(sp) // Recover s3
|
|
||||||
LOAD x20, 8*REGBYTES(sp) // Recover s4
|
|
||||||
LOAD x21, 7*REGBYTES(sp) // Recover s5
|
|
||||||
LOAD x22, 6*REGBYTES(sp) // Recover s6
|
|
||||||
LOAD x23, 5*REGBYTES(sp) // Recover s7
|
|
||||||
LOAD x24, 4*REGBYTES(sp) // Recover s8
|
|
||||||
LOAD x25, 3*REGBYTES(sp) // Recover s9
|
|
||||||
LOAD x26, 2*REGBYTES(sp) // Recover s10
|
|
||||||
LOAD x27, 1*REGBYTES(sp) // Recover s11
|
|
||||||
LOAD x28, 16*REGBYTES(sp) // Recover t3
|
|
||||||
LOAD x29, 15*REGBYTES(sp) // Recover t4
|
|
||||||
LOAD x30, 14*REGBYTES(sp) // Recover t5
|
|
||||||
LOAD x31, 13*REGBYTES(sp) // Recover t6
|
|
||||||
|
|
||||||
addi sp, sp, TX_INTERRUPT_FRAME_SIZE
|
|
||||||
mret // Return to point of interrupt
|
|
||||||
|
|
||||||
_tx_thread_synch_return:
|
|
||||||
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_LOAD f8, TX_SOLICITED_FP_OFFSET(0)(sp) // Recover fs0
|
|
||||||
TX_FP_LOAD f9, TX_SOLICITED_FP_OFFSET(1)(sp) // Recover fs1
|
|
||||||
TX_FP_LOAD f18, TX_SOLICITED_FP_OFFSET(2)(sp) // Recover fs2
|
|
||||||
TX_FP_LOAD f19, TX_SOLICITED_FP_OFFSET(3)(sp) // Recover fs3
|
|
||||||
TX_FP_LOAD f20, TX_SOLICITED_FP_OFFSET(4)(sp) // Recover fs4
|
|
||||||
TX_FP_LOAD f21, TX_SOLICITED_FP_OFFSET(5)(sp) // Recover fs5
|
|
||||||
TX_FP_LOAD f22, TX_SOLICITED_FP_OFFSET(6)(sp) // Recover fs6
|
|
||||||
TX_FP_LOAD f23, TX_SOLICITED_FP_OFFSET(7)(sp) // Recover fs7
|
|
||||||
TX_FP_LOAD f24, TX_SOLICITED_FP_OFFSET(8)(sp) // Recover fs8
|
|
||||||
TX_FP_LOAD f25, TX_SOLICITED_FP_OFFSET(9)(sp) // Recover fs9
|
|
||||||
TX_FP_LOAD f26, TX_SOLICITED_FP_OFFSET(10)(sp) // Recover fs10
|
|
||||||
TX_FP_LOAD f27, TX_SOLICITED_FP_OFFSET(11)(sp) // Recover fs11
|
|
||||||
LOAD t0, TX_SOLICITED_FCSR_OFFSET(sp) // Recover fcsr
|
|
||||||
csrw fcsr, t0 //
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Recover standard preserved registers. */
|
|
||||||
/* Recover standard registers. */
|
|
||||||
|
|
||||||
LOAD x1, 13*REGBYTES(sp) // Recover RA
|
|
||||||
LOAD x8, 12*REGBYTES(sp) // Recover s0
|
|
||||||
LOAD x9, 11*REGBYTES(sp) // Recover s1
|
|
||||||
LOAD x18, 10*REGBYTES(sp) // Recover s2
|
|
||||||
LOAD x19, 9*REGBYTES(sp) // Recover s3
|
|
||||||
LOAD x20, 8*REGBYTES(sp) // Recover s4
|
|
||||||
LOAD x21, 7*REGBYTES(sp) // Recover s5
|
|
||||||
LOAD x22, 6*REGBYTES(sp) // Recover s6
|
|
||||||
LOAD x23, 5*REGBYTES(sp) // Recover s7
|
|
||||||
LOAD x24, 4*REGBYTES(sp) // Recover s8
|
|
||||||
LOAD x25, 3*REGBYTES(sp) // Recover s9
|
|
||||||
LOAD x26, 2*REGBYTES(sp) // Recover s10
|
|
||||||
LOAD x27, 1*REGBYTES(sp) // Recover s11
|
|
||||||
LOAD t0, 14*REGBYTES(sp) // Recover mstatus
|
|
||||||
csrw mstatus, t0 // Store mstatus, enables interrupt
|
|
||||||
addi sp, sp, TX_SOLICITED_FRAME_SIZE
|
|
||||||
synch_return_exit_label:
|
|
||||||
ret // Return to thread
|
|
||||||
|
|
||||||
/* } */
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
.align 2
|
|
||||||
|
|
||||||
.global _tx_thread_smp_core_get
|
|
||||||
.type _tx_thread_smp_core_get, @function
|
|
||||||
_tx_thread_smp_core_get:
|
|
||||||
csrr a0, mhartid // Pickup the current hart ID
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#include <aclint_ipi.h>
|
|
||||||
#include <tx_port.h>
|
|
||||||
void _tx_thread_smp_core_preempt(UINT target_core)
|
|
||||||
{
|
|
||||||
send_ipi(target_core);
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
.align 2
|
|
||||||
|
|
||||||
.global _tx_thread_smp_current_state_get
|
|
||||||
.type _tx_thread_smp_current_state_get, @function
|
|
||||||
_tx_thread_smp_current_state_get:
|
|
||||||
csrr t0, mhartid // Pickup current hart ID
|
|
||||||
la t1, _tx_thread_system_state // Base of per-hart system-state array
|
|
||||||
slli t0, t0, LOG_REGBYTES // Build offset into array
|
|
||||||
add t1, t1, t0 // Select this hart's slot
|
|
||||||
LOAD a0, 0(t1) // Return current system state
|
|
||||||
ret
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
.align 2
|
|
||||||
|
|
||||||
.global _tx_thread_smp_current_thread_get
|
|
||||||
.type _tx_thread_smp_current_thread_get, @function
|
|
||||||
_tx_thread_smp_current_thread_get:
|
|
||||||
csrr t0, mstatus // Pickup current interrupt posture
|
|
||||||
csrci mstatus, 0x08 // Lockout interrupts
|
|
||||||
|
|
||||||
csrr t1, mhartid // Pickup current hart ID
|
|
||||||
la t2, _tx_thread_current_ptr // Base of current-thread pointer array
|
|
||||||
slli t1, t1, LOG_REGBYTES // Build per-hart byte offset
|
|
||||||
add t2, t2, t1 // Select this hart's slot
|
|
||||||
LOAD a0, 0(t2) // Pickup current thread pointer
|
|
||||||
|
|
||||||
csrw mstatus, t0 // Restore interrupt posture
|
|
||||||
ret
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
#include "tx_port.h"
|
|
||||||
#include "csr.h"
|
|
||||||
.section .text
|
|
||||||
.align 2
|
|
||||||
|
|
||||||
.global _tx_thread_smp_initialize_wait
|
|
||||||
.type _tx_thread_smp_initialize_wait, @function
|
|
||||||
.extern _tx_thread_schedule
|
|
||||||
_tx_thread_smp_initialize_wait:
|
|
||||||
|
|
||||||
/* Lockout interrupts while startup synchronization is in progress. */
|
|
||||||
csrci mstatus, 0x08 // Lockout interrupts
|
|
||||||
|
|
||||||
/* Pickup current hart ID. */
|
|
||||||
csrr t0, mhartid // Pickup current hart ID
|
|
||||||
beqz t0, _tx_thread_smp_initialize_done // Core 0 does not wait
|
|
||||||
|
|
||||||
/* Build per-hart offsets for ULONG and pointer arrays. */
|
|
||||||
slli t1, t0, LOG_REGBYTES // ULONG array offset
|
|
||||||
slli t2, t0, LOG_REGBYTES // Pointer array offset
|
|
||||||
|
|
||||||
/* Wait until ThreadX has acknowledged this hart by setting its
|
|
||||||
system state to TX_INITIALIZE_IN_PROGRESS. */
|
|
||||||
li t3, 0xF0F0F0F0 // TX_INITIALIZE_IN_PROGRESS
|
|
||||||
#if __riscv_xlen == 64
|
|
||||||
slli t3, t3, 32
|
|
||||||
srli t3, t3, 32
|
|
||||||
#endif
|
|
||||||
la t4, _tx_thread_system_state // Base of system state array
|
|
||||||
add t5, t4, t1 // This hart's system state slot
|
|
||||||
|
|
||||||
_tx_thread_smp_wait_for_initialize:
|
|
||||||
LOAD t6, 0(t5) // Pickup current hart's system state
|
|
||||||
bne t6, t3, _tx_thread_smp_wait_for_initialize
|
|
||||||
|
|
||||||
/* Save the system stack pointer for this hart. */
|
|
||||||
la t3, _tx_thread_system_stack_ptr // Base of system stack pointer array
|
|
||||||
add t3, t3, t2 // Select this hart's slot
|
|
||||||
STORE sp, 0(t3) // Save system stack pointer
|
|
||||||
|
|
||||||
/* Wait for core 0 to release the secondary harts. */
|
|
||||||
la t3, _tx_thread_smp_release_cores_flag // Release flag address
|
|
||||||
|
|
||||||
_tx_thread_smp_wait_for_release:
|
|
||||||
LOAD t6, 0(t3) // Pickup release flag
|
|
||||||
beqz t6, _tx_thread_smp_wait_for_release
|
|
||||||
|
|
||||||
/* Acknowledge the release by clearing this hart's system state. */
|
|
||||||
STORE x0, 0(t5) // Set this hart's system state to zero
|
|
||||||
|
|
||||||
/* Wait for core 0 to finish initialization. */
|
|
||||||
_tx_thread_smp_wait_for_core0:
|
|
||||||
LOAD t6, 0(t4) // Pickup core 0 system state
|
|
||||||
bnez t6, _tx_thread_smp_wait_for_core0
|
|
||||||
|
|
||||||
/* Prepare interrupt state */
|
|
||||||
li t0, MSTATUS_MIE
|
|
||||||
csrrc zero, mstatus, t0 // clear MSTATUS_MIE bit
|
|
||||||
li t0, (MSTATUS_MPP_M | MSTATUS_MPIE )
|
|
||||||
csrrs zero, mstatus, t0 // set MSTATUS_MPP, MPIE bit
|
|
||||||
li t0, (MIE_MTIE | MIE_MSIE | MIE_MEIE)
|
|
||||||
csrrs zero, mie, t0 // set mie
|
|
||||||
#ifdef __riscv_flen
|
|
||||||
li t0, MSTATUS_FS
|
|
||||||
csrrs zero, mstatus, t0 // set MSTATUS_FS bit to open f/d isa in riscv
|
|
||||||
fscsr x0
|
|
||||||
#endif
|
|
||||||
la t0, trap_entry
|
|
||||||
csrw mtvec, t0
|
|
||||||
|
|
||||||
/* Initialization is complete for this hart, enter the scheduler. */
|
|
||||||
j _tx_thread_schedule
|
|
||||||
|
|
||||||
_tx_thread_smp_initialize_done:
|
|
||||||
ret
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
.align 2
|
|
||||||
|
|
||||||
.global _tx_thread_smp_low_level_initialize
|
|
||||||
.type _tx_thread_smp_low_level_initialize, @function
|
|
||||||
_tx_thread_smp_low_level_initialize:
|
|
||||||
ret
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
.align 2
|
|
||||||
|
|
||||||
.global _tx_thread_smp_protect
|
|
||||||
.type _tx_thread_smp_protect, @function
|
|
||||||
_tx_thread_smp_protect:
|
|
||||||
|
|
||||||
/* Disable interrupts so we don't get preempted. */
|
|
||||||
csrr a0, mstatus // Pickup current interrupt posture
|
|
||||||
csrci mstatus, 0x08 // Lockout interrupts
|
|
||||||
|
|
||||||
/* Pickup the hart ID. */
|
|
||||||
csrr t2, mhartid // Pickup the current hart ID
|
|
||||||
|
|
||||||
/* Build address to protection structure. */
|
|
||||||
la t1, _tx_thread_smp_protection
|
|
||||||
|
|
||||||
/* If this hart already owns protection, just nest the count. */
|
|
||||||
LOAD t3, 1*REGBYTES(t1) // Pickup owning hart
|
|
||||||
beq t3, t2, _owned // Already owned by this hart
|
|
||||||
|
|
||||||
/* Try to get the protection. */
|
|
||||||
LOAD t4, 0(t1) // Pickup protection flag
|
|
||||||
bnez t4, _protection_busy // If set, protection is busy
|
|
||||||
li t4, 1 // Build lock value
|
|
||||||
AMOSWAP_AQ t5, t4, (t1) // Attempt to get protection
|
|
||||||
bnez t5, _protection_busy // If old value != 0, retry
|
|
||||||
|
|
||||||
fence rw, rw // Ensure lock acquisition is visible
|
|
||||||
STORE t2, 1*REGBYTES(t1) // Save owning hart
|
|
||||||
|
|
||||||
_owned:
|
|
||||||
LOAD t5, 2*REGBYTES(t1) // Pickup ownership count
|
|
||||||
addi t5, t5, 1 // Increment ownership count
|
|
||||||
STORE t5, 2*REGBYTES(t1) // Store ownership count
|
|
||||||
fence rw, rw // Publish owner/count before return
|
|
||||||
ret
|
|
||||||
|
|
||||||
_protection_busy:
|
|
||||||
csrw mstatus, a0 // Restore interrupts
|
|
||||||
j _tx_thread_smp_protect // Restart the protection attempt
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
.align 2
|
|
||||||
|
|
||||||
.global _tx_thread_smp_unprotect
|
|
||||||
.type _tx_thread_smp_unprotect, @function
|
|
||||||
_tx_thread_smp_unprotect:
|
|
||||||
|
|
||||||
/* Lockout interrupts while protection state is updated. */
|
|
||||||
csrci mstatus, 0x08 // Lockout interrupts
|
|
||||||
|
|
||||||
/* Pickup the current hart ID. */
|
|
||||||
csrr t1, mhartid // Pickup hart ID
|
|
||||||
|
|
||||||
/* Build address of protection structure. */
|
|
||||||
la t2, _tx_thread_smp_protection
|
|
||||||
|
|
||||||
/* Only the owning hart may release the protection. */
|
|
||||||
LOAD t3, 1*REGBYTES(t2) // Pickup owning hart
|
|
||||||
bne t1, t3, _still_protected // Not owner, skip release
|
|
||||||
|
|
||||||
/* Pickup and decrement the protection count. */
|
|
||||||
LOAD t3, 2*REGBYTES(t2) // Pickup protection count
|
|
||||||
beqz t3, _still_protected // Already cleared
|
|
||||||
addi t3, t3, -1 // Decrement protection count
|
|
||||||
STORE t3, 2*REGBYTES(t2) // Store new count
|
|
||||||
bnez t3, _still_protected // Still nested, stay protected
|
|
||||||
|
|
||||||
/* If preemption is disabled, keep protection in force. */
|
|
||||||
la t4, _tx_thread_preempt_disable
|
|
||||||
LWU t5, 0(t4) // Pickup preempt disable
|
|
||||||
bnez t5, _still_protected // Skip protection release
|
|
||||||
|
|
||||||
/* Release the protection. */
|
|
||||||
li t3, -1 // Invalid owner value
|
|
||||||
STORE t3, 1*REGBYTES(t2) // Mark owning hart invalid
|
|
||||||
AMOSWAP_RL x0, x0, (t2) // Release protection flag
|
|
||||||
|
|
||||||
_still_protected:
|
|
||||||
csrw mstatus, a0 // Restore interrupt posture
|
|
||||||
ret
|
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Thread */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_stack_build RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Scott Larson, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function builds a stack frame on the supplied thread's stack. */
|
|
||||||
/* The stack frame results in a fake interrupt return to the supplied */
|
|
||||||
/* function pointer. */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* thread_ptr Pointer to thread control blk */
|
|
||||||
/* function_ptr Pointer to return function */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_create Create thread service */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
/* VOID _tx_thread_stack_build(TX_THREAD *thread_ptr, VOID (*function_ptr)(VOID))
|
|
||||||
{ */
|
|
||||||
.global _tx_thread_stack_build
|
|
||||||
_tx_thread_stack_build:
|
|
||||||
|
|
||||||
/* Build a fake interrupt frame using this port's inc/tx_context_layout.h,
|
|
||||||
included through tx_port.h. Integer slot indices below are multiplied
|
|
||||||
by REGBYTES to obtain byte offsets from the saved stack pointer.
|
|
||||||
Reg Integer slot
|
|
||||||
Stack Top: 1 0 Interrupt stack frame type
|
|
||||||
x27 1 Initial s11
|
|
||||||
x26 2 Initial s10
|
|
||||||
x25 3 Initial s9
|
|
||||||
x24 4 Initial s8
|
|
||||||
x23 5 Initial s7
|
|
||||||
x22 6 Initial s6
|
|
||||||
x21 7 Initial s5
|
|
||||||
x20 8 Initial s4
|
|
||||||
x19 9 Initial s3
|
|
||||||
x18 10 Initial s2
|
|
||||||
x9 11 Initial s1
|
|
||||||
x8 12 Initial s0
|
|
||||||
x31 13 Initial t6
|
|
||||||
x30 14 Initial t5
|
|
||||||
x29 15 Initial t4
|
|
||||||
x28 16 Initial t3
|
|
||||||
x7 17 Initial t2
|
|
||||||
x6 18 Initial t1
|
|
||||||
x5 19 Initial t0
|
|
||||||
x17 20 Initial a7
|
|
||||||
x16 21 Initial a6
|
|
||||||
x15 22 Initial a5
|
|
||||||
x14 23 Initial a4
|
|
||||||
x13 24 Initial a3
|
|
||||||
x12 25 Initial a2
|
|
||||||
x11 26 Initial a1
|
|
||||||
x10 27 Initial a0
|
|
||||||
x1 28 Initial ra
|
|
||||||
-- 29 reserved
|
|
||||||
mepc 30 Initial mepc
|
|
||||||
-- 31 Alignment padding
|
|
||||||
|
|
||||||
With FP support, f0..f31 follow at TX_INTERRUPT_FP_BASE. Each register
|
|
||||||
occupies TX_FP_BYTES bytes; fN is at TX_INTERRUPT_FP_OFFSET(N). The
|
|
||||||
fcsr slot is at TX_INTERRUPT_FCSR_OFFSET and occupies REGBYTES bytes.
|
|
||||||
Trailing padding rounds the frame size up to a multiple of 16 bytes.
|
|
||||||
Without FP support, the frame ends after integer slot 31.
|
|
||||||
|
|
||||||
Stack Bottom: saved stack pointer + TX_INTERRUPT_FRAME_SIZE
|
|
||||||
(higher memory address) */
|
|
||||||
|
|
||||||
LOAD t0, 4*REGBYTES(a0) // Pickup end of stack area
|
|
||||||
andi t0, t0, -16 // Ensure 16-byte alignment
|
|
||||||
|
|
||||||
/* Actually build the stack frame. */
|
|
||||||
|
|
||||||
addi t0, t0, -TX_INTERRUPT_FRAME_SIZE
|
|
||||||
/* Clear the whole frame, including both halves of RV32D FP slots. */
|
|
||||||
mv t1, t0
|
|
||||||
addi t2, t0, TX_INTERRUPT_FRAME_SIZE
|
|
||||||
.Lclear_initial_context:
|
|
||||||
STORE x0, 0(t1)
|
|
||||||
addi t1, t1, REGBYTES
|
|
||||||
bltu t1, t2, .Lclear_initial_context
|
|
||||||
|
|
||||||
li t1, 1 // Build stack type
|
|
||||||
STORE t1, 0*REGBYTES(t0) // Place stack type on the top
|
|
||||||
STORE a1, 30*REGBYTES(t0) // Initial mepc
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
csrr a1, fcsr
|
|
||||||
STORE a1, TX_INTERRUPT_FCSR_OFFSET(t0) // Initial fcsr
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Setup stack pointer. */
|
|
||||||
/* thread_ptr -> tx_thread_stack_ptr = t0; */
|
|
||||||
|
|
||||||
STORE t0, 2*REGBYTES(a0) // Save stack pointer in thread's
|
|
||||||
addi t1, x0, 1 // Build ready flag
|
|
||||||
STORE t1, TX_THREAD_SMP_LOCK_READY_BIT_OFFSET(a0) // Set ready flag
|
|
||||||
ret // control block and return
|
|
||||||
/* } */
|
|
||||||
@@ -1,179 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Thread */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
#include "tx_port.h"
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_system_return RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Scott Larson, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function is target processor specific. It is used to transfer */
|
|
||||||
/* control from a thread back to the system. Only a minimal context */
|
|
||||||
/* is saved since the compiler assumes temp registers are going to get */
|
|
||||||
/* slicked by a function call anyway. */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* _tx_thread_schedule Thread scheduling loop */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* ThreadX components */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
/* VOID _tx_thread_system_return(VOID)
|
|
||||||
{ */
|
|
||||||
.global _tx_thread_system_return
|
|
||||||
_tx_thread_system_return:
|
|
||||||
|
|
||||||
/* Save minimal context on the stack. */
|
|
||||||
|
|
||||||
addi sp, sp, -TX_SOLICITED_FRAME_SIZE
|
|
||||||
|
|
||||||
/* Store floating point preserved registers. */
|
|
||||||
#if TX_CONTEXT_FP_ENABLED
|
|
||||||
TX_FP_STORE f8, TX_SOLICITED_FP_OFFSET(0)(sp) // Store fs0
|
|
||||||
TX_FP_STORE f9, TX_SOLICITED_FP_OFFSET(1)(sp) // Store fs1
|
|
||||||
TX_FP_STORE f18, TX_SOLICITED_FP_OFFSET(2)(sp) // Store fs2
|
|
||||||
TX_FP_STORE f19, TX_SOLICITED_FP_OFFSET(3)(sp) // Store fs3
|
|
||||||
TX_FP_STORE f20, TX_SOLICITED_FP_OFFSET(4)(sp) // Store fs4
|
|
||||||
TX_FP_STORE f21, TX_SOLICITED_FP_OFFSET(5)(sp) // Store fs5
|
|
||||||
TX_FP_STORE f22, TX_SOLICITED_FP_OFFSET(6)(sp) // Store fs6
|
|
||||||
TX_FP_STORE f23, TX_SOLICITED_FP_OFFSET(7)(sp) // Store fs7
|
|
||||||
TX_FP_STORE f24, TX_SOLICITED_FP_OFFSET(8)(sp) // Store fs8
|
|
||||||
TX_FP_STORE f25, TX_SOLICITED_FP_OFFSET(9)(sp) // Store fs9
|
|
||||||
TX_FP_STORE f26, TX_SOLICITED_FP_OFFSET(10)(sp) // Store fs10
|
|
||||||
TX_FP_STORE f27, TX_SOLICITED_FP_OFFSET(11)(sp) // Store fs11
|
|
||||||
csrr t0, fcsr
|
|
||||||
STORE t0, TX_SOLICITED_FCSR_OFFSET(sp) // Store fcsr
|
|
||||||
#endif
|
|
||||||
|
|
||||||
STORE x0, 0(sp) // Solicited stack type
|
|
||||||
STORE x1, 13*REGBYTES(sp) // Save RA
|
|
||||||
STORE x8, 12*REGBYTES(sp) // Save s0
|
|
||||||
STORE x9, 11*REGBYTES(sp) // Save s1
|
|
||||||
STORE x18, 10*REGBYTES(sp) // Save s2
|
|
||||||
STORE x19, 9*REGBYTES(sp) // Save s3
|
|
||||||
STORE x20, 8*REGBYTES(sp) // Save s4
|
|
||||||
STORE x21, 7*REGBYTES(sp) // Save s5
|
|
||||||
STORE x22, 6*REGBYTES(sp) // Save s6
|
|
||||||
STORE x23, 5*REGBYTES(sp) // Save s7
|
|
||||||
STORE x24, 4*REGBYTES(sp) // Save s8
|
|
||||||
STORE x25, 3*REGBYTES(sp) // Save s9
|
|
||||||
STORE x26, 2*REGBYTES(sp) // Save s10
|
|
||||||
STORE x27, 1*REGBYTES(sp) // Save s11
|
|
||||||
csrr t0, mstatus // Pickup mstatus
|
|
||||||
STORE t0, 14*REGBYTES(sp) // Save mstatus
|
|
||||||
|
|
||||||
|
|
||||||
/* Lockout interrupts. - will be enabled in _tx_thread_schedule */
|
|
||||||
|
|
||||||
csrci mstatus, 0xF
|
|
||||||
|
|
||||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
|
||||||
|
|
||||||
call _tx_execution_thread_exit // Call the thread execution exit function
|
|
||||||
#endif
|
|
||||||
|
|
||||||
csrr t5, mhartid // Pickup current hart ID
|
|
||||||
slli t6, t5, LOG_REGBYTES // Build per-hart ULONG offset
|
|
||||||
slli t5, t5, LOG_REGBYTES // Build per-hart pointer offset
|
|
||||||
|
|
||||||
la t0, _tx_thread_current_ptr // Pickup base of current-thread array
|
|
||||||
add t0, t0, t5 // Select this hart's current-thread slot
|
|
||||||
LOAD t1, 0(t0) // Pickup current thread pointer
|
|
||||||
la t2, _tx_thread_system_stack_ptr // Pickup base of system-stack array
|
|
||||||
|
|
||||||
/* Save current stack and switch to system stack. */
|
|
||||||
/* _tx_thread_current_ptr -> tx_thread_stack_ptr = SP;
|
|
||||||
SP = _tx_thread_system_stack_ptr; */
|
|
||||||
|
|
||||||
STORE sp, 2*REGBYTES(t1) // Save stack pointer
|
|
||||||
add t2, t2, t5 // Select this hart's system-stack slot
|
|
||||||
LOAD sp, 0(t2) // Switch to system stack
|
|
||||||
|
|
||||||
/* Determine if the time-slice is active. */
|
|
||||||
/* if (_tx_timer_time_slice)
|
|
||||||
{ */
|
|
||||||
|
|
||||||
la t4, _tx_timer_time_slice // Pickup base of time-slice array
|
|
||||||
add t4, t4, t6 // Select this hart's time-slice slot
|
|
||||||
LOAD t3, 0(t4) // Pickup time slice value
|
|
||||||
la t2, _tx_thread_schedule // Pickup address of scheduling loop
|
|
||||||
beqz t3, _tx_thread_dont_save_ts // If no time-slice, don't save it
|
|
||||||
|
|
||||||
/* Save time-slice for the thread and clear the current time-slice. */
|
|
||||||
/* _tx_thread_current_ptr -> tx_thread_time_slice = _tx_timer_time_slice;
|
|
||||||
_tx_timer_time_slice = 0; */
|
|
||||||
|
|
||||||
STORE t3, 6*REGBYTES(t1) // Save current time-slice for thread
|
|
||||||
STORE x0, 0(t4) // Clear time-slice variable
|
|
||||||
|
|
||||||
/* } */
|
|
||||||
_tx_thread_dont_save_ts:
|
|
||||||
|
|
||||||
/* Clear the current thread pointer. */
|
|
||||||
/* _tx_thread_current_ptr = TX_NULL; */
|
|
||||||
|
|
||||||
STORE x0, 0(t0) // Clear current thread pointer
|
|
||||||
|
|
||||||
/* Make the thread runnable again before returning to the scheduler. */
|
|
||||||
fence rw, rw // Publish current-thread clear before ready token
|
|
||||||
addi t3, t1, TX_THREAD_SMP_LOCK_READY_BIT_OFFSET // Pickup lock/ready-bit address
|
|
||||||
li t4, 1 // Build ready token
|
|
||||||
AMOSWAP_RL x0, t4, (t3) // Restore ready token
|
|
||||||
|
|
||||||
/* Clear protection state. */
|
|
||||||
la t3, _tx_thread_preempt_disable // Pickup preempt-disable address
|
|
||||||
sw x0, 0(t3) // Clear preempt disable flag
|
|
||||||
|
|
||||||
la t3, _tx_thread_smp_protection // Pickup protection structure
|
|
||||||
STORE x0, 2*REGBYTES(t3) // Clear protection count
|
|
||||||
li t4, -1 // Build invalid owner value
|
|
||||||
STORE t4, 1*REGBYTES(t3) // Invalidate owning hart
|
|
||||||
fence rw, rw // Ensure shared accesses complete before unlock
|
|
||||||
STORE x0, 0(t3) // Clear protection in-force flag
|
|
||||||
jr t2 // Return to thread scheduler
|
|
||||||
|
|
||||||
/* } */
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
/** */
|
|
||||||
/** ThreadX Component */
|
|
||||||
/** */
|
|
||||||
/** Timer */
|
|
||||||
/** */
|
|
||||||
/**************************************************************************/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
#define TX_SOURCE_CODE
|
|
||||||
#define TX_THREAD_SMP_SOURCE_CODE
|
|
||||||
|
|
||||||
/* Include necessary system files. */
|
|
||||||
|
|
||||||
#include "tx_api.h"
|
|
||||||
#include "tx_thread.h"
|
|
||||||
#include "tx_timer.h"
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* _tx_timer_interrupt RISC-V64/GNU */
|
|
||||||
/* 6.2.1 */
|
|
||||||
/* AUTHOR */
|
|
||||||
/* */
|
|
||||||
/* Scott Larson, Microsoft Corporation */
|
|
||||||
/* */
|
|
||||||
/* DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* This function processes the hardware timer interrupt. This */
|
|
||||||
/* processing includes incrementing the system clock and checking for */
|
|
||||||
/* time slice and/or timer expiration. If either is found, the */
|
|
||||||
/* interrupt context save/restore functions are called along with the */
|
|
||||||
/* expiration functions. */
|
|
||||||
/* */
|
|
||||||
/* INPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* OUTPUT */
|
|
||||||
/* */
|
|
||||||
/* None */
|
|
||||||
/* */
|
|
||||||
/* CALLS */
|
|
||||||
/* */
|
|
||||||
/* _tx_timer_expiration_process Timer expiration processing */
|
|
||||||
/* _tx_thread_time_slice Time slice interrupted thread */
|
|
||||||
/* */
|
|
||||||
/* CALLED BY */
|
|
||||||
/* */
|
|
||||||
/* interrupt vector */
|
|
||||||
/* */
|
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
VOID _tx_timer_interrupt(VOID)
|
|
||||||
{
|
|
||||||
UINT saved_posture;
|
|
||||||
|
|
||||||
|
|
||||||
/* Only core 0 advances the global timer wheel. */
|
|
||||||
if (TX_SMP_CORE_ID != ((UINT) 0))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the protection. */
|
|
||||||
saved_posture = _tx_thread_smp_protect();
|
|
||||||
|
|
||||||
/* Indicate timer interrupt processing is active. */
|
|
||||||
_tx_timer_interrupt_active++;
|
|
||||||
|
|
||||||
/* Increment system clock. */
|
|
||||||
_tx_timer_system_clock++;
|
|
||||||
|
|
||||||
/* Test for timer expiration. */
|
|
||||||
if (*_tx_timer_current_ptr)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Set expiration flag. */
|
|
||||||
_tx_timer_expired = TX_TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
/* No timer expired, increment the timer pointer. */
|
|
||||||
_tx_timer_current_ptr++;
|
|
||||||
|
|
||||||
/* Check for wrap-around. */
|
|
||||||
if (_tx_timer_current_ptr == _tx_timer_list_end)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Wrap to beginning of list. */
|
|
||||||
_tx_timer_current_ptr = _tx_timer_list_start;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Did a timer expire? */
|
|
||||||
if (_tx_timer_expired)
|
|
||||||
{
|
|
||||||
/* Process timer expiration. */
|
|
||||||
_tx_timer_expiration_process();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Process time-slice expiration for all cores. */
|
|
||||||
_tx_thread_time_slice();
|
|
||||||
|
|
||||||
/* Timer interrupt processing is no longer active. */
|
|
||||||
_tx_timer_interrupt_active--;
|
|
||||||
|
|
||||||
/* Release the protection. */
|
|
||||||
_tx_thread_smp_unprotect(saved_posture);
|
|
||||||
}
|
|
||||||
+5
-5
@@ -137,11 +137,11 @@ void thread_0_entry(ULONG thread_input)
|
|||||||
|
|
||||||
UINT status;
|
UINT status;
|
||||||
NX_PACKET* my_packet;
|
NX_PACKET* my_packet;
|
||||||
UINT32 length;
|
ULONG length;
|
||||||
|
|
||||||
NXD_ADDRESS server_ipv4_address;
|
NXD_ADDRESS server_ipv4_address;
|
||||||
NXD_ADDRESS peer_address;
|
NXD_ADDRESS peer_address;
|
||||||
UINT32 peer_port;
|
ULONG peer_port;
|
||||||
|
|
||||||
NX_PARAMETER_NOT_USED(thread_input);
|
NX_PARAMETER_NOT_USED(thread_input);
|
||||||
|
|
||||||
@@ -259,7 +259,7 @@ void thread_1_entry(ULONG thread_input)
|
|||||||
|
|
||||||
UINT status;
|
UINT status;
|
||||||
NX_PACKET* packet_ptr;
|
NX_PACKET* packet_ptr;
|
||||||
UINT32 actual_status;
|
ULONG actual_status;
|
||||||
|
|
||||||
NX_PARAMETER_NOT_USED(thread_input);
|
NX_PARAMETER_NOT_USED(thread_input);
|
||||||
|
|
||||||
@@ -331,10 +331,10 @@ void thread_1_entry(ULONG thread_input)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
UINT32 size;
|
ULONG size;
|
||||||
nx_packet_data_extract_offset(packet_ptr, 0, buffer, 64, &size);
|
nx_packet_data_extract_offset(packet_ptr, 0, buffer, 64, &size);
|
||||||
buffer[size] = 0;
|
buffer[size] = 0;
|
||||||
printf("Received packet %lu with %s\n", thread_1_counter, buffer);
|
printf("Received packet %lu with %s\n", (unsigned long)thread_1_counter, buffer);
|
||||||
/* Release the packet. */
|
/* Release the packet. */
|
||||||
nx_packet_release(packet_ptr);
|
nx_packet_release(packet_ptr);
|
||||||
}
|
}
|
||||||
|
|||||||
+51
-23
@@ -24,7 +24,10 @@ if(NOT THREADX_TEST_SIMULATOR)
|
|||||||
"THREADX_TEST_SIMULATOR is not set. Configure with -DTHREADX_TEST_SIMULATOR=/path/to/riscv-vp")
|
"THREADX_TEST_SIMULATOR is not set. Configure with -DTHREADX_TEST_SIMULATOR=/path/to/riscv-vp")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "risc-v32")
|
if(ARCH_FLAGS MATCHES "-march=(rv(32|64)gc)")
|
||||||
|
set(THREADX_TEST_ISA "${CMAKE_MATCH_1}_m")
|
||||||
|
set(THREADX_TEST_FP_CONTEXT ON)
|
||||||
|
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "risc-v32")
|
||||||
set(THREADX_TEST_ISA "rv32imac_m")
|
set(THREADX_TEST_ISA "rv32imac_m")
|
||||||
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "risc-v64")
|
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "risc-v64")
|
||||||
set(THREADX_TEST_ISA "rv64imac_m")
|
set(THREADX_TEST_ISA "rv64imac_m")
|
||||||
@@ -37,21 +40,6 @@ set(__THREAD_LOCAL_STORAGE OFF)
|
|||||||
add_subdirectory(${THREADX4TGFS_ROOT}/third-party/picolibc ${CMAKE_BINARY_DIR}/picolibc)
|
add_subdirectory(${THREADX4TGFS_ROOT}/third-party/picolibc ${CMAKE_BINARY_DIR}/picolibc)
|
||||||
target_link_libraries(c PUBLIC gcc)
|
target_link_libraries(c PUBLIC gcc)
|
||||||
|
|
||||||
set(THREADX_LOW_LEVEL_INIT_SOURCE_INPUT
|
|
||||||
${THREADX4TGFS_ROOT}/port/threadx_smp/src/tx_initialize_low_level.c)
|
|
||||||
set(THREADX_LOW_LEVEL_INIT_SOURCE
|
|
||||||
${CMAKE_BINARY_DIR}/generated/tx_initialize_low_level.c)
|
|
||||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
|
|
||||||
${THREADX_LOW_LEVEL_INIT_SOURCE_INPUT}
|
|
||||||
${THREADX4TGFS_ROOT}/test/threadx/generate_trap_file.sh)
|
|
||||||
execute_process(
|
|
||||||
COMMAND bash ${THREADX4TGFS_ROOT}/test/threadx/generate_trap_file.sh
|
|
||||||
${THREADX_LOW_LEVEL_INIT_SOURCE_INPUT}
|
|
||||||
${THREADX_LOW_LEVEL_INIT_SOURCE}
|
|
||||||
RESULT_VARIABLE THREADX_LOW_LEVEL_INIT_GENERATE_RESULT
|
|
||||||
COMMAND_ERROR_IS_FATAL ANY
|
|
||||||
)
|
|
||||||
|
|
||||||
add_subdirectory(${THREADX4TGFS_ROOT}/port/moonlight ${CMAKE_BINARY_DIR}/port/moonlight)
|
add_subdirectory(${THREADX4TGFS_ROOT}/port/moonlight ${CMAKE_BINARY_DIR}/port/moonlight)
|
||||||
target_sources(c PRIVATE ${THREADX4TGFS_ROOT}/port/picolibc/port.c)
|
target_sources(c PRIVATE ${THREADX4TGFS_ROOT}/port/picolibc/port.c)
|
||||||
target_link_libraries(c PUBLIC moonlight gcc)
|
target_link_libraries(c PUBLIC moonlight gcc)
|
||||||
@@ -94,9 +82,6 @@ endfunction()
|
|||||||
set(TX_REGRESSION_DIR
|
set(TX_REGRESSION_DIR
|
||||||
${THREADX4TGFS_ROOT}/third-party/threadx/test/smp/regression
|
${THREADX4TGFS_ROOT}/third-party/threadx/test/smp/regression
|
||||||
)
|
)
|
||||||
set(TX_CMAKE_DIR
|
|
||||||
${THREADX4TGFS_ROOT}/third-party/threadx/test/tx/cmake
|
|
||||||
)
|
|
||||||
|
|
||||||
set(TX_REGRESSION_CASES
|
set(TX_REGRESSION_CASES
|
||||||
${TX_REGRESSION_DIR}/threadx_block_memory_basic_test.c
|
${TX_REGRESSION_DIR}/threadx_block_memory_basic_test.c
|
||||||
@@ -169,8 +154,8 @@ set(TX_REGRESSION_CASES
|
|||||||
${TX_REGRESSION_DIR}/threadx_smp_random_resume_suspend_test.c
|
${TX_REGRESSION_DIR}/threadx_smp_random_resume_suspend_test.c
|
||||||
${TX_REGRESSION_DIR}/threadx_smp_rebalance_exclusion_test.c
|
${TX_REGRESSION_DIR}/threadx_smp_rebalance_exclusion_test.c
|
||||||
${TX_REGRESSION_DIR}/threadx_smp_relinquish_test.c
|
${TX_REGRESSION_DIR}/threadx_smp_relinquish_test.c
|
||||||
${TX_REGRESSION_DIR}/threadx_smp_resume_suspend_accending_order_test.c
|
${TX_REGRESSION_DIR}/threadx_smp_resume_suspend_ascending_order_test.c
|
||||||
${TX_REGRESSION_DIR}/threadx_smp_resume_suspend_decending_order_test.c
|
${TX_REGRESSION_DIR}/threadx_smp_resume_suspend_descending_order_test.c
|
||||||
${TX_REGRESSION_DIR}/threadx_smp_time_slice_test.c
|
${TX_REGRESSION_DIR}/threadx_smp_time_slice_test.c
|
||||||
${TX_REGRESSION_DIR}/threadx_smp_two_threads_one_core_test.c
|
${TX_REGRESSION_DIR}/threadx_smp_two_threads_one_core_test.c
|
||||||
${TX_REGRESSION_DIR}/threadx_thread_basic_execution_test.c
|
${TX_REGRESSION_DIR}/threadx_thread_basic_execution_test.c
|
||||||
@@ -213,7 +198,7 @@ set(TX_REGRESSION_CASES
|
|||||||
add_library(
|
add_library(
|
||||||
threadx_smp_regression_support STATIC
|
threadx_smp_regression_support STATIC
|
||||||
${TX_REGRESSION_DIR}/testcontrol.c
|
${TX_REGRESSION_DIR}/testcontrol.c
|
||||||
${TX_CMAKE_DIR}/samples/fake.c
|
../threadx/vp_time.c
|
||||||
)
|
)
|
||||||
target_link_libraries(threadx_smp_regression_support PUBLIC threadx_smp c)
|
target_link_libraries(threadx_smp_regression_support PUBLIC threadx_smp c)
|
||||||
target_compile_definitions(
|
target_compile_definitions(
|
||||||
@@ -227,9 +212,25 @@ target_compile_definitions(
|
|||||||
TEST_STACK_SIZE_PRINTF=4096
|
TEST_STACK_SIZE_PRINTF=4096
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_library(threadx_smp_regression_weak_defaults OBJECT
|
||||||
|
${THREADX4TGFS_ROOT}/third-party/threadx/test/shared/regression/testcontrol_weak_defaults.c
|
||||||
|
)
|
||||||
|
|
||||||
function(add_threadx_regression_test TEST_SOURCE)
|
function(add_threadx_regression_test TEST_SOURCE)
|
||||||
get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE)
|
get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE)
|
||||||
|
|
||||||
|
if(TEST_NAME STREQUAL "threadx_thread_basic_execution_test")
|
||||||
|
# This fixture calls _tx_thread_timeout directly. Use its existing pointer
|
||||||
|
# setup on ports where ULONG cannot carry a thread pointer.
|
||||||
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${TEST_SOURCE}")
|
||||||
|
file(READ "${TEST_SOURCE}" test_source_text)
|
||||||
|
string(REPLACE "#if defined(_WIN64)\n {\n TX_TIMER_INTERNAL timeout_timer;"
|
||||||
|
"#if defined(_WIN64) || defined(TX_TIMER_EXTENSION_PTR_DEFINED)\n {\n TX_TIMER_INTERNAL timeout_timer;"
|
||||||
|
test_source_text "${test_source_text}")
|
||||||
|
set(TEST_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.c")
|
||||||
|
file(GENERATE OUTPUT "${TEST_SOURCE}" CONTENT "${test_source_text}")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(TEST_NAME STREQUAL "threadx_initialize_kernel_setup_test")
|
if(TEST_NAME STREQUAL "threadx_initialize_kernel_setup_test")
|
||||||
set(test_libraries threadx_smp)
|
set(test_libraries threadx_smp)
|
||||||
else()
|
else()
|
||||||
@@ -238,9 +239,19 @@ function(add_threadx_regression_test TEST_SOURCE)
|
|||||||
|
|
||||||
setup_target(
|
setup_target(
|
||||||
${TEST_NAME}
|
${TEST_NAME}
|
||||||
LIBRARIES ${test_libraries}
|
LIBRARIES threadx_smp_regression_weak_defaults ${test_libraries}
|
||||||
SOURCES ${TEST_SOURCE}
|
SOURCES ${TEST_SOURCE}
|
||||||
)
|
)
|
||||||
|
target_include_directories(${TEST_NAME} PRIVATE ${THREADX4TGFS_ROOT}/third-party/threadx/test/tx/regression)
|
||||||
|
|
||||||
|
# Vary timer phase for the interrupt-window and time-sliced contention cases.
|
||||||
|
if(TEST_NAME STREQUAL "threadx_event_flag_isr_set_clear_test" OR
|
||||||
|
TEST_NAME STREQUAL "threadx_event_flag_isr_wait_abort_test" OR
|
||||||
|
TEST_NAME STREQUAL "threadx_thread_delayed_suspension_test" OR
|
||||||
|
TEST_NAME STREQUAL "threadx_byte_memory_thread_contention_test")
|
||||||
|
target_sources(${TEST_NAME} PRIVATE ../threadx/vp_timer_jitter.c)
|
||||||
|
target_link_options(${TEST_NAME} PRIVATE -Wl,--wrap=_tx_timer_interrupt)
|
||||||
|
endif()
|
||||||
|
|
||||||
list(APPEND TX_REGRESSION_TARGETS ${TEST_NAME})
|
list(APPEND TX_REGRESSION_TARGETS ${TEST_NAME})
|
||||||
set(TX_REGRESSION_TARGETS ${TX_REGRESSION_TARGETS} PARENT_SCOPE)
|
set(TX_REGRESSION_TARGETS ${TX_REGRESSION_TARGETS} PARENT_SCOPE)
|
||||||
@@ -254,6 +265,10 @@ function(add_threadx_regression_test TEST_SOURCE)
|
|||||||
-p tb.top.num_cores=4
|
-p tb.top.num_cores=4
|
||||||
)
|
)
|
||||||
set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 60)
|
set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 60)
|
||||||
|
if(TEST_NAME STREQUAL "threadx_byte_memory_thread_contention_test")
|
||||||
|
# The four-hart VP has to simulate more than 1,280 ticks of active work.
|
||||||
|
set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 120)
|
||||||
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
foreach(test_case ${TX_REGRESSION_CASES})
|
foreach(test_case ${TX_REGRESSION_CASES})
|
||||||
@@ -264,3 +279,16 @@ add_custom_target(
|
|||||||
threadx_smp_regression_build
|
threadx_smp_regression_build
|
||||||
DEPENDS ${TX_REGRESSION_TARGETS}
|
DEPENDS ${TX_REGRESSION_TARGETS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(THREADX_TEST_FP_CONTEXT)
|
||||||
|
setup_target(vp_smp_context
|
||||||
|
SOURCES vp_smp_context.c vp_smp_context_fp.S
|
||||||
|
LIBRARIES threadx_smp_regression_weak_defaults threadx_smp)
|
||||||
|
target_include_directories(vp_smp_context PRIVATE ${THREADX4TGFS_ROOT}/port/moonlight/inc)
|
||||||
|
add_test(NAME vp_smp_context COMMAND ${THREADX_TEST_SIMULATOR}
|
||||||
|
--isa=${THREADX_TEST_ISA}
|
||||||
|
-f $<TARGET_FILE:vp_smp_context>
|
||||||
|
-m 60s
|
||||||
|
-p tb.top.num_cores=4)
|
||||||
|
set_tests_properties(vp_smp_context PROPERTIES TIMEOUT 60)
|
||||||
|
endif()
|
||||||
@@ -59,6 +59,22 @@
|
|||||||
"CMAKE_BUILD_TYPE": "MinSizeRel",
|
"CMAKE_BUILD_TYPE": "MinSizeRel",
|
||||||
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
|
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Context32",
|
||||||
|
"inherits": "Debug32",
|
||||||
|
"binaryDir": "${sourceDir}/../../build/${presetName}/test/smp",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/../../cmake/rv32gc_gnu.cmake"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Context64",
|
||||||
|
"inherits": "Debug",
|
||||||
|
"binaryDir": "${sourceDir}/../../build/${presetName}/test/smp",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/../../cmake/rv64gc_gnu.cmake"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"buildPresets": [
|
"buildPresets": [
|
||||||
@@ -67,6 +83,21 @@
|
|||||||
{ "name": "Release", "configurePreset": "Release" },
|
{ "name": "Release", "configurePreset": "Release" },
|
||||||
{ "name": "Release32", "configurePreset": "Release32" },
|
{ "name": "Release32", "configurePreset": "Release32" },
|
||||||
{ "name": "MinSizeRel", "configurePreset": "MinSizeRel" },
|
{ "name": "MinSizeRel", "configurePreset": "MinSizeRel" },
|
||||||
{ "name": "MinSizeRel32", "configurePreset": "MinSizeRel32" }
|
{ "name": "MinSizeRel32", "configurePreset": "MinSizeRel32" },
|
||||||
|
{ "name": "Context32", "configurePreset": "Context32", "targets": ["vp_smp_context"] },
|
||||||
|
{ "name": "Context64", "configurePreset": "Context64", "targets": ["vp_smp_context"] }
|
||||||
|
],
|
||||||
|
"testPresets": [
|
||||||
|
{
|
||||||
|
"name": "Context32",
|
||||||
|
"configurePreset": "Context32",
|
||||||
|
"filter": { "include": { "name": "^vp_smp_context$" } },
|
||||||
|
"output": { "outputOnFailure": true }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Context64",
|
||||||
|
"inherits": "Context32",
|
||||||
|
"configurePreset": "Context64"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "aclint_ipi.h"
|
||||||
|
#include "board.h"
|
||||||
|
#include "riscv-csr.h"
|
||||||
|
#include "riscv-traps.h"
|
||||||
|
#include "tx_api.h"
|
||||||
|
#include "tx_thread.h"
|
||||||
|
|
||||||
|
static TX_THREAD controller;
|
||||||
|
static TX_THREAD worker;
|
||||||
|
static ULONG controller_stack[1024];
|
||||||
|
static ULONG worker_stack[1024];
|
||||||
|
static TX_SEMAPHORE worker_finished;
|
||||||
|
static volatile UINT worker_waiting_on_hart_1;
|
||||||
|
static volatile UINT request_nested_irq;
|
||||||
|
static volatile UINT observed_nested_irq;
|
||||||
|
|
||||||
|
/* Disable fault injection in the regression-configured kernel. */
|
||||||
|
TEST_FLAG test_initialize_flag;
|
||||||
|
#ifndef TX_TIMER_PROCESS_IN_ISR
|
||||||
|
TEST_FLAG threadx_delete_timer_thread;
|
||||||
|
|
||||||
|
void delete_timer_thread(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
UINT vp_fp_context_sleep(void);
|
||||||
|
UINT vp_fp_context_migrate(volatile UINT *waiting);
|
||||||
|
|
||||||
|
static void check(UINT pass, const char *message)
|
||||||
|
{
|
||||||
|
if (!pass) {
|
||||||
|
puts(message);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void check_software_interrupt(void)
|
||||||
|
{
|
||||||
|
UINT hart = tx_thread_smp_core_get();
|
||||||
|
set_aclint_msip(aclint, hart, 0);
|
||||||
|
|
||||||
|
if (hart == 0 && request_nested_irq) {
|
||||||
|
observed_nested_irq = _tx_thread_smp_current_state_get() == 2;
|
||||||
|
request_nested_irq = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Called by the board timer ISR after it has acknowledged the timer. */
|
||||||
|
void test_interrupt_dispatch(void)
|
||||||
|
{
|
||||||
|
if (tx_thread_smp_core_get() == 0 && request_nested_irq) {
|
||||||
|
send_ipi(0);
|
||||||
|
csr_set_bits_mstatus(MSTATUS_MIE_BIT_MASK);
|
||||||
|
while (request_nested_irq) {
|
||||||
|
}
|
||||||
|
csr_clr_bits_mstatus(MSTATUS_MIE_BIT_MASK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void run_worker(ULONG input)
|
||||||
|
{
|
||||||
|
(void)input;
|
||||||
|
check(tx_thread_smp_core_get() == 1, "Worker did not start on hart 1");
|
||||||
|
check(vp_fp_context_migrate(&worker_waiting_on_hart_1) == TX_SUCCESS,
|
||||||
|
"FP context was corrupted during interrupt-driven migration");
|
||||||
|
check(tx_thread_smp_core_get() == 2, "Worker did not migrate to hart 2");
|
||||||
|
check(tx_semaphore_put(&worker_finished) == TX_SUCCESS, "Worker completion signal failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void run_controller(ULONG input)
|
||||||
|
{
|
||||||
|
(void)input;
|
||||||
|
request_nested_irq = 1;
|
||||||
|
check(vp_fp_context_sleep() == TX_SUCCESS, "Sleep failed or corrupted the solicited FP context");
|
||||||
|
check(observed_nested_irq, "Software interrupt did not nest inside the timer interrupt");
|
||||||
|
|
||||||
|
check(tx_thread_resume(&worker) == TX_SUCCESS, "Unable to start worker");
|
||||||
|
for (UINT tick = 0; tick < 50 && !worker_waiting_on_hart_1; ++tick) {
|
||||||
|
check(tx_thread_sleep(1) == TX_SUCCESS, "Sleep while waiting for worker failed");
|
||||||
|
}
|
||||||
|
check(worker_waiting_on_hart_1, "Worker never started on hart 1");
|
||||||
|
check(tx_thread_smp_core_exclude(&worker, TX_THREAD_SMP_CORE_MASK & ~(1UL << 2)) == TX_SUCCESS,
|
||||||
|
"Unable to migrate worker to hart 2");
|
||||||
|
check(tx_semaphore_get(&worker_finished, 50) == TX_SUCCESS, "Worker did not finish after migration");
|
||||||
|
puts("SMP context test passed");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tx_application_define(void *memory)
|
||||||
|
{
|
||||||
|
(void)memory;
|
||||||
|
check(register_irq_handler(RISCV_INT_MSI, check_software_interrupt), "Unable to install software IRQ handler");
|
||||||
|
check(tx_semaphore_create(&worker_finished, "worker finished", 0) == TX_SUCCESS,
|
||||||
|
"Unable to create worker completion semaphore");
|
||||||
|
check(tx_thread_create(&worker, "worker", run_worker, 0, worker_stack, sizeof(worker_stack),
|
||||||
|
5, 5, TX_NO_TIME_SLICE, TX_DONT_START) == TX_SUCCESS, "Unable to create worker");
|
||||||
|
check(tx_thread_smp_core_exclude(&worker, TX_THREAD_SMP_CORE_MASK & ~(1UL << 1)) == TX_SUCCESS,
|
||||||
|
"Unable to assign worker to hart 1");
|
||||||
|
check(tx_thread_create(&controller, "controller", run_controller, 0, controller_stack, sizeof(controller_stack),
|
||||||
|
5, 5, TX_NO_TIME_SLICE, TX_AUTO_START) == TX_SUCCESS, "Unable to create controller");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
tx_kernel_enter();
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
.section .text
|
||||||
|
.balign 4
|
||||||
|
|
||||||
|
.global vp_fp_context_sleep
|
||||||
|
.type vp_fp_context_sleep, @function
|
||||||
|
vp_fp_context_sleep:
|
||||||
|
li a1, 0
|
||||||
|
j .Lcheck_context
|
||||||
|
|
||||||
|
.global vp_fp_context_migrate
|
||||||
|
.type vp_fp_context_migrate, @function
|
||||||
|
vp_fp_context_migrate:
|
||||||
|
li a1, 1
|
||||||
|
|
||||||
|
.Lcheck_context:
|
||||||
|
addi sp, sp, -48
|
||||||
|
#if __riscv_xlen == 64
|
||||||
|
sd ra, 40(sp)
|
||||||
|
#else
|
||||||
|
sw ra, 40(sp)
|
||||||
|
#endif
|
||||||
|
fsd fs0, 16(sp)
|
||||||
|
fsd fs11, 24(sp)
|
||||||
|
frcsr t0
|
||||||
|
sw t0, 32(sp)
|
||||||
|
|
||||||
|
la t0, .Lpatterns
|
||||||
|
fld fs0, 0(t0)
|
||||||
|
fld fs11, 8(t0)
|
||||||
|
fld ft0, 16(t0)
|
||||||
|
fld ft11, 24(t0)
|
||||||
|
li t0, 0x65
|
||||||
|
fscsr t0
|
||||||
|
bnez a1, .Linterrupt_switch
|
||||||
|
|
||||||
|
li a0, 2
|
||||||
|
call _tx_thread_sleep
|
||||||
|
bnez a0, .Lreturn
|
||||||
|
j .Lcheck_preserved
|
||||||
|
|
||||||
|
.Linterrupt_switch:
|
||||||
|
fence rw, w
|
||||||
|
sw a1, 0(a0)
|
||||||
|
.Lwait_for_migration:
|
||||||
|
csrr t0, mhartid
|
||||||
|
li t1, 2
|
||||||
|
bne t0, t1, .Lwait_for_migration
|
||||||
|
|
||||||
|
fsd ft0, 0(sp)
|
||||||
|
fsd ft11, 8(sp)
|
||||||
|
la t0, .Lpatterns
|
||||||
|
addi t0, t0, 16
|
||||||
|
mv t1, sp
|
||||||
|
li t2, 4
|
||||||
|
jal t3, .Lcompare_words
|
||||||
|
|
||||||
|
.Lcheck_preserved:
|
||||||
|
frcsr t0
|
||||||
|
li t1, 0x65
|
||||||
|
bne t0, t1, .Lbad_context
|
||||||
|
fsd fs0, 0(sp)
|
||||||
|
fsd fs11, 8(sp)
|
||||||
|
la t0, .Lpatterns
|
||||||
|
mv t1, sp
|
||||||
|
li t2, 4
|
||||||
|
jal t3, .Lcompare_words
|
||||||
|
li a0, 0
|
||||||
|
j .Lreturn
|
||||||
|
|
||||||
|
.Lcompare_words:
|
||||||
|
lw t4, 0(t0)
|
||||||
|
lw t5, 0(t1)
|
||||||
|
bne t4, t5, .Lbad_context
|
||||||
|
addi t0, t0, 4
|
||||||
|
addi t1, t1, 4
|
||||||
|
addi t2, t2, -1
|
||||||
|
bnez t2, .Lcompare_words
|
||||||
|
jr t3
|
||||||
|
|
||||||
|
.Lbad_context:
|
||||||
|
li a0, 1
|
||||||
|
.Lreturn:
|
||||||
|
fld fs0, 16(sp)
|
||||||
|
fld fs11, 24(sp)
|
||||||
|
lw t0, 32(sp)
|
||||||
|
fscsr t0
|
||||||
|
#if __riscv_xlen == 64
|
||||||
|
ld ra, 40(sp)
|
||||||
|
#else
|
||||||
|
lw ra, 40(sp)
|
||||||
|
#endif
|
||||||
|
addi sp, sp, 48
|
||||||
|
ret
|
||||||
|
|
||||||
|
.section .rodata
|
||||||
|
.balign 8
|
||||||
|
.Lpatterns:
|
||||||
|
.dword 0x3ff0123456789abc, 0x40023456789abcde
|
||||||
|
.dword 0x401456789abcdef0, 0x4026789abcdef012
|
||||||
+23
-27
@@ -37,29 +37,15 @@ set(__THREAD_LOCAL_STORAGE OFF)
|
|||||||
add_subdirectory(${THREADX4TGFS_ROOT}/third-party/picolibc ${CMAKE_BINARY_DIR}/picolibc)
|
add_subdirectory(${THREADX4TGFS_ROOT}/third-party/picolibc ${CMAKE_BINARY_DIR}/picolibc)
|
||||||
target_link_libraries(c PUBLIC gcc)
|
target_link_libraries(c PUBLIC gcc)
|
||||||
|
|
||||||
set(THREADX_LOW_LEVEL_INIT_SOURCE_INPUT
|
|
||||||
${THREADX4TGFS_ROOT}/port/threadx/src/tx_initialize_low_level.c)
|
|
||||||
set(THREADX_LOW_LEVEL_INIT_SOURCE
|
|
||||||
${CMAKE_BINARY_DIR}/generated/tx_initialize_low_level.c)
|
|
||||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
|
|
||||||
${THREADX_LOW_LEVEL_INIT_SOURCE_INPUT}
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/generate_trap_file.sh)
|
|
||||||
execute_process(
|
|
||||||
COMMAND bash ${CMAKE_CURRENT_LIST_DIR}/generate_trap_file.sh
|
|
||||||
${THREADX_LOW_LEVEL_INIT_SOURCE_INPUT}
|
|
||||||
${THREADX_LOW_LEVEL_INIT_SOURCE}
|
|
||||||
RESULT_VARIABLE THREADX_LOW_LEVEL_INIT_GENERATE_RESULT
|
|
||||||
COMMAND_ERROR_IS_FATAL ANY
|
|
||||||
)
|
|
||||||
|
|
||||||
add_subdirectory(${THREADX4TGFS_ROOT}/port/moonlight ${CMAKE_BINARY_DIR}/port/moonlight)
|
add_subdirectory(${THREADX4TGFS_ROOT}/port/moonlight ${CMAKE_BINARY_DIR}/port/moonlight)
|
||||||
target_sources(c PRIVATE ${THREADX4TGFS_ROOT}/port/picolibc/port.c)
|
target_sources(c PRIVATE ${THREADX4TGFS_ROOT}/port/picolibc/port.c)
|
||||||
target_link_libraries(c PUBLIC moonlight gcc)
|
target_link_libraries(c PUBLIC moonlight gcc)
|
||||||
|
|
||||||
set(THREADX_CUSTOM_PORT ${THREADX4TGFS_ROOT}/port/threadx)
|
add_subdirectory(${THREADX4TGFS_ROOT}/port/threadx ${CMAKE_BINARY_DIR}/port/threadx)
|
||||||
add_subdirectory(${THREADX4TGFS_ROOT}/third-party/threadx ${CMAKE_BINARY_DIR}/threadx)
|
|
||||||
target_link_libraries(threadx PUBLIC moonlight c)
|
|
||||||
target_compile_definitions(threadx PUBLIC TX_REGRESSION_TEST)
|
target_compile_definitions(threadx PUBLIC TX_REGRESSION_TEST)
|
||||||
|
if(THREADX_ARCH STREQUAL "risc-v64")
|
||||||
|
target_compile_definitions(threadx PRIVATE $<$<COMPILE_LANGUAGE:ASM>:TX_USE_WFI_IDLE>)
|
||||||
|
endif()
|
||||||
|
|
||||||
function(setup_target TARGET)
|
function(setup_target TARGET)
|
||||||
set(options)
|
set(options)
|
||||||
@@ -96,9 +82,6 @@ endfunction()
|
|||||||
set(TX_REGRESSION_DIR
|
set(TX_REGRESSION_DIR
|
||||||
${THREADX4TGFS_ROOT}/third-party/threadx/test/tx/regression
|
${THREADX4TGFS_ROOT}/third-party/threadx/test/tx/regression
|
||||||
)
|
)
|
||||||
set(TX_CMAKE_DIR
|
|
||||||
${THREADX4TGFS_ROOT}/third-party/threadx/test/tx/cmake
|
|
||||||
)
|
|
||||||
|
|
||||||
set(TX_REGRESSION_CASES
|
set(TX_REGRESSION_CASES
|
||||||
${TX_REGRESSION_DIR}/threadx_block_memory_basic_test.c
|
${TX_REGRESSION_DIR}/threadx_block_memory_basic_test.c
|
||||||
@@ -204,25 +187,28 @@ set(TX_REGRESSION_TARGETS)
|
|||||||
add_library(
|
add_library(
|
||||||
threadx_regression_support STATIC
|
threadx_regression_support STATIC
|
||||||
${TX_REGRESSION_DIR}/testcontrol.c
|
${TX_REGRESSION_DIR}/testcontrol.c
|
||||||
${TX_CMAKE_DIR}/samples/fake.c
|
vp_time.c
|
||||||
)
|
)
|
||||||
target_link_libraries(threadx_regression_support PUBLIC threadx c)
|
target_link_libraries(threadx_regression_support PUBLIC threadx c)
|
||||||
|
target_compile_options(threadx_regression_support PRIVATE -include stdlib.h)
|
||||||
target_compile_definitions(
|
target_compile_definitions(
|
||||||
threadx_regression_support
|
threadx_regression_support
|
||||||
PUBLIC
|
PUBLIC
|
||||||
TX_REGRESSION_TEST
|
|
||||||
CTEST
|
CTEST
|
||||||
BATCH_TEST
|
BATCH_TEST
|
||||||
TEST_STACK_SIZE_PRINTF=4096
|
TEST_STACK_SIZE_PRINTF=4096
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_library(threadx_regression_weak_defaults OBJECT
|
||||||
|
${THREADX4TGFS_ROOT}/third-party/threadx/test/shared/regression/testcontrol_weak_defaults.c
|
||||||
|
)
|
||||||
|
|
||||||
function(add_threadx_regression_test TEST_SOURCE)
|
function(add_threadx_regression_test TEST_SOURCE)
|
||||||
get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE)
|
get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE)
|
||||||
|
|
||||||
if(TEST_NAME STREQUAL "threadx_initialize_kernel_setup_test")
|
set(test_libraries moonlight_threadx threadx_regression_weak_defaults)
|
||||||
set(test_libraries threadx)
|
if(NOT TEST_NAME STREQUAL "threadx_initialize_kernel_setup_test")
|
||||||
else()
|
list(APPEND test_libraries threadx_regression_support)
|
||||||
set(test_libraries threadx_regression_support)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
setup_target(
|
setup_target(
|
||||||
@@ -230,6 +216,12 @@ function(add_threadx_regression_test TEST_SOURCE)
|
|||||||
LIBRARIES ${test_libraries}
|
LIBRARIES ${test_libraries}
|
||||||
SOURCES ${TEST_SOURCE}
|
SOURCES ${TEST_SOURCE}
|
||||||
)
|
)
|
||||||
|
target_compile_options(${TEST_NAME} PRIVATE -include stdlib.h)
|
||||||
|
if(TEST_NAME STREQUAL "threadx_thread_basic_execution_test" OR
|
||||||
|
TEST_NAME STREQUAL "threadx_thread_delayed_suspension_test")
|
||||||
|
target_sources(${TEST_NAME} PRIVATE vp_timer_jitter.c)
|
||||||
|
target_link_options(${TEST_NAME} PRIVATE -Wl,--wrap=_tx_timer_interrupt)
|
||||||
|
endif()
|
||||||
|
|
||||||
list(APPEND TX_REGRESSION_TARGETS ${TEST_NAME})
|
list(APPEND TX_REGRESSION_TARGETS ${TEST_NAME})
|
||||||
set(TX_REGRESSION_TARGETS ${TX_REGRESSION_TARGETS} PARENT_SCOPE)
|
set(TX_REGRESSION_TARGETS ${TX_REGRESSION_TARGETS} PARENT_SCOPE)
|
||||||
@@ -248,6 +240,10 @@ foreach(test_case ${TX_REGRESSION_CASES})
|
|||||||
add_threadx_regression_test(${test_case})
|
add_threadx_regression_test(${test_case})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
# This case waits for repeated hits in a short interrupt window, which can
|
||||||
|
# take longer to simulate on an unoptimized VP build.
|
||||||
|
set_tests_properties(threadx_event_flag_isr_wait_abort_test PROPERTIES TIMEOUT 120)
|
||||||
|
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
threadx_regression_build
|
threadx_regression_build
|
||||||
DEPENDS ${TX_REGRESSION_TARGETS}
|
DEPENDS ${TX_REGRESSION_TARGETS}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
src="$1"
|
|
||||||
dst="$2"
|
|
||||||
|
|
||||||
extern_anchor='extern void _tx_timer_interrupt(void);'
|
|
||||||
call_anchor='_tx_timer_interrupt();'
|
|
||||||
|
|
||||||
mkdir -p "$(dirname "$dst")"
|
|
||||||
tmp1="${dst}.tmp1"
|
|
||||||
|
|
||||||
line=$(grep -n -F "$extern_anchor" "$src" | head -n 1 | cut -d: -f1)
|
|
||||||
if [ -z "$line" ]; then
|
|
||||||
echo "failed to find _tx_timer_interrupt declaration anchor in input source" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sed "${line}a\\
|
|
||||||
void test_interrupt_dispatch(void) __attribute__((weak));\nvoid test_interrupt_dispatch(void) {}" "$src" > "$tmp1"
|
|
||||||
|
|
||||||
line=$(grep -n -F "$call_anchor" "$tmp1" | head -n 1 | cut -d: -f1)
|
|
||||||
if [ -z "$line" ]; then
|
|
||||||
echo "failed to find _tx_timer_interrupt call anchor in input source" >&2
|
|
||||||
rm -f "$tmp1"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sed "${line}i\\
|
|
||||||
test_interrupt_dispatch();" "$tmp1" > "$dst"
|
|
||||||
rm -f "$tmp1"
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#include "hwtimer.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
time_t time(time_t *result)
|
||||||
|
{
|
||||||
|
time_t now = (time_t)(get_aclint_mtime(aclint) / TICKNUM_PER_SECOND);
|
||||||
|
if (result)
|
||||||
|
*result = now;
|
||||||
|
return now;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#include "hwtimer.h"
|
||||||
|
|
||||||
|
void __real__tx_timer_interrupt(void);
|
||||||
|
|
||||||
|
void __wrap__tx_timer_interrupt(void)
|
||||||
|
{
|
||||||
|
static uint32_t sequence = 1;
|
||||||
|
|
||||||
|
/* Vary the interval over 17 ACLINT counts, centred on the normal tick,
|
||||||
|
so the ISR samples more than two phases of the test thread's loop. */
|
||||||
|
sequence = sequence * 1664525u + 1013904223u;
|
||||||
|
uint64_t next = get_aclint_mtimecmp(aclint);
|
||||||
|
set_aclint_mtimecmp(aclint, next - 8 + (sequence >> 16) % 17u);
|
||||||
|
|
||||||
|
__real__tx_timer_interrupt();
|
||||||
|
}
|
||||||
Vendored
+1
-1
Submodule third-party/netxduo updated: 949c0f235c...c690f59f9a.
Vendored
+1
-1
Submodule third-party/threadx updated: c9ff0ce2c8...fa06c6f137.
Reference in new issue
Block a user