Skip to content

Commit 1de3589

Browse files
committed
ThreadX: Interrupt fixes for TX_ENABLE_EXECUTION_CHANGE_NOTIFY
- Must reload register trashed by notify hook function call - Must ensure PS.WOE is set before using call8 - Remove unused XT_USE_INT_WRAPPER define and associated changes, which had a bug in XEA2 usage - Fix another case where enabling the thread notify hooks for call0 ABI corrupted a register
1 parent c256915 commit 1de3589

6 files changed

Lines changed: 23 additions & 21 deletions

File tree

ports/xtensa/xcc/inc/xtensa_context.h

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -373,21 +373,6 @@ XSTRUCT_END(XtExcFrame)
373373
#endif
374374
#endif
375375

376-
377-
/*
378-
-------------------------------------------------------------------------------
379-
This flag is meant for internal use. Have all interrupts be dispatched via a
380-
common wrapper, which takes care of doing some OS-specific stuff common to
381-
all interrupt handlers. Said stuff cannot safely be handled in the RTOS_ENTER
382-
and RTOS_EXIT macros.
383-
-------------------------------------------------------------------------------
384-
*/
385-
#if (defined TX_ENABLE_EXECUTION_CHANGE_NOTIFY) || (defined XT_INTEXC_HOOKS)
386-
#define XT_USE_INT_WRAPPER 1
387-
#else
388-
#define XT_USE_INT_WRAPPER 0
389-
#endif
390-
391376
#if XCHAL_HAVE_XEA2 && (XCHAL_NUM_INTERRUPTS > 32) && (defined XT_USE_SWPRI)
392377
#error "Software prioritization of interrupts (XT_USE_SWPRI) not supported for XEA2 with > 32 interrupts."
393378
#endif
@@ -504,12 +489,15 @@ XSTRUCT_END(XtExcFrame)
504489

505490
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
506491
// Call the thread entry function to indicate the thread is executing.
507-
// SP should be pointing to a safe region at this point.
492+
// SP should be pointing to a safe region at this point. Note that a9
493+
// may be trashed by this call, must be reloaded.
508494
#ifdef __XTENSA_CALL0_ABI__
509495
call0 _tx_execution_thread_enter
510496
#else
511497
call8 _tx_execution_thread_enter
512498
#endif
499+
movi a9, _tx_thread_current_ptr // a9 <- &_tx_thread_current_ptr
500+
l32i a9, a9, 0 // a9 <- _tx_thread_current_ptr
513501
#endif
514502

515503
l32i a2, a9, tx_thread_solicited // a2 = solicited flag

ports/xtensa/xcc/src/tx_thread_schedule.S

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,18 @@ _tx_thread_schedule:
166166

167167
#if (defined(TX_ENABLE_EXECUTION_CHANGE_NOTIFY) || defined(TX_EXECUTION_PROFILE_ENABLE))
168168
/* Call the thread entry function to indicate the thread is executing. */
169+
/* Note a2 may be trashed by this call, must be reloaded. */
169170
#ifdef __XTENSA_CALL0_ABI__
170171
call0 _tx_execution_thread_enter
172+
movi a2, _tx_thread_current_ptr
173+
l32i a2, a2, 0
171174
#else
175+
/* Ensure that PS.WOE is set for windowed call */
176+
movi a0, PS_WOE
177+
rsr.ps a3
178+
or a3, a3, a0
179+
wsr.ps a3
180+
rsync
172181
call8 _tx_execution_thread_enter
173182
#endif
174183
#endif

ports/xtensa/xcc/src/tx_thread_system_return.S

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ _tx_thread_system_return:
8383
#if (defined(TX_ENABLE_EXECUTION_CHANGE_NOTIFY) || defined(TX_EXECUTION_PROFILE_ENABLE))
8484
/* Call the thread exit function to indicate the thread is no longer executing. */
8585
#ifdef __XTENSA_CALL0_ABI__
86+
/* Preserve a0 across the call. */
87+
#if !XCHAL_HAVE_XEA3
88+
s32i a0, sp, 0
89+
#endif
8690
call0 _tx_execution_thread_exit
91+
l32i a0, sp, 0
8792
#else
8893
call8 _tx_execution_thread_exit
8994
#endif

ports/xtensa/xcc/src/xtensa_intr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ typedef struct xt_handler_table_entry {
9393
void * arg;
9494
} xt_handler_table_entry;
9595

96-
#if (XT_USE_INT_WRAPPER || XCHAL_HAVE_XEA3)
96+
#if XCHAL_HAVE_XEA3
9797
extern xt_handler_table_entry _xt_interrupt_table[XCHAL_NUM_INTERRUPTS + 1];
9898
#else
9999
extern xt_handler_table_entry _xt_interrupt_table[XCHAL_NUM_INTERRUPTS];
@@ -131,7 +131,7 @@ xt_handler xt_set_interrupt_handler(uint32_t n, xt_handler f, void * arg)
131131
}
132132
#endif
133133

134-
#if (XT_USE_INT_WRAPPER || XCHAL_HAVE_XEA3)
134+
#if XCHAL_HAVE_XEA3
135135
entry = _xt_interrupt_table + n + 1;
136136
#else
137137
entry = _xt_interrupt_table + n;

ports/xtensa/xcc/src/xtensa_intr_asm.S

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ _xt_interrupt_table:
112112
#if XCHAL_HAVE_XEA3
113113
.word xt_interrupt_wrapper
114114
.word 0
115-
#elif XT_USE_INT_WRAPPER
116-
.word 0
117-
.word 0
118115
#endif
119116

120117
.set i, 0

ports/xtensa/xcc/src/xtensa_vectors.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@
150150
.macro call_exec_isr_entry_fn
151151
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
152152
#ifdef __XTENSA_CALL0_ABI__
153+
/* Preserve a2 across the call, a12 is callee-saved for call0 ABI. */
154+
mov a12, a2
153155
call0 _tx_execution_isr_enter
156+
mov a2, a12
154157
#else
155158
call4 _tx_execution_isr_enter
156159
#endif

0 commit comments

Comments
 (0)