Skip to content

Commit

Permalink
Merge pull request #19914 from hrydgard/misc-fixes
Browse files Browse the repository at this point in the history
Fix a logging problem reported by Nemo, and a pause bug reported by IRVN
  • Loading branch information
hrydgard authored Jan 23, 2025
2 parents adbd721 + 662a889 commit d6b15c7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 34 deletions.
10 changes: 9 additions & 1 deletion Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ volatile bool coreStatePending = false;

static bool powerSaving = false;
static bool g_breakAfterFrame = false;
static std::string g_breakReason;

static MIPSExceptionInfo g_exceptionInfo;

Expand Down Expand Up @@ -390,7 +391,6 @@ void Core_Break(const char *reason, u32 relatedAddress) {
}

{
// Stop the tracer
std::lock_guard<std::mutex> lock(g_stepMutex);
if (!g_cpuStepCommand.empty() && Core_IsStepping()) {
// If we're in a failed step that uses a temp breakpoint, we need to be able to override it here.
Expand All @@ -404,7 +404,11 @@ void Core_Break(const char *reason, u32 relatedAddress) {
return;
}
}

// Stop the tracer
mipsTracer.stop_tracing();

g_breakReason = reason;
g_cpuStepCommand.type = CPUStepType::None;
g_cpuStepCommand.reason = reason;
g_cpuStepCommand.relatedAddr = relatedAddress;
Expand All @@ -415,6 +419,10 @@ void Core_Break(const char *reason, u32 relatedAddress) {
System_Notify(SystemNotification::DEBUG_MODE_CHANGE);
}

const std::string &Core_BreakReason() {
return g_breakReason;
}

// Free-threaded (or at least should be)
void Core_Resume() {
// If the current PC is on a breakpoint, the user doesn't want to do nothing.
Expand Down
2 changes: 2 additions & 0 deletions Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ void Core_Break(const char *reason, u32 relatedAddress = 0);
// Resumes execution. Works both when stepping the CPU and the GE.
void Core_Resume();

const std::string &Core_BreakReason();

// This should be called externally.
// Can fail if another step type was requested this frame.
bool Core_RequestCPUStep(CPUStepType stepType, int stepSize);
Expand Down
50 changes: 26 additions & 24 deletions Core/HLE/sceIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2545,16 +2545,16 @@ static u32 sceIoDclose(int id) {
return kernelObjects.Destroy<DirListing>(id);
}

// NOTE: Logs like a HLE function. Careful.
int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) {
u32 error;
FileNode *f = __IoGetFd(id, error);
if (error) {
return hleLogError(Log::sceIo, error, "bad file");
return error;
}

if (f->asyncBusy()) {
return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ASYNC_BUSY, "async busy");
ERROR_LOG(Log::sceIo, "__IoIoctl: async busy");
return SCE_KERNEL_ERROR_ASYNC_BUSY;
}

// TODO: Move this into each command, probably?
Expand Down Expand Up @@ -2591,16 +2591,18 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
pspFileSystem.SeekFile(f->handle, (s32)0, FILEMOVE_BEGIN);
if (memcmp(pgd_header, pgd_magic, 4) == 0) {
// File is PGD file, but key mismatch
return hleLogError(Log::sceIo, ERROR_PGD_INVALID_HEADER, "%s is PGD file, but there's likely a key mismatch. Returning error.", f->fullpath.c_str());
ERROR_LOG(Log::sceIo, "%s is PGD file, but there's likely a key mismatch. Returning error.", f->fullpath.c_str());
return ERROR_PGD_INVALID_HEADER;
} else {
// File is not encrypted.
return hleLogSuccessInfoI(Log::sceIo, 0, "%s is not an encrypted PGD file as was expected. Proceeding.", f->fullpath.c_str());
WARN_LOG(Log::sceIo, "%s is not an encrypted PGD file as was expected. Proceeding anyway.", f->fullpath.c_str());
return 0;
}
} else {
// Everything OK.
f->npdrm = true;
f->pgdInfo->data_offset += f->pgd_offset;
return hleLogDebug(Log::sceIo, 0);
return 0;
}
break;
}
Expand All @@ -2613,9 +2615,9 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
// Get PGD data size. Called from sceNpDrmEdataGetDataSize
case 0x04100010:
if (f->pgdInfo)
return hleLogDebug(Log::sceIo, f->pgdInfo->data_size);
return f->pgdInfo->data_size;
else
return hleLogDebug(Log::sceIo, (int)f->FileInfo().size);
return (int)f->FileInfo().size;
break;

// Get UMD sector size
Expand All @@ -2627,7 +2629,7 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
// ISOs always use 2048 sized sectors.
Memory::Write_U32(2048, outdataPtr);
} else {
return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT);
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
}
break;

Expand All @@ -2640,7 +2642,7 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
u32 offset = (u32)pspFileSystem.GetSeekPos(f->handle);
Memory::Write_U32(offset, outdataPtr);
} else {
return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT);
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
}
break;

Expand All @@ -2664,7 +2666,7 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
}
pspFileSystem.SeekFile(f->handle, (s32)seekInfo->offset, seek);
} else {
return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT);
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
}
break;

Expand All @@ -2676,7 +2678,7 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
if (Memory::IsValidAddress(outdataPtr) && outlen >= 4) {
Memory::Write_U32(f->FileInfo().startSector, outdataPtr);
} else {
return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT);
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
}
break;

Expand All @@ -2688,7 +2690,7 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
if (Memory::IsValidAddress(outdataPtr) && outlen >= 8) {
Memory::Write_U64(f->FileInfo().size, outdataPtr);
} else {
return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT);
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
}
break;

Expand All @@ -2704,10 +2706,10 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
usec = 0;
return sceIoRead(id, outdataPtr, size);
} else {
return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT);
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
}
} else {
return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT);
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
}
break;

Expand Down Expand Up @@ -2736,10 +2738,10 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
usec = 0;
return hleCall(IoFileMgrForUser, u32, sceIoRead, id, outdataPtr, size);
} else {
return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT);
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
}
} else {
return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT);
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
}
break;

Expand All @@ -2765,11 +2767,11 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
// Position is in sectors, don't forget.
if (newPos < 0 || newPos > f->FileInfo().size) {
// Not allowed to seek past the end of the file with this API.
return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_FILE_SIZE);
return SCE_KERNEL_ERROR_ERRNO_INVALID_FILE_SIZE;
}
pspFileSystem.SeekFile(f->handle, (s32)seekInfo->offset, seek);
} else {
return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT);
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
}
break;

Expand All @@ -2783,21 +2785,21 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
Reporting::ReportMessage(temp, f->fullpath.c_str(), indataPtr, inlen, outdataPtr, outlen);
ERROR_LOG(Log::sceIo, "UNIMPL 0=sceIoIoctl id: %08x, cmd %08x, indataPtr %08x, inlen %08x, outdataPtr %08x, outLen %08x", id,cmd,indataPtr,inlen,outdataPtr,outlen);
}
return hleLogSuccessOrError(Log::sceIo, result);
return result;
}
break;
}

return hleLogDebug(Log::sceIo, 0);
return 0;
}

u32 sceIoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen) {
int usec = 0;
int result = __IoIoctl(id, cmd, indataPtr, inlen, outdataPtr, outlen, usec);
if (usec != 0) {
return hleDelayResult(result, "io ctrl command", usec);
return hleDelayResult(hleLogSuccessOrError(Log::sceIo, result), "io ctrl command", usec);
}
return result;
return hleLogSuccessOrError(Log::sceIo, result);
}

static u32 sceIoIoctlAsync(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen) {
Expand Down Expand Up @@ -2960,7 +2962,7 @@ static int IoAsyncFinish(int id) {
hleSkipDeadbeef();

params.op = IoAsyncOp::NONE;
return 0;
return hleLogDebug(Log::sceIo, 0);
} else {
return hleLogError(Log::sceIo, error, "bad file descriptor");
}
Expand Down
17 changes: 9 additions & 8 deletions Core/HLE/scePspNpDrm_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
#include "Core/HLE/sceIo.h"

static int sceNpDrmSetLicenseeKey(u32 npDrmKeyAddr) {
return hleLogWarning(Log::HLE, 0, "UNIMPL");
return hleLogWarning(Log::sceIo, 0, "UNIMPL");
}

static int sceNpDrmClearLicenseeKey() {
return hleLogWarning(Log::HLE, 0, "UNIMPL");
return hleLogWarning(Log::sceIo, 0, "UNIMPL");
}

static int sceNpDrmRenameCheck(const char *filename) {
return hleLogWarning(Log::HLE, 0, "UNIMPL");
return hleLogWarning(Log::sceIo, 0, "UNIMPL");
}

static int sceNpDrmEdataSetupKey(u32 edataFd) {
Expand All @@ -23,22 +23,23 @@ static int sceNpDrmEdataSetupKey(u32 edataFd) {

// set PGD offset
int retval = __IoIoctl(edataFd, 0x04100002, 0x90, 0, 0, 0, usec);
if (retval != 0) {
return hleDelayResult(retval, "io ctrl command", usec);
if (retval < 0) {
return hleDelayResult(hleLogError(Log::sceIo, retval), "io ctrl command", usec);
}

// call PGD open
// Note that usec accumulates.
retval = __IoIoctl(edataFd, 0x04100001, 0, 0, 0, 0, usec);
return hleDelayResult(retval, "io ctrl command", usec);
return hleDelayResult(hleLogError(Log::sceIo, retval), "io ctrl command", usec);
}

static int sceNpDrmEdataGetDataSize(u32 edataFd) {
int retval = hleCall(IoFileMgrForKernel, u32, sceIoIoctl, edataFd, 0x04100010, 0, 0, 0, 0);
return hleLogSuccessInfoI(Log::HLE, retval);
return hleLogSuccessInfoI(Log::sceIo, retval);
}

static int sceNpDrmOpen() {
ERROR_LOG(Log::HLE, "UNIMPL: sceNpDrmOpen()");
ERROR_LOG(Log::sceIo, "UNIMPL: sceNpDrmOpen()");
return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,12 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) {
break;
case VIRTKEY_FASTFORWARD:
if (down && !NetworkWarnUserIfOnlineAndCantSpeed()) {
/*
// This seems like strange behavior. Commented it out.
if (coreState == CORE_STEPPING_CPU) {
Core_Resume();
}
*/
PSP_CoreParameter().fastForward = true;
} else {
PSP_CoreParameter().fastForward = false;
Expand Down
2 changes: 1 addition & 1 deletion Windows/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ namespace MainWindow
} else {
if (pause) {
Core_Break("ui.lost_focus", 0);
} else {
} else if (Core_BreakReason() == "ui.lost_focus") {
Core_Resume();
}
}
Expand Down

0 comments on commit d6b15c7

Please sign in to comment.