Commit | Line | Data |
---|---|---|
14cf11af | 1 | /* |
14cf11af PM |
2 | * PowerPC version |
3 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) | |
4 | * | |
5 | * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP | |
6 | * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu> | |
7 | * Adapted for Power Macintosh by Paul Mackerras. | |
8 | * Low-level exception handlers and MMU support | |
9 | * rewritten by Paul Mackerras. | |
10 | * Copyright (C) 1996 Paul Mackerras. | |
11 | * | |
12 | * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and | |
13 | * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com | |
14 | * | |
15 | * This file contains the low-level support and setup for the | |
16 | * PowerPC-64 platform, including trap and interrupt dispatch. | |
17 | * | |
18 | * This program is free software; you can redistribute it and/or | |
19 | * modify it under the terms of the GNU General Public License | |
20 | * as published by the Free Software Foundation; either version | |
21 | * 2 of the License, or (at your option) any later version. | |
22 | */ | |
23 | ||
14cf11af | 24 | #include <linux/threads.h> |
b5bbeb23 | 25 | #include <asm/reg.h> |
14cf11af PM |
26 | #include <asm/page.h> |
27 | #include <asm/mmu.h> | |
14cf11af PM |
28 | #include <asm/ppc_asm.h> |
29 | #include <asm/asm-offsets.h> | |
30 | #include <asm/bug.h> | |
31 | #include <asm/cputable.h> | |
32 | #include <asm/setup.h> | |
33 | #include <asm/hvcall.h> | |
c43a55ff | 34 | #include <asm/iseries/lpar_map.h> |
6cb7bfeb | 35 | #include <asm/thread_info.h> |
3f639ee8 | 36 | #include <asm/firmware.h> |
16a15a30 | 37 | #include <asm/page_64.h> |
f9ff0f30 | 38 | #include <asm/exception.h> |
945feb17 | 39 | #include <asm/irqflags.h> |
14cf11af PM |
40 | |
41 | /* | |
42 | * We layout physical memory as follows: | |
43 | * 0x0000 - 0x00ff : Secondary processor spin code | |
44 | * 0x0100 - 0x2fff : pSeries Interrupt prologs | |
45 | * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs | |
46 | * 0x6000 - 0x6fff : Initial (CPU0) segment table | |
47 | * 0x7000 - 0x7fff : FWNMI data area | |
48 | * 0x8000 - : Early init and support code | |
49 | */ | |
50 | ||
51 | /* | |
52 | * SPRG Usage | |
53 | * | |
54 | * Register Definition | |
55 | * | |
56 | * SPRG0 reserved for hypervisor | |
57 | * SPRG1 temp - used to save gpr | |
58 | * SPRG2 temp - used to save gpr | |
59 | * SPRG3 virt addr of paca | |
60 | */ | |
61 | ||
62 | /* | |
63 | * Entering into this code we make the following assumptions: | |
64 | * For pSeries: | |
65 | * 1. The MMU is off & open firmware is running in real mode. | |
66 | * 2. The kernel is entered at __start | |
67 | * | |
68 | * For iSeries: | |
69 | * 1. The MMU is on (as it always is for iSeries) | |
70 | * 2. The kernel is entered at system_reset_iSeries | |
71 | */ | |
72 | ||
73 | .text | |
74 | .globl _stext | |
75 | _stext: | |
14cf11af PM |
76 | _GLOBAL(__start) |
77 | /* NOP this out unconditionally */ | |
78 | BEGIN_FTR_SECTION | |
b85a046a | 79 | b .__start_initialization_multiplatform |
14cf11af | 80 | END_FTR_SECTION(0, 1) |
14cf11af PM |
81 | |
82 | /* Catch branch to 0 in real mode */ | |
83 | trap | |
84 | ||
1f6a93e4 PM |
85 | /* Secondary processors spin on this value until it becomes nonzero. |
86 | * When it does it contains the real address of the descriptor | |
87 | * of the function that the cpu should jump to to continue | |
88 | * initialization. | |
89 | */ | |
14cf11af PM |
90 | .globl __secondary_hold_spinloop |
91 | __secondary_hold_spinloop: | |
92 | .llong 0x0 | |
93 | ||
94 | /* Secondary processors write this value with their cpu # */ | |
95 | /* after they enter the spin loop immediately below. */ | |
96 | .globl __secondary_hold_acknowledge | |
97 | __secondary_hold_acknowledge: | |
98 | .llong 0x0 | |
99 | ||
1dce0e30 ME |
100 | #ifdef CONFIG_PPC_ISERIES |
101 | /* | |
102 | * At offset 0x20, there is a pointer to iSeries LPAR data. | |
103 | * This is required by the hypervisor | |
104 | */ | |
105 | . = 0x20 | |
106 | .llong hvReleaseData-KERNELBASE | |
107 | #endif /* CONFIG_PPC_ISERIES */ | |
108 | ||
8b8b0cc1 MM |
109 | #ifdef CONFIG_CRASH_DUMP |
110 | /* This flag is set to 1 by a loader if the kernel should run | |
111 | * at the loaded address instead of the linked address. This | |
112 | * is used by kexec-tools to keep the the kdump kernel in the | |
113 | * crash_kernel region. The loader is responsible for | |
114 | * observing the alignment requirement. | |
115 | */ | |
116 | /* Do not move this variable as kexec-tools knows about it. */ | |
117 | . = 0x5c | |
118 | .globl __run_at_load | |
119 | __run_at_load: | |
120 | .long 0x72756e30 /* "run0" -- relocate to 0 by default */ | |
121 | #endif | |
122 | ||
14cf11af PM |
123 | . = 0x60 |
124 | /* | |
75423b7b GL |
125 | * The following code is used to hold secondary processors |
126 | * in a spin loop after they have entered the kernel, but | |
14cf11af PM |
127 | * before the bulk of the kernel has been relocated. This code |
128 | * is relocated to physical address 0x60 before prom_init is run. | |
129 | * All of it must fit below the first exception vector at 0x100. | |
1f6a93e4 PM |
130 | * Use .globl here not _GLOBAL because we want __secondary_hold |
131 | * to be the actual text address, not a descriptor. | |
14cf11af | 132 | */ |
1f6a93e4 PM |
133 | .globl __secondary_hold |
134 | __secondary_hold: | |
14cf11af PM |
135 | mfmsr r24 |
136 | ori r24,r24,MSR_RI | |
137 | mtmsrd r24 /* RI on */ | |
138 | ||
f1870f77 | 139 | /* Grab our physical cpu number */ |
14cf11af PM |
140 | mr r24,r3 |
141 | ||
142 | /* Tell the master cpu we're here */ | |
143 | /* Relocation is off & we are located at an address less */ | |
144 | /* than 0x100, so only need to grab low order offset. */ | |
e31aa453 | 145 | std r24,__secondary_hold_acknowledge-_stext(0) |
14cf11af PM |
146 | sync |
147 | ||
148 | /* All secondary cpus wait here until told to start. */ | |
e31aa453 | 149 | 100: ld r4,__secondary_hold_spinloop-_stext(0) |
1f6a93e4 PM |
150 | cmpdi 0,r4,0 |
151 | beq 100b | |
14cf11af | 152 | |
f1870f77 | 153 | #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC) |
1f6a93e4 | 154 | ld r4,0(r4) /* deref function descriptor */ |
758438a7 | 155 | mtctr r4 |
14cf11af | 156 | mr r3,r24 |
758438a7 | 157 | bctr |
14cf11af PM |
158 | #else |
159 | BUG_OPCODE | |
160 | #endif | |
14cf11af PM |
161 | |
162 | /* This value is used to mark exception frames on the stack. */ | |
163 | .section ".toc","aw" | |
164 | exception_marker: | |
165 | .tc ID_72656773_68657265[TC],0x7265677368657265 | |
166 | .text | |
167 | ||
14cf11af PM |
168 | /* |
169 | * This is the start of the interrupt handlers for pSeries | |
170 | * This code runs with relocation off. | |
1f6a93e4 PM |
171 | * Code from here to __end_interrupts gets copied down to real |
172 | * address 0x100 when we are running a relocatable kernel. | |
173 | * Therefore any relative branches in this section must only | |
174 | * branch to labels in this section. | |
14cf11af PM |
175 | */ |
176 | . = 0x100 | |
177 | .globl __start_interrupts | |
178 | __start_interrupts: | |
179 | ||
180 | STD_EXCEPTION_PSERIES(0x100, system_reset) | |
181 | ||
182 | . = 0x200 | |
183 | _machine_check_pSeries: | |
184 | HMT_MEDIUM | |
b5bbeb23 | 185 | mtspr SPRN_SPRG1,r13 /* save r13 */ |
14cf11af PM |
186 | EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common) |
187 | ||
188 | . = 0x300 | |
189 | .globl data_access_pSeries | |
190 | data_access_pSeries: | |
191 | HMT_MEDIUM | |
b5bbeb23 | 192 | mtspr SPRN_SPRG1,r13 |
14cf11af | 193 | BEGIN_FTR_SECTION |
b5bbeb23 PM |
194 | mtspr SPRN_SPRG2,r12 |
195 | mfspr r13,SPRN_DAR | |
196 | mfspr r12,SPRN_DSISR | |
14cf11af PM |
197 | srdi r13,r13,60 |
198 | rlwimi r13,r12,16,0x20 | |
199 | mfcr r12 | |
200 | cmpwi r13,0x2c | |
3ccfc65c | 201 | beq do_stab_bolted_pSeries |
14cf11af | 202 | mtcrf 0x80,r12 |
b5bbeb23 | 203 | mfspr r12,SPRN_SPRG2 |
14cf11af PM |
204 | END_FTR_SECTION_IFCLR(CPU_FTR_SLB) |
205 | EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common) | |
206 | ||
207 | . = 0x380 | |
208 | .globl data_access_slb_pSeries | |
209 | data_access_slb_pSeries: | |
210 | HMT_MEDIUM | |
b5bbeb23 | 211 | mtspr SPRN_SPRG1,r13 |
b5bbeb23 | 212 | mfspr r13,SPRN_SPRG3 /* get paca address into r13 */ |
3c726f8d BH |
213 | std r3,PACA_EXSLB+EX_R3(r13) |
214 | mfspr r3,SPRN_DAR | |
14cf11af | 215 | std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */ |
3c726f8d BH |
216 | mfcr r9 |
217 | #ifdef __DISABLED__ | |
218 | /* Keep that around for when we re-implement dynamic VSIDs */ | |
219 | cmpdi r3,0 | |
220 | bge slb_miss_user_pseries | |
221 | #endif /* __DISABLED__ */ | |
14cf11af PM |
222 | std r10,PACA_EXSLB+EX_R10(r13) |
223 | std r11,PACA_EXSLB+EX_R11(r13) | |
224 | std r12,PACA_EXSLB+EX_R12(r13) | |
3c726f8d BH |
225 | mfspr r10,SPRN_SPRG1 |
226 | std r10,PACA_EXSLB+EX_R13(r13) | |
b5bbeb23 | 227 | mfspr r12,SPRN_SRR1 /* and SRR1 */ |
1f6a93e4 PM |
228 | #ifndef CONFIG_RELOCATABLE |
229 | b .slb_miss_realmode | |
230 | #else | |
231 | /* | |
232 | * We can't just use a direct branch to .slb_miss_realmode | |
233 | * because the distance from here to there depends on where | |
234 | * the kernel ends up being put. | |
235 | */ | |
236 | mfctr r11 | |
237 | ld r10,PACAKBASE(r13) | |
238 | LOAD_HANDLER(r10, .slb_miss_realmode) | |
239 | mtctr r10 | |
240 | bctr | |
241 | #endif | |
14cf11af PM |
242 | |
243 | STD_EXCEPTION_PSERIES(0x400, instruction_access) | |
244 | ||
245 | . = 0x480 | |
246 | .globl instruction_access_slb_pSeries | |
247 | instruction_access_slb_pSeries: | |
248 | HMT_MEDIUM | |
b5bbeb23 | 249 | mtspr SPRN_SPRG1,r13 |
b5bbeb23 | 250 | mfspr r13,SPRN_SPRG3 /* get paca address into r13 */ |
3c726f8d BH |
251 | std r3,PACA_EXSLB+EX_R3(r13) |
252 | mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */ | |
14cf11af | 253 | std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */ |
3c726f8d BH |
254 | mfcr r9 |
255 | #ifdef __DISABLED__ | |
256 | /* Keep that around for when we re-implement dynamic VSIDs */ | |
257 | cmpdi r3,0 | |
258 | bge slb_miss_user_pseries | |
259 | #endif /* __DISABLED__ */ | |
14cf11af PM |
260 | std r10,PACA_EXSLB+EX_R10(r13) |
261 | std r11,PACA_EXSLB+EX_R11(r13) | |
262 | std r12,PACA_EXSLB+EX_R12(r13) | |
3c726f8d BH |
263 | mfspr r10,SPRN_SPRG1 |
264 | std r10,PACA_EXSLB+EX_R13(r13) | |
b5bbeb23 | 265 | mfspr r12,SPRN_SRR1 /* and SRR1 */ |
1f6a93e4 PM |
266 | #ifndef CONFIG_RELOCATABLE |
267 | b .slb_miss_realmode | |
268 | #else | |
269 | mfctr r11 | |
270 | ld r10,PACAKBASE(r13) | |
271 | LOAD_HANDLER(r10, .slb_miss_realmode) | |
272 | mtctr r10 | |
273 | bctr | |
274 | #endif | |
14cf11af | 275 | |
d04c56f7 | 276 | MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt) |
14cf11af PM |
277 | STD_EXCEPTION_PSERIES(0x600, alignment) |
278 | STD_EXCEPTION_PSERIES(0x700, program_check) | |
279 | STD_EXCEPTION_PSERIES(0x800, fp_unavailable) | |
d04c56f7 | 280 | MASKABLE_EXCEPTION_PSERIES(0x900, decrementer) |
14cf11af PM |
281 | STD_EXCEPTION_PSERIES(0xa00, trap_0a) |
282 | STD_EXCEPTION_PSERIES(0xb00, trap_0b) | |
283 | ||
284 | . = 0xc00 | |
285 | .globl system_call_pSeries | |
286 | system_call_pSeries: | |
287 | HMT_MEDIUM | |
745a14cc PM |
288 | BEGIN_FTR_SECTION |
289 | cmpdi r0,0x1ebe | |
290 | beq- 1f | |
291 | END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) | |
14cf11af | 292 | mr r9,r13 |
b5bbeb23 PM |
293 | mfspr r13,SPRN_SPRG3 |
294 | mfspr r11,SPRN_SRR0 | |
1f6a93e4 PM |
295 | ld r12,PACAKBASE(r13) |
296 | ld r10,PACAKMSR(r13) | |
297 | LOAD_HANDLER(r12, system_call_entry) | |
b5bbeb23 | 298 | mtspr SPRN_SRR0,r12 |
b5bbeb23 PM |
299 | mfspr r12,SPRN_SRR1 |
300 | mtspr SPRN_SRR1,r10 | |
14cf11af PM |
301 | rfid |
302 | b . /* prevent speculative execution */ | |
303 | ||
745a14cc PM |
304 | /* Fast LE/BE switch system call */ |
305 | 1: mfspr r12,SPRN_SRR1 | |
306 | xori r12,r12,MSR_LE | |
307 | mtspr SPRN_SRR1,r12 | |
308 | rfid /* return to userspace */ | |
309 | b . | |
310 | ||
14cf11af PM |
311 | STD_EXCEPTION_PSERIES(0xd00, single_step) |
312 | STD_EXCEPTION_PSERIES(0xe00, trap_0e) | |
313 | ||
314 | /* We need to deal with the Altivec unavailable exception | |
315 | * here which is at 0xf20, thus in the middle of the | |
316 | * prolog code of the PerformanceMonitor one. A little | |
317 | * trickery is thus necessary | |
318 | */ | |
319 | . = 0xf00 | |
320 | b performance_monitor_pSeries | |
321 | ||
10e34392 MN |
322 | . = 0xf20 |
323 | b altivec_unavailable_pSeries | |
14cf11af | 324 | |
ce48b210 MN |
325 | . = 0xf40 |
326 | b vsx_unavailable_pSeries | |
327 | ||
acf7d768 BH |
328 | #ifdef CONFIG_CBE_RAS |
329 | HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error) | |
330 | #endif /* CONFIG_CBE_RAS */ | |
14cf11af | 331 | STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint) |
acf7d768 BH |
332 | #ifdef CONFIG_CBE_RAS |
333 | HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance) | |
334 | #endif /* CONFIG_CBE_RAS */ | |
14cf11af | 335 | STD_EXCEPTION_PSERIES(0x1700, altivec_assist) |
acf7d768 BH |
336 | #ifdef CONFIG_CBE_RAS |
337 | HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal) | |
338 | #endif /* CONFIG_CBE_RAS */ | |
14cf11af PM |
339 | |
340 | . = 0x3000 | |
341 | ||
342 | /*** pSeries interrupt support ***/ | |
343 | ||
344 | /* moved from 0xf00 */ | |
449d846d | 345 | STD_EXCEPTION_PSERIES(., performance_monitor) |
10e34392 | 346 | STD_EXCEPTION_PSERIES(., altivec_unavailable) |
ce48b210 | 347 | STD_EXCEPTION_PSERIES(., vsx_unavailable) |
d04c56f7 PM |
348 | |
349 | /* | |
350 | * An interrupt came in while soft-disabled; clear EE in SRR1, | |
351 | * clear paca->hard_enabled and return. | |
352 | */ | |
353 | masked_interrupt: | |
354 | stb r10,PACAHARDIRQEN(r13) | |
355 | mtcrf 0x80,r9 | |
356 | ld r9,PACA_EXGEN+EX_R9(r13) | |
357 | mfspr r10,SPRN_SRR1 | |
358 | rldicl r10,r10,48,1 /* clear MSR_EE */ | |
359 | rotldi r10,r10,16 | |
360 | mtspr SPRN_SRR1,r10 | |
361 | ld r10,PACA_EXGEN+EX_R10(r13) | |
362 | mfspr r13,SPRN_SPRG1 | |
363 | rfid | |
364 | b . | |
14cf11af PM |
365 | |
366 | .align 7 | |
3ccfc65c | 367 | do_stab_bolted_pSeries: |
14cf11af | 368 | mtcrf 0x80,r12 |
b5bbeb23 | 369 | mfspr r12,SPRN_SPRG2 |
14cf11af PM |
370 | EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted) |
371 | ||
9a955167 PM |
372 | #ifdef CONFIG_PPC_PSERIES |
373 | /* | |
374 | * Vectors for the FWNMI option. Share common code. | |
375 | */ | |
376 | .globl system_reset_fwnmi | |
377 | .align 7 | |
378 | system_reset_fwnmi: | |
379 | HMT_MEDIUM | |
380 | mtspr SPRN_SPRG1,r13 /* save r13 */ | |
381 | EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common) | |
382 | ||
383 | .globl machine_check_fwnmi | |
384 | .align 7 | |
385 | machine_check_fwnmi: | |
386 | HMT_MEDIUM | |
387 | mtspr SPRN_SPRG1,r13 /* save r13 */ | |
388 | EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common) | |
389 | ||
390 | #endif /* CONFIG_PPC_PSERIES */ | |
391 | ||
392 | #ifdef __DISABLED__ | |
3c726f8d | 393 | /* |
3c726f8d BH |
394 | * This is used for when the SLB miss handler has to go virtual, |
395 | * which doesn't happen for now anymore but will once we re-implement | |
396 | * dynamic VSIDs for shared page tables | |
397 | */ | |
3c726f8d BH |
398 | slb_miss_user_pseries: |
399 | std r10,PACA_EXGEN+EX_R10(r13) | |
400 | std r11,PACA_EXGEN+EX_R11(r13) | |
401 | std r12,PACA_EXGEN+EX_R12(r13) | |
402 | mfspr r10,SPRG1 | |
403 | ld r11,PACA_EXSLB+EX_R9(r13) | |
404 | ld r12,PACA_EXSLB+EX_R3(r13) | |
405 | std r10,PACA_EXGEN+EX_R13(r13) | |
406 | std r11,PACA_EXGEN+EX_R9(r13) | |
407 | std r12,PACA_EXGEN+EX_R3(r13) | |
408 | clrrdi r12,r13,32 | |
409 | mfmsr r10 | |
410 | mfspr r11,SRR0 /* save SRR0 */ | |
411 | ori r12,r12,slb_miss_user_common@l /* virt addr of handler */ | |
412 | ori r10,r10,MSR_IR|MSR_DR|MSR_RI | |
413 | mtspr SRR0,r12 | |
414 | mfspr r12,SRR1 /* and SRR1 */ | |
415 | mtspr SRR1,r10 | |
416 | rfid | |
417 | b . /* prevent spec. execution */ | |
418 | #endif /* __DISABLED__ */ | |
419 | ||
9a955167 PM |
420 | .align 7 |
421 | .globl __end_interrupts | |
422 | __end_interrupts: | |
423 | ||
14cf11af | 424 | /* |
9a955167 | 425 | * Code from here down to __end_handlers is invoked from the |
1f6a93e4 PM |
426 | * exception prologs above. Because the prologs assemble the |
427 | * addresses of these handlers using the LOAD_HANDLER macro, | |
428 | * which uses an addi instruction, these handlers must be in | |
429 | * the first 32k of the kernel image. | |
14cf11af | 430 | */ |
9e4859ef | 431 | |
14cf11af PM |
432 | /*** Common interrupt handlers ***/ |
433 | ||
434 | STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception) | |
435 | ||
436 | /* | |
437 | * Machine check is different because we use a different | |
438 | * save area: PACA_EXMC instead of PACA_EXGEN. | |
439 | */ | |
440 | .align 7 | |
441 | .globl machine_check_common | |
442 | machine_check_common: | |
443 | EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC) | |
f39224a8 | 444 | FINISH_NAP |
14cf11af PM |
445 | DISABLE_INTS |
446 | bl .save_nvgprs | |
447 | addi r3,r1,STACK_FRAME_OVERHEAD | |
448 | bl .machine_check_exception | |
449 | b .ret_from_except | |
450 | ||
451 | STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt) | |
452 | STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception) | |
453 | STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception) | |
454 | STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception) | |
455 | STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception) | |
f39224a8 | 456 | STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception) |
14cf11af PM |
457 | STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception) |
458 | #ifdef CONFIG_ALTIVEC | |
459 | STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception) | |
460 | #else | |
461 | STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception) | |
462 | #endif | |
acf7d768 BH |
463 | #ifdef CONFIG_CBE_RAS |
464 | STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception) | |
465 | STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception) | |
466 | STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception) | |
467 | #endif /* CONFIG_CBE_RAS */ | |
14cf11af | 468 | |
1f6a93e4 PM |
469 | .align 7 |
470 | system_call_entry: | |
471 | b system_call_common | |
472 | ||
14cf11af PM |
473 | /* |
474 | * Here we have detected that the kernel stack pointer is bad. | |
475 | * R9 contains the saved CR, r13 points to the paca, | |
476 | * r10 contains the (bad) kernel stack pointer, | |
477 | * r11 and r12 contain the saved SRR0 and SRR1. | |
478 | * We switch to using an emergency stack, save the registers there, | |
479 | * and call kernel_bad_stack(), which panics. | |
480 | */ | |
481 | bad_stack: | |
482 | ld r1,PACAEMERGSP(r13) | |
483 | subi r1,r1,64+INT_FRAME_SIZE | |
484 | std r9,_CCR(r1) | |
485 | std r10,GPR1(r1) | |
486 | std r11,_NIP(r1) | |
487 | std r12,_MSR(r1) | |
b5bbeb23 PM |
488 | mfspr r11,SPRN_DAR |
489 | mfspr r12,SPRN_DSISR | |
14cf11af PM |
490 | std r11,_DAR(r1) |
491 | std r12,_DSISR(r1) | |
492 | mflr r10 | |
493 | mfctr r11 | |
494 | mfxer r12 | |
495 | std r10,_LINK(r1) | |
496 | std r11,_CTR(r1) | |
497 | std r12,_XER(r1) | |
498 | SAVE_GPR(0,r1) | |
499 | SAVE_GPR(2,r1) | |
500 | SAVE_4GPRS(3,r1) | |
501 | SAVE_2GPRS(7,r1) | |
502 | SAVE_10GPRS(12,r1) | |
503 | SAVE_10GPRS(22,r1) | |
68730401 OJ |
504 | lhz r12,PACA_TRAP_SAVE(r13) |
505 | std r12,_TRAP(r1) | |
14cf11af PM |
506 | addi r11,r1,INT_FRAME_SIZE |
507 | std r11,0(r1) | |
508 | li r12,0 | |
509 | std r12,0(r11) | |
510 | ld r2,PACATOC(r13) | |
511 | 1: addi r3,r1,STACK_FRAME_OVERHEAD | |
512 | bl .kernel_bad_stack | |
513 | b 1b | |
514 | ||
14cf11af PM |
515 | /* |
516 | * Here r13 points to the paca, r9 contains the saved CR, | |
517 | * SRR0 and SRR1 are saved in r11 and r12, | |
518 | * r9 - r13 are saved in paca->exgen. | |
519 | */ | |
520 | .align 7 | |
521 | .globl data_access_common | |
522 | data_access_common: | |
b5bbeb23 | 523 | mfspr r10,SPRN_DAR |
14cf11af | 524 | std r10,PACA_EXGEN+EX_DAR(r13) |
b5bbeb23 | 525 | mfspr r10,SPRN_DSISR |
14cf11af PM |
526 | stw r10,PACA_EXGEN+EX_DSISR(r13) |
527 | EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN) | |
528 | ld r3,PACA_EXGEN+EX_DAR(r13) | |
529 | lwz r4,PACA_EXGEN+EX_DSISR(r13) | |
530 | li r5,0x300 | |
531 | b .do_hash_page /* Try to handle as hpte fault */ | |
532 | ||
533 | .align 7 | |
534 | .globl instruction_access_common | |
535 | instruction_access_common: | |
536 | EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN) | |
537 | ld r3,_NIP(r1) | |
538 | andis. r4,r12,0x5820 | |
539 | li r5,0x400 | |
540 | b .do_hash_page /* Try to handle as hpte fault */ | |
541 | ||
3c726f8d BH |
542 | /* |
543 | * Here is the common SLB miss user that is used when going to virtual | |
544 | * mode for SLB misses, that is currently not used | |
545 | */ | |
546 | #ifdef __DISABLED__ | |
547 | .align 7 | |
548 | .globl slb_miss_user_common | |
549 | slb_miss_user_common: | |
550 | mflr r10 | |
551 | std r3,PACA_EXGEN+EX_DAR(r13) | |
552 | stw r9,PACA_EXGEN+EX_CCR(r13) | |
553 | std r10,PACA_EXGEN+EX_LR(r13) | |
554 | std r11,PACA_EXGEN+EX_SRR0(r13) | |
555 | bl .slb_allocate_user | |
556 | ||
557 | ld r10,PACA_EXGEN+EX_LR(r13) | |
558 | ld r3,PACA_EXGEN+EX_R3(r13) | |
559 | lwz r9,PACA_EXGEN+EX_CCR(r13) | |
560 | ld r11,PACA_EXGEN+EX_SRR0(r13) | |
561 | mtlr r10 | |
562 | beq- slb_miss_fault | |
563 | ||
564 | andi. r10,r12,MSR_RI /* check for unrecoverable exception */ | |
565 | beq- unrecov_user_slb | |
566 | mfmsr r10 | |
567 | ||
568 | .machine push | |
569 | .machine "power4" | |
570 | mtcrf 0x80,r9 | |
571 | .machine pop | |
572 | ||
573 | clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */ | |
574 | mtmsrd r10,1 | |
575 | ||
576 | mtspr SRR0,r11 | |
577 | mtspr SRR1,r12 | |
578 | ||
579 | ld r9,PACA_EXGEN+EX_R9(r13) | |
580 | ld r10,PACA_EXGEN+EX_R10(r13) | |
581 | ld r11,PACA_EXGEN+EX_R11(r13) | |
582 | ld r12,PACA_EXGEN+EX_R12(r13) | |
583 | ld r13,PACA_EXGEN+EX_R13(r13) | |
584 | rfid | |
585 | b . | |
586 | ||
587 | slb_miss_fault: | |
588 | EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN) | |
589 | ld r4,PACA_EXGEN+EX_DAR(r13) | |
590 | li r5,0 | |
591 | std r4,_DAR(r1) | |
592 | std r5,_DSISR(r1) | |
3ccfc65c | 593 | b handle_page_fault |
3c726f8d BH |
594 | |
595 | unrecov_user_slb: | |
596 | EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN) | |
597 | DISABLE_INTS | |
598 | bl .save_nvgprs | |
599 | 1: addi r3,r1,STACK_FRAME_OVERHEAD | |
600 | bl .unrecoverable_exception | |
601 | b 1b | |
602 | ||
603 | #endif /* __DISABLED__ */ | |
604 | ||
605 | ||
606 | /* | |
607 | * r13 points to the PACA, r9 contains the saved CR, | |
608 | * r12 contain the saved SRR1, SRR0 is still ready for return | |
609 | * r3 has the faulting address | |
610 | * r9 - r13 are saved in paca->exslb. | |
611 | * r3 is saved in paca->slb_r3 | |
612 | * We assume we aren't going to take any exceptions during this procedure. | |
613 | */ | |
614 | _GLOBAL(slb_miss_realmode) | |
615 | mflr r10 | |
1f6a93e4 PM |
616 | #ifdef CONFIG_RELOCATABLE |
617 | mtctr r11 | |
618 | #endif | |
3c726f8d BH |
619 | |
620 | stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */ | |
621 | std r10,PACA_EXSLB+EX_LR(r13) /* save LR */ | |
622 | ||
623 | bl .slb_allocate_realmode | |
624 | ||
625 | /* All done -- return from exception. */ | |
626 | ||
627 | ld r10,PACA_EXSLB+EX_LR(r13) | |
628 | ld r3,PACA_EXSLB+EX_R3(r13) | |
629 | lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */ | |
630 | #ifdef CONFIG_PPC_ISERIES | |
3f639ee8 | 631 | BEGIN_FW_FTR_SECTION |
3356bb9f DG |
632 | ld r11,PACALPPACAPTR(r13) |
633 | ld r11,LPPACASRR0(r11) /* get SRR0 value */ | |
3f639ee8 | 634 | END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES) |
3c726f8d BH |
635 | #endif /* CONFIG_PPC_ISERIES */ |
636 | ||
637 | mtlr r10 | |
638 | ||
639 | andi. r10,r12,MSR_RI /* check for unrecoverable exception */ | |
320787c7 | 640 | beq- 2f |
3c726f8d BH |
641 | |
642 | .machine push | |
643 | .machine "power4" | |
644 | mtcrf 0x80,r9 | |
645 | mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */ | |
646 | .machine pop | |
647 | ||
648 | #ifdef CONFIG_PPC_ISERIES | |
3f639ee8 | 649 | BEGIN_FW_FTR_SECTION |
3c726f8d BH |
650 | mtspr SPRN_SRR0,r11 |
651 | mtspr SPRN_SRR1,r12 | |
3f639ee8 | 652 | END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES) |
3c726f8d BH |
653 | #endif /* CONFIG_PPC_ISERIES */ |
654 | ld r9,PACA_EXSLB+EX_R9(r13) | |
655 | ld r10,PACA_EXSLB+EX_R10(r13) | |
656 | ld r11,PACA_EXSLB+EX_R11(r13) | |
657 | ld r12,PACA_EXSLB+EX_R12(r13) | |
658 | ld r13,PACA_EXSLB+EX_R13(r13) | |
659 | rfid | |
660 | b . /* prevent speculative execution */ | |
661 | ||
320787c7 PM |
662 | 2: |
663 | #ifdef CONFIG_PPC_ISERIES | |
664 | BEGIN_FW_FTR_SECTION | |
665 | b unrecov_slb | |
666 | END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES) | |
667 | #endif /* CONFIG_PPC_ISERIES */ | |
668 | mfspr r11,SPRN_SRR0 | |
1f6a93e4 | 669 | ld r10,PACAKBASE(r13) |
320787c7 PM |
670 | LOAD_HANDLER(r10,unrecov_slb) |
671 | mtspr SPRN_SRR0,r10 | |
1f6a93e4 | 672 | ld r10,PACAKMSR(r13) |
320787c7 PM |
673 | mtspr SPRN_SRR1,r10 |
674 | rfid | |
675 | b . | |
676 | ||
3c726f8d BH |
677 | unrecov_slb: |
678 | EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB) | |
679 | DISABLE_INTS | |
680 | bl .save_nvgprs | |
681 | 1: addi r3,r1,STACK_FRAME_OVERHEAD | |
682 | bl .unrecoverable_exception | |
683 | b 1b | |
684 | ||
14cf11af PM |
685 | .align 7 |
686 | .globl hardware_interrupt_common | |
687 | .globl hardware_interrupt_entry | |
688 | hardware_interrupt_common: | |
689 | EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN) | |
f39224a8 | 690 | FINISH_NAP |
14cf11af PM |
691 | hardware_interrupt_entry: |
692 | DISABLE_INTS | |
a416561b | 693 | BEGIN_FTR_SECTION |
cb2c9b27 | 694 | bl .ppc64_runlatch_on |
a416561b | 695 | END_FTR_SECTION_IFSET(CPU_FTR_CTRL) |
14cf11af PM |
696 | addi r3,r1,STACK_FRAME_OVERHEAD |
697 | bl .do_IRQ | |
698 | b .ret_from_except_lite | |
699 | ||
f39224a8 PM |
700 | #ifdef CONFIG_PPC_970_NAP |
701 | power4_fixup_nap: | |
702 | andc r9,r9,r10 | |
703 | std r9,TI_LOCAL_FLAGS(r11) | |
704 | ld r10,_LINK(r1) /* make idle task do the */ | |
705 | std r10,_NIP(r1) /* equivalent of a blr */ | |
706 | blr | |
707 | #endif | |
708 | ||
14cf11af PM |
709 | .align 7 |
710 | .globl alignment_common | |
711 | alignment_common: | |
b5bbeb23 | 712 | mfspr r10,SPRN_DAR |
14cf11af | 713 | std r10,PACA_EXGEN+EX_DAR(r13) |
b5bbeb23 | 714 | mfspr r10,SPRN_DSISR |
14cf11af PM |
715 | stw r10,PACA_EXGEN+EX_DSISR(r13) |
716 | EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN) | |
717 | ld r3,PACA_EXGEN+EX_DAR(r13) | |
718 | lwz r4,PACA_EXGEN+EX_DSISR(r13) | |
719 | std r3,_DAR(r1) | |
720 | std r4,_DSISR(r1) | |
721 | bl .save_nvgprs | |
722 | addi r3,r1,STACK_FRAME_OVERHEAD | |
723 | ENABLE_INTS | |
724 | bl .alignment_exception | |
725 | b .ret_from_except | |
726 | ||
727 | .align 7 | |
728 | .globl program_check_common | |
729 | program_check_common: | |
730 | EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN) | |
731 | bl .save_nvgprs | |
732 | addi r3,r1,STACK_FRAME_OVERHEAD | |
733 | ENABLE_INTS | |
734 | bl .program_check_exception | |
735 | b .ret_from_except | |
736 | ||
737 | .align 7 | |
738 | .globl fp_unavailable_common | |
739 | fp_unavailable_common: | |
740 | EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN) | |
3ccfc65c | 741 | bne 1f /* if from user, just load it up */ |
14cf11af PM |
742 | bl .save_nvgprs |
743 | addi r3,r1,STACK_FRAME_OVERHEAD | |
744 | ENABLE_INTS | |
745 | bl .kernel_fp_unavailable_exception | |
746 | BUG_OPCODE | |
6f3d8e69 MN |
747 | 1: bl .load_up_fpu |
748 | b fast_exception_return | |
14cf11af | 749 | |
14cf11af PM |
750 | .align 7 |
751 | .globl altivec_unavailable_common | |
752 | altivec_unavailable_common: | |
753 | EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN) | |
754 | #ifdef CONFIG_ALTIVEC | |
755 | BEGIN_FTR_SECTION | |
6f3d8e69 MN |
756 | beq 1f |
757 | bl .load_up_altivec | |
758 | b fast_exception_return | |
759 | 1: | |
14cf11af PM |
760 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) |
761 | #endif | |
762 | bl .save_nvgprs | |
763 | addi r3,r1,STACK_FRAME_OVERHEAD | |
764 | ENABLE_INTS | |
765 | bl .altivec_unavailable_exception | |
766 | b .ret_from_except | |
767 | ||
9a955167 PM |
768 | .align 7 |
769 | .globl vsx_unavailable_common | |
770 | vsx_unavailable_common: | |
771 | EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN) | |
772 | #ifdef CONFIG_VSX | |
773 | BEGIN_FTR_SECTION | |
774 | bne .load_up_vsx | |
775 | 1: | |
776 | END_FTR_SECTION_IFSET(CPU_FTR_VSX) | |
777 | #endif | |
778 | bl .save_nvgprs | |
779 | addi r3,r1,STACK_FRAME_OVERHEAD | |
780 | ENABLE_INTS | |
781 | bl .vsx_unavailable_exception | |
782 | b .ret_from_except | |
783 | ||
784 | .align 7 | |
785 | .globl __end_handlers | |
786 | __end_handlers: | |
787 | ||
788 | /* | |
789 | * Return from an exception with minimal checks. | |
790 | * The caller is assumed to have done EXCEPTION_PROLOG_COMMON. | |
791 | * If interrupts have been enabled, or anything has been | |
792 | * done that might have changed the scheduling status of | |
793 | * any task or sent any task a signal, you should use | |
794 | * ret_from_except or ret_from_except_lite instead of this. | |
795 | */ | |
796 | fast_exc_return_irq: /* restores irq state too */ | |
797 | ld r3,SOFTE(r1) | |
798 | TRACE_AND_RESTORE_IRQ(r3); | |
799 | ld r12,_MSR(r1) | |
800 | rldicl r4,r12,49,63 /* get MSR_EE to LSB */ | |
801 | stb r4,PACAHARDIRQEN(r13) /* restore paca->hard_enabled */ | |
802 | b 1f | |
803 | ||
804 | .globl fast_exception_return | |
805 | fast_exception_return: | |
806 | ld r12,_MSR(r1) | |
807 | 1: ld r11,_NIP(r1) | |
808 | andi. r3,r12,MSR_RI /* check if RI is set */ | |
809 | beq- unrecov_fer | |
810 | ||
811 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING | |
812 | andi. r3,r12,MSR_PR | |
813 | beq 2f | |
814 | ACCOUNT_CPU_USER_EXIT(r3, r4) | |
815 | 2: | |
816 | #endif | |
817 | ||
818 | ld r3,_CCR(r1) | |
819 | ld r4,_LINK(r1) | |
820 | ld r5,_CTR(r1) | |
821 | ld r6,_XER(r1) | |
822 | mtcr r3 | |
823 | mtlr r4 | |
824 | mtctr r5 | |
825 | mtxer r6 | |
826 | REST_GPR(0, r1) | |
827 | REST_8GPRS(2, r1) | |
828 | ||
829 | mfmsr r10 | |
830 | rldicl r10,r10,48,1 /* clear EE */ | |
831 | rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */ | |
832 | mtmsrd r10,1 | |
833 | ||
834 | mtspr SPRN_SRR1,r12 | |
835 | mtspr SPRN_SRR0,r11 | |
836 | REST_4GPRS(10, r1) | |
837 | ld r1,GPR1(r1) | |
838 | rfid | |
839 | b . /* prevent speculative execution */ | |
840 | ||
841 | unrecov_fer: | |
842 | bl .save_nvgprs | |
843 | 1: addi r3,r1,STACK_FRAME_OVERHEAD | |
844 | bl .unrecoverable_exception | |
845 | b 1b | |
846 | ||
ce48b210 | 847 | |
14cf11af PM |
848 | /* |
849 | * Hash table stuff | |
850 | */ | |
851 | .align 7 | |
945feb17 | 852 | _STATIC(do_hash_page) |
14cf11af PM |
853 | std r3,_DAR(r1) |
854 | std r4,_DSISR(r1) | |
855 | ||
856 | andis. r0,r4,0xa450 /* weird error? */ | |
3ccfc65c | 857 | bne- handle_page_fault /* if not, try to insert a HPTE */ |
14cf11af PM |
858 | BEGIN_FTR_SECTION |
859 | andis. r0,r4,0x0020 /* Is it a segment table fault? */ | |
3ccfc65c | 860 | bne- do_ste_alloc /* If so handle it */ |
14cf11af PM |
861 | END_FTR_SECTION_IFCLR(CPU_FTR_SLB) |
862 | ||
945feb17 BH |
863 | /* |
864 | * On iSeries, we soft-disable interrupts here, then | |
865 | * hard-enable interrupts so that the hash_page code can spin on | |
866 | * the hash_table_lock without problems on a shared processor. | |
867 | */ | |
868 | DISABLE_INTS | |
869 | ||
870 | /* | |
871 | * Currently, trace_hardirqs_off() will be called by DISABLE_INTS | |
872 | * and will clobber volatile registers when irq tracing is enabled | |
873 | * so we need to reload them. It may be possible to be smarter here | |
874 | * and move the irq tracing elsewhere but let's keep it simple for | |
875 | * now | |
876 | */ | |
877 | #ifdef CONFIG_TRACE_IRQFLAGS | |
878 | ld r3,_DAR(r1) | |
879 | ld r4,_DSISR(r1) | |
880 | ld r5,_TRAP(r1) | |
881 | ld r12,_MSR(r1) | |
882 | clrrdi r5,r5,4 | |
883 | #endif /* CONFIG_TRACE_IRQFLAGS */ | |
14cf11af PM |
884 | /* |
885 | * We need to set the _PAGE_USER bit if MSR_PR is set or if we are | |
886 | * accessing a userspace segment (even from the kernel). We assume | |
887 | * kernel addresses always have the high bit set. | |
888 | */ | |
889 | rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */ | |
890 | rotldi r0,r3,15 /* Move high bit into MSR_PR posn */ | |
891 | orc r0,r12,r0 /* MSR_PR | ~high_bit */ | |
892 | rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */ | |
893 | ori r4,r4,1 /* add _PAGE_PRESENT */ | |
894 | rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */ | |
895 | ||
14cf11af PM |
896 | /* |
897 | * r3 contains the faulting address | |
898 | * r4 contains the required access permissions | |
899 | * r5 contains the trap number | |
900 | * | |
901 | * at return r3 = 0 for success | |
902 | */ | |
903 | bl .hash_page /* build HPTE if possible */ | |
904 | cmpdi r3,0 /* see if hash_page succeeded */ | |
905 | ||
3f639ee8 | 906 | BEGIN_FW_FTR_SECTION |
14cf11af PM |
907 | /* |
908 | * If we had interrupts soft-enabled at the point where the | |
909 | * DSI/ISI occurred, and an interrupt came in during hash_page, | |
910 | * handle it now. | |
911 | * We jump to ret_from_except_lite rather than fast_exception_return | |
912 | * because ret_from_except_lite will check for and handle pending | |
913 | * interrupts if necessary. | |
914 | */ | |
3ccfc65c | 915 | beq 13f |
b0a779de | 916 | END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES) |
945feb17 | 917 | |
b0a779de PM |
918 | BEGIN_FW_FTR_SECTION |
919 | /* | |
920 | * Here we have interrupts hard-disabled, so it is sufficient | |
921 | * to restore paca->{soft,hard}_enable and get out. | |
922 | */ | |
923 | beq fast_exc_return_irq /* Return from exception on success */ | |
924 | END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES) | |
925 | ||
14cf11af PM |
926 | /* For a hash failure, we don't bother re-enabling interrupts */ |
927 | ble- 12f | |
928 | ||
929 | /* | |
930 | * hash_page couldn't handle it, set soft interrupt enable back | |
945feb17 | 931 | * to what it was before the trap. Note that .raw_local_irq_restore |
14cf11af PM |
932 | * handles any interrupts pending at this point. |
933 | */ | |
934 | ld r3,SOFTE(r1) | |
945feb17 BH |
935 | TRACE_AND_RESTORE_IRQ_PARTIAL(r3, 11f) |
936 | bl .raw_local_irq_restore | |
14cf11af | 937 | b 11f |
14cf11af PM |
938 | |
939 | /* Here we have a page fault that hash_page can't handle. */ | |
3ccfc65c | 940 | handle_page_fault: |
14cf11af PM |
941 | ENABLE_INTS |
942 | 11: ld r4,_DAR(r1) | |
943 | ld r5,_DSISR(r1) | |
944 | addi r3,r1,STACK_FRAME_OVERHEAD | |
945 | bl .do_page_fault | |
946 | cmpdi r3,0 | |
3ccfc65c | 947 | beq+ 13f |
14cf11af PM |
948 | bl .save_nvgprs |
949 | mr r5,r3 | |
950 | addi r3,r1,STACK_FRAME_OVERHEAD | |
951 | lwz r4,_DAR(r1) | |
952 | bl .bad_page_fault | |
953 | b .ret_from_except | |
954 | ||
79acbb3f PM |
955 | 13: b .ret_from_except_lite |
956 | ||
14cf11af PM |
957 | /* We have a page fault that hash_page could handle but HV refused |
958 | * the PTE insertion | |
959 | */ | |
960 | 12: bl .save_nvgprs | |
fa28237c | 961 | mr r5,r3 |
14cf11af | 962 | addi r3,r1,STACK_FRAME_OVERHEAD |
a792e75d | 963 | ld r4,_DAR(r1) |
14cf11af PM |
964 | bl .low_hash_fault |
965 | b .ret_from_except | |
966 | ||
967 | /* here we have a segment miss */ | |
3ccfc65c | 968 | do_ste_alloc: |
14cf11af PM |
969 | bl .ste_allocate /* try to insert stab entry */ |
970 | cmpdi r3,0 | |
3ccfc65c PM |
971 | bne- handle_page_fault |
972 | b fast_exception_return | |
14cf11af PM |
973 | |
974 | /* | |
975 | * r13 points to the PACA, r9 contains the saved CR, | |
976 | * r11 and r12 contain the saved SRR0 and SRR1. | |
977 | * r9 - r13 are saved in paca->exslb. | |
978 | * We assume we aren't going to take any exceptions during this procedure. | |
979 | * We assume (DAR >> 60) == 0xc. | |
980 | */ | |
981 | .align 7 | |
982 | _GLOBAL(do_stab_bolted) | |
983 | stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */ | |
984 | std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */ | |
985 | ||
986 | /* Hash to the primary group */ | |
987 | ld r10,PACASTABVIRT(r13) | |
b5bbeb23 | 988 | mfspr r11,SPRN_DAR |
14cf11af PM |
989 | srdi r11,r11,28 |
990 | rldimi r10,r11,7,52 /* r10 = first ste of the group */ | |
991 | ||
992 | /* Calculate VSID */ | |
993 | /* This is a kernel address, so protovsid = ESID */ | |
1189be65 | 994 | ASM_VSID_SCRAMBLE(r11, r9, 256M) |
14cf11af PM |
995 | rldic r9,r11,12,16 /* r9 = vsid << 12 */ |
996 | ||
997 | /* Search the primary group for a free entry */ | |
998 | 1: ld r11,0(r10) /* Test valid bit of the current ste */ | |
999 | andi. r11,r11,0x80 | |
1000 | beq 2f | |
1001 | addi r10,r10,16 | |
1002 | andi. r11,r10,0x70 | |
1003 | bne 1b | |
1004 | ||
1005 | /* Stick for only searching the primary group for now. */ | |
1006 | /* At least for now, we use a very simple random castout scheme */ | |
1007 | /* Use the TB as a random number ; OR in 1 to avoid entry 0 */ | |
1008 | mftb r11 | |
1009 | rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */ | |
1010 | ori r11,r11,0x10 | |
1011 | ||
1012 | /* r10 currently points to an ste one past the group of interest */ | |
1013 | /* make it point to the randomly selected entry */ | |
1014 | subi r10,r10,128 | |
1015 | or r10,r10,r11 /* r10 is the entry to invalidate */ | |
1016 | ||
1017 | isync /* mark the entry invalid */ | |
1018 | ld r11,0(r10) | |
1019 | rldicl r11,r11,56,1 /* clear the valid bit */ | |
1020 | rotldi r11,r11,8 | |
1021 | std r11,0(r10) | |
1022 | sync | |
1023 | ||
1024 | clrrdi r11,r11,28 /* Get the esid part of the ste */ | |
1025 | slbie r11 | |
1026 | ||
1027 | 2: std r9,8(r10) /* Store the vsid part of the ste */ | |
1028 | eieio | |
1029 | ||
b5bbeb23 | 1030 | mfspr r11,SPRN_DAR /* Get the new esid */ |
14cf11af PM |
1031 | clrrdi r11,r11,28 /* Permits a full 32b of ESID */ |
1032 | ori r11,r11,0x90 /* Turn on valid and kp */ | |
1033 | std r11,0(r10) /* Put new entry back into the stab */ | |
1034 | ||
1035 | sync | |
1036 | ||
1037 | /* All done -- return from exception. */ | |
1038 | lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */ | |
1039 | ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */ | |
1040 | ||
1041 | andi. r10,r12,MSR_RI | |
1042 | beq- unrecov_slb | |
1043 | ||
1044 | mtcrf 0x80,r9 /* restore CR */ | |
1045 | ||
1046 | mfmsr r10 | |
1047 | clrrdi r10,r10,2 | |
1048 | mtmsrd r10,1 | |
1049 | ||
b5bbeb23 PM |
1050 | mtspr SPRN_SRR0,r11 |
1051 | mtspr SPRN_SRR1,r12 | |
14cf11af PM |
1052 | ld r9,PACA_EXSLB+EX_R9(r13) |
1053 | ld r10,PACA_EXSLB+EX_R10(r13) | |
1054 | ld r11,PACA_EXSLB+EX_R11(r13) | |
1055 | ld r12,PACA_EXSLB+EX_R12(r13) | |
1056 | ld r13,PACA_EXSLB+EX_R13(r13) | |
1057 | rfid | |
1058 | b . /* prevent speculative execution */ | |
1059 | ||
14cf11af PM |
1060 | /* |
1061 | * Space for CPU0's segment table. | |
1062 | * | |
1063 | * On iSeries, the hypervisor must fill in at least one entry before | |
16a15a30 SR |
1064 | * we get control (with relocate on). The address is given to the hv |
1065 | * as a page number (see xLparMap below), so this must be at a | |
14cf11af PM |
1066 | * fixed address (the linker can't compute (u64)&initial_stab >> |
1067 | * PAGE_SHIFT). | |
1068 | */ | |
758438a7 | 1069 | . = STAB0_OFFSET /* 0x6000 */ |
14cf11af PM |
1070 | .globl initial_stab |
1071 | initial_stab: | |
1072 | .space 4096 | |
1073 | ||
9e4859ef | 1074 | #ifdef CONFIG_PPC_PSERIES |
14cf11af PM |
1075 | /* |
1076 | * Data area reserved for FWNMI option. | |
1077 | * This address (0x7000) is fixed by the RPA. | |
1078 | */ | |
1079 | .= 0x7000 | |
1080 | .globl fwnmi_data_area | |
1081 | fwnmi_data_area: | |
9e4859ef | 1082 | #endif /* CONFIG_PPC_PSERIES */ |
14cf11af PM |
1083 | |
1084 | /* iSeries does not use the FWNMI stuff, so it is safe to put | |
1085 | * this here, even if we later allow kernels that will boot on | |
1086 | * both pSeries and iSeries */ | |
1087 | #ifdef CONFIG_PPC_ISERIES | |
1088 | . = LPARMAP_PHYS | |
16a15a30 SR |
1089 | .globl xLparMap |
1090 | xLparMap: | |
1091 | .quad HvEsidsToMap /* xNumberEsids */ | |
1092 | .quad HvRangesToMap /* xNumberRanges */ | |
1093 | .quad STAB0_PAGE /* xSegmentTableOffs */ | |
1094 | .zero 40 /* xRsvd */ | |
1095 | /* xEsids (HvEsidsToMap entries of 2 quads) */ | |
1096 | .quad PAGE_OFFSET_ESID /* xKernelEsid */ | |
1097 | .quad PAGE_OFFSET_VSID /* xKernelVsid */ | |
1098 | .quad VMALLOC_START_ESID /* xKernelEsid */ | |
1099 | .quad VMALLOC_START_VSID /* xKernelVsid */ | |
1100 | /* xRanges (HvRangesToMap entries of 3 quads) */ | |
1101 | .quad HvPagesToMap /* xPages */ | |
1102 | .quad 0 /* xOffset */ | |
1103 | .quad PAGE_OFFSET_VSID << (SID_SHIFT - HW_PAGE_SHIFT) /* xVPN */ | |
1104 | ||
14cf11af PM |
1105 | #endif /* CONFIG_PPC_ISERIES */ |
1106 | ||
9e4859ef | 1107 | #ifdef CONFIG_PPC_PSERIES |
14cf11af | 1108 | . = 0x8000 |
9e4859ef | 1109 | #endif /* CONFIG_PPC_PSERIES */ |
14cf11af PM |
1110 | |
1111 | /* | |
f39b7a55 OJ |
1112 | * On pSeries and most other platforms, secondary processors spin |
1113 | * in the following code. | |
14cf11af PM |
1114 | * At entry, r3 = this processor's number (physical cpu id) |
1115 | */ | |
f39b7a55 | 1116 | _GLOBAL(generic_secondary_smp_init) |
14cf11af PM |
1117 | mr r24,r3 |
1118 | ||
1119 | /* turn on 64-bit mode */ | |
1120 | bl .enable_64b_mode | |
14cf11af | 1121 | |
e31aa453 PM |
1122 | /* get the TOC pointer (real address) */ |
1123 | bl .relative_toc | |
1124 | ||
14cf11af PM |
1125 | /* Set up a paca value for this processor. Since we have the |
1126 | * physical cpu id in r24, we need to search the pacas to find | |
1127 | * which logical id maps to our physical one. | |
1128 | */ | |
e31aa453 | 1129 | LOAD_REG_ADDR(r13, paca) /* Get base vaddr of paca array */ |
14cf11af PM |
1130 | li r5,0 /* logical cpu id */ |
1131 | 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */ | |
1132 | cmpw r6,r24 /* Compare to our id */ | |
1133 | beq 2f | |
1134 | addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */ | |
1135 | addi r5,r5,1 | |
1136 | cmpwi r5,NR_CPUS | |
1137 | blt 1b | |
1138 | ||
1139 | mr r3,r24 /* not found, copy phys to r3 */ | |
1140 | b .kexec_wait /* next kernel might do better */ | |
1141 | ||
b5bbeb23 | 1142 | 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */ |
14cf11af PM |
1143 | /* From now on, r24 is expected to be logical cpuid */ |
1144 | mr r24,r5 | |
1145 | 3: HMT_LOW | |
1146 | lbz r23,PACAPROCSTART(r13) /* Test if this processor should */ | |
1147 | /* start. */ | |
14cf11af | 1148 | |
f39b7a55 OJ |
1149 | #ifndef CONFIG_SMP |
1150 | b 3b /* Never go on non-SMP */ | |
1151 | #else | |
1152 | cmpwi 0,r23,0 | |
1153 | beq 3b /* Loop until told to go */ | |
1154 | ||
b6f6b98a SR |
1155 | sync /* order paca.run and cur_cpu_spec */ |
1156 | ||
f39b7a55 | 1157 | /* See if we need to call a cpu state restore handler */ |
e31aa453 | 1158 | LOAD_REG_ADDR(r23, cur_cpu_spec) |
f39b7a55 OJ |
1159 | ld r23,0(r23) |
1160 | ld r23,CPU_SPEC_RESTORE(r23) | |
1161 | cmpdi 0,r23,0 | |
1162 | beq 4f | |
1163 | ld r23,0(r23) | |
1164 | mtctr r23 | |
1165 | bctrl | |
1166 | ||
1167 | 4: /* Create a temp kernel stack for use before relocation is on. */ | |
14cf11af PM |
1168 | ld r1,PACAEMERGSP(r13) |
1169 | subi r1,r1,STACK_FRAME_OVERHEAD | |
1170 | ||
c705677e | 1171 | b __secondary_start |
14cf11af | 1172 | #endif |
14cf11af | 1173 | |
e31aa453 PM |
1174 | /* |
1175 | * Turn the MMU off. | |
1176 | * Assumes we're mapped EA == RA if the MMU is on. | |
1177 | */ | |
14cf11af PM |
1178 | _STATIC(__mmu_off) |
1179 | mfmsr r3 | |
1180 | andi. r0,r3,MSR_IR|MSR_DR | |
1181 | beqlr | |
e31aa453 | 1182 | mflr r4 |
14cf11af PM |
1183 | andc r3,r3,r0 |
1184 | mtspr SPRN_SRR0,r4 | |
1185 | mtspr SPRN_SRR1,r3 | |
1186 | sync | |
1187 | rfid | |
1188 | b . /* prevent speculative execution */ | |
1189 | ||
1190 | ||
1191 | /* | |
1192 | * Here is our main kernel entry point. We support currently 2 kind of entries | |
1193 | * depending on the value of r5. | |
1194 | * | |
1195 | * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content | |
1196 | * in r3...r7 | |
1197 | * | |
1198 | * r5 == NULL -> kexec style entry. r3 is a physical pointer to the | |
1199 | * DT block, r4 is a physical pointer to the kernel itself | |
1200 | * | |
1201 | */ | |
1202 | _GLOBAL(__start_initialization_multiplatform) | |
e31aa453 PM |
1203 | /* Make sure we are running in 64 bits mode */ |
1204 | bl .enable_64b_mode | |
1205 | ||
1206 | /* Get TOC pointer (current runtime address) */ | |
1207 | bl .relative_toc | |
1208 | ||
1209 | /* find out where we are now */ | |
1210 | bcl 20,31,$+4 | |
1211 | 0: mflr r26 /* r26 = runtime addr here */ | |
1212 | addis r26,r26,(_stext - 0b)@ha | |
1213 | addi r26,r26,(_stext - 0b)@l /* current runtime base addr */ | |
1214 | ||
14cf11af PM |
1215 | /* |
1216 | * Are we booted from a PROM Of-type client-interface ? | |
1217 | */ | |
1218 | cmpldi cr0,r5,0 | |
939e60f6 SR |
1219 | beq 1f |
1220 | b .__boot_from_prom /* yes -> prom */ | |
1221 | 1: | |
14cf11af PM |
1222 | /* Save parameters */ |
1223 | mr r31,r3 | |
1224 | mr r30,r4 | |
1225 | ||
14cf11af | 1226 | /* Setup some critical 970 SPRs before switching MMU off */ |
f39b7a55 OJ |
1227 | mfspr r0,SPRN_PVR |
1228 | srwi r0,r0,16 | |
1229 | cmpwi r0,0x39 /* 970 */ | |
1230 | beq 1f | |
1231 | cmpwi r0,0x3c /* 970FX */ | |
1232 | beq 1f | |
1233 | cmpwi r0,0x44 /* 970MP */ | |
190a24f5 OJ |
1234 | beq 1f |
1235 | cmpwi r0,0x45 /* 970GX */ | |
f39b7a55 OJ |
1236 | bne 2f |
1237 | 1: bl .__cpu_preinit_ppc970 | |
1238 | 2: | |
14cf11af | 1239 | |
e31aa453 | 1240 | /* Switch off MMU if not already off */ |
14cf11af PM |
1241 | bl .__mmu_off |
1242 | b .__after_prom_start | |
1243 | ||
939e60f6 | 1244 | _INIT_STATIC(__boot_from_prom) |
28794d34 | 1245 | #ifdef CONFIG_PPC_OF_BOOT_TRAMPOLINE |
14cf11af PM |
1246 | /* Save parameters */ |
1247 | mr r31,r3 | |
1248 | mr r30,r4 | |
1249 | mr r29,r5 | |
1250 | mr r28,r6 | |
1251 | mr r27,r7 | |
1252 | ||
6088857b OH |
1253 | /* |
1254 | * Align the stack to 16-byte boundary | |
1255 | * Depending on the size and layout of the ELF sections in the initial | |
e31aa453 | 1256 | * boot binary, the stack pointer may be unaligned on PowerMac |
6088857b | 1257 | */ |
c05b4770 LT |
1258 | rldicr r1,r1,0,59 |
1259 | ||
549e8152 PM |
1260 | #ifdef CONFIG_RELOCATABLE |
1261 | /* Relocate code for where we are now */ | |
1262 | mr r3,r26 | |
1263 | bl .relocate | |
1264 | #endif | |
1265 | ||
14cf11af PM |
1266 | /* Restore parameters */ |
1267 | mr r3,r31 | |
1268 | mr r4,r30 | |
1269 | mr r5,r29 | |
1270 | mr r6,r28 | |
1271 | mr r7,r27 | |
1272 | ||
1273 | /* Do all of the interaction with OF client interface */ | |
549e8152 | 1274 | mr r8,r26 |
14cf11af | 1275 | bl .prom_init |
28794d34 BH |
1276 | #endif /* #CONFIG_PPC_OF_BOOT_TRAMPOLINE */ |
1277 | ||
1278 | /* We never return. We also hit that trap if trying to boot | |
1279 | * from OF while CONFIG_PPC_OF_BOOT_TRAMPOLINE isn't selected */ | |
14cf11af PM |
1280 | trap |
1281 | ||
14cf11af | 1282 | _STATIC(__after_prom_start) |
549e8152 PM |
1283 | #ifdef CONFIG_RELOCATABLE |
1284 | /* process relocations for the final address of the kernel */ | |
1285 | lis r25,PAGE_OFFSET@highest /* compute virtual base of kernel */ | |
1286 | sldi r25,r25,32 | |
54622f10 | 1287 | #ifdef CONFIG_CRASH_DUMP |
8b8b0cc1 MM |
1288 | lwz r7,__run_at_load-_stext(r26) |
1289 | cmplwi cr0,r7,1 /* kdump kernel ? - stay where we are */ | |
54622f10 MK |
1290 | bne 1f |
1291 | add r25,r25,r26 | |
1292 | #endif | |
1293 | 1: mr r3,r25 | |
549e8152 PM |
1294 | bl .relocate |
1295 | #endif | |
14cf11af PM |
1296 | |
1297 | /* | |
e31aa453 | 1298 | * We need to run with _stext at physical address PHYSICAL_START. |
14cf11af PM |
1299 | * This will leave some code in the first 256B of |
1300 | * real memory, which are reserved for software use. | |
14cf11af PM |
1301 | * |
1302 | * Note: This process overwrites the OF exception vectors. | |
14cf11af | 1303 | */ |
549e8152 PM |
1304 | li r3,0 /* target addr */ |
1305 | mr. r4,r26 /* In some cases the loader may */ | |
e31aa453 | 1306 | beq 9f /* have already put us at zero */ |
14cf11af PM |
1307 | li r6,0x100 /* Start offset, the first 0x100 */ |
1308 | /* bytes were copied earlier. */ | |
1309 | ||
54622f10 MK |
1310 | #ifdef CONFIG_CRASH_DUMP |
1311 | /* | |
1312 | * Check if the kernel has to be running as relocatable kernel based on the | |
8b8b0cc1 | 1313 | * variable __run_at_load, if it is set the kernel is treated as relocatable |
54622f10 MK |
1314 | * kernel, otherwise it will be moved to PHYSICAL_START |
1315 | */ | |
8b8b0cc1 MM |
1316 | lwz r7,__run_at_load-_stext(r26) |
1317 | cmplwi cr0,r7,1 | |
54622f10 MK |
1318 | bne 3f |
1319 | ||
1320 | li r5,__end_interrupts - _stext /* just copy interrupts */ | |
1321 | b 5f | |
1322 | 3: | |
1323 | #endif | |
1324 | lis r5,(copy_to_here - _stext)@ha | |
1325 | addi r5,r5,(copy_to_here - _stext)@l /* # bytes of memory to copy */ | |
1326 | ||
14cf11af PM |
1327 | bl .copy_and_flush /* copy the first n bytes */ |
1328 | /* this includes the code being */ | |
1329 | /* executed here. */ | |
e31aa453 PM |
1330 | addis r8,r3,(4f - _stext)@ha /* Jump to the copy of this code */ |
1331 | addi r8,r8,(4f - _stext)@l /* that we just made */ | |
1332 | mtctr r8 | |
14cf11af PM |
1333 | bctr |
1334 | ||
54622f10 MK |
1335 | p_end: .llong _end - _stext |
1336 | ||
e31aa453 PM |
1337 | 4: /* Now copy the rest of the kernel up to _end */ |
1338 | addis r5,r26,(p_end - _stext)@ha | |
1339 | ld r5,(p_end - _stext)@l(r5) /* get _end */ | |
54622f10 | 1340 | 5: bl .copy_and_flush /* copy the rest */ |
e31aa453 PM |
1341 | |
1342 | 9: b .start_here_multiplatform | |
1343 | ||
14cf11af PM |
1344 | /* |
1345 | * Copy routine used to copy the kernel to start at physical address 0 | |
1346 | * and flush and invalidate the caches as needed. | |
1347 | * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset | |
1348 | * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5. | |
1349 | * | |
1350 | * Note: this routine *only* clobbers r0, r6 and lr | |
1351 | */ | |
1352 | _GLOBAL(copy_and_flush) | |
1353 | addi r5,r5,-8 | |
1354 | addi r6,r6,-8 | |
5a2fe38d | 1355 | 4: li r0,8 /* Use the smallest common */ |
14cf11af PM |
1356 | /* denominator cache line */ |
1357 | /* size. This results in */ | |
1358 | /* extra cache line flushes */ | |
1359 | /* but operation is correct. */ | |
1360 | /* Can't get cache line size */ | |
1361 | /* from NACA as it is being */ | |
1362 | /* moved too. */ | |
1363 | ||
1364 | mtctr r0 /* put # words/line in ctr */ | |
1365 | 3: addi r6,r6,8 /* copy a cache line */ | |
1366 | ldx r0,r6,r4 | |
1367 | stdx r0,r6,r3 | |
1368 | bdnz 3b | |
1369 | dcbst r6,r3 /* write it to memory */ | |
1370 | sync | |
1371 | icbi r6,r3 /* flush the icache line */ | |
1372 | cmpld 0,r6,r5 | |
1373 | blt 4b | |
1374 | sync | |
1375 | addi r5,r5,8 | |
1376 | addi r6,r6,8 | |
1377 | blr | |
1378 | ||
1379 | .align 8 | |
1380 | copy_to_here: | |
1381 | ||
1382 | #ifdef CONFIG_SMP | |
1383 | #ifdef CONFIG_PPC_PMAC | |
1384 | /* | |
1385 | * On PowerMac, secondary processors starts from the reset vector, which | |
1386 | * is temporarily turned into a call to one of the functions below. | |
1387 | */ | |
1388 | .section ".text"; | |
1389 | .align 2 ; | |
1390 | ||
35499c01 PM |
1391 | .globl __secondary_start_pmac_0 |
1392 | __secondary_start_pmac_0: | |
1393 | /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */ | |
1394 | li r24,0 | |
1395 | b 1f | |
1396 | li r24,1 | |
1397 | b 1f | |
1398 | li r24,2 | |
1399 | b 1f | |
1400 | li r24,3 | |
1401 | 1: | |
14cf11af PM |
1402 | |
1403 | _GLOBAL(pmac_secondary_start) | |
1404 | /* turn on 64-bit mode */ | |
1405 | bl .enable_64b_mode | |
14cf11af | 1406 | |
c478b581 BH |
1407 | li r0,0 |
1408 | mfspr r3,SPRN_HID4 | |
1409 | rldimi r3,r0,40,23 /* clear bit 23 (rm_ci) */ | |
1410 | sync | |
1411 | mtspr SPRN_HID4,r3 | |
1412 | isync | |
1413 | sync | |
1414 | slbia | |
1415 | ||
e31aa453 PM |
1416 | /* get TOC pointer (real address) */ |
1417 | bl .relative_toc | |
1418 | ||
14cf11af | 1419 | /* Copy some CPU settings from CPU 0 */ |
f39b7a55 | 1420 | bl .__restore_cpu_ppc970 |
14cf11af PM |
1421 | |
1422 | /* pSeries do that early though I don't think we really need it */ | |
1423 | mfmsr r3 | |
1424 | ori r3,r3,MSR_RI | |
1425 | mtmsrd r3 /* RI on */ | |
1426 | ||
1427 | /* Set up a paca value for this processor. */ | |
e31aa453 PM |
1428 | LOAD_REG_ADDR(r4,paca) /* Get base vaddr of paca array */ |
1429 | mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */ | |
14cf11af | 1430 | add r13,r13,r4 /* for this processor. */ |
e31aa453 | 1431 | mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */ |
14cf11af PM |
1432 | |
1433 | /* Create a temp kernel stack for use before relocation is on. */ | |
1434 | ld r1,PACAEMERGSP(r13) | |
1435 | subi r1,r1,STACK_FRAME_OVERHEAD | |
1436 | ||
c705677e | 1437 | b __secondary_start |
14cf11af PM |
1438 | |
1439 | #endif /* CONFIG_PPC_PMAC */ | |
1440 | ||
1441 | /* | |
1442 | * This function is called after the master CPU has released the | |
1443 | * secondary processors. The execution environment is relocation off. | |
1444 | * The paca for this processor has the following fields initialized at | |
1445 | * this point: | |
1446 | * 1. Processor number | |
1447 | * 2. Segment table pointer (virtual address) | |
1448 | * On entry the following are set: | |
1449 | * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries | |
1450 | * r24 = cpu# (in Linux terms) | |
1451 | * r13 = paca virtual address | |
1452 | * SPRG3 = paca virtual address | |
1453 | */ | |
fc68e869 | 1454 | .globl __secondary_start |
c705677e | 1455 | __secondary_start: |
799d6046 PM |
1456 | /* Set thread priority to MEDIUM */ |
1457 | HMT_MEDIUM | |
14cf11af | 1458 | |
799d6046 PM |
1459 | /* Do early setup for that CPU (stab, slb, hash table pointer) */ |
1460 | bl .early_setup_secondary | |
14cf11af PM |
1461 | |
1462 | /* Initialize the kernel stack. Just a repeat for iSeries. */ | |
e58c3495 | 1463 | LOAD_REG_ADDR(r3, current_set) |
14cf11af PM |
1464 | sldi r28,r24,3 /* get current_set[cpu#] */ |
1465 | ldx r1,r3,r28 | |
1466 | addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD | |
1467 | std r1,PACAKSAVE(r13) | |
1468 | ||
799d6046 | 1469 | /* Clear backchain so we get nice backtraces */ |
14cf11af PM |
1470 | li r7,0 |
1471 | mtlr r7 | |
1472 | ||
1473 | /* enable MMU and jump to start_secondary */ | |
e58c3495 DG |
1474 | LOAD_REG_ADDR(r3, .start_secondary_prolog) |
1475 | LOAD_REG_IMMEDIATE(r4, MSR_KERNEL) | |
d04c56f7 | 1476 | #ifdef CONFIG_PPC_ISERIES |
3f639ee8 | 1477 | BEGIN_FW_FTR_SECTION |
14cf11af | 1478 | ori r4,r4,MSR_EE |
ff3da2e0 BH |
1479 | li r8,1 |
1480 | stb r8,PACAHARDIRQEN(r13) | |
3f639ee8 | 1481 | END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES) |
14cf11af | 1482 | #endif |
d04c56f7 | 1483 | BEGIN_FW_FTR_SECTION |
d04c56f7 PM |
1484 | stb r7,PACAHARDIRQEN(r13) |
1485 | END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES) | |
ff3da2e0 | 1486 | stb r7,PACASOFTIRQEN(r13) |
d04c56f7 | 1487 | |
b5bbeb23 PM |
1488 | mtspr SPRN_SRR0,r3 |
1489 | mtspr SPRN_SRR1,r4 | |
14cf11af PM |
1490 | rfid |
1491 | b . /* prevent speculative execution */ | |
1492 | ||
1493 | /* | |
1494 | * Running with relocation on at this point. All we want to do is | |
e31aa453 PM |
1495 | * zero the stack back-chain pointer and get the TOC virtual address |
1496 | * before going into C code. | |
14cf11af PM |
1497 | */ |
1498 | _GLOBAL(start_secondary_prolog) | |
e31aa453 | 1499 | ld r2,PACATOC(r13) |
14cf11af PM |
1500 | li r3,0 |
1501 | std r3,0(r1) /* Zero the stack frame pointer */ | |
1502 | bl .start_secondary | |
799d6046 | 1503 | b . |
14cf11af PM |
1504 | #endif |
1505 | ||
1506 | /* | |
1507 | * This subroutine clobbers r11 and r12 | |
1508 | */ | |
1509 | _GLOBAL(enable_64b_mode) | |
1510 | mfmsr r11 /* grab the current MSR */ | |
e31aa453 PM |
1511 | li r12,(MSR_SF | MSR_ISF)@highest |
1512 | sldi r12,r12,48 | |
14cf11af PM |
1513 | or r11,r11,r12 |
1514 | mtmsrd r11 | |
1515 | isync | |
1516 | blr | |
1517 | ||
e31aa453 PM |
1518 | /* |
1519 | * This puts the TOC pointer into r2, offset by 0x8000 (as expected | |
1520 | * by the toolchain). It computes the correct value for wherever we | |
1521 | * are running at the moment, using position-independent code. | |
1522 | */ | |
1523 | _GLOBAL(relative_toc) | |
1524 | mflr r0 | |
1525 | bcl 20,31,$+4 | |
1526 | 0: mflr r9 | |
1527 | ld r2,(p_toc - 0b)(r9) | |
1528 | add r2,r2,r9 | |
1529 | mtlr r0 | |
1530 | blr | |
1531 | ||
1532 | p_toc: .llong __toc_start + 0x8000 - 0b | |
1533 | ||
14cf11af PM |
1534 | /* |
1535 | * This is where the main kernel code starts. | |
1536 | */ | |
939e60f6 | 1537 | _INIT_STATIC(start_here_multiplatform) |
e31aa453 PM |
1538 | /* set up the TOC (real address) */ |
1539 | bl .relative_toc | |
14cf11af PM |
1540 | |
1541 | /* Clear out the BSS. It may have been done in prom_init, | |
1542 | * already but that's irrelevant since prom_init will soon | |
1543 | * be detached from the kernel completely. Besides, we need | |
1544 | * to clear it now for kexec-style entry. | |
1545 | */ | |
e31aa453 PM |
1546 | LOAD_REG_ADDR(r11,__bss_stop) |
1547 | LOAD_REG_ADDR(r8,__bss_start) | |
14cf11af PM |
1548 | sub r11,r11,r8 /* bss size */ |
1549 | addi r11,r11,7 /* round up to an even double word */ | |
e31aa453 | 1550 | srdi. r11,r11,3 /* shift right by 3 */ |
14cf11af PM |
1551 | beq 4f |
1552 | addi r8,r8,-8 | |
1553 | li r0,0 | |
1554 | mtctr r11 /* zero this many doublewords */ | |
1555 | 3: stdu r0,8(r8) | |
1556 | bdnz 3b | |
1557 | 4: | |
1558 | ||
1559 | mfmsr r6 | |
1560 | ori r6,r6,MSR_RI | |
1561 | mtmsrd r6 /* RI on */ | |
1562 | ||
549e8152 PM |
1563 | #ifdef CONFIG_RELOCATABLE |
1564 | /* Save the physical address we're running at in kernstart_addr */ | |
1565 | LOAD_REG_ADDR(r4, kernstart_addr) | |
1566 | clrldi r0,r25,2 | |
1567 | std r0,0(r4) | |
1568 | #endif | |
1569 | ||
e31aa453 | 1570 | /* The following gets the stack set up with the regs */ |
14cf11af PM |
1571 | /* pointing to the real addr of the kernel stack. This is */ |
1572 | /* all done to support the C function call below which sets */ | |
1573 | /* up the htab. This is done because we have relocated the */ | |
1574 | /* kernel but are still running in real mode. */ | |
1575 | ||
e31aa453 | 1576 | LOAD_REG_ADDR(r3,init_thread_union) |
14cf11af | 1577 | |
e31aa453 | 1578 | /* set up a stack pointer */ |
14cf11af PM |
1579 | addi r1,r3,THREAD_SIZE |
1580 | li r0,0 | |
1581 | stdu r0,-STACK_FRAME_OVERHEAD(r1) | |
1582 | ||
14cf11af PM |
1583 | /* Do very early kernel initializations, including initial hash table, |
1584 | * stab and slb setup before we turn on relocation. */ | |
1585 | ||
1586 | /* Restore parameters passed from prom_init/kexec */ | |
1587 | mr r3,r31 | |
e31aa453 | 1588 | bl .early_setup /* also sets r13 and SPRG3 */ |
14cf11af | 1589 | |
e31aa453 PM |
1590 | LOAD_REG_ADDR(r3, .start_here_common) |
1591 | ld r4,PACAKMSR(r13) | |
b5bbeb23 PM |
1592 | mtspr SPRN_SRR0,r3 |
1593 | mtspr SPRN_SRR1,r4 | |
14cf11af PM |
1594 | rfid |
1595 | b . /* prevent speculative execution */ | |
14cf11af PM |
1596 | |
1597 | /* This is where all platforms converge execution */ | |
fc68e869 | 1598 | _INIT_GLOBAL(start_here_common) |
14cf11af | 1599 | /* relocation is on at this point */ |
e31aa453 | 1600 | std r1,PACAKSAVE(r13) |
14cf11af | 1601 | |
e31aa453 | 1602 | /* Load the TOC (virtual address) */ |
14cf11af | 1603 | ld r2,PACATOC(r13) |
14cf11af PM |
1604 | |
1605 | bl .setup_system | |
1606 | ||
1607 | /* Load up the kernel context */ | |
1608 | 5: | |
14cf11af | 1609 | li r5,0 |
d04c56f7 PM |
1610 | stb r5,PACASOFTIRQEN(r13) /* Soft Disabled */ |
1611 | #ifdef CONFIG_PPC_ISERIES | |
1612 | BEGIN_FW_FTR_SECTION | |
14cf11af | 1613 | mfmsr r5 |
ff3da2e0 | 1614 | ori r5,r5,MSR_EE /* Hard Enabled on iSeries*/ |
14cf11af | 1615 | mtmsrd r5 |
ff3da2e0 | 1616 | li r5,1 |
3f639ee8 | 1617 | END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES) |
14cf11af | 1618 | #endif |
ff3da2e0 | 1619 | stb r5,PACAHARDIRQEN(r13) /* Hard Disabled on others */ |
14cf11af | 1620 | |
ff3da2e0 | 1621 | bl .start_kernel |
14cf11af | 1622 | |
f1870f77 AB |
1623 | /* Not reached */ |
1624 | BUG_OPCODE | |
14cf11af | 1625 | |
14cf11af PM |
1626 | /* |
1627 | * We put a few things here that have to be page-aligned. | |
1628 | * This stuff goes at the beginning of the bss, which is page-aligned. | |
1629 | */ | |
1630 | .section ".bss" | |
1631 | ||
1632 | .align PAGE_SHIFT | |
1633 | ||
1634 | .globl empty_zero_page | |
1635 | empty_zero_page: | |
1636 | .space PAGE_SIZE | |
1637 | ||
1638 | .globl swapper_pg_dir | |
1639 | swapper_pg_dir: | |
ee7a76da | 1640 | .space PGD_TABLE_SIZE |