 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
jojojoris
Joined: 30 Mar 2008 Posts: 261
|
Posted: Wed Nov 04, 2009 2:43 am Post subject: Global Exception handler plugin |
|
|
Hello everyone,
I want to have a plugin which can show a BSOD-like screen when the psp crashes just like windows XP
I tried to write some plugin which load the exception.prx but it seems the exception.prx from sakya can only monitor the module which loaded it.
main.c
| Code: | #include <pspkernel.h>
#include <pspdebug.h>
#include "../utility/exception.h"
PSP_MODULE_INFO("pspBSOD_plugin", 0, 1, 0);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
int module_start(SceSize args, void *argp)
{
initExceptionHandler();
return 0;
} |
exception.c
| Code: | #include <pspkernel.h>
#include <pspsdk.h>
#include <pspctrl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
PspDebugRegBlock exception_regs;
extern SceModule module_info;
extern int _ftext;
static const char *codeTxt[32] ={
"Interrupt", "TLB modification", "TLB load/inst fetch", "TLB store",
"Address load/inst fetch", "Address store", "Bus error (instr)",
"Bus error (data)", "Syscall", "Breakpoint", "Reserved instruction",
"Coprocessor unusable", "Arithmetic overflow", "Unknown 13", "Unknown 14",
"FPU Exception", "Unknown 16", "Unknown 17", "Unknown 18",
"Unknown 20", "Unknown 21", "Unknown 22", "Unknown 23",
"Unknown 24", "Unknown 25", "Unknown 26", "Unknown 27",
"Unknown 28", "Unknown 29", "Unknown 30", "Unknown 31"
};
static const unsigned char regName[32][5] ={
"zr", "at", "v0", "v1", "a0", "a1", "a2", "a3",
"t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
"s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
"t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra"
};
void ExceptionHandler(PspDebugRegBlock * regs) {
int i;
SceCtrlData pad;
pspDebugScreenInit();
pspDebugScreenSetBackColor(0x00FF0000);
pspDebugScreenSetTextColor(0xFFFFFFFF);
pspDebugScreenClear();
pspDebugScreenPrintf(" A problem has been detected and your psp has been stopped.\n");
pspDebugScreenPrintf("\n");
pspDebugScreenPrintf(" The problem seems to be caused by the following module:\n %s\n", module_info.modname);
pspDebugScreenPrintf("\n");
pspDebugScreenPrintf(" If this is the first time you've seen this Stop error screen, you\n can restart the game. If this screen appears again, you can contact the developer to tell about this bug.\n");
pspDebugScreenPrintf("\n");
pspDebugScreenPrintf(" Technical information:\n\n");
pspDebugScreenPrintf(" Exception - %s\n", codeTxt[(regs->cause >> 2) & 31]);
pspDebugScreenPrintf(" EPC - %08X\n", (int) regs->epc);
pspDebugScreenPrintf(" Module - %s\n", module_info.modname);
pspDebugScreenPrintf(" ModuleAddr- %08X\n", (unsigned int) (regs->epc - (int) & _ftext));
pspDebugScreenPrintf(" Cause - %08X\n", (int) regs->cause);
pspDebugScreenPrintf(" Status - %08X\n", (int) regs->status);
pspDebugScreenPrintf(" BadVAddr - %08X\n", (int) regs->badvaddr);
for (i = 0; i < 32; i += 4) pspDebugScreenPrintf(" %s:%08X %s:%08X %s:%08X %s:%08X\n", regName[i], (int) regs->r[i], regName[i + 1], (int) regs->r[i + 1], regName[i + 2], (int) regs->r[i + 2], regName[i + 3], (int) regs->r[i + 3]);
sceKernelDelayThread(1000000);
pspDebugScreenPrintf("\n Press CIRCLE to try to go back to the XMB");
for (;;) {
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_CIRCLE) {
break;
}
sceKernelDelayThread(100000);
}
sceKernelExitGame();
}
void initExceptionHandler() {
SceKernelLMOption option;
int args[2], fd, modid;
memset(&option, 0, sizeof (option));
option.size = sizeof (option);
option.mpidtext = PSP_MEMORY_PARTITION_KERNEL;
option.mpiddata = PSP_MEMORY_PARTITION_KERNEL;
option.position = 0;
option.access = 1;
if ((modid = sceKernelLoadModule("exception.prx", 0, &option)) >= 0) {
args[0] = (int) ExceptionHandler;
args[1] = (int) & exception_regs;
sceKernelStartModule(modid, 8, args, &fd, NULL);
}
}
|
| Code: | TARGET = bsodplugin
OBJS = ../utility/exception.o main.o
#To build for custom firmware:
BUILD_PRX = 1
#CFLAGS = -O3 -G0 -Wall
CFLAGS = -O3 -frename-registers -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LIBS =
LDFLAGS =
#PSP_EBOOT_ICON = ICON0.PNG
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build_prx.mak |
the exception.prx is the same as the one from sakya.
Why doesn't give this a nice BSOD on all crashes? (in this prx form it doesn't give any BSOD) _________________
| Code: | int main(){
SetupCallbacks();
makeNiceGame();
sceKernelExitGame();
} |
|
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Wed Nov 04, 2009 6:19 am Post subject: |
|
|
| initExceptionHandler() is loading and starting the prx, but your module_start() is calling initExceptionHandler() making it recursive. Instead, initExceptionHandler() should be setting the exception vector, not loading the already loaded module. |
|
| Back to top |
|
 |
jojojoris
Joined: 30 Mar 2008 Posts: 261
|
Posted: Wed Nov 04, 2009 11:55 pm Post subject: |
|
|
maybe i don't understand you but i already have 2 prxes. bsodplugin.prx should be the one which load the exception.prx. the source is the source of bsodplugin.prx
and what do you mean with exception vector? _________________
| Code: | int main(){
SetupCallbacks();
makeNiceGame();
sceKernelExitGame();
} |
|
|
| Back to top |
|
 |
a_noob
Joined: 17 Sep 2006 Posts: 97 Location: _start: jr 0xDEADBEEF
|
Posted: Thu Nov 05, 2009 12:50 am Post subject: |
|
|
THis has been done before, but not quite as a plugin I don't think, in pspradio and many other apps. The functions you need are already coded for you.
int pspDebugInstallErrorHandler (PspDebugErrorHandler handler)
Install an error handler to catch unhandled exceptions.
void pspDebugDumpException (PspDebugRegBlock *regs)
Dump an exception to screen using the pspDebugScreen functions.
all of the debug library docu is here http://psp.jim.sh/pspsdk-doc/group__Debug.html
So your code becomes greatly simplified, all you do is install a error handler and have that in turn call pspDebugDumpException, personally I would also have it write the exception to a file, so you can more easily send it to a developer. This will print all the registers along with the section that caused the error and the bad addr etc, can be quite helpfull. _________________
| Code: | .øOº'ºOø.
'ºOo.oOº' |
|
|
| Back to top |
|
 |
jojojoris
Joined: 30 Mar 2008 Posts: 261
|
Posted: Thu Nov 05, 2009 7:05 am Post subject: |
|
|
Thanks i will try that out.
I want it in the screen because the windows BSOD is cool.
EDIT:
wasn't pspDebugInstallErrorHandler kernel 1.50 only??? _________________
| Code: | int main(){
SetupCallbacks();
makeNiceGame();
sceKernelExitGame();
} |
|
|
| Back to top |
|
 |
a_noob
Joined: 17 Sep 2006 Posts: 97 Location: _start: jr 0xDEADBEEF
|
Posted: Thu Nov 05, 2009 9:12 am Post subject: |
|
|
| jojojoris wrote: | I want it in the screen because the windows BSOD is cool.
|
I'll take some of whatever you are smoking.
Also im not sure if its 1.50 only. Its possible. _________________
| Code: | .øOº'ºOø.
'ºOo.oOº' |
|
|
| Back to top |
|
 |
sakya
Joined: 28 Apr 2006 Posts: 190
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|