[SPARC64]: Fix branch signedness bug in all code patching.
[linux-2.6] / arch / sparc64 / kernel / ktlb.S
1 /* arch/sparc64/kernel/ktlb.S: Kernel mapping TLB miss handling.
2  *
3  * Copyright (C) 1995, 1997, 2005 David S. Miller <davem@davemloft.net>
4  * Copyright (C) 1996 Eddie C. Dost        (ecd@brainaid.de)
5  * Copyright (C) 1996 Miguel de Icaza      (miguel@nuclecu.unam.mx)
6  * Copyright (C) 1996,98,99 Jakub Jelinek  (jj@sunsite.mff.cuni.cz)
7  */
8
9 #include <linux/config.h>
10 #include <asm/head.h>
11 #include <asm/asi.h>
12 #include <asm/page.h>
13 #include <asm/pgtable.h>
14 #include <asm/tsb.h>
15
16         .text
17         .align          32
18
19 kvmap_itlb:
20         /* g6: TAG TARGET */
21         mov             TLB_TAG_ACCESS, %g4
22         ldxa            [%g4] ASI_IMMU, %g4
23
24         /* sun4v_itlb_miss branches here with the missing virtual
25          * address already loaded into %g4
26          */
27 kvmap_itlb_4v:
28
29 kvmap_itlb_nonlinear:
30         /* Catch kernel NULL pointer calls.  */
31         sethi           %hi(PAGE_SIZE), %g5
32         cmp             %g4, %g5
33         bleu,pn         %xcc, kvmap_dtlb_longpath
34          nop
35
36         KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_itlb_load)
37
38 kvmap_itlb_tsb_miss:
39         sethi           %hi(LOW_OBP_ADDRESS), %g5
40         cmp             %g4, %g5
41         blu,pn          %xcc, kvmap_itlb_vmalloc_addr
42          mov            0x1, %g5
43         sllx            %g5, 32, %g5
44         cmp             %g4, %g5
45         blu,pn          %xcc, kvmap_itlb_obp
46          nop
47
48 kvmap_itlb_vmalloc_addr:
49         KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_itlb_longpath)
50
51         KTSB_LOCK_TAG(%g1, %g2, %g7)
52
53         /* Load and check PTE.  */
54         ldxa            [%g5] ASI_PHYS_USE_EC, %g5
55         brgez,a,pn      %g5, kvmap_itlb_longpath
56          KTSB_STORE(%g1, %g0)
57
58         KTSB_WRITE(%g1, %g5, %g6)
59
60         /* fallthrough to TLB load */
61
62 kvmap_itlb_load:
63
64 661:    stxa            %g5, [%g0] ASI_ITLB_DATA_IN
65         retry
66         .section        .sun4v_2insn_patch, "ax"
67         .word           661b
68         nop
69         nop
70         .previous
71
72         /* For sun4v the ASI_ITLB_DATA_IN store and the retry
73          * instruction get nop'd out and we get here to branch
74          * to the sun4v tlb load code.  The registers are setup
75          * as follows:
76          *
77          * %g4: vaddr
78          * %g5: PTE
79          * %g6: TAG
80          *
81          * The sun4v TLB load wants the PTE in %g3 so we fix that
82          * up here.
83          */
84         ba,pt           %xcc, sun4v_itlb_load
85          mov            %g5, %g3
86
87 kvmap_itlb_longpath:
88
89 661:    rdpr    %pstate, %g5
90         wrpr    %g5, PSTATE_AG | PSTATE_MG, %pstate
91         .section .sun4v_2insn_patch, "ax"
92         .word   661b
93         nop
94         nop
95         .previous
96
97         rdpr    %tpc, %g5
98         ba,pt   %xcc, sparc64_realfault_common
99          mov    FAULT_CODE_ITLB, %g4
100
101 kvmap_itlb_obp:
102         OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_itlb_longpath)
103
104         KTSB_LOCK_TAG(%g1, %g2, %g7)
105
106         KTSB_WRITE(%g1, %g5, %g6)
107
108         ba,pt           %xcc, kvmap_itlb_load
109          nop
110
111 kvmap_dtlb_obp:
112         OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_dtlb_longpath)
113
114         KTSB_LOCK_TAG(%g1, %g2, %g7)
115
116         KTSB_WRITE(%g1, %g5, %g6)
117
118         ba,pt           %xcc, kvmap_dtlb_load
119          nop
120
121         .align          32
122 kvmap_dtlb:
123         /* %g6: TAG TARGET */
124         mov             TLB_TAG_ACCESS, %g4
125         ldxa            [%g4] ASI_DMMU, %g4
126
127         /* sun4v_dtlb_miss branches here with the missing virtual
128          * address already loaded into %g4
129          */
130 kvmap_dtlb_4v:
131         brgez,pn        %g4, kvmap_dtlb_nonlinear
132          nop
133
134         sethi           %hi(kern_linear_pte_xor), %g2
135         ldx             [%g2 + %lo(kern_linear_pte_xor)], %g2
136
137         .globl          kvmap_linear_patch
138 kvmap_linear_patch:
139         ba,pt           %xcc, kvmap_dtlb_load
140          xor            %g2, %g4, %g5
141
142 kvmap_dtlb_vmalloc_addr:
143         KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
144
145         KTSB_LOCK_TAG(%g1, %g2, %g7)
146
147         /* Load and check PTE.  */
148         ldxa            [%g5] ASI_PHYS_USE_EC, %g5
149         brgez,a,pn      %g5, kvmap_dtlb_longpath
150          KTSB_STORE(%g1, %g0)
151
152         KTSB_WRITE(%g1, %g5, %g6)
153
154         /* fallthrough to TLB load */
155
156 kvmap_dtlb_load:
157
158 661:    stxa            %g5, [%g0] ASI_DTLB_DATA_IN     ! Reload TLB
159         retry
160         .section        .sun4v_2insn_patch, "ax"
161         .word           661b
162         nop
163         nop
164         .previous
165
166         /* For sun4v the ASI_DTLB_DATA_IN store and the retry
167          * instruction get nop'd out and we get here to branch
168          * to the sun4v tlb load code.  The registers are setup
169          * as follows:
170          *
171          * %g4: vaddr
172          * %g5: PTE
173          * %g6: TAG
174          *
175          * The sun4v TLB load wants the PTE in %g3 so we fix that
176          * up here.
177          */
178         ba,pt           %xcc, sun4v_dtlb_load
179          mov            %g5, %g3
180
181 kvmap_dtlb_nonlinear:
182         /* Catch kernel NULL pointer derefs.  */
183         sethi           %hi(PAGE_SIZE), %g5
184         cmp             %g4, %g5
185         bleu,pn         %xcc, kvmap_dtlb_longpath
186          nop
187
188         KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
189
190 kvmap_dtlb_tsbmiss:
191         sethi           %hi(MODULES_VADDR), %g5
192         cmp             %g4, %g5
193         blu,pn          %xcc, kvmap_dtlb_longpath
194          mov            (VMALLOC_END >> 24), %g5
195         sllx            %g5, 24, %g5
196         cmp             %g4, %g5
197         bgeu,pn         %xcc, kvmap_dtlb_longpath
198          nop
199
200 kvmap_check_obp:
201         sethi           %hi(LOW_OBP_ADDRESS), %g5
202         cmp             %g4, %g5
203         blu,pn          %xcc, kvmap_dtlb_vmalloc_addr
204          mov            0x1, %g5
205         sllx            %g5, 32, %g5
206         cmp             %g4, %g5
207         blu,pn          %xcc, kvmap_dtlb_obp
208          nop
209         ba,pt           %xcc, kvmap_dtlb_vmalloc_addr
210          nop
211
212 kvmap_dtlb_longpath:
213
214 661:    rdpr    %pstate, %g5
215         wrpr    %g5, PSTATE_AG | PSTATE_MG, %pstate
216         .section .sun4v_2insn_patch, "ax"
217         .word   661b
218         nop
219         nop
220         .previous
221
222         rdpr    %tl, %g3
223         cmp     %g3, 1
224
225 661:    mov     TLB_TAG_ACCESS, %g4
226         ldxa    [%g4] ASI_DMMU, %g5
227         .section .sun4v_2insn_patch, "ax"
228         .word   661b
229         mov     %g4, %g5
230         nop
231         .previous
232
233         be,pt   %xcc, sparc64_realfault_common
234          mov    FAULT_CODE_DTLB, %g4
235         ba,pt   %xcc, winfix_trampoline
236          nop