[acc25ee] | 1 | /* |
---|
| 2 | * raw_exception.c - This file contains implementation of C function to |
---|
[a84392d] | 3 | * Instantiate 60x ppc primary exception entries. |
---|
| 4 | * More detailed information can be found on motorola |
---|
[acc25ee] | 5 | * site and more precisely in the following book : |
---|
| 6 | * |
---|
| 7 | * MPC750 |
---|
| 8 | * Risc Microporcessor User's Manual |
---|
| 9 | * Motorola REF : MPC750UM/AD 8/97 |
---|
| 10 | * |
---|
| 11 | * Copyright (C) 1999 Eric Valette (valette@crf.canon.fr) |
---|
| 12 | * Canon Centre Recherche France. |
---|
| 13 | * |
---|
[95273a6] | 14 | * Enhanced by Jay Kulpinski <jskulpin@eng01.gdds.com> |
---|
| 15 | * to support 603, 603e, 604, 604e exceptions |
---|
| 16 | * |
---|
[acc25ee] | 17 | * The license and distribution terms for this file may be |
---|
| 18 | * found in found in the file LICENSE in this distribution or at |
---|
[21e1c44] | 19 | * http://www.rtems.com/license/LICENSE. |
---|
[acc25ee] | 20 | * |
---|
| 21 | * $Id$ |
---|
| 22 | */ |
---|
[a73a977] | 23 | #include <rtems/system.h> |
---|
[f0f1641] | 24 | #include <rtems/score/powerpc.h> |
---|
[c0af822e] | 25 | #include <rtems/bspIo.h> |
---|
[acc25ee] | 26 | #include <libcpu/raw_exception.h> |
---|
[e05f4315] | 27 | #include <libcpu/cpuIdent.h> |
---|
[acc25ee] | 28 | |
---|
[cebb89b] | 29 | #include <string.h> |
---|
| 30 | |
---|
[acc25ee] | 31 | static rtems_raw_except_connect_data* raw_except_table; |
---|
| 32 | static rtems_raw_except_connect_data default_raw_except_entry; |
---|
| 33 | static rtems_raw_except_global_settings* local_settings; |
---|
| 34 | |
---|
[cebb89b] | 35 | void * codemove(void *, const void *, unsigned int, unsigned long); |
---|
[a84392d] | 36 | |
---|
| 37 | void* mpc60x_get_vector_addr(rtems_vector vector) |
---|
| 38 | { |
---|
| 39 | extern rtems_cpu_table Cpu_table; |
---|
| 40 | |
---|
| 41 | if ( Cpu_table.exceptions_in_RAM ) |
---|
| 42 | return ((void*) (((unsigned) vector) << 8)); |
---|
| 43 | |
---|
| 44 | return ((void*) (((unsigned) vector) << 8) + 0xfff00000); |
---|
| 45 | } |
---|
| 46 | |
---|
[acc25ee] | 47 | int mpc750_vector_is_valid(rtems_vector vector) |
---|
[cebb89b] | 48 | |
---|
[acc25ee] | 49 | { |
---|
| 50 | switch(vector) { |
---|
| 51 | case ASM_RESET_VECTOR: /* fall through */ |
---|
| 52 | case ASM_MACH_VECTOR: |
---|
| 53 | case ASM_PROT_VECTOR: |
---|
| 54 | case ASM_ISI_VECTOR: |
---|
| 55 | case ASM_EXT_VECTOR: |
---|
| 56 | case ASM_ALIGN_VECTOR: |
---|
| 57 | case ASM_PROG_VECTOR: |
---|
| 58 | case ASM_FLOAT_VECTOR: |
---|
| 59 | case ASM_DEC_VECTOR: |
---|
| 60 | case ASM_SYS_VECTOR: |
---|
| 61 | case ASM_TRACE_VECTOR: |
---|
| 62 | case ASM_ADDR_VECTOR: |
---|
| 63 | case ASM_SYSMGMT_VECTOR: |
---|
| 64 | case ASM_ITM_VECTOR: |
---|
| 65 | return 1; |
---|
| 66 | default: return 0; |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
[faed5fa] | 70 | int PSIM_vector_is_valid(rtems_vector vector) |
---|
| 71 | { |
---|
| 72 | switch(vector) { |
---|
| 73 | case ASM_RESET_VECTOR: /* fall through */ |
---|
| 74 | case ASM_MACH_VECTOR: |
---|
| 75 | case ASM_PROT_VECTOR: |
---|
| 76 | case ASM_ISI_VECTOR: |
---|
| 77 | case ASM_EXT_VECTOR: |
---|
| 78 | case ASM_ALIGN_VECTOR: |
---|
| 79 | case ASM_PROG_VECTOR: |
---|
| 80 | case ASM_FLOAT_VECTOR: |
---|
| 81 | case ASM_DEC_VECTOR: |
---|
| 82 | return 1; |
---|
| 83 | case ASM_SYS_VECTOR: |
---|
| 84 | return 0; |
---|
| 85 | case ASM_TRACE_VECTOR: |
---|
| 86 | return 1; |
---|
| 87 | case ASM_PERFMON_VECTOR: |
---|
| 88 | return 0; |
---|
| 89 | case ASM_IMISS_VECTOR: /* fall through */ |
---|
| 90 | case ASM_DLMISS_VECTOR: |
---|
| 91 | case ASM_DSMISS_VECTOR: |
---|
| 92 | case ASM_ADDR_VECTOR: |
---|
| 93 | case ASM_SYSMGMT_VECTOR: |
---|
| 94 | return 1; |
---|
| 95 | case ASM_ITM_VECTOR: |
---|
| 96 | return 0; |
---|
| 97 | } |
---|
| 98 | return 0; |
---|
| 99 | } |
---|
| 100 | |
---|
[95273a6] | 101 | int mpc603_vector_is_valid(rtems_vector vector) |
---|
| 102 | { |
---|
| 103 | switch(vector) { |
---|
| 104 | case ASM_RESET_VECTOR: /* fall through */ |
---|
| 105 | case ASM_MACH_VECTOR: |
---|
| 106 | case ASM_PROT_VECTOR: |
---|
| 107 | case ASM_ISI_VECTOR: |
---|
| 108 | case ASM_EXT_VECTOR: |
---|
| 109 | case ASM_ALIGN_VECTOR: |
---|
| 110 | case ASM_PROG_VECTOR: |
---|
| 111 | case ASM_FLOAT_VECTOR: |
---|
| 112 | case ASM_DEC_VECTOR: |
---|
| 113 | case ASM_SYS_VECTOR: |
---|
| 114 | case ASM_TRACE_VECTOR: |
---|
| 115 | return 1; |
---|
| 116 | case ASM_PERFMON_VECTOR: |
---|
| 117 | return 0; |
---|
| 118 | case ASM_IMISS_VECTOR: /* fall through */ |
---|
| 119 | case ASM_DLMISS_VECTOR: |
---|
| 120 | case ASM_DSMISS_VECTOR: |
---|
| 121 | case ASM_ADDR_VECTOR: |
---|
| 122 | case ASM_SYSMGMT_VECTOR: |
---|
| 123 | return 1; |
---|
| 124 | case ASM_ITM_VECTOR: |
---|
| 125 | return 0; |
---|
| 126 | } |
---|
| 127 | return 0; |
---|
| 128 | } |
---|
| 129 | |
---|
[acc25ee] | 130 | int mpc604_vector_is_valid(rtems_vector vector) |
---|
| 131 | { |
---|
[95273a6] | 132 | switch(vector) { |
---|
| 133 | case ASM_RESET_VECTOR: /* fall through */ |
---|
| 134 | case ASM_MACH_VECTOR: |
---|
| 135 | case ASM_PROT_VECTOR: |
---|
| 136 | case ASM_ISI_VECTOR: |
---|
| 137 | case ASM_EXT_VECTOR: |
---|
| 138 | case ASM_ALIGN_VECTOR: |
---|
| 139 | case ASM_PROG_VECTOR: |
---|
| 140 | case ASM_FLOAT_VECTOR: |
---|
| 141 | case ASM_DEC_VECTOR: |
---|
| 142 | case ASM_SYS_VECTOR: |
---|
| 143 | case ASM_TRACE_VECTOR: |
---|
| 144 | case ASM_PERFMON_VECTOR: |
---|
| 145 | return 1; |
---|
| 146 | case ASM_IMISS_VECTOR: /* fall through */ |
---|
| 147 | case ASM_DLMISS_VECTOR: |
---|
| 148 | case ASM_DSMISS_VECTOR: |
---|
| 149 | return 0; |
---|
| 150 | case ASM_ADDR_VECTOR: /* fall through */ |
---|
| 151 | case ASM_SYSMGMT_VECTOR: |
---|
| 152 | return 1; |
---|
| 153 | case ASM_ITM_VECTOR: |
---|
| 154 | return 0; |
---|
| 155 | } |
---|
[acc25ee] | 156 | return 0; |
---|
| 157 | } |
---|
| 158 | |
---|
[55e4dcf3] | 159 | int mpc60x_vector_is_valid(rtems_vector vector) |
---|
[acc25ee] | 160 | { |
---|
[55e4dcf3] | 161 | switch (current_ppc_cpu) { |
---|
[0d776cd2] | 162 | case PPC_7400: |
---|
[95273a6] | 163 | case PPC_750: |
---|
[55e4dcf3] | 164 | if (!mpc750_vector_is_valid(vector)) { |
---|
[95273a6] | 165 | return 0; |
---|
| 166 | } |
---|
| 167 | break; |
---|
| 168 | case PPC_604: |
---|
| 169 | case PPC_604e: |
---|
[d49389a] | 170 | case PPC_604r: |
---|
[83d7232] | 171 | case PPC_7455: /* Kate Feng */ |
---|
[55e4dcf3] | 172 | if (!mpc604_vector_is_valid(vector)) { |
---|
[95273a6] | 173 | return 0; |
---|
| 174 | } |
---|
| 175 | break; |
---|
| 176 | case PPC_603: |
---|
| 177 | case PPC_603e: |
---|
[83795347] | 178 | case PPC_603ev: |
---|
[a84392d] | 179 | case PPC_8260: |
---|
| 180 | /* case PPC_8240: -- same value as 8260 */ |
---|
| 181 | case PPC_8245: |
---|
[55e4dcf3] | 182 | if (!mpc603_vector_is_valid(vector)) { |
---|
[95273a6] | 183 | return 0; |
---|
| 184 | } |
---|
| 185 | break; |
---|
[faed5fa] | 186 | case PPC_PSIM: |
---|
| 187 | if (!PSIM_vector_is_valid(vector)) { |
---|
| 188 | return 0; |
---|
| 189 | } |
---|
| 190 | break; |
---|
[a84392d] | 191 | default: |
---|
| 192 | printk("Please complete " |
---|
| 193 | "libcpu/powerpc/mpc6xx/exceptions/raw_exception.c\n" |
---|
| 194 | "current_ppc_cpu = %x\n", current_ppc_cpu); |
---|
[95273a6] | 195 | return 0; |
---|
[55e4dcf3] | 196 | } |
---|
| 197 | return 1; |
---|
| 198 | } |
---|
[95273a6] | 199 | |
---|
[55e4dcf3] | 200 | int mpc60x_set_exception (const rtems_raw_except_connect_data* except) |
---|
| 201 | { |
---|
| 202 | unsigned int level; |
---|
| 203 | |
---|
| 204 | if (!mpc60x_vector_is_valid(except->exceptIndex)) { |
---|
[a84392d] | 205 | printk("mpc60x_set_exception: vector %d is not valid\n", |
---|
| 206 | except->exceptIndex); |
---|
[55e4dcf3] | 207 | return 0; |
---|
| 208 | } |
---|
[acc25ee] | 209 | /* |
---|
| 210 | * Check if default handler is actually connected. If not issue an error. |
---|
| 211 | * You must first get the current handler via mpc60x_get_current_exception |
---|
| 212 | * and then disconnect it using mpc60x_delete_exception. |
---|
| 213 | * RATIONALE : to always have the same transition by forcing the user |
---|
| 214 | * to get the previous handler before accepting to disconnect. |
---|
| 215 | */ |
---|
[a84392d] | 216 | |
---|
| 217 | if (memcmp(mpc60x_get_vector_addr(except->exceptIndex), |
---|
| 218 | (void*)default_raw_except_entry.hdl.raw_hdl, |
---|
| 219 | default_raw_except_entry.hdl.raw_hdl_size)) { |
---|
| 220 | printk("mpc60x_set_exception: raw vector not installed\n"); |
---|
[acc25ee] | 221 | return 0; |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | _CPU_ISR_Disable(level); |
---|
| 225 | |
---|
| 226 | raw_except_table [except->exceptIndex] = *except; |
---|
| 227 | codemove((void*)mpc60x_get_vector_addr(except->exceptIndex), |
---|
| 228 | except->hdl.raw_hdl, |
---|
| 229 | except->hdl.raw_hdl_size, |
---|
| 230 | PPC_CACHE_ALIGNMENT); |
---|
| 231 | except->on(except); |
---|
| 232 | |
---|
| 233 | _CPU_ISR_Enable(level); |
---|
| 234 | return 1; |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | int mpc60x_get_current_exception (rtems_raw_except_connect_data* except) |
---|
| 238 | { |
---|
[55e4dcf3] | 239 | if (!mpc60x_vector_is_valid(except->exceptIndex)){ |
---|
[acc25ee] | 240 | return 0; |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | *except = raw_except_table [except->exceptIndex]; |
---|
| 244 | |
---|
| 245 | return 1; |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | int mpc60x_delete_exception (const rtems_raw_except_connect_data* except) |
---|
| 249 | { |
---|
| 250 | unsigned int level; |
---|
| 251 | |
---|
[55e4dcf3] | 252 | if (!mpc60x_vector_is_valid(except->exceptIndex)){ |
---|
[acc25ee] | 253 | return 0; |
---|
| 254 | } |
---|
| 255 | /* |
---|
| 256 | * Check if handler passed is actually connected. If not issue an error. |
---|
| 257 | * You must first get the current handler via mpc60x_get_current_exception |
---|
| 258 | * and then disconnect it using mpc60x_delete_exception. |
---|
| 259 | * RATIONALE : to always have the same transition by forcing the user |
---|
| 260 | * to get the previous handler before accepting to disconnect. |
---|
| 261 | */ |
---|
| 262 | if (memcmp(mpc60x_get_vector_addr(except->exceptIndex), |
---|
| 263 | (void*)except->hdl.raw_hdl, |
---|
| 264 | except->hdl.raw_hdl_size)) { |
---|
| 265 | return 0; |
---|
| 266 | } |
---|
| 267 | _CPU_ISR_Disable(level); |
---|
| 268 | |
---|
| 269 | except->off(except); |
---|
| 270 | codemove((void*)mpc60x_get_vector_addr(except->exceptIndex), |
---|
| 271 | default_raw_except_entry.hdl.raw_hdl, |
---|
| 272 | default_raw_except_entry.hdl.raw_hdl_size, |
---|
| 273 | PPC_CACHE_ALIGNMENT); |
---|
| 274 | |
---|
| 275 | |
---|
| 276 | raw_except_table[except->exceptIndex] = default_raw_except_entry; |
---|
| 277 | raw_except_table[except->exceptIndex].exceptIndex = except->exceptIndex; |
---|
| 278 | |
---|
| 279 | _CPU_ISR_Enable(level); |
---|
| 280 | |
---|
| 281 | return 1; |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | /* |
---|
| 285 | * Exception global init. |
---|
| 286 | */ |
---|
| 287 | int mpc60x_init_exceptions (rtems_raw_except_global_settings* config) |
---|
| 288 | { |
---|
| 289 | unsigned i; |
---|
| 290 | unsigned int level; |
---|
| 291 | |
---|
| 292 | /* |
---|
| 293 | * store various accelerators |
---|
| 294 | */ |
---|
| 295 | raw_except_table = config->rawExceptHdlTbl; |
---|
| 296 | local_settings = config; |
---|
| 297 | default_raw_except_entry = config->defaultRawEntry; |
---|
| 298 | |
---|
| 299 | _CPU_ISR_Disable(level); |
---|
| 300 | |
---|
| 301 | for (i=0; i <= LAST_VALID_EXC; i++) { |
---|
[55e4dcf3] | 302 | if (!mpc60x_vector_is_valid(i)){ |
---|
[acc25ee] | 303 | continue; |
---|
| 304 | } |
---|
| 305 | codemove((void*)mpc60x_get_vector_addr(i), |
---|
| 306 | raw_except_table[i].hdl.raw_hdl, |
---|
| 307 | raw_except_table[i].hdl.raw_hdl_size, |
---|
| 308 | PPC_CACHE_ALIGNMENT); |
---|
| 309 | if (raw_except_table[i].hdl.raw_hdl != default_raw_except_entry.hdl.raw_hdl) { |
---|
| 310 | raw_except_table[i].on(&raw_except_table[i]); |
---|
| 311 | } |
---|
| 312 | else { |
---|
| 313 | raw_except_table[i].off(&raw_except_table[i]); |
---|
| 314 | } |
---|
| 315 | } |
---|
| 316 | _CPU_ISR_Enable(level); |
---|
| 317 | |
---|
| 318 | return 1; |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | int mpc60x_get_exception_config (rtems_raw_except_global_settings** config) |
---|
| 322 | { |
---|
| 323 | *config = local_settings; |
---|
| 324 | return 1; |
---|
| 325 | } |
---|