From 225ff95e189ffd1fa2c2c02daf4a0f71fe8cbb8b Mon Sep 17 00:00:00 2001 From: jhibbits Date: Wed, 21 Feb 2018 03:34:33 +0000 Subject: [PATCH] Split printtrap() into generic and CPU-specific components Summary: This compartmentalizes the CPU-specific trap components into its own function, rather than littering the general printtrap() with various checks. This will let us replace a series of #ifdef's with a runtime conditional check in the future. Reviewed By: nwhitehorn Differential Revision: https://reviews.freebsd.org/D14416 --- sys/powerpc/powerpc/trap.c | 61 +++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/sys/powerpc/powerpc/trap.c b/sys/powerpc/powerpc/trap.c index 613033dc2303..62030edeb9d4 100644 --- a/sys/powerpc/powerpc/trap.c +++ b/sys/powerpc/powerpc/trap.c @@ -444,13 +444,45 @@ trap_fatal(struct trapframe *frame) panic("%s trap", trapname(frame->exc)); } +static void +cpu_printtrap(u_int vector, struct trapframe *frame, int isfatal, int user) +{ +#ifdef AIM + uint16_t ver; + + switch (vector) { + case EXC_DSE: + case EXC_DSI: + case EXC_DTMISS: + printf(" dsisr = 0x%lx\n", + (u_long)frame->cpu.aim.dsisr); + break; + case EXC_MCHK: + ver = mfpvr() >> 16; + if (MPC745X_P(ver)) + printf(" msssr0 = 0x%b\n", + (int)mfspr(SPR_MSSSR0), MSSSR_BITMASK); + break; + } +#elif defined(BOOKE) + vm_paddr_t pa; + + switch (vector) { + case EXC_MCHK: + pa = mfspr(SPR_MCARU); + pa = (pa << 32) | (u_register_t)mfspr(SPR_MCAR); + printf(" mcsr = 0x%b\n", + (int)mfspr(SPR_MCSR), MCSR_BITMASK); + printf(" mcar = 0x%jx\n", (uintmax_t)pa); + } + printf(" esr = 0x%b\n", + (int)frame->cpu.booke.esr, ESR_BITMASK); +#endif +} + static void printtrap(u_int vector, struct trapframe *frame, int isfatal, int user) { - uint16_t ver; -#ifdef BOOKE - vm_paddr_t pa; -#endif printf("\n"); printf("%s %s trap:\n", isfatal ? "fatal" : "handled", @@ -462,10 +494,6 @@ printtrap(u_int vector, struct trapframe *frame, int isfatal, int user) case EXC_DSI: case EXC_DTMISS: printf(" virtual address = 0x%" PRIxPTR "\n", frame->dar); -#ifdef AIM - printf(" dsisr = 0x%lx\n", - (u_long)frame->cpu.aim.dsisr); -#endif break; case EXC_ISE: case EXC_ISI: @@ -473,24 +501,9 @@ printtrap(u_int vector, struct trapframe *frame, int isfatal, int user) printf(" virtual address = 0x%" PRIxPTR "\n", frame->srr0); break; case EXC_MCHK: - ver = mfpvr() >> 16; -#if defined(AIM) - if (MPC745X_P(ver)) - printf(" msssr0 = 0x%b\n", - (int)mfspr(SPR_MSSSR0), MSSSR_BITMASK); -#elif defined(BOOKE) - pa = mfspr(SPR_MCARU); - pa = (pa << 32) | (u_register_t)mfspr(SPR_MCAR); - printf(" mcsr = 0x%b\n", - (int)mfspr(SPR_MCSR), MCSR_BITMASK); - printf(" mcar = 0x%jx\n", (uintmax_t)pa); -#endif break; } -#ifdef BOOKE - printf(" esr = 0x%b\n", - (int)frame->cpu.booke.esr, ESR_BITMASK); -#endif + cpu_printtrap(vector, frame, isfatal, user); printf(" srr0 = 0x%" PRIxPTR " (0x%" PRIxPTR ")\n", frame->srr0, frame->srr0 - (register_t)(__startkernel - KERNBASE)); printf(" srr1 = 0x%lx\n", (u_long)frame->srr1);