20967eae550b061fe6ee300a0a81d1168fd8e5f6
[coreboot.git] / src / cpu / intel / model_6ex / cache_as_ram.inc
1 /* 
2  * This file is part of the coreboot project.
3  * 
4  * Copyright (C) 2000,2007 Ronald G. Minnich <rminnich@gmail.com>
5  * Copyright (C) 2007-2008 coresystems GmbH
6  * 
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.
10  * 
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.
15  * 
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
19  */
20
21 #define CACHE_AS_RAM_SIZE DCACHE_RAM_SIZE
22 #define CACHE_AS_RAM_BASE DCACHE_RAM_BASE
23 #define post_code(x) intel_chip_post_macro(x)
24
25 #include <cpu/x86/mtrr.h>
26 #include <cpu/amd/mtrr.h>
27
28         /* Save the BIST result */
29         movl    %eax, %ebp
30
31 cache_as_ram:
32 #if USE_FALLBACK_IMAGE == 1
33
34         post_code(0x20)
35
36         /* Send INIT IPI to all excluding ourself */
37         movl    $0x000C4500, %eax
38         movl    $0xFEE00300, %esi
39         movl    %eax, (%esi)
40
41         /* Zero out all Fixed Range and Variable Range MTRRs */
42         movl    $mtrr_table, %esi
43         movl    $( (mtrr_table_end - mtrr_table) / 2), %edi
44         xorl    %eax, %eax
45         xorl    %edx, %edx
46 clear_mtrrs:
47         movw    (%esi), %bx
48         movzx   %bx, %ecx
49         wrmsr
50         add     $2, %esi
51         dec     %edi
52         jnz     clear_mtrrs
53
54         /* Configure the default memory type to uncacheable */
55         movl    $MTRRdefType_MSR, %ecx
56         rdmsr
57         andl    $(~0x00000cff), %eax
58         wrmsr
59
60         /* Set cache as ram base address */
61         movl    $(MTRRphysBase_MSR(0)), %ecx
62         movl    $(CACHE_AS_RAM_BASE | MTRR_TYPE_WRBACK), %eax
63         xorl    %edx, %edx
64         wrmsr
65
66         /* Set cache as ram mask */
67         movl    $(MTRRphysMask_MSR(0)), %ecx
68         movl    $(~((CACHE_AS_RAM_SIZE-1)) | (1 << 11)), %eax
69         movl    $0x0000000f, %edx
70         wrmsr
71
72         /* Enable MTRR */
73         movl    $MTRRdefType_MSR, %ecx
74         rdmsr
75         orl     $(1 << 11), %eax
76         wrmsr
77
78         /* Enable L2 Cache */
79         movl    $0x11e, %ecx
80         rdmsr
81         orl     $(1 << 8), %eax
82         wrmsr
83
84         /* CR0.CD = 0, CR0.NW = 0 */
85         movl    %cr0, %eax
86         andl    $( ~( (1 << 30) | (1 << 29) ) ), %eax
87         invd
88         movl    %eax, %cr0
89
90         /* Clear the cache memory reagion */
91         movl    $CACHE_AS_RAM_BASE, %esi
92         movl    %esi, %edi
93         movl    $(CACHE_AS_RAM_SIZE / 4), %ecx
94         //movl  $0x23322332, %eax
95         xorl    %eax, %eax
96         rep     stosl
97 #endif
98
99         /* Enable Cache As RAM mode by disabling cache */
100         movl    %cr0, %eax
101         orl     $(1 << 30), %eax
102         movl    %eax, %cr0
103
104 #if defined(XIP_ROM_SIZE) && defined(XIP_ROM_BASE)
105         /* Enable cache for our code in Flash because we do XIP here */
106         movl    $MTRRphysBase_MSR(1), %ecx
107         xorl    %edx, %edx
108         movl    $(XIP_ROM_BASE | MTRR_TYPE_WRBACK), %eax
109         wrmsr
110
111         movl    $MTRRphysMask_MSR(1), %ecx
112         movl    $0x0000000f, %edx
113         movl    $(~(XIP_ROM_SIZE - 1) | 0x800), %eax
114         wrmsr
115 #endif /* XIP_ROM_SIZE && XIP_ROM_BASE */
116
117         /* enable cache */
118         movl    %cr0, %eax
119         andl    $( ~( (1 << 30) | (1 << 29) ) ), %eax
120         movl    %eax, %cr0
121
122         /* Set up stack pointer */
123         movl    $(CACHE_AS_RAM_BASE + CACHE_AS_RAM_SIZE - 4), %eax
124         movl    %eax, %esp
125
126         /* Restore the BIST result */
127         movl    %ebp, %eax
128         movl    %esp, %ebp
129         pushl   %eax
130
131         post_code(0x23)
132
133         call    stage1_main
134
135         post_code(0x2f)
136 error:
137         hlt
138         jmp     error
139
140 mtrr_table:
141         /* Fixed MTRRs */
142         .word 0x250, 0x258, 0x259
143         .word 0x268, 0x269, 0x26A
144         .word 0x26B, 0x26C, 0x26D
145         .word 0x26E, 0x26F
146         /* Variable MTRRs */
147         .word 0x200, 0x201, 0x202, 0x203
148         .word 0x204, 0x205, 0x206, 0x207
149         .word 0x208, 0x209, 0x20A, 0x20B
150         .word 0x20C, 0x20D, 0x20E, 0x20F
151 mtrr_table_end:
152