Skip to content

Commit 716efb2

Browse files
dcpleungcarlescufi
authored andcommitted
xtensa: extract printing of fatal exception into its own func
This extracts the printing of fatal exception information into its own function to declutter xtensa_excint1_c(). Signed-off-by: Daniel Leung <[email protected]> Signed-off-by: Flavio Ceolin <[email protected]>
1 parent e9c449a commit 716efb2

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

arch/xtensa/core/xtensa-asm2.c

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,39 @@ static inline unsigned int get_bits(int offset, int num_bits, unsigned int val)
202202
return val & mask;
203203
}
204204

205+
static void print_fatal_exception(_xtensa_irq_bsa_t *bsa, int cause,
206+
bool is_dblexc, uint32_t depc)
207+
{
208+
void *pc;
209+
uint32_t ps, vaddr;
210+
211+
ps = bsa->ps;
212+
pc = (void *)bsa->pc;
213+
214+
__asm__ volatile("rsr.excvaddr %0" : "=r"(vaddr));
215+
216+
LOG_ERR(" ** FATAL EXCEPTION%s", (is_dblexc ? " (DOUBLE)" : ""));
217+
LOG_ERR(" ** CPU %d EXCCAUSE %d (%s)",
218+
arch_curr_cpu()->id, cause,
219+
z_xtensa_exccause(cause));
220+
LOG_ERR(" ** PC %p VADDR %p", pc, (void *)vaddr);
221+
222+
if (is_dblexc) {
223+
LOG_ERR(" ** DEPC %p", (void *)depc);
224+
}
225+
226+
#ifdef CONFIG_USERSPACE
227+
LOG_ERR(" ** THREADPTR %p", (void *)bsa->threadptr);
228+
#endif /* CONFIG_USERSPACE */
229+
230+
LOG_ERR(" ** PS %p", (void *)bsa->ps);
231+
LOG_ERR(" ** (INTLEVEL:%d EXCM: %d UM:%d RING:%d WOE:%d OWB:%d CALLINC:%d)",
232+
get_bits(0, 4, ps), get_bits(4, 1, ps),
233+
get_bits(5, 1, ps), get_bits(6, 2, ps),
234+
get_bits(18, 1, ps),
235+
get_bits(8, 4, ps), get_bits(16, 2, ps));
236+
}
237+
205238
static ALWAYS_INLINE void usage_stop(void)
206239
{
207240
#ifdef CONFIG_SCHED_THREAD_USAGE
@@ -296,18 +329,13 @@ static inline DEF_INT_C_HANDLER(1)
296329
*/
297330
void *xtensa_excint1_c(int *interrupted_stack)
298331
{
299-
int cause, vaddr;
332+
int cause;
300333
_xtensa_irq_bsa_t *bsa = (void *)*(int **)interrupted_stack;
301334
bool is_fatal_error = false;
335+
bool is_dblexc = false;
302336
uint32_t ps;
303337
void *pc;
304-
305-
#ifdef CONFIG_XTENSA_MMU
306-
bool is_dblexc;
307-
uint32_t depc;
308-
#else
309-
const bool is_dblexc = false;
310-
#endif /* CONFIG_XTENSA_MMU */
338+
uint32_t depc = 0;
311339

312340
__asm__ volatile("rsr.exccause %0" : "=r"(cause));
313341

@@ -359,8 +387,6 @@ void *xtensa_excint1_c(int *interrupted_stack)
359387
}
360388
#endif /* CONFIG_USERSPACE */
361389

362-
__asm__ volatile("rsr.excvaddr %0" : "=r"(vaddr));
363-
364390
/* Default for exception */
365391
int reason = K_ERR_CPU_EXCEPTION;
366392
is_fatal_error = true;
@@ -380,24 +406,7 @@ void *xtensa_excint1_c(int *interrupted_stack)
380406
reason = bsa->a2;
381407
}
382408

383-
LOG_ERR(" ** FATAL EXCEPTION%s", (is_dblexc ? " (DOUBLE)" : ""));
384-
LOG_ERR(" ** CPU %d EXCCAUSE %d (%s)",
385-
arch_curr_cpu()->id, cause,
386-
z_xtensa_exccause(cause));
387-
LOG_ERR(" ** PC %p VADDR %p",
388-
pc, (void *)vaddr);
389-
LOG_ERR(" ** PS %p", (void *)bsa->ps);
390-
if (is_dblexc) {
391-
LOG_ERR(" ** DEPC %p", (void *)depc);
392-
}
393-
#ifdef CONFIG_USERSPACE
394-
LOG_ERR(" ** THREADPTR %p", (void *)bsa->threadptr);
395-
#endif /* CONFIG_USERSPACE */
396-
LOG_ERR(" ** (INTLEVEL:%d EXCM: %d UM:%d RING:%d WOE:%d OWB:%d CALLINC:%d)",
397-
get_bits(0, 4, ps), get_bits(4, 1, ps),
398-
get_bits(5, 1, ps), get_bits(6, 2, ps),
399-
get_bits(18, 1, ps),
400-
get_bits(8, 4, ps), get_bits(16, 2, ps));
409+
print_fatal_exception(bsa, cause, is_dblexc, depc);
401410

402411
/* FIXME: legacy xtensa port reported "HW" exception
403412
* for all unhandled exceptions, which seems incorrect

0 commit comments

Comments
 (0)