Revision 376253ec monitor.c
b/monitor.c | ||
---|---|---|
30 | 30 |
#include "net.h" |
31 | 31 |
#include "qemu-char.h" |
32 | 32 |
#include "sysemu.h" |
33 |
#include "monitor.h" |
|
34 |
#include "readline.h" |
|
33 | 35 |
#include "console.h" |
34 | 36 |
#include "block.h" |
35 | 37 |
#include "audio/audio.h" |
... | ... | |
57 | 59 |
* |
58 | 60 |
*/ |
59 | 61 |
|
60 |
typedef struct term_cmd_t {
|
|
62 |
typedef struct mon_cmd_t {
|
|
61 | 63 |
const char *name; |
62 | 64 |
const char *args_type; |
63 | 65 |
void *handler; |
64 | 66 |
const char *params; |
65 | 67 |
const char *help; |
66 |
} term_cmd_t;
|
|
68 |
} mon_cmd_t;
|
|
67 | 69 |
|
68 | 70 |
#define MAX_MON 4 |
69 | 71 |
static CharDriverState *monitor_hd[MAX_MON]; |
70 | 72 |
static int hide_banner; |
71 | 73 |
|
72 |
static const term_cmd_t term_cmds[];
|
|
73 |
static const term_cmd_t info_cmds[];
|
|
74 |
static const mon_cmd_t mon_cmds[];
|
|
75 |
static const mon_cmd_t info_cmds[];
|
|
74 | 76 |
|
75 | 77 |
static uint8_t term_outbuf[1024]; |
76 | 78 |
static int term_outbuf_index; |
77 | 79 |
static BlockDriverCompletionFunc *password_completion_cb; |
78 | 80 |
static void *password_opaque; |
79 | 81 |
|
82 |
Monitor *cur_mon; |
|
83 |
|
|
80 | 84 |
static void monitor_start_input(void); |
81 | 85 |
|
82 | 86 |
static CPUState *mon_cpu = NULL; |
83 | 87 |
|
84 |
static void monitor_read_password(ReadLineFunc *readline_func, void *opaque) |
|
88 |
static void monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, |
|
89 |
void *opaque) |
|
85 | 90 |
{ |
86 | 91 |
readline_start("Password: ", 1, readline_func, opaque); |
87 | 92 |
} |
88 | 93 |
|
89 |
void term_flush(void)
|
|
94 |
void monitor_flush(Monitor *mon)
|
|
90 | 95 |
{ |
91 | 96 |
int i; |
92 | 97 |
if (term_outbuf_index > 0) { |
... | ... | |
98 | 103 |
} |
99 | 104 |
|
100 | 105 |
/* flush at every end of line or if the buffer is full */ |
101 |
void term_puts(const char *str)
|
|
106 |
static void monitor_puts(Monitor *mon, const char *str)
|
|
102 | 107 |
{ |
103 | 108 |
char c; |
104 | 109 |
for(;;) { |
... | ... | |
110 | 115 |
term_outbuf[term_outbuf_index++] = c; |
111 | 116 |
if (term_outbuf_index >= (sizeof(term_outbuf) - 1) || |
112 | 117 |
c == '\n') |
113 |
term_flush();
|
|
118 |
monitor_flush(mon);
|
|
114 | 119 |
} |
115 | 120 |
} |
116 | 121 |
|
117 |
void term_vprintf(const char *fmt, va_list ap)
|
|
122 |
void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
|
|
118 | 123 |
{ |
119 | 124 |
char buf[4096]; |
120 | 125 |
vsnprintf(buf, sizeof(buf), fmt, ap); |
121 |
term_puts(buf);
|
|
126 |
monitor_puts(mon, buf);
|
|
122 | 127 |
} |
123 | 128 |
|
124 |
void term_printf(const char *fmt, ...)
|
|
129 |
void monitor_printf(Monitor *mon, const char *fmt, ...)
|
|
125 | 130 |
{ |
126 | 131 |
va_list ap; |
127 | 132 |
va_start(ap, fmt); |
128 |
term_vprintf(fmt, ap);
|
|
133 |
monitor_vprintf(mon, fmt, ap);
|
|
129 | 134 |
va_end(ap); |
130 | 135 |
} |
131 | 136 |
|
132 |
void term_print_filename(const char *filename)
|
|
137 |
void monitor_print_filename(Monitor *mon, const char *filename)
|
|
133 | 138 |
{ |
134 | 139 |
int i; |
135 | 140 |
|
... | ... | |
138 | 143 |
case ' ': |
139 | 144 |
case '"': |
140 | 145 |
case '\\': |
141 |
term_printf("\\%c", filename[i]);
|
|
146 |
monitor_printf(mon, "\\%c", filename[i]);
|
|
142 | 147 |
break; |
143 | 148 |
case '\t': |
144 |
term_printf("\\t");
|
|
149 |
monitor_printf(mon, "\\t");
|
|
145 | 150 |
break; |
146 | 151 |
case '\r': |
147 |
term_printf("\\r");
|
|
152 |
monitor_printf(mon, "\\r");
|
|
148 | 153 |
break; |
149 | 154 |
case '\n': |
150 |
term_printf("\\n");
|
|
155 |
monitor_printf(mon, "\\n");
|
|
151 | 156 |
break; |
152 | 157 |
default: |
153 |
term_printf("%c", filename[i]);
|
|
158 |
monitor_printf(mon, "%c", filename[i]);
|
|
154 | 159 |
break; |
155 | 160 |
} |
156 | 161 |
} |
... | ... | |
160 | 165 |
{ |
161 | 166 |
va_list ap; |
162 | 167 |
va_start(ap, fmt); |
163 |
term_vprintf(fmt, ap);
|
|
168 |
monitor_vprintf((Monitor *)stream, fmt, ap);
|
|
164 | 169 |
va_end(ap); |
165 | 170 |
return 0; |
166 | 171 |
} |
... | ... | |
185 | 190 |
return 0; |
186 | 191 |
} |
187 | 192 |
|
188 |
static void help_cmd1(const term_cmd_t *cmds, const char *prefix, const char *name) |
|
193 |
static void help_cmd_dump(Monitor *mon, const mon_cmd_t *cmds, |
|
194 |
const char *prefix, const char *name) |
|
189 | 195 |
{ |
190 |
const term_cmd_t *cmd;
|
|
196 |
const mon_cmd_t *cmd;
|
|
191 | 197 |
|
192 | 198 |
for(cmd = cmds; cmd->name != NULL; cmd++) { |
193 | 199 |
if (!name || !strcmp(name, cmd->name)) |
194 |
term_printf("%s%s %s -- %s\n", prefix, cmd->name, cmd->params, cmd->help); |
|
200 |
monitor_printf(mon, "%s%s %s -- %s\n", prefix, cmd->name, |
|
201 |
cmd->params, cmd->help); |
|
195 | 202 |
} |
196 | 203 |
} |
197 | 204 |
|
198 |
static void help_cmd(const char *name) |
|
205 |
static void help_cmd(Monitor *mon, const char *name)
|
|
199 | 206 |
{ |
200 | 207 |
if (name && !strcmp(name, "info")) { |
201 |
help_cmd1(info_cmds, "info ", NULL);
|
|
208 |
help_cmd_dump(mon, info_cmds, "info ", NULL);
|
|
202 | 209 |
} else { |
203 |
help_cmd1(term_cmds, "", name);
|
|
210 |
help_cmd_dump(mon, mon_cmds, "", name);
|
|
204 | 211 |
if (name && !strcmp(name, "log")) { |
205 | 212 |
const CPULogItem *item; |
206 |
term_printf("Log items (comma separated):\n");
|
|
207 |
term_printf("%-10s %s\n", "none", "remove all logs");
|
|
213 |
monitor_printf(mon, "Log items (comma separated):\n");
|
|
214 |
monitor_printf(mon, "%-10s %s\n", "none", "remove all logs");
|
|
208 | 215 |
for(item = cpu_log_items; item->mask != 0; item++) { |
209 |
term_printf("%-10s %s\n", item->name, item->help);
|
|
216 |
monitor_printf(mon, "%-10s %s\n", item->name, item->help);
|
|
210 | 217 |
} |
211 | 218 |
} |
212 | 219 |
} |
213 | 220 |
} |
214 | 221 |
|
215 |
static void do_help(const char *name) |
|
216 |
{ |
|
217 |
help_cmd(name); |
|
218 |
} |
|
219 |
|
|
220 |
static void do_commit(const char *device) |
|
222 |
static void do_commit(Monitor *mon, const char *device) |
|
221 | 223 |
{ |
222 | 224 |
int i, all_devices; |
223 | 225 |
|
... | ... | |
229 | 231 |
} |
230 | 232 |
} |
231 | 233 |
|
232 |
static void do_info(const char *item) |
|
234 |
static void do_info(Monitor *mon, const char *item)
|
|
233 | 235 |
{ |
234 |
const term_cmd_t *cmd;
|
|
235 |
void (*handler)(void);
|
|
236 |
const mon_cmd_t *cmd;
|
|
237 |
void (*handler)(Monitor *);
|
|
236 | 238 |
|
237 | 239 |
if (!item) |
238 | 240 |
goto help; |
... | ... | |
241 | 243 |
goto found; |
242 | 244 |
} |
243 | 245 |
help: |
244 |
help_cmd("info"); |
|
246 |
help_cmd(mon, "info");
|
|
245 | 247 |
return; |
246 | 248 |
found: |
247 | 249 |
handler = cmd->handler; |
248 |
handler(); |
|
250 |
handler(mon);
|
|
249 | 251 |
} |
250 | 252 |
|
251 |
static void do_info_version(void)
|
|
253 |
static void do_info_version(Monitor *mon)
|
|
252 | 254 |
{ |
253 |
term_printf("%s\n", QEMU_VERSION);
|
|
255 |
monitor_printf(mon, "%s\n", QEMU_VERSION);
|
|
254 | 256 |
} |
255 | 257 |
|
256 |
static void do_info_name(void)
|
|
258 |
static void do_info_name(Monitor *mon)
|
|
257 | 259 |
{ |
258 | 260 |
if (qemu_name) |
259 |
term_printf("%s\n", qemu_name);
|
|
261 |
monitor_printf(mon, "%s\n", qemu_name);
|
|
260 | 262 |
} |
261 | 263 |
|
262 | 264 |
#if defined(TARGET_I386) |
263 |
static void do_info_hpet(void)
|
|
265 |
static void do_info_hpet(Monitor *mon)
|
|
264 | 266 |
{ |
265 |
term_printf("HPET is %s by QEMU\n", (no_hpet) ? "disabled" : "enabled"); |
|
267 |
monitor_printf(mon, "HPET is %s by QEMU\n", |
|
268 |
(no_hpet) ? "disabled" : "enabled"); |
|
266 | 269 |
} |
267 | 270 |
#endif |
268 | 271 |
|
269 |
static void do_info_uuid(void) |
|
270 |
{ |
|
271 |
term_printf(UUID_FMT "\n", qemu_uuid[0], qemu_uuid[1], qemu_uuid[2], |
|
272 |
qemu_uuid[3], qemu_uuid[4], qemu_uuid[5], qemu_uuid[6], |
|
273 |
qemu_uuid[7], qemu_uuid[8], qemu_uuid[9], qemu_uuid[10], |
|
274 |
qemu_uuid[11], qemu_uuid[12], qemu_uuid[13], qemu_uuid[14], |
|
275 |
qemu_uuid[15]); |
|
276 |
} |
|
277 |
|
|
278 |
static void do_info_block(void) |
|
279 |
{ |
|
280 |
bdrv_info(); |
|
281 |
} |
|
282 |
|
|
283 |
static void do_info_blockstats(void) |
|
272 |
static void do_info_uuid(Monitor *mon) |
|
284 | 273 |
{ |
285 |
bdrv_info_stats(); |
|
274 |
monitor_printf(mon, UUID_FMT "\n", qemu_uuid[0], qemu_uuid[1], |
|
275 |
qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5], |
|
276 |
qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9], |
|
277 |
qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13], |
|
278 |
qemu_uuid[14], qemu_uuid[15]); |
|
286 | 279 |
} |
287 | 280 |
|
288 | 281 |
/* get the current CPU defined by the user */ |
... | ... | |
307 | 300 |
return mon_cpu; |
308 | 301 |
} |
309 | 302 |
|
310 |
static void do_info_registers(void)
|
|
303 |
static void do_info_registers(Monitor *mon)
|
|
311 | 304 |
{ |
312 | 305 |
CPUState *env; |
313 | 306 |
env = mon_get_cpu(); |
314 | 307 |
if (!env) |
315 | 308 |
return; |
316 | 309 |
#ifdef TARGET_I386 |
317 |
cpu_dump_state(env, NULL, monitor_fprintf,
|
|
310 |
cpu_dump_state(env, (FILE *)mon, monitor_fprintf,
|
|
318 | 311 |
X86_DUMP_FPU); |
319 | 312 |
#else |
320 |
cpu_dump_state(env, NULL, monitor_fprintf,
|
|
313 |
cpu_dump_state(env, (FILE *)mon, monitor_fprintf,
|
|
321 | 314 |
0); |
322 | 315 |
#endif |
323 | 316 |
} |
324 | 317 |
|
325 |
static void do_info_cpus(void)
|
|
318 |
static void do_info_cpus(Monitor *mon)
|
|
326 | 319 |
{ |
327 | 320 |
CPUState *env; |
328 | 321 |
|
... | ... | |
330 | 323 |
mon_get_cpu(); |
331 | 324 |
|
332 | 325 |
for(env = first_cpu; env != NULL; env = env->next_cpu) { |
333 |
term_printf("%c CPU #%d:",
|
|
334 |
(env == mon_cpu) ? '*' : ' ', |
|
335 |
env->cpu_index); |
|
326 |
monitor_printf(mon, "%c CPU #%d:",
|
|
327 |
(env == mon_cpu) ? '*' : ' ',
|
|
328 |
env->cpu_index);
|
|
336 | 329 |
#if defined(TARGET_I386) |
337 |
term_printf(" pc=0x" TARGET_FMT_lx, env->eip + env->segs[R_CS].base); |
|
330 |
monitor_printf(mon, " pc=0x" TARGET_FMT_lx, |
|
331 |
env->eip + env->segs[R_CS].base); |
|
338 | 332 |
#elif defined(TARGET_PPC) |
339 |
term_printf(" nip=0x" TARGET_FMT_lx, env->nip);
|
|
333 |
monitor_printf(mon, " nip=0x" TARGET_FMT_lx, env->nip);
|
|
340 | 334 |
#elif defined(TARGET_SPARC) |
341 |
term_printf(" pc=0x" TARGET_FMT_lx " npc=0x" TARGET_FMT_lx, env->pc, env->npc); |
|
335 |
monitor_printf(mon, " pc=0x" TARGET_FMT_lx " npc=0x" TARGET_FMT_lx, |
|
336 |
env->pc, env->npc); |
|
342 | 337 |
#elif defined(TARGET_MIPS) |
343 |
term_printf(" PC=0x" TARGET_FMT_lx, env->active_tc.PC);
|
|
338 |
monitor_printf(mon, " PC=0x" TARGET_FMT_lx, env->active_tc.PC);
|
|
344 | 339 |
#endif |
345 | 340 |
if (env->halted) |
346 |
term_printf(" (halted)");
|
|
347 |
term_printf("\n");
|
|
341 |
monitor_printf(mon, " (halted)");
|
|
342 |
monitor_printf(mon, "\n");
|
|
348 | 343 |
} |
349 | 344 |
} |
350 | 345 |
|
351 |
static void do_cpu_set(int index) |
|
346 |
static void do_cpu_set(Monitor *mon, int index)
|
|
352 | 347 |
{ |
353 | 348 |
if (mon_set_cpu(index) < 0) |
354 |
term_printf("Invalid CPU index\n");
|
|
349 |
monitor_printf(mon, "Invalid CPU index\n");
|
|
355 | 350 |
} |
356 | 351 |
|
357 |
static void do_info_jit(void)
|
|
352 |
static void do_info_jit(Monitor *mon)
|
|
358 | 353 |
{ |
359 |
dump_exec_info(NULL, monitor_fprintf);
|
|
354 |
dump_exec_info((FILE *)mon, monitor_fprintf);
|
|
360 | 355 |
} |
361 | 356 |
|
362 |
static void do_info_history (void)
|
|
357 |
static void do_info_history(Monitor *mon)
|
|
363 | 358 |
{ |
364 | 359 |
int i; |
365 | 360 |
const char *str; |
... | ... | |
369 | 364 |
str = readline_get_history(i); |
370 | 365 |
if (!str) |
371 | 366 |
break; |
372 |
term_printf("%d: '%s'\n", i, str);
|
|
367 |
monitor_printf(mon, "%d: '%s'\n", i, str);
|
|
373 | 368 |
i++; |
374 | 369 |
} |
375 | 370 |
} |
376 | 371 |
|
377 | 372 |
#if defined(TARGET_PPC) |
378 | 373 |
/* XXX: not implemented in other targets */ |
379 |
static void do_info_cpu_stats (void)
|
|
374 |
static void do_info_cpu_stats(Monitor *mon)
|
|
380 | 375 |
{ |
381 | 376 |
CPUState *env; |
382 | 377 |
|
383 | 378 |
env = mon_get_cpu(); |
384 |
cpu_dump_statistics(env, NULL, &monitor_fprintf, 0);
|
|
379 |
cpu_dump_statistics(env, (FILE *)mon, &monitor_fprintf, 0);
|
|
385 | 380 |
} |
386 | 381 |
#endif |
387 | 382 |
|
388 |
static void do_quit(void)
|
|
383 |
static void do_quit(Monitor *mon)
|
|
389 | 384 |
{ |
390 | 385 |
exit(0); |
391 | 386 |
} |
392 | 387 |
|
393 |
static int eject_device(BlockDriverState *bs, int force) |
|
388 |
static int eject_device(Monitor *mon, BlockDriverState *bs, int force)
|
|
394 | 389 |
{ |
395 | 390 |
if (bdrv_is_inserted(bs)) { |
396 | 391 |
if (!force) { |
397 | 392 |
if (!bdrv_is_removable(bs)) { |
398 |
term_printf("device is not removable\n");
|
|
393 |
monitor_printf(mon, "device is not removable\n");
|
|
399 | 394 |
return -1; |
400 | 395 |
} |
401 | 396 |
if (bdrv_is_locked(bs)) { |
402 |
term_printf("device is locked\n");
|
|
397 |
monitor_printf(mon, "device is locked\n");
|
|
403 | 398 |
return -1; |
404 | 399 |
} |
405 | 400 |
} |
... | ... | |
408 | 403 |
return 0; |
409 | 404 |
} |
410 | 405 |
|
411 |
static void do_eject(int force, const char *filename) |
|
406 |
static void do_eject(Monitor *mon, int force, const char *filename)
|
|
412 | 407 |
{ |
413 | 408 |
BlockDriverState *bs; |
414 | 409 |
|
415 | 410 |
bs = bdrv_find(filename); |
416 | 411 |
if (!bs) { |
417 |
term_printf("device not found\n");
|
|
412 |
monitor_printf(mon, "device not found\n");
|
|
418 | 413 |
return; |
419 | 414 |
} |
420 |
eject_device(bs, force); |
|
415 |
eject_device(mon, bs, force);
|
|
421 | 416 |
} |
422 | 417 |
|
423 |
static void do_change_block(const char *device, const char *filename, const char *fmt) |
|
418 |
static void do_change_block(Monitor *mon, const char *device, |
|
419 |
const char *filename, const char *fmt) |
|
424 | 420 |
{ |
425 | 421 |
BlockDriverState *bs; |
426 | 422 |
BlockDriver *drv = NULL; |
427 | 423 |
|
428 | 424 |
bs = bdrv_find(device); |
429 | 425 |
if (!bs) { |
430 |
term_printf("device not found\n");
|
|
426 |
monitor_printf(mon, "device not found\n");
|
|
431 | 427 |
return; |
432 | 428 |
} |
433 | 429 |
if (fmt) { |
434 | 430 |
drv = bdrv_find_format(fmt); |
435 | 431 |
if (!drv) { |
436 |
term_printf("invalid format %s\n", fmt);
|
|
432 |
monitor_printf(mon, "invalid format %s\n", fmt);
|
|
437 | 433 |
return; |
438 | 434 |
} |
439 | 435 |
} |
440 |
if (eject_device(bs, 0) < 0) |
|
436 |
if (eject_device(mon, bs, 0) < 0)
|
|
441 | 437 |
return; |
442 | 438 |
bdrv_open2(bs, filename, 0, drv); |
443 |
monitor_read_bdrv_key_start(bs, NULL, NULL); |
|
439 |
monitor_read_bdrv_key_start(mon, bs, NULL, NULL);
|
|
444 | 440 |
} |
445 | 441 |
|
446 |
static void change_vnc_password_cb(void *opaque, const char *password) |
|
442 |
static void change_vnc_password_cb(Monitor *mon, const char *password, |
|
443 |
void *opaque) |
|
447 | 444 |
{ |
448 | 445 |
if (vnc_display_password(NULL, password) < 0) |
449 |
term_printf("could not set VNC server password\n");
|
|
446 |
monitor_printf(mon, "could not set VNC server password\n");
|
|
450 | 447 |
|
451 | 448 |
monitor_start_input(); |
452 | 449 |
} |
453 | 450 |
|
454 |
static void do_change_vnc(const char *target, const char *arg) |
|
451 |
static void do_change_vnc(Monitor *mon, const char *target, const char *arg)
|
|
455 | 452 |
{ |
456 | 453 |
if (strcmp(target, "passwd") == 0 || |
457 | 454 |
strcmp(target, "password") == 0) { |
... | ... | |
459 | 456 |
char password[9]; |
460 | 457 |
strncpy(password, arg, sizeof(password)); |
461 | 458 |
password[sizeof(password) - 1] = '\0'; |
462 |
change_vnc_password_cb(NULL, password);
|
|
459 |
change_vnc_password_cb(mon, password, NULL);
|
|
463 | 460 |
} else { |
464 |
monitor_read_password(change_vnc_password_cb, NULL); |
|
461 |
monitor_read_password(mon, change_vnc_password_cb, NULL);
|
|
465 | 462 |
} |
466 | 463 |
} else { |
467 | 464 |
if (vnc_display_open(NULL, target) < 0) |
468 |
term_printf("could not start VNC server on %s\n", target);
|
|
465 |
monitor_printf(mon, "could not start VNC server on %s\n", target);
|
|
469 | 466 |
} |
470 | 467 |
} |
471 | 468 |
|
472 |
static void do_change(const char *device, const char *target, const char *arg) |
|
469 |
static void do_change(Monitor *mon, const char *device, const char *target, |
|
470 |
const char *arg) |
|
473 | 471 |
{ |
474 | 472 |
if (strcmp(device, "vnc") == 0) { |
475 |
do_change_vnc(target, arg); |
|
473 |
do_change_vnc(mon, target, arg);
|
|
476 | 474 |
} else { |
477 |
do_change_block(device, target, arg); |
|
475 |
do_change_block(mon, device, target, arg);
|
|
478 | 476 |
} |
479 | 477 |
} |
480 | 478 |
|
481 |
static void do_screen_dump(const char *filename) |
|
479 |
static void do_screen_dump(Monitor *mon, const char *filename)
|
|
482 | 480 |
{ |
483 | 481 |
vga_hw_screen_dump(filename); |
484 | 482 |
} |
485 | 483 |
|
486 |
static void do_logfile(const char *filename) |
|
484 |
static void do_logfile(Monitor *mon, const char *filename)
|
|
487 | 485 |
{ |
488 | 486 |
cpu_set_log_filename(filename); |
489 | 487 |
} |
490 | 488 |
|
491 |
static void do_log(const char *items) |
|
489 |
static void do_log(Monitor *mon, const char *items)
|
|
492 | 490 |
{ |
493 | 491 |
int mask; |
494 | 492 |
|
... | ... | |
497 | 495 |
} else { |
498 | 496 |
mask = cpu_str_to_log_mask(items); |
499 | 497 |
if (!mask) { |
500 |
help_cmd("log"); |
|
498 |
help_cmd(mon, "log");
|
|
501 | 499 |
return; |
502 | 500 |
} |
503 | 501 |
} |
504 | 502 |
cpu_set_log(mask); |
505 | 503 |
} |
506 | 504 |
|
507 |
static void do_stop(void)
|
|
505 |
static void do_stop(Monitor *mon)
|
|
508 | 506 |
{ |
509 | 507 |
vm_stop(EXCP_INTERRUPT); |
510 | 508 |
} |
511 | 509 |
|
512 | 510 |
static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs); |
513 | 511 |
|
514 |
static void do_cont(void) |
|
512 |
struct bdrv_iterate_context { |
|
513 |
Monitor *mon; |
|
514 |
int err; |
|
515 |
}; |
|
516 |
|
|
517 |
static void do_cont(Monitor *mon) |
|
515 | 518 |
{ |
516 |
int err = 0;
|
|
519 |
struct bdrv_iterate_context context = { mon, 0 };
|
|
517 | 520 |
|
518 |
bdrv_iterate(encrypted_bdrv_it, &err);
|
|
521 |
bdrv_iterate(encrypted_bdrv_it, &context);
|
|
519 | 522 |
/* only resume the vm if all keys are set and valid */ |
520 |
if (!err) |
|
523 |
if (!context.err)
|
|
521 | 524 |
vm_start(); |
522 | 525 |
} |
523 | 526 |
|
524 | 527 |
static void bdrv_key_cb(void *opaque, int err) |
525 | 528 |
{ |
529 |
Monitor *mon = opaque; |
|
530 |
|
|
526 | 531 |
/* another key was set successfully, retry to continue */ |
527 | 532 |
if (!err) |
528 |
do_cont(); |
|
533 |
do_cont(mon);
|
|
529 | 534 |
} |
530 | 535 |
|
531 | 536 |
static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs) |
532 | 537 |
{ |
533 |
int *err = opaque;
|
|
538 |
struct bdrv_iterate_context *context = opaque;
|
|
534 | 539 |
|
535 |
if (!*err && bdrv_key_required(bs)) { |
|
536 |
*err = -EBUSY; |
|
537 |
monitor_read_bdrv_key_start(bs, bdrv_key_cb, NULL); |
|
540 |
if (!context->err && bdrv_key_required(bs)) { |
|
541 |
context->err = -EBUSY; |
|
542 |
monitor_read_bdrv_key_start(context->mon, bs, bdrv_key_cb, |
|
543 |
context->mon); |
|
538 | 544 |
} |
539 | 545 |
} |
540 | 546 |
|
541 | 547 |
#ifdef CONFIG_GDBSTUB |
542 |
static void do_gdbserver(const char *port) |
|
548 |
static void do_gdbserver(Monitor *mon, const char *port)
|
|
543 | 549 |
{ |
544 | 550 |
if (!port) |
545 | 551 |
port = DEFAULT_GDBSTUB_PORT; |
546 | 552 |
if (gdbserver_start(port) < 0) { |
547 |
qemu_printf("Could not open gdbserver socket on port '%s'\n", port); |
|
553 |
monitor_printf(mon, "Could not open gdbserver socket on port '%s'\n", |
|
554 |
port); |
|
548 | 555 |
} else { |
549 |
qemu_printf("Waiting gdb connection on port '%s'\n", port);
|
|
556 |
monitor_printf(mon, "Waiting gdb connection on port '%s'\n", port);
|
|
550 | 557 |
} |
551 | 558 |
} |
552 | 559 |
#endif |
553 | 560 |
|
554 |
static void term_printc(int c)
|
|
561 |
static void monitor_printc(Monitor *mon, int c)
|
|
555 | 562 |
{ |
556 |
term_printf("'");
|
|
563 |
monitor_printf(mon, "'");
|
|
557 | 564 |
switch(c) { |
558 | 565 |
case '\'': |
559 |
term_printf("\\'");
|
|
566 |
monitor_printf(mon, "\\'");
|
|
560 | 567 |
break; |
561 | 568 |
case '\\': |
562 |
term_printf("\\\\");
|
|
569 |
monitor_printf(mon, "\\\\");
|
|
563 | 570 |
break; |
564 | 571 |
case '\n': |
565 |
term_printf("\\n");
|
|
572 |
monitor_printf(mon, "\\n");
|
|
566 | 573 |
break; |
567 | 574 |
case '\r': |
568 |
term_printf("\\r");
|
|
575 |
monitor_printf(mon, "\\r");
|
|
569 | 576 |
break; |
570 | 577 |
default: |
571 | 578 |
if (c >= 32 && c <= 126) { |
572 |
term_printf("%c", c);
|
|
579 |
monitor_printf(mon, "%c", c);
|
|
573 | 580 |
} else { |
574 |
term_printf("\\x%02x", c);
|
|
581 |
monitor_printf(mon, "\\x%02x", c);
|
|
575 | 582 |
} |
576 | 583 |
break; |
577 | 584 |
} |
578 |
term_printf("'");
|
|
585 |
monitor_printf(mon, "'");
|
|
579 | 586 |
} |
580 | 587 |
|
581 |
static void memory_dump(int count, int format, int wsize, |
|
588 |
static void memory_dump(Monitor *mon, int count, int format, int wsize,
|
|
582 | 589 |
target_phys_addr_t addr, int is_physical) |
583 | 590 |
{ |
584 | 591 |
CPUState *env; |
... | ... | |
612 | 619 |
} |
613 | 620 |
} |
614 | 621 |
#endif |
615 |
monitor_disas(env, addr, count, is_physical, flags); |
|
622 |
monitor_disas(mon, env, addr, count, is_physical, flags);
|
|
616 | 623 |
return; |
617 | 624 |
} |
618 | 625 |
|
... | ... | |
643 | 650 |
|
644 | 651 |
while (len > 0) { |
645 | 652 |
if (is_physical) |
646 |
term_printf(TARGET_FMT_plx ":", addr);
|
|
653 |
monitor_printf(mon, TARGET_FMT_plx ":", addr);
|
|
647 | 654 |
else |
648 |
term_printf(TARGET_FMT_lx ":", (target_ulong)addr);
|
|
655 |
monitor_printf(mon, TARGET_FMT_lx ":", (target_ulong)addr);
|
|
649 | 656 |
l = len; |
650 | 657 |
if (l > line_size) |
651 | 658 |
l = line_size; |
... | ... | |
656 | 663 |
if (!env) |
657 | 664 |
break; |
658 | 665 |
if (cpu_memory_rw_debug(env, addr, buf, l, 0) < 0) { |
659 |
term_printf(" Cannot access memory\n");
|
|
666 |
monitor_printf(mon, " Cannot access memory\n");
|
|
660 | 667 |
break; |
661 | 668 |
} |
662 | 669 |
} |
... | ... | |
677 | 684 |
v = ldq_raw(buf + i); |
678 | 685 |
break; |
679 | 686 |
} |
680 |
term_printf(" ");
|
|
687 |
monitor_printf(mon, " ");
|
|
681 | 688 |
switch(format) { |
682 | 689 |
case 'o': |
683 |
term_printf("%#*" PRIo64, max_digits, v);
|
|
690 |
monitor_printf(mon, "%#*" PRIo64, max_digits, v);
|
|
684 | 691 |
break; |
685 | 692 |
case 'x': |
686 |
term_printf("0x%0*" PRIx64, max_digits, v);
|
|
693 |
monitor_printf(mon, "0x%0*" PRIx64, max_digits, v);
|
|
687 | 694 |
break; |
688 | 695 |
case 'u': |
689 |
term_printf("%*" PRIu64, max_digits, v);
|
|
696 |
monitor_printf(mon, "%*" PRIu64, max_digits, v);
|
|
690 | 697 |
break; |
691 | 698 |
case 'd': |
692 |
term_printf("%*" PRId64, max_digits, v);
|
|
699 |
monitor_printf(mon, "%*" PRId64, max_digits, v);
|
|
693 | 700 |
break; |
694 | 701 |
case 'c': |
695 |
term_printc(v);
|
|
702 |
monitor_printc(mon, v);
|
|
696 | 703 |
break; |
697 | 704 |
} |
698 | 705 |
i += wsize; |
699 | 706 |
} |
700 |
term_printf("\n");
|
|
707 |
monitor_printf(mon, "\n");
|
|
701 | 708 |
addr += l; |
702 | 709 |
len -= l; |
703 | 710 |
} |
... | ... | |
709 | 716 |
#define GET_TLONG(h, l) (l) |
710 | 717 |
#endif |
711 | 718 |
|
712 |
static void do_memory_dump(int count, int format, int size, |
|
719 |
static void do_memory_dump(Monitor *mon, int count, int format, int size,
|
|
713 | 720 |
uint32_t addrh, uint32_t addrl) |
714 | 721 |
{ |
715 | 722 |
target_long addr = GET_TLONG(addrh, addrl); |
716 |
memory_dump(count, format, size, addr, 0); |
|
723 |
memory_dump(mon, count, format, size, addr, 0);
|
|
717 | 724 |
} |
718 | 725 |
|
719 | 726 |
#if TARGET_PHYS_ADDR_BITS > 32 |
... | ... | |
722 | 729 |
#define GET_TPHYSADDR(h, l) (l) |
723 | 730 |
#endif |
724 | 731 |
|
725 |
static void do_physical_memory_dump(int count, int format, int size,
|
|
726 |
uint32_t addrh, uint32_t addrl) |
|
732 |
static void do_physical_memory_dump(Monitor *mon, int count, int format,
|
|
733 |
int size, uint32_t addrh, uint32_t addrl)
|
|
727 | 734 |
|
728 | 735 |
{ |
729 | 736 |
target_phys_addr_t addr = GET_TPHYSADDR(addrh, addrl); |
730 |
memory_dump(count, format, size, addr, 1); |
|
737 |
memory_dump(mon, count, format, size, addr, 1);
|
|
731 | 738 |
} |
732 | 739 |
|
733 |
static void do_print(int count, int format, int size, unsigned int valh, unsigned int vall) |
|
740 |
static void do_print(Monitor *mon, int count, int format, int size, |
|
741 |
unsigned int valh, unsigned int vall) |
|
734 | 742 |
{ |
735 | 743 |
target_phys_addr_t val = GET_TPHYSADDR(valh, vall); |
736 | 744 |
#if TARGET_PHYS_ADDR_BITS == 32 |
737 | 745 |
switch(format) { |
738 | 746 |
case 'o': |
739 |
term_printf("%#o", val);
|
|
747 |
monitor_printf(mon, "%#o", val);
|
|
740 | 748 |
break; |
741 | 749 |
case 'x': |
742 |
term_printf("%#x", val);
|
|
750 |
monitor_printf(mon, "%#x", val);
|
|
743 | 751 |
break; |
744 | 752 |
case 'u': |
745 |
term_printf("%u", val);
|
|
753 |
monitor_printf(mon, "%u", val);
|
|
746 | 754 |
break; |
747 | 755 |
default: |
748 | 756 |
case 'd': |
749 |
term_printf("%d", val);
|
|
757 |
monitor_printf(mon, "%d", val);
|
|
750 | 758 |
break; |
751 | 759 |
case 'c': |
752 |
term_printc(val);
|
|
760 |
monitor_printc(mon, val);
|
|
753 | 761 |
break; |
754 | 762 |
} |
755 | 763 |
#else |
756 | 764 |
switch(format) { |
757 | 765 |
case 'o': |
758 |
term_printf("%#" PRIo64, val);
|
|
766 |
monitor_printf(mon, "%#" PRIo64, val);
|
|
759 | 767 |
break; |
760 | 768 |
case 'x': |
761 |
term_printf("%#" PRIx64, val);
|
|
769 |
monitor_printf(mon, "%#" PRIx64, val);
|
|
762 | 770 |
break; |
763 | 771 |
case 'u': |
764 |
term_printf("%" PRIu64, val);
|
|
772 |
monitor_printf(mon, "%" PRIu64, val);
|
|
765 | 773 |
break; |
766 | 774 |
default: |
767 | 775 |
case 'd': |
768 |
term_printf("%" PRId64, val);
|
|
776 |
monitor_printf(mon, "%" PRId64, val);
|
|
769 | 777 |
break; |
770 | 778 |
case 'c': |
771 |
term_printc(val);
|
|
779 |
monitor_printc(mon, val);
|
|
772 | 780 |
break; |
773 | 781 |
} |
774 | 782 |
#endif |
775 |
term_printf("\n");
|
|
783 |
monitor_printf(mon, "\n");
|
|
776 | 784 |
} |
777 | 785 |
|
778 |
static void do_memory_save(unsigned int valh, unsigned int vall, |
|
786 |
static void do_memory_save(Monitor *mon, unsigned int valh, unsigned int vall,
|
|
779 | 787 |
uint32_t size, const char *filename) |
780 | 788 |
{ |
781 | 789 |
FILE *f; |
... | ... | |
790 | 798 |
|
791 | 799 |
f = fopen(filename, "wb"); |
792 | 800 |
if (!f) { |
793 |
term_printf("could not open '%s'\n", filename);
|
|
801 |
monitor_printf(mon, "could not open '%s'\n", filename);
|
|
794 | 802 |
return; |
795 | 803 |
} |
796 | 804 |
while (size != 0) { |
... | ... | |
805 | 813 |
fclose(f); |
806 | 814 |
} |
807 | 815 |
|
808 |
static void do_physical_memory_save(unsigned int valh, unsigned int vall, |
|
809 |
uint32_t size, const char *filename) |
|
816 |
static void do_physical_memory_save(Monitor *mon, unsigned int valh, |
|
817 |
unsigned int vall, uint32_t size, |
|
818 |
const char *filename) |
|
810 | 819 |
{ |
811 | 820 |
FILE *f; |
812 | 821 |
uint32_t l; |
... | ... | |
815 | 824 |
|
816 | 825 |
f = fopen(filename, "wb"); |
817 | 826 |
if (!f) { |
818 |
term_printf("could not open '%s'\n", filename);
|
|
827 |
monitor_printf(mon, "could not open '%s'\n", filename);
|
|
819 | 828 |
return; |
820 | 829 |
} |
821 | 830 |
while (size != 0) { |
... | ... | |
831 | 840 |
fclose(f); |
832 | 841 |
} |
833 | 842 |
|
834 |
static void do_sum(uint32_t start, uint32_t size) |
|
843 |
static void do_sum(Monitor *mon, uint32_t start, uint32_t size)
|
|
835 | 844 |
{ |
836 | 845 |
uint32_t addr; |
837 | 846 |
uint8_t buf[1]; |
... | ... | |
844 | 853 |
sum = (sum >> 1) | (sum << 15); |
845 | 854 |
sum += buf[0]; |
846 | 855 |
} |
847 |
term_printf("%05d\n", sum);
|
|
856 |
monitor_printf(mon, "%05d\n", sum);
|
|
848 | 857 |
} |
849 | 858 |
|
850 | 859 |
typedef struct { |
... | ... | |
1027 | 1036 |
} |
1028 | 1037 |
} |
1029 | 1038 |
|
1030 |
static void do_sendkey(const char *string, int has_hold_time, int hold_time) |
|
1039 |
static void do_sendkey(Monitor *mon, const char *string, int has_hold_time, |
|
1040 |
int hold_time) |
|
1031 | 1041 |
{ |
1032 | 1042 |
char keyname_buf[16]; |
1033 | 1043 |
char *separator; |
... | ... | |
1046 | 1056 |
if (keyname_len > 0) { |
1047 | 1057 |
pstrcpy(keyname_buf, sizeof(keyname_buf), string); |
1048 | 1058 |
if (keyname_len > sizeof(keyname_buf) - 1) { |
1049 |
term_printf("invalid key: '%s...'\n", keyname_buf);
|
|
1059 |
monitor_printf(mon, "invalid key: '%s...'\n", keyname_buf);
|
|
1050 | 1060 |
return; |
1051 | 1061 |
} |
1052 | 1062 |
if (i == MAX_KEYCODES) { |
1053 |
term_printf("too many keys\n");
|
|
1063 |
monitor_printf(mon, "too many keys\n");
|
|
1054 | 1064 |
return; |
1055 | 1065 |
} |
1056 | 1066 |
keyname_buf[keyname_len] = 0; |
1057 | 1067 |
keycode = get_keycode(keyname_buf); |
1058 | 1068 |
if (keycode < 0) { |
1059 |
term_printf("unknown key: '%s'\n", keyname_buf);
|
|
1069 |
monitor_printf(mon, "unknown key: '%s'\n", keyname_buf);
|
|
1060 | 1070 |
return; |
1061 | 1071 |
} |
1062 | 1072 |
keycodes[i++] = keycode; |
... | ... | |
1080 | 1090 |
|
1081 | 1091 |
static int mouse_button_state; |
1082 | 1092 |
|
1083 |
static void do_mouse_move(const char *dx_str, const char *dy_str, |
|
1093 |
static void do_mouse_move(Monitor *mon, const char *dx_str, const char *dy_str,
|
|
1084 | 1094 |
const char *dz_str) |
1085 | 1095 |
{ |
1086 | 1096 |
int dx, dy, dz; |
... | ... | |
1092 | 1102 |
kbd_mouse_event(dx, dy, dz, mouse_button_state); |
1093 | 1103 |
} |
1094 | 1104 |
|
1095 |
static void do_mouse_button(int button_state) |
|
1105 |
static void do_mouse_button(Monitor *mon, int button_state)
|
|
1096 | 1106 |
{ |
1097 | 1107 |
mouse_button_state = button_state; |
1098 | 1108 |
kbd_mouse_event(0, 0, 0, mouse_button_state); |
1099 | 1109 |
} |
1100 | 1110 |
|
1101 |
static void do_ioport_read(int count, int format, int size, int addr, int has_index, int index) |
|
1111 |
static void do_ioport_read(Monitor *mon, int count, int format, int size, |
|
1112 |
int addr, int has_index, int index) |
|
1102 | 1113 |
{ |
1103 | 1114 |
uint32_t val; |
1104 | 1115 |
int suffix; |
... | ... | |
1124 | 1135 |
suffix = 'l'; |
1125 | 1136 |
break; |
1126 | 1137 |
} |
1127 |
term_printf("port%c[0x%04x] = %#0*x\n",
|
|
1128 |
suffix, addr, size * 2, val); |
|
1138 |
monitor_printf(mon, "port%c[0x%04x] = %#0*x\n",
|
|
1139 |
suffix, addr, size * 2, val);
|
|
1129 | 1140 |
} |
1130 | 1141 |
|
1131 | 1142 |
/* boot_set handler */ |
... | ... | |
1138 | 1149 |
boot_opaque = opaque; |
1139 | 1150 |
} |
1140 | 1151 |
|
1141 |
static void do_boot_set(const char *bootdevice) |
|
1152 |
static void do_boot_set(Monitor *mon, const char *bootdevice)
|
|
1142 | 1153 |
{ |
1143 | 1154 |
int res; |
1144 | 1155 |
|
1145 | 1156 |
if (qemu_boot_set_handler) { |
1146 | 1157 |
res = qemu_boot_set_handler(boot_opaque, bootdevice); |
1147 | 1158 |
if (res == 0) |
1148 |
term_printf("boot device list now set to %s\n", bootdevice); |
|
1159 |
monitor_printf(mon, "boot device list now set to %s\n", |
|
1160 |
bootdevice); |
|
1149 | 1161 |
else |
1150 |
term_printf("setting boot device list failed with error %i\n", res); |
|
1162 |
monitor_printf(mon, "setting boot device list failed with " |
|
1163 |
"error %i\n", res); |
|
1151 | 1164 |
} else { |
1152 |
term_printf("no function defined to set boot device list for this architecture\n"); |
|
1165 |
monitor_printf(mon, "no function defined to set boot device list for " |
|
1166 |
"this architecture\n"); |
|
1153 | 1167 |
} |
1154 | 1168 |
} |
1155 | 1169 |
|
1156 |
static void do_system_reset(void)
|
|
1170 |
static void do_system_reset(Monitor *mon)
|
|
1157 | 1171 |
{ |
1158 | 1172 |
qemu_system_reset_request(); |
1159 | 1173 |
} |
1160 | 1174 |
|
1161 |
static void do_system_powerdown(void)
|
|
1175 |
static void do_system_powerdown(Monitor *mon)
|
|
1162 | 1176 |
{ |
1163 | 1177 |
qemu_system_powerdown_request(); |
1164 | 1178 |
} |
1165 | 1179 |
|
1166 | 1180 |
#if defined(TARGET_I386) |
1167 |
static void print_pte(uint32_t addr, uint32_t pte, uint32_t mask) |
|
1181 |
static void print_pte(Monitor *mon, uint32_t addr, uint32_t pte, uint32_t mask)
|
|
1168 | 1182 |
{ |
1169 |
term_printf("%08x: %08x %c%c%c%c%c%c%c%c\n",
|
|
1170 |
addr, |
|
1171 |
pte & mask, |
|
1172 |
pte & PG_GLOBAL_MASK ? 'G' : '-', |
|
1173 |
pte & PG_PSE_MASK ? 'P' : '-', |
|
1174 |
pte & PG_DIRTY_MASK ? 'D' : '-', |
|
1175 |
pte & PG_ACCESSED_MASK ? 'A' : '-', |
|
1176 |
pte & PG_PCD_MASK ? 'C' : '-', |
|
1177 |
pte & PG_PWT_MASK ? 'T' : '-', |
|
1178 |
pte & PG_USER_MASK ? 'U' : '-', |
|
1179 |
pte & PG_RW_MASK ? 'W' : '-'); |
|
1183 |
monitor_printf(mon, "%08x: %08x %c%c%c%c%c%c%c%c\n",
|
|
1184 |
addr,
|
|
1185 |
pte & mask,
|
|
1186 |
pte & PG_GLOBAL_MASK ? 'G' : '-',
|
|
1187 |
pte & PG_PSE_MASK ? 'P' : '-',
|
|
1188 |
pte & PG_DIRTY_MASK ? 'D' : '-',
|
|
1189 |
pte & PG_ACCESSED_MASK ? 'A' : '-',
|
|
1190 |
pte & PG_PCD_MASK ? 'C' : '-',
|
|
1191 |
pte & PG_PWT_MASK ? 'T' : '-',
|
|
1192 |
pte & PG_USER_MASK ? 'U' : '-',
|
|
1193 |
pte & PG_RW_MASK ? 'W' : '-');
|
|
1180 | 1194 |
} |
1181 | 1195 |
|
1182 |
static void tlb_info(void)
|
|
1196 |
static void tlb_info(Monitor *mon)
|
|
1183 | 1197 |
{ |
1184 | 1198 |
CPUState *env; |
1185 | 1199 |
int l1, l2; |
... | ... | |
1190 | 1204 |
return; |
1191 | 1205 |
|
1192 | 1206 |
if (!(env->cr[0] & CR0_PG_MASK)) { |
1193 |
term_printf("PG disabled\n");
|
|
1207 |
monitor_printf(mon, "PG disabled\n");
|
|
1194 | 1208 |
return; |
1195 | 1209 |
} |
1196 | 1210 |
pgd = env->cr[3] & ~0xfff; |
... | ... | |
1199 | 1213 |
pde = le32_to_cpu(pde); |
1200 | 1214 |
if (pde & PG_PRESENT_MASK) { |
1201 | 1215 |
if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { |
1202 |
print_pte((l1 << 22), pde, ~((1 << 20) - 1)); |
|
1216 |
print_pte(mon, (l1 << 22), pde, ~((1 << 20) - 1));
|
|
1203 | 1217 |
} else { |
1204 | 1218 |
for(l2 = 0; l2 < 1024; l2++) { |
1205 | 1219 |
cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, |
1206 | 1220 |
(uint8_t *)&pte, 4); |
1207 | 1221 |
pte = le32_to_cpu(pte); |
1208 | 1222 |
if (pte & PG_PRESENT_MASK) { |
1209 |
print_pte((l1 << 22) + (l2 << 12), |
|
1223 |
print_pte(mon, (l1 << 22) + (l2 << 12),
|
|
1210 | 1224 |
pte & ~PG_PSE_MASK, |
1211 | 1225 |
~0xfff); |
1212 | 1226 |
} |
... | ... | |
1216 | 1230 |
} |
1217 | 1231 |
} |
1218 | 1232 |
|
1219 |
static void mem_print(uint32_t *pstart, int *plast_prot, |
|
1233 |
static void mem_print(Monitor *mon, uint32_t *pstart, int *plast_prot,
|
|
1220 | 1234 |
uint32_t end, int prot) |
1221 | 1235 |
{ |
1222 | 1236 |
int prot1; |
1223 | 1237 |
prot1 = *plast_prot; |
1224 | 1238 |
if (prot != prot1) { |
1225 | 1239 |
if (*pstart != -1) { |
1226 |
term_printf("%08x-%08x %08x %c%c%c\n",
|
|
1227 |
*pstart, end, end - *pstart, |
|
1228 |
prot1 & PG_USER_MASK ? 'u' : '-', |
|
1229 |
'r', |
|
1230 |
prot1 & PG_RW_MASK ? 'w' : '-'); |
|
1240 |
monitor_printf(mon, "%08x-%08x %08x %c%c%c\n",
|
|
1241 |
*pstart, end, end - *pstart,
|
|
1242 |
prot1 & PG_USER_MASK ? 'u' : '-',
|
|
1243 |
'r',
|
|
1244 |
prot1 & PG_RW_MASK ? 'w' : '-');
|
|
1231 | 1245 |
} |
1232 | 1246 |
if (prot != 0) |
1233 | 1247 |
*pstart = end; |
... | ... | |
1237 | 1251 |
} |
1238 | 1252 |
} |
1239 | 1253 |
|
1240 |
static void mem_info(void)
|
|
1254 |
static void mem_info(Monitor *mon)
|
|
1241 | 1255 |
{ |
1242 | 1256 |
CPUState *env; |
1243 | 1257 |
int l1, l2, prot, last_prot; |
... | ... | |
1248 | 1262 |
return; |
1249 | 1263 |
|
1250 | 1264 |
if (!(env->cr[0] & CR0_PG_MASK)) { |
1251 |
term_printf("PG disabled\n");
|
|
1265 |
monitor_printf(mon, "PG disabled\n");
|
|
1252 | 1266 |
return; |
1253 | 1267 |
} |
1254 | 1268 |
pgd = env->cr[3] & ~0xfff; |
... | ... | |
1261 | 1275 |
if (pde & PG_PRESENT_MASK) { |
1262 | 1276 |
if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { |
1263 | 1277 |
prot = pde & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK); |
1264 |
mem_print(&start, &last_prot, end, prot); |
|
1278 |
mem_print(mon, &start, &last_prot, end, prot);
|
|
1265 | 1279 |
} else { |
1266 | 1280 |
for(l2 = 0; l2 < 1024; l2++) { |
1267 | 1281 |
cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, |
... | ... | |
1273 | 1287 |
} else { |
1274 | 1288 |
prot = 0; |
1275 | 1289 |
} |
1276 |
mem_print(&start, &last_prot, end, prot); |
|
1290 |
mem_print(mon, &start, &last_prot, end, prot);
|
|
1277 | 1291 |
} |
1278 | 1292 |
} |
1279 | 1293 |
} else { |
1280 | 1294 |
prot = 0; |
1281 |
mem_print(&start, &last_prot, end, prot); |
|
1295 |
mem_print(mon, &start, &last_prot, end, prot);
|
|
1282 | 1296 |
} |
1283 | 1297 |
} |
1284 | 1298 |
} |
... | ... | |
1286 | 1300 |
|
1287 | 1301 |
#if defined(TARGET_SH4) |
1288 | 1302 |
|
1289 |
static void print_tlb(int idx, tlb_t *tlb) |
|
1303 |
static void print_tlb(Monitor *mon, int idx, tlb_t *tlb)
|
|
1290 | 1304 |
{ |
1291 |
term_printf(" tlb%i:\t"
|
|
1292 |
"asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t" |
|
1293 |
"v=%hhu shared=%hhu cached=%hhu prot=%hhu " |
|
1294 |
"dirty=%hhu writethrough=%hhu\n", |
|
1295 |
idx, |
|
1296 |
tlb->asid, tlb->vpn, tlb->ppn, tlb->sz, tlb->size, |
|
1297 |
tlb->v, tlb->sh, tlb->c, tlb->pr, |
|
1298 |
tlb->d, tlb->wt); |
|
1305 |
monitor_printf(mon, " tlb%i:\t"
|
|
1306 |
"asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t"
|
|
1307 |
"v=%hhu shared=%hhu cached=%hhu prot=%hhu "
|
|
1308 |
"dirty=%hhu writethrough=%hhu\n",
|
|
1309 |
idx,
|
|
1310 |
tlb->asid, tlb->vpn, tlb->ppn, tlb->sz, tlb->size,
|
|
1311 |
tlb->v, tlb->sh, tlb->c, tlb->pr,
|
|
1312 |
tlb->d, tlb->wt);
|
|
1299 | 1313 |
} |
1300 | 1314 |
|
1301 |
static void tlb_info(void)
|
|
1315 |
static void tlb_info(Monitor *mon)
|
|
1302 | 1316 |
{ |
1303 | 1317 |
CPUState *env = mon_get_cpu(); |
1304 | 1318 |
int i; |
1305 | 1319 |
|
1306 |
term_printf ("ITLB:\n");
|
|
1320 |
monitor_printf (mon, "ITLB:\n");
|
|
1307 | 1321 |
for (i = 0 ; i < ITLB_SIZE ; i++) |
1308 |
print_tlb (i, &env->itlb[i]); |
|
1309 |
term_printf ("UTLB:\n");
|
|
1322 |
print_tlb (mon, i, &env->itlb[i]);
|
|
1323 |
monitor_printf (mon, "UTLB:\n");
|
|
1310 | 1324 |
for (i = 0 ; i < UTLB_SIZE ; i++) |
1311 |
print_tlb (i, &env->utlb[i]); |
|
1325 |
print_tlb (mon, i, &env->utlb[i]);
|
|
1312 | 1326 |
} |
1313 | 1327 |
|
1314 | 1328 |
#endif |
1315 | 1329 |
|
1316 |
static void do_info_kqemu(void)
|
|
1330 |
static void do_info_kqemu(Monitor *mon)
|
|
1317 | 1331 |
{ |
1318 | 1332 |
#ifdef USE_KQEMU |
1319 | 1333 |
CPUState *env; |
... | ... | |
1321 | 1335 |
val = 0; |
1322 | 1336 |
env = mon_get_cpu(); |
1323 | 1337 |
if (!env) { |
1324 |
term_printf("No cpu initialized yet");
|
|
1338 |
monitor_printf(mon, "No cpu initialized yet");
|
|
1325 | 1339 |
return; |
1326 | 1340 |
} |
1327 | 1341 |
val = env->kqemu_enabled; |
1328 |
term_printf("kqemu support: ");
|
|
1342 |
monitor_printf(mon, "kqemu support: ");
|
|
1329 | 1343 |
switch(val) { |
1330 | 1344 |
default: |
1331 | 1345 |
case 0: |
1332 |
term_printf("disabled\n");
|
|
1346 |
monitor_printf(mon, "disabled\n");
|
|
1333 | 1347 |
break; |
1334 | 1348 |
case 1: |
1335 |
term_printf("enabled for user code\n");
|
|
1349 |
monitor_printf(mon, "enabled for user code\n");
|
|
1336 | 1350 |
break; |
1337 | 1351 |
case 2: |
1338 |
term_printf("enabled for user and kernel code\n");
|
|
1352 |
monitor_printf(mon, "enabled for user and kernel code\n");
|
|
1339 | 1353 |
break; |
1340 | 1354 |
} |
1341 | 1355 |
#else |
1342 |
term_printf("kqemu support: not compiled\n");
|
|
1356 |
monitor_printf(mon, "kqemu support: not compiled\n");
|
|
1343 | 1357 |
#endif |
1344 | 1358 |
} |
1345 | 1359 |
|
1346 |
static void do_info_kvm(void)
|
|
1360 |
static void do_info_kvm(Monitor *mon)
|
|
1347 | 1361 |
{ |
1348 | 1362 |
#ifdef CONFIG_KVM |
1349 |
term_printf("kvm support: ");
|
|
1363 |
monitor_printf(mon, "kvm support: ");
|
|
1350 | 1364 |
if (kvm_enabled()) |
1351 |
term_printf("enabled\n");
|
|
1365 |
monitor_printf(mon, "enabled\n");
|
|
1352 | 1366 |
else |
1353 |
term_printf("disabled\n");
|
|
1367 |
monitor_printf(mon, "disabled\n");
|
|
1354 | 1368 |
#else |
1355 |
term_printf("kvm support: not compiled\n");
|
|
1369 |
monitor_printf(mon, "kvm support: not compiled\n");
|
|
1356 | 1370 |
#endif |
1357 | 1371 |
} |
1358 | 1372 |
|
... | ... | |
1366 | 1380 |
int64_t kqemu_ret_excp_count; |
1367 | 1381 |
int64_t kqemu_ret_intr_count; |
1368 | 1382 |
|
1369 |
static void do_info_profile(void)
|
|
1383 |
static void do_info_profile(Monitor *mon)
|
|
1370 | 1384 |
{ |
1371 | 1385 |
int64_t total; |
1372 | 1386 |
total = qemu_time; |
1373 | 1387 |
if (total == 0) |
1374 | 1388 |
total = 1; |
1375 |
term_printf("async time %" PRId64 " (%0.3f)\n", |
|
1376 |
dev_time, dev_time / (double)ticks_per_sec); |
|
1377 |
term_printf("qemu time %" PRId64 " (%0.3f)\n", |
|
1378 |
qemu_time, qemu_time / (double)ticks_per_sec); |
|
1379 |
term_printf("kqemu time %" PRId64 " (%0.3f %0.1f%%) count=%" PRId64 " int=%" PRId64 " excp=%" PRId64 " intr=%" PRId64 "\n", |
|
1380 |
kqemu_time, kqemu_time / (double)ticks_per_sec, |
|
1381 |
kqemu_time / (double)total * 100.0, |
|
1382 |
kqemu_exec_count, |
|
1383 |
kqemu_ret_int_count, |
|
1384 |
kqemu_ret_excp_count, |
|
1385 |
kqemu_ret_intr_count); |
|
1389 |
monitor_printf(mon, "async time %" PRId64 " (%0.3f)\n", |
|
1390 |
dev_time, dev_time / (double)ticks_per_sec); |
|
1391 |
monitor_printf(mon, "qemu time %" PRId64 " (%0.3f)\n", |
|
1392 |
qemu_time, qemu_time / (double)ticks_per_sec); |
|
1393 |
monitor_printf(mon, "kqemu time %" PRId64 " (%0.3f %0.1f%%) count=%" |
|
1394 |
PRId64 " int=%" PRId64 " excp=%" PRId64 " intr=%" |
|
1395 |
PRId64 "\n", |
|
1396 |
kqemu_time, kqemu_time / (double)ticks_per_sec, |
|
1397 |
kqemu_time / (double)total * 100.0, |
|
1398 |
kqemu_exec_count, |
|
1399 |
kqemu_ret_int_count, |
|
1400 |
kqemu_ret_excp_count, |
|
1401 |
kqemu_ret_intr_count); |
|
1386 | 1402 |
qemu_time = 0; |
1387 | 1403 |
kqemu_time = 0; |
1388 | 1404 |
kqemu_exec_count = 0; |
... | ... | |
1395 | 1411 |
#endif |
1396 | 1412 |
} |
1397 | 1413 |
#else |
1398 |
static void do_info_profile(void)
|
|
1414 |
static void do_info_profile(Monitor *mon)
|
|
1399 | 1415 |
{ |
1400 |
term_printf("Internal profiler not compiled\n");
|
|
1416 |
monitor_printf(mon, "Internal profiler not compiled\n");
|
|
1401 | 1417 |
} |
1402 | 1418 |
#endif |
1403 | 1419 |
|
1404 | 1420 |
/* Capture support */ |
1405 | 1421 |
static LIST_HEAD (capture_list_head, CaptureState) capture_head; |
1406 | 1422 |
|
1407 |
static void do_info_capture (void)
|
|
1423 |
static void do_info_capture(Monitor *mon)
|
|
1408 | 1424 |
{ |
1409 | 1425 |
int i; |
1410 | 1426 |
CaptureState *s; |
1411 | 1427 |
|
1412 | 1428 |
for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) { |
1413 |
term_printf ("[%d]: ", i);
|
|
1429 |
monitor_printf(mon, "[%d]: ", i);
|
|
1414 | 1430 |
s->ops.info (s->opaque); |
1415 | 1431 |
} |
1416 | 1432 |
} |
1417 | 1433 |
|
1418 |
static void do_stop_capture (int n)
|
|
1434 |
static void do_stop_capture(Monitor *mon, int n)
|
|
1419 | 1435 |
{ |
1420 | 1436 |
int i; |
1421 | 1437 |
CaptureState *s; |
... | ... | |
1431 | 1447 |
} |
1432 | 1448 |
|
1433 | 1449 |
#ifdef HAS_AUDIO |
1434 |
static void do_wav_capture (const char *path,
|
|
1435 |
int has_freq, int freq,
|
|
1436 |
int has_bits, int bits,
|
|
1437 |
int has_channels, int nchannels)
|
|
1450 |
static void do_wav_capture(Monitor *mon, const char *path,
|
|
1451 |
int has_freq, int freq, |
|
1452 |
int has_bits, int bits, |
|
1453 |
int has_channels, int nchannels) |
|
1438 | 1454 |
{ |
1439 | 1455 |
CaptureState *s; |
1440 | 1456 |
|
... | ... | |
1445 | 1461 |
nchannels = has_channels ? nchannels : 2; |
1446 | 1462 |
|
1447 | 1463 |
if (wav_start_capture (s, path, freq, bits, nchannels)) { |
1448 |
term_printf ("Faied to add wave capture\n");
|
|
1464 |
monitor_printf(mon, "Faied to add wave capture\n");
|
|
1449 | 1465 |
qemu_free (s); |
1450 | 1466 |
} |
1451 | 1467 |
LIST_INSERT_HEAD (&capture_head, s, entries); |
... | ... | |
1453 | 1469 |
#endif |
1454 | 1470 |
|
1455 | 1471 |
#if defined(TARGET_I386) |
1456 |
static void do_inject_nmi(int cpu_index) |
|
1472 |
static void do_inject_nmi(Monitor *mon, int cpu_index)
|
|
1457 | 1473 |
{ |
1458 | 1474 |
CPUState *env; |
1459 | 1475 |
|
... | ... | |
1465 | 1481 |
} |
1466 | 1482 |
#endif |
1467 | 1483 |
|
1468 |
static void do_info_status(void)
|
|
1484 |
static void do_info_status(Monitor *mon)
|
|
1469 | 1485 |
{ |
1470 | 1486 |
if (vm_running) |
1471 |
term_printf("VM status: running\n");
|
|
1487 |
monitor_printf(mon, "VM status: running\n");
|
|
1472 | 1488 |
else |
1473 |
term_printf("VM status: paused\n");
|
|
1489 |
monitor_printf(mon, "VM status: paused\n");
|
|
1474 | 1490 |
} |
1475 | 1491 |
|
1476 | 1492 |
|
1477 |
static void do_balloon(int value) |
|
1493 |
static void do_balloon(Monitor *mon, int value)
|
|
1478 | 1494 |
{ |
1479 | 1495 |
ram_addr_t target = value; |
1480 | 1496 |
qemu_balloon(target << 20); |
1481 | 1497 |
} |
1482 | 1498 |
|
1483 |
static void do_info_balloon(void)
|
|
1499 |
static void do_info_balloon(Monitor *mon)
|
|
1484 | 1500 |
{ |
1485 | 1501 |
ram_addr_t actual; |
1486 | 1502 |
|
1487 | 1503 |
actual = qemu_balloon_status(); |
1488 | 1504 |
if (kvm_enabled() && !kvm_has_sync_mmu()) |
1489 |
term_printf("Using KVM without synchronous MMU, ballooning disabled\n"); |
|
1505 |
monitor_printf(mon, "Using KVM without synchronous MMU, " |
|
1506 |
"ballooning disabled\n"); |
|
1490 | 1507 |
else if (actual == 0) |
1491 |
term_printf("Ballooning not activated in VM\n");
|
|
1508 |
monitor_printf(mon, "Ballooning not activated in VM\n");
|
|
1492 | 1509 |
else |
1493 |
term_printf("balloon: actual=%d\n", (int)(actual >> 20));
|
|
1510 |
monitor_printf(mon, "balloon: actual=%d\n", (int)(actual >> 20));
|
|
1494 | 1511 |
} |
1495 | 1512 |
|
1496 | 1513 |
/* Please update qemu-doc.texi when adding or changing commands */ |
1497 |
static const term_cmd_t term_cmds[] = {
|
|
1498 |
{ "help|?", "s?", do_help,
|
|
1514 |
static const mon_cmd_t mon_cmds[] = {
|
|
1515 |
{ "help|?", "s?", help_cmd,
|
|
1499 | 1516 |
"[cmd]", "show the help" }, |
1500 | 1517 |
{ "commit", "s", do_commit, |
1501 | 1518 |
"device|all", "commit changes to the disk images (if -snapshot is used) or backing files" }, |
... | ... | |
1601 | 1618 |
}; |
1602 | 1619 |
|
1603 | 1620 |
/* Please update qemu-doc.texi when adding or changing commands */ |
1604 |
static const term_cmd_t info_cmds[] = {
|
|
1621 |
static const mon_cmd_t info_cmds[] = {
|
|
1605 | 1622 |
{ "version", "", do_info_version, |
1606 | 1623 |
"", "show the version of QEMU" }, |
1607 | 1624 |
{ "network", "", do_info_network, |
1608 | 1625 |
"", "show the network state" }, |
1609 | 1626 |
{ "chardev", "", qemu_chr_info, |
1610 | 1627 |
"", "show the character devices" }, |
1611 |
{ "block", "", do_info_block,
|
|
1628 |
{ "block", "", bdrv_info,
|
|
1612 | 1629 |
"", "show the block devices" }, |
1613 |
{ "blockstats", "", do_info_blockstats,
|
|
1630 |
{ "blockstats", "", bdrv_info_stats,
|
|
1614 | 1631 |
"", "show block device statistics" }, |
1615 | 1632 |
{ "registers", "", do_info_registers, |
1616 | 1633 |
"", "show the cpu registers" }, |
... | ... | |
2020 | 2037 |
{ NULL }, |
2021 | 2038 |
}; |
2022 | 2039 |
|
2023 |
static void expr_error(const char *msg) |
|
2040 |
static void expr_error(Monitor *mon, const char *msg)
|
|
2024 | 2041 |
{ |
2025 |
term_printf("%s\n", msg);
|
|
2042 |
monitor_printf(mon, "%s\n", msg);
|
|
2026 | 2043 |
longjmp(expr_env, 1); |
2027 | 2044 |
} |
2028 | 2045 |
|
... | ... | |
2068 | 2085 |
} |
2069 | 2086 |
} |
2070 | 2087 |
|
2071 |
static int64_t expr_sum(void);
|
|
2088 |
static int64_t expr_sum(Monitor *mon);
|
|
2072 | 2089 |
|
2073 |
static int64_t expr_unary(void)
|
|
2090 |
static int64_t expr_unary(Monitor *mon)
|
|
2074 | 2091 |
{ |
2075 | 2092 |
int64_t n; |
2076 | 2093 |
char *p; |
... | ... | |
2079 | 2096 |
switch(*pch) { |
2080 | 2097 |
case '+': |
2081 | 2098 |
next(); |
2082 |
n = expr_unary(); |
|
2099 |
n = expr_unary(mon);
|
|
2083 | 2100 |
break; |
2084 | 2101 |
case '-': |
2085 | 2102 |
next(); |
2086 |
n = -expr_unary(); |
|
2103 |
n = -expr_unary(mon);
|
|
2087 | 2104 |
break; |
2088 | 2105 |
case '~': |
2089 | 2106 |
next(); |
2090 |
n = ~expr_unary(); |
|
2107 |
n = ~expr_unary(mon);
|
|
2091 | 2108 |
break; |
2092 | 2109 |
case '(': |
2093 | 2110 |
next(); |
2094 |
n = expr_sum(); |
|
2111 |
n = expr_sum(mon);
|
|
2095 | 2112 |
if (*pch != ')') { |
2096 |
expr_error("')' expected"); |
|
2113 |
expr_error(mon, "')' expected");
|
|
2097 | 2114 |
} |
2098 | 2115 |
next(); |
2099 | 2116 |
break; |
2100 | 2117 |
case '\'': |
2101 | 2118 |
pch++; |
2102 | 2119 |
if (*pch == '\0') |
2103 |
expr_error("character constant expected"); |
|
2120 |
expr_error(mon, "character constant expected");
|
|
2104 | 2121 |
n = *pch; |
2105 | 2122 |
pch++; |
2106 | 2123 |
if (*pch != '\'') |
2107 |
expr_error("missing terminating \' character"); |
|
2124 |
expr_error(mon, "missing terminating \' character");
|
|
2108 | 2125 |
next(); |
2109 | 2126 |
break; |
2110 | 2127 |
case '$': |
... | ... | |
2127 | 2144 |
*q = 0; |
2128 | 2145 |
ret = get_monitor_def(®, buf); |
2129 | 2146 |
if (ret == -1) |
2130 |
expr_error("unknown register"); |
|
2147 |
expr_error(mon, "unknown register");
|
|
2131 | 2148 |
else if (ret == -2) |
2132 |
expr_error("no cpu defined"); |
|
2149 |
expr_error(mon, "no cpu defined");
|
|
2133 | 2150 |
n = reg; |
2134 | 2151 |
} |
2135 | 2152 |
break; |
2136 | 2153 |
case '\0': |
2137 |
expr_error("unexpected end of expression"); |
|
2154 |
expr_error(mon, "unexpected end of expression");
|
|
2138 | 2155 |
n = 0; |
2139 | 2156 |
break; |
2140 | 2157 |
default: |
... | ... | |
2144 | 2161 |
n = strtoul(pch, &p, 0); |
2145 | 2162 |
#endif |
2146 | 2163 |
if (pch == p) { |
2147 |
expr_error("invalid char in expression"); |
|
2164 |
expr_error(mon, "invalid char in expression");
|
|
2148 | 2165 |
} |
2149 | 2166 |
pch = p; |
2150 | 2167 |
while (qemu_isspace(*pch)) |
... | ... | |
2155 | 2172 |
} |
2156 | 2173 |
|
2157 | 2174 |
|
2158 |
static int64_t expr_prod(void)
|
|
2175 |
static int64_t expr_prod(Monitor *mon)
|
|
2159 | 2176 |
{ |
2160 | 2177 |
int64_t val, val2; |
2161 | 2178 |
int op; |
2162 | 2179 |
|
2163 |
val = expr_unary(); |
|
2180 |
val = expr_unary(mon);
|
|
2164 | 2181 |
for(;;) { |
2165 | 2182 |
op = *pch; |
2166 | 2183 |
if (op != '*' && op != '/' && op != '%') |
2167 | 2184 |
break; |
2168 | 2185 |
next(); |
2169 |
val2 = expr_unary(); |
|
2186 |
val2 = expr_unary(mon);
|
|
2170 | 2187 |
switch(op) { |
2171 | 2188 |
default: |
2172 | 2189 |
case '*': |
... | ... | |
2175 | 2192 |
case '/': |
2176 | 2193 |
case '%': |
2177 | 2194 |
if (val2 == 0) |
2178 |
expr_error("division by zero"); |
|
2195 |
expr_error(mon, "division by zero");
|
|
2179 | 2196 |
if (op == '/') |
2180 | 2197 |
val /= val2; |
2181 | 2198 |
else |
... | ... | |
2186 | 2203 |
return val; |
2187 | 2204 |
} |
2188 | 2205 |
|
2189 |
static int64_t expr_logic(void)
|
|
2206 |
static int64_t expr_logic(Monitor *mon)
|
|
2190 | 2207 |
{ |
2191 | 2208 |
int64_t val, val2; |
2192 | 2209 |
int op; |
2193 | 2210 |
|
2194 |
val = expr_prod(); |
Also available in: Unified diff