From b999b9cb996be487e15acb196245d623db024b4a Mon Sep 17 00:00:00 2001 From: Pierce Andjelkovic Date: Fri, 25 Jun 2021 04:56:43 +1000 Subject: [PATCH 01/12] Update CMakeLists.txt --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec5aa331f6..d1d3704429 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,8 @@ if(CMAKE_SYSTEM_PROCESSOR) set(X86_DEVICE ON) elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^mips") set(MIPS_DEVICE ON) + elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^riscv64") + set(RISCV64_DEVICE ON) else() message("Unknown CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") endif() @@ -113,6 +115,7 @@ endif() option(ARMV7 "Set to ON if targeting an ARMv7 processor" ${ARMV7_DEVICE}) option(ARM "Set to ON if targeting an ARM processor" ${ARM_DEVICE}) option(MIPS "Set to ON if targeting a MIPS processor" ${MIPS_DEVICE}) +option(RISCV64 "Set to ON if targeting a RISCV64 processor" ${RISCV64_DEVICE}) option(X86 "Set to ON if targeting an X86 processor" ${X86_DEVICE}) option(X86_64 "Set to ON if targeting an X86_64 processor" ${X86_64_DEVICE}) # :: Environments @@ -248,6 +251,9 @@ endif() if(MIPS) message("Generating for MIPS, ${CMAKE_BUILD_TYPE}") endif() +if(RISCV64) + message("Generating for RISCV64, ${CMAKE_BUILD_TYPE}") +endif() if(X86) message("Generating for x86, ${CMAKE_BUILD_TYPE}") endif() @@ -712,6 +718,8 @@ if(USE_FFMPEG) set(PLATFORM_ARCH "linux/arm") elseif(MIPS) set(PLATFORM_ARCH "linux/mips32") + elseif(RISCV64) + set(PLATFORM_ARCH "linux/riscv64") elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) set(PLATFORM_ARCH "linux/x86_64") elseif(X86) From 549ad024e40b964bdac02b684d838252e907eb2a Mon Sep 17 00:00:00 2001 From: Pierce Andjelkovic Date: Tue, 29 Jun 2021 21:46:17 +1000 Subject: [PATCH 02/12] Include FakeJit in RISC-V build --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d1d3704429..1dc167efda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -429,6 +429,12 @@ set(CommonMIPS ) source_group(MIPS FILES ${CommonMIPS}) +set(CommonRISCV64 + Core/MIPS/fake/FakeJit.cpp + Core/MIPS/fake/FakeJit.h +) +source_group(RISCV64 FILES ${CommonRISCV64}) + if(WIN32) set(CommonD3D Common/GPU/D3D9/D3D9ShaderCompiler.cpp @@ -448,6 +454,7 @@ add_library(Common STATIC ${CommonARM} ${CommonARM64} ${CommonMIPS} + ${CommonRISCV64} ${CommonD3D} Common/Serialize/Serializer.cpp Common/Serialize/Serializer.h From 15cdea8650f75928942d43ea1a3a716a0fb85453 Mon Sep 17 00:00:00 2001 From: Pierce Andjelkovic Date: Tue, 29 Jun 2021 22:01:30 +1000 Subject: [PATCH 03/12] Swap submodule repo to fork --- .gitmodules | 2 +- ffmpeg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 773fbeb290..485479f633 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,7 +6,7 @@ url = https://github.com/hrydgard/ppsspp-lang.git [submodule "ffmpeg"] path = ffmpeg - url = https://github.com/hrydgard/ppsspp-ffmpeg.git + url = https://github.com/archanox/ppsspp-ffmpeg.git [submodule "dx9sdk"] path = dx9sdk url = https://github.com/hrydgard/minidx9.git diff --git a/ffmpeg b/ffmpeg index 0b28335ace..2455c82d39 160000 --- a/ffmpeg +++ b/ffmpeg @@ -1 +1 @@ -Subproject commit 0b28335acea4f429ae798c5e75232e54881bf164 +Subproject commit 2455c82d394dddcef187b6413d8b0a617e8e166a From 77e578bbb88fa7523eea0387c791d423d825bfe6 Mon Sep 17 00:00:00 2001 From: Pierce Andjelkovic Date: Thu, 1 Jul 2021 12:01:18 +1000 Subject: [PATCH 04/12] Re-target to merged upstream changes --- .gitmodules | 2 +- ffmpeg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 485479f633..773fbeb290 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,7 +6,7 @@ url = https://github.com/hrydgard/ppsspp-lang.git [submodule "ffmpeg"] path = ffmpeg - url = https://github.com/archanox/ppsspp-ffmpeg.git + url = https://github.com/hrydgard/ppsspp-ffmpeg.git [submodule "dx9sdk"] path = dx9sdk url = https://github.com/hrydgard/minidx9.git diff --git a/ffmpeg b/ffmpeg index 2455c82d39..a5baf97df4 160000 --- a/ffmpeg +++ b/ffmpeg @@ -1 +1 @@ -Subproject commit 2455c82d394dddcef187b6413d8b0a617e8e166a +Subproject commit a5baf97df4579b4614cd5e643241c7acfc36b0c4 From d9a3741fcbb51fbd9f5ff82b70ed93314c798ab1 Mon Sep 17 00:00:00 2001 From: Pierce Andjelkovic Date: Wed, 28 Jul 2021 21:58:56 +1000 Subject: [PATCH 05/12] RISC-V CPU detect --- CMakeLists.txt | 1 + Common/Common.vcxproj | 1 + Common/Common.vcxproj.filters | 1 + Common/FakeCPUDetect.cpp | 2 + Common/RiscVCPUDetect.cpp | 121 ++++++++++++++++++++++++++++++++++ UI/DevScreens.cpp | 2 + libretro/Makefile.common | 1 + ppsspp_config.h | 5 ++ 8 files changed, 134 insertions(+) create mode 100644 Common/RiscVCPUDetect.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ef5e97ed41..07ba91f5c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -430,6 +430,7 @@ set(CommonMIPS source_group(MIPS FILES ${CommonMIPS}) set(CommonRISCV64 + Common/RiscVCPUDetect.cpp Core/MIPS/fake/FakeJit.cpp Core/MIPS/fake/FakeJit.h ) diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj index 5bc0e2ab83..ef63de1054 100644 --- a/Common/Common.vcxproj +++ b/Common/Common.vcxproj @@ -898,6 +898,7 @@ + diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters index 58ca55dbbf..ddfbebd6e3 100644 --- a/Common/Common.vcxproj.filters +++ b/Common/Common.vcxproj.filters @@ -777,6 +777,7 @@ Thread + diff --git a/Common/FakeCPUDetect.cpp b/Common/FakeCPUDetect.cpp index 9b1469c21c..3bdaeabbcd 100644 --- a/Common/FakeCPUDetect.cpp +++ b/Common/FakeCPUDetect.cpp @@ -22,6 +22,8 @@ #define REAL_CPUDETECT_AVAIL 1 #elif PPSSPP_ARCH(MIPS) || PPSSPP_ARCH(MIPS64) #define REAL_CPUDETECT_AVAIL 1 +#elif PPSSPP_ARCH(RISCV64) +#define REAL_CPUDETECT_AVAIL 1 #endif #ifndef REAL_CPUDETECT_AVAIL diff --git a/Common/RiscVCPUDetect.cpp b/Common/RiscVCPUDetect.cpp new file mode 100644 index 0000000000..28be934fd2 --- /dev/null +++ b/Common/RiscVCPUDetect.cpp @@ -0,0 +1,121 @@ +// Copyright (C) 2003 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#include "ppsspp_config.h" +#if PPSSPP_ARCH(RISCV64) + +#include "Common/Common.h" +#include "Common/CPUDetect.h" +#include "Common/StringUtils.h" +#include "Common/File/FileUtil.h" +#include "Common/Data/Encoding/Utf8.h" +#include +#include + +// Only Linux platforms have /proc/cpuinfo +#if defined(__linux__) +const char procfile[] = "/proc/cpuinfo"; +// https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-system-cpu +const char syscpupresentfile[] = "/sys/devices/system/cpu/present"; + +std::string GetCPUString() { + std::string cpu_string = "Unknown"; + + return cpu_string; +} + +int GetCoreCount() +{ + std::string line, marker = "processor\t: "; + int cores = 1; + + std::string presentData; + bool presentSuccess = File::ReadFileToString(true, syscpupresentfile, presentData); + std::istringstream presentFile(presentData); + + if (presentSuccess) { + int low, high, found; + std::getline(presentFile, line); + found = sscanf(line.c_str(), "%d-%d", &low, &high); + if (found == 1) + return 1; + if (found == 2) + return high - low + 1; + } + + std::string procdata; + if (!File::ReadFileToString(true, procfile, procdata)) + return 1; + std::istringstream file(procdata); + + while (std::getline(file, line)) + { + if (line.find(marker) != std::string::npos) + ++cores; + } + + return cores; +} +#endif + +CPUInfo cpu_info; + +CPUInfo::CPUInfo() { + Detect(); +} + +// Detects the various cpu features +void CPUInfo::Detect() +{ + // Set some defaults here + HTT = false; +#if PPSSPP_ARCH(RISCV64) + OS64bit = true; + CPU64bit = true; + Mode64bit = true; +#else + OS64bit = false; + CPU64bit = false; + Mode64bit = false; +#endif + vendor = VENDOR_OTHER; + logical_cpu_count = 1; + + // Get the information about the CPU +#if !defined(__linux__) + num_cores = 1; +#else // __linux__ + strncpy(cpu_string, GetCPUString().c_str(), sizeof(cpu_string)); + unsigned short CPUPart = GetCPUPart(); + num_cores = GetCoreCount(); +#endif +} + +// Turn the cpu info into a string we can show +std::string CPUInfo::Summarize() +{ + std::string sum; + if (num_cores == 1) + sum = StringFromFormat("%s, %i core", cpu_string, num_cores); + else + sum = StringFromFormat("%s, %i cores", cpu_string, num_cores); + if (CPU64bit) sum += ", 64-bit"; + + return sum; +} + +#endif // PPSSPP_ARCH(RISCV64) diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 735ae47928..89fceb30bd 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -423,6 +423,8 @@ const char *GetCompilerABI() { return "x86"; #elif PPSSPP_ARCH(AMD64) return "x86-64"; +#elif PPSSPP_ARCH(RISCV64) + return "rv64"; #else return "other"; #endif diff --git a/libretro/Makefile.common b/libretro/Makefile.common index 77fd240274..a80ff92847 100644 --- a/libretro/Makefile.common +++ b/libretro/Makefile.common @@ -300,6 +300,7 @@ SOURCES_CXX += \ $(COMMONDIR)/OSVersion.cpp \ $(COMMONDIR)/MemoryUtil.cpp \ $(COMMONDIR)/MipsCPUDetect.cpp \ + $(COMMONDIR)/RiscVCPUDetect.cpp \ $(COMMONDIR)/LogReporting.cpp \ $(COMMONDIR)/SysError.cpp \ $(COMMONDIR)/StringUtils.cpp \ diff --git a/ppsspp_config.h b/ppsspp_config.h index 5725778144..91f0ffb854 100644 --- a/ppsspp_config.h +++ b/ppsspp_config.h @@ -64,6 +64,11 @@ #define PPSSPP_ARCH_32BIT 1 #endif +#if defined(__riscv64__) + #define PPSSPP_ARCH_RISCV64 1 + #define PPSSPP_ARCH_64BIT 1 +#endif + // PLATFORM defines #if defined(_WIN32) From d452b0c1f7f1a747563635fc54da9b67ca097725 Mon Sep 17 00:00:00 2001 From: Pierce Andjelkovic Date: Thu, 29 Jul 2021 03:26:18 +1000 Subject: [PATCH 06/12] No CPU part for RISC-V --- Common/RiscVCPUDetect.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Common/RiscVCPUDetect.cpp b/Common/RiscVCPUDetect.cpp index 28be934fd2..d9f446acb2 100644 --- a/Common/RiscVCPUDetect.cpp +++ b/Common/RiscVCPUDetect.cpp @@ -100,7 +100,6 @@ void CPUInfo::Detect() num_cores = 1; #else // __linux__ strncpy(cpu_string, GetCPUString().c_str(), sizeof(cpu_string)); - unsigned short CPUPart = GetCPUPart(); num_cores = GetCoreCount(); #endif } From 8cb4fb83a4c7c7de03ceaee447031ea8844b11eb Mon Sep 17 00:00:00 2001 From: Pierce Andjelkovic Date: Thu, 29 Jul 2021 07:19:44 +1000 Subject: [PATCH 07/12] temporary riscv define fix --- ppsspp_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ppsspp_config.h b/ppsspp_config.h index 91f0ffb854..fcb3f06038 100644 --- a/ppsspp_config.h +++ b/ppsspp_config.h @@ -64,7 +64,7 @@ #define PPSSPP_ARCH_32BIT 1 #endif -#if defined(__riscv64__) +#if defined(__riscv) #define PPSSPP_ARCH_RISCV64 1 #define PPSSPP_ARCH_64BIT 1 #endif From c48888c5e50af48ecc0674d0201116d781d8d8d2 Mon Sep 17 00:00:00 2001 From: Pierce Andjelkovic Date: Thu, 29 Jul 2021 07:28:29 +1000 Subject: [PATCH 08/12] Add in bit length check --- ppsspp_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ppsspp_config.h b/ppsspp_config.h index fcb3f06038..0c4e2b9c1d 100644 --- a/ppsspp_config.h +++ b/ppsspp_config.h @@ -64,7 +64,7 @@ #define PPSSPP_ARCH_32BIT 1 #endif -#if defined(__riscv) +#if defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64 #define PPSSPP_ARCH_RISCV64 1 #define PPSSPP_ARCH_64BIT 1 #endif From 0d0e2c44e0d218d17a0f0676ede9e144abf459ee Mon Sep 17 00:00:00 2001 From: Pierce Andjelkovic Date: Thu, 29 Jul 2021 07:47:09 +1000 Subject: [PATCH 09/12] Fix copied mips bugs --- Common/RiscVCPUDetect.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Common/RiscVCPUDetect.cpp b/Common/RiscVCPUDetect.cpp index d9f446acb2..c433136c84 100644 --- a/Common/RiscVCPUDetect.cpp +++ b/Common/RiscVCPUDetect.cpp @@ -44,7 +44,7 @@ int GetCoreCount() int cores = 1; std::string presentData; - bool presentSuccess = File::ReadFileToString(true, syscpupresentfile, presentData); + bool presentSuccess = File::ReadFileToString(true, Path(syscpupresentfile), presentData); std::istringstream presentFile(presentData); if (presentSuccess) { @@ -58,7 +58,7 @@ int GetCoreCount() } std::string procdata; - if (!File::ReadFileToString(true, procfile, procdata)) + if (!File::ReadFileToString(true, Path(procfile), procdata)) return 1; std::istringstream file(procdata); From bd8759853bf8496abb113a5b17d0c972fce0250b Mon Sep 17 00:00:00 2001 From: Pierce Andjelkovic Date: Sat, 31 Jul 2021 01:50:48 +1000 Subject: [PATCH 10/12] Fix ABI --- Common/RiscVCPUDetect.cpp | 4 ++-- UI/DevScreens.cpp | 12 +++++++++++- ppsspp_config.h | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Common/RiscVCPUDetect.cpp b/Common/RiscVCPUDetect.cpp index c433136c84..4e3c10d7aa 100644 --- a/Common/RiscVCPUDetect.cpp +++ b/Common/RiscVCPUDetect.cpp @@ -33,8 +33,8 @@ const char procfile[] = "/proc/cpuinfo"; const char syscpupresentfile[] = "/sys/devices/system/cpu/present"; std::string GetCPUString() { - std::string cpu_string = "Unknown"; - + std::string cpu_string; + cpu_string = "Unknown"; return cpu_string; } diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 89fceb30bd..e5e9878d6f 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -424,7 +424,17 @@ const char *GetCompilerABI() { #elif PPSSPP_ARCH(AMD64) return "x86-64"; #elif PPSSPP_ARCH(RISCV64) - return "rv64"; + //https://github.com/riscv/riscv-toolchain-conventions#cc-preprocessor-definitions + //https://github.com/riscv/riscv-c-api-doc/blob/master/riscv-c-api.md#abi-related-preprocessor-definitions + #if defined(__riscv_float_abi_single) + return "lp64f"; + #elif defined(__riscv_float_abi_double) + return "lp64d"; + #elif defined(__riscv_float_abi_quad) + return "lp64q"; + #elif defined(__riscv_float_abi_soft) + return "lp64"; + #endif #else return "other"; #endif diff --git a/ppsspp_config.h b/ppsspp_config.h index 0c4e2b9c1d..cdf01e07d6 100644 --- a/ppsspp_config.h +++ b/ppsspp_config.h @@ -65,6 +65,7 @@ #endif #if defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64 + //https://github.com/riscv/riscv-c-api-doc/blob/master/riscv-c-api.md #define PPSSPP_ARCH_RISCV64 1 #define PPSSPP_ARCH_64BIT 1 #endif From 9ac49316366dde99418f3e81249fe17a74d0d605 Mon Sep 17 00:00:00 2001 From: Pierce Andjelkovic Date: Sat, 31 Jul 2021 03:03:13 +1000 Subject: [PATCH 11/12] Fix get CPU & CPU Brand --- Common/RiscVCPUDetect.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Common/RiscVCPUDetect.cpp b/Common/RiscVCPUDetect.cpp index 4e3c10d7aa..7a47bd1021 100644 --- a/Common/RiscVCPUDetect.cpp +++ b/Common/RiscVCPUDetect.cpp @@ -33,11 +33,19 @@ const char procfile[] = "/proc/cpuinfo"; const char syscpupresentfile[] = "/sys/devices/system/cpu/present"; std::string GetCPUString() { + //TODO std::string cpu_string; cpu_string = "Unknown"; return cpu_string; } +std::string GetCPUBrandString() { + //TODO + std::string brand_string; + brand_string = "Unknown"; + return brand_string; +} + int GetCoreCount() { std::string line, marker = "processor\t: "; @@ -99,7 +107,8 @@ void CPUInfo::Detect() #if !defined(__linux__) num_cores = 1; #else // __linux__ - strncpy(cpu_string, GetCPUString().c_str(), sizeof(cpu_string)); + truncate_cpy(cpu_string, GetCPUString().c_str()); + truncate_cpy(brand_string, GetCPUBrandString().c_str()); num_cores = GetCoreCount(); #endif } @@ -114,6 +123,8 @@ std::string CPUInfo::Summarize() sum = StringFromFormat("%s, %i cores", cpu_string, num_cores); if (CPU64bit) sum += ", 64-bit"; + //TODO: parse "isa : rv64imafdc" from /proc/cpuinfo + return sum; } From 1e949c8097602d6bf4a6c5a49902fbe37eedbd33 Mon Sep 17 00:00:00 2001 From: Pierce Andjelkovic Date: Sat, 7 Aug 2021 04:08:39 +1000 Subject: [PATCH 12/12] Fix indentation --- ppsspp_config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ppsspp_config.h b/ppsspp_config.h index cdf01e07d6..eb12cf244e 100644 --- a/ppsspp_config.h +++ b/ppsspp_config.h @@ -66,8 +66,8 @@ #if defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64 //https://github.com/riscv/riscv-c-api-doc/blob/master/riscv-c-api.md - #define PPSSPP_ARCH_RISCV64 1 - #define PPSSPP_ARCH_64BIT 1 + #define PPSSPP_ARCH_RISCV64 1 + #define PPSSPP_ARCH_64BIT 1 #endif