Add a "pedantic" self-check mode, improve logging some more.

This commit is contained in:
Henrik Rydgård committed 2025-01-20 12:20:21 +01:00
1 parent e24317b20b
commit 2b5b2a8fa5
5 files changed
+52 -81

No files matched your search

+4 -2
View File
@@ -736,7 +736,8 @@ static void CallSyscallWithFlags(const HLEFunction *info) {
info->func();
}
// Now, g_stackSize should be back to 0.
// 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)
@@ -759,7 +760,8 @@ static void CallSyscallWithoutFlags(const HLEFunction *info) {
info->func();
// Now, g_stackSize should be back to 0.
// 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)
+29 -52
View File
@@ -188,46 +188,37 @@ static u32 sceAudioChReserve(int chan, u32 sampleCount, u32 format) {
if (chan < 0) {
chan = GetFreeChannel();
if (chan < 0) {
ERROR_LOG(Log::sceAudio, "sceAudioChReserve - no channels remaining");
return SCE_ERROR_AUDIO_NO_CHANNELS_AVAILABLE;
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_NO_CHANNELS_AVAILABLE, "no channels remaining");
}
}
if ((u32)chan >= PSP_AUDIO_CHANNEL_MAX) {
ERROR_LOG(Log::sceAudio, "sceAudioChReserve(%08x, %08x, %08x) - bad channel", chan, sampleCount, format);
return SCE_ERROR_AUDIO_INVALID_CHANNEL;
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_INVALID_CHANNEL, "bad channel %d", chan);
}
if ((sampleCount & 63) != 0 || sampleCount == 0 || sampleCount > PSP_AUDIO_SAMPLE_MAX) {
ERROR_LOG(Log::sceAudio, "sceAudioChReserve(%08x, %08x, %08x) - invalid sample count", chan, sampleCount, format);
return SCE_ERROR_AUDIO_OUTPUT_SAMPLE_DATA_SIZE_NOT_ALIGNED;
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_OUTPUT_SAMPLE_DATA_SIZE_NOT_ALIGNED, "invalid sample count (not aligned)");
}
if (format != PSP_AUDIO_FORMAT_MONO && format != PSP_AUDIO_FORMAT_STEREO) {
ERROR_LOG(Log::sceAudio, "sceAudioChReserve(%08x, %08x, %08x) - invalid format", chan, sampleCount, format);
return SCE_ERROR_AUDIO_INVALID_FORMAT;
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_INVALID_FORMAT, "invalid format");
}
if (chans[chan].reserved) {
ERROR_LOG(Log::sceAudio, "sceAudioChReserve - reserve channel failed");
return SCE_ERROR_AUDIO_INVALID_CHANNEL;
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_INVALID_CHANNEL, "reserve channel failed");
}
DEBUG_LOG(Log::sceAudio, "sceAudioChReserve(%08x, %08x, %08x)", chan, sampleCount, format);
chans[chan].sampleCount = sampleCount;
chans[chan].format = format;
chans[chan].reserved = true;
chans[chan].leftVolume = 0;
chans[chan].rightVolume = 0;
return chan;
return hleLogDebug(Log::sceAudio, chan);
}
static u32 sceAudioChRelease(u32 chan) {
if (chan >= PSP_AUDIO_CHANNEL_MAX) {
ERROR_LOG(Log::sceAudio, "sceAudioChRelease(%i) - bad channel", chan);
return SCE_ERROR_AUDIO_INVALID_CHANNEL;
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_INVALID_CHANNEL, "bad channel %d", chan);
} else if (!chans[chan].reserved) {
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_CHANNEL_NOT_INIT, "channel %d not reserved", chan);
}
if (!chans[chan].reserved) {
ERROR_LOG(Log::sceAudio, "sceAudioChRelease(%i) - channel not reserved", chan);
return SCE_ERROR_AUDIO_CHANNEL_NOT_RESERVED;
}
// TODO: Does this error if busy?
chans[chan].reset();
chans[chan].reserved = false;
@@ -235,65 +226,51 @@ static u32 sceAudioChRelease(u32 chan) {
}
static u32 sceAudioSetChannelDataLen(u32 chan, u32 len) {
int result = 0;
if (chan >= PSP_AUDIO_CHANNEL_MAX) {
ERROR_LOG(Log::sceAudio, "sceAudioSetChannelDataLen(%08x, %08x) - bad channel", chan, len);
result = SCE_ERROR_AUDIO_INVALID_CHANNEL;
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_INVALID_CHANNEL, "bad channel %d", chan);
} else if (!chans[chan].reserved) {
ERROR_LOG(Log::sceAudio, "sceAudioSetChannelDataLen(%08x, %08x) - channel not reserved", chan, len);
result = SCE_ERROR_AUDIO_CHANNEL_NOT_INIT;
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_CHANNEL_NOT_INIT, "channel %d not reserved", chan);
} else if ((len & 63) != 0 || len == 0 || len > PSP_AUDIO_SAMPLE_MAX) {
ERROR_LOG(Log::sceAudio, "sceAudioSetChannelDataLen(%08x, %08x) - invalid sample count", chan, len);
result = SCE_ERROR_AUDIO_OUTPUT_SAMPLE_DATA_SIZE_NOT_ALIGNED;
} else {
chans[chan].sampleCount = len;
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_OUTPUT_SAMPLE_DATA_SIZE_NOT_ALIGNED, "invalid sample count");
}
DEBUG_LOG(Log::sceAudio, "%08x = sceAudioSetChannelDataLen(%08x, %08x)", result , chan, len);
return result;
chans[chan].sampleCount = len;
return hleLogDebug(Log::sceAudio, 0);
}
static u32 sceAudioChangeChannelConfig(u32 chan, u32 format) {
if (chan >= PSP_AUDIO_CHANNEL_MAX) {
ERROR_LOG(Log::sceAudio, "sceAudioChangeChannelConfig(%08x, %08x) - invalid channel number", chan, format);
return SCE_ERROR_AUDIO_INVALID_CHANNEL;
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_INVALID_CHANNEL, "invalid channel number %d", chan);
} else if (!chans[chan].reserved) {
ERROR_LOG(Log::sceAudio, "sceAudioChangeChannelConfig(%08x, %08x) - channel not reserved", chan, format);
return SCE_ERROR_AUDIO_CHANNEL_NOT_RESERVED;
} else {
DEBUG_LOG(Log::sceAudio, "sceAudioChangeChannelConfig(%08x, %08x)", chan, format);
chans[chan].format = format;
return 0;
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_CHANNEL_NOT_RESERVED, "channel %d not reserved", chan);
}
chans[chan].format = format;
return hleLogDebug(Log::sceAudio, 0);
}
static u32 sceAudioChangeChannelVolume(u32 chan, u32 leftvol, u32 rightvol) {
if (leftvol > 0xFFFF || rightvol > 0xFFFF) {
ERROR_LOG(Log::sceAudio, "sceAudioChangeChannelVolume(%08x, %08x, %08x) - invalid volume", chan, leftvol, rightvol);
return SCE_ERROR_AUDIO_INVALID_VOLUME;
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_INVALID_VOLUME, "invalid chan %d volume %d %d", chan, leftvol, rightvol);
} else if (chan >= PSP_AUDIO_CHANNEL_MAX) {
ERROR_LOG(Log::sceAudio, "sceAudioChangeChannelVolume(%08x, %08x, %08x) - invalid channel number", chan, leftvol, rightvol);
return SCE_ERROR_AUDIO_INVALID_CHANNEL;
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_INVALID_CHANNEL, "invalid channel %d", chan);
} else if (!chans[chan].reserved) {
ERROR_LOG(Log::sceAudio, "sceAudioChangeChannelVolume(%08x, %08x, %08x) - channel not reserved", chan, leftvol, rightvol);
return SCE_ERROR_AUDIO_CHANNEL_NOT_RESERVED;
} else {
DEBUG_LOG(Log::sceAudio, "sceAudioChangeChannelVolume(%08x, %08x, %08x)", chan, leftvol, rightvol);
chans[chan].leftVolume = leftvol;
chans[chan].rightVolume = rightvol;
return 0;
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_CHANNEL_NOT_RESERVED, "channel %d not reserved", chan);
}
chans[chan].leftVolume = leftvol;
chans[chan].rightVolume = rightvol;
return hleLogDebug(Log::sceAudio, 0);
}
static u32 sceAudioInit() {
DEBUG_LOG(Log::sceAudio, "sceAudioInit()");
// Don't need to do anything
return 0;
return hleLogDebug(Log::sceAudio, 0);
}
static u32 sceAudioEnd() {
DEBUG_LOG(Log::sceAudio, "sceAudioEnd()");
// Don't need to do anything
return 0;
return hleLogDebug(Log::sceAudio, 0);
}
static u32 sceAudioOutput2Reserve(u32 sampleCount) {
+6 -6
View File
@@ -390,14 +390,14 @@ u32 sceGeListEnQueueHead(u32 listAddress, u32 stallAddress, int callbackId, u32
}
hleEatCycles(480);
hleCoreTimingForceCheck();
return listID; // We already logged above, logs get confusing if we use hleLogSuccess.
return hleNoLog(listID); // We already logged above, logs get confusing if we use hleLogSuccess.
}
static int sceGeListDeQueue(u32 listID) {
WARN_LOG(Log::sceGe, "sceGeListDeQueue(%08x)", listID);
int result = gpu->DequeueList(LIST_ID_MAGIC ^ listID);
hleReSchedule("dlist dequeued");
return result;
return hleNoLog(result);
}
static int sceGeListUpdateStallAddr(u32 displayListID, u32 stallAddress) {
@@ -416,7 +416,7 @@ static int sceGeListUpdateStallAddr(u32 displayListID, u32 stallAddress) {
gpu->ProcessDLQueue();
}
}
return retval;
return hleNoLog(retval);
}
// 0 : wait for completion. 1:check and return
@@ -465,9 +465,9 @@ static int sceGeBreak(u32 mode, u32 unknownPtr) {
DEBUG_LOG(Log::sceGe, "sceGeBreak(mode=%d, unknown=%08x)", mode, unknownPtr);
int result = gpu->Break(mode);
if (result >= 0 && mode == 0) {
return LIST_ID_MAGIC ^ result;
return hleNoLog(LIST_ID_MAGIC ^ result);
}
return result;
return hleNoLog(result);
}
static u32 sceGeSetCallback(u32 structAddr) {
@@ -626,7 +626,7 @@ static u32 sceGeEdramSetAddrTranslation(u32 new_size) {
return hleLogError(Log::sceGe, -1, "GPUInterface not available");
}
return hleReportDebug(Log::sceGe, gpu->SetAddrTranslation(new_size));
return hleLogDebug(Log::sceGe, gpu->SetAddrTranslation(new_size));
}
const HLEFunction sceGe_user[] = {
+11 -17
View File
@@ -349,20 +349,15 @@ u32 sceKernelDevkitVersion()
int revision = firmwareVersion % 10;
int devkitVersion = (major << 24) | (minor << 16) | (revision << 8) | 0x10;
DEBUG_LOG(Log::sceKernel, "%08x=sceKernelDevkitVersion()", devkitVersion);
return devkitVersion;
return hleLogDebug(Log::sceKernel, devkitVersion, "%d.%d.%d", major, minor, revision);
}
u32 sceKernelRegisterKprintfHandler()
{
ERROR_LOG(Log::sceKernel, "UNIMPL sceKernelRegisterKprintfHandler()");
return 0;
u32 sceKernelRegisterKprintfHandler() {
return hleLogError(Log::sceKernel, 0, "UNIMPL");
}
int sceKernelRegisterDefaultExceptionHandler()
{
ERROR_LOG(Log::sceKernel, "UNIMPL sceKernelRegisterDefaultExceptionHandler()");
return 0;
int sceKernelRegisterDefaultExceptionHandler() {
return hleLogError(Log::sceKernel, 0, "UNIMPL");
}
void sceKernelSetGPO(u32 ledBits)
@@ -391,18 +386,18 @@ int sceKernelDcacheInvalidateRange(u32 addr, int size)
NOTICE_LOG(Log::CPU,"sceKernelDcacheInvalidateRange(%08x, %i)", addr, size);
#endif
if (size < 0 || (int) addr + size < 0)
return SCE_KERNEL_ERROR_ILLEGAL_ADDR;
return hleNoLog(SCE_KERNEL_ERROR_ILLEGAL_ADDR);
if (size > 0)
{
if ((addr % 64) != 0 || (size % 64) != 0)
return SCE_KERNEL_ERROR_CACHE_ALIGNMENT;
return hleNoLog(SCE_KERNEL_ERROR_CACHE_ALIGNMENT);
if (addr != 0)
gpu->InvalidateCache(addr, size, GPU_INVALIDATE_HINT);
}
hleEatCycles(190);
return 0;
return hleNoLog(0);
}
int sceKernelIcacheInvalidateRange(u32 addr, int size) {
@@ -462,7 +457,7 @@ int sceKernelDcacheWritebackInvalidateAll()
gpu->InvalidateCache(0, -1, GPU_INVALIDATE_ALL);
hleEatCycles(1165);
hleReSchedule("dcache invalidate all");
return 0;
return hleLogDebug(Log::CPU, 0, "Dcache invalidated");
}
u32 sceKernelIcacheInvalidateAll()
@@ -472,7 +467,7 @@ u32 sceKernelIcacheInvalidateAll()
#endif
// Note that this doesn't actually fully invalidate all with such a large range.
currentMIPS->InvalidateICache(0, 0x3FFFFFFF);
return 0;
return hleLogDebug(Log::CPU, 0, "Icache invalidated");
}
u32 sceKernelIcacheClearAll()
@@ -480,10 +475,9 @@ u32 sceKernelIcacheClearAll()
#ifdef LOG_CACHE
NOTICE_LOG(Log::CPU, "Icache cleared - should clear JIT someday");
#endif
DEBUG_LOG(Log::CPU, "Icache cleared - should clear JIT someday");
// Note that this doesn't actually fully invalidate all with such a large range.
currentMIPS->InvalidateICache(0, 0x3FFFFFFF);
return 0;
return hleLogDebug(Log::CPU, 0, "Icache cleared");
}
void KernelObject::GetQuickInfo(char *ptr, int size) {
+2 -4
View File
@@ -2415,11 +2415,9 @@ u32 __KernelGetCurThreadStackStart() {
return 0;
}
SceUID sceKernelGetThreadId()
{
VERBOSE_LOG(Log::sceKernel, "%i = sceKernelGetThreadId()", currentThread);
SceUID sceKernelGetThreadId() {
hleEatCycles(180);
return currentThread;
return hleLogVerbose(Log::sceKernel, currentThread);
}
int sceKernelGetThreadCurrentPriority() {