blob: 175b1e84be2f6d10e1169a0c8d2c3e3b30cadf02 [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.
Aaron Durbin029aaf62013-10-10 12:41:49 -050015 */
16#ifndef CPU_X86_CR_H
17#define CPU_X86_CR_H
18
19#if !defined(__ASSEMBLER__)
20
21#include <stdint.h>
22#include <arch/cpu.h>
23
24/* ROMCC apparently chokes certain clobber registers. */
25#if defined(__ROMCC__)
26#define COMPILER_BARRIER
27#else
28#define COMPILER_BARRIER "memory"
29#endif
30
Stefan Reinauerbef400b2015-06-17 16:11:18 -070031#ifdef __x86_64__
32#define CRx_TYPE uint64_t
33#define CRx_IN "q"
34#define CRx_RET "=q"
35#else
36#define CRx_TYPE uint32_t
37#define CRx_IN "r"
38#define CRx_RET "=r"
39#endif
40static alwaysinline CRx_TYPE read_cr0(void)
Aaron Durbin029aaf62013-10-10 12:41:49 -050041{
Stefan Reinauerbef400b2015-06-17 16:11:18 -070042 CRx_TYPE value;
Aaron Durbin029aaf62013-10-10 12:41:49 -050043 __asm__ __volatile__ (
44 "mov %%cr0, %0"
Stefan Reinauerbef400b2015-06-17 16:11:18 -070045 : CRx_RET (value)
Aaron Durbin029aaf62013-10-10 12:41:49 -050046 :
47 : COMPILER_BARRIER
48 );
49 return value;
50}
51
Stefan Reinauerbef400b2015-06-17 16:11:18 -070052static alwaysinline void write_cr0(CRx_TYPE data)
Aaron Durbin029aaf62013-10-10 12:41:49 -050053{
54 __asm__ __volatile__ (
55 "mov %0, %%cr0"
56 :
Stefan Reinauerbef400b2015-06-17 16:11:18 -070057 : CRx_IN (data)
Aaron Durbin029aaf62013-10-10 12:41:49 -050058 : COMPILER_BARRIER
59 );
60}
61
Stefan Reinauerbef400b2015-06-17 16:11:18 -070062static alwaysinline CRx_TYPE read_cr4(void)
Aaron Durbin029aaf62013-10-10 12:41:49 -050063{
Stefan Reinauerbef400b2015-06-17 16:11:18 -070064 CRx_TYPE value;
Aaron Durbin029aaf62013-10-10 12:41:49 -050065 __asm__ __volatile__ (
66 "mov %%cr4, %0"
Stefan Reinauerbef400b2015-06-17 16:11:18 -070067 : CRx_RET (value)
Aaron Durbin029aaf62013-10-10 12:41:49 -050068 :
69 : COMPILER_BARRIER
70 );
71 return value;
72}
73
Stefan Reinauerbef400b2015-06-17 16:11:18 -070074static alwaysinline void write_cr4(CRx_TYPE data)
Aaron Durbin029aaf62013-10-10 12:41:49 -050075{
76 __asm__ __volatile__ (
77 "mov %0, %%cr4"
78 :
Stefan Reinauerbef400b2015-06-17 16:11:18 -070079 : CRx_IN (data)
Aaron Durbin029aaf62013-10-10 12:41:49 -050080 : COMPILER_BARRIER
81 );
82}
83
84#endif /* !defined(__ASSEMBLER__) */
85
86/* CR0 flags */
87#define CR0_PE (1 << 0)
88#define CR0_MP (1 << 1)
89#define CR0_EM (1 << 2)
90#define CR0_TS (1 << 3)
91#define CR0_ET (1 << 4)
92#define CR0_NE (1 << 5)
93#define CR0_WP (1 << 16)
94#define CR0_AM (1 << 18)
95#define CR0_NW (1 << 29)
96#define CR0_CD (1 << 30)
97#define CR0_PG (1 << 31)
98
99/* CR4 flags */
100#define CR4_VME (1 << 0)
101#define CR4_PVI (1 << 1)
102#define CR4_TSD (1 << 2)
103#define CR4_DE (1 << 3)
104#define CR4_PSE (1 << 4)
105#define CR4_PAE (1 << 5)
106#define CR4_MCE (1 << 6)
107#define CR4_PGE (1 << 7)
108#define CR4_PCE (1 << 8)
109#define CR4_OSFXSR (1 << 9)
110#define CR4_OSXMMEXCPT (1 << 10)
111#define CR4_VMXE (1 << 13)
112#define CR4_SMXE (1 << 14)
113#define CR4_FSGSBASE (1 << 16)
114#define CR4_PCIDE (1 << 17)
115#define CR4_OSXSAVE (1 << 18)
116#define CR4_SMEP (1 << 20)
117
118#endif /* CPU_X86_CR_H */