VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / arch / sparc64 / kernel / head.S
1 /* $Id: head.S,v 1.87 2002/02/09 19:49:31 davem Exp $
2  * head.S: Initial boot code for the Sparc64 port of Linux.
3  *
4  * Copyright (C) 1996,1997 David S. Miller (davem@caip.rutgers.edu)
5  * Copyright (C) 1996 David Sitsky (David.Sitsky@anu.edu.au)
6  * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7  * Copyright (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx)
8  */
9
10 #include <linux/config.h>
11 #include <linux/version.h>
12 #include <linux/errno.h>
13 #include <asm/thread_info.h>
14 #include <asm/asi.h>
15 #include <asm/pstate.h>
16 #include <asm/ptrace.h>
17 #include <asm/spitfire.h>
18 #include <asm/page.h>
19 #include <asm/pgtable.h>
20 #include <asm/errno.h>
21 #include <asm/signal.h>
22 #include <asm/processor.h>
23 #include <asm/lsu.h>
24 #include <asm/dcr.h>
25 #include <asm/dcu.h>
26 #include <asm/head.h>
27 #include <asm/ttable.h>
28         
29 /* This section from from _start to sparc64_boot_end should fit into
30  * 0x0000.0000.0040.4000 to 0x0000.0000.0040.8000 and will be sharing space
31  * with bootup_user_stack, which is from 0x0000.0000.0040.4000 to
32  * 0x0000.0000.0040.6000 and empty_bad_page, which is from
33  * 0x0000.0000.0040.6000 to 0x0000.0000.0040.8000. 
34  */
35
36         .text
37         .globl  start, _start, stext, _stext
38 _start:
39 start:
40 _stext:
41 stext:
42 bootup_user_stack:
43 ! 0x0000000000404000
44         b       sparc64_boot
45          flushw                                 /* Flush register file.      */
46
47 /* This stuff has to be in sync with SILO and other potential boot loaders
48  * Fields should be kept upward compatible and whenever any change is made,
49  * HdrS version should be incremented.
50  */
51         .global root_flags, ram_flags, root_dev
52         .global sparc_ramdisk_image, sparc_ramdisk_size
53
54         .ascii  "HdrS"
55         .word   LINUX_VERSION_CODE
56
57         /* History:
58          *
59          * 0x0300 : Supports being located at other than 0x4000
60          * 0x0202 : Supports kernel params string
61          * 0x0201 : Supports reboot_command
62          */
63         .half   0x0300          /* HdrS version */
64
65 root_flags:
66         .half   1
67 root_dev:
68         .half   0
69 ram_flags:
70         .half   0
71 sparc_ramdisk_image:
72         .word   0
73 sparc_ramdisk_size:
74         .word   0
75         .xword  reboot_command
76         .xword  bootstr_info
77         .word   _end
78
79         /* We must be careful, 32-bit OpenBOOT will get confused if it
80          * tries to save away a register window to a 64-bit kernel
81          * stack address.  Flush all windows, disable interrupts,
82          * remap if necessary, jump onto kernel trap table, then kernel
83          * stack, or else we die.
84          *
85          * PROM entry point is on %o4
86          */
87 sparc64_boot:
88         BRANCH_IF_CHEETAH_BASE(g1,g5,cheetah_boot)
89         BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1,g5,cheetah_plus_boot)
90         ba,pt   %xcc, spitfire_boot
91          nop
92
93 cheetah_plus_boot:
94         /* Preserve OBP chosen DCU and DCR register settings.  */
95         ba,pt   %xcc, cheetah_generic_boot
96          nop
97
98 cheetah_boot:
99         mov     DCR_BPE | DCR_RPE | DCR_SI | DCR_IFPOE | DCR_MS, %g1
100         wr      %g1, %asr18
101
102         sethi   %uhi(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g5
103         or      %g5, %ulo(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g5
104         sllx    %g5, 32, %g5
105         or      %g5, DCU_DM | DCU_IM | DCU_DC | DCU_IC, %g5
106         stxa    %g5, [%g0] ASI_DCU_CONTROL_REG
107         membar  #Sync
108
109 cheetah_generic_boot:
110         mov     TSB_EXTENSION_P, %g3
111         stxa    %g0, [%g3] ASI_DMMU
112         stxa    %g0, [%g3] ASI_IMMU
113         membar  #Sync
114
115         mov     TSB_EXTENSION_S, %g3
116         stxa    %g0, [%g3] ASI_DMMU
117         membar  #Sync
118
119         mov     TSB_EXTENSION_N, %g3
120         stxa    %g0, [%g3] ASI_DMMU
121         stxa    %g0, [%g3] ASI_IMMU
122         membar  #Sync
123
124         wrpr    %g0, (PSTATE_PRIV|PSTATE_PEF|PSTATE_IE), %pstate
125         wr      %g0, 0, %fprs
126
127         /* Just like for Spitfire, we probe itlb-2 for a mapping which
128          * matches our current %pc.  We take the physical address in
129          * that mapping and use it to make our own.
130          */
131
132         /* %g5 holds the tlb data */
133         sethi   %uhi(_PAGE_VALID | _PAGE_SZ4MB), %g5
134         sllx    %g5, 32, %g5
135         or      %g5, (_PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_L | _PAGE_W | _PAGE_G), %g5
136
137         /* Put PADDR tlb data mask into %g3. */
138         sethi   %uhi(_PAGE_PADDR), %g3
139         or      %g3, %ulo(_PAGE_PADDR), %g3
140         sllx    %g3, 32, %g3
141         sethi   %hi(_PAGE_PADDR), %g7
142         or      %g7, %lo(_PAGE_PADDR), %g7
143         or      %g3, %g7, %g3
144
145         set     2 << 16, %l0            /* TLB entry walker. */
146         set     0x1fff, %l2             /* Page mask. */
147         rd      %pc, %l3
148         andn    %l3, %l2, %g2           /* vaddr comparator */
149
150 1:      ldxa    [%l0] ASI_ITLB_TAG_READ, %g1
151         membar  #Sync
152         andn    %g1, %l2, %g1
153         cmp     %g1, %g2
154         be,pn   %xcc, cheetah_got_tlbentry
155          nop
156         and     %l0, (127 << 3), %g1
157         cmp     %g1, (127 << 3)
158         blu,pt  %xcc, 1b
159          add    %l0, (1 << 3), %l0
160
161         /* Search the small TLB.  OBP never maps us like that but
162          * newer SILO can.
163          */
164         clr     %l0
165
166 1:      ldxa    [%l0] ASI_ITLB_TAG_READ, %g1
167         membar  #Sync
168         andn    %g1, %l2, %g1
169         cmp     %g1, %g2
170         be,pn   %xcc, cheetah_got_tlbentry
171          nop
172         cmp     %l0, (15 << 3)
173         blu,pt  %xcc, 1b
174          add    %l0, (1 << 3), %l0
175
176         /* BUG() if we get here... */
177         ta      0x5
178
179 cheetah_got_tlbentry:
180         ldxa    [%l0] ASI_ITLB_DATA_ACCESS, %g0
181         ldxa    [%l0] ASI_ITLB_DATA_ACCESS, %g1
182         membar  #Sync
183         and     %g1, %g3, %g1
184         set     0x5fff, %l0
185         andn    %g1, %l0, %g1
186         or      %g5, %g1, %g5
187
188         /* Clear out any KERNBASE area entries. */
189         set     2 << 16, %l0
190         sethi   %hi(KERNBASE), %g3
191         sethi   %hi(KERNBASE<<1), %g7
192         mov     TLB_TAG_ACCESS, %l7
193
194         /* First, check ITLB */
195 1:      ldxa    [%l0] ASI_ITLB_TAG_READ, %g1
196         membar  #Sync
197         andn    %g1, %l2, %g1
198         cmp     %g1, %g3
199         blu,pn  %xcc, 2f
200          cmp    %g1, %g7
201         bgeu,pn %xcc, 2f
202          nop
203         stxa    %g0, [%l7] ASI_IMMU
204         membar  #Sync
205         stxa    %g0, [%l0] ASI_ITLB_DATA_ACCESS
206         membar  #Sync
207
208 2:      and     %l0, (127 << 3), %g1
209         cmp     %g1, (127 << 3)
210         blu,pt  %xcc, 1b
211          add    %l0, (1 << 3), %l0
212
213         /* Next, check DTLB */
214         set     2 << 16, %l0
215 1:      ldxa    [%l0] ASI_DTLB_TAG_READ, %g1
216         membar  #Sync
217         andn    %g1, %l2, %g1
218         cmp     %g1, %g3
219         blu,pn  %xcc, 2f
220          cmp    %g1, %g7
221         bgeu,pn %xcc, 2f
222          nop
223         stxa    %g0, [%l7] ASI_DMMU
224         membar  #Sync
225         stxa    %g0, [%l0] ASI_DTLB_DATA_ACCESS
226         membar  #Sync
227         
228 2:      and     %l0, (511 << 3), %g1
229         cmp     %g1, (511 << 3)
230         blu,pt  %xcc, 1b
231          add    %l0, (1 << 3), %l0
232
233         /* On Cheetah+, have to check second DTLB.  */
234         BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1,l0,2f)
235         ba,pt   %xcc, 9f
236          nop
237
238 2:      set     3 << 16, %l0
239 1:      ldxa    [%l0] ASI_DTLB_TAG_READ, %g1
240         membar  #Sync
241         andn    %g1, %l2, %g1
242         cmp     %g1, %g3
243         blu,pn  %xcc, 2f
244          cmp    %g1, %g7
245         bgeu,pn %xcc, 2f
246          nop
247         stxa    %g0, [%l7] ASI_DMMU
248         membar  #Sync
249         stxa    %g0, [%l0] ASI_DTLB_DATA_ACCESS
250         membar  #Sync
251         
252 2:      and     %l0, (511 << 3), %g1
253         cmp     %g1, (511 << 3)
254         blu,pt  %xcc, 1b
255          add    %l0, (1 << 3), %l0
256
257 9:
258
259         /* Now lock the TTE we created into ITLB-0 and DTLB-0,
260          * entry 15 (and maybe 14 too).
261          */
262         sethi   %hi(KERNBASE), %g3
263         set     (0 << 16) | (15 << 3), %g7
264         stxa    %g3, [%l7] ASI_DMMU
265         membar  #Sync
266         stxa    %g5, [%g7] ASI_DTLB_DATA_ACCESS
267         membar  #Sync
268         stxa    %g3, [%l7] ASI_IMMU
269         membar  #Sync
270         stxa    %g5, [%g7] ASI_ITLB_DATA_ACCESS
271         membar  #Sync
272         flush   %g3
273         membar  #Sync
274         sethi   %hi(_end), %g3                  /* Check for bigkernel case */
275         or      %g3, %lo(_end), %g3
276         srl     %g3, 23, %g3                    /* Check if _end > 8M */
277         brz,pt  %g3, 1f
278          sethi  %hi(KERNBASE), %g3              /* Restore for fixup code below */
279         sethi   %hi(0x400000), %g3
280         or      %g3, %lo(0x400000), %g3
281         add     %g5, %g3, %g5                   /* New tte data */
282         andn    %g5, (_PAGE_G), %g5
283         sethi   %hi(KERNBASE+0x400000), %g3
284         or      %g3, %lo(KERNBASE+0x400000), %g3
285         set     (0 << 16) | (14 << 3), %g7
286         stxa    %g3, [%l7] ASI_DMMU
287         membar  #Sync
288         stxa    %g5, [%g7] ASI_DTLB_DATA_ACCESS
289         membar  #Sync
290         stxa    %g3, [%l7] ASI_IMMU
291         membar  #Sync
292         stxa    %g5, [%g7] ASI_ITLB_DATA_ACCESS
293         membar  #Sync
294         flush   %g3
295         membar  #Sync
296         sethi   %hi(KERNBASE), %g3              /* Restore for fixup code below */
297         ba,pt   %xcc, 1f
298          nop
299
300 1:      set     sun4u_init, %g2
301         jmpl    %g2 + %g0, %g0
302          nop
303
304 spitfire_boot:
305         /* Typically PROM has already enabled both MMU's and both on-chip
306          * caches, but we do it here anyway just to be paranoid.
307          */
308         mov     (LSU_CONTROL_IC|LSU_CONTROL_DC|LSU_CONTROL_IM|LSU_CONTROL_DM), %g1
309         stxa    %g1, [%g0] ASI_LSU_CONTROL
310         membar  #Sync
311
312         /*
313          * Make sure we are in privileged mode, have address masking,
314          * using the ordinary globals and have enabled floating
315          * point.
316          *
317          * Again, typically PROM has left %pil at 13 or similar, and
318          * (PSTATE_PRIV | PSTATE_PEF | PSTATE_IE) in %pstate.
319          */
320         wrpr    %g0, (PSTATE_PRIV|PSTATE_PEF|PSTATE_IE), %pstate
321         wr      %g0, 0, %fprs
322
323 spitfire_create_mappings:
324         /* %g5 holds the tlb data */
325         sethi   %uhi(_PAGE_VALID | _PAGE_SZ4MB), %g5
326         sllx    %g5, 32, %g5
327         or      %g5, (_PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_L | _PAGE_W | _PAGE_G), %g5
328
329         /* Base of physical memory cannot reliably be assumed to be
330          * at 0x0!  Figure out where it happens to be. -DaveM
331          */
332
333         /* Put PADDR tlb data mask into %g3. */
334         sethi   %uhi(_PAGE_PADDR_SF), %g3
335         or      %g3, %ulo(_PAGE_PADDR_SF), %g3
336         sllx    %g3, 32, %g3
337         sethi   %hi(_PAGE_PADDR_SF), %g7
338         or      %g7, %lo(_PAGE_PADDR_SF), %g7
339         or      %g3, %g7, %g3
340
341         /* Walk through entire ITLB, looking for entry which maps
342          * our %pc currently, stick PADDR from there into %g5 tlb data.
343          */
344         clr     %l0                     /* TLB entry walker. */
345         set     0x1fff, %l2             /* Page mask. */
346         rd      %pc, %l3
347         andn    %l3, %l2, %g2           /* vaddr comparator */
348 1:
349         /* Yes, the nops seem to be necessary for now, don't ask me why. -DaveM */
350         ldxa    [%l0] ASI_ITLB_TAG_READ, %g1
351         nop
352         nop
353         nop
354         andn    %g1, %l2, %g1           /* Get vaddr */
355         cmp     %g1, %g2
356         be,a,pn %xcc, spitfire_got_tlbentry
357          ldxa   [%l0] ASI_ITLB_DATA_ACCESS, %g1
358         cmp     %l0, (63 << 3)
359         blu,pt  %xcc, 1b
360          add    %l0, (1 << 3), %l0
361
362         /* BUG() if we get here... */
363         ta      0x5
364
365 spitfire_got_tlbentry:
366         /* Nops here again, perhaps Cheetah/Blackbird are better behaved... */
367         nop
368         nop
369         nop
370         and     %g1, %g3, %g1           /* Mask to just get paddr bits.       */
371         set     0x5fff, %l3             /* Mask offset to get phys base.      */
372         andn    %g1, %l3, %g1
373
374         /* NOTE: We hold on to %g1 paddr base as we need it below to lock
375          * NOTE: the PROM cif code into the TLB.
376          */
377
378         or      %g5, %g1, %g5           /* Or it into TAG being built.        */
379
380         clr     %l0                     /* TLB entry walker. */
381         sethi   %hi(KERNBASE), %g3      /* 4M lower limit */
382         sethi   %hi(KERNBASE<<1), %g7   /* 8M upper limit */
383         mov     TLB_TAG_ACCESS, %l7
384 1:
385         /* Yes, the nops seem to be necessary for now, don't ask me why. -DaveM */
386         ldxa    [%l0] ASI_ITLB_TAG_READ, %g1
387         nop
388         nop
389         nop
390         andn    %g1, %l2, %g1           /* Get vaddr */
391         cmp     %g1, %g3
392         blu,pn  %xcc, 2f
393          cmp    %g1, %g7
394         bgeu,pn %xcc, 2f
395          nop
396         stxa    %g0, [%l7] ASI_IMMU
397         stxa    %g0, [%l0] ASI_ITLB_DATA_ACCESS
398         membar  #Sync
399 2:
400         cmp     %l0, (63 << 3)
401         blu,pt  %xcc, 1b
402          add    %l0, (1 << 3), %l0
403
404         nop; nop; nop
405
406         clr     %l0                     /* TLB entry walker. */
407 1:
408         /* Yes, the nops seem to be necessary for now, don't ask me why. -DaveM */
409         ldxa    [%l0] ASI_DTLB_TAG_READ, %g1
410         nop
411         nop
412         nop
413         andn    %g1, %l2, %g1           /* Get vaddr */
414         cmp     %g1, %g3
415         blu,pn  %xcc, 2f
416          cmp    %g1, %g7
417         bgeu,pn %xcc, 2f
418          nop
419         stxa    %g0, [%l7] ASI_DMMU
420         stxa    %g0, [%l0] ASI_DTLB_DATA_ACCESS
421         membar  #Sync
422 2:
423         cmp     %l0, (63 << 3)
424         blu,pt  %xcc, 1b
425          add    %l0, (1 << 3), %l0
426
427         nop; nop; nop
428
429
430         /* PROM never puts any TLB entries into the MMU with the lock bit
431          * set.  So we gladly use tlb entry 63 for KERNBASE. And maybe 62 too.
432          */
433
434         sethi   %hi(KERNBASE), %g3
435         mov     (63 << 3), %g7
436         stxa    %g3, [%l7] ASI_DMMU             /* KERNBASE into TLB TAG        */
437         stxa    %g5, [%g7] ASI_DTLB_DATA_ACCESS /* TTE into TLB DATA            */
438         membar  #Sync
439         stxa    %g3, [%l7] ASI_IMMU             /* KERNBASE into TLB TAG        */
440         stxa    %g5, [%g7] ASI_ITLB_DATA_ACCESS /* TTE into TLB DATA            */
441         membar  #Sync
442         flush   %g3
443         membar  #Sync
444         sethi   %hi(_end), %g3                  /* Check for bigkernel case */
445         or      %g3, %lo(_end), %g3
446         srl     %g3, 23, %g3                    /* Check if _end > 8M */
447         brz,pt  %g3, 2f
448          sethi  %hi(KERNBASE), %g3              /* Restore for fixup code below */
449         sethi   %hi(0x400000), %g3
450         or      %g3, %lo(0x400000), %g3
451         add     %g5, %g3, %g5                   /* New tte data */
452         andn    %g5, (_PAGE_G), %g5
453         sethi   %hi(KERNBASE+0x400000), %g3
454         or      %g3, %lo(KERNBASE+0x400000), %g3
455         mov     (62 << 3), %g7
456         stxa    %g3, [%l7] ASI_DMMU
457         stxa    %g5, [%g7] ASI_DTLB_DATA_ACCESS
458         membar  #Sync
459         stxa    %g3, [%l7] ASI_IMMU
460         stxa    %g5, [%g7] ASI_ITLB_DATA_ACCESS
461         membar  #Sync
462         flush   %g3
463         membar  #Sync
464         sethi   %hi(KERNBASE), %g3              /* Restore for fixup code below */
465 2:      ba,pt   %xcc, 1f
466          nop
467 1:
468         set     sun4u_init, %g2
469         jmpl    %g2 + %g0, %g0
470          nop
471
472 sun4u_init:
473         /* Set ctx 0 */
474         mov     PRIMARY_CONTEXT, %g7
475         stxa    %g0, [%g7] ASI_DMMU
476         membar  #Sync
477
478         mov     SECONDARY_CONTEXT, %g7
479         stxa    %g0, [%g7] ASI_DMMU
480         membar  #Sync
481
482         /* We are now safely (we hope) in Nucleus context (0), rewrite
483          * the KERNBASE TTE's so they no longer have the global bit set.
484          * Don't forget to setup TAG_ACCESS first 8-)
485          */
486         mov     TLB_TAG_ACCESS, %g2
487         stxa    %g3, [%g2] ASI_IMMU
488         stxa    %g3, [%g2] ASI_DMMU
489         membar  #Sync
490
491         BRANCH_IF_ANY_CHEETAH(g1,g5,cheetah_tlb_fixup)
492
493         ba,pt   %xcc, spitfire_tlb_fixup
494          nop
495
496 cheetah_tlb_fixup:
497         set     (0 << 16) | (15 << 3), %g7
498         ldxa    [%g7] ASI_ITLB_DATA_ACCESS, %g0
499         ldxa    [%g7] ASI_ITLB_DATA_ACCESS, %g1
500         andn    %g1, (_PAGE_G), %g1
501         stxa    %g1, [%g7] ASI_ITLB_DATA_ACCESS
502         membar  #Sync
503
504         ldxa    [%g7] ASI_DTLB_DATA_ACCESS, %g0
505         ldxa    [%g7] ASI_DTLB_DATA_ACCESS, %g1
506         andn    %g1, (_PAGE_G), %g1
507         stxa    %g1, [%g7] ASI_DTLB_DATA_ACCESS
508         membar  #Sync
509
510         /* Kill instruction prefetch queues. */
511         flush   %g3
512         membar  #Sync
513
514         mov     2, %g2          /* Set TLB type to cheetah+. */
515         BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g5,g7,1f)
516
517         mov     1, %g2          /* Set TLB type to cheetah. */
518
519 1:      sethi   %hi(tlb_type), %g5
520         stw     %g2, [%g5 + %lo(tlb_type)]
521
522         /* Patch copy/page operations to cheetah optimized versions. */
523         call    cheetah_patch_copyops
524          nop
525         call    cheetah_patch_cachetlbops
526          nop
527
528         ba,pt   %xcc, tlb_fixup_done
529          nop
530
531 spitfire_tlb_fixup:
532         mov     (63 << 3), %g7
533         ldxa    [%g7] ASI_ITLB_DATA_ACCESS, %g1
534         andn    %g1, (_PAGE_G), %g1
535         stxa    %g1, [%g7] ASI_ITLB_DATA_ACCESS
536         membar  #Sync
537
538         ldxa    [%g7] ASI_DTLB_DATA_ACCESS, %g1
539         andn    %g1, (_PAGE_G), %g1
540         stxa    %g1, [%g7] ASI_DTLB_DATA_ACCESS
541         membar  #Sync
542
543         /* Kill instruction prefetch queues. */
544         flush   %g3
545         membar  #Sync
546
547         /* Set TLB type to spitfire. */
548         mov     0, %g2
549         sethi   %hi(tlb_type), %g5
550         stw     %g2, [%g5 + %lo(tlb_type)]
551
552 tlb_fixup_done:
553         sethi   %hi(init_thread_union), %g6
554         or      %g6, %lo(init_thread_union), %g6
555         ldx     [%g6 + TI_TASK], %g4
556         mov     %sp, %l6
557         mov     %o4, %l7
558
559 #if 0   /* We don't do it like this anymore, but for historical hack value
560          * I leave this snippet here to show how crazy we can be sometimes. 8-)
561          */
562
563         /* Setup "Linux Current Register", thanks Sun 8-) */
564         wr      %g0, 0x1, %pcr
565
566         /* Blackbird errata workaround.  See commentary in
567          * smp.c:smp_percpu_timer_interrupt() for more
568          * information.
569          */
570         ba,pt   %xcc, 99f
571          nop
572         .align  64
573 99:     wr      %g6, %g0, %pic
574         rd      %pic, %g0
575 #endif
576
577         wr      %g0, ASI_P, %asi
578         mov     1, %g5
579         sllx    %g5, THREAD_SHIFT, %g5
580         sub     %g5, (STACKFRAME_SZ + STACK_BIAS), %g5
581         add     %g6, %g5, %sp
582         mov     0, %fp
583
584         wrpr    %g0, 0, %wstate
585         wrpr    %g0, 0x0, %tl
586
587         /* Clear the bss */
588         sethi   %hi(__bss_start), %o0
589         or      %o0, %lo(__bss_start), %o0
590         sethi   %hi(_end), %o1
591         or      %o1, %lo(_end), %o1
592         call    __bzero
593          sub    %o1, %o0, %o1
594
595         mov     %l6, %o1                        ! OpenPROM stack
596         call    prom_init
597          mov    %l7, %o0                        ! OpenPROM cif handler
598
599         /* Off we go.... */
600         call    start_kernel
601          nop
602         /* Not reached... */
603
604 /* IMPORTANT NOTE: Whenever making changes here, check
605  * trampoline.S as well. -jj */
606         .globl  setup_tba
607 setup_tba:      /* i0 = is_starfire */
608         save    %sp, -160, %sp
609
610         rdpr    %tba, %g7
611         sethi   %hi(prom_tba), %o1
612         or      %o1, %lo(prom_tba), %o1
613         stx     %g7, [%o1]
614
615         /* Setup "Linux" globals 8-) */
616         rdpr    %pstate, %o1
617         mov     %g6, %o2
618         wrpr    %o1, (PSTATE_AG|PSTATE_IE), %pstate
619         sethi   %hi(sparc64_ttable_tl0), %g5
620         wrpr    %g5, %tba
621         mov     %o2, %g6
622
623         /* Set up MMU globals */
624         wrpr    %o1, (PSTATE_MG|PSTATE_IE), %pstate
625
626         /* Set fixed globals used by dTLB miss handler. */
627 #define KERN_HIGHBITS           ((_PAGE_VALID|_PAGE_SZ4MB)^0xfffff80000000000)
628 #define KERN_LOWBITS            (_PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_W)
629
630         mov     TSB_REG, %g1
631         stxa    %g0, [%g1] ASI_DMMU
632         membar  #Sync
633         mov     TLB_SFSR, %g1
634         sethi   %uhi(KERN_HIGHBITS), %g2
635         or      %g2, %ulo(KERN_HIGHBITS), %g2
636         sllx    %g2, 32, %g2
637         or      %g2, KERN_LOWBITS, %g2
638
639         BRANCH_IF_ANY_CHEETAH(g3,g7,cheetah_vpte_base)
640         ba,pt   %xcc, spitfire_vpte_base
641          nop
642
643 cheetah_vpte_base:
644         sethi           %uhi(VPTE_BASE_CHEETAH), %g3
645         or              %g3, %ulo(VPTE_BASE_CHEETAH), %g3
646         ba,pt           %xcc, 2f
647          sllx           %g3, 32, %g3
648
649 spitfire_vpte_base:
650         sethi           %uhi(VPTE_BASE_SPITFIRE), %g3
651         or              %g3, %ulo(VPTE_BASE_SPITFIRE), %g3
652         sllx            %g3, 32, %g3
653
654 2:
655         clr     %g7
656 #undef KERN_HIGHBITS
657 #undef KERN_LOWBITS
658
659         /* Kill PROM timer */
660         sethi   %hi(0x80000000), %o2
661         sllx    %o2, 32, %o2
662         wr      %o2, 0, %tick_cmpr
663
664         BRANCH_IF_ANY_CHEETAH(o2,o3,1f)
665
666         ba,pt   %xcc, 2f
667          nop
668
669         /* Disable STICK_INT interrupts. */
670 1:
671         sethi   %hi(0x80000000), %o2
672         sllx    %o2, 32, %o2
673         wr      %o2, %asr25
674
675         /* Ok, we're done setting up all the state our trap mechanims needs,
676          * now get back into normal globals and let the PROM know what is up.
677          */
678 2:
679         wrpr    %g0, %g0, %wstate
680         wrpr    %o1, PSTATE_IE, %pstate
681
682         call    init_irqwork_curcpu
683          nop
684
685         sethi   %hi(sparc64_ttable_tl0), %g5
686         call    prom_set_trap_table
687          mov    %g5, %o0
688
689         rdpr    %pstate, %o1
690         or      %o1, PSTATE_IE, %o1
691         wrpr    %o1, 0, %pstate
692
693         ret
694          restore
695
696 /*
697  * The following skips make sure the trap table in ttable.S is aligned
698  * on a 32K boundary as required by the v9 specs for TBA register.
699  */
700 sparc64_boot_end:
701         .skip   0x2000 + _start - sparc64_boot_end
702 bootup_user_stack_end:
703         .skip   0x2000
704
705 #ifdef CONFIG_SBUS
706 /* This is just a hack to fool make depend config.h discovering
707    strategy: As the .S files below need config.h, but
708    make depend does not find it for them, we include config.h
709    in head.S */
710 #endif
711
712 ! 0x0000000000408000
713
714 #include "ttable.S"
715 #include "systbls.S"
716
717         .align  1024
718         .globl  swapper_pg_dir
719 swapper_pg_dir:
720         .word   0
721
722 #include "etrap.S"
723 #include "rtrap.S"
724 #include "winfixup.S"
725 #include "entry.S"
726
727         /* This is just anal retentiveness on my part... */
728         .align  16384
729
730         .data
731         .align  8
732         .globl  prom_tba, tlb_type
733 prom_tba:       .xword  0
734 tlb_type:       .word   0       /* Must NOT end up in BSS */
735         .section        ".fixup",#alloc,#execinstr
736         .globl  __ret_efault
737 __ret_efault:
738         ret
739          restore %g0, -EFAULT, %o0
740