blob: 8f77aec1d3e79931e4ed16de3d2532fff7ebb665 [file] [log] [blame]
Aaron Durbin029aaf62013-10-10 12:41:49 -05001
2/*
3 * This file is part of the coreboot project.
4 *
5 * Copyright (C) 2013 Google Inc.
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
Patrick Georgib890a122015-03-26 15:17:45 +010018 * Foundation, Inc.
Aaron Durbin029aaf62013-10-10 12:41:49 -050019 */
20#ifndef CPU_X86_CR_H
21#define CPU_X86_CR_H
22
23#if !defined(__ASSEMBLER__)
24
25#include <stdint.h>
26#include <arch/cpu.h>
27
28/* ROMCC apparently chokes certain clobber registers. */
29#if defined(__ROMCC__)
30#define COMPILER_BARRIER
31#else
32#define COMPILER_BARRIER "memory"
33#endif
34
Stefan Reinauerbef400b2015-06-17 16:11:18 -070035#ifdef __x86_64__
36#define CRx_TYPE uint64_t
37#define CRx_IN "q"
38#define CRx_RET "=q"
39#else
40#define CRx_TYPE uint32_t
41#define CRx_IN "r"
42#define CRx_RET "=r"
43#endif
44static alwaysinline CRx_TYPE read_cr0(void)
Aaron Durbin029aaf62013-10-10 12:41:49 -050045{
Stefan Reinauerbef400b2015-06-17 16:11:18 -070046 CRx_TYPE value;
Aaron Durbin029aaf62013-10-10 12:41:49 -050047 __asm__ __volatile__ (
48 "mov %%cr0, %0"
Stefan Reinauerbef400b2015-06-17 16:11:18 -070049 : CRx_RET (value)
Aaron Durbin029aaf62013-10-10 12:41:49 -050050 :
51 : COMPILER_BARRIER
52 );
53 return value;
54}
55
Stefan Reinauerbef400b2015-06-17 16:11:18 -070056static alwaysinline void write_cr0(CRx_TYPE data)
Aaron Durbin029aaf62013-10-10 12:41:49 -050057{
58 __asm__ __volatile__ (
59 "mov %0, %%cr0"
60 :
Stefan Reinauerbef400b2015-06-17 16:11:18 -070061 : CRx_IN (data)
Aaron Durbin029aaf62013-10-10 12:41:49 -050062 : COMPILER_BARRIER
63 );
64}
65
Stefan Reinauerbef400b2015-06-17 16:11:18 -070066static alwaysinline CRx_TYPE read_cr4(void)
Aaron Durbin029aaf62013-10-10 12:41:49 -050067{
Stefan Reinauerbef400b2015-06-17 16:11:18 -070068 CRx_TYPE value;
Aaron Durbin029aaf62013-10-10 12:41:49 -050069 __asm__ __volatile__ (
70 "mov %%cr4, %0"
Stefan Reinauerbef400b2015-06-17 16:11:18 -070071 : CRx_RET (value)
Aaron Durbin029aaf62013-10-10 12:41:49 -050072 :
73 : COMPILER_BARRIER
74 );
75 return value;
76}
77
Stefan Reinauerbef400b2015-06-17 16:11:18 -070078static alwaysinline void write_cr4(CRx_TYPE data)
Aaron Durbin029aaf62013-10-10 12:41:49 -050079{
80 __asm__ __volatile__ (
81 "mov %0, %%cr4"
82 :
Stefan Reinauerbef400b2015-06-17 16:11:18 -070083 : CRx_IN (data)
Aaron Durbin029aaf62013-10-10 12:41:49 -050084 : COMPILER_BARRIER
85 );
86}
87
88#endif /* !defined(__ASSEMBLER__) */
89
90/* CR0 flags */
91#define CR0_PE (1 << 0)
92#define CR0_MP (1 << 1)
93#define CR0_EM (1 << 2)
94#define CR0_TS (1 << 3)
95#define CR0_ET (1 << 4)
96#define CR0_NE (1 << 5)
97#define CR0_WP (1 << 16)
98#define CR0_AM (1 << 18)
99#define CR0_NW (1 << 29)
100#define CR0_CD (1 << 30)
101#define CR0_PG (1 << 31)
102
103/* CR4 flags */
104#define CR4_VME (1 << 0)
105#define CR4_PVI (1 << 1)
106#define CR4_TSD (1 << 2)
107#define CR4_DE (1 << 3)
108#define CR4_PSE (1 << 4)
109#define CR4_PAE (1 << 5)
110#define CR4_MCE (1 << 6)
111#define CR4_PGE (1 << 7)
112#define CR4_PCE (1 << 8)
113#define CR4_OSFXSR (1 << 9)
114#define CR4_OSXMMEXCPT (1 << 10)
115#define CR4_VMXE (1 << 13)
116#define CR4_SMXE (1 << 14)
117#define CR4_FSGSBASE (1 << 16)
118#define CR4_PCIDE (1 << 17)
119#define CR4_OSXSAVE (1 << 18)
120#define CR4_SMEP (1 << 20)
121
122#endif /* CPU_X86_CR_H */