Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 1994, 95, 96, 99, 2001 Ralf Baechle |
| 7 | * Copyright (C) 1994, 1995, 1996 Paul M. Antoine. |
| 8 | * Copyright (C) 1999 Silicon Graphics, Inc. |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 9 | * Copyright (C) 2007 Maciej W. Rozycki |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | #ifndef _ASM_STACKFRAME_H |
| 12 | #define _ASM_STACKFRAME_H |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/threads.h> |
| 15 | |
| 16 | #include <asm/asm.h> |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 17 | #include <asm/asmmacro.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/mipsregs.h> |
Sam Ravnborg | 048eb58 | 2005-09-09 22:32:31 +0200 | [diff] [blame] | 19 | #include <asm/asm-offsets.h> |
Jayachandran C | c2377a4 | 2013-08-11 17:10:16 +0530 | [diff] [blame] | 20 | #include <asm/thread_info.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Maciej W. Rozycki | fbf6ede | 2007-05-21 13:47:22 +0100 | [diff] [blame] | 22 | /* |
| 23 | * For SMTC kernel, global IE should be left set, and interrupts |
| 24 | * controlled exclusively via IXMT. |
| 25 | */ |
| 26 | #ifdef CONFIG_MIPS_MT_SMTC |
| 27 | #define STATMASK 0x1e |
| 28 | #elif defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX) |
| 29 | #define STATMASK 0x3f |
| 30 | #else |
| 31 | #define STATMASK 0x1f |
| 32 | #endif |
| 33 | |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 34 | #ifdef CONFIG_MIPS_MT_SMTC |
| 35 | #include <asm/mipsmtregs.h> |
| 36 | #endif /* CONFIG_MIPS_MT_SMTC */ |
| 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | .macro SAVE_AT |
| 39 | .set push |
| 40 | .set noat |
| 41 | LONG_S $1, PT_R1(sp) |
| 42 | .set pop |
| 43 | .endm |
| 44 | |
| 45 | .macro SAVE_TEMP |
Franck Bui-Huu | 9693a85 | 2007-02-02 17:41:47 +0100 | [diff] [blame] | 46 | #ifdef CONFIG_CPU_HAS_SMARTMIPS |
| 47 | mflhxu v1 |
| 48 | LONG_S v1, PT_LO(sp) |
| 49 | mflhxu v1 |
| 50 | LONG_S v1, PT_HI(sp) |
| 51 | mflhxu v1 |
| 52 | LONG_S v1, PT_ACX(sp) |
| 53 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | mfhi v1 |
Franck Bui-Huu | 9693a85 | 2007-02-02 17:41:47 +0100 | [diff] [blame] | 55 | #endif |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 56 | #ifdef CONFIG_32BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | LONG_S $8, PT_R8(sp) |
| 58 | LONG_S $9, PT_R9(sp) |
| 59 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | LONG_S $10, PT_R10(sp) |
| 61 | LONG_S $11, PT_R11(sp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | LONG_S $12, PT_R12(sp) |
David Daney | 362e696 | 2009-06-26 09:01:43 -0700 | [diff] [blame] | 63 | #ifndef CONFIG_CPU_HAS_SMARTMIPS |
| 64 | LONG_S v1, PT_HI(sp) |
| 65 | mflo v1 |
| 66 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | LONG_S $13, PT_R13(sp) |
| 68 | LONG_S $14, PT_R14(sp) |
| 69 | LONG_S $15, PT_R15(sp) |
| 70 | LONG_S $24, PT_R24(sp) |
David Daney | 362e696 | 2009-06-26 09:01:43 -0700 | [diff] [blame] | 71 | #ifndef CONFIG_CPU_HAS_SMARTMIPS |
| 72 | LONG_S v1, PT_LO(sp) |
| 73 | #endif |
David Daney | 8dfdd02 | 2013-06-21 21:14:53 +0000 | [diff] [blame] | 74 | #ifdef CONFIG_CPU_CAVIUM_OCTEON |
| 75 | /* |
| 76 | * The Octeon multiplier state is affected by general |
| 77 | * multiply instructions. It must be saved before and |
| 78 | * kernel code might corrupt it |
| 79 | */ |
| 80 | jal octeon_mult_save |
| 81 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | .endm |
| 83 | |
| 84 | .macro SAVE_STATIC |
| 85 | LONG_S $16, PT_R16(sp) |
| 86 | LONG_S $17, PT_R17(sp) |
| 87 | LONG_S $18, PT_R18(sp) |
| 88 | LONG_S $19, PT_R19(sp) |
| 89 | LONG_S $20, PT_R20(sp) |
| 90 | LONG_S $21, PT_R21(sp) |
| 91 | LONG_S $22, PT_R22(sp) |
| 92 | LONG_S $23, PT_R23(sp) |
| 93 | LONG_S $30, PT_R30(sp) |
| 94 | .endm |
| 95 | |
| 96 | #ifdef CONFIG_SMP |
| 97 | .macro get_saved_sp /* SMP variation */ |
Jayachandran C | c2377a4 | 2013-08-11 17:10:16 +0530 | [diff] [blame] | 98 | ASM_CPUID_MFC0 k0, ASM_SMP_CPUID_REG |
Franck Bui-Huu | 054c51b | 2007-02-15 14:21:36 +0100 | [diff] [blame] | 99 | #if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32) |
| 100 | lui k1, %hi(kernelsp) |
| 101 | #else |
Atsushi Nemoto | 9b95e62 | 2006-10-10 22:46:52 +0900 | [diff] [blame] | 102 | lui k1, %highest(kernelsp) |
| 103 | daddiu k1, %higher(kernelsp) |
| 104 | dsll k1, 16 |
| 105 | daddiu k1, %hi(kernelsp) |
| 106 | dsll k1, 16 |
Atsushi Nemoto | 9b95e62 | 2006-10-10 22:46:52 +0900 | [diff] [blame] | 107 | #endif |
Jayachandran C | c2377a4 | 2013-08-11 17:10:16 +0530 | [diff] [blame] | 108 | LONG_SRL k0, SMP_CPUID_PTRSHIFT |
Atsushi Nemoto | 9b95e62 | 2006-10-10 22:46:52 +0900 | [diff] [blame] | 109 | LONG_ADDU k1, k0 |
Ralf Baechle | 85b6e81 | 2005-02-13 00:32:43 +0000 | [diff] [blame] | 110 | LONG_L k1, %lo(kernelsp)(k1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | .endm |
| 112 | |
| 113 | .macro set_saved_sp stackp temp temp2 |
Jayachandran C | c2377a4 | 2013-08-11 17:10:16 +0530 | [diff] [blame] | 114 | ASM_CPUID_MFC0 \temp, ASM_SMP_CPUID_REG |
| 115 | LONG_SRL \temp, SMP_CPUID_PTRSHIFT |
Thiemo Seufer | 9556ac2 | 2005-07-08 08:03:48 +0000 | [diff] [blame] | 116 | LONG_S \stackp, kernelsp(\temp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | .endm |
Jayachandran C | c2377a4 | 2013-08-11 17:10:16 +0530 | [diff] [blame] | 118 | #else /* !CONFIG_SMP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | .macro get_saved_sp /* Uniprocessor variation */ |
Wu Zhangjin | b197b62 | 2010-04-10 20:07:01 +0800 | [diff] [blame] | 120 | #ifdef CONFIG_CPU_JUMP_WORKAROUNDS |
Wu Zhangjin | f1df323 | 2010-03-13 12:34:15 +0800 | [diff] [blame] | 121 | /* |
| 122 | * Clear BTB (branch target buffer), forbid RAS (return address |
| 123 | * stack) to workaround the Out-of-order Issue in Loongson2F |
| 124 | * via its diagnostic register. |
| 125 | */ |
| 126 | move k0, ra |
| 127 | jal 1f |
| 128 | nop |
| 129 | 1: jal 1f |
| 130 | nop |
| 131 | 1: jal 1f |
| 132 | nop |
| 133 | 1: jal 1f |
| 134 | nop |
| 135 | 1: move ra, k0 |
| 136 | li k0, 3 |
| 137 | mtc0 k0, $22 |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 138 | #endif /* CONFIG_CPU_JUMP_WORKAROUNDS */ |
Franck Bui-Huu | 054c51b | 2007-02-15 14:21:36 +0100 | [diff] [blame] | 139 | #if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32) |
| 140 | lui k1, %hi(kernelsp) |
| 141 | #else |
Thiemo Seufer | 9556ac2 | 2005-07-08 08:03:48 +0000 | [diff] [blame] | 142 | lui k1, %highest(kernelsp) |
| 143 | daddiu k1, %higher(kernelsp) |
| 144 | dsll k1, k1, 16 |
| 145 | daddiu k1, %hi(kernelsp) |
| 146 | dsll k1, k1, 16 |
Thiemo Seufer | 9556ac2 | 2005-07-08 08:03:48 +0000 | [diff] [blame] | 147 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | LONG_L k1, %lo(kernelsp)(k1) |
| 149 | .endm |
| 150 | |
| 151 | .macro set_saved_sp stackp temp temp2 |
| 152 | LONG_S \stackp, kernelsp |
| 153 | .endm |
| 154 | #endif |
| 155 | |
| 156 | .macro SAVE_SOME |
| 157 | .set push |
| 158 | .set noat |
| 159 | .set reorder |
| 160 | mfc0 k0, CP0_STATUS |
| 161 | sll k0, 3 /* extract cu0 bit */ |
| 162 | .set noreorder |
| 163 | bltz k0, 8f |
| 164 | move k1, sp |
| 165 | .set reorder |
| 166 | /* Called from user mode, new stack. */ |
| 167 | get_saved_sp |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 168 | #ifndef CONFIG_CPU_DADDI_WORKAROUNDS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | 8: move k0, sp |
| 170 | PTR_SUBU sp, k1, PT_SIZE |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 171 | #else |
| 172 | .set at=k0 |
| 173 | 8: PTR_SUBU k1, PT_SIZE |
| 174 | .set noat |
| 175 | move k0, sp |
| 176 | move sp, k1 |
| 177 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | LONG_S k0, PT_R29(sp) |
| 179 | LONG_S $3, PT_R3(sp) |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 180 | /* |
| 181 | * You might think that you don't need to save $0, |
| 182 | * but the FPU emulator and gdb remote debug stub |
| 183 | * need it to operate correctly |
| 184 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | LONG_S $0, PT_R0(sp) |
| 186 | mfc0 v1, CP0_STATUS |
| 187 | LONG_S $2, PT_R2(sp) |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 188 | LONG_S v1, PT_STATUS(sp) |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 189 | #ifdef CONFIG_MIPS_MT_SMTC |
| 190 | /* |
| 191 | * Ideally, these instructions would be shuffled in |
| 192 | * to cover the pipeline delay. |
| 193 | */ |
| 194 | .set mips32 |
David Daney | d968275 | 2011-08-30 06:45:20 -0700 | [diff] [blame] | 195 | mfc0 k0, CP0_TCSTATUS |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 196 | .set mips0 |
David Daney | d968275 | 2011-08-30 06:45:20 -0700 | [diff] [blame] | 197 | LONG_S k0, PT_TCSTATUS(sp) |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 198 | #endif /* CONFIG_MIPS_MT_SMTC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | LONG_S $4, PT_R4(sp) |
David Daney | 362e696 | 2009-06-26 09:01:43 -0700 | [diff] [blame] | 200 | mfc0 v1, CP0_CAUSE |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 201 | LONG_S $5, PT_R5(sp) |
David Daney | 362e696 | 2009-06-26 09:01:43 -0700 | [diff] [blame] | 202 | LONG_S v1, PT_CAUSE(sp) |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 203 | LONG_S $6, PT_R6(sp) |
David Daney | 362e696 | 2009-06-26 09:01:43 -0700 | [diff] [blame] | 204 | MFC0 v1, CP0_EPC |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 205 | LONG_S $7, PT_R7(sp) |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 206 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | LONG_S $8, PT_R8(sp) |
| 208 | LONG_S $9, PT_R9(sp) |
| 209 | #endif |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 210 | LONG_S v1, PT_EPC(sp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | LONG_S $25, PT_R25(sp) |
| 212 | LONG_S $28, PT_R28(sp) |
| 213 | LONG_S $31, PT_R31(sp) |
| 214 | ori $28, sp, _THREAD_MASK |
| 215 | xori $28, _THREAD_MASK |
David Daney | 2a219b0 | 2008-12-11 15:33:33 -0800 | [diff] [blame] | 216 | #ifdef CONFIG_CPU_CAVIUM_OCTEON |
David Daney | 8dfdd02 | 2013-06-21 21:14:53 +0000 | [diff] [blame] | 217 | .set mips64 |
| 218 | pref 0, 0($28) /* Prefetch the current pointer */ |
David Daney | 2a219b0 | 2008-12-11 15:33:33 -0800 | [diff] [blame] | 219 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | .set pop |
| 221 | .endm |
| 222 | |
| 223 | .macro SAVE_ALL |
| 224 | SAVE_SOME |
| 225 | SAVE_AT |
| 226 | SAVE_TEMP |
| 227 | SAVE_STATIC |
| 228 | .endm |
| 229 | |
| 230 | .macro RESTORE_AT |
| 231 | .set push |
| 232 | .set noat |
| 233 | LONG_L $1, PT_R1(sp) |
| 234 | .set pop |
| 235 | .endm |
| 236 | |
| 237 | .macro RESTORE_TEMP |
David Daney | 8dfdd02 | 2013-06-21 21:14:53 +0000 | [diff] [blame] | 238 | #ifdef CONFIG_CPU_CAVIUM_OCTEON |
| 239 | /* Restore the Octeon multiplier state */ |
| 240 | jal octeon_mult_restore |
| 241 | #endif |
Franck Bui-Huu | 9693a85 | 2007-02-02 17:41:47 +0100 | [diff] [blame] | 242 | #ifdef CONFIG_CPU_HAS_SMARTMIPS |
| 243 | LONG_L $24, PT_ACX(sp) |
| 244 | mtlhx $24 |
| 245 | LONG_L $24, PT_HI(sp) |
| 246 | mtlhx $24 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | LONG_L $24, PT_LO(sp) |
Franck Bui-Huu | 9693a85 | 2007-02-02 17:41:47 +0100 | [diff] [blame] | 248 | mtlhx $24 |
| 249 | #else |
| 250 | LONG_L $24, PT_LO(sp) |
| 251 | mtlo $24 |
| 252 | LONG_L $24, PT_HI(sp) |
| 253 | mthi $24 |
| 254 | #endif |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 255 | #ifdef CONFIG_32BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | LONG_L $8, PT_R8(sp) |
| 257 | LONG_L $9, PT_R9(sp) |
| 258 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | LONG_L $10, PT_R10(sp) |
| 260 | LONG_L $11, PT_R11(sp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | LONG_L $12, PT_R12(sp) |
| 262 | LONG_L $13, PT_R13(sp) |
| 263 | LONG_L $14, PT_R14(sp) |
| 264 | LONG_L $15, PT_R15(sp) |
| 265 | LONG_L $24, PT_R24(sp) |
| 266 | .endm |
| 267 | |
| 268 | .macro RESTORE_STATIC |
| 269 | LONG_L $16, PT_R16(sp) |
| 270 | LONG_L $17, PT_R17(sp) |
| 271 | LONG_L $18, PT_R18(sp) |
| 272 | LONG_L $19, PT_R19(sp) |
| 273 | LONG_L $20, PT_R20(sp) |
| 274 | LONG_L $21, PT_R21(sp) |
| 275 | LONG_L $22, PT_R22(sp) |
| 276 | LONG_L $23, PT_R23(sp) |
| 277 | LONG_L $30, PT_R30(sp) |
| 278 | .endm |
| 279 | |
| 280 | #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX) |
| 281 | |
| 282 | .macro RESTORE_SOME |
| 283 | .set push |
| 284 | .set reorder |
| 285 | .set noat |
| 286 | mfc0 a0, CP0_STATUS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | li v1, 0xff00 |
Maciej W. Rozycki | fbf6ede | 2007-05-21 13:47:22 +0100 | [diff] [blame] | 288 | ori a0, STATMASK |
| 289 | xori a0, STATMASK |
| 290 | mtc0 a0, CP0_STATUS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | and a0, v1 |
| 292 | LONG_L v0, PT_STATUS(sp) |
| 293 | nor v1, $0, v1 |
| 294 | and v0, v1 |
| 295 | or v0, a0 |
| 296 | mtc0 v0, CP0_STATUS |
| 297 | LONG_L $31, PT_R31(sp) |
| 298 | LONG_L $28, PT_R28(sp) |
| 299 | LONG_L $25, PT_R25(sp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | LONG_L $7, PT_R7(sp) |
| 301 | LONG_L $6, PT_R6(sp) |
| 302 | LONG_L $5, PT_R5(sp) |
| 303 | LONG_L $4, PT_R4(sp) |
| 304 | LONG_L $3, PT_R3(sp) |
| 305 | LONG_L $2, PT_R2(sp) |
| 306 | .set pop |
| 307 | .endm |
| 308 | |
| 309 | .macro RESTORE_SP_AND_RET |
| 310 | .set push |
| 311 | .set noreorder |
| 312 | LONG_L k0, PT_EPC(sp) |
| 313 | LONG_L sp, PT_R29(sp) |
| 314 | jr k0 |
| 315 | rfe |
| 316 | .set pop |
| 317 | .endm |
| 318 | |
| 319 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | .macro RESTORE_SOME |
| 321 | .set push |
| 322 | .set reorder |
| 323 | .set noat |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 324 | #ifdef CONFIG_MIPS_MT_SMTC |
| 325 | .set mips32r2 |
| 326 | /* |
Kevin D. Kissell | d2bb01b | 2008-09-09 21:35:01 +0200 | [diff] [blame] | 327 | * We need to make sure the read-modify-write |
| 328 | * of Status below isn't perturbed by an interrupt |
| 329 | * or cross-TC access, so we need to do at least a DMT, |
| 330 | * protected by an interrupt-inhibit. But setting IXMT |
| 331 | * also creates a few-cycle window where an IPI could |
| 332 | * be queued and not be detected before potentially |
| 333 | * returning to a WAIT or user-mode loop. It must be |
| 334 | * replayed. |
| 335 | * |
| 336 | * We're in the middle of a context switch, and |
| 337 | * we can't dispatch it directly without trashing |
| 338 | * some registers, so we'll try to detect this unlikely |
| 339 | * case and program a software interrupt in the VPE, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 340 | * as would be done for a cross-VPE IPI. To accommodate |
Kevin D. Kissell | d2bb01b | 2008-09-09 21:35:01 +0200 | [diff] [blame] | 341 | * the handling of that case, we're doing a DVPE instead |
| 342 | * of just a DMT here to protect against other threads. |
| 343 | * This is a lot of cruft to cover a tiny window. |
| 344 | * If you can find a better design, implement it! |
| 345 | * |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 346 | */ |
| 347 | mfc0 v0, CP0_TCSTATUS |
| 348 | ori v0, TCSTATUS_IXMT |
| 349 | mtc0 v0, CP0_TCSTATUS |
Ralf Baechle | 4277ff5 | 2006-06-03 22:40:15 +0100 | [diff] [blame] | 350 | _ehb |
Kevin D. Kissell | d2bb01b | 2008-09-09 21:35:01 +0200 | [diff] [blame] | 351 | DVPE 5 # dvpe a1 |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 352 | jal mips_ihb |
| 353 | #endif /* CONFIG_MIPS_MT_SMTC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | mfc0 a0, CP0_STATUS |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 355 | ori a0, STATMASK |
| 356 | xori a0, STATMASK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | mtc0 a0, CP0_STATUS |
| 358 | li v1, 0xff00 |
| 359 | and a0, v1 |
| 360 | LONG_L v0, PT_STATUS(sp) |
| 361 | nor v1, $0, v1 |
| 362 | and v0, v1 |
| 363 | or v0, a0 |
| 364 | mtc0 v0, CP0_STATUS |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 365 | #ifdef CONFIG_MIPS_MT_SMTC |
| 366 | /* |
| 367 | * Only after EXL/ERL have been restored to status can we |
| 368 | * restore TCStatus.IXMT. |
| 369 | */ |
| 370 | LONG_L v1, PT_TCSTATUS(sp) |
Ralf Baechle | 4277ff5 | 2006-06-03 22:40:15 +0100 | [diff] [blame] | 371 | _ehb |
Kevin D. Kissell | d2bb01b | 2008-09-09 21:35:01 +0200 | [diff] [blame] | 372 | mfc0 a0, CP0_TCSTATUS |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 373 | andi v1, TCSTATUS_IXMT |
Kevin D. Kissell | d2bb01b | 2008-09-09 21:35:01 +0200 | [diff] [blame] | 374 | bnez v1, 0f |
| 375 | |
| 376 | /* |
| 377 | * We'd like to detect any IPIs queued in the tiny window |
| 378 | * above and request an software interrupt to service them |
| 379 | * when we ERET. |
| 380 | * |
| 381 | * Computing the offset into the IPIQ array of the executing |
| 382 | * TC's IPI queue in-line would be tedious. We use part of |
| 383 | * the TCContext register to hold 16 bits of offset that we |
| 384 | * can add in-line to find the queue head. |
| 385 | */ |
| 386 | mfc0 v0, CP0_TCCONTEXT |
| 387 | la a2, IPIQ |
| 388 | srl v0, v0, 16 |
| 389 | addu a2, a2, v0 |
| 390 | LONG_L v0, 0(a2) |
| 391 | beqz v0, 0f |
| 392 | /* |
| 393 | * If we have a queue, provoke dispatch within the VPE by setting C_SW1 |
| 394 | */ |
| 395 | mfc0 v0, CP0_CAUSE |
| 396 | ori v0, v0, C_SW1 |
| 397 | mtc0 v0, CP0_CAUSE |
| 398 | 0: |
| 399 | /* |
| 400 | * This test should really never branch but |
| 401 | * let's be prudent here. Having atomized |
| 402 | * the shared register modifications, we can |
| 403 | * now EVPE, and must do so before interrupts |
| 404 | * are potentially re-enabled. |
| 405 | */ |
| 406 | andi a1, a1, MVPCONTROL_EVP |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 407 | beqz a1, 1f |
Kevin D. Kissell | d2bb01b | 2008-09-09 21:35:01 +0200 | [diff] [blame] | 408 | evpe |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 409 | 1: |
Kevin D. Kissell | d2bb01b | 2008-09-09 21:35:01 +0200 | [diff] [blame] | 410 | /* We know that TCStatua.IXMT should be set from above */ |
| 411 | xori a0, a0, TCSTATUS_IXMT |
| 412 | or a0, a0, v1 |
| 413 | mtc0 a0, CP0_TCSTATUS |
| 414 | _ehb |
| 415 | |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 416 | .set mips0 |
| 417 | #endif /* CONFIG_MIPS_MT_SMTC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | LONG_L v1, PT_EPC(sp) |
| 419 | MTC0 v1, CP0_EPC |
| 420 | LONG_L $31, PT_R31(sp) |
| 421 | LONG_L $28, PT_R28(sp) |
| 422 | LONG_L $25, PT_R25(sp) |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 423 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | LONG_L $8, PT_R8(sp) |
| 425 | LONG_L $9, PT_R9(sp) |
| 426 | #endif |
| 427 | LONG_L $7, PT_R7(sp) |
| 428 | LONG_L $6, PT_R6(sp) |
| 429 | LONG_L $5, PT_R5(sp) |
| 430 | LONG_L $4, PT_R4(sp) |
| 431 | LONG_L $3, PT_R3(sp) |
| 432 | LONG_L $2, PT_R2(sp) |
| 433 | .set pop |
| 434 | .endm |
| 435 | |
| 436 | .macro RESTORE_SP_AND_RET |
| 437 | LONG_L sp, PT_R29(sp) |
| 438 | .set mips3 |
| 439 | eret |
| 440 | .set mips0 |
| 441 | .endm |
| 442 | |
| 443 | #endif |
| 444 | |
| 445 | .macro RESTORE_SP |
| 446 | LONG_L sp, PT_R29(sp) |
| 447 | .endm |
| 448 | |
| 449 | .macro RESTORE_ALL |
| 450 | RESTORE_TEMP |
| 451 | RESTORE_STATIC |
| 452 | RESTORE_AT |
| 453 | RESTORE_SOME |
| 454 | RESTORE_SP |
| 455 | .endm |
| 456 | |
| 457 | .macro RESTORE_ALL_AND_RET |
| 458 | RESTORE_TEMP |
| 459 | RESTORE_STATIC |
| 460 | RESTORE_AT |
| 461 | RESTORE_SOME |
| 462 | RESTORE_SP_AND_RET |
| 463 | .endm |
| 464 | |
| 465 | /* |
| 466 | * Move to kernel mode and disable interrupts. |
| 467 | * Set cp0 enable bit as sign that we're running on the kernel stack |
| 468 | */ |
| 469 | .macro CLI |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 470 | #if !defined(CONFIG_MIPS_MT_SMTC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | mfc0 t0, CP0_STATUS |
Maciej W. Rozycki | fbf6ede | 2007-05-21 13:47:22 +0100 | [diff] [blame] | 472 | li t1, ST0_CU0 | STATMASK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | or t0, t1 |
Maciej W. Rozycki | fbf6ede | 2007-05-21 13:47:22 +0100 | [diff] [blame] | 474 | xori t0, STATMASK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | mtc0 t0, CP0_STATUS |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 476 | #else /* CONFIG_MIPS_MT_SMTC */ |
| 477 | /* |
| 478 | * For SMTC, we need to set privilege |
| 479 | * and disable interrupts only for the |
| 480 | * current TC, using the TCStatus register. |
| 481 | */ |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 482 | mfc0 t0, CP0_TCSTATUS |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 483 | /* Fortunately CU 0 is in the same place in both registers */ |
| 484 | /* Set TCU0, TMX, TKSU (for later inversion) and IXMT */ |
| 485 | li t1, ST0_CU0 | 0x08001c00 |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 486 | or t0, t1 |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 487 | /* Clear TKSU, leave IXMT */ |
| 488 | xori t0, 0x00001800 |
| 489 | mtc0 t0, CP0_TCSTATUS |
Ralf Baechle | 4277ff5 | 2006-06-03 22:40:15 +0100 | [diff] [blame] | 490 | _ehb |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 491 | /* We need to leave the global IE bit set, but clear EXL...*/ |
| 492 | mfc0 t0, CP0_STATUS |
| 493 | ori t0, ST0_EXL | ST0_ERL |
| 494 | xori t0, ST0_EXL | ST0_ERL |
| 495 | mtc0 t0, CP0_STATUS |
| 496 | #endif /* CONFIG_MIPS_MT_SMTC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | irq_disable_hazard |
| 498 | .endm |
| 499 | |
| 500 | /* |
| 501 | * Move to kernel mode and enable interrupts. |
| 502 | * Set cp0 enable bit as sign that we're running on the kernel stack |
| 503 | */ |
| 504 | .macro STI |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 505 | #if !defined(CONFIG_MIPS_MT_SMTC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | mfc0 t0, CP0_STATUS |
Maciej W. Rozycki | fbf6ede | 2007-05-21 13:47:22 +0100 | [diff] [blame] | 507 | li t1, ST0_CU0 | STATMASK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | or t0, t1 |
Maciej W. Rozycki | fbf6ede | 2007-05-21 13:47:22 +0100 | [diff] [blame] | 509 | xori t0, STATMASK & ~1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | mtc0 t0, CP0_STATUS |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 511 | #else /* CONFIG_MIPS_MT_SMTC */ |
| 512 | /* |
| 513 | * For SMTC, we need to set privilege |
| 514 | * and enable interrupts only for the |
| 515 | * current TC, using the TCStatus register. |
| 516 | */ |
Ralf Baechle | 4277ff5 | 2006-06-03 22:40:15 +0100 | [diff] [blame] | 517 | _ehb |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 518 | mfc0 t0, CP0_TCSTATUS |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 519 | /* Fortunately CU 0 is in the same place in both registers */ |
| 520 | /* Set TCU0, TKSU (for later inversion) and IXMT */ |
| 521 | li t1, ST0_CU0 | 0x08001c00 |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 522 | or t0, t1 |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 523 | /* Clear TKSU *and* IXMT */ |
| 524 | xori t0, 0x00001c00 |
| 525 | mtc0 t0, CP0_TCSTATUS |
Ralf Baechle | 4277ff5 | 2006-06-03 22:40:15 +0100 | [diff] [blame] | 526 | _ehb |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 527 | /* We need to leave the global IE bit set, but clear EXL...*/ |
| 528 | mfc0 t0, CP0_STATUS |
| 529 | ori t0, ST0_EXL |
| 530 | xori t0, ST0_EXL |
| 531 | mtc0 t0, CP0_STATUS |
| 532 | /* irq_enable_hazard below should expand to EHB for 24K/34K cpus */ |
| 533 | #endif /* CONFIG_MIPS_MT_SMTC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | irq_enable_hazard |
| 535 | .endm |
| 536 | |
| 537 | /* |
Maciej W. Rozycki | fbf6ede | 2007-05-21 13:47:22 +0100 | [diff] [blame] | 538 | * Just move to kernel mode and leave interrupts as they are. Note |
| 539 | * for the R3000 this means copying the previous enable from IEp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | * Set cp0 enable bit as sign that we're running on the kernel stack |
| 541 | */ |
| 542 | .macro KMODE |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 543 | #ifdef CONFIG_MIPS_MT_SMTC |
| 544 | /* |
| 545 | * This gets baroque in SMTC. We want to |
| 546 | * protect the non-atomic clearing of EXL |
| 547 | * with DMT/EMT, but we don't want to take |
| 548 | * an interrupt while DMT is still in effect. |
| 549 | */ |
| 550 | |
| 551 | /* KMODE gets invoked from both reorder and noreorder code */ |
| 552 | .set push |
| 553 | .set mips32r2 |
| 554 | .set noreorder |
| 555 | mfc0 v0, CP0_TCSTATUS |
| 556 | andi v1, v0, TCSTATUS_IXMT |
| 557 | ori v0, TCSTATUS_IXMT |
| 558 | mtc0 v0, CP0_TCSTATUS |
Ralf Baechle | 4277ff5 | 2006-06-03 22:40:15 +0100 | [diff] [blame] | 559 | _ehb |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 560 | DMT 2 # dmt v0 |
| 561 | /* |
| 562 | * We don't know a priori if ra is "live" |
| 563 | */ |
| 564 | move t0, ra |
| 565 | jal mips_ihb |
| 566 | nop /* delay slot */ |
| 567 | move ra, t0 |
| 568 | #endif /* CONFIG_MIPS_MT_SMTC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | mfc0 t0, CP0_STATUS |
Maciej W. Rozycki | fbf6ede | 2007-05-21 13:47:22 +0100 | [diff] [blame] | 570 | li t1, ST0_CU0 | (STATMASK & ~1) |
| 571 | #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX) |
| 572 | andi t2, t0, ST0_IEP |
| 573 | srl t2, 2 |
| 574 | or t0, t2 |
| 575 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | or t0, t1 |
Maciej W. Rozycki | fbf6ede | 2007-05-21 13:47:22 +0100 | [diff] [blame] | 577 | xori t0, STATMASK & ~1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | mtc0 t0, CP0_STATUS |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 579 | #ifdef CONFIG_MIPS_MT_SMTC |
Ralf Baechle | 4277ff5 | 2006-06-03 22:40:15 +0100 | [diff] [blame] | 580 | _ehb |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 581 | andi v0, v0, VPECONTROL_TE |
| 582 | beqz v0, 2f |
| 583 | nop /* delay slot */ |
| 584 | emt |
| 585 | 2: |
| 586 | mfc0 v0, CP0_TCSTATUS |
| 587 | /* Clear IXMT, then OR in previous value */ |
| 588 | ori v0, TCSTATUS_IXMT |
| 589 | xori v0, TCSTATUS_IXMT |
| 590 | or v0, v1, v0 |
| 591 | mtc0 v0, CP0_TCSTATUS |
| 592 | /* |
| 593 | * irq_disable_hazard below should expand to EHB |
| 594 | * on 24K/34K CPUS |
| 595 | */ |
| 596 | .set pop |
| 597 | #endif /* CONFIG_MIPS_MT_SMTC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | irq_disable_hazard |
| 599 | .endm |
| 600 | |
| 601 | #endif /* _ASM_STACKFRAME_H */ |