Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HLE auto log flag: Will let us entirely omit logging code from most syscalls, while still getting good logging. #19933

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 10 additions & 33 deletions Core/HLE/HLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ static void updateSyscallStats(int modulenum, int funcnum, double total)
}
}

static void CallSyscallWithFlags(const HLEFunction *info) {
static void PerformCallSyscall(const HLEFunction *info) {
// _dbg_assert_(g_stackSize == 0);
g_stackSize = 0;

Expand All @@ -735,6 +735,10 @@ static void CallSyscallWithFlags(const HLEFunction *info) {
RETURN(hleLogDebug(Log::HLE, SCE_KERNEL_ERROR_ILLEGAL_CONTEXT, "in interrupt"));
} else {
info->func();
if (flags & HLE_AUTO_LOG) {
int retval = currentMIPS->r[MIPS_REG_V0];
retval = hleLogDebugOrError(info->logCat, retval);
}
}

// Now, g_stackSize should be back to 0. Enable this for "pedantic mode", will find a lot of problems.
Expand All @@ -749,31 +753,6 @@ static void CallSyscallWithFlags(const HLEFunction *info) {
g_stackSize = 0;
}

static void CallSyscallWithoutFlags(const HLEFunction *info) {
// _dbg_assert_(g_stackSize == 0);
g_stackSize = 0;

const int stackSize = g_stackSize;
if (stackSize == 0) {
g_stack[0] = info;
g_stackSize = 1;
}
g_syscallPC = currentMIPS->pc;

info->func();

// Now, g_stackSize should be back to 0. Enable this for "pedantic mode", will find a lot of problems.
// Check g_stack[0] in the debugger.
// _dbg_assert_(g_stackSize == 0);

if (hleAfterSyscall != HLE_AFTER_NOTHING)
hleFinishSyscall(info);
else
SetDeadbeefRegs();

g_stackSize = 0;
}

const HLEFunction *GetSyscallFuncPointer(MIPSOpcode op) {
u32 callno = (op >> 6) & 0xFFFFF; //20 bits
int funcnum = callno & 0xFFF;
Expand All @@ -794,6 +773,7 @@ const HLEFunction *GetSyscallFuncPointer(MIPSOpcode op) {
return &moduleDB[modulenum].funcTable[funcnum];
}

// This almost never returns a direct function, we nearly always return PerformCallSyscall.
void *GetQuickSyscallFunc(MIPSOpcode op) {
if (coreCollectDebugStats)
return nullptr;
Expand All @@ -807,15 +787,14 @@ void *GetQuickSyscallFunc(MIPSOpcode op) {
// TODO: Do this with a flag?
if (op == idleOp)
return (void *)info->func;
if (info->flags != 0)
return (void *)&CallSyscallWithFlags;
return (void *)&CallSyscallWithoutFlags;
return (void *)&PerformCallSyscall;
}

void hleSetFlipTime(double t) {
hleFlipTime = t;
}

// This is only called when debug stats is on. In that case, code is recompiled to call this instead of using GetQuickSyscallFunc to bypass it.
void CallSyscall(MIPSOpcode op) {
PROFILE_THIS_SCOPE("syscall");
double start = 0.0; // need to initialize to fix the race condition where coreCollectDebugStats is enabled in the middle of this func.
Expand All @@ -833,10 +812,8 @@ void CallSyscall(MIPSOpcode op) {
if (info->func) {
if (op == idleOp)
info->func();
else if (info->flags != 0)
CallSyscallWithFlags(info);
else
CallSyscallWithoutFlags(info);
PerformCallSyscall(info);
} else {
// We haven't incremented the stack yet.
RETURN(SCE_KERNEL_ERROR_LIBRARY_NOT_YET_LINKED);
Expand Down Expand Up @@ -919,7 +896,7 @@ size_t hleFormatLogArgs(char *message, size_t sz, const char *argmask) {
if (Memory::IsValidAddress(regval)) {
const char *s = Memory::GetCharPointer(regval);
const int safeLen = Memory::ValidSize(regval, 128);
if (strnlen(s, safeLen) >= safeLen) {
if ((int)strnlen(s, safeLen) >= safeLen) {
APPEND_FMT("%.*s...", safeLen, Memory::GetCharPointer(regval));
} else {
APPEND_FMT("%.*s", safeLen, Memory::GetCharPointer(regval));
Expand Down
3 changes: 3 additions & 0 deletions Core/HLE/HLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ enum {
HLE_CLEAR_STACK_BYTES = 1 << 10,
// Indicates that this call operates in kernel mode.
HLE_KERNEL_SYSCALL = 1 << 11,
// Indicates that the framework performs the logging, depending on the return value.
HLE_AUTO_LOG = 1 << 12,
};

struct HLEFunction {
Expand Down Expand Up @@ -74,6 +76,7 @@ struct HLEFunction {
u32 flags;
// See HLE_CLEAR_STACK_BYTES.
u32 stackBytesToClear;
Log logCat;
};

struct HLEModule {
Expand Down
4 changes: 2 additions & 2 deletions Core/HLE/sceDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ static void __DisplayWaitForVblanksCB(const char *reason, int vblanks) {

static int sceDisplayWaitVblankStart() {
__DisplayWaitForVblanks("vblank start waited", 1);
return hleLogDebug(Log::sceDisplay, 0);
return 0;
}

static int sceDisplayWaitVblank() {
Expand Down Expand Up @@ -1107,7 +1107,7 @@ const HLEFunction sceDisplay[] = {
{0X289D82FE, &WrapI_UIII<sceDisplaySetFramebuf>, "sceDisplaySetFrameBuf", 'i', "xiii"},
{0XEEDA2E54, &WrapU_UUUI<sceDisplayGetFramebuf>, "sceDisplayGetFrameBuf", 'x', "pppi"},
{0X36CDFADE, &WrapI_V<sceDisplayWaitVblank>, "sceDisplayWaitVblank", 'i', "", HLE_NOT_DISPATCH_SUSPENDED },
{0X984C27E7, &WrapI_V<sceDisplayWaitVblankStart>, "sceDisplayWaitVblankStart", 'i', "", HLE_NOT_IN_INTERRUPT | HLE_NOT_DISPATCH_SUSPENDED },
{0X984C27E7, &WrapI_V<sceDisplayWaitVblankStart>, "sceDisplayWaitVblankStart", 'i', "", HLE_NOT_IN_INTERRUPT | HLE_NOT_DISPATCH_SUSPENDED | HLE_AUTO_LOG, 0, Log::sceDisplay },
{0X40F1469C, &WrapI_I<sceDisplayWaitVblankStartMulti>, "sceDisplayWaitVblankStartMulti", 'i', "i" },
{0X8EB9EC49, &WrapI_V<sceDisplayWaitVblankCB>, "sceDisplayWaitVblankCB", 'i', "", HLE_NOT_DISPATCH_SUSPENDED },
{0X46F186C3, &WrapI_V<sceDisplayWaitVblankStartCB>, "sceDisplayWaitVblankStartCB", 'i', "", HLE_NOT_IN_INTERRUPT | HLE_NOT_DISPATCH_SUSPENDED },
Expand Down
7 changes: 2 additions & 5 deletions Core/MIPS/ARM/ArmCompBranch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,14 +690,11 @@ void ArmJit::Comp_Syscall(MIPSOpcode op)
#else
// Skip the CallSyscall where possible.
void *quickFunc = GetQuickSyscallFunc(op);
if (quickFunc)
{
if (quickFunc) {
gpr.SetRegImm(R0, (u32)(intptr_t)GetSyscallFuncPointer(op));
// Already flushed, so R1 is safe.
QuickCallFunction(R1, quickFunc);
}
else
{
} else {
gpr.SetRegImm(R0, op.encoding);
QuickCallFunction(R1, (void *)&CallSyscall);
}
Expand Down
Loading