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
This commit is contained in:
aliguori 2009-03-05 23:01:23 +00:00
parent bb5fc20f7c
commit 376253ece4
45 changed files with 831 additions and 720 deletions

View File

@ -23,7 +23,7 @@
*/
#include "hw/hw.h"
#include "audio.h"
#include "console.h"
#include "monitor.h"
#include "qemu-timer.h"
#include "sysemu.h"
@ -328,10 +328,10 @@ void AUD_vlog (const char *cap, const char *fmt, va_list ap)
{
if (conf.log_to_monitor) {
if (cap) {
term_printf ("%s: ", cap);
monitor_printf(cur_mon, "%s: ", cap);
}
term_vprintf (fmt, ap);
monitor_vprintf(cur_mon, fmt, ap);
}
else {
if (cap) {

View File

@ -1,5 +1,5 @@
#include "hw/hw.h"
#include "console.h"
#include "monitor.h"
#include "audio.h"
typedef struct {
@ -71,7 +71,7 @@ static void wav_capture_info (void *opaque)
WAVState *wav = opaque;
char *path = wav->path;
term_printf ("Capturing audio(%d,%d,%d) to %s: %d bytes\n",
monitor_printf(cur_mon, "Capturing audio(%d,%d,%d) to %s: %d bytes\n",
wav->freq, wav->bits, wav->nchannels,
path ? path : "<not available>", wav->bytes);
}
@ -84,6 +84,7 @@ static struct capture_ops wav_capture_ops = {
int wav_start_capture (CaptureState *s, const char *path, int freq,
int bits, int nchannels)
{
Monitor *mon = cur_mon;
WAVState *wav;
uint8_t hdr[] = {
0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56,
@ -97,12 +98,12 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
CaptureVoiceOut *cap;
if (bits != 8 && bits != 16) {
term_printf ("incorrect bit count %d, must be 8 or 16\n", bits);
monitor_printf(mon, "incorrect bit count %d, must be 8 or 16\n", bits);
return -1;
}
if (nchannels != 1 && nchannels != 2) {
term_printf ("incorrect channel count %d, must be 1 or 2\n",
monitor_printf(mon, "incorrect channel count %d, must be 1 or 2\n",
nchannels);
return -1;
}
@ -131,7 +132,7 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
wav->f = qemu_fopen (path, "wb");
if (!wav->f) {
term_printf ("Failed to open wave file `%s'\nReason: %s\n",
monitor_printf(mon, "Failed to open wave file `%s'\nReason: %s\n",
path, strerror (errno));
qemu_free (wav);
return -1;
@ -146,7 +147,7 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
cap = AUD_add_capture (NULL, &as, &ops, wav);
if (!cap) {
term_printf ("Failed to add audio capture\n");
monitor_printf(mon, "Failed to add audio capture\n");
qemu_free (wav->path);
qemu_fclose (wav->f);
qemu_free (wav);

44
block.c
View File

@ -28,7 +28,7 @@
#endif
#include "qemu-common.h"
#include "console.h"
#include "monitor.h"
#include "block_int.h"
#ifdef _BSD
@ -1091,53 +1091,53 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum);
}
void bdrv_info(void)
void bdrv_info(Monitor *mon)
{
BlockDriverState *bs;
for (bs = bdrv_first; bs != NULL; bs = bs->next) {
term_printf("%s:", bs->device_name);
term_printf(" type=");
monitor_printf(mon, "%s:", bs->device_name);
monitor_printf(mon, " type=");
switch(bs->type) {
case BDRV_TYPE_HD:
term_printf("hd");
monitor_printf(mon, "hd");
break;
case BDRV_TYPE_CDROM:
term_printf("cdrom");
monitor_printf(mon, "cdrom");
break;
case BDRV_TYPE_FLOPPY:
term_printf("floppy");
monitor_printf(mon, "floppy");
break;
}
term_printf(" removable=%d", bs->removable);
monitor_printf(mon, " removable=%d", bs->removable);
if (bs->removable) {
term_printf(" locked=%d", bs->locked);
monitor_printf(mon, " locked=%d", bs->locked);
}
if (bs->drv) {
term_printf(" file=");
term_print_filename(bs->filename);
monitor_printf(mon, " file=");
monitor_print_filename(mon, bs->filename);
if (bs->backing_file[0] != '\0') {
term_printf(" backing_file=");
term_print_filename(bs->backing_file);
monitor_printf(mon, " backing_file=");
monitor_print_filename(mon, bs->backing_file);
}
term_printf(" ro=%d", bs->read_only);
term_printf(" drv=%s", bs->drv->format_name);
term_printf(" encrypted=%d", bdrv_is_encrypted(bs));
monitor_printf(mon, " ro=%d", bs->read_only);
monitor_printf(mon, " drv=%s", bs->drv->format_name);
monitor_printf(mon, " encrypted=%d", bdrv_is_encrypted(bs));
} else {
term_printf(" [not inserted]");
monitor_printf(mon, " [not inserted]");
}
term_printf("\n");
monitor_printf(mon, "\n");
}
}
/* The "info blockstats" command. */
void bdrv_info_stats (void)
void bdrv_info_stats(Monitor *mon)
{
BlockDriverState *bs;
BlockDriverInfo bdi;
for (bs = bdrv_first; bs != NULL; bs = bs->next) {
term_printf ("%s:"
monitor_printf(mon, "%s:"
" rd_bytes=%" PRIu64
" wr_bytes=%" PRIu64
" rd_operations=%" PRIu64
@ -1147,10 +1147,10 @@ void bdrv_info_stats (void)
bs->rd_bytes, bs->wr_bytes,
bs->rd_ops, bs->wr_ops);
if (bdrv_get_info(bs, &bdi) == 0)
term_printf(" high=%" PRId64
monitor_printf(mon, " high=%" PRId64
" bytes_free=%" PRId64,
bdi.highest_alloc, bdi.num_free_bytes);
term_printf("\n");
monitor_printf(mon, "\n");
}
}

View File

@ -56,8 +56,8 @@ typedef struct QEMUSnapshotInfo {
#define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_CACHE_DEF)
void bdrv_info(void);
void bdrv_info_stats(void);
void bdrv_info(Monitor *mon);
void bdrv_info_stats(Monitor *mon);
void bdrv_init(void);
BlockDriver *bdrv_find_format(const char *format_name);

View File

@ -43,8 +43,8 @@ struct mouse_transform_info_s {
int a[7];
};
void do_info_mice(void);
void do_mouse_set(int index);
void do_info_mice(Monitor *mon);
void do_mouse_set(Monitor *mon, int index);
/* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
constants) */
@ -287,39 +287,9 @@ void vnc_display_init(DisplayState *ds);
void vnc_display_close(DisplayState *ds);
int vnc_display_open(DisplayState *ds, const char *display);
int vnc_display_password(DisplayState *ds, const char *password);
void do_info_vnc(void);
void do_info_vnc(Monitor *mon);
/* curses.c */
void curses_display_init(DisplayState *ds, int full_screen);
/* FIXME: term_printf et al should probably go elsewhere so everything
does not need to include console.h */
/* monitor.c */
void monitor_init(CharDriverState *hd, int show_banner);
void term_puts(const char *str);
void term_vprintf(const char *fmt, va_list ap);
void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
void term_print_filename(const char *filename);
void term_flush(void);
void term_print_help(void);
void monitor_suspend(void);
void monitor_resume(void);
#include "block.h"
void monitor_read_bdrv_key_start(BlockDriverState *bs,
BlockDriverCompletionFunc *completion_cb,
void *opaque);
/* readline.c */
typedef void ReadLineFunc(void *opaque, const char *str);
extern int completion_index;
void add_completion(const char *str);
void readline_handle_byte(int ch);
void readline_find_completion(const char *cmdline);
const char *readline_get_history(unsigned int index);
void readline_start(const char *prompt, int is_password,
ReadLineFunc *readline_func, void *opaque);
void readline_show_prompt(void);
#endif

15
disas.c
View File

@ -308,8 +308,7 @@ const char *lookup_symbol(target_ulong orig_addr)
#if !defined(CONFIG_USER_ONLY)
void term_vprintf(const char *fmt, va_list ap);
void term_printf(const char *fmt, ...);
#include "monitor.h"
static int monitor_disas_is_physical;
static CPUState *monitor_disas_env;
@ -330,19 +329,19 @@ static int monitor_fprintf(FILE *stream, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
term_vprintf(fmt, ap);
monitor_vprintf((Monitor *)stream, fmt, ap);
va_end(ap);
return 0;
}
void monitor_disas(CPUState *env,
void monitor_disas(Monitor *mon, CPUState *env,
target_ulong pc, int nb_insn, int is_physical, int flags)
{
int count, i;
struct disassemble_info disasm_info;
int (*print_insn)(bfd_vma pc, disassemble_info *info);
INIT_DISASSEMBLE_INFO(disasm_info, NULL, monitor_fprintf);
INIT_DISASSEMBLE_INFO(disasm_info, (FILE *)mon, monitor_fprintf);
monitor_disas_env = env;
monitor_disas_is_physical = is_physical;
@ -388,15 +387,15 @@ void monitor_disas(CPUState *env,
print_insn = print_insn_little_mips;
#endif
#else
term_printf("0x" TARGET_FMT_lx
monitor_printf(mon, "0x" TARGET_FMT_lx
": Asm output not supported on this arch\n", pc);
return;
#endif
for(i = 0; i < nb_insn; i++) {
term_printf("0x" TARGET_FMT_lx ": ", pc);
monitor_printf(mon, "0x" TARGET_FMT_lx ": ", pc);
count = print_insn(pc, &disasm_info);
term_printf("\n");
monitor_printf(mon, "\n");
if (count < 0)
break;
pc += count;

View File

@ -1,11 +1,17 @@
#ifndef _QEMU_DISAS_H
#define _QEMU_DISAS_H
#include "qemu-common.h"
/* Disassemble this for me please... (debugging). */
void disas(FILE *out, void *code, unsigned long size);
void target_disas(FILE *out, target_ulong code, target_ulong size, int flags);
void monitor_disas(CPUState *env,
/* The usual mess... FIXME: Remove this condition once dyngen-exec.h is gone */
#ifndef __DYNGEN_EXEC_H__
void monitor_disas(Monitor *mon, CPUState *env,
target_ulong pc, int nb_insn, int is_physical, int flags);
#endif
/* Look up symbol for debugging purpose. Returns "" if unknown. */
const char *lookup_symbol(target_ulong orig_addr);

View File

@ -7,6 +7,7 @@
*/
#include "hw.h"
#include "pc.h"
#include "mcf.h"
#include "sysemu.h"
#include "boards.h"
@ -16,11 +17,11 @@
#define AN5206_RAMBAR_ADDR 0x20000000
/* Stub functions for hardware that doesn't exist. */
void pic_info(void)
void pic_info(Monitor *mon)
{
}
void irq_info(void)
void irq_info(Monitor *mon)
{
}

View File

@ -8,14 +8,15 @@
*/
#include "hw.h"
#include "pc.h"
#include "arm-misc.h"
/* Stub functions for hardware that doesn't exist. */
void pic_info(void)
void pic_info(Monitor *mon)
{
}
void irq_info(void)
void irq_info(Monitor *mon)
{
}

View File

@ -24,6 +24,7 @@
#include <stdio.h>
#include "hw.h"
#include "pc.h"
#include "etraxfs.h"
#define D(x)
@ -135,11 +136,11 @@ static CPUWriteMemoryFunc *pic_write[] = {
&pic_writel,
};
void pic_info(void)
void pic_info(Monitor *mon)
{
}
void irq_info(void)
void irq_info(Monitor *mon)
{
}

View File

@ -24,7 +24,7 @@
#include "hw.h"
#include "pc.h"
#include "isa.h"
#include "console.h"
#include "monitor.h"
/* debug PIC */
//#define DEBUG_PIC
@ -511,7 +511,7 @@ static void pic_init1(int io_addr, int elcr_addr, PicState *s)
qemu_register_reset(pic_reset, s);
}
void pic_info(void)
void pic_info(Monitor *mon)
{
int i;
PicState *s;
@ -521,26 +521,27 @@ void pic_info(void)
for(i=0;i<2;i++) {
s = &isa_pic->pics[i];
term_printf("pic%d: irr=%02x imr=%02x isr=%02x hprio=%d irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n",
monitor_printf(mon, "pic%d: irr=%02x imr=%02x isr=%02x hprio=%d "
"irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n",
i, s->irr, s->imr, s->isr, s->priority_add,
s->irq_base, s->read_reg_select, s->elcr,
s->special_fully_nested_mode);
}
}
void irq_info(void)
void irq_info(Monitor *mon)
{
#ifndef DEBUG_IRQ_COUNT
term_printf("irq statistic code not compiled.\n");
monitor_printf(mon, "irq statistic code not compiled.\n");
#else
int i;
int64_t count;
term_printf("IRQ statistics:\n");
monitor_printf(mon, "IRQ statistics:\n");
for (i = 0; i < 16; i++) {
count = irq_count[i];
if (count > 0)
term_printf("%2d: %" PRId64 "\n", i, count);
monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
}
#endif
}

View File

@ -31,7 +31,7 @@
#include "net.h"
#include "smbus.h"
#include "boards.h"
#include "console.h"
#include "monitor.h"
#include "fw_cfg.h"
#include "virtio-blk.h"
#include "virtio-balloon.h"
@ -208,6 +208,7 @@ static int boot_device2nibble(char boot_device)
and used there as well */
static int pc_boot_set(void *opaque, const char *boot_device)
{
Monitor *mon = cur_mon;
#define PC_MAX_BOOT_DEVICES 3
RTCState *s = (RTCState *)opaque;
int nbds, bds[3] = { 0, };
@ -215,13 +216,13 @@ static int pc_boot_set(void *opaque, const char *boot_device)
nbds = strlen(boot_device);
if (nbds > PC_MAX_BOOT_DEVICES) {
term_printf("Too many boot devices for PC\n");
monitor_printf(mon, "Too many boot devices for PC\n");
return(1);
}
for (i = 0; i < nbds; i++) {
bds[i] = boot_device2nibble(boot_device[i]);
if (bds[i] == 0) {
term_printf("Invalid boot device for PC: '%c'\n",
monitor_printf(mon, "Invalid boot device for PC: '%c'\n",
boot_device[i]);
return(1);
}

View File

@ -1,5 +1,8 @@
#ifndef HW_PC_H
#define HW_PC_H
#include "qemu-common.h"
/* PC-style peripherals (also used by other machines). */
/* serial.c */
@ -34,8 +37,8 @@ void pic_set_alt_irq_func(PicState2 *s, SetIRQFunc *alt_irq_func,
int pic_read_irq(PicState2 *s);
void pic_update_irq(PicState2 *s);
uint32_t pic_intack_read(PicState2 *s);
void pic_info(void);
void irq_info(void);
void pic_info(Monitor *mon);
void irq_info(Monitor *mon);
/* APIC */
typedef struct IOAPICState IOAPICState;

View File

@ -28,7 +28,7 @@
#include "net.h"
#include "sysemu.h"
#include "pc.h"
#include "console.h"
#include "monitor.h"
#include "block_int.h"
#include "virtio-blk.h"
@ -43,7 +43,7 @@ static PCIDevice *qemu_pci_hot_add_nic(PCIBus *pci_bus, const char *opts)
return pci_nic_init (pci_bus, &nd_table[ret], -1, "rtl8139");
}
void drive_hot_add(const char *pci_addr, const char *opts)
void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
{
int dom, pci_bus;
unsigned slot;
@ -52,13 +52,13 @@ void drive_hot_add(const char *pci_addr, const char *opts)
PCIDevice *dev;
if (pci_read_devaddr(pci_addr, &dom, &pci_bus, &slot)) {
term_printf("Invalid pci address\n");
monitor_printf(mon, "Invalid pci address\n");
return;
}
dev = pci_find_device(pci_bus, slot, 0);
if (!dev) {
term_printf("no pci device with address %s\n", pci_addr);
monitor_printf(mon, "no pci device with address %s\n", pci_addr);
return;
}
@ -75,16 +75,18 @@ void drive_hot_add(const char *pci_addr, const char *opts)
drives_table[drive_idx].unit);
break;
default:
term_printf("Can't hot-add drive to type %d\n", type);
monitor_printf(mon, "Can't hot-add drive to type %d\n", type);
}
if (success)
term_printf("OK bus %d, unit %d\n", drives_table[drive_idx].bus,
monitor_printf(mon, "OK bus %d, unit %d\n",
drives_table[drive_idx].bus,
drives_table[drive_idx].unit);
return;
}
static PCIDevice *qemu_pci_hot_add_storage(PCIBus *pci_bus, const char *opts)
static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, PCIBus *pci_bus,
const char *opts)
{
void *opaque = NULL;
int type = -1, drive_idx = -1;
@ -97,7 +99,7 @@ static PCIDevice *qemu_pci_hot_add_storage(PCIBus *pci_bus, const char *opts)
type = IF_VIRTIO;
}
} else {
term_printf("no if= specified\n");
monitor_printf(mon, "no if= specified\n");
return NULL;
}
@ -106,7 +108,7 @@ static PCIDevice *qemu_pci_hot_add_storage(PCIBus *pci_bus, const char *opts)
if (drive_idx < 0)
return NULL;
} else if (type == IF_VIRTIO) {
term_printf("virtio requires a backing file/device.\n");
monitor_printf(mon, "virtio requires a backing file/device.\n");
return NULL;
}
@ -121,13 +123,14 @@ static PCIDevice *qemu_pci_hot_add_storage(PCIBus *pci_bus, const char *opts)
opaque = virtio_blk_init (pci_bus, drives_table[drive_idx].bdrv);
break;
default:
term_printf ("type %s not a hotpluggable PCI device.\n", buf);
monitor_printf(mon, "type %s not a hotpluggable PCI device.\n", buf);
}
return opaque;
}
void pci_device_hot_add(const char *pci_addr, const char *type, const char *opts)
void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
const char *opts)
{
PCIDevice *dev = NULL;
PCIBus *pci_bus;
@ -135,47 +138,47 @@ void pci_device_hot_add(const char *pci_addr, const char *type, const char *opts
unsigned slot;
if (pci_assign_devaddr(pci_addr, &dom, &bus, &slot)) {
term_printf("Invalid pci address\n");
monitor_printf(mon, "Invalid pci address\n");
return;
}
pci_bus = pci_find_bus(bus);
if (!pci_bus) {
term_printf("Can't find pci_bus %d\n", bus);
monitor_printf(mon, "Can't find pci_bus %d\n", bus);
return;
}
if (strcmp(type, "nic") == 0)
dev = qemu_pci_hot_add_nic(pci_bus, opts);
else if (strcmp(type, "storage") == 0)
dev = qemu_pci_hot_add_storage(pci_bus, opts);
dev = qemu_pci_hot_add_storage(mon, pci_bus, opts);
else
term_printf("invalid type: %s\n", type);
monitor_printf(mon, "invalid type: %s\n", type);
if (dev) {
qemu_system_device_hot_add(bus, PCI_SLOT(dev->devfn), 1);
term_printf("OK domain %d, bus %d, slot %d, function %d\n",
monitor_printf(mon, "OK domain %d, bus %d, slot %d, function %d\n",
0, pci_bus_num(dev->bus), PCI_SLOT(dev->devfn),
PCI_FUNC(dev->devfn));
} else
term_printf("failed to add %s\n", opts);
monitor_printf(mon, "failed to add %s\n", opts);
}
#endif
void pci_device_hot_remove(const char *pci_addr)
void pci_device_hot_remove(Monitor *mon, const char *pci_addr)
{
PCIDevice *d;
int dom, bus;
unsigned slot;
if (pci_read_devaddr(pci_addr, &dom, &bus, &slot)) {
term_printf("Invalid pci address\n");
monitor_printf(mon, "Invalid pci address\n");
return;
}
d = pci_find_device(bus, slot, 0);
if (!d) {
term_printf("slot %d empty\n", slot);
monitor_printf(mon, "slot %d empty\n", slot);
return;
}
@ -199,7 +202,7 @@ void pci_device_hot_remove_success(int pcibus, int slot)
int class_code;
if (!d) {
term_printf("invalid slot %d\n", slot);
monitor_printf(cur_mon, "invalid slot %d\n", slot);
return;
}

View File

@ -23,7 +23,7 @@
*/
#include "hw.h"
#include "pci.h"
#include "console.h"
#include "monitor.h"
#include "net.h"
#include "virtio-net.h"
#include "sysemu.h"
@ -705,41 +705,43 @@ static const pci_class_desc pci_class_descriptions[] =
static void pci_info_device(PCIDevice *d)
{
Monitor *mon = cur_mon;
int i, class;
PCIIORegion *r;
const pci_class_desc *desc;
term_printf(" Bus %2d, device %3d, function %d:\n",
monitor_printf(mon, " Bus %2d, device %3d, function %d:\n",
d->bus->bus_num, d->devfn >> 3, d->devfn & 7);
class = le16_to_cpu(*((uint16_t *)(d->config + PCI_CLASS_DEVICE)));
term_printf(" ");
monitor_printf(mon, " ");
desc = pci_class_descriptions;
while (desc->desc && class != desc->class)
desc++;
if (desc->desc) {
term_printf("%s", desc->desc);
monitor_printf(mon, "%s", desc->desc);
} else {
term_printf("Class %04x", class);
monitor_printf(mon, "Class %04x", class);
}
term_printf(": PCI device %04x:%04x\n",
monitor_printf(mon, ": PCI device %04x:%04x\n",
le16_to_cpu(*((uint16_t *)(d->config + PCI_VENDOR_ID))),
le16_to_cpu(*((uint16_t *)(d->config + PCI_DEVICE_ID))));
if (d->config[PCI_INTERRUPT_PIN] != 0) {
term_printf(" IRQ %d.\n", d->config[PCI_INTERRUPT_LINE]);
monitor_printf(mon, " IRQ %d.\n",
d->config[PCI_INTERRUPT_LINE]);
}
if (class == 0x0604) {
term_printf(" BUS %d.\n", d->config[0x19]);
monitor_printf(mon, " BUS %d.\n", d->config[0x19]);
}
for(i = 0;i < PCI_NUM_REGIONS; i++) {
r = &d->io_regions[i];
if (r->size != 0) {
term_printf(" BAR%d: ", i);
monitor_printf(mon, " BAR%d: ", i);
if (r->type & PCI_ADDRESS_SPACE_IO) {
term_printf("I/O at 0x%04x [0x%04x].\n",
monitor_printf(mon, "I/O at 0x%04x [0x%04x].\n",
r->addr, r->addr + r->size - 1);
} else {
term_printf("32 bit memory at 0x%08x [0x%08x].\n",
monitor_printf(mon, "32 bit memory at 0x%08x [0x%08x].\n",
r->addr, r->addr + r->size - 1);
}
}
@ -766,7 +768,7 @@ void pci_for_each_device(int bus_num, void (*fn)(PCIDevice *d))
}
}
void pci_info(void)
void pci_info(Monitor *mon)
{
pci_for_each_device(0, pci_info_device);
}

View File

@ -1,6 +1,8 @@
#ifndef QEMU_PCI_H
#define QEMU_PCI_H
#include "qemu-common.h"
/* PCI includes legacy ISA access. */
#include "isa.h"
@ -242,7 +244,7 @@ PCIDevice *pci_find_device(int bus_num, int slot, int function);
int pci_read_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp);
int pci_assign_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp);
void pci_info(void);
void pci_info(Monitor *mon);
PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
pci_map_irq_fn map_irq, const char *name);

View File

@ -1,5 +1,7 @@
/* PCMCIA/Cardbus */
#include "qemu-common.h"
struct pcmcia_socket_s {
qemu_irq irq;
int attached;
@ -9,7 +11,7 @@ struct pcmcia_socket_s {
void pcmcia_socket_register(struct pcmcia_socket_s *socket);
void pcmcia_socket_unregister(struct pcmcia_socket_s *socket);
void pcmcia_info(void);
void pcmcia_info(Monitor *mon);
struct pcmcia_card_s {
void *state;

View File

@ -28,6 +28,7 @@
More information in target-sh4/README.sh4
*/
#include "hw.h"
#include "pc.h"
#include "sh.h"
#include "sysemu.h"
#include "boards.h"
@ -35,12 +36,12 @@
#define BIOS_FILENAME "shix_bios.bin"
#define BIOS_ADDRESS 0xA0000000
void irq_info(void)
void irq_info(Monitor *mon)
{
/* XXXXX */
}
void pic_info(void)
void pic_info(Monitor *mon)
{
/* XXXXX */
}

View File

@ -23,7 +23,7 @@
*/
#include "hw.h"
#include "sun4m.h"
#include "console.h"
#include "monitor.h"
//#define DEBUG_IRQ_COUNT
//#define DEBUG_IRQ
@ -219,33 +219,33 @@ static CPUWriteMemoryFunc *slavio_intctlm_mem_write[3] = {
slavio_intctlm_mem_writel,
};
void slavio_pic_info(void *opaque)
void slavio_pic_info(Monitor *mon, void *opaque)
{
SLAVIO_INTCTLState *s = opaque;
int i;
for (i = 0; i < MAX_CPUS; i++) {
term_printf("per-cpu %d: pending 0x%08x\n", i,
monitor_printf(mon, "per-cpu %d: pending 0x%08x\n", i,
s->slaves[i]->intreg_pending);
}
term_printf("master: pending 0x%08x, disabled 0x%08x\n",
monitor_printf(mon, "master: pending 0x%08x, disabled 0x%08x\n",
s->intregm_pending, s->intregm_disabled);
}
void slavio_irq_info(void *opaque)
void slavio_irq_info(Monitor *mon, void *opaque)
{
#ifndef DEBUG_IRQ_COUNT
term_printf("irq statistic code not compiled.\n");
monitor_printf(mon, "irq statistic code not compiled.\n");
#else
SLAVIO_INTCTLState *s = opaque;
int i;
int64_t count;
term_printf("IRQ statistics:\n");
monitor_printf(mon, "IRQ statistics:\n");
for (i = 0; i < 32; i++) {
count = s->irq_count[i];
if (count > 0)
term_printf("%2d: %" PRId64 "\n", i, count);
monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
}
#endif
}

View File

@ -23,7 +23,7 @@
*/
#include "hw.h"
#include "sun4m.h"
#include "console.h"
#include "monitor.h"
//#define DEBUG_IRQ_COUNT
//#define DEBUG_IRQ
@ -90,26 +90,26 @@ static CPUWriteMemoryFunc *sun4c_intctl_mem_write[3] = {
NULL,
};
void sun4c_pic_info(void *opaque)
void sun4c_pic_info(Monitor *mon, void *opaque)
{
Sun4c_INTCTLState *s = opaque;
term_printf("master: pending 0x%2.2x, enabled 0x%2.2x\n", s->pending,
s->reg);
monitor_printf(mon, "master: pending 0x%2.2x, enabled 0x%2.2x\n",
s->pending, s->reg);
}
void sun4c_irq_info(void *opaque)
void sun4c_irq_info(Monitor *mon, void *opaque)
{
#ifndef DEBUG_IRQ_COUNT
term_printf("irq statistic code not compiled.\n");
monitor_printf(mon, "irq statistic code not compiled.\n");
#else
Sun4c_INTCTLState *s = opaque;
int64_t count;
term_printf("IRQ statistics:\n");
monitor_printf(mon, "IRQ statistics:\n");
count = s->irq_count[i];
if (count > 0)
term_printf("%2d: %" PRId64 "\n", i, count);
monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
#endif
}

View File

@ -283,16 +283,16 @@ static void nvram_init(m48t59_t *nvram, uint8_t *macaddr, const char *cmdline,
static void *slavio_intctl;
void pic_info(void)
void pic_info(Monitor *mon)
{
if (slavio_intctl)
slavio_pic_info(slavio_intctl);
slavio_pic_info(mon, slavio_intctl);
}
void irq_info(void)
void irq_info(Monitor *mon)
{
if (slavio_intctl)
slavio_irq_info(slavio_intctl);
slavio_irq_info(mon, slavio_intctl);
}
void cpu_check_irqs(CPUState *env)

View File

@ -1,6 +1,8 @@
#ifndef SUN4M_H
#define SUN4M_H
#include "qemu-common.h"
/* Devices used by sparc32 system. */
/* iommu.c */
@ -31,8 +33,8 @@ void *slavio_intctl_init(target_phys_addr_t addr, target_phys_addr_t addrg,
const uint32_t *intbit_to_level,
qemu_irq **irq, qemu_irq **cpu_irq,
qemu_irq **parent_irq, unsigned int cputimer);
void slavio_pic_info(void *opaque);
void slavio_irq_info(void *opaque);
void slavio_pic_info(Monitor *mon, void *opaque);
void slavio_irq_info(Monitor *mon, void *opaque);
/* sbi.c */
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,
/* sun4c_intctl.c */
void *sun4c_intctl_init(target_phys_addr_t addr, qemu_irq **irq,
qemu_irq *parent_irq);
void sun4c_pic_info(void *opaque);
void sun4c_irq_info(void *opaque);
void sun4c_pic_info(Monitor *mon, void *opaque);
void sun4c_irq_info(Monitor *mon, void *opaque);
/* slavio_timer.c */
void slavio_timer_init_all(target_phys_addr_t base, qemu_irq master_irq,

View File

@ -244,7 +244,7 @@ USBDevice *usb_hub_init(int nb_ports);
/* usb-linux.c */
USBDevice *usb_host_device_open(const char *devname);
int usb_host_device_close(const char *devname);
void usb_host_info(void);
void usb_host_info(Monitor *mon);
/* usb-hid.c */
USBDevice *usb_mouse_init(void);

View File

@ -18,7 +18,7 @@
#include "migration.h"
#include "qemu-char.h"
#include "sysemu.h"
#include "console.h"
#include "monitor.h"
#include "buffered_file.h"
#include "block.h"
@ -94,7 +94,7 @@ MigrationState *exec_start_outgoing_migration(const char *command,
if (s->detach == 1) {
dprintf("detaching from monitor\n");
monitor_suspend();
monitor_suspend(cur_mon);
s->detach = 2;
}

View File

@ -16,7 +16,7 @@
#include "migration.h"
#include "qemu-char.h"
#include "sysemu.h"
#include "console.h"
#include "monitor.h"
#include "buffered_file.h"
#include "block.h"
@ -110,7 +110,7 @@ MigrationState *tcp_start_outgoing_migration(const char *host_port,
if (s->detach == 1) {
dprintf("detaching from monitor\n");
monitor_suspend();
monitor_suspend(cur_mon);
s->detach = 2;
}

View File

@ -13,7 +13,7 @@
#include "qemu-common.h"
#include "migration.h"
#include "console.h"
#include "monitor.h"
#include "buffered_file.h"
#include "sysemu.h"
#include "block.h"
@ -48,7 +48,7 @@ void qemu_start_incoming_migration(const char *uri)
fprintf(stderr, "unknown migration protocol: %s\n", uri);
}
void do_migrate(int detach, const char *uri)
void do_migrate(Monitor *mon, int detach, const char *uri)
{
MigrationState *s = NULL;
const char *p;
@ -60,10 +60,10 @@ void do_migrate(int detach, const char *uri)
s = exec_start_outgoing_migration(p, max_throttle, detach);
#endif
else
term_printf("unknown migration protocol: %s\n", uri);
monitor_printf(mon, "unknown migration protocol: %s\n", uri);
if (s == NULL)
term_printf("migration failed\n");
monitor_printf(mon, "migration failed\n");
else {
if (current_migration)
current_migration->release(current_migration);
@ -72,7 +72,7 @@ void do_migrate(int detach, const char *uri)
}
}
void do_migrate_cancel(void)
void do_migrate_cancel(Monitor *mon)
{
MigrationState *s = current_migration;
@ -80,7 +80,7 @@ void do_migrate_cancel(void)
s->cancel(s);
}
void do_migrate_set_speed(const char *value)
void do_migrate_set_speed(Monitor *mon, const char *value)
{
double d;
char *ptr;
@ -100,24 +100,24 @@ void do_migrate_set_speed(const char *value)
max_throttle = (uint32_t)d;
}
void do_info_migrate(void)
void do_info_migrate(Monitor *mon)
{
MigrationState *s = current_migration;
if (s) {
term_printf("Migration status: ");
monitor_printf(mon, "Migration status: ");
switch (s->get_status(s)) {
case MIG_STATE_ACTIVE:
term_printf("active\n");
monitor_printf(mon, "active\n");
break;
case MIG_STATE_COMPLETED:
term_printf("completed\n");
monitor_printf(mon, "completed\n");
break;
case MIG_STATE_ERROR:
term_printf("failed\n");
monitor_printf(mon, "failed\n");
break;
case MIG_STATE_CANCELLED:
term_printf("cancelled\n");
monitor_printf(mon, "cancelled\n");
break;
}
}
@ -146,7 +146,7 @@ void migrate_fd_cleanup(FdMigrationState *s)
/* Don't resume monitor until we've flushed all of the buffers */
if (s->detach == 2) {
monitor_resume();
monitor_resume(cur_mon);
s->detach = 0;
}

View File

@ -14,6 +14,8 @@
#ifndef QEMU_MIGRATION_H
#define QEMU_MIGRATION_H
#include "qemu-common.h"
#define MIG_STATE_ERROR -1
#define MIG_STATE_COMPLETED 0
#define MIG_STATE_CANCELLED 1
@ -47,13 +49,13 @@ struct FdMigrationState
void qemu_start_incoming_migration(const char *uri);
void do_migrate(int detach, const char *uri);
void do_migrate(Monitor *mon, int detach, const char *uri);
void do_migrate_cancel(void);
void do_migrate_cancel(Monitor *mon);
void do_migrate_set_speed(const char *value);
void do_migrate_set_speed(Monitor *mon, const char *value);
void do_info_migrate(void);
void do_info_migrate(Monitor *mon);
int exec_start_incoming_migration(const char *host_port);

676
monitor.c

File diff suppressed because it is too large Load Diff

25
monitor.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef MONITOR_H
#define MONITOR_H
#include "qemu-common.h"
#include "qemu-char.h"
#include "block.h"
extern Monitor *cur_mon;
void monitor_init(CharDriverState *chr, int show_banner);
void monitor_suspend(Monitor *mon);
void monitor_resume(Monitor *mon);
void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
BlockDriverCompletionFunc *completion_cb,
void *opaque);
void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap);
void monitor_printf(Monitor *mon, const char *fmt, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
void monitor_print_filename(Monitor *mon, const char *filename);
void monitor_flush(Monitor *mon);
#endif /* !MONITOR_H */

30
net.c
View File

@ -23,7 +23,7 @@
*/
#include "qemu-common.h"
#include "net.h"
#include "console.h"
#include "monitor.h"
#include "sysemu.h"
#include "qemu-timer.h"
#include "qemu-char.h"
@ -665,7 +665,7 @@ void net_slirp_smb(const char *exported_dir)
}
#endif /* !defined(_WIN32) */
void do_info_slirp(void)
void do_info_slirp(Monitor *mon)
{
slirp_stats();
}
@ -1804,28 +1804,28 @@ static int net_host_check_device(const char *device)
return 0;
}
void net_host_device_add(const char *device, const char *opts)
void net_host_device_add(Monitor *mon, const char *device, const char *opts)
{
if (!net_host_check_device(device)) {
term_printf("invalid host network device %s\n", device);
monitor_printf(mon, "invalid host network device %s\n", device);
return;
}
net_client_init(device, opts);
}
void net_host_device_remove(int vlan_id, const char *device)
void net_host_device_remove(Monitor *mon, int vlan_id, const char *device)
{
VLANState *vlan;
VLANClientState *vc;
if (!net_host_check_device(device)) {
term_printf("invalid host network device %s\n", device);
monitor_printf(mon, "invalid host network device %s\n", device);
return;
}
vlan = qemu_find_vlan(vlan_id);
if (!vlan) {
term_printf("can't find vlan %d\n", vlan_id);
monitor_printf(mon, "can't find vlan %d\n", vlan_id);
return;
}
@ -1834,7 +1834,7 @@ void net_host_device_remove(int vlan_id, const char *device)
break;
if (!vc) {
term_printf("can't find device %s\n", device);
monitor_printf(mon, "can't find device %s\n", device);
return;
}
qemu_del_vlan_client(vc);
@ -1860,19 +1860,19 @@ int net_client_parse(const char *str)
return net_client_init(device, p);
}
void do_info_network(void)
void do_info_network(Monitor *mon)
{
VLANState *vlan;
VLANClientState *vc;
for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
term_printf("VLAN %d devices:\n", vlan->id);
monitor_printf(mon, "VLAN %d devices:\n", vlan->id);
for(vc = vlan->first_client; vc != NULL; vc = vc->next)
term_printf(" %s: %s\n", vc->name, vc->info_str);
monitor_printf(mon, " %s: %s\n", vc->name, vc->info_str);
}
}
int do_set_link(const char *name, const char *up_or_down)
int do_set_link(Monitor *mon, const char *name, const char *up_or_down)
{
VLANState *vlan;
VLANClientState *vc = NULL;
@ -1884,7 +1884,7 @@ int do_set_link(const char *name, const char *up_or_down)
done:
if (!vc) {
term_printf("could not find network device '%s'", name);
monitor_printf(mon, "could not find network device '%s'", name);
return 0;
}
@ -1893,8 +1893,8 @@ done:
else if (strcmp(up_or_down, "down") == 0)
vc->link_down = 1;
else
term_printf("invalid link status '%s'; only 'up' or 'down' valid\n",
up_or_down);
monitor_printf(mon, "invalid link status '%s'; only 'up' or 'down' "
"valid\n", up_or_down);
if (vc->link_status_changed)
vc->link_status_changed(vc);

8
net.h
View File

@ -53,8 +53,8 @@ void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
const char *default_model);
void qemu_handler_true(void *opaque);
void do_info_network(void);
int do_set_link(const char *name, const char *up_or_down);
void do_info_network(Monitor *mon);
int do_set_link(Monitor *mon, const char *name, const char *up_or_down);
/* NIC info */
@ -102,8 +102,8 @@ void net_slirp_redir(const char *redir_str);
void net_cleanup(void);
int slirp_is_inited(void);
void net_client_check(void);
void net_host_device_add(const char *device, const char *opts);
void net_host_device_remove(int vlan_id, const char *device);
void net_host_device_add(Monitor *mon, const char *device, const char *opts);
void net_host_device_remove(Monitor *mon, int vlan_id, const char *device);
#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"

View File

@ -23,6 +23,7 @@
*/
#include "qemu-common.h"
#include "net.h"
#include "monitor.h"
#include "console.h"
#include "sysemu.h"
#include "qemu-timer.h"
@ -2199,11 +2200,11 @@ void qemu_chr_close(CharDriverState *chr)
qemu_free(chr);
}
void qemu_chr_info(void)
void qemu_chr_info(Monitor *mon)
{
CharDriverState *chr;
TAILQ_FOREACH(chr, &chardevs, next) {
term_printf("%s: filename=%s\n", chr->label, chr->filename);
monitor_printf(mon, "%s: filename=%s\n", chr->label, chr->filename);
}
}

View File

@ -1,7 +1,9 @@
#ifndef QEMU_CHAR_H
#define QEMU_CHAR_H
#include "qemu-common.h"
#include "sys-queue.h"
/* character device */
#define CHR_EVENT_BREAK 0 /* serial break char */
@ -78,7 +80,7 @@ void qemu_chr_initial_reset(void);
int qemu_chr_can_read(CharDriverState *s);
void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len);
void qemu_chr_accept_input(CharDriverState *s);
void qemu_chr_info(void);
void qemu_chr_info(Monitor *mon);
extern int term_escape_char;

View File

@ -205,6 +205,9 @@ void qemu_iovec_reset(QEMUIOVector *qiov);
void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
struct Monitor;
typedef struct Monitor Monitor;
#endif /* dyngen-exec.h hack */
#endif

View File

@ -12,7 +12,7 @@
*/
#include "qemu-common.h"
#include "console.h"
#include "monitor.h"
#include "sysemu.h"
#include "qemu-timer.h"
@ -30,11 +30,13 @@ void qemu_service_io(void)
{
}
void term_printf(const char *fmt, ...)
Monitor *cur_mon;
void monitor_printf(Monitor *mon, const char *fmt, ...)
{
}
void term_print_filename(const char *filename)
void monitor_print_filename(Monitor *mon, const char *filename)
{
}

View File

@ -21,8 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "qemu-common.h"
#include "console.h"
#include "readline.h"
#include "monitor.h"
#define TERM_CMD_BUF_SIZE 4095
#define TERM_MAX_CMDS 64
@ -49,7 +49,7 @@ static char *term_history[TERM_MAX_CMDS];
static int term_hist_entry = -1;
static int nb_completions;
int completion_index;
static int completion_index;
static char *completions[NB_COMPLETIONS_MAX];
static ReadLineFunc *term_readline_func;
@ -59,8 +59,10 @@ static void *term_readline_opaque;
void readline_show_prompt(void)
{
term_printf("%s", term_prompt);
term_flush();
Monitor *mon = cur_mon;
monitor_printf(mon, "%s", term_prompt);
monitor_flush(mon);
term_last_cmd_buf_index = 0;
term_last_cmd_buf_size = 0;
term_esc_state = IS_NORM;
@ -69,22 +71,23 @@ void readline_show_prompt(void)
/* update the displayed command line */
static void term_update(void)
{
Monitor *mon = cur_mon;
int i, delta, len;
if (term_cmd_buf_size != term_last_cmd_buf_size ||
memcmp(term_cmd_buf, term_last_cmd_buf, term_cmd_buf_size) != 0) {
for(i = 0; i < term_last_cmd_buf_index; i++) {
term_printf("\033[D");
monitor_printf(mon, "\033[D");
}
term_cmd_buf[term_cmd_buf_size] = '\0';
if (term_is_password) {
len = strlen(term_cmd_buf);
for(i = 0; i < len; i++)
term_printf("*");
monitor_printf(mon, "*");
} else {
term_printf("%s", term_cmd_buf);
monitor_printf(mon, "%s", term_cmd_buf);
}
term_printf("\033[K");
monitor_printf(mon, "\033[K");
memcpy(term_last_cmd_buf, term_cmd_buf, term_cmd_buf_size);
term_last_cmd_buf_size = term_cmd_buf_size;
term_last_cmd_buf_index = term_cmd_buf_size;
@ -93,17 +96,17 @@ static void term_update(void)
delta = term_cmd_buf_index - term_last_cmd_buf_index;
if (delta > 0) {
for(i = 0;i < delta; i++) {
term_printf("\033[C");
monitor_printf(mon, "\033[C");
}
} else {
delta = -delta;
for(i = 0;i < delta; i++) {
term_printf("\033[D");
monitor_printf(mon, "\033[D");
}
}
term_last_cmd_buf_index = term_cmd_buf_index;
}
term_flush();
monitor_flush(mon);
}
static void term_insert_char(int ch)
@ -285,15 +288,21 @@ static void term_hist_add(const char *cmdline)
/* completion support */
void add_completion(const char *str)
void readline_add_completion(const char *str)
{
if (nb_completions < NB_COMPLETIONS_MAX) {
completions[nb_completions++] = qemu_strdup(str);
}
}
void readline_set_completion_index(int index)
{
completion_index = index;
}
static void term_completion(void)
{
Monitor *mon = cur_mon;
int len, i, j, max_width, nb_cols, max_prefix;
char *cmdline;
@ -317,7 +326,7 @@ static void term_completion(void)
if (len > 0 && completions[0][len - 1] != '/')
term_insert_char(' ');
} else {
term_printf("\n");
monitor_printf(mon, "\n");
max_width = 0;
max_prefix = 0;
for(i = 0; i < nb_completions; i++) {
@ -347,9 +356,9 @@ static void term_completion(void)
nb_cols = 80 / max_width;
j = 0;
for(i = 0; i < nb_completions; i++) {
term_printf("%-*s", max_width, completions[i]);
monitor_printf(mon, "%-*s", max_width, completions[i]);
if (++j == nb_cols || i == (nb_completions - 1)) {
term_printf("\n");
monitor_printf(mon, "\n");
j = 0;
}
}
@ -360,6 +369,8 @@ static void term_completion(void)
/* return true if command handled */
void readline_handle_byte(int ch)
{
Monitor *mon = cur_mon;
switch(term_esc_state) {
case IS_NORM:
switch(ch) {
@ -380,13 +391,13 @@ void readline_handle_byte(int ch)
term_cmd_buf[term_cmd_buf_size] = '\0';
if (!term_is_password)
term_hist_add(term_cmd_buf);
term_printf("\n");
monitor_printf(mon, "\n");
term_cmd_buf_index = 0;
term_cmd_buf_size = 0;
term_last_cmd_buf_index = 0;
term_last_cmd_buf_size = 0;
/* NOTE: readline_start can be called here */
term_readline_func(term_readline_opaque, term_cmd_buf);
term_readline_func(mon, term_cmd_buf, term_readline_opaque);
break;
case 23:
/* ^W */

20
readline.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef READLINE_H
#define READLINE_H
#include "qemu-common.h"
typedef void ReadLineFunc(Monitor *mon, const char *str, void *opaque);
void readline_add_completion(const char *str);
void readline_set_completion_index(int index);
void readline_find_completion(const char *cmdline);
const char *readline_get_history(unsigned int index);
void readline_handle_byte(int ch);
void readline_start(const char *prompt, int is_password,
ReadLineFunc *readline_func, void *opaque);
void readline_show_prompt(void);
#endif /* !READLINE_H */

View File

@ -24,7 +24,7 @@
#include "qemu-common.h"
#include "hw/hw.h"
#include "net.h"
#include "console.h"
#include "monitor.h"
#include "sysemu.h"
#include "qemu-timer.h"
#include "qemu-char.h"
@ -993,7 +993,7 @@ static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
return ret;
}
void do_savevm(const char *name)
void do_savevm(Monitor *mon, const char *name)
{
BlockDriverState *bs, *bs1;
QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1;
@ -1010,7 +1010,7 @@ void do_savevm(const char *name)
bs = get_bs_snapshots();
if (!bs) {
term_printf("No block device can accept snapshots\n");
monitor_printf(mon, "No block device can accept snapshots\n");
return;
}
@ -1049,7 +1049,7 @@ void do_savevm(const char *name)
sn->vm_clock_nsec = qemu_get_clock(vm_clock);
if (bdrv_get_info(bs, bdi) < 0 || bdi->vm_state_offset <= 0) {
term_printf("Device %s does not support VM state snapshots\n",
monitor_printf(mon, "Device %s does not support VM state snapshots\n",
bdrv_get_device_name(bs));
goto the_end;
}
@ -1057,14 +1057,14 @@ void do_savevm(const char *name)
/* save the VM state */
f = qemu_fopen_bdrv(bs, bdi->vm_state_offset, 1);
if (!f) {
term_printf("Could not open VM state file\n");
monitor_printf(mon, "Could not open VM state file\n");
goto the_end;
}
ret = qemu_savevm_state(f);
vm_state_size = qemu_ftell(f);
qemu_fclose(f);
if (ret < 0) {
term_printf("Error %d while writing VM\n", ret);
monitor_printf(mon, "Error %d while writing VM\n", ret);
goto the_end;
}
@ -1076,7 +1076,8 @@ void do_savevm(const char *name)
if (must_delete) {
ret = bdrv_snapshot_delete(bs1, old_sn->id_str);
if (ret < 0) {
term_printf("Error while deleting snapshot on '%s'\n",
monitor_printf(mon,
"Error while deleting snapshot on '%s'\n",
bdrv_get_device_name(bs1));
}
}
@ -1084,7 +1085,7 @@ void do_savevm(const char *name)
sn->vm_state_size = (bs == bs1 ? vm_state_size : 0);
ret = bdrv_snapshot_create(bs1, sn);
if (ret < 0) {
term_printf("Error while creating snapshot on '%s'\n",
monitor_printf(mon, "Error while creating snapshot on '%s'\n",
bdrv_get_device_name(bs1));
}
}
@ -1095,7 +1096,7 @@ void do_savevm(const char *name)
vm_start();
}
void do_loadvm(const char *name)
void do_loadvm(Monitor *mon, const char *name)
{
BlockDriverState *bs, *bs1;
BlockDriverInfo bdi1, *bdi = &bdi1;
@ -1106,7 +1107,7 @@ void do_loadvm(const char *name)
bs = get_bs_snapshots();
if (!bs) {
term_printf("No block device supports snapshots\n");
monitor_printf(mon, "No block device supports snapshots\n");
return;
}
@ -1122,19 +1123,21 @@ void do_loadvm(const char *name)
ret = bdrv_snapshot_goto(bs1, name);
if (ret < 0) {
if (bs != bs1)
term_printf("Warning: ");
monitor_printf(mon, "Warning: ");
switch(ret) {
case -ENOTSUP:
term_printf("Snapshots not supported on device '%s'\n",
monitor_printf(mon,
"Snapshots not supported on device '%s'\n",
bdrv_get_device_name(bs1));
break;
case -ENOENT:
term_printf("Could not find snapshot '%s' on device '%s'\n",
monitor_printf(mon, "Could not find snapshot '%s' on "
"device '%s'\n",
name, bdrv_get_device_name(bs1));
break;
default:
term_printf("Error %d while activating snapshot on '%s'\n",
ret, bdrv_get_device_name(bs1));
monitor_printf(mon, "Error %d while activating snapshot on"
" '%s'\n", ret, bdrv_get_device_name(bs1));
break;
}
/* fatal on snapshot block device */
@ -1145,7 +1148,7 @@ void do_loadvm(const char *name)
}
if (bdrv_get_info(bs, bdi) < 0 || bdi->vm_state_offset <= 0) {
term_printf("Device %s does not support VM state snapshots\n",
monitor_printf(mon, "Device %s does not support VM state snapshots\n",
bdrv_get_device_name(bs));
return;
}
@ -1158,27 +1161,27 @@ void do_loadvm(const char *name)
/* restore the VM state */
f = qemu_fopen_bdrv(bs, bdi->vm_state_offset, 0);
if (!f) {
term_printf("Could not open VM state file\n");
monitor_printf(mon, "Could not open VM state file\n");
goto the_end;
}
ret = qemu_loadvm_state(f);
qemu_fclose(f);
if (ret < 0) {
term_printf("Error %d while loading VM state\n", ret);
monitor_printf(mon, "Error %d while loading VM state\n", ret);
}
the_end:
if (saved_vm_running)
vm_start();
}
void do_delvm(const char *name)
void do_delvm(Monitor *mon, const char *name)
{
BlockDriverState *bs, *bs1;
int i, ret;
bs = get_bs_snapshots();
if (!bs) {
term_printf("No block device supports snapshots\n");
monitor_printf(mon, "No block device supports snapshots\n");
return;
}
@ -1188,17 +1191,18 @@ void do_delvm(const char *name)
ret = bdrv_snapshot_delete(bs1, name);
if (ret < 0) {
if (ret == -ENOTSUP)
term_printf("Snapshots not supported on device '%s'\n",
monitor_printf(mon,
"Snapshots not supported on device '%s'\n",
bdrv_get_device_name(bs1));
else
term_printf("Error %d while deleting snapshot on '%s'\n",
ret, bdrv_get_device_name(bs1));
monitor_printf(mon, "Error %d while deleting snapshot on "
"'%s'\n", ret, bdrv_get_device_name(bs1));
}
}
}
}
void do_info_snapshots(void)
void do_info_snapshots(Monitor *mon)
{
BlockDriverState *bs, *bs1;
QEMUSnapshotInfo *sn_tab, *sn;
@ -1207,29 +1211,30 @@ void do_info_snapshots(void)
bs = get_bs_snapshots();
if (!bs) {
term_printf("No available block device supports snapshots\n");
monitor_printf(mon, "No available block device supports snapshots\n");
return;
}
term_printf("Snapshot devices:");
monitor_printf(mon, "Snapshot devices:");
for(i = 0; i <= nb_drives; i++) {
bs1 = drives_table[i].bdrv;
if (bdrv_has_snapshot(bs1)) {
if (bs == bs1)
term_printf(" %s", bdrv_get_device_name(bs1));
monitor_printf(mon, " %s", bdrv_get_device_name(bs1));
}
}
term_printf("\n");
monitor_printf(mon, "\n");
nb_sns = bdrv_snapshot_list(bs, &sn_tab);
if (nb_sns < 0) {
term_printf("bdrv_snapshot_list: error %d\n", nb_sns);
monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
return;
}
term_printf("Snapshot list (from %s):\n", bdrv_get_device_name(bs));
term_printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
monitor_printf(mon, "Snapshot list (from %s):\n",
bdrv_get_device_name(bs));
monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
for(i = 0; i < nb_sns; i++) {
sn = &sn_tab[i];
term_printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn));
monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn));
}
qemu_free(sn_tab);
}

View File

@ -557,14 +557,14 @@ relay(s)
#endif
#ifdef CONFIG_QEMU
extern void term_vprintf(const char *fmt, va_list ap);
#include "monitor.h"
void lprint(const char *format, ...)
{
va_list args;
va_start(args, format);
term_vprintf(format, args);
monitor_vprintf(cur_mon, format, args);
va_end(args);
}
#else

View File

@ -2,6 +2,8 @@
#define SYSEMU_H
/* Misc. things related to the system emulator. */
#include "qemu-common.h"
/* vl.c */
extern const char *bios_name;
extern const char *bios_dir;
@ -39,10 +41,10 @@ void qemu_system_powerdown(void);
#endif
void qemu_system_reset(void);
void do_savevm(const char *name);
void do_loadvm(const char *name);
void do_delvm(const char *name);
void do_info_snapshots(void);
void do_savevm(Monitor *mon, const char *name);
void do_loadvm(Monitor *mon, const char *name);
void do_delvm(Monitor *mon, const char *name);
void do_info_snapshots(Monitor *mon);
void qemu_announce_self(void);
@ -75,7 +77,7 @@ int tap_win32_init(VLANState *vlan, const char *model,
const char *name, const char *ifname);
/* SLIRP */
void do_info_slirp(void);
void do_info_slirp(Monitor *mon);
extern int bios_size;
extern int cirrus_vga_enabled;
@ -179,9 +181,10 @@ void destroy_nic(dev_match_fn *match_fn, void *arg);
void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
/* pci-hotplug */
void pci_device_hot_add(const char *pci_addr, const char *type, const char *opts);
void drive_hot_add(const char *pci_addr, const char *opts);
void pci_device_hot_remove(const char *pci_addr);
void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
const char *opts);
void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts);
void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
void pci_device_hot_remove_success(int pcibus, int slot);
/* serial ports */
@ -237,9 +240,9 @@ struct soundhw {
extern struct soundhw soundhw[];
#endif
void do_usb_add(const char *devname);
void do_usb_del(const char *devname);
void usb_info(void);
void do_usb_add(Monitor *mon, const char *devname);
void do_usb_del(Monitor *mon, const char *devname);
void usb_info(Monitor *mon);
const char *get_opt_name(char *buf, int buf_size, const char *p);
const char *get_opt_value(char *buf, int buf_size, const char *p);

View File

@ -554,6 +554,7 @@ static void usb_info_device(int bus_num, int addr, int class_id,
int speed)
{
const char *class_str, *speed_str;
Monitor *mon = cur_mon;
switch(speed) {
case USB_SPEED_LOW:
@ -570,20 +571,21 @@ static void usb_info_device(int bus_num, int addr, int class_id,
break;
}
term_printf(" Device %d.%d, speed %s Mb/s\n",
monitor_printf(mon, " Device %d.%d, speed %s Mb/s\n",
bus_num, addr, speed_str);
class_str = usb_class_str(class_id);
if (class_str)
term_printf(" %s:", class_str);
monitor_printf(mon, " %s:", class_str);
else
term_printf(" Class %02x:", class_id);
term_printf(" USB device %04x:%04x", vendor_id, product_id);
monitor_printf(mon, " Class %02x:", class_id);
monitor_printf(mon, " USB device %04x:%04x", vendor_id, product_id);
if (product_name[0] != '\0')
term_printf(", %s", product_name);
term_printf("\n");
monitor_printf(mon, ", %s", product_name);
monitor_printf(mon, "\n");
}
static int usb_host_info_device(void *opaque, int bus_num, int addr,
static int usb_host_info_device(void *opaque,
int bus_num, int addr,
int class_id,
int vendor_id, int product_id,
const char *product_name,
@ -594,7 +596,7 @@ static int usb_host_info_device(void *opaque, int bus_num, int addr,
return 0;
}
void usb_host_info(void)
void usb_host_info(Monitor *mon)
{
usb_host_scan(NULL, usb_host_info_device);
}

View File

@ -32,7 +32,7 @@
#include "qemu-common.h"
#include "qemu-timer.h"
#include "console.h"
#include "monitor.h"
#include <dirent.h>
#include <sys/ioctl.h>
@ -985,6 +985,7 @@ static int usb_host_auto_del(const char *spec);
USBDevice *usb_host_device_open(const char *devname)
{
Monitor *mon = cur_mon;
int bus_num, addr;
char product_name[PRODUCT_NAME_SZ];
@ -998,7 +999,8 @@ USBDevice *usb_host_device_open(const char *devname)
return NULL;
if (hostdev_find(bus_num, addr)) {
term_printf("husb: host usb device %d.%d is already open\n", bus_num, addr);
monitor_printf(mon, "husb: host usb device %d.%d is already open\n",
bus_num, addr);
return NULL;
}
@ -1149,6 +1151,7 @@ static int usb_host_scan_dev(void *opaque, USBScanFunc *func)
*/
static int usb_host_read_file(char *line, size_t line_size, const char *device_file, const char *device_name)
{
Monitor *mon = cur_mon;
FILE *f;
int ret = 0;
char filename[PATH_MAX];
@ -1161,7 +1164,7 @@ static int usb_host_read_file(char *line, size_t line_size, const char *device_f
fclose(f);
ret = 1;
} else {
term_printf("husb: could not open %s\n", filename);
monitor_printf(mon, "husb: could not open %s\n", filename);
}
return ret;
@ -1254,6 +1257,7 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func)
*/
static int usb_host_scan(void *opaque, USBScanFunc *func)
{
Monitor *mon = cur_mon;
FILE *f = 0;
DIR *dir = 0;
int ret = 0;
@ -1292,14 +1296,15 @@ static int usb_host_scan(void *opaque, USBScanFunc *func)
}
found_devices:
if (!usb_fs_type) {
term_printf("husb: unable to access USB devices\n");
monitor_printf(mon, "husb: unable to access USB devices\n");
return -ENOENT;
}
/* the module setting (used later for opening devices) */
usb_host_device_path = qemu_mallocz(strlen(devpath)+1);
strcpy(usb_host_device_path, devpath);
term_printf("husb: using %s file-system with %s\n", fs_type[usb_fs_type], usb_host_device_path);
monitor_printf(mon, "husb: using %s file-system with %s\n",
fs_type[usb_fs_type], usb_host_device_path);
}
switch (usb_fs_type) {
@ -1606,6 +1611,7 @@ static void usb_info_device(int bus_num, int addr, int class_id,
const char *product_name,
int speed)
{
Monitor *mon = cur_mon;
const char *class_str, *speed_str;
switch(speed) {
@ -1623,17 +1629,17 @@ static void usb_info_device(int bus_num, int addr, int class_id,
break;
}
term_printf(" Device %d.%d, speed %s Mb/s\n",
monitor_printf(mon, " Device %d.%d, speed %s Mb/s\n",
bus_num, addr, speed_str);
class_str = usb_class_str(class_id);
if (class_str)
term_printf(" %s:", class_str);
monitor_printf(mon, " %s:", class_str);
else
term_printf(" Class %02x:", class_id);
term_printf(" USB device %04x:%04x", vendor_id, product_id);
monitor_printf(mon, " Class %02x:", class_id);
monitor_printf(mon, " USB device %04x:%04x", vendor_id, product_id);
if (product_name[0] != '\0')
term_printf(", %s", product_name);
term_printf("\n");
monitor_printf(mon, ", %s", product_name);
monitor_printf(mon, "\n");
}
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)
snprintf(str, size, "%x", val);
}
void usb_host_info(void)
void usb_host_info(Monitor *mon)
{
struct USBAutoFilter *f;
usb_host_scan(NULL, usb_host_info_device);
if (usb_auto_filter)
term_printf(" Auto filters:\n");
monitor_printf(mon, " Auto filters:\n");
for (f = usb_auto_filter; f; f = f->next) {
char bus[10], addr[10], vid[10], pid[10];
dec2str(f->bus_num, bus, sizeof(bus));
dec2str(f->addr, addr, sizeof(addr));
hex2str(f->vendor_id, vid, sizeof(vid));
hex2str(f->product_id, pid, sizeof(pid));
term_printf(" Device %s.%s ID %s:%s\n", bus, addr, vid, pid);
monitor_printf(mon, " Device %s.%s ID %s:%s\n",
bus, addr, vid, pid);
}
}

View File

@ -33,10 +33,11 @@
#include "qemu-common.h"
#include "console.h"
#include "hw/usb.h"
#include "monitor.h"
void usb_host_info(void)
void usb_host_info(Monitor *mon)
{
term_printf("USB host devices not supported\n");
monitor_printf(mon, "USB host devices not supported\n");
}
/* XXX: modify configure to compile the right host driver */

37
vl.c
View File

@ -31,6 +31,7 @@
#include "hw/baum.h"
#include "hw/bt.h"
#include "net.h"
#include "monitor.h"
#include "console.h"
#include "sysemu.h"
#include "gdbstub.h"
@ -653,20 +654,20 @@ int kbd_mouse_is_absolute(void)
return qemu_put_mouse_event_current->qemu_put_mouse_event_absolute;
}
void do_info_mice(void)
void do_info_mice(Monitor *mon)
{
QEMUPutMouseEntry *cursor;
int index = 0;
if (!qemu_put_mouse_event_head) {
term_printf("No mouse devices connected\n");
monitor_printf(mon, "No mouse devices connected\n");
return;
}
term_printf("Mouse devices available:\n");
monitor_printf(mon, "Mouse devices available:\n");
cursor = qemu_put_mouse_event_head;
while (cursor != NULL) {
term_printf("%c Mouse #%d: %s\n",
monitor_printf(mon, "%c Mouse #%d: %s\n",
(cursor == qemu_put_mouse_event_current ? '*' : ' '),
index, cursor->qemu_put_mouse_event_name);
index++;
@ -674,13 +675,13 @@ void do_info_mice(void)
}
}
void do_mouse_set(int index)
void do_mouse_set(Monitor *mon, int index)
{
QEMUPutMouseEntry *cursor;
int i = 0;
if (!qemu_put_mouse_event_head) {
term_printf("No mouse devices connected\n");
monitor_printf(mon, "No mouse devices connected\n");
return;
}
@ -693,7 +694,7 @@ void do_mouse_set(int index)
if (cursor != NULL)
qemu_put_mouse_event_current = cursor;
else
term_printf("Mouse at given index not found\n");
monitor_printf(mon, "Mouse at given index not found\n");
}
/* compute with 96 bit intermediate result: (a*b)/c */
@ -2697,7 +2698,8 @@ static int usb_device_add(const char *devname, int is_hotplug)
if (bdrv_key_required(bs)) {
autostart = 0;
if (is_hotplug) {
monitor_read_bdrv_key_start(bs, usb_msd_password_cb, dev);
monitor_read_bdrv_key_start(cur_mon, bs, usb_msd_password_cb,
dev);
return 0;
}
}
@ -2779,24 +2781,24 @@ static int usb_device_del(const char *devname)
return usb_device_del_addr(bus_num, addr);
}
void do_usb_add(const char *devname)
void do_usb_add(Monitor *mon, const char *devname)
{
usb_device_add(devname, 1);
}
void do_usb_del(const char *devname)
void do_usb_del(Monitor *mon, const char *devname)
{
usb_device_del(devname);
}
void usb_info(void)
void usb_info(Monitor *mon)
{
USBDevice *dev;
USBPort *port;
const char *speed_str;
if (!usb_enabled) {
term_printf("USB support not enabled\n");
monitor_printf(mon, "USB support not enabled\n");
return;
}
@ -2818,7 +2820,7 @@ void usb_info(void)
speed_str = "?";
break;
}
term_printf(" Device %d.%d, Speed %s Mb/s, Product %s\n",
monitor_printf(mon, " Device %d.%d, Speed %s Mb/s, Product %s\n",
0, dev->addr, speed_str, dev->devname);
}
}
@ -2853,14 +2855,15 @@ void pcmcia_socket_unregister(struct pcmcia_socket_s *socket)
}
}
void pcmcia_info(void)
void pcmcia_info(Monitor *mon)
{
struct pcmcia_socket_entry_s *iter;
if (!pcmcia_sockets)
term_printf("No PCMCIA sockets\n");
monitor_printf(mon, "No PCMCIA sockets\n");
for (iter = pcmcia_sockets; iter; iter = iter->next)
term_printf("%s: %s\n", iter->socket->slot_string,
monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
iter->socket->attached ? iter->socket->card_string :
"Empty");
}
@ -5726,7 +5729,7 @@ int main(int argc, char **argv, char **envp)
#endif
if (loadvm)
do_loadvm(loadvm);
do_loadvm(cur_mon, loadvm);
if (incoming) {
autostart = 0; /* fixme how to deal with -daemonize */

20
vnc.c
View File

@ -24,6 +24,7 @@
*/
#include "qemu-common.h"
#include "monitor.h"
#include "console.h"
#include "sysemu.h"
#include "qemu_socket.h"
@ -166,19 +167,19 @@ struct VncState
static VncDisplay *vnc_display; /* needed for info vnc */
static DisplayChangeListener *dcl;
void do_info_vnc(void)
void do_info_vnc(Monitor *mon)
{
if (vnc_display == NULL || vnc_display->display == NULL)
term_printf("VNC server disabled\n");
monitor_printf(mon, "VNC server disabled\n");
else {
term_printf("VNC server active on: ");
term_print_filename(vnc_display->display);
term_printf("\n");
monitor_printf(mon, "VNC server active on: ");
monitor_print_filename(mon, vnc_display->display);
monitor_printf(mon, "\n");
if (vnc_display->clients == NULL)
term_printf("No client connected\n");
monitor_printf(mon, "No client connected\n");
else
term_printf("Client connected\n");
monitor_printf(mon, "Client connected\n");
}
}
@ -807,10 +808,11 @@ static void audio_capture(void *opaque, void *buf, int size)
static void audio_add(VncState *vs)
{
Monitor *mon = cur_mon;
struct audio_capture_ops ops;
if (vs->audio_cap) {
term_printf ("audio already running\n");
monitor_printf(mon, "audio already running\n");
return;
}
@ -820,7 +822,7 @@ static void audio_add(VncState *vs)
vs->audio_cap = AUD_add_capture(NULL, &vs->as, &ops, vs);
if (!vs->audio_cap) {
term_printf ("Failed to add audio capture\n");
monitor_printf(mon, "Failed to add audio capture\n");
}
}