Back to home page

LXR

 
 

    


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

0001 /*
0002  * vectors_init.c Exception hanlding initialisation (and generic handler).
0003  *
0004  *  This include file describe the data structure and the functions implemented
0005  *  by rtems to handle exceptions.
0006  */
0007 
0008 /*
0009  *  MPC5xx port sponsored by Defence Research and Development Canada - Suffield
0010  *  Copyright (C) 2004, Real-Time Systems Inc. (querbach@realtime.bc.ca)
0011  *
0012  *  Derived from libbsp/powerpc/mbx8xx/vectors/vectors_init.c:
0013  *
0014  *  CopyRight (C) 1999 valette@crf.canon.fr
0015  *
0016  *  The license and distribution terms for this file may be
0017  *  found in the file LICENSE in this distribution or at
0018  *  http://www.rtems.org/license/LICENSE.
0019  */
0020 #include <inttypes.h>
0021 #include <rtems/bspIo.h>
0022 #include <libcpu/vectors.h>
0023 #include <libcpu/raw_exception.h>
0024 #include <bsp/irq.h>
0025 
0026 extern rtems_exception_handler_t default_exception_handler;
0027 
0028 static rtems_raw_except_global_settings exception_config;
0029 static rtems_raw_except_connect_data    exception_table[NUM_EXCEPTIONS];
0030 rtems_exception_handler_t* exception_handler_table[NUM_EXCEPTIONS];
0031 
0032 void C_default_exception_handler(CPU_Exception_frame* excPtr)
0033 {
0034   int recoverable = 0;
0035 
0036   printk("exception handler called for exception %" PRIu32 "\n",
0037          excPtr->_EXC_number);
0038   printk("\t Next PC or Address of fault = %" PRIxPTR "\n", excPtr->EXC_SRR0);
0039   printk("\t Saved MSR = %" PRIxPTR "\n", excPtr->EXC_SRR1);
0040   printk("\t R0 = %" PRIxPTR "\n", excPtr->GPR0);
0041   printk("\t R1 = %" PRIxPTR "\n", excPtr->GPR1);
0042   printk("\t R2 = %" PRIxPTR "\n", excPtr->GPR2);
0043   printk("\t R3 = %" PRIxPTR "\n", excPtr->GPR3);
0044   printk("\t R4 = %" PRIxPTR "\n", excPtr->GPR4);
0045   printk("\t R5 = %" PRIxPTR "\n", excPtr->GPR5);
0046   printk("\t R6 = %" PRIxPTR "\n", excPtr->GPR6);
0047   printk("\t R7 = %" PRIxPTR "\n", excPtr->GPR7);
0048   printk("\t R8 = %" PRIxPTR "\n", excPtr->GPR8);
0049   printk("\t R9 = %" PRIxPTR "\n", excPtr->GPR9);
0050   printk("\t R10 = %" PRIxPTR "\n", excPtr->GPR10);
0051   printk("\t R11 = %" PRIxPTR "\n", excPtr->GPR11);
0052   printk("\t R12 = %" PRIxPTR "\n", excPtr->GPR12);
0053   printk("\t R13 = %" PRIxPTR "\n", excPtr->GPR13);
0054   printk("\t R14 = %" PRIxPTR "\n", excPtr->GPR14);
0055   printk("\t R15 = %" PRIxPTR "\n", excPtr->GPR15);
0056   printk("\t R16 = %" PRIxPTR "\n", excPtr->GPR16);
0057   printk("\t R17 = %" PRIxPTR "\n", excPtr->GPR17);
0058   printk("\t R18 = %" PRIxPTR "\n", excPtr->GPR18);
0059   printk("\t R19 = %" PRIxPTR "\n", excPtr->GPR19);
0060   printk("\t R20 = %" PRIxPTR "\n", excPtr->GPR20);
0061   printk("\t R21 = %" PRIxPTR "\n", excPtr->GPR21);
0062   printk("\t R22 = %" PRIxPTR "\n", excPtr->GPR22);
0063   printk("\t R23 = %" PRIxPTR "\n", excPtr->GPR23);
0064   printk("\t R24 = %" PRIxPTR "\n", excPtr->GPR24);
0065   printk("\t R25 = %" PRIxPTR "\n", excPtr->GPR25);
0066   printk("\t R26 = %" PRIxPTR "\n", excPtr->GPR26);
0067   printk("\t R27 = %" PRIxPTR "\n", excPtr->GPR27);
0068   printk("\t R28 = %" PRIxPTR "\n", excPtr->GPR28);
0069   printk("\t R29 = %" PRIxPTR "\n", excPtr->GPR29);
0070   printk("\t R30 = %" PRIxPTR "\n", excPtr->GPR30);
0071   printk("\t R31 = %" PRIxPTR "\n", excPtr->GPR31);
0072   printk("\t CR = %" PRIx32 "\n", excPtr->EXC_CR);
0073   printk("\t CTR = %" PRIxPTR "\n", excPtr->EXC_CTR);
0074   printk("\t XER = %" PRIx32 "\n", excPtr->EXC_XER);
0075   printk("\t LR = %" PRIxPTR "\n", excPtr->EXC_LR);
0076   if (excPtr->_EXC_number == ASM_DEC_VECTOR)
0077        recoverable = 1;
0078   if (excPtr->_EXC_number == ASM_SYS_VECTOR)
0079 #ifdef TEST_RAW_EXCEPTION_CODE
0080     recoverable = 1;
0081 #else
0082     recoverable = 0;
0083 #endif
0084     if (!recoverable) {
0085       printk("unrecoverable exception!!! Push reset button\n");
0086       while(1);
0087     }
0088 }
0089 
0090 static void nop_except_enable(const rtems_raw_except_connect_data* ptr)
0091 {
0092 }
0093 
0094 static int except_always_enabled(const rtems_raw_except_connect_data* ptr)
0095 {
0096   return 1;
0097 }
0098 
0099 void initialize_exceptions(void)
0100 {
0101   int i;
0102 
0103   /*
0104    * Initialize all entries of the exception table with a description of the
0105    * default exception handler.
0106    */
0107   exception_config.exceptSize           = NUM_EXCEPTIONS;
0108   exception_config.rawExceptHdlTbl      = &exception_table[0];
0109   exception_config.defaultRawEntry.exceptIndex  = 0;
0110   exception_config.defaultRawEntry.hdl.vector   = 0;
0111   exception_config.defaultRawEntry.hdl.raw_hdl  = default_exception_handler;
0112 
0113   for (i = 0; i < exception_config.exceptSize; i++) {
0114     printk("installing exception number %d\n", i);
0115     exception_table[i].exceptIndex  = i;
0116     exception_table[i].hdl      = exception_config.defaultRawEntry.hdl;
0117     exception_table[i].hdl.vector   = i;
0118     exception_table[i].on       = nop_except_enable;
0119     exception_table[i].off      = nop_except_enable;
0120     exception_table[i].isOn     = except_always_enabled;
0121   }
0122 
0123   /*
0124    * Now pass the initialized exception table to the exceptions module which
0125    * will install the handler pointers in the exception handler table.
0126    */
0127   if (!mpc5xx_init_exceptions(&exception_config)) {
0128     /*
0129      * At this stage we may not call CPU_Panic because it uses exceptions!!!
0130      */
0131     printk("Exception handling initialization failed\n");
0132     printk("System locked\n"); while(1);
0133   }
0134   else {
0135     printk("Exception handling initialization done\n");
0136   }
0137 }