18aa34ab8SBenjamin Herrenschmidt #ifndef _ASM_POWERPC_EXCEPTION_H 28aa34ab8SBenjamin Herrenschmidt #define _ASM_POWERPC_EXCEPTION_H 38aa34ab8SBenjamin Herrenschmidt /* 48aa34ab8SBenjamin Herrenschmidt * Extracted from head_64.S 58aa34ab8SBenjamin Herrenschmidt * 68aa34ab8SBenjamin Herrenschmidt * PowerPC version 78aa34ab8SBenjamin Herrenschmidt * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) 88aa34ab8SBenjamin Herrenschmidt * 98aa34ab8SBenjamin Herrenschmidt * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP 108aa34ab8SBenjamin Herrenschmidt * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu> 118aa34ab8SBenjamin Herrenschmidt * Adapted for Power Macintosh by Paul Mackerras. 128aa34ab8SBenjamin Herrenschmidt * Low-level exception handlers and MMU support 138aa34ab8SBenjamin Herrenschmidt * rewritten by Paul Mackerras. 148aa34ab8SBenjamin Herrenschmidt * Copyright (C) 1996 Paul Mackerras. 158aa34ab8SBenjamin Herrenschmidt * 168aa34ab8SBenjamin Herrenschmidt * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and 178aa34ab8SBenjamin Herrenschmidt * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com 188aa34ab8SBenjamin Herrenschmidt * 198aa34ab8SBenjamin Herrenschmidt * This file contains the low-level support and setup for the 208aa34ab8SBenjamin Herrenschmidt * PowerPC-64 platform, including trap and interrupt dispatch. 218aa34ab8SBenjamin Herrenschmidt * 228aa34ab8SBenjamin Herrenschmidt * This program is free software; you can redistribute it and/or 238aa34ab8SBenjamin Herrenschmidt * modify it under the terms of the GNU General Public License 248aa34ab8SBenjamin Herrenschmidt * as published by the Free Software Foundation; either version 258aa34ab8SBenjamin Herrenschmidt * 2 of the License, or (at your option) any later version. 268aa34ab8SBenjamin Herrenschmidt */ 278aa34ab8SBenjamin Herrenschmidt /* 288aa34ab8SBenjamin Herrenschmidt * The following macros define the code that appears as 298aa34ab8SBenjamin Herrenschmidt * the prologue to each of the exception handlers. They 308aa34ab8SBenjamin Herrenschmidt * are split into two parts to allow a single kernel binary 318aa34ab8SBenjamin Herrenschmidt * to be used for pSeries and iSeries. 328aa34ab8SBenjamin Herrenschmidt * 338aa34ab8SBenjamin Herrenschmidt * We make as much of the exception code common between native 348aa34ab8SBenjamin Herrenschmidt * exception handlers (including pSeries LPAR) and iSeries LPAR 358aa34ab8SBenjamin Herrenschmidt * implementations as possible. 368aa34ab8SBenjamin Herrenschmidt */ 378aa34ab8SBenjamin Herrenschmidt 388aa34ab8SBenjamin Herrenschmidt #define EX_R9 0 398aa34ab8SBenjamin Herrenschmidt #define EX_R10 8 408aa34ab8SBenjamin Herrenschmidt #define EX_R11 16 418aa34ab8SBenjamin Herrenschmidt #define EX_R12 24 428aa34ab8SBenjamin Herrenschmidt #define EX_R13 32 438aa34ab8SBenjamin Herrenschmidt #define EX_SRR0 40 448aa34ab8SBenjamin Herrenschmidt #define EX_DAR 48 458aa34ab8SBenjamin Herrenschmidt #define EX_DSISR 56 468aa34ab8SBenjamin Herrenschmidt #define EX_CCR 60 478aa34ab8SBenjamin Herrenschmidt #define EX_R3 64 488aa34ab8SBenjamin Herrenschmidt #define EX_LR 72 4948404f2eSPaul Mackerras #define EX_CFAR 80 50a09688cdSHaren Myneni #define EX_PPR 88 /* SMT thread status register (priority) */ 518aa34ab8SBenjamin Herrenschmidt 524700dfafSMichael Neuling #ifdef CONFIG_RELOCATABLE 534700dfafSMichael Neuling #define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 544700dfafSMichael Neuling ld r12,PACAKBASE(r13); /* get high part of &label */ \ 554700dfafSMichael Neuling mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 564700dfafSMichael Neuling LOAD_HANDLER(r12,label); \ 574700dfafSMichael Neuling mtlr r12; \ 584700dfafSMichael Neuling mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 594700dfafSMichael Neuling li r10,MSR_RI; \ 604700dfafSMichael Neuling mtmsrd r10,1; /* Set RI (EE=0) */ \ 614700dfafSMichael Neuling blr; 624700dfafSMichael Neuling #else 634700dfafSMichael Neuling /* If not relocatable, we can jump directly -- and save messing with LR */ 644700dfafSMichael Neuling #define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 654700dfafSMichael Neuling mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 664700dfafSMichael Neuling mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 674700dfafSMichael Neuling li r10,MSR_RI; \ 684700dfafSMichael Neuling mtmsrd r10,1; /* Set RI (EE=0) */ \ 694700dfafSMichael Neuling b label; 704700dfafSMichael Neuling #endif 714700dfafSMichael Neuling 724700dfafSMichael Neuling /* 734700dfafSMichael Neuling * As EXCEPTION_PROLOG_PSERIES(), except we've already got relocation on 744700dfafSMichael Neuling * so no need to rfid. Save lr in case we're CONFIG_RELOCATABLE, in which 754700dfafSMichael Neuling * case EXCEPTION_RELON_PROLOG_PSERIES_1 will be using lr. 764700dfafSMichael Neuling */ 774700dfafSMichael Neuling #define EXCEPTION_RELON_PROLOG_PSERIES(area, label, h, extra, vec) \ 784700dfafSMichael Neuling EXCEPTION_PROLOG_1(area, extra, vec); \ 794700dfafSMichael Neuling EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) 804700dfafSMichael Neuling 818aa34ab8SBenjamin Herrenschmidt /* 828aa34ab8SBenjamin Herrenschmidt * We're short on space and time in the exception prolog, so we can't 838aa34ab8SBenjamin Herrenschmidt * use the normal SET_REG_IMMEDIATE macro. Normally we just need the 848aa34ab8SBenjamin Herrenschmidt * low halfword of the address, but for Kdump we need the whole low 858aa34ab8SBenjamin Herrenschmidt * word. 868aa34ab8SBenjamin Herrenschmidt */ 878aa34ab8SBenjamin Herrenschmidt #define LOAD_HANDLER(reg, label) \ 8861e2390eSMichael Neuling /* Handlers must be within 64K of kbase, which must be 64k aligned */ \ 8961e2390eSMichael Neuling ori reg,reg,(label)-_stext; /* virt addr of handler ... */ 908aa34ab8SBenjamin Herrenschmidt 91a5d4f3adSBenjamin Herrenschmidt /* Exception register prefixes */ 92a5d4f3adSBenjamin Herrenschmidt #define EXC_HV H 93a5d4f3adSBenjamin Herrenschmidt #define EXC_STD 94a5d4f3adSBenjamin Herrenschmidt 954700dfafSMichael Neuling #if defined(CONFIG_RELOCATABLE) 964700dfafSMichael Neuling /* 974700dfafSMichael Neuling * If we support interrupts with relocation on AND we're a relocatable 984700dfafSMichael Neuling * kernel, we need to use LR to get to the 2nd level handler. So, save/restore 994700dfafSMichael Neuling * it when required. 1004700dfafSMichael Neuling */ 1014700dfafSMichael Neuling #define SAVE_LR(reg, area) mflr reg ; std reg,area+EX_LR(r13) 1024700dfafSMichael Neuling #define GET_LR(reg, area) ld reg,area+EX_LR(r13) 1034700dfafSMichael Neuling #define RESTORE_LR(reg, area) ld reg,area+EX_LR(r13) ; mtlr reg 1044700dfafSMichael Neuling #else 1054700dfafSMichael Neuling /* ...else LR is unused and in register. */ 1064700dfafSMichael Neuling #define SAVE_LR(reg, area) 1074700dfafSMichael Neuling #define GET_LR(reg, area) mflr reg 1084700dfafSMichael Neuling #define RESTORE_LR(reg, area) 1094700dfafSMichael Neuling #endif 1104700dfafSMichael Neuling 11113e7a8e8SHaren Myneni /* 11213e7a8e8SHaren Myneni * PPR save/restore macros used in exceptions_64s.S 11313e7a8e8SHaren Myneni * Used for P7 or later processors 11413e7a8e8SHaren Myneni */ 11513e7a8e8SHaren Myneni #define SAVE_PPR(area, ra, rb) \ 11613e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(940) \ 11713e7a8e8SHaren Myneni ld ra,PACACURRENT(r13); \ 11813e7a8e8SHaren Myneni ld rb,area+EX_PPR(r13); /* Read PPR from paca */ \ 11913e7a8e8SHaren Myneni std rb,TASKTHREADPPR(ra); \ 12013e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940) 12113e7a8e8SHaren Myneni 12213e7a8e8SHaren Myneni #define RESTORE_PPR_PACA(area, ra) \ 12313e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(941) \ 12413e7a8e8SHaren Myneni ld ra,area+EX_PPR(r13); \ 12513e7a8e8SHaren Myneni mtspr SPRN_PPR,ra; \ 12613e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,941) 12713e7a8e8SHaren Myneni 12813e7a8e8SHaren Myneni /* 12913e7a8e8SHaren Myneni * Increase the priority on systems where PPR save/restore is not 13013e7a8e8SHaren Myneni * implemented/ supported. 13113e7a8e8SHaren Myneni */ 13213e7a8e8SHaren Myneni #define HMT_MEDIUM_PPR_DISCARD \ 13313e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(942) \ 13413e7a8e8SHaren Myneni HMT_MEDIUM; \ 13513e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,0,942) /*non P7*/ 13613e7a8e8SHaren Myneni 13713e7a8e8SHaren Myneni /* 13813e7a8e8SHaren Myneni * Save PPR in paca whenever some register is available to use. 13913e7a8e8SHaren Myneni * Then increase the priority. 14013e7a8e8SHaren Myneni */ 14113e7a8e8SHaren Myneni #define HMT_MEDIUM_PPR_SAVE(area, ra) \ 14213e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(943) \ 14313e7a8e8SHaren Myneni mfspr ra,SPRN_PPR; \ 14413e7a8e8SHaren Myneni std ra,area+EX_PPR(r13); \ 14513e7a8e8SHaren Myneni HMT_MEDIUM; \ 14613e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,943) 14713e7a8e8SHaren Myneni 148b01c8b54SPaul Mackerras #define __EXCEPTION_PROLOG_1(area, extra, vec) \ 1492dd60d79SBenjamin Herrenschmidt GET_PACA(r13); \ 15044e9309fSHaren Myneni std r9,area+EX_R9(r13); /* save r9 */ \ 15144e9309fSHaren Myneni HMT_MEDIUM_PPR_SAVE(area, r9); \ 15244e9309fSHaren Myneni std r10,area+EX_R10(r13); /* save r10 - r12 */ \ 15348404f2eSPaul Mackerras BEGIN_FTR_SECTION_NESTED(66); \ 15448404f2eSPaul Mackerras mfspr r10,SPRN_CFAR; \ 15548404f2eSPaul Mackerras std r10,area+EX_CFAR(r13); \ 15648404f2eSPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \ 157c1fb6816SMichael Neuling SAVE_LR(r10, area); \ 158b01c8b54SPaul Mackerras mfcr r9; \ 159b01c8b54SPaul Mackerras extra(vec); \ 160b01c8b54SPaul Mackerras std r11,area+EX_R11(r13); \ 161b01c8b54SPaul Mackerras std r12,area+EX_R12(r13); \ 162b01c8b54SPaul Mackerras GET_SCRATCH0(r10); \ 163b01c8b54SPaul Mackerras std r10,area+EX_R13(r13) 164b01c8b54SPaul Mackerras #define EXCEPTION_PROLOG_1(area, extra, vec) \ 165b01c8b54SPaul Mackerras __EXCEPTION_PROLOG_1(area, extra, vec) 1668aa34ab8SBenjamin Herrenschmidt 167a5d4f3adSBenjamin Herrenschmidt #define __EXCEPTION_PROLOG_PSERIES_1(label, h) \ 1688aa34ab8SBenjamin Herrenschmidt ld r12,PACAKBASE(r13); /* get high part of &label */ \ 1698aa34ab8SBenjamin Herrenschmidt ld r10,PACAKMSR(r13); /* get MSR value for kernel */ \ 170a5d4f3adSBenjamin Herrenschmidt mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 1718aa34ab8SBenjamin Herrenschmidt LOAD_HANDLER(r12,label) \ 172a5d4f3adSBenjamin Herrenschmidt mtspr SPRN_##h##SRR0,r12; \ 173a5d4f3adSBenjamin Herrenschmidt mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 174a5d4f3adSBenjamin Herrenschmidt mtspr SPRN_##h##SRR1,r10; \ 175a5d4f3adSBenjamin Herrenschmidt h##rfid; \ 1768aa34ab8SBenjamin Herrenschmidt b . /* prevent speculative execution */ 177a5d4f3adSBenjamin Herrenschmidt #define EXCEPTION_PROLOG_PSERIES_1(label, h) \ 178a5d4f3adSBenjamin Herrenschmidt __EXCEPTION_PROLOG_PSERIES_1(label, h) 1798aa34ab8SBenjamin Herrenschmidt 180b01c8b54SPaul Mackerras #define EXCEPTION_PROLOG_PSERIES(area, label, h, extra, vec) \ 181b01c8b54SPaul Mackerras EXCEPTION_PROLOG_1(area, extra, vec); \ 182a5d4f3adSBenjamin Herrenschmidt EXCEPTION_PROLOG_PSERIES_1(label, h); 183c5a8c0c9SBenjamin Herrenschmidt 184b01c8b54SPaul Mackerras #define __KVMTEST(n) \ 1853c42bf8aSPaul Mackerras lbz r10,HSTATE_IN_GUEST(r13); \ 186b01c8b54SPaul Mackerras cmpwi r10,0; \ 187b01c8b54SPaul Mackerras bne do_kvm_##n 188b01c8b54SPaul Mackerras 189b01c8b54SPaul Mackerras #define __KVM_HANDLER(area, h, n) \ 190b01c8b54SPaul Mackerras do_kvm_##n: \ 191b01c8b54SPaul Mackerras ld r10,area+EX_R10(r13); \ 1923c42bf8aSPaul Mackerras stw r9,HSTATE_SCRATCH1(r13); \ 193b01c8b54SPaul Mackerras ld r9,area+EX_R9(r13); \ 1943c42bf8aSPaul Mackerras std r12,HSTATE_SCRATCH0(r13); \ 195b01c8b54SPaul Mackerras li r12,n; \ 196b01c8b54SPaul Mackerras b kvmppc_interrupt 197b01c8b54SPaul Mackerras 198b01c8b54SPaul Mackerras #define __KVM_HANDLER_SKIP(area, h, n) \ 199b01c8b54SPaul Mackerras do_kvm_##n: \ 200b01c8b54SPaul Mackerras cmpwi r10,KVM_GUEST_MODE_SKIP; \ 201b01c8b54SPaul Mackerras ld r10,area+EX_R10(r13); \ 202b01c8b54SPaul Mackerras beq 89f; \ 2033c42bf8aSPaul Mackerras stw r9,HSTATE_SCRATCH1(r13); \ 204b01c8b54SPaul Mackerras ld r9,area+EX_R9(r13); \ 2053c42bf8aSPaul Mackerras std r12,HSTATE_SCRATCH0(r13); \ 206b01c8b54SPaul Mackerras li r12,n; \ 207b01c8b54SPaul Mackerras b kvmppc_interrupt; \ 208b01c8b54SPaul Mackerras 89: mtocrf 0x80,r9; \ 209b01c8b54SPaul Mackerras ld r9,area+EX_R9(r13); \ 210b01c8b54SPaul Mackerras b kvmppc_skip_##h##interrupt 211b01c8b54SPaul Mackerras 212b01c8b54SPaul Mackerras #ifdef CONFIG_KVM_BOOK3S_64_HANDLER 213b01c8b54SPaul Mackerras #define KVMTEST(n) __KVMTEST(n) 214b01c8b54SPaul Mackerras #define KVM_HANDLER(area, h, n) __KVM_HANDLER(area, h, n) 215b01c8b54SPaul Mackerras #define KVM_HANDLER_SKIP(area, h, n) __KVM_HANDLER_SKIP(area, h, n) 216b01c8b54SPaul Mackerras 217b01c8b54SPaul Mackerras #else 218b01c8b54SPaul Mackerras #define KVMTEST(n) 219b01c8b54SPaul Mackerras #define KVM_HANDLER(area, h, n) 220b01c8b54SPaul Mackerras #define KVM_HANDLER_SKIP(area, h, n) 221b01c8b54SPaul Mackerras #endif 222b01c8b54SPaul Mackerras 223de56a948SPaul Mackerras #ifdef CONFIG_KVM_BOOK3S_PR 224de56a948SPaul Mackerras #define KVMTEST_PR(n) __KVMTEST(n) 225de56a948SPaul Mackerras #define KVM_HANDLER_PR(area, h, n) __KVM_HANDLER(area, h, n) 226de56a948SPaul Mackerras #define KVM_HANDLER_PR_SKIP(area, h, n) __KVM_HANDLER_SKIP(area, h, n) 227de56a948SPaul Mackerras 228de56a948SPaul Mackerras #else 229de56a948SPaul Mackerras #define KVMTEST_PR(n) 230de56a948SPaul Mackerras #define KVM_HANDLER_PR(area, h, n) 231de56a948SPaul Mackerras #define KVM_HANDLER_PR_SKIP(area, h, n) 232de56a948SPaul Mackerras #endif 233de56a948SPaul Mackerras 234b01c8b54SPaul Mackerras #define NOTEST(n) 235b01c8b54SPaul Mackerras 2368aa34ab8SBenjamin Herrenschmidt /* 2378aa34ab8SBenjamin Herrenschmidt * The common exception prolog is used for all except a few exceptions 2388aa34ab8SBenjamin Herrenschmidt * such as a segment miss on a kernel address. We have to be prepared 2398aa34ab8SBenjamin Herrenschmidt * to take another exception from the point where we first touch the 2408aa34ab8SBenjamin Herrenschmidt * kernel stack onwards. 2418aa34ab8SBenjamin Herrenschmidt * 2428aa34ab8SBenjamin Herrenschmidt * On entry r13 points to the paca, r9-r13 are saved in the paca, 2438aa34ab8SBenjamin Herrenschmidt * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and 2448aa34ab8SBenjamin Herrenschmidt * SRR1, and relocation is on. 2458aa34ab8SBenjamin Herrenschmidt */ 2468aa34ab8SBenjamin Herrenschmidt #define EXCEPTION_PROLOG_COMMON(n, area) \ 2478aa34ab8SBenjamin Herrenschmidt andi. r10,r12,MSR_PR; /* See if coming from user */ \ 2488aa34ab8SBenjamin Herrenschmidt mr r10,r1; /* Save r1 */ \ 2498aa34ab8SBenjamin Herrenschmidt subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \ 2508aa34ab8SBenjamin Herrenschmidt beq- 1f; \ 2518aa34ab8SBenjamin Herrenschmidt ld r1,PACAKSAVE(r13); /* kernel stack to use */ \ 2528aa34ab8SBenjamin Herrenschmidt 1: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \ 2531977b502SPaul Mackerras blt+ cr1,3f; /* abort if it is */ \ 2541977b502SPaul Mackerras li r1,(n); /* will be reloaded later */ \ 2558aa34ab8SBenjamin Herrenschmidt sth r1,PACA_TRAP_SAVE(r13); \ 2561977b502SPaul Mackerras std r3,area+EX_R3(r13); \ 2571977b502SPaul Mackerras addi r3,r13,area; /* r3 -> where regs are saved*/ \ 258c1fb6816SMichael Neuling RESTORE_LR(r1, area); \ 2598aa34ab8SBenjamin Herrenschmidt b bad_stack; \ 2608aa34ab8SBenjamin Herrenschmidt 3: std r9,_CCR(r1); /* save CR in stackframe */ \ 2618aa34ab8SBenjamin Herrenschmidt std r11,_NIP(r1); /* save SRR0 in stackframe */ \ 2628aa34ab8SBenjamin Herrenschmidt std r12,_MSR(r1); /* save SRR1 in stackframe */ \ 2638aa34ab8SBenjamin Herrenschmidt std r10,0(r1); /* make stack chain pointer */ \ 2648aa34ab8SBenjamin Herrenschmidt std r0,GPR0(r1); /* save r0 in stackframe */ \ 2658aa34ab8SBenjamin Herrenschmidt std r10,GPR1(r1); /* save r1 in stackframe */ \ 2665d75b264SHaren Myneni beq 4f; /* if from kernel mode */ \ 2678aa34ab8SBenjamin Herrenschmidt ACCOUNT_CPU_USER_ENTRY(r9, r10); \ 26844e9309fSHaren Myneni SAVE_PPR(area, r9, r10); \ 2695d75b264SHaren Myneni 4: std r2,GPR2(r1); /* save r2 in stackframe */ \ 2708aa34ab8SBenjamin Herrenschmidt SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \ 2718aa34ab8SBenjamin Herrenschmidt SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \ 2728aa34ab8SBenjamin Herrenschmidt ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \ 2738aa34ab8SBenjamin Herrenschmidt ld r10,area+EX_R10(r13); \ 2748aa34ab8SBenjamin Herrenschmidt std r9,GPR9(r1); \ 2758aa34ab8SBenjamin Herrenschmidt std r10,GPR10(r1); \ 2768aa34ab8SBenjamin Herrenschmidt ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \ 2778aa34ab8SBenjamin Herrenschmidt ld r10,area+EX_R12(r13); \ 2788aa34ab8SBenjamin Herrenschmidt ld r11,area+EX_R13(r13); \ 2798aa34ab8SBenjamin Herrenschmidt std r9,GPR11(r1); \ 2808aa34ab8SBenjamin Herrenschmidt std r10,GPR12(r1); \ 2818aa34ab8SBenjamin Herrenschmidt std r11,GPR13(r1); \ 28248404f2eSPaul Mackerras BEGIN_FTR_SECTION_NESTED(66); \ 28348404f2eSPaul Mackerras ld r10,area+EX_CFAR(r13); \ 28448404f2eSPaul Mackerras std r10,ORIG_GPR3(r1); \ 28548404f2eSPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \ 286c1fb6816SMichael Neuling GET_LR(r9,area); /* Get LR, later save to stack */ \ 2878aa34ab8SBenjamin Herrenschmidt ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \ 2888aa34ab8SBenjamin Herrenschmidt std r9,_LINK(r1); \ 2898aa34ab8SBenjamin Herrenschmidt mfctr r10; /* save CTR in stackframe */ \ 2908aa34ab8SBenjamin Herrenschmidt std r10,_CTR(r1); \ 2918aa34ab8SBenjamin Herrenschmidt lbz r10,PACASOFTIRQEN(r13); \ 2928aa34ab8SBenjamin Herrenschmidt mfspr r11,SPRN_XER; /* save XER in stackframe */ \ 2938aa34ab8SBenjamin Herrenschmidt std r10,SOFTE(r1); \ 2948aa34ab8SBenjamin Herrenschmidt std r11,_XER(r1); \ 2958aa34ab8SBenjamin Herrenschmidt li r9,(n)+1; \ 2968aa34ab8SBenjamin Herrenschmidt std r9,_TRAP(r1); /* set trap number */ \ 2978aa34ab8SBenjamin Herrenschmidt li r10,0; \ 2988aa34ab8SBenjamin Herrenschmidt ld r11,exception_marker@toc(r2); \ 2998aa34ab8SBenjamin Herrenschmidt std r10,RESULT(r1); /* clear regs->result */ \ 300cf9efce0SPaul Mackerras std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */ \ 301cf9efce0SPaul Mackerras ACCOUNT_STOLEN_TIME 3028aa34ab8SBenjamin Herrenschmidt 3038aa34ab8SBenjamin Herrenschmidt /* 3048aa34ab8SBenjamin Herrenschmidt * Exception vectors. 3058aa34ab8SBenjamin Herrenschmidt */ 306b3e6b5dfSBenjamin Herrenschmidt #define STD_EXCEPTION_PSERIES(loc, vec, label) \ 307b3e6b5dfSBenjamin Herrenschmidt . = loc; \ 3088aa34ab8SBenjamin Herrenschmidt .globl label##_pSeries; \ 3098aa34ab8SBenjamin Herrenschmidt label##_pSeries: \ 31044e9309fSHaren Myneni HMT_MEDIUM_PPR_DISCARD; \ 311673b189aSPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 312b01c8b54SPaul Mackerras EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common, \ 313de56a948SPaul Mackerras EXC_STD, KVMTEST_PR, vec) 3148aa34ab8SBenjamin Herrenschmidt 315b3e6b5dfSBenjamin Herrenschmidt #define STD_EXCEPTION_HV(loc, vec, label) \ 316b3e6b5dfSBenjamin Herrenschmidt . = loc; \ 317b3e6b5dfSBenjamin Herrenschmidt .globl label##_hv; \ 318b3e6b5dfSBenjamin Herrenschmidt label##_hv: \ 31944e9309fSHaren Myneni HMT_MEDIUM_PPR_DISCARD; \ 320673b189aSPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 321b01c8b54SPaul Mackerras EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common, \ 322b01c8b54SPaul Mackerras EXC_HV, KVMTEST, vec) 3238aa34ab8SBenjamin Herrenschmidt 3244700dfafSMichael Neuling #define STD_RELON_EXCEPTION_PSERIES(loc, vec, label) \ 3254700dfafSMichael Neuling . = loc; \ 3264700dfafSMichael Neuling .globl label##_relon_pSeries; \ 3274700dfafSMichael Neuling label##_relon_pSeries: \ 32844e9309fSHaren Myneni HMT_MEDIUM_PPR_DISCARD; \ 3294700dfafSMichael Neuling /* No guest interrupts come through here */ \ 3304700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 3314700dfafSMichael Neuling EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label##_common, \ 3324700dfafSMichael Neuling EXC_STD, KVMTEST_PR, vec) 3334700dfafSMichael Neuling 3344700dfafSMichael Neuling #define STD_RELON_EXCEPTION_HV(loc, vec, label) \ 3354700dfafSMichael Neuling . = loc; \ 3364700dfafSMichael Neuling .globl label##_relon_hv; \ 3374700dfafSMichael Neuling label##_relon_hv: \ 33844e9309fSHaren Myneni HMT_MEDIUM_PPR_DISCARD; \ 3394700dfafSMichael Neuling /* No guest interrupts come through here */ \ 3404700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 3414700dfafSMichael Neuling EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label##_common, \ 3424700dfafSMichael Neuling EXC_HV, KVMTEST, vec) 3434700dfafSMichael Neuling 3447230c564SBenjamin Herrenschmidt /* This associate vector numbers with bits in paca->irq_happened */ 3457230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x500 PACA_IRQ_EE 3467230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x502 PACA_IRQ_EE 3477230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x900 PACA_IRQ_DEC 3487230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x982 PACA_IRQ_DEC 3491dbdafecSIan Munsie #define SOFTEN_VALUE_0xa00 PACA_IRQ_DBELL 350655bb3f4SIan Munsie #define SOFTEN_VALUE_0xe80 PACA_IRQ_DBELL 351655bb3f4SIan Munsie #define SOFTEN_VALUE_0xe82 PACA_IRQ_DBELL 3527230c564SBenjamin Herrenschmidt 3537230c564SBenjamin Herrenschmidt #define __SOFTEN_TEST(h, vec) \ 3548aa34ab8SBenjamin Herrenschmidt lbz r10,PACASOFTIRQEN(r13); \ 3558aa34ab8SBenjamin Herrenschmidt cmpwi r10,0; \ 3567230c564SBenjamin Herrenschmidt li r10,SOFTEN_VALUE_##vec; \ 357b01c8b54SPaul Mackerras beq masked_##h##interrupt 3587230c564SBenjamin Herrenschmidt #define _SOFTEN_TEST(h, vec) __SOFTEN_TEST(h, vec) 359b01c8b54SPaul Mackerras 360de56a948SPaul Mackerras #define SOFTEN_TEST_PR(vec) \ 361de56a948SPaul Mackerras KVMTEST_PR(vec); \ 3627230c564SBenjamin Herrenschmidt _SOFTEN_TEST(EXC_STD, vec) 363b01c8b54SPaul Mackerras 364b01c8b54SPaul Mackerras #define SOFTEN_TEST_HV(vec) \ 365b01c8b54SPaul Mackerras KVMTEST(vec); \ 3667230c564SBenjamin Herrenschmidt _SOFTEN_TEST(EXC_HV, vec) 367b01c8b54SPaul Mackerras 3689e368f29SPaul Mackerras #define SOFTEN_TEST_HV_201(vec) \ 3699e368f29SPaul Mackerras KVMTEST(vec); \ 3707230c564SBenjamin Herrenschmidt _SOFTEN_TEST(EXC_STD, vec) 3719e368f29SPaul Mackerras 3724700dfafSMichael Neuling #define SOFTEN_NOTEST_PR(vec) _SOFTEN_TEST(EXC_STD, vec) 3734700dfafSMichael Neuling #define SOFTEN_NOTEST_HV(vec) _SOFTEN_TEST(EXC_HV, vec) 3744700dfafSMichael Neuling 375b01c8b54SPaul Mackerras #define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \ 37644e9309fSHaren Myneni HMT_MEDIUM_PPR_DISCARD; \ 377b01c8b54SPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 378b01c8b54SPaul Mackerras __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \ 379b01c8b54SPaul Mackerras EXCEPTION_PROLOG_PSERIES_1(label##_common, h); 380b01c8b54SPaul Mackerras #define _MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \ 381b01c8b54SPaul Mackerras __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) 382b3e6b5dfSBenjamin Herrenschmidt 383b3e6b5dfSBenjamin Herrenschmidt #define MASKABLE_EXCEPTION_PSERIES(loc, vec, label) \ 384b3e6b5dfSBenjamin Herrenschmidt . = loc; \ 385b3e6b5dfSBenjamin Herrenschmidt .globl label##_pSeries; \ 386b3e6b5dfSBenjamin Herrenschmidt label##_pSeries: \ 387b01c8b54SPaul Mackerras _MASKABLE_EXCEPTION_PSERIES(vec, label, \ 388de56a948SPaul Mackerras EXC_STD, SOFTEN_TEST_PR) 389b3e6b5dfSBenjamin Herrenschmidt 390b3e6b5dfSBenjamin Herrenschmidt #define MASKABLE_EXCEPTION_HV(loc, vec, label) \ 391b3e6b5dfSBenjamin Herrenschmidt . = loc; \ 392b3e6b5dfSBenjamin Herrenschmidt .globl label##_hv; \ 393b3e6b5dfSBenjamin Herrenschmidt label##_hv: \ 394b01c8b54SPaul Mackerras _MASKABLE_EXCEPTION_PSERIES(vec, label, \ 395b01c8b54SPaul Mackerras EXC_HV, SOFTEN_TEST_HV) 3968aa34ab8SBenjamin Herrenschmidt 3974700dfafSMichael Neuling #define __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \ 39844e9309fSHaren Myneni HMT_MEDIUM_PPR_DISCARD; \ 3994700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 4004700dfafSMichael Neuling __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \ 4014700dfafSMichael Neuling EXCEPTION_RELON_PROLOG_PSERIES_1(label##_common, h); 4024700dfafSMichael Neuling #define _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \ 4034700dfafSMichael Neuling __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) 4044700dfafSMichael Neuling 4054700dfafSMichael Neuling #define MASKABLE_RELON_EXCEPTION_PSERIES(loc, vec, label) \ 4064700dfafSMichael Neuling . = loc; \ 4074700dfafSMichael Neuling .globl label##_relon_pSeries; \ 4084700dfafSMichael Neuling label##_relon_pSeries: \ 4094700dfafSMichael Neuling _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \ 4104700dfafSMichael Neuling EXC_STD, SOFTEN_NOTEST_PR) 4114700dfafSMichael Neuling 4124700dfafSMichael Neuling #define MASKABLE_RELON_EXCEPTION_HV(loc, vec, label) \ 4134700dfafSMichael Neuling . = loc; \ 4144700dfafSMichael Neuling .globl label##_relon_hv; \ 4154700dfafSMichael Neuling label##_relon_hv: \ 4164700dfafSMichael Neuling _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \ 4174700dfafSMichael Neuling EXC_HV, SOFTEN_NOTEST_HV) 4184700dfafSMichael Neuling 4191b701179SBenjamin Herrenschmidt /* 4201b701179SBenjamin Herrenschmidt * Our exception common code can be passed various "additions" 4211b701179SBenjamin Herrenschmidt * to specify the behaviour of interrupts, whether to kick the 4221b701179SBenjamin Herrenschmidt * runlatch, etc... 4231b701179SBenjamin Herrenschmidt */ 4241b701179SBenjamin Herrenschmidt 4251b701179SBenjamin Herrenschmidt /* Exception addition: Hard disable interrupts */ 4267230c564SBenjamin Herrenschmidt #define DISABLE_INTS SOFT_DISABLE_INTS(r10,r11) 4278aa34ab8SBenjamin Herrenschmidt 428fe1952fcSBenjamin Herrenschmidt #define ADD_NVGPRS \ 429fe1952fcSBenjamin Herrenschmidt bl .save_nvgprs 430fe1952fcSBenjamin Herrenschmidt 431fe1952fcSBenjamin Herrenschmidt #define RUNLATCH_ON \ 432fe1952fcSBenjamin Herrenschmidt BEGIN_FTR_SECTION \ 4339778b696SStuart Yoder CURRENT_THREAD_INFO(r3, r1); \ 434fe1952fcSBenjamin Herrenschmidt ld r4,TI_LOCAL_FLAGS(r3); \ 435fe1952fcSBenjamin Herrenschmidt andi. r0,r4,_TLF_RUNLATCH; \ 436fe1952fcSBenjamin Herrenschmidt beql ppc64_runlatch_on_trampoline; \ 437fe1952fcSBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CTRL) 438fe1952fcSBenjamin Herrenschmidt 439fe1952fcSBenjamin Herrenschmidt #define EXCEPTION_COMMON(trap, label, hdlr, ret, additions) \ 4408aa34ab8SBenjamin Herrenschmidt .align 7; \ 4418aa34ab8SBenjamin Herrenschmidt .globl label##_common; \ 4428aa34ab8SBenjamin Herrenschmidt label##_common: \ 4438aa34ab8SBenjamin Herrenschmidt EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \ 444fe1952fcSBenjamin Herrenschmidt additions; \ 4458aa34ab8SBenjamin Herrenschmidt addi r3,r1,STACK_FRAME_OVERHEAD; \ 4468aa34ab8SBenjamin Herrenschmidt bl hdlr; \ 447fe1952fcSBenjamin Herrenschmidt b ret 448fe1952fcSBenjamin Herrenschmidt 449fe1952fcSBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON(trap, label, hdlr) \ 450fe1952fcSBenjamin Herrenschmidt EXCEPTION_COMMON(trap, label, hdlr, ret_from_except, \ 451fe1952fcSBenjamin Herrenschmidt ADD_NVGPRS;DISABLE_INTS) 4528aa34ab8SBenjamin Herrenschmidt 4538aa34ab8SBenjamin Herrenschmidt /* 4548aa34ab8SBenjamin Herrenschmidt * Like STD_EXCEPTION_COMMON, but for exceptions that can occur 4557450f6f0SBenjamin Herrenschmidt * in the idle task and therefore need the special idle handling 4567450f6f0SBenjamin Herrenschmidt * (finish nap and runlatch) 4578aa34ab8SBenjamin Herrenschmidt */ 4587450f6f0SBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON_ASYNC(trap, label, hdlr) \ 459fe1952fcSBenjamin Herrenschmidt EXCEPTION_COMMON(trap, label, hdlr, ret_from_except_lite, \ 460fe1952fcSBenjamin Herrenschmidt FINISH_NAP;RUNLATCH_ON;DISABLE_INTS) 4618aa34ab8SBenjamin Herrenschmidt 4628aa34ab8SBenjamin Herrenschmidt /* 4638aa34ab8SBenjamin Herrenschmidt * When the idle code in power4_idle puts the CPU into NAP mode, 4648aa34ab8SBenjamin Herrenschmidt * it has to do so in a loop, and relies on the external interrupt 4658aa34ab8SBenjamin Herrenschmidt * and decrementer interrupt entry code to get it out of the loop. 4668aa34ab8SBenjamin Herrenschmidt * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags 4678aa34ab8SBenjamin Herrenschmidt * to signal that it is in the loop and needs help to get out. 4688aa34ab8SBenjamin Herrenschmidt */ 4698aa34ab8SBenjamin Herrenschmidt #ifdef CONFIG_PPC_970_NAP 4708aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP \ 4718aa34ab8SBenjamin Herrenschmidt BEGIN_FTR_SECTION \ 4729778b696SStuart Yoder CURRENT_THREAD_INFO(r11, r1); \ 4738aa34ab8SBenjamin Herrenschmidt ld r9,TI_LOCAL_FLAGS(r11); \ 4748aa34ab8SBenjamin Herrenschmidt andi. r10,r9,_TLF_NAPPING; \ 4758aa34ab8SBenjamin Herrenschmidt bnel power4_fixup_nap; \ 4768aa34ab8SBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP) 4778aa34ab8SBenjamin Herrenschmidt #else 4788aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP 4798aa34ab8SBenjamin Herrenschmidt #endif 4808aa34ab8SBenjamin Herrenschmidt 4818aa34ab8SBenjamin Herrenschmidt #endif /* _ASM_POWERPC_EXCEPTION_H */ 482