vserver 1.9.5.x5
[linux-2.6.git] / arch / sparc64 / kernel / trampoline.S
1 /* $Id: trampoline.S,v 1.26 2002/02/09 19:49:30 davem Exp $
2  * trampoline.S: Jump start slave processors on sparc64.
3  *
4  * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
5  */
6
7 #include <asm/head.h>
8 #include <asm/asi.h>
9 #include <asm/lsu.h>
10 #include <asm/dcr.h>
11 #include <asm/dcu.h>
12 #include <asm/pstate.h>
13 #include <asm/page.h>
14 #include <asm/pgtable.h>
15 #include <asm/spitfire.h>
16 #include <asm/processor.h>
17 #include <asm/thread_info.h>
18
19         .data
20         .align  8
21 call_method:
22         .asciz  "call-method"
23         .align  8
24 itlb_load:
25         .asciz  "SUNW,itlb-load"
26         .align  8
27 dtlb_load:
28         .asciz  "SUNW,dtlb-load"
29
30         .text
31         .align          8
32         .globl          sparc64_cpu_startup, sparc64_cpu_startup_end
33 sparc64_cpu_startup:
34         flushw
35
36         BRANCH_IF_CHEETAH_BASE(g1,g5,cheetah_startup)
37         BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1,g5,cheetah_plus_startup)
38
39         ba,pt   %xcc, spitfire_startup
40          nop
41
42 cheetah_plus_startup:
43         /* Preserve OBP chosen DCU and DCR register settings.  */
44         ba,pt   %xcc, cheetah_generic_startup
45          nop
46
47 cheetah_startup:
48         mov     DCR_BPE | DCR_RPE | DCR_SI | DCR_IFPOE | DCR_MS, %g1
49         wr      %g1, %asr18
50
51         sethi   %uhi(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g5
52         or      %g5, %ulo(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g5
53         sllx    %g5, 32, %g5
54         or      %g5, DCU_DM | DCU_IM | DCU_DC | DCU_IC, %g5
55         stxa    %g5, [%g0] ASI_DCU_CONTROL_REG
56         membar  #Sync
57
58 cheetah_generic_startup:
59         mov     TSB_EXTENSION_P, %g3
60         stxa    %g0, [%g3] ASI_DMMU
61         stxa    %g0, [%g3] ASI_IMMU
62         membar  #Sync
63
64         mov     TSB_EXTENSION_S, %g3
65         stxa    %g0, [%g3] ASI_DMMU
66         membar  #Sync
67
68         mov     TSB_EXTENSION_N, %g3
69         stxa    %g0, [%g3] ASI_DMMU
70         stxa    %g0, [%g3] ASI_IMMU
71         membar  #Sync
72
73         /* Disable STICK_INT interrupts. */
74         sethi           %hi(0x80000000), %g5
75         sllx            %g5, 32, %g5
76         wr              %g5, %asr25
77
78         ba,pt           %xcc, startup_continue
79          nop
80
81 spitfire_startup:
82         mov             (LSU_CONTROL_IC | LSU_CONTROL_DC | LSU_CONTROL_IM | LSU_CONTROL_DM), %g1
83         stxa            %g1, [%g0] ASI_LSU_CONTROL
84         membar          #Sync
85
86 startup_continue:
87         wrpr            %g0, 15, %pil
88
89         sethi           %hi(0x80000000), %g2
90         sllx            %g2, 32, %g2
91         wr              %g2, 0, %tick_cmpr
92
93         /* Call OBP by hand to lock KERNBASE into i/d tlbs.
94          * We lock 2 consequetive entries if we are 'bigkernel'.
95          */
96         mov             %o0, %l0
97
98         sethi           %hi(prom_entry_lock), %g2
99 1:      ldstub          [%g2 + %lo(prom_entry_lock)], %g1
100         brnz,pn         %g1, 1b
101          membar         #StoreLoad | #StoreStore
102
103         sethi           %hi(p1275buf), %g2
104         or              %g2, %lo(p1275buf), %g2
105         ldx             [%g2 + 0x10], %l2
106         mov             %sp, %l1
107         add             %l2, -(192 + 128), %sp
108         flushw
109
110         sethi           %hi(call_method), %g2
111         or              %g2, %lo(call_method), %g2
112         stx             %g2, [%sp + 2047 + 128 + 0x00]
113         mov             5, %g2
114         stx             %g2, [%sp + 2047 + 128 + 0x08]
115         mov             1, %g2
116         stx             %g2, [%sp + 2047 + 128 + 0x10]
117         sethi           %hi(itlb_load), %g2
118         or              %g2, %lo(itlb_load), %g2
119         stx             %g2, [%sp + 2047 + 128 + 0x18]
120         sethi           %hi(mmu_ihandle_cache), %g2
121         lduw            [%g2 + %lo(mmu_ihandle_cache)], %g2
122         stx             %g2, [%sp + 2047 + 128 + 0x20]
123         sethi           %hi(KERNBASE), %g2
124         stx             %g2, [%sp + 2047 + 128 + 0x28]
125         sethi           %hi(kern_locked_tte_data), %g2
126         ldx             [%g2 + %lo(kern_locked_tte_data)], %g2
127         stx             %g2, [%sp + 2047 + 128 + 0x30]
128
129         mov             15, %g2
130         BRANCH_IF_ANY_CHEETAH(g1,g5,1f)
131
132         mov             63, %g2
133 1:
134         stx             %g2, [%sp + 2047 + 128 + 0x38]
135         sethi           %hi(p1275buf), %g2
136         or              %g2, %lo(p1275buf), %g2
137         ldx             [%g2 + 0x08], %o1
138         call            %o1
139          add            %sp, (2047 + 128), %o0
140
141         sethi           %hi(bigkernel), %g2
142         lduw            [%g2 + %lo(bigkernel)], %g2
143         cmp             %g2, 0
144         be,pt           %icc, do_dtlb
145          nop
146
147         sethi           %hi(call_method), %g2
148         or              %g2, %lo(call_method), %g2
149         stx             %g2, [%sp + 2047 + 128 + 0x00]
150         mov             5, %g2
151         stx             %g2, [%sp + 2047 + 128 + 0x08]
152         mov             1, %g2
153         stx             %g2, [%sp + 2047 + 128 + 0x10]
154         sethi           %hi(itlb_load), %g2
155         or              %g2, %lo(itlb_load), %g2
156         stx             %g2, [%sp + 2047 + 128 + 0x18]
157         sethi           %hi(mmu_ihandle_cache), %g2
158         lduw            [%g2 + %lo(mmu_ihandle_cache)], %g2
159         stx             %g2, [%sp + 2047 + 128 + 0x20]
160         sethi           %hi(KERNBASE + 0x400000), %g2
161         stx             %g2, [%sp + 2047 + 128 + 0x28]
162         sethi           %hi(kern_locked_tte_data), %g2
163         ldx             [%g2 + %lo(kern_locked_tte_data)], %g2
164         sethi           %hi(0x400000), %g1
165         add             %g2, %g1, %g2
166         stx             %g2, [%sp + 2047 + 128 + 0x30]
167
168         mov             14, %g2
169         BRANCH_IF_ANY_CHEETAH(g1,g5,1f)
170
171         mov             62, %g2
172 1:
173         stx             %g2, [%sp + 2047 + 128 + 0x38]
174         sethi           %hi(p1275buf), %g2
175         or              %g2, %lo(p1275buf), %g2
176         ldx             [%g2 + 0x08], %o1
177         call            %o1
178          add            %sp, (2047 + 128), %o0
179
180 do_dtlb:
181         sethi           %hi(call_method), %g2
182         or              %g2, %lo(call_method), %g2
183         stx             %g2, [%sp + 2047 + 128 + 0x00]
184         mov             5, %g2
185         stx             %g2, [%sp + 2047 + 128 + 0x08]
186         mov             1, %g2
187         stx             %g2, [%sp + 2047 + 128 + 0x10]
188         sethi           %hi(dtlb_load), %g2
189         or              %g2, %lo(dtlb_load), %g2
190         stx             %g2, [%sp + 2047 + 128 + 0x18]
191         sethi           %hi(mmu_ihandle_cache), %g2
192         lduw            [%g2 + %lo(mmu_ihandle_cache)], %g2
193         stx             %g2, [%sp + 2047 + 128 + 0x20]
194         sethi           %hi(KERNBASE), %g2
195         stx             %g2, [%sp + 2047 + 128 + 0x28]
196         sethi           %hi(kern_locked_tte_data), %g2
197         ldx             [%g2 + %lo(kern_locked_tte_data)], %g2
198         stx             %g2, [%sp + 2047 + 128 + 0x30]
199
200         mov             15, %g2
201         BRANCH_IF_ANY_CHEETAH(g1,g5,1f)
202
203         mov             63, %g2
204 1:
205
206         stx             %g2, [%sp + 2047 + 128 + 0x38]
207         sethi           %hi(p1275buf), %g2
208         or              %g2, %lo(p1275buf), %g2
209         ldx             [%g2 + 0x08], %o1
210         call            %o1
211          add            %sp, (2047 + 128), %o0
212
213         sethi           %hi(bigkernel), %g2
214         lduw            [%g2 + %lo(bigkernel)], %g2
215         cmp             %g2, 0
216         be,pt           %icc, do_unlock
217          nop
218
219         sethi           %hi(call_method), %g2
220         or              %g2, %lo(call_method), %g2
221         stx             %g2, [%sp + 2047 + 128 + 0x00]
222         mov             5, %g2
223         stx             %g2, [%sp + 2047 + 128 + 0x08]
224         mov             1, %g2
225         stx             %g2, [%sp + 2047 + 128 + 0x10]
226         sethi           %hi(dtlb_load), %g2
227         or              %g2, %lo(dtlb_load), %g2
228         stx             %g2, [%sp + 2047 + 128 + 0x18]
229         sethi           %hi(mmu_ihandle_cache), %g2
230         lduw            [%g2 + %lo(mmu_ihandle_cache)], %g2
231         stx             %g2, [%sp + 2047 + 128 + 0x20]
232         sethi           %hi(KERNBASE + 0x400000), %g2
233         stx             %g2, [%sp + 2047 + 128 + 0x28]
234         sethi           %hi(kern_locked_tte_data), %g2
235         ldx             [%g2 + %lo(kern_locked_tte_data)], %g2
236         sethi           %hi(0x400000), %g1
237         add             %g2, %g1, %g2
238         stx             %g2, [%sp + 2047 + 128 + 0x30]
239
240         mov             14, %g2
241         BRANCH_IF_ANY_CHEETAH(g1,g5,1f)
242
243         mov             62, %g2
244 1:
245
246         stx             %g2, [%sp + 2047 + 128 + 0x38]
247         sethi           %hi(p1275buf), %g2
248         or              %g2, %lo(p1275buf), %g2
249         ldx             [%g2 + 0x08], %o1
250         call            %o1
251          add            %sp, (2047 + 128), %o0
252
253 do_unlock:
254         sethi           %hi(prom_entry_lock), %g2
255         stb             %g0, [%g2 + %lo(prom_entry_lock)]
256         membar          #StoreStore | #StoreLoad
257
258         mov             %l1, %sp
259         flushw
260
261         mov             %l0, %o0
262
263         wrpr            %g0, (PSTATE_PRIV | PSTATE_PEF), %pstate
264         wr              %g0, 0, %fprs
265
266         /* XXX Buggy PROM... */
267         srl             %o0, 0, %o0
268         ldx             [%o0], %g6
269
270         wr              %g0, ASI_P, %asi
271
272         mov             PRIMARY_CONTEXT, %g7
273         stxa            %g0, [%g7] ASI_DMMU
274         membar          #Sync
275         mov             SECONDARY_CONTEXT, %g7
276         stxa            %g0, [%g7] ASI_DMMU
277         membar          #Sync
278
279         mov             1, %g5
280         sllx            %g5, THREAD_SHIFT, %g5
281         sub             %g5, (STACKFRAME_SZ + STACK_BIAS), %g5
282         add             %g6, %g5, %sp
283         mov             0, %fp
284
285         wrpr            %g0, 0, %wstate
286         wrpr            %g0, 0, %tl
287
288         /* Setup the trap globals, then we can resurface. */
289         rdpr            %pstate, %o1
290         mov             %g6, %o2
291         wrpr            %o1, PSTATE_AG, %pstate
292         sethi           %hi(sparc64_ttable_tl0), %g5
293         wrpr            %g5, %tba
294         mov             %o2, %g6
295
296         wrpr            %o1, PSTATE_MG, %pstate
297 #define KERN_HIGHBITS           ((_PAGE_VALID|_PAGE_SZ4MB)^0xfffff80000000000)
298 #define KERN_LOWBITS            (_PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_W)
299
300         mov             TSB_REG, %g1
301         stxa            %g0, [%g1] ASI_DMMU
302         membar          #Sync
303         mov             TLB_SFSR, %g1
304         sethi           %uhi(KERN_HIGHBITS), %g2
305         or              %g2, %ulo(KERN_HIGHBITS), %g2
306         sllx            %g2, 32, %g2
307         or              %g2, KERN_LOWBITS, %g2
308
309         BRANCH_IF_ANY_CHEETAH(g3,g7,9f)
310
311         ba,pt           %xcc, 1f
312          nop
313
314 9:
315         sethi           %uhi(VPTE_BASE_CHEETAH), %g3
316         or              %g3, %ulo(VPTE_BASE_CHEETAH), %g3
317         ba,pt           %xcc, 2f
318          sllx           %g3, 32, %g3
319 1:
320         sethi           %uhi(VPTE_BASE_SPITFIRE), %g3
321         or              %g3, %ulo(VPTE_BASE_SPITFIRE), %g3
322         sllx            %g3, 32, %g3
323
324 2:
325         clr     %g7
326 #undef KERN_HIGHBITS
327 #undef KERN_LOWBITS
328
329         wrpr            %o1, 0x0, %pstate
330         ldx             [%g6 + TI_TASK], %g4
331
332         wrpr            %g0, 0, %wstate
333
334         call            init_irqwork_curcpu
335          nop
336
337         rdpr            %pstate, %o1
338         or              %o1, PSTATE_IE, %o1
339         wrpr            %o1, 0, %pstate
340
341         call            prom_set_trap_table
342          sethi          %hi(sparc64_ttable_tl0), %o0
343
344         call            smp_callin
345          nop
346         call            cpu_idle
347          mov            0, %o0
348         call            cpu_panic
349          nop
350 1:      b,a,pt          %xcc, 1b
351
352         .align          8
353 sparc64_cpu_startup_end: