1 | /* |
---|
2 | * raw_exception.c - This file contains implementation of C function to |
---|
3 | * Instanciate 8xx ppc primary exception entries. |
---|
4 | * More detailled information can be found on motorola |
---|
5 | * site and more precisely in the following book : |
---|
6 | * |
---|
7 | * MPC860 |
---|
8 | * Risc Microporcessor User's Manual |
---|
9 | * Motorola REF : MPC860UM/AD |
---|
10 | * |
---|
11 | * Copyright (C) 1999 Eric Valette (valette@crf.canon.fr) |
---|
12 | * Canon Centre Recherche France. |
---|
13 | * |
---|
14 | * Changes for MPC5XX Wilfried Busalski (w.busalski@lancier-monitoring.de) |
---|
15 | * Copyright (C) 2003 Lancier Monitoring GmbH |
---|
16 | * |
---|
17 | * The license and distribution terms for this file may be |
---|
18 | * found in found in the file LICENSE in this distribution or at |
---|
19 | * http://www.OARcorp.com/rtems/license.html. |
---|
20 | * |
---|
21 | * raw_exception.c,v 1.5 2002/11/04 14:29:02 joel Exp |
---|
22 | */ |
---|
23 | |
---|
24 | #include <rtems/system.h> |
---|
25 | #include <rtems/score/cpu.h> |
---|
26 | #include <rtems/score/ppc.h> |
---|
27 | #include <libcpu/raw_exception.h> |
---|
28 | #include <libcpu/cpuIdent.h> |
---|
29 | #include <rtems/bspIo.h> /* for printk */ |
---|
30 | #include <string.h> |
---|
31 | |
---|
32 | void * codemove(void *, const void *, unsigned int, unsigned long); |
---|
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 mpc565_vector_is_valid(rtems_vector vector) |
---|
39 | { |
---|
40 | switch(vector) { |
---|
41 | case ASM_RESET_VECTOR: /* fall through */ |
---|
42 | case ASM_MACH_VECTOR: |
---|
43 | case ASM_PROT_VECTOR: |
---|
44 | case ASM_ISI_VECTOR: |
---|
45 | case ASM_EXT_VECTOR: |
---|
46 | case ASM_ALIGN_VECTOR: |
---|
47 | case ASM_PROG_VECTOR: |
---|
48 | case ASM_FLOAT_VECTOR: |
---|
49 | case ASM_DEC_VECTOR: |
---|
50 | |
---|
51 | case ASM_SYS_VECTOR: |
---|
52 | case ASM_TRACE_VECTOR: |
---|
53 | case ASM_FLOATASSIST_VECTOR: |
---|
54 | |
---|
55 | case ASM_SOFTEMUL_VECTOR: |
---|
56 | |
---|
57 | case ASM_ITLBERROR_VECTOR: |
---|
58 | case ASM_DTLBERROR_VECTOR: |
---|
59 | |
---|
60 | case ASM_DBREAK_VECTOR: |
---|
61 | case ASM_IBREAK_VECTOR: |
---|
62 | case ASM_PERIFBREAK_VECTOR: |
---|
63 | case ASM_DEVPORT_VECTOR: |
---|
64 | return 1; |
---|
65 | default: return 0; |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | int mpc5xx_vector_is_valid(rtems_vector vector) |
---|
70 | { |
---|
71 | switch (current_ppc_cpu) { |
---|
72 | case MPC_5XX: |
---|
73 | if (!mpc565_vector_is_valid(vector)) { |
---|
74 | return 0; |
---|
75 | } |
---|
76 | break; |
---|
77 | default: |
---|
78 | printk("Please complete libcpu/powerpc/mpc5xx/exceptions/raw_exception.c\n"); |
---|
79 | printk("current_ppc_cpu = %x\n", current_ppc_cpu); |
---|
80 | return 0; |
---|
81 | } |
---|
82 | return 1; |
---|
83 | } |
---|
84 | |
---|
85 | int mpc5xx_set_exception (const rtems_raw_except_connect_data* except) |
---|
86 | { |
---|
87 | unsigned int level; |
---|
88 | |
---|
89 | if (!mpc5xx_vector_is_valid(except->exceptIndex)) { |
---|
90 | return 0; |
---|
91 | } |
---|
92 | /* |
---|
93 | * Check if default handler is actually connected. If not issue an error. |
---|
94 | * You must first get the current handler via mpc5xx_get_current_exception |
---|
95 | * and then disconnect it using mpc5xx_delete_exception. |
---|
96 | * RATIONALE : to always have the same transition by forcing the user |
---|
97 | * to get the previous handler before accepting to disconnect. |
---|
98 | */ |
---|
99 | if (memcmp(mpc5xx_get_vector_addr(except->exceptIndex), (void*)default_raw_except_entry.hdl.raw_hdl,default_raw_except_entry.hdl.raw_hdl_size)) { |
---|
100 | return 0; |
---|
101 | } |
---|
102 | |
---|
103 | _CPU_ISR_Disable(level); |
---|
104 | |
---|
105 | raw_except_table [except->exceptIndex] = *except; |
---|
106 | codemove((void*)mpc5xx_get_vector_addr(except->exceptIndex), |
---|
107 | except->hdl.raw_hdl, |
---|
108 | except->hdl.raw_hdl_size, |
---|
109 | PPC_CACHE_ALIGNMENT); |
---|
110 | except->on(except); |
---|
111 | |
---|
112 | _CPU_ISR_Enable(level); |
---|
113 | return 1; |
---|
114 | } |
---|
115 | |
---|
116 | int mpc5xx_get_current_exception (rtems_raw_except_connect_data* except) |
---|
117 | { |
---|
118 | if (!mpc5xx_vector_is_valid(except->exceptIndex)){ |
---|
119 | return 0; |
---|
120 | } |
---|
121 | |
---|
122 | *except = raw_except_table [except->exceptIndex]; |
---|
123 | |
---|
124 | return 1; |
---|
125 | } |
---|
126 | |
---|
127 | int mpc5xx_delete_exception (const rtems_raw_except_connect_data* except) |
---|
128 | { |
---|
129 | unsigned int level; |
---|
130 | |
---|
131 | if (!mpc5xx_vector_is_valid(except->exceptIndex)){ |
---|
132 | return 0; |
---|
133 | } |
---|
134 | /* |
---|
135 | * Check if handler passed is actually connected. If not issue an error. |
---|
136 | * You must first get the current handler via mpc5xx_get_current_exception |
---|
137 | * and then disconnect it using mpc5xx_delete_exception. |
---|
138 | * RATIONALE : to always have the same transition by forcing the user |
---|
139 | * to get the previous handler before accepting to disconnect. |
---|
140 | */ |
---|
141 | if (memcmp(mpc5xx_get_vector_addr(except->exceptIndex), |
---|
142 | (void*)except->hdl.raw_hdl, |
---|
143 | except->hdl.raw_hdl_size)) { |
---|
144 | return 0; |
---|
145 | } |
---|
146 | _CPU_ISR_Disable(level); |
---|
147 | |
---|
148 | except->off(except); |
---|
149 | codemove((void*)mpc5xx_get_vector_addr(except->exceptIndex), |
---|
150 | default_raw_except_entry.hdl.raw_hdl, |
---|
151 | default_raw_except_entry.hdl.raw_hdl_size, |
---|
152 | PPC_CACHE_ALIGNMENT); |
---|
153 | |
---|
154 | |
---|
155 | raw_except_table[except->exceptIndex] = default_raw_except_entry; |
---|
156 | raw_except_table[except->exceptIndex].exceptIndex = except->exceptIndex; |
---|
157 | |
---|
158 | _CPU_ISR_Enable(level); |
---|
159 | |
---|
160 | return 1; |
---|
161 | } |
---|
162 | |
---|
163 | /* |
---|
164 | * Exception global init. |
---|
165 | */ |
---|
166 | int mpc5xx_init_exceptions (rtems_raw_except_global_settings* config) |
---|
167 | { |
---|
168 | unsigned i; |
---|
169 | unsigned int level; |
---|
170 | |
---|
171 | /* |
---|
172 | * store various accelerators |
---|
173 | */ |
---|
174 | raw_except_table = config->rawExceptHdlTbl; |
---|
175 | local_settings = config; |
---|
176 | default_raw_except_entry = config->defaultRawEntry; |
---|
177 | |
---|
178 | _CPU_ISR_Disable(level); |
---|
179 | |
---|
180 | for (i=0; i <= LAST_VALID_EXC; i++) { |
---|
181 | if (!mpc5xx_vector_is_valid(i)){ |
---|
182 | continue; |
---|
183 | } |
---|
184 | codemove((void*)mpc5xx_get_vector_addr(i), |
---|
185 | raw_except_table[i].hdl.raw_hdl, |
---|
186 | raw_except_table[i].hdl.raw_hdl_size, |
---|
187 | PPC_CACHE_ALIGNMENT); |
---|
188 | if (raw_except_table[i].hdl.raw_hdl != default_raw_except_entry.hdl.raw_hdl) { |
---|
189 | raw_except_table[i].on(&raw_except_table[i]); |
---|
190 | } |
---|
191 | else { |
---|
192 | raw_except_table[i].off(&raw_except_table[i]); |
---|
193 | } |
---|
194 | } |
---|
195 | _CPU_ISR_Enable(level); |
---|
196 | |
---|
197 | return 1; |
---|
198 | } |
---|
199 | |
---|
200 | int mpc5xx_get_exception_config (rtems_raw_except_global_settings** config) |
---|
201 | { |
---|
202 | *config = local_settings; |
---|
203 | return 1; |
---|
204 | } |
---|
205 | |
---|