f5f4ff856eb07914a89cb4199ff7d8812a268007
[coreboot.git] / src / cpu / intel / model_106cx / cache_as_ram_post.c
1 /*
2  * This file is part of the coreboot project.
3  * 
4  * Copyright (C) 2007-2008 coresystems GmbH
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19
20         __asm__ volatile (
21
22         "movb   $0x30, %al\noutb %al, $0x80\n"
23
24         /* Disable Cache */
25         "movl   %cr0, %eax\n"
26         "orl    $(1 << 30), %eax\n"
27         "movl   %eax, %cr0\n"
28
29         "movb   $0x31, %al\noutb %al, $0x80\n"
30
31         /* Disable MTRR */
32         "movl   $MTRRdefType_MSR, %ecx\n"
33         "rdmsr\n"
34         "andl   $(~(1 << 11)), %eax\n"
35         "wrmsr\n"
36
37         "movb   $0x32, %al\noutb %al, $0x80\n"
38
39         "invd\n"
40 #if 0
41         "xorl   %eax, %eax\n"
42         "xorl   %edx, %edx\n"
43         "movl   $MTRRphysBase_MSR(0), %ecx\n"
44         "wrmsr\n"
45         "movl   $MTRRphysMask_MSR(0), %ecx\n"
46         "wrmsr\n"
47         "movl   $MTRRphysBase_MSR(1), %ecx\n"
48         "wrmsr\n"
49         "movl   $MTRRphysMask_MSR(1), %ecx\n"
50         "wrmsr\n"
51 #endif
52
53         "movb   $0x33, %al\noutb %al, $0x80\n"
54 #ifdef CLEAR_FIRST_1M_RAM
55         "movb   $0x34, %al\noutb %al, $0x80\n"
56         /* Enable Write Combining and Speculative Reads for the first 1MB */
57         "movl   $MTRRphysBase_MSR(0), %ecx\n"
58         "movl   $(0x00000000 | MTRR_TYPE_WRCOMB), %eax\n"
59         "xorl   %edx, %edx\n"
60         "wrmsr\n"
61         "movl   $MTRRphysMask_MSR(0), %ecx\n"
62         "movl   $(~(1024*1024 -1) | (1 << 11)), %eax\n"
63         "movl   $0x0000000f, %edx\n"    // 36bit address space
64         "wrmsr\n"
65         "movb   $0x35, %al\noutb %al, $0x80\n"
66 #endif
67
68         /* Enable Cache */
69         "movl   %cr0, %eax\n"
70         "andl    $~( (1 << 30) | (1 << 29) ), %eax\n"
71         "movl   %eax, %cr0\n"
72
73         "movb   $0x36, %al\noutb %al, $0x80\n"
74 #ifdef CLEAR_FIRST_1M_RAM
75
76         /* Clear first 1MB of RAM */
77         "movl   $0x00000000, %edi\n"
78         "cld\n"
79         "xorl   %eax, %eax\n"
80         "movl   $((1024*1024) / 4), %ecx\n"
81         "rep stosl\n"
82         
83         "movb   $0x37, %al\noutb %al, $0x80\n"
84 #endif
85
86         /* Disable Cache */
87         "movl   %cr0, %eax\n"
88         "orl    $(1 << 30), %eax\n"
89         "movl   %eax, %cr0\n"
90
91         "movb   $0x38, %al\noutb %al, $0x80\n"
92
93         /* Enable Write Back and Speculative Reads for the first 1MB */
94         "movl   $MTRRphysBase_MSR(0), %ecx\n"
95         "movl   $(0x00000000 | MTRR_TYPE_WRBACK), %eax\n"
96         "xorl   %edx, %edx\n"
97         "wrmsr\n"
98         "movl   $MTRRphysMask_MSR(0), %ecx\n"
99         "movl   $(~(1024*1024 -1) | (1 << 11)), %eax\n"
100         "movl   $0x0000000f, %edx\n"    // 36bit address space
101         "wrmsr\n"
102
103         "movb   $0x39, %al\noutb %al, $0x80\n"
104
105         /* And Enable Cache again after setting MTRRs */
106         "movl   %cr0, %eax\n"
107         "andl    $~( (1 << 30) | (1 << 29) ), %eax\n"
108         "movl   %eax, %cr0\n"
109
110         "movb   $0x3a, %al\noutb %al, $0x80\n"
111
112         /* Enable MTRR */
113         "movl   $MTRRdefType_MSR, %ecx\n"
114         "rdmsr\n"
115         "orl    $(1 << 11), %eax\n"
116         "wrmsr\n"
117
118         "movb   $0x3b, %al\noutb %al, $0x80\n"
119
120         /* Invalidate the cache again */
121         "invd\n"
122         "movb   $0x3c, %al\noutb %al, $0x80\n"
123         );