mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-20 11:36:13 +00:00
sceLibKernel.h added
This commit is contained in:
parent
55a2a5c8e5
commit
2647b77c01
6 changed files with 381 additions and 99 deletions
|
@ -4,89 +4,13 @@
|
|||
#include "Emu/ARMv7/PSVFuncList.h"
|
||||
|
||||
#include "Emu/CPU/CPUThreadManager.h"
|
||||
#include "Emu/SysCalls/Callback.h"
|
||||
#include "Emu/ARMv7/ARMv7Thread.h"
|
||||
|
||||
extern psv_log_base sceLibKernel;
|
||||
#include "sceLibKernel.h"
|
||||
|
||||
#define RETURN_ERROR(code) { Emu.Pause(); sceLibKernel.Error("%s() failed: %s", __FUNCTION__, #code); return code; }
|
||||
|
||||
#pragma pack(push, 4)
|
||||
|
||||
typedef s32(*SceKernelThreadEntry)(u32 argSize, vm::psv::ptr<void> pArgBlock);
|
||||
|
||||
union SceKernelSysClock
|
||||
{
|
||||
struct
|
||||
{
|
||||
u32 low;
|
||||
u32 hi;
|
||||
};
|
||||
u64 quad;
|
||||
};
|
||||
|
||||
struct SceKernelThreadOptParam
|
||||
{
|
||||
u32 size;
|
||||
u32 attr;
|
||||
};
|
||||
|
||||
struct SceKernelThreadInfo
|
||||
{
|
||||
u32 size;
|
||||
s32 processId;
|
||||
char name[32];
|
||||
u32 attr;
|
||||
u32 status;
|
||||
SceKernelThreadEntry entry;
|
||||
vm::psv::ptr<void> pStack;
|
||||
u32 stackSize;
|
||||
s32 initPriority;
|
||||
s32 currentPriority;
|
||||
s32 initCpuAffinityMask;
|
||||
s32 currentCpuAffinityMask;
|
||||
s32 currentCpuId;
|
||||
s32 lastExecutedCpuId;
|
||||
u32 waitType;
|
||||
s32 waitId;
|
||||
s32 exitStatus;
|
||||
SceKernelSysClock runClocks;
|
||||
u32 intrPreemptCount;
|
||||
u32 threadPreemptCount;
|
||||
u32 threadReleaseCount;
|
||||
s32 changeCpuCount;
|
||||
s32 fNotifyCallback;
|
||||
s32 reserved;
|
||||
};
|
||||
|
||||
struct SceKernelThreadRunStatus
|
||||
{
|
||||
u32 size;
|
||||
|
||||
struct
|
||||
{
|
||||
s32 processId;
|
||||
s32 threadId;
|
||||
s32 priority;
|
||||
|
||||
} cpuInfo[4];
|
||||
};
|
||||
|
||||
struct SceKernelSystemInfo
|
||||
{
|
||||
u32 size;
|
||||
u32 activeCpuMask;
|
||||
|
||||
struct
|
||||
{
|
||||
SceKernelSysClock idleClock;
|
||||
u32 comesOutOfIdleCount;
|
||||
u32 threadSwitchCount;
|
||||
|
||||
} cpuInfo[4];
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
u32 sceKernelCreateThread(
|
||||
vm::psv::ptr<const char> pName,
|
||||
vm::psv::ptr<SceKernelThreadEntry> entry,
|
||||
|
@ -113,17 +37,24 @@ u32 sceKernelCreateThread(
|
|||
return id;
|
||||
}
|
||||
|
||||
s32 sceKernelStartThread(u32 threadId, u32 argSize, vm::psv::ptr<const void> pArgBlock)
|
||||
s32 sceKernelStartThread(s32 threadId, u32 argSize, vm::psv::ptr<const void> pArgBlock)
|
||||
{
|
||||
sceLibKernel.Error("sceKernelStartThread(threadId=0x%x, argSize=0x%x, pArgBlock=0x%x)", threadId, argSize, pArgBlock);
|
||||
|
||||
std::shared_ptr<CPUThread> t = Emu.GetCPU().GetThread(threadId);
|
||||
std::shared_ptr<CPUThread> t = Emu.GetCPU().GetThread(threadId, CPU_THREAD_ARMv7);
|
||||
|
||||
if (!t || t->GetType() != CPU_THREAD_ARMv7)
|
||||
if (!t)
|
||||
{
|
||||
RETURN_ERROR(SCE_KERNEL_ERROR_INVALID_UID);
|
||||
}
|
||||
|
||||
// thread should be in DORMANT state, but it's not possible to check it correctly atm
|
||||
|
||||
if (t->IsAlive())
|
||||
{
|
||||
RETURN_ERROR(SCE_KERNEL_ERROR_NOT_DORMANT);
|
||||
}
|
||||
|
||||
ARMv7Thread& thread = static_cast<ARMv7Thread&>(*t);
|
||||
|
||||
// push arg block onto the stack
|
||||
|
@ -148,35 +79,60 @@ s32 sceKernelExitThread(ARMv7Context& context, s32 exitStatus)
|
|||
return SCE_OK;
|
||||
}
|
||||
|
||||
s32 sceKernelDeleteThread(u32 threadId)
|
||||
s32 sceKernelDeleteThread(s32 threadId)
|
||||
{
|
||||
sceLibKernel.Todo("sceKernelDeleteThread(threadId=0x%x)", threadId);
|
||||
sceLibKernel.Error("sceKernelDeleteThread(threadId=0x%x)", threadId);
|
||||
|
||||
std::shared_ptr<CPUThread> t = Emu.GetCPU().GetThread(threadId, CPU_THREAD_ARMv7);
|
||||
|
||||
if (!t)
|
||||
{
|
||||
RETURN_ERROR(SCE_KERNEL_ERROR_INVALID_UID);
|
||||
}
|
||||
|
||||
// thread should be in DORMANT state, but it's not possible to check it correctly atm
|
||||
|
||||
if (t->IsAlive())
|
||||
{
|
||||
RETURN_ERROR(SCE_KERNEL_ERROR_NOT_DORMANT);
|
||||
}
|
||||
|
||||
Emu.GetCPU().RemoveThread(threadId);
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
s32 sceKernelExitDeleteThread(ARMv7Context& context, s32 exitStatus)
|
||||
{
|
||||
sceLibKernel.Error("sceKernelExitDeleteThread(exitStatus=0x%x)", exitStatus);
|
||||
|
||||
// exit status is stored in r0
|
||||
context.thread.Stop();
|
||||
|
||||
// current thread should be deleted
|
||||
const u32 id = context.thread.GetId();
|
||||
CallAfter([id]()
|
||||
{
|
||||
Emu.GetCPU().RemoveThread(id);
|
||||
});
|
||||
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
s32 sceKernelExitDeleteThread(s32 exitStatus)
|
||||
{
|
||||
sceLibKernel.Todo("sceKernelExitDeleteThread(exitStatus=0x%x)", exitStatus);
|
||||
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
s32 sceKernelChangeThreadCpuAffinityMask(u32 threadId, s32 cpuAffinityMask)
|
||||
s32 sceKernelChangeThreadCpuAffinityMask(s32 threadId, s32 cpuAffinityMask)
|
||||
{
|
||||
sceLibKernel.Todo("sceKernelChangeThreadCpuAffinityMask(threadId=0x%x, cpuAffinityMask=0x%x)", threadId, cpuAffinityMask);
|
||||
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
s32 sceKernelGetThreadCpuAffinityMask(u32 threadId)
|
||||
s32 sceKernelGetThreadCpuAffinityMask(s32 threadId)
|
||||
{
|
||||
sceLibKernel.Todo("sceKernelGetThreadCpuAffinityMask(threadId=0x%x)", threadId);
|
||||
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
s32 sceKernelChangeThreadPriority(u32 threadId, s32 priority)
|
||||
s32 sceKernelChangeThreadPriority(s32 threadId, s32 priority)
|
||||
{
|
||||
sceLibKernel.Todo("sceKernelChangeThreadPriority(threadId=0x%x, priority=%d)", threadId, priority);
|
||||
|
||||
|
@ -204,7 +160,7 @@ s32 sceKernelChangeCurrentThreadAttr(u32 clearAttr, u32 setAttr)
|
|||
return SCE_OK;
|
||||
}
|
||||
|
||||
s32 sceKernelGetThreadExitStatus(u32 threadId, vm::psv::ptr<s32> pExitStatus)
|
||||
s32 sceKernelGetThreadExitStatus(s32 threadId, vm::psv::ptr<s32> pExitStatus)
|
||||
{
|
||||
sceLibKernel.Todo("sceKernelGetThreadExitStatus(threadId=0x%x, pExitStatus=0x%x)", threadId, pExitStatus);
|
||||
|
||||
|
@ -225,7 +181,7 @@ s32 sceKernelCheckWaitableStatus()
|
|||
return SCE_OK;
|
||||
}
|
||||
|
||||
s32 sceKernelGetThreadInfo(u32 threadId, vm::psv::ptr<SceKernelThreadInfo> pInfo)
|
||||
s32 sceKernelGetThreadInfo(s32 threadId, vm::psv::ptr<SceKernelThreadInfo> pInfo)
|
||||
{
|
||||
sceLibKernel.Todo("sceKernelGetThreadInfo(threadId=0x%x, pInfo=0x%x)", threadId, pInfo);
|
||||
|
||||
|
@ -281,13 +237,13 @@ s32 sceKernelDelayThreadCB(u32 usec)
|
|||
return SCE_OK;
|
||||
}
|
||||
|
||||
s32 sceKernelWaitThreadEnd(u32 threadId, vm::psv::ptr<s32> pExitStatus, vm::psv::ptr<u32> pTimeout)
|
||||
s32 sceKernelWaitThreadEnd(s32 threadId, vm::psv::ptr<s32> pExitStatus, vm::psv::ptr<u32> pTimeout)
|
||||
{
|
||||
sceLibKernel.Error("sceKernelWaitThreadEnd(threadId=0x%x, pExitStatus=0x%x, pTimeout=0x%x)", threadId, pExitStatus, pTimeout);
|
||||
|
||||
std::shared_ptr<CPUThread> t = Emu.GetCPU().GetThread(threadId);
|
||||
std::shared_ptr<CPUThread> t = Emu.GetCPU().GetThread(threadId, CPU_THREAD_ARMv7);
|
||||
|
||||
if (!t || t->GetType() != CPU_THREAD_ARMv7)
|
||||
if (!t)
|
||||
{
|
||||
RETURN_ERROR(SCE_KERNEL_ERROR_INVALID_UID);
|
||||
}
|
||||
|
@ -316,7 +272,7 @@ s32 sceKernelWaitThreadEnd(u32 threadId, vm::psv::ptr<s32> pExitStatus, vm::psv:
|
|||
return SCE_OK;
|
||||
}
|
||||
|
||||
s32 sceKernelWaitThreadEndCB(u32 threadId, vm::psv::ptr<s32> pExitStatus, vm::psv::ptr<u32> pTimeout)
|
||||
s32 sceKernelWaitThreadEndCB(s32 threadId, vm::psv::ptr<s32> pExitStatus, vm::psv::ptr<u32> pTimeout)
|
||||
{
|
||||
sceLibKernel.Todo("sceKernelWaitThreadEndCB(threadId=0x%x, pExitStatus=0x%x, pTimeout=0x%x)", threadId, pExitStatus, pTimeout);
|
||||
|
||||
|
|
308
rpcs3/Emu/ARMv7/Modules/sceLibKernel.h
Normal file
308
rpcs3/Emu/ARMv7/Modules/sceLibKernel.h
Normal file
|
@ -0,0 +1,308 @@
|
|||
#pragma once
|
||||
|
||||
union SceKernelSysClock
|
||||
{
|
||||
struct
|
||||
{
|
||||
u32 low;
|
||||
u32 hi;
|
||||
};
|
||||
|
||||
u64 quad;
|
||||
};
|
||||
|
||||
// Memory Manager definitions
|
||||
|
||||
typedef s32 SceKernelMemoryType;
|
||||
|
||||
struct SceKernelMemBlockInfo
|
||||
{
|
||||
u32 size;
|
||||
vm::psv::ptr<void> mappedBase;
|
||||
u32 mappedSize;
|
||||
SceKernelMemoryType memoryType;
|
||||
u32 access;
|
||||
};
|
||||
|
||||
// Thread Manager definitions (threads)
|
||||
|
||||
typedef s32(*SceKernelThreadEntry)(u32 argSize, vm::psv::ptr<void> pArgBlock);
|
||||
|
||||
struct SceKernelThreadOptParam
|
||||
{
|
||||
u32 size;
|
||||
u32 attr;
|
||||
};
|
||||
|
||||
struct SceKernelThreadInfo
|
||||
{
|
||||
u32 size;
|
||||
s32 processId;
|
||||
char name[32];
|
||||
u32 attr;
|
||||
u32 status;
|
||||
vm::psv::ptr<SceKernelThreadEntry> entry;
|
||||
vm::psv::ptr<void> pStack;
|
||||
u32 stackSize;
|
||||
s32 initPriority;
|
||||
s32 currentPriority;
|
||||
s32 initCpuAffinityMask;
|
||||
s32 currentCpuAffinityMask;
|
||||
s32 currentCpuId;
|
||||
s32 lastExecutedCpuId;
|
||||
u32 waitType;
|
||||
s32 waitId;
|
||||
s32 exitStatus;
|
||||
SceKernelSysClock runClocks;
|
||||
u32 intrPreemptCount;
|
||||
u32 threadPreemptCount;
|
||||
u32 threadReleaseCount;
|
||||
s32 changeCpuCount;
|
||||
s32 fNotifyCallback;
|
||||
s32 reserved;
|
||||
};
|
||||
|
||||
struct SceKernelThreadRunStatus
|
||||
{
|
||||
u32 size;
|
||||
|
||||
struct
|
||||
{
|
||||
s32 processId;
|
||||
s32 threadId;
|
||||
s32 priority;
|
||||
|
||||
} cpuInfo[4];
|
||||
};
|
||||
|
||||
struct SceKernelSystemInfo
|
||||
{
|
||||
u32 size;
|
||||
u32 activeCpuMask;
|
||||
|
||||
struct
|
||||
{
|
||||
SceKernelSysClock idleClock;
|
||||
u32 comesOutOfIdleCount;
|
||||
u32 threadSwitchCount;
|
||||
|
||||
} cpuInfo[4];
|
||||
};
|
||||
|
||||
// Thread Manager definitions (callbacks)
|
||||
|
||||
typedef s32(*SceKernelCallbackFunction)(s32 notifyId, s32 notifyCount, s32 notifyArg, vm::psv::ptr<void> pCommon);
|
||||
|
||||
struct SceKernelCallbackInfo
|
||||
{
|
||||
u32 size;
|
||||
s32 callbackId;
|
||||
char name[32];
|
||||
u32 attr;
|
||||
s32 threadId;
|
||||
vm::psv::ptr<SceKernelCallbackFunction> callbackFunc;
|
||||
s32 notifyId;
|
||||
s32 notifyCount;
|
||||
s32 notifyArg;
|
||||
vm::psv::ptr<void> pCommon;
|
||||
};
|
||||
|
||||
// Thread Manager definitions (events)
|
||||
|
||||
typedef s32(*SceKernelThreadEventHandler)(s32 type, s32 threadId, s32 arg, vm::psv::ptr<void> pCommon);
|
||||
|
||||
struct SceKernelEventInfo
|
||||
{
|
||||
u32 size;
|
||||
s32 eventId;
|
||||
char name[32];
|
||||
u32 attr;
|
||||
u32 eventPattern;
|
||||
u64 userData;
|
||||
u32 numWaitThreads;
|
||||
s32 reserved[1];
|
||||
};
|
||||
|
||||
struct SceKernelWaitEvent
|
||||
{
|
||||
s32 eventId;
|
||||
u32 eventPattern;
|
||||
};
|
||||
|
||||
struct SceKernelResultEvent
|
||||
{
|
||||
s32 eventId;
|
||||
s32 result;
|
||||
u32 resultPattern;
|
||||
s32 reserved[1];
|
||||
u64 userData;
|
||||
};
|
||||
|
||||
// Thread Manager definitions (event flags)
|
||||
|
||||
struct SceKernelEventFlagOptParam
|
||||
{
|
||||
u32 size;
|
||||
};
|
||||
|
||||
struct SceKernelEventFlagInfo
|
||||
{
|
||||
u32 size;
|
||||
s32 evfId;
|
||||
char name[32];
|
||||
u32 attr;
|
||||
u32 initPattern;
|
||||
u32 currentPattern;
|
||||
s32 numWaitThreads;
|
||||
};
|
||||
|
||||
// Thread Manager definitions (semaphores)
|
||||
|
||||
struct SceKernelSemaOptParam
|
||||
{
|
||||
u32 size;
|
||||
};
|
||||
|
||||
struct SceKernelSemaInfo
|
||||
{
|
||||
u32 size;
|
||||
s32 semaId;
|
||||
char name[32];
|
||||
u32 attr;
|
||||
s32 initCount;
|
||||
s32 currentCount;
|
||||
s32 maxCount;
|
||||
s32 numWaitThreads;
|
||||
};
|
||||
|
||||
// Thread Manager definitions (mutexes)
|
||||
|
||||
struct SceKernelMutexOptParam
|
||||
{
|
||||
u32 size;
|
||||
s32 ceilingPriority;
|
||||
};
|
||||
|
||||
struct SceKernelMutexInfo
|
||||
{
|
||||
u32 size;
|
||||
s32 mutexId;
|
||||
char name[32];
|
||||
u32 attr;
|
||||
s32 initCount;
|
||||
s32 currentCount;
|
||||
s32 currentOwnerId;
|
||||
s32 numWaitThreads;
|
||||
};
|
||||
|
||||
// Thread Manager definitions (lightweight mutexes)
|
||||
|
||||
struct SceKernelLwMutexWork
|
||||
{
|
||||
s32 data[4];
|
||||
};
|
||||
|
||||
struct SceKernelLwMutexOptParam
|
||||
{
|
||||
u32 size;
|
||||
};
|
||||
|
||||
struct SceKernelLwMutexInfo
|
||||
{
|
||||
u32 size;
|
||||
s32 uid;
|
||||
char name[32];
|
||||
u32 attr;
|
||||
vm::psv::ptr<SceKernelLwMutexWork> pWork;
|
||||
s32 initCount;
|
||||
s32 currentCount;
|
||||
s32 currentOwnerId;
|
||||
s32 numWaitThreads;
|
||||
};
|
||||
|
||||
// Thread Manager definitions (condition variables)
|
||||
|
||||
struct SceKernelCondOptParam
|
||||
{
|
||||
u32 size;
|
||||
};
|
||||
|
||||
struct SceKernelCondInfo
|
||||
{
|
||||
u32 size;
|
||||
s32 condId;
|
||||
char name[32];
|
||||
u32 attr;
|
||||
s32 mutexId;
|
||||
u32 numWaitThreads;
|
||||
};
|
||||
|
||||
// Thread Manager definitions (lightweight condition variables)
|
||||
|
||||
struct SceKernelLwCondWork
|
||||
{
|
||||
s32 data[4];
|
||||
};
|
||||
|
||||
struct SceKernelLwCondOptParam
|
||||
{
|
||||
u32 size;
|
||||
};
|
||||
|
||||
struct SceKernelLwCondInfo
|
||||
{
|
||||
u32 size;
|
||||
s32 uid;
|
||||
char name[32];
|
||||
u32 attr;
|
||||
vm::psv::ptr<SceKernelLwCondWork> pWork;
|
||||
vm::psv::ptr<SceKernelLwMutexWork> pLwMutex;
|
||||
u32 numWaitThreads;
|
||||
};
|
||||
|
||||
// Thread Manager definitions (timers)
|
||||
|
||||
struct SceKernelTimerOptParam
|
||||
{
|
||||
u32 size;
|
||||
};
|
||||
|
||||
struct SceKernelTimerInfo
|
||||
{
|
||||
u32 size;
|
||||
s32 timerId;
|
||||
char name[32];
|
||||
u32 attr;
|
||||
s32 fActive;
|
||||
SceKernelSysClock baseTime;
|
||||
SceKernelSysClock currentTime;
|
||||
SceKernelSysClock schedule;
|
||||
SceKernelSysClock interval;
|
||||
s32 type;
|
||||
s32 fRepeat;
|
||||
s32 numWaitThreads;
|
||||
s32 reserved[1];
|
||||
};
|
||||
|
||||
// Thread Manager definitions (reader/writer locks)
|
||||
|
||||
struct SceKernelRWLockOptParam
|
||||
{
|
||||
u32 size;
|
||||
};
|
||||
|
||||
struct SceKernelRWLockInfo
|
||||
{
|
||||
u32 size;
|
||||
s32 rwLockId;
|
||||
char name[32];
|
||||
u32 attr;
|
||||
s32 lockCount;
|
||||
s32 writeOwnerId;
|
||||
s32 numReadWaitThreads;
|
||||
s32 numWriteWaitThreads;
|
||||
};
|
||||
|
||||
// Module
|
||||
|
||||
extern psv_log_base sceLibKernel;
|
|
@ -117,6 +117,19 @@ std::shared_ptr<CPUThread> CPUThreadManager::GetThread(u32 id)
|
|||
return res;
|
||||
}
|
||||
|
||||
std::shared_ptr<CPUThread> CPUThreadManager::GetThread(u32 id, CPUThreadType type)
|
||||
{
|
||||
std::shared_ptr<CPUThread> res;
|
||||
|
||||
if (!id) return nullptr;
|
||||
|
||||
if (!Emu.GetIdManager().GetIDData(id, res)) return nullptr;
|
||||
|
||||
if (res->GetType() != type) return nullptr;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
RawSPUThread* CPUThreadManager::GetRawSPUThread(u32 num)
|
||||
{
|
||||
if (num < sizeof(Memory.RawSPUMem) / sizeof(Memory.RawSPUMem[0]))
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
//std::vector<std::shared_ptr<CPUThread>>& GetThreads() { return m_threads; }
|
||||
s32 GetThreadNumById(CPUThreadType type, u32 id);
|
||||
std::shared_ptr<CPUThread> GetThread(u32 id);
|
||||
std::shared_ptr<CPUThread> GetThread(u32 id, CPUThreadType type);
|
||||
RawSPUThread* GetRawSPUThread(u32 num);
|
||||
|
||||
void Exec();
|
||||
|
|
|
@ -274,6 +274,7 @@
|
|||
<ClInclude Include="Emu\ARMv7\ARMv7Interpreter.h" />
|
||||
<ClInclude Include="Emu\ARMv7\ARMv7Opcodes.h" />
|
||||
<ClInclude Include="Emu\ARMv7\ARMv7Thread.h" />
|
||||
<ClInclude Include="Emu\ARMv7\Modules\sceLibKernel.h" />
|
||||
<ClInclude Include="Emu\ARMv7\PSVFuncList.h" />
|
||||
<ClInclude Include="Emu\Audio\AL\OpenALThread.h" />
|
||||
<ClInclude Include="Emu\Audio\AudioDumper.h" />
|
||||
|
|
|
@ -1291,5 +1291,8 @@
|
|||
<ClInclude Include="Emu\ARMv7\ARMv7Callback.h">
|
||||
<Filter>Emu\CPU\ARMv7</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Emu\ARMv7\Modules\sceLibKernel.h">
|
||||
<Filter>Emu\CPU\ARMv7\Modules</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Add table
Reference in a new issue