Turnstone Operating System
Loading...
Searching...
No Matches
cpu.h File Reference

cpu commands which needs assembly codes. More...

#include <types.h>

Classes

struct  cpu_cpuid_regs_t
 cpuid command set/get registers. More...
 

Macros

#define ___CPU_H   0
 

Typedefs

typedef struct cpu_cpuid_regs_t cpu_cpuid_regs_t
 struct short hand
 

Functions

void cpu_hlt (void)
 stops cpu. More...
 
void cpu_idle (void)
 
static boolean_t cpu_cli (void)
 disables interrupts More...
 
static void cpu_sti (void)
 enables interrupts More...
 
static void cpu_nop (void)
 nop instruction More...
 
static void cpu_cld (void)
 cld instruction More...
 
uint16_t cpu_read_data_segment (void)
 reads data segment (ds) value from cpu. More...
 
int8_t cpu_check_rdrand (void)
 checks rdrand supported More...
 
uint64_t cpu_read_msr (uint32_t msr_address)
 read msr and return More...
 
int8_t cpu_write_msr (uint32_t msr_address, uint64_t value)
 writes msr More...
 
uint64_t cpu_read_cr2 (void)
 read cr2 and return More...
 
uint64_t cpu_read_cr3 (void)
 read cr3 and return More...
 
uint8_t cpu_cpuid (cpu_cpuid_regs_t query, cpu_cpuid_regs_t *answer)
 
void cpu_clear_segments (void)
 clears segments More...
 
static void cpu_set_and_clear_stack (uint64_t stack_address)
 prepares stack More...
 
static void cpu_tlb_invalidate (void *address)
 invalidates tlb for address More...
 
static void cpu_tlb_flush (void)
 
boolean_t cpu_is_interrupt_enabled (void)
 
uint64_t cpu_read_fs_base (void)
 
uint64_t cpu_read_gs_base (void)
 

Detailed Description

cpu commands which needs assembly codes.

This work is licensed under TURNSTONE OS Public License. Please read and understand latest version of Licence.

Macro Definition Documentation

◆ ___CPU_H

#define ___CPU_H   0

prevent duplicate header error macro

Function Documentation

◆ cpu_check_rdrand()

int8_t cpu_check_rdrand ( void  )

checks rdrand supported

Returns
0 when supported else -1

◆ cpu_cld()

static void cpu_cld ( void  )
inlinestatic

cld instruction

This command clears direction flag.

◆ cpu_clear_segments()

void cpu_clear_segments ( void  )

clears segments

sets segment registers to zero

◆ cpu_cli()

static boolean_t cpu_cli ( void  )
inlinestatic

disables interrupts

This command disables interrupts with cli assembly command.

◆ cpu_hlt()

void cpu_hlt ( void  )

stops cpu.

This command stops cpu using hlt assembly command inside for.

◆ cpu_nop()

static void cpu_nop ( void  )
inlinestatic

nop instruction

This command nops.

◆ cpu_read_cr2()

uint64_t cpu_read_cr2 ( void  )

read cr2 and return

Returns
cr2 value

returns cr2 value for page faults

◆ cpu_read_cr3()

uint64_t cpu_read_cr3 ( void  )

read cr3 and return

Returns
cr3 value

returns cr3 value for page tables

◆ cpu_read_data_segment()

uint16_t cpu_read_data_segment ( void  )

reads data segment (ds) value from cpu.

Returns
ds value

This function is meaningful at real mode. At long mode is does nothing

◆ cpu_read_msr()

uint64_t cpu_read_msr ( uint32_t  msr_address)

read msr and return

Parameters
[in]msr_addressmodel Specific register address
Returns
msr value

returns edx:eax as uint64_t

◆ cpu_set_and_clear_stack()

static void cpu_set_and_clear_stack ( uint64_t  stack_address)
inlinestatic

prepares stack

Parameters
[in]stack_addressstack top value

sets esp and clears ebp

◆ cpu_sti()

static void cpu_sti ( void  )
inlinestatic

enables interrupts

This command enables interrupts with sti assembly command.

◆ cpu_tlb_invalidate()

static void cpu_tlb_invalidate ( void *  address)
inlinestatic

invalidates tlb for address

Parameters
[in]addressadddress to invalidate

calls invlpg instruction

◆ cpu_write_msr()

int8_t cpu_write_msr ( uint32_t  msr_address,
uint64_t  value 
)

writes msr

Parameters
[in]msr_addressmodel Specific register address
[in]valuevalue to write
Returns
0 on sucess

parse value into edx:eax