[v0.98][PPC] Start PowerPC port. It just compiles but nothing is displayed

This commit is contained in:
Dr-Noob
2021-07-27 20:26:17 +02:00
parent 7afb6fd0fe
commit f4aa335af1
10 changed files with 200 additions and 10 deletions

View File

@@ -9,6 +9,8 @@
#ifdef ARCH_X86
#include "../x86/uarch.h"
#elif ARCH_PPC
#include "../ppc/uarch.h"
#elif ARCH_ARM
#include "../arm/uarch.h"
#endif
@@ -30,11 +32,13 @@ int64_t get_freq(struct frequency* freq) {
return freq->max;
}
#ifdef ARCH_X86
#if defined(ARCH_X86) || defined(ARCH_PPC)
char* get_str_cpu_name(struct cpuInfo* cpu) {
return cpu->cpu_name;
}
#endif
#ifdef ARCH_X86
char* get_str_sockets(struct topology* topo) {
char* string = malloc(sizeof(char) * 2);
int32_t sanity_ret = snprintf(string, 2, "%d", topo->sockets);

View File

@@ -94,7 +94,9 @@ struct features {
bool SSE4_2;
bool FMA3;
bool FMA4;
bool SHA;
bool SHA;
#elif ARCH_PPC
bool altivec;
#elif ARCH_ARM
bool NEON;
bool SHA1;
@@ -111,7 +113,12 @@ struct cpuInfo {
struct cache* cach;
struct topology* topo;
struct features* feat;
#ifdef ARCH_PPC
// CPU name from model
char* cpu_name;
#endif
#ifdef ARCH_X86
// CPU name from model
char* cpu_name;
@@ -142,6 +149,10 @@ char* get_str_sockets(struct topology* topo);
uint32_t get_nsockets(struct topology* topo);
#endif
#ifdef ARCH_PPC
char* get_str_cpu_name(struct cpuInfo* cpu);
#endif
VENDOR get_cpu_vendor(struct cpuInfo* cpu);
int64_t get_freq(struct frequency* freq);

View File

@@ -53,7 +53,7 @@ void printBug(const char *fmt, ...) {
vsnprintf(buffer,buffer_size, fmt, args);
va_end(args);
fprintf(stderr,RED "[ERROR]: "RESET "%s\n",buffer);
#ifdef ARCH_X86
#if defined(ARCH_X86) || defined(ARCH_PPC)
fprintf(stderr,"Please, create a new issue with this error message and the output of 'cpufetch --debug' in https://github.com/Dr-Noob/cpufetch/issues\n");
#elif ARCH_ARM
fprintf(stderr,"Please, create a new issue with this error message, your smartphone/computer model and the output of 'cpufetch --debug' in https://github.com/Dr-Noob/cpufetch/issues\n");

View File

@@ -9,6 +9,9 @@
#ifdef ARCH_X86
static const char* ARCH_STR = "x86_64 build";
#include "../x86/cpuid.h"
#elif ARCH_PPC
static const char* ARCH_STR = "PowerPC build";
#include "../ppc/ppc.h"
#elif ARCH_ARM
static const char* ARCH_STR = "ARM build";
#include "../arm/midr.h"

View File

@@ -11,6 +11,8 @@
#ifdef ARCH_X86
#include "../x86/uarch.h"
#include "../x86/cpuid.h"
#elif ARCH_PPC
#include "../ppc/ppc.h"
#else
#include "../arm/uarch.h"
#include "../arm/midr.h"
@@ -45,7 +47,7 @@
#define COLOR_RESET "\x1b[m"
enum {
#ifdef ARCH_X86
#if defined(ARCH_X86) || defined(ARCH_PPC)
ATTRIBUTE_NAME,
#elif ARCH_ARM
ATTRIBUTE_SOC,
@@ -72,9 +74,9 @@ enum {
};
static const char* ATTRIBUTE_FIELDS [] = {
#ifdef ARCH_X86
#if defined(ARCH_X86) || defined(ARCH_PPC)
"Name:",
#elif ARCH_ARM
#elif ARCH_ARM
"SoC:",
"",
#endif
@@ -88,7 +90,7 @@ static const char* ATTRIBUTE_FIELDS [] = {
#ifdef ARCH_X86
"AVX:",
"FMA:",
#elif ARCH_ARM
#elif defined(ARCH_ARM) || defined(ARCH_PPC)
"Features: ",
#endif
"L1i Size:",
@@ -176,6 +178,12 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct colors* cs) {
printBug("Invalid CPU vendor in set_ascii (%d)", art->vendor);
return NULL;
}
#elif ARCH_PPC
COL_FANCY_1 = COLOR_BG_CYAN;
COL_FANCY_2 = COLOR_BG_WHITE;
COL_FANCY_3 = COLOR_FG_CYAN;
COL_FANCY_4 = COLOR_FG_WHITE;
art->ascii_chars[0] = '#';
#elif ARCH_ARM
if(art->vendor == SOC_VENDOR_SNAPDRAGON) {
COL_FANCY_1 = COLOR_BG_RED;
@@ -314,7 +322,9 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct colors* cs) {
else if(art->vendor == CPU_VENDOR_AMD)
strcpy(tmp, AMD_ASCII);
else
strcpy(tmp, UNKNOWN_ASCII);
strcpy(tmp, UNKNOWN_ASCII);
#elif ARCH_PPC
strcpy(tmp, UNKNOWN_ASCII);
#elif ARCH_ARM
if(art->vendor == SOC_VENDOR_SNAPDRAGON)
strcpy(tmp, SNAPDRAGON_ASCII);
@@ -507,6 +517,110 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
}
#endif
#ifdef ARCH_PPC
void print_algorithm_ppc(struct ascii* art, int n) {
for(int i=0; i < LINE_SIZE; i++) {
if(art->art[n][i] == '@')
printf("%s%c%s", art->color1_ascii, art->ascii_chars[0], art->reset);
else if(art->art[n][i] == '#')
printf("%s%c%s", art->color2_ascii, art->ascii_chars[1], art->reset);
else
printf("%c",art->art[n][i]);
}
}
void print_ascii_ppc(struct ascii* art, uint32_t la) {
int attr_to_print = 0;
int attr_type;
char* attr_value;
uint32_t space_right;
uint32_t space_up = (NUMBER_OF_LINES - art->n_attributes_set)/2;
uint32_t space_down = NUMBER_OF_LINES - art->n_attributes_set - space_up;
bool flag = false;
printf("\n");
for(uint32_t n=0;n<NUMBER_OF_LINES;n++) {
print_algorithm_ppc(art, n);
if(n > space_up-1 && n < NUMBER_OF_LINES-space_down) {
attr_type = art->attributes[attr_to_print]->type;
attr_value = art->attributes[attr_to_print]->value;
attr_to_print++;
space_right = 1 + (la - strlen(ATTRIBUTE_FIELDS[attr_type]));
printf("%s%s%s%*s%s%s%s\n", art->color1_text, ATTRIBUTE_FIELDS[attr_type], art->reset, space_right, "", art->color2_text, attr_value, art->reset);
}
else printf("\n");
}
printf("\n");
}
void print_ascii(struct ascii* art) {
uint32_t longest_attribute = longest_attribute_length(art);
print_ascii_ppc(art, longest_attribute);
}
bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
struct ascii* art = set_ascii(get_cpu_vendor(cpu), s, cs);
if(art == NULL)
return false;
/*char* uarch = get_str_uarch(cpu);
char* manufacturing_process = get_str_process(cpu);
char* sockets = get_str_sockets(cpu->topo);
char* max_frequency = get_str_freq(cpu->freq);
char* n_cores = get_str_topology(cpu, cpu->topo, false);
char* n_cores_dual = get_str_topology(cpu, cpu->topo, true);
*/
char* cpu_name = get_str_cpu_name(cpu);
/*
char* l1i = get_str_l1i(cpu->cach);
char* l1d = get_str_l1d(cpu->cach);
char* l2 = get_str_l2(cpu->cach);
char* l3 = get_str_l3(cpu->cach);
char* pp = get_str_peak_performance(cpu,cpu->topo,get_freq(cpu->freq));*/
setAttribute(art,ATTRIBUTE_NAME,cpu_name);
/*
if(cpu->hv->present) {
setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name);
}
setAttribute(art,ATTRIBUTE_UARCH,uarch);
setAttribute(art,ATTRIBUTE_TECHNOLOGY,manufacturing_process);
setAttribute(art,ATTRIBUTE_FREQUENCY,max_frequency);
uint32_t socket_num = get_nsockets(cpu->topo);
if (socket_num > 1) {
setAttribute(art, ATTRIBUTE_SOCKETS, sockets);
setAttribute(art, ATTRIBUTE_NCORES,n_cores);
setAttribute(art, ATTRIBUTE_NCORES_DUAL, n_cores_dual);
}
else {
setAttribute(art,ATTRIBUTE_NCORES,n_cores);
}
setAttribute(art,ATTRIBUTE_AVX,avx);
setAttribute(art,ATTRIBUTE_FMA,fma);
setAttribute(art,ATTRIBUTE_L1i,l1i);
setAttribute(art,ATTRIBUTE_L1d,l1d);
setAttribute(art,ATTRIBUTE_L2,l2);
if(l3 != NULL) {
setAttribute(art,ATTRIBUTE_L3,l3);
}
setAttribute(art,ATTRIBUTE_PEAK,pp);
*/
if(art->n_attributes_set > NUMBER_OF_LINES) {
printBug("The number of attributes set is bigger than the max that can be displayed");
return false;
}
print_ascii(art);
return true;
}
#endif
#ifdef ARCH_ARM
void print_algorithm_snapd_mtk(struct ascii* art, int n) {
for(int i=0; i < LINE_SIZE; i++) {
@@ -715,7 +829,9 @@ bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
#ifdef ARCH_X86
return print_cpufetch_x86(cpu, s, cs);
#elif ARCH_PPC
return print_cpufetch_ppc(cpu, s, cs);
#elif ARCH_ARM
return print_cpufetch_arm(cpu, s, cs);
return print_cpufetch_arm(cpu, s, cs);
#endif
}

28
src/ppc/ppc.c Normal file
View File

@@ -0,0 +1,28 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include "ppc.h"
#define STRING_UNKNOWN "Unknown"
struct cpuInfo* get_cpu_info() {
struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo));
struct features* feat = malloc(sizeof(struct features));
cpu->feat = feat;
bool *ptr = &(feat->AES);
for(uint32_t i = 0; i < sizeof(struct features)/sizeof(bool); i++, ptr++) {
*ptr = false;
}
cpu->cpu_name = malloc(sizeof(char) * strlen(STRING_UNKNOWN) + 1);
snprintf(cpu->cpu_name, strlen(STRING_UNKNOWN) + 1, STRING_UNKNOWN);
return cpu;
}
void print_debug(struct cpuInfo* cpu) {
printf("TODO\n");
}

9
src/ppc/ppc.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef __POWERPC__
#define __POWERPC__
#include "../common/cpu.h"
struct cpuInfo* get_cpu_info();
void print_debug(struct cpuInfo* cpu);
#endif

7
src/ppc/uarch.c Normal file
View File

@@ -0,0 +1,7 @@
struct uarch {
int d;
};
void free_uarch_struct(struct uarch* arch) {
}

6
src/ppc/uarch.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef __UARCH__
#define __UARCH__
void free_uarch_struct(struct uarch* arch);
#endif