* @brief 通用异常处理辅助函数 * @param exception_msg 异常类型描述 * @param context 中断上下文 * @param print_regs 要打印的寄存器数量 (0, 4, 或 8) */
| 23 | * @param print_regs 要打印的寄存器数量 (0, 4, 或 8) |
| 24 | */ |
| 25 | auto HandleException(const char* exception_msg, cpu_io::TrapContext* context, |
| 26 | int print_regs = 0) -> void { |
| 27 | klog::Err("{}", exception_msg); |
| 28 | klog::Err( |
| 29 | " ESR_EL1: {:#X}, ELR_EL1: {:#X}, SP_EL0: {:#X}, SP_EL1: {:#X}, " |
| 30 | "SPSR_EL1: {:#X}", |
| 31 | context->esr_el1, context->elr_el1, context->sp_el0, context->sp_el1, |
| 32 | context->spsr_el1); |
| 33 | |
| 34 | if (print_regs == 4) { |
| 35 | klog::Err(" x0-x3: {:#X} {:#X} {:#X} {:#X}", context->x0, context->x1, |
| 36 | context->x2, context->x3); |
| 37 | } else if (print_regs == 8) { |
| 38 | klog::Err(" x0-x7: {:#X} {:#X} {:#X} {:#X} {:#X} {:#X} {:#X} {:#X}", |
| 39 | context->x0, context->x1, context->x2, context->x3, context->x4, |
| 40 | context->x5, context->x6, context->x7); |
| 41 | } |
| 42 | |
| 43 | while (true) { |
| 44 | cpu_io::Pause(); |
| 45 | } |
| 46 | } |
| 47 | } // namespace |
| 48 | |
| 49 | /// 异常向量表入口 |
no test coverage detected