diff --git a/Core/HLE/HLE.h b/Core/HLE/HLE.h index cc69a76b0d..fde7b1623c 100644 --- a/Core/HLE/HLE.h +++ b/Core/HLE/HLE.h @@ -216,6 +216,13 @@ T hleDoLog(Log t, LogLevel level, T res, const char *file, int line, const char return res; } +// This will become important later. +template +[[nodiscard]] +T hleNoLog(T t) { + return t; +} + // This is just a quick way to force logging to be more visible for one file. #ifdef HLE_LOG_FORCE #define HLE_LOG_LDEBUG LNOTICE diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 7317d2f388..793c373d2f 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -1625,11 +1625,12 @@ static u32 sceIoClose(int id) { } static u32 sceIoRemove(const char *filename) { - // TODO: This timing isn't necessarily accurate, low end for now. - if (!pspFileSystem.GetFileInfo(filename).exists) - return hleDelayResult(SCE_KERNEL_ERROR_ERRNO_FILE_NOT_FOUND, "file removed", 100); + if (!pspFileSystem.GetFileInfo(filename).exists) { + return hleDelayResult(hleLogWarning(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_FILE_NOT_FOUND), "file removed", 100); + } pspFileSystem.RemoveFile(filename); + // TODO: This timing isn't necessarily accurate, low end for now. return hleDelayResult(hleLogDebug(Log::sceIo, 0), "file removed", 100); } @@ -1638,7 +1639,7 @@ static u32 sceIoMkdir(const char *dirname, int mode) { if (pspFileSystem.MkDir(dirname)) return hleDelayResult(hleLogDebug(Log::sceIo, 0), "mkdir", 1000); else - return hleDelayResult(SCE_KERNEL_ERROR_ERRNO_FILE_ALREADY_EXISTS, "mkdir", 1000); + return hleDelayResult(hleLogWarning(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_FILE_ALREADY_EXISTS), "mkdir", 1000); } static u32 sceIoRmdir(const char *dirname) { @@ -1646,7 +1647,7 @@ static u32 sceIoRmdir(const char *dirname) { if (pspFileSystem.RmDir(dirname)) return hleDelayResult(hleLogDebug(Log::sceIo, 0), "rmdir", 1000); else - return hleDelayResult(SCE_KERNEL_ERROR_ERRNO_FILE_NOT_FOUND, "rmdir", 1000); + return hleDelayResult(hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_FILE_NOT_FOUND), "rmdir", 1000); } static u32 sceIoSync(const char *devicename, int flag) { @@ -1674,7 +1675,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o Memory::Write_U32(0x10, outPtr + 4); // Always return game disc (if present) return 0; } else { - return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS; + return hleLogError(Log::sceIo, ERROR_MEMSTICK_DEVCTL_BAD_PARAMS); } break; case 0x01F20002: @@ -1683,7 +1684,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o Memory::Write_U32(0x10, outPtr); // Assume first sector return 0; } else { - return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS; + return hleLogError(Log::sceIo, ERROR_MEMSTICK_DEVCTL_BAD_PARAMS); } break; case 0x01F20003: @@ -1692,7 +1693,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o Memory::Write_U32((u32) (info.size) - 1, outPtr); return 0; } else { - return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS; + return hleLogError(Log::sceIo, ERROR_MEMSTICK_DEVCTL_BAD_PARAMS); } break; case 0x01F100A3: @@ -1700,7 +1701,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o if (Memory::IsValidAddress(argAddr) && argLen >= 4) { return hleDelayResult(0, "dev seek", 100); } else { - return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS; + return hleLogError(Log::sceIo, ERROR_MEMSTICK_DEVCTL_BAD_PARAMS); } break; case 0x01F100A4: @@ -1708,7 +1709,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o if (Memory::IsValidAddress(argAddr) && argLen >= 4) { return 0; } else { - return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS; + return hleLogError(Log::sceIo, ERROR_MEMSTICK_DEVCTL_BAD_PARAMS); } break; case 0x01F300A5: @@ -1717,7 +1718,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o Memory::Write_U32(1, outPtr); // Status (unitary index of the requested read, greater or equal to 1) return 0; } else { - return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS; + return hleLogError(Log::sceIo, ERROR_MEMSTICK_DEVCTL_BAD_PARAMS); } break; case 0x01F300A7: @@ -1727,7 +1728,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o // Place the calling thread in wait state return 0; } else { - return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS; + return hleLogError(Log::sceIo, ERROR_MEMSTICK_DEVCTL_BAD_PARAMS); } break; case 0x01F300A8: @@ -1738,7 +1739,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o // 0x20 - UMD data cache thread is running return 0; // Return finished } else { - return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS; + return hleLogError(Log::sceIo, ERROR_MEMSTICK_DEVCTL_BAD_PARAMS); } break; case 0x01F300A9: @@ -1748,7 +1749,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o // Wake up the thread waiting for the UMD data cache handling. return 0; } else { - return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS; + return hleLogError(Log::sceIo, ERROR_MEMSTICK_DEVCTL_BAD_PARAMS); } break; // TODO: What do these do? Seem to require a u32 in, no output. @@ -1776,7 +1777,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o } return 0; } else { - return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS; + return hleLogError(Log::sceIo, ERROR_MEMSTICK_DEVCTL_BAD_PARAMS); } break; case 0x02015804: @@ -1804,7 +1805,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT; } } else { - return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS; + return hleLogError(Log::sceIo, ERROR_MEMSTICK_DEVCTL_BAD_PARAMS); } break; case 0x02015805: @@ -1828,7 +1829,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT; } } else { - return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS; + return hleLogError(Log::sceIo, ERROR_MEMSTICK_DEVCTL_BAD_PARAMS); } break; case 0x02025806: @@ -1839,7 +1840,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o Memory::Write_U32(MemoryStick_State(), outPtr); return 0; } else { - return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS; + return hleLogError(Log::sceIo, ERROR_MEMSTICK_DEVCTL_BAD_PARAMS); } break; case 0x02425818: @@ -1868,7 +1869,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o return 0; } else { - return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS; + return hleLogError(Log::sceIo, ERROR_MEMSTICK_DEVCTL_BAD_PARAMS); } break; case 0x02425824: @@ -1880,8 +1881,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o Memory::WriteUnchecked_U32(0, outPtr); return 0; } else { - ERROR_LOG(Log::sceIo, "Failed 0x02425824 fat"); - return -1; + return hleLogError(Log::sceIo, -1, "Failed 0x02425824 fat"); } break; } @@ -1914,10 +1914,10 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o } return 0; } else { - return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT; + return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT); } } else { - return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT; + return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT); } break; case 0x02415822: @@ -1938,7 +1938,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o DEBUG_LOG(Log::sceIo, "sceIoDevCtl: Unregistered memstick FAT callback %i", cbId); return 0; } else { - return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT; + return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT); } } break; @@ -1961,7 +1961,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o } else if (!Memory::IsValidAddress(outPtr)) { // Technically, only checks for NULL, crashes for many bad addresses. ERROR_LOG(Log::sceIo, "sceIoDevctl: fatms0: 0x02425823 command, no output address"); - return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT; + return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT); } else { // Does not care about outLen, even if it's 0. // Note: writes 1 when inserted, 0 when not inserted. @@ -1978,8 +1978,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o Memory::Write_U32(0, outPtr); return 0; } else { - ERROR_LOG(Log::sceIo, "Failed 0x02425824 fat"); - return -1; + return hleLogError(Log::sceIo, -1, "Failed 0x02425824 fat"); } break; case 0x02425818: @@ -2006,14 +2005,13 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o } return 0; } else { - return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS; + return hleLogError(Log::sceIo, ERROR_MEMSTICK_DEVCTL_BAD_PARAMS); } break; } } - if (!strcmp(name, "kemulator:") || !strcmp(name, "emulator:")) - { + if (!strcmp(name, "kemulator:") || !strcmp(name, "emulator:")) { // Emulator special tricks! enum { @@ -2104,9 +2102,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o return 0; } - ERROR_LOG(Log::sceIo, "sceIoDevCtl: UNKNOWN PARAMETERS"); - - return 0; + return hleLogError(Log::sceIo, 0, "UNKNOWN PARAMETERS"); } //089c6d1c weird branch @@ -2114,8 +2110,9 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o 089c6bdc ]: HLE: sceKernelCreateCallback(name= MemoryStick Detection ,entry= 089c7484 ) (z_un_089c6bc4) 089c6c40 ]: HLE: sceKernelCreateCallback(name= MemoryStick Assignment ,entry= 089c7534 ) (z_un_089c6bc4) */ + // Keeping this report intact ERROR_LOG_REPORT(Log::sceIo, "UNIMPL sceIoDevctl(\"%s\", %08x, %08x, %i, %08x, %i)", name, cmd, argAddr, argLen, outPtr, outLen); - return SCE_KERNEL_ERROR_UNSUP; + return hleNoLog(SCE_KERNEL_ERROR_UNSUP); } static u32 sceIoRename(const char *from, const char *to) { diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index 36db220d6e..361a06426c 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -678,9 +678,7 @@ int sceKernelCreateFpl(const char *name, u32 mpid, u32 attr, u32 blockSize, u32 bool atEnd = (attr & PSP_FPL_ATTR_HIGHMEM) != 0; u32 address = allocator->Alloc(totalSize, atEnd, StringFromFormat("FPL/%s", name).c_str()); if (address == (u32)-1) { - DEBUG_LOG(Log::sceKernel, "sceKernelCreateFpl(\"%s\", partition=%i, attr=%08x, bsize=%i, nb=%i) FAILED - out of ram", - name, mpid, attr, blockSize, numBlocks); - return SCE_KERNEL_ERROR_NO_MEMORY; + return hleLogDebug(Log::sceKernel, SCE_KERNEL_ERROR_NO_MEMORY, "FAILED - out of ram"); } FPL *fpl = new FPL; @@ -700,10 +698,7 @@ int sceKernelCreateFpl(const char *name, u32 mpid, u32 attr, u32 blockSize, u32 fpl->address = address; fpl->alignedSize = alignedSize; - DEBUG_LOG(Log::sceKernel, "%i=sceKernelCreateFpl(\"%s\", partition=%i, attr=%08x, bsize=%i, nb=%i)", - id, name, mpid, attr, blockSize, numBlocks); - - return id; + return hleLogDebug(Log::sceKernel, id); } int sceKernelDeleteFpl(SceUID uid) @@ -711,25 +706,19 @@ int sceKernelDeleteFpl(SceUID uid) hleEatCycles(600); u32 error; FPL *fpl = kernelObjects.Get(uid, error); - if (fpl) - { - DEBUG_LOG(Log::sceKernel, "sceKernelDeleteFpl(%i)", uid); - - bool wokeThreads = __KernelClearFplThreads(fpl, SCE_KERNEL_ERROR_WAIT_DELETE); - if (wokeThreads) - hleReSchedule("fpl deleted"); - - BlockAllocator *alloc = BlockAllocatorFromAddr(fpl->address); - _assert_msg_(alloc != nullptr, "Should always have a valid allocator/address"); - if (alloc) - alloc->Free(fpl->address); - return kernelObjects.Destroy(uid); - } - else - { - DEBUG_LOG(Log::sceKernel, "sceKernelDeleteFpl(%i): invalid fpl", uid); - return error; + if (!fpl) { + return hleLogDebug(Log::sceKernel, error, "invalid fpl", uid); } + + bool wokeThreads = __KernelClearFplThreads(fpl, SCE_KERNEL_ERROR_WAIT_DELETE); + if (wokeThreads) + hleReSchedule("fpl deleted"); + + BlockAllocator *alloc = BlockAllocatorFromAddr(fpl->address); + _assert_msg_(alloc != nullptr, "Should always have a valid allocator/address"); + if (alloc) + alloc->Free(fpl->address); + return hleLogDebug(Log::sceKernel, kernelObjects.Destroy(uid)); } void __KernelFplTimeout(u64 userdata, int cyclesLate) @@ -764,8 +753,6 @@ int sceKernelAllocateFpl(SceUID uid, u32 blockPtrAddr, u32 timeoutPtr) FPL *fpl = kernelObjects.Get(uid, error); if (fpl) { - DEBUG_LOG(Log::sceKernel, "sceKernelAllocateFpl(%i, %08x, %08x)", uid, blockPtrAddr, timeoutPtr); - int blockNum = fpl->allocateBlock(); if (blockNum >= 0) { u32 blockPtr = fpl->address + fpl->alignedSize * blockNum; @@ -781,12 +768,11 @@ int sceKernelAllocateFpl(SceUID uid, u32 blockPtrAddr, u32 timeoutPtr) __KernelWaitCurThread(WAITTYPE_FPL, uid, 0, timeoutPtr, false, "fpl waited"); } - return 0; + return hleLogDebug(Log::sceKernel, 0); } else { - DEBUG_LOG(Log::sceKernel, "sceKernelAllocateFpl(%i, %08x, %08x): invalid fpl", uid, blockPtrAddr, timeoutPtr); - return error; + return hleLogDebug(Log::sceKernel, error, "invalid fpl"); } } @@ -817,8 +803,7 @@ int sceKernelAllocateFplCB(SceUID uid, u32 blockPtrAddr, u32 timeoutPtr) } else { - DEBUG_LOG(Log::sceKernel, "sceKernelAllocateFplCB(%i, %08x, %08x): invalid fpl", uid, blockPtrAddr, timeoutPtr); - return error; + return hleLogDebug(Log::sceKernel, error, "invalid fpl"); } } @@ -842,8 +827,7 @@ int sceKernelTryAllocateFpl(SceUID uid, u32 blockPtrAddr) } else { - DEBUG_LOG(Log::sceKernel, "sceKernelTryAllocateFpl(%i, %08x): invalid fpl", uid, blockPtrAddr); - return error; + return hleLogDebug(Log::sceKernel, error, "invalid fpl"); } } @@ -891,8 +875,7 @@ retry: } else { - DEBUG_LOG(Log::sceKernel, "sceKernelFreeFpl(%i, %08x): invalid fpl", uid, blockPtr); - return error; + return hleLogDebug(Log::sceKernel, error, "invalid fpl"); } } @@ -916,8 +899,7 @@ int sceKernelCancelFpl(SceUID uid, u32 numWaitThreadsPtr) } else { - DEBUG_LOG(Log::sceKernel, "sceKernelCancelFpl(%i, %08x): invalid fpl", uid, numWaitThreadsPtr); - return error; + return hleLogDebug(Log::sceKernel, error, "invalid fpl"); } } @@ -1020,15 +1002,13 @@ public: static u32 sceKernelMaxFreeMemSize() { u32 retVal = userMemory.GetLargestFreeBlockSize(); - DEBUG_LOG(Log::sceKernel, "%08x (dec %i)=sceKernelMaxFreeMemSize()", retVal, retVal); - return retVal; + return hleLogDebug(Log::sceKernel, retVal); } static u32 sceKernelTotalFreeMemSize() { u32 retVal = userMemory.GetTotalFreeBytes(); - DEBUG_LOG(Log::sceKernel, "%08x (dec %i)=sceKernelTotalFreeMemSize()", retVal, retVal); - return retVal; + return hleLogDebug(Log::sceKernel, retVal); } int sceKernelAllocPartitionMemory(int partition, const char *name, int type, u32 size, u32 addr) { @@ -1054,44 +1034,30 @@ int sceKernelAllocPartitionMemory(int partition, const char *name, int type, u32 PartitionMemoryBlock *block = new PartitionMemoryBlock(allocator, name, size, (MemblockType)type, addr); if (!block->IsValid()) { delete block; - ERROR_LOG(Log::sceKernel, "sceKernelAllocPartitionMemory(partition = %i, %s, type= %i, size= %i, addr= %08x): allocation failed", partition, name, type, size, addr); - return SCE_KERNEL_ERROR_MEMBLOCK_ALLOC_FAILED; + return hleLogError(Log::sceKernel, SCE_KERNEL_ERROR_MEMBLOCK_ALLOC_FAILED); } SceUID uid = kernelObjects.Create(block); - DEBUG_LOG(Log::sceKernel,"%i = sceKernelAllocPartitionMemory(partition = %i, %s, type= %i, size= %i, addr= %08x)", - uid, partition, name, type, size, addr); - - return uid; + return hleLogDebug(Log::sceKernel, uid); } -int sceKernelFreePartitionMemory(SceUID id) -{ - DEBUG_LOG(Log::sceKernel,"sceKernelFreePartitionMemory(%d)",id); - - return kernelObjects.Destroy(id); +int sceKernelFreePartitionMemory(SceUID id) { + return hleLogSuccessOrError(Log::sceKernel, kernelObjects.Destroy(id)); } -u32 sceKernelGetBlockHeadAddr(SceUID id) -{ +u32 sceKernelGetBlockHeadAddr(SceUID id) { u32 error; PartitionMemoryBlock *block = kernelObjects.Get(id, error); - if (block) - { - DEBUG_LOG(Log::sceKernel,"%08x = sceKernelGetBlockHeadAddr(%i)", block->address, id); - return block->address; - } - else - { - ERROR_LOG(Log::sceKernel,"sceKernelGetBlockHeadAddr failed(%i)", id); - return 0; + if (block) { + return hleLogDebug(Log::sceKernel, block->address, "addr: %08x", block->address); + } else { + // TODO: return value? + return hleLogError(Log::sceKernel, 0, "sceKernelGetBlockHeadAddr failed(%i)", id); } } - -static int sceKernelPrintf(const char *formatString) -{ - if (formatString == NULL) +static int sceKernelPrintf(const char *formatString) { + if (!formatString) return -1; bool supported = true; @@ -1209,10 +1175,9 @@ static int sceKernelPrintf(const char *formatString) result.resize(result.size() - 1); if (supported) - INFO_LOG(Log::Printf, "sceKernelPrintf: %s", result.c_str()); + return hleLogSuccessInfoI(Log::Printf, 0, "\"%s\"", result.c_str()); else - ERROR_LOG(Log::Printf, "UNIMPL sceKernelPrintf(%s, %08x, %08x, %08x)", format.c_str(), PARAM(1), PARAM(2), PARAM(3)); - return 0; + return hleLogError(Log::Printf, 0, "UNIMPL fmt (%s, %08x, %08x, %08x)", format.c_str(), PARAM(1), PARAM(2), PARAM(3)); } static int sceKernelSetCompiledSdkVersion(int sdkVersion) { @@ -1243,10 +1208,9 @@ static int sceKernelSetCompiledSdkVersion(int sdkVersion) { WARN_LOG_REPORT(Log::sceKernel, "sceKernelSetCompiledSdkVersion unknown SDK: %x", sdkVersion); } - DEBUG_LOG(Log::sceKernel, "sceKernelSetCompiledSdkVersion(%08x)", sdkVersion); sdkVersion_ = sdkVersion; flags_ |= SCE_KERNEL_HASCOMPILEDSDKVERSION; - return 0; + return hleLogDebug(Log::sceKernel, 0); } static int sceKernelSetCompiledSdkVersion370(int sdkVersion) { @@ -1255,10 +1219,9 @@ static int sceKernelSetCompiledSdkVersion370(int sdkVersion) { WARN_LOG_REPORT(Log::sceKernel, "sceKernelSetCompiledSdkVersion370 unknown SDK: %x", sdkVersion); } - DEBUG_LOG(Log::sceKernel, "sceKernelSetCompiledSdkVersion370(%08x)", sdkVersion); sdkVersion_ = sdkVersion; flags_ |= SCE_KERNEL_HASCOMPILEDSDKVERSION; - return 0; + return hleLogDebug(Log::sceKernel, 0); } static int sceKernelSetCompiledSdkVersion380_390(int sdkVersion) { @@ -1269,10 +1232,9 @@ static int sceKernelSetCompiledSdkVersion380_390(int sdkVersion) { flags_ |= SCE_KERNEL_HASCOMPILEDSDKVERSION; } - DEBUG_LOG(Log::sceKernel, "sceKernelSetCompiledSdkVersion380_390(%08x)", sdkVersion); sdkVersion_ = sdkVersion; flags_ |= SCE_KERNEL_HASCOMPILEDSDKVERSION; - return 0; + return hleLogDebug(Log::sceKernel, 0); } static int sceKernelSetCompiledSdkVersion395(int sdkVersion) { @@ -1285,10 +1247,9 @@ static int sceKernelSetCompiledSdkVersion395(int sdkVersion) { WARN_LOG_REPORT(Log::sceKernel, "sceKernelSetCompiledSdkVersion395 unknown SDK: %x", sdkVersion); } - DEBUG_LOG(Log::sceKernel, "sceKernelSetCompiledSdkVersion395(%08x)", sdkVersion); sdkVersion_ = sdkVersion; flags_ |= SCE_KERNEL_HASCOMPILEDSDKVERSION; - return 0; + return hleLogDebug(Log::sceKernel, 0); } static int sceKernelSetCompiledSdkVersion600_602(int sdkVersion) { @@ -1299,10 +1260,9 @@ static int sceKernelSetCompiledSdkVersion600_602(int sdkVersion) { WARN_LOG_REPORT(Log::sceKernel, "sceKernelSetCompiledSdkVersion600_602 unknown SDK: %x", sdkVersion); } - DEBUG_LOG(Log::sceKernel, "sceKernelSetCompiledSdkVersion600_602(%08x)", sdkVersion); sdkVersion_ = sdkVersion; flags_ |= SCE_KERNEL_HASCOMPILEDSDKVERSION; - return 0; + return hleLogDebug(Log::sceKernel, 0); } static int sceKernelSetCompiledSdkVersion500_505(int sdkVersion) @@ -1313,10 +1273,9 @@ static int sceKernelSetCompiledSdkVersion500_505(int sdkVersion) WARN_LOG_REPORT(Log::sceKernel, "sceKernelSetCompiledSdkVersion500_505 unknown SDK: %x", sdkVersion); } - DEBUG_LOG(Log::sceKernel, "sceKernelSetCompiledSdkVersion500_505(%08x)", sdkVersion); sdkVersion_ = sdkVersion; flags_ |= SCE_KERNEL_HASCOMPILEDSDKVERSION; - return 0; + return hleLogDebug(Log::sceKernel, 0); } static int sceKernelSetCompiledSdkVersion401_402(int sdkVersion) { @@ -1326,10 +1285,9 @@ static int sceKernelSetCompiledSdkVersion401_402(int sdkVersion) { WARN_LOG_REPORT(Log::sceKernel, "sceKernelSetCompiledSdkVersion401_402 unknown SDK: %x", sdkVersion); } - DEBUG_LOG(Log::sceKernel, "sceKernelSetCompiledSdkVersion401_402(%08x)", sdkVersion); sdkVersion_ = sdkVersion; flags_ |= SCE_KERNEL_HASCOMPILEDSDKVERSION; - return 0; + return hleLogDebug(Log::sceKernel, 0); } static int sceKernelSetCompiledSdkVersion507(int sdkVersion) { @@ -1338,10 +1296,9 @@ static int sceKernelSetCompiledSdkVersion507(int sdkVersion) { WARN_LOG_REPORT(Log::sceKernel, "sceKernelSetCompiledSdkVersion507 unknown SDK: %x", sdkVersion); } - DEBUG_LOG(Log::sceKernel, "sceKernelSetCompiledSdkVersion507(%08x)", sdkVersion); sdkVersion_ = sdkVersion; flags_ |= SCE_KERNEL_HASCOMPILEDSDKVERSION; - return 0; + return hleLogDebug(Log::sceKernel, 0); } static int sceKernelSetCompiledSdkVersion603_605(int sdkVersion) { @@ -1352,10 +1309,9 @@ static int sceKernelSetCompiledSdkVersion603_605(int sdkVersion) { WARN_LOG_REPORT(Log::sceKernel, "sceKernelSetCompiledSdkVersion603_605 unknown SDK: %x", sdkVersion); } - DEBUG_LOG(Log::sceKernel, "sceKernelSetCompiledSdkVersion603_605(%08x)", sdkVersion); sdkVersion_ = sdkVersion; flags_ |= SCE_KERNEL_HASCOMPILEDSDKVERSION; - return 0; + return hleLogDebug(Log::sceKernel, 0); } static int sceKernelSetCompiledSdkVersion606(int sdkVersion) { @@ -1364,10 +1320,9 @@ static int sceKernelSetCompiledSdkVersion606(int sdkVersion) { ERROR_LOG_REPORT(Log::sceKernel, "sceKernelSetCompiledSdkVersion606 unknown SDK: %x (would crash)", sdkVersion); } - DEBUG_LOG(Log::sceKernel, "sceKernelSetCompiledSdkVersion606(%08x)", sdkVersion); sdkVersion_ = sdkVersion; flags_ |= SCE_KERNEL_HASCOMPILEDSDKVERSION; - return 0; + return hleLogDebug(Log::sceKernel, 0); } int sceKernelGetCompiledSdkVersion() { @@ -1377,10 +1332,9 @@ int sceKernelGetCompiledSdkVersion() { } static int sceKernelSetCompilerVersion(int version) { - DEBUG_LOG(Log::sceKernel, "sceKernelSetCompilerVersion(%08x)", version); compilerVersion_ = version; flags_ |= SCE_KERNEL_HASCOMPILERVERSION; - return 0; + return hleLogDebug(Log::sceKernel, 0); } KernelObject *__KernelMemoryFPLObject() diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 64efdc234e..57647190cc 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -2147,10 +2147,8 @@ u32 sceKernelLoadModule(const char *name, u32 flags, u32 optionAddr) { if (!module) { if (magic == 0x46535000) { - ERROR_LOG(Log::Loader, "Game tried to load an SFO as a module. Go figure? Magic = %08x", magic); // TODO: What's actually going on here? - error = -1; - return hleDelayResult(error, "module loaded", 500); + return hleDelayResult(hleLogError(Log::Loader, error, "Game tried to load an SFO as a module. Go figure? Magic = %08x", magic), "module loaded", 500); } PSPFileInfo info = pspFileSystem.GetFileInfo(name); @@ -2176,14 +2174,13 @@ u32 sceKernelLoadModule(const char *name, u32 flags, u32 optionAddr) { } // TODO: This is not the right timing and probably not the right wait type, just an approximation. - return hleDelayResult(module->GetUID(), "module loaded", 500); + return hleDelayResult(hleNoLog(module->GetUID()), "module loaded", 500); } static u32 sceKernelLoadModuleNpDrm(const char *name, u32 flags, u32 optionAddr) { - DEBUG_LOG(Log::Loader, "sceKernelLoadModuleNpDrm(%s, %08x)", name, flags); - - return sceKernelLoadModule(name, flags, optionAddr); + // TODO: Handle recursive syscall properly + return hleLogSuccessOrError(Log::Loader, sceKernelLoadModule(name, flags, optionAddr)); } int __KernelStartModule(SceUID moduleId, u32 argsize, u32 argAddr, u32 returnValueAddr, SceKernelSMOption *smoption, bool *needsWait) { @@ -2281,21 +2278,16 @@ static u32 sceKernelStopModule(u32 moduleId, u32 argSize, u32 argAddr, u32 retur PSPModule *module = kernelObjects.Get(moduleId, error); if (!module) { - ERROR_LOG(Log::sceModule, "sceKernelStopModule(%08x, %08x, %08x, %08x, %08x): invalid module id", moduleId, argSize, argAddr, returnValueAddr, optionAddr); - return error; + return hleLogError(Log::sceModule, error, "invalid module id"); } - if (module->isFake) - { - INFO_LOG(Log::sceModule, "sceKernelStopModule(%08x, %08x, %08x, %08x, %08x) - faking", moduleId, argSize, argAddr, returnValueAddr, optionAddr); + if (module->isFake) { if (returnValueAddr) Memory::Write_U32(0, returnValueAddr); - return 0; + return hleLogSuccessInfoI(Log::sceModule, 0, "faking"); } - if (module->nm.status != MODULE_STATUS_STARTED) - { - ERROR_LOG(Log::sceModule, "sceKernelStopModule(%08x, %08x, %08x, %08x, %08x): already stopped", moduleId, argSize, argAddr, returnValueAddr, optionAddr); - return SCE_KERNEL_ERROR_ALREADY_STOPPED; + if (module->nm.status != MODULE_STATUS_STARTED) { + return hleLogError(Log::sceModule, SCE_KERNEL_ERROR_ALREADY_STOPPED, "already stopped"); } u32 stopFunc = module->nm.module_stop_func; @@ -2336,32 +2328,29 @@ static u32 sceKernelStopModule(u32 moduleId, u32 argSize, u32 argAddr, u32 retur } else if (stopFunc == 0) { - INFO_LOG(Log::sceModule, "sceKernelStopModule(%08x, %08x, %08x, %08x, %08x): no stop func, skipping", moduleId, argSize, argAddr, returnValueAddr, optionAddr); module->nm.status = MODULE_STATUS_STOPPED; + return hleLogSuccessInfoI(Log::sceModule, 0, "no stop func, skipping"); } else { - ERROR_LOG_REPORT(Log::sceModule, "sceKernelStopModule(%08x, %08x, %08x, %08x, %08x): bad stop func address", moduleId, argSize, argAddr, returnValueAddr, optionAddr); module->nm.status = MODULE_STATUS_STOPPED; + return hleLogError(Log::sceModule, 0, "sceKernelStopModule(%08x, %08x, %08x, %08x, %08x): bad stop func address", moduleId, argSize, argAddr, returnValueAddr, optionAddr); } - - return 0; + return hleLogDebug(Log::sceModule, 0); } -static u32 sceKernelUnloadModule(u32 moduleId) -{ - INFO_LOG(Log::sceModule,"sceKernelUnloadModule(%i)", moduleId); +static u32 sceKernelUnloadModule(u32 moduleId) { u32 error; PSPModule *module = kernelObjects.Get(moduleId, error); if (!module) - return hleDelayResult(error, "module unloaded", 150); + return hleDelayResult(hleLogError(Log::sceModule, error), "module unloaded", 150); module->Cleanup(); kernelObjects.Destroy(moduleId); - return hleDelayResult(moduleId, "module unloaded", 500); + return hleDelayResult(hleLogDebug(Log::sceModule, moduleId), "module unloaded", 500); } -u32 hleKernelStopUnloadSelfModuleWithOrWithoutStatus(u32 exitCode, u32 argSize, u32 argp, u32 statusAddr, u32 optionAddr, bool WithStatus) { +u32 __KernelStopUnloadSelfModuleWithOrWithoutStatus(u32 exitCode, u32 argSize, u32 argp, u32 statusAddr, u32 optionAddr, bool WithStatus) { if (loadedModules.size() > 1) { if (WithStatus) { ERROR_LOG_REPORT(Log::sceModule, "UNIMPL sceKernelStopUnloadSelfModuleWithStatus(%08x, %08x, %08x, %08x, %08x): game may have crashed", exitCode, argSize, argp, statusAddr, optionAddr); @@ -2447,12 +2436,12 @@ u32 hleKernelStopUnloadSelfModuleWithOrWithoutStatus(u32 exitCode, u32 argSize, } static u32 sceKernelSelfStopUnloadModule(u32 exitCode, u32 argSize, u32 argp) { - // Used in Tom Clancy's Splinter Cell Essentials,Ghost in the Shell Stand Alone Complex - return hleKernelStopUnloadSelfModuleWithOrWithoutStatus(exitCode, argSize, argp, 0, 0, false); + // Used in Tom Clancy's Splinter Cell Essentials, Ghost in the Shell Stand Alone Complex + return __KernelStopUnloadSelfModuleWithOrWithoutStatus(exitCode, argSize, argp, 0, 0, false); } static u32 sceKernelStopUnloadSelfModuleWithStatus(u32 exitCode, u32 argSize, u32 argp, u32 statusAddr, u32 optionAddr) { - return hleKernelStopUnloadSelfModuleWithOrWithoutStatus(exitCode, argSize, argp, statusAddr, optionAddr, true); + return __KernelStopUnloadSelfModuleWithOrWithoutStatus(exitCode, argSize, argp, statusAddr, optionAddr, true); } void __KernelReturnFromModuleFunc() @@ -2526,11 +2515,11 @@ static u32 sceKernelGetModuleIdByAddress(u32 moduleAddr) state.result = SCE_KERNEL_ERROR_UNKNOWN_MODULE; kernelObjects.Iterate(&__GetModuleIdByAddressIterator, &state); - if (state.result == (SceUID)SCE_KERNEL_ERROR_UNKNOWN_MODULE) - ERROR_LOG(Log::sceModule, "sceKernelGetModuleIdByAddress(%08x): module not found", moduleAddr); - else - DEBUG_LOG(Log::sceModule, "%x=sceKernelGetModuleIdByAddress(%08x)", state.result, moduleAddr); - return state.result; + if (state.result == (SceUID)SCE_KERNEL_ERROR_UNKNOWN_MODULE) { + return hleLogError(Log::sceModule, state.result, "module not found at address"); + } else { + return hleLogSuccessOrError(Log::sceModule, state.result, "%08x", state.result); + } } static u32 sceKernelGetModuleId() @@ -2543,8 +2532,7 @@ u32 sceKernelFindModuleByUID(u32 uid) u32 error; PSPModule *module = kernelObjects.Get(uid, error); if (!module || module->isFake) { - ERROR_LOG(Log::sceModule, "0 = sceKernelFindModuleByUID(%d): Module Not Found or Fake", uid); - return 0; + return hleLogError(Log::sceModule, 0, "Module Not Found or Fake"); } return hleLogSuccessInfoI(Log::sceModule, module->modulePtr.ptr); } @@ -2567,8 +2555,7 @@ u32 sceKernelFindModuleByName(const char *name) } } } - WARN_LOG(Log::sceModule, "0 = sceKernelFindModuleByName(%s): Module Not Found", name); - return 0; + return hleLogWarning(Log::sceModule, 0, "Module Not Found", name); } static u32 sceKernelLoadModuleByID(u32 id, u32 flags, u32 lmoptionPtr) @@ -2576,8 +2563,7 @@ static u32 sceKernelLoadModuleByID(u32 id, u32 flags, u32 lmoptionPtr) u32 error; u32 handle = __IoGetFileHandleFromId(id, error); if (handle == (u32)-1) { - ERROR_LOG(Log::sceModule,"sceKernelLoadModuleByID(%08x, %08x, %08x): could not open file id",id,flags,lmoptionPtr); - return error; + return hleLogError(Log::sceModule, error, "couldn't open file"); } if (flags != 0) { WARN_LOG_REPORT(Log::Loader, "sceKernelLoadModuleByID: unsupported flags: %08x", flags); @@ -2602,8 +2588,7 @@ static u32 sceKernelLoadModuleByID(u32 id, u32 flags, u32 lmoptionPtr) // Some games try to load strange stuff as PARAM.SFO as modules and expect it to fail. // This checks for the SFO magic number. if (magic == 0x46535000) { - ERROR_LOG(Log::Loader, "Game tried to load an SFO as a module. Go figure? Magic = %08x", magic); - return error; + return hleLogError(Log::Loader, error, "Game tried to load an SFO as a module. Go figure? Magic = %08x", magic); } if ((int)error >= 0) @@ -2616,7 +2601,7 @@ static u32 sceKernelLoadModuleByID(u32 id, u32 flags, u32 lmoptionPtr) else { NOTICE_LOG(Log::Loader, "Module %d failed to load: %08x", id, error); - return error; + return hleLogError(Log::Loader, error); } } @@ -2628,7 +2613,7 @@ static u32 sceKernelLoadModuleByID(u32 id, u32 flags, u32 lmoptionPtr) INFO_LOG(Log::sceModule,"%i=sceKernelLoadModuleByID(%d,flag=%08x,(...))", module->GetUID(), id, flags); } - return module->GetUID(); + return hleNoLog(module->GetUID()); } static u32 sceKernelLoadModuleDNAS(const char *name, u32 flags) @@ -2692,11 +2677,11 @@ static u32 sceKernelQueryModuleInfo(u32 uid, u32 infoAddr) DEBUG_LOG(Log::sceModule, "sceKernelQueryModuleInfo(%i, %08x)", uid, infoAddr); u32 error; PSPModule *module = kernelObjects.Get(uid, error); - if (!module) + if (!module) { return error; + } if (!Memory::IsValidAddress(infoAddr)) { - ERROR_LOG(Log::sceModule, "sceKernelQueryModuleInfo(%i, %08x) - bad infoAddr", uid, infoAddr); - return -1; + return hleLogError(Log::sceModule, -1, "bad infoAddr"); } auto info = PSPPointer::Create(infoAddr); @@ -2720,7 +2705,7 @@ static u32 sceKernelQueryModuleInfo(u32 uid, u32 infoAddr) memcpy(info->name, module->nm.name, 28); } - return 0; + return hleNoLog(0); } static u32 sceKernelGetModuleIdList(u32 resultBuffer, u32 resultBufferSize, u32 idCountAddr) @@ -2744,7 +2729,7 @@ static u32 sceKernelGetModuleIdList(u32 resultBuffer, u32 resultBufferSize, u32 Memory::Write_U32(idCount, idCountAddr); - return 0; + return hleNoLog(0); } //fix for tiger x dragon diff --git a/Core/HLE/sceKernelModule.h b/Core/HLE/sceKernelModule.h index 6d358a60f2..5dadbc6a24 100644 --- a/Core/HLE/sceKernelModule.h +++ b/Core/HLE/sceKernelModule.h @@ -47,7 +47,7 @@ int __KernelGPUReplay(); void __KernelReturnFromModuleFunc(); SceUID KernelLoadModule(const std::string &filename, std::string *error_string); int __KernelStartModule(SceUID moduleId, u32 argsize, u32 argAddr, u32 returnValueAddr, SceKernelSMOption *smoption, bool *needsWait); -u32 hleKernelStopUnloadSelfModuleWithOrWithoutStatus(u32 exitCode, u32 argSize, u32 argp, u32 statusAddr, u32 optionAddr, bool WithStatus); +u32 __KernelStopUnloadSelfModuleWithOrWithoutStatus(u32 exitCode, u32 argSize, u32 argp, u32 statusAddr, u32 optionAddr, bool WithStatus); u32 sceKernelFindModuleByUID(u32 uid); void Register_ModuleMgrForUser(); diff --git a/Core/HLE/sceKernelMsgPipe.cpp b/Core/HLE/sceKernelMsgPipe.cpp index 63244b2a0b..0b4e6869d5 100644 --- a/Core/HLE/sceKernelMsgPipe.cpp +++ b/Core/HLE/sceKernelMsgPipe.cpp @@ -826,8 +826,7 @@ int sceKernelSendMsgPipeCB(SceUID uid, u32 sendBufAddr, u32 sendSize, u32 waitMo } MsgPipe *m = kernelObjects.Get(uid, error); if (!m) { - ERROR_LOG(Log::sceKernel, "sceKernelSendMsgPipeCB(%i) - ERROR %08x", uid, error); - return error; + return hleLogError(Log::sceKernel, error, "ERROR %08x, couldn't find msgpipe", error); } DEBUG_LOG(Log::sceKernel, "sceKernelSendMsgPipeCB(id=%i, addr=%08x, size=%i, mode=%i, result=%08x, timeout=%08x)", uid, sendBufAddr, sendSize, waitMode, resultAddr, timeoutPtr); @@ -844,8 +843,7 @@ int sceKernelTrySendMsgPipe(SceUID uid, u32 sendBufAddr, u32 sendSize, u32 waitM } MsgPipe *m = kernelObjects.Get(uid, error); if (!m) { - ERROR_LOG(Log::sceKernel, "sceKernelTrySendMsgPipe(%i) - ERROR %08x", uid, error); - return error; + return hleLogError(Log::sceKernel, error, "ERROR %08x, couldn't find msgpipe", error); } DEBUG_LOG(Log::sceKernel, "sceKernelTrySendMsgPipe(id=%i, addr=%08x, size=%i, mode=%i, result=%08x)", uid, sendBufAddr, sendSize, waitMode, resultAddr); diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index ba6c3fecd2..47baf6cf63 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -3633,9 +3633,8 @@ int sceKernelRegisterExitCallback(SceUID cbId) return 0; } - DEBUG_LOG(Log::sceKernel, "sceKernelRegisterExitCallback(%i)", cbId); registeredExitCbId = cbId; - return 0; + return hleLogDebug(Log::sceKernel, 0); } int LoadExecForUser_362A956B() @@ -3644,33 +3643,28 @@ int LoadExecForUser_362A956B() u32 error; PSPCallback *cb = kernelObjects.Get(registeredExitCbId, error); if (!cb) { - WARN_LOG(Log::sceKernel, "LoadExecForUser_362A956B() : registeredExitCbId not found 0x%x", registeredExitCbId); - return SCE_KERNEL_ERROR_UNKNOWN_CBID; + return hleLogWarning(Log::sceKernel, SCE_KERNEL_ERROR_UNKNOWN_CBID, "registeredExitCbId not found 0x%x", registeredExitCbId); } int cbArg = cb->nc.commonArgument; if (!Memory::IsValidAddress(cbArg)) { - WARN_LOG(Log::sceKernel, "LoadExecForUser_362A956B() : invalid address for cbArg (0x%08X)", cbArg); - return SCE_KERNEL_ERROR_ILLEGAL_ADDR; + return hleLogWarning(Log::sceKernel, SCE_KERNEL_ERROR_ILLEGAL_ADDR, "invalid address for cbArg (0x%08X)", cbArg); } u32 unknown1 = Memory::Read_U32(cbArg - 8); if (unknown1 >= 4) { - WARN_LOG(Log::sceKernel, "LoadExecForUser_362A956B() : invalid value unknown1 (0x%08X)", unknown1); - return SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT; + return hleLogWarning(Log::sceKernel, SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT, "invalid value unknown1 (0x%08X)", unknown1); } u32 parameterArea = Memory::Read_U32(cbArg - 4); if (!Memory::IsValidAddress(parameterArea)) { - WARN_LOG(Log::sceKernel, "LoadExecForUser_362A956B() : invalid address for parameterArea on userMemory (0x%08X)", parameterArea); - return SCE_KERNEL_ERROR_ILLEGAL_ADDR; + return hleLogWarning(Log::sceKernel, SCE_KERNEL_ERROR_ILLEGAL_ADDR, "invalid address for parameterArea on userMemory (0x%08X)", parameterArea); } u32 size = Memory::Read_U32(parameterArea); if (size < 12) { - WARN_LOG(Log::sceKernel, "LoadExecForUser_362A956B() : invalid parameterArea size %d", size); - return SCE_KERNEL_ERROR_ILLEGAL_SIZE; + return hleLogWarning(Log::sceKernel, SCE_KERNEL_ERROR_ILLEGAL_SIZE, "invalid parameterArea size %d", size); } Memory::Write_U32(0, parameterArea + 4); Memory::Write_U32(-1, parameterArea + 8); - return 0; + return hleLogDebug(Log::sceKernel, 0); } static const SceUID SCE_TE_THREADID_ALL_USER = 0xFFFFFFF0;