arch: arm64: Dump registers content on fatal error

Extend the ESF structure and dump the most important registers in the
error exception handler.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
This commit is contained in:
Carlo Caione 2020-01-20 16:14:17 +01:00 committed by Anas Nashif
commit 3aef85458d
7 changed files with 52 additions and 15 deletions

View file

@ -131,7 +131,31 @@ static void print_EC_cause(u64_t esr)
}
}
void z_arm64_fatal_error(unsigned int reason)
static void esf_dump(const z_arch_esf_t *esf)
{
LOG_ERR("x1: %-8llx x0: %llx",
esf->basic.regs[18], esf->basic.regs[19]);
LOG_ERR("x2: %-8llx x3: %llx",
esf->basic.regs[16], esf->basic.regs[17]);
LOG_ERR("x4: %-8llx x5: %llx",
esf->basic.regs[14], esf->basic.regs[15]);
LOG_ERR("x6: %-8llx x7: %llx",
esf->basic.regs[12], esf->basic.regs[13]);
LOG_ERR("x8: %-8llx x9: %llx",
esf->basic.regs[10], esf->basic.regs[11]);
LOG_ERR("x10: %-8llx x11: %llx",
esf->basic.regs[8], esf->basic.regs[9]);
LOG_ERR("x12: %-8llx x13: %llx",
esf->basic.regs[6], esf->basic.regs[7]);
LOG_ERR("x14: %-8llx x15: %llx",
esf->basic.regs[4], esf->basic.regs[5]);
LOG_ERR("x16: %-8llx x17: %llx",
esf->basic.regs[2], esf->basic.regs[3]);
LOG_ERR("x18: %-8llx x30: %llx",
esf->basic.regs[0], esf->basic.regs[1]);
}
void z_arm64_fatal_error(unsigned int reason, const z_arch_esf_t *esf)
{
u64_t el, esr, elr, far;
@ -170,7 +194,10 @@ void z_arm64_fatal_error(unsigned int reason)
}
z_fatal_error(reason, NULL);
if (esf != NULL) {
esf_dump(esf);
}
z_fatal_error(reason, esf);
CODE_UNREACHABLE;
}

View file

@ -19,7 +19,7 @@
#include <linker/sections.h>
#include <sw_isr_table.h>
extern void z_arm64_fatal_error(unsigned int reason);
void z_arm64_fatal_error(unsigned int reason, const z_arch_esf_t *esf);
void arch_irq_enable(unsigned int irq)
{
@ -56,5 +56,5 @@ void z_irq_spurious(void *unused)
{
ARG_UNUSED(unused);
z_arm64_fatal_error(K_ERR_SPURIOUS_IRQ);
z_arm64_fatal_error(K_ERR_SPURIOUS_IRQ, NULL);
}

View file

@ -237,8 +237,8 @@ exit:
b z_arm64_exit_exc
inv:
/* K_ERR_CPU_EXCEPTION */
mov x0, #0
mov x1, sp
mov x0, #0 /* K_ERR_CPU_EXCEPTION */
b z_arm64_fatal_error

View file

@ -56,10 +56,10 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
pInitCtx = (struct __esf *)(STACK_ROUND_DOWN(stackEnd -
sizeof(struct __basic_sf)));
pInitCtx->basic.x0 = (u64_t)pEntry;
pInitCtx->basic.x1 = (u64_t)parameter1;
pInitCtx->basic.x2 = (u64_t)parameter2;
pInitCtx->basic.x3 = (u64_t)parameter3;
pInitCtx->basic.regs[0] = (u64_t)pEntry;
pInitCtx->basic.regs[1] = (u64_t)parameter1;
pInitCtx->basic.regs[2] = (u64_t)parameter2;
pInitCtx->basic.regs[3] = (u64_t)parameter3;
/*
* We are saving:

View file

@ -86,6 +86,19 @@ SECTION_SUBSEC_FUNC(exc_vector_table,_vector_table_section,_vector_table)
/* Current EL with SPx / SError */
.align 7
stp x0, x1, [sp, #-16]!
stp x2, x3, [sp, #-16]!
stp x4, x5, [sp, #-16]!
stp x6, x7, [sp, #-16]!
stp x8, x9, [sp, #-16]!
stp x10, x11, [sp, #-16]!
stp x12, x13, [sp, #-16]!
stp x14, x15, [sp, #-16]!
stp x16, x17, [sp, #-16]!
stp x18, x30, [sp, #-16]!
mov x1, sp
mov x0, #0 /* K_ERR_CPU_EXCEPTION */
b z_arm64_fatal_error

View file

@ -38,7 +38,7 @@ arch_thread_return_value_set(struct k_thread *thread, unsigned int value)
thread->arch.swap_return_value = value;
}
extern void z_arm64_fatal_error(unsigned int reason);
extern void z_arm64_fatal_error(const z_arch_esf_t *esf, unsigned int reason);
#endif /* _ASMLANGUAGE */

View file

@ -26,10 +26,7 @@ extern "C" {
struct __esf {
struct __basic_sf {
u64_t x0;
u64_t x1;
u64_t x2;
u64_t x3;
u64_t regs[20];
} basic;
};