Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $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 | |
| 8 | #include <linux/config.h> |
| 9 | |
| 10 | #include <asm/asi.h> |
| 11 | #include <asm/pstate.h> |
| 12 | #include <asm/ptrace.h> |
| 13 | #include <asm/page.h> |
| 14 | #include <asm/spitfire.h> |
| 15 | #include <asm/head.h> |
| 16 | #include <asm/processor.h> |
| 17 | #include <asm/mmu.h> |
| 18 | |
| 19 | #define TASK_REGOFF (THREAD_SIZE-TRACEREG_SZ-STACKFRAME_SZ) |
| 20 | #define ETRAP_PSTATE1 (PSTATE_RMO | PSTATE_PRIV) |
| 21 | #define ETRAP_PSTATE2 \ |
| 22 | (PSTATE_RMO | PSTATE_PEF | PSTATE_PRIV | PSTATE_IE) |
| 23 | |
| 24 | /* |
| 25 | * On entry, %g7 is return address - 0x4. |
| 26 | * %g4 and %g5 will be preserved %l4 and %l5 respectively. |
| 27 | */ |
| 28 | |
| 29 | .text |
| 30 | .align 64 |
| 31 | .globl etrap, etrap_irq, etraptl1 |
| 32 | etrap: rdpr %pil, %g2 |
| 33 | etrap_irq: |
David S. Miller | ffe483d | 2006-02-02 21:55:10 -0800 | [diff] [blame] | 34 | TRAP_LOAD_THREAD_REG(%g6, %g1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | rdpr %tstate, %g1 |
| 36 | sllx %g2, 20, %g3 |
| 37 | andcc %g1, TSTATE_PRIV, %g0 |
| 38 | or %g1, %g3, %g1 |
| 39 | bne,pn %xcc, 1f |
| 40 | sub %sp, STACKFRAME_SZ+TRACEREG_SZ-STACK_BIAS, %g2 |
| 41 | wrpr %g0, 7, %cleanwin |
| 42 | |
| 43 | sethi %hi(TASK_REGOFF), %g2 |
| 44 | sethi %hi(TSTATE_PEF), %g3 |
| 45 | or %g2, %lo(TASK_REGOFF), %g2 |
| 46 | and %g1, %g3, %g3 |
| 47 | brnz,pn %g3, 1f |
| 48 | add %g6, %g2, %g2 |
| 49 | wr %g0, 0, %fprs |
| 50 | 1: rdpr %tpc, %g3 |
| 51 | |
| 52 | stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TSTATE] |
| 53 | rdpr %tnpc, %g1 |
| 54 | stx %g3, [%g2 + STACKFRAME_SZ + PT_V9_TPC] |
| 55 | rd %y, %g3 |
| 56 | stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TNPC] |
| 57 | st %g3, [%g2 + STACKFRAME_SZ + PT_V9_Y] |
David S. Miller | 314ef68 | 2006-02-04 00:10:01 -0800 | [diff] [blame] | 58 | |
| 59 | rdpr %cansave, %g1 |
| 60 | brnz,pt %g1, etrap_save |
| 61 | nop |
| 62 | |
| 63 | rdpr %cwp, %g1 |
| 64 | add %g1, 2, %g1 |
| 65 | wrpr %g1, %cwp |
| 66 | be,pt %xcc, etrap_user_spill |
| 67 | mov ASI_AIUP, %g3 |
| 68 | |
| 69 | rdpr %otherwin, %g3 |
| 70 | brz %g3, etrap_kernel_spill |
| 71 | mov ASI_AIUS, %g3 |
| 72 | |
| 73 | etrap_user_spill: |
| 74 | |
| 75 | wr %g3, 0x0, %asi |
| 76 | ldx [%g6 + TI_FLAGS], %g3 |
| 77 | and %g3, _TIF_32BIT, %g3 |
| 78 | brnz,pt %g3, etrap_user_spill_32bit |
| 79 | nop |
| 80 | ba,a,pt %xcc, etrap_user_spill_64bit |
| 81 | |
| 82 | etrap_save: save %g2, -STACK_BIAS, %sp |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | mov %g6, %l6 |
| 84 | |
| 85 | bne,pn %xcc, 3f |
| 86 | mov PRIMARY_CONTEXT, %l4 |
| 87 | rdpr %canrestore, %g3 |
| 88 | rdpr %wstate, %g2 |
| 89 | wrpr %g0, 0, %canrestore |
| 90 | sll %g2, 3, %g2 |
| 91 | mov 1, %l5 |
| 92 | stb %l5, [%l6 + TI_FPDEPTH] |
| 93 | |
| 94 | wrpr %g3, 0, %otherwin |
| 95 | wrpr %g2, 0, %wstate |
David S. Miller | 0835ae0 | 2005-10-04 15:23:20 -0700 | [diff] [blame] | 96 | sethi %hi(sparc64_kern_pri_context), %g2 |
| 97 | ldx [%g2 + %lo(sparc64_kern_pri_context)], %g3 |
David S. Miller | 8b11bd1 | 2006-02-07 22:13:05 -0800 | [diff] [blame] | 98 | |
| 99 | 661: stxa %g3, [%l4] ASI_DMMU |
| 100 | .section .sun4v_1insn_patch, "ax" |
| 101 | .word 661b |
| 102 | stxa %g3, [%l4] ASI_MMU |
| 103 | .previous |
| 104 | |
David S. Miller | 4da808c | 2006-01-31 18:33:00 -0800 | [diff] [blame] | 105 | sethi %hi(KERNBASE), %l4 |
| 106 | flush %l4 |
David S. Miller | 6e02493 | 2006-02-05 20:47:26 -0800 | [diff] [blame] | 107 | mov ASI_AIUS, %l7 |
| 108 | 2: mov %g4, %l4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | mov %g5, %l5 |
David S. Miller | 6e02493 | 2006-02-05 20:47:26 -0800 | [diff] [blame] | 110 | add %g7, 4, %l2 |
David S. Miller | 936f482 | 2006-02-05 21:29:28 -0800 | [diff] [blame] | 111 | |
| 112 | /* Go to trap time globals so we can save them. */ |
| 113 | 661: wrpr %g0, ETRAP_PSTATE1, %pstate |
David S. Miller | df7d6ae | 2006-02-07 00:00:16 -0800 | [diff] [blame] | 114 | .section .sun4v_1insn_patch, "ax" |
David S. Miller | 936f482 | 2006-02-05 21:29:28 -0800 | [diff] [blame] | 115 | .word 661b |
| 116 | SET_GL(0) |
| 117 | .previous |
| 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | stx %g1, [%sp + PTREGS_OFF + PT_V9_G1] |
| 120 | stx %g2, [%sp + PTREGS_OFF + PT_V9_G2] |
David S. Miller | 6e02493 | 2006-02-05 20:47:26 -0800 | [diff] [blame] | 121 | sllx %l7, 24, %l7 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | stx %g3, [%sp + PTREGS_OFF + PT_V9_G3] |
David S. Miller | 6e02493 | 2006-02-05 20:47:26 -0800 | [diff] [blame] | 123 | rdpr %cwp, %l0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | stx %g4, [%sp + PTREGS_OFF + PT_V9_G4] |
| 125 | stx %g5, [%sp + PTREGS_OFF + PT_V9_G5] |
| 126 | stx %g6, [%sp + PTREGS_OFF + PT_V9_G6] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | stx %g7, [%sp + PTREGS_OFF + PT_V9_G7] |
David S. Miller | 6e02493 | 2006-02-05 20:47:26 -0800 | [diff] [blame] | 128 | or %l7, %l0, %l7 |
| 129 | sethi %hi(TSTATE_RMO | TSTATE_PEF), %l0 |
| 130 | or %l7, %l0, %l7 |
| 131 | wrpr %l2, %tnpc |
| 132 | wrpr %l7, (TSTATE_PRIV | TSTATE_IE), %tstate |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | stx %i0, [%sp + PTREGS_OFF + PT_V9_I0] |
| 134 | stx %i1, [%sp + PTREGS_OFF + PT_V9_I1] |
| 135 | stx %i2, [%sp + PTREGS_OFF + PT_V9_I2] |
| 136 | stx %i3, [%sp + PTREGS_OFF + PT_V9_I3] |
| 137 | stx %i4, [%sp + PTREGS_OFF + PT_V9_I4] |
| 138 | stx %i5, [%sp + PTREGS_OFF + PT_V9_I5] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | stx %i6, [%sp + PTREGS_OFF + PT_V9_I6] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | mov %l6, %g6 |
David S. Miller | 6e02493 | 2006-02-05 20:47:26 -0800 | [diff] [blame] | 141 | stx %i7, [%sp + PTREGS_OFF + PT_V9_I7] |
David S. Miller | ffe483d | 2006-02-02 21:55:10 -0800 | [diff] [blame] | 142 | LOAD_PER_CPU_BASE(%g5, %g6, %g4, %g3, %l1) |
David S. Miller | 6e02493 | 2006-02-05 20:47:26 -0800 | [diff] [blame] | 143 | ldx [%g6 + TI_TASK], %g4 |
| 144 | done |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
David S. Miller | 6e02493 | 2006-02-05 20:47:26 -0800 | [diff] [blame] | 146 | 3: mov ASI_P, %l7 |
| 147 | ldub [%l6 + TI_FPDEPTH], %l5 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | add %l6, TI_FPSAVED + 1, %l4 |
| 149 | srl %l5, 1, %l3 |
| 150 | add %l5, 2, %l5 |
| 151 | stb %l5, [%l6 + TI_FPDEPTH] |
| 152 | ba,pt %xcc, 2b |
| 153 | stb %g0, [%l4 + %l3] |
| 154 | nop |
| 155 | |
| 156 | etraptl1: /* Save tstate/tpc/tnpc of TL 1-->4 and the tl register itself. |
| 157 | * We place this right after pt_regs on the trap stack. |
| 158 | * The layout is: |
| 159 | * 0x00 TL1's TSTATE |
| 160 | * 0x08 TL1's TPC |
| 161 | * 0x10 TL1's TNPC |
| 162 | * 0x18 TL1's TT |
| 163 | * ... |
| 164 | * 0x58 TL4's TT |
| 165 | * 0x60 TL |
| 166 | */ |
David S. Miller | ffe483d | 2006-02-02 21:55:10 -0800 | [diff] [blame] | 167 | TRAP_LOAD_THREAD_REG(%g6, %g1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | sub %sp, ((4 * 8) * 4) + 8, %g2 |
| 169 | rdpr %tl, %g1 |
| 170 | |
| 171 | wrpr %g0, 1, %tl |
| 172 | rdpr %tstate, %g3 |
| 173 | stx %g3, [%g2 + STACK_BIAS + 0x00] |
| 174 | rdpr %tpc, %g3 |
| 175 | stx %g3, [%g2 + STACK_BIAS + 0x08] |
| 176 | rdpr %tnpc, %g3 |
| 177 | stx %g3, [%g2 + STACK_BIAS + 0x10] |
| 178 | rdpr %tt, %g3 |
| 179 | stx %g3, [%g2 + STACK_BIAS + 0x18] |
| 180 | |
| 181 | wrpr %g0, 2, %tl |
| 182 | rdpr %tstate, %g3 |
| 183 | stx %g3, [%g2 + STACK_BIAS + 0x20] |
| 184 | rdpr %tpc, %g3 |
| 185 | stx %g3, [%g2 + STACK_BIAS + 0x28] |
| 186 | rdpr %tnpc, %g3 |
| 187 | stx %g3, [%g2 + STACK_BIAS + 0x30] |
| 188 | rdpr %tt, %g3 |
| 189 | stx %g3, [%g2 + STACK_BIAS + 0x38] |
| 190 | |
David S. Miller | 3d6395c | 2006-02-16 01:41:41 -0800 | [diff] [blame^] | 191 | sethi %hi(is_sun4v), %g3 |
| 192 | lduw [%g3 + %lo(is_sun4v)], %g3 |
| 193 | brnz,pn %g3, finish_tl1_capture |
| 194 | nop |
| 195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | wrpr %g0, 3, %tl |
| 197 | rdpr %tstate, %g3 |
| 198 | stx %g3, [%g2 + STACK_BIAS + 0x40] |
| 199 | rdpr %tpc, %g3 |
| 200 | stx %g3, [%g2 + STACK_BIAS + 0x48] |
| 201 | rdpr %tnpc, %g3 |
| 202 | stx %g3, [%g2 + STACK_BIAS + 0x50] |
| 203 | rdpr %tt, %g3 |
| 204 | stx %g3, [%g2 + STACK_BIAS + 0x58] |
| 205 | |
| 206 | wrpr %g0, 4, %tl |
| 207 | rdpr %tstate, %g3 |
| 208 | stx %g3, [%g2 + STACK_BIAS + 0x60] |
| 209 | rdpr %tpc, %g3 |
| 210 | stx %g3, [%g2 + STACK_BIAS + 0x68] |
| 211 | rdpr %tnpc, %g3 |
| 212 | stx %g3, [%g2 + STACK_BIAS + 0x70] |
| 213 | rdpr %tt, %g3 |
| 214 | stx %g3, [%g2 + STACK_BIAS + 0x78] |
| 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | stx %g1, [%g2 + STACK_BIAS + 0x80] |
| 217 | |
David S. Miller | 3d6395c | 2006-02-16 01:41:41 -0800 | [diff] [blame^] | 218 | finish_tl1_capture: |
David S. Miller | 936f482 | 2006-02-05 21:29:28 -0800 | [diff] [blame] | 219 | wrpr %g0, 1, %tl |
| 220 | 661: nop |
David S. Miller | df7d6ae | 2006-02-07 00:00:16 -0800 | [diff] [blame] | 221 | .section .sun4v_1insn_patch, "ax" |
David S. Miller | 936f482 | 2006-02-05 21:29:28 -0800 | [diff] [blame] | 222 | .word 661b |
| 223 | SET_GL(1) |
| 224 | .previous |
| 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | rdpr %tstate, %g1 |
| 227 | sub %g2, STACKFRAME_SZ + TRACEREG_SZ - STACK_BIAS, %g2 |
| 228 | ba,pt %xcc, 1b |
| 229 | andcc %g1, TSTATE_PRIV, %g0 |
| 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | #undef TASK_REGOFF |
| 232 | #undef ETRAP_PSTATE1 |