2 * Copyright (c) 2012 The Chromium OS Authors.
4 * (C) Copyright 2008-2011
5 * Graeme Russ, <graeme.russ@gmail.com>
8 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
10 * Portions of this file are derived from the Linux kernel source
11 * Copyright (C) 1991, 1992 Linus Torvalds
13 * See file CREDITS for list of people who contributed to this
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.
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.
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,
32 #ifndef __X86_CONTROL_REGS_H
33 #define __X86_CONTROL_REGS_H
36 * The memory clobber prevents the GCC from reordering the read/write order
39 static inline unsigned long read_cr0(void)
43 asm volatile ("movl %%cr0, %0" : "=r" (val) : : "memory");
47 static inline void write_cr0(unsigned long val)
49 asm volatile ("movl %0, %%cr0" : : "r" (val) : "memory");
52 static inline unsigned long read_cr2(void)
56 asm volatile("mov %%cr2,%0\n\t" : "=r" (val) : : "memory");
60 static inline unsigned long read_cr3(void)
64 asm volatile("mov %%cr3,%0\n\t" : "=r" (val) : : "memory");
68 static inline unsigned long read_cr4(void)
72 asm volatile("mov %%cr4,%0\n\t" : "=r" (val) : : "memory");
76 static inline unsigned long get_debugreg(int regno)
78 unsigned long val = 0; /* Damn you, gcc! */
82 asm("mov %%db0, %0" : "=r" (val));
85 asm("mov %%db1, %0" : "=r" (val));
88 asm("mov %%db2, %0" : "=r" (val));
91 asm("mov %%db3, %0" : "=r" (val));
94 asm("mov %%db6, %0" : "=r" (val));
97 asm("mov %%db7, %0" : "=r" (val));