]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - arch/powerpc/kernel/exceptions-64s.S
powerpc: Properly handshake CPUs going out of boot spin loop
[mirror_ubuntu-zesty-kernel.git] / arch / powerpc / kernel / exceptions-64s.S
CommitLineData
0ebc4cda
BH
1/*
2 * This file contains the 64-bit "server" PowerPC variant
3 * of the low level exception handling including exception
4 * vectors, exception return, part of the slb and stab
5 * handling and other fixed offset specific things.
6 *
7 * This file is meant to be #included from head_64.S due to
25985edc 8 * position dependent assembly.
0ebc4cda
BH
9 *
10 * Most of this originates from head_64.S and thus has the same
11 * copyright history.
12 *
13 */
14
8aa34ab8 15#include <asm/exception-64s.h>
46f52210 16#include <asm/ptrace.h>
8aa34ab8 17
0ebc4cda
BH
18/*
19 * We layout physical memory as follows:
20 * 0x0000 - 0x00ff : Secondary processor spin code
21 * 0x0100 - 0x2fff : pSeries Interrupt prologs
22 * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
23 * 0x6000 - 0x6fff : Initial (CPU0) segment table
24 * 0x7000 - 0x7fff : FWNMI data area
25 * 0x8000 - : Early init and support code
26 */
27
0ebc4cda
BH
28/*
29 * This is the start of the interrupt handlers for pSeries
30 * This code runs with relocation off.
31 * Code from here to __end_interrupts gets copied down to real
32 * address 0x100 when we are running a relocatable kernel.
33 * Therefore any relative branches in this section must only
34 * branch to labels in this section.
35 */
36 . = 0x100
37 .globl __start_interrupts
38__start_interrupts:
39
b3e6b5df 40 STD_EXCEPTION_PSERIES(0x100, 0x100, system_reset)
0ebc4cda
BH
41
42 . = 0x200
43_machine_check_pSeries:
44 HMT_MEDIUM
842f2fed 45 DO_KVM 0x200
673b189a 46 SET_SCRATCH0(r13)
a5d4f3ad 47 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common, EXC_STD)
0ebc4cda
BH
48
49 . = 0x300
50 .globl data_access_pSeries
51data_access_pSeries:
52 HMT_MEDIUM
842f2fed 53 DO_KVM 0x300
673b189a 54 SET_SCRATCH0(r13)
0ebc4cda 55BEGIN_FTR_SECTION
2dd60d79 56 GET_PACA(r13)
c5a8c0c9
BH
57 std r9,PACA_EXSLB+EX_R9(r13)
58 std r10,PACA_EXSLB+EX_R10(r13)
59 mfspr r10,SPRN_DAR
60 mfspr r9,SPRN_DSISR
61 srdi r10,r10,60
62 rlwimi r10,r9,16,0x20
63 mfcr r9
64 cmpwi r10,0x2c
0ebc4cda 65 beq do_stab_bolted_pSeries
c5a8c0c9
BH
66 ld r10,PACA_EXSLB+EX_R10(r13)
67 std r11,PACA_EXGEN+EX_R11(r13)
68 ld r11,PACA_EXSLB+EX_R9(r13)
69 std r12,PACA_EXGEN+EX_R12(r13)
673b189a 70 GET_SCRATCH0(r12)
c5a8c0c9
BH
71 std r10,PACA_EXGEN+EX_R10(r13)
72 std r11,PACA_EXGEN+EX_R9(r13)
73 std r12,PACA_EXGEN+EX_R13(r13)
a5d4f3ad 74 EXCEPTION_PROLOG_PSERIES_1(data_access_common, EXC_STD)
c5a8c0c9 75FTR_SECTION_ELSE
a5d4f3ad 76 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common, EXC_STD)
c5a8c0c9 77ALT_FTR_SECTION_END_IFCLR(CPU_FTR_SLB)
0ebc4cda
BH
78
79 . = 0x380
80 .globl data_access_slb_pSeries
81data_access_slb_pSeries:
82 HMT_MEDIUM
842f2fed 83 DO_KVM 0x380
673b189a 84 SET_SCRATCH0(r13)
2dd60d79 85 GET_PACA(r13)
0ebc4cda
BH
86 std r3,PACA_EXSLB+EX_R3(r13)
87 mfspr r3,SPRN_DAR
88 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
89 mfcr r9
90#ifdef __DISABLED__
91 /* Keep that around for when we re-implement dynamic VSIDs */
92 cmpdi r3,0
93 bge slb_miss_user_pseries
94#endif /* __DISABLED__ */
95 std r10,PACA_EXSLB+EX_R10(r13)
96 std r11,PACA_EXSLB+EX_R11(r13)
97 std r12,PACA_EXSLB+EX_R12(r13)
673b189a 98 GET_SCRATCH0(r10)
0ebc4cda
BH
99 std r10,PACA_EXSLB+EX_R13(r13)
100 mfspr r12,SPRN_SRR1 /* and SRR1 */
101#ifndef CONFIG_RELOCATABLE
102 b .slb_miss_realmode
103#else
104 /*
105 * We can't just use a direct branch to .slb_miss_realmode
106 * because the distance from here to there depends on where
107 * the kernel ends up being put.
108 */
109 mfctr r11
110 ld r10,PACAKBASE(r13)
111 LOAD_HANDLER(r10, .slb_miss_realmode)
112 mtctr r10
113 bctr
114#endif
115
b3e6b5df 116 STD_EXCEPTION_PSERIES(0x400, 0x400, instruction_access)
0ebc4cda
BH
117
118 . = 0x480
119 .globl instruction_access_slb_pSeries
120instruction_access_slb_pSeries:
121 HMT_MEDIUM
842f2fed 122 DO_KVM 0x480
673b189a 123 SET_SCRATCH0(r13)
2dd60d79 124 GET_PACA(r13)
0ebc4cda
BH
125 std r3,PACA_EXSLB+EX_R3(r13)
126 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
127 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
128 mfcr r9
129#ifdef __DISABLED__
130 /* Keep that around for when we re-implement dynamic VSIDs */
131 cmpdi r3,0
132 bge slb_miss_user_pseries
133#endif /* __DISABLED__ */
134 std r10,PACA_EXSLB+EX_R10(r13)
135 std r11,PACA_EXSLB+EX_R11(r13)
136 std r12,PACA_EXSLB+EX_R12(r13)
673b189a 137 GET_SCRATCH0(r10)
0ebc4cda
BH
138 std r10,PACA_EXSLB+EX_R13(r13)
139 mfspr r12,SPRN_SRR1 /* and SRR1 */
140#ifndef CONFIG_RELOCATABLE
141 b .slb_miss_realmode
142#else
143 mfctr r11
144 ld r10,PACAKBASE(r13)
145 LOAD_HANDLER(r10, .slb_miss_realmode)
146 mtctr r10
147 bctr
148#endif
149
b3e6b5df
BH
150 /* We open code these as we can't have a ". = x" (even with
151 * x = "." within a feature section
152 */
a5d4f3ad 153 . = 0x500;
b3e6b5df
BH
154 .globl hardware_interrupt_pSeries;
155 .globl hardware_interrupt_hv;
a5d4f3ad 156hardware_interrupt_pSeries:
b3e6b5df 157hardware_interrupt_hv:
a5d4f3ad 158 BEGIN_FTR_SECTION
b3e6b5df 159 _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt, EXC_STD)
a5d4f3ad 160 FTR_SECTION_ELSE
b3e6b5df 161 _MASKABLE_EXCEPTION_PSERIES(0x502, hardware_interrupt, EXC_HV)
a5d4f3ad
BH
162 ALT_FTR_SECTION_END_IFCLR(CPU_FTR_HVMODE_206)
163
b3e6b5df
BH
164 STD_EXCEPTION_PSERIES(0x600, 0x600, alignment)
165 STD_EXCEPTION_PSERIES(0x700, 0x700, program_check)
166 STD_EXCEPTION_PSERIES(0x800, 0x800, fp_unavailable)
a5d4f3ad 167
b3e6b5df
BH
168 MASKABLE_EXCEPTION_PSERIES(0x900, 0x900, decrementer)
169 MASKABLE_EXCEPTION_HV(0x980, 0x980, decrementer)
a5d4f3ad 170
b3e6b5df
BH
171 STD_EXCEPTION_PSERIES(0xa00, 0xa00, trap_0a)
172 STD_EXCEPTION_PSERIES(0xb00, 0xb00, trap_0b)
0ebc4cda
BH
173
174 . = 0xc00
175 .globl system_call_pSeries
176system_call_pSeries:
177 HMT_MEDIUM
842f2fed 178 DO_KVM 0xc00
0ebc4cda
BH
179BEGIN_FTR_SECTION
180 cmpdi r0,0x1ebe
181 beq- 1f
182END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)
183 mr r9,r13
2dd60d79 184 GET_PACA(r13)
0ebc4cda
BH
185 mfspr r11,SPRN_SRR0
186 ld r12,PACAKBASE(r13)
187 ld r10,PACAKMSR(r13)
188 LOAD_HANDLER(r12, system_call_entry)
189 mtspr SPRN_SRR0,r12
190 mfspr r12,SPRN_SRR1
191 mtspr SPRN_SRR1,r10
192 rfid
193 b . /* prevent speculative execution */
194
195/* Fast LE/BE switch system call */
1961: mfspr r12,SPRN_SRR1
197 xori r12,r12,MSR_LE
198 mtspr SPRN_SRR1,r12
199 rfid /* return to userspace */
200 b .
201
b3e6b5df
BH
202 STD_EXCEPTION_PSERIES(0xd00, 0xd00, single_step)
203
204 /* At 0xe??? we have a bunch of hypervisor exceptions, we branch
205 * out of line to handle them
206 */
207 . = 0xe00
208 b h_data_storage_hv
209 . = 0xe20
210 b h_instr_storage_hv
211 . = 0xe40
212 b emulation_assist_hv
213 . = 0xe50
214 b hmi_exception_hv
215 . = 0xe60
216 b hmi_exception_hv
0ebc4cda
BH
217
218 /* We need to deal with the Altivec unavailable exception
219 * here which is at 0xf20, thus in the middle of the
220 * prolog code of the PerformanceMonitor one. A little
221 * trickery is thus necessary
222 */
c86e2ead 223performance_monitor_pSeries_1:
0ebc4cda
BH
224 . = 0xf00
225 b performance_monitor_pSeries
226
c86e2ead 227altivec_unavailable_pSeries_1:
0ebc4cda
BH
228 . = 0xf20
229 b altivec_unavailable_pSeries
230
c86e2ead 231vsx_unavailable_pSeries_1:
0ebc4cda
BH
232 . = 0xf40
233 b vsx_unavailable_pSeries
234
235#ifdef CONFIG_CBE_RAS
b3e6b5df 236 STD_EXCEPTION_HV(0x1200, 0x1202, cbe_system_error)
0ebc4cda 237#endif /* CONFIG_CBE_RAS */
b3e6b5df 238 STD_EXCEPTION_PSERIES(0x1300, 0x1300, instruction_breakpoint)
0ebc4cda 239#ifdef CONFIG_CBE_RAS
b3e6b5df 240 STD_EXCEPTION_HV(0x1600, 0x1602, cbe_maintenance)
0ebc4cda 241#endif /* CONFIG_CBE_RAS */
b3e6b5df 242 STD_EXCEPTION_PSERIES(0x1700, 0x1700, altivec_assist)
0ebc4cda 243#ifdef CONFIG_CBE_RAS
b3e6b5df 244 STD_EXCEPTION_HV(0x1800, 0x1802, cbe_thermal)
0ebc4cda
BH
245#endif /* CONFIG_CBE_RAS */
246
247 . = 0x3000
248
b3e6b5df
BH
249/*** Out of line interrupts support ***/
250
251 /* moved from 0xe00 */
252 STD_EXCEPTION_HV(., 0xe00, h_data_storage)
253 STD_EXCEPTION_HV(., 0xe20, h_instr_storage)
254 STD_EXCEPTION_HV(., 0xe40, emulation_assist)
255 STD_EXCEPTION_HV(., 0xe60, hmi_exception) /* need to flush cache ? */
0ebc4cda
BH
256
257 /* moved from 0xf00 */
b3e6b5df
BH
258 STD_EXCEPTION_PSERIES(., 0xf00, performance_monitor)
259 STD_EXCEPTION_PSERIES(., 0xf20, altivec_unavailable)
260 STD_EXCEPTION_PSERIES(., 0xf40, vsx_unavailable)
0ebc4cda
BH
261
262/*
263 * An interrupt came in while soft-disabled; clear EE in SRR1,
264 * clear paca->hard_enabled and return.
265 */
266masked_interrupt:
267 stb r10,PACAHARDIRQEN(r13)
268 mtcrf 0x80,r9
269 ld r9,PACA_EXGEN+EX_R9(r13)
270 mfspr r10,SPRN_SRR1
271 rldicl r10,r10,48,1 /* clear MSR_EE */
272 rotldi r10,r10,16
273 mtspr SPRN_SRR1,r10
274 ld r10,PACA_EXGEN+EX_R10(r13)
673b189a 275 GET_SCRATCH0(r13)
0ebc4cda
BH
276 rfid
277 b .
278
a5d4f3ad
BH
279masked_Hinterrupt:
280 stb r10,PACAHARDIRQEN(r13)
281 mtcrf 0x80,r9
282 ld r9,PACA_EXGEN+EX_R9(r13)
283 mfspr r10,SPRN_HSRR1
284 rldicl r10,r10,48,1 /* clear MSR_EE */
285 rotldi r10,r10,16
286 mtspr SPRN_HSRR1,r10
287 ld r10,PACA_EXGEN+EX_R10(r13)
673b189a 288 GET_SCRATCH0(r13)
a5d4f3ad
BH
289 hrfid
290 b .
291
0ebc4cda
BH
292 .align 7
293do_stab_bolted_pSeries:
c5a8c0c9
BH
294 std r11,PACA_EXSLB+EX_R11(r13)
295 std r12,PACA_EXSLB+EX_R12(r13)
673b189a 296 GET_SCRATCH0(r10)
c5a8c0c9 297 std r10,PACA_EXSLB+EX_R13(r13)
a5d4f3ad 298 EXCEPTION_PROLOG_PSERIES_1(.do_stab_bolted, EXC_STD)
0ebc4cda
BH
299
300#ifdef CONFIG_PPC_PSERIES
301/*
302 * Vectors for the FWNMI option. Share common code.
303 */
304 .globl system_reset_fwnmi
305 .align 7
306system_reset_fwnmi:
307 HMT_MEDIUM
673b189a 308 SET_SCRATCH0(r13) /* save r13 */
a5d4f3ad 309 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD)
0ebc4cda
BH
310
311 .globl machine_check_fwnmi
312 .align 7
313machine_check_fwnmi:
314 HMT_MEDIUM
673b189a 315 SET_SCRATCH0(r13) /* save r13 */
a5d4f3ad 316 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common, EXC_STD)
0ebc4cda
BH
317
318#endif /* CONFIG_PPC_PSERIES */
319
320#ifdef __DISABLED__
321/*
322 * This is used for when the SLB miss handler has to go virtual,
323 * which doesn't happen for now anymore but will once we re-implement
324 * dynamic VSIDs for shared page tables
325 */
326slb_miss_user_pseries:
327 std r10,PACA_EXGEN+EX_R10(r13)
328 std r11,PACA_EXGEN+EX_R11(r13)
329 std r12,PACA_EXGEN+EX_R12(r13)
673b189a 330 GET_SCRATCH0(r10)
0ebc4cda
BH
331 ld r11,PACA_EXSLB+EX_R9(r13)
332 ld r12,PACA_EXSLB+EX_R3(r13)
333 std r10,PACA_EXGEN+EX_R13(r13)
334 std r11,PACA_EXGEN+EX_R9(r13)
335 std r12,PACA_EXGEN+EX_R3(r13)
336 clrrdi r12,r13,32
337 mfmsr r10
338 mfspr r11,SRR0 /* save SRR0 */
339 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
340 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
341 mtspr SRR0,r12
342 mfspr r12,SRR1 /* and SRR1 */
343 mtspr SRR1,r10
344 rfid
345 b . /* prevent spec. execution */
346#endif /* __DISABLED__ */
347
a58ddea5
AG
348/* KVM's trampoline code needs to be close to the interrupt handlers */
349
350#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
351#include "../kvm/book3s_rmhandlers.S"
352#endif
353
0ebc4cda
BH
354 .align 7
355 .globl __end_interrupts
356__end_interrupts:
357
358/*
359 * Code from here down to __end_handlers is invoked from the
360 * exception prologs above. Because the prologs assemble the
361 * addresses of these handlers using the LOAD_HANDLER macro,
362 * which uses an addi instruction, these handlers must be in
363 * the first 32k of the kernel image.
364 */
365
366/*** Common interrupt handlers ***/
367
368 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
369
370 /*
371 * Machine check is different because we use a different
372 * save area: PACA_EXMC instead of PACA_EXGEN.
373 */
374 .align 7
375 .globl machine_check_common
376machine_check_common:
377 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
378 FINISH_NAP
379 DISABLE_INTS
380 bl .save_nvgprs
381 addi r3,r1,STACK_FRAME_OVERHEAD
382 bl .machine_check_exception
383 b .ret_from_except
384
385 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
386 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
387 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
388 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
389 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
b3e6b5df
BH
390 STD_EXCEPTION_COMMON(0xe40, emulation_assist, .program_check_exception)
391 STD_EXCEPTION_COMMON(0xe60, hmi_exception, .unknown_exception)
0ebc4cda
BH
392 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
393 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
394#ifdef CONFIG_ALTIVEC
395 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
396#else
397 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
398#endif
399#ifdef CONFIG_CBE_RAS
400 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
401 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
402 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
403#endif /* CONFIG_CBE_RAS */
404
405 .align 7
406system_call_entry:
407 b system_call_common
408
409/*
410 * Here we have detected that the kernel stack pointer is bad.
411 * R9 contains the saved CR, r13 points to the paca,
412 * r10 contains the (bad) kernel stack pointer,
413 * r11 and r12 contain the saved SRR0 and SRR1.
414 * We switch to using an emergency stack, save the registers there,
415 * and call kernel_bad_stack(), which panics.
416 */
417bad_stack:
418 ld r1,PACAEMERGSP(r13)
419 subi r1,r1,64+INT_FRAME_SIZE
420 std r9,_CCR(r1)
421 std r10,GPR1(r1)
422 std r11,_NIP(r1)
423 std r12,_MSR(r1)
424 mfspr r11,SPRN_DAR
425 mfspr r12,SPRN_DSISR
426 std r11,_DAR(r1)
427 std r12,_DSISR(r1)
428 mflr r10
429 mfctr r11
430 mfxer r12
431 std r10,_LINK(r1)
432 std r11,_CTR(r1)
433 std r12,_XER(r1)
434 SAVE_GPR(0,r1)
435 SAVE_GPR(2,r1)
436 SAVE_4GPRS(3,r1)
437 SAVE_2GPRS(7,r1)
438 SAVE_10GPRS(12,r1)
439 SAVE_10GPRS(22,r1)
440 lhz r12,PACA_TRAP_SAVE(r13)
441 std r12,_TRAP(r1)
442 addi r11,r1,INT_FRAME_SIZE
443 std r11,0(r1)
444 li r12,0
445 std r12,0(r11)
446 ld r2,PACATOC(r13)
4471: addi r3,r1,STACK_FRAME_OVERHEAD
448 bl .kernel_bad_stack
449 b 1b
450
451/*
452 * Here r13 points to the paca, r9 contains the saved CR,
453 * SRR0 and SRR1 are saved in r11 and r12,
454 * r9 - r13 are saved in paca->exgen.
455 */
456 .align 7
457 .globl data_access_common
458data_access_common:
459 mfspr r10,SPRN_DAR
460 std r10,PACA_EXGEN+EX_DAR(r13)
461 mfspr r10,SPRN_DSISR
462 stw r10,PACA_EXGEN+EX_DSISR(r13)
463 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
464 ld r3,PACA_EXGEN+EX_DAR(r13)
465 lwz r4,PACA_EXGEN+EX_DSISR(r13)
466 li r5,0x300
467 b .do_hash_page /* Try to handle as hpte fault */
468
b3e6b5df
BH
469 .align 7
470 .globl h_data_storage_common
471h_data_storage_common:
472 mfspr r10,SPRN_HDAR
473 std r10,PACA_EXGEN+EX_DAR(r13)
474 mfspr r10,SPRN_HDSISR
475 stw r10,PACA_EXGEN+EX_DSISR(r13)
476 EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
477 bl .save_nvgprs
478 addi r3,r1,STACK_FRAME_OVERHEAD
479 bl .unknown_exception
480 b .ret_from_except
481
0ebc4cda
BH
482 .align 7
483 .globl instruction_access_common
484instruction_access_common:
485 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
486 ld r3,_NIP(r1)
487 andis. r4,r12,0x5820
488 li r5,0x400
489 b .do_hash_page /* Try to handle as hpte fault */
490
b3e6b5df
BH
491 STD_EXCEPTION_COMMON(0xe20, h_instr_storage, .unknown_exception)
492
0ebc4cda
BH
493/*
494 * Here is the common SLB miss user that is used when going to virtual
495 * mode for SLB misses, that is currently not used
496 */
497#ifdef __DISABLED__
498 .align 7
499 .globl slb_miss_user_common
500slb_miss_user_common:
501 mflr r10
502 std r3,PACA_EXGEN+EX_DAR(r13)
503 stw r9,PACA_EXGEN+EX_CCR(r13)
504 std r10,PACA_EXGEN+EX_LR(r13)
505 std r11,PACA_EXGEN+EX_SRR0(r13)
506 bl .slb_allocate_user
507
508 ld r10,PACA_EXGEN+EX_LR(r13)
509 ld r3,PACA_EXGEN+EX_R3(r13)
510 lwz r9,PACA_EXGEN+EX_CCR(r13)
511 ld r11,PACA_EXGEN+EX_SRR0(r13)
512 mtlr r10
513 beq- slb_miss_fault
514
515 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
516 beq- unrecov_user_slb
517 mfmsr r10
518
519.machine push
520.machine "power4"
521 mtcrf 0x80,r9
522.machine pop
523
524 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
525 mtmsrd r10,1
526
527 mtspr SRR0,r11
528 mtspr SRR1,r12
529
530 ld r9,PACA_EXGEN+EX_R9(r13)
531 ld r10,PACA_EXGEN+EX_R10(r13)
532 ld r11,PACA_EXGEN+EX_R11(r13)
533 ld r12,PACA_EXGEN+EX_R12(r13)
534 ld r13,PACA_EXGEN+EX_R13(r13)
535 rfid
536 b .
537
538slb_miss_fault:
539 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
540 ld r4,PACA_EXGEN+EX_DAR(r13)
541 li r5,0
542 std r4,_DAR(r1)
543 std r5,_DSISR(r1)
544 b handle_page_fault
545
546unrecov_user_slb:
547 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
548 DISABLE_INTS
549 bl .save_nvgprs
5501: addi r3,r1,STACK_FRAME_OVERHEAD
551 bl .unrecoverable_exception
552 b 1b
553
554#endif /* __DISABLED__ */
555
556
557/*
558 * r13 points to the PACA, r9 contains the saved CR,
559 * r12 contain the saved SRR1, SRR0 is still ready for return
560 * r3 has the faulting address
561 * r9 - r13 are saved in paca->exslb.
562 * r3 is saved in paca->slb_r3
563 * We assume we aren't going to take any exceptions during this procedure.
564 */
565_GLOBAL(slb_miss_realmode)
566 mflr r10
567#ifdef CONFIG_RELOCATABLE
568 mtctr r11
569#endif
570
571 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
572 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
573
574 bl .slb_allocate_realmode
575
576 /* All done -- return from exception. */
577
578 ld r10,PACA_EXSLB+EX_LR(r13)
579 ld r3,PACA_EXSLB+EX_R3(r13)
580 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
581#ifdef CONFIG_PPC_ISERIES
582BEGIN_FW_FTR_SECTION
583 ld r11,PACALPPACAPTR(r13)
584 ld r11,LPPACASRR0(r11) /* get SRR0 value */
585END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
586#endif /* CONFIG_PPC_ISERIES */
587
588 mtlr r10
589
590 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
591 beq- 2f
592
593.machine push
594.machine "power4"
595 mtcrf 0x80,r9
596 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
597.machine pop
598
599#ifdef CONFIG_PPC_ISERIES
600BEGIN_FW_FTR_SECTION
601 mtspr SPRN_SRR0,r11
602 mtspr SPRN_SRR1,r12
603END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
604#endif /* CONFIG_PPC_ISERIES */
605 ld r9,PACA_EXSLB+EX_R9(r13)
606 ld r10,PACA_EXSLB+EX_R10(r13)
607 ld r11,PACA_EXSLB+EX_R11(r13)
608 ld r12,PACA_EXSLB+EX_R12(r13)
609 ld r13,PACA_EXSLB+EX_R13(r13)
610 rfid
611 b . /* prevent speculative execution */
612
6132:
614#ifdef CONFIG_PPC_ISERIES
615BEGIN_FW_FTR_SECTION
616 b unrecov_slb
617END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
618#endif /* CONFIG_PPC_ISERIES */
619 mfspr r11,SPRN_SRR0
620 ld r10,PACAKBASE(r13)
621 LOAD_HANDLER(r10,unrecov_slb)
622 mtspr SPRN_SRR0,r10
623 ld r10,PACAKMSR(r13)
624 mtspr SPRN_SRR1,r10
625 rfid
626 b .
627
628unrecov_slb:
629 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
630 DISABLE_INTS
631 bl .save_nvgprs
6321: addi r3,r1,STACK_FRAME_OVERHEAD
633 bl .unrecoverable_exception
634 b 1b
635
636 .align 7
637 .globl hardware_interrupt_common
638 .globl hardware_interrupt_entry
639hardware_interrupt_common:
640 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
641 FINISH_NAP
642hardware_interrupt_entry:
643 DISABLE_INTS
644BEGIN_FTR_SECTION
645 bl .ppc64_runlatch_on
646END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
647 addi r3,r1,STACK_FRAME_OVERHEAD
648 bl .do_IRQ
649 b .ret_from_except_lite
650
651#ifdef CONFIG_PPC_970_NAP
652power4_fixup_nap:
653 andc r9,r9,r10
654 std r9,TI_LOCAL_FLAGS(r11)
655 ld r10,_LINK(r1) /* make idle task do the */
656 std r10,_NIP(r1) /* equivalent of a blr */
657 blr
658#endif
659
660 .align 7
661 .globl alignment_common
662alignment_common:
663 mfspr r10,SPRN_DAR
664 std r10,PACA_EXGEN+EX_DAR(r13)
665 mfspr r10,SPRN_DSISR
666 stw r10,PACA_EXGEN+EX_DSISR(r13)
667 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
668 ld r3,PACA_EXGEN+EX_DAR(r13)
669 lwz r4,PACA_EXGEN+EX_DSISR(r13)
670 std r3,_DAR(r1)
671 std r4,_DSISR(r1)
672 bl .save_nvgprs
673 addi r3,r1,STACK_FRAME_OVERHEAD
674 ENABLE_INTS
675 bl .alignment_exception
676 b .ret_from_except
677
678 .align 7
679 .globl program_check_common
680program_check_common:
681 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
682 bl .save_nvgprs
683 addi r3,r1,STACK_FRAME_OVERHEAD
684 ENABLE_INTS
685 bl .program_check_exception
686 b .ret_from_except
687
688 .align 7
689 .globl fp_unavailable_common
690fp_unavailable_common:
691 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
692 bne 1f /* if from user, just load it up */
693 bl .save_nvgprs
694 addi r3,r1,STACK_FRAME_OVERHEAD
695 ENABLE_INTS
696 bl .kernel_fp_unavailable_exception
697 BUG_OPCODE
6981: bl .load_up_fpu
699 b fast_exception_return
700
701 .align 7
702 .globl altivec_unavailable_common
703altivec_unavailable_common:
704 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
705#ifdef CONFIG_ALTIVEC
706BEGIN_FTR_SECTION
707 beq 1f
708 bl .load_up_altivec
709 b fast_exception_return
7101:
711END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
712#endif
713 bl .save_nvgprs
714 addi r3,r1,STACK_FRAME_OVERHEAD
715 ENABLE_INTS
716 bl .altivec_unavailable_exception
717 b .ret_from_except
718
719 .align 7
720 .globl vsx_unavailable_common
721vsx_unavailable_common:
722 EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
723#ifdef CONFIG_VSX
724BEGIN_FTR_SECTION
725 bne .load_up_vsx
7261:
727END_FTR_SECTION_IFSET(CPU_FTR_VSX)
728#endif
729 bl .save_nvgprs
730 addi r3,r1,STACK_FRAME_OVERHEAD
731 ENABLE_INTS
732 bl .vsx_unavailable_exception
733 b .ret_from_except
734
735 .align 7
736 .globl __end_handlers
737__end_handlers:
738
739/*
740 * Return from an exception with minimal checks.
741 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
742 * If interrupts have been enabled, or anything has been
743 * done that might have changed the scheduling status of
744 * any task or sent any task a signal, you should use
745 * ret_from_except or ret_from_except_lite instead of this.
746 */
747fast_exc_return_irq: /* restores irq state too */
748 ld r3,SOFTE(r1)
749 TRACE_AND_RESTORE_IRQ(r3);
750 ld r12,_MSR(r1)
751 rldicl r4,r12,49,63 /* get MSR_EE to LSB */
752 stb r4,PACAHARDIRQEN(r13) /* restore paca->hard_enabled */
753 b 1f
754
755 .globl fast_exception_return
756fast_exception_return:
757 ld r12,_MSR(r1)
7581: ld r11,_NIP(r1)
759 andi. r3,r12,MSR_RI /* check if RI is set */
760 beq- unrecov_fer
761
762#ifdef CONFIG_VIRT_CPU_ACCOUNTING
763 andi. r3,r12,MSR_PR
764 beq 2f
765 ACCOUNT_CPU_USER_EXIT(r3, r4)
7662:
767#endif
768
769 ld r3,_CCR(r1)
770 ld r4,_LINK(r1)
771 ld r5,_CTR(r1)
772 ld r6,_XER(r1)
773 mtcr r3
774 mtlr r4
775 mtctr r5
776 mtxer r6
777 REST_GPR(0, r1)
778 REST_8GPRS(2, r1)
779
780 mfmsr r10
781 rldicl r10,r10,48,1 /* clear EE */
782 rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */
783 mtmsrd r10,1
784
785 mtspr SPRN_SRR1,r12
786 mtspr SPRN_SRR0,r11
787 REST_4GPRS(10, r1)
788 ld r1,GPR1(r1)
789 rfid
790 b . /* prevent speculative execution */
791
792unrecov_fer:
793 bl .save_nvgprs
7941: addi r3,r1,STACK_FRAME_OVERHEAD
795 bl .unrecoverable_exception
796 b 1b
797
798
799/*
800 * Hash table stuff
801 */
802 .align 7
803_STATIC(do_hash_page)
804 std r3,_DAR(r1)
805 std r4,_DSISR(r1)
806
9c7cc234 807 andis. r0,r4,0xa410 /* weird error? */
0ebc4cda 808 bne- handle_page_fault /* if not, try to insert a HPTE */
9c7cc234
P
809 andis. r0,r4,DSISR_DABRMATCH@h
810 bne- handle_dabr_fault
811
0ebc4cda
BH
812BEGIN_FTR_SECTION
813 andis. r0,r4,0x0020 /* Is it a segment table fault? */
814 bne- do_ste_alloc /* If so handle it */
815END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
816
9c1e1052
PM
817 clrrdi r11,r1,THREAD_SHIFT
818 lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
819 andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
820 bne 77f /* then don't call hash_page now */
821
0ebc4cda
BH
822 /*
823 * On iSeries, we soft-disable interrupts here, then
824 * hard-enable interrupts so that the hash_page code can spin on
825 * the hash_table_lock without problems on a shared processor.
826 */
827 DISABLE_INTS
828
829 /*
830 * Currently, trace_hardirqs_off() will be called by DISABLE_INTS
831 * and will clobber volatile registers when irq tracing is enabled
832 * so we need to reload them. It may be possible to be smarter here
833 * and move the irq tracing elsewhere but let's keep it simple for
834 * now
835 */
836#ifdef CONFIG_TRACE_IRQFLAGS
837 ld r3,_DAR(r1)
838 ld r4,_DSISR(r1)
839 ld r5,_TRAP(r1)
840 ld r12,_MSR(r1)
841 clrrdi r5,r5,4
842#endif /* CONFIG_TRACE_IRQFLAGS */
843 /*
844 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
845 * accessing a userspace segment (even from the kernel). We assume
846 * kernel addresses always have the high bit set.
847 */
848 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
849 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
850 orc r0,r12,r0 /* MSR_PR | ~high_bit */
851 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
852 ori r4,r4,1 /* add _PAGE_PRESENT */
853 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
854
855 /*
856 * r3 contains the faulting address
857 * r4 contains the required access permissions
858 * r5 contains the trap number
859 *
860 * at return r3 = 0 for success
861 */
862 bl .hash_page /* build HPTE if possible */
863 cmpdi r3,0 /* see if hash_page succeeded */
864
865BEGIN_FW_FTR_SECTION
866 /*
867 * If we had interrupts soft-enabled at the point where the
868 * DSI/ISI occurred, and an interrupt came in during hash_page,
869 * handle it now.
870 * We jump to ret_from_except_lite rather than fast_exception_return
871 * because ret_from_except_lite will check for and handle pending
872 * interrupts if necessary.
873 */
874 beq 13f
875END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
876
877BEGIN_FW_FTR_SECTION
878 /*
879 * Here we have interrupts hard-disabled, so it is sufficient
880 * to restore paca->{soft,hard}_enable and get out.
881 */
882 beq fast_exc_return_irq /* Return from exception on success */
883END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
884
885 /* For a hash failure, we don't bother re-enabling interrupts */
886 ble- 12f
887
888 /*
889 * hash_page couldn't handle it, set soft interrupt enable back
df9ee292 890 * to what it was before the trap. Note that .arch_local_irq_restore
0ebc4cda
BH
891 * handles any interrupts pending at this point.
892 */
893 ld r3,SOFTE(r1)
894 TRACE_AND_RESTORE_IRQ_PARTIAL(r3, 11f)
df9ee292 895 bl .arch_local_irq_restore
0ebc4cda
BH
896 b 11f
897
9c7cc234
P
898/* We have a data breakpoint exception - handle it */
899handle_dabr_fault:
5aae8a53 900 bl .save_nvgprs
9c7cc234
P
901 ld r4,_DAR(r1)
902 ld r5,_DSISR(r1)
903 addi r3,r1,STACK_FRAME_OVERHEAD
904 bl .do_dabr
905 b .ret_from_except_lite
906
0ebc4cda
BH
907/* Here we have a page fault that hash_page can't handle. */
908handle_page_fault:
909 ENABLE_INTS
91011: ld r4,_DAR(r1)
911 ld r5,_DSISR(r1)
912 addi r3,r1,STACK_FRAME_OVERHEAD
913 bl .do_page_fault
914 cmpdi r3,0
915 beq+ 13f
916 bl .save_nvgprs
917 mr r5,r3
918 addi r3,r1,STACK_FRAME_OVERHEAD
919 lwz r4,_DAR(r1)
920 bl .bad_page_fault
921 b .ret_from_except
922
92313: b .ret_from_except_lite
924
925/* We have a page fault that hash_page could handle but HV refused
926 * the PTE insertion
927 */
92812: bl .save_nvgprs
929 mr r5,r3
930 addi r3,r1,STACK_FRAME_OVERHEAD
931 ld r4,_DAR(r1)
932 bl .low_hash_fault
933 b .ret_from_except
934
9c1e1052
PM
935/*
936 * We come here as a result of a DSI at a point where we don't want
937 * to call hash_page, such as when we are accessing memory (possibly
938 * user memory) inside a PMU interrupt that occurred while interrupts
939 * were soft-disabled. We want to invoke the exception handler for
940 * the access, or panic if there isn't a handler.
941 */
94277: bl .save_nvgprs
943 mr r4,r3
944 addi r3,r1,STACK_FRAME_OVERHEAD
945 li r5,SIGSEGV
946 bl .bad_page_fault
947 b .ret_from_except
948
0ebc4cda
BH
949 /* here we have a segment miss */
950do_ste_alloc:
951 bl .ste_allocate /* try to insert stab entry */
952 cmpdi r3,0
953 bne- handle_page_fault
954 b fast_exception_return
955
956/*
957 * r13 points to the PACA, r9 contains the saved CR,
958 * r11 and r12 contain the saved SRR0 and SRR1.
959 * r9 - r13 are saved in paca->exslb.
960 * We assume we aren't going to take any exceptions during this procedure.
961 * We assume (DAR >> 60) == 0xc.
962 */
963 .align 7
964_GLOBAL(do_stab_bolted)
965 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
966 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
967
968 /* Hash to the primary group */
969 ld r10,PACASTABVIRT(r13)
970 mfspr r11,SPRN_DAR
971 srdi r11,r11,28
972 rldimi r10,r11,7,52 /* r10 = first ste of the group */
973
974 /* Calculate VSID */
975 /* This is a kernel address, so protovsid = ESID */
976 ASM_VSID_SCRAMBLE(r11, r9, 256M)
977 rldic r9,r11,12,16 /* r9 = vsid << 12 */
978
979 /* Search the primary group for a free entry */
9801: ld r11,0(r10) /* Test valid bit of the current ste */
981 andi. r11,r11,0x80
982 beq 2f
983 addi r10,r10,16
984 andi. r11,r10,0x70
985 bne 1b
986
987 /* Stick for only searching the primary group for now. */
988 /* At least for now, we use a very simple random castout scheme */
989 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
990 mftb r11
991 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
992 ori r11,r11,0x10
993
994 /* r10 currently points to an ste one past the group of interest */
995 /* make it point to the randomly selected entry */
996 subi r10,r10,128
997 or r10,r10,r11 /* r10 is the entry to invalidate */
998
999 isync /* mark the entry invalid */
1000 ld r11,0(r10)
1001 rldicl r11,r11,56,1 /* clear the valid bit */
1002 rotldi r11,r11,8
1003 std r11,0(r10)
1004 sync
1005
1006 clrrdi r11,r11,28 /* Get the esid part of the ste */
1007 slbie r11
1008
10092: std r9,8(r10) /* Store the vsid part of the ste */
1010 eieio
1011
1012 mfspr r11,SPRN_DAR /* Get the new esid */
1013 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1014 ori r11,r11,0x90 /* Turn on valid and kp */
1015 std r11,0(r10) /* Put new entry back into the stab */
1016
1017 sync
1018
1019 /* All done -- return from exception. */
1020 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1021 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1022
1023 andi. r10,r12,MSR_RI
1024 beq- unrecov_slb
1025
1026 mtcrf 0x80,r9 /* restore CR */
1027
1028 mfmsr r10
1029 clrrdi r10,r10,2
1030 mtmsrd r10,1
1031
1032 mtspr SPRN_SRR0,r11
1033 mtspr SPRN_SRR1,r12
1034 ld r9,PACA_EXSLB+EX_R9(r13)
1035 ld r10,PACA_EXSLB+EX_R10(r13)
1036 ld r11,PACA_EXSLB+EX_R11(r13)
1037 ld r12,PACA_EXSLB+EX_R12(r13)
1038 ld r13,PACA_EXSLB+EX_R13(r13)
1039 rfid
1040 b . /* prevent speculative execution */
1041
0ebc4cda
BH
1042#ifdef CONFIG_PPC_PSERIES
1043/*
1044 * Data area reserved for FWNMI option.
1045 * This address (0x7000) is fixed by the RPA.
1046 */
1047 .= 0x7000
1048 .globl fwnmi_data_area
1049fwnmi_data_area:
1050#endif /* CONFIG_PPC_PSERIES */
1051
1052 /* iSeries does not use the FWNMI stuff, so it is safe to put
1053 * this here, even if we later allow kernels that will boot on
1054 * both pSeries and iSeries */
1055#ifdef CONFIG_PPC_ISERIES
1056 . = LPARMAP_PHYS
1057 .globl xLparMap
1058xLparMap:
1059 .quad HvEsidsToMap /* xNumberEsids */
1060 .quad HvRangesToMap /* xNumberRanges */
1061 .quad STAB0_PAGE /* xSegmentTableOffs */
1062 .zero 40 /* xRsvd */
1063 /* xEsids (HvEsidsToMap entries of 2 quads) */
1064 .quad PAGE_OFFSET_ESID /* xKernelEsid */
1065 .quad PAGE_OFFSET_VSID /* xKernelVsid */
1066 .quad VMALLOC_START_ESID /* xKernelEsid */
1067 .quad VMALLOC_START_VSID /* xKernelVsid */
1068 /* xRanges (HvRangesToMap entries of 3 quads) */
1069 .quad HvPagesToMap /* xPages */
1070 .quad 0 /* xOffset */
1071 .quad PAGE_OFFSET_VSID << (SID_SHIFT - HW_PAGE_SHIFT) /* xVPN */
1072
1073#endif /* CONFIG_PPC_ISERIES */
1074
1075#ifdef CONFIG_PPC_PSERIES
1076 . = 0x8000
1077#endif /* CONFIG_PPC_PSERIES */
84493804
BH
1078
1079/*
1080 * Space for CPU0's segment table.
1081 *
1082 * On iSeries, the hypervisor must fill in at least one entry before
1083 * we get control (with relocate on). The address is given to the hv
1084 * as a page number (see xLparMap above), so this must be at a
1085 * fixed address (the linker can't compute (u64)&initial_stab >>
1086 * PAGE_SHIFT).
1087 */
1088 . = STAB0_OFFSET /* 0x8000 */
1089 .globl initial_stab
1090initial_stab:
1091 .space 4096