From 715c054de57c8925982275855c7877bb44e4bad6 Mon Sep 17 00:00:00 2001 From: jSTE0 <98854293+jSTE0@users.noreply.github.com> Date: Wed, 9 Mar 2022 20:27:12 +0000 Subject: [PATCH] Improve CPU architecture and model name identification for Miyoo (#13704) * features_cpu: Return model name on non-x86 Linux platforms Extract model name from /proc/cpuinfo. * platform/unix: Rework identification of classic Arm CPUs Identify pre-ARMv7 CPUs based on the machine hardware name starting with "arm" instead of matching every individual variant. This will then include the ARM926EJ-S which has armv5tejl as its machine hardware name. --- frontend/drivers/platform_unix.c | 7 +----- libretro-common/features/features_cpu.c | 33 +++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/frontend/drivers/platform_unix.c b/frontend/drivers/platform_unix.c index b3b5dad173..86b9aa824b 100644 --- a/frontend/drivers/platform_unix.c +++ b/frontend/drivers/platform_unix.c @@ -1274,12 +1274,7 @@ static enum frontend_architecture frontend_unix_get_arch(void) string_is_equal(val, "armv7b") ) return FRONTEND_ARCH_ARMV7; - else if ( - string_is_equal(val, "armv6l") || - string_is_equal(val, "armv6b") || - string_is_equal(val, "armv5tel") || - string_is_equal(val, "arm") - ) + else if (string_starts_with(val, "arm")) return FRONTEND_ARCH_ARM; else if (string_is_equal(val, "x86_64")) return FRONTEND_ARCH_X86_64; diff --git a/libretro-common/features/features_cpu.c b/libretro-common/features/features_cpu.c index 63f10163c3..b5dec4fa1d 100644 --- a/libretro-common/features/features_cpu.c +++ b/libretro-common/features/features_cpu.c @@ -46,8 +46,8 @@ #if defined(_XBOX360) #include #elif !defined(__MACH__) && (defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__) || defined(__PPC64__) || defined(__powerpc64__)) -#ifndef _PPU_INTRINSICS_H -#include +#ifndef _PPU_INTRINSICS_H +#include #endif #elif defined(_POSIX_MONOTONIC_CLOCK) || defined(ANDROID) || defined(__QNX__) || defined(DJGPP) /* POSIX_MONOTONIC_CLOCK is not being defined in Android headers despite support being present. */ @@ -871,6 +871,35 @@ end: size_t len_size = len; sysctlbyname("machdep.cpu.brand_string", name, &len_size, NULL, 0); } +#elif defined(__linux__) + if (!name) + return; + { + char *model_name, line[128]; + RFILE *fp = filestream_open("/proc/cpuinfo", + RETRO_VFS_FILE_ACCESS_READ, + RETRO_VFS_FILE_ACCESS_HINT_NONE); + + if (!fp) + return; + + while (filestream_gets(fp, line, sizeof(line))) + { + if (strncmp(line, "model name", 10)) + continue; + + if ((model_name = strstr(line + 10, ": "))) + { + model_name += 2; + strncpy(name, model_name, len); + name[len - 1] = '\0'; + } + + break; + } + + filestream_close(fp); + } #else if (!name) return;