1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2012 The Chromium OS Authors.
5 * (C) Copyright 2008-2011
6 * Graeme Russ, <graeme.russ@gmail.com>
9 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
11 * Portions of this file are derived from the Linux kernel source
12 * Copyright (C) 1991, 1992 Linus Torvalds
15 #ifndef __X86_CONTROL_REGS_H
16 #define __X86_CONTROL_REGS_H
19 * The memory clobber prevents the GCC from reordering the read/write order
22 static inline unsigned long read_cr0(void)
26 asm volatile ("movl %%cr0, %0" : "=r" (val) : : "memory");
30 static inline void write_cr0(unsigned long val)
32 asm volatile ("movl %0, %%cr0" : : "r" (val) : "memory");
35 static inline unsigned long read_cr2(void)
39 asm volatile("mov %%cr2,%0\n\t" : "=r" (val) : : "memory");
43 static inline unsigned long read_cr3(void)
47 asm volatile("mov %%cr3,%0\n\t" : "=r" (val) : : "memory");
51 static inline unsigned long read_cr4(void)
55 asm volatile("mov %%cr4,%0\n\t" : "=r" (val) : : "memory");
59 static inline unsigned long get_debugreg(int regno)
61 unsigned long val = 0; /* Damn you, gcc! */
65 asm("mov %%db0, %0" : "=r" (val));
68 asm("mov %%db1, %0" : "=r" (val));
71 asm("mov %%db2, %0" : "=r" (val));
74 asm("mov %%db3, %0" : "=r" (val));
77 asm("mov %%db6, %0" : "=r" (val));
80 asm("mov %%db7, %0" : "=r" (val));