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,7 +23,7 @@
23 */ 23 */
24 #include "hw/hw.h" 24 #include "hw/hw.h"
25 #include "audio.h" 25 #include "audio.h"
26 -#include "console.h" 26 +#include "monitor.h"
27 #include "qemu-timer.h" 27 #include "qemu-timer.h"
28 #include "sysemu.h" 28 #include "sysemu.h"
29 29
@@ -328,10 +328,10 @@ void AUD_vlog (const char *cap, const char *fmt, va_list ap) @@ -328,10 +328,10 @@ void AUD_vlog (const char *cap, const char *fmt, va_list ap)
328 { 328 {
329 if (conf.log_to_monitor) { 329 if (conf.log_to_monitor) {
330 if (cap) { 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 else { 336 else {
337 if (cap) { 337 if (cap) {
audio/wavcapture.c
1 #include "hw/hw.h" 1 #include "hw/hw.h"
2 -#include "console.h" 2 +#include "monitor.h"
3 #include "audio.h" 3 #include "audio.h"
4 4
5 typedef struct { 5 typedef struct {
@@ -71,9 +71,9 @@ static void wav_capture_info (void *opaque) @@ -71,9 +71,9 @@ static void wav_capture_info (void *opaque)
71 WAVState *wav = opaque; 71 WAVState *wav = opaque;
72 char *path = wav->path; 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 static struct capture_ops wav_capture_ops = { 79 static struct capture_ops wav_capture_ops = {
@@ -84,6 +84,7 @@ static struct capture_ops wav_capture_ops = { @@ -84,6 +84,7 @@ static struct capture_ops wav_capture_ops = {
84 int wav_start_capture (CaptureState *s, const char *path, int freq, 84 int wav_start_capture (CaptureState *s, const char *path, int freq,
85 int bits, int nchannels) 85 int bits, int nchannels)
86 { 86 {
  87 + Monitor *mon = cur_mon;
87 WAVState *wav; 88 WAVState *wav;
88 uint8_t hdr[] = { 89 uint8_t hdr[] = {
89 0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, 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,13 +98,13 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
97 CaptureVoiceOut *cap; 98 CaptureVoiceOut *cap;
98 99
99 if (bits != 8 && bits != 16) { 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 return -1; 102 return -1;
102 } 103 }
103 104
104 if (nchannels != 1 && nchannels != 2) { 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 return -1; 108 return -1;
108 } 109 }
109 110
@@ -131,8 +132,8 @@ int wav_start_capture (CaptureState *s, const char *path, int freq, @@ -131,8 +132,8 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
131 132
132 wav->f = qemu_fopen (path, "wb"); 133 wav->f = qemu_fopen (path, "wb");
133 if (!wav->f) { 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 qemu_free (wav); 137 qemu_free (wav);
137 return -1; 138 return -1;
138 } 139 }
@@ -146,7 +147,7 @@ int wav_start_capture (CaptureState *s, const char *path, int freq, @@ -146,7 +147,7 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
146 147
147 cap = AUD_add_capture (NULL, &as, &ops, wav); 148 cap = AUD_add_capture (NULL, &as, &ops, wav);
148 if (!cap) { 149 if (!cap) {
149 - term_printf ("Failed to add audio capture\n"); 150 + monitor_printf(mon, "Failed to add audio capture\n");
150 qemu_free (wav->path); 151 qemu_free (wav->path);
151 qemu_fclose (wav->f); 152 qemu_fclose (wav->f);
152 qemu_free (wav); 153 qemu_free (wav);
@@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
28 #endif 28 #endif
29 29
30 #include "qemu-common.h" 30 #include "qemu-common.h"
31 -#include "console.h" 31 +#include "monitor.h"
32 #include "block_int.h" 32 #include "block_int.h"
33 33
34 #ifdef _BSD 34 #ifdef _BSD
@@ -1091,66 +1091,66 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, @@ -1091,66 +1091,66 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
1091 return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum); 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 BlockDriverState *bs; 1096 BlockDriverState *bs;
1097 1097
1098 for (bs = bdrv_first; bs != NULL; bs = bs->next) { 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 switch(bs->type) { 1101 switch(bs->type) {
1102 case BDRV_TYPE_HD: 1102 case BDRV_TYPE_HD:
1103 - term_printf("hd"); 1103 + monitor_printf(mon, "hd");
1104 break; 1104 break;
1105 case BDRV_TYPE_CDROM: 1105 case BDRV_TYPE_CDROM:
1106 - term_printf("cdrom"); 1106 + monitor_printf(mon, "cdrom");
1107 break; 1107 break;
1108 case BDRV_TYPE_FLOPPY: 1108 case BDRV_TYPE_FLOPPY:
1109 - term_printf("floppy"); 1109 + monitor_printf(mon, "floppy");
1110 break; 1110 break;
1111 } 1111 }
1112 - term_printf(" removable=%d", bs->removable); 1112 + monitor_printf(mon, " removable=%d", bs->removable);
1113 if (bs->removable) { 1113 if (bs->removable) {
1114 - term_printf(" locked=%d", bs->locked); 1114 + monitor_printf(mon, " locked=%d", bs->locked);
1115 } 1115 }
1116 if (bs->drv) { 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 if (bs->backing_file[0] != '\0') { 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 } else { 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 /* The "info blockstats" command. */ 1133 /* The "info blockstats" command. */
1134 -void bdrv_info_stats (void) 1134 +void bdrv_info_stats(Monitor *mon)
1135 { 1135 {
1136 BlockDriverState *bs; 1136 BlockDriverState *bs;
1137 BlockDriverInfo bdi; 1137 BlockDriverInfo bdi;
1138 1138
1139 for (bs = bdrv_first; bs != NULL; bs = bs->next) { 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 if (bdrv_get_info(bs, &bdi) == 0) 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,8 +56,8 @@ typedef struct QEMUSnapshotInfo {
56 56
57 #define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_CACHE_DEF) 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 void bdrv_init(void); 62 void bdrv_init(void);
63 BlockDriver *bdrv_find_format(const char *format_name); 63 BlockDriver *bdrv_find_format(const char *format_name);
console.h
@@ -43,8 +43,8 @@ struct mouse_transform_info_s { @@ -43,8 +43,8 @@ struct mouse_transform_info_s {
43 int a[7]; 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 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx 49 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
50 constants) */ 50 constants) */
@@ -287,39 +287,9 @@ void vnc_display_init(DisplayState *ds); @@ -287,39 +287,9 @@ void vnc_display_init(DisplayState *ds);
287 void vnc_display_close(DisplayState *ds); 287 void vnc_display_close(DisplayState *ds);
288 int vnc_display_open(DisplayState *ds, const char *display); 288 int vnc_display_open(DisplayState *ds, const char *display);
289 int vnc_display_password(DisplayState *ds, const char *password); 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 /* curses.c */ 292 /* curses.c */
293 void curses_display_init(DisplayState *ds, int full_screen); 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 #endif 295 #endif
@@ -308,8 +308,7 @@ const char *lookup_symbol(target_ulong orig_addr) @@ -308,8 +308,7 @@ const char *lookup_symbol(target_ulong orig_addr)
308 308
309 #if !defined(CONFIG_USER_ONLY) 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 static int monitor_disas_is_physical; 313 static int monitor_disas_is_physical;
315 static CPUState *monitor_disas_env; 314 static CPUState *monitor_disas_env;
@@ -330,19 +329,19 @@ static int monitor_fprintf(FILE *stream, const char *fmt, ...) @@ -330,19 +329,19 @@ static int monitor_fprintf(FILE *stream, const char *fmt, ...)
330 { 329 {
331 va_list ap; 330 va_list ap;
332 va_start(ap, fmt); 331 va_start(ap, fmt);
333 - term_vprintf(fmt, ap); 332 + monitor_vprintf((Monitor *)stream, fmt, ap);
334 va_end(ap); 333 va_end(ap);
335 return 0; 334 return 0;
336 } 335 }
337 336
338 -void monitor_disas(CPUState *env, 337 +void monitor_disas(Monitor *mon, CPUState *env,
339 target_ulong pc, int nb_insn, int is_physical, int flags) 338 target_ulong pc, int nb_insn, int is_physical, int flags)
340 { 339 {
341 int count, i; 340 int count, i;
342 struct disassemble_info disasm_info; 341 struct disassemble_info disasm_info;
343 int (*print_insn)(bfd_vma pc, disassemble_info *info); 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 monitor_disas_env = env; 346 monitor_disas_env = env;
348 monitor_disas_is_physical = is_physical; 347 monitor_disas_is_physical = is_physical;
@@ -388,15 +387,15 @@ void monitor_disas(CPUState *env, @@ -388,15 +387,15 @@ void monitor_disas(CPUState *env,
388 print_insn = print_insn_little_mips; 387 print_insn = print_insn_little_mips;
389 #endif 388 #endif
390 #else 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 return; 392 return;
394 #endif 393 #endif
395 394
396 for(i = 0; i < nb_insn; i++) { 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 count = print_insn(pc, &disasm_info); 397 count = print_insn(pc, &disasm_info);
399 - term_printf("\n"); 398 + monitor_printf(mon, "\n");
400 if (count < 0) 399 if (count < 0)
401 break; 400 break;
402 pc += count; 401 pc += count;
1 #ifndef _QEMU_DISAS_H 1 #ifndef _QEMU_DISAS_H
2 #define _QEMU_DISAS_H 2 #define _QEMU_DISAS_H
3 3
  4 +#include "qemu-common.h"
  5 +
4 /* Disassemble this for me please... (debugging). */ 6 /* Disassemble this for me please... (debugging). */
5 void disas(FILE *out, void *code, unsigned long size); 7 void disas(FILE *out, void *code, unsigned long size);
6 void target_disas(FILE *out, target_ulong code, target_ulong size, int flags); 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 target_ulong pc, int nb_insn, int is_physical, int flags); 13 target_ulong pc, int nb_insn, int is_physical, int flags);
  14 +#endif
9 15
10 /* Look up symbol for debugging purpose. Returns "" if unknown. */ 16 /* Look up symbol for debugging purpose. Returns "" if unknown. */
11 const char *lookup_symbol(target_ulong orig_addr); 17 const char *lookup_symbol(target_ulong orig_addr);
hw/an5206.c
@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 */ 7 */
8 8
9 #include "hw.h" 9 #include "hw.h"
  10 +#include "pc.h"
10 #include "mcf.h" 11 #include "mcf.h"
11 #include "sysemu.h" 12 #include "sysemu.h"
12 #include "boards.h" 13 #include "boards.h"
@@ -16,11 +17,11 @@ @@ -16,11 +17,11 @@
16 #define AN5206_RAMBAR_ADDR 0x20000000 17 #define AN5206_RAMBAR_ADDR 0x20000000
17 18
18 /* Stub functions for hardware that doesn't exist. */ 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,14 +8,15 @@
8 */ 8 */
9 9
10 #include "hw.h" 10 #include "hw.h"
  11 +#include "pc.h"
11 #include "arm-misc.h" 12 #include "arm-misc.h"
12 13
13 /* Stub functions for hardware that doesn't exist. */ 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,6 +24,7 @@
24 24
25 #include <stdio.h> 25 #include <stdio.h>
26 #include "hw.h" 26 #include "hw.h"
  27 +#include "pc.h"
27 #include "etraxfs.h" 28 #include "etraxfs.h"
28 29
29 #define D(x) 30 #define D(x)
@@ -135,11 +136,11 @@ static CPUWriteMemoryFunc *pic_write[] = { @@ -135,11 +136,11 @@ static CPUWriteMemoryFunc *pic_write[] = {
135 &pic_writel, 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,7 +24,7 @@
24 #include "hw.h" 24 #include "hw.h"
25 #include "pc.h" 25 #include "pc.h"
26 #include "isa.h" 26 #include "isa.h"
27 -#include "console.h" 27 +#include "monitor.h"
28 28
29 /* debug PIC */ 29 /* debug PIC */
30 //#define DEBUG_PIC 30 //#define DEBUG_PIC
@@ -511,7 +511,7 @@ static void pic_init1(int io_addr, int elcr_addr, PicState *s) @@ -511,7 +511,7 @@ static void pic_init1(int io_addr, int elcr_addr, PicState *s)
511 qemu_register_reset(pic_reset, s); 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 int i; 516 int i;
517 PicState *s; 517 PicState *s;
@@ -521,26 +521,27 @@ void pic_info(void) @@ -521,26 +521,27 @@ void pic_info(void)
521 521
522 for(i=0;i<2;i++) { 522 for(i=0;i<2;i++) {
523 s = &isa_pic->pics[i]; 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 #ifndef DEBUG_IRQ_COUNT 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 #else 536 #else
536 int i; 537 int i;
537 int64_t count; 538 int64_t count;
538 539
539 - term_printf("IRQ statistics:\n"); 540 + monitor_printf(mon, "IRQ statistics:\n");
540 for (i = 0; i < 16; i++) { 541 for (i = 0; i < 16; i++) {
541 count = irq_count[i]; 542 count = irq_count[i];
542 if (count > 0) 543 if (count > 0)
543 - term_printf("%2d: %" PRId64 "\n", i, count); 544 + monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
544 } 545 }
545 #endif 546 #endif
546 } 547 }
@@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
31 #include "net.h" 31 #include "net.h"
32 #include "smbus.h" 32 #include "smbus.h"
33 #include "boards.h" 33 #include "boards.h"
34 -#include "console.h" 34 +#include "monitor.h"
35 #include "fw_cfg.h" 35 #include "fw_cfg.h"
36 #include "virtio-blk.h" 36 #include "virtio-blk.h"
37 #include "virtio-balloon.h" 37 #include "virtio-balloon.h"
@@ -208,6 +208,7 @@ static int boot_device2nibble(char boot_device) @@ -208,6 +208,7 @@ static int boot_device2nibble(char boot_device)
208 and used there as well */ 208 and used there as well */
209 static int pc_boot_set(void *opaque, const char *boot_device) 209 static int pc_boot_set(void *opaque, const char *boot_device)
210 { 210 {
  211 + Monitor *mon = cur_mon;
211 #define PC_MAX_BOOT_DEVICES 3 212 #define PC_MAX_BOOT_DEVICES 3
212 RTCState *s = (RTCState *)opaque; 213 RTCState *s = (RTCState *)opaque;
213 int nbds, bds[3] = { 0, }; 214 int nbds, bds[3] = { 0, };
@@ -215,14 +216,14 @@ static int pc_boot_set(void *opaque, const char *boot_device) @@ -215,14 +216,14 @@ static int pc_boot_set(void *opaque, const char *boot_device)
215 216
216 nbds = strlen(boot_device); 217 nbds = strlen(boot_device);
217 if (nbds > PC_MAX_BOOT_DEVICES) { 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 return(1); 220 return(1);
220 } 221 }
221 for (i = 0; i < nbds; i++) { 222 for (i = 0; i < nbds; i++) {
222 bds[i] = boot_device2nibble(boot_device[i]); 223 bds[i] = boot_device2nibble(boot_device[i]);
223 if (bds[i] == 0) { 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 return(1); 227 return(1);
227 } 228 }
228 } 229 }
1 #ifndef HW_PC_H 1 #ifndef HW_PC_H
2 #define HW_PC_H 2 #define HW_PC_H
  3 +
  4 +#include "qemu-common.h"
  5 +
3 /* PC-style peripherals (also used by other machines). */ 6 /* PC-style peripherals (also used by other machines). */
4 7
5 /* serial.c */ 8 /* serial.c */
@@ -34,8 +37,8 @@ void pic_set_alt_irq_func(PicState2 *s, SetIRQFunc *alt_irq_func, @@ -34,8 +37,8 @@ void pic_set_alt_irq_func(PicState2 *s, SetIRQFunc *alt_irq_func,
34 int pic_read_irq(PicState2 *s); 37 int pic_read_irq(PicState2 *s);
35 void pic_update_irq(PicState2 *s); 38 void pic_update_irq(PicState2 *s);
36 uint32_t pic_intack_read(PicState2 *s); 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 /* APIC */ 43 /* APIC */
41 typedef struct IOAPICState IOAPICState; 44 typedef struct IOAPICState IOAPICState;
hw/pci-hotplug.c
@@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
28 #include "net.h" 28 #include "net.h"
29 #include "sysemu.h" 29 #include "sysemu.h"
30 #include "pc.h" 30 #include "pc.h"
31 -#include "console.h" 31 +#include "monitor.h"
32 #include "block_int.h" 32 #include "block_int.h"
33 #include "virtio-blk.h" 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,7 +43,7 @@ static PCIDevice *qemu_pci_hot_add_nic(PCIBus *pci_bus, const char *opts)
43 return pci_nic_init (pci_bus, &nd_table[ret], -1, "rtl8139"); 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 int dom, pci_bus; 48 int dom, pci_bus;
49 unsigned slot; 49 unsigned slot;
@@ -52,13 +52,13 @@ void drive_hot_add(const char *pci_addr, const char *opts) @@ -52,13 +52,13 @@ void drive_hot_add(const char *pci_addr, const char *opts)
52 PCIDevice *dev; 52 PCIDevice *dev;
53 53
54 if (pci_read_devaddr(pci_addr, &dom, &pci_bus, &slot)) { 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 return; 56 return;
57 } 57 }
58 58
59 dev = pci_find_device(pci_bus, slot, 0); 59 dev = pci_find_device(pci_bus, slot, 0);
60 if (!dev) { 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 return; 62 return;
63 } 63 }
64 64
@@ -75,16 +75,18 @@ void drive_hot_add(const char *pci_addr, const char *opts) @@ -75,16 +75,18 @@ void drive_hot_add(const char *pci_addr, const char *opts)
75 drives_table[drive_idx].unit); 75 drives_table[drive_idx].unit);
76 break; 76 break;
77 default: 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 if (success) 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 return; 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 void *opaque = NULL; 91 void *opaque = NULL;
90 int type = -1, drive_idx = -1; 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,7 +99,7 @@ static PCIDevice *qemu_pci_hot_add_storage(PCIBus *pci_bus, const char *opts)
97 type = IF_VIRTIO; 99 type = IF_VIRTIO;
98 } 100 }
99 } else { 101 } else {
100 - term_printf("no if= specified\n"); 102 + monitor_printf(mon, "no if= specified\n");
101 return NULL; 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,7 +108,7 @@ static PCIDevice *qemu_pci_hot_add_storage(PCIBus *pci_bus, const char *opts)
106 if (drive_idx < 0) 108 if (drive_idx < 0)
107 return NULL; 109 return NULL;
108 } else if (type == IF_VIRTIO) { 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 return NULL; 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,13 +123,14 @@ static PCIDevice *qemu_pci_hot_add_storage(PCIBus *pci_bus, const char *opts)
121 opaque = virtio_blk_init (pci_bus, drives_table[drive_idx].bdrv); 123 opaque = virtio_blk_init (pci_bus, drives_table[drive_idx].bdrv);
122 break; 124 break;
123 default: 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 return opaque; 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 PCIDevice *dev = NULL; 135 PCIDevice *dev = NULL;
133 PCIBus *pci_bus; 136 PCIBus *pci_bus;
@@ -135,47 +138,47 @@ void pci_device_hot_add(const char *pci_addr, const char *type, const char *opts @@ -135,47 +138,47 @@ void pci_device_hot_add(const char *pci_addr, const char *type, const char *opts
135 unsigned slot; 138 unsigned slot;
136 139
137 if (pci_assign_devaddr(pci_addr, &dom, &bus, &slot)) { 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 return; 142 return;
140 } 143 }
141 144
142 pci_bus = pci_find_bus(bus); 145 pci_bus = pci_find_bus(bus);
143 if (!pci_bus) { 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 return; 148 return;
146 } 149 }
147 150
148 if (strcmp(type, "nic") == 0) 151 if (strcmp(type, "nic") == 0)
149 dev = qemu_pci_hot_add_nic(pci_bus, opts); 152 dev = qemu_pci_hot_add_nic(pci_bus, opts);
150 else if (strcmp(type, "storage") == 0) 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 else 155 else
153 - term_printf("invalid type: %s\n", type); 156 + monitor_printf(mon, "invalid type: %s\n", type);
154 157
155 if (dev) { 158 if (dev) {
156 qemu_system_device_hot_add(bus, PCI_SLOT(dev->devfn), 1); 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 } else 163 } else
161 - term_printf("failed to add %s\n", opts); 164 + monitor_printf(mon, "failed to add %s\n", opts);
162 } 165 }
163 #endif 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 PCIDevice *d; 170 PCIDevice *d;
168 int dom, bus; 171 int dom, bus;
169 unsigned slot; 172 unsigned slot;
170 173
171 if (pci_read_devaddr(pci_addr, &dom, &bus, &slot)) { 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 return; 176 return;
174 } 177 }
175 178
176 d = pci_find_device(bus, slot, 0); 179 d = pci_find_device(bus, slot, 0);
177 if (!d) { 180 if (!d) {
178 - term_printf("slot %d empty\n", slot); 181 + monitor_printf(mon, "slot %d empty\n", slot);
179 return; 182 return;
180 } 183 }
181 184
@@ -199,7 +202,7 @@ void pci_device_hot_remove_success(int pcibus, int slot) @@ -199,7 +202,7 @@ void pci_device_hot_remove_success(int pcibus, int slot)
199 int class_code; 202 int class_code;
200 203
201 if (!d) { 204 if (!d) {
202 - term_printf("invalid slot %d\n", slot); 205 + monitor_printf(cur_mon, "invalid slot %d\n", slot);
203 return; 206 return;
204 } 207 }
205 208
hw/pci.c
@@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
23 */ 23 */
24 #include "hw.h" 24 #include "hw.h"
25 #include "pci.h" 25 #include "pci.h"
26 -#include "console.h" 26 +#include "monitor.h"
27 #include "net.h" 27 #include "net.h"
28 #include "virtio-net.h" 28 #include "virtio-net.h"
29 #include "sysemu.h" 29 #include "sysemu.h"
@@ -705,42 +705,44 @@ static const pci_class_desc pci_class_descriptions[] = @@ -705,42 +705,44 @@ static const pci_class_desc pci_class_descriptions[] =
705 705
706 static void pci_info_device(PCIDevice *d) 706 static void pci_info_device(PCIDevice *d)
707 { 707 {
  708 + Monitor *mon = cur_mon;
708 int i, class; 709 int i, class;
709 PCIIORegion *r; 710 PCIIORegion *r;
710 const pci_class_desc *desc; 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 class = le16_to_cpu(*((uint16_t *)(d->config + PCI_CLASS_DEVICE))); 715 class = le16_to_cpu(*((uint16_t *)(d->config + PCI_CLASS_DEVICE)));
715 - term_printf(" "); 716 + monitor_printf(mon, " ");
716 desc = pci_class_descriptions; 717 desc = pci_class_descriptions;
717 while (desc->desc && class != desc->class) 718 while (desc->desc && class != desc->class)
718 desc++; 719 desc++;
719 if (desc->desc) { 720 if (desc->desc) {
720 - term_printf("%s", desc->desc); 721 + monitor_printf(mon, "%s", desc->desc);
721 } else { 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 le16_to_cpu(*((uint16_t *)(d->config + PCI_VENDOR_ID))), 726 le16_to_cpu(*((uint16_t *)(d->config + PCI_VENDOR_ID))),
726 le16_to_cpu(*((uint16_t *)(d->config + PCI_DEVICE_ID)))); 727 le16_to_cpu(*((uint16_t *)(d->config + PCI_DEVICE_ID))));
727 728
728 if (d->config[PCI_INTERRUPT_PIN] != 0) { 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 if (class == 0x0604) { 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 for(i = 0;i < PCI_NUM_REGIONS; i++) { 736 for(i = 0;i < PCI_NUM_REGIONS; i++) {
735 r = &d->io_regions[i]; 737 r = &d->io_regions[i];
736 if (r->size != 0) { 738 if (r->size != 0) {
737 - term_printf(" BAR%d: ", i); 739 + monitor_printf(mon, " BAR%d: ", i);
738 if (r->type & PCI_ADDRESS_SPACE_IO) { 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 } else { 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,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 pci_for_each_device(0, pci_info_device); 773 pci_for_each_device(0, pci_info_device);
772 } 774 }
hw/pci.h
1 #ifndef QEMU_PCI_H 1 #ifndef QEMU_PCI_H
2 #define QEMU_PCI_H 2 #define QEMU_PCI_H
3 3
  4 +#include "qemu-common.h"
  5 +
4 /* PCI includes legacy ISA access. */ 6 /* PCI includes legacy ISA access. */
5 #include "isa.h" 7 #include "isa.h"
6 8
@@ -242,7 +244,7 @@ PCIDevice *pci_find_device(int bus_num, int slot, int function); @@ -242,7 +244,7 @@ PCIDevice *pci_find_device(int bus_num, int slot, int function);
242 int pci_read_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp); 244 int pci_read_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp);
243 int pci_assign_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp); 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 PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, 248 PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
247 pci_map_irq_fn map_irq, const char *name); 249 pci_map_irq_fn map_irq, const char *name);
248 250
hw/pcmcia.h
1 /* PCMCIA/Cardbus */ 1 /* PCMCIA/Cardbus */
2 2
  3 +#include "qemu-common.h"
  4 +
3 struct pcmcia_socket_s { 5 struct pcmcia_socket_s {
4 qemu_irq irq; 6 qemu_irq irq;
5 int attached; 7 int attached;
@@ -9,7 +11,7 @@ struct pcmcia_socket_s { @@ -9,7 +11,7 @@ struct pcmcia_socket_s {
9 11
10 void pcmcia_socket_register(struct pcmcia_socket_s *socket); 12 void pcmcia_socket_register(struct pcmcia_socket_s *socket);
11 void pcmcia_socket_unregister(struct pcmcia_socket_s *socket); 13 void pcmcia_socket_unregister(struct pcmcia_socket_s *socket);
12 -void pcmcia_info(void); 14 +void pcmcia_info(Monitor *mon);
13 15
14 struct pcmcia_card_s { 16 struct pcmcia_card_s {
15 void *state; 17 void *state;
hw/shix.c
@@ -28,6 +28,7 @@ @@ -28,6 +28,7 @@
28 More information in target-sh4/README.sh4 28 More information in target-sh4/README.sh4
29 */ 29 */
30 #include "hw.h" 30 #include "hw.h"
  31 +#include "pc.h"
31 #include "sh.h" 32 #include "sh.h"
32 #include "sysemu.h" 33 #include "sysemu.h"
33 #include "boards.h" 34 #include "boards.h"
@@ -35,12 +36,12 @@ @@ -35,12 +36,12 @@
35 #define BIOS_FILENAME "shix_bios.bin" 36 #define BIOS_FILENAME "shix_bios.bin"
36 #define BIOS_ADDRESS 0xA0000000 37 #define BIOS_ADDRESS 0xA0000000
37 38
38 -void irq_info(void) 39 +void irq_info(Monitor *mon)
39 { 40 {
40 /* XXXXX */ 41 /* XXXXX */
41 } 42 }
42 43
43 -void pic_info(void) 44 +void pic_info(Monitor *mon)
44 { 45 {
45 /* XXXXX */ 46 /* XXXXX */
46 } 47 }
hw/slavio_intctl.c
@@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
23 */ 23 */
24 #include "hw.h" 24 #include "hw.h"
25 #include "sun4m.h" 25 #include "sun4m.h"
26 -#include "console.h" 26 +#include "monitor.h"
27 27
28 //#define DEBUG_IRQ_COUNT 28 //#define DEBUG_IRQ_COUNT
29 //#define DEBUG_IRQ 29 //#define DEBUG_IRQ
@@ -219,33 +219,33 @@ static CPUWriteMemoryFunc *slavio_intctlm_mem_write[3] = { @@ -219,33 +219,33 @@ static CPUWriteMemoryFunc *slavio_intctlm_mem_write[3] = {
219 slavio_intctlm_mem_writel, 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 SLAVIO_INTCTLState *s = opaque; 224 SLAVIO_INTCTLState *s = opaque;
225 int i; 225 int i;
226 226
227 for (i = 0; i < MAX_CPUS; i++) { 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 #ifndef DEBUG_IRQ_COUNT 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 #else 239 #else
240 SLAVIO_INTCTLState *s = opaque; 240 SLAVIO_INTCTLState *s = opaque;
241 int i; 241 int i;
242 int64_t count; 242 int64_t count;
243 243
244 - term_printf("IRQ statistics:\n"); 244 + monitor_printf(mon, "IRQ statistics:\n");
245 for (i = 0; i < 32; i++) { 245 for (i = 0; i < 32; i++) {
246 count = s->irq_count[i]; 246 count = s->irq_count[i];
247 if (count > 0) 247 if (count > 0)
248 - term_printf("%2d: %" PRId64 "\n", i, count); 248 + monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
249 } 249 }
250 #endif 250 #endif
251 } 251 }
hw/sun4c_intctl.c
@@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
23 */ 23 */
24 #include "hw.h" 24 #include "hw.h"
25 #include "sun4m.h" 25 #include "sun4m.h"
26 -#include "console.h" 26 +#include "monitor.h"
27 //#define DEBUG_IRQ_COUNT 27 //#define DEBUG_IRQ_COUNT
28 //#define DEBUG_IRQ 28 //#define DEBUG_IRQ
29 29
@@ -90,26 +90,26 @@ static CPUWriteMemoryFunc *sun4c_intctl_mem_write[3] = { @@ -90,26 +90,26 @@ static CPUWriteMemoryFunc *sun4c_intctl_mem_write[3] = {
90 NULL, 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 Sun4c_INTCTLState *s = opaque; 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 #ifndef DEBUG_IRQ_COUNT 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 #else 105 #else
106 Sun4c_INTCTLState *s = opaque; 106 Sun4c_INTCTLState *s = opaque;
107 int64_t count; 107 int64_t count;
108 108
109 - term_printf("IRQ statistics:\n"); 109 + monitor_printf(mon, "IRQ statistics:\n");
110 count = s->irq_count[i]; 110 count = s->irq_count[i];
111 if (count > 0) 111 if (count > 0)
112 - term_printf("%2d: %" PRId64 "\n", i, count); 112 + monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
113 #endif 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,16 +283,16 @@ static void nvram_init(m48t59_t *nvram, uint8_t *macaddr, const char *cmdline,
283 283
284 static void *slavio_intctl; 284 static void *slavio_intctl;
285 285
286 -void pic_info(void) 286 +void pic_info(Monitor *mon)
287 { 287 {
288 if (slavio_intctl) 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 if (slavio_intctl) 294 if (slavio_intctl)
295 - slavio_irq_info(slavio_intctl); 295 + slavio_irq_info(mon, slavio_intctl);
296 } 296 }
297 297
298 void cpu_check_irqs(CPUState *env) 298 void cpu_check_irqs(CPUState *env)
hw/sun4m.h
1 #ifndef SUN4M_H 1 #ifndef SUN4M_H
2 #define SUN4M_H 2 #define SUN4M_H
3 3
  4 +#include "qemu-common.h"
  5 +
4 /* Devices used by sparc32 system. */ 6 /* Devices used by sparc32 system. */
5 7
6 /* iommu.c */ 8 /* iommu.c */
@@ -31,8 +33,8 @@ void *slavio_intctl_init(target_phys_addr_t addr, target_phys_addr_t addrg, @@ -31,8 +33,8 @@ void *slavio_intctl_init(target_phys_addr_t addr, target_phys_addr_t addrg,
31 const uint32_t *intbit_to_level, 33 const uint32_t *intbit_to_level,
32 qemu_irq **irq, qemu_irq **cpu_irq, 34 qemu_irq **irq, qemu_irq **cpu_irq,
33 qemu_irq **parent_irq, unsigned int cputimer); 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 /* sbi.c */ 39 /* sbi.c */
38 void *sbi_init(target_phys_addr_t addr, qemu_irq **irq, qemu_irq **cpu_irq, 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,8 +43,8 @@ void *sbi_init(target_phys_addr_t addr, qemu_irq **irq, qemu_irq **cpu_irq,
41 /* sun4c_intctl.c */ 43 /* sun4c_intctl.c */
42 void *sun4c_intctl_init(target_phys_addr_t addr, qemu_irq **irq, 44 void *sun4c_intctl_init(target_phys_addr_t addr, qemu_irq **irq,
43 qemu_irq *parent_irq); 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 /* slavio_timer.c */ 49 /* slavio_timer.c */
48 void slavio_timer_init_all(target_phys_addr_t base, qemu_irq master_irq, 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,7 +244,7 @@ USBDevice *usb_hub_init(int nb_ports);
244 /* usb-linux.c */ 244 /* usb-linux.c */
245 USBDevice *usb_host_device_open(const char *devname); 245 USBDevice *usb_host_device_open(const char *devname);
246 int usb_host_device_close(const char *devname); 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 /* usb-hid.c */ 249 /* usb-hid.c */
250 USBDevice *usb_mouse_init(void); 250 USBDevice *usb_mouse_init(void);
migration-exec.c
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 #include "migration.h" 18 #include "migration.h"
19 #include "qemu-char.h" 19 #include "qemu-char.h"
20 #include "sysemu.h" 20 #include "sysemu.h"
21 -#include "console.h" 21 +#include "monitor.h"
22 #include "buffered_file.h" 22 #include "buffered_file.h"
23 #include "block.h" 23 #include "block.h"
24 24
@@ -94,7 +94,7 @@ MigrationState *exec_start_outgoing_migration(const char *command, @@ -94,7 +94,7 @@ MigrationState *exec_start_outgoing_migration(const char *command,
94 94
95 if (s->detach == 1) { 95 if (s->detach == 1) {
96 dprintf("detaching from monitor\n"); 96 dprintf("detaching from monitor\n");
97 - monitor_suspend(); 97 + monitor_suspend(cur_mon);
98 s->detach = 2; 98 s->detach = 2;
99 } 99 }
100 100
migration-tcp.c
@@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
16 #include "migration.h" 16 #include "migration.h"
17 #include "qemu-char.h" 17 #include "qemu-char.h"
18 #include "sysemu.h" 18 #include "sysemu.h"
19 -#include "console.h" 19 +#include "monitor.h"
20 #include "buffered_file.h" 20 #include "buffered_file.h"
21 #include "block.h" 21 #include "block.h"
22 22
@@ -110,7 +110,7 @@ MigrationState *tcp_start_outgoing_migration(const char *host_port, @@ -110,7 +110,7 @@ MigrationState *tcp_start_outgoing_migration(const char *host_port,
110 110
111 if (s->detach == 1) { 111 if (s->detach == 1) {
112 dprintf("detaching from monitor\n"); 112 dprintf("detaching from monitor\n");
113 - monitor_suspend(); 113 + monitor_suspend(cur_mon);
114 s->detach = 2; 114 s->detach = 2;
115 } 115 }
116 116
migration.c
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 13
14 #include "qemu-common.h" 14 #include "qemu-common.h"
15 #include "migration.h" 15 #include "migration.h"
16 -#include "console.h" 16 +#include "monitor.h"
17 #include "buffered_file.h" 17 #include "buffered_file.h"
18 #include "sysemu.h" 18 #include "sysemu.h"
19 #include "block.h" 19 #include "block.h"
@@ -48,7 +48,7 @@ void qemu_start_incoming_migration(const char *uri) @@ -48,7 +48,7 @@ void qemu_start_incoming_migration(const char *uri)
48 fprintf(stderr, "unknown migration protocol: %s\n", uri); 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 MigrationState *s = NULL; 53 MigrationState *s = NULL;
54 const char *p; 54 const char *p;
@@ -60,10 +60,10 @@ void do_migrate(int detach, const char *uri) @@ -60,10 +60,10 @@ void do_migrate(int detach, const char *uri)
60 s = exec_start_outgoing_migration(p, max_throttle, detach); 60 s = exec_start_outgoing_migration(p, max_throttle, detach);
61 #endif 61 #endif
62 else 62 else
63 - term_printf("unknown migration protocol: %s\n", uri); 63 + monitor_printf(mon, "unknown migration protocol: %s\n", uri);
64 64
65 if (s == NULL) 65 if (s == NULL)
66 - term_printf("migration failed\n"); 66 + monitor_printf(mon, "migration failed\n");
67 else { 67 else {
68 if (current_migration) 68 if (current_migration)
69 current_migration->release(current_migration); 69 current_migration->release(current_migration);
@@ -72,7 +72,7 @@ void do_migrate(int detach, const char *uri) @@ -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 MigrationState *s = current_migration; 77 MigrationState *s = current_migration;
78 78
@@ -80,7 +80,7 @@ void do_migrate_cancel(void) @@ -80,7 +80,7 @@ void do_migrate_cancel(void)
80 s->cancel(s); 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 double d; 85 double d;
86 char *ptr; 86 char *ptr;
@@ -100,24 +100,24 @@ void do_migrate_set_speed(const char *value) @@ -100,24 +100,24 @@ void do_migrate_set_speed(const char *value)
100 max_throttle = (uint32_t)d; 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 MigrationState *s = current_migration; 105 MigrationState *s = current_migration;
106 - 106 +
107 if (s) { 107 if (s) {
108 - term_printf("Migration status: "); 108 + monitor_printf(mon, "Migration status: ");
109 switch (s->get_status(s)) { 109 switch (s->get_status(s)) {
110 case MIG_STATE_ACTIVE: 110 case MIG_STATE_ACTIVE:
111 - term_printf("active\n"); 111 + monitor_printf(mon, "active\n");
112 break; 112 break;
113 case MIG_STATE_COMPLETED: 113 case MIG_STATE_COMPLETED:
114 - term_printf("completed\n"); 114 + monitor_printf(mon, "completed\n");
115 break; 115 break;
116 case MIG_STATE_ERROR: 116 case MIG_STATE_ERROR:
117 - term_printf("failed\n"); 117 + monitor_printf(mon, "failed\n");
118 break; 118 break;
119 case MIG_STATE_CANCELLED: 119 case MIG_STATE_CANCELLED:
120 - term_printf("cancelled\n"); 120 + monitor_printf(mon, "cancelled\n");
121 break; 121 break;
122 } 122 }
123 } 123 }
@@ -146,7 +146,7 @@ void migrate_fd_cleanup(FdMigrationState *s) @@ -146,7 +146,7 @@ void migrate_fd_cleanup(FdMigrationState *s)
146 146
147 /* Don't resume monitor until we've flushed all of the buffers */ 147 /* Don't resume monitor until we've flushed all of the buffers */
148 if (s->detach == 2) { 148 if (s->detach == 2) {
149 - monitor_resume(); 149 + monitor_resume(cur_mon);
150 s->detach = 0; 150 s->detach = 0;
151 } 151 }
152 152
migration.h
@@ -14,6 +14,8 @@ @@ -14,6 +14,8 @@
14 #ifndef QEMU_MIGRATION_H 14 #ifndef QEMU_MIGRATION_H
15 #define QEMU_MIGRATION_H 15 #define QEMU_MIGRATION_H
16 16
  17 +#include "qemu-common.h"
  18 +
17 #define MIG_STATE_ERROR -1 19 #define MIG_STATE_ERROR -1
18 #define MIG_STATE_COMPLETED 0 20 #define MIG_STATE_COMPLETED 0
19 #define MIG_STATE_CANCELLED 1 21 #define MIG_STATE_CANCELLED 1
@@ -47,13 +49,13 @@ struct FdMigrationState @@ -47,13 +49,13 @@ struct FdMigrationState
47 49
48 void qemu_start_incoming_migration(const char *uri); 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 int exec_start_incoming_migration(const char *host_port); 60 int exec_start_incoming_migration(const char *host_port);
59 61
monitor.c
@@ -30,6 +30,8 @@ @@ -30,6 +30,8 @@
30 #include "net.h" 30 #include "net.h"
31 #include "qemu-char.h" 31 #include "qemu-char.h"
32 #include "sysemu.h" 32 #include "sysemu.h"
  33 +#include "monitor.h"
  34 +#include "readline.h"
33 #include "console.h" 35 #include "console.h"
34 #include "block.h" 36 #include "block.h"
35 #include "audio/audio.h" 37 #include "audio/audio.h"
@@ -57,36 +59,39 @@ @@ -57,36 +59,39 @@
57 * 59 *
58 */ 60 */
59 61
60 -typedef struct term_cmd_t { 62 +typedef struct mon_cmd_t {
61 const char *name; 63 const char *name;
62 const char *args_type; 64 const char *args_type;
63 void *handler; 65 void *handler;
64 const char *params; 66 const char *params;
65 const char *help; 67 const char *help;
66 -} term_cmd_t; 68 +} mon_cmd_t;
67 69
68 #define MAX_MON 4 70 #define MAX_MON 4
69 static CharDriverState *monitor_hd[MAX_MON]; 71 static CharDriverState *monitor_hd[MAX_MON];
70 static int hide_banner; 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 static uint8_t term_outbuf[1024]; 77 static uint8_t term_outbuf[1024];
76 static int term_outbuf_index; 78 static int term_outbuf_index;
77 static BlockDriverCompletionFunc *password_completion_cb; 79 static BlockDriverCompletionFunc *password_completion_cb;
78 static void *password_opaque; 80 static void *password_opaque;
79 81
  82 +Monitor *cur_mon;
  83 +
80 static void monitor_start_input(void); 84 static void monitor_start_input(void);
81 85
82 static CPUState *mon_cpu = NULL; 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 readline_start("Password: ", 1, readline_func, opaque); 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 int i; 96 int i;
92 if (term_outbuf_index > 0) { 97 if (term_outbuf_index > 0) {
@@ -98,7 +103,7 @@ void term_flush(void) @@ -98,7 +103,7 @@ void term_flush(void)
98 } 103 }
99 104
100 /* flush at every end of line or if the buffer is full */ 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 char c; 108 char c;
104 for(;;) { 109 for(;;) {
@@ -110,26 +115,26 @@ void term_puts(const char *str) @@ -110,26 +115,26 @@ void term_puts(const char *str)
110 term_outbuf[term_outbuf_index++] = c; 115 term_outbuf[term_outbuf_index++] = c;
111 if (term_outbuf_index >= (sizeof(term_outbuf) - 1) || 116 if (term_outbuf_index >= (sizeof(term_outbuf) - 1) ||
112 c == '\n') 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 char buf[4096]; 124 char buf[4096];
120 vsnprintf(buf, sizeof(buf), fmt, ap); 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 va_list ap; 131 va_list ap;
127 va_start(ap, fmt); 132 va_start(ap, fmt);
128 - term_vprintf(fmt, ap); 133 + monitor_vprintf(mon, fmt, ap);
129 va_end(ap); 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 int i; 139 int i;
135 140
@@ -138,19 +143,19 @@ void term_print_filename(const char *filename) @@ -138,19 +143,19 @@ void term_print_filename(const char *filename)
138 case ' ': 143 case ' ':
139 case '"': 144 case '"':
140 case '\\': 145 case '\\':
141 - term_printf("\\%c", filename[i]); 146 + monitor_printf(mon, "\\%c", filename[i]);
142 break; 147 break;
143 case '\t': 148 case '\t':
144 - term_printf("\\t"); 149 + monitor_printf(mon, "\\t");
145 break; 150 break;
146 case '\r': 151 case '\r':
147 - term_printf("\\r"); 152 + monitor_printf(mon, "\\r");
148 break; 153 break;
149 case '\n': 154 case '\n':
150 - term_printf("\\n"); 155 + monitor_printf(mon, "\\n");
151 break; 156 break;
152 default: 157 default:
153 - term_printf("%c", filename[i]); 158 + monitor_printf(mon, "%c", filename[i]);
154 break; 159 break;
155 } 160 }
156 } 161 }
@@ -160,7 +165,7 @@ static int monitor_fprintf(FILE *stream, const char *fmt, ...) @@ -160,7 +165,7 @@ static int monitor_fprintf(FILE *stream, const char *fmt, ...)
160 { 165 {
161 va_list ap; 166 va_list ap;
162 va_start(ap, fmt); 167 va_start(ap, fmt);
163 - term_vprintf(fmt, ap); 168 + monitor_vprintf((Monitor *)stream, fmt, ap);
164 va_end(ap); 169 va_end(ap);
165 return 0; 170 return 0;
166 } 171 }
@@ -185,39 +190,36 @@ static int compare_cmd(const char *name, const char *list) @@ -185,39 +190,36 @@ static int compare_cmd(const char *name, const char *list)
185 return 0; 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 for(cmd = cmds; cmd->name != NULL; cmd++) { 198 for(cmd = cmds; cmd->name != NULL; cmd++) {
193 if (!name || !strcmp(name, cmd->name)) 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 if (name && !strcmp(name, "info")) { 207 if (name && !strcmp(name, "info")) {
201 - help_cmd1(info_cmds, "info ", NULL); 208 + help_cmd_dump(mon, info_cmds, "info ", NULL);
202 } else { 209 } else {
203 - help_cmd1(term_cmds, "", name); 210 + help_cmd_dump(mon, mon_cmds, "", name);
204 if (name && !strcmp(name, "log")) { 211 if (name && !strcmp(name, "log")) {
205 const CPULogItem *item; 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 for(item = cpu_log_items; item->mask != 0; item++) { 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 int i, all_devices; 224 int i, all_devices;
223 225
@@ -229,10 +231,10 @@ static void do_commit(const char *device) @@ -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 if (!item) 239 if (!item)
238 goto help; 240 goto help;
@@ -241,48 +243,39 @@ static void do_info(const char *item) @@ -241,48 +243,39 @@ static void do_info(const char *item)
241 goto found; 243 goto found;
242 } 244 }
243 help: 245 help:
244 - help_cmd("info"); 246 + help_cmd(mon, "info");
245 return; 247 return;
246 found: 248 found:
247 handler = cmd->handler; 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 if (qemu_name) 260 if (qemu_name)
259 - term_printf("%s\n", qemu_name); 261 + monitor_printf(mon, "%s\n", qemu_name);
260 } 262 }
261 263
262 #if defined(TARGET_I386) 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 #endif 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 /* get the current CPU defined by the user */ 281 /* get the current CPU defined by the user */
@@ -307,22 +300,22 @@ static CPUState *mon_get_cpu(void) @@ -307,22 +300,22 @@ static CPUState *mon_get_cpu(void)
307 return mon_cpu; 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 CPUState *env; 305 CPUState *env;
313 env = mon_get_cpu(); 306 env = mon_get_cpu();
314 if (!env) 307 if (!env)
315 return; 308 return;
316 #ifdef TARGET_I386 309 #ifdef TARGET_I386
317 - cpu_dump_state(env, NULL, monitor_fprintf, 310 + cpu_dump_state(env, (FILE *)mon, monitor_fprintf,
318 X86_DUMP_FPU); 311 X86_DUMP_FPU);
319 #else 312 #else
320 - cpu_dump_state(env, NULL, monitor_fprintf, 313 + cpu_dump_state(env, (FILE *)mon, monitor_fprintf,
321 0); 314 0);
322 #endif 315 #endif
323 } 316 }
324 317
325 -static void do_info_cpus(void) 318 +static void do_info_cpus(Monitor *mon)
326 { 319 {
327 CPUState *env; 320 CPUState *env;
328 321
@@ -330,36 +323,38 @@ static void do_info_cpus(void) @@ -330,36 +323,38 @@ static void do_info_cpus(void)
330 mon_get_cpu(); 323 mon_get_cpu();
331 324
332 for(env = first_cpu; env != NULL; env = env->next_cpu) { 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 #if defined(TARGET_I386) 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 #elif defined(TARGET_PPC) 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 #elif defined(TARGET_SPARC) 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 #elif defined(TARGET_MIPS) 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 #endif 339 #endif
345 if (env->halted) 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 if (mon_set_cpu(index) < 0) 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 int i; 359 int i;
365 const char *str; 360 const char *str;
@@ -369,37 +364,37 @@ static void do_info_history (void) @@ -369,37 +364,37 @@ static void do_info_history (void)
369 str = readline_get_history(i); 364 str = readline_get_history(i);
370 if (!str) 365 if (!str)
371 break; 366 break;
372 - term_printf("%d: '%s'\n", i, str); 367 + monitor_printf(mon, "%d: '%s'\n", i, str);
373 i++; 368 i++;
374 } 369 }
375 } 370 }
376 371
377 #if defined(TARGET_PPC) 372 #if defined(TARGET_PPC)
378 /* XXX: not implemented in other targets */ 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 CPUState *env; 376 CPUState *env;
382 377
383 env = mon_get_cpu(); 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 #endif 381 #endif
387 382
388 -static void do_quit(void) 383 +static void do_quit(Monitor *mon)
389 { 384 {
390 exit(0); 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 if (bdrv_is_inserted(bs)) { 390 if (bdrv_is_inserted(bs)) {
396 if (!force) { 391 if (!force) {
397 if (!bdrv_is_removable(bs)) { 392 if (!bdrv_is_removable(bs)) {
398 - term_printf("device is not removable\n"); 393 + monitor_printf(mon, "device is not removable\n");
399 return -1; 394 return -1;
400 } 395 }
401 if (bdrv_is_locked(bs)) { 396 if (bdrv_is_locked(bs)) {
402 - term_printf("device is locked\n"); 397 + monitor_printf(mon, "device is locked\n");
403 return -1; 398 return -1;
404 } 399 }
405 } 400 }
@@ -408,50 +403,52 @@ static int eject_device(BlockDriverState *bs, int force) @@ -408,50 +403,52 @@ static int eject_device(BlockDriverState *bs, int force)
408 return 0; 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 BlockDriverState *bs; 408 BlockDriverState *bs;
414 409
415 bs = bdrv_find(filename); 410 bs = bdrv_find(filename);
416 if (!bs) { 411 if (!bs) {
417 - term_printf("device not found\n"); 412 + monitor_printf(mon, "device not found\n");
418 return; 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 BlockDriverState *bs; 421 BlockDriverState *bs;
426 BlockDriver *drv = NULL; 422 BlockDriver *drv = NULL;
427 423
428 bs = bdrv_find(device); 424 bs = bdrv_find(device);
429 if (!bs) { 425 if (!bs) {
430 - term_printf("device not found\n"); 426 + monitor_printf(mon, "device not found\n");
431 return; 427 return;
432 } 428 }
433 if (fmt) { 429 if (fmt) {
434 drv = bdrv_find_format(fmt); 430 drv = bdrv_find_format(fmt);
435 if (!drv) { 431 if (!drv) {
436 - term_printf("invalid format %s\n", fmt); 432 + monitor_printf(mon, "invalid format %s\n", fmt);
437 return; 433 return;
438 } 434 }
439 } 435 }
440 - if (eject_device(bs, 0) < 0) 436 + if (eject_device(mon, bs, 0) < 0)
441 return; 437 return;
442 bdrv_open2(bs, filename, 0, drv); 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 if (vnc_display_password(NULL, password) < 0) 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 monitor_start_input(); 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 if (strcmp(target, "passwd") == 0 || 453 if (strcmp(target, "passwd") == 0 ||
457 strcmp(target, "password") == 0) { 454 strcmp(target, "password") == 0) {
@@ -459,36 +456,37 @@ static void do_change_vnc(const char *target, const char *arg) @@ -459,36 +456,37 @@ static void do_change_vnc(const char *target, const char *arg)
459 char password[9]; 456 char password[9];
460 strncpy(password, arg, sizeof(password)); 457 strncpy(password, arg, sizeof(password));
461 password[sizeof(password) - 1] = '\0'; 458 password[sizeof(password) - 1] = '\0';
462 - change_vnc_password_cb(NULL, password); 459 + change_vnc_password_cb(mon, password, NULL);
463 } else { 460 } else {
464 - monitor_read_password(change_vnc_password_cb, NULL); 461 + monitor_read_password(mon, change_vnc_password_cb, NULL);
465 } 462 }
466 } else { 463 } else {
467 if (vnc_display_open(NULL, target) < 0) 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 if (strcmp(device, "vnc") == 0) { 472 if (strcmp(device, "vnc") == 0) {
475 - do_change_vnc(target, arg); 473 + do_change_vnc(mon, target, arg);
476 } else { 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 vga_hw_screen_dump(filename); 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 cpu_set_log_filename(filename); 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 int mask; 491 int mask;
494 492
@@ -497,88 +495,97 @@ static void do_log(const char *items) @@ -497,88 +495,97 @@ static void do_log(const char *items)
497 } else { 495 } else {
498 mask = cpu_str_to_log_mask(items); 496 mask = cpu_str_to_log_mask(items);
499 if (!mask) { 497 if (!mask) {
500 - help_cmd("log"); 498 + help_cmd(mon, "log");
501 return; 499 return;
502 } 500 }
503 } 501 }
504 cpu_set_log(mask); 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 vm_stop(EXCP_INTERRUPT); 507 vm_stop(EXCP_INTERRUPT);
510 } 508 }
511 509
512 static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs); 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 /* only resume the vm if all keys are set and valid */ 522 /* only resume the vm if all keys are set and valid */
520 - if (!err) 523 + if (!context.err)
521 vm_start(); 524 vm_start();
522 } 525 }
523 526
524 static void bdrv_key_cb(void *opaque, int err) 527 static void bdrv_key_cb(void *opaque, int err)
525 { 528 {
  529 + Monitor *mon = opaque;
  530 +
526 /* another key was set successfully, retry to continue */ 531 /* another key was set successfully, retry to continue */
527 if (!err) 532 if (!err)
528 - do_cont(); 533 + do_cont(mon);
529 } 534 }
530 535
531 static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs) 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 #ifdef CONFIG_GDBSTUB 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 if (!port) 550 if (!port)
545 port = DEFAULT_GDBSTUB_PORT; 551 port = DEFAULT_GDBSTUB_PORT;
546 if (gdbserver_start(port) < 0) { 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 } else { 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 #endif 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 switch(c) { 564 switch(c) {
558 case '\'': 565 case '\'':
559 - term_printf("\\'"); 566 + monitor_printf(mon, "\\'");
560 break; 567 break;
561 case '\\': 568 case '\\':
562 - term_printf("\\\\"); 569 + monitor_printf(mon, "\\\\");
563 break; 570 break;
564 case '\n': 571 case '\n':
565 - term_printf("\\n"); 572 + monitor_printf(mon, "\\n");
566 break; 573 break;
567 case '\r': 574 case '\r':
568 - term_printf("\\r"); 575 + monitor_printf(mon, "\\r");
569 break; 576 break;
570 default: 577 default:
571 if (c >= 32 && c <= 126) { 578 if (c >= 32 && c <= 126) {
572 - term_printf("%c", c); 579 + monitor_printf(mon, "%c", c);
573 } else { 580 } else {
574 - term_printf("\\x%02x", c); 581 + monitor_printf(mon, "\\x%02x", c);
575 } 582 }
576 break; 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 target_phys_addr_t addr, int is_physical) 589 target_phys_addr_t addr, int is_physical)
583 { 590 {
584 CPUState *env; 591 CPUState *env;
@@ -612,7 +619,7 @@ static void memory_dump(int count, int format, int wsize, @@ -612,7 +619,7 @@ static void memory_dump(int count, int format, int wsize,
612 } 619 }
613 } 620 }
614 #endif 621 #endif
615 - monitor_disas(env, addr, count, is_physical, flags); 622 + monitor_disas(mon, env, addr, count, is_physical, flags);
616 return; 623 return;
617 } 624 }
618 625
@@ -643,9 +650,9 @@ static void memory_dump(int count, int format, int wsize, @@ -643,9 +650,9 @@ static void memory_dump(int count, int format, int wsize,
643 650
644 while (len > 0) { 651 while (len > 0) {
645 if (is_physical) 652 if (is_physical)
646 - term_printf(TARGET_FMT_plx ":", addr); 653 + monitor_printf(mon, TARGET_FMT_plx ":", addr);
647 else 654 else
648 - term_printf(TARGET_FMT_lx ":", (target_ulong)addr); 655 + monitor_printf(mon, TARGET_FMT_lx ":", (target_ulong)addr);
649 l = len; 656 l = len;
650 if (l > line_size) 657 if (l > line_size)
651 l = line_size; 658 l = line_size;
@@ -656,7 +663,7 @@ static void memory_dump(int count, int format, int wsize, @@ -656,7 +663,7 @@ static void memory_dump(int count, int format, int wsize,
656 if (!env) 663 if (!env)
657 break; 664 break;
658 if (cpu_memory_rw_debug(env, addr, buf, l, 0) < 0) { 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 break; 667 break;
661 } 668 }
662 } 669 }
@@ -677,27 +684,27 @@ static void memory_dump(int count, int format, int wsize, @@ -677,27 +684,27 @@ static void memory_dump(int count, int format, int wsize,
677 v = ldq_raw(buf + i); 684 v = ldq_raw(buf + i);
678 break; 685 break;
679 } 686 }
680 - term_printf(" "); 687 + monitor_printf(mon, " ");
681 switch(format) { 688 switch(format) {
682 case 'o': 689 case 'o':
683 - term_printf("%#*" PRIo64, max_digits, v); 690 + monitor_printf(mon, "%#*" PRIo64, max_digits, v);
684 break; 691 break;
685 case 'x': 692 case 'x':
686 - term_printf("0x%0*" PRIx64, max_digits, v); 693 + monitor_printf(mon, "0x%0*" PRIx64, max_digits, v);
687 break; 694 break;
688 case 'u': 695 case 'u':
689 - term_printf("%*" PRIu64, max_digits, v); 696 + monitor_printf(mon, "%*" PRIu64, max_digits, v);
690 break; 697 break;
691 case 'd': 698 case 'd':
692 - term_printf("%*" PRId64, max_digits, v); 699 + monitor_printf(mon, "%*" PRId64, max_digits, v);
693 break; 700 break;
694 case 'c': 701 case 'c':
695 - term_printc(v); 702 + monitor_printc(mon, v);
696 break; 703 break;
697 } 704 }
698 i += wsize; 705 i += wsize;
699 } 706 }
700 - term_printf("\n"); 707 + monitor_printf(mon, "\n");
701 addr += l; 708 addr += l;
702 len -= l; 709 len -= l;
703 } 710 }
@@ -709,11 +716,11 @@ static void memory_dump(int count, int format, int wsize, @@ -709,11 +716,11 @@ static void memory_dump(int count, int format, int wsize,
709 #define GET_TLONG(h, l) (l) 716 #define GET_TLONG(h, l) (l)
710 #endif 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 uint32_t addrh, uint32_t addrl) 720 uint32_t addrh, uint32_t addrl)
714 { 721 {
715 target_long addr = GET_TLONG(addrh, addrl); 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 #if TARGET_PHYS_ADDR_BITS > 32 726 #if TARGET_PHYS_ADDR_BITS > 32
@@ -722,60 +729,61 @@ static void do_memory_dump(int count, int format, int size, @@ -722,60 +729,61 @@ static void do_memory_dump(int count, int format, int size,
722 #define GET_TPHYSADDR(h, l) (l) 729 #define GET_TPHYSADDR(h, l) (l)
723 #endif 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 target_phys_addr_t addr = GET_TPHYSADDR(addrh, addrl); 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 target_phys_addr_t val = GET_TPHYSADDR(valh, vall); 743 target_phys_addr_t val = GET_TPHYSADDR(valh, vall);
736 #if TARGET_PHYS_ADDR_BITS == 32 744 #if TARGET_PHYS_ADDR_BITS == 32
737 switch(format) { 745 switch(format) {
738 case 'o': 746 case 'o':
739 - term_printf("%#o", val); 747 + monitor_printf(mon, "%#o", val);
740 break; 748 break;
741 case 'x': 749 case 'x':
742 - term_printf("%#x", val); 750 + monitor_printf(mon, "%#x", val);
743 break; 751 break;
744 case 'u': 752 case 'u':
745 - term_printf("%u", val); 753 + monitor_printf(mon, "%u", val);
746 break; 754 break;
747 default: 755 default:
748 case 'd': 756 case 'd':
749 - term_printf("%d", val); 757 + monitor_printf(mon, "%d", val);
750 break; 758 break;
751 case 'c': 759 case 'c':
752 - term_printc(val); 760 + monitor_printc(mon, val);
753 break; 761 break;
754 } 762 }
755 #else 763 #else
756 switch(format) { 764 switch(format) {
757 case 'o': 765 case 'o':
758 - term_printf("%#" PRIo64, val); 766 + monitor_printf(mon, "%#" PRIo64, val);
759 break; 767 break;
760 case 'x': 768 case 'x':
761 - term_printf("%#" PRIx64, val); 769 + monitor_printf(mon, "%#" PRIx64, val);
762 break; 770 break;
763 case 'u': 771 case 'u':
764 - term_printf("%" PRIu64, val); 772 + monitor_printf(mon, "%" PRIu64, val);
765 break; 773 break;
766 default: 774 default:
767 case 'd': 775 case 'd':
768 - term_printf("%" PRId64, val); 776 + monitor_printf(mon, "%" PRId64, val);
769 break; 777 break;
770 case 'c': 778 case 'c':
771 - term_printc(val); 779 + monitor_printc(mon, val);
772 break; 780 break;
773 } 781 }
774 #endif 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 uint32_t size, const char *filename) 787 uint32_t size, const char *filename)
780 { 788 {
781 FILE *f; 789 FILE *f;
@@ -790,7 +798,7 @@ static void do_memory_save(unsigned int valh, unsigned int vall, @@ -790,7 +798,7 @@ static void do_memory_save(unsigned int valh, unsigned int vall,
790 798
791 f = fopen(filename, "wb"); 799 f = fopen(filename, "wb");
792 if (!f) { 800 if (!f) {
793 - term_printf("could not open '%s'\n", filename); 801 + monitor_printf(mon, "could not open '%s'\n", filename);
794 return; 802 return;
795 } 803 }
796 while (size != 0) { 804 while (size != 0) {
@@ -805,8 +813,9 @@ static void do_memory_save(unsigned int valh, unsigned int vall, @@ -805,8 +813,9 @@ static void do_memory_save(unsigned int valh, unsigned int vall,
805 fclose(f); 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 FILE *f; 820 FILE *f;
812 uint32_t l; 821 uint32_t l;
@@ -815,7 +824,7 @@ static void do_physical_memory_save(unsigned int valh, unsigned int vall, @@ -815,7 +824,7 @@ static void do_physical_memory_save(unsigned int valh, unsigned int vall,
815 824
816 f = fopen(filename, "wb"); 825 f = fopen(filename, "wb");
817 if (!f) { 826 if (!f) {
818 - term_printf("could not open '%s'\n", filename); 827 + monitor_printf(mon, "could not open '%s'\n", filename);
819 return; 828 return;
820 } 829 }
821 while (size != 0) { 830 while (size != 0) {
@@ -831,7 +840,7 @@ static void do_physical_memory_save(unsigned int valh, unsigned int vall, @@ -831,7 +840,7 @@ static void do_physical_memory_save(unsigned int valh, unsigned int vall,
831 fclose(f); 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 uint32_t addr; 845 uint32_t addr;
837 uint8_t buf[1]; 846 uint8_t buf[1];
@@ -844,7 +853,7 @@ static void do_sum(uint32_t start, uint32_t size) @@ -844,7 +853,7 @@ static void do_sum(uint32_t start, uint32_t size)
844 sum = (sum >> 1) | (sum << 15); 853 sum = (sum >> 1) | (sum << 15);
845 sum += buf[0]; 854 sum += buf[0];
846 } 855 }
847 - term_printf("%05d\n", sum); 856 + monitor_printf(mon, "%05d\n", sum);
848 } 857 }
849 858
850 typedef struct { 859 typedef struct {
@@ -1027,7 +1036,8 @@ static void release_keys(void *opaque) @@ -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 char keyname_buf[16]; 1042 char keyname_buf[16];
1033 char *separator; 1043 char *separator;
@@ -1046,17 +1056,17 @@ static void do_sendkey(const char *string, int has_hold_time, int hold_time) @@ -1046,17 +1056,17 @@ static void do_sendkey(const char *string, int has_hold_time, int hold_time)
1046 if (keyname_len > 0) { 1056 if (keyname_len > 0) {
1047 pstrcpy(keyname_buf, sizeof(keyname_buf), string); 1057 pstrcpy(keyname_buf, sizeof(keyname_buf), string);
1048 if (keyname_len > sizeof(keyname_buf) - 1) { 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 return; 1060 return;
1051 } 1061 }
1052 if (i == MAX_KEYCODES) { 1062 if (i == MAX_KEYCODES) {
1053 - term_printf("too many keys\n"); 1063 + monitor_printf(mon, "too many keys\n");
1054 return; 1064 return;
1055 } 1065 }
1056 keyname_buf[keyname_len] = 0; 1066 keyname_buf[keyname_len] = 0;
1057 keycode = get_keycode(keyname_buf); 1067 keycode = get_keycode(keyname_buf);
1058 if (keycode < 0) { 1068 if (keycode < 0) {
1059 - term_printf("unknown key: '%s'\n", keyname_buf); 1069 + monitor_printf(mon, "unknown key: '%s'\n", keyname_buf);
1060 return; 1070 return;
1061 } 1071 }
1062 keycodes[i++] = keycode; 1072 keycodes[i++] = keycode;
@@ -1080,7 +1090,7 @@ static void do_sendkey(const char *string, int has_hold_time, int hold_time) @@ -1080,7 +1090,7 @@ static void do_sendkey(const char *string, int has_hold_time, int hold_time)
1080 1090
1081 static int mouse_button_state; 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 const char *dz_str) 1094 const char *dz_str)
1085 { 1095 {
1086 int dx, dy, dz; 1096 int dx, dy, dz;
@@ -1092,13 +1102,14 @@ static void do_mouse_move(const char *dx_str, const char *dy_str, @@ -1092,13 +1102,14 @@ static void do_mouse_move(const char *dx_str, const char *dy_str,
1092 kbd_mouse_event(dx, dy, dz, mouse_button_state); 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 mouse_button_state = button_state; 1107 mouse_button_state = button_state;
1098 kbd_mouse_event(0, 0, 0, mouse_button_state); 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 uint32_t val; 1114 uint32_t val;
1104 int suffix; 1115 int suffix;
@@ -1124,8 +1135,8 @@ static void do_ioport_read(int count, int format, int size, int addr, int has_in @@ -1124,8 +1135,8 @@ static void do_ioport_read(int count, int format, int size, int addr, int has_in
1124 suffix = 'l'; 1135 suffix = 'l';
1125 break; 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 /* boot_set handler */ 1142 /* boot_set handler */
@@ -1138,48 +1149,51 @@ void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque) @@ -1138,48 +1149,51 @@ void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
1138 boot_opaque = opaque; 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 int res; 1154 int res;
1144 1155
1145 if (qemu_boot_set_handler) { 1156 if (qemu_boot_set_handler) {
1146 res = qemu_boot_set_handler(boot_opaque, bootdevice); 1157 res = qemu_boot_set_handler(boot_opaque, bootdevice);
1147 if (res == 0) 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 else 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 } else { 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 qemu_system_reset_request(); 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 qemu_system_powerdown_request(); 1177 qemu_system_powerdown_request();
1164 } 1178 }
1165 1179
1166 #if defined(TARGET_I386) 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 CPUState *env; 1198 CPUState *env;
1185 int l1, l2; 1199 int l1, l2;
@@ -1190,7 +1204,7 @@ static void tlb_info(void) @@ -1190,7 +1204,7 @@ static void tlb_info(void)
1190 return; 1204 return;
1191 1205
1192 if (!(env->cr[0] & CR0_PG_MASK)) { 1206 if (!(env->cr[0] & CR0_PG_MASK)) {
1193 - term_printf("PG disabled\n"); 1207 + monitor_printf(mon, "PG disabled\n");
1194 return; 1208 return;
1195 } 1209 }
1196 pgd = env->cr[3] & ~0xfff; 1210 pgd = env->cr[3] & ~0xfff;
@@ -1199,14 +1213,14 @@ static void tlb_info(void) @@ -1199,14 +1213,14 @@ static void tlb_info(void)
1199 pde = le32_to_cpu(pde); 1213 pde = le32_to_cpu(pde);
1200 if (pde & PG_PRESENT_MASK) { 1214 if (pde & PG_PRESENT_MASK) {
1201 if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { 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 } else { 1217 } else {
1204 for(l2 = 0; l2 < 1024; l2++) { 1218 for(l2 = 0; l2 < 1024; l2++) {
1205 cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, 1219 cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
1206 (uint8_t *)&pte, 4); 1220 (uint8_t *)&pte, 4);
1207 pte = le32_to_cpu(pte); 1221 pte = le32_to_cpu(pte);
1208 if (pte & PG_PRESENT_MASK) { 1222 if (pte & PG_PRESENT_MASK) {
1209 - print_pte((l1 << 22) + (l2 << 12), 1223 + print_pte(mon, (l1 << 22) + (l2 << 12),
1210 pte & ~PG_PSE_MASK, 1224 pte & ~PG_PSE_MASK,
1211 ~0xfff); 1225 ~0xfff);
1212 } 1226 }
@@ -1216,18 +1230,18 @@ static void tlb_info(void) @@ -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 uint32_t end, int prot) 1234 uint32_t end, int prot)
1221 { 1235 {
1222 int prot1; 1236 int prot1;
1223 prot1 = *plast_prot; 1237 prot1 = *plast_prot;
1224 if (prot != prot1) { 1238 if (prot != prot1) {
1225 if (*pstart != -1) { 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 if (prot != 0) 1246 if (prot != 0)
1233 *pstart = end; 1247 *pstart = end;
@@ -1237,7 +1251,7 @@ static void mem_print(uint32_t *pstart, int *plast_prot, @@ -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 CPUState *env; 1256 CPUState *env;
1243 int l1, l2, prot, last_prot; 1257 int l1, l2, prot, last_prot;
@@ -1248,7 +1262,7 @@ static void mem_info(void) @@ -1248,7 +1262,7 @@ static void mem_info(void)
1248 return; 1262 return;
1249 1263
1250 if (!(env->cr[0] & CR0_PG_MASK)) { 1264 if (!(env->cr[0] & CR0_PG_MASK)) {
1251 - term_printf("PG disabled\n"); 1265 + monitor_printf(mon, "PG disabled\n");
1252 return; 1266 return;
1253 } 1267 }
1254 pgd = env->cr[3] & ~0xfff; 1268 pgd = env->cr[3] & ~0xfff;
@@ -1261,7 +1275,7 @@ static void mem_info(void) @@ -1261,7 +1275,7 @@ static void mem_info(void)
1261 if (pde & PG_PRESENT_MASK) { 1275 if (pde & PG_PRESENT_MASK) {
1262 if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { 1276 if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
1263 prot = pde & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK); 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 } else { 1279 } else {
1266 for(l2 = 0; l2 < 1024; l2++) { 1280 for(l2 = 0; l2 < 1024; l2++) {
1267 cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, 1281 cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
@@ -1273,12 +1287,12 @@ static void mem_info(void) @@ -1273,12 +1287,12 @@ static void mem_info(void)
1273 } else { 1287 } else {
1274 prot = 0; 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 } else { 1293 } else {
1280 prot = 0; 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,34 +1300,34 @@ static void mem_info(void)
1286 1300
1287 #if defined(TARGET_SH4) 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 CPUState *env = mon_get_cpu(); 1317 CPUState *env = mon_get_cpu();
1304 int i; 1318 int i;
1305 1319
1306 - term_printf ("ITLB:\n"); 1320 + monitor_printf (mon, "ITLB:\n");
1307 for (i = 0 ; i < ITLB_SIZE ; i++) 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 for (i = 0 ; i < UTLB_SIZE ; i++) 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 #endif 1328 #endif
1315 1329
1316 -static void do_info_kqemu(void) 1330 +static void do_info_kqemu(Monitor *mon)
1317 { 1331 {
1318 #ifdef USE_KQEMU 1332 #ifdef USE_KQEMU
1319 CPUState *env; 1333 CPUState *env;
@@ -1321,38 +1335,38 @@ static void do_info_kqemu(void) @@ -1321,38 +1335,38 @@ static void do_info_kqemu(void)
1321 val = 0; 1335 val = 0;
1322 env = mon_get_cpu(); 1336 env = mon_get_cpu();
1323 if (!env) { 1337 if (!env) {
1324 - term_printf("No cpu initialized yet"); 1338 + monitor_printf(mon, "No cpu initialized yet");
1325 return; 1339 return;
1326 } 1340 }
1327 val = env->kqemu_enabled; 1341 val = env->kqemu_enabled;
1328 - term_printf("kqemu support: "); 1342 + monitor_printf(mon, "kqemu support: ");
1329 switch(val) { 1343 switch(val) {
1330 default: 1344 default:
1331 case 0: 1345 case 0:
1332 - term_printf("disabled\n"); 1346 + monitor_printf(mon, "disabled\n");
1333 break; 1347 break;
1334 case 1: 1348 case 1:
1335 - term_printf("enabled for user code\n"); 1349 + monitor_printf(mon, "enabled for user code\n");
1336 break; 1350 break;
1337 case 2: 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 break; 1353 break;
1340 } 1354 }
1341 #else 1355 #else
1342 - term_printf("kqemu support: not compiled\n"); 1356 + monitor_printf(mon, "kqemu support: not compiled\n");
1343 #endif 1357 #endif
1344 } 1358 }
1345 1359
1346 -static void do_info_kvm(void) 1360 +static void do_info_kvm(Monitor *mon)
1347 { 1361 {
1348 #ifdef CONFIG_KVM 1362 #ifdef CONFIG_KVM
1349 - term_printf("kvm support: "); 1363 + monitor_printf(mon, "kvm support: ");
1350 if (kvm_enabled()) 1364 if (kvm_enabled())
1351 - term_printf("enabled\n"); 1365 + monitor_printf(mon, "enabled\n");
1352 else 1366 else
1353 - term_printf("disabled\n"); 1367 + monitor_printf(mon, "disabled\n");
1354 #else 1368 #else
1355 - term_printf("kvm support: not compiled\n"); 1369 + monitor_printf(mon, "kvm support: not compiled\n");
1356 #endif 1370 #endif
1357 } 1371 }
1358 1372
@@ -1366,23 +1380,25 @@ int64_t kqemu_ret_int_count; @@ -1366,23 +1380,25 @@ int64_t kqemu_ret_int_count;
1366 int64_t kqemu_ret_excp_count; 1380 int64_t kqemu_ret_excp_count;
1367 int64_t kqemu_ret_intr_count; 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 int64_t total; 1385 int64_t total;
1372 total = qemu_time; 1386 total = qemu_time;
1373 if (total == 0) 1387 if (total == 0)
1374 total = 1; 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 qemu_time = 0; 1402 qemu_time = 0;
1387 kqemu_time = 0; 1403 kqemu_time = 0;
1388 kqemu_exec_count = 0; 1404 kqemu_exec_count = 0;
@@ -1395,27 +1411,27 @@ static void do_info_profile(void) @@ -1395,27 +1411,27 @@ static void do_info_profile(void)
1395 #endif 1411 #endif
1396 } 1412 }
1397 #else 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 #endif 1418 #endif
1403 1419
1404 /* Capture support */ 1420 /* Capture support */
1405 static LIST_HEAD (capture_list_head, CaptureState) capture_head; 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 int i; 1425 int i;
1410 CaptureState *s; 1426 CaptureState *s;
1411 1427
1412 for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) { 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 s->ops.info (s->opaque); 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 int i; 1436 int i;
1421 CaptureState *s; 1437 CaptureState *s;
@@ -1431,10 +1447,10 @@ static void do_stop_capture (int n) @@ -1431,10 +1447,10 @@ static void do_stop_capture (int n)
1431 } 1447 }
1432 1448
1433 #ifdef HAS_AUDIO 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 CaptureState *s; 1455 CaptureState *s;
1440 1456
@@ -1445,7 +1461,7 @@ static void do_wav_capture (const char *path, @@ -1445,7 +1461,7 @@ static void do_wav_capture (const char *path,
1445 nchannels = has_channels ? nchannels : 2; 1461 nchannels = has_channels ? nchannels : 2;
1446 1462
1447 if (wav_start_capture (s, path, freq, bits, nchannels)) { 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 qemu_free (s); 1465 qemu_free (s);
1450 } 1466 }
1451 LIST_INSERT_HEAD (&capture_head, s, entries); 1467 LIST_INSERT_HEAD (&capture_head, s, entries);
@@ -1453,7 +1469,7 @@ static void do_wav_capture (const char *path, @@ -1453,7 +1469,7 @@ static void do_wav_capture (const char *path,
1453 #endif 1469 #endif
1454 1470
1455 #if defined(TARGET_I386) 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 CPUState *env; 1474 CPUState *env;
1459 1475
@@ -1465,37 +1481,38 @@ static void do_inject_nmi(int cpu_index) @@ -1465,37 +1481,38 @@ static void do_inject_nmi(int cpu_index)
1465 } 1481 }
1466 #endif 1482 #endif
1467 1483
1468 -static void do_info_status(void) 1484 +static void do_info_status(Monitor *mon)
1469 { 1485 {
1470 if (vm_running) 1486 if (vm_running)
1471 - term_printf("VM status: running\n"); 1487 + monitor_printf(mon, "VM status: running\n");
1472 else 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 ram_addr_t target = value; 1495 ram_addr_t target = value;
1480 qemu_balloon(target << 20); 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 ram_addr_t actual; 1501 ram_addr_t actual;
1486 1502
1487 actual = qemu_balloon_status(); 1503 actual = qemu_balloon_status();
1488 if (kvm_enabled() && !kvm_has_sync_mmu()) 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 else if (actual == 0) 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 else 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 /* Please update qemu-doc.texi when adding or changing commands */ 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 "[cmd]", "show the help" }, 1516 "[cmd]", "show the help" },
1500 { "commit", "s", do_commit, 1517 { "commit", "s", do_commit,
1501 "device|all", "commit changes to the disk images (if -snapshot is used) or backing files" }, 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,16 +1618,16 @@ static const term_cmd_t term_cmds[] = {
1601 }; 1618 };
1602 1619
1603 /* Please update qemu-doc.texi when adding or changing commands */ 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 { "version", "", do_info_version, 1622 { "version", "", do_info_version,
1606 "", "show the version of QEMU" }, 1623 "", "show the version of QEMU" },
1607 { "network", "", do_info_network, 1624 { "network", "", do_info_network,
1608 "", "show the network state" }, 1625 "", "show the network state" },
1609 { "chardev", "", qemu_chr_info, 1626 { "chardev", "", qemu_chr_info,
1610 "", "show the character devices" }, 1627 "", "show the character devices" },
1611 - { "block", "", do_info_block, 1628 + { "block", "", bdrv_info,
1612 "", "show the block devices" }, 1629 "", "show the block devices" },
1613 - { "blockstats", "", do_info_blockstats, 1630 + { "blockstats", "", bdrv_info_stats,
1614 "", "show block device statistics" }, 1631 "", "show block device statistics" },
1615 { "registers", "", do_info_registers, 1632 { "registers", "", do_info_registers,
1616 "", "show the cpu registers" }, 1633 "", "show the cpu registers" },
@@ -2020,9 +2037,9 @@ static const MonitorDef monitor_defs[] = { @@ -2020,9 +2037,9 @@ static const MonitorDef monitor_defs[] = {
2020 { NULL }, 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 longjmp(expr_env, 1); 2043 longjmp(expr_env, 1);
2027 } 2044 }
2028 2045
@@ -2068,9 +2085,9 @@ static void next(void) @@ -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 int64_t n; 2092 int64_t n;
2076 char *p; 2093 char *p;
@@ -2079,32 +2096,32 @@ static int64_t expr_unary(void) @@ -2079,32 +2096,32 @@ static int64_t expr_unary(void)
2079 switch(*pch) { 2096 switch(*pch) {
2080 case '+': 2097 case '+':
2081 next(); 2098 next();
2082 - n = expr_unary(); 2099 + n = expr_unary(mon);
2083 break; 2100 break;
2084 case '-': 2101 case '-':
2085 next(); 2102 next();
2086 - n = -expr_unary(); 2103 + n = -expr_unary(mon);
2087 break; 2104 break;
2088 case '~': 2105 case '~':
2089 next(); 2106 next();
2090 - n = ~expr_unary(); 2107 + n = ~expr_unary(mon);
2091 break; 2108 break;
2092 case '(': 2109 case '(':
2093 next(); 2110 next();
2094 - n = expr_sum(); 2111 + n = expr_sum(mon);
2095 if (*pch != ')') { 2112 if (*pch != ')') {
2096 - expr_error("')' expected"); 2113 + expr_error(mon, "')' expected");
2097 } 2114 }
2098 next(); 2115 next();
2099 break; 2116 break;
2100 case '\'': 2117 case '\'':
2101 pch++; 2118 pch++;
2102 if (*pch == '\0') 2119 if (*pch == '\0')
2103 - expr_error("character constant expected"); 2120 + expr_error(mon, "character constant expected");
2104 n = *pch; 2121 n = *pch;
2105 pch++; 2122 pch++;
2106 if (*pch != '\'') 2123 if (*pch != '\'')
2107 - expr_error("missing terminating \' character"); 2124 + expr_error(mon, "missing terminating \' character");
2108 next(); 2125 next();
2109 break; 2126 break;
2110 case '$': 2127 case '$':
@@ -2127,14 +2144,14 @@ static int64_t expr_unary(void) @@ -2127,14 +2144,14 @@ static int64_t expr_unary(void)
2127 *q = 0; 2144 *q = 0;
2128 ret = get_monitor_def(&reg, buf); 2145 ret = get_monitor_def(&reg, buf);
2129 if (ret == -1) 2146 if (ret == -1)
2130 - expr_error("unknown register"); 2147 + expr_error(mon, "unknown register");
2131 else if (ret == -2) 2148 else if (ret == -2)
2132 - expr_error("no cpu defined"); 2149 + expr_error(mon, "no cpu defined");
2133 n = reg; 2150 n = reg;
2134 } 2151 }
2135 break; 2152 break;
2136 case '\0': 2153 case '\0':
2137 - expr_error("unexpected end of expression"); 2154 + expr_error(mon, "unexpected end of expression");
2138 n = 0; 2155 n = 0;
2139 break; 2156 break;
2140 default: 2157 default:
@@ -2144,7 +2161,7 @@ static int64_t expr_unary(void) @@ -2144,7 +2161,7 @@ static int64_t expr_unary(void)
2144 n = strtoul(pch, &p, 0); 2161 n = strtoul(pch, &p, 0);
2145 #endif 2162 #endif
2146 if (pch == p) { 2163 if (pch == p) {
2147 - expr_error("invalid char in expression"); 2164 + expr_error(mon, "invalid char in expression");
2148 } 2165 }
2149 pch = p; 2166 pch = p;
2150 while (qemu_isspace(*pch)) 2167 while (qemu_isspace(*pch))
@@ -2155,18 +2172,18 @@ static int64_t expr_unary(void) @@ -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 int64_t val, val2; 2177 int64_t val, val2;
2161 int op; 2178 int op;
2162 2179
2163 - val = expr_unary(); 2180 + val = expr_unary(mon);
2164 for(;;) { 2181 for(;;) {
2165 op = *pch; 2182 op = *pch;
2166 if (op != '*' && op != '/' && op != '%') 2183 if (op != '*' && op != '/' && op != '%')
2167 break; 2184 break;
2168 next(); 2185 next();
2169 - val2 = expr_unary(); 2186 + val2 = expr_unary(mon);
2170 switch(op) { 2187 switch(op) {
2171 default: 2188 default:
2172 case '*': 2189 case '*':
@@ -2175,7 +2192,7 @@ static int64_t expr_prod(void) @@ -2175,7 +2192,7 @@ static int64_t expr_prod(void)
2175 case '/': 2192 case '/':
2176 case '%': 2193 case '%':
2177 if (val2 == 0) 2194 if (val2 == 0)
2178 - expr_error("division by zero"); 2195 + expr_error(mon, "division by zero");
2179 if (op == '/') 2196 if (op == '/')
2180 val /= val2; 2197 val /= val2;
2181 else 2198 else
@@ -2186,18 +2203,18 @@ static int64_t expr_prod(void) @@ -2186,18 +2203,18 @@ static int64_t expr_prod(void)
2186 return val; 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 int64_t val, val2; 2208 int64_t val, val2;
2192 int op; 2209 int op;
2193 2210
2194 - val = expr_prod(); 2211 + val = expr_prod(mon);
2195 for(;;) { 2212 for(;;) {
2196 op = *pch; 2213 op = *pch;
2197 if (op != '&' && op != '|' && op != '^') 2214 if (op != '&' && op != '|' && op != '^')
2198 break; 2215 break;
2199 next(); 2216 next();
2200 - val2 = expr_prod(); 2217 + val2 = expr_prod(mon);
2201 switch(op) { 2218 switch(op) {
2202 default: 2219 default:
2203 case '&': 2220 case '&':
@@ -2214,18 +2231,18 @@ static int64_t expr_logic(void) @@ -2214,18 +2231,18 @@ static int64_t expr_logic(void)
2214 return val; 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 int64_t val, val2; 2236 int64_t val, val2;
2220 int op; 2237 int op;
2221 2238
2222 - val = expr_logic(); 2239 + val = expr_logic(mon);
2223 for(;;) { 2240 for(;;) {
2224 op = *pch; 2241 op = *pch;
2225 if (op != '+' && op != '-') 2242 if (op != '+' && op != '-')
2226 break; 2243 break;
2227 next(); 2244 next();
2228 - val2 = expr_logic(); 2245 + val2 = expr_logic(mon);
2229 if (op == '+') 2246 if (op == '+')
2230 val += val2; 2247 val += val2;
2231 else 2248 else
@@ -2234,7 +2251,7 @@ static int64_t expr_sum(void) @@ -2234,7 +2251,7 @@ static int64_t expr_sum(void)
2234 return val; 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 pch = *pp; 2256 pch = *pp;
2240 if (setjmp(expr_env)) { 2257 if (setjmp(expr_env)) {
@@ -2243,7 +2260,7 @@ static int get_expr(int64_t *pval, const char **pp) @@ -2243,7 +2260,7 @@ static int get_expr(int64_t *pval, const char **pp)
2243 } 2260 }
2244 while (qemu_isspace(*pch)) 2261 while (qemu_isspace(*pch))
2245 pch++; 2262 pch++;
2246 - *pval = expr_sum(); 2263 + *pval = expr_sum(mon);
2247 *pp = pch; 2264 *pp = pch;
2248 return 0; 2265 return 0;
2249 } 2266 }
@@ -2318,30 +2335,31 @@ static int default_fmt_size = 4; @@ -2318,30 +2335,31 @@ static int default_fmt_size = 4;
2318 2335
2319 #define MAX_ARGS 16 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 const char *p, *pstart, *typestr; 2340 const char *p, *pstart, *typestr;
2324 char *q; 2341 char *q;
2325 int c, nb_args, len, i, has_arg; 2342 int c, nb_args, len, i, has_arg;
2326 - const term_cmd_t *cmd; 2343 + const mon_cmd_t *cmd;
2327 char cmdname[256]; 2344 char cmdname[256];
2328 char buf[1024]; 2345 char buf[1024];
2329 void *str_allocated[MAX_ARGS]; 2346 void *str_allocated[MAX_ARGS];
2330 void *args[MAX_ARGS]; 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 #ifdef DEBUG 2361 #ifdef DEBUG
2344 - term_printf("command='%s'\n", cmdline); 2362 + monitor_printf(mon, "command='%s'\n", cmdline);
2345 #endif 2363 #endif
2346 2364
2347 /* extract the command name */ 2365 /* extract the command name */
@@ -2361,11 +2379,11 @@ static void monitor_handle_command(const char *cmdline) @@ -2361,11 +2379,11 @@ static void monitor_handle_command(const char *cmdline)
2361 cmdname[len] = '\0'; 2379 cmdname[len] = '\0';
2362 2380
2363 /* find the command */ 2381 /* find the command */
2364 - for(cmd = term_cmds; cmd->name != NULL; cmd++) { 2382 + for(cmd = mon_cmds; cmd->name != NULL; cmd++) {
2365 if (compare_cmd(cmdname, cmd->name)) 2383 if (compare_cmd(cmdname, cmd->name))
2366 goto found; 2384 goto found;
2367 } 2385 }
2368 - term_printf("unknown command: '%s'\n", cmdname); 2386 + monitor_printf(mon, "unknown command: '%s'\n", cmdname);
2369 return; 2387 return;
2370 found: 2388 found:
2371 2389
@@ -2402,13 +2420,15 @@ static void monitor_handle_command(const char *cmdline) @@ -2402,13 +2420,15 @@ static void monitor_handle_command(const char *cmdline)
2402 if (ret < 0) { 2420 if (ret < 0) {
2403 switch(c) { 2421 switch(c) {
2404 case 'F': 2422 case 'F':
2405 - term_printf("%s: filename expected\n", cmdname); 2423 + monitor_printf(mon, "%s: filename expected\n",
  2424 + cmdname);
2406 break; 2425 break;
2407 case 'B': 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 break; 2429 break;
2410 default: 2430 default:
2411 - term_printf("%s: string expected\n", cmdname); 2431 + monitor_printf(mon, "%s: string expected\n", cmdname);
2412 break; 2432 break;
2413 } 2433 }
2414 goto fail; 2434 goto fail;
@@ -2419,7 +2439,7 @@ static void monitor_handle_command(const char *cmdline) @@ -2419,7 +2439,7 @@ static void monitor_handle_command(const char *cmdline)
2419 add_str: 2439 add_str:
2420 if (nb_args >= MAX_ARGS) { 2440 if (nb_args >= MAX_ARGS) {
2421 error_args: 2441 error_args:
2422 - term_printf("%s: too many arguments\n", cmdname); 2442 + monitor_printf(mon, "%s: too many arguments\n", cmdname);
2423 goto fail; 2443 goto fail;
2424 } 2444 }
2425 args[nb_args++] = str; 2445 args[nb_args++] = str;
@@ -2477,7 +2497,8 @@ static void monitor_handle_command(const char *cmdline) @@ -2477,7 +2497,8 @@ static void monitor_handle_command(const char *cmdline)
2477 } 2497 }
2478 next: 2498 next:
2479 if (*p != '\0' && !qemu_isspace(*p)) { 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 goto fail; 2502 goto fail;
2482 } 2503 }
2483 if (format < 0) 2504 if (format < 0)
@@ -2539,7 +2560,7 @@ static void monitor_handle_command(const char *cmdline) @@ -2539,7 +2560,7 @@ static void monitor_handle_command(const char *cmdline)
2539 goto add_num; 2560 goto add_num;
2540 } 2561 }
2541 } 2562 }
2542 - if (get_expr(&val, &p)) 2563 + if (get_expr(mon, &val, &p))
2543 goto fail; 2564 goto fail;
2544 add_num: 2565 add_num:
2545 if (c == 'i') { 2566 if (c == 'i') {
@@ -2572,8 +2593,8 @@ static void monitor_handle_command(const char *cmdline) @@ -2572,8 +2593,8 @@ static void monitor_handle_command(const char *cmdline)
2572 if (*p == '-') { 2593 if (*p == '-') {
2573 p++; 2594 p++;
2574 if (*p != c) { 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 goto fail; 2598 goto fail;
2578 } 2599 }
2579 p++; 2600 p++;
@@ -2586,7 +2607,7 @@ static void monitor_handle_command(const char *cmdline) @@ -2586,7 +2607,7 @@ static void monitor_handle_command(const char *cmdline)
2586 break; 2607 break;
2587 default: 2608 default:
2588 bad_type: 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 goto fail; 2611 goto fail;
2591 } 2612 }
2592 } 2613 }
@@ -2594,46 +2615,47 @@ static void monitor_handle_command(const char *cmdline) @@ -2594,46 +2615,47 @@ static void monitor_handle_command(const char *cmdline)
2594 while (qemu_isspace(*p)) 2615 while (qemu_isspace(*p))
2595 p++; 2616 p++;
2596 if (*p != '\0') { 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 goto fail; 2620 goto fail;
2600 } 2621 }
2601 2622
2602 switch(nb_args) { 2623 switch(nb_args) {
2603 case 0: 2624 case 0:
2604 handler_0 = cmd->handler; 2625 handler_0 = cmd->handler;
2605 - handler_0(); 2626 + handler_0(mon);
2606 break; 2627 break;
2607 case 1: 2628 case 1:
2608 handler_1 = cmd->handler; 2629 handler_1 = cmd->handler;
2609 - handler_1(args[0]); 2630 + handler_1(mon, args[0]);
2610 break; 2631 break;
2611 case 2: 2632 case 2:
2612 handler_2 = cmd->handler; 2633 handler_2 = cmd->handler;
2613 - handler_2(args[0], args[1]); 2634 + handler_2(mon, args[0], args[1]);
2614 break; 2635 break;
2615 case 3: 2636 case 3:
2616 handler_3 = cmd->handler; 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 break; 2639 break;
2619 case 4: 2640 case 4:
2620 handler_4 = cmd->handler; 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 break; 2643 break;
2623 case 5: 2644 case 5:
2624 handler_5 = cmd->handler; 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 break; 2647 break;
2627 case 6: 2648 case 6:
2628 handler_6 = cmd->handler; 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 break; 2651 break;
2631 case 7: 2652 case 7:
2632 handler_7 = cmd->handler; 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 break; 2656 break;
2635 default: 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 goto fail; 2659 goto fail;
2638 } 2660 }
2639 fail: 2661 fail:
@@ -2660,7 +2682,7 @@ static void cmd_completion(const char *name, const char *list) @@ -2660,7 +2682,7 @@ static void cmd_completion(const char *name, const char *list)
2660 memcpy(cmd, pstart, len); 2682 memcpy(cmd, pstart, len);
2661 cmd[len] = '\0'; 2683 cmd[len] = '\0';
2662 if (name[0] == '\0' || !strncmp(name, cmd, strlen(name))) { 2684 if (name[0] == '\0' || !strncmp(name, cmd, strlen(name))) {
2663 - add_completion(cmd); 2685 + readline_add_completion(cmd);
2664 } 2686 }
2665 if (*p == '\0') 2687 if (*p == '\0')
2666 break; 2688 break;
@@ -2691,7 +2713,8 @@ static void file_completion(const char *input) @@ -2691,7 +2713,8 @@ static void file_completion(const char *input)
2691 pstrcpy(file_prefix, sizeof(file_prefix), p + 1); 2713 pstrcpy(file_prefix, sizeof(file_prefix), p + 1);
2692 } 2714 }
2693 #ifdef DEBUG_COMPLETION 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 #endif 2718 #endif
2696 ffs = opendir(path); 2719 ffs = opendir(path);
2697 if (!ffs) 2720 if (!ffs)
@@ -2712,7 +2735,7 @@ static void file_completion(const char *input) @@ -2712,7 +2735,7 @@ static void file_completion(const char *input)
2712 stat(file, &sb); 2735 stat(file, &sb);
2713 if(S_ISDIR(sb.st_mode)) 2736 if(S_ISDIR(sb.st_mode))
2714 pstrcat(file, sizeof(file), "/"); 2737 pstrcat(file, sizeof(file), "/");
2715 - add_completion(file); 2738 + readline_add_completion(file);
2716 } 2739 }
2717 } 2740 }
2718 closedir(ffs); 2741 closedir(ffs);
@@ -2725,7 +2748,7 @@ static void block_completion_it(void *opaque, BlockDriverState *bs) @@ -2725,7 +2748,7 @@ static void block_completion_it(void *opaque, BlockDriverState *bs)
2725 2748
2726 if (input[0] == '\0' || 2749 if (input[0] == '\0' ||
2727 !strncmp(name, (char *)input, strlen(input))) { 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,13 +2784,13 @@ void readline_find_completion(const char *cmdline)
2761 char *args[MAX_ARGS]; 2784 char *args[MAX_ARGS];
2762 int nb_args, i, len; 2785 int nb_args, i, len;
2763 const char *ptype, *str; 2786 const char *ptype, *str;
2764 - const term_cmd_t *cmd; 2787 + const mon_cmd_t *cmd;
2765 const KeyDef *key; 2788 const KeyDef *key;
2766 2789
2767 parse_cmdline(cmdline, &nb_args, args); 2790 parse_cmdline(cmdline, &nb_args, args);
2768 #ifdef DEBUG_COMPLETION 2791 #ifdef DEBUG_COMPLETION
2769 for(i = 0; i < nb_args; i++) { 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 #endif 2795 #endif
2773 2796
@@ -2785,13 +2808,13 @@ void readline_find_completion(const char *cmdline) @@ -2785,13 +2808,13 @@ void readline_find_completion(const char *cmdline)
2785 cmdname = ""; 2808 cmdname = "";
2786 else 2809 else
2787 cmdname = args[0]; 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 cmd_completion(cmdname, cmd->name); 2813 cmd_completion(cmdname, cmd->name);
2791 } 2814 }
2792 } else { 2815 } else {
2793 /* find the command */ 2816 /* find the command */
2794 - for(cmd = term_cmds; cmd->name != NULL; cmd++) { 2817 + for(cmd = mon_cmds; cmd->name != NULL; cmd++) {
2795 if (compare_cmd(args[0], cmd->name)) 2818 if (compare_cmd(args[0], cmd->name))
2796 goto found; 2819 goto found;
2797 } 2820 }
@@ -2809,23 +2832,23 @@ void readline_find_completion(const char *cmdline) @@ -2809,23 +2832,23 @@ void readline_find_completion(const char *cmdline)
2809 switch(*ptype) { 2832 switch(*ptype) {
2810 case 'F': 2833 case 'F':
2811 /* file completion */ 2834 /* file completion */
2812 - completion_index = strlen(str); 2835 + readline_set_completion_index(strlen(str));
2813 file_completion(str); 2836 file_completion(str);
2814 break; 2837 break;
2815 case 'B': 2838 case 'B':
2816 /* block device name completion */ 2839 /* block device name completion */
2817 - completion_index = strlen(str); 2840 + readline_set_completion_index(strlen(str));
2818 bdrv_iterate(block_completion_it, (void *)str); 2841 bdrv_iterate(block_completion_it, (void *)str);
2819 break; 2842 break;
2820 case 's': 2843 case 's':
2821 /* XXX: more generic ? */ 2844 /* XXX: more generic ? */
2822 if (!strcmp(cmd->name, "info")) { 2845 if (!strcmp(cmd->name, "info")) {
2823 - completion_index = strlen(str); 2846 + readline_set_completion_index(strlen(str));
2824 for(cmd = info_cmds; cmd->name != NULL; cmd++) { 2847 for(cmd = info_cmds; cmd->name != NULL; cmd++) {
2825 cmd_completion(str, cmd->name); 2848 cmd_completion(str, cmd->name);
2826 } 2849 }
2827 } else if (!strcmp(cmd->name, "sendkey")) { 2850 } else if (!strcmp(cmd->name, "sendkey")) {
2828 - completion_index = strlen(str); 2851 + readline_set_completion_index(strlen(str));
2829 for(key = key_defs; key->name != NULL; key++) { 2852 for(key = key_defs; key->name != NULL; key++) {
2830 cmd_completion(str, key->name); 2853 cmd_completion(str, key->name);
2831 } 2854 }
@@ -2847,27 +2870,28 @@ static int term_can_read(void *opaque) @@ -2847,27 +2870,28 @@ static int term_can_read(void *opaque)
2847 static void term_read(void *opaque, const uint8_t *buf, int size) 2870 static void term_read(void *opaque, const uint8_t *buf, int size)
2848 { 2871 {
2849 int i; 2872 int i;
2850 - for(i = 0; i < size; i++) 2873 +
  2874 + for (i = 0; i < size; i++)
2851 readline_handle_byte(buf[i]); 2875 readline_handle_byte(buf[i]);
2852 } 2876 }
2853 2877
2854 static int monitor_suspended; 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 if (!monitor_suspended) 2883 if (!monitor_suspended)
2860 readline_show_prompt(); 2884 readline_show_prompt();
2861 else 2885 else
2862 monitor_suspended = 2; 2886 monitor_suspended = 2;
2863 } 2887 }
2864 2888
2865 -void monitor_suspend(void) 2889 +void monitor_suspend(Monitor *mon)
2866 { 2890 {
2867 monitor_suspended = 1; 2891 monitor_suspended = 1;
2868 } 2892 }
2869 2893
2870 -void monitor_resume(void) 2894 +void monitor_resume(Monitor *mon)
2871 { 2895 {
2872 if (monitor_suspended == 2) 2896 if (monitor_suspended == 2)
2873 monitor_start_input(); 2897 monitor_start_input();
@@ -2876,24 +2900,26 @@ void monitor_resume(void) @@ -2876,24 +2900,26 @@ void monitor_resume(void)
2876 2900
2877 static void monitor_start_input(void) 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 readline_show_prompt(); 2904 readline_show_prompt();
2881 } 2905 }
2882 2906
2883 static void term_event(void *opaque, int event) 2907 static void term_event(void *opaque, int event)
2884 { 2908 {
  2909 + Monitor *mon = opaque;
  2910 +
2885 if (event != CHR_EVENT_RESET) 2911 if (event != CHR_EVENT_RESET)
2886 return; 2912 return;
2887 2913
2888 if (!hide_banner) 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 monitor_start_input(); 2917 monitor_start_input();
2892 } 2918 }
2893 2919
2894 static int is_first_init = 1; 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 int i; 2924 int i;
2899 2925
@@ -2908,25 +2934,25 @@ void monitor_init(CharDriverState *hd, int show_banner) @@ -2908,25 +2934,25 @@ void monitor_init(CharDriverState *hd, int show_banner)
2908 } 2934 }
2909 for (i = 0; i < MAX_MON; i++) { 2935 for (i = 0; i < MAX_MON; i++) {
2910 if (monitor_hd[i] == NULL) { 2936 if (monitor_hd[i] == NULL) {
2911 - monitor_hd[i] = hd; 2937 + monitor_hd[i] = chr;
2912 break; 2938 break;
2913 } 2939 }
2914 } 2940 }
2915 2941
2916 hide_banner = !show_banner; 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 BlockDriverState *bs = opaque; 2951 BlockDriverState *bs = opaque;
2926 int ret = 0; 2952 int ret = 0;
2927 2953
2928 if (bdrv_set_key(bs, password) != 0) { 2954 if (bdrv_set_key(bs, password) != 0) {
2929 - term_printf("invalid password\n"); 2955 + monitor_printf(mon, "invalid password\n");
2930 ret = -EPERM; 2956 ret = -EPERM;
2931 } 2957 }
2932 if (password_completion_cb) 2958 if (password_completion_cb)
@@ -2935,7 +2961,7 @@ static void bdrv_password_cb(void *opaque, const char *password) @@ -2935,7 +2961,7 @@ static void bdrv_password_cb(void *opaque, const char *password)
2935 monitor_start_input(); 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 BlockDriverCompletionFunc *completion_cb, 2965 BlockDriverCompletionFunc *completion_cb,
2940 void *opaque) 2966 void *opaque)
2941 { 2967 {
@@ -2945,11 +2971,11 @@ void monitor_read_bdrv_key_start(BlockDriverState *bs, @@ -2945,11 +2971,11 @@ void monitor_read_bdrv_key_start(BlockDriverState *bs,
2945 return; 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 password_completion_cb = completion_cb; 2977 password_completion_cb = completion_cb;
2952 password_opaque = opaque; 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,7 +23,7 @@
23 */ 23 */
24 #include "qemu-common.h" 24 #include "qemu-common.h"
25 #include "net.h" 25 #include "net.h"
26 -#include "console.h" 26 +#include "monitor.h"
27 #include "sysemu.h" 27 #include "sysemu.h"
28 #include "qemu-timer.h" 28 #include "qemu-timer.h"
29 #include "qemu-char.h" 29 #include "qemu-char.h"
@@ -665,7 +665,7 @@ void net_slirp_smb(const char *exported_dir) @@ -665,7 +665,7 @@ void net_slirp_smb(const char *exported_dir)
665 } 665 }
666 666
667 #endif /* !defined(_WIN32) */ 667 #endif /* !defined(_WIN32) */
668 -void do_info_slirp(void) 668 +void do_info_slirp(Monitor *mon)
669 { 669 {
670 slirp_stats(); 670 slirp_stats();
671 } 671 }
@@ -1804,28 +1804,28 @@ static int net_host_check_device(const char *device) @@ -1804,28 +1804,28 @@ static int net_host_check_device(const char *device)
1804 return 0; 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 if (!net_host_check_device(device)) { 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 return; 1811 return;
1812 } 1812 }
1813 net_client_init(device, opts); 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 VLANState *vlan; 1818 VLANState *vlan;
1819 VLANClientState *vc; 1819 VLANClientState *vc;
1820 1820
1821 if (!net_host_check_device(device)) { 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 return; 1823 return;
1824 } 1824 }
1825 1825
1826 vlan = qemu_find_vlan(vlan_id); 1826 vlan = qemu_find_vlan(vlan_id);
1827 if (!vlan) { 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 return; 1829 return;
1830 } 1830 }
1831 1831
@@ -1834,7 +1834,7 @@ void net_host_device_remove(int vlan_id, const char *device) @@ -1834,7 +1834,7 @@ void net_host_device_remove(int vlan_id, const char *device)
1834 break; 1834 break;
1835 1835
1836 if (!vc) { 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 return; 1838 return;
1839 } 1839 }
1840 qemu_del_vlan_client(vc); 1840 qemu_del_vlan_client(vc);
@@ -1860,19 +1860,19 @@ int net_client_parse(const char *str) @@ -1860,19 +1860,19 @@ int net_client_parse(const char *str)
1860 return net_client_init(device, p); 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 VLANState *vlan; 1865 VLANState *vlan;
1866 VLANClientState *vc; 1866 VLANClientState *vc;
1867 1867
1868 for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) { 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 for(vc = vlan->first_client; vc != NULL; vc = vc->next) 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 VLANState *vlan; 1877 VLANState *vlan;
1878 VLANClientState *vc = NULL; 1878 VLANClientState *vc = NULL;
@@ -1884,7 +1884,7 @@ int do_set_link(const char *name, const char *up_or_down) @@ -1884,7 +1884,7 @@ int do_set_link(const char *name, const char *up_or_down)
1884 done: 1884 done:
1885 1885
1886 if (!vc) { 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 return 0; 1888 return 0;
1889 } 1889 }
1890 1890
@@ -1893,8 +1893,8 @@ done: @@ -1893,8 +1893,8 @@ done:
1893 else if (strcmp(up_or_down, "down") == 0) 1893 else if (strcmp(up_or_down, "down") == 0)
1894 vc->link_down = 1; 1894 vc->link_down = 1;
1895 else 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 if (vc->link_status_changed) 1899 if (vc->link_status_changed)
1900 vc->link_status_changed(vc); 1900 vc->link_status_changed(vc);
@@ -53,8 +53,8 @@ void qemu_check_nic_model_list(NICInfo *nd, const char * const *models, @@ -53,8 +53,8 @@ void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
53 const char *default_model); 53 const char *default_model);
54 void qemu_handler_true(void *opaque); 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 /* NIC info */ 59 /* NIC info */
60 60
@@ -102,8 +102,8 @@ void net_slirp_redir(const char *redir_str); @@ -102,8 +102,8 @@ void net_slirp_redir(const char *redir_str);
102 void net_cleanup(void); 102 void net_cleanup(void);
103 int slirp_is_inited(void); 103 int slirp_is_inited(void);
104 void net_client_check(void); 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 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" 108 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
109 #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown" 109 #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
qemu-char.c
@@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
23 */ 23 */
24 #include "qemu-common.h" 24 #include "qemu-common.h"
25 #include "net.h" 25 #include "net.h"
  26 +#include "monitor.h"
26 #include "console.h" 27 #include "console.h"
27 #include "sysemu.h" 28 #include "sysemu.h"
28 #include "qemu-timer.h" 29 #include "qemu-timer.h"
@@ -2199,11 +2200,11 @@ void qemu_chr_close(CharDriverState *chr) @@ -2199,11 +2200,11 @@ void qemu_chr_close(CharDriverState *chr)
2199 qemu_free(chr); 2200 qemu_free(chr);
2200 } 2201 }
2201 2202
2202 -void qemu_chr_info(void) 2203 +void qemu_chr_info(Monitor *mon)
2203 { 2204 {
2204 CharDriverState *chr; 2205 CharDriverState *chr;
2205 2206
2206 TAILQ_FOREACH(chr, &chardevs, next) { 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 #ifndef QEMU_CHAR_H 1 #ifndef QEMU_CHAR_H
2 #define QEMU_CHAR_H 2 #define QEMU_CHAR_H
3 3
  4 +#include "qemu-common.h"
4 #include "sys-queue.h" 5 #include "sys-queue.h"
  6 +
5 /* character device */ 7 /* character device */
6 8
7 #define CHR_EVENT_BREAK 0 /* serial break char */ 9 #define CHR_EVENT_BREAK 0 /* serial break char */
@@ -78,7 +80,7 @@ void qemu_chr_initial_reset(void); @@ -78,7 +80,7 @@ void qemu_chr_initial_reset(void);
78 int qemu_chr_can_read(CharDriverState *s); 80 int qemu_chr_can_read(CharDriverState *s);
79 void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len); 81 void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len);
80 void qemu_chr_accept_input(CharDriverState *s); 82 void qemu_chr_accept_input(CharDriverState *s);
81 -void qemu_chr_info(void); 83 +void qemu_chr_info(Monitor *mon);
82 84
83 extern int term_escape_char; 85 extern int term_escape_char;
84 86
qemu-common.h
@@ -205,6 +205,9 @@ void qemu_iovec_reset(QEMUIOVector *qiov); @@ -205,6 +205,9 @@ void qemu_iovec_reset(QEMUIOVector *qiov);
205 void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf); 205 void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
206 void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count); 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 #endif /* dyngen-exec.h hack */ 211 #endif /* dyngen-exec.h hack */
209 212
210 #endif 213 #endif
qemu-tool.c
@@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
12 */ 12 */
13 13
14 #include "qemu-common.h" 14 #include "qemu-common.h"
15 -#include "console.h" 15 +#include "monitor.h"
16 #include "sysemu.h" 16 #include "sysemu.h"
17 #include "qemu-timer.h" 17 #include "qemu-timer.h"
18 18
@@ -30,11 +30,13 @@ void qemu_service_io(void) @@ -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,8 +21,8 @@
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE. 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 #define TERM_CMD_BUF_SIZE 4095 27 #define TERM_CMD_BUF_SIZE 4095
28 #define TERM_MAX_CMDS 64 28 #define TERM_MAX_CMDS 64
@@ -49,7 +49,7 @@ static char *term_history[TERM_MAX_CMDS]; @@ -49,7 +49,7 @@ static char *term_history[TERM_MAX_CMDS];
49 static int term_hist_entry = -1; 49 static int term_hist_entry = -1;
50 50
51 static int nb_completions; 51 static int nb_completions;
52 -int completion_index; 52 +static int completion_index;
53 static char *completions[NB_COMPLETIONS_MAX]; 53 static char *completions[NB_COMPLETIONS_MAX];
54 54
55 static ReadLineFunc *term_readline_func; 55 static ReadLineFunc *term_readline_func;
@@ -59,8 +59,10 @@ static void *term_readline_opaque; @@ -59,8 +59,10 @@ static void *term_readline_opaque;
59 59
60 void readline_show_prompt(void) 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 term_last_cmd_buf_index = 0; 66 term_last_cmd_buf_index = 0;
65 term_last_cmd_buf_size = 0; 67 term_last_cmd_buf_size = 0;
66 term_esc_state = IS_NORM; 68 term_esc_state = IS_NORM;
@@ -69,22 +71,23 @@ void readline_show_prompt(void) @@ -69,22 +71,23 @@ void readline_show_prompt(void)
69 /* update the displayed command line */ 71 /* update the displayed command line */
70 static void term_update(void) 72 static void term_update(void)
71 { 73 {
  74 + Monitor *mon = cur_mon;
72 int i, delta, len; 75 int i, delta, len;
73 76
74 if (term_cmd_buf_size != term_last_cmd_buf_size || 77 if (term_cmd_buf_size != term_last_cmd_buf_size ||
75 memcmp(term_cmd_buf, term_last_cmd_buf, term_cmd_buf_size) != 0) { 78 memcmp(term_cmd_buf, term_last_cmd_buf, term_cmd_buf_size) != 0) {
76 for(i = 0; i < term_last_cmd_buf_index; i++) { 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 term_cmd_buf[term_cmd_buf_size] = '\0'; 82 term_cmd_buf[term_cmd_buf_size] = '\0';
80 if (term_is_password) { 83 if (term_is_password) {
81 len = strlen(term_cmd_buf); 84 len = strlen(term_cmd_buf);
82 for(i = 0; i < len; i++) 85 for(i = 0; i < len; i++)
83 - term_printf("*"); 86 + monitor_printf(mon, "*");
84 } else { 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 memcpy(term_last_cmd_buf, term_cmd_buf, term_cmd_buf_size); 91 memcpy(term_last_cmd_buf, term_cmd_buf, term_cmd_buf_size);
89 term_last_cmd_buf_size = term_cmd_buf_size; 92 term_last_cmd_buf_size = term_cmd_buf_size;
90 term_last_cmd_buf_index = term_cmd_buf_size; 93 term_last_cmd_buf_index = term_cmd_buf_size;
@@ -93,17 +96,17 @@ static void term_update(void) @@ -93,17 +96,17 @@ static void term_update(void)
93 delta = term_cmd_buf_index - term_last_cmd_buf_index; 96 delta = term_cmd_buf_index - term_last_cmd_buf_index;
94 if (delta > 0) { 97 if (delta > 0) {
95 for(i = 0;i < delta; i++) { 98 for(i = 0;i < delta; i++) {
96 - term_printf("\033[C"); 99 + monitor_printf(mon, "\033[C");
97 } 100 }
98 } else { 101 } else {
99 delta = -delta; 102 delta = -delta;
100 for(i = 0;i < delta; i++) { 103 for(i = 0;i < delta; i++) {
101 - term_printf("\033[D"); 104 + monitor_printf(mon, "\033[D");
102 } 105 }
103 } 106 }
104 term_last_cmd_buf_index = term_cmd_buf_index; 107 term_last_cmd_buf_index = term_cmd_buf_index;
105 } 108 }
106 - term_flush(); 109 + monitor_flush(mon);
107 } 110 }
108 111
109 static void term_insert_char(int ch) 112 static void term_insert_char(int ch)
@@ -285,15 +288,21 @@ static void term_hist_add(const char *cmdline) @@ -285,15 +288,21 @@ static void term_hist_add(const char *cmdline)
285 288
286 /* completion support */ 289 /* completion support */
287 290
288 -void add_completion(const char *str) 291 +void readline_add_completion(const char *str)
289 { 292 {
290 if (nb_completions < NB_COMPLETIONS_MAX) { 293 if (nb_completions < NB_COMPLETIONS_MAX) {
291 completions[nb_completions++] = qemu_strdup(str); 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 static void term_completion(void) 303 static void term_completion(void)
296 { 304 {
  305 + Monitor *mon = cur_mon;
297 int len, i, j, max_width, nb_cols, max_prefix; 306 int len, i, j, max_width, nb_cols, max_prefix;
298 char *cmdline; 307 char *cmdline;
299 308
@@ -317,7 +326,7 @@ static void term_completion(void) @@ -317,7 +326,7 @@ static void term_completion(void)
317 if (len > 0 && completions[0][len - 1] != '/') 326 if (len > 0 && completions[0][len - 1] != '/')
318 term_insert_char(' '); 327 term_insert_char(' ');
319 } else { 328 } else {
320 - term_printf("\n"); 329 + monitor_printf(mon, "\n");
321 max_width = 0; 330 max_width = 0;
322 max_prefix = 0; 331 max_prefix = 0;
323 for(i = 0; i < nb_completions; i++) { 332 for(i = 0; i < nb_completions; i++) {
@@ -347,9 +356,9 @@ static void term_completion(void) @@ -347,9 +356,9 @@ static void term_completion(void)
347 nb_cols = 80 / max_width; 356 nb_cols = 80 / max_width;
348 j = 0; 357 j = 0;
349 for(i = 0; i < nb_completions; i++) { 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 if (++j == nb_cols || i == (nb_completions - 1)) { 360 if (++j == nb_cols || i == (nb_completions - 1)) {
352 - term_printf("\n"); 361 + monitor_printf(mon, "\n");
353 j = 0; 362 j = 0;
354 } 363 }
355 } 364 }
@@ -360,6 +369,8 @@ static void term_completion(void) @@ -360,6 +369,8 @@ static void term_completion(void)
360 /* return true if command handled */ 369 /* return true if command handled */
361 void readline_handle_byte(int ch) 370 void readline_handle_byte(int ch)
362 { 371 {
  372 + Monitor *mon = cur_mon;
  373 +
363 switch(term_esc_state) { 374 switch(term_esc_state) {
364 case IS_NORM: 375 case IS_NORM:
365 switch(ch) { 376 switch(ch) {
@@ -380,13 +391,13 @@ void readline_handle_byte(int ch) @@ -380,13 +391,13 @@ void readline_handle_byte(int ch)
380 term_cmd_buf[term_cmd_buf_size] = '\0'; 391 term_cmd_buf[term_cmd_buf_size] = '\0';
381 if (!term_is_password) 392 if (!term_is_password)
382 term_hist_add(term_cmd_buf); 393 term_hist_add(term_cmd_buf);
383 - term_printf("\n"); 394 + monitor_printf(mon, "\n");
384 term_cmd_buf_index = 0; 395 term_cmd_buf_index = 0;
385 term_cmd_buf_size = 0; 396 term_cmd_buf_size = 0;
386 term_last_cmd_buf_index = 0; 397 term_last_cmd_buf_index = 0;
387 term_last_cmd_buf_size = 0; 398 term_last_cmd_buf_size = 0;
388 /* NOTE: readline_start can be called here */ 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 break; 401 break;
391 case 23: 402 case 23:
392 /* ^W */ 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,7 +24,7 @@
24 #include "qemu-common.h" 24 #include "qemu-common.h"
25 #include "hw/hw.h" 25 #include "hw/hw.h"
26 #include "net.h" 26 #include "net.h"
27 -#include "console.h" 27 +#include "monitor.h"
28 #include "sysemu.h" 28 #include "sysemu.h"
29 #include "qemu-timer.h" 29 #include "qemu-timer.h"
30 #include "qemu-char.h" 30 #include "qemu-char.h"
@@ -993,7 +993,7 @@ static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, @@ -993,7 +993,7 @@ static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
993 return ret; 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 BlockDriverState *bs, *bs1; 998 BlockDriverState *bs, *bs1;
999 QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1; 999 QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1;
@@ -1010,7 +1010,7 @@ void do_savevm(const char *name) @@ -1010,7 +1010,7 @@ void do_savevm(const char *name)
1010 1010
1011 bs = get_bs_snapshots(); 1011 bs = get_bs_snapshots();
1012 if (!bs) { 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 return; 1014 return;
1015 } 1015 }
1016 1016
@@ -1049,22 +1049,22 @@ void do_savevm(const char *name) @@ -1049,22 +1049,22 @@ void do_savevm(const char *name)
1049 sn->vm_clock_nsec = qemu_get_clock(vm_clock); 1049 sn->vm_clock_nsec = qemu_get_clock(vm_clock);
1050 1050
1051 if (bdrv_get_info(bs, bdi) < 0 || bdi->vm_state_offset <= 0) { 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 goto the_end; 1054 goto the_end;
1055 } 1055 }
1056 1056
1057 /* save the VM state */ 1057 /* save the VM state */
1058 f = qemu_fopen_bdrv(bs, bdi->vm_state_offset, 1); 1058 f = qemu_fopen_bdrv(bs, bdi->vm_state_offset, 1);
1059 if (!f) { 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 goto the_end; 1061 goto the_end;
1062 } 1062 }
1063 ret = qemu_savevm_state(f); 1063 ret = qemu_savevm_state(f);
1064 vm_state_size = qemu_ftell(f); 1064 vm_state_size = qemu_ftell(f);
1065 qemu_fclose(f); 1065 qemu_fclose(f);
1066 if (ret < 0) { 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 goto the_end; 1068 goto the_end;
1069 } 1069 }
1070 1070
@@ -1076,16 +1076,17 @@ void do_savevm(const char *name) @@ -1076,16 +1076,17 @@ void do_savevm(const char *name)
1076 if (must_delete) { 1076 if (must_delete) {
1077 ret = bdrv_snapshot_delete(bs1, old_sn->id_str); 1077 ret = bdrv_snapshot_delete(bs1, old_sn->id_str);
1078 if (ret < 0) { 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 /* Write VM state size only to the image that contains the state */ 1084 /* Write VM state size only to the image that contains the state */
1084 sn->vm_state_size = (bs == bs1 ? vm_state_size : 0); 1085 sn->vm_state_size = (bs == bs1 ? vm_state_size : 0);
1085 ret = bdrv_snapshot_create(bs1, sn); 1086 ret = bdrv_snapshot_create(bs1, sn);
1086 if (ret < 0) { 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,7 +1096,7 @@ void do_savevm(const char *name)
1095 vm_start(); 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 BlockDriverState *bs, *bs1; 1101 BlockDriverState *bs, *bs1;
1101 BlockDriverInfo bdi1, *bdi = &bdi1; 1102 BlockDriverInfo bdi1, *bdi = &bdi1;
@@ -1106,7 +1107,7 @@ void do_loadvm(const char *name) @@ -1106,7 +1107,7 @@ void do_loadvm(const char *name)
1106 1107
1107 bs = get_bs_snapshots(); 1108 bs = get_bs_snapshots();
1108 if (!bs) { 1109 if (!bs) {
1109 - term_printf("No block device supports snapshots\n"); 1110 + monitor_printf(mon, "No block device supports snapshots\n");
1110 return; 1111 return;
1111 } 1112 }
1112 1113
@@ -1122,19 +1123,21 @@ void do_loadvm(const char *name) @@ -1122,19 +1123,21 @@ void do_loadvm(const char *name)
1122 ret = bdrv_snapshot_goto(bs1, name); 1123 ret = bdrv_snapshot_goto(bs1, name);
1123 if (ret < 0) { 1124 if (ret < 0) {
1124 if (bs != bs1) 1125 if (bs != bs1)
1125 - term_printf("Warning: "); 1126 + monitor_printf(mon, "Warning: ");
1126 switch(ret) { 1127 switch(ret) {
1127 case -ENOTSUP: 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 break; 1132 break;
1131 case -ENOENT: 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 break; 1137 break;
1135 default: 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 break; 1141 break;
1139 } 1142 }
1140 /* fatal on snapshot block device */ 1143 /* fatal on snapshot block device */
@@ -1145,8 +1148,8 @@ void do_loadvm(const char *name) @@ -1145,8 +1148,8 @@ void do_loadvm(const char *name)
1145 } 1148 }
1146 1149
1147 if (bdrv_get_info(bs, bdi) < 0 || bdi->vm_state_offset <= 0) { 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 return; 1153 return;
1151 } 1154 }
1152 1155
@@ -1158,27 +1161,27 @@ void do_loadvm(const char *name) @@ -1158,27 +1161,27 @@ void do_loadvm(const char *name)
1158 /* restore the VM state */ 1161 /* restore the VM state */
1159 f = qemu_fopen_bdrv(bs, bdi->vm_state_offset, 0); 1162 f = qemu_fopen_bdrv(bs, bdi->vm_state_offset, 0);
1160 if (!f) { 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 goto the_end; 1165 goto the_end;
1163 } 1166 }
1164 ret = qemu_loadvm_state(f); 1167 ret = qemu_loadvm_state(f);
1165 qemu_fclose(f); 1168 qemu_fclose(f);
1166 if (ret < 0) { 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 the_end: 1172 the_end:
1170 if (saved_vm_running) 1173 if (saved_vm_running)
1171 vm_start(); 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 BlockDriverState *bs, *bs1; 1179 BlockDriverState *bs, *bs1;
1177 int i, ret; 1180 int i, ret;
1178 1181
1179 bs = get_bs_snapshots(); 1182 bs = get_bs_snapshots();
1180 if (!bs) { 1183 if (!bs) {
1181 - term_printf("No block device supports snapshots\n"); 1184 + monitor_printf(mon, "No block device supports snapshots\n");
1182 return; 1185 return;
1183 } 1186 }
1184 1187
@@ -1188,17 +1191,18 @@ void do_delvm(const char *name) @@ -1188,17 +1191,18 @@ void do_delvm(const char *name)
1188 ret = bdrv_snapshot_delete(bs1, name); 1191 ret = bdrv_snapshot_delete(bs1, name);
1189 if (ret < 0) { 1192 if (ret < 0) {
1190 if (ret == -ENOTSUP) 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 else 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 BlockDriverState *bs, *bs1; 1207 BlockDriverState *bs, *bs1;
1204 QEMUSnapshotInfo *sn_tab, *sn; 1208 QEMUSnapshotInfo *sn_tab, *sn;
@@ -1207,29 +1211,30 @@ void do_info_snapshots(void) @@ -1207,29 +1211,30 @@ void do_info_snapshots(void)
1207 1211
1208 bs = get_bs_snapshots(); 1212 bs = get_bs_snapshots();
1209 if (!bs) { 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 return; 1215 return;
1212 } 1216 }
1213 - term_printf("Snapshot devices:"); 1217 + monitor_printf(mon, "Snapshot devices:");
1214 for(i = 0; i <= nb_drives; i++) { 1218 for(i = 0; i <= nb_drives; i++) {
1215 bs1 = drives_table[i].bdrv; 1219 bs1 = drives_table[i].bdrv;
1216 if (bdrv_has_snapshot(bs1)) { 1220 if (bdrv_has_snapshot(bs1)) {
1217 if (bs == bs1) 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 nb_sns = bdrv_snapshot_list(bs, &sn_tab); 1227 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1224 if (nb_sns < 0) { 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 return; 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 for(i = 0; i < nb_sns; i++) { 1235 for(i = 0; i < nb_sns; i++) {
1231 sn = &sn_tab[i]; 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 qemu_free(sn_tab); 1239 qemu_free(sn_tab);
1235 } 1240 }
slirp/misc.c
@@ -557,14 +557,14 @@ relay(s) @@ -557,14 +557,14 @@ relay(s)
557 #endif 557 #endif
558 558
559 #ifdef CONFIG_QEMU 559 #ifdef CONFIG_QEMU
560 -extern void term_vprintf(const char *fmt, va_list ap); 560 +#include "monitor.h"
561 561
562 void lprint(const char *format, ...) 562 void lprint(const char *format, ...)
563 { 563 {
564 va_list args; 564 va_list args;
565 565
566 va_start(args, format); 566 va_start(args, format);
567 - term_vprintf(format, args); 567 + monitor_vprintf(cur_mon, format, args);
568 va_end(args); 568 va_end(args);
569 } 569 }
570 #else 570 #else
sysemu.h
@@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
2 #define SYSEMU_H 2 #define SYSEMU_H
3 /* Misc. things related to the system emulator. */ 3 /* Misc. things related to the system emulator. */
4 4
  5 +#include "qemu-common.h"
  6 +
5 /* vl.c */ 7 /* vl.c */
6 extern const char *bios_name; 8 extern const char *bios_name;
7 extern const char *bios_dir; 9 extern const char *bios_dir;
@@ -39,10 +41,10 @@ void qemu_system_powerdown(void); @@ -39,10 +41,10 @@ void qemu_system_powerdown(void);
39 #endif 41 #endif
40 void qemu_system_reset(void); 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 void qemu_announce_self(void); 49 void qemu_announce_self(void);
48 50
@@ -75,7 +77,7 @@ int tap_win32_init(VLANState *vlan, const char *model, @@ -75,7 +77,7 @@ int tap_win32_init(VLANState *vlan, const char *model,
75 const char *name, const char *ifname); 77 const char *name, const char *ifname);
76 78
77 /* SLIRP */ 79 /* SLIRP */
78 -void do_info_slirp(void); 80 +void do_info_slirp(Monitor *mon);
79 81
80 extern int bios_size; 82 extern int bios_size;
81 extern int cirrus_vga_enabled; 83 extern int cirrus_vga_enabled;
@@ -179,9 +181,10 @@ void destroy_nic(dev_match_fn *match_fn, void *arg); @@ -179,9 +181,10 @@ void destroy_nic(dev_match_fn *match_fn, void *arg);
179 void destroy_bdrvs(dev_match_fn *match_fn, void *arg); 181 void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
180 182
181 /* pci-hotplug */ 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 void pci_device_hot_remove_success(int pcibus, int slot); 188 void pci_device_hot_remove_success(int pcibus, int slot);
186 189
187 /* serial ports */ 190 /* serial ports */
@@ -237,9 +240,9 @@ struct soundhw { @@ -237,9 +240,9 @@ struct soundhw {
237 extern struct soundhw soundhw[]; 240 extern struct soundhw soundhw[];
238 #endif 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 const char *get_opt_name(char *buf, int buf_size, const char *p); 247 const char *get_opt_name(char *buf, int buf_size, const char *p);
245 const char *get_opt_value(char *buf, int buf_size, const char *p); 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,6 +554,7 @@ static void usb_info_device(int bus_num, int addr, int class_id,
554 int speed) 554 int speed)
555 { 555 {
556 const char *class_str, *speed_str; 556 const char *class_str, *speed_str;
  557 + Monitor *mon = cur_mon;
557 558
558 switch(speed) { 559 switch(speed) {
559 case USB_SPEED_LOW: 560 case USB_SPEED_LOW:
@@ -570,20 +571,21 @@ static void usb_info_device(int bus_num, int addr, int class_id, @@ -570,20 +571,21 @@ static void usb_info_device(int bus_num, int addr, int class_id,
570 break; 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 class_str = usb_class_str(class_id); 576 class_str = usb_class_str(class_id);
576 if (class_str) 577 if (class_str)
577 - term_printf(" %s:", class_str); 578 + monitor_printf(mon, " %s:", class_str);
578 else 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 if (product_name[0] != '\0') 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 int class_id, 589 int class_id,
588 int vendor_id, int product_id, 590 int vendor_id, int product_id,
589 const char *product_name, 591 const char *product_name,
@@ -594,7 +596,7 @@ static int usb_host_info_device(void *opaque, int bus_num, int addr, @@ -594,7 +596,7 @@ static int usb_host_info_device(void *opaque, int bus_num, int addr,
594 return 0; 596 return 0;
595 } 597 }
596 598
597 -void usb_host_info(void) 599 +void usb_host_info(Monitor *mon)
598 { 600 {
599 usb_host_scan(NULL, usb_host_info_device); 601 usb_host_scan(NULL, usb_host_info_device);
600 } 602 }
usb-linux.c
@@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
32 32
33 #include "qemu-common.h" 33 #include "qemu-common.h"
34 #include "qemu-timer.h" 34 #include "qemu-timer.h"
35 -#include "console.h" 35 +#include "monitor.h"
36 36
37 #include <dirent.h> 37 #include <dirent.h>
38 #include <sys/ioctl.h> 38 #include <sys/ioctl.h>
@@ -985,6 +985,7 @@ static int usb_host_auto_del(const char *spec); @@ -985,6 +985,7 @@ static int usb_host_auto_del(const char *spec);
985 985
986 USBDevice *usb_host_device_open(const char *devname) 986 USBDevice *usb_host_device_open(const char *devname)
987 { 987 {
  988 + Monitor *mon = cur_mon;
988 int bus_num, addr; 989 int bus_num, addr;
989 char product_name[PRODUCT_NAME_SZ]; 990 char product_name[PRODUCT_NAME_SZ];
990 991
@@ -998,7 +999,8 @@ USBDevice *usb_host_device_open(const char *devname) @@ -998,7 +999,8 @@ USBDevice *usb_host_device_open(const char *devname)
998 return NULL; 999 return NULL;
999 1000
1000 if (hostdev_find(bus_num, addr)) { 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 return NULL; 1004 return NULL;
1003 } 1005 }
1004 1006
@@ -1149,6 +1151,7 @@ static int usb_host_scan_dev(void *opaque, USBScanFunc *func) @@ -1149,6 +1151,7 @@ static int usb_host_scan_dev(void *opaque, USBScanFunc *func)
1149 */ 1151 */
1150 static int usb_host_read_file(char *line, size_t line_size, const char *device_file, const char *device_name) 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 FILE *f; 1155 FILE *f;
1153 int ret = 0; 1156 int ret = 0;
1154 char filename[PATH_MAX]; 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,7 +1164,7 @@ static int usb_host_read_file(char *line, size_t line_size, const char *device_f
1161 fclose(f); 1164 fclose(f);
1162 ret = 1; 1165 ret = 1;
1163 } else { 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 return ret; 1170 return ret;
@@ -1254,6 +1257,7 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func) @@ -1254,6 +1257,7 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func)
1254 */ 1257 */
1255 static int usb_host_scan(void *opaque, USBScanFunc *func) 1258 static int usb_host_scan(void *opaque, USBScanFunc *func)
1256 { 1259 {
  1260 + Monitor *mon = cur_mon;
1257 FILE *f = 0; 1261 FILE *f = 0;
1258 DIR *dir = 0; 1262 DIR *dir = 0;
1259 int ret = 0; 1263 int ret = 0;
@@ -1292,14 +1296,15 @@ static int usb_host_scan(void *opaque, USBScanFunc *func) @@ -1292,14 +1296,15 @@ static int usb_host_scan(void *opaque, USBScanFunc *func)
1292 } 1296 }
1293 found_devices: 1297 found_devices:
1294 if (!usb_fs_type) { 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 return -ENOENT; 1300 return -ENOENT;
1297 } 1301 }
1298 1302
1299 /* the module setting (used later for opening devices) */ 1303 /* the module setting (used later for opening devices) */
1300 usb_host_device_path = qemu_mallocz(strlen(devpath)+1); 1304 usb_host_device_path = qemu_mallocz(strlen(devpath)+1);
1301 strcpy(usb_host_device_path, devpath); 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 switch (usb_fs_type) { 1310 switch (usb_fs_type) {
@@ -1606,6 +1611,7 @@ static void usb_info_device(int bus_num, int addr, int class_id, @@ -1606,6 +1611,7 @@ static void usb_info_device(int bus_num, int addr, int class_id,
1606 const char *product_name, 1611 const char *product_name,
1607 int speed) 1612 int speed)
1608 { 1613 {
  1614 + Monitor *mon = cur_mon;
1609 const char *class_str, *speed_str; 1615 const char *class_str, *speed_str;
1610 1616
1611 switch(speed) { 1617 switch(speed) {
@@ -1623,17 +1629,17 @@ static void usb_info_device(int bus_num, int addr, int class_id, @@ -1623,17 +1629,17 @@ static void usb_info_device(int bus_num, int addr, int class_id,
1623 break; 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 bus_num, addr, speed_str); 1633 bus_num, addr, speed_str);
1628 class_str = usb_class_str(class_id); 1634 class_str = usb_class_str(class_id);
1629 if (class_str) 1635 if (class_str)
1630 - term_printf(" %s:", class_str); 1636 + monitor_printf(mon, " %s:", class_str);
1631 else 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 if (product_name[0] != '\0') 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 static int usb_host_info_device(void *opaque, int bus_num, int addr, 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,20 +1669,21 @@ static void hex2str(int val, char *str, size_t size)
1663 snprintf(str, size, "%x", val); 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 struct USBAutoFilter *f; 1674 struct USBAutoFilter *f;
1669 1675
1670 usb_host_scan(NULL, usb_host_info_device); 1676 usb_host_scan(NULL, usb_host_info_device);
1671 1677
1672 if (usb_auto_filter) 1678 if (usb_auto_filter)
1673 - term_printf(" Auto filters:\n"); 1679 + monitor_printf(mon, " Auto filters:\n");
1674 for (f = usb_auto_filter; f; f = f->next) { 1680 for (f = usb_auto_filter; f; f = f->next) {
1675 char bus[10], addr[10], vid[10], pid[10]; 1681 char bus[10], addr[10], vid[10], pid[10];
1676 dec2str(f->bus_num, bus, sizeof(bus)); 1682 dec2str(f->bus_num, bus, sizeof(bus));
1677 dec2str(f->addr, addr, sizeof(addr)); 1683 dec2str(f->addr, addr, sizeof(addr));
1678 hex2str(f->vendor_id, vid, sizeof(vid)); 1684 hex2str(f->vendor_id, vid, sizeof(vid));
1679 hex2str(f->product_id, pid, sizeof(pid)); 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,10 +33,11 @@
33 #include "qemu-common.h" 33 #include "qemu-common.h"
34 #include "console.h" 34 #include "console.h"
35 #include "hw/usb.h" 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 /* XXX: modify configure to compile the right host driver */ 43 /* XXX: modify configure to compile the right host driver */
@@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
31 #include "hw/baum.h" 31 #include "hw/baum.h"
32 #include "hw/bt.h" 32 #include "hw/bt.h"
33 #include "net.h" 33 #include "net.h"
  34 +#include "monitor.h"
34 #include "console.h" 35 #include "console.h"
35 #include "sysemu.h" 36 #include "sysemu.h"
36 #include "gdbstub.h" 37 #include "gdbstub.h"
@@ -653,34 +654,34 @@ int kbd_mouse_is_absolute(void) @@ -653,34 +654,34 @@ int kbd_mouse_is_absolute(void)
653 return qemu_put_mouse_event_current->qemu_put_mouse_event_absolute; 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 QEMUPutMouseEntry *cursor; 659 QEMUPutMouseEntry *cursor;
659 int index = 0; 660 int index = 0;
660 661
661 if (!qemu_put_mouse_event_head) { 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 return; 664 return;
664 } 665 }
665 666
666 - term_printf("Mouse devices available:\n"); 667 + monitor_printf(mon, "Mouse devices available:\n");
667 cursor = qemu_put_mouse_event_head; 668 cursor = qemu_put_mouse_event_head;
668 while (cursor != NULL) { 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 index++; 673 index++;
673 cursor = cursor->next; 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 QEMUPutMouseEntry *cursor; 680 QEMUPutMouseEntry *cursor;
680 int i = 0; 681 int i = 0;
681 682
682 if (!qemu_put_mouse_event_head) { 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 return; 685 return;
685 } 686 }
686 687
@@ -693,7 +694,7 @@ void do_mouse_set(int index) @@ -693,7 +694,7 @@ void do_mouse_set(int index)
693 if (cursor != NULL) 694 if (cursor != NULL)
694 qemu_put_mouse_event_current = cursor; 695 qemu_put_mouse_event_current = cursor;
695 else 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 /* compute with 96 bit intermediate result: (a*b)/c */ 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,7 +2698,8 @@ static int usb_device_add(const char *devname, int is_hotplug)
2697 if (bdrv_key_required(bs)) { 2698 if (bdrv_key_required(bs)) {
2698 autostart = 0; 2699 autostart = 0;
2699 if (is_hotplug) { 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 return 0; 2703 return 0;
2702 } 2704 }
2703 } 2705 }
@@ -2779,24 +2781,24 @@ static int usb_device_del(const char *devname) @@ -2779,24 +2781,24 @@ static int usb_device_del(const char *devname)
2779 return usb_device_del_addr(bus_num, addr); 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 usb_device_add(devname, 1); 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 usb_device_del(devname); 2791 usb_device_del(devname);
2790 } 2792 }
2791 2793
2792 -void usb_info(void) 2794 +void usb_info(Monitor *mon)
2793 { 2795 {
2794 USBDevice *dev; 2796 USBDevice *dev;
2795 USBPort *port; 2797 USBPort *port;
2796 const char *speed_str; 2798 const char *speed_str;
2797 2799
2798 if (!usb_enabled) { 2800 if (!usb_enabled) {
2799 - term_printf("USB support not enabled\n"); 2801 + monitor_printf(mon, "USB support not enabled\n");
2800 return; 2802 return;
2801 } 2803 }
2802 2804
@@ -2818,8 +2820,8 @@ void usb_info(void) @@ -2818,8 +2820,8 @@ void usb_info(void)
2818 speed_str = "?"; 2820 speed_str = "?";
2819 break; 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,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 struct pcmcia_socket_entry_s *iter; 2860 struct pcmcia_socket_entry_s *iter;
  2861 +
2859 if (!pcmcia_sockets) 2862 if (!pcmcia_sockets)
2860 - term_printf("No PCMCIA sockets\n"); 2863 + monitor_printf(mon, "No PCMCIA sockets\n");
2861 2864
2862 for (iter = pcmcia_sockets; iter; iter = iter->next) 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,7 +5729,7 @@ int main(int argc, char **argv, char **envp)
5726 #endif 5729 #endif
5727 5730
5728 if (loadvm) 5731 if (loadvm)
5729 - do_loadvm(loadvm); 5732 + do_loadvm(cur_mon, loadvm);
5730 5733
5731 if (incoming) { 5734 if (incoming) {
5732 autostart = 0; /* fixme how to deal with -daemonize */ 5735 autostart = 0; /* fixme how to deal with -daemonize */
@@ -24,6 +24,7 @@ @@ -24,6 +24,7 @@
24 */ 24 */
25 25
26 #include "qemu-common.h" 26 #include "qemu-common.h"
  27 +#include "monitor.h"
27 #include "console.h" 28 #include "console.h"
28 #include "sysemu.h" 29 #include "sysemu.h"
29 #include "qemu_socket.h" 30 #include "qemu_socket.h"
@@ -166,19 +167,19 @@ struct VncState @@ -166,19 +167,19 @@ struct VncState
166 static VncDisplay *vnc_display; /* needed for info vnc */ 167 static VncDisplay *vnc_display; /* needed for info vnc */
167 static DisplayChangeListener *dcl; 168 static DisplayChangeListener *dcl;
168 169
169 -void do_info_vnc(void) 170 +void do_info_vnc(Monitor *mon)
170 { 171 {
171 if (vnc_display == NULL || vnc_display->display == NULL) 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 else { 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 if (vnc_display->clients == NULL) 179 if (vnc_display->clients == NULL)
179 - term_printf("No client connected\n"); 180 + monitor_printf(mon, "No client connected\n");
180 else 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,10 +808,11 @@ static void audio_capture(void *opaque, void *buf, int size)
807 808
808 static void audio_add(VncState *vs) 809 static void audio_add(VncState *vs)
809 { 810 {
  811 + Monitor *mon = cur_mon;
810 struct audio_capture_ops ops; 812 struct audio_capture_ops ops;
811 813
812 if (vs->audio_cap) { 814 if (vs->audio_cap) {
813 - term_printf ("audio already running\n"); 815 + monitor_printf(mon, "audio already running\n");
814 return; 816 return;
815 } 817 }
816 818
@@ -820,7 +822,7 @@ static void audio_add(VncState *vs) @@ -820,7 +822,7 @@ static void audio_add(VncState *vs)
820 822
821 vs->audio_cap = AUD_add_capture(NULL, &vs->as, &ops, vs); 823 vs->audio_cap = AUD_add_capture(NULL, &vs->as, &ops, vs);
822 if (!vs->audio_cap) { 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