[30ef8ce] | 1 | #
|
---|
[df4ed85] | 2 | # Copyright (c) 2005 Jakub Jermar
|
---|
[30ef8ce] | 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 |
|
---|
[802bb95] | 29 | #include <arch/register.h>
|
---|
[5ac2e61] | 30 | #include <arch/mm/page.h>
|
---|
| 31 | #include <arch/mm/asid.h>
|
---|
| 32 | #include <mm/asid.h>
|
---|
| 33 |
|
---|
| 34 | #define RR_MASK (0xFFFFFFFF00000002)
|
---|
| 35 | #define RID_SHIFT 8
|
---|
| 36 | #define PS_SHIFT 2
|
---|
| 37 |
|
---|
[7208b6c] | 38 | #define KERNEL_TRANSLATION_I 0x0010000000000661
|
---|
| 39 | #define KERNEL_TRANSLATION_D 0x0010000000000661
|
---|
| 40 | #define KERNEL_TRANSLATION_VIO 0x0010000000000671
|
---|
| 41 | #define KERNEL_TRANSLATION_IO 0x00100FFFFC000671
|
---|
[59e4864] | 42 | #define KERNEL_TRANSLATION_FW 0x00100000F0000671
|
---|
[7208b6c] | 43 |
|
---|
| 44 |
|
---|
[5ac2e61] | 45 |
|
---|
[9faddb3] | 46 | .section K_TEXT_START, "ax"
|
---|
[00a44bc] | 47 |
|
---|
[30ef8ce] | 48 | .global kernel_image_start
|
---|
| 49 |
|
---|
[2217ac3] | 50 | stack0:
|
---|
[30ef8ce] | 51 | kernel_image_start:
|
---|
[7f1bfce] | 52 | .auto
|
---|
[75eacab] | 53 |
|
---|
[59e4864] | 54 | #identifi self(CPU) in OS structures by ID / EID
|
---|
| 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 |
|
---|
| 64 |
|
---|
| 65 |
|
---|
[7208b6c] | 66 | mov psr.l = r0
|
---|
| 67 | srlz.i
|
---|
| 68 | srlz.d
|
---|
| 69 |
|
---|
[481c520] | 70 | # Fill TR.i and TR.d using Region Register #VRN_KERNEL
|
---|
[5ac2e61] | 71 |
|
---|
[7208b6c] | 72 |
|
---|
[15819e37] | 73 | movl r8 = (VRN_KERNEL << VRN_SHIFT)
|
---|
| 74 | mov r9 = rr[r8]
|
---|
[7208b6c] | 75 |
|
---|
| 76 |
|
---|
[15819e37] | 77 | movl r10 = (RR_MASK)
|
---|
| 78 | and r9 = r10, r9
|
---|
| 79 | movl r10 = ((RID_KERNEL << RID_SHIFT) | (KERNEL_PAGE_WIDTH << PS_SHIFT))
|
---|
| 80 | or r9 = r10, r9
|
---|
[7208b6c] | 81 |
|
---|
| 82 |
|
---|
[15819e37] | 83 | mov rr[r8] = r9
|
---|
| 84 |
|
---|
[7208b6c] | 85 |
|
---|
| 86 |
|
---|
[15819e37] | 87 | movl r8 = (VRN_KERNEL << VRN_SHIFT)
|
---|
| 88 | mov cr.ifa = r8
|
---|
[7208b6c] | 89 |
|
---|
| 90 |
|
---|
| 91 | mov r11 = cr.itir ;;
|
---|
| 92 | movl r10 = (KERNEL_PAGE_WIDTH << PS_SHIFT);;
|
---|
| 93 | or r10 =r10 , r11 ;;
|
---|
| 94 | mov cr.itir = r10;;
|
---|
| 95 |
|
---|
| 96 |
|
---|
[15819e37] | 97 | movl r10 = (KERNEL_TRANSLATION_I)
|
---|
| 98 | itr.i itr[r0] = r10
|
---|
[7208b6c] | 99 |
|
---|
| 100 |
|
---|
[15819e37] | 101 | movl r10 = (KERNEL_TRANSLATION_D)
|
---|
| 102 | itr.d dtr[r0] = r10
|
---|
[5ac2e61] | 103 |
|
---|
[7208b6c] | 104 |
|
---|
| 105 | movl r7 = 1
|
---|
| 106 | movl r8 = (VRN_KERNEL << VRN_SHIFT) | VIO_OFFSET
|
---|
| 107 | mov cr.ifa = r8
|
---|
| 108 | movl r10 = (KERNEL_TRANSLATION_VIO)
|
---|
| 109 | itr.d dtr[r7] = r10
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 | mov r11 = cr.itir ;;
|
---|
| 113 | movl r10 = ~0xfc;;
|
---|
| 114 | and r10 =r10 , r11 ;;
|
---|
| 115 | movl r11 = (IO_PAGE_WIDTH << PS_SHIFT);;
|
---|
| 116 | or r10 =r10 , r11 ;;
|
---|
| 117 | mov cr.itir = r10;;
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 | movl r7 = 2
|
---|
| 121 | movl r8 = (VRN_KERNEL << VRN_SHIFT) | IO_OFFSET
|
---|
| 122 | mov cr.ifa = r8
|
---|
| 123 | movl r10 = (KERNEL_TRANSLATION_IO)
|
---|
| 124 | itr.d dtr[r7] = r10
|
---|
| 125 |
|
---|
| 126 |
|
---|
[59e4864] | 127 | #setup mapping for fimware arrea (also SAPIC)
|
---|
| 128 | mov r11 = cr.itir ;;
|
---|
| 129 | movl r10 = ~0xfc;;
|
---|
| 130 | and r10 =r10 , r11 ;;
|
---|
| 131 | movl r11 = (FW_PAGE_WIDTH << PS_SHIFT);;
|
---|
| 132 | or r10 =r10 , r11 ;;
|
---|
| 133 | mov cr.itir = r10;;
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 | movl r7 = 3
|
---|
| 137 | movl r8 = (VRN_KERNEL << VRN_SHIFT) | FW_OFFSET
|
---|
| 138 | mov cr.ifa = r8
|
---|
| 139 | movl r10 = (KERNEL_TRANSLATION_FW)
|
---|
| 140 | itr.d dtr[r7] = r10
|
---|
| 141 |
|
---|
| 142 |
|
---|
| 143 |
|
---|
[7208b6c] | 144 |
|
---|
| 145 |
|
---|
[7f1bfce] | 146 | # initialize PSR
|
---|
[15819e37] | 147 | movl r10 = (PSR_DT_MASK | PSR_RT_MASK | PSR_IT_MASK | PSR_IC_MASK) /* Enable paging */
|
---|
| 148 | mov r9 = psr
|
---|
| 149 | or r10 = r10, r9
|
---|
| 150 | mov cr.ipsr = r10
|
---|
| 151 | mov cr.ifs = r0
|
---|
| 152 | movl r8 = paging_start
|
---|
| 153 | mov cr.iip = r8
|
---|
[802bb95] | 154 | srlz.d
|
---|
[5ac2e61] | 155 | srlz.i
|
---|
[085434a] | 156 |
|
---|
[481c520] | 157 | .explicit
|
---|
| 158 | /*
|
---|
| 159 | * Return From Interupt is the only the way to fill upper half word of PSR.
|
---|
| 160 | */
|
---|
| 161 | rfi;;
|
---|
[085434a] | 162 |
|
---|
| 163 | .global paging_start
|
---|
| 164 | paging_start:
|
---|
[481c520] | 165 |
|
---|
| 166 | /*
|
---|
| 167 | * Now we are paging.
|
---|
| 168 | */
|
---|
| 169 |
|
---|
[802bb95] | 170 | # switch to register bank 1
|
---|
| 171 | bsw.1
|
---|
[59e4864] | 172 |
|
---|
| 173 | #Am'I BSP or AP
|
---|
| 174 | movl r20=bsp_started;;
|
---|
| 175 | ld8 r20=[r20];;
|
---|
| 176 | cmp.eq p3,p2=r20,r0;;
|
---|
| 177 |
|
---|
[7f1bfce] | 178 |
|
---|
[c884ef1] | 179 | # initialize register stack
|
---|
[7f1bfce] | 180 | mov ar.rsc = r0
|
---|
[15819e37] | 181 | movl r8 = (VRN_KERNEL << VRN_SHIFT) ;;
|
---|
[5ac2e61] | 182 | mov ar.bspstore = r8
|
---|
[7f1bfce] | 183 | loadrs
|
---|
[2a0047fc] | 184 |
|
---|
[c884ef1] | 185 | # initialize memory stack to some sane value
|
---|
[15819e37] | 186 | movl r12 = stack0 ;;
|
---|
[5ac2e61] | 187 |
|
---|
[15819e37] | 188 | add r12 = -16, r12 /* allocate a scratch area on the stack */
|
---|
[00a44bc] | 189 |
|
---|
[c884ef1] | 190 | # initialize gp (Global Pointer) register
|
---|
[7a9364c] | 191 | movl r20 = (VRN_KERNEL << VRN_SHIFT);;
|
---|
| 192 | or r20 = r20,r1;;
|
---|
[b994a60] | 193 | movl r1 = _hardcoded_load_address
|
---|
[7a9364c] | 194 |
|
---|
[481c520] | 195 | /*
|
---|
[59e4864] | 196 | * Initialize hardcoded_* variables. Do only BSP
|
---|
[481c520] | 197 | */
|
---|
[59e4864] | 198 | (p3) movl r14 = _hardcoded_ktext_size
|
---|
| 199 | (p3) movl r15 = _hardcoded_kdata_size
|
---|
| 200 | (p3) movl r16 = _hardcoded_load_address ;;
|
---|
| 201 | (p3) addl r17 = @gprel(hardcoded_ktext_size), gp
|
---|
| 202 | (p3) addl r18 = @gprel(hardcoded_kdata_size), gp
|
---|
| 203 | (p3) addl r19 = @gprel(hardcoded_load_address), gp
|
---|
| 204 | (p3) addl r21 = @gprel(bootinfo), gp
|
---|
[ac5d02b] | 205 | ;;
|
---|
[59e4864] | 206 | (p3) st8 [r17] = r14
|
---|
| 207 | (p3) st8 [r18] = r15
|
---|
| 208 | (p3) st8 [r19] = r16
|
---|
| 209 | (p3) st8 [r21] = r20
|
---|
[5ac2e61] | 210 |
|
---|
[15819e37] | 211 | ssm (1 << 19) ;; /* Disable f32 - f127 */
|
---|
| 212 | srlz.i
|
---|
| 213 | srlz.d ;;
|
---|
[41fa6f2] | 214 |
|
---|
[59e4864] | 215 | (p2) movl r18 = main_ap ;;
|
---|
| 216 | (p2) mov b1 = r18 ;;
|
---|
| 217 | (p2) br.call.sptk.many b0 = b1
|
---|
| 218 |
|
---|
| 219 | #Mark that BSP is on
|
---|
| 220 | mov r20=1;;
|
---|
| 221 | movl r21=bsp_started;;
|
---|
| 222 | st8 [r21]=r20;;
|
---|
| 223 |
|
---|
| 224 |
|
---|
[6ecc8bce] | 225 | br.call.sptk.many b0 = arch_pre_main
|
---|
[41fa6f2] | 226 |
|
---|
[15819e37] | 227 | movl r18 = main_bsp ;;
|
---|
| 228 | mov b1 = r18 ;;
|
---|
| 229 | br.call.sptk.many b0 = b1
|
---|
[5ac2e61] | 230 |
|
---|
[41fa6f2] | 231 |
|
---|
[2a0047fc] | 232 | 0:
|
---|
[47d78c6] | 233 | br 0b
|
---|
[59e4864] | 234 | .align 4096
|
---|
| 235 |
|
---|
| 236 | kernel_image_ap_start:
|
---|
| 237 | .auto
|
---|
| 238 | #identifi self(CPU) in OS structures by ID / EID
|
---|
| 239 | mov r9=cr64
|
---|
| 240 | mov r10=1
|
---|
| 241 | movl r12=0xffffffff
|
---|
| 242 | movl r8=cpu_by_id_eid_list
|
---|
| 243 | and r8=r8,r12
|
---|
| 244 | shr r9=r9,16
|
---|
| 245 | add r8=r8,r9
|
---|
| 246 | st1 [r8]=r10
|
---|
| 247 |
|
---|
| 248 | #wait for wakeup sychro signal (#3 in cpu_by_id_eid_list)
|
---|
| 249 | kernel_image_ap_start_loop:
|
---|
| 250 | movl r11=kernel_image_ap_start_loop
|
---|
| 251 | and r11=r11,r12
|
---|
| 252 | mov b1 = r11
|
---|
| 253 |
|
---|
| 254 | ld1 r20=[r8];;
|
---|
| 255 | movl r21=3;;
|
---|
| 256 | cmp.eq p2,p3=r20,r21;;
|
---|
| 257 | (p3)br.call.sptk.many b0 = b1
|
---|
| 258 |
|
---|
| 259 | movl r11=kernel_image_start
|
---|
| 260 | and r11=r11,r12
|
---|
| 261 | mov b1 = r11
|
---|
| 262 | br.call.sptk.many b0 = b1
|
---|
| 263 |
|
---|
| 264 |
|
---|
| 265 | .align 16
|
---|
| 266 | .global bsp_started
|
---|
| 267 | bsp_started:
|
---|
| 268 | .space 8
|
---|
| 269 |
|
---|
| 270 |
|
---|
| 271 | .align 4096
|
---|
| 272 | .global cpu_by_id_eid_list
|
---|
| 273 | cpu_by_id_eid_list:
|
---|
| 274 | .space 65536
|
---|
| 275 |
|
---|
| 276 |
|
---|