MentOS  0.8.0
The Mentoring Operating System
Macros | Functions
proc_access.h File Reference

Set of functions and flags used to manage processors registers. More...

Go to the source code of this file.

Macros

#define CR0_PE   0x00000001u
 Protected mode Enable.
 
#define CR0_MP   0x00000002u
 "Math" Present (e.g. npx), wait for it.
 
#define CR0_EM   0x00000004u
 EMulate NPX, e.g. trap, don't execute code.
 
#define CR0_TS   0x00000008u
 Process has done Task Switch, do NPX save.
 
#define CR0_ET   0x00000010u
 32 bit (if set) vs 16 bit (387 vs 287).
 
#define CR0_PG   0x80000000u
 Paging Enable.
 
#define CR4_SEE   0x00008000u
 Secure Enclave Enable XXX.
 
#define CR4_SMAP   0x00200000u
 Supervisor-Mode Access Protect.
 
#define CR4_SMEP   0x00100000u
 Supervisor-Mode Execute Protect.
 
#define CR4_OSXSAVE   0x00040000u
 OS supports XSAVE.
 
#define CR4_PCIDE   0x00020000u
 PCID Enable.
 
#define CR4_RDWRFSGS   0x00010000u
 RDWRFSGS Enable.
 
#define CR4_SMXE   0x00004000u
 Enable SMX operation.
 
#define CR4_VMXE   0x00002000u
 Enable VMX operation.
 
#define CR4_OSXMM   0x00000400u
 SSE/SSE2 exception support in OS.
 
#define CR4_OSFXS   0x00000200u
 SSE/SSE2 OS supports FXSave.
 
#define CR4_PCE   0x00000100u
 Performance-Monitor Count Enable.
 
#define CR4_PGE   0x00000080u
 Page Global Enable.
 
#define CR4_MCE   0x00000040u
 Machine Check Exceptions.
 
#define CR4_PAE   0x00000020u
 Physical Address Extensions.
 
#define CR4_PSE   0x00000010u
 Page Size Extensions.
 
#define CR4_DE   0x00000008u
 Debugging Extensions.
 
#define CR4_TSD   0x00000004u
 Time Stamp Disable.
 
#define CR4_PVI   0x00000002u
 Protected-mode Virtual Interrupts.
 
#define CR4_VME   0x00000001u
 Virtual-8086 Mode Extensions.
 

Functions

static uint16_t get_es (void)
 Reads the Extra Segment (DS). More...
 
static void set_es (uint16_t es)
 Sets the Extra Segment (DS). More...
 
static uint16_t get_ds (void)
 Reads the Data Segment (DS). More...
 
static void set_ds (uint16_t ds)
 Sets the Data Segment (DS). More...
 
static uint16_t get_fs (void)
 Reads FS. More...
 
static void set_fs (uint16_t fs)
 Sets FS. More...
 
static uint16_t get_gs (void)
 Reads GS. More...
 
static void set_gs (uint16_t gs)
 Sets GS. More...
 
static uint16_t get_ss (void)
 Reads the Stack Segment (SS). More...
 
static void set_ss (uint16_t ss)
 Sets the Stack Segment (SS). More...
 
static uintptr_t get_cr0 (void)
 Reads the current cr0 value. More...
 
static void set_cr0 (uintptr_t cr0)
 Sets the cr0 value. More...
 
static uintptr_t get_cr2 (void)
 Reads the current cr2 value. More...
 
static void set_cr2 (uintptr_t cr2)
 Sets the cr2 value. More...
 
static uintptr_t get_cr3 (void)
 Reads the current cr3 value. More...
 
static void set_cr3 (uintptr_t cr3)
 Sets the cr3 value. More...
 
static uintptr_t get_cr4 (void)
 Reads the current cr4 value. More...
 
static void set_cr4 (uintptr_t cr4)
 Sets the cr4 value. More...
 
static uintptr_t get_eflags (void)
 Reads entire contents of the EFLAGS register. More...
 
static void clear_ts (void)
 Clears the task-switched (TS) flag in the CR0 register.
 
static unsigned short get_tr (void)
 Reads the segment selector from the task register (TR). More...
 
static void set_tr (unsigned short seg)
 Loads the source operand into the segment selector field of the task register. More...
 
static unsigned short sldt (void)
 Reads the segment selector from the local descriptor table register (LDTR). More...
 
static void lldt (unsigned short seg)
 Loads the source operand into the segment selector field of the local descriptor table register (LDTR). More...
 
static void lgdt (uintptr_t *desc)
 Loads the values in the source operand into the global descriptor table register (GDTR) or the interrupt descriptor table register (IDTR). More...
 
static void lidt (uintptr_t *desc)
 Loads the values in the source operand into the global descriptor table register (GDTR) or the interrupt descriptor table register (IDTR). More...
 
static void sti (void)
 Set interrupt flag; external, maskable interrupts enabled at the end of the next instruction.
 
static void cli (void)
 Clear interrupt flag; interrupts disabled when interrupt flag cleared.
 
static void swapgs (void)
 Exchanges the current GS base register value with the value contained in MSR address C0000102H.
 
static void hlt (void)
 Halts the CPU until the next external interrupt is fired.
 
static void pause (void)
 Gives hint to processor that improves performance of spin-wait loops.
 

Detailed Description

Set of functions and flags used to manage processors registers.

Function Documentation

◆ get_cr0()

static uintptr_t get_cr0 ( void  )
inlinestatic

Reads the current cr0 value.

Returns
the value we read.

◆ get_cr2()

static uintptr_t get_cr2 ( void  )
inlinestatic

Reads the current cr2 value.

Returns
the value we read.

◆ get_cr3()

static uintptr_t get_cr3 ( void  )
inlinestatic

Reads the current cr3 value.

Returns
the value we read.

◆ get_cr4()

static uintptr_t get_cr4 ( void  )
inlinestatic

Reads the current cr4 value.

Returns
the value we read.

◆ get_ds()

static uint16_t get_ds ( void  )
inlinestatic

Reads the Data Segment (DS).

Returns
the value we read.

◆ get_eflags()

static uintptr_t get_eflags ( void  )
inlinestatic

Reads entire contents of the EFLAGS register.

Returns
the content of EFLAGS.

◆ get_es()

static uint16_t get_es ( void  )
inlinestatic

Reads the Extra Segment (DS).

Returns
the value we read.

◆ get_fs()

static uint16_t get_fs ( void  )
inlinestatic

Reads FS.

Returns
the value we read.

◆ get_gs()

static uint16_t get_gs ( void  )
inlinestatic

Reads GS.

Returns
the value we read.

◆ get_ss()

static uint16_t get_ss ( void  )
inlinestatic

Reads the Stack Segment (SS).

Returns
the value we read.

◆ get_tr()

static unsigned short get_tr ( void  )
inlinestatic

Reads the segment selector from the task register (TR).

Returns

◆ lgdt()

static void lgdt ( uintptr_t desc)
inlinestatic

Loads the values in the source operand into the global descriptor table register (GDTR) or the interrupt descriptor table register (IDTR).

Parameters
descthe value we need to load.

◆ lidt()

static void lidt ( uintptr_t desc)
inlinestatic

Loads the values in the source operand into the global descriptor table register (GDTR) or the interrupt descriptor table register (IDTR).

Parameters
descthe value we need to load.

◆ lldt()

static void lldt ( unsigned short  seg)
inlinestatic

Loads the source operand into the segment selector field of the local descriptor table register (LDTR).

Parameters
segThe segment selector we need to set.

◆ set_cr0()

static void set_cr0 ( uintptr_t  cr0)
inlinestatic

Sets the cr0 value.

Parameters
cr0the value we want to set.

◆ set_cr2()

static void set_cr2 ( uintptr_t  cr2)
inlinestatic

Sets the cr2 value.

Parameters
cr2the value we want to set.

◆ set_cr3()

static void set_cr3 ( uintptr_t  cr3)
inlinestatic

Sets the cr3 value.

Parameters
cr3the value we want to set.

◆ set_cr4()

static void set_cr4 ( uintptr_t  cr4)
inlinestatic

Sets the cr4 value.

Parameters
cr4the value we want to set.

◆ set_ds()

static void set_ds ( uint16_t  ds)
inlinestatic

Sets the Data Segment (DS).

Parameters
dsthe value we set.

◆ set_es()

static void set_es ( uint16_t  es)
inlinestatic

Sets the Extra Segment (DS).

Parameters
esthe value we set.

◆ set_fs()

static void set_fs ( uint16_t  fs)
inlinestatic

Sets FS.

Parameters
fsthe value we set.

◆ set_gs()

static void set_gs ( uint16_t  gs)
inlinestatic

Sets GS.

Parameters
gsthe value we set.

◆ set_ss()

static void set_ss ( uint16_t  ss)
inlinestatic

Sets the Stack Segment (SS).

Parameters
ssthe value we set.

◆ set_tr()

static void set_tr ( unsigned short  seg)
inlinestatic

Loads the source operand into the segment selector field of the task register.

Parameters
segthe segment selector we want to set.

◆ sldt()

static unsigned short sldt ( void  )
inlinestatic

Reads the segment selector from the local descriptor table register (LDTR).

Returns
the segment selector.