1/* 2 * Copyright 2014, General Dynamics C4 Systems 3 * 4 * This software may be distributed and modified according to the terms of 5 * the GNU General Public License version 2. Note that NO WARRANTY is provided. 6 * See "LICENSE_GPLv2.txt" for details. 7 * 8 * @TAG(GD_GPL) 9 */ 10 11#ifndef __MODE_MACHINE_CPU_REGISTERS_H 12#define __MODE_MACHINE_CPU_REGISTERS_H 13 14static inline unsigned long read_cr3(void) 15{ 16 unsigned long val; 17 asm volatile("movl %%cr3, %0" : "=r"(val), "=m"(control_reg_order)); 18 return val; 19} 20 21static inline void write_cr3(unsigned long val) 22{ 23 asm volatile("movl %0, %%cr3" :: "r"(val), "m"(control_reg_order)); 24} 25 26static inline unsigned long read_cr0(void) 27{ 28 unsigned long val; 29 asm volatile("movl %%cr0, %0" : "=r"(val), "=m"(control_reg_order)); 30 return val; 31} 32 33static inline void write_cr0(unsigned long val) 34{ 35 asm volatile("movl %0, %%cr0" :: "r"(val), "m"(control_reg_order)); 36} 37 38static inline unsigned long read_cr2(void) 39{ 40 unsigned long val; 41 asm volatile("movl %%cr2, %0" : "=r"(val), "=m"(control_reg_order)); 42 return val; 43} 44 45static inline unsigned long read_cr4(void) 46{ 47 unsigned long val; 48 asm volatile("movl %%cr4, %0" : "=r"(val), "=m"(control_reg_order)); 49 return val; 50} 51 52static inline void write_cr4(unsigned long value) 53{ 54 asm volatile("movl %0, %%cr4" :: "r"(value), "m"(control_reg_order)); 55} 56 57#endif 58