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 */
91 #define PTEBASE_SHIFT 23 /* CONTEXT */
93 .macro get_saved_sp
/* SMP variation */
94 #ifdef CONFIG_MIPS_MT_SMTC
99 #if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32)
100 lui k1
, %hi(kernelsp
)
102 lui k1
, %highest(kernelsp
)
103 daddiu k1
, %higher(kernelsp
)
105 daddiu k1
, %hi(kernelsp
)
108 LONG_SRL k0
, PTEBASE_SHIFT
110 LONG_L k1
, %lo(kernelsp
)(k1
)
113 .macro set_saved_sp stackp temp temp2
114 #ifdef CONFIG_MIPS_MT_SMTC
115 mfc0
\temp
, CP0_TCBIND
117 MFC0
\temp
, CP0_CONTEXT
119 LONG_SRL
\temp
, PTEBASE_SHIFT
120 LONG_S \stackp
, kernelsp(\temp
)
123 .macro get_saved_sp
/* Uniprocessor variation */
124 #if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32)
125 lui k1
, %hi(kernelsp
)
127 lui k1
, %highest(kernelsp
)
128 daddiu k1
, %higher(kernelsp
)
130 daddiu k1
, %hi(kernelsp
)
133 LONG_L k1
, %lo(kernelsp
)(k1
)
136 .macro set_saved_sp stackp temp temp2
137 LONG_S \stackp
, kernelsp
146 sll k0
, 3 /* extract cu0 bit */
151 /* Called from user mode, new stack. */
153 #ifndef CONFIG_CPU_DADDI_WORKAROUNDS
155 PTR_SUBU sp
, k1
, PT_SIZE
158 8: PTR_SUBU k1
, PT_SIZE
163 LONG_S k0
, PT_R29(sp
)
166 * You might think that you don't need to save $0,
167 * but the FPU emulator and gdb remote debug stub
168 * need it to operate correctly
173 #ifdef CONFIG_MIPS_MT_SMTC
175 * Ideally, these instructions would be shuffled in
176 * to cover the pipeline delay.
179 mfc0 v1
, CP0_TCSTATUS
181 LONG_S v1
, PT_TCSTATUS(sp
)
182 #endif /* CONFIG_MIPS_MT_SMTC */
185 LONG_S v1
, PT_STATUS(sp
)
189 LONG_S v1
, PT_CAUSE(sp
)
195 LONG_S $
25, PT_R25(sp
)
196 LONG_S $
28, PT_R28(sp
)
197 LONG_S $
31, PT_R31(sp
)
198 LONG_S v1
, PT_EPC(sp
)
199 ori $
28, sp
, _THREAD_MASK
200 xori $
28, _THREAD_MASK
201 #ifdef CONFIG_CPU_CAVIUM_OCTEON
203 pref
0, 0($
28) /* Prefetch the current pointer */
204 pref
0, PT_R31(sp
) /* Prefetch the $31(ra) */
205 /* The Octeon multiplier state is affected by general multiply
206 instructions. It must be saved before and kernel code might
209 LONG_L v1
, 0($
28) /* Load the current pointer */
210 /* Restore $31(ra) that was changed by the jal */
211 LONG_L ra
, PT_R31(sp
)
212 pref
0, 0(v1
) /* Prefetch the current thread */
232 #ifdef CONFIG_CPU_HAS_SMARTMIPS
233 LONG_L $
24, PT_ACX(sp
)
235 LONG_L $
24, PT_HI(sp
)
237 LONG_L $
24, PT_LO(sp
)
240 LONG_L $
24, PT_LO(sp
)
242 LONG_L $
24, PT_HI(sp
)
249 LONG_L $
10, PT_R10(sp
)
250 LONG_L $
11, PT_R11(sp
)
251 LONG_L $
12, PT_R12(sp
)
252 LONG_L $
13, PT_R13(sp
)
253 LONG_L $
14, PT_R14(sp
)
254 LONG_L $
15, PT_R15(sp
)
255 LONG_L $
24, PT_R24(sp
)
258 .macro RESTORE_STATIC
259 LONG_L $
16, PT_R16(sp
)
260 LONG_L $
17, PT_R17(sp
)
261 LONG_L $
18, PT_R18(sp
)
262 LONG_L $
19, PT_R19(sp
)
263 LONG_L $
20, PT_R20(sp
)
264 LONG_L $
21, PT_R21(sp
)
265 LONG_L $
22, PT_R22(sp
)
266 LONG_L $
23, PT_R23(sp
)
267 LONG_L $
30, PT_R30(sp
)
270 #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
282 LONG_L v0
, PT_STATUS(sp
)
287 LONG_L $
31, PT_R31(sp
)
288 LONG_L $
28, PT_R28(sp
)
289 LONG_L $
25, PT_R25(sp
)
299 .macro RESTORE_SP_AND_RET
302 LONG_L k0
, PT_EPC(sp
)
303 LONG_L sp
, PT_R29(sp
)
314 #ifdef CONFIG_MIPS_MT_SMTC
317 * We need to make sure the read-modify-write
318 * of Status below isn't perturbed by an interrupt
319 * or cross-TC access, so we need to do at least a DMT,
320 * protected by an interrupt-inhibit. But setting IXMT
321 * also creates a few-cycle window where an IPI could
322 * be queued and not be detected before potentially
323 * returning to a WAIT or user-mode loop. It must be
326 * We're in the middle of a context switch, and
327 * we can't dispatch it directly without trashing
328 * some registers, so we'll try to detect this unlikely
329 * case and program a software interrupt in the VPE,
330 * as would be done for a cross-VPE IPI. To accomodate
331 * the handling of that case, we're doing a DVPE instead
332 * of just a DMT here to protect against other threads.
333 * This is a lot of cruft to cover a tiny window.
334 * If you can find a better design, implement it!
337 mfc0 v0
, CP0_TCSTATUS
338 ori v0
, TCSTATUS_IXMT
339 mtc0 v0
, CP0_TCSTATUS
343 #endif /* CONFIG_MIPS_MT_SMTC */
344 #ifdef CONFIG_CPU_CAVIUM_OCTEON
345 /* Restore the Octeon multiplier state */
346 jal octeon_mult_restore
354 LONG_L v0
, PT_STATUS(sp
)
359 #ifdef CONFIG_MIPS_MT_SMTC
361 * Only after EXL/ERL have been restored to status can we
362 * restore TCStatus.IXMT.
364 LONG_L v1
, PT_TCSTATUS(sp
)
366 mfc0 a0
, CP0_TCSTATUS
367 andi v1
, TCSTATUS_IXMT
371 * We'd like to detect any IPIs queued in the tiny window
372 * above and request an software interrupt to service them
375 * Computing the offset into the IPIQ array of the executing
376 * TC's IPI queue in-line would be tedious. We use part of
377 * the TCContext register to hold 16 bits of offset that we
378 * can add in-line to find the queue head.
380 mfc0 v0
, CP0_TCCONTEXT
387 * If we have a queue, provoke dispatch within the VPE by setting C_SW1
394 * This test should really never branch but
395 * let's be prudent here. Having atomized
396 * the shared register modifications, we can
397 * now EVPE, and must do so before interrupts
398 * are potentially re-enabled.
400 andi a1
, a1
, MVPCONTROL_EVP
404 /* We know that TCStatua.IXMT should be set from above */
405 xori a0
, a0
, TCSTATUS_IXMT
407 mtc0 a0
, CP0_TCSTATUS
411 #endif /* CONFIG_MIPS_MT_SMTC */
412 LONG_L v1
, PT_EPC(sp
)
414 LONG_L $
31, PT_R31(sp
)
415 LONG_L $
28, PT_R28(sp
)
416 LONG_L $
25, PT_R25(sp
)
430 .macro RESTORE_SP_AND_RET
431 LONG_L sp
, PT_R29(sp
)
440 LONG_L sp
, PT_R29(sp
)
451 .macro RESTORE_ALL_AND_RET
460 * Move to kernel mode and disable interrupts.
461 * Set cp0 enable bit as sign that we're running on the kernel stack
464 #if !defined(CONFIG_MIPS_MT_SMTC)
466 li t1
, ST0_CU0
| STATMASK
470 #else /* CONFIG_MIPS_MT_SMTC */
472 * For SMTC, we need to set privilege
473 * and disable interrupts only for the
474 * current TC, using the TCStatus register.
476 mfc0 t0
, CP0_TCSTATUS
477 /* Fortunately CU 0 is in the same place in both registers */
478 /* Set TCU0, TMX, TKSU (for later inversion) and IXMT */
479 li t1
, ST0_CU0
| 0x08001c00
481 /* Clear TKSU, leave IXMT */
483 mtc0 t0
, CP0_TCSTATUS
485 /* We need to leave the global IE bit set, but clear EXL...*/
487 ori t0
, ST0_EXL
| ST0_ERL
488 xori t0
, ST0_EXL
| ST0_ERL
490 #endif /* CONFIG_MIPS_MT_SMTC */
495 * Move to kernel mode and enable interrupts.
496 * Set cp0 enable bit as sign that we're running on the kernel stack
499 #if !defined(CONFIG_MIPS_MT_SMTC)
501 li t1
, ST0_CU0
| STATMASK
503 xori t0
, STATMASK
& ~1
505 #else /* CONFIG_MIPS_MT_SMTC */
507 * For SMTC, we need to set privilege
508 * and enable interrupts only for the
509 * current TC, using the TCStatus register.
512 mfc0 t0
, CP0_TCSTATUS
513 /* Fortunately CU 0 is in the same place in both registers */
514 /* Set TCU0, TKSU (for later inversion) and IXMT */
515 li t1
, ST0_CU0
| 0x08001c00
517 /* Clear TKSU *and* IXMT */
519 mtc0 t0
, CP0_TCSTATUS
521 /* We need to leave the global IE bit set, but clear EXL...*/
526 /* irq_enable_hazard below should expand to EHB for 24K/34K cpus */
527 #endif /* CONFIG_MIPS_MT_SMTC */
532 * Just move to kernel mode and leave interrupts as they are. Note
533 * for the R3000 this means copying the previous enable from IEp.
534 * Set cp0 enable bit as sign that we're running on the kernel stack
537 #ifdef CONFIG_MIPS_MT_SMTC
539 * This gets baroque in SMTC. We want to
540 * protect the non-atomic clearing of EXL
541 * with DMT/EMT, but we don't want to take
542 * an interrupt while DMT is still in effect.
545 /* KMODE gets invoked from both reorder and noreorder code */
549 mfc0 v0
, CP0_TCSTATUS
550 andi v1
, v0
, TCSTATUS_IXMT
551 ori v0
, TCSTATUS_IXMT
552 mtc0 v0
, CP0_TCSTATUS
556 * We don't know a priori if ra is "live"
562 #endif /* CONFIG_MIPS_MT_SMTC */
564 li t1
, ST0_CU0
| (STATMASK
& ~1)
565 #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
571 xori t0
, STATMASK
& ~1
573 #ifdef CONFIG_MIPS_MT_SMTC
575 andi v0
, v0
, VPECONTROL_TE
580 mfc0 v0
, CP0_TCSTATUS
581 /* Clear IXMT, then OR in previous value */
582 ori v0
, TCSTATUS_IXMT
583 xori v0
, TCSTATUS_IXMT
585 mtc0 v0
, CP0_TCSTATUS
587 * irq_disable_hazard below should expand to EHB
591 #endif /* CONFIG_MIPS_MT_SMTC */
595 #endif /* _ASM_STACKFRAME_H */