blob: b49d3b60bc0ca267cb79a61dc293c29d7faae83b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: etrap.S,v 1.46 2002/02/09 19:49:30 davem Exp $
2 * etrap.S: Preparing for entry into the kernel on Sparc V9.
3 *
4 * Copyright (C) 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1997, 1998, 1999 Jakub Jelinek (jj@ultra.linux.cz)
6 */
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9#include <asm/asi.h>
10#include <asm/pstate.h>
11#include <asm/ptrace.h>
12#include <asm/page.h>
13#include <asm/spitfire.h>
14#include <asm/head.h>
15#include <asm/processor.h>
16#include <asm/mmu.h>
17
18#define TASK_REGOFF (THREAD_SIZE-TRACEREG_SZ-STACKFRAME_SZ)
19#define ETRAP_PSTATE1 (PSTATE_RMO | PSTATE_PRIV)
20#define ETRAP_PSTATE2 \
21 (PSTATE_RMO | PSTATE_PEF | PSTATE_PRIV | PSTATE_IE)
22
23/*
24 * On entry, %g7 is return address - 0x4.
25 * %g4 and %g5 will be preserved %l4 and %l5 respectively.
26 */
27
28 .text
29 .align 64
30 .globl etrap, etrap_irq, etraptl1
31etrap: rdpr %pil, %g2
32etrap_irq:
David S. Millerffe483d2006-02-02 21:55:10 -080033 TRAP_LOAD_THREAD_REG(%g6, %g1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 rdpr %tstate, %g1
35 sllx %g2, 20, %g3
36 andcc %g1, TSTATE_PRIV, %g0
37 or %g1, %g3, %g1
38 bne,pn %xcc, 1f
39 sub %sp, STACKFRAME_SZ+TRACEREG_SZ-STACK_BIAS, %g2
40 wrpr %g0, 7, %cleanwin
41
42 sethi %hi(TASK_REGOFF), %g2
43 sethi %hi(TSTATE_PEF), %g3
44 or %g2, %lo(TASK_REGOFF), %g2
45 and %g1, %g3, %g3
46 brnz,pn %g3, 1f
47 add %g6, %g2, %g2
48 wr %g0, 0, %fprs
491: rdpr %tpc, %g3
50
51 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TSTATE]
52 rdpr %tnpc, %g1
53 stx %g3, [%g2 + STACKFRAME_SZ + PT_V9_TPC]
54 rd %y, %g3
55 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TNPC]
David S. Miller8243e40a2008-04-23 22:52:13 -070056 rdpr %tt, %g1
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 st %g3, [%g2 + STACKFRAME_SZ + PT_V9_Y]
David S. Miller8243e40a2008-04-23 22:52:13 -070058 sethi %hi(PT_REGS_MAGIC), %g3
59 or %g3, %g1, %g1
60 st %g1, [%g2 + STACKFRAME_SZ + PT_V9_MAGIC]
David S. Miller314ef682006-02-04 00:10:01 -080061
62 rdpr %cansave, %g1
63 brnz,pt %g1, etrap_save
64 nop
65
66 rdpr %cwp, %g1
67 add %g1, 2, %g1
68 wrpr %g1, %cwp
69 be,pt %xcc, etrap_user_spill
70 mov ASI_AIUP, %g3
71
72 rdpr %otherwin, %g3
73 brz %g3, etrap_kernel_spill
74 mov ASI_AIUS, %g3
75
76etrap_user_spill:
77
78 wr %g3, 0x0, %asi
79 ldx [%g6 + TI_FLAGS], %g3
80 and %g3, _TIF_32BIT, %g3
81 brnz,pt %g3, etrap_user_spill_32bit
82 nop
83 ba,a,pt %xcc, etrap_user_spill_64bit
84
85etrap_save: save %g2, -STACK_BIAS, %sp
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 mov %g6, %l6
87
88 bne,pn %xcc, 3f
89 mov PRIMARY_CONTEXT, %l4
90 rdpr %canrestore, %g3
91 rdpr %wstate, %g2
92 wrpr %g0, 0, %canrestore
93 sll %g2, 3, %g2
94 mov 1, %l5
95 stb %l5, [%l6 + TI_FPDEPTH]
96
97 wrpr %g3, 0, %otherwin
98 wrpr %g2, 0, %wstate
David S. Miller0835ae02005-10-04 15:23:20 -070099 sethi %hi(sparc64_kern_pri_context), %g2
100 ldx [%g2 + %lo(sparc64_kern_pri_context)], %g3
David S. Miller8b11bd12006-02-07 22:13:05 -0800101
102661: stxa %g3, [%l4] ASI_DMMU
103 .section .sun4v_1insn_patch, "ax"
104 .word 661b
105 stxa %g3, [%l4] ASI_MMU
106 .previous
107
David S. Miller4da808c2006-01-31 18:33:00 -0800108 sethi %hi(KERNBASE), %l4
109 flush %l4
David S. Miller6e024932006-02-05 20:47:26 -0800110 mov ASI_AIUS, %l7
1112: mov %g4, %l4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 mov %g5, %l5
David S. Miller6e024932006-02-05 20:47:26 -0800113 add %g7, 4, %l2
David S. Miller936f4822006-02-05 21:29:28 -0800114
115 /* Go to trap time globals so we can save them. */
116661: wrpr %g0, ETRAP_PSTATE1, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800117 .section .sun4v_1insn_patch, "ax"
David S. Miller936f4822006-02-05 21:29:28 -0800118 .word 661b
119 SET_GL(0)
120 .previous
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 stx %g1, [%sp + PTREGS_OFF + PT_V9_G1]
123 stx %g2, [%sp + PTREGS_OFF + PT_V9_G2]
David S. Miller6e024932006-02-05 20:47:26 -0800124 sllx %l7, 24, %l7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 stx %g3, [%sp + PTREGS_OFF + PT_V9_G3]
David S. Miller6e024932006-02-05 20:47:26 -0800126 rdpr %cwp, %l0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 stx %g4, [%sp + PTREGS_OFF + PT_V9_G4]
128 stx %g5, [%sp + PTREGS_OFF + PT_V9_G5]
129 stx %g6, [%sp + PTREGS_OFF + PT_V9_G6]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 stx %g7, [%sp + PTREGS_OFF + PT_V9_G7]
David S. Miller6e024932006-02-05 20:47:26 -0800131 or %l7, %l0, %l7
132 sethi %hi(TSTATE_RMO | TSTATE_PEF), %l0
133 or %l7, %l0, %l7
134 wrpr %l2, %tnpc
135 wrpr %l7, (TSTATE_PRIV | TSTATE_IE), %tstate
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 stx %i0, [%sp + PTREGS_OFF + PT_V9_I0]
137 stx %i1, [%sp + PTREGS_OFF + PT_V9_I1]
138 stx %i2, [%sp + PTREGS_OFF + PT_V9_I2]
139 stx %i3, [%sp + PTREGS_OFF + PT_V9_I3]
140 stx %i4, [%sp + PTREGS_OFF + PT_V9_I4]
141 stx %i5, [%sp + PTREGS_OFF + PT_V9_I5]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 stx %i6, [%sp + PTREGS_OFF + PT_V9_I6]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 mov %l6, %g6
David S. Miller6e024932006-02-05 20:47:26 -0800144 stx %i7, [%sp + PTREGS_OFF + PT_V9_I7]
David S. Millerffe483d2006-02-02 21:55:10 -0800145 LOAD_PER_CPU_BASE(%g5, %g6, %g4, %g3, %l1)
David S. Miller6e024932006-02-05 20:47:26 -0800146 ldx [%g6 + TI_TASK], %g4
147 done
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
David S. Miller6e024932006-02-05 20:47:26 -08001493: mov ASI_P, %l7
150 ldub [%l6 + TI_FPDEPTH], %l5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 add %l6, TI_FPSAVED + 1, %l4
152 srl %l5, 1, %l3
153 add %l5, 2, %l5
154 stb %l5, [%l6 + TI_FPDEPTH]
155 ba,pt %xcc, 2b
156 stb %g0, [%l4 + %l3]
157 nop
158
159etraptl1: /* Save tstate/tpc/tnpc of TL 1-->4 and the tl register itself.
160 * We place this right after pt_regs on the trap stack.
161 * The layout is:
162 * 0x00 TL1's TSTATE
163 * 0x08 TL1's TPC
164 * 0x10 TL1's TNPC
165 * 0x18 TL1's TT
166 * ...
167 * 0x58 TL4's TT
168 * 0x60 TL
169 */
David S. Millerffe483d2006-02-02 21:55:10 -0800170 TRAP_LOAD_THREAD_REG(%g6, %g1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 sub %sp, ((4 * 8) * 4) + 8, %g2
172 rdpr %tl, %g1
173
174 wrpr %g0, 1, %tl
175 rdpr %tstate, %g3
176 stx %g3, [%g2 + STACK_BIAS + 0x00]
177 rdpr %tpc, %g3
178 stx %g3, [%g2 + STACK_BIAS + 0x08]
179 rdpr %tnpc, %g3
180 stx %g3, [%g2 + STACK_BIAS + 0x10]
181 rdpr %tt, %g3
182 stx %g3, [%g2 + STACK_BIAS + 0x18]
183
184 wrpr %g0, 2, %tl
185 rdpr %tstate, %g3
186 stx %g3, [%g2 + STACK_BIAS + 0x20]
187 rdpr %tpc, %g3
188 stx %g3, [%g2 + STACK_BIAS + 0x28]
189 rdpr %tnpc, %g3
190 stx %g3, [%g2 + STACK_BIAS + 0x30]
191 rdpr %tt, %g3
192 stx %g3, [%g2 + STACK_BIAS + 0x38]
193
David S. Miller3d6395c2006-02-16 01:41:41 -0800194 sethi %hi(is_sun4v), %g3
195 lduw [%g3 + %lo(is_sun4v)], %g3
196 brnz,pn %g3, finish_tl1_capture
197 nop
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 wrpr %g0, 3, %tl
200 rdpr %tstate, %g3
201 stx %g3, [%g2 + STACK_BIAS + 0x40]
202 rdpr %tpc, %g3
203 stx %g3, [%g2 + STACK_BIAS + 0x48]
204 rdpr %tnpc, %g3
205 stx %g3, [%g2 + STACK_BIAS + 0x50]
206 rdpr %tt, %g3
207 stx %g3, [%g2 + STACK_BIAS + 0x58]
208
209 wrpr %g0, 4, %tl
210 rdpr %tstate, %g3
211 stx %g3, [%g2 + STACK_BIAS + 0x60]
212 rdpr %tpc, %g3
213 stx %g3, [%g2 + STACK_BIAS + 0x68]
214 rdpr %tnpc, %g3
215 stx %g3, [%g2 + STACK_BIAS + 0x70]
216 rdpr %tt, %g3
217 stx %g3, [%g2 + STACK_BIAS + 0x78]
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 stx %g1, [%g2 + STACK_BIAS + 0x80]
220
David S. Miller3d6395c2006-02-16 01:41:41 -0800221finish_tl1_capture:
David S. Miller936f4822006-02-05 21:29:28 -0800222 wrpr %g0, 1, %tl
223661: nop
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800224 .section .sun4v_1insn_patch, "ax"
David S. Miller936f4822006-02-05 21:29:28 -0800225 .word 661b
226 SET_GL(1)
227 .previous
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 rdpr %tstate, %g1
230 sub %g2, STACKFRAME_SZ + TRACEREG_SZ - STACK_BIAS, %g2
231 ba,pt %xcc, 1b
232 andcc %g1, TSTATE_PRIV, %g0
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234#undef TASK_REGOFF
235#undef ETRAP_PSTATE1