This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 31bbc2f68908f177221dce4abbfb521f6c80e23f
Author: zhangyu117 <[email protected]>
AuthorDate: Tue Nov 17 17:59:48 2026 +0800

    arch/tricore: unify trap and interrupt vector handling
    
    Use a single trap vector table and a common register-based trap entry
    for both toolchains. Move trap declarations into tricore_vectors.h and
    let FCU recovery use a registered CSA pool.
    
    Signed-off-by: zhangyu117 <[email protected]>
    Co-Authored-By: Kimi <[email protected]>
---
 arch/tricore/Kconfig                               |  10 -
 arch/tricore/src/common/gnu/tricore_vectors.S      | 194 ++++----
 .../tricore/src/common/tasking/tricore_vectors.asm | 178 ++++----
 arch/tricore/src/common/tricore_initialize.c       |   1 +
 arch/tricore/src/common/tricore_internal.h         |  28 --
 arch/tricore/src/common/tricore_registerdump.c     |   1 +
 arch/tricore/src/common/tricore_trapcall.c         | 505 ++++++++++-----------
 arch/tricore/src/common/tricore_vectors.h          | 163 +++++++
 .../tc3xx/a2g-tc397-5v-tft/scripts/tricore.ld      |   4 +-
 .../tc3xx/a2g-tc397-5v-tft/scripts/tricore.lsl     |   4 +-
 .../tc4xx/triboard_tc4x9_com/scripts/tricore.ld    |   4 +-
 .../tc4xx/triboard_tc4x9_com/scripts/tricore.lsl   |   4 +-
 12 files changed, 613 insertions(+), 483 deletions(-)

diff --git a/arch/tricore/Kconfig b/arch/tricore/Kconfig
index b08ac9ce60a..175a06f121f 100644
--- a/arch/tricore/Kconfig
+++ b/arch/tricore/Kconfig
@@ -174,16 +174,6 @@ config TRICORE_TRAP_ALERT
                Print the trap name and reason before the trap panics.  The
                panic message has the trap class and TIN in any case.
 
-config TRICORE_FCU_CSA_NUM
-       int "Context save areas for the FCU trap"
-       default 0
-       ---help---
-               Context save areas reserved for a free context list underflow
-               (FCU) trap, so that the trap can still be reported when no free
-               context save area is left.  0 reserves none, then the core stops
-               in the trap unless the board passes its own pool to
-               tricore_fcu_register_pool.  At least 20 are needed.
-
 if ARCH_CHIP_TC3XX
 source "arch/tricore/src/tc3xx/Kconfig"
 endif
diff --git a/arch/tricore/src/common/gnu/tricore_vectors.S 
b/arch/tricore/src/common/gnu/tricore_vectors.S
index 534652697db..b3ab7c57719 100644
--- a/arch/tricore/src/common/gnu/tricore_vectors.S
+++ b/arch/tricore/src/common/gnu/tricore_vectors.S
@@ -21,124 +21,126 @@
  ****************************************************************************/
 
 /****************************************************************************
- * Trap vector table, one per core.  BTV points at the table of the core in
- * use; the linker script keeps the .traptab_cpuN section of that core.
- *
- * Each 32-byte slot saves the lower context and enters the common trap
- * entry with the trap class in %d5; the hardware has put the TIN in %d15
- * and the trap return address in %a11.  The entry builds a struct
- * tricore_trap_s on the stack and enters the handler with jli, so the
- * handler sees PCXI pointing at the lower context of the trapped code.
- * The handler returns with ji %a11, then the entry restores the lower
- * context and returns from the trap.
- *
- * Context management traps go through tricore_ctx_entry first: on a free
- * context list underflow (FCU, TIN 4) there is no free CSA, so svlcx
- * cannot run.  tricore_fcu_entry then saves the trapped context into the
- * pool registered with tricore_fcu_register_pool and continues in
- * tricore_fcu_recover.  The saved %a4 is lost, as the entry uses it, and
- * so is %sp when the trap switched to the interrupt stack.  Without a pool
- * the core stops in tricore_fcu_entry.
- *
- * The interrupt vector saves the lower context and enters
- * tricore_doirq the same way.  The startup code sets the priority bits
- * of BIV, so every interrupt priority enters this one vector.
- *
- * tasking/tricore_vectors.asm is the same code in the TASKING syntax.
+ * Trap vector table (BTV) in .traptab and interrupt vector table (BIV) in
+ * .inttab; the linker script places both sections.
  ****************************************************************************/
 
-#include <arch/csfr.h>
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <arch/irq.h>
 
-       .macro  TRAPSLOT cls, entry
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+.macro TRAPSLOT cls, entry
        svlcx
        mov     %d5, \cls
        j       \entry
        .p2align 5
-       .endm
-
-       .macro  TRAPJUMP entry
-       j       \entry
-       .p2align 5
-       .endm
+.endm
 
-       .macro  TRAPTAB cpu
-       .section .traptab_cpu\cpu, "ax", %progbits
-       .p2align 8
-       .global tricore_trap_vectors_cpu\cpu
-tricore_trap_vectors_cpu\cpu:
-       TRAPSLOT 0, tricore_trap_entry
-       TRAPSLOT 1, tricore_trap_entry
-       TRAPSLOT 2, tricore_trap_entry
-       TRAPJUMP tricore_ctx_entry
-       TRAPSLOT 4, tricore_trap_entry
-       TRAPSLOT 5, tricore_trap_entry
-       TRAPSLOT 6, tricore_syscall_entry
-       TRAPSLOT 7, tricore_trap_entry
-       .endm
-
-       TRAPTAB 0
-       TRAPTAB 1
-       TRAPTAB 2
-       TRAPTAB 3
-       TRAPTAB 4
-       TRAPTAB 5
-
-       .section .intvec, "ax", %progbits
-       .p2align 5
-       .global tricore_int_vector
-tricore_int_vector:
+.macro INTSLOT handler
        svlcx
-       j       tricore_int_entry
-
-       /* struct tricore_trap_s: taddr at 0, tid at 4, tclass at 5, tcpu at 6 
*/
-
-       .macro  TRAPENTRY name, handler
-       .global \name
-       .type   \name, %function
-\name:
-       sub.a   %sp, 8
-       st.a    [%sp]0, %a11
-       st.b    [%sp]4, %d15
-       st.b    [%sp]5, %d5
-       mfcr    %d4, TRICORE_CPU_CORE_ID
-       and     %d4, %d4, 7
-       st.b    [%sp]6, %d4
-       mov.aa  %a4, %sp
-       movh.a  %a2, hi:\handler
-       lea     %a2, [%a2]lo:\handler
-       jli     %a2
-       lea     %sp, [%sp]8
+       jl      \handler
        rslcx
        rfe
-       .endm
+       .p2align 5
+.endm
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Tricore_trap_entry
+ ****************************************************************************/
 
        .text
        .p2align 1
 
-       TRAPENTRY tricore_trap_entry, tricore_trapcall
-       TRAPENTRY tricore_syscall_entry, tricore_svcall
+       .global tricore_trap_entry
+       .type   tricore_trap_entry, @function
+tricore_trap_entry:
+       mov.aa  %a4, %a11
+       mov     %d4, %d15
+       jl      tricore_trapcall
+       rslcx
+       rfe
+       .size   tricore_trap_entry, . - tricore_trap_entry
 
-       .type   tricore_int_entry, %function
-tricore_int_entry:
-       movh.a  %a2, hi:tricore_doirq
-       lea     %a2, [%a2]lo:tricore_doirq
-       jli     %a2
+/****************************************************************************
+ * Tricore_syscall_entry
+ ****************************************************************************/
+
+       .type   tricore_syscall_entry, @function
+tricore_syscall_entry:
+       jl      tricore_svcall
        rslcx
        rfe
+       .size   tricore_syscall_entry, . - tricore_syscall_entry
 
-       .type   tricore_ctx_entry, %function
-tricore_ctx_entry:
-       jeq     %d15, 4, tricore_fcu_entry
-       svlcx
-       mov     %d5, 3
-       j       tricore_trap_entry
+/****************************************************************************
+ * Tricore_fcu_entry
+ ****************************************************************************/
 
-       .type   tricore_fcu_entry, %function
+       .type   tricore_fcu_entry, @function
 tricore_fcu_entry:
-       movh.a  %a4, hi:g_tricore_fcu_pool
-       ld.a    %a4, [%a4]lo:g_tricore_fcu_pool
+       movh.a  %a4, hi:g_fcu_csa_base
+       ld.a    %a4, [%a4]lo:g_fcu_csa_base
 .Lfcu_nopool:
        jz.a    %a4, .Lfcu_nopool
        stucx   [%a4]0
        stlcx   [%a4]64
-       j       tricore_fcu_recover
+       jl      tricore_fcutrap_recover
+       movh.a  %a4, hi:g_fcu_csa_base
+       ld.a    %a4, [%a4]lo:g_fcu_csa_base
+       ld.a    %a11, [%a4](REG_UA11 * 4)
+       mov     %d15, 4
+       mov     %d5, 3
+       j       tricore_trap_entry
+       .size   tricore_fcu_entry, . - tricore_fcu_entry
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Trap vector table
+ ****************************************************************************/
+
+       .section .traptab, "ax", @progbits
+       .p2align 8
+       .global tricore_traptab
+       .type   tricore_traptab, @function
+tricore_traptab:
+       TRAPSLOT 0, tricore_trap_entry
+       TRAPSLOT 1, tricore_trap_entry
+       TRAPSLOT 2, tricore_trap_entry
+
+       jne     %d15, 4, 1f
+       j       tricore_fcu_entry
+1:
+       TRAPSLOT 3, tricore_trap_entry
+
+       TRAPSLOT 4, tricore_trap_entry
+       TRAPSLOT 5, tricore_trap_entry
+       TRAPSLOT 6, tricore_syscall_entry
+       TRAPSLOT 7, tricore_trap_entry
+       .size   tricore_traptab, . - tricore_traptab
+
+/****************************************************************************
+ * Interrupt vector table.  One entry serves all priorities; the startup
+ * code sets the BIV priority bits accordingly.
+ ****************************************************************************/
+
+       .section .inttab, "ax", @progbits
+       .p2align 5
+       .global tricore_inttab
+       .type   tricore_inttab, @function
+tricore_inttab:
+       INTSLOT tricore_doirq
+       .size   tricore_inttab, . - tricore_inttab
diff --git a/arch/tricore/src/common/tasking/tricore_vectors.asm 
b/arch/tricore/src/common/tasking/tricore_vectors.asm
index c72232dfd12..cf36b93dc38 100644
--- a/arch/tricore/src/common/tasking/tricore_vectors.asm
+++ b/arch/tricore/src/common/tasking/tricore_vectors.asm
@@ -19,110 +19,134 @@
 ; under the License.
 ;
 ;****************************************************************************
-;
-; TASKING (astc) version of gnu/tricore_vectors.S, same code and layout; see
-; there for the description.  astc does not run the C preprocessor, so the
-; CORE_ID offset (TRICORE_CPU_CORE_ID in arch/csfr.h) is written out.  The
-; tables are protected, as nothing references them by symbol.
-;
+
+;****************************************************************************
+; Trap vector table (BTV) in .text.traptab and interrupt vector table (BIV)
+; in .text.inttab; the linker script places both sections.
+;****************************************************************************
+
+;****************************************************************************
+; Included Files
+;****************************************************************************
+
+#include <nuttx/config.h>
+#include <arch/irq.h>
+
+;****************************************************************************
+; Pre-processor Definitions
 ;****************************************************************************
 
        .extern tricore_trapcall
        .extern tricore_svcall
+       .extern tricore_fcutrap_recover
+       .extern g_fcu_csa_base
        .extern tricore_doirq
-       .extern tricore_fcu_recover
-       .extern g_tricore_fcu_pool
 
 TRAPSLOT       .macro  cls, entry
        svlcx
        mov     d5, #cls
        j       entry
        .align  32
-       .endm
+.endm
 
-TRAPJUMP       .macro  entry
-       j       entry
+INTSLOT        .macro  handler
+       svlcx
+       jl      handler
+       rslcx
+       rfe
        .align  32
-       .endm
+.endm
 
-TRAPTAB        .macro  cpu, label
-       .sdecl  ".text.traptab_cpu\cpu",code,protect
-       .sect   ".text.traptab_cpu\cpu"
-       .align  256
-       .global label
-label:
-       TRAPSLOT        0, tricore_trap_entry
-       TRAPSLOT        1, tricore_trap_entry
-       TRAPSLOT        2, tricore_trap_entry
-       TRAPJUMP        tricore_ctx_entry
-       TRAPSLOT        4, tricore_trap_entry
-       TRAPSLOT        5, tricore_trap_entry
-       TRAPSLOT        6, tricore_syscall_entry
-       TRAPSLOT        7, tricore_trap_entry
-       .endm
+;****************************************************************************
+; Private Functions
+;****************************************************************************
 
-       TRAPTAB 0, tricore_trap_vectors_cpu0
-       TRAPTAB 1, tricore_trap_vectors_cpu1
-       TRAPTAB 2, tricore_trap_vectors_cpu2
-       TRAPTAB 3, tricore_trap_vectors_cpu3
-       TRAPTAB 4, tricore_trap_vectors_cpu4
-       TRAPTAB 5, tricore_trap_vectors_cpu5
+;****************************************************************************
+; Tricore_trap_entry
+;****************************************************************************
 
-       .sdecl  ".text.intvec",code,protect
-       .sect   ".text.intvec"
-       .align  32
-       .global tricore_int_vector
-tricore_int_vector:
-       svlcx
-       j       tricore_int_entry
-
-; struct tricore_trap_s: taddr at 0, tid at 4, tclass at 5, tcpu at 6
-
-TRAPENTRY      .macro  name, handler
-       .global name
-name:
-       sub.a   sp, #8
-       st.a    [sp]0, a11
-       st.b    [sp]4, d15
-       st.b    [sp]5, d5
-       mfcr    d4, #0xfe1c             ; TRICORE_CPU_CORE_ID
-       and     d4, d4, #7
-       st.b    [sp]6, d4
-       mov.aa  a4, sp
-       movh.a  a2, #@HIS(handler)
-       lea     a2, [a2]@LOS(handler)
-       jli     a2
-       lea     sp, [sp]8
+       .sdecl  ".text.tricore_vectors",code
+       .sect   ".text.tricore_vectors"
+       .align  2
+
+       .global tricore_trap_entry
+tricore_trap_entry:    .type   func
+       mov.aa  a4, a11
+       mov     d4, d15
+       jl      tricore_trapcall
        rslcx
        rfe
-       .endm
-
-       .sdecl  ".text.tricore_trap_entry",code
-       .sect   ".text.tricore_trap_entry"
+       .size   tricore_trap_entry, * - tricore_trap_entry
 
-       TRAPENTRY       tricore_trap_entry, tricore_trapcall
-       TRAPENTRY       tricore_syscall_entry, tricore_svcall
+;****************************************************************************
+; Tricore_syscall_entry
+;****************************************************************************
 
-tricore_int_entry:
-       movh.a  a2, #@HIS(tricore_doirq)
-       lea     a2, [a2]@LOS(tricore_doirq)
-       jli     a2
+tricore_syscall_entry: .type   func
+       jl      tricore_svcall
        rslcx
        rfe
+       .size   tricore_syscall_entry, * - tricore_syscall_entry
 
-tricore_ctx_entry:
-       jeq     d15, #4, tricore_fcu_entry
-       svlcx
-       mov     d5, #3
-       j       tricore_trap_entry
+;****************************************************************************
+; Tricore_fcu_entry
+;****************************************************************************
 
-tricore_fcu_entry:
-       movh.a  a4, #@HIS(g_tricore_fcu_pool)
-       ld.a    a4, [a4]@LOS(g_tricore_fcu_pool)
+tricore_fcu_entry:     .type   func
+       movh.a  a4, #@HIS(g_fcu_csa_base)
+       ld.a    a4, [a4]@LOS(g_fcu_csa_base)
 fcu_nopool:
        jz.a    a4, fcu_nopool
        stucx   [a4]0
        stlcx   [a4]64
-       j       tricore_fcu_recover
+       jl      tricore_fcutrap_recover
+       movh.a  a4, #@HIS(g_fcu_csa_base)
+       ld.a    a4, [a4]@LOS(g_fcu_csa_base)
+       ld.a    a11, [a4](REG_UA11 * 4)
+       mov     d15, #4
+       mov     d5, #3
+       j       tricore_trap_entry
+       .size   tricore_fcu_entry, * - tricore_fcu_entry
+
+;****************************************************************************
+; Public Functions
+;****************************************************************************
+
+;****************************************************************************
+; Trap vector table
+;****************************************************************************
+
+       .sdecl  ".text.traptab",code,protect
+       .sect   ".text.traptab"
+       .align  256
+       .global tricore_traptab
+tricore_traptab:       .type   func
+       TRAPSLOT        0, tricore_trap_entry
+       TRAPSLOT        1, tricore_trap_entry
+       TRAPSLOT        2, tricore_trap_entry
+
+       jne     d15, #4, ctx_notfcu
+       j       tricore_fcu_entry
+ctx_notfcu:
+       TRAPSLOT        3, tricore_trap_entry
+
+       TRAPSLOT        4, tricore_trap_entry
+       TRAPSLOT        5, tricore_trap_entry
+       TRAPSLOT        6, tricore_syscall_entry
+       TRAPSLOT        7, tricore_trap_entry
+       .size   tricore_traptab, * - tricore_traptab
+
+;****************************************************************************
+; Interrupt vector table.  One entry serves all priorities; the startup
+; code sets the BIV priority bits accordingly.
+;****************************************************************************
+
+       .sdecl  ".text.inttab",code,protect
+       .sect   ".text.inttab"
+       .align  32
+       .global tricore_inttab
+tricore_inttab:        .type   func
+       INTSLOT tricore_doirq
+       .size   tricore_inttab, * - tricore_inttab
 
        .end
diff --git a/arch/tricore/src/common/tricore_initialize.c 
b/arch/tricore/src/common/tricore_initialize.c
index ce72f530e85..b6f4625050e 100644
--- a/arch/tricore/src/common/tricore_initialize.c
+++ b/arch/tricore/src/common/tricore_initialize.c
@@ -30,6 +30,7 @@
 #include <arch/board/board.h>
 
 #include "tricore_internal.h"
+#include "tricore_vectors.h"
 
 /****************************************************************************
  * Public Functions
diff --git a/arch/tricore/src/common/tricore_internal.h 
b/arch/tricore/src/common/tricore_internal.h
index e55451dc063..517fb944cfd 100644
--- a/arch/tricore/src/common/tricore_internal.h
+++ b/arch/tricore/src/common/tricore_internal.h
@@ -123,25 +123,6 @@
 
 #ifndef __ASSEMBLY__
 typedef void (*up_vector_t)(void);
-
-/* Bus trap hook function type for safety test modules.
- * Returns OK if the trap was handled, ERROR otherwise.
- */
-
-typedef int (*tricore_bustrap_hook_t)(uint32_t tid, void *context);
-
-/* Trap information that tricore_vectors.S/.asm builds on the stack and
- * passes to tricore_trapcall and tricore_svcall; keep the layout in
- * sync with the vectors.
- */
-
-struct tricore_trap_s
-{
-  uintptr_t taddr;  /* Trap return address (A11) */
-  uint8_t   tid;    /* Trap identification number (TIN) */
-  uint8_t   tclass; /* Trap class */
-  uint8_t   tcpu;   /* Core that took the trap */
-};
 #endif
 
 /****************************************************************************
@@ -213,15 +194,6 @@ uint32_t tricore_clock_asclinf(void);
 
 void tricore_sigdeliver(void);
 
-/* Exception Handler ********************************************************/
-
-void tricore_svcall(volatile void *trap);
-void tricore_trapcall(volatile void *trap);
-void tricore_trapinit(void);
-void tricore_bustrap_register_hook(tricore_bustrap_hook_t hook);
-void tricore_fcu_register_pool(void *base, size_t num);
-void tricore_fcu_recover(void);
-
 /* Context Save Areas *******************************************************/
 
 uintptr_t *tricore_alloc_csa(uintptr_t pc, uintptr_t sp,
diff --git a/arch/tricore/src/common/tricore_registerdump.c 
b/arch/tricore/src/common/tricore_registerdump.c
index 60f5ad6badd..2518858f68c 100644
--- a/arch/tricore/src/common/tricore_registerdump.c
+++ b/arch/tricore/src/common/tricore_registerdump.c
@@ -34,6 +34,7 @@
 #include <nuttx/irq.h>
 
 #include "tricore_internal.h"
+#include "tricore_vectors.h"
 
 /****************************************************************************
  * Public Functions
diff --git a/arch/tricore/src/common/tricore_trapcall.c 
b/arch/tricore/src/common/tricore_trapcall.c
index 953c82cce6a..b7d3d7bf42a 100644
--- a/arch/tricore/src/common/tricore_trapcall.c
+++ b/arch/tricore/src/common/tricore_trapcall.c
@@ -27,241 +27,219 @@
 #include <nuttx/config.h>
 
 #include <stdint.h>
+#include <inttypes.h>
 #include <stdio.h>
-#include <string.h>
 #include <assert.h>
-#include <nuttx/debug.h>
-#include <syscall.h>
 
 #include <arch/irq.h>
+#include <arch/barriers.h>
 #include <sched/sched.h>
+#include <nuttx/debug.h>
 #include <nuttx/coredump.h>
 #include <nuttx/sched.h>
 
 #include "tricore_internal.h"
+#include "tricore_vectors.h"
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
-/* Trap classes and trap identification numbers (TIN), as named in the
- * TriCore architecture manual.
- */
-
-#define TRICORE_TRAP_CLASS_MMU    0  /* Memory management */
-#define TRICORE_TRAP_CLASS_PROT   1  /* Internal protection */
-#define TRICORE_TRAP_CLASS_INSN   2  /* Instruction errors */
-#define TRICORE_TRAP_CLASS_CTX    3  /* Context management */
-#define TRICORE_TRAP_CLASS_BUS    4  /* System bus and peripheral errors */
-#define TRICORE_TRAP_CLASS_ASSERT 5  /* Assertion */
-#define TRICORE_TRAP_CLASS_NMI    7  /* Non-maskable interrupt */
-
-#define TRICORE_TIN_VAF           0  /* Class 0: virtual address fill */
-#define TRICORE_TIN_VAP           1  /* Class 0: virtual addr protection */
-
-#define TRICORE_TIN_PRIV          1  /* Class 1: privilege violation */
-#define TRICORE_TIN_MPR           2  /* Class 1: protection read */
-#define TRICORE_TIN_MPW           3  /* Class 1: protection write */
-#define TRICORE_TIN_MPX           4  /* Class 1: protection execute */
-#define TRICORE_TIN_MPP           5  /* Class 1: peripheral access */
-#define TRICORE_TIN_MPN           6  /* Class 1: null address */
-#define TRICORE_TIN_GRWP          7  /* Class 1: global register write */
-
-#define TRICORE_TIN_IOPC          1  /* Class 2: illegal opcode */
-#define TRICORE_TIN_UOPC          2  /* Class 2: unimplemented opcode */
-#define TRICORE_TIN_OPD           3  /* Class 2: invalid operand */
-#define TRICORE_TIN_ALN           4  /* Class 2: data address alignment */
-#define TRICORE_TIN_MEM           5  /* Class 2: invalid local memory */
-#define TRICORE_TIN_CSE           6  /* Class 2: coprocessor synchronous */
-
-#define TRICORE_TIN_FCD           1  /* Class 3: free context depletion */
-#define TRICORE_TIN_CDO           2  /* Class 3: call depth overflow */
-#define TRICORE_TIN_CDU           3  /* Class 3: call depth underflow */
-#define TRICORE_TIN_FCU           4  /* Class 3: free context underflow */
-#define TRICORE_TIN_CSU           5  /* Class 3: call stack underflow */
-#define TRICORE_TIN_CTYP          6  /* Class 3: context type error */
-#define TRICORE_TIN_NEST          7  /* Class 3: nesting error */
-
-#define TRICORE_TIN_PSE           1  /* Class 4: program fetch synchronous */
-#define TRICORE_TIN_DSE           2  /* Class 4: data access synchronous */
-#define TRICORE_TIN_DAE           3  /* Class 4: data access asynchronous */
-#define TRICORE_TIN_CAE           4  /* Class 4: coprocessor asynchronous */
-#define TRICORE_TIN_PIE           5  /* Class 4: program memory integrity */
-#define TRICORE_TIN_DIE           6  /* Class 4: data memory integrity */
-#define TRICORE_TIN_TAE           7  /* Class 4: temporal asynchronous */
-
-#define TRICORE_TIN_OVF           1  /* Class 5: arithmetic overflow */
-#define TRICORE_TIN_SOVF          2  /* Class 5: sticky overflow */
-
-/* Panic message of a trap, "Trap c=<class> t=<TIN>" */
-
-#define TRICORE_TRAP_MSG_LEN      24
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
+/* TriCore trap panic message contract. */
 
-/* Last trap and the trap status registers, for the coredump */
+#define TRICORE_TRAP_MSG_LEN    24
 
-struct tricore_trapinfo_s
-{
-  struct tricore_trap_s trap;
-  uint32_t pstr;   /* Program synchronous trap status */
-  uint32_t dstr;   /* Data synchronous trap status */
-  uint32_t datr;   /* Data asynchronous trap */
-  uint32_t deadd;  /* Data error address */
-};
+#define TRICORE_FCU_CSA_MINNUM  20
 
 /****************************************************************************
  * Private Data
  ****************************************************************************/
 
-static struct tricore_trapinfo_s g_trapinfo;
-
-/* FCU pool, also read by tricore_fcu_entry in tricore_vectors.S/.asm */
-
-uintptr_t *g_tricore_fcu_pool;
-static size_t g_tricore_fcu_num;
-
-#if CONFIG_TRICORE_FCU_CSA_NUM > 0
-static uintptr_t g_fcu_csa[CONFIG_TRICORE_FCU_CSA_NUM * TC_CONTEXT_REGS]
-  aligned_data(TC_CONTEXT_SIZE);
-#endif
+static struct tricore_trap_s g_trapinfo;
 
 /* Bus trap hook for safety test modules (e.g., BusMonTst). */
 
 static tricore_bustrap_hook_t g_bustrap_hook;
 
-/* Trap names and reasons, indexed by trap class and TIN */
+/* Trap reason description tables. */
 
 #ifdef CONFIG_TRICORE_TRAP_ALERT
-static const char * const g_trap_names[8] =
+static const char *const g_mmutrap_reasons[] =
+{
+  [TRICORE_TRAP_MMU_VAF] = "Virtual Address Fill",
+  [TRICORE_TRAP_MMU_VAP] = "Virtual Address Protection",
+};
+
+static const char *const g_intprot_reasons[] =
 {
-  [TRICORE_TRAP_CLASS_MMU]    = "MMU",
-  [TRICORE_TRAP_CLASS_PROT]   = "Internal Protection",
-  [TRICORE_TRAP_CLASS_INSN]   = "Instruction Errors",
-  [TRICORE_TRAP_CLASS_CTX]    = "Context Management",
-  [TRICORE_TRAP_CLASS_BUS]    = "System Bus",
-  [TRICORE_TRAP_CLASS_ASSERT] = "Assertion",
-  [TRICORE_TRAP_CLASS_NMI]    = "NMI",
+  [TRICORE_TRAP_INTPROT_PRIV] = "Privileged instruction",
+  [TRICORE_TRAP_INTPROT_MPR]  = "Memory Protection Read",
+  [TRICORE_TRAP_INTPROT_MPW]  = "Memory Protection Write",
+  [TRICORE_TRAP_INTPROT_MPX]  = "Memory Protection Execution",
+  [TRICORE_TRAP_INTPROT_MPP]  = "Memory Protection Peripheral Access",
+  [TRICORE_TRAP_INTPROT_MPN]  = "Memory Protection Null Address",
+  [TRICORE_TRAP_INTPROT_GRWP] = "Global Register Write Protection",
 };
 
-static const char * const g_trap_reasons[8][8] =
+static const char *const g_insterr_reasons[] =
 {
-  [TRICORE_TRAP_CLASS_MMU] =
-  {
-    [TRICORE_TIN_VAF]  = "Virtual Address Fill",
-    [TRICORE_TIN_VAP]  = "Virtual Address Protection",
-  },
-  [TRICORE_TRAP_CLASS_PROT] =
-  {
-    [TRICORE_TIN_PRIV] = "Privileged Instruction",
-    [TRICORE_TIN_MPR]  = "Memory Protection Read",
-    [TRICORE_TIN_MPW]  = "Memory Protection Write",
-    [TRICORE_TIN_MPX]  = "Memory Protection Execution",
-    [TRICORE_TIN_MPP]  = "Memory Protection Peripheral Access",
-    [TRICORE_TIN_MPN]  = "Memory Protection Null Address",
-    [TRICORE_TIN_GRWP] = "Global Register Write Protection",
-  },
-  [TRICORE_TRAP_CLASS_INSN] =
-  {
-    [TRICORE_TIN_IOPC] = "Illegal Opcode",
-    [TRICORE_TIN_UOPC] = "Unimplemented Opcode",
-    [TRICORE_TIN_OPD]  = "Invalid Operand Specification",
-    [TRICORE_TIN_ALN]  = "Data Address Alignment",
-    [TRICORE_TIN_MEM]  = "Invalid Local Memory Address",
-    [TRICORE_TIN_CSE]  = "Coprocessor Trap Synchronous Error",
-  },
-  [TRICORE_TRAP_CLASS_CTX] =
-  {
-    [TRICORE_TIN_FCD]  = "Free Context List Depletion",
-    [TRICORE_TIN_CDO]  = "Call Depth Overflow",
-    [TRICORE_TIN_CDU]  = "Call Depth Underflow",
-    [TRICORE_TIN_FCU]  = "Free Context List Underflow",
-    [TRICORE_TIN_CSU]  = "Call Stack Underflow",
-    [TRICORE_TIN_CTYP] = "Context Type",
-    [TRICORE_TIN_NEST] = "Nesting Error:RFE with non-zero call depth",
-  },
-  [TRICORE_TRAP_CLASS_BUS] =
-  {
-    [TRICORE_TIN_PSE]  = "Program Fetch Synchronous Error",
-    [TRICORE_TIN_DSE]  = "Data Access Synchronous Error",
-    [TRICORE_TIN_DAE]  = "Data Access Asynchronous Error",
-    [TRICORE_TIN_CAE]  = "Coprocessor Trap Asynchronous Error",
-    [TRICORE_TIN_PIE]  = "Program Memory Integrity Error",
-    [TRICORE_TIN_DIE]  = "Data Memory Integrity Error",
-    [TRICORE_TIN_TAE]  = "Temporal Asynchronous Error",
-  },
-  [TRICORE_TRAP_CLASS_ASSERT] =
-  {
-    [TRICORE_TIN_OVF]  = "Arithmetic Overflow",
-    [TRICORE_TIN_SOVF] = "Sticky Arithmetic Overflow",
-  },
+  [TRICORE_TRAP_INSTERR_IOPC] = "Illegal Opcode",
+  [TRICORE_TRAP_INSTERR_UOPC] = "Unimplemented Opcode",
+  [TRICORE_TRAP_INSTERR_OPD]  = "Invalid Operand Specification",
+  [TRICORE_TRAP_INSTERR_ALN]  = "Data Address Alignment",
+  [TRICORE_TRAP_INSTERR_MEM]  = "Invalid Local Memory Address",
+  [TRICORE_TRAP_INSTERR_CSE]  = "Coprocessor Trap Synchronous Error",
+};
+
+static const char *const g_ctxmgmt_reasons[] =
+{
+  [TRICORE_TRAP_CTXMGMT_FCD]  = "Free Context List Depletion",
+  [TRICORE_TRAP_CTXMGMT_CDO]  = "Call Depth Overflow",
+  [TRICORE_TRAP_CTXMGMT_CDU]  = "Call Depth Underflow",
+  [TRICORE_TRAP_CTXMGMT_FCU]  = "Free Context List Underflow",
+  [TRICORE_TRAP_CTXMGMT_CSU]  = "Call Stack Underflow",
+  [TRICORE_TRAP_CTXMGMT_CTYP] = "Context Type",
+  [TRICORE_TRAP_CTXMGMT_NEST] = "RFE with non-zero call depth",
+};
+
+static const char *const g_bustrap_reasons[] =
+{
+  [TRICORE_TRAP_BUS_PSE] = "Program Fetch Synchronous Error",
+  [TRICORE_TRAP_BUS_DSE] = "Data Access Synchronous Error",
+  [TRICORE_TRAP_BUS_DAE] = "Data Access Asynchronous Error",
+  [TRICORE_TRAP_BUS_CAE] = "Coprocessor Trap Asynchronous Error",
+  [TRICORE_TRAP_BUS_PIE] = "Program Memory Integrity Error",
+  [TRICORE_TRAP_BUS_DIE] = "Data Memory Integrity Error",
+  [TRICORE_TRAP_BUS_TAE] = "Temporal Asynchronous Error",
+};
+
+static const char *const g_assert_reasons[] =
+{
+  [TRICORE_TRAP_ASSERT_OVF]  = "Arithmetic Overflow",
+  [TRICORE_TRAP_ASSERT_SOVF] = "Sticky Arithmetic Overflow",
+};
+
+static const char *const g_nmitrap_reasons[] =
+{
+  [TRICORE_TRAP_NMI_NMI] = "Non Maskable Interrupt",
+};
+
+static const char *const g_trapclass_names[] =
+{
+  [TRICORE_TRAP_CLASS_MMU]     = "Memory Management Error",
+  [TRICORE_TRAP_CLASS_INTPROT] = "Internal Protection Error",
+  [TRICORE_TRAP_CLASS_INSTERR] = "Instruction Error",
+  [TRICORE_TRAP_CLASS_CTXMGMT] = "Context Management Error",
+  [TRICORE_TRAP_CLASS_BUS]     = "System Bus Error",
+  [TRICORE_TRAP_CLASS_ASSERT]  = "System Assertion",
+  [TRICORE_TRAP_CLASS_NMI]     = "Non Maskable Interrupt",
+};
+
+static const char *const *const g_trapclass_reasons[] =
+{
+  [TRICORE_TRAP_CLASS_MMU]     = g_mmutrap_reasons,
+  [TRICORE_TRAP_CLASS_INTPROT] = g_intprot_reasons,
+  [TRICORE_TRAP_CLASS_INSTERR] = g_insterr_reasons,
+  [TRICORE_TRAP_CLASS_CTXMGMT] = g_ctxmgmt_reasons,
+  [TRICORE_TRAP_CLASS_BUS]     = g_bustrap_reasons,
+  [TRICORE_TRAP_CLASS_ASSERT]  = g_assert_reasons,
+  [TRICORE_TRAP_CLASS_NMI]     = g_nmitrap_reasons,
 };
 #endif
 
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+uintptr_t *g_fcu_csa_base;
+size_t g_fcu_csa_num;
+
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
 
-static void tricore_trapinfo(volatile void *trap)
+#ifdef CONFIG_TRICORE_TRAP_ALERT
+static void tricore_trap_alert(enum tricore_trap_class_e cls, uint32_t tid,
+                               void *context)
 {
-  g_trapinfo.trap  = *(struct tricore_trap_s *)trap;
-  g_trapinfo.pstr  = tricore_mfcr(TRICORE_CPU_PSTR);
-  g_trapinfo.dstr  = tricore_mfcr(TRICORE_CPU_DSTR);
-  g_trapinfo.datr  = tricore_mfcr(TRICORE_CPU_DATR);
-  g_trapinfo.deadd = tricore_mfcr(TRICORE_CPU_DEADD);
+  _alert("PANIC!!! %s Trap:\n", g_trapclass_names[cls]);
+  _alert("\tclass %d TID: %" PRIu32 " regs: %p\n", cls, tid, context);
+  _alert("\t%s\n", g_trapclass_reasons[cls][tid]);
 }
+#else
+#  define tricore_trap_alert(cls, tid, context)
+#endif
 
-/* The message tells a panic notifier which trap it was.  The buffer is on
- * the stack of the trapping CPU, which the panic does not return to.
- */
+/* TriCore trap panic message contract. */
 
-static void tricore_trap_panic(unsigned int tclass, uint32_t tid,
-                               void *regs)
+static void tricore_trap_panic(uint32_t cls, uint32_t tid, void *regs)
 {
-  char msg[TRICORE_TRAP_MSG_LEN];
+  char buf[TRICORE_TRAP_MSG_LEN];
 
-#ifdef CONFIG_TRICORE_TRAP_ALERT
-  const char *name = g_trap_names[tclass & 7];
+  snprintf(buf, sizeof(buf), "Trap c=%" PRIu32 " t=%" PRIu32, cls, tid);
+  PANIC_WITH_REGS(buf, regs);
+}
+
+static void tricore_defaulttrap(enum tricore_trap_class_e cls, uint32_t tid,
+                                void *context)
+{
+  tricore_trap_alert(cls, tid, context);
+  tricore_trap_panic(cls, tid, context);
+}
 
-  _alert("PANIC!!! %s Trap:\n", name != NULL ? name : "Unknown");
-  _alert("\tClass %u TID: %" PRIu32 " regs: %p\n", tclass, tid, regs);
-  if (tid < 8 && g_trap_reasons[tclass & 7][tid] != NULL)
+static void tricore_insterrorstrap(uint32_t tid, void *context)
+{
+#ifdef CONFIG_ARCH_TC1V8
+  if (tid == TRICORE_TRAP_INSTERR_CSE)
     {
-      _alert("\t%s\n", g_trap_reasons[tclass & 7][tid]);
+#  ifdef CONFIG_ARCH_HAVE_FPU
+      uint32_t fpu_sync = tricore_mfcr(FPU_SYNC_TRAP_REG);
+
+      _alert("\tFPU_SYNC_TRAP:%" PRIX32 "\n\n", fpu_sync);
+      tricore_mtcr(FPU_SYNC_TRAP_REG,
+                   fpu_sync | (1U << FPU_TRAP_TCL_SHIFT));
+      UP_ISB();
+#  endif
     }
 #endif
 
-  snprintf(msg, sizeof(msg), "Trap c=%u t=%" PRIu32, tclass, tid);
-  up_irq_save();
-  PANIC_WITH_REGS(msg, regs);
+  tricore_defaulttrap(TRICORE_TRAP_CLASS_INSTERR, tid, context);
 }
 
-/* Report and clear the FPU trap status of a coprocessor trap */
-
-static void tricore_trap_fpu(unsigned int tclass, uint32_t tid)
+static int tricore_bustrap(uint32_t tid, void *context)
 {
-#ifdef CONFIG_ARCH_HAVE_FPU
-#  ifdef CONFIG_ARCH_TC1V8
-  if (tclass == TRICORE_TRAP_CLASS_INSN && tid == TRICORE_TIN_CSE)
+  /* First, let the registered hook try to handle the trap.
+   * This is used by safety test modules (e.g., BusMonTst) to handle
+   * expected bus errors during self-tests.
+   */
+
+  if (g_bustrap_hook != NULL)
     {
-      _alert("\tFPU_SYNC_TRAP:%" PRIX32 "\n\n",
-             tricore_mfcr(FPU_SYNC_TRAP_REG));
-      tricore_mtcr(FPU_SYNC_TRAP_REG, tricore_mfcr(FPU_SYNC_TRAP_REG) |
-                                      (1U << FPU_TRAP_TCL_SHIFT));
+      if (g_bustrap_hook(tid, context) == OK)
+        {
+          /* Hook handled the trap, return normally */
+
+          return OK;
+        }
     }
-#  endif
 
-  if (tclass == TRICORE_TRAP_CLASS_BUS && tid == TRICORE_TIN_CAE)
+  /* Hook did not handle or no hook registered, proceed with panic */
+
+#ifdef CONFIG_ARCH_HAVE_FPU
+  if (tid == TRICORE_TRAP_BUS_CAE)
     {
-      _alert("\tFPU_ASYNC_TRAP:%" PRIX32 "\n\n",
-             tricore_mfcr(FPU_ASYNC_TRAP_REG));
-      tricore_mtcr(FPU_ASYNC_TRAP_REG, tricore_mfcr(FPU_ASYNC_TRAP_REG) |
-                                       (1U << FPU_TRAP_TCL_SHIFT));
+      uint32_t fpu_async = tricore_mfcr(FPU_ASYNC_TRAP_REG);
+
+      _alert("\tFPU_ASYNC_TRAP:%" PRIX32 "\n\n", fpu_async);
+      tricore_mtcr(FPU_ASYNC_TRAP_REG,
+                   fpu_async | (1U << FPU_TRAP_TCL_SHIFT));
       UP_ISB();
     }
 #endif
+
+  tricore_defaulttrap(TRICORE_TRAP_CLASS_BUS, tid, context);
+
+  return OK;
 }
 
 /****************************************************************************
@@ -289,10 +267,9 @@ void tricore_bustrap_register_hook(tricore_bustrap_hook_t 
hook)
   g_bustrap_hook = hook;
 }
 
-int weak_function tricore_nmitrap(uint32_t tid, void *context, void *arg)
+void weak_function tricore_nmitrap(uint32_t tid, void *context)
 {
-  tricore_trap_panic(TRICORE_TRAP_CLASS_NMI, tid, context);
-  return OK;
+  tricore_defaulttrap(TRICORE_TRAP_CLASS_NMI, tid, context);
 }
 
 /****************************************************************************
@@ -303,16 +280,21 @@ int weak_function tricore_nmitrap(uint32_t tid, void 
*context, void *arg)
  *
  ****************************************************************************/
 
-void tricore_trapcall(volatile void *trap)
+noinstrument_function
+void tricore_trapcall(void *taddr, uint32_t tid, uint32_t tclass)
 {
+  struct tricore_trap_s trap;
   uintptr_t *regs;
   bool from_task;
 
-  struct tricore_trap_s *ctrap = (struct tricore_trap_s *)trap;
-  uint8_t tclass = ctrap->tclass;
-  unsigned int tid = ctrap->tid;
-
-  tricore_trapinfo(trap);
+  trap.taddr  = (uintptr_t)taddr;
+  trap.tid    = tid;
+  trap.tclass = tclass;
+  trap.tcpu   = up_cpu_index();
+  trap.tpstr  = tricore_mfcr(TRICORE_CPU_PSTR);
+  trap.tdstr  = tricore_mfcr(TRICORE_CPU_DSTR);
+  trap.tdatr  = tricore_mfcr(TRICORE_CPU_DATR);
+  trap.tdeadd = tricore_mfcr(TRICORE_CPU_DEADD);
 
   regs = tricore_csa2addr(tricore_mfcr(TRICORE_CPU_PCXI));
 
@@ -324,124 +306,119 @@ void tricore_trapcall(volatile void *trap)
       g_running_tasks[this_cpu()]->xcp.regs = regs;
     }
 
-  if (tclass == TRICORE_TRAP_CLASS_NMI)
-    {
-      tricore_nmitrap(tid, regs, NULL);
-      tricore_jump_backto_link();
-    }
+  /* Save trap info for coredump */
 
-  /* A bus trap hook of a safety test module (e.g., BusMonTst) may handle
-   * an expected bus error.
-   */
+  g_trapinfo = trap;
 
-  if (tclass == TRICORE_TRAP_CLASS_BUS && g_bustrap_hook != NULL &&
-      g_bustrap_hook(tid, regs) == OK)
+  switch (tclass)
     {
-      if (from_task)
-        {
-          /* g_running_tasks[]->xcp.regs is about to become invalid
-           * and will be marked as NULL to avoid misusage.
-           */
+      case TRICORE_TRAP_CLASS_INSTERR:
+        tricore_insterrorstrap(tid, regs);
+        break;
 
-          g_running_tasks[this_cpu()]->xcp.regs = NULL;
-        }
+      case TRICORE_TRAP_CLASS_BUS:
+        tricore_bustrap(tid, regs);
+        break;
+
+      case TRICORE_TRAP_CLASS_NMI:
+        tricore_nmitrap(tid, regs);
+        break;
 
-      tricore_jump_backto_link();
+      default:
+        tricore_defaulttrap(tclass, tid, regs);
+        break;
     }
 
-  tricore_trap_fpu(tclass, tid);
-  tricore_trap_panic(tclass, tid, regs);
+  if (from_task)
+    {
+      /* g_running_tasks[]->xcp.regs is about to become invalid
+       * and will be marked as NULL to avoid misusage.
+       */
+
+      g_running_tasks[this_cpu()]->xcp.regs = NULL;
+    }
+
+  tricore_jump_backto_link();
 }
 
 /****************************************************************************
- * Name: tricore_fcu_register_pool
+ * Function:  tricore_trapinit
  *
  * Description:
- *   Register the context save areas that the free context list underflow
- *   (FCU) trap uses to report the trap when no free CSA is left.  The pool
- *   is linked only when the trap happens, so it may also be RAM that is in
- *   use until then.
- *
- * Input Parameters:
- *   base - 64-byte aligned start of the pool
- *   num  - Number of context save areas, at least 20: two for the trapped
- *          context, the rest for the panic path
+ *   Trap init for tricore arch.
  *
  ****************************************************************************/
 
-void tricore_fcu_register_pool(void *base, size_t num)
+void tricore_trapinit(void)
 {
-  DEBUGASSERT(base != NULL);
-  DEBUGASSERT(((uintptr_t)base & (TC_CONTEXT_SIZE - 1)) == 0);
-
-  g_tricore_fcu_num  = num;
-  g_tricore_fcu_pool = base;
+#ifdef CONFIG_COREDUMP
+  coredump_add_memory_region(&g_trapinfo, sizeof(struct tricore_trap_s),
+                             PF_REGISTER);
+#endif
 }
 
 /****************************************************************************
- * Name: tricore_fcu_recover
+ * Name: tricore_fcutrap_recover
  *
  * Description:
- *   Entered by a jump from tricore_fcu_entry, after the trapped upper and
- *   lower context were saved into the first two CSAs of the FCU pool.
- *   Link the rest of the pool into the free context list, point PCXI at
- *   the saved lower context and report the trap through the normal trap
- *   entry, as a context management trap with TIN 4.
+ *   Entered from tricore_fcu_entry, after the trapped upper and lower
+ *   context have been saved into the first two CSAs of the FCU pool.
+ *
+ *   The FCU pool registered via tricore_fcu_register_pool() may be backed
+ *   in one of two ways:
+ *
+ *     1. Reuse a RAM block that normal business keeps occupying until the
+ *        system crashes (preferred when RAM is tight), the block becomes
+ *        available at trap time.
+ *     2. A dedicated static buffer reserved up front (when RAM is enough).
+ *
+ *   Either way the LPCXI chain is built lazily here at trap time, not at
+ *   registration: for case (1) writing it earlier would corrupt live
+ *   business data, so the linking is deferred until normal business has
+ *   ceased.
  *
  ****************************************************************************/
 
-noinstrument_function void tricore_fcu_recover(void)
+used_code noinstrument_function
+void tricore_fcutrap_recover(void)
 {
-  uintptr_t *csa = g_tricore_fcu_pool;
+  uintptr_t *csa_iter;
+  uintptr_t csa;
   size_t i;
 
-  for (i = 2; i < g_tricore_fcu_num - 1; i++)
+  DEBUGASSERT(g_fcu_csa_num >= TRICORE_FCU_CSA_MINNUM);
+
+  /* Link the pool csas into free chain. */
+
+  csa = tricore_addr2csa(g_fcu_csa_base);
+  csa_iter = &g_fcu_csa_base[2 * TC_CONTEXT_REGS];
+  for (i = 2; i < g_fcu_csa_num - 1; i++)
     {
-      csa[i * TC_CONTEXT_REGS + REG_LPCXI] =
-        tricore_addr2csa(&csa[(i + 1) * TC_CONTEXT_REGS]);
+      csa_iter[REG_LPCXI] = tricore_addr2csa(csa_iter + TC_CONTEXT_REGS);
+      csa_iter += TC_CONTEXT_REGS;
     }
 
-  csa[(g_tricore_fcu_num - 1) * TC_CONTEXT_REGS + REG_LPCXI] = 0;
-  csa[TC_CONTEXT_REGS + REG_LPCXI] = tricore_addr2csa(csa) | PCXI_UL;
-
-  tricore_mtcr(TRICORE_CPU_PCXI, tricore_addr2csa(&csa[TC_CONTEXT_REGS]));
-  tricore_mtcr(TRICORE_CPU_FCX,
-               tricore_addr2csa(&csa[2 * TC_CONTEXT_REGS]));
-  UP_ISB();
+  csa_iter[REG_LPCXI] = 0;
 
-  /* A11 is the trap return address, from the saved upper context */
+  g_fcu_csa_base[TC_CONTEXT_REGS + REG_LPCXI] = csa | PCXI_UL;
 
-#ifdef CONFIG_TRICORE_TOOLCHAIN_TASKING
-  __asm__ __volatile__ ("ld.a a11, [%0]12\n\t"
-                        "mov d15, #4\n\t"
-                        "mov d5, #3\n\t"
-                        "j tricore_trap_entry\n\t" : : "a"(csa));
-#else
-  __asm__ __volatile__ ("ld.a %%a11, [%0]12\n\t"
-                        "mov %%d15, 4\n\t"
-                        "mov %%d5, 3\n\t"
-                        "j tricore_trap_entry\n\t" : : "a"(csa));
-#endif
+  tricore_mtcr(TRICORE_CPU_PCXI, csa + 1);
+  tricore_mtcr(TRICORE_CPU_FCX, csa + 2);
+  UP_ISB();
 
-  for (; ; );
+  tricore_jump_backto_link();
 }
 
 /****************************************************************************
- * Function:  tricore_trapinit
- *
- * Description:
- *   Trap init for tricore arch.
- *
+ * Name: tricore_fcu_register_pool
  ****************************************************************************/
 
-void tricore_trapinit(void)
+void tricore_fcu_register_pool(void *base, size_t num)
 {
-#if CONFIG_TRICORE_FCU_CSA_NUM > 0
-  tricore_fcu_register_pool(g_fcu_csa, CONFIG_TRICORE_FCU_CSA_NUM);
-#endif
+  DEBUGASSERT(base != NULL);
+  DEBUGASSERT(((uintptr_t)base & (TC_CONTEXT_SIZE - 1)) == 0);
+  DEBUGASSERT(num >= TRICORE_FCU_CSA_MINNUM);
 
-#ifdef CONFIG_COREDUMP
-  coredump_add_memory_region(&g_trapinfo, sizeof(g_trapinfo),
-                             PF_REGISTER);
-#endif
+  g_fcu_csa_base = (uintptr_t *)base;
+  g_fcu_csa_num  = num;
 }
diff --git a/arch/tricore/src/common/tricore_vectors.h 
b/arch/tricore/src/common/tricore_vectors.h
new file mode 100644
index 00000000000..d97a7ca69a6
--- /dev/null
+++ b/arch/tricore/src/common/tricore_vectors.h
@@ -0,0 +1,163 @@
+/****************************************************************************
+ * arch/tricore/src/common/tricore_vectors.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_TRICORE_SRC_COMMON_TRICORE_VECTORS_H
+#define __ARCH_TRICORE_SRC_COMMON_TRICORE_VECTORS_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stddef.h>
+#include <stdint.h>
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+/* Bus trap hook function type for safety test modules.
+ * Returns OK if the trap was handled, ERROR otherwise.
+ */
+
+typedef int (*tricore_bustrap_hook_t)(uint32_t tid, void *context);
+
+/* Arch-native TriCore trap definitions. */
+
+enum tricore_trap_class_e
+{
+  TRICORE_TRAP_CLASS_MMU       = 0,  /* Memory management */
+  TRICORE_TRAP_CLASS_INTPROT   = 1,  /* Internal protection */
+  TRICORE_TRAP_CLASS_INSTERR   = 2,  /* Instruction errors */
+  TRICORE_TRAP_CLASS_CTXMGMT   = 3,  /* Context management */
+  TRICORE_TRAP_CLASS_BUS       = 4,  /* Bus */
+  TRICORE_TRAP_CLASS_ASSERT    = 5,  /* Assertion */
+  TRICORE_TRAP_CLASS_SYSCALL   = 6,  /* System call */
+  TRICORE_TRAP_CLASS_NMI       = 7,  /* Non maskable interrupt */
+};
+
+/* Memory management (MMU) trap identification numbers */
+
+enum tricore_trap_mmu_id_e
+{
+  TRICORE_TRAP_MMU_VAF         = 0,  /* Virtual address fill */
+  TRICORE_TRAP_MMU_VAP         = 1,  /* Virtual address protection */
+};
+
+/* Internal protection trap identification numbers */
+
+enum tricore_trap_intprot_id_e
+{
+  TRICORE_TRAP_INTPROT_PRIV    = 1,  /* Privilege violation */
+  TRICORE_TRAP_INTPROT_MPR     = 2,  /* Memory protection read */
+  TRICORE_TRAP_INTPROT_MPW     = 3,  /* Memory protection write */
+  TRICORE_TRAP_INTPROT_MPX     = 4,  /* Memory protection execute */
+  TRICORE_TRAP_INTPROT_MPP     = 5,  /* Memory protection peripheral access */
+  TRICORE_TRAP_INTPROT_MPN     = 6,  /* Memory protection null address */
+  TRICORE_TRAP_INTPROT_GRWP    = 7,  /* Global register write protection */
+};
+
+/* Instruction errors trap identification numbers */
+
+enum tricore_trap_insterr_id_e
+{
+  TRICORE_TRAP_INSTERR_IOPC    = 1,  /* Illegal opcode */
+  TRICORE_TRAP_INSTERR_UOPC    = 2,  /* Unimplemented opcode */
+  TRICORE_TRAP_INSTERR_OPD     = 3,  /* Invalid operand specification */
+  TRICORE_TRAP_INSTERR_ALN     = 4,  /* Data address alignment */
+  TRICORE_TRAP_INSTERR_MEM     = 5,  /* Invalid local memory address */
+  TRICORE_TRAP_INSTERR_CSE     = 6,  /* Coprocessor trap synchronous error */
+};
+
+/* Context management trap identification numbers */
+
+enum tricore_trap_ctxmgmt_id_e
+{
+  TRICORE_TRAP_CTXMGMT_FCD     = 1,  /* Free context list depletion */
+  TRICORE_TRAP_CTXMGMT_CDO     = 2,  /* Call depth overflow */
+  TRICORE_TRAP_CTXMGMT_CDU     = 3,  /* Call depth underflow */
+  TRICORE_TRAP_CTXMGMT_FCU     = 4,  /* Free context list underflow */
+  TRICORE_TRAP_CTXMGMT_CSU     = 5,  /* Call stack underflow */
+  TRICORE_TRAP_CTXMGMT_CTYP    = 6,  /* Context type */
+  TRICORE_TRAP_CTXMGMT_NEST    = 7,  /* Nesting error */
+};
+
+/* Bus trap identification numbers */
+
+enum tricore_trap_bus_id_e
+{
+  TRICORE_TRAP_BUS_PSE         = 1,  /* Program fetch synchronous error */
+  TRICORE_TRAP_BUS_DSE         = 2,  /* Data access synchronous error */
+  TRICORE_TRAP_BUS_DAE         = 3,  /* Data access asynchronous error */
+  TRICORE_TRAP_BUS_CAE         = 4,  /* Coprocessor trap asynchronous error */
+  TRICORE_TRAP_BUS_PIE         = 5,  /* Program memory integrity error */
+  TRICORE_TRAP_BUS_DIE         = 6,  /* Data memory integrity error */
+  TRICORE_TRAP_BUS_TAE         = 7,  /* Temporal asynchronous error */
+};
+
+/* Assertion trap identification numbers */
+
+enum tricore_trap_assert_id_e
+{
+  TRICORE_TRAP_ASSERT_OVF      = 1,  /* Arithmetic overflow */
+  TRICORE_TRAP_ASSERT_SOVF     = 2,  /* Sticky arithmetic overflow */
+};
+
+/* Non-maskable interrupt trap identification numbers */
+
+enum tricore_trap_nmi_id_e
+{
+  TRICORE_TRAP_NMI_NMI         = 0,  /* Non-maskable interrupt */
+};
+
+/* Trap information record. */
+
+struct tricore_trap_s
+{
+  uintptr_t taddr;
+  uint32_t  tid    : 8;
+  uint32_t  tclass : 8;
+  uint32_t  tcpu   : 3;
+  uint32_t  tpstr;    /* Program Synchronous Trap Register */
+  uint32_t  tdstr;    /* Data Synchronous Trap Register    */
+  uint32_t  tdatr;    /* Data Asynchronous Trap Register   */
+  uint32_t  tdeadd;   /* Data Error Address Register       */
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* Trap Handler */
+
+void tricore_svcall(volatile void *trap);
+void tricore_trapcall(void *taddr, uint32_t tid, uint32_t tclass);
+void tricore_trapinit(void);
+void tricore_bustrap_register_hook(tricore_bustrap_hook_t hook);
+void tricore_fcu_register_pool(void *base, size_t num);
+void tricore_fcutrap_recover(void);
+
+#endif /* __ASSEMBLY__ */
+#endif /* __ARCH_TRICORE_SRC_COMMON_TRICORE_VECTORS_H */
diff --git a/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.ld 
b/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.ld
index 80fb7fcb4b5..e68bb68c611 100644
--- a/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.ld
+++ b/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.ld
@@ -88,13 +88,13 @@ SECTIONS
   .traptab ORIGIN(pfls) + 0x100 :
   {
     __TRAPTAB_CPU0 = .;
-    KEEP(*(.traptab_cpu0))
+    KEEP(*(.traptab))
   } > pfls
 
   .intvec ORIGIN(pfls) + 0x1fe0 :
   {
     __INTTAB_CPU0 = ORIGIN(pfls);
-    KEEP(*(.intvec))
+    KEEP(*(.inttab))
   } > pfls
 
   .text :
diff --git a/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.lsl 
b/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.lsl
index 1886918cc98..d9615ec1b06 100644
--- a/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.lsl
+++ b/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.lsl
@@ -111,12 +111,12 @@ section_layout mpe:tc0:linear
 
   group traptab (ordered, run_addr = PFLS_BASE + 0x100)
   {
-    select ".text.traptab_cpu0";
+    select ".text.traptab";
   }
 
   group intvec (ordered, run_addr = PFLS_BASE + 0x1fe0)
   {
-    select ".text.intvec";
+    select ".text.inttab";
   }
 
   group text (run_addr = mem:mpe:pfls)
diff --git a/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.ld 
b/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.ld
index 8ef0f726123..fc63b06acd8 100644
--- a/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.ld
+++ b/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.ld
@@ -94,13 +94,13 @@ SECTIONS
   .traptab ORIGIN(pfls) + 0x100 :
   {
     __TRAPTAB_CPU0 = .;
-    KEEP(*(.traptab_cpu0))
+    KEEP(*(.traptab))
   } > pfls
 
   .intvec ORIGIN(pfls) + 0x1fe0 :
   {
     __INTTAB_CPU0 = ORIGIN(pfls);
-    KEEP(*(.intvec))
+    KEEP(*(.inttab))
   } > pfls
 
   .text :
diff --git a/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.lsl 
b/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.lsl
index 359255c2d3f..e911e50fe06 100644
--- a/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.lsl
+++ b/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.lsl
@@ -123,12 +123,12 @@ section_layout mpe:tc0:linear
 
   group traptab (ordered, run_addr = PFLS_BASE + 0x100)
   {
-    select ".text.traptab_cpu0";
+    select ".text.traptab";
   }
 
   group intvec (ordered, run_addr = PFLS_BASE + 0x1fe0)
   {
-    select ".text.intvec";
+    select ".text.inttab";
   }
 
   group text (run_addr = mem:mpe:pfls)

Reply via email to