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 /* 58dbeea1d6SNicholas Piggin * EX_LR is only used in EXSLB and where it does not overlap with EX_DAR 59dbeea1d6SNicholas Piggin * EX_CCR similarly with DSISR, but being 4 byte registers there is a hole 60dbeea1d6SNicholas Piggin * in the save area so it's not necessary to overlap them. Could be used 61dbeea1d6SNicholas Piggin * for future savings though if another 4 byte register was to be saved. 62dbeea1d6SNicholas Piggin */ 63dbeea1d6SNicholas Piggin #define EX_LR EX_DAR 648c388514SNicholas Piggin 65635942aeSNicholas Piggin /* 66635942aeSNicholas Piggin * EX_R3 is only used by the bad_stack handler. bad_stack reloads and 67635942aeSNicholas Piggin * saves DAR from SPRN_DAR, and EX_DAR is not used. So EX_R3 can overlap 68635942aeSNicholas Piggin * with EX_DAR. 69635942aeSNicholas Piggin */ 70635942aeSNicholas Piggin #define EX_R3 EX_DAR 71635942aeSNicholas Piggin 724700dfafSMichael Neuling #ifdef CONFIG_RELOCATABLE 731707dd16SPaul Mackerras #define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 744700dfafSMichael Neuling mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 754700dfafSMichael Neuling LOAD_HANDLER(r12,label); \ 76bc2e6c6aSMichael Neuling mtctr r12; \ 774700dfafSMichael Neuling mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 784700dfafSMichael Neuling li r10,MSR_RI; \ 794700dfafSMichael Neuling mtmsrd r10,1; /* Set RI (EE=0) */ \ 80bc2e6c6aSMichael Neuling bctr; 814700dfafSMichael Neuling #else 824700dfafSMichael Neuling /* If not relocatable, we can jump directly -- and save messing with LR */ 831707dd16SPaul Mackerras #define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 844700dfafSMichael Neuling mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 854700dfafSMichael Neuling mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 864700dfafSMichael Neuling li r10,MSR_RI; \ 874700dfafSMichael Neuling mtmsrd r10,1; /* Set RI (EE=0) */ \ 884700dfafSMichael Neuling b label; 894700dfafSMichael Neuling #endif 901707dd16SPaul Mackerras #define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 911707dd16SPaul Mackerras __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ 924700dfafSMichael Neuling 934700dfafSMichael Neuling /* 944700dfafSMichael Neuling * As EXCEPTION_PROLOG_PSERIES(), except we've already got relocation on 954700dfafSMichael Neuling * so no need to rfid. Save lr in case we're CONFIG_RELOCATABLE, in which 964700dfafSMichael Neuling * case EXCEPTION_RELON_PROLOG_PSERIES_1 will be using lr. 974700dfafSMichael Neuling */ 984700dfafSMichael Neuling #define EXCEPTION_RELON_PROLOG_PSERIES(area, label, h, extra, vec) \ 991707dd16SPaul Mackerras EXCEPTION_PROLOG_0(area); \ 1004700dfafSMichael Neuling EXCEPTION_PROLOG_1(area, extra, vec); \ 1014700dfafSMichael Neuling EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) 1024700dfafSMichael Neuling 1038aa34ab8SBenjamin Herrenschmidt /* 1048aa34ab8SBenjamin Herrenschmidt * We're short on space and time in the exception prolog, so we can't 10527510235SMichael Ellerman * use the normal LOAD_REG_IMMEDIATE macro to load the address of label. 10627510235SMichael Ellerman * Instead we get the base of the kernel from paca->kernelbase and or in the low 10727510235SMichael Ellerman * part of label. This requires that the label be within 64KB of kernelbase, and 10827510235SMichael Ellerman * that kernelbase be 64K aligned. 1098aa34ab8SBenjamin Herrenschmidt */ 1108aa34ab8SBenjamin Herrenschmidt #define LOAD_HANDLER(reg, label) \ 111d8d42b05SMichael Ellerman ld reg,PACAKBASE(r13); /* get high part of &label */ \ 112e6740ae6SHugh Dickins ori reg,reg,FIXED_SYMBOL_ABS_ADDR(label); 1138aa34ab8SBenjamin Herrenschmidt 114fb479e44SNicholas Piggin #define __LOAD_HANDLER(reg, label) \ 115fb479e44SNicholas Piggin ld reg,PACAKBASE(r13); \ 116fb479e44SNicholas Piggin ori reg,reg,(ABS_ADDR(label))@l; 117fb479e44SNicholas Piggin 118a97a65d5SNicholas Piggin /* 119a97a65d5SNicholas Piggin * Branches from unrelocated code (e.g., interrupts) to labels outside 120a97a65d5SNicholas Piggin * head-y require >64K offsets. 121a97a65d5SNicholas Piggin */ 122a97a65d5SNicholas Piggin #define __LOAD_FAR_HANDLER(reg, label) \ 123a97a65d5SNicholas Piggin ld reg,PACAKBASE(r13); \ 124a97a65d5SNicholas Piggin ori reg,reg,(ABS_ADDR(label))@l; \ 125a97a65d5SNicholas Piggin addis reg,reg,(ABS_ADDR(label))@h; 126a97a65d5SNicholas Piggin 127a5d4f3adSBenjamin Herrenschmidt /* Exception register prefixes */ 128a5d4f3adSBenjamin Herrenschmidt #define EXC_HV H 129a5d4f3adSBenjamin Herrenschmidt #define EXC_STD 130a5d4f3adSBenjamin Herrenschmidt 1314700dfafSMichael Neuling #if defined(CONFIG_RELOCATABLE) 1324700dfafSMichael Neuling /* 133bc2e6c6aSMichael Neuling * If we support interrupts with relocation on AND we're a relocatable kernel, 134bc2e6c6aSMichael Neuling * we need to use CTR to get to the 2nd level handler. So, save/restore it 135bc2e6c6aSMichael Neuling * when required. 1364700dfafSMichael Neuling */ 137bc2e6c6aSMichael Neuling #define SAVE_CTR(reg, area) mfctr reg ; std reg,area+EX_CTR(r13) 138bc2e6c6aSMichael Neuling #define GET_CTR(reg, area) ld reg,area+EX_CTR(r13) 139bc2e6c6aSMichael Neuling #define RESTORE_CTR(reg, area) ld reg,area+EX_CTR(r13) ; mtctr reg 1404700dfafSMichael Neuling #else 141bc2e6c6aSMichael Neuling /* ...else CTR is unused and in register. */ 142bc2e6c6aSMichael Neuling #define SAVE_CTR(reg, area) 143bc2e6c6aSMichael Neuling #define GET_CTR(reg, area) mfctr reg 144bc2e6c6aSMichael Neuling #define RESTORE_CTR(reg, area) 1454700dfafSMichael Neuling #endif 1464700dfafSMichael Neuling 14713e7a8e8SHaren Myneni /* 14813e7a8e8SHaren Myneni * PPR save/restore macros used in exceptions_64s.S 14913e7a8e8SHaren Myneni * Used for P7 or later processors 15013e7a8e8SHaren Myneni */ 15113e7a8e8SHaren Myneni #define SAVE_PPR(area, ra, rb) \ 15213e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(940) \ 15313e7a8e8SHaren Myneni ld ra,PACACURRENT(r13); \ 15413e7a8e8SHaren Myneni ld rb,area+EX_PPR(r13); /* Read PPR from paca */ \ 15513e7a8e8SHaren Myneni std rb,TASKTHREADPPR(ra); \ 15613e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940) 15713e7a8e8SHaren Myneni 15813e7a8e8SHaren Myneni #define RESTORE_PPR_PACA(area, ra) \ 15913e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(941) \ 16013e7a8e8SHaren Myneni ld ra,area+EX_PPR(r13); \ 16113e7a8e8SHaren Myneni mtspr SPRN_PPR,ra; \ 16213e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,941) 16313e7a8e8SHaren Myneni 16413e7a8e8SHaren Myneni /* 1651707dd16SPaul Mackerras * Get an SPR into a register if the CPU has the given feature 16613e7a8e8SHaren Myneni */ 1671707dd16SPaul Mackerras #define OPT_GET_SPR(ra, spr, ftr) \ 16813e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(943) \ 1691707dd16SPaul Mackerras mfspr ra,spr; \ 1701707dd16SPaul Mackerras END_FTR_SECTION_NESTED(ftr,ftr,943) 17113e7a8e8SHaren Myneni 1721707dd16SPaul Mackerras /* 173d410ae21SMahesh Salgaonkar * Set an SPR from a register if the CPU has the given feature 174d410ae21SMahesh Salgaonkar */ 175d410ae21SMahesh Salgaonkar #define OPT_SET_SPR(ra, spr, ftr) \ 176d410ae21SMahesh Salgaonkar BEGIN_FTR_SECTION_NESTED(943) \ 177d410ae21SMahesh Salgaonkar mtspr spr,ra; \ 178d410ae21SMahesh Salgaonkar END_FTR_SECTION_NESTED(ftr,ftr,943) 179d410ae21SMahesh Salgaonkar 180d410ae21SMahesh Salgaonkar /* 1811707dd16SPaul Mackerras * Save a register to the PACA if the CPU has the given feature 1821707dd16SPaul Mackerras */ 1831707dd16SPaul Mackerras #define OPT_SAVE_REG_TO_PACA(offset, ra, ftr) \ 1841707dd16SPaul Mackerras BEGIN_FTR_SECTION_NESTED(943) \ 1851707dd16SPaul Mackerras std ra,offset(r13); \ 1861707dd16SPaul Mackerras END_FTR_SECTION_NESTED(ftr,ftr,943) 1871707dd16SPaul Mackerras 188544686caSNicholas Piggin #define EXCEPTION_PROLOG_0(area) \ 189544686caSNicholas Piggin GET_PACA(r13); \ 19044e9309fSHaren Myneni std r9,area+EX_R9(r13); /* save r9 */ \ 1911707dd16SPaul Mackerras OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR); \ 1921707dd16SPaul Mackerras HMT_MEDIUM; \ 19344e9309fSHaren Myneni std r10,area+EX_R10(r13); /* save r10 - r12 */ \ 1941707dd16SPaul Mackerras OPT_GET_SPR(r10, SPRN_CFAR, CPU_FTR_CFAR) 1951707dd16SPaul Mackerras 1961707dd16SPaul Mackerras #define __EXCEPTION_PROLOG_1(area, extra, vec) \ 1971707dd16SPaul Mackerras OPT_SAVE_REG_TO_PACA(area+EX_PPR, r9, CPU_FTR_HAS_PPR); \ 1981707dd16SPaul Mackerras OPT_SAVE_REG_TO_PACA(area+EX_CFAR, r10, CPU_FTR_CFAR); \ 199bc2e6c6aSMichael Neuling SAVE_CTR(r10, area); \ 200b01c8b54SPaul Mackerras mfcr r9; \ 201b01c8b54SPaul Mackerras extra(vec); \ 202b01c8b54SPaul Mackerras std r11,area+EX_R11(r13); \ 203b01c8b54SPaul Mackerras std r12,area+EX_R12(r13); \ 204b01c8b54SPaul Mackerras GET_SCRATCH0(r10); \ 205b01c8b54SPaul Mackerras std r10,area+EX_R13(r13) 206b01c8b54SPaul Mackerras #define EXCEPTION_PROLOG_1(area, extra, vec) \ 207b01c8b54SPaul Mackerras __EXCEPTION_PROLOG_1(area, extra, vec) 2088aa34ab8SBenjamin Herrenschmidt 209a5d4f3adSBenjamin Herrenschmidt #define __EXCEPTION_PROLOG_PSERIES_1(label, h) \ 2108aa34ab8SBenjamin Herrenschmidt ld r10,PACAKMSR(r13); /* get MSR value for kernel */ \ 211a5d4f3adSBenjamin Herrenschmidt mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 2128aa34ab8SBenjamin Herrenschmidt LOAD_HANDLER(r12,label) \ 213a5d4f3adSBenjamin Herrenschmidt mtspr SPRN_##h##SRR0,r12; \ 214a5d4f3adSBenjamin Herrenschmidt mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 215a5d4f3adSBenjamin Herrenschmidt mtspr SPRN_##h##SRR1,r10; \ 216a5d4f3adSBenjamin Herrenschmidt h##rfid; \ 2178aa34ab8SBenjamin Herrenschmidt b . /* prevent speculative execution */ 218a5d4f3adSBenjamin Herrenschmidt #define EXCEPTION_PROLOG_PSERIES_1(label, h) \ 219a5d4f3adSBenjamin Herrenschmidt __EXCEPTION_PROLOG_PSERIES_1(label, h) 2208aa34ab8SBenjamin Herrenschmidt 22183a980f7SNicholas Piggin /* _NORI variant keeps MSR_RI clear */ 22283a980f7SNicholas Piggin #define __EXCEPTION_PROLOG_PSERIES_1_NORI(label, h) \ 22383a980f7SNicholas Piggin ld r10,PACAKMSR(r13); /* get MSR value for kernel */ \ 22483a980f7SNicholas Piggin xori r10,r10,MSR_RI; /* Clear MSR_RI */ \ 22583a980f7SNicholas Piggin mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ 22683a980f7SNicholas Piggin LOAD_HANDLER(r12,label) \ 22783a980f7SNicholas Piggin mtspr SPRN_##h##SRR0,r12; \ 22883a980f7SNicholas Piggin mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ 22983a980f7SNicholas Piggin mtspr SPRN_##h##SRR1,r10; \ 23083a980f7SNicholas Piggin h##rfid; \ 23183a980f7SNicholas Piggin b . /* prevent speculative execution */ 23283a980f7SNicholas Piggin 23383a980f7SNicholas Piggin #define EXCEPTION_PROLOG_PSERIES_1_NORI(label, h) \ 23483a980f7SNicholas Piggin __EXCEPTION_PROLOG_PSERIES_1_NORI(label, h) 23583a980f7SNicholas Piggin 236b01c8b54SPaul Mackerras #define EXCEPTION_PROLOG_PSERIES(area, label, h, extra, vec) \ 2371707dd16SPaul Mackerras EXCEPTION_PROLOG_0(area); \ 238b01c8b54SPaul Mackerras EXCEPTION_PROLOG_1(area, extra, vec); \ 239a5d4f3adSBenjamin Herrenschmidt EXCEPTION_PROLOG_PSERIES_1(label, h); 240c5a8c0c9SBenjamin Herrenschmidt 241da2bc464SMichael Ellerman #define __KVMTEST(h, n) \ 2423c42bf8aSPaul Mackerras lbz r10,HSTATE_IN_GUEST(r13); \ 243b01c8b54SPaul Mackerras cmpwi r10,0; \ 244da2bc464SMichael Ellerman bne do_kvm_##h##n 245b01c8b54SPaul Mackerras 246dd96b2c2SAneesh Kumar K.V #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 247dd96b2c2SAneesh Kumar K.V /* 248dd96b2c2SAneesh Kumar K.V * If hv is possible, interrupts come into to the hv version 249dd96b2c2SAneesh Kumar K.V * of the kvmppc_interrupt code, which then jumps to the PR handler, 250dd96b2c2SAneesh Kumar K.V * kvmppc_interrupt_pr, if the guest is a PR guest. 251dd96b2c2SAneesh Kumar K.V */ 252dd96b2c2SAneesh Kumar K.V #define kvmppc_interrupt kvmppc_interrupt_hv 253dd96b2c2SAneesh Kumar K.V #else 254dd96b2c2SAneesh Kumar K.V #define kvmppc_interrupt kvmppc_interrupt_pr 255dd96b2c2SAneesh Kumar K.V #endif 256dd96b2c2SAneesh Kumar K.V 257b51351e2SNicholas Piggin /* 258b51351e2SNicholas Piggin * Branch to label using its 0xC000 address. This results in instruction 259b51351e2SNicholas Piggin * address suitable for MSR[IR]=0 or 1, which allows relocation to be turned 260b51351e2SNicholas Piggin * on using mtmsr rather than rfid. 261b51351e2SNicholas Piggin * 262b51351e2SNicholas Piggin * This could set the 0xc bits for !RELOCATABLE as an immediate, rather than 263b51351e2SNicholas Piggin * load KBASE for a slight optimisation. 264b51351e2SNicholas Piggin */ 265b51351e2SNicholas Piggin #define BRANCH_TO_C000(reg, label) \ 266b51351e2SNicholas Piggin __LOAD_HANDLER(reg, label); \ 267b51351e2SNicholas Piggin mtctr reg; \ 268b51351e2SNicholas Piggin bctr 269b51351e2SNicholas Piggin 270fb479e44SNicholas Piggin #ifdef CONFIG_RELOCATABLE 271fb479e44SNicholas Piggin #define BRANCH_TO_COMMON(reg, label) \ 272fb479e44SNicholas Piggin __LOAD_HANDLER(reg, label); \ 273fb479e44SNicholas Piggin mtctr reg; \ 274fb479e44SNicholas Piggin bctr 275fb479e44SNicholas Piggin 276be5c5e84SMichael Ellerman #define BRANCH_LINK_TO_FAR(label) \ 277be5c5e84SMichael Ellerman __LOAD_FAR_HANDLER(r12, label); \ 278be5c5e84SMichael Ellerman mtctr r12; \ 2792337d207SNicholas Piggin bctrl 2802337d207SNicholas Piggin 281a97a65d5SNicholas Piggin /* 282a97a65d5SNicholas Piggin * KVM requires __LOAD_FAR_HANDLER. 283a97a65d5SNicholas Piggin * 284a97a65d5SNicholas Piggin * __BRANCH_TO_KVM_EXIT branches are also a special case because they 285a97a65d5SNicholas Piggin * explicitly use r9 then reload it from PACA before branching. Hence 286a97a65d5SNicholas Piggin * the double-underscore. 287a97a65d5SNicholas Piggin */ 288a97a65d5SNicholas Piggin #define __BRANCH_TO_KVM_EXIT(area, label) \ 289a97a65d5SNicholas Piggin mfctr r9; \ 290a97a65d5SNicholas Piggin std r9,HSTATE_SCRATCH1(r13); \ 291a97a65d5SNicholas Piggin __LOAD_FAR_HANDLER(r9, label); \ 292a97a65d5SNicholas Piggin mtctr r9; \ 293a97a65d5SNicholas Piggin ld r9,area+EX_R9(r13); \ 294a97a65d5SNicholas Piggin bctr 295a97a65d5SNicholas Piggin 296fb479e44SNicholas Piggin #else 297fb479e44SNicholas Piggin #define BRANCH_TO_COMMON(reg, label) \ 298fb479e44SNicholas Piggin b label 299fb479e44SNicholas Piggin 300be5c5e84SMichael Ellerman #define BRANCH_LINK_TO_FAR(label) \ 3012337d207SNicholas Piggin bl label 3022337d207SNicholas Piggin 303a97a65d5SNicholas Piggin #define __BRANCH_TO_KVM_EXIT(area, label) \ 304a97a65d5SNicholas Piggin ld r9,area+EX_R9(r13); \ 305a97a65d5SNicholas Piggin b label 306a97a65d5SNicholas Piggin 307fb479e44SNicholas Piggin #endif 308fb479e44SNicholas Piggin 309c4f3b52cSNicholas Piggin /* Do not enable RI */ 310c4f3b52cSNicholas Piggin #define EXCEPTION_PROLOG_PSERIES_NORI(area, label, h, extra, vec) \ 311c4f3b52cSNicholas Piggin EXCEPTION_PROLOG_0(area); \ 312c4f3b52cSNicholas Piggin EXCEPTION_PROLOG_1(area, extra, vec); \ 313c4f3b52cSNicholas Piggin EXCEPTION_PROLOG_PSERIES_1_NORI(label, h); 314c4f3b52cSNicholas Piggin 315a97a65d5SNicholas Piggin 316d3918e7fSNicholas Piggin #define __KVM_HANDLER(area, h, n) \ 3170acb9111SPaul Mackerras BEGIN_FTR_SECTION_NESTED(947) \ 3180acb9111SPaul Mackerras ld r10,area+EX_CFAR(r13); \ 3190acb9111SPaul Mackerras std r10,HSTATE_CFAR(r13); \ 3200acb9111SPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_CFAR,CPU_FTR_CFAR,947); \ 3214b8473c9SPaul Mackerras BEGIN_FTR_SECTION_NESTED(948) \ 3224b8473c9SPaul Mackerras ld r10,area+EX_PPR(r13); \ 3234b8473c9SPaul Mackerras std r10,HSTATE_PPR(r13); \ 3244b8473c9SPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \ 325b01c8b54SPaul Mackerras ld r10,area+EX_R10(r13); \ 3263c42bf8aSPaul Mackerras std r12,HSTATE_SCRATCH0(r13); \ 327d3918e7fSNicholas Piggin sldi r12,r9,32; \ 328d3918e7fSNicholas Piggin ori r12,r12,(n); \ 329a97a65d5SNicholas Piggin /* This reloads r9 before branching to kvmppc_interrupt */ \ 330a97a65d5SNicholas Piggin __BRANCH_TO_KVM_EXIT(area, kvmppc_interrupt) 331b01c8b54SPaul Mackerras 332b01c8b54SPaul Mackerras #define __KVM_HANDLER_SKIP(area, h, n) \ 333b01c8b54SPaul Mackerras cmpwi r10,KVM_GUEST_MODE_SKIP; \ 334b01c8b54SPaul Mackerras beq 89f; \ 3354b8473c9SPaul Mackerras BEGIN_FTR_SECTION_NESTED(948) \ 336d3918e7fSNicholas Piggin ld r10,area+EX_PPR(r13); \ 337d3918e7fSNicholas Piggin std r10,HSTATE_PPR(r13); \ 3384b8473c9SPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \ 339d3918e7fSNicholas Piggin ld r10,area+EX_R10(r13); \ 3403c42bf8aSPaul Mackerras std r12,HSTATE_SCRATCH0(r13); \ 341d3918e7fSNicholas Piggin sldi r12,r9,32; \ 342d3918e7fSNicholas Piggin ori r12,r12,(n); \ 343a97a65d5SNicholas Piggin /* This reloads r9 before branching to kvmppc_interrupt */ \ 344a97a65d5SNicholas Piggin __BRANCH_TO_KVM_EXIT(area, kvmppc_interrupt); \ 345b01c8b54SPaul Mackerras 89: mtocrf 0x80,r9; \ 346b01c8b54SPaul Mackerras ld r9,area+EX_R9(r13); \ 347d3918e7fSNicholas Piggin ld r10,area+EX_R10(r13); \ 348b01c8b54SPaul Mackerras b kvmppc_skip_##h##interrupt 349b01c8b54SPaul Mackerras 350b01c8b54SPaul Mackerras #ifdef CONFIG_KVM_BOOK3S_64_HANDLER 351da2bc464SMichael Ellerman #define KVMTEST(h, n) __KVMTEST(h, n) 352b01c8b54SPaul Mackerras #define KVM_HANDLER(area, h, n) __KVM_HANDLER(area, h, n) 353b01c8b54SPaul Mackerras #define KVM_HANDLER_SKIP(area, h, n) __KVM_HANDLER_SKIP(area, h, n) 354b01c8b54SPaul Mackerras 355b01c8b54SPaul Mackerras #else 356da2bc464SMichael Ellerman #define KVMTEST(h, n) 357b01c8b54SPaul Mackerras #define KVM_HANDLER(area, h, n) 358b01c8b54SPaul Mackerras #define KVM_HANDLER_SKIP(area, h, n) 359b01c8b54SPaul Mackerras #endif 360b01c8b54SPaul Mackerras 361b01c8b54SPaul Mackerras #define NOTEST(n) 362b01c8b54SPaul Mackerras 363a4087a4dSNicholas Piggin #define EXCEPTION_PROLOG_COMMON_1() \ 364a4087a4dSNicholas Piggin std r9,_CCR(r1); /* save CR in stackframe */ \ 365a4087a4dSNicholas Piggin std r11,_NIP(r1); /* save SRR0 in stackframe */ \ 366a4087a4dSNicholas Piggin std r12,_MSR(r1); /* save SRR1 in stackframe */ \ 367a4087a4dSNicholas Piggin std r10,0(r1); /* make stack chain pointer */ \ 368a4087a4dSNicholas Piggin std r0,GPR0(r1); /* save r0 in stackframe */ \ 369a4087a4dSNicholas Piggin std r10,GPR1(r1); /* save r1 in stackframe */ \ 370a4087a4dSNicholas Piggin 371a4087a4dSNicholas Piggin 3728aa34ab8SBenjamin Herrenschmidt /* 3738aa34ab8SBenjamin Herrenschmidt * The common exception prolog is used for all except a few exceptions 3748aa34ab8SBenjamin Herrenschmidt * such as a segment miss on a kernel address. We have to be prepared 3758aa34ab8SBenjamin Herrenschmidt * to take another exception from the point where we first touch the 3768aa34ab8SBenjamin Herrenschmidt * kernel stack onwards. 3778aa34ab8SBenjamin Herrenschmidt * 3788aa34ab8SBenjamin Herrenschmidt * On entry r13 points to the paca, r9-r13 are saved in the paca, 3798aa34ab8SBenjamin Herrenschmidt * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and 3808aa34ab8SBenjamin Herrenschmidt * SRR1, and relocation is on. 3818aa34ab8SBenjamin Herrenschmidt */ 3828aa34ab8SBenjamin Herrenschmidt #define EXCEPTION_PROLOG_COMMON(n, area) \ 3838aa34ab8SBenjamin Herrenschmidt andi. r10,r12,MSR_PR; /* See if coming from user */ \ 3848aa34ab8SBenjamin Herrenschmidt mr r10,r1; /* Save r1 */ \ 3858aa34ab8SBenjamin Herrenschmidt subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \ 3868aa34ab8SBenjamin Herrenschmidt beq- 1f; \ 3878aa34ab8SBenjamin Herrenschmidt ld r1,PACAKSAVE(r13); /* kernel stack to use */ \ 38890ff5d68SMichael Neuling 1: cmpdi cr1,r1,-INT_FRAME_SIZE; /* check if r1 is in userspace */ \ 3891977b502SPaul Mackerras blt+ cr1,3f; /* abort if it is */ \ 3901977b502SPaul Mackerras li r1,(n); /* will be reloaded later */ \ 3918aa34ab8SBenjamin Herrenschmidt sth r1,PACA_TRAP_SAVE(r13); \ 3921977b502SPaul Mackerras std r3,area+EX_R3(r13); \ 3931977b502SPaul Mackerras addi r3,r13,area; /* r3 -> where regs are saved*/ \ 394bc2e6c6aSMichael Neuling RESTORE_CTR(r1, area); \ 3958aa34ab8SBenjamin Herrenschmidt b bad_stack; \ 396a4087a4dSNicholas Piggin 3: EXCEPTION_PROLOG_COMMON_1(); \ 3975d75b264SHaren Myneni beq 4f; /* if from kernel mode */ \ 398c223c903SChristophe Leroy ACCOUNT_CPU_USER_ENTRY(r13, r9, r10); \ 39944e9309fSHaren Myneni SAVE_PPR(area, r9, r10); \ 400b14a7253SMahesh Salgaonkar 4: EXCEPTION_PROLOG_COMMON_2(area) \ 401b14a7253SMahesh Salgaonkar EXCEPTION_PROLOG_COMMON_3(n) \ 402b14a7253SMahesh Salgaonkar ACCOUNT_STOLEN_TIME 403b14a7253SMahesh Salgaonkar 404b14a7253SMahesh Salgaonkar /* Save original regs values from save area to stack frame. */ 405b14a7253SMahesh Salgaonkar #define EXCEPTION_PROLOG_COMMON_2(area) \ 4068aa34ab8SBenjamin Herrenschmidt ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \ 4078aa34ab8SBenjamin Herrenschmidt ld r10,area+EX_R10(r13); \ 4088aa34ab8SBenjamin Herrenschmidt std r9,GPR9(r1); \ 4098aa34ab8SBenjamin Herrenschmidt std r10,GPR10(r1); \ 4108aa34ab8SBenjamin Herrenschmidt ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \ 4118aa34ab8SBenjamin Herrenschmidt ld r10,area+EX_R12(r13); \ 4128aa34ab8SBenjamin Herrenschmidt ld r11,area+EX_R13(r13); \ 4138aa34ab8SBenjamin Herrenschmidt std r9,GPR11(r1); \ 4148aa34ab8SBenjamin Herrenschmidt std r10,GPR12(r1); \ 4158aa34ab8SBenjamin Herrenschmidt std r11,GPR13(r1); \ 41648404f2eSPaul Mackerras BEGIN_FTR_SECTION_NESTED(66); \ 41748404f2eSPaul Mackerras ld r10,area+EX_CFAR(r13); \ 41848404f2eSPaul Mackerras std r10,ORIG_GPR3(r1); \ 41948404f2eSPaul Mackerras END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \ 420b14a7253SMahesh Salgaonkar GET_CTR(r10, area); \ 421b14a7253SMahesh Salgaonkar std r10,_CTR(r1); 422b14a7253SMahesh Salgaonkar 423b14a7253SMahesh Salgaonkar #define EXCEPTION_PROLOG_COMMON_3(n) \ 424b14a7253SMahesh Salgaonkar std r2,GPR2(r1); /* save r2 in stackframe */ \ 425b14a7253SMahesh Salgaonkar SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \ 426b14a7253SMahesh Salgaonkar SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \ 427bc2e6c6aSMichael Neuling mflr r9; /* Get LR, later save to stack */ \ 4288aa34ab8SBenjamin Herrenschmidt ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \ 4298aa34ab8SBenjamin Herrenschmidt std r9,_LINK(r1); \ 4308aa34ab8SBenjamin Herrenschmidt lbz r10,PACASOFTIRQEN(r13); \ 4318aa34ab8SBenjamin Herrenschmidt mfspr r11,SPRN_XER; /* save XER in stackframe */ \ 4328aa34ab8SBenjamin Herrenschmidt std r10,SOFTE(r1); \ 4338aa34ab8SBenjamin Herrenschmidt std r11,_XER(r1); \ 4348aa34ab8SBenjamin Herrenschmidt li r9,(n)+1; \ 4358aa34ab8SBenjamin Herrenschmidt std r9,_TRAP(r1); /* set trap number */ \ 4368aa34ab8SBenjamin Herrenschmidt li r10,0; \ 4378aa34ab8SBenjamin Herrenschmidt ld r11,exception_marker@toc(r2); \ 4388aa34ab8SBenjamin Herrenschmidt std r10,RESULT(r1); /* clear regs->result */ \ 439b14a7253SMahesh Salgaonkar std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */ 4408aa34ab8SBenjamin Herrenschmidt 4418aa34ab8SBenjamin Herrenschmidt /* 4428aa34ab8SBenjamin Herrenschmidt * Exception vectors. 4438aa34ab8SBenjamin Herrenschmidt */ 4442613265cSMichael Ellerman #define STD_EXCEPTION_PSERIES(vec, label) \ 445673b189aSPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 446da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \ 447da2bc464SMichael Ellerman EXC_STD, KVMTEST_PR, vec); \ 4488aa34ab8SBenjamin Herrenschmidt 4491707dd16SPaul Mackerras /* Version of above for when we have to branch out-of-line */ 450da2bc464SMichael Ellerman #define __OOL_EXCEPTION(vec, label, hdlr) \ 451da2bc464SMichael Ellerman SET_SCRATCH0(r13) \ 452da2bc464SMichael Ellerman EXCEPTION_PROLOG_0(PACA_EXGEN) \ 453da2bc464SMichael Ellerman b hdlr; 454da2bc464SMichael Ellerman 4551707dd16SPaul Mackerras #define STD_EXCEPTION_PSERIES_OOL(vec, label) \ 456da2bc464SMichael Ellerman EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_PR, vec); \ 457da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD) 4581707dd16SPaul Mackerras 459b3e6b5dfSBenjamin Herrenschmidt #define STD_EXCEPTION_HV(loc, vec, label) \ 460673b189aSPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 461da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \ 462da2bc464SMichael Ellerman EXC_HV, KVMTEST_HV, vec); 4638aa34ab8SBenjamin Herrenschmidt 4641707dd16SPaul Mackerras #define STD_EXCEPTION_HV_OOL(vec, label) \ 465da2bc464SMichael Ellerman EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \ 466da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV) 4671707dd16SPaul Mackerras 4684700dfafSMichael Neuling #define STD_RELON_EXCEPTION_PSERIES(loc, vec, label) \ 4694700dfafSMichael Neuling /* No guest interrupts come through here */ \ 4704700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 471da2bc464SMichael Ellerman EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, EXC_STD, NOTEST, vec); 4724700dfafSMichael Neuling 4731707dd16SPaul Mackerras #define STD_RELON_EXCEPTION_PSERIES_OOL(vec, label) \ 474c9f69518SMichael Ellerman EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, vec); \ 475da2bc464SMichael Ellerman EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_STD) 4761707dd16SPaul Mackerras 4774700dfafSMichael Neuling #define STD_RELON_EXCEPTION_HV(loc, vec, label) \ 4784700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 479bc355125SPaul Mackerras EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, \ 480bc355125SPaul Mackerras EXC_HV, KVMTEST_HV, vec); 4814700dfafSMichael Neuling 4821707dd16SPaul Mackerras #define STD_RELON_EXCEPTION_HV_OOL(vec, label) \ 483bc355125SPaul Mackerras EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \ 484da2bc464SMichael Ellerman EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV) 4851707dd16SPaul Mackerras 4867230c564SBenjamin Herrenschmidt /* This associate vector numbers with bits in paca->irq_happened */ 4877230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x500 PACA_IRQ_EE 4887230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x900 PACA_IRQ_DEC 489da2bc464SMichael Ellerman #define SOFTEN_VALUE_0x980 PACA_IRQ_DEC 4901dbdafecSIan Munsie #define SOFTEN_VALUE_0xa00 PACA_IRQ_DBELL 491655bb3f4SIan Munsie #define SOFTEN_VALUE_0xe80 PACA_IRQ_DBELL 4920869b6fdSMahesh Salgaonkar #define SOFTEN_VALUE_0xe60 PACA_IRQ_HMI 4939baaef0aSBenjamin Herrenschmidt #define SOFTEN_VALUE_0xea0 PACA_IRQ_EE 4947230c564SBenjamin Herrenschmidt 4957230c564SBenjamin Herrenschmidt #define __SOFTEN_TEST(h, vec) \ 4968aa34ab8SBenjamin Herrenschmidt lbz r10,PACASOFTIRQEN(r13); \ 4978aa34ab8SBenjamin Herrenschmidt cmpwi r10,0; \ 4987230c564SBenjamin Herrenschmidt li r10,SOFTEN_VALUE_##vec; \ 499b01c8b54SPaul Mackerras beq masked_##h##interrupt 500da2bc464SMichael Ellerman 5017230c564SBenjamin Herrenschmidt #define _SOFTEN_TEST(h, vec) __SOFTEN_TEST(h, vec) 502b01c8b54SPaul Mackerras 503de56a948SPaul Mackerras #define SOFTEN_TEST_PR(vec) \ 504da2bc464SMichael Ellerman KVMTEST(EXC_STD, vec); \ 5057230c564SBenjamin Herrenschmidt _SOFTEN_TEST(EXC_STD, vec) 506b01c8b54SPaul Mackerras 507b01c8b54SPaul Mackerras #define SOFTEN_TEST_HV(vec) \ 508da2bc464SMichael Ellerman KVMTEST(EXC_HV, vec); \ 5097230c564SBenjamin Herrenschmidt _SOFTEN_TEST(EXC_HV, vec) 510b01c8b54SPaul Mackerras 511da2bc464SMichael Ellerman #define KVMTEST_PR(vec) \ 512da2bc464SMichael Ellerman KVMTEST(EXC_STD, vec) 513da2bc464SMichael Ellerman 514da2bc464SMichael Ellerman #define KVMTEST_HV(vec) \ 515da2bc464SMichael Ellerman KVMTEST(EXC_HV, vec) 516da2bc464SMichael Ellerman 5174700dfafSMichael Neuling #define SOFTEN_NOTEST_PR(vec) _SOFTEN_TEST(EXC_STD, vec) 5184700dfafSMichael Neuling #define SOFTEN_NOTEST_HV(vec) _SOFTEN_TEST(EXC_HV, vec) 5194700dfafSMichael Neuling 520b01c8b54SPaul Mackerras #define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \ 521b01c8b54SPaul Mackerras SET_SCRATCH0(r13); /* save r13 */ \ 5221707dd16SPaul Mackerras EXCEPTION_PROLOG_0(PACA_EXGEN); \ 523b01c8b54SPaul Mackerras __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \ 524da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES_1(label, h); 5251707dd16SPaul Mackerras 526b01c8b54SPaul Mackerras #define _MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \ 527b01c8b54SPaul Mackerras __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) 528b3e6b5dfSBenjamin Herrenschmidt 529b3e6b5dfSBenjamin Herrenschmidt #define MASKABLE_EXCEPTION_PSERIES(loc, vec, label) \ 530b01c8b54SPaul Mackerras _MASKABLE_EXCEPTION_PSERIES(vec, label, \ 531de56a948SPaul Mackerras EXC_STD, SOFTEN_TEST_PR) 532b3e6b5dfSBenjamin Herrenschmidt 533da2bc464SMichael Ellerman #define MASKABLE_EXCEPTION_PSERIES_OOL(vec, label) \ 534da2bc464SMichael Ellerman EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_PR, vec); \ 535da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD) 536da2bc464SMichael Ellerman 537b3e6b5dfSBenjamin Herrenschmidt #define MASKABLE_EXCEPTION_HV(loc, vec, label) \ 538b01c8b54SPaul Mackerras _MASKABLE_EXCEPTION_PSERIES(vec, label, \ 539b01c8b54SPaul Mackerras EXC_HV, SOFTEN_TEST_HV) 5408aa34ab8SBenjamin Herrenschmidt 5411707dd16SPaul Mackerras #define MASKABLE_EXCEPTION_HV_OOL(vec, label) \ 5421707dd16SPaul Mackerras EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec); \ 543da2bc464SMichael Ellerman EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV) 5441707dd16SPaul Mackerras 5454700dfafSMichael Neuling #define __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \ 5464700dfafSMichael Neuling SET_SCRATCH0(r13); /* save r13 */ \ 5471707dd16SPaul Mackerras EXCEPTION_PROLOG_0(PACA_EXGEN); \ 5484700dfafSMichael Neuling __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \ 549da2bc464SMichael Ellerman EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) 550da2bc464SMichael Ellerman 5514700dfafSMichael Neuling #define _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \ 5524700dfafSMichael Neuling __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) 5534700dfafSMichael Neuling 5544700dfafSMichael Neuling #define MASKABLE_RELON_EXCEPTION_PSERIES(loc, vec, label) \ 5554700dfafSMichael Neuling _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \ 5564700dfafSMichael Neuling EXC_STD, SOFTEN_NOTEST_PR) 5574700dfafSMichael Neuling 5584700dfafSMichael Neuling #define MASKABLE_RELON_EXCEPTION_HV(loc, vec, label) \ 5594700dfafSMichael Neuling _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \ 560bc355125SPaul Mackerras EXC_HV, SOFTEN_TEST_HV) 5614700dfafSMichael Neuling 5621707dd16SPaul Mackerras #define MASKABLE_RELON_EXCEPTION_HV_OOL(vec, label) \ 563bc355125SPaul Mackerras EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec); \ 564a050d20dSNicholas Piggin EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV) 5651707dd16SPaul Mackerras 5661b701179SBenjamin Herrenschmidt /* 5671b701179SBenjamin Herrenschmidt * Our exception common code can be passed various "additions" 5681b701179SBenjamin Herrenschmidt * to specify the behaviour of interrupts, whether to kick the 5691b701179SBenjamin Herrenschmidt * runlatch, etc... 5701b701179SBenjamin Herrenschmidt */ 5711b701179SBenjamin Herrenschmidt 5729daf112bSMichael Ellerman /* 5739daf112bSMichael Ellerman * This addition reconciles our actual IRQ state with the various software 5749daf112bSMichael Ellerman * flags that track it. This may call C code. 5759daf112bSMichael Ellerman */ 5769daf112bSMichael Ellerman #define ADD_RECONCILE RECONCILE_IRQ_STATE(r10,r11) 5778aa34ab8SBenjamin Herrenschmidt 578fe1952fcSBenjamin Herrenschmidt #define ADD_NVGPRS \ 579b1576fecSAnton Blanchard bl save_nvgprs 580fe1952fcSBenjamin Herrenschmidt 581fe1952fcSBenjamin Herrenschmidt #define RUNLATCH_ON \ 582fe1952fcSBenjamin Herrenschmidt BEGIN_FTR_SECTION \ 5839778b696SStuart Yoder CURRENT_THREAD_INFO(r3, r1); \ 584fe1952fcSBenjamin Herrenschmidt ld r4,TI_LOCAL_FLAGS(r3); \ 585fe1952fcSBenjamin Herrenschmidt andi. r0,r4,_TLF_RUNLATCH; \ 586fe1952fcSBenjamin Herrenschmidt beql ppc64_runlatch_on_trampoline; \ 587fe1952fcSBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CTRL) 588fe1952fcSBenjamin Herrenschmidt 589a3d96f70SNicholas Piggin #define EXCEPTION_COMMON(area, trap, label, hdlr, ret, additions) \ 590a3d96f70SNicholas Piggin EXCEPTION_PROLOG_COMMON(trap, area); \ 591a1d711c5SMichael Ellerman /* Volatile regs are potentially clobbered here */ \ 592fe1952fcSBenjamin Herrenschmidt additions; \ 5938aa34ab8SBenjamin Herrenschmidt addi r3,r1,STACK_FRAME_OVERHEAD; \ 5948aa34ab8SBenjamin Herrenschmidt bl hdlr; \ 595fe1952fcSBenjamin Herrenschmidt b ret 596fe1952fcSBenjamin Herrenschmidt 597b1ee8a3dSNicholas Piggin /* 598b1ee8a3dSNicholas Piggin * Exception where stack is already set in r1, r1 is saved in r10, and it 599b1ee8a3dSNicholas Piggin * continues rather than returns. 600b1ee8a3dSNicholas Piggin */ 601b1ee8a3dSNicholas Piggin #define EXCEPTION_COMMON_NORET_STACK(area, trap, label, hdlr, additions) \ 602b1ee8a3dSNicholas Piggin EXCEPTION_PROLOG_COMMON_1(); \ 603b1ee8a3dSNicholas Piggin EXCEPTION_PROLOG_COMMON_2(area); \ 604b1ee8a3dSNicholas Piggin EXCEPTION_PROLOG_COMMON_3(trap); \ 605b1ee8a3dSNicholas Piggin /* Volatile regs are potentially clobbered here */ \ 606b1ee8a3dSNicholas Piggin additions; \ 607b1ee8a3dSNicholas Piggin addi r3,r1,STACK_FRAME_OVERHEAD; \ 608b1ee8a3dSNicholas Piggin bl hdlr 609b1ee8a3dSNicholas Piggin 610fe1952fcSBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON(trap, label, hdlr) \ 611a3d96f70SNicholas Piggin EXCEPTION_COMMON(PACA_EXGEN, trap, label, hdlr, \ 612a3d96f70SNicholas Piggin ret_from_except, ADD_NVGPRS;ADD_RECONCILE) 6138aa34ab8SBenjamin Herrenschmidt 6148aa34ab8SBenjamin Herrenschmidt /* 6158aa34ab8SBenjamin Herrenschmidt * Like STD_EXCEPTION_COMMON, but for exceptions that can occur 6167450f6f0SBenjamin Herrenschmidt * in the idle task and therefore need the special idle handling 6177450f6f0SBenjamin Herrenschmidt * (finish nap and runlatch) 6188aa34ab8SBenjamin Herrenschmidt */ 6197450f6f0SBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON_ASYNC(trap, label, hdlr) \ 620a3d96f70SNicholas Piggin EXCEPTION_COMMON(PACA_EXGEN, trap, label, hdlr, \ 621a3d96f70SNicholas Piggin ret_from_except_lite, FINISH_NAP;ADD_RECONCILE;RUNLATCH_ON) 6228aa34ab8SBenjamin Herrenschmidt 6238aa34ab8SBenjamin Herrenschmidt /* 6248aa34ab8SBenjamin Herrenschmidt * When the idle code in power4_idle puts the CPU into NAP mode, 6258aa34ab8SBenjamin Herrenschmidt * it has to do so in a loop, and relies on the external interrupt 6268aa34ab8SBenjamin Herrenschmidt * and decrementer interrupt entry code to get it out of the loop. 6278aa34ab8SBenjamin Herrenschmidt * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags 6288aa34ab8SBenjamin Herrenschmidt * to signal that it is in the loop and needs help to get out. 6298aa34ab8SBenjamin Herrenschmidt */ 6308aa34ab8SBenjamin Herrenschmidt #ifdef CONFIG_PPC_970_NAP 6318aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP \ 6328aa34ab8SBenjamin Herrenschmidt BEGIN_FTR_SECTION \ 6339778b696SStuart Yoder CURRENT_THREAD_INFO(r11, r1); \ 6348aa34ab8SBenjamin Herrenschmidt ld r9,TI_LOCAL_FLAGS(r11); \ 6358aa34ab8SBenjamin Herrenschmidt andi. r10,r9,_TLF_NAPPING; \ 6368aa34ab8SBenjamin Herrenschmidt bnel power4_fixup_nap; \ 6378aa34ab8SBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP) 6388aa34ab8SBenjamin Herrenschmidt #else 6398aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP 6408aa34ab8SBenjamin Herrenschmidt #endif 6418aa34ab8SBenjamin Herrenschmidt 6428aa34ab8SBenjamin Herrenschmidt #endif /* _ASM_POWERPC_EXCEPTION_H */ 643