kdebugserver.c
2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "os.h"
#include "os_internal.h"
#include "rdb.h"
#include "R4300.h"
#ifdef BBPLAYER
#include <bcp.h>
#include <bbdebug.h>
#include <bbint.h>
#endif
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
OSThread __osThreadSave;
extern OSThread *__osRunningThread;
#ifndef _FINALROM
static u8 buffer[12];
static u32 numChars = 0;
extern u32 __osRdb_IP6_Empty;
static u32 string_to_u32(u8 *s)
{
u32 k;
k = (((u32) s[0]) & 0xff) << 24;
k |= (((u32) s[1]) & 0xff) << 16;
k |= (((u32) s[2]) & 0xff) << 8;
k |= ((u32) s[3]) & 0xff;
return k;
}
static void send_packet(u8 *s, u32 n)
{ /* 1 <= n <= 3 */
rdbPacket packet;
u32 i;
packet.type = RDB_TYPE_GtoH_KDEBUG;
packet.length = n;
for (i = 0; i < n; i++)
packet.buf[i] = s[i];
/* send out packet */
#ifdef BBPLAYER
if (__osBbIsBb) {
IDE_WRITE(IDE_RDB_RDATA_REG, *((u32 *) &packet)>>16);
IDE_WRITE(IDE_RDB_RDATA_REG+2, *((u32 *) &packet));
IDE_WRITE(IDE_RDB_CTRL_REG, IDE_RDB_CTRL_SET_BB_REQ);
} else
#endif
*((vu32 *) RDB_BASE_REG) = *((vu32 *) &packet);
}
static void clear_IP6(void)
{
#ifdef BBPLAYER
if (__osBbIsBb) {
while ((IO_READ(MI_EINTR_REG) & MI_INTR_IDE) == 0)
;/* do nothing */
IDE_WRITE(IDE_RDB_CTRL_REG, IDE_RDB_CTRL_CLR_HOST_ACK);
while ((IO_READ(MI_EINTR_REG) & MI_INTR_IDE) != 0)
;/* do nothing */
} else {
#endif
while ((__osGetCause() & CAUSE_IP6) == 0);
*((vu32 *) RDB_READ_INTR_REG) = 0;
while ((__osGetCause() & CAUSE_IP6) != 0);
#ifdef BBPLAYER
}
#endif
}
/*
* This send takes place within the exception handler, so you can't use the
* regular osSendRdb(). If exceptasm is waiting for an IP6, __osRdb_IP6_Empty
* will be FALSE. In this case, clear the IP6, send your data clearing all but
* the last IP6, which you want to leave around to replace the one you cleared
* at the start. If osRdb_IP6_Empty is TRUE, don't block for an IP6 at the start,
* go ahead sending your data, clearing each one, and also clear the last IP6
*/
static void send(u8 *s, u32 n)
{
u32 ct, i = 0;
u32 getLastIP6;
if (!__osRdb_IP6_Empty)
{
clear_IP6();
getLastIP6 = FALSE;
}
else
getLastIP6 = TRUE;
while(n > 0)
{
ct = MIN(n,3);
send_packet(&s[i], ct);
n -= ct;
i += ct;
if (n > 0) /* won't clear the last IP6 */
clear_IP6();
}
if(getLastIP6) /* should you get the last IP6 ? */
clear_IP6();
}
void kdebugserver(rdbPacket packet)
{
u32 i,length;
u8 *addr;
for (i = 0; i < 3; i++)
buffer[numChars++] = packet.buf[i];
if(buffer[0] == DEBUG_COMMAND_REGISTER)
{
/* send((u8*)&(__osThreadSave.context), sizeof(__OSThreadContext)); */
send((u8*)&(__osRunningThread->context), sizeof(__OSThreadContext));
numChars = 0;
}
else if((numChars >= 9) && buffer[0] == DEBUG_COMMAND_MEMORY)
{
addr = (u8*)string_to_u32(&buffer[1]);
length = string_to_u32(&buffer[5]);
send(addr,length);
numChars = 0;
}
}
#endif /*#ifndef _FINALROM */