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 */ 37da2bc464SMichael Ellerman #include <asm/head-64.h> 382c86cd18SChristophe Leroy #include <asm/feature-fixups.h> 398aa34ab8SBenjamin Herrenschmidt 408c388514SNicholas Piggin /* PACA save area offsets (exgen, exmc, etc) */ 418aa34ab8SBenjamin Herrenschmidt #define EX_R9 0 428aa34ab8SBenjamin Herrenschmidt #define EX_R10 8 438aa34ab8SBenjamin Herrenschmidt #define EX_R11 16 448aa34ab8SBenjamin Herrenschmidt #define EX_R12 24 458aa34ab8SBenjamin Herrenschmidt #define EX_R13 32 4636670fcfSNicholas Piggin #define EX_DAR 40 4736670fcfSNicholas Piggin #define EX_DSISR 48 4836670fcfSNicholas Piggin #define EX_CCR 52 49635942aeSNicholas Piggin #define EX_CFAR 56 50635942aeSNicholas Piggin #define EX_PPR 64 518568f1e0SNicholas Piggin #if defined(CONFIG_RELOCATABLE) 52635942aeSNicholas Piggin #define EX_CTR 72 53635942aeSNicholas Piggin #define EX_SIZE 10 /* size in u64 units */ 548568f1e0SNicholas Piggin #else 558568f1e0SNicholas Piggin #define EX_SIZE 9 /* size in u64 units */ 568568f1e0SNicholas Piggin #endif 57dbeea1d6SNicholas Piggin 58dbeea1d6SNicholas Piggin /* 59ba41e1e1SBalbir Singh * maximum recursive depth of MCE exceptions 60ba41e1e1SBalbir Singh */ 61ba41e1e1SBalbir Singh #define MAX_MCE_DEPTH 4 62ba41e1e1SBalbir Singh 63ba41e1e1SBalbir Singh /* 64635942aeSNicholas Piggin * EX_R3 is only used by the bad_stack handler. bad_stack reloads and 65635942aeSNicholas Piggin * saves DAR from SPRN_DAR, and EX_DAR is not used. So EX_R3 can overlap 66635942aeSNicholas Piggin * with EX_DAR. 67635942aeSNicholas Piggin */ 68635942aeSNicholas Piggin #define EX_R3 EX_DAR 69635942aeSNicholas Piggin 70*4508a74aSNicholas Piggin #ifdef __ASSEMBLY__ 71*4508a74aSNicholas Piggin 72a048a07dSNicholas Piggin #define STF_ENTRY_BARRIER_SLOT \ 73a048a07dSNicholas Piggin STF_ENTRY_BARRIER_FIXUP_SECTION; \ 74a048a07dSNicholas Piggin nop; \ 75a048a07dSNicholas Piggin nop; \ 76a048a07dSNicholas Piggin nop 77a048a07dSNicholas Piggin 78a048a07dSNicholas Piggin #define STF_EXIT_BARRIER_SLOT \ 79a048a07dSNicholas Piggin STF_EXIT_BARRIER_FIXUP_SECTION; \ 80a048a07dSNicholas Piggin nop; \ 81a048a07dSNicholas Piggin nop; \ 82a048a07dSNicholas Piggin nop; \ 83a048a07dSNicholas Piggin nop; \ 84a048a07dSNicholas Piggin nop; \ 85a048a07dSNicholas Piggin nop 86a048a07dSNicholas Piggin 87a048a07dSNicholas Piggin /* 88a048a07dSNicholas Piggin * r10 must be free to use, r13 must be paca 89a048a07dSNicholas Piggin */ 90a048a07dSNicholas Piggin #define INTERRUPT_TO_KERNEL \ 91a048a07dSNicholas Piggin STF_ENTRY_BARRIER_SLOT 92a048a07dSNicholas Piggin 93aa8a5e00SMichael Ellerman /* 94aa8a5e00SMichael Ellerman * Macros for annotating the expected destination of (h)rfid 95aa8a5e00SMichael Ellerman * 96aa8a5e00SMichael Ellerman * The nop instructions allow us to insert one or more instructions to flush the 97aa8a5e00SMichael Ellerman * L1-D cache when returning to userspace or a guest. 98aa8a5e00SMichael Ellerman */ 99aa8a5e00SMichael Ellerman #define RFI_FLUSH_SLOT \ 100aa8a5e00SMichael Ellerman RFI_FLUSH_FIXUP_SECTION; \ 101aa8a5e00SMichael Ellerman nop; \ 102aa8a5e00SMichael Ellerman nop; \ 103aa8a5e00SMichael Ellerman nop 10450e51c13SNicholas Piggin 10550e51c13SNicholas Piggin #define RFI_TO_KERNEL \ 10650e51c13SNicholas Piggin rfid 10750e51c13SNicholas Piggin 10850e51c13SNicholas Piggin #define RFI_TO_USER \ 109a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 110aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 111aa8a5e00SMichael Ellerman rfid; \ 112aa8a5e00SMichael Ellerman b rfi_flush_fallback 11350e51c13SNicholas Piggin 11450e51c13SNicholas Piggin #define RFI_TO_USER_OR_KERNEL \ 115a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 116aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 117aa8a5e00SMichael Ellerman rfid; \ 118aa8a5e00SMichael Ellerman b rfi_flush_fallback 11950e51c13SNicholas Piggin 12050e51c13SNicholas Piggin #define RFI_TO_GUEST \ 121a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 122aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 123aa8a5e00SMichael Ellerman rfid; \ 124aa8a5e00SMichael Ellerman b rfi_flush_fallback 12550e51c13SNicholas Piggin 12650e51c13SNicholas Piggin #define HRFI_TO_KERNEL \ 12750e51c13SNicholas Piggin hrfid 12850e51c13SNicholas Piggin 12950e51c13SNicholas Piggin #define HRFI_TO_USER \ 130a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 131aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 132aa8a5e00SMichael Ellerman hrfid; \ 133aa8a5e00SMichael Ellerman b hrfi_flush_fallback 13450e51c13SNicholas Piggin 13550e51c13SNicholas Piggin #define HRFI_TO_USER_OR_KERNEL \ 136a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 137aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 138aa8a5e00SMichael Ellerman hrfid; \ 139aa8a5e00SMichael Ellerman b hrfi_flush_fallback 14050e51c13SNicholas Piggin 14150e51c13SNicholas Piggin #define HRFI_TO_GUEST \ 142a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 143aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 144aa8a5e00SMichael Ellerman hrfid; \ 145aa8a5e00SMichael Ellerman b hrfi_flush_fallback 14650e51c13SNicholas Piggin 14750e51c13SNicholas Piggin #define HRFI_TO_UNKNOWN \ 148a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 149aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 150aa8a5e00SMichael Ellerman hrfid; \ 151aa8a5e00SMichael Ellerman b hrfi_flush_fallback 15250e51c13SNicholas Piggin 1538aa34ab8SBenjamin Herrenschmidt /* 1548aa34ab8SBenjamin Herrenschmidt * We're short on space and time in the exception prolog, so we can't 15527510235SMichael Ellerman * use the normal LOAD_REG_IMMEDIATE macro to load the address of label. 15627510235SMichael Ellerman * Instead we get the base of the kernel from paca->kernelbase and or in the low 15727510235SMichael Ellerman * part of label. This requires that the label be within 64KB of kernelbase, and 15827510235SMichael Ellerman * that kernelbase be 64K aligned. 1598aa34ab8SBenjamin Herrenschmidt */ 1608aa34ab8SBenjamin Herrenschmidt #define LOAD_HANDLER(reg, label) \ 161d8d42b05SMichael Ellerman ld reg,PACAKBASE(r13); /* get high part of &label */ \ 1624b1f5cccSNicholas Piggin ori reg,reg,FIXED_SYMBOL_ABS_ADDR(label) 1638aa34ab8SBenjamin Herrenschmidt 164fb479e44SNicholas Piggin #define __LOAD_HANDLER(reg, label) \ 165fb479e44SNicholas Piggin ld reg,PACAKBASE(r13); \ 1664b1f5cccSNicholas Piggin ori reg,reg,(ABS_ADDR(label))@l 167fb479e44SNicholas Piggin 168a97a65d5SNicholas Piggin /* 169a97a65d5SNicholas Piggin * Branches from unrelocated code (e.g., interrupts) to labels outside 170a97a65d5SNicholas Piggin * head-y require >64K offsets. 171a97a65d5SNicholas Piggin */ 172a97a65d5SNicholas Piggin #define __LOAD_FAR_HANDLER(reg, label) \ 173a97a65d5SNicholas Piggin ld reg,PACAKBASE(r13); \ 174a97a65d5SNicholas Piggin ori reg,reg,(ABS_ADDR(label))@l; \ 1754b1f5cccSNicholas Piggin addis reg,reg,(ABS_ADDR(label))@h 176a97a65d5SNicholas Piggin 177*4508a74aSNicholas Piggin #ifdef CONFIG_RELOCATABLE 178*4508a74aSNicholas Piggin .macro EXCEPTION_PROLOG_2_RELON label, hsrr 179*4508a74aSNicholas Piggin .if \hsrr 180*4508a74aSNicholas Piggin mfspr r11,SPRN_HSRR0 /* save HSRR0 */ 181*4508a74aSNicholas Piggin .else 182*4508a74aSNicholas Piggin mfspr r11,SPRN_SRR0 /* save SRR0 */ 183*4508a74aSNicholas Piggin .endif 184*4508a74aSNicholas Piggin LOAD_HANDLER(r12, \label\()) 185*4508a74aSNicholas Piggin mtctr r12 186*4508a74aSNicholas Piggin .if \hsrr 187*4508a74aSNicholas Piggin mfspr r12,SPRN_HSRR1 /* and HSRR1 */ 188*4508a74aSNicholas Piggin .else 189*4508a74aSNicholas Piggin mfspr r12,SPRN_SRR1 /* and HSRR1 */ 190*4508a74aSNicholas Piggin .endif 191*4508a74aSNicholas Piggin li r10,MSR_RI 192*4508a74aSNicholas Piggin mtmsrd r10,1 /* Set RI (EE=0) */ 193*4508a74aSNicholas Piggin bctr 194*4508a74aSNicholas Piggin .endm 195*4508a74aSNicholas Piggin #else 196*4508a74aSNicholas Piggin /* If not relocatable, we can jump directly -- and save messing with LR */ 197*4508a74aSNicholas Piggin .macro EXCEPTION_PROLOG_2_RELON label, hsrr 198*4508a74aSNicholas Piggin .if \hsrr 199*4508a74aSNicholas Piggin mfspr r11,SPRN_HSRR0 /* save HSRR0 */ 200*4508a74aSNicholas Piggin mfspr r12,SPRN_HSRR1 /* and HSRR1 */ 201*4508a74aSNicholas Piggin .else 202*4508a74aSNicholas Piggin mfspr r11,SPRN_SRR0 /* save SRR0 */ 203*4508a74aSNicholas Piggin mfspr r12,SPRN_SRR1 /* and SRR1 */ 204*4508a74aSNicholas Piggin .endif 205*4508a74aSNicholas Piggin li r10,MSR_RI 206*4508a74aSNicholas Piggin mtmsrd r10,1 /* Set RI (EE=0) */ 207*4508a74aSNicholas Piggin b \label 208*4508a74aSNicholas Piggin .endm 209*4508a74aSNicholas Piggin #endif 210*4508a74aSNicholas Piggin 211*4508a74aSNicholas Piggin /* 212*4508a74aSNicholas Piggin * As EXCEPTION_PROLOG(), except we've already got relocation on so no need to 213*4508a74aSNicholas Piggin * rfid. Save LR in case we're CONFIG_RELOCATABLE, in which case 214*4508a74aSNicholas Piggin * EXCEPTION_PROLOG_2_RELON will be using LR. 215*4508a74aSNicholas Piggin */ 216*4508a74aSNicholas Piggin #define EXCEPTION_RELON_PROLOG(area, label, hsrr, extra, vec) \ 217*4508a74aSNicholas Piggin SET_SCRATCH0(r13); /* save r13 */ \ 218*4508a74aSNicholas Piggin EXCEPTION_PROLOG_0(area); \ 219*4508a74aSNicholas Piggin EXCEPTION_PROLOG_1(area, extra, vec); \ 220*4508a74aSNicholas Piggin EXCEPTION_PROLOG_2_RELON label, hsrr 221*4508a74aSNicholas Piggin 222a5d4f3adSBenjamin Herrenschmidt /* Exception register prefixes */ 223*4508a74aSNicholas Piggin #define EXC_HV 1 224*4508a74aSNicholas Piggin #define EXC_STD 0 225a5d4f3adSBenjamin Herrenschmidt 2264700dfafSMichael Neuling #if defined(CONFIG_RELOCATABLE) 2274700dfafSMichael Neuling /* 228bc2e6c6aSMichael Neuling * If we support interrupts with relocation on AND we're a relocatable kernel, 229bc2e6c6aSMichael Neuling * we need to use CTR to get to the 2nd level handler. So, save/restore it 230bc2e6c6aSMichael Neuling * when required. 2314700dfafSMichael Neuling */ 232bc2e6c6aSMichael Neuling #define SAVE_CTR(reg, area) mfctr reg ; std reg,area+EX_CTR(r13) 233bc2e6c6aSMichael Neuling #define GET_CTR(reg, area) ld reg,area+EX_CTR(r13) 234bc2e6c6aSMichael Neuling #define RESTORE_CTR(reg, area) ld reg,area+EX_CTR(r13) ; mtctr reg 2354700dfafSMichael Neuling #else 236bc2e6c6aSMichael Neuling /* ...else CTR is unused and in register. */ 237bc2e6c6aSMichael Neuling #define SAVE_CTR(reg, area) 238bc2e6c6aSMichael Neuling #define GET_CTR(reg, area) mfctr reg 239bc2e6c6aSMichael Neuling #define RESTORE_CTR(reg, area) 2404700dfafSMichael Neuling #endif 2414700dfafSMichael Neuling 24213e7a8e8SHaren Myneni /* 24313e7a8e8SHaren Myneni * PPR save/restore macros used in exceptions_64s.S 24413e7a8e8SHaren Myneni * Used for P7 or later processors 24513e7a8e8SHaren Myneni */ 2464c2de74cSNicholas Piggin #define SAVE_PPR(area, ra) \ 24713e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(940) \ 2484c2de74cSNicholas Piggin ld ra,area+EX_PPR(r13); /* Read PPR from paca */ \ 2494c2de74cSNicholas Piggin std ra,_PPR(r1); \ 25013e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940) 25113e7a8e8SHaren Myneni 25213e7a8e8SHaren Myneni #define RESTORE_PPR_PACA(area, ra) \ 25313e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(941) \ 25413e7a8e8SHaren Myneni ld ra,area+EX_PPR(r13); \ 25513e7a8e8SHaren Myneni mtspr SPRN_PPR,ra; \ 25613e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,941) 25713e7a8e8SHaren Myneni 25813e7a8e8SHaren Myneni /* 2591707dd16SPaul Mackerras * Get an SPR into a register if the CPU has the given feature 26013e7a8e8SHaren Myneni */ 2611707dd16SPaul Mackerras #define OPT_GET_SPR(ra, spr, ftr) \ 26213e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(943) \ 2631707dd16SPaul Mackerras mfspr ra,spr; \ 2641707dd16SPaul Mackerras END_FTR_SECTION_NESTED(ftr,ftr,943) 26513e7a8e8SHaren Myneni 2661707dd16SPaul Mackerras /* 267d410ae21SMahesh Salgaonkar * Set an SPR from a register if the CPU has the given feature 268d410ae21SMahesh Salgaonkar */ 269d410ae21SMahesh Salgaonkar #define OPT_SET_SPR(ra, spr, ftr) \ 270d410ae21SMahesh Salgaonkar BEGIN_FTR_SECTION_NESTED(943) \ 271d410ae21SMahesh Salgaonkar mtspr spr,ra; \ 272d410ae21SMahesh Salgaonkar END_FTR_SECTION_NESTED(ftr,ftr,943) 273d410ae21SMahesh Salgaonkar 274d410ae21SMahesh Salgaonkar /* 2751707dd16SPaul Mackerras * Save a register to the PACA if the CPU has the given feature 2761707dd16SPaul Mackerras */ 2771707dd16SPaul Mackerras #define OPT_SAVE_REG_TO_PACA(offset, ra, ftr) \ 2781707dd16SPaul Mackerras BEGIN_FTR_SECTION_NESTED(943) \ 2791707dd16SPaul Mackerras std ra,offset(r13); \ 2801707dd16SPaul Mackerras END_FTR_SECTION_NESTED(ftr,ftr,943) 2811707dd16SPaul Mackerras 282544686caSNicholas Piggin #define EXCEPTION_PROLOG_0(area) \ 283544686caSNicholas Piggin GET_PACA(r13); \ 28444e9309fSHaren Myneni std r9,area+EX_R9(r13); /* save r9 */ \ 2851707dd16SPaul Mackerras OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR); \ 2861707dd16SPaul Mackerras HMT_MEDIUM; \ 28744e9309fSHaren Myneni std r10,area+EX_R10(r13); /* save r10 - r12 */ \ 2881707dd16SPaul Mackerras OPT_GET_SPR(r10, SPRN_CFAR, CPU_FTR_CFAR) 2891707dd16SPaul Mackerras 290f14e953bSMadhavan Srinivasan #define __EXCEPTION_PROLOG_1_PRE(area) \ 2911707dd16SPaul Mackerras OPT_SAVE_REG_TO_PACA(area+EX_PPR, r9, CPU_FTR_HAS_PPR); \ 2921707dd16SPaul Mackerras OPT_SAVE_REG_TO_PACA(area+EX_CFAR, r10, CPU_FTR_CFAR); \ 293a048a07dSNicholas Piggin INTERRUPT_TO_KERNEL; \ 294bc2e6c6aSMichael Neuling SAVE_CTR(r10, area); \ 2954b1f5cccSNicholas Piggin mfcr r9 296f14e953bSMadhavan Srinivasan 297f14e953bSMadhavan Srinivasan #define __EXCEPTION_PROLOG_1_POST(area) \ 298b01c8b54SPaul Mackerras std r11,area+EX_R11(r13); \ 299b01c8b54SPaul Mackerras std r12,area+EX_R12(r13); \ 300b01c8b54SPaul Mackerras GET_SCRATCH0(r10); \ 301b01c8b54SPaul Mackerras std r10,area+EX_R13(r13) 302f14e953bSMadhavan Srinivasan 303f14e953bSMadhavan Srinivasan /* 304f14e953bSMadhavan Srinivasan * This version of the EXCEPTION_PROLOG_1 will carry 305f14e953bSMadhavan Srinivasan * addition parameter called "bitmask" to support 306f14e953bSMadhavan Srinivasan * checking of the interrupt maskable level in the SOFTEN_TEST. 307f14e953bSMadhavan Srinivasan * Intended to be used in MASKABLE_EXCPETION_* macros. 308f14e953bSMadhavan Srinivasan */ 309f14e953bSMadhavan Srinivasan #define MASKABLE_EXCEPTION_PROLOG_1(area, extra, vec, bitmask) \ 310f14e953bSMadhavan Srinivasan __EXCEPTION_PROLOG_1_PRE(area); \ 311f14e953bSMadhavan Srinivasan extra(vec, bitmask); \ 3124b1f5cccSNicholas Piggin __EXCEPTION_PROLOG_1_POST(area) 313f14e953bSMadhavan Srinivasan 314f14e953bSMadhavan Srinivasan /* 315f14e953bSMadhavan Srinivasan * This version of the EXCEPTION_PROLOG_1 is intended 316f14e953bSMadhavan Srinivasan * to be used in STD_EXCEPTION* macros 317f14e953bSMadhavan Srinivasan */ 318f14e953bSMadhavan Srinivasan #define _EXCEPTION_PROLOG_1(area, extra, vec) \ 319f14e953bSMadhavan Srinivasan __EXCEPTION_PROLOG_1_PRE(area); \ 320f14e953bSMadhavan Srinivasan extra(vec); \ 3214b1f5cccSNicholas Piggin __EXCEPTION_PROLOG_1_POST(area) 322f14e953bSMadhavan Srinivasan 323b01c8b54SPaul Mackerras #define EXCEPTION_PROLOG_1(area, extra, vec) \ 324f14e953bSMadhavan Srinivasan _EXCEPTION_PROLOG_1(area, extra, vec) 3258aa34ab8SBenjamin Herrenschmidt 326*4508a74aSNicholas Piggin .macro EXCEPTION_PROLOG_2 label, hsrr 327*4508a74aSNicholas Piggin ld r10,PACAKMSR(r13) /* get MSR value for kernel */ 328*4508a74aSNicholas Piggin .if \hsrr 329*4508a74aSNicholas Piggin mfspr r11,SPRN_HSRR0 /* save HSRR0 */ 330*4508a74aSNicholas Piggin .else 331*4508a74aSNicholas Piggin mfspr r11,SPRN_SRR0 /* save SRR0 */ 332*4508a74aSNicholas Piggin .endif 333*4508a74aSNicholas Piggin LOAD_HANDLER(r12,\label\()) 334*4508a74aSNicholas Piggin .if \hsrr 335*4508a74aSNicholas Piggin mtspr SPRN_HSRR0,r12 336*4508a74aSNicholas Piggin mfspr r12,SPRN_HSRR1 /* and HSRR1 */ 337*4508a74aSNicholas Piggin mtspr SPRN_HSRR1,r10 338*4508a74aSNicholas Piggin HRFI_TO_KERNEL 339*4508a74aSNicholas Piggin .else 340*4508a74aSNicholas Piggin mtspr SPRN_SRR0,r12 341*4508a74aSNicholas Piggin mfspr r12,SPRN_SRR1 /* and SRR1 */ 342*4508a74aSNicholas Piggin mtspr SPRN_SRR1,r10 343*4508a74aSNicholas Piggin RFI_TO_KERNEL 344*4508a74aSNicholas Piggin .endif 3458aa34ab8SBenjamin Herrenschmidt b . /* prevent speculative execution */ 346*4508a74aSNicholas Piggin .endm 3478aa34ab8SBenjamin Herrenschmidt 34883a980f7SNicholas Piggin /* _NORI variant keeps MSR_RI clear */ 349*4508a74aSNicholas Piggin .macro EXCEPTION_PROLOG_2_NORI label, hsrr 350*4508a74aSNicholas Piggin ld r10,PACAKMSR(r13) /* get MSR value for kernel */ 351*4508a74aSNicholas Piggin xori r10,r10,MSR_RI /* Clear MSR_RI */ 352*4508a74aSNicholas Piggin .if \hsrr 353*4508a74aSNicholas Piggin mfspr r11,SPRN_HSRR0 /* save HSRR0 */ 354*4508a74aSNicholas Piggin .else 355*4508a74aSNicholas Piggin mfspr r11,SPRN_SRR0 /* save SRR0 */ 356*4508a74aSNicholas Piggin .endif 357*4508a74aSNicholas Piggin LOAD_HANDLER(r12,\label\()) 358*4508a74aSNicholas Piggin .if \hsrr 359*4508a74aSNicholas Piggin mtspr SPRN_HSRR0,r12 360*4508a74aSNicholas Piggin mfspr r12,SPRN_HSRR1 /* and HSRR1 */ 361*4508a74aSNicholas Piggin mtspr SPRN_HSRR1,r10 362*4508a74aSNicholas Piggin HRFI_TO_KERNEL 363*4508a74aSNicholas Piggin .else 364*4508a74aSNicholas Piggin mtspr SPRN_SRR0,r12 365*4508a74aSNicholas Piggin mfspr r12,SPRN_SRR1 /* and SRR1 */ 366*4508a74aSNicholas Piggin mtspr SPRN_SRR1,r10 367*4508a74aSNicholas Piggin RFI_TO_KERNEL 368*4508a74aSNicholas Piggin .endif 36983a980f7SNicholas Piggin b . /* prevent speculative execution */ 370*4508a74aSNicholas Piggin .endm 37183a980f7SNicholas Piggin 372bdf08e1dSMichael Ellerman #define EXCEPTION_PROLOG(area, label, h, extra, vec) \ 3734a7a0a84SMichael Ellerman SET_SCRATCH0(r13); /* save r13 */ \ 3741707dd16SPaul Mackerras EXCEPTION_PROLOG_0(area); \ 375b01c8b54SPaul Mackerras EXCEPTION_PROLOG_1(area, extra, vec); \ 376*4508a74aSNicholas Piggin EXCEPTION_PROLOG_2 label, h 377b01c8b54SPaul Mackerras 378dd96b2c2SAneesh Kumar K.V #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 379dd96b2c2SAneesh Kumar K.V /* 380dd96b2c2SAneesh Kumar K.V * If hv is possible, interrupts come into to the hv version 381dd96b2c2SAneesh Kumar K.V * of the kvmppc_interrupt code, which then jumps to the PR handler, 382dd96b2c2SAneesh Kumar K.V * kvmppc_interrupt_pr, if the guest is a PR guest. 383dd96b2c2SAneesh Kumar K.V */ 384dd96b2c2SAneesh Kumar K.V #define kvmppc_interrupt kvmppc_interrupt_hv 385dd96b2c2SAneesh Kumar K.V #else 386dd96b2c2SAneesh Kumar K.V #define kvmppc_interrupt kvmppc_interrupt_pr 387dd96b2c2SAneesh Kumar K.V #endif 388dd96b2c2SAneesh Kumar K.V 389b51351e2SNicholas Piggin /* 390b51351e2SNicholas Piggin * Branch to label using its 0xC000 address. This results in instruction 391b51351e2SNicholas Piggin * address suitable for MSR[IR]=0 or 1, which allows relocation to be turned 392b51351e2SNicholas Piggin * on using mtmsr rather than rfid. 393b51351e2SNicholas Piggin * 394b51351e2SNicholas Piggin * This could set the 0xc bits for !RELOCATABLE as an immediate, rather than 395b51351e2SNicholas Piggin * load KBASE for a slight optimisation. 396b51351e2SNicholas Piggin */ 397b51351e2SNicholas Piggin #define BRANCH_TO_C000(reg, label) \ 398b51351e2SNicholas Piggin __LOAD_HANDLER(reg, label); \ 399b51351e2SNicholas Piggin mtctr reg; \ 400b51351e2SNicholas Piggin bctr 401b51351e2SNicholas Piggin 402fb479e44SNicholas Piggin #ifdef CONFIG_RELOCATABLE 403fb479e44SNicholas Piggin #define BRANCH_TO_COMMON(reg, label) \ 404fb479e44SNicholas Piggin __LOAD_HANDLER(reg, label); \ 405fb479e44SNicholas Piggin mtctr reg; \ 406fb479e44SNicholas Piggin bctr 407fb479e44SNicholas Piggin 408be5c5e84SMichael Ellerman #define BRANCH_LINK_TO_FAR(label) \ 409be5c5e84SMichael Ellerman __LOAD_FAR_HANDLER(r12, label); \ 410be5c5e84SMichael Ellerman mtctr r12; \ 4112337d207SNicholas Piggin bctrl 4122337d207SNicholas Piggin 413a97a65d5SNicholas Piggin /* 414a97a65d5SNicholas Piggin * KVM requires __LOAD_FAR_HANDLER. 415a97a65d5SNicholas Piggin * 416a97a65d5SNicholas Piggin * __BRANCH_TO_KVM_EXIT branches are also a special case because they 417a97a65d5SNicholas Piggin * explicitly use r9 then reload it from PACA before branching. Hence 418a97a65d5SNicholas Piggin * the double-underscore. 419a97a65d5SNicholas Piggin */ 420a97a65d5SNicholas Piggin #define __BRANCH_TO_KVM_EXIT(area, label) \ 421a97a65d5SNicholas Piggin mfctr r9; \ 422a97a65d5SNicholas Piggin std r9,HSTATE_SCRATCH1(r13); \ 423a97a65d5SNicholas Piggin __LOAD_FAR_HANDLER(r9, label); \ 424a97a65d5SNicholas Piggin mtctr r9; \ 425a97a65d5SNicholas Piggin ld r9,area+EX_R9(r13); \ 426a97a65d5SNicholas Piggin bctr 427a97a65d5SNicholas Piggin 428fb479e44SNicholas Piggin #else 429fb479e44SNicholas Piggin #define BRANCH_TO_COMMON(reg, label) \ 430fb479e44SNicholas Piggin b label 431fb479e44SNicholas Piggin 432be5c5e84SMichael Ellerman #define BRANCH_LINK_TO_FAR(label) \ 4332337d207SNicholas Piggin bl label 4342337d207SNicholas Piggin 435a97a65d5SNicholas Piggin #define __BRANCH_TO_KVM_EXIT(area, label) \ 436a97a65d5SNicholas Piggin ld r9,area+EX_R9(r13); \ 437a97a65d5SNicholas Piggin b label 438a97a65d5SNicholas Piggin 439fb479e44SNicholas Piggin #endif 440fb479e44SNicholas Piggin 441c4f3b52cSNicholas Piggin /* Do not enable RI */ 44294f3cc8eSMichael Ellerman #define EXCEPTION_PROLOG_NORI(area, label, h, extra, vec) \ 443c4f3b52cSNicholas Piggin EXCEPTION_PROLOG_0(area); \ 444c4f3b52cSNicholas Piggin EXCEPTION_PROLOG_1(area, extra, vec); \ 445*4508a74aSNicholas Piggin EXCEPTION_PROLOG_2_NORI label, h 446b01c8b54SPaul Mackerras 447b01c8b54SPaul Mackerras #ifdef CONFIG_KVM_BOOK3S_64_HANDLER 448*4508a74aSNicholas Piggin .macro KVMTEST hsrr, n 449*4508a74aSNicholas Piggin lbz r10,HSTATE_IN_GUEST(r13) 450*4508a74aSNicholas Piggin cmpwi r10,0 451*4508a74aSNicholas Piggin .if \hsrr 452*4508a74aSNicholas Piggin bne do_kvm_H\n 453*4508a74aSNicholas Piggin .else 454*4508a74aSNicholas Piggin bne do_kvm_\n 455*4508a74aSNicholas Piggin .endif 456*4508a74aSNicholas Piggin .endm 457*4508a74aSNicholas Piggin 458*4508a74aSNicholas Piggin .macro KVM_HANDLER area, hsrr, n 459*4508a74aSNicholas Piggin BEGIN_FTR_SECTION_NESTED(947) 460*4508a74aSNicholas Piggin ld r10,\area+EX_CFAR(r13) 461*4508a74aSNicholas Piggin std r10,HSTATE_CFAR(r13) 462*4508a74aSNicholas Piggin END_FTR_SECTION_NESTED(CPU_FTR_CFAR,CPU_FTR_CFAR,947) 463*4508a74aSNicholas Piggin BEGIN_FTR_SECTION_NESTED(948) 464*4508a74aSNicholas Piggin ld r10,\area+EX_PPR(r13) 465*4508a74aSNicholas Piggin std r10,HSTATE_PPR(r13) 466*4508a74aSNicholas Piggin END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948) 467*4508a74aSNicholas Piggin ld r10,\area+EX_R10(r13) 468*4508a74aSNicholas Piggin std r12,HSTATE_SCRATCH0(r13) 469*4508a74aSNicholas Piggin sldi r12,r9,32 470*4508a74aSNicholas Piggin ori r12,r12,(\n) 471*4508a74aSNicholas Piggin /* This reloads r9 before branching to kvmppc_interrupt */ 472*4508a74aSNicholas Piggin __BRANCH_TO_KVM_EXIT(\area, kvmppc_interrupt) 473*4508a74aSNicholas Piggin .endm 474*4508a74aSNicholas Piggin 475*4508a74aSNicholas Piggin .macro KVM_HANDLER_SKIP area, hsrr, n 476*4508a74aSNicholas Piggin cmpwi r10,KVM_GUEST_MODE_SKIP 477*4508a74aSNicholas Piggin beq 89f 478*4508a74aSNicholas Piggin BEGIN_FTR_SECTION_NESTED(948) 479*4508a74aSNicholas Piggin ld r10,\area+EX_PPR(r13) 480*4508a74aSNicholas Piggin std r10,HSTATE_PPR(r13) 481*4508a74aSNicholas Piggin END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948) 482*4508a74aSNicholas Piggin ld r10,\area+EX_R10(r13) 483*4508a74aSNicholas Piggin std r12,HSTATE_SCRATCH0(r13) 484*4508a74aSNicholas Piggin sldi r12,r9,32 485*4508a74aSNicholas Piggin ori r12,r12,(\n) 486*4508a74aSNicholas Piggin /* This reloads r9 before branching to kvmppc_interrupt */ 487*4508a74aSNicholas Piggin __BRANCH_TO_KVM_EXIT(\area, kvmppc_interrupt) 488*4508a74aSNicholas Piggin 89: mtocrf 0x80,r9 489*4508a74aSNicholas Piggin ld r9,\area+EX_R9(r13) 490*4508a74aSNicholas Piggin ld r10,\area+EX_R10(r13) 491*4508a74aSNicholas Piggin .if \hsrr 492*4508a74aSNicholas Piggin b kvmppc_skip_Hinterrupt 493*4508a74aSNicholas Piggin .else 494*4508a74aSNicholas Piggin b kvmppc_skip_interrupt 495*4508a74aSNicholas Piggin .endif 496*4508a74aSNicholas Piggin .endm 497b01c8b54SPaul Mackerras 498b01c8b54SPaul Mackerras #else 499*4508a74aSNicholas Piggin .macro KVMTEST hsrr, n 500*4508a74aSNicholas Piggin .endm 501*4508a74aSNicholas Piggin .macro KVM_HANDLER area, hsrr, n 502*4508a74aSNicholas Piggin .endm 503*4508a74aSNicholas Piggin .macro KVM_HANDLER_SKIP area, hsrr, n 504*4508a74aSNicholas Piggin .endm 505b01c8b54SPaul Mackerras #endif 506b01c8b54SPaul Mackerras 507b01c8b54SPaul Mackerras #define NOTEST(n) 508b01c8b54SPaul Mackerras 509a4087a4dSNicholas Piggin #define EXCEPTION_PROLOG_COMMON_1() \ 510a4087a4dSNicholas Piggin std r9,_CCR(r1); /* save CR in stackframe */ \ 511a4087a4dSNicholas Piggin std r11,_NIP(r1); /* save SRR0 in stackframe */ \ 512a4087a4dSNicholas Piggin std r12,_MSR(r1); /* save SRR1 in stackframe */ \ 513a4087a4dSNicholas Piggin std r10,0(r1); /* make stack chain pointer */ \ 514a4087a4dSNicholas Piggin std r0,GPR0(r1); /* save r0 in stackframe */ \ 515a4087a4dSNicholas Piggin std r10,GPR1(r1); /* save r1 in stackframe */ \ 516a4087a4dSNicholas Piggin 517a4087a4dSNicholas Piggin 5188aa34ab8SBenjamin Herrenschmidt /* 5198aa34ab8SBenjamin Herrenschmidt * The common exception prolog is used for all except a few exceptions 5208aa34ab8SBenjamin Herrenschmidt * such as a segment miss on a kernel address. We have to be prepared 5218aa34ab8SBenjamin Herrenschmidt * to take another exception from the point where we first touch the 5228aa34ab8SBenjamin Herrenschmidt * kernel stack onwards. 5238aa34ab8SBenjamin Herrenschmidt * 5248aa34ab8SBenjamin Herrenschmidt * On entry r13 points to the paca, r9-r13 are saved in the paca, 5258aa34ab8SBenjamin Herrenschmidt * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and 5268aa34ab8SBenjamin Herrenschmidt * SRR1, and relocation is on. 5278aa34ab8SBenjamin Herrenschmidt */ 5288aa34ab8SBenjamin Herrenschmidt #define EXCEPTION_PROLOG_COMMON(n, area) \ 5298aa34ab8SBenjamin Herrenschmidt andi. r10,r12,MSR_PR; /* See if coming from user */ \ 5308aa34ab8SBenjamin Herrenschmidt mr r10,r1; /* Save r1 */ \ 5318aa34ab8SBenjamin Herrenschmidt subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \ 5328aa34ab8SBenjamin Herrenschmidt beq- 1f; \ 5338aa34ab8SBenjamin Herrenschmidt ld r1,PACAKSAVE(r13); /* kernel stack to use */ \ 53490ff5d68SMichael Neuling 1: cmpdi cr1,r1,-INT_FRAME_SIZE; /* check if r1 is in userspace */ \ 5351977b502SPaul Mackerras blt+ cr1,3f; /* abort if it is */ \ 5361977b502SPaul Mackerras li r1,(n); /* will be reloaded later */ \ 5378aa34ab8SBenjamin Herrenschmidt sth r1,PACA_TRAP_SAVE(r13); \ 5381977b502SPaul Mackerras std r3,area+EX_R3(r13); \ 5391977b502SPaul Mackerras addi r3,r13,area; /* r3 -> where regs are saved*/ \ 540bc2e6c6aSMichael Neuling RESTORE_CTR(r1, area); \ 5418aa34ab8SBenjamin Herrenschmidt b bad_stack; \ 542a4087a4dSNicholas Piggin 3: EXCEPTION_PROLOG_COMMON_1(); \ 543890274c2SMichael Ellerman kuap_save_amr_and_lock r9, r10, cr1, cr0; \ 5445d75b264SHaren Myneni beq 4f; /* if from kernel mode */ \ 545c223c903SChristophe Leroy ACCOUNT_CPU_USER_ENTRY(r13, r9, r10); \ 5464c2de74cSNicholas Piggin SAVE_PPR(area, r9); \ 547b14a7253SMahesh Salgaonkar 4: EXCEPTION_PROLOG_COMMON_2(area) \ 548b14a7253SMahesh Salgaonkar EXCEPTION_PROLOG_COMMON_3(n) \ 549b14a7253SMahesh Salgaonkar ACCOUNT_STOLEN_TIME 550b14a7253SMahesh Salgaonkar 551b14a7253SMahesh Salgaonkar /* Save original regs values from save area to stack frame. */ 552b14a7253SMahesh Salgaonkar #define EXCEPTION_PROLOG_COMMON_2(area) \ 5538aa34ab8SBenjamin Herrenschmidt ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \ 5548aa34ab8SBenjamin Herrenschmidt ld r10,area+EX_R10(r13); \ 5558aa34ab8SBenjamin Herrenschmidt std r9,GPR9(r1); \ 5568aa34ab8SBenjamin Herrenschmidt std r10,GPR10(r1); \ 5578aa34ab8SBenjamin Herrenschmidt ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \ 5588aa34ab8SBenjamin Herrenschmidt ld r10,area+EX_R12(r13); \ 5598aa34ab8SBenjamin Herrenschmidt ld r11,area+EX_R13(r13); \ 5608aa34ab8SBenjamin Herrenschmidt std r9,GPR11(r1); \ 5618aa34ab8SBenjamin Herrenschmidt std r10,GPR12(r1); \ 5628aa34ab8SBenjamin Herrenschmidt std r11,GPR13(r1); \ 56348404f2eSPaul Mackerras BEGIN_FTR_SECTION_NESTED(66); \ 56448404f2eSPaul Mackerras ld r10,area+EX_CFAR(r13); \ 56548404f2eSPaul Mackerras std r10,ORIG_GPR3(r1); \ 56648404f2eSPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \ 567b14a7253SMahesh Salgaonkar GET_CTR(r10, area); \ 568b14a7253SMahesh Salgaonkar std r10,_CTR(r1); 569b14a7253SMahesh Salgaonkar 570b14a7253SMahesh Salgaonkar #define EXCEPTION_PROLOG_COMMON_3(n) \ 571b14a7253SMahesh Salgaonkar std r2,GPR2(r1); /* save r2 in stackframe */ \ 572b14a7253SMahesh Salgaonkar SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \ 573b14a7253SMahesh Salgaonkar SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \ 574bc2e6c6aSMichael Neuling mflr r9; /* Get LR, later save to stack */ \ 5758aa34ab8SBenjamin Herrenschmidt ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \ 5768aa34ab8SBenjamin Herrenschmidt std r9,_LINK(r1); \ 5774e26bc4aSMadhavan Srinivasan lbz r10,PACAIRQSOFTMASK(r13); \ 5788aa34ab8SBenjamin Herrenschmidt mfspr r11,SPRN_XER; /* save XER in stackframe */ \ 5798aa34ab8SBenjamin Herrenschmidt std r10,SOFTE(r1); \ 5808aa34ab8SBenjamin Herrenschmidt std r11,_XER(r1); \ 5818aa34ab8SBenjamin Herrenschmidt li r9,(n)+1; \ 5828aa34ab8SBenjamin Herrenschmidt std r9,_TRAP(r1); /* set trap number */ \ 5838aa34ab8SBenjamin Herrenschmidt li r10,0; \ 5848aa34ab8SBenjamin Herrenschmidt ld r11,exception_marker@toc(r2); \ 5858aa34ab8SBenjamin Herrenschmidt std r10,RESULT(r1); /* clear regs->result */ \ 586b14a7253SMahesh Salgaonkar std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */ 5878aa34ab8SBenjamin Herrenschmidt 5888aa34ab8SBenjamin Herrenschmidt /* 5898aa34ab8SBenjamin Herrenschmidt * Exception vectors. 5908aa34ab8SBenjamin Herrenschmidt */ 591e899fce5SMichael Ellerman #define STD_EXCEPTION(vec, label) \ 592bdf08e1dSMichael Ellerman EXCEPTION_PROLOG(PACA_EXGEN, label, EXC_STD, KVMTEST_PR, vec); 5938aa34ab8SBenjamin Herrenschmidt 5941707dd16SPaul Mackerras /* Version of above for when we have to branch out-of-line */ 595da2bc464SMichael Ellerman #define __OOL_EXCEPTION(vec, label, hdlr) \ 5964b1f5cccSNicholas Piggin SET_SCRATCH0(r13); \ 5974b1f5cccSNicholas Piggin EXCEPTION_PROLOG_0(PACA_EXGEN); \ 5984b1f5cccSNicholas Piggin b hdlr 599da2bc464SMichael Ellerman 60075e8bef3SMichael Ellerman #define STD_EXCEPTION_OOL(vec, label) \ 601da2bc464SMichael Ellerman EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_PR, vec); \ 602*4508a74aSNicholas Piggin EXCEPTION_PROLOG_2 label, EXC_STD 6031707dd16SPaul Mackerras 604b3e6b5dfSBenjamin Herrenschmidt #define STD_EXCEPTION_HV(loc, vec, label) \ 6054b1f5cccSNicholas Piggin EXCEPTION_PROLOG(PACA_EXGEN, label, EXC_HV, KVMTEST_HV, vec) 6068aa34ab8SBenjamin Herrenschmidt 6071707dd16SPaul Mackerras #define STD_EXCEPTION_HV_OOL(vec, label) \ 608da2bc464SMichael Ellerman EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \ 609*4508a74aSNicholas Piggin EXCEPTION_PROLOG_2 label, EXC_HV 6101707dd16SPaul Mackerras 611e42389c5SMichael Ellerman #define STD_RELON_EXCEPTION(loc, vec, label) \ 6124700dfafSMichael Neuling /* No guest interrupts come through here */ \ 6134b1f5cccSNicholas Piggin EXCEPTION_RELON_PROLOG(PACA_EXGEN, label, EXC_STD, NOTEST, vec) 6144700dfafSMichael Neuling 615b706f423SMichael Ellerman #define STD_RELON_EXCEPTION_OOL(vec, label) \ 616c9f69518SMichael Ellerman EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, vec); \ 617*4508a74aSNicholas Piggin EXCEPTION_PROLOG_2_RELON label, EXC_STD 6181707dd16SPaul Mackerras 6194700dfafSMichael Neuling #define STD_RELON_EXCEPTION_HV(loc, vec, label) \ 6204b1f5cccSNicholas Piggin EXCEPTION_RELON_PROLOG(PACA_EXGEN, label, EXC_HV, KVMTEST_HV, vec) 6214700dfafSMichael Neuling 6221707dd16SPaul Mackerras #define STD_RELON_EXCEPTION_HV_OOL(vec, label) \ 623bc355125SPaul Mackerras EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \ 624*4508a74aSNicholas Piggin EXCEPTION_PROLOG_2_RELON label, EXC_HV 6251707dd16SPaul Mackerras 626*4508a74aSNicholas Piggin .macro SOFTEN_TEST hsrr, vec, bitmask 627*4508a74aSNicholas Piggin lbz r10, PACAIRQSOFTMASK(r13) 628*4508a74aSNicholas Piggin andi. r10, r10, \bitmask 629*4508a74aSNicholas Piggin /* This associates vector numbers with bits in paca->irq_happened */ 630*4508a74aSNicholas Piggin .if \vec == 0x500 || \vec == 0xea0 631*4508a74aSNicholas Piggin li r10, PACA_IRQ_EE 632*4508a74aSNicholas Piggin .elseif \vec == 0x900 633*4508a74aSNicholas Piggin li r10, PACA_IRQ_DEC 634*4508a74aSNicholas Piggin .elseif \vec == 0xa00 || \vec == 0xe80 635*4508a74aSNicholas Piggin li r10, PACA_IRQ_DBELL 636*4508a74aSNicholas Piggin .elseif \vec == 0xe60 637*4508a74aSNicholas Piggin li r10, PACA_IRQ_HMI 638*4508a74aSNicholas Piggin .elseif \vec == 0xf00 639*4508a74aSNicholas Piggin li r10, PACA_IRQ_PMI 640*4508a74aSNicholas Piggin .else 641*4508a74aSNicholas Piggin .abort "Bad maskable vector" 642*4508a74aSNicholas Piggin .endif 6437230c564SBenjamin Herrenschmidt 644da2bc464SMichael Ellerman 645*4508a74aSNicholas Piggin .if \hsrr 646*4508a74aSNicholas Piggin bne masked_Hinterrupt 647*4508a74aSNicholas Piggin .else 648*4508a74aSNicholas Piggin bne masked_interrupt 649*4508a74aSNicholas Piggin .endif 650*4508a74aSNicholas Piggin .endm 651b01c8b54SPaul Mackerras 652f14e953bSMadhavan Srinivasan #define SOFTEN_TEST_PR(vec, bitmask) \ 653*4508a74aSNicholas Piggin KVMTEST EXC_STD, vec ; \ 654*4508a74aSNicholas Piggin SOFTEN_TEST EXC_STD, vec, bitmask 655b01c8b54SPaul Mackerras 656f14e953bSMadhavan Srinivasan #define SOFTEN_TEST_HV(vec, bitmask) \ 657*4508a74aSNicholas Piggin KVMTEST EXC_HV, vec ; \ 658*4508a74aSNicholas Piggin SOFTEN_TEST EXC_HV, vec, bitmask 659b01c8b54SPaul Mackerras 660da2bc464SMichael Ellerman #define KVMTEST_PR(vec) \ 661*4508a74aSNicholas Piggin KVMTEST EXC_STD, vec 662da2bc464SMichael Ellerman 663da2bc464SMichael Ellerman #define KVMTEST_HV(vec) \ 664*4508a74aSNicholas Piggin KVMTEST EXC_HV, vec 665da2bc464SMichael Ellerman 666*4508a74aSNicholas Piggin #define SOFTEN_NOTEST_PR(vec, bitmask) SOFTEN_TEST EXC_STD, vec, bitmask 667*4508a74aSNicholas Piggin #define SOFTEN_NOTEST_HV(vec, bitmask) SOFTEN_TEST EXC_HV, vec, bitmask 6684700dfafSMichael Neuling 6690a55c241SMichael Ellerman #define __MASKABLE_EXCEPTION(vec, label, h, extra, bitmask) \ 670b01c8b54SPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 6711707dd16SPaul Mackerras EXCEPTION_PROLOG_0(PACA_EXGEN); \ 672f14e953bSMadhavan Srinivasan MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec, bitmask); \ 673*4508a74aSNicholas Piggin EXCEPTION_PROLOG_2 label, h 6741707dd16SPaul Mackerras 675b536da7cSMichael Ellerman #define MASKABLE_EXCEPTION(vec, label, bitmask) \ 6760a55c241SMichael Ellerman __MASKABLE_EXCEPTION(vec, label, EXC_STD, SOFTEN_TEST_PR, bitmask) 677b3e6b5dfSBenjamin Herrenschmidt 6780a55c241SMichael Ellerman #define MASKABLE_EXCEPTION_OOL(vec, label, bitmask) \ 679f14e953bSMadhavan Srinivasan MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_PR, vec, bitmask);\ 680*4508a74aSNicholas Piggin EXCEPTION_PROLOG_2 label, EXC_STD 681da2bc464SMichael Ellerman 682b536da7cSMichael Ellerman #define MASKABLE_EXCEPTION_HV(vec, label, bitmask) \ 6830a55c241SMichael Ellerman __MASKABLE_EXCEPTION(vec, label, EXC_HV, SOFTEN_TEST_HV, bitmask) 6848aa34ab8SBenjamin Herrenschmidt 685f14e953bSMadhavan Srinivasan #define MASKABLE_EXCEPTION_HV_OOL(vec, label, bitmask) \ 686f14e953bSMadhavan Srinivasan MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec, bitmask);\ 687*4508a74aSNicholas Piggin EXCEPTION_PROLOG_2 label, EXC_HV 6881707dd16SPaul Mackerras 6890a55c241SMichael Ellerman #define __MASKABLE_RELON_EXCEPTION(vec, label, h, extra, bitmask) \ 6904700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 6911707dd16SPaul Mackerras EXCEPTION_PROLOG_0(PACA_EXGEN); \ 692f14e953bSMadhavan Srinivasan MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec, bitmask); \ 693*4508a74aSNicholas Piggin EXCEPTION_PROLOG_2_RELON label, h 694da2bc464SMichael Ellerman 695b536da7cSMichael Ellerman #define MASKABLE_RELON_EXCEPTION(vec, label, bitmask) \ 6960a55c241SMichael Ellerman __MASKABLE_RELON_EXCEPTION(vec, label, EXC_STD, SOFTEN_NOTEST_PR, bitmask) 6974700dfafSMichael Neuling 6980a55c241SMichael Ellerman #define MASKABLE_RELON_EXCEPTION_OOL(vec, label, bitmask) \ 699f442d004SMadhavan Srinivasan MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_NOTEST_PR, vec, bitmask);\ 700*4508a74aSNicholas Piggin EXCEPTION_PROLOG_2 label, EXC_STD 701f442d004SMadhavan Srinivasan 702b536da7cSMichael Ellerman #define MASKABLE_RELON_EXCEPTION_HV(vec, label, bitmask) \ 7030a55c241SMichael Ellerman __MASKABLE_RELON_EXCEPTION(vec, label, EXC_HV, SOFTEN_TEST_HV, bitmask) 7044700dfafSMichael Neuling 705f14e953bSMadhavan Srinivasan #define MASKABLE_RELON_EXCEPTION_HV_OOL(vec, label, bitmask) \ 7065c11d1e5SMadhavan Srinivasan MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec, bitmask);\ 707*4508a74aSNicholas Piggin EXCEPTION_PROLOG_2_RELON label, EXC_HV 7081707dd16SPaul Mackerras 7091b701179SBenjamin Herrenschmidt /* 7101b701179SBenjamin Herrenschmidt * Our exception common code can be passed various "additions" 7111b701179SBenjamin Herrenschmidt * to specify the behaviour of interrupts, whether to kick the 7121b701179SBenjamin Herrenschmidt * runlatch, etc... 7131b701179SBenjamin Herrenschmidt */ 7141b701179SBenjamin Herrenschmidt 7159daf112bSMichael Ellerman /* 7169daf112bSMichael Ellerman * This addition reconciles our actual IRQ state with the various software 7179daf112bSMichael Ellerman * flags that track it. This may call C code. 7189daf112bSMichael Ellerman */ 7199daf112bSMichael Ellerman #define ADD_RECONCILE RECONCILE_IRQ_STATE(r10,r11) 7208aa34ab8SBenjamin Herrenschmidt 721fe1952fcSBenjamin Herrenschmidt #define ADD_NVGPRS \ 722b1576fecSAnton Blanchard bl save_nvgprs 723fe1952fcSBenjamin Herrenschmidt 724fe1952fcSBenjamin Herrenschmidt #define RUNLATCH_ON \ 725fe1952fcSBenjamin Herrenschmidt BEGIN_FTR_SECTION \ 726c911d2e1SChristophe Leroy ld r3, PACA_THREAD_INFO(r13); \ 727fe1952fcSBenjamin Herrenschmidt ld r4,TI_LOCAL_FLAGS(r3); \ 728fe1952fcSBenjamin Herrenschmidt andi. r0,r4,_TLF_RUNLATCH; \ 729fe1952fcSBenjamin Herrenschmidt beql ppc64_runlatch_on_trampoline; \ 730fe1952fcSBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CTRL) 731fe1952fcSBenjamin Herrenschmidt 732a3d96f70SNicholas Piggin #define EXCEPTION_COMMON(area, trap, label, hdlr, ret, additions) \ 733a3d96f70SNicholas Piggin EXCEPTION_PROLOG_COMMON(trap, area); \ 734a1d711c5SMichael Ellerman /* Volatile regs are potentially clobbered here */ \ 735fe1952fcSBenjamin Herrenschmidt additions; \ 7368aa34ab8SBenjamin Herrenschmidt addi r3,r1,STACK_FRAME_OVERHEAD; \ 7378aa34ab8SBenjamin Herrenschmidt bl hdlr; \ 738fe1952fcSBenjamin Herrenschmidt b ret 739fe1952fcSBenjamin Herrenschmidt 740b1ee8a3dSNicholas Piggin /* 741b1ee8a3dSNicholas Piggin * Exception where stack is already set in r1, r1 is saved in r10, and it 742b1ee8a3dSNicholas Piggin * continues rather than returns. 743b1ee8a3dSNicholas Piggin */ 744b1ee8a3dSNicholas Piggin #define EXCEPTION_COMMON_NORET_STACK(area, trap, label, hdlr, additions) \ 745b1ee8a3dSNicholas Piggin EXCEPTION_PROLOG_COMMON_1(); \ 746890274c2SMichael Ellerman kuap_save_amr_and_lock r9, r10, cr1; \ 747b1ee8a3dSNicholas Piggin EXCEPTION_PROLOG_COMMON_2(area); \ 748b1ee8a3dSNicholas Piggin EXCEPTION_PROLOG_COMMON_3(trap); \ 749b1ee8a3dSNicholas Piggin /* Volatile regs are potentially clobbered here */ \ 750b1ee8a3dSNicholas Piggin additions; \ 751b1ee8a3dSNicholas Piggin addi r3,r1,STACK_FRAME_OVERHEAD; \ 752b1ee8a3dSNicholas Piggin bl hdlr 753b1ee8a3dSNicholas Piggin 754fe1952fcSBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON(trap, label, hdlr) \ 755a3d96f70SNicholas Piggin EXCEPTION_COMMON(PACA_EXGEN, trap, label, hdlr, \ 756a3d96f70SNicholas Piggin ret_from_except, ADD_NVGPRS;ADD_RECONCILE) 7578aa34ab8SBenjamin Herrenschmidt 7588aa34ab8SBenjamin Herrenschmidt /* 7598aa34ab8SBenjamin Herrenschmidt * Like STD_EXCEPTION_COMMON, but for exceptions that can occur 7607450f6f0SBenjamin Herrenschmidt * in the idle task and therefore need the special idle handling 7617450f6f0SBenjamin Herrenschmidt * (finish nap and runlatch) 7628aa34ab8SBenjamin Herrenschmidt */ 7637450f6f0SBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON_ASYNC(trap, label, hdlr) \ 764a3d96f70SNicholas Piggin EXCEPTION_COMMON(PACA_EXGEN, trap, label, hdlr, \ 765a3d96f70SNicholas Piggin ret_from_except_lite, FINISH_NAP;ADD_RECONCILE;RUNLATCH_ON) 7668aa34ab8SBenjamin Herrenschmidt 7678aa34ab8SBenjamin Herrenschmidt /* 7688aa34ab8SBenjamin Herrenschmidt * When the idle code in power4_idle puts the CPU into NAP mode, 7698aa34ab8SBenjamin Herrenschmidt * it has to do so in a loop, and relies on the external interrupt 7708aa34ab8SBenjamin Herrenschmidt * and decrementer interrupt entry code to get it out of the loop. 7718aa34ab8SBenjamin Herrenschmidt * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags 7728aa34ab8SBenjamin Herrenschmidt * to signal that it is in the loop and needs help to get out. 7738aa34ab8SBenjamin Herrenschmidt */ 7748aa34ab8SBenjamin Herrenschmidt #ifdef CONFIG_PPC_970_NAP 7758aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP \ 7768aa34ab8SBenjamin Herrenschmidt BEGIN_FTR_SECTION \ 777c911d2e1SChristophe Leroy ld r11, PACA_THREAD_INFO(r13); \ 7788aa34ab8SBenjamin Herrenschmidt ld r9,TI_LOCAL_FLAGS(r11); \ 7798aa34ab8SBenjamin Herrenschmidt andi. r10,r9,_TLF_NAPPING; \ 7808aa34ab8SBenjamin Herrenschmidt bnel power4_fixup_nap; \ 7818aa34ab8SBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP) 7828aa34ab8SBenjamin Herrenschmidt #else 7838aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP 7848aa34ab8SBenjamin Herrenschmidt #endif 7858aa34ab8SBenjamin Herrenschmidt 786*4508a74aSNicholas Piggin #endif /* __ASSEMBLY__ */ 787*4508a74aSNicholas Piggin 7888aa34ab8SBenjamin Herrenschmidt #endif /* _ASM_POWERPC_EXCEPTION_H */ 789