Rev 3766 | 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) |
3766 | jermar | 35 | #define RID_SHIFT 8 |
36 | #define PS_SHIFT 2 |
||
869 | vana | 37 | |
3766 | jermar | 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 | |
3766 | jermar | 52 | # Identify self(CPU) in OS structures by ID / EID |
3578 | vana | 53 | |
3766 | jermar | 54 | mov r9 = cr64 |
55 | mov r10 = 1 |
||
56 | movl r12 = 0xffffffff |
||
57 | movl r8 = cpu_by_id_eid_list |
||
58 | and r8 = r8, r12 |
||
59 | shr r9 = r9, 16 |
||
60 | add r8 = r8, r9 |
||
61 | st1 [r8] = r10 |
||
3578 | vana | 62 | |
2726 | vana | 63 | mov psr.l = r0 |
64 | srlz.i |
||
65 | srlz.d |
||
66 | |||
893 | jermar | 67 | # Fill TR.i and TR.d using Region Register #VRN_KERNEL |
869 | vana | 68 | |
2110 | jermar | 69 | movl r8 = (VRN_KERNEL << VRN_SHIFT) |
70 | mov r9 = rr[r8] |
||
2726 | vana | 71 | |
2110 | jermar | 72 | movl r10 = (RR_MASK) |
73 | and r9 = r10, r9 |
||
74 | movl r10 = ((RID_KERNEL << RID_SHIFT) | (KERNEL_PAGE_WIDTH << PS_SHIFT)) |
||
75 | or r9 = r10, r9 |
||
2726 | vana | 76 | |
2110 | jermar | 77 | mov rr[r8] = r9 |
869 | vana | 78 | |
2110 | jermar | 79 | movl r8 = (VRN_KERNEL << VRN_SHIFT) |
80 | mov cr.ifa = r8 |
||
2726 | vana | 81 | |
82 | mov r11 = cr.itir ;; |
||
83 | movl r10 = (KERNEL_PAGE_WIDTH << PS_SHIFT);; |
||
3766 | jermar | 84 | or r10 = r10, r11 ;; |
2726 | vana | 85 | mov cr.itir = r10;; |
86 | |||
2110 | jermar | 87 | movl r10 = (KERNEL_TRANSLATION_I) |
88 | itr.i itr[r0] = r10 |
||
89 | movl r10 = (KERNEL_TRANSLATION_D) |
||
90 | itr.d dtr[r0] = r10 |
||
869 | vana | 91 | |
2726 | vana | 92 | movl r7 = 1 |
93 | movl r8 = (VRN_KERNEL << VRN_SHIFT) | VIO_OFFSET |
||
94 | mov cr.ifa = r8 |
||
95 | movl r10 = (KERNEL_TRANSLATION_VIO) |
||
96 | itr.d dtr[r7] = r10 |
||
97 | |||
98 | mov r11 = cr.itir ;; |
||
99 | movl r10 = ~0xfc;; |
||
3766 | jermar | 100 | and r10 = r10, r11 ;; |
2726 | vana | 101 | movl r11 = (IO_PAGE_WIDTH << PS_SHIFT);; |
3766 | jermar | 102 | or r10 = r10, r11 ;; |
2726 | vana | 103 | mov cr.itir = r10;; |
104 | |||
105 | movl r7 = 2 |
||
106 | movl r8 = (VRN_KERNEL << VRN_SHIFT) | IO_OFFSET |
||
107 | mov cr.ifa = r8 |
||
108 | movl r10 = (KERNEL_TRANSLATION_IO) |
||
109 | itr.d dtr[r7] = r10 |
||
110 | |||
3766 | jermar | 111 | # Setup mapping for fimware arrea (also SAPIC) |
2726 | vana | 112 | |
3578 | vana | 113 | mov r11 = cr.itir ;; |
114 | movl r10 = ~0xfc;; |
||
3766 | jermar | 115 | and r10 = r10, r11 ;; |
3578 | vana | 116 | movl r11 = (FW_PAGE_WIDTH << PS_SHIFT);; |
3766 | jermar | 117 | or r10 = r10, r11 ;; |
3578 | vana | 118 | mov cr.itir = r10;; |
2726 | vana | 119 | |
3578 | vana | 120 | movl r7 = 3 |
121 | movl r8 = (VRN_KERNEL << VRN_SHIFT) | FW_OFFSET |
||
122 | mov cr.ifa = r8 |
||
123 | movl r10 = (KERNEL_TRANSLATION_FW) |
||
124 | itr.d dtr[r7] = r10 |
||
125 | |||
3766 | jermar | 126 | # Initialize PSR |
3578 | vana | 127 | |
2110 | jermar | 128 | movl r10 = (PSR_DT_MASK | PSR_RT_MASK | PSR_IT_MASK | PSR_IC_MASK) /* Enable paging */ |
129 | mov r9 = psr |
||
3766 | jermar | 130 | |
2110 | jermar | 131 | or r10 = r10, r9 |
132 | mov cr.ipsr = r10 |
||
133 | mov cr.ifs = r0 |
||
134 | movl r8 = paging_start |
||
135 | mov cr.iip = r8 |
||
473 | jermar | 136 | srlz.d |
869 | vana | 137 | srlz.i |
879 | vana | 138 | |
893 | jermar | 139 | .explicit |
3766 | jermar | 140 | |
893 | jermar | 141 | /* |
3781 | jermar | 142 | * Return From Interrupt is the only way to |
143 | * fill the upper half word of PSR. |
||
893 | jermar | 144 | */ |
145 | rfi;; |
||
879 | vana | 146 | |
3766 | jermar | 147 | |
879 | vana | 148 | .global paging_start |
149 | paging_start: |
||
893 | jermar | 150 | |
151 | /* |
||
152 | * Now we are paging. |
||
153 | */ |
||
154 | |||
3766 | jermar | 155 | # Switch to register bank 1 |
473 | jermar | 156 | bsw.1 |
3578 | vana | 157 | |
3766 | jermar | 158 | # Am I BSP or AP? |
159 | movl r20 = bsp_started;; |
||
160 | ld8 r20 = [r20];; |
||
161 | cmp.eq p3, p2 = r20, r0;; |
||
473 | jermar | 162 | |
3766 | jermar | 163 | # Initialize register stack |
81 | jermar | 164 | mov ar.rsc = r0 |
2110 | jermar | 165 | movl r8 = (VRN_KERNEL << VRN_SHIFT) ;; |
869 | vana | 166 | mov ar.bspstore = r8 |
81 | jermar | 167 | loadrs |
36 | jermar | 168 | |
3766 | jermar | 169 | # Initialize memory stack to some sane value |
2110 | jermar | 170 | movl r12 = stack0 ;; |
171 | add r12 = -16, r12 /* allocate a scratch area on the stack */ |
||
60 | jermar | 172 | |
3766 | jermar | 173 | # Initialize gp (Global Pointer) register |
2519 | vana | 174 | movl r20 = (VRN_KERNEL << VRN_SHIFT);; |
175 | or r20 = r20,r1;; |
||
919 | jermar | 176 | movl r1 = _hardcoded_load_address |
2519 | vana | 177 | |
893 | jermar | 178 | /* |
3578 | vana | 179 | * Initialize hardcoded_* variables. Do only BSP |
893 | jermar | 180 | */ |
3578 | vana | 181 | (p3) movl r14 = _hardcoded_ktext_size |
182 | (p3) movl r15 = _hardcoded_kdata_size |
||
183 | (p3) movl r16 = _hardcoded_load_address ;; |
||
184 | (p3) addl r17 = @gprel(hardcoded_ktext_size), gp |
||
185 | (p3) addl r18 = @gprel(hardcoded_kdata_size), gp |
||
186 | (p3) addl r19 = @gprel(hardcoded_load_address), gp |
||
187 | (p3) addl r21 = @gprel(bootinfo), gp |
||
106 | jermar | 188 | ;; |
3578 | vana | 189 | (p3) st8 [r17] = r14 |
190 | (p3) st8 [r18] = r15 |
||
191 | (p3) st8 [r19] = r16 |
||
192 | (p3) st8 [r21] = r20 |
||
869 | vana | 193 | |
2110 | jermar | 194 | ssm (1 << 19) ;; /* Disable f32 - f127 */ |
195 | srlz.i |
||
196 | srlz.d ;; |
||
1053 | vana | 197 | |
3578 | vana | 198 | (p2) movl r18 = main_ap ;; |
199 | (p2) mov b1 = r18 ;; |
||
200 | (p2) br.call.sptk.many b0 = b1 |
||
201 | |||
3766 | jermar | 202 | # Mark that BSP is on |
3578 | vana | 203 | mov r20=1;; |
204 | movl r21=bsp_started;; |
||
205 | st8 [r21]=r20;; |
||
206 | |||
1223 | jermar | 207 | br.call.sptk.many b0 = arch_pre_main |
1053 | vana | 208 | |
2110 | jermar | 209 | movl r18 = main_bsp ;; |
210 | mov b1 = r18 ;; |
||
211 | br.call.sptk.many b0 = b1 |
||
51 | jermar | 212 | |
36 | jermar | 213 | 0: |
39 | jermar | 214 | br 0b |
3578 | vana | 215 | .align 4096 |
216 | |||
217 | kernel_image_ap_start: |
||
218 | .auto |
||
3766 | jermar | 219 | |
220 | # Identify self(CPU) in OS structures by ID / EID |
||
221 | |||
222 | mov r9 = cr64 |
||
223 | mov r10 = 1 |
||
224 | movl r12 = 0xffffffff |
||
225 | movl r8 = cpu_by_id_eid_list |
||
226 | and r8 = r8, r12 |
||
227 | shr r9 = r9, 16 |
||
228 | add r8 = r8, r9 |
||
229 | st1 [r8] = r10 |
||
3578 | vana | 230 | |
3766 | jermar | 231 | # Wait for wakeup synchro signal (#3 in cpu_by_id_eid_list) |
3578 | vana | 232 | kernel_image_ap_start_loop: |
3766 | jermar | 233 | movl r11 = kernel_image_ap_start_loop |
234 | and r11 = r11, r12 |
||
3578 | vana | 235 | mov b1 = r11 |
236 | |||
3766 | jermar | 237 | ld1 r20 = [r8];; |
238 | movl r21 = 3;; |
||
239 | cmp.eq p2, p3 = r20, r21;; |
||
240 | (p3) br.call.sptk.many b0 = b1 |
||
3578 | vana | 241 | |
3766 | jermar | 242 | movl r11 = kernel_image_start |
243 | and r11 = r11, r12 |
||
244 | mov b1 = r11 |
||
3578 | vana | 245 | br.call.sptk.many b0 = b1 |
246 | |||
247 | |||
248 | .align 16 |
||
249 | .global bsp_started |
||
250 | bsp_started: |
||
251 | .space 8 |
||
252 | |||
253 | .align 4096 |
||
254 | .global cpu_by_id_eid_list |
||
255 | cpu_by_id_eid_list: |
||
256 | .space 65536 |
||
257 |