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> 388aa34ab8SBenjamin Herrenschmidt 398c388514SNicholas Piggin /* PACA save area offsets (exgen, exmc, etc) */ 408aa34ab8SBenjamin Herrenschmidt #define EX_R9 0 418aa34ab8SBenjamin Herrenschmidt #define EX_R10 8 428aa34ab8SBenjamin Herrenschmidt #define EX_R11 16 438aa34ab8SBenjamin Herrenschmidt #define EX_R12 24 448aa34ab8SBenjamin Herrenschmidt #define EX_R13 32 4536670fcfSNicholas Piggin #define EX_DAR 40 4636670fcfSNicholas Piggin #define EX_DSISR 48 4736670fcfSNicholas Piggin #define EX_CCR 52 48635942aeSNicholas Piggin #define EX_CFAR 56 49635942aeSNicholas Piggin #define EX_PPR 64 508568f1e0SNicholas Piggin #if defined(CONFIG_RELOCATABLE) 51635942aeSNicholas Piggin #define EX_CTR 72 52635942aeSNicholas Piggin #define EX_SIZE 10 /* size in u64 units */ 538568f1e0SNicholas Piggin #else 548568f1e0SNicholas Piggin #define EX_SIZE 9 /* size in u64 units */ 558568f1e0SNicholas Piggin #endif 56dbeea1d6SNicholas Piggin 57dbeea1d6SNicholas Piggin /* 58ba41e1e1SBalbir Singh * maximum recursive depth of MCE exceptions 59ba41e1e1SBalbir Singh */ 60ba41e1e1SBalbir Singh #define MAX_MCE_DEPTH 4 61ba41e1e1SBalbir Singh 62ba41e1e1SBalbir Singh /* 63dbeea1d6SNicholas Piggin * EX_LR is only used in EXSLB and where it does not overlap with EX_DAR 64dbeea1d6SNicholas Piggin * EX_CCR similarly with DSISR, but being 4 byte registers there is a hole 65dbeea1d6SNicholas Piggin * in the save area so it's not necessary to overlap them. Could be used 66dbeea1d6SNicholas Piggin * for future savings though if another 4 byte register was to be saved. 67dbeea1d6SNicholas Piggin */ 68dbeea1d6SNicholas Piggin #define EX_LR EX_DAR 698c388514SNicholas Piggin 70635942aeSNicholas Piggin /* 71635942aeSNicholas Piggin * EX_R3 is only used by the bad_stack handler. bad_stack reloads and 72635942aeSNicholas Piggin * saves DAR from SPRN_DAR, and EX_DAR is not used. So EX_R3 can overlap 73635942aeSNicholas Piggin * with EX_DAR. 74635942aeSNicholas Piggin */ 75635942aeSNicholas Piggin #define EX_R3 EX_DAR 76635942aeSNicholas Piggin 7750e51c13SNicholas Piggin /* Macros for annotating the expected destination of (h)rfid */ 7850e51c13SNicholas Piggin 7950e51c13SNicholas Piggin #define RFI_TO_KERNEL \ 8050e51c13SNicholas Piggin rfid 8150e51c13SNicholas Piggin 8250e51c13SNicholas Piggin #define RFI_TO_USER \ 8350e51c13SNicholas Piggin rfid 8450e51c13SNicholas Piggin 8550e51c13SNicholas Piggin #define RFI_TO_USER_OR_KERNEL \ 8650e51c13SNicholas Piggin rfid 8750e51c13SNicholas Piggin 8850e51c13SNicholas Piggin #define RFI_TO_GUEST \ 8950e51c13SNicholas Piggin rfid 9050e51c13SNicholas Piggin 9150e51c13SNicholas Piggin #define HRFI_TO_KERNEL \ 9250e51c13SNicholas Piggin hrfid 9350e51c13SNicholas Piggin 9450e51c13SNicholas Piggin #define HRFI_TO_USER \ 9550e51c13SNicholas Piggin hrfid 9650e51c13SNicholas Piggin 9750e51c13SNicholas Piggin #define HRFI_TO_USER_OR_KERNEL \ 9850e51c13SNicholas Piggin hrfid 9950e51c13SNicholas Piggin 10050e51c13SNicholas Piggin #define HRFI_TO_GUEST \ 10150e51c13SNicholas Piggin hrfid 10250e51c13SNicholas Piggin 10350e51c13SNicholas Piggin #define HRFI_TO_UNKNOWN \ 10450e51c13SNicholas Piggin hrfid 10550e51c13SNicholas Piggin 1064700dfafSMichael Neuling #ifdef CONFIG_RELOCATABLE 1071707dd16SPaul Mackerras #define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 1084700dfafSMichael Neuling mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 1094700dfafSMichael Neuling LOAD_HANDLER(r12,label); \ 110bc2e6c6aSMichael Neuling mtctr r12; \ 1114700dfafSMichael Neuling mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 1124700dfafSMichael Neuling li r10,MSR_RI; \ 1134700dfafSMichael Neuling mtmsrd r10,1; /* Set RI (EE=0) */ \ 114bc2e6c6aSMichael Neuling bctr; 1154700dfafSMichael Neuling #else 1164700dfafSMichael Neuling /* If not relocatable, we can jump directly -- and save messing with LR */ 1171707dd16SPaul Mackerras #define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 1184700dfafSMichael Neuling mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 1194700dfafSMichael Neuling mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 1204700dfafSMichael Neuling li r10,MSR_RI; \ 1214700dfafSMichael Neuling mtmsrd r10,1; /* Set RI (EE=0) */ \ 1224700dfafSMichael Neuling b label; 1234700dfafSMichael Neuling #endif 1241707dd16SPaul Mackerras #define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 1251707dd16SPaul Mackerras __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 1264700dfafSMichael Neuling 1274700dfafSMichael Neuling /* 1284700dfafSMichael Neuling * As EXCEPTION_PROLOG_PSERIES(), except we've already got relocation on 1294700dfafSMichael Neuling * so no need to rfid. Save lr in case we're CONFIG_RELOCATABLE, in which 1304700dfafSMichael Neuling * case EXCEPTION_RELON_PROLOG_PSERIES_1 will be using lr. 1314700dfafSMichael Neuling */ 1324700dfafSMichael Neuling #define EXCEPTION_RELON_PROLOG_PSERIES(area, label, h, extra, vec) \ 1331707dd16SPaul Mackerras EXCEPTION_PROLOG_0(area); \ 1344700dfafSMichael Neuling EXCEPTION_PROLOG_1(area, extra, vec); \ 1354700dfafSMichael Neuling EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) 1364700dfafSMichael Neuling 1378aa34ab8SBenjamin Herrenschmidt /* 1388aa34ab8SBenjamin Herrenschmidt * We're short on space and time in the exception prolog, so we can't 13927510235SMichael Ellerman * use the normal LOAD_REG_IMMEDIATE macro to load the address of label. 14027510235SMichael Ellerman * Instead we get the base of the kernel from paca->kernelbase and or in the low 14127510235SMichael Ellerman * part of label. This requires that the label be within 64KB of kernelbase, and 14227510235SMichael Ellerman * that kernelbase be 64K aligned. 1438aa34ab8SBenjamin Herrenschmidt */ 1448aa34ab8SBenjamin Herrenschmidt #define LOAD_HANDLER(reg, label) \ 145d8d42b05SMichael Ellerman ld reg,PACAKBASE(r13); /* get high part of &label */ \ 146e6740ae6SHugh Dickins ori reg,reg,FIXED_SYMBOL_ABS_ADDR(label); 1478aa34ab8SBenjamin Herrenschmidt 148fb479e44SNicholas Piggin #define __LOAD_HANDLER(reg, label) \ 149fb479e44SNicholas Piggin ld reg,PACAKBASE(r13); \ 150fb479e44SNicholas Piggin ori reg,reg,(ABS_ADDR(label))@l; 151fb479e44SNicholas Piggin 152a97a65d5SNicholas Piggin /* 153a97a65d5SNicholas Piggin * Branches from unrelocated code (e.g., interrupts) to labels outside 154a97a65d5SNicholas Piggin * head-y require >64K offsets. 155a97a65d5SNicholas Piggin */ 156a97a65d5SNicholas Piggin #define __LOAD_FAR_HANDLER(reg, label) \ 157a97a65d5SNicholas Piggin ld reg,PACAKBASE(r13); \ 158a97a65d5SNicholas Piggin ori reg,reg,(ABS_ADDR(label))@l; \ 159a97a65d5SNicholas Piggin addis reg,reg,(ABS_ADDR(label))@h; 160a97a65d5SNicholas Piggin 161a5d4f3adSBenjamin Herrenschmidt /* Exception register prefixes */ 162a5d4f3adSBenjamin Herrenschmidt #define EXC_HV H 163a5d4f3adSBenjamin Herrenschmidt #define EXC_STD 164a5d4f3adSBenjamin Herrenschmidt 1654700dfafSMichael Neuling #if defined(CONFIG_RELOCATABLE) 1664700dfafSMichael Neuling /* 167bc2e6c6aSMichael Neuling * If we support interrupts with relocation on AND we're a relocatable kernel, 168bc2e6c6aSMichael Neuling * we need to use CTR to get to the 2nd level handler. So, save/restore it 169bc2e6c6aSMichael Neuling * when required. 1704700dfafSMichael Neuling */ 171bc2e6c6aSMichael Neuling #define SAVE_CTR(reg, area) mfctr reg ; std reg,area+EX_CTR(r13) 172bc2e6c6aSMichael Neuling #define GET_CTR(reg, area) ld reg,area+EX_CTR(r13) 173bc2e6c6aSMichael Neuling #define RESTORE_CTR(reg, area) ld reg,area+EX_CTR(r13) ; mtctr reg 1744700dfafSMichael Neuling #else 175bc2e6c6aSMichael Neuling /* ...else CTR is unused and in register. */ 176bc2e6c6aSMichael Neuling #define SAVE_CTR(reg, area) 177bc2e6c6aSMichael Neuling #define GET_CTR(reg, area) mfctr reg 178bc2e6c6aSMichael Neuling #define RESTORE_CTR(reg, area) 1794700dfafSMichael Neuling #endif 1804700dfafSMichael Neuling 18113e7a8e8SHaren Myneni /* 18213e7a8e8SHaren Myneni * PPR save/restore macros used in exceptions_64s.S 18313e7a8e8SHaren Myneni * Used for P7 or later processors 18413e7a8e8SHaren Myneni */ 18513e7a8e8SHaren Myneni #define SAVE_PPR(area, ra, rb) \ 18613e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(940) \ 18713e7a8e8SHaren Myneni ld ra,PACACURRENT(r13); \ 18813e7a8e8SHaren Myneni ld rb,area+EX_PPR(r13); /* Read PPR from paca */ \ 18913e7a8e8SHaren Myneni std rb,TASKTHREADPPR(ra); \ 19013e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940) 19113e7a8e8SHaren Myneni 19213e7a8e8SHaren Myneni #define RESTORE_PPR_PACA(area, ra) \ 19313e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(941) \ 19413e7a8e8SHaren Myneni ld ra,area+EX_PPR(r13); \ 19513e7a8e8SHaren Myneni mtspr SPRN_PPR,ra; \ 19613e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,941) 19713e7a8e8SHaren Myneni 19813e7a8e8SHaren Myneni /* 1991707dd16SPaul Mackerras * Get an SPR into a register if the CPU has the given feature 20013e7a8e8SHaren Myneni */ 2011707dd16SPaul Mackerras #define OPT_GET_SPR(ra, spr, ftr) \ 20213e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(943) \ 2031707dd16SPaul Mackerras mfspr ra,spr; \ 2041707dd16SPaul Mackerras END_FTR_SECTION_NESTED(ftr,ftr,943) 20513e7a8e8SHaren Myneni 2061707dd16SPaul Mackerras /* 207d410ae21SMahesh Salgaonkar * Set an SPR from a register if the CPU has the given feature 208d410ae21SMahesh Salgaonkar */ 209d410ae21SMahesh Salgaonkar #define OPT_SET_SPR(ra, spr, ftr) \ 210d410ae21SMahesh Salgaonkar BEGIN_FTR_SECTION_NESTED(943) \ 211d410ae21SMahesh Salgaonkar mtspr spr,ra; \ 212d410ae21SMahesh Salgaonkar END_FTR_SECTION_NESTED(ftr,ftr,943) 213d410ae21SMahesh Salgaonkar 214d410ae21SMahesh Salgaonkar /* 2151707dd16SPaul Mackerras * Save a register to the PACA if the CPU has the given feature 2161707dd16SPaul Mackerras */ 2171707dd16SPaul Mackerras #define OPT_SAVE_REG_TO_PACA(offset, ra, ftr) \ 2181707dd16SPaul Mackerras BEGIN_FTR_SECTION_NESTED(943) \ 2191707dd16SPaul Mackerras std ra,offset(r13); \ 2201707dd16SPaul Mackerras END_FTR_SECTION_NESTED(ftr,ftr,943) 2211707dd16SPaul Mackerras 222544686caSNicholas Piggin #define EXCEPTION_PROLOG_0(area) \ 223544686caSNicholas Piggin GET_PACA(r13); \ 22444e9309fSHaren Myneni std r9,area+EX_R9(r13); /* save r9 */ \ 2251707dd16SPaul Mackerras OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR); \ 2261707dd16SPaul Mackerras HMT_MEDIUM; \ 22744e9309fSHaren Myneni std r10,area+EX_R10(r13); /* save r10 - r12 */ \ 2281707dd16SPaul Mackerras OPT_GET_SPR(r10, SPRN_CFAR, CPU_FTR_CFAR) 2291707dd16SPaul Mackerras 2301707dd16SPaul Mackerras #define __EXCEPTION_PROLOG_1(area, extra, vec) \ 2311707dd16SPaul Mackerras OPT_SAVE_REG_TO_PACA(area+EX_PPR, r9, CPU_FTR_HAS_PPR); \ 2321707dd16SPaul Mackerras OPT_SAVE_REG_TO_PACA(area+EX_CFAR, r10, CPU_FTR_CFAR); \ 233bc2e6c6aSMichael Neuling SAVE_CTR(r10, area); \ 234b01c8b54SPaul Mackerras mfcr r9; \ 235b01c8b54SPaul Mackerras extra(vec); \ 236b01c8b54SPaul Mackerras std r11,area+EX_R11(r13); \ 237b01c8b54SPaul Mackerras std r12,area+EX_R12(r13); \ 238b01c8b54SPaul Mackerras GET_SCRATCH0(r10); \ 239b01c8b54SPaul Mackerras std r10,area+EX_R13(r13) 240b01c8b54SPaul Mackerras #define EXCEPTION_PROLOG_1(area, extra, vec) \ 241b01c8b54SPaul Mackerras __EXCEPTION_PROLOG_1(area, extra, vec) 2428aa34ab8SBenjamin Herrenschmidt 243a5d4f3adSBenjamin Herrenschmidt #define __EXCEPTION_PROLOG_PSERIES_1(label, h) \ 2448aa34ab8SBenjamin Herrenschmidt ld r10,PACAKMSR(r13); /* get MSR value for kernel */ \ 245a5d4f3adSBenjamin Herrenschmidt mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 2468aa34ab8SBenjamin Herrenschmidt LOAD_HANDLER(r12,label) \ 247a5d4f3adSBenjamin Herrenschmidt mtspr SPRN_##h##SRR0,r12; \ 248a5d4f3adSBenjamin Herrenschmidt mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 249a5d4f3adSBenjamin Herrenschmidt mtspr SPRN_##h##SRR1,r10; \ 250222f20f1SNicholas Piggin h##RFI_TO_KERNEL; \ 2518aa34ab8SBenjamin Herrenschmidt b . /* prevent speculative execution */ 252a5d4f3adSBenjamin Herrenschmidt #define EXCEPTION_PROLOG_PSERIES_1(label, h) \ 253a5d4f3adSBenjamin Herrenschmidt __EXCEPTION_PROLOG_PSERIES_1(label, h) 2548aa34ab8SBenjamin Herrenschmidt 25583a980f7SNicholas Piggin /* _NORI variant keeps MSR_RI clear */ 25683a980f7SNicholas Piggin #define __EXCEPTION_PROLOG_PSERIES_1_NORI(label, h) \ 25783a980f7SNicholas Piggin ld r10,PACAKMSR(r13); /* get MSR value for kernel */ \ 25883a980f7SNicholas Piggin xori r10,r10,MSR_RI; /* Clear MSR_RI */ \ 25983a980f7SNicholas Piggin mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 26083a980f7SNicholas Piggin LOAD_HANDLER(r12,label) \ 26183a980f7SNicholas Piggin mtspr SPRN_##h##SRR0,r12; \ 26283a980f7SNicholas Piggin mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 26383a980f7SNicholas Piggin mtspr SPRN_##h##SRR1,r10; \ 264222f20f1SNicholas Piggin h##RFI_TO_KERNEL; \ 26583a980f7SNicholas Piggin b . /* prevent speculative execution */ 26683a980f7SNicholas Piggin 26783a980f7SNicholas Piggin #define EXCEPTION_PROLOG_PSERIES_1_NORI(label, h) \ 26883a980f7SNicholas Piggin __EXCEPTION_PROLOG_PSERIES_1_NORI(label, h) 26983a980f7SNicholas Piggin 270b01c8b54SPaul Mackerras #define EXCEPTION_PROLOG_PSERIES(area, label, h, extra, vec) \ 2711707dd16SPaul Mackerras EXCEPTION_PROLOG_0(area); \ 272b01c8b54SPaul Mackerras EXCEPTION_PROLOG_1(area, extra, vec); \ 273a5d4f3adSBenjamin Herrenschmidt EXCEPTION_PROLOG_PSERIES_1(label, h); 274c5a8c0c9SBenjamin Herrenschmidt 275da2bc464SMichael Ellerman #define __KVMTEST(h, n) \ 2763c42bf8aSPaul Mackerras lbz r10,HSTATE_IN_GUEST(r13); \ 277b01c8b54SPaul Mackerras cmpwi r10,0; \ 278da2bc464SMichael Ellerman bne do_kvm_##h##n 279b01c8b54SPaul Mackerras 280dd96b2c2SAneesh Kumar K.V #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 281dd96b2c2SAneesh Kumar K.V /* 282dd96b2c2SAneesh Kumar K.V * If hv is possible, interrupts come into to the hv version 283dd96b2c2SAneesh Kumar K.V * of the kvmppc_interrupt code, which then jumps to the PR handler, 284dd96b2c2SAneesh Kumar K.V * kvmppc_interrupt_pr, if the guest is a PR guest. 285dd96b2c2SAneesh Kumar K.V */ 286dd96b2c2SAneesh Kumar K.V #define kvmppc_interrupt kvmppc_interrupt_hv 287dd96b2c2SAneesh Kumar K.V #else 288dd96b2c2SAneesh Kumar K.V #define kvmppc_interrupt kvmppc_interrupt_pr 289dd96b2c2SAneesh Kumar K.V #endif 290dd96b2c2SAneesh Kumar K.V 291b51351e2SNicholas Piggin /* 292b51351e2SNicholas Piggin * Branch to label using its 0xC000 address. This results in instruction 293b51351e2SNicholas Piggin * address suitable for MSR[IR]=0 or 1, which allows relocation to be turned 294b51351e2SNicholas Piggin * on using mtmsr rather than rfid. 295b51351e2SNicholas Piggin * 296b51351e2SNicholas Piggin * This could set the 0xc bits for !RELOCATABLE as an immediate, rather than 297b51351e2SNicholas Piggin * load KBASE for a slight optimisation. 298b51351e2SNicholas Piggin */ 299b51351e2SNicholas Piggin #define BRANCH_TO_C000(reg, label) \ 300b51351e2SNicholas Piggin __LOAD_HANDLER(reg, label); \ 301b51351e2SNicholas Piggin mtctr reg; \ 302b51351e2SNicholas Piggin bctr 303b51351e2SNicholas Piggin 304fb479e44SNicholas Piggin #ifdef CONFIG_RELOCATABLE 305fb479e44SNicholas Piggin #define BRANCH_TO_COMMON(reg, label) \ 306fb479e44SNicholas Piggin __LOAD_HANDLER(reg, label); \ 307fb479e44SNicholas Piggin mtctr reg; \ 308fb479e44SNicholas Piggin bctr 309fb479e44SNicholas Piggin 310be5c5e84SMichael Ellerman #define BRANCH_LINK_TO_FAR(label) \ 311be5c5e84SMichael Ellerman __LOAD_FAR_HANDLER(r12, label); \ 312be5c5e84SMichael Ellerman mtctr r12; \ 3132337d207SNicholas Piggin bctrl 3142337d207SNicholas Piggin 315a97a65d5SNicholas Piggin /* 316a97a65d5SNicholas Piggin * KVM requires __LOAD_FAR_HANDLER. 317a97a65d5SNicholas Piggin * 318a97a65d5SNicholas Piggin * __BRANCH_TO_KVM_EXIT branches are also a special case because they 319a97a65d5SNicholas Piggin * explicitly use r9 then reload it from PACA before branching. Hence 320a97a65d5SNicholas Piggin * the double-underscore. 321a97a65d5SNicholas Piggin */ 322a97a65d5SNicholas Piggin #define __BRANCH_TO_KVM_EXIT(area, label) \ 323a97a65d5SNicholas Piggin mfctr r9; \ 324a97a65d5SNicholas Piggin std r9,HSTATE_SCRATCH1(r13); \ 325a97a65d5SNicholas Piggin __LOAD_FAR_HANDLER(r9, label); \ 326a97a65d5SNicholas Piggin mtctr r9; \ 327a97a65d5SNicholas Piggin ld r9,area+EX_R9(r13); \ 328a97a65d5SNicholas Piggin bctr 329a97a65d5SNicholas Piggin 330fb479e44SNicholas Piggin #else 331fb479e44SNicholas Piggin #define BRANCH_TO_COMMON(reg, label) \ 332fb479e44SNicholas Piggin b label 333fb479e44SNicholas Piggin 334be5c5e84SMichael Ellerman #define BRANCH_LINK_TO_FAR(label) \ 3352337d207SNicholas Piggin bl label 3362337d207SNicholas Piggin 337a97a65d5SNicholas Piggin #define __BRANCH_TO_KVM_EXIT(area, label) \ 338a97a65d5SNicholas Piggin ld r9,area+EX_R9(r13); \ 339a97a65d5SNicholas Piggin b label 340a97a65d5SNicholas Piggin 341fb479e44SNicholas Piggin #endif 342fb479e44SNicholas Piggin 343c4f3b52cSNicholas Piggin /* Do not enable RI */ 344c4f3b52cSNicholas Piggin #define EXCEPTION_PROLOG_PSERIES_NORI(area, label, h, extra, vec) \ 345c4f3b52cSNicholas Piggin EXCEPTION_PROLOG_0(area); \ 346c4f3b52cSNicholas Piggin EXCEPTION_PROLOG_1(area, extra, vec); \ 347c4f3b52cSNicholas Piggin EXCEPTION_PROLOG_PSERIES_1_NORI(label, h); 348c4f3b52cSNicholas Piggin 349a97a65d5SNicholas Piggin 350d3918e7fSNicholas Piggin #define __KVM_HANDLER(area, h, n) \ 3510acb9111SPaul Mackerras BEGIN_FTR_SECTION_NESTED(947) \ 3520acb9111SPaul Mackerras ld r10,area+EX_CFAR(r13); \ 3530acb9111SPaul Mackerras std r10,HSTATE_CFAR(r13); \ 3540acb9111SPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_CFAR,CPU_FTR_CFAR,947); \ 3554b8473c9SPaul Mackerras BEGIN_FTR_SECTION_NESTED(948) \ 3564b8473c9SPaul Mackerras ld r10,area+EX_PPR(r13); \ 3574b8473c9SPaul Mackerras std r10,HSTATE_PPR(r13); \ 3584b8473c9SPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \ 359b01c8b54SPaul Mackerras ld r10,area+EX_R10(r13); \ 3603c42bf8aSPaul Mackerras std r12,HSTATE_SCRATCH0(r13); \ 361d3918e7fSNicholas Piggin sldi r12,r9,32; \ 362d3918e7fSNicholas Piggin ori r12,r12,(n); \ 363a97a65d5SNicholas Piggin /* This reloads r9 before branching to kvmppc_interrupt */ \ 364a97a65d5SNicholas Piggin __BRANCH_TO_KVM_EXIT(area, kvmppc_interrupt) 365b01c8b54SPaul Mackerras 366b01c8b54SPaul Mackerras #define __KVM_HANDLER_SKIP(area, h, n) \ 367b01c8b54SPaul Mackerras cmpwi r10,KVM_GUEST_MODE_SKIP; \ 368b01c8b54SPaul Mackerras beq 89f; \ 3694b8473c9SPaul Mackerras BEGIN_FTR_SECTION_NESTED(948) \ 370d3918e7fSNicholas Piggin ld r10,area+EX_PPR(r13); \ 371d3918e7fSNicholas Piggin std r10,HSTATE_PPR(r13); \ 3724b8473c9SPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \ 373d3918e7fSNicholas Piggin ld r10,area+EX_R10(r13); \ 3743c42bf8aSPaul Mackerras std r12,HSTATE_SCRATCH0(r13); \ 375d3918e7fSNicholas Piggin sldi r12,r9,32; \ 376d3918e7fSNicholas Piggin ori r12,r12,(n); \ 377a97a65d5SNicholas Piggin /* This reloads r9 before branching to kvmppc_interrupt */ \ 378a97a65d5SNicholas Piggin __BRANCH_TO_KVM_EXIT(area, kvmppc_interrupt); \ 379b01c8b54SPaul Mackerras 89: mtocrf 0x80,r9; \ 380b01c8b54SPaul Mackerras ld r9,area+EX_R9(r13); \ 381d3918e7fSNicholas Piggin ld r10,area+EX_R10(r13); \ 382b01c8b54SPaul Mackerras b kvmppc_skip_##h##interrupt 383b01c8b54SPaul Mackerras 384b01c8b54SPaul Mackerras #ifdef CONFIG_KVM_BOOK3S_64_HANDLER 385da2bc464SMichael Ellerman #define KVMTEST(h, n) __KVMTEST(h, n) 386b01c8b54SPaul Mackerras #define KVM_HANDLER(area, h, n) __KVM_HANDLER(area, h, n) 387b01c8b54SPaul Mackerras #define KVM_HANDLER_SKIP(area, h, n) __KVM_HANDLER_SKIP(area, h, n) 388b01c8b54SPaul Mackerras 389b01c8b54SPaul Mackerras #else 390da2bc464SMichael Ellerman #define KVMTEST(h, n) 391b01c8b54SPaul Mackerras #define KVM_HANDLER(area, h, n) 392b01c8b54SPaul Mackerras #define KVM_HANDLER_SKIP(area, h, n) 393b01c8b54SPaul Mackerras #endif 394b01c8b54SPaul Mackerras 395b01c8b54SPaul Mackerras #define NOTEST(n) 396b01c8b54SPaul Mackerras 397a4087a4dSNicholas Piggin #define EXCEPTION_PROLOG_COMMON_1() \ 398a4087a4dSNicholas Piggin std r9,_CCR(r1); /* save CR in stackframe */ \ 399a4087a4dSNicholas Piggin std r11,_NIP(r1); /* save SRR0 in stackframe */ \ 400a4087a4dSNicholas Piggin std r12,_MSR(r1); /* save SRR1 in stackframe */ \ 401a4087a4dSNicholas Piggin std r10,0(r1); /* make stack chain pointer */ \ 402a4087a4dSNicholas Piggin std r0,GPR0(r1); /* save r0 in stackframe */ \ 403a4087a4dSNicholas Piggin std r10,GPR1(r1); /* save r1 in stackframe */ \ 404a4087a4dSNicholas Piggin 405a4087a4dSNicholas Piggin 4068aa34ab8SBenjamin Herrenschmidt /* 4078aa34ab8SBenjamin Herrenschmidt * The common exception prolog is used for all except a few exceptions 4088aa34ab8SBenjamin Herrenschmidt * such as a segment miss on a kernel address. We have to be prepared 4098aa34ab8SBenjamin Herrenschmidt * to take another exception from the point where we first touch the 4108aa34ab8SBenjamin Herrenschmidt * kernel stack onwards. 4118aa34ab8SBenjamin Herrenschmidt * 4128aa34ab8SBenjamin Herrenschmidt * On entry r13 points to the paca, r9-r13 are saved in the paca, 4138aa34ab8SBenjamin Herrenschmidt * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and 4148aa34ab8SBenjamin Herrenschmidt * SRR1, and relocation is on. 4158aa34ab8SBenjamin Herrenschmidt */ 4168aa34ab8SBenjamin Herrenschmidt #define EXCEPTION_PROLOG_COMMON(n, area) \ 4178aa34ab8SBenjamin Herrenschmidt andi. r10,r12,MSR_PR; /* See if coming from user */ \ 4188aa34ab8SBenjamin Herrenschmidt mr r10,r1; /* Save r1 */ \ 4198aa34ab8SBenjamin Herrenschmidt subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \ 4208aa34ab8SBenjamin Herrenschmidt beq- 1f; \ 4218aa34ab8SBenjamin Herrenschmidt ld r1,PACAKSAVE(r13); /* kernel stack to use */ \ 42290ff5d68SMichael Neuling 1: cmpdi cr1,r1,-INT_FRAME_SIZE; /* check if r1 is in userspace */ \ 4231977b502SPaul Mackerras blt+ cr1,3f; /* abort if it is */ \ 4241977b502SPaul Mackerras li r1,(n); /* will be reloaded later */ \ 4258aa34ab8SBenjamin Herrenschmidt sth r1,PACA_TRAP_SAVE(r13); \ 4261977b502SPaul Mackerras std r3,area+EX_R3(r13); \ 4271977b502SPaul Mackerras addi r3,r13,area; /* r3 -> where regs are saved*/ \ 428bc2e6c6aSMichael Neuling RESTORE_CTR(r1, area); \ 4298aa34ab8SBenjamin Herrenschmidt b bad_stack; \ 430a4087a4dSNicholas Piggin 3: EXCEPTION_PROLOG_COMMON_1(); \ 4315d75b264SHaren Myneni beq 4f; /* if from kernel mode */ \ 432c223c903SChristophe Leroy ACCOUNT_CPU_USER_ENTRY(r13, r9, r10); \ 43344e9309fSHaren Myneni SAVE_PPR(area, r9, r10); \ 434b14a7253SMahesh Salgaonkar 4: EXCEPTION_PROLOG_COMMON_2(area) \ 435b14a7253SMahesh Salgaonkar EXCEPTION_PROLOG_COMMON_3(n) \ 436b14a7253SMahesh Salgaonkar ACCOUNT_STOLEN_TIME 437b14a7253SMahesh Salgaonkar 438b14a7253SMahesh Salgaonkar /* Save original regs values from save area to stack frame. */ 439b14a7253SMahesh Salgaonkar #define EXCEPTION_PROLOG_COMMON_2(area) \ 4408aa34ab8SBenjamin Herrenschmidt ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \ 4418aa34ab8SBenjamin Herrenschmidt ld r10,area+EX_R10(r13); \ 4428aa34ab8SBenjamin Herrenschmidt std r9,GPR9(r1); \ 4438aa34ab8SBenjamin Herrenschmidt std r10,GPR10(r1); \ 4448aa34ab8SBenjamin Herrenschmidt ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \ 4458aa34ab8SBenjamin Herrenschmidt ld r10,area+EX_R12(r13); \ 4468aa34ab8SBenjamin Herrenschmidt ld r11,area+EX_R13(r13); \ 4478aa34ab8SBenjamin Herrenschmidt std r9,GPR11(r1); \ 4488aa34ab8SBenjamin Herrenschmidt std r10,GPR12(r1); \ 4498aa34ab8SBenjamin Herrenschmidt std r11,GPR13(r1); \ 45048404f2eSPaul Mackerras BEGIN_FTR_SECTION_NESTED(66); \ 45148404f2eSPaul Mackerras ld r10,area+EX_CFAR(r13); \ 45248404f2eSPaul Mackerras std r10,ORIG_GPR3(r1); \ 45348404f2eSPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \ 454b14a7253SMahesh Salgaonkar GET_CTR(r10, area); \ 455b14a7253SMahesh Salgaonkar std r10,_CTR(r1); 456b14a7253SMahesh Salgaonkar 457b14a7253SMahesh Salgaonkar #define EXCEPTION_PROLOG_COMMON_3(n) \ 458b14a7253SMahesh Salgaonkar std r2,GPR2(r1); /* save r2 in stackframe */ \ 459b14a7253SMahesh Salgaonkar SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \ 460b14a7253SMahesh Salgaonkar SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \ 461bc2e6c6aSMichael Neuling mflr r9; /* Get LR, later save to stack */ \ 4628aa34ab8SBenjamin Herrenschmidt ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \ 4638aa34ab8SBenjamin Herrenschmidt std r9,_LINK(r1); \ 4648aa34ab8SBenjamin Herrenschmidt lbz r10,PACASOFTIRQEN(r13); \ 4658aa34ab8SBenjamin Herrenschmidt mfspr r11,SPRN_XER; /* save XER in stackframe */ \ 4668aa34ab8SBenjamin Herrenschmidt std r10,SOFTE(r1); \ 4678aa34ab8SBenjamin Herrenschmidt std r11,_XER(r1); \ 4688aa34ab8SBenjamin Herrenschmidt li r9,(n)+1; \ 4698aa34ab8SBenjamin Herrenschmidt std r9,_TRAP(r1); /* set trap number */ \ 4708aa34ab8SBenjamin Herrenschmidt li r10,0; \ 4718aa34ab8SBenjamin Herrenschmidt ld r11,exception_marker@toc(r2); \ 4728aa34ab8SBenjamin Herrenschmidt std r10,RESULT(r1); /* clear regs->result */ \ 473b14a7253SMahesh Salgaonkar std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */ 4748aa34ab8SBenjamin Herrenschmidt 4758aa34ab8SBenjamin Herrenschmidt /* 4768aa34ab8SBenjamin Herrenschmidt * Exception vectors. 4778aa34ab8SBenjamin Herrenschmidt */ 4782613265cSMichael Ellerman #define STD_EXCEPTION_PSERIES(vec, label) \ 479673b189aSPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 480da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \ 481da2bc464SMichael Ellerman EXC_STD, KVMTEST_PR, vec); \ 4828aa34ab8SBenjamin Herrenschmidt 4831707dd16SPaul Mackerras /* Version of above for when we have to branch out-of-line */ 484da2bc464SMichael Ellerman #define __OOL_EXCEPTION(vec, label, hdlr) \ 485da2bc464SMichael Ellerman SET_SCRATCH0(r13) \ 486da2bc464SMichael Ellerman EXCEPTION_PROLOG_0(PACA_EXGEN) \ 487da2bc464SMichael Ellerman b hdlr; 488da2bc464SMichael Ellerman 4891707dd16SPaul Mackerras #define STD_EXCEPTION_PSERIES_OOL(vec, label) \ 490da2bc464SMichael Ellerman EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_PR, vec); \ 491da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD) 4921707dd16SPaul Mackerras 493b3e6b5dfSBenjamin Herrenschmidt #define STD_EXCEPTION_HV(loc, vec, label) \ 494673b189aSPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 495da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \ 496da2bc464SMichael Ellerman EXC_HV, KVMTEST_HV, vec); 4978aa34ab8SBenjamin Herrenschmidt 4981707dd16SPaul Mackerras #define STD_EXCEPTION_HV_OOL(vec, label) \ 499da2bc464SMichael Ellerman EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \ 500da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV) 5011707dd16SPaul Mackerras 5024700dfafSMichael Neuling #define STD_RELON_EXCEPTION_PSERIES(loc, vec, label) \ 5034700dfafSMichael Neuling /* No guest interrupts come through here */ \ 5044700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 505da2bc464SMichael Ellerman EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, EXC_STD, NOTEST, vec); 5064700dfafSMichael Neuling 5071707dd16SPaul Mackerras #define STD_RELON_EXCEPTION_PSERIES_OOL(vec, label) \ 508c9f69518SMichael Ellerman EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, vec); \ 509da2bc464SMichael Ellerman EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_STD) 5101707dd16SPaul Mackerras 5114700dfafSMichael Neuling #define STD_RELON_EXCEPTION_HV(loc, vec, label) \ 5124700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 513bc355125SPaul Mackerras EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, \ 514bc355125SPaul Mackerras EXC_HV, KVMTEST_HV, vec); 5154700dfafSMichael Neuling 5161707dd16SPaul Mackerras #define STD_RELON_EXCEPTION_HV_OOL(vec, label) \ 517bc355125SPaul Mackerras EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \ 518da2bc464SMichael Ellerman EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV) 5191707dd16SPaul Mackerras 5207230c564SBenjamin Herrenschmidt /* This associate vector numbers with bits in paca->irq_happened */ 5217230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x500 PACA_IRQ_EE 5227230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x900 PACA_IRQ_DEC 523da2bc464SMichael Ellerman #define SOFTEN_VALUE_0x980 PACA_IRQ_DEC 5241dbdafecSIan Munsie #define SOFTEN_VALUE_0xa00 PACA_IRQ_DBELL 525655bb3f4SIan Munsie #define SOFTEN_VALUE_0xe80 PACA_IRQ_DBELL 5260869b6fdSMahesh Salgaonkar #define SOFTEN_VALUE_0xe60 PACA_IRQ_HMI 5279baaef0aSBenjamin Herrenschmidt #define SOFTEN_VALUE_0xea0 PACA_IRQ_EE 5287230c564SBenjamin Herrenschmidt 5297230c564SBenjamin Herrenschmidt #define __SOFTEN_TEST(h, vec) \ 5308aa34ab8SBenjamin Herrenschmidt lbz r10,PACASOFTIRQEN(r13); \ 5318aa34ab8SBenjamin Herrenschmidt cmpwi r10,0; \ 5327230c564SBenjamin Herrenschmidt li r10,SOFTEN_VALUE_##vec; \ 533b01c8b54SPaul Mackerras beq masked_##h##interrupt 534da2bc464SMichael Ellerman 5357230c564SBenjamin Herrenschmidt #define _SOFTEN_TEST(h, vec) __SOFTEN_TEST(h, vec) 536b01c8b54SPaul Mackerras 537de56a948SPaul Mackerras #define SOFTEN_TEST_PR(vec) \ 538da2bc464SMichael Ellerman KVMTEST(EXC_STD, vec); \ 5397230c564SBenjamin Herrenschmidt _SOFTEN_TEST(EXC_STD, vec) 540b01c8b54SPaul Mackerras 541b01c8b54SPaul Mackerras #define SOFTEN_TEST_HV(vec) \ 542da2bc464SMichael Ellerman KVMTEST(EXC_HV, vec); \ 5437230c564SBenjamin Herrenschmidt _SOFTEN_TEST(EXC_HV, vec) 544b01c8b54SPaul Mackerras 545da2bc464SMichael Ellerman #define KVMTEST_PR(vec) \ 546da2bc464SMichael Ellerman KVMTEST(EXC_STD, vec) 547da2bc464SMichael Ellerman 548da2bc464SMichael Ellerman #define KVMTEST_HV(vec) \ 549da2bc464SMichael Ellerman KVMTEST(EXC_HV, vec) 550da2bc464SMichael Ellerman 5514700dfafSMichael Neuling #define SOFTEN_NOTEST_PR(vec) _SOFTEN_TEST(EXC_STD, vec) 5524700dfafSMichael Neuling #define SOFTEN_NOTEST_HV(vec) _SOFTEN_TEST(EXC_HV, vec) 5534700dfafSMichael Neuling 554b01c8b54SPaul Mackerras #define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \ 555b01c8b54SPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 5561707dd16SPaul Mackerras EXCEPTION_PROLOG_0(PACA_EXGEN); \ 557b01c8b54SPaul Mackerras __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \ 558da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES_1(label, h); 5591707dd16SPaul Mackerras 560b01c8b54SPaul Mackerras #define _MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \ 561b01c8b54SPaul Mackerras __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) 562b3e6b5dfSBenjamin Herrenschmidt 563b3e6b5dfSBenjamin Herrenschmidt #define MASKABLE_EXCEPTION_PSERIES(loc, vec, label) \ 564b01c8b54SPaul Mackerras _MASKABLE_EXCEPTION_PSERIES(vec, label, \ 565de56a948SPaul Mackerras EXC_STD, SOFTEN_TEST_PR) 566b3e6b5dfSBenjamin Herrenschmidt 567da2bc464SMichael Ellerman #define MASKABLE_EXCEPTION_PSERIES_OOL(vec, label) \ 568da2bc464SMichael Ellerman EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_PR, vec); \ 569da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD) 570da2bc464SMichael Ellerman 571b3e6b5dfSBenjamin Herrenschmidt #define MASKABLE_EXCEPTION_HV(loc, vec, label) \ 572b01c8b54SPaul Mackerras _MASKABLE_EXCEPTION_PSERIES(vec, label, \ 573b01c8b54SPaul Mackerras EXC_HV, SOFTEN_TEST_HV) 5748aa34ab8SBenjamin Herrenschmidt 5751707dd16SPaul Mackerras #define MASKABLE_EXCEPTION_HV_OOL(vec, label) \ 5761707dd16SPaul Mackerras EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec); \ 577da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV) 5781707dd16SPaul Mackerras 5794700dfafSMichael Neuling #define __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \ 5804700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 5811707dd16SPaul Mackerras EXCEPTION_PROLOG_0(PACA_EXGEN); \ 5824700dfafSMichael Neuling __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \ 583da2bc464SMichael Ellerman EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) 584da2bc464SMichael Ellerman 5854700dfafSMichael Neuling #define _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \ 5864700dfafSMichael Neuling __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) 5874700dfafSMichael Neuling 5884700dfafSMichael Neuling #define MASKABLE_RELON_EXCEPTION_PSERIES(loc, vec, label) \ 5894700dfafSMichael Neuling _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \ 5904700dfafSMichael Neuling EXC_STD, SOFTEN_NOTEST_PR) 5914700dfafSMichael Neuling 5924700dfafSMichael Neuling #define MASKABLE_RELON_EXCEPTION_HV(loc, vec, label) \ 5934700dfafSMichael Neuling _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \ 594bc355125SPaul Mackerras EXC_HV, SOFTEN_TEST_HV) 5954700dfafSMichael Neuling 5961707dd16SPaul Mackerras #define MASKABLE_RELON_EXCEPTION_HV_OOL(vec, label) \ 597bc355125SPaul Mackerras EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec); \ 598a050d20dSNicholas Piggin EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV) 5991707dd16SPaul Mackerras 6001b701179SBenjamin Herrenschmidt /* 6011b701179SBenjamin Herrenschmidt * Our exception common code can be passed various "additions" 6021b701179SBenjamin Herrenschmidt * to specify the behaviour of interrupts, whether to kick the 6031b701179SBenjamin Herrenschmidt * runlatch, etc... 6041b701179SBenjamin Herrenschmidt */ 6051b701179SBenjamin Herrenschmidt 6069daf112bSMichael Ellerman /* 6079daf112bSMichael Ellerman * This addition reconciles our actual IRQ state with the various software 6089daf112bSMichael Ellerman * flags that track it. This may call C code. 6099daf112bSMichael Ellerman */ 6109daf112bSMichael Ellerman #define ADD_RECONCILE RECONCILE_IRQ_STATE(r10,r11) 6118aa34ab8SBenjamin Herrenschmidt 612fe1952fcSBenjamin Herrenschmidt #define ADD_NVGPRS \ 613b1576fecSAnton Blanchard bl save_nvgprs 614fe1952fcSBenjamin Herrenschmidt 615fe1952fcSBenjamin Herrenschmidt #define RUNLATCH_ON \ 616fe1952fcSBenjamin Herrenschmidt BEGIN_FTR_SECTION \ 6179778b696SStuart Yoder CURRENT_THREAD_INFO(r3, r1); \ 618fe1952fcSBenjamin Herrenschmidt ld r4,TI_LOCAL_FLAGS(r3); \ 619fe1952fcSBenjamin Herrenschmidt andi. r0,r4,_TLF_RUNLATCH; \ 620fe1952fcSBenjamin Herrenschmidt beql ppc64_runlatch_on_trampoline; \ 621fe1952fcSBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CTRL) 622fe1952fcSBenjamin Herrenschmidt 623a3d96f70SNicholas Piggin #define EXCEPTION_COMMON(area, trap, label, hdlr, ret, additions) \ 624a3d96f70SNicholas Piggin EXCEPTION_PROLOG_COMMON(trap, area); \ 625a1d711c5SMichael Ellerman /* Volatile regs are potentially clobbered here */ \ 626fe1952fcSBenjamin Herrenschmidt additions; \ 6278aa34ab8SBenjamin Herrenschmidt addi r3,r1,STACK_FRAME_OVERHEAD; \ 6288aa34ab8SBenjamin Herrenschmidt bl hdlr; \ 629fe1952fcSBenjamin Herrenschmidt b ret 630fe1952fcSBenjamin Herrenschmidt 631b1ee8a3dSNicholas Piggin /* 632b1ee8a3dSNicholas Piggin * Exception where stack is already set in r1, r1 is saved in r10, and it 633b1ee8a3dSNicholas Piggin * continues rather than returns. 634b1ee8a3dSNicholas Piggin */ 635b1ee8a3dSNicholas Piggin #define EXCEPTION_COMMON_NORET_STACK(area, trap, label, hdlr, additions) \ 636b1ee8a3dSNicholas Piggin EXCEPTION_PROLOG_COMMON_1(); \ 637b1ee8a3dSNicholas Piggin EXCEPTION_PROLOG_COMMON_2(area); \ 638b1ee8a3dSNicholas Piggin EXCEPTION_PROLOG_COMMON_3(trap); \ 639b1ee8a3dSNicholas Piggin /* Volatile regs are potentially clobbered here */ \ 640b1ee8a3dSNicholas Piggin additions; \ 641b1ee8a3dSNicholas Piggin addi r3,r1,STACK_FRAME_OVERHEAD; \ 642b1ee8a3dSNicholas Piggin bl hdlr 643b1ee8a3dSNicholas Piggin 644fe1952fcSBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON(trap, label, hdlr) \ 645a3d96f70SNicholas Piggin EXCEPTION_COMMON(PACA_EXGEN, trap, label, hdlr, \ 646a3d96f70SNicholas Piggin ret_from_except, ADD_NVGPRS;ADD_RECONCILE) 6478aa34ab8SBenjamin Herrenschmidt 6488aa34ab8SBenjamin Herrenschmidt /* 6498aa34ab8SBenjamin Herrenschmidt * Like STD_EXCEPTION_COMMON, but for exceptions that can occur 6507450f6f0SBenjamin Herrenschmidt * in the idle task and therefore need the special idle handling 6517450f6f0SBenjamin Herrenschmidt * (finish nap and runlatch) 6528aa34ab8SBenjamin Herrenschmidt */ 6537450f6f0SBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON_ASYNC(trap, label, hdlr) \ 654a3d96f70SNicholas Piggin EXCEPTION_COMMON(PACA_EXGEN, trap, label, hdlr, \ 655a3d96f70SNicholas Piggin ret_from_except_lite, FINISH_NAP;ADD_RECONCILE;RUNLATCH_ON) 6568aa34ab8SBenjamin Herrenschmidt 6578aa34ab8SBenjamin Herrenschmidt /* 6588aa34ab8SBenjamin Herrenschmidt * When the idle code in power4_idle puts the CPU into NAP mode, 6598aa34ab8SBenjamin Herrenschmidt * it has to do so in a loop, and relies on the external interrupt 6608aa34ab8SBenjamin Herrenschmidt * and decrementer interrupt entry code to get it out of the loop. 6618aa34ab8SBenjamin Herrenschmidt * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags 6628aa34ab8SBenjamin Herrenschmidt * to signal that it is in the loop and needs help to get out. 6638aa34ab8SBenjamin Herrenschmidt */ 6648aa34ab8SBenjamin Herrenschmidt #ifdef CONFIG_PPC_970_NAP 6658aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP \ 6668aa34ab8SBenjamin Herrenschmidt BEGIN_FTR_SECTION \ 6679778b696SStuart Yoder CURRENT_THREAD_INFO(r11, r1); \ 6688aa34ab8SBenjamin Herrenschmidt ld r9,TI_LOCAL_FLAGS(r11); \ 6698aa34ab8SBenjamin Herrenschmidt andi. r10,r9,_TLF_NAPPING; \ 6708aa34ab8SBenjamin Herrenschmidt bnel power4_fixup_nap; \ 6718aa34ab8SBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP) 6728aa34ab8SBenjamin Herrenschmidt #else 6738aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP 6748aa34ab8SBenjamin Herrenschmidt #endif 6758aa34ab8SBenjamin Herrenschmidt 6768aa34ab8SBenjamin Herrenschmidt #endif /* _ASM_POWERPC_EXCEPTION_H */ 677