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>
30 #include <console/post_codes.h>
32 #define CacheSize CONFIG_DCACHE_RAM_SIZE
33 #define CacheBase CONFIG_DCACHE_RAM_BASE
35 /* Save the BIST result. */
46 /* Set the default memory type and enable fixed and variable MTRRs. */
47 movl $MTRRdefType_MSR, %ecx
49 movl $(MTRRdefTypeEn | MTRRdefTypeFixEn), %eax
52 /* Clear all MTRRs. */
54 movl $all_mtrr_msrs, %esi
59 jz clear_fixed_var_mtrr_out
65 jmp clear_fixed_var_mtrr
69 .long MTRRfix64K_00000_MSR
70 .long MTRRfix16K_80000_MSR
71 .long MTRRfix16K_A0000_MSR
72 .long MTRRfix4K_C0000_MSR
73 .long MTRRfix4K_C8000_MSR
74 .long MTRRfix4K_D0000_MSR
75 .long MTRRfix4K_D8000_MSR
76 .long MTRRfix4K_E0000_MSR
77 .long MTRRfix4K_E8000_MSR
78 .long MTRRfix4K_F0000_MSR
79 .long MTRRfix4K_F8000_MSR
82 .long MTRRphysBase_MSR(0)
83 .long MTRRphysMask_MSR(0)
84 .long MTRRphysBase_MSR(1)
85 .long MTRRphysMask_MSR(1)
86 .long MTRRphysBase_MSR(2)
87 .long MTRRphysMask_MSR(2)
88 .long MTRRphysBase_MSR(3)
89 .long MTRRphysMask_MSR(3)
90 .long MTRRphysBase_MSR(4)
91 .long MTRRphysMask_MSR(4)
92 .long MTRRphysBase_MSR(5)
93 .long MTRRphysMask_MSR(5)
94 .long MTRRphysBase_MSR(6)
95 .long MTRRphysMask_MSR(6)
96 .long MTRRphysBase_MSR(7)
97 .long MTRRphysMask_MSR(7)
99 .long 0x000 /* NULL, end of table */
101 clear_fixed_var_mtrr_out:
102 movl $MTRRphysBase_MSR(0), %ecx
104 movl $(CacheBase | MTRR_TYPE_WRBACK), %eax
107 movl $MTRRphysMask_MSR(0), %ecx
108 /* This assumes we never access addresses above 2^36 in CAR. */
109 movl $0x0000000f, %edx
110 movl $(~(CacheSize - 1) | MTRRphysMaskValid), %eax
114 * Enable write base caching so we can do execute in place (XIP)
117 movl $MTRRphysBase_MSR(1), %ecx
120 * IMPORTANT: The following calculation _must_ be done at runtime. See
121 * http://www.coreboot.org/pipermail/coreboot/2010-October/060855.html
123 movl $copy_and_run, %eax
124 andl $(~(CONFIG_XIP_ROM_SIZE - 1)), %eax
125 orl $MTRR_TYPE_WRBACK, %eax
128 movl $MTRRphysMask_MSR(1), %ecx
129 movl $0x0000000f, %edx
130 movl $(~(CONFIG_XIP_ROM_SIZE - 1) | MTRRphysMaskValid), %eax
133 /* Set the default memory type and enable fixed and variable MTRRs. */
134 /* TODO: Or also enable fixed MTRRs? Bug in the code? */
135 movl $MTRRdefType_MSR, %ecx
137 movl $(MTRRdefTypeEn), %eax
142 andl $(~((1 << 30) | (1 << 29))), %eax
145 /* Read the range with lodsl. */
147 movl $CacheBase, %esi
149 movl $(CacheSize >> 2), %ecx
152 movl $CacheBase, %esi
154 movl $(CacheSize >> 2), %ecx
157 * 0x5c5c5c5c is a memory test pattern.
158 * TODO: Check if everything works with the zero pattern as well.
160 /* xorl %eax, %eax */
161 xorl $0x5c5c5c5c, %eax
166 * IMPORTANT: The following calculation _must_ be done at runtime. See
167 * http://www.coreboot.org/pipermail/coreboot/2010-October/060855.html
169 movl $copy_and_run, %esi
170 andl $(~(CONFIG_XIP_ROM_SIZE - 1)), %ei
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 area to speedup coreboot code. */
244 movl $MTRRphysBase_MSR(1), %ecx
247 * IMPORTANT: The following calculation _must_ be done at runtime. See
248 * http://www.coreboot.org/pipermail/coreboot/2010-October/060855.html
250 movl $copy_and_run, %eax
251 andl $(~(CONFIG_XIP_ROM_SIZE - 1)), %eax
252 orl $MTRR_TYPE_WRBACK, %eax
255 movl $MTRRphysMask_MSR(1), %ecx
257 movl $(~(CONFIG_XIP_ROM_SIZE - 1) | MTRRphysMaskValid), %eax
262 andl $(~((1 << 30) | (1 << 29))), %eax
266 /* Clear boot_complete flag. */
269 post_code(POST_PREPARE_RAMSTAGE)
270 cld /* Clear direction flag. */
274 movl $ROMSTAGE_STACK, %esp
280 post_code(POST_DEAD_CODE)