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 /* Base address to cache all of Flash ROM, just below 4GB. */
29 #define CACHE_ROM_BASE ((1<<22 - CONFIG_CACHE_ROM_SIZE>>10)<<10)
31 #define CACHE_AS_RAM_SIZE CONFIG_DCACHE_RAM_SIZE
32 #define CACHE_AS_RAM_BASE CONFIG_DCACHE_RAM_BASE
34 /* Save the BIST result. */
40 /* Send INIT IPI to all excluding ourself. */
41 movl $0x000C4500, %eax
42 movl $0xFEE00300, %esi
45 /* Zero out all fixed range and variable range MTRRs. */
46 movl $mtrr_table, %esi
47 movl $((mtrr_table_end - mtrr_table) / 2), %edi
58 /* Configure the default memory type to uncacheable. */
59 movl $MTRRdefType_MSR, %ecx
61 andl $(~0x00000cff), %eax
64 /* Set Cache-as-RAM base address. */
65 movl $(MTRRphysBase_MSR(0)), %ecx
66 movl $(CACHE_AS_RAM_BASE | MTRR_TYPE_WRBACK), %eax
70 /* Set Cache-as-RAM mask. */
71 movl $(MTRRphysMask_MSR(0)), %ecx
72 movl $(~(CACHE_AS_RAM_SIZE - 1) | MTRRphysMaskValid), %eax
73 movl $CPU_PHYSMASK_HI, %edx
77 movl $MTRRdefType_MSR, %ecx
79 orl $MTRRdefTypeEn, %eax
82 /* Enable L2 cache. */
88 /* Enable cache (CR0.CD = 0, CR0.NW = 0). */
90 andl $(~((1 << 30) | (1 << 29))), %eax
94 /* Clear the cache memory reagion. */
95 movl $CACHE_AS_RAM_BASE, %esi
97 movl $(CACHE_AS_RAM_SIZE / 4), %ecx
98 // movl $0x23322332, %eax
102 /* Enable Cache-as-RAM mode by disabling cache. */
107 #if CONFIG_XIP_ROM_SIZE
108 /* Enable cache for our code in Flash because we do XIP here */
109 movl $MTRRphysBase_MSR(1), %ecx
112 * IMPORTANT: The following calculation _must_ be done at runtime. See
113 * http://www.coreboot.org/pipermail/coreboot/2010-October/060855.html
115 movl $copy_and_run, %eax
116 andl $(~(CONFIG_XIP_ROM_SIZE - 1)), %eax
117 orl $MTRR_TYPE_WRBACK, %eax
120 movl $MTRRphysMask_MSR(1), %ecx
121 movl $CPU_PHYSMASK_HI, %edx
122 movl $(~(CONFIG_XIP_ROM_SIZE - 1) | MTRRphysMaskValid), %eax
124 #endif /* CONFIG_XIP_ROM_SIZE */
128 andl $(~((1 << 30) | (1 << 29))), %eax
131 /* Set up the stack pointer. */
133 /* Leave some space for the struct ehci_debug_info. */
134 movl $(CACHE_AS_RAM_BASE + CACHE_AS_RAM_SIZE - 4 - 128), %eax
136 movl $(CACHE_AS_RAM_BASE + CACHE_AS_RAM_SIZE - 4), %eax
140 /* Restore the BIST result. */
147 /* Call romstage.c main function. */
162 movl $MTRRdefType_MSR, %ecx
164 andl $(~MTRRdefTypeEn), %eax
173 movl $MTRRphysBase_MSR(0), %ecx
175 movl $MTRRphysMask_MSR(0), %ecx
177 movl $MTRRphysBase_MSR(1), %ecx
179 movl $MTRRphysMask_MSR(1), %ecx
187 andl $~((1 << 30) | (1 << 29)), %eax
199 /* Enable Write Back and Speculative Reads for the first 1MB. */
200 movl $MTRRphysBase_MSR(0), %ecx
201 movl $(0x00000000 | MTRR_TYPE_WRBACK), %eax
204 movl $MTRRphysMask_MSR(0), %ecx
205 movl $(~(CONFIG_RAMTOP - 1) | MTRRphysMaskValid), %eax
206 movl $CPU_PHYSMASK_HI, %edx
209 /* Enable caching and Speculative Reads for Flash ROM device. */
210 movl $MTRRphysBase_MSR(1), %ecx
211 movl $(CACHE_ROM_BASE | MTRR_TYPE_WRPROT), %eax
214 movl $MTRRphysMask_MSR(1), %ecx
215 movl $(~(CONFIG_CACHE_ROM_SIZE - 1) | MTRRphysMaskValid), %eax
216 movl $CPU_PHYSMASK_HI, %edx
221 /* And enable cache again after setting MTRRs. */
223 andl $~((1 << 30) | (1 << 29)), %eax
229 movl $MTRRdefType_MSR, %ecx
231 orl $MTRRdefTypeEn, %eax
236 /* Invalidate the cache again. */
241 /* Clear boot_complete flag. */
244 post_code(POST_PREPARE_RAMSTAGE)
245 cld /* Clear direction flag. */
249 movl $ROMSTAGE_STACK, %esp
255 post_code(POST_DEAD_CODE)
261 .word 0x250, 0x258, 0x259
262 .word 0x268, 0x269, 0x26A
263 .word 0x26B, 0x26C, 0x26D
266 .word 0x200, 0x201, 0x202, 0x203
267 .word 0x204, 0x205, 0x206, 0x207
268 .word 0x208, 0x209, 0x20A, 0x20B
269 .word 0x20C, 0x20D, 0x20E, 0x20F