[v1.03][RISCV] Implementing basic skeleton for RISC-V backend

This commit is contained in:
Dr-Noob
2023-04-01 16:46:54 +02:00
parent 1f450b23a1
commit 9a69a7f58d
10 changed files with 141 additions and 6 deletions

View File

@@ -43,8 +43,8 @@ ifneq ($(OS),Windows_NT)
endif endif
else ifeq ($(arch), $(filter $(arch), riscv64 riscv32)) else ifeq ($(arch), $(filter $(arch), riscv64 riscv32))
SRC_DIR=src/riscv/ SRC_DIR=src/riscv/
SOURCE += $(COMMON_SRC) $(SRC_DIR)riscv.c $(SRC_DIR)uarch.c SOURCE += $(COMMON_SRC) $(SRC_DIR)riscv.c $(SRC_DIR)uarch.c $(SRC_DIR)soc.c
HEADERS += $(COMMON_SRC) $(SRC_DIR)riscv.h $(SRC_DIR)uarch.h HEADERS += $(COMMON_SRC) $(SRC_DIR)riscv.h $(SRC_DIR)uarch.h $(SRC_DIR)soc.h
CFLAGS += -DARCH_RISCV -Wno-unused-parameter -std=c99 -fstack-protector-all CFLAGS += -DARCH_RISCV -Wno-unused-parameter -std=c99 -fstack-protector-all
else else
# Error lines should not be tabulated because Makefile complains about it # Error lines should not be tabulated because Makefile complains about it

View File

@@ -246,6 +246,26 @@ $C1##. ###. ####. #### ### .## #### ### ### #.##### \
$C1 ## \ $C1 ## \
$C1 " $C1 "
#define ASCII_RISCV \
"$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 \
"$C1 \ "$C1 \
@@ -348,6 +368,7 @@ asciiL logo_ibm = { ASCII_IBM, 42, 9, false, {C_FG_CYAN, C_FG_W
asciiL logo_apple = { ASCII_APPLE, 32, 17, false, {C_FG_WHITE}, {C_FG_CYAN, C_FG_B_WHITE} }; asciiL logo_apple = { ASCII_APPLE, 32, 17, false, {C_FG_WHITE}, {C_FG_CYAN, C_FG_B_WHITE} };
asciiL logo_allwinner = { ASCII_ALLWINNER, 47, 16, false, {C_FG_CYAN}, {C_FG_B_BLACK, C_FG_B_CYAN } }; asciiL logo_allwinner = { ASCII_ALLWINNER, 47, 16, false, {C_FG_CYAN}, {C_FG_B_BLACK, C_FG_B_CYAN } };
asciiL logo_rockchip = { ASCII_ROCKCHIP, 58, 8, false, {C_FG_CYAN, C_FG_YELLOW}, {C_FG_CYAN, C_FG_YELLOW} }; asciiL logo_rockchip = { ASCII_ROCKCHIP, 58, 8, false, {C_FG_CYAN, C_FG_YELLOW}, {C_FG_CYAN, C_FG_YELLOW} };
asciiL logo_riscv = { ASCII_RISCV, 63, 18, false, {C_FG_CYAN, C_FG_YELLOW}, {C_FG_CYAN, C_FG_YELLOW} };
// 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

@@ -20,6 +20,8 @@ enum {
CPU_VENDOR_SAMSUNG, CPU_VENDOR_SAMSUNG,
CPU_VENDOR_MARVELL, CPU_VENDOR_MARVELL,
CPU_VENDOR_PHYTIUM, CPU_VENDOR_PHYTIUM,
// ARCH_RISCV
CPU_VENDOR_RISCV,
// OTHERS // OTHERS
CPU_VENDOR_UNKNOWN, CPU_VENDOR_UNKNOWN,
CPU_VENDOR_INVALID CPU_VENDOR_INVALID
@@ -149,7 +151,7 @@ struct cpuInfo {
uint32_t midr; uint32_t midr;
#endif #endif
#ifdef ARCH_ARM #if defined(ARCH_ARM) || defined(ARCH_RISCV)
struct system_on_chip* soc; struct system_on_chip* soc;
#endif #endif

View File

@@ -22,6 +22,8 @@
#include "../arm/soc.h" #include "../arm/soc.h"
#elif ARCH_RISCV #elif ARCH_RISCV
#include "../riscv/riscv.h" #include "../riscv/riscv.h"
#include "../riscv/uarch.h"
#include "../riscv/soc.h"
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
@@ -366,6 +368,8 @@ void choose_ascii_art(struct ascii* art, struct color** cs, struct terminal* ter
else { else {
art->art = choose_ascii_art_aux(&logo_arm_l, &logo_arm, term, lf); art->art = choose_ascii_art_aux(&logo_arm_l, &logo_arm, term, lf);
} }
#elif ARCH_RISCV
art->art = &logo_riscv;
#endif #endif
// 2. Choose colors // 2. Choose colors
@@ -431,7 +435,7 @@ uint32_t longest_field_length(struct ascii* art, int la) {
return max; return max;
} }
#if defined(ARCH_X86) || defined(ARCH_PPC) #if defined(ARCH_X86) || defined(ARCH_PPC) || defined(ARCH_RISCV)
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, const char** attribute_fields, 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;
@@ -915,7 +919,50 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
#ifdef ARCH_RISCV #ifdef ARCH_RISCV
bool print_cpufetch_riscv(struct cpuInfo* cpu, STYLE s, struct color** cs, struct terminal* term) { bool print_cpufetch_riscv(struct cpuInfo* cpu, STYLE s, struct color** cs, struct terminal* term) {
printf("Unimplemented\n"); struct ascii* art = set_ascii(get_cpu_vendor(cpu), s);
if(art == NULL)
return false;
// Step 1. Retrieve attributes
char* uarch = get_str_uarch(cpu);
char* manufacturing_process = get_str_process(cpu->soc);
char* max_frequency = get_str_freq(cpu->freq);
char* n_cores = get_str_topology(cpu, cpu->topo);
/*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->peak_performance);
// Step 2. Set attributes
setAttribute(art,ATTRIBUTE_UARCH,uarch);
setAttribute(art,ATTRIBUTE_TECHNOLOGY,manufacturing_process);
setAttribute(art,ATTRIBUTE_FREQUENCY,max_frequency);
setAttribute(art,ATTRIBUTE_NCORES, n_cores);
/*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);
// Step 3. Print output
const char** attribute_fields = ATTRIBUTE_FIELDS;
uint32_t longest_attribute = longest_attribute_length(art, attribute_fields);
uint32_t longest_field = longest_field_length(art, longest_attribute);
choose_ascii_art(art, cs, term, longest_field);
if(!ascii_fits_screen(term->w, *art->art, longest_field)) {
// Despite of choosing the smallest logo, the output does not fit
// Choose the shorter field names and recalculate the longest attr
attribute_fields = ATTRIBUTE_FIELDS_SHORT;
longest_attribute = longest_attribute_length(art, attribute_fields);
}
print_ascii_generic(art, longest_attribute, term->w, attribute_fields, false);
return true; return true;
} }
#endif #endif

View File

@@ -3,8 +3,35 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "../common/global.h"
#include "../common/udev.h"
struct frequency* get_frequency_info(uint32_t core) {
struct frequency* freq = emalloc(sizeof(struct frequency));
freq->base = UNKNOWN_DATA;
freq->max = get_max_freq_from_file(core);
return freq;
}
struct cpuInfo* get_cpu_info(void) { struct cpuInfo* get_cpu_info(void) {
return NULL; struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo));
//init_cpu_info(cpu);
int ncores = get_ncores_from_cpuinfo();
cpu->hv = emalloc(sizeof(struct hypervisor));
cpu->hv->present = false;
//cpu->soc = get_soc();
//cpu->peak_performance = get_peak_performance(cpu);
cpu->peak_performance = 0;
cpu->freq = get_frequency_info(0);
cpu->cpu_vendor = CPU_VENDOR_RISCV;
return cpu;
}
char* get_str_topology(struct cpuInfo* cpu, struct topology* topo) {
return "Many cores";
} }
void print_debug(struct cpuInfo* cpu) { void print_debug(struct cpuInfo* cpu) {

View File

@@ -4,6 +4,7 @@
#include "../common/cpu.h" #include "../common/cpu.h"
struct cpuInfo* get_cpu_info(void); struct cpuInfo* get_cpu_info(void);
char* get_str_topology(struct cpuInfo* cpu, struct topology* topo);
void print_debug(struct cpuInfo* cpu); void print_debug(struct cpuInfo* cpu);
#endif #endif

9
src/riscv/soc.c Normal file
View File

@@ -0,0 +1,9 @@
#include "soc.h"
char* get_str_process(struct system_on_chip* soc) {
return "-1 nm";
}
char* get_soc_name(struct system_on_chip* soc) {
return "Unknown";
}

20
src/riscv/soc.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef __SOC__
#define __SOC__
#include "../common/cpu.h"
#include <stdint.h>
typedef int32_t SOC;
struct system_on_chip {
SOC soc_model;
VENDOR soc_vendor;
int32_t process;
char* soc_name;
char* raw_name;
};
char* get_soc_name(struct system_on_chip* soc);
char* get_str_process(struct system_on_chip* soc);
#endif

View File

@@ -1,11 +1,18 @@
#include <stdint.h> #include <stdint.h>
#include "uarch.h"
#include "../common/global.h"
struct uarch { struct uarch {
//MICROARCH uarch; //MICROARCH uarch;
char* uarch_str; char* uarch_str;
int32_t process; // measured in nanometers int32_t process; // measured in nanometers
}; };
char* get_str_uarch(struct cpuInfo* cpu) {
return "Unknown";
}
void free_uarch_struct(struct uarch* arch) { void free_uarch_struct(struct uarch* arch) {
} }

View File

@@ -6,6 +6,7 @@
struct uarch; struct uarch;
char* get_str_uarch(struct cpuInfo* cpu);
void free_uarch_struct(struct uarch* arch); void free_uarch_struct(struct uarch* arch);
#endif #endif