Compare commits

..

16 Commits

Author SHA1 Message Date
Dr-Noob
d36123a363 Completing extension strings... 2025-10-30 09:07:04 +01:00
Dr-Noob
8f40c45211 Fixes 2025-10-30 08:49:25 +01:00
Dr-Noob
6713af7de1 Fixes 2025-10-30 08:49:07 +01:00
Dr-Noob
9bd50264b3 Fixes 2025-10-30 08:36:50 +01:00
Dr-Noob
bdadac5dd8 Fixes 2025-10-30 08:35:58 +01:00
Dr-Noob
e823c769ff Attempting to replace 64-bit mask with bool array 2025-10-30 08:33:27 +01:00
Dr-Noob
2116f19073 Delete repeated entry 2025-10-30 07:48:21 +01:00
Dr-Noob
8ce24150e7 Add IME 2025-10-29 22:44:22 +01:00
Dr-Noob
a0cb54dc8b Add IME 2025-10-29 22:43:50 +01:00
Dr-Noob
8e6b0b1a2b Crazy amount of new extensions! 2025-10-29 22:39:22 +01:00
Dr-Noob
5bddbc6b06 [v1.06] Reorganize attributes in printer
This follows the same approach of gpufetch (in
6589de971750b7f4e52c0c35c031fe6204cefdba) where, instead of having a
separate struct for long and short names, both gets merged in a single
struct (ATTRIBUTE_INFO)

This indirectly fixes a bug in RISC-V printer where, if the output
was too large and the short name was selected, it could try to print
an out-of-bound value when accessing the ATTRIBUTE_PEAK. The reason is
that the long and short structures didnt have the same length (because
one attribute name was missing in the short struct). This is now fixed
since we have combined both long and short attribute names.

commit 6e8cccde32
Author: Dr-Noob <peibolms@gmail.com>
Date:   Wed Oct 29 21:54:38 2025 +0100

    Reorganize attributes in printer
2025-10-29 22:08:44 +01:00
Dr-Noob
a0c08ccc0b [v1.06][RISCV] Add support for SpacemiT K1-X SoC (#286) 2024-10-10 08:39:24 +01:00
Dr-Noob
65c75eb443 [v1.06][RISCV] Support for fetching mvendorid, marchid and mimpid (#286)
Getting these 3 RISC-V cpuinfo fields allows the detection of
microarchitecture (and other information), extending the RISC-V
detection capabilities. In particular, this is used here to detect
the marchid of Spacemit X60 uarch.

This commit also changes how the microarchitecture is fetched
(i.e., get_uarch) so that it does not rely only in the uarch field
in cpuinfo, but also on the marchid value.
2024-10-10 08:37:12 +01:00
Dr-Noob
2df8aa8217 [v1.06][X86] Warn the users whenever they use a VM (#293) 2024-10-09 08:52:47 +01:00
Dr-Noob
a5d52b59df [v1.06] Nit: Fix warning due to missing newline at the end of file 2024-10-09 08:29:51 +01:00
Dr-Noob
f09454d442 [v1.06][X86] Fix CPUID 000806EC clash (#298) 2024-10-07 08:30:30 +01:00
9 changed files with 336 additions and 140 deletions

View File

@@ -446,24 +446,24 @@ $C1 ########### ___########### __________ \
$C1.########## |__________| |__________| " $C1.########## |__________| |__________| "
#define ASCII_SPACEMIT \ #define ASCII_SPACEMIT \
"$C1 :#: \ "$C1 :#: \
$C1 :####: \ $C1 :####: \
$C1 :#######: \ $C1 :#######: \
$C1 :#########: \ $C1 :#########: \
$C1 :#########: \ $C1 :#########: \
$C1 :#######: \ $C1 :#######: \
$C1 :####: \ $C1 :####: \
$C1 :#: \ $C1 :#: \
$C1:##: :#: \ $C1:##: :#: \
$C1:####: :###: \ $C1:####: :###: \
$C1:#######: :####: \ $C1:#######: :####: \
$C1:##########: :###: \ $C1:##########: :###: \
$C1:###########: :#: \ $C1:###########: :#: \
$C1:###########: \ $C1:###########: \
$C1 :##########: \ $C1 :##########: \
$C1 :#######: \ $C1 :#######: \
$C1 :####: \ $C1 :####: \
$C1 :##: " $C1 :##: "
// --------------------- LONG LOGOS ------------------------- // // --------------------- LONG LOGOS ------------------------- //
#define ASCII_AMD_L \ #define ASCII_AMD_L \
@@ -644,7 +644,7 @@ asciiL logo_ampere = { ASCII_AMPERE, 50, 17, false, {C_FG_RED},
asciiL logo_nxp = { ASCII_NXP, 55, 8, false, {C_FG_YELLOW, C_FG_CYAN, C_FG_GREEN}, {C_FG_CYAN, C_FG_WHITE} }; asciiL logo_nxp = { ASCII_NXP, 55, 8, false, {C_FG_YELLOW, C_FG_CYAN, C_FG_GREEN}, {C_FG_CYAN, C_FG_WHITE} };
asciiL logo_amlogic = { ASCII_AMLOGIC, 58, 8, false, {C_FG_BLUE}, {C_FG_BLUE, C_FG_B_WHITE} }; asciiL logo_amlogic = { ASCII_AMLOGIC, 58, 8, false, {C_FG_BLUE}, {C_FG_BLUE, C_FG_B_WHITE} };
asciiL logo_marvell = { ASCII_MARVELL, 56, 10, false, {C_FG_B_BLACK}, {C_FG_B_BLACK, C_FG_B_WHITE} }; asciiL logo_marvell = { ASCII_MARVELL, 56, 10, false, {C_FG_B_BLACK}, {C_FG_B_BLACK, C_FG_B_WHITE} };
asciiL logo_spacemit = { ASCII_SPACEMIT, 26, 18, false, {C_FG_B_GREEN}, {C_FG_B_GREEN, C_FG_B_WHITE} }; asciiL logo_spacemit = { ASCII_SPACEMIT, 27, 18, false, {C_FG_B_GREEN}, {C_FG_B_GREEN, C_FG_B_WHITE} };
// Long variants | ----------------------------------------------------------------------------------------------------------------| // Long variants | ----------------------------------------------------------------------------------------------------------------|
asciiL logo_amd_l = { ASCII_AMD_L, 62, 19, true, {C_BG_WHITE, C_BG_GREEN}, {C_FG_WHITE, C_FG_GREEN} }; asciiL logo_amd_l = { ASCII_AMD_L, 62, 19, true, {C_BG_WHITE, C_BG_GREEN}, {C_FG_WHITE, C_FG_GREEN} };

View File

@@ -138,7 +138,7 @@ struct features {
struct extensions { struct extensions {
char* str; char* str;
uint64_t mask; bool* mask; // allocated at runtime with size RISCV_ISA_EXT_ID_MAX-1
}; };
struct cpuInfo { struct cpuInfo {

View File

@@ -45,9 +45,17 @@
#define MAX_ATTRIBUTES 100 #define MAX_ATTRIBUTES 100
#define MAX_TERM_SIZE 1024 #define MAX_TERM_SIZE 1024
typedef struct {
int id;
const char *name;
const char *shortname;
} AttributeField;
enum { enum {
#if defined(ARCH_X86) || defined(ARCH_PPC) #if defined(ARCH_X86)
ATTRIBUTE_NAME, ATTRIBUTE_NAME,
#elif defined(ARCH_PPC)
ATTRIBUTE_PART_NUMBER,
#elif defined(ARCH_ARM) || defined(ARCH_RISCV) #elif defined(ARCH_ARM) || defined(ARCH_RISCV)
ATTRIBUTE_SOC, ATTRIBUTE_SOC,
#endif #endif
@@ -79,76 +87,40 @@ enum {
ATTRIBUTE_PEAK ATTRIBUTE_PEAK
}; };
static const char* ATTRIBUTE_FIELDS [] = { static const AttributeField ATTRIBUTE_INFO[] = {
#ifdef ARCH_X86
"Name:",
#elif ARCH_PPC
"Part Number:",
#elif defined(ARCH_ARM) || defined(ARCH_RISCV)
"SoC:",
#endif
#if defined(ARCH_X86) || defined(ARCH_ARM)
"",
#endif
"Hypervisor:",
"Microarchitecture:",
"Technology:",
"Max Frequency:",
"Sockets:",
"Cores:",
"Cores (Total):",
#ifdef ARCH_X86
"SSE:",
"AVX:",
"FMA:",
#elif ARCH_PPC
"Altivec: ",
#elif defined(ARCH_ARM)
"Features: ",
#elif defined(ARCH_RISCV)
"Extensions: ",
#endif
"L1i Size:",
"L1d Size:",
"L2 Size:",
"L3 Size:",
"Peak Performance:",
};
static const char* ATTRIBUTE_FIELDS_SHORT [] = {
#if defined(ARCH_X86) #if defined(ARCH_X86)
"Name:", { ATTRIBUTE_NAME, "Name:", "Name:" },
#elif ARCH_PPC #elif defined(ARCH_PPC)
"P/N:", { ATTRIBUTE_PART_NUMBER, "Part Number:", "P/N:" },
#elif ARCH_ARM #elif defined(ARCH_ARM) || defined(ARCH_RISCV)
"SoC:", { ATTRIBUTE_SOC, "SoC:", "SoC:" },
#endif #endif
#if defined(ARCH_X86) || defined(ARCH_ARM) #if defined(ARCH_X86) || defined(ARCH_ARM)
"", { ATTRIBUTE_CPU_NUM, "", "" },
#endif #endif
"Hypervisor:", { ATTRIBUTE_HYPERVISOR, "Hypervisor:", "Hypervisor:" },
"uArch:", { ATTRIBUTE_UARCH, "Microarchitecture:", "uArch:" },
"Technology:", { ATTRIBUTE_TECHNOLOGY, "Technology:", "Technology:" },
"Max Freq:", { ATTRIBUTE_FREQUENCY, "Max Frequency:", "Max Freq:" },
"Sockets:", { ATTRIBUTE_SOCKETS, "Sockets:", "Sockets:" },
"Cores:", { ATTRIBUTE_NCORES, "Cores:", "Cores:" },
"Cores (Total):", { ATTRIBUTE_NCORES_DUAL, "Cores (Total):", "Cores (Total):" },
#ifdef ARCH_X86 #ifdef ARCH_X86
"SSE:", { ATTRIBUTE_SSE, "SSE:", "SSE:" },
"AVX:", { ATTRIBUTE_AVX, "AVX:", "AVX:" },
"FMA:", { ATTRIBUTE_FMA, "FMA:", "FMA:" },
#elif ARCH_PPC #elif ARCH_PPC
"Altivec: ", { ATTRIBUTE_ALTIVEC, "Altivec: ", "Altivec: " },
#elif defined(ARCH_ARM) #elif ARCH_ARM
"Features: ", { ATTRIBUTE_FEATURES, "Features: ", "Features: " },
#elif defined(ARCH_RISCV) #elif ARCH_RISCV
"Extensions: ", { ATTRIBUTE_EXTENSIONS, "Extensions: ", "Extensions: " },
#endif #endif
"L1i Size:", { ATTRIBUTE_L1i, "L1i Size:", "L1i Size:" },
"L1d Size:", { ATTRIBUTE_L1d, "L1d Size:", "L1d Size:" },
"L2 Size:", { ATTRIBUTE_L2, "L2 Size:", "L2 Size:" },
"L3 Size:", { ATTRIBUTE_L3, "L3 Size:", "L3 Size:" },
"Peak Perf.:", { ATTRIBUTE_PEAK, "Peak Performance:", "Peak Perf.:" },
}; };
struct terminal { struct terminal {
@@ -454,13 +426,14 @@ void choose_ascii_art(struct ascii* art, struct color** cs, struct terminal* ter
} }
} }
uint32_t longest_attribute_length(struct ascii* art, const char** attribute_fields) { uint32_t longest_attribute_length(struct ascii* art, bool use_short) {
uint32_t max = 0; uint32_t max = 0;
uint64_t len = 0; uint64_t len = 0;
for(uint32_t i=0; i < art->n_attributes_set; i++) { for(uint32_t i=0; i < art->n_attributes_set; i++) {
if(art->attributes[i]->value != NULL) { if(art->attributes[i]->value != NULL) {
len = strlen(attribute_fields[art->attributes[i]->type]); const char* str = use_short ? ATTRIBUTE_INFO[art->attributes[i]->type].shortname : ATTRIBUTE_INFO[art->attributes[i]->type].name;
len = strlen(str);
if(len > max) max = len; if(len > max) max = len;
} }
} }
@@ -485,7 +458,7 @@ uint32_t longest_field_length(struct ascii* art, int la) {
} }
#if defined(ARCH_X86) || defined(ARCH_PPC) #if defined(ARCH_X86) || defined(ARCH_PPC)
void print_ascii_generic(struct ascii* art, uint32_t la, int32_t termw, const char** attribute_fields, bool hybrid_architecture) { void print_ascii_generic(struct ascii* art, uint32_t la, int32_t termw, bool use_short, bool hybrid_architecture) {
struct ascii_logo* logo = art->art; struct ascii_logo* logo = art->art;
int attr_to_print = 0; int attr_to_print = 0;
int attr_type; int attr_type;
@@ -547,14 +520,15 @@ void print_ascii_generic(struct ascii* art, uint32_t la, int32_t termw, const ch
else { else {
#endif #endif
beg_space = 0; beg_space = 0;
space_right = 2 + 1 + (la - strlen(attribute_fields[attr_type])); const char* attr_str = use_short ? ATTRIBUTE_INFO[attr_type].shortname : ATTRIBUTE_INFO[attr_type].name;
space_right = 2 + 1 + (la - strlen(attr_str));
if(hybrid_architecture && add_space) { if(hybrid_architecture && add_space) {
beg_space = 2; beg_space = 2;
space_right -= 2; space_right -= 2;
} }
printOut(lbuf, beg_space + strlen(attribute_fields[attr_type]) + space_right + strlen(attr_value), printOut(lbuf, beg_space + strlen(attr_str) + space_right + strlen(attr_value),
"%*s%s%s%s%*s%s%s%s", beg_space, "", logo->color_text[0], attribute_fields[attr_type], art->reset, space_right, "", logo->color_text[1], attr_value, art->reset); "%*s%s%s%s%*s%s%s%s", beg_space, "", logo->color_text[0], attr_str, art->reset, space_right, "", logo->color_text[1], attr_value, art->reset);
#ifdef ARCH_X86 #ifdef ARCH_X86
} }
#endif #endif
@@ -663,19 +637,19 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
setAttribute(art, ATTRIBUTE_PEAK, pp); setAttribute(art, ATTRIBUTE_PEAK, pp);
// Step 3. Print output // Step 3. Print output
const char** attribute_fields = ATTRIBUTE_FIELDS; bool use_short = false;
uint32_t longest_attribute = longest_attribute_length(art, attribute_fields); uint32_t longest_attribute = longest_attribute_length(art, use_short);
uint32_t longest_field = longest_field_length(art, longest_attribute); uint32_t longest_field = longest_field_length(art, longest_attribute);
choose_ascii_art(art, cs, term, longest_field); choose_ascii_art(art, cs, term, longest_field);
if(!ascii_fits_screen(term->w, *art->art, longest_field)) { if(!ascii_fits_screen(term->w, *art->art, longest_field)) {
// Despite of choosing the smallest logo, the output does not fit // Despite of choosing the smallest logo, the output does not fit
// Choose the shorter field names and recalculate the longest attr // Choose the shorter field names and recalculate the longest attr
attribute_fields = ATTRIBUTE_FIELDS_SHORT; use_short = true;
longest_attribute = longest_attribute_length(art, attribute_fields); longest_attribute = longest_attribute_length(art, use_short);
} }
print_ascii_generic(art, longest_attribute, term->w, attribute_fields, hybrid_architecture); print_ascii_generic(art, longest_attribute, term->w, use_short, hybrid_architecture);
free(manufacturing_process); free(manufacturing_process);
free(sockets); free(sockets);
@@ -724,7 +698,7 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
// Step 2. Set attributes // Step 2. Set attributes
if(cpu_name != NULL) { if(cpu_name != NULL) {
setAttribute(art, ATTRIBUTE_NAME, cpu_name); setAttribute(art, ATTRIBUTE_PART_NUMBER, cpu_name);
} }
setAttribute(art, ATTRIBUTE_UARCH, uarch); setAttribute(art, ATTRIBUTE_UARCH, uarch);
if(cpu->hv->present) { if(cpu->hv->present) {
@@ -751,19 +725,19 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
setAttribute(art, ATTRIBUTE_PEAK, pp); setAttribute(art, ATTRIBUTE_PEAK, pp);
// Step 3. Print output // Step 3. Print output
const char** attribute_fields = ATTRIBUTE_FIELDS; bool use_short = false;
uint32_t longest_attribute = longest_attribute_length(art, attribute_fields); uint32_t longest_attribute = longest_attribute_length(art, use_short);
uint32_t longest_field = longest_field_length(art, longest_attribute); uint32_t longest_field = longest_field_length(art, longest_attribute);
choose_ascii_art(art, cs, term, longest_field); choose_ascii_art(art, cs, term, longest_field);
if(!ascii_fits_screen(term->w, *art->art, longest_field)) { if(!ascii_fits_screen(term->w, *art->art, longest_field)) {
// Despite of choosing the smallest logo, the output does not fit // Despite of choosing the smallest logo, the output does not fit
// Choose the shorter field names and recalculate the longest attr // Choose the shorter field names and recalculate the longest attr
attribute_fields = ATTRIBUTE_FIELDS_SHORT; use_short = true;
longest_attribute = longest_attribute_length(art, attribute_fields); longest_attribute = longest_attribute_length(art, use_short);
} }
print_ascii_generic(art, longest_attribute, term->w, attribute_fields, false); print_ascii_generic(art, longest_attribute, term->w, use_short, false);
return true; return true;
} }
@@ -791,7 +765,7 @@ uint32_t longest_field_length_arm(struct ascii* art, int la) {
return max; return max;
} }
void print_ascii_arm(struct ascii* art, uint32_t la, int32_t termw, const char** attribute_fields) { void print_ascii_arm(struct ascii* art, uint32_t la, int32_t termw, bool use_short) {
struct ascii_logo* logo = art->art; struct ascii_logo* logo = art->art;
int attr_to_print = 0; int attr_to_print = 0;
int attr_type; int attr_type;
@@ -862,14 +836,15 @@ void print_ascii_arm(struct ascii* art, uint32_t la, int32_t termw, const char**
} }
else { else {
beg_space = 0; beg_space = 0;
space_right = 2 + 1 + (la - strlen(attribute_fields[attr_type])); const char* attr_str = use_short ? ATTRIBUTE_INFO[attr_type].shortname : ATTRIBUTE_INFO[attr_type].name;
space_right = 2 + 1 + (la - strlen(attr_str));
if(add_space) { if(add_space) {
beg_space = 2; beg_space = 2;
space_right -= 2; space_right -= 2;
} }
printOut(lbuf, beg_space + strlen(attribute_fields[attr_type]) + space_right + strlen(attr_value), printOut(lbuf, beg_space + strlen(attr_str) + space_right + strlen(attr_value),
"%*s%s%s%s%*s%s%s%s", beg_space, "", logo->color_text[0], attribute_fields[attr_type], art->reset, space_right, "", logo->color_text[1], attr_value, art->reset); "%*s%s%s%s%*s%s%s%s", beg_space, "", logo->color_text[0], attr_str, art->reset, space_right, "", logo->color_text[1], attr_value, art->reset);
} }
} }
printOutLine(lbuf, art, termw); printOutLine(lbuf, art, termw);
@@ -939,8 +914,8 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name); setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name);
} }
const char** attribute_fields = ATTRIBUTE_FIELDS; bool use_short = false;
uint32_t longest_attribute = longest_attribute_length(art, attribute_fields); uint32_t longest_attribute = longest_attribute_length(art, use_short);
uint32_t longest_field = longest_field_length_arm(art, longest_attribute); uint32_t longest_field = longest_field_length_arm(art, longest_attribute);
choose_ascii_art(art, cs, term, longest_field); choose_ascii_art(art, cs, term, longest_field);
@@ -952,11 +927,11 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
if(!ascii_fits_screen(term->w, *art->art, longest_field)) { if(!ascii_fits_screen(term->w, *art->art, longest_field)) {
// Despite of choosing the smallest logo, the output does not fit // Despite of choosing the smallest logo, the output does not fit
// Choose the shorter field names and recalculate the longest attr // Choose the shorter field names and recalculate the longest attr
attribute_fields = ATTRIBUTE_FIELDS_SHORT; use_short = true;
longest_attribute = longest_attribute_length(art, attribute_fields); longest_attribute = longest_attribute_length(art, use_short);
} }
print_ascii_arm(art, longest_attribute, term->w, attribute_fields); print_ascii_arm(art, longest_attribute, term->w, use_short);
free(manufacturing_process); free(manufacturing_process);
free(pp); free(pp);
@@ -974,14 +949,7 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
#endif #endif
#ifdef ARCH_RISCV #ifdef ARCH_RISCV
// https://stackoverflow.com/a/2709523 void print_ascii_riscv(struct ascii* art, uint32_t la, int32_t termw, bool use_short, bool* extensions_mask) {
uint64_t number_of_bits(uint64_t i) {
i = i - ((i >> 1) & 0x5555555555555555);
i = (i & 0x3333333333333333) + ((i >> 2) & 0x3333333333333333);
return (((i + (i >> 4)) & 0xF0F0F0F0F0F0F0F) * 0x101010101010101) >> 56;
}
void print_ascii_riscv(struct ascii* art, uint32_t la, int32_t termw, const char** attribute_fields, uint64_t extensions_mask) {
struct ascii_logo* logo = art->art; struct ascii_logo* logo = art->art;
int attr_to_print = 0; int attr_to_print = 0;
int attr_type; int attr_type;
@@ -991,7 +959,7 @@ void print_ascii_riscv(struct ascii* art, uint32_t la, int32_t termw, const char
int32_t ext_list_size = sizeof(extension_list)/sizeof(extension_list[0]); int32_t ext_list_size = sizeof(extension_list)/sizeof(extension_list[0]);
int32_t ext_num = 0; int32_t ext_num = 0;
int32_t ext_to_print = 0; int32_t ext_to_print = 0;
int32_t num_extensions = number_of_bits(extensions_mask); int32_t num_extensions = get_num_extensions(extensions_mask);
int32_t space_up = ((int)logo->height - (int)(art->n_attributes_set + num_extensions))/2; int32_t space_up = ((int)logo->height - (int)(art->n_attributes_set + num_extensions))/2;
int32_t space_down = (int)logo->height - (int)(art->n_attributes_set + num_extensions) - (int)space_up; int32_t space_down = (int)logo->height - (int)(art->n_attributes_set + num_extensions) - (int)space_up;
uint32_t logo_pos = 0; uint32_t logo_pos = 0;
@@ -1037,7 +1005,9 @@ void print_ascii_riscv(struct ascii* art, uint32_t la, int32_t termw, const char
// Print extension // Print extension
if(attr_to_print > 0 && art->attributes[attr_to_print-1]->type == ATTRIBUTE_EXTENSIONS && ext_num != num_extensions) { if(attr_to_print > 0 && art->attributes[attr_to_print-1]->type == ATTRIBUTE_EXTENSIONS && ext_num != num_extensions) {
// Search for the extension to print // Search for the extension to print
while(ext_to_print < ext_list_size && !((extensions_mask >> extension_list[ext_to_print].id) & 1U)) ext_to_print++; while (ext_to_print < ext_list_size && !((extensions_mask[extension_list[ext_to_print].id])))
ext_to_print++;
if(ext_to_print == ext_list_size) { if(ext_to_print == ext_list_size) {
printBug("print_ascii_riscv: Unable to find the extension to print"); printBug("print_ascii_riscv: Unable to find the extension to print");
} }
@@ -1049,10 +1019,11 @@ void print_ascii_riscv(struct ascii* art, uint32_t la, int32_t termw, const char
else { else {
attr_to_print++; attr_to_print++;
beg_space = 0; beg_space = 0;
space_right = 2 + 1 + (la - strlen(attribute_fields[attr_type])); const char* attr_str = use_short ? ATTRIBUTE_INFO[attr_type].shortname : ATTRIBUTE_INFO[attr_type].name;
space_right = 2 + 1 + (la - strlen(attr_str));
printOut(lbuf, beg_space + strlen(attribute_fields[attr_type]) + space_right + strlen(attr_value), printOut(lbuf, beg_space + strlen(attr_str) + space_right + strlen(attr_value),
"%*s%s%s%s%*s%s%s%s", beg_space, "", logo->color_text[0], attribute_fields[attr_type], art->reset, space_right, "", logo->color_text[1], attr_value, art->reset); "%*s%s%s%s%*s%s%s%s", beg_space, "", logo->color_text[0], attr_str, art->reset, space_right, "", logo->color_text[1], attr_value, art->reset);
} }
} }
printOutLine(lbuf, art, termw); printOutLine(lbuf, art, termw);
@@ -1090,19 +1061,19 @@ bool print_cpufetch_riscv(struct cpuInfo* cpu, STYLE s, struct color** cs, struc
setAttribute(art, ATTRIBUTE_PEAK, pp); setAttribute(art, ATTRIBUTE_PEAK, pp);
// Step 3. Print output // Step 3. Print output
const char** attribute_fields = ATTRIBUTE_FIELDS; bool use_short = false;
uint32_t longest_attribute = longest_attribute_length(art, attribute_fields); uint32_t longest_attribute = longest_attribute_length(art, use_short);
uint32_t longest_field = longest_field_length(art, longest_attribute); uint32_t longest_field = longest_field_length(art, longest_attribute);
choose_ascii_art(art, cs, term, longest_field); choose_ascii_art(art, cs, term, longest_field);
if(!ascii_fits_screen(term->w, *art->art, longest_field)) { if(!ascii_fits_screen(term->w, *art->art, longest_field)) {
// Despite of choosing the smallest logo, the output does not fit // Despite of choosing the smallest logo, the output does not fit
// Choose the shorter field names and recalculate the longest attr // Choose the shorter field names and recalculate the longest attr
attribute_fields = ATTRIBUTE_FIELDS_SHORT; use_short = true;
longest_attribute = longest_attribute_length(art, attribute_fields); longest_attribute = longest_attribute_length(art, use_short);
} }
print_ascii_riscv(art, longest_attribute, term->w, attribute_fields, cpu->ext->mask); print_ascii_riscv(art, longest_attribute, term->w, use_short, cpu->ext->mask);
return true; return true;
} }

View File

@@ -426,4 +426,4 @@ struct devtree** get_devtree_compatible_struct(int *num_vendors_ptr) {
*num_vendors_ptr = num_vendors; *num_vendors_ptr = num_vendors;
return vendors; return vendors;
} }

View File

@@ -12,7 +12,7 @@
#define SET_ISA_EXT_MAP(name, bit) \ #define SET_ISA_EXT_MAP(name, bit) \
if(strncmp(multi_letter_extension, name, \ if(strncmp(multi_letter_extension, name, \
multi_letter_extension_len) == 0) { \ multi_letter_extension_len) == 0) { \
ext->mask |= 1UL << bit; \ ext->mask[bit] = true; \
maskset = true; \ maskset = true; \
} \ } \
@@ -62,7 +62,6 @@ int parse_multi_letter_extension(struct extensions* ext, char* e) {
SET_ISA_EXT_MAP("zicbom", RISCV_ISA_EXT_ZICBOM) SET_ISA_EXT_MAP("zicbom", RISCV_ISA_EXT_ZICBOM)
SET_ISA_EXT_MAP("zihintpause", RISCV_ISA_EXT_ZIHINTPAUSE) SET_ISA_EXT_MAP("zihintpause", RISCV_ISA_EXT_ZIHINTPAUSE)
SET_ISA_EXT_MAP("svnapot", RISCV_ISA_EXT_SVNAPOT) SET_ISA_EXT_MAP("svnapot", RISCV_ISA_EXT_SVNAPOT)
SET_ISA_EXT_MAP("zicbop", RISCV_ISA_EXT_ZICBOP)
SET_ISA_EXT_MAP("zicboz", RISCV_ISA_EXT_ZICBOZ) SET_ISA_EXT_MAP("zicboz", RISCV_ISA_EXT_ZICBOZ)
SET_ISA_EXT_MAP("smaia", RISCV_ISA_EXT_SMAIA) SET_ISA_EXT_MAP("smaia", RISCV_ISA_EXT_SMAIA)
SET_ISA_EXT_MAP("ssaia", RISCV_ISA_EXT_SSAIA) SET_ISA_EXT_MAP("ssaia", RISCV_ISA_EXT_SSAIA)
@@ -72,6 +71,65 @@ int parse_multi_letter_extension(struct extensions* ext, char* e) {
SET_ISA_EXT_MAP("zicsr", RISCV_ISA_EXT_ZICSR) SET_ISA_EXT_MAP("zicsr", RISCV_ISA_EXT_ZICSR)
SET_ISA_EXT_MAP("zifencei", RISCV_ISA_EXT_ZIFENCEI) SET_ISA_EXT_MAP("zifencei", RISCV_ISA_EXT_ZIFENCEI)
SET_ISA_EXT_MAP("zihpm", RISCV_ISA_EXT_ZIHPM) SET_ISA_EXT_MAP("zihpm", RISCV_ISA_EXT_ZIHPM)
SET_ISA_EXT_MAP("smstateen", RISCV_ISA_EXT_SMSTATEEN)
SET_ISA_EXT_MAP("zicond", RISCV_ISA_EXT_ZICOND)
SET_ISA_EXT_MAP("zbc", RISCV_ISA_EXT_ZBC)
SET_ISA_EXT_MAP("zbkb", RISCV_ISA_EXT_ZBKB)
SET_ISA_EXT_MAP("zbkc", RISCV_ISA_EXT_ZBKC)
SET_ISA_EXT_MAP("zbkx", RISCV_ISA_EXT_ZBKX)
SET_ISA_EXT_MAP("zknd", RISCV_ISA_EXT_ZKND)
SET_ISA_EXT_MAP("zkne", RISCV_ISA_EXT_ZKNE)
SET_ISA_EXT_MAP("zknh", RISCV_ISA_EXT_ZKNH)
SET_ISA_EXT_MAP("zkr", RISCV_ISA_EXT_ZKR)
SET_ISA_EXT_MAP("zksed", RISCV_ISA_EXT_ZKSED)
SET_ISA_EXT_MAP("zksh", RISCV_ISA_EXT_ZKSH)
SET_ISA_EXT_MAP("zkt", RISCV_ISA_EXT_ZKT)
SET_ISA_EXT_MAP("zvbb", RISCV_ISA_EXT_ZVBB)
SET_ISA_EXT_MAP("zvbc", RISCV_ISA_EXT_ZVBC)
SET_ISA_EXT_MAP("zvkb", RISCV_ISA_EXT_ZVKB)
SET_ISA_EXT_MAP("zvkg", RISCV_ISA_EXT_ZVKG)
SET_ISA_EXT_MAP("zvkned", RISCV_ISA_EXT_ZVKNED)
SET_ISA_EXT_MAP("zvknha", RISCV_ISA_EXT_ZVKNHA)
SET_ISA_EXT_MAP("zvknhb", RISCV_ISA_EXT_ZVKNHB)
SET_ISA_EXT_MAP("zvksed", RISCV_ISA_EXT_ZVKSED)
SET_ISA_EXT_MAP("zvksh", RISCV_ISA_EXT_ZVKSH)
SET_ISA_EXT_MAP("zvkt", RISCV_ISA_EXT_ZVKT)
SET_ISA_EXT_MAP("zfh", RISCV_ISA_EXT_ZFH)
SET_ISA_EXT_MAP("zfhmin", RISCV_ISA_EXT_ZFHMIN)
SET_ISA_EXT_MAP("zihintntl", RISCV_ISA_EXT_ZIHINTNTL)
SET_ISA_EXT_MAP("zvfh", RISCV_ISA_EXT_ZVFH)
SET_ISA_EXT_MAP("zvfhmin", RISCV_ISA_EXT_ZVFHMIN)
SET_ISA_EXT_MAP("zfa", RISCV_ISA_EXT_ZFA)
SET_ISA_EXT_MAP("ztso", RISCV_ISA_EXT_ZTSO)
SET_ISA_EXT_MAP("zacas", RISCV_ISA_EXT_ZACAS)
SET_ISA_EXT_MAP("zve32x", RISCV_ISA_EXT_ZVE32X)
SET_ISA_EXT_MAP("zve32f", RISCV_ISA_EXT_ZVE32F)
SET_ISA_EXT_MAP("zve64x", RISCV_ISA_EXT_ZVE64X)
SET_ISA_EXT_MAP("zve64f", RISCV_ISA_EXT_ZVE64F)
SET_ISA_EXT_MAP("zve64d", RISCV_ISA_EXT_ZVE64D)
SET_ISA_EXT_MAP("zimop", RISCV_ISA_EXT_ZIMOP)
SET_ISA_EXT_MAP("zca", RISCV_ISA_EXT_ZCA)
SET_ISA_EXT_MAP("zcb", RISCV_ISA_EXT_ZCB)
SET_ISA_EXT_MAP("zcd", RISCV_ISA_EXT_ZCD)
SET_ISA_EXT_MAP("zcf", RISCV_ISA_EXT_ZCF)
SET_ISA_EXT_MAP("zcmop", RISCV_ISA_EXT_ZCMOP)
SET_ISA_EXT_MAP("zawrs", RISCV_ISA_EXT_ZAWRS)
SET_ISA_EXT_MAP("svvptc", RISCV_ISA_EXT_SVVPTC)
SET_ISA_EXT_MAP("smmpm", RISCV_ISA_EXT_SMMPM)
SET_ISA_EXT_MAP("smnpm", RISCV_ISA_EXT_SMNPM)
SET_ISA_EXT_MAP("ssnpm", RISCV_ISA_EXT_SSNPM)
SET_ISA_EXT_MAP("zabha", RISCV_ISA_EXT_ZABHA)
SET_ISA_EXT_MAP("ziccrse", RISCV_ISA_EXT_ZICCRSE)
SET_ISA_EXT_MAP("svade", RISCV_ISA_EXT_SVADE)
SET_ISA_EXT_MAP("svadu", RISCV_ISA_EXT_SVADU)
SET_ISA_EXT_MAP("zfbfmin", RISCV_ISA_EXT_ZFBFMIN)
SET_ISA_EXT_MAP("zvfbfmin", RISCV_ISA_EXT_ZVFBFMIN)
SET_ISA_EXT_MAP("zvfbfwma", RISCV_ISA_EXT_ZVFBFWMA)
SET_ISA_EXT_MAP("zaamo", RISCV_ISA_EXT_ZAAMO)
SET_ISA_EXT_MAP("zalrsc", RISCV_ISA_EXT_ZALRSC)
SET_ISA_EXT_MAP("zicbop", RISCV_ISA_EXT_ZICBOP)
SET_ISA_EXT_MAP("ime", RISCV_ISA_EXT_IME)
if(!maskset) { if(!maskset) {
printBug("parse_multi_letter_extension: Unknown multi-letter extension: %s", multi_letter_extension); printBug("parse_multi_letter_extension: Unknown multi-letter extension: %s", multi_letter_extension);
return -1; return -1;
@@ -94,7 +152,7 @@ bool valid_extension(char ext) {
struct extensions* get_extensions_from_str(char* str) { struct extensions* get_extensions_from_str(char* str) {
struct extensions* ext = emalloc(sizeof(struct extensions)); struct extensions* ext = emalloc(sizeof(struct extensions));
ext->mask = 0; ext->mask = ecalloc(RISCV_ISA_EXT_ID_MAX, sizeof(bool));
ext->str = NULL; ext->str = NULL;
if(str == NULL) { if(str == NULL) {
@@ -107,6 +165,8 @@ struct extensions* get_extensions_from_str(char* str) {
// Code inspired in Linux kernel (riscv_fill_hwcap): // Code inspired in Linux kernel (riscv_fill_hwcap):
// https://elixir.bootlin.com/linux/v6.2.10/source/arch/riscv/kernel/cpufeature.c // https://elixir.bootlin.com/linux/v6.2.10/source/arch/riscv/kernel/cpufeature.c
// Now it seems to be here in riscv_parse_isa_string:
// https://elixir.bootlin.com/linux/v6.16/source/arch/riscv/kernel/cpufeature.c
char* isa = str; char* isa = str;
if (!strncmp(isa, "rv32", 4)) if (!strncmp(isa, "rv32", 4))
isa += 4; isa += 4;
@@ -138,7 +198,7 @@ struct extensions* get_extensions_from_str(char* str) {
// adding it to the mask // adding it to the mask
if(valid_extension(*e)) { if(valid_extension(*e)) {
int n = *e - 'a'; int n = *e - 'a';
ext->mask |= 1UL << n; ext->mask[n] = true;
} }
else { else {
printBug("get_extensions_from_str: Invalid extension: '%c'", *e); printBug("get_extensions_from_str: Invalid extension: '%c'", *e);
@@ -149,6 +209,18 @@ struct extensions* get_extensions_from_str(char* str) {
return ext; return ext;
} }
uint32_t get_num_extensions(bool* mask) {
uint32_t num = 0;
for (int i=0; i < RISCV_ISA_EXT_ID_MAX; i++) {
if (mask[i]) num++;
}
return num;
}
bool is_mask_empty(bool* mask) {
return get_num_extensions(mask) == 0;
}
struct cpuInfo* get_cpu_info(void) { struct cpuInfo* get_cpu_info(void) {
struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo)); struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo));
//init_cpu_info(cpu); //init_cpu_info(cpu);
@@ -161,7 +233,7 @@ struct cpuInfo* get_cpu_info(void) {
cpu->hv = emalloc(sizeof(struct hypervisor)); cpu->hv = emalloc(sizeof(struct hypervisor));
cpu->hv->present = false; cpu->hv->present = false;
cpu->ext = get_extensions_from_str(ext_str); cpu->ext = get_extensions_from_str(ext_str);
if(cpu->ext->str != NULL && cpu->ext->mask == 0) return NULL; if(cpu->ext->str != NULL && is_mask_empty(cpu->ext->mask)) return NULL;
cpu->arch = get_uarch(cpu); cpu->arch = get_uarch(cpu);
cpu->soc = get_soc(cpu); cpu->soc = get_soc(cpu);
cpu->freq = get_frequency_info(0); cpu->freq = get_frequency_info(0);

View File

@@ -23,7 +23,6 @@ enum riscv_isa_ext_id {
RISCV_ISA_EXT_ZICBOM, RISCV_ISA_EXT_ZICBOM,
RISCV_ISA_EXT_ZIHINTPAUSE, RISCV_ISA_EXT_ZIHINTPAUSE,
RISCV_ISA_EXT_SVNAPOT, RISCV_ISA_EXT_SVNAPOT,
RISCV_ISA_EXT_ZICBOP,
RISCV_ISA_EXT_ZICBOZ, RISCV_ISA_EXT_ZICBOZ,
RISCV_ISA_EXT_SMAIA, RISCV_ISA_EXT_SMAIA,
RISCV_ISA_EXT_SSAIA, RISCV_ISA_EXT_SSAIA,
@@ -33,12 +32,73 @@ enum riscv_isa_ext_id {
RISCV_ISA_EXT_ZICSR, RISCV_ISA_EXT_ZICSR,
RISCV_ISA_EXT_ZIFENCEI, RISCV_ISA_EXT_ZIFENCEI,
RISCV_ISA_EXT_ZIHPM, RISCV_ISA_EXT_ZIHPM,
RISCV_ISA_EXT_SMSTATEEN,
RISCV_ISA_EXT_ZICOND,
RISCV_ISA_EXT_ZBC,
RISCV_ISA_EXT_ZBKB,
RISCV_ISA_EXT_ZBKC,
RISCV_ISA_EXT_ZBKX,
RISCV_ISA_EXT_ZKND,
RISCV_ISA_EXT_ZKNE,
RISCV_ISA_EXT_ZKNH,
RISCV_ISA_EXT_ZKR,
RISCV_ISA_EXT_ZKSED,
RISCV_ISA_EXT_ZKSH,
RISCV_ISA_EXT_ZKT,
RISCV_ISA_EXT_ZVBB,
RISCV_ISA_EXT_ZVBC,
RISCV_ISA_EXT_ZVKB,
RISCV_ISA_EXT_ZVKG,
RISCV_ISA_EXT_ZVKNED,
RISCV_ISA_EXT_ZVKNHA,
RISCV_ISA_EXT_ZVKNHB,
RISCV_ISA_EXT_ZVKSED,
RISCV_ISA_EXT_ZVKSH,
RISCV_ISA_EXT_ZVKT,
RISCV_ISA_EXT_ZFH,
RISCV_ISA_EXT_ZFHMIN,
RISCV_ISA_EXT_ZIHINTNTL,
RISCV_ISA_EXT_ZVFH,
RISCV_ISA_EXT_ZVFHMIN,
RISCV_ISA_EXT_ZFA,
RISCV_ISA_EXT_ZTSO,
RISCV_ISA_EXT_ZACAS,
RISCV_ISA_EXT_ZVE32X,
RISCV_ISA_EXT_ZVE32F,
RISCV_ISA_EXT_ZVE64X,
RISCV_ISA_EXT_ZVE64F,
RISCV_ISA_EXT_ZVE64D,
RISCV_ISA_EXT_ZIMOP,
RISCV_ISA_EXT_ZCA,
RISCV_ISA_EXT_ZCB,
RISCV_ISA_EXT_ZCD,
RISCV_ISA_EXT_ZCF,
RISCV_ISA_EXT_ZCMOP,
RISCV_ISA_EXT_ZAWRS,
RISCV_ISA_EXT_SVVPTC,
RISCV_ISA_EXT_SMMPM,
RISCV_ISA_EXT_SMNPM,
RISCV_ISA_EXT_SSNPM,
RISCV_ISA_EXT_ZABHA,
RISCV_ISA_EXT_ZICCRSE,
RISCV_ISA_EXT_SVADE,
RISCV_ISA_EXT_SVADU,
RISCV_ISA_EXT_ZFBFMIN,
RISCV_ISA_EXT_ZVFBFMIN,
RISCV_ISA_EXT_ZVFBFWMA,
RISCV_ISA_EXT_ZAAMO,
RISCV_ISA_EXT_ZALRSC,
RISCV_ISA_EXT_ZICBOP,
RISCV_ISA_EXT_IME, // This is not in the kernel! but it was seen on a Muse Pi Pro board
RISCV_ISA_EXT_ID_MAX RISCV_ISA_EXT_ID_MAX
}; };
// https://five-embeddev.com/riscv-isa-manual/latest/preface.html#preface // https://five-embeddev.com/riscv-isa-manual/latest/preface.html#preface
// https://en.wikichip.org/wiki/risc-v/standard_extensions // https://en.wikichip.org/wiki/risc-v/standard_extensions
// (Zicbop) https://github.com/riscv/riscv-CMOs/blob/master/cmobase/Zicbop.adoc // (Zicbop) https://github.com/riscv/riscv-CMOs/blob/master/cmobase/Zicbop.adoc
// https://raw.githubusercontent.com/riscv/riscv-CMOs/master/specifications/cmobase-v1.0.1.pdf
// https://www.kernel.org/doc/Documentation/devicetree/bindings/riscv/extensions.yaml
// (Ime) https://github.com/riscv/integrated-matrix-extension (not confirmed, just a guess...)
// Included all except for G // Included all except for G
static const struct extension extension_list[] = { static const struct extension extension_list[] = {
{ 'i' - 'a', "(I) Integer Instruction Set" }, { 'i' - 'a', "(I) Integer Instruction Set" },
@@ -74,12 +134,71 @@ static const struct extension extension_list[] = {
{ RISCV_ISA_EXT_ZICNTR, "(Zicntr) Base Counters and Timers" }, { RISCV_ISA_EXT_ZICNTR, "(Zicntr) Base Counters and Timers" },
{ RISCV_ISA_EXT_ZICSR, "(Zicsr) Control and Status Register" }, { RISCV_ISA_EXT_ZICSR, "(Zicsr) Control and Status Register" },
{ RISCV_ISA_EXT_ZIFENCEI, "(Zifencei) Instruction-Fetch Fence" }, { RISCV_ISA_EXT_ZIFENCEI, "(Zifencei) Instruction-Fetch Fence" },
{ RISCV_ISA_EXT_ZIHPM, "(Zihpm) Hardware Performance Counters" } { RISCV_ISA_EXT_ZIHPM, "(Zihpm) Hardware Performance Counters" },
{ RISCV_ISA_EXT_SMSTATEEN, "(Smstateen) " },
{ RISCV_ISA_EXT_ZICOND, "(Zicond) Integer Conditional Operations" },
{ RISCV_ISA_EXT_ZBC, "(Zbc) Carry-Less Multiplication" },
{ RISCV_ISA_EXT_ZBKB, "(Zbkb) " },
{ RISCV_ISA_EXT_ZBKC, "(Zbkc) " },
{ RISCV_ISA_EXT_ZBKX, "(Zbkx) " },
{ RISCV_ISA_EXT_ZKND, "(Zknd) " },
{ RISCV_ISA_EXT_ZKNE, "(Zkne) " },
{ RISCV_ISA_EXT_ZKNH, "(Zknh) " },
{ RISCV_ISA_EXT_ZKR, "(Zkr) " },
{ RISCV_ISA_EXT_ZKSED, "(Zksed) " },
{ RISCV_ISA_EXT_ZKSH, "(Zksh) " },
{ RISCV_ISA_EXT_ZKT, "(Zkt) Data-Independent Execution Latency" },
{ RISCV_ISA_EXT_ZVBB, "(Zvbb) " },
{ RISCV_ISA_EXT_ZVBC, "(Zvbc) " },
{ RISCV_ISA_EXT_ZVKB, "(Zvkb) " },
{ RISCV_ISA_EXT_ZVKG, "(Zvkg) " },
{ RISCV_ISA_EXT_ZVKNED, "(Zvkned) " },
{ RISCV_ISA_EXT_ZVKNHA, "(Zvknha) " },
{ RISCV_ISA_EXT_ZVKNHB, "(Zvknhb) " },
{ RISCV_ISA_EXT_ZVKSED, "(Zvksed) " },
{ RISCV_ISA_EXT_ZVKSH, "(Zvksh) " },
{ RISCV_ISA_EXT_ZVKT, "(Zvkt) " },
{ RISCV_ISA_EXT_ZFH, "(Zfh) " },
{ RISCV_ISA_EXT_ZFHMIN, "(Zfhmin) " },
{ RISCV_ISA_EXT_ZIHINTNTL, "(Zihintntl) " },
{ RISCV_ISA_EXT_ZVFH, "(Zvfh) " },
{ RISCV_ISA_EXT_ZVFHMIN, "(Zvfhmin) " },
{ RISCV_ISA_EXT_ZFA, "(Zfa) " },
{ RISCV_ISA_EXT_ZTSO, "(Ztso) " },
{ RISCV_ISA_EXT_ZACAS, "(Zacas) " },
{ RISCV_ISA_EXT_ZVE32X, "(Zve32x) Vector Extensions (i32)" },
{ RISCV_ISA_EXT_ZVE32F, "(Zve32f) Vector Extensions (f32)" },
{ RISCV_ISA_EXT_ZVE64X, "(Zve64x) Vector Extensions (i64)" },
{ RISCV_ISA_EXT_ZVE64F, "(Zve64f) Vector Extensions (f64)" },
{ RISCV_ISA_EXT_ZVE64D, "(Zve64d) Vector Extensions (???)" },
{ RISCV_ISA_EXT_ZIMOP, "(Zimop) " },
{ RISCV_ISA_EXT_ZCA, "(Zca) " },
{ RISCV_ISA_EXT_ZCB, "(Zcb) " },
{ RISCV_ISA_EXT_ZCD, "(Zcd) " },
{ RISCV_ISA_EXT_ZCF, "(Zcf) " },
{ RISCV_ISA_EXT_ZCMOP, "(Zcmop) " },
{ RISCV_ISA_EXT_ZAWRS, "(Zawrs) " },
{ RISCV_ISA_EXT_SVVPTC, "(Svvptc) " },
{ RISCV_ISA_EXT_SMMPM, "(Smmpm) " },
{ RISCV_ISA_EXT_SMNPM, "(Smnpm) " },
{ RISCV_ISA_EXT_SSNPM, "(Ssnpm) " },
{ RISCV_ISA_EXT_ZABHA, "(Zabha) " },
{ RISCV_ISA_EXT_ZICCRSE, "(Ziccrse) " },
{ RISCV_ISA_EXT_SVADE, "(Svade) " },
{ RISCV_ISA_EXT_SVADU, "(Svadu) " },
{ RISCV_ISA_EXT_ZFBFMIN, "(Zfbfmin) " },
{ RISCV_ISA_EXT_ZVFBFMIN, "(Zvfbfmin) " },
{ RISCV_ISA_EXT_ZVFBFWMA, "(Zvfbfwma) " },
{ RISCV_ISA_EXT_ZAAMO, "(Zaamo) " },
{ RISCV_ISA_EXT_ZALRSC, "(Zalrsc) " },
{ RISCV_ISA_EXT_ZICBOP, "(Zicbop) " },
{ RISCV_ISA_EXT_IME, "(Ime) Integrated Matrix Extension" },
}; };
struct cpuInfo* get_cpu_info(void); struct cpuInfo* get_cpu_info(void);
char* get_str_topology(struct cpuInfo* cpu, struct topology* topo); char* get_str_topology(struct cpuInfo* cpu, struct topology* topo);
char* get_str_extensions(struct cpuInfo* cpu); char* get_str_extensions(struct cpuInfo* cpu);
uint32_t get_num_extensions(bool* mask);
void print_debug(struct cpuInfo* cpu); void print_debug(struct cpuInfo* cpu);
#endif #endif

View File

@@ -78,7 +78,7 @@ char* parse_cpuinfo_field(char* field_str) {
return ret; return ret;
} }
unsigned long parse_cpuinfo_field_uint64(char* field_str) { unsigned long parse_cpuinfo_field_uint64(char* field_str) {
int filelen; int filelen;
char* buf; char* buf;
if((buf = read_file(_PATH_CPUINFO, &filelen)) == NULL) { if((buf = read_file(_PATH_CPUINFO, &filelen)) == NULL) {
@@ -97,13 +97,13 @@ unsigned long parse_cpuinfo_field_uint64(char* field_str) {
printWarn("strtoul: %s: %s", strerror(errno), tmp); printWarn("strtoul: %s: %s", strerror(errno), tmp);
return 0; return 0;
} }
return ret; return ret;
} }
// Creates and fills in the riscv_cpuinfo struct (which contains // Creates and fills in the riscv_cpuinfo struct (which contains
// mvendorid, marchid and mimpid) using cpuinfo to fetch the values. // mvendorid, marchid and mimpid) using cpuinfo to fetch the values.
// //
// Every RISC-V hart (hardware thread) [1] provides a // Every RISC-V hart (hardware thread) [1] provides a
// marchid (Machine Architecture ID register) CSR that encodes its // marchid (Machine Architecture ID register) CSR that encodes its
// base microarchitecture [2]. For more information about // base microarchitecture [2]. For more information about

View File

@@ -333,6 +333,15 @@ struct features* get_features_info(struct cpuInfo* cpu) {
bool hv_present = (ecx & (1U << 31)) != 0; bool hv_present = (ecx & (1U << 31)) != 0;
if((cpu->hv = get_hp_info(hv_present)) == NULL) if((cpu->hv = get_hp_info(hv_present)) == NULL)
return NULL; return NULL;
if(cpu->hv->present) {
// Hypervisor will likely mess up something and users will think that
// there is something wrong with cpufetch whereas actually cpufetch has
// nothing to do with it.
// https://github.com/Dr-Noob/cpufetch/issues/96
// https://github.com/Dr-Noob/cpufetch/issues/267
// https://github.com/Dr-Noob/cpufetch/issues/293
printWarn("You are running an hypervisor. Please note that it will likely tamper your results, so do not post an issue if you find anything incorrect");
}
} }
else { else {
printWarn("Can't read features information from cpuid (needed level is 0x%.8X, max is 0x%.8X)", 0x00000001, cpu->maxLevels); printWarn("Can't read features information from cpuid (needed level is 0x%.8X, max is 0x%.8X)", 0x00000001, cpu->maxLevels);

View File

@@ -255,7 +255,7 @@ struct uarch* get_uarch_from_cpuid_intel(uint32_t ef, uint32_t f, uint32_t em, u
// CHECK_UARCH(arch, 0, 6, 8, 14, 9, ...) It is not possible to determine uarch only from CPUID dump (can be Kaby Lake or Amber Lake) // CHECK_UARCH(arch, 0, 6, 8, 14, 9, ...) It is not possible to determine uarch only from CPUID dump (can be Kaby Lake or Amber Lake)
// CHECK_UARCH(arch, 0, 6, 8, 14, 10, ...) It is not possible to determine uarch only from CPUID dump (can be Kaby Lake R or Coffee Lake U) // CHECK_UARCH(arch, 0, 6, 8, 14, 10, ...) It is not possible to determine uarch only from CPUID dump (can be Kaby Lake R or Coffee Lake U)
CHECK_UARCH(arch, 0, 6, 8, 14, 11, "Whiskey Lake", UARCH_WHISKEY_LAKE, 14) // wikichip CHECK_UARCH(arch, 0, 6, 8, 14, 11, "Whiskey Lake", UARCH_WHISKEY_LAKE, 14) // wikichip
CHECK_UARCH(arch, 0, 6, 8, 14, 12, "Comet Lake", UARCH_COMET_LAKE, 14) // wikichip // CHECK_UARCH(arch, 0, 6, 8, 14, 12, ...) It is not possible to determine uarch only from CPUID dump (can be Comet Lake U or Whiskey Lake U)
CHECK_UARCH(arch, 0, 6, 8, 15, 8, "Sapphire Rapids", UARCH_SAPPHIRE_RAPIDS, 7) // wikichip CHECK_UARCH(arch, 0, 6, 8, 15, 8, "Sapphire Rapids", UARCH_SAPPHIRE_RAPIDS, 7) // wikichip
CHECK_UARCH(arch, 0, 6, 9, 6, NA, "Tremont", UARCH_TREMONT, 10) // LX* CHECK_UARCH(arch, 0, 6, 9, 6, NA, "Tremont", UARCH_TREMONT, 10) // LX*
CHECK_UARCH(arch, 0, 6, 9, 7, NA, "Alder Lake", UARCH_ALDER_LAKE, 10) // instlatx64 (Alder Lake-S) CHECK_UARCH(arch, 0, 6, 9, 7, NA, "Alder Lake", UARCH_ALDER_LAKE, 10) // instlatx64 (Alder Lake-S)
@@ -447,6 +447,7 @@ struct uarch* get_uarch_from_cpuid_hygon(uint32_t ef, uint32_t f, uint32_t em, u
struct uarch* get_uarch_from_cpuid(struct cpuInfo* cpu, uint32_t dump, uint32_t ef, uint32_t f, uint32_t em, uint32_t m, int s) { struct uarch* get_uarch_from_cpuid(struct cpuInfo* cpu, uint32_t dump, uint32_t ef, uint32_t f, uint32_t em, uint32_t m, int s) {
if(cpu->cpu_vendor == CPU_VENDOR_INTEL) { if(cpu->cpu_vendor == CPU_VENDOR_INTEL) {
struct uarch* arch = emalloc(sizeof(struct uarch)); struct uarch* arch = emalloc(sizeof(struct uarch));
// TODO: Refactor these 3 checks in a common function.
if(dump == 0x000806E9) { if(dump == 0x000806E9) {
if (cpu->cpu_name == NULL) { if (cpu->cpu_name == NULL) {
printErr("Unable to find uarch without CPU name"); printErr("Unable to find uarch without CPU name");
@@ -486,6 +487,30 @@ struct uarch* get_uarch_from_cpuid(struct cpuInfo* cpu, uint32_t dump, uint32_t
return arch; return arch;
} }
else if (dump == 0x000806EC) {
if (cpu->cpu_name == NULL) {
printErr("Unable to find uarch without CPU name");
fill_uarch(arch, STRING_UNKNOWN, UARCH_UNKNOWN, UNK);
return arch;
}
// It is not possible to determine uarch only from CPUID dump (can be Comet Lake U or Whiskey Lake U)
// https://github.com/Dr-Noob/cpufetch/issues/298
if (strstr(cpu->cpu_name, "i3-8145U") != NULL ||
strstr(cpu->cpu_name, "i5-8265U") != NULL ||
strstr(cpu->cpu_name, "i5-8365U") != NULL ||
strstr(cpu->cpu_name, "i7-8565U") != NULL ||
strstr(cpu->cpu_name, "i7-8665U") != NULL ||
strstr(cpu->cpu_name, "5405U") != NULL ||
strstr(cpu->cpu_name, "4205U") != NULL) {
fill_uarch(arch, "Whiskey Lake", UARCH_WHISKEY_LAKE, 14);
}
else {
fill_uarch(arch, "Comet Lake", UARCH_COMET_LAKE, 14);
}
return arch;
}
return get_uarch_from_cpuid_intel(ef, f, em, m, s); return get_uarch_from_cpuid_intel(ef, f, em, m, s);
} }
else if(cpu->cpu_vendor == CPU_VENDOR_AMD) { else if(cpu->cpu_vendor == CPU_VENDOR_AMD) {