1 | /* |
---|
2 | * PowerPC CPU Dependent Source |
---|
3 | * |
---|
4 | * Author: Andrew Bray <andy@i-cubed.demon.co.uk> |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1995 by i-cubed ltd. |
---|
7 | * |
---|
8 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
9 | * without any express or implied warranty: |
---|
10 | * permission to use, copy, modify, and distribute this file |
---|
11 | * for any purpose is hereby granted without fee, provided that |
---|
12 | * the above copyright notice and this notice appears in all |
---|
13 | * copies, and that the name of i-cubed limited not be used in |
---|
14 | * advertising or publicity pertaining to distribution of the |
---|
15 | * software without specific, written prior permission. |
---|
16 | * i-cubed limited makes no representations about the suitability |
---|
17 | * of this software for any purpose. |
---|
18 | * |
---|
19 | * Derived from c/src/exec/cpu/no_cpu/cpu.c: |
---|
20 | * |
---|
21 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
22 | * On-Line Applications Research Corporation (OAR). |
---|
23 | * All rights assigned to U.S. Government, 1994. |
---|
24 | * |
---|
25 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
26 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
27 | * notice must appear in all copies of this file and its derivatives. |
---|
28 | * |
---|
29 | */ |
---|
30 | |
---|
31 | #include <rtems/system.h> |
---|
32 | #include <rtems/score/isr.h> |
---|
33 | #include <rtems/score/context.h> |
---|
34 | #include <rtems/score/thread.h> |
---|
35 | #include <rtems/score/wkspace.h> |
---|
36 | |
---|
37 | /* |
---|
38 | * These are for testing purposes. |
---|
39 | */ |
---|
40 | /* |
---|
41 | #define Testing |
---|
42 | */ |
---|
43 | |
---|
44 | #ifdef Testing |
---|
45 | static unsigned32 msr; |
---|
46 | #ifdef ppc403 |
---|
47 | static unsigned32 evpr; |
---|
48 | static unsigned32 exier; |
---|
49 | #endif |
---|
50 | #endif |
---|
51 | |
---|
52 | /* |
---|
53 | * ppc_interrupt_level_to_msr |
---|
54 | * |
---|
55 | * This routine converts a two bit interrupt level to an MSR bit map. |
---|
56 | */ |
---|
57 | |
---|
58 | const unsigned32 _CPU_msrs[4] = |
---|
59 | { PPC_MSR_0, PPC_MSR_1, PPC_MSR_2, PPC_MSR_3 }; |
---|
60 | |
---|
61 | /* _CPU_Initialize |
---|
62 | * |
---|
63 | * This routine performs processor dependent initialization. |
---|
64 | * |
---|
65 | * INPUT PARAMETERS: |
---|
66 | * cpu_table - CPU table to initialize |
---|
67 | * thread_dispatch - address of disptaching routine |
---|
68 | */ |
---|
69 | |
---|
70 | static void ppc_spurious(int, CPU_Interrupt_frame *); |
---|
71 | |
---|
72 | void _CPU_Initialize( |
---|
73 | rtems_cpu_table *cpu_table, |
---|
74 | void (*thread_dispatch) /* ignored on this CPU */ |
---|
75 | ) |
---|
76 | { |
---|
77 | proc_ptr handler = (proc_ptr)ppc_spurious; |
---|
78 | int i; |
---|
79 | #if (PPC_ABI != PPC_ABI_POWEROPEN) |
---|
80 | register unsigned32 r2; |
---|
81 | #if (PPC_ABI != PPC_ABI_GCC27) |
---|
82 | register unsigned32 r13; |
---|
83 | |
---|
84 | asm ("mr %0,13" : "=r" ((r13)) : "0" ((r13))); |
---|
85 | _CPU_IRQ_info.Default_r13 = r13; |
---|
86 | #endif |
---|
87 | |
---|
88 | asm ("mr %0,2" : "=r" ((r2)) : "0" ((r2))); |
---|
89 | _CPU_IRQ_info.Default_r2 = r2; |
---|
90 | #endif |
---|
91 | |
---|
92 | _CPU_IRQ_info.Nest_level = &_ISR_Nest_level; |
---|
93 | _CPU_IRQ_info.Disable_level = &_Thread_Dispatch_disable_level; |
---|
94 | _CPU_IRQ_info.Vector_table = _ISR_Vector_table; |
---|
95 | #if (PPC_ABI == PPC_ABI_POWEROPEN) |
---|
96 | _CPU_IRQ_info.Dispatch_r2 = ((unsigned32 *)_Thread_Dispatch)[1]; |
---|
97 | #endif |
---|
98 | _CPU_IRQ_info.Switch_necessary = &_Context_Switch_necessary; |
---|
99 | _CPU_IRQ_info.Signal = &_ISR_Signals_to_thread_executing; |
---|
100 | |
---|
101 | i = (int)&_CPU_IRQ_info; |
---|
102 | asm volatile("mtsprg3 %0" : "=r" (i) : "0" (i)); |
---|
103 | |
---|
104 | i = PPC_MSR_INITIAL & ~PPC_MSR_DISABLE_MASK; |
---|
105 | asm volatile("mtsprg2 %0" : "=r" (i) : "0" (i)); |
---|
106 | |
---|
107 | #ifdef Testing |
---|
108 | { |
---|
109 | unsigned32 tmp; |
---|
110 | |
---|
111 | asm volatile ("mfmsr %0" : "=r" (tmp)); |
---|
112 | msr = tmp; |
---|
113 | #ifdef ppc403 |
---|
114 | asm volatile ("mfevpr %0" : "=r" (tmp)); |
---|
115 | evpr = tmp; |
---|
116 | asm volatile ("mfexier %0" : "=r" (tmp)); |
---|
117 | exier = tmp; |
---|
118 | asm volatile ("mtevpr %0" :: "r" (0)); |
---|
119 | #endif |
---|
120 | } |
---|
121 | #endif |
---|
122 | |
---|
123 | if ( cpu_table->spurious_handler ) |
---|
124 | handler = (proc_ptr)cpu_table->spurious_handler; |
---|
125 | |
---|
126 | for (i = 0; i < PPC_INTERRUPT_MAX; i++) |
---|
127 | _ISR_Vector_table[i] = handler; |
---|
128 | |
---|
129 | _CPU_Table = *cpu_table; |
---|
130 | } |
---|
131 | |
---|
132 | /* _CPU_ISR_install_vector |
---|
133 | * |
---|
134 | * This kernel routine installs the RTEMS handler for the |
---|
135 | * specified vector. |
---|
136 | * |
---|
137 | * Input parameters: |
---|
138 | * vector - interrupt vector number |
---|
139 | * old_handler - former ISR for this vector number |
---|
140 | * new_handler - replacement ISR for this vector number |
---|
141 | * |
---|
142 | * Output parameters: NONE |
---|
143 | * |
---|
144 | */ |
---|
145 | |
---|
146 | void _CPU_ISR_install_vector( |
---|
147 | unsigned32 vector, |
---|
148 | proc_ptr new_handler, |
---|
149 | proc_ptr *old_handler |
---|
150 | ) |
---|
151 | { |
---|
152 | *old_handler = _ISR_Vector_table[ vector ]; |
---|
153 | |
---|
154 | /* |
---|
155 | * If the interrupt vector table is a table of pointer to isr entry |
---|
156 | * points, then we need to install the appropriate RTEMS interrupt |
---|
157 | * handler for this vector number. |
---|
158 | */ |
---|
159 | |
---|
160 | /* |
---|
161 | * We put the actual user ISR address in '_ISR_vector_table'. This will |
---|
162 | * be used by the _ISR_Handler so the user gets control. |
---|
163 | */ |
---|
164 | |
---|
165 | _ISR_Vector_table[ vector ] = |
---|
166 | (new_handler) ? (ISR_Handler_entry) new_handler : |
---|
167 | ((_CPU_Table.spurious_handler) ? |
---|
168 | (ISR_Handler_entry) _CPU_Table.spurious_handler : |
---|
169 | (ISR_Handler_entry) ppc_spurious); |
---|
170 | } |
---|
171 | |
---|
172 | /*PAGE |
---|
173 | * |
---|
174 | * _CPU_Install_interrupt_stack |
---|
175 | */ |
---|
176 | |
---|
177 | void _CPU_Install_interrupt_stack( void ) |
---|
178 | { |
---|
179 | #if (PPC_ABI == PPC_ABI_POWEROPEN || PPC_ABI == PPC_ABI_GCC27) |
---|
180 | _CPU_IRQ_info.Stack = _CPU_Interrupt_stack_high - 56; |
---|
181 | #else |
---|
182 | _CPU_IRQ_info.Stack = _CPU_Interrupt_stack_high - 8; |
---|
183 | #endif |
---|
184 | } |
---|
185 | |
---|
186 | /* Handle a spurious interrupt */ |
---|
187 | static void ppc_spurious(int v, CPU_Interrupt_frame *i) |
---|
188 | { |
---|
189 | #if 0 |
---|
190 | printf("Spurious interrupt on vector %d from %08.8x\n", |
---|
191 | v, i->pc); |
---|
192 | #endif |
---|
193 | #ifdef ppc403 |
---|
194 | if (v == PPC_IRQ_EXTERNAL) |
---|
195 | { |
---|
196 | register int r = 0; |
---|
197 | |
---|
198 | asm volatile("mtexier %0" : "=r" ((r)) : "0" ((r))); |
---|
199 | } |
---|
200 | else if (v == PPC_IRQ_PIT) |
---|
201 | { |
---|
202 | register int r = 0x08000000; |
---|
203 | |
---|
204 | asm volatile("mttsr %0" : "=r" ((r)) : "0" ((r))); |
---|
205 | } |
---|
206 | else if (v == PPC_IRQ_FIT) |
---|
207 | { |
---|
208 | register int r = 0x04000000; |
---|
209 | |
---|
210 | asm volatile("mttsr %0" : "=r" ((r)) : "0" ((r))); |
---|
211 | } |
---|
212 | #endif |
---|
213 | } |
---|
214 | |
---|
215 | void _CPU_Fatal_error(unsigned32 _error) |
---|
216 | { |
---|
217 | #ifdef Testing |
---|
218 | unsigned32 tmp; |
---|
219 | |
---|
220 | tmp = msr; |
---|
221 | asm volatile ("mtmsr %0" :: "r" (tmp)); |
---|
222 | #ifdef ppc403 |
---|
223 | tmp = evpr; |
---|
224 | asm volatile ("mtevpr %0" :: "r" (tmp)); |
---|
225 | tmp = exier; |
---|
226 | asm volatile ("mtexier %0" :: "r" (tmp)); |
---|
227 | #endif |
---|
228 | #endif |
---|
229 | asm volatile ("mr 3, %0" : : "r" ((_error))); |
---|
230 | asm volatile ("tweq 5,5"); |
---|
231 | asm volatile ("li 0,0; mtmsr 0"); |
---|
232 | while (1) ; |
---|
233 | } |
---|