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.
10 #ifndef _ASM_STACKFRAME_H
11 #define _ASM_STACKFRAME_H
13 #include <linux/threads.h>
16 #include <asm/asmmacro.h>
17 #include <asm/mipsregs.h>
18 #include <asm/asm-offsets.h>
20 #ifdef CONFIG_MIPS_MT_SMTC
21 #include <asm/mipsmtregs.h>
22 #endif /* CONFIG_MIPS_MT_SMTC */
39 LONG_S $
10, PT_R10(sp
)
40 LONG_S $
11, PT_R11(sp
)
42 LONG_S $
12, PT_R12(sp
)
43 LONG_S $
13, PT_R13(sp
)
44 LONG_S $
14, PT_R14(sp
)
45 LONG_S $
15, PT_R15(sp
)
46 LONG_S $
24, PT_R24(sp
)
50 LONG_S $
16, PT_R16(sp
)
51 LONG_S $
17, PT_R17(sp
)
52 LONG_S $
18, PT_R18(sp
)
53 LONG_S $
19, PT_R19(sp
)
54 LONG_S $
20, PT_R20(sp
)
55 LONG_S $
21, PT_R21(sp
)
56 LONG_S $
22, PT_R22(sp
)
57 LONG_S $
23, PT_R23(sp
)
58 LONG_S $
30, PT_R30(sp
)
62 .macro get_saved_sp
/* SMP variation */
64 #ifdef CONFIG_MIPS_MT_SMTC
70 /* No need to shift down and up to clear bits 0-1 */
77 LONG_L k1
, %lo(kernelsp
)(k1
)
80 #ifdef CONFIG_MIPS_MT_SMTC
84 lui k0
, %highest(kernelsp
)
86 /* No need to shift down and up to clear bits 0-2 */
89 lui k0
, %highest(kernelsp
)
91 daddiu k0
, %higher(kernelsp
)
93 daddiu k0
, %hi(kernelsp
)
95 #endif /* CONFIG_MIPS_MT_SMTC */
97 LONG_L k1
, %lo(kernelsp
)(k1
)
98 #endif /* CONFIG_64BIT */
101 .macro set_saved_sp stackp temp temp2
103 #ifdef CONFIG_MIPS_MT_SMTC
104 mfc0
\temp
, CP0_TCBIND
107 mfc0
\temp
, CP0_CONTEXT
112 #ifdef CONFIG_MIPS_MT_SMTC
113 mfc0
\temp
, CP0_TCBIND
116 MFC0
\temp
, CP0_CONTEXT
120 LONG_S \stackp
, kernelsp(\temp
)
123 .macro get_saved_sp
/* Uniprocessor variation */
125 lui k1
, %highest(kernelsp
)
126 daddiu k1
, %higher(kernelsp
)
128 daddiu k1
, %hi(kernelsp
)
131 lui 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. */
154 PTR_SUBU sp
, k1
, PT_SIZE
155 LONG_S k0
, PT_R29(sp
)
158 * You might think that you don't need to save $0,
159 * but the FPU emulator and gdb remote debug stub
160 * need it to operate correctly
165 LONG_S v1
, PT_STATUS(sp
)
166 #ifdef CONFIG_MIPS_MT_SMTC
168 * Ideally, these instructions would be shuffled in
169 * to cover the pipeline delay.
172 mfc0 v1
, CP0_TCSTATUS
174 LONG_S v1
, PT_TCSTATUS(sp
)
175 #endif /* CONFIG_MIPS_MT_SMTC */
179 LONG_S v1
, PT_CAUSE(sp
)
187 LONG_S v1
, PT_EPC(sp
)
188 LONG_S $
25, PT_R25(sp
)
189 LONG_S $
28, PT_R28(sp
)
190 LONG_S $
31, PT_R31(sp
)
191 ori $
28, sp
, _THREAD_MASK
192 xori $
28, _THREAD_MASK
211 LONG_L $
24, PT_LO(sp
)
217 LONG_L $
24, PT_HI(sp
)
218 LONG_L $
10, PT_R10(sp
)
219 LONG_L $
11, PT_R11(sp
)
221 LONG_L $
12, PT_R12(sp
)
222 LONG_L $
13, PT_R13(sp
)
223 LONG_L $
14, PT_R14(sp
)
224 LONG_L $
15, PT_R15(sp
)
225 LONG_L $
24, PT_R24(sp
)
228 .macro RESTORE_STATIC
229 LONG_L $
16, PT_R16(sp
)
230 LONG_L $
17, PT_R17(sp
)
231 LONG_L $
18, PT_R18(sp
)
232 LONG_L $
19, PT_R19(sp
)
233 LONG_L $
20, PT_R20(sp
)
234 LONG_L $
21, PT_R21(sp
)
235 LONG_L $
22, PT_R22(sp
)
236 LONG_L $
23, PT_R23(sp
)
237 LONG_L $
30, PT_R30(sp
)
240 #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
252 LONG_L v0
, PT_STATUS(sp
)
257 LONG_L $
31, PT_R31(sp
)
258 LONG_L $
28, PT_R28(sp
)
259 LONG_L $
25, PT_R25(sp
)
273 .macro RESTORE_SP_AND_RET
276 LONG_L k0
, PT_EPC(sp
)
277 LONG_L sp
, PT_R29(sp
)
285 * For SMTC kernel, global IE should be left set, and interrupts
286 * controlled exclusively via IXMT.
289 #ifdef CONFIG_MIPS_MT_SMTC
290 #define STATMASK 0x1e
292 #define STATMASK 0x1f
298 #ifdef CONFIG_MIPS_MT_SMTC
301 * This may not really be necessary if ints are already
304 mfc0 v0
, CP0_TCSTATUS
305 ori v0
, TCSTATUS_IXMT
306 mtc0 v0
, CP0_TCSTATUS
310 #endif /* CONFIG_MIPS_MT_SMTC */
317 LONG_L v0
, PT_STATUS(sp
)
322 #ifdef CONFIG_MIPS_MT_SMTC
324 * Only after EXL/ERL have been restored to status can we
325 * restore TCStatus.IXMT.
327 LONG_L v1
, PT_TCSTATUS(sp
)
329 mfc0 v0
, CP0_TCSTATUS
330 andi v1
, TCSTATUS_IXMT
331 /* We know that TCStatua.IXMT should be set from above */
332 xori v0
, v0
, TCSTATUS_IXMT
334 mtc0 v0
, CP0_TCSTATUS
336 andi a1
, a1
, VPECONTROL_TE
341 #endif /* CONFIG_MIPS_MT_SMTC */
342 LONG_L v1
, PT_EPC(sp
)
344 LONG_L $
31, PT_R31(sp
)
345 LONG_L $
28, PT_R28(sp
)
346 LONG_L $
25, PT_R25(sp
)
360 .macro RESTORE_SP_AND_RET
361 LONG_L sp
, PT_R29(sp
)
370 LONG_L sp
, PT_R29(sp
)
381 .macro RESTORE_ALL_AND_RET
390 * Move to kernel mode and disable interrupts.
391 * Set cp0 enable bit as sign that we're running on the kernel stack
394 #if !defined(CONFIG_MIPS_MT_SMTC)
396 li t1
, ST0_CU0
| 0x1f
400 #else /* CONFIG_MIPS_MT_SMTC */
402 * For SMTC, we need to set privilege
403 * and disable interrupts only for the
404 * current TC, using the TCStatus register.
407 /* Fortunately CU 0 is in the same place in both registers */
408 /* Set TCU0, TMX, TKSU (for later inversion) and IXMT */
409 li t1
, ST0_CU0
| 0x08001c00
411 /* Clear TKSU, leave IXMT */
413 mtc0 t0
, CP0_TCSTATUS
415 /* We need to leave the global IE bit set, but clear EXL...*/
417 ori t0
, ST0_EXL
| ST0_ERL
418 xori t0
, ST0_EXL
| ST0_ERL
420 #endif /* CONFIG_MIPS_MT_SMTC */
425 * Move to kernel mode and enable interrupts.
426 * Set cp0 enable bit as sign that we're running on the kernel stack
429 #if !defined(CONFIG_MIPS_MT_SMTC)
431 li t1
, ST0_CU0
| 0x1f
435 #else /* CONFIG_MIPS_MT_SMTC */
437 * For SMTC, we need to set privilege
438 * and enable interrupts only for the
439 * current TC, using the TCStatus register.
443 /* Fortunately CU 0 is in the same place in both registers */
444 /* Set TCU0, TKSU (for later inversion) and IXMT */
445 li t1
, ST0_CU0
| 0x08001c00
447 /* Clear TKSU *and* IXMT */
449 mtc0 t0
, CP0_TCSTATUS
451 /* We need to leave the global IE bit set, but clear EXL...*/
456 /* irq_enable_hazard below should expand to EHB for 24K/34K cpus */
457 #endif /* CONFIG_MIPS_MT_SMTC */
462 * Just move to kernel mode and leave interrupts as they are.
463 * Set cp0 enable bit as sign that we're running on the kernel stack
466 #ifdef CONFIG_MIPS_MT_SMTC
468 * This gets baroque in SMTC. We want to
469 * protect the non-atomic clearing of EXL
470 * with DMT/EMT, but we don't want to take
471 * an interrupt while DMT is still in effect.
474 /* KMODE gets invoked from both reorder and noreorder code */
478 mfc0 v0
, CP0_TCSTATUS
479 andi v1
, v0
, TCSTATUS_IXMT
480 ori v0
, TCSTATUS_IXMT
481 mtc0 v0
, CP0_TCSTATUS
485 * We don't know a priori if ra is "live"
491 #endif /* CONFIG_MIPS_MT_SMTC */
493 li t1
, ST0_CU0
| 0x1e
497 #ifdef CONFIG_MIPS_MT_SMTC
499 andi v0
, v0
, VPECONTROL_TE
504 mfc0 v0
, CP0_TCSTATUS
505 /* Clear IXMT, then OR in previous value */
506 ori v0
, TCSTATUS_IXMT
507 xori v0
, TCSTATUS_IXMT
509 mtc0 v0
, CP0_TCSTATUS
511 * irq_disable_hazard below should expand to EHB
515 #endif /* CONFIG_MIPS_MT_SMTC */
519 #endif /* _ASM_STACKFRAME_H */