Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
0ebc4cda BH |
2 | /* |
3 | * This file contains the 64-bit "server" PowerPC variant | |
4 | * of the low level exception handling including exception | |
5 | * vectors, exception return, part of the slb and stab | |
6 | * handling and other fixed offset specific things. | |
7 | * | |
8 | * This file is meant to be #included from head_64.S due to | |
25985edc | 9 | * position dependent assembly. |
0ebc4cda BH |
10 | * |
11 | * Most of this originates from head_64.S and thus has the same | |
12 | * copyright history. | |
13 | * | |
14 | */ | |
15 | ||
7230c564 | 16 | #include <asm/hw_irq.h> |
8aa34ab8 | 17 | #include <asm/exception-64s.h> |
46f52210 | 18 | #include <asm/ptrace.h> |
7cba160a | 19 | #include <asm/cpuidle.h> |
da2bc464 | 20 | #include <asm/head-64.h> |
2c86cd18 | 21 | #include <asm/feature-fixups.h> |
890274c2 | 22 | #include <asm/kup.h> |
8aa34ab8 | 23 | |
15820091 NP |
24 | /* PACA save area offsets (exgen, exmc, etc) */ |
25 | #define EX_R9 0 | |
26 | #define EX_R10 8 | |
27 | #define EX_R11 16 | |
28 | #define EX_R12 24 | |
29 | #define EX_R13 32 | |
30 | #define EX_DAR 40 | |
31 | #define EX_DSISR 48 | |
32 | #define EX_CCR 52 | |
33 | #define EX_CFAR 56 | |
34 | #define EX_PPR 64 | |
35 | #if defined(CONFIG_RELOCATABLE) | |
36 | #define EX_CTR 72 | |
37 | .if EX_SIZE != 10 | |
38 | .error "EX_SIZE is wrong" | |
39 | .endif | |
40 | #else | |
41 | .if EX_SIZE != 9 | |
42 | .error "EX_SIZE is wrong" | |
43 | .endif | |
44 | #endif | |
45 | ||
12a04809 NP |
46 | /* |
47 | * We're short on space and time in the exception prolog, so we can't | |
48 | * use the normal LOAD_REG_IMMEDIATE macro to load the address of label. | |
49 | * Instead we get the base of the kernel from paca->kernelbase and or in the low | |
50 | * part of label. This requires that the label be within 64KB of kernelbase, and | |
51 | * that kernelbase be 64K aligned. | |
52 | */ | |
53 | #define LOAD_HANDLER(reg, label) \ | |
54 | ld reg,PACAKBASE(r13); /* get high part of &label */ \ | |
55 | ori reg,reg,FIXED_SYMBOL_ABS_ADDR(label) | |
56 | ||
57 | #define __LOAD_HANDLER(reg, label) \ | |
58 | ld reg,PACAKBASE(r13); \ | |
59 | ori reg,reg,(ABS_ADDR(label))@l | |
60 | ||
61 | /* | |
62 | * Branches from unrelocated code (e.g., interrupts) to labels outside | |
63 | * head-y require >64K offsets. | |
64 | */ | |
65 | #define __LOAD_FAR_HANDLER(reg, label) \ | |
66 | ld reg,PACAKBASE(r13); \ | |
67 | ori reg,reg,(ABS_ADDR(label))@l; \ | |
68 | addis reg,reg,(ABS_ADDR(label))@h | |
69 | ||
70 | /* Exception register prefixes */ | |
71 | #define EXC_HV 1 | |
72 | #define EXC_STD 0 | |
73 | ||
74 | #if defined(CONFIG_RELOCATABLE) | |
75 | /* | |
76 | * If we support interrupts with relocation on AND we're a relocatable kernel, | |
77 | * we need to use CTR to get to the 2nd level handler. So, save/restore it | |
78 | * when required. | |
79 | */ | |
80 | #define SAVE_CTR(reg, area) mfctr reg ; std reg,area+EX_CTR(r13) | |
81 | #define GET_CTR(reg, area) ld reg,area+EX_CTR(r13) | |
82 | #define RESTORE_CTR(reg, area) ld reg,area+EX_CTR(r13) ; mtctr reg | |
83 | #else | |
84 | /* ...else CTR is unused and in register. */ | |
85 | #define SAVE_CTR(reg, area) | |
86 | #define GET_CTR(reg, area) mfctr reg | |
87 | #define RESTORE_CTR(reg, area) | |
88 | #endif | |
89 | ||
90 | /* | |
91 | * PPR save/restore macros used in exceptions-64s.S | |
92 | * Used for P7 or later processors | |
93 | */ | |
94 | #define SAVE_PPR(area, ra) \ | |
95 | BEGIN_FTR_SECTION_NESTED(940) \ | |
96 | ld ra,area+EX_PPR(r13); /* Read PPR from paca */ \ | |
97 | std ra,_PPR(r1); \ | |
98 | END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940) | |
99 | ||
100 | #define RESTORE_PPR_PACA(area, ra) \ | |
101 | BEGIN_FTR_SECTION_NESTED(941) \ | |
102 | ld ra,area+EX_PPR(r13); \ | |
103 | mtspr SPRN_PPR,ra; \ | |
104 | END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,941) | |
105 | ||
106 | /* | |
107 | * Get an SPR into a register if the CPU has the given feature | |
108 | */ | |
109 | #define OPT_GET_SPR(ra, spr, ftr) \ | |
110 | BEGIN_FTR_SECTION_NESTED(943) \ | |
111 | mfspr ra,spr; \ | |
112 | END_FTR_SECTION_NESTED(ftr,ftr,943) | |
113 | ||
114 | /* | |
115 | * Set an SPR from a register if the CPU has the given feature | |
116 | */ | |
117 | #define OPT_SET_SPR(ra, spr, ftr) \ | |
118 | BEGIN_FTR_SECTION_NESTED(943) \ | |
119 | mtspr spr,ra; \ | |
120 | END_FTR_SECTION_NESTED(ftr,ftr,943) | |
121 | ||
122 | /* | |
123 | * Save a register to the PACA if the CPU has the given feature | |
124 | */ | |
125 | #define OPT_SAVE_REG_TO_PACA(offset, ra, ftr) \ | |
126 | BEGIN_FTR_SECTION_NESTED(943) \ | |
127 | std ra,offset(r13); \ | |
128 | END_FTR_SECTION_NESTED(ftr,ftr,943) | |
129 | ||
130 | .macro EXCEPTION_PROLOG_0 area | |
131 | GET_PACA(r13) | |
132 | std r9,\area\()+EX_R9(r13) /* save r9 */ | |
133 | OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR) | |
134 | HMT_MEDIUM | |
135 | std r10,\area\()+EX_R10(r13) /* save r10 - r12 */ | |
136 | OPT_GET_SPR(r10, SPRN_CFAR, CPU_FTR_CFAR) | |
137 | .endm | |
138 | ||
5312c494 | 139 | .macro EXCEPTION_PROLOG_1 hsrr, area, kvm, vec, dar, dsisr, bitmask |
12a04809 NP |
140 | OPT_SAVE_REG_TO_PACA(\area\()+EX_PPR, r9, CPU_FTR_HAS_PPR) |
141 | OPT_SAVE_REG_TO_PACA(\area\()+EX_CFAR, r10, CPU_FTR_CFAR) | |
142 | INTERRUPT_TO_KERNEL | |
143 | SAVE_CTR(r10, \area\()) | |
144 | mfcr r9 | |
145 | .if \kvm | |
146 | KVMTEST \hsrr \vec | |
147 | .endif | |
148 | .if \bitmask | |
149 | lbz r10,PACAIRQSOFTMASK(r13) | |
150 | andi. r10,r10,\bitmask | |
151 | /* Associate vector numbers with bits in paca->irq_happened */ | |
152 | .if \vec == 0x500 || \vec == 0xea0 | |
153 | li r10,PACA_IRQ_EE | |
154 | .elseif \vec == 0x900 | |
155 | li r10,PACA_IRQ_DEC | |
156 | .elseif \vec == 0xa00 || \vec == 0xe80 | |
157 | li r10,PACA_IRQ_DBELL | |
158 | .elseif \vec == 0xe60 | |
159 | li r10,PACA_IRQ_HMI | |
160 | .elseif \vec == 0xf00 | |
161 | li r10,PACA_IRQ_PMI | |
162 | .else | |
163 | .abort "Bad maskable vector" | |
164 | .endif | |
165 | ||
166 | .if \hsrr | |
167 | bne masked_Hinterrupt | |
168 | .else | |
169 | bne masked_interrupt | |
170 | .endif | |
171 | .endif | |
172 | ||
173 | std r11,\area\()+EX_R11(r13) | |
174 | std r12,\area\()+EX_R12(r13) | |
5312c494 NP |
175 | |
176 | /* | |
177 | * DAR/DSISR, SCRATCH0 must be read before setting MSR[RI], | |
178 | * because a d-side MCE will clobber those registers so is | |
179 | * not recoverable if they are live. | |
180 | */ | |
12a04809 NP |
181 | GET_SCRATCH0(r10) |
182 | std r10,\area\()+EX_R13(r13) | |
5312c494 NP |
183 | .if \dar |
184 | mfspr r10,SPRN_DAR | |
185 | std r10,\area\()+EX_DAR(r13) | |
186 | .endif | |
187 | .if \dsisr | |
188 | mfspr r10,SPRN_DSISR | |
189 | stw r10,\area\()+EX_DSISR(r13) | |
190 | .endif | |
12a04809 NP |
191 | .endm |
192 | ||
193 | .macro EXCEPTION_PROLOG_2_REAL label, hsrr, set_ri | |
194 | ld r10,PACAKMSR(r13) /* get MSR value for kernel */ | |
195 | .if ! \set_ri | |
196 | xori r10,r10,MSR_RI /* Clear MSR_RI */ | |
197 | .endif | |
198 | .if \hsrr | |
199 | mfspr r11,SPRN_HSRR0 /* save HSRR0 */ | |
63d60d0c NP |
200 | mfspr r12,SPRN_HSRR1 /* and HSRR1 */ |
201 | mtspr SPRN_HSRR1,r10 | |
12a04809 NP |
202 | .else |
203 | mfspr r11,SPRN_SRR0 /* save SRR0 */ | |
63d60d0c NP |
204 | mfspr r12,SPRN_SRR1 /* and SRR1 */ |
205 | mtspr SPRN_SRR1,r10 | |
12a04809 | 206 | .endif |
63d60d0c | 207 | LOAD_HANDLER(r10, \label\()) |
12a04809 | 208 | .if \hsrr |
63d60d0c | 209 | mtspr SPRN_HSRR0,r10 |
12a04809 NP |
210 | HRFI_TO_KERNEL |
211 | .else | |
63d60d0c | 212 | mtspr SPRN_SRR0,r10 |
12a04809 NP |
213 | RFI_TO_KERNEL |
214 | .endif | |
215 | b . /* prevent speculative execution */ | |
216 | .endm | |
217 | ||
218 | .macro EXCEPTION_PROLOG_2_VIRT label, hsrr | |
219 | #ifdef CONFIG_RELOCATABLE | |
220 | .if \hsrr | |
221 | mfspr r11,SPRN_HSRR0 /* save HSRR0 */ | |
222 | .else | |
223 | mfspr r11,SPRN_SRR0 /* save SRR0 */ | |
224 | .endif | |
225 | LOAD_HANDLER(r12, \label\()) | |
226 | mtctr r12 | |
227 | .if \hsrr | |
228 | mfspr r12,SPRN_HSRR1 /* and HSRR1 */ | |
229 | .else | |
230 | mfspr r12,SPRN_SRR1 /* and HSRR1 */ | |
231 | .endif | |
232 | li r10,MSR_RI | |
233 | mtmsrd r10,1 /* Set RI (EE=0) */ | |
234 | bctr | |
235 | #else | |
236 | .if \hsrr | |
237 | mfspr r11,SPRN_HSRR0 /* save HSRR0 */ | |
238 | mfspr r12,SPRN_HSRR1 /* and HSRR1 */ | |
239 | .else | |
240 | mfspr r11,SPRN_SRR0 /* save SRR0 */ | |
241 | mfspr r12,SPRN_SRR1 /* and SRR1 */ | |
242 | .endif | |
243 | li r10,MSR_RI | |
244 | mtmsrd r10,1 /* Set RI (EE=0) */ | |
245 | b \label | |
246 | #endif | |
247 | .endm | |
248 | ||
249 | /* | |
250 | * Branch to label using its 0xC000 address. This results in instruction | |
251 | * address suitable for MSR[IR]=0 or 1, which allows relocation to be turned | |
252 | * on using mtmsr rather than rfid. | |
253 | * | |
254 | * This could set the 0xc bits for !RELOCATABLE as an immediate, rather than | |
255 | * load KBASE for a slight optimisation. | |
256 | */ | |
257 | #define BRANCH_TO_C000(reg, label) \ | |
258 | __LOAD_HANDLER(reg, label); \ | |
259 | mtctr reg; \ | |
260 | bctr | |
261 | ||
262 | #ifdef CONFIG_RELOCATABLE | |
12a04809 NP |
263 | #define BRANCH_LINK_TO_FAR(label) \ |
264 | __LOAD_FAR_HANDLER(r12, label); \ | |
265 | mtctr r12; \ | |
266 | bctrl | |
267 | ||
268 | #else | |
12a04809 NP |
269 | #define BRANCH_LINK_TO_FAR(label) \ |
270 | bl label | |
271 | #endif | |
272 | ||
273 | #ifdef CONFIG_KVM_BOOK3S_64_HANDLER | |
12a04809 NP |
274 | #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE |
275 | /* | |
276 | * If hv is possible, interrupts come into to the hv version | |
277 | * of the kvmppc_interrupt code, which then jumps to the PR handler, | |
278 | * kvmppc_interrupt_pr, if the guest is a PR guest. | |
279 | */ | |
280 | #define kvmppc_interrupt kvmppc_interrupt_hv | |
281 | #else | |
282 | #define kvmppc_interrupt kvmppc_interrupt_pr | |
283 | #endif | |
284 | ||
285 | .macro KVMTEST hsrr, n | |
286 | lbz r10,HSTATE_IN_GUEST(r13) | |
287 | cmpwi r10,0 | |
288 | .if \hsrr | |
289 | bne do_kvm_H\n | |
290 | .else | |
291 | bne do_kvm_\n | |
292 | .endif | |
293 | .endm | |
294 | ||
295 | .macro KVM_HANDLER area, hsrr, n, skip | |
296 | .if \skip | |
297 | cmpwi r10,KVM_GUEST_MODE_SKIP | |
298 | beq 89f | |
299 | .else | |
bf66e3c4 | 300 | BEGIN_FTR_SECTION_NESTED(947) |
12a04809 NP |
301 | ld r10,\area+EX_CFAR(r13) |
302 | std r10,HSTATE_CFAR(r13) | |
bf66e3c4 | 303 | END_FTR_SECTION_NESTED(CPU_FTR_CFAR,CPU_FTR_CFAR,947) |
12a04809 NP |
304 | .endif |
305 | ||
bf66e3c4 | 306 | BEGIN_FTR_SECTION_NESTED(948) |
12a04809 NP |
307 | ld r10,\area+EX_PPR(r13) |
308 | std r10,HSTATE_PPR(r13) | |
bf66e3c4 | 309 | END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948) |
12a04809 NP |
310 | ld r10,\area+EX_R10(r13) |
311 | std r12,HSTATE_SCRATCH0(r13) | |
312 | sldi r12,r9,32 | |
313 | /* HSRR variants have the 0x2 bit added to their trap number */ | |
314 | .if \hsrr | |
315 | ori r12,r12,(\n + 0x2) | |
316 | .else | |
317 | ori r12,r12,(\n) | |
318 | .endif | |
64e41351 NP |
319 | |
320 | #ifdef CONFIG_RELOCATABLE | |
321 | /* | |
322 | * KVM requires __LOAD_FAR_HANDLER beause kvmppc_interrupt lives | |
323 | * outside the head section. CONFIG_RELOCATABLE KVM expects CTR | |
324 | * to be saved in HSTATE_SCRATCH1. | |
325 | */ | |
326 | mfctr r9 | |
327 | std r9,HSTATE_SCRATCH1(r13) | |
328 | __LOAD_FAR_HANDLER(r9, kvmppc_interrupt) | |
329 | mtctr r9 | |
330 | ld r9,\area+EX_R9(r13) | |
331 | bctr | |
332 | #else | |
333 | ld r9,\area+EX_R9(r13) | |
334 | b kvmppc_interrupt | |
335 | #endif | |
336 | ||
12a04809 NP |
337 | |
338 | .if \skip | |
339 | 89: mtocrf 0x80,r9 | |
340 | ld r9,\area+EX_R9(r13) | |
341 | ld r10,\area+EX_R10(r13) | |
342 | .if \hsrr | |
343 | b kvmppc_skip_Hinterrupt | |
344 | .else | |
345 | b kvmppc_skip_interrupt | |
346 | .endif | |
347 | .endif | |
348 | .endm | |
349 | ||
350 | #else | |
351 | .macro KVMTEST hsrr, n | |
352 | .endm | |
353 | .macro KVM_HANDLER area, hsrr, n, skip | |
354 | .endm | |
355 | #endif | |
356 | ||
357 | #define EXCEPTION_PROLOG_COMMON_1() \ | |
358 | std r9,_CCR(r1); /* save CR in stackframe */ \ | |
359 | std r11,_NIP(r1); /* save SRR0 in stackframe */ \ | |
360 | std r12,_MSR(r1); /* save SRR1 in stackframe */ \ | |
361 | std r10,0(r1); /* make stack chain pointer */ \ | |
362 | std r0,GPR0(r1); /* save r0 in stackframe */ \ | |
363 | std r10,GPR1(r1); /* save r1 in stackframe */ \ | |
364 | ||
12a04809 NP |
365 | /* Save original regs values from save area to stack frame. */ |
366 | #define EXCEPTION_PROLOG_COMMON_2(area) \ | |
367 | ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \ | |
368 | ld r10,area+EX_R10(r13); \ | |
369 | std r9,GPR9(r1); \ | |
370 | std r10,GPR10(r1); \ | |
371 | ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \ | |
372 | ld r10,area+EX_R12(r13); \ | |
373 | ld r11,area+EX_R13(r13); \ | |
374 | std r9,GPR11(r1); \ | |
375 | std r10,GPR12(r1); \ | |
376 | std r11,GPR13(r1); \ | |
bf66e3c4 | 377 | BEGIN_FTR_SECTION_NESTED(66); \ |
12a04809 NP |
378 | ld r10,area+EX_CFAR(r13); \ |
379 | std r10,ORIG_GPR3(r1); \ | |
bf66e3c4 | 380 | END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \ |
12a04809 NP |
381 | GET_CTR(r10, area); \ |
382 | std r10,_CTR(r1); | |
383 | ||
d064151f | 384 | #define EXCEPTION_PROLOG_COMMON_3(trap) \ |
12a04809 NP |
385 | std r2,GPR2(r1); /* save r2 in stackframe */ \ |
386 | SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \ | |
387 | SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \ | |
388 | mflr r9; /* Get LR, later save to stack */ \ | |
389 | ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \ | |
390 | std r9,_LINK(r1); \ | |
391 | lbz r10,PACAIRQSOFTMASK(r13); \ | |
392 | mfspr r11,SPRN_XER; /* save XER in stackframe */ \ | |
393 | std r10,SOFTE(r1); \ | |
394 | std r11,_XER(r1); \ | |
d064151f | 395 | li r9,(trap)+1; \ |
12a04809 NP |
396 | std r9,_TRAP(r1); /* set trap number */ \ |
397 | li r10,0; \ | |
398 | ld r11,exception_marker@toc(r2); \ | |
399 | std r10,RESULT(r1); /* clear regs->result */ \ | |
400 | std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */ | |
401 | ||
d064151f NP |
402 | /* |
403 | * On entry r13 points to the paca, r9-r13 are saved in the paca, | |
404 | * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and | |
405 | * SRR1, and relocation is on. | |
406 | */ | |
407 | #define EXCEPTION_COMMON(area, trap) \ | |
408 | andi. r10,r12,MSR_PR; /* See if coming from user */ \ | |
409 | mr r10,r1; /* Save r1 */ \ | |
410 | subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \ | |
411 | beq- 1f; \ | |
412 | ld r1,PACAKSAVE(r13); /* kernel stack to use */ \ | |
413 | 1: cmpdi cr1,r1,-INT_FRAME_SIZE; /* check if r1 is in userspace */ \ | |
414 | blt+ cr1,3f; /* abort if it is */ \ | |
415 | li r1,(trap); /* will be reloaded later */ \ | |
416 | sth r1,PACA_TRAP_SAVE(r13); \ | |
417 | std r3,area+EX_R3(r13); \ | |
418 | addi r3,r13,area; /* r3 -> where regs are saved*/ \ | |
419 | RESTORE_CTR(r1, area); \ | |
420 | b bad_stack; \ | |
421 | 3: EXCEPTION_PROLOG_COMMON_1(); \ | |
422 | kuap_save_amr_and_lock r9, r10, cr1, cr0; \ | |
423 | beq 4f; /* if from kernel mode */ \ | |
424 | ACCOUNT_CPU_USER_ENTRY(r13, r9, r10); \ | |
425 | SAVE_PPR(area, r9); \ | |
426 | 4: EXCEPTION_PROLOG_COMMON_2(area); \ | |
427 | EXCEPTION_PROLOG_COMMON_3(trap); \ | |
428 | ACCOUNT_STOLEN_TIME | |
12a04809 | 429 | |
12a04809 NP |
430 | |
431 | /* | |
d064151f NP |
432 | * Exception where stack is already set in r1, r1 is saved in r10. |
433 | * PPR save and CPU accounting is not done (for some reason). | |
12a04809 NP |
434 | */ |
435 | #define EXCEPTION_COMMON_STACK(area, trap) \ | |
436 | EXCEPTION_PROLOG_COMMON_1(); \ | |
437 | kuap_save_amr_and_lock r9, r10, cr1; \ | |
438 | EXCEPTION_PROLOG_COMMON_2(area); \ | |
439 | EXCEPTION_PROLOG_COMMON_3(trap) | |
440 | ||
391e941b NP |
441 | /* |
442 | * Restore all registers including H/SRR0/1 saved in a stack frame of a | |
443 | * standard exception. | |
444 | */ | |
445 | .macro EXCEPTION_RESTORE_REGS hsrr | |
446 | /* Move original SRR0 and SRR1 into the respective regs */ | |
447 | ld r9,_MSR(r1) | |
448 | .if \hsrr | |
449 | mtspr SPRN_HSRR1,r9 | |
450 | .else | |
451 | mtspr SPRN_SRR1,r9 | |
452 | .endif | |
453 | ld r9,_NIP(r1) | |
454 | .if \hsrr | |
455 | mtspr SPRN_HSRR0,r9 | |
456 | .else | |
457 | mtspr SPRN_SRR0,r9 | |
458 | .endif | |
459 | ld r9,_CTR(r1) | |
460 | mtctr r9 | |
461 | ld r9,_XER(r1) | |
462 | mtxer r9 | |
463 | ld r9,_LINK(r1) | |
464 | mtlr r9 | |
465 | ld r9,_CCR(r1) | |
466 | mtcr r9 | |
467 | REST_8GPRS(2, r1) | |
468 | REST_4GPRS(10, r1) | |
469 | REST_GPR(0, r1) | |
470 | /* restore original r1. */ | |
471 | ld r1,GPR1(r1) | |
472 | .endm | |
d064151f NP |
473 | |
474 | #define RUNLATCH_ON \ | |
475 | BEGIN_FTR_SECTION \ | |
476 | ld r3, PACA_THREAD_INFO(r13); \ | |
477 | ld r4,TI_LOCAL_FLAGS(r3); \ | |
478 | andi. r0,r4,_TLF_RUNLATCH; \ | |
479 | beql ppc64_runlatch_on_trampoline; \ | |
480 | END_FTR_SECTION_IFSET(CPU_FTR_CTRL) | |
481 | ||
12a04809 NP |
482 | /* |
483 | * When the idle code in power4_idle puts the CPU into NAP mode, | |
484 | * it has to do so in a loop, and relies on the external interrupt | |
485 | * and decrementer interrupt entry code to get it out of the loop. | |
486 | * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags | |
487 | * to signal that it is in the loop and needs help to get out. | |
488 | */ | |
489 | #ifdef CONFIG_PPC_970_NAP | |
490 | #define FINISH_NAP \ | |
491 | BEGIN_FTR_SECTION \ | |
492 | ld r11, PACA_THREAD_INFO(r13); \ | |
493 | ld r9,TI_LOCAL_FLAGS(r11); \ | |
494 | andi. r10,r9,_TLF_NAPPING; \ | |
495 | bnel power4_fixup_nap; \ | |
496 | END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP) | |
497 | #else | |
498 | #define FINISH_NAP | |
499 | #endif | |
500 | ||
a0502434 NP |
501 | /* |
502 | * Following are the BOOK3S exception handler helper macros. | |
503 | * Handlers come in a number of types, and each type has a number of varieties. | |
504 | * | |
505 | * EXC_REAL_* - real, unrelocated exception vectors | |
506 | * EXC_VIRT_* - virt (AIL), unrelocated exception vectors | |
507 | * TRAMP_REAL_* - real, unrelocated helpers (virt can call these) | |
508 | * TRAMP_VIRT_* - virt, unreloc helpers (in practice, real can use) | |
509 | * TRAMP_KVM - KVM handlers that get put into real, unrelocated | |
510 | * EXC_COMMON - virt, relocated common handlers | |
511 | * | |
512 | * The EXC handlers are given a name, and branch to name_common, or the | |
513 | * appropriate KVM or masking function. Vector handler verieties are as | |
514 | * follows: | |
515 | * | |
516 | * EXC_{REAL|VIRT}_BEGIN/END - used to open-code the exception | |
517 | * | |
518 | * EXC_{REAL|VIRT} - standard exception | |
519 | * | |
520 | * EXC_{REAL|VIRT}_suffix | |
521 | * where _suffix is: | |
522 | * - _MASKABLE - maskable exception | |
523 | * - _OOL - out of line with trampoline to common handler | |
524 | * - _HV - HV exception | |
525 | * | |
526 | * There can be combinations, e.g., EXC_VIRT_OOL_MASKABLE_HV | |
527 | * | |
528 | * The one unusual case is __EXC_REAL_OOL_HV_DIRECT, which is | |
529 | * an OOL vector that branches to a specified handler rather than the usual | |
530 | * trampoline that goes to common. It, and other underscore macros, should | |
531 | * be used with care. | |
532 | * | |
533 | * KVM handlers come in the following verieties: | |
534 | * TRAMP_KVM | |
535 | * TRAMP_KVM_SKIP | |
536 | * TRAMP_KVM_HV | |
537 | * TRAMP_KVM_HV_SKIP | |
538 | * | |
539 | * COMMON handlers come in the following verieties: | |
540 | * EXC_COMMON_BEGIN/END - used to open-code the handler | |
541 | * EXC_COMMON | |
542 | * EXC_COMMON_ASYNC | |
543 | * | |
544 | * TRAMP_REAL and TRAMP_VIRT can be used with BEGIN/END. KVM | |
545 | * and OOL handlers are implemented as types of TRAMP and TRAMP_VIRT handlers. | |
546 | */ | |
547 | ||
548 | #define __EXC_REAL(name, start, size, area) \ | |
549 | EXC_REAL_BEGIN(name, start, size); \ | |
550 | SET_SCRATCH0(r13); /* save r13 */ \ | |
551 | EXCEPTION_PROLOG_0 area ; \ | |
5312c494 | 552 | EXCEPTION_PROLOG_1 EXC_STD, area, 1, start, 0, 0, 0 ; \ |
a0502434 NP |
553 | EXCEPTION_PROLOG_2_REAL name##_common, EXC_STD, 1 ; \ |
554 | EXC_REAL_END(name, start, size) | |
555 | ||
556 | #define EXC_REAL(name, start, size) \ | |
557 | __EXC_REAL(name, start, size, PACA_EXGEN) | |
558 | ||
559 | #define __EXC_VIRT(name, start, size, realvec, area) \ | |
560 | EXC_VIRT_BEGIN(name, start, size); \ | |
561 | SET_SCRATCH0(r13); /* save r13 */ \ | |
562 | EXCEPTION_PROLOG_0 area ; \ | |
5312c494 | 563 | EXCEPTION_PROLOG_1 EXC_STD, area, 0, realvec, 0, 0, 0; \ |
a0502434 NP |
564 | EXCEPTION_PROLOG_2_VIRT name##_common, EXC_STD ; \ |
565 | EXC_VIRT_END(name, start, size) | |
566 | ||
567 | #define EXC_VIRT(name, start, size, realvec) \ | |
568 | __EXC_VIRT(name, start, size, realvec, PACA_EXGEN) | |
569 | ||
570 | #define EXC_REAL_MASKABLE(name, start, size, bitmask) \ | |
571 | EXC_REAL_BEGIN(name, start, size); \ | |
572 | SET_SCRATCH0(r13); /* save r13 */ \ | |
573 | EXCEPTION_PROLOG_0 PACA_EXGEN ; \ | |
5312c494 | 574 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, start, 0, 0, bitmask ; \ |
a0502434 NP |
575 | EXCEPTION_PROLOG_2_REAL name##_common, EXC_STD, 1 ; \ |
576 | EXC_REAL_END(name, start, size) | |
577 | ||
578 | #define EXC_VIRT_MASKABLE(name, start, size, realvec, bitmask) \ | |
579 | EXC_VIRT_BEGIN(name, start, size); \ | |
580 | SET_SCRATCH0(r13); /* save r13 */ \ | |
581 | EXCEPTION_PROLOG_0 PACA_EXGEN ; \ | |
5312c494 | 582 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 0, realvec, 0, 0, bitmask ; \ |
a0502434 NP |
583 | EXCEPTION_PROLOG_2_VIRT name##_common, EXC_STD ; \ |
584 | EXC_VIRT_END(name, start, size) | |
585 | ||
586 | #define EXC_REAL_HV(name, start, size) \ | |
587 | EXC_REAL_BEGIN(name, start, size); \ | |
588 | SET_SCRATCH0(r13); /* save r13 */ \ | |
589 | EXCEPTION_PROLOG_0 PACA_EXGEN; \ | |
5312c494 | 590 | EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, start, 0, 0, 0 ; \ |
a0502434 NP |
591 | EXCEPTION_PROLOG_2_REAL name##_common, EXC_HV, 1 ; \ |
592 | EXC_REAL_END(name, start, size) | |
593 | ||
594 | #define EXC_VIRT_HV(name, start, size, realvec) \ | |
595 | EXC_VIRT_BEGIN(name, start, size); \ | |
596 | SET_SCRATCH0(r13); /* save r13 */ \ | |
597 | EXCEPTION_PROLOG_0 PACA_EXGEN; \ | |
5312c494 | 598 | EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, realvec, 0, 0, 0 ; \ |
a0502434 NP |
599 | EXCEPTION_PROLOG_2_VIRT name##_common, EXC_HV ; \ |
600 | EXC_VIRT_END(name, start, size) | |
601 | ||
602 | #define __EXC_REAL_OOL(name, start, size) \ | |
603 | EXC_REAL_BEGIN(name, start, size); \ | |
604 | SET_SCRATCH0(r13); \ | |
605 | EXCEPTION_PROLOG_0 PACA_EXGEN ; \ | |
606 | b tramp_real_##name ; \ | |
607 | EXC_REAL_END(name, start, size) | |
608 | ||
609 | #define __TRAMP_REAL_OOL(name, vec) \ | |
610 | TRAMP_REAL_BEGIN(tramp_real_##name); \ | |
5312c494 | 611 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, vec, 0, 0, 0 ; \ |
a0502434 NP |
612 | EXCEPTION_PROLOG_2_REAL name##_common, EXC_STD, 1 |
613 | ||
614 | #define EXC_REAL_OOL(name, start, size) \ | |
615 | __EXC_REAL_OOL(name, start, size); \ | |
616 | __TRAMP_REAL_OOL(name, start) | |
617 | ||
618 | #define __EXC_REAL_OOL_MASKABLE(name, start, size) \ | |
619 | __EXC_REAL_OOL(name, start, size) | |
620 | ||
621 | #define __TRAMP_REAL_OOL_MASKABLE(name, vec, bitmask) \ | |
622 | TRAMP_REAL_BEGIN(tramp_real_##name); \ | |
5312c494 | 623 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, vec, 0, 0, bitmask ; \ |
a0502434 NP |
624 | EXCEPTION_PROLOG_2_REAL name##_common, EXC_STD, 1 |
625 | ||
626 | #define EXC_REAL_OOL_MASKABLE(name, start, size, bitmask) \ | |
627 | __EXC_REAL_OOL_MASKABLE(name, start, size); \ | |
628 | __TRAMP_REAL_OOL_MASKABLE(name, start, bitmask) | |
629 | ||
630 | #define __EXC_REAL_OOL_HV_DIRECT(name, start, size, handler) \ | |
631 | EXC_REAL_BEGIN(name, start, size); \ | |
632 | SET_SCRATCH0(r13); \ | |
633 | EXCEPTION_PROLOG_0 PACA_EXGEN ; \ | |
634 | b handler; \ | |
635 | EXC_REAL_END(name, start, size) | |
636 | ||
637 | #define __EXC_REAL_OOL_HV(name, start, size) \ | |
638 | __EXC_REAL_OOL(name, start, size) | |
639 | ||
640 | #define __TRAMP_REAL_OOL_HV(name, vec) \ | |
641 | TRAMP_REAL_BEGIN(tramp_real_##name); \ | |
5312c494 | 642 | EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, vec, 0, 0, 0 ; \ |
a0502434 NP |
643 | EXCEPTION_PROLOG_2_REAL name##_common, EXC_HV, 1 |
644 | ||
645 | #define EXC_REAL_OOL_HV(name, start, size) \ | |
646 | __EXC_REAL_OOL_HV(name, start, size); \ | |
647 | __TRAMP_REAL_OOL_HV(name, start) | |
648 | ||
649 | #define __EXC_REAL_OOL_MASKABLE_HV(name, start, size) \ | |
650 | __EXC_REAL_OOL(name, start, size) | |
651 | ||
652 | #define __TRAMP_REAL_OOL_MASKABLE_HV(name, vec, bitmask) \ | |
653 | TRAMP_REAL_BEGIN(tramp_real_##name); \ | |
5312c494 | 654 | EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, vec, 0, 0, bitmask ; \ |
a0502434 NP |
655 | EXCEPTION_PROLOG_2_REAL name##_common, EXC_HV, 1 |
656 | ||
657 | #define EXC_REAL_OOL_MASKABLE_HV(name, start, size, bitmask) \ | |
658 | __EXC_REAL_OOL_MASKABLE_HV(name, start, size); \ | |
659 | __TRAMP_REAL_OOL_MASKABLE_HV(name, start, bitmask) | |
660 | ||
661 | #define __EXC_VIRT_OOL(name, start, size) \ | |
662 | EXC_VIRT_BEGIN(name, start, size); \ | |
663 | SET_SCRATCH0(r13); \ | |
664 | EXCEPTION_PROLOG_0 PACA_EXGEN ; \ | |
665 | b tramp_virt_##name; \ | |
666 | EXC_VIRT_END(name, start, size) | |
667 | ||
668 | #define __TRAMP_VIRT_OOL(name, realvec) \ | |
669 | TRAMP_VIRT_BEGIN(tramp_virt_##name); \ | |
5312c494 | 670 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 0, vec, 0, 0, 0 ; \ |
a0502434 NP |
671 | EXCEPTION_PROLOG_2_VIRT name##_common, EXC_STD |
672 | ||
673 | #define EXC_VIRT_OOL(name, start, size, realvec) \ | |
674 | __EXC_VIRT_OOL(name, start, size); \ | |
675 | __TRAMP_VIRT_OOL(name, realvec) | |
676 | ||
677 | #define __EXC_VIRT_OOL_MASKABLE(name, start, size) \ | |
678 | __EXC_VIRT_OOL(name, start, size) | |
679 | ||
680 | #define __TRAMP_VIRT_OOL_MASKABLE(name, realvec, bitmask) \ | |
681 | TRAMP_VIRT_BEGIN(tramp_virt_##name); \ | |
5312c494 | 682 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 0, realvec, 0, 0, bitmask ; \ |
a0502434 NP |
683 | EXCEPTION_PROLOG_2_REAL name##_common, EXC_STD, 1 |
684 | ||
685 | #define EXC_VIRT_OOL_MASKABLE(name, start, size, realvec, bitmask) \ | |
686 | __EXC_VIRT_OOL_MASKABLE(name, start, size); \ | |
687 | __TRAMP_VIRT_OOL_MASKABLE(name, realvec, bitmask) | |
688 | ||
689 | #define __EXC_VIRT_OOL_HV(name, start, size) \ | |
690 | __EXC_VIRT_OOL(name, start, size) | |
691 | ||
692 | #define __TRAMP_VIRT_OOL_HV(name, realvec) \ | |
693 | TRAMP_VIRT_BEGIN(tramp_virt_##name); \ | |
5312c494 | 694 | EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, realvec, 0, 0, 0 ; \ |
a0502434 NP |
695 | EXCEPTION_PROLOG_2_VIRT name##_common, EXC_HV |
696 | ||
697 | #define EXC_VIRT_OOL_HV(name, start, size, realvec) \ | |
698 | __EXC_VIRT_OOL_HV(name, start, size); \ | |
699 | __TRAMP_VIRT_OOL_HV(name, realvec) | |
700 | ||
701 | #define __EXC_VIRT_OOL_MASKABLE_HV(name, start, size) \ | |
702 | __EXC_VIRT_OOL(name, start, size) | |
703 | ||
704 | #define __TRAMP_VIRT_OOL_MASKABLE_HV(name, realvec, bitmask) \ | |
705 | TRAMP_VIRT_BEGIN(tramp_virt_##name); \ | |
5312c494 | 706 | EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, realvec, 0, 0, bitmask ; \ |
a0502434 NP |
707 | EXCEPTION_PROLOG_2_VIRT name##_common, EXC_HV |
708 | ||
709 | #define EXC_VIRT_OOL_MASKABLE_HV(name, start, size, realvec, bitmask) \ | |
710 | __EXC_VIRT_OOL_MASKABLE_HV(name, start, size); \ | |
711 | __TRAMP_VIRT_OOL_MASKABLE_HV(name, realvec, bitmask) | |
712 | ||
713 | #define TRAMP_KVM(area, n) \ | |
714 | TRAMP_KVM_BEGIN(do_kvm_##n); \ | |
715 | KVM_HANDLER area, EXC_STD, n, 0 | |
716 | ||
717 | #define TRAMP_KVM_SKIP(area, n) \ | |
718 | TRAMP_KVM_BEGIN(do_kvm_##n); \ | |
719 | KVM_HANDLER area, EXC_STD, n, 1 | |
720 | ||
721 | #define TRAMP_KVM_HV(area, n) \ | |
722 | TRAMP_KVM_BEGIN(do_kvm_H##n); \ | |
723 | KVM_HANDLER area, EXC_HV, n, 0 | |
724 | ||
725 | #define TRAMP_KVM_HV_SKIP(area, n) \ | |
726 | TRAMP_KVM_BEGIN(do_kvm_H##n); \ | |
727 | KVM_HANDLER area, EXC_HV, n, 1 | |
728 | ||
729 | #define EXC_COMMON(name, realvec, hdlr) \ | |
730 | EXC_COMMON_BEGIN(name); \ | |
731 | EXCEPTION_COMMON(PACA_EXGEN, realvec); \ | |
732 | bl save_nvgprs; \ | |
733 | RECONCILE_IRQ_STATE(r10, r11); \ | |
734 | addi r3,r1,STACK_FRAME_OVERHEAD; \ | |
735 | bl hdlr; \ | |
736 | b ret_from_except | |
737 | ||
738 | /* | |
739 | * Like EXC_COMMON, but for exceptions that can occur in the idle task and | |
740 | * therefore need the special idle handling (finish nap and runlatch) | |
741 | */ | |
742 | #define EXC_COMMON_ASYNC(name, realvec, hdlr) \ | |
743 | EXC_COMMON_BEGIN(name); \ | |
744 | EXCEPTION_COMMON(PACA_EXGEN, realvec); \ | |
745 | FINISH_NAP; \ | |
746 | RECONCILE_IRQ_STATE(r10, r11); \ | |
747 | RUNLATCH_ON; \ | |
748 | addi r3,r1,STACK_FRAME_OVERHEAD; \ | |
749 | bl hdlr; \ | |
750 | b ret_from_except_lite | |
751 | ||
12a04809 | 752 | |
0ebc4cda | 753 | /* |
57f26649 NP |
754 | * There are a few constraints to be concerned with. |
755 | * - Real mode exceptions code/data must be located at their physical location. | |
756 | * - Virtual mode exceptions must be mapped at their 0xc000... location. | |
757 | * - Fixed location code must not call directly beyond the __end_interrupts | |
758 | * area when built with CONFIG_RELOCATABLE. LOAD_HANDLER / bctr sequence | |
759 | * must be used. | |
760 | * - LOAD_HANDLER targets must be within first 64K of physical 0 / | |
761 | * virtual 0xc00... | |
762 | * - Conditional branch targets must be within +/-32K of caller. | |
763 | * | |
764 | * "Virtual exceptions" run with relocation on (MSR_IR=1, MSR_DR=1), and | |
765 | * therefore don't have to run in physically located code or rfid to | |
766 | * virtual mode kernel code. However on relocatable kernels they do have | |
767 | * to branch to KERNELBASE offset because the rest of the kernel (outside | |
768 | * the exception vectors) may be located elsewhere. | |
769 | * | |
770 | * Virtual exceptions correspond with physical, except their entry points | |
771 | * are offset by 0xc000000000000000 and also tend to get an added 0x4000 | |
772 | * offset applied. Virtual exceptions are enabled with the Alternate | |
773 | * Interrupt Location (AIL) bit set in the LPCR. However this does not | |
774 | * guarantee they will be delivered virtually. Some conditions (see the ISA) | |
775 | * cause exceptions to be delivered in real mode. | |
776 | * | |
777 | * It's impossible to receive interrupts below 0x300 via AIL. | |
778 | * | |
779 | * KVM: None of the virtual exceptions are from the guest. Anything that | |
780 | * escalated to HV=1 from HV=0 is delivered via real mode handlers. | |
781 | * | |
782 | * | |
0ebc4cda BH |
783 | * We layout physical memory as follows: |
784 | * 0x0000 - 0x00ff : Secondary processor spin code | |
57f26649 NP |
785 | * 0x0100 - 0x18ff : Real mode pSeries interrupt vectors |
786 | * 0x1900 - 0x3fff : Real mode trampolines | |
787 | * 0x4000 - 0x58ff : Relon (IR=1,DR=1) mode pSeries interrupt vectors | |
788 | * 0x5900 - 0x6fff : Relon mode trampolines | |
0ebc4cda | 789 | * 0x7000 - 0x7fff : FWNMI data area |
57f26649 NP |
790 | * 0x8000 - .... : Common interrupt handlers, remaining early |
791 | * setup code, rest of kernel. | |
e0319829 NP |
792 | * |
793 | * We could reclaim 0x4000-0x42ff for real mode trampolines if the space | |
794 | * is necessary. Until then it's more consistent to explicitly put VIRT_NONE | |
795 | * vectors there. | |
57f26649 NP |
796 | */ |
797 | OPEN_FIXED_SECTION(real_vectors, 0x0100, 0x1900) | |
798 | OPEN_FIXED_SECTION(real_trampolines, 0x1900, 0x4000) | |
799 | OPEN_FIXED_SECTION(virt_vectors, 0x4000, 0x5900) | |
800 | OPEN_FIXED_SECTION(virt_trampolines, 0x5900, 0x7000) | |
ccd47702 NP |
801 | |
802 | #ifdef CONFIG_PPC_POWERNV | |
bd3524fe NP |
803 | .globl start_real_trampolines |
804 | .globl end_real_trampolines | |
805 | .globl start_virt_trampolines | |
806 | .globl end_virt_trampolines | |
ccd47702 NP |
807 | #endif |
808 | ||
57f26649 NP |
809 | #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) |
810 | /* | |
811 | * Data area reserved for FWNMI option. | |
812 | * This address (0x7000) is fixed by the RPA. | |
813 | * pseries and powernv need to keep the whole page from | |
814 | * 0x7000 to 0x8000 free for use by the firmware | |
0ebc4cda | 815 | */ |
57f26649 NP |
816 | ZERO_FIXED_SECTION(fwnmi_page, 0x7000, 0x8000) |
817 | OPEN_TEXT_SECTION(0x8000) | |
818 | #else | |
819 | OPEN_TEXT_SECTION(0x7000) | |
820 | #endif | |
821 | ||
822 | USE_FIXED_SECTION(real_vectors) | |
823 | ||
0ebc4cda BH |
824 | /* |
825 | * This is the start of the interrupt handlers for pSeries | |
826 | * This code runs with relocation off. | |
827 | * Code from here to __end_interrupts gets copied down to real | |
828 | * address 0x100 when we are running a relocatable kernel. | |
829 | * Therefore any relative branches in this section must only | |
830 | * branch to labels in this section. | |
831 | */ | |
0ebc4cda BH |
832 | .globl __start_interrupts |
833 | __start_interrupts: | |
834 | ||
e0319829 | 835 | /* No virt vectors corresponding with 0x0..0x100 */ |
1a6822d1 | 836 | EXC_VIRT_NONE(0x4000, 0x100) |
e0319829 | 837 | |
fb479e44 | 838 | |
a7c1ca19 NP |
839 | EXC_REAL_BEGIN(system_reset, 0x100, 0x100) |
840 | SET_SCRATCH0(r13) | |
5dba1d50 | 841 | EXCEPTION_PROLOG_0 PACA_EXNMI |
a7c1ca19 NP |
842 | |
843 | /* This is EXCEPTION_PROLOG_1 with the idle feature section added */ | |
844 | OPT_SAVE_REG_TO_PACA(PACA_EXNMI+EX_PPR, r9, CPU_FTR_HAS_PPR) | |
845 | OPT_SAVE_REG_TO_PACA(PACA_EXNMI+EX_CFAR, r10, CPU_FTR_CFAR) | |
846 | INTERRUPT_TO_KERNEL | |
847 | SAVE_CTR(r10, PACA_EXNMI) | |
848 | mfcr r9 | |
849 | ||
948cf67c | 850 | #ifdef CONFIG_PPC_P7_NAP |
fb479e44 NP |
851 | /* |
852 | * If running native on arch 2.06 or later, check if we are waking up | |
ba6d334a BH |
853 | * from nap/sleep/winkle, and branch to idle handler. This tests SRR1 |
854 | * bits 46:47. A non-0 value indicates that we are coming from a power | |
855 | * saving state. The idle wakeup handler initially runs in real mode, | |
856 | * but we branch to the 0xc000... address so we can turn on relocation | |
857 | * with mtmsr. | |
948cf67c | 858 | */ |
bf66e3c4 | 859 | BEGIN_FTR_SECTION |
a7c1ca19 NP |
860 | mfspr r10,SPRN_SRR1 |
861 | rlwinm. r10,r10,47-31,30,31 | |
862 | beq- 1f | |
863 | cmpwi cr1,r10,2 | |
864 | mfspr r3,SPRN_SRR1 | |
865 | bltlr cr1 /* no state loss, return to idle caller */ | |
866 | BRANCH_TO_C000(r10, system_reset_idle_common) | |
867 | 1: | |
bf66e3c4 | 868 | END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) |
fb479e44 | 869 | #endif |
371fefd6 | 870 | |
a7c1ca19 NP |
871 | KVMTEST EXC_STD 0x100 |
872 | std r11,PACA_EXNMI+EX_R11(r13) | |
873 | std r12,PACA_EXNMI+EX_R12(r13) | |
874 | GET_SCRATCH0(r10) | |
875 | std r10,PACA_EXNMI+EX_R13(r13) | |
876 | ||
877 | EXCEPTION_PROLOG_2_REAL system_reset_common, EXC_STD, 0 | |
c4f3b52c NP |
878 | /* |
879 | * MSR_RI is not enabled, because PACA_EXNMI and nmi stack is | |
880 | * being used, so a nested NMI exception would corrupt it. | |
881 | */ | |
fb479e44 | 882 | |
1a6822d1 NP |
883 | EXC_REAL_END(system_reset, 0x100, 0x100) |
884 | EXC_VIRT_NONE(0x4100, 0x100) | |
6de6638b | 885 | TRAMP_KVM(PACA_EXNMI, 0x100) |
fb479e44 NP |
886 | |
887 | #ifdef CONFIG_PPC_P7_NAP | |
888 | EXC_COMMON_BEGIN(system_reset_idle_common) | |
10d91611 NP |
889 | /* |
890 | * This must be a direct branch (without linker branch stub) because | |
891 | * we can not use TOC at this point as r2 may not be restored yet. | |
892 | */ | |
893 | b idle_return_gpr_loss | |
371fefd6 PM |
894 | #endif |
895 | ||
a3d96f70 | 896 | EXC_COMMON_BEGIN(system_reset_common) |
c4f3b52c NP |
897 | /* |
898 | * Increment paca->in_nmi then enable MSR_RI. SLB or MCE will be able | |
899 | * to recover, but nested NMI will notice in_nmi and not recover | |
900 | * because of the use of the NMI stack. in_nmi reentrancy is tested in | |
901 | * system_reset_exception. | |
902 | */ | |
903 | lhz r10,PACA_IN_NMI(r13) | |
904 | addi r10,r10,1 | |
905 | sth r10,PACA_IN_NMI(r13) | |
906 | li r10,MSR_RI | |
907 | mtmsrd r10,1 | |
aca79d2b | 908 | |
b1ee8a3d NP |
909 | mr r10,r1 |
910 | ld r1,PACA_NMI_EMERG_SP(r13) | |
911 | subi r1,r1,INT_FRAME_SIZE | |
47169fba NP |
912 | EXCEPTION_COMMON_STACK(PACA_EXNMI, 0x100) |
913 | bl save_nvgprs | |
914 | /* | |
915 | * Set IRQS_ALL_DISABLED unconditionally so arch_irqs_disabled does | |
916 | * the right thing. We do not want to reconcile because that goes | |
917 | * through irq tracing which we don't want in NMI. | |
918 | * | |
919 | * Save PACAIRQHAPPENED because some code will do a hard disable | |
920 | * (e.g., xmon). So we want to restore this back to where it was | |
921 | * when we return. DAR is unused in the stack, so save it there. | |
922 | */ | |
923 | li r10,IRQS_ALL_DISABLED | |
924 | stb r10,PACAIRQSOFTMASK(r13) | |
925 | lbz r10,PACAIRQHAPPENED(r13) | |
926 | std r10,_DAR(r1) | |
927 | ||
c06075f3 NP |
928 | addi r3,r1,STACK_FRAME_OVERHEAD |
929 | bl system_reset_exception | |
15b4dd79 | 930 | |
15b4dd79 | 931 | /* Clear MSR_RI before setting SRR0 and SRR1. */ |
fbc50063 | 932 | li r9,0 |
15b4dd79 | 933 | mtmsrd r9,1 |
c4f3b52c NP |
934 | |
935 | /* | |
15b4dd79 | 936 | * MSR_RI is clear, now we can decrement paca->in_nmi. |
c4f3b52c NP |
937 | */ |
938 | lhz r10,PACA_IN_NMI(r13) | |
939 | subi r10,r10,1 | |
940 | sth r10,PACA_IN_NMI(r13) | |
941 | ||
15b4dd79 NP |
942 | /* |
943 | * Restore soft mask settings. | |
944 | */ | |
945 | ld r10,_DAR(r1) | |
946 | stb r10,PACAIRQHAPPENED(r13) | |
947 | ld r10,SOFTE(r1) | |
948 | stb r10,PACAIRQSOFTMASK(r13) | |
949 | ||
391e941b | 950 | EXCEPTION_RESTORE_REGS EXC_STD |
15b4dd79 | 951 | RFI_TO_USER_OR_KERNEL |
582baf44 NP |
952 | |
953 | #ifdef CONFIG_PPC_PSERIES | |
954 | /* | |
955 | * Vectors for the FWNMI option. Share common code. | |
956 | */ | |
957 | TRAMP_REAL_BEGIN(system_reset_fwnmi) | |
958 | SET_SCRATCH0(r13) /* save r13 */ | |
fc557537 NP |
959 | /* See comment at system_reset exception, don't turn on RI */ |
960 | EXCEPTION_PROLOG_0 PACA_EXNMI | |
5312c494 | 961 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXNMI, 0, 0x100, 0, 0, 0 |
fc557537 NP |
962 | EXCEPTION_PROLOG_2_REAL system_reset_common, EXC_STD, 0 |
963 | ||
582baf44 NP |
964 | #endif /* CONFIG_PPC_PSERIES */ |
965 | ||
0ebc4cda | 966 | |
1a6822d1 | 967 | EXC_REAL_BEGIN(machine_check, 0x200, 0x100) |
b01c8b54 PM |
968 | /* This is moved out of line as it can be patched by FW, but |
969 | * some code path might still want to branch into the original | |
970 | * vector | |
971 | */ | |
1707dd16 | 972 | SET_SCRATCH0(r13) /* save r13 */ |
5dba1d50 | 973 | EXCEPTION_PROLOG_0 PACA_EXMC |
1e9b4507 | 974 | BEGIN_FTR_SECTION |
db7d31ac | 975 | b machine_check_common_early |
1e9b4507 | 976 | FTR_SECTION_ELSE |
1707dd16 | 977 | b machine_check_pSeries_0 |
1e9b4507 | 978 | ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE) |
1a6822d1 NP |
979 | EXC_REAL_END(machine_check, 0x200, 0x100) |
980 | EXC_VIRT_NONE(0x4200, 0x100) | |
db7d31ac | 981 | TRAMP_REAL_BEGIN(machine_check_common_early) |
5312c494 | 982 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 0, 0x200, 0, 0, 0 |
afcf0095 NP |
983 | /* |
984 | * Register contents: | |
985 | * R13 = PACA | |
986 | * R9 = CR | |
987 | * Original R9 to R13 is saved on PACA_EXMC | |
988 | * | |
989 | * Switch to mc_emergency stack and handle re-entrancy (we limit | |
990 | * the nested MCE upto level 4 to avoid stack overflow). | |
991 | * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1 | |
992 | * | |
993 | * We use paca->in_mce to check whether this is the first entry or | |
994 | * nested machine check. We increment paca->in_mce to track nested | |
995 | * machine checks. | |
996 | * | |
997 | * If this is the first entry then set stack pointer to | |
998 | * paca->mc_emergency_sp, otherwise r1 is already pointing to | |
999 | * stack frame on mc_emergency stack. | |
1000 | * | |
1001 | * NOTE: We are here with MSR_ME=0 (off), which means we risk a | |
1002 | * checkstop if we get another machine check exception before we do | |
1003 | * rfid with MSR_ME=1. | |
1945bc45 NP |
1004 | * |
1005 | * This interrupt can wake directly from idle. If that is the case, | |
1006 | * the machine check is handled then the idle wakeup code is called | |
2bf1071a | 1007 | * to restore state. |
afcf0095 NP |
1008 | */ |
1009 | mr r11,r1 /* Save r1 */ | |
1010 | lhz r10,PACA_IN_MCE(r13) | |
1011 | cmpwi r10,0 /* Are we in nested machine check */ | |
1012 | bne 0f /* Yes, we are. */ | |
1013 | /* First machine check entry */ | |
1014 | ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */ | |
1015 | 0: subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */ | |
1016 | addi r10,r10,1 /* increment paca->in_mce */ | |
1017 | sth r10,PACA_IN_MCE(r13) | |
1018 | /* Limit nested MCE to level 4 to avoid stack overflow */ | |
ba41e1e1 | 1019 | cmpwi r10,MAX_MCE_DEPTH |
afcf0095 NP |
1020 | bgt 2f /* Check if we hit limit of 4 */ |
1021 | std r11,GPR1(r1) /* Save r1 on the stack. */ | |
1022 | std r11,0(r1) /* make stack chain pointer */ | |
1023 | mfspr r11,SPRN_SRR0 /* Save SRR0 */ | |
1024 | std r11,_NIP(r1) | |
1025 | mfspr r11,SPRN_SRR1 /* Save SRR1 */ | |
1026 | std r11,_MSR(r1) | |
1027 | mfspr r11,SPRN_DAR /* Save DAR */ | |
1028 | std r11,_DAR(r1) | |
1029 | mfspr r11,SPRN_DSISR /* Save DSISR */ | |
1030 | std r11,_DSISR(r1) | |
1031 | std r9,_CCR(r1) /* Save CR in stackframe */ | |
e13e7cd4 | 1032 | /* We don't touch AMR here, we never go to virtual mode */ |
afcf0095 NP |
1033 | /* Save r9 through r13 from EXMC save area to stack frame. */ |
1034 | EXCEPTION_PROLOG_COMMON_2(PACA_EXMC) | |
1035 | mfmsr r11 /* get MSR value */ | |
db7d31ac | 1036 | BEGIN_FTR_SECTION |
afcf0095 | 1037 | ori r11,r11,MSR_ME /* turn on ME bit */ |
db7d31ac | 1038 | END_FTR_SECTION_IFSET(CPU_FTR_HVMODE) |
afcf0095 NP |
1039 | ori r11,r11,MSR_RI /* turn on RI bit */ |
1040 | LOAD_HANDLER(r12, machine_check_handle_early) | |
1041 | 1: mtspr SPRN_SRR0,r12 | |
1042 | mtspr SPRN_SRR1,r11 | |
222f20f1 | 1043 | RFI_TO_KERNEL |
afcf0095 NP |
1044 | b . /* prevent speculative execution */ |
1045 | 2: | |
1046 | /* Stack overflow. Stay on emergency stack and panic. | |
1047 | * Keep the ME bit off while panic-ing, so that if we hit | |
1048 | * another machine check we checkstop. | |
1049 | */ | |
1050 | addi r1,r1,INT_FRAME_SIZE /* go back to previous stack frame */ | |
1051 | ld r11,PACAKMSR(r13) | |
1052 | LOAD_HANDLER(r12, unrecover_mce) | |
1053 | li r10,MSR_ME | |
1054 | andc r11,r11,r10 /* Turn off MSR_ME */ | |
1055 | b 1b | |
1056 | b . /* prevent speculative execution */ | |
afcf0095 NP |
1057 | |
1058 | TRAMP_REAL_BEGIN(machine_check_pSeries) | |
1059 | .globl machine_check_fwnmi | |
1060 | machine_check_fwnmi: | |
1061 | SET_SCRATCH0(r13) /* save r13 */ | |
5dba1d50 | 1062 | EXCEPTION_PROLOG_0 PACA_EXMC |
a43c1590 | 1063 | BEGIN_FTR_SECTION |
db7d31ac | 1064 | b machine_check_common_early |
a43c1590 | 1065 | END_FTR_SECTION_IFCLR(CPU_FTR_HVMODE) |
afcf0095 | 1066 | machine_check_pSeries_0: |
5312c494 | 1067 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 1, 0x200, 0, 0, 0 |
afcf0095 | 1068 | /* |
83a980f7 NP |
1069 | * MSR_RI is not enabled, because PACA_EXMC is being used, so a |
1070 | * nested machine check corrupts it. machine_check_common enables | |
1071 | * MSR_RI. | |
afcf0095 | 1072 | */ |
2d046308 | 1073 | EXCEPTION_PROLOG_2_REAL machine_check_common, EXC_STD, 0 |
afcf0095 NP |
1074 | |
1075 | TRAMP_KVM_SKIP(PACA_EXMC, 0x200) | |
1076 | ||
1077 | EXC_COMMON_BEGIN(machine_check_common) | |
1078 | /* | |
1079 | * Machine check is different because we use a different | |
1080 | * save area: PACA_EXMC instead of PACA_EXGEN. | |
1081 | */ | |
1082 | mfspr r10,SPRN_DAR | |
1083 | std r10,PACA_EXMC+EX_DAR(r13) | |
1084 | mfspr r10,SPRN_DSISR | |
1085 | stw r10,PACA_EXMC+EX_DSISR(r13) | |
d064151f | 1086 | EXCEPTION_COMMON(PACA_EXMC, 0x200) |
afcf0095 NP |
1087 | FINISH_NAP |
1088 | RECONCILE_IRQ_STATE(r10, r11) | |
1089 | ld r3,PACA_EXMC+EX_DAR(r13) | |
1090 | lwz r4,PACA_EXMC+EX_DSISR(r13) | |
1091 | /* Enable MSR_RI when finished with PACA_EXMC */ | |
1092 | li r10,MSR_RI | |
1093 | mtmsrd r10,1 | |
1094 | std r3,_DAR(r1) | |
1095 | std r4,_DSISR(r1) | |
1096 | bl save_nvgprs | |
1097 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1098 | bl machine_check_exception | |
1099 | b ret_from_except | |
1100 | ||
1101 | #define MACHINE_CHECK_HANDLER_WINDUP \ | |
1102 | /* Clear MSR_RI before setting SRR0 and SRR1. */\ | |
fbc50063 | 1103 | li r9,0; \ |
afcf0095 | 1104 | mtmsrd r9,1; /* Clear MSR_RI */ \ |
ad73d8d4 NP |
1105 | /* Decrement paca->in_mce now RI is clear. */ \ |
1106 | lhz r12,PACA_IN_MCE(r13); \ | |
1107 | subi r12,r12,1; \ | |
1108 | sth r12,PACA_IN_MCE(r13); \ | |
391e941b | 1109 | EXCEPTION_RESTORE_REGS EXC_STD |
afcf0095 | 1110 | |
1945bc45 NP |
1111 | #ifdef CONFIG_PPC_P7_NAP |
1112 | /* | |
1113 | * This is an idle wakeup. Low level machine check has already been | |
1114 | * done. Queue the event then call the idle code to do the wake up. | |
1115 | */ | |
1116 | EXC_COMMON_BEGIN(machine_check_idle_common) | |
1117 | bl machine_check_queue_event | |
1118 | ||
1119 | /* | |
1120 | * We have not used any non-volatile GPRs here, and as a rule | |
1121 | * most exception code including machine check does not. | |
1122 | * Therefore PACA_NAPSTATELOST does not need to be set. Idle | |
1123 | * wakeup will restore volatile registers. | |
1124 | * | |
1125 | * Load the original SRR1 into r3 for pnv_powersave_wakeup_mce. | |
1126 | * | |
1127 | * Then decrement MCE nesting after finishing with the stack. | |
1128 | */ | |
1129 | ld r3,_MSR(r1) | |
10d91611 | 1130 | ld r4,_LINK(r1) |
1945bc45 NP |
1131 | |
1132 | lhz r11,PACA_IN_MCE(r13) | |
1133 | subi r11,r11,1 | |
1134 | sth r11,PACA_IN_MCE(r13) | |
1135 | ||
10d91611 NP |
1136 | mtlr r4 |
1137 | rlwinm r10,r3,47-31,30,31 | |
1138 | cmpwi cr1,r10,2 | |
1139 | bltlr cr1 /* no state loss, return to idle caller */ | |
1140 | b idle_return_gpr_loss | |
1945bc45 | 1141 | #endif |
afcf0095 NP |
1142 | /* |
1143 | * Handle machine check early in real mode. We come here with | |
1144 | * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack. | |
1145 | */ | |
1146 | EXC_COMMON_BEGIN(machine_check_handle_early) | |
1147 | std r0,GPR0(r1) /* Save r0 */ | |
1148 | EXCEPTION_PROLOG_COMMON_3(0x200) | |
1149 | bl save_nvgprs | |
1150 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1151 | bl machine_check_early | |
1152 | std r3,RESULT(r1) /* Save result */ | |
1153 | ld r12,_MSR(r1) | |
db7d31ac MS |
1154 | BEGIN_FTR_SECTION |
1155 | b 4f | |
1156 | END_FTR_SECTION_IFCLR(CPU_FTR_HVMODE) | |
1945bc45 | 1157 | |
afcf0095 NP |
1158 | #ifdef CONFIG_PPC_P7_NAP |
1159 | /* | |
1160 | * Check if thread was in power saving mode. We come here when any | |
1161 | * of the following is true: | |
1162 | * a. thread wasn't in power saving mode | |
1163 | * b. thread was in power saving mode with no state loss, | |
1164 | * supervisor state loss or hypervisor state loss. | |
1165 | * | |
1166 | * Go back to nap/sleep/winkle mode again if (b) is true. | |
1167 | */ | |
bf66e3c4 | 1168 | BEGIN_FTR_SECTION |
1945bc45 | 1169 | rlwinm. r11,r12,47-31,30,31 |
6102c005 | 1170 | bne machine_check_idle_common |
bf66e3c4 | 1171 | END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) |
afcf0095 | 1172 | #endif |
1945bc45 | 1173 | |
afcf0095 NP |
1174 | /* |
1175 | * Check if we are coming from hypervisor userspace. If yes then we | |
1176 | * continue in host kernel in V mode to deliver the MC event. | |
1177 | */ | |
1178 | rldicl. r11,r12,4,63 /* See if MC hit while in HV mode. */ | |
1179 | beq 5f | |
db7d31ac | 1180 | 4: andi. r11,r12,MSR_PR /* See if coming from user. */ |
afcf0095 NP |
1181 | bne 9f /* continue in V mode if we are. */ |
1182 | ||
1183 | 5: | |
1184 | #ifdef CONFIG_KVM_BOOK3S_64_HANDLER | |
db7d31ac | 1185 | BEGIN_FTR_SECTION |
afcf0095 NP |
1186 | /* |
1187 | * We are coming from kernel context. Check if we are coming from | |
1188 | * guest. if yes, then we can continue. We will fall through | |
1189 | * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest. | |
1190 | */ | |
1191 | lbz r11,HSTATE_IN_GUEST(r13) | |
1192 | cmpwi r11,0 /* Check if coming from guest */ | |
1193 | bne 9f /* continue if we are. */ | |
db7d31ac | 1194 | END_FTR_SECTION_IFSET(CPU_FTR_HVMODE) |
afcf0095 NP |
1195 | #endif |
1196 | /* | |
1197 | * At this point we are not sure about what context we come from. | |
1198 | * Queue up the MCE event and return from the interrupt. | |
1199 | * But before that, check if this is an un-recoverable exception. | |
1200 | * If yes, then stay on emergency stack and panic. | |
1201 | */ | |
1202 | andi. r11,r12,MSR_RI | |
1203 | bne 2f | |
1204 | 1: mfspr r11,SPRN_SRR0 | |
1205 | LOAD_HANDLER(r10,unrecover_mce) | |
1206 | mtspr SPRN_SRR0,r10 | |
1207 | ld r10,PACAKMSR(r13) | |
1208 | /* | |
1209 | * We are going down. But there are chances that we might get hit by | |
1210 | * another MCE during panic path and we may run into unstable state | |
1211 | * with no way out. Hence, turn ME bit off while going down, so that | |
1212 | * when another MCE is hit during panic path, system will checkstop | |
1213 | * and hypervisor will get restarted cleanly by SP. | |
1214 | */ | |
1215 | li r3,MSR_ME | |
1216 | andc r10,r10,r3 /* Turn off MSR_ME */ | |
1217 | mtspr SPRN_SRR1,r10 | |
222f20f1 | 1218 | RFI_TO_KERNEL |
afcf0095 NP |
1219 | b . |
1220 | 2: | |
1221 | /* | |
1222 | * Check if we have successfully handled/recovered from error, if not | |
1223 | * then stay on emergency stack and panic. | |
1224 | */ | |
1225 | ld r3,RESULT(r1) /* Load result */ | |
1226 | cmpdi r3,0 /* see if we handled MCE successfully */ | |
1227 | ||
1228 | beq 1b /* if !handled then panic */ | |
db7d31ac | 1229 | BEGIN_FTR_SECTION |
afcf0095 NP |
1230 | /* |
1231 | * Return from MC interrupt. | |
1232 | * Queue up the MCE event so that we can log it later, while | |
1233 | * returning from kernel or opal call. | |
1234 | */ | |
1235 | bl machine_check_queue_event | |
1236 | MACHINE_CHECK_HANDLER_WINDUP | |
222f20f1 | 1237 | RFI_TO_USER_OR_KERNEL |
db7d31ac MS |
1238 | FTR_SECTION_ELSE |
1239 | /* | |
1240 | * pSeries: Return from MC interrupt. Before that stay on emergency | |
1241 | * stack and call machine_check_exception to log the MCE event. | |
1242 | */ | |
1243 | LOAD_HANDLER(r10,mce_return) | |
1244 | mtspr SPRN_SRR0,r10 | |
1245 | ld r10,PACAKMSR(r13) | |
1246 | mtspr SPRN_SRR1,r10 | |
1247 | RFI_TO_KERNEL | |
1248 | b . | |
1249 | ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE) | |
afcf0095 NP |
1250 | 9: |
1251 | /* Deliver the machine check to host kernel in V mode. */ | |
1252 | MACHINE_CHECK_HANDLER_WINDUP | |
db7d31ac | 1253 | SET_SCRATCH0(r13) /* save r13 */ |
5dba1d50 | 1254 | EXCEPTION_PROLOG_0 PACA_EXMC |
db7d31ac | 1255 | b machine_check_pSeries_0 |
afcf0095 NP |
1256 | |
1257 | EXC_COMMON_BEGIN(unrecover_mce) | |
1258 | /* Invoke machine_check_exception to print MCE event and panic. */ | |
1259 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1260 | bl machine_check_exception | |
1261 | /* | |
1262 | * We will not reach here. Even if we did, there is no way out. Call | |
1263 | * unrecoverable_exception and die. | |
1264 | */ | |
1265 | 1: addi r3,r1,STACK_FRAME_OVERHEAD | |
1266 | bl unrecoverable_exception | |
1267 | b 1b | |
1268 | ||
a43c1590 MS |
1269 | EXC_COMMON_BEGIN(mce_return) |
1270 | /* Invoke machine_check_exception to print MCE event and return. */ | |
1271 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1272 | bl machine_check_exception | |
db7d31ac | 1273 | MACHINE_CHECK_HANDLER_WINDUP |
a43c1590 MS |
1274 | RFI_TO_KERNEL |
1275 | b . | |
0ebc4cda | 1276 | |
e779fc93 | 1277 | EXC_REAL_BEGIN(data_access, 0x300, 0x80) |
bf66e3c4 NP |
1278 | SET_SCRATCH0(r13) /* save r13 */ |
1279 | EXCEPTION_PROLOG_0 PACA_EXGEN | |
e779fc93 NP |
1280 | b tramp_real_data_access |
1281 | EXC_REAL_END(data_access, 0x300, 0x80) | |
1282 | ||
1283 | TRAMP_REAL_BEGIN(tramp_real_data_access) | |
5312c494 NP |
1284 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, 0x300, 1, 1, 0 |
1285 | EXCEPTION_PROLOG_2_REAL data_access_common, EXC_STD, 1 | |
e779fc93 NP |
1286 | |
1287 | EXC_VIRT_BEGIN(data_access, 0x4300, 0x80) | |
bf66e3c4 NP |
1288 | SET_SCRATCH0(r13) /* save r13 */ |
1289 | EXCEPTION_PROLOG_0 PACA_EXGEN | |
5312c494 | 1290 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 0, 0x300, 1, 1, 0 |
2d046308 | 1291 | EXCEPTION_PROLOG_2_VIRT data_access_common, EXC_STD |
e779fc93 NP |
1292 | EXC_VIRT_END(data_access, 0x4300, 0x80) |
1293 | ||
80795e6c NP |
1294 | TRAMP_KVM_SKIP(PACA_EXGEN, 0x300) |
1295 | ||
1296 | EXC_COMMON_BEGIN(data_access_common) | |
1297 | /* | |
1298 | * Here r13 points to the paca, r9 contains the saved CR, | |
1299 | * SRR0 and SRR1 are saved in r11 and r12, | |
1300 | * r9 - r13 are saved in paca->exgen. | |
38555434 | 1301 | * EX_DAR and EX_DSISR have saved DAR/DSISR |
80795e6c | 1302 | */ |
d064151f | 1303 | EXCEPTION_COMMON(PACA_EXGEN, 0x300) |
80795e6c NP |
1304 | RECONCILE_IRQ_STATE(r10, r11) |
1305 | ld r12,_MSR(r1) | |
1306 | ld r3,PACA_EXGEN+EX_DAR(r13) | |
1307 | lwz r4,PACA_EXGEN+EX_DSISR(r13) | |
1308 | li r5,0x300 | |
1309 | std r3,_DAR(r1) | |
1310 | std r4,_DSISR(r1) | |
1311 | BEGIN_MMU_FTR_SECTION | |
1312 | b do_hash_page /* Try to handle as hpte fault */ | |
1313 | MMU_FTR_SECTION_ELSE | |
1314 | b handle_page_fault | |
1315 | ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) | |
1316 | ||
0ebc4cda | 1317 | |
1a6822d1 | 1318 | EXC_REAL_BEGIN(data_access_slb, 0x380, 0x80) |
bf66e3c4 NP |
1319 | SET_SCRATCH0(r13) /* save r13 */ |
1320 | EXCEPTION_PROLOG_0 PACA_EXSLB | |
e779fc93 | 1321 | b tramp_real_data_access_slb |
1a6822d1 | 1322 | EXC_REAL_END(data_access_slb, 0x380, 0x80) |
0ebc4cda | 1323 | |
e779fc93 | 1324 | TRAMP_REAL_BEGIN(tramp_real_data_access_slb) |
5312c494 | 1325 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXSLB, 1, 0x380, 1, 0, 0 |
bf66e3c4 | 1326 | EXCEPTION_PROLOG_2_REAL data_access_slb_common, EXC_STD, 1 |
e779fc93 | 1327 | |
1a6822d1 | 1328 | EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80) |
bf66e3c4 NP |
1329 | SET_SCRATCH0(r13) /* save r13 */ |
1330 | EXCEPTION_PROLOG_0 PACA_EXSLB | |
5312c494 | 1331 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXSLB, 0, 0x380, 1, 0, 0 |
bf66e3c4 | 1332 | EXCEPTION_PROLOG_2_VIRT data_access_slb_common, EXC_STD |
1a6822d1 | 1333 | EXC_VIRT_END(data_access_slb, 0x4380, 0x80) |
48e7b769 | 1334 | |
2b9af6e4 NP |
1335 | TRAMP_KVM_SKIP(PACA_EXSLB, 0x380) |
1336 | ||
48e7b769 | 1337 | EXC_COMMON_BEGIN(data_access_slb_common) |
d064151f | 1338 | EXCEPTION_COMMON(PACA_EXSLB, 0x380) |
48e7b769 NP |
1339 | ld r4,PACA_EXSLB+EX_DAR(r13) |
1340 | std r4,_DAR(r1) | |
1341 | addi r3,r1,STACK_FRAME_OVERHEAD | |
7100e870 NP |
1342 | BEGIN_MMU_FTR_SECTION |
1343 | /* HPT case, do SLB fault */ | |
48e7b769 NP |
1344 | bl do_slb_fault |
1345 | cmpdi r3,0 | |
1346 | bne- 1f | |
1347 | b fast_exception_return | |
1348 | 1: /* Error case */ | |
7100e870 NP |
1349 | MMU_FTR_SECTION_ELSE |
1350 | /* Radix case, access is outside page table range */ | |
1351 | li r3,-EFAULT | |
1352 | ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) | |
48e7b769 NP |
1353 | std r3,RESULT(r1) |
1354 | bl save_nvgprs | |
1355 | RECONCILE_IRQ_STATE(r10, r11) | |
1356 | ld r4,_DAR(r1) | |
1357 | ld r5,RESULT(r1) | |
1358 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1359 | bl do_bad_slb_fault | |
1360 | b ret_from_except | |
1361 | ||
2b9af6e4 | 1362 | |
1a6822d1 NP |
1363 | EXC_REAL(instruction_access, 0x400, 0x80) |
1364 | EXC_VIRT(instruction_access, 0x4400, 0x80, 0x400) | |
27ce77df NP |
1365 | TRAMP_KVM(PACA_EXGEN, 0x400) |
1366 | ||
1367 | EXC_COMMON_BEGIN(instruction_access_common) | |
d064151f | 1368 | EXCEPTION_COMMON(PACA_EXGEN, 0x400) |
27ce77df NP |
1369 | RECONCILE_IRQ_STATE(r10, r11) |
1370 | ld r12,_MSR(r1) | |
1371 | ld r3,_NIP(r1) | |
475b581f | 1372 | andis. r4,r12,DSISR_SRR1_MATCH_64S@h |
27ce77df NP |
1373 | li r5,0x400 |
1374 | std r3,_DAR(r1) | |
1375 | std r4,_DSISR(r1) | |
1376 | BEGIN_MMU_FTR_SECTION | |
1377 | b do_hash_page /* Try to handle as hpte fault */ | |
1378 | MMU_FTR_SECTION_ELSE | |
1379 | b handle_page_fault | |
1380 | ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) | |
1381 | ||
0ebc4cda | 1382 | |
fc557537 NP |
1383 | __EXC_REAL(instruction_access_slb, 0x480, 0x80, PACA_EXSLB) |
1384 | __EXC_VIRT(instruction_access_slb, 0x4480, 0x80, 0x480, PACA_EXSLB) | |
48e7b769 | 1385 | TRAMP_KVM(PACA_EXSLB, 0x480) |
54be0b9c | 1386 | |
48e7b769 | 1387 | EXC_COMMON_BEGIN(instruction_access_slb_common) |
d064151f | 1388 | EXCEPTION_COMMON(PACA_EXSLB, 0x480) |
48e7b769 NP |
1389 | ld r4,_NIP(r1) |
1390 | addi r3,r1,STACK_FRAME_OVERHEAD | |
7100e870 NP |
1391 | BEGIN_MMU_FTR_SECTION |
1392 | /* HPT case, do SLB fault */ | |
48e7b769 NP |
1393 | bl do_slb_fault |
1394 | cmpdi r3,0 | |
1395 | bne- 1f | |
1396 | b fast_exception_return | |
1397 | 1: /* Error case */ | |
7100e870 NP |
1398 | MMU_FTR_SECTION_ELSE |
1399 | /* Radix case, access is outside page table range */ | |
1400 | li r3,-EFAULT | |
1401 | ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) | |
48e7b769 | 1402 | std r3,RESULT(r1) |
8d04631a | 1403 | bl save_nvgprs |
8d04631a | 1404 | RECONCILE_IRQ_STATE(r10, r11) |
48e7b769 NP |
1405 | ld r4,_NIP(r1) |
1406 | ld r5,RESULT(r1) | |
1407 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1408 | bl do_bad_slb_fault | |
8d04631a NP |
1409 | b ret_from_except |
1410 | ||
48e7b769 | 1411 | |
1a6822d1 | 1412 | EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100) |
80bd9177 NP |
1413 | SET_SCRATCH0(r13) /* save r13 */ |
1414 | EXCEPTION_PROLOG_0 PACA_EXGEN | |
bf66e3c4 | 1415 | BEGIN_FTR_SECTION |
5312c494 | 1416 | EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, 0x500, 0, 0, IRQS_DISABLED |
bf66e3c4 NP |
1417 | EXCEPTION_PROLOG_2_REAL hardware_interrupt_common, EXC_HV, 1 |
1418 | FTR_SECTION_ELSE | |
5312c494 | 1419 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, 0x500, 0, 0, IRQS_DISABLED |
bf66e3c4 NP |
1420 | EXCEPTION_PROLOG_2_REAL hardware_interrupt_common, EXC_STD, 1 |
1421 | ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) | |
1a6822d1 | 1422 | EXC_REAL_END(hardware_interrupt, 0x500, 0x100) |
da2bc464 | 1423 | |
1a6822d1 | 1424 | EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100) |
80bd9177 NP |
1425 | SET_SCRATCH0(r13) /* save r13 */ |
1426 | EXCEPTION_PROLOG_0 PACA_EXGEN | |
bf66e3c4 | 1427 | BEGIN_FTR_SECTION |
5312c494 | 1428 | EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, 0x500, 0, 0, IRQS_DISABLED |
bf66e3c4 NP |
1429 | EXCEPTION_PROLOG_2_VIRT hardware_interrupt_common, EXC_HV |
1430 | FTR_SECTION_ELSE | |
5312c494 | 1431 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, 0x500, 0, 0, IRQS_DISABLED |
bf66e3c4 NP |
1432 | EXCEPTION_PROLOG_2_VIRT hardware_interrupt_common, EXC_STD |
1433 | ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE) | |
1a6822d1 | 1434 | EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100) |
c138e588 | 1435 | |
7ede5317 NP |
1436 | TRAMP_KVM(PACA_EXGEN, 0x500) |
1437 | TRAMP_KVM_HV(PACA_EXGEN, 0x500) | |
c138e588 NP |
1438 | EXC_COMMON_ASYNC(hardware_interrupt_common, 0x500, do_IRQ) |
1439 | ||
1440 | ||
e779fc93 | 1441 | EXC_REAL_BEGIN(alignment, 0x600, 0x100) |
bf66e3c4 NP |
1442 | SET_SCRATCH0(r13) /* save r13 */ |
1443 | EXCEPTION_PROLOG_0 PACA_EXGEN | |
5312c494 | 1444 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, 0x600, 1, 1, 0 |
bf66e3c4 | 1445 | EXCEPTION_PROLOG_2_REAL alignment_common, EXC_STD, 1 |
e779fc93 NP |
1446 | EXC_REAL_END(alignment, 0x600, 0x100) |
1447 | ||
1448 | EXC_VIRT_BEGIN(alignment, 0x4600, 0x100) | |
bf66e3c4 NP |
1449 | SET_SCRATCH0(r13) /* save r13 */ |
1450 | EXCEPTION_PROLOG_0 PACA_EXGEN | |
5312c494 | 1451 | EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 0, 0x600, 1, 1, 0 |
bf66e3c4 | 1452 | EXCEPTION_PROLOG_2_VIRT alignment_common, EXC_STD |
e779fc93 NP |
1453 | EXC_VIRT_END(alignment, 0x4600, 0x100) |
1454 | ||
da2bc464 | 1455 | TRAMP_KVM(PACA_EXGEN, 0x600) |
f9aa6714 | 1456 | EXC_COMMON_BEGIN(alignment_common) |
d064151f | 1457 | EXCEPTION_COMMON(PACA_EXGEN, 0x600) |
f9aa6714 NP |
1458 | ld r3,PACA_EXGEN+EX_DAR(r13) |
1459 | lwz r4,PACA_EXGEN+EX_DSISR(r13) | |
1460 | std r3,_DAR(r1) | |
1461 | std r4,_DSISR(r1) | |
1462 | bl save_nvgprs | |
1463 | RECONCILE_IRQ_STATE(r10, r11) | |
1464 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1465 | bl alignment_exception | |
1466 | b ret_from_except | |
1467 | ||
da2bc464 | 1468 | |
1a6822d1 NP |
1469 | EXC_REAL(program_check, 0x700, 0x100) |
1470 | EXC_VIRT(program_check, 0x4700, 0x100, 0x700) | |
da2bc464 | 1471 | TRAMP_KVM(PACA_EXGEN, 0x700) |
11e87346 | 1472 | EXC_COMMON_BEGIN(program_check_common) |
265e60a1 CB |
1473 | /* |
1474 | * It's possible to receive a TM Bad Thing type program check with | |
1475 | * userspace register values (in particular r1), but with SRR1 reporting | |
1476 | * that we came from the kernel. Normally that would confuse the bad | |
1477 | * stack logic, and we would report a bad kernel stack pointer. Instead | |
1478 | * we switch to the emergency stack if we're taking a TM Bad Thing from | |
1479 | * the kernel. | |
1480 | */ | |
1481 | li r10,MSR_PR /* Build a mask of MSR_PR .. */ | |
1482 | oris r10,r10,0x200000@h /* .. and SRR1_PROGTM */ | |
1483 | and r10,r10,r12 /* Mask SRR1 with that. */ | |
1484 | srdi r10,r10,8 /* Shift it so we can compare */ | |
1485 | cmpldi r10,(0x200000 >> 8) /* .. with an immediate. */ | |
1486 | bne 1f /* If != go to normal path. */ | |
1487 | ||
1488 | /* SRR1 had PR=0 and SRR1_PROGTM=1, so use the emergency stack */ | |
1489 | andi. r10,r12,MSR_PR; /* Set CR0 correctly for label */ | |
1490 | /* 3 in EXCEPTION_PROLOG_COMMON */ | |
1491 | mr r10,r1 /* Save r1 */ | |
1492 | ld r1,PACAEMERGSP(r13) /* Use emergency stack */ | |
1493 | subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */ | |
1494 | b 3f /* Jump into the macro !! */ | |
d064151f | 1495 | 1: EXCEPTION_COMMON(PACA_EXGEN, 0x700) |
11e87346 NP |
1496 | bl save_nvgprs |
1497 | RECONCILE_IRQ_STATE(r10, r11) | |
1498 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1499 | bl program_check_exception | |
1500 | b ret_from_except | |
1501 | ||
b01c8b54 | 1502 | |
1a6822d1 NP |
1503 | EXC_REAL(fp_unavailable, 0x800, 0x100) |
1504 | EXC_VIRT(fp_unavailable, 0x4800, 0x100, 0x800) | |
da2bc464 | 1505 | TRAMP_KVM(PACA_EXGEN, 0x800) |
c78d9b97 | 1506 | EXC_COMMON_BEGIN(fp_unavailable_common) |
d064151f | 1507 | EXCEPTION_COMMON(PACA_EXGEN, 0x800) |
c78d9b97 NP |
1508 | bne 1f /* if from user, just load it up */ |
1509 | bl save_nvgprs | |
1510 | RECONCILE_IRQ_STATE(r10, r11) | |
1511 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1512 | bl kernel_fp_unavailable_exception | |
1513 | BUG_OPCODE | |
1514 | 1: | |
1515 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
1516 | BEGIN_FTR_SECTION | |
1517 | /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in | |
1518 | * transaction), go do TM stuff | |
1519 | */ | |
1520 | rldicl. r0, r12, (64-MSR_TS_LG), (64-2) | |
1521 | bne- 2f | |
1522 | END_FTR_SECTION_IFSET(CPU_FTR_TM) | |
1523 | #endif | |
1524 | bl load_up_fpu | |
1525 | b fast_exception_return | |
1526 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
1527 | 2: /* User process was in a transaction */ | |
1528 | bl save_nvgprs | |
1529 | RECONCILE_IRQ_STATE(r10, r11) | |
1530 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1531 | bl fp_unavailable_tm | |
1532 | b ret_from_except | |
1533 | #endif | |
1534 | ||
a5d4f3ad | 1535 | |
a048a07d | 1536 | EXC_REAL_OOL_MASKABLE(decrementer, 0x900, 0x80, IRQS_DISABLED) |
f14e953b | 1537 | EXC_VIRT_MASKABLE(decrementer, 0x4900, 0x80, 0x900, IRQS_DISABLED) |
39c0da57 NP |
1538 | TRAMP_KVM(PACA_EXGEN, 0x900) |
1539 | EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt) | |
1540 | ||
a485c709 | 1541 | |
1a6822d1 NP |
1542 | EXC_REAL_HV(hdecrementer, 0x980, 0x80) |
1543 | EXC_VIRT_HV(hdecrementer, 0x4980, 0x80, 0x980) | |
facc6d74 NP |
1544 | TRAMP_KVM_HV(PACA_EXGEN, 0x980) |
1545 | EXC_COMMON(hdecrementer_common, 0x980, hdec_interrupt) | |
1546 | ||
a5d4f3ad | 1547 | |
f14e953b MS |
1548 | EXC_REAL_MASKABLE(doorbell_super, 0xa00, 0x100, IRQS_DISABLED) |
1549 | EXC_VIRT_MASKABLE(doorbell_super, 0x4a00, 0x100, 0xa00, IRQS_DISABLED) | |
da2bc464 | 1550 | TRAMP_KVM(PACA_EXGEN, 0xa00) |
ca243163 NP |
1551 | #ifdef CONFIG_PPC_DOORBELL |
1552 | EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, doorbell_exception) | |
1553 | #else | |
1554 | EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, unknown_exception) | |
1555 | #endif | |
1556 | ||
0ebc4cda | 1557 | |
1a6822d1 NP |
1558 | EXC_REAL(trap_0b, 0xb00, 0x100) |
1559 | EXC_VIRT(trap_0b, 0x4b00, 0x100, 0xb00) | |
da2bc464 | 1560 | TRAMP_KVM(PACA_EXGEN, 0xb00) |
341215dc NP |
1561 | EXC_COMMON(trap_0b_common, 0xb00, unknown_exception) |
1562 | ||
acd7d8ce NP |
1563 | /* |
1564 | * system call / hypercall (0xc00, 0x4c00) | |
1565 | * | |
1566 | * The system call exception is invoked with "sc 0" and does not alter HV bit. | |
1567 | * There is support for kernel code to invoke system calls but there are no | |
1568 | * in-tree users. | |
1569 | * | |
1570 | * The hypercall is invoked with "sc 1" and sets HV=1. | |
1571 | * | |
1572 | * In HPT, sc 1 always goes to 0xc00 real mode. In RADIX, sc 1 can go to | |
1573 | * 0x4c00 virtual mode. | |
1574 | * | |
1575 | * Call convention: | |
1576 | * | |
1577 | * syscall register convention is in Documentation/powerpc/syscall64-abi.txt | |
1578 | * | |
1579 | * For hypercalls, the register convention is as follows: | |
1580 | * r0 volatile | |
1581 | * r1-2 nonvolatile | |
1582 | * r3 volatile parameter and return value for status | |
1583 | * r4-r10 volatile input and output value | |
1584 | * r11 volatile hypercall number and output value | |
76fc0cfc | 1585 | * r12 volatile input and output value |
acd7d8ce NP |
1586 | * r13-r31 nonvolatile |
1587 | * LR nonvolatile | |
1588 | * CTR volatile | |
1589 | * XER volatile | |
1590 | * CR0-1 CR5-7 volatile | |
1591 | * CR2-4 nonvolatile | |
1592 | * Other registers nonvolatile | |
1593 | * | |
1594 | * The intersection of volatile registers that don't contain possible | |
76fc0cfc NP |
1595 | * inputs is: cr0, xer, ctr. We may use these as scratch regs upon entry |
1596 | * without saving, though xer is not a good idea to use, as hardware may | |
1597 | * interpret some bits so it may be costly to change them. | |
acd7d8ce | 1598 | */ |
1b4d4a79 | 1599 | .macro SYSTEM_CALL virt |
bc355125 | 1600 | #ifdef CONFIG_KVM_BOOK3S_64_HANDLER |
acd7d8ce NP |
1601 | /* |
1602 | * There is a little bit of juggling to get syscall and hcall | |
76fc0cfc NP |
1603 | * working well. Save r13 in ctr to avoid using SPRG scratch |
1604 | * register. | |
acd7d8ce NP |
1605 | * |
1606 | * Userspace syscalls have already saved the PPR, hcalls must save | |
1607 | * it before setting HMT_MEDIUM. | |
1608 | */ | |
1b4d4a79 NP |
1609 | mtctr r13 |
1610 | GET_PACA(r13) | |
1611 | std r10,PACA_EXGEN+EX_R10(r13) | |
1612 | INTERRUPT_TO_KERNEL | |
1613 | KVMTEST EXC_STD 0xc00 /* uses r10, branch to do_kvm_0xc00_system_call */ | |
1b4d4a79 | 1614 | mfctr r9 |
bc355125 | 1615 | #else |
1b4d4a79 NP |
1616 | mr r9,r13 |
1617 | GET_PACA(r13) | |
1618 | INTERRUPT_TO_KERNEL | |
bc355125 | 1619 | #endif |
d807ad37 | 1620 | |
727f1361 | 1621 | #ifdef CONFIG_PPC_FAST_ENDIAN_SWITCH |
1b4d4a79 NP |
1622 | BEGIN_FTR_SECTION |
1623 | cmpdi r0,0x1ebe | |
1624 | beq- 1f | |
1625 | END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) | |
1626 | #endif | |
d807ad37 | 1627 | |
b0b2a93d | 1628 | /* We reach here with PACA in r13, r13 in r9. */ |
1b4d4a79 NP |
1629 | mfspr r11,SPRN_SRR0 |
1630 | mfspr r12,SPRN_SRR1 | |
b0b2a93d NP |
1631 | |
1632 | HMT_MEDIUM | |
1633 | ||
1634 | .if ! \virt | |
1b4d4a79 NP |
1635 | __LOAD_HANDLER(r10, system_call_common) |
1636 | mtspr SPRN_SRR0,r10 | |
1637 | ld r10,PACAKMSR(r13) | |
1638 | mtspr SPRN_SRR1,r10 | |
1639 | RFI_TO_KERNEL | |
1640 | b . /* prevent speculative execution */ | |
1641 | .else | |
b0b2a93d NP |
1642 | li r10,MSR_RI |
1643 | mtmsrd r10,1 /* Set RI (EE=0) */ | |
1b4d4a79 | 1644 | #ifdef CONFIG_RELOCATABLE |
1b4d4a79 NP |
1645 | __LOAD_HANDLER(r10, system_call_common) |
1646 | mtctr r10 | |
1b4d4a79 | 1647 | bctr |
d807ad37 | 1648 | #else |
1b4d4a79 NP |
1649 | b system_call_common |
1650 | #endif | |
1651 | .endif | |
1652 | ||
1653 | #ifdef CONFIG_PPC_FAST_ENDIAN_SWITCH | |
1654 | /* Fast LE/BE switch system call */ | |
1655 | 1: mfspr r12,SPRN_SRR1 | |
1656 | xori r12,r12,MSR_LE | |
1657 | mtspr SPRN_SRR1,r12 | |
1658 | mr r13,r9 | |
1659 | RFI_TO_USER /* return to userspace */ | |
1660 | b . /* prevent speculative execution */ | |
d807ad37 | 1661 | #endif |
1b4d4a79 | 1662 | .endm |
d807ad37 | 1663 | |
1a6822d1 | 1664 | EXC_REAL_BEGIN(system_call, 0xc00, 0x100) |
1b4d4a79 | 1665 | SYSTEM_CALL 0 |
1a6822d1 | 1666 | EXC_REAL_END(system_call, 0xc00, 0x100) |
da2bc464 | 1667 | |
1a6822d1 | 1668 | EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100) |
1b4d4a79 | 1669 | SYSTEM_CALL 1 |
1a6822d1 | 1670 | EXC_VIRT_END(system_call, 0x4c00, 0x100) |
d807ad37 | 1671 | |
acd7d8ce NP |
1672 | #ifdef CONFIG_KVM_BOOK3S_64_HANDLER |
1673 | /* | |
1674 | * This is a hcall, so register convention is as above, with these | |
1675 | * differences: | |
1676 | * r13 = PACA | |
76fc0cfc NP |
1677 | * ctr = orig r13 |
1678 | * orig r10 saved in PACA | |
acd7d8ce NP |
1679 | */ |
1680 | TRAMP_KVM_BEGIN(do_kvm_0xc00) | |
1681 | /* | |
1682 | * Save the PPR (on systems that support it) before changing to | |
1683 | * HMT_MEDIUM. That allows the KVM code to save that value into the | |
1684 | * guest state (it is the guest's PPR value). | |
1685 | */ | |
76fc0cfc | 1686 | OPT_GET_SPR(r10, SPRN_PPR, CPU_FTR_HAS_PPR) |
acd7d8ce | 1687 | HMT_MEDIUM |
76fc0cfc | 1688 | OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r10, CPU_FTR_HAS_PPR) |
acd7d8ce | 1689 | mfctr r10 |
76fc0cfc | 1690 | SET_SCRATCH0(r10) |
acd7d8ce NP |
1691 | std r9,PACA_EXGEN+EX_R9(r13) |
1692 | mfcr r9 | |
17bdc064 | 1693 | KVM_HANDLER PACA_EXGEN, EXC_STD, 0xc00, 0 |
acd7d8ce | 1694 | #endif |
da2bc464 | 1695 | |
d807ad37 | 1696 | |
1a6822d1 NP |
1697 | EXC_REAL(single_step, 0xd00, 0x100) |
1698 | EXC_VIRT(single_step, 0x4d00, 0x100, 0xd00) | |
da2bc464 | 1699 | TRAMP_KVM(PACA_EXGEN, 0xd00) |
bc6675c6 | 1700 | EXC_COMMON(single_step_common, 0xd00, single_step_exception) |
b01c8b54 | 1701 | |
1a6822d1 | 1702 | EXC_REAL_OOL_HV(h_data_storage, 0xe00, 0x20) |
da0e7e62 | 1703 | EXC_VIRT_OOL_HV(h_data_storage, 0x4e00, 0x20, 0xe00) |
f5c32c1d NP |
1704 | TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0xe00) |
1705 | EXC_COMMON_BEGIN(h_data_storage_common) | |
1706 | mfspr r10,SPRN_HDAR | |
1707 | std r10,PACA_EXGEN+EX_DAR(r13) | |
1708 | mfspr r10,SPRN_HDSISR | |
1709 | stw r10,PACA_EXGEN+EX_DSISR(r13) | |
d064151f | 1710 | EXCEPTION_COMMON(PACA_EXGEN, 0xe00) |
f5c32c1d NP |
1711 | bl save_nvgprs |
1712 | RECONCILE_IRQ_STATE(r10, r11) | |
1713 | addi r3,r1,STACK_FRAME_OVERHEAD | |
d7b45615 SJS |
1714 | BEGIN_MMU_FTR_SECTION |
1715 | ld r4,PACA_EXGEN+EX_DAR(r13) | |
1716 | lwz r5,PACA_EXGEN+EX_DSISR(r13) | |
1717 | std r4,_DAR(r1) | |
1718 | std r5,_DSISR(r1) | |
1719 | li r5,SIGSEGV | |
1720 | bl bad_page_fault | |
1721 | MMU_FTR_SECTION_ELSE | |
f5c32c1d | 1722 | bl unknown_exception |
d7b45615 | 1723 | ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_TYPE_RADIX) |
f5c32c1d | 1724 | b ret_from_except |
f5c32c1d | 1725 | |
1707dd16 | 1726 | |
1a6822d1 | 1727 | EXC_REAL_OOL_HV(h_instr_storage, 0xe20, 0x20) |
da0e7e62 | 1728 | EXC_VIRT_OOL_HV(h_instr_storage, 0x4e20, 0x20, 0xe20) |
82517cab NP |
1729 | TRAMP_KVM_HV(PACA_EXGEN, 0xe20) |
1730 | EXC_COMMON(h_instr_storage_common, 0xe20, unknown_exception) | |
1731 | ||
1707dd16 | 1732 | |
1a6822d1 NP |
1733 | EXC_REAL_OOL_HV(emulation_assist, 0xe40, 0x20) |
1734 | EXC_VIRT_OOL_HV(emulation_assist, 0x4e40, 0x20, 0xe40) | |
031b4026 NP |
1735 | TRAMP_KVM_HV(PACA_EXGEN, 0xe40) |
1736 | EXC_COMMON(emulation_assist_common, 0xe40, emulation_assist_interrupt) | |
1737 | ||
1707dd16 | 1738 | |
e0319829 NP |
1739 | /* |
1740 | * hmi_exception trampoline is a special case. It jumps to hmi_exception_early | |
1741 | * first, and then eventaully from there to the trampoline to get into virtual | |
1742 | * mode. | |
1743 | */ | |
1a6822d1 | 1744 | __EXC_REAL_OOL_HV_DIRECT(hmi_exception, 0xe60, 0x20, hmi_exception_early) |
f14e953b | 1745 | __TRAMP_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60, IRQS_DISABLED) |
1a6822d1 | 1746 | EXC_VIRT_NONE(0x4e60, 0x20) |
62f9b03b NP |
1747 | TRAMP_KVM_HV(PACA_EXGEN, 0xe60) |
1748 | TRAMP_REAL_BEGIN(hmi_exception_early) | |
5312c494 | 1749 | EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, 0xe60, 0, 0, 0 |
a4087a4d NP |
1750 | mr r10,r1 /* Save r1 */ |
1751 | ld r1,PACAEMERGSP(r13) /* Use emergency stack for realmode */ | |
62f9b03b | 1752 | subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */ |
62f9b03b | 1753 | mfspr r11,SPRN_HSRR0 /* Save HSRR0 */ |
a4087a4d NP |
1754 | mfspr r12,SPRN_HSRR1 /* Save HSRR1 */ |
1755 | EXCEPTION_PROLOG_COMMON_1() | |
890274c2 | 1756 | /* We don't touch AMR here, we never go to virtual mode */ |
62f9b03b NP |
1757 | EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN) |
1758 | EXCEPTION_PROLOG_COMMON_3(0xe60) | |
1759 | addi r3,r1,STACK_FRAME_OVERHEAD | |
505a314f | 1760 | BRANCH_LINK_TO_FAR(DOTSYM(hmi_exception_realmode)) /* Function call ABI */ |
5080332c | 1761 | cmpdi cr0,r3,0 |
67d4160a | 1762 | bne 1f |
5080332c | 1763 | |
391e941b | 1764 | EXCEPTION_RESTORE_REGS EXC_HV |
222f20f1 | 1765 | HRFI_TO_USER_OR_KERNEL |
5080332c | 1766 | |
67d4160a | 1767 | 1: |
62f9b03b NP |
1768 | /* |
1769 | * Go to virtual mode and pull the HMI event information from | |
1770 | * firmware. | |
1771 | */ | |
391e941b | 1772 | EXCEPTION_RESTORE_REGS EXC_HV |
62f9b03b | 1773 | SET_SCRATCH0(r13) |
5dba1d50 | 1774 | EXCEPTION_PROLOG_0 PACA_EXGEN |
62f9b03b NP |
1775 | b tramp_real_hmi_exception |
1776 | ||
5080332c | 1777 | EXC_COMMON_BEGIN(hmi_exception_common) |
47169fba NP |
1778 | EXCEPTION_COMMON(PACA_EXGEN, 0xe60) |
1779 | FINISH_NAP | |
1780 | bl save_nvgprs | |
1781 | RECONCILE_IRQ_STATE(r10, r11) | |
1782 | RUNLATCH_ON | |
c06075f3 NP |
1783 | addi r3,r1,STACK_FRAME_OVERHEAD |
1784 | bl handle_hmi_exception | |
1785 | b ret_from_except | |
1707dd16 | 1786 | |
f14e953b MS |
1787 | EXC_REAL_OOL_MASKABLE_HV(h_doorbell, 0xe80, 0x20, IRQS_DISABLED) |
1788 | EXC_VIRT_OOL_MASKABLE_HV(h_doorbell, 0x4e80, 0x20, 0xe80, IRQS_DISABLED) | |
9bcb81bf NP |
1789 | TRAMP_KVM_HV(PACA_EXGEN, 0xe80) |
1790 | #ifdef CONFIG_PPC_DOORBELL | |
1791 | EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, doorbell_exception) | |
1792 | #else | |
1793 | EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, unknown_exception) | |
1794 | #endif | |
1795 | ||
0ebc4cda | 1796 | |
f14e953b MS |
1797 | EXC_REAL_OOL_MASKABLE_HV(h_virt_irq, 0xea0, 0x20, IRQS_DISABLED) |
1798 | EXC_VIRT_OOL_MASKABLE_HV(h_virt_irq, 0x4ea0, 0x20, 0xea0, IRQS_DISABLED) | |
74408776 NP |
1799 | TRAMP_KVM_HV(PACA_EXGEN, 0xea0) |
1800 | EXC_COMMON_ASYNC(h_virt_irq_common, 0xea0, do_IRQ) | |
1801 | ||
9baaef0a | 1802 | |
1a6822d1 NP |
1803 | EXC_REAL_NONE(0xec0, 0x20) |
1804 | EXC_VIRT_NONE(0x4ec0, 0x20) | |
1805 | EXC_REAL_NONE(0xee0, 0x20) | |
1806 | EXC_VIRT_NONE(0x4ee0, 0x20) | |
bda7fea2 | 1807 | |
0ebc4cda | 1808 | |
f442d004 MS |
1809 | EXC_REAL_OOL_MASKABLE(performance_monitor, 0xf00, 0x20, IRQS_PMI_DISABLED) |
1810 | EXC_VIRT_OOL_MASKABLE(performance_monitor, 0x4f00, 0x20, 0xf00, IRQS_PMI_DISABLED) | |
b1c7f150 NP |
1811 | TRAMP_KVM(PACA_EXGEN, 0xf00) |
1812 | EXC_COMMON_ASYNC(performance_monitor_common, 0xf00, performance_monitor_exception) | |
1813 | ||
0ebc4cda | 1814 | |
1a6822d1 NP |
1815 | EXC_REAL_OOL(altivec_unavailable, 0xf20, 0x20) |
1816 | EXC_VIRT_OOL(altivec_unavailable, 0x4f20, 0x20, 0xf20) | |
d1a0ca9c NP |
1817 | TRAMP_KVM(PACA_EXGEN, 0xf20) |
1818 | EXC_COMMON_BEGIN(altivec_unavailable_common) | |
d064151f | 1819 | EXCEPTION_COMMON(PACA_EXGEN, 0xf20) |
d1a0ca9c NP |
1820 | #ifdef CONFIG_ALTIVEC |
1821 | BEGIN_FTR_SECTION | |
1822 | beq 1f | |
1823 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
1824 | BEGIN_FTR_SECTION_NESTED(69) | |
1825 | /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in | |
1826 | * transaction), go do TM stuff | |
1827 | */ | |
1828 | rldicl. r0, r12, (64-MSR_TS_LG), (64-2) | |
1829 | bne- 2f | |
1830 | END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69) | |
1831 | #endif | |
1832 | bl load_up_altivec | |
1833 | b fast_exception_return | |
1834 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
1835 | 2: /* User process was in a transaction */ | |
1836 | bl save_nvgprs | |
1837 | RECONCILE_IRQ_STATE(r10, r11) | |
1838 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1839 | bl altivec_unavailable_tm | |
1840 | b ret_from_except | |
1841 | #endif | |
1842 | 1: | |
1843 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) | |
1844 | #endif | |
1845 | bl save_nvgprs | |
1846 | RECONCILE_IRQ_STATE(r10, r11) | |
1847 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1848 | bl altivec_unavailable_exception | |
1849 | b ret_from_except | |
1850 | ||
0ebc4cda | 1851 | |
1a6822d1 NP |
1852 | EXC_REAL_OOL(vsx_unavailable, 0xf40, 0x20) |
1853 | EXC_VIRT_OOL(vsx_unavailable, 0x4f40, 0x20, 0xf40) | |
792cbddd NP |
1854 | TRAMP_KVM(PACA_EXGEN, 0xf40) |
1855 | EXC_COMMON_BEGIN(vsx_unavailable_common) | |
d064151f | 1856 | EXCEPTION_COMMON(PACA_EXGEN, 0xf40) |
792cbddd NP |
1857 | #ifdef CONFIG_VSX |
1858 | BEGIN_FTR_SECTION | |
1859 | beq 1f | |
1860 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
1861 | BEGIN_FTR_SECTION_NESTED(69) | |
1862 | /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in | |
1863 | * transaction), go do TM stuff | |
1864 | */ | |
1865 | rldicl. r0, r12, (64-MSR_TS_LG), (64-2) | |
1866 | bne- 2f | |
1867 | END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69) | |
1868 | #endif | |
1869 | b load_up_vsx | |
1870 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
1871 | 2: /* User process was in a transaction */ | |
1872 | bl save_nvgprs | |
1873 | RECONCILE_IRQ_STATE(r10, r11) | |
1874 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1875 | bl vsx_unavailable_tm | |
1876 | b ret_from_except | |
1877 | #endif | |
1878 | 1: | |
1879 | END_FTR_SECTION_IFSET(CPU_FTR_VSX) | |
1880 | #endif | |
1881 | bl save_nvgprs | |
1882 | RECONCILE_IRQ_STATE(r10, r11) | |
1883 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1884 | bl vsx_unavailable_exception | |
1885 | b ret_from_except | |
1886 | ||
da2bc464 | 1887 | |
1a6822d1 NP |
1888 | EXC_REAL_OOL(facility_unavailable, 0xf60, 0x20) |
1889 | EXC_VIRT_OOL(facility_unavailable, 0x4f60, 0x20, 0xf60) | |
1134713c NP |
1890 | TRAMP_KVM(PACA_EXGEN, 0xf60) |
1891 | EXC_COMMON(facility_unavailable_common, 0xf60, facility_unavailable_exception) | |
1892 | ||
da2bc464 | 1893 | |
1a6822d1 NP |
1894 | EXC_REAL_OOL_HV(h_facility_unavailable, 0xf80, 0x20) |
1895 | EXC_VIRT_OOL_HV(h_facility_unavailable, 0x4f80, 0x20, 0xf80) | |
14b0072c NP |
1896 | TRAMP_KVM_HV(PACA_EXGEN, 0xf80) |
1897 | EXC_COMMON(h_facility_unavailable_common, 0xf80, facility_unavailable_exception) | |
1898 | ||
da2bc464 | 1899 | |
1a6822d1 NP |
1900 | EXC_REAL_NONE(0xfa0, 0x20) |
1901 | EXC_VIRT_NONE(0x4fa0, 0x20) | |
1902 | EXC_REAL_NONE(0xfc0, 0x20) | |
1903 | EXC_VIRT_NONE(0x4fc0, 0x20) | |
1904 | EXC_REAL_NONE(0xfe0, 0x20) | |
1905 | EXC_VIRT_NONE(0x4fe0, 0x20) | |
1906 | ||
1907 | EXC_REAL_NONE(0x1000, 0x100) | |
1908 | EXC_VIRT_NONE(0x5000, 0x100) | |
1909 | EXC_REAL_NONE(0x1100, 0x100) | |
1910 | EXC_VIRT_NONE(0x5100, 0x100) | |
d0c0c9a1 | 1911 | |
0ebc4cda | 1912 | #ifdef CONFIG_CBE_RAS |
1a6822d1 NP |
1913 | EXC_REAL_HV(cbe_system_error, 0x1200, 0x100) |
1914 | EXC_VIRT_NONE(0x5200, 0x100) | |
da2bc464 | 1915 | TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1200) |
ff1b3206 | 1916 | EXC_COMMON(cbe_system_error_common, 0x1200, cbe_system_error_exception) |
da2bc464 | 1917 | #else /* CONFIG_CBE_RAS */ |
1a6822d1 NP |
1918 | EXC_REAL_NONE(0x1200, 0x100) |
1919 | EXC_VIRT_NONE(0x5200, 0x100) | |
da2bc464 | 1920 | #endif |
b01c8b54 | 1921 | |
ff1b3206 | 1922 | |
1a6822d1 NP |
1923 | EXC_REAL(instruction_breakpoint, 0x1300, 0x100) |
1924 | EXC_VIRT(instruction_breakpoint, 0x5300, 0x100, 0x1300) | |
da2bc464 | 1925 | TRAMP_KVM_SKIP(PACA_EXGEN, 0x1300) |
4e96dbbf NP |
1926 | EXC_COMMON(instruction_breakpoint_common, 0x1300, instruction_breakpoint_exception) |
1927 | ||
1a6822d1 NP |
1928 | EXC_REAL_NONE(0x1400, 0x100) |
1929 | EXC_VIRT_NONE(0x5400, 0x100) | |
da2bc464 | 1930 | |
1a6822d1 | 1931 | EXC_REAL_BEGIN(denorm_exception_hv, 0x1500, 0x100) |
b92a66a6 | 1932 | mtspr SPRN_SPRG_HSCRATCH0,r13 |
5dba1d50 | 1933 | EXCEPTION_PROLOG_0 PACA_EXGEN |
5312c494 | 1934 | EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 0, 0x1500, 0, 0, 0 |
b92a66a6 MN |
1935 | |
1936 | #ifdef CONFIG_PPC_DENORMALISATION | |
1937 | mfspr r10,SPRN_HSRR1 | |
afcf0095 | 1938 | andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */ |
afcf0095 NP |
1939 | bne+ denorm_assist |
1940 | #endif | |
1e9b4507 | 1941 | |
a7c1ca19 | 1942 | KVMTEST EXC_HV 0x1500 |
2d046308 | 1943 | EXCEPTION_PROLOG_2_REAL denorm_common, EXC_HV, 1 |
1a6822d1 | 1944 | EXC_REAL_END(denorm_exception_hv, 0x1500, 0x100) |
a74599a5 | 1945 | |
d7e89849 | 1946 | #ifdef CONFIG_PPC_DENORMALISATION |
1a6822d1 | 1947 | EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100) |
d7e89849 | 1948 | b exc_real_0x1500_denorm_exception_hv |
1a6822d1 | 1949 | EXC_VIRT_END(denorm_exception, 0x5500, 0x100) |
d7e89849 | 1950 | #else |
1a6822d1 | 1951 | EXC_VIRT_NONE(0x5500, 0x100) |
afcf0095 NP |
1952 | #endif |
1953 | ||
4bb3c7a0 | 1954 | TRAMP_KVM_HV(PACA_EXGEN, 0x1500) |
b01c8b54 | 1955 | |
b92a66a6 | 1956 | #ifdef CONFIG_PPC_DENORMALISATION |
da2bc464 | 1957 | TRAMP_REAL_BEGIN(denorm_assist) |
b92a66a6 MN |
1958 | BEGIN_FTR_SECTION |
1959 | /* | |
1960 | * To denormalise we need to move a copy of the register to itself. | |
1961 | * For POWER6 do that here for all FP regs. | |
1962 | */ | |
1963 | mfmsr r10 | |
1964 | ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1) | |
1965 | xori r10,r10,(MSR_FE0|MSR_FE1) | |
1966 | mtmsrd r10 | |
1967 | sync | |
d7c67fb1 | 1968 | |
f3c8b6c6 NP |
1969 | .Lreg=0 |
1970 | .rept 32 | |
1971 | fmr .Lreg,.Lreg | |
1972 | .Lreg=.Lreg+1 | |
1973 | .endr | |
d7c67fb1 | 1974 | |
b92a66a6 MN |
1975 | FTR_SECTION_ELSE |
1976 | /* | |
1977 | * To denormalise we need to move a copy of the register to itself. | |
1978 | * For POWER7 do that here for the first 32 VSX registers only. | |
1979 | */ | |
1980 | mfmsr r10 | |
1981 | oris r10,r10,MSR_VSX@h | |
1982 | mtmsrd r10 | |
1983 | sync | |
d7c67fb1 | 1984 | |
f3c8b6c6 NP |
1985 | .Lreg=0 |
1986 | .rept 32 | |
1987 | XVCPSGNDP(.Lreg,.Lreg,.Lreg) | |
1988 | .Lreg=.Lreg+1 | |
1989 | .endr | |
d7c67fb1 | 1990 | |
b92a66a6 | 1991 | ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206) |
fb0fce3e MN |
1992 | |
1993 | BEGIN_FTR_SECTION | |
1994 | b denorm_done | |
1995 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) | |
1996 | /* | |
1997 | * To denormalise we need to move a copy of the register to itself. | |
1998 | * For POWER8 we need to do that for all 64 VSX registers | |
1999 | */ | |
f3c8b6c6 NP |
2000 | .Lreg=32 |
2001 | .rept 32 | |
2002 | XVCPSGNDP(.Lreg,.Lreg,.Lreg) | |
2003 | .Lreg=.Lreg+1 | |
2004 | .endr | |
2005 | ||
fb0fce3e | 2006 | denorm_done: |
f14040bc MN |
2007 | mfspr r11,SPRN_HSRR0 |
2008 | subi r11,r11,4 | |
b92a66a6 MN |
2009 | mtspr SPRN_HSRR0,r11 |
2010 | mtcrf 0x80,r9 | |
2011 | ld r9,PACA_EXGEN+EX_R9(r13) | |
44e9309f | 2012 | RESTORE_PPR_PACA(PACA_EXGEN, r10) |
630573c1 PM |
2013 | BEGIN_FTR_SECTION |
2014 | ld r10,PACA_EXGEN+EX_CFAR(r13) | |
2015 | mtspr SPRN_CFAR,r10 | |
2016 | END_FTR_SECTION_IFSET(CPU_FTR_CFAR) | |
b92a66a6 MN |
2017 | ld r10,PACA_EXGEN+EX_R10(r13) |
2018 | ld r11,PACA_EXGEN+EX_R11(r13) | |
2019 | ld r12,PACA_EXGEN+EX_R12(r13) | |
2020 | ld r13,PACA_EXGEN+EX_R13(r13) | |
222f20f1 | 2021 | HRFI_TO_UNKNOWN |
b92a66a6 MN |
2022 | b . |
2023 | #endif | |
2024 | ||
872e2ae4 | 2025 | EXC_COMMON(denorm_common, 0x1500, unknown_exception) |
d7e89849 NP |
2026 | |
2027 | ||
2028 | #ifdef CONFIG_CBE_RAS | |
1a6822d1 NP |
2029 | EXC_REAL_HV(cbe_maintenance, 0x1600, 0x100) |
2030 | EXC_VIRT_NONE(0x5600, 0x100) | |
d7e89849 | 2031 | TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1600) |
69a79344 | 2032 | EXC_COMMON(cbe_maintenance_common, 0x1600, cbe_maintenance_exception) |
d7e89849 | 2033 | #else /* CONFIG_CBE_RAS */ |
1a6822d1 NP |
2034 | EXC_REAL_NONE(0x1600, 0x100) |
2035 | EXC_VIRT_NONE(0x5600, 0x100) | |
d7e89849 NP |
2036 | #endif |
2037 | ||
69a79344 | 2038 | |
1a6822d1 NP |
2039 | EXC_REAL(altivec_assist, 0x1700, 0x100) |
2040 | EXC_VIRT(altivec_assist, 0x5700, 0x100, 0x1700) | |
d7e89849 | 2041 | TRAMP_KVM(PACA_EXGEN, 0x1700) |
b51c079e NP |
2042 | #ifdef CONFIG_ALTIVEC |
2043 | EXC_COMMON(altivec_assist_common, 0x1700, altivec_assist_exception) | |
2044 | #else | |
2045 | EXC_COMMON(altivec_assist_common, 0x1700, unknown_exception) | |
2046 | #endif | |
2047 | ||
d7e89849 NP |
2048 | |
2049 | #ifdef CONFIG_CBE_RAS | |
1a6822d1 NP |
2050 | EXC_REAL_HV(cbe_thermal, 0x1800, 0x100) |
2051 | EXC_VIRT_NONE(0x5800, 0x100) | |
d7e89849 | 2052 | TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1800) |
3965f8ab | 2053 | EXC_COMMON(cbe_thermal_common, 0x1800, cbe_thermal_exception) |
d7e89849 | 2054 | #else /* CONFIG_CBE_RAS */ |
1a6822d1 NP |
2055 | EXC_REAL_NONE(0x1800, 0x100) |
2056 | EXC_VIRT_NONE(0x5800, 0x100) | |
d7e89849 NP |
2057 | #endif |
2058 | ||
75eb767e | 2059 | #ifdef CONFIG_PPC_WATCHDOG |
2104180a NP |
2060 | |
2061 | #define MASKED_DEC_HANDLER_LABEL 3f | |
2062 | ||
2063 | #define MASKED_DEC_HANDLER(_H) \ | |
2064 | 3: /* soft-nmi */ \ | |
2065 | std r12,PACA_EXGEN+EX_R12(r13); \ | |
2066 | GET_SCRATCH0(r10); \ | |
2067 | std r10,PACA_EXGEN+EX_R13(r13); \ | |
2d046308 | 2068 | EXCEPTION_PROLOG_2_REAL soft_nmi_common, _H, 1 |
2104180a | 2069 | |
cc491f1d NP |
2070 | /* |
2071 | * Branch to soft_nmi_interrupt using the emergency stack. The emergency | |
2072 | * stack is one that is usable by maskable interrupts so long as MSR_EE | |
2073 | * remains off. It is used for recovery when something has corrupted the | |
2074 | * normal kernel stack, for example. The "soft NMI" must not use the process | |
2075 | * stack because we want irq disabled sections to avoid touching the stack | |
2076 | * at all (other than PMU interrupts), so use the emergency stack for this, | |
2077 | * and run it entirely with interrupts hard disabled. | |
2078 | */ | |
2104180a NP |
2079 | EXC_COMMON_BEGIN(soft_nmi_common) |
2080 | mr r10,r1 | |
2081 | ld r1,PACAEMERGSP(r13) | |
2104180a | 2082 | subi r1,r1,INT_FRAME_SIZE |
47169fba NP |
2083 | EXCEPTION_COMMON_STACK(PACA_EXGEN, 0x900) |
2084 | bl save_nvgprs | |
2085 | RECONCILE_IRQ_STATE(r10, r11) | |
c06075f3 NP |
2086 | addi r3,r1,STACK_FRAME_OVERHEAD |
2087 | bl soft_nmi_interrupt | |
2104180a NP |
2088 | b ret_from_except |
2089 | ||
75eb767e | 2090 | #else /* CONFIG_PPC_WATCHDOG */ |
2104180a NP |
2091 | #define MASKED_DEC_HANDLER_LABEL 2f /* normal return */ |
2092 | #define MASKED_DEC_HANDLER(_H) | |
75eb767e | 2093 | #endif /* CONFIG_PPC_WATCHDOG */ |
d7e89849 | 2094 | |
0ebc4cda | 2095 | /* |
fe9e1d54 IM |
2096 | * An interrupt came in while soft-disabled. We set paca->irq_happened, then: |
2097 | * - If it was a decrementer interrupt, we bump the dec to max and and return. | |
2098 | * - If it was a doorbell we return immediately since doorbells are edge | |
2099 | * triggered and won't automatically refire. | |
0869b6fd MS |
2100 | * - If it was a HMI we return immediately since we handled it in realmode |
2101 | * and it won't refire. | |
6cc3f91b | 2102 | * - Else it is one of PACA_IRQ_MUST_HARD_MASK, so hard disable and return. |
fe9e1d54 | 2103 | * This is called with r10 containing the value to OR to the paca field. |
0ebc4cda | 2104 | */ |
4508a74a NP |
2105 | .macro MASKED_INTERRUPT hsrr |
2106 | .if \hsrr | |
2107 | masked_Hinterrupt: | |
2108 | .else | |
2109 | masked_interrupt: | |
2110 | .endif | |
2111 | std r11,PACA_EXGEN+EX_R11(r13) | |
2112 | lbz r11,PACAIRQHAPPENED(r13) | |
2113 | or r11,r11,r10 | |
2114 | stb r11,PACAIRQHAPPENED(r13) | |
2115 | cmpwi r10,PACA_IRQ_DEC | |
2116 | bne 1f | |
2117 | lis r10,0x7fff | |
2118 | ori r10,r10,0xffff | |
2119 | mtspr SPRN_DEC,r10 | |
2120 | b MASKED_DEC_HANDLER_LABEL | |
2121 | 1: andi. r10,r10,PACA_IRQ_MUST_HARD_MASK | |
2122 | beq 2f | |
2123 | .if \hsrr | |
2124 | mfspr r10,SPRN_HSRR1 | |
2125 | xori r10,r10,MSR_EE /* clear MSR_EE */ | |
2126 | mtspr SPRN_HSRR1,r10 | |
2127 | .else | |
2128 | mfspr r10,SPRN_SRR1 | |
2129 | xori r10,r10,MSR_EE /* clear MSR_EE */ | |
2130 | mtspr SPRN_SRR1,r10 | |
2131 | .endif | |
2132 | ori r11,r11,PACA_IRQ_HARD_DIS | |
2133 | stb r11,PACAIRQHAPPENED(r13) | |
2134 | 2: /* done */ | |
2135 | mtcrf 0x80,r9 | |
2136 | std r1,PACAR1(r13) | |
2137 | ld r9,PACA_EXGEN+EX_R9(r13) | |
2138 | ld r10,PACA_EXGEN+EX_R10(r13) | |
2139 | ld r11,PACA_EXGEN+EX_R11(r13) | |
2140 | /* returns to kernel where r13 must be set up, so don't restore it */ | |
2141 | .if \hsrr | |
2142 | HRFI_TO_KERNEL | |
2143 | .else | |
2144 | RFI_TO_KERNEL | |
2145 | .endif | |
2146 | b . | |
2147 | MASKED_DEC_HANDLER(\hsrr\()) | |
2148 | .endm | |
57f26649 | 2149 | |
a048a07d NP |
2150 | TRAMP_REAL_BEGIN(stf_barrier_fallback) |
2151 | std r9,PACA_EXRFI+EX_R9(r13) | |
2152 | std r10,PACA_EXRFI+EX_R10(r13) | |
2153 | sync | |
2154 | ld r9,PACA_EXRFI+EX_R9(r13) | |
2155 | ld r10,PACA_EXRFI+EX_R10(r13) | |
2156 | ori 31,31,0 | |
2157 | .rept 14 | |
2158 | b 1f | |
2159 | 1: | |
2160 | .endr | |
2161 | blr | |
2162 | ||
aa8a5e00 ME |
2163 | TRAMP_REAL_BEGIN(rfi_flush_fallback) |
2164 | SET_SCRATCH0(r13); | |
2165 | GET_PACA(r13); | |
78ee9946 ME |
2166 | std r1,PACA_EXRFI+EX_R12(r13) |
2167 | ld r1,PACAKSAVE(r13) | |
aa8a5e00 ME |
2168 | std r9,PACA_EXRFI+EX_R9(r13) |
2169 | std r10,PACA_EXRFI+EX_R10(r13) | |
2170 | std r11,PACA_EXRFI+EX_R11(r13) | |
aa8a5e00 ME |
2171 | mfctr r9 |
2172 | ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13) | |
bdcb1aef NP |
2173 | ld r11,PACA_L1D_FLUSH_SIZE(r13) |
2174 | srdi r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */ | |
aa8a5e00 | 2175 | mtctr r11 |
15a3204d | 2176 | DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */ |
aa8a5e00 ME |
2177 | |
2178 | /* order ld/st prior to dcbt stop all streams with flushing */ | |
2179 | sync | |
bdcb1aef NP |
2180 | |
2181 | /* | |
2182 | * The load adresses are at staggered offsets within cachelines, | |
2183 | * which suits some pipelines better (on others it should not | |
2184 | * hurt). | |
2185 | */ | |
2186 | 1: | |
2187 | ld r11,(0x80 + 8)*0(r10) | |
2188 | ld r11,(0x80 + 8)*1(r10) | |
2189 | ld r11,(0x80 + 8)*2(r10) | |
2190 | ld r11,(0x80 + 8)*3(r10) | |
2191 | ld r11,(0x80 + 8)*4(r10) | |
2192 | ld r11,(0x80 + 8)*5(r10) | |
2193 | ld r11,(0x80 + 8)*6(r10) | |
2194 | ld r11,(0x80 + 8)*7(r10) | |
2195 | addi r10,r10,0x80*8 | |
aa8a5e00 ME |
2196 | bdnz 1b |
2197 | ||
2198 | mtctr r9 | |
2199 | ld r9,PACA_EXRFI+EX_R9(r13) | |
2200 | ld r10,PACA_EXRFI+EX_R10(r13) | |
2201 | ld r11,PACA_EXRFI+EX_R11(r13) | |
78ee9946 | 2202 | ld r1,PACA_EXRFI+EX_R12(r13) |
aa8a5e00 ME |
2203 | GET_SCRATCH0(r13); |
2204 | rfid | |
2205 | ||
2206 | TRAMP_REAL_BEGIN(hrfi_flush_fallback) | |
2207 | SET_SCRATCH0(r13); | |
2208 | GET_PACA(r13); | |
78ee9946 ME |
2209 | std r1,PACA_EXRFI+EX_R12(r13) |
2210 | ld r1,PACAKSAVE(r13) | |
aa8a5e00 ME |
2211 | std r9,PACA_EXRFI+EX_R9(r13) |
2212 | std r10,PACA_EXRFI+EX_R10(r13) | |
2213 | std r11,PACA_EXRFI+EX_R11(r13) | |
aa8a5e00 ME |
2214 | mfctr r9 |
2215 | ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13) | |
bdcb1aef NP |
2216 | ld r11,PACA_L1D_FLUSH_SIZE(r13) |
2217 | srdi r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */ | |
aa8a5e00 | 2218 | mtctr r11 |
15a3204d | 2219 | DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */ |
aa8a5e00 ME |
2220 | |
2221 | /* order ld/st prior to dcbt stop all streams with flushing */ | |
2222 | sync | |
bdcb1aef NP |
2223 | |
2224 | /* | |
2225 | * The load adresses are at staggered offsets within cachelines, | |
2226 | * which suits some pipelines better (on others it should not | |
2227 | * hurt). | |
2228 | */ | |
2229 | 1: | |
2230 | ld r11,(0x80 + 8)*0(r10) | |
2231 | ld r11,(0x80 + 8)*1(r10) | |
2232 | ld r11,(0x80 + 8)*2(r10) | |
2233 | ld r11,(0x80 + 8)*3(r10) | |
2234 | ld r11,(0x80 + 8)*4(r10) | |
2235 | ld r11,(0x80 + 8)*5(r10) | |
2236 | ld r11,(0x80 + 8)*6(r10) | |
2237 | ld r11,(0x80 + 8)*7(r10) | |
2238 | addi r10,r10,0x80*8 | |
aa8a5e00 ME |
2239 | bdnz 1b |
2240 | ||
2241 | mtctr r9 | |
2242 | ld r9,PACA_EXRFI+EX_R9(r13) | |
2243 | ld r10,PACA_EXRFI+EX_R10(r13) | |
2244 | ld r11,PACA_EXRFI+EX_R11(r13) | |
78ee9946 | 2245 | ld r1,PACA_EXRFI+EX_R12(r13) |
aa8a5e00 ME |
2246 | GET_SCRATCH0(r13); |
2247 | hrfid | |
2248 | ||
57f26649 NP |
2249 | /* |
2250 | * Real mode exceptions actually use this too, but alternate | |
2251 | * instruction code patches (which end up in the common .text area) | |
2252 | * cannot reach these if they are put there. | |
2253 | */ | |
2254 | USE_FIXED_SECTION(virt_trampolines) | |
4508a74a NP |
2255 | MASKED_INTERRUPT EXC_STD |
2256 | MASKED_INTERRUPT EXC_HV | |
0ebc4cda | 2257 | |
4f6c11db | 2258 | #ifdef CONFIG_KVM_BOOK3S_64_HANDLER |
da2bc464 | 2259 | TRAMP_REAL_BEGIN(kvmppc_skip_interrupt) |
4f6c11db PM |
2260 | /* |
2261 | * Here all GPRs are unchanged from when the interrupt happened | |
2262 | * except for r13, which is saved in SPRG_SCRATCH0. | |
2263 | */ | |
2264 | mfspr r13, SPRN_SRR0 | |
2265 | addi r13, r13, 4 | |
2266 | mtspr SPRN_SRR0, r13 | |
2267 | GET_SCRATCH0(r13) | |
222f20f1 | 2268 | RFI_TO_KERNEL |
4f6c11db PM |
2269 | b . |
2270 | ||
da2bc464 | 2271 | TRAMP_REAL_BEGIN(kvmppc_skip_Hinterrupt) |
4f6c11db PM |
2272 | /* |
2273 | * Here all GPRs are unchanged from when the interrupt happened | |
2274 | * except for r13, which is saved in SPRG_SCRATCH0. | |
2275 | */ | |
2276 | mfspr r13, SPRN_HSRR0 | |
2277 | addi r13, r13, 4 | |
2278 | mtspr SPRN_HSRR0, r13 | |
2279 | GET_SCRATCH0(r13) | |
222f20f1 | 2280 | HRFI_TO_KERNEL |
4f6c11db PM |
2281 | b . |
2282 | #endif | |
2283 | ||
0ebc4cda | 2284 | /* |
057b6d7e HB |
2285 | * Ensure that any handlers that get invoked from the exception prologs |
2286 | * above are below the first 64KB (0x10000) of the kernel image because | |
2287 | * the prologs assemble the addresses of these handlers using the | |
2288 | * LOAD_HANDLER macro, which uses an ori instruction. | |
0ebc4cda BH |
2289 | */ |
2290 | ||
2291 | /*** Common interrupt handlers ***/ | |
2292 | ||
0ebc4cda | 2293 | |
c1fb6816 MN |
2294 | /* |
2295 | * Relocation-on interrupts: A subset of the interrupts can be delivered | |
2296 | * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering | |
2297 | * it. Addresses are the same as the original interrupt addresses, but | |
2298 | * offset by 0xc000000000004000. | |
2299 | * It's impossible to receive interrupts below 0x300 via this mechanism. | |
2300 | * KVM: None of these traps are from the guest ; anything that escalated | |
2301 | * to HV=1 from HV=0 is delivered via real mode handlers. | |
2302 | */ | |
2303 | ||
2304 | /* | |
2305 | * This uses the standard macro, since the original 0x300 vector | |
2306 | * only has extra guff for STAB-based processors -- which never | |
2307 | * come here. | |
2308 | */ | |
da2bc464 | 2309 | |
57f26649 | 2310 | EXC_COMMON_BEGIN(ppc64_runlatch_on_trampoline) |
b1576fec | 2311 | b __ppc64_runlatch_on |
fe1952fc | 2312 | |
57f26649 | 2313 | USE_FIXED_SECTION(virt_trampolines) |
8ed8ab40 HB |
2314 | /* |
2315 | * The __end_interrupts marker must be past the out-of-line (OOL) | |
2316 | * handlers, so that they are copied to real address 0x100 when running | |
2317 | * a relocatable kernel. This ensures they can be reached from the short | |
2318 | * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch | |
2319 | * directly, without using LOAD_HANDLER(). | |
2320 | */ | |
2321 | .align 7 | |
2322 | .globl __end_interrupts | |
2323 | __end_interrupts: | |
57f26649 | 2324 | DEFINE_FIXED_SYMBOL(__end_interrupts) |
61383407 | 2325 | |
087aa036 | 2326 | #ifdef CONFIG_PPC_970_NAP |
7c8cb4b5 | 2327 | EXC_COMMON_BEGIN(power4_fixup_nap) |
087aa036 CG |
2328 | andc r9,r9,r10 |
2329 | std r9,TI_LOCAL_FLAGS(r11) | |
2330 | ld r10,_LINK(r1) /* make idle task do the */ | |
2331 | std r10,_NIP(r1) /* equivalent of a blr */ | |
2332 | blr | |
2333 | #endif | |
2334 | ||
57f26649 NP |
2335 | CLOSE_FIXED_SECTION(real_vectors); |
2336 | CLOSE_FIXED_SECTION(real_trampolines); | |
2337 | CLOSE_FIXED_SECTION(virt_vectors); | |
2338 | CLOSE_FIXED_SECTION(virt_trampolines); | |
2339 | ||
2340 | USE_TEXT_SECTION() | |
2341 | ||
0ebc4cda BH |
2342 | /* |
2343 | * Hash table stuff | |
2344 | */ | |
f4329f2e | 2345 | .balign IFETCH_ALIGN_BYTES |
6a3bab90 | 2346 | do_hash_page: |
4e003747 | 2347 | #ifdef CONFIG_PPC_BOOK3S_64 |
e6c2a479 | 2348 | lis r0,(DSISR_BAD_FAULT_64S | DSISR_DABRMATCH | DSISR_KEYFAULT)@h |
398a719d BH |
2349 | ori r0,r0,DSISR_BAD_FAULT_64S@l |
2350 | and. r0,r4,r0 /* weird error? */ | |
0ebc4cda | 2351 | bne- handle_page_fault /* if not, try to insert a HPTE */ |
c911d2e1 | 2352 | ld r11, PACA_THREAD_INFO(r13) |
9c1e1052 PM |
2353 | lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */ |
2354 | andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */ | |
2355 | bne 77f /* then don't call hash_page now */ | |
0ebc4cda BH |
2356 | |
2357 | /* | |
2358 | * r3 contains the faulting address | |
106713a1 | 2359 | * r4 msr |
0ebc4cda | 2360 | * r5 contains the trap number |
aefa5688 | 2361 | * r6 contains dsisr |
0ebc4cda | 2362 | * |
7230c564 | 2363 | * at return r3 = 0 for success, 1 for page fault, negative for error |
0ebc4cda | 2364 | */ |
106713a1 | 2365 | mr r4,r12 |
aefa5688 | 2366 | ld r6,_DSISR(r1) |
106713a1 AK |
2367 | bl __hash_page /* build HPTE if possible */ |
2368 | cmpdi r3,0 /* see if __hash_page succeeded */ | |
0ebc4cda | 2369 | |
7230c564 | 2370 | /* Success */ |
0ebc4cda | 2371 | beq fast_exc_return_irq /* Return from exception on success */ |
0ebc4cda | 2372 | |
7230c564 BH |
2373 | /* Error */ |
2374 | blt- 13f | |
d89ba535 NR |
2375 | |
2376 | /* Reload DSISR into r4 for the DABR check below */ | |
2377 | ld r4,_DSISR(r1) | |
4e003747 | 2378 | #endif /* CONFIG_PPC_BOOK3S_64 */ |
9c7cc234 | 2379 | |
0ebc4cda BH |
2380 | /* Here we have a page fault that hash_page can't handle. */ |
2381 | handle_page_fault: | |
d89ba535 NR |
2382 | 11: andis. r0,r4,DSISR_DABRMATCH@h |
2383 | bne- handle_dabr_fault | |
2384 | ld r4,_DAR(r1) | |
0ebc4cda BH |
2385 | ld r5,_DSISR(r1) |
2386 | addi r3,r1,STACK_FRAME_OVERHEAD | |
b1576fec | 2387 | bl do_page_fault |
0ebc4cda | 2388 | cmpdi r3,0 |
f474c28f | 2389 | beq+ ret_from_except_lite |
b1576fec | 2390 | bl save_nvgprs |
0ebc4cda BH |
2391 | mr r5,r3 |
2392 | addi r3,r1,STACK_FRAME_OVERHEAD | |
2393 | lwz r4,_DAR(r1) | |
b1576fec AB |
2394 | bl bad_page_fault |
2395 | b ret_from_except | |
0ebc4cda | 2396 | |
a546498f BH |
2397 | /* We have a data breakpoint exception - handle it */ |
2398 | handle_dabr_fault: | |
b1576fec | 2399 | bl save_nvgprs |
a546498f BH |
2400 | ld r4,_DAR(r1) |
2401 | ld r5,_DSISR(r1) | |
2402 | addi r3,r1,STACK_FRAME_OVERHEAD | |
b1576fec | 2403 | bl do_break |
f474c28f RB |
2404 | /* |
2405 | * do_break() may have changed the NV GPRS while handling a breakpoint. | |
2406 | * If so, we need to restore them with their updated values. Don't use | |
2407 | * ret_from_except_lite here. | |
2408 | */ | |
2409 | b ret_from_except | |
a546498f | 2410 | |
0ebc4cda | 2411 | |
4e003747 | 2412 | #ifdef CONFIG_PPC_BOOK3S_64 |
0ebc4cda BH |
2413 | /* We have a page fault that hash_page could handle but HV refused |
2414 | * the PTE insertion | |
2415 | */ | |
b1576fec | 2416 | 13: bl save_nvgprs |
0ebc4cda BH |
2417 | mr r5,r3 |
2418 | addi r3,r1,STACK_FRAME_OVERHEAD | |
2419 | ld r4,_DAR(r1) | |
b1576fec AB |
2420 | bl low_hash_fault |
2421 | b ret_from_except | |
caca285e | 2422 | #endif |
0ebc4cda | 2423 | |
9c1e1052 PM |
2424 | /* |
2425 | * We come here as a result of a DSI at a point where we don't want | |
2426 | * to call hash_page, such as when we are accessing memory (possibly | |
2427 | * user memory) inside a PMU interrupt that occurred while interrupts | |
2428 | * were soft-disabled. We want to invoke the exception handler for | |
2429 | * the access, or panic if there isn't a handler. | |
2430 | */ | |
b1576fec | 2431 | 77: bl save_nvgprs |
9c1e1052 PM |
2432 | mr r4,r3 |
2433 | addi r3,r1,STACK_FRAME_OVERHEAD | |
2434 | li r5,SIGSEGV | |
b1576fec AB |
2435 | bl bad_page_fault |
2436 | b ret_from_except | |
4e2bf01b ME |
2437 | |
2438 | /* | |
2439 | * Here we have detected that the kernel stack pointer is bad. | |
2440 | * R9 contains the saved CR, r13 points to the paca, | |
2441 | * r10 contains the (bad) kernel stack pointer, | |
2442 | * r11 and r12 contain the saved SRR0 and SRR1. | |
2443 | * We switch to using an emergency stack, save the registers there, | |
2444 | * and call kernel_bad_stack(), which panics. | |
2445 | */ | |
2446 | bad_stack: | |
2447 | ld r1,PACAEMERGSP(r13) | |
2448 | subi r1,r1,64+INT_FRAME_SIZE | |
2449 | std r9,_CCR(r1) | |
2450 | std r10,GPR1(r1) | |
2451 | std r11,_NIP(r1) | |
2452 | std r12,_MSR(r1) | |
2453 | mfspr r11,SPRN_DAR | |
2454 | mfspr r12,SPRN_DSISR | |
2455 | std r11,_DAR(r1) | |
2456 | std r12,_DSISR(r1) | |
2457 | mflr r10 | |
2458 | mfctr r11 | |
2459 | mfxer r12 | |
2460 | std r10,_LINK(r1) | |
2461 | std r11,_CTR(r1) | |
2462 | std r12,_XER(r1) | |
2463 | SAVE_GPR(0,r1) | |
2464 | SAVE_GPR(2,r1) | |
2465 | ld r10,EX_R3(r3) | |
2466 | std r10,GPR3(r1) | |
2467 | SAVE_GPR(4,r1) | |
2468 | SAVE_4GPRS(5,r1) | |
2469 | ld r9,EX_R9(r3) | |
2470 | ld r10,EX_R10(r3) | |
2471 | SAVE_2GPRS(9,r1) | |
2472 | ld r9,EX_R11(r3) | |
2473 | ld r10,EX_R12(r3) | |
2474 | ld r11,EX_R13(r3) | |
2475 | std r9,GPR11(r1) | |
2476 | std r10,GPR12(r1) | |
2477 | std r11,GPR13(r1) | |
2478 | BEGIN_FTR_SECTION | |
2479 | ld r10,EX_CFAR(r3) | |
2480 | std r10,ORIG_GPR3(r1) | |
2481 | END_FTR_SECTION_IFSET(CPU_FTR_CFAR) | |
2482 | SAVE_8GPRS(14,r1) | |
2483 | SAVE_10GPRS(22,r1) | |
2484 | lhz r12,PACA_TRAP_SAVE(r13) | |
2485 | std r12,_TRAP(r1) | |
2486 | addi r11,r1,INT_FRAME_SIZE | |
2487 | std r11,0(r1) | |
2488 | li r12,0 | |
2489 | std r12,0(r11) | |
2490 | ld r2,PACATOC(r13) | |
2491 | ld r11,exception_marker@toc(r2) | |
2492 | std r12,RESULT(r1) | |
2493 | std r11,STACK_FRAME_OVERHEAD-16(r1) | |
2494 | 1: addi r3,r1,STACK_FRAME_OVERHEAD | |
2495 | bl kernel_bad_stack | |
2496 | b 1b | |
15770a13 | 2497 | _ASM_NOKPROBE_SYMBOL(bad_stack); |
0f0c6ca1 | 2498 | |
a9af97aa NP |
2499 | /* |
2500 | * When doorbell is triggered from system reset wakeup, the message is | |
2501 | * not cleared, so it would fire again when EE is enabled. | |
2502 | * | |
2503 | * When coming from local_irq_enable, there may be the same problem if | |
2504 | * we were hard disabled. | |
2505 | * | |
2506 | * Execute msgclr to clear pending exceptions before handling it. | |
2507 | */ | |
2508 | h_doorbell_common_msgclr: | |
2509 | LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36)) | |
2510 | PPC_MSGCLR(3) | |
2511 | b h_doorbell_common | |
2512 | ||
2513 | doorbell_super_common_msgclr: | |
2514 | LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36)) | |
2515 | PPC_MSGCLRP(3) | |
2516 | b doorbell_super_common | |
2517 | ||
0f0c6ca1 NP |
2518 | /* |
2519 | * Called from arch_local_irq_enable when an interrupt needs | |
2520 | * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate | |
2521 | * which kind of interrupt. MSR:EE is already off. We generate a | |
2522 | * stackframe like if a real interrupt had happened. | |
2523 | * | |
2524 | * Note: While MSR:EE is off, we need to make sure that _MSR | |
2525 | * in the generated frame has EE set to 1 or the exception | |
2526 | * handler will not properly re-enable them. | |
b48bbb82 NP |
2527 | * |
2528 | * Note that we don't specify LR as the NIP (return address) for | |
2529 | * the interrupt because that would unbalance the return branch | |
2530 | * predictor. | |
0f0c6ca1 NP |
2531 | */ |
2532 | _GLOBAL(__replay_interrupt) | |
2533 | /* We are going to jump to the exception common code which | |
2534 | * will retrieve various register values from the PACA which | |
2535 | * we don't give a damn about, so we don't bother storing them. | |
2536 | */ | |
2537 | mfmsr r12 | |
3e23a12b | 2538 | LOAD_REG_ADDR(r11, replay_interrupt_return) |
0f0c6ca1 NP |
2539 | mfcr r9 |
2540 | ori r12,r12,MSR_EE | |
2541 | cmpwi r3,0x900 | |
2542 | beq decrementer_common | |
2543 | cmpwi r3,0x500 | |
e6c1203d NP |
2544 | BEGIN_FTR_SECTION |
2545 | beq h_virt_irq_common | |
2546 | FTR_SECTION_ELSE | |
0f0c6ca1 | 2547 | beq hardware_interrupt_common |
e6c1203d | 2548 | ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_300) |
f442d004 MS |
2549 | cmpwi r3,0xf00 |
2550 | beq performance_monitor_common | |
0f0c6ca1 | 2551 | BEGIN_FTR_SECTION |
d6f73fc6 | 2552 | cmpwi r3,0xa00 |
a9af97aa | 2553 | beq h_doorbell_common_msgclr |
0f0c6ca1 NP |
2554 | cmpwi r3,0xe60 |
2555 | beq hmi_exception_common | |
2556 | FTR_SECTION_ELSE | |
2557 | cmpwi r3,0xa00 | |
a9af97aa | 2558 | beq doorbell_super_common_msgclr |
0f0c6ca1 | 2559 | ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE) |
3e23a12b | 2560 | replay_interrupt_return: |
0f0c6ca1 | 2561 | blr |
b48bbb82 | 2562 | |
15770a13 | 2563 | _ASM_NOKPROBE_SYMBOL(__replay_interrupt) |