|
71 | 71 | #endif |
72 | 72 | #define REGBYTES (1 << LOG_REGBYTES) |
73 | 73 |
|
| 74 | +/* RISC-V mstatus bit definitions */ |
| 75 | +#ifndef MSTATUS_MIE |
| 76 | +#define MSTATUS_MIE (1UL << 3) /* Machine interrupt enable */ |
| 77 | +#define MSTATUS_MPIE (1UL << 7) /* Machine previous interrupt enable */ |
| 78 | +#define MSTATUS_MPP_SHIFT 11 |
| 79 | +#define MSTATUS_MPP_MASK (3UL << MSTATUS_MPP_SHIFT) |
| 80 | +#define MSTATUS_MPP_MACHINE (3UL << MSTATUS_MPP_SHIFT) /* MPP = Machine */ |
| 81 | +#define MSTATUS_FS_INITIAL (1UL << 13) /* FP/FS state seed used by port */ |
| 82 | +#endif |
| 83 | + |
74 | 84 | #else /*not __ASSEMBLER__ */ |
75 | 85 |
|
76 | 86 | /* Include for memset. */ |
@@ -141,8 +151,13 @@ typedef unsigned short USHORT; |
141 | 151 |
|
142 | 152 | /* Define various constants for the ThreadX RISC-V port. */ |
143 | 153 |
|
144 | | -#define TX_INT_DISABLE 0x00000000 /* Disable interrupts value */ |
145 | | -#define TX_INT_ENABLE 0x00000008 /* Enable interrupt value */ |
| 154 | +/* This port assumes execution in Machine mode (M-mode). mstatus bits |
| 155 | + are manipulated directly for interrupt control. For S-mode ports, |
| 156 | + sstatus and SIE/SPIE semantics must be used instead. See the |
| 157 | + RISC-V Privileged Spec for details. */ |
| 158 | + |
| 159 | +#define TX_INT_DISABLE 0x00000000UL /* Disable interrupts value */ |
| 160 | +#define TX_INT_ENABLE MSTATUS_MIE /* Enable interrupt value */ |
146 | 161 |
|
147 | 162 |
|
148 | 163 | /* Define the clock source for trace event entry time stamp. The following two item are port specific. |
@@ -253,23 +268,24 @@ typedef unsigned short USHORT; |
253 | 268 | is used to define a local function save area for the disable and restore |
254 | 269 | macros. */ |
255 | 270 |
|
256 | | -#ifdef TX_DISABLE_INLINE |
| 271 | +/* Expose helper used to perform an atomic read/modify/write of mstatus. |
| 272 | + The helper composes and returns the posture per ThreadX contract. */ |
| 273 | +UINT _tx_thread_interrupt_control(UINT new_posture); |
257 | 274 |
|
258 | | -ULONG64 _tx_thread_interrupt_control(unsigned int new_posture); |
| 275 | +#ifdef TX_DISABLE_INLINE |
259 | 276 |
|
260 | | -#define TX_INTERRUPT_SAVE_AREA register ULONG64 interrupt_save; |
| 277 | +#define TX_INTERRUPT_SAVE_AREA register UINT interrupt_save; |
261 | 278 |
|
262 | 279 | #define TX_DISABLE interrupt_save = _tx_thread_interrupt_control(TX_INT_DISABLE); |
263 | 280 | #define TX_RESTORE _tx_thread_interrupt_control(interrupt_save); |
264 | 281 |
|
265 | 282 | #else |
266 | 283 |
|
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) : );}; |
| 284 | +/* Default inline macros delegate to the portable helper to ensure |
| 285 | + correct read/modify/write semantics across toolchains. */ |
| 286 | +#define TX_INTERRUPT_SAVE_AREA UINT interrupt_save; |
| 287 | +#define TX_DISABLE interrupt_save = _tx_thread_interrupt_control(TX_INT_DISABLE); |
| 288 | +#define TX_RESTORE _tx_thread_interrupt_control(interrupt_save); |
273 | 289 |
|
274 | 290 | #endif |
275 | 291 |
|
|
0 commit comments