Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2000,2007 Ronald G. Minnich <rminnich@gmail.com> |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 5 | * Copyright (C) 2005 Tyan (written by Yinghai Lu for Tyan) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 6 | * Copyright (C) 2007-2008 coresystems GmbH |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 7 | * Copyright (C) 2012 Kyösti Mälkki <kyosti.malkki@gmail.com> |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; version 2 of the License. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | */ |
| 22 | |
| 23 | #include <cpu/x86/stack.h> |
| 24 | #include <cpu/x86/mtrr.h> |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 25 | #include <cpu/x86/cache.h> |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 26 | #include <cpu/x86/post_code.h> |
Kyösti Mälkki | f9d1a42 | 2012-02-28 01:45:44 +0200 | [diff] [blame] | 27 | #include <cpu/x86/lapic_def.h> |
| 28 | |
| 29 | /* Macro to access Local APIC registers at default base. */ |
| 30 | #define LAPIC(x) $(LAPIC_DEFAULT_BASE | LAPIC_ ## x) |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 31 | #define START_IPI_VECTOR ((CONFIG_AP_SIPI_VECTOR >> 12) & 0xff) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 32 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 33 | #define CACHE_AS_RAM_SIZE CONFIG_DCACHE_RAM_SIZE |
| 34 | #define CACHE_AS_RAM_BASE CONFIG_DCACHE_RAM_BASE |
| 35 | |
| 36 | /* Save the BIST result. */ |
| 37 | movl %eax, %ebp |
| 38 | |
| 39 | cache_as_ram: |
| 40 | post_code(0x20) |
| 41 | |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 42 | movl $LAPIC_BASE_MSR, %ecx |
| 43 | rdmsr |
| 44 | andl $LAPIC_BASE_MSR_BOOTSTRAP_PROCESSOR, %eax |
| 45 | jz ap_init |
| 46 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 47 | /* Zero out all fixed range and variable range MTRRs. |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 48 | * For hyper-threaded CPUs these are shared. |
| 49 | */ |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 50 | movl $mtrr_table, %esi |
| 51 | movl $((mtrr_table_end - mtrr_table) / 2), %edi |
| 52 | xorl %eax, %eax |
| 53 | xorl %edx, %edx |
| 54 | clear_mtrrs: |
| 55 | movw (%esi), %bx |
| 56 | movzx %bx, %ecx |
| 57 | wrmsr |
| 58 | add $2, %esi |
| 59 | dec %edi |
| 60 | jnz clear_mtrrs |
| 61 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 62 | post_code(0x21) |
| 63 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 64 | /* Configure the default memory type to uncacheable. */ |
| 65 | movl $MTRRdefType_MSR, %ecx |
| 66 | rdmsr |
| 67 | andl $(~0x00000cff), %eax |
| 68 | wrmsr |
| 69 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 70 | post_code(0x22) |
| 71 | |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 72 | /* Determine CPU_ADDR_BITS and load PHYSMASK high |
| 73 | * word to %edx. |
| 74 | */ |
| 75 | movl $0x80000000, %eax |
| 76 | cpuid |
| 77 | cmpl $0x80000008, %eax |
| 78 | jc addrsize_no_MSR |
| 79 | movl $0x80000008, %eax |
| 80 | cpuid |
| 81 | movb %al, %cl |
| 82 | sub $32, %cl |
| 83 | movl $1, %edx |
| 84 | shl %cl, %edx |
| 85 | subl $1, %edx |
| 86 | jmp addrsize_set_high |
| 87 | addrsize_no_MSR: |
| 88 | movl $1, %eax |
| 89 | cpuid |
| 90 | andl $(1<<6 | 1<<17), %edx /* PAE or PSE36 */ |
| 91 | jz addrsize_set_high |
| 92 | movl $0x0f, %edx |
| 93 | |
| 94 | /* Preload high word of address mask (in %edx) for Variable |
| 95 | * MTRRs 0 and 1 and enable local apic at default base. |
| 96 | */ |
| 97 | addrsize_set_high: |
| 98 | xorl %eax, %eax |
| 99 | movl $MTRRphysMask_MSR(0), %ecx |
| 100 | wrmsr |
| 101 | movl $MTRRphysMask_MSR(1), %ecx |
| 102 | wrmsr |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 103 | movl $LAPIC_BASE_MSR, %ecx |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 104 | not %edx |
| 105 | movl %edx, %ebx |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 106 | rdmsr |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 107 | andl %ebx, %edx |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 108 | andl $(~LAPIC_BASE_MSR_ADDR_MASK), %eax |
| 109 | orl $(LAPIC_DEFAULT_BASE | LAPIC_BASE_MSR_ENABLE), %eax |
| 110 | wrmsr |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 111 | |
| 112 | bsp_init: |
| 113 | |
| 114 | post_code(0x23) |
| 115 | |
| 116 | /* Send INIT IPI to all excluding ourself. */ |
| 117 | movl LAPIC(ICR), %edi |
| 118 | movl $(LAPIC_DEST_ALLBUT | LAPIC_INT_ASSERT | LAPIC_DM_INIT), %eax |
| 119 | 1: movl %eax, (%edi) |
| 120 | movl $0x30, %ecx |
| 121 | 2: pause |
| 122 | dec %ecx |
| 123 | jnz 2b |
| 124 | movl (%edi), %ecx |
| 125 | andl $LAPIC_ICR_BUSY, %ecx |
| 126 | jnz 1b |
| 127 | |
| 128 | post_code(0x24) |
Patrick Georgi | 819c7d4 | 2012-03-31 13:08:12 +0200 | [diff] [blame] | 129 | |
Kyösti Mälkki | df0fbc7 | 2012-07-04 12:02:58 +0300 | [diff] [blame^] | 130 | movl $1, %eax |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 131 | cpuid |
| 132 | btl $28, %edx |
| 133 | jnc sipi_complete |
| 134 | bswapl %ebx |
Kyösti Mälkki | df0fbc7 | 2012-07-04 12:02:58 +0300 | [diff] [blame^] | 135 | movzx %bh, %edi |
| 136 | cmpb $1, %bh |
| 137 | jbe sipi_complete /* only one LAPIC ID in package */ |
| 138 | |
| 139 | movl $0, %eax |
| 140 | cpuid |
| 141 | movb $1, %bl |
| 142 | cmpl $4, %eax |
| 143 | jb cores_counted |
| 144 | movl $4, %eax |
| 145 | movl $0, %ecx |
| 146 | cpuid |
| 147 | shr $26, %eax |
| 148 | movb %al, %bl |
| 149 | inc %bl |
| 150 | |
| 151 | cores_counted: |
| 152 | movl %edi, %eax |
| 153 | divb %bl |
| 154 | cmpb $1, %al |
| 155 | jbe sipi_complete /* only LAPIC ID of a core */ |
| 156 | |
| 157 | /* For a hyper-threading processor, cache must not be disabled |
| 158 | * on an AP on the same physical package with the BSP. |
| 159 | */ |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 160 | |
| 161 | hyper_threading_cpu: |
| 162 | |
| 163 | /* delay 10 ms */ |
| 164 | movl $10000, %ecx |
| 165 | 1: inb $0x80, %al |
| 166 | dec %ecx |
| 167 | jnz 1b |
| 168 | |
| 169 | post_code(0x25) |
| 170 | |
| 171 | /* Send Start IPI to all excluding ourself. */ |
| 172 | movl LAPIC(ICR), %edi |
| 173 | movl $(LAPIC_DEST_ALLBUT | LAPIC_DM_STARTUP | START_IPI_VECTOR), %eax |
| 174 | 1: movl %eax, (%edi) |
| 175 | movl $0x30, %ecx |
| 176 | 2: pause |
| 177 | dec %ecx |
| 178 | jnz 2b |
| 179 | movl (%edi), %ecx |
| 180 | andl $LAPIC_ICR_BUSY, %ecx |
| 181 | jnz 1b |
| 182 | |
| 183 | /* delay 250 us */ |
| 184 | movl $250, %ecx |
| 185 | 1: inb $0x80, %al |
| 186 | dec %ecx |
| 187 | jnz 1b |
| 188 | |
| 189 | post_code(0x26) |
| 190 | |
| 191 | /* Wait for sibling CPU to start. */ |
| 192 | 1: movl $(MTRRphysBase_MSR(0)), %ecx |
| 193 | rdmsr |
| 194 | andl %eax, %eax |
| 195 | jnz sipi_complete |
| 196 | |
| 197 | movl $0x30, %ecx |
| 198 | 2: pause |
| 199 | dec %ecx |
| 200 | jnz 2b |
| 201 | jmp 1b |
| 202 | |
| 203 | |
| 204 | ap_init: |
| 205 | post_code(0x27) |
| 206 | |
| 207 | /* Do not disable cache (so BSP can enable it). */ |
| 208 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 209 | andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 210 | movl %eax, %cr0 |
| 211 | |
| 212 | post_code(0x28) |
| 213 | |
| 214 | /* MTRR registers are shared between HT siblings. */ |
| 215 | movl $(MTRRphysBase_MSR(0)), %ecx |
| 216 | movl $(1<<12), %eax |
| 217 | xorl %edx, %edx |
| 218 | wrmsr |
| 219 | |
| 220 | post_code(0x29) |
| 221 | |
| 222 | ap_halt: |
| 223 | cli |
| 224 | 1: hlt |
Kyösti Mälkki | df0fbc7 | 2012-07-04 12:02:58 +0300 | [diff] [blame^] | 225 | jmp 1b |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 226 | |
| 227 | |
| 228 | |
| 229 | sipi_complete: |
| 230 | |
| 231 | post_code(0x2a) |
| 232 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 233 | /* Set Cache-as-RAM base address. */ |
| 234 | movl $(MTRRphysBase_MSR(0)), %ecx |
| 235 | movl $(CACHE_AS_RAM_BASE | MTRR_TYPE_WRBACK), %eax |
| 236 | xorl %edx, %edx |
| 237 | wrmsr |
| 238 | |
| 239 | /* Set Cache-as-RAM mask. */ |
| 240 | movl $(MTRRphysMask_MSR(0)), %ecx |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 241 | rdmsr |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 242 | movl $(~(CACHE_AS_RAM_SIZE - 1) | MTRRphysMaskValid), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 243 | wrmsr |
| 244 | |
| 245 | /* Enable MTRR. */ |
| 246 | movl $MTRRdefType_MSR, %ecx |
| 247 | rdmsr |
| 248 | orl $MTRRdefTypeEn, %eax |
| 249 | wrmsr |
| 250 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 251 | post_code(0x2b) |
| 252 | |
Kyösti Mälkki | 05d6ffb | 2012-02-16 23:12:04 +0200 | [diff] [blame] | 253 | /* Enable L2 cache Write-Back (WBINVD and FLUSH#). |
| 254 | * |
| 255 | * MSR is set when DisplayFamily_DisplayModel is one of: |
| 256 | * 06_0x, 06_17, 06_1C |
| 257 | * |
| 258 | * Description says this bit enables use of WBINVD and FLUSH#. |
| 259 | * Should this be set only after the system bus and/or memory |
| 260 | * controller can successfully handle write cycles? |
| 261 | */ |
| 262 | |
| 263 | #define EAX_FAMILY(a) (a << 8) /* for family <= 0fH */ |
| 264 | #define EAX_MODEL(a) (((a & 0xf0) << 12) | ((a & 0xf) << 4)) |
| 265 | |
| 266 | movl $1, %eax |
| 267 | cpuid |
| 268 | movl %eax, %ebx |
| 269 | andl $EAX_FAMILY(0x0f), %eax |
| 270 | cmpl $EAX_FAMILY(0x06), %eax |
| 271 | jne no_msr_11e |
| 272 | movl %ebx, %eax |
| 273 | andl $EAX_MODEL(0xff), %eax |
| 274 | cmpl $EAX_MODEL(0x17), %eax |
| 275 | je has_msr_11e |
| 276 | cmpl $EAX_MODEL(0x1c), %eax |
| 277 | je has_msr_11e |
| 278 | andl $EAX_MODEL(0xf0), %eax |
| 279 | cmpl $EAX_MODEL(0x00), %eax |
| 280 | jne no_msr_11e |
| 281 | has_msr_11e: |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 282 | movl $0x11e, %ecx |
| 283 | rdmsr |
| 284 | orl $(1 << 8), %eax |
| 285 | wrmsr |
Kyösti Mälkki | 05d6ffb | 2012-02-16 23:12:04 +0200 | [diff] [blame] | 286 | no_msr_11e: |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 287 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 288 | post_code(0x2c) |
| 289 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 290 | /* Enable cache (CR0.CD = 0, CR0.NW = 0). */ |
Kyösti Mälkki | f9d1a42 | 2012-02-28 01:45:44 +0200 | [diff] [blame] | 291 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 292 | andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 293 | invd |
| 294 | movl %eax, %cr0 |
| 295 | |
| 296 | /* Clear the cache memory reagion. */ |
Kyösti Mälkki | f9d1a42 | 2012-02-28 01:45:44 +0200 | [diff] [blame] | 297 | cld |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 298 | xorl %eax, %eax |
Kyösti Mälkki | f9d1a42 | 2012-02-28 01:45:44 +0200 | [diff] [blame] | 299 | movl $CACHE_AS_RAM_BASE, %edi |
| 300 | movl $(CACHE_AS_RAM_SIZE / 4), %ecx |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 301 | rep stosl |
| 302 | |
| 303 | /* Enable Cache-as-RAM mode by disabling cache. */ |
| 304 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 305 | orl $CR0_CacheDisable, %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 306 | movl %eax, %cr0 |
| 307 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 308 | post_code(0x2d) |
| 309 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 310 | #if CONFIG_XIP_ROM_SIZE |
| 311 | /* Enable cache for our code in Flash because we do XIP here */ |
| 312 | movl $MTRRphysBase_MSR(1), %ecx |
| 313 | xorl %edx, %edx |
| 314 | /* |
| 315 | * IMPORTANT: The following calculation _must_ be done at runtime. See |
| 316 | * http://www.coreboot.org/pipermail/coreboot/2010-October/060855.html |
| 317 | */ |
| 318 | movl $copy_and_run, %eax |
| 319 | andl $(~(CONFIG_XIP_ROM_SIZE - 1)), %eax |
| 320 | orl $MTRR_TYPE_WRBACK, %eax |
| 321 | wrmsr |
| 322 | |
| 323 | movl $MTRRphysMask_MSR(1), %ecx |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 324 | rdmsr |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 325 | movl $(~(CONFIG_XIP_ROM_SIZE - 1) | MTRRphysMaskValid), %eax |
| 326 | wrmsr |
| 327 | #endif /* CONFIG_XIP_ROM_SIZE */ |
| 328 | |
| 329 | /* Enable cache. */ |
| 330 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 331 | andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 332 | movl %eax, %cr0 |
| 333 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 334 | post_code(0x2e) |
| 335 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 336 | /* Set up the stack pointer. */ |
| 337 | #if CONFIG_USBDEBUG |
| 338 | /* Leave some space for the struct ehci_debug_info. */ |
Kyösti Mälkki | f9d1a42 | 2012-02-28 01:45:44 +0200 | [diff] [blame] | 339 | movl $(CACHE_AS_RAM_BASE + CACHE_AS_RAM_SIZE - 4 - 128), %esp |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 340 | #else |
Kyösti Mälkki | f9d1a42 | 2012-02-28 01:45:44 +0200 | [diff] [blame] | 341 | movl $(CACHE_AS_RAM_BASE + CACHE_AS_RAM_SIZE - 4), %esp |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 342 | #endif |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 343 | |
| 344 | /* Restore the BIST result. */ |
| 345 | movl %ebp, %eax |
| 346 | movl %esp, %ebp |
| 347 | pushl %eax |
| 348 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 349 | post_code(0x2f) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 350 | |
| 351 | /* Call romstage.c main function. */ |
| 352 | call main |
Kyösti Mälkki | f9d1a42 | 2012-02-28 01:45:44 +0200 | [diff] [blame] | 353 | addl $4, %esp |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 354 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 355 | post_code(0x30) |
| 356 | |
| 357 | /* Disable cache. */ |
| 358 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 359 | orl $CR0_CacheDisable, %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 360 | movl %eax, %cr0 |
| 361 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 362 | post_code(0x34) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 363 | |
| 364 | /* Disable MTRR. */ |
| 365 | movl $MTRRdefType_MSR, %ecx |
| 366 | rdmsr |
| 367 | andl $(~MTRRdefTypeEn), %eax |
| 368 | wrmsr |
| 369 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 370 | post_code(0x35) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 371 | |
| 372 | invd |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 373 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 374 | post_code(0x36) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 375 | |
| 376 | /* Enable cache. */ |
| 377 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 378 | andl $~(CR0_CacheDisable | CR0_NoWriteThrough), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 379 | movl %eax, %cr0 |
| 380 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 381 | post_code(0x37) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 382 | |
| 383 | /* Disable cache. */ |
| 384 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 385 | orl $CR0_CacheDisable, %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 386 | movl %eax, %cr0 |
| 387 | |
| 388 | post_code(0x38) |
| 389 | |
Kyösti Mälkki | f9d1a42 | 2012-02-28 01:45:44 +0200 | [diff] [blame] | 390 | /* Enable Write Back and Speculative Reads for low RAM. */ |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 391 | movl $MTRRphysBase_MSR(0), %ecx |
| 392 | movl $(0x00000000 | MTRR_TYPE_WRBACK), %eax |
| 393 | xorl %edx, %edx |
| 394 | wrmsr |
| 395 | movl $MTRRphysMask_MSR(0), %ecx |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 396 | rdmsr |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 397 | movl $(~(CONFIG_RAMTOP - 1) | MTRRphysMaskValid), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 398 | wrmsr |
| 399 | |
Kyösti Mälkki | 5458b9d | 2012-06-30 11:41:08 +0300 | [diff] [blame] | 400 | #if CONFIG_CACHE_ROM_SIZE |
Kyösti Mälkki | 325b92f | 2012-02-28 00:24:15 +0200 | [diff] [blame] | 401 | /* Enable caching and Speculative Reads for Flash ROM device. */ |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 402 | movl $MTRRphysBase_MSR(1), %ecx |
Kyösti Mälkki | 325b92f | 2012-02-28 00:24:15 +0200 | [diff] [blame] | 403 | movl $(CACHE_ROM_BASE | MTRR_TYPE_WRPROT), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 404 | xorl %edx, %edx |
| 405 | wrmsr |
| 406 | movl $MTRRphysMask_MSR(1), %ecx |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 407 | rdmsr |
Kyösti Mälkki | 325b92f | 2012-02-28 00:24:15 +0200 | [diff] [blame] | 408 | movl $(~(CONFIG_CACHE_ROM_SIZE - 1) | MTRRphysMaskValid), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 409 | wrmsr |
Kyösti Mälkki | 5458b9d | 2012-06-30 11:41:08 +0300 | [diff] [blame] | 410 | #endif |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 411 | |
| 412 | post_code(0x39) |
| 413 | |
| 414 | /* And enable cache again after setting MTRRs. */ |
| 415 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 416 | andl $~(CR0_CacheDisable | CR0_NoWriteThrough), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 417 | movl %eax, %cr0 |
| 418 | |
| 419 | post_code(0x3a) |
| 420 | |
| 421 | /* Enable MTRR. */ |
| 422 | movl $MTRRdefType_MSR, %ecx |
| 423 | rdmsr |
| 424 | orl $MTRRdefTypeEn, %eax |
| 425 | wrmsr |
| 426 | |
| 427 | post_code(0x3b) |
| 428 | |
| 429 | /* Invalidate the cache again. */ |
| 430 | invd |
| 431 | |
| 432 | post_code(0x3c) |
| 433 | |
| 434 | /* Clear boot_complete flag. */ |
| 435 | xorl %ebp, %ebp |
| 436 | __main: |
| 437 | post_code(POST_PREPARE_RAMSTAGE) |
| 438 | cld /* Clear direction flag. */ |
| 439 | |
| 440 | movl %ebp, %esi |
| 441 | |
| 442 | movl $ROMSTAGE_STACK, %esp |
| 443 | movl %esp, %ebp |
| 444 | pushl %esi |
| 445 | call copy_and_run |
| 446 | |
| 447 | .Lhlt: |
| 448 | post_code(POST_DEAD_CODE) |
| 449 | hlt |
| 450 | jmp .Lhlt |
| 451 | |
| 452 | mtrr_table: |
| 453 | /* Fixed MTRRs */ |
| 454 | .word 0x250, 0x258, 0x259 |
| 455 | .word 0x268, 0x269, 0x26A |
| 456 | .word 0x26B, 0x26C, 0x26D |
| 457 | .word 0x26E, 0x26F |
| 458 | /* Variable MTRRs */ |
| 459 | .word 0x200, 0x201, 0x202, 0x203 |
| 460 | .word 0x204, 0x205, 0x206, 0x207 |
| 461 | .word 0x208, 0x209, 0x20A, 0x20B |
| 462 | .word 0x20C, 0x20D, 0x20E, 0x20F |
| 463 | mtrr_table_end: |
| 464 | |