Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 12 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.21)
cmake_minimum_required(VERSION 3.24)

if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{VITASDK})
set(PS2X_VITA_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake")
Expand All @@ -17,7 +17,7 @@ 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)
option(PS2X_BUILD_STUDIO "Build ps2xStudio" OFF)

if(ANDROID)
message(STATUS "Android target detected, building runtime only")
Expand All @@ -28,6 +28,10 @@ if(ANDROID)
endif()

set(PS2X_IS_ARM_TARGET OFF)
if(PS2X_BUILD_TEST OR PS2X_BUILD_STUDIO)
enable_testing()
endif()

set(PS2X_IS_AARCH64_TARGET OFF)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64|ARM64")
set(PS2X_IS_ARM_TARGET ON)
Expand Down Expand Up @@ -79,20 +83,22 @@ if(PS2X_IS_ARM_TARGET)
endif()
endif()

if(PS2X_BUILD_RECOMP)
# Include modules required by enabled consumers even if their own option is OFF.
# Tests use all three libraries; Studio also uses the test library.
if(PS2X_BUILD_RECOMP OR PS2X_BUILD_ANALYZER OR PS2X_BUILD_TEST OR PS2X_BUILD_STUDIO)
add_subdirectory("ps2xRecomp")
endif()

if(PS2X_BUILD_RUNTIME)
if(PS2X_BUILD_RUNTIME OR PS2X_BUILD_TEST OR PS2X_BUILD_STUDIO)
add_subdirectory("ps2xIOP")
add_subdirectory("ps2xRuntime")
endif()

if(PS2X_BUILD_ANALYZER)
if(PS2X_BUILD_ANALYZER OR PS2X_BUILD_TEST OR PS2X_BUILD_STUDIO)
add_subdirectory("ps2xAnalyzer")
endif()

if(PS2X_BUILD_TEST)
if(PS2X_BUILD_TEST OR PS2X_BUILD_STUDIO)
add_subdirectory("ps2xTest")
endif()

Expand Down
5 changes: 5 additions & 0 deletions ps2xIOP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ if(PS2X_IOP_BUILD_TESTS)
target_include_directories(ps2_iop_import_version_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_test(NAME ps2_iop_import_version_tests COMMAND ps2_iop_import_version_tests)

add_executable(ps2_iop_execution_tests tests/iop_execution_tests.cpp)
target_link_libraries(ps2_iop_execution_tests PRIVATE ps2_iop)
target_include_directories(ps2_iop_execution_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_test(NAME ps2_iop_execution_tests COMMAND ps2_iop_execution_tests)

endif()

install(TARGETS ps2_iop
Expand Down
1 change: 1 addition & 0 deletions ps2xIOP/include/ps2x/iop/iop_subsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace ps2x::iop
[[nodiscard]] ModuleLoadResult loadModuleBuffer(uint32_t guestAddress, const void *arguments = nullptr, uint32_t argumentSize = 0);
[[nodiscard]] bool stopModule(int32_t moduleId, int32_t *result = nullptr);
void runEeCycles(uint64_t eeCycles) noexcept;
[[nodiscard]] const ExecutionFault &fault() const noexcept;

[[nodiscard]] RpcAbi selectRpcAbi(const RpcAbiRequest &request) const;
[[nodiscard]] bool canBindRpc(uint32_t sid) const noexcept;
Expand Down
8 changes: 8 additions & 0 deletions ps2xIOP/include/ps2x/iop/iop_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
#include <cstdint>
#include <string>
#include <vector>
#include <array>

namespace ps2x::iop
{
struct ExecutionFault
{
bool active = false;
uint32_t pc = 0;
std::array<char, 192> reason{};
};

struct GuestBuffer
{
uint32_t address = 0;
Expand Down
15 changes: 9 additions & 6 deletions ps2xIOP/src/emulator/core/iop_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,20 @@ namespace ps2x::iop::detail
cpu.cop0[12] = (status & ~0x3Fu) | ((status << 2u) & 0x3Fu);
cpu.pc = (status & (1u << 22u)) ? 0xBFC00180u : 0x80000080u;
cpu.branchPending = false;
if (cpu.pendingLoad && cpu.pendingLoadReg != 0u)
cpu.gpr[cpu.pendingLoadReg] = cpu.pendingLoadValue;
cpu.pendingLoad = false;
cpu.exception = true;
}

bool IopCpuCore::executeInstruction(IopCpuState &cpu)
{
return executeInstruction(cpu, m_memory.read32(cpu.pc));
}

bool IopCpuCore::executeInstruction(IopCpuState &cpu, uint32_t instruction)
{
const uint32_t pc = cpu.pc;
const uint32_t instruction = m_memory.read32(pc);
const bool wasDelaySlot = cpu.branchPending;
const uint32_t priorBranchTarget = cpu.branchTarget;

Expand All @@ -82,11 +88,8 @@ namespace ps2x::iop::detail

auto branch = [&](bool condition)
{
if (condition)
{
newBranch = true;
newBranchTarget = nextPc + (static_cast<uint32_t>(simm) << 2u);
}
newBranch = true;
newBranchTarget = condition ? nextPc + (static_cast<uint32_t>(simm) << 2u) : nextPc + 4u;
};
auto write = [&](uint32_t reg, uint32_t value)
{
Expand Down
1 change: 1 addition & 0 deletions ps2xIOP/src/emulator/core/iop_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace ps2x::iop::detail
explicit IopCpuCore(IopMemory &memory) noexcept;

[[nodiscard]] bool executeInstruction(IopCpuState &cpu);
[[nodiscard]] bool executeInstruction(IopCpuState &cpu, uint32_t instruction);
void raiseException(IopCpuState &cpu, uint32_t code, uint32_t faultPc, bool delaySlot, std::optional<uint32_t> badAddress = std::nullopt) const;

private:
Expand Down
Loading
Loading