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
9 #include "irx_imports.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
;
26 u16 newflags
; /* For modload shipped with games. */
28 u16 flags
; /* I believe this is where flags are kept for BIOS versions. */
29 u32 entry
; /* _start */
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). */
44 return (smod_mod_info_t
*)0x800;
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
)))
63 *r_epc
= epc
- mod_info
->text_start
;
65 return mod_info
->name
;
72 static void excep_handler2(exception_frame_t
*frame
)
74 u32 r_epc
; // relative epc
77 u32
* buffer
= excep_buffer
;
79 module_name
= ExceptionGetModuleName(frame
->epc
, &r_epc
);
81 len
= strlen(module_name
);
84 buffer
[0] = 0x0d02beba; // reverse engineering..
87 memcpy(buffer
, frame
, BUFFER_SIZE
);
88 buffer
+= (sizeof(exception_frame_t
)/4);
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)
112 set_exception_handler(i
, excep_handler
);
114 for(i
=10; i
< 13; i
++)
115 set_exception_handler(i
, excep_handler
);