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 #ifdef CONFIG_MIPS_MT_SMTC
63 #define PTEBASE_SHIFT 19 /* TCBIND */
65 #define PTEBASE_SHIFT 23 /* CONTEXT */
67 .macro get_saved_sp /* SMP variation */
68 #ifdef CONFIG_MIPS_MT_SMTC
73 #if defined(CONFIG_BUILD_ELF64) || (defined(CONFIG_64BIT) && __GNUC__ < 4)
74 lui k1, %highest(kernelsp)
75 daddiu k1, %higher(kernelsp)
77 daddiu k1, %hi(kernelsp)
82 LONG_SRL k0, PTEBASE_SHIFT
84 LONG_L k1, %lo(kernelsp)(k1)
87 .macro set_saved_sp stackp temp temp2
88 #ifdef CONFIG_MIPS_MT_SMTC
89 mfc0 \temp, CP0_TCBIND
91 MFC0 \temp, CP0_CONTEXT
93 LONG_SRL \temp, PTEBASE_SHIFT
94 LONG_S \stackp, kernelsp(\temp)
97 .macro get_saved_sp /* Uniprocessor variation */
98 #if defined(CONFIG_BUILD_ELF64) || (defined(CONFIG_64BIT) && __GNUC__ < 4)
99 lui k1, %highest(kernelsp)
100 daddiu k1, %higher(kernelsp)
102 daddiu k1, %hi(kernelsp)
105 lui k1, %hi(kernelsp)
107 LONG_L k1, %lo(kernelsp)(k1)
110 .macro set_saved_sp stackp temp temp2
111 LONG_S \stackp, kernelsp
120 sll k0, 3 /* extract cu0 bit */
125 /* Called from user mode, new stack. */
128 PTR_SUBU sp, k1, PT_SIZE
129 LONG_S k0, PT_R29(sp)
132 * You might think that you don't need to save $0,
133 * but the FPU emulator and gdb remote debug stub
134 * need it to operate correctly
139 LONG_S v1, PT_STATUS(sp)
140 #ifdef CONFIG_MIPS_MT_SMTC
142 * Ideally, these instructions would be shuffled in
143 * to cover the pipeline delay.
146 mfc0 v1, CP0_TCSTATUS
148 LONG_S v1, PT_TCSTATUS(sp)
149 #endif /* CONFIG_MIPS_MT_SMTC */
153 LONG_S v1, PT_CAUSE(sp)
161 LONG_S v1, PT_EPC(sp)
162 LONG_S $25, PT_R25(sp)
163 LONG_S $28, PT_R28(sp)
164 LONG_S $31, PT_R31(sp)
165 ori $28, sp, _THREAD_MASK
166 xori $28, _THREAD_MASK
185 LONG_L $24, PT_LO(sp)
191 LONG_L $24, PT_HI(sp)
192 LONG_L $10, PT_R10(sp)
193 LONG_L $11, PT_R11(sp)
195 LONG_L $12, PT_R12(sp)
196 LONG_L $13, PT_R13(sp)
197 LONG_L $14, PT_R14(sp)
198 LONG_L $15, PT_R15(sp)
199 LONG_L $24, PT_R24(sp)
202 .macro RESTORE_STATIC
203 LONG_L $16, PT_R16(sp)
204 LONG_L $17, PT_R17(sp)
205 LONG_L $18, PT_R18(sp)
206 LONG_L $19, PT_R19(sp)
207 LONG_L $20, PT_R20(sp)
208 LONG_L $21, PT_R21(sp)
209 LONG_L $22, PT_R22(sp)
210 LONG_L $23, PT_R23(sp)
211 LONG_L $30, PT_R30(sp)
214 #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
226 LONG_L v0, PT_STATUS(sp)
231 LONG_L $31, PT_R31(sp)
232 LONG_L $28, PT_R28(sp)
233 LONG_L $25, PT_R25(sp)
247 .macro RESTORE_SP_AND_RET
250 LONG_L k0, PT_EPC(sp)
251 LONG_L sp, PT_R29(sp)
259 * For SMTC kernel, global IE should be left set, and interrupts
260 * controlled exclusively via IXMT.
263 #ifdef CONFIG_MIPS_MT_SMTC
264 #define STATMASK 0x1e
266 #define STATMASK 0x1f
272 #ifdef CONFIG_MIPS_MT_SMTC
275 * This may not really be necessary if ints are already
278 mfc0 v0, CP0_TCSTATUS
279 ori v0, TCSTATUS_IXMT
280 mtc0 v0, CP0_TCSTATUS
284 #endif /* CONFIG_MIPS_MT_SMTC */
291 LONG_L v0, PT_STATUS(sp)
296 #ifdef CONFIG_MIPS_MT_SMTC
298 * Only after EXL/ERL have been restored to status can we
299 * restore TCStatus.IXMT.
301 LONG_L v1, PT_TCSTATUS(sp)
303 mfc0 v0, CP0_TCSTATUS
304 andi v1, TCSTATUS_IXMT
305 /* We know that TCStatua.IXMT should be set from above */
306 xori v0, v0, TCSTATUS_IXMT
308 mtc0 v0, CP0_TCSTATUS
310 andi a1, a1, VPECONTROL_TE
315 #endif /* CONFIG_MIPS_MT_SMTC */
316 LONG_L v1, PT_EPC(sp)
318 LONG_L $31, PT_R31(sp)
319 LONG_L $28, PT_R28(sp)
320 LONG_L $25, PT_R25(sp)
334 .macro RESTORE_SP_AND_RET
335 LONG_L sp, PT_R29(sp)
344 LONG_L sp, PT_R29(sp)
355 .macro RESTORE_ALL_AND_RET
364 * Move to kernel mode and disable interrupts.
365 * Set cp0 enable bit as sign that we're running on the kernel stack
368 #if !defined(CONFIG_MIPS_MT_SMTC)
370 li t1, ST0_CU0 | 0x1f
374 #else /* CONFIG_MIPS_MT_SMTC */
376 * For SMTC, we need to set privilege
377 * and disable interrupts only for the
378 * current TC, using the TCStatus register.
381 /* Fortunately CU 0 is in the same place in both registers */
382 /* Set TCU0, TMX, TKSU (for later inversion) and IXMT */
383 li t1, ST0_CU0 | 0x08001c00
385 /* Clear TKSU, leave IXMT */
387 mtc0 t0, CP0_TCSTATUS
389 /* We need to leave the global IE bit set, but clear EXL...*/
391 ori t0, ST0_EXL | ST0_ERL
392 xori t0, ST0_EXL | ST0_ERL
394 #endif /* CONFIG_MIPS_MT_SMTC */
399 * Move to kernel mode and enable interrupts.
400 * Set cp0 enable bit as sign that we're running on the kernel stack
403 #if !defined(CONFIG_MIPS_MT_SMTC)
405 li t1, ST0_CU0 | 0x1f
409 #else /* CONFIG_MIPS_MT_SMTC */
411 * For SMTC, we need to set privilege
412 * and enable interrupts only for the
413 * current TC, using the TCStatus register.
417 /* Fortunately CU 0 is in the same place in both registers */
418 /* Set TCU0, TKSU (for later inversion) and IXMT */
419 li t1, ST0_CU0 | 0x08001c00
421 /* Clear TKSU *and* IXMT */
423 mtc0 t0, CP0_TCSTATUS
425 /* We need to leave the global IE bit set, but clear EXL...*/
430 /* irq_enable_hazard below should expand to EHB for 24K/34K cpus */
431 #endif /* CONFIG_MIPS_MT_SMTC */
436 * Just move to kernel mode and leave interrupts as they are.
437 * Set cp0 enable bit as sign that we're running on the kernel stack
440 #ifdef CONFIG_MIPS_MT_SMTC
442 * This gets baroque in SMTC. We want to
443 * protect the non-atomic clearing of EXL
444 * with DMT/EMT, but we don't want to take
445 * an interrupt while DMT is still in effect.
448 /* KMODE gets invoked from both reorder and noreorder code */
452 mfc0 v0, CP0_TCSTATUS
453 andi v1, v0, TCSTATUS_IXMT
454 ori v0, TCSTATUS_IXMT
455 mtc0 v0, CP0_TCSTATUS
459 * We don't know a priori if ra is "live"
465 #endif /* CONFIG_MIPS_MT_SMTC */
467 li t1, ST0_CU0 | 0x1e
471 #ifdef CONFIG_MIPS_MT_SMTC
473 andi v0, v0, VPECONTROL_TE
478 mfc0 v0, CP0_TCSTATUS
479 /* Clear IXMT, then OR in previous value */
480 ori v0, TCSTATUS_IXMT
481 xori v0, TCSTATUS_IXMT
483 mtc0 v0, CP0_TCSTATUS
485 * irq_disable_hazard below should expand to EHB
489 #endif /* CONFIG_MIPS_MT_SMTC */
493 #endif /* _ASM_STACKFRAME_H */