1 /* 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 * SPDX-License-Identifier: GPL-2.0+ 14 */ 15 16 #ifndef __X86_CONTROL_REGS_H 17 #define __X86_CONTROL_REGS_H 18 19 /* 20 * The memory clobber prevents the GCC from reordering the read/write order 21 * of CR0 22 */ 23 static inline unsigned long read_cr0(void) 24 { 25 unsigned long val; 26 27 asm volatile ("movl %%cr0, %0" : "=r" (val) : : "memory"); 28 return val; 29 } 30 31 static inline void write_cr0(unsigned long val) 32 { 33 asm volatile ("movl %0, %%cr0" : : "r" (val) : "memory"); 34 } 35 36 static inline unsigned long read_cr2(void) 37 { 38 unsigned long val; 39 40 asm volatile("mov %%cr2,%0\n\t" : "=r" (val) : : "memory"); 41 return val; 42 } 43 44 static inline unsigned long read_cr3(void) 45 { 46 unsigned long val; 47 48 asm volatile("mov %%cr3,%0\n\t" : "=r" (val) : : "memory"); 49 return val; 50 } 51 52 static inline unsigned long read_cr4(void) 53 { 54 unsigned long val; 55 56 asm volatile("mov %%cr4,%0\n\t" : "=r" (val) : : "memory"); 57 return val; 58 } 59 60 static inline unsigned long get_debugreg(int regno) 61 { 62 unsigned long val = 0; /* Damn you, gcc! */ 63 64 switch (regno) { 65 case 0: 66 asm("mov %%db0, %0" : "=r" (val)); 67 break; 68 case 1: 69 asm("mov %%db1, %0" : "=r" (val)); 70 break; 71 case 2: 72 asm("mov %%db2, %0" : "=r" (val)); 73 break; 74 case 3: 75 asm("mov %%db3, %0" : "=r" (val)); 76 break; 77 case 6: 78 asm("mov %%db6, %0" : "=r" (val)); 79 break; 80 case 7: 81 asm("mov %%db7, %0" : "=r" (val)); 82 break; 83 default: 84 val = 0; 85 } 86 return val; 87 } 88 89 #endif 90