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>
21 * For SMTC kernel, global IE should be left set, and interrupts
22 * controlled exclusively via IXMT.
24 #ifdef CONFIG_MIPS_MT_SMTC
26 #elif defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
32 #ifdef CONFIG_MIPS_MT_SMTC
33 #include <asm/mipsmtregs.h>
34 #endif /* CONFIG_MIPS_MT_SMTC */
44 #ifdef CONFIG_CPU_HAS_SMARTMIPS
61 LONG_S $
10, PT_R10(sp
)
62 LONG_S $
11, PT_R11(sp
)
63 LONG_S $
12, PT_R12(sp
)
64 LONG_S $
13, PT_R13(sp
)
65 LONG_S $
14, PT_R14(sp
)
66 LONG_S $
15, PT_R15(sp
)
67 LONG_S $
24, PT_R24(sp
)
71 LONG_S $
16, PT_R16(sp
)
72 LONG_S $
17, PT_R17(sp
)
73 LONG_S $
18, PT_R18(sp
)
74 LONG_S $
19, PT_R19(sp
)
75 LONG_S $
20, PT_R20(sp
)
76 LONG_S $
21, PT_R21(sp
)
77 LONG_S $
22, PT_R22(sp
)
78 LONG_S $
23, PT_R23(sp
)
79 LONG_S $
30, PT_R30(sp
)
83 #ifdef CONFIG_MIPS_MT_SMTC
84 #define PTEBASE_SHIFT 19 /* TCBIND */
86 #define PTEBASE_SHIFT 23 /* CONTEXT */
88 .macro get_saved_sp
/* SMP variation */
89 #ifdef CONFIG_MIPS_MT_SMTC
94 #if defined(CONFIG_BUILD_ELF64) || (defined(CONFIG_64BIT) && __GNUC__ < 4)
95 lui k1
, %highest(kernelsp
)
96 daddiu k1
, %higher(kernelsp
)
98 daddiu k1
, %hi(kernelsp
)
101 lui k1
, %hi(kernelsp
)
103 LONG_SRL k0
, PTEBASE_SHIFT
105 LONG_L k1
, %lo(kernelsp
)(k1
)
108 .macro set_saved_sp stackp temp temp2
109 #ifdef CONFIG_MIPS_MT_SMTC
110 mfc0
\temp
, CP0_TCBIND
112 MFC0
\temp
, CP0_CONTEXT
114 LONG_SRL
\temp
, PTEBASE_SHIFT
115 LONG_S \stackp
, kernelsp(\temp
)
118 .macro get_saved_sp
/* Uniprocessor variation */
119 #if defined(CONFIG_BUILD_ELF64) || (defined(CONFIG_64BIT) && __GNUC__ < 4)
120 lui k1
, %highest(kernelsp
)
121 daddiu k1
, %higher(kernelsp
)
123 daddiu k1
, %hi(kernelsp
)
126 lui k1
, %hi(kernelsp
)
128 LONG_L k1
, %lo(kernelsp
)(k1
)
131 .macro set_saved_sp stackp temp temp2
132 LONG_S \stackp
, kernelsp
141 sll k0
, 3 /* extract cu0 bit */
146 /* Called from user mode, new stack. */
149 PTR_SUBU sp
, k1
, PT_SIZE
150 LONG_S k0
, PT_R29(sp
)
153 * You might think that you don't need to save $0,
154 * but the FPU emulator and gdb remote debug stub
155 * need it to operate correctly
160 LONG_S v1
, PT_STATUS(sp
)
161 #ifdef CONFIG_MIPS_MT_SMTC
163 * Ideally, these instructions would be shuffled in
164 * to cover the pipeline delay.
167 mfc0 v1
, CP0_TCSTATUS
169 LONG_S v1
, PT_TCSTATUS(sp
)
170 #endif /* CONFIG_MIPS_MT_SMTC */
174 LONG_S v1
, PT_CAUSE(sp
)
182 LONG_S v1
, PT_EPC(sp
)
183 LONG_S $
25, PT_R25(sp
)
184 LONG_S $
28, PT_R28(sp
)
185 LONG_S $
31, PT_R31(sp
)
186 ori $
28, sp
, _THREAD_MASK
187 xori $
28, _THREAD_MASK
206 #ifdef CONFIG_CPU_HAS_SMARTMIPS
207 LONG_L $
24, PT_ACX(sp
)
209 LONG_L $
24, PT_HI(sp
)
211 LONG_L $
24, PT_LO(sp
)
214 LONG_L $
24, PT_LO(sp
)
216 LONG_L $
24, PT_HI(sp
)
223 LONG_L $
10, PT_R10(sp
)
224 LONG_L $
11, PT_R11(sp
)
225 LONG_L $
12, PT_R12(sp
)
226 LONG_L $
13, PT_R13(sp
)
227 LONG_L $
14, PT_R14(sp
)
228 LONG_L $
15, PT_R15(sp
)
229 LONG_L $
24, PT_R24(sp
)
232 .macro RESTORE_STATIC
233 LONG_L $
16, PT_R16(sp
)
234 LONG_L $
17, PT_R17(sp
)
235 LONG_L $
18, PT_R18(sp
)
236 LONG_L $
19, PT_R19(sp
)
237 LONG_L $
20, PT_R20(sp
)
238 LONG_L $
21, PT_R21(sp
)
239 LONG_L $
22, PT_R22(sp
)
240 LONG_L $
23, PT_R23(sp
)
241 LONG_L $
30, PT_R30(sp
)
244 #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
256 LONG_L v0
, PT_STATUS(sp
)
261 LONG_L $
31, PT_R31(sp
)
262 LONG_L $
28, PT_R28(sp
)
263 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
)
288 #ifdef CONFIG_MIPS_MT_SMTC
291 * This may not really be necessary if ints are already
294 mfc0 v0
, CP0_TCSTATUS
295 ori v0
, TCSTATUS_IXMT
296 mtc0 v0
, CP0_TCSTATUS
300 #endif /* CONFIG_MIPS_MT_SMTC */
307 LONG_L v0
, PT_STATUS(sp
)
312 #ifdef CONFIG_MIPS_MT_SMTC
314 * Only after EXL/ERL have been restored to status can we
315 * restore TCStatus.IXMT.
317 LONG_L v1
, PT_TCSTATUS(sp
)
319 mfc0 v0
, CP0_TCSTATUS
320 andi v1
, TCSTATUS_IXMT
321 /* We know that TCStatua.IXMT should be set from above */
322 xori v0
, v0
, TCSTATUS_IXMT
324 mtc0 v0
, CP0_TCSTATUS
326 andi a1
, a1
, VPECONTROL_TE
331 #endif /* CONFIG_MIPS_MT_SMTC */
332 LONG_L v1
, PT_EPC(sp
)
334 LONG_L $
31, PT_R31(sp
)
335 LONG_L $
28, PT_R28(sp
)
336 LONG_L $
25, PT_R25(sp
)
350 .macro RESTORE_SP_AND_RET
351 LONG_L sp
, PT_R29(sp
)
360 LONG_L sp
, PT_R29(sp
)
371 .macro RESTORE_ALL_AND_RET
380 * Move to kernel mode and disable interrupts.
381 * Set cp0 enable bit as sign that we're running on the kernel stack
384 #if !defined(CONFIG_MIPS_MT_SMTC)
386 li t1
, ST0_CU0
| STATMASK
390 #else /* CONFIG_MIPS_MT_SMTC */
392 * For SMTC, we need to set privilege
393 * and disable interrupts only for the
394 * current TC, using the TCStatus register.
397 /* Fortunately CU 0 is in the same place in both registers */
398 /* Set TCU0, TMX, TKSU (for later inversion) and IXMT */
399 li t1
, ST0_CU0
| 0x08001c00
401 /* Clear TKSU, leave IXMT */
403 mtc0 t0
, CP0_TCSTATUS
405 /* We need to leave the global IE bit set, but clear EXL...*/
407 ori t0
, ST0_EXL
| ST0_ERL
408 xori t0
, ST0_EXL
| ST0_ERL
410 #endif /* CONFIG_MIPS_MT_SMTC */
415 * Move to kernel mode and enable interrupts.
416 * Set cp0 enable bit as sign that we're running on the kernel stack
419 #if !defined(CONFIG_MIPS_MT_SMTC)
421 li t1
, ST0_CU0
| STATMASK
423 xori t0
, STATMASK
& ~1
425 #else /* CONFIG_MIPS_MT_SMTC */
427 * For SMTC, we need to set privilege
428 * and enable interrupts only for the
429 * current TC, using the TCStatus register.
433 /* Fortunately CU 0 is in the same place in both registers */
434 /* Set TCU0, TKSU (for later inversion) and IXMT */
435 li t1
, ST0_CU0
| 0x08001c00
437 /* Clear TKSU *and* IXMT */
439 mtc0 t0
, CP0_TCSTATUS
441 /* We need to leave the global IE bit set, but clear EXL...*/
446 /* irq_enable_hazard below should expand to EHB for 24K/34K cpus */
447 #endif /* CONFIG_MIPS_MT_SMTC */
452 * Just move to kernel mode and leave interrupts as they are. Note
453 * for the R3000 this means copying the previous enable from IEp.
454 * Set cp0 enable bit as sign that we're running on the kernel stack
457 #ifdef CONFIG_MIPS_MT_SMTC
459 * This gets baroque in SMTC. We want to
460 * protect the non-atomic clearing of EXL
461 * with DMT/EMT, but we don't want to take
462 * an interrupt while DMT is still in effect.
465 /* KMODE gets invoked from both reorder and noreorder code */
469 mfc0 v0
, CP0_TCSTATUS
470 andi v1
, v0
, TCSTATUS_IXMT
471 ori v0
, TCSTATUS_IXMT
472 mtc0 v0
, CP0_TCSTATUS
476 * We don't know a priori if ra is "live"
482 #endif /* CONFIG_MIPS_MT_SMTC */
484 li t1
, ST0_CU0
| (STATMASK
& ~1)
485 #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
491 xori t0
, STATMASK
& ~1
493 #ifdef CONFIG_MIPS_MT_SMTC
495 andi v0
, v0
, VPECONTROL_TE
500 mfc0 v0
, CP0_TCSTATUS
501 /* Clear IXMT, then OR in previous value */
502 ori v0
, TCSTATUS_IXMT
503 xori v0
, TCSTATUS_IXMT
505 mtc0 v0
, CP0_TCSTATUS
507 * irq_disable_hazard below should expand to EHB
511 #endif /* CONFIG_MIPS_MT_SMTC */
515 #endif /* _ASM_STACKFRAME_H */