10 #define CR0_PE 0x00000001u
11 #define CR0_MP 0x00000002u
12 #define CR0_EM 0x00000004u
13 #define CR0_TS 0x00000008u
14 #define CR0_ET 0x00000010u
15 #define CR0_PG 0x80000000u
17 #define CR4_SEE 0x00008000u
18 #define CR4_SMAP 0x00200000u
19 #define CR4_SMEP 0x00100000u
20 #define CR4_OSXSAVE 0x00040000u
21 #define CR4_PCIDE 0x00020000u
22 #define CR4_RDWRFSGS 0x00010000u
23 #define CR4_SMXE 0x00004000u
24 #define CR4_VMXE 0x00002000u
25 #define CR4_OSXMM 0x00000400u
26 #define CR4_OSFXS 0x00000200u
27 #define CR4_PCE 0x00000100u
28 #define CR4_PGE 0x00000080u
29 #define CR4_MCE 0x00000040u
30 #define CR4_PAE 0x00000020u
31 #define CR4_PSE 0x00000010u
32 #define CR4_DE 0x00000008u
33 #define CR4_TSD 0x00000004u
34 #define CR4_PVI 0x00000002u
35 #define CR4_VME 0x00000001u
42 __asm__ __volatile__(
"mov %%es, %0"
51 __asm__ __volatile__(
"mov %0, %%es"
61 __asm__ __volatile__(
"mov %%ds, %0"
70 __asm__ __volatile__(
"mov %0, %%ds"
80 __asm__ __volatile__(
"mov %%fs, %0"
89 __asm__ __volatile__(
"mov %0, %%fs"
99 __asm__ __volatile__(
"mov %%gs, %0"
108 __asm__ __volatile__(
"mov %0, %%gs"
118 __asm__ __volatile__(
"mov %%ss, %0"
127 __asm__ __volatile__(
"mov %0, %%ss"
137 __asm__ __volatile__(
"mov %%cr0, %0"
146 __asm__ __volatile__(
"mov %0, %%cr0"
157 __asm__ __volatile__(
"mov %%cr2, %0"
166 __asm__ __volatile__(
"mov %0, %%cr2"
176 __asm__ __volatile__(
"mov %%cr3, %0"
185 __asm__ __volatile__(
"mov %0, %%cr3"
195 __asm__ __volatile__(
"mov %%cr4, %0"
204 __asm__ __volatile__(
"mov %0, %%cr4"
218 __asm__ __volatile__(
"pushf; pop %0"
228 __asm__ __volatile__(
"clts");
233 static inline unsigned short get_tr(
void)
236 __asm__ __volatile__(
"str %0"
243 static inline void set_tr(
unsigned short seg)
245 __asm__ __volatile__(
"ltr %0"
252 static inline unsigned short sldt(
void)
255 __asm__ __volatile__(
"sldt %0"
262 static inline void lldt(
unsigned short seg)
264 __asm__ __volatile__(
"lldt %0"
274 __asm__ __volatile__(
"lgdt %0"
284 __asm__ __volatile__(
"lidt %0"
291 static inline void sti(
void)
293 __asm__ __volatile__(
"sti"
301 static inline void cli(
void)
303 __asm__ __volatile__(
"cli"
313 __asm__ __volatile__(
"swapgs");
317 static inline void hlt(
void)
319 __asm__ __volatile__(
"hlt");
325 __asm__ __volatile__(
"pause");
static uint16_t get_ss(void)
Reads the Stack Segment (SS).
Definition: proc_access.h:115
static void set_fs(uint16_t fs)
Sets FS.
Definition: proc_access.h:87
static uintptr_t get_cr0(void)
Reads the current cr0 value.
Definition: proc_access.h:134
static uint16_t get_es(void)
Reads the Extra Segment (DS).
Definition: proc_access.h:39
static void set_cr0(uintptr_t cr0)
Sets the cr0 value.
Definition: proc_access.h:144
static unsigned short sldt(void)
Reads the segment selector from the local descriptor table register (LDTR).
Definition: proc_access.h:252
static uintptr_t get_cr3(void)
Reads the current cr3 value.
Definition: proc_access.h:173
static void set_es(uint16_t es)
Sets the Extra Segment (DS).
Definition: proc_access.h:49
static uint16_t get_fs(void)
Reads FS.
Definition: proc_access.h:77
static uint16_t get_ds(void)
Reads the Data Segment (DS).
Definition: proc_access.h:58
static void set_cr3(uintptr_t cr3)
Sets the cr3 value.
Definition: proc_access.h:183
static void lgdt(uintptr_t *desc)
Loads the values in the source operand into the global descriptor table register (GDTR) or the interr...
Definition: proc_access.h:272
static uintptr_t get_eflags(void)
Reads entire contents of the EFLAGS register.
Definition: proc_access.h:212
static void swapgs(void)
Exchanges the current GS base register value with the value contained in MSR address C0000102H.
Definition: proc_access.h:311
static void lldt(unsigned short seg)
Loads the source operand into the segment selector field of the local descriptor table register (LDTR...
Definition: proc_access.h:262
static void set_ss(uint16_t ss)
Sets the Stack Segment (SS).
Definition: proc_access.h:125
static void lidt(uintptr_t *desc)
Loads the values in the source operand into the global descriptor table register (GDTR) or the interr...
Definition: proc_access.h:282
static void set_cr4(uintptr_t cr4)
Sets the cr4 value.
Definition: proc_access.h:202
static void cli(void)
Clear interrupt flag; interrupts disabled when interrupt flag cleared.
Definition: proc_access.h:301
static void set_cr2(uintptr_t cr2)
Sets the cr2 value.
Definition: proc_access.h:164
static void pause(void)
Gives hint to processor that improves performance of spin-wait loops.
Definition: proc_access.h:323
static uintptr_t get_cr4(void)
Reads the current cr4 value.
Definition: proc_access.h:192
static unsigned short get_tr(void)
Reads the segment selector from the task register (TR).
Definition: proc_access.h:233
static uint16_t get_gs(void)
Reads GS.
Definition: proc_access.h:96
static void set_tr(unsigned short seg)
Loads the source operand into the segment selector field of the task register.
Definition: proc_access.h:243
static void set_gs(uint16_t gs)
Sets GS.
Definition: proc_access.h:106
static void hlt(void)
Halts the CPU until the next external interrupt is fired.
Definition: proc_access.h:317
static void clear_ts(void)
Clears the task-switched (TS) flag in the CR0 register.
Definition: proc_access.h:226
static void set_ds(uint16_t ds)
Sets the Data Segment (DS).
Definition: proc_access.h:68
static void sti(void)
Set interrupt flag; external, maskable interrupts enabled at the end of the next instruction.
Definition: proc_access.h:291
static uintptr_t get_cr2(void)
Reads the current cr2 value.
Definition: proc_access.h:154
procfs_t fs
The procfs filesystem.
Definition: procfs.c:76
Standard integer data-types.
unsigned uintptr_t
Define the unsigned 32-bit pointer.
Definition: stdint.h:36
unsigned short uint16_t
Define the unsigned 16-bit integer.
Definition: stdint.h:24