blob: db0fa7b5aeaf3f849d0a197f63c7a1ba8a487498 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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. Rozycki619b6e12007-10-23 12:43:25 +01009 * Copyright (C) 2007 Maciej W. Rozycki
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
11#ifndef _ASM_STACKFRAME_H
12#define _ASM_STACKFRAME_H
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/threads.h>
15
16#include <asm/asm.h>
Ralf Baechle41c594a2006-04-05 09:45:45 +010017#include <asm/asmmacro.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/mipsregs.h>
Sam Ravnborg048eb582005-09-09 22:32:31 +020019#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Maciej W. Rozyckifbf6ede2007-05-21 13:47:22 +010021/*
22 * For SMTC kernel, global IE should be left set, and interrupts
23 * controlled exclusively via IXMT.
24 */
25#ifdef CONFIG_MIPS_MT_SMTC
26#define STATMASK 0x1e
27#elif defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
28#define STATMASK 0x3f
29#else
30#define STATMASK 0x1f
31#endif
32
Ralf Baechle41c594a2006-04-05 09:45:45 +010033#ifdef CONFIG_MIPS_MT_SMTC
34#include <asm/mipsmtregs.h>
35#endif /* CONFIG_MIPS_MT_SMTC */
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 .macro SAVE_AT
38 .set push
39 .set noat
40 LONG_S $1, PT_R1(sp)
41 .set pop
42 .endm
43
44 .macro SAVE_TEMP
Franck Bui-Huu9693a852007-02-02 17:41:47 +010045#ifdef CONFIG_CPU_HAS_SMARTMIPS
46 mflhxu v1
47 LONG_S v1, PT_LO(sp)
48 mflhxu v1
49 LONG_S v1, PT_HI(sp)
50 mflhxu v1
51 LONG_S v1, PT_ACX(sp)
52#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 mfhi v1
Franck Bui-Huu9693a852007-02-02 17:41:47 +010054 LONG_S v1, PT_HI(sp)
55 mflo v1
56 LONG_S v1, PT_LO(sp)
57#endif
Ralf Baechle875d43e2005-09-03 15:56:16 -070058#ifdef CONFIG_32BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 LONG_S $8, PT_R8(sp)
60 LONG_S $9, PT_R9(sp)
61#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 LONG_S $10, PT_R10(sp)
63 LONG_S $11, PT_R11(sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 LONG_S $12, PT_R12(sp)
65 LONG_S $13, PT_R13(sp)
66 LONG_S $14, PT_R14(sp)
67 LONG_S $15, PT_R15(sp)
68 LONG_S $24, PT_R24(sp)
69 .endm
70
71 .macro SAVE_STATIC
72 LONG_S $16, PT_R16(sp)
73 LONG_S $17, PT_R17(sp)
74 LONG_S $18, PT_R18(sp)
75 LONG_S $19, PT_R19(sp)
76 LONG_S $20, PT_R20(sp)
77 LONG_S $21, PT_R21(sp)
78 LONG_S $22, PT_R22(sp)
79 LONG_S $23, PT_R23(sp)
80 LONG_S $30, PT_R30(sp)
81 .endm
82
83#ifdef CONFIG_SMP
Atsushi Nemoto9b95e622006-10-10 22:46:52 +090084#ifdef CONFIG_MIPS_MT_SMTC
85#define PTEBASE_SHIFT 19 /* TCBIND */
86#else
87#define PTEBASE_SHIFT 23 /* CONTEXT */
88#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 .macro get_saved_sp /* SMP variation */
Ralf Baechle41c594a2006-04-05 09:45:45 +010090#ifdef CONFIG_MIPS_MT_SMTC
Atsushi Nemoto9b95e622006-10-10 22:46:52 +090091 mfc0 k0, CP0_TCBIND
Ralf Baechle41c594a2006-04-05 09:45:45 +010092#else
Atsushi Nemoto9b95e622006-10-10 22:46:52 +090093 MFC0 k0, CP0_CONTEXT
Ralf Baechle41c594a2006-04-05 09:45:45 +010094#endif
Franck Bui-Huu054c51b2007-02-15 14:21:36 +010095#if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32)
96 lui k1, %hi(kernelsp)
97#else
Atsushi Nemoto9b95e622006-10-10 22:46:52 +090098 lui k1, %highest(kernelsp)
99 daddiu k1, %higher(kernelsp)
100 dsll k1, 16
101 daddiu k1, %hi(kernelsp)
102 dsll k1, 16
Atsushi Nemoto9b95e622006-10-10 22:46:52 +0900103#endif
104 LONG_SRL k0, PTEBASE_SHIFT
105 LONG_ADDU k1, k0
Ralf Baechle85b6e812005-02-13 00:32:43 +0000106 LONG_L k1, %lo(kernelsp)(k1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 .endm
108
109 .macro set_saved_sp stackp temp temp2
Ralf Baechle41c594a2006-04-05 09:45:45 +0100110#ifdef CONFIG_MIPS_MT_SMTC
111 mfc0 \temp, CP0_TCBIND
Ralf Baechle41c594a2006-04-05 09:45:45 +0100112#else
Thiemo Seufer1b3a6e92005-04-01 14:07:13 +0000113 MFC0 \temp, CP0_CONTEXT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#endif
Atsushi Nemoto9b95e622006-10-10 22:46:52 +0900115 LONG_SRL \temp, PTEBASE_SHIFT
Thiemo Seufer9556ac22005-07-08 08:03:48 +0000116 LONG_S \stackp, kernelsp(\temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 .endm
118#else
119 .macro get_saved_sp /* Uniprocessor variation */
Franck Bui-Huu054c51b2007-02-15 14:21:36 +0100120#if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32)
121 lui k1, %hi(kernelsp)
122#else
Thiemo Seufer9556ac22005-07-08 08:03:48 +0000123 lui k1, %highest(kernelsp)
124 daddiu k1, %higher(kernelsp)
125 dsll k1, k1, 16
126 daddiu k1, %hi(kernelsp)
127 dsll k1, k1, 16
Thiemo Seufer9556ac22005-07-08 08:03:48 +0000128#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 LONG_L k1, %lo(kernelsp)(k1)
130 .endm
131
132 .macro set_saved_sp stackp temp temp2
133 LONG_S \stackp, kernelsp
134 .endm
135#endif
136
137 .macro SAVE_SOME
138 .set push
139 .set noat
140 .set reorder
141 mfc0 k0, CP0_STATUS
142 sll k0, 3 /* extract cu0 bit */
143 .set noreorder
144 bltz k0, 8f
145 move k1, sp
146 .set reorder
147 /* Called from user mode, new stack. */
148 get_saved_sp
Maciej W. Rozycki619b6e12007-10-23 12:43:25 +0100149#ifndef CONFIG_CPU_DADDI_WORKAROUNDS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508: move k0, sp
151 PTR_SUBU sp, k1, PT_SIZE
Maciej W. Rozycki619b6e12007-10-23 12:43:25 +0100152#else
153 .set at=k0
1548: PTR_SUBU k1, PT_SIZE
155 .set noat
156 move k0, sp
157 move sp, k1
158#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 LONG_S k0, PT_R29(sp)
160 LONG_S $3, PT_R3(sp)
Ralf Baechle41c594a2006-04-05 09:45:45 +0100161 /*
162 * You might think that you don't need to save $0,
163 * but the FPU emulator and gdb remote debug stub
164 * need it to operate correctly
165 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 LONG_S $0, PT_R0(sp)
167 mfc0 v1, CP0_STATUS
168 LONG_S $2, PT_R2(sp)
169 LONG_S v1, PT_STATUS(sp)
Ralf Baechle41c594a2006-04-05 09:45:45 +0100170#ifdef CONFIG_MIPS_MT_SMTC
171 /*
172 * Ideally, these instructions would be shuffled in
173 * to cover the pipeline delay.
174 */
175 .set mips32
176 mfc0 v1, CP0_TCSTATUS
177 .set mips0
178 LONG_S v1, PT_TCSTATUS(sp)
179#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 LONG_S $4, PT_R4(sp)
181 mfc0 v1, CP0_CAUSE
182 LONG_S $5, PT_R5(sp)
183 LONG_S v1, PT_CAUSE(sp)
184 LONG_S $6, PT_R6(sp)
185 MFC0 v1, CP0_EPC
186 LONG_S $7, PT_R7(sp)
Ralf Baechle875d43e2005-09-03 15:56:16 -0700187#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 LONG_S $8, PT_R8(sp)
189 LONG_S $9, PT_R9(sp)
190#endif
191 LONG_S v1, PT_EPC(sp)
192 LONG_S $25, PT_R25(sp)
193 LONG_S $28, PT_R28(sp)
194 LONG_S $31, PT_R31(sp)
195 ori $28, sp, _THREAD_MASK
196 xori $28, _THREAD_MASK
David Daney2a219b02008-12-11 15:33:33 -0800197#ifdef CONFIG_CPU_CAVIUM_OCTEON
198 .set mips64
199 pref 0, 0($28) /* Prefetch the current pointer */
200 pref 0, PT_R31(sp) /* Prefetch the $31(ra) */
201 /* The Octeon multiplier state is affected by general multiply
202 instructions. It must be saved before and kernel code might
203 corrupt it */
204 jal octeon_mult_save
205 LONG_L v1, 0($28) /* Load the current pointer */
206 /* Restore $31(ra) that was changed by the jal */
207 LONG_L ra, PT_R31(sp)
208 pref 0, 0(v1) /* Prefetch the current thread */
209#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 .set pop
211 .endm
212
213 .macro SAVE_ALL
214 SAVE_SOME
215 SAVE_AT
216 SAVE_TEMP
217 SAVE_STATIC
218 .endm
219
220 .macro RESTORE_AT
221 .set push
222 .set noat
223 LONG_L $1, PT_R1(sp)
224 .set pop
225 .endm
226
227 .macro RESTORE_TEMP
Franck Bui-Huu9693a852007-02-02 17:41:47 +0100228#ifdef CONFIG_CPU_HAS_SMARTMIPS
229 LONG_L $24, PT_ACX(sp)
230 mtlhx $24
231 LONG_L $24, PT_HI(sp)
232 mtlhx $24
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 LONG_L $24, PT_LO(sp)
Franck Bui-Huu9693a852007-02-02 17:41:47 +0100234 mtlhx $24
235#else
236 LONG_L $24, PT_LO(sp)
237 mtlo $24
238 LONG_L $24, PT_HI(sp)
239 mthi $24
240#endif
Ralf Baechle875d43e2005-09-03 15:56:16 -0700241#ifdef CONFIG_32BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 LONG_L $8, PT_R8(sp)
243 LONG_L $9, PT_R9(sp)
244#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 LONG_L $10, PT_R10(sp)
246 LONG_L $11, PT_R11(sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 LONG_L $12, PT_R12(sp)
248 LONG_L $13, PT_R13(sp)
249 LONG_L $14, PT_R14(sp)
250 LONG_L $15, PT_R15(sp)
251 LONG_L $24, PT_R24(sp)
252 .endm
253
254 .macro RESTORE_STATIC
255 LONG_L $16, PT_R16(sp)
256 LONG_L $17, PT_R17(sp)
257 LONG_L $18, PT_R18(sp)
258 LONG_L $19, PT_R19(sp)
259 LONG_L $20, PT_R20(sp)
260 LONG_L $21, PT_R21(sp)
261 LONG_L $22, PT_R22(sp)
262 LONG_L $23, PT_R23(sp)
263 LONG_L $30, PT_R30(sp)
264 .endm
265
266#if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
267
268 .macro RESTORE_SOME
269 .set push
270 .set reorder
271 .set noat
272 mfc0 a0, CP0_STATUS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 li v1, 0xff00
Maciej W. Rozyckifbf6ede2007-05-21 13:47:22 +0100274 ori a0, STATMASK
275 xori a0, STATMASK
276 mtc0 a0, CP0_STATUS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 and a0, v1
278 LONG_L v0, PT_STATUS(sp)
279 nor v1, $0, v1
280 and v0, v1
281 or v0, a0
282 mtc0 v0, CP0_STATUS
283 LONG_L $31, PT_R31(sp)
284 LONG_L $28, PT_R28(sp)
285 LONG_L $25, PT_R25(sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 LONG_L $7, PT_R7(sp)
287 LONG_L $6, PT_R6(sp)
288 LONG_L $5, PT_R5(sp)
289 LONG_L $4, PT_R4(sp)
290 LONG_L $3, PT_R3(sp)
291 LONG_L $2, PT_R2(sp)
292 .set pop
293 .endm
294
295 .macro RESTORE_SP_AND_RET
296 .set push
297 .set noreorder
298 LONG_L k0, PT_EPC(sp)
299 LONG_L sp, PT_R29(sp)
300 jr k0
301 rfe
302 .set pop
303 .endm
304
305#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 .macro RESTORE_SOME
307 .set push
308 .set reorder
309 .set noat
Ralf Baechle41c594a2006-04-05 09:45:45 +0100310#ifdef CONFIG_MIPS_MT_SMTC
311 .set mips32r2
312 /*
Kevin D. Kisselld2bb01b2008-09-09 21:35:01 +0200313 * We need to make sure the read-modify-write
314 * of Status below isn't perturbed by an interrupt
315 * or cross-TC access, so we need to do at least a DMT,
316 * protected by an interrupt-inhibit. But setting IXMT
317 * also creates a few-cycle window where an IPI could
318 * be queued and not be detected before potentially
319 * returning to a WAIT or user-mode loop. It must be
320 * replayed.
321 *
322 * We're in the middle of a context switch, and
323 * we can't dispatch it directly without trashing
324 * some registers, so we'll try to detect this unlikely
325 * case and program a software interrupt in the VPE,
326 * as would be done for a cross-VPE IPI. To accomodate
327 * the handling of that case, we're doing a DVPE instead
328 * of just a DMT here to protect against other threads.
329 * This is a lot of cruft to cover a tiny window.
330 * If you can find a better design, implement it!
331 *
Ralf Baechle41c594a2006-04-05 09:45:45 +0100332 */
333 mfc0 v0, CP0_TCSTATUS
334 ori v0, TCSTATUS_IXMT
335 mtc0 v0, CP0_TCSTATUS
Ralf Baechle4277ff52006-06-03 22:40:15 +0100336 _ehb
Kevin D. Kisselld2bb01b2008-09-09 21:35:01 +0200337 DVPE 5 # dvpe a1
Ralf Baechle41c594a2006-04-05 09:45:45 +0100338 jal mips_ihb
339#endif /* CONFIG_MIPS_MT_SMTC */
David Daney2a219b02008-12-11 15:33:33 -0800340#ifdef CONFIG_CPU_CAVIUM_OCTEON
341 /* Restore the Octeon multiplier state */
342 jal octeon_mult_restore
343#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 mfc0 a0, CP0_STATUS
Ralf Baechle41c594a2006-04-05 09:45:45 +0100345 ori a0, STATMASK
346 xori a0, STATMASK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 mtc0 a0, CP0_STATUS
348 li v1, 0xff00
349 and a0, v1
350 LONG_L v0, PT_STATUS(sp)
351 nor v1, $0, v1
352 and v0, v1
353 or v0, a0
354 mtc0 v0, CP0_STATUS
Ralf Baechle41c594a2006-04-05 09:45:45 +0100355#ifdef CONFIG_MIPS_MT_SMTC
356/*
357 * Only after EXL/ERL have been restored to status can we
358 * restore TCStatus.IXMT.
359 */
360 LONG_L v1, PT_TCSTATUS(sp)
Ralf Baechle4277ff52006-06-03 22:40:15 +0100361 _ehb
Kevin D. Kisselld2bb01b2008-09-09 21:35:01 +0200362 mfc0 a0, CP0_TCSTATUS
Ralf Baechle41c594a2006-04-05 09:45:45 +0100363 andi v1, TCSTATUS_IXMT
Kevin D. Kisselld2bb01b2008-09-09 21:35:01 +0200364 bnez v1, 0f
365
366/*
367 * We'd like to detect any IPIs queued in the tiny window
368 * above and request an software interrupt to service them
369 * when we ERET.
370 *
371 * Computing the offset into the IPIQ array of the executing
372 * TC's IPI queue in-line would be tedious. We use part of
373 * the TCContext register to hold 16 bits of offset that we
374 * can add in-line to find the queue head.
375 */
376 mfc0 v0, CP0_TCCONTEXT
377 la a2, IPIQ
378 srl v0, v0, 16
379 addu a2, a2, v0
380 LONG_L v0, 0(a2)
381 beqz v0, 0f
382/*
383 * If we have a queue, provoke dispatch within the VPE by setting C_SW1
384 */
385 mfc0 v0, CP0_CAUSE
386 ori v0, v0, C_SW1
387 mtc0 v0, CP0_CAUSE
3880:
389 /*
390 * This test should really never branch but
391 * let's be prudent here. Having atomized
392 * the shared register modifications, we can
393 * now EVPE, and must do so before interrupts
394 * are potentially re-enabled.
395 */
396 andi a1, a1, MVPCONTROL_EVP
Ralf Baechle41c594a2006-04-05 09:45:45 +0100397 beqz a1, 1f
Kevin D. Kisselld2bb01b2008-09-09 21:35:01 +0200398 evpe
Ralf Baechle41c594a2006-04-05 09:45:45 +01003991:
Kevin D. Kisselld2bb01b2008-09-09 21:35:01 +0200400 /* We know that TCStatua.IXMT should be set from above */
401 xori a0, a0, TCSTATUS_IXMT
402 or a0, a0, v1
403 mtc0 a0, CP0_TCSTATUS
404 _ehb
405
Ralf Baechle41c594a2006-04-05 09:45:45 +0100406 .set mips0
407#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 LONG_L v1, PT_EPC(sp)
409 MTC0 v1, CP0_EPC
410 LONG_L $31, PT_R31(sp)
411 LONG_L $28, PT_R28(sp)
412 LONG_L $25, PT_R25(sp)
Ralf Baechle875d43e2005-09-03 15:56:16 -0700413#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 LONG_L $8, PT_R8(sp)
415 LONG_L $9, PT_R9(sp)
416#endif
417 LONG_L $7, PT_R7(sp)
418 LONG_L $6, PT_R6(sp)
419 LONG_L $5, PT_R5(sp)
420 LONG_L $4, PT_R4(sp)
421 LONG_L $3, PT_R3(sp)
422 LONG_L $2, PT_R2(sp)
423 .set pop
424 .endm
425
426 .macro RESTORE_SP_AND_RET
427 LONG_L sp, PT_R29(sp)
428 .set mips3
429 eret
430 .set mips0
431 .endm
432
433#endif
434
435 .macro RESTORE_SP
436 LONG_L sp, PT_R29(sp)
437 .endm
438
439 .macro RESTORE_ALL
440 RESTORE_TEMP
441 RESTORE_STATIC
442 RESTORE_AT
443 RESTORE_SOME
444 RESTORE_SP
445 .endm
446
447 .macro RESTORE_ALL_AND_RET
448 RESTORE_TEMP
449 RESTORE_STATIC
450 RESTORE_AT
451 RESTORE_SOME
452 RESTORE_SP_AND_RET
453 .endm
454
455/*
456 * Move to kernel mode and disable interrupts.
457 * Set cp0 enable bit as sign that we're running on the kernel stack
458 */
459 .macro CLI
Ralf Baechle41c594a2006-04-05 09:45:45 +0100460#if !defined(CONFIG_MIPS_MT_SMTC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 mfc0 t0, CP0_STATUS
Maciej W. Rozyckifbf6ede2007-05-21 13:47:22 +0100462 li t1, ST0_CU0 | STATMASK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 or t0, t1
Maciej W. Rozyckifbf6ede2007-05-21 13:47:22 +0100464 xori t0, STATMASK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 mtc0 t0, CP0_STATUS
Ralf Baechle41c594a2006-04-05 09:45:45 +0100466#else /* CONFIG_MIPS_MT_SMTC */
467 /*
468 * For SMTC, we need to set privilege
469 * and disable interrupts only for the
470 * current TC, using the TCStatus register.
471 */
Ralf Baechle21a151d2007-10-11 23:46:15 +0100472 mfc0 t0, CP0_TCSTATUS
Ralf Baechle41c594a2006-04-05 09:45:45 +0100473 /* Fortunately CU 0 is in the same place in both registers */
474 /* Set TCU0, TMX, TKSU (for later inversion) and IXMT */
475 li t1, ST0_CU0 | 0x08001c00
Ralf Baechle21a151d2007-10-11 23:46:15 +0100476 or t0, t1
Ralf Baechle41c594a2006-04-05 09:45:45 +0100477 /* Clear TKSU, leave IXMT */
478 xori t0, 0x00001800
479 mtc0 t0, CP0_TCSTATUS
Ralf Baechle4277ff52006-06-03 22:40:15 +0100480 _ehb
Ralf Baechle41c594a2006-04-05 09:45:45 +0100481 /* We need to leave the global IE bit set, but clear EXL...*/
482 mfc0 t0, CP0_STATUS
483 ori t0, ST0_EXL | ST0_ERL
484 xori t0, ST0_EXL | ST0_ERL
485 mtc0 t0, CP0_STATUS
486#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 irq_disable_hazard
488 .endm
489
490/*
491 * Move to kernel mode and enable interrupts.
492 * Set cp0 enable bit as sign that we're running on the kernel stack
493 */
494 .macro STI
Ralf Baechle41c594a2006-04-05 09:45:45 +0100495#if !defined(CONFIG_MIPS_MT_SMTC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 mfc0 t0, CP0_STATUS
Maciej W. Rozyckifbf6ede2007-05-21 13:47:22 +0100497 li t1, ST0_CU0 | STATMASK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 or t0, t1
Maciej W. Rozyckifbf6ede2007-05-21 13:47:22 +0100499 xori t0, STATMASK & ~1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 mtc0 t0, CP0_STATUS
Ralf Baechle41c594a2006-04-05 09:45:45 +0100501#else /* CONFIG_MIPS_MT_SMTC */
502 /*
503 * For SMTC, we need to set privilege
504 * and enable interrupts only for the
505 * current TC, using the TCStatus register.
506 */
Ralf Baechle4277ff52006-06-03 22:40:15 +0100507 _ehb
Ralf Baechle21a151d2007-10-11 23:46:15 +0100508 mfc0 t0, CP0_TCSTATUS
Ralf Baechle41c594a2006-04-05 09:45:45 +0100509 /* Fortunately CU 0 is in the same place in both registers */
510 /* Set TCU0, TKSU (for later inversion) and IXMT */
511 li t1, ST0_CU0 | 0x08001c00
Ralf Baechle21a151d2007-10-11 23:46:15 +0100512 or t0, t1
Ralf Baechle41c594a2006-04-05 09:45:45 +0100513 /* Clear TKSU *and* IXMT */
514 xori t0, 0x00001c00
515 mtc0 t0, CP0_TCSTATUS
Ralf Baechle4277ff52006-06-03 22:40:15 +0100516 _ehb
Ralf Baechle41c594a2006-04-05 09:45:45 +0100517 /* We need to leave the global IE bit set, but clear EXL...*/
518 mfc0 t0, CP0_STATUS
519 ori t0, ST0_EXL
520 xori t0, ST0_EXL
521 mtc0 t0, CP0_STATUS
522 /* irq_enable_hazard below should expand to EHB for 24K/34K cpus */
523#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 irq_enable_hazard
525 .endm
526
527/*
Maciej W. Rozyckifbf6ede2007-05-21 13:47:22 +0100528 * Just move to kernel mode and leave interrupts as they are. Note
529 * for the R3000 this means copying the previous enable from IEp.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 * Set cp0 enable bit as sign that we're running on the kernel stack
531 */
532 .macro KMODE
Ralf Baechle41c594a2006-04-05 09:45:45 +0100533#ifdef CONFIG_MIPS_MT_SMTC
534 /*
535 * This gets baroque in SMTC. We want to
536 * protect the non-atomic clearing of EXL
537 * with DMT/EMT, but we don't want to take
538 * an interrupt while DMT is still in effect.
539 */
540
541 /* KMODE gets invoked from both reorder and noreorder code */
542 .set push
543 .set mips32r2
544 .set noreorder
545 mfc0 v0, CP0_TCSTATUS
546 andi v1, v0, TCSTATUS_IXMT
547 ori v0, TCSTATUS_IXMT
548 mtc0 v0, CP0_TCSTATUS
Ralf Baechle4277ff52006-06-03 22:40:15 +0100549 _ehb
Ralf Baechle41c594a2006-04-05 09:45:45 +0100550 DMT 2 # dmt v0
551 /*
552 * We don't know a priori if ra is "live"
553 */
554 move t0, ra
555 jal mips_ihb
556 nop /* delay slot */
557 move ra, t0
558#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 mfc0 t0, CP0_STATUS
Maciej W. Rozyckifbf6ede2007-05-21 13:47:22 +0100560 li t1, ST0_CU0 | (STATMASK & ~1)
561#if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
562 andi t2, t0, ST0_IEP
563 srl t2, 2
564 or t0, t2
565#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 or t0, t1
Maciej W. Rozyckifbf6ede2007-05-21 13:47:22 +0100567 xori t0, STATMASK & ~1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 mtc0 t0, CP0_STATUS
Ralf Baechle41c594a2006-04-05 09:45:45 +0100569#ifdef CONFIG_MIPS_MT_SMTC
Ralf Baechle4277ff52006-06-03 22:40:15 +0100570 _ehb
Ralf Baechle41c594a2006-04-05 09:45:45 +0100571 andi v0, v0, VPECONTROL_TE
572 beqz v0, 2f
573 nop /* delay slot */
574 emt
5752:
576 mfc0 v0, CP0_TCSTATUS
577 /* Clear IXMT, then OR in previous value */
578 ori v0, TCSTATUS_IXMT
579 xori v0, TCSTATUS_IXMT
580 or v0, v1, v0
581 mtc0 v0, CP0_TCSTATUS
582 /*
583 * irq_disable_hazard below should expand to EHB
584 * on 24K/34K CPUS
585 */
586 .set pop
587#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 irq_disable_hazard
589 .endm
590
591#endif /* _ASM_STACKFRAME_H */