2 * This file is part of the coreboot project.
4 * Copyright (C) 2000,2007 Ronald G. Minnich <rminnich@gmail.com>
5 * Copyright (C) 2007-2008 coresystems GmbH
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <cpu/x86/stack.h>
22 #include <cpu/x86/mtrr.h>
23 #include <cpu/x86/post_code.h>
25 #define CPU_MAXPHYADDR 36
26 #define CPU_PHYSMASK_HI (1 << (CPU_MAXPHYADDR - 32) - 1)
28 #define CACHE_AS_RAM_SIZE CONFIG_DCACHE_RAM_SIZE
29 #define CACHE_AS_RAM_BASE CONFIG_DCACHE_RAM_BASE
31 /* Save the BIST result. */
37 /* Send INIT IPI to all excluding ourself. */
38 movl $0x000C4500, %eax
39 movl $0xFEE00300, %esi
42 /* Zero out all fixed range and variable range MTRRs. */
43 movl $mtrr_table, %esi
44 movl $((mtrr_table_end - mtrr_table) / 2), %edi
55 /* Configure the default memory type to uncacheable. */
56 movl $MTRRdefType_MSR, %ecx
58 andl $(~0x00000cff), %eax
61 /* Set Cache-as-RAM base address. */
62 movl $(MTRRphysBase_MSR(0)), %ecx
63 movl $(CACHE_AS_RAM_BASE | MTRR_TYPE_WRBACK), %eax
67 /* Set Cache-as-RAM mask. */
68 movl $(MTRRphysMask_MSR(0)), %ecx
69 movl $(~(CACHE_AS_RAM_SIZE - 1) | MTRRphysMaskValid), %eax
70 movl $CPU_PHYSMASK_HI, %edx
74 movl $MTRRdefType_MSR, %ecx
76 orl $MTRRdefTypeEn, %eax
79 /* Enable L2 cache. */
85 /* Enable cache (CR0.CD = 0, CR0.NW = 0). */
87 andl $(~((1 << 30) | (1 << 29))), %eax
91 /* Clear the cache memory reagion. */
92 movl $CACHE_AS_RAM_BASE, %esi
94 movl $(CACHE_AS_RAM_SIZE / 4), %ecx
95 // movl $0x23322332, %eax
99 /* Enable Cache-as-RAM mode by disabling cache. */
104 #if CONFIG_XIP_ROM_SIZE
105 /* Enable cache for our code in Flash because we do XIP here */
106 movl $MTRRphysBase_MSR(1), %ecx
109 * IMPORTANT: The following calculation _must_ be done at runtime. See
110 * http://www.coreboot.org/pipermail/coreboot/2010-October/060855.html
112 movl $copy_and_run, %eax
113 andl $(~(CONFIG_XIP_ROM_SIZE - 1)), %eax
114 orl $MTRR_TYPE_WRBACK, %eax
117 movl $MTRRphysMask_MSR(1), %ecx
118 movl $CPU_PHYSMASK_HI, %edx
119 movl $(~(CONFIG_XIP_ROM_SIZE - 1) | MTRRphysMaskValid), %eax
121 #endif /* CONFIG_XIP_ROM_SIZE */
125 andl $(~((1 << 30) | (1 << 29))), %eax
128 /* Set up the stack pointer. */
130 /* Leave some space for the struct ehci_debug_info. */
131 movl $(CACHE_AS_RAM_BASE + CACHE_AS_RAM_SIZE - 4 - 128), %eax
133 movl $(CACHE_AS_RAM_BASE + CACHE_AS_RAM_SIZE - 4), %eax
137 /* Restore the BIST result. */
144 /* Call romstage.c main function. */
159 movl $MTRRdefType_MSR, %ecx
161 andl $(~MTRRdefTypeEn), %eax
170 movl $MTRRphysBase_MSR(0), %ecx
172 movl $MTRRphysMask_MSR(0), %ecx
174 movl $MTRRphysBase_MSR(1), %ecx
176 movl $MTRRphysMask_MSR(1), %ecx
184 andl $~((1 << 30) | (1 << 29)), %eax
196 /* Enable Write Back and Speculative Reads for the first 1MB. */
197 movl $MTRRphysBase_MSR(0), %ecx
198 movl $(0x00000000 | MTRR_TYPE_WRBACK), %eax
201 movl $MTRRphysMask_MSR(0), %ecx
202 movl $(~(CONFIG_RAMTOP - 1) | MTRRphysMaskValid), %eax
203 movl $CPU_PHYSMASK_HI, %edx
206 /* Enable caching and Speculative Reads for the last 4MB. */
207 movl $MTRRphysBase_MSR(1), %ecx
208 movl $(0xffc00000 | MTRR_TYPE_WRPROT), %eax
211 movl $MTRRphysMask_MSR(1), %ecx
212 movl $(~(4 * 1024 * 1024 - 1) | MTRRphysMaskValid), %eax
213 movl $CPU_PHYSMASK_HI, %edx
218 /* And enable cache again after setting MTRRs. */
220 andl $~((1 << 30) | (1 << 29)), %eax
226 movl $MTRRdefType_MSR, %ecx
228 orl $MTRRdefTypeEn, %eax
233 /* Invalidate the cache again. */
238 /* Clear boot_complete flag. */
241 post_code(POST_PREPARE_RAMSTAGE)
242 cld /* Clear direction flag. */
246 movl $ROMSTAGE_STACK, %esp
252 post_code(POST_DEAD_CODE)
258 .word 0x250, 0x258, 0x259
259 .word 0x268, 0x269, 0x26A
260 .word 0x26B, 0x26C, 0x26D
263 .word 0x200, 0x201, 0x202, 0x203
264 .word 0x204, 0x205, 0x206, 0x207
265 .word 0x208, 0x209, 0x20A, 0x20B
266 .word 0x20C, 0x20D, 0x20E, 0x20F