2 * This file is part of the coreboot project.
4 * Copyright (C) 2000,2007 Ronald G. Minnich <rminnich@gmail.com>
5 * Copyright (C) 2005 Eswar Nallusamy, LANL
6 * Copyright (C) 2005 Tyan
7 * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
8 * Copyright (C) 2007 coresystems GmbH
9 * (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH)
10 * Copyright (C) 2007,2008 Carl-Daniel Hailfinger
11 * Copyright (C) 2008 VIA Technologies, Inc.
12 * (Written by Jason Zhao <jasonzhao@viatech.com.cn> for VIA)
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; version 2 of the License.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <cpu/x86/stack.h>
29 #include <cpu/x86/mtrr.h>
31 #define CacheSize CONFIG_DCACHE_RAM_SIZE
32 #define CacheBase CONFIG_DCACHE_RAM_BASE
34 /* Save the BIST result. */
45 /* Set the default memory type and enable fixed and variable MTRRs. */
46 movl $MTRRdefType_MSR, %ecx
48 movl $(MTRRdefTypeEn | MTRRdefTypeFixEn), %eax
51 /* Clear all MTRRs. */
53 movl $all_mtrr_msrs, %esi
58 jz clear_fixed_var_mtrr_out
64 jmp clear_fixed_var_mtrr
68 .long MTRRfix64K_00000_MSR
69 .long MTRRfix16K_80000_MSR
70 .long MTRRfix16K_A0000_MSR
71 .long MTRRfix4K_C0000_MSR
72 .long MTRRfix4K_C8000_MSR
73 .long MTRRfix4K_D0000_MSR
74 .long MTRRfix4K_D8000_MSR
75 .long MTRRfix4K_E0000_MSR
76 .long MTRRfix4K_E8000_MSR
77 .long MTRRfix4K_F0000_MSR
78 .long MTRRfix4K_F8000_MSR
81 .long MTRRphysBase_MSR(0)
82 .long MTRRphysMask_MSR(0)
83 .long MTRRphysBase_MSR(1)
84 .long MTRRphysMask_MSR(1)
85 .long MTRRphysBase_MSR(2)
86 .long MTRRphysMask_MSR(2)
87 .long MTRRphysBase_MSR(3)
88 .long MTRRphysMask_MSR(3)
89 .long MTRRphysBase_MSR(4)
90 .long MTRRphysMask_MSR(4)
91 .long MTRRphysBase_MSR(5)
92 .long MTRRphysMask_MSR(5)
93 .long MTRRphysBase_MSR(6)
94 .long MTRRphysMask_MSR(6)
95 .long MTRRphysBase_MSR(7)
96 .long MTRRphysMask_MSR(7)
98 .long 0x000 /* NULL, end of table */
100 clear_fixed_var_mtrr_out:
101 movl $MTRRphysBase_MSR(0), %ecx
103 movl $(CacheBase | MTRR_TYPE_WRBACK), %eax
106 movl $MTRRphysMask_MSR(0), %ecx
107 /* This assumes we never access addresses above 2^36 in CAR. */
108 movl $0x0000000f, %edx
109 movl $(~(CacheSize - 1) | MTRRphysMaskValid), %eax
112 #if defined(CONFIG_TINY_BOOTBLOCK) && CONFIG_TINY_BOOTBLOCK
113 #define REAL_XIP_ROM_BASE AUTO_XIP_ROM_BASE
115 #define REAL_XIP_ROM_BASE CONFIG_XIP_ROM_BASE
119 * Enable write base caching so we can do execute in place (XIP)
122 movl $MTRRphysBase_MSR(1), %ecx
125 * IMPORTANT: The two lines below can _not_ be written like this:
126 * movl $(REAL_XIP_ROM_BASE | MTRR_TYPE_WRBACK), %eax
127 * http://www.coreboot.org/pipermail/coreboot/2010-October/060855.html
129 movl $REAL_XIP_ROM_BASE, %eax
130 orl $MTRR_TYPE_WRBACK, %eax
133 movl $MTRRphysMask_MSR(1), %ecx
134 movl $0x0000000f, %edx
135 movl $(~(CONFIG_XIP_ROM_SIZE - 1) | MTRRphysMaskValid), %eax
138 /* Set the default memory type and enable fixed and variable MTRRs. */
139 /* TODO: Or also enable fixed MTRRs? Bug in the code? */
140 movl $MTRRdefType_MSR, %ecx
142 movl $(MTRRdefTypeEn), %eax
147 andl $(~((1 << 30) | (1 << 29))), %eax
150 /* Read the range with lodsl. */
152 movl $CacheBase, %esi
154 movl $(CacheSize >> 2), %ecx
157 movl $CacheBase, %esi
159 movl $(CacheSize >> 2), %ecx
162 * 0x5c5c5c5c is a memory test pattern.
163 * TODO: Check if everything works with the zero pattern as well.
165 /* xorl %eax, %eax */
166 xorl $0x5c5c5c5c, %eax
170 movl REAL_XIP_ROM_BASE, %esi
172 movl $(CONFIG_XIP_ROM_SIZE >> 2), %ecx
177 * The key point of this CAR code is C7 cache does not turn into
178 * "no fill" mode, which is not compatible with general CAR code.
181 movl $(CacheBase + CacheSize - 4), %eax
204 /* Restore the BIST result. */
207 /* We need to set EBP? No need. */
209 pushl %eax /* BIST */
213 * TODO: Backup stack in CACHE_AS_RAM into MMX and SSE and after we
214 * get STACK up, we restore that. It is only needed if we
218 /* We don't need CAR from now on. */
225 /* Set the default memory type and enable variable MTRRs. */
226 /* TODO: Or also enable fixed MTRRs? Bug in the code? */
227 movl $MTRRdefType_MSR, %ecx
229 movl $(MTRRdefTypeEn), %eax
232 /* Enable caching for CONFIG_RAMBASE..CONFIG_RAMTOP. */
233 movl $MTRRphysBase_MSR(0), %ecx
235 movl $(CONFIG_RAMBASE | MTRR_TYPE_WRBACK), %eax
238 movl $MTRRphysMask_MSR(0), %ecx
239 movl $0x0000000f, %edx /* AMD 40 bit 0xff */
240 movl $(~(CONFIG_RAMTOP - CONFIG_RAMBASE - 1) | MTRRphysMaskValid), %eax
243 /* Cache XIP_ROM_BASE-SIZE to speedup coreboot code. */
244 movl $MTRRphysBase_MSR(1), %ecx
246 movl $REAL_XIP_ROM_BASE, %eax
247 orl $MTRR_TYPE_WRBACK, %eax
250 movl $MTRRphysMask_MSR(1), %ecx
252 movl $(~(CONFIG_XIP_ROM_SIZE - 1) | MTRRphysMaskValid), %eax
257 andl $(~((1 << 30) | (1 << 29))), %eax
261 /* Clear boot_complete flag. */
265 cld /* Clear direction flag. */
269 movl $ROMSTAGE_STACK, %esp