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 */
32 #ifdef CONFIG_CPU_HAS_SMARTMIPS
49 LONG_S $10, PT_R10(sp)
50 LONG_S $11, PT_R11(sp)
51 LONG_S $12, PT_R12(sp)
52 LONG_S $13, PT_R13(sp)
53 LONG_S $14, PT_R14(sp)
54 LONG_S $15, PT_R15(sp)
55 LONG_S $24, PT_R24(sp)
59 LONG_S $16, PT_R16(sp)
60 LONG_S $17, PT_R17(sp)
61 LONG_S $18, PT_R18(sp)
62 LONG_S $19, PT_R19(sp)
63 LONG_S $20, PT_R20(sp)
64 LONG_S $21, PT_R21(sp)
65 LONG_S $22, PT_R22(sp)
66 LONG_S $23, PT_R23(sp)
67 LONG_S $30, PT_R30(sp)
71 #ifdef CONFIG_MIPS_MT_SMTC
72 #define PTEBASE_SHIFT 19 /* TCBIND */
74 #define PTEBASE_SHIFT 23 /* CONTEXT */
76 .macro get_saved_sp /* SMP variation */
77 #ifdef CONFIG_MIPS_MT_SMTC
82 #if defined(CONFIG_BUILD_ELF64) || (defined(CONFIG_64BIT) && __GNUC__ < 4)
83 lui k1, %highest(kernelsp)
84 daddiu k1, %higher(kernelsp)
86 daddiu k1, %hi(kernelsp)
91 LONG_SRL k0, PTEBASE_SHIFT
93 LONG_L k1, %lo(kernelsp)(k1)
96 .macro set_saved_sp stackp temp temp2
97 #ifdef CONFIG_MIPS_MT_SMTC
98 mfc0 \temp, CP0_TCBIND
100 MFC0 \temp, CP0_CONTEXT
102 LONG_SRL \temp, PTEBASE_SHIFT
103 LONG_S \stackp, kernelsp(\temp)
106 .macro get_saved_sp /* Uniprocessor variation */
107 #if defined(CONFIG_BUILD_ELF64) || (defined(CONFIG_64BIT) && __GNUC__ < 4)
108 lui k1, %highest(kernelsp)
109 daddiu k1, %higher(kernelsp)
111 daddiu k1, %hi(kernelsp)
114 lui k1, %hi(kernelsp)
116 LONG_L k1, %lo(kernelsp)(k1)
119 .macro set_saved_sp stackp temp temp2
120 LONG_S \stackp, kernelsp
129 sll k0, 3 /* extract cu0 bit */
134 /* Called from user mode, new stack. */
137 PTR_SUBU sp, k1, PT_SIZE
138 LONG_S k0, PT_R29(sp)
141 * You might think that you don't need to save $0,
142 * but the FPU emulator and gdb remote debug stub
143 * need it to operate correctly
148 LONG_S v1, PT_STATUS(sp)
149 #ifdef CONFIG_MIPS_MT_SMTC
151 * Ideally, these instructions would be shuffled in
152 * to cover the pipeline delay.
155 mfc0 v1, CP0_TCSTATUS
157 LONG_S v1, PT_TCSTATUS(sp)
158 #endif /* CONFIG_MIPS_MT_SMTC */
162 LONG_S v1, PT_CAUSE(sp)
170 LONG_S v1, PT_EPC(sp)
171 LONG_S $25, PT_R25(sp)
172 LONG_S $28, PT_R28(sp)
173 LONG_S $31, PT_R31(sp)
174 ori $28, sp, _THREAD_MASK
175 xori $28, _THREAD_MASK
194 #ifdef CONFIG_CPU_HAS_SMARTMIPS
195 LONG_L $24, PT_ACX(sp)
197 LONG_L $24, PT_HI(sp)
199 LONG_L $24, PT_LO(sp)
202 LONG_L $24, PT_LO(sp)
204 LONG_L $24, PT_HI(sp)
211 LONG_L $10, PT_R10(sp)
212 LONG_L $11, PT_R11(sp)
213 LONG_L $12, PT_R12(sp)
214 LONG_L $13, PT_R13(sp)
215 LONG_L $14, PT_R14(sp)
216 LONG_L $15, PT_R15(sp)
217 LONG_L $24, PT_R24(sp)
220 .macro RESTORE_STATIC
221 LONG_L $16, PT_R16(sp)
222 LONG_L $17, PT_R17(sp)
223 LONG_L $18, PT_R18(sp)
224 LONG_L $19, PT_R19(sp)
225 LONG_L $20, PT_R20(sp)
226 LONG_L $21, PT_R21(sp)
227 LONG_L $22, PT_R22(sp)
228 LONG_L $23, PT_R23(sp)
229 LONG_L $30, PT_R30(sp)
232 #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
244 LONG_L v0, PT_STATUS(sp)
249 LONG_L $31, PT_R31(sp)
250 LONG_L $28, PT_R28(sp)
251 LONG_L $25, PT_R25(sp)
265 .macro RESTORE_SP_AND_RET
268 LONG_L k0, PT_EPC(sp)
269 LONG_L sp, PT_R29(sp)
277 * For SMTC kernel, global IE should be left set, and interrupts
278 * controlled exclusively via IXMT.
281 #ifdef CONFIG_MIPS_MT_SMTC
282 #define STATMASK 0x1e
284 #define STATMASK 0x1f
290 #ifdef CONFIG_MIPS_MT_SMTC
293 * This may not really be necessary if ints are already
296 mfc0 v0, CP0_TCSTATUS
297 ori v0, TCSTATUS_IXMT
298 mtc0 v0, CP0_TCSTATUS
302 #endif /* CONFIG_MIPS_MT_SMTC */
309 LONG_L v0, PT_STATUS(sp)
314 #ifdef CONFIG_MIPS_MT_SMTC
316 * Only after EXL/ERL have been restored to status can we
317 * restore TCStatus.IXMT.
319 LONG_L v1, PT_TCSTATUS(sp)
321 mfc0 v0, CP0_TCSTATUS
322 andi v1, TCSTATUS_IXMT
323 /* We know that TCStatua.IXMT should be set from above */
324 xori v0, v0, TCSTATUS_IXMT
326 mtc0 v0, CP0_TCSTATUS
328 andi a1, a1, VPECONTROL_TE
333 #endif /* CONFIG_MIPS_MT_SMTC */
334 LONG_L v1, PT_EPC(sp)
336 LONG_L $31, PT_R31(sp)
337 LONG_L $28, PT_R28(sp)
338 LONG_L $25, PT_R25(sp)
352 .macro RESTORE_SP_AND_RET
353 LONG_L sp, PT_R29(sp)
362 LONG_L sp, PT_R29(sp)
373 .macro RESTORE_ALL_AND_RET
382 * Move to kernel mode and disable interrupts.
383 * Set cp0 enable bit as sign that we're running on the kernel stack
386 #if !defined(CONFIG_MIPS_MT_SMTC)
388 li t1, ST0_CU0 | 0x1f
392 #else /* CONFIG_MIPS_MT_SMTC */
394 * For SMTC, we need to set privilege
395 * and disable interrupts only for the
396 * current TC, using the TCStatus register.
399 /* Fortunately CU 0 is in the same place in both registers */
400 /* Set TCU0, TMX, TKSU (for later inversion) and IXMT */
401 li t1, ST0_CU0 | 0x08001c00
403 /* Clear TKSU, leave IXMT */
405 mtc0 t0, CP0_TCSTATUS
407 /* We need to leave the global IE bit set, but clear EXL...*/
409 ori t0, ST0_EXL | ST0_ERL
410 xori t0, ST0_EXL | ST0_ERL
412 #endif /* CONFIG_MIPS_MT_SMTC */
417 * Move to kernel mode and enable interrupts.
418 * Set cp0 enable bit as sign that we're running on the kernel stack
421 #if !defined(CONFIG_MIPS_MT_SMTC)
423 li t1, ST0_CU0 | 0x1f
427 #else /* CONFIG_MIPS_MT_SMTC */
429 * For SMTC, we need to set privilege
430 * and enable interrupts only for the
431 * current TC, using the TCStatus register.
435 /* Fortunately CU 0 is in the same place in both registers */
436 /* Set TCU0, TKSU (for later inversion) and IXMT */
437 li t1, ST0_CU0 | 0x08001c00
439 /* Clear TKSU *and* IXMT */
441 mtc0 t0, CP0_TCSTATUS
443 /* We need to leave the global IE bit set, but clear EXL...*/
448 /* irq_enable_hazard below should expand to EHB for 24K/34K cpus */
449 #endif /* CONFIG_MIPS_MT_SMTC */
454 * Just move to kernel mode and leave interrupts as they are.
455 * Set cp0 enable bit as sign that we're running on the kernel stack
458 #ifdef CONFIG_MIPS_MT_SMTC
460 * This gets baroque in SMTC. We want to
461 * protect the non-atomic clearing of EXL
462 * with DMT/EMT, but we don't want to take
463 * an interrupt while DMT is still in effect.
466 /* KMODE gets invoked from both reorder and noreorder code */
470 mfc0 v0, CP0_TCSTATUS
471 andi v1, v0, TCSTATUS_IXMT
472 ori v0, TCSTATUS_IXMT
473 mtc0 v0, CP0_TCSTATUS
477 * We don't know a priori if ra is "live"
483 #endif /* CONFIG_MIPS_MT_SMTC */
485 li t1, ST0_CU0 | 0x1e
489 #ifdef CONFIG_MIPS_MT_SMTC
491 andi v0, v0, VPECONTROL_TE
496 mfc0 v0, CP0_TCSTATUS
497 /* Clear IXMT, then OR in previous value */
498 ori v0, TCSTATUS_IXMT
499 xori v0, TCSTATUS_IXMT
501 mtc0 v0, CP0_TCSTATUS
503 * irq_disable_hazard below should expand to EHB
507 #endif /* CONFIG_MIPS_MT_SMTC */
511 #endif /* _ASM_STACKFRAME_H */