mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-31 07:43:16 +00:00
code: Add clang-format target and CI workflow (#82)
* code: Add clang format target, rules and CI workflow * code: Run clang format on sources
This commit is contained in:
parent
32a5ff15bb
commit
6f4c6ae0bb
90 changed files with 2942 additions and 1941 deletions
|
@ -1,10 +1,11 @@
|
|||
#include "gpu_memory.h"
|
||||
#include <atomic>
|
||||
#include <xxh3.h>
|
||||
#include "gpu_memory.h"
|
||||
|
||||
#include "common/singleton.h"
|
||||
|
||||
void* GPU::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, void* todo /*CommandBuffer?*/, u64 virtual_addr, u64 size,
|
||||
void* GPU::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx,
|
||||
void* todo /*CommandBuffer?*/, u64 virtual_addr, u64 size,
|
||||
const GPUObject& info) {
|
||||
auto* gpumemory = Common::Singleton<GPUMemory>::Instance();
|
||||
|
||||
|
@ -23,9 +24,12 @@ void GPU::memorySetAllocArea(u64 virtual_addr, u64 size) {
|
|||
gpumemory->m_heaps.push_back(h);
|
||||
}
|
||||
|
||||
u64 GPU::calculate_hash(const u08* buf, u64 size) { return (size > 0 && buf != nullptr ? XXH3_64bits(buf, size) : 0); }
|
||||
u64 GPU::calculate_hash(const u08* buf, u64 size) {
|
||||
return (size > 0 && buf != nullptr ? XXH3_64bits(buf, size) : 0);
|
||||
}
|
||||
|
||||
bool GPU::vulkanAllocateMemory(HLE::Libs::Graphics::GraphicCtx* ctx, HLE::Libs::Graphics::VulkanMemory* mem) {
|
||||
bool GPU::vulkanAllocateMemory(HLE::Libs::Graphics::GraphicCtx* ctx,
|
||||
HLE::Libs::Graphics::VulkanMemory* mem) {
|
||||
static std::atomic_uint64_t unique_id = 0;
|
||||
|
||||
VkPhysicalDeviceMemoryProperties memory_properties{};
|
||||
|
@ -66,7 +70,8 @@ void GPU::flushGarlic(HLE::Libs::Graphics::GraphicCtx* ctx) {
|
|||
int GPU::GPUMemory::getHeapId(u64 virtual_addr, u64 size) {
|
||||
int index = 0;
|
||||
for (const auto& heap : m_heaps) {
|
||||
if ((virtual_addr >= heap.allocated_virtual_addr && virtual_addr < heap.allocated_virtual_addr + heap.allocated_size) ||
|
||||
if ((virtual_addr >= heap.allocated_virtual_addr &&
|
||||
virtual_addr < heap.allocated_virtual_addr + heap.allocated_size) ||
|
||||
((virtual_addr + size - 1) >= heap.allocated_virtual_addr &&
|
||||
(virtual_addr + size - 1) < heap.allocated_virtual_addr + heap.allocated_size)) {
|
||||
return index;
|
||||
|
@ -76,7 +81,8 @@ int GPU::GPUMemory::getHeapId(u64 virtual_addr, u64 size) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
void* GPU::GPUMemory::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, void* todo, const u64* virtual_addr, const u64* size,
|
||||
void* GPU::GPUMemory::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx,
|
||||
void* todo, const u64* virtual_addr, const u64* size,
|
||||
int virtual_addr_num, const GPUObject& info) {
|
||||
auto* gpumemory = Common::Singleton<GPUMemory>::Instance();
|
||||
|
||||
|
@ -101,7 +107,8 @@ void* GPU::GPUMemory::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::Graphi
|
|||
|
||||
for (int h = 0; h < virtual_addr_num; h++) {
|
||||
if (info.check_hash) {
|
||||
objInfo.hash[h] = GPU::calculate_hash(reinterpret_cast<const u08*>(virtual_addr[h]), size[h]);
|
||||
objInfo.hash[h] =
|
||||
GPU::calculate_hash(reinterpret_cast<const u08*>(virtual_addr[h]), size[h]);
|
||||
} else {
|
||||
objInfo.hash[h] = 0;
|
||||
}
|
||||
|
@ -109,7 +116,8 @@ void* GPU::GPUMemory::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::Graphi
|
|||
objInfo.submit_id = submit_id;
|
||||
objInfo.check_hash = info.check_hash;
|
||||
|
||||
objInfo.gpu_object.obj = info.getCreateFunc()(ctx, objInfo.obj_params, virtual_addr, size, virtual_addr_num, &objInfo.mem);
|
||||
objInfo.gpu_object.obj = info.getCreateFunc()(ctx, objInfo.obj_params, virtual_addr, size,
|
||||
virtual_addr_num, &objInfo.mem);
|
||||
|
||||
objInfo.update_func = info.getUpdateFunc();
|
||||
int index = static_cast<int>(heap.objects.size());
|
||||
|
@ -123,7 +131,8 @@ void* GPU::GPUMemory::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::Graphi
|
|||
return objInfo.gpu_object.obj;
|
||||
}
|
||||
|
||||
GPU::HeapBlock GPU::GPUMemory::createHeapBlock(const u64* virtual_addr, const u64* size, int virtual_addr_num, int heap_id, int obj_id) {
|
||||
GPU::HeapBlock GPU::GPUMemory::createHeapBlock(const u64* virtual_addr, const u64* size,
|
||||
int virtual_addr_num, int heap_id, int obj_id) {
|
||||
auto& heap = m_heaps[heap_id];
|
||||
|
||||
GPU::HeapBlock heapBlock{};
|
||||
|
@ -135,7 +144,8 @@ GPU::HeapBlock GPU::GPUMemory::createHeapBlock(const u64* virtual_addr, const u6
|
|||
return heapBlock;
|
||||
}
|
||||
|
||||
void GPU::GPUMemory::update(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, int heap_id, int obj_id) {
|
||||
void GPU::GPUMemory::update(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, int heap_id,
|
||||
int obj_id) {
|
||||
auto& heap = m_heaps[heap_id];
|
||||
|
||||
auto& heapObj = heap.objects[obj_id];
|
||||
|
@ -147,7 +157,9 @@ void GPU::GPUMemory::update(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx,
|
|||
|
||||
for (int i = 0; i < heapObj.block.virtual_addr_num; i++) {
|
||||
if (objInfo.check_hash) {
|
||||
hash[i] = GPU::calculate_hash(reinterpret_cast<const uint8_t*>(heapObj.block.virtual_addr[i]), heapObj.block.size[i]);
|
||||
hash[i] = GPU::calculate_hash(
|
||||
reinterpret_cast<const uint8_t*>(heapObj.block.virtual_addr[i]),
|
||||
heapObj.block.size[i]);
|
||||
} else {
|
||||
hash[i] = 0;
|
||||
}
|
||||
|
@ -166,7 +178,8 @@ void GPU::GPUMemory::update(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx,
|
|||
}
|
||||
|
||||
if (need_update) {
|
||||
objInfo.update_func(ctx, objInfo.obj_params, objInfo.gpu_object.obj, heapObj.block.virtual_addr, heapObj.block.size,
|
||||
objInfo.update_func(ctx, objInfo.obj_params, objInfo.gpu_object.obj,
|
||||
heapObj.block.virtual_addr, heapObj.block.size,
|
||||
heapObj.block.virtual_addr_num);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <core/PS4/HLE/Graphics/graphics_ctx.h>
|
||||
#include "common/types.h"
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <core/PS4/HLE/Graphics/graphics_ctx.h>
|
||||
#include "common/types.h"
|
||||
|
||||
namespace GPU {
|
||||
|
||||
|
@ -24,7 +24,7 @@ struct HeapBlock {
|
|||
};
|
||||
|
||||
class GPUObject {
|
||||
public:
|
||||
public:
|
||||
GPUObject() = default;
|
||||
virtual ~GPUObject() = default;
|
||||
u64 obj_params[8] = {};
|
||||
|
@ -32,9 +32,11 @@ class GPUObject {
|
|||
bool isReadOnly = false;
|
||||
MemoryObjectType objectType = MemoryObjectType::InvalidObj;
|
||||
|
||||
using create_func_t = void* (*)(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params, const u64* virtual_addr, const u64* size, int virtual_addr_num,
|
||||
using create_func_t = void* (*)(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params,
|
||||
const u64* virtual_addr, const u64* size, int virtual_addr_num,
|
||||
HLE::Libs::Graphics::VulkanMemory* mem);
|
||||
using update_func_t = void (*)(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params, void* obj, const u64* virtual_addr, const u64* size,
|
||||
using update_func_t = void (*)(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params,
|
||||
void* obj, const u64* virtual_addr, const u64* size,
|
||||
int virtual_addr_num);
|
||||
|
||||
virtual create_func_t getCreateFunc() const = 0;
|
||||
|
@ -63,23 +65,27 @@ struct MemoryHeap {
|
|||
};
|
||||
|
||||
class GPUMemory {
|
||||
public:
|
||||
public:
|
||||
GPUMemory() {}
|
||||
virtual ~GPUMemory() {}
|
||||
int getHeapId(u64 vaddr, u64 size);
|
||||
std::mutex m_mutex;
|
||||
std::vector<MemoryHeap> m_heaps;
|
||||
void* memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, /*CommandBuffer* buffer*/ void* todo, const u64* virtual_addr,
|
||||
void* memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx,
|
||||
/*CommandBuffer* buffer*/ void* todo, const u64* virtual_addr,
|
||||
const u64* size, int virtual_addr_num, const GPUObject& info);
|
||||
HeapBlock createHeapBlock(const u64* virtual_addr, const u64* size, int virtual_addr_num, int heap_id, int obj_id);
|
||||
HeapBlock createHeapBlock(const u64* virtual_addr, const u64* size, int virtual_addr_num,
|
||||
int heap_id, int obj_id);
|
||||
void update(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, int heap_id, int obj_id);
|
||||
void flushAllHeaps(HLE::Libs::Graphics::GraphicCtx* ctx);
|
||||
};
|
||||
|
||||
void memorySetAllocArea(u64 virtual_addr, u64 size);
|
||||
void* memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, /*CommandBuffer* buffer*/ void* todo, u64 virtual_addr, u64 size,
|
||||
void* memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx,
|
||||
/*CommandBuffer* buffer*/ void* todo, u64 virtual_addr, u64 size,
|
||||
const GPUObject& info);
|
||||
u64 calculate_hash(const u08* buf, u64 size);
|
||||
bool vulkanAllocateMemory(HLE::Libs::Graphics::GraphicCtx* ctx, HLE::Libs::Graphics::VulkanMemory* mem);
|
||||
bool vulkanAllocateMemory(HLE::Libs::Graphics::GraphicCtx* ctx,
|
||||
HLE::Libs::Graphics::VulkanMemory* mem);
|
||||
void flushGarlic(HLE::Libs::Graphics::GraphicCtx* ctx);
|
||||
} // namespace GPU
|
||||
} // namespace GPU
|
|
@ -1,20 +1,22 @@
|
|||
#include "tile_manager.h"
|
||||
#include "common/singleton.h"
|
||||
#include <mutex>
|
||||
#include "common/singleton.h"
|
||||
#include "tile_manager.h"
|
||||
|
||||
namespace GPU {
|
||||
|
||||
static u32 IntLog2(u32 i) { return 31 - __builtin_clz(i | 1u); }
|
||||
static u32 IntLog2(u32 i) {
|
||||
return 31 - __builtin_clz(i | 1u);
|
||||
}
|
||||
|
||||
class TileManager {
|
||||
public:
|
||||
TileManager(){}
|
||||
virtual ~TileManager() { }
|
||||
public:
|
||||
TileManager() {}
|
||||
virtual ~TileManager() {}
|
||||
std::mutex m_mutex;
|
||||
};
|
||||
|
||||
class TileManager32 {
|
||||
public:
|
||||
public:
|
||||
u32 m_macro_tile_height = 0;
|
||||
u32 m_bank_height = 0;
|
||||
u32 m_num_banks = 0;
|
||||
|
@ -69,25 +71,26 @@ class TileManager32 {
|
|||
return pipe;
|
||||
}
|
||||
|
||||
static u32 getBankIdx(u32 x, u32 y, u32 bank_width, u32 bank_height, u32 num_banks, u32 num_pipes) {
|
||||
static u32 getBankIdx(u32 x, u32 y, u32 bank_width, u32 bank_height, u32 num_banks,
|
||||
u32 num_pipes) {
|
||||
const u32 x_shift_offset = IntLog2(bank_width * num_pipes);
|
||||
const u32 y_shift_offset = IntLog2(bank_height);
|
||||
const u32 xs = x >> x_shift_offset;
|
||||
const u32 ys = y >> y_shift_offset;
|
||||
u32 bank = 0;
|
||||
switch (num_banks) {
|
||||
case 8:
|
||||
bank |= (((xs >> 3u) ^ (ys >> 5u)) & 0x1u) << 0u;
|
||||
bank |= (((xs >> 4u) ^ (ys >> 4u) ^ (ys >> 5u)) & 0x1u) << 1u;
|
||||
bank |= (((xs >> 5u) ^ (ys >> 3u)) & 0x1u) << 2u;
|
||||
break;
|
||||
case 16:
|
||||
bank |= (((xs >> 3u) ^ (ys >> 6u)) & 0x1u) << 0u;
|
||||
bank |= (((xs >> 4u) ^ (ys >> 5u) ^ (ys >> 6u)) & 0x1u) << 1u;
|
||||
bank |= (((xs >> 5u) ^ (ys >> 4u)) & 0x1u) << 2u;
|
||||
bank |= (((xs >> 6u) ^ (ys >> 3u)) & 0x1u) << 3u;
|
||||
break;
|
||||
default:;
|
||||
case 8:
|
||||
bank |= (((xs >> 3u) ^ (ys >> 5u)) & 0x1u) << 0u;
|
||||
bank |= (((xs >> 4u) ^ (ys >> 4u) ^ (ys >> 5u)) & 0x1u) << 1u;
|
||||
bank |= (((xs >> 5u) ^ (ys >> 3u)) & 0x1u) << 2u;
|
||||
break;
|
||||
case 16:
|
||||
bank |= (((xs >> 3u) ^ (ys >> 6u)) & 0x1u) << 0u;
|
||||
bank |= (((xs >> 4u) ^ (ys >> 5u) ^ (ys >> 6u)) & 0x1u) << 1u;
|
||||
bank |= (((xs >> 5u) ^ (ys >> 4u)) & 0x1u) << 2u;
|
||||
bank |= (((xs >> 6u) ^ (ys >> 3u)) & 0x1u) << 3u;
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
|
||||
return bank;
|
||||
|
@ -110,11 +113,13 @@ class TileManager32 {
|
|||
tile_bytes = 512;
|
||||
}
|
||||
|
||||
u64 macro_tile_bytes = (128 / 8) * (m_macro_tile_height / 8) * tile_bytes / (m_num_pipes * m_num_banks);
|
||||
u64 macro_tile_bytes =
|
||||
(128 / 8) * (m_macro_tile_height / 8) * tile_bytes / (m_num_pipes * m_num_banks);
|
||||
u64 macro_tiles_per_row = m_padded_width / 128;
|
||||
u64 macro_tile_row_index = y / m_macro_tile_height;
|
||||
u64 macro_tile_column_index = x / 128;
|
||||
u64 macro_tile_index = (macro_tile_row_index * macro_tiles_per_row) + macro_tile_column_index;
|
||||
u64 macro_tile_index =
|
||||
(macro_tile_row_index * macro_tiles_per_row) + macro_tile_column_index;
|
||||
u64 macro_tile_offset = macro_tile_index * macro_tile_bytes;
|
||||
u64 macro_tiles_per_slice = macro_tiles_per_row * (m_padded_height / m_macro_tile_height);
|
||||
u64 slice_bytes = macro_tiles_per_slice * macro_tile_bytes;
|
||||
|
@ -133,20 +138,21 @@ class TileManager32 {
|
|||
|
||||
u64 pipe_interleave_offset = total_offset & 0xffu;
|
||||
u64 offset = total_offset >> 8u;
|
||||
u64 byte_offset = pipe_interleave_offset | (pipe << (8u)) | (bank << (8u + m_pipe_bits)) | (offset << (8u + m_pipe_bits + m_bank_bits));
|
||||
u64 byte_offset = pipe_interleave_offset | (pipe << (8u)) | (bank << (8u + m_pipe_bits)) |
|
||||
(offset << (8u + m_pipe_bits + m_bank_bits));
|
||||
|
||||
return ((byte_offset << 3u) | bit_offset) / 8;
|
||||
}
|
||||
};
|
||||
|
||||
void convertTileToLinear(void* dst, const void* src,u32 width, u32 height, bool is_neo) {
|
||||
void convertTileToLinear(void* dst, const void* src, u32 width, u32 height, bool is_neo) {
|
||||
TileManager32 t;
|
||||
t.Init(width, height, is_neo);
|
||||
|
||||
auto* g_TileManager = Common::Singleton<TileManager>::Instance();
|
||||
|
||||
std::scoped_lock lock{g_TileManager->m_mutex};
|
||||
|
||||
|
||||
for (u32 y = 0; y < height; y++) {
|
||||
u32 x = 0;
|
||||
u64 linear_offset = y * width * 4;
|
||||
|
@ -166,4 +172,4 @@ void convertTileToLinear(void* dst, const void* src,u32 width, u32 height, bool
|
|||
}
|
||||
}
|
||||
}
|
||||
} // namespace GPU
|
||||
} // namespace GPU
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
#include "common/log.h"
|
||||
|
||||
#include "common/debug.h"
|
||||
#include <vulkan_util.h>
|
||||
#include "common/debug.h"
|
||||
#include "tile_manager.h"
|
||||
|
||||
constexpr bool log_file_videoOutBuffer = true; // disable it to disable logging
|
||||
constexpr bool log_file_videoOutBuffer = true; // disable it to disable logging
|
||||
|
||||
static void update_func(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params, void* obj, const u64* virtual_addr, const u64* size,
|
||||
int virtual_addr_num) {
|
||||
static void update_func(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params, void* obj,
|
||||
const u64* virtual_addr, const u64* size, int virtual_addr_num) {
|
||||
|
||||
auto pitch = params[GPU::VideoOutBufferObj::PITCH_PARAM];
|
||||
bool tiled = (params[GPU::VideoOutBufferObj::IS_TILE_PARAM] != 0);
|
||||
|
@ -21,19 +21,22 @@ static void update_func(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params,
|
|||
|
||||
vk_obj->layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
|
||||
if (tiled)
|
||||
{
|
||||
if (tiled) {
|
||||
std::vector<u08> tempbuff(*size);
|
||||
GPU::convertTileToLinear(tempbuff.data(), reinterpret_cast<void*>(*virtual_addr), width, height, neo);
|
||||
Graphics::Vulkan::vulkanFillImage(ctx, vk_obj, tempbuff.data(), *size, pitch, static_cast<u64>(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
|
||||
GPU::convertTileToLinear(tempbuff.data(), reinterpret_cast<void*>(*virtual_addr), width,
|
||||
height, neo);
|
||||
Graphics::Vulkan::vulkanFillImage(
|
||||
ctx, vk_obj, tempbuff.data(), *size, pitch,
|
||||
static_cast<u64>(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
|
||||
} else {
|
||||
Graphics::Vulkan::vulkanFillImage(ctx, vk_obj, reinterpret_cast<void*>(*virtual_addr), *size, pitch,
|
||||
static_cast<u64>(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
|
||||
Graphics::Vulkan::vulkanFillImage(
|
||||
ctx, vk_obj, reinterpret_cast<void*>(*virtual_addr), *size, pitch,
|
||||
static_cast<u64>(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void* create_func(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params, const u64* virtual_addr, const u64* size, int virtual_addr_num,
|
||||
static void* create_func(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params,
|
||||
const u64* virtual_addr, const u64* size, int virtual_addr_num,
|
||||
HLE::Libs::Graphics::VulkanMemory* mem) {
|
||||
auto pixel_format = params[GPU::VideoOutBufferObj::PIXEL_FORMAT_PARAM];
|
||||
auto width = params[GPU::VideoOutBufferObj::WIDTH_PARAM];
|
||||
|
@ -44,9 +47,15 @@ static void* create_func(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params
|
|||
VkFormat vk_format = VK_FORMAT_UNDEFINED;
|
||||
|
||||
switch (pixel_format) {
|
||||
case static_cast<uint64_t>(GPU::VideoOutBufferFormat::R8G8B8A8Srgb): vk_format = VK_FORMAT_R8G8B8A8_SRGB; break;
|
||||
case static_cast<uint64_t>(GPU::VideoOutBufferFormat::B8G8R8A8Srgb): vk_format = VK_FORMAT_B8G8R8A8_SRGB; break;
|
||||
default: LOG_CRITICAL_IF(log_file_videoOutBuffer, "unknown pixelFormat = {}\n", pixel_format); std::exit(0);
|
||||
case static_cast<uint64_t>(GPU::VideoOutBufferFormat::R8G8B8A8Srgb):
|
||||
vk_format = VK_FORMAT_R8G8B8A8_SRGB;
|
||||
break;
|
||||
case static_cast<uint64_t>(GPU::VideoOutBufferFormat::B8G8R8A8Srgb):
|
||||
vk_format = VK_FORMAT_B8G8R8A8_SRGB;
|
||||
break;
|
||||
default:
|
||||
LOG_CRITICAL_IF(log_file_videoOutBuffer, "unknown pixelFormat = {}\n", pixel_format);
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
vk_obj->extent.width = width;
|
||||
|
@ -72,8 +81,9 @@ static void* create_func(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params
|
|||
image_info.format = vk_obj->format;
|
||||
image_info.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
image_info.initialLayout = vk_obj->layout;
|
||||
image_info.usage =
|
||||
static_cast<VkImageUsageFlags>(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT) | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
image_info.usage = static_cast<VkImageUsageFlags>(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
|
||||
VK_IMAGE_USAGE_TRANSFER_SRC_BIT) |
|
||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
image_info.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
|
||||
|
@ -124,7 +134,8 @@ static void* create_func(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params
|
|||
create_info.subresourceRange.layerCount = 1;
|
||||
create_info.subresourceRange.levelCount = 1;
|
||||
|
||||
vkCreateImageView(ctx->m_device, &create_info, nullptr, &vk_obj->image_view[HLE::Libs::Graphics::VulkanImage::VIEW_DEFAULT]);
|
||||
vkCreateImageView(ctx->m_device, &create_info, nullptr,
|
||||
&vk_obj->image_view[HLE::Libs::Graphics::VulkanImage::VIEW_DEFAULT]);
|
||||
|
||||
if (vk_obj->image_view[HLE::Libs::Graphics::VulkanImage::VIEW_DEFAULT] == nullptr) {
|
||||
LOG_CRITICAL_IF(log_file_videoOutBuffer, "vk_obj->image_view is null\n");
|
||||
|
@ -134,6 +145,10 @@ static void* create_func(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params
|
|||
return vk_obj;
|
||||
}
|
||||
|
||||
GPU::GPUObject::create_func_t GPU::VideoOutBufferObj::getCreateFunc() const { return create_func; }
|
||||
GPU::GPUObject::create_func_t GPU::VideoOutBufferObj::getCreateFunc() const {
|
||||
return create_func;
|
||||
}
|
||||
|
||||
GPU::GPUObject::update_func_t GPU::VideoOutBufferObj::getUpdateFunc() const { return update_func; }
|
||||
GPU::GPUObject::update_func_t GPU::VideoOutBufferObj::getUpdateFunc() const {
|
||||
return update_func;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ enum class VideoOutBufferFormat : u64 {
|
|||
};
|
||||
|
||||
class VideoOutBufferObj : public GPUObject {
|
||||
public:
|
||||
public:
|
||||
static constexpr int PIXEL_FORMAT_PARAM = 0;
|
||||
static constexpr int WIDTH_PARAM = 1;
|
||||
static constexpr int HEIGHT_PARAM = 2;
|
||||
|
@ -21,7 +21,8 @@ class VideoOutBufferObj : public GPUObject {
|
|||
static constexpr int IS_NEO_PARAM = 4;
|
||||
static constexpr int PITCH_PARAM = 5;
|
||||
|
||||
explicit VideoOutBufferObj(VideoOutBufferFormat pixel_format, u32 width, u32 height, bool is_tiled, bool is_neo, u32 pitch) {
|
||||
explicit VideoOutBufferObj(VideoOutBufferFormat pixel_format, u32 width, u32 height,
|
||||
bool is_tiled, bool is_neo, u32 pitch) {
|
||||
obj_params[PIXEL_FORMAT_PARAM] = static_cast<uint64_t>(pixel_format);
|
||||
obj_params[WIDTH_PARAM] = width;
|
||||
obj_params[HEIGHT_PARAM] = height;
|
||||
|
@ -35,4 +36,4 @@ class VideoOutBufferObj : public GPUObject {
|
|||
create_func_t getCreateFunc() const override;
|
||||
update_func_t getUpdateFunc() const override;
|
||||
};
|
||||
} // namespace GPU
|
||||
} // namespace GPU
|
||||
|
|
|
@ -17,7 +17,7 @@ int VideoOutCtx::Open() {
|
|||
int handle = -1;
|
||||
|
||||
if (!m_video_out_ctx.isOpened) {
|
||||
handle = 1; // positive return , should be more than 1 ?
|
||||
handle = 1; // positive return , should be more than 1 ?
|
||||
}
|
||||
|
||||
m_video_out_ctx.isOpened = true;
|
||||
|
@ -35,7 +35,7 @@ void VideoOutCtx::Close(s32 handle) {
|
|||
m_video_out_ctx.isOpened = false;
|
||||
|
||||
if (m_video_out_ctx.m_flip_evtEq.size() > 0) {
|
||||
BREAKPOINT(); // we need to clear all events if they have been created
|
||||
BREAKPOINT(); // we need to clear all events if they have been created
|
||||
}
|
||||
|
||||
m_video_out_ctx.m_flip_rate = 0;
|
||||
|
@ -57,7 +57,7 @@ VideoConfigInternal* VideoOutCtx::getCtx(int handle) {
|
|||
if (handle != 1) [[unlikely]] {
|
||||
return nullptr;
|
||||
}
|
||||
return &m_video_out_ctx; // assuming that it's the only ctx TODO check if we need more
|
||||
return &m_video_out_ctx; // assuming that it's the only ctx TODO check if we need more
|
||||
}
|
||||
|
||||
void FlipQueue::getFlipStatus(VideoConfigInternal* cfg, SceVideoOutFlipStatus* out) {
|
||||
|
@ -91,11 +91,12 @@ bool FlipQueue::submitFlip(VideoConfigInternal* cfg, s32 index, s64 flip_arg) {
|
|||
bool FlipQueue::flip(u32 micros) {
|
||||
const auto request = [&]() -> Request* {
|
||||
std::unique_lock lock{m_mutex};
|
||||
m_submit_cond.wait_for(lock, std::chrono::microseconds(micros), [&] { return !m_requests.empty(); });
|
||||
m_submit_cond.wait_for(lock, std::chrono::microseconds(micros),
|
||||
[&] { return !m_requests.empty(); });
|
||||
if (m_requests.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
return &m_requests.at(0); // Process first request
|
||||
return &m_requests.at(0); // Process first request
|
||||
}();
|
||||
|
||||
if (!request) {
|
||||
|
@ -111,7 +112,8 @@ bool FlipQueue::flip(u32 micros) {
|
|||
std::scoped_lock cfg_lock{request->cfg->m_mutex};
|
||||
for (auto& flip_eq : request->cfg->m_flip_evtEq) {
|
||||
if (flip_eq != nullptr) {
|
||||
flip_eq->triggerEvent(SCE_VIDEO_OUT_EVENT_FLIP, Core::Kernel::EVFILT_VIDEO_OUT, reinterpret_cast<void*>(request->flip_arg));
|
||||
flip_eq->triggerEvent(SCE_VIDEO_OUT_EVENT_FLIP, Core::Kernel::EVFILT_VIDEO_OUT,
|
||||
reinterpret_cast<void*>(request->flip_arg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <core/PS4/HLE/Graphics/video_out.h>
|
||||
#include <core/PS4/HLE/Graphics/graphics_ctx.h>
|
||||
#include <core/PS4/HLE/Graphics/video_out.h>
|
||||
#include <emulator.h>
|
||||
|
||||
using namespace HLE::Libs::Graphics::VideoOut;
|
||||
|
@ -32,14 +32,15 @@ struct VideoConfigInternal {
|
|||
};
|
||||
|
||||
class FlipQueue {
|
||||
public:
|
||||
public:
|
||||
FlipQueue() {}
|
||||
virtual ~FlipQueue() {}
|
||||
|
||||
void getFlipStatus(VideoConfigInternal* cfg, SceVideoOutFlipStatus* out);
|
||||
bool submitFlip(VideoConfigInternal* cfg, s32 index, s64 flip_arg);
|
||||
bool flip(u32 micros);
|
||||
private:
|
||||
|
||||
private:
|
||||
struct Request {
|
||||
VideoConfigInternal* cfg;
|
||||
int index;
|
||||
|
@ -55,24 +56,27 @@ class FlipQueue {
|
|||
|
||||
class VideoOutCtx {
|
||||
|
||||
public:
|
||||
public:
|
||||
VideoOutCtx() {}
|
||||
virtual ~VideoOutCtx() {}
|
||||
void Init(u32 width, u32 height);
|
||||
int Open();
|
||||
void Close(s32 handle);
|
||||
VideoConfigInternal* getCtx(int handle);
|
||||
FlipQueue& getFlipQueue() { return m_flip_queue; }
|
||||
FlipQueue& getFlipQueue() {
|
||||
return m_flip_queue;
|
||||
}
|
||||
HLE::Libs::Graphics::GraphicCtx* getGraphicCtx() {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
|
||||
|
||||
if (!m_graphic_ctx) {
|
||||
m_graphic_ctx = Emu::getGraphicCtx();
|
||||
}
|
||||
|
||||
return m_graphic_ctx;
|
||||
}
|
||||
private:
|
||||
|
||||
private:
|
||||
std::mutex m_mutex;
|
||||
VideoConfigInternal m_video_out_ctx;
|
||||
FlipQueue m_flip_queue;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
#include "common/types.h"
|
||||
|
||||
namespace HLE::Libs::Graphics {
|
||||
|
||||
|
@ -31,7 +31,7 @@ struct GraphicCtx {
|
|||
VkInstance m_instance = nullptr;
|
||||
VkPhysicalDevice m_physical_device = nullptr;
|
||||
VkDevice m_device = nullptr;
|
||||
VulkanQueueInfo queues[11]; // VULKAN_QUEUES_NUM
|
||||
VulkanQueueInfo queues[11]; // VULKAN_QUEUES_NUM
|
||||
};
|
||||
|
||||
enum class VulkanImageType { Unknown, VideoOut };
|
||||
|
@ -71,4 +71,4 @@ struct VideoOutVulkanImage : public VulkanImage {
|
|||
VideoOutVulkanImage() : VulkanImage(VulkanImageType::VideoOut) {}
|
||||
};
|
||||
|
||||
} // namespace HLE::Libs::Graphics
|
||||
} // namespace HLE::Libs::Graphics
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "graphics_render.h"
|
||||
#include <fmt/core.h>
|
||||
#include "common/singleton.h"
|
||||
#include "emulator.h"
|
||||
#include "graphics_render.h"
|
||||
|
||||
static thread_local GPU::CommandPool g_command_pool;
|
||||
|
||||
|
@ -155,7 +155,8 @@ void GPU::CommandPool::createPool(int id) {
|
|||
alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
alloc_info.commandBufferCount = m_pool[id].buffers_count;
|
||||
|
||||
if (vkAllocateCommandBuffers(ctx->m_device, &alloc_info, m_pool[id].buffers.data()) != VK_SUCCESS) {
|
||||
if (vkAllocateCommandBuffers(ctx->m_device, &alloc_info, m_pool[id].buffers.data()) !=
|
||||
VK_SUCCESS) {
|
||||
fmt::print("Can't allocate command buffers\n");
|
||||
std::exit(0);
|
||||
}
|
||||
|
@ -168,7 +169,8 @@ void GPU::CommandPool::createPool(int id) {
|
|||
fence_info.pNext = nullptr;
|
||||
fence_info.flags = 0;
|
||||
|
||||
if (vkCreateFence(ctx->m_device, &fence_info, nullptr, &m_pool[id].fences[i]) != VK_SUCCESS) {
|
||||
if (vkCreateFence(ctx->m_device, &fence_info, nullptr, &m_pool[id].fences[i]) !=
|
||||
VK_SUCCESS) {
|
||||
fmt::print("Can't create fence\n");
|
||||
std::exit(0);
|
||||
}
|
||||
|
@ -178,7 +180,8 @@ void GPU::CommandPool::createPool(int id) {
|
|||
semaphore_info.pNext = nullptr;
|
||||
semaphore_info.flags = 0;
|
||||
|
||||
if (vkCreateSemaphore(ctx->m_device, &semaphore_info, nullptr, &m_pool[id].semaphores[i]) != VK_SUCCESS) {
|
||||
if (vkCreateSemaphore(ctx->m_device, &semaphore_info, nullptr, &m_pool[id].semaphores[i]) !=
|
||||
VK_SUCCESS) {
|
||||
fmt::print("Can't create semas\n");
|
||||
std::exit(0);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
namespace GPU {
|
||||
|
||||
class CommandPool {
|
||||
public:
|
||||
public:
|
||||
CommandPool() = default;
|
||||
~CommandPool() {}
|
||||
|
||||
|
@ -17,16 +17,20 @@ class CommandPool {
|
|||
return &m_pool[id];
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
void createPool(int id);
|
||||
void deleteAllPool();
|
||||
|
||||
std::array<HLE::Libs::Graphics::VulkanCommandPool, 11> m_pool{};
|
||||
};
|
||||
class CommandBuffer {
|
||||
public:
|
||||
explicit CommandBuffer(int queue) : m_queue(queue) { allocateBuffer(); }
|
||||
virtual ~CommandBuffer() { freeBuffer(); }
|
||||
public:
|
||||
explicit CommandBuffer(int queue) : m_queue(queue) {
|
||||
allocateBuffer();
|
||||
}
|
||||
virtual ~CommandBuffer() {
|
||||
freeBuffer();
|
||||
}
|
||||
void allocateBuffer();
|
||||
void freeBuffer();
|
||||
void waitForFence();
|
||||
|
@ -34,9 +38,14 @@ class CommandBuffer {
|
|||
void end() const;
|
||||
void executeWithSemaphore();
|
||||
void execute();
|
||||
u32 getIndex() const { return m_index; }
|
||||
HLE::Libs::Graphics::VulkanCommandPool* getPool() { return m_pool; }
|
||||
private:
|
||||
u32 getIndex() const {
|
||||
return m_index;
|
||||
}
|
||||
HLE::Libs::Graphics::VulkanCommandPool* getPool() {
|
||||
return m_pool;
|
||||
}
|
||||
|
||||
private:
|
||||
int m_queue = -1;
|
||||
u32 m_index = static_cast<u32>(-1);
|
||||
HLE::Libs::Graphics::VulkanCommandPool* m_pool = nullptr;
|
||||
|
@ -44,22 +53,26 @@ class CommandBuffer {
|
|||
};
|
||||
|
||||
class Framebuffer {
|
||||
public:
|
||||
public:
|
||||
Framebuffer() {}
|
||||
virtual ~Framebuffer() {}
|
||||
};
|
||||
class RenderCtx {
|
||||
public:
|
||||
public:
|
||||
RenderCtx() = default;
|
||||
|
||||
virtual ~RenderCtx() {}
|
||||
void setGraphicCtx(HLE::Libs::Graphics::GraphicCtx* ctx) { m_graphic_ctx = ctx; }
|
||||
HLE::Libs::Graphics::GraphicCtx* getGraphicCtx() { return m_graphic_ctx; }
|
||||
void setGraphicCtx(HLE::Libs::Graphics::GraphicCtx* ctx) {
|
||||
m_graphic_ctx = ctx;
|
||||
}
|
||||
HLE::Libs::Graphics::GraphicCtx* getGraphicCtx() {
|
||||
return m_graphic_ctx;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
Framebuffer m_framebuffer{};
|
||||
HLE::Libs::Graphics::GraphicCtx* m_graphic_ctx = nullptr;
|
||||
};
|
||||
|
||||
void renderCreateCtx();
|
||||
}; // namespace GPU
|
||||
}; // namespace GPU
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <magic_enum.hpp>
|
||||
#include "common/log.h"
|
||||
#include "Objects/video_out_ctx.h"
|
||||
#include "Util/config.h"
|
||||
#include "common/debug.h"
|
||||
#include "core/loader/symbols_resolver.h"
|
||||
#include "core/PS4/HLE/Graphics/video_out.h"
|
||||
#include "common/log.h"
|
||||
#include "common/singleton.h"
|
||||
#include "core/PS4/GPU/gpu_memory.h"
|
||||
#include "core/PS4/GPU/video_out_buffer.h"
|
||||
#include "core/PS4/HLE/Graphics/video_out.h"
|
||||
#include "core/hle/error_codes.h"
|
||||
#include "core/hle/libraries/libscegnmdriver/libscegnmdriver.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
#include "core/hle/libraries/libscegnmdriver/libscegnmdriver.h"
|
||||
#include "core/hle/libraries/libuserservice/usr_mng_codes.h"
|
||||
#include "Util/config.h"
|
||||
#include "Objects/video_out_ctx.h"
|
||||
#include "common/singleton.h"
|
||||
#include "core/loader/symbols_resolver.h"
|
||||
#include "emulator.h"
|
||||
#include "graphics_render.h"
|
||||
|
||||
namespace HLE::Libs::Graphics::VideoOut {
|
||||
|
||||
constexpr bool log_file_videoout = true; // disable it to disable logging
|
||||
constexpr bool log_file_videoout = true; // disable it to disable logging
|
||||
|
||||
void videoOutInit(u32 width, u32 height) {
|
||||
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance();
|
||||
|
@ -33,19 +33,28 @@ bool videoOutFlip(u32 micros) {
|
|||
|
||||
std::string getPixelFormatString(s32 format) {
|
||||
switch (format) {
|
||||
case SCE_VIDEO_OUT_PIXEL_FORMAT_A8R8G8B8_SRGB: return "PIXEL_FORMAT_A8R8G8B8_SRGB";
|
||||
case SCE_VIDEO_OUT_PIXEL_FORMAT_A8B8G8R8_SRGB: return "PIXEL_FORMAT_A8B8G8R8_SRGB";
|
||||
case SCE_VIDEO_OUT_PIXEL_FORMAT_A2R10G10B10: return "PIXEL_FORMAT_A2R10G10B10";
|
||||
case SCE_VIDEO_OUT_PIXEL_FORMAT_A2R10G10B10_SRGB: return "PIXEL_FORMAT_A2R10G10B10_SRGB";
|
||||
case SCE_VIDEO_OUT_PIXEL_FORMAT_A2R10G10B10_BT2020_PQ: return "PIXEL_FORMAT_A2R10G10B10_BT2020_PQ";
|
||||
case SCE_VIDEO_OUT_PIXEL_FORMAT_A16R16G16B16_FLOAT: return "PIXEL_FORMAT_A16R16G16B16_FLOAT";
|
||||
case SCE_VIDEO_OUT_PIXEL_FORMAT_YCBCR420_BT709: return "PIXEL_FORMAT_YCBCR420_BT709";
|
||||
default: return "Unknown pixel format";
|
||||
case SCE_VIDEO_OUT_PIXEL_FORMAT_A8R8G8B8_SRGB:
|
||||
return "PIXEL_FORMAT_A8R8G8B8_SRGB";
|
||||
case SCE_VIDEO_OUT_PIXEL_FORMAT_A8B8G8R8_SRGB:
|
||||
return "PIXEL_FORMAT_A8B8G8R8_SRGB";
|
||||
case SCE_VIDEO_OUT_PIXEL_FORMAT_A2R10G10B10:
|
||||
return "PIXEL_FORMAT_A2R10G10B10";
|
||||
case SCE_VIDEO_OUT_PIXEL_FORMAT_A2R10G10B10_SRGB:
|
||||
return "PIXEL_FORMAT_A2R10G10B10_SRGB";
|
||||
case SCE_VIDEO_OUT_PIXEL_FORMAT_A2R10G10B10_BT2020_PQ:
|
||||
return "PIXEL_FORMAT_A2R10G10B10_BT2020_PQ";
|
||||
case SCE_VIDEO_OUT_PIXEL_FORMAT_A16R16G16B16_FLOAT:
|
||||
return "PIXEL_FORMAT_A16R16G16B16_FLOAT";
|
||||
case SCE_VIDEO_OUT_PIXEL_FORMAT_YCBCR420_BT709:
|
||||
return "PIXEL_FORMAT_YCBCR420_BT709";
|
||||
default:
|
||||
return "Unknown pixel format";
|
||||
}
|
||||
}
|
||||
|
||||
void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(SceVideoOutBufferAttribute* attribute, u32 pixelFormat, u32 tilingMode, u32 aspectRatio, u32 width,
|
||||
u32 height, u32 pitchInPixel) {
|
||||
void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(SceVideoOutBufferAttribute* attribute,
|
||||
u32 pixelFormat, u32 tilingMode, u32 aspectRatio,
|
||||
u32 width, u32 height, u32 pitchInPixel) {
|
||||
PRINT_FUNCTION_NAME();
|
||||
|
||||
auto tileMode = magic_enum::enum_cast<SceVideoOutTilingMode>(tilingMode);
|
||||
|
@ -81,11 +90,13 @@ static void flip_trigger_event_func(Core::Kernel::EqueueEvent* event, void* trig
|
|||
event->event.data = reinterpret_cast<intptr_t>(trigger_data);
|
||||
}
|
||||
|
||||
static void flip_delete_event_func(Core::Kernel::SceKernelEqueue eq, Core::Kernel::EqueueEvent* event) {
|
||||
BREAKPOINT(); // TODO
|
||||
static void flip_delete_event_func(Core::Kernel::SceKernelEqueue eq,
|
||||
Core::Kernel::EqueueEvent* event) {
|
||||
BREAKPOINT(); // TODO
|
||||
}
|
||||
|
||||
s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(Core::Kernel::SceKernelEqueue eq, s32 handle, void* udata) {
|
||||
s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(Core::Kernel::SceKernelEqueue eq, s32 handle,
|
||||
void* udata) {
|
||||
PRINT_FUNCTION_NAME();
|
||||
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance();
|
||||
|
||||
|
@ -119,13 +130,14 @@ s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(Core::Kernel::SceKernelEqueue eq, s32 h
|
|||
return result;
|
||||
}
|
||||
|
||||
s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* const* addresses, s32 bufferNum,
|
||||
s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* const* addresses,
|
||||
s32 bufferNum,
|
||||
const SceVideoOutBufferAttribute* attribute) {
|
||||
PRINT_FUNCTION_NAME();
|
||||
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance();
|
||||
auto* ctx = videoOut->getCtx(handle);
|
||||
|
||||
if (handle == 1) { // main port
|
||||
if (handle == 1) { // main port
|
||||
if (startIndex < 0 || startIndex > 15) {
|
||||
LOG_TRACE_IF(log_file_videoout, "invalid startIndex = {}\n", startIndex);
|
||||
return SCE_VIDEO_OUT_ERROR_INVALID_VALUE;
|
||||
|
@ -168,7 +180,7 @@ s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* co
|
|||
GPU::renderCreateCtx();
|
||||
|
||||
// try to calculate buffer size
|
||||
u64 buffer_size = 0; // still calculation is probably partial or wrong :D
|
||||
u64 buffer_size = 0; // still calculation is probably partial or wrong :D
|
||||
if (attribute->tilingMode == 0) {
|
||||
buffer_size = 1920 * 1088 * 4;
|
||||
} else {
|
||||
|
@ -193,7 +205,9 @@ s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* co
|
|||
format = GPU::VideoOutBufferFormat::R8G8B8A8Srgb;
|
||||
}
|
||||
|
||||
GPU::VideoOutBufferObj buffer_info(format, attribute->width, attribute->height, attribute->tilingMode == 0, Config::isNeoMode(), buffer_pitch);
|
||||
GPU::VideoOutBufferObj buffer_info(format, attribute->width, attribute->height,
|
||||
attribute->tilingMode == 0, Config::isNeoMode(),
|
||||
buffer_pitch);
|
||||
|
||||
for (int i = 0; i < bufferNum; i++) {
|
||||
if (ctx->buffers[i + startIndex].buffer != nullptr) {
|
||||
|
@ -205,10 +219,13 @@ s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* co
|
|||
ctx->buffers[i + startIndex].buffer = addresses[i];
|
||||
ctx->buffers[i + startIndex].buffer_size = buffer_size;
|
||||
ctx->buffers[i + startIndex].buffer_pitch = buffer_pitch;
|
||||
ctx->buffers[i + startIndex].buffer_render = static_cast<Graphics::VideoOutVulkanImage*>(
|
||||
GPU::memoryCreateObj(0, videoOut->getGraphicCtx(), nullptr, reinterpret_cast<uint64_t>(addresses[i]), buffer_size, buffer_info));
|
||||
ctx->buffers[i + startIndex].buffer_render =
|
||||
static_cast<Graphics::VideoOutVulkanImage*>(GPU::memoryCreateObj(
|
||||
0, videoOut->getGraphicCtx(), nullptr, reinterpret_cast<uint64_t>(addresses[i]),
|
||||
buffer_size, buffer_info));
|
||||
|
||||
LOG_INFO_IF(log_file_videoout, "buffers[{}] = {:#x}\n", i + startIndex, reinterpret_cast<u64>(addresses[i]));
|
||||
LOG_INFO_IF(log_file_videoout, "buffers[{}] = {:#x}\n", i + startIndex,
|
||||
reinterpret_cast<u64>(addresses[i]));
|
||||
}
|
||||
|
||||
return registration_index;
|
||||
|
@ -234,14 +251,16 @@ s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode
|
|||
auto* ctx = videoOut->getCtx(handle);
|
||||
|
||||
if (flipMode != 1) {
|
||||
// BREAKPOINT(); // only flipmode==1 is supported
|
||||
LOG_TRACE_IF(log_file_videoout, "sceVideoOutSubmitFlip flipmode {}\n", bufferIndex);//openBOR needs 2 but seems to work
|
||||
// BREAKPOINT(); // only flipmode==1 is supported
|
||||
LOG_TRACE_IF(log_file_videoout, "sceVideoOutSubmitFlip flipmode {}\n",
|
||||
bufferIndex); // openBOR needs 2 but seems to work
|
||||
}
|
||||
if (bufferIndex == -1) {
|
||||
BREAKPOINT(); // blank output not supported
|
||||
BREAKPOINT(); // blank output not supported
|
||||
}
|
||||
if (bufferIndex < -1 || bufferIndex > 15) {
|
||||
LOG_TRACE_IF(log_file_videoout, "sceVideoOutSubmitFlip invalid bufferIndex {}\n", bufferIndex);
|
||||
LOG_TRACE_IF(log_file_videoout, "sceVideoOutSubmitFlip invalid bufferIndex {}\n",
|
||||
bufferIndex);
|
||||
return SCE_VIDEO_OUT_ERROR_INVALID_INDEX;
|
||||
}
|
||||
LOG_INFO_IF(log_file_videoout, "bufferIndex = {}\n", bufferIndex);
|
||||
|
@ -252,7 +271,8 @@ s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode
|
|||
LOG_TRACE_IF(log_file_videoout, "sceVideoOutSubmitFlip flip queue is full\n");
|
||||
return SCE_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL;
|
||||
}
|
||||
Core::Libraries::LibSceGnmDriver::sceGnmFlushGarlic(); // hackish should be done that neccesary for niko's homebrew
|
||||
Core::Libraries::LibSceGnmDriver::sceGnmFlushGarlic(); // hackish should be done that neccesary
|
||||
// for niko's homebrew
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
|
@ -280,7 +300,8 @@ s32 PS4_SYSV_ABI sceVideoOutGetResolutionStatus(s32 handle, SceVideoOutResolutio
|
|||
return SCE_OK;
|
||||
}
|
||||
|
||||
s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param) {
|
||||
s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index,
|
||||
const void* param) {
|
||||
PRINT_FUNCTION_NAME();
|
||||
if (userId != SCE_USER_SERVICE_USER_ID_SYSTEM && userId != 0) {
|
||||
BREAKPOINT();
|
||||
|
@ -300,7 +321,7 @@ s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 i
|
|||
|
||||
if (handle < 0) {
|
||||
LOG_TRACE_IF(log_file_videoout, "sceVideoOutOpen all available handles are open\n");
|
||||
return SCE_VIDEO_OUT_ERROR_RESOURCE_BUSY; // it is alreadyOpened
|
||||
return SCE_VIDEO_OUT_ERROR_RESOURCE_BUSY; // it is alreadyOpened
|
||||
}
|
||||
|
||||
return handle;
|
||||
|
@ -319,25 +340,38 @@ s32 PS4_SYSV_ABI sceVideoOutUnregisterBuffers(s32 handle, s32 attributeIndex) {
|
|||
|
||||
void videoOutRegisterLib(Core::Loader::SymbolsResolver* sym) {
|
||||
using namespace Core;
|
||||
LIB_FUNCTION("SbU3dwp80lQ", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutGetFlipStatus);
|
||||
LIB_FUNCTION("SbU3dwp80lQ", "libSceVideoOut", 1, "libSceVideoOut", 0, 0,
|
||||
sceVideoOutGetFlipStatus);
|
||||
LIB_FUNCTION("U46NwOiJpys", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutSubmitFlip);
|
||||
LIB_FUNCTION("w3BY+tAEiQY", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutRegisterBuffers);
|
||||
LIB_FUNCTION("HXzjK9yI30k", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutAddFlipEvent);
|
||||
LIB_FUNCTION("CBiu4mCE1DA", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutSetFlipRate);
|
||||
LIB_FUNCTION("i6-sR91Wt-4", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutSetBufferAttribute);
|
||||
LIB_FUNCTION("6kPnj51T62Y", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutGetResolutionStatus);
|
||||
LIB_FUNCTION("w3BY+tAEiQY", "libSceVideoOut", 1, "libSceVideoOut", 0, 0,
|
||||
sceVideoOutRegisterBuffers);
|
||||
LIB_FUNCTION("HXzjK9yI30k", "libSceVideoOut", 1, "libSceVideoOut", 0, 0,
|
||||
sceVideoOutAddFlipEvent);
|
||||
LIB_FUNCTION("CBiu4mCE1DA", "libSceVideoOut", 1, "libSceVideoOut", 0, 0,
|
||||
sceVideoOutSetFlipRate);
|
||||
LIB_FUNCTION("i6-sR91Wt-4", "libSceVideoOut", 1, "libSceVideoOut", 0, 0,
|
||||
sceVideoOutSetBufferAttribute);
|
||||
LIB_FUNCTION("6kPnj51T62Y", "libSceVideoOut", 1, "libSceVideoOut", 0, 0,
|
||||
sceVideoOutGetResolutionStatus);
|
||||
LIB_FUNCTION("Up36PTk687E", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutOpen);
|
||||
LIB_FUNCTION("zgXifHT9ErY", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutIsFlipPending);
|
||||
LIB_FUNCTION("N5KDtkIjjJ4", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutUnregisterBuffers);
|
||||
LIB_FUNCTION("zgXifHT9ErY", "libSceVideoOut", 1, "libSceVideoOut", 0, 0,
|
||||
sceVideoOutIsFlipPending);
|
||||
LIB_FUNCTION("N5KDtkIjjJ4", "libSceVideoOut", 1, "libSceVideoOut", 0, 0,
|
||||
sceVideoOutUnregisterBuffers);
|
||||
LIB_FUNCTION("uquVH4-Du78", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutClose);
|
||||
|
||||
// openOrbis appears to have libSceVideoOut_v1 module libSceVideoOut_v1.1
|
||||
LIB_FUNCTION("Up36PTk687E", "libSceVideoOut", 1, "libSceVideoOut", 1, 1, sceVideoOutOpen);
|
||||
LIB_FUNCTION("CBiu4mCE1DA", "libSceVideoOut", 1, "libSceVideoOut", 1, 1, sceVideoOutSetFlipRate);
|
||||
LIB_FUNCTION("HXzjK9yI30k", "libSceVideoOut", 1, "libSceVideoOut", 1, 1, sceVideoOutAddFlipEvent);
|
||||
LIB_FUNCTION("i6-sR91Wt-4", "libSceVideoOut", 1, "libSceVideoOut", 1, 1, sceVideoOutSetBufferAttribute);
|
||||
LIB_FUNCTION("w3BY+tAEiQY", "libSceVideoOut", 1, "libSceVideoOut", 1, 1, sceVideoOutRegisterBuffers);
|
||||
LIB_FUNCTION("CBiu4mCE1DA", "libSceVideoOut", 1, "libSceVideoOut", 1, 1,
|
||||
sceVideoOutSetFlipRate);
|
||||
LIB_FUNCTION("HXzjK9yI30k", "libSceVideoOut", 1, "libSceVideoOut", 1, 1,
|
||||
sceVideoOutAddFlipEvent);
|
||||
LIB_FUNCTION("i6-sR91Wt-4", "libSceVideoOut", 1, "libSceVideoOut", 1, 1,
|
||||
sceVideoOutSetBufferAttribute);
|
||||
LIB_FUNCTION("w3BY+tAEiQY", "libSceVideoOut", 1, "libSceVideoOut", 1, 1,
|
||||
sceVideoOutRegisterBuffers);
|
||||
LIB_FUNCTION("U46NwOiJpys", "libSceVideoOut", 1, "libSceVideoOut", 1, 1, sceVideoOutSubmitFlip);
|
||||
LIB_FUNCTION("SbU3dwp80lQ", "libSceVideoOut", 1, "libSceVideoOut", 1, 1, sceVideoOutGetFlipStatus);
|
||||
LIB_FUNCTION("SbU3dwp80lQ", "libSceVideoOut", 1, "libSceVideoOut", 1, 1,
|
||||
sceVideoOutGetFlipStatus);
|
||||
}
|
||||
} // namespace HLE::Libs::Graphics::VideoOut
|
||||
} // namespace HLE::Libs::Graphics::VideoOut
|
||||
|
|
|
@ -9,12 +9,12 @@ class SymbolsResolver;
|
|||
|
||||
namespace HLE::Libs::Graphics::VideoOut {
|
||||
|
||||
using SceUserServiceUserId = s32; // TODO move it to proper place
|
||||
using SceUserServiceUserId = s32; // TODO move it to proper place
|
||||
|
||||
// SceVideoOutBusType
|
||||
constexpr int SCE_VIDEO_OUT_BUS_TYPE_MAIN = 0; // Main output
|
||||
constexpr int SCE_VIDEO_OUT_BUS_TYPE_AUX_SOCIAL_SCREEN = 5; // Aux output for social
|
||||
constexpr int SCE_VIDEO_OUT_BUS_TYPE_AUX_GAME_LIVE_STREAMING = 6; // Aux output for screaming
|
||||
constexpr int SCE_VIDEO_OUT_BUS_TYPE_MAIN = 0; // Main output
|
||||
constexpr int SCE_VIDEO_OUT_BUS_TYPE_AUX_SOCIAL_SCREEN = 5; // Aux output for social
|
||||
constexpr int SCE_VIDEO_OUT_BUS_TYPE_AUX_GAME_LIVE_STREAMING = 6; // Aux output for screaming
|
||||
|
||||
// SceVideoOutRefreshRate
|
||||
constexpr int SCE_VIDEO_OUT_REFRESH_RATE_UNKNOWN = 0;
|
||||
|
@ -37,9 +37,16 @@ constexpr int SCE_VIDEO_OUT_BUFFER_ATTRIBUTE_OPTION_NONE = 0;
|
|||
constexpr int SCE_VIDEO_OUT_BUFFER_ATTRIBUTE_OPTION_VR = 7;
|
||||
constexpr int SCE_VIDEO_OUT_BUFFER_ATTRIBUTE_OPTION_STRICT_COLORIMETRY = 8;
|
||||
|
||||
enum SceVideoOutEventId : s16 { SCE_VIDEO_OUT_EVENT_FLIP = 0, SCE_VIDEO_OUT_EVENT_VBLANK = 1, SCE_VIDEO_OUT_EVENT_PRE_VBLANK_START = 2 };
|
||||
enum SceVideoOutEventId : s16 {
|
||||
SCE_VIDEO_OUT_EVENT_FLIP = 0,
|
||||
SCE_VIDEO_OUT_EVENT_VBLANK = 1,
|
||||
SCE_VIDEO_OUT_EVENT_PRE_VBLANK_START = 2
|
||||
};
|
||||
|
||||
enum SceVideoOutTilingMode : s32 { SCE_VIDEO_OUT_TILING_MODE_TILE = 0, SCE_VIDEO_OUT_TILING_MODE_LINEAR = 1 };
|
||||
enum SceVideoOutTilingMode : s32 {
|
||||
SCE_VIDEO_OUT_TILING_MODE_TILE = 0,
|
||||
SCE_VIDEO_OUT_TILING_MODE_LINEAR = 1
|
||||
};
|
||||
|
||||
enum AspectRatioMode : s32 { SCE_VIDEO_OUT_ASPECT_RATIO_16_9 = 0 };
|
||||
|
||||
|
@ -101,17 +108,20 @@ std::string getPixelFormatString(s32 format);
|
|||
void videoOutRegisterLib(Core::Loader::SymbolsResolver* sym);
|
||||
bool videoOutFlip(u32 micros);
|
||||
|
||||
void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(SceVideoOutBufferAttribute* attribute, u32 pixelFormat, u32 tilingMode, u32 aspectRatio, u32 width,
|
||||
u32 height, u32 pitchInPixel);
|
||||
void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(SceVideoOutBufferAttribute* attribute,
|
||||
u32 pixelFormat, u32 tilingMode, u32 aspectRatio,
|
||||
u32 width, u32 height, u32 pitchInPixel);
|
||||
s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(Core::Kernel::SceKernelEqueue eq, s32 handle, void* udata);
|
||||
s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* const* addresses, s32 bufferNum,
|
||||
s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* const* addresses,
|
||||
s32 bufferNum,
|
||||
const SceVideoOutBufferAttribute* attribute);
|
||||
s32 PS4_SYSV_ABI sceVideoOutSetFlipRate(s32 handle, s32 rate);
|
||||
s32 PS4_SYSV_ABI sceVideoOutIsFlipPending(s32 handle);
|
||||
s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode, s64 flipArg);
|
||||
s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, SceVideoOutFlipStatus* status);
|
||||
s32 PS4_SYSV_ABI sceVideoOutGetResolutionStatus(s32 handle, SceVideoOutResolutionStatus* status);
|
||||
s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param);
|
||||
s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index,
|
||||
const void* param);
|
||||
s32 PS4_SYSV_ABI sceVideoOutClose(s32 handle);
|
||||
|
||||
} // namespace HLE::Libs::Graphics::VideoOut
|
||||
|
|
|
@ -6,8 +6,7 @@ namespace Core::AeroLib {
|
|||
|
||||
// Use a direct table here + binary search as contents are static
|
||||
static constexpr NidEntry NIDS[] = {
|
||||
#define STUB(nid, name) \
|
||||
{ nid, #name },
|
||||
#define STUB(nid, name) {nid, #name},
|
||||
#include "aerolib.inl"
|
||||
#undef STUB
|
||||
};
|
||||
|
|
|
@ -5,16 +5,16 @@
|
|||
namespace Core::AeroLib {
|
||||
|
||||
// Helper to provide stub implementations for missing functions
|
||||
//
|
||||
//
|
||||
// This works by pre-compiling generic stub functions ("slots"), and then
|
||||
// on lookup, setting up the nid_entry they are matched with
|
||||
//
|
||||
//
|
||||
// If it runs out of stubs with name information, it will return
|
||||
// a default implemetnation without function name details
|
||||
|
||||
// Up to 512, larger values lead to more resolve stub slots
|
||||
// and to longer compile / CI times
|
||||
//
|
||||
//
|
||||
// Must match STUBS_LIST define
|
||||
constexpr u32 MAX_STUBS = 128;
|
||||
|
||||
|
@ -24,11 +24,11 @@ u64 UnresolvedStub() {
|
|||
}
|
||||
|
||||
static u64 UnknownStub() {
|
||||
LOG_ERROR("Stub: Unknown (nid: Unknown) called, returning zero to {}\n", __builtin_return_address(0));
|
||||
LOG_ERROR("Stub: Unknown (nid: Unknown) called, returning zero to {}\n",
|
||||
__builtin_return_address(0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const NidEntry* stub_nids[MAX_STUBS];
|
||||
static std::string stub_nids_unknown[MAX_STUBS];
|
||||
|
||||
|
@ -36,17 +36,18 @@ template <int stub_index>
|
|||
static u64 CommonStub() {
|
||||
auto entry = stub_nids[stub_index];
|
||||
if (entry) {
|
||||
LOG_ERROR("Stub: {} (nid: {}) called, returning zero to {}\n", entry->name, entry->nid, __builtin_return_address(0));
|
||||
LOG_ERROR("Stub: {} (nid: {}) called, returning zero to {}\n", entry->name, entry->nid,
|
||||
__builtin_return_address(0));
|
||||
} else {
|
||||
LOG_ERROR("Stub: Unknown (nid: {}) called, returning zero to {}\n", stub_nids_unknown[stub_index], __builtin_return_address(0));
|
||||
LOG_ERROR("Stub: Unknown (nid: {}) called, returning zero to {}\n",
|
||||
stub_nids_unknown[stub_index], __builtin_return_address(0));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u32 UsedStubEntries;
|
||||
|
||||
#define XREP_1(x) \
|
||||
&CommonStub<x>,
|
||||
#define XREP_1(x) &CommonStub<x>,
|
||||
|
||||
#define XREP_2(x) XREP_1(x) XREP_1(x + 1)
|
||||
#define XREP_4(x) XREP_2(x) XREP_2(x + 2)
|
||||
|
@ -60,9 +61,7 @@ static u32 UsedStubEntries;
|
|||
|
||||
#define STUBS_LIST XREP_128(0)
|
||||
|
||||
static u64 (*stub_handlers[MAX_STUBS])() = {
|
||||
STUBS_LIST
|
||||
};
|
||||
static u64 (*stub_handlers[MAX_STUBS])() = {STUBS_LIST};
|
||||
|
||||
u64 GetStub(const char* nid) {
|
||||
if (UsedStubEntries >= MAX_STUBS) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Core::FileSys {
|
||||
|
||||
constexpr int RESERVED_HANDLES = 3; // First 3 handles are stdin,stdout,stderr
|
||||
constexpr int RESERVED_HANDLES = 3; // First 3 handles are stdin,stdout,stderr
|
||||
|
||||
void MntPoints::mount(const std::string& host_folder, const std::string& guest_folder) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
|
@ -15,7 +15,7 @@ void MntPoints::mount(const std::string& host_folder, const std::string& guest_f
|
|||
|
||||
m_mnt_pairs.push_back(pair);
|
||||
}
|
||||
void MntPoints::unmount(const std::string& path) {} // TODO!
|
||||
void MntPoints::unmount(const std::string& path) {} // TODO!
|
||||
void MntPoints::unmountAll() {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_mnt_pairs.clear();
|
||||
|
@ -40,10 +40,10 @@ std::string MntPoints::getHostFile(const std::string& guest_file) {
|
|||
std::scoped_lock lock{m_mutex};
|
||||
|
||||
for (auto& pair : m_mnt_pairs) {
|
||||
//horrible code but it works :D
|
||||
// horrible code but it works :D
|
||||
int find = guest_file.find(pair.guest_path);
|
||||
if (find == 0) {
|
||||
std::string npath = guest_file.substr(pair.guest_path.size(), guest_file.size()-1);
|
||||
std::string npath = guest_file.substr(pair.guest_path.size(), guest_file.size() - 1);
|
||||
std::replace(pair.host_path.begin(), pair.host_path.end(), '\\', '/');
|
||||
return pair.host_path + npath;
|
||||
}
|
||||
|
@ -88,4 +88,4 @@ File* HandleTable::getFile(const std::string& host_name) {
|
|||
}
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace Core::FileSys
|
||||
} // namespace Core::FileSys
|
|
@ -5,16 +5,16 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "common/fs_file.h"
|
||||
#include <common/io_file.h>
|
||||
#include "common/fs_file.h"
|
||||
|
||||
namespace Core::FileSys {
|
||||
|
||||
class MntPoints {
|
||||
public:
|
||||
public:
|
||||
struct MntPair {
|
||||
std::string host_path;
|
||||
std::string guest_path; // e.g /app0/
|
||||
std::string guest_path; // e.g /app0/
|
||||
};
|
||||
|
||||
MntPoints() = default;
|
||||
|
@ -25,7 +25,7 @@ class MntPoints {
|
|||
std::string getHostDirectory(const std::string& guest_directory);
|
||||
std::string getHostFile(const std::string& guest_file);
|
||||
|
||||
private:
|
||||
private:
|
||||
std::vector<MntPair> m_mnt_pairs;
|
||||
std::mutex m_mutex;
|
||||
};
|
||||
|
@ -36,12 +36,12 @@ struct File {
|
|||
std::string m_host_name;
|
||||
std::string m_guest_name;
|
||||
IOFile f;
|
||||
//std::vector<Common::FS::DirEntry> dirents;
|
||||
// std::vector<Common::FS::DirEntry> dirents;
|
||||
u32 dirents_index;
|
||||
std::mutex m_mutex;
|
||||
};
|
||||
class HandleTable {
|
||||
public:
|
||||
public:
|
||||
HandleTable() {}
|
||||
virtual ~HandleTable() {}
|
||||
int createHandle();
|
||||
|
@ -49,9 +49,9 @@ class HandleTable {
|
|||
File* getFile(int d);
|
||||
File* getFile(const std::string& host_name);
|
||||
|
||||
private:
|
||||
private:
|
||||
std::vector<File*> m_files;
|
||||
std::mutex m_mutex;
|
||||
};
|
||||
|
||||
} // namespace Core::FileSys
|
||||
} // namespace Core::FileSys
|
||||
|
|
|
@ -231,14 +231,14 @@ constexpr int SCE_KERNEL_ERROR_ESTART = 0x80020064;
|
|||
constexpr int SCE_KERNEL_ERROR_ESTOP = 0x80020065;
|
||||
|
||||
// videoOut
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_VALUE = 0x80290001; // invalid argument
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_ADDRESS = 0x80290002; // invalid addresses
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_TILING_MODE = 0x80290007; // invalid tiling mode
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_ASPECT_RATIO = 0x80290008; // invalid aspect ration
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_RESOURCE_BUSY = 0x80290009; // already opened
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_INDEX = 0x8029000A; // invalid buffer index
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_HANDLE = 0x8029000B; // invalid handle
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE = 0x8029000C; // Invalid event queue
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_SLOT_OCCUPIED = 0x80290010; // slot already used
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL = 0x80290012; // flip queue is full
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_OPTION = 0x8029001A; // Invalid buffer attribute option
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_VALUE = 0x80290001; // invalid argument
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_ADDRESS = 0x80290002; // invalid addresses
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_TILING_MODE = 0x80290007; // invalid tiling mode
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_ASPECT_RATIO = 0x80290008; // invalid aspect ration
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_RESOURCE_BUSY = 0x80290009; // already opened
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_INDEX = 0x8029000A; // invalid buffer index
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_HANDLE = 0x8029000B; // invalid handle
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE = 0x8029000C; // Invalid event queue
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_SLOT_OCCUPIED = 0x80290010; // slot already used
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL = 0x80290012; // flip queue is full
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_OPTION = 0x8029001A; // Invalid buffer attribute option
|
||||
|
|
|
@ -15,7 +15,7 @@ int EqueueInternal::addEvent(const EqueueEvent& event) {
|
|||
m_events.push_back(event);
|
||||
|
||||
if (event.isTriggered) {
|
||||
BREAKPOINT(); // we don't support that either yet
|
||||
BREAKPOINT(); // we don't support that either yet
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -42,7 +42,7 @@ bool EqueueInternal::triggerEvent(u64 ident, s16 filter, void* trigger_data) {
|
|||
std::scoped_lock lock{m_mutex};
|
||||
|
||||
if (m_events.size() > 1) {
|
||||
BREAKPOINT(); // we currently support one event
|
||||
BREAKPOINT(); // we currently support one event
|
||||
}
|
||||
auto& event = m_events[0];
|
||||
|
||||
|
@ -61,7 +61,7 @@ int EqueueInternal::getTriggeredEvents(SceKernelEvent* ev, int num) {
|
|||
int ret = 0;
|
||||
|
||||
if (m_events.size() > 1) {
|
||||
BREAKPOINT(); // we currently support one event
|
||||
BREAKPOINT(); // we currently support one event
|
||||
}
|
||||
auto& event = m_events[0];
|
||||
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <condition_variable>
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
constexpr s16 EVFILT_READ = -1;
|
||||
constexpr s16 EVFILT_WRITE = -2;
|
||||
constexpr s16 EVFILT_AIO = -3; // attached to aio requests
|
||||
constexpr s16 EVFILT_VNODE = -4; // attached to vnodes
|
||||
constexpr s16 EVFILT_PROC = -5; // attached to struct proc
|
||||
constexpr s16 EVFILT_SIGNAL = -6; // attached to struct proc
|
||||
constexpr s16 EVFILT_TIMER = -7; // timers
|
||||
constexpr s16 EVFILT_FS = -9; // filesystem events
|
||||
constexpr s16 EVFILT_LIO = -10; // attached to lio requests
|
||||
constexpr s16 EVFILT_USER = -11; // User events
|
||||
constexpr s16 EVFILT_AIO = -3; // attached to aio requests
|
||||
constexpr s16 EVFILT_VNODE = -4; // attached to vnodes
|
||||
constexpr s16 EVFILT_PROC = -5; // attached to struct proc
|
||||
constexpr s16 EVFILT_SIGNAL = -6; // attached to struct proc
|
||||
constexpr s16 EVFILT_TIMER = -7; // timers
|
||||
constexpr s16 EVFILT_FS = -9; // filesystem events
|
||||
constexpr s16 EVFILT_LIO = -10; // attached to lio requests
|
||||
constexpr s16 EVFILT_USER = -11; // User events
|
||||
constexpr s16 EVFILT_POLLING = -12;
|
||||
constexpr s16 EVFILT_VIDEO_OUT = -13;
|
||||
constexpr s16 EVFILT_GRAPHICS_CORE = -14;
|
||||
|
@ -61,17 +61,20 @@ struct EqueueEvent {
|
|||
};
|
||||
|
||||
class EqueueInternal {
|
||||
public:
|
||||
public:
|
||||
EqueueInternal() = default;
|
||||
virtual ~EqueueInternal();
|
||||
void setName(const std::string& m_name) { this->m_name = m_name; }
|
||||
void setName(const std::string& m_name) {
|
||||
this->m_name = m_name;
|
||||
}
|
||||
int addEvent(const EqueueEvent& event);
|
||||
int waitForEvents(SceKernelEvent* ev, int num, u32 micros);
|
||||
bool triggerEvent(u64 ident, s16 filter, void* trigger_data);
|
||||
int getTriggeredEvents(SceKernelEvent* ev, int num);
|
||||
private:
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
std::mutex m_mutex;
|
||||
std::mutex m_mutex;
|
||||
std::vector<EqueueEvent> m_events;
|
||||
std::condition_variable m_cond;
|
||||
};
|
||||
|
|
|
@ -6,8 +6,8 @@ static u64 AlignUp(u64 pos, u64 align) {
|
|||
return (align != 0 ? (pos + (align - 1)) & ~(align - 1) : pos);
|
||||
}
|
||||
|
||||
bool PhysicalMemory::Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignment,
|
||||
u64* physAddrOut, int memoryType) {
|
||||
bool PhysicalMemory::Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignment, u64* physAddrOut,
|
||||
int memoryType) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
u64 find_free_pos = 0;
|
||||
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
#include <vector>
|
||||
|
||||
#include "common/types.h"
|
||||
#include "core/virtual_memory.h"
|
||||
#include "core/PS4/GPU/gpu_memory.h"
|
||||
#include "core/virtual_memory.h"
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
class PhysicalMemory {
|
||||
public:
|
||||
public:
|
||||
struct AllocatedBlock {
|
||||
u64 start_addr;
|
||||
u64 size;
|
||||
|
@ -24,11 +24,13 @@ class PhysicalMemory {
|
|||
PhysicalMemory() {}
|
||||
virtual ~PhysicalMemory() {}
|
||||
|
||||
public:
|
||||
bool Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignment, u64* physAddrOut, int memoryType);
|
||||
bool Map(u64 virtual_addr, u64 phys_addr, u64 len, int prot, VirtualMemory::MemoryMode cpu_mode, GPU::MemoryMode gpu_mode);
|
||||
public:
|
||||
bool Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignment, u64* physAddrOut,
|
||||
int memoryType);
|
||||
bool Map(u64 virtual_addr, u64 phys_addr, u64 len, int prot, VirtualMemory::MemoryMode cpu_mode,
|
||||
GPU::MemoryMode gpu_mode);
|
||||
|
||||
private:
|
||||
private:
|
||||
std::vector<AllocatedBlock> m_allocatedBlocks;
|
||||
std::mutex m_mutex;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "Util/config.h"
|
||||
#include "common/log.h"
|
||||
#include "core/hle/kernel/cpu_management.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
#include "Util/config.h"
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
|
|
|
@ -1,31 +1,36 @@
|
|||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "core/hle/kernel/event_queues.h"
|
||||
#include "core/hle/error_codes.h"
|
||||
#include "core/hle/kernel/event_queues.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
constexpr bool log_file_equeues = true; // disable it to disable logging
|
||||
constexpr bool log_file_equeues = true; // disable it to disable logging
|
||||
|
||||
int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name) {
|
||||
PRINT_FUNCTION_NAME();
|
||||
|
||||
if (eq == nullptr) {
|
||||
LOG_TRACE_IF(log_file_equeues, "sceKernelCreateEqueue returned SCE_KERNEL_ERROR_EINVAL eq invalid\n");
|
||||
LOG_TRACE_IF(log_file_equeues,
|
||||
"sceKernelCreateEqueue returned SCE_KERNEL_ERROR_EINVAL eq invalid\n");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if (name == nullptr) {
|
||||
LOG_TRACE_IF(log_file_equeues, "sceKernelCreateEqueue returned SCE_KERNEL_ERROR_EFAULT name invalid\n");
|
||||
LOG_TRACE_IF(log_file_equeues,
|
||||
"sceKernelCreateEqueue returned SCE_KERNEL_ERROR_EFAULT name invalid\n");
|
||||
return SCE_KERNEL_ERROR_EFAULT;
|
||||
}
|
||||
if (name == NULL) {
|
||||
LOG_TRACE_IF(log_file_equeues, "sceKernelCreateEqueue returned SCE_KERNEL_ERROR_EINVAL name is null\n");
|
||||
LOG_TRACE_IF(log_file_equeues,
|
||||
"sceKernelCreateEqueue returned SCE_KERNEL_ERROR_EINVAL name is null\n");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
if (strlen(name) > 31) { // max is 32 including null terminator
|
||||
LOG_TRACE_IF(log_file_equeues, "sceKernelCreateEqueue returned SCE_KERNEL_ERROR_ENAMETOOLONG name size exceeds 32 bytes\n");
|
||||
if (strlen(name) > 31) { // max is 32 including null terminator
|
||||
LOG_TRACE_IF(log_file_equeues,
|
||||
"sceKernelCreateEqueue returned SCE_KERNEL_ERROR_ENAMETOOLONG name size "
|
||||
"exceeds 32 bytes\n");
|
||||
return SCE_KERNEL_ERROR_ENAMETOOLONG;
|
||||
}
|
||||
*eq = new EqueueInternal;
|
||||
|
@ -35,8 +40,8 @@ int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name) {
|
|||
return SCE_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev,
|
||||
int num, int* out, SceKernelUseconds* timo) {
|
||||
int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev, int num, int* out,
|
||||
SceKernelUseconds* timo) {
|
||||
PRINT_FUNCTION_NAME();
|
||||
|
||||
if (eq == nullptr) {
|
||||
|
@ -51,7 +56,7 @@ int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev,
|
|||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
if (timo == nullptr) { // wait until an event arrives without timing out
|
||||
if (timo == nullptr) { // wait until an event arrives without timing out
|
||||
*out = eq->waitForEvents(ev, num, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ using SceKernelUseconds = u32;
|
|||
using SceKernelEqueue = EqueueInternal*;
|
||||
|
||||
int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name);
|
||||
int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev,
|
||||
int num, int* out, SceKernelUseconds *timo);
|
||||
int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev, int num, int* out,
|
||||
SceKernelUseconds* timo);
|
||||
|
||||
} // namespace Core::Kernel
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
#include <bit>
|
||||
#include <magic_enum.hpp>
|
||||
#include <core/PS4/GPU/gpu_memory.h>
|
||||
#include <core/virtual_memory.h>
|
||||
#include "common/log.h"
|
||||
#include <magic_enum.hpp>
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "common/singleton.h"
|
||||
#include "core/hle/error_codes.h"
|
||||
#include "core/hle/kernel/Objects/physical_memory.h"
|
||||
#include "core/hle/kernel/memory_management.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
#include "core/hle/kernel/Objects/physical_memory.h"
|
||||
#include "core/hle/error_codes.h"
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
constexpr bool log_file_memory = true; // disable it to disable logging
|
||||
constexpr bool log_file_memory = true; // disable it to disable logging
|
||||
|
||||
bool is16KBAligned(u64 n) {
|
||||
return ((n % (16ull * 1024) == 0));
|
||||
|
@ -23,24 +23,31 @@ u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() {
|
|||
return SCE_KERNEL_MAIN_DMEM_SIZE;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len, u64 alignment, int memoryType, s64* physAddrOut) {
|
||||
int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len,
|
||||
u64 alignment, int memoryType, s64* physAddrOut) {
|
||||
PRINT_FUNCTION_NAME();
|
||||
|
||||
if (searchStart < 0 || searchEnd <= searchStart) {
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL searchStart,searchEnd invalid\n");
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned "
|
||||
"SCE_KERNEL_ERROR_EINVAL searchStart,searchEnd invalid\n");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
bool isInRange = (searchStart < len && searchEnd > len);
|
||||
if (len <= 0 || !is16KBAligned(len) || !isInRange) {
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL memory range invalid\n");
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned "
|
||||
"SCE_KERNEL_ERROR_EINVAL memory range invalid\n");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if ((alignment != 0 || is16KBAligned(alignment)) && !std::has_single_bit(alignment)) {
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL alignment invalid\n");
|
||||
LOG_TRACE_IF(
|
||||
log_file_memory,
|
||||
"sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL alignment invalid\n");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if (physAddrOut == nullptr) {
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL physAddrOut is null\n");
|
||||
LOG_TRACE_IF(
|
||||
log_file_memory,
|
||||
"sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL physAddrOut is null\n");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
auto memtype = magic_enum::enum_cast<MemoryTypes>(memoryType);
|
||||
|
@ -53,8 +60,10 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u
|
|||
|
||||
u64 physical_addr = 0;
|
||||
auto* physical_memory = Common::Singleton<PhysicalMemory>::Instance();
|
||||
if (!physical_memory->Alloc(searchStart, searchEnd, len, alignment, &physical_addr, memoryType)) {
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EAGAIN can't allocate physical memory\n");
|
||||
if (!physical_memory->Alloc(searchStart, searchEnd, len, alignment, &physical_addr,
|
||||
memoryType)) {
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned "
|
||||
"SCE_KERNEL_ERROR_EAGAIN can't allocate physical memory\n");
|
||||
return SCE_KERNEL_ERROR_EAGAIN;
|
||||
}
|
||||
*physAddrOut = static_cast<s64>(physical_addr);
|
||||
|
@ -62,19 +71,24 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u
|
|||
return SCE_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags, s64 directMemoryStart, u64 alignment) {
|
||||
int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags,
|
||||
s64 directMemoryStart, u64 alignment) {
|
||||
PRINT_FUNCTION_NAME();
|
||||
if (len == 0 || !is16KBAligned(len)) {
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL len invalid\n");
|
||||
LOG_TRACE_IF(log_file_memory,
|
||||
"sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL len invalid\n");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if (!is16KBAligned(directMemoryStart)) {
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL directMemoryStart invalid\n");
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL "
|
||||
"directMemoryStart invalid\n");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if (alignment != 0) {
|
||||
if ((!std::has_single_bit(alignment) && !is16KBAligned(alignment))) {
|
||||
LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL alignment invalid\n");
|
||||
LOG_TRACE_IF(
|
||||
log_file_memory,
|
||||
"sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL alignment invalid\n");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
@ -89,12 +103,13 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl
|
|||
GPU::MemoryMode gpu_mode = GPU::MemoryMode::NoAccess;
|
||||
|
||||
switch (prot) {
|
||||
case 0x32:
|
||||
case 0x33: // SCE_KERNEL_PROT_CPU_READ|SCE_KERNEL_PROT_CPU_WRITE|SCE_KERNEL_PROT_GPU_READ|SCE_KERNEL_PROT_GPU_ALL
|
||||
cpu_mode = VirtualMemory::MemoryMode::ReadWrite;
|
||||
gpu_mode = GPU::MemoryMode::ReadWrite;
|
||||
break;
|
||||
default: BREAKPOINT();
|
||||
case 0x32:
|
||||
case 0x33: // SCE_KERNEL_PROT_CPU_READ|SCE_KERNEL_PROT_CPU_WRITE|SCE_KERNEL_PROT_GPU_READ|SCE_KERNEL_PROT_GPU_ALL
|
||||
cpu_mode = VirtualMemory::MemoryMode::ReadWrite;
|
||||
gpu_mode = GPU::MemoryMode::ReadWrite;
|
||||
break;
|
||||
default:
|
||||
BREAKPOINT();
|
||||
}
|
||||
|
||||
auto in_addr = reinterpret_cast<u64>(*addr);
|
||||
|
@ -106,7 +121,7 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl
|
|||
LOG_INFO_IF(log_file_memory, "in_addr = {:#x}\n", in_addr);
|
||||
LOG_INFO_IF(log_file_memory, "out_addr = {:#x}\n", out_addr);
|
||||
|
||||
*addr = reinterpret_cast<void*>(out_addr); // return out_addr to first functions parameter
|
||||
*addr = reinterpret_cast<void*>(out_addr); // return out_addr to first functions parameter
|
||||
|
||||
if (out_addr == 0) {
|
||||
return SCE_KERNEL_ERROR_ENOMEM;
|
||||
|
|
|
@ -2,33 +2,35 @@
|
|||
|
||||
#include "common/types.h"
|
||||
|
||||
constexpr u64 SCE_KERNEL_MAIN_DMEM_SIZE = 5376_MB; // ~ 6GB
|
||||
constexpr u64 SCE_KERNEL_MAIN_DMEM_SIZE = 5376_MB; // ~ 6GB
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
enum MemoryTypes : u32 {
|
||||
SCE_KERNEL_WB_ONION = 0, // write - back mode (Onion bus)
|
||||
SCE_KERNEL_WC_GARLIC = 3, // write - combining mode (Garlic bus)
|
||||
SCE_KERNEL_WB_GARLIC = 10 // write - back mode (Garlic bus)
|
||||
SCE_KERNEL_WB_ONION = 0, // write - back mode (Onion bus)
|
||||
SCE_KERNEL_WC_GARLIC = 3, // write - combining mode (Garlic bus)
|
||||
SCE_KERNEL_WB_GARLIC = 10 // write - back mode (Garlic bus)
|
||||
};
|
||||
|
||||
enum MemoryFlags : u32 {
|
||||
SCE_KERNEL_MAP_FIXED = 0x0010, // Fixed
|
||||
SCE_KERNEL_MAP_FIXED = 0x0010, // Fixed
|
||||
SCE_KERNEL_MAP_NO_OVERWRITE = 0x0080,
|
||||
SCE_KERNEL_MAP_NO_COALESCE = 0x400000
|
||||
};
|
||||
|
||||
enum MemoryProtection : u32 {
|
||||
SCE_KERNEL_PROT_CPU_READ = 0x01, // Permit reads from the CPU
|
||||
SCE_KERNEL_PROT_CPU_RW = 0x02, // Permit reads/writes from the CPU
|
||||
SCE_KERNEL_PROT_CPU_WRITE = 0x02, // Permit reads/writes from the CPU (same)
|
||||
SCE_KERNEL_PROT_GPU_READ = 0x10, // Permit reads from the GPU
|
||||
SCE_KERNEL_PROT_GPU_WRITE = 0x20, // Permit writes from the GPU
|
||||
SCE_KERNEL_PROT_GPU_RW = 0x30 // Permit reads/writes from the GPU
|
||||
SCE_KERNEL_PROT_CPU_READ = 0x01, // Permit reads from the CPU
|
||||
SCE_KERNEL_PROT_CPU_RW = 0x02, // Permit reads/writes from the CPU
|
||||
SCE_KERNEL_PROT_CPU_WRITE = 0x02, // Permit reads/writes from the CPU (same)
|
||||
SCE_KERNEL_PROT_GPU_READ = 0x10, // Permit reads from the GPU
|
||||
SCE_KERNEL_PROT_GPU_WRITE = 0x20, // Permit writes from the GPU
|
||||
SCE_KERNEL_PROT_GPU_RW = 0x30 // Permit reads/writes from the GPU
|
||||
};
|
||||
|
||||
u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize();
|
||||
int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len, u64 alignment, int memoryType, s64* physAddrOut);
|
||||
int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags, s64 directMemoryStart, u64 alignment);
|
||||
int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len,
|
||||
u64 alignment, int memoryType, s64* physAddrOut);
|
||||
int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags,
|
||||
s64 directMemoryStart, u64 alignment);
|
||||
|
||||
} // namespace Core::Kernel
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <cstdlib>
|
||||
#include "common/debug.h"
|
||||
#include "common/singleton.h"
|
||||
#include "common/log.h"
|
||||
#include "common/singleton.h"
|
||||
#include "core/hle/libraries/libc/libc.h"
|
||||
#include "core/hle/libraries/libc/libc_cxa.h"
|
||||
#include "core/hle/libraries/libc/libc_math.h"
|
||||
|
@ -12,7 +12,7 @@
|
|||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
constexpr bool log_file_libc = true; // disable it to disable logging
|
||||
constexpr bool log_file_libc = true; // disable it to disable logging
|
||||
static u32 g_need_sceLibc = 1;
|
||||
|
||||
using cxa_destructor_func_t = void (*)(void*);
|
||||
|
@ -82,55 +82,73 @@ PS4_SYSV_ABI void* ps4__Znwm(u64 count) {
|
|||
}
|
||||
|
||||
static constexpr u16 lowercaseTable[256] = {
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, 0x0010, 0x0011,
|
||||
0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, 0x0020, 0x0021, 0x0022, 0x0023,
|
||||
0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
|
||||
0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, 0x0040, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
|
||||
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079,
|
||||
0x007A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F, 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B,
|
||||
0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D,
|
||||
0x007E, 0x007F, 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
|
||||
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F, 0x00A0, 0x00A1,
|
||||
0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3,
|
||||
0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5,
|
||||
0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
|
||||
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9,
|
||||
0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB,
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B,
|
||||
0x000C, 0x000D, 0x000E, 0x000F, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
|
||||
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, 0x0020, 0x0021, 0x0022, 0x0023,
|
||||
0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
|
||||
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B,
|
||||
0x003C, 0x003D, 0x003E, 0x003F, 0x0040, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
|
||||
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073,
|
||||
0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
|
||||
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B,
|
||||
0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
|
||||
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F, 0x0080, 0x0081, 0x0082, 0x0083,
|
||||
0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
|
||||
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009A, 0x009B,
|
||||
0x009C, 0x009D, 0x009E, 0x009F, 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3,
|
||||
0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
|
||||
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB,
|
||||
0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
|
||||
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3,
|
||||
0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
|
||||
0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB,
|
||||
0x00FC, 0x00FD, 0x00FE, 0x00FF,
|
||||
};
|
||||
|
||||
const PS4_SYSV_ABI u16* ps4__Getptolower() { return &lowercaseTable[0]; }
|
||||
const PS4_SYSV_ABI u16* ps4__Getptolower() {
|
||||
return &lowercaseTable[0];
|
||||
}
|
||||
|
||||
static constexpr u16 uppercaseTable[256] = {
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, 0x0010, 0x0011,
|
||||
0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, 0x0020, 0x0021, 0x0022, 0x0023,
|
||||
0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
|
||||
0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
|
||||
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059,
|
||||
0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F, 0x0060, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B,
|
||||
0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x007B, 0x007C, 0x007D,
|
||||
0x007E, 0x007F, 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
|
||||
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F, 0x00A0, 0x00A1,
|
||||
0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3,
|
||||
0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5,
|
||||
0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
|
||||
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9,
|
||||
0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB,
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B,
|
||||
0x000C, 0x000D, 0x000E, 0x000F, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
|
||||
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, 0x0020, 0x0021, 0x0022, 0x0023,
|
||||
0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
|
||||
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B,
|
||||
0x003C, 0x003D, 0x003E, 0x003F, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
|
||||
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053,
|
||||
0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
|
||||
0x0060, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B,
|
||||
0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
|
||||
0x0058, 0x0059, 0x005A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F, 0x0080, 0x0081, 0x0082, 0x0083,
|
||||
0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
|
||||
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009A, 0x009B,
|
||||
0x009C, 0x009D, 0x009E, 0x009F, 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3,
|
||||
0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
|
||||
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB,
|
||||
0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
|
||||
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3,
|
||||
0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
|
||||
0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB,
|
||||
0x00FC, 0x00FD, 0x00FE, 0x00FF,
|
||||
};
|
||||
|
||||
const PS4_SYSV_ABI u16* ps4__Getptoupper() { return &uppercaseTable[0]; }
|
||||
const PS4_SYSV_ABI u16* ps4__Getptoupper() {
|
||||
return &uppercaseTable[0];
|
||||
}
|
||||
|
||||
namespace CharacterType {
|
||||
enum : u16 {
|
||||
HexDigit = 0x1, // '0'-'9', 'A'-'F', 'a'-'f'
|
||||
Uppercase = 0x2, // 'A'-'Z'
|
||||
HexDigit = 0x1, // '0'-'9', 'A'-'F', 'a'-'f'
|
||||
Uppercase = 0x2, // 'A'-'Z'
|
||||
Space = 0x4,
|
||||
Punctuation = 0x08,
|
||||
Lowercase = 0x10, // 'a'-'z'
|
||||
DecimalDigit = 0x20, // '0'-'9'
|
||||
Control = 0x40, // CR, FF, HT, NL, VT
|
||||
Control2 = 0x80, // BEL, BS, etc
|
||||
Lowercase = 0x10, // 'a'-'z'
|
||||
DecimalDigit = 0x20, // '0'-'9'
|
||||
Control = 0x40, // CR, FF, HT, NL, VT
|
||||
Control2 = 0x80, // BEL, BS, etc
|
||||
ExtraSpace = 0x100,
|
||||
ExtraAlphabetic = 0x200,
|
||||
ExtraBlank = 0x400
|
||||
|
@ -170,101 +188,101 @@ static constexpr u16 characterTypeTable[256] = {
|
|||
CharacterType::Control2,
|
||||
CharacterType::Control2,
|
||||
CharacterType::Control2,
|
||||
CharacterType::Space, //
|
||||
CharacterType::Punctuation, // !
|
||||
CharacterType::Punctuation, // "
|
||||
CharacterType::Punctuation, // #
|
||||
CharacterType::Punctuation, // $
|
||||
CharacterType::Punctuation, // %
|
||||
CharacterType::Punctuation, // &
|
||||
CharacterType::Punctuation, // '
|
||||
CharacterType::Punctuation, // (
|
||||
CharacterType::Punctuation, // )
|
||||
CharacterType::Punctuation, // *
|
||||
CharacterType::Punctuation, // +
|
||||
CharacterType::Punctuation, // ,
|
||||
CharacterType::Punctuation, // -
|
||||
CharacterType::Punctuation, // .
|
||||
CharacterType::Punctuation, // /
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 0
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 1
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 2
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 3
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 4
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 5
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 6
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 7
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 8
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 9
|
||||
CharacterType::Punctuation, // :
|
||||
CharacterType::Punctuation, // ;
|
||||
CharacterType::Punctuation, // <
|
||||
CharacterType::Punctuation, // =
|
||||
CharacterType::Punctuation, // >
|
||||
CharacterType::Punctuation, // ?
|
||||
CharacterType::Punctuation, // @
|
||||
CharacterType::HexDigit | CharacterType::Uppercase, // A
|
||||
CharacterType::HexDigit | CharacterType::Uppercase, // B
|
||||
CharacterType::HexDigit | CharacterType::Uppercase, // C
|
||||
CharacterType::HexDigit | CharacterType::Uppercase, // D
|
||||
CharacterType::HexDigit | CharacterType::Uppercase, // E
|
||||
CharacterType::HexDigit | CharacterType::Uppercase, // F
|
||||
CharacterType::Uppercase, // G
|
||||
CharacterType::Uppercase, // H
|
||||
CharacterType::Uppercase, // I
|
||||
CharacterType::Uppercase, // J
|
||||
CharacterType::Uppercase, // K
|
||||
CharacterType::Uppercase, // L
|
||||
CharacterType::Uppercase, // M
|
||||
CharacterType::Uppercase, // N
|
||||
CharacterType::Uppercase, // O
|
||||
CharacterType::Uppercase, // P
|
||||
CharacterType::Uppercase, // Q
|
||||
CharacterType::Uppercase, // R
|
||||
CharacterType::Uppercase, // S
|
||||
CharacterType::Uppercase, // T
|
||||
CharacterType::Uppercase, // U
|
||||
CharacterType::Uppercase, // V
|
||||
CharacterType::Uppercase, // W
|
||||
CharacterType::Uppercase, // X
|
||||
CharacterType::Uppercase, // Y
|
||||
CharacterType::Uppercase, // Z
|
||||
CharacterType::Punctuation, // [
|
||||
CharacterType::Punctuation, //
|
||||
CharacterType::Punctuation, // ]
|
||||
CharacterType::Punctuation, // ^
|
||||
CharacterType::Punctuation, // _
|
||||
CharacterType::Punctuation, // `
|
||||
CharacterType::HexDigit | CharacterType::Lowercase, // a
|
||||
CharacterType::HexDigit | CharacterType::Lowercase, // b
|
||||
CharacterType::HexDigit | CharacterType::Lowercase, // c
|
||||
CharacterType::HexDigit | CharacterType::Lowercase, // d
|
||||
CharacterType::HexDigit | CharacterType::Lowercase, // e
|
||||
CharacterType::HexDigit | CharacterType::Lowercase, // f
|
||||
CharacterType::Lowercase, // g
|
||||
CharacterType::Lowercase, // h
|
||||
CharacterType::Lowercase, // i
|
||||
CharacterType::Lowercase, // j
|
||||
CharacterType::Lowercase, // k
|
||||
CharacterType::Lowercase, // l
|
||||
CharacterType::Lowercase, // m
|
||||
CharacterType::Lowercase, // n
|
||||
CharacterType::Lowercase, // o
|
||||
CharacterType::Lowercase, // p
|
||||
CharacterType::Lowercase, // q
|
||||
CharacterType::Lowercase, // r
|
||||
CharacterType::Lowercase, // s
|
||||
CharacterType::Lowercase, // t
|
||||
CharacterType::Lowercase, // u
|
||||
CharacterType::Lowercase, // v
|
||||
CharacterType::Lowercase, // w
|
||||
CharacterType::Lowercase, // x
|
||||
CharacterType::Lowercase, // y
|
||||
CharacterType::Lowercase, // z
|
||||
CharacterType::Punctuation, // {
|
||||
CharacterType::Punctuation, // |
|
||||
CharacterType::Punctuation, // }
|
||||
CharacterType::Punctuation, // ~
|
||||
CharacterType::Space, //
|
||||
CharacterType::Punctuation, // !
|
||||
CharacterType::Punctuation, // "
|
||||
CharacterType::Punctuation, // #
|
||||
CharacterType::Punctuation, // $
|
||||
CharacterType::Punctuation, // %
|
||||
CharacterType::Punctuation, // &
|
||||
CharacterType::Punctuation, // '
|
||||
CharacterType::Punctuation, // (
|
||||
CharacterType::Punctuation, // )
|
||||
CharacterType::Punctuation, // *
|
||||
CharacterType::Punctuation, // +
|
||||
CharacterType::Punctuation, // ,
|
||||
CharacterType::Punctuation, // -
|
||||
CharacterType::Punctuation, // .
|
||||
CharacterType::Punctuation, // /
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 0
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 1
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 2
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 3
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 4
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 5
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 6
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 7
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 8
|
||||
CharacterType::HexDigit | CharacterType::DecimalDigit, // 9
|
||||
CharacterType::Punctuation, // :
|
||||
CharacterType::Punctuation, // ;
|
||||
CharacterType::Punctuation, // <
|
||||
CharacterType::Punctuation, // =
|
||||
CharacterType::Punctuation, // >
|
||||
CharacterType::Punctuation, // ?
|
||||
CharacterType::Punctuation, // @
|
||||
CharacterType::HexDigit | CharacterType::Uppercase, // A
|
||||
CharacterType::HexDigit | CharacterType::Uppercase, // B
|
||||
CharacterType::HexDigit | CharacterType::Uppercase, // C
|
||||
CharacterType::HexDigit | CharacterType::Uppercase, // D
|
||||
CharacterType::HexDigit | CharacterType::Uppercase, // E
|
||||
CharacterType::HexDigit | CharacterType::Uppercase, // F
|
||||
CharacterType::Uppercase, // G
|
||||
CharacterType::Uppercase, // H
|
||||
CharacterType::Uppercase, // I
|
||||
CharacterType::Uppercase, // J
|
||||
CharacterType::Uppercase, // K
|
||||
CharacterType::Uppercase, // L
|
||||
CharacterType::Uppercase, // M
|
||||
CharacterType::Uppercase, // N
|
||||
CharacterType::Uppercase, // O
|
||||
CharacterType::Uppercase, // P
|
||||
CharacterType::Uppercase, // Q
|
||||
CharacterType::Uppercase, // R
|
||||
CharacterType::Uppercase, // S
|
||||
CharacterType::Uppercase, // T
|
||||
CharacterType::Uppercase, // U
|
||||
CharacterType::Uppercase, // V
|
||||
CharacterType::Uppercase, // W
|
||||
CharacterType::Uppercase, // X
|
||||
CharacterType::Uppercase, // Y
|
||||
CharacterType::Uppercase, // Z
|
||||
CharacterType::Punctuation, // [
|
||||
CharacterType::Punctuation, //
|
||||
CharacterType::Punctuation, // ]
|
||||
CharacterType::Punctuation, // ^
|
||||
CharacterType::Punctuation, // _
|
||||
CharacterType::Punctuation, // `
|
||||
CharacterType::HexDigit | CharacterType::Lowercase, // a
|
||||
CharacterType::HexDigit | CharacterType::Lowercase, // b
|
||||
CharacterType::HexDigit | CharacterType::Lowercase, // c
|
||||
CharacterType::HexDigit | CharacterType::Lowercase, // d
|
||||
CharacterType::HexDigit | CharacterType::Lowercase, // e
|
||||
CharacterType::HexDigit | CharacterType::Lowercase, // f
|
||||
CharacterType::Lowercase, // g
|
||||
CharacterType::Lowercase, // h
|
||||
CharacterType::Lowercase, // i
|
||||
CharacterType::Lowercase, // j
|
||||
CharacterType::Lowercase, // k
|
||||
CharacterType::Lowercase, // l
|
||||
CharacterType::Lowercase, // m
|
||||
CharacterType::Lowercase, // n
|
||||
CharacterType::Lowercase, // o
|
||||
CharacterType::Lowercase, // p
|
||||
CharacterType::Lowercase, // q
|
||||
CharacterType::Lowercase, // r
|
||||
CharacterType::Lowercase, // s
|
||||
CharacterType::Lowercase, // t
|
||||
CharacterType::Lowercase, // u
|
||||
CharacterType::Lowercase, // v
|
||||
CharacterType::Lowercase, // w
|
||||
CharacterType::Lowercase, // x
|
||||
CharacterType::Lowercase, // y
|
||||
CharacterType::Lowercase, // z
|
||||
CharacterType::Punctuation, // {
|
||||
CharacterType::Punctuation, // |
|
||||
CharacterType::Punctuation, // }
|
||||
CharacterType::Punctuation, // ~
|
||||
CharacterType::Control2,
|
||||
0,
|
||||
0,
|
||||
|
@ -396,7 +414,9 @@ static constexpr u16 characterTypeTable[256] = {
|
|||
0,
|
||||
};
|
||||
|
||||
const PS4_SYSV_ABI u16* ps4__Getpctype() { return &characterTypeTable[0]; }
|
||||
const PS4_SYSV_ABI u16* ps4__Getpctype() {
|
||||
return &characterTypeTable[0];
|
||||
}
|
||||
|
||||
void libcSymbolsRegister(Loader::SymbolsResolver* sym) {
|
||||
// cxa functions
|
||||
|
@ -441,8 +461,8 @@ void libcSymbolsRegister(Loader::SymbolsResolver* sym) {
|
|||
|
||||
// misc
|
||||
LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &g_need_sceLibc);
|
||||
LIB_OBJ("2sWzhYqFH4E","libc", 1, "libc", 1, 1,stdout);
|
||||
LIB_OBJ("H8AprKeZtNg", "libc", 1, "libc", 1, 1, stderr);
|
||||
LIB_OBJ("2sWzhYqFH4E", "libc", 1, "libc", 1, 1, stdout);
|
||||
LIB_OBJ("H8AprKeZtNg", "libc", 1, "libc", 1, 1, stderr);
|
||||
LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, ps4_init_env);
|
||||
LIB_FUNCTION("XKRegsFpEpk", "libc", 1, "libc", 1, 1, ps4_catchReturnFromMain);
|
||||
LIB_FUNCTION("-QgqOT5u2Vk", "libc", 1, "libc", 1, 1, ps4__Assert);
|
||||
|
@ -458,4 +478,4 @@ void libcSymbolsRegister(Loader::SymbolsResolver* sym) {
|
|||
LIB_FUNCTION("sUP1hBaouOw", "libc", 1, "libc", 1, 1, ps4__Getpctype);
|
||||
}
|
||||
|
||||
}; // namespace Core::Libraries::LibC
|
||||
}; // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -8,4 +8,4 @@ namespace Core::Libraries::LibC {
|
|||
|
||||
void libcSymbolsRegister(Loader::SymbolsResolver* sym);
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
#include "libc_cxa.h"
|
||||
|
||||
#include "common/log.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
|
||||
// adapted from https://opensource.apple.com/source/libcppabi/libcppabi-14/src/cxa_guard.cxx.auto.html
|
||||
// adapted from
|
||||
// https://opensource.apple.com/source/libcppabi/libcppabi-14/src/cxa_guard.cxx.auto.html
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
constexpr bool log_file_cxa = true; // disable it to disable logging
|
||||
constexpr bool log_file_cxa = true; // disable it to disable logging
|
||||
|
||||
// This file implements the __cxa_guard_* functions as defined at:
|
||||
// http://www.codesourcery.com/public/cxx-abi/abi.html
|
||||
|
@ -55,15 +56,25 @@ __attribute__((noinline)) static pthread_mutex_t* guard_mutex() {
|
|||
}
|
||||
|
||||
// helper functions for getting/setting flags in guard_object
|
||||
static bool initializerHasRun(u64* guard_object) { return (*((u08*)guard_object) != 0); }
|
||||
static bool initializerHasRun(u64* guard_object) {
|
||||
return (*((u08*)guard_object) != 0);
|
||||
}
|
||||
|
||||
static void setInitializerHasRun(u64* guard_object) { *((u08*)guard_object) = 1; }
|
||||
static void setInitializerHasRun(u64* guard_object) {
|
||||
*((u08*)guard_object) = 1;
|
||||
}
|
||||
|
||||
static bool inUse(u64* guard_object) { return (((u08*)guard_object)[1] != 0); }
|
||||
static bool inUse(u64* guard_object) {
|
||||
return (((u08*)guard_object)[1] != 0);
|
||||
}
|
||||
|
||||
static void setInUse(u64* guard_object) { ((u08*)guard_object)[1] = 1; }
|
||||
static void setInUse(u64* guard_object) {
|
||||
((u08*)guard_object)[1] = 1;
|
||||
}
|
||||
|
||||
static void setNotInUse(u64* guard_object) { ((u08*)guard_object)[1] = 0; }
|
||||
static void setNotInUse(u64* guard_object) {
|
||||
((u08*)guard_object)[1] = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Returns 1 if the caller needs to run the initializer and then either
|
||||
|
@ -75,7 +86,8 @@ static void setNotInUse(u64* guard_object) { ((u08*)guard_object)[1] = 0; }
|
|||
//
|
||||
int PS4_SYSV_ABI ps4___cxa_guard_acquire(u64* guard_object) {
|
||||
// Double check that the initializer has not already been run
|
||||
if (initializerHasRun(guard_object)) return 0;
|
||||
if (initializerHasRun(guard_object))
|
||||
return 0;
|
||||
|
||||
// We now need to acquire a lock that allows only one thread
|
||||
// to run the initializer. If a different thread calls
|
||||
|
@ -89,7 +101,8 @@ int PS4_SYSV_ABI ps4___cxa_guard_acquire(u64* guard_object) {
|
|||
|
||||
int result = ::pthread_mutex_lock(guard_mutex());
|
||||
if (result != 0) {
|
||||
LOG_TRACE_IF(log_file_cxa, "__cxa_guard_acquire(): pthread_mutex_lock failed with {}\n", result);
|
||||
LOG_TRACE_IF(log_file_cxa, "__cxa_guard_acquire(): pthread_mutex_lock failed with {}\n",
|
||||
result);
|
||||
}
|
||||
// At this point all other threads will block in __cxa_guard_acquire()
|
||||
|
||||
|
@ -97,7 +110,8 @@ int PS4_SYSV_ABI ps4___cxa_guard_acquire(u64* guard_object) {
|
|||
if (initializerHasRun(guard_object)) {
|
||||
int result = ::pthread_mutex_unlock(guard_mutex());
|
||||
if (result != 0) {
|
||||
LOG_TRACE_IF(log_file_cxa, "__cxa_guard_acquire(): pthread_mutex_unlock failed with {}\n", result);
|
||||
LOG_TRACE_IF(log_file_cxa,
|
||||
"__cxa_guard_acquire(): pthread_mutex_unlock failed with {}\n", result);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -107,7 +121,8 @@ int PS4_SYSV_ABI ps4___cxa_guard_acquire(u64* guard_object) {
|
|||
// But if the same thread can call __cxa_guard_acquire() on the
|
||||
// *same* guard object again, we call abort();
|
||||
if (inUse(guard_object)) {
|
||||
LOG_TRACE_IF(log_file_cxa, "__cxa_guard_acquire(): initializer for function local static variable called enclosing function\n");
|
||||
LOG_TRACE_IF(log_file_cxa, "__cxa_guard_acquire(): initializer for function local static "
|
||||
"variable called enclosing function\n");
|
||||
}
|
||||
|
||||
// mark this guard object as being in use
|
||||
|
@ -129,7 +144,8 @@ void PS4_SYSV_ABI ps4___cxa_guard_release(u64* guard_object) {
|
|||
// release global mutex
|
||||
int result = ::pthread_mutex_unlock(guard_mutex());
|
||||
if (result != 0) {
|
||||
LOG_TRACE_IF(log_file_cxa, "__cxa_guard_acquire(): pthread_mutex_unlock failed with {}\n", result);
|
||||
LOG_TRACE_IF(log_file_cxa, "__cxa_guard_acquire(): pthread_mutex_unlock failed with {}\n",
|
||||
result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,11 +155,12 @@ void PS4_SYSV_ABI ps4___cxa_guard_release(u64* guard_object) {
|
|||
void PS4_SYSV_ABI ps4___cxa_guard_abort(u64* guard_object) {
|
||||
int result = ::pthread_mutex_unlock(guard_mutex());
|
||||
if (result != 0) {
|
||||
LOG_TRACE_IF(log_file_cxa, "__cxa_guard_abort(): pthread_mutex_unlock failed with {}\n", result);
|
||||
LOG_TRACE_IF(log_file_cxa, "__cxa_guard_abort(): pthread_mutex_unlock failed with {}\n",
|
||||
result);
|
||||
}
|
||||
|
||||
// now reset state, so possible to try to initialize again
|
||||
setNotInUse(guard_object);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
constexpr bool log_file_libc = true; // disable it to disable logging
|
||||
constexpr bool log_file_libc = true; // disable it to disable logging
|
||||
|
||||
int PS4_SYSV_ABI ps4_printf(VA_ARGS) {
|
||||
VA_CTX(ctx);
|
||||
|
@ -13,7 +13,7 @@ int PS4_SYSV_ABI ps4_printf(VA_ARGS) {
|
|||
|
||||
int PS4_SYSV_ABI ps4_fprintf(FILE* file, VA_ARGS) {
|
||||
int fd = fileno(file);
|
||||
if (fd == 1 || fd == 2) { // output stdout and stderr to console
|
||||
if (fd == 1 || fd == 2) { // output stdout and stderr to console
|
||||
VA_CTX(ctx);
|
||||
return printf_ctx(&ctx);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include <cstdlib>
|
||||
#include "common/log.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "core/hle/libraries/libc/libc_stdlib.h"
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
constexpr bool log_file_libc = true; // disable it to disable logging
|
||||
constexpr bool log_file_libc = true; // disable it to disable logging
|
||||
|
||||
void PS4_SYSV_ABI ps4_exit(int code) {
|
||||
std::exit(code);
|
||||
|
@ -35,7 +35,8 @@ int qsort_compair(const void* arg1, const void* arg2) {
|
|||
return compair_ps4(arg1, arg2);
|
||||
}
|
||||
|
||||
void PS4_SYSV_ABI ps4_qsort(void* ptr, size_t count, size_t size, int(PS4_SYSV_ABI* comp)(const void*, const void*)) {
|
||||
void PS4_SYSV_ABI ps4_qsort(void* ptr, size_t count, size_t size,
|
||||
int(PS4_SYSV_ABI* comp)(const void*, const void*)) {
|
||||
compair_ps4 = comp;
|
||||
std::qsort(ptr, count, size, qsort_compair);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@ void PS4_SYSV_ABI ps4_exit(int code);
|
|||
int PS4_SYSV_ABI ps4_atexit(void (*func)());
|
||||
void* PS4_SYSV_ABI ps4_malloc(size_t size);
|
||||
void PS4_SYSV_ABI ps4_free(void* ptr);
|
||||
void PS4_SYSV_ABI ps4_qsort(void* ptr, size_t count, size_t size, int(PS4_SYSV_ABI* comp)(const void*, const void*));
|
||||
void PS4_SYSV_ABI ps4_qsort(void* ptr, size_t count, size_t size,
|
||||
int(PS4_SYSV_ABI* comp)(const void*, const void*));
|
||||
int PS4_SYSV_ABI ps4_rand();
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -140,7 +140,9 @@ static inline unsigned int _strlen(const char* str) {
|
|||
|
||||
// internal test if char is a digit (0-9)
|
||||
// \return true if char is a digit
|
||||
static inline bool _is_digit(char ch) { return (ch >= '0') && (ch <= '9'); }
|
||||
static inline bool _is_digit(char ch) {
|
||||
return (ch >= '0') && (ch <= '9');
|
||||
}
|
||||
|
||||
// internal ASCII string to unsigned int conversion
|
||||
static inline unsigned int _atoi(const char** str) {
|
||||
|
@ -152,7 +154,8 @@ static inline unsigned int _atoi(const char** str) {
|
|||
}
|
||||
|
||||
// internal itoa format
|
||||
static inline size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t maxlen, char* buf, size_t len, bool negative, unsigned int base,
|
||||
static inline size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t maxlen,
|
||||
char* buf, size_t len, bool negative, unsigned int base,
|
||||
unsigned int prec, unsigned int width, unsigned int flags) {
|
||||
const size_t start_idx = idx;
|
||||
|
||||
|
@ -160,7 +163,8 @@ static inline size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, si
|
|||
while (!(flags & FLAGS_LEFT) && (len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||
buf[len++] = '0';
|
||||
}
|
||||
while (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||
while (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD) && (len < width) &&
|
||||
(len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||
buf[len++] = '0';
|
||||
}
|
||||
|
||||
|
@ -191,7 +195,7 @@ static inline size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, si
|
|||
if (negative) {
|
||||
buf[len++] = '-';
|
||||
} else if (flags & FLAGS_PLUS) {
|
||||
buf[len++] = '+'; // ignore the space if the '+' exists
|
||||
buf[len++] = '+'; // ignore the space if the '+' exists
|
||||
} else if (flags & FLAGS_SPACE) {
|
||||
buf[len++] = ' ';
|
||||
}
|
||||
|
@ -220,7 +224,8 @@ static inline size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, si
|
|||
}
|
||||
|
||||
// internal itoa for 'long' type
|
||||
static inline size_t _ntoa_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, unsigned long value, bool negative, unsigned long base,
|
||||
static inline size_t _ntoa_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen,
|
||||
unsigned long value, bool negative, unsigned long base,
|
||||
unsigned int prec, unsigned int width, unsigned int flags) {
|
||||
char buf[PRINTF_NTOA_BUFFER_SIZE];
|
||||
size_t len = 0U;
|
||||
|
@ -229,18 +234,22 @@ static inline size_t _ntoa_long(out_fct_type out, char* buffer, size_t idx, size
|
|||
if (!(flags & FLAGS_PRECISION) || value) {
|
||||
do {
|
||||
const char digit = (char)(value % base);
|
||||
buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10;
|
||||
buf[len++] =
|
||||
digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10;
|
||||
value /= base;
|
||||
} while (value && (len < PRINTF_NTOA_BUFFER_SIZE));
|
||||
}
|
||||
|
||||
return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags);
|
||||
return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec,
|
||||
width, flags);
|
||||
}
|
||||
|
||||
// internal itoa for 'long long' type
|
||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||
static inline size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, unsigned long long value, bool negative,
|
||||
unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags) {
|
||||
static inline size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen,
|
||||
unsigned long long value, bool negative,
|
||||
unsigned long long base, unsigned int prec, unsigned int width,
|
||||
unsigned int flags) {
|
||||
char buf[PRINTF_NTOA_BUFFER_SIZE];
|
||||
size_t len = 0U;
|
||||
|
||||
|
@ -248,18 +257,20 @@ static inline size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx,
|
|||
if (!(flags & FLAGS_PRECISION) || value) {
|
||||
do {
|
||||
const char digit = (char)(value % base);
|
||||
buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10;
|
||||
buf[len++] =
|
||||
digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10;
|
||||
value /= base;
|
||||
} while (value && (len < PRINTF_NTOA_BUFFER_SIZE));
|
||||
}
|
||||
|
||||
return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags);
|
||||
return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec,
|
||||
width, flags);
|
||||
}
|
||||
#endif // PRINTF_SUPPORT_LONG_LONG
|
||||
#endif // PRINTF_SUPPORT_LONG_LONG
|
||||
|
||||
#if defined(PRINTF_SUPPORT_FLOAT)
|
||||
static inline size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width,
|
||||
unsigned int flags) {
|
||||
static inline size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value,
|
||||
unsigned int prec, unsigned int width, unsigned int flags) {
|
||||
char buf[PRINTF_FTOA_BUFFER_SIZE];
|
||||
size_t len = 0U;
|
||||
double diff = 0.0;
|
||||
|
@ -268,7 +279,8 @@ static inline size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t ma
|
|||
const double thres_max = (double)0x7FFFFFFF;
|
||||
|
||||
// powers of 10
|
||||
static const double pow10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
|
||||
static const double pow10[] = {1, 10, 100, 1000, 10000,
|
||||
100000, 1000000, 10000000, 100000000, 1000000000};
|
||||
|
||||
// test for negative
|
||||
bool negative = false;
|
||||
|
@ -304,8 +316,9 @@ static inline size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t ma
|
|||
++frac;
|
||||
}
|
||||
|
||||
// TBD: for very large numbers switch back to native sprintf for exponentials. Anyone want to write code to replace this?
|
||||
// Normal printf behavior is to print EVERY whole number digit which can be 100s of characters overflowing your buffers == bad
|
||||
// TBD: for very large numbers switch back to native sprintf for exponentials. Anyone want to
|
||||
// write code to replace this? Normal printf behavior is to print EVERY whole number digit which
|
||||
// can be 100s of characters overflowing your buffers == bad
|
||||
if (value > thres_max) {
|
||||
return 0U;
|
||||
}
|
||||
|
@ -349,7 +362,8 @@ static inline size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t ma
|
|||
}
|
||||
|
||||
// pad leading zeros
|
||||
while (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) {
|
||||
while (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD) && (len < width) &&
|
||||
(len < PRINTF_FTOA_BUFFER_SIZE)) {
|
||||
buf[len++] = '0';
|
||||
}
|
||||
|
||||
|
@ -361,7 +375,7 @@ static inline size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t ma
|
|||
if (negative) {
|
||||
buf[len++] = '-';
|
||||
} else if (flags & FLAGS_PLUS) {
|
||||
buf[len++] = '+'; // ignore the space if the '+' exists
|
||||
buf[len++] = '+'; // ignore the space if the '+' exists
|
||||
} else if (flags & FLAGS_SPACE) {
|
||||
buf[len++] = ' ';
|
||||
}
|
||||
|
@ -388,7 +402,7 @@ static inline size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t ma
|
|||
|
||||
return idx;
|
||||
}
|
||||
#endif // PRINTF_SUPPORT_FLOAT
|
||||
#endif // PRINTF_SUPPORT_FLOAT
|
||||
|
||||
// internal vsnprintf
|
||||
static inline int _vsnprintf(out_fct_type out, char* buffer, const char* format, VaList* va_list) {
|
||||
|
@ -417,32 +431,34 @@ static inline int _vsnprintf(out_fct_type out, char* buffer, const char* format,
|
|||
flags = 0U;
|
||||
do {
|
||||
switch (*format) {
|
||||
case '0':
|
||||
flags |= FLAGS_ZEROPAD;
|
||||
format++;
|
||||
n = 1U;
|
||||
break;
|
||||
case '-':
|
||||
flags |= FLAGS_LEFT;
|
||||
format++;
|
||||
n = 1U;
|
||||
break;
|
||||
case '+':
|
||||
flags |= FLAGS_PLUS;
|
||||
format++;
|
||||
n = 1U;
|
||||
break;
|
||||
case ' ':
|
||||
flags |= FLAGS_SPACE;
|
||||
format++;
|
||||
n = 1U;
|
||||
break;
|
||||
case '#':
|
||||
flags |= FLAGS_HASH;
|
||||
format++;
|
||||
n = 1U;
|
||||
break;
|
||||
default: n = 0U; break;
|
||||
case '0':
|
||||
flags |= FLAGS_ZEROPAD;
|
||||
format++;
|
||||
n = 1U;
|
||||
break;
|
||||
case '-':
|
||||
flags |= FLAGS_LEFT;
|
||||
format++;
|
||||
n = 1U;
|
||||
break;
|
||||
case '+':
|
||||
flags |= FLAGS_PLUS;
|
||||
format++;
|
||||
n = 1U;
|
||||
break;
|
||||
case ' ':
|
||||
flags |= FLAGS_SPACE;
|
||||
format++;
|
||||
n = 1U;
|
||||
break;
|
||||
case '#':
|
||||
flags |= FLAGS_HASH;
|
||||
format++;
|
||||
n = 1U;
|
||||
break;
|
||||
default:
|
||||
n = 0U;
|
||||
break;
|
||||
}
|
||||
} while (n);
|
||||
|
||||
|
@ -451,10 +467,10 @@ static inline int _vsnprintf(out_fct_type out, char* buffer, const char* format,
|
|||
if (_is_digit(*format)) {
|
||||
width = _atoi(&format);
|
||||
} else if (*format == '*') {
|
||||
const int w = vaArgInteger(va_list); // const int w = va.next<int>(cpu, mem);
|
||||
const int w = vaArgInteger(va_list); // const int w = va.next<int>(cpu, mem);
|
||||
|
||||
if (w < 0) {
|
||||
flags |= FLAGS_LEFT; // reverse padding
|
||||
flags |= FLAGS_LEFT; // reverse padding
|
||||
width = (unsigned int)-w;
|
||||
} else {
|
||||
width = (unsigned int)w;
|
||||
|
@ -470,212 +486,234 @@ static inline int _vsnprintf(out_fct_type out, char* buffer, const char* format,
|
|||
if (_is_digit(*format)) {
|
||||
precision = _atoi(&format);
|
||||
} else if (*format == '*') {
|
||||
precision = vaArgInteger(va_list); // precision = (unsigned int)va.next<int>(cpu, mem);
|
||||
precision =
|
||||
vaArgInteger(va_list); // precision = (unsigned int)va.next<int>(cpu, mem);
|
||||
format++;
|
||||
}
|
||||
}
|
||||
|
||||
// evaluate length field
|
||||
switch (*format) {
|
||||
case 'l':
|
||||
flags |= FLAGS_LONG;
|
||||
case 'l':
|
||||
flags |= FLAGS_LONG;
|
||||
format++;
|
||||
if (*format == 'l') {
|
||||
flags |= FLAGS_LONG_LONG;
|
||||
format++;
|
||||
if (*format == 'l') {
|
||||
flags |= FLAGS_LONG_LONG;
|
||||
format++;
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
flags |= FLAGS_SHORT;
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
flags |= FLAGS_SHORT;
|
||||
format++;
|
||||
if (*format == 'h') {
|
||||
flags |= FLAGS_CHAR;
|
||||
format++;
|
||||
if (*format == 'h') {
|
||||
flags |= FLAGS_CHAR;
|
||||
format++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
#if defined(PRINTF_SUPPORT_PTRDIFF_T)
|
||||
case 't':
|
||||
flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||
format++;
|
||||
break;
|
||||
case 't':
|
||||
flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||
format++;
|
||||
break;
|
||||
#endif
|
||||
case 'j':
|
||||
flags |= (sizeof(intmax_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||
format++;
|
||||
break;
|
||||
case 'z':
|
||||
flags |= (sizeof(size_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||
format++;
|
||||
break;
|
||||
default: break;
|
||||
case 'j':
|
||||
flags |= (sizeof(intmax_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||
format++;
|
||||
break;
|
||||
case 'z':
|
||||
flags |= (sizeof(size_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||
format++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// evaluate specifier
|
||||
switch (*format) {
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'X':
|
||||
case 'o':
|
||||
case 'b': {
|
||||
// set the base
|
||||
unsigned int base;
|
||||
if (*format == 'x' || *format == 'X') {
|
||||
base = 16U;
|
||||
} else if (*format == 'o') {
|
||||
base = 8U;
|
||||
} else if (*format == 'b') {
|
||||
base = 2U;
|
||||
flags &= ~FLAGS_HASH; // no hash for bin format
|
||||
} else {
|
||||
base = 10U;
|
||||
flags &= ~FLAGS_HASH; // no hash for dec format
|
||||
}
|
||||
// uppercase
|
||||
if (*format == 'X') {
|
||||
flags |= FLAGS_UPPERCASE;
|
||||
}
|
||||
|
||||
// no plus or space flag for u, x, X, o, b
|
||||
if ((*format != 'i') && (*format != 'd')) {
|
||||
flags &= ~(FLAGS_PLUS | FLAGS_SPACE);
|
||||
}
|
||||
|
||||
// convert the integer
|
||||
if ((*format == 'i') || (*format == 'd')) {
|
||||
// signed
|
||||
if (flags & FLAGS_LONG_LONG) {
|
||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||
auto value = vaArgLongLong(va_list); // const long long value = va.next<long long>(cpu, mem);
|
||||
idx = _ntoa_long_long(out, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value), value < 0, base,
|
||||
precision, width, flags);
|
||||
#endif
|
||||
} else if (flags & FLAGS_LONG) {
|
||||
auto value = vaArgLong(va_list); // const long value = va.next<long>(cpu, mem);
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision, width,
|
||||
flags);
|
||||
} else {
|
||||
// const int value = (flags & FLAGS_CHAR) ? (char)va.next<int>(cpu, mem) : (flags & FLAGS_SHORT) ? (short
|
||||
// int)va.next<int>(cpu, mem): va.next<int>(cpu, mem);
|
||||
const int value = (flags & FLAGS_CHAR) ? static_cast<char>(vaArgInteger(va_list))
|
||||
: (flags & FLAGS_SHORT) ? static_cast<int16_t>(vaArgInteger(va_list))
|
||||
: vaArgInteger(va_list);
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0, base, precision, width,
|
||||
flags);
|
||||
}
|
||||
} else {
|
||||
// unsigned
|
||||
if (flags & FLAGS_LONG_LONG) {
|
||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||
// idx = _ntoa_long_long(out, buffer, idx, maxlen, va.next<unsigned long long>(cpu, mem), false, base, precision, width,
|
||||
// flags);
|
||||
idx =
|
||||
_ntoa_long_long(out, buffer, idx, maxlen, static_cast<u64>(vaArgLongLong(va_list)), false, base, precision, width, flags);
|
||||
#endif
|
||||
} else if (flags & FLAGS_LONG) {
|
||||
// idx = _ntoa_long(out, buffer, idx, maxlen, va.next<unsigned long>(cpu, mem), false, base, precision, width, flags);
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, static_cast<u32>(vaArgLong(va_list)), false, base, precision, width, flags);
|
||||
} else {
|
||||
// const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned char)va.next<unsigned int>(cpu, mem) : (flags & FLAGS_SHORT) ?
|
||||
// (unsigned short int)va.next<unsigned int>(cpu, mem) : va.next<unsigned int>(cpu, mem);
|
||||
const unsigned int value = (flags & FLAGS_CHAR) ? static_cast<u08>(vaArgInteger(va_list))
|
||||
: (flags & FLAGS_SHORT) ? static_cast<u16>(vaArgInteger(va_list))
|
||||
: static_cast<u32>(vaArgInteger(va_list));
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, flags);
|
||||
}
|
||||
}
|
||||
format++;
|
||||
break;
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'X':
|
||||
case 'o':
|
||||
case 'b': {
|
||||
// set the base
|
||||
unsigned int base;
|
||||
if (*format == 'x' || *format == 'X') {
|
||||
base = 16U;
|
||||
} else if (*format == 'o') {
|
||||
base = 8U;
|
||||
} else if (*format == 'b') {
|
||||
base = 2U;
|
||||
flags &= ~FLAGS_HASH; // no hash for bin format
|
||||
} else {
|
||||
base = 10U;
|
||||
flags &= ~FLAGS_HASH; // no hash for dec format
|
||||
}
|
||||
// uppercase
|
||||
if (*format == 'X') {
|
||||
flags |= FLAGS_UPPERCASE;
|
||||
}
|
||||
|
||||
// no plus or space flag for u, x, X, o, b
|
||||
if ((*format != 'i') && (*format != 'd')) {
|
||||
flags &= ~(FLAGS_PLUS | FLAGS_SPACE);
|
||||
}
|
||||
|
||||
// convert the integer
|
||||
if ((*format == 'i') || (*format == 'd')) {
|
||||
// signed
|
||||
if (flags & FLAGS_LONG_LONG) {
|
||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||
auto value = vaArgLongLong(
|
||||
va_list); // const long long value = va.next<long long>(cpu, mem);
|
||||
idx = _ntoa_long_long(out, buffer, idx, maxlen,
|
||||
(unsigned long long)(value > 0 ? value : 0 - value),
|
||||
value < 0, base, precision, width, flags);
|
||||
#endif
|
||||
} else if (flags & FLAGS_LONG) {
|
||||
auto value = vaArgLong(va_list); // const long value = va.next<long>(cpu, mem);
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen,
|
||||
(unsigned long)(value > 0 ? value : 0 - value), value < 0,
|
||||
base, precision, width, flags);
|
||||
} else {
|
||||
// const int value = (flags & FLAGS_CHAR) ? (char)va.next<int>(cpu, mem) :
|
||||
// (flags & FLAGS_SHORT) ? (short int)va.next<int>(cpu, mem): va.next<int>(cpu,
|
||||
// mem);
|
||||
const int value =
|
||||
(flags & FLAGS_CHAR) ? static_cast<char>(vaArgInteger(va_list))
|
||||
: (flags & FLAGS_SHORT) ? static_cast<int16_t>(vaArgInteger(va_list))
|
||||
: vaArgInteger(va_list);
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen,
|
||||
(unsigned int)(value > 0 ? value : 0 - value), value < 0, base,
|
||||
precision, width, flags);
|
||||
}
|
||||
} else {
|
||||
// unsigned
|
||||
if (flags & FLAGS_LONG_LONG) {
|
||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||
// idx = _ntoa_long_long(out, buffer, idx, maxlen, va.next<unsigned long
|
||||
// long>(cpu, mem), false, base, precision, width, flags);
|
||||
idx = _ntoa_long_long(out, buffer, idx, maxlen,
|
||||
static_cast<u64>(vaArgLongLong(va_list)), false, base,
|
||||
precision, width, flags);
|
||||
#endif
|
||||
} else if (flags & FLAGS_LONG) {
|
||||
// idx = _ntoa_long(out, buffer, idx, maxlen, va.next<unsigned long>(cpu, mem),
|
||||
// false, base, precision, width, flags);
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, static_cast<u32>(vaArgLong(va_list)),
|
||||
false, base, precision, width, flags);
|
||||
} else {
|
||||
// const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned
|
||||
// char)va.next<unsigned int>(cpu, mem) : (flags & FLAGS_SHORT) ?
|
||||
// (unsigned short int)va.next<unsigned int>(cpu, mem) : va.next<unsigned
|
||||
// int>(cpu, mem);
|
||||
const unsigned int value =
|
||||
(flags & FLAGS_CHAR) ? static_cast<u08>(vaArgInteger(va_list))
|
||||
: (flags & FLAGS_SHORT) ? static_cast<u16>(vaArgInteger(va_list))
|
||||
: static_cast<u32>(vaArgInteger(va_list));
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width,
|
||||
flags);
|
||||
}
|
||||
}
|
||||
format++;
|
||||
break;
|
||||
}
|
||||
#if defined(PRINTF_SUPPORT_FLOAT)
|
||||
case 'f':
|
||||
case 'F':
|
||||
// idx = _ftoa(out, buffer, idx, maxlen, va.next<double>(cpu, mem), precision, width, flags);
|
||||
idx = _ftoa(out, buffer, idx, maxlen, vaArgDouble(va_list), precision, width, flags);
|
||||
format++;
|
||||
break;
|
||||
#endif // PRINTF_SUPPORT_FLOAT
|
||||
case 'c': {
|
||||
unsigned int l = 1U;
|
||||
// pre padding
|
||||
if (!(flags & FLAGS_LEFT)) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
case 'f':
|
||||
case 'F':
|
||||
// idx = _ftoa(out, buffer, idx, maxlen, va.next<double>(cpu, mem), precision, width,
|
||||
// flags);
|
||||
idx = _ftoa(out, buffer, idx, maxlen, vaArgDouble(va_list), precision, width, flags);
|
||||
format++;
|
||||
break;
|
||||
#endif // PRINTF_SUPPORT_FLOAT
|
||||
case 'c': {
|
||||
unsigned int l = 1U;
|
||||
// pre padding
|
||||
if (!(flags & FLAGS_LEFT)) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
// char output
|
||||
// out((char)va.next<int>(cpu, mem), buffer, idx++, maxlen);
|
||||
out(static_cast<char>(vaArgInteger(va_list)), buffer, idx++, maxlen);
|
||||
// post padding
|
||||
if (flags & FLAGS_LEFT) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
format++;
|
||||
break;
|
||||
}
|
||||
|
||||
case 's': {
|
||||
const char* p = vaArgPtr<const char>(va_list); // const char *p = va.next<Ptr<char>>(cpu, mem).get(mem);
|
||||
p = p != nullptr ? p : "(null)";
|
||||
unsigned int l = _strlen(p);
|
||||
// pre padding
|
||||
if (flags & FLAGS_PRECISION) {
|
||||
l = (l < precision ? l : precision);
|
||||
// char output
|
||||
// out((char)va.next<int>(cpu, mem), buffer, idx++, maxlen);
|
||||
out(static_cast<char>(vaArgInteger(va_list)), buffer, idx++, maxlen);
|
||||
// post padding
|
||||
if (flags & FLAGS_LEFT) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
if (!(flags & FLAGS_LEFT)) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
// string output
|
||||
while ((*p != 0) && (!(flags & FLAGS_PRECISION) || precision--)) {
|
||||
out(*(p++), buffer, idx++, maxlen);
|
||||
}
|
||||
// post padding
|
||||
if (flags & FLAGS_LEFT) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
format++;
|
||||
break;
|
||||
}
|
||||
format++;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'p': {
|
||||
width = sizeof(void*) * 2U;
|
||||
flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE;
|
||||
case 's': {
|
||||
const char* p = vaArgPtr<const char>(
|
||||
va_list); // const char *p = va.next<Ptr<char>>(cpu, mem).get(mem);
|
||||
p = p != nullptr ? p : "(null)";
|
||||
unsigned int l = _strlen(p);
|
||||
// pre padding
|
||||
if (flags & FLAGS_PRECISION) {
|
||||
l = (l < precision ? l : precision);
|
||||
}
|
||||
if (!(flags & FLAGS_LEFT)) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
// string output
|
||||
while ((*p != 0) && (!(flags & FLAGS_PRECISION) || precision--)) {
|
||||
out(*(p++), buffer, idx++, maxlen);
|
||||
}
|
||||
// post padding
|
||||
if (flags & FLAGS_LEFT) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
format++;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'p': {
|
||||
width = sizeof(void*) * 2U;
|
||||
flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE;
|
||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||
const bool is_ll = sizeof(uintptr_t) == sizeof(long long);
|
||||
if (is_ll) {
|
||||
// idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va.next<Ptr<void>>(cpu, mem).address(), false, 16U, precision,
|
||||
// width, flags);
|
||||
idx = _ntoa_long_long(out, buffer, idx, maxlen, reinterpret_cast<uintptr_t>(vaArgPtr<void>(va_list)), false, 16U, precision,
|
||||
width, flags);
|
||||
} else {
|
||||
const bool is_ll = sizeof(uintptr_t) == sizeof(long long);
|
||||
if (is_ll) {
|
||||
// idx = _ntoa_long_long(out, buffer, idx, maxlen,
|
||||
// (uintptr_t)va.next<Ptr<void>>(cpu, mem).address(), false, 16U, precision, width,
|
||||
// flags);
|
||||
idx = _ntoa_long_long(out, buffer, idx, maxlen,
|
||||
reinterpret_cast<uintptr_t>(vaArgPtr<void>(va_list)), false,
|
||||
16U, precision, width, flags);
|
||||
} else {
|
||||
#endif
|
||||
// idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va.next<Ptr<void>>(cpu, mem).address()), false, 16U,
|
||||
// precision, width, flags);
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, static_cast<uint32_t>(reinterpret_cast<uintptr_t>(vaArgPtr<void>(va_list))), false,
|
||||
16U, precision, width, flags);
|
||||
// idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned
|
||||
// long)((uintptr_t)va.next<Ptr<void>>(cpu, mem).address()), false, 16U, precision,
|
||||
// width, flags);
|
||||
idx = _ntoa_long(
|
||||
out, buffer, idx, maxlen,
|
||||
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(vaArgPtr<void>(va_list))),
|
||||
false, 16U, precision, width, flags);
|
||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||
}
|
||||
#endif
|
||||
format++;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
format++;
|
||||
break;
|
||||
}
|
||||
|
||||
case '%':
|
||||
out('%', buffer, idx++, maxlen);
|
||||
format++;
|
||||
break;
|
||||
case '%':
|
||||
out('%', buffer, idx++, maxlen);
|
||||
format++;
|
||||
break;
|
||||
|
||||
default:
|
||||
out(*format, buffer, idx++, maxlen);
|
||||
format++;
|
||||
break;
|
||||
default:
|
||||
out(*format, buffer, idx++, maxlen);
|
||||
format++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -700,4 +738,4 @@ static int vsnprintf_ctx(char* s, size_t n, const char* format, VaList* arg) {
|
|||
std::strcpy(s, buffer);
|
||||
return result;
|
||||
}
|
||||
} // namespace Core::Libraries::LibC
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -1,29 +1,30 @@
|
|||
#include "common/types.h"
|
||||
#include <xmmintrin.h>
|
||||
#include "common/types.h"
|
||||
|
||||
#define VA_ARGS \
|
||||
uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_t rcx, uint64_t r8, uint64_t r9, uint64_t overflow_arg_area, __m128 xmm0, __m128 xmm1, \
|
||||
__m128 xmm2, __m128 xmm3, __m128 xmm4, __m128 xmm5, __m128 xmm6, __m128 xmm7, ...
|
||||
#define VA_ARGS \
|
||||
uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_t rcx, uint64_t r8, uint64_t r9, \
|
||||
uint64_t overflow_arg_area, __m128 xmm0, __m128 xmm1, __m128 xmm2, __m128 xmm3, \
|
||||
__m128 xmm4, __m128 xmm5, __m128 xmm6, __m128 xmm7, ...
|
||||
|
||||
#define VA_CTX(ctx) \
|
||||
alignas(16) VaCtx ctx; \
|
||||
(ctx).reg_save_area.gp[0] = rdi; \
|
||||
(ctx).reg_save_area.gp[1] = rsi; \
|
||||
(ctx).reg_save_area.gp[2] = rdx; \
|
||||
(ctx).reg_save_area.gp[3] = rcx; \
|
||||
(ctx).reg_save_area.gp[4] = r8; \
|
||||
(ctx).reg_save_area.gp[5] = r9; \
|
||||
(ctx).reg_save_area.fp[0] = xmm0; \
|
||||
(ctx).reg_save_area.fp[1] = xmm1; \
|
||||
(ctx).reg_save_area.fp[2] = xmm2; \
|
||||
(ctx).reg_save_area.fp[3] = xmm3; \
|
||||
(ctx).reg_save_area.fp[4] = xmm4; \
|
||||
(ctx).reg_save_area.fp[5] = xmm5; \
|
||||
(ctx).reg_save_area.fp[6] = xmm6; \
|
||||
(ctx).reg_save_area.fp[7] = xmm7; \
|
||||
(ctx).va_list.reg_save_area = &(ctx).reg_save_area; \
|
||||
(ctx).va_list.gp_offset = offsetof(VaRegSave, gp); \
|
||||
(ctx).va_list.fp_offset = offsetof(VaRegSave, fp); \
|
||||
#define VA_CTX(ctx) \
|
||||
alignas(16) VaCtx ctx; \
|
||||
(ctx).reg_save_area.gp[0] = rdi; \
|
||||
(ctx).reg_save_area.gp[1] = rsi; \
|
||||
(ctx).reg_save_area.gp[2] = rdx; \
|
||||
(ctx).reg_save_area.gp[3] = rcx; \
|
||||
(ctx).reg_save_area.gp[4] = r8; \
|
||||
(ctx).reg_save_area.gp[5] = r9; \
|
||||
(ctx).reg_save_area.fp[0] = xmm0; \
|
||||
(ctx).reg_save_area.fp[1] = xmm1; \
|
||||
(ctx).reg_save_area.fp[2] = xmm2; \
|
||||
(ctx).reg_save_area.fp[3] = xmm3; \
|
||||
(ctx).reg_save_area.fp[4] = xmm4; \
|
||||
(ctx).reg_save_area.fp[5] = xmm5; \
|
||||
(ctx).reg_save_area.fp[6] = xmm6; \
|
||||
(ctx).reg_save_area.fp[7] = xmm7; \
|
||||
(ctx).va_list.reg_save_area = &(ctx).reg_save_area; \
|
||||
(ctx).va_list.gp_offset = offsetof(VaRegSave, gp); \
|
||||
(ctx).va_list.fp_offset = offsetof(VaRegSave, fp); \
|
||||
(ctx).va_list.overflow_arg_area = &overflow_arg_area;
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
#include "common/log.h"
|
||||
#include <common/singleton.h>
|
||||
#include <core/file_sys/fs.h>
|
||||
#include <core/hle/error_codes.h>
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "core/hle/libraries/libkernel/file_system.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
#include <core/file_sys/fs.h>
|
||||
#include <common/singleton.h>
|
||||
#include <core/hle/error_codes.h>
|
||||
|
||||
namespace Core::Libraries::LibKernel {
|
||||
|
||||
constexpr bool log_file_fs = true; // disable it to disable logging
|
||||
constexpr bool log_file_fs = true; // disable it to disable logging
|
||||
|
||||
int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) {
|
||||
LOG_INFO_IF(log_file_fs, "sceKernelOpen path = {} flags = {:#x} mode = {:#x}\n", path, flags, mode);
|
||||
LOG_INFO_IF(log_file_fs, "sceKernelOpen path = {} flags = {:#x} mode = {:#x}\n", path, flags,
|
||||
mode);
|
||||
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
|
||||
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
|
||||
|
||||
|
@ -34,7 +35,7 @@ int PS4_SYSV_ABI posix_open(const char* path, int flags, /* SceKernelMode*/ u16
|
|||
LOG_INFO_IF(log_file_fs, "posix open redirect to sceKernelOpen\n");
|
||||
int result = sceKernelOpen(path, flags, mode);
|
||||
if (result < 0) {
|
||||
BREAKPOINT(); // posix calls different only for their return values
|
||||
BREAKPOINT(); // posix calls different only for their return values
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -45,7 +46,7 @@ size_t PS4_SYSV_ABI _readv(int d, const SceKernelIovec* iov, int iovcnt) {
|
|||
size_t total_read = 0;
|
||||
file->m_mutex.lock();
|
||||
for (int i = 0; i < iovcnt; i++) {
|
||||
total_read += file->f.readBytes(iov[i].iov_base,iov[i].iov_len).second;
|
||||
total_read += file->f.readBytes(iov[i].iov_base, iov[i].iov_len).second;
|
||||
}
|
||||
file->m_mutex.unlock();
|
||||
return total_read;
|
||||
|
@ -57,7 +58,8 @@ void fileSystemSymbolsRegister(Loader::SymbolsResolver* sym) {
|
|||
LIB_FUNCTION("+WRlkKjZvag", "libkernel", 1, "libkernel", 1, 1, _readv);
|
||||
|
||||
// openOrbis (to check if it is valid out of OpenOrbis
|
||||
LIB_FUNCTION("6c3rCVE-fTU", "libkernel", 1, "libkernel", 1, 1, posix_open); // _open shoudld be equal to open function
|
||||
LIB_FUNCTION("6c3rCVE-fTU", "libkernel", 1, "libkernel", 1, 1,
|
||||
posix_open); // _open shoudld be equal to open function
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
|
|
|
@ -9,14 +9,14 @@ class SymbolsResolver;
|
|||
namespace Core::Libraries::LibKernel {
|
||||
|
||||
struct SceKernelIovec {
|
||||
void *iov_base;
|
||||
void* iov_base;
|
||||
size_t iov_len;
|
||||
};
|
||||
|
||||
int PS4_SYSV_ABI sceKernelOpen(const char *path, int flags, /* SceKernelMode*/ u16 mode);
|
||||
int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, /* SceKernelMode*/ u16 mode);
|
||||
|
||||
int PS4_SYSV_ABI posix_open(const char *path, int flags, /* SceKernelMode*/ u16 mode);
|
||||
int PS4_SYSV_ABI posix_open(const char* path, int flags, /* SceKernelMode*/ u16 mode);
|
||||
|
||||
void fileSystemSymbolsRegister(Loader::SymbolsResolver *sym);
|
||||
void fileSystemSymbolsRegister(Loader::SymbolsResolver* sym);
|
||||
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
#include "core/loader/elf.h"
|
||||
|
||||
#ifdef _WIN64
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
@ -22,20 +22,26 @@
|
|||
|
||||
namespace Core::Libraries::LibKernel {
|
||||
|
||||
constexpr bool log_libkernel_file = true; // disable it to disable logging
|
||||
constexpr bool log_libkernel_file = true; // disable it to disable logging
|
||||
|
||||
static u64 g_stack_chk_guard = 0xDEADBEEF54321ABC; // dummy return
|
||||
static u64 g_stack_chk_guard = 0xDEADBEEF54321ABC; // dummy return
|
||||
|
||||
int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len) {
|
||||
BREAKPOINT();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PS4_SYSV_ABI void stack_chk_fail() { BREAKPOINT(); }
|
||||
static PS4_SYSV_ABI void stack_chk_fail() {
|
||||
BREAKPOINT();
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) { BREAKPOINT(); }
|
||||
int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) {
|
||||
BREAKPOINT();
|
||||
}
|
||||
|
||||
void PS4_SYSV_ABI sceKernelUsleep(unsigned int microseconds) { std::this_thread::sleep_for(std::chrono::microseconds(microseconds)); }
|
||||
void PS4_SYSV_ABI sceKernelUsleep(unsigned int microseconds) {
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(microseconds));
|
||||
}
|
||||
|
||||
struct iovec {
|
||||
void* iov_base; /* Base address. */
|
||||
|
@ -43,7 +49,8 @@ struct iovec {
|
|||
};
|
||||
|
||||
size_t PS4_SYSV_ABI _writev(int fd, const struct iovec* iov, int iovcn) {
|
||||
// weird it gives fd ==0 and writes to stdout , i am not sure if it that is valid (found in openorbis)
|
||||
// weird it gives fd ==0 and writes to stdout , i am not sure if it that is valid (found in
|
||||
// openorbis)
|
||||
size_t total_written = 0;
|
||||
for (int i = 0; i < iovcn; i++) {
|
||||
total_written += ::fwrite(iov[i].iov_base, 1, iov[i].iov_len, stdout);
|
||||
|
@ -52,15 +59,18 @@ size_t PS4_SYSV_ABI _writev(int fd, const struct iovec* iov, int iovcn) {
|
|||
}
|
||||
|
||||
static thread_local int libc_error;
|
||||
int* PS4_SYSV_ABI __Error() { return &libc_error; }
|
||||
int* PS4_SYSV_ABI __Error() {
|
||||
return &libc_error;
|
||||
}
|
||||
|
||||
#define PROT_READ 0x1
|
||||
#define PROT_WRITE 0x2
|
||||
|
||||
int PS4_SYSV_ABI sceKernelMmap(void* addr, u64 len, int prot, int flags, int fd, off_t offset, void** res) {
|
||||
int PS4_SYSV_ABI sceKernelMmap(void* addr, u64 len, int prot, int flags, int fd, off_t offset,
|
||||
void** res) {
|
||||
#ifdef _WIN64
|
||||
PRINT_FUNCTION_NAME();
|
||||
if (prot > 3) // READ,WRITE or bitwise READ | WRITE supported
|
||||
if (prot > 3) // READ,WRITE or bitwise READ | WRITE supported
|
||||
{
|
||||
LOG_ERROR_IF(log_libkernel_file, "sceKernelMmap prot ={} not supported\n", prot);
|
||||
}
|
||||
|
@ -76,7 +86,8 @@ int PS4_SYSV_ABI sceKernelMmap(void* addr, u64 len, int prot, int flags, int fd,
|
|||
mmap_fd = (HANDLE)_get_osfhandle(fd);
|
||||
h = CreateFileMapping(mmap_fd, NULL, flProtect, 0, end, NULL);
|
||||
int k = GetLastError();
|
||||
if (NULL == h) return -1;
|
||||
if (NULL == h)
|
||||
return -1;
|
||||
DWORD dwDesiredAccess;
|
||||
if (prot & PROT_WRITE)
|
||||
dwDesiredAccess = FILE_MAP_WRITE;
|
||||
|
@ -102,7 +113,8 @@ int PS4_SYSV_ABI sceKernelMmap(void* addr, u64 len, int prot, int flags, int fd,
|
|||
PS4_SYSV_ABI void* posix_mmap(void* addr, u64 len, int prot, int flags, int fd, u64 offset) {
|
||||
void* ptr;
|
||||
LOG_INFO_IF(log_libkernel_file, "posix mmap redirect to sceKernelMmap\n");
|
||||
// posix call the difference is that there is a different behaviour when it doesn't return 0 or SCE_OK
|
||||
// posix call the difference is that there is a different behaviour when it doesn't return 0 or
|
||||
// SCE_OK
|
||||
int result = sceKernelMmap(addr, len, prot, flags, fd, offset, &ptr);
|
||||
if (result != 0) {
|
||||
BREAKPOINT();
|
||||
|
@ -114,9 +126,12 @@ void LibKernel_Register(Loader::SymbolsResolver* sym) {
|
|||
// obj
|
||||
LIB_OBJ("f7uOxY9mM1U", "libkernel", 1, "libkernel", 1, 1, &g_stack_chk_guard);
|
||||
// memory
|
||||
LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelAllocateDirectMemory);
|
||||
LIB_FUNCTION("pO96TwzOm5E", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelGetDirectMemorySize);
|
||||
LIB_FUNCTION("L-Q3LEjIbgA", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelMapDirectMemory);
|
||||
LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1,
|
||||
Kernel::sceKernelAllocateDirectMemory);
|
||||
LIB_FUNCTION("pO96TwzOm5E", "libkernel", 1, "libkernel", 1, 1,
|
||||
Kernel::sceKernelGetDirectMemorySize);
|
||||
LIB_FUNCTION("L-Q3LEjIbgA", "libkernel", 1, "libkernel", 1, 1,
|
||||
Kernel::sceKernelMapDirectMemory);
|
||||
LIB_FUNCTION("MBuItvba6z8", "libkernel", 1, "libkernel", 1, 1, sceKernelReleaseDirectMemory);
|
||||
LIB_FUNCTION("cQke9UuBQOk", "libkernel", 1, "libkernel", 1, 1, sceKernelMunmap);
|
||||
// equeue
|
||||
|
@ -135,4 +150,4 @@ void LibKernel_Register(Loader::SymbolsResolver* sym) {
|
|||
Core::Libraries::LibKernel::pthreadSymbolsRegister(sym);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
|
|
|
@ -15,4 +15,4 @@ int* PS4_SYSV_ABI __Error();
|
|||
|
||||
void LibKernel_Register(Loader::SymbolsResolver* sym);
|
||||
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace Core::Libraries::LibKernel {
|
|||
thread_local ScePthread g_pthread_self{};
|
||||
PThreadCxt* g_pthread_cxt = nullptr;
|
||||
|
||||
constexpr bool log_pthread_file = true; // disable it to disable logging
|
||||
constexpr bool log_pthread_file = true; // disable it to disable logging
|
||||
|
||||
void init_pthreads() {
|
||||
g_pthread_cxt = new PThreadCxt{};
|
||||
|
@ -49,9 +49,12 @@ int PS4_SYSV_ABI scePthreadAttrInit(ScePthreadAttr* attr) {
|
|||
result = (result == 0 ? scePthreadAttrSetdetachstate(attr, PTHREAD_CREATE_JOINABLE) : result);
|
||||
|
||||
switch (result) {
|
||||
case 0: return SCE_OK;
|
||||
case ENOMEM: return SCE_KERNEL_ERROR_ENOMEM;
|
||||
default: return SCE_KERNEL_ERROR_EINVAL;
|
||||
case 0:
|
||||
return SCE_OK;
|
||||
case ENOMEM:
|
||||
return SCE_KERNEL_ERROR_ENOMEM;
|
||||
default:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,12 +65,20 @@ int PS4_SYSV_ABI scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachst
|
|||
|
||||
int pstate = PTHREAD_CREATE_JOINABLE;
|
||||
switch (detachstate) {
|
||||
case 0: pstate = PTHREAD_CREATE_JOINABLE; break;
|
||||
case 1: pstate = PTHREAD_CREATE_DETACHED; break;
|
||||
default: LOG_TRACE_IF(log_pthread_file, "scePthreadAttrSetdetachstate invalid detachstate: {}\n", detachstate); std::exit(0);
|
||||
case 0:
|
||||
pstate = PTHREAD_CREATE_JOINABLE;
|
||||
break;
|
||||
case 1:
|
||||
pstate = PTHREAD_CREATE_DETACHED;
|
||||
break;
|
||||
default:
|
||||
LOG_TRACE_IF(log_pthread_file, "scePthreadAttrSetdetachstate invalid detachstate: {}\n",
|
||||
detachstate);
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
// int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate); doesn't seem to work correctly
|
||||
// int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate); doesn't seem to work
|
||||
// correctly
|
||||
int result = 0;
|
||||
|
||||
(*attr)->detached = (pstate == PTHREAD_CREATE_DETACHED);
|
||||
|
@ -82,9 +93,16 @@ int PS4_SYSV_ABI scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inherit
|
|||
|
||||
int pinherit_sched = PTHREAD_INHERIT_SCHED;
|
||||
switch (inheritSched) {
|
||||
case 0: pinherit_sched = PTHREAD_EXPLICIT_SCHED; break;
|
||||
case 4: pinherit_sched = PTHREAD_INHERIT_SCHED; break;
|
||||
default: LOG_TRACE_IF(log_pthread_file, "scePthreadAttrSetinheritsched invalid inheritSched: {}\n", inheritSched); std::exit(0);
|
||||
case 0:
|
||||
pinherit_sched = PTHREAD_EXPLICIT_SCHED;
|
||||
break;
|
||||
case 4:
|
||||
pinherit_sched = PTHREAD_INHERIT_SCHED;
|
||||
break;
|
||||
default:
|
||||
LOG_TRACE_IF(log_pthread_file, "scePthreadAttrSetinheritsched invalid inheritSched: {}\n",
|
||||
inheritSched);
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
int result = pthread_attr_setinheritsched(&(*attr)->pth_attr, pinherit_sched);
|
||||
|
@ -92,7 +110,8 @@ int PS4_SYSV_ABI scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inherit
|
|||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param) {
|
||||
int PS4_SYSV_ABI scePthreadAttrSetschedparam(ScePthreadAttr* attr,
|
||||
const SceKernelSchedParam* param) {
|
||||
if (param == nullptr || attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
@ -116,9 +135,11 @@ int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy)
|
|||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int ppolicy = SCHED_OTHER; // winpthreads only supports SCHED_OTHER
|
||||
int ppolicy = SCHED_OTHER; // winpthreads only supports SCHED_OTHER
|
||||
if (policy != SCHED_OTHER) {
|
||||
LOG_TRACE_IF(log_pthread_file, "scePthreadAttrSetschedpolicy policy={} not supported by winpthreads\n", policy);
|
||||
LOG_TRACE_IF(log_pthread_file,
|
||||
"scePthreadAttrSetschedpolicy policy={} not supported by winpthreads\n",
|
||||
policy);
|
||||
}
|
||||
(*attr)->policy = policy;
|
||||
|
||||
|
@ -126,9 +147,12 @@ int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy)
|
|||
|
||||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
ScePthread PS4_SYSV_ABI scePthreadSelf() { return g_pthread_self; }
|
||||
ScePthread PS4_SYSV_ABI scePthreadSelf() {
|
||||
return g_pthread_self;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrSetaffinity(ScePthreadAttr* pattr, const /*SceKernelCpumask*/ u64 mask) {
|
||||
int PS4_SYSV_ABI scePthreadAttrSetaffinity(ScePthreadAttr* pattr,
|
||||
const /*SceKernelCpumask*/ u64 mask) {
|
||||
PRINT_FUNCTION_NAME();
|
||||
|
||||
if (pattr == nullptr || *pattr == nullptr) {
|
||||
|
@ -151,7 +175,8 @@ int PS4_SYSV_ABI scePthreadSetaffinity(ScePthread thread, const /*SceKernelCpuma
|
|||
|
||||
return result;
|
||||
}
|
||||
int PS4_SYSV_ABI scePthreadCreate(ScePthread* thread, const ScePthreadAttr* attr, pthreadEntryFunc start_routine, void* arg, const char* name) {
|
||||
int PS4_SYSV_ABI scePthreadCreate(ScePthread* thread, const ScePthreadAttr* attr,
|
||||
pthreadEntryFunc start_routine, void* arg, const char* name) {
|
||||
PRINT_DUMMY_FUNCTION_NAME();
|
||||
return 0;
|
||||
}
|
||||
|
@ -169,7 +194,8 @@ void* createMutex(void* addr) {
|
|||
return addr;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr, const char* name) {
|
||||
int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr,
|
||||
const char* name) {
|
||||
PRINT_FUNCTION_NAME();
|
||||
if (mutex == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
|
@ -192,11 +218,16 @@ int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMut
|
|||
}
|
||||
|
||||
switch (result) {
|
||||
case 0: return SCE_OK;
|
||||
case EAGAIN: return SCE_KERNEL_ERROR_EAGAIN;
|
||||
case EINVAL: return SCE_KERNEL_ERROR_EINVAL;
|
||||
case ENOMEM: return SCE_KERNEL_ERROR_ENOMEM;
|
||||
default: return SCE_KERNEL_ERROR_EINVAL;
|
||||
case 0:
|
||||
return SCE_OK;
|
||||
case EAGAIN:
|
||||
return SCE_KERNEL_ERROR_EAGAIN;
|
||||
case EINVAL:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
case ENOMEM:
|
||||
return SCE_KERNEL_ERROR_ENOMEM;
|
||||
default:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,20 +240,31 @@ int PS4_SYSV_ABI scePthreadMutexattrInit(ScePthreadMutexattr* attr) {
|
|||
result = (result == 0 ? scePthreadMutexattrSetprotocol(attr, 0) : result);
|
||||
|
||||
switch (result) {
|
||||
case 0: return SCE_OK;
|
||||
case ENOMEM: return SCE_KERNEL_ERROR_ENOMEM;
|
||||
default: return SCE_KERNEL_ERROR_EINVAL;
|
||||
case 0:
|
||||
return SCE_OK;
|
||||
case ENOMEM:
|
||||
return SCE_KERNEL_ERROR_ENOMEM;
|
||||
default:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadMutexattrSettype(ScePthreadMutexattr* attr, int type) {
|
||||
int ptype = PTHREAD_MUTEX_DEFAULT;
|
||||
switch (type) {
|
||||
case 1: ptype = PTHREAD_MUTEX_ERRORCHECK; break;
|
||||
case 2: ptype = PTHREAD_MUTEX_RECURSIVE; break;
|
||||
case 3:
|
||||
case 4: ptype = PTHREAD_MUTEX_NORMAL; break;
|
||||
default: LOG_TRACE_IF(log_pthread_file, "scePthreadMutexattrSettype invalid type: {}\n", type); std::exit(0);
|
||||
case 1:
|
||||
ptype = PTHREAD_MUTEX_ERRORCHECK;
|
||||
break;
|
||||
case 2:
|
||||
ptype = PTHREAD_MUTEX_RECURSIVE;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
ptype = PTHREAD_MUTEX_NORMAL;
|
||||
break;
|
||||
default:
|
||||
LOG_TRACE_IF(log_pthread_file, "scePthreadMutexattrSettype invalid type: {}\n", type);
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
int result = pthread_mutexattr_settype(&(*attr)->pth_mutex_attr, ptype);
|
||||
|
@ -233,13 +275,23 @@ int PS4_SYSV_ABI scePthreadMutexattrSettype(ScePthreadMutexattr* attr, int type)
|
|||
int PS4_SYSV_ABI scePthreadMutexattrSetprotocol(ScePthreadMutexattr* attr, int protocol) {
|
||||
int pprotocol = PTHREAD_PRIO_NONE;
|
||||
switch (protocol) {
|
||||
case 0: pprotocol = PTHREAD_PRIO_NONE; break;
|
||||
case 1: pprotocol = PTHREAD_PRIO_INHERIT; break;
|
||||
case 2: pprotocol = PTHREAD_PRIO_PROTECT; break;
|
||||
default: LOG_TRACE_IF(log_pthread_file, "scePthreadMutexattrSetprotocol invalid protocol: {}\n", protocol); std::exit(0);
|
||||
case 0:
|
||||
pprotocol = PTHREAD_PRIO_NONE;
|
||||
break;
|
||||
case 1:
|
||||
pprotocol = PTHREAD_PRIO_INHERIT;
|
||||
break;
|
||||
case 2:
|
||||
pprotocol = PTHREAD_PRIO_PROTECT;
|
||||
break;
|
||||
default:
|
||||
LOG_TRACE_IF(log_pthread_file, "scePthreadMutexattrSetprotocol invalid protocol: {}\n",
|
||||
protocol);
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
int result = 0; // pthread_mutexattr_setprotocol(&(*attr)->p, pprotocol); //it appears that pprotocol has issues in winpthreads
|
||||
int result = 0; // pthread_mutexattr_setprotocol(&(*attr)->p, pprotocol); //it appears that
|
||||
// pprotocol has issues in winpthreads
|
||||
(*attr)->pprotocol = pprotocol;
|
||||
|
||||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
||||
|
@ -253,13 +305,19 @@ int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex) {
|
|||
}
|
||||
|
||||
int result = pthread_mutex_lock(&(*mutex)->pth_mutex);
|
||||
LOG_INFO_IF(log_pthread_file, "scePthreadMutexLock name={} result={}\n", (*mutex)->name, result);
|
||||
LOG_INFO_IF(log_pthread_file, "scePthreadMutexLock name={} result={}\n", (*mutex)->name,
|
||||
result);
|
||||
switch (result) {
|
||||
case 0: return SCE_OK;
|
||||
case EAGAIN: return SCE_KERNEL_ERROR_EAGAIN;
|
||||
case EINVAL: return SCE_KERNEL_ERROR_EINVAL;
|
||||
case EDEADLK: return SCE_KERNEL_ERROR_EDEADLK;
|
||||
default: return SCE_KERNEL_ERROR_EINVAL;
|
||||
case 0:
|
||||
return SCE_OK;
|
||||
case EAGAIN:
|
||||
return SCE_KERNEL_ERROR_EAGAIN;
|
||||
case EINVAL:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
case EDEADLK:
|
||||
return SCE_KERNEL_ERROR_EDEADLK;
|
||||
default:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
int PS4_SYSV_ABI scePthreadMutexUnlock(ScePthreadMutex* mutex) {
|
||||
|
@ -270,13 +328,18 @@ int PS4_SYSV_ABI scePthreadMutexUnlock(ScePthreadMutex* mutex) {
|
|||
}
|
||||
|
||||
int result = pthread_mutex_unlock(&(*mutex)->pth_mutex);
|
||||
LOG_INFO_IF(log_pthread_file, "scePthreadMutexUnlock name={} result={}\n", (*mutex)->name, result);
|
||||
LOG_INFO_IF(log_pthread_file, "scePthreadMutexUnlock name={} result={}\n", (*mutex)->name,
|
||||
result);
|
||||
switch (result) {
|
||||
case 0: return SCE_OK;
|
||||
case 0:
|
||||
return SCE_OK;
|
||||
|
||||
case EINVAL: return SCE_KERNEL_ERROR_EINVAL;
|
||||
case EPERM: return SCE_KERNEL_ERROR_EPERM;
|
||||
default: return SCE_KERNEL_ERROR_EINVAL;
|
||||
case EINVAL:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
case EPERM:
|
||||
return SCE_KERNEL_ERROR_EPERM;
|
||||
default:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,7 +357,8 @@ void* createCond(void* addr) {
|
|||
return addr;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadCondInit(ScePthreadCond* cond, const ScePthreadCondattr* attr, const char* name) {
|
||||
int PS4_SYSV_ABI scePthreadCondInit(ScePthreadCond* cond, const ScePthreadCondattr* attr,
|
||||
const char* name) {
|
||||
if (cond == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
@ -318,11 +382,16 @@ int PS4_SYSV_ABI scePthreadCondInit(ScePthreadCond* cond, const ScePthreadCondat
|
|||
}
|
||||
|
||||
switch (result) {
|
||||
case 0: return SCE_OK;
|
||||
case EAGAIN: return SCE_KERNEL_ERROR_EAGAIN;
|
||||
case EINVAL: return SCE_KERNEL_ERROR_EINVAL;
|
||||
case ENOMEM: return SCE_KERNEL_ERROR_ENOMEM;
|
||||
default: return SCE_KERNEL_ERROR_EINVAL;
|
||||
case 0:
|
||||
return SCE_OK;
|
||||
case EAGAIN:
|
||||
return SCE_KERNEL_ERROR_EAGAIN;
|
||||
case EINVAL:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
case ENOMEM:
|
||||
return SCE_KERNEL_ERROR_ENOMEM;
|
||||
default:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,9 +401,12 @@ int PS4_SYSV_ABI scePthreadCondattrInit(ScePthreadCondattr* attr) {
|
|||
int result = pthread_condattr_init(&(*attr)->cond_attr);
|
||||
|
||||
switch (result) {
|
||||
case 0: return SCE_OK;
|
||||
case ENOMEM: return SCE_KERNEL_ERROR_ENOMEM;
|
||||
default: return SCE_KERNEL_ERROR_EINVAL;
|
||||
case 0:
|
||||
return SCE_OK;
|
||||
case ENOMEM:
|
||||
return SCE_KERNEL_ERROR_ENOMEM;
|
||||
default:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,7 +431,9 @@ int PS4_SYSV_ABI posix_pthread_mutex_init(ScePthreadMutex* mutex, const ScePthre
|
|||
LOG_INFO_IF(log_pthread_file, "posix pthread_mutex_init redirect to scePthreadMutexInit\n");
|
||||
int result = scePthreadMutexInit(mutex, attr, nullptr);
|
||||
if (result < 0) {
|
||||
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP ? result + -SCE_KERNEL_ERROR_UNKNOWN : POSIX_EOTHER;
|
||||
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
||||
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
||||
: POSIX_EOTHER;
|
||||
return rt;
|
||||
}
|
||||
return result;
|
||||
|
@ -369,7 +443,9 @@ int PS4_SYSV_ABI posix_pthread_mutex_lock(ScePthreadMutex* mutex) {
|
|||
LOG_INFO_IF(log_pthread_file, "posix pthread_mutex_lock redirect to scePthreadMutexLock\n");
|
||||
int result = scePthreadMutexLock(mutex);
|
||||
if (result < 0) {
|
||||
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP ? result + -SCE_KERNEL_ERROR_UNKNOWN : POSIX_EOTHER;
|
||||
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
||||
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
||||
: POSIX_EOTHER;
|
||||
return rt;
|
||||
}
|
||||
return result;
|
||||
|
@ -379,17 +455,22 @@ int PS4_SYSV_ABI posix_pthread_mutex_unlock(ScePthreadMutex* mutex) {
|
|||
LOG_INFO_IF(log_pthread_file, "posix pthread_mutex_unlock redirect to scePthreadMutexUnlock\n");
|
||||
int result = scePthreadMutexUnlock(mutex);
|
||||
if (result < 0) {
|
||||
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP ? result + -SCE_KERNEL_ERROR_UNKNOWN : POSIX_EOTHER;
|
||||
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
||||
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
||||
: POSIX_EOTHER;
|
||||
return rt;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI posix_pthread_cond_broadcast(ScePthreadCond* cond) {
|
||||
LOG_INFO_IF(log_pthread_file, "posix posix_pthread_cond_broadcast redirect to scePthreadCondBroadcast\n");
|
||||
LOG_INFO_IF(log_pthread_file,
|
||||
"posix posix_pthread_cond_broadcast redirect to scePthreadCondBroadcast\n");
|
||||
int result = scePthreadCondBroadcast(cond);
|
||||
if (result != 0) {
|
||||
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP ? result + -SCE_KERNEL_ERROR_UNKNOWN : POSIX_EOTHER;
|
||||
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
||||
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
||||
: POSIX_EOTHER;
|
||||
return rt;
|
||||
}
|
||||
return result;
|
||||
|
@ -412,7 +493,7 @@ void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) {
|
|||
LIB_FUNCTION("1FGvU0i9saQ", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrSetprotocol);
|
||||
LIB_FUNCTION("9UK1vLZQft4", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexLock);
|
||||
LIB_FUNCTION("tn3VlD0hG60", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexUnlock);
|
||||
//cond calls
|
||||
// cond calls
|
||||
LIB_FUNCTION("2Tb92quprl0", "libkernel", 1, "libkernel", 1, 1, scePthreadCondInit);
|
||||
LIB_FUNCTION("m5-2bsNfv7s", "libkernel", 1, "libkernel", 1, 1, scePthreadCondattrInit);
|
||||
LIB_FUNCTION("JGgj7Uvrl+A", "libkernel", 1, "libkernel", 1, 1, scePthreadCondBroadcast);
|
||||
|
@ -428,4 +509,4 @@ void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) {
|
|||
LIB_FUNCTION("mkx2fVhNMsg", "libkernel", 1, "libkernel", 1, 1, posix_pthread_cond_broadcast);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
} // namespace Core::Libraries::LibKernel
|
|
@ -71,13 +71,21 @@ struct PthreadCondAttrInternal {
|
|||
};
|
||||
|
||||
class PThreadCxt {
|
||||
public:
|
||||
ScePthreadMutexattr* getDefaultMutexattr() { return &m_default_mutexattr; }
|
||||
void setDefaultMutexattr(ScePthreadMutexattr attr) { m_default_mutexattr = attr; }
|
||||
ScePthreadCondattr* getDefaultCondattr() { return &m_default_condattr; }
|
||||
void setDefaultCondattr(ScePthreadCondattr attr) { m_default_condattr = attr; }
|
||||
public:
|
||||
ScePthreadMutexattr* getDefaultMutexattr() {
|
||||
return &m_default_mutexattr;
|
||||
}
|
||||
void setDefaultMutexattr(ScePthreadMutexattr attr) {
|
||||
m_default_mutexattr = attr;
|
||||
}
|
||||
ScePthreadCondattr* getDefaultCondattr() {
|
||||
return &m_default_condattr;
|
||||
}
|
||||
void setDefaultCondattr(ScePthreadCondattr attr) {
|
||||
m_default_condattr = attr;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
ScePthreadMutexattr m_default_mutexattr = nullptr;
|
||||
ScePthreadCondattr m_default_condattr = nullptr;
|
||||
};
|
||||
|
@ -88,17 +96,21 @@ void pthreadInitSelfMainThread();
|
|||
int PS4_SYSV_ABI scePthreadAttrInit(ScePthreadAttr* attr);
|
||||
int PS4_SYSV_ABI scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate);
|
||||
int PS4_SYSV_ABI scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched);
|
||||
int PS4_SYSV_ABI scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param);
|
||||
int PS4_SYSV_ABI scePthreadAttrSetschedparam(ScePthreadAttr* attr,
|
||||
const SceKernelSchedParam* param);
|
||||
int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy);
|
||||
ScePthread PS4_SYSV_ABI scePthreadSelf();
|
||||
int PS4_SYSV_ABI scePthreadAttrSetaffinity(ScePthreadAttr* pattr, const /*SceKernelCpumask*/ u64 mask);
|
||||
int PS4_SYSV_ABI scePthreadAttrSetaffinity(ScePthreadAttr* pattr,
|
||||
const /*SceKernelCpumask*/ u64 mask);
|
||||
int PS4_SYSV_ABI scePthreadSetaffinity(ScePthread thread, const /*SceKernelCpumask*/ u64 mask);
|
||||
int PS4_SYSV_ABI scePthreadCreate(ScePthread* thread, const ScePthreadAttr* attr, pthreadEntryFunc start_routine, void* arg, const char* name);
|
||||
int PS4_SYSV_ABI scePthreadCreate(ScePthread* thread, const ScePthreadAttr* attr,
|
||||
pthreadEntryFunc start_routine, void* arg, const char* name);
|
||||
|
||||
/***
|
||||
* Mutex calls
|
||||
*/
|
||||
int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr, const char* name);
|
||||
int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr,
|
||||
const char* name);
|
||||
int PS4_SYSV_ABI scePthreadMutexattrInit(ScePthreadMutexattr* attr);
|
||||
int PS4_SYSV_ABI scePthreadMutexattrSettype(ScePthreadMutexattr* attr, int type);
|
||||
int PS4_SYSV_ABI scePthreadMutexattrSetprotocol(ScePthreadMutexattr* attr, int protocol);
|
||||
|
@ -107,10 +119,11 @@ int PS4_SYSV_ABI scePthreadMutexUnlock(ScePthreadMutex* mutex);
|
|||
/****
|
||||
* Cond calls
|
||||
*/
|
||||
int PS4_SYSV_ABI scePthreadCondInit(ScePthreadCond* cond, const ScePthreadCondattr* attr, const char* name);
|
||||
int PS4_SYSV_ABI scePthreadCondInit(ScePthreadCond* cond, const ScePthreadCondattr* attr,
|
||||
const char* name);
|
||||
int PS4_SYSV_ABI scePthreadCondattrInit(ScePthreadCondattr* attr);
|
||||
int PS4_SYSV_ABI scePthreadCondBroadcast(ScePthreadCond* cond);
|
||||
/****
|
||||
/****
|
||||
* Posix calls
|
||||
*/
|
||||
int PS4_SYSV_ABI posix_pthread_mutex_init(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr);
|
||||
|
@ -119,4 +132,4 @@ int PS4_SYSV_ABI posix_pthread_mutex_unlock(ScePthreadMutex* mutex);
|
|||
int PS4_SYSV_ABI posix_pthread_cond_broadcast(ScePthreadCond* cond);
|
||||
|
||||
void pthreadSymbolsRegister(Loader::SymbolsResolver* sym);
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
} // namespace Core::Libraries::LibKernel
|
|
@ -26,10 +26,11 @@ u64 PS4_SYSV_ABI sceKernelReadTsc() {
|
|||
void timeSymbolsRegister(Loader::SymbolsResolver* sym) {
|
||||
clock = std::make_unique<Common::NativeClock>();
|
||||
initial_ptc = clock->GetUptime();
|
||||
LIB_FUNCTION("4J2sUJmuHZQ", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcessTime);
|
||||
LIB_FUNCTION("4J2sUJmuHZQ", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcessTime);
|
||||
LIB_FUNCTION("fgxnMeTNUtY", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcessTimeCounter);
|
||||
LIB_FUNCTION("BNowx2l588E", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcessTimeCounterFrequency);
|
||||
LIB_FUNCTION("BNowx2l588E", "libkernel", 1, "libkernel", 1, 1,
|
||||
sceKernelGetProcessTimeCounterFrequency);
|
||||
LIB_FUNCTION("-2IRUCO--PM", "libkernel", 1, "libkernel", 1, 1, sceKernelReadTsc);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
#include "Emulator/Host/controller.h"
|
||||
#include "common/log.h"
|
||||
#include "common/singleton.h"
|
||||
#include "core/hle/libraries/libpad/pad.h"
|
||||
#include "core/hle/error_codes.h"
|
||||
#include "core/hle/libraries/libpad/pad.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
#include "Emulator/Host/controller.h"
|
||||
|
||||
namespace Core::Libraries::LibPad {
|
||||
|
||||
constexpr bool log_file_pad = true; // disable it to disable logging
|
||||
constexpr bool log_file_pad = true; // disable it to disable logging
|
||||
|
||||
int PS4_SYSV_ABI scePadInit() {
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePadOpen(Core::Libraries::LibUserService::SceUserServiceUserId userId, s32 type, s32 index,
|
||||
const ScePadOpenParam* pParam) {
|
||||
int PS4_SYSV_ABI scePadOpen(Core::Libraries::LibUserService::SceUserServiceUserId userId, s32 type,
|
||||
s32 index, const ScePadOpenParam* pParam) {
|
||||
LOG_INFO_IF(log_file_pad, "scePadOpen userid = {} type = {} index = {}\n", userId, type, index);
|
||||
return 1; // dummy
|
||||
return 1; // dummy
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) {
|
||||
|
@ -28,19 +28,19 @@ int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) {
|
|||
|
||||
controller->readState(&state, &isConnected, &connectedCount);
|
||||
pData->buttons = state.buttonsState;
|
||||
pData->leftStick.x = 128; // dummy
|
||||
pData->leftStick.y = 128; // dummy
|
||||
pData->rightStick.x = 0; // dummy
|
||||
pData->rightStick.y = 0; // dummy
|
||||
pData->analogButtons.r2 = 0;//dummy
|
||||
pData->analogButtons.l2 = 0;//dummy
|
||||
pData->leftStick.x = 128; // dummy
|
||||
pData->leftStick.y = 128; // dummy
|
||||
pData->rightStick.x = 0; // dummy
|
||||
pData->rightStick.y = 0; // dummy
|
||||
pData->analogButtons.r2 = 0; // dummy
|
||||
pData->analogButtons.l2 = 0; // dummy
|
||||
pData->orientation.x = 0;
|
||||
pData->orientation.y = 0;
|
||||
pData->orientation.z = 0;
|
||||
pData->orientation.w = 0;
|
||||
pData->timestamp = state.time;
|
||||
pData->connected = true; // isConnected; //TODO fix me proper
|
||||
pData->connectedCount = 1;//connectedCount;
|
||||
pData->connected = true; // isConnected; //TODO fix me proper
|
||||
pData->connectedCount = 1; // connectedCount;
|
||||
pData->deviceUniqueDataLen = 0;
|
||||
|
||||
return SCE_OK;
|
||||
|
@ -52,4 +52,4 @@ void padSymbolsRegister(Loader::SymbolsResolver* sym) {
|
|||
LIB_FUNCTION("YndgXqQVV7c", "libScePad", 1, "libScePad", 1, 1, scePadReadState);
|
||||
}
|
||||
|
||||
} // namespace Emulator::HLE::Libraries::LibPad
|
||||
} // namespace Core::Libraries::LibPad
|
||||
|
|
|
@ -95,4 +95,4 @@ int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData);
|
|||
|
||||
void padSymbolsRegister(Loader::SymbolsResolver* sym);
|
||||
|
||||
}; // namespace Core::Libraries::LibPad
|
||||
}; // namespace Core::Libraries::LibPad
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "core/hle/libraries/libs.h"
|
||||
#include "core/PS4/HLE/Graphics/video_out.h"
|
||||
#include "core/hle/libraries/libkernel/libkernel.h"
|
||||
#include "core/hle/libraries/libscegnmdriver/libscegnmdriver.h"
|
||||
#include "core/hle/libraries/libuserservice/libuserservice.h"
|
||||
#include "core/hle/libraries/libpad/pad.h"
|
||||
#include "core/hle/libraries/libsystemservice/system_service.h"
|
||||
#include "core/hle/libraries/libc/libc.h"
|
||||
#include "core/hle/libraries/libkernel/libkernel.h"
|
||||
#include "core/hle/libraries/libpad/pad.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
#include "core/hle/libraries/libscegnmdriver/libscegnmdriver.h"
|
||||
#include "core/hle/libraries/libsystemservice/system_service.h"
|
||||
#include "core/hle/libraries/libuserservice/libuserservice.h"
|
||||
|
||||
namespace Core::Libraries {
|
||||
|
||||
|
@ -19,4 +19,4 @@ void InitHLELibs(Loader::SymbolsResolver* sym) {
|
|||
LibC::libcSymbolsRegister(sym);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries
|
||||
} // namespace Core::Libraries
|
||||
|
|
|
@ -3,40 +3,38 @@
|
|||
#include "core/loader/elf.h"
|
||||
#include "core/loader/symbols_resolver.h"
|
||||
|
||||
#define LIB_FUNCTION(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \
|
||||
{\
|
||||
Loader::SymbolRes sr{}; \
|
||||
sr.name = nid; \
|
||||
sr.library = lib; \
|
||||
sr.library_version = libversion;\
|
||||
sr.module = mod;\
|
||||
sr.module_version_major = moduleVersionMajor;\
|
||||
sr.module_version_minor = moduleVersionMinor;\
|
||||
sr.type = STT_FUN;\
|
||||
auto func = reinterpret_cast<u64>(function);\
|
||||
sym->AddSymbol(sr, func);\
|
||||
}
|
||||
|
||||
#define LIB_OBJ(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \
|
||||
{ \
|
||||
Loader::SymbolRes sr{}; \
|
||||
sr.name = nid; \
|
||||
sr.library = lib; \
|
||||
sr.library_version = libversion; \
|
||||
sr.module = mod; \
|
||||
sr.module_version_major = moduleVersionMajor; \
|
||||
sr.module_version_minor = moduleVersionMinor; \
|
||||
sr.type = STT_OBJECT; \
|
||||
auto func = reinterpret_cast<u64>(function); \
|
||||
sym->AddSymbol(sr, func); \
|
||||
#define LIB_FUNCTION(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \
|
||||
{ \
|
||||
Loader::SymbolRes sr{}; \
|
||||
sr.name = nid; \
|
||||
sr.library = lib; \
|
||||
sr.library_version = libversion; \
|
||||
sr.module = mod; \
|
||||
sr.module_version_major = moduleVersionMajor; \
|
||||
sr.module_version_minor = moduleVersionMinor; \
|
||||
sr.type = STT_FUN; \
|
||||
auto func = reinterpret_cast<u64>(function); \
|
||||
sym->AddSymbol(sr, func); \
|
||||
}
|
||||
|
||||
#define PRINT_FUNCTION_NAME() \
|
||||
{ \
|
||||
LOG_INFO_IF(true, "{}()\n", __func__); \
|
||||
#define LIB_OBJ(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \
|
||||
{ \
|
||||
Loader::SymbolRes sr{}; \
|
||||
sr.name = nid; \
|
||||
sr.library = lib; \
|
||||
sr.library_version = libversion; \
|
||||
sr.module = mod; \
|
||||
sr.module_version_major = moduleVersionMajor; \
|
||||
sr.module_version_minor = moduleVersionMinor; \
|
||||
sr.type = STT_OBJECT; \
|
||||
auto func = reinterpret_cast<u64>(function); \
|
||||
sym->AddSymbol(sr, func); \
|
||||
}
|
||||
|
||||
#define PRINT_DUMMY_FUNCTION_NAME() \
|
||||
#define PRINT_FUNCTION_NAME() \
|
||||
{ LOG_INFO_IF(true, "{}()\n", __func__); }
|
||||
|
||||
#define PRINT_DUMMY_FUNCTION_NAME() \
|
||||
{ LOG_WARN_IF(true, "dummy {}()\n", __func__); }
|
||||
|
||||
namespace Core::Libraries {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "common/log.h"
|
||||
#include "core/PS4/GPU/gpu_memory.h"
|
||||
#include "core/hle/libraries/libscegnmdriver/libscegnmdriver.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
#include "core/hle/libraries/libscegnmdriver/libscegnmdriver.h"
|
||||
#include "emulator.h"
|
||||
|
||||
namespace Core::Libraries::LibSceGnmDriver {
|
||||
|
@ -20,5 +20,5 @@ void LibSceGnmDriver_Register(Loader::SymbolsResolver* sym) {
|
|||
LIB_FUNCTION("yvZ73uQUqrk", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSubmitDone);
|
||||
LIB_FUNCTION("iBt3Oe00Kvc", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmFlushGarlic);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}; // namespace Core::Libraries::LibSceGnmDriver
|
||||
|
|
|
@ -24,8 +24,10 @@ s32 PS4_SYSV_ABI sceSystemServiceGetStatus(SceSystemServiceStatus* status) {
|
|||
}
|
||||
|
||||
void systemServiceSymbolsRegister(Loader::SymbolsResolver* sym) {
|
||||
LIB_FUNCTION("Vo5V8KAwCmk", "libSceSystemService", 1, "libSceSystemService", 1, 1, sceSystemServiceHideSplashScreen);
|
||||
LIB_FUNCTION("rPo6tV8D9bM", "libSceSystemService", 1, "libSceSystemService", 1, 1, sceSystemServiceGetStatus);
|
||||
LIB_FUNCTION("Vo5V8KAwCmk", "libSceSystemService", 1, "libSceSystemService", 1, 1,
|
||||
sceSystemServiceHideSplashScreen);
|
||||
LIB_FUNCTION("rPo6tV8D9bM", "libSceSystemService", 1, "libSceSystemService", 1, 1,
|
||||
sceSystemServiceGetStatus);
|
||||
}
|
||||
|
||||
}; // namespace Core::Libraries::LibSystemService
|
||||
}; // namespace Core::Libraries::LibSystemService
|
||||
|
|
|
@ -23,4 +23,4 @@ s32 PS4_SYSV_ABI sceSystemServiceGetStatus(SceSystemServiceStatus* status);
|
|||
|
||||
void systemServiceSymbolsRegister(Loader::SymbolsResolver* sym);
|
||||
|
||||
}; // namespace Core::Libraries::LibSystemService
|
||||
}; // namespace Core::Libraries::LibSystemService
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "common/log.h"
|
||||
#include "core/hle/libraries/libuserservice/libuserservice.h"
|
||||
#include "core/hle/error_codes.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
#include "core/hle/libraries/libuserservice/libuserservice.h"
|
||||
|
||||
namespace Core::Libraries::LibUserService {
|
||||
|
||||
|
@ -21,8 +21,10 @@ s32 PS4_SYSV_ABI sceUserServiceGetLoginUserIdList(SceUserServiceLoginUserIdList*
|
|||
}
|
||||
|
||||
void userServiceSymbolsRegister(Loader::SymbolsResolver* sym) {
|
||||
LIB_FUNCTION("j3YMu1MVNNo", "libSceUserService", 1, "libSceUserService", 1, 1, sceUserServiceInitialize);
|
||||
LIB_FUNCTION("fPhymKNvK-A", "libSceUserService", 1, "libSceUserService", 1, 1, sceUserServiceGetLoginUserIdList);
|
||||
LIB_FUNCTION("j3YMu1MVNNo", "libSceUserService", 1, "libSceUserService", 1, 1,
|
||||
sceUserServiceInitialize);
|
||||
LIB_FUNCTION("fPhymKNvK-A", "libSceUserService", 1, "libSceUserService", 1, 1,
|
||||
sceUserServiceGetLoginUserIdList);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibUserService
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
//constants
|
||||
|
||||
constexpr int SCE_USER_SERVICE_MAX_LOGIN_USERS = 4; //max users logged in at once
|
||||
constexpr int SCE_USER_SERVICE_MAX_USER_NAME_LENGTH = 16;//Max length for user name
|
||||
|
||||
constexpr int SCE_USER_SERVICE_USER_ID_INVALID = -1;//invalid user ID
|
||||
constexpr int SCE_USER_SERVICE_USER_ID_SYSTEM = 255; //generic id for device
|
||||
constexpr int SCE_USER_SERVICE_USER_ID_EVERYONE = 254; // generic id for user (mostly used in common dialogs)
|
||||
// constants
|
||||
|
||||
constexpr int SCE_USER_SERVICE_MAX_LOGIN_USERS = 4; // max users logged in at once
|
||||
constexpr int SCE_USER_SERVICE_MAX_USER_NAME_LENGTH = 16; // Max length for user name
|
||||
|
||||
constexpr int SCE_USER_SERVICE_USER_ID_INVALID = -1; // invalid user ID
|
||||
constexpr int SCE_USER_SERVICE_USER_ID_SYSTEM = 255; // generic id for device
|
||||
constexpr int SCE_USER_SERVICE_USER_ID_EVERYONE =
|
||||
254; // generic id for user (mostly used in common dialogs)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include "core/loader/elf.h"
|
||||
#include "core/loader/symbols_resolver.h"
|
||||
|
||||
|
@ -17,30 +17,30 @@ struct EntryParams {
|
|||
};
|
||||
|
||||
struct ModuleInfo {
|
||||
std::string name;
|
||||
std::string name;
|
||||
union {
|
||||
u64 value;
|
||||
u64 value;
|
||||
struct {
|
||||
u32 name_offset;
|
||||
u08 version_minor;
|
||||
u08 version_major;
|
||||
u16 id;
|
||||
};
|
||||
};
|
||||
std::string enc_id;
|
||||
u32 name_offset;
|
||||
u08 version_minor;
|
||||
u08 version_major;
|
||||
u16 id;
|
||||
};
|
||||
};
|
||||
std::string enc_id;
|
||||
};
|
||||
|
||||
struct LibraryInfo {
|
||||
std::string name;
|
||||
std::string name;
|
||||
union {
|
||||
u64 value;
|
||||
u64 value;
|
||||
struct {
|
||||
u32 name_offset;
|
||||
u16 version;
|
||||
u16 id;
|
||||
};
|
||||
};
|
||||
std::string enc_id;
|
||||
u32 name_offset;
|
||||
u16 version;
|
||||
u16 id;
|
||||
};
|
||||
};
|
||||
std::string enc_id;
|
||||
};
|
||||
|
||||
struct PS4ThreadLocal {
|
||||
|
@ -110,22 +110,25 @@ struct Module {
|
|||
|
||||
class Linker {
|
||||
public:
|
||||
Linker();
|
||||
virtual ~Linker();
|
||||
Linker();
|
||||
virtual ~Linker();
|
||||
|
||||
Module* LoadModule(const std::string& elf_name);
|
||||
Module* FindModule(/*u32 id*/);
|
||||
void LoadModuleToMemory(Module* m);
|
||||
void LoadDynamicInfo(Module* m);
|
||||
void LoadSymbols(Module* m);
|
||||
Loader::SymbolsResolver& getHLESymbols() { return m_hle_symbols; }
|
||||
void Relocate(Module* m);
|
||||
void Resolve(const std::string& name, int Symtype, Module* m, Loader::SymbolRecord* return_info);
|
||||
Module* LoadModule(const std::string& elf_name);
|
||||
Module* FindModule(/*u32 id*/);
|
||||
void LoadModuleToMemory(Module* m);
|
||||
void LoadDynamicInfo(Module* m);
|
||||
void LoadSymbols(Module* m);
|
||||
Loader::SymbolsResolver& getHLESymbols() {
|
||||
return m_hle_symbols;
|
||||
}
|
||||
void Relocate(Module* m);
|
||||
void Resolve(const std::string& name, int Symtype, Module* m,
|
||||
Loader::SymbolRecord* return_info);
|
||||
void Execute();
|
||||
|
||||
private:
|
||||
const ModuleInfo* FindModule(const Module& m, const std::string& id);
|
||||
const LibraryInfo* FindLibrary(const Module& program, const std::string& id);
|
||||
const ModuleInfo* FindModule(const Module& m, const std::string& id);
|
||||
const LibraryInfo* FindLibrary(const Module& program, const std::string& id);
|
||||
|
||||
std::vector<Module> m_modules;
|
||||
Loader::SymbolsResolver m_hle_symbols{};
|
||||
|
|
|
@ -1,120 +1,185 @@
|
|||
#include <fmt/core.h>
|
||||
#include "common/log.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "core/loader/elf.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
|
||||
constexpr bool log_file_loader = false; // disable it to disable logging
|
||||
constexpr bool log_file_loader = false; // disable it to disable logging
|
||||
|
||||
static std::string_view getProgramTypeName(program_type_es type) {
|
||||
switch (type) {
|
||||
case PT_FAKE: return "PT_FAKE";
|
||||
case PT_NPDRM_EXEC: return "PT_NPDRM_EXEC";
|
||||
case PT_NPDRM_DYNLIB: return "PT_NPDRM_DYNLIB";
|
||||
case PT_SYSTEM_EXEC: return "PT_SYSTEM_EXEC";
|
||||
case PT_SYSTEM_DYNLIB: return "PT_SYSTEM_DYNLIB";
|
||||
case PT_HOST_KERNEL: return "PT_HOST_KERNEL";
|
||||
case PT_SECURE_MODULE: return "PT_SECURE_MODULE";
|
||||
case PT_SECURE_KERNEL: return "PT_SECURE_KERNEL";
|
||||
default: return "INVALID";
|
||||
case PT_FAKE:
|
||||
return "PT_FAKE";
|
||||
case PT_NPDRM_EXEC:
|
||||
return "PT_NPDRM_EXEC";
|
||||
case PT_NPDRM_DYNLIB:
|
||||
return "PT_NPDRM_DYNLIB";
|
||||
case PT_SYSTEM_EXEC:
|
||||
return "PT_SYSTEM_EXEC";
|
||||
case PT_SYSTEM_DYNLIB:
|
||||
return "PT_SYSTEM_DYNLIB";
|
||||
case PT_HOST_KERNEL:
|
||||
return "PT_HOST_KERNEL";
|
||||
case PT_SECURE_MODULE:
|
||||
return "PT_SECURE_MODULE";
|
||||
case PT_SECURE_KERNEL:
|
||||
return "PT_SECURE_KERNEL";
|
||||
default:
|
||||
return "INVALID";
|
||||
}
|
||||
}
|
||||
|
||||
static std::string_view getIdentClassName(ident_class_es elf_class) {
|
||||
switch (elf_class) {
|
||||
case ELF_CLASS_NONE: return "ELF_CLASS_NONE";
|
||||
case ELF_CLASS_32: return "ELF_CLASS_32";
|
||||
case ELF_CLASS_64: return "ELF_CLASS_64";
|
||||
case ELF_CLASS_NUM: return "ELF_CLASS_NUM";
|
||||
default: return "INVALID";
|
||||
case ELF_CLASS_NONE:
|
||||
return "ELF_CLASS_NONE";
|
||||
case ELF_CLASS_32:
|
||||
return "ELF_CLASS_32";
|
||||
case ELF_CLASS_64:
|
||||
return "ELF_CLASS_64";
|
||||
case ELF_CLASS_NUM:
|
||||
return "ELF_CLASS_NUM";
|
||||
default:
|
||||
return "INVALID";
|
||||
}
|
||||
}
|
||||
|
||||
static std::string_view getIdentEndianName(ident_endian_es endian) {
|
||||
switch (endian) {
|
||||
case ELF_DATA_NONE: return "ELF_DATA_NONE";
|
||||
case ELF_DATA_2LSB: return "ELF_DATA_2LSB";
|
||||
case ELF_DATA_2MSB: return "ELF_DATA_2MSB";
|
||||
case ELF_DATA_NUM: return "ELF_DATA_NUM";
|
||||
default: return "INVALID";
|
||||
case ELF_DATA_NONE:
|
||||
return "ELF_DATA_NONE";
|
||||
case ELF_DATA_2LSB:
|
||||
return "ELF_DATA_2LSB";
|
||||
case ELF_DATA_2MSB:
|
||||
return "ELF_DATA_2MSB";
|
||||
case ELF_DATA_NUM:
|
||||
return "ELF_DATA_NUM";
|
||||
default:
|
||||
return "INVALID";
|
||||
}
|
||||
}
|
||||
|
||||
static std::string_view getIdentVersionName(ident_version_es version) {
|
||||
switch (version) {
|
||||
case ELF_VERSION_NONE: return "ELF_VERSION_NONE";
|
||||
case ELF_VERSION_CURRENT: return "ELF_VERSION_CURRENT";
|
||||
case ELF_VERSION_NUM: return "ELF_VERSION_NUM";
|
||||
default: return "INVALID";
|
||||
case ELF_VERSION_NONE:
|
||||
return "ELF_VERSION_NONE";
|
||||
case ELF_VERSION_CURRENT:
|
||||
return "ELF_VERSION_CURRENT";
|
||||
case ELF_VERSION_NUM:
|
||||
return "ELF_VERSION_NUM";
|
||||
default:
|
||||
return "INVALID";
|
||||
}
|
||||
}
|
||||
|
||||
static std::string_view getIdentOsabiName(ident_osabi_es osabi) {
|
||||
switch (osabi) {
|
||||
case ELF_OSABI_NONE: return "ELF_OSABI_NONE";
|
||||
case ELF_OSABI_HPUX: return "ELF_OSABI_HPUX";
|
||||
case ELF_OSABI_NETBSD: return "ELF_OSABI_NETBSD";
|
||||
case ELF_OSABI_LINUX: return "ELF_OSABI_LINUX";
|
||||
case ELF_OSABI_SOLARIS: return "ELF_OSABI_SOLARIS";
|
||||
case ELF_OSABI_AIX: return "ELF_OSABI_AIX";
|
||||
case ELF_OSABI_IRIX: return "ELF_OSABI_IRIX";
|
||||
case ELF_OSABI_FREEBSD: return "ELF_OSABI_FREEBSD";
|
||||
case ELF_OSABI_TRU64: return "ELF_OSABI_TRU64";
|
||||
case ELF_OSABI_MODESTO: return "ELF_OSABI_MODESTO";
|
||||
case ELF_OSABI_OPENBSD: return "ELF_OSABI_OPENBSD";
|
||||
case ELF_OSABI_OPENVMS: return "ELF_OSABI_OPENVMS";
|
||||
case ELF_OSABI_NSK: return "ELF_OSABI_NSK";
|
||||
case ELF_OSABI_AROS: return "ELF_OSABI_AROS";
|
||||
case ELF_OSABI_ARM_AEABI: return "ELF_OSABI_ARM_AEABI";
|
||||
case ELF_OSABI_ARM: return "ELF_OSABI_ARM";
|
||||
case ELF_OSABI_STANDALONE: return "ELF_OSABI_STANDALONE";
|
||||
default: return "INVALID";
|
||||
case ELF_OSABI_NONE:
|
||||
return "ELF_OSABI_NONE";
|
||||
case ELF_OSABI_HPUX:
|
||||
return "ELF_OSABI_HPUX";
|
||||
case ELF_OSABI_NETBSD:
|
||||
return "ELF_OSABI_NETBSD";
|
||||
case ELF_OSABI_LINUX:
|
||||
return "ELF_OSABI_LINUX";
|
||||
case ELF_OSABI_SOLARIS:
|
||||
return "ELF_OSABI_SOLARIS";
|
||||
case ELF_OSABI_AIX:
|
||||
return "ELF_OSABI_AIX";
|
||||
case ELF_OSABI_IRIX:
|
||||
return "ELF_OSABI_IRIX";
|
||||
case ELF_OSABI_FREEBSD:
|
||||
return "ELF_OSABI_FREEBSD";
|
||||
case ELF_OSABI_TRU64:
|
||||
return "ELF_OSABI_TRU64";
|
||||
case ELF_OSABI_MODESTO:
|
||||
return "ELF_OSABI_MODESTO";
|
||||
case ELF_OSABI_OPENBSD:
|
||||
return "ELF_OSABI_OPENBSD";
|
||||
case ELF_OSABI_OPENVMS:
|
||||
return "ELF_OSABI_OPENVMS";
|
||||
case ELF_OSABI_NSK:
|
||||
return "ELF_OSABI_NSK";
|
||||
case ELF_OSABI_AROS:
|
||||
return "ELF_OSABI_AROS";
|
||||
case ELF_OSABI_ARM_AEABI:
|
||||
return "ELF_OSABI_ARM_AEABI";
|
||||
case ELF_OSABI_ARM:
|
||||
return "ELF_OSABI_ARM";
|
||||
case ELF_OSABI_STANDALONE:
|
||||
return "ELF_OSABI_STANDALONE";
|
||||
default:
|
||||
return "INVALID";
|
||||
}
|
||||
}
|
||||
|
||||
static std::string_view getIdentAbiversionName(ident_abiversion_es version) {
|
||||
switch (version) {
|
||||
case ELF_ABI_VERSION_AMDGPU_HSA_V2: return "ELF_ABI_VERSION_AMDGPU_HSA_V2";
|
||||
case ELF_ABI_VERSION_AMDGPU_HSA_V3: return "ELF_ABI_VERSION_AMDGPU_HSA_V3";
|
||||
case ELF_ABI_VERSION_AMDGPU_HSA_V4: return "ELF_ABI_VERSION_AMDGPU_HSA_V4";
|
||||
case ELF_ABI_VERSION_AMDGPU_HSA_V5: return "ELF_ABI_VERSION_AMDGPU_HSA_V5";
|
||||
default: return "INVALID";
|
||||
case ELF_ABI_VERSION_AMDGPU_HSA_V2:
|
||||
return "ELF_ABI_VERSION_AMDGPU_HSA_V2";
|
||||
case ELF_ABI_VERSION_AMDGPU_HSA_V3:
|
||||
return "ELF_ABI_VERSION_AMDGPU_HSA_V3";
|
||||
case ELF_ABI_VERSION_AMDGPU_HSA_V4:
|
||||
return "ELF_ABI_VERSION_AMDGPU_HSA_V4";
|
||||
case ELF_ABI_VERSION_AMDGPU_HSA_V5:
|
||||
return "ELF_ABI_VERSION_AMDGPU_HSA_V5";
|
||||
default:
|
||||
return "INVALID";
|
||||
}
|
||||
}
|
||||
static std::string_view getVersion(e_version_es version) {
|
||||
switch (version) {
|
||||
case EV_NONE: return "EV_NONE";
|
||||
case EV_CURRENT: return "EV_CURRENT";
|
||||
default: return "INVALID";
|
||||
case EV_NONE:
|
||||
return "EV_NONE";
|
||||
case EV_CURRENT:
|
||||
return "EV_CURRENT";
|
||||
default:
|
||||
return "INVALID";
|
||||
}
|
||||
}
|
||||
|
||||
static std::string_view getType(e_type_s type) {
|
||||
switch (type) {
|
||||
case ET_NONE: return "ET_NONE";
|
||||
case ET_REL: return "ET_REL";
|
||||
case ET_EXEC: return "ET_EXEC";
|
||||
case ET_DYN: return "ET_DYN";
|
||||
case ET_CORE: return "ET_CORE";
|
||||
case ET_SCE_EXEC: return "ET_SCE_EXEC";
|
||||
case ET_SCE_STUBLIB: return "ET_SCE_STUBLIB";
|
||||
case ET_SCE_DYNEXEC: return "ET_SCE_DYNEXEC";
|
||||
case ET_SCE_DYNAMIC: return "ET_SCE_DYNAMIC";
|
||||
default: return "INVALID";
|
||||
case ET_NONE:
|
||||
return "ET_NONE";
|
||||
case ET_REL:
|
||||
return "ET_REL";
|
||||
case ET_EXEC:
|
||||
return "ET_EXEC";
|
||||
case ET_DYN:
|
||||
return "ET_DYN";
|
||||
case ET_CORE:
|
||||
return "ET_CORE";
|
||||
case ET_SCE_EXEC:
|
||||
return "ET_SCE_EXEC";
|
||||
case ET_SCE_STUBLIB:
|
||||
return "ET_SCE_STUBLIB";
|
||||
case ET_SCE_DYNEXEC:
|
||||
return "ET_SCE_DYNEXEC";
|
||||
case ET_SCE_DYNAMIC:
|
||||
return "ET_SCE_DYNAMIC";
|
||||
default:
|
||||
return "INVALID";
|
||||
}
|
||||
}
|
||||
|
||||
static std::string_view getMachine(e_machine_es machine) {
|
||||
switch (machine) {
|
||||
case EM_X86_64: return "EM_X86_64";
|
||||
default: return "INVALID";
|
||||
case EM_X86_64:
|
||||
return "EM_X86_64";
|
||||
default:
|
||||
return "INVALID";
|
||||
}
|
||||
}
|
||||
|
||||
Elf::~Elf() { Reset(); }
|
||||
Elf::~Elf() {
|
||||
Reset();
|
||||
}
|
||||
|
||||
void Elf::Reset() { m_f.close(); }
|
||||
void Elf::Reset() {
|
||||
m_f.close();
|
||||
}
|
||||
|
||||
void Elf::Open(const std::string& file_name) {
|
||||
Reset();
|
||||
|
@ -156,7 +221,7 @@ void Elf::Open(const std::string& file_name) {
|
|||
header_size += m_elf_header.e_phnum * m_elf_header.e_phentsize;
|
||||
header_size += m_elf_header.e_shnum * m_elf_header.e_shentsize;
|
||||
header_size += 15;
|
||||
header_size &= ~15; // Align
|
||||
header_size &= ~15; // Align
|
||||
|
||||
if (m_elf_header.e_ehsize - header_size >= sizeof(elf_program_id_header)) {
|
||||
m_f.seek(header_size, Common::FS::SeekMode::Set);
|
||||
|
@ -169,12 +234,14 @@ void Elf::Open(const std::string& file_name) {
|
|||
|
||||
bool Elf::isSelfFile() const {
|
||||
if (m_self.magic != self_header::signature) [[unlikely]] {
|
||||
LOG_ERROR_IF(log_file_loader, "Not a SELF file.Magic file mismatched !current = {:#x} required = {:#x}\n ", m_self.magic,
|
||||
self_header::signature);
|
||||
LOG_ERROR_IF(log_file_loader,
|
||||
"Not a SELF file.Magic file mismatched !current = {:#x} required = {:#x}\n ",
|
||||
m_self.magic, self_header::signature);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_self.version != 0x00 || m_self.mode != 0x01 || m_self.endian != 0x01 || m_self.attributes != 0x12) [[unlikely]] {
|
||||
if (m_self.version != 0x00 || m_self.mode != 0x01 || m_self.endian != 0x01 ||
|
||||
m_self.attributes != 0x12) [[unlikely]] {
|
||||
LOG_ERROR_IF(log_file_loader, "Unknown SELF file\n");
|
||||
return false;
|
||||
}
|
||||
|
@ -188,60 +255,74 @@ bool Elf::isSelfFile() const {
|
|||
}
|
||||
|
||||
bool Elf::isElfFile() const {
|
||||
if (m_elf_header.e_ident.magic[EI_MAG0] != ELFMAG0 || m_elf_header.e_ident.magic[EI_MAG1] != ELFMAG1 ||
|
||||
m_elf_header.e_ident.magic[EI_MAG2] != ELFMAG2 || m_elf_header.e_ident.magic[EI_MAG3] != ELFMAG3) {
|
||||
if (m_elf_header.e_ident.magic[EI_MAG0] != ELFMAG0 ||
|
||||
m_elf_header.e_ident.magic[EI_MAG1] != ELFMAG1 ||
|
||||
m_elf_header.e_ident.magic[EI_MAG2] != ELFMAG2 ||
|
||||
m_elf_header.e_ident.magic[EI_MAG3] != ELFMAG3) {
|
||||
LOG_ERROR_IF(log_file_loader, "Not an ELF file magic is wrong!\n");
|
||||
return false;
|
||||
}
|
||||
if (m_elf_header.e_ident.ei_class != ELF_CLASS_64) {
|
||||
LOG_ERROR_IF(log_file_loader, "e_ident[EI_CLASS] expected 0x02 is ({:#x})\n", static_cast<u32>(m_elf_header.e_ident.ei_class));
|
||||
LOG_ERROR_IF(log_file_loader, "e_ident[EI_CLASS] expected 0x02 is ({:#x})\n",
|
||||
static_cast<u32>(m_elf_header.e_ident.ei_class));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_elf_header.e_ident.ei_data != ELF_DATA_2LSB) {
|
||||
LOG_ERROR_IF(log_file_loader, "e_ident[EI_DATA] expected 0x01 is ({:#x})\n", static_cast<u32>(m_elf_header.e_ident.ei_data));
|
||||
LOG_ERROR_IF(log_file_loader, "e_ident[EI_DATA] expected 0x01 is ({:#x})\n",
|
||||
static_cast<u32>(m_elf_header.e_ident.ei_data));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_elf_header.e_ident.ei_version != ELF_VERSION_CURRENT) {
|
||||
LOG_ERROR_IF(log_file_loader, "e_ident[EI_VERSION] expected 0x01 is ({:#x})\n", static_cast<u32>(m_elf_header.e_ident.ei_version));
|
||||
LOG_ERROR_IF(log_file_loader, "e_ident[EI_VERSION] expected 0x01 is ({:#x})\n",
|
||||
static_cast<u32>(m_elf_header.e_ident.ei_version));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_elf_header.e_ident.ei_osabi != ELF_OSABI_FREEBSD) {
|
||||
LOG_ERROR_IF(log_file_loader, "e_ident[EI_OSABI] expected 0x09 is ({:#x})\n", static_cast<u32>(m_elf_header.e_ident.ei_osabi));
|
||||
LOG_ERROR_IF(log_file_loader, "e_ident[EI_OSABI] expected 0x09 is ({:#x})\n",
|
||||
static_cast<u32>(m_elf_header.e_ident.ei_osabi));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_elf_header.e_ident.ei_abiversion != ELF_ABI_VERSION_AMDGPU_HSA_V2) {
|
||||
LOG_ERROR_IF(log_file_loader, "e_ident[EI_ABIVERSION] expected 0x00 is ({:#x})\n", static_cast<u32>(m_elf_header.e_ident.ei_abiversion));
|
||||
LOG_ERROR_IF(log_file_loader, "e_ident[EI_ABIVERSION] expected 0x00 is ({:#x})\n",
|
||||
static_cast<u32>(m_elf_header.e_ident.ei_abiversion));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_elf_header.e_type != ET_SCE_DYNEXEC && m_elf_header.e_type != ET_SCE_DYNAMIC && m_elf_header.e_type != ET_SCE_EXEC) {
|
||||
LOG_ERROR_IF(log_file_loader, "e_type expected 0xFE10 OR 0xFE18 OR 0xfe00 is ({:#x})\n", static_cast<u32>(m_elf_header.e_type));
|
||||
if (m_elf_header.e_type != ET_SCE_DYNEXEC && m_elf_header.e_type != ET_SCE_DYNAMIC &&
|
||||
m_elf_header.e_type != ET_SCE_EXEC) {
|
||||
LOG_ERROR_IF(log_file_loader, "e_type expected 0xFE10 OR 0xFE18 OR 0xfe00 is ({:#x})\n",
|
||||
static_cast<u32>(m_elf_header.e_type));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_elf_header.e_machine != EM_X86_64) {
|
||||
LOG_ERROR_IF(log_file_loader, "e_machine expected 0x3E is ({:#x})\n", static_cast<u32>(m_elf_header.e_machine));
|
||||
LOG_ERROR_IF(log_file_loader, "e_machine expected 0x3E is ({:#x})\n",
|
||||
static_cast<u32>(m_elf_header.e_machine));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_elf_header.e_version != EV_CURRENT) {
|
||||
LOG_ERROR_IF(log_file_loader, "m_elf_header.e_version expected 0x01 is ({:#x})\n", static_cast<u32>(m_elf_header.e_version));
|
||||
LOG_ERROR_IF(log_file_loader, "m_elf_header.e_version expected 0x01 is ({:#x})\n",
|
||||
static_cast<u32>(m_elf_header.e_version));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_elf_header.e_phentsize != sizeof(elf_program_header)) {
|
||||
LOG_ERROR_IF(log_file_loader, "e_phentsize ({}) != sizeof(elf_program_header)\n", static_cast<u32>(m_elf_header.e_phentsize));
|
||||
LOG_ERROR_IF(log_file_loader, "e_phentsize ({}) != sizeof(elf_program_header)\n",
|
||||
static_cast<u32>(m_elf_header.e_phentsize));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_elf_header.e_shentsize > 0 &&
|
||||
m_elf_header.e_shentsize != sizeof(elf_section_header)) // Commercial games doesn't appear to have section headers
|
||||
m_elf_header.e_shentsize !=
|
||||
sizeof(elf_section_header)) // Commercial games doesn't appear to have section headers
|
||||
{
|
||||
LOG_ERROR_IF(log_file_loader, "e_shentsize ({}) != sizeof(elf_section_header)\n", m_elf_header.e_shentsize);
|
||||
LOG_ERROR_IF(log_file_loader, "e_shentsize ({}) != sizeof(elf_section_header)\n",
|
||||
m_elf_header.e_shentsize);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -249,7 +330,7 @@ bool Elf::isElfFile() const {
|
|||
}
|
||||
|
||||
void Elf::DebugDump() {
|
||||
if (is_self) { // If we load elf instead
|
||||
if (is_self) { // If we load elf instead
|
||||
LOG_INFO_IF(log_file_loader, (SElfHeaderStr()));
|
||||
for (u16 i = 0; i < m_self.segment_count; i++) {
|
||||
LOG_INFO_IF(log_file_loader, SELFSegHeader(i));
|
||||
|
@ -276,7 +357,8 @@ void Elf::DebugDump() {
|
|||
LOG_INFO_IF(log_file_loader, "sh_size ........: {:#018x}\n", m_elf_shdr[i].sh_size);
|
||||
LOG_INFO_IF(log_file_loader, "sh_link ........: {:#010x}\n", m_elf_shdr[i].sh_link);
|
||||
LOG_INFO_IF(log_file_loader, "sh_info ........: {:#010x}\n", m_elf_shdr[i].sh_info);
|
||||
LOG_INFO_IF(log_file_loader, "sh_addralign ...: {:#018x}\n", m_elf_shdr[i].sh_addralign);
|
||||
LOG_INFO_IF(log_file_loader, "sh_addralign ...: {:#018x}\n",
|
||||
m_elf_shdr[i].sh_addralign);
|
||||
LOG_INFO_IF(log_file_loader, "sh_entsize .....: {:#018x}\n", m_elf_shdr[i].sh_entsize);
|
||||
}
|
||||
}
|
||||
|
@ -284,7 +366,8 @@ void Elf::DebugDump() {
|
|||
if (is_self) {
|
||||
LOG_INFO_IF(log_file_loader, "SELF info:\n");
|
||||
LOG_INFO_IF(log_file_loader, "auth id ............: {:#018x}\n", m_self_id_header.authid);
|
||||
LOG_INFO_IF(log_file_loader, "program type .......: {}\n", getProgramTypeName(m_self_id_header.program_type));
|
||||
LOG_INFO_IF(log_file_loader, "program type .......: {}\n",
|
||||
getProgramTypeName(m_self_id_header.program_type));
|
||||
LOG_INFO_IF(log_file_loader, "app version ........: {:#018x}\n", m_self_id_header.appver);
|
||||
LOG_INFO_IF(log_file_loader, "fw version .........: {:#018x}\n", m_self_id_header.firmver);
|
||||
std::string digest;
|
||||
|
@ -333,11 +416,16 @@ std::string Elf::ElfHeaderStr() {
|
|||
}
|
||||
header += fmt::format("\n");
|
||||
|
||||
header += fmt::format("ident class.......: {}\n", getIdentClassName(m_elf_header.e_ident.ei_class));
|
||||
header += fmt::format("ident data .......: {}\n", getIdentEndianName(m_elf_header.e_ident.ei_data));
|
||||
header += fmt::format("ident version.....: {}\n", getIdentVersionName(m_elf_header.e_ident.ei_version));
|
||||
header += fmt::format("ident osabi .....: {}\n", getIdentOsabiName(m_elf_header.e_ident.ei_osabi));
|
||||
header += fmt::format("ident abiversion..: {}\n", getIdentAbiversionName(m_elf_header.e_ident.ei_abiversion));
|
||||
header +=
|
||||
fmt::format("ident class.......: {}\n", getIdentClassName(m_elf_header.e_ident.ei_class));
|
||||
header +=
|
||||
fmt::format("ident data .......: {}\n", getIdentEndianName(m_elf_header.e_ident.ei_data));
|
||||
header += fmt::format("ident version.....: {}\n",
|
||||
getIdentVersionName(m_elf_header.e_ident.ei_version));
|
||||
header +=
|
||||
fmt::format("ident osabi .....: {}\n", getIdentOsabiName(m_elf_header.e_ident.ei_osabi));
|
||||
header += fmt::format("ident abiversion..: {}\n",
|
||||
getIdentAbiversionName(m_elf_header.e_ident.ei_abiversion));
|
||||
|
||||
header += fmt::format("ident UNK ........: 0x");
|
||||
for (auto i : m_elf_header.e_ident.pad) {
|
||||
|
@ -363,26 +451,46 @@ std::string Elf::ElfHeaderStr() {
|
|||
|
||||
std::string Elf::ElfPheaderTypeStr(u32 type) {
|
||||
switch (type) {
|
||||
case PT_NULL: return "Null";
|
||||
case PT_LOAD: return "Loadable";
|
||||
case PT_DYNAMIC: return "Dynamic";
|
||||
case PT_INTERP: return "Interpreter Path";
|
||||
case PT_NOTE: return "Note";
|
||||
case PT_SHLIB: return "Section Header Library";
|
||||
case PT_PHDR: return "Program Header";
|
||||
case PT_TLS: return "Thread-Local Storage";
|
||||
case PT_NUM: return "Defined Sections Number";
|
||||
case PT_SCE_RELA: return "SCE Relative";
|
||||
case PT_SCE_DYNLIBDATA: return "SCE Dynamic Library Data";
|
||||
case PT_SCE_PROCPARAM: return "SCE Processor Parameters";
|
||||
case PT_SCE_MODULE_PARAM: return "SCE Module Parameters";
|
||||
case PT_SCE_RELRO: return "SCE Read-Only After Relocation";
|
||||
case PT_GNU_EH_FRAME: return "GNU Entry Header Frame";
|
||||
case PT_GNU_STACK: return "GNU Stack (executability)";
|
||||
case PT_GNU_RELRO: return "GNU Read-Only After Relocation";
|
||||
case PT_SCE_COMMENT: return "SCE Comment";
|
||||
case PT_SCE_LIBVERSION: return "SCE Library Version";
|
||||
default: return "Unknown Section";
|
||||
case PT_NULL:
|
||||
return "Null";
|
||||
case PT_LOAD:
|
||||
return "Loadable";
|
||||
case PT_DYNAMIC:
|
||||
return "Dynamic";
|
||||
case PT_INTERP:
|
||||
return "Interpreter Path";
|
||||
case PT_NOTE:
|
||||
return "Note";
|
||||
case PT_SHLIB:
|
||||
return "Section Header Library";
|
||||
case PT_PHDR:
|
||||
return "Program Header";
|
||||
case PT_TLS:
|
||||
return "Thread-Local Storage";
|
||||
case PT_NUM:
|
||||
return "Defined Sections Number";
|
||||
case PT_SCE_RELA:
|
||||
return "SCE Relative";
|
||||
case PT_SCE_DYNLIBDATA:
|
||||
return "SCE Dynamic Library Data";
|
||||
case PT_SCE_PROCPARAM:
|
||||
return "SCE Processor Parameters";
|
||||
case PT_SCE_MODULE_PARAM:
|
||||
return "SCE Module Parameters";
|
||||
case PT_SCE_RELRO:
|
||||
return "SCE Read-Only After Relocation";
|
||||
case PT_GNU_EH_FRAME:
|
||||
return "GNU Entry Header Frame";
|
||||
case PT_GNU_STACK:
|
||||
return "GNU Stack (executability)";
|
||||
case PT_GNU_RELRO:
|
||||
return "GNU Read-Only After Relocation";
|
||||
case PT_SCE_COMMENT:
|
||||
return "SCE Comment";
|
||||
case PT_SCE_LIBVERSION:
|
||||
return "SCE Library Version";
|
||||
default:
|
||||
return "Unknown Section";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -431,7 +539,7 @@ void Elf::LoadSegment(u64 virtual_addr, u64 file_offset, u64 size) {
|
|||
}
|
||||
}
|
||||
}
|
||||
BREAKPOINT(); // Hmm we didn't return something...
|
||||
BREAKPOINT(); // Hmm we didn't return something...
|
||||
}
|
||||
|
||||
} // namespace Core::Loader
|
||||
|
|
|
@ -14,7 +14,7 @@ struct self_header {
|
|||
u32 magic;
|
||||
u08 version;
|
||||
u08 mode;
|
||||
u08 endian; // 1 is little endian
|
||||
u08 endian; // 1 is little endian
|
||||
u08 attributes;
|
||||
u08 category;
|
||||
u08 program_type;
|
||||
|
@ -24,31 +24,33 @@ struct self_header {
|
|||
u32 file_size;
|
||||
u32 padding2;
|
||||
u16 segment_count;
|
||||
u16 unknown1A; // always 0x22
|
||||
u16 unknown1A; // always 0x22
|
||||
u32 padding3;
|
||||
};
|
||||
|
||||
struct self_segment_header {
|
||||
bool IsBlocked() const {
|
||||
return (flags & 0x800) != 0; // 0 or 0x800
|
||||
return (flags & 0x800) != 0; // 0 or 0x800
|
||||
}
|
||||
|
||||
u32 GetId() const { return (flags >> 20u) & 0xFFFu; }
|
||||
u32 GetId() const {
|
||||
return (flags >> 20u) & 0xFFFu;
|
||||
}
|
||||
|
||||
bool IsOrdered() const {
|
||||
return (flags & 1) != 0; // 0 or 1
|
||||
return (flags & 1) != 0; // 0 or 1
|
||||
}
|
||||
|
||||
bool IsEncrypted() const {
|
||||
return (flags & 2) != 0; // 0 or 2
|
||||
return (flags & 2) != 0; // 0 or 2
|
||||
}
|
||||
|
||||
bool IsSigned() const {
|
||||
return (flags & 4) != 0; // 0 or 4
|
||||
return (flags & 4) != 0; // 0 or 4
|
||||
}
|
||||
|
||||
bool IsCompressed() const {
|
||||
return (flags & 8) != 0; // 0 or 8
|
||||
return (flags & 8) != 0; // 0 or 8
|
||||
}
|
||||
|
||||
u64 flags;
|
||||
|
@ -181,11 +183,25 @@ typedef enum : u16 {
|
|||
|
||||
typedef enum : u32 { EV_NONE = 0x0, EV_CURRENT = 0x1 } e_version_es;
|
||||
|
||||
typedef enum : u08 { ELF_CLASS_NONE = 0x0, ELF_CLASS_32 = 0x1, ELF_CLASS_64 = 0x2, ELF_CLASS_NUM = 0x3 } ident_class_es;
|
||||
typedef enum : u08 {
|
||||
ELF_CLASS_NONE = 0x0,
|
||||
ELF_CLASS_32 = 0x1,
|
||||
ELF_CLASS_64 = 0x2,
|
||||
ELF_CLASS_NUM = 0x3
|
||||
} ident_class_es;
|
||||
|
||||
typedef enum : u08 { ELF_DATA_NONE = 0x0, ELF_DATA_2LSB = 0x1, ELF_DATA_2MSB = 0x2, ELF_DATA_NUM = 0x3 } ident_endian_es;
|
||||
typedef enum : u08 {
|
||||
ELF_DATA_NONE = 0x0,
|
||||
ELF_DATA_2LSB = 0x1,
|
||||
ELF_DATA_2MSB = 0x2,
|
||||
ELF_DATA_NUM = 0x3
|
||||
} ident_endian_es;
|
||||
|
||||
typedef enum : u08 { ELF_VERSION_NONE = 0x0, ELF_VERSION_CURRENT = 0x1, ELF_VERSION_NUM = 0x2 } ident_version_es;
|
||||
typedef enum : u08 {
|
||||
ELF_VERSION_NONE = 0x0,
|
||||
ELF_VERSION_CURRENT = 0x1,
|
||||
ELF_VERSION_NUM = 0x2
|
||||
} ident_version_es;
|
||||
|
||||
typedef enum : u08 {
|
||||
ELF_OSABI_NONE = 0x0, /* No extensions or unspecified */
|
||||
|
@ -383,7 +399,7 @@ constexpr u08 STT_FILE = 4;
|
|||
constexpr u08 STT_COMMON = 5;
|
||||
constexpr u08 STT_TLS = 6;
|
||||
constexpr u08 STT_LOOS = 10;
|
||||
constexpr u08 STT_SCE = 11; // module_start/module_stop
|
||||
constexpr u08 STT_SCE = 11; // module_start/module_stop
|
||||
constexpr u08 STT_HIOS = 12;
|
||||
constexpr u08 STT_LOPRO = 13;
|
||||
constexpr u08 STT_SPARC_REGISTER = 13;
|
||||
|
@ -395,9 +411,15 @@ constexpr u08 STV_HIDDEN = 2;
|
|||
constexpr u08 STV_PROTECTED = 3;
|
||||
|
||||
struct elf_symbol {
|
||||
u08 GetBind() const { return st_info >> 4u; }
|
||||
u08 GetType() const { return st_info & 0xfu; }
|
||||
u08 GetVisibility() const { return st_other & 3u; }
|
||||
u08 GetBind() const {
|
||||
return st_info >> 4u;
|
||||
}
|
||||
u08 GetType() const {
|
||||
return st_info & 0xfu;
|
||||
}
|
||||
u08 GetVisibility() const {
|
||||
return st_other & 3u;
|
||||
}
|
||||
|
||||
u32 st_name;
|
||||
u08 st_info;
|
||||
|
@ -408,23 +430,27 @@ struct elf_symbol {
|
|||
};
|
||||
|
||||
struct elf_relocation {
|
||||
u32 GetSymbol() const { return static_cast<u32>(rel_info >> 32u); }
|
||||
u32 GetType() const { return static_cast<u32>(rel_info & 0xffffffff); }
|
||||
u32 GetSymbol() const {
|
||||
return static_cast<u32>(rel_info >> 32u);
|
||||
}
|
||||
u32 GetType() const {
|
||||
return static_cast<u32>(rel_info & 0xffffffff);
|
||||
}
|
||||
|
||||
u64 rel_offset;
|
||||
u64 rel_info;
|
||||
s64 rel_addend;
|
||||
};
|
||||
constexpr u32 R_X86_64_64 = 1; // Direct 64 bit
|
||||
constexpr u32 R_X86_64_64 = 1; // Direct 64 bit
|
||||
constexpr u32 R_X86_64_GLOB_DAT = 6;
|
||||
constexpr u32 R_X86_64_JUMP_SLOT = 7; // Create PLT entry
|
||||
constexpr u32 R_X86_64_RELATIVE = 8; // Adjust by program base
|
||||
constexpr u32 R_X86_64_JUMP_SLOT = 7; // Create PLT entry
|
||||
constexpr u32 R_X86_64_RELATIVE = 8; // Adjust by program base
|
||||
constexpr u32 R_X86_64_DTPMOD64 = 16;
|
||||
|
||||
namespace Core::Loader {
|
||||
|
||||
class Elf {
|
||||
public:
|
||||
public:
|
||||
Elf() = default;
|
||||
virtual ~Elf();
|
||||
|
||||
|
@ -433,15 +459,25 @@ class Elf {
|
|||
bool isElfFile() const;
|
||||
void DebugDump();
|
||||
|
||||
[[nodiscard]] self_header GetSElfHeader() const { return m_self; }
|
||||
[[nodiscard]] self_header GetSElfHeader() const {
|
||||
return m_self;
|
||||
}
|
||||
|
||||
[[nodiscard]] elf_header GetElfHeader() const { return m_elf_header; }
|
||||
[[nodiscard]] elf_header GetElfHeader() const {
|
||||
return m_elf_header;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::span<const elf_program_header> GetProgramHeader() const { return m_elf_phdr; }
|
||||
[[nodiscard]] std::span<const elf_program_header> GetProgramHeader() const {
|
||||
return m_elf_phdr;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::span<const self_segment_header> GetSegmentHeader() const { return m_self_segments; }
|
||||
[[nodiscard]] std::span<const self_segment_header> GetSegmentHeader() const {
|
||||
return m_self_segments;
|
||||
}
|
||||
|
||||
[[nodiscard]] u64 GetElfEntry() const { return m_elf_header.e_entry; }
|
||||
[[nodiscard]] u64 GetElfEntry() const {
|
||||
return m_elf_header.e_entry;
|
||||
}
|
||||
|
||||
std::string SElfHeaderStr();
|
||||
std::string SELFSegHeader(u16 no);
|
||||
|
@ -452,10 +488,10 @@ class Elf {
|
|||
|
||||
void LoadSegment(u64 virtual_addr, u64 file_offset, u64 size);
|
||||
|
||||
private:
|
||||
private:
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
private:
|
||||
Common::FS::File m_f{};
|
||||
bool is_self{};
|
||||
self_header m_self{};
|
||||
|
@ -466,4 +502,4 @@ class Elf {
|
|||
elf_program_id_header m_self_id_header{};
|
||||
};
|
||||
|
||||
} // namespace Core::Loader
|
||||
} // namespace Core::Loader
|
||||
|
|
|
@ -5,20 +5,19 @@
|
|||
namespace Core::Loader {
|
||||
|
||||
void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr) {
|
||||
SymbolRecord r{};
|
||||
SymbolRecord r{};
|
||||
r.name = GenerateName(s);
|
||||
r.virtual_address = virtual_addr;
|
||||
m_symbols.push_back(r);
|
||||
r.virtual_address = virtual_addr;
|
||||
m_symbols.push_back(r);
|
||||
}
|
||||
|
||||
std::string SymbolsResolver::GenerateName(const SymbolRes& s) {
|
||||
return fmt::format("{} lib[{}_v{}]mod[{}_v{}.{}]",
|
||||
s.name, s.library, s.library_version,
|
||||
return fmt::format("{} lib[{}_v{}]mod[{}_v{}.{}]", s.name, s.library, s.library_version,
|
||||
s.module, s.module_version_major, s.module_version_minor);
|
||||
}
|
||||
|
||||
const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolRes& s) const {
|
||||
const std::string name = GenerateName(s);
|
||||
const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolRes& s) const {
|
||||
const std::string name = GenerateName(s);
|
||||
for (u32 i = 0; i < m_symbols.size(); i++) {
|
||||
if (m_symbols[i].name.compare(name) == 0) {
|
||||
return &m_symbols[i];
|
||||
|
@ -26,7 +25,7 @@ const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolRes& s) const {
|
|||
}
|
||||
|
||||
LOG_INFO("Unresolved! {}\n", name);
|
||||
return nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace Core::Loader
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
|
||||
struct SymbolRecord {
|
||||
std::string name;
|
||||
u64 virtual_address;
|
||||
u64 virtual_address;
|
||||
};
|
||||
|
||||
struct SymbolRes {
|
||||
|
@ -25,10 +25,10 @@ struct SymbolRes {
|
|||
|
||||
class SymbolsResolver {
|
||||
public:
|
||||
SymbolsResolver() = default;
|
||||
virtual ~SymbolsResolver() = default;
|
||||
SymbolsResolver() = default;
|
||||
virtual ~SymbolsResolver() = default;
|
||||
|
||||
void AddSymbol(const SymbolRes& s, u64 virtual_addr);
|
||||
void AddSymbol(const SymbolRes& s, u64 virtual_addr);
|
||||
const SymbolRecord* FindSymbol(const SymbolRes& s) const;
|
||||
|
||||
static std::string GenerateName(const SymbolRes& s);
|
||||
|
|
|
@ -22,35 +22,50 @@ enum PosixPageProtection {
|
|||
namespace VirtualMemory {
|
||||
static u32 convertMemoryMode(MemoryMode mode) {
|
||||
switch (mode) {
|
||||
case MemoryMode::Read: return PAGE_READONLY;
|
||||
case MemoryMode::Write:
|
||||
case MemoryMode::ReadWrite: return PAGE_READWRITE;
|
||||
case MemoryMode::Read:
|
||||
return PAGE_READONLY;
|
||||
case MemoryMode::Write:
|
||||
case MemoryMode::ReadWrite:
|
||||
return PAGE_READWRITE;
|
||||
|
||||
case MemoryMode::Execute: return PAGE_EXECUTE;
|
||||
case MemoryMode::ExecuteRead: return PAGE_EXECUTE_READ;
|
||||
case MemoryMode::ExecuteWrite:
|
||||
case MemoryMode::ExecuteReadWrite: return PAGE_EXECUTE_READWRITE;
|
||||
case MemoryMode::Execute:
|
||||
return PAGE_EXECUTE;
|
||||
case MemoryMode::ExecuteRead:
|
||||
return PAGE_EXECUTE_READ;
|
||||
case MemoryMode::ExecuteWrite:
|
||||
case MemoryMode::ExecuteReadWrite:
|
||||
return PAGE_EXECUTE_READWRITE;
|
||||
|
||||
case MemoryMode::NoAccess: return PAGE_NOACCESS;
|
||||
default: return PAGE_NOACCESS;
|
||||
case MemoryMode::NoAccess:
|
||||
return PAGE_NOACCESS;
|
||||
default:
|
||||
return PAGE_NOACCESS;
|
||||
}
|
||||
}
|
||||
static MemoryMode convertMemoryMode(u32 mode) {
|
||||
switch (mode) {
|
||||
case PAGE_NOACCESS: return MemoryMode::NoAccess;
|
||||
case PAGE_READONLY: return MemoryMode::Read;
|
||||
case PAGE_READWRITE: return MemoryMode::ReadWrite;
|
||||
case PAGE_EXECUTE: return MemoryMode::Execute;
|
||||
case PAGE_EXECUTE_READ: return MemoryMode::ExecuteRead;
|
||||
case PAGE_EXECUTE_READWRITE: return MemoryMode::ExecuteReadWrite;
|
||||
default: return MemoryMode::NoAccess;
|
||||
case PAGE_NOACCESS:
|
||||
return MemoryMode::NoAccess;
|
||||
case PAGE_READONLY:
|
||||
return MemoryMode::Read;
|
||||
case PAGE_READWRITE:
|
||||
return MemoryMode::ReadWrite;
|
||||
case PAGE_EXECUTE:
|
||||
return MemoryMode::Execute;
|
||||
case PAGE_EXECUTE_READ:
|
||||
return MemoryMode::ExecuteRead;
|
||||
case PAGE_EXECUTE_READWRITE:
|
||||
return MemoryMode::ExecuteReadWrite;
|
||||
default:
|
||||
return MemoryMode::NoAccess;
|
||||
}
|
||||
}
|
||||
|
||||
u64 memory_alloc(u64 address, u64 size, MemoryMode mode) {
|
||||
#ifdef _WIN64
|
||||
auto ptr = reinterpret_cast<uintptr_t>(VirtualAlloc(reinterpret_cast<LPVOID>(static_cast<uintptr_t>(address)), size,
|
||||
static_cast<DWORD>(MEM_COMMIT) | static_cast<DWORD>(MEM_RESERVE), convertMemoryMode(mode)));
|
||||
auto ptr = reinterpret_cast<uintptr_t>(VirtualAlloc(
|
||||
reinterpret_cast<LPVOID>(static_cast<uintptr_t>(address)), size,
|
||||
static_cast<DWORD>(MEM_COMMIT) | static_cast<DWORD>(MEM_RESERVE), convertMemoryMode(mode)));
|
||||
|
||||
if (ptr == 0) {
|
||||
auto err = static_cast<u32>(GetLastError());
|
||||
|
@ -58,7 +73,8 @@ u64 memory_alloc(u64 address, u64 size, MemoryMode mode) {
|
|||
}
|
||||
#else
|
||||
auto ptr = reinterpret_cast<uintptr_t>(
|
||||
mmap(reinterpret_cast<void*>(static_cast<uintptr_t>(address)), size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0));
|
||||
mmap(reinterpret_cast<void*>(static_cast<uintptr_t>(address)), size,
|
||||
PROT_EXEC | PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0));
|
||||
|
||||
if (ptr == reinterpret_cast<uintptr_t> MAP_FAILED) {
|
||||
LOG_ERROR_IF(true, "mmap() failed: {}\n", std::strerror(errno));
|
||||
|
@ -69,7 +85,8 @@ u64 memory_alloc(u64 address, u64 size, MemoryMode mode) {
|
|||
bool memory_protect(u64 address, u64 size, MemoryMode mode, MemoryMode* old_mode) {
|
||||
#ifdef _WIN64
|
||||
DWORD old_protect = 0;
|
||||
if (VirtualProtect(reinterpret_cast<LPVOID>(static_cast<uintptr_t>(address)), size, convertMemoryMode(mode), &old_protect) == 0) {
|
||||
if (VirtualProtect(reinterpret_cast<LPVOID>(static_cast<uintptr_t>(address)), size,
|
||||
convertMemoryMode(mode), &old_protect) == 0) {
|
||||
auto err = static_cast<u32>(GetLastError());
|
||||
LOG_ERROR_IF(true, "VirtualProtect() failed: 0x{:X}\n", err);
|
||||
return false;
|
||||
|
@ -86,13 +103,15 @@ bool memory_protect(u64 address, u64 size, MemoryMode mode, MemoryMode* old_mode
|
|||
|
||||
bool memory_flush(u64 address, u64 size) {
|
||||
#ifdef _WIN64
|
||||
if (::FlushInstructionCache(GetCurrentProcess(), reinterpret_cast<LPVOID>(static_cast<uintptr_t>(address)), size) == 0) {
|
||||
if (::FlushInstructionCache(GetCurrentProcess(),
|
||||
reinterpret_cast<LPVOID>(static_cast<uintptr_t>(address)),
|
||||
size) == 0) {
|
||||
auto err = static_cast<u32>(GetLastError());
|
||||
LOG_ERROR_IF(true, "FlushInstructionCache() failed: 0x{:X}\n", err);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#else // linux probably doesn't have something similar
|
||||
#else // linux probably doesn't have something similar
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
@ -115,21 +134,27 @@ bool memory_patch(u64 vaddr, u64 value) {
|
|||
|
||||
return ret;
|
||||
}
|
||||
static u64 AlignUp(u64 pos, u64 align) { return (align != 0 ? (pos + (align - 1)) & ~(align - 1) : pos); }
|
||||
static u64 AlignUp(u64 pos, u64 align) {
|
||||
return (align != 0 ? (pos + (align - 1)) & ~(align - 1) : pos);
|
||||
}
|
||||
|
||||
u64 memory_alloc_aligned(u64 address, u64 size, MemoryMode mode, u64 alignment) {
|
||||
#ifdef _WIN64
|
||||
// try allocate aligned address inside user area
|
||||
MEM_ADDRESS_REQUIREMENTS req{};
|
||||
MEM_EXTENDED_PARAMETER param{};
|
||||
req.LowestStartingAddress = (address == 0 ? reinterpret_cast<PVOID>(USER_MIN) : reinterpret_cast<PVOID>(AlignUp(address, alignment)));
|
||||
req.LowestStartingAddress =
|
||||
(address == 0 ? reinterpret_cast<PVOID>(USER_MIN)
|
||||
: reinterpret_cast<PVOID>(AlignUp(address, alignment)));
|
||||
req.HighestEndingAddress = reinterpret_cast<PVOID>(USER_MAX);
|
||||
req.Alignment = alignment;
|
||||
param.Type = MemExtendedParameterAddressRequirements;
|
||||
param.Pointer = &req;
|
||||
|
||||
auto ptr = reinterpret_cast<uintptr_t>(VirtualAlloc2(
|
||||
GetCurrentProcess(), nullptr, size, static_cast<DWORD>(MEM_COMMIT) | static_cast<DWORD>(MEM_RESERVE), convertMemoryMode(mode), ¶m, 1));
|
||||
auto ptr = reinterpret_cast<uintptr_t>(
|
||||
VirtualAlloc2(GetCurrentProcess(), nullptr, size,
|
||||
static_cast<DWORD>(MEM_COMMIT) | static_cast<DWORD>(MEM_RESERVE),
|
||||
convertMemoryMode(mode), ¶m, 1));
|
||||
|
||||
if (ptr == 0) {
|
||||
auto err = static_cast<u32>(GetLastError());
|
||||
|
@ -145,4 +170,4 @@ u64 memory_alloc_aligned(u64 address, u64 size, MemoryMode mode, u64 alignment)
|
|||
return reinterpret_cast<u64>(ptr);
|
||||
#endif
|
||||
}
|
||||
} // namespace VirtualMemory
|
||||
} // namespace VirtualMemory
|
||||
|
|
|
@ -27,12 +27,17 @@ bool memory_patch(u64 vaddr, u64 value);
|
|||
|
||||
inline bool containsExecuteMode(MemoryMode mode) {
|
||||
switch (mode) {
|
||||
case MemoryMode::Execute: return true;
|
||||
case MemoryMode::ExecuteRead: return true;
|
||||
case MemoryMode::ExecuteWrite: return true;
|
||||
case MemoryMode::ExecuteReadWrite: return true;
|
||||
default: return false;
|
||||
case MemoryMode::Execute:
|
||||
return true;
|
||||
case MemoryMode::ExecuteRead:
|
||||
return true;
|
||||
case MemoryMode::ExecuteWrite:
|
||||
return true;
|
||||
case MemoryMode::ExecuteReadWrite:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace VirtualMemory
|
||||
} // namespace VirtualMemory
|
Loading…
Add table
Add a link
Reference in a new issue