Skip to content

Commit c2b1e8d

Browse files
tbr-ttioannisg
authored andcommitted
SPARC: implement ARCH_EXCEPT()
Introduce a new software trap 15 which is generated by the ARCH_EXCEPT() function macro. The handler for this software trap calls z_sparc_fatal_error() and finally z_fatal_error() with "reason" and ESF as arguments. Signed-off-by: Martin Åberg <[email protected]>
1 parent 9da5a78 commit c2b1e8d

File tree

4 files changed

+43
-15
lines changed

4 files changed

+43
-15
lines changed

arch/sparc/core/fatal.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,3 @@ FUNC_NORETURN void z_sparc_fatal_error(unsigned int reason,
2323
z_fatal_error(reason, esf);
2424
CODE_UNREACHABLE;
2525
}
26-
27-
FUNC_NORETURN void _Fault(const z_arch_esf_t *esf)
28-
{
29-
LOG_ERR("Trap tt=0x%02x", (esf->tbr >> 4) & 0xff);
30-
31-
z_sparc_fatal_error(K_ERR_CPU_EXCEPTION, esf);
32-
}

arch/sparc/core/fault_trap.S

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <offsets_short.h>
1010
#include <arch/sparc/sparc.h>
1111

12+
GTEXT(__sparc_trap_except_reason)
1213
GTEXT(__sparc_trap_fault)
1314

1415
/*
@@ -22,11 +23,14 @@ GTEXT(__sparc_trap_fault)
2223
* %l2: npc
2324
* %l6: tbr (set by trap code)
2425
* %fp: %sp of current register window at trap time
26+
* %g1: reason
2527
*
2628
* This trap handler will trash some of the global registers, which is OK since
2729
* we will not return to where we trapped.
2830
*/
29-
SECTION_FUNC(TEXT, __sparc_trap_fault)
31+
SECTION_FUNC(TEXT, __sparc_trap_except_reason)
32+
mov %g1, %l7
33+
.Ldoit:
3034
/* We may have trapped into the invalid window. If so, make it valid. */
3135
rd %wim, %g2
3236
srl %g2, %l0, %g3
@@ -66,6 +70,7 @@ SECTION_FUNC(TEXT, __sparc_trap_fault)
6670
* %sp: %sp of interrupted task - ABI_frame - esf
6771
*/
6872

73+
mov %l7, %o0
6974
/* Fill in the content of the exception stack frame */
7075
st %l1, [%sp + 96 + __z_arch_esf_t_pc_OFFSET]
7176
st %l2, [%sp + 96 + __z_arch_esf_t_npc_OFFSET]
@@ -76,11 +81,27 @@ SECTION_FUNC(TEXT, __sparc_trap_fault)
7681
st %g1, [%sp + 96 + __z_arch_esf_t_y_OFFSET]
7782

7883
/* Enable traps, raise PIL to mask all maskable interrupts. */
79-
or %l0, PSR_PIL, %o0
80-
wr %o0, PSR_ET, %psr
84+
or %l0, PSR_PIL, %o2
85+
wr %o2, PSR_ET, %psr
8186
nop
8287
nop
8388
nop
84-
/* Exception stack frame prepared earlier is the first argument. */
85-
call _Fault
86-
add %sp, 96, %o0
89+
/*
90+
* reason is the first argument.
91+
* Exception stack frame prepared earlier is the second argument.
92+
*/
93+
call z_sparc_fatal_error
94+
add %sp, 96, %o1
95+
96+
97+
/*
98+
* Entry for trap we don't handle explicitly
99+
*
100+
* Just drop into __sparc_trap_except_reason with reason set to
101+
* K_ERR_CPU_EXCEPTION. Note that "reason" is transported in %l7 of the
102+
* trapped-into window and global %g1 is preserved.
103+
*/
104+
SECTION_FUNC(TEXT, __sparc_trap_fault)
105+
b .Ldoit
106+
/* K_ERR_CPU_EXCEPTION */
107+
mov %g0, %l7

arch/sparc/core/trap_table_mvt.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
rd %psr, %l0; \
3030
sethi %hi(handler), %l4; \
3131
jmp %l4+%lo(handler); \
32-
nop;
32+
rd %tbr, %l6;
3333

3434
#define RESET_TRAP(handler) \
3535
mov %g0, %g4; \
@@ -168,7 +168,7 @@ __start:
168168
SOFT_TRAP; ! 12
169169
IRQ_OFFLOAD_TRAP; ! 13
170170
SOFT_TRAP; ! 14
171-
SOFT_TRAP; ! 15
171+
TRAP(__sparc_trap_except_reason); ! 15
172172
SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 90 - 93
173173
SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 94 - 97
174174
SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 98 - 9B

include/arch/sparc/arch.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
*/
3535
#define SPARC_SW_TRAP_FLUSH_WINDOWS 0x03
3636
#define SPARC_SW_TRAP_SET_PIL 0x09
37+
#define SPARC_SW_TRAP_EXCEPT 0x0F
3738

3839
#ifndef _ASMLANGUAGE
3940
#include <sys/util.h>
@@ -111,6 +112,19 @@ struct __esf {
111112

112113
typedef struct __esf z_arch_esf_t;
113114

115+
#define ARCH_EXCEPT(reason_p) \
116+
do { \
117+
register uint32_t _g1 __asm__("g1") = reason_p; \
118+
\
119+
__asm__ volatile ( \
120+
"ta %[vector]\n\t" \
121+
: \
122+
: [vector] "i" (SPARC_SW_TRAP_EXCEPT), "r" (_g1) \
123+
: "memory" \
124+
); \
125+
CODE_UNREACHABLE; \
126+
} while (false)
127+
114128
#ifdef __cplusplus
115129
}
116130
#endif

0 commit comments

Comments
 (0)