Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1c94142
feat: remove memory and pad from stub section
ran-j Apr 1, 2026
b394078
feat: add support for resume entry targets in CodeGenerator (this all…
ran-j Apr 1, 2026
55d482a
feat: optmizations for release build
ran-j Apr 1, 2026
7b7771d
feat: remove unused file
ran-j Apr 1, 2026
63e32a2
feat: added some test cases for code gen
ran-j Apr 1, 2026
fe287bf
feat: added log macro and remove win specific code
ran-j Apr 1, 2026
06c011c
feat: refactor runtime folder structure
ran-j Apr 1, 2026
945df43
feat: added game override for code veronica
ran-j Apr 1, 2026
7f97d1a
feat: apply vita patch
ran-j Apr 1, 2026
f278ad0
feat: flags to disable build
ran-j Apr 1, 2026
76194f9
feat: fix merges
ran-j Apr 1, 2026
6f3b299
feat: better throw error on empty cd path
ran-j Apr 1, 2026
5b2e04c
feat: gamedp is now part of lib
ran-j Apr 1, 2026
7ac1b96
feat: small cleanup
ran-j Apr 1, 2026
64f85aa
feat: missing vita changes
ran-j Apr 1, 2026
4bf1f89
feat: fix more merge
ran-j Apr 1, 2026
3f3e9d6
feat: fix tests
ran-j Apr 2, 2026
fe9bd32
feat: last missing feature
ran-j Apr 2, 2026
35af001
feat: added missing import
ran-j Apr 2, 2026
eadb290
feat: rename test local functions
ran-j Apr 2, 2026
061dc6b
feat: init syscall on ps2 list
ran-j Apr 2, 2026
1ea448e
feat: added DMA helpers
ran-j Apr 2, 2026
95e75ef
feat: faster builds
ran-j Apr 4, 2026
9c6918c
feat: back missing file
ran-j Apr 4, 2026
c20d84d
feat: added missing includes
ran-j Apr 4, 2026
55f16ab
feat: remove test
ran-j Apr 4, 2026
90169ed
feat: missing include
ran-j Apr 4, 2026
66914d0
feat: read register funtion
ran-j Apr 4, 2026
24d1ba4
feat: build fix
ran-j Apr 5, 2026
f967e72
feat: force exit on detach thread
ran-j Apr 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 51 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
cmake_minimum_required(VERSION 3.21)

if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{VITASDK})
set(PS2X_VITA_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake")
if(EXISTS "${PS2X_VITA_TOOLCHAIN_FILE}")
set(CMAKE_TOOLCHAIN_FILE "${PS2X_VITA_TOOLCHAIN_FILE}" CACHE PATH
"Toolchain file used for cross-compiling" FORCE)
message(STATUS "Using VitaSDK toolchain from VITASDK: ${CMAKE_TOOLCHAIN_FILE}")
endif()
endif()

project("PS2 Retro X")

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

option(PS2X_RUNTIME OFF)
option(PS2X_BUILD_RECOMP "Build ps2xRecomp" ON)
option(PS2X_BUILD_RUNTIME "Build ps2xRuntime" ON)
option(PS2X_BUILD_ANALYZER "Build ps2xAnalyzer" ON)
option(PS2X_BUILD_TEST "Build ps2xTest" ON)
option(PS2X_BUILD_STUDIO "Build ps2xStudio" ON)

# ARM64 support using sse2neon
set(PS2X_IS_ARM_TARGET OFF)
set(PS2X_IS_AARCH64_TARGET OFF)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64|ARM64")
message(STATUS "ARM64 detected, fetching sse2neon")
set(PS2X_IS_ARM_TARGET ON)
set(PS2X_IS_AARCH64_TARGET ON)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm|^ARM")
set(PS2X_IS_ARM_TARGET ON)
endif()

if((CMAKE_C_COMPILER MATCHES "arm-vita-eabi") OR
(CMAKE_CXX_COMPILER MATCHES "arm-vita-eabi"))
set(PS2X_IS_ARM_TARGET ON)
endif()

if(PS2X_IS_ARM_TARGET)
message(STATUS "ARM target detected, fetching sse2neon")

include(FetchContent)
FetchContent_Declare(
Expand All @@ -22,13 +48,13 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64|ARM64")
include_directories(${sse2neon_SOURCE_DIR})
add_compile_definitions(USE_SSE2NEON)

if(APPLE)
if(PS2X_IS_AARCH64_TARGET AND APPLE)
# macOS ARM64 already uses optimal defaults
message(STATUS "macOS ARM64 - using default compiler flags")
elseif(MSVC)
elseif(PS2X_IS_AARCH64_TARGET AND MSVC)
# Windows ARM64 - MSVC already uses optimal defaults
message(STATUS "Windows ARM64 (MSVC) - using default compiler flags")
else()
elseif(PS2X_IS_AARCH64_TARGET)
# Linux ARM64 - add NEON flags
message(STATUS "Non-Apple ARM64 - adding NEON compiler flags")
add_compile_options(-march=armv8-a+fp+simd)
Expand All @@ -39,14 +65,28 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64|ARM64")
if(COMPILER_SUPPORTS_CRYPTO_CRC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+fp+simd+crypto+crc")
message(STATUS "Crypto and CRC extensions enabled")
else()
add_compile_options(-march=armv8-a+fp+simd)
endif()
endif()
endif()

add_subdirectory("ps2xRecomp")
if(PS2X_BUILD_RECOMP)
add_subdirectory("ps2xRecomp")
endif()

if(PS2X_BUILD_RUNTIME)
add_subdirectory("ps2xRuntime")
endif()

add_subdirectory("ps2xRuntime")
if(PS2X_BUILD_ANALYZER)
add_subdirectory("ps2xAnalyzer")
endif()

add_subdirectory("ps2xAnalyzer")
add_subdirectory("ps2xTest")
add_subdirectory("ps2xStudio")
if(PS2X_BUILD_TEST)
add_subdirectory("ps2xTest")
endif()

if(PS2X_BUILD_STUDIO)
add_subdirectory("ps2xStudio")
endif()
7 changes: 7 additions & 0 deletions ps2xAnalyzer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ install(TARGETS ps2_analyzer ps2_analyzer_lib
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

include("${CMAKE_SOURCE_DIR}/ps2xRuntime/cmake/ReleaseMode.cmake")

if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
EnableFastReleaseMode(ps2_analyzer_lib)
EnableFastReleaseMode(ps2_analyzer)
endif()
19 changes: 17 additions & 2 deletions ps2xAnalyzer/src/elf_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace ps2recomp
static bool hasPs2ApiPrefix(const std::string &name);
static bool hasReliableSymbolName(const std::string &name);
static bool isDoNotSkipOrStub(const std::string &name);
static bool isKnownLocalHelperName(const std::string &name);
static bool matchesKernelRuntimeName(const std::string &name);
static uint32_t decodeAbsoluteJumpTarget(uint32_t instructionAddress, uint32_t targetField);
static bool tryReadWord(const ElfParser *parser, uint32_t address, uint32_t &outWord);
Expand Down Expand Up @@ -313,7 +314,7 @@ namespace ps2recomp
"malloc", "free", "calloc", "realloc", "aligned_alloc", "posix_memalign",

// Memory manipulation
"memcpy", "memset", "memmove", "memcmp", "memcpy2", "memchr", "bcopy", "bzero",
"memcpy", "memset", "memmove", "memcmp", "memchr", "bcopy", "bzero",

// String manipulation
"strcpy", "strncpy", "strcat", "strncat", "strcmp", "strncmp", "strlen", "strstr",
Expand Down Expand Up @@ -2020,7 +2021,6 @@ namespace ps2recomp
const std::vector<std::string> libraryPrefixes = {
"sce", "Sce", "SCE", // Sony prefixes
"sif", "Sif", "SIF", // SIF functions
"pad", "Pad", "PAD", // Pad functions
"gs", "Gs", "GS", // Graphics Synthesizer
"dma", "Dma", "DMA", // DMA functions
"iop", "Iop", "IOP", // IOP functions
Expand Down Expand Up @@ -2068,6 +2068,15 @@ namespace ps2recomp
return kDoNotSkipOrStub.contains(name);
}

static bool isKnownLocalHelperName(const std::string &name)
{
static const std::unordered_set<std::string> kKnownLocalHelpers = {
"memcpy2",
"_memcpy2"};

return kKnownLocalHelpers.contains(name);
}

static bool hasReliableSymbolName(const std::string &name)
{
if (name.empty())
Expand Down Expand Up @@ -2182,12 +2191,18 @@ namespace ps2recomp
if (!hasReliableSymbolName(name))
return false;

if (isKnownLocalHelperName(name))
return false;

std::string normalizedName = name;
if (normalizedName[0] == '_' && normalizedName.size() > 1)
{
normalizedName = normalizedName.substr(1);
}

if (isKnownLocalHelperName(normalizedName))
return false;

if (matchesKernelRuntimeName(normalizedName))
return true;

Expand Down
7 changes: 7 additions & 0 deletions ps2xRecomp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,10 @@ install(TARGETS ps2_recomp ps2_recomp_lib
install(DIRECTORY include/
DESTINATION include
)

include("${CMAKE_SOURCE_DIR}/ps2xRuntime/cmake/ReleaseMode.cmake")

if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
EnableFastReleaseMode(ps2_recomp_lib)
EnableFastReleaseMode(ps2_recomp)
endif()
7 changes: 6 additions & 1 deletion ps2xRecomp/include/ps2recomp/code_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace ps2recomp

struct AnalysisResult {
std::unordered_set<uint32_t> entryPoints;
std::unordered_set<uint32_t> externalEntryPoints;
std::unordered_set<uint32_t> resumeEntryPoints;
std::unordered_map<uint32_t, std::vector<uint32_t>> jumpTableTargets;
};

Expand All @@ -49,15 +51,18 @@ namespace ps2recomp
void setBootstrapInfo(const BootstrapInfo &info);
void setRelocationCallNames(const std::unordered_map<uint32_t, std::string> &callNames);
void setConfiguredJumpTables(const std::vector<JumpTable> &jumpTables);
void setResumeEntryTargets(const std::unordered_map<uint32_t, std::vector<uint32_t>> &resumeTargetsByOwner);

AnalysisResult collectInternalBranchTargets(const Function &function,
const std::vector<Instruction> &instructions);
const std::vector<Instruction> &instructions,
const std::vector<Function> *allFunctions = nullptr);

public:
std::unordered_map<uint32_t, Symbol> m_symbols;
std::unordered_map<uint32_t, std::string> m_renamedFunctions;
std::unordered_map<uint32_t, std::string> m_relocationCallNames;
std::unordered_map<uint32_t, std::vector<uint32_t>> m_configJumpTableTargetsByAddress;
std::unordered_map<uint32_t, std::vector<uint32_t>> m_resumeEntryTargetsByOwner;
const std::vector<Section>& m_sections;
BootstrapInfo m_bootstrapInfo;

Expand Down
1 change: 1 addition & 0 deletions ps2xRecomp/include/ps2recomp/ps2_recompiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace ps2recomp
std::unordered_map<uint32_t, std::string> m_stubHandlerBindingsByStart;
std::map<uint32_t, std::string> m_generatedStubs;
std::unordered_map<uint32_t, std::string> m_functionRenames;
std::unordered_map<uint32_t, std::vector<uint32_t>> m_resumeEntryTargetsByOwner;
CodeGenerator::BootstrapInfo m_bootstrapInfo;

bool decodeFunction(Function &function);
Expand Down
Loading