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 508aa34ab8SBenjamin Herrenschmidt 514700dfafSMichael Neuling #ifdef CONFIG_RELOCATABLE 524700dfafSMichael Neuling #define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 534700dfafSMichael Neuling ld r12,PACAKBASE(r13); /* get high part of &label */ \ 544700dfafSMichael Neuling mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 554700dfafSMichael Neuling LOAD_HANDLER(r12,label); \ 564700dfafSMichael Neuling mtlr r12; \ 574700dfafSMichael Neuling mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 584700dfafSMichael Neuling li r10,MSR_RI; \ 594700dfafSMichael Neuling mtmsrd r10,1; /* Set RI (EE=0) */ \ 604700dfafSMichael Neuling blr; 614700dfafSMichael Neuling #else 624700dfafSMichael Neuling /* If not relocatable, we can jump directly -- and save messing with LR */ 634700dfafSMichael Neuling #define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 644700dfafSMichael Neuling mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 654700dfafSMichael Neuling mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 664700dfafSMichael Neuling li r10,MSR_RI; \ 674700dfafSMichael Neuling mtmsrd r10,1; /* Set RI (EE=0) */ \ 684700dfafSMichael Neuling b label; 694700dfafSMichael Neuling #endif 704700dfafSMichael Neuling 714700dfafSMichael Neuling /* 724700dfafSMichael Neuling * As EXCEPTION_PROLOG_PSERIES(), except we've already got relocation on 734700dfafSMichael Neuling * so no need to rfid. Save lr in case we're CONFIG_RELOCATABLE, in which 744700dfafSMichael Neuling * case EXCEPTION_RELON_PROLOG_PSERIES_1 will be using lr. 754700dfafSMichael Neuling */ 764700dfafSMichael Neuling #define EXCEPTION_RELON_PROLOG_PSERIES(area, label, h, extra, vec) \ 774700dfafSMichael Neuling EXCEPTION_PROLOG_1(area, extra, vec); \ 784700dfafSMichael Neuling EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) 794700dfafSMichael Neuling 808aa34ab8SBenjamin Herrenschmidt /* 818aa34ab8SBenjamin Herrenschmidt * We're short on space and time in the exception prolog, so we can't 828aa34ab8SBenjamin Herrenschmidt * use the normal SET_REG_IMMEDIATE macro. Normally we just need the 838aa34ab8SBenjamin Herrenschmidt * low halfword of the address, but for Kdump we need the whole low 848aa34ab8SBenjamin Herrenschmidt * word. 858aa34ab8SBenjamin Herrenschmidt */ 868aa34ab8SBenjamin Herrenschmidt #define LOAD_HANDLER(reg, label) \ 8761e2390eSMichael Neuling /* Handlers must be within 64K of kbase, which must be 64k aligned */ \ 8861e2390eSMichael Neuling ori reg,reg,(label)-_stext; /* virt addr of handler ... */ 898aa34ab8SBenjamin Herrenschmidt 90a5d4f3adSBenjamin Herrenschmidt /* Exception register prefixes */ 91a5d4f3adSBenjamin Herrenschmidt #define EXC_HV H 92a5d4f3adSBenjamin Herrenschmidt #define EXC_STD 93a5d4f3adSBenjamin Herrenschmidt 944700dfafSMichael Neuling #if defined(CONFIG_RELOCATABLE) 954700dfafSMichael Neuling /* 964700dfafSMichael Neuling * If we support interrupts with relocation on AND we're a relocatable 974700dfafSMichael Neuling * kernel, we need to use LR to get to the 2nd level handler. So, save/restore 984700dfafSMichael Neuling * it when required. 994700dfafSMichael Neuling */ 1004700dfafSMichael Neuling #define SAVE_LR(reg, area) mflr reg ; std reg,area+EX_LR(r13) 1014700dfafSMichael Neuling #define GET_LR(reg, area) ld reg,area+EX_LR(r13) 1024700dfafSMichael Neuling #define RESTORE_LR(reg, area) ld reg,area+EX_LR(r13) ; mtlr reg 1034700dfafSMichael Neuling #else 1044700dfafSMichael Neuling /* ...else LR is unused and in register. */ 1054700dfafSMichael Neuling #define SAVE_LR(reg, area) 1064700dfafSMichael Neuling #define GET_LR(reg, area) mflr reg 1074700dfafSMichael Neuling #define RESTORE_LR(reg, area) 1084700dfafSMichael Neuling #endif 1094700dfafSMichael Neuling 110b01c8b54SPaul Mackerras #define __EXCEPTION_PROLOG_1(area, extra, vec) \ 1112dd60d79SBenjamin Herrenschmidt GET_PACA(r13); \ 1128aa34ab8SBenjamin Herrenschmidt std r9,area+EX_R9(r13); /* save r9 - r12 */ \ 1138aa34ab8SBenjamin Herrenschmidt std r10,area+EX_R10(r13); \ 11448404f2eSPaul Mackerras BEGIN_FTR_SECTION_NESTED(66); \ 11548404f2eSPaul Mackerras mfspr r10,SPRN_CFAR; \ 11648404f2eSPaul Mackerras std r10,area+EX_CFAR(r13); \ 11748404f2eSPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \ 118c1fb6816SMichael Neuling SAVE_LR(r10, area); \ 119b01c8b54SPaul Mackerras mfcr r9; \ 120b01c8b54SPaul Mackerras extra(vec); \ 121b01c8b54SPaul Mackerras std r11,area+EX_R11(r13); \ 122b01c8b54SPaul Mackerras std r12,area+EX_R12(r13); \ 123b01c8b54SPaul Mackerras GET_SCRATCH0(r10); \ 124b01c8b54SPaul Mackerras std r10,area+EX_R13(r13) 125b01c8b54SPaul Mackerras #define EXCEPTION_PROLOG_1(area, extra, vec) \ 126b01c8b54SPaul Mackerras __EXCEPTION_PROLOG_1(area, extra, vec) 1278aa34ab8SBenjamin Herrenschmidt 128a5d4f3adSBenjamin Herrenschmidt #define __EXCEPTION_PROLOG_PSERIES_1(label, h) \ 1298aa34ab8SBenjamin Herrenschmidt ld r12,PACAKBASE(r13); /* get high part of &label */ \ 1308aa34ab8SBenjamin Herrenschmidt ld r10,PACAKMSR(r13); /* get MSR value for kernel */ \ 131a5d4f3adSBenjamin Herrenschmidt mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 1328aa34ab8SBenjamin Herrenschmidt LOAD_HANDLER(r12,label) \ 133a5d4f3adSBenjamin Herrenschmidt mtspr SPRN_##h##SRR0,r12; \ 134a5d4f3adSBenjamin Herrenschmidt mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 135a5d4f3adSBenjamin Herrenschmidt mtspr SPRN_##h##SRR1,r10; \ 136a5d4f3adSBenjamin Herrenschmidt h##rfid; \ 1378aa34ab8SBenjamin Herrenschmidt b . /* prevent speculative execution */ 138a5d4f3adSBenjamin Herrenschmidt #define EXCEPTION_PROLOG_PSERIES_1(label, h) \ 139a5d4f3adSBenjamin Herrenschmidt __EXCEPTION_PROLOG_PSERIES_1(label, h) 1408aa34ab8SBenjamin Herrenschmidt 141b01c8b54SPaul Mackerras #define EXCEPTION_PROLOG_PSERIES(area, label, h, extra, vec) \ 142b01c8b54SPaul Mackerras EXCEPTION_PROLOG_1(area, extra, vec); \ 143a5d4f3adSBenjamin Herrenschmidt EXCEPTION_PROLOG_PSERIES_1(label, h); 144c5a8c0c9SBenjamin Herrenschmidt 145b01c8b54SPaul Mackerras #define __KVMTEST(n) \ 1463c42bf8aSPaul Mackerras lbz r10,HSTATE_IN_GUEST(r13); \ 147b01c8b54SPaul Mackerras cmpwi r10,0; \ 148b01c8b54SPaul Mackerras bne do_kvm_##n 149b01c8b54SPaul Mackerras 150b01c8b54SPaul Mackerras #define __KVM_HANDLER(area, h, n) \ 151b01c8b54SPaul Mackerras do_kvm_##n: \ 152b01c8b54SPaul Mackerras ld r10,area+EX_R10(r13); \ 1533c42bf8aSPaul Mackerras stw r9,HSTATE_SCRATCH1(r13); \ 154b01c8b54SPaul Mackerras ld r9,area+EX_R9(r13); \ 1553c42bf8aSPaul Mackerras std r12,HSTATE_SCRATCH0(r13); \ 156b01c8b54SPaul Mackerras li r12,n; \ 157b01c8b54SPaul Mackerras b kvmppc_interrupt 158b01c8b54SPaul Mackerras 159b01c8b54SPaul Mackerras #define __KVM_HANDLER_SKIP(area, h, n) \ 160b01c8b54SPaul Mackerras do_kvm_##n: \ 161b01c8b54SPaul Mackerras cmpwi r10,KVM_GUEST_MODE_SKIP; \ 162b01c8b54SPaul Mackerras ld r10,area+EX_R10(r13); \ 163b01c8b54SPaul Mackerras beq 89f; \ 1643c42bf8aSPaul Mackerras stw r9,HSTATE_SCRATCH1(r13); \ 165b01c8b54SPaul Mackerras ld r9,area+EX_R9(r13); \ 1663c42bf8aSPaul Mackerras std r12,HSTATE_SCRATCH0(r13); \ 167b01c8b54SPaul Mackerras li r12,n; \ 168b01c8b54SPaul Mackerras b kvmppc_interrupt; \ 169b01c8b54SPaul Mackerras 89: mtocrf 0x80,r9; \ 170b01c8b54SPaul Mackerras ld r9,area+EX_R9(r13); \ 171b01c8b54SPaul Mackerras b kvmppc_skip_##h##interrupt 172b01c8b54SPaul Mackerras 173b01c8b54SPaul Mackerras #ifdef CONFIG_KVM_BOOK3S_64_HANDLER 174b01c8b54SPaul Mackerras #define KVMTEST(n) __KVMTEST(n) 175b01c8b54SPaul Mackerras #define KVM_HANDLER(area, h, n) __KVM_HANDLER(area, h, n) 176b01c8b54SPaul Mackerras #define KVM_HANDLER_SKIP(area, h, n) __KVM_HANDLER_SKIP(area, h, n) 177b01c8b54SPaul Mackerras 178b01c8b54SPaul Mackerras #else 179b01c8b54SPaul Mackerras #define KVMTEST(n) 180b01c8b54SPaul Mackerras #define KVM_HANDLER(area, h, n) 181b01c8b54SPaul Mackerras #define KVM_HANDLER_SKIP(area, h, n) 182b01c8b54SPaul Mackerras #endif 183b01c8b54SPaul Mackerras 184de56a948SPaul Mackerras #ifdef CONFIG_KVM_BOOK3S_PR 185de56a948SPaul Mackerras #define KVMTEST_PR(n) __KVMTEST(n) 186de56a948SPaul Mackerras #define KVM_HANDLER_PR(area, h, n) __KVM_HANDLER(area, h, n) 187de56a948SPaul Mackerras #define KVM_HANDLER_PR_SKIP(area, h, n) __KVM_HANDLER_SKIP(area, h, n) 188de56a948SPaul Mackerras 189de56a948SPaul Mackerras #else 190de56a948SPaul Mackerras #define KVMTEST_PR(n) 191de56a948SPaul Mackerras #define KVM_HANDLER_PR(area, h, n) 192de56a948SPaul Mackerras #define KVM_HANDLER_PR_SKIP(area, h, n) 193de56a948SPaul Mackerras #endif 194de56a948SPaul Mackerras 195b01c8b54SPaul Mackerras #define NOTEST(n) 196b01c8b54SPaul Mackerras 1978aa34ab8SBenjamin Herrenschmidt /* 1988aa34ab8SBenjamin Herrenschmidt * The common exception prolog is used for all except a few exceptions 1998aa34ab8SBenjamin Herrenschmidt * such as a segment miss on a kernel address. We have to be prepared 2008aa34ab8SBenjamin Herrenschmidt * to take another exception from the point where we first touch the 2018aa34ab8SBenjamin Herrenschmidt * kernel stack onwards. 2028aa34ab8SBenjamin Herrenschmidt * 2038aa34ab8SBenjamin Herrenschmidt * On entry r13 points to the paca, r9-r13 are saved in the paca, 2048aa34ab8SBenjamin Herrenschmidt * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and 2058aa34ab8SBenjamin Herrenschmidt * SRR1, and relocation is on. 2068aa34ab8SBenjamin Herrenschmidt */ 2078aa34ab8SBenjamin Herrenschmidt #define EXCEPTION_PROLOG_COMMON(n, area) \ 2088aa34ab8SBenjamin Herrenschmidt andi. r10,r12,MSR_PR; /* See if coming from user */ \ 2098aa34ab8SBenjamin Herrenschmidt mr r10,r1; /* Save r1 */ \ 2108aa34ab8SBenjamin Herrenschmidt subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \ 2118aa34ab8SBenjamin Herrenschmidt beq- 1f; \ 2128aa34ab8SBenjamin Herrenschmidt ld r1,PACAKSAVE(r13); /* kernel stack to use */ \ 2138aa34ab8SBenjamin Herrenschmidt 1: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \ 2141977b502SPaul Mackerras blt+ cr1,3f; /* abort if it is */ \ 2151977b502SPaul Mackerras li r1,(n); /* will be reloaded later */ \ 2168aa34ab8SBenjamin Herrenschmidt sth r1,PACA_TRAP_SAVE(r13); \ 2171977b502SPaul Mackerras std r3,area+EX_R3(r13); \ 2181977b502SPaul Mackerras addi r3,r13,area; /* r3 -> where regs are saved*/ \ 219c1fb6816SMichael Neuling RESTORE_LR(r1, area); \ 2208aa34ab8SBenjamin Herrenschmidt b bad_stack; \ 2218aa34ab8SBenjamin Herrenschmidt 3: std r9,_CCR(r1); /* save CR in stackframe */ \ 2228aa34ab8SBenjamin Herrenschmidt std r11,_NIP(r1); /* save SRR0 in stackframe */ \ 2238aa34ab8SBenjamin Herrenschmidt std r12,_MSR(r1); /* save SRR1 in stackframe */ \ 2248aa34ab8SBenjamin Herrenschmidt std r10,0(r1); /* make stack chain pointer */ \ 2258aa34ab8SBenjamin Herrenschmidt std r0,GPR0(r1); /* save r0 in stackframe */ \ 2268aa34ab8SBenjamin Herrenschmidt std r10,GPR1(r1); /* save r1 in stackframe */ \ 2278aa34ab8SBenjamin Herrenschmidt ACCOUNT_CPU_USER_ENTRY(r9, r10); \ 2288aa34ab8SBenjamin Herrenschmidt std r2,GPR2(r1); /* save r2 in stackframe */ \ 2298aa34ab8SBenjamin Herrenschmidt SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \ 2308aa34ab8SBenjamin Herrenschmidt SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \ 2318aa34ab8SBenjamin Herrenschmidt ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \ 2328aa34ab8SBenjamin Herrenschmidt ld r10,area+EX_R10(r13); \ 2338aa34ab8SBenjamin Herrenschmidt std r9,GPR9(r1); \ 2348aa34ab8SBenjamin Herrenschmidt std r10,GPR10(r1); \ 2358aa34ab8SBenjamin Herrenschmidt ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \ 2368aa34ab8SBenjamin Herrenschmidt ld r10,area+EX_R12(r13); \ 2378aa34ab8SBenjamin Herrenschmidt ld r11,area+EX_R13(r13); \ 2388aa34ab8SBenjamin Herrenschmidt std r9,GPR11(r1); \ 2398aa34ab8SBenjamin Herrenschmidt std r10,GPR12(r1); \ 2408aa34ab8SBenjamin Herrenschmidt std r11,GPR13(r1); \ 24148404f2eSPaul Mackerras BEGIN_FTR_SECTION_NESTED(66); \ 24248404f2eSPaul Mackerras ld r10,area+EX_CFAR(r13); \ 24348404f2eSPaul Mackerras std r10,ORIG_GPR3(r1); \ 24448404f2eSPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \ 245c1fb6816SMichael Neuling GET_LR(r9,area); /* Get LR, later save to stack */ \ 2468aa34ab8SBenjamin Herrenschmidt ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \ 2478aa34ab8SBenjamin Herrenschmidt std r9,_LINK(r1); \ 2488aa34ab8SBenjamin Herrenschmidt mfctr r10; /* save CTR in stackframe */ \ 2498aa34ab8SBenjamin Herrenschmidt std r10,_CTR(r1); \ 2508aa34ab8SBenjamin Herrenschmidt lbz r10,PACASOFTIRQEN(r13); \ 2518aa34ab8SBenjamin Herrenschmidt mfspr r11,SPRN_XER; /* save XER in stackframe */ \ 2528aa34ab8SBenjamin Herrenschmidt std r10,SOFTE(r1); \ 2538aa34ab8SBenjamin Herrenschmidt std r11,_XER(r1); \ 2548aa34ab8SBenjamin Herrenschmidt li r9,(n)+1; \ 2558aa34ab8SBenjamin Herrenschmidt std r9,_TRAP(r1); /* set trap number */ \ 2568aa34ab8SBenjamin Herrenschmidt li r10,0; \ 2578aa34ab8SBenjamin Herrenschmidt ld r11,exception_marker@toc(r2); \ 2588aa34ab8SBenjamin Herrenschmidt std r10,RESULT(r1); /* clear regs->result */ \ 259cf9efce0SPaul Mackerras std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */ \ 260cf9efce0SPaul Mackerras ACCOUNT_STOLEN_TIME 2618aa34ab8SBenjamin Herrenschmidt 2628aa34ab8SBenjamin Herrenschmidt /* 2638aa34ab8SBenjamin Herrenschmidt * Exception vectors. 2648aa34ab8SBenjamin Herrenschmidt */ 265b3e6b5dfSBenjamin Herrenschmidt #define STD_EXCEPTION_PSERIES(loc, vec, label) \ 266b3e6b5dfSBenjamin Herrenschmidt . = loc; \ 2678aa34ab8SBenjamin Herrenschmidt .globl label##_pSeries; \ 2688aa34ab8SBenjamin Herrenschmidt label##_pSeries: \ 2698aa34ab8SBenjamin Herrenschmidt HMT_MEDIUM; \ 270673b189aSPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 271b01c8b54SPaul Mackerras EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common, \ 272de56a948SPaul Mackerras EXC_STD, KVMTEST_PR, vec) 2738aa34ab8SBenjamin Herrenschmidt 274b3e6b5dfSBenjamin Herrenschmidt #define STD_EXCEPTION_HV(loc, vec, label) \ 275b3e6b5dfSBenjamin Herrenschmidt . = loc; \ 276b3e6b5dfSBenjamin Herrenschmidt .globl label##_hv; \ 277b3e6b5dfSBenjamin Herrenschmidt label##_hv: \ 2788aa34ab8SBenjamin Herrenschmidt HMT_MEDIUM; \ 279673b189aSPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 280b01c8b54SPaul Mackerras EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common, \ 281b01c8b54SPaul Mackerras EXC_HV, KVMTEST, vec) 2828aa34ab8SBenjamin Herrenschmidt 2834700dfafSMichael Neuling #define STD_RELON_EXCEPTION_PSERIES(loc, vec, label) \ 2844700dfafSMichael Neuling . = loc; \ 2854700dfafSMichael Neuling .globl label##_relon_pSeries; \ 2864700dfafSMichael Neuling label##_relon_pSeries: \ 2874700dfafSMichael Neuling HMT_MEDIUM; \ 2884700dfafSMichael Neuling /* No guest interrupts come through here */ \ 2894700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 2904700dfafSMichael Neuling EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label##_common, \ 2914700dfafSMichael Neuling EXC_STD, KVMTEST_PR, vec) 2924700dfafSMichael Neuling 2934700dfafSMichael Neuling #define STD_RELON_EXCEPTION_HV(loc, vec, label) \ 2944700dfafSMichael Neuling . = loc; \ 2954700dfafSMichael Neuling .globl label##_relon_hv; \ 2964700dfafSMichael Neuling label##_relon_hv: \ 2974700dfafSMichael Neuling HMT_MEDIUM; \ 2984700dfafSMichael Neuling /* No guest interrupts come through here */ \ 2994700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 3004700dfafSMichael Neuling EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label##_common, \ 3014700dfafSMichael Neuling EXC_HV, KVMTEST, vec) 3024700dfafSMichael Neuling 3037230c564SBenjamin Herrenschmidt /* This associate vector numbers with bits in paca->irq_happened */ 3047230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x500 PACA_IRQ_EE 3057230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x502 PACA_IRQ_EE 3067230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x900 PACA_IRQ_DEC 3077230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x982 PACA_IRQ_DEC 3081dbdafecSIan Munsie #define SOFTEN_VALUE_0xa00 PACA_IRQ_DBELL 309655bb3f4SIan Munsie #define SOFTEN_VALUE_0xe80 PACA_IRQ_DBELL 310655bb3f4SIan Munsie #define SOFTEN_VALUE_0xe82 PACA_IRQ_DBELL 3117230c564SBenjamin Herrenschmidt 3127230c564SBenjamin Herrenschmidt #define __SOFTEN_TEST(h, vec) \ 3138aa34ab8SBenjamin Herrenschmidt lbz r10,PACASOFTIRQEN(r13); \ 3148aa34ab8SBenjamin Herrenschmidt cmpwi r10,0; \ 3157230c564SBenjamin Herrenschmidt li r10,SOFTEN_VALUE_##vec; \ 316b01c8b54SPaul Mackerras beq masked_##h##interrupt 3177230c564SBenjamin Herrenschmidt #define _SOFTEN_TEST(h, vec) __SOFTEN_TEST(h, vec) 318b01c8b54SPaul Mackerras 319de56a948SPaul Mackerras #define SOFTEN_TEST_PR(vec) \ 320de56a948SPaul Mackerras KVMTEST_PR(vec); \ 3217230c564SBenjamin Herrenschmidt _SOFTEN_TEST(EXC_STD, vec) 322b01c8b54SPaul Mackerras 323b01c8b54SPaul Mackerras #define SOFTEN_TEST_HV(vec) \ 324b01c8b54SPaul Mackerras KVMTEST(vec); \ 3257230c564SBenjamin Herrenschmidt _SOFTEN_TEST(EXC_HV, vec) 326b01c8b54SPaul Mackerras 3279e368f29SPaul Mackerras #define SOFTEN_TEST_HV_201(vec) \ 3289e368f29SPaul Mackerras KVMTEST(vec); \ 3297230c564SBenjamin Herrenschmidt _SOFTEN_TEST(EXC_STD, vec) 3309e368f29SPaul Mackerras 3314700dfafSMichael Neuling #define SOFTEN_NOTEST_PR(vec) _SOFTEN_TEST(EXC_STD, vec) 3324700dfafSMichael Neuling #define SOFTEN_NOTEST_HV(vec) _SOFTEN_TEST(EXC_HV, vec) 3334700dfafSMichael Neuling 334b01c8b54SPaul Mackerras #define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \ 335b01c8b54SPaul Mackerras HMT_MEDIUM; \ 336b01c8b54SPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 337b01c8b54SPaul Mackerras __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \ 338b01c8b54SPaul Mackerras EXCEPTION_PROLOG_PSERIES_1(label##_common, h); 339b01c8b54SPaul Mackerras #define _MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \ 340b01c8b54SPaul Mackerras __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) 341b3e6b5dfSBenjamin Herrenschmidt 342b3e6b5dfSBenjamin Herrenschmidt #define MASKABLE_EXCEPTION_PSERIES(loc, vec, label) \ 343b3e6b5dfSBenjamin Herrenschmidt . = loc; \ 344b3e6b5dfSBenjamin Herrenschmidt .globl label##_pSeries; \ 345b3e6b5dfSBenjamin Herrenschmidt label##_pSeries: \ 346b01c8b54SPaul Mackerras _MASKABLE_EXCEPTION_PSERIES(vec, label, \ 347de56a948SPaul Mackerras EXC_STD, SOFTEN_TEST_PR) 348b3e6b5dfSBenjamin Herrenschmidt 349b3e6b5dfSBenjamin Herrenschmidt #define MASKABLE_EXCEPTION_HV(loc, vec, label) \ 350b3e6b5dfSBenjamin Herrenschmidt . = loc; \ 351b3e6b5dfSBenjamin Herrenschmidt .globl label##_hv; \ 352b3e6b5dfSBenjamin Herrenschmidt label##_hv: \ 353b01c8b54SPaul Mackerras _MASKABLE_EXCEPTION_PSERIES(vec, label, \ 354b01c8b54SPaul Mackerras EXC_HV, SOFTEN_TEST_HV) 3558aa34ab8SBenjamin Herrenschmidt 3564700dfafSMichael Neuling #define __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \ 3574700dfafSMichael Neuling HMT_MEDIUM; \ 3584700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 3594700dfafSMichael Neuling __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \ 3604700dfafSMichael Neuling EXCEPTION_RELON_PROLOG_PSERIES_1(label##_common, h); 3614700dfafSMichael Neuling #define _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \ 3624700dfafSMichael Neuling __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) 3634700dfafSMichael Neuling 3644700dfafSMichael Neuling #define MASKABLE_RELON_EXCEPTION_PSERIES(loc, vec, label) \ 3654700dfafSMichael Neuling . = loc; \ 3664700dfafSMichael Neuling .globl label##_relon_pSeries; \ 3674700dfafSMichael Neuling label##_relon_pSeries: \ 3684700dfafSMichael Neuling _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \ 3694700dfafSMichael Neuling EXC_STD, SOFTEN_NOTEST_PR) 3704700dfafSMichael Neuling 3714700dfafSMichael Neuling #define MASKABLE_RELON_EXCEPTION_HV(loc, vec, label) \ 3724700dfafSMichael Neuling . = loc; \ 3734700dfafSMichael Neuling .globl label##_relon_hv; \ 3744700dfafSMichael Neuling label##_relon_hv: \ 3754700dfafSMichael Neuling _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \ 3764700dfafSMichael Neuling EXC_HV, SOFTEN_NOTEST_HV) 3774700dfafSMichael Neuling 3781b701179SBenjamin Herrenschmidt /* 3791b701179SBenjamin Herrenschmidt * Our exception common code can be passed various "additions" 3801b701179SBenjamin Herrenschmidt * to specify the behaviour of interrupts, whether to kick the 3811b701179SBenjamin Herrenschmidt * runlatch, etc... 3821b701179SBenjamin Herrenschmidt */ 3831b701179SBenjamin Herrenschmidt 3841b701179SBenjamin Herrenschmidt /* Exception addition: Hard disable interrupts */ 3857230c564SBenjamin Herrenschmidt #define DISABLE_INTS SOFT_DISABLE_INTS(r10,r11) 3868aa34ab8SBenjamin Herrenschmidt 387fe1952fcSBenjamin Herrenschmidt #define ADD_NVGPRS \ 388fe1952fcSBenjamin Herrenschmidt bl .save_nvgprs 389fe1952fcSBenjamin Herrenschmidt 390fe1952fcSBenjamin Herrenschmidt #define RUNLATCH_ON \ 391fe1952fcSBenjamin Herrenschmidt BEGIN_FTR_SECTION \ 3929778b696SStuart Yoder CURRENT_THREAD_INFO(r3, r1); \ 393fe1952fcSBenjamin Herrenschmidt ld r4,TI_LOCAL_FLAGS(r3); \ 394fe1952fcSBenjamin Herrenschmidt andi. r0,r4,_TLF_RUNLATCH; \ 395fe1952fcSBenjamin Herrenschmidt beql ppc64_runlatch_on_trampoline; \ 396fe1952fcSBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CTRL) 397fe1952fcSBenjamin Herrenschmidt 398fe1952fcSBenjamin Herrenschmidt #define EXCEPTION_COMMON(trap, label, hdlr, ret, additions) \ 3998aa34ab8SBenjamin Herrenschmidt .align 7; \ 4008aa34ab8SBenjamin Herrenschmidt .globl label##_common; \ 4018aa34ab8SBenjamin Herrenschmidt label##_common: \ 4028aa34ab8SBenjamin Herrenschmidt EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \ 403fe1952fcSBenjamin Herrenschmidt additions; \ 4048aa34ab8SBenjamin Herrenschmidt addi r3,r1,STACK_FRAME_OVERHEAD; \ 4058aa34ab8SBenjamin Herrenschmidt bl hdlr; \ 406fe1952fcSBenjamin Herrenschmidt b ret 407fe1952fcSBenjamin Herrenschmidt 408fe1952fcSBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON(trap, label, hdlr) \ 409fe1952fcSBenjamin Herrenschmidt EXCEPTION_COMMON(trap, label, hdlr, ret_from_except, \ 410fe1952fcSBenjamin Herrenschmidt ADD_NVGPRS;DISABLE_INTS) 4118aa34ab8SBenjamin Herrenschmidt 4128aa34ab8SBenjamin Herrenschmidt /* 4138aa34ab8SBenjamin Herrenschmidt * Like STD_EXCEPTION_COMMON, but for exceptions that can occur 4147450f6f0SBenjamin Herrenschmidt * in the idle task and therefore need the special idle handling 4157450f6f0SBenjamin Herrenschmidt * (finish nap and runlatch) 4168aa34ab8SBenjamin Herrenschmidt */ 4177450f6f0SBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON_ASYNC(trap, label, hdlr) \ 418fe1952fcSBenjamin Herrenschmidt EXCEPTION_COMMON(trap, label, hdlr, ret_from_except_lite, \ 419fe1952fcSBenjamin Herrenschmidt FINISH_NAP;RUNLATCH_ON;DISABLE_INTS) 4208aa34ab8SBenjamin Herrenschmidt 4218aa34ab8SBenjamin Herrenschmidt /* 4228aa34ab8SBenjamin Herrenschmidt * When the idle code in power4_idle puts the CPU into NAP mode, 4238aa34ab8SBenjamin Herrenschmidt * it has to do so in a loop, and relies on the external interrupt 4248aa34ab8SBenjamin Herrenschmidt * and decrementer interrupt entry code to get it out of the loop. 4258aa34ab8SBenjamin Herrenschmidt * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags 4268aa34ab8SBenjamin Herrenschmidt * to signal that it is in the loop and needs help to get out. 4278aa34ab8SBenjamin Herrenschmidt */ 4288aa34ab8SBenjamin Herrenschmidt #ifdef CONFIG_PPC_970_NAP 4298aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP \ 4308aa34ab8SBenjamin Herrenschmidt BEGIN_FTR_SECTION \ 4319778b696SStuart Yoder CURRENT_THREAD_INFO(r11, r1); \ 4328aa34ab8SBenjamin Herrenschmidt ld r9,TI_LOCAL_FLAGS(r11); \ 4338aa34ab8SBenjamin Herrenschmidt andi. r10,r9,_TLF_NAPPING; \ 4348aa34ab8SBenjamin Herrenschmidt bnel power4_fixup_nap; \ 4358aa34ab8SBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP) 4368aa34ab8SBenjamin Herrenschmidt #else 4378aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP 4388aa34ab8SBenjamin Herrenschmidt #endif 4398aa34ab8SBenjamin Herrenschmidt 4408aa34ab8SBenjamin Herrenschmidt #endif /* _ASM_POWERPC_EXCEPTION_H */ 441