1b8b572e1SStephen Rothwell /* 2b8b572e1SStephen Rothwell * Copyright (C) 1995-1999 Gary Thomas, Paul Mackerras, Cort Dougan. 3b8b572e1SStephen Rothwell */ 4b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_PPC_ASM_H 5b8b572e1SStephen Rothwell #define _ASM_POWERPC_PPC_ASM_H 6b8b572e1SStephen Rothwell 79203fc9cSTim Abbott #include <linux/init.h> 8b8b572e1SStephen Rothwell #include <linux/stringify.h> 9b8b572e1SStephen Rothwell #include <asm/asm-compat.h> 10b8b572e1SStephen Rothwell #include <asm/processor.h> 1116c57b36SKumar Gala #include <asm/ppc-opcode.h> 12cf9efce0SPaul Mackerras #include <asm/firmware.h> 13b8b572e1SStephen Rothwell 14b8b572e1SStephen Rothwell #ifndef __ASSEMBLY__ 15b8b572e1SStephen Rothwell #error __FILE__ should only be used in assembler files 16b8b572e1SStephen Rothwell #else 17b8b572e1SStephen Rothwell 18b8b572e1SStephen Rothwell #define SZL (BITS_PER_LONG/8) 19b8b572e1SStephen Rothwell 20b8b572e1SStephen Rothwell /* 21b8b572e1SStephen Rothwell * Stuff for accurate CPU time accounting. 22b8b572e1SStephen Rothwell * These macros handle transitions between user and system state 23b8b572e1SStephen Rothwell * in exception entry and exit and accumulate time to the 24b8b572e1SStephen Rothwell * user_time and system_time fields in the paca. 25b8b572e1SStephen Rothwell */ 26b8b572e1SStephen Rothwell 27abf917cdSFrederic Weisbecker #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE 28b8b572e1SStephen Rothwell #define ACCOUNT_CPU_USER_ENTRY(ra, rb) 29b8b572e1SStephen Rothwell #define ACCOUNT_CPU_USER_EXIT(ra, rb) 30cf9efce0SPaul Mackerras #define ACCOUNT_STOLEN_TIME 31b8b572e1SStephen Rothwell #else 32b8b572e1SStephen Rothwell #define ACCOUNT_CPU_USER_ENTRY(ra, rb) \ 33cf9efce0SPaul Mackerras MFTB(ra); /* get timebase */ \ 34cf9efce0SPaul Mackerras ld rb,PACA_STARTTIME_USER(r13); \ 35cf9efce0SPaul Mackerras std ra,PACA_STARTTIME(r13); \ 36b8b572e1SStephen Rothwell subf rb,rb,ra; /* subtract start value */ \ 37b8b572e1SStephen Rothwell ld ra,PACA_USER_TIME(r13); \ 38b8b572e1SStephen Rothwell add ra,ra,rb; /* add on to user time */ \ 39b8b572e1SStephen Rothwell std ra,PACA_USER_TIME(r13); \ 40b8b572e1SStephen Rothwell 41b8b572e1SStephen Rothwell #define ACCOUNT_CPU_USER_EXIT(ra, rb) \ 42cf9efce0SPaul Mackerras MFTB(ra); /* get timebase */ \ 43cf9efce0SPaul Mackerras ld rb,PACA_STARTTIME(r13); \ 44cf9efce0SPaul Mackerras std ra,PACA_STARTTIME_USER(r13); \ 45b8b572e1SStephen Rothwell subf rb,rb,ra; /* subtract start value */ \ 46b8b572e1SStephen Rothwell ld ra,PACA_SYSTEM_TIME(r13); \ 47cf9efce0SPaul Mackerras add ra,ra,rb; /* add on to system time */ \ 48cf9efce0SPaul Mackerras std ra,PACA_SYSTEM_TIME(r13) 49cf9efce0SPaul Mackerras 50cf9efce0SPaul Mackerras #ifdef CONFIG_PPC_SPLPAR 51cf9efce0SPaul Mackerras #define ACCOUNT_STOLEN_TIME \ 52cf9efce0SPaul Mackerras BEGIN_FW_FTR_SECTION; \ 53cf9efce0SPaul Mackerras beq 33f; \ 54cf9efce0SPaul Mackerras /* from user - see if there are any DTL entries to process */ \ 55cf9efce0SPaul Mackerras ld r10,PACALPPACAPTR(r13); /* get ptr to VPA */ \ 56cf9efce0SPaul Mackerras ld r11,PACA_DTL_RIDX(r13); /* get log read index */ \ 577ffcf8ecSAnton Blanchard addi r10,r10,LPPACA_DTLIDX; \ 587ffcf8ecSAnton Blanchard LDX_BE r10,0,r10; /* get log write index */ \ 59cf9efce0SPaul Mackerras cmpd cr1,r11,r10; \ 60cf9efce0SPaul Mackerras beq+ cr1,33f; \ 61cf9efce0SPaul Mackerras bl .accumulate_stolen_time; \ 62990118c8SBenjamin Herrenschmidt ld r12,_MSR(r1); \ 63990118c8SBenjamin Herrenschmidt andi. r10,r12,MSR_PR; /* Restore cr0 (coming from user) */ \ 64cf9efce0SPaul Mackerras 33: \ 65cf9efce0SPaul Mackerras END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR) 66cf9efce0SPaul Mackerras 67cf9efce0SPaul Mackerras #else /* CONFIG_PPC_SPLPAR */ 68cf9efce0SPaul Mackerras #define ACCOUNT_STOLEN_TIME 69cf9efce0SPaul Mackerras 70cf9efce0SPaul Mackerras #endif /* CONFIG_PPC_SPLPAR */ 71cf9efce0SPaul Mackerras 72abf917cdSFrederic Weisbecker #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ 73b8b572e1SStephen Rothwell 74b8b572e1SStephen Rothwell /* 75b8b572e1SStephen Rothwell * Macros for storing registers into and loading registers from 76b8b572e1SStephen Rothwell * exception frames. 77b8b572e1SStephen Rothwell */ 78b8b572e1SStephen Rothwell #ifdef __powerpc64__ 79b8b572e1SStephen Rothwell #define SAVE_GPR(n, base) std n,GPR0+8*(n)(base) 80b8b572e1SStephen Rothwell #define REST_GPR(n, base) ld n,GPR0+8*(n)(base) 81b8b572e1SStephen Rothwell #define SAVE_NVGPRS(base) SAVE_8GPRS(14, base); SAVE_10GPRS(22, base) 82b8b572e1SStephen Rothwell #define REST_NVGPRS(base) REST_8GPRS(14, base); REST_10GPRS(22, base) 83b8b572e1SStephen Rothwell #else 84b8b572e1SStephen Rothwell #define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base) 85b8b572e1SStephen Rothwell #define REST_GPR(n, base) lwz n,GPR0+4*(n)(base) 86b8b572e1SStephen Rothwell #define SAVE_NVGPRS(base) SAVE_GPR(13, base); SAVE_8GPRS(14, base); \ 87b8b572e1SStephen Rothwell SAVE_10GPRS(22, base) 88b8b572e1SStephen Rothwell #define REST_NVGPRS(base) REST_GPR(13, base); REST_8GPRS(14, base); \ 89b8b572e1SStephen Rothwell REST_10GPRS(22, base) 90b8b572e1SStephen Rothwell #endif 91b8b572e1SStephen Rothwell 92b8b572e1SStephen Rothwell #define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base) 93b8b572e1SStephen Rothwell #define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base) 94b8b572e1SStephen Rothwell #define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base) 95b8b572e1SStephen Rothwell #define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base) 96b8b572e1SStephen Rothwell #define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base) 97b8b572e1SStephen Rothwell #define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base) 98b8b572e1SStephen Rothwell #define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base) 99b8b572e1SStephen Rothwell #define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base) 100b8b572e1SStephen Rothwell 101b8b572e1SStephen Rothwell #define SAVE_FPR(n, base) stfd n,THREAD_FPR0+8*TS_FPRWIDTH*(n)(base) 102b8b572e1SStephen Rothwell #define SAVE_2FPRS(n, base) SAVE_FPR(n, base); SAVE_FPR(n+1, base) 103b8b572e1SStephen Rothwell #define SAVE_4FPRS(n, base) SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base) 104b8b572e1SStephen Rothwell #define SAVE_8FPRS(n, base) SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base) 105b8b572e1SStephen Rothwell #define SAVE_16FPRS(n, base) SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base) 106b8b572e1SStephen Rothwell #define SAVE_32FPRS(n, base) SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base) 107b8b572e1SStephen Rothwell #define REST_FPR(n, base) lfd n,THREAD_FPR0+8*TS_FPRWIDTH*(n)(base) 108b8b572e1SStephen Rothwell #define REST_2FPRS(n, base) REST_FPR(n, base); REST_FPR(n+1, base) 109b8b572e1SStephen Rothwell #define REST_4FPRS(n, base) REST_2FPRS(n, base); REST_2FPRS(n+2, base) 110b8b572e1SStephen Rothwell #define REST_8FPRS(n, base) REST_4FPRS(n, base); REST_4FPRS(n+4, base) 111b8b572e1SStephen Rothwell #define REST_16FPRS(n, base) REST_8FPRS(n, base); REST_8FPRS(n+8, base) 112b8b572e1SStephen Rothwell #define REST_32FPRS(n, base) REST_16FPRS(n, base); REST_16FPRS(n+16, base) 113b8b572e1SStephen Rothwell 11423e55f92SMichael Wolf #define SAVE_VR(n,b,base) li b,THREAD_VR0+(16*(n)); stvx n,base,b 115b8b572e1SStephen Rothwell #define SAVE_2VRS(n,b,base) SAVE_VR(n,b,base); SAVE_VR(n+1,b,base) 116b8b572e1SStephen Rothwell #define SAVE_4VRS(n,b,base) SAVE_2VRS(n,b,base); SAVE_2VRS(n+2,b,base) 117b8b572e1SStephen Rothwell #define SAVE_8VRS(n,b,base) SAVE_4VRS(n,b,base); SAVE_4VRS(n+4,b,base) 118b8b572e1SStephen Rothwell #define SAVE_16VRS(n,b,base) SAVE_8VRS(n,b,base); SAVE_8VRS(n+8,b,base) 119b8b572e1SStephen Rothwell #define SAVE_32VRS(n,b,base) SAVE_16VRS(n,b,base); SAVE_16VRS(n+16,b,base) 12023e55f92SMichael Wolf #define REST_VR(n,b,base) li b,THREAD_VR0+(16*(n)); lvx n,base,b 121b8b572e1SStephen Rothwell #define REST_2VRS(n,b,base) REST_VR(n,b,base); REST_VR(n+1,b,base) 122b8b572e1SStephen Rothwell #define REST_4VRS(n,b,base) REST_2VRS(n,b,base); REST_2VRS(n+2,b,base) 123b8b572e1SStephen Rothwell #define REST_8VRS(n,b,base) REST_4VRS(n,b,base); REST_4VRS(n+4,b,base) 124b8b572e1SStephen Rothwell #define REST_16VRS(n,b,base) REST_8VRS(n,b,base); REST_8VRS(n+8,b,base) 125b8b572e1SStephen Rothwell #define REST_32VRS(n,b,base) REST_16VRS(n,b,base); REST_16VRS(n+16,b,base) 126b8b572e1SStephen Rothwell 1278b3c34cfSMichael Neuling /* Save/restore FPRs, VRs and VSRs from their checkpointed backups in 1288b3c34cfSMichael Neuling * thread_struct: 1298b3c34cfSMichael Neuling */ 1308b3c34cfSMichael Neuling #define SAVE_FPR_TRANSACT(n, base) stfd n,THREAD_TRANSACT_FPR0+ \ 1318b3c34cfSMichael Neuling 8*TS_FPRWIDTH*(n)(base) 1328b3c34cfSMichael Neuling #define SAVE_2FPRS_TRANSACT(n, base) SAVE_FPR_TRANSACT(n, base); \ 1338b3c34cfSMichael Neuling SAVE_FPR_TRANSACT(n+1, base) 1348b3c34cfSMichael Neuling #define SAVE_4FPRS_TRANSACT(n, base) SAVE_2FPRS_TRANSACT(n, base); \ 1358b3c34cfSMichael Neuling SAVE_2FPRS_TRANSACT(n+2, base) 1368b3c34cfSMichael Neuling #define SAVE_8FPRS_TRANSACT(n, base) SAVE_4FPRS_TRANSACT(n, base); \ 1378b3c34cfSMichael Neuling SAVE_4FPRS_TRANSACT(n+4, base) 1388b3c34cfSMichael Neuling #define SAVE_16FPRS_TRANSACT(n, base) SAVE_8FPRS_TRANSACT(n, base); \ 1398b3c34cfSMichael Neuling SAVE_8FPRS_TRANSACT(n+8, base) 1408b3c34cfSMichael Neuling #define SAVE_32FPRS_TRANSACT(n, base) SAVE_16FPRS_TRANSACT(n, base); \ 1418b3c34cfSMichael Neuling SAVE_16FPRS_TRANSACT(n+16, base) 1428b3c34cfSMichael Neuling 1438b3c34cfSMichael Neuling #define REST_FPR_TRANSACT(n, base) lfd n,THREAD_TRANSACT_FPR0+ \ 1448b3c34cfSMichael Neuling 8*TS_FPRWIDTH*(n)(base) 1458b3c34cfSMichael Neuling #define REST_2FPRS_TRANSACT(n, base) REST_FPR_TRANSACT(n, base); \ 1468b3c34cfSMichael Neuling REST_FPR_TRANSACT(n+1, base) 1478b3c34cfSMichael Neuling #define REST_4FPRS_TRANSACT(n, base) REST_2FPRS_TRANSACT(n, base); \ 1488b3c34cfSMichael Neuling REST_2FPRS_TRANSACT(n+2, base) 1498b3c34cfSMichael Neuling #define REST_8FPRS_TRANSACT(n, base) REST_4FPRS_TRANSACT(n, base); \ 1508b3c34cfSMichael Neuling REST_4FPRS_TRANSACT(n+4, base) 1518b3c34cfSMichael Neuling #define REST_16FPRS_TRANSACT(n, base) REST_8FPRS_TRANSACT(n, base); \ 1528b3c34cfSMichael Neuling REST_8FPRS_TRANSACT(n+8, base) 1538b3c34cfSMichael Neuling #define REST_32FPRS_TRANSACT(n, base) REST_16FPRS_TRANSACT(n, base); \ 1548b3c34cfSMichael Neuling REST_16FPRS_TRANSACT(n+16, base) 1558b3c34cfSMichael Neuling 1568b3c34cfSMichael Neuling 1578b3c34cfSMichael Neuling #define SAVE_VR_TRANSACT(n,b,base) li b,THREAD_TRANSACT_VR0+(16*(n)); \ 1588b3c34cfSMichael Neuling stvx n,b,base 1598b3c34cfSMichael Neuling #define SAVE_2VRS_TRANSACT(n,b,base) SAVE_VR_TRANSACT(n,b,base); \ 1608b3c34cfSMichael Neuling SAVE_VR_TRANSACT(n+1,b,base) 1618b3c34cfSMichael Neuling #define SAVE_4VRS_TRANSACT(n,b,base) SAVE_2VRS_TRANSACT(n,b,base); \ 1628b3c34cfSMichael Neuling SAVE_2VRS_TRANSACT(n+2,b,base) 1638b3c34cfSMichael Neuling #define SAVE_8VRS_TRANSACT(n,b,base) SAVE_4VRS_TRANSACT(n,b,base); \ 1648b3c34cfSMichael Neuling SAVE_4VRS_TRANSACT(n+4,b,base) 1658b3c34cfSMichael Neuling #define SAVE_16VRS_TRANSACT(n,b,base) SAVE_8VRS_TRANSACT(n,b,base); \ 1668b3c34cfSMichael Neuling SAVE_8VRS_TRANSACT(n+8,b,base) 1678b3c34cfSMichael Neuling #define SAVE_32VRS_TRANSACT(n,b,base) SAVE_16VRS_TRANSACT(n,b,base); \ 1688b3c34cfSMichael Neuling SAVE_16VRS_TRANSACT(n+16,b,base) 1698b3c34cfSMichael Neuling 1708b3c34cfSMichael Neuling #define REST_VR_TRANSACT(n,b,base) li b,THREAD_TRANSACT_VR0+(16*(n)); \ 1718b3c34cfSMichael Neuling lvx n,b,base 1728b3c34cfSMichael Neuling #define REST_2VRS_TRANSACT(n,b,base) REST_VR_TRANSACT(n,b,base); \ 1738b3c34cfSMichael Neuling REST_VR_TRANSACT(n+1,b,base) 1748b3c34cfSMichael Neuling #define REST_4VRS_TRANSACT(n,b,base) REST_2VRS_TRANSACT(n,b,base); \ 1758b3c34cfSMichael Neuling REST_2VRS_TRANSACT(n+2,b,base) 1768b3c34cfSMichael Neuling #define REST_8VRS_TRANSACT(n,b,base) REST_4VRS_TRANSACT(n,b,base); \ 1778b3c34cfSMichael Neuling REST_4VRS_TRANSACT(n+4,b,base) 1788b3c34cfSMichael Neuling #define REST_16VRS_TRANSACT(n,b,base) REST_8VRS_TRANSACT(n,b,base); \ 1798b3c34cfSMichael Neuling REST_8VRS_TRANSACT(n+8,b,base) 1808b3c34cfSMichael Neuling #define REST_32VRS_TRANSACT(n,b,base) REST_16VRS_TRANSACT(n,b,base); \ 1818b3c34cfSMichael Neuling REST_16VRS_TRANSACT(n+16,b,base) 1828b3c34cfSMichael Neuling 183926f160fSAnton Blanchard #ifdef __BIG_ENDIAN__ 184926f160fSAnton Blanchard #define STXVD2X_ROT(n,b,base) STXVD2X(n,b,base) 185926f160fSAnton Blanchard #define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base) 186926f160fSAnton Blanchard #else 187926f160fSAnton Blanchard #define STXVD2X_ROT(n,b,base) XXSWAPD(n,n); \ 188926f160fSAnton Blanchard STXVD2X(n,b,base); \ 189926f160fSAnton Blanchard XXSWAPD(n,n) 190926f160fSAnton Blanchard 191926f160fSAnton Blanchard #define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base); \ 192926f160fSAnton Blanchard XXSWAPD(n,n) 193926f160fSAnton Blanchard #endif 1948b3c34cfSMichael Neuling 1958b3c34cfSMichael Neuling #define SAVE_VSR_TRANSACT(n,b,base) li b,THREAD_TRANSACT_VSR0+(16*(n)); \ 196926f160fSAnton Blanchard STXVD2X_ROT(n,R##base,R##b) 1978b3c34cfSMichael Neuling #define SAVE_2VSRS_TRANSACT(n,b,base) SAVE_VSR_TRANSACT(n,b,base); \ 1988b3c34cfSMichael Neuling SAVE_VSR_TRANSACT(n+1,b,base) 1998b3c34cfSMichael Neuling #define SAVE_4VSRS_TRANSACT(n,b,base) SAVE_2VSRS_TRANSACT(n,b,base); \ 2008b3c34cfSMichael Neuling SAVE_2VSRS_TRANSACT(n+2,b,base) 2018b3c34cfSMichael Neuling #define SAVE_8VSRS_TRANSACT(n,b,base) SAVE_4VSRS_TRANSACT(n,b,base); \ 2028b3c34cfSMichael Neuling SAVE_4VSRS_TRANSACT(n+4,b,base) 2038b3c34cfSMichael Neuling #define SAVE_16VSRS_TRANSACT(n,b,base) SAVE_8VSRS_TRANSACT(n,b,base); \ 2048b3c34cfSMichael Neuling SAVE_8VSRS_TRANSACT(n+8,b,base) 2058b3c34cfSMichael Neuling #define SAVE_32VSRS_TRANSACT(n,b,base) SAVE_16VSRS_TRANSACT(n,b,base); \ 2068b3c34cfSMichael Neuling SAVE_16VSRS_TRANSACT(n+16,b,base) 2078b3c34cfSMichael Neuling 2088b3c34cfSMichael Neuling #define REST_VSR_TRANSACT(n,b,base) li b,THREAD_TRANSACT_VSR0+(16*(n)); \ 209926f160fSAnton Blanchard LXVD2X_ROT(n,R##base,R##b) 2108b3c34cfSMichael Neuling #define REST_2VSRS_TRANSACT(n,b,base) REST_VSR_TRANSACT(n,b,base); \ 2118b3c34cfSMichael Neuling REST_VSR_TRANSACT(n+1,b,base) 2128b3c34cfSMichael Neuling #define REST_4VSRS_TRANSACT(n,b,base) REST_2VSRS_TRANSACT(n,b,base); \ 2138b3c34cfSMichael Neuling REST_2VSRS_TRANSACT(n+2,b,base) 2148b3c34cfSMichael Neuling #define REST_8VSRS_TRANSACT(n,b,base) REST_4VSRS_TRANSACT(n,b,base); \ 2158b3c34cfSMichael Neuling REST_4VSRS_TRANSACT(n+4,b,base) 2168b3c34cfSMichael Neuling #define REST_16VSRS_TRANSACT(n,b,base) REST_8VSRS_TRANSACT(n,b,base); \ 2178b3c34cfSMichael Neuling REST_8VSRS_TRANSACT(n+8,b,base) 2188b3c34cfSMichael Neuling #define REST_32VSRS_TRANSACT(n,b,base) REST_16VSRS_TRANSACT(n,b,base); \ 2198b3c34cfSMichael Neuling REST_16VSRS_TRANSACT(n+16,b,base) 2208b3c34cfSMichael Neuling 221b8b572e1SStephen Rothwell /* Save the lower 32 VSRs in the thread VSR region */ 222926f160fSAnton Blanchard #define SAVE_VSR(n,b,base) li b,THREAD_VSR0+(16*(n)); \ 223926f160fSAnton Blanchard STXVD2X_ROT(n,R##base,R##b) 224b8b572e1SStephen Rothwell #define SAVE_2VSRS(n,b,base) SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base) 225b8b572e1SStephen Rothwell #define SAVE_4VSRS(n,b,base) SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base) 226b8b572e1SStephen Rothwell #define SAVE_8VSRS(n,b,base) SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base) 227b8b572e1SStephen Rothwell #define SAVE_16VSRS(n,b,base) SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base) 228b8b572e1SStephen Rothwell #define SAVE_32VSRS(n,b,base) SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base) 229926f160fSAnton Blanchard #define REST_VSR(n,b,base) li b,THREAD_VSR0+(16*(n)); \ 230926f160fSAnton Blanchard LXVD2X_ROT(n,R##base,R##b) 231b8b572e1SStephen Rothwell #define REST_2VSRS(n,b,base) REST_VSR(n,b,base); REST_VSR(n+1,b,base) 232b8b572e1SStephen Rothwell #define REST_4VSRS(n,b,base) REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base) 233b8b572e1SStephen Rothwell #define REST_8VSRS(n,b,base) REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base) 234b8b572e1SStephen Rothwell #define REST_16VSRS(n,b,base) REST_8VSRS(n,b,base); REST_8VSRS(n+8,b,base) 235b8b572e1SStephen Rothwell #define REST_32VSRS(n,b,base) REST_16VSRS(n,b,base); REST_16VSRS(n+16,b,base) 236b8b572e1SStephen Rothwell 237c51584d5SScott Wood /* 238c51584d5SScott Wood * b = base register for addressing, o = base offset from register of 1st EVR 239c51584d5SScott Wood * n = first EVR, s = scratch 240c51584d5SScott Wood */ 241c51584d5SScott Wood #define SAVE_EVR(n,s,b,o) evmergehi s,s,n; stw s,o+4*(n)(b) 242c51584d5SScott Wood #define SAVE_2EVRS(n,s,b,o) SAVE_EVR(n,s,b,o); SAVE_EVR(n+1,s,b,o) 243c51584d5SScott Wood #define SAVE_4EVRS(n,s,b,o) SAVE_2EVRS(n,s,b,o); SAVE_2EVRS(n+2,s,b,o) 244c51584d5SScott Wood #define SAVE_8EVRS(n,s,b,o) SAVE_4EVRS(n,s,b,o); SAVE_4EVRS(n+4,s,b,o) 245c51584d5SScott Wood #define SAVE_16EVRS(n,s,b,o) SAVE_8EVRS(n,s,b,o); SAVE_8EVRS(n+8,s,b,o) 246c51584d5SScott Wood #define SAVE_32EVRS(n,s,b,o) SAVE_16EVRS(n,s,b,o); SAVE_16EVRS(n+16,s,b,o) 247c51584d5SScott Wood #define REST_EVR(n,s,b,o) lwz s,o+4*(n)(b); evmergelo n,s,n 248c51584d5SScott Wood #define REST_2EVRS(n,s,b,o) REST_EVR(n,s,b,o); REST_EVR(n+1,s,b,o) 249c51584d5SScott Wood #define REST_4EVRS(n,s,b,o) REST_2EVRS(n,s,b,o); REST_2EVRS(n+2,s,b,o) 250c51584d5SScott Wood #define REST_8EVRS(n,s,b,o) REST_4EVRS(n,s,b,o); REST_4EVRS(n+4,s,b,o) 251c51584d5SScott Wood #define REST_16EVRS(n,s,b,o) REST_8EVRS(n,s,b,o); REST_8EVRS(n+8,s,b,o) 252c51584d5SScott Wood #define REST_32EVRS(n,s,b,o) REST_16EVRS(n,s,b,o); REST_16EVRS(n+16,s,b,o) 253b8b572e1SStephen Rothwell 254b8b572e1SStephen Rothwell /* Macros to adjust thread priority for hardware multithreading */ 255b8b572e1SStephen Rothwell #define HMT_VERY_LOW or 31,31,31 # very low priority 256b8b572e1SStephen Rothwell #define HMT_LOW or 1,1,1 257b8b572e1SStephen Rothwell #define HMT_MEDIUM_LOW or 6,6,6 # medium low priority 258b8b572e1SStephen Rothwell #define HMT_MEDIUM or 2,2,2 259b8b572e1SStephen Rothwell #define HMT_MEDIUM_HIGH or 5,5,5 # medium high priority 260b8b572e1SStephen Rothwell #define HMT_HIGH or 3,3,3 26150fb8ebeSBenjamin Herrenschmidt #define HMT_EXTRA_HIGH or 7,7,7 # power7 only 262b8b572e1SStephen Rothwell 263d72be892SMichael Neuling #ifdef CONFIG_PPC64 264d72be892SMichael Neuling #define ULONG_SIZE 8 265d72be892SMichael Neuling #else 266d72be892SMichael Neuling #define ULONG_SIZE 4 267d72be892SMichael Neuling #endif 2680b7673c3SMichael Neuling #define __VCPU_GPR(n) (VCPU_GPRS + (n * ULONG_SIZE)) 2690b7673c3SMichael Neuling #define VCPU_GPR(n) __VCPU_GPR(__REG_##n) 270d72be892SMichael Neuling 271b8b572e1SStephen Rothwell #ifdef __KERNEL__ 272b8b572e1SStephen Rothwell #ifdef CONFIG_PPC64 273b8b572e1SStephen Rothwell 27444ce6a5eSMichael Neuling #define STACKFRAMESIZE 256 2750b7673c3SMichael Neuling #define __STK_REG(i) (112 + ((i)-14)*8) 2760b7673c3SMichael Neuling #define STK_REG(i) __STK_REG(__REG_##i) 27744ce6a5eSMichael Neuling 2780b7673c3SMichael Neuling #define __STK_PARAM(i) (48 + ((i)-3)*8) 2790b7673c3SMichael Neuling #define STK_PARAM(i) __STK_PARAM(__REG_##i) 28044ce6a5eSMichael Neuling 281b8b572e1SStephen Rothwell #define XGLUE(a,b) a##b 282b8b572e1SStephen Rothwell #define GLUE(a,b) XGLUE(a,b) 283b8b572e1SStephen Rothwell 284b8b572e1SStephen Rothwell #define _GLOBAL(name) \ 285b8b572e1SStephen Rothwell .section ".text"; \ 286b8b572e1SStephen Rothwell .align 2 ; \ 287b8b572e1SStephen Rothwell .globl name; \ 288b8b572e1SStephen Rothwell .globl GLUE(.,name); \ 289b8b572e1SStephen Rothwell .section ".opd","aw"; \ 290b8b572e1SStephen Rothwell name: \ 291b8b572e1SStephen Rothwell .quad GLUE(.,name); \ 292b8b572e1SStephen Rothwell .quad .TOC.@tocbase; \ 293b8b572e1SStephen Rothwell .quad 0; \ 294b8b572e1SStephen Rothwell .previous; \ 295b8b572e1SStephen Rothwell .type GLUE(.,name),@function; \ 296b8b572e1SStephen Rothwell GLUE(.,name): 297b8b572e1SStephen Rothwell 298b8b572e1SStephen Rothwell #define _INIT_GLOBAL(name) \ 2999203fc9cSTim Abbott __REF; \ 300b8b572e1SStephen Rothwell .align 2 ; \ 301b8b572e1SStephen Rothwell .globl name; \ 302b8b572e1SStephen Rothwell .globl GLUE(.,name); \ 303b8b572e1SStephen Rothwell .section ".opd","aw"; \ 304b8b572e1SStephen Rothwell name: \ 305b8b572e1SStephen Rothwell .quad GLUE(.,name); \ 306b8b572e1SStephen Rothwell .quad .TOC.@tocbase; \ 307b8b572e1SStephen Rothwell .quad 0; \ 308b8b572e1SStephen Rothwell .previous; \ 309b8b572e1SStephen Rothwell .type GLUE(.,name),@function; \ 310b8b572e1SStephen Rothwell GLUE(.,name): 311b8b572e1SStephen Rothwell 312b8b572e1SStephen Rothwell #define _KPROBE(name) \ 313b8b572e1SStephen Rothwell .section ".kprobes.text","a"; \ 314b8b572e1SStephen Rothwell .align 2 ; \ 315b8b572e1SStephen Rothwell .globl name; \ 316b8b572e1SStephen Rothwell .globl GLUE(.,name); \ 317b8b572e1SStephen Rothwell .section ".opd","aw"; \ 318b8b572e1SStephen Rothwell name: \ 319b8b572e1SStephen Rothwell .quad GLUE(.,name); \ 320b8b572e1SStephen Rothwell .quad .TOC.@tocbase; \ 321b8b572e1SStephen Rothwell .quad 0; \ 322b8b572e1SStephen Rothwell .previous; \ 323b8b572e1SStephen Rothwell .type GLUE(.,name),@function; \ 324b8b572e1SStephen Rothwell GLUE(.,name): 325b8b572e1SStephen Rothwell 326b8b572e1SStephen Rothwell #define _STATIC(name) \ 327b8b572e1SStephen Rothwell .section ".text"; \ 328b8b572e1SStephen Rothwell .align 2 ; \ 329b8b572e1SStephen Rothwell .section ".opd","aw"; \ 330b8b572e1SStephen Rothwell name: \ 331b8b572e1SStephen Rothwell .quad GLUE(.,name); \ 332b8b572e1SStephen Rothwell .quad .TOC.@tocbase; \ 333b8b572e1SStephen Rothwell .quad 0; \ 334b8b572e1SStephen Rothwell .previous; \ 335b8b572e1SStephen Rothwell .type GLUE(.,name),@function; \ 336b8b572e1SStephen Rothwell GLUE(.,name): 337b8b572e1SStephen Rothwell 338b8b572e1SStephen Rothwell #define _INIT_STATIC(name) \ 3399203fc9cSTim Abbott __REF; \ 340b8b572e1SStephen Rothwell .align 2 ; \ 341b8b572e1SStephen Rothwell .section ".opd","aw"; \ 342b8b572e1SStephen Rothwell name: \ 343b8b572e1SStephen Rothwell .quad GLUE(.,name); \ 344b8b572e1SStephen Rothwell .quad .TOC.@tocbase; \ 345b8b572e1SStephen Rothwell .quad 0; \ 346b8b572e1SStephen Rothwell .previous; \ 347b8b572e1SStephen Rothwell .type GLUE(.,name),@function; \ 348b8b572e1SStephen Rothwell GLUE(.,name): 349b8b572e1SStephen Rothwell 350b8b572e1SStephen Rothwell #else /* 32-bit */ 351b8b572e1SStephen Rothwell 352b8b572e1SStephen Rothwell #define _ENTRY(n) \ 353b8b572e1SStephen Rothwell .globl n; \ 354b8b572e1SStephen Rothwell n: 355b8b572e1SStephen Rothwell 356b8b572e1SStephen Rothwell #define _GLOBAL(n) \ 357b8b572e1SStephen Rothwell .text; \ 358b8b572e1SStephen Rothwell .stabs __stringify(n:F-1),N_FUN,0,0,n;\ 359b8b572e1SStephen Rothwell .globl n; \ 360b8b572e1SStephen Rothwell n: 361b8b572e1SStephen Rothwell 362b8b572e1SStephen Rothwell #define _KPROBE(n) \ 363b8b572e1SStephen Rothwell .section ".kprobes.text","a"; \ 364b8b572e1SStephen Rothwell .globl n; \ 365b8b572e1SStephen Rothwell n: 366b8b572e1SStephen Rothwell 367b8b572e1SStephen Rothwell #endif 368b8b572e1SStephen Rothwell 369b8b572e1SStephen Rothwell /* 370b8b572e1SStephen Rothwell * LOAD_REG_IMMEDIATE(rn, expr) 371b8b572e1SStephen Rothwell * Loads the value of the constant expression 'expr' into register 'rn' 372b8b572e1SStephen Rothwell * using immediate instructions only. Use this when it's important not 373b8b572e1SStephen Rothwell * to reference other data (i.e. on ppc64 when the TOC pointer is not 374e31aa453SPaul Mackerras * valid) and when 'expr' is a constant or absolute address. 375b8b572e1SStephen Rothwell * 376b8b572e1SStephen Rothwell * LOAD_REG_ADDR(rn, name) 377b8b572e1SStephen Rothwell * Loads the address of label 'name' into register 'rn'. Use this when 378b8b572e1SStephen Rothwell * you don't particularly need immediate instructions only, but you need 379b8b572e1SStephen Rothwell * the whole address in one register (e.g. it's a structure address and 380b8b572e1SStephen Rothwell * you want to access various offsets within it). On ppc32 this is 381b8b572e1SStephen Rothwell * identical to LOAD_REG_IMMEDIATE. 382b8b572e1SStephen Rothwell * 383b8b572e1SStephen Rothwell * LOAD_REG_ADDRBASE(rn, name) 384b8b572e1SStephen Rothwell * ADDROFF(name) 385b8b572e1SStephen Rothwell * LOAD_REG_ADDRBASE loads part of the address of label 'name' into 386b8b572e1SStephen Rothwell * register 'rn'. ADDROFF(name) returns the remainder of the address as 387b8b572e1SStephen Rothwell * a constant expression. ADDROFF(name) is a signed expression < 16 bits 388b8b572e1SStephen Rothwell * in size, so is suitable for use directly as an offset in load and store 389b8b572e1SStephen Rothwell * instructions. Use this when loading/storing a single word or less as: 390b8b572e1SStephen Rothwell * LOAD_REG_ADDRBASE(rX, name) 391b8b572e1SStephen Rothwell * ld rY,ADDROFF(name)(rX) 392b8b572e1SStephen Rothwell */ 393b8b572e1SStephen Rothwell #ifdef __powerpc64__ 394b8b572e1SStephen Rothwell #define LOAD_REG_IMMEDIATE(reg,expr) \ 395564aa5cfSMichael Neuling lis reg,(expr)@highest; \ 396564aa5cfSMichael Neuling ori reg,reg,(expr)@higher; \ 397564aa5cfSMichael Neuling rldicr reg,reg,32,31; \ 398564aa5cfSMichael Neuling oris reg,reg,(expr)@h; \ 399564aa5cfSMichael Neuling ori reg,reg,(expr)@l; 400b8b572e1SStephen Rothwell 401b8b572e1SStephen Rothwell #define LOAD_REG_ADDR(reg,name) \ 402564aa5cfSMichael Neuling ld reg,name@got(r2) 403b8b572e1SStephen Rothwell 404b8b572e1SStephen Rothwell #define LOAD_REG_ADDRBASE(reg,name) LOAD_REG_ADDR(reg,name) 405b8b572e1SStephen Rothwell #define ADDROFF(name) 0 406b8b572e1SStephen Rothwell 407b8b572e1SStephen Rothwell /* offsets for stack frame layout */ 408b8b572e1SStephen Rothwell #define LRSAVE 16 409b8b572e1SStephen Rothwell 410b8b572e1SStephen Rothwell #else /* 32-bit */ 411b8b572e1SStephen Rothwell 412b8b572e1SStephen Rothwell #define LOAD_REG_IMMEDIATE(reg,expr) \ 413564aa5cfSMichael Neuling lis reg,(expr)@ha; \ 414564aa5cfSMichael Neuling addi reg,reg,(expr)@l; 415b8b572e1SStephen Rothwell 416b8b572e1SStephen Rothwell #define LOAD_REG_ADDR(reg,name) LOAD_REG_IMMEDIATE(reg, name) 417b8b572e1SStephen Rothwell 418564aa5cfSMichael Neuling #define LOAD_REG_ADDRBASE(reg, name) lis reg,name@ha 419b8b572e1SStephen Rothwell #define ADDROFF(name) name@l 420b8b572e1SStephen Rothwell 421b8b572e1SStephen Rothwell /* offsets for stack frame layout */ 422b8b572e1SStephen Rothwell #define LRSAVE 4 423b8b572e1SStephen Rothwell 424b8b572e1SStephen Rothwell #endif 425b8b572e1SStephen Rothwell 426b8b572e1SStephen Rothwell /* various errata or part fixups */ 427b8b572e1SStephen Rothwell #ifdef CONFIG_PPC601_SYNC_FIX 428b8b572e1SStephen Rothwell #define SYNC \ 429b8b572e1SStephen Rothwell BEGIN_FTR_SECTION \ 430b8b572e1SStephen Rothwell sync; \ 431b8b572e1SStephen Rothwell isync; \ 432b8b572e1SStephen Rothwell END_FTR_SECTION_IFSET(CPU_FTR_601) 433b8b572e1SStephen Rothwell #define SYNC_601 \ 434b8b572e1SStephen Rothwell BEGIN_FTR_SECTION \ 435b8b572e1SStephen Rothwell sync; \ 436b8b572e1SStephen Rothwell END_FTR_SECTION_IFSET(CPU_FTR_601) 437b8b572e1SStephen Rothwell #define ISYNC_601 \ 438b8b572e1SStephen Rothwell BEGIN_FTR_SECTION \ 439b8b572e1SStephen Rothwell isync; \ 440b8b572e1SStephen Rothwell END_FTR_SECTION_IFSET(CPU_FTR_601) 441b8b572e1SStephen Rothwell #else 442b8b572e1SStephen Rothwell #define SYNC 443b8b572e1SStephen Rothwell #define SYNC_601 444b8b572e1SStephen Rothwell #define ISYNC_601 445b8b572e1SStephen Rothwell #endif 446b8b572e1SStephen Rothwell 447d52459caSScott Wood #if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_FSL_BOOK3E) 448b8b572e1SStephen Rothwell #define MFTB(dest) \ 449beb2dc0aSScott Wood 90: mfspr dest, SPRN_TBRL; \ 450b8b572e1SStephen Rothwell BEGIN_FTR_SECTION_NESTED(96); \ 451b8b572e1SStephen Rothwell cmpwi dest,0; \ 452b8b572e1SStephen Rothwell beq- 90b; \ 453b8b572e1SStephen Rothwell END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96) 454b8b572e1SStephen Rothwell #else 455beb2dc0aSScott Wood #define MFTB(dest) mfspr dest, SPRN_TBRL 456b8b572e1SStephen Rothwell #endif 457b8b572e1SStephen Rothwell 458b8b572e1SStephen Rothwell #ifndef CONFIG_SMP 459b8b572e1SStephen Rothwell #define TLBSYNC 460b8b572e1SStephen Rothwell #else /* CONFIG_SMP */ 461b8b572e1SStephen Rothwell /* tlbsync is not implemented on 601 */ 462b8b572e1SStephen Rothwell #define TLBSYNC \ 463b8b572e1SStephen Rothwell BEGIN_FTR_SECTION \ 464b8b572e1SStephen Rothwell tlbsync; \ 465b8b572e1SStephen Rothwell sync; \ 466b8b572e1SStephen Rothwell END_FTR_SECTION_IFCLR(CPU_FTR_601) 467b8b572e1SStephen Rothwell #endif 468b8b572e1SStephen Rothwell 469694caf02SAnton Blanchard #ifdef CONFIG_PPC64 470694caf02SAnton Blanchard #define MTOCRF(FXM, RS) \ 471694caf02SAnton Blanchard BEGIN_FTR_SECTION_NESTED(848); \ 47286e32fdcSMichael Neuling mtcrf (FXM), RS; \ 473694caf02SAnton Blanchard FTR_SECTION_ELSE_NESTED(848); \ 47486e32fdcSMichael Neuling mtocrf (FXM), RS; \ 475694caf02SAnton Blanchard ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_NOEXECUTE, 848) 47613e7a8e8SHaren Myneni 47713e7a8e8SHaren Myneni /* 47813e7a8e8SHaren Myneni * PPR restore macros used in entry_64.S 47913e7a8e8SHaren Myneni * Used for P7 or later processors 48013e7a8e8SHaren Myneni */ 48113e7a8e8SHaren Myneni #define HMT_MEDIUM_LOW_HAS_PPR \ 48213e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(944) \ 48313e7a8e8SHaren Myneni HMT_MEDIUM_LOW; \ 48413e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,944) 48513e7a8e8SHaren Myneni 48613e7a8e8SHaren Myneni #define SET_DEFAULT_THREAD_PPR(ra, rb) \ 48713e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(945) \ 48813e7a8e8SHaren Myneni lis ra,INIT_PPR@highest; /* default ppr=3 */ \ 48913e7a8e8SHaren Myneni ld rb,PACACURRENT(r13); \ 49013e7a8e8SHaren Myneni sldi ra,ra,32; /* 11- 13 bits are used for ppr */ \ 49113e7a8e8SHaren Myneni std ra,TASKTHREADPPR(rb); \ 49213e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,945) 49313e7a8e8SHaren Myneni 49413e7a8e8SHaren Myneni #define RESTORE_PPR(ra, rb) \ 49513e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(946) \ 49613e7a8e8SHaren Myneni ld ra,PACACURRENT(r13); \ 49713e7a8e8SHaren Myneni ld rb,TASKTHREADPPR(ra); \ 49813e7a8e8SHaren Myneni mtspr SPRN_PPR,rb; /* Restore PPR */ \ 49913e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,946) 50013e7a8e8SHaren Myneni 501694caf02SAnton Blanchard #endif 502b8b572e1SStephen Rothwell 503b8b572e1SStephen Rothwell /* 504b8b572e1SStephen Rothwell * This instruction is not implemented on the PPC 603 or 601; however, on 505b8b572e1SStephen Rothwell * the 403GCX and 405GP tlbia IS defined and tlbie is not. 506b8b572e1SStephen Rothwell * All of these instructions exist in the 8xx, they have magical powers, 507b8b572e1SStephen Rothwell * and they must be used. 508b8b572e1SStephen Rothwell */ 509b8b572e1SStephen Rothwell 510b8b572e1SStephen Rothwell #if !defined(CONFIG_4xx) && !defined(CONFIG_8xx) 511b8b572e1SStephen Rothwell #define tlbia \ 512b8b572e1SStephen Rothwell li r4,1024; \ 513b8b572e1SStephen Rothwell mtctr r4; \ 514b8b572e1SStephen Rothwell lis r4,KERNELBASE@h; \ 515b8b572e1SStephen Rothwell 0: tlbie r4; \ 516b8b572e1SStephen Rothwell addi r4,r4,0x1000; \ 517b8b572e1SStephen Rothwell bdnz 0b 518b8b572e1SStephen Rothwell #endif 519b8b572e1SStephen Rothwell 520b8b572e1SStephen Rothwell 521b8b572e1SStephen Rothwell #ifdef CONFIG_IBM440EP_ERR42 522b8b572e1SStephen Rothwell #define PPC440EP_ERR42 isync 523b8b572e1SStephen Rothwell #else 524b8b572e1SStephen Rothwell #define PPC440EP_ERR42 525b8b572e1SStephen Rothwell #endif 526b8b572e1SStephen Rothwell 527a515348fSMichael Neuling /* The following stops all load and store data streams associated with stream 528a515348fSMichael Neuling * ID (ie. streams created explicitly). The embedded and server mnemonics for 529a515348fSMichael Neuling * dcbt are different so we use machine "power4" here explicitly. 530a515348fSMichael Neuling */ 531a515348fSMichael Neuling #define DCBT_STOP_ALL_STREAM_IDS(scratch) \ 532a515348fSMichael Neuling .machine push ; \ 533a515348fSMichael Neuling .machine "power4" ; \ 534a515348fSMichael Neuling lis scratch,0x60000000@h; \ 535a515348fSMichael Neuling dcbt r0,scratch,0b01010; \ 536a515348fSMichael Neuling .machine pop 537a515348fSMichael Neuling 53844c58cccSBenjamin Herrenschmidt /* 53944c58cccSBenjamin Herrenschmidt * toreal/fromreal/tophys/tovirt macros. 32-bit BookE makes them 54044c58cccSBenjamin Herrenschmidt * keep the address intact to be compatible with code shared with 54144c58cccSBenjamin Herrenschmidt * 32-bit classic. 54244c58cccSBenjamin Herrenschmidt * 54344c58cccSBenjamin Herrenschmidt * On the other hand, I find it useful to have them behave as expected 54444c58cccSBenjamin Herrenschmidt * by their name (ie always do the addition) on 64-bit BookE 54544c58cccSBenjamin Herrenschmidt */ 54644c58cccSBenjamin Herrenschmidt #if defined(CONFIG_BOOKE) && !defined(CONFIG_PPC64) 547b8b572e1SStephen Rothwell #define toreal(rd) 548b8b572e1SStephen Rothwell #define fromreal(rd) 549b8b572e1SStephen Rothwell 550b8b572e1SStephen Rothwell /* 551b8b572e1SStephen Rothwell * We use addis to ensure compatibility with the "classic" ppc versions of 552b8b572e1SStephen Rothwell * these macros, which use rs = 0 to get the tophys offset in rd, rather than 553b8b572e1SStephen Rothwell * converting the address in r0, and so this version has to do that too 554b8b572e1SStephen Rothwell * (i.e. set register rd to 0 when rs == 0). 555b8b572e1SStephen Rothwell */ 556b8b572e1SStephen Rothwell #define tophys(rd,rs) \ 557b8b572e1SStephen Rothwell addis rd,rs,0 558b8b572e1SStephen Rothwell 559b8b572e1SStephen Rothwell #define tovirt(rd,rs) \ 560b8b572e1SStephen Rothwell addis rd,rs,0 561b8b572e1SStephen Rothwell 562b8b572e1SStephen Rothwell #elif defined(CONFIG_PPC64) 563b8b572e1SStephen Rothwell #define toreal(rd) /* we can access c000... in real mode */ 564b8b572e1SStephen Rothwell #define fromreal(rd) 565b8b572e1SStephen Rothwell 566b8b572e1SStephen Rothwell #define tophys(rd,rs) \ 567b8b572e1SStephen Rothwell clrldi rd,rs,2 568b8b572e1SStephen Rothwell 569b8b572e1SStephen Rothwell #define tovirt(rd,rs) \ 570b8b572e1SStephen Rothwell rotldi rd,rs,16; \ 571b8b572e1SStephen Rothwell ori rd,rd,((KERNELBASE>>48)&0xFFFF);\ 572b8b572e1SStephen Rothwell rotldi rd,rd,48 573b8b572e1SStephen Rothwell #else 574b8b572e1SStephen Rothwell /* 575b8b572e1SStephen Rothwell * On APUS (Amiga PowerPC cpu upgrade board), we don't know the 576b8b572e1SStephen Rothwell * physical base address of RAM at compile time. 577b8b572e1SStephen Rothwell */ 578b8b572e1SStephen Rothwell #define toreal(rd) tophys(rd,rd) 579b8b572e1SStephen Rothwell #define fromreal(rd) tovirt(rd,rd) 580b8b572e1SStephen Rothwell 581b8b572e1SStephen Rothwell #define tophys(rd,rs) \ 582ccdcef72SDale Farnsworth 0: addis rd,rs,-PAGE_OFFSET@h; \ 583b8b572e1SStephen Rothwell .section ".vtop_fixup","aw"; \ 584b8b572e1SStephen Rothwell .align 1; \ 585b8b572e1SStephen Rothwell .long 0b; \ 586b8b572e1SStephen Rothwell .previous 587b8b572e1SStephen Rothwell 588b8b572e1SStephen Rothwell #define tovirt(rd,rs) \ 589ccdcef72SDale Farnsworth 0: addis rd,rs,PAGE_OFFSET@h; \ 590b8b572e1SStephen Rothwell .section ".ptov_fixup","aw"; \ 591b8b572e1SStephen Rothwell .align 1; \ 592b8b572e1SStephen Rothwell .long 0b; \ 593b8b572e1SStephen Rothwell .previous 594b8b572e1SStephen Rothwell #endif 595b8b572e1SStephen Rothwell 59644c58cccSBenjamin Herrenschmidt #ifdef CONFIG_PPC_BOOK3S_64 597b8b572e1SStephen Rothwell #define RFI rfid 598b8b572e1SStephen Rothwell #define MTMSRD(r) mtmsrd r 599b38c77d8SBenjamin Herrenschmidt #define MTMSR_EERI(reg) mtmsrd reg,1 600b8b572e1SStephen Rothwell #else 601b8b572e1SStephen Rothwell #define FIX_SRR1(ra, rb) 602b8b572e1SStephen Rothwell #ifndef CONFIG_40x 603b8b572e1SStephen Rothwell #define RFI rfi 604b8b572e1SStephen Rothwell #else 605b8b572e1SStephen Rothwell #define RFI rfi; b . /* Prevent prefetch past rfi */ 606b8b572e1SStephen Rothwell #endif 607b8b572e1SStephen Rothwell #define MTMSRD(r) mtmsr r 608b38c77d8SBenjamin Herrenschmidt #define MTMSR_EERI(reg) mtmsr reg 609b8b572e1SStephen Rothwell #define CLR_TOP32(r) 610b8b572e1SStephen Rothwell #endif 611b8b572e1SStephen Rothwell 612b8b572e1SStephen Rothwell #endif /* __KERNEL__ */ 613b8b572e1SStephen Rothwell 614b8b572e1SStephen Rothwell /* The boring bits... */ 615b8b572e1SStephen Rothwell 616b8b572e1SStephen Rothwell /* Condition Register Bit Fields */ 617b8b572e1SStephen Rothwell 618b8b572e1SStephen Rothwell #define cr0 0 619b8b572e1SStephen Rothwell #define cr1 1 620b8b572e1SStephen Rothwell #define cr2 2 621b8b572e1SStephen Rothwell #define cr3 3 622b8b572e1SStephen Rothwell #define cr4 4 623b8b572e1SStephen Rothwell #define cr5 5 624b8b572e1SStephen Rothwell #define cr6 6 625b8b572e1SStephen Rothwell #define cr7 7 626b8b572e1SStephen Rothwell 627b8b572e1SStephen Rothwell 6289a13a524SMichael Neuling /* 6299a13a524SMichael Neuling * General Purpose Registers (GPRs) 6309a13a524SMichael Neuling * 6319a13a524SMichael Neuling * The lower case r0-r31 should be used in preference to the upper 6329a13a524SMichael Neuling * case R0-R31 as they provide more error checking in the assembler. 6339a13a524SMichael Neuling * Use R0-31 only when really nessesary. 6349a13a524SMichael Neuling */ 635b8b572e1SStephen Rothwell 6369a13a524SMichael Neuling #define r0 %r0 6379a13a524SMichael Neuling #define r1 %r1 6389a13a524SMichael Neuling #define r2 %r2 6399a13a524SMichael Neuling #define r3 %r3 6409a13a524SMichael Neuling #define r4 %r4 6419a13a524SMichael Neuling #define r5 %r5 6429a13a524SMichael Neuling #define r6 %r6 6439a13a524SMichael Neuling #define r7 %r7 6449a13a524SMichael Neuling #define r8 %r8 6459a13a524SMichael Neuling #define r9 %r9 6469a13a524SMichael Neuling #define r10 %r10 6479a13a524SMichael Neuling #define r11 %r11 6489a13a524SMichael Neuling #define r12 %r12 6499a13a524SMichael Neuling #define r13 %r13 6509a13a524SMichael Neuling #define r14 %r14 6519a13a524SMichael Neuling #define r15 %r15 6529a13a524SMichael Neuling #define r16 %r16 6539a13a524SMichael Neuling #define r17 %r17 6549a13a524SMichael Neuling #define r18 %r18 6559a13a524SMichael Neuling #define r19 %r19 6569a13a524SMichael Neuling #define r20 %r20 6579a13a524SMichael Neuling #define r21 %r21 6589a13a524SMichael Neuling #define r22 %r22 6599a13a524SMichael Neuling #define r23 %r23 6609a13a524SMichael Neuling #define r24 %r24 6619a13a524SMichael Neuling #define r25 %r25 6629a13a524SMichael Neuling #define r26 %r26 6639a13a524SMichael Neuling #define r27 %r27 6649a13a524SMichael Neuling #define r28 %r28 6659a13a524SMichael Neuling #define r29 %r29 6669a13a524SMichael Neuling #define r30 %r30 6679a13a524SMichael Neuling #define r31 %r31 668b8b572e1SStephen Rothwell 669b8b572e1SStephen Rothwell 670b8b572e1SStephen Rothwell /* Floating Point Registers (FPRs) */ 671b8b572e1SStephen Rothwell 672b8b572e1SStephen Rothwell #define fr0 0 673b8b572e1SStephen Rothwell #define fr1 1 674b8b572e1SStephen Rothwell #define fr2 2 675b8b572e1SStephen Rothwell #define fr3 3 676b8b572e1SStephen Rothwell #define fr4 4 677b8b572e1SStephen Rothwell #define fr5 5 678b8b572e1SStephen Rothwell #define fr6 6 679b8b572e1SStephen Rothwell #define fr7 7 680b8b572e1SStephen Rothwell #define fr8 8 681b8b572e1SStephen Rothwell #define fr9 9 682b8b572e1SStephen Rothwell #define fr10 10 683b8b572e1SStephen Rothwell #define fr11 11 684b8b572e1SStephen Rothwell #define fr12 12 685b8b572e1SStephen Rothwell #define fr13 13 686b8b572e1SStephen Rothwell #define fr14 14 687b8b572e1SStephen Rothwell #define fr15 15 688b8b572e1SStephen Rothwell #define fr16 16 689b8b572e1SStephen Rothwell #define fr17 17 690b8b572e1SStephen Rothwell #define fr18 18 691b8b572e1SStephen Rothwell #define fr19 19 692b8b572e1SStephen Rothwell #define fr20 20 693b8b572e1SStephen Rothwell #define fr21 21 694b8b572e1SStephen Rothwell #define fr22 22 695b8b572e1SStephen Rothwell #define fr23 23 696b8b572e1SStephen Rothwell #define fr24 24 697b8b572e1SStephen Rothwell #define fr25 25 698b8b572e1SStephen Rothwell #define fr26 26 699b8b572e1SStephen Rothwell #define fr27 27 700b8b572e1SStephen Rothwell #define fr28 28 701b8b572e1SStephen Rothwell #define fr29 29 702b8b572e1SStephen Rothwell #define fr30 30 703b8b572e1SStephen Rothwell #define fr31 31 704b8b572e1SStephen Rothwell 705b8b572e1SStephen Rothwell /* AltiVec Registers (VPRs) */ 706b8b572e1SStephen Rothwell 707b8b572e1SStephen Rothwell #define vr0 0 708b8b572e1SStephen Rothwell #define vr1 1 709b8b572e1SStephen Rothwell #define vr2 2 710b8b572e1SStephen Rothwell #define vr3 3 711b8b572e1SStephen Rothwell #define vr4 4 712b8b572e1SStephen Rothwell #define vr5 5 713b8b572e1SStephen Rothwell #define vr6 6 714b8b572e1SStephen Rothwell #define vr7 7 715b8b572e1SStephen Rothwell #define vr8 8 716b8b572e1SStephen Rothwell #define vr9 9 717b8b572e1SStephen Rothwell #define vr10 10 718b8b572e1SStephen Rothwell #define vr11 11 719b8b572e1SStephen Rothwell #define vr12 12 720b8b572e1SStephen Rothwell #define vr13 13 721b8b572e1SStephen Rothwell #define vr14 14 722b8b572e1SStephen Rothwell #define vr15 15 723b8b572e1SStephen Rothwell #define vr16 16 724b8b572e1SStephen Rothwell #define vr17 17 725b8b572e1SStephen Rothwell #define vr18 18 726b8b572e1SStephen Rothwell #define vr19 19 727b8b572e1SStephen Rothwell #define vr20 20 728b8b572e1SStephen Rothwell #define vr21 21 729b8b572e1SStephen Rothwell #define vr22 22 730b8b572e1SStephen Rothwell #define vr23 23 731b8b572e1SStephen Rothwell #define vr24 24 732b8b572e1SStephen Rothwell #define vr25 25 733b8b572e1SStephen Rothwell #define vr26 26 734b8b572e1SStephen Rothwell #define vr27 27 735b8b572e1SStephen Rothwell #define vr28 28 736b8b572e1SStephen Rothwell #define vr29 29 737b8b572e1SStephen Rothwell #define vr30 30 738b8b572e1SStephen Rothwell #define vr31 31 739b8b572e1SStephen Rothwell 740b8b572e1SStephen Rothwell /* VSX Registers (VSRs) */ 741b8b572e1SStephen Rothwell 742b8b572e1SStephen Rothwell #define vsr0 0 743b8b572e1SStephen Rothwell #define vsr1 1 744b8b572e1SStephen Rothwell #define vsr2 2 745b8b572e1SStephen Rothwell #define vsr3 3 746b8b572e1SStephen Rothwell #define vsr4 4 747b8b572e1SStephen Rothwell #define vsr5 5 748b8b572e1SStephen Rothwell #define vsr6 6 749b8b572e1SStephen Rothwell #define vsr7 7 750b8b572e1SStephen Rothwell #define vsr8 8 751b8b572e1SStephen Rothwell #define vsr9 9 752b8b572e1SStephen Rothwell #define vsr10 10 753b8b572e1SStephen Rothwell #define vsr11 11 754b8b572e1SStephen Rothwell #define vsr12 12 755b8b572e1SStephen Rothwell #define vsr13 13 756b8b572e1SStephen Rothwell #define vsr14 14 757b8b572e1SStephen Rothwell #define vsr15 15 758b8b572e1SStephen Rothwell #define vsr16 16 759b8b572e1SStephen Rothwell #define vsr17 17 760b8b572e1SStephen Rothwell #define vsr18 18 761b8b572e1SStephen Rothwell #define vsr19 19 762b8b572e1SStephen Rothwell #define vsr20 20 763b8b572e1SStephen Rothwell #define vsr21 21 764b8b572e1SStephen Rothwell #define vsr22 22 765b8b572e1SStephen Rothwell #define vsr23 23 766b8b572e1SStephen Rothwell #define vsr24 24 767b8b572e1SStephen Rothwell #define vsr25 25 768b8b572e1SStephen Rothwell #define vsr26 26 769b8b572e1SStephen Rothwell #define vsr27 27 770b8b572e1SStephen Rothwell #define vsr28 28 771b8b572e1SStephen Rothwell #define vsr29 29 772b8b572e1SStephen Rothwell #define vsr30 30 773b8b572e1SStephen Rothwell #define vsr31 31 774b8b572e1SStephen Rothwell #define vsr32 32 775b8b572e1SStephen Rothwell #define vsr33 33 776b8b572e1SStephen Rothwell #define vsr34 34 777b8b572e1SStephen Rothwell #define vsr35 35 778b8b572e1SStephen Rothwell #define vsr36 36 779b8b572e1SStephen Rothwell #define vsr37 37 780b8b572e1SStephen Rothwell #define vsr38 38 781b8b572e1SStephen Rothwell #define vsr39 39 782b8b572e1SStephen Rothwell #define vsr40 40 783b8b572e1SStephen Rothwell #define vsr41 41 784b8b572e1SStephen Rothwell #define vsr42 42 785b8b572e1SStephen Rothwell #define vsr43 43 786b8b572e1SStephen Rothwell #define vsr44 44 787b8b572e1SStephen Rothwell #define vsr45 45 788b8b572e1SStephen Rothwell #define vsr46 46 789b8b572e1SStephen Rothwell #define vsr47 47 790b8b572e1SStephen Rothwell #define vsr48 48 791b8b572e1SStephen Rothwell #define vsr49 49 792b8b572e1SStephen Rothwell #define vsr50 50 793b8b572e1SStephen Rothwell #define vsr51 51 794b8b572e1SStephen Rothwell #define vsr52 52 795b8b572e1SStephen Rothwell #define vsr53 53 796b8b572e1SStephen Rothwell #define vsr54 54 797b8b572e1SStephen Rothwell #define vsr55 55 798b8b572e1SStephen Rothwell #define vsr56 56 799b8b572e1SStephen Rothwell #define vsr57 57 800b8b572e1SStephen Rothwell #define vsr58 58 801b8b572e1SStephen Rothwell #define vsr59 59 802b8b572e1SStephen Rothwell #define vsr60 60 803b8b572e1SStephen Rothwell #define vsr61 61 804b8b572e1SStephen Rothwell #define vsr62 62 805b8b572e1SStephen Rothwell #define vsr63 63 806b8b572e1SStephen Rothwell 807b8b572e1SStephen Rothwell /* SPE Registers (EVPRs) */ 808b8b572e1SStephen Rothwell 809b8b572e1SStephen Rothwell #define evr0 0 810b8b572e1SStephen Rothwell #define evr1 1 811b8b572e1SStephen Rothwell #define evr2 2 812b8b572e1SStephen Rothwell #define evr3 3 813b8b572e1SStephen Rothwell #define evr4 4 814b8b572e1SStephen Rothwell #define evr5 5 815b8b572e1SStephen Rothwell #define evr6 6 816b8b572e1SStephen Rothwell #define evr7 7 817b8b572e1SStephen Rothwell #define evr8 8 818b8b572e1SStephen Rothwell #define evr9 9 819b8b572e1SStephen Rothwell #define evr10 10 820b8b572e1SStephen Rothwell #define evr11 11 821b8b572e1SStephen Rothwell #define evr12 12 822b8b572e1SStephen Rothwell #define evr13 13 823b8b572e1SStephen Rothwell #define evr14 14 824b8b572e1SStephen Rothwell #define evr15 15 825b8b572e1SStephen Rothwell #define evr16 16 826b8b572e1SStephen Rothwell #define evr17 17 827b8b572e1SStephen Rothwell #define evr18 18 828b8b572e1SStephen Rothwell #define evr19 19 829b8b572e1SStephen Rothwell #define evr20 20 830b8b572e1SStephen Rothwell #define evr21 21 831b8b572e1SStephen Rothwell #define evr22 22 832b8b572e1SStephen Rothwell #define evr23 23 833b8b572e1SStephen Rothwell #define evr24 24 834b8b572e1SStephen Rothwell #define evr25 25 835b8b572e1SStephen Rothwell #define evr26 26 836b8b572e1SStephen Rothwell #define evr27 27 837b8b572e1SStephen Rothwell #define evr28 28 838b8b572e1SStephen Rothwell #define evr29 29 839b8b572e1SStephen Rothwell #define evr30 30 840b8b572e1SStephen Rothwell #define evr31 31 841b8b572e1SStephen Rothwell 842b8b572e1SStephen Rothwell /* some stab codes */ 843b8b572e1SStephen Rothwell #define N_FUN 36 844b8b572e1SStephen Rothwell #define N_RSYM 64 845b8b572e1SStephen Rothwell #define N_SLINE 68 846b8b572e1SStephen Rothwell #define N_SO 100 847b8b572e1SStephen Rothwell 8485c0484e2SBenjamin Herrenschmidt /* 8495c0484e2SBenjamin Herrenschmidt * Create an endian fixup trampoline 8505c0484e2SBenjamin Herrenschmidt * 8515c0484e2SBenjamin Herrenschmidt * This starts with a "tdi 0,0,0x48" instruction which is 8525c0484e2SBenjamin Herrenschmidt * essentially a "trap never", and thus akin to a nop. 8535c0484e2SBenjamin Herrenschmidt * 8545c0484e2SBenjamin Herrenschmidt * The opcode for this instruction read with the wrong endian 8555c0484e2SBenjamin Herrenschmidt * however results in a b . + 8 8565c0484e2SBenjamin Herrenschmidt * 8575c0484e2SBenjamin Herrenschmidt * So essentially we use that trick to execute the following 8585c0484e2SBenjamin Herrenschmidt * trampoline in "reverse endian" if we are running with the 8595c0484e2SBenjamin Herrenschmidt * MSR_LE bit set the "wrong" way for whatever endianness the 8605c0484e2SBenjamin Herrenschmidt * kernel is built for. 8615c0484e2SBenjamin Herrenschmidt */ 862b8b572e1SStephen Rothwell 8635c0484e2SBenjamin Herrenschmidt #ifdef CONFIG_PPC_BOOK3E 8645c0484e2SBenjamin Herrenschmidt #define FIXUP_ENDIAN 8655c0484e2SBenjamin Herrenschmidt #else 8665c0484e2SBenjamin Herrenschmidt #define FIXUP_ENDIAN \ 8675c0484e2SBenjamin Herrenschmidt tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \ 8685c0484e2SBenjamin Herrenschmidt b $+36; /* Skip trampoline if endian is good */ \ 8695c0484e2SBenjamin Herrenschmidt .long 0x05009f42; /* bcl 20,31,$+4 */ \ 8705c0484e2SBenjamin Herrenschmidt .long 0xa602487d; /* mflr r10 */ \ 8715c0484e2SBenjamin Herrenschmidt .long 0x1c004a39; /* addi r10,r10,28 */ \ 8725c0484e2SBenjamin Herrenschmidt .long 0xa600607d; /* mfmsr r11 */ \ 8735c0484e2SBenjamin Herrenschmidt .long 0x01006b69; /* xori r11,r11,1 */ \ 8745c0484e2SBenjamin Herrenschmidt .long 0xa6035a7d; /* mtsrr0 r10 */ \ 8755c0484e2SBenjamin Herrenschmidt .long 0xa6037b7d; /* mtsrr1 r11 */ \ 8765c0484e2SBenjamin Herrenschmidt .long 0x2400004c /* rfid */ 8775c0484e2SBenjamin Herrenschmidt #endif /* !CONFIG_PPC_BOOK3E */ 8785c0484e2SBenjamin Herrenschmidt #endif /* __ASSEMBLY__ */ 879b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_PPC_ASM_H */ 880