This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 79d08944562fb54cbdecae89a2f33166d84c482b Author: zhangyuan29 <[email protected]> AuthorDate: Wed Oct 28 14:08:59 2026 +0800 arch/tricore: use TASKING builtins for irq save/restore and mfcr/mtcr fca138800b6 ("arch/tricore: drop illd dependence for irq") replaced the TASKING compiler builtins __disable_and_save()/__restore() (and the unconditional tricore_mfcr/tricore_mtcr macros) with GNU-style output-only volatile inline asm ("disable %0" / "restore %0" / "mfcr %0,%1"). TASKING mis-compiles such output-only volatile asm: when the result register is clobbered by a subsequent asm (e.g. mfcr PSW in up_interrupt_context()) and a call follows, TASKING re-executes the disable on the same path and returns the 2nd result. Since the 1st disable already cleared ICR.IE, the 2nd returns 0, so saved flags are always 0 and leave_critical_section() never re-enables interrupts. Secondary cores deadlock (idle with ICR.IE=0, tick pending) and core0 hits the boot barrier timeout. gcc is unaffected. Repro (cctc --tradeoff=2 -O3, enter_critical_section structure): disable d15 ; mfcr d15,#0xfe04 (clobbers) ; call note ; disable d2 ; ret -> 2x disable, flags = 0 (bug) Fix: under CONFIG_TRICORE_TOOLCHAIN_TASKING, route up_irq_save/restore to the __disable_and_save()/__restore() builtins and tricore_mfcr/tricore_mtcr to the __mfcr/__mtcr builtins; GNU keeps the inline asm (gcc volatile-asm semantics are correct). Builtins are not re-executed: disable d8 ; mfcr d15 ; call note ; mov d2,d8 ; ret -> 1x disable, flags ok This also fixes the latent same-class exposure on the HIPRI interrupt path (up_irq_save/restore R/W ICR via tricore_mfcr/tricore_mtcr), up_getpc, up_interrupt_context, up_cpu_index and the PPRS macros, which all went through the unguarded GNU-asm macros. up_getpc is simplified to a single tricore_mfcr(TRICORE_CPU_PC) call since the macro now dispatches per toolchain. Signed-off-by: zhangyuan29 <[email protected]> --- arch/tricore/include/arch.h | 32 +++++++++++++++++++------------- arch/tricore/include/irq.h | 4 ++++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/arch/tricore/include/arch.h b/arch/tricore/include/arch.h index 4f072f06369..cc176f24aea 100644 --- a/arch/tricore/include/arch.h +++ b/arch/tricore/include/arch.h @@ -84,19 +84,25 @@ }) #endif -/* MTCR and MFCR - move to / from Core Special Function Register */ - -#define tricore_mtcr(reg, val) \ - ({ \ - __asm__ __volatile__ ("mtcr %0,%1\n\t"::"i"(reg),"d"(val):"memory"); \ - }) - -#define tricore_mfcr(reg) \ - ({ \ - uint32_t __val; \ - __asm__ __volatile__ ("mfcr %0,%1": "=d" (__val) :"i"(reg): "memory"); \ - __val; \ - }) +/* TASKING mis-compiles output-only volatile mfcr asm; use its builtins. */ + +#ifdef CONFIG_TRICORE_TOOLCHAIN_TASKING +# define tricore_mtcr(reg, val) __mtcr((reg), (int)(uintptr_t)(val)) +# define tricore_mfcr(reg) (__mfcr(reg)) +#else +# define tricore_mtcr(reg, val) \ + ({ \ + __asm__ __volatile__ ("mtcr %0,%1\n\t"::"i"(reg),"d"(val):"memory"); \ + }) + +# define tricore_mfcr(reg) \ + ({ \ + uint32_t __val; \ + __asm__ __volatile__ ("mfcr %0,%1": "=d" (__val) :"i"(reg): \ + "memory"); \ + __val; \ + }) +#endif /* Return from a handler that the trap or interrupt vector entered with * jli, to the vector code at A11. diff --git a/arch/tricore/include/irq.h b/arch/tricore/include/irq.h index ae2782588a8..12246632a28 100644 --- a/arch/tricore/include/irq.h +++ b/arch/tricore/include/irq.h @@ -348,6 +348,8 @@ noinstrument_function static inline_function irqstate_t up_irq_save(void) tricore_mtcr(TRICORE_CPU_ICR, icr); UP_ISB(); } +#elif defined(CONFIG_TRICORE_TOOLCHAIN_TASKING) + flags = __disable_and_save(); #else __asm__ __volatile__ ("disable %0" : "=d"(flags) :: "memory"); #endif @@ -378,6 +380,8 @@ void up_irq_restore(irqstate_t flags) tricore_mtcr(TRICORE_CPU_ICR, icr); UP_ISB(); } +#elif defined(CONFIG_TRICORE_TOOLCHAIN_TASKING) + __restore(flags); #else __asm__ __volatile__ ("restore %0" :: "d"(flags) : "memory"); #endif
