blob: aa8be30bac751407d097191d75afeced1230c846 [file] [log] [blame]
Stefan Reinauer095593c2012-12-02 04:49:50 +00001/*
2 * Copyright (c) 2012 The Chromium OS Authors.
3 *
4 * (C) Copyright 2008-2011
5 * Graeme Russ, <graeme.russ@gmail.com>
6 *
7 * (C) Copyright 2002
8 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
9 *
10 * Portions of this file are derived from the Linux kernel source
11 * Copyright (C) 1991, 1992 Linus Torvalds
12 *
13 * See file CREDITS for list of people who contributed to this
14 * project.
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 */
31
32#ifndef __X86_CONTROL_REGS_H
33#define __X86_CONTROL_REGS_H
34
35/*
36 * The memory clobber prevents the GCC from reordering the read/write order
37 * of CR0
38*/
39static inline unsigned long read_cr0(void)
40{
41 unsigned long val;
42
43 asm volatile ("movl %%cr0, %0" : "=r" (val) : : "memory");
44 return val;
45}
46
47static inline void write_cr0(unsigned long val)
48{
49 asm volatile ("movl %0, %%cr0" : : "r" (val) : "memory");
50}
51
52static inline unsigned long read_cr2(void)
53{
54 unsigned long val;
55
56 asm volatile("mov %%cr2,%0\n\t" : "=r" (val) : : "memory");
57 return val;
58}
59
60static inline unsigned long read_cr3(void)
61{
62 unsigned long val;
63
64 asm volatile("mov %%cr3,%0\n\t" : "=r" (val) : : "memory");
65 return val;
66}
67
68static inline unsigned long read_cr4(void)
69{
70 unsigned long val;
71
72 asm volatile("mov %%cr4,%0\n\t" : "=r" (val) : : "memory");
73 return val;
74}
75
76static inline unsigned long get_debugreg(int regno)
77{
78 unsigned long val = 0; /* Damn you, gcc! */
79
80 switch (regno) {
81 case 0:
82 asm("mov %%db0, %0" : "=r" (val));
83 break;
84 case 1:
85 asm("mov %%db1, %0" : "=r" (val));
86 break;
87 case 2:
88 asm("mov %%db2, %0" : "=r" (val));
89 break;
90 case 3:
91 asm("mov %%db3, %0" : "=r" (val));
92 break;
93 case 6:
94 asm("mov %%db6, %0" : "=r" (val));
95 break;
96 case 7:
97 asm("mov %%db7, %0" : "=r" (val));
98 break;
99 default:
100 val = 0;
101 }
102 return val;
103}
104
105#endif