From 1c2fdf5af82ef4dcb2444433e0b8cbc2d837bae5 Mon Sep 17 00:00:00 2001 From: Joost Peters Date: Wed, 28 Sep 2005 23:10:18 +0000 Subject: Make ScummVM run in usermode, install exception handler in kernelmode. svn-id: r18897 --- backends/psp/psp_main.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'backends/psp') diff --git a/backends/psp/psp_main.cpp b/backends/psp/psp_main.cpp index 0a4b8fa05d..89ad768941 100644 --- a/backends/psp/psp_main.cpp +++ b/backends/psp/psp_main.cpp @@ -37,10 +37,21 @@ #include #include "./trace.h" + +/** + * Define the module info section + * + * 2nd arg must 0x1000 so __init is executed in + * kernelmode for our loaderInit function + */ PSP_MODULE_INFO("SCUMMVM-PSP", 0x1000, 1, 1); -/* Define the main thread's attribute value (optional) */ -PSP_MAIN_THREAD_ATTR(/*THREAD_ATTR_USER | THREAD_ATTR_VFPU*/ 0); +/** + * THREAD_ATTR_USER causes the thread that the startup + * code (crt0.c) starts this program in to be in usermode + * even though the module was started in kernelmode + */ +PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU); /* global quit flag, this is used to let the VM engine shutdown properly */ bool g_quit = false; @@ -60,6 +71,16 @@ void MyExceptionHandler(PspDebugRegBlock *regs) { while (1) ; } +/** + * Function that is called from _init in kernelmode before the + * main thread is started in usermode. + */ +__attribute__ ((constructor)) +void loaderInit() { + pspKernelSetKernelPC(); + pspDebugInstallErrorHandler(MyExceptionHandler); +} + /* Exit callback */ SceKernelCallbackFunction exit_callback(int /*arg1*/, int /*arg2*/, void * /*common*/) { @@ -104,9 +125,6 @@ int main(void) //PSPDebugTrace("Setup callbacks\n"); SetupCallbacks(); - //install exception handler - pspDebugInstallErrorHandler(MyExceptionHandler); - //check if the save directory exists SceUID fd = sceIoDopen(SCUMMVM_SAVEPATH); if (fd < 0) { -- cgit v1.2.3