Back to home page

LXR

 
 

    


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

0001 /*
0002  * raw_exception.c  - This file contains implementation of C functions to
0003  *                    Instantiate mpc5xx primary exception entries.
0004  *            More detailled information can be found on the Motorola
0005  *                site and more precisely in the following book:
0006  *
0007  *           MPC555/MPC556 User's Manual
0008  *           Motorola REF : MPC555UM/D Rev. 3, 2000 October 15
0009  *
0010  *
0011  * MPC5xx port sponsored by Defence Research and Development Canada - Suffield
0012  * Copyright (C) 2004, Real-Time Systems Inc. (querbach@realtime.bc.ca)
0013  *
0014  * Derived from libcpu/powerpc/mpc8xx/exceptions/raw_exception.c:
0015  *
0016  * Copyright (C) 1999  Eric Valette (valette@crf.canon.fr)
0017  *                     Canon Centre Recherche France.
0018  *
0019  *  The license and distribution terms for this file may be
0020  *  found in the file LICENSE in this distribution or at
0021  *  http://www.rtems.org/license/LICENSE.
0022  *
0023  */
0024 
0025 #include <rtems.h>
0026 #include <rtems/score/powerpc.h>
0027 #include <libcpu/raw_exception.h>
0028 #include <libcpu/cpuIdent.h>
0029 #include <rtems/bspIo.h>    /* for printk */
0030 #include <string.h>
0031 
0032 static rtems_raw_except_connect_data*       raw_except_table;
0033 static rtems_raw_except_connect_data        default_raw_except_entry;
0034 static rtems_raw_except_global_settings*    local_settings;
0035 
0036 int mpc5xx_vector_is_valid(rtems_vector vector)
0037 {
0038   switch (current_ppc_cpu) {
0039     case PPC_5XX:
0040       switch(vector) {
0041         case ASM_RESET_VECTOR:
0042         case ASM_MACH_VECTOR:
0043 
0044         case ASM_EXT_VECTOR:
0045         case ASM_ALIGN_VECTOR:
0046         case ASM_PROG_VECTOR:
0047         case ASM_FLOAT_VECTOR:
0048         case ASM_DEC_VECTOR:
0049 
0050         case ASM_SYS_VECTOR:
0051         case ASM_TRACE_VECTOR:
0052         case ASM_FLOATASSIST_VECTOR:
0053 
0054         case ASM_SOFTEMUL_VECTOR:
0055 
0056         case ASM_IPROT_VECTOR:
0057         case ASM_DPROT_VECTOR:
0058 
0059         case ASM_DBREAK_VECTOR:
0060         case ASM_IBREAK_VECTOR:
0061         case ASM_MEBREAK_VECTOR:
0062         case ASM_NMEBREAK_VECTOR:
0063           return 1;
0064         default:
0065           return 0;
0066       }
0067     default:
0068       printk("Please complete libcpu/powerpc/mpc5xx/exceptions/raw_exception.c\n");
0069       printk("current_ppc_cpu = %x\n", current_ppc_cpu);
0070       return 0;
0071   }
0072 }
0073 
0074 int mpc5xx_set_exception  (const rtems_raw_except_connect_data* except)
0075 {
0076   rtems_interrupt_level level;
0077 
0078   if (!mpc5xx_vector_is_valid(except->exceptIndex)) {
0079     return 0;
0080   }
0081   /*
0082    * Check if default handler is actually connected. If not issue an error.
0083    * You must first get the current handler via mpc5xx_get_current_exception
0084    * and then disconnect it using mpc5xx_delete_exception.
0085    * RATIONALE : to always have the same transition by forcing the user
0086    * to get the previous handler before accepting to disconnect.
0087    */
0088   if (exception_handler_table[except->exceptIndex] !=
0089       default_raw_except_entry.hdl.raw_hdl) {
0090     return 0;
0091   }
0092 
0093   rtems_interrupt_disable(level);
0094 
0095   raw_except_table[except->exceptIndex] = *except;
0096 
0097   exception_handler_table[except->exceptIndex] = except->hdl.raw_hdl;
0098   if (except->on)
0099     except->on(except);
0100 
0101   rtems_interrupt_enable(level);
0102   return 1;
0103 }
0104 
0105 int mpc5xx_get_current_exception (rtems_raw_except_connect_data* except)
0106 {
0107   if (!mpc5xx_vector_is_valid(except->exceptIndex)){
0108     return 0;
0109   }
0110 
0111   *except = raw_except_table[except->exceptIndex];
0112 
0113   return 1;
0114 }
0115 
0116 int mpc5xx_delete_exception (const rtems_raw_except_connect_data* except)
0117 {
0118   rtems_interrupt_level level;
0119 
0120   if (!mpc5xx_vector_is_valid(except->exceptIndex)){
0121     return 0;
0122   }
0123   /*
0124    * Check if handler passed is actually connected. If not issue an error.
0125    * You must first get the current handler via mpc5xx_get_current_exception
0126    * and then disconnect it using mpc5xx_delete_exception.
0127    * RATIONALE : to always have the same transition by forcing the user
0128    * to get the previous handler before accepting to disconnect.
0129    */
0130   if (exception_handler_table[except->exceptIndex] != except->hdl.raw_hdl) {
0131     return 0;
0132   }
0133 
0134   rtems_interrupt_disable(level);
0135 
0136   if (except->off)
0137     except->off(except);
0138   exception_handler_table[except->exceptIndex] =
0139     default_raw_except_entry.hdl.raw_hdl;
0140 
0141   raw_except_table[except->exceptIndex] = default_raw_except_entry;
0142   raw_except_table[except->exceptIndex].exceptIndex = except->exceptIndex;
0143 
0144   rtems_interrupt_enable(level);
0145 
0146   return 1;
0147 }
0148 
0149 /*
0150  * Exception global init.
0151  *
0152  * Install exception handler pointers from the raw exception table into the
0153  * exception handler table.
0154  */
0155 int mpc5xx_init_exceptions (rtems_raw_except_global_settings* config)
0156 {
0157   unsigned      i;
0158   rtems_interrupt_level level;
0159 
0160   /*
0161    * store various accelerators
0162    */
0163   raw_except_table      = config->rawExceptHdlTbl;
0164   local_settings        = config;
0165   default_raw_except_entry  = config->defaultRawEntry;
0166 
0167   rtems_interrupt_disable(level);
0168 
0169   for (i = 0; i < NUM_EXCEPTIONS; i++) {
0170     exception_handler_table[i] = raw_except_table[i].hdl.raw_hdl;
0171 
0172     if (raw_except_table[i].hdl.raw_hdl != default_raw_except_entry.hdl.raw_hdl) {
0173       if (raw_except_table[i].on)
0174         raw_except_table[i].on(&raw_except_table[i]);
0175     }
0176     else {
0177       if (raw_except_table[i].off)
0178         raw_except_table[i].off(&raw_except_table[i]);
0179     }
0180   }
0181   rtems_interrupt_enable(level);
0182 
0183   return 1;
0184 }
0185 
0186 int mpc5xx_get_exception_config (rtems_raw_except_global_settings** config)
0187 {
0188   *config = local_settings;
0189   return 1;
0190 }