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 458aa34ab8SBenjamin Herrenschmidt #define EX_SRR0 40 468aa34ab8SBenjamin Herrenschmidt #define EX_DAR 48 478aa34ab8SBenjamin Herrenschmidt #define EX_DSISR 56 488aa34ab8SBenjamin Herrenschmidt #define EX_CCR 60 498aa34ab8SBenjamin Herrenschmidt #define EX_R3 64 508aa34ab8SBenjamin Herrenschmidt #define EX_LR 72 5148404f2eSPaul Mackerras #define EX_CFAR 80 52a09688cdSHaren Myneni #define EX_PPR 88 /* SMT thread status register (priority) */ 53bc2e6c6aSMichael Neuling #define EX_CTR 96 548aa34ab8SBenjamin Herrenschmidt 558c388514SNicholas Piggin #define EX_SIZE 13 /* size in u64 units */ 568c388514SNicholas Piggin 574700dfafSMichael Neuling #ifdef CONFIG_RELOCATABLE 581707dd16SPaul Mackerras #define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 594700dfafSMichael Neuling mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 604700dfafSMichael Neuling LOAD_HANDLER(r12,label); \ 61bc2e6c6aSMichael Neuling mtctr r12; \ 624700dfafSMichael Neuling mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 634700dfafSMichael Neuling li r10,MSR_RI; \ 644700dfafSMichael Neuling mtmsrd r10,1; /* Set RI (EE=0) */ \ 65bc2e6c6aSMichael Neuling bctr; 664700dfafSMichael Neuling #else 674700dfafSMichael Neuling /* If not relocatable, we can jump directly -- and save messing with LR */ 681707dd16SPaul Mackerras #define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 694700dfafSMichael Neuling mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 704700dfafSMichael Neuling mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 714700dfafSMichael Neuling li r10,MSR_RI; \ 724700dfafSMichael Neuling mtmsrd r10,1; /* Set RI (EE=0) */ \ 734700dfafSMichael Neuling b label; 744700dfafSMichael Neuling #endif 751707dd16SPaul Mackerras #define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 761707dd16SPaul Mackerras __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 774700dfafSMichael Neuling 784700dfafSMichael Neuling /* 794700dfafSMichael Neuling * As EXCEPTION_PROLOG_PSERIES(), except we've already got relocation on 804700dfafSMichael Neuling * so no need to rfid. Save lr in case we're CONFIG_RELOCATABLE, in which 814700dfafSMichael Neuling * case EXCEPTION_RELON_PROLOG_PSERIES_1 will be using lr. 824700dfafSMichael Neuling */ 834700dfafSMichael Neuling #define EXCEPTION_RELON_PROLOG_PSERIES(area, label, h, extra, vec) \ 841707dd16SPaul Mackerras EXCEPTION_PROLOG_0(area); \ 854700dfafSMichael Neuling EXCEPTION_PROLOG_1(area, extra, vec); \ 864700dfafSMichael Neuling EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) 874700dfafSMichael Neuling 888aa34ab8SBenjamin Herrenschmidt /* 898aa34ab8SBenjamin Herrenschmidt * We're short on space and time in the exception prolog, so we can't 9027510235SMichael Ellerman * use the normal LOAD_REG_IMMEDIATE macro to load the address of label. 9127510235SMichael Ellerman * Instead we get the base of the kernel from paca->kernelbase and or in the low 9227510235SMichael Ellerman * part of label. This requires that the label be within 64KB of kernelbase, and 9327510235SMichael Ellerman * that kernelbase be 64K aligned. 948aa34ab8SBenjamin Herrenschmidt */ 958aa34ab8SBenjamin Herrenschmidt #define LOAD_HANDLER(reg, label) \ 96d8d42b05SMichael Ellerman ld reg,PACAKBASE(r13); /* get high part of &label */ \ 97e6740ae6SHugh Dickins ori reg,reg,FIXED_SYMBOL_ABS_ADDR(label); 988aa34ab8SBenjamin Herrenschmidt 99fb479e44SNicholas Piggin #define __LOAD_HANDLER(reg, label) \ 100fb479e44SNicholas Piggin ld reg,PACAKBASE(r13); \ 101fb479e44SNicholas Piggin ori reg,reg,(ABS_ADDR(label))@l; 102fb479e44SNicholas Piggin 103a97a65d5SNicholas Piggin /* 104a97a65d5SNicholas Piggin * Branches from unrelocated code (e.g., interrupts) to labels outside 105a97a65d5SNicholas Piggin * head-y require >64K offsets. 106a97a65d5SNicholas Piggin */ 107a97a65d5SNicholas Piggin #define __LOAD_FAR_HANDLER(reg, label) \ 108a97a65d5SNicholas Piggin ld reg,PACAKBASE(r13); \ 109a97a65d5SNicholas Piggin ori reg,reg,(ABS_ADDR(label))@l; \ 110a97a65d5SNicholas Piggin addis reg,reg,(ABS_ADDR(label))@h; 111a97a65d5SNicholas Piggin 112a5d4f3adSBenjamin Herrenschmidt /* Exception register prefixes */ 113a5d4f3adSBenjamin Herrenschmidt #define EXC_HV H 114a5d4f3adSBenjamin Herrenschmidt #define EXC_STD 115a5d4f3adSBenjamin Herrenschmidt 1164700dfafSMichael Neuling #if defined(CONFIG_RELOCATABLE) 1174700dfafSMichael Neuling /* 118bc2e6c6aSMichael Neuling * If we support interrupts with relocation on AND we're a relocatable kernel, 119bc2e6c6aSMichael Neuling * we need to use CTR to get to the 2nd level handler. So, save/restore it 120bc2e6c6aSMichael Neuling * when required. 1214700dfafSMichael Neuling */ 122bc2e6c6aSMichael Neuling #define SAVE_CTR(reg, area) mfctr reg ; std reg,area+EX_CTR(r13) 123bc2e6c6aSMichael Neuling #define GET_CTR(reg, area) ld reg,area+EX_CTR(r13) 124bc2e6c6aSMichael Neuling #define RESTORE_CTR(reg, area) ld reg,area+EX_CTR(r13) ; mtctr reg 1254700dfafSMichael Neuling #else 126bc2e6c6aSMichael Neuling /* ...else CTR is unused and in register. */ 127bc2e6c6aSMichael Neuling #define SAVE_CTR(reg, area) 128bc2e6c6aSMichael Neuling #define GET_CTR(reg, area) mfctr reg 129bc2e6c6aSMichael Neuling #define RESTORE_CTR(reg, area) 1304700dfafSMichael Neuling #endif 1314700dfafSMichael Neuling 13213e7a8e8SHaren Myneni /* 13313e7a8e8SHaren Myneni * PPR save/restore macros used in exceptions_64s.S 13413e7a8e8SHaren Myneni * Used for P7 or later processors 13513e7a8e8SHaren Myneni */ 13613e7a8e8SHaren Myneni #define SAVE_PPR(area, ra, rb) \ 13713e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(940) \ 13813e7a8e8SHaren Myneni ld ra,PACACURRENT(r13); \ 13913e7a8e8SHaren Myneni ld rb,area+EX_PPR(r13); /* Read PPR from paca */ \ 14013e7a8e8SHaren Myneni std rb,TASKTHREADPPR(ra); \ 14113e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940) 14213e7a8e8SHaren Myneni 14313e7a8e8SHaren Myneni #define RESTORE_PPR_PACA(area, ra) \ 14413e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(941) \ 14513e7a8e8SHaren Myneni ld ra,area+EX_PPR(r13); \ 14613e7a8e8SHaren Myneni mtspr SPRN_PPR,ra; \ 14713e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,941) 14813e7a8e8SHaren Myneni 14913e7a8e8SHaren Myneni /* 1501707dd16SPaul Mackerras * Get an SPR into a register if the CPU has the given feature 15113e7a8e8SHaren Myneni */ 1521707dd16SPaul Mackerras #define OPT_GET_SPR(ra, spr, ftr) \ 15313e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(943) \ 1541707dd16SPaul Mackerras mfspr ra,spr; \ 1551707dd16SPaul Mackerras END_FTR_SECTION_NESTED(ftr,ftr,943) 15613e7a8e8SHaren Myneni 1571707dd16SPaul Mackerras /* 158d410ae21SMahesh Salgaonkar * Set an SPR from a register if the CPU has the given feature 159d410ae21SMahesh Salgaonkar */ 160d410ae21SMahesh Salgaonkar #define OPT_SET_SPR(ra, spr, ftr) \ 161d410ae21SMahesh Salgaonkar BEGIN_FTR_SECTION_NESTED(943) \ 162d410ae21SMahesh Salgaonkar mtspr spr,ra; \ 163d410ae21SMahesh Salgaonkar END_FTR_SECTION_NESTED(ftr,ftr,943) 164d410ae21SMahesh Salgaonkar 165d410ae21SMahesh Salgaonkar /* 1661707dd16SPaul Mackerras * Save a register to the PACA if the CPU has the given feature 1671707dd16SPaul Mackerras */ 1681707dd16SPaul Mackerras #define OPT_SAVE_REG_TO_PACA(offset, ra, ftr) \ 1691707dd16SPaul Mackerras BEGIN_FTR_SECTION_NESTED(943) \ 1701707dd16SPaul Mackerras std ra,offset(r13); \ 1711707dd16SPaul Mackerras END_FTR_SECTION_NESTED(ftr,ftr,943) 1721707dd16SPaul Mackerras 173544686caSNicholas Piggin #define EXCEPTION_PROLOG_0(area) \ 174544686caSNicholas Piggin GET_PACA(r13); \ 17544e9309fSHaren Myneni std r9,area+EX_R9(r13); /* save r9 */ \ 1761707dd16SPaul Mackerras OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR); \ 1771707dd16SPaul Mackerras HMT_MEDIUM; \ 17844e9309fSHaren Myneni std r10,area+EX_R10(r13); /* save r10 - r12 */ \ 1791707dd16SPaul Mackerras OPT_GET_SPR(r10, SPRN_CFAR, CPU_FTR_CFAR) 1801707dd16SPaul Mackerras 1811707dd16SPaul Mackerras #define __EXCEPTION_PROLOG_1(area, extra, vec) \ 1821707dd16SPaul Mackerras OPT_SAVE_REG_TO_PACA(area+EX_PPR, r9, CPU_FTR_HAS_PPR); \ 1831707dd16SPaul Mackerras OPT_SAVE_REG_TO_PACA(area+EX_CFAR, r10, CPU_FTR_CFAR); \ 184bc2e6c6aSMichael Neuling SAVE_CTR(r10, area); \ 185b01c8b54SPaul Mackerras mfcr r9; \ 186b01c8b54SPaul Mackerras extra(vec); \ 187b01c8b54SPaul Mackerras std r11,area+EX_R11(r13); \ 188b01c8b54SPaul Mackerras std r12,area+EX_R12(r13); \ 189b01c8b54SPaul Mackerras GET_SCRATCH0(r10); \ 190b01c8b54SPaul Mackerras std r10,area+EX_R13(r13) 191b01c8b54SPaul Mackerras #define EXCEPTION_PROLOG_1(area, extra, vec) \ 192b01c8b54SPaul Mackerras __EXCEPTION_PROLOG_1(area, extra, vec) 1938aa34ab8SBenjamin Herrenschmidt 194a5d4f3adSBenjamin Herrenschmidt #define __EXCEPTION_PROLOG_PSERIES_1(label, h) \ 1958aa34ab8SBenjamin Herrenschmidt ld r10,PACAKMSR(r13); /* get MSR value for kernel */ \ 196a5d4f3adSBenjamin Herrenschmidt mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 1978aa34ab8SBenjamin Herrenschmidt LOAD_HANDLER(r12,label) \ 198a5d4f3adSBenjamin Herrenschmidt mtspr SPRN_##h##SRR0,r12; \ 199a5d4f3adSBenjamin Herrenschmidt mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 200a5d4f3adSBenjamin Herrenschmidt mtspr SPRN_##h##SRR1,r10; \ 201a5d4f3adSBenjamin Herrenschmidt h##rfid; \ 2028aa34ab8SBenjamin Herrenschmidt b . /* prevent speculative execution */ 203a5d4f3adSBenjamin Herrenschmidt #define EXCEPTION_PROLOG_PSERIES_1(label, h) \ 204a5d4f3adSBenjamin Herrenschmidt __EXCEPTION_PROLOG_PSERIES_1(label, h) 2058aa34ab8SBenjamin Herrenschmidt 20683a980f7SNicholas Piggin /* _NORI variant keeps MSR_RI clear */ 20783a980f7SNicholas Piggin #define __EXCEPTION_PROLOG_PSERIES_1_NORI(label, h) \ 20883a980f7SNicholas Piggin ld r10,PACAKMSR(r13); /* get MSR value for kernel */ \ 20983a980f7SNicholas Piggin xori r10,r10,MSR_RI; /* Clear MSR_RI */ \ 21083a980f7SNicholas Piggin mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 21183a980f7SNicholas Piggin LOAD_HANDLER(r12,label) \ 21283a980f7SNicholas Piggin mtspr SPRN_##h##SRR0,r12; \ 21383a980f7SNicholas Piggin mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 21483a980f7SNicholas Piggin mtspr SPRN_##h##SRR1,r10; \ 21583a980f7SNicholas Piggin h##rfid; \ 21683a980f7SNicholas Piggin b . /* prevent speculative execution */ 21783a980f7SNicholas Piggin 21883a980f7SNicholas Piggin #define EXCEPTION_PROLOG_PSERIES_1_NORI(label, h) \ 21983a980f7SNicholas Piggin __EXCEPTION_PROLOG_PSERIES_1_NORI(label, h) 22083a980f7SNicholas Piggin 221b01c8b54SPaul Mackerras #define EXCEPTION_PROLOG_PSERIES(area, label, h, extra, vec) \ 2221707dd16SPaul Mackerras EXCEPTION_PROLOG_0(area); \ 223b01c8b54SPaul Mackerras EXCEPTION_PROLOG_1(area, extra, vec); \ 224a5d4f3adSBenjamin Herrenschmidt EXCEPTION_PROLOG_PSERIES_1(label, h); 225c5a8c0c9SBenjamin Herrenschmidt 226da2bc464SMichael Ellerman #define __KVMTEST(h, n) \ 2273c42bf8aSPaul Mackerras lbz r10,HSTATE_IN_GUEST(r13); \ 228b01c8b54SPaul Mackerras cmpwi r10,0; \ 229da2bc464SMichael Ellerman bne do_kvm_##h##n 230b01c8b54SPaul Mackerras 231dd96b2c2SAneesh Kumar K.V #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 232dd96b2c2SAneesh Kumar K.V /* 233dd96b2c2SAneesh Kumar K.V * If hv is possible, interrupts come into to the hv version 234dd96b2c2SAneesh Kumar K.V * of the kvmppc_interrupt code, which then jumps to the PR handler, 235dd96b2c2SAneesh Kumar K.V * kvmppc_interrupt_pr, if the guest is a PR guest. 236dd96b2c2SAneesh Kumar K.V */ 237dd96b2c2SAneesh Kumar K.V #define kvmppc_interrupt kvmppc_interrupt_hv 238dd96b2c2SAneesh Kumar K.V #else 239dd96b2c2SAneesh Kumar K.V #define kvmppc_interrupt kvmppc_interrupt_pr 240dd96b2c2SAneesh Kumar K.V #endif 241dd96b2c2SAneesh Kumar K.V 242b51351e2SNicholas Piggin /* 243b51351e2SNicholas Piggin * Branch to label using its 0xC000 address. This results in instruction 244b51351e2SNicholas Piggin * address suitable for MSR[IR]=0 or 1, which allows relocation to be turned 245b51351e2SNicholas Piggin * on using mtmsr rather than rfid. 246b51351e2SNicholas Piggin * 247b51351e2SNicholas Piggin * This could set the 0xc bits for !RELOCATABLE as an immediate, rather than 248b51351e2SNicholas Piggin * load KBASE for a slight optimisation. 249b51351e2SNicholas Piggin */ 250b51351e2SNicholas Piggin #define BRANCH_TO_C000(reg, label) \ 251b51351e2SNicholas Piggin __LOAD_HANDLER(reg, label); \ 252b51351e2SNicholas Piggin mtctr reg; \ 253b51351e2SNicholas Piggin bctr 254b51351e2SNicholas Piggin 255fb479e44SNicholas Piggin #ifdef CONFIG_RELOCATABLE 256fb479e44SNicholas Piggin #define BRANCH_TO_COMMON(reg, label) \ 257fb479e44SNicholas Piggin __LOAD_HANDLER(reg, label); \ 258fb479e44SNicholas Piggin mtctr reg; \ 259fb479e44SNicholas Piggin bctr 260fb479e44SNicholas Piggin 261be5c5e84SMichael Ellerman #define BRANCH_LINK_TO_FAR(label) \ 262be5c5e84SMichael Ellerman __LOAD_FAR_HANDLER(r12, label); \ 263be5c5e84SMichael Ellerman mtctr r12; \ 2642337d207SNicholas Piggin bctrl 2652337d207SNicholas Piggin 266a97a65d5SNicholas Piggin /* 267a97a65d5SNicholas Piggin * KVM requires __LOAD_FAR_HANDLER. 268a97a65d5SNicholas Piggin * 269a97a65d5SNicholas Piggin * __BRANCH_TO_KVM_EXIT branches are also a special case because they 270a97a65d5SNicholas Piggin * explicitly use r9 then reload it from PACA before branching. Hence 271a97a65d5SNicholas Piggin * the double-underscore. 272a97a65d5SNicholas Piggin */ 273a97a65d5SNicholas Piggin #define __BRANCH_TO_KVM_EXIT(area, label) \ 274a97a65d5SNicholas Piggin mfctr r9; \ 275a97a65d5SNicholas Piggin std r9,HSTATE_SCRATCH1(r13); \ 276a97a65d5SNicholas Piggin __LOAD_FAR_HANDLER(r9, label); \ 277a97a65d5SNicholas Piggin mtctr r9; \ 278a97a65d5SNicholas Piggin ld r9,area+EX_R9(r13); \ 279a97a65d5SNicholas Piggin bctr 280a97a65d5SNicholas Piggin 281fb479e44SNicholas Piggin #else 282fb479e44SNicholas Piggin #define BRANCH_TO_COMMON(reg, label) \ 283fb479e44SNicholas Piggin b label 284fb479e44SNicholas Piggin 285be5c5e84SMichael Ellerman #define BRANCH_LINK_TO_FAR(label) \ 2862337d207SNicholas Piggin bl label 2872337d207SNicholas Piggin 288a97a65d5SNicholas Piggin #define __BRANCH_TO_KVM_EXIT(area, label) \ 289a97a65d5SNicholas Piggin ld r9,area+EX_R9(r13); \ 290a97a65d5SNicholas Piggin b label 291a97a65d5SNicholas Piggin 292fb479e44SNicholas Piggin #endif 293fb479e44SNicholas Piggin 294c4f3b52cSNicholas Piggin /* Do not enable RI */ 295c4f3b52cSNicholas Piggin #define EXCEPTION_PROLOG_PSERIES_NORI(area, label, h, extra, vec) \ 296c4f3b52cSNicholas Piggin EXCEPTION_PROLOG_0(area); \ 297c4f3b52cSNicholas Piggin EXCEPTION_PROLOG_1(area, extra, vec); \ 298c4f3b52cSNicholas Piggin EXCEPTION_PROLOG_PSERIES_1_NORI(label, h); 299c4f3b52cSNicholas Piggin 300a97a65d5SNicholas Piggin 301d3918e7fSNicholas Piggin #define __KVM_HANDLER(area, h, n) \ 3020acb9111SPaul Mackerras BEGIN_FTR_SECTION_NESTED(947) \ 3030acb9111SPaul Mackerras ld r10,area+EX_CFAR(r13); \ 3040acb9111SPaul Mackerras std r10,HSTATE_CFAR(r13); \ 3050acb9111SPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_CFAR,CPU_FTR_CFAR,947); \ 3064b8473c9SPaul Mackerras BEGIN_FTR_SECTION_NESTED(948) \ 3074b8473c9SPaul Mackerras ld r10,area+EX_PPR(r13); \ 3084b8473c9SPaul Mackerras std r10,HSTATE_PPR(r13); \ 3094b8473c9SPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \ 310b01c8b54SPaul Mackerras ld r10,area+EX_R10(r13); \ 3113c42bf8aSPaul Mackerras std r12,HSTATE_SCRATCH0(r13); \ 312d3918e7fSNicholas Piggin sldi r12,r9,32; \ 313d3918e7fSNicholas Piggin ori r12,r12,(n); \ 314a97a65d5SNicholas Piggin /* This reloads r9 before branching to kvmppc_interrupt */ \ 315a97a65d5SNicholas Piggin __BRANCH_TO_KVM_EXIT(area, kvmppc_interrupt) 316b01c8b54SPaul Mackerras 317b01c8b54SPaul Mackerras #define __KVM_HANDLER_SKIP(area, h, n) \ 318b01c8b54SPaul Mackerras cmpwi r10,KVM_GUEST_MODE_SKIP; \ 319b01c8b54SPaul Mackerras beq 89f; \ 3204b8473c9SPaul Mackerras BEGIN_FTR_SECTION_NESTED(948) \ 321d3918e7fSNicholas Piggin ld r10,area+EX_PPR(r13); \ 322d3918e7fSNicholas Piggin std r10,HSTATE_PPR(r13); \ 3234b8473c9SPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \ 324d3918e7fSNicholas Piggin ld r10,area+EX_R10(r13); \ 3253c42bf8aSPaul Mackerras std r12,HSTATE_SCRATCH0(r13); \ 326d3918e7fSNicholas Piggin sldi r12,r9,32; \ 327d3918e7fSNicholas Piggin ori r12,r12,(n); \ 328a97a65d5SNicholas Piggin /* This reloads r9 before branching to kvmppc_interrupt */ \ 329a97a65d5SNicholas Piggin __BRANCH_TO_KVM_EXIT(area, kvmppc_interrupt); \ 330b01c8b54SPaul Mackerras 89: mtocrf 0x80,r9; \ 331b01c8b54SPaul Mackerras ld r9,area+EX_R9(r13); \ 332d3918e7fSNicholas Piggin ld r10,area+EX_R10(r13); \ 333b01c8b54SPaul Mackerras b kvmppc_skip_##h##interrupt 334b01c8b54SPaul Mackerras 335b01c8b54SPaul Mackerras #ifdef CONFIG_KVM_BOOK3S_64_HANDLER 336da2bc464SMichael Ellerman #define KVMTEST(h, n) __KVMTEST(h, n) 337b01c8b54SPaul Mackerras #define KVM_HANDLER(area, h, n) __KVM_HANDLER(area, h, n) 338b01c8b54SPaul Mackerras #define KVM_HANDLER_SKIP(area, h, n) __KVM_HANDLER_SKIP(area, h, n) 339b01c8b54SPaul Mackerras 340b01c8b54SPaul Mackerras #else 341da2bc464SMichael Ellerman #define KVMTEST(h, n) 342b01c8b54SPaul Mackerras #define KVM_HANDLER(area, h, n) 343b01c8b54SPaul Mackerras #define KVM_HANDLER_SKIP(area, h, n) 344b01c8b54SPaul Mackerras #endif 345b01c8b54SPaul Mackerras 346b01c8b54SPaul Mackerras #define NOTEST(n) 347b01c8b54SPaul Mackerras 348a4087a4dSNicholas Piggin #define EXCEPTION_PROLOG_COMMON_1() \ 349a4087a4dSNicholas Piggin std r9,_CCR(r1); /* save CR in stackframe */ \ 350a4087a4dSNicholas Piggin std r11,_NIP(r1); /* save SRR0 in stackframe */ \ 351a4087a4dSNicholas Piggin std r12,_MSR(r1); /* save SRR1 in stackframe */ \ 352a4087a4dSNicholas Piggin std r10,0(r1); /* make stack chain pointer */ \ 353a4087a4dSNicholas Piggin std r0,GPR0(r1); /* save r0 in stackframe */ \ 354a4087a4dSNicholas Piggin std r10,GPR1(r1); /* save r1 in stackframe */ \ 355a4087a4dSNicholas Piggin 356a4087a4dSNicholas Piggin 3578aa34ab8SBenjamin Herrenschmidt /* 3588aa34ab8SBenjamin Herrenschmidt * The common exception prolog is used for all except a few exceptions 3598aa34ab8SBenjamin Herrenschmidt * such as a segment miss on a kernel address. We have to be prepared 3608aa34ab8SBenjamin Herrenschmidt * to take another exception from the point where we first touch the 3618aa34ab8SBenjamin Herrenschmidt * kernel stack onwards. 3628aa34ab8SBenjamin Herrenschmidt * 3638aa34ab8SBenjamin Herrenschmidt * On entry r13 points to the paca, r9-r13 are saved in the paca, 3648aa34ab8SBenjamin Herrenschmidt * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and 3658aa34ab8SBenjamin Herrenschmidt * SRR1, and relocation is on. 3668aa34ab8SBenjamin Herrenschmidt */ 3678aa34ab8SBenjamin Herrenschmidt #define EXCEPTION_PROLOG_COMMON(n, area) \ 3688aa34ab8SBenjamin Herrenschmidt andi. r10,r12,MSR_PR; /* See if coming from user */ \ 3698aa34ab8SBenjamin Herrenschmidt mr r10,r1; /* Save r1 */ \ 3708aa34ab8SBenjamin Herrenschmidt subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \ 3718aa34ab8SBenjamin Herrenschmidt beq- 1f; \ 3728aa34ab8SBenjamin Herrenschmidt ld r1,PACAKSAVE(r13); /* kernel stack to use */ \ 37390ff5d68SMichael Neuling 1: cmpdi cr1,r1,-INT_FRAME_SIZE; /* check if r1 is in userspace */ \ 3741977b502SPaul Mackerras blt+ cr1,3f; /* abort if it is */ \ 3751977b502SPaul Mackerras li r1,(n); /* will be reloaded later */ \ 3768aa34ab8SBenjamin Herrenschmidt sth r1,PACA_TRAP_SAVE(r13); \ 3771977b502SPaul Mackerras std r3,area+EX_R3(r13); \ 3781977b502SPaul Mackerras addi r3,r13,area; /* r3 -> where regs are saved*/ \ 379bc2e6c6aSMichael Neuling RESTORE_CTR(r1, area); \ 3808aa34ab8SBenjamin Herrenschmidt b bad_stack; \ 381a4087a4dSNicholas Piggin 3: EXCEPTION_PROLOG_COMMON_1(); \ 3825d75b264SHaren Myneni beq 4f; /* if from kernel mode */ \ 383c223c903SChristophe Leroy ACCOUNT_CPU_USER_ENTRY(r13, r9, r10); \ 38444e9309fSHaren Myneni SAVE_PPR(area, r9, r10); \ 385b14a7253SMahesh Salgaonkar 4: EXCEPTION_PROLOG_COMMON_2(area) \ 386b14a7253SMahesh Salgaonkar EXCEPTION_PROLOG_COMMON_3(n) \ 387b14a7253SMahesh Salgaonkar ACCOUNT_STOLEN_TIME 388b14a7253SMahesh Salgaonkar 389b14a7253SMahesh Salgaonkar /* Save original regs values from save area to stack frame. */ 390b14a7253SMahesh Salgaonkar #define EXCEPTION_PROLOG_COMMON_2(area) \ 3918aa34ab8SBenjamin Herrenschmidt ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \ 3928aa34ab8SBenjamin Herrenschmidt ld r10,area+EX_R10(r13); \ 3938aa34ab8SBenjamin Herrenschmidt std r9,GPR9(r1); \ 3948aa34ab8SBenjamin Herrenschmidt std r10,GPR10(r1); \ 3958aa34ab8SBenjamin Herrenschmidt ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \ 3968aa34ab8SBenjamin Herrenschmidt ld r10,area+EX_R12(r13); \ 3978aa34ab8SBenjamin Herrenschmidt ld r11,area+EX_R13(r13); \ 3988aa34ab8SBenjamin Herrenschmidt std r9,GPR11(r1); \ 3998aa34ab8SBenjamin Herrenschmidt std r10,GPR12(r1); \ 4008aa34ab8SBenjamin Herrenschmidt std r11,GPR13(r1); \ 40148404f2eSPaul Mackerras BEGIN_FTR_SECTION_NESTED(66); \ 40248404f2eSPaul Mackerras ld r10,area+EX_CFAR(r13); \ 40348404f2eSPaul Mackerras std r10,ORIG_GPR3(r1); \ 40448404f2eSPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \ 405b14a7253SMahesh Salgaonkar GET_CTR(r10, area); \ 406b14a7253SMahesh Salgaonkar std r10,_CTR(r1); 407b14a7253SMahesh Salgaonkar 408b14a7253SMahesh Salgaonkar #define EXCEPTION_PROLOG_COMMON_3(n) \ 409b14a7253SMahesh Salgaonkar std r2,GPR2(r1); /* save r2 in stackframe */ \ 410b14a7253SMahesh Salgaonkar SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \ 411b14a7253SMahesh Salgaonkar SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \ 412bc2e6c6aSMichael Neuling mflr r9; /* Get LR, later save to stack */ \ 4138aa34ab8SBenjamin Herrenschmidt ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \ 4148aa34ab8SBenjamin Herrenschmidt std r9,_LINK(r1); \ 4158aa34ab8SBenjamin Herrenschmidt lbz r10,PACASOFTIRQEN(r13); \ 4168aa34ab8SBenjamin Herrenschmidt mfspr r11,SPRN_XER; /* save XER in stackframe */ \ 4178aa34ab8SBenjamin Herrenschmidt std r10,SOFTE(r1); \ 4188aa34ab8SBenjamin Herrenschmidt std r11,_XER(r1); \ 4198aa34ab8SBenjamin Herrenschmidt li r9,(n)+1; \ 4208aa34ab8SBenjamin Herrenschmidt std r9,_TRAP(r1); /* set trap number */ \ 4218aa34ab8SBenjamin Herrenschmidt li r10,0; \ 4228aa34ab8SBenjamin Herrenschmidt ld r11,exception_marker@toc(r2); \ 4238aa34ab8SBenjamin Herrenschmidt std r10,RESULT(r1); /* clear regs->result */ \ 424b14a7253SMahesh Salgaonkar std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */ 4258aa34ab8SBenjamin Herrenschmidt 4268aa34ab8SBenjamin Herrenschmidt /* 4278aa34ab8SBenjamin Herrenschmidt * Exception vectors. 4288aa34ab8SBenjamin Herrenschmidt */ 4292613265cSMichael Ellerman #define STD_EXCEPTION_PSERIES(vec, label) \ 430673b189aSPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 431da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \ 432da2bc464SMichael Ellerman EXC_STD, KVMTEST_PR, vec); \ 4338aa34ab8SBenjamin Herrenschmidt 4341707dd16SPaul Mackerras /* Version of above for when we have to branch out-of-line */ 435da2bc464SMichael Ellerman #define __OOL_EXCEPTION(vec, label, hdlr) \ 436da2bc464SMichael Ellerman SET_SCRATCH0(r13) \ 437da2bc464SMichael Ellerman EXCEPTION_PROLOG_0(PACA_EXGEN) \ 438da2bc464SMichael Ellerman b hdlr; 439da2bc464SMichael Ellerman 4401707dd16SPaul Mackerras #define STD_EXCEPTION_PSERIES_OOL(vec, label) \ 441da2bc464SMichael Ellerman EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_PR, vec); \ 442da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD) 4431707dd16SPaul Mackerras 444b3e6b5dfSBenjamin Herrenschmidt #define STD_EXCEPTION_HV(loc, vec, label) \ 445673b189aSPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 446da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \ 447da2bc464SMichael Ellerman EXC_HV, KVMTEST_HV, vec); 4488aa34ab8SBenjamin Herrenschmidt 4491707dd16SPaul Mackerras #define STD_EXCEPTION_HV_OOL(vec, label) \ 450da2bc464SMichael Ellerman EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \ 451da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV) 4521707dd16SPaul Mackerras 4534700dfafSMichael Neuling #define STD_RELON_EXCEPTION_PSERIES(loc, vec, label) \ 4544700dfafSMichael Neuling /* No guest interrupts come through here */ \ 4554700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 456da2bc464SMichael Ellerman EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, EXC_STD, NOTEST, vec); 4574700dfafSMichael Neuling 4581707dd16SPaul Mackerras #define STD_RELON_EXCEPTION_PSERIES_OOL(vec, label) \ 459c9f69518SMichael Ellerman EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, vec); \ 460da2bc464SMichael Ellerman EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_STD) 4611707dd16SPaul Mackerras 4624700dfafSMichael Neuling #define STD_RELON_EXCEPTION_HV(loc, vec, label) \ 4634700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 464bc355125SPaul Mackerras EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, \ 465bc355125SPaul Mackerras EXC_HV, KVMTEST_HV, vec); 4664700dfafSMichael Neuling 4671707dd16SPaul Mackerras #define STD_RELON_EXCEPTION_HV_OOL(vec, label) \ 468bc355125SPaul Mackerras EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \ 469da2bc464SMichael Ellerman EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV) 4701707dd16SPaul Mackerras 4717230c564SBenjamin Herrenschmidt /* This associate vector numbers with bits in paca->irq_happened */ 4727230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x500 PACA_IRQ_EE 4737230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x900 PACA_IRQ_DEC 474da2bc464SMichael Ellerman #define SOFTEN_VALUE_0x980 PACA_IRQ_DEC 4751dbdafecSIan Munsie #define SOFTEN_VALUE_0xa00 PACA_IRQ_DBELL 476655bb3f4SIan Munsie #define SOFTEN_VALUE_0xe80 PACA_IRQ_DBELL 4770869b6fdSMahesh Salgaonkar #define SOFTEN_VALUE_0xe60 PACA_IRQ_HMI 4789baaef0aSBenjamin Herrenschmidt #define SOFTEN_VALUE_0xea0 PACA_IRQ_EE 4797230c564SBenjamin Herrenschmidt 4807230c564SBenjamin Herrenschmidt #define __SOFTEN_TEST(h, vec) \ 4818aa34ab8SBenjamin Herrenschmidt lbz r10,PACASOFTIRQEN(r13); \ 4828aa34ab8SBenjamin Herrenschmidt cmpwi r10,0; \ 4837230c564SBenjamin Herrenschmidt li r10,SOFTEN_VALUE_##vec; \ 484b01c8b54SPaul Mackerras beq masked_##h##interrupt 485da2bc464SMichael Ellerman 4867230c564SBenjamin Herrenschmidt #define _SOFTEN_TEST(h, vec) __SOFTEN_TEST(h, vec) 487b01c8b54SPaul Mackerras 488de56a948SPaul Mackerras #define SOFTEN_TEST_PR(vec) \ 489da2bc464SMichael Ellerman KVMTEST(EXC_STD, vec); \ 4907230c564SBenjamin Herrenschmidt _SOFTEN_TEST(EXC_STD, vec) 491b01c8b54SPaul Mackerras 492b01c8b54SPaul Mackerras #define SOFTEN_TEST_HV(vec) \ 493da2bc464SMichael Ellerman KVMTEST(EXC_HV, vec); \ 4947230c564SBenjamin Herrenschmidt _SOFTEN_TEST(EXC_HV, vec) 495b01c8b54SPaul Mackerras 496da2bc464SMichael Ellerman #define KVMTEST_PR(vec) \ 497da2bc464SMichael Ellerman KVMTEST(EXC_STD, vec) 498da2bc464SMichael Ellerman 499da2bc464SMichael Ellerman #define KVMTEST_HV(vec) \ 500da2bc464SMichael Ellerman KVMTEST(EXC_HV, vec) 501da2bc464SMichael Ellerman 5024700dfafSMichael Neuling #define SOFTEN_NOTEST_PR(vec) _SOFTEN_TEST(EXC_STD, vec) 5034700dfafSMichael Neuling #define SOFTEN_NOTEST_HV(vec) _SOFTEN_TEST(EXC_HV, vec) 5044700dfafSMichael Neuling 505b01c8b54SPaul Mackerras #define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \ 506b01c8b54SPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 5071707dd16SPaul Mackerras EXCEPTION_PROLOG_0(PACA_EXGEN); \ 508b01c8b54SPaul Mackerras __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \ 509da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES_1(label, h); 5101707dd16SPaul Mackerras 511b01c8b54SPaul Mackerras #define _MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \ 512b01c8b54SPaul Mackerras __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) 513b3e6b5dfSBenjamin Herrenschmidt 514b3e6b5dfSBenjamin Herrenschmidt #define MASKABLE_EXCEPTION_PSERIES(loc, vec, label) \ 515b01c8b54SPaul Mackerras _MASKABLE_EXCEPTION_PSERIES(vec, label, \ 516de56a948SPaul Mackerras EXC_STD, SOFTEN_TEST_PR) 517b3e6b5dfSBenjamin Herrenschmidt 518da2bc464SMichael Ellerman #define MASKABLE_EXCEPTION_PSERIES_OOL(vec, label) \ 519da2bc464SMichael Ellerman EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_PR, vec); \ 520da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD) 521da2bc464SMichael Ellerman 522b3e6b5dfSBenjamin Herrenschmidt #define MASKABLE_EXCEPTION_HV(loc, vec, label) \ 523b01c8b54SPaul Mackerras _MASKABLE_EXCEPTION_PSERIES(vec, label, \ 524b01c8b54SPaul Mackerras EXC_HV, SOFTEN_TEST_HV) 5258aa34ab8SBenjamin Herrenschmidt 5261707dd16SPaul Mackerras #define MASKABLE_EXCEPTION_HV_OOL(vec, label) \ 5271707dd16SPaul Mackerras EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec); \ 528da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV) 5291707dd16SPaul Mackerras 5304700dfafSMichael Neuling #define __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \ 5314700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 5321707dd16SPaul Mackerras EXCEPTION_PROLOG_0(PACA_EXGEN); \ 5334700dfafSMichael Neuling __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \ 534da2bc464SMichael Ellerman EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) 535da2bc464SMichael Ellerman 5364700dfafSMichael Neuling #define _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \ 5374700dfafSMichael Neuling __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) 5384700dfafSMichael Neuling 5394700dfafSMichael Neuling #define MASKABLE_RELON_EXCEPTION_PSERIES(loc, vec, label) \ 5404700dfafSMichael Neuling _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \ 5414700dfafSMichael Neuling EXC_STD, SOFTEN_NOTEST_PR) 5424700dfafSMichael Neuling 5434700dfafSMichael Neuling #define MASKABLE_RELON_EXCEPTION_HV(loc, vec, label) \ 5444700dfafSMichael Neuling _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \ 545bc355125SPaul Mackerras EXC_HV, SOFTEN_TEST_HV) 5464700dfafSMichael Neuling 5471707dd16SPaul Mackerras #define MASKABLE_RELON_EXCEPTION_HV_OOL(vec, label) \ 548bc355125SPaul Mackerras EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec); \ 549a050d20dSNicholas Piggin EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV) 5501707dd16SPaul Mackerras 5511b701179SBenjamin Herrenschmidt /* 5521b701179SBenjamin Herrenschmidt * Our exception common code can be passed various "additions" 5531b701179SBenjamin Herrenschmidt * to specify the behaviour of interrupts, whether to kick the 5541b701179SBenjamin Herrenschmidt * runlatch, etc... 5551b701179SBenjamin Herrenschmidt */ 5561b701179SBenjamin Herrenschmidt 5579daf112bSMichael Ellerman /* 5589daf112bSMichael Ellerman * This addition reconciles our actual IRQ state with the various software 5599daf112bSMichael Ellerman * flags that track it. This may call C code. 5609daf112bSMichael Ellerman */ 5619daf112bSMichael Ellerman #define ADD_RECONCILE RECONCILE_IRQ_STATE(r10,r11) 5628aa34ab8SBenjamin Herrenschmidt 563fe1952fcSBenjamin Herrenschmidt #define ADD_NVGPRS \ 564b1576fecSAnton Blanchard bl save_nvgprs 565fe1952fcSBenjamin Herrenschmidt 566fe1952fcSBenjamin Herrenschmidt #define RUNLATCH_ON \ 567fe1952fcSBenjamin Herrenschmidt BEGIN_FTR_SECTION \ 5689778b696SStuart Yoder CURRENT_THREAD_INFO(r3, r1); \ 569fe1952fcSBenjamin Herrenschmidt ld r4,TI_LOCAL_FLAGS(r3); \ 570fe1952fcSBenjamin Herrenschmidt andi. r0,r4,_TLF_RUNLATCH; \ 571fe1952fcSBenjamin Herrenschmidt beql ppc64_runlatch_on_trampoline; \ 572fe1952fcSBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CTRL) 573fe1952fcSBenjamin Herrenschmidt 574a3d96f70SNicholas Piggin #define EXCEPTION_COMMON(area, trap, label, hdlr, ret, additions) \ 575a3d96f70SNicholas Piggin EXCEPTION_PROLOG_COMMON(trap, area); \ 576a1d711c5SMichael Ellerman /* Volatile regs are potentially clobbered here */ \ 577fe1952fcSBenjamin Herrenschmidt additions; \ 5788aa34ab8SBenjamin Herrenschmidt addi r3,r1,STACK_FRAME_OVERHEAD; \ 5798aa34ab8SBenjamin Herrenschmidt bl hdlr; \ 580fe1952fcSBenjamin Herrenschmidt b ret 581fe1952fcSBenjamin Herrenschmidt 582b1ee8a3dSNicholas Piggin /* 583b1ee8a3dSNicholas Piggin * Exception where stack is already set in r1, r1 is saved in r10, and it 584b1ee8a3dSNicholas Piggin * continues rather than returns. 585b1ee8a3dSNicholas Piggin */ 586b1ee8a3dSNicholas Piggin #define EXCEPTION_COMMON_NORET_STACK(area, trap, label, hdlr, additions) \ 587b1ee8a3dSNicholas Piggin EXCEPTION_PROLOG_COMMON_1(); \ 588b1ee8a3dSNicholas Piggin EXCEPTION_PROLOG_COMMON_2(area); \ 589b1ee8a3dSNicholas Piggin EXCEPTION_PROLOG_COMMON_3(trap); \ 590b1ee8a3dSNicholas Piggin /* Volatile regs are potentially clobbered here */ \ 591b1ee8a3dSNicholas Piggin additions; \ 592b1ee8a3dSNicholas Piggin addi r3,r1,STACK_FRAME_OVERHEAD; \ 593b1ee8a3dSNicholas Piggin bl hdlr 594b1ee8a3dSNicholas Piggin 595fe1952fcSBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON(trap, label, hdlr) \ 596a3d96f70SNicholas Piggin EXCEPTION_COMMON(PACA_EXGEN, trap, label, hdlr, \ 597a3d96f70SNicholas Piggin ret_from_except, ADD_NVGPRS;ADD_RECONCILE) 5988aa34ab8SBenjamin Herrenschmidt 5998aa34ab8SBenjamin Herrenschmidt /* 6008aa34ab8SBenjamin Herrenschmidt * Like STD_EXCEPTION_COMMON, but for exceptions that can occur 6017450f6f0SBenjamin Herrenschmidt * in the idle task and therefore need the special idle handling 6027450f6f0SBenjamin Herrenschmidt * (finish nap and runlatch) 6038aa34ab8SBenjamin Herrenschmidt */ 6047450f6f0SBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON_ASYNC(trap, label, hdlr) \ 605a3d96f70SNicholas Piggin EXCEPTION_COMMON(PACA_EXGEN, trap, label, hdlr, \ 606a3d96f70SNicholas Piggin ret_from_except_lite, FINISH_NAP;ADD_RECONCILE;RUNLATCH_ON) 6078aa34ab8SBenjamin Herrenschmidt 6088aa34ab8SBenjamin Herrenschmidt /* 6098aa34ab8SBenjamin Herrenschmidt * When the idle code in power4_idle puts the CPU into NAP mode, 6108aa34ab8SBenjamin Herrenschmidt * it has to do so in a loop, and relies on the external interrupt 6118aa34ab8SBenjamin Herrenschmidt * and decrementer interrupt entry code to get it out of the loop. 6128aa34ab8SBenjamin Herrenschmidt * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags 6138aa34ab8SBenjamin Herrenschmidt * to signal that it is in the loop and needs help to get out. 6148aa34ab8SBenjamin Herrenschmidt */ 6158aa34ab8SBenjamin Herrenschmidt #ifdef CONFIG_PPC_970_NAP 6168aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP \ 6178aa34ab8SBenjamin Herrenschmidt BEGIN_FTR_SECTION \ 6189778b696SStuart Yoder CURRENT_THREAD_INFO(r11, r1); \ 6198aa34ab8SBenjamin Herrenschmidt ld r9,TI_LOCAL_FLAGS(r11); \ 6208aa34ab8SBenjamin Herrenschmidt andi. r10,r9,_TLF_NAPPING; \ 6218aa34ab8SBenjamin Herrenschmidt bnel power4_fixup_nap; \ 6228aa34ab8SBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP) 6238aa34ab8SBenjamin Herrenschmidt #else 6248aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP 6258aa34ab8SBenjamin Herrenschmidt #endif 6268aa34ab8SBenjamin Herrenschmidt 6278aa34ab8SBenjamin Herrenschmidt #endif /* _ASM_POWERPC_EXCEPTION_H */ 628