tape-kernel 1.0
a modular modern independent kernel
Loading...
Searching...
No Matches
cpu.c
Go to the documentation of this file.
1//cpu.c - cpu related functions
2#include "cpu.h"
3#include "../lib/types.h"
4#include "../lib/utils.h"
5
6//external asm functions
7extern int __cpuid_supported(void);
8extern void __cpuid_get_vendor(uint32_t *ebx, uint32_t *edx, uint32_t *ecx);
10
11/**
12 * @brief getcpu detects cpu vendor and model information
13 *
14 * getcpu is a function that uses the cpuid instruction to detect
15 * the cpu vendor string and model information and formats it into
16 * a readable string
17 * @param buffer, the output buffer for the cpu description string
18 * @param buffer_len, the size of the output buffer
19 *
20 * using getcpu is done with
21 * @code{.c}
22 * #include "../kernel/cpu.h" //or just cpu.h
23 * char cpu[64];
24 * getcpu(cpu, sizeof(cpu));
25 * @endcode
26 *
27 * @see __cpuid_supported(), shell() info cmd
28 */
29void __getcpu(char *buffer, uint32_t buffer_len) {
30 char num[8];
31
32 if (buffer == NULL || buffer_len == 0) return;
33
34 if (__cpuid_supported()) {
35 uint32_t ebx, edx, ecx;
36
37 __cpuid_get_vendor(&ebx, &edx, &ecx);
38
39 char vendor[13];
40 uint32_t *vid = (uint32_t*)vendor;
41 vid[0] = ebx;
42 vid[1] = edx;
43 vid[2] = ecx;
44 vendor[12] = '\0';
45
47 uint32_t family = (eax >> 8) & 0xF;
48 uint32_t model = (eax >> 4) & 0xF;
49 uint32_t stepping = eax & 0xF;
50
51 strcpy(buffer, vendor);
52 strcat(buffer, " family ");
53 itoa((int)family, num);
54 strcat(buffer, num);
55 strcat(buffer, " model ");
56 itoa((int)model, num);
57 strcat(buffer, num);
58 strcat(buffer, " stepping ");
59 itoa((int)stepping, num);
60 strcat(buffer, num);
61 } else {
62 strcpy(buffer, "unknown");
63 }
64}
65
uint32_t __cpuid_get_features(void)
int __cpuid_supported(void)
void __getcpu(char *buffer, uint32_t buffer_len)
getcpu detects cpu vendor and model information
Definition cpu.c:29
void __cpuid_get_vendor(uint32_t *ebx, uint32_t *edx, uint32_t *ecx)
#define NULL
Definition types.h:38
unsigned int uint32_t
Definition types.h:30
void strcpy(char *dest, const char *src)
Definition utils.c:21
void itoa(int num, char *str)
itoa converts an integer to a decimal string
Definition utils.c:49
void strcat(char *dest, const char *src)
Definition utils.c:26