Sandrine Bailleux | a43b003 | 2019-01-14 14:04:32 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2019, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <stdint.h> |
| 8 | #include <stdio.h> |
| 9 | |
| 10 | #include <arch_helpers.h> |
| 11 | #include <debug.h> |
| 12 | #include <platform.h> |
| 13 | #include <utils_def.h> |
| 14 | |
| 15 | /* We save r0-r12. */ |
| 16 | #define GPREGS_CNT 13 |
| 17 | |
| 18 | /* Set of registers saved by the crash_dump() assembly function. */ |
| 19 | struct cpu_context { |
| 20 | u_register_t regs[GPREGS_CNT]; |
| 21 | u_register_t lr; |
| 22 | u_register_t sp; |
| 23 | }; |
| 24 | |
| 25 | void __dead2 print_exception(const struct cpu_context *ctx) |
| 26 | { |
| 27 | u_register_t mpid = read_mpidr(); |
| 28 | |
| 29 | /* |
| 30 | * The instruction barrier ensures we don't read stale values of system |
| 31 | * registers. |
| 32 | */ |
| 33 | isb(); |
| 34 | |
| 35 | printf("Unhandled exception on CPU%u.\n", platform_get_core_pos(mpid)); |
| 36 | |
| 37 | /* Dump some interesting system registers. */ |
| 38 | printf("System registers:\n"); |
| 39 | printf(" MPIDR=0x%lx\n", mpid); |
| 40 | printf(" HSR=0x%lx ELR=0x%lx SPSR=0x%lx\n", read_hsr(), |
| 41 | read_elr_hyp(), read_spsr()); |
| 42 | |
| 43 | /* Dump general-purpose registers. */ |
| 44 | printf("General-purpose registers:\n"); |
| 45 | for (int i = 0; i < GPREGS_CNT; ++i) { |
| 46 | printf(" r%u=0x%lx\n", i, ctx->regs[i]); |
| 47 | } |
| 48 | printf(" LR=0x%lx\n", ctx->lr); |
| 49 | printf(" SP=0x%lx\n", ctx->sp); |
| 50 | |
| 51 | while (1) |
| 52 | wfi(); |
| 53 | } |