Commit 376253ece484b7dc86f215641dca47c3c88f38d1

Authored by aliguori
1 parent bb5fc20f

monitor: Rework API (Jan Kiszka)

Refactor the monitor API and prepare it for decoupled terminals:
term_print functions are renamed to monitor_* and all monitor services
gain a new parameter (mon) that will once refer to the monitor instance
the output is supposed to appear on. However, the argument remains
unused for now. All monitor command callbacks are also extended by a mon
parameter so that command handlers are able to pass an appropriate
reference to monitor output services.

For the case that monitor outputs so far happen without clearly
identifiable context, the global variable cur_mon is introduced that
shall once provide a pointer either to the current active monitor (while
processing commands) or to the default one. On the mid or long term,
those use case will be obsoleted so that this variable can be removed
again.

Due to the broad usage of the monitor interface, this patch mostly deals
with converting users of the monitor API. A few of them are already
extended to pass 'mon' from the command handler further down to internal
functions that invoke monitor_printf.

At this chance, monitor-related prototypes are moved from console.h to
a new monitor.h. The same is done for the readline API.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6711 c046a42c-6fe2-441c-8c8c-71466251a162
audio/audio.c
... ... @@ -23,7 +23,7 @@
23 23 */
24 24 #include "hw/hw.h"
25 25 #include "audio.h"
26   -#include "console.h"
  26 +#include "monitor.h"
27 27 #include "qemu-timer.h"
28 28 #include "sysemu.h"
29 29  
... ... @@ -328,10 +328,10 @@ void AUD_vlog (const char *cap, const char *fmt, va_list ap)
328 328 {
329 329 if (conf.log_to_monitor) {
330 330 if (cap) {
331   - term_printf ("%s: ", cap);
  331 + monitor_printf(cur_mon, "%s: ", cap);
332 332 }
333 333  
334   - term_vprintf (fmt, ap);
  334 + monitor_vprintf(cur_mon, fmt, ap);
335 335 }
336 336 else {
337 337 if (cap) {
... ...
audio/wavcapture.c
1 1 #include "hw/hw.h"
2   -#include "console.h"
  2 +#include "monitor.h"
3 3 #include "audio.h"
4 4  
5 5 typedef struct {
... ... @@ -71,9 +71,9 @@ static void wav_capture_info (void *opaque)
71 71 WAVState *wav = opaque;
72 72 char *path = wav->path;
73 73  
74   - term_printf ("Capturing audio(%d,%d,%d) to %s: %d bytes\n",
75   - wav->freq, wav->bits, wav->nchannels,
76   - path ? path : "<not available>", wav->bytes);
  74 + monitor_printf(cur_mon, "Capturing audio(%d,%d,%d) to %s: %d bytes\n",
  75 + wav->freq, wav->bits, wav->nchannels,
  76 + path ? path : "<not available>", wav->bytes);
77 77 }
78 78  
79 79 static struct capture_ops wav_capture_ops = {
... ... @@ -84,6 +84,7 @@ static struct capture_ops wav_capture_ops = {
84 84 int wav_start_capture (CaptureState *s, const char *path, int freq,
85 85 int bits, int nchannels)
86 86 {
  87 + Monitor *mon = cur_mon;
87 88 WAVState *wav;
88 89 uint8_t hdr[] = {
89 90 0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56,
... ... @@ -97,13 +98,13 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
97 98 CaptureVoiceOut *cap;
98 99  
99 100 if (bits != 8 && bits != 16) {
100   - term_printf ("incorrect bit count %d, must be 8 or 16\n", bits);
  101 + monitor_printf(mon, "incorrect bit count %d, must be 8 or 16\n", bits);
101 102 return -1;
102 103 }
103 104  
104 105 if (nchannels != 1 && nchannels != 2) {
105   - term_printf ("incorrect channel count %d, must be 1 or 2\n",
106   - nchannels);
  106 + monitor_printf(mon, "incorrect channel count %d, must be 1 or 2\n",
  107 + nchannels);
107 108 return -1;
108 109 }
109 110  
... ... @@ -131,8 +132,8 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
131 132  
132 133 wav->f = qemu_fopen (path, "wb");
133 134 if (!wav->f) {
134   - term_printf ("Failed to open wave file `%s'\nReason: %s\n",
135   - path, strerror (errno));
  135 + monitor_printf(mon, "Failed to open wave file `%s'\nReason: %s\n",
  136 + path, strerror (errno));
136 137 qemu_free (wav);
137 138 return -1;
138 139 }
... ... @@ -146,7 +147,7 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
146 147  
147 148 cap = AUD_add_capture (NULL, &as, &ops, wav);
148 149 if (!cap) {
149   - term_printf ("Failed to add audio capture\n");
  150 + monitor_printf(mon, "Failed to add audio capture\n");
150 151 qemu_free (wav->path);
151 152 qemu_fclose (wav->f);
152 153 qemu_free (wav);
... ...
... ... @@ -28,7 +28,7 @@
28 28 #endif
29 29  
30 30 #include "qemu-common.h"
31   -#include "console.h"
  31 +#include "monitor.h"
32 32 #include "block_int.h"
33 33  
34 34 #ifdef _BSD
... ... @@ -1091,66 +1091,66 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
1091 1091 return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum);
1092 1092 }
1093 1093  
1094   -void bdrv_info(void)
  1094 +void bdrv_info(Monitor *mon)
1095 1095 {
1096 1096 BlockDriverState *bs;
1097 1097  
1098 1098 for (bs = bdrv_first; bs != NULL; bs = bs->next) {
1099   - term_printf("%s:", bs->device_name);
1100   - term_printf(" type=");
  1099 + monitor_printf(mon, "%s:", bs->device_name);
  1100 + monitor_printf(mon, " type=");
1101 1101 switch(bs->type) {
1102 1102 case BDRV_TYPE_HD:
1103   - term_printf("hd");
  1103 + monitor_printf(mon, "hd");
1104 1104 break;
1105 1105 case BDRV_TYPE_CDROM:
1106   - term_printf("cdrom");
  1106 + monitor_printf(mon, "cdrom");
1107 1107 break;
1108 1108 case BDRV_TYPE_FLOPPY:
1109   - term_printf("floppy");
  1109 + monitor_printf(mon, "floppy");
1110 1110 break;
1111 1111 }
1112   - term_printf(" removable=%d", bs->removable);
  1112 + monitor_printf(mon, " removable=%d", bs->removable);
1113 1113 if (bs->removable) {
1114   - term_printf(" locked=%d", bs->locked);
  1114 + monitor_printf(mon, " locked=%d", bs->locked);
1115 1115 }
1116 1116 if (bs->drv) {
1117   - term_printf(" file=");
1118   - term_print_filename(bs->filename);
  1117 + monitor_printf(mon, " file=");
  1118 + monitor_print_filename(mon, bs->filename);
1119 1119 if (bs->backing_file[0] != '\0') {
1120   - term_printf(" backing_file=");
1121   - term_print_filename(bs->backing_file);
1122   - }
1123   - term_printf(" ro=%d", bs->read_only);
1124   - term_printf(" drv=%s", bs->drv->format_name);
1125   - term_printf(" encrypted=%d", bdrv_is_encrypted(bs));
  1120 + monitor_printf(mon, " backing_file=");
  1121 + monitor_print_filename(mon, bs->backing_file);
  1122 + }
  1123 + monitor_printf(mon, " ro=%d", bs->read_only);
  1124 + monitor_printf(mon, " drv=%s", bs->drv->format_name);
  1125 + monitor_printf(mon, " encrypted=%d", bdrv_is_encrypted(bs));
1126 1126 } else {
1127   - term_printf(" [not inserted]");
  1127 + monitor_printf(mon, " [not inserted]");
1128 1128 }
1129   - term_printf("\n");
  1129 + monitor_printf(mon, "\n");
1130 1130 }
1131 1131 }
1132 1132  
1133 1133 /* The "info blockstats" command. */
1134   -void bdrv_info_stats (void)
  1134 +void bdrv_info_stats(Monitor *mon)
1135 1135 {
1136 1136 BlockDriverState *bs;
1137 1137 BlockDriverInfo bdi;
1138 1138  
1139 1139 for (bs = bdrv_first; bs != NULL; bs = bs->next) {
1140   - term_printf ("%s:"
1141   - " rd_bytes=%" PRIu64
1142   - " wr_bytes=%" PRIu64
1143   - " rd_operations=%" PRIu64
1144   - " wr_operations=%" PRIu64
1145   - ,
1146   - bs->device_name,
1147   - bs->rd_bytes, bs->wr_bytes,
1148   - bs->rd_ops, bs->wr_ops);
  1140 + monitor_printf(mon, "%s:"
  1141 + " rd_bytes=%" PRIu64
  1142 + " wr_bytes=%" PRIu64
  1143 + " rd_operations=%" PRIu64
  1144 + " wr_operations=%" PRIu64
  1145 + ,
  1146 + bs->device_name,
  1147 + bs->rd_bytes, bs->wr_bytes,
  1148 + bs->rd_ops, bs->wr_ops);
1149 1149 if (bdrv_get_info(bs, &bdi) == 0)
1150   - term_printf(" high=%" PRId64
1151   - " bytes_free=%" PRId64,
1152   - bdi.highest_alloc, bdi.num_free_bytes);
1153   - term_printf("\n");
  1150 + monitor_printf(mon, " high=%" PRId64
  1151 + " bytes_free=%" PRId64,
  1152 + bdi.highest_alloc, bdi.num_free_bytes);
  1153 + monitor_printf(mon, "\n");
1154 1154 }
1155 1155 }
1156 1156  
... ...
... ... @@ -56,8 +56,8 @@ typedef struct QEMUSnapshotInfo {
56 56  
57 57 #define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_CACHE_DEF)
58 58  
59   -void bdrv_info(void);
60   -void bdrv_info_stats(void);
  59 +void bdrv_info(Monitor *mon);
  60 +void bdrv_info_stats(Monitor *mon);
61 61  
62 62 void bdrv_init(void);
63 63 BlockDriver *bdrv_find_format(const char *format_name);
... ...
console.h
... ... @@ -43,8 +43,8 @@ struct mouse_transform_info_s {
43 43 int a[7];
44 44 };
45 45  
46   -void do_info_mice(void);
47   -void do_mouse_set(int index);
  46 +void do_info_mice(Monitor *mon);
  47 +void do_mouse_set(Monitor *mon, int index);
48 48  
49 49 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
50 50 constants) */
... ... @@ -287,39 +287,9 @@ void vnc_display_init(DisplayState *ds);
287 287 void vnc_display_close(DisplayState *ds);
288 288 int vnc_display_open(DisplayState *ds, const char *display);
289 289 int vnc_display_password(DisplayState *ds, const char *password);
290   -void do_info_vnc(void);
  290 +void do_info_vnc(Monitor *mon);
291 291  
292 292 /* curses.c */
293 293 void curses_display_init(DisplayState *ds, int full_screen);
294 294  
295   -/* FIXME: term_printf et al should probably go elsewhere so everything
296   - does not need to include console.h */
297   -/* monitor.c */
298   -void monitor_init(CharDriverState *hd, int show_banner);
299   -void term_puts(const char *str);
300   -void term_vprintf(const char *fmt, va_list ap);
301   -void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
302   -void term_print_filename(const char *filename);
303   -void term_flush(void);
304   -void term_print_help(void);
305   -void monitor_suspend(void);
306   -void monitor_resume(void);
307   -
308   -#include "block.h"
309   -void monitor_read_bdrv_key_start(BlockDriverState *bs,
310   - BlockDriverCompletionFunc *completion_cb,
311   - void *opaque);
312   -
313   -/* readline.c */
314   -typedef void ReadLineFunc(void *opaque, const char *str);
315   -
316   -extern int completion_index;
317   -void add_completion(const char *str);
318   -void readline_handle_byte(int ch);
319   -void readline_find_completion(const char *cmdline);
320   -const char *readline_get_history(unsigned int index);
321   -void readline_start(const char *prompt, int is_password,
322   - ReadLineFunc *readline_func, void *opaque);
323   -void readline_show_prompt(void);
324   -
325 295 #endif
... ...
... ... @@ -308,8 +308,7 @@ const char *lookup_symbol(target_ulong orig_addr)
308 308  
309 309 #if !defined(CONFIG_USER_ONLY)
310 310  
311   -void term_vprintf(const char *fmt, va_list ap);
312   -void term_printf(const char *fmt, ...);
  311 +#include "monitor.h"
313 312  
314 313 static int monitor_disas_is_physical;
315 314 static CPUState *monitor_disas_env;
... ... @@ -330,19 +329,19 @@ static int monitor_fprintf(FILE *stream, const char *fmt, ...)
330 329 {
331 330 va_list ap;
332 331 va_start(ap, fmt);
333   - term_vprintf(fmt, ap);
  332 + monitor_vprintf((Monitor *)stream, fmt, ap);
334 333 va_end(ap);
335 334 return 0;
336 335 }
337 336  
338   -void monitor_disas(CPUState *env,
  337 +void monitor_disas(Monitor *mon, CPUState *env,
339 338 target_ulong pc, int nb_insn, int is_physical, int flags)
340 339 {
341 340 int count, i;
342 341 struct disassemble_info disasm_info;
343 342 int (*print_insn)(bfd_vma pc, disassemble_info *info);
344 343  
345   - INIT_DISASSEMBLE_INFO(disasm_info, NULL, monitor_fprintf);
  344 + INIT_DISASSEMBLE_INFO(disasm_info, (FILE *)mon, monitor_fprintf);
346 345  
347 346 monitor_disas_env = env;
348 347 monitor_disas_is_physical = is_physical;
... ... @@ -388,15 +387,15 @@ void monitor_disas(CPUState *env,
388 387 print_insn = print_insn_little_mips;
389 388 #endif
390 389 #else
391   - term_printf("0x" TARGET_FMT_lx
392   - ": Asm output not supported on this arch\n", pc);
  390 + monitor_printf(mon, "0x" TARGET_FMT_lx
  391 + ": Asm output not supported on this arch\n", pc);
393 392 return;
394 393 #endif
395 394  
396 395 for(i = 0; i < nb_insn; i++) {
397   - term_printf("0x" TARGET_FMT_lx ": ", pc);
  396 + monitor_printf(mon, "0x" TARGET_FMT_lx ": ", pc);
398 397 count = print_insn(pc, &disasm_info);
399   - term_printf("\n");
  398 + monitor_printf(mon, "\n");
400 399 if (count < 0)
401 400 break;
402 401 pc += count;
... ...
1 1 #ifndef _QEMU_DISAS_H
2 2 #define _QEMU_DISAS_H
3 3  
  4 +#include "qemu-common.h"
  5 +
4 6 /* Disassemble this for me please... (debugging). */
5 7 void disas(FILE *out, void *code, unsigned long size);
6 8 void target_disas(FILE *out, target_ulong code, target_ulong size, int flags);
7   -void monitor_disas(CPUState *env,
  9 +
  10 +/* The usual mess... FIXME: Remove this condition once dyngen-exec.h is gone */
  11 +#ifndef __DYNGEN_EXEC_H__
  12 +void monitor_disas(Monitor *mon, CPUState *env,
8 13 target_ulong pc, int nb_insn, int is_physical, int flags);
  14 +#endif
9 15  
10 16 /* Look up symbol for debugging purpose. Returns "" if unknown. */
11 17 const char *lookup_symbol(target_ulong orig_addr);
... ...
hw/an5206.c
... ... @@ -7,6 +7,7 @@
7 7 */
8 8  
9 9 #include "hw.h"
  10 +#include "pc.h"
10 11 #include "mcf.h"
11 12 #include "sysemu.h"
12 13 #include "boards.h"
... ... @@ -16,11 +17,11 @@
16 17 #define AN5206_RAMBAR_ADDR 0x20000000
17 18  
18 19 /* Stub functions for hardware that doesn't exist. */
19   -void pic_info(void)
  20 +void pic_info(Monitor *mon)
20 21 {
21 22 }
22 23  
23   -void irq_info(void)
  24 +void irq_info(Monitor *mon)
24 25 {
25 26 }
26 27  
... ...
hw/arm_pic.c
... ... @@ -8,14 +8,15 @@
8 8 */
9 9  
10 10 #include "hw.h"
  11 +#include "pc.h"
11 12 #include "arm-misc.h"
12 13  
13 14 /* Stub functions for hardware that doesn't exist. */
14   -void pic_info(void)
  15 +void pic_info(Monitor *mon)
15 16 {
16 17 }
17 18  
18   -void irq_info(void)
  19 +void irq_info(Monitor *mon)
19 20 {
20 21 }
21 22  
... ...
hw/etraxfs_pic.c
... ... @@ -24,6 +24,7 @@
24 24  
25 25 #include <stdio.h>
26 26 #include "hw.h"
  27 +#include "pc.h"
27 28 #include "etraxfs.h"
28 29  
29 30 #define D(x)
... ... @@ -135,11 +136,11 @@ static CPUWriteMemoryFunc *pic_write[] = {
135 136 &pic_writel,
136 137 };
137 138  
138   -void pic_info(void)
  139 +void pic_info(Monitor *mon)
139 140 {
140 141 }
141 142  
142   -void irq_info(void)
  143 +void irq_info(Monitor *mon)
143 144 {
144 145 }
145 146  
... ...
hw/i8259.c
... ... @@ -24,7 +24,7 @@
24 24 #include "hw.h"
25 25 #include "pc.h"
26 26 #include "isa.h"
27   -#include "console.h"
  27 +#include "monitor.h"
28 28  
29 29 /* debug PIC */
30 30 //#define DEBUG_PIC
... ... @@ -511,7 +511,7 @@ static void pic_init1(int io_addr, int elcr_addr, PicState *s)
511 511 qemu_register_reset(pic_reset, s);
512 512 }
513 513  
514   -void pic_info(void)
  514 +void pic_info(Monitor *mon)
515 515 {
516 516 int i;
517 517 PicState *s;
... ... @@ -521,26 +521,27 @@ void pic_info(void)
521 521  
522 522 for(i=0;i<2;i++) {
523 523 s = &isa_pic->pics[i];
524   - term_printf("pic%d: irr=%02x imr=%02x isr=%02x hprio=%d irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n",
525   - i, s->irr, s->imr, s->isr, s->priority_add,
526   - s->irq_base, s->read_reg_select, s->elcr,
527   - s->special_fully_nested_mode);
  524 + monitor_printf(mon, "pic%d: irr=%02x imr=%02x isr=%02x hprio=%d "
  525 + "irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n",
  526 + i, s->irr, s->imr, s->isr, s->priority_add,
  527 + s->irq_base, s->read_reg_select, s->elcr,
  528 + s->special_fully_nested_mode);
528 529 }
529 530 }
530 531  
531   -void irq_info(void)
  532 +void irq_info(Monitor *mon)
532 533 {
533 534 #ifndef DEBUG_IRQ_COUNT
534   - term_printf("irq statistic code not compiled.\n");
  535 + monitor_printf(mon, "irq statistic code not compiled.\n");
535 536 #else
536 537 int i;
537 538 int64_t count;
538 539  
539   - term_printf("IRQ statistics:\n");
  540 + monitor_printf(mon, "IRQ statistics:\n");
540 541 for (i = 0; i < 16; i++) {
541 542 count = irq_count[i];
542 543 if (count > 0)
543   - term_printf("%2d: %" PRId64 "\n", i, count);
  544 + monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
544 545 }
545 546 #endif
546 547 }
... ...
... ... @@ -31,7 +31,7 @@
31 31 #include "net.h"
32 32 #include "smbus.h"
33 33 #include "boards.h"
34   -#include "console.h"
  34 +#include "monitor.h"
35 35 #include "fw_cfg.h"
36 36 #include "virtio-blk.h"
37 37 #include "virtio-balloon.h"
... ... @@ -208,6 +208,7 @@ static int boot_device2nibble(char boot_device)
208 208 and used there as well */
209 209 static int pc_boot_set(void *opaque, const char *boot_device)
210 210 {
  211 + Monitor *mon = cur_mon;
211 212 #define PC_MAX_BOOT_DEVICES 3
212 213 RTCState *s = (RTCState *)opaque;
213 214 int nbds, bds[3] = { 0, };
... ... @@ -215,14 +216,14 @@ static int pc_boot_set(void *opaque, const char *boot_device)
215 216  
216 217 nbds = strlen(boot_device);
217 218 if (nbds > PC_MAX_BOOT_DEVICES) {
218   - term_printf("Too many boot devices for PC\n");
  219 + monitor_printf(mon, "Too many boot devices for PC\n");
219 220 return(1);
220 221 }
221 222 for (i = 0; i < nbds; i++) {
222 223 bds[i] = boot_device2nibble(boot_device[i]);
223 224 if (bds[i] == 0) {
224   - term_printf("Invalid boot device for PC: '%c'\n",
225   - boot_device[i]);
  225 + monitor_printf(mon, "Invalid boot device for PC: '%c'\n",
  226 + boot_device[i]);
226 227 return(1);
227 228 }
228 229 }
... ...
1 1 #ifndef HW_PC_H
2 2 #define HW_PC_H
  3 +
  4 +#include "qemu-common.h"
  5 +
3 6 /* PC-style peripherals (also used by other machines). */
4 7  
5 8 /* serial.c */
... ... @@ -34,8 +37,8 @@ void pic_set_alt_irq_func(PicState2 *s, SetIRQFunc *alt_irq_func,
34 37 int pic_read_irq(PicState2 *s);
35 38 void pic_update_irq(PicState2 *s);
36 39 uint32_t pic_intack_read(PicState2 *s);
37   -void pic_info(void);
38   -void irq_info(void);
  40 +void pic_info(Monitor *mon);
  41 +void irq_info(Monitor *mon);
39 42  
40 43 /* APIC */
41 44 typedef struct IOAPICState IOAPICState;
... ...
hw/pci-hotplug.c
... ... @@ -28,7 +28,7 @@
28 28 #include "net.h"
29 29 #include "sysemu.h"
30 30 #include "pc.h"
31   -#include "console.h"
  31 +#include "monitor.h"
32 32 #include "block_int.h"
33 33 #include "virtio-blk.h"
34 34  
... ... @@ -43,7 +43,7 @@ static PCIDevice *qemu_pci_hot_add_nic(PCIBus *pci_bus, const char *opts)
43 43 return pci_nic_init (pci_bus, &nd_table[ret], -1, "rtl8139");
44 44 }
45 45  
46   -void drive_hot_add(const char *pci_addr, const char *opts)
  46 +void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
47 47 {
48 48 int dom, pci_bus;
49 49 unsigned slot;
... ... @@ -52,13 +52,13 @@ void drive_hot_add(const char *pci_addr, const char *opts)
52 52 PCIDevice *dev;
53 53  
54 54 if (pci_read_devaddr(pci_addr, &dom, &pci_bus, &slot)) {
55   - term_printf("Invalid pci address\n");
  55 + monitor_printf(mon, "Invalid pci address\n");
56 56 return;
57 57 }
58 58  
59 59 dev = pci_find_device(pci_bus, slot, 0);
60 60 if (!dev) {
61   - term_printf("no pci device with address %s\n", pci_addr);
  61 + monitor_printf(mon, "no pci device with address %s\n", pci_addr);
62 62 return;
63 63 }
64 64  
... ... @@ -75,16 +75,18 @@ void drive_hot_add(const char *pci_addr, const char *opts)
75 75 drives_table[drive_idx].unit);
76 76 break;
77 77 default:
78   - term_printf("Can't hot-add drive to type %d\n", type);
  78 + monitor_printf(mon, "Can't hot-add drive to type %d\n", type);
79 79 }
80 80  
81 81 if (success)
82   - term_printf("OK bus %d, unit %d\n", drives_table[drive_idx].bus,
83   - drives_table[drive_idx].unit);
  82 + monitor_printf(mon, "OK bus %d, unit %d\n",
  83 + drives_table[drive_idx].bus,
  84 + drives_table[drive_idx].unit);
84 85 return;
85 86 }
86 87  
87   -static PCIDevice *qemu_pci_hot_add_storage(PCIBus *pci_bus, const char *opts)
  88 +static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, PCIBus *pci_bus,
  89 + const char *opts)
88 90 {
89 91 void *opaque = NULL;
90 92 int type = -1, drive_idx = -1;
... ... @@ -97,7 +99,7 @@ static PCIDevice *qemu_pci_hot_add_storage(PCIBus *pci_bus, const char *opts)
97 99 type = IF_VIRTIO;
98 100 }
99 101 } else {
100   - term_printf("no if= specified\n");
  102 + monitor_printf(mon, "no if= specified\n");
101 103 return NULL;
102 104 }
103 105  
... ... @@ -106,7 +108,7 @@ static PCIDevice *qemu_pci_hot_add_storage(PCIBus *pci_bus, const char *opts)
106 108 if (drive_idx < 0)
107 109 return NULL;
108 110 } else if (type == IF_VIRTIO) {
109   - term_printf("virtio requires a backing file/device.\n");
  111 + monitor_printf(mon, "virtio requires a backing file/device.\n");
110 112 return NULL;
111 113 }
112 114  
... ... @@ -121,13 +123,14 @@ static PCIDevice *qemu_pci_hot_add_storage(PCIBus *pci_bus, const char *opts)
121 123 opaque = virtio_blk_init (pci_bus, drives_table[drive_idx].bdrv);
122 124 break;
123 125 default:
124   - term_printf ("type %s not a hotpluggable PCI device.\n", buf);
  126 + monitor_printf(mon, "type %s not a hotpluggable PCI device.\n", buf);
125 127 }
126 128  
127 129 return opaque;
128 130 }
129 131  
130   -void pci_device_hot_add(const char *pci_addr, const char *type, const char *opts)
  132 +void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
  133 + const char *opts)
131 134 {
132 135 PCIDevice *dev = NULL;
133 136 PCIBus *pci_bus;
... ... @@ -135,47 +138,47 @@ void pci_device_hot_add(const char *pci_addr, const char *type, const char *opts
135 138 unsigned slot;
136 139  
137 140 if (pci_assign_devaddr(pci_addr, &dom, &bus, &slot)) {
138   - term_printf("Invalid pci address\n");
  141 + monitor_printf(mon, "Invalid pci address\n");
139 142 return;
140 143 }
141 144  
142 145 pci_bus = pci_find_bus(bus);
143 146 if (!pci_bus) {
144   - term_printf("Can't find pci_bus %d\n", bus);
  147 + monitor_printf(mon, "Can't find pci_bus %d\n", bus);
145 148 return;
146 149 }
147 150  
148 151 if (strcmp(type, "nic") == 0)
149 152 dev = qemu_pci_hot_add_nic(pci_bus, opts);
150 153 else if (strcmp(type, "storage") == 0)
151   - dev = qemu_pci_hot_add_storage(pci_bus, opts);
  154 + dev = qemu_pci_hot_add_storage(mon, pci_bus, opts);
152 155 else
153   - term_printf("invalid type: %s\n", type);
  156 + monitor_printf(mon, "invalid type: %s\n", type);
154 157  
155 158 if (dev) {
156 159 qemu_system_device_hot_add(bus, PCI_SLOT(dev->devfn), 1);
157   - term_printf("OK domain %d, bus %d, slot %d, function %d\n",
158   - 0, pci_bus_num(dev->bus), PCI_SLOT(dev->devfn),
159   - PCI_FUNC(dev->devfn));
  160 + monitor_printf(mon, "OK domain %d, bus %d, slot %d, function %d\n",
  161 + 0, pci_bus_num(dev->bus), PCI_SLOT(dev->devfn),
  162 + PCI_FUNC(dev->devfn));
160 163 } else
161   - term_printf("failed to add %s\n", opts);
  164 + monitor_printf(mon, "failed to add %s\n", opts);
162 165 }
163 166 #endif
164 167  
165   -void pci_device_hot_remove(const char *pci_addr)
  168 +void pci_device_hot_remove(Monitor *mon, const char *pci_addr)
166 169 {
167 170 PCIDevice *d;
168 171 int dom, bus;
169 172 unsigned slot;
170 173  
171 174 if (pci_read_devaddr(pci_addr, &dom, &bus, &slot)) {
172   - term_printf("Invalid pci address\n");
  175 + monitor_printf(mon, "Invalid pci address\n");
173 176 return;
174 177 }
175 178  
176 179 d = pci_find_device(bus, slot, 0);
177 180 if (!d) {
178   - term_printf("slot %d empty\n", slot);
  181 + monitor_printf(mon, "slot %d empty\n", slot);
179 182 return;
180 183 }
181 184  
... ... @@ -199,7 +202,7 @@ void pci_device_hot_remove_success(int pcibus, int slot)
199 202 int class_code;
200 203  
201 204 if (!d) {
202   - term_printf("invalid slot %d\n", slot);
  205 + monitor_printf(cur_mon, "invalid slot %d\n", slot);
203 206 return;
204 207 }
205 208  
... ...
hw/pci.c
... ... @@ -23,7 +23,7 @@
23 23 */
24 24 #include "hw.h"
25 25 #include "pci.h"
26   -#include "console.h"
  26 +#include "monitor.h"
27 27 #include "net.h"
28 28 #include "virtio-net.h"
29 29 #include "sysemu.h"
... ... @@ -705,42 +705,44 @@ static const pci_class_desc pci_class_descriptions[] =
705 705  
706 706 static void pci_info_device(PCIDevice *d)
707 707 {
  708 + Monitor *mon = cur_mon;
708 709 int i, class;
709 710 PCIIORegion *r;
710 711 const pci_class_desc *desc;
711 712  
712   - term_printf(" Bus %2d, device %3d, function %d:\n",
713   - d->bus->bus_num, d->devfn >> 3, d->devfn & 7);
  713 + monitor_printf(mon, " Bus %2d, device %3d, function %d:\n",
  714 + d->bus->bus_num, d->devfn >> 3, d->devfn & 7);
714 715 class = le16_to_cpu(*((uint16_t *)(d->config + PCI_CLASS_DEVICE)));
715   - term_printf(" ");
  716 + monitor_printf(mon, " ");
716 717 desc = pci_class_descriptions;
717 718 while (desc->desc && class != desc->class)
718 719 desc++;
719 720 if (desc->desc) {
720   - term_printf("%s", desc->desc);
  721 + monitor_printf(mon, "%s", desc->desc);
721 722 } else {
722   - term_printf("Class %04x", class);
  723 + monitor_printf(mon, "Class %04x", class);
723 724 }
724   - term_printf(": PCI device %04x:%04x\n",
  725 + monitor_printf(mon, ": PCI device %04x:%04x\n",
725 726 le16_to_cpu(*((uint16_t *)(d->config + PCI_VENDOR_ID))),
726 727 le16_to_cpu(*((uint16_t *)(d->config + PCI_DEVICE_ID))));
727 728  
728 729 if (d->config[PCI_INTERRUPT_PIN] != 0) {
729   - term_printf(" IRQ %d.\n", d->config[PCI_INTERRUPT_LINE]);
  730 + monitor_printf(mon, " IRQ %d.\n",
  731 + d->config[PCI_INTERRUPT_LINE]);
730 732 }
731 733 if (class == 0x0604) {
732   - term_printf(" BUS %d.\n", d->config[0x19]);
  734 + monitor_printf(mon, " BUS %d.\n", d->config[0x19]);
733 735 }
734 736 for(i = 0;i < PCI_NUM_REGIONS; i++) {
735 737 r = &d->io_regions[i];
736 738 if (r->size != 0) {
737   - term_printf(" BAR%d: ", i);
  739 + monitor_printf(mon, " BAR%d: ", i);
738 740 if (r->type & PCI_ADDRESS_SPACE_IO) {
739   - term_printf("I/O at 0x%04x [0x%04x].\n",
740   - r->addr, r->addr + r->size - 1);
  741 + monitor_printf(mon, "I/O at 0x%04x [0x%04x].\n",
  742 + r->addr, r->addr + r->size - 1);
741 743 } else {
742   - term_printf("32 bit memory at 0x%08x [0x%08x].\n",
743   - r->addr, r->addr + r->size - 1);
  744 + monitor_printf(mon, "32 bit memory at 0x%08x [0x%08x].\n",
  745 + r->addr, r->addr + r->size - 1);
744 746 }
745 747 }
746 748 }
... ... @@ -766,7 +768,7 @@ void pci_for_each_device(int bus_num, void (*fn)(PCIDevice *d))
766 768 }
767 769 }
768 770  
769   -void pci_info(void)
  771 +void pci_info(Monitor *mon)
770 772 {
771 773 pci_for_each_device(0, pci_info_device);
772 774 }
... ...
hw/pci.h
1 1 #ifndef QEMU_PCI_H
2 2 #define QEMU_PCI_H
3 3  
  4 +#include "qemu-common.h"
  5 +
4 6 /* PCI includes legacy ISA access. */
5 7 #include "isa.h"
6 8  
... ... @@ -242,7 +244,7 @@ PCIDevice *pci_find_device(int bus_num, int slot, int function);
242 244 int pci_read_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp);
243 245 int pci_assign_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp);
244 246  
245   -void pci_info(void);
  247 +void pci_info(Monitor *mon);
246 248 PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
247 249 pci_map_irq_fn map_irq, const char *name);
248 250  
... ...
hw/pcmcia.h
1 1 /* PCMCIA/Cardbus */
2 2  
  3 +#include "qemu-common.h"
  4 +
3 5 struct pcmcia_socket_s {
4 6 qemu_irq irq;
5 7 int attached;
... ... @@ -9,7 +11,7 @@ struct pcmcia_socket_s {
9 11  
10 12 void pcmcia_socket_register(struct pcmcia_socket_s *socket);
11 13 void pcmcia_socket_unregister(struct pcmcia_socket_s *socket);
12   -void pcmcia_info(void);
  14 +void pcmcia_info(Monitor *mon);
13 15  
14 16 struct pcmcia_card_s {
15 17 void *state;
... ...
hw/shix.c
... ... @@ -28,6 +28,7 @@
28 28 More information in target-sh4/README.sh4
29 29 */
30 30 #include "hw.h"
  31 +#include "pc.h"
31 32 #include "sh.h"
32 33 #include "sysemu.h"
33 34 #include "boards.h"
... ... @@ -35,12 +36,12 @@
35 36 #define BIOS_FILENAME "shix_bios.bin"
36 37 #define BIOS_ADDRESS 0xA0000000
37 38  
38   -void irq_info(void)
  39 +void irq_info(Monitor *mon)
39 40 {
40 41 /* XXXXX */
41 42 }
42 43  
43   -void pic_info(void)
  44 +void pic_info(Monitor *mon)
44 45 {
45 46 /* XXXXX */
46 47 }
... ...
hw/slavio_intctl.c
... ... @@ -23,7 +23,7 @@
23 23 */
24 24 #include "hw.h"
25 25 #include "sun4m.h"
26   -#include "console.h"
  26 +#include "monitor.h"
27 27  
28 28 //#define DEBUG_IRQ_COUNT
29 29 //#define DEBUG_IRQ
... ... @@ -219,33 +219,33 @@ static CPUWriteMemoryFunc *slavio_intctlm_mem_write[3] = {
219 219 slavio_intctlm_mem_writel,
220 220 };
221 221  
222   -void slavio_pic_info(void *opaque)
  222 +void slavio_pic_info(Monitor *mon, void *opaque)
223 223 {
224 224 SLAVIO_INTCTLState *s = opaque;
225 225 int i;
226 226  
227 227 for (i = 0; i < MAX_CPUS; i++) {
228   - term_printf("per-cpu %d: pending 0x%08x\n", i,
229   - s->slaves[i]->intreg_pending);
  228 + monitor_printf(mon, "per-cpu %d: pending 0x%08x\n", i,
  229 + s->slaves[i]->intreg_pending);
230 230 }
231   - term_printf("master: pending 0x%08x, disabled 0x%08x\n",
232   - s->intregm_pending, s->intregm_disabled);
  231 + monitor_printf(mon, "master: pending 0x%08x, disabled 0x%08x\n",
  232 + s->intregm_pending, s->intregm_disabled);
233 233 }
234 234  
235   -void slavio_irq_info(void *opaque)
  235 +void slavio_irq_info(Monitor *mon, void *opaque)
236 236 {
237 237 #ifndef DEBUG_IRQ_COUNT
238   - term_printf("irq statistic code not compiled.\n");
  238 + monitor_printf(mon, "irq statistic code not compiled.\n");
239 239 #else
240 240 SLAVIO_INTCTLState *s = opaque;
241 241 int i;
242 242 int64_t count;
243 243  
244   - term_printf("IRQ statistics:\n");
  244 + monitor_printf(mon, "IRQ statistics:\n");
245 245 for (i = 0; i < 32; i++) {
246 246 count = s->irq_count[i];
247 247 if (count > 0)
248   - term_printf("%2d: %" PRId64 "\n", i, count);
  248 + monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
249 249 }
250 250 #endif
251 251 }
... ...
hw/sun4c_intctl.c
... ... @@ -23,7 +23,7 @@
23 23 */
24 24 #include "hw.h"
25 25 #include "sun4m.h"
26   -#include "console.h"
  26 +#include "monitor.h"
27 27 //#define DEBUG_IRQ_COUNT
28 28 //#define DEBUG_IRQ
29 29  
... ... @@ -90,26 +90,26 @@ static CPUWriteMemoryFunc *sun4c_intctl_mem_write[3] = {
90 90 NULL,
91 91 };
92 92  
93   -void sun4c_pic_info(void *opaque)
  93 +void sun4c_pic_info(Monitor *mon, void *opaque)
94 94 {
95 95 Sun4c_INTCTLState *s = opaque;
96 96  
97   - term_printf("master: pending 0x%2.2x, enabled 0x%2.2x\n", s->pending,
98   - s->reg);
  97 + monitor_printf(mon, "master: pending 0x%2.2x, enabled 0x%2.2x\n",
  98 + s->pending, s->reg);
99 99 }
100 100  
101   -void sun4c_irq_info(void *opaque)
  101 +void sun4c_irq_info(Monitor *mon, void *opaque)
102 102 {
103 103 #ifndef DEBUG_IRQ_COUNT
104   - term_printf("irq statistic code not compiled.\n");
  104 + monitor_printf(mon, "irq statistic code not compiled.\n");
105 105 #else
106 106 Sun4c_INTCTLState *s = opaque;
107 107 int64_t count;
108 108  
109   - term_printf("IRQ statistics:\n");
  109 + monitor_printf(mon, "IRQ statistics:\n");
110 110 count = s->irq_count[i];
111 111 if (count > 0)
112   - term_printf("%2d: %" PRId64 "\n", i, count);
  112 + monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
113 113 #endif
114 114 }
115 115  
... ...
hw/sun4m.c
... ... @@ -283,16 +283,16 @@ static void nvram_init(m48t59_t *nvram, uint8_t *macaddr, const char *cmdline,
283 283  
284 284 static void *slavio_intctl;
285 285  
286   -void pic_info(void)
  286 +void pic_info(Monitor *mon)
287 287 {
288 288 if (slavio_intctl)
289   - slavio_pic_info(slavio_intctl);
  289 + slavio_pic_info(mon, slavio_intctl);
290 290 }
291 291  
292   -void irq_info(void)
  292 +void irq_info(Monitor *mon)
293 293 {
294 294 if (slavio_intctl)
295   - slavio_irq_info(slavio_intctl);
  295 + slavio_irq_info(mon, slavio_intctl);
296 296 }
297 297  
298 298 void cpu_check_irqs(CPUState *env)
... ...
hw/sun4m.h
1 1 #ifndef SUN4M_H
2 2 #define SUN4M_H
3 3  
  4 +#include "qemu-common.h"
  5 +
4 6 /* Devices used by sparc32 system. */
5 7  
6 8 /* iommu.c */
... ... @@ -31,8 +33,8 @@ void *slavio_intctl_init(target_phys_addr_t addr, target_phys_addr_t addrg,
31 33 const uint32_t *intbit_to_level,
32 34 qemu_irq **irq, qemu_irq **cpu_irq,
33 35 qemu_irq **parent_irq, unsigned int cputimer);
34   -void slavio_pic_info(void *opaque);
35   -void slavio_irq_info(void *opaque);
  36 +void slavio_pic_info(Monitor *mon, void *opaque);
  37 +void slavio_irq_info(Monitor *mon, void *opaque);
36 38  
37 39 /* sbi.c */
38 40 void *sbi_init(target_phys_addr_t addr, qemu_irq **irq, qemu_irq **cpu_irq,
... ... @@ -41,8 +43,8 @@ void *sbi_init(target_phys_addr_t addr, qemu_irq **irq, qemu_irq **cpu_irq,
41 43 /* sun4c_intctl.c */
42 44 void *sun4c_intctl_init(target_phys_addr_t addr, qemu_irq **irq,
43 45 qemu_irq *parent_irq);
44   -void sun4c_pic_info(void *opaque);
45   -void sun4c_irq_info(void *opaque);
  46 +void sun4c_pic_info(Monitor *mon, void *opaque);
  47 +void sun4c_irq_info(Monitor *mon, void *opaque);
46 48  
47 49 /* slavio_timer.c */
48 50 void slavio_timer_init_all(target_phys_addr_t base, qemu_irq master_irq,
... ...
hw/usb.h
... ... @@ -244,7 +244,7 @@ USBDevice *usb_hub_init(int nb_ports);
244 244 /* usb-linux.c */
245 245 USBDevice *usb_host_device_open(const char *devname);
246 246 int usb_host_device_close(const char *devname);
247   -void usb_host_info(void);
  247 +void usb_host_info(Monitor *mon);
248 248  
249 249 /* usb-hid.c */
250 250 USBDevice *usb_mouse_init(void);
... ...
migration-exec.c
... ... @@ -18,7 +18,7 @@
18 18 #include "migration.h"
19 19 #include "qemu-char.h"
20 20 #include "sysemu.h"
21   -#include "console.h"
  21 +#include "monitor.h"
22 22 #include "buffered_file.h"
23 23 #include "block.h"
24 24  
... ... @@ -94,7 +94,7 @@ MigrationState *exec_start_outgoing_migration(const char *command,
94 94  
95 95 if (s->detach == 1) {
96 96 dprintf("detaching from monitor\n");
97   - monitor_suspend();
  97 + monitor_suspend(cur_mon);
98 98 s->detach = 2;
99 99 }
100 100  
... ...
migration-tcp.c
... ... @@ -16,7 +16,7 @@
16 16 #include "migration.h"
17 17 #include "qemu-char.h"
18 18 #include "sysemu.h"
19   -#include "console.h"
  19 +#include "monitor.h"
20 20 #include "buffered_file.h"
21 21 #include "block.h"
22 22  
... ... @@ -110,7 +110,7 @@ MigrationState *tcp_start_outgoing_migration(const char *host_port,
110 110  
111 111 if (s->detach == 1) {
112 112 dprintf("detaching from monitor\n");
113   - monitor_suspend();
  113 + monitor_suspend(cur_mon);
114 114 s->detach = 2;
115 115 }
116 116  
... ...
migration.c
... ... @@ -13,7 +13,7 @@
13 13  
14 14 #include "qemu-common.h"
15 15 #include "migration.h"
16   -#include "console.h"
  16 +#include "monitor.h"
17 17 #include "buffered_file.h"
18 18 #include "sysemu.h"
19 19 #include "block.h"
... ... @@ -48,7 +48,7 @@ void qemu_start_incoming_migration(const char *uri)
48 48 fprintf(stderr, "unknown migration protocol: %s\n", uri);
49 49 }
50 50  
51   -void do_migrate(int detach, const char *uri)
  51 +void do_migrate(Monitor *mon, int detach, const char *uri)
52 52 {
53 53 MigrationState *s = NULL;
54 54 const char *p;
... ... @@ -60,10 +60,10 @@ void do_migrate(int detach, const char *uri)
60 60 s = exec_start_outgoing_migration(p, max_throttle, detach);
61 61 #endif
62 62 else
63   - term_printf("unknown migration protocol: %s\n", uri);
  63 + monitor_printf(mon, "unknown migration protocol: %s\n", uri);
64 64  
65 65 if (s == NULL)
66   - term_printf("migration failed\n");
  66 + monitor_printf(mon, "migration failed\n");
67 67 else {
68 68 if (current_migration)
69 69 current_migration->release(current_migration);
... ... @@ -72,7 +72,7 @@ void do_migrate(int detach, const char *uri)
72 72 }
73 73 }
74 74  
75   -void do_migrate_cancel(void)
  75 +void do_migrate_cancel(Monitor *mon)
76 76 {
77 77 MigrationState *s = current_migration;
78 78  
... ... @@ -80,7 +80,7 @@ void do_migrate_cancel(void)
80 80 s->cancel(s);
81 81 }
82 82  
83   -void do_migrate_set_speed(const char *value)
  83 +void do_migrate_set_speed(Monitor *mon, const char *value)
84 84 {
85 85 double d;
86 86 char *ptr;
... ... @@ -100,24 +100,24 @@ void do_migrate_set_speed(const char *value)
100 100 max_throttle = (uint32_t)d;
101 101 }
102 102  
103   -void do_info_migrate(void)
  103 +void do_info_migrate(Monitor *mon)
104 104 {
105 105 MigrationState *s = current_migration;
106   -
  106 +
107 107 if (s) {
108   - term_printf("Migration status: ");
  108 + monitor_printf(mon, "Migration status: ");
109 109 switch (s->get_status(s)) {
110 110 case MIG_STATE_ACTIVE:
111   - term_printf("active\n");
  111 + monitor_printf(mon, "active\n");
112 112 break;
113 113 case MIG_STATE_COMPLETED:
114   - term_printf("completed\n");
  114 + monitor_printf(mon, "completed\n");
115 115 break;
116 116 case MIG_STATE_ERROR:
117   - term_printf("failed\n");
  117 + monitor_printf(mon, "failed\n");
118 118 break;
119 119 case MIG_STATE_CANCELLED:
120   - term_printf("cancelled\n");
  120 + monitor_printf(mon, "cancelled\n");
121 121 break;
122 122 }
123 123 }
... ... @@ -146,7 +146,7 @@ void migrate_fd_cleanup(FdMigrationState *s)
146 146  
147 147 /* Don't resume monitor until we've flushed all of the buffers */
148 148 if (s->detach == 2) {
149   - monitor_resume();
  149 + monitor_resume(cur_mon);
150 150 s->detach = 0;
151 151 }
152 152  
... ...
migration.h
... ... @@ -14,6 +14,8 @@
14 14 #ifndef QEMU_MIGRATION_H
15 15 #define QEMU_MIGRATION_H
16 16  
  17 +#include "qemu-common.h"
  18 +
17 19 #define MIG_STATE_ERROR -1
18 20 #define MIG_STATE_COMPLETED 0
19 21 #define MIG_STATE_CANCELLED 1
... ... @@ -47,13 +49,13 @@ struct FdMigrationState
47 49  
48 50 void qemu_start_incoming_migration(const char *uri);
49 51  
50   -void do_migrate(int detach, const char *uri);
  52 +void do_migrate(Monitor *mon, int detach, const char *uri);
51 53  
52   -void do_migrate_cancel(void);
  54 +void do_migrate_cancel(Monitor *mon);
53 55  
54   -void do_migrate_set_speed(const char *value);
  56 +void do_migrate_set_speed(Monitor *mon, const char *value);
55 57  
56   -void do_info_migrate(void);
  58 +void do_info_migrate(Monitor *mon);
57 59  
58 60 int exec_start_incoming_migration(const char *host_port);
59 61  
... ...
monitor.c
... ... @@ -30,6 +30,8 @@
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,36 +59,39 @@
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,7 +103,7 @@ void term_flush(void)
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,26 +115,26 @@ void term_puts(const char *str)
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,19 +143,19 @@ void term_print_filename(const char *filename)
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,7 +165,7 @@ static int monitor_fprintf(FILE *stream, const char *fmt, ...)
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,39 +190,36 @@ static int compare_cmd(const char *name, const char *list)
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,10 +231,10 @@ static void do_commit(const char *device)
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,48 +243,39 @@ static void do_info(const char *item)
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,22 +300,22 @@ static CPUState *mon_get_cpu(void)
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,36 +323,38 @@ static void do_info_cpus(void)
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,37 +364,37 @@ static void do_info_history (void)
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,50 +403,52 @@ static int eject_device(BlockDriverState *bs, int force)
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,36 +456,37 @@ static void do_change_vnc(const char *target, const char *arg)
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,88 +495,97 @@ static void do_log(const char *items)
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,7 +619,7 @@ static void memory_dump(int count, int format, int wsize,
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,9 +650,9 @@ static void memory_dump(int count, int format, int wsize,
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,7 +663,7 @@ static void memory_dump(int count, int format, int wsize,
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,27 +684,27 @@ static void memory_dump(int count, int format, int wsize,
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,11 +716,11 @@ static void memory_dump(int count, int format, int wsize,
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,60 +729,61 @@ static void do_memory_dump(int count, int format, int size,
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,7 +798,7 @@ static void do_memory_save(unsigned int valh, unsigned int vall,
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,8 +813,9 @@ static void do_memory_save(unsigned int valh, unsigned int vall,
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,7 +824,7 @@ static void do_physical_memory_save(unsigned int valh, unsigned int vall,
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,7 +840,7 @@ static void do_physical_memory_save(unsigned int valh, unsigned int vall,
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,7 +853,7 @@ static void do_sum(uint32_t start, uint32_t size)
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,7 +1036,8 @@ static void release_keys(void *opaque)
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,17 +1056,17 @@ static void do_sendkey(const char *string, int has_hold_time, int hold_time)
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,7 +1090,7 @@ static void do_sendkey(const char *string, int has_hold_time, int hold_time)
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,13 +1102,14 @@ static void do_mouse_move(const char *dx_str, const char *dy_str,
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,8 +1135,8 @@ static void do_ioport_read(int count, int format, int size, int addr, int has_in
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,48 +1149,51 @@ void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
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,7 +1204,7 @@ static void tlb_info(void)
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,14 +1213,14 @@ static void tlb_info(void)
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,18 +1230,18 @@ static void tlb_info(void)
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,7 +1251,7 @@ static void mem_print(uint32_t *pstart, int *plast_prot,
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,7 +1262,7 @@ static void mem_info(void)
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,7 +1275,7 @@ static void mem_info(void)
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,12 +1287,12 @@ static void mem_info(void)
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,34 +1300,34 @@ static void mem_info(void)
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,38 +1335,38 @@ static void do_info_kqemu(void)
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,23 +1380,25 @@ int64_t kqemu_ret_int_count;
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,27 +1411,27 @@ static void do_info_profile(void)
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,10 +1447,10 @@ static void do_stop_capture (int n)
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,7 +1461,7 @@ static void do_wav_capture (const char *path,
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,7 +1469,7 @@ static void do_wav_capture (const char *path,
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,37 +1481,38 @@ static void do_inject_nmi(int cpu_index)
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,16 +1618,16 @@ static const term_cmd_t term_cmds[] = {
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,9 +2037,9 @@ static const MonitorDef monitor_defs[] = {
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,9 +2085,9 @@ static void next(void)
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,32 +2096,32 @@ static int64_t expr_unary(void)
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,14 +2144,14 @@ static int64_t expr_unary(void)
2127 2144 *q = 0;
2128 2145 ret = get_monitor_def(&reg, 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,7 +2161,7 @@ static int64_t expr_unary(void)
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,18 +2172,18 @@ static int64_t expr_unary(void)
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,7 +2192,7 @@ static int64_t expr_prod(void)
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,18 +2203,18 @@ static int64_t expr_prod(void)
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();
  2211 + val = expr_prod(mon);
2195 2212 for(;;) {
2196 2213 op = *pch;
2197 2214 if (op != '&' && op != '|' && op != '^')
2198 2215 break;
2199 2216 next();
2200   - val2 = expr_prod();
  2217 + val2 = expr_prod(mon);
2201 2218 switch(op) {
2202 2219 default:
2203 2220 case '&':
... ... @@ -2214,18 +2231,18 @@ static int64_t expr_logic(void)
2214 2231 return val;
2215 2232 }
2216 2233  
2217   -static int64_t expr_sum(void)
  2234 +static int64_t expr_sum(Monitor *mon)
2218 2235 {
2219 2236 int64_t val, val2;
2220 2237 int op;
2221 2238  
2222   - val = expr_logic();
  2239 + val = expr_logic(mon);
2223 2240 for(;;) {
2224 2241 op = *pch;
2225 2242 if (op != '+' && op != '-')
2226 2243 break;
2227 2244 next();
2228   - val2 = expr_logic();
  2245 + val2 = expr_logic(mon);
2229 2246 if (op == '+')
2230 2247 val += val2;
2231 2248 else
... ... @@ -2234,7 +2251,7 @@ static int64_t expr_sum(void)
2234 2251 return val;
2235 2252 }
2236 2253  
2237   -static int get_expr(int64_t *pval, const char **pp)
  2254 +static int get_expr(Monitor *mon, int64_t *pval, const char **pp)
2238 2255 {
2239 2256 pch = *pp;
2240 2257 if (setjmp(expr_env)) {
... ... @@ -2243,7 +2260,7 @@ static int get_expr(int64_t *pval, const char **pp)
2243 2260 }
2244 2261 while (qemu_isspace(*pch))
2245 2262 pch++;
2246   - *pval = expr_sum();
  2263 + *pval = expr_sum(mon);
2247 2264 *pp = pch;
2248 2265 return 0;
2249 2266 }
... ... @@ -2318,30 +2335,31 @@ static int default_fmt_size = 4;
2318 2335  
2319 2336 #define MAX_ARGS 16
2320 2337  
2321   -static void monitor_handle_command(const char *cmdline)
  2338 +static void monitor_handle_command(Monitor *mon, const char *cmdline)
2322 2339 {
2323 2340 const char *p, *pstart, *typestr;
2324 2341 char *q;
2325 2342 int c, nb_args, len, i, has_arg;
2326   - const term_cmd_t *cmd;
  2343 + const mon_cmd_t *cmd;
2327 2344 char cmdname[256];
2328 2345 char buf[1024];
2329 2346 void *str_allocated[MAX_ARGS];
2330 2347 void *args[MAX_ARGS];
2331   - void (*handler_0)(void);
2332   - void (*handler_1)(void *arg0);
2333   - void (*handler_2)(void *arg0, void *arg1);
2334   - void (*handler_3)(void *arg0, void *arg1, void *arg2);
2335   - void (*handler_4)(void *arg0, void *arg1, void *arg2, void *arg3);
2336   - void (*handler_5)(void *arg0, void *arg1, void *arg2, void *arg3,
2337   - void *arg4);
2338   - void (*handler_6)(void *arg0, void *arg1, void *arg2, void *arg3,
2339   - void *arg4, void *arg5);
2340   - void (*handler_7)(void *arg0, void *arg1, void *arg2, void *arg3,
2341   - void *arg4, void *arg5, void *arg6);
  2348 + void (*handler_0)(Monitor *mon);
  2349 + void (*handler_1)(Monitor *mon, void *arg0);
  2350 + void (*handler_2)(Monitor *mon, void *arg0, void *arg1);
  2351 + void (*handler_3)(Monitor *mon, void *arg0, void *arg1, void *arg2);
  2352 + void (*handler_4)(Monitor *mon, void *arg0, void *arg1, void *arg2,
  2353 + void *arg3);
  2354 + void (*handler_5)(Monitor *mon, void *arg0, void *arg1, void *arg2,
  2355 + void *arg3, void *arg4);
  2356 + void (*handler_6)(Monitor *mon, void *arg0, void *arg1, void *arg2,
  2357 + void *arg3, void *arg4, void *arg5);
  2358 + void (*handler_7)(Monitor *mon, void *arg0, void *arg1, void *arg2,
  2359 + void *arg3, void *arg4, void *arg5, void *arg6);
2342 2360  
2343 2361 #ifdef DEBUG
2344   - term_printf("command='%s'\n", cmdline);
  2362 + monitor_printf(mon, "command='%s'\n", cmdline);
2345 2363 #endif
2346 2364  
2347 2365 /* extract the command name */
... ... @@ -2361,11 +2379,11 @@ static void monitor_handle_command(const char *cmdline)
2361 2379 cmdname[len] = '\0';
2362 2380  
2363 2381 /* find the command */
2364   - for(cmd = term_cmds; cmd->name != NULL; cmd++) {
  2382 + for(cmd = mon_cmds; cmd->name != NULL; cmd++) {
2365 2383 if (compare_cmd(cmdname, cmd->name))
2366 2384 goto found;
2367 2385 }
2368   - term_printf("unknown command: '%s'\n", cmdname);
  2386 + monitor_printf(mon, "unknown command: '%s'\n", cmdname);
2369 2387 return;
2370 2388 found:
2371 2389  
... ... @@ -2402,13 +2420,15 @@ static void monitor_handle_command(const char *cmdline)
2402 2420 if (ret < 0) {
2403 2421 switch(c) {
2404 2422 case 'F':
2405   - term_printf("%s: filename expected\n", cmdname);
  2423 + monitor_printf(mon, "%s: filename expected\n",
  2424 + cmdname);
2406 2425 break;
2407 2426 case 'B':
2408   - term_printf("%s: block device name expected\n", cmdname);
  2427 + monitor_printf(mon, "%s: block device name expected\n",
  2428 + cmdname);
2409 2429 break;
2410 2430 default:
2411   - term_printf("%s: string expected\n", cmdname);
  2431 + monitor_printf(mon, "%s: string expected\n", cmdname);
2412 2432 break;
2413 2433 }
2414 2434 goto fail;
... ... @@ -2419,7 +2439,7 @@ static void monitor_handle_command(const char *cmdline)
2419 2439 add_str:
2420 2440 if (nb_args >= MAX_ARGS) {
2421 2441 error_args:
2422   - term_printf("%s: too many arguments\n", cmdname);
  2442 + monitor_printf(mon, "%s: too many arguments\n", cmdname);
2423 2443 goto fail;
2424 2444 }
2425 2445 args[nb_args++] = str;
... ... @@ -2477,7 +2497,8 @@ static void monitor_handle_command(const char *cmdline)
2477 2497 }
2478 2498 next:
2479 2499 if (*p != '\0' && !qemu_isspace(*p)) {
2480   - term_printf("invalid char in format: '%c'\n", *p);
  2500 + monitor_printf(mon, "invalid char in format: '%c'\n",
  2501 + *p);
2481 2502 goto fail;
2482 2503 }
2483 2504 if (format < 0)
... ... @@ -2539,7 +2560,7 @@ static void monitor_handle_command(const char *cmdline)
2539 2560 goto add_num;
2540 2561 }
2541 2562 }
2542   - if (get_expr(&val, &p))
  2563 + if (get_expr(mon, &val, &p))
2543 2564 goto fail;
2544 2565 add_num:
2545 2566 if (c == 'i') {
... ... @@ -2572,8 +2593,8 @@ static void monitor_handle_command(const char *cmdline)
2572 2593 if (*p == '-') {
2573 2594 p++;
2574 2595 if (*p != c) {
2575   - term_printf("%s: unsupported option -%c\n",
2576   - cmdname, *p);
  2596 + monitor_printf(mon, "%s: unsupported option -%c\n",
  2597 + cmdname, *p);
2577 2598 goto fail;
2578 2599 }
2579 2600 p++;
... ... @@ -2586,7 +2607,7 @@ static void monitor_handle_command(const char *cmdline)
2586 2607 break;
2587 2608 default:
2588 2609 bad_type:
2589   - term_printf("%s: unknown type '%c'\n", cmdname, c);
  2610 + monitor_printf(mon, "%s: unknown type '%c'\n", cmdname, c);
2590 2611 goto fail;
2591 2612 }
2592 2613 }
... ... @@ -2594,46 +2615,47 @@ static void monitor_handle_command(const char *cmdline)
2594 2615 while (qemu_isspace(*p))
2595 2616 p++;
2596 2617 if (*p != '\0') {
2597   - term_printf("%s: extraneous characters at the end of line\n",
2598   - cmdname);
  2618 + monitor_printf(mon, "%s: extraneous characters at the end of line\n",
  2619 + cmdname);
2599 2620 goto fail;
2600 2621 }
2601 2622  
2602 2623 switch(nb_args) {
2603 2624 case 0:
2604 2625 handler_0 = cmd->handler;
2605   - handler_0();
  2626 + handler_0(mon);
2606 2627 break;
2607 2628 case 1:
2608 2629 handler_1 = cmd->handler;
2609   - handler_1(args[0]);
  2630 + handler_1(mon, args[0]);
2610 2631 break;
2611 2632 case 2:
2612 2633 handler_2 = cmd->handler;
2613   - handler_2(args[0], args[1]);
  2634 + handler_2(mon, args[0], args[1]);
2614 2635 break;
2615 2636 case 3:
2616 2637 handler_3 = cmd->handler;
2617   - handler_3(args[0], args[1], args[2]);
  2638 + handler_3(mon, args[0], args[1], args[2]);
2618 2639 break;
2619 2640 case 4:
2620 2641 handler_4 = cmd->handler;
2621   - handler_4(args[0], args[1], args[2], args[3]);
  2642 + handler_4(mon, args[0], args[1], args[2], args[3]);
2622 2643 break;
2623 2644 case 5:
2624 2645 handler_5 = cmd->handler;
2625   - handler_5(args[0], args[1], args[2], args[3], args[4]);
  2646 + handler_5(mon, args[0], args[1], args[2], args[3], args[4]);
2626 2647 break;
2627 2648 case 6:
2628 2649 handler_6 = cmd->handler;
2629   - handler_6(args[0], args[1], args[2], args[3], args[4], args[5]);
  2650 + handler_6(mon, args[0], args[1], args[2], args[3], args[4], args[5]);
2630 2651 break;
2631 2652 case 7:
2632 2653 handler_7 = cmd->handler;
2633   - handler_7(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  2654 + handler_7(mon, args[0], args[1], args[2], args[3], args[4], args[5],
  2655 + args[6]);
2634 2656 break;
2635 2657 default:
2636   - term_printf("unsupported number of arguments: %d\n", nb_args);
  2658 + monitor_printf(mon, "unsupported number of arguments: %d\n", nb_args);
2637 2659 goto fail;
2638 2660 }
2639 2661 fail:
... ... @@ -2660,7 +2682,7 @@ static void cmd_completion(const char *name, const char *list)
2660 2682 memcpy(cmd, pstart, len);
2661 2683 cmd[len] = '\0';
2662 2684 if (name[0] == '\0' || !strncmp(name, cmd, strlen(name))) {
2663   - add_completion(cmd);
  2685 + readline_add_completion(cmd);
2664 2686 }
2665 2687 if (*p == '\0')
2666 2688 break;
... ... @@ -2691,7 +2713,8 @@ static void file_completion(const char *input)
2691 2713 pstrcpy(file_prefix, sizeof(file_prefix), p + 1);
2692 2714 }
2693 2715 #ifdef DEBUG_COMPLETION
2694   - term_printf("input='%s' path='%s' prefix='%s'\n", input, path, file_prefix);
  2716 + monitor_printf(cur_mon, "input='%s' path='%s' prefix='%s'\n",
  2717 + input, path, file_prefix);
2695 2718 #endif
2696 2719 ffs = opendir(path);
2697 2720 if (!ffs)
... ... @@ -2712,7 +2735,7 @@ static void file_completion(const char *input)
2712 2735 stat(file, &sb);
2713 2736 if(S_ISDIR(sb.st_mode))
2714 2737 pstrcat(file, sizeof(file), "/");
2715   - add_completion(file);
  2738 + readline_add_completion(file);
2716 2739 }
2717 2740 }
2718 2741 closedir(ffs);
... ... @@ -2725,7 +2748,7 @@ static void block_completion_it(void *opaque, BlockDriverState *bs)
2725 2748  
2726 2749 if (input[0] == '\0' ||
2727 2750 !strncmp(name, (char *)input, strlen(input))) {
2728   - add_completion(name);
  2751 + readline_add_completion(name);
2729 2752 }
2730 2753 }
2731 2754  
... ... @@ -2761,13 +2784,13 @@ void readline_find_completion(const char *cmdline)
2761 2784 char *args[MAX_ARGS];
2762 2785 int nb_args, i, len;
2763 2786 const char *ptype, *str;
2764   - const term_cmd_t *cmd;
  2787 + const mon_cmd_t *cmd;
2765 2788 const KeyDef *key;
2766 2789  
2767 2790 parse_cmdline(cmdline, &nb_args, args);
2768 2791 #ifdef DEBUG_COMPLETION
2769 2792 for(i = 0; i < nb_args; i++) {
2770   - term_printf("arg%d = '%s'\n", i, (char *)args[i]);
  2793 + monitor_printf(cur_mon, "arg%d = '%s'\n", i, (char *)args[i]);
2771 2794 }
2772 2795 #endif
2773 2796  
... ... @@ -2785,13 +2808,13 @@ void readline_find_completion(const char *cmdline)
2785 2808 cmdname = "";
2786 2809 else
2787 2810 cmdname = args[0];
2788   - completion_index = strlen(cmdname);
2789   - for(cmd = term_cmds; cmd->name != NULL; cmd++) {
  2811 + readline_set_completion_index(strlen(cmdname));
  2812 + for(cmd = mon_cmds; cmd->name != NULL; cmd++) {
2790 2813 cmd_completion(cmdname, cmd->name);
2791 2814 }
2792 2815 } else {
2793 2816 /* find the command */
2794   - for(cmd = term_cmds; cmd->name != NULL; cmd++) {
  2817 + for(cmd = mon_cmds; cmd->name != NULL; cmd++) {
2795 2818 if (compare_cmd(args[0], cmd->name))
2796 2819 goto found;
2797 2820 }
... ... @@ -2809,23 +2832,23 @@ void readline_find_completion(const char *cmdline)
2809 2832 switch(*ptype) {
2810 2833 case 'F':
2811 2834 /* file completion */
2812   - completion_index = strlen(str);
  2835 + readline_set_completion_index(strlen(str));
2813 2836 file_completion(str);
2814 2837 break;
2815 2838 case 'B':
2816 2839 /* block device name completion */
2817   - completion_index = strlen(str);
  2840 + readline_set_completion_index(strlen(str));
2818 2841 bdrv_iterate(block_completion_it, (void *)str);
2819 2842 break;
2820 2843 case 's':
2821 2844 /* XXX: more generic ? */
2822 2845 if (!strcmp(cmd->name, "info")) {
2823   - completion_index = strlen(str);
  2846 + readline_set_completion_index(strlen(str));
2824 2847 for(cmd = info_cmds; cmd->name != NULL; cmd++) {
2825 2848 cmd_completion(str, cmd->name);
2826 2849 }
2827 2850 } else if (!strcmp(cmd->name, "sendkey")) {
2828   - completion_index = strlen(str);
  2851 + readline_set_completion_index(strlen(str));
2829 2852 for(key = key_defs; key->name != NULL; key++) {
2830 2853 cmd_completion(str, key->name);
2831 2854 }
... ... @@ -2847,27 +2870,28 @@ static int term_can_read(void *opaque)
2847 2870 static void term_read(void *opaque, const uint8_t *buf, int size)
2848 2871 {
2849 2872 int i;
2850   - for(i = 0; i < size; i++)
  2873 +
  2874 + for (i = 0; i < size; i++)
2851 2875 readline_handle_byte(buf[i]);
2852 2876 }
2853 2877  
2854 2878 static int monitor_suspended;
2855 2879  
2856   -static void monitor_handle_command1(void *opaque, const char *cmdline)
  2880 +static void monitor_command_cb(Monitor *mon, const char *cmdline, void *opaque)
2857 2881 {
2858   - monitor_handle_command(cmdline);
  2882 + monitor_handle_command(mon, cmdline);
2859 2883 if (!monitor_suspended)
2860 2884 readline_show_prompt();
2861 2885 else
2862 2886 monitor_suspended = 2;
2863 2887 }
2864 2888  
2865   -void monitor_suspend(void)
  2889 +void monitor_suspend(Monitor *mon)
2866 2890 {
2867 2891 monitor_suspended = 1;
2868 2892 }
2869 2893  
2870   -void monitor_resume(void)
  2894 +void monitor_resume(Monitor *mon)
2871 2895 {
2872 2896 if (monitor_suspended == 2)
2873 2897 monitor_start_input();
... ... @@ -2876,24 +2900,26 @@ void monitor_resume(void)
2876 2900  
2877 2901 static void monitor_start_input(void)
2878 2902 {
2879   - readline_start("(qemu) ", 0, monitor_handle_command1, NULL);
  2903 + readline_start("(qemu) ", 0, monitor_command_cb, NULL);
2880 2904 readline_show_prompt();
2881 2905 }
2882 2906  
2883 2907 static void term_event(void *opaque, int event)
2884 2908 {
  2909 + Monitor *mon = opaque;
  2910 +
2885 2911 if (event != CHR_EVENT_RESET)
2886 2912 return;
2887 2913  
2888 2914 if (!hide_banner)
2889   - term_printf("QEMU %s monitor - type 'help' for more information\n",
2890   - QEMU_VERSION);
  2915 + monitor_printf(mon, "QEMU %s monitor - type 'help' for more "
  2916 + "information\n", QEMU_VERSION);
2891 2917 monitor_start_input();
2892 2918 }
2893 2919  
2894 2920 static int is_first_init = 1;
2895 2921  
2896   -void monitor_init(CharDriverState *hd, int show_banner)
  2922 +void monitor_init(CharDriverState *chr, int show_banner)
2897 2923 {
2898 2924 int i;
2899 2925  
... ... @@ -2908,25 +2934,25 @@ void monitor_init(CharDriverState *hd, int show_banner)
2908 2934 }
2909 2935 for (i = 0; i < MAX_MON; i++) {
2910 2936 if (monitor_hd[i] == NULL) {
2911   - monitor_hd[i] = hd;
  2937 + monitor_hd[i] = chr;
2912 2938 break;
2913 2939 }
2914 2940 }
2915 2941  
2916 2942 hide_banner = !show_banner;
2917 2943  
2918   - qemu_chr_add_handlers(hd, term_can_read, term_read, term_event, NULL);
  2944 + qemu_chr_add_handlers(chr, term_can_read, term_read, term_event, cur_mon);
2919 2945  
2920   - readline_start("", 0, monitor_handle_command1, NULL);
  2946 + readline_start("", 0, monitor_command_cb, NULL);
2921 2947 }
2922 2948  
2923   -static void bdrv_password_cb(void *opaque, const char *password)
  2949 +static void bdrv_password_cb(Monitor *mon, const char *password, void *opaque)
2924 2950 {
2925 2951 BlockDriverState *bs = opaque;
2926 2952 int ret = 0;
2927 2953  
2928 2954 if (bdrv_set_key(bs, password) != 0) {
2929   - term_printf("invalid password\n");
  2955 + monitor_printf(mon, "invalid password\n");
2930 2956 ret = -EPERM;
2931 2957 }
2932 2958 if (password_completion_cb)
... ... @@ -2935,7 +2961,7 @@ static void bdrv_password_cb(void *opaque, const char *password)
2935 2961 monitor_start_input();
2936 2962 }
2937 2963  
2938   -void monitor_read_bdrv_key_start(BlockDriverState *bs,
  2964 +void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
2939 2965 BlockDriverCompletionFunc *completion_cb,
2940 2966 void *opaque)
2941 2967 {
... ... @@ -2945,11 +2971,11 @@ void monitor_read_bdrv_key_start(BlockDriverState *bs,
2945 2971 return;
2946 2972 }
2947 2973  
2948   - term_printf("%s (%s) is encrypted.\n", bdrv_get_device_name(bs),
2949   - bdrv_get_encrypted_filename(bs));
  2974 + monitor_printf(mon, "%s (%s) is encrypted.\n", bdrv_get_device_name(bs),
  2975 + bdrv_get_encrypted_filename(bs));
2950 2976  
2951 2977 password_completion_cb = completion_cb;
2952 2978 password_opaque = opaque;
2953 2979  
2954   - monitor_read_password(bdrv_password_cb, bs);
  2980 + monitor_read_password(mon, bdrv_password_cb, bs);
2955 2981 }
... ...
monitor.h 0 โ†’ 100644
  1 +#ifndef MONITOR_H
  2 +#define MONITOR_H
  3 +
  4 +#include "qemu-common.h"
  5 +#include "qemu-char.h"
  6 +#include "block.h"
  7 +
  8 +extern Monitor *cur_mon;
  9 +
  10 +void monitor_init(CharDriverState *chr, int show_banner);
  11 +
  12 +void monitor_suspend(Monitor *mon);
  13 +void monitor_resume(Monitor *mon);
  14 +
  15 +void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
  16 + BlockDriverCompletionFunc *completion_cb,
  17 + void *opaque);
  18 +
  19 +void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap);
  20 +void monitor_printf(Monitor *mon, const char *fmt, ...)
  21 + __attribute__ ((__format__ (__printf__, 2, 3)));
  22 +void monitor_print_filename(Monitor *mon, const char *filename);
  23 +void monitor_flush(Monitor *mon);
  24 +
  25 +#endif /* !MONITOR_H */
... ...
... ... @@ -23,7 +23,7 @@
23 23 */
24 24 #include "qemu-common.h"
25 25 #include "net.h"
26   -#include "console.h"
  26 +#include "monitor.h"
27 27 #include "sysemu.h"
28 28 #include "qemu-timer.h"
29 29 #include "qemu-char.h"
... ... @@ -665,7 +665,7 @@ void net_slirp_smb(const char *exported_dir)
665 665 }
666 666  
667 667 #endif /* !defined(_WIN32) */
668   -void do_info_slirp(void)
  668 +void do_info_slirp(Monitor *mon)
669 669 {
670 670 slirp_stats();
671 671 }
... ... @@ -1804,28 +1804,28 @@ static int net_host_check_device(const char *device)
1804 1804 return 0;
1805 1805 }
1806 1806  
1807   -void net_host_device_add(const char *device, const char *opts)
  1807 +void net_host_device_add(Monitor *mon, const char *device, const char *opts)
1808 1808 {
1809 1809 if (!net_host_check_device(device)) {
1810   - term_printf("invalid host network device %s\n", device);
  1810 + monitor_printf(mon, "invalid host network device %s\n", device);
1811 1811 return;
1812 1812 }
1813 1813 net_client_init(device, opts);
1814 1814 }
1815 1815  
1816   -void net_host_device_remove(int vlan_id, const char *device)
  1816 +void net_host_device_remove(Monitor *mon, int vlan_id, const char *device)
1817 1817 {
1818 1818 VLANState *vlan;
1819 1819 VLANClientState *vc;
1820 1820  
1821 1821 if (!net_host_check_device(device)) {
1822   - term_printf("invalid host network device %s\n", device);
  1822 + monitor_printf(mon, "invalid host network device %s\n", device);
1823 1823 return;
1824 1824 }
1825 1825  
1826 1826 vlan = qemu_find_vlan(vlan_id);
1827 1827 if (!vlan) {
1828   - term_printf("can't find vlan %d\n", vlan_id);
  1828 + monitor_printf(mon, "can't find vlan %d\n", vlan_id);
1829 1829 return;
1830 1830 }
1831 1831  
... ... @@ -1834,7 +1834,7 @@ void net_host_device_remove(int vlan_id, const char *device)
1834 1834 break;
1835 1835  
1836 1836 if (!vc) {
1837   - term_printf("can't find device %s\n", device);
  1837 + monitor_printf(mon, "can't find device %s\n", device);
1838 1838 return;
1839 1839 }
1840 1840 qemu_del_vlan_client(vc);
... ... @@ -1860,19 +1860,19 @@ int net_client_parse(const char *str)
1860 1860 return net_client_init(device, p);
1861 1861 }
1862 1862  
1863   -void do_info_network(void)
  1863 +void do_info_network(Monitor *mon)
1864 1864 {
1865 1865 VLANState *vlan;
1866 1866 VLANClientState *vc;
1867 1867  
1868 1868 for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
1869   - term_printf("VLAN %d devices:\n", vlan->id);
  1869 + monitor_printf(mon, "VLAN %d devices:\n", vlan->id);
1870 1870 for(vc = vlan->first_client; vc != NULL; vc = vc->next)
1871   - term_printf(" %s: %s\n", vc->name, vc->info_str);
  1871 + monitor_printf(mon, " %s: %s\n", vc->name, vc->info_str);
1872 1872 }
1873 1873 }
1874 1874  
1875   -int do_set_link(const char *name, const char *up_or_down)
  1875 +int do_set_link(Monitor *mon, const char *name, const char *up_or_down)
1876 1876 {
1877 1877 VLANState *vlan;
1878 1878 VLANClientState *vc = NULL;
... ... @@ -1884,7 +1884,7 @@ int do_set_link(const char *name, const char *up_or_down)
1884 1884 done:
1885 1885  
1886 1886 if (!vc) {
1887   - term_printf("could not find network device '%s'", name);
  1887 + monitor_printf(mon, "could not find network device '%s'", name);
1888 1888 return 0;
1889 1889 }
1890 1890  
... ... @@ -1893,8 +1893,8 @@ done:
1893 1893 else if (strcmp(up_or_down, "down") == 0)
1894 1894 vc->link_down = 1;
1895 1895 else
1896   - term_printf("invalid link status '%s'; only 'up' or 'down' valid\n",
1897   - up_or_down);
  1896 + monitor_printf(mon, "invalid link status '%s'; only 'up' or 'down' "
  1897 + "valid\n", up_or_down);
1898 1898  
1899 1899 if (vc->link_status_changed)
1900 1900 vc->link_status_changed(vc);
... ...
... ... @@ -53,8 +53,8 @@ void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
53 53 const char *default_model);
54 54 void qemu_handler_true(void *opaque);
55 55  
56   -void do_info_network(void);
57   -int do_set_link(const char *name, const char *up_or_down);
  56 +void do_info_network(Monitor *mon);
  57 +int do_set_link(Monitor *mon, const char *name, const char *up_or_down);
58 58  
59 59 /* NIC info */
60 60  
... ... @@ -102,8 +102,8 @@ void net_slirp_redir(const char *redir_str);
102 102 void net_cleanup(void);
103 103 int slirp_is_inited(void);
104 104 void net_client_check(void);
105   -void net_host_device_add(const char *device, const char *opts);
106   -void net_host_device_remove(int vlan_id, const char *device);
  105 +void net_host_device_add(Monitor *mon, const char *device, const char *opts);
  106 +void net_host_device_remove(Monitor *mon, int vlan_id, const char *device);
107 107  
108 108 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
109 109 #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
... ...
qemu-char.c
... ... @@ -23,6 +23,7 @@
23 23 */
24 24 #include "qemu-common.h"
25 25 #include "net.h"
  26 +#include "monitor.h"
26 27 #include "console.h"
27 28 #include "sysemu.h"
28 29 #include "qemu-timer.h"
... ... @@ -2199,11 +2200,11 @@ void qemu_chr_close(CharDriverState *chr)
2199 2200 qemu_free(chr);
2200 2201 }
2201 2202  
2202   -void qemu_chr_info(void)
  2203 +void qemu_chr_info(Monitor *mon)
2203 2204 {
2204 2205 CharDriverState *chr;
2205 2206  
2206 2207 TAILQ_FOREACH(chr, &chardevs, next) {
2207   - term_printf("%s: filename=%s\n", chr->label, chr->filename);
  2208 + monitor_printf(mon, "%s: filename=%s\n", chr->label, chr->filename);
2208 2209 }
2209 2210 }
... ...
qemu-char.h
1 1 #ifndef QEMU_CHAR_H
2 2 #define QEMU_CHAR_H
3 3  
  4 +#include "qemu-common.h"
4 5 #include "sys-queue.h"
  6 +
5 7 /* character device */
6 8  
7 9 #define CHR_EVENT_BREAK 0 /* serial break char */
... ... @@ -78,7 +80,7 @@ void qemu_chr_initial_reset(void);
78 80 int qemu_chr_can_read(CharDriverState *s);
79 81 void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len);
80 82 void qemu_chr_accept_input(CharDriverState *s);
81   -void qemu_chr_info(void);
  83 +void qemu_chr_info(Monitor *mon);
82 84  
83 85 extern int term_escape_char;
84 86  
... ...
qemu-common.h
... ... @@ -205,6 +205,9 @@ void qemu_iovec_reset(QEMUIOVector *qiov);
205 205 void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
206 206 void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
207 207  
  208 +struct Monitor;
  209 +typedef struct Monitor Monitor;
  210 +
208 211 #endif /* dyngen-exec.h hack */
209 212  
210 213 #endif
... ...
qemu-tool.c
... ... @@ -12,7 +12,7 @@
12 12 */
13 13  
14 14 #include "qemu-common.h"
15   -#include "console.h"
  15 +#include "monitor.h"
16 16 #include "sysemu.h"
17 17 #include "qemu-timer.h"
18 18  
... ... @@ -30,11 +30,13 @@ void qemu_service_io(void)
30 30 {
31 31 }
32 32  
33   -void term_printf(const char *fmt, ...)
  33 +Monitor *cur_mon;
  34 +
  35 +void monitor_printf(Monitor *mon, const char *fmt, ...)
34 36 {
35 37 }
36 38  
37   -void term_print_filename(const char *filename)
  39 +void monitor_print_filename(Monitor *mon, const char *filename)
38 40 {
39 41 }
40 42  
... ...
readline.c
... ... @@ -21,8 +21,8 @@
21 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 22 * THE SOFTWARE.
23 23 */
24   -#include "qemu-common.h"
25   -#include "console.h"
  24 +#include "readline.h"
  25 +#include "monitor.h"
26 26  
27 27 #define TERM_CMD_BUF_SIZE 4095
28 28 #define TERM_MAX_CMDS 64
... ... @@ -49,7 +49,7 @@ static char *term_history[TERM_MAX_CMDS];
49 49 static int term_hist_entry = -1;
50 50  
51 51 static int nb_completions;
52   -int completion_index;
  52 +static int completion_index;
53 53 static char *completions[NB_COMPLETIONS_MAX];
54 54  
55 55 static ReadLineFunc *term_readline_func;
... ... @@ -59,8 +59,10 @@ static void *term_readline_opaque;
59 59  
60 60 void readline_show_prompt(void)
61 61 {
62   - term_printf("%s", term_prompt);
63   - term_flush();
  62 + Monitor *mon = cur_mon;
  63 +
  64 + monitor_printf(mon, "%s", term_prompt);
  65 + monitor_flush(mon);
64 66 term_last_cmd_buf_index = 0;
65 67 term_last_cmd_buf_size = 0;
66 68 term_esc_state = IS_NORM;
... ... @@ -69,22 +71,23 @@ void readline_show_prompt(void)
69 71 /* update the displayed command line */
70 72 static void term_update(void)
71 73 {
  74 + Monitor *mon = cur_mon;
72 75 int i, delta, len;
73 76  
74 77 if (term_cmd_buf_size != term_last_cmd_buf_size ||
75 78 memcmp(term_cmd_buf, term_last_cmd_buf, term_cmd_buf_size) != 0) {
76 79 for(i = 0; i < term_last_cmd_buf_index; i++) {
77   - term_printf("\033[D");
  80 + monitor_printf(mon, "\033[D");
78 81 }
79 82 term_cmd_buf[term_cmd_buf_size] = '\0';
80 83 if (term_is_password) {
81 84 len = strlen(term_cmd_buf);
82 85 for(i = 0; i < len; i++)
83   - term_printf("*");
  86 + monitor_printf(mon, "*");
84 87 } else {
85   - term_printf("%s", term_cmd_buf);
  88 + monitor_printf(mon, "%s", term_cmd_buf);
86 89 }
87   - term_printf("\033[K");
  90 + monitor_printf(mon, "\033[K");
88 91 memcpy(term_last_cmd_buf, term_cmd_buf, term_cmd_buf_size);
89 92 term_last_cmd_buf_size = term_cmd_buf_size;
90 93 term_last_cmd_buf_index = term_cmd_buf_size;
... ... @@ -93,17 +96,17 @@ static void term_update(void)
93 96 delta = term_cmd_buf_index - term_last_cmd_buf_index;
94 97 if (delta > 0) {
95 98 for(i = 0;i < delta; i++) {
96   - term_printf("\033[C");
  99 + monitor_printf(mon, "\033[C");
97 100 }
98 101 } else {
99 102 delta = -delta;
100 103 for(i = 0;i < delta; i++) {
101   - term_printf("\033[D");
  104 + monitor_printf(mon, "\033[D");
102 105 }
103 106 }
104 107 term_last_cmd_buf_index = term_cmd_buf_index;
105 108 }
106   - term_flush();
  109 + monitor_flush(mon);
107 110 }
108 111  
109 112 static void term_insert_char(int ch)
... ... @@ -285,15 +288,21 @@ static void term_hist_add(const char *cmdline)
285 288  
286 289 /* completion support */
287 290  
288   -void add_completion(const char *str)
  291 +void readline_add_completion(const char *str)
289 292 {
290 293 if (nb_completions < NB_COMPLETIONS_MAX) {
291 294 completions[nb_completions++] = qemu_strdup(str);
292 295 }
293 296 }
294 297  
  298 +void readline_set_completion_index(int index)
  299 +{
  300 + completion_index = index;
  301 +}
  302 +
295 303 static void term_completion(void)
296 304 {
  305 + Monitor *mon = cur_mon;
297 306 int len, i, j, max_width, nb_cols, max_prefix;
298 307 char *cmdline;
299 308  
... ... @@ -317,7 +326,7 @@ static void term_completion(void)
317 326 if (len > 0 && completions[0][len - 1] != '/')
318 327 term_insert_char(' ');
319 328 } else {
320   - term_printf("\n");
  329 + monitor_printf(mon, "\n");
321 330 max_width = 0;
322 331 max_prefix = 0;
323 332 for(i = 0; i < nb_completions; i++) {
... ... @@ -347,9 +356,9 @@ static void term_completion(void)
347 356 nb_cols = 80 / max_width;
348 357 j = 0;
349 358 for(i = 0; i < nb_completions; i++) {
350   - term_printf("%-*s", max_width, completions[i]);
  359 + monitor_printf(mon, "%-*s", max_width, completions[i]);
351 360 if (++j == nb_cols || i == (nb_completions - 1)) {
352   - term_printf("\n");
  361 + monitor_printf(mon, "\n");
353 362 j = 0;
354 363 }
355 364 }
... ... @@ -360,6 +369,8 @@ static void term_completion(void)
360 369 /* return true if command handled */
361 370 void readline_handle_byte(int ch)
362 371 {
  372 + Monitor *mon = cur_mon;
  373 +
363 374 switch(term_esc_state) {
364 375 case IS_NORM:
365 376 switch(ch) {
... ... @@ -380,13 +391,13 @@ void readline_handle_byte(int ch)
380 391 term_cmd_buf[term_cmd_buf_size] = '\0';
381 392 if (!term_is_password)
382 393 term_hist_add(term_cmd_buf);
383   - term_printf("\n");
  394 + monitor_printf(mon, "\n");
384 395 term_cmd_buf_index = 0;
385 396 term_cmd_buf_size = 0;
386 397 term_last_cmd_buf_index = 0;
387 398 term_last_cmd_buf_size = 0;
388 399 /* NOTE: readline_start can be called here */
389   - term_readline_func(term_readline_opaque, term_cmd_buf);
  400 + term_readline_func(mon, term_cmd_buf, term_readline_opaque);
390 401 break;
391 402 case 23:
392 403 /* ^W */
... ...
readline.h 0 โ†’ 100644
  1 +#ifndef READLINE_H
  2 +#define READLINE_H
  3 +
  4 +#include "qemu-common.h"
  5 +
  6 +typedef void ReadLineFunc(Monitor *mon, const char *str, void *opaque);
  7 +
  8 +void readline_add_completion(const char *str);
  9 +void readline_set_completion_index(int index);
  10 +void readline_find_completion(const char *cmdline);
  11 +
  12 +const char *readline_get_history(unsigned int index);
  13 +
  14 +void readline_handle_byte(int ch);
  15 +
  16 +void readline_start(const char *prompt, int is_password,
  17 + ReadLineFunc *readline_func, void *opaque);
  18 +void readline_show_prompt(void);
  19 +
  20 +#endif /* !READLINE_H */
... ...
savevm.c
... ... @@ -24,7 +24,7 @@
24 24 #include "qemu-common.h"
25 25 #include "hw/hw.h"
26 26 #include "net.h"
27   -#include "console.h"
  27 +#include "monitor.h"
28 28 #include "sysemu.h"
29 29 #include "qemu-timer.h"
30 30 #include "qemu-char.h"
... ... @@ -993,7 +993,7 @@ static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
993 993 return ret;
994 994 }
995 995  
996   -void do_savevm(const char *name)
  996 +void do_savevm(Monitor *mon, const char *name)
997 997 {
998 998 BlockDriverState *bs, *bs1;
999 999 QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1;
... ... @@ -1010,7 +1010,7 @@ void do_savevm(const char *name)
1010 1010  
1011 1011 bs = get_bs_snapshots();
1012 1012 if (!bs) {
1013   - term_printf("No block device can accept snapshots\n");
  1013 + monitor_printf(mon, "No block device can accept snapshots\n");
1014 1014 return;
1015 1015 }
1016 1016  
... ... @@ -1049,22 +1049,22 @@ void do_savevm(const char *name)
1049 1049 sn->vm_clock_nsec = qemu_get_clock(vm_clock);
1050 1050  
1051 1051 if (bdrv_get_info(bs, bdi) < 0 || bdi->vm_state_offset <= 0) {
1052   - term_printf("Device %s does not support VM state snapshots\n",
1053   - bdrv_get_device_name(bs));
  1052 + monitor_printf(mon, "Device %s does not support VM state snapshots\n",
  1053 + bdrv_get_device_name(bs));
1054 1054 goto the_end;
1055 1055 }
1056 1056  
1057 1057 /* save the VM state */
1058 1058 f = qemu_fopen_bdrv(bs, bdi->vm_state_offset, 1);
1059 1059 if (!f) {
1060   - term_printf("Could not open VM state file\n");
  1060 + monitor_printf(mon, "Could not open VM state file\n");
1061 1061 goto the_end;
1062 1062 }
1063 1063 ret = qemu_savevm_state(f);
1064 1064 vm_state_size = qemu_ftell(f);
1065 1065 qemu_fclose(f);
1066 1066 if (ret < 0) {
1067   - term_printf("Error %d while writing VM\n", ret);
  1067 + monitor_printf(mon, "Error %d while writing VM\n", ret);
1068 1068 goto the_end;
1069 1069 }
1070 1070  
... ... @@ -1076,16 +1076,17 @@ void do_savevm(const char *name)
1076 1076 if (must_delete) {
1077 1077 ret = bdrv_snapshot_delete(bs1, old_sn->id_str);
1078 1078 if (ret < 0) {
1079   - term_printf("Error while deleting snapshot on '%s'\n",
1080   - bdrv_get_device_name(bs1));
  1079 + monitor_printf(mon,
  1080 + "Error while deleting snapshot on '%s'\n",
  1081 + bdrv_get_device_name(bs1));
1081 1082 }
1082 1083 }
1083 1084 /* Write VM state size only to the image that contains the state */
1084 1085 sn->vm_state_size = (bs == bs1 ? vm_state_size : 0);
1085 1086 ret = bdrv_snapshot_create(bs1, sn);
1086 1087 if (ret < 0) {
1087   - term_printf("Error while creating snapshot on '%s'\n",
1088   - bdrv_get_device_name(bs1));
  1088 + monitor_printf(mon, "Error while creating snapshot on '%s'\n",
  1089 + bdrv_get_device_name(bs1));
1089 1090 }
1090 1091 }
1091 1092 }
... ... @@ -1095,7 +1096,7 @@ void do_savevm(const char *name)
1095 1096 vm_start();
1096 1097 }
1097 1098  
1098   -void do_loadvm(const char *name)
  1099 +void do_loadvm(Monitor *mon, const char *name)
1099 1100 {
1100 1101 BlockDriverState *bs, *bs1;
1101 1102 BlockDriverInfo bdi1, *bdi = &bdi1;
... ... @@ -1106,7 +1107,7 @@ void do_loadvm(const char *name)
1106 1107  
1107 1108 bs = get_bs_snapshots();
1108 1109 if (!bs) {
1109   - term_printf("No block device supports snapshots\n");
  1110 + monitor_printf(mon, "No block device supports snapshots\n");
1110 1111 return;
1111 1112 }
1112 1113  
... ... @@ -1122,19 +1123,21 @@ void do_loadvm(const char *name)
1122 1123 ret = bdrv_snapshot_goto(bs1, name);
1123 1124 if (ret < 0) {
1124 1125 if (bs != bs1)
1125   - term_printf("Warning: ");
  1126 + monitor_printf(mon, "Warning: ");
1126 1127 switch(ret) {
1127 1128 case -ENOTSUP:
1128   - term_printf("Snapshots not supported on device '%s'\n",
1129   - bdrv_get_device_name(bs1));
  1129 + monitor_printf(mon,
  1130 + "Snapshots not supported on device '%s'\n",
  1131 + bdrv_get_device_name(bs1));
1130 1132 break;
1131 1133 case -ENOENT:
1132   - term_printf("Could not find snapshot '%s' on device '%s'\n",
1133   - name, bdrv_get_device_name(bs1));
  1134 + monitor_printf(mon, "Could not find snapshot '%s' on "
  1135 + "device '%s'\n",
  1136 + name, bdrv_get_device_name(bs1));
1134 1137 break;
1135 1138 default:
1136   - term_printf("Error %d while activating snapshot on '%s'\n",
1137   - ret, bdrv_get_device_name(bs1));
  1139 + monitor_printf(mon, "Error %d while activating snapshot on"
  1140 + " '%s'\n", ret, bdrv_get_device_name(bs1));
1138 1141 break;
1139 1142 }
1140 1143 /* fatal on snapshot block device */
... ... @@ -1145,8 +1148,8 @@ void do_loadvm(const char *name)
1145 1148 }
1146 1149  
1147 1150 if (bdrv_get_info(bs, bdi) < 0 || bdi->vm_state_offset <= 0) {
1148   - term_printf("Device %s does not support VM state snapshots\n",
1149   - bdrv_get_device_name(bs));
  1151 + monitor_printf(mon, "Device %s does not support VM state snapshots\n",
  1152 + bdrv_get_device_name(bs));
1150 1153 return;
1151 1154 }
1152 1155  
... ... @@ -1158,27 +1161,27 @@ void do_loadvm(const char *name)
1158 1161 /* restore the VM state */
1159 1162 f = qemu_fopen_bdrv(bs, bdi->vm_state_offset, 0);
1160 1163 if (!f) {
1161   - term_printf("Could not open VM state file\n");
  1164 + monitor_printf(mon, "Could not open VM state file\n");
1162 1165 goto the_end;
1163 1166 }
1164 1167 ret = qemu_loadvm_state(f);
1165 1168 qemu_fclose(f);
1166 1169 if (ret < 0) {
1167   - term_printf("Error %d while loading VM state\n", ret);
  1170 + monitor_printf(mon, "Error %d while loading VM state\n", ret);
1168 1171 }
1169 1172 the_end:
1170 1173 if (saved_vm_running)
1171 1174 vm_start();
1172 1175 }
1173 1176  
1174   -void do_delvm(const char *name)
  1177 +void do_delvm(Monitor *mon, const char *name)
1175 1178 {
1176 1179 BlockDriverState *bs, *bs1;
1177 1180 int i, ret;
1178 1181  
1179 1182 bs = get_bs_snapshots();
1180 1183 if (!bs) {
1181   - term_printf("No block device supports snapshots\n");
  1184 + monitor_printf(mon, "No block device supports snapshots\n");
1182 1185 return;
1183 1186 }
1184 1187  
... ... @@ -1188,17 +1191,18 @@ void do_delvm(const char *name)
1188 1191 ret = bdrv_snapshot_delete(bs1, name);
1189 1192 if (ret < 0) {
1190 1193 if (ret == -ENOTSUP)
1191   - term_printf("Snapshots not supported on device '%s'\n",
1192   - bdrv_get_device_name(bs1));
  1194 + monitor_printf(mon,
  1195 + "Snapshots not supported on device '%s'\n",
  1196 + bdrv_get_device_name(bs1));
1193 1197 else
1194   - term_printf("Error %d while deleting snapshot on '%s'\n",
1195   - ret, bdrv_get_device_name(bs1));
  1198 + monitor_printf(mon, "Error %d while deleting snapshot on "
  1199 + "'%s'\n", ret, bdrv_get_device_name(bs1));
1196 1200 }
1197 1201 }
1198 1202 }
1199 1203 }
1200 1204  
1201   -void do_info_snapshots(void)
  1205 +void do_info_snapshots(Monitor *mon)
1202 1206 {
1203 1207 BlockDriverState *bs, *bs1;
1204 1208 QEMUSnapshotInfo *sn_tab, *sn;
... ... @@ -1207,29 +1211,30 @@ void do_info_snapshots(void)
1207 1211  
1208 1212 bs = get_bs_snapshots();
1209 1213 if (!bs) {
1210   - term_printf("No available block device supports snapshots\n");
  1214 + monitor_printf(mon, "No available block device supports snapshots\n");
1211 1215 return;
1212 1216 }
1213   - term_printf("Snapshot devices:");
  1217 + monitor_printf(mon, "Snapshot devices:");
1214 1218 for(i = 0; i <= nb_drives; i++) {
1215 1219 bs1 = drives_table[i].bdrv;
1216 1220 if (bdrv_has_snapshot(bs1)) {
1217 1221 if (bs == bs1)
1218   - term_printf(" %s", bdrv_get_device_name(bs1));
  1222 + monitor_printf(mon, " %s", bdrv_get_device_name(bs1));
1219 1223 }
1220 1224 }
1221   - term_printf("\n");
  1225 + monitor_printf(mon, "\n");
1222 1226  
1223 1227 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1224 1228 if (nb_sns < 0) {
1225   - term_printf("bdrv_snapshot_list: error %d\n", nb_sns);
  1229 + monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1226 1230 return;
1227 1231 }
1228   - term_printf("Snapshot list (from %s):\n", bdrv_get_device_name(bs));
1229   - term_printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
  1232 + monitor_printf(mon, "Snapshot list (from %s):\n",
  1233 + bdrv_get_device_name(bs));
  1234 + monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
1230 1235 for(i = 0; i < nb_sns; i++) {
1231 1236 sn = &sn_tab[i];
1232   - term_printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn));
  1237 + monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn));
1233 1238 }
1234 1239 qemu_free(sn_tab);
1235 1240 }
... ...
slirp/misc.c
... ... @@ -557,14 +557,14 @@ relay(s)
557 557 #endif
558 558  
559 559 #ifdef CONFIG_QEMU
560   -extern void term_vprintf(const char *fmt, va_list ap);
  560 +#include "monitor.h"
561 561  
562 562 void lprint(const char *format, ...)
563 563 {
564 564 va_list args;
565 565  
566 566 va_start(args, format);
567   - term_vprintf(format, args);
  567 + monitor_vprintf(cur_mon, format, args);
568 568 va_end(args);
569 569 }
570 570 #else
... ...
sysemu.h
... ... @@ -2,6 +2,8 @@
2 2 #define SYSEMU_H
3 3 /* Misc. things related to the system emulator. */
4 4  
  5 +#include "qemu-common.h"
  6 +
5 7 /* vl.c */
6 8 extern const char *bios_name;
7 9 extern const char *bios_dir;
... ... @@ -39,10 +41,10 @@ void qemu_system_powerdown(void);
39 41 #endif
40 42 void qemu_system_reset(void);
41 43  
42   -void do_savevm(const char *name);
43   -void do_loadvm(const char *name);
44   -void do_delvm(const char *name);
45   -void do_info_snapshots(void);
  44 +void do_savevm(Monitor *mon, const char *name);
  45 +void do_loadvm(Monitor *mon, const char *name);
  46 +void do_delvm(Monitor *mon, const char *name);
  47 +void do_info_snapshots(Monitor *mon);
46 48  
47 49 void qemu_announce_self(void);
48 50  
... ... @@ -75,7 +77,7 @@ int tap_win32_init(VLANState *vlan, const char *model,
75 77 const char *name, const char *ifname);
76 78  
77 79 /* SLIRP */
78   -void do_info_slirp(void);
  80 +void do_info_slirp(Monitor *mon);
79 81  
80 82 extern int bios_size;
81 83 extern int cirrus_vga_enabled;
... ... @@ -179,9 +181,10 @@ void destroy_nic(dev_match_fn *match_fn, void *arg);
179 181 void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
180 182  
181 183 /* pci-hotplug */
182   -void pci_device_hot_add(const char *pci_addr, const char *type, const char *opts);
183   -void drive_hot_add(const char *pci_addr, const char *opts);
184   -void pci_device_hot_remove(const char *pci_addr);
  184 +void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
  185 + const char *opts);
  186 +void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts);
  187 +void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
185 188 void pci_device_hot_remove_success(int pcibus, int slot);
186 189  
187 190 /* serial ports */
... ... @@ -237,9 +240,9 @@ struct soundhw {
237 240 extern struct soundhw soundhw[];
238 241 #endif
239 242  
240   -void do_usb_add(const char *devname);
241   -void do_usb_del(const char *devname);
242   -void usb_info(void);
  243 +void do_usb_add(Monitor *mon, const char *devname);
  244 +void do_usb_del(Monitor *mon, const char *devname);
  245 +void usb_info(Monitor *mon);
243 246  
244 247 const char *get_opt_name(char *buf, int buf_size, const char *p);
245 248 const char *get_opt_value(char *buf, int buf_size, const char *p);
... ...
usb-bsd.c
... ... @@ -554,6 +554,7 @@ static void usb_info_device(int bus_num, int addr, int class_id,
554 554 int speed)
555 555 {
556 556 const char *class_str, *speed_str;
  557 + Monitor *mon = cur_mon;
557 558  
558 559 switch(speed) {
559 560 case USB_SPEED_LOW:
... ... @@ -570,20 +571,21 @@ static void usb_info_device(int bus_num, int addr, int class_id,
570 571 break;
571 572 }
572 573  
573   - term_printf(" Device %d.%d, speed %s Mb/s\n",
574   - bus_num, addr, speed_str);
  574 + monitor_printf(mon, " Device %d.%d, speed %s Mb/s\n",
  575 + bus_num, addr, speed_str);
575 576 class_str = usb_class_str(class_id);
576 577 if (class_str)
577   - term_printf(" %s:", class_str);
  578 + monitor_printf(mon, " %s:", class_str);
578 579 else
579   - term_printf(" Class %02x:", class_id);
580   - term_printf(" USB device %04x:%04x", vendor_id, product_id);
  580 + monitor_printf(mon, " Class %02x:", class_id);
  581 + monitor_printf(mon, " USB device %04x:%04x", vendor_id, product_id);
581 582 if (product_name[0] != '\0')
582   - term_printf(", %s", product_name);
583   - term_printf("\n");
  583 + monitor_printf(mon, ", %s", product_name);
  584 + monitor_printf(mon, "\n");
584 585 }
585 586  
586   -static int usb_host_info_device(void *opaque, int bus_num, int addr,
  587 +static int usb_host_info_device(void *opaque,
  588 + int bus_num, int addr,
587 589 int class_id,
588 590 int vendor_id, int product_id,
589 591 const char *product_name,
... ... @@ -594,7 +596,7 @@ static int usb_host_info_device(void *opaque, int bus_num, int addr,
594 596 return 0;
595 597 }
596 598  
597   -void usb_host_info(void)
  599 +void usb_host_info(Monitor *mon)
598 600 {
599 601 usb_host_scan(NULL, usb_host_info_device);
600 602 }
... ...
usb-linux.c
... ... @@ -32,7 +32,7 @@
32 32  
33 33 #include "qemu-common.h"
34 34 #include "qemu-timer.h"
35   -#include "console.h"
  35 +#include "monitor.h"
36 36  
37 37 #include <dirent.h>
38 38 #include <sys/ioctl.h>
... ... @@ -985,6 +985,7 @@ static int usb_host_auto_del(const char *spec);
985 985  
986 986 USBDevice *usb_host_device_open(const char *devname)
987 987 {
  988 + Monitor *mon = cur_mon;
988 989 int bus_num, addr;
989 990 char product_name[PRODUCT_NAME_SZ];
990 991  
... ... @@ -998,7 +999,8 @@ USBDevice *usb_host_device_open(const char *devname)
998 999 return NULL;
999 1000  
1000 1001 if (hostdev_find(bus_num, addr)) {
1001   - term_printf("husb: host usb device %d.%d is already open\n", bus_num, addr);
  1002 + monitor_printf(mon, "husb: host usb device %d.%d is already open\n",
  1003 + bus_num, addr);
1002 1004 return NULL;
1003 1005 }
1004 1006  
... ... @@ -1149,6 +1151,7 @@ static int usb_host_scan_dev(void *opaque, USBScanFunc *func)
1149 1151 */
1150 1152 static int usb_host_read_file(char *line, size_t line_size, const char *device_file, const char *device_name)
1151 1153 {
  1154 + Monitor *mon = cur_mon;
1152 1155 FILE *f;
1153 1156 int ret = 0;
1154 1157 char filename[PATH_MAX];
... ... @@ -1161,7 +1164,7 @@ static int usb_host_read_file(char *line, size_t line_size, const char *device_f
1161 1164 fclose(f);
1162 1165 ret = 1;
1163 1166 } else {
1164   - term_printf("husb: could not open %s\n", filename);
  1167 + monitor_printf(mon, "husb: could not open %s\n", filename);
1165 1168 }
1166 1169  
1167 1170 return ret;
... ... @@ -1254,6 +1257,7 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func)
1254 1257 */
1255 1258 static int usb_host_scan(void *opaque, USBScanFunc *func)
1256 1259 {
  1260 + Monitor *mon = cur_mon;
1257 1261 FILE *f = 0;
1258 1262 DIR *dir = 0;
1259 1263 int ret = 0;
... ... @@ -1292,14 +1296,15 @@ static int usb_host_scan(void *opaque, USBScanFunc *func)
1292 1296 }
1293 1297 found_devices:
1294 1298 if (!usb_fs_type) {
1295   - term_printf("husb: unable to access USB devices\n");
  1299 + monitor_printf(mon, "husb: unable to access USB devices\n");
1296 1300 return -ENOENT;
1297 1301 }
1298 1302  
1299 1303 /* the module setting (used later for opening devices) */
1300 1304 usb_host_device_path = qemu_mallocz(strlen(devpath)+1);
1301 1305 strcpy(usb_host_device_path, devpath);
1302   - term_printf("husb: using %s file-system with %s\n", fs_type[usb_fs_type], usb_host_device_path);
  1306 + monitor_printf(mon, "husb: using %s file-system with %s\n",
  1307 + fs_type[usb_fs_type], usb_host_device_path);
1303 1308 }
1304 1309  
1305 1310 switch (usb_fs_type) {
... ... @@ -1606,6 +1611,7 @@ static void usb_info_device(int bus_num, int addr, int class_id,
1606 1611 const char *product_name,
1607 1612 int speed)
1608 1613 {
  1614 + Monitor *mon = cur_mon;
1609 1615 const char *class_str, *speed_str;
1610 1616  
1611 1617 switch(speed) {
... ... @@ -1623,17 +1629,17 @@ static void usb_info_device(int bus_num, int addr, int class_id,
1623 1629 break;
1624 1630 }
1625 1631  
1626   - term_printf(" Device %d.%d, speed %s Mb/s\n",
  1632 + monitor_printf(mon, " Device %d.%d, speed %s Mb/s\n",
1627 1633 bus_num, addr, speed_str);
1628 1634 class_str = usb_class_str(class_id);
1629 1635 if (class_str)
1630   - term_printf(" %s:", class_str);
  1636 + monitor_printf(mon, " %s:", class_str);
1631 1637 else
1632   - term_printf(" Class %02x:", class_id);
1633   - term_printf(" USB device %04x:%04x", vendor_id, product_id);
  1638 + monitor_printf(mon, " Class %02x:", class_id);
  1639 + monitor_printf(mon, " USB device %04x:%04x", vendor_id, product_id);
1634 1640 if (product_name[0] != '\0')
1635   - term_printf(", %s", product_name);
1636   - term_printf("\n");
  1641 + monitor_printf(mon, ", %s", product_name);
  1642 + monitor_printf(mon, "\n");
1637 1643 }
1638 1644  
1639 1645 static int usb_host_info_device(void *opaque, int bus_num, int addr,
... ... @@ -1663,20 +1669,21 @@ static void hex2str(int val, char *str, size_t size)
1663 1669 snprintf(str, size, "%x", val);
1664 1670 }
1665 1671  
1666   -void usb_host_info(void)
  1672 +void usb_host_info(Monitor *mon)
1667 1673 {
1668 1674 struct USBAutoFilter *f;
1669 1675  
1670 1676 usb_host_scan(NULL, usb_host_info_device);
1671 1677  
1672 1678 if (usb_auto_filter)
1673   - term_printf(" Auto filters:\n");
  1679 + monitor_printf(mon, " Auto filters:\n");
1674 1680 for (f = usb_auto_filter; f; f = f->next) {
1675 1681 char bus[10], addr[10], vid[10], pid[10];
1676 1682 dec2str(f->bus_num, bus, sizeof(bus));
1677 1683 dec2str(f->addr, addr, sizeof(addr));
1678 1684 hex2str(f->vendor_id, vid, sizeof(vid));
1679 1685 hex2str(f->product_id, pid, sizeof(pid));
1680   - term_printf(" Device %s.%s ID %s:%s\n", bus, addr, vid, pid);
  1686 + monitor_printf(mon, " Device %s.%s ID %s:%s\n",
  1687 + bus, addr, vid, pid);
1681 1688 }
1682 1689 }
... ...
usb-stub.c
... ... @@ -33,10 +33,11 @@
33 33 #include "qemu-common.h"
34 34 #include "console.h"
35 35 #include "hw/usb.h"
  36 +#include "monitor.h"
36 37  
37   -void usb_host_info(void)
  38 +void usb_host_info(Monitor *mon)
38 39 {
39   - term_printf("USB host devices not supported\n");
  40 + monitor_printf(mon, "USB host devices not supported\n");
40 41 }
41 42  
42 43 /* XXX: modify configure to compile the right host driver */
... ...
... ... @@ -31,6 +31,7 @@
31 31 #include "hw/baum.h"
32 32 #include "hw/bt.h"
33 33 #include "net.h"
  34 +#include "monitor.h"
34 35 #include "console.h"
35 36 #include "sysemu.h"
36 37 #include "gdbstub.h"
... ... @@ -653,34 +654,34 @@ int kbd_mouse_is_absolute(void)
653 654 return qemu_put_mouse_event_current->qemu_put_mouse_event_absolute;
654 655 }
655 656  
656   -void do_info_mice(void)
  657 +void do_info_mice(Monitor *mon)
657 658 {
658 659 QEMUPutMouseEntry *cursor;
659 660 int index = 0;
660 661  
661 662 if (!qemu_put_mouse_event_head) {
662   - term_printf("No mouse devices connected\n");
  663 + monitor_printf(mon, "No mouse devices connected\n");
663 664 return;
664 665 }
665 666  
666   - term_printf("Mouse devices available:\n");
  667 + monitor_printf(mon, "Mouse devices available:\n");
667 668 cursor = qemu_put_mouse_event_head;
668 669 while (cursor != NULL) {
669   - term_printf("%c Mouse #%d: %s\n",
670   - (cursor == qemu_put_mouse_event_current ? '*' : ' '),
671   - index, cursor->qemu_put_mouse_event_name);
  670 + monitor_printf(mon, "%c Mouse #%d: %s\n",
  671 + (cursor == qemu_put_mouse_event_current ? '*' : ' '),
  672 + index, cursor->qemu_put_mouse_event_name);
672 673 index++;
673 674 cursor = cursor->next;
674 675 }
675 676 }
676 677  
677   -void do_mouse_set(int index)
  678 +void do_mouse_set(Monitor *mon, int index)
678 679 {
679 680 QEMUPutMouseEntry *cursor;
680 681 int i = 0;
681 682  
682 683 if (!qemu_put_mouse_event_head) {
683   - term_printf("No mouse devices connected\n");
  684 + monitor_printf(mon, "No mouse devices connected\n");
684 685 return;
685 686 }
686 687  
... ... @@ -693,7 +694,7 @@ void do_mouse_set(int index)
693 694 if (cursor != NULL)
694 695 qemu_put_mouse_event_current = cursor;
695 696 else
696   - term_printf("Mouse at given index not found\n");
  697 + monitor_printf(mon, "Mouse at given index not found\n");
697 698 }
698 699  
699 700 /* compute with 96 bit intermediate result: (a*b)/c */
... ... @@ -2697,7 +2698,8 @@ static int usb_device_add(const char *devname, int is_hotplug)
2697 2698 if (bdrv_key_required(bs)) {
2698 2699 autostart = 0;
2699 2700 if (is_hotplug) {
2700   - monitor_read_bdrv_key_start(bs, usb_msd_password_cb, dev);
  2701 + monitor_read_bdrv_key_start(cur_mon, bs, usb_msd_password_cb,
  2702 + dev);
2701 2703 return 0;
2702 2704 }
2703 2705 }
... ... @@ -2779,24 +2781,24 @@ static int usb_device_del(const char *devname)
2779 2781 return usb_device_del_addr(bus_num, addr);
2780 2782 }
2781 2783  
2782   -void do_usb_add(const char *devname)
  2784 +void do_usb_add(Monitor *mon, const char *devname)
2783 2785 {
2784 2786 usb_device_add(devname, 1);
2785 2787 }
2786 2788  
2787   -void do_usb_del(const char *devname)
  2789 +void do_usb_del(Monitor *mon, const char *devname)
2788 2790 {
2789 2791 usb_device_del(devname);
2790 2792 }
2791 2793  
2792   -void usb_info(void)
  2794 +void usb_info(Monitor *mon)
2793 2795 {
2794 2796 USBDevice *dev;
2795 2797 USBPort *port;
2796 2798 const char *speed_str;
2797 2799  
2798 2800 if (!usb_enabled) {
2799   - term_printf("USB support not enabled\n");
  2801 + monitor_printf(mon, "USB support not enabled\n");
2800 2802 return;
2801 2803 }
2802 2804  
... ... @@ -2818,8 +2820,8 @@ void usb_info(void)
2818 2820 speed_str = "?";
2819 2821 break;
2820 2822 }
2821   - term_printf(" Device %d.%d, Speed %s Mb/s, Product %s\n",
2822   - 0, dev->addr, speed_str, dev->devname);
  2823 + monitor_printf(mon, " Device %d.%d, Speed %s Mb/s, Product %s\n",
  2824 + 0, dev->addr, speed_str, dev->devname);
2823 2825 }
2824 2826 }
2825 2827  
... ... @@ -2853,16 +2855,17 @@ void pcmcia_socket_unregister(struct pcmcia_socket_s *socket)
2853 2855 }
2854 2856 }
2855 2857  
2856   -void pcmcia_info(void)
  2858 +void pcmcia_info(Monitor *mon)
2857 2859 {
2858 2860 struct pcmcia_socket_entry_s *iter;
  2861 +
2859 2862 if (!pcmcia_sockets)
2860   - term_printf("No PCMCIA sockets\n");
  2863 + monitor_printf(mon, "No PCMCIA sockets\n");
2861 2864  
2862 2865 for (iter = pcmcia_sockets; iter; iter = iter->next)
2863   - term_printf("%s: %s\n", iter->socket->slot_string,
2864   - iter->socket->attached ? iter->socket->card_string :
2865   - "Empty");
  2866 + monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
  2867 + iter->socket->attached ? iter->socket->card_string :
  2868 + "Empty");
2866 2869 }
2867 2870  
2868 2871 /***********************************************************/
... ... @@ -5726,7 +5729,7 @@ int main(int argc, char **argv, char **envp)
5726 5729 #endif
5727 5730  
5728 5731 if (loadvm)
5729   - do_loadvm(loadvm);
  5732 + do_loadvm(cur_mon, loadvm);
5730 5733  
5731 5734 if (incoming) {
5732 5735 autostart = 0; /* fixme how to deal with -daemonize */
... ...
... ... @@ -24,6 +24,7 @@
24 24 */
25 25  
26 26 #include "qemu-common.h"
  27 +#include "monitor.h"
27 28 #include "console.h"
28 29 #include "sysemu.h"
29 30 #include "qemu_socket.h"
... ... @@ -166,19 +167,19 @@ struct VncState
166 167 static VncDisplay *vnc_display; /* needed for info vnc */
167 168 static DisplayChangeListener *dcl;
168 169  
169   -void do_info_vnc(void)
  170 +void do_info_vnc(Monitor *mon)
170 171 {
171 172 if (vnc_display == NULL || vnc_display->display == NULL)
172   - term_printf("VNC server disabled\n");
  173 + monitor_printf(mon, "VNC server disabled\n");
173 174 else {
174   - term_printf("VNC server active on: ");
175   - term_print_filename(vnc_display->display);
176   - term_printf("\n");
  175 + monitor_printf(mon, "VNC server active on: ");
  176 + monitor_print_filename(mon, vnc_display->display);
  177 + monitor_printf(mon, "\n");
177 178  
178 179 if (vnc_display->clients == NULL)
179   - term_printf("No client connected\n");
  180 + monitor_printf(mon, "No client connected\n");
180 181 else
181   - term_printf("Client connected\n");
  182 + monitor_printf(mon, "Client connected\n");
182 183 }
183 184 }
184 185  
... ... @@ -807,10 +808,11 @@ static void audio_capture(void *opaque, void *buf, int size)
807 808  
808 809 static void audio_add(VncState *vs)
809 810 {
  811 + Monitor *mon = cur_mon;
810 812 struct audio_capture_ops ops;
811 813  
812 814 if (vs->audio_cap) {
813   - term_printf ("audio already running\n");
  815 + monitor_printf(mon, "audio already running\n");
814 816 return;
815 817 }
816 818  
... ... @@ -820,7 +822,7 @@ static void audio_add(VncState *vs)
820 822  
821 823 vs->audio_cap = AUD_add_capture(NULL, &vs->as, &ops, vs);
822 824 if (!vs->audio_cap) {
823   - term_printf ("Failed to add audio capture\n");
  825 + monitor_printf(mon, "Failed to add audio capture\n");
824 826 }
825 827 }
826 828  
... ...