[0aee2be5] | 1 | /* |
---|
[8430205] | 2 | * raw_exception.c - This file contains implementation of C functions to |
---|
| 3 | * Instantiate mpc5xx primary exception entries. |
---|
| 4 | * More detailled information can be found on the Motorola |
---|
| 5 | * site and more precisely in the following book: |
---|
[0aee2be5] | 6 | * |
---|
[8430205] | 7 | * MPC555/MPC556 User's Manual |
---|
| 8 | * Motorola REF : MPC555UM/D Rev. 3, 2000 October 15 |
---|
| 9 | * |
---|
| 10 | * |
---|
| 11 | * MPC5xx port sponsored by Defence Research and Development Canada - Suffield |
---|
| 12 | * Copyright (C) 2004, Real-Time Systems Inc. (querbach@realtime.bc.ca) |
---|
| 13 | * |
---|
| 14 | * Derived from libcpu/powerpc/mpc8xx/exceptions/raw_exception.c: |
---|
[0aee2be5] | 15 | * |
---|
| 16 | * Copyright (C) 1999 Eric Valette (valette@crf.canon.fr) |
---|
| 17 | * Canon Centre Recherche France. |
---|
| 18 | * |
---|
| 19 | * The license and distribution terms for this file may be |
---|
| 20 | * found in found in the file LICENSE in this distribution or at |
---|
[8430205] | 21 | * http://www.rtems.com/license/LICENSE. |
---|
[0aee2be5] | 22 | * |
---|
[8430205] | 23 | * $Id$ |
---|
[0aee2be5] | 24 | */ |
---|
| 25 | |
---|
| 26 | #include <rtems/system.h> |
---|
| 27 | #include <rtems/score/cpu.h> |
---|
| 28 | #include <rtems/score/ppc.h> |
---|
| 29 | #include <libcpu/raw_exception.h> |
---|
| 30 | #include <libcpu/cpuIdent.h> |
---|
| 31 | #include <rtems/bspIo.h> /* for printk */ |
---|
| 32 | #include <string.h> |
---|
| 33 | |
---|
| 34 | static rtems_raw_except_connect_data* raw_except_table; |
---|
| 35 | static rtems_raw_except_connect_data default_raw_except_entry; |
---|
| 36 | static rtems_raw_except_global_settings* local_settings; |
---|
| 37 | |
---|
| 38 | int mpc5xx_vector_is_valid(rtems_vector vector) |
---|
| 39 | { |
---|
[8430205] | 40 | switch (current_ppc_cpu) { |
---|
| 41 | case PPC_5XX: |
---|
| 42 | switch(vector) { |
---|
| 43 | case ASM_RESET_VECTOR: |
---|
| 44 | case ASM_MACH_VECTOR: |
---|
| 45 | |
---|
| 46 | case ASM_EXT_VECTOR: |
---|
| 47 | case ASM_ALIGN_VECTOR: |
---|
| 48 | case ASM_PROG_VECTOR: |
---|
| 49 | case ASM_FLOAT_VECTOR: |
---|
| 50 | case ASM_DEC_VECTOR: |
---|
| 51 | |
---|
| 52 | case ASM_SYS_VECTOR: |
---|
| 53 | case ASM_TRACE_VECTOR: |
---|
| 54 | case ASM_FLOATASSIST_VECTOR: |
---|
| 55 | |
---|
| 56 | case ASM_SOFTEMUL_VECTOR: |
---|
| 57 | |
---|
| 58 | case ASM_IPROT_VECTOR: |
---|
| 59 | case ASM_DPROT_VECTOR: |
---|
| 60 | |
---|
| 61 | case ASM_DBREAK_VECTOR: |
---|
| 62 | case ASM_IBREAK_VECTOR: |
---|
| 63 | case ASM_MEBREAK_VECTOR: |
---|
| 64 | case ASM_NMEBREAK_VECTOR: |
---|
| 65 | return 1; |
---|
| 66 | default: |
---|
| 67 | return 0; |
---|
| 68 | } |
---|
| 69 | default: |
---|
| 70 | printk("Please complete libcpu/powerpc/mpc5xx/exceptions/raw_exception.c\n"); |
---|
| 71 | printk("current_ppc_cpu = %x\n", current_ppc_cpu); |
---|
| 72 | return 0; |
---|
| 73 | } |
---|
[0aee2be5] | 74 | } |
---|
| 75 | |
---|
| 76 | int mpc5xx_set_exception (const rtems_raw_except_connect_data* except) |
---|
| 77 | { |
---|
[8430205] | 78 | unsigned int level; |
---|
[0aee2be5] | 79 | |
---|
[8430205] | 80 | if (!mpc5xx_vector_is_valid(except->exceptIndex)) { |
---|
| 81 | return 0; |
---|
| 82 | } |
---|
| 83 | /* |
---|
| 84 | * Check if default handler is actually connected. If not issue an error. |
---|
| 85 | * You must first get the current handler via mpc5xx_get_current_exception |
---|
| 86 | * and then disconnect it using mpc5xx_delete_exception. |
---|
| 87 | * RATIONALE : to always have the same transition by forcing the user |
---|
| 88 | * to get the previous handler before accepting to disconnect. |
---|
| 89 | */ |
---|
| 90 | if (exception_handler_table[except->exceptIndex] != |
---|
| 91 | default_raw_except_entry.hdl.raw_hdl) { |
---|
| 92 | return 0; |
---|
| 93 | } |
---|
[0aee2be5] | 94 | |
---|
[8430205] | 95 | _CPU_ISR_Disable(level); |
---|
| 96 | |
---|
| 97 | raw_except_table[except->exceptIndex] = *except; |
---|
| 98 | |
---|
| 99 | exception_handler_table[except->exceptIndex] = except->hdl.raw_hdl; |
---|
| 100 | except->on(except); |
---|
| 101 | |
---|
| 102 | _CPU_ISR_Enable(level); |
---|
| 103 | return 1; |
---|
[0aee2be5] | 104 | } |
---|
| 105 | |
---|
| 106 | int mpc5xx_get_current_exception (rtems_raw_except_connect_data* except) |
---|
| 107 | { |
---|
| 108 | if (!mpc5xx_vector_is_valid(except->exceptIndex)){ |
---|
| 109 | return 0; |
---|
| 110 | } |
---|
| 111 | |
---|
[8430205] | 112 | *except = raw_except_table[except->exceptIndex]; |
---|
[0aee2be5] | 113 | |
---|
| 114 | return 1; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | int mpc5xx_delete_exception (const rtems_raw_except_connect_data* except) |
---|
| 118 | { |
---|
| 119 | unsigned int level; |
---|
| 120 | |
---|
| 121 | if (!mpc5xx_vector_is_valid(except->exceptIndex)){ |
---|
| 122 | return 0; |
---|
| 123 | } |
---|
| 124 | /* |
---|
| 125 | * Check if handler passed is actually connected. If not issue an error. |
---|
| 126 | * You must first get the current handler via mpc5xx_get_current_exception |
---|
| 127 | * and then disconnect it using mpc5xx_delete_exception. |
---|
| 128 | * RATIONALE : to always have the same transition by forcing the user |
---|
| 129 | * to get the previous handler before accepting to disconnect. |
---|
| 130 | */ |
---|
[8430205] | 131 | if (exception_handler_table[except->exceptIndex] != except->hdl.raw_hdl) { |
---|
| 132 | return 0; |
---|
[0aee2be5] | 133 | } |
---|
[8430205] | 134 | |
---|
[0aee2be5] | 135 | _CPU_ISR_Disable(level); |
---|
| 136 | |
---|
| 137 | except->off(except); |
---|
[8430205] | 138 | exception_handler_table[except->exceptIndex] = |
---|
| 139 | default_raw_except_entry.hdl.raw_hdl; |
---|
| 140 | |
---|
[0aee2be5] | 141 | raw_except_table[except->exceptIndex] = default_raw_except_entry; |
---|
| 142 | raw_except_table[except->exceptIndex].exceptIndex = except->exceptIndex; |
---|
| 143 | |
---|
| 144 | _CPU_ISR_Enable(level); |
---|
| 145 | |
---|
| 146 | return 1; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | /* |
---|
| 150 | * Exception global init. |
---|
[8430205] | 151 | * |
---|
| 152 | * Install exception handler pointers from the raw exception table into the |
---|
| 153 | * exception handler table. |
---|
[0aee2be5] | 154 | */ |
---|
| 155 | int mpc5xx_init_exceptions (rtems_raw_except_global_settings* config) |
---|
| 156 | { |
---|
[8430205] | 157 | unsigned i; |
---|
| 158 | unsigned int level; |
---|
| 159 | |
---|
| 160 | /* |
---|
| 161 | * store various accelerators |
---|
| 162 | */ |
---|
| 163 | raw_except_table = config->rawExceptHdlTbl; |
---|
| 164 | local_settings = config; |
---|
| 165 | default_raw_except_entry = config->defaultRawEntry; |
---|
| 166 | |
---|
| 167 | _CPU_ISR_Disable(level); |
---|
| 168 | |
---|
| 169 | for (i = 0; i < NUM_EXCEPTIONS; i++) { |
---|
| 170 | exception_handler_table[i] = raw_except_table[i].hdl.raw_hdl; |
---|
| 171 | |
---|
| 172 | if (raw_except_table[i].hdl.raw_hdl != default_raw_except_entry.hdl.raw_hdl) { |
---|
| 173 | raw_except_table[i].on(&raw_except_table[i]); |
---|
| 174 | } |
---|
| 175 | else { |
---|
| 176 | raw_except_table[i].off(&raw_except_table[i]); |
---|
[0aee2be5] | 177 | } |
---|
[8430205] | 178 | } |
---|
| 179 | _CPU_ISR_Enable(level); |
---|
[0aee2be5] | 180 | |
---|
[8430205] | 181 | return 1; |
---|
[0aee2be5] | 182 | } |
---|
| 183 | |
---|
| 184 | int mpc5xx_get_exception_config (rtems_raw_except_global_settings** config) |
---|
| 185 | { |
---|
| 186 | *config = local_settings; |
---|
| 187 | return 1; |
---|
| 188 | } |
---|
| 189 | |
---|