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
62 LONG_S $
10, PT_R10(sp
)
63 LONG_S $
11, PT_R11(sp
)
64 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
)
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
)
84 #ifdef CONFIG_MIPS_MT_SMTC
85 #define PTEBASE_SHIFT 19 /* TCBIND */
87 #define PTEBASE_SHIFT 23 /* CONTEXT */
89 .macro get_saved_sp
/* SMP variation */
90 #ifdef CONFIG_MIPS_MT_SMTC
95 #if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32)
98 lui k1
, %highest(kernelsp
)
99 daddiu k1
, %higher(kernelsp
)
101 daddiu k1
, %hi(kernelsp
)
104 LONG_SRL k0
, PTEBASE_SHIFT
106 LONG_L k1
, %lo(kernelsp
)(k1
)
109 .macro set_saved_sp stackp temp temp2
110 #ifdef CONFIG_MIPS_MT_SMTC
111 mfc0
\temp
, CP0_TCBIND
113 MFC0
\temp
, CP0_CONTEXT
115 LONG_SRL
\temp
, PTEBASE_SHIFT
116 LONG_S \stackp
, kernelsp(\temp
)
119 .macro get_saved_sp
/* Uniprocessor variation */
120 #if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32)
121 lui k1
, %hi(kernelsp
)
123 lui k1
, %highest(kernelsp
)
124 daddiu k1
, %higher(kernelsp
)
126 daddiu k1
, %hi(kernelsp
)
129 LONG_L k1
, %lo(kernelsp
)(k1
)
132 .macro set_saved_sp stackp temp temp2
133 LONG_S \stackp
, kernelsp
142 sll k0
, 3 /* extract cu0 bit */
147 /* Called from user mode, new stack. */
149 #ifndef CONFIG_CPU_DADDI_WORKAROUNDS
151 PTR_SUBU sp
, k1
, PT_SIZE
154 8: PTR_SUBU k1
, PT_SIZE
159 LONG_S k0
, PT_R29(sp
)
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
169 LONG_S v1
, PT_STATUS(sp
)
170 #ifdef CONFIG_MIPS_MT_SMTC
172 * Ideally, these instructions would be shuffled in
173 * to cover the pipeline delay.
176 mfc0 v1
, CP0_TCSTATUS
178 LONG_S v1
, PT_TCSTATUS(sp
)
179 #endif /* CONFIG_MIPS_MT_SMTC */
183 LONG_S v1
, PT_CAUSE(sp
)
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
215 #ifdef CONFIG_CPU_HAS_SMARTMIPS
216 LONG_L $
24, PT_ACX(sp
)
218 LONG_L $
24, PT_HI(sp
)
220 LONG_L $
24, PT_LO(sp
)
223 LONG_L $
24, PT_LO(sp
)
225 LONG_L $
24, PT_HI(sp
)
232 LONG_L $
10, PT_R10(sp
)
233 LONG_L $
11, PT_R11(sp
)
234 LONG_L $
12, PT_R12(sp
)
235 LONG_L $
13, PT_R13(sp
)
236 LONG_L $
14, PT_R14(sp
)
237 LONG_L $
15, PT_R15(sp
)
238 LONG_L $
24, PT_R24(sp
)
241 .macro RESTORE_STATIC
242 LONG_L $
16, PT_R16(sp
)
243 LONG_L $
17, PT_R17(sp
)
244 LONG_L $
18, PT_R18(sp
)
245 LONG_L $
19, PT_R19(sp
)
246 LONG_L $
20, PT_R20(sp
)
247 LONG_L $
21, PT_R21(sp
)
248 LONG_L $
22, PT_R22(sp
)
249 LONG_L $
23, PT_R23(sp
)
250 LONG_L $
30, PT_R30(sp
)
253 #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
265 LONG_L v0
, PT_STATUS(sp
)
270 LONG_L $
31, PT_R31(sp
)
271 LONG_L $
28, PT_R28(sp
)
272 LONG_L $
25, PT_R25(sp
)
282 .macro RESTORE_SP_AND_RET
285 LONG_L k0
, PT_EPC(sp
)
286 LONG_L sp
, PT_R29(sp
)
297 #ifdef CONFIG_MIPS_MT_SMTC
300 * This may not really be necessary if ints are already
303 mfc0 v0
, CP0_TCSTATUS
304 ori v0
, TCSTATUS_IXMT
305 mtc0 v0
, CP0_TCSTATUS
309 #endif /* CONFIG_MIPS_MT_SMTC */
316 LONG_L v0
, PT_STATUS(sp
)
321 #ifdef CONFIG_MIPS_MT_SMTC
323 * Only after EXL/ERL have been restored to status can we
324 * restore TCStatus.IXMT.
326 LONG_L v1
, PT_TCSTATUS(sp
)
328 mfc0 v0
, CP0_TCSTATUS
329 andi v1
, TCSTATUS_IXMT
330 /* We know that TCStatua.IXMT should be set from above */
331 xori v0
, v0
, TCSTATUS_IXMT
333 mtc0 v0
, CP0_TCSTATUS
335 andi a1
, a1
, VPECONTROL_TE
340 #endif /* CONFIG_MIPS_MT_SMTC */
341 LONG_L v1
, PT_EPC(sp
)
343 LONG_L $
31, PT_R31(sp
)
344 LONG_L $
28, PT_R28(sp
)
345 LONG_L $
25, PT_R25(sp
)
359 .macro RESTORE_SP_AND_RET
360 LONG_L sp
, PT_R29(sp
)
369 LONG_L sp
, PT_R29(sp
)
380 .macro RESTORE_ALL_AND_RET
389 * Move to kernel mode and disable interrupts.
390 * Set cp0 enable bit as sign that we're running on the kernel stack
393 #if !defined(CONFIG_MIPS_MT_SMTC)
395 li t1
, ST0_CU0
| STATMASK
399 #else /* CONFIG_MIPS_MT_SMTC */
401 * For SMTC, we need to set privilege
402 * and disable interrupts only for the
403 * current TC, using the TCStatus register.
405 mfc0 t0
, CP0_TCSTATUS
406 /* Fortunately CU 0 is in the same place in both registers */
407 /* Set TCU0, TMX, TKSU (for later inversion) and IXMT */
408 li t1
, ST0_CU0
| 0x08001c00
410 /* Clear TKSU, leave IXMT */
412 mtc0 t0
, CP0_TCSTATUS
414 /* We need to leave the global IE bit set, but clear EXL...*/
416 ori t0
, ST0_EXL
| ST0_ERL
417 xori t0
, ST0_EXL
| ST0_ERL
419 #endif /* CONFIG_MIPS_MT_SMTC */
424 * Move to kernel mode and enable interrupts.
425 * Set cp0 enable bit as sign that we're running on the kernel stack
428 #if !defined(CONFIG_MIPS_MT_SMTC)
430 li t1
, ST0_CU0
| STATMASK
432 xori t0
, STATMASK
& ~1
434 #else /* CONFIG_MIPS_MT_SMTC */
436 * For SMTC, we need to set privilege
437 * and enable interrupts only for the
438 * current TC, using the TCStatus register.
441 mfc0 t0
, CP0_TCSTATUS
442 /* Fortunately CU 0 is in the same place in both registers */
443 /* Set TCU0, TKSU (for later inversion) and IXMT */
444 li t1
, ST0_CU0
| 0x08001c00
446 /* Clear TKSU *and* IXMT */
448 mtc0 t0
, CP0_TCSTATUS
450 /* We need to leave the global IE bit set, but clear EXL...*/
455 /* irq_enable_hazard below should expand to EHB for 24K/34K cpus */
456 #endif /* CONFIG_MIPS_MT_SMTC */
461 * Just move to kernel mode and leave interrupts as they are. Note
462 * for the R3000 this means copying the previous enable from IEp.
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
| (STATMASK
& ~1)
494 #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
500 xori t0
, STATMASK
& ~1
502 #ifdef CONFIG_MIPS_MT_SMTC
504 andi v0
, v0
, VPECONTROL_TE
509 mfc0 v0
, CP0_TCSTATUS
510 /* Clear IXMT, then OR in previous value */
511 ori v0
, TCSTATUS_IXMT
512 xori v0
, TCSTATUS_IXMT
514 mtc0 v0
, CP0_TCSTATUS
516 * irq_disable_hazard below should expand to EHB
520 #endif /* CONFIG_MIPS_MT_SMTC */
524 #endif /* _ASM_STACKFRAME_H */