Sorry for this. I fixed that reverting the change for ROMCC.
[coreboot.git] / src / include / cpu / x86 / cache.h
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2004 Eric W. Biederman
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * 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 #ifndef CPU_X86_CACHE
21 #define CPU_X86_CACHE
22
23 /* the memory clobber prevents the GCC from reordering the read/write order
24    of CR0 */
25
26  */
27
28 #if defined(__GNUC__)
29
30 /*
31 Need this because ROMCC fails here with:
32
33 cache.h:29.71: cache.h:60.24: earlymtrr.c:117.23: romstage.c:144.33: 
34 0x1559920 asm        Internal compiler error: lhs 1 regcm == 0
35 */
36
37 static inline unsigned long read_cr0(void)
38 {
39         unsigned long cr0;
40         asm volatile ("movl %%cr0, %0" : "=r" (cr0) :: "memory");
41         return cr0;
42 }
43
44 static inline void write_cr0(unsigned long cr0)
45 {
46         asm volatile ("movl %0, %%cr0" : : "r" (cr0) : "memory");
47 }
48
49 #else
50
51 static inline unsigned long read_cr0(void)
52 {
53         unsigned long cr0;
54         asm volatile ("movl %%cr0, %0" : "=r" (cr0));
55         return cr0;
56 }
57
58 static inline void write_cr0(unsigned long cr0)
59 {
60         asm volatile ("movl %0, %%cr0" : : "r" (cr0));
61 }
62
63 #endif
64
65
66 static inline void invd(void)
67 {
68         asm volatile("invd" ::: "memory");
69 }
70
71 static inline void wbinvd(void)
72 {
73         asm volatile ("wbinvd" ::: "memory");
74 }
75
76 static inline void enable_cache(void)
77 {
78         unsigned long cr0;
79         cr0 = read_cr0();
80         cr0 &= 0x9fffffff;
81         write_cr0(cr0);
82 }
83
84 static inline void disable_cache(void)
85 {
86         /* Disable and write back the cache */
87         unsigned long cr0;
88         cr0 = read_cr0();
89         cr0 |= 0x40000000;
90         wbinvd();
91         write_cr0(cr0);
92         wbinvd();
93 }
94
95 #if !defined(__PRE_RAM__)
96 void x86_enable_cache(void);
97 #endif
98
99 #endif /* CPU_X86_CACHE */