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 * SPDX-License-Identifier: GPL-2.0+
16 #ifndef __X86_CONTROL_REGS_H
17 #define __X86_CONTROL_REGS_H
20 * The memory clobber prevents the GCC from reordering the read/write order
23 static inline unsigned long read_cr0(void)
27 asm volatile ("movl %%cr0, %0" : "=r" (val) : : "memory");
31 static inline void write_cr0(unsigned long val)
33 asm volatile ("movl %0, %%cr0" : : "r" (val) : "memory");
36 static inline unsigned long read_cr2(void)
40 asm volatile("mov %%cr2,%0\n\t" : "=r" (val) : : "memory");
44 static inline unsigned long read_cr3(void)
48 asm volatile("mov %%cr3,%0\n\t" : "=r" (val) : : "memory");
52 static inline unsigned long read_cr4(void)
56 asm volatile("mov %%cr4,%0\n\t" : "=r" (val) : : "memory");
60 static inline unsigned long get_debugreg(int regno)
62 unsigned long val = 0; /* Damn you, gcc! */
66 asm("mov %%db0, %0" : "=r" (val));
69 asm("mov %%db1, %0" : "=r" (val));
72 asm("mov %%db2, %0" : "=r" (val));
75 asm("mov %%db3, %0" : "=r" (val));
78 asm("mov %%db6, %0" : "=r" (val));
81 asm("mov %%db7, %0" : "=r" (val));