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/.
|
|
|
|
|
2013-01-10 22:42:46 +00:00
|
|
|
#include "base/timeutil.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "HLE.h"
|
|
|
|
#include <map>
|
2012-12-28 22:33:00 +00:00
|
|
|
#include <vector>
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "../MemMap.h"
|
2013-01-31 05:58:51 +00:00
|
|
|
#include "../Config.h"
|
2013-03-09 19:37:57 +00:00
|
|
|
#include "Core/CoreTiming.h"
|
2013-03-02 07:14:00 +00:00
|
|
|
#include "Core/Reporting.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
#include "HLETables.h"
|
|
|
|
#include "../System.h"
|
|
|
|
#include "sceDisplay.h"
|
|
|
|
#include "sceIo.h"
|
|
|
|
#include "sceAudio.h"
|
|
|
|
#include "sceKernelMemory.h"
|
2012-12-09 06:39:36 +00:00
|
|
|
#include "sceKernelThread.h"
|
2012-12-21 05:54:40 +00:00
|
|
|
#include "sceKernelInterrupt.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "../MIPS/MIPSCodeUtils.h"
|
2012-12-25 05:47:54 +00:00
|
|
|
#include "../Host.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-12-09 06:39:36 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
// Do nothing after the syscall.
|
|
|
|
HLE_AFTER_NOTHING = 0x00,
|
|
|
|
// Reschedule immediately after the syscall.
|
|
|
|
HLE_AFTER_RESCHED = 0x01,
|
|
|
|
// Call current thread's callbacks after the syscall.
|
|
|
|
HLE_AFTER_CURRENT_CALLBACKS = 0x02,
|
|
|
|
// Check all threads' callbacks after the syscall.
|
|
|
|
HLE_AFTER_ALL_CALLBACKS = 0x04,
|
|
|
|
// Reschedule and process current thread's callbacks after the syscall.
|
|
|
|
HLE_AFTER_RESCHED_CALLBACKS = 0x08,
|
2012-12-21 05:54:40 +00:00
|
|
|
// Run interrupts (and probably reschedule) after the syscall.
|
|
|
|
HLE_AFTER_RUN_INTERRUPTS = 0x10,
|
2012-12-25 05:47:54 +00:00
|
|
|
// Switch to CORE_STEPPING after the syscall (for debugging.)
|
|
|
|
HLE_AFTER_DEBUG_BREAK = 0x20,
|
2012-12-09 06:39:36 +00:00
|
|
|
};
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-12-09 09:16:19 +00:00
|
|
|
static std::vector<HLEModule> moduleDB;
|
|
|
|
static std::vector<Syscall> unresolvedSyscalls;
|
2013-01-02 02:08:42 +00:00
|
|
|
static std::vector<Syscall> exportedCalls;
|
2013-03-09 19:37:57 +00:00
|
|
|
static int delayedResultEvent = -1;
|
2012-12-09 09:16:19 +00:00
|
|
|
static int hleAfterSyscall = HLE_AFTER_NOTHING;
|
2013-01-26 18:59:17 +00:00
|
|
|
static const char *hleAfterSyscallReschedReason;
|
2012-12-09 09:16:19 +00:00
|
|
|
|
2013-03-09 19:37:57 +00:00
|
|
|
void hleDelayResultFinish(u64 userdata, int cycleslate)
|
|
|
|
{
|
|
|
|
u32 error;
|
|
|
|
SceUID threadID = (SceUID) userdata;
|
|
|
|
SceUID verify = __KernelGetWaitID(threadID, WAITTYPE_DELAY, error);
|
2013-03-10 17:59:59 +00:00
|
|
|
u64 result = (userdata ^ threadID) | __KernelGetWaitValue(threadID, error);
|
2013-03-09 19:37:57 +00:00
|
|
|
|
|
|
|
if (error == 0 && verify == 1)
|
|
|
|
__KernelResumeThreadFromWait(threadID, result);
|
|
|
|
else
|
|
|
|
WARN_LOG(HLE, "Someone else woke up HLE-blocked thread?");
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
void HLEInit()
|
|
|
|
{
|
|
|
|
RegisterAllModules();
|
2013-03-09 19:37:57 +00:00
|
|
|
delayedResultEvent = CoreTiming::RegisterEvent("HLEDelayedResult", hleDelayResultFinish);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-28 06:14:31 +00:00
|
|
|
void HLEDoState(PointerWrap &p)
|
|
|
|
{
|
2013-02-24 18:23:31 +00:00
|
|
|
Syscall sc = {""};
|
2012-12-28 22:33:00 +00:00
|
|
|
p.Do(unresolvedSyscalls, sc);
|
2013-01-02 02:08:42 +00:00
|
|
|
p.Do(exportedCalls, sc);
|
2013-03-09 19:37:57 +00:00
|
|
|
p.Do(delayedResultEvent);
|
|
|
|
CoreTiming::RestoreRegisterEvent(delayedResultEvent, "HLEDelayedResult", hleDelayResultFinish);
|
2012-12-28 06:14:31 +00:00
|
|
|
p.DoMarker("HLE");
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
void HLEShutdown()
|
|
|
|
{
|
2012-12-25 05:04:28 +00:00
|
|
|
hleAfterSyscall = HLE_AFTER_NOTHING;
|
2012-11-01 15:19:01 +00:00
|
|
|
moduleDB.clear();
|
2012-12-25 05:04:28 +00:00
|
|
|
unresolvedSyscalls.clear();
|
2013-01-02 02:08:42 +00:00
|
|
|
exportedCalls.clear();
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterModule(const char *name, int numFunctions, const HLEFunction *funcTable)
|
|
|
|
{
|
|
|
|
HLEModule module = {name, numFunctions, funcTable};
|
|
|
|
moduleDB.push_back(module);
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetModuleIndex(const char *moduleName)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < moduleDB.size(); i++)
|
|
|
|
if (strcmp(moduleName, moduleDB[i].name) == 0)
|
|
|
|
return (int)i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetFuncIndex(int moduleIndex, u32 nib)
|
|
|
|
{
|
|
|
|
const HLEModule &module = moduleDB[moduleIndex];
|
|
|
|
for (int i = 0; i < module.numFunctions; i++)
|
|
|
|
{
|
|
|
|
if (module.funcTable[i].ID == nib)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 GetNibByName(const char *moduleName, const char *function)
|
|
|
|
{
|
|
|
|
int moduleIndex = GetModuleIndex(moduleName);
|
|
|
|
const HLEModule &module = moduleDB[moduleIndex];
|
|
|
|
for (int i = 0; i < module.numFunctions; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(module.funcTable[i].name, function))
|
|
|
|
return module.funcTable[i].ID;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const HLEFunction *GetFunc(const char *moduleName, u32 nib)
|
|
|
|
{
|
|
|
|
int moduleIndex = GetModuleIndex(moduleName);
|
|
|
|
if (moduleIndex != -1)
|
|
|
|
{
|
|
|
|
int idx = GetFuncIndex(moduleIndex, nib);
|
|
|
|
if (idx != -1)
|
|
|
|
return &(moduleDB[moduleIndex].funcTable[idx]);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *GetFuncName(const char *moduleName, u32 nib)
|
|
|
|
{
|
2013-01-02 02:08:42 +00:00
|
|
|
_dbg_assert_msg_(HLE, moduleName != NULL, "Invalid module name.");
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
const HLEFunction *func = GetFunc(moduleName,nib);
|
|
|
|
if (func)
|
|
|
|
return func->name;
|
2013-01-02 02:08:42 +00:00
|
|
|
|
|
|
|
// Was this function exported previously?
|
|
|
|
static char temp[256];
|
|
|
|
for (auto it = exportedCalls.begin(), end = exportedCalls.end(); it != end; ++it)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-01-02 02:08:42 +00:00
|
|
|
if (!strcmp(it->moduleName, moduleName) && it->nid == nib)
|
|
|
|
{
|
|
|
|
sprintf(temp, "[EXP: 0x%08x]", nib);
|
|
|
|
return temp;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
2013-01-02 02:08:42 +00:00
|
|
|
|
|
|
|
// No good, we can't find it.
|
|
|
|
sprintf(temp,"[UNK: 0x%08x]", nib);
|
|
|
|
return temp;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 GetSyscallOp(const char *moduleName, u32 nib)
|
|
|
|
{
|
|
|
|
int modindex = GetModuleIndex(moduleName);
|
|
|
|
if (modindex != -1)
|
|
|
|
{
|
|
|
|
int funcindex = GetFuncIndex(modindex, nib);
|
|
|
|
if (funcindex != -1)
|
|
|
|
{
|
|
|
|
return (0x0000000c | (modindex<<18) | (funcindex<<6));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-27 10:37:45 +00:00
|
|
|
INFO_LOG(HLE, "Syscall (%s, %08x) unknown", moduleName, nib);
|
2013-03-02 07:14:00 +00:00
|
|
|
Reporting::ReportMessage("Unknown syscall in known module: %s 0x%08x", moduleName, nib);
|
2012-11-01 15:19:01 +00:00
|
|
|
return (0x0003FFCC | (modindex<<18)); // invalid syscall
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERROR_LOG(HLE, "Unknown module %s!", moduleName);
|
2013-01-27 10:37:45 +00:00
|
|
|
return (0x03FFFFCC); // invalid syscall
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WriteSyscall(const char *moduleName, u32 nib, u32 address)
|
|
|
|
{
|
|
|
|
if (nib == 0)
|
|
|
|
{
|
|
|
|
Memory::Write_U32(MIPS_MAKE_JR_RA(), address); //patched out?
|
|
|
|
Memory::Write_U32(MIPS_MAKE_NOP(), address+4); //patched out?
|
|
|
|
return;
|
|
|
|
}
|
2012-11-04 18:01:20 +00:00
|
|
|
int modindex = GetModuleIndex(moduleName);
|
|
|
|
if (modindex != -1)
|
|
|
|
{
|
|
|
|
Memory::Write_U32(MIPS_MAKE_JR_RA(), address); // jr ra
|
|
|
|
Memory::Write_U32(GetSyscallOp(moduleName, nib), address + 4);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-02 02:08:42 +00:00
|
|
|
// Did another module export this already?
|
|
|
|
for (auto it = exportedCalls.begin(), end = exportedCalls.end(); it != end; ++it)
|
|
|
|
{
|
|
|
|
if (!strcmp(it->moduleName, moduleName) && it->nid == nib)
|
|
|
|
{
|
|
|
|
Memory::Write_U32(MIPS_MAKE_J(it->symAddr), address); // j symAddr
|
|
|
|
Memory::Write_U32(MIPS_MAKE_NOP(), address + 4); // nop (delay slot)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-04 18:01:20 +00:00
|
|
|
// Module inexistent.. for now; let's store the syscall for it to be resolved later
|
|
|
|
INFO_LOG(HLE,"Syscall (%s,%08x) unresolved, storing for later resolving", moduleName, nib);
|
|
|
|
Syscall sysc = {"", address, nib};
|
2013-01-02 02:08:42 +00:00
|
|
|
strncpy(sysc.moduleName, moduleName, KERNELOBJECT_MAX_NAME_LENGTH);
|
|
|
|
sysc.moduleName[KERNELOBJECT_MAX_NAME_LENGTH] = '\0';
|
2012-11-04 18:01:20 +00:00
|
|
|
unresolvedSyscalls.push_back(sysc);
|
2013-01-08 08:35:55 +00:00
|
|
|
|
|
|
|
// Write a trap so we notice this func if it's called before resolving.
|
|
|
|
Memory::Write_U32(MIPS_MAKE_JR_RA(), address); // jr ra
|
|
|
|
Memory::Write_U32(GetSyscallOp("(invalid syscall)", nib), address + 4);
|
2012-11-04 18:01:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResolveSyscall(const char *moduleName, u32 nib, u32 address)
|
|
|
|
{
|
2013-01-02 02:08:42 +00:00
|
|
|
_dbg_assert_msg_(HLE, moduleName != NULL, "Invalid module name.");
|
|
|
|
|
2012-11-04 18:01:20 +00:00
|
|
|
for (size_t i = 0; i < unresolvedSyscalls.size(); i++)
|
|
|
|
{
|
|
|
|
Syscall *sysc = &unresolvedSyscalls[i];
|
|
|
|
if (strncmp(sysc->moduleName, moduleName, 32) == 0 && sysc->nid == nib)
|
|
|
|
{
|
|
|
|
INFO_LOG(HLE,"Resolving %s/%08x",moduleName,nib);
|
|
|
|
// Note: doing that, we can't trace external module calls, so maybe something else should be done to debug more efficiently
|
2012-12-17 20:27:50 +00:00
|
|
|
// Note that this should be J not JAL, as otherwise control will return to the stub..
|
|
|
|
Memory::Write_U32(MIPS_MAKE_J(address), sysc->symAddr);
|
2012-11-04 18:01:20 +00:00
|
|
|
Memory::Write_U32(MIPS_MAKE_NOP(), sysc->symAddr + 4);
|
|
|
|
}
|
|
|
|
}
|
2013-01-02 02:08:42 +00:00
|
|
|
|
|
|
|
Syscall ex = {"", address, nib};
|
|
|
|
strncpy(ex.moduleName, moduleName, KERNELOBJECT_MAX_NAME_LENGTH);
|
|
|
|
ex.moduleName[KERNELOBJECT_MAX_NAME_LENGTH] = '\0';
|
|
|
|
exportedCalls.push_back(ex);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *GetFuncName(int moduleIndex, int func)
|
|
|
|
{
|
|
|
|
if (moduleIndex >= 0 && moduleIndex < (int)moduleDB.size())
|
|
|
|
{
|
|
|
|
const HLEModule &module = moduleDB[moduleIndex];
|
|
|
|
if (func>=0 && func <= module.numFunctions)
|
|
|
|
{
|
|
|
|
return module.funcTable[func].name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "[unknown]";
|
|
|
|
}
|
|
|
|
|
2012-12-09 06:39:36 +00:00
|
|
|
void hleCheckAllCallbacks()
|
|
|
|
{
|
|
|
|
hleAfterSyscall |= HLE_AFTER_ALL_CALLBACKS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hleCheckCurrentCallbacks()
|
|
|
|
{
|
|
|
|
hleAfterSyscall |= HLE_AFTER_CURRENT_CALLBACKS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hleReSchedule(const char *reason)
|
|
|
|
{
|
|
|
|
_dbg_assert_msg_(HLE, reason != 0, "hleReSchedule: Expecting a valid reason.");
|
2012-12-22 00:57:44 +00:00
|
|
|
_dbg_assert_msg_(HLE, reason != 0 && strlen(reason) < 256, "hleReSchedule: Not too long reason.");
|
2012-12-09 06:39:36 +00:00
|
|
|
|
|
|
|
hleAfterSyscall |= HLE_AFTER_RESCHED;
|
2012-12-09 17:12:49 +00:00
|
|
|
|
|
|
|
if (!reason)
|
2013-01-26 18:59:17 +00:00
|
|
|
hleAfterSyscallReschedReason = "Invalid reason";
|
2012-12-09 17:12:49 +00:00
|
|
|
else
|
2013-01-26 18:59:17 +00:00
|
|
|
hleAfterSyscallReschedReason = reason;
|
2012-12-09 06:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void hleReSchedule(bool callbacks, const char *reason)
|
|
|
|
{
|
|
|
|
hleReSchedule(reason);
|
2012-12-09 23:08:44 +00:00
|
|
|
if (callbacks)
|
|
|
|
hleAfterSyscall |= HLE_AFTER_RESCHED_CALLBACKS;
|
2012-12-09 06:39:36 +00:00
|
|
|
}
|
|
|
|
|
2012-12-21 05:54:40 +00:00
|
|
|
void hleRunInterrupts()
|
|
|
|
{
|
|
|
|
hleAfterSyscall |= HLE_AFTER_RUN_INTERRUPTS;
|
|
|
|
}
|
|
|
|
|
2012-12-25 05:47:54 +00:00
|
|
|
void hleDebugBreak()
|
2012-12-09 09:16:19 +00:00
|
|
|
{
|
2012-12-25 05:47:54 +00:00
|
|
|
hleAfterSyscall |= HLE_AFTER_DEBUG_BREAK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pauses execution after an HLE call.
|
2012-12-25 05:58:54 +00:00
|
|
|
bool hleExecuteDebugBreak(const HLEFunction &func)
|
2012-12-25 05:47:54 +00:00
|
|
|
{
|
|
|
|
const u32 NID_SUSPEND_INTR = 0x092968F4, NID_RESUME_INTR = 0x5F10D406;
|
|
|
|
|
|
|
|
// Never break on these, they're noise.
|
|
|
|
u32 blacklistedNIDs[] = {NID_SUSPEND_INTR, NID_RESUME_INTR, NID_IDLE};
|
2013-02-18 16:44:59 +00:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(blacklistedNIDs); ++i)
|
2012-12-25 05:47:54 +00:00
|
|
|
{
|
|
|
|
if (func.ID == blacklistedNIDs[i])
|
2012-12-25 05:58:54 +00:00
|
|
|
return false;
|
2012-12-25 05:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Core_EnableStepping(true);
|
|
|
|
host->SetDebugMode(true);
|
2012-12-25 05:58:54 +00:00
|
|
|
return true;
|
2012-12-25 05:47:54 +00:00
|
|
|
}
|
|
|
|
|
2013-03-09 19:37:57 +00:00
|
|
|
u32 hleDelayResult(u32 result, const char *reason, int usec)
|
|
|
|
{
|
|
|
|
CoreTiming::ScheduleEvent(usToCycles(usec), delayedResultEvent, __KernelGetCurThread());
|
|
|
|
__KernelWaitCurThread(WAITTYPE_DELAY, 1, result, 0, false, reason);
|
2013-03-10 17:59:59 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 hleDelayResult(u64 result, const char *reason, int usec)
|
|
|
|
{
|
|
|
|
u64 param = (result & 0xFFFFFFFF00000000) | __KernelGetCurThread();
|
|
|
|
CoreTiming::ScheduleEvent(usToCycles(usec), delayedResultEvent, param);
|
|
|
|
__KernelWaitCurThread(WAITTYPE_DELAY, 1, (u32) result, 0, false, reason);
|
2013-03-09 19:37:57 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-03-09 21:41:42 +00:00
|
|
|
void hleEatMicro(int usec)
|
|
|
|
{
|
|
|
|
// Maybe this should Idle, at least for larger delays? Could that cause issues?
|
|
|
|
currentMIPS->downcount -= (int) usToCycles(usec);
|
|
|
|
}
|
|
|
|
|
2012-12-25 05:47:54 +00:00
|
|
|
inline void hleFinishSyscall(int modulenum, int funcnum)
|
|
|
|
{
|
2012-12-09 09:16:19 +00:00
|
|
|
if ((hleAfterSyscall & HLE_AFTER_CURRENT_CALLBACKS) != 0)
|
|
|
|
__KernelForceCallbacks();
|
|
|
|
|
2012-12-21 05:54:40 +00:00
|
|
|
if ((hleAfterSyscall & HLE_AFTER_RUN_INTERRUPTS) != 0)
|
|
|
|
__RunOnePendingInterrupt();
|
|
|
|
|
2012-12-09 09:16:19 +00:00
|
|
|
// Rescheduling will also do HLE_AFTER_ALL_CALLBACKS.
|
|
|
|
if ((hleAfterSyscall & HLE_AFTER_RESCHED_CALLBACKS) != 0)
|
|
|
|
__KernelReSchedule(true, hleAfterSyscallReschedReason);
|
|
|
|
else if ((hleAfterSyscall & HLE_AFTER_RESCHED) != 0)
|
|
|
|
__KernelReSchedule(hleAfterSyscallReschedReason);
|
|
|
|
else if ((hleAfterSyscall & HLE_AFTER_ALL_CALLBACKS) != 0)
|
|
|
|
__KernelCheckCallbacks();
|
|
|
|
|
2012-12-25 05:58:54 +00:00
|
|
|
if ((hleAfterSyscall & HLE_AFTER_DEBUG_BREAK) != 0)
|
|
|
|
{
|
|
|
|
if (!hleExecuteDebugBreak(moduleDB[modulenum].funcTable[funcnum]))
|
|
|
|
{
|
|
|
|
// We'll do it next syscall.
|
|
|
|
hleAfterSyscall = HLE_AFTER_DEBUG_BREAK;
|
2013-01-26 18:59:17 +00:00
|
|
|
hleAfterSyscallReschedReason = 0;
|
2012-12-25 05:58:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-09 09:16:19 +00:00
|
|
|
hleAfterSyscall = HLE_AFTER_NOTHING;
|
2013-01-26 18:59:17 +00:00
|
|
|
hleAfterSyscallReschedReason = 0;
|
2012-12-09 09:16:19 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 16:37:54 +00:00
|
|
|
inline void updateSyscallStats(int modulenum, int funcnum, double total)
|
|
|
|
{
|
|
|
|
const char *name = moduleDB[modulenum].funcTable[funcnum].name;
|
|
|
|
// Ignore this one, especially for msInSyscalls (although that ignores CoreTiming events.)
|
|
|
|
if (0 == strcmp(name, "_sceKernelIdle"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (total > kernelStats.slowestSyscallTime)
|
|
|
|
{
|
|
|
|
kernelStats.slowestSyscallTime = total;
|
|
|
|
kernelStats.slowestSyscallName = name;
|
|
|
|
}
|
|
|
|
kernelStats.msInSyscalls += total;
|
|
|
|
|
|
|
|
KernelStatsSyscall statCall(modulenum, funcnum);
|
|
|
|
auto summedStat = kernelStats.summedMsInSyscalls.find(statCall);
|
|
|
|
if (summedStat == kernelStats.summedMsInSyscalls.end())
|
|
|
|
{
|
|
|
|
kernelStats.summedMsInSyscalls[statCall] = total;
|
|
|
|
if (total > kernelStats.summedSlowestSyscallTime)
|
|
|
|
{
|
|
|
|
kernelStats.summedSlowestSyscallTime = total;
|
|
|
|
kernelStats.summedSlowestSyscallName = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double newTotal = kernelStats.summedMsInSyscalls[statCall] += total;
|
|
|
|
if (newTotal > kernelStats.summedSlowestSyscallTime)
|
|
|
|
{
|
|
|
|
kernelStats.summedSlowestSyscallTime = newTotal;
|
|
|
|
kernelStats.summedSlowestSyscallName = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
void CallSyscall(u32 op)
|
|
|
|
{
|
2013-02-03 04:04:45 +00:00
|
|
|
if (g_Config.bShowDebugStats)
|
|
|
|
time_update();
|
2013-01-10 22:42:46 +00:00
|
|
|
double start = time_now_d();
|
2012-11-01 15:19:01 +00:00
|
|
|
u32 callno = (op >> 6) & 0xFFFFF; //20 bits
|
|
|
|
int funcnum = callno & 0xFFF;
|
|
|
|
int modulenum = (callno & 0xFF000) >> 12;
|
2012-12-21 09:18:52 +00:00
|
|
|
if (funcnum == 0xfff || op == 0xffff)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
_dbg_assert_msg_(HLE,0,"Unknown syscall");
|
2013-01-27 10:37:45 +00:00
|
|
|
ERROR_LOG(HLE,"Unknown syscall: Module: %s", modulenum > (int) moduleDB.size() ? "(unknown)" : moduleDB[modulenum].name);
|
2012-11-01 15:19:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
HLEFunc func = moduleDB[modulenum].funcTable[funcnum].func;
|
|
|
|
if (func)
|
|
|
|
{
|
|
|
|
func();
|
2012-12-09 06:39:36 +00:00
|
|
|
|
2012-12-09 09:16:19 +00:00
|
|
|
if (hleAfterSyscall != HLE_AFTER_NOTHING)
|
2012-12-25 05:47:54 +00:00
|
|
|
hleFinishSyscall(modulenum, funcnum);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERROR_LOG(HLE,"Unimplemented HLE function %s", moduleDB[modulenum].funcTable[funcnum].name);
|
|
|
|
}
|
2013-01-31 05:58:51 +00:00
|
|
|
if (g_Config.bShowDebugStats)
|
2013-02-03 04:04:45 +00:00
|
|
|
{
|
|
|
|
time_update();
|
2013-01-31 05:58:51 +00:00
|
|
|
updateSyscallStats(modulenum, funcnum, time_now_d() - start);
|
2013-02-03 04:04:45 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|