-
Notifications
You must be signed in to change notification settings - Fork 19
/
cmd.c
277 lines (232 loc) · 8.64 KB
/
cmd.c
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
* Demul
* Copyright (C) 2006 Org, Demul Team
*
* Demul is not free software: you can't redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Demul isn't distributed in the hope that it will be useful,
* and WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
// Console commands. EXCLUDE THIS FILE FROM THE BUILD!
DebugCmd cmd_list[];
int cmd_num;
// ---------------------------------------------------------------------------
// .
static void cmd_dot(void) {
db_set_disa_cur(sh4.pc);
db_update(DB_UPDATE_DISA);
}
// ---------------------------------------------------------------------------
// db
static void cmd_db(void) {
if (tokencount <= 1) {
Printf("Current memory view address: 0x%08X\n", wind.data);
return;
}
wind.data = db_convert_expression(tokens[1]);
db_update(DB_UPDATE_DATA);
}
// ---------------------------------------------------------------------------
// u
static void cmd_u(void) {
if (tokencount <= 1) {
Printf("Current CPU view address: 0x%08X\n", wind.disa_cursor);
return;
}
db_set_disa_cur(db_convert_expression(tokens[1]));
db_update(DB_UPDATE_DISA);
}
// ---------------------------------------------------------------------------
// pc
static void cmd_pc(void) {
if (tokencount > 1)
sh4.pc = db_convert_expression(tokens[1]);
else
sh4.pc = wind.disa_cursor;
debug_new_pc = sh4.pc;
db_set_disa_cur(sh4.pc);
db_update(DB_UPDATE_DISA);
}
// ---------------------------------------------------------------------------
// bp
static void cmd_bp(void) {
char cur;
u32 idx = 0, cond = 0, expr;
strlwr(tokens[1]);
while ((cur = tokens[1][idx++]) != 0) {
switch (cur) {
case 'r': cond |= BP_READ; break;
case 'w': cond |= BP_WRITE; break;
case 'x': cond |= BP_EXECUTE; break;
}
}
if (cond) {
expr = db_convert_expression(tokens[2]);
if (!db_search_breakpoint(cond, expr, 1))
db_add_breakpoint(cond, expr, 0);
else
Printf(CC_CYAN "Breakpoint already exists!\n");
} else
Printf(CC_CYAN "Wrong break conditions!\n");
}
// ---------------------------------------------------------------------------
// bpr
static void cmd_bpr(void) {
char cur;
u32 idx = 0, cond = 0, expr, range;
strlwr(tokens[1]);
while ((cur = tokens[1][idx++]) != 0) {
switch (cur) {
case 'r': cond |= BP_READ; break;
case 'w': cond |= BP_WRITE; break;
case 'x': cond |= BP_EXECUTE; break;
}
}
if (cond) {
expr = db_convert_expression(tokens[2]);
range = db_convert_expression(tokens[3]);
if (range < expr) {
u32 temp = range;
range = expr;
expr = temp;
}
if (!db_search_breakpoint(cond, expr, 1))
db_add_breakpoint(cond, expr, range);
else
Printf(CC_CYAN "Breakpoint already exists!\n");
} else
Printf(CC_CYAN "Wrong break conditions!\n");
}
// ---------------------------------------------------------------------------
// bc
static void cmd_bc(void) {
char *tok = strlwr(tokens[1]);
if (tok[0] == '*')
db_clear_breakpoints();
else
db_clear_breakpoint(strtoul(tok, NULL, 16));
db_update(DB_UPDATE_DISA);
}
// ---------------------------------------------------------------------------
// bl
static void cmd_bl(void) {
db_list_breakpoints();
}
// ---------------------------------------------------------------------------
// run
static void cmd_run(void) {
debug_step_mode = 0;
}
// ---------------------------------------------------------------------------
// pause
static void cmd_pause(void) {
debug_step_mode = 1;
db_set_disa_cur(sh4.pc);
db_update(DB_UPDATE_ALL);
}
// ---------------------------------------------------------------------------
// step in
static void cmd_step(void) {
debug_trace_mode = 1;
}
// ---------------------------------------------------------------------------
// help
char *help_text =
CC_CYAN "--- cpu debug commands --------------------------------------------------------\n"
CC_WHITE " . " CC_NORM "- view code at PC\n"
CC_WHITE " u [expression] " CC_NORM "- view code at specified address\n"
CC_WHITE " db [expression] " CC_NORM "- view data at specified address\n"
CC_WHITE " pc [expression] " CC_NORM "- set program counter (F8 also)\n"
CC_WHITE " step " CC_NORM "- execute one instruction (F11 also)\n"
// CC_WHITE " thru " CC_NORM "- execute call (F10 also)\n"
CC_WHITE " pause " CC_NORM "- toggle pause emulation (F5 also)\n"
CC_WHITE " run " CC_NORM "- toggle start emulation (F5 also)\n"
CC_WHITE " bp [rwx] [expression]" CC_NORM "- set breakpoint [r]ead/[w]rite/e[x]ecute at address\n"
CC_WHITE " bpr [rwx] [range] " CC_NORM "- set breakpoint [r]ead/[w]rite/e[x]ecute at address range\n"
CC_WHITE " bc ##|* " CC_NORM "- clear breakpoint\n"
CC_WHITE " bl " CC_NORM "- list breakpoints\n"
"\n"
CC_CYAN "--- functional keys -----------------------------------------------------------\n"
CC_WHITE " F1 " CC_NORM "- update registers instantly\n"
CC_WHITE " F2 " CC_NORM "- switch to memory view\n"
CC_WHITE " F3 " CC_NORM "- switch to disassembly\n"
CC_WHITE " F4 " CC_NORM "- switch to command input\n"
CC_WHITE " F5 " CC_NORM "- toggle run, stop\n"
CC_WHITE " F6, ^F6 " CC_NORM "- switch registers view (CPU/FPU)\n"
CC_WHITE " F8 " CC_NORM "- set program counter at cursor\n"
CC_WHITE " F9 " CC_NORM "- toggle breakpoint\n"
// CC_WHITE " F10 " CC_NORM "- step thru call\n"
CC_WHITE " F11 " CC_NORM "- step \n"
"\n"
CC_CYAN "--- misc keys -----------------------------------------------------------------\n"
CC_WHITE " PGUP, PGDN " CC_NORM "- scroll windows\n"
CC_WHITE " ENTER, ESC " CC_NORM "- follow/return branch (in disasm window)\n"
"\n";
static void cmd_help(void) {
int i;
if (tokencount > 1) {
for (i = 0; i < cmd_num - 1; i++) {
if (!stricmp(tokens[1], cmd_list[i].name)) {
if (cmd_list[i].helptext) Printf(cmd_list[i].helptext);
else Printf(CC_GREEN "help: no topic found for \"%s\"\n", cmd_list[i].name);
return;
}
}
Printf(CC_GREEN "help: unknown command '%s'\n", tokens[1]);
} else Printf(help_text);
}
static void cmd_except(void) {
debug_exception_mode ^= 1;
Printf("Exception mode: %s", debug_exception_mode ? "On" : "Off");
}
#ifdef STAT_ENABLE
static void cmd_stat(void) {
Printf("Stat Flush Start\n");
statFlush();
Printf("Stat Flush Finished\n");
}
#endif
// ---------------------------------------------------------------------------
DebugCmd cmd_list[] = {
{ ".", cmd_dot, 0, // .
CC_CYAN ".: Set disasm cursor to PC location.\n"
"syntax: .\n" },
{ "db", cmd_db, 0, // d
CC_CYAN "db: Set memory viewer cursor to given address.\n"
"syntax: db [r##|r#.b|rp]\n" },
{ "u", cmd_u, 0, // u
CC_CYAN "u: Set CPU disassembler cursor to given address.\n"
"syntax: u [r##|r#.b|rp]\n" },
{ "pc", cmd_pc, 0, // pc
CC_CYAN "pc: Set program counter to current disassembler line or expression.\n"
"syntax: pc [r##|r#.b|rp]\n" },
{ "bp", cmd_bp, 2, // bp
CC_CYAN "bp: Set access breakpoint to memory address.\n"
"syntax: bp [rwx] [r##|r#.b|rp]\n" },
{ "bpr", cmd_bpr, 3, // bpr
CC_CYAN "bpr: Set access breakpoint to memory area.\n"
"syntax: bpr [rwx] [r##|r#.b|rp] [r##|r#.b|rp]\n" },
{ "bc", cmd_bc, 1, // bc
CC_CYAN "bc: Clear breakpoint with desired number or clear breakpoints list.\n"
"syntax: bc [#|*]\n" },
{ "bl", cmd_bl, 0, // bl
CC_CYAN "bl: List current breakpoits.\n"
"syntax: bl\n" },
{ "run", cmd_run, 0, // run
CC_CYAN "run: Run paused emulation.\n" },
{ "pause", cmd_pause, 0, // pause
CC_CYAN "pause: Pause emualation.\n" },
{ "step", cmd_step, 0, // step in
CC_CYAN "step: Step by step execution with subroutines.\n" },
{ "help", cmd_help, 0, NULL }, // help
{ "exception", cmd_except, 0, NULL }, // exception
#ifdef STAT_ENABLE
{ "stat", cmd_stat, 0, NULL }, // stat
#endif
};
int cmd_num = sizeof(cmd_list) / sizeof(DebugCmd);