MicrOS
cpuid.h File Reference
#include "headers/cpuid_defines.h"
#include "headers/cpuid_0x00h.h"
#include "headers/cpuid_0x01h.h"
#include "headers/cpuid_0x04h.h"
#include <stdint.h>

Go to the source code of this file.

Classes

struct  cpuid_cache_struct
 Struct to represent cache. More...
 

Enumerations

enum  cpuid_cache_type { DATA_CACHE = 0x01, INSTRUCTION_CACHE = 0x02, UNIFIED_CACHE = 0x03 }
 Enum to represent cache type. More...
 

Functions

uint8_t cpuid_init ()
 Initialization of CPUID. More...
 
uint32_t cpuid_get_highest_function_parameter ()
 Get highest function parameter. More...
 
char * cpuid_get_vendor_string (char *buffer)
 Get vendor string. More...
 
uint8_t cpuid_get_stepping_id ()
 Get stepping id. More...
 
uint8_t cpuid_get_model_id ()
 Get model id. More...
 
uint8_t cpuid_get_family_id ()
 Get family id. More...
 
uint8_t cpuid_get_processor_type ()
 Get processor type. More...
 
uint8_t cpuid_is_hyperthreading_available ()
 Check if Hyper-Threading is available. More...
 
uint8_t cpuid_number_of_logical_processors ()
 Get number of logical processors. More...
 
uint8_t cpuid_number_of_physical_processors_cores ()
 Get number of physical processors cores. More...
 
uint8_t cpuid_get_valid_number_cache_entries ()
 Get number of valid cache entries. More...
 
uint32_t cpuid_get_cache_size_in_bytes (uint8_t cache_index)
 Get cache size in bytes. More...
 
cpuid_cache_struct cpuid_get_cache_data (uint8_t cache_index)
 Get cache data. More...
 
const cpuid_0x00hcpuid_get_0x00h_fields ()
 Get 0x00h fields. More...
 
const cpuid_0x01hcpuid_get_0x01h_fields ()
 Get 0x01h fields. More...
 
const cpuid_0x04hcpuid_get_0x04h_fields (uint8_t index)
 Get 0x04h fields. More...
 
static void __cpuid_features (int code, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
 Perform CPUID instruction. More...
 
static void __cpuid (unsigned int code, uint32_t where[4])
 
static void __cpuid_features_count (int code, int count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
 Perform CPUID instruction. More...
 
static void __cpuid_count (unsigned int code, int count, uint32_t where[4])
 
void __cpuid_get_manufacturer_string ()
 Helper function to get manufacturer id. More...
 
char * __cpuid_get_processor_brand (char *buffer)
 Get prcessor brand. More...
 

Enumeration Type Documentation

◆ cpuid_cache_type

Enum to represent cache type.

Enumerator
DATA_CACHE 

Data cache.

INSTRUCTION_CACHE 

Instruction cache.

UNIFIED_CACHE 

Unified cache.

Function Documentation

◆ __cpuid()

static void __cpuid ( unsigned int  code,
uint32_t  where[4] 
)
inlinestatic

◆ __cpuid_count()

static void __cpuid_count ( unsigned int  code,
int  count,
uint32_t  where[4] 
)
inlinestatic

◆ __cpuid_features()

static void __cpuid_features ( int  code,
uint32_t eax,
uint32_t ebx,
uint32_t ecx,
uint32_t edx 
)
inlinestatic

Perform CPUID instruction.

Returns processor identification and feature information to the EAX, EBX, ECX, and EDX registers, as determined by input entered in EAX (in some cases, ECX as well).

Parameters
codeInitial EAX value. Code for EAX variant.
eaxResult from EAX.
ebxResult from EAX.
ecxResult from EAX.
edxResult from EAX.

◆ __cpuid_features_count()

static void __cpuid_features_count ( int  code,
int  count,
uint32_t eax,
uint32_t ebx,
uint32_t ecx,
uint32_t edx 
)
inlinestatic

Perform CPUID instruction.

Returns processor identification and feature information to the EAX, EBX, ECX, and EDX registers, as determined by input entered in EAX (in some cases, ECX as well).

Parameters
codeInitial EAX value. Code for EAX variant.
countNumber to put in ECX..
eaxResult from EAX.
ebxResult from EAX.
ecxResult from EAX.
edxResult from EAX.

◆ __cpuid_get_manufacturer_string()

void __cpuid_get_manufacturer_string ( )

Helper function to get manufacturer id.

Put vendor string in __cpuid_vendor_string variable.

◆ __cpuid_get_processor_brand()

char* __cpuid_get_processor_brand ( char *  buffer)

Get prcessor brand.

Function copy procesor brand to buffer and terminate string with /0.

Parameters
bufferBuffer for vendor string with size at least 48.
Returns
Pointer to buffer where serial number is stored.

◆ cpuid_get_0x00h_fields()

const cpuid_0x00h* cpuid_get_0x00h_fields ( )

Get 0x00h fields.

Returns
CPUID 0x00h fields.

◆ cpuid_get_0x01h_fields()

const cpuid_0x01h* cpuid_get_0x01h_fields ( )

Get 0x01h fields.

Result will be valid only if cpuid_get_highest_function_parameter() returns value 1 or higher.

Returns
CPUID 0x01h fields.

◆ cpuid_get_0x04h_fields()

const cpuid_0x04h* cpuid_get_0x04h_fields ( uint8_t  index)

Get 0x04h fields.

Result will be valid only if cpuid_get_highest_function_parameter() returns value 4 or higher.

Parameters
indexIndex of struct to return.
Returns
CPUID 0x04h fields.

◆ cpuid_get_cache_data()

cpuid_cache_struct cpuid_get_cache_data ( uint8_t  cache_index)

Get cache data.

Result will be valid only if cpuid_get_highest_function_parameter() returns value 4 or higher.

Parameters
cache_indexIndex of cache to return. To get max number use cpuid_get_valid_number_cache_entries(). If invalid 0 will be returned.
Returns
Cache data.

◆ cpuid_get_cache_size_in_bytes()

uint32_t cpuid_get_cache_size_in_bytes ( uint8_t  cache_index)

Get cache size in bytes.

Result will be valid only if cpuid_get_highest_function_parameter() returns value 4 or higher.

Parameters
cache_indexIndex of cache to return. To get max number use cpuid_get_valid_number_cache_entries(). If invalid 0 will be returned.
Returns
Cache size in bytes.

◆ cpuid_get_family_id()

uint8_t cpuid_get_family_id ( )

Get family id.

Result will be valid only if cpuid_get_highest_function_parameter() returns value 1 or higher.

Returns
CPU family id.

◆ cpuid_get_highest_function_parameter()

uint32_t cpuid_get_highest_function_parameter ( )

Get highest function parameter.

Indicates how many function parameters CPUID supports. You should use it to determine how much data you can aquire from CPUID functions.

Returns
Highest parameter function.

◆ cpuid_get_model_id()

uint8_t cpuid_get_model_id ( )

Get model id.

Result will be valid only if cpuid_get_highest_function_parameter() returns value 1 or higher.

Returns
CPU model id.

◆ cpuid_get_processor_type()

uint8_t cpuid_get_processor_type ( )

Get processor type.

Result will be valid only if cpuid_get_highest_function_parameter() returns value 1 or higher.

Returns
CPU processor type.

◆ cpuid_get_stepping_id()

uint8_t cpuid_get_stepping_id ( )

Get stepping id.

Result will be valid only if cpuid_get_highest_function_parameter() returns value 1 or higher.

Returns
CPU stepping id.

◆ cpuid_get_valid_number_cache_entries()

uint8_t cpuid_get_valid_number_cache_entries ( )

Get number of valid cache entries.

Number that determines how much cache entries are stored. Used in function cpuid_get_cache_size_in_bytes(uint8_t cache_index), cpuid_get_cache_data(uint8_t cache_index).
Result will be valid only if cpuid_get_highest_function_parameter() returns value 4 or higher.

Returns
Number of valid cache entries.

◆ cpuid_get_vendor_string()

char* cpuid_get_vendor_string ( char *  buffer)

Get vendor string.

Function copy vendor string to buffer and terminate string with /0.

Parameters
bufferBuffer for vendor string with size at least 13.
Returns
Pointer to buffer where serial number is stored.

◆ cpuid_init()

uint8_t cpuid_init ( )

Initialization of CPUID.

Sets internal variables.

Returns
1 is success, 0 is failure.

◆ cpuid_is_hyperthreading_available()

uint8_t cpuid_is_hyperthreading_available ( )

Check if Hyper-Threading is available.

Result will be valid only if cpuid_get_highest_function_parameter() returns value 1 or higher.

Returns
1 if yes, 0 if no.

◆ cpuid_number_of_logical_processors()

uint8_t cpuid_number_of_logical_processors ( )

Get number of logical processors.

Addressable IDs for logical processors in the same Package. Valid if Hyper-Threading is enabled.
Result will be valid only if cpuid_get_highest_function_parameter() returns value 1 or higher.

Returns
Number of addressable logical processors.

◆ cpuid_number_of_physical_processors_cores()

uint8_t cpuid_number_of_physical_processors_cores ( )

Get number of physical processors cores.

Addressable IDs for physical processors cores in a physical package. Result will be valid only if cpuid_get_highest_function_parameter() returns value 4 or higher.

Returns
Number of addressable physical processors cores.