Disabling auto-refresh of game list by default, as it is causing bugs sometimes
[open-ps2-loader/simon.git] / modules / debug / ps2link / excepHandler.c
bloba5b880c22c9df9fc3f91ae323429a5baf4de2760
1 /*********************************************************************
2 * Copyright (C) 2004 Lukasz Bruun (mail@lukasz.dk)
3 * This file is subject to the terms and conditions of the PS2Link License.
4 * See the file LICENSE in the main directory of this distribution for more
5 * details.
6 */
8 #include <tamtypes.h>
9 #include "irx_imports.h"
10 #include "hostlink.h"
12 #define BUFFER_SIZE sizeof(exception_frame_t)+4+4+128
14 u32 excep_buffer[BUFFER_SIZE/4] __attribute__ ((aligned(16)));
16 extern unsigned int pkoSendSifCmd(unsigned int cmd, void *src, unsigned int len); // lazy fix :)
17 extern int excepscrdump;
19 // taken from smod by mrbrown, only use one function, didn't wanna include another irx.
21 /* Module info entry. */
22 typedef struct _smod_mod_info {
23 struct _smod_mod_info *next;
24 u8 *name;
25 u16 version;
26 u16 newflags; /* For modload shipped with games. */
27 u16 id;
28 u16 flags; /* I believe this is where flags are kept for BIOS versions. */
29 u32 entry; /* _start */
30 u32 gp;
31 u32 text_start;
32 u32 text_size;
33 u32 data_size;
34 u32 bss_size;
35 u32 unused1;
36 u32 unused2;
37 } smod_mod_info_t;
40 smod_mod_info_t *smod_get_next_mod(smod_mod_info_t *cur_mod)
42 /* If cur_mod is 0, return the head of the list (IOP address 0x800). */
43 if (!cur_mod) {
44 return (smod_mod_info_t *)0x800;
45 } else {
46 if (!cur_mod->next)
47 return 0;
48 else
49 return cur_mod->next;
51 return 0;
54 char* ExceptionGetModuleName(u32 epc, u32* r_epc)
56 smod_mod_info_t *mod_info = 0;
58 while((mod_info = smod_get_next_mod(mod_info)) != 0)
60 if((epc >= mod_info->text_start) && (epc <= (mod_info->text_start+mod_info->text_size)))
62 if(r_epc)
63 *r_epc = epc - mod_info->text_start;
65 return mod_info->name;
69 return 0;
72 static void excep_handler2(exception_frame_t *frame)
74 u32 r_epc; // relative epc
75 char *module_name;
76 u32 len;
77 u32* buffer = excep_buffer;
79 module_name = ExceptionGetModuleName(frame->epc, &r_epc);
81 len = strlen(module_name);
84 buffer[0] = 0x0d02beba; // reverse engineering..
85 buffer++;
87 memcpy(buffer, frame, BUFFER_SIZE);
88 buffer+= (sizeof(exception_frame_t)/4);
90 buffer[0] = r_epc;
91 buffer[1] = len;
92 buffer+=2;
93 memcpy(buffer, module_name, len+1);
95 pkoSendSifCmd(PKO_RPC_IOPEXCEP, excep_buffer, BUFFER_SIZE);
99 static void excep_handler(exception_type_t type, exception_frame_t *frame)
101 excep_handler2(frame); // Don't know why this works, but keeps iop alive.
105 ////////////////////////////////////////////////////////////////////////
106 // Installs iop exception handlers for the 'usual' exceptions..
107 void installExceptionHandlers(void)
109 s32 i;
111 for(i=1; i < 8; i++)
112 set_exception_handler(i, excep_handler);
114 for(i=10; i < 13; i++)
115 set_exception_handler(i, excep_handler);