PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
sbus_dbg.c
1#include <tamtypes.h>
2#include <stdio.h>
3#include <stdarg.h>
4#include <sysclib.h>
5#include <sysmem.h>
6#include <excepman.h>
7#include <intrman.h>
8#include <loadcore.h>
9#include <thbase.h>
10#include <ioman.h>
11#include <ps2_debug.h>
12#include <ps2_sbus.h>
13
14#include "iopdebug.h"
15
16#define SIF2_CMD_DBG_PUTS (1)
17#define SIF2_CMD_DBG_EXC (2)
18#define SIF2_CMD_DBG_CTRL (3)
19
20extern int _iop_exception_state;
21
22static IOP_RegFrame *_iop_ex_def_frame;
23static IOP_RegFrame *_iop_ex_dbg_frame;
24
26{
27 u32 mode; // 0 = update register frame and release, 1 = control
28 IOP_RegFrame reg_frame;
30
31extern int _iop_controlled;
32
33// send a string to EE for output.
34void sbus_tty_puts(const char *str)
35{
36 SIF2_send_cmd(SIF2_CMD_DBG_PUTS, (void *) str, strlen(str) + 1);
37}
38
39void signal_iop_exception(IOP_RegFrame *frame)
40{
41 SIF2_send_cmd(SIF2_CMD_DBG_EXC, (void *) frame, sizeof(IOP_RegFrame));
42}
43
44extern int tid;
45
46void _sif2_cmd_dbg_control(SIF2_CmdPkt *cmd, void *param)
47{
49
50 (void)param;
51
52 params = (SBUS_ControlCPU_Params *) ((((u32) cmd) + sizeof(SIF2_CmdPkt)) | 0x00000000);
53
54 if(params->mode == 1)
55 {
56 // wake up the controller thread.
57 iWakeupThread(tid);
58 }
59 else
60 {
61 IOP_RegFrame *frame;
62
63 if(_iop_exception_state == 0) { return; }
64
65 if(_iop_exception_state == 1) { frame = _iop_ex_def_frame; }
66 else { frame = _iop_ex_dbg_frame; }
67
68 // update the register frame and release the CPU.
69 memcpy(frame, &params->reg_frame, sizeof(IOP_RegFrame));
70
71 FlushIcache();
72 FlushDcache();
73
74 _iop_exception_state = 0;
75 _iop_controlled = 0;
76 }
77}
78
79void SBUS_dbg_init(void)
80{
81 iop_dbg_get_reg_frames(&_iop_ex_def_frame, &_iop_ex_dbg_frame);
82 SIF2_set_cmd_handler(SIF2_CMD_DBG_CTRL, &_sif2_cmd_dbg_control, NULL);
83}