diff --git a/Makefile b/Makefile index 0d7b6e7..dbd9c3c 100644 --- a/Makefile +++ b/Makefile @@ -43,8 +43,8 @@ ifneq ($(OS),Windows_NT) endif else ifeq ($(arch), $(filter $(arch), riscv64 riscv32)) SRC_DIR=src/riscv/ - SOURCE += $(COMMON_SRC) $(SRC_DIR)riscv.c $(SRC_DIR)uarch.c - HEADERS += $(COMMON_SRC) $(SRC_DIR)riscv.h $(SRC_DIR)uarch.h + 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 $(SRC_DIR)soc.h CFLAGS += -DARCH_RISCV -Wno-unused-parameter -std=c99 -fstack-protector-all else # Error lines should not be tabulated because Makefile complains about it diff --git a/src/common/ascii.h b/src/common/ascii.h index 1c8e96e..fe7b692 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -246,6 +246,26 @@ $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 ------------------------- // #define ASCII_AMD_L \ "$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_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_riscv = { ASCII_RISCV, 63, 18, false, {C_FG_CYAN, C_FG_YELLOW}, {C_FG_CYAN, C_FG_YELLOW} }; // Long variants | ----------------------------------------------------------------------------------------------------| asciiL logo_amd_l = { ASCII_AMD_L, 62, 19, true, {C_BG_WHITE, C_BG_GREEN}, {C_FG_WHITE, C_FG_GREEN} }; diff --git a/src/common/cpu.h b/src/common/cpu.h index ed08fc7..011e1e6 100644 --- a/src/common/cpu.h +++ b/src/common/cpu.h @@ -20,6 +20,8 @@ enum { CPU_VENDOR_SAMSUNG, CPU_VENDOR_MARVELL, CPU_VENDOR_PHYTIUM, +// ARCH_RISCV + CPU_VENDOR_RISCV, // OTHERS CPU_VENDOR_UNKNOWN, CPU_VENDOR_INVALID @@ -149,7 +151,7 @@ struct cpuInfo { uint32_t midr; #endif -#ifdef ARCH_ARM +#if defined(ARCH_ARM) || defined(ARCH_RISCV) struct system_on_chip* soc; #endif diff --git a/src/common/printer.c b/src/common/printer.c index dd73a8c..da106b0 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -22,6 +22,8 @@ #include "../arm/soc.h" #elif ARCH_RISCV #include "../riscv/riscv.h" + #include "../riscv/uarch.h" + #include "../riscv/soc.h" #endif #ifdef _WIN32 @@ -366,6 +368,8 @@ void choose_ascii_art(struct ascii* art, struct color** cs, struct terminal* ter else { art->art = choose_ascii_art_aux(&logo_arm_l, &logo_arm, term, lf); } +#elif ARCH_RISCV + art->art = &logo_riscv; #endif // 2. Choose colors @@ -431,7 +435,7 @@ uint32_t longest_field_length(struct ascii* art, int la) { 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) { struct ascii_logo* logo = art->art; 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 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; } #endif diff --git a/src/riscv/riscv.c b/src/riscv/riscv.c index d4859a9..4a3a203 100644 --- a/src/riscv/riscv.c +++ b/src/riscv/riscv.c @@ -3,8 +3,35 @@ #include #include +#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) { - 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) { diff --git a/src/riscv/riscv.h b/src/riscv/riscv.h index 25dd7a5..367c56e 100644 --- a/src/riscv/riscv.h +++ b/src/riscv/riscv.h @@ -4,6 +4,7 @@ #include "../common/cpu.h" struct cpuInfo* get_cpu_info(void); +char* get_str_topology(struct cpuInfo* cpu, struct topology* topo); void print_debug(struct cpuInfo* cpu); #endif diff --git a/src/riscv/soc.c b/src/riscv/soc.c new file mode 100644 index 0000000..6f6f115 --- /dev/null +++ b/src/riscv/soc.c @@ -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"; +} diff --git a/src/riscv/soc.h b/src/riscv/soc.h new file mode 100644 index 0000000..9f55c1b --- /dev/null +++ b/src/riscv/soc.h @@ -0,0 +1,20 @@ +#ifndef __SOC__ +#define __SOC__ + +#include "../common/cpu.h" +#include + +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 diff --git a/src/riscv/uarch.c b/src/riscv/uarch.c index a7f579b..a9aa42e 100644 --- a/src/riscv/uarch.c +++ b/src/riscv/uarch.c @@ -1,11 +1,18 @@ #include +#include "uarch.h" +#include "../common/global.h" + struct uarch { //MICROARCH uarch; char* uarch_str; int32_t process; // measured in nanometers }; +char* get_str_uarch(struct cpuInfo* cpu) { + return "Unknown"; +} + void free_uarch_struct(struct uarch* arch) { } diff --git a/src/riscv/uarch.h b/src/riscv/uarch.h index 7b37e26..02548f9 100644 --- a/src/riscv/uarch.h +++ b/src/riscv/uarch.h @@ -6,6 +6,7 @@ struct uarch; +char* get_str_uarch(struct cpuInfo* cpu); void free_uarch_struct(struct uarch* arch); #endif