Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 1995-1999 Gary Thomas, Paul Mackerras, Cort Dougan. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | */ |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 4 | #ifndef _ASM_POWERPC_PPC_ASM_H |
| 5 | #define _ASM_POWERPC_PPC_ASM_H |
| 6 | |
Tim Abbott | 9203fc9 | 2009-04-27 14:02:24 -0400 | [diff] [blame] | 7 | #include <linux/init.h> |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 8 | #include <linux/stringify.h> |
David Gibson | 3ddfbcf | 2005-11-10 12:56:55 +1100 | [diff] [blame] | 9 | #include <asm/asm-compat.h> |
Michael Neuling | 9c75a31 | 2008-06-26 17:07:48 +1000 | [diff] [blame] | 10 | #include <asm/processor.h> |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 11 | #include <asm/ppc-opcode.h> |
Paul Mackerras | cf9efce | 2010-08-26 19:56:43 +0000 | [diff] [blame] | 12 | #include <asm/firmware.h> |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 13 | |
David Gibson | 3ddfbcf | 2005-11-10 12:56:55 +1100 | [diff] [blame] | 14 | #ifndef __ASSEMBLY__ |
| 15 | #error __FILE__ should only be used in assembler files |
| 16 | #else |
| 17 | |
| 18 | #define SZL (BITS_PER_LONG/8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | /* |
Paul Mackerras | c6622f6 | 2006-02-24 10:06:59 +1100 | [diff] [blame] | 21 | * Stuff for accurate CPU time accounting. |
| 22 | * These macros handle transitions between user and system state |
| 23 | * in exception entry and exit and accumulate time to the |
| 24 | * user_time and system_time fields in the paca. |
| 25 | */ |
| 26 | |
Frederic Weisbecker | abf917c | 2012-07-25 07:56:04 +0200 | [diff] [blame] | 27 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
Paul Mackerras | c6622f6 | 2006-02-24 10:06:59 +1100 | [diff] [blame] | 28 | #define ACCOUNT_CPU_USER_ENTRY(ra, rb) |
| 29 | #define ACCOUNT_CPU_USER_EXIT(ra, rb) |
Paul Mackerras | cf9efce | 2010-08-26 19:56:43 +0000 | [diff] [blame] | 30 | #define ACCOUNT_STOLEN_TIME |
Paul Mackerras | c6622f6 | 2006-02-24 10:06:59 +1100 | [diff] [blame] | 31 | #else |
| 32 | #define ACCOUNT_CPU_USER_ENTRY(ra, rb) \ |
Paul Mackerras | cf9efce | 2010-08-26 19:56:43 +0000 | [diff] [blame] | 33 | MFTB(ra); /* get timebase */ \ |
| 34 | ld rb,PACA_STARTTIME_USER(r13); \ |
| 35 | std ra,PACA_STARTTIME(r13); \ |
Paul Mackerras | c6622f6 | 2006-02-24 10:06:59 +1100 | [diff] [blame] | 36 | subf rb,rb,ra; /* subtract start value */ \ |
| 37 | ld ra,PACA_USER_TIME(r13); \ |
| 38 | add ra,ra,rb; /* add on to user time */ \ |
| 39 | std ra,PACA_USER_TIME(r13); \ |
Paul Mackerras | c6622f6 | 2006-02-24 10:06:59 +1100 | [diff] [blame] | 40 | |
| 41 | #define ACCOUNT_CPU_USER_EXIT(ra, rb) \ |
Paul Mackerras | cf9efce | 2010-08-26 19:56:43 +0000 | [diff] [blame] | 42 | MFTB(ra); /* get timebase */ \ |
| 43 | ld rb,PACA_STARTTIME(r13); \ |
| 44 | std ra,PACA_STARTTIME_USER(r13); \ |
Paul Mackerras | c6622f6 | 2006-02-24 10:06:59 +1100 | [diff] [blame] | 45 | subf rb,rb,ra; /* subtract start value */ \ |
| 46 | ld ra,PACA_SYSTEM_TIME(r13); \ |
Paul Mackerras | cf9efce | 2010-08-26 19:56:43 +0000 | [diff] [blame] | 47 | add ra,ra,rb; /* add on to system time */ \ |
| 48 | std ra,PACA_SYSTEM_TIME(r13) |
| 49 | |
| 50 | #ifdef CONFIG_PPC_SPLPAR |
| 51 | #define ACCOUNT_STOLEN_TIME \ |
| 52 | BEGIN_FW_FTR_SECTION; \ |
| 53 | beq 33f; \ |
| 54 | /* from user - see if there are any DTL entries to process */ \ |
| 55 | ld r10,PACALPPACAPTR(r13); /* get ptr to VPA */ \ |
| 56 | ld r11,PACA_DTL_RIDX(r13); /* get log read index */ \ |
Anton Blanchard | 7ffcf8e | 2013-08-07 02:01:46 +1000 | [diff] [blame] | 57 | addi r10,r10,LPPACA_DTLIDX; \ |
| 58 | LDX_BE r10,0,r10; /* get log write index */ \ |
Paul Mackerras | cf9efce | 2010-08-26 19:56:43 +0000 | [diff] [blame] | 59 | cmpd cr1,r11,r10; \ |
| 60 | beq+ cr1,33f; \ |
| 61 | bl .accumulate_stolen_time; \ |
Benjamin Herrenschmidt | 990118c | 2012-03-02 11:01:31 +1100 | [diff] [blame] | 62 | ld r12,_MSR(r1); \ |
| 63 | andi. r10,r12,MSR_PR; /* Restore cr0 (coming from user) */ \ |
Paul Mackerras | cf9efce | 2010-08-26 19:56:43 +0000 | [diff] [blame] | 64 | 33: \ |
| 65 | END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR) |
| 66 | |
| 67 | #else /* CONFIG_PPC_SPLPAR */ |
| 68 | #define ACCOUNT_STOLEN_TIME |
| 69 | |
| 70 | #endif /* CONFIG_PPC_SPLPAR */ |
| 71 | |
Frederic Weisbecker | abf917c | 2012-07-25 07:56:04 +0200 | [diff] [blame] | 72 | #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ |
Paul Mackerras | c6622f6 | 2006-02-24 10:06:59 +1100 | [diff] [blame] | 73 | |
| 74 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | * Macros for storing registers into and loading registers from |
| 76 | * exception frames. |
| 77 | */ |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 78 | #ifdef __powerpc64__ |
| 79 | #define SAVE_GPR(n, base) std n,GPR0+8*(n)(base) |
| 80 | #define REST_GPR(n, base) ld n,GPR0+8*(n)(base) |
| 81 | #define SAVE_NVGPRS(base) SAVE_8GPRS(14, base); SAVE_10GPRS(22, base) |
| 82 | #define REST_NVGPRS(base) REST_8GPRS(14, base); REST_10GPRS(22, base) |
| 83 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | #define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #define REST_GPR(n, base) lwz n,GPR0+4*(n)(base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | #define SAVE_NVGPRS(base) SAVE_GPR(13, base); SAVE_8GPRS(14, base); \ |
| 87 | SAVE_10GPRS(22, base) |
| 88 | #define REST_NVGPRS(base) REST_GPR(13, base); REST_8GPRS(14, base); \ |
| 89 | REST_10GPRS(22, base) |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 90 | #endif |
| 91 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 92 | #define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base) |
| 93 | #define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base) |
| 94 | #define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base) |
| 95 | #define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base) |
| 96 | #define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base) |
| 97 | #define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base) |
| 98 | #define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base) |
| 99 | #define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Michael Neuling | 9c75a31 | 2008-06-26 17:07:48 +1000 | [diff] [blame] | 101 | #define SAVE_FPR(n, base) stfd n,THREAD_FPR0+8*TS_FPRWIDTH*(n)(base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | #define SAVE_2FPRS(n, base) SAVE_FPR(n, base); SAVE_FPR(n+1, base) |
| 103 | #define SAVE_4FPRS(n, base) SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base) |
| 104 | #define SAVE_8FPRS(n, base) SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base) |
| 105 | #define SAVE_16FPRS(n, base) SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base) |
| 106 | #define SAVE_32FPRS(n, base) SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base) |
Michael Neuling | 9c75a31 | 2008-06-26 17:07:48 +1000 | [diff] [blame] | 107 | #define REST_FPR(n, base) lfd n,THREAD_FPR0+8*TS_FPRWIDTH*(n)(base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | #define REST_2FPRS(n, base) REST_FPR(n, base); REST_FPR(n+1, base) |
| 109 | #define REST_4FPRS(n, base) REST_2FPRS(n, base); REST_2FPRS(n+2, base) |
| 110 | #define REST_8FPRS(n, base) REST_4FPRS(n, base); REST_4FPRS(n+4, base) |
| 111 | #define REST_16FPRS(n, base) REST_8FPRS(n, base); REST_8FPRS(n+8, base) |
| 112 | #define REST_32FPRS(n, base) REST_16FPRS(n, base); REST_16FPRS(n+16, base) |
| 113 | |
Michael Wolf | 23e55f9 | 2009-08-20 13:21:45 +0000 | [diff] [blame] | 114 | #define SAVE_VR(n,b,base) li b,THREAD_VR0+(16*(n)); stvx n,base,b |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 115 | #define SAVE_2VRS(n,b,base) SAVE_VR(n,b,base); SAVE_VR(n+1,b,base) |
| 116 | #define SAVE_4VRS(n,b,base) SAVE_2VRS(n,b,base); SAVE_2VRS(n+2,b,base) |
| 117 | #define SAVE_8VRS(n,b,base) SAVE_4VRS(n,b,base); SAVE_4VRS(n+4,b,base) |
| 118 | #define SAVE_16VRS(n,b,base) SAVE_8VRS(n,b,base); SAVE_8VRS(n+8,b,base) |
| 119 | #define SAVE_32VRS(n,b,base) SAVE_16VRS(n,b,base); SAVE_16VRS(n+16,b,base) |
Michael Wolf | 23e55f9 | 2009-08-20 13:21:45 +0000 | [diff] [blame] | 120 | #define REST_VR(n,b,base) li b,THREAD_VR0+(16*(n)); lvx n,base,b |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 121 | #define REST_2VRS(n,b,base) REST_VR(n,b,base); REST_VR(n+1,b,base) |
| 122 | #define REST_4VRS(n,b,base) REST_2VRS(n,b,base); REST_2VRS(n+2,b,base) |
| 123 | #define REST_8VRS(n,b,base) REST_4VRS(n,b,base); REST_4VRS(n+4,b,base) |
| 124 | #define REST_16VRS(n,b,base) REST_8VRS(n,b,base); REST_8VRS(n+8,b,base) |
| 125 | #define REST_32VRS(n,b,base) REST_16VRS(n,b,base); REST_16VRS(n+16,b,base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Michael Neuling | 8b3c34c | 2013-02-13 16:21:32 +0000 | [diff] [blame] | 127 | /* Save/restore FPRs, VRs and VSRs from their checkpointed backups in |
| 128 | * thread_struct: |
| 129 | */ |
| 130 | #define SAVE_FPR_TRANSACT(n, base) stfd n,THREAD_TRANSACT_FPR0+ \ |
| 131 | 8*TS_FPRWIDTH*(n)(base) |
| 132 | #define SAVE_2FPRS_TRANSACT(n, base) SAVE_FPR_TRANSACT(n, base); \ |
| 133 | SAVE_FPR_TRANSACT(n+1, base) |
| 134 | #define SAVE_4FPRS_TRANSACT(n, base) SAVE_2FPRS_TRANSACT(n, base); \ |
| 135 | SAVE_2FPRS_TRANSACT(n+2, base) |
| 136 | #define SAVE_8FPRS_TRANSACT(n, base) SAVE_4FPRS_TRANSACT(n, base); \ |
| 137 | SAVE_4FPRS_TRANSACT(n+4, base) |
| 138 | #define SAVE_16FPRS_TRANSACT(n, base) SAVE_8FPRS_TRANSACT(n, base); \ |
| 139 | SAVE_8FPRS_TRANSACT(n+8, base) |
| 140 | #define SAVE_32FPRS_TRANSACT(n, base) SAVE_16FPRS_TRANSACT(n, base); \ |
| 141 | SAVE_16FPRS_TRANSACT(n+16, base) |
| 142 | |
| 143 | #define REST_FPR_TRANSACT(n, base) lfd n,THREAD_TRANSACT_FPR0+ \ |
| 144 | 8*TS_FPRWIDTH*(n)(base) |
| 145 | #define REST_2FPRS_TRANSACT(n, base) REST_FPR_TRANSACT(n, base); \ |
| 146 | REST_FPR_TRANSACT(n+1, base) |
| 147 | #define REST_4FPRS_TRANSACT(n, base) REST_2FPRS_TRANSACT(n, base); \ |
| 148 | REST_2FPRS_TRANSACT(n+2, base) |
| 149 | #define REST_8FPRS_TRANSACT(n, base) REST_4FPRS_TRANSACT(n, base); \ |
| 150 | REST_4FPRS_TRANSACT(n+4, base) |
| 151 | #define REST_16FPRS_TRANSACT(n, base) REST_8FPRS_TRANSACT(n, base); \ |
| 152 | REST_8FPRS_TRANSACT(n+8, base) |
| 153 | #define REST_32FPRS_TRANSACT(n, base) REST_16FPRS_TRANSACT(n, base); \ |
| 154 | REST_16FPRS_TRANSACT(n+16, base) |
| 155 | |
| 156 | |
| 157 | #define SAVE_VR_TRANSACT(n,b,base) li b,THREAD_TRANSACT_VR0+(16*(n)); \ |
| 158 | stvx n,b,base |
| 159 | #define SAVE_2VRS_TRANSACT(n,b,base) SAVE_VR_TRANSACT(n,b,base); \ |
| 160 | SAVE_VR_TRANSACT(n+1,b,base) |
| 161 | #define SAVE_4VRS_TRANSACT(n,b,base) SAVE_2VRS_TRANSACT(n,b,base); \ |
| 162 | SAVE_2VRS_TRANSACT(n+2,b,base) |
| 163 | #define SAVE_8VRS_TRANSACT(n,b,base) SAVE_4VRS_TRANSACT(n,b,base); \ |
| 164 | SAVE_4VRS_TRANSACT(n+4,b,base) |
| 165 | #define SAVE_16VRS_TRANSACT(n,b,base) SAVE_8VRS_TRANSACT(n,b,base); \ |
| 166 | SAVE_8VRS_TRANSACT(n+8,b,base) |
| 167 | #define SAVE_32VRS_TRANSACT(n,b,base) SAVE_16VRS_TRANSACT(n,b,base); \ |
| 168 | SAVE_16VRS_TRANSACT(n+16,b,base) |
| 169 | |
| 170 | #define REST_VR_TRANSACT(n,b,base) li b,THREAD_TRANSACT_VR0+(16*(n)); \ |
| 171 | lvx n,b,base |
| 172 | #define REST_2VRS_TRANSACT(n,b,base) REST_VR_TRANSACT(n,b,base); \ |
| 173 | REST_VR_TRANSACT(n+1,b,base) |
| 174 | #define REST_4VRS_TRANSACT(n,b,base) REST_2VRS_TRANSACT(n,b,base); \ |
| 175 | REST_2VRS_TRANSACT(n+2,b,base) |
| 176 | #define REST_8VRS_TRANSACT(n,b,base) REST_4VRS_TRANSACT(n,b,base); \ |
| 177 | REST_4VRS_TRANSACT(n+4,b,base) |
| 178 | #define REST_16VRS_TRANSACT(n,b,base) REST_8VRS_TRANSACT(n,b,base); \ |
| 179 | REST_8VRS_TRANSACT(n+8,b,base) |
| 180 | #define REST_32VRS_TRANSACT(n,b,base) REST_16VRS_TRANSACT(n,b,base); \ |
| 181 | REST_16VRS_TRANSACT(n+16,b,base) |
| 182 | |
Anton Blanchard | 926f160 | 2013-09-23 12:04:39 +1000 | [diff] [blame^] | 183 | #ifdef __BIG_ENDIAN__ |
| 184 | #define STXVD2X_ROT(n,b,base) STXVD2X(n,b,base) |
| 185 | #define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base) |
| 186 | #else |
| 187 | #define STXVD2X_ROT(n,b,base) XXSWAPD(n,n); \ |
| 188 | STXVD2X(n,b,base); \ |
| 189 | XXSWAPD(n,n) |
| 190 | |
| 191 | #define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base); \ |
| 192 | XXSWAPD(n,n) |
| 193 | #endif |
Michael Neuling | 8b3c34c | 2013-02-13 16:21:32 +0000 | [diff] [blame] | 194 | |
| 195 | #define SAVE_VSR_TRANSACT(n,b,base) li b,THREAD_TRANSACT_VSR0+(16*(n)); \ |
Anton Blanchard | 926f160 | 2013-09-23 12:04:39 +1000 | [diff] [blame^] | 196 | STXVD2X_ROT(n,R##base,R##b) |
Michael Neuling | 8b3c34c | 2013-02-13 16:21:32 +0000 | [diff] [blame] | 197 | #define SAVE_2VSRS_TRANSACT(n,b,base) SAVE_VSR_TRANSACT(n,b,base); \ |
| 198 | SAVE_VSR_TRANSACT(n+1,b,base) |
| 199 | #define SAVE_4VSRS_TRANSACT(n,b,base) SAVE_2VSRS_TRANSACT(n,b,base); \ |
| 200 | SAVE_2VSRS_TRANSACT(n+2,b,base) |
| 201 | #define SAVE_8VSRS_TRANSACT(n,b,base) SAVE_4VSRS_TRANSACT(n,b,base); \ |
| 202 | SAVE_4VSRS_TRANSACT(n+4,b,base) |
| 203 | #define SAVE_16VSRS_TRANSACT(n,b,base) SAVE_8VSRS_TRANSACT(n,b,base); \ |
| 204 | SAVE_8VSRS_TRANSACT(n+8,b,base) |
| 205 | #define SAVE_32VSRS_TRANSACT(n,b,base) SAVE_16VSRS_TRANSACT(n,b,base); \ |
| 206 | SAVE_16VSRS_TRANSACT(n+16,b,base) |
| 207 | |
| 208 | #define REST_VSR_TRANSACT(n,b,base) li b,THREAD_TRANSACT_VSR0+(16*(n)); \ |
Anton Blanchard | 926f160 | 2013-09-23 12:04:39 +1000 | [diff] [blame^] | 209 | LXVD2X_ROT(n,R##base,R##b) |
Michael Neuling | 8b3c34c | 2013-02-13 16:21:32 +0000 | [diff] [blame] | 210 | #define REST_2VSRS_TRANSACT(n,b,base) REST_VSR_TRANSACT(n,b,base); \ |
| 211 | REST_VSR_TRANSACT(n+1,b,base) |
| 212 | #define REST_4VSRS_TRANSACT(n,b,base) REST_2VSRS_TRANSACT(n,b,base); \ |
| 213 | REST_2VSRS_TRANSACT(n+2,b,base) |
| 214 | #define REST_8VSRS_TRANSACT(n,b,base) REST_4VSRS_TRANSACT(n,b,base); \ |
| 215 | REST_4VSRS_TRANSACT(n+4,b,base) |
| 216 | #define REST_16VSRS_TRANSACT(n,b,base) REST_8VSRS_TRANSACT(n,b,base); \ |
| 217 | REST_8VSRS_TRANSACT(n+8,b,base) |
| 218 | #define REST_32VSRS_TRANSACT(n,b,base) REST_16VSRS_TRANSACT(n,b,base); \ |
| 219 | REST_16VSRS_TRANSACT(n+16,b,base) |
| 220 | |
Michael Neuling | 72ffff5 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 221 | /* Save the lower 32 VSRs in the thread VSR region */ |
Anton Blanchard | 926f160 | 2013-09-23 12:04:39 +1000 | [diff] [blame^] | 222 | #define SAVE_VSR(n,b,base) li b,THREAD_VSR0+(16*(n)); \ |
| 223 | STXVD2X_ROT(n,R##base,R##b) |
Michael Neuling | 72ffff5 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 224 | #define SAVE_2VSRS(n,b,base) SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base) |
| 225 | #define SAVE_4VSRS(n,b,base) SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base) |
| 226 | #define SAVE_8VSRS(n,b,base) SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base) |
| 227 | #define SAVE_16VSRS(n,b,base) SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base) |
| 228 | #define SAVE_32VSRS(n,b,base) SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base) |
Anton Blanchard | 926f160 | 2013-09-23 12:04:39 +1000 | [diff] [blame^] | 229 | #define REST_VSR(n,b,base) li b,THREAD_VSR0+(16*(n)); \ |
| 230 | LXVD2X_ROT(n,R##base,R##b) |
Michael Neuling | 72ffff5 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 231 | #define REST_2VSRS(n,b,base) REST_VSR(n,b,base); REST_VSR(n+1,b,base) |
| 232 | #define REST_4VSRS(n,b,base) REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base) |
| 233 | #define REST_8VSRS(n,b,base) REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base) |
| 234 | #define REST_16VSRS(n,b,base) REST_8VSRS(n,b,base); REST_8VSRS(n+8,b,base) |
| 235 | #define REST_32VSRS(n,b,base) REST_16VSRS(n,b,base); REST_16VSRS(n+16,b,base) |
Michael Neuling | 72ffff5 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 236 | |
Scott Wood | c51584d | 2011-06-14 18:34:27 -0500 | [diff] [blame] | 237 | /* |
| 238 | * b = base register for addressing, o = base offset from register of 1st EVR |
| 239 | * n = first EVR, s = scratch |
| 240 | */ |
| 241 | #define SAVE_EVR(n,s,b,o) evmergehi s,s,n; stw s,o+4*(n)(b) |
| 242 | #define SAVE_2EVRS(n,s,b,o) SAVE_EVR(n,s,b,o); SAVE_EVR(n+1,s,b,o) |
| 243 | #define SAVE_4EVRS(n,s,b,o) SAVE_2EVRS(n,s,b,o); SAVE_2EVRS(n+2,s,b,o) |
| 244 | #define SAVE_8EVRS(n,s,b,o) SAVE_4EVRS(n,s,b,o); SAVE_4EVRS(n+4,s,b,o) |
| 245 | #define SAVE_16EVRS(n,s,b,o) SAVE_8EVRS(n,s,b,o); SAVE_8EVRS(n+8,s,b,o) |
| 246 | #define SAVE_32EVRS(n,s,b,o) SAVE_16EVRS(n,s,b,o); SAVE_16EVRS(n+16,s,b,o) |
| 247 | #define REST_EVR(n,s,b,o) lwz s,o+4*(n)(b); evmergelo n,s,n |
| 248 | #define REST_2EVRS(n,s,b,o) REST_EVR(n,s,b,o); REST_EVR(n+1,s,b,o) |
| 249 | #define REST_4EVRS(n,s,b,o) REST_2EVRS(n,s,b,o); REST_2EVRS(n+2,s,b,o) |
| 250 | #define REST_8EVRS(n,s,b,o) REST_4EVRS(n,s,b,o); REST_4EVRS(n+4,s,b,o) |
| 251 | #define REST_16EVRS(n,s,b,o) REST_8EVRS(n,s,b,o); REST_8EVRS(n+8,s,b,o) |
| 252 | #define REST_32EVRS(n,s,b,o) REST_16EVRS(n,s,b,o); REST_16EVRS(n+16,s,b,o) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
Michael Ellerman | 8c71632 | 2005-10-24 15:07:27 +1000 | [diff] [blame] | 254 | /* Macros to adjust thread priority for hardware multithreading */ |
| 255 | #define HMT_VERY_LOW or 31,31,31 # very low priority |
| 256 | #define HMT_LOW or 1,1,1 |
| 257 | #define HMT_MEDIUM_LOW or 6,6,6 # medium low priority |
| 258 | #define HMT_MEDIUM or 2,2,2 |
| 259 | #define HMT_MEDIUM_HIGH or 5,5,5 # medium high priority |
| 260 | #define HMT_HIGH or 3,3,3 |
Benjamin Herrenschmidt | 50fb8eb | 2011-01-12 17:41:28 +1100 | [diff] [blame] | 261 | #define HMT_EXTRA_HIGH or 7,7,7 # power7 only |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 262 | |
Michael Neuling | d72be89 | 2012-06-25 13:33:15 +0000 | [diff] [blame] | 263 | #ifdef CONFIG_PPC64 |
| 264 | #define ULONG_SIZE 8 |
| 265 | #else |
| 266 | #define ULONG_SIZE 4 |
| 267 | #endif |
Michael Neuling | 0b7673c | 2012-06-25 13:33:23 +0000 | [diff] [blame] | 268 | #define __VCPU_GPR(n) (VCPU_GPRS + (n * ULONG_SIZE)) |
| 269 | #define VCPU_GPR(n) __VCPU_GPR(__REG_##n) |
Michael Neuling | d72be89 | 2012-06-25 13:33:15 +0000 | [diff] [blame] | 270 | |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 271 | #ifdef __KERNEL__ |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 272 | #ifdef CONFIG_PPC64 |
| 273 | |
Michael Neuling | 44ce6a5 | 2012-06-25 13:33:14 +0000 | [diff] [blame] | 274 | #define STACKFRAMESIZE 256 |
Michael Neuling | 0b7673c | 2012-06-25 13:33:23 +0000 | [diff] [blame] | 275 | #define __STK_REG(i) (112 + ((i)-14)*8) |
| 276 | #define STK_REG(i) __STK_REG(__REG_##i) |
Michael Neuling | 44ce6a5 | 2012-06-25 13:33:14 +0000 | [diff] [blame] | 277 | |
Michael Neuling | 0b7673c | 2012-06-25 13:33:23 +0000 | [diff] [blame] | 278 | #define __STK_PARAM(i) (48 + ((i)-3)*8) |
| 279 | #define STK_PARAM(i) __STK_PARAM(__REG_##i) |
Michael Neuling | 44ce6a5 | 2012-06-25 13:33:14 +0000 | [diff] [blame] | 280 | |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 281 | #define XGLUE(a,b) a##b |
| 282 | #define GLUE(a,b) XGLUE(a,b) |
| 283 | |
| 284 | #define _GLOBAL(name) \ |
| 285 | .section ".text"; \ |
| 286 | .align 2 ; \ |
| 287 | .globl name; \ |
| 288 | .globl GLUE(.,name); \ |
| 289 | .section ".opd","aw"; \ |
| 290 | name: \ |
| 291 | .quad GLUE(.,name); \ |
| 292 | .quad .TOC.@tocbase; \ |
| 293 | .quad 0; \ |
| 294 | .previous; \ |
| 295 | .type GLUE(.,name),@function; \ |
| 296 | GLUE(.,name): |
| 297 | |
Stephen Rothwell | fc68e86 | 2007-08-22 13:44:58 +1000 | [diff] [blame] | 298 | #define _INIT_GLOBAL(name) \ |
Tim Abbott | 9203fc9 | 2009-04-27 14:02:24 -0400 | [diff] [blame] | 299 | __REF; \ |
Stephen Rothwell | fc68e86 | 2007-08-22 13:44:58 +1000 | [diff] [blame] | 300 | .align 2 ; \ |
| 301 | .globl name; \ |
| 302 | .globl GLUE(.,name); \ |
| 303 | .section ".opd","aw"; \ |
| 304 | name: \ |
| 305 | .quad GLUE(.,name); \ |
| 306 | .quad .TOC.@tocbase; \ |
| 307 | .quad 0; \ |
| 308 | .previous; \ |
| 309 | .type GLUE(.,name),@function; \ |
| 310 | GLUE(.,name): |
| 311 | |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 312 | #define _KPROBE(name) \ |
| 313 | .section ".kprobes.text","a"; \ |
| 314 | .align 2 ; \ |
| 315 | .globl name; \ |
| 316 | .globl GLUE(.,name); \ |
| 317 | .section ".opd","aw"; \ |
| 318 | name: \ |
| 319 | .quad GLUE(.,name); \ |
| 320 | .quad .TOC.@tocbase; \ |
| 321 | .quad 0; \ |
| 322 | .previous; \ |
| 323 | .type GLUE(.,name),@function; \ |
| 324 | GLUE(.,name): |
| 325 | |
| 326 | #define _STATIC(name) \ |
| 327 | .section ".text"; \ |
| 328 | .align 2 ; \ |
| 329 | .section ".opd","aw"; \ |
| 330 | name: \ |
| 331 | .quad GLUE(.,name); \ |
| 332 | .quad .TOC.@tocbase; \ |
| 333 | .quad 0; \ |
| 334 | .previous; \ |
| 335 | .type GLUE(.,name),@function; \ |
| 336 | GLUE(.,name): |
| 337 | |
Stephen Rothwell | c40b91b | 2007-07-25 09:27:35 +1000 | [diff] [blame] | 338 | #define _INIT_STATIC(name) \ |
Tim Abbott | 9203fc9 | 2009-04-27 14:02:24 -0400 | [diff] [blame] | 339 | __REF; \ |
Stephen Rothwell | c40b91b | 2007-07-25 09:27:35 +1000 | [diff] [blame] | 340 | .align 2 ; \ |
| 341 | .section ".opd","aw"; \ |
| 342 | name: \ |
| 343 | .quad GLUE(.,name); \ |
| 344 | .quad .TOC.@tocbase; \ |
| 345 | .quad 0; \ |
| 346 | .previous; \ |
| 347 | .type GLUE(.,name),@function; \ |
| 348 | GLUE(.,name): |
| 349 | |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 350 | #else /* 32-bit */ |
| 351 | |
Kumar Gala | 748a768 | 2007-09-13 15:42:35 -0500 | [diff] [blame] | 352 | #define _ENTRY(n) \ |
| 353 | .globl n; \ |
| 354 | n: |
| 355 | |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 356 | #define _GLOBAL(n) \ |
| 357 | .text; \ |
| 358 | .stabs __stringify(n:F-1),N_FUN,0,0,n;\ |
| 359 | .globl n; \ |
| 360 | n: |
| 361 | |
| 362 | #define _KPROBE(n) \ |
| 363 | .section ".kprobes.text","a"; \ |
| 364 | .globl n; \ |
| 365 | n: |
| 366 | |
| 367 | #endif |
| 368 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 369 | /* |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 370 | * LOAD_REG_IMMEDIATE(rn, expr) |
| 371 | * Loads the value of the constant expression 'expr' into register 'rn' |
| 372 | * using immediate instructions only. Use this when it's important not |
| 373 | * to reference other data (i.e. on ppc64 when the TOC pointer is not |
Paul Mackerras | e31aa45 | 2008-08-30 11:41:12 +1000 | [diff] [blame] | 374 | * valid) and when 'expr' is a constant or absolute address. |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 375 | * |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 376 | * LOAD_REG_ADDR(rn, name) |
| 377 | * Loads the address of label 'name' into register 'rn'. Use this when |
| 378 | * you don't particularly need immediate instructions only, but you need |
| 379 | * the whole address in one register (e.g. it's a structure address and |
| 380 | * you want to access various offsets within it). On ppc32 this is |
| 381 | * identical to LOAD_REG_IMMEDIATE. |
| 382 | * |
| 383 | * LOAD_REG_ADDRBASE(rn, name) |
| 384 | * ADDROFF(name) |
| 385 | * LOAD_REG_ADDRBASE loads part of the address of label 'name' into |
| 386 | * register 'rn'. ADDROFF(name) returns the remainder of the address as |
| 387 | * a constant expression. ADDROFF(name) is a signed expression < 16 bits |
| 388 | * in size, so is suitable for use directly as an offset in load and store |
| 389 | * instructions. Use this when loading/storing a single word or less as: |
| 390 | * LOAD_REG_ADDRBASE(rX, name) |
| 391 | * ld rY,ADDROFF(name)(rX) |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 392 | */ |
| 393 | #ifdef __powerpc64__ |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 394 | #define LOAD_REG_IMMEDIATE(reg,expr) \ |
Michael Neuling | 564aa5c | 2012-06-25 13:33:09 +0000 | [diff] [blame] | 395 | lis reg,(expr)@highest; \ |
| 396 | ori reg,reg,(expr)@higher; \ |
| 397 | rldicr reg,reg,32,31; \ |
| 398 | oris reg,reg,(expr)@h; \ |
| 399 | ori reg,reg,(expr)@l; |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 400 | |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 401 | #define LOAD_REG_ADDR(reg,name) \ |
Michael Neuling | 564aa5c | 2012-06-25 13:33:09 +0000 | [diff] [blame] | 402 | ld reg,name@got(r2) |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 403 | |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 404 | #define LOAD_REG_ADDRBASE(reg,name) LOAD_REG_ADDR(reg,name) |
| 405 | #define ADDROFF(name) 0 |
Paul Mackerras | b85a046 | 2005-10-06 10:59:19 +1000 | [diff] [blame] | 406 | |
Paul Mackerras | f78541dc | 2005-10-28 22:53:37 +1000 | [diff] [blame] | 407 | /* offsets for stack frame layout */ |
| 408 | #define LRSAVE 16 |
Paul Mackerras | b85a046 | 2005-10-06 10:59:19 +1000 | [diff] [blame] | 409 | |
| 410 | #else /* 32-bit */ |
Stephen Rothwell | 7062018 | 2005-10-12 17:44:55 +1000 | [diff] [blame] | 411 | |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 412 | #define LOAD_REG_IMMEDIATE(reg,expr) \ |
Michael Neuling | 564aa5c | 2012-06-25 13:33:09 +0000 | [diff] [blame] | 413 | lis reg,(expr)@ha; \ |
| 414 | addi reg,reg,(expr)@l; |
Paul Mackerras | b85a046 | 2005-10-06 10:59:19 +1000 | [diff] [blame] | 415 | |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 416 | #define LOAD_REG_ADDR(reg,name) LOAD_REG_IMMEDIATE(reg, name) |
| 417 | |
Michael Neuling | 564aa5c | 2012-06-25 13:33:09 +0000 | [diff] [blame] | 418 | #define LOAD_REG_ADDRBASE(reg, name) lis reg,name@ha |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 419 | #define ADDROFF(name) name@l |
Paul Mackerras | b85a046 | 2005-10-06 10:59:19 +1000 | [diff] [blame] | 420 | |
Paul Mackerras | f78541dc | 2005-10-28 22:53:37 +1000 | [diff] [blame] | 421 | /* offsets for stack frame layout */ |
| 422 | #define LRSAVE 4 |
Paul Mackerras | b85a046 | 2005-10-06 10:59:19 +1000 | [diff] [blame] | 423 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 424 | #endif |
| 425 | |
| 426 | /* various errata or part fixups */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | #ifdef CONFIG_PPC601_SYNC_FIX |
| 428 | #define SYNC \ |
| 429 | BEGIN_FTR_SECTION \ |
| 430 | sync; \ |
| 431 | isync; \ |
| 432 | END_FTR_SECTION_IFSET(CPU_FTR_601) |
| 433 | #define SYNC_601 \ |
| 434 | BEGIN_FTR_SECTION \ |
| 435 | sync; \ |
| 436 | END_FTR_SECTION_IFSET(CPU_FTR_601) |
| 437 | #define ISYNC_601 \ |
| 438 | BEGIN_FTR_SECTION \ |
| 439 | isync; \ |
| 440 | END_FTR_SECTION_IFSET(CPU_FTR_601) |
| 441 | #else |
| 442 | #define SYNC |
| 443 | #define SYNC_601 |
| 444 | #define ISYNC_601 |
| 445 | #endif |
| 446 | |
Scott Wood | d52459c | 2013-07-23 20:21:11 -0500 | [diff] [blame] | 447 | #if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_FSL_BOOK3E) |
Benjamin Herrenschmidt | 859deea | 2006-10-20 14:37:05 +1000 | [diff] [blame] | 448 | #define MFTB(dest) \ |
Scott Wood | beb2dc0 | 2013-08-20 19:33:12 -0500 | [diff] [blame] | 449 | 90: mfspr dest, SPRN_TBRL; \ |
Benjamin Herrenschmidt | 859deea | 2006-10-20 14:37:05 +1000 | [diff] [blame] | 450 | BEGIN_FTR_SECTION_NESTED(96); \ |
| 451 | cmpwi dest,0; \ |
| 452 | beq- 90b; \ |
| 453 | END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96) |
| 454 | #else |
Scott Wood | beb2dc0 | 2013-08-20 19:33:12 -0500 | [diff] [blame] | 455 | #define MFTB(dest) mfspr dest, SPRN_TBRL |
Benjamin Herrenschmidt | 859deea | 2006-10-20 14:37:05 +1000 | [diff] [blame] | 456 | #endif |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | #ifndef CONFIG_SMP |
| 459 | #define TLBSYNC |
| 460 | #else /* CONFIG_SMP */ |
| 461 | /* tlbsync is not implemented on 601 */ |
| 462 | #define TLBSYNC \ |
| 463 | BEGIN_FTR_SECTION \ |
| 464 | tlbsync; \ |
| 465 | sync; \ |
| 466 | END_FTR_SECTION_IFCLR(CPU_FTR_601) |
| 467 | #endif |
| 468 | |
Anton Blanchard | 694caf0 | 2012-04-18 02:21:52 +0000 | [diff] [blame] | 469 | #ifdef CONFIG_PPC64 |
| 470 | #define MTOCRF(FXM, RS) \ |
| 471 | BEGIN_FTR_SECTION_NESTED(848); \ |
Michael Neuling | 86e32fd | 2012-06-25 13:33:16 +0000 | [diff] [blame] | 472 | mtcrf (FXM), RS; \ |
Anton Blanchard | 694caf0 | 2012-04-18 02:21:52 +0000 | [diff] [blame] | 473 | FTR_SECTION_ELSE_NESTED(848); \ |
Michael Neuling | 86e32fd | 2012-06-25 13:33:16 +0000 | [diff] [blame] | 474 | mtocrf (FXM), RS; \ |
Anton Blanchard | 694caf0 | 2012-04-18 02:21:52 +0000 | [diff] [blame] | 475 | ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_NOEXECUTE, 848) |
Haren Myneni | 13e7a8e | 2012-12-06 21:50:32 +0000 | [diff] [blame] | 476 | |
| 477 | /* |
| 478 | * PPR restore macros used in entry_64.S |
| 479 | * Used for P7 or later processors |
| 480 | */ |
| 481 | #define HMT_MEDIUM_LOW_HAS_PPR \ |
| 482 | BEGIN_FTR_SECTION_NESTED(944) \ |
| 483 | HMT_MEDIUM_LOW; \ |
| 484 | END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,944) |
| 485 | |
| 486 | #define SET_DEFAULT_THREAD_PPR(ra, rb) \ |
| 487 | BEGIN_FTR_SECTION_NESTED(945) \ |
| 488 | lis ra,INIT_PPR@highest; /* default ppr=3 */ \ |
| 489 | ld rb,PACACURRENT(r13); \ |
| 490 | sldi ra,ra,32; /* 11- 13 bits are used for ppr */ \ |
| 491 | std ra,TASKTHREADPPR(rb); \ |
| 492 | END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,945) |
| 493 | |
| 494 | #define RESTORE_PPR(ra, rb) \ |
| 495 | BEGIN_FTR_SECTION_NESTED(946) \ |
| 496 | ld ra,PACACURRENT(r13); \ |
| 497 | ld rb,TASKTHREADPPR(ra); \ |
| 498 | mtspr SPRN_PPR,rb; /* Restore PPR */ \ |
| 499 | END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,946) |
| 500 | |
Anton Blanchard | 694caf0 | 2012-04-18 02:21:52 +0000 | [diff] [blame] | 501 | #endif |
| 502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | /* |
| 504 | * This instruction is not implemented on the PPC 603 or 601; however, on |
| 505 | * the 403GCX and 405GP tlbia IS defined and tlbie is not. |
| 506 | * All of these instructions exist in the 8xx, they have magical powers, |
| 507 | * and they must be used. |
| 508 | */ |
| 509 | |
| 510 | #if !defined(CONFIG_4xx) && !defined(CONFIG_8xx) |
| 511 | #define tlbia \ |
| 512 | li r4,1024; \ |
| 513 | mtctr r4; \ |
| 514 | lis r4,KERNELBASE@h; \ |
| 515 | 0: tlbie r4; \ |
| 516 | addi r4,r4,0x1000; \ |
| 517 | bdnz 0b |
| 518 | #endif |
| 519 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 520 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 521 | #ifdef CONFIG_IBM440EP_ERR42 |
| 522 | #define PPC440EP_ERR42 isync |
| 523 | #else |
| 524 | #define PPC440EP_ERR42 |
| 525 | #endif |
| 526 | |
Michael Neuling | a515348 | 2013-05-29 19:34:27 +0000 | [diff] [blame] | 527 | /* The following stops all load and store data streams associated with stream |
| 528 | * ID (ie. streams created explicitly). The embedded and server mnemonics for |
| 529 | * dcbt are different so we use machine "power4" here explicitly. |
| 530 | */ |
| 531 | #define DCBT_STOP_ALL_STREAM_IDS(scratch) \ |
| 532 | .machine push ; \ |
| 533 | .machine "power4" ; \ |
| 534 | lis scratch,0x60000000@h; \ |
| 535 | dcbt r0,scratch,0b01010; \ |
| 536 | .machine pop |
| 537 | |
Benjamin Herrenschmidt | 44c58cc | 2009-07-23 23:15:20 +0000 | [diff] [blame] | 538 | /* |
| 539 | * toreal/fromreal/tophys/tovirt macros. 32-bit BookE makes them |
| 540 | * keep the address intact to be compatible with code shared with |
| 541 | * 32-bit classic. |
| 542 | * |
| 543 | * On the other hand, I find it useful to have them behave as expected |
| 544 | * by their name (ie always do the addition) on 64-bit BookE |
| 545 | */ |
| 546 | #if defined(CONFIG_BOOKE) && !defined(CONFIG_PPC64) |
Paul Mackerras | 6316222 | 2005-10-27 22:44:39 +1000 | [diff] [blame] | 547 | #define toreal(rd) |
| 548 | #define fromreal(rd) |
| 549 | |
Roland McGrath | 2ca7633 | 2008-05-11 10:40:47 +1000 | [diff] [blame] | 550 | /* |
| 551 | * We use addis to ensure compatibility with the "classic" ppc versions of |
| 552 | * these macros, which use rs = 0 to get the tophys offset in rd, rather than |
| 553 | * converting the address in r0, and so this version has to do that too |
| 554 | * (i.e. set register rd to 0 when rs == 0). |
| 555 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | #define tophys(rd,rs) \ |
| 557 | addis rd,rs,0 |
| 558 | |
| 559 | #define tovirt(rd,rs) \ |
| 560 | addis rd,rs,0 |
| 561 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 562 | #elif defined(CONFIG_PPC64) |
Paul Mackerras | 6316222 | 2005-10-27 22:44:39 +1000 | [diff] [blame] | 563 | #define toreal(rd) /* we can access c000... in real mode */ |
| 564 | #define fromreal(rd) |
| 565 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 566 | #define tophys(rd,rs) \ |
Paul Mackerras | 6316222 | 2005-10-27 22:44:39 +1000 | [diff] [blame] | 567 | clrldi rd,rs,2 |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 568 | |
| 569 | #define tovirt(rd,rs) \ |
Paul Mackerras | 6316222 | 2005-10-27 22:44:39 +1000 | [diff] [blame] | 570 | rotldi rd,rs,16; \ |
| 571 | ori rd,rd,((KERNELBASE>>48)&0xFFFF);\ |
| 572 | rotldi rd,rd,48 |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 573 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | /* |
| 575 | * On APUS (Amiga PowerPC cpu upgrade board), we don't know the |
| 576 | * physical base address of RAM at compile time. |
| 577 | */ |
Paul Mackerras | 6316222 | 2005-10-27 22:44:39 +1000 | [diff] [blame] | 578 | #define toreal(rd) tophys(rd,rd) |
| 579 | #define fromreal(rd) tovirt(rd,rd) |
| 580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | #define tophys(rd,rs) \ |
Dale Farnsworth | ccdcef7 | 2008-12-17 10:09:13 +0000 | [diff] [blame] | 582 | 0: addis rd,rs,-PAGE_OFFSET@h; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | .section ".vtop_fixup","aw"; \ |
| 584 | .align 1; \ |
| 585 | .long 0b; \ |
| 586 | .previous |
| 587 | |
| 588 | #define tovirt(rd,rs) \ |
Dale Farnsworth | ccdcef7 | 2008-12-17 10:09:13 +0000 | [diff] [blame] | 589 | 0: addis rd,rs,PAGE_OFFSET@h; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | .section ".ptov_fixup","aw"; \ |
| 591 | .align 1; \ |
| 592 | .long 0b; \ |
| 593 | .previous |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 594 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Benjamin Herrenschmidt | 44c58cc | 2009-07-23 23:15:20 +0000 | [diff] [blame] | 596 | #ifdef CONFIG_PPC_BOOK3S_64 |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 597 | #define RFI rfid |
| 598 | #define MTMSRD(r) mtmsrd r |
Benjamin Herrenschmidt | b38c77d | 2012-07-04 14:49:12 +1000 | [diff] [blame] | 599 | #define MTMSR_EERI(reg) mtmsrd reg,1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | #else |
| 601 | #define FIX_SRR1(ra, rb) |
| 602 | #ifndef CONFIG_40x |
| 603 | #define RFI rfi |
| 604 | #else |
| 605 | #define RFI rfi; b . /* Prevent prefetch past rfi */ |
| 606 | #endif |
| 607 | #define MTMSRD(r) mtmsr r |
Benjamin Herrenschmidt | b38c77d | 2012-07-04 14:49:12 +1000 | [diff] [blame] | 608 | #define MTMSR_EERI(reg) mtmsr reg |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | #define CLR_TOP32(r) |
Matt Porter | c9cf73a | 2005-07-31 22:34:52 -0700 | [diff] [blame] | 610 | #endif |
| 611 | |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 612 | #endif /* __KERNEL__ */ |
| 613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | /* The boring bits... */ |
| 615 | |
| 616 | /* Condition Register Bit Fields */ |
| 617 | |
| 618 | #define cr0 0 |
| 619 | #define cr1 1 |
| 620 | #define cr2 2 |
| 621 | #define cr3 3 |
| 622 | #define cr4 4 |
| 623 | #define cr5 5 |
| 624 | #define cr6 6 |
| 625 | #define cr7 7 |
| 626 | |
| 627 | |
Michael Neuling | 9a13a52 | 2012-06-25 13:33:12 +0000 | [diff] [blame] | 628 | /* |
| 629 | * General Purpose Registers (GPRs) |
| 630 | * |
| 631 | * The lower case r0-r31 should be used in preference to the upper |
| 632 | * case R0-R31 as they provide more error checking in the assembler. |
| 633 | * Use R0-31 only when really nessesary. |
| 634 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
Michael Neuling | 9a13a52 | 2012-06-25 13:33:12 +0000 | [diff] [blame] | 636 | #define r0 %r0 |
| 637 | #define r1 %r1 |
| 638 | #define r2 %r2 |
| 639 | #define r3 %r3 |
| 640 | #define r4 %r4 |
| 641 | #define r5 %r5 |
| 642 | #define r6 %r6 |
| 643 | #define r7 %r7 |
| 644 | #define r8 %r8 |
| 645 | #define r9 %r9 |
| 646 | #define r10 %r10 |
| 647 | #define r11 %r11 |
| 648 | #define r12 %r12 |
| 649 | #define r13 %r13 |
| 650 | #define r14 %r14 |
| 651 | #define r15 %r15 |
| 652 | #define r16 %r16 |
| 653 | #define r17 %r17 |
| 654 | #define r18 %r18 |
| 655 | #define r19 %r19 |
| 656 | #define r20 %r20 |
| 657 | #define r21 %r21 |
| 658 | #define r22 %r22 |
| 659 | #define r23 %r23 |
| 660 | #define r24 %r24 |
| 661 | #define r25 %r25 |
| 662 | #define r26 %r26 |
| 663 | #define r27 %r27 |
| 664 | #define r28 %r28 |
| 665 | #define r29 %r29 |
| 666 | #define r30 %r30 |
| 667 | #define r31 %r31 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
| 669 | |
| 670 | /* Floating Point Registers (FPRs) */ |
| 671 | |
| 672 | #define fr0 0 |
| 673 | #define fr1 1 |
| 674 | #define fr2 2 |
| 675 | #define fr3 3 |
| 676 | #define fr4 4 |
| 677 | #define fr5 5 |
| 678 | #define fr6 6 |
| 679 | #define fr7 7 |
| 680 | #define fr8 8 |
| 681 | #define fr9 9 |
| 682 | #define fr10 10 |
| 683 | #define fr11 11 |
| 684 | #define fr12 12 |
| 685 | #define fr13 13 |
| 686 | #define fr14 14 |
| 687 | #define fr15 15 |
| 688 | #define fr16 16 |
| 689 | #define fr17 17 |
| 690 | #define fr18 18 |
| 691 | #define fr19 19 |
| 692 | #define fr20 20 |
| 693 | #define fr21 21 |
| 694 | #define fr22 22 |
| 695 | #define fr23 23 |
| 696 | #define fr24 24 |
| 697 | #define fr25 25 |
| 698 | #define fr26 26 |
| 699 | #define fr27 27 |
| 700 | #define fr28 28 |
| 701 | #define fr29 29 |
| 702 | #define fr30 30 |
| 703 | #define fr31 31 |
| 704 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 705 | /* AltiVec Registers (VPRs) */ |
| 706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | #define vr0 0 |
| 708 | #define vr1 1 |
| 709 | #define vr2 2 |
| 710 | #define vr3 3 |
| 711 | #define vr4 4 |
| 712 | #define vr5 5 |
| 713 | #define vr6 6 |
| 714 | #define vr7 7 |
| 715 | #define vr8 8 |
| 716 | #define vr9 9 |
| 717 | #define vr10 10 |
| 718 | #define vr11 11 |
| 719 | #define vr12 12 |
| 720 | #define vr13 13 |
| 721 | #define vr14 14 |
| 722 | #define vr15 15 |
| 723 | #define vr16 16 |
| 724 | #define vr17 17 |
| 725 | #define vr18 18 |
| 726 | #define vr19 19 |
| 727 | #define vr20 20 |
| 728 | #define vr21 21 |
| 729 | #define vr22 22 |
| 730 | #define vr23 23 |
| 731 | #define vr24 24 |
| 732 | #define vr25 25 |
| 733 | #define vr26 26 |
| 734 | #define vr27 27 |
| 735 | #define vr28 28 |
| 736 | #define vr29 29 |
| 737 | #define vr30 30 |
| 738 | #define vr31 31 |
| 739 | |
Michael Neuling | 72ffff5 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 740 | /* VSX Registers (VSRs) */ |
| 741 | |
| 742 | #define vsr0 0 |
| 743 | #define vsr1 1 |
| 744 | #define vsr2 2 |
| 745 | #define vsr3 3 |
| 746 | #define vsr4 4 |
| 747 | #define vsr5 5 |
| 748 | #define vsr6 6 |
| 749 | #define vsr7 7 |
| 750 | #define vsr8 8 |
| 751 | #define vsr9 9 |
| 752 | #define vsr10 10 |
| 753 | #define vsr11 11 |
| 754 | #define vsr12 12 |
| 755 | #define vsr13 13 |
| 756 | #define vsr14 14 |
| 757 | #define vsr15 15 |
| 758 | #define vsr16 16 |
| 759 | #define vsr17 17 |
| 760 | #define vsr18 18 |
| 761 | #define vsr19 19 |
| 762 | #define vsr20 20 |
| 763 | #define vsr21 21 |
| 764 | #define vsr22 22 |
| 765 | #define vsr23 23 |
| 766 | #define vsr24 24 |
| 767 | #define vsr25 25 |
| 768 | #define vsr26 26 |
| 769 | #define vsr27 27 |
| 770 | #define vsr28 28 |
| 771 | #define vsr29 29 |
| 772 | #define vsr30 30 |
| 773 | #define vsr31 31 |
| 774 | #define vsr32 32 |
| 775 | #define vsr33 33 |
| 776 | #define vsr34 34 |
| 777 | #define vsr35 35 |
| 778 | #define vsr36 36 |
| 779 | #define vsr37 37 |
| 780 | #define vsr38 38 |
| 781 | #define vsr39 39 |
| 782 | #define vsr40 40 |
| 783 | #define vsr41 41 |
| 784 | #define vsr42 42 |
| 785 | #define vsr43 43 |
| 786 | #define vsr44 44 |
| 787 | #define vsr45 45 |
| 788 | #define vsr46 46 |
| 789 | #define vsr47 47 |
| 790 | #define vsr48 48 |
| 791 | #define vsr49 49 |
| 792 | #define vsr50 50 |
| 793 | #define vsr51 51 |
| 794 | #define vsr52 52 |
| 795 | #define vsr53 53 |
| 796 | #define vsr54 54 |
| 797 | #define vsr55 55 |
| 798 | #define vsr56 56 |
| 799 | #define vsr57 57 |
| 800 | #define vsr58 58 |
| 801 | #define vsr59 59 |
| 802 | #define vsr60 60 |
| 803 | #define vsr61 61 |
| 804 | #define vsr62 62 |
| 805 | #define vsr63 63 |
| 806 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 807 | /* SPE Registers (EVPRs) */ |
| 808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | #define evr0 0 |
| 810 | #define evr1 1 |
| 811 | #define evr2 2 |
| 812 | #define evr3 3 |
| 813 | #define evr4 4 |
| 814 | #define evr5 5 |
| 815 | #define evr6 6 |
| 816 | #define evr7 7 |
| 817 | #define evr8 8 |
| 818 | #define evr9 9 |
| 819 | #define evr10 10 |
| 820 | #define evr11 11 |
| 821 | #define evr12 12 |
| 822 | #define evr13 13 |
| 823 | #define evr14 14 |
| 824 | #define evr15 15 |
| 825 | #define evr16 16 |
| 826 | #define evr17 17 |
| 827 | #define evr18 18 |
| 828 | #define evr19 19 |
| 829 | #define evr20 20 |
| 830 | #define evr21 21 |
| 831 | #define evr22 22 |
| 832 | #define evr23 23 |
| 833 | #define evr24 24 |
| 834 | #define evr25 25 |
| 835 | #define evr26 26 |
| 836 | #define evr27 27 |
| 837 | #define evr28 28 |
| 838 | #define evr29 29 |
| 839 | #define evr30 30 |
| 840 | #define evr31 31 |
| 841 | |
| 842 | /* some stab codes */ |
| 843 | #define N_FUN 36 |
| 844 | #define N_RSYM 64 |
| 845 | #define N_SLINE 68 |
| 846 | #define N_SO 100 |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 847 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 848 | #endif /* __ASSEMBLY__ */ |
| 849 | |
| 850 | #endif /* _ASM_POWERPC_PPC_ASM_H */ |