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 CACHE_AS_RAM_SIZE CONFIG_DCACHE_RAM_SIZE
26 #define CACHE_AS_RAM_BASE CONFIG_DCACHE_RAM_BASE
28 /* Save the BIST result. */
34 /* Send INIT IPI to all excluding ourself. */
35 movl $0x000C4500, %eax
36 movl $0xFEE00300, %esi
39 /* Disable prefetchers */
42 orl $((1 << 9) | (1 << 19)), %eax
43 orl $((1 << 5) | (1 << 7)), %edx
46 /* Zero out all fixed range and variable range MTRRs. */
47 movl $mtrr_table, %esi
48 movl $((mtrr_table_end - mtrr_table) / 2), %edi
59 /* Configure the default memory type to uncacheable. */
60 movl $MTRRdefType_MSR, %ecx
62 andl $(~0x00000cff), %eax
65 /* Set Cache-as-RAM base address. */
66 movl $(MTRRphysBase_MSR(0)), %ecx
67 movl $(CACHE_AS_RAM_BASE | MTRR_TYPE_WRBACK), %eax
71 /* Set Cache-as-RAM mask. */
72 movl $(MTRRphysMask_MSR(0)), %ecx
73 movl $(~((CACHE_AS_RAM_SIZE - 1)) | (1 << 11)), %eax
74 movl $0x0000000f, %edx
78 movl $MTRRdefType_MSR, %ecx
83 /* Enable L2 cache. */
89 /* Enable cache (CR0.CD = 0, CR0.NW = 0). */
91 andl $(~((1 << 30) | (1 << 29))), %eax
95 /* Clear the cache memory reagion. */
96 movl $CACHE_AS_RAM_BASE, %esi
98 movl $(CACHE_AS_RAM_SIZE / 4), %ecx
99 // movl $0x23322332, %eax
103 /* Enable Cache-as-RAM mode by disabling cache. */
108 #if defined(CONFIG_XIP_ROM_SIZE) && defined(CONFIG_XIP_ROM_BASE)
109 /* Enable cache for our code in Flash because we do XIP here */
110 movl $MTRRphysBase_MSR(1), %ecx
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
118 * IMPORTANT: The two lines below can _not_ be written like this:
119 * movl $(REAL_XIP_ROM_BASE | MTRR_TYPE_WRBACK), %eax
120 * http://www.coreboot.org/pipermail/coreboot/2010-October/060855.html
122 movl $REAL_XIP_ROM_BASE, %eax
123 orl $MTRR_TYPE_WRBACK, %eax
126 movl $MTRRphysMask_MSR(1), %ecx
127 movl $0x0000000f, %edx
128 movl $(~(CONFIG_XIP_ROM_SIZE - 1) | 0x800), %eax
130 #endif /* CONFIG_XIP_ROM_SIZE && CONFIG_XIP_ROM_BASE */
134 andl $(~((1 << 30) | (1 << 29))), %eax
137 /* Set up the stack pointer. */
138 #if defined(CONFIG_USBDEBUG) && (CONFIG_USBDEBUG == 1)
139 /* Leave some space for the struct ehci_debug_info. */
140 movl $(CACHE_AS_RAM_BASE + CACHE_AS_RAM_SIZE - 4 - 128), %eax
142 movl $(CACHE_AS_RAM_BASE + CACHE_AS_RAM_SIZE - 4), %eax
146 /* Restore the BIST result. */
153 /* Call romstage.c main function. */
168 movl $MTRRdefType_MSR, %ecx
170 andl $(~(1 << 11)), %eax
179 movl $MTRRphysBase_MSR(0), %ecx
181 movl $MTRRphysMask_MSR(0), %ecx
183 movl $MTRRphysBase_MSR(1), %ecx
185 movl $MTRRphysMask_MSR(1), %ecx
193 andl $~((1 << 30) | (1 << 29)), %eax
205 /* Enable Write Back and Speculative Reads for the first 1MB. */
206 movl $MTRRphysBase_MSR(0), %ecx
207 movl $(0x00000000 | MTRR_TYPE_WRBACK), %eax
210 movl $MTRRphysMask_MSR(0), %ecx
211 movl $(~(1024 * 1024 - 1) | (1 << 11)), %eax
212 movl $0x0000000f, %edx // 36bit address space
217 /* And enable cache again after setting MTRRs. */
219 andl $~((1 << 30) | (1 << 29)), %eax
225 movl $MTRRdefType_MSR, %ecx
232 /* Enable prefetchers */
235 andl $~((1 << 9) | (1 << 19)), %eax
236 andl $~((1 << 5) | (1 << 7)), %edx
239 /* Invalidate the cache again. */
244 /* Clear boot_complete flag. */
247 post_code(POST_PREPARE_RAMSTAGE)
248 cld /* Clear direction flag. */
252 movl $ROMSTAGE_STACK, %esp
258 post_code(POST_DEAD_CODE)
264 .word 0x250, 0x258, 0x259
265 .word 0x268, 0x269, 0x26A
266 .word 0x26B, 0x26C, 0x26D
269 .word 0x200, 0x201, 0x202, 0x203
270 .word 0x204, 0x205, 0x206, 0x207
271 .word 0x208, 0x209, 0x20A, 0x20B
272 .word 0x20C, 0x20D, 0x20E, 0x20F