Rev 3022 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
35 | jermar | 1 | # |
2071 | jermar | 2 | # Copyright (c) 2005 Jakub Jermar |
35 | jermar | 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 | # |
||
9 | # - Redistributions of source code must retain the above copyright |
||
10 | # notice, this list of conditions and the following disclaimer. |
||
11 | # - Redistributions in binary form must reproduce the above copyright |
||
12 | # notice, this list of conditions and the following disclaimer in the |
||
13 | # documentation and/or other materials provided with the distribution. |
||
14 | # - The name of the author may not be used to endorse or promote products |
||
15 | # derived from this software without specific prior written permission. |
||
16 | # |
||
17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | # |
||
28 | |||
473 | jermar | 29 | #include <arch/register.h> |
869 | vana | 30 | #include <arch/mm/page.h> |
31 | #include <arch/mm/asid.h> |
||
32 | #include <mm/asid.h> |
||
473 | jermar | 33 | |
869 | vana | 34 | #define RR_MASK (0xFFFFFFFF00000002) |
4055 | trochtova | 35 | #define RID_SHIFT 8 |
36 | #define PS_SHIFT 2 |
||
869 | vana | 37 | |
4055 | trochtova | 38 | #define KERNEL_TRANSLATION_I 0x0010000000000661 |
39 | #define KERNEL_TRANSLATION_D 0x0010000000000661 |
||
40 | #define KERNEL_TRANSLATION_VIO 0x0010000000000671 |
||
41 | #define KERNEL_TRANSLATION_IO 0x00100FFFFC000671 |
||
42 | #define KERNEL_TRANSLATION_FW 0x00100000F0000671 |
||
869 | vana | 43 | |
923 | vana | 44 | .section K_TEXT_START, "ax" |
60 | jermar | 45 | |
35 | jermar | 46 | .global kernel_image_start |
47 | |||
37 | jermar | 48 | stack0: |
35 | jermar | 49 | kernel_image_start: |
81 | jermar | 50 | .auto |
412 | jermar | 51 | |
4055 | trochtova | 52 | #ifdef CONFIG_SMP |
53 | # Identify self(CPU) in OS structures by ID / EID |
||
54 | |||
55 | mov r9 = cr64 |
||
56 | mov r10 = 1 |
||
57 | movl r12 = 0xffffffff |
||
58 | movl r8 = cpu_by_id_eid_list |
||
59 | and r8 = r8, r12 |
||
60 | shr r9 = r9, 16 |
||
61 | add r8 = r8, r9 |
||
62 | st1 [r8] = r10 |
||
63 | #endif |
||
64 | |||
2726 | vana | 65 | mov psr.l = r0 |
66 | srlz.i |
||
67 | srlz.d |
||
68 | |||
893 | jermar | 69 | # Fill TR.i and TR.d using Region Register #VRN_KERNEL |
869 | vana | 70 | |
2110 | jermar | 71 | movl r8 = (VRN_KERNEL << VRN_SHIFT) |
72 | mov r9 = rr[r8] |
||
2726 | vana | 73 | |
2110 | jermar | 74 | movl r10 = (RR_MASK) |
75 | and r9 = r10, r9 |
||
76 | movl r10 = ((RID_KERNEL << RID_SHIFT) | (KERNEL_PAGE_WIDTH << PS_SHIFT)) |
||
77 | or r9 = r10, r9 |
||
2726 | vana | 78 | |
2110 | jermar | 79 | mov rr[r8] = r9 |
869 | vana | 80 | |
2110 | jermar | 81 | movl r8 = (VRN_KERNEL << VRN_SHIFT) |
82 | mov cr.ifa = r8 |
||
2726 | vana | 83 | |
4055 | trochtova | 84 | mov r11 = cr.itir |
85 | movl r10 = (KERNEL_PAGE_WIDTH << PS_SHIFT) |
||
86 | or r10 = r10, r11 |
||
87 | mov cr.itir = r10 |
||
2726 | vana | 88 | |
2110 | jermar | 89 | movl r10 = (KERNEL_TRANSLATION_I) |
90 | itr.i itr[r0] = r10 |
||
91 | movl r10 = (KERNEL_TRANSLATION_D) |
||
92 | itr.d dtr[r0] = r10 |
||
869 | vana | 93 | |
2726 | vana | 94 | movl r7 = 1 |
95 | movl r8 = (VRN_KERNEL << VRN_SHIFT) | VIO_OFFSET |
||
96 | mov cr.ifa = r8 |
||
97 | movl r10 = (KERNEL_TRANSLATION_VIO) |
||
98 | itr.d dtr[r7] = r10 |
||
99 | |||
4055 | trochtova | 100 | mov r11 = cr.itir |
101 | movl r10 = ~0xfc |
||
102 | and r10 = r10, r11 |
||
103 | movl r11 = (IO_PAGE_WIDTH << PS_SHIFT) |
||
104 | or r10 = r10, r11 |
||
105 | mov cr.itir = r10 |
||
2726 | vana | 106 | |
107 | movl r7 = 2 |
||
108 | movl r8 = (VRN_KERNEL << VRN_SHIFT) | IO_OFFSET |
||
109 | mov cr.ifa = r8 |
||
110 | movl r10 = (KERNEL_TRANSLATION_IO) |
||
111 | itr.d dtr[r7] = r10 |
||
112 | |||
4055 | trochtova | 113 | # Setup mapping for fimware arrea (also SAPIC) |
2726 | vana | 114 | |
4055 | trochtova | 115 | mov r11 = cr.itir |
116 | movl r10 = ~0xfc |
||
117 | and r10 = r10, r11 |
||
118 | movl r11 = (FW_PAGE_WIDTH << PS_SHIFT) |
||
119 | or r10 = r10, r11 |
||
120 | mov cr.itir = r10 |
||
2726 | vana | 121 | |
4055 | trochtova | 122 | movl r7 = 3 |
123 | movl r8 = (VRN_KERNEL << VRN_SHIFT) | FW_OFFSET |
||
124 | mov cr.ifa = r8 |
||
125 | movl r10 = (KERNEL_TRANSLATION_FW) |
||
126 | itr.d dtr[r7] = r10 |
||
2726 | vana | 127 | |
4055 | trochtova | 128 | # Initialize PSR |
129 | |||
2110 | jermar | 130 | movl r10 = (PSR_DT_MASK | PSR_RT_MASK | PSR_IT_MASK | PSR_IC_MASK) /* Enable paging */ |
131 | mov r9 = psr |
||
4055 | trochtova | 132 | |
2110 | jermar | 133 | or r10 = r10, r9 |
134 | mov cr.ipsr = r10 |
||
135 | mov cr.ifs = r0 |
||
136 | movl r8 = paging_start |
||
137 | mov cr.iip = r8 |
||
473 | jermar | 138 | srlz.d |
869 | vana | 139 | srlz.i |
879 | vana | 140 | |
893 | jermar | 141 | .explicit |
4055 | trochtova | 142 | |
893 | jermar | 143 | /* |
4055 | trochtova | 144 | * Return From Interrupt is the only way to |
145 | * fill the upper half word of PSR. |
||
893 | jermar | 146 | */ |
4055 | trochtova | 147 | rfi ;; |
879 | vana | 148 | |
4055 | trochtova | 149 | |
879 | vana | 150 | .global paging_start |
151 | paging_start: |
||
893 | jermar | 152 | |
153 | /* |
||
154 | * Now we are paging. |
||
155 | */ |
||
156 | |||
4055 | trochtova | 157 | # Switch to register bank 1 |
473 | jermar | 158 | bsw.1 |
4055 | trochtova | 159 | |
160 | #ifdef CONFIG_SMP |
||
161 | # Am I BSP or AP? |
||
162 | movl r20 = bsp_started ;; |
||
163 | ld8 r20 = [r20] ;; |
||
164 | cmp.eq p3, p2 = r20, r0 ;; |
||
165 | #else |
||
166 | cmp.eq p3, p2 = r0, r0 ;; /* you are BSP */ |
||
167 | #endif /* CONFIG_SMP */ |
||
473 | jermar | 168 | |
4055 | trochtova | 169 | # Initialize register stack |
81 | jermar | 170 | mov ar.rsc = r0 |
2110 | jermar | 171 | movl r8 = (VRN_KERNEL << VRN_SHIFT) ;; |
869 | vana | 172 | mov ar.bspstore = r8 |
81 | jermar | 173 | loadrs |
36 | jermar | 174 | |
4055 | trochtova | 175 | # Initialize memory stack to some sane value |
2110 | jermar | 176 | movl r12 = stack0 ;; |
177 | add r12 = -16, r12 /* allocate a scratch area on the stack */ |
||
60 | jermar | 178 | |
4055 | trochtova | 179 | # Initialize gp (Global Pointer) register |
2519 | vana | 180 | movl r20 = (VRN_KERNEL << VRN_SHIFT);; |
181 | or r20 = r20,r1;; |
||
919 | jermar | 182 | movl r1 = _hardcoded_load_address |
2519 | vana | 183 | |
893 | jermar | 184 | /* |
4055 | trochtova | 185 | * Initialize hardcoded_* variables. Do only BSP |
893 | jermar | 186 | */ |
4055 | trochtova | 187 | (p3) movl r14 = _hardcoded_ktext_size |
188 | (p3) movl r15 = _hardcoded_kdata_size |
||
189 | (p3) movl r16 = _hardcoded_load_address ;; |
||
190 | (p3) addl r17 = @gprel(hardcoded_ktext_size), gp |
||
191 | (p3) addl r18 = @gprel(hardcoded_kdata_size), gp |
||
192 | (p3) addl r19 = @gprel(hardcoded_load_address), gp |
||
193 | (p3) addl r21 = @gprel(bootinfo), gp |
||
106 | jermar | 194 | ;; |
4055 | trochtova | 195 | (p3) st8 [r17] = r14 |
196 | (p3) st8 [r18] = r15 |
||
197 | (p3) st8 [r19] = r16 |
||
198 | (p3) st8 [r21] = r20 |
||
869 | vana | 199 | |
2110 | jermar | 200 | ssm (1 << 19) ;; /* Disable f32 - f127 */ |
201 | srlz.i |
||
202 | srlz.d ;; |
||
1053 | vana | 203 | |
4055 | trochtova | 204 | #ifdef CONFIG_SMP |
205 | (p2) movl r18 = main_ap ;; |
||
206 | (p2) mov b1 = r18 ;; |
||
207 | (p2) br.call.sptk.many b0 = b1 |
||
208 | |||
209 | # Mark that BSP is on |
||
210 | mov r20 = 1 ;; |
||
211 | movl r21 = bsp_started ;; |
||
212 | st8 [r21] = r20 ;; |
||
213 | #endif |
||
214 | |||
1223 | jermar | 215 | br.call.sptk.many b0 = arch_pre_main |
1053 | vana | 216 | |
2110 | jermar | 217 | movl r18 = main_bsp ;; |
218 | mov b1 = r18 ;; |
||
219 | br.call.sptk.many b0 = b1 |
||
51 | jermar | 220 | |
36 | jermar | 221 | 0: |
39 | jermar | 222 | br 0b |
4055 | trochtova | 223 | |
224 | #ifdef CONFIG_SMP |
||
225 | |||
226 | .align 4096 |
||
227 | kernel_image_ap_start: |
||
228 | .auto |
||
229 | |||
230 | # Identify self(CPU) in OS structures by ID / EID |
||
231 | |||
232 | mov r9 = cr64 |
||
233 | mov r10 = 1 |
||
234 | movl r12 = 0xffffffff |
||
235 | movl r8 = cpu_by_id_eid_list |
||
236 | and r8 = r8, r12 |
||
237 | shr r9 = r9, 16 |
||
238 | add r8 = r8, r9 |
||
239 | st1 [r8] = r10 |
||
240 | |||
241 | # Wait for wakeup synchro signal (#3 in cpu_by_id_eid_list) |
||
242 | |||
243 | kernel_image_ap_start_loop: |
||
244 | movl r11 = kernel_image_ap_start_loop |
||
245 | and r11 = r11, r12 |
||
246 | mov b1 = r11 |
||
247 | |||
248 | ld1 r20 = [r8] ;; |
||
249 | movl r21 = 3 ;; |
||
250 | cmp.eq p2, p3 = r20, r21 ;; |
||
251 | (p3) br.call.sptk.many b0 = b1 |
||
252 | |||
253 | movl r11 = kernel_image_start |
||
254 | and r11 = r11, r12 |
||
255 | mov b1 = r11 |
||
256 | br.call.sptk.many b0 = b1 |
||
257 | |||
258 | .align 16 |
||
259 | .global bsp_started |
||
260 | bsp_started: |
||
261 | .space 8 |
||
262 | |||
263 | .align 4096 |
||
264 | .global cpu_by_id_eid_list |
||
265 | cpu_by_id_eid_list: |
||
266 | .space 65536 |
||
267 | |||
268 | #endif /* CONFIG_SMP */ |