52 lines
942 B
C++
52 lines
942 B
C++
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
extern "C" uintptr_t asm_get_rflags();
|
|
extern "C" void asm_set_rflags(uintptr_t);
|
|
|
|
inline uintptr_t read_rflags()
|
|
{
|
|
return asm_get_rflags();
|
|
}
|
|
|
|
inline void write_rflags(uintptr_t value)
|
|
{
|
|
asm_set_rflags(value);
|
|
}
|
|
|
|
inline uintptr_t read_cr0()
|
|
{
|
|
uintptr_t value;
|
|
asm volatile("mov %%cr0, %0" : "=r"(value));
|
|
return value;
|
|
}
|
|
|
|
inline uintptr_t read_cr3()
|
|
{
|
|
uintptr_t value;
|
|
asm volatile("mov %%cr3, %0" : "=r"(value));
|
|
return value;
|
|
}
|
|
|
|
inline uintptr_t read_cr4()
|
|
{
|
|
uintptr_t value;
|
|
asm volatile("mov %%cr4, %0" : "=r"(value));
|
|
return value;
|
|
}
|
|
|
|
template <typename T> inline void write_cr0(T value)
|
|
{
|
|
asm volatile("mov %0, %%cr0" : : "r"(value));
|
|
}
|
|
|
|
template <typename T> inline void write_cr3(T value)
|
|
{
|
|
asm volatile("mov %0, %%cr3" : : "r"(value));
|
|
}
|
|
|
|
template <typename T> inline void write_cr4(T value)
|
|
{
|
|
asm volatile("mov %0, %%cr4" : : "r"(value));
|
|
} |