11/***************************************************************************
2- * Copyright (c) 2024 Microsoft Corporation
3- *
2+ * Copyright (c) 2024 Microsoft Corporation
3+ *
44 * This program and the accompanying materials are made available under the
55 * terms of the MIT License which is available at
66 * https://opensource.org/licenses/MIT.
7- *
7+ *
88 * SPDX-License-Identifier: MIT
99 **************************************************************************/
1010
5353#ifndef TX_PORT_H
5454#define TX_PORT_H
5555
56- #ifdef __ASSEMBLER__
57-
58-
59- #if __riscv_xlen == 64
60- # define SLL32 sllw
61- # define STORE sd
62- # define LOAD ld
63- # define LWU lwu
64- # define LOG_REGBYTES 3
65- #else
66- # define SLL32 sll
67- # define STORE sw
68- # define LOAD lw
69- # define LWU lw
70- # define LOG_REGBYTES 2
71- #endif
72- #define REGBYTES (1 << LOG_REGBYTES)
73-
74- #else /*not __ASSEMBLER__ */
75-
7656/* Include for memset. */
7757#include <string.h>
7858
8666 alternately be defined on the command line. */
8767
8868#include "tx_user.h"
89- #endif
90-
91-
92- /* Define compiler library include files. */
69+ #endif /* TX_INCLUDE_USER_DEFINE_FILE */
9370
9471
9572/* Define ThreadX basic types for this port. */
@@ -105,8 +82,6 @@ typedef unsigned long long ULONG64;
10582typedef short SHORT ;
10683typedef unsigned short USHORT ;
10784#define ULONG64_DEFINED
108- #define ALIGN_TYPE_DEFINED
109- #define ALIGN_TYPE ULONG64
11085
11186
11287
@@ -253,25 +228,34 @@ typedef unsigned short USHORT;
253228 is used to define a local function save area for the disable and restore
254229 macros. */
255230
256- #ifdef TX_DISABLE_INLINE
231+ /* Expose helper used to perform an atomic read/modify/write of mstatus.
232+ The helper composes and returns the posture per ThreadX contract. */
233+ UINT _tx_thread_interrupt_control (UINT new_posture );
257234
258- ULONG64 _tx_thread_interrupt_control ( unsigned int new_posture );
235+ #ifdef TX_DISABLE_INLINE
259236
260- #define TX_INTERRUPT_SAVE_AREA register ULONG64 interrupt_save;
237+ #define TX_INTERRUPT_SAVE_AREA register UINT interrupt_save;
261238
262- #define TX_DISABLE interrupt_save = _tx_thread_interrupt_control(TX_INT_DISABLE);
263- #define TX_RESTORE _tx_thread_interrupt_control(interrupt_save);
239+ #define TX_DISABLE __asm__ volatile("csrrci %0, mstatus, 8" : "=r" (interrupt_save) :: "memory");
240+ #define TX_RESTORE { \
241+ unsigned long _temp_mstatus; \
242+ __asm__ volatile( \
243+ "csrc mstatus, 8\n" \
244+ "andi %0, %1, 8\n" \
245+ "csrs mstatus, %0" \
246+ : "=&r" (_temp_mstatus) \
247+ : "r" (interrupt_save) \
248+ : "memory"); \
249+ }
264250
265251#else
266252
267- #define TX_INTERRUPT_SAVE_AREA ULONG64 interrupt_save;
268- /* Atomically read mstatus into interrupt_save and clear bit 3 of mstatus. */
269- #define TX_DISABLE {__asm__ ("csrrci %0, mstatus, 0x08" : "=r" (interrupt_save) : );};
270- /* We only care about mstatus.mie (bit 3), so mask interrupt_save and write to mstatus. */
271- #define TX_RESTORE {register ULONG64 __tempmask = interrupt_save & 0x08; \
272- __asm__ ("csrrs x0, mstatus, %0 \n\t" : : "r" (__tempmask) : );};
253+ #define TX_INTERRUPT_SAVE_AREA register UINT interrupt_save;
273254
274- #endif
255+ #define TX_DISABLE interrupt_save = _tx_thread_interrupt_control(TX_INT_DISABLE);
256+ #define TX_RESTORE _tx_thread_interrupt_control(interrupt_save);
257+
258+ #endif /* TX_DISABLE_INLINE */
275259
276260
277261/* Define the interrupt lockout macros for each ThreadX object. */
@@ -291,7 +275,6 @@ CHAR _tx_version_id[] =
291275 "Copyright (c) 2024 Microsoft Corporation. * ThreadX RISC-V64/GNU Version 6.4.2 *" ;
292276#else
293277extern CHAR _tx_version_id [];
294- #endif
278+ #endif /* TX_THREAD_INIT */
295279
296- #endif /*not __ASSEMBLER__ */
297- #endif
280+ #endif /* TX_PORT_H */
0 commit comments