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)
51{
52 while(1)
53 {
54// printf("IOP: Controller thread going to sleep(%d)...\n", _iop_exception_state);
55 SleepThread();
56// printf("IOP: Controller thread woke up!\n");
57 soft_break();
58 }
59}
60
61void create_th(void)
62{
63 iop_thread_t param;
64
65 param.attr = TH_C;
66 param.thread = (void *) _controller_thread;
67 param.priority = 9; // highest possible priority
68 param.stacksize = 512; // tiny stack, not much is needed!
69 param.option = 0;
70
71 tid = CreateThread(&param);
72 StartThread(tid, 0);
73}
74
75extern void SBUS_dbg_init(void);
76
77int _start(int argc, char *argv[])
78{
79 int i;
80
81 (void)argc;
82 (void)argv;
83
84 for(i = 2; i <= 7; i++)
85 {
86 iop_dbg_set_handler(i, (IOP_ExceptionHandler *) _iop_ex_handler);
87 }
88
89 for(i = 9; i <= 15; i++)
90 {
91 iop_dbg_set_handler(i, (IOP_ExceptionHandler *) _iop_ex_handler);
92 }
93
94 create_th();
95
96 if(sbus_tty_init() != 0)
97 {
98 printf("Failed initializing SBUS TTY system!\n");
99 return MODULE_NO_RESIDENT_END;
100 }
101
102 SBUS_dbg_init();
103
104 FlushIcache();
105 FlushDcache();
106
107 printf("IOP SBUS Debug installed!\n");
108
109 return MODULE_RESIDENT_END;
110}
#define IOP_EXCEPTION_HDB
Definition excepman.h:58