[v0.88][ARM][BUGFIX] Fix some compilation issues

This commit is contained in:
Dr-Noob
2020-11-23 18:45:42 +01:00
parent eaa86522a4
commit bb05a4d577
5 changed files with 30 additions and 15 deletions

View File

@@ -128,13 +128,14 @@ struct cpuInfo* get_cpu_info() {
cpu->next_cpu = NULL;
int ncores = get_ncores_from_cpuinfo();
bool success = false;
uint32_t* midr_array = malloc(sizeof(uint32_t) * ncores);
uint32_t* ids_array = malloc(sizeof(uint32_t) * ncores);
for(int i=0; i < ncores; i++) {
midr_array[i] = get_midr_from_cpuinfo(i);
midr_array[i] = get_midr_from_cpuinfo(i, &success);
if(midr_array[i] == UNKNOWN) {
if(!success) {
printWarn("Unable to fetch MIDR for core %d. This is probably because the core is offline", i);
midr_array[i] = midr_array[0];
}
@@ -217,14 +218,15 @@ char* get_soc_name(struct cpuInfo* cpu) {
void print_debug(struct cpuInfo* cpu) {
int ncores = get_ncores_from_cpuinfo();
bool success = false;
for(int i=0; i < ncores; i++) {
printf("[Core %d] ", i);
long freq = get_max_freq_from_file(i);
uint32_t midr = get_midr_from_cpuinfo(i);
if(midr == UNKNOWN) {
uint32_t midr = get_midr_from_cpuinfo(i, &success);
if(!success) {
printWarn("Unable to fetch MIDR for core %d. This is probably because the core is offline", i);
printf("0x%.8X ", get_midr_from_cpuinfo(0));
printf("0x%.8X ", get_midr_from_cpuinfo(0, &success));
}
else {
printf("0x%.8X ", midr);

View File

@@ -7,6 +7,8 @@
#include "uarch.h"
#include "../common/global.h"
#define STRING_UNKNOWN "Unknown"
// Data not available
#define NA -1
@@ -276,8 +278,8 @@ char* get_str_uarch(struct cpuInfo* cpu) {
}
char* get_str_process(struct cpuInfo* cpu) {
char* str = malloc(sizeof(char) * (4+2+1));
sprintf(str, "%s", "Unknown");
char* str = malloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1));
snprintf(str, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
return str;
}

View File

@@ -534,7 +534,8 @@ void print_ascii(struct ascii* art) {
if(art->vendor == CPU_VENDOR_ARM)
print_ascii_arm(art, longest_attribute);
else {
printBug("Invalid CPU vendor: %d\n", art->vendor);
printWarn("Invalid CPU vendor: %d\n", art->vendor);
print_ascii_arm(art, longest_attribute);
}
}
@@ -581,7 +582,7 @@ bool print_cpufetch_arm(struct ascii* art, struct cpuInfo* cpu, struct colors* c
char* l2 = get_str_l2(ptr->cach);
char* l3 = get_str_l3(ptr->cach);
char* cpu_num = malloc(sizeof(char) * 6);
char* cpu_num = malloc(sizeof(char) * 9);
sprintf(cpu_num, "CPU %d:", i+1);
setAttribute(art, ATTRIBUTE_CPU_NUM, cpu_num);
setAttribute(art, ATTRIBUTE_UARCH, uarch);

View File

@@ -164,12 +164,14 @@ long parse_cpuinfo_field(char* buf, char* field_str, int field_base) {
}
// https://developer.arm.com/docs/ddi0595/h/aarch32-system-registers/midr
// https://static.docs.arm.com/ddi0595/h/SysReg_xml_v86A-2020-06.pdf
uint32_t get_midr_from_cpuinfo(uint32_t core) {
uint32_t get_midr_from_cpuinfo(uint32_t core, bool* success) {
int fd = open(_PATH_CPUINFO, O_RDONLY);
*success = true;
if(fd == -1) {
*success = false;
perror("open");
return UNKNOWN;
return 0;
}
//File exists, read it
@@ -191,8 +193,10 @@ uint32_t get_midr_from_cpuinfo(uint32_t core) {
tmp = strstr(tmp, CPUINFO_CPU_STRING);
}
if(tmp == NULL)
return UNKNOWN;
if(tmp == NULL) {
*success = false;
return 0;
}
uint32_t cpu_implementer;
uint32_t cpu_architecture;
@@ -204,30 +208,35 @@ uint32_t get_midr_from_cpuinfo(uint32_t core) {
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_IMPLEMENTER_STR, 16)) < 0) {
printf("Failed parsing cpu_implementer\n");
*success = false;
return 0;
}
cpu_implementer = (uint32_t) ret;
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_ARCHITECTURE_STR, 10)) < 0) {
printf("Failed parsing cpu_architecture\n");
*success = false;
return 0;
}
cpu_architecture = (uint32_t) 0xF; // Why?
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_VARIANT_STR, 16)) < 0) {
printf("Failed parsing cpu_variant\n");
*success = false;
return 0;
}
cpu_variant = (uint32_t) ret;
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_PART_STR, 16)) < 0) {
printf("Failed parsing cpu_part\n");
*success = false;
return 0;
}
cpu_part = (uint32_t) ret;
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_REVISION_STR, 10)) < 0) {
printf("Failed parsing cpu_revision\n");
*success = false;
return 0;
}
cpu_revision = (uint32_t) ret;

View File

@@ -2,6 +2,7 @@
#define __UDEV__
#include <stdint.h>
#include <stdbool.h>
long get_max_freq_from_file(uint32_t core);
long get_min_freq_from_file(uint32_t core);
@@ -9,7 +10,7 @@ long get_min_freq_from_file(uint32_t core);
#ifdef ARCH_ARM
#define UNKNOWN -1
int get_ncores_from_cpuinfo();
uint32_t get_midr_from_cpuinfo(uint32_t core);
uint32_t get_midr_from_cpuinfo(uint32_t core, bool* success);
#endif
#endif