60
typedef struct term_cmd_t {
65
typedef struct mon_cmd_t {
62
67
const char *args_type;
64
69
const char *params;
69
static CharDriverState *monitor_hd[MAX_MON];
70
static int hide_banner;
72
static const term_cmd_t term_cmds[];
73
static const term_cmd_t info_cmds[];
75
static uint8_t term_outbuf[1024];
76
static int term_outbuf_index;
78
static void monitor_start_input(void);
79
static void monitor_readline(const char *prompt, int is_password,
80
char *buf, int buf_size);
82
static CPUState *mon_cpu = NULL;
87
if (term_outbuf_index > 0) {
88
for (i = 0; i < MAX_MON; i++)
89
if (monitor_hd[i] && monitor_hd[i]->focus == 0)
90
qemu_chr_write(monitor_hd[i], term_outbuf, term_outbuf_index);
91
term_outbuf_index = 0;
73
/* file descriptors passed via SCM_RIGHTS */
74
typedef struct mon_fd_t mon_fd_t;
78
LIST_ENTRY(mon_fd_t) next;
89
BlockDriverCompletionFunc *password_completion_cb;
90
void *password_opaque;
91
LIST_HEAD(,mon_fd_t) fds;
92
LIST_ENTRY(Monitor) entry;
95
static LIST_HEAD(mon_list, Monitor) mon_list;
97
static const mon_cmd_t mon_cmds[];
98
static const mon_cmd_t info_cmds[];
100
Monitor *cur_mon = NULL;
102
static void monitor_command_cb(Monitor *mon, const char *cmdline,
105
static void monitor_read_command(Monitor *mon, int show_prompt)
107
readline_start(mon->rs, "(qemu) ", 0, monitor_command_cb, NULL);
109
readline_show_prompt(mon->rs);
112
static int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func,
116
readline_start(mon->rs, "Password: ", 1, readline_func, opaque);
117
/* prompt is printed on return from the command handler */
120
monitor_printf(mon, "terminal does not support password prompting\n");
125
void monitor_flush(Monitor *mon)
127
if (mon && mon->outbuf_index != 0 && mon->chr->focus == 0) {
128
qemu_chr_write(mon->chr, mon->outbuf, mon->outbuf_index);
129
mon->outbuf_index = 0;
95
133
/* flush at every end of line or if the buffer is full */
96
void term_puts(const char *str)
134
static void monitor_puts(Monitor *mon, const char *str)
104
term_outbuf[term_outbuf_index++] = '\r';
105
term_outbuf[term_outbuf_index++] = c;
106
if (term_outbuf_index >= (sizeof(term_outbuf) - 1) ||
146
mon->outbuf[mon->outbuf_index++] = '\r';
147
mon->outbuf[mon->outbuf_index++] = c;
148
if (mon->outbuf_index >= (sizeof(mon->outbuf) - 1)
112
void term_vprintf(const char *fmt, va_list ap)
154
void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
115
157
vsnprintf(buf, sizeof(buf), fmt, ap);
158
monitor_puts(mon, buf);
119
void term_printf(const char *fmt, ...)
161
void monitor_printf(Monitor *mon, const char *fmt, ...)
122
164
va_start(ap, fmt);
123
term_vprintf(fmt, ap);
165
monitor_vprintf(mon, fmt, ap);
127
void term_print_filename(const char *filename)
169
void monitor_print_filename(Monitor *mon, const char *filename)
131
173
for (i = 0; filename[i]; i++) {
132
switch (filename[i]) {
136
term_printf("\\%c", filename[i]);
148
term_printf("%c", filename[i]);
174
switch (filename[i]) {
178
monitor_printf(mon, "\\%c", filename[i]);
181
monitor_printf(mon, "\\t");
184
monitor_printf(mon, "\\r");
187
monitor_printf(mon, "\\n");
190
monitor_printf(mon, "%c", filename[i]);
327
360
for(env = first_cpu; env != NULL; env = env->next_cpu) {
328
term_printf("%c CPU #%d:",
329
(env == mon_cpu) ? '*' : ' ',
361
cpu_synchronize_state(env, 0);
362
monitor_printf(mon, "%c CPU #%d:",
363
(env == mon->mon_cpu) ? '*' : ' ',
331
365
#if defined(TARGET_I386)
332
term_printf(" pc=0x" TARGET_FMT_lx, env->eip + env->segs[R_CS].base);
366
monitor_printf(mon, " pc=0x" TARGET_FMT_lx,
367
env->eip + env->segs[R_CS].base);
333
368
#elif defined(TARGET_PPC)
334
term_printf(" nip=0x" TARGET_FMT_lx, env->nip);
369
monitor_printf(mon, " nip=0x" TARGET_FMT_lx, env->nip);
335
370
#elif defined(TARGET_SPARC)
336
term_printf(" pc=0x" TARGET_FMT_lx " npc=0x" TARGET_FMT_lx, env->pc, env->npc);
371
monitor_printf(mon, " pc=0x" TARGET_FMT_lx " npc=0x" TARGET_FMT_lx,
337
373
#elif defined(TARGET_MIPS)
338
term_printf(" PC=0x" TARGET_FMT_lx, env->active_tc.PC);
374
monitor_printf(mon, " PC=0x" TARGET_FMT_lx, env->active_tc.PC);
341
term_printf(" (halted)");
377
monitor_printf(mon, " (halted)");
378
monitor_printf(mon, "\n");
346
static void do_cpu_set(int index)
382
static void do_cpu_set(Monitor *mon, int index)
348
384
if (mon_set_cpu(index) < 0)
349
term_printf("Invalid CPU index\n");
385
monitor_printf(mon, "Invalid CPU index\n");
352
static void do_info_jit(void)
388
static void do_info_jit(Monitor *mon)
354
dump_exec_info(NULL, monitor_fprintf);
390
dump_exec_info((FILE *)mon, monitor_fprintf);
357
static void do_info_history (void)
393
static void do_info_history(Monitor *mon)
364
str = readline_get_history(i);
402
str = readline_get_history(mon->rs, i);
367
term_printf("%d: '%s'\n", i, str);
405
monitor_printf(mon, "%d: '%s'\n", i, str);
372
410
#if defined(TARGET_PPC)
373
411
/* XXX: not implemented in other targets */
374
static void do_info_cpu_stats (void)
412
static void do_info_cpu_stats(Monitor *mon)
378
416
env = mon_get_cpu();
379
cpu_dump_statistics(env, NULL, &monitor_fprintf, 0);
417
cpu_dump_statistics(env, (FILE *)mon, &monitor_fprintf, 0);
383
static void do_quit(void)
421
static void do_quit(Monitor *mon)
388
static int eject_device(BlockDriverState *bs, int force)
426
static int eject_device(Monitor *mon, BlockDriverState *bs, int force)
390
428
if (bdrv_is_inserted(bs)) {
392
430
if (!bdrv_is_removable(bs)) {
393
term_printf("device is not removable\n");
431
monitor_printf(mon, "device is not removable\n");
396
434
if (bdrv_is_locked(bs)) {
397
term_printf("device is locked\n");
435
monitor_printf(mon, "device is locked\n");
406
static void do_eject(int force, const char *filename)
444
static void do_eject(Monitor *mon, int force, const char *filename)
408
446
BlockDriverState *bs;
410
448
bs = bdrv_find(filename);
412
term_printf("device not found\n");
450
monitor_printf(mon, "device not found\n");
415
eject_device(bs, force);
453
eject_device(mon, bs, force);
418
static void do_change_block(const char *device, const char *filename, const char *fmt)
456
static void do_change_block(Monitor *mon, const char *device,
457
const char *filename, const char *fmt)
420
459
BlockDriverState *bs;
421
460
BlockDriver *drv = NULL;
423
462
bs = bdrv_find(device);
425
term_printf("device not found\n");
464
monitor_printf(mon, "device not found\n");
429
468
drv = bdrv_find_format(fmt);
431
term_printf("invalid format %s\n", fmt);
470
monitor_printf(mon, "invalid format %s\n", fmt);
435
if (eject_device(bs, 0) < 0)
474
if (eject_device(mon, bs, 0) < 0)
437
476
bdrv_open2(bs, filename, 0, drv);
438
monitor_read_bdrv_key(bs);
441
static void do_change_vnc(const char *target, const char *arg)
477
monitor_read_bdrv_key_start(mon, bs, NULL, NULL);
480
static void change_vnc_password_cb(Monitor *mon, const char *password,
483
if (vnc_display_password(NULL, password) < 0)
484
monitor_printf(mon, "could not set VNC server password\n");
486
monitor_read_command(mon, 1);
489
static void do_change_vnc(Monitor *mon, const char *target, const char *arg)
443
491
if (strcmp(target, "passwd") == 0 ||
444
strcmp(target, "password") == 0) {
447
strncpy(password, arg, sizeof(password));
448
password[sizeof(password) - 1] = '\0';
450
monitor_readline("Password: ", 1, password, sizeof(password));
451
if (vnc_display_password(NULL, password) < 0)
452
term_printf("could not set VNC server password\n");
492
strcmp(target, "password") == 0) {
495
strncpy(password, arg, sizeof(password));
496
password[sizeof(password) - 1] = '\0';
497
change_vnc_password_cb(mon, password, NULL);
499
monitor_read_password(mon, change_vnc_password_cb, NULL);
454
if (vnc_display_open(NULL, target) < 0)
455
term_printf("could not start VNC server on %s\n", target);
502
if (vnc_display_open(NULL, target) < 0)
503
monitor_printf(mon, "could not start VNC server on %s\n", target);
459
static void do_change(const char *device, const char *target, const char *arg)
507
static void do_change(Monitor *mon, const char *device, const char *target,
461
510
if (strcmp(device, "vnc") == 0) {
462
do_change_vnc(target, arg);
511
do_change_vnc(mon, target, arg);
464
do_change_block(device, target, arg);
513
do_change_block(mon, device, target, arg);
468
static void do_screen_dump(const char *filename)
517
static void do_screen_dump(Monitor *mon, const char *filename)
470
519
vga_hw_screen_dump(filename);
473
static void do_logfile(const char *filename)
522
static void do_logfile(Monitor *mon, const char *filename)
475
524
cpu_set_log_filename(filename);
478
static void do_log(const char *items)
527
static void do_log(Monitor *mon, const char *items)
485
534
mask = cpu_str_to_log_mask(items);
536
help_cmd(mon, "log");
491
540
cpu_set_log(mask);
494
static void do_stop(void)
543
static void do_singlestep(Monitor *mon, const char *option)
545
if (!option || !strcmp(option, "on")) {
547
} else if (!strcmp(option, "off")) {
550
monitor_printf(mon, "unexpected option %s\n", option);
554
static void do_stop(Monitor *mon)
496
556
vm_stop(EXCP_INTERRUPT);
499
static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs)
503
if (bdrv_key_required(bs))
504
*err = monitor_read_bdrv_key(bs);
509
static void do_cont(void)
513
bdrv_iterate(encrypted_bdrv_it, &err);
559
static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs);
561
struct bdrv_iterate_context {
566
static void do_cont(Monitor *mon)
568
struct bdrv_iterate_context context = { mon, 0 };
570
bdrv_iterate(encrypted_bdrv_it, &context);
514
571
/* only resume the vm if all keys are set and valid */
576
static void bdrv_key_cb(void *opaque, int err)
578
Monitor *mon = opaque;
580
/* another key was set successfully, retry to continue */
519
#ifdef CONFIG_GDBSTUB
520
static void do_gdbserver(const char *port)
523
port = DEFAULT_GDBSTUB_PORT;
524
if (gdbserver_start(port) < 0) {
525
qemu_printf("Could not open gdbserver socket on port '%s'\n", port);
585
static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs)
587
struct bdrv_iterate_context *context = opaque;
589
if (!context->err && bdrv_key_required(bs)) {
590
context->err = -EBUSY;
591
monitor_read_bdrv_key_start(context->mon, bs, bdrv_key_cb,
596
static void do_gdbserver(Monitor *mon, const char *device)
599
device = "tcp::" DEFAULT_GDBSTUB_PORT;
600
if (gdbserver_start(device) < 0) {
601
monitor_printf(mon, "Could not open gdbserver on device '%s'\n",
603
} else if (strcmp(device, "none") == 0) {
604
monitor_printf(mon, "Disabled gdbserver\n");
527
qemu_printf("Waiting gdb connection on port '%s'\n", port);
532
static void term_printc(int c)
606
monitor_printf(mon, "Waiting for gdb connection on device '%s'\n",
611
static void do_watchdog_action(Monitor *mon, const char *action)
613
if (select_watchdog_action(action) == -1) {
614
monitor_printf(mon, "Unknown watchdog action '%s'\n", action);
618
static void monitor_printc(Monitor *mon, int c)
620
monitor_printf(mon, "'");
623
monitor_printf(mon, "\\'");
626
monitor_printf(mon, "\\\\");
629
monitor_printf(mon, "\\n");
632
monitor_printf(mon, "\\r");
549
635
if (c >= 32 && c <= 126) {
550
term_printf("%c", c);
636
monitor_printf(mon, "%c", c);
552
term_printf("\\x%02x", c);
638
monitor_printf(mon, "\\x%02x", c);
642
monitor_printf(mon, "'");
559
static void memory_dump(int count, int format, int wsize,
645
static void memory_dump(Monitor *mon, int count, int format, int wsize,
560
646
target_phys_addr_t addr, int is_physical)
1105
term_printf("port%c[0x%04x] = %#0*x\n",
1106
suffix, addr, size * 2, val);
1195
monitor_printf(mon, "port%c[0x%04x] = %#0*x\n",
1196
suffix, addr, size * 2, val);
1109
/* boot_set handler */
1110
static QEMUBootSetHandler *qemu_boot_set_handler = NULL;
1111
static void *boot_opaque;
1113
void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
1199
static void do_ioport_write(Monitor *mon, int count, int format, int size,
1115
qemu_boot_set_handler = func;
1116
boot_opaque = opaque;
1202
addr &= IOPORTS_MASK;
1207
cpu_outb(NULL, addr, val);
1210
cpu_outw(NULL, addr, val);
1213
cpu_outl(NULL, addr, val);
1119
static void do_boot_set(const char *bootdevice)
1218
static void do_boot_set(Monitor *mon, const char *bootdevice)
1123
if (qemu_boot_set_handler) {
1124
res = qemu_boot_set_handler(boot_opaque, bootdevice);
1126
term_printf("boot device list now set to %s\n", bootdevice);
1128
term_printf("setting boot device list failed with error %i\n", res);
1222
res = qemu_boot_set(bootdevice);
1224
monitor_printf(mon, "boot device list now set to %s\n", bootdevice);
1225
} else if (res > 0) {
1226
monitor_printf(mon, "setting boot device list failed\n");
1130
term_printf("no function defined to set boot device list for this architecture\n");
1228
monitor_printf(mon, "no function defined to set boot device list for "
1229
"this architecture\n");
1134
static void do_system_reset(void)
1233
static void do_system_reset(Monitor *mon)
1136
1235
qemu_system_reset_request();
1139
static void do_system_powerdown(void)
1238
static void do_system_powerdown(Monitor *mon)
1141
1240
qemu_system_powerdown_request();
1144
1243
#if defined(TARGET_I386)
1145
static void print_pte(uint32_t addr, uint32_t pte, uint32_t mask)
1244
static void print_pte(Monitor *mon, uint32_t addr, uint32_t pte, uint32_t mask)
1147
term_printf("%08x: %08x %c%c%c%c%c%c%c%c\n",
1150
pte & PG_GLOBAL_MASK ? 'G' : '-',
1151
pte & PG_PSE_MASK ? 'P' : '-',
1152
pte & PG_DIRTY_MASK ? 'D' : '-',
1153
pte & PG_ACCESSED_MASK ? 'A' : '-',
1154
pte & PG_PCD_MASK ? 'C' : '-',
1155
pte & PG_PWT_MASK ? 'T' : '-',
1156
pte & PG_USER_MASK ? 'U' : '-',
1157
pte & PG_RW_MASK ? 'W' : '-');
1246
monitor_printf(mon, "%08x: %08x %c%c%c%c%c%c%c%c\n",
1249
pte & PG_GLOBAL_MASK ? 'G' : '-',
1250
pte & PG_PSE_MASK ? 'P' : '-',
1251
pte & PG_DIRTY_MASK ? 'D' : '-',
1252
pte & PG_ACCESSED_MASK ? 'A' : '-',
1253
pte & PG_PCD_MASK ? 'C' : '-',
1254
pte & PG_PWT_MASK ? 'T' : '-',
1255
pte & PG_USER_MASK ? 'U' : '-',
1256
pte & PG_RW_MASK ? 'W' : '-');
1160
static void tlb_info(void)
1259
static void tlb_info(Monitor *mon)
1265
1364
#if defined(TARGET_SH4)
1267
static void print_tlb(int idx, tlb_t *tlb)
1366
static void print_tlb(Monitor *mon, int idx, tlb_t *tlb)
1269
term_printf(" tlb%i:\t"
1270
"asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t"
1271
"v=%hhu shared=%hhu cached=%hhu prot=%hhu "
1272
"dirty=%hhu writethrough=%hhu\n",
1274
tlb->asid, tlb->vpn, tlb->ppn, tlb->sz, tlb->size,
1275
tlb->v, tlb->sh, tlb->c, tlb->pr,
1368
monitor_printf(mon, " tlb%i:\t"
1369
"asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t"
1370
"v=%hhu shared=%hhu cached=%hhu prot=%hhu "
1371
"dirty=%hhu writethrough=%hhu\n",
1373
tlb->asid, tlb->vpn, tlb->ppn, tlb->sz, tlb->size,
1374
tlb->v, tlb->sh, tlb->c, tlb->pr,
1279
static void tlb_info(void)
1378
static void tlb_info(Monitor *mon)
1281
1380
CPUState *env = mon_get_cpu();
1284
term_printf ("ITLB:\n");
1383
monitor_printf (mon, "ITLB:\n");
1285
1384
for (i = 0 ; i < ITLB_SIZE ; i++)
1286
print_tlb (i, &env->itlb[i]);
1287
term_printf ("UTLB:\n");
1385
print_tlb (mon, i, &env->itlb[i]);
1386
monitor_printf (mon, "UTLB:\n");
1288
1387
for (i = 0 ; i < UTLB_SIZE ; i++)
1289
print_tlb (i, &env->utlb[i]);
1388
print_tlb (mon, i, &env->utlb[i]);
1294
static void do_info_kqemu(void)
1393
static void do_info_kqemu(Monitor *mon)
1300
1399
env = mon_get_cpu();
1302
term_printf("No cpu initialized yet");
1401
monitor_printf(mon, "No cpu initialized yet");
1305
1404
val = env->kqemu_enabled;
1306
term_printf("kqemu support: ");
1405
monitor_printf(mon, "kqemu support: ");
1310
term_printf("disabled\n");
1409
monitor_printf(mon, "disabled\n");
1313
term_printf("enabled for user code\n");
1412
monitor_printf(mon, "enabled for user code\n");
1316
term_printf("enabled for user and kernel code\n");
1415
monitor_printf(mon, "enabled for user and kernel code\n");
1320
term_printf("kqemu support: not compiled\n");
1419
monitor_printf(mon, "kqemu support: not compiled\n");
1324
static void do_info_kvm(void)
1423
static void do_info_kvm(Monitor *mon)
1326
1425
#ifdef CONFIG_KVM
1327
term_printf("kvm support: ");
1426
monitor_printf(mon, "kvm support: ");
1328
1427
if (kvm_enabled())
1329
term_printf("enabled\n");
1428
monitor_printf(mon, "enabled\n");
1331
term_printf("disabled\n");
1430
monitor_printf(mon, "disabled\n");
1333
term_printf("kvm support: not compiled\n");
1432
monitor_printf(mon, "kvm support: not compiled\n");
1436
static void do_info_numa(Monitor *mon)
1441
monitor_printf(mon, "%d nodes\n", nb_numa_nodes);
1442
for (i = 0; i < nb_numa_nodes; i++) {
1443
monitor_printf(mon, "node %d cpus:", i);
1444
for (env = first_cpu; env != NULL; env = env->next_cpu) {
1445
if (env->numa_node == i) {
1446
monitor_printf(mon, " %d", env->cpu_index);
1449
monitor_printf(mon, "\n");
1450
monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i,
1337
1455
#ifdef CONFIG_PROFILER
1339
1457
int64_t kqemu_time;
1446
static void do_info_status(void)
1566
static void do_info_status(Monitor *mon)
1449
term_printf("VM status: running\n");
1451
term_printf("VM status: paused\n");
1570
monitor_printf(mon, "VM status: running (single step mode)\n");
1572
monitor_printf(mon, "VM status: running\n");
1575
monitor_printf(mon, "VM status: paused\n");
1455
static void do_balloon(int value)
1579
static void do_balloon(Monitor *mon, int value)
1457
1581
ram_addr_t target = value;
1458
1582
qemu_balloon(target << 20);
1461
static void do_info_balloon(void)
1585
static void do_info_balloon(Monitor *mon)
1463
1587
ram_addr_t actual;
1465
1589
actual = qemu_balloon_status();
1466
1590
if (kvm_enabled() && !kvm_has_sync_mmu())
1467
term_printf("Using KVM without synchronous MMU, ballooning disabled\n");
1591
monitor_printf(mon, "Using KVM without synchronous MMU, "
1592
"ballooning disabled\n");
1468
1593
else if (actual == 0)
1469
term_printf("Ballooning not activated in VM\n");
1594
monitor_printf(mon, "Ballooning not activated in VM\n");
1471
term_printf("balloon: actual=%d\n", (int)(actual >> 20));
1474
/* Please update qemu-doc.texi when adding or changing commands */
1475
static const term_cmd_t term_cmds[] = {
1476
{ "help|?", "s?", do_help,
1477
"[cmd]", "show the help" },
1478
{ "commit", "s", do_commit,
1479
"device|all", "commit changes to the disk images (if -snapshot is used) or backing files" },
1480
{ "info", "s?", do_info,
1481
"subcommand", "show various information about the system state" },
1482
{ "q|quit", "", do_quit,
1483
"", "quit the emulator" },
1484
{ "eject", "-fB", do_eject,
1485
"[-f] device", "eject a removable medium (use -f to force it)" },
1486
{ "change", "BFs?", do_change,
1487
"device filename [format]", "change a removable medium, optional format" },
1488
{ "screendump", "F", do_screen_dump,
1489
"filename", "save screen into PPM image 'filename'" },
1490
{ "logfile", "F", do_logfile,
1491
"filename", "output logs to 'filename'" },
1492
{ "log", "s", do_log,
1493
"item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" },
1494
{ "savevm", "s?", do_savevm,
1495
"tag|id", "save a VM snapshot. If no tag or id are provided, a new snapshot is created" },
1496
{ "loadvm", "s", do_loadvm,
1497
"tag|id", "restore a VM snapshot from its tag or id" },
1498
{ "delvm", "s", do_delvm,
1499
"tag|id", "delete a VM snapshot from its tag or id" },
1500
{ "stop", "", do_stop,
1501
"", "stop emulation", },
1502
{ "c|cont", "", do_cont,
1503
"", "resume emulation", },
1504
#ifdef CONFIG_GDBSTUB
1505
{ "gdbserver", "s?", do_gdbserver,
1506
"[port]", "start gdbserver session (default port=1234)", },
1508
{ "x", "/l", do_memory_dump,
1509
"/fmt addr", "virtual memory dump starting at 'addr'", },
1510
{ "xp", "/l", do_physical_memory_dump,
1511
"/fmt addr", "physical memory dump starting at 'addr'", },
1512
{ "p|print", "/l", do_print,
1513
"/fmt expr", "print expression value (use $reg for CPU register access)", },
1514
{ "i", "/ii.", do_ioport_read,
1515
"/fmt addr", "I/O port read" },
1517
{ "sendkey", "si?", do_sendkey,
1518
"keys [hold_ms]", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1', default hold time=100 ms)" },
1519
{ "system_reset", "", do_system_reset,
1520
"", "reset the system" },
1521
{ "system_powerdown", "", do_system_powerdown,
1522
"", "send system power down event" },
1523
{ "sum", "ii", do_sum,
1524
"addr size", "compute the checksum of a memory region" },
1525
{ "usb_add", "s", do_usb_add,
1526
"device", "add USB device (e.g. 'host:bus.addr' or 'host:vendor_id:product_id')" },
1527
{ "usb_del", "s", do_usb_del,
1528
"device", "remove USB device 'bus.addr'" },
1529
{ "cpu", "i", do_cpu_set,
1530
"index", "set the default CPU" },
1531
{ "mouse_move", "sss?", do_mouse_move,
1532
"dx dy [dz]", "send mouse move events" },
1533
{ "mouse_button", "i", do_mouse_button,
1534
"state", "change mouse button state (1=L, 2=M, 4=R)" },
1535
{ "mouse_set", "i", do_mouse_set,
1536
"index", "set which mouse device receives events" },
1538
{ "wavcapture", "si?i?i?", do_wav_capture,
1539
"path [frequency bits channels]",
1540
"capture audio to a wave file (default frequency=44100 bits=16 channels=2)" },
1542
{ "stopcapture", "i", do_stop_capture,
1543
"capture index", "stop capture" },
1544
{ "memsave", "lis", do_memory_save,
1545
"addr size file", "save to disk virtual memory dump starting at 'addr' of size 'size'", },
1546
{ "pmemsave", "lis", do_physical_memory_save,
1547
"addr size file", "save to disk physical memory dump starting at 'addr' of size 'size'", },
1548
{ "boot_set", "s", do_boot_set,
1549
"bootdevice", "define new values for the boot device list" },
1550
#if defined(TARGET_I386)
1551
{ "nmi", "i", do_inject_nmi,
1552
"cpu", "inject an NMI on the given CPU", },
1554
{ "migrate", "-ds", do_migrate,
1555
"[-d] uri", "migrate to URI (using -d to not wait for completion)" },
1556
{ "migrate_cancel", "", do_migrate_cancel,
1557
"", "cancel the current VM migration" },
1558
{ "migrate_set_speed", "s", do_migrate_set_speed,
1559
"value", "set maximum speed (in bytes) for migrations" },
1560
#if defined(TARGET_I386)
1561
{ "drive_add", "ss", drive_hot_add, "pci_addr=[[<domain>:]<bus>:]<slot>\n"
1562
"[file=file][,if=type][,bus=n]\n"
1563
"[,unit=m][,media=d][index=i]\n"
1564
"[,cyls=c,heads=h,secs=s[,trans=t]]\n"
1565
"[snapshot=on|off][,cache=on|off]",
1566
"add drive to PCI storage controller" },
1567
{ "pci_add", "sss", pci_device_hot_add, "pci_addr=auto|[[<domain>:]<bus>:]<slot> nic|storage [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]...", "hot-add PCI device" },
1568
{ "pci_del", "s", pci_device_hot_remove, "pci_addr=[[<domain>:]<bus>:]<slot>", "hot remove PCI device" },
1569
{ "host_net_add", "ss", net_host_device_add,
1570
"[tap,user,socket,vde] options", "add host VLAN client" },
1571
{ "host_net_remove", "is", net_host_device_remove,
1572
"vlan_id name", "remove host VLAN client" },
1574
{ "balloon", "i", do_balloon,
1575
"target", "request VM to change it's memory allocation (in MB)" },
1576
{ "set_link", "ss", do_set_link,
1577
"name [up|down]", "change the link status of a network adapter" },
1596
monitor_printf(mon, "balloon: actual=%d\n", (int)(actual >> 20));
1599
static qemu_acl *find_acl(Monitor *mon, const char *name)
1601
qemu_acl *acl = qemu_acl_find(name);
1604
monitor_printf(mon, "acl: unknown list '%s'\n", name);
1609
static void do_acl_show(Monitor *mon, const char *aclname)
1611
qemu_acl *acl = find_acl(mon, aclname);
1612
qemu_acl_entry *entry;
1616
monitor_printf(mon, "policy: %s\n",
1617
acl->defaultDeny ? "deny" : "allow");
1618
TAILQ_FOREACH(entry, &acl->entries, next) {
1620
monitor_printf(mon, "%d: %s %s\n", i,
1621
entry->deny ? "deny" : "allow", entry->match);
1626
static void do_acl_reset(Monitor *mon, const char *aclname)
1628
qemu_acl *acl = find_acl(mon, aclname);
1631
qemu_acl_reset(acl);
1632
monitor_printf(mon, "acl: removed all rules\n");
1636
static void do_acl_policy(Monitor *mon, const char *aclname,
1639
qemu_acl *acl = find_acl(mon, aclname);
1642
if (strcmp(policy, "allow") == 0) {
1643
acl->defaultDeny = 0;
1644
monitor_printf(mon, "acl: policy set to 'allow'\n");
1645
} else if (strcmp(policy, "deny") == 0) {
1646
acl->defaultDeny = 1;
1647
monitor_printf(mon, "acl: policy set to 'deny'\n");
1649
monitor_printf(mon, "acl: unknown policy '%s', "
1650
"expected 'deny' or 'allow'\n", policy);
1655
static void do_acl_add(Monitor *mon, const char *aclname,
1656
const char *match, const char *policy,
1657
int has_index, int index)
1659
qemu_acl *acl = find_acl(mon, aclname);
1663
if (strcmp(policy, "allow") == 0) {
1665
} else if (strcmp(policy, "deny") == 0) {
1668
monitor_printf(mon, "acl: unknown policy '%s', "
1669
"expected 'deny' or 'allow'\n", policy);
1673
ret = qemu_acl_insert(acl, deny, match, index);
1675
ret = qemu_acl_append(acl, deny, match);
1677
monitor_printf(mon, "acl: unable to add acl entry\n");
1679
monitor_printf(mon, "acl: added rule at position %d\n", ret);
1683
static void do_acl_remove(Monitor *mon, const char *aclname, const char *match)
1685
qemu_acl *acl = find_acl(mon, aclname);
1689
ret = qemu_acl_remove(acl, match);
1691
monitor_printf(mon, "acl: no matching acl entry\n");
1693
monitor_printf(mon, "acl: removed rule at position %d\n", ret);
1697
#if defined(TARGET_I386)
1698
static void do_inject_mce(Monitor *mon,
1699
int cpu_index, int bank,
1700
unsigned status_hi, unsigned status_lo,
1701
unsigned mcg_status_hi, unsigned mcg_status_lo,
1702
unsigned addr_hi, unsigned addr_lo,
1703
unsigned misc_hi, unsigned misc_lo)
1706
uint64_t status = ((uint64_t)status_hi << 32) | status_lo;
1707
uint64_t mcg_status = ((uint64_t)mcg_status_hi << 32) | mcg_status_lo;
1708
uint64_t addr = ((uint64_t)addr_hi << 32) | addr_lo;
1709
uint64_t misc = ((uint64_t)misc_hi << 32) | misc_lo;
1711
for (cenv = first_cpu; cenv != NULL; cenv = cenv->next_cpu)
1712
if (cenv->cpu_index == cpu_index && cenv->mcg_cap) {
1713
cpu_inject_x86_mce(cenv, bank, status, mcg_status, addr, misc);
1719
static void do_getfd(Monitor *mon, const char *fdname)
1724
fd = qemu_chr_get_msgfd(mon->chr);
1726
monitor_printf(mon, "getfd: no file descriptor supplied via SCM_RIGHTS\n");
1730
if (qemu_isdigit(fdname[0])) {
1731
monitor_printf(mon, "getfd: monitor names may not begin with a number\n");
1737
monitor_printf(mon, "Failed to dup() file descriptor: %s\n",
1742
LIST_FOREACH(monfd, &mon->fds, next) {
1743
if (strcmp(monfd->name, fdname) != 0) {
1752
monfd = qemu_mallocz(sizeof(mon_fd_t));
1753
monfd->name = qemu_strdup(fdname);
1756
LIST_INSERT_HEAD(&mon->fds, monfd, next);
1759
static void do_closefd(Monitor *mon, const char *fdname)
1763
LIST_FOREACH(monfd, &mon->fds, next) {
1764
if (strcmp(monfd->name, fdname) != 0) {
1768
LIST_REMOVE(monfd, next);
1770
qemu_free(monfd->name);
1775
monitor_printf(mon, "Failed to find file descriptor named %s\n",
1779
int monitor_get_fd(Monitor *mon, const char *fdname)
1783
LIST_FOREACH(monfd, &mon->fds, next) {
1786
if (strcmp(monfd->name, fdname) != 0) {
1792
/* caller takes ownership of fd */
1793
LIST_REMOVE(monfd, next);
1794
qemu_free(monfd->name);
1803
static const mon_cmd_t mon_cmds[] = {
1804
#include "qemu-monitor.h"
1578
1805
{ NULL, NULL, },
1581
/* Please update qemu-doc.texi when adding or changing commands */
1582
static const term_cmd_t info_cmds[] = {
1808
/* Please update qemu-monitor.hx when adding or changing commands */
1809
static const mon_cmd_t info_cmds[] = {
1583
1810
{ "version", "", do_info_version,
1584
1811
"", "show the version of QEMU" },
1585
1812
{ "network", "", do_info_network,
1586
1813
"", "show the network state" },
1587
1814
{ "chardev", "", qemu_chr_info,
1588
1815
"", "show the character devices" },
1589
{ "block", "", do_info_block,
1816
{ "block", "", bdrv_info,
1590
1817
"", "show the block devices" },
1591
{ "blockstats", "", do_info_blockstats,
1818
{ "blockstats", "", bdrv_info_stats,
1592
1819
"", "show block device statistics" },
1593
1820
{ "registers", "", do_info_registers,
1594
1821
"", "show the cpu registers" },
2526
* Store the command-name in cmdname, and return a pointer to
2527
* the remaining of the command string.
2529
static const char *get_command_name(const char *cmdline,
2530
char *cmdname, size_t nlen)
2533
const char *p, *pstart;
2536
while (qemu_isspace(*p))
2541
while (*p != '\0' && *p != '/' && !qemu_isspace(*p))
2546
memcpy(cmdname, pstart, len);
2547
cmdname[len] = '\0';
2294
2551
static int default_fmt_format = 'x';
2295
2552
static int default_fmt_size = 4;
2297
2554
#define MAX_ARGS 16
2299
static void monitor_handle_command(const char *cmdline)
2556
static void monitor_handle_command(Monitor *mon, const char *cmdline)
2301
const char *p, *pstart, *typestr;
2303
int c, nb_args, len, i, has_arg;
2304
const term_cmd_t *cmd;
2558
const char *p, *typestr;
2559
int c, nb_args, i, has_arg;
2560
const mon_cmd_t *cmd;
2305
2561
char cmdname[256];
2306
2562
char buf[1024];
2307
2563
void *str_allocated[MAX_ARGS];
2308
2564
void *args[MAX_ARGS];
2309
void (*handler_0)(void);
2310
void (*handler_1)(void *arg0);
2311
void (*handler_2)(void *arg0, void *arg1);
2312
void (*handler_3)(void *arg0, void *arg1, void *arg2);
2313
void (*handler_4)(void *arg0, void *arg1, void *arg2, void *arg3);
2314
void (*handler_5)(void *arg0, void *arg1, void *arg2, void *arg3,
2316
void (*handler_6)(void *arg0, void *arg1, void *arg2, void *arg3,
2317
void *arg4, void *arg5);
2318
void (*handler_7)(void *arg0, void *arg1, void *arg2, void *arg3,
2319
void *arg4, void *arg5, void *arg6);
2565
void (*handler_0)(Monitor *mon);
2566
void (*handler_1)(Monitor *mon, void *arg0);
2567
void (*handler_2)(Monitor *mon, void *arg0, void *arg1);
2568
void (*handler_3)(Monitor *mon, void *arg0, void *arg1, void *arg2);
2569
void (*handler_4)(Monitor *mon, void *arg0, void *arg1, void *arg2,
2571
void (*handler_5)(Monitor *mon, void *arg0, void *arg1, void *arg2,
2572
void *arg3, void *arg4);
2573
void (*handler_6)(Monitor *mon, void *arg0, void *arg1, void *arg2,
2574
void *arg3, void *arg4, void *arg5);
2575
void (*handler_7)(Monitor *mon, void *arg0, void *arg1, void *arg2,
2576
void *arg3, void *arg4, void *arg5, void *arg6);
2577
void (*handler_8)(Monitor *mon, void *arg0, void *arg1, void *arg2,
2578
void *arg3, void *arg4, void *arg5, void *arg6,
2580
void (*handler_9)(Monitor *mon, void *arg0, void *arg1, void *arg2,
2581
void *arg3, void *arg4, void *arg5, void *arg6,
2582
void *arg7, void *arg8);
2583
void (*handler_10)(Monitor *mon, void *arg0, void *arg1, void *arg2,
2584
void *arg3, void *arg4, void *arg5, void *arg6,
2585
void *arg7, void *arg8, void *arg9);
2322
term_printf("command='%s'\n", cmdline);
2588
monitor_printf(mon, "command='%s'\n", cmdline);
2325
2591
/* extract the command name */
2328
while (qemu_isspace(*p))
2592
p = get_command_name(cmdline, cmdname, sizeof(cmdname));
2333
while (*p != '\0' && *p != '/' && !qemu_isspace(*p))
2336
if (len > sizeof(cmdname) - 1)
2337
len = sizeof(cmdname) - 1;
2338
memcpy(cmdname, pstart, len);
2339
cmdname[len] = '\0';
2341
2596
/* find the command */
2342
for(cmd = term_cmds; cmd->name != NULL; cmd++) {
2597
for(cmd = mon_cmds; cmd->name != NULL; cmd++) {
2343
2598
if (compare_cmd(cmdname, cmd->name))
2346
term_printf("unknown command: '%s'\n", cmdname);
2602
if (cmd->name == NULL) {
2603
monitor_printf(mon, "unknown command: '%s'\n", cmdname);
2350
2607
for(i = 0; i < MAX_ARGS; i++)
2351
2608
str_allocated[i] = NULL;
2572
2832
while (qemu_isspace(*p))
2574
2834
if (*p != '\0') {
2575
term_printf("%s: extraneous characters at the end of line\n",
2835
monitor_printf(mon, "%s: extraneous characters at the end of line\n",
2580
2840
switch(nb_args) {
2582
2842
handler_0 = cmd->handler;
2586
2846
handler_1 = cmd->handler;
2847
handler_1(mon, args[0]);
2590
2850
handler_2 = cmd->handler;
2591
handler_2(args[0], args[1]);
2851
handler_2(mon, args[0], args[1]);
2594
2854
handler_3 = cmd->handler;
2595
handler_3(args[0], args[1], args[2]);
2855
handler_3(mon, args[0], args[1], args[2]);
2598
2858
handler_4 = cmd->handler;
2599
handler_4(args[0], args[1], args[2], args[3]);
2859
handler_4(mon, args[0], args[1], args[2], args[3]);
2602
2862
handler_5 = cmd->handler;
2603
handler_5(args[0], args[1], args[2], args[3], args[4]);
2863
handler_5(mon, args[0], args[1], args[2], args[3], args[4]);
2606
2866
handler_6 = cmd->handler;
2607
handler_6(args[0], args[1], args[2], args[3], args[4], args[5]);
2867
handler_6(mon, args[0], args[1], args[2], args[3], args[4], args[5]);
2610
2870
handler_7 = cmd->handler;
2611
handler_7(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
2871
handler_7(mon, args[0], args[1], args[2], args[3], args[4], args[5],
2875
handler_8 = cmd->handler;
2876
handler_8(mon, args[0], args[1], args[2], args[3], args[4], args[5],
2880
handler_9 = cmd->handler;
2881
handler_9(mon, args[0], args[1], args[2], args[3], args[4], args[5],
2882
args[6], args[7], args[8]);
2885
handler_10 = cmd->handler;
2886
handler_10(mon, args[0], args[1], args[2], args[3], args[4], args[5],
2887
args[6], args[7], args[8], args[9]);
2614
term_printf("unsupported number of arguments: %d\n", nb_args);
2890
monitor_printf(mon, "unsupported number of arguments: %d\n", nb_args);
2618
2894
for(i = 0; i < MAX_ARGS; i++)
2619
2895
qemu_free(str_allocated[i]);
2623
2898
static void cmd_completion(const char *name, const char *list)
2817
3101
qemu_free(args[i]);
2820
static int term_can_read(void *opaque)
2825
static void term_read(void *opaque, const uint8_t *buf, int size)
2828
for(i = 0; i < size; i++)
2829
readline_handle_byte(buf[i]);
2832
static int monitor_suspended;
2834
static void monitor_handle_command1(void *opaque, const char *cmdline)
2836
monitor_handle_command(cmdline);
2837
if (!monitor_suspended)
2838
monitor_start_input();
2840
monitor_suspended = 2;
2843
void monitor_suspend(void)
2845
monitor_suspended = 1;
2848
void monitor_resume(void)
2850
if (monitor_suspended == 2)
2851
monitor_start_input();
2852
monitor_suspended = 0;
2855
static void monitor_start_input(void)
2857
readline_start("(qemu) ", 0, monitor_handle_command1, NULL);
2860
static void term_event(void *opaque, int event)
2862
if (event != CHR_EVENT_RESET)
2866
term_printf("QEMU %s monitor - type 'help' for more information\n",
2868
monitor_start_input();
2871
static int is_first_init = 1;
2873
void monitor_init(CharDriverState *hd, int show_banner)
3104
static int monitor_can_read(void *opaque)
3106
Monitor *mon = opaque;
3108
return (mon->suspend_cnt == 0) ? 128 : 0;
3111
static void monitor_read(void *opaque, const uint8_t *buf, int size)
3113
Monitor *old_mon = cur_mon;
3119
for (i = 0; i < size; i++)
3120
readline_handle_byte(cur_mon->rs, buf[i]);
3122
if (size == 0 || buf[size - 1] != 0)
3123
monitor_printf(cur_mon, "corrupted command\n");
3125
monitor_handle_command(cur_mon, (char *)buf);
3131
static void monitor_command_cb(Monitor *mon, const char *cmdline, void *opaque)
3133
monitor_suspend(mon);
3134
monitor_handle_command(mon, cmdline);
3135
monitor_resume(mon);
3138
int monitor_suspend(Monitor *mon)
3146
void monitor_resume(Monitor *mon)
3150
if (--mon->suspend_cnt == 0)
3151
readline_show_prompt(mon->rs);
3154
static void monitor_event(void *opaque, int event)
3156
Monitor *mon = opaque;
3159
case CHR_EVENT_MUX_IN:
3160
readline_restart(mon->rs);
3161
monitor_resume(mon);
3165
case CHR_EVENT_MUX_OUT:
3166
if (mon->suspend_cnt == 0)
3167
monitor_printf(mon, "\n");
3169
monitor_suspend(mon);
3172
case CHR_EVENT_RESET:
3173
monitor_printf(mon, "QEMU %s monitor - type 'help' for more "
3174
"information\n", QEMU_VERSION);
3175
if (mon->chr->focus == 0)
3176
readline_show_prompt(mon->rs);
3190
void monitor_init(CharDriverState *chr, int flags)
3192
static int is_first_init = 1;
2877
3195
if (is_first_init) {
2878
3196
key_timer = qemu_new_timer(vm_clock, release_keys, NULL);
2881
for (i = 0; i < MAX_MON; i++) {
2882
monitor_hd[i] = NULL;
2884
3197
is_first_init = 0;
2886
for (i = 0; i < MAX_MON; i++) {
2887
if (monitor_hd[i] == NULL) {
2893
hide_banner = !show_banner;
2895
qemu_chr_add_handlers(hd, term_can_read, term_read, term_event, NULL);
2897
readline_start("", 0, monitor_handle_command1, NULL);
2900
/* XXX: use threads ? */
2901
/* modal monitor readline */
2902
static int monitor_readline_started;
2903
static char *monitor_readline_buf;
2904
static int monitor_readline_buf_size;
2906
static void monitor_readline_cb(void *opaque, const char *input)
2908
pstrcpy(monitor_readline_buf, monitor_readline_buf_size, input);
2909
monitor_readline_started = 0;
2912
static void monitor_readline(const char *prompt, int is_password,
2913
char *buf, int buf_size)
2916
int old_focus[MAX_MON];
2919
for (i = 0; i < MAX_MON; i++) {
2921
if (monitor_hd[i]) {
2922
old_focus[i] = monitor_hd[i]->focus;
2923
monitor_hd[i]->focus = 0;
2924
qemu_chr_send_event(monitor_hd[i], CHR_EVENT_FOCUS);
2929
readline_start(prompt, is_password, monitor_readline_cb, NULL);
2930
monitor_readline_buf = buf;
2931
monitor_readline_buf_size = buf_size;
2932
monitor_readline_started = 1;
2933
while (monitor_readline_started) {
2936
/* restore original focus */
2938
for (i = 0; i < MAX_MON; i++)
2940
monitor_hd[i]->focus = old_focus[i];
2944
int monitor_read_bdrv_key(BlockDriverState *bs)
2949
if (!bdrv_is_encrypted(bs))
2952
term_printf("%s (%s) is encrypted.\n", bdrv_get_device_name(bs),
2953
bdrv_get_encrypted_filename(bs));
2954
for(i = 0; i < 3; i++) {
2955
monitor_readline("Password: ", 1, password, sizeof(password));
2956
if (bdrv_set_key(bs, password) == 0)
2958
term_printf("invalid password\n");
3200
mon = qemu_mallocz(sizeof(*mon));
3204
if (mon->chr->focus != 0)
3205
mon->suspend_cnt = 1; /* mux'ed monitors start suspended */
3206
if (flags & MONITOR_USE_READLINE) {
3207
mon->rs = readline_init(mon, monitor_find_completion);
3208
monitor_read_command(mon, 0);
3211
qemu_chr_add_handlers(chr, monitor_can_read, monitor_read, monitor_event,
3214
LIST_INSERT_HEAD(&mon_list, mon, entry);
3215
if (!cur_mon || (flags & MONITOR_IS_DEFAULT))
3219
static void bdrv_password_cb(Monitor *mon, const char *password, void *opaque)
3221
BlockDriverState *bs = opaque;
3224
if (bdrv_set_key(bs, password) != 0) {
3225
monitor_printf(mon, "invalid password\n");
3228
if (mon->password_completion_cb)
3229
mon->password_completion_cb(mon->password_opaque, ret);
3231
monitor_read_command(mon, 1);
3234
void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
3235
BlockDriverCompletionFunc *completion_cb,
3240
if (!bdrv_key_required(bs)) {
3242
completion_cb(opaque, 0);
3246
monitor_printf(mon, "%s (%s) is encrypted.\n", bdrv_get_device_name(bs),
3247
bdrv_get_encrypted_filename(bs));
3249
mon->password_completion_cb = completion_cb;
3250
mon->password_opaque = opaque;
3252
err = monitor_read_password(mon, bdrv_password_cb, bs);
3254
if (err && completion_cb)
3255
completion_cb(opaque, err);