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
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.
9 * Copyright (C) 2007 Maciej W. Rozycki
11 #ifndef _ASM_STACKFRAME_H
12 #define _ASM_STACKFRAME_H
14 #include <linux/threads.h>
17 #include <asm/asmmacro.h>
18 #include <asm/mipsregs.h>
19 #include <asm/asm-offsets.h>
22 * For SMTC kernel, global IE should be left set, and interrupts
23 * controlled exclusively via IXMT.
25 #ifdef CONFIG_MIPS_MT_SMTC
27 #elif defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
33 #ifdef CONFIG_MIPS_MT_SMTC
34 #include <asm/mipsmtregs.h>
35 #endif /* CONFIG_MIPS_MT_SMTC */
45 #ifdef CONFIG_CPU_HAS_SMARTMIPS
59 LONG_S $
10, PT_R10(sp
)
60 LONG_S $
11, PT_R11(sp
)
61 LONG_S $
12, PT_R12(sp
)
62 #ifndef CONFIG_CPU_HAS_SMARTMIPS
66 LONG_S $
13, PT_R13(sp
)
67 LONG_S $
14, PT_R14(sp
)
68 LONG_S $
15, PT_R15(sp
)
69 LONG_S $
24, PT_R24(sp
)
70 #ifndef CONFIG_CPU_HAS_SMARTMIPS
76 LONG_S $
16, PT_R16(sp
)
77 LONG_S $
17, PT_R17(sp
)
78 LONG_S $
18, PT_R18(sp
)
79 LONG_S $
19, PT_R19(sp
)
80 LONG_S $
20, PT_R20(sp
)
81 LONG_S $
21, PT_R21(sp
)
82 LONG_S $
22, PT_R22(sp
)
83 LONG_S $
23, PT_R23(sp
)
84 LONG_S $
30, PT_R30(sp
)
88 #ifdef CONFIG_MIPS_MT_SMTC
89 #define PTEBASE_SHIFT 19 /* TCBIND */
90 #define CPU_ID_REG CP0_TCBIND
91 #define CPU_ID_MFC0 mfc0
92 #elif defined(CONFIG_MIPS_PGD_C0_CONTEXT)
93 #define PTEBASE_SHIFT 48 /* XCONTEXT */
94 #define CPU_ID_REG CP0_XCONTEXT
95 #define CPU_ID_MFC0 MFC0
97 #define PTEBASE_SHIFT 23 /* CONTEXT */
98 #define CPU_ID_REG CP0_CONTEXT
99 #define CPU_ID_MFC0 MFC0
101 .macro get_saved_sp
/* SMP variation */
102 CPU_ID_MFC0 k0
, CPU_ID_REG
103 #if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32)
104 lui k1
, %hi(kernelsp
)
106 lui k1
, %highest(kernelsp
)
107 daddiu k1
, %higher(kernelsp
)
109 daddiu k1
, %hi(kernelsp
)
112 LONG_SRL k0
, PTEBASE_SHIFT
114 LONG_L k1
, %lo(kernelsp
)(k1
)
117 .macro set_saved_sp stackp temp temp2
118 CPU_ID_MFC0
\temp
, CPU_ID_REG
119 LONG_SRL
\temp
, PTEBASE_SHIFT
120 LONG_S \stackp
, kernelsp(\temp
)
123 .macro get_saved_sp
/* Uniprocessor variation */
124 #ifdef CONFIG_CPU_JUMP_WORKAROUNDS
137 #endif /* CONFIG_CPU_JUMP_WORKAROUNDS */
138 #if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32)
139 lui k1
, %hi(kernelsp
)
141 lui k1
, %highest(kernelsp
)
142 daddiu k1
, %higher(kernelsp
)
144 daddiu k1
, %hi(kernelsp
)
147 LONG_L k1
, %lo(kernelsp
)(k1
)
150 .macro set_saved_sp stackp temp temp2
151 LONG_S \stackp
, kernelsp
160 sll k0
, 3 /* extract cu0 bit */
165 /* Called from user mode, new stack. */
167 #ifndef CONFIG_CPU_DADDI_WORKAROUNDS
169 PTR_SUBU sp
, k1
, PT_SIZE
172 8: PTR_SUBU k1
, PT_SIZE
177 LONG_S k0
, PT_R29(sp
)
180 * You might think that you don't need to save $0,
181 * but the FPU emulator and gdb remote debug stub
182 * need it to operate correctly
187 LONG_S v1
, PT_STATUS(sp
)
188 #ifdef CONFIG_MIPS_MT_SMTC
190 * Ideally, these instructions would be shuffled in
191 * to cover the pipeline delay.
194 mfc0 v1
, CP0_TCSTATUS
196 LONG_S v1
, PT_TCSTATUS(sp
)
197 #endif /* CONFIG_MIPS_MT_SMTC */
201 LONG_S v1
, PT_CAUSE(sp
)
209 LONG_S v1
, PT_EPC(sp
)
210 LONG_S $
25, PT_R25(sp
)
211 LONG_S $
28, PT_R28(sp
)
212 LONG_S $
31, PT_R31(sp
)
213 ori $
28, sp
, _THREAD_MASK
214 xori $
28, _THREAD_MASK
215 #ifdef CONFIG_CPU_CAVIUM_OCTEON
217 pref
0, 0($
28) /* Prefetch the current pointer */
218 pref
0, PT_R31(sp
) /* Prefetch the $31(ra) */
219 /* The Octeon multiplier state is affected by general multiply
220 instructions. It must be saved before and kernel code might
223 LONG_L v1
, 0($
28) /* Load the current pointer */
224 /* Restore $31(ra) that was changed by the jal */
225 LONG_L ra
, PT_R31(sp
)
226 pref
0, 0(v1
) /* Prefetch the current thread */
246 #ifdef CONFIG_CPU_HAS_SMARTMIPS
247 LONG_L $
24, PT_ACX(sp
)
249 LONG_L $
24, PT_HI(sp
)
251 LONG_L $
24, PT_LO(sp
)
254 LONG_L $
24, PT_LO(sp
)
256 LONG_L $
24, PT_HI(sp
)
263 LONG_L $
10, PT_R10(sp
)
264 LONG_L $
11, PT_R11(sp
)
265 LONG_L $
12, PT_R12(sp
)
266 LONG_L $
13, PT_R13(sp
)
267 LONG_L $
14, PT_R14(sp
)
268 LONG_L $
15, PT_R15(sp
)
269 LONG_L $
24, PT_R24(sp
)
272 .macro RESTORE_STATIC
273 LONG_L $
16, PT_R16(sp
)
274 LONG_L $
17, PT_R17(sp
)
275 LONG_L $
18, PT_R18(sp
)
276 LONG_L $
19, PT_R19(sp
)
277 LONG_L $
20, PT_R20(sp
)
278 LONG_L $
21, PT_R21(sp
)
279 LONG_L $
22, PT_R22(sp
)
280 LONG_L $
23, PT_R23(sp
)
281 LONG_L $
30, PT_R30(sp
)
284 #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
296 LONG_L v0
, PT_STATUS(sp
)
301 LONG_L $
31, PT_R31(sp
)
302 LONG_L $
28, PT_R28(sp
)
303 LONG_L $
25, PT_R25(sp
)
313 .macro RESTORE_SP_AND_RET
316 LONG_L k0
, PT_EPC(sp
)
317 LONG_L sp
, PT_R29(sp
)
328 #ifdef CONFIG_MIPS_MT_SMTC
331 * We need to make sure the read-modify-write
332 * of Status below isn't perturbed by an interrupt
333 * or cross-TC access, so we need to do at least a DMT,
334 * protected by an interrupt-inhibit. But setting IXMT
335 * also creates a few-cycle window where an IPI could
336 * be queued and not be detected before potentially
337 * returning to a WAIT or user-mode loop. It must be
340 * We're in the middle of a context switch, and
341 * we can't dispatch it directly without trashing
342 * some registers, so we'll try to detect this unlikely
343 * case and program a software interrupt in the VPE,
344 * as would be done for a cross-VPE IPI. To accomodate
345 * the handling of that case, we're doing a DVPE instead
346 * of just a DMT here to protect against other threads.
347 * This is a lot of cruft to cover a tiny window.
348 * If you can find a better design, implement it!
351 mfc0 v0
, CP0_TCSTATUS
352 ori v0
, TCSTATUS_IXMT
353 mtc0 v0
, CP0_TCSTATUS
357 #endif /* CONFIG_MIPS_MT_SMTC */
358 #ifdef CONFIG_CPU_CAVIUM_OCTEON
359 /* Restore the Octeon multiplier state */
360 jal octeon_mult_restore
368 LONG_L v0
, PT_STATUS(sp
)
373 #ifdef CONFIG_MIPS_MT_SMTC
375 * Only after EXL/ERL have been restored to status can we
376 * restore TCStatus.IXMT.
378 LONG_L v1
, PT_TCSTATUS(sp
)
380 mfc0 a0
, CP0_TCSTATUS
381 andi v1
, TCSTATUS_IXMT
385 * We'd like to detect any IPIs queued in the tiny window
386 * above and request an software interrupt to service them
389 * Computing the offset into the IPIQ array of the executing
390 * TC's IPI queue in-line would be tedious. We use part of
391 * the TCContext register to hold 16 bits of offset that we
392 * can add in-line to find the queue head.
394 mfc0 v0
, CP0_TCCONTEXT
401 * If we have a queue, provoke dispatch within the VPE by setting C_SW1
408 * This test should really never branch but
409 * let's be prudent here. Having atomized
410 * the shared register modifications, we can
411 * now EVPE, and must do so before interrupts
412 * are potentially re-enabled.
414 andi a1
, a1
, MVPCONTROL_EVP
418 /* We know that TCStatua.IXMT should be set from above */
419 xori a0
, a0
, TCSTATUS_IXMT
421 mtc0 a0
, CP0_TCSTATUS
425 #endif /* CONFIG_MIPS_MT_SMTC */
426 LONG_L v1
, PT_EPC(sp
)
428 LONG_L $
31, PT_R31(sp
)
429 LONG_L $
28, PT_R28(sp
)
430 LONG_L $
25, PT_R25(sp
)
444 .macro RESTORE_SP_AND_RET
445 LONG_L sp
, PT_R29(sp
)
454 LONG_L sp
, PT_R29(sp
)
465 .macro RESTORE_ALL_AND_RET
474 * Move to kernel mode and disable interrupts.
475 * Set cp0 enable bit as sign that we're running on the kernel stack
478 #if !defined(CONFIG_MIPS_MT_SMTC)
480 li t1
, ST0_CU0
| STATMASK
484 #else /* CONFIG_MIPS_MT_SMTC */
486 * For SMTC, we need to set privilege
487 * and disable interrupts only for the
488 * current TC, using the TCStatus register.
490 mfc0 t0
, CP0_TCSTATUS
491 /* Fortunately CU 0 is in the same place in both registers */
492 /* Set TCU0, TMX, TKSU (for later inversion) and IXMT */
493 li t1
, ST0_CU0
| 0x08001c00
495 /* Clear TKSU, leave IXMT */
497 mtc0 t0
, CP0_TCSTATUS
499 /* We need to leave the global IE bit set, but clear EXL...*/
501 ori t0
, ST0_EXL
| ST0_ERL
502 xori t0
, ST0_EXL
| ST0_ERL
504 #endif /* CONFIG_MIPS_MT_SMTC */
509 * Move to kernel mode and enable interrupts.
510 * Set cp0 enable bit as sign that we're running on the kernel stack
513 #if !defined(CONFIG_MIPS_MT_SMTC)
515 li t1
, ST0_CU0
| STATMASK
517 xori t0
, STATMASK
& ~1
519 #else /* CONFIG_MIPS_MT_SMTC */
521 * For SMTC, we need to set privilege
522 * and enable interrupts only for the
523 * current TC, using the TCStatus register.
526 mfc0 t0
, CP0_TCSTATUS
527 /* Fortunately CU 0 is in the same place in both registers */
528 /* Set TCU0, TKSU (for later inversion) and IXMT */
529 li t1
, ST0_CU0
| 0x08001c00
531 /* Clear TKSU *and* IXMT */
533 mtc0 t0
, CP0_TCSTATUS
535 /* We need to leave the global IE bit set, but clear EXL...*/
540 /* irq_enable_hazard below should expand to EHB for 24K/34K cpus */
541 #endif /* CONFIG_MIPS_MT_SMTC */
546 * Just move to kernel mode and leave interrupts as they are. Note
547 * for the R3000 this means copying the previous enable from IEp.
548 * Set cp0 enable bit as sign that we're running on the kernel stack
551 #ifdef CONFIG_MIPS_MT_SMTC
553 * This gets baroque in SMTC. We want to
554 * protect the non-atomic clearing of EXL
555 * with DMT/EMT, but we don't want to take
556 * an interrupt while DMT is still in effect.
559 /* KMODE gets invoked from both reorder and noreorder code */
563 mfc0 v0
, CP0_TCSTATUS
564 andi v1
, v0
, TCSTATUS_IXMT
565 ori v0
, TCSTATUS_IXMT
566 mtc0 v0
, CP0_TCSTATUS
570 * We don't know a priori if ra is "live"
576 #endif /* CONFIG_MIPS_MT_SMTC */
578 li t1
, ST0_CU0
| (STATMASK
& ~1)
579 #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
585 xori t0
, STATMASK
& ~1
587 #ifdef CONFIG_MIPS_MT_SMTC
589 andi v0
, v0
, VPECONTROL_TE
594 mfc0 v0
, CP0_TCSTATUS
595 /* Clear IXMT, then OR in previous value */
596 ori v0
, TCSTATUS_IXMT
597 xori v0
, TCSTATUS_IXMT
599 mtc0 v0
, CP0_TCSTATUS
601 * irq_disable_hazard below should expand to EHB
605 #endif /* CONFIG_MIPS_MT_SMTC */
609 #endif /* _ASM_STACKFRAME_H */