From a3c6f15658b9a274e21b5e530faf6c5fe39c0af9 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Mon, 2 Aug 2021 09:48:50 +0100 Subject: [PATCH 1/7] [v0.98][ARM] Fix compilation for ARM in macOS --- src/arm/midr.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/arm/midr.c b/src/arm/midr.c index 2a45e77..5dbf3c3 100644 --- a/src/arm/midr.c +++ b/src/arm/midr.c @@ -4,8 +4,11 @@ #include #include #include -#include -#include + +#ifdef __linux__ + #include + #include +#endif #include "../common/global.h" #include "udev.h" @@ -122,6 +125,7 @@ void init_cpu_info(struct cpuInfo* cpu) { cpu->next_cpu = NULL; } +#ifdef __linux__ // We assume all cpus share the same hardware // capabilities but I'm not sure it is always // true... @@ -167,6 +171,18 @@ struct features* get_features_info() { return feat; } +#elif defined __APPLE__ || __MACH__ +struct features* get_features_info() { + struct features* feat = malloc(sizeof(struct features)); + + bool *ptr = &(feat->AES); + for(uint32_t i = 0; i < sizeof(struct features)/sizeof(bool); i++, ptr++) { + *ptr = false; + } + + return feat; +} +#endif struct cpuInfo* get_cpu_info() { struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo)); From 4998cf3c82ad486f1374b7c454093d84916d5de8 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Mon, 2 Aug 2021 12:02:41 +0100 Subject: [PATCH 2/7] [v0.98][ARM] Compiles and does not segfault in ARM running macOS --- src/arm/midr.c | 111 ++++++++++++++++++++++++++++--------------------- src/arm/soc.c | 4 ++ 2 files changed, 67 insertions(+), 48 deletions(-) diff --git a/src/arm/midr.c b/src/arm/midr.c index 5dbf3c3..6c0b5f3 100644 --- a/src/arm/midr.c +++ b/src/arm/midr.c @@ -125,7 +125,6 @@ void init_cpu_info(struct cpuInfo* cpu) { cpu->next_cpu = NULL; } -#ifdef __linux__ // We assume all cpus share the same hardware // capabilities but I'm not sure it is always // true... @@ -137,57 +136,45 @@ struct features* get_features_info() { for(uint32_t i = 0; i < sizeof(struct features)/sizeof(bool); i++, ptr++) { *ptr = false; } + + #ifdef __linux__ + errno = 0; + long hwcaps = getauxval(AT_HWCAP); - errno = 0; - long hwcaps = getauxval(AT_HWCAP); - - if(errno == ENOENT) { - printWarn("Unable to retrieve AT_HWCAP using getauxval"); - } -#ifdef __aarch64__ - else { - feat->AES = hwcaps & HWCAP_AES; - feat->CRC32 = hwcaps & HWCAP_CRC32; - feat->SHA1 = hwcaps & HWCAP_SHA1; - feat->SHA2 = hwcaps & HWCAP_SHA2; - feat->NEON = hwcaps & HWCAP_ASIMD; - } -#else - else { - feat->NEON = hwcaps & HWCAP_NEON; - } - - hwcaps = getauxval(AT_HWCAP2); - if(errno == ENOENT) { - printWarn("Unable to retrieve AT_HWCAP2 using getauxval"); - } - else { - feat->AES = hwcaps & HWCAP2_AES; - feat->CRC32 = hwcaps & HWCAP2_CRC32; - feat->SHA1 = hwcaps & HWCAP2_SHA1; - feat->SHA2 = hwcaps & HWCAP2_SHA2; - } -#endif + if(errno == ENOENT) { + printWarn("Unable to retrieve AT_HWCAP using getauxval"); + } + #ifdef __aarch64__ + else { + feat->AES = hwcaps & HWCAP_AES; + feat->CRC32 = hwcaps & HWCAP_CRC32; + feat->SHA1 = hwcaps & HWCAP_SHA1; + feat->SHA2 = hwcaps & HWCAP_SHA2; + feat->NEON = hwcaps & HWCAP_ASIMD; + } + #else + else { + feat->NEON = hwcaps & HWCAP_NEON; + } + + hwcaps = getauxval(AT_HWCAP2); + if(errno == ENOENT) { + printWarn("Unable to retrieve AT_HWCAP2 using getauxval"); + } + else { + feat->AES = hwcaps & HWCAP2_AES; + feat->CRC32 = hwcaps & HWCAP2_CRC32; + feat->SHA1 = hwcaps & HWCAP2_SHA1; + feat->SHA2 = hwcaps & HWCAP2_SHA2; + } + #endif // ifdef __aarch64__ + #elif defined __APPLE__ || __MACH__ + #endif return feat; } -#elif defined __APPLE__ || __MACH__ -struct features* get_features_info() { - struct features* feat = malloc(sizeof(struct features)); - - bool *ptr = &(feat->AES); - for(uint32_t i = 0; i < sizeof(struct features)/sizeof(bool); i++, ptr++) { - *ptr = false; - } - - return feat; -} -#endif - -struct cpuInfo* get_cpu_info() { - struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo)); - init_cpu_info(cpu); +void get_cpu_info_linux(struct cpuInfo* cpu) { int ncores = get_ncores_from_cpuinfo(); bool success = false; int32_t* freq_array = malloc(sizeof(uint32_t) * ncores); @@ -236,7 +223,35 @@ struct cpuInfo* get_cpu_info() { cpu->num_cpus = sockets; cpu->hv = malloc(sizeof(struct hypervisor)); cpu->hv->present = false; - cpu->soc = get_soc(); + cpu->soc = get_soc(); +} + +void get_cpu_info_mach(struct cpuInfo* cpu) { + cpu->midr = 0; + cpu->arch = get_uarch_from_midr(cpu->midr, cpu); + + cpu->cach = get_cache_info(cpu); + cpu->feat = get_features_info(); + cpu->topo = malloc(sizeof(struct topology)); + cpu->freq = malloc(sizeof(struct frequency)); + cpu->freq->base = UNKNOWN_FREQ; + cpu->freq->max = 1000000000; + + cpu->num_cpus = 1; + cpu->hv = malloc(sizeof(struct hypervisor)); + cpu->hv->present = false; + cpu->soc = get_soc(); +} + +struct cpuInfo* get_cpu_info() { + struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo)); + init_cpu_info(cpu); + + #ifdef __linux__ + get_cpu_info_linux(cpu); + #elif defined __APPLE__ || __MACH__ + get_cpu_info_mach(cpu); + #endif return cpu; } diff --git a/src/arm/soc.c b/src/arm/soc.c index a8e8889..7d6dab9 100644 --- a/src/arm/soc.c +++ b/src/arm/soc.c @@ -587,6 +587,7 @@ struct system_on_chip* get_soc() { soc->soc_vendor = SOC_VENDOR_UNKNOWN; soc->process = UNKNOWN; + #ifdef __linux__ bool isRPi = is_raspberry_pi(); if(isRPi) { soc = guess_soc_raspbery_pi(soc); @@ -612,6 +613,9 @@ struct system_on_chip* get_soc() { printWarn("SoC detection failed using Android: Found '%s' string", soc->raw_name); #endif } + #elif defined __APPLE__ || __MACH__ + soc->raw_name = NULL; + #endif if(soc->raw_name == NULL) { soc->raw_name = malloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1)); From e350f1759feb18301f032e4a7da3c2b37d4d4193 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Mon, 2 Aug 2021 12:31:19 +0100 Subject: [PATCH 3/7] [v0.98][ARM] Add simple topology detection using sysctlbyname in macOS --- Makefile | 4 ++-- src/arm/midr.c | 6 ++++-- src/arm/sysctl.c | 25 +++++++++++++++++++++++++ src/arm/sysctl.h | 6 ++++++ 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 src/arm/sysctl.c create mode 100644 src/arm/sysctl.h diff --git a/Makefile b/Makefile index 463e90d..dfad59a 100644 --- a/Makefile +++ b/Makefile @@ -25,8 +25,8 @@ ifneq ($(OS),Windows_NT) else # Assume ARM SRC_DIR=src/arm/ - SOURCE += $(COMMON_SRC) $(SRC_DIR)midr.c $(SRC_DIR)uarch.c $(SRC_DIR)soc.c $(SRC_DIR)udev.c - HEADERS += $(COMMON_HDR) $(SRC_DIR)midr.h $(SRC_DIR)uarch.h $(SRC_DIR)soc.h $(SRC_DIR)udev.c $(SRC_DIR)socs.h + SOURCE += $(COMMON_SRC) $(SRC_DIR)midr.c $(SRC_DIR)uarch.c $(SRC_DIR)soc.c $(SRC_DIR)udev.c $(SRC_DIR)sysctl.c + HEADERS += $(COMMON_HDR) $(SRC_DIR)midr.h $(SRC_DIR)uarch.h $(SRC_DIR)soc.h $(SRC_DIR)udev.c $(SRC_DIR)socs.h $(SRC_DIR)sysctl.h CFLAGS += -DARCH_ARM -Wno-unused-parameter -std=c99 endif diff --git a/src/arm/midr.c b/src/arm/midr.c index 6c0b5f3..16a2e08 100644 --- a/src/arm/midr.c +++ b/src/arm/midr.c @@ -7,7 +7,9 @@ #ifdef __linux__ #include - #include + #include +#elif defined __APPLE__ || __MACH__ + #include "sysctl.h" #endif #include "../common/global.h" @@ -232,7 +234,7 @@ void get_cpu_info_mach(struct cpuInfo* cpu) { cpu->cach = get_cache_info(cpu); cpu->feat = get_features_info(); - cpu->topo = malloc(sizeof(struct topology)); + cpu->topo = get_topology_from_sysctl(); cpu->freq = malloc(sizeof(struct frequency)); cpu->freq->base = UNKNOWN_FREQ; cpu->freq->max = 1000000000; diff --git a/src/arm/sysctl.c b/src/arm/sysctl.c new file mode 100644 index 0000000..94f4a3f --- /dev/null +++ b/src/arm/sysctl.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include + +#include "../common/global.h" +#include "../common/cpu.h" + +struct topology* get_topology_from_sysctl() { + struct topology* t = malloc(sizeof(struct topology)); + size_t dummy; + + if(sysctlbyname("hw.physicalcpu_max", &t->total_cores, &dummy, NULL, 0) != 0) { + printWarn("sysctlbyname(\"hw.physicalcpu_max\") failed: %s\n", strerror(errno)); + t->total_cores = 1; + } + else if(t->total_cores <= 0) { + printWarn("sysctlbyname(\"hw.physicalcpu_max\") returned invalid value: %d\n", t->total_cores); + t->total_cores = 1; + } + + return t; +} + diff --git a/src/arm/sysctl.h b/src/arm/sysctl.h new file mode 100644 index 0000000..8d4bade --- /dev/null +++ b/src/arm/sysctl.h @@ -0,0 +1,6 @@ +#ifndef __SYSCTL__ +#define __SYSCTL__ + +struct topology* get_topology_from_sysctl(); + +#endif From d2dc2046debd962ba8b3bdb385c9e0643a1039cb Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Mon, 2 Aug 2021 15:56:24 +0100 Subject: [PATCH 4/7] [v0.98][ARM] Detect fire/icestorm CPUs and manually fill most of the fields --- src/arm/midr.c | 86 +++++++++++++++++++++++++++++++++++++----------- src/arm/sysctl.c | 22 ++++++------- src/arm/sysctl.h | 2 +- src/arm/uarch.c | 11 ++++++- src/common/cpu.h | 1 + 5 files changed, 90 insertions(+), 32 deletions(-) diff --git a/src/arm/midr.c b/src/arm/midr.c index 16a2e08..e62fb0d 100644 --- a/src/arm/midr.c +++ b/src/arm/midr.c @@ -10,6 +10,12 @@ #include #elif defined __APPLE__ || __MACH__ #include "sysctl.h" + #ifndef CPUFAMILY_ARM_FIRESTORM_ICESTORM + #define CPUFAMILY_ARM_FIRESTORM_ICESTORM 0x1B588BB3 + // From arch/arm64/include/asm/cputype.h + #define MIDR_APPLE_M1_ICESTORM 0x610F0220 + #define MIDR_APPLE_M1_FIRESTORM 0x610F0230 + #endif #endif #include "../common/global.h" @@ -171,12 +177,18 @@ struct features* get_features_info() { } #endif // ifdef __aarch64__ #elif defined __APPLE__ || __MACH__ + // Must be M1 + feat->AES = true; + feat->CRC32 = true; + feat->SHA1 = true; + feat->SHA2 = true; + feat->NEON = true; #endif return feat; } -void get_cpu_info_linux(struct cpuInfo* cpu) { +struct cpuInfo* get_cpu_info_linux(struct cpuInfo* cpu) { int ncores = get_ncores_from_cpuinfo(); bool success = false; int32_t* freq_array = malloc(sizeof(uint32_t) * ncores); @@ -225,24 +237,62 @@ void get_cpu_info_linux(struct cpuInfo* cpu) { cpu->num_cpus = sockets; cpu->hv = malloc(sizeof(struct hypervisor)); cpu->hv->present = false; - cpu->soc = get_soc(); + cpu->soc = get_soc(); + + return cpu; } -void get_cpu_info_mach(struct cpuInfo* cpu) { - cpu->midr = 0; - cpu->arch = get_uarch_from_midr(cpu->midr, cpu); +void fill_cpu_info_firestorm_icestorm(struct cpuInfo* cpu) { + // 1. Fill ICESTORM + struct cpuInfo* ice = cpu; - cpu->cach = get_cache_info(cpu); - cpu->feat = get_features_info(); - cpu->topo = get_topology_from_sysctl(); - cpu->freq = malloc(sizeof(struct frequency)); - cpu->freq->base = UNKNOWN_FREQ; - cpu->freq->max = 1000000000; + ice->midr = MIDR_APPLE_M1_ICESTORM; + ice->arch = get_uarch_from_midr(ice->midr, ice); + ice->cach = get_cache_info(ice); + ice->feat = get_features_info(); + ice->topo = malloc(sizeof(struct topology)); + ice->topo->cach = ice->cach; + ice->topo->total_cores = 4; + ice->freq = malloc(sizeof(struct frequency)); + ice->freq->base = UNKNOWN_FREQ; + ice->freq->max = 2064; + ice->hv = malloc(sizeof(struct hypervisor)); + ice->hv->present = false; + ice->next_cpu = malloc(sizeof(struct cpuInfo)); - cpu->num_cpus = 1; - cpu->hv = malloc(sizeof(struct hypervisor)); - cpu->hv->present = false; - cpu->soc = get_soc(); + // 2. Fill FIRESTORM + struct cpuInfo* fire = ice->next_cpu; + fire->midr = MIDR_APPLE_M1_FIRESTORM; + fire->arch = get_uarch_from_midr(fire->midr, fire); + fire->cach = get_cache_info(fire); + fire->feat = get_features_info(); + fire->topo = malloc(sizeof(struct topology)); + fire->topo->cach = fire->cach; + fire->topo->total_cores = 4; + fire->freq = malloc(sizeof(struct frequency)); + fire->freq->base = UNKNOWN_FREQ; + fire->freq->max = 3200; + fire->hv = malloc(sizeof(struct hypervisor)); + fire->hv->present = false; + fire->next_cpu = NULL; +} + +struct cpuInfo* get_cpu_info_mach(struct cpuInfo* cpu) { + uint32_t cpu_family = get_sys_info_by_name("hw.cpufamily"); + + // Manually fill the cpuInfo assuming that the CPU + // is a ARM_FIRESTORM_ICESTORM (Apple M1) + if(cpu_family == CPUFAMILY_ARM_FIRESTORM_ICESTORM) { + cpu->num_cpus = 2; + cpu->soc = get_soc(); + fill_cpu_info_firestorm_icestorm(cpu); + } + else { + printBug("Found invalid cpu_family: 0x%.8X", cpu_family); + return NULL; + } + + return cpu; } struct cpuInfo* get_cpu_info() { @@ -250,12 +300,10 @@ struct cpuInfo* get_cpu_info() { init_cpu_info(cpu); #ifdef __linux__ - get_cpu_info_linux(cpu); + return get_cpu_info_linux(cpu); #elif defined __APPLE__ || __MACH__ - get_cpu_info_mach(cpu); + return get_cpu_info_mach(cpu); #endif - - return cpu; } char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket) { diff --git a/src/arm/sysctl.c b/src/arm/sysctl.c index 94f4a3f..8ee401e 100644 --- a/src/arm/sysctl.c +++ b/src/arm/sysctl.c @@ -7,19 +7,19 @@ #include "../common/global.h" #include "../common/cpu.h" -struct topology* get_topology_from_sysctl() { - struct topology* t = malloc(sizeof(struct topology)); - size_t dummy; +uint32_t get_sys_info_by_name(char* name) { + size_t size = 0; + uint32_t ret = 0; - if(sysctlbyname("hw.physicalcpu_max", &t->total_cores, &dummy, NULL, 0) != 0) { - printWarn("sysctlbyname(\"hw.physicalcpu_max\") failed: %s\n", strerror(errno)); - t->total_cores = 1; + if (sysctlbyname(name, NULL, &size, NULL, 0) != 0) { + printWarn("sysctlbyname(\"%s\") failed: %s", name, strerror(errno)); } - else if(t->total_cores <= 0) { - printWarn("sysctlbyname(\"hw.physicalcpu_max\") returned invalid value: %d\n", t->total_cores); - t->total_cores = 1; + else if (size == sizeof(uint32_t)) { + sysctlbyname(name, &ret, &size, NULL, 0); + } + else { + printWarn("sysctl does not support non-integer lookup for (\"%s\")", name); } - return t; + return ret; } - diff --git a/src/arm/sysctl.h b/src/arm/sysctl.h index 8d4bade..1140aec 100644 --- a/src/arm/sysctl.h +++ b/src/arm/sysctl.h @@ -1,6 +1,6 @@ #ifndef __SYSCTL__ #define __SYSCTL__ -struct topology* get_topology_from_sysctl(); +uint32_t get_sys_info_by_name(char* name); #endif diff --git a/src/arm/uarch.c b/src/arm/uarch.c index 5082137..59b043d 100644 --- a/src/arm/uarch.c +++ b/src/arm/uarch.c @@ -34,6 +34,7 @@ enum { ISA_ARMv8_1_A, ISA_ARMv8_2_A, ISA_ARMv8_3_A, + ISA_ARMv8_4_A, }; enum { @@ -93,6 +94,8 @@ enum { UARCH_TEMPEST, // Apple A12 processor (big cores). UARCH_LIGHTNING, // Apple A13 processor (big cores). UARCH_THUNDER, // Apple A13 processor (little cores). + UARCH_ICESTORM, // Apple M1 processor (little cores). + UARCH_FIRESTORM, // Apple M1 processor (big cores). // CAVIUM UARCH_THUNDERX, // Cavium ThunderX UARCH_THUNDERX2, // Cavium ThunderX2 (originally Broadcom Vulkan). @@ -150,6 +153,8 @@ static const ISA isas_uarch[] = { [UARCH_EXYNOS_M3] = ISA_ARMv8_A, [UARCH_EXYNOS_M4] = ISA_ARMv8_2_A, [UARCH_EXYNOS_M5] = ISA_ARMv8_2_A, + [UARCH_ICESTORM] = ISA_ARMv8_4_A, + [UARCH_FIRESTORM] = ISA_ARMv8_4_A, [UARCH_PJ4] = ISA_ARMv7_A, }; @@ -164,6 +169,7 @@ static char* isas_string[] = { [ISA_ARMv8_1_A] = "ARMv8.1", [ISA_ARMv8_2_A] = "ARMv8.2", [ISA_ARMv8_3_A] = "ARMv8.3", + [ISA_ARMv8_4_A] = "ARMv8.4" }; #define UARCH_START if (false) {} @@ -281,7 +287,10 @@ struct uarch* get_uarch_from_midr(uint32_t midr, struct cpuInfo* cpu) { CHECK_UARCH(arch, cpu, 'S', 0x002, 1, NA, "Exynos M3", UARCH_EXYNOS_M3, CPU_VENDOR_SAMSUNG) // Exynos 9810 CHECK_UARCH(arch, cpu, 'S', 0x003, 1, NA, "Exynos M4", UARCH_EXYNOS_M4, CPU_VENDOR_SAMSUNG) // Exynos 9820 CHECK_UARCH(arch, cpu, 'S', 0x004, 1, NA, "Exynos M5", UARCH_EXYNOS_M5, CPU_VENDOR_SAMSUNG) // Exynos 9820 (this one looks wrong at uarch.c ...) - + + CHECK_UARCH(arch, cpu, 'a', 0x022, NA, NA, "Icestorm", UARCH_ICESTORM, CPU_VENDOR_APPLE) + CHECK_UARCH(arch, cpu, 'a', 0x023, NA, NA, "Firestorm", UARCH_FIRESTORM, CPU_VENDOR_APPLE) + CHECK_UARCH(arch, cpu, 'V', 0x581, NA, NA, "PJ4", UARCH_PJ4, CPU_VENDOR_MARVELL) CHECK_UARCH(arch, cpu, 'V', 0x584, NA, NA, "PJ4B-MP", UARCH_PJ4, CPU_VENDOR_MARVELL) diff --git a/src/common/cpu.h b/src/common/cpu.h index bd61f8c..f422202 100644 --- a/src/common/cpu.h +++ b/src/common/cpu.h @@ -10,6 +10,7 @@ enum { CPU_VENDOR_AMD, // ARCH_ARM CPU_VENDOR_ARM, + CPU_VENDOR_APPLE, CPU_VENDOR_BROADCOM, CPU_VENDOR_CAVIUM, CPU_VENDOR_NVIDIA, From 843da5cf7057c2283fc01fc778137d4602ae3f80 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Mon, 2 Aug 2021 21:11:53 +0100 Subject: [PATCH 5/7] [v0.98][ARM] Add M1 SoC detection and apple logo --- src/arm/soc.c | 3 ++- src/arm/soc.h | 3 ++- src/arm/socs.h | 3 +++ src/common/ascii.h | 22 ++++++++++++++++++++++ src/common/printer.c | 9 +++++++++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/arm/soc.c b/src/arm/soc.c index 7d6dab9..d33f99e 100644 --- a/src/arm/soc.c +++ b/src/arm/soc.c @@ -18,6 +18,7 @@ static char* soc_trademark_string[] = { [SOC_VENDOR_EXYNOS] = "Exynos ", [SOC_VENDOR_KIRIN] = "Kirin ", [SOC_VENDOR_BROADCOM] = "Broadcom BCM", + [SOC_VENDOR_APPLE] = "Apple " }; static char* soc_rpi_string[] = { @@ -614,7 +615,7 @@ struct system_on_chip* get_soc() { #endif } #elif defined __APPLE__ || __MACH__ - soc->raw_name = NULL; + fill_soc(soc, "M1", SOC_APPLE_M1, 5); #endif if(soc->raw_name == NULL) { diff --git a/src/arm/soc.h b/src/arm/soc.h index 1dc10b3..90df32c 100644 --- a/src/arm/soc.h +++ b/src/arm/soc.h @@ -12,7 +12,8 @@ enum { SOC_VENDOR_MEDIATEK, SOC_VENDOR_EXYNOS, SOC_VENDOR_KIRIN, - SOC_VENDOR_BROADCOM + SOC_VENDOR_BROADCOM, + SOC_VENDOR_APPLE }; struct system_on_chip { diff --git a/src/arm/socs.h b/src/arm/socs.h index c028d11..66466b2 100644 --- a/src/arm/socs.h +++ b/src/arm/socs.h @@ -250,6 +250,8 @@ enum { SOC_SNAPD_SM8250, SOC_SNAPD_SM8250_AB, SOC_SNAPD_SM8350, + // APPLE + SOC_APPLE_M1 }; inline static VENDOR get_soc_vendor_from_soc(SOC soc) { @@ -258,6 +260,7 @@ inline static VENDOR get_soc_vendor_from_soc(SOC soc) { else if(soc >= SOC_EXYNOS_3475 && soc <= SOC_EXYNOS_880) return SOC_VENDOR_EXYNOS; else if(soc >= SOC_MTK_MT6889 && soc <= SOC_MTK_MT8783) return SOC_VENDOR_MEDIATEK; else if(soc >= SOC_SNAPD_QSD8650 && soc <= SOC_SNAPD_SM8350) return SOC_VENDOR_SNAPDRAGON; + else if(soc >= SOC_APPLE_M1 && soc <= SOC_APPLE_M1) return SOC_VENDOR_APPLE; return SOC_VENDOR_UNKNOWN; } diff --git a/src/common/ascii.h b/src/common/ascii.h index bd77ac9..c57c1f7 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -150,6 +150,27 @@ ######################## \ ############### \ " + +#define APPLE_ASCII \ +" ;' \ + .clod. \ + cdddd; \ + cdddo \ + ddddddd:` dddddddd: \ + ,clooddoolcc:clloddddoll: \ + 'lddddddddddddddddddddddddd' \ + ;ddddddddddddddddddddddddd' \ + .ddddddddddddddddddddddddd, \ + .ddddddddddddddddddddddddd. \ + .ddddddddddddddddddddddddd' \ + dddddddddddddddddddddddddo. \ + ,dddddddddddddddddddddddddoc. \ + ldddddddddddddddddddddddddddl \ + ldddddddddddddddddddddddddd \ + 'dddddddddddddddddddddddc \ + ldddddddddddddddddddd \ + .ddd ldd' \ + " #define ARM_ASCII \ " \ @@ -225,6 +246,7 @@ static const char* ASCII_ARRAY [] = { EXYNOS_ASCII, KIRIN_ASCII, BROADCOM_ASCII, + APPLE_ASCII, IBM_ASCII, UNKNOWN_ASCII }; diff --git a/src/common/printer.c b/src/common/printer.c index 76f5d97..7453f89 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -225,6 +225,13 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct colors* cs) { COL_FANCY_4 = COLOR_FG_RED; art->ascii_chars[0] = '@'; } + else if(art->vendor == SOC_VENDOR_APPLE) { + COL_FANCY_1 = COLOR_BG_BLACK; + COL_FANCY_2 = COLOR_BG_BLACK; + COL_FANCY_3 = COLOR_FG_BLACK; + COL_FANCY_4 = COLOR_FG_BLACK; + art->ascii_chars[0] = '@'; + } else { COL_FANCY_1 = COLOR_BG_CYAN; COL_FANCY_2 = COLOR_BG_CYAN; @@ -341,6 +348,8 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct colors* cs) { strcpy(tmp, KIRIN_ASCII); else if(art->vendor == SOC_VENDOR_BROADCOM) strcpy(tmp, BROADCOM_ASCII); + else if(art->vendor == SOC_VENDOR_APPLE) + strcpy(tmp, APPLE_ASCII); else strcpy(tmp, ARM_ASCII); #endif From 4b0ea3053f24d40488d9912cdcd39a02d24a9f84 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Wed, 4 Aug 2021 10:06:26 +0200 Subject: [PATCH 6/7] [v0.98] Add command used to generate apple logo --- src/common/ascii.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index c57c1f7..ad38105 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -150,7 +150,8 @@ ######################## \ ############### \ " - + +// jp2a --height=19 apple.jpg #define APPLE_ASCII \ " ;' \ .clod. \ From e2f7ec0765019fd9e900d6c0047e3c4a6b2e2d14 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Thu, 12 Aug 2021 12:44:37 +0100 Subject: [PATCH 7/7] [v0.98][ARM] Apply bug fixes already in master --- src/arm/midr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/arm/midr.c b/src/arm/midr.c index e62fb0d..5e0d780 100644 --- a/src/arm/midr.c +++ b/src/arm/midr.c @@ -80,7 +80,7 @@ struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach, uint int cores_in_socket = 0; while(socket_idx + 1 > sockets_seen) { - if(midr_array[first_core_idx] == midr_array[currrent_core_idx] && currrent_core_idx < ncores) { + if(currrent_core_idx < ncores && midr_array[first_core_idx] == midr_array[currrent_core_idx]) { currrent_core_idx++; cores_in_socket++; } @@ -349,9 +349,10 @@ char* get_str_peak_performance(struct cpuInfo* cpu) { char* get_str_features(struct cpuInfo* cpu) { struct features* feat = cpu->feat; - char* string = malloc(sizeof(char) * 25); + uint32_t max_len = strlen("NEON,SHA1,SHA2,AES,CRC32,") + 1; uint32_t len = 0; - + char* string = calloc(max_len, sizeof(char)); + if(feat->NEON) { strcat(string, "NEON,"); len += 5;