diff --git a/CMakeLists.txt b/CMakeLists.txt index 0725795392..d4921c07bb 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() @@ -423,6 +429,13 @@ set(CommonMIPS ) source_group(MIPS FILES ${CommonMIPS}) +set(CommonRISCV64 + Common/RiscVCPUDetect.cpp + Core/MIPS/fake/FakeJit.cpp + Core/MIPS/fake/FakeJit.h +) +source_group(RISCV64 FILES ${CommonRISCV64}) + if(WIN32) set(CommonD3D Common/GPU/D3D9/D3D9ShaderCompiler.cpp @@ -442,6 +455,7 @@ add_library(Common STATIC ${CommonARM} ${CommonARM64} ${CommonMIPS} + ${CommonRISCV64} ${CommonD3D} Common/Serialize/Serializer.cpp Common/Serialize/Serializer.h @@ -712,6 +726,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) 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..7a47bd1021 --- /dev/null +++ b/Common/RiscVCPUDetect.cpp @@ -0,0 +1,131 @@ +// 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() { + //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: "; + int cores = 1; + + std::string presentData; + bool presentSuccess = File::ReadFileToString(true, Path(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, Path(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__ + truncate_cpy(cpu_string, GetCPUString().c_str()); + truncate_cpy(brand_string, GetCPUBrandString().c_str()); + 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"; + + //TODO: parse "isa : rv64imafdc" from /proc/cpuinfo + + return sum; +} + +#endif // PPSSPP_ARCH(RISCV64) diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 2d18c69315..0342ee1d67 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -420,6 +420,18 @@ const char *GetCompilerABI() { return "x86"; #elif PPSSPP_ARCH(AMD64) return "x86-64"; +#elif PPSSPP_ARCH(RISCV64) + //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/ffmpeg b/ffmpeg index 0b28335ace..a5baf97df4 160000 --- a/ffmpeg +++ b/ffmpeg @@ -1 +1 @@ -Subproject commit 0b28335acea4f429ae798c5e75232e54881bf164 +Subproject commit a5baf97df4579b4614cd5e643241c7acfc36b0c4 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..eb12cf244e 100644 --- a/ppsspp_config.h +++ b/ppsspp_config.h @@ -64,6 +64,12 @@ #define PPSSPP_ARCH_32BIT 1 #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 + // PLATFORM defines #if defined(_WIN32)