Gallileo GT64xxx support, by Aurelien Jarno.
[qemu] / monitor.c
index d9257ff..6cb1c38 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -55,6 +55,7 @@ typedef struct term_cmd_t {
 } term_cmd_t;
 
 static CharDriverState *monitor_hd;
+static int hide_banner;
 
 static term_cmd_t term_cmds[];
 static term_cmd_t info_cmds[];
@@ -82,8 +83,10 @@ void term_puts(const char *str)
         c = *str++;
         if (c == '\0')
             break;
+        if (c == '\n')
+            term_outbuf[term_outbuf_index++] = '\r';
         term_outbuf[term_outbuf_index++] = c;
-        if (term_outbuf_index >= sizeof(term_outbuf) ||
+        if (term_outbuf_index >= (sizeof(term_outbuf) - 1) ||
             c == '\n')
             term_flush();
     }
@@ -104,6 +107,33 @@ void term_printf(const char *fmt, ...)
     va_end(ap);
 }
 
+void term_print_filename(const char *filename)
+{
+    int i;
+
+    for (i = 0; filename[i]; i++) {
+       switch (filename[i]) {
+       case ' ':
+       case '"':
+       case '\\':
+           term_printf("\\%c", filename[i]);
+           break;
+       case '\t':
+           term_printf("\\t");
+           break;
+       case '\r':
+           term_printf("\\r");
+           break;
+       case '\n':
+           term_printf("\\n");
+           break;
+       default:
+           term_printf("%c", filename[i]);
+           break;
+       }
+    }
+}
+
 static int monitor_fprintf(FILE *stream, const char *fmt, ...)
 {
     va_list ap;
@@ -165,13 +195,16 @@ static void do_help(const char *name)
     help_cmd(name);
 }
 
-static void do_commit(void)
+static void do_commit(const char *device)
 {
-    int i;
-
+    int i, all_devices;
+    
+    all_devices = !strcmp(device, "all");
     for (i = 0; i < MAX_DISKS; i++) {
         if (bs_table[i]) {
-            bdrv_commit(bs_table[i]);
+            if (all_devices || 
+                !strcmp(bdrv_get_device_name(bs_table[i]), device))
+                bdrv_commit(bs_table[i]);
         }
     }
 }
@@ -375,18 +408,6 @@ static void do_log(const char *items)
     cpu_set_log(mask);
 }
 
-static void do_savevm(const char *filename)
-{
-    if (qemu_savevm(filename) < 0)
-        term_printf("I/O error when saving VM to '%s'\n", filename);
-}
-
-static void do_loadvm(const char *filename)
-{
-    if (qemu_loadvm(filename) < 0) 
-        term_printf("I/O error when loading VM from '%s'\n", filename);
-}
-
 static void do_stop(void)
 {
     vm_stop(EXCP_INTERRUPT);
@@ -533,16 +554,16 @@ static void memory_dump(int count, int format, int wsize,
             term_printf(" ");
             switch(format) {
             case 'o':
-                term_printf("%#*llo", max_digits, v);
+                term_printf("%#*" PRIo64, max_digits, v);
                 break;
             case 'x':
-                term_printf("0x%0*llx", max_digits, v);
+                term_printf("0x%0*" PRIx64, max_digits, v);
                 break;
             case 'u':
-                term_printf("%*llu", max_digits, v);
+                term_printf("%*" PRIu64, max_digits, v);
                 break;
             case 'd':
-                term_printf("%*lld", max_digits, v);
+                term_printf("%*" PRId64, max_digits, v);
                 break;
             case 'c':
                 term_printc(v);
@@ -602,17 +623,17 @@ static void do_print(int count, int format, int size, unsigned int valh, unsigne
 #else
     switch(format) {
     case 'o':
-        term_printf("%#llo", val);
+        term_printf("%#" PRIo64, val);
         break;
     case 'x':
-        term_printf("%#llx", val);
+        term_printf("%#" PRIx64, val);
         break;
     case 'u':
-        term_printf("%llu", val);
+        term_printf("%" PRIu64, val);
         break;
     default:
     case 'd':
-        term_printf("%lld", val);
+        term_printf("%" PRId64, val);
         break;
     case 'c':
         term_printc(val);
@@ -622,6 +643,36 @@ static void do_print(int count, int format, int size, unsigned int valh, unsigne
     term_printf("\n");
 }
 
+static void do_memory_save(unsigned int valh, unsigned int vall, 
+                           uint32_t size, const char *filename)
+{
+    FILE *f;
+    target_long addr = GET_TLONG(valh, vall);
+    uint32_t l;
+    CPUState *env;
+    uint8_t buf[1024];
+
+    env = mon_get_cpu();
+    if (!env)
+        return;
+
+    f = fopen(filename, "wb");
+    if (!f) {
+        term_printf("could not open '%s'\n", filename);
+        return;
+    }
+    while (size != 0) {
+        l = sizeof(buf);
+        if (l > size)
+            l = size;
+        cpu_memory_rw_debug(env, addr, buf, l, 0);
+        fwrite(buf, 1, l, f);
+        addr += l;
+        size -= l;
+    }
+    fclose(f);
+}
+
 static void do_sum(uint32_t start, uint32_t size)
 {
     uint32_t addr;
@@ -819,6 +870,26 @@ static void do_send_key(const char *string)
     }
 }
 
+static int mouse_button_state;
+
+static void do_mouse_move(const char *dx_str, const char *dy_str, 
+                          const char *dz_str)
+{
+    int dx, dy, dz;
+    dx = strtol(dx_str, NULL, 0);
+    dy = strtol(dy_str, NULL, 0);
+    dz = 0;
+    if (dz_str) 
+        dz = strtol(dz_str, NULL, 0);
+    kbd_mouse_event(dx, dy, dz, mouse_button_state);
+}
+
+static void do_mouse_button(int button_state)
+{
+    mouse_button_state = button_state;
+    kbd_mouse_event(0, 0, 0, mouse_button_state);
+}
+
 static void do_ioport_read(int count, int format, int size, int addr, int has_index, int index)
 {
     uint32_t val;
@@ -1026,11 +1097,11 @@ static void do_info_profile(void)
     total = qemu_time;
     if (total == 0)
         total = 1;
-    term_printf("async time  %lld (%0.3f)\n",
+    term_printf("async time  %" PRId64 " (%0.3f)\n",
                 dev_time, dev_time / (double)ticks_per_sec);
-    term_printf("qemu time   %lld (%0.3f)\n",
+    term_printf("qemu time   %" PRId64 " (%0.3f)\n",
                 qemu_time, qemu_time / (double)ticks_per_sec);
-    term_printf("kqemu time  %lld (%0.3f %0.1f%%) count=%lld int=%lld excp=%lld intr=%lld\n",
+    term_printf("kqemu time  %" PRId64 " (%0.3f %0.1f%%) count=%" PRId64 " int=%" PRId64 " excp=%" PRId64 " intr=%" PRId64 "\n",
                 kqemu_time, kqemu_time / (double)ticks_per_sec,
                 kqemu_time / (double)total * 100.0,
                 kqemu_exec_count,
@@ -1055,11 +1126,69 @@ static void do_info_profile(void)
 }
 #endif
 
+/* Capture support */
+static LIST_HEAD (capture_list_head, CaptureState) capture_head;
+
+static void do_info_capture (void)
+{
+    int i;
+    CaptureState *s;
+
+    for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) {
+        term_printf ("[%d]: ", i);
+        s->ops.info (s->opaque);
+    }
+}
+
+static void do_stop_capture (int n)
+{
+    int i;
+    CaptureState *s;
+
+    for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) {
+        if (i == n) {
+            s->ops.destroy (s->opaque);
+            LIST_REMOVE (s, entries);
+            qemu_free (s);
+            return;
+        }
+    }
+}
+
+#ifdef HAS_AUDIO
+int wav_start_capture (CaptureState *s, const char *path, int freq,
+                       int bits, int nchannels);
+
+static void do_wav_capture (const char *path,
+                            int has_freq, int freq,
+                            int has_bits, int bits,
+                            int has_channels, int nchannels)
+{
+    CaptureState *s;
+
+    s = qemu_mallocz (sizeof (*s));
+    if (!s) {
+        term_printf ("Not enough memory to add wave capture\n");
+        return;
+    }
+
+    freq = has_freq ? freq : 44100;
+    bits = has_bits ? bits : 16;
+    nchannels = has_channels ? nchannels : 2;
+
+    if (wav_start_capture (s, path, freq, bits, nchannels)) {
+        term_printf ("Faied to add wave capture\n");
+        qemu_free (s);
+    }
+    LIST_INSERT_HEAD (&capture_head, s, entries);
+}
+#endif
+
 static term_cmd_t term_cmds[] = {
     { "help|?", "s?", do_help, 
       "[cmd]", "show the help" },
-    { "commit", "", do_commit, 
-      "", "commit changes to the disk images (if -snapshot is used)" },
+    { "commit", "s", do_commit, 
+      "device|all", "commit changes to the disk images (if -snapshot is used) or backing files" },
     { "info", "s?", do_info,
       "subcommand", "show various information about the system state" },
     { "q|quit", "", do_quit,
@@ -1072,10 +1201,12 @@ static term_cmd_t term_cmds[] = {
       "filename", "save screen into PPM image 'filename'" },
     { "log", "s", do_log,
       "item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" }, 
-    { "savevm", "F", do_savevm,
-      "filename", "save the whole virtual machine state to 'filename'" }, 
-    { "loadvm", "F", do_loadvm,
-      "filename", "restore the whole virtual machine state from 'filename'" }, 
+    { "savevm", "s?", do_savevm,
+      "tag|id", "save a VM snapshot. If no tag or id are provided, a new snapshot is created" }, 
+    { "loadvm", "s", do_loadvm,
+      "tag|id", "restore a VM snapshot from its tag or id" }, 
+    { "delvm", "s", do_delvm,
+      "tag|id", "delete a VM snapshot from its tag or id" }, 
     { "stop", "", do_stop, 
       "", "stop emulation", },
     { "c|cont", "", do_cont, 
@@ -1107,6 +1238,21 @@ static term_cmd_t term_cmds[] = {
       "device", "remove USB device 'bus.addr'" },
     { "cpu", "i", do_cpu_set, 
       "index", "set the default CPU" },
+    { "mouse_move", "sss?", do_mouse_move, 
+      "dx dy [dz]", "send mouse move events" },
+    { "mouse_button", "i", do_mouse_button, 
+      "state", "change mouse button state (1=L, 2=M, 4=R)" },
+    { "mouse_set", "i", do_mouse_set,
+      "index", "set which mouse device receives events" },
+#ifdef HAS_AUDIO
+    { "wavcapture", "si?i?i?", do_wav_capture,
+      "path [frequency bits channels]",
+      "capture audio to a wave file (default frequency=44100 bits=16 channels=2)" },
+#endif
+     { "stopcapture", "i", do_stop_capture,
+       "capture index", "stop capture" },
+    { "memsave", "lis", do_memory_save, 
+      "addr size file", "save to disk virtual memory dump starting at 'addr' of size 'size'", },
     { NULL, NULL, }, 
 };
 
@@ -1145,6 +1291,12 @@ static term_cmd_t info_cmds[] = {
       "", "show host USB devices", },
     { "profile", "", do_info_profile,
       "", "show profiling information", },
+    { "capture", "", do_info_capture,
+      "", "show capture information" },
+    { "snapshots", "", do_info_snapshots,
+      "", "show the currently saved VM snapshots" },
+    { "mice", "", do_info_mice,
+      "", "show which guest mouse is receiving events" },
     { NULL, NULL, },
 };
 
@@ -1584,8 +1736,11 @@ static target_long expr_unary(void)
         n = 0;
         break;
     default:
-        /* XXX: 64 bit version */
+#if TARGET_LONG_BITS == 64
+        n = strtoull(pch, &p, 0);
+#else
         n = strtoul(pch, &p, 0);
+#endif
         if (pch == p) {
             expr_error("invalid char in expression");
         }
@@ -1944,7 +2099,6 @@ static void monitor_handle_command(const char *cmdline)
                 while (isspace(*p)) 
                     p++;
                 if (*typestr == '?' || *typestr == '.') {
-                    typestr++;
                     if (*typestr == '?') {
                         if (*p == '\0')
                             has_arg = 0;
@@ -1960,6 +2114,7 @@ static void monitor_handle_command(const char *cmdline)
                             has_arg = 0;
                         }
                     }
+                    typestr++;
                     if (nb_args >= MAX_ARGS)
                         goto error_args;
                     args[nb_args++] = (void *)has_arg;
@@ -2052,6 +2207,9 @@ static void monitor_handle_command(const char *cmdline)
     case 6:
         cmd->handler(args[0], args[1], args[2], args[3], args[4], args[5]);
         break;
+    case 7:
+        cmd->handler(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
+        break;
     default:
         term_printf("unsupported number of arguments: %d\n", nb_args);
         goto fail;
@@ -2281,15 +2439,24 @@ static void monitor_start_input(void)
     readline_start("(qemu) ", 0, monitor_handle_command1, NULL);
 }
 
+static void term_event(void *opaque, int event)
+{
+    if (event != CHR_EVENT_RESET)
+       return;
+
+    if (!hide_banner)
+           term_printf("QEMU %s monitor - type 'help' for more information\n",
+                       QEMU_VERSION);
+    monitor_start_input();
+}
+
 void monitor_init(CharDriverState *hd, int show_banner)
 {
     monitor_hd = hd;
-    if (show_banner) {
-        term_printf("QEMU %s monitor - type 'help' for more information\n",
-                    QEMU_VERSION);
-    }
+    hide_banner = !show_banner;
+
     qemu_chr_add_read_handler(hd, term_can_read, term_read, NULL);
-    monitor_start_input();
+    qemu_chr_add_event_handler(hd, term_event);
 }
 
 /* XXX: use threads ? */