2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
|
2014-06-22 04:27:58 +00:00
|
|
|
#include "Core/Reporting.h"
|
2013-12-14 22:54:05 +00:00
|
|
|
#include "Core/HLE/HLE.h"
|
2014-03-15 18:22:19 +00:00
|
|
|
#include "Core/HLE/FunctionWrappers.h"
|
2013-12-14 22:54:05 +00:00
|
|
|
#include "Core/MIPS/MIPS.h"
|
|
|
|
#include "Common/ChunkFile.h"
|
|
|
|
|
|
|
|
#include "Core/Debugger/Breakpoints.h"
|
|
|
|
#include "Core/HLE/sceKernel.h"
|
|
|
|
#include "Core/HLE/sceKernelThread.h"
|
|
|
|
#include "Core/HLE/sceKernelInterrupt.h"
|
|
|
|
#include "Core/HLE/sceKernelMemory.h"
|
|
|
|
#include "Core/HLE/sceKernelMutex.h"
|
2013-09-21 16:52:30 +00:00
|
|
|
#include "GPU/GPUCommon.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-12-24 06:07:17 +00:00
|
|
|
void __DisableInterrupts();
|
|
|
|
void __EnableInterrupts();
|
|
|
|
bool __InterruptsEnabled();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2014-06-22 04:27:58 +00:00
|
|
|
// Seems like some > 16 are taken but not available. Probably kernel only?
|
|
|
|
static const u32 PSP_NUMBER_SUBINTERRUPTS = 32;
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
// InterruptsManager
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// INTERRUPT MANAGEMENT
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2013-02-03 23:41:16 +00:00
|
|
|
|
|
|
|
class InterruptState
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void save();
|
|
|
|
void restore();
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
void DoState(PointerWrap &p)
|
|
|
|
{
|
2013-09-15 03:23:03 +00:00
|
|
|
auto s = p.Section("InterruptState", 1);
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
p.Do(savedCpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadContext savedCpu;
|
|
|
|
};
|
|
|
|
|
|
|
|
// STATE
|
|
|
|
|
|
|
|
InterruptState intState;
|
|
|
|
IntrHandler* intrHandlers[PSP_NUMBER_INTERRUPTS];
|
|
|
|
std::list<PendingInterrupt> pendingInterrupts;
|
|
|
|
|
|
|
|
// Yeah, this bit is a bit silly.
|
|
|
|
static int interruptsEnabled = 1;
|
|
|
|
static bool inInterrupt;
|
2013-04-07 00:03:39 +00:00
|
|
|
static SceUID threadBeforeInterrupt;
|
2013-02-03 23:41:16 +00:00
|
|
|
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static void sceKernelCpuSuspendIntr()
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-09-07 19:19:21 +00:00
|
|
|
VERBOSE_LOG(SCEINTC, "sceKernelCpuSuspendIntr");
|
2012-11-01 15:19:01 +00:00
|
|
|
int returnValue;
|
|
|
|
if (__InterruptsEnabled())
|
|
|
|
{
|
|
|
|
returnValue = 1;
|
|
|
|
__DisableInterrupts();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
returnValue = 0;
|
|
|
|
}
|
2013-05-28 08:30:49 +00:00
|
|
|
hleEatCycles(15);
|
2012-11-01 15:19:01 +00:00
|
|
|
RETURN(returnValue);
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static void sceKernelCpuResumeIntr(u32 enable)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-09-07 19:19:21 +00:00
|
|
|
VERBOSE_LOG(SCEINTC, "sceKernelCpuResumeIntr(%i)", enable);
|
2012-11-01 15:19:01 +00:00
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
__EnableInterrupts();
|
2012-12-21 06:49:48 +00:00
|
|
|
hleRunInterrupts();
|
2013-08-26 05:38:45 +00:00
|
|
|
hleReSchedule("interrupts resumed");
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__DisableInterrupts();
|
|
|
|
}
|
2013-05-28 08:30:49 +00:00
|
|
|
hleEatCycles(15);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static void sceKernelIsCpuIntrEnable()
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
u32 retVal = __InterruptsEnabled();
|
2013-09-07 19:19:21 +00:00
|
|
|
DEBUG_LOG(SCEINTC, "%i=sceKernelIsCpuIntrEnable()", retVal);
|
2012-11-01 15:19:01 +00:00
|
|
|
RETURN(retVal);
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static int sceKernelIsCpuIntrSuspended(int flag)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-11-02 20:54:06 +00:00
|
|
|
int retVal = flag == 0 ? 1 : 0;
|
|
|
|
DEBUG_LOG(SCEINTC, "%i=sceKernelIsCpuIntrSuspended(%d)", retVal, flag);
|
|
|
|
return retVal;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static void sceKernelCpuResumeIntrWithSync(u32 enable)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
sceKernelCpuResumeIntr(enable);
|
|
|
|
}
|
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
bool IntrHandler::run(PendingInterrupt& pend)
|
|
|
|
{
|
|
|
|
SubIntrHandler *handler = get(pend.subintr);
|
|
|
|
if (handler == NULL)
|
2012-12-27 23:56:46 +00:00
|
|
|
{
|
2013-09-07 19:19:21 +00:00
|
|
|
WARN_LOG(SCEINTC, "Ignoring interrupt, already been released.");
|
2013-02-03 23:41:16 +00:00
|
|
|
return false;
|
2012-12-27 23:56:46 +00:00
|
|
|
}
|
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
copyArgsToCPU(pend);
|
2012-12-27 23:56:46 +00:00
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
void IntrHandler::copyArgsToCPU(PendingInterrupt& pend)
|
|
|
|
{
|
|
|
|
SubIntrHandler* handler = get(pend.subintr);
|
|
|
|
DEBUG_LOG(CPU, "Entering interrupt handler %08x", handler->handlerAddress);
|
|
|
|
currentMIPS->pc = handler->handlerAddress;
|
|
|
|
currentMIPS->r[MIPS_REG_A0] = handler->subIntrNumber;
|
|
|
|
currentMIPS->r[MIPS_REG_A1] = handler->handlerArg;
|
|
|
|
// RA is already taken care of
|
|
|
|
}
|
2012-11-06 17:14:09 +00:00
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
void IntrHandler::handleResult(PendingInterrupt& pend)
|
|
|
|
{
|
|
|
|
//u32 result = currentMIPS->r[MIPS_REG_V0];
|
|
|
|
}
|
|
|
|
|
|
|
|
SubIntrHandler* IntrHandler::add(int subIntrNum)
|
|
|
|
{
|
|
|
|
return &subIntrHandlers[subIntrNum];
|
|
|
|
}
|
|
|
|
void IntrHandler::remove(int subIntrNum)
|
|
|
|
{
|
|
|
|
if (has(subIntrNum))
|
2012-11-06 17:14:09 +00:00
|
|
|
{
|
2013-02-03 23:41:16 +00:00
|
|
|
subIntrHandlers.erase(subIntrNum);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
2013-02-03 23:41:16 +00:00
|
|
|
}
|
|
|
|
bool IntrHandler::has(int subIntrNum) const
|
|
|
|
{
|
|
|
|
return subIntrHandlers.find(subIntrNum) != subIntrHandlers.end();
|
|
|
|
}
|
|
|
|
void IntrHandler::enable(int subIntrNum)
|
|
|
|
{
|
|
|
|
subIntrHandlers[subIntrNum].enabled = true;
|
|
|
|
}
|
|
|
|
void IntrHandler::disable(int subIntrNum)
|
|
|
|
{
|
2013-08-27 06:18:37 +00:00
|
|
|
subIntrHandlers[subIntrNum].enabled = false;
|
2013-02-03 23:41:16 +00:00
|
|
|
}
|
|
|
|
SubIntrHandler* IntrHandler::get(int subIntrNum)
|
|
|
|
{
|
|
|
|
if (has(subIntrNum))
|
|
|
|
return &subIntrHandlers[subIntrNum];
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
void IntrHandler::clear()
|
|
|
|
{
|
|
|
|
subIntrHandlers.clear();
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2014-06-22 04:41:54 +00:00
|
|
|
void IntrHandler::queueUp(int subintr) {
|
|
|
|
if (subintr == PSP_INTR_SUB_NONE) {
|
2013-02-03 23:41:16 +00:00
|
|
|
pendingInterrupts.push_back(PendingInterrupt(intrNumber, subintr));
|
2014-06-22 04:41:54 +00:00
|
|
|
} else {
|
2013-02-03 23:41:16 +00:00
|
|
|
// Just call execute on all the subintr handlers for this interrupt.
|
|
|
|
// They will get queued up.
|
2014-06-22 04:41:54 +00:00
|
|
|
for (auto iter = subIntrHandlers.begin(); iter != subIntrHandlers.end(); ++iter) {
|
|
|
|
if ((subintr == PSP_INTR_SUB_ALL || iter->first == subintr) && iter->second.enabled && iter->second.handlerAddress != 0) {
|
2013-02-03 23:41:16 +00:00
|
|
|
pendingInterrupts.push_back(PendingInterrupt(intrNumber, iter->first));
|
2014-06-22 04:41:54 +00:00
|
|
|
}
|
2012-12-27 23:56:46 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-03 23:41:16 +00:00
|
|
|
}
|
2012-12-27 23:56:46 +00:00
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
void IntrHandler::DoState(PointerWrap &p)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-09-15 03:23:03 +00:00
|
|
|
auto s = p.Section("IntrHandler", 1);
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
p.Do(intrNumber);
|
|
|
|
p.Do<int, SubIntrHandler>(subIntrHandlers);
|
2013-02-04 06:10:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PendingInterrupt::DoState(PointerWrap &p)
|
|
|
|
{
|
2013-09-15 03:23:03 +00:00
|
|
|
auto s = p.Section("PendingInterrupt", 1);
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
2013-02-04 06:10:06 +00:00
|
|
|
p.Do(intr);
|
|
|
|
p.Do(subintr);
|
2013-02-03 23:41:16 +00:00
|
|
|
}
|
2012-12-24 06:07:17 +00:00
|
|
|
|
|
|
|
void __InterruptsInit()
|
|
|
|
{
|
|
|
|
interruptsEnabled = 1;
|
|
|
|
inInterrupt = false;
|
2013-02-24 18:38:30 +00:00
|
|
|
for (int i = 0; i < (int)ARRAY_SIZE(intrHandlers); ++i)
|
2013-02-03 23:41:16 +00:00
|
|
|
intrHandlers[i] = new IntrHandler(i);
|
2012-12-24 06:07:17 +00:00
|
|
|
intState.clear();
|
2013-04-07 00:03:39 +00:00
|
|
|
threadBeforeInterrupt = 0;
|
2012-12-24 06:07:17 +00:00
|
|
|
}
|
|
|
|
|
2012-12-27 23:56:46 +00:00
|
|
|
void __InterruptsDoState(PointerWrap &p)
|
|
|
|
{
|
2013-09-15 03:23:03 +00:00
|
|
|
auto s = p.Section("sceKernelInterrupt", 1);
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
2012-12-27 23:56:46 +00:00
|
|
|
int numInterrupts = PSP_NUMBER_INTERRUPTS;
|
|
|
|
p.Do(numInterrupts);
|
|
|
|
if (numInterrupts != PSP_NUMBER_INTERRUPTS)
|
|
|
|
{
|
2013-04-13 08:39:17 +00:00
|
|
|
p.SetError(p.ERROR_FAILURE);
|
2013-09-07 19:19:21 +00:00
|
|
|
ERROR_LOG(SCEINTC, "Savestate failure: wrong number of interrupts, can't load.");
|
2012-12-27 23:56:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
intState.DoState(p);
|
2012-12-28 22:33:00 +00:00
|
|
|
PendingInterrupt pi(0, 0);
|
2013-02-04 16:24:32 +00:00
|
|
|
p.Do(pendingInterrupts, pi);
|
2012-12-27 23:56:46 +00:00
|
|
|
p.Do(interruptsEnabled);
|
|
|
|
p.Do(inInterrupt);
|
2013-04-07 00:03:39 +00:00
|
|
|
p.Do(threadBeforeInterrupt);
|
2012-12-27 23:56:46 +00:00
|
|
|
}
|
|
|
|
|
2012-12-28 03:30:36 +00:00
|
|
|
void __InterruptsDoStateLate(PointerWrap &p)
|
|
|
|
{
|
|
|
|
// We do these later to ensure the handlers have been registered.
|
|
|
|
for (int i = 0; i < PSP_NUMBER_INTERRUPTS; ++i)
|
2013-02-03 23:41:16 +00:00
|
|
|
intrHandlers[i]->DoState(p);
|
2012-12-28 03:30:36 +00:00
|
|
|
p.DoMarker("sceKernelInterrupt Late");
|
|
|
|
}
|
|
|
|
|
2012-12-24 06:07:17 +00:00
|
|
|
void __InterruptsShutdown()
|
|
|
|
{
|
2013-02-18 17:04:43 +00:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(intrHandlers); ++i)
|
2013-02-03 23:41:16 +00:00
|
|
|
intrHandlers[i]->clear();
|
2013-02-18 17:04:43 +00:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(intrHandlers); ++i)
|
2013-02-03 23:41:16 +00:00
|
|
|
{
|
2013-02-18 17:04:43 +00:00
|
|
|
if (intrHandlers[i])
|
2013-02-03 23:41:16 +00:00
|
|
|
{
|
|
|
|
delete intrHandlers[i];
|
|
|
|
intrHandlers[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-12-24 06:07:17 +00:00
|
|
|
pendingInterrupts.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void __DisableInterrupts()
|
|
|
|
{
|
|
|
|
interruptsEnabled = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __EnableInterrupts()
|
|
|
|
{
|
|
|
|
interruptsEnabled = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool __InterruptsEnabled()
|
|
|
|
{
|
|
|
|
return interruptsEnabled != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool __IsInInterrupt()
|
|
|
|
{
|
|
|
|
return inInterrupt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterruptState::save()
|
|
|
|
{
|
2013-04-07 18:28:37 +00:00
|
|
|
__KernelSaveContext(&savedCpu, true);
|
2012-12-24 06:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InterruptState::restore()
|
|
|
|
{
|
2013-04-07 18:28:37 +00:00
|
|
|
__KernelLoadContext(&savedCpu, true);
|
2012-12-24 06:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InterruptState::clear()
|
|
|
|
{
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// http://forums.ps2dev.org/viewtopic.php?t=5687
|
|
|
|
|
|
|
|
// http://www.google.se/url?sa=t&rct=j&q=&esrc=s&source=web&cd=7&ved=0CFYQFjAG&url=http%3A%2F%2Fdev.psnpt.com%2Fredmine%2Fprojects%2Fuofw%2Frepository%2Frevisions%2F65%2Fraw%2Ftrunk%2Finclude%2Finterruptman.h&ei=J4pCUKvyK4nl4QSu-YC4Cg&usg=AFQjCNFxJcgzQnv6dK7aiQlht_BM9grfQQ&sig2=GGk5QUEWI6qouYDoyE07YQ
|
|
|
|
|
|
|
|
|
|
|
|
// Returns true if anything was executed.
|
|
|
|
bool __RunOnePendingInterrupt()
|
|
|
|
{
|
2014-01-22 06:47:18 +00:00
|
|
|
bool needsThreadReturn = false;
|
|
|
|
|
|
|
|
if (inInterrupt || !interruptsEnabled) {
|
2012-11-01 15:19:01 +00:00
|
|
|
// Already in an interrupt! We'll keep going when it's done.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Can easily prioritize between different kinds of interrupts if necessary.
|
2012-12-27 23:56:46 +00:00
|
|
|
retry:
|
2014-01-22 06:47:18 +00:00
|
|
|
if (!pendingInterrupts.empty()) {
|
2012-11-06 17:14:09 +00:00
|
|
|
PendingInterrupt pend = pendingInterrupts.front();
|
2013-02-03 23:41:16 +00:00
|
|
|
|
|
|
|
IntrHandler* handler = intrHandlers[pend.intr];
|
2014-01-22 06:47:18 +00:00
|
|
|
if (handler == NULL) {
|
2013-09-07 19:19:21 +00:00
|
|
|
WARN_LOG(SCEINTC, "Ignoring interrupt");
|
2012-12-27 23:56:46 +00:00
|
|
|
pendingInterrupts.pop_front();
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
2014-01-22 06:47:18 +00:00
|
|
|
// If we came from CoreTiming::Advance(), we might've come from a waiting thread's callback.
|
|
|
|
// To avoid "injecting" return values into our saved state, we context switch here.
|
|
|
|
SceUID savedThread = __KernelGetCurThread();
|
|
|
|
if (__KernelSwitchOffThread("interrupt")) {
|
|
|
|
threadBeforeInterrupt = savedThread;
|
|
|
|
needsThreadReturn = true;
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
intState.save();
|
2013-02-03 23:41:16 +00:00
|
|
|
inInterrupt = true;
|
|
|
|
|
2014-01-22 06:47:18 +00:00
|
|
|
if (!handler->run(pend)) {
|
2013-02-03 23:41:16 +00:00
|
|
|
pendingInterrupts.pop_front();
|
|
|
|
inInterrupt = false;
|
|
|
|
goto retry;
|
|
|
|
}
|
2012-11-06 17:14:09 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
currentMIPS->r[MIPS_REG_RA] = __KernelInterruptReturnAddress();
|
|
|
|
return true;
|
2014-01-22 06:47:18 +00:00
|
|
|
} else {
|
|
|
|
if (needsThreadReturn)
|
|
|
|
__KernelSwitchToThread(threadBeforeInterrupt, "left interrupt");
|
2013-09-07 19:19:21 +00:00
|
|
|
// DEBUG_LOG(SCEINTC, "No more interrupts!");
|
2012-11-01 15:19:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static void __TriggerRunInterrupts(int type)
|
2012-12-21 06:49:48 +00:00
|
|
|
{
|
|
|
|
// If interrupts aren't enabled, we run them later.
|
|
|
|
if (interruptsEnabled && !inInterrupt)
|
|
|
|
{
|
|
|
|
if ((type & PSP_INTR_HLE) != 0)
|
|
|
|
hleRunInterrupts();
|
2013-02-03 21:41:36 +00:00
|
|
|
else if ((type & PSP_INTR_ALWAYS_RESCHED) != 0)
|
|
|
|
{
|
2013-04-07 00:03:39 +00:00
|
|
|
// "Always" only means if dispatch is enabled.
|
|
|
|
if (!__RunOnePendingInterrupt() && __KernelIsDispatchEnabled())
|
|
|
|
{
|
|
|
|
SceUID savedThread = __KernelGetCurThread();
|
|
|
|
if (__KernelSwitchOffThread("interrupt"))
|
|
|
|
threadBeforeInterrupt = savedThread;
|
|
|
|
}
|
2013-02-03 21:41:36 +00:00
|
|
|
}
|
2012-12-21 06:49:48 +00:00
|
|
|
else
|
|
|
|
__RunOnePendingInterrupt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-21 05:54:40 +00:00
|
|
|
void __TriggerInterrupt(int type, PSPInterrupt intno, int subintr)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2012-12-21 05:54:40 +00:00
|
|
|
if (interruptsEnabled || (type & PSP_INTR_ONLY_IF_ENABLED) == 0)
|
|
|
|
{
|
2013-02-03 23:41:16 +00:00
|
|
|
intrHandlers[intno]->queueUp(subintr);
|
2013-09-07 19:19:21 +00:00
|
|
|
VERBOSE_LOG(SCEINTC, "Triggering subinterrupts for interrupt %i sub %i (%i in queue)", intno, subintr, (u32)pendingInterrupts.size());
|
2012-12-21 06:49:48 +00:00
|
|
|
__TriggerRunInterrupts(type);
|
2012-12-21 05:54:40 +00:00
|
|
|
}
|
2012-11-06 17:14:09 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 14:44:48 +00:00
|
|
|
void __KernelReturnFromInterrupt()
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-09-07 19:19:21 +00:00
|
|
|
VERBOSE_LOG(SCEINTC, "Left interrupt handler at %08x", currentMIPS->pc);
|
2012-12-19 16:10:48 +00:00
|
|
|
|
2013-10-30 05:53:25 +00:00
|
|
|
hleSkipDeadbeef();
|
|
|
|
|
2012-12-19 16:10:48 +00:00
|
|
|
// This is what we just ran.
|
|
|
|
PendingInterrupt pend = pendingInterrupts.front();
|
|
|
|
pendingInterrupts.pop_front();
|
2012-12-27 23:56:46 +00:00
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
intrHandlers[pend.intr]->handleResult(pend);
|
|
|
|
inInterrupt = false;
|
2012-12-19 16:10:48 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
// Restore context after running the interrupt.
|
|
|
|
intState.restore();
|
|
|
|
// All should now be back to normal, including PC.
|
|
|
|
|
|
|
|
// Alright, let's see if there's any more interrupts queued...
|
|
|
|
if (!__RunOnePendingInterrupt())
|
2013-04-07 00:03:39 +00:00
|
|
|
{
|
|
|
|
// Otherwise, we reschedule when dispatch was enabled, or switch back otherwise.
|
|
|
|
if (__KernelIsDispatchEnabled())
|
2013-08-25 17:25:49 +00:00
|
|
|
__KernelReSchedule("left interrupt");
|
2013-04-07 00:03:39 +00:00
|
|
|
else
|
2013-08-25 17:25:49 +00:00
|
|
|
__KernelSwitchToThread(threadBeforeInterrupt, "left interrupt");
|
2013-04-07 00:03:39 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
void __RegisterIntrHandler(u32 intrNumber, IntrHandler* handler)
|
2012-12-19 15:38:35 +00:00
|
|
|
{
|
2013-02-03 23:41:16 +00:00
|
|
|
if(intrHandlers[intrNumber])
|
|
|
|
delete intrHandlers[intrNumber];
|
|
|
|
intrHandlers[intrNumber] = handler;
|
2012-12-27 23:56:46 +00:00
|
|
|
}
|
|
|
|
|
2014-06-22 04:27:58 +00:00
|
|
|
SubIntrHandler *__RegisterSubIntrHandler(u32 intrNumber, u32 subIntrNumber, u32 handler, u32 handlerArg, u32 &error) {
|
|
|
|
if (intrNumber >= PSP_NUMBER_INTERRUPTS) {
|
|
|
|
error = SCE_KERNEL_ERROR_ILLEGAL_INTRCODE;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
IntrHandler *intr = intrHandlers[intrNumber];
|
|
|
|
if (intr->has(subIntrNumber)) {
|
2014-06-22 04:41:54 +00:00
|
|
|
if (intr->get(subIntrNumber)->handlerAddress != 0) {
|
|
|
|
error = SCE_KERNEL_ERROR_FOUND_HANDLER;
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
SubIntrHandler *subIntrHandler = intr->get(subIntrNumber);
|
|
|
|
subIntrHandler->handlerAddress = handler;
|
|
|
|
subIntrHandler->handlerArg = handlerArg;
|
|
|
|
|
|
|
|
error = SCE_KERNEL_ERROR_OK;
|
|
|
|
return subIntrHandler;
|
|
|
|
}
|
2014-06-22 04:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SubIntrHandler *subIntrHandler = intr->add(subIntrNumber);
|
2013-02-03 23:41:16 +00:00
|
|
|
subIntrHandler->subIntrNumber = subIntrNumber;
|
2012-12-21 06:49:48 +00:00
|
|
|
subIntrHandler->intrNumber = intrNumber;
|
2014-06-22 04:27:58 +00:00
|
|
|
subIntrHandler->handlerAddress = handler;
|
|
|
|
subIntrHandler->handlerArg = handlerArg;
|
2014-06-22 04:41:54 +00:00
|
|
|
subIntrHandler->enabled = false;
|
|
|
|
|
2014-06-22 04:27:58 +00:00
|
|
|
error = SCE_KERNEL_ERROR_OK;
|
2012-12-27 23:56:46 +00:00
|
|
|
return subIntrHandler;
|
2012-12-19 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
2014-06-22 04:27:58 +00:00
|
|
|
int __ReleaseSubIntrHandler(int intrNumber, int subIntrNumber) {
|
|
|
|
if (intrNumber >= PSP_NUMBER_INTERRUPTS) {
|
|
|
|
return SCE_KERNEL_ERROR_ILLEGAL_INTRCODE;
|
|
|
|
}
|
2014-06-22 04:41:54 +00:00
|
|
|
IntrHandler *intr = intrHandlers[intrNumber];
|
|
|
|
if (!intr->has(subIntrNumber) || intr->get(subIntrNumber)->handlerAddress == 0) {
|
2014-06-22 04:27:58 +00:00
|
|
|
return SCE_KERNEL_ERROR_NOTFOUND_HANDLER;
|
|
|
|
}
|
2012-12-19 15:38:35 +00:00
|
|
|
|
2014-06-22 04:27:58 +00:00
|
|
|
for (auto it = pendingInterrupts.begin(); it != pendingInterrupts.end(); ) {
|
|
|
|
if (it->intr == intrNumber && it->subintr == subIntrNumber) {
|
2012-12-21 06:49:48 +00:00
|
|
|
pendingInterrupts.erase(it++);
|
2014-06-22 04:27:58 +00:00
|
|
|
} else {
|
2012-12-21 06:49:48 +00:00
|
|
|
++it;
|
2014-06-22 04:27:58 +00:00
|
|
|
}
|
2012-12-21 06:49:48 +00:00
|
|
|
}
|
2012-12-19 15:38:35 +00:00
|
|
|
|
2014-06-22 04:41:54 +00:00
|
|
|
// This also implicitly disables it, which is correct.
|
2013-02-03 23:41:16 +00:00
|
|
|
intrHandlers[intrNumber]->remove(subIntrNumber);
|
2012-12-19 15:38:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-22 04:27:58 +00:00
|
|
|
u32 sceKernelRegisterSubIntrHandler(u32 intrNumber, u32 subIntrNumber, u32 handler, u32 handlerArg) {
|
|
|
|
if (intrNumber >= PSP_NUMBER_INTERRUPTS) {
|
|
|
|
ERROR_LOG_REPORT(SCEINTC, "sceKernelRegisterSubIntrHandler(%i, %i, %08x, %08x): invalid interrupt", intrNumber, subIntrNumber, handler, handlerArg);
|
|
|
|
return SCE_KERNEL_ERROR_ILLEGAL_INTRCODE;
|
|
|
|
}
|
|
|
|
if (subIntrNumber >= PSP_NUMBER_SUBINTERRUPTS) {
|
|
|
|
ERROR_LOG_REPORT(SCEINTC, "sceKernelRegisterSubIntrHandler(%i, %i, %08x, %08x): invalid subinterrupt", intrNumber, subIntrNumber, handler, handlerArg);
|
|
|
|
return SCE_KERNEL_ERROR_ILLEGAL_INTRCODE;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-12-27 23:56:46 +00:00
|
|
|
u32 error;
|
2014-06-22 04:27:58 +00:00
|
|
|
SubIntrHandler *subIntrHandler = __RegisterSubIntrHandler(intrNumber, subIntrNumber, handler, handlerArg, error);
|
|
|
|
if (subIntrHandler) {
|
2014-06-22 04:41:54 +00:00
|
|
|
if (handler == 0) {
|
|
|
|
WARN_LOG_REPORT(SCEINTC, "sceKernelRegisterSubIntrHandler(%i, %i, %08x, %08x): ignored NULL handler", intrNumber, subIntrNumber, handler, handlerArg);
|
|
|
|
} else {
|
|
|
|
DEBUG_LOG(SCEINTC, "sceKernelRegisterSubIntrHandler(%i, %i, %08x, %08x)", intrNumber, subIntrNumber, handler, handlerArg);
|
|
|
|
}
|
2014-07-16 06:33:01 +00:00
|
|
|
} else if (error == SCE_KERNEL_ERROR_FOUND_HANDLER) {
|
2014-06-22 04:27:58 +00:00
|
|
|
ERROR_LOG_REPORT(SCEINTC, "sceKernelRegisterSubIntrHandler(%i, %i, %08x, %08x): duplicate handler", intrNumber, subIntrNumber, handler, handlerArg);
|
|
|
|
} else {
|
|
|
|
ERROR_LOG_REPORT(SCEINTC, "sceKernelRegisterSubIntrHandler(%i, %i, %08x, %08x): error %08x", intrNumber, subIntrNumber, handler, handlerArg, error);
|
2012-12-27 23:56:46 +00:00
|
|
|
}
|
|
|
|
return error;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-06-22 04:27:58 +00:00
|
|
|
u32 sceKernelReleaseSubIntrHandler(u32 intrNumber, u32 subIntrNumber) {
|
|
|
|
if (intrNumber >= PSP_NUMBER_INTERRUPTS) {
|
|
|
|
ERROR_LOG_REPORT(SCEINTC, "sceKernelReleaseSubIntrHandler(%i, %i): invalid interrupt", intrNumber, subIntrNumber);
|
|
|
|
return SCE_KERNEL_ERROR_ILLEGAL_INTRCODE;
|
|
|
|
}
|
|
|
|
if (subIntrNumber >= PSP_NUMBER_SUBINTERRUPTS) {
|
|
|
|
ERROR_LOG_REPORT(SCEINTC, "sceKernelReleaseSubIntrHandler(%i, %i): invalid subinterrupt", intrNumber, subIntrNumber);
|
|
|
|
return SCE_KERNEL_ERROR_ILLEGAL_INTRCODE;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2014-06-22 04:27:58 +00:00
|
|
|
u32 error = __ReleaseSubIntrHandler(intrNumber, subIntrNumber);
|
|
|
|
if (error != SCE_KERNEL_ERROR_OK) {
|
2014-07-16 06:33:01 +00:00
|
|
|
ERROR_LOG(SCEINTC, "sceKernelReleaseSubIntrHandler(%i, %i): error %08x", intrNumber, subIntrNumber, error);
|
2014-06-22 04:27:58 +00:00
|
|
|
}
|
|
|
|
return error;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-06-22 04:41:54 +00:00
|
|
|
u32 sceKernelEnableSubIntr(u32 intrNumber, u32 subIntrNumber) {
|
|
|
|
if (intrNumber >= PSP_NUMBER_INTERRUPTS) {
|
|
|
|
ERROR_LOG_REPORT(SCEINTC, "sceKernelEnableSubIntr(%i, %i): invalid interrupt", intrNumber, subIntrNumber);
|
|
|
|
return SCE_KERNEL_ERROR_ILLEGAL_INTRCODE;
|
|
|
|
}
|
|
|
|
if (subIntrNumber >= PSP_NUMBER_SUBINTERRUPTS) {
|
|
|
|
ERROR_LOG_REPORT(SCEINTC, "sceKernelEnableSubIntr(%i, %i): invalid subinterrupt", intrNumber, subIntrNumber);
|
|
|
|
return SCE_KERNEL_ERROR_ILLEGAL_INTRCODE;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2014-06-22 04:41:54 +00:00
|
|
|
DEBUG_LOG(SCEINTC, "sceKernelEnableSubIntr(%i, %i)", intrNumber, subIntrNumber);
|
|
|
|
u32 error;
|
|
|
|
if (!intrHandlers[intrNumber]->has(subIntrNumber)) {
|
|
|
|
// Enableing a handler before registering it works fine.
|
|
|
|
__RegisterSubIntrHandler(intrNumber, subIntrNumber, 0, 0, error);
|
|
|
|
}
|
2012-11-04 12:27:11 +00:00
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
intrHandlers[intrNumber]->enable(subIntrNumber);
|
2012-11-01 15:19:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceKernelDisableSubIntr(u32 intrNumber, u32 subIntrNumber) {
|
2014-06-22 04:41:54 +00:00
|
|
|
if (intrNumber >= PSP_NUMBER_INTERRUPTS) {
|
|
|
|
ERROR_LOG_REPORT(SCEINTC, "sceKernelDisableSubIntr(%i, %i): invalid interrupt", intrNumber, subIntrNumber);
|
|
|
|
return SCE_KERNEL_ERROR_ILLEGAL_INTRCODE;
|
|
|
|
}
|
|
|
|
if (subIntrNumber >= PSP_NUMBER_SUBINTERRUPTS) {
|
|
|
|
ERROR_LOG_REPORT(SCEINTC, "sceKernelDisableSubIntr(%i, %i): invalid subinterrupt", intrNumber, subIntrNumber);
|
|
|
|
return SCE_KERNEL_ERROR_ILLEGAL_INTRCODE;
|
|
|
|
}
|
|
|
|
|
2013-09-07 19:19:21 +00:00
|
|
|
DEBUG_LOG(SCEINTC, "sceKernelDisableSubIntr(%i, %i)", intrNumber, subIntrNumber);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2014-06-22 04:41:54 +00:00
|
|
|
if (!intrHandlers[intrNumber]->has(subIntrNumber)) {
|
|
|
|
// Disabling when not registered is not an error.
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
intrHandlers[intrNumber]->disable(subIntrNumber);
|
2012-11-01 15:19:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct PspIntrHandlerOptionParam {
|
2014-03-03 16:16:53 +00:00
|
|
|
int size; //+00
|
|
|
|
u32 entry; //+04
|
|
|
|
u32 common; //+08
|
|
|
|
u32 gp; //+0C
|
|
|
|
u16 intr_code; //+10
|
|
|
|
u16 sub_count; //+12
|
|
|
|
u16 intr_level; //+14
|
|
|
|
u16 enabled; //+16
|
|
|
|
u32 calls; //+18
|
|
|
|
u32 field_1C; //+1C
|
|
|
|
u32 total_clock_lo; //+20
|
|
|
|
u32 total_clock_hi; //+24
|
|
|
|
u32 min_clock_lo; //+28
|
|
|
|
u32 min_clock_hi; //+2C
|
|
|
|
u32 max_clock_lo; //+30
|
|
|
|
u32 max_clock_hi; //+34
|
|
|
|
}; //=38
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static void QueryIntrHandlerInfo()
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2014-06-22 04:27:58 +00:00
|
|
|
ERROR_LOG_REPORT(SCEINTC, "QueryIntrHandlerInfo()");
|
2012-11-01 15:19:01 +00:00
|
|
|
RETURN(0);
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceKernelMemset(u32 addr, u32 fillc, u32 n)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2012-12-23 08:44:43 +00:00
|
|
|
u8 c = fillc & 0xff;
|
2013-09-07 19:19:21 +00:00
|
|
|
DEBUG_LOG(SCEINTC, "sceKernelMemset(ptr = %08x, c = %02x, n = %08x)", addr, c, n);
|
2014-05-27 08:14:29 +00:00
|
|
|
bool skip = false;
|
2014-11-07 22:49:24 +00:00
|
|
|
if (n != 0) {
|
|
|
|
if (Memory::IsVRAMAddress(addr)) {
|
|
|
|
skip = gpu->PerformMemorySet(addr, fillc, n);
|
|
|
|
}
|
|
|
|
if (!skip) {
|
|
|
|
Memory::Memset(addr, c, n);
|
|
|
|
}
|
2014-05-26 21:18:06 +00:00
|
|
|
}
|
2013-01-02 08:35:31 +00:00
|
|
|
return addr;
|
2012-11-23 18:51:36 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceKernelMemcpy(u32 dst, u32 src, u32 size)
|
2012-11-23 18:51:36 +00:00
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCEKERNEL, "sceKernelMemcpy(dest=%08x, src=%08x, size=%i)", dst, src, size);
|
2014-05-26 03:05:28 +00:00
|
|
|
|
2014-07-05 20:23:33 +00:00
|
|
|
// Some games copy from executable code. We need to flush emuhack ops.
|
|
|
|
currentMIPS->InvalidateICache(src, size);
|
|
|
|
|
2014-05-26 03:05:28 +00:00
|
|
|
bool skip = false;
|
|
|
|
if (Memory::IsVRAMAddress(src) || Memory::IsVRAMAddress(dst)) {
|
2014-05-27 08:14:29 +00:00
|
|
|
skip = gpu->PerformMemoryCopy(dst, src, size);
|
2014-05-26 03:05:28 +00:00
|
|
|
}
|
2013-09-21 16:52:30 +00:00
|
|
|
|
2013-01-02 08:35:31 +00:00
|
|
|
// Technically should crash if these are invalid and size > 0...
|
2014-05-26 03:05:28 +00:00
|
|
|
if (!skip && Memory::IsValidAddress(dst) && Memory::IsValidAddress(src) && Memory::IsValidAddress(dst + size - 1) && Memory::IsValidAddress(src + size - 1))
|
2012-11-23 18:51:36 +00:00
|
|
|
{
|
2014-10-19 21:20:51 +00:00
|
|
|
u8 *dstp = Memory::GetPointerUnchecked(dst);
|
|
|
|
u8 *srcp = Memory::GetPointerUnchecked(src);
|
2013-01-02 08:35:31 +00:00
|
|
|
|
2013-06-03 06:39:36 +00:00
|
|
|
// If it's non-overlapping, just do it in one go.
|
|
|
|
if (dst + size < src || src + size < dst)
|
|
|
|
memcpy(dstp, srcp, size);
|
|
|
|
else
|
2013-01-02 08:35:31 +00:00
|
|
|
{
|
2013-06-03 06:39:36 +00:00
|
|
|
// Try to handle overlapped copies with similar properties to hardware, just in case.
|
|
|
|
// Not that anyone ought to rely on it.
|
|
|
|
for (u32 size64 = size / 8; size64 > 0; --size64)
|
2013-06-03 07:23:56 +00:00
|
|
|
{
|
2013-06-03 06:39:36 +00:00
|
|
|
memmove(dstp, srcp, 8);
|
2013-06-03 07:23:56 +00:00
|
|
|
dstp += 8;
|
|
|
|
srcp += 8;
|
|
|
|
}
|
2013-06-03 06:39:36 +00:00
|
|
|
for (u32 size8 = size % 8; size8 > 0; --size8)
|
|
|
|
*dstp++ = *srcp++;
|
2013-01-02 08:35:31 +00:00
|
|
|
}
|
2012-11-23 18:51:36 +00:00
|
|
|
}
|
2014-02-08 18:29:22 +00:00
|
|
|
#ifndef MOBILE_DEVICE
|
2013-12-14 22:54:05 +00:00
|
|
|
CBreakPoints::ExecMemCheck(src, false, size, currentMIPS->pc);
|
|
|
|
CBreakPoints::ExecMemCheck(dst, true, size, currentMIPS->pc);
|
|
|
|
#endif
|
2013-01-02 08:35:31 +00:00
|
|
|
return dst;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 08:44:43 +00:00
|
|
|
const HLEFunction Kernel_Library[] =
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-04-08 03:57:53 +00:00
|
|
|
{0x092968F4,sceKernelCpuSuspendIntr, "sceKernelCpuSuspendIntr"},
|
2012-11-01 15:19:01 +00:00
|
|
|
{0x5F10D406,WrapV_U<sceKernelCpuResumeIntr>, "sceKernelCpuResumeIntr"}, //int oldstat
|
|
|
|
{0x3b84732d,WrapV_U<sceKernelCpuResumeIntrWithSync>, "sceKernelCpuResumeIntrWithSync"},
|
2013-11-02 20:54:06 +00:00
|
|
|
{0x47a0b729,WrapI_I<sceKernelIsCpuIntrSuspended>, "sceKernelIsCpuIntrSuspended"}, //flags
|
2012-12-23 08:44:43 +00:00
|
|
|
{0xb55249d2,sceKernelIsCpuIntrEnable, "sceKernelIsCpuIntrEnable"},
|
|
|
|
{0xa089eca4,WrapU_UUU<sceKernelMemset>, "sceKernelMemset"},
|
|
|
|
{0xDC692EE3,WrapI_UI<sceKernelTryLockLwMutex>, "sceKernelTryLockLwMutex"},
|
|
|
|
{0x37431849,WrapI_UI<sceKernelTryLockLwMutex_600>, "sceKernelTryLockLwMutex_600"},
|
2013-08-29 06:15:13 +00:00
|
|
|
{0xbea46419,WrapI_UIU<sceKernelLockLwMutex>, "sceKernelLockLwMutex", HLE_NOT_IN_INTERRUPT | HLE_NOT_DISPATCH_SUSPENDED},
|
|
|
|
{0x1FC64E09,WrapI_UIU<sceKernelLockLwMutexCB>, "sceKernelLockLwMutexCB", HLE_NOT_IN_INTERRUPT | HLE_NOT_DISPATCH_SUSPENDED},
|
2012-12-23 08:44:43 +00:00
|
|
|
{0x15b6446b,WrapI_UI<sceKernelUnlockLwMutex>, "sceKernelUnlockLwMutex"},
|
2013-02-25 06:50:48 +00:00
|
|
|
{0xc1734599,WrapI_UU<sceKernelReferLwMutexStatus>, "sceKernelReferLwMutexStatus"},
|
2013-04-10 06:16:23 +00:00
|
|
|
{0x293b45b8,WrapI_V<sceKernelGetThreadId>, "sceKernelGetThreadId"},
|
2013-03-23 13:41:13 +00:00
|
|
|
{0xD13BDE95,WrapI_V<sceKernelCheckThreadStack>, "sceKernelCheckThreadStack"},
|
2013-05-20 02:21:59 +00:00
|
|
|
{0x1839852A,WrapU_UUU<sceKernelMemcpy>, "sceKernelMemcpy"},
|
2013-12-03 07:29:52 +00:00
|
|
|
{0xfa835cde,WrapI_I<sceKernelGetTlsAddr>, "sceKernelGetTlsAddr"},
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sysclib_memcpy(u32 dst, u32 src, u32 size) {
|
2014-02-17 12:42:35 +00:00
|
|
|
ERROR_LOG(SCEKERNEL, "Untested sysclib_memcpy(dest=%08x, src=%08x, size=%i)", dst, src, size);
|
2014-01-17 06:35:17 +00:00
|
|
|
memcpy(Memory::GetPointer(dst), Memory::GetPointer(src), size);
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sysclib_strcat(u32 dst, u32 src) {
|
2014-02-17 12:42:35 +00:00
|
|
|
ERROR_LOG(SCEKERNEL, "Untested sysclib_strcat(dest=%08x, src=%08x)", dst, src);
|
2014-01-17 06:35:17 +00:00
|
|
|
strcat((char *)Memory::GetPointer(dst), (char *)Memory::GetPointer(src));
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static int sysclib_strcmp(u32 dst, u32 src) {
|
2014-02-17 12:42:35 +00:00
|
|
|
ERROR_LOG(SCEKERNEL, "Untested sysclib_strcmp(dest=%08x, src=%08x)", dst, src);
|
2014-01-17 06:35:17 +00:00
|
|
|
return strcmp((char *)Memory::GetPointer(dst), (char *)Memory::GetPointer(src));
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sysclib_strcpy(u32 dst, u32 src) {
|
2014-02-17 12:42:35 +00:00
|
|
|
ERROR_LOG(SCEKERNEL, "Untested sysclib_strcpy(dest=%08x, src=%08x)", dst, src);
|
2014-01-17 06:35:17 +00:00
|
|
|
strcpy((char *)Memory::GetPointer(dst), (char *)Memory::GetPointer(src));
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sysclib_strlen(u32 src) {
|
2014-02-25 12:39:01 +00:00
|
|
|
ERROR_LOG(SCEKERNEL, "Untested sysclib_strlen(src=%08x)", src);
|
2014-01-17 06:35:17 +00:00
|
|
|
return (u32)strlen(Memory::GetCharPointer(src));
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static int sysclib_memcmp(u32 dst, u32 src, u32 size) {
|
2014-02-17 12:42:35 +00:00
|
|
|
ERROR_LOG(SCEKERNEL, "Untested sysclib_memcmp(dest=%08x, src=%08x, size=%i)", dst, src, size);
|
2014-01-17 06:35:17 +00:00
|
|
|
return memcmp(Memory::GetCharPointer(dst), Memory::GetCharPointer(src), size);
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static int sysclib_sprintf(u32 dst, u32 fmt) {
|
2014-02-17 12:42:35 +00:00
|
|
|
ERROR_LOG(SCEKERNEL, "Unimpl sysclib_sprintf(dest=%08x, src=%08x)", dst, fmt);
|
2014-01-17 06:35:17 +00:00
|
|
|
// TODO
|
|
|
|
return sprintf((char *)Memory::GetPointer(dst), "%s", Memory::GetCharPointer(fmt));
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sysclib_memset(u32 destAddr, int data, int size) {
|
2014-05-17 15:06:01 +00:00
|
|
|
ERROR_LOG(SCEKERNEL, "Untested sysclib_memset(dest=%08x, data=%d ,size=%d)", destAddr, data, size);
|
2014-05-17 20:23:10 +00:00
|
|
|
if (Memory::IsValidAddress(destAddr))
|
2014-05-17 15:06:01 +00:00
|
|
|
memset(Memory::GetPointer(destAddr), data, size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-17 06:35:17 +00:00
|
|
|
const HLEFunction SysclibForKernel[] =
|
|
|
|
{
|
|
|
|
{0xAB7592FF, WrapU_UUU<sysclib_memcpy>, "memcpy"},
|
|
|
|
{0x476FD94A, WrapU_UU<sysclib_strcat>, "strcat"},
|
|
|
|
{0xC0AB8932, WrapI_UU<sysclib_strcmp>, "strcmp"},
|
|
|
|
{0xEC6F1CF2, WrapU_UU<sysclib_strcpy>, "strcpy"},
|
|
|
|
{0x52DF196C, WrapU_U<sysclib_strlen>, "strlen"},
|
|
|
|
{0x81D0D1F7, WrapI_UUU<sysclib_memcmp>, "memcmp"},
|
|
|
|
{0x7661e728, WrapI_UU<sysclib_sprintf>, "sprintf"},
|
2014-05-17 20:20:48 +00:00
|
|
|
{0x10F3BB61, WrapU_UII<sysclib_memset>, "memset" },
|
2014-01-17 06:35:17 +00:00
|
|
|
};
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
void Register_Kernel_Library()
|
|
|
|
{
|
|
|
|
RegisterModule("Kernel_Library", ARRAY_SIZE(Kernel_Library), Kernel_Library);
|
2014-02-17 12:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Register_SysclibForKernel()
|
|
|
|
{
|
2014-01-17 06:35:17 +00:00
|
|
|
RegisterModule("SysclibForKernel", ARRAY_SIZE(SysclibForKernel), SysclibForKernel);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 08:44:43 +00:00
|
|
|
const HLEFunction InterruptManager[] =
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
{0xCA04A2B9, WrapU_UUUU<sceKernelRegisterSubIntrHandler>, "sceKernelRegisterSubIntrHandler"},
|
2014-06-22 04:27:58 +00:00
|
|
|
{0xD61E6961, WrapU_UU<sceKernelReleaseSubIntrHandler>, "sceKernelReleaseSubIntrHandler"},
|
2012-11-01 15:19:01 +00:00
|
|
|
{0xFB8E22EC, WrapU_UU<sceKernelEnableSubIntr>, "sceKernelEnableSubIntr"},
|
|
|
|
{0x8A389411, WrapU_UU<sceKernelDisableSubIntr>, "sceKernelDisableSubIntr"},
|
|
|
|
{0x5CB5A78B, 0, "sceKernelSuspendSubIntr"},
|
|
|
|
{0x7860E0DC, 0, "sceKernelResumeSubIntr"},
|
|
|
|
{0xFC4374B8, 0, "sceKernelIsSubInterruptOccurred"},
|
2012-12-23 08:44:43 +00:00
|
|
|
{0xD2E8363F, QueryIntrHandlerInfo, "QueryIntrHandlerInfo"}, // No sce prefix for some reason
|
2012-11-01 15:19:01 +00:00
|
|
|
{0xEEE43F47, 0, "sceKernelRegisterUserSpaceIntrStack"},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void Register_InterruptManager()
|
|
|
|
{
|
|
|
|
RegisterModule("InterruptManager", ARRAY_SIZE(InterruptManager), InterruptManager);
|
|
|
|
}
|