MicrOS
cpuid.h
Go to the documentation of this file.
1 #ifndef CPUID_H
2 #define CPUID_H
3 
5 #include "headers/cpuid_0x00h.h"
6 #include "headers/cpuid_0x01h.h"
7 #include "headers/cpuid_0x04h.h"
8 #include <stdint.h>
9 
11 typedef enum cpuid_cache_type
12 {
14  DATA_CACHE = 0x01,
18  UNIFIED_CACHE = 0x03
20 
22 typedef struct cpuid_cache_struct
23 {
27  uint8_t level;
31 
33 
37 uint8_t cpuid_init();
38 
40 
46 
48 
53 char* cpuid_get_vendor_string(char* buffer);
54 
56 
60 uint8_t cpuid_get_stepping_id();
61 
63 
66 uint8_t cpuid_get_model_id();
67 
69 
72 uint8_t cpuid_get_family_id();
73 
75 
78 uint8_t cpuid_get_processor_type();
79 
81 
85 
87 
92 
94 
99 
101 
107 
109 
113 uint32_t cpuid_get_cache_size_in_bytes(uint8_t cache_index);
114 
116 
120 cpuid_cache_struct cpuid_get_cache_data(uint8_t cache_index);
121 
123 
127 
129 
133 
135 
139 const cpuid_0x04h* cpuid_get_0x04h_fields(uint8_t index);
140 
141 // Helpers
142 
144 
152 static inline void __cpuid_features(int code, uint32_t *eax, uint32_t *ebx, uint32_t *ecx ,uint32_t *edx)
153 {
154  asm volatile("cpuid":"=a"(*eax),"=b"(*ebx),"=c"(*ecx),"=d"(*edx):"a"(code));
155 }
156 
157 static inline void __cpuid(unsigned int code, uint32_t where[4]) {
158  asm volatile("cpuid":"=a"(*where),"=b"(*(where+1)),
159  "=c"(*(where+2)),"=d"(*(where+3)):"a"(code));
160 }
161 
163 
172 static inline void __cpuid_features_count(int code, int count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx ,uint32_t *edx)
173 {
174  asm volatile("cpuid":"=a"(*eax),"=b"(*ebx),"=c"(*ecx),"=d"(*edx):"a"(code), "c"(count));
175 }
176 
177 static inline void __cpuid_count(unsigned int code, int count, uint32_t where[4]) {
178  asm volatile("cpuid":"=a"(*where),"=b"(*(where+1)),
179  "=c"(*(where+2)),"=d"(*(where+3)):"a"(code), "c"(count));
180 }
181 
183 
187 
189 
195 
196 #endif
char * __cpuid_get_processor_brand(char *buffer)
Get prcessor brand.
Definition: cpuid.c:191
Unified cache.
Definition: cpuid.h:18
Instruction cache.
Definition: cpuid.h:16
uint8_t cpuid_get_valid_number_cache_entries()
Get number of valid cache entries.
Definition: cpuid.c:117
uint8_t cpuid_get_family_id()
Get family id.
Definition: cpuid.c:77
Processor Info and Feature Bits.
Definition: cpuid_0x01h.h:220
static void __cpuid_features_count(int code, int count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
Perform CPUID instruction.
Definition: cpuid.h:172
const cpuid_0x04h * cpuid_get_0x04h_fields(uint8_t index)
Get 0x04h fields.
Definition: cpuid.c:161
uint8_t cpuid_get_model_id()
Get model id.
Definition: cpuid.c:65
const cpuid_0x01h * cpuid_get_0x01h_fields()
Get 0x01h fields.
Definition: cpuid.c:156
uint32_t cpuid_get_highest_function_parameter()
Get highest function parameter.
Definition: cpuid.c:45
uint8_t cpuid_get_processor_type()
Get processor type.
Definition: cpuid.c:89
uint8_t cpuid_get_stepping_id()
Get stepping id.
Definition: cpuid.c:60
uint8_t cpuid_is_hyperthreading_available()
Check if Hyper-Threading is available.
Definition: cpuid.c:94
uint8_t level
Level of cache.
Definition: cpuid.h:27
Struct to represent cache.
Definition: cpuid.h:22
cpuid_cache_type
Enum to represent cache type.
Definition: cpuid.h:11
Data cache.
Definition: cpuid.h:14
uint8_t cpuid_number_of_logical_processors()
Get number of logical processors.
Definition: cpuid.c:99
void __cpuid_get_manufacturer_string()
Helper function to get manufacturer id.
Definition: cpuid.c:168
static void __cpuid(unsigned int code, uint32_t where[4])
Definition: cpuid.h:157
const cpuid_0x00h * cpuid_get_0x00h_fields()
Get 0x00h fields.
Definition: cpuid.c:151
uint8_t cpuid_number_of_physical_processors_cores()
Get number of physical processors cores.
Definition: cpuid.c:112
cpuid_cache_struct cpuid_get_cache_data(uint8_t cache_index)
Get cache data.
Definition: cpuid.c:135
CPU highest function parameter and manufacturer id.
Definition: cpuid_0x00h.h:21
static void __cpuid_features(int code, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
Perform CPUID instruction.
Definition: cpuid.h:152
uint32_t size
Size of cache in bytes.
Definition: cpuid.h:29
char buffer[500]
Definition: physical_memory_manager.c:5
Intel thread/core and cache topology.
Definition: cpuid_0x04h.h:90
cpuid_cache_type type
Type of cache.
Definition: cpuid.h:25
char * cpuid_get_vendor_string(char *buffer)
Get vendor string.
Definition: cpuid.c:50
uint8_t cpuid_init()
Initialization of CPUID.
Definition: cpuid.c:21
size_t uint32_t
Unsigned integral type.
Definition: string.h:8
static void __cpuid_count(unsigned int code, int count, uint32_t where[4])
Definition: cpuid.h:177
uint32_t cpuid_get_cache_size_in_bytes(uint8_t cache_index)
Get cache size in bytes.
Definition: cpuid.c:122