mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-29 23:03:18 +00:00
core: Reorganize
This commit is contained in:
parent
89cf4dbfcb
commit
369d92fa56
73 changed files with 724 additions and 572 deletions
23
src/core/hle/error_codes.h
Normal file
23
src/core/hle/error_codes.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
constexpr int SCE_OK = 0;
|
||||
|
||||
constexpr int SCE_KERNEL_ERROR_EBADF = 0x80020009;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOMEM = 0x8002000c; // Insufficient memory
|
||||
constexpr int SCE_KERNEL_ERROR_EFAULT = 0x8002000e; // Invalid address pointer
|
||||
constexpr int SCE_KERNEL_ERROR_EINVAL = 0x80020016; // null or invalid states
|
||||
constexpr int SCE_KERNEL_ERROR_EAGAIN = 0x80020023; // Memory cannot be allocated
|
||||
constexpr int SCE_KERNEL_ERROR_ENAMETOOLONG = 0x8002003f; // character strings exceeds valid size
|
||||
|
||||
// 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
|
89
src/core/hle/kernel/Objects/event_queue.cpp
Normal file
89
src/core/hle/kernel/Objects/event_queue.cpp
Normal file
|
@ -0,0 +1,89 @@
|
|||
#include "common/debug.h"
|
||||
#include "core/hle/kernel/objects/event_queue.h"
|
||||
#include "Lib/Timer.h"
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
EqueueInternal::~EqueueInternal() = default;
|
||||
|
||||
int EqueueInternal::addEvent(const EqueueEvent& event) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
|
||||
if (m_events.size() > 0) {
|
||||
BREAKPOINT();
|
||||
}
|
||||
// TODO check if event is already exists and return it. Currently we just add in m_events array
|
||||
m_events.push_back(event);
|
||||
|
||||
if (event.isTriggered) {
|
||||
BREAKPOINT(); // we don't support that either yet
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EqueueInternal::waitForEvents(SceKernelEvent* ev, int num, u32 micros) {
|
||||
std::unique_lock lock{m_mutex};
|
||||
|
||||
u32 timeElapsed = 0;
|
||||
Lib::Timer t;
|
||||
t.Start();
|
||||
|
||||
for (;;) {
|
||||
int ret = getTriggeredEvents(ev, num);
|
||||
|
||||
if (ret > 0 || (timeElapsed >= micros && micros != 0)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (micros == 0) {
|
||||
m_cond.wait(lock);
|
||||
} else {
|
||||
m_cond.wait_for(lock, std::chrono::microseconds(micros - timeElapsed));
|
||||
}
|
||||
|
||||
timeElapsed = static_cast<uint32_t>(t.GetTimeSec() * 1000000.0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
auto& event = m_events[0];
|
||||
|
||||
if (event.filter.trigger_event_func != nullptr) {
|
||||
event.filter.trigger_event_func(&event, trigger_data);
|
||||
} else {
|
||||
event.isTriggered = true;
|
||||
}
|
||||
|
||||
m_cond.notify_one();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int EqueueInternal::getTriggeredEvents(SceKernelEvent* ev, int num) {
|
||||
int ret = 0;
|
||||
|
||||
if (m_events.size() > 1) {
|
||||
BREAKPOINT(); // we currently support one event
|
||||
}
|
||||
auto& event = m_events[0];
|
||||
|
||||
if (event.isTriggered) {
|
||||
ev[ret++] = event.event;
|
||||
|
||||
if (event.filter.reset_event_func != nullptr) {
|
||||
event.filter.reset_event_func(&event);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace Core::Kernel
|
78
src/core/hle/kernel/Objects/event_queue.h
Normal file
78
src/core/hle/kernel/Objects/event_queue.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#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_POLLING = -12;
|
||||
constexpr s16 EVFILT_VIDEO_OUT = -13;
|
||||
constexpr s16 EVFILT_GRAPHICS_CORE = -14;
|
||||
constexpr s16 EVFILT_HRTIMER = -15;
|
||||
constexpr s16 EVFILT_UVD_TRAP = -16;
|
||||
constexpr s16 EVFILT_VCE_TRAP = -17;
|
||||
constexpr s16 EVFILT_SDMA_TRAP = -18;
|
||||
constexpr s16 EVFILT_REG_EV = -19;
|
||||
constexpr s16 EVFILT_GPU_EXCEPTION = -20;
|
||||
constexpr s16 EVFILT_GPU_SYSTEM_EXCEPTION = -21;
|
||||
constexpr s16 EVFILT_GPU_DBGGC_EV = -22;
|
||||
constexpr s16 EVFILT_SYSCOUNT = 22;
|
||||
|
||||
class EqueueInternal;
|
||||
struct EqueueEvent;
|
||||
|
||||
using TriggerFunc = void (*)(EqueueEvent* event, void* trigger_data);
|
||||
using ResetFunc = void (*)(EqueueEvent* event);
|
||||
using DeleteFunc = void (*)(EqueueInternal* eq, EqueueEvent* event);
|
||||
|
||||
struct SceKernelEvent {
|
||||
u64 ident = 0; /* identifier for this event */
|
||||
s16 filter = 0; /* filter for event */
|
||||
u16 flags = 0;
|
||||
u32 fflags = 0;
|
||||
s64 data = 0;
|
||||
void* udata = nullptr; /* opaque user data identifier */
|
||||
};
|
||||
|
||||
struct Filter {
|
||||
void* data = nullptr;
|
||||
TriggerFunc trigger_event_func = nullptr;
|
||||
ResetFunc reset_event_func = nullptr;
|
||||
DeleteFunc delete_event_func = nullptr;
|
||||
};
|
||||
|
||||
struct EqueueEvent {
|
||||
bool isTriggered = false;
|
||||
SceKernelEvent event;
|
||||
Filter filter;
|
||||
};
|
||||
|
||||
class EqueueInternal {
|
||||
public:
|
||||
EqueueInternal() = default;
|
||||
virtual ~EqueueInternal();
|
||||
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:
|
||||
std::string m_name;
|
||||
std::mutex m_mutex;
|
||||
std::vector<EqueueEvent> m_events;
|
||||
std::condition_variable m_cond;
|
||||
};
|
||||
|
||||
} // namespace Core::Kernel
|
68
src/core/hle/kernel/Objects/physical_memory.cpp
Normal file
68
src/core/hle/kernel/Objects/physical_memory.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
#include "core/hle/kernel/objects/physical_memory.h"
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
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) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
u64 find_free_pos = 0;
|
||||
|
||||
// iterate through allocated blocked and find the next free position
|
||||
for (const auto& block : m_allocatedBlocks) {
|
||||
u64 n = block.start_addr + block.size;
|
||||
if (n > find_free_pos) {
|
||||
find_free_pos = n;
|
||||
}
|
||||
}
|
||||
|
||||
// align free position
|
||||
find_free_pos = AlignUp(find_free_pos, alignment);
|
||||
|
||||
// if the new position is between searchStart - searchEnd , allocate a new block
|
||||
if (find_free_pos >= searchStart && find_free_pos + len <= searchEnd) {
|
||||
AllocatedBlock block{};
|
||||
block.size = len;
|
||||
block.start_addr = find_free_pos;
|
||||
block.memoryType = memoryType;
|
||||
block.gpu_mode = GPU::MemoryMode::NoAccess;
|
||||
block.map_size = 0;
|
||||
block.map_virtual_addr = 0;
|
||||
block.prot = 0;
|
||||
block.cpu_mode = VirtualMemory::MemoryMode::NoAccess;
|
||||
|
||||
m_allocatedBlocks.push_back(block);
|
||||
|
||||
*physAddrOut = find_free_pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PhysicalMemory::Map(u64 virtual_addr, u64 phys_addr, u64 len, int prot,
|
||||
VirtualMemory::MemoryMode cpu_mode, GPU::MemoryMode gpu_mode) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
for (auto& b : m_allocatedBlocks) {
|
||||
if (phys_addr >= b.start_addr && phys_addr < b.start_addr + b.size) {
|
||||
if (b.map_virtual_addr != 0 || b.map_size != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
b.map_virtual_addr = virtual_addr;
|
||||
b.map_size = len;
|
||||
b.prot = prot;
|
||||
b.cpu_mode = cpu_mode;
|
||||
b.gpu_mode = gpu_mode;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace Core::Kernel
|
36
src/core/hle/kernel/Objects/physical_memory.h
Normal file
36
src/core/hle/kernel/Objects/physical_memory.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include "common/types.h"
|
||||
#include "core/virtual_memory.h"
|
||||
#include "core/PS4/GPU/gpu_memory.h"
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
class PhysicalMemory {
|
||||
public:
|
||||
struct AllocatedBlock {
|
||||
u64 start_addr;
|
||||
u64 size;
|
||||
int memoryType;
|
||||
u64 map_virtual_addr;
|
||||
u64 map_size;
|
||||
int prot;
|
||||
VirtualMemory::MemoryMode cpu_mode;
|
||||
GPU::MemoryMode gpu_mode;
|
||||
};
|
||||
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);
|
||||
|
||||
private:
|
||||
std::vector<AllocatedBlock> m_allocatedBlocks;
|
||||
std::mutex m_mutex;
|
||||
};
|
||||
|
||||
} // namespace Core::Kernel
|
123
src/core/hle/kernel/ThreadManagement.cpp
Normal file
123
src/core/hle/kernel/ThreadManagement.cpp
Normal file
|
@ -0,0 +1,123 @@
|
|||
#include "common/debug.h"
|
||||
#include "core/hle/kernel/ThreadManagement.h"
|
||||
#include "core/hle/error_codes.h"
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
thread_local PthreadInternal* g_pthread_self = nullptr;
|
||||
PThreadCxt* g_pthread_cxt = nullptr;
|
||||
|
||||
void Pthread_Init_Self_MainThread() {
|
||||
g_pthread_self = new PthreadInternal{};
|
||||
scePthreadAttrInit(&g_pthread_self->attr);
|
||||
g_pthread_self->pth = pthread_self();
|
||||
g_pthread_self->name = "Main_Thread";
|
||||
}
|
||||
|
||||
int scePthreadAttrInit(ScePthreadAttr* attr) {
|
||||
*attr = new PthreadAttrInternal{};
|
||||
|
||||
int result = pthread_attr_init(&(*attr)->pth_attr);
|
||||
|
||||
(*attr)->affinity = 0x7f;
|
||||
(*attr)->guard_size = 0x1000;
|
||||
|
||||
SceKernelSchedParam param{};
|
||||
param.sched_priority = 700;
|
||||
|
||||
result = (result == 0 ? scePthreadAttrSetinheritsched(attr, 4) : result);
|
||||
result = (result == 0 ? scePthreadAttrSetschedparam(attr, ¶m) : result);
|
||||
result = (result == 0 ? scePthreadAttrSetschedpolicy(attr, SCHED_OTHER) : result);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) {
|
||||
if (attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int pstate = PTHREAD_CREATE_JOINABLE;
|
||||
switch (detachstate) {
|
||||
case 0: pstate = PTHREAD_CREATE_JOINABLE; break;
|
||||
case 1: pstate = PTHREAD_CREATE_DETACHED; break;
|
||||
default: BREAKPOINT(); // unknown state
|
||||
}
|
||||
|
||||
int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate);
|
||||
|
||||
(*attr)->detached = (pstate == PTHREAD_CREATE_DETACHED);
|
||||
|
||||
if (result == 0) {
|
||||
return SCE_OK;
|
||||
}
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched) {
|
||||
if (attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
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: BREAKPOINT(); // unknown inheritSched
|
||||
}
|
||||
|
||||
int result = pthread_attr_setinheritsched(&(*attr)->pth_attr, pinherit_sched);
|
||||
|
||||
if (result == 0) {
|
||||
return SCE_OK;
|
||||
}
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param) {
|
||||
if (param == nullptr || attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
SceKernelSchedParam pparam{};
|
||||
if (param->sched_priority <= 478) {
|
||||
pparam.sched_priority = +2;
|
||||
} else if (param->sched_priority >= 733) {
|
||||
pparam.sched_priority = -2;
|
||||
} else {
|
||||
pparam.sched_priority = 0;
|
||||
}
|
||||
|
||||
int result = pthread_attr_setschedparam(&(*attr)->pth_attr, &pparam);
|
||||
|
||||
if (result == 0) {
|
||||
return SCE_OK;
|
||||
}
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) {
|
||||
if (attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
if (policy != SCHED_OTHER) {
|
||||
BREAKPOINT(); // invest if policy is other and if winpthreadlibrary support it
|
||||
}
|
||||
|
||||
(*attr)->policy = policy;
|
||||
|
||||
int result = pthread_attr_setschedpolicy(&(*attr)->pth_attr, policy);
|
||||
|
||||
if (result == 0) {
|
||||
return SCE_OK;
|
||||
}
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
} // namespace Core::Kernel
|
42
src/core/hle/kernel/ThreadManagement.h
Normal file
42
src/core/hle/kernel/ThreadManagement.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
#pragma once
|
||||
#define _TIMESPEC_DEFINED
|
||||
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include "common/types.h"
|
||||
#include <string>
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
struct PthreadAttrInternal;
|
||||
|
||||
using SceKernelSchedParam = ::sched_param;
|
||||
using ScePthreadAttr = PthreadAttrInternal*;
|
||||
|
||||
struct PthreadInternal {
|
||||
u08 reserved[4096];
|
||||
std::string name;
|
||||
pthread_t pth;
|
||||
ScePthreadAttr attr;
|
||||
};
|
||||
|
||||
struct PthreadAttrInternal {
|
||||
u08 reserved[64];
|
||||
u64 affinity;
|
||||
size_t guard_size;
|
||||
int policy;
|
||||
bool detached;
|
||||
pthread_attr_t pth_attr;
|
||||
};
|
||||
|
||||
class PThreadCxt {};
|
||||
|
||||
void Pthread_Init_Self_MainThread();
|
||||
|
||||
int scePthreadAttrInit(ScePthreadAttr* attr);
|
||||
int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate);
|
||||
int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched);
|
||||
int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param);
|
||||
int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy);
|
||||
|
||||
} // namespace Core::Kernel
|
13
src/core/hle/kernel/cpu_management.cpp
Normal file
13
src/core/hle/kernel/cpu_management.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "common/log.h"
|
||||
#include "core/hle/kernel/cpu_management.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
#include "Util/config.h"
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
int PS4_SYSV_ABI sceKernelIsNeoMode() {
|
||||
PRINT_FUNCTION_NAME();
|
||||
return Config::isNeoMode();
|
||||
}
|
||||
|
||||
} // namespace Core::Kernel
|
9
src/core/hle/kernel/cpu_management.h
Normal file
9
src/core/hle/kernel/cpu_management.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
int PS4_SYSV_ABI sceKernelIsNeoMode();
|
||||
|
||||
} // namespace Core::Kernel
|
71
src/core/hle/kernel/event_queues.cpp
Normal file
71
src/core/hle/kernel/event_queues.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "core/hle/kernel/event_queues.h"
|
||||
#include "core/hle/error_codes.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
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");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if (name == nullptr) {
|
||||
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");
|
||||
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");
|
||||
return SCE_KERNEL_ERROR_ENAMETOOLONG;
|
||||
}
|
||||
*eq = new EqueueInternal;
|
||||
(*eq)->setName(std::string(name));
|
||||
|
||||
LOG_INFO_IF(log_file_equeues, "sceKernelCreateEqueue created with name \"{}\"\n", name);
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev,
|
||||
int num, int* out, SceKernelUseconds* timo) {
|
||||
PRINT_FUNCTION_NAME();
|
||||
|
||||
if (eq == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EBADF;
|
||||
}
|
||||
|
||||
if (ev == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EFAULT;
|
||||
}
|
||||
|
||||
if (num < 1) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
if (timo == nullptr) { // wait until an event arrives without timing out
|
||||
*out = eq->waitForEvents(ev, num, 0);
|
||||
}
|
||||
|
||||
if (timo != nullptr) {
|
||||
// Only events that have already arrived at the time of this function call can be received
|
||||
if (*timo == 0) {
|
||||
BREAKPOINT();
|
||||
} else {
|
||||
// Wait until an event arrives with timing out
|
||||
BREAKPOINT();
|
||||
}
|
||||
}
|
||||
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
} // namespace Core::Kernel
|
14
src/core/hle/kernel/event_queues.h
Normal file
14
src/core/hle/kernel/event_queues.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "core/hle/kernel/objects/event_queue.h"
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
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);
|
||||
|
||||
} // namespace Core::Kernel
|
126
src/core/hle/kernel/memory_management.cpp
Normal file
126
src/core/hle/kernel/memory_management.cpp
Normal file
|
@ -0,0 +1,126 @@
|
|||
#include <bit>
|
||||
#include <magic_enum.hpp>
|
||||
#include <core/PS4/GPU/gpu_memory.h>
|
||||
#include <core/virtual_memory.h>
|
||||
#include "common/log.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/singleton.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
|
||||
|
||||
bool is16KBAligned(u64 n) {
|
||||
return ((n % (16ull * 1024) == 0));
|
||||
}
|
||||
|
||||
u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() {
|
||||
PRINT_FUNCTION_NAME();
|
||||
return SCE_KERNEL_MAIN_DMEM_SIZE;
|
||||
}
|
||||
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if (physAddrOut == nullptr) {
|
||||
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);
|
||||
|
||||
LOG_INFO_IF(log_file_memory, "search_start = {:#x}\n", searchStart);
|
||||
LOG_INFO_IF(log_file_memory, "search_end = {:#x}\n", searchEnd);
|
||||
LOG_INFO_IF(log_file_memory, "len = {:#x}\n", len);
|
||||
LOG_INFO_IF(log_file_memory, "alignment = {:#x}\n", alignment);
|
||||
LOG_INFO_IF(log_file_memory, "memory_type = {}\n", magic_enum::enum_name(memtype.value()));
|
||||
|
||||
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");
|
||||
return SCE_KERNEL_ERROR_EAGAIN;
|
||||
}
|
||||
*physAddrOut = static_cast<s64>(physical_addr);
|
||||
LOG_INFO_IF(true, "physAddrOut = {:#x}\n", physical_addr);
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
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");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if (!is16KBAligned(directMemoryStart)) {
|
||||
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");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
LOG_INFO_IF(log_file_memory, "len = {:#x}\n", len);
|
||||
LOG_INFO_IF(log_file_memory, "prot = {:#x}\n", prot);
|
||||
LOG_INFO_IF(log_file_memory, "flags = {:#x}\n", flags);
|
||||
LOG_INFO_IF(log_file_memory, "directMemoryStart = {:#x}\n", directMemoryStart);
|
||||
LOG_INFO_IF(log_file_memory, "alignment = {:#x}\n", alignment);
|
||||
|
||||
VirtualMemory::MemoryMode cpu_mode = VirtualMemory::MemoryMode::NoAccess;
|
||||
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();
|
||||
}
|
||||
|
||||
auto in_addr = reinterpret_cast<u64>(*addr);
|
||||
u64 out_addr = 0;
|
||||
|
||||
if (flags == 0) {
|
||||
out_addr = VirtualMemory::memory_alloc_aligned(in_addr, len, cpu_mode, alignment);
|
||||
}
|
||||
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
|
||||
|
||||
if (out_addr == 0) {
|
||||
return SCE_KERNEL_ERROR_ENOMEM;
|
||||
}
|
||||
|
||||
auto* physical_memory = Common::Singleton<PhysicalMemory>::Instance();
|
||||
if (!physical_memory->Map(out_addr, directMemoryStart, len, prot, cpu_mode, gpu_mode)) {
|
||||
BREAKPOINT();
|
||||
}
|
||||
|
||||
if (gpu_mode != GPU::MemoryMode::NoAccess) {
|
||||
GPU::memorySetAllocArea(out_addr, len);
|
||||
}
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
} // namespace Core::Kernel
|
34
src/core/hle/kernel/memory_management.h
Normal file
34
src/core/hle/kernel/memory_management.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
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)
|
||||
};
|
||||
|
||||
enum MemoryFlags : u32 {
|
||||
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
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
} // namespace Core::Kernel
|
|
@ -1,19 +1,17 @@
|
|||
#include "libc.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include "common/debug.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "common/singleton.h"
|
||||
#include "common/log.h"
|
||||
#include "core/PS4/HLE/Libs.h"
|
||||
#include "core/hle/libraries/libc/libc.h"
|
||||
#include "core/hle/libraries/libc/libc_cxa.h"
|
||||
#include "core/hle/libraries/libc/libc_math.h"
|
||||
#include "core/hle/libraries/libc/libc_stdio.h"
|
||||
#include "core/hle/libraries/libc/libc_stdlib.h"
|
||||
#include "core/hle/libraries/libc/libc_string.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
constexpr bool log_file_libc = true; // disable it to disable logging
|
||||
static u32 g_need_sceLibc = 1;
|
||||
|
||||
|
@ -39,28 +37,41 @@ static PS4_SYSV_ABI int __cxa_atexit(void (*func)(void*), void* arg, void* dso_h
|
|||
return 0;
|
||||
}
|
||||
|
||||
void PS4_SYSV_ABI __cxa_finalize(void* d) { __debugbreak(); }
|
||||
void PS4_SYSV_ABI __cxa_finalize(void* d) {
|
||||
BREAKPOINT();
|
||||
}
|
||||
|
||||
void PS4_SYSV_ABI __cxa_pure_virtual() { __debugbreak(); }
|
||||
void PS4_SYSV_ABI __cxa_pure_virtual() {
|
||||
BREAKPOINT();
|
||||
}
|
||||
|
||||
static PS4_SYSV_ABI void init_env() { PRINT_DUMMY_FUNCTION_NAME(); }
|
||||
static PS4_SYSV_ABI void init_env() {
|
||||
PRINT_DUMMY_FUNCTION_NAME();
|
||||
}
|
||||
|
||||
static PS4_SYSV_ABI void catchReturnFromMain(int status) { LOG_INFO_IF(log_file_libc, "catchReturnFromMain returned ={}\n", status); }
|
||||
static PS4_SYSV_ABI void catchReturnFromMain(int status) {
|
||||
LOG_INFO_IF(log_file_libc, "catchReturnFromMain returned ={}\n", status);
|
||||
}
|
||||
|
||||
static PS4_SYSV_ABI void _Assert() {
|
||||
PRINT_DUMMY_FUNCTION_NAME();
|
||||
BREAKPOINT();
|
||||
}
|
||||
|
||||
PS4_SYSV_ABI void _ZdlPv(void* ptr) { std::free(ptr); }
|
||||
PS4_SYSV_ABI void _ZdlPv(void* ptr) {
|
||||
std::free(ptr);
|
||||
}
|
||||
|
||||
PS4_SYSV_ABI void _ZSt11_Xbad_allocv() {
|
||||
PRINT_DUMMY_FUNCTION_NAME();
|
||||
BREAKPOINT();
|
||||
}
|
||||
|
||||
PS4_SYSV_ABI void _ZSt14_Xlength_errorPKc() {
|
||||
PRINT_DUMMY_FUNCTION_NAME();
|
||||
BREAKPOINT();
|
||||
}
|
||||
|
||||
PS4_SYSV_ABI void* _Znwm(u64 count) {
|
||||
if (count == 0) {
|
||||
LOG_ERROR_IF(log_file_libc, "_Znwm count ={}\n", count);
|
||||
|
@ -70,7 +81,7 @@ PS4_SYSV_ABI void* _Znwm(u64 count) {
|
|||
return ptr;
|
||||
}
|
||||
|
||||
void libcSymbolsRegister(SymbolsResolver* sym) {
|
||||
void libcSymbolsRegister(Loader::SymbolsResolver* sym) {
|
||||
// cxa functions
|
||||
LIB_FUNCTION("3GPpjQdAMTw", "libc", 1, "libc", 1, 1, __cxa_guard_acquire);
|
||||
LIB_FUNCTION("9rAeANT2tyE", "libc", 1, "libc", 1, 1, __cxa_guard_release);
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
#include "core/PS4/Loader/SymbolsResolver.h"
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
void libcSymbolsRegister(SymbolsResolver* sym);
|
||||
void libcSymbolsRegister(Loader::SymbolsResolver* sym);
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
// 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
|
||||
|
||||
// This file implements the __cxa_guard_* functions as defined at:
|
||||
|
@ -145,4 +146,4 @@ void PS4_SYSV_ABI __cxa_guard_abort(u64* guard_object) {
|
|||
setNotInUse(guard_object);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
#include "common/types.h"
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
int PS4_SYSV_ABI __cxa_guard_acquire(u64* guard_object);
|
||||
void PS4_SYSV_ABI __cxa_guard_release(u64* guard_object);
|
||||
void PS4_SYSV_ABI __cxa_guard_abort(u64* guard_object);
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -1,23 +1,38 @@
|
|||
#include "libc_math.h"
|
||||
|
||||
#include <cmath>
|
||||
#include "core/hle/libraries/libc/libc_math.h"
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
float PS4_SYSV_ABI atan2f(float y, float x) { return std::atan2f(y, x); }
|
||||
float PS4_SYSV_ABI atan2f(float y, float x) {
|
||||
return std::atan2f(y, x);
|
||||
}
|
||||
|
||||
float PS4_SYSV_ABI acosf(float num) { return std::acosf(num); }
|
||||
float PS4_SYSV_ABI acosf(float num) {
|
||||
return std::acosf(num);
|
||||
}
|
||||
|
||||
float PS4_SYSV_ABI tanf(float num) { return std::tanf(num); }
|
||||
float PS4_SYSV_ABI tanf(float num) {
|
||||
return std::tanf(num);
|
||||
}
|
||||
|
||||
float PS4_SYSV_ABI asinf(float num) { return std::asinf(num); }
|
||||
float PS4_SYSV_ABI asinf(float num) {
|
||||
return std::asinf(num);
|
||||
}
|
||||
|
||||
double PS4_SYSV_ABI pow(double base, double exponent) { return std::pow(base, exponent); }
|
||||
double PS4_SYSV_ABI pow(double base, double exponent) {
|
||||
return std::pow(base, exponent);
|
||||
}
|
||||
|
||||
double PS4_SYSV_ABI _Sin(double x) { return std::sin(x); }
|
||||
double PS4_SYSV_ABI _Sin(double x) {
|
||||
return std::sin(x);
|
||||
}
|
||||
|
||||
float PS4_SYSV_ABI _Fsin(float arg) { return std::sinf(arg); }
|
||||
float PS4_SYSV_ABI _Fsin(float arg) {
|
||||
return std::sinf(arg);
|
||||
}
|
||||
|
||||
double PS4_SYSV_ABI exp2(double arg) { return std::exp2(arg); }
|
||||
double PS4_SYSV_ABI exp2(double arg) {
|
||||
return std::exp2(arg);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "common/types.h"
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
float PS4_SYSV_ABI atan2f(float y, float x);
|
||||
float PS4_SYSV_ABI acosf(float num);
|
||||
float PS4_SYSV_ABI tanf(float num);
|
||||
|
@ -11,4 +12,5 @@ double PS4_SYSV_ABI pow(double base, double exponent);
|
|||
double PS4_SYSV_ABI _Sin(double x);
|
||||
float PS4_SYSV_ABI _Fsin(float arg);
|
||||
double PS4_SYSV_ABI exp2(double arg);
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
#include "libc_stdio.h"
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "core/hle/libraries/libc/libc_stdio.h"
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
constexpr bool log_file_libc = true; // disable it to disable logging
|
||||
|
||||
int PS4_SYSV_ABI printf(VA_ARGS) {
|
||||
VA_CTX(ctx);
|
||||
return printf_ctx(&ctx);
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI fprintf(FILE* file, VA_ARGS) {
|
||||
int fd = _fileno(file);
|
||||
if (fd == 1 || fd == 2) { // output stdout and stderr to console
|
||||
|
@ -21,8 +22,12 @@ int PS4_SYSV_ABI fprintf(FILE* file, VA_ARGS) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg) { return vsnprintf_ctx(s, n, format, arg); }
|
||||
int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg) {
|
||||
return vsnprintf_ctx(s, n, format, arg);
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI puts(const char* s) { return std::puts(s); }
|
||||
int PS4_SYSV_ABI puts(const char* s) {
|
||||
return std::puts(s);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
#include "printf.h"
|
||||
#include "core/hle/libraries/libc/printf.h"
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
int PS4_SYSV_ABI printf(VA_ARGS);
|
||||
int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg);
|
||||
int PS4_SYSV_ABI puts(const char* s);
|
||||
int PS4_SYSV_ABI fprintf(FILE* file, VA_ARGS);
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
#include "libc_stdlib.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include "common/log.h"
|
||||
#include "common/debug.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include "core/hle/libraries/libc/libc_stdlib.h"
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
constexpr bool log_file_libc = true; // disable it to disable logging
|
||||
|
||||
void PS4_SYSV_ABI exit(int code) { std::exit(code); }
|
||||
void PS4_SYSV_ABI exit(int code) {
|
||||
std::exit(code);
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI atexit(void (*func)()) {
|
||||
int rt = std::atexit(func);
|
||||
|
@ -19,19 +20,28 @@ int PS4_SYSV_ABI atexit(void (*func)()) {
|
|||
return rt;
|
||||
}
|
||||
|
||||
void* PS4_SYSV_ABI malloc(size_t size) { return std::malloc(size); }
|
||||
void* PS4_SYSV_ABI malloc(size_t size) {
|
||||
return std::malloc(size);
|
||||
}
|
||||
|
||||
void PS4_SYSV_ABI free(void* ptr) { std::free(ptr); }
|
||||
void PS4_SYSV_ABI free(void* ptr) {
|
||||
std::free(ptr);
|
||||
}
|
||||
|
||||
typedef int(PS4_SYSV_ABI* pfunc_QsortCmp)(const void*, const void*);
|
||||
thread_local static pfunc_QsortCmp compair_ps4;
|
||||
|
||||
int qsort_compair(const void* arg1, const void* arg2) { return compair_ps4(arg1, arg2); }
|
||||
int qsort_compair(const void* arg1, const void* arg2) {
|
||||
return compair_ps4(arg1, arg2);
|
||||
}
|
||||
|
||||
void PS4_SYSV_ABI 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);
|
||||
}
|
||||
int PS4_SYSV_ABI rand() { return std::rand(); }
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
int PS4_SYSV_ABI rand() {
|
||||
return std::rand();
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include "common/types.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
void PS4_SYSV_ABI exit(int code);
|
||||
int PS4_SYSV_ABI atexit(void (*func)());
|
||||
void* PS4_SYSV_ABI malloc(size_t size);
|
||||
void PS4_SYSV_ABI free(void* ptr);
|
||||
void PS4_SYSV_ABI qsort(void* ptr, size_t count, size_t size, int(PS4_SYSV_ABI* comp)(const void*, const void*));
|
||||
int PS4_SYSV_ABI rand();
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -1,25 +1,42 @@
|
|||
#include "libc_string.h"
|
||||
|
||||
#include <cstring>
|
||||
#include "core/hle/libraries/libc/libc_string.h"
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
int PS4_SYSV_ABI memcmp(const void* s1, const void* s2, size_t n) { return std::memcmp(s1, s2, n); }
|
||||
int PS4_SYSV_ABI memcmp(const void* s1, const void* s2, size_t n) {
|
||||
return std::memcmp(s1, s2, n);
|
||||
}
|
||||
|
||||
void* PS4_SYSV_ABI memcpy(void* dest, const void* src, size_t n) { return std::memcpy(dest, src, n); }
|
||||
void* PS4_SYSV_ABI memcpy(void* dest, const void* src, size_t n) {
|
||||
return std::memcpy(dest, src, n);
|
||||
}
|
||||
|
||||
void* PS4_SYSV_ABI memset(void* s, int c, size_t n) { return std::memset(s, c, n); }
|
||||
void* PS4_SYSV_ABI memset(void* s, int c, size_t n) {
|
||||
return std::memset(s, c, n);
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI strcmp(const char* str1, const char* str2) { return std::strcmp(str1, str2); }
|
||||
int PS4_SYSV_ABI strcmp(const char* str1, const char* str2) {
|
||||
return std::strcmp(str1, str2);
|
||||
}
|
||||
|
||||
char* PS4_SYSV_ABI strncpy(char* dest, const char* src, size_t count) { return std::strncpy(dest, src, count); }
|
||||
char* PS4_SYSV_ABI strncpy(char* dest, const char* src, size_t count) {
|
||||
return std::strncpy(dest, src, count);
|
||||
}
|
||||
|
||||
void* PS4_SYSV_ABI memmove(void* dest, const void* src, std::size_t count) { return std::memmove(dest, src, count); }
|
||||
void* PS4_SYSV_ABI memmove(void* dest, const void* src, std::size_t count) {
|
||||
return std::memmove(dest, src, count);
|
||||
}
|
||||
|
||||
char* PS4_SYSV_ABI strcpy(char* dest, const char* src) { return std::strcpy(dest, src); }
|
||||
char* PS4_SYSV_ABI strcpy(char* dest, const char* src) {
|
||||
return std::strcpy(dest, src);
|
||||
}
|
||||
|
||||
char* PS4_SYSV_ABI strcat(char* dest, const char* src) { return std::strcat(dest, src); }
|
||||
char* PS4_SYSV_ABI strcat(char* dest, const char* src) {
|
||||
return std::strcat(dest, src);
|
||||
}
|
||||
|
||||
size_t PS4_SYSV_ABI strlen(const char* str) { return std::strlen(str); }
|
||||
size_t PS4_SYSV_ABI strlen(const char* str) {
|
||||
return std::strlen(str);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include "common/types.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
int PS4_SYSV_ABI memcmp(const void* s1, const void* s2, size_t n);
|
||||
void* PS4_SYSV_ABI memcpy(void* dest, const void* src, size_t n);
|
||||
void* PS4_SYSV_ABI memset(void* s, int c, size_t n);
|
||||
|
@ -14,4 +14,5 @@ void* PS4_SYSV_ABI memmove(void* dest, const void* src, std::size_t count);
|
|||
char* PS4_SYSV_ABI strcpy(char* destination, const char* source);
|
||||
char* PS4_SYSV_ABI strcat(char* dest, const char* src);
|
||||
size_t PS4_SYSV_ABI strlen(const char* str);
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -103,4 +103,4 @@ T* vaArgPtr(VaList* l) {
|
|||
return vaArgOverflowArgArea<T*, 1, 8>(l);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include "file_system.h"
|
||||
|
||||
#include <core/PS4/HLE/Libs.h>
|
||||
#include "common/log.h"
|
||||
#include "common/debug.h"
|
||||
#include "core/hle/libraries/libkernel/file_system.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
|
||||
namespace Core::Libraries::LibKernel {
|
||||
|
||||
constexpr bool log_file_fs = true; // disable it to disable logging
|
||||
|
||||
int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) {
|
||||
|
@ -21,9 +21,9 @@ int PS4_SYSV_ABI open(const char* path, int flags, /* SceKernelMode*/ u16 mode)
|
|||
return result;
|
||||
}
|
||||
|
||||
void fileSystemSymbolsRegister(SymbolsResolver* sym) {
|
||||
void fileSystemSymbolsRegister(Loader::SymbolsResolver* sym) {
|
||||
LIB_FUNCTION("1G3lF1Gg1k8", "libkernel", 1, "libkernel", 1, 1, sceKernelOpen);
|
||||
LIB_FUNCTION("wuCroIGjt2g", "libScePosix", 1, "libkernel", 1, 1, open);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
#include "core/PS4/Loader/SymbolsResolver.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Core::Libraries::LibKernel {
|
||||
|
||||
int PS4_SYSV_ABI sceKernelOpen(const char *path, int flags, /* SceKernelMode*/ u16 mode);
|
||||
|
||||
// posix file system
|
||||
int PS4_SYSV_ABI open(const char *path, int flags, /* SceKernelMode*/ u16 mode);
|
||||
|
||||
void fileSystemSymbolsRegister(Loader::SymbolsResolver *sym);
|
||||
|
||||
void fileSystemSymbolsRegister(SymbolsResolver *sym);
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
|
|
55
src/core/hle/libraries/libkernel/libkernel.cpp
Normal file
55
src/core/hle/libraries/libkernel/libkernel.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include "common/log.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/singleton.h"
|
||||
#include "core/loader/elf.h"
|
||||
#include "core/hle/kernel/Objects/physical_memory.h"
|
||||
#include "core/hle/kernel/cpu_management.h"
|
||||
#include "core/hle/kernel/event_queues.h"
|
||||
#include "core/hle/kernel/memory_management.h"
|
||||
#include "core/hle/libraries/libkernel/libkernel.h"
|
||||
#include "core/hle/libraries/libkernel/file_system.h"
|
||||
#include "core/hle/libraries/libkernel/time_management.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
|
||||
#ifdef _WIN64
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace Core::Libraries::LibKernel {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) {
|
||||
BREAKPOINT();
|
||||
}
|
||||
|
||||
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("MBuItvba6z8", "libkernel", 1, "libkernel", 1, 1, sceKernelReleaseDirectMemory);
|
||||
LIB_FUNCTION("cQke9UuBQOk", "libkernel", 1, "libkernel", 1, 1, sceKernelMunmap);
|
||||
// equeue
|
||||
LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelCreateEqueue);
|
||||
LIB_FUNCTION("fzyMKs9kim0", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelWaitEqueue);
|
||||
// misc
|
||||
LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelIsNeoMode);
|
||||
LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail);
|
||||
|
||||
Core::Libraries::LibKernel::fileSystemSymbolsRegister(sym);
|
||||
Core::Libraries::LibKernel::timeSymbolsRegister(sym);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibKernel
|
16
src/core/hle/libraries/libkernel/libkernel.h
Normal file
16
src/core/hle/libraries/libkernel/libkernel.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Core::Libraries::LibKernel {
|
||||
|
||||
int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len);
|
||||
|
||||
void LibKernel_Register(Loader::SymbolsResolver* sym);
|
||||
|
||||
} // namespace Core::Libraries::LibKernel
|
|
@ -1,20 +1,27 @@
|
|||
#include "time_management.h"
|
||||
|
||||
#include <core/PS4/HLE/Libs.h>
|
||||
#include "core/hle/libraries/libkernel/time_management.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
#include "Lib/Timer.h"
|
||||
#include "emuTimer.h"
|
||||
|
||||
namespace Core::Libraries::LibKernel {
|
||||
|
||||
u64 PS4_SYSV_ABI sceKernelGetProcessTime() {
|
||||
return static_cast<u64>(Emulator::emuTimer::getTimeMsec() * 1000.0); // return time in microseconds
|
||||
}
|
||||
u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounter() { return Emulator::emuTimer::getTimeCounter(); }
|
||||
|
||||
u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounterFrequency() { return Emulator::emuTimer::getTimeFrequency(); }
|
||||
u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounter() {
|
||||
return Emulator::emuTimer::getTimeCounter();
|
||||
}
|
||||
|
||||
u64 PS4_SYSV_ABI sceKernelReadTsc() { return Lib::Timer::getQueryPerformanceCounter(); }
|
||||
u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounterFrequency() {
|
||||
return Emulator::emuTimer::getTimeFrequency();
|
||||
}
|
||||
|
||||
void timeSymbolsRegister(SymbolsResolver* sym) {
|
||||
u64 PS4_SYSV_ABI sceKernelReadTsc() {
|
||||
return Lib::Timer::getQueryPerformanceCounter();
|
||||
}
|
||||
|
||||
void timeSymbolsRegister(Loader::SymbolsResolver* sym) {
|
||||
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);
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
#include "core/PS4/Loader/SymbolsResolver.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Core::Libraries::LibKernel {
|
||||
|
||||
u64 PS4_SYSV_ABI sceKernelGetProcessTime();
|
||||
u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounter();
|
||||
u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounterFrequency();
|
||||
u64 PS4_SYSV_ABI sceKernelReadTsc();
|
||||
|
||||
void timeSymbolsRegister(SymbolsResolver* sym);
|
||||
}
|
||||
void timeSymbolsRegister(Loader::SymbolsResolver* sym);
|
||||
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
#include "pad.h"
|
||||
|
||||
#include <core/PS4/HLE/ErrorCodes.h>
|
||||
#include <core/PS4/HLE/Libs.h>
|
||||
|
||||
#include "common/singleton.h"
|
||||
#include "Emulator/Host/controller.h"
|
||||
#include "common/debug.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/libs.h"
|
||||
#include "Emulator/Host/controller.h"
|
||||
|
||||
namespace Core::Libraries::LibPad {
|
||||
|
||||
constexpr bool log_file_pad = true; // disable it to disable logging
|
||||
|
||||
int PS4_SYSV_ABI scePadInit() { return SCE_OK; }
|
||||
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) {
|
||||
|
@ -47,7 +46,7 @@ int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) {
|
|||
return SCE_OK;
|
||||
}
|
||||
|
||||
void padSymbolsRegister(SymbolsResolver* sym) {
|
||||
void padSymbolsRegister(Loader::SymbolsResolver* sym) {
|
||||
LIB_FUNCTION("hv1luiJrqQM", "libScePad", 1, "libScePad", 1, 1, scePadInit);
|
||||
LIB_FUNCTION("xk0AcarP3V4", "libScePad", 1, "libScePad", 1, 1, scePadOpen);
|
||||
LIB_FUNCTION("YndgXqQVV7c", "libScePad", 1, "libScePad", 1, 1, scePadReadState);
|
||||
|
|
|
@ -1,30 +1,29 @@
|
|||
#pragma once
|
||||
#include "common/types.h"
|
||||
|
||||
#include "core/PS4/Loader/SymbolsResolver.h"
|
||||
#include "core/hle/libraries/libuserservice/user_service.h"
|
||||
#include "common/types.h"
|
||||
#include "core/hle/libraries/libuserservice/libuserservice.h"
|
||||
|
||||
namespace Core::Libraries::LibPad {
|
||||
|
||||
typedef enum : u32 {
|
||||
SCE_PAD_BUTTON_L3 = 0x00000002,
|
||||
SCE_PAD_BUTTON_R3 = 0x00000004,
|
||||
SCE_PAD_BUTTON_OPTIONS = 0x00000008,
|
||||
SCE_PAD_BUTTON_UP = 0x00000010,
|
||||
SCE_PAD_BUTTON_RIGHT = 0x00000020,
|
||||
SCE_PAD_BUTTON_DOWN = 0x00000040,
|
||||
SCE_PAD_BUTTON_LEFT = 0x00000080,
|
||||
SCE_PAD_BUTTON_L2 = 0x00000100,
|
||||
SCE_PAD_BUTTON_R2 = 0x00000200,
|
||||
SCE_PAD_BUTTON_L1 = 0x00000400,
|
||||
SCE_PAD_BUTTON_R1 = 0x00000800,
|
||||
SCE_PAD_BUTTON_TRIANGLE = 0x00001000,
|
||||
SCE_PAD_BUTTON_CIRCLE = 0x00002000,
|
||||
SCE_PAD_BUTTON_CROSS = 0x00004000,
|
||||
SCE_PAD_BUTTON_SQUARE = 0x00008000,
|
||||
SCE_PAD_BUTTON_TOUCH_PAD = 0x00100000,
|
||||
SCE_PAD_BUTTON_INTERCEPTED = 0x80000000,
|
||||
} ScePadButton;
|
||||
enum ScePadButton : u32 {
|
||||
L3 = 0x00000002,
|
||||
R3 = 0x00000004,
|
||||
OPTIONS = 0x00000008,
|
||||
UP = 0x00000010,
|
||||
RIGHT = 0x00000020,
|
||||
DOWN = 0x00000040,
|
||||
LEFT = 0x00000080,
|
||||
L2 = 0x00000100,
|
||||
R2 = 0x00000200,
|
||||
L1 = 0x00000400,
|
||||
R1 = 0x00000800,
|
||||
TRIANGLE = 0x00001000,
|
||||
CIRCLE = 0x00002000,
|
||||
CROSS = 0x00004000,
|
||||
SQUARE = 0x00008000,
|
||||
TOUCH_PAD = 0x00100000,
|
||||
INTERCEPTED = 0x80000000,
|
||||
};
|
||||
|
||||
struct ScePadOpenParam {
|
||||
u08 reserve[8];
|
||||
|
@ -88,11 +87,12 @@ struct ScePadData {
|
|||
uint8_t deviceUniqueDataLen;
|
||||
uint8_t deviceUniqueData[12];
|
||||
};
|
||||
// hle functions
|
||||
|
||||
int PS4_SYSV_ABI scePadInit();
|
||||
int PS4_SYSV_ABI scePadOpen(Core::Libraries::LibUserService::SceUserServiceUserId userId, s32 type, s32 index,
|
||||
int PS4_SYSV_ABI scePadOpen(LibUserService::SceUserServiceUserId userId, s32 type, s32 index,
|
||||
const ScePadOpenParam* pParam);
|
||||
int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData);
|
||||
|
||||
void padSymbolsRegister(SymbolsResolver* sym);
|
||||
}; // namespace Core::Libraries::LibPad
|
||||
void padSymbolsRegister(Loader::SymbolsResolver* sym);
|
||||
|
||||
}; // namespace Core::Libraries::LibPad
|
||||
|
|
22
src/core/hle/libraries/libs.cpp
Normal file
22
src/core/hle/libraries/libs.cpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#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"
|
||||
|
||||
namespace Core::Libraries {
|
||||
|
||||
void InitHLELibs(Loader::SymbolsResolver* sym) {
|
||||
LibKernel::LibKernel_Register(sym);
|
||||
HLE::Libs::Graphics::VideoOut::videoOutRegisterLib(sym);
|
||||
LibSceGnmDriver::LibSceGnmDriver_Register(sym);
|
||||
LibUserService::userServiceSymbolsRegister(sym);
|
||||
LibPad::padSymbolsRegister(sym);
|
||||
LibSystemService::systemServiceSymbolsRegister(sym);
|
||||
LibC::libcSymbolsRegister(sym);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries
|
46
src/core/hle/libraries/libs.h
Normal file
46
src/core/hle/libraries/libs.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#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 PRINT_FUNCTION_NAME() \
|
||||
{ \
|
||||
LOG_INFO_IF(true, "{}()\n", __func__); \
|
||||
}
|
||||
|
||||
#define PRINT_DUMMY_FUNCTION_NAME() \
|
||||
{ LOG_WARN_IF(true, "dummy {}()\n", __func__); }
|
||||
|
||||
namespace Core::Libraries {
|
||||
|
||||
void InitHLELibs(Loader::SymbolsResolver* sym);
|
||||
|
||||
} // namespace Core::Libraries
|
24
src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp
Normal file
24
src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#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 "emulator.h"
|
||||
|
||||
namespace Core::Libraries::LibSceGnmDriver {
|
||||
|
||||
int32_t sceGnmSubmitDone() {
|
||||
PRINT_DUMMY_FUNCTION_NAME();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sceGnmFlushGarlic() {
|
||||
PRINT_FUNCTION_NAME();
|
||||
GPU::flushGarlic(Emu::getGraphicCtx());
|
||||
}
|
||||
|
||||
void LibSceGnmDriver_Register(Loader::SymbolsResolver* sym) {
|
||||
LIB_FUNCTION("yvZ73uQUqrk", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSubmitDone);
|
||||
LIB_FUNCTION("iBt3Oe00Kvc", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmFlushGarlic);
|
||||
}
|
||||
|
||||
};
|
16
src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h
Normal file
16
src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Core::Libraries::LibSceGnmDriver {
|
||||
|
||||
int32_t sceGnmSubmitDone();
|
||||
void sceGnmFlushGarlic();
|
||||
|
||||
void LibSceGnmDriver_Register(Loader::SymbolsResolver* sym);
|
||||
|
||||
}; // namespace Core::Libraries::LibSceGnmDriver
|
|
@ -1,7 +1,7 @@
|
|||
#include <core/PS4/HLE/ErrorCodes.h>
|
||||
#include <core/PS4/HLE/Libs.h>
|
||||
#include "common/log.h"
|
||||
#include "system_service.h"
|
||||
#include "core/hle/error_codes.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
#include "core/hle/libraries/libsystemservice/system_service.h"
|
||||
|
||||
namespace Core::Libraries::LibSystemService {
|
||||
|
||||
|
@ -10,7 +10,9 @@ s32 PS4_SYSV_ABI sceSystemServiceHideSplashScreen() {
|
|||
return SCE_OK;
|
||||
}
|
||||
|
||||
void systemServiceSymbolsRegister(SymbolsResolver* sym) {
|
||||
LIB_FUNCTION("Vo5V8KAwCmk", "libSceSystemService", 1, "libSceSystemService", 1, 1, sceSystemServiceHideSplashScreen);
|
||||
void systemServiceSymbolsRegister(Loader::SymbolsResolver* sym) {
|
||||
LIB_FUNCTION("Vo5V8KAwCmk", "libSceSystemService", 1, "libSceSystemService", 1, 1,
|
||||
sceSystemServiceHideSplashScreen);
|
||||
}
|
||||
}; // namespace Emulator::HLE::Libraries::LibUserService
|
||||
|
||||
}; // namespace Core::Libraries::LibSystemService
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
#pragma once
|
||||
#include "core/PS4/Loader/SymbolsResolver.h"
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Core::Libraries::LibSystemService {
|
||||
|
||||
//HLE functions
|
||||
s32 PS4_SYSV_ABI sceSystemServiceHideSplashScreen();
|
||||
|
||||
void systemServiceSymbolsRegister(SymbolsResolver* sym);
|
||||
void systemServiceSymbolsRegister(Loader::SymbolsResolver* sym);
|
||||
|
||||
}; // namespace Emulator::HLE::Libraries::LibUserService
|
||||
}; // namespace Core::Libraries::LibSystemService
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
#include "user_service.h"
|
||||
|
||||
#include <core/PS4/HLE/ErrorCodes.h>
|
||||
#include <core/PS4/HLE/Libs.h>
|
||||
|
||||
#include "common/log.h"
|
||||
#include "core/hle/libraries/libuserservice/libuserservice.h"
|
||||
#include "core/hle/error_codes.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
|
||||
namespace Core::Libraries::LibUserService {
|
||||
|
||||
|
@ -21,9 +19,10 @@ s32 PS4_SYSV_ABI sceUserServiceGetLoginUserIdList(SceUserServiceLoginUserIdList*
|
|||
|
||||
return SCE_OK;
|
||||
}
|
||||
void userServiceSymbolsRegister(SymbolsResolver* sym) {
|
||||
|
||||
void userServiceSymbolsRegister(Loader::SymbolsResolver* sym) {
|
||||
LIB_FUNCTION("j3YMu1MVNNo", "libSceUserService", 1, "libSceUserService", 1, 1, sceUserServiceInitialize);
|
||||
LIB_FUNCTION("fPhymKNvK-A", "libSceUserService", 1, "libSceUserService", 1, 1, sceUserServiceGetLoginUserIdList);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibUserService
|
||||
} // namespace Core::Libraries::LibUserService
|
|
@ -1,5 +1,10 @@
|
|||
#pragma once
|
||||
#include "core/PS4/Loader/SymbolsResolver.h"
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Core::Libraries::LibUserService {
|
||||
|
||||
|
@ -16,5 +21,6 @@ struct SceUserServiceLoginUserIdList {
|
|||
s32 PS4_SYSV_ABI sceUserServiceInitialize(const SceUserServiceInitializeParams* initParams);
|
||||
s32 PS4_SYSV_ABI sceUserServiceGetLoginUserIdList(SceUserServiceLoginUserIdList* userIdList);
|
||||
|
||||
void userServiceSymbolsRegister(SymbolsResolver* sym);
|
||||
}; // namespace Emulator::HLE::Libraries::LibUserService
|
||||
void userServiceSymbolsRegister(Loader::SymbolsResolver* sym);
|
||||
|
||||
}; // namespace Core::Libraries::LibUserService
|
12
src/core/hle/libraries/libuserservice/usr_mng_codes.h
Normal file
12
src/core/hle/libraries/libuserservice/usr_mng_codes.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#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)
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue