mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #774 from adriadam10/feat/agc-payload-range
feat(agc): implement sceAgcGetDataPacketPayloadRange
This commit is contained in:
@@ -115,6 +115,19 @@ if(BUILD_TESTING)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_test_executable(agc_payload_range_tests EXCLUDE_FROM_ALL tests/PayloadRange.cpp)
|
||||
target_include_directories(agc_payload_range_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(agc_payload_range_tests PRIVATE libSceAgc libc)
|
||||
configure_windows_unwind(agc_payload_range_tests)
|
||||
if(BUILD_TESTING)
|
||||
set_target_properties(agc_payload_range_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
|
||||
add_test(NAME agc_payload_range_tests COMMAND agc_payload_range_tests)
|
||||
if(WIN32)
|
||||
set_tests_properties(agc_payload_range_tests PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_test_executable(agc_branch_patch_tests EXCLUDE_FROM_ALL
|
||||
tests/BranchPatch.cpp
|
||||
Command/src/Packet.cpp
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
#ifndef CORE_LIBS_PRX_LIBSCEAGC_MISC_INCLUDE_PACKETINFO_HPP
|
||||
#define CORE_LIBS_PRX_LIBSCEAGC_MISC_INCLUDE_PACKETINFO_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
struct SceAgcMemoryRange {
|
||||
void* base;
|
||||
uint64_t size;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -29,6 +29,23 @@ int APS5_VABI sceAgcGetDataPacketPayloadAddressUnk(uint32_t** addr, uint32_t* cm
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcGetDataPacketPayloadRange(SceAgcMemoryRange* range, uint32_t* cmd, int type) {
|
||||
Agc::Command::CheckAddress(reinterpret_cast<std::uintptr_t>(range), alignof(SceAgcMemoryRange), __func__);
|
||||
Agc::Command::CheckAddress(reinterpret_cast<std::uintptr_t>(cmd), alignof(uint32_t), __func__);
|
||||
const uint64_t count_bytes = (cmd[0] >> 14u) & 0xfffcu;
|
||||
if (type != 0) {
|
||||
range->base = cmd + 2;
|
||||
range->size = count_bytes;
|
||||
} else if ((~cmd[0] & 0x3fff0000u) == 0) {
|
||||
range->base = nullptr;
|
||||
range->size = 0;
|
||||
} else {
|
||||
range->base = cmd + 1;
|
||||
range->size = count_bytes + sizeof(uint32_t);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDcbGetSystemSoftwareVersion(uint32_t* destination, const uint32_t* packet) {
|
||||
Agc::Command::CheckAddress(reinterpret_cast<std::uintptr_t>(destination), alignof(uint32_t), __func__);
|
||||
Agc::Command::CheckAddress(reinterpret_cast<std::uintptr_t>(packet), alignof(uint32_t), __func__);
|
||||
|
||||
@@ -55,11 +55,6 @@ int APS5_VABI sceAgcDebugRaiseException() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcGetDataPacketPayloadRange() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcGetDefaultCxStateFlat() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
#include "prx/libSceAgc/Misc/include/PacketInfo.hpp"
|
||||
#include "prx/libc/include/general/VabiMacros.hpp"
|
||||
#include "prx/libc/include/Shutdown.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
|
||||
extern "C" int APS5_VABI sceAgcGetDataPacketPayloadRange(SceAgcMemoryRange* range, std::uint32_t* cmd, int type);
|
||||
extern "C" int APS5_VABI sceAgcGetDataPacketPayloadAddressUnk(std::uint32_t** addr, std::uint32_t* cmd, int type);
|
||||
|
||||
namespace {
|
||||
|
||||
void check(bool condition, const char* message) {
|
||||
if (!condition) throw std::runtime_error(message);
|
||||
}
|
||||
|
||||
template <typename TAction>
|
||||
void expectFailure(TAction action) {
|
||||
try {
|
||||
action();
|
||||
} catch (const std::runtime_error& error) {
|
||||
check(error.what()[0] != '\0', "empty exception message");
|
||||
return;
|
||||
}
|
||||
throw std::runtime_error("expected an exception");
|
||||
}
|
||||
|
||||
void testRanges() {
|
||||
const std::array<std::tuple<std::uint32_t, int, std::ptrdiff_t, std::uint64_t>, 10> rows{{
|
||||
{0xc0047600u, 1, 2, 16}, {0xc0001000u, 1, 2, 0}, {0xffff7600u, 1, 2, 0xfffc}, {0xc0047600u, -1, 2, 16},
|
||||
{0xc0047600u, 7, 2, 16}, {0xc0021000u, 0, 1, 12}, {0xc0001000u, 0, 1, 4}, {0xfffe1000u, 0, 1, 0xfffc},
|
||||
{0xffff1000u, 0, -1, 0}, {0xffff7600u, 0, -1, 0}}};
|
||||
for (const auto& [header, type, offset, size] : rows) {
|
||||
std::array<std::uint32_t, 2> words{header, 0x12345678u};
|
||||
SceAgcMemoryRange range{reinterpret_cast<void*>(std::uintptr_t{0x1000}), 0xdeadu};
|
||||
check(sceAgcGetDataPacketPayloadRange(&range, words.data(), type) == 0, "payload range failed");
|
||||
void* expected = offset < 0 ? nullptr : static_cast<void*>(words.data() + offset);
|
||||
check(range.base == expected, "payload range base mismatch");
|
||||
check(range.size == size, "payload range size mismatch");
|
||||
check(words[0] == header && words[1] == 0x12345678u, "payload range query modified the packet");
|
||||
std::uint32_t* address = nullptr;
|
||||
check(sceAgcGetDataPacketPayloadAddressUnk(&address, words.data(), type) == 0 && address == range.base,
|
||||
"payload range base differs from the payload address");
|
||||
}
|
||||
}
|
||||
|
||||
void testRejections() {
|
||||
std::array<std::uint32_t, 2> words{0xc0047600u, 0u};
|
||||
SceAgcMemoryRange range{};
|
||||
expectFailure([&] { sceAgcGetDataPacketPayloadRange(nullptr, words.data(), 1); });
|
||||
expectFailure([&] { sceAgcGetDataPacketPayloadRange(&range, nullptr, 1); });
|
||||
auto* misaligned = reinterpret_cast<std::uint32_t*>(reinterpret_cast<unsigned char*>(words.data()) + 1);
|
||||
expectFailure([&] { sceAgcGetDataPacketPayloadRange(&range, misaligned, 0); });
|
||||
std::array<unsigned char, sizeof(SceAgcMemoryRange) + 8> storage{};
|
||||
auto* misalignedRange = reinterpret_cast<SceAgcMemoryRange*>(storage.data() + 4);
|
||||
if (reinterpret_cast<std::uintptr_t>(misalignedRange) % alignof(SceAgcMemoryRange) == 0) {
|
||||
misalignedRange = reinterpret_cast<SceAgcMemoryRange*>(storage.data() + 2);
|
||||
}
|
||||
expectFailure([&] { sceAgcGetDataPacketPayloadRange(misalignedRange, words.data(), 1); });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
testRanges();
|
||||
testRejections();
|
||||
LibcRunShutdown_nid_postfix();
|
||||
std::puts("AGC payload range tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::fprintf(stderr, "%s\n", error.what());
|
||||
try { LibcRunShutdown_nid_postfix(); }
|
||||
catch (const std::exception& shutdown) { std::fprintf(stderr, "shutdown: %s\n", shutdown.what()); }
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,7 @@ Throughout the project, every function at every stage either **does exactly what
|
||||
- [dolOmWH+huQ](../../core/libs/prx/libSceAgc/Misc/src/ShaderFusion.cpp) (libSceAgc) - unknown name
|
||||
- [dbOlWdppb4o](../../core/libs/prx/libSceAgc/Shader/src/InterpolantMapping.cpp) (libSceAgc) - unknown name; same arguments as `sceAgcCreateInterpolantMapping`; the `SPI_PS_INPUT_CNTL` bits for `is_f16` 2 inputs follow KytyPS5, not confirmed on hardware
|
||||
- [V++UgBtQhn0](../../core/libs/prx/libSceAgc/Misc/src/PacketInfo.cpp) (libSceAgc) - unknown name
|
||||
- [sceAgcGetDataPacketPayloadRange](../../core/libs/prx/libSceAgc/Misc/src/PacketInfo.cpp) (libSceAgc) - signature, the `{base, size in bytes}` output and the type 0 range (header + 1, one dword longer than the type 1 payload) from KytyPS5 only, matching `V++UgBtQhn0`; prosper returns header + 2 for both types from that address function
|
||||
- [gQkqkLttcpw](../../core/libs/prx/libSceAgc/Acb/src/Control.cpp) (libSceAgc) - unknown name, signature
|
||||
- [sceAgcDcbPrimeUtcl2](../../core/libs/prx/libSceAgc/DcbState/src/Display.cpp) (libSceAgc) - assumed to write the packet `sceAgcAcbPrimeUtcl2` writes: PRIME_UTCL2 has the same 5 dwords on the graphics and compute rings. Not confirmed on a title. Both write a NOP of that size, as there is no TLB to prime
|
||||
- [sceKernelInternalMemoryGetModuleSegmentInfo](../../core/libs/prx/libkernel/Module/src/Module.cpp) (libkernel) - unknown signature
|
||||
|
||||
Reference in New Issue
Block a user