From a470ba1999ba51d908325573d753be280673ec31 Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Wed, 7 Aug 2019 09:06:23 +0200 Subject: [PATCH] kernel: remove z_fatal_print() Use LOG_ERR instead. Signed-off-by: Andrew Boie --- arch/arc/core/fatal.c | 7 +- arch/arc/core/fault.c | 124 ++++++++++++++++----------------- arch/arm/core/cortex_m/fault.c | 5 +- arch/arm/core/fatal.c | 31 +++++---- arch/nios2/core/fatal.c | 29 ++++---- arch/nios2/core/irq_manage.c | 6 +- arch/riscv/core/fatal.c | 29 ++++---- arch/riscv/core/irq_manage.c | 8 ++- arch/x86/core/ia32/fatal.c | 72 +++++++++---------- arch/x86_64/core/x86_64.c | 17 +++-- arch/xtensa/core/fatal.c | 8 ++- arch/xtensa/core/xtensa-asm2.c | 72 +++++++++---------- include/fatal.h | 23 ------ kernel/fatal.c | 23 ++---- 14 files changed, 216 insertions(+), 238 deletions(-) diff --git a/arch/arc/core/fatal.c b/arch/arc/core/fatal.c index 8683e586525..3f5bbc67931 100644 --- a/arch/arc/core/fatal.c +++ b/arch/arc/core/fatal.c @@ -16,13 +16,14 @@ #include #include #include -#include +#include +LOG_MODULE_DECLARE(os); void z_arc_fatal_error(unsigned int reason, const z_arch_esf_t *esf) { if (reason == K_ERR_CPU_EXCEPTION) { - z_fatal_print("Faulting instruction address = 0x%lx", - z_arc_v2_aux_reg_read(_ARC_V2_ERET)); + LOG_ERR("Faulting instruction address = 0x%lx", + z_arc_v2_aux_reg_read(_ARC_V2_ERET)); } z_fatal_error(reason, esf); diff --git a/arch/arc/core/fault.c b/arch/arc/core/fault.c index c0ff451dbbf..2604e83396a 100644 --- a/arch/arc/core/fault.c +++ b/arch/arc/core/fault.c @@ -18,8 +18,8 @@ #include #include #include -#include - +#include +LOG_MODULE_DECLARE(os); #ifdef CONFIG_USERSPACE Z_EXC_DECLARE(z_arch_user_string_nlen); @@ -154,32 +154,32 @@ static void dump_protv_exception(u32_t cause, u32_t parameter) { switch (cause) { case 0x0: - z_fatal_print("Instruction fetch violation (%s)", - get_protv_access_err(parameter)); + LOG_ERR("Instruction fetch violation (%s)", + get_protv_access_err(parameter)); break; case 0x1: - z_fatal_print("Memory read protection violation (%s)", - get_protv_access_err(parameter)); + LOG_ERR("Memory read protection violation (%s)", + get_protv_access_err(parameter)); break; case 0x2: - z_fatal_print("Memory write protection violation (%s)", - get_protv_access_err(parameter)); + LOG_ERR("Memory write protection violation (%s)", + get_protv_access_err(parameter)); break; case 0x3: - z_fatal_print("Memory read-modify-write violation (%s)", - get_protv_access_err(parameter)); + LOG_ERR("Memory read-modify-write violation (%s)", + get_protv_access_err(parameter)); break; case 0x10: - z_fatal_print("Normal vector table in secure memory"); + LOG_ERR("Normal vector table in secure memory"); break; case 0x11: - z_fatal_print("NS handler code located in S memory"); + LOG_ERR("NS handler code located in S memory"); break; case 0x12: - z_fatal_print("NSC Table Range Violation"); + LOG_ERR("NSC Table Range Violation"); break; default: - z_fatal_print("unknown"); + LOG_ERR("unknown"); break; } } @@ -188,46 +188,46 @@ static void dump_machine_check_exception(u32_t cause, u32_t parameter) { switch (cause) { case 0x0: - z_fatal_print("double fault"); + LOG_ERR("double fault"); break; case 0x1: - z_fatal_print("overlapping TLB entries"); + LOG_ERR("overlapping TLB entries"); break; case 0x2: - z_fatal_print("fatal TLB error"); + LOG_ERR("fatal TLB error"); break; case 0x3: - z_fatal_print("fatal cache error"); + LOG_ERR("fatal cache error"); break; case 0x4: - z_fatal_print("internal memory error on instruction fetch"); + LOG_ERR("internal memory error on instruction fetch"); break; case 0x5: - z_fatal_print("internal memory error on data fetch"); + LOG_ERR("internal memory error on data fetch"); break; case 0x6: - z_fatal_print("illegal overlapping MPU entries"); + LOG_ERR("illegal overlapping MPU entries"); if (parameter == 0x1) { - z_fatal_print(" - jump and branch target"); + LOG_ERR(" - jump and branch target"); } break; case 0x10: - z_fatal_print("secure vector table not located in secure memory"); + LOG_ERR("secure vector table not located in secure memory"); break; case 0x11: - z_fatal_print("NSC jump table not located in secure memory"); + LOG_ERR("NSC jump table not located in secure memory"); break; case 0x12: - z_fatal_print("secure handler code not located in secure memory"); + LOG_ERR("secure handler code not located in secure memory"); break; case 0x13: - z_fatal_print("NSC target address not located in secure memory"); + LOG_ERR("NSC target address not located in secure memory"); break; case 0x80: - z_fatal_print("uncorrectable ECC or parity error in vector memory"); + LOG_ERR("uncorrectable ECC or parity error in vector memory"); break; default: - z_fatal_print("unknown"); + LOG_ERR("unknown"); break; } } @@ -236,54 +236,54 @@ static void dump_privilege_exception(u32_t cause, u32_t parameter) { switch (cause) { case 0x0: - z_fatal_print("Privilege violation"); + LOG_ERR("Privilege violation"); break; case 0x1: - z_fatal_print("disabled extension"); + LOG_ERR("disabled extension"); break; case 0x2: - z_fatal_print("action point hit"); + LOG_ERR("action point hit"); break; case 0x10: switch (parameter) { case 0x1: - z_fatal_print("N to S return using incorrect return mechanism"); + LOG_ERR("N to S return using incorrect return mechanism"); break; case 0x2: - z_fatal_print("N to S return with incorrect operating mode"); + LOG_ERR("N to S return with incorrect operating mode"); break; case 0x3: - z_fatal_print("IRQ/exception return fetch from wrong mode"); + LOG_ERR("IRQ/exception return fetch from wrong mode"); break; case 0x4: - z_fatal_print("attempt to halt secure processor in NS mode"); + LOG_ERR("attempt to halt secure processor in NS mode"); break; case 0x20: - z_fatal_print("attempt to access secure resource from normal mode"); + LOG_ERR("attempt to access secure resource from normal mode"); break; case 0x40: - z_fatal_print("SID violation on resource access (APEX/UAUX/key NVM)"); + LOG_ERR("SID violation on resource access (APEX/UAUX/key NVM)"); break; default: - z_fatal_print("unknown"); + LOG_ERR("unknown"); break; } break; case 0x13: switch (parameter) { case 0x20: - z_fatal_print("attempt to access secure APEX feature from NS mode"); + LOG_ERR("attempt to access secure APEX feature from NS mode"); break; case 0x40: - z_fatal_print("SID violation on access to APEX feature"); + LOG_ERR("SID violation on access to APEX feature"); break; default: - z_fatal_print("unknown"); + LOG_ERR("unknown"); break; } break; default: - z_fatal_print("unknown"); + LOG_ERR("unknown"); break; } } @@ -291,7 +291,7 @@ static void dump_privilege_exception(u32_t cause, u32_t parameter) static void dump_exception_info(u32_t vector, u32_t cause, u32_t parameter) { if (vector >= 0x10 && vector <= 0xFF) { - z_fatal_print("interrupt %u", vector); + LOG_ERR("interrupt %u", vector); return; } @@ -300,55 +300,55 @@ static void dump_exception_info(u32_t vector, u32_t cause, u32_t parameter) */ switch (vector) { case ARC_EV_RESET: - z_fatal_print("Reset"); + LOG_ERR("Reset"); break; case ARC_EV_MEM_ERROR: - z_fatal_print("Memory Error"); + LOG_ERR("Memory Error"); break; case ARC_EV_INS_ERROR: - z_fatal_print("Instruction Error"); + LOG_ERR("Instruction Error"); break; case ARC_EV_MACHINE_CHECK: - z_fatal_print("EV_MachineCheck"); + LOG_ERR("EV_MachineCheck"); dump_machine_check_exception(cause, parameter); break; case ARC_EV_TLB_MISS_I: - z_fatal_print("EV_TLBMissI"); + LOG_ERR("EV_TLBMissI"); break; case ARC_EV_TLB_MISS_D: - z_fatal_print("EV_TLBMissD"); + LOG_ERR("EV_TLBMissD"); break; case ARC_EV_PROT_V: - z_fatal_print("EV_ProtV"); + LOG_ERR("EV_ProtV"); dump_protv_exception(cause, parameter); break; case ARC_EV_PRIVILEGE_V: - z_fatal_print("EV_PrivilegeV"); + LOG_ERR("EV_PrivilegeV"); dump_privilege_exception(cause, parameter); break; case ARC_EV_SWI: - z_fatal_print("EV_SWI"); + LOG_ERR("EV_SWI"); break; case ARC_EV_TRAP: - z_fatal_print("EV_Trap"); + LOG_ERR("EV_Trap"); break; case ARC_EV_EXTENSION: - z_fatal_print("EV_Extension"); + LOG_ERR("EV_Extension"); break; case ARC_EV_DIV_ZERO: - z_fatal_print("EV_DivZero"); + LOG_ERR("EV_DivZero"); break; case ARC_EV_DC_ERROR: - z_fatal_print("EV_DCError"); + LOG_ERR("EV_DCError"); break; case ARC_EV_MISALIGNED: - z_fatal_print("EV_Misaligned"); + LOG_ERR("EV_Misaligned"); break; case ARC_EV_VEC_UNIT: - z_fatal_print("EV_VecUnit"); + LOG_ERR("EV_VecUnit"); break; default: - z_fatal_print("unknown"); + LOG_ERR("unknown"); break; } } @@ -401,9 +401,9 @@ void _Fault(z_arch_esf_t *esf, u32_t old_sp) return; } - z_fatal_print("***** Exception vector: 0x%x, cause code: 0x%x, parameter 0x%x", - vector, cause, parameter); - z_fatal_print("Address 0x%x", exc_addr); + LOG_ERR("***** Exception vector: 0x%x, cause code: 0x%x, parameter 0x%x", + vector, cause, parameter); + LOG_ERR("Address 0x%x", exc_addr); #ifdef CONFIG_ARC_EXCEPTION_DEBUG dump_exception_info(vector, cause, parameter); #endif diff --git a/arch/arm/core/cortex_m/fault.c b/arch/arm/core/cortex_m/fault.c index 7943248368e..99a8f86d7cb 100644 --- a/arch/arm/core/cortex_m/fault.c +++ b/arch/arm/core/cortex_m/fault.c @@ -18,10 +18,11 @@ #include #include #include -#include +#include +LOG_MODULE_DECLARE(os); #if defined(CONFIG_PRINTK) || defined(CONFIG_LOG) -#define PR_EXC(...) z_fatal_print(__VA_ARGS__) +#define PR_EXC(...) LOG_ERR(__VA_ARGS__) #define STORE_xFAR(reg_var, reg) u32_t reg_var = (u32_t)reg #else #define PR_EXC(...) diff --git a/arch/arm/core/fatal.c b/arch/arm/core/fatal.c index d12dc1c648f..fa89f390d81 100644 --- a/arch/arm/core/fatal.c +++ b/arch/arm/core/fatal.c @@ -17,28 +17,29 @@ #include #include -#include +#include +LOG_MODULE_DECLARE(os); static void esf_dump(const z_arch_esf_t *esf) { - z_fatal_print("r0/a1: 0x%08x r1/a2: 0x%08x r2/a3: 0x%08x", - esf->basic.a1, esf->basic.a2, esf->basic.a3); - z_fatal_print("r3/a4: 0x%08x r12/ip: 0x%08x r14/lr: 0x%08x", - esf->basic.a4, esf->basic.ip, esf->basic.lr); - z_fatal_print(" xpsr: 0x%08x", esf->basic.xpsr); + LOG_ERR("r0/a1: 0x%08x r1/a2: 0x%08x r2/a3: 0x%08x", + esf->basic.a1, esf->basic.a2, esf->basic.a3); + LOG_ERR("r3/a4: 0x%08x r12/ip: 0x%08x r14/lr: 0x%08x", + esf->basic.a4, esf->basic.ip, esf->basic.lr); + LOG_ERR(" xpsr: 0x%08x", esf->basic.xpsr); #if defined(CONFIG_FLOAT) && defined(CONFIG_FP_SHARING) for (int i = 0; i < 16; i += 4) { - z_fatal_print("s[%d]: 0x%08x s[%d]: 0x%08x" - " s[%d]: 0x%08x s[%d]: 0x%08x\n", - i, (u32_t)esf->s[i], - i + 1, (u32_t)esf->s[i + 1], - i + 2, (u32_t)esf->s[i + 2], - i + 3, (u32_t)esf->s[i + 3]); + LOG_ERR("s[%d]: 0x%08x s[%d]: 0x%08x" + " s[%d]: 0x%08x s[%d]: 0x%08x\n", + i, (u32_t)esf->s[i], + i + 1, (u32_t)esf->s[i + 1], + i + 2, (u32_t)esf->s[i + 2], + i + 3, (u32_t)esf->s[i + 3]); } - z_fatal_print("fpscr: 0x%08x\n", esf->fpscr); + LOG_ERR("fpscr: 0x%08x\n", esf->fpscr); #endif - z_fatal_print("Faulting instruction address (r15/pc): 0x%08x", - esf->basic.pc); + LOG_ERR("Faulting instruction address (r15/pc): 0x%08x", + esf->basic.pc); } void z_arm_fatal_error(unsigned int reason, const z_arch_esf_t *esf) diff --git a/arch/nios2/core/fatal.c b/arch/nios2/core/fatal.c index 2a9cf2b22e6..6438a4f2278 100644 --- a/arch/nios2/core/fatal.c +++ b/arch/nios2/core/fatal.c @@ -8,7 +8,8 @@ #include #include #include -#include +#include +LOG_MODULE_DECLARE(os); FUNC_NORETURN void z_nios2_fatal_error(unsigned int reason, const z_arch_esf_t *esf) @@ -21,16 +22,16 @@ FUNC_NORETURN void z_nios2_fatal_error(unsigned int reason, * entry. We may want to introduce a config option to save and * dump all registers, at the expense of some stack space. */ - z_fatal_print("Faulting instruction: 0x%08x", esf->instr - 4); - z_fatal_print(" r1: 0x%08x r2: 0x%08x r3: 0x%08x r4: 0x%08x", - esf->r1, esf->r2, esf->r3, esf->r4); - z_fatal_print(" r5: 0x%08x r6: 0x%08x r7: 0x%08x r8: 0x%08x", - esf->r5, esf->r6, esf->r7, esf->r8); - z_fatal_print(" r9: 0x%08x r10: 0x%08x r11: 0x%08x r12: 0x%08x", - esf->r9, esf->r10, esf->r11, esf->r12); - z_fatal_print(" r13: 0x%08x r14: 0x%08x r15: 0x%08x ra: 0x%08x", - esf->r13, esf->r14, esf->r15, esf->ra); - z_fatal_print("estatus: %08x", esf->estatus); + LOG_ERR("Faulting instruction: 0x%08x", esf->instr - 4); + LOG_ERR(" r1: 0x%08x r2: 0x%08x r3: 0x%08x r4: 0x%08x", + esf->r1, esf->r2, esf->r3, esf->r4); + LOG_ERR(" r5: 0x%08x r6: 0x%08x r7: 0x%08x r8: 0x%08x", + esf->r5, esf->r6, esf->r7, esf->r8); + LOG_ERR(" r9: 0x%08x r10: 0x%08x r11: 0x%08x r12: 0x%08x", + esf->r9, esf->r10, esf->r11, esf->r12); + LOG_ERR(" r13: 0x%08x r14: 0x%08x r15: 0x%08x ra: 0x%08x", + esf->r13, esf->r14, esf->r15, esf->ra); + LOG_ERR("estatus: %08x", esf->estatus); } z_fatal_error(reason, esf); @@ -116,13 +117,13 @@ FUNC_NORETURN void _Fault(const z_arch_esf_t *esf) cause = (exc_reg & NIOS2_EXCEPTION_REG_CAUSE_MASK) >> NIOS2_EXCEPTION_REG_CAUSE_OFST; - z_fatal_print("Exception cause: %d ECCFTL: 0x%x", cause, eccftl); + LOG_ERR("Exception cause: %d ECCFTL: 0x%x", cause, eccftl); #if CONFIG_EXTRA_EXCEPTION_INFO - z_fatal_print("reason: %s", cause_str(cause)); + LOG_ERR("reason: %s", cause_str(cause)); #endif if (BIT(cause) & NIOS2_BADADDR_CAUSE_MASK) { badaddr_reg = z_nios2_creg_read(NIOS2_CR_BADADDR); - z_fatal_print("Badaddr: 0x%x", badaddr_reg); + LOG_ERR("Badaddr: 0x%x", badaddr_reg); } #endif /* ALT_CPU_HAS_EXTRA_EXCEPTION_INFO */ #endif /* CONFIG_PRINTK || CONFIG_LOG */ diff --git a/arch/nios2/core/irq_manage.c b/arch/nios2/core/irq_manage.c index da457a67b12..d15cdd60ea5 100644 --- a/arch/nios2/core/irq_manage.c +++ b/arch/nios2/core/irq_manage.c @@ -19,12 +19,14 @@ #include #include #include +#include +LOG_MODULE_DECLARE(os); FUNC_NORETURN void z_irq_spurious(void *unused) { ARG_UNUSED(unused); - z_fatal_print("Spurious interrupt detected! ipending: %x", - z_nios2_creg_read(NIOS2_CR_IPENDING)); + LOG_ERR("Spurious interrupt detected! ipending: %x", + z_nios2_creg_read(NIOS2_CR_IPENDING)); z_nios2_fatal_error(K_ERR_SPURIOUS_IRQ, NULL); } diff --git a/arch/riscv/core/fatal.c b/arch/riscv/core/fatal.c index 572ffbb5783..2380f22fa29 100644 --- a/arch/riscv/core/fatal.c +++ b/arch/riscv/core/fatal.c @@ -7,24 +7,25 @@ #include #include #include -#include +#include +LOG_MODULE_DECLARE(os); FUNC_NORETURN void z_riscv_fatal_error(unsigned int reason, const z_arch_esf_t *esf) { if (esf != NULL) { - z_fatal_print("Faulting instruction address = 0x%08lx", - esf->mepc); - z_fatal_print(" ra: 0x%08lx gp: 0x%08lx tp: 0x%08lx t0: 0x%08lx", - esf->ra, esf->gp, esf->tp, esf->t0); - z_fatal_print(" t1: 0x%08lx t2: 0x%08lx t3: 0x%08lx t4: 0x%08lx", - esf->t1, esf->t2, esf->t3, esf->t4); - z_fatal_print(" t5: 0x%08lx t6: 0x%08lx a0: 0x%08lx a1: 0x%08lx", - esf->t5, esf->t6, esf->a0, esf->a1); - z_fatal_print(" a2: 0x%08lx a3: 0x%08lx a4: 0x%08lx a5: 0x%08lx", - esf->a2, esf->a3, esf->a4, esf->a5); - z_fatal_print(" a6: 0x%08lx a7: 0x%08lx\n", - esf->a6, esf->a7); + LOG_ERR("Faulting instruction address = 0x%08lx", + esf->mepc); + LOG_ERR(" ra: 0x%08lx gp: 0x%08lx tp: 0x%08lx t0: 0x%08lx", + esf->ra, esf->gp, esf->tp, esf->t0); + LOG_ERR(" t1: 0x%08lx t2: 0x%08lx t3: 0x%08lx t4: 0x%08lx", + esf->t1, esf->t2, esf->t3, esf->t4); + LOG_ERR(" t5: 0x%08lx t6: 0x%08lx a0: 0x%08lx a1: 0x%08lx", + esf->t5, esf->t6, esf->a0, esf->a1); + LOG_ERR(" a2: 0x%08lx a3: 0x%08lx a4: 0x%08lx a5: 0x%08lx", + esf->a2, esf->a3, esf->a4, esf->a5); + LOG_ERR(" a6: 0x%08lx a7: 0x%08lx\n", + esf->a6, esf->a7); } z_fatal_error(reason, esf); @@ -58,7 +59,7 @@ FUNC_NORETURN void _Fault(const z_arch_esf_t *esf) __asm__ volatile("csrr %0, mcause" : "=r" (mcause)); mcause &= SOC_MCAUSE_EXP_MASK; - z_fatal_print("Exception cause %s (%ld)", cause_str(mcause), mcause); + LOG_ERR("Exception cause %s (%ld)", cause_str(mcause), mcause); z_riscv_fatal_error(K_ERR_CPU_EXCEPTION, esf); } diff --git a/arch/riscv/core/irq_manage.c b/arch/riscv/core/irq_manage.c index 8c94362d960..38fb46579ad 100644 --- a/arch/riscv/core/irq_manage.c +++ b/arch/riscv/core/irq_manage.c @@ -6,6 +6,8 @@ #include #include +#include +LOG_MODULE_DECLARE(os); FUNC_NORETURN void z_irq_spurious(void *unused) { @@ -17,11 +19,11 @@ FUNC_NORETURN void z_irq_spurious(void *unused) mcause &= SOC_MCAUSE_EXP_MASK; - z_fatal_print("Spurious interrupt detected! IRQ: %ld", mcause); + LOG_ERR("Spurious interrupt detected! IRQ: %ld", mcause); #if defined(CONFIG_RISCV_HAS_PLIC) if (mcause == RISCV_MACHINE_EXT_IRQ) { - z_fatal_print("PLIC interrupt line causing the IRQ: %d", - riscv_plic_get_irq()); + LOG_ERR("PLIC interrupt line causing the IRQ: %d", + riscv_plic_get_irq()); } #endif z_riscv_fatal_error(K_ERR_SPURIOUS_IRQ, NULL); diff --git a/arch/x86/core/ia32/fatal.c b/arch/x86/core/ia32/fatal.c index a4cbda2f387..b703d91a82d 100644 --- a/arch/x86/core/ia32/fatal.c +++ b/arch/x86/core/ia32/fatal.c @@ -19,7 +19,8 @@ #include #include #include -#include +#include +LOG_MODULE_DECLARE(os); __weak void z_debug_fatal_hook(const z_arch_esf_t *esf) { ARG_UNUSED(esf); } @@ -77,13 +78,13 @@ static void unwind_stack(u32_t base_ptr, u16_t cs) int i; if (base_ptr == 0U) { - z_fatal_print("NULL base ptr"); + LOG_ERR("NULL base ptr"); return; } for (i = 0; i < MAX_STACK_FRAMES; i++) { if (base_ptr % sizeof(base_ptr) != 0U) { - z_fatal_print("unaligned frame ptr"); + LOG_ERR("unaligned frame ptr"); return; } @@ -97,7 +98,7 @@ static void unwind_stack(u32_t base_ptr, u16_t cs) * stack buffer */ if (check_stack_bounds((u32_t)frame, sizeof(*frame), cs)) { - z_fatal_print(" corrupted? (bp=%p)", frame); + LOG_ERR(" corrupted? (bp=%p)", frame); break; } #endif @@ -105,8 +106,7 @@ static void unwind_stack(u32_t base_ptr, u16_t cs) if (frame->ret_addr == 0U) { break; } - z_fatal_print(" 0x%08x (0x%x)", frame->ret_addr, - frame->args); + LOG_ERR(" 0x%08x (0x%x)", frame->ret_addr, frame->args); base_ptr = frame->next; } } @@ -128,17 +128,17 @@ FUNC_NORETURN void z_arch_system_halt(unsigned int reason) FUNC_NORETURN void z_x86_fatal_error(unsigned int reason, const z_arch_esf_t *esf) { if (esf != NULL) { - z_fatal_print("eax: 0x%08x, ebx: 0x%08x, ecx: 0x%08x, edx: 0x%08x", - esf->eax, esf->ebx, esf->ecx, esf->edx); - z_fatal_print("esi: 0x%08x, edi: 0x%08x, ebp: 0x%08x, esp: 0x%08x", - esf->esi, esf->edi, esf->ebp, esf->esp); - z_fatal_print("eflags: 0x%08x cs: 0x%04x cr3: %p", esf->eflags, - esf->cs & 0xFFFFU, z_x86_page_tables_get()); + LOG_ERR("eax: 0x%08x, ebx: 0x%08x, ecx: 0x%08x, edx: 0x%08x", + esf->eax, esf->ebx, esf->ecx, esf->edx); + LOG_ERR("esi: 0x%08x, edi: 0x%08x, ebp: 0x%08x, esp: 0x%08x", + esf->esi, esf->edi, esf->ebp, esf->esp); + LOG_ERR("eflags: 0x%08x cs: 0x%04x cr3: %p", esf->eflags, + esf->cs & 0xFFFFU, z_x86_page_tables_get()); #ifdef CONFIG_EXCEPTION_STACK_TRACE - z_fatal_print("call trace:"); + LOG_ERR("call trace:"); #endif - z_fatal_print("eip: 0x%08x", esf->eip); + LOG_ERR("eip: 0x%08x", esf->eip); #ifdef CONFIG_EXCEPTION_STACK_TRACE unwind_stack(esf->ebp, esf->cs); #endif @@ -153,7 +153,7 @@ void z_x86_spurious_irq(const z_arch_esf_t *esf) int vector = z_irq_controller_isr_vector_get(); if (vector >= 0) { - z_fatal_print("IRQ vector: %d", vector); + LOG_ERR("IRQ vector: %d", vector); } z_x86_fatal_error(K_ERR_SPURIOUS_IRQ, esf); @@ -208,17 +208,17 @@ FUNC_NORETURN static void generic_exc_handle(unsigned int vector, { switch (vector) { case IV_GENERAL_PROTECTION: - z_fatal_print("General Protection Fault"); + LOG_ERR("General Protection Fault"); break; case IV_DEVICE_NOT_AVAILABLE: - z_fatal_print("Floating point unit not enabled"); + LOG_ERR("Floating point unit not enabled"); break; default: - z_fatal_print("CPU exception %d", vector); + LOG_ERR("CPU exception %d", vector); break; } if ((BIT(vector) & _EXC_ERROR_CODE_FAULTS) != 0) { - z_fatal_print("Exception code: 0x%x", pEsf->errorCode); + LOG_ERR("Exception code: 0x%x", pEsf->errorCode); } z_x86_fatal_error(K_ERR_CPU_EXCEPTION, pEsf); } @@ -275,16 +275,16 @@ EXC_FUNC_NOCODE(IV_MACHINE_CHECK); #ifdef CONFIG_X86_MMU static void dump_entry_flags(const char *name, x86_page_entry_data_t flags) { - z_fatal_print("%s: 0x%x%x %s, %s, %s, %s", name, (u32_t)(flags>>32), - (u32_t)(flags), - flags & (x86_page_entry_data_t)MMU_ENTRY_PRESENT ? - "Present" : "Non-present", - flags & (x86_page_entry_data_t)MMU_ENTRY_WRITE ? - "Writable" : "Read-only", - flags & (x86_page_entry_data_t)MMU_ENTRY_USER ? - "User" : "Supervisor", - flags & (x86_page_entry_data_t)MMU_ENTRY_EXECUTE_DISABLE ? - "Execute Disable" : "Execute Enabled"); + LOG_ERR("%s: 0x%x%x %s, %s, %s, %s", name, (u32_t)(flags>>32), + (u32_t)(flags), + flags & (x86_page_entry_data_t)MMU_ENTRY_PRESENT ? + "Present" : "Non-present", + flags & (x86_page_entry_data_t)MMU_ENTRY_WRITE ? + "Writable" : "Read-only", + flags & (x86_page_entry_data_t)MMU_ENTRY_USER ? + "User" : "Supervisor", + flags & (x86_page_entry_data_t)MMU_ENTRY_EXECUTE_DISABLE ? + "Execute Disable" : "Execute Enabled"); } static void dump_mmu_flags(struct x86_mmu_pdpt *pdpt, void *addr) @@ -306,13 +306,13 @@ static void dump_page_fault(z_arch_esf_t *esf) __asm__ ("mov %%cr2, %0" : "=r" (cr2)); err = esf->errorCode; - z_fatal_print("***** CPU Page Fault (error code 0x%08x)", err); + LOG_ERR("***** CPU Page Fault (error code 0x%08x)", err); - z_fatal_print("%s thread %s address 0x%08x", - (err & US) != 0U ? "User" : "Supervisor", - (err & ID) != 0U ? "executed" : ((err & WR) != 0U ? - "wrote" : - "read"), cr2); + LOG_ERR("%s thread %s address 0x%08x", + (err & US) != 0U ? "User" : "Supervisor", + (err & ID) != 0U ? "executed" : ((err & WR) != 0U ? + "wrote" : + "read"), cr2); #ifdef CONFIG_X86_MMU #ifdef CONFIG_X86_KPTI @@ -408,7 +408,7 @@ static __used void df_handler_bottom(void) _df_tss.esp = (u32_t)(_df_stack + sizeof(_df_stack)); _df_tss.eip = (u32_t)df_handler_top; - z_fatal_print("Double Fault"); + LOG_ERR("Double Fault"); #ifdef CONFIG_THREAD_STACK_INFO if (check_stack_bounds(_df_esf.esp, 0, _df_esf.cs)) { reason = K_ERR_STACK_CHK_FAIL; diff --git a/arch/x86_64/core/x86_64.c b/arch/x86_64/core/x86_64.c index 41cb8074b48..c44f606961e 100644 --- a/arch/x86_64/core/x86_64.c +++ b/arch/x86_64/core/x86_64.c @@ -8,8 +8,11 @@ #include #include #include +#include #include "xuk.h" +LOG_MODULE_DECLARE(os); + /* Always pick a lowest priority interrupt for scheduling IPI's, by * definition they're done on behalf of thread mode code and should * never preempt a true device interrupt @@ -51,13 +54,13 @@ void z_unhandled_vector(int vector, int err, struct xuk_entry_frame *f) /* Yes, there are five regsiters missing. See notes on * xuk_entry_frame/xuk_stack_frame. */ - z_fatal_print("*** FATAL ERROR vector %d code %d", vector, err); - z_fatal_print("*** RIP %d:0x%llx RSP %d:0x%llx RFLAGS 0x%llx", - (int)f->cs, f->rip, (int)f->ss, f->rsp, f->rflags); - z_fatal_print("*** RAX 0x%llx RCX 0x%llx RDX 0x%llx RSI 0x%llx RDI 0x%llx", - f->rax, f->rcx, f->rdx, f->rsi, f->rdi); - z_fatal_print("*** R8 0x%llx R9 0x%llx R10 0x%llx R11 0x%llx", - f->r8, f->r9, f->r10, f->r11); + LOG_ERR("*** FATAL ERROR vector %d code %d", vector, err); + LOG_ERR("*** RIP %d:0x%llx RSP %d:0x%llx RFLAGS 0x%llx", + (int)f->cs, f->rip, (int)f->ss, f->rsp, f->rflags); + LOG_ERR("*** RAX 0x%llx RCX 0x%llx RDX 0x%llx RSI 0x%llx RDI 0x%llx", + f->rax, f->rcx, f->rdx, f->rsi, f->rdi); + LOG_ERR("*** R8 0x%llx R9 0x%llx R10 0x%llx R11 0x%llx", + f->r8, f->r9, f->r10, f->r11); /* FIXME: Why isn't xuk_entry_frame a z_arch_esf_t? */ z_fatal_error(x86_64_except_reason, NULL); diff --git a/arch/xtensa/core/fatal.c b/arch/xtensa/core/fatal.c index 545df90c958..883a06c0ceb 100644 --- a/arch/xtensa/core/fatal.c +++ b/arch/xtensa/core/fatal.c @@ -10,6 +10,8 @@ #include #include #include +#include +LOG_MODULE_DECLARE(os); #ifdef XT_SIMULATOR #include @@ -101,8 +103,8 @@ XTENSA_ERR_NORET void FatalErrorHandler(void) XTENSA_ERR_NORET void ReservedInterruptHandler(unsigned int intNo) { - z_fatal_print("INTENABLE = 0x%x INTERRUPT = 0x%x (%x)", - get_sreg(INTENABLE), (1 << intNo), intNo); + LOG_ERR("INTENABLE = 0x%x INTERRUPT = 0x%x (%x)", + get_sreg(INTENABLE), (1 << intNo), intNo); z_xtensa_fatal_error(K_ERR_SPURIOUS_IRQ, NULL); } @@ -117,7 +119,7 @@ void exit(int return_code) : [code] "r" (return_code), [call] "i" (SYS_exit) : "a3", "a2"); #else - z_fatal_print("exit(%d)", return_code); + LOG_ERR("exit(%d)", return_code); k_panic(); #endif } diff --git a/arch/xtensa/core/xtensa-asm2.c b/arch/xtensa/core/xtensa-asm2.c index c0c60862083..17a0f131043 100644 --- a/arch/xtensa/core/xtensa-asm2.c +++ b/arch/xtensa/core/xtensa-asm2.c @@ -11,6 +11,9 @@ #include #include #include <_soc_inthandlers.h> +#include + +LOG_MODULE_DECLARE(os); void *xtensa_init_stack(int *stack_top, void (*entry)(void *, void *, void *), @@ -77,8 +80,8 @@ void z_irq_spurious(void *arg) __asm__ volatile("rsr.interrupt %0" : "=r"(irqs)); __asm__ volatile("rsr.intenable %0" : "=r"(ie)); - z_fatal_print(" ** Spurious INTERRUPT(s) %p, INTENABLE = %p", - (void *)irqs, (void *)ie); + LOG_ERR(" ** Spurious INTERRUPT(s) %p, INTENABLE = %p", + (void *)irqs, (void *)ie); z_xtensa_fatal_error(K_ERR_SPURIOUS_IRQ, NULL); } @@ -86,38 +89,37 @@ void z_xtensa_dump_stack(const z_arch_esf_t *stack) { int *bsa = *(int **)stack; - z_fatal_print(" ** A0 %p SP %p A2 %p A3 %p", - (void *)bsa[BSA_A0_OFF/4], - ((char *)bsa) + BASE_SAVE_AREA_SIZE, - (void *)bsa[BSA_A2_OFF/4], (void *)bsa[BSA_A3_OFF/4]); + LOG_ERR(" ** A0 %p SP %p A2 %p A3 %p", + (void *)bsa[BSA_A0_OFF/4], + ((char *)bsa) + BASE_SAVE_AREA_SIZE, + (void *)bsa[BSA_A2_OFF/4], (void *)bsa[BSA_A3_OFF/4]); if (bsa - stack > 4) { - z_fatal_print(" ** A4 %p A5 %p A6 %p A7 %p", - (void *)bsa[-4], (void *)bsa[-3], - (void *)bsa[-2], (void *)bsa[-1]); + LOG_ERR(" ** A4 %p A5 %p A6 %p A7 %p", + (void *)bsa[-4], (void *)bsa[-3], + (void *)bsa[-2], (void *)bsa[-1]); } if (bsa - stack > 8) { - z_fatal_print(" ** A8 %p A9 %p A10 %p A11 %p", - (void *)bsa[-8], (void *)bsa[-7], - (void *)bsa[-6], (void *)bsa[-5]); + LOG_ERR(" ** A8 %p A9 %p A10 %p A11 %p", + (void *)bsa[-8], (void *)bsa[-7], + (void *)bsa[-6], (void *)bsa[-5]); } if (bsa - stack > 12) { - z_fatal_print(" ** A12 %p A13 %p A14 %p A15 %p", - (void *)bsa[-12], (void *)bsa[-11], - (void *)bsa[-10], (void *)bsa[-9]); + LOG_ERR(" ** A12 %p A13 %p A14 %p A15 %p", + (void *)bsa[-12], (void *)bsa[-11], + (void *)bsa[-10], (void *)bsa[-9]); } #if XCHAL_HAVE_LOOPS - z_fatal_print(" ** LBEG %p LEND %p LCOUNT %p", - (void *)bsa[BSA_LBEG_OFF/4], - (void *)bsa[BSA_LEND_OFF/4], - (void *)bsa[BSA_LCOUNT_OFF/4]); - + LOG_ERR(" ** LBEG %p LEND %p LCOUNT %p", + (void *)bsa[BSA_LBEG_OFF/4], + (void *)bsa[BSA_LEND_OFF/4], + (void *)bsa[BSA_LCOUNT_OFF/4]); #endif - z_fatal_print(" ** SAR %p", (void *)bsa[BSA_SAR_OFF/4]); + LOG_ERR(" ** SAR %p", (void *)bsa[BSA_SAR_OFF/4]); } static inline unsigned int get_bits(int offset, int num_bits, unsigned int val) @@ -174,8 +176,8 @@ void *xtensa_excint1_c(int *interrupted_stack) } else if (cause == EXCCAUSE_SYSCALL) { /* Just report it to the console for now */ - z_fatal_print(" ** SYSCALL PS %p PC %p", - (void *)bsa[BSA_PS_OFF/4], (void *)bsa[BSA_PC_OFF/4]); + LOG_ERR(" ** SYSCALL PS %p PC %p", + (void *)bsa[BSA_PS_OFF/4], (void *)bsa[BSA_PC_OFF/4]); z_xtensa_dump_stack(interrupted_stack); /* Xtensa exceptions don't automatically advance PC, @@ -189,18 +191,18 @@ void *xtensa_excint1_c(int *interrupted_stack) __asm__ volatile("rsr.excvaddr %0" : "=r"(vaddr)); - z_fatal_print(" ** FATAL EXCEPTION"); - z_fatal_print(" ** CPU %d EXCCAUSE %d (%s)", - z_arch_curr_cpu()->id, cause, - z_xtensa_exccause(cause)); - z_fatal_print(" ** PC %p VADDR %p", - (void *)bsa[BSA_PC_OFF/4], (void *)vaddr); - z_fatal_print(" ** PS %p", (void *)bsa[BSA_PS_OFF/4]); - z_fatal_print(" ** (INTLEVEL:%d EXCM: %d UM:%d RING:%d WOE:%d OWB:%d CALLINC:%d)", - get_bits(0, 4, ps), get_bits(4, 1, ps), - get_bits(5, 1, ps), get_bits(6, 2, ps), - get_bits(18, 1, ps), - get_bits(8, 4, ps), get_bits(16, 2, ps)); + LOG_ERR(" ** FATAL EXCEPTION"); + LOG_ERR(" ** CPU %d EXCCAUSE %d (%s)", + z_arch_curr_cpu()->id, cause, + z_xtensa_exccause(cause)); + LOG_ERR(" ** PC %p VADDR %p", + (void *)bsa[BSA_PC_OFF/4], (void *)vaddr); + LOG_ERR(" ** PS %p", (void *)bsa[BSA_PS_OFF/4]); + LOG_ERR(" ** (INTLEVEL:%d EXCM: %d UM:%d RING:%d WOE:%d OWB:%d CALLINC:%d)", + get_bits(0, 4, ps), get_bits(4, 1, ps), + get_bits(5, 1, ps), get_bits(6, 2, ps), + get_bits(18, 1, ps), + get_bits(8, 4, ps), get_bits(16, 2, ps)); /* FIXME: legacy xtensa port reported "HW" exception * for all unhandled exceptions, which seems incorrect diff --git a/include/fatal.h b/include/fatal.h index 35bc71c10bb..bf3ddfd9fa7 100644 --- a/include/fatal.h +++ b/include/fatal.h @@ -88,27 +88,4 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *esf); */ void z_fatal_error(unsigned int reason, const z_arch_esf_t *esf); -/** - * Print messages related to an exception - * - * This ensures the following: - * - The log system will enter panic mode if it is not already - * - Messages will be sent to printk() or the log subsystem if it is enabled - * - * Log subsystem filtering is disabled. - * To conform with log subsystem semantics, newlines are automatically - * appended, invoke this once per line. - * - * @param fmt Format string - * @param ... Optional list of format arguments - * - * FIXME: Implemented in C file to avoid #include loops, disentangle and - * make this a macro - */ -#if defined(CONFIG_LOG) || defined(CONFIG_PRINTK) -__printf_like(1, 2) void z_fatal_print(const char *fmt, ...); -#else -#define z_fatal_print(...) do { } while (false) -#endif - #endif /* ZEPHYR_INCLUDE_FATAL_H */ diff --git a/kernel/fatal.c b/kernel/fatal.c index 4324bf5ded7..e4fec53f20b 100644 --- a/kernel/fatal.c +++ b/kernel/fatal.c @@ -38,13 +38,12 @@ __weak void k_sys_fatal_error_handler(unsigned int reason, ARG_UNUSED(esf); LOG_PANIC(); - z_fatal_print("Halting system"); + LOG_ERR("Halting system"); z_arch_system_halt(reason); CODE_UNREACHABLE; } /* LCOV_EXCL_STOP */ -#if defined(CONFIG_LOG) || defined(CONFIG_PRINTK) static const char *thread_name_get(struct k_thread *thread) { const char *thread_name = k_thread_name_get(thread); @@ -74,18 +73,6 @@ static const char *reason_to_str(unsigned int reason) } } -void z_fatal_print(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - printk("FATAL: "); - vprintk(fmt, ap); - printk("\n"); - va_end(ap); -} -#endif /* CONFIG_LOG || CONFIG_PRINTK */ - /* LCOV_EXCL_START */ FUNC_NORETURN void k_fatal_halt(unsigned int reason) { @@ -93,7 +80,6 @@ FUNC_NORETURN void k_fatal_halt(unsigned int reason) } /* LCOV_EXCL_STOP */ - void z_fatal_error(unsigned int reason, const z_arch_esf_t *esf) { struct k_thread *thread = k_current_get(); @@ -101,8 +87,7 @@ void z_fatal_error(unsigned int reason, const z_arch_esf_t *esf) /* sanitycheck looks for the "ZEPHYR FATAL ERROR" string, don't * change it without also updating sanitycheck */ - z_fatal_print(">>> ZEPHYR FATAL ERROR %d: %s", reason, - reason_to_str(reason)); + LOG_ERR(">>> ZEPHYR FATAL ERROR %d: %s", reason, reason_to_str(reason)); /* FIXME: This doesn't seem to work as expected on all arches. * Need a reliable way to determine whether the fault happened when @@ -115,8 +100,8 @@ void z_fatal_error(unsigned int reason, const z_arch_esf_t *esf) * } */ - z_fatal_print("Current thread: %p (%s)", thread, - thread_name_get(thread)); + LOG_ERR("Current thread: %p (%s)", thread, + log_strdup(thread_name_get(thread))); k_sys_fatal_error_handler(reason, esf);