Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:57

0001 /*
0002  * Authorship
0003  * ----------
0004  * This software was created by
0005  *     Till Straumann <strauman@slac.stanford.edu>, 5/2002,
0006  *     Stanford Linear Accelerator Center, Stanford University.
0007  *
0008  * Acknowledgement of sponsorship
0009  * ------------------------------
0010  * This software was produced by
0011  *     the Stanford Linear Accelerator Center, Stanford University,
0012  *     under Contract DE-AC03-76SFO0515 with the Department of Energy.
0013  *
0014  * Government disclaimer of liability
0015  * ----------------------------------
0016  * Neither the United States nor the United States Department of Energy,
0017  * nor any of their employees, makes any warranty, express or implied, or
0018  * assumes any legal liability or responsibility for the accuracy,
0019  * completeness, or usefulness of any data, apparatus, product, or process
0020  * disclosed, or represents that its use would not infringe privately owned
0021  * rights.
0022  *
0023  * Stanford disclaimer of liability
0024  * --------------------------------
0025  * Stanford University makes no representations or warranties, express or
0026  * implied, nor assumes any liability for the use of this software.
0027  *
0028  * Stanford disclaimer of copyright
0029  * --------------------------------
0030  * Stanford University, owner of the copyright, hereby disclaims its
0031  * copyright and all other rights in this software.  Hence, anyone may
0032  * freely use it for any purpose without restriction.
0033  *
0034  * Maintenance of notices
0035  * ----------------------
0036  * In the interest of clarity regarding the origin and status of this
0037  * SLAC software, this and all the preceding Stanford University notices
0038  * are to remain affixed to any copy or derivative of this software made
0039  * or distributed by the recipient and are to be affixed to any copy of
0040  * software made or distributed by the recipient that contains a copy or
0041  * derivative of this software.
0042  *
0043  * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
0044  */
0045 /* Copyright :
0046  * (C) S. Kate Feng <feng1@bnl.gov> 4/2004 modified it for MVME5500
0047  */
0048 
0049 #include <bsp.h>
0050 #include <bsp/vectors.h>
0051 #include <bsp/bootcard.h>
0052 #include <libcpu/spr.h>
0053 #include <bsp/pci.h>
0054 #include <rtems/bspIo.h>
0055 #include <rtems/score/percpu.h>
0056 #include <threads.h>
0057 #include <inttypes.h>
0058 
0059 #include <bsp/bspException.h>
0060 
0061 #define SRR1_TEA_EXC    (1<<(31-13))
0062 #define SRR1_MCP_EXC    (1<<(31-12))
0063 
0064 static thread_local volatile BSP_ExceptionExtension BSP_exceptionExtension = 0;
0065 
0066 BSP_ExceptionExtension
0067 BSP_exceptionHandlerInstall(BSP_ExceptionExtension e)
0068 {
0069 volatile BSP_ExceptionExtension test;
0070     test = BSP_exceptionExtension;
0071     BSP_exceptionExtension = e;
0072     return test;
0073 }
0074 
0075 void
0076 BSP_exceptionHandler(BSP_Exception_frame* excPtr)
0077 {
0078 BSP_ExceptionExtension  ext=0;
0079 rtems_id        id=0;
0080 int         recoverable = 0;
0081 char            *fmt="Uhuuuh, Exception %d in unknown task???\n";
0082 int         quiet=0;
0083 
0084  if (!quiet) printk("In BSP_exceptionHandler()\n");
0085    /* If we are in interrupt context, we are in trouble - skip the user
0086     * hook and panic
0087     */
0088     if (rtems_interrupt_is_in_progress()) {
0089       fmt="Aieeh, Exception %d in interrupt handler\n";
0090     } else if ( !_Thread_Executing) {
0091       fmt="Aieeh, Exception %d in initialization code\n";
0092     } else {
0093     /* retrieve the notepad which possibly holds an extention pointer */
0094     if (RTEMS_SUCCESSFUL==rtems_task_ident(RTEMS_SELF,RTEMS_LOCAL,&id)) {
0095        ext = BSP_exceptionExtension;
0096        if (ext)
0097            quiet=ext->quiet;
0098        if (!quiet) {
0099           printk("Task (Id 0x%08" PRIx32 ") got ",id);
0100        }
0101        fmt="exception %d\n";
0102     }
0103     }
0104 
0105     if (ext && ext->lowlevelHook && ext->lowlevelHook(excPtr,ext,0)) {
0106         /* they did all the work and want us to do nothing! */
0107       printk("they did all the work and want us to do nothing!\n");
0108         return;
0109     }
0110 
0111     if (!quiet) {
0112        /* message about exception */
0113        printk(fmt, excPtr->_EXC_number);
0114        /* register dump */
0115        printk("\t Next PC or Address of fault = %" PRIxPTR ", ", excPtr->EXC_SRR0);
0116        printk("Mvme5500 Saved MSR = %" PRIxPTR "\n", excPtr->EXC_SRR1);
0117        printk("\t R0  = %08" PRIxPTR, excPtr->GPR0);
0118        printk(" R1  = %08" PRIxPTR, excPtr->GPR1);
0119        printk(" R2  = %08" PRIxPTR, excPtr->GPR2);
0120        printk(" R3  = %08" PRIxPTR "\n", excPtr->GPR3);
0121        printk("\t R4  = %08" PRIxPTR, excPtr->GPR4);
0122        printk(" R5  = %08" PRIxPTR, excPtr->GPR5);
0123        printk(" R6  = %08" PRIxPTR, excPtr->GPR6);
0124        printk(" R7  = %08" PRIxPTR "\n", excPtr->GPR7);
0125        printk("\t R8  = %08" PRIxPTR, excPtr->GPR8);
0126        printk(" R9  = %08" PRIxPTR, excPtr->GPR9);
0127        printk(" R10 = %08" PRIxPTR, excPtr->GPR10);
0128        printk(" R11 = %08" PRIxPTR "\n", excPtr->GPR11);
0129        printk("\t R12 = %08" PRIxPTR, excPtr->GPR12);
0130        printk(" R13 = %08" PRIxPTR, excPtr->GPR13);
0131        printk(" R14 = %08" PRIxPTR, excPtr->GPR14);
0132        printk(" R15 = %08" PRIxPTR "\n", excPtr->GPR15);
0133        printk("\t R16 = %08" PRIxPTR, excPtr->GPR16);
0134        printk(" R17 = %08" PRIxPTR, excPtr->GPR17);
0135        printk(" R18 = %08" PRIxPTR, excPtr->GPR18);
0136        printk(" R19 = %08" PRIxPTR "\n", excPtr->GPR19);
0137        printk("\t R20 = %08" PRIxPTR, excPtr->GPR20);
0138        printk(" R21 = %08" PRIxPTR, excPtr->GPR21);
0139        printk(" R22 = %08" PRIxPTR, excPtr->GPR22);
0140        printk(" R23 = %08" PRIxPTR "\n", excPtr->GPR23);
0141        printk("\t R24 = %08" PRIxPTR, excPtr->GPR24);
0142        printk(" R25 = %08" PRIxPTR, excPtr->GPR25);
0143        printk(" R26 = %08" PRIxPTR, excPtr->GPR26);
0144        printk(" R27 = %08" PRIxPTR "\n", excPtr->GPR27);
0145        printk("\t R28 = %08" PRIxPTR, excPtr->GPR28);
0146        printk(" R29 = %08" PRIxPTR, excPtr->GPR29);
0147        printk(" R30 = %08" PRIxPTR, excPtr->GPR30);
0148        printk(" R31 = %08" PRIxPTR "\n", excPtr->GPR31);
0149        printk("\t CR  = %08" PRIx32 "\n", excPtr->EXC_CR);
0150        printk("\t CTR = %08" PRIxPTR "\n", excPtr->EXC_CTR);
0151        printk("\t XER = %08" PRIx32 "\n", excPtr->EXC_XER);
0152        printk("\t LR  = %08" PRIxPTR "\n", excPtr->EXC_LR);
0153 
0154        BSP_printStackTrace(excPtr);
0155     }
0156 
0157     if (ASM_MACH_VECTOR == excPtr->_EXC_number) {
0158        /* ollah , we got a machine check - this could either
0159     * be a TEA, MCP or internal; let's see and provide more info
0160     */
0161        if (!quiet)
0162        printk("Machine check; reason:");
0163        if ( ! (excPtr->EXC_SRR1 & (SRR1_TEA_EXC | SRR1_MCP_EXC)) ) {
0164        if (!quiet)
0165            printk("SRR1\n");
0166        } else {
0167        if (excPtr->EXC_SRR1 & (SRR1_TEA_EXC)) {
0168           if (!quiet)
0169          printk(" TEA");
0170        }
0171        if (excPtr->EXC_SRR1 & (SRR1_MCP_EXC)) {
0172           unsigned long gerr;
0173 
0174           if (!quiet) printk(" MCP\n");
0175 
0176           /* it's MCP; gather info from the host bridge */
0177           gerr=_BSP_clear_hostbridge_errors(0,0);
0178               if (gerr&0x80000000) printk("GT64260 Parity error\n");
0179               if (gerr&0x40000000) printk("GT64260 SysErr\n");
0180           if ((!quiet) && (!gerr)) printk("GT64260 host bridge seems OK\n");
0181         }
0182        }
0183     } else if (ASM_DEC_VECTOR == excPtr->_EXC_number) {
0184         recoverable = 1;
0185     } else if (ASM_SYS_VECTOR == excPtr->_EXC_number) {
0186 #ifdef TEST_RAW_EXCEPTION_CODE
0187         recoverable = 1;
0188 #else
0189         recoverable = 0;
0190 #endif
0191     }
0192 
0193     /* call them for a second time giving a chance to intercept
0194      * the task_suspend
0195      */
0196     if (ext && ext->lowlevelHook && ext->lowlevelHook(excPtr, ext, 1))
0197         return;
0198 
0199     if (!recoverable) {
0200         if (id) {
0201             /* if there's a highlevel hook, install it */
0202             if (ext && ext->highlevelHook) {
0203                 excPtr->EXC_SRR0 = (uint32_t)ext->highlevelHook;
0204                 excPtr->GPR3     = (uint32_t)ext;
0205                 return;
0206             }
0207             if (excPtr->EXC_SRR1 & MSR_FP) {
0208                 /* thread dispatching is _not_ disabled at this point; hence
0209                  * we must make sure we have the FPU enabled...
0210                  */
0211                 _write_MSR( _read_MSR() | MSR_FP );
0212                 __asm__ __volatile__("isync");
0213             }
0214             printk("unrecoverable exception!!! task %08" PRIx32 " suspended\n",id);
0215             rtems_task_suspend(id);
0216         } else {
0217             printk("PANIC, rebooting...\n");
0218             bsp_reset(RTEMS_FATAL_SOURCE_BSP, 0);
0219         }
0220     }
0221 }