2 * This file is part of the coreboot project.
4 * Copyright (C) 2004 Eric W. Biederman
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.
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.
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
24 * Need two versions because ROMCC chokes on certain clobbers:
25 * cache.h:29.71: cache.h:60.24: earlymtrr.c:117.23: romstage.c:144.33:
26 * 0x1559920 asm Internal compiler error: lhs 1 regcm == 0
31 /* The memory clobber prevents the GCC from reordering the read/write order
34 static inline unsigned long read_cr0(void)
37 asm volatile ("movl %%cr0, %0" : "=r" (cr0) :: "memory");
41 static inline void write_cr0(unsigned long cr0)
43 asm volatile ("movl %0, %%cr0" : : "r" (cr0) : "memory");
46 static inline void wbinvd(void)
48 asm volatile ("wbinvd" ::: "memory");
53 static inline unsigned long read_cr0(void)
56 asm volatile ("movl %%cr0, %0" : "=r" (cr0));
60 static inline void write_cr0(unsigned long cr0)
62 asm volatile ("movl %0, %%cr0" : : "r" (cr0));
65 static inline void wbinvd(void)
67 asm volatile ("wbinvd");
72 static inline void invd(void)
74 asm volatile("invd" ::: "memory");
77 /* The following functions require the always_inline due to AMD
78 * function STOP_CAR_AND_CPU that disables cache as
79 * ram, the cache as ram stack can no longer be used. Called
80 * functions must be inlined to avoid stack usage. Also, the
81 * compiler must keep local variables register based and not
82 * allocated them from the stack. With gcc 4.5.0, some functions
83 * declared as inline are not being inlined. This patch forces
84 * these functions to always be inlined by adding the qualifier
85 * __attribute__((always_inline)) to their declaration.
87 static inline __attribute__((always_inline)) void enable_cache(void)
95 static inline __attribute__((always_inline)) void disable_cache(void)
97 /* Disable and write back the cache */
106 #if !defined(__PRE_RAM__)
107 void x86_enable_cache(void);
110 #endif /* CPU_X86_CACHE */