|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 NVIDIA Corporation <[email protected]> * |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <zephyr/kernel.h> |
| 8 | +#include <zephyr/logging/log.h> |
| 9 | +LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); |
| 10 | + |
| 11 | +FUNC_NORETURN void z_openrisc_fatal_error(unsigned int reason, |
| 12 | + const struct arch_esf *esf) |
| 13 | +{ |
| 14 | +#ifdef CONFIG_EXCEPTION_DEBUG |
| 15 | + if (esf != NULL) { |
| 16 | + LOG_ERR("epcr: 0x%08x esr: 0x%08x", esf->epcr, esf->esr); |
| 17 | + LOG_ERR(" r3: 0x%08x r4: 0x%08x r5: 0x%08x r6: 0x%08x", |
| 18 | + esf->r3, esf->r4, esf->r5, esf->r6); |
| 19 | + LOG_ERR(" r7: 0x%08x r8: 0x%08x", |
| 20 | + esf->r7, esf->r8); |
| 21 | + LOG_ERR(" r11: 0x%08x r12: 0x%08x", |
| 22 | + esf->r11, esf->r12); |
| 23 | + LOG_ERR(" r13: 0x%08x r15: 0x%08x r17: 0x%08x r19: 0x%08x", |
| 24 | + esf->r13, esf->r15, esf->r17, esf->r19); |
| 25 | + LOG_ERR(" r21: 0x%08x r23: 0x%08x r25: 0x%08x r27: 0x%08x", |
| 26 | + esf->r21, esf->r23, esf->r25, esf->r27); |
| 27 | + LOG_ERR(" r29: 0x%08x r31: 0x%08x", |
| 28 | + esf->r29, esf->r31); |
| 29 | + } |
| 30 | +#endif /* CONFIG_EXCEPTION_DEBUG */ |
| 31 | + z_fatal_error(reason, esf); |
| 32 | + CODE_UNREACHABLE; |
| 33 | +} |
| 34 | + |
| 35 | +static char *reason_str(unsigned int reason) |
| 36 | +{ |
| 37 | + switch (reason) { |
| 38 | + case 0x2: |
| 39 | + return "Bus Error"; |
| 40 | + case 0x3: |
| 41 | + return "Data Page Fault"; |
| 42 | + case 0x4: |
| 43 | + return "Instruction Page Fault"; |
| 44 | + case 0x5: |
| 45 | + return "Tick Timer"; |
| 46 | + case 0x6: |
| 47 | + return "Alignment Exception"; |
| 48 | + case 0x7: |
| 49 | + return "Illegal Instruction"; |
| 50 | + case 0x8: |
| 51 | + return "External Interrupt"; |
| 52 | + case 0x9: |
| 53 | + return "D-TLB Miss"; |
| 54 | + case 0xA: |
| 55 | + return "I-TLB Miss"; |
| 56 | + case 0xB: |
| 57 | + return "Range Exception"; |
| 58 | + case 0xC: |
| 59 | + return "Syscall"; |
| 60 | + case 0xD: |
| 61 | + return "Floating Point Exception"; |
| 62 | + case 0xE: |
| 63 | + return "Trap"; |
| 64 | + default: |
| 65 | + return "unknown"; |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +void _Fault(struct arch_esf *esf, unsigned int reason) |
| 70 | +{ |
| 71 | + LOG_ERR(""); |
| 72 | + LOG_ERR(" reason: %d, %s", reason, reason_str(reason)); |
| 73 | + |
| 74 | + z_openrisc_fatal_error(K_ERR_CPU_EXCEPTION, esf); |
| 75 | +} |
0 commit comments