From 52c36a8c6248e782802a1cc79dbdd829e8e080fe Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Sat, 24 Aug 2024 20:10:56 +0200 Subject: [PATCH] Update daedalus after latest gprof changes on the SDK --- Options.cmake | 2 + Source/HLEAudio/Plugin/PSP/AudioPluginPSP.cpp | 1 + Source/Input/SDL/InputManagerSDL.cpp | 4 - Source/SysPSP/Debug/CMakeLists.txt | 2 - Source/SysPSP/Debug/mcount.S | 60 ---- Source/SysPSP/Debug/prof.c | 274 ------------------ Source/SysPSP/Utility/exception.cpp | 15 +- Source/SysPSP/main.cpp | 7 - Source/UI/GlobalSettingsComponent.cpp | 4 +- Source/UI/RomSelectorComponent.cpp | 4 +- Source/UI/UIContext.h | 1 - 11 files changed, 14 insertions(+), 360 deletions(-) delete mode 100644 Source/SysPSP/Debug/mcount.S delete mode 100644 Source/SysPSP/Debug/prof.c diff --git a/Options.cmake b/Options.cmake index edcd7051a..a6879a62e 100644 --- a/Options.cmake +++ b/Options.cmake @@ -118,6 +118,8 @@ endif() if(DAEDALUS_PSP_GPROF) message("DAEDALUS_PSP_GPROF=ON") add_compile_definitions(DAEDALUS_PSP_GPROF) + add_compile_options(-pg) + add_link_options(-pg) endif() if(DAEDALUS_SIM_DOUBLES) diff --git a/Source/HLEAudio/Plugin/PSP/AudioPluginPSP.cpp b/Source/HLEAudio/Plugin/PSP/AudioPluginPSP.cpp index 6f04d5b18..18b28b140 100644 --- a/Source/HLEAudio/Plugin/PSP/AudioPluginPSP.cpp +++ b/Source/HLEAudio/Plugin/PSP/AudioPluginPSP.cpp @@ -84,6 +84,7 @@ bool InitialiseMediaEngine() else { printf("Media Engine already Initialised\n"); + return true; } } diff --git a/Source/Input/SDL/InputManagerSDL.cpp b/Source/Input/SDL/InputManagerSDL.cpp index 9983c776d..66f728b3b 100644 --- a/Source/Input/SDL/InputManagerSDL.cpp +++ b/Source/Input/SDL/InputManagerSDL.cpp @@ -444,8 +444,4 @@ v2 ApplyDeadzone( const v2 & in, f32 min_deadzone, f32 max_deadzone ) scale = std::clamp( scale, 0.0f, 1.0f ); return ProjectToUnitSquare( in * (scale / length) ); -} - -void sceKernelExitGame() { - // todo } \ No newline at end of file diff --git a/Source/SysPSP/Debug/CMakeLists.txt b/Source/SysPSP/Debug/CMakeLists.txt index 1060753c8..90dda5532 100644 --- a/Source/SysPSP/Debug/CMakeLists.txt +++ b/Source/SysPSP/Debug/CMakeLists.txt @@ -3,8 +3,6 @@ add_library(Debug_PSP OBJECT DBGConsolePSP.cpp ) - set (GPROF_SRCS SysPSP/Debug/prof.c SysPSP/Debug/mcount.S ) - list(APPEND daed_libs "Debug_PSP") set(daed_libs ${daed_libs} PARENT_SCOPE) diff --git a/Source/SysPSP/Debug/mcount.S b/Source/SysPSP/Debug/mcount.S deleted file mode 100644 index 9533cc15c..000000000 --- a/Source/SysPSP/Debug/mcount.S +++ /dev/null @@ -1,60 +0,0 @@ -.globl _mcount -.ent _mcount - -_mcount: - -.set noreorder -.set noat - - # generated code already substracts 8 bytes - # we store our ra, at and a0-a3 - addu $29, $29, -40 - sd $31, 0($29) # store ra - sd $1, 8($29) # at = ra of caller - sd $4, 16($29) - sd $5, 24($29) - sd $6, 32($29) - sd $7, 40($29) - - # make sure we're not recursively called when compiling __mcount() - # with -pg - la $4, _busy - lw $5, 0($4) - bnez $5, done - nop - - # mark busy - li $5, 1 - sw $5, 0($4) - - # call internal C handler - move $4, $1 - move $5, $31 - jal __mcount - nop - - # unmark busy - la $4, _busy - li $5, 0 - sw $5, 0($4) - - done: - - # restore registers - ld $31, 0($29) - ld $1, 8($29) - ld $4, 16($29) - ld $5, 24($29) - ld $6, 32($29) - ld $7, 40($29) - addu $29, $29, 48 # generated code substracts 8 bytes - j $31 - move $31, $1 # restore caller's ra - -_busy: - .space 4 - -.set reorder -.set at - .end _mcount - diff --git a/Source/SysPSP/Debug/prof.c b/Source/SysPSP/Debug/prof.c deleted file mode 100644 index add57f424..000000000 --- a/Source/SysPSP/Debug/prof.c +++ /dev/null @@ -1,274 +0,0 @@ -/* - * PSP Software Development Kit - http://www.pspdev.org - * ----------------------------------------------------------------------- - * Licensed under the BSD license, see LICENSE in PSPSDK root for details. - * - * main.c - Basic sample to demonstrate the profiler - * - * Copyright (c) 2005 urchin - * - * $Id: - */ -#include -#include -#include -#include -#include - - -#define DAEDALUS_PSP_GPROF - -#define GMON_PROF_ON 0 -#define GMON_PROF_BUSY 1 -#define GMON_PROF_ERROR 2 -#define GMON_PROF_OFF 3 - -#define GMONVERSION 0x00051879 - -#include - -/** gmon.out file header */ -struct gmonhdr -{ - char cookie[4]; - char version[4]; - char spare[3*4]; -}; - -struct gmonhisthdr -{ - int lpc; /* lowest pc address */ - int hpc; /* highest pc address */ - int ncnt; /* size of samples + size of header */ - int profrate; /* profiling clock rate */ - char dimension[15]; - char abbrev; -}; - -/** frompc -> selfpc graph */ -struct rawarc -{ - unsigned int frompc; - unsigned int selfpc; - unsigned int count; -}; - -/** context */ -struct gmonparam -{ - int state; - unsigned int lowpc; - unsigned int highpc; - unsigned int textsize; - unsigned int hashfraction; - - int narcs; - struct rawarc *arcs; - - int nsamples; - unsigned short int *samples; - - int timer; - - unsigned int pc; -}; - -/// holds context statistics -static struct gmonparam gp; - -/// one histogram per four bytes of text space -#define HISTFRACTION 4 - -/// define sample frequency - 1000 hz = 1ms -#define SAMPLE_FREQ 1000 - -/// have we allocated memory and registered already -static int initialized = 0; - -/// defined by linker -extern int _ftext; -extern int _etext; - -/* forward declarations */ -void gprof_cleanup(); -static SceUInt timer_handler(SceUID uid, SceKernelSysClock *c1, SceKernelSysClock *c2, void *common); - -/** Initializes pg library - - After calculating the text size, initialize() allocates enough - memory to allow fastest access to arc structures, and some more - for sampling statistics. Note that this also installs a timer that - runs at 1000 hert. -*/ -static void initialize() -{ - initialized = 1; - - memset(&gp, '\0', sizeof(gp)); - gp.state = GMON_PROF_ON; - gp.lowpc = (unsigned int)&_ftext; - gp.highpc = (unsigned int)&_etext; - gp.textsize = gp.highpc - gp.lowpc; - gp.hashfraction = HISTFRACTION; - - gp.narcs = (gp.textsize + gp.hashfraction - 1) / gp.hashfraction; - gp.arcs = (struct rawarc *)malloc(sizeof(struct rawarc) * gp.narcs); - if (gp.arcs == NULL) - { - gp.state = GMON_PROF_ERROR; - return; - } - - gp.nsamples = (gp.textsize + gp.hashfraction - 1) / gp.hashfraction; - gp.samples = (unsigned short int *)malloc(sizeof(unsigned short int) * gp.nsamples); - if (gp.samples == NULL) - { - free(gp.arcs); - gp.arcs = 0; - gp.state = GMON_PROF_ERROR; - return; - } - - memset((void *)gp.arcs, '\0', gp.narcs * (sizeof(struct rawarc))); - memset((void *)gp.samples, '\0', gp.nsamples * (sizeof(unsigned short int ))); - - gp.timer = sceKernelCreateVTimer("gprof timer", NULL); - - SceKernelSysClock sc; - sc.hi = 0; - sc.low = SAMPLE_FREQ; - - int thid = sceKernelGetThreadId(); - - SceKernelThreadInfo info; - info.size = sizeof(info); - int ret = sceKernelReferThreadStatus(thid, &info); - - if(ret == 0) - { - void* timer_addr = timer_handler; - if((info.attr & PSP_THREAD_ATTR_USER) == 0) - { - timer_addr += 0x80000000; - } - - ret = sceKernelSetVTimerHandler(gp.timer, &sc, timer_addr, NULL); - } - - if(ret == 0) - { - sceKernelStartVTimer(gp.timer); - } -} - -/** Writes gmon.out dump file and stops profiling - - Called from atexit() handler; will dump out a host:gmon.out file - with all collected information. -*/ -void gprof_cleanup() -{ - int i; - struct gmonhdr hdr; - struct gmonhisthdr histhdr; - - if (gp.state != GMON_PROF_ON) - { - /* profiling was disabled anyway */ - return; - } - - /* disable profiling before we make plenty of libc calls */ - gp.state = GMON_PROF_OFF; - - sceKernelStopVTimer(gp.timer); - - std::ofstream fp = fopen("gmon.out", std::ios::binary); - - memset(&hdr, 0x00, sizeof(hdr)); - memcpy(hdr.cookie, "gmon", 4); - hdr.version[0]=1; - fwrite(&hdr, 1, sizeof(hdr), fp); - - fputc(0x00, fp); /* GMON_TAG_TIME_HIST */ - memset(&histhdr, 0x00, sizeof(histhdr)); - histhdr.lpc = gp.lowpc - gp.lowpc; - histhdr.hpc = gp.highpc - gp.lowpc; - histhdr.ncnt = gp.nsamples; - histhdr.profrate = SAMPLE_FREQ; - strcpy(histhdr.dimension, "seconds"); - histhdr.abbrev = 's'; - fwrite(&histhdr, 1, sizeof(histhdr), fp); - fwrite(gp.samples, gp.nsamples, sizeof(unsigned short int), fp); - - - for (i=0; i 0) - { - fputc(0x01, fp); /* GMON_TAG_CG_ARC */ - fwrite(gp.arcs + i, sizeof(struct rawarc), 1, fp); - } - } - - fclose(fp); -} - -/** Internal C handler for _mcount() - @param frompc pc address of caller - @param selfpc pc address of current function - - Called from mcount.S to make life a bit easier. __mcount is called - right before a function starts. GCC generates a tiny stub at the very - beginning of each compiled routine, which eventually brings the - control to here. -*/ -void __mcount(unsigned int frompc, unsigned int selfpc) -{ - int e; - struct rawarc *arc; - - if (initialized == 0) - { - initialize(); - } - - if (gp.state != GMON_PROF_ON) - { - /* returned off for some reason */ - return; - } - - frompc = frompc & 0x0FFFFFFF; - selfpc = selfpc & 0x0FFFFFFF; - - /* call might come from stack */ - if (frompc >= gp.lowpc && frompc <= gp.highpc) - { - gp.pc = selfpc; - e = (frompc - gp.lowpc) / gp.hashfraction; - arc = gp.arcs + e; - arc->frompc = frompc - gp.lowpc; - arc->selfpc = selfpc - gp.lowpc; - arc->count++; - } -} - -/** Internal timer handler -*/ -static SceUInt timer_handler(SceUID uid, SceKernelSysClock *requested, SceKernelSysClock *actual, void *common) -{ - unsigned int frompc = gp.pc; - - if (gp.state == GMON_PROF_ON) - { - /* call might come from stack */ - if (frompc >= gp.lowpc && frompc <= gp.highpc) - { - int e = (frompc - gp.lowpc) / gp.hashfraction; - gp.samples[e]++; - } - } - - return SAMPLE_FREQ; -} diff --git a/Source/SysPSP/Utility/exception.cpp b/Source/SysPSP/Utility/exception.cpp index 49bbdec5c..a45cacc6d 100644 --- a/Source/SysPSP/Utility/exception.cpp +++ b/Source/SysPSP/Utility/exception.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -176,7 +177,7 @@ void ExceptionHandler(PspDebugRegBlock * regs) const u32 RDRAM_base {(u32)g_pu8RamBase}; const u32 RDRAM_end {(u32)g_pu8RamBase + 8 * 1024 * 1024 - 1}; SceCtrlData pad; - bool exit {false}; + bool mustExit {false}; pspDebugScreenInit(); pspDebugScreenSetBackColor(0x00FF0000); @@ -190,7 +191,7 @@ void ExceptionHandler(PspDebugRegBlock * regs) u32 scroll_epc {(u32)regs->epc}; #endif - while( !exit ) + while( !mustExit ) { pspDebugScreenClear(); pspDebugScreenPrintf("Exception[%s] RDRAM[%08X:%08X]\n\n", codeTxt[(regs->cause >> 2) & 31], (int)RDRAM_base, (int)RDRAM_end ); @@ -244,12 +245,12 @@ void ExceptionHandler(PspDebugRegBlock * regs) if (pad.Buttons & PSP_CTRL_CROSS) { DumpInformation(regs); - exit = true; + mustExit = true; update = true; } else if (pad.Buttons & PSP_CTRL_CIRCLE) { - exit = true; + mustExit = true; update = true; } else if (pad.Buttons & PSP_CTRL_UP) @@ -274,12 +275,12 @@ void ExceptionHandler(PspDebugRegBlock * regs) if (pad.Buttons & PSP_CTRL_CROSS) { DumpInformation(regs); - exit = true; + mustExit = true; update = true; } else if (pad.Buttons & PSP_CTRL_CIRCLE) { - exit = true; + mustExit = true; update = true; } } @@ -287,7 +288,7 @@ void ExceptionHandler(PspDebugRegBlock * regs) } - sceKernelExitGame(); + exit(1); } void initExceptionHandler() diff --git a/Source/SysPSP/main.cpp b/Source/SysPSP/main.cpp index 6f0f3e223..5c8db8ccb 100644 --- a/Source/SysPSP/main.cpp +++ b/Source/SysPSP/main.cpp @@ -86,11 +86,6 @@ extern "C" /* Video Manager functions */ int pspDveMgrCheckVideoOut(); int pspDveMgrSetVideoOut(int, int, int, int, int, int, int); - -#ifdef DAEDALUS_PSP_GPROF - /* Profile with psp-gprof */ - void gprof_cleanup(); -#endif } /* Kernel Exception Handler functions */ @@ -239,7 +234,6 @@ int main(int argc, char* argv[]) CPU_Run(); System_Close(); System_Finalize(); - sceKernelExitGame(); return 0; } #endif @@ -260,6 +254,5 @@ int main(int argc, char* argv[]) System_Finalize(); } - sceKernelExitGame(); return 0; } diff --git a/Source/UI/GlobalSettingsComponent.cpp b/Source/UI/GlobalSettingsComponent.cpp index e081529da..80c433689 100644 --- a/Source/UI/GlobalSettingsComponent.cpp +++ b/Source/UI/GlobalSettingsComponent.cpp @@ -182,7 +182,7 @@ namespace gShowDialog->Render( mpContext,"Daedalus will exit now",true); - sceKernelExitGame(); + exit(0); } } if(gShowDialog->Render( mpContext,"Reset settings?", false) ) @@ -194,7 +194,7 @@ namespace gShowDialog->Render( mpContext,"Daedalus will exit now",true); - sceKernelExitGame(); + exit(0); } } diff --git a/Source/UI/RomSelectorComponent.cpp b/Source/UI/RomSelectorComponent.cpp index 2bc0ec216..37b8470eb 100644 --- a/Source/UI/RomSelectorComponent.cpp +++ b/Source/UI/RomSelectorComponent.cpp @@ -562,12 +562,10 @@ void IRomSelectorComponent::Update( float elapsed_time, const v2 & stick, u32 ol mCurrentSelection++; } } -#ifndef DAEDALUS_PSP_GPROF if(new_buttons & PSP_CTRL_SELECT) { - sceKernelExitGame(); + exit(0); } -#endif if(new_buttons & PSP_CTRL_CROSS && mRomDelete) // DONT CHANGE ORDER { remove( mSelectedRom.c_str() ); diff --git a/Source/UI/UIContext.h b/Source/UI/UIContext.h index f1a63b850..ec829400c 100644 --- a/Source/UI/UIContext.h +++ b/Source/UI/UIContext.h @@ -140,7 +140,6 @@ class CUIContext }; void sceCtrlPeekBufferPositive(struct SceCtrlData*, int n); - void sceKernelExitGame(); #endif //##########################################################################################################