uboot/cpu/mpc5xx/traps.c
<<
>>
Prefs
   1/*
   2 * linux/arch/ppc/kernel/traps.c
   3 *
   4 * Copyright (C) 1995-1996  Gary Thomas (gdt@linuxppc.org)
   5 *
   6 * Modified by Cort Dougan (cort@cs.nmt.edu)
   7 * and Paul Mackerras (paulus@cs.anu.edu.au)
   8 *
   9 * (C) Copyright 2000
  10 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  11 *
  12 * See file CREDITS for list of people who contributed to this
  13 * project.
  14 *
  15 * This program is free software; you can redistribute it and/or
  16 * modify it under the terms of the GNU General Public License as
  17 * published by the Free Software Foundation; either version 2 of
  18 * the License, or (at your option) any later version.
  19 *
  20 * This program is distributed in the hope that it will be useful,
  21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23 * GNU General Public License for more details.
  24 *
  25 * You should have received a copy of the GNU General Public License
  26 * along with this program; if not, write to the Free Software
  27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28 * MA 02111-1307 USA
  29 */
  30
  31/*
  32 * This file handles the architecture-dependent parts of hardware exceptions
  33 */
  34
  35#include <common.h>
  36#include <command.h>
  37#include <asm/processor.h>
  38
  39#if defined(CONFIG_CMD_KGDB)
  40int (*debugger_exception_handler)(struct pt_regs *) = 0;
  41#endif
  42
  43#if defined(CONFIG_CMD_BEDBUG)
  44extern void do_bedbug_breakpoint(struct pt_regs *);
  45#endif
  46
  47/* Returns 0 if exception not found and fixup otherwise.  */
  48extern unsigned long search_exception_table(unsigned long);
  49
  50/* THIS NEEDS CHANGING to use the board info structure.
  51*/
  52#define END_OF_MEM      0x0001000
  53
  54
  55/*
  56 * Print stack backtrace
  57 */
  58void print_backtrace(unsigned long *sp)
  59{
  60        int cnt = 0;
  61        unsigned long i;
  62
  63        printf("Call backtrace: ");
  64        while (sp) {
  65                if ((uint)sp > END_OF_MEM)
  66                        break;
  67
  68                i = sp[1];
  69                if (cnt++ % 7 == 0)
  70                        printf("\n");
  71                printf("%08lX ", i);
  72                if (cnt > 32) break;
  73                sp = (unsigned long *)*sp;
  74        }
  75        printf("\n");
  76}
  77
  78/*
  79 * Print current registers
  80 */
  81void show_regs(struct pt_regs * regs)
  82{
  83        int i;
  84        printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  85               regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  86        printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  87               regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  88               regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  89               regs->msr&MSR_IR ? 1 : 0,
  90               regs->msr&MSR_DR ? 1 : 0);
  91
  92        printf("\n");
  93        for (i = 0;  i < 32;  i++) {
  94                if ((i % 8) == 0)
  95                {
  96                        printf("GPR%02d: ", i);
  97                }
  98
  99                printf("%08lX ", regs->gpr[i]);
 100                if ((i % 8) == 7)
 101                {
 102                        printf("\n");
 103                }
 104        }
 105}
 106
 107
 108/*
 109 * General exception handler routine
 110 */
 111void _exception(int signr, struct pt_regs *regs)
 112{
 113        show_regs(regs);
 114        print_backtrace((unsigned long *)regs->gpr[1]);
 115        panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
 116}
 117
 118/*
 119 * Machine check exception handler routine
 120 */
 121void MachineCheckException(struct pt_regs *regs)
 122{
 123        unsigned long fixup;
 124
 125        /* Probing PCI using config cycles cause this exception
 126         * when a device is not present.  Catch it and return to
 127         * the PCI exception handler.
 128         */
 129        if ((fixup = search_exception_table(regs->nip)) != 0) {
 130                regs->nip = fixup;
 131                return;
 132        }
 133
 134#if defined(CONFIG_CMD_KGDB)
 135        if (debugger_exception_handler && (*debugger_exception_handler)(regs))
 136                return;
 137#endif
 138
 139        printf("Machine check in kernel mode.\n");
 140        printf("Caused by (from msr): ");
 141        printf("regs %p ",regs);
 142        switch( regs->msr & 0x000F0000) {
 143        case (0x80000000>>12):
 144                printf("Machine check signal\n");
 145                break;
 146        case (0x80000000>>13):
 147                printf("Transfer error ack signal\n");
 148                break;
 149        case (0x80000000>>14):
 150                printf("Data parity signal\n");
 151                break;
 152        case (0x80000000>>15):
 153                printf("Address parity signal\n");
 154                break;
 155        default:
 156                printf("Unknown values in msr\n");
 157        }
 158        show_regs(regs);
 159        print_backtrace((unsigned long *)regs->gpr[1]);
 160        panic("machine check");
 161}
 162
 163/*
 164 * Alignment exception handler routine
 165 */
 166void AlignmentException(struct pt_regs *regs)
 167{
 168#if defined(CONFIG_CMD_KGDB)
 169        if (debugger_exception_handler && (*debugger_exception_handler)(regs))
 170                return;
 171#endif
 172        show_regs(regs);
 173        print_backtrace((unsigned long *)regs->gpr[1]);
 174        panic("Alignment Exception");
 175}
 176
 177/*
 178 * Program check exception handler routine
 179 */
 180void ProgramCheckException(struct pt_regs *regs)
 181{
 182#if defined(CONFIG_CMD_KGDB)
 183        if (debugger_exception_handler && (*debugger_exception_handler)(regs))
 184                return;
 185#endif
 186        show_regs(regs);
 187        print_backtrace((unsigned long *)regs->gpr[1]);
 188        panic("Program Check Exception");
 189}
 190
 191/*
 192 * Software emulation exception handler routine
 193 */
 194void SoftEmuException(struct pt_regs *regs)
 195{
 196#if defined(CONFIG_CMD_KGDB)
 197        if (debugger_exception_handler && (*debugger_exception_handler)(regs))
 198                return;
 199#endif
 200        show_regs(regs);
 201        print_backtrace((unsigned long *)regs->gpr[1]);
 202        panic("Software Emulation Exception");
 203}
 204
 205
 206/*
 207 * Unknown exception handler routine
 208 */
 209void UnknownException(struct pt_regs *regs)
 210{
 211#if defined(CONFIG_CMD_KGDB)
 212        if (debugger_exception_handler && (*debugger_exception_handler)(regs))
 213                return;
 214#endif
 215        printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
 216               regs->nip, regs->msr, regs->trap);
 217        _exception(0, regs);
 218}
 219
 220/*
 221 * Debug exception handler routine
 222 */
 223void DebugException(struct pt_regs *regs)
 224{
 225        printf("Debugger trap at @ %lx\n", regs->nip );
 226        show_regs(regs);
 227#if defined(CONFIG_CMD_BEDBUG)
 228        do_bedbug_breakpoint( regs );
 229#endif
 230}
 231