PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
main.c
1#include <tamtypes.h>
2#include <stdio.h>
3#include <loadcore.h>
4#include <thbase.h>
5#include <iop_cop0_defs.h>
6#include <ps2_sbus.h>
7#include <iopdebug.h>
8#include <excepman.h>
9#include "sbus_tty.h"
10
11IRX_ID("sbusdebug", 1, 0);
12
13volatile int _iop_controlled = 0;
14volatile int _iop_exception_state = 0;
15
16extern void signal_iop_exception(IOP_RegFrame *frame);
17
18// this is called by the IOP debug/exception handler
19void _iop_ex_handler(IOP_RegFrame *frame)
20{
21 int excode = M_IOP_GET_CAUSE_EXCODE(frame->cause);
22
23 if(excode == IOP_EXCEPTION_HDB)
24 {
25 _iop_exception_state = 2;
26 }
27 else
28 {
29 _iop_exception_state = 1;
30 }
31
32 _iop_controlled = 1;
33
34 // signal to the EE that an IOP exception occured.
35 signal_iop_exception(frame);
36
37 // wait for EE to send a "IOP control" command and release the IOP.
38 while(_iop_controlled)
39 {
40 // since we're spinning in an interrupt-disabled state, we have to manually
41 // poll for SBUS interrupts from EE, otherwise we'll never get released!
42 SBUS_check_intr();
43 }
44}
45
46int tid;
47
48extern void soft_break(void);
49
50void _controller_thread(void *arg)
51{
52 (void)arg;
53
54 while(1)
55 {
56// printf("IOP: Controller thread going to sleep(%d)...\n", _iop_exception_state);
57 SleepThread();
58// printf("IOP: Controller thread woke up!\n");
59 soft_break();
60 }
61}
62
63void create_th(void)
64{
65 iop_thread_t param;
66
67 param.attr = TH_C;
68 param.thread = _controller_thread;
69 param.priority = 9; // highest possible priority
70 param.stacksize = 512; // tiny stack, not much is needed!
71 param.option = 0;
72
73 tid = CreateThread(&param);
74 StartThread(tid, 0);
75}
76
77extern void SBUS_dbg_init(void);
78
79int _start(int argc, char *argv[])
80{
81 int i;
82
83 (void)argc;
84 (void)argv;
85
86 for(i = 2; i <= 7; i++)
87 {
88 iop_dbg_set_handler(i, (IOP_ExceptionHandler *) _iop_ex_handler);
89 }
90
91 for(i = 9; i <= 15; i++)
92 {
93 iop_dbg_set_handler(i, (IOP_ExceptionHandler *) _iop_ex_handler);
94 }
95
96 create_th();
97
98 if(sbus_tty_init() != 0)
99 {
100 printf("Failed initializing SBUS TTY system!\n");
101 return MODULE_NO_RESIDENT_END;
102 }
103
104 SBUS_dbg_init();
105
106 FlushIcache();
107 FlushDcache();
108
109 printf("IOP SBUS Debug installed!\n");
110
111 return MODULE_RESIDENT_END;
112}
#define IOP_EXCEPTION_HDB
Definition excepman.h:58