]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/sun4v/sun4v/mp_locore.S
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / sun4v / sun4v / mp_locore.S
1 /*-
2  * Copyright (c) 2002 Jake Burkholder.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26
27 #include <machine/asm.h>
28 __FBSDID("$FreeBSD$");
29
30 #include <machine/asi.h>
31 #include <machine/asmacros.h>
32 #include <machine/hypervisorvar.h>
33 #include <machine/intr_machdep.h>
34 #include <machine/ktr.h>
35 #include <machine/pstate.h>
36 #include <machine/smp.h>
37
38 #include "assym.s"
39
40         .register       %g2, #ignore
41         .register       %g3, #ignore
42
43         .text
44         _ALIGN_TEXT
45         
46 1:      rd      %pc, %l0                        ! startpc
47         mov     %o0, %g1                        ! save arg to to mp_tramp_func
48         ldx     [%l0 + (6f-1b)], %l1            ! read mp_tramp_tte_slots
49         add     %l0, (7f-1b), %l2               ! %l2 points to start of slot area
50         clr     %l3
51 2:      cmp     %l3, %l1                        ! number of slots entered == total?
52         be      %xcc, 3f
53           nop
54         ldx     [%l2], %o0                      ! VA
55         mov     0, %o1                          ! ctx0
56         ldx     [%l2 + 8], %o2                  ! TTE
57         mov     MAP_ITLB|MAP_DTLB, %o3          
58         mov     MMU_MAP_PERM_ADDR, %o5
59         ta      FAST_TRAP
60 #ifdef DEBUG
61         brz     %o0, 9f
62           nop
63         ta      0x77
64         ta      0x71    
65 9:
66 #endif          
67         add     %l2, 16, %l2                    ! point %l2 at next slot
68         inc     %l3
69         ba      %xcc, 2b
70           nop
71 3:              
72         ldx     [%l0 + (4f-1b)], %o1            ! read mp_tramp_tsb_ra
73         mov     2, %o0
74         mov     MMU_TSB_CTX0, %o5               ! set ctx0 TSBs
75         ta      FAST_TRAP
76 #ifdef DEBUG
77         brz     %o0, 9f
78           nop
79         ta      0x77
80         ta      0x71    
81 9:
82 #endif          
83         ldx     [%l0 + (5f-1b)], %l1            ! fetch mp_tramp_func
84         jmpl    %l1, %g0                        ! and off we go
85           mov   %g1, %o0
86         _ALIGN_DATA
87 4:      .xword  0x0
88 5:      .xword  0x0
89 6:      .xword  0x0
90 7:      
91
92 DATA(mp_tramp_code)
93         .xword  1b
94 DATA(mp_tramp_code_len)
95         .xword  7b-1b
96 DATA(mp_tramp_tsb_desc_ra)
97         .xword  4b-1b
98 DATA(mp_tramp_func)
99         .xword  5b-1b
100 DATA(mp_tramp_tte_slots)
101         .xword  6b-1b
102
103
104 #define PUTCHAR(x) \
105         mov     x, %o0          ; \
106         mov     CONS_WRITE, %o5 ; \
107         ta      FAST_TRAP
108 /*
109  * void mp_startup(void)
110  */
111 ENTRY(mp_startup)
112         wrpr    %g0, PSTATE_NORMAL, %pstate
113         wrpr    %g0, 0, %cleanwin
114         wrpr    %g0, 0, %pil
115         wr      %g0, 0, %fprs
116
117         SET(cpu_start_args, %l1, %l0)
118 #if KTR_COMPILE & KTR_SMP
119         CATR(KTR_SMP, "mp_start: cpu %d entered kernel"
120             , %g1, %g2, %g3, 7, 8, 9)
121         stx     %o0, [%g1 + KTR_PARM1]
122 9:
123 #endif
124
125         /*
126          * Inform the boot processor we have inited.
127          */
128         mov     CPU_INIT, %l1
129         membar  #LoadStore
130         stw     %l1, [%l0 + CSA_STATE]
131
132 #if KTR_COMPILE & KTR_SMP
133         CATR(KTR_SMP, "_mp_start: cpu %d got start signal"
134             , %g1, %g2, %g3, 7, 8, 9)
135         stx     %o0, [%g1 + KTR_PARM1]
136 9:
137 #endif
138 2:      
139          ld     [%l0 + CSA_CPUID], %l1
140         cmp     %l1, %o0
141         bne     %xcc, 2b
142           nop
143         
144         /*
145          * Get onto our per-cpu panic stack, which precedes the struct pcpu
146          * in the per-cpu page.
147          */
148         ldx     [%l0 + CSA_PCPU], %l1
149         set     PCPU_PAGES * PAGE_SIZE - PC_SIZEOF, %l2
150         add     %l1, %l2, %l1
151         sub     %l1, SPOFF + CCFSZ, %sp
152         wrpr    %g0, PIL_TICK, %pil
153 #if KTR_COMPILE & KTR_SMP
154         CATR(KTR_SMP,
155             "_mp_start: bootstrap cpuid=%d mid=%d pcpu=%#lx data=%#lx sp=%#lx"
156             , %g1, %g2, %g3, 7, 8, 9)
157         lduw    [%l1 + PC_CPUID], %g2
158         stx     %g2, [%g1 + KTR_PARM1]
159         lduw    [%l1 + PC_MID], %g2
160         stx     %g2, [%g1 + KTR_PARM2]
161         stx     %l1, [%g1 + KTR_PARM3]
162         stx     %sp, [%g1 + KTR_PARM5]
163 9:
164 #endif
165
166         /*
167          * And away we go.  This doesn't return.
168          */
169         call    cpu_mp_bootstrap
170          mov    %l1, %o0
171         sir
172         ! NOTREACHED
173 END(mp_startup)