bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU monitor |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 4 | * Copyright (c) 2003-2004 Fabrice Bellard |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 5 | * |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 24 | #include <dirent.h> |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 25 | #include "hw/hw.h" |
Gerd Hoffmann | cae4956 | 2009-06-05 15:53:17 +0100 | [diff] [blame] | 26 | #include "hw/qdev.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 27 | #include "hw/usb.h" |
| 28 | #include "hw/pcmcia.h" |
| 29 | #include "hw/pc.h" |
| 30 | #include "hw/pci.h" |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 31 | #include "hw/watchdog.h" |
Gerd Hoffmann | 45a50b1 | 2009-10-01 16:42:33 +0200 | [diff] [blame] | 32 | #include "hw/loader.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 33 | #include "gdbstub.h" |
| 34 | #include "net.h" |
| 35 | #include "qemu-char.h" |
| 36 | #include "sysemu.h" |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 37 | #include "monitor.h" |
| 38 | #include "readline.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 39 | #include "console.h" |
| 40 | #include "block.h" |
| 41 | #include "audio/audio.h" |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 42 | #include "disas.h" |
aliguori | df751fa | 2008-12-04 20:19:35 +0000 | [diff] [blame] | 43 | #include "balloon.h" |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 44 | #include "qemu-timer.h" |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 45 | #include "migration.h" |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 46 | #include "kvm.h" |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 47 | #include "acl.h" |
Luiz Capitulino | f7188bb | 2009-08-28 15:27:10 -0300 | [diff] [blame] | 48 | #include "qint.h" |
| 49 | #include "qdict.h" |
| 50 | #include "qstring.h" |
ths | 6a5bd30 | 2007-12-03 17:05:38 +0000 | [diff] [blame] | 51 | |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 52 | //#define DEBUG |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 53 | //#define DEBUG_COMPLETION |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 54 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 55 | /* |
| 56 | * Supported types: |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 57 | * |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 58 | * 'F' filename |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 59 | * 'B' block device name |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 60 | * 's' string (accept optional quote) |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 61 | * 'i' 32 bit integer |
| 62 | * 'l' target long (32 or 64 bit) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 63 | * '/' optional gdb-like print format (like "/10x") |
| 64 | * |
Luiz Capitulino | fb46660 | 2009-08-28 15:27:27 -0300 | [diff] [blame] | 65 | * '?' optional type (for all types, except '/') |
| 66 | * '.' other form of optional type (for 'i' and 'l') |
| 67 | * '-' optional parameter (eg. '-f') |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 68 | * |
| 69 | */ |
| 70 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 71 | typedef struct mon_cmd_t { |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 72 | const char *name; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 73 | const char *args_type; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 74 | const char *params; |
| 75 | const char *help; |
Luiz Capitulino | a2876f5 | 2009-10-07 13:41:53 -0300 | [diff] [blame] | 76 | void (*user_print)(Monitor *mon, const QObject *data); |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 77 | union { |
| 78 | void (*info)(Monitor *mon); |
Luiz Capitulino | af4ce88 | 2009-10-07 13:41:52 -0300 | [diff] [blame] | 79 | void (*cmd)(Monitor *mon, const QDict *qdict); |
Luiz Capitulino | 13917be | 2009-10-07 13:41:54 -0300 | [diff] [blame^] | 80 | void (*cmd_new)(Monitor *mon, const QDict *params, QObject **ret_data); |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 81 | } mhandler; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 82 | } mon_cmd_t; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 83 | |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 84 | /* file descriptors passed via SCM_RIGHTS */ |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 85 | typedef struct mon_fd_t mon_fd_t; |
| 86 | struct mon_fd_t { |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 87 | char *name; |
| 88 | int fd; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 89 | QLIST_ENTRY(mon_fd_t) next; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 90 | }; |
| 91 | |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 92 | struct Monitor { |
| 93 | CharDriverState *chr; |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 94 | int mux_out; |
| 95 | int reset_seen; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 96 | int flags; |
| 97 | int suspend_cnt; |
| 98 | uint8_t outbuf[1024]; |
| 99 | int outbuf_index; |
| 100 | ReadLineState *rs; |
| 101 | CPUState *mon_cpu; |
| 102 | BlockDriverCompletionFunc *password_completion_cb; |
| 103 | void *password_opaque; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 104 | QLIST_HEAD(,mon_fd_t) fds; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 105 | QLIST_ENTRY(Monitor) entry; |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 108 | static QLIST_HEAD(mon_list, Monitor) mon_list; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 109 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 110 | static const mon_cmd_t mon_cmds[]; |
| 111 | static const mon_cmd_t info_cmds[]; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 112 | |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 113 | Monitor *cur_mon = NULL; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 114 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 115 | static void monitor_command_cb(Monitor *mon, const char *cmdline, |
| 116 | void *opaque); |
aliguori | 83ab795 | 2008-08-19 14:44:22 +0000 | [diff] [blame] | 117 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 118 | static void monitor_read_command(Monitor *mon, int show_prompt) |
| 119 | { |
| 120 | readline_start(mon->rs, "(qemu) ", 0, monitor_command_cb, NULL); |
| 121 | if (show_prompt) |
| 122 | readline_show_prompt(mon->rs); |
| 123 | } |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 124 | |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 125 | static int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, |
| 126 | void *opaque) |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 127 | { |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 128 | if (mon->rs) { |
| 129 | readline_start(mon->rs, "Password: ", 1, readline_func, opaque); |
| 130 | /* prompt is printed on return from the command handler */ |
| 131 | return 0; |
| 132 | } else { |
| 133 | monitor_printf(mon, "terminal does not support password prompting\n"); |
| 134 | return -ENOTTY; |
| 135 | } |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 136 | } |
| 137 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 138 | void monitor_flush(Monitor *mon) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 139 | { |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 140 | if (mon && mon->outbuf_index != 0 && !mon->mux_out) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 141 | qemu_chr_write(mon->chr, mon->outbuf, mon->outbuf_index); |
| 142 | mon->outbuf_index = 0; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
| 146 | /* flush at every end of line or if the buffer is full */ |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 147 | static void monitor_puts(Monitor *mon, const char *str) |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 148 | { |
ths | 60fe76f | 2007-12-16 03:02:09 +0000 | [diff] [blame] | 149 | char c; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 150 | |
| 151 | if (!mon) |
| 152 | return; |
| 153 | |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 154 | for(;;) { |
| 155 | c = *str++; |
| 156 | if (c == '\0') |
| 157 | break; |
bellard | 7ba1260 | 2006-07-14 20:26:42 +0000 | [diff] [blame] | 158 | if (c == '\n') |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 159 | mon->outbuf[mon->outbuf_index++] = '\r'; |
| 160 | mon->outbuf[mon->outbuf_index++] = c; |
| 161 | if (mon->outbuf_index >= (sizeof(mon->outbuf) - 1) |
| 162 | || c == '\n') |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 163 | monitor_flush(mon); |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 167 | void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 168 | { |
| 169 | char buf[4096]; |
| 170 | vsnprintf(buf, sizeof(buf), fmt, ap); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 171 | monitor_puts(mon, buf); |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 172 | } |
| 173 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 174 | void monitor_printf(Monitor *mon, const char *fmt, ...) |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 175 | { |
| 176 | va_list ap; |
| 177 | va_start(ap, fmt); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 178 | monitor_vprintf(mon, fmt, ap); |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 179 | va_end(ap); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 180 | } |
| 181 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 182 | void monitor_print_filename(Monitor *mon, const char *filename) |
ths | fef3074 | 2006-12-22 14:11:32 +0000 | [diff] [blame] | 183 | { |
| 184 | int i; |
| 185 | |
| 186 | for (i = 0; filename[i]; i++) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 187 | switch (filename[i]) { |
| 188 | case ' ': |
| 189 | case '"': |
| 190 | case '\\': |
| 191 | monitor_printf(mon, "\\%c", filename[i]); |
| 192 | break; |
| 193 | case '\t': |
| 194 | monitor_printf(mon, "\\t"); |
| 195 | break; |
| 196 | case '\r': |
| 197 | monitor_printf(mon, "\\r"); |
| 198 | break; |
| 199 | case '\n': |
| 200 | monitor_printf(mon, "\\n"); |
| 201 | break; |
| 202 | default: |
| 203 | monitor_printf(mon, "%c", filename[i]); |
| 204 | break; |
| 205 | } |
ths | fef3074 | 2006-12-22 14:11:32 +0000 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 209 | static int monitor_fprintf(FILE *stream, const char *fmt, ...) |
| 210 | { |
| 211 | va_list ap; |
| 212 | va_start(ap, fmt); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 213 | monitor_vprintf((Monitor *)stream, fmt, ap); |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 214 | va_end(ap); |
| 215 | return 0; |
| 216 | } |
| 217 | |
Luiz Capitulino | 13917be | 2009-10-07 13:41:54 -0300 | [diff] [blame^] | 218 | static inline int monitor_handler_ported(const mon_cmd_t *cmd) |
| 219 | { |
| 220 | return cmd->user_print != NULL; |
| 221 | } |
| 222 | |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 223 | static int compare_cmd(const char *name, const char *list) |
| 224 | { |
| 225 | const char *p, *pstart; |
| 226 | int len; |
| 227 | len = strlen(name); |
| 228 | p = list; |
| 229 | for(;;) { |
| 230 | pstart = p; |
| 231 | p = strchr(p, '|'); |
| 232 | if (!p) |
| 233 | p = pstart + strlen(pstart); |
| 234 | if ((p - pstart) == len && !memcmp(pstart, name, len)) |
| 235 | return 1; |
| 236 | if (*p == '\0') |
| 237 | break; |
| 238 | p++; |
| 239 | } |
| 240 | return 0; |
| 241 | } |
| 242 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 243 | static void help_cmd_dump(Monitor *mon, const mon_cmd_t *cmds, |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 244 | const char *prefix, const char *name) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 245 | { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 246 | const mon_cmd_t *cmd; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 247 | |
| 248 | for(cmd = cmds; cmd->name != NULL; cmd++) { |
| 249 | if (!name || !strcmp(name, cmd->name)) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 250 | monitor_printf(mon, "%s%s %s -- %s\n", prefix, cmd->name, |
| 251 | cmd->params, cmd->help); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 255 | static void help_cmd(Monitor *mon, const char *name) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 256 | { |
| 257 | if (name && !strcmp(name, "info")) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 258 | help_cmd_dump(mon, info_cmds, "info ", NULL); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 259 | } else { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 260 | help_cmd_dump(mon, mon_cmds, "", name); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 261 | if (name && !strcmp(name, "log")) { |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 262 | const CPULogItem *item; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 263 | monitor_printf(mon, "Log items (comma separated):\n"); |
| 264 | monitor_printf(mon, "%-10s %s\n", "none", "remove all logs"); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 265 | for(item = cpu_log_items; item->mask != 0; item++) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 266 | monitor_printf(mon, "%-10s %s\n", item->name, item->help); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 267 | } |
| 268 | } |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 272 | static void do_help_cmd(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | 3818318 | 2009-08-28 15:27:08 -0300 | [diff] [blame] | 273 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 274 | help_cmd(mon, qdict_get_try_str(qdict, "name")); |
Luiz Capitulino | 3818318 | 2009-08-28 15:27:08 -0300 | [diff] [blame] | 275 | } |
| 276 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 277 | static void do_commit(Monitor *mon, const QDict *qdict) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 278 | { |
Gerd Hoffmann | 751c6a1 | 2009-07-22 16:42:57 +0200 | [diff] [blame] | 279 | int all_devices; |
| 280 | DriveInfo *dinfo; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 281 | const char *device = qdict_get_str(qdict, "device"); |
balrog | 2dc7b60 | 2007-05-24 18:53:22 +0000 | [diff] [blame] | 282 | |
bellard | 7954c73 | 2006-08-01 15:52:40 +0000 | [diff] [blame] | 283 | all_devices = !strcmp(device, "all"); |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 284 | QTAILQ_FOREACH(dinfo, &drives, next) { |
Gerd Hoffmann | 751c6a1 | 2009-07-22 16:42:57 +0200 | [diff] [blame] | 285 | if (!all_devices) |
Luiz Capitulino | 73006d2 | 2009-07-31 15:15:41 -0300 | [diff] [blame] | 286 | if (strcmp(bdrv_get_device_name(dinfo->bdrv), device)) |
Gerd Hoffmann | 751c6a1 | 2009-07-22 16:42:57 +0200 | [diff] [blame] | 287 | continue; |
| 288 | bdrv_commit(dinfo->bdrv); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 292 | static void do_info(Monitor *mon, const QDict *qdict) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 293 | { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 294 | const mon_cmd_t *cmd; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 295 | const char *item = qdict_get_try_str(qdict, "item"); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 296 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 297 | if (!item) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 298 | goto help; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 299 | for(cmd = info_cmds; cmd->name != NULL; cmd++) { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 300 | if (compare_cmd(item, cmd->name)) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 301 | goto found; |
| 302 | } |
| 303 | help: |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 304 | help_cmd(mon, "info"); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 305 | return; |
| 306 | found: |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 307 | cmd->mhandler.info(mon); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 308 | } |
| 309 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 310 | static void do_info_version(Monitor *mon) |
bellard | 9bc9d1c | 2004-10-10 15:15:51 +0000 | [diff] [blame] | 311 | { |
pbrook | 4a19f1e | 2009-04-07 23:17:49 +0000 | [diff] [blame] | 312 | monitor_printf(mon, "%s\n", QEMU_VERSION QEMU_PKGVERSION); |
bellard | 9bc9d1c | 2004-10-10 15:15:51 +0000 | [diff] [blame] | 313 | } |
| 314 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 315 | static void do_info_name(Monitor *mon) |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 316 | { |
| 317 | if (qemu_name) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 318 | monitor_printf(mon, "%s\n", qemu_name); |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 319 | } |
| 320 | |
aurel32 | bf4f74c | 2008-12-18 22:42:34 +0000 | [diff] [blame] | 321 | #if defined(TARGET_I386) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 322 | static void do_info_hpet(Monitor *mon) |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 323 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 324 | monitor_printf(mon, "HPET is %s by QEMU\n", |
| 325 | (no_hpet) ? "disabled" : "enabled"); |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 326 | } |
aurel32 | bf4f74c | 2008-12-18 22:42:34 +0000 | [diff] [blame] | 327 | #endif |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 328 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 329 | static void do_info_uuid(Monitor *mon) |
blueswir1 | f1f23ad | 2008-09-18 18:30:20 +0000 | [diff] [blame] | 330 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 331 | monitor_printf(mon, UUID_FMT "\n", qemu_uuid[0], qemu_uuid[1], |
| 332 | qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5], |
| 333 | qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9], |
| 334 | qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13], |
| 335 | qemu_uuid[14], qemu_uuid[15]); |
ths | a36e69d | 2007-12-02 05:18:19 +0000 | [diff] [blame] | 336 | } |
| 337 | |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 338 | /* get the current CPU defined by the user */ |
pbrook | 9596ebb | 2007-11-18 01:44:38 +0000 | [diff] [blame] | 339 | static int mon_set_cpu(int cpu_index) |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 340 | { |
| 341 | CPUState *env; |
| 342 | |
| 343 | for(env = first_cpu; env != NULL; env = env->next_cpu) { |
| 344 | if (env->cpu_index == cpu_index) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 345 | cur_mon->mon_cpu = env; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 346 | return 0; |
| 347 | } |
| 348 | } |
| 349 | return -1; |
| 350 | } |
| 351 | |
pbrook | 9596ebb | 2007-11-18 01:44:38 +0000 | [diff] [blame] | 352 | static CPUState *mon_get_cpu(void) |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 353 | { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 354 | if (!cur_mon->mon_cpu) { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 355 | mon_set_cpu(0); |
| 356 | } |
Avi Kivity | 4c0960c | 2009-08-17 23:19:53 +0300 | [diff] [blame] | 357 | cpu_synchronize_state(cur_mon->mon_cpu); |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 358 | return cur_mon->mon_cpu; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 359 | } |
| 360 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 361 | static void do_info_registers(Monitor *mon) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 362 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 363 | CPUState *env; |
| 364 | env = mon_get_cpu(); |
| 365 | if (!env) |
| 366 | return; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 367 | #ifdef TARGET_I386 |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 368 | cpu_dump_state(env, (FILE *)mon, monitor_fprintf, |
bellard | d24b15a | 2005-07-03 21:28:00 +0000 | [diff] [blame] | 369 | X86_DUMP_FPU); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 370 | #else |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 371 | cpu_dump_state(env, (FILE *)mon, monitor_fprintf, |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 372 | 0); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 373 | #endif |
| 374 | } |
| 375 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 376 | static void do_info_cpus(Monitor *mon) |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 377 | { |
| 378 | CPUState *env; |
| 379 | |
| 380 | /* just to set the default cpu if not already done */ |
| 381 | mon_get_cpu(); |
| 382 | |
| 383 | for(env = first_cpu; env != NULL; env = env->next_cpu) { |
Avi Kivity | 4c0960c | 2009-08-17 23:19:53 +0300 | [diff] [blame] | 384 | cpu_synchronize_state(env); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 385 | monitor_printf(mon, "%c CPU #%d:", |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 386 | (env == mon->mon_cpu) ? '*' : ' ', |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 387 | env->cpu_index); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 388 | #if defined(TARGET_I386) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 389 | monitor_printf(mon, " pc=0x" TARGET_FMT_lx, |
| 390 | env->eip + env->segs[R_CS].base); |
bellard | e80e1cc | 2005-11-23 22:05:28 +0000 | [diff] [blame] | 391 | #elif defined(TARGET_PPC) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 392 | monitor_printf(mon, " nip=0x" TARGET_FMT_lx, env->nip); |
bellard | ba3c64f | 2005-12-05 20:31:52 +0000 | [diff] [blame] | 393 | #elif defined(TARGET_SPARC) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 394 | monitor_printf(mon, " pc=0x" TARGET_FMT_lx " npc=0x" TARGET_FMT_lx, |
| 395 | env->pc, env->npc); |
ths | ead9360 | 2007-09-06 00:18:15 +0000 | [diff] [blame] | 396 | #elif defined(TARGET_MIPS) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 397 | monitor_printf(mon, " PC=0x" TARGET_FMT_lx, env->active_tc.PC); |
bellard | ce5232c | 2008-05-28 17:14:10 +0000 | [diff] [blame] | 398 | #endif |
ths | ead9360 | 2007-09-06 00:18:15 +0000 | [diff] [blame] | 399 | if (env->halted) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 400 | monitor_printf(mon, " (halted)"); |
| 401 | monitor_printf(mon, "\n"); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 405 | static void do_cpu_set(Monitor *mon, const QDict *qdict) |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 406 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 407 | int index = qdict_get_int(qdict, "index"); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 408 | if (mon_set_cpu(index) < 0) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 409 | monitor_printf(mon, "Invalid CPU index\n"); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 410 | } |
| 411 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 412 | static void do_info_jit(Monitor *mon) |
bellard | e3db722 | 2005-01-26 22:00:47 +0000 | [diff] [blame] | 413 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 414 | dump_exec_info((FILE *)mon, monitor_fprintf); |
bellard | e3db722 | 2005-01-26 22:00:47 +0000 | [diff] [blame] | 415 | } |
| 416 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 417 | static void do_info_history(Monitor *mon) |
bellard | aa45548 | 2004-04-04 13:07:25 +0000 | [diff] [blame] | 418 | { |
| 419 | int i; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 420 | const char *str; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 421 | |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 422 | if (!mon->rs) |
| 423 | return; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 424 | i = 0; |
| 425 | for(;;) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 426 | str = readline_get_history(mon->rs, i); |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 427 | if (!str) |
| 428 | break; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 429 | monitor_printf(mon, "%d: '%s'\n", i, str); |
bellard | 8e3a9fd | 2004-10-09 17:32:58 +0000 | [diff] [blame] | 430 | i++; |
bellard | aa45548 | 2004-04-04 13:07:25 +0000 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | |
j_mayer | 76a6625 | 2007-03-07 08:32:30 +0000 | [diff] [blame] | 434 | #if defined(TARGET_PPC) |
| 435 | /* XXX: not implemented in other targets */ |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 436 | static void do_info_cpu_stats(Monitor *mon) |
j_mayer | 76a6625 | 2007-03-07 08:32:30 +0000 | [diff] [blame] | 437 | { |
| 438 | CPUState *env; |
| 439 | |
| 440 | env = mon_get_cpu(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 441 | cpu_dump_statistics(env, (FILE *)mon, &monitor_fprintf, 0); |
j_mayer | 76a6625 | 2007-03-07 08:32:30 +0000 | [diff] [blame] | 442 | } |
| 443 | #endif |
| 444 | |
Luiz Capitulino | f96fc8a | 2009-08-28 15:27:12 -0300 | [diff] [blame] | 445 | static void do_quit(Monitor *mon, const QDict *qdict) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 446 | { |
| 447 | exit(0); |
| 448 | } |
| 449 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 450 | static int eject_device(Monitor *mon, BlockDriverState *bs, int force) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 451 | { |
| 452 | if (bdrv_is_inserted(bs)) { |
| 453 | if (!force) { |
| 454 | if (!bdrv_is_removable(bs)) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 455 | monitor_printf(mon, "device is not removable\n"); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 456 | return -1; |
| 457 | } |
| 458 | if (bdrv_is_locked(bs)) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 459 | monitor_printf(mon, "device is locked\n"); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 460 | return -1; |
| 461 | } |
| 462 | } |
| 463 | bdrv_close(bs); |
| 464 | } |
| 465 | return 0; |
| 466 | } |
| 467 | |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 468 | static void do_eject(Monitor *mon, const QDict *qdict) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 469 | { |
| 470 | BlockDriverState *bs; |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 471 | int force = qdict_get_int(qdict, "force"); |
| 472 | const char *filename = qdict_get_str(qdict, "filename"); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 473 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 474 | bs = bdrv_find(filename); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 475 | if (!bs) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 476 | monitor_printf(mon, "device not found\n"); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 477 | return; |
| 478 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 479 | eject_device(mon, bs, force); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 480 | } |
| 481 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 482 | static void do_change_block(Monitor *mon, const char *device, |
| 483 | const char *filename, const char *fmt) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 484 | { |
| 485 | BlockDriverState *bs; |
aurel32 | 2ecea9b | 2008-06-18 22:10:01 +0000 | [diff] [blame] | 486 | BlockDriver *drv = NULL; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 487 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 488 | bs = bdrv_find(device); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 489 | if (!bs) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 490 | monitor_printf(mon, "device not found\n"); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 491 | return; |
| 492 | } |
aurel32 | 2ecea9b | 2008-06-18 22:10:01 +0000 | [diff] [blame] | 493 | if (fmt) { |
| 494 | drv = bdrv_find_format(fmt); |
| 495 | if (!drv) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 496 | monitor_printf(mon, "invalid format %s\n", fmt); |
aurel32 | 2ecea9b | 2008-06-18 22:10:01 +0000 | [diff] [blame] | 497 | return; |
| 498 | } |
| 499 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 500 | if (eject_device(mon, bs, 0) < 0) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 501 | return; |
aurel32 | 2ecea9b | 2008-06-18 22:10:01 +0000 | [diff] [blame] | 502 | bdrv_open2(bs, filename, 0, drv); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 503 | monitor_read_bdrv_key_start(mon, bs, NULL, NULL); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 504 | } |
| 505 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 506 | static void change_vnc_password_cb(Monitor *mon, const char *password, |
| 507 | void *opaque) |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 508 | { |
| 509 | if (vnc_display_password(NULL, password) < 0) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 510 | monitor_printf(mon, "could not set VNC server password\n"); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 511 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 512 | monitor_read_command(mon, 1); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 513 | } |
| 514 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 515 | static void do_change_vnc(Monitor *mon, const char *target, const char *arg) |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 516 | { |
ths | 7084851 | 2007-08-25 01:37:05 +0000 | [diff] [blame] | 517 | if (strcmp(target, "passwd") == 0 || |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 518 | strcmp(target, "password") == 0) { |
| 519 | if (arg) { |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 520 | char password[9]; |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 521 | strncpy(password, arg, sizeof(password)); |
| 522 | password[sizeof(password) - 1] = '\0'; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 523 | change_vnc_password_cb(mon, password, NULL); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 524 | } else { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 525 | monitor_read_password(mon, change_vnc_password_cb, NULL); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 526 | } |
ths | 7084851 | 2007-08-25 01:37:05 +0000 | [diff] [blame] | 527 | } else { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 528 | if (vnc_display_open(NULL, target) < 0) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 529 | monitor_printf(mon, "could not start VNC server on %s\n", target); |
ths | 7084851 | 2007-08-25 01:37:05 +0000 | [diff] [blame] | 530 | } |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 533 | static void do_change(Monitor *mon, const QDict *qdict) |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 534 | { |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 535 | const char *device = qdict_get_str(qdict, "device"); |
| 536 | const char *target = qdict_get_str(qdict, "target"); |
| 537 | const char *arg = qdict_get_try_str(qdict, "arg"); |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 538 | if (strcmp(device, "vnc") == 0) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 539 | do_change_vnc(mon, target, arg); |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 540 | } else { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 541 | do_change_block(mon, device, target, arg); |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 545 | static void do_screen_dump(Monitor *mon, const QDict *qdict) |
bellard | 59a983b | 2004-03-17 23:17:16 +0000 | [diff] [blame] | 546 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 547 | vga_hw_screen_dump(qdict_get_str(qdict, "filename")); |
bellard | 59a983b | 2004-03-17 23:17:16 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 550 | static void do_logfile(Monitor *mon, const QDict *qdict) |
pbrook | e735b91 | 2007-06-30 13:53:24 +0000 | [diff] [blame] | 551 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 552 | cpu_set_log_filename(qdict_get_str(qdict, "filename")); |
pbrook | e735b91 | 2007-06-30 13:53:24 +0000 | [diff] [blame] | 553 | } |
| 554 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 555 | static void do_log(Monitor *mon, const QDict *qdict) |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 556 | { |
| 557 | int mask; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 558 | const char *items = qdict_get_str(qdict, "items"); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 559 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 560 | if (!strcmp(items, "none")) { |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 561 | mask = 0; |
| 562 | } else { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 563 | mask = cpu_str_to_log_mask(items); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 564 | if (!mask) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 565 | help_cmd(mon, "log"); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 566 | return; |
| 567 | } |
| 568 | } |
| 569 | cpu_set_log(mask); |
| 570 | } |
| 571 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 572 | static void do_singlestep(Monitor *mon, const QDict *qdict) |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 573 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 574 | const char *option = qdict_get_try_str(qdict, "option"); |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 575 | if (!option || !strcmp(option, "on")) { |
| 576 | singlestep = 1; |
| 577 | } else if (!strcmp(option, "off")) { |
| 578 | singlestep = 0; |
| 579 | } else { |
| 580 | monitor_printf(mon, "unexpected option %s\n", option); |
| 581 | } |
| 582 | } |
| 583 | |
Luiz Capitulino | f96fc8a | 2009-08-28 15:27:12 -0300 | [diff] [blame] | 584 | static void do_stop(Monitor *mon, const QDict *qdict) |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 585 | { |
| 586 | vm_stop(EXCP_INTERRUPT); |
| 587 | } |
| 588 | |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 589 | static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs); |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 590 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 591 | struct bdrv_iterate_context { |
| 592 | Monitor *mon; |
| 593 | int err; |
| 594 | }; |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 595 | |
Luiz Capitulino | f96fc8a | 2009-08-28 15:27:12 -0300 | [diff] [blame] | 596 | static void do_cont(Monitor *mon, const QDict *qdict) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 597 | { |
| 598 | struct bdrv_iterate_context context = { mon, 0 }; |
| 599 | |
| 600 | bdrv_iterate(encrypted_bdrv_it, &context); |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 601 | /* only resume the vm if all keys are set and valid */ |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 602 | if (!context.err) |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 603 | vm_start(); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 604 | } |
| 605 | |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 606 | static void bdrv_key_cb(void *opaque, int err) |
| 607 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 608 | Monitor *mon = opaque; |
| 609 | |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 610 | /* another key was set successfully, retry to continue */ |
| 611 | if (!err) |
Luiz Capitulino | f96fc8a | 2009-08-28 15:27:12 -0300 | [diff] [blame] | 612 | do_cont(mon, NULL); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs) |
| 616 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 617 | struct bdrv_iterate_context *context = opaque; |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 618 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 619 | if (!context->err && bdrv_key_required(bs)) { |
| 620 | context->err = -EBUSY; |
| 621 | monitor_read_bdrv_key_start(context->mon, bs, bdrv_key_cb, |
| 622 | context->mon); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 623 | } |
| 624 | } |
| 625 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 626 | static void do_gdbserver(Monitor *mon, const QDict *qdict) |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 627 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 628 | const char *device = qdict_get_try_str(qdict, "device"); |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 629 | if (!device) |
| 630 | device = "tcp::" DEFAULT_GDBSTUB_PORT; |
| 631 | if (gdbserver_start(device) < 0) { |
| 632 | monitor_printf(mon, "Could not open gdbserver on device '%s'\n", |
| 633 | device); |
| 634 | } else if (strcmp(device, "none") == 0) { |
aliguori | 36556b2 | 2009-03-28 18:05:53 +0000 | [diff] [blame] | 635 | monitor_printf(mon, "Disabled gdbserver\n"); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 636 | } else { |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 637 | monitor_printf(mon, "Waiting for gdb connection on device '%s'\n", |
| 638 | device); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 642 | static void do_watchdog_action(Monitor *mon, const QDict *qdict) |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 643 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 644 | const char *action = qdict_get_str(qdict, "action"); |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 645 | if (select_watchdog_action(action) == -1) { |
| 646 | monitor_printf(mon, "Unknown watchdog action '%s'\n", action); |
| 647 | } |
| 648 | } |
| 649 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 650 | static void monitor_printc(Monitor *mon, int c) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 651 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 652 | monitor_printf(mon, "'"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 653 | switch(c) { |
| 654 | case '\'': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 655 | monitor_printf(mon, "\\'"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 656 | break; |
| 657 | case '\\': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 658 | monitor_printf(mon, "\\\\"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 659 | break; |
| 660 | case '\n': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 661 | monitor_printf(mon, "\\n"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 662 | break; |
| 663 | case '\r': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 664 | monitor_printf(mon, "\\r"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 665 | break; |
| 666 | default: |
| 667 | if (c >= 32 && c <= 126) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 668 | monitor_printf(mon, "%c", c); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 669 | } else { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 670 | monitor_printf(mon, "\\x%02x", c); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 671 | } |
| 672 | break; |
| 673 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 674 | monitor_printf(mon, "'"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 675 | } |
| 676 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 677 | static void memory_dump(Monitor *mon, int count, int format, int wsize, |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 678 | target_phys_addr_t addr, int is_physical) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 679 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 680 | CPUState *env; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 681 | int nb_per_line, l, line_size, i, max_digits, len; |
| 682 | uint8_t buf[16]; |
| 683 | uint64_t v; |
| 684 | |
| 685 | if (format == 'i') { |
| 686 | int flags; |
| 687 | flags = 0; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 688 | env = mon_get_cpu(); |
| 689 | if (!env && !is_physical) |
| 690 | return; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 691 | #ifdef TARGET_I386 |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 692 | if (wsize == 2) { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 693 | flags = 1; |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 694 | } else if (wsize == 4) { |
| 695 | flags = 0; |
| 696 | } else { |
bellard | 6a15fd1 | 2006-04-12 21:07:07 +0000 | [diff] [blame] | 697 | /* as default we use the current CS size */ |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 698 | flags = 0; |
bellard | 6a15fd1 | 2006-04-12 21:07:07 +0000 | [diff] [blame] | 699 | if (env) { |
| 700 | #ifdef TARGET_X86_64 |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 701 | if ((env->efer & MSR_EFER_LMA) && |
bellard | 6a15fd1 | 2006-04-12 21:07:07 +0000 | [diff] [blame] | 702 | (env->segs[R_CS].flags & DESC_L_MASK)) |
| 703 | flags = 2; |
| 704 | else |
| 705 | #endif |
| 706 | if (!(env->segs[R_CS].flags & DESC_B_MASK)) |
| 707 | flags = 1; |
| 708 | } |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 709 | } |
| 710 | #endif |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 711 | monitor_disas(mon, env, addr, count, is_physical, flags); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 712 | return; |
| 713 | } |
| 714 | |
| 715 | len = wsize * count; |
| 716 | if (wsize == 1) |
| 717 | line_size = 8; |
| 718 | else |
| 719 | line_size = 16; |
| 720 | nb_per_line = line_size / wsize; |
| 721 | max_digits = 0; |
| 722 | |
| 723 | switch(format) { |
| 724 | case 'o': |
| 725 | max_digits = (wsize * 8 + 2) / 3; |
| 726 | break; |
| 727 | default: |
| 728 | case 'x': |
| 729 | max_digits = (wsize * 8) / 4; |
| 730 | break; |
| 731 | case 'u': |
| 732 | case 'd': |
| 733 | max_digits = (wsize * 8 * 10 + 32) / 33; |
| 734 | break; |
| 735 | case 'c': |
| 736 | wsize = 1; |
| 737 | break; |
| 738 | } |
| 739 | |
| 740 | while (len > 0) { |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 741 | if (is_physical) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 742 | monitor_printf(mon, TARGET_FMT_plx ":", addr); |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 743 | else |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 744 | monitor_printf(mon, TARGET_FMT_lx ":", (target_ulong)addr); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 745 | l = len; |
| 746 | if (l > line_size) |
| 747 | l = line_size; |
| 748 | if (is_physical) { |
| 749 | cpu_physical_memory_rw(addr, buf, l, 0); |
| 750 | } else { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 751 | env = mon_get_cpu(); |
| 752 | if (!env) |
| 753 | break; |
aliguori | c8f79b6 | 2008-08-18 14:00:20 +0000 | [diff] [blame] | 754 | if (cpu_memory_rw_debug(env, addr, buf, l, 0) < 0) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 755 | monitor_printf(mon, " Cannot access memory\n"); |
aliguori | c8f79b6 | 2008-08-18 14:00:20 +0000 | [diff] [blame] | 756 | break; |
| 757 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 758 | } |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 759 | i = 0; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 760 | while (i < l) { |
| 761 | switch(wsize) { |
| 762 | default: |
| 763 | case 1: |
| 764 | v = ldub_raw(buf + i); |
| 765 | break; |
| 766 | case 2: |
| 767 | v = lduw_raw(buf + i); |
| 768 | break; |
| 769 | case 4: |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 770 | v = (uint32_t)ldl_raw(buf + i); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 771 | break; |
| 772 | case 8: |
| 773 | v = ldq_raw(buf + i); |
| 774 | break; |
| 775 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 776 | monitor_printf(mon, " "); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 777 | switch(format) { |
| 778 | case 'o': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 779 | monitor_printf(mon, "%#*" PRIo64, max_digits, v); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 780 | break; |
| 781 | case 'x': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 782 | monitor_printf(mon, "0x%0*" PRIx64, max_digits, v); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 783 | break; |
| 784 | case 'u': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 785 | monitor_printf(mon, "%*" PRIu64, max_digits, v); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 786 | break; |
| 787 | case 'd': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 788 | monitor_printf(mon, "%*" PRId64, max_digits, v); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 789 | break; |
| 790 | case 'c': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 791 | monitor_printc(mon, v); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 792 | break; |
| 793 | } |
| 794 | i += wsize; |
| 795 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 796 | monitor_printf(mon, "\n"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 797 | addr += l; |
| 798 | len -= l; |
| 799 | } |
| 800 | } |
| 801 | |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 802 | static void do_memory_dump(Monitor *mon, const QDict *qdict) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 803 | { |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 804 | int count = qdict_get_int(qdict, "count"); |
| 805 | int format = qdict_get_int(qdict, "format"); |
| 806 | int size = qdict_get_int(qdict, "size"); |
| 807 | target_long addr = qdict_get_int(qdict, "addr"); |
| 808 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 809 | memory_dump(mon, count, format, size, addr, 0); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 812 | static void do_physical_memory_dump(Monitor *mon, const QDict *qdict) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 813 | { |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 814 | int count = qdict_get_int(qdict, "count"); |
| 815 | int format = qdict_get_int(qdict, "format"); |
| 816 | int size = qdict_get_int(qdict, "size"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 817 | target_phys_addr_t addr = qdict_get_int(qdict, "addr"); |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 818 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 819 | memory_dump(mon, count, format, size, addr, 1); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 820 | } |
| 821 | |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 822 | static void do_print(Monitor *mon, const QDict *qdict) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 823 | { |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 824 | int format = qdict_get_int(qdict, "format"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 825 | target_phys_addr_t val = qdict_get_int(qdict, "val"); |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 826 | |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 827 | #if TARGET_PHYS_ADDR_BITS == 32 |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 828 | switch(format) { |
| 829 | case 'o': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 830 | monitor_printf(mon, "%#o", val); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 831 | break; |
| 832 | case 'x': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 833 | monitor_printf(mon, "%#x", val); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 834 | break; |
| 835 | case 'u': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 836 | monitor_printf(mon, "%u", val); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 837 | break; |
| 838 | default: |
| 839 | case 'd': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 840 | monitor_printf(mon, "%d", val); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 841 | break; |
| 842 | case 'c': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 843 | monitor_printc(mon, val); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 844 | break; |
| 845 | } |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 846 | #else |
| 847 | switch(format) { |
| 848 | case 'o': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 849 | monitor_printf(mon, "%#" PRIo64, val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 850 | break; |
| 851 | case 'x': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 852 | monitor_printf(mon, "%#" PRIx64, val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 853 | break; |
| 854 | case 'u': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 855 | monitor_printf(mon, "%" PRIu64, val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 856 | break; |
| 857 | default: |
| 858 | case 'd': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 859 | monitor_printf(mon, "%" PRId64, val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 860 | break; |
| 861 | case 'c': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 862 | monitor_printc(mon, val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 863 | break; |
| 864 | } |
| 865 | #endif |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 866 | monitor_printf(mon, "\n"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 867 | } |
| 868 | |
Luiz Capitulino | afe67ef | 2009-08-28 15:27:16 -0300 | [diff] [blame] | 869 | static void do_memory_save(Monitor *mon, const QDict *qdict) |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 870 | { |
| 871 | FILE *f; |
Luiz Capitulino | afe67ef | 2009-08-28 15:27:16 -0300 | [diff] [blame] | 872 | uint32_t size = qdict_get_int(qdict, "size"); |
| 873 | const char *filename = qdict_get_str(qdict, "filename"); |
| 874 | target_long addr = qdict_get_int(qdict, "val"); |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 875 | uint32_t l; |
| 876 | CPUState *env; |
| 877 | uint8_t buf[1024]; |
| 878 | |
| 879 | env = mon_get_cpu(); |
| 880 | if (!env) |
| 881 | return; |
| 882 | |
| 883 | f = fopen(filename, "wb"); |
| 884 | if (!f) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 885 | monitor_printf(mon, "could not open '%s'\n", filename); |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 886 | return; |
| 887 | } |
| 888 | while (size != 0) { |
| 889 | l = sizeof(buf); |
| 890 | if (l > size) |
| 891 | l = size; |
| 892 | cpu_memory_rw_debug(env, addr, buf, l, 0); |
| 893 | fwrite(buf, 1, l, f); |
| 894 | addr += l; |
| 895 | size -= l; |
| 896 | } |
| 897 | fclose(f); |
| 898 | } |
| 899 | |
Luiz Capitulino | afe67ef | 2009-08-28 15:27:16 -0300 | [diff] [blame] | 900 | static void do_physical_memory_save(Monitor *mon, const QDict *qdict) |
aurel32 | a8bdf7a | 2008-04-11 21:36:14 +0000 | [diff] [blame] | 901 | { |
| 902 | FILE *f; |
| 903 | uint32_t l; |
| 904 | uint8_t buf[1024]; |
Luiz Capitulino | afe67ef | 2009-08-28 15:27:16 -0300 | [diff] [blame] | 905 | uint32_t size = qdict_get_int(qdict, "size"); |
| 906 | const char *filename = qdict_get_str(qdict, "filename"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 907 | target_phys_addr_t addr = qdict_get_int(qdict, "val"); |
aurel32 | a8bdf7a | 2008-04-11 21:36:14 +0000 | [diff] [blame] | 908 | |
| 909 | f = fopen(filename, "wb"); |
| 910 | if (!f) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 911 | monitor_printf(mon, "could not open '%s'\n", filename); |
aurel32 | a8bdf7a | 2008-04-11 21:36:14 +0000 | [diff] [blame] | 912 | return; |
| 913 | } |
| 914 | while (size != 0) { |
| 915 | l = sizeof(buf); |
| 916 | if (l > size) |
| 917 | l = size; |
| 918 | cpu_physical_memory_rw(addr, buf, l, 0); |
| 919 | fwrite(buf, 1, l, f); |
| 920 | fflush(f); |
| 921 | addr += l; |
| 922 | size -= l; |
| 923 | } |
| 924 | fclose(f); |
| 925 | } |
| 926 | |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 927 | static void do_sum(Monitor *mon, const QDict *qdict) |
bellard | e4cf1ad | 2005-06-04 20:15:57 +0000 | [diff] [blame] | 928 | { |
| 929 | uint32_t addr; |
| 930 | uint8_t buf[1]; |
| 931 | uint16_t sum; |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 932 | uint32_t start = qdict_get_int(qdict, "start"); |
| 933 | uint32_t size = qdict_get_int(qdict, "size"); |
bellard | e4cf1ad | 2005-06-04 20:15:57 +0000 | [diff] [blame] | 934 | |
| 935 | sum = 0; |
| 936 | for(addr = start; addr < (start + size); addr++) { |
| 937 | cpu_physical_memory_rw(addr, buf, 1, 0); |
| 938 | /* BSD sum algorithm ('sum' Unix command) */ |
| 939 | sum = (sum >> 1) | (sum << 15); |
| 940 | sum += buf[0]; |
| 941 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 942 | monitor_printf(mon, "%05d\n", sum); |
bellard | e4cf1ad | 2005-06-04 20:15:57 +0000 | [diff] [blame] | 943 | } |
| 944 | |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 945 | typedef struct { |
| 946 | int keycode; |
| 947 | const char *name; |
| 948 | } KeyDef; |
| 949 | |
| 950 | static const KeyDef key_defs[] = { |
| 951 | { 0x2a, "shift" }, |
| 952 | { 0x36, "shift_r" }, |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 953 | |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 954 | { 0x38, "alt" }, |
| 955 | { 0xb8, "alt_r" }, |
ths | 2ba27c7 | 2008-08-13 12:54:23 +0000 | [diff] [blame] | 956 | { 0x64, "altgr" }, |
| 957 | { 0xe4, "altgr_r" }, |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 958 | { 0x1d, "ctrl" }, |
| 959 | { 0x9d, "ctrl_r" }, |
| 960 | |
| 961 | { 0xdd, "menu" }, |
| 962 | |
| 963 | { 0x01, "esc" }, |
| 964 | |
| 965 | { 0x02, "1" }, |
| 966 | { 0x03, "2" }, |
| 967 | { 0x04, "3" }, |
| 968 | { 0x05, "4" }, |
| 969 | { 0x06, "5" }, |
| 970 | { 0x07, "6" }, |
| 971 | { 0x08, "7" }, |
| 972 | { 0x09, "8" }, |
| 973 | { 0x0a, "9" }, |
| 974 | { 0x0b, "0" }, |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 975 | { 0x0c, "minus" }, |
| 976 | { 0x0d, "equal" }, |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 977 | { 0x0e, "backspace" }, |
| 978 | |
| 979 | { 0x0f, "tab" }, |
| 980 | { 0x10, "q" }, |
| 981 | { 0x11, "w" }, |
| 982 | { 0x12, "e" }, |
| 983 | { 0x13, "r" }, |
| 984 | { 0x14, "t" }, |
| 985 | { 0x15, "y" }, |
| 986 | { 0x16, "u" }, |
| 987 | { 0x17, "i" }, |
| 988 | { 0x18, "o" }, |
| 989 | { 0x19, "p" }, |
| 990 | |
| 991 | { 0x1c, "ret" }, |
| 992 | |
| 993 | { 0x1e, "a" }, |
| 994 | { 0x1f, "s" }, |
| 995 | { 0x20, "d" }, |
| 996 | { 0x21, "f" }, |
| 997 | { 0x22, "g" }, |
| 998 | { 0x23, "h" }, |
| 999 | { 0x24, "j" }, |
| 1000 | { 0x25, "k" }, |
| 1001 | { 0x26, "l" }, |
| 1002 | |
| 1003 | { 0x2c, "z" }, |
| 1004 | { 0x2d, "x" }, |
| 1005 | { 0x2e, "c" }, |
| 1006 | { 0x2f, "v" }, |
| 1007 | { 0x30, "b" }, |
| 1008 | { 0x31, "n" }, |
| 1009 | { 0x32, "m" }, |
aurel32 | 9155fc4 | 2008-10-01 21:46:15 +0000 | [diff] [blame] | 1010 | { 0x33, "comma" }, |
| 1011 | { 0x34, "dot" }, |
| 1012 | { 0x35, "slash" }, |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1013 | |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 1014 | { 0x37, "asterisk" }, |
| 1015 | |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1016 | { 0x39, "spc" }, |
bellard | 00ffa62 | 2004-06-04 13:25:15 +0000 | [diff] [blame] | 1017 | { 0x3a, "caps_lock" }, |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1018 | { 0x3b, "f1" }, |
| 1019 | { 0x3c, "f2" }, |
| 1020 | { 0x3d, "f3" }, |
| 1021 | { 0x3e, "f4" }, |
| 1022 | { 0x3f, "f5" }, |
| 1023 | { 0x40, "f6" }, |
| 1024 | { 0x41, "f7" }, |
| 1025 | { 0x42, "f8" }, |
| 1026 | { 0x43, "f9" }, |
| 1027 | { 0x44, "f10" }, |
bellard | 00ffa62 | 2004-06-04 13:25:15 +0000 | [diff] [blame] | 1028 | { 0x45, "num_lock" }, |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1029 | { 0x46, "scroll_lock" }, |
| 1030 | |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1031 | { 0xb5, "kp_divide" }, |
| 1032 | { 0x37, "kp_multiply" }, |
ths | 0cfec83 | 2007-06-23 16:02:43 +0000 | [diff] [blame] | 1033 | { 0x4a, "kp_subtract" }, |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1034 | { 0x4e, "kp_add" }, |
| 1035 | { 0x9c, "kp_enter" }, |
| 1036 | { 0x53, "kp_decimal" }, |
balrog | f2289cb | 2008-06-04 10:14:16 +0000 | [diff] [blame] | 1037 | { 0x54, "sysrq" }, |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1038 | |
| 1039 | { 0x52, "kp_0" }, |
| 1040 | { 0x4f, "kp_1" }, |
| 1041 | { 0x50, "kp_2" }, |
| 1042 | { 0x51, "kp_3" }, |
| 1043 | { 0x4b, "kp_4" }, |
| 1044 | { 0x4c, "kp_5" }, |
| 1045 | { 0x4d, "kp_6" }, |
| 1046 | { 0x47, "kp_7" }, |
| 1047 | { 0x48, "kp_8" }, |
| 1048 | { 0x49, "kp_9" }, |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1049 | |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1050 | { 0x56, "<" }, |
| 1051 | |
| 1052 | { 0x57, "f11" }, |
| 1053 | { 0x58, "f12" }, |
| 1054 | |
| 1055 | { 0xb7, "print" }, |
| 1056 | |
| 1057 | { 0xc7, "home" }, |
| 1058 | { 0xc9, "pgup" }, |
| 1059 | { 0xd1, "pgdn" }, |
| 1060 | { 0xcf, "end" }, |
| 1061 | |
| 1062 | { 0xcb, "left" }, |
| 1063 | { 0xc8, "up" }, |
| 1064 | { 0xd0, "down" }, |
| 1065 | { 0xcd, "right" }, |
| 1066 | |
| 1067 | { 0xd2, "insert" }, |
| 1068 | { 0xd3, "delete" }, |
blueswir1 | c0b5b10 | 2008-06-22 07:45:42 +0000 | [diff] [blame] | 1069 | #if defined(TARGET_SPARC) && !defined(TARGET_SPARC64) |
| 1070 | { 0xf0, "stop" }, |
| 1071 | { 0xf1, "again" }, |
| 1072 | { 0xf2, "props" }, |
| 1073 | { 0xf3, "undo" }, |
| 1074 | { 0xf4, "front" }, |
| 1075 | { 0xf5, "copy" }, |
| 1076 | { 0xf6, "open" }, |
| 1077 | { 0xf7, "paste" }, |
| 1078 | { 0xf8, "find" }, |
| 1079 | { 0xf9, "cut" }, |
| 1080 | { 0xfa, "lf" }, |
| 1081 | { 0xfb, "help" }, |
| 1082 | { 0xfc, "meta_l" }, |
| 1083 | { 0xfd, "meta_r" }, |
| 1084 | { 0xfe, "compose" }, |
| 1085 | #endif |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1086 | { 0, NULL }, |
| 1087 | }; |
| 1088 | |
| 1089 | static int get_keycode(const char *key) |
| 1090 | { |
| 1091 | const KeyDef *p; |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1092 | char *endp; |
| 1093 | int ret; |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1094 | |
| 1095 | for(p = key_defs; p->name != NULL; p++) { |
| 1096 | if (!strcmp(key, p->name)) |
| 1097 | return p->keycode; |
| 1098 | } |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1099 | if (strstart(key, "0x", NULL)) { |
| 1100 | ret = strtoul(key, &endp, 0); |
| 1101 | if (*endp == '\0' && ret >= 0x01 && ret <= 0xff) |
| 1102 | return ret; |
| 1103 | } |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1104 | return -1; |
| 1105 | } |
| 1106 | |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1107 | #define MAX_KEYCODES 16 |
| 1108 | static uint8_t keycodes[MAX_KEYCODES]; |
| 1109 | static int nb_pending_keycodes; |
| 1110 | static QEMUTimer *key_timer; |
| 1111 | |
| 1112 | static void release_keys(void *opaque) |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1113 | { |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1114 | int keycode; |
| 1115 | |
| 1116 | while (nb_pending_keycodes > 0) { |
| 1117 | nb_pending_keycodes--; |
| 1118 | keycode = keycodes[nb_pending_keycodes]; |
| 1119 | if (keycode & 0x80) |
| 1120 | kbd_put_keycode(0xe0); |
| 1121 | kbd_put_keycode(keycode | 0x80); |
| 1122 | } |
| 1123 | } |
| 1124 | |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 1125 | static void do_sendkey(Monitor *mon, const QDict *qdict) |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1126 | { |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1127 | char keyname_buf[16]; |
| 1128 | char *separator; |
| 1129 | int keyname_len, keycode, i; |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 1130 | const char *string = qdict_get_str(qdict, "string"); |
| 1131 | int has_hold_time = qdict_haskey(qdict, "hold_time"); |
| 1132 | int hold_time = qdict_get_try_int(qdict, "hold_time", -1); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1133 | |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1134 | if (nb_pending_keycodes > 0) { |
| 1135 | qemu_del_timer(key_timer); |
| 1136 | release_keys(NULL); |
| 1137 | } |
| 1138 | if (!has_hold_time) |
| 1139 | hold_time = 100; |
| 1140 | i = 0; |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1141 | while (1) { |
| 1142 | separator = strchr(string, '-'); |
| 1143 | keyname_len = separator ? separator - string : strlen(string); |
| 1144 | if (keyname_len > 0) { |
| 1145 | pstrcpy(keyname_buf, sizeof(keyname_buf), string); |
| 1146 | if (keyname_len > sizeof(keyname_buf) - 1) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1147 | monitor_printf(mon, "invalid key: '%s...'\n", keyname_buf); |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1148 | return; |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1149 | } |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1150 | if (i == MAX_KEYCODES) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1151 | monitor_printf(mon, "too many keys\n"); |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1152 | return; |
| 1153 | } |
| 1154 | keyname_buf[keyname_len] = 0; |
| 1155 | keycode = get_keycode(keyname_buf); |
| 1156 | if (keycode < 0) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1157 | monitor_printf(mon, "unknown key: '%s'\n", keyname_buf); |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1158 | return; |
| 1159 | } |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1160 | keycodes[i++] = keycode; |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1161 | } |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1162 | if (!separator) |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1163 | break; |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1164 | string = separator + 1; |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1165 | } |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1166 | nb_pending_keycodes = i; |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1167 | /* key down events */ |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1168 | for (i = 0; i < nb_pending_keycodes; i++) { |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1169 | keycode = keycodes[i]; |
| 1170 | if (keycode & 0x80) |
| 1171 | kbd_put_keycode(0xe0); |
| 1172 | kbd_put_keycode(keycode & 0x7f); |
| 1173 | } |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1174 | /* delayed key up events */ |
balrog | f227f17 | 2008-06-09 00:03:47 +0000 | [diff] [blame] | 1175 | qemu_mod_timer(key_timer, qemu_get_clock(vm_clock) + |
Juan Quintela | 6ee093c | 2009-09-10 03:04:26 +0200 | [diff] [blame] | 1176 | muldiv64(get_ticks_per_sec(), hold_time, 1000)); |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1179 | static int mouse_button_state; |
| 1180 | |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 1181 | static void do_mouse_move(Monitor *mon, const QDict *qdict) |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1182 | { |
| 1183 | int dx, dy, dz; |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 1184 | const char *dx_str = qdict_get_str(qdict, "dx_str"); |
| 1185 | const char *dy_str = qdict_get_str(qdict, "dy_str"); |
| 1186 | const char *dz_str = qdict_get_try_str(qdict, "dz_str"); |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1187 | dx = strtol(dx_str, NULL, 0); |
| 1188 | dy = strtol(dy_str, NULL, 0); |
| 1189 | dz = 0; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1190 | if (dz_str) |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1191 | dz = strtol(dz_str, NULL, 0); |
| 1192 | kbd_mouse_event(dx, dy, dz, mouse_button_state); |
| 1193 | } |
| 1194 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1195 | static void do_mouse_button(Monitor *mon, const QDict *qdict) |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1196 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1197 | int button_state = qdict_get_int(qdict, "button_state"); |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1198 | mouse_button_state = button_state; |
| 1199 | kbd_mouse_event(0, 0, 0, mouse_button_state); |
| 1200 | } |
| 1201 | |
Luiz Capitulino | aa93e39 | 2009-08-28 15:27:18 -0300 | [diff] [blame] | 1202 | static void do_ioport_read(Monitor *mon, const QDict *qdict) |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1203 | { |
Luiz Capitulino | aa93e39 | 2009-08-28 15:27:18 -0300 | [diff] [blame] | 1204 | int size = qdict_get_int(qdict, "size"); |
| 1205 | int addr = qdict_get_int(qdict, "addr"); |
| 1206 | int has_index = qdict_haskey(qdict, "index"); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1207 | uint32_t val; |
| 1208 | int suffix; |
| 1209 | |
| 1210 | if (has_index) { |
Luiz Capitulino | aa93e39 | 2009-08-28 15:27:18 -0300 | [diff] [blame] | 1211 | int index = qdict_get_int(qdict, "index"); |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1212 | cpu_outb(addr & IOPORTS_MASK, index & 0xff); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1213 | addr++; |
| 1214 | } |
| 1215 | addr &= 0xffff; |
| 1216 | |
| 1217 | switch(size) { |
| 1218 | default: |
| 1219 | case 1: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1220 | val = cpu_inb(addr); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1221 | suffix = 'b'; |
| 1222 | break; |
| 1223 | case 2: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1224 | val = cpu_inw(addr); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1225 | suffix = 'w'; |
| 1226 | break; |
| 1227 | case 4: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1228 | val = cpu_inl(addr); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1229 | suffix = 'l'; |
| 1230 | break; |
| 1231 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1232 | monitor_printf(mon, "port%c[0x%04x] = %#0*x\n", |
| 1233 | suffix, addr, size * 2, val); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1234 | } |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1235 | |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1236 | static void do_ioport_write(Monitor *mon, const QDict *qdict) |
Jan Kiszka | f114784 | 2009-07-14 10:20:11 +0200 | [diff] [blame] | 1237 | { |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1238 | int size = qdict_get_int(qdict, "size"); |
| 1239 | int addr = qdict_get_int(qdict, "addr"); |
| 1240 | int val = qdict_get_int(qdict, "val"); |
| 1241 | |
Jan Kiszka | f114784 | 2009-07-14 10:20:11 +0200 | [diff] [blame] | 1242 | addr &= IOPORTS_MASK; |
| 1243 | |
| 1244 | switch (size) { |
| 1245 | default: |
| 1246 | case 1: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1247 | cpu_outb(addr, val); |
Jan Kiszka | f114784 | 2009-07-14 10:20:11 +0200 | [diff] [blame] | 1248 | break; |
| 1249 | case 2: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1250 | cpu_outw(addr, val); |
Jan Kiszka | f114784 | 2009-07-14 10:20:11 +0200 | [diff] [blame] | 1251 | break; |
| 1252 | case 4: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1253 | cpu_outl(addr, val); |
Jan Kiszka | f114784 | 2009-07-14 10:20:11 +0200 | [diff] [blame] | 1254 | break; |
| 1255 | } |
| 1256 | } |
| 1257 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1258 | static void do_boot_set(Monitor *mon, const QDict *qdict) |
aurel32 | 0ecdffb | 2008-05-04 20:11:34 +0000 | [diff] [blame] | 1259 | { |
| 1260 | int res; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1261 | const char *bootdevice = qdict_get_str(qdict, "bootdevice"); |
aurel32 | 0ecdffb | 2008-05-04 20:11:34 +0000 | [diff] [blame] | 1262 | |
Jan Kiszka | 76e30d0 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1263 | res = qemu_boot_set(bootdevice); |
| 1264 | if (res == 0) { |
| 1265 | monitor_printf(mon, "boot device list now set to %s\n", bootdevice); |
| 1266 | } else if (res > 0) { |
| 1267 | monitor_printf(mon, "setting boot device list failed\n"); |
aurel32 | 0ecdffb | 2008-05-04 20:11:34 +0000 | [diff] [blame] | 1268 | } else { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1269 | monitor_printf(mon, "no function defined to set boot device list for " |
| 1270 | "this architecture\n"); |
aurel32 | 0ecdffb | 2008-05-04 20:11:34 +0000 | [diff] [blame] | 1271 | } |
| 1272 | } |
| 1273 | |
Luiz Capitulino | f96fc8a | 2009-08-28 15:27:12 -0300 | [diff] [blame] | 1274 | static void do_system_reset(Monitor *mon, const QDict *qdict) |
bellard | e4f9082 | 2004-06-20 12:35:44 +0000 | [diff] [blame] | 1275 | { |
| 1276 | qemu_system_reset_request(); |
| 1277 | } |
| 1278 | |
Luiz Capitulino | f96fc8a | 2009-08-28 15:27:12 -0300 | [diff] [blame] | 1279 | static void do_system_powerdown(Monitor *mon, const QDict *qdict) |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 1280 | { |
| 1281 | qemu_system_powerdown_request(); |
| 1282 | } |
| 1283 | |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1284 | #if defined(TARGET_I386) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1285 | static void print_pte(Monitor *mon, uint32_t addr, uint32_t pte, uint32_t mask) |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1286 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1287 | monitor_printf(mon, "%08x: %08x %c%c%c%c%c%c%c%c\n", |
| 1288 | addr, |
| 1289 | pte & mask, |
| 1290 | pte & PG_GLOBAL_MASK ? 'G' : '-', |
| 1291 | pte & PG_PSE_MASK ? 'P' : '-', |
| 1292 | pte & PG_DIRTY_MASK ? 'D' : '-', |
| 1293 | pte & PG_ACCESSED_MASK ? 'A' : '-', |
| 1294 | pte & PG_PCD_MASK ? 'C' : '-', |
| 1295 | pte & PG_PWT_MASK ? 'T' : '-', |
| 1296 | pte & PG_USER_MASK ? 'U' : '-', |
| 1297 | pte & PG_RW_MASK ? 'W' : '-'); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1300 | static void tlb_info(Monitor *mon) |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1301 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1302 | CPUState *env; |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1303 | int l1, l2; |
| 1304 | uint32_t pgd, pde, pte; |
| 1305 | |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1306 | env = mon_get_cpu(); |
| 1307 | if (!env) |
| 1308 | return; |
| 1309 | |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1310 | if (!(env->cr[0] & CR0_PG_MASK)) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1311 | monitor_printf(mon, "PG disabled\n"); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1312 | return; |
| 1313 | } |
| 1314 | pgd = env->cr[3] & ~0xfff; |
| 1315 | for(l1 = 0; l1 < 1024; l1++) { |
| 1316 | cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4); |
| 1317 | pde = le32_to_cpu(pde); |
| 1318 | if (pde & PG_PRESENT_MASK) { |
| 1319 | if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1320 | print_pte(mon, (l1 << 22), pde, ~((1 << 20) - 1)); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1321 | } else { |
| 1322 | for(l2 = 0; l2 < 1024; l2++) { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1323 | cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1324 | (uint8_t *)&pte, 4); |
| 1325 | pte = le32_to_cpu(pte); |
| 1326 | if (pte & PG_PRESENT_MASK) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1327 | print_pte(mon, (l1 << 22) + (l2 << 12), |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1328 | pte & ~PG_PSE_MASK, |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1329 | ~0xfff); |
| 1330 | } |
| 1331 | } |
| 1332 | } |
| 1333 | } |
| 1334 | } |
| 1335 | } |
| 1336 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1337 | static void mem_print(Monitor *mon, uint32_t *pstart, int *plast_prot, |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1338 | uint32_t end, int prot) |
| 1339 | { |
bellard | 9746b15 | 2004-11-11 18:30:24 +0000 | [diff] [blame] | 1340 | int prot1; |
| 1341 | prot1 = *plast_prot; |
| 1342 | if (prot != prot1) { |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1343 | if (*pstart != -1) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1344 | monitor_printf(mon, "%08x-%08x %08x %c%c%c\n", |
| 1345 | *pstart, end, end - *pstart, |
| 1346 | prot1 & PG_USER_MASK ? 'u' : '-', |
| 1347 | 'r', |
| 1348 | prot1 & PG_RW_MASK ? 'w' : '-'); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1349 | } |
| 1350 | if (prot != 0) |
| 1351 | *pstart = end; |
| 1352 | else |
| 1353 | *pstart = -1; |
| 1354 | *plast_prot = prot; |
| 1355 | } |
| 1356 | } |
| 1357 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1358 | static void mem_info(Monitor *mon) |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1359 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1360 | CPUState *env; |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1361 | int l1, l2, prot, last_prot; |
| 1362 | uint32_t pgd, pde, pte, start, end; |
| 1363 | |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1364 | env = mon_get_cpu(); |
| 1365 | if (!env) |
| 1366 | return; |
| 1367 | |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1368 | if (!(env->cr[0] & CR0_PG_MASK)) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1369 | monitor_printf(mon, "PG disabled\n"); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1370 | return; |
| 1371 | } |
| 1372 | pgd = env->cr[3] & ~0xfff; |
| 1373 | last_prot = 0; |
| 1374 | start = -1; |
| 1375 | for(l1 = 0; l1 < 1024; l1++) { |
| 1376 | cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4); |
| 1377 | pde = le32_to_cpu(pde); |
| 1378 | end = l1 << 22; |
| 1379 | if (pde & PG_PRESENT_MASK) { |
| 1380 | if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { |
| 1381 | prot = pde & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1382 | mem_print(mon, &start, &last_prot, end, prot); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1383 | } else { |
| 1384 | for(l2 = 0; l2 < 1024; l2++) { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1385 | cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1386 | (uint8_t *)&pte, 4); |
| 1387 | pte = le32_to_cpu(pte); |
| 1388 | end = (l1 << 22) + (l2 << 12); |
| 1389 | if (pte & PG_PRESENT_MASK) { |
| 1390 | prot = pte & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK); |
| 1391 | } else { |
| 1392 | prot = 0; |
| 1393 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1394 | mem_print(mon, &start, &last_prot, end, prot); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1395 | } |
| 1396 | } |
| 1397 | } else { |
| 1398 | prot = 0; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1399 | mem_print(mon, &start, &last_prot, end, prot); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1400 | } |
| 1401 | } |
| 1402 | } |
| 1403 | #endif |
| 1404 | |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 1405 | #if defined(TARGET_SH4) |
| 1406 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1407 | static void print_tlb(Monitor *mon, int idx, tlb_t *tlb) |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 1408 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1409 | monitor_printf(mon, " tlb%i:\t" |
| 1410 | "asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t" |
| 1411 | "v=%hhu shared=%hhu cached=%hhu prot=%hhu " |
| 1412 | "dirty=%hhu writethrough=%hhu\n", |
| 1413 | idx, |
| 1414 | tlb->asid, tlb->vpn, tlb->ppn, tlb->sz, tlb->size, |
| 1415 | tlb->v, tlb->sh, tlb->c, tlb->pr, |
| 1416 | tlb->d, tlb->wt); |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1419 | static void tlb_info(Monitor *mon) |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 1420 | { |
| 1421 | CPUState *env = mon_get_cpu(); |
| 1422 | int i; |
| 1423 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1424 | monitor_printf (mon, "ITLB:\n"); |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 1425 | for (i = 0 ; i < ITLB_SIZE ; i++) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1426 | print_tlb (mon, i, &env->itlb[i]); |
| 1427 | monitor_printf (mon, "UTLB:\n"); |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 1428 | for (i = 0 ; i < UTLB_SIZE ; i++) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1429 | print_tlb (mon, i, &env->utlb[i]); |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | #endif |
| 1433 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1434 | static void do_info_kvm(Monitor *mon) |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 1435 | { |
| 1436 | #ifdef CONFIG_KVM |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1437 | monitor_printf(mon, "kvm support: "); |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 1438 | if (kvm_enabled()) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1439 | monitor_printf(mon, "enabled\n"); |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 1440 | else |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1441 | monitor_printf(mon, "disabled\n"); |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 1442 | #else |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1443 | monitor_printf(mon, "kvm support: not compiled\n"); |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 1444 | #endif |
| 1445 | } |
| 1446 | |
aliguori | 030ea37 | 2009-04-21 22:30:47 +0000 | [diff] [blame] | 1447 | static void do_info_numa(Monitor *mon) |
| 1448 | { |
aliguori | b28b623 | 2009-04-22 20:20:29 +0000 | [diff] [blame] | 1449 | int i; |
aliguori | 030ea37 | 2009-04-21 22:30:47 +0000 | [diff] [blame] | 1450 | CPUState *env; |
| 1451 | |
| 1452 | monitor_printf(mon, "%d nodes\n", nb_numa_nodes); |
| 1453 | for (i = 0; i < nb_numa_nodes; i++) { |
| 1454 | monitor_printf(mon, "node %d cpus:", i); |
| 1455 | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
| 1456 | if (env->numa_node == i) { |
| 1457 | monitor_printf(mon, " %d", env->cpu_index); |
| 1458 | } |
| 1459 | } |
| 1460 | monitor_printf(mon, "\n"); |
| 1461 | monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i, |
| 1462 | node_mem[i] >> 20); |
| 1463 | } |
| 1464 | } |
| 1465 | |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 1466 | #ifdef CONFIG_PROFILER |
| 1467 | |
Aurelien Jarno | e9a6625 | 2009-09-30 14:09:52 +0200 | [diff] [blame] | 1468 | int64_t qemu_time; |
| 1469 | int64_t dev_time; |
| 1470 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1471 | static void do_info_profile(Monitor *mon) |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 1472 | { |
| 1473 | int64_t total; |
| 1474 | total = qemu_time; |
| 1475 | if (total == 0) |
| 1476 | total = 1; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1477 | monitor_printf(mon, "async time %" PRId64 " (%0.3f)\n", |
Juan Quintela | 6ee093c | 2009-09-10 03:04:26 +0200 | [diff] [blame] | 1478 | dev_time, dev_time / (double)get_ticks_per_sec()); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1479 | monitor_printf(mon, "qemu time %" PRId64 " (%0.3f)\n", |
Juan Quintela | 6ee093c | 2009-09-10 03:04:26 +0200 | [diff] [blame] | 1480 | qemu_time, qemu_time / (double)get_ticks_per_sec()); |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 1481 | qemu_time = 0; |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 1482 | dev_time = 0; |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 1483 | } |
| 1484 | #else |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1485 | static void do_info_profile(Monitor *mon) |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 1486 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1487 | monitor_printf(mon, "Internal profiler not compiled\n"); |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 1488 | } |
| 1489 | #endif |
| 1490 | |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 1491 | /* Capture support */ |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1492 | static QLIST_HEAD (capture_list_head, CaptureState) capture_head; |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 1493 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1494 | static void do_info_capture(Monitor *mon) |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 1495 | { |
| 1496 | int i; |
| 1497 | CaptureState *s; |
| 1498 | |
| 1499 | for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1500 | monitor_printf(mon, "[%d]: ", i); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 1501 | s->ops.info (s->opaque); |
| 1502 | } |
| 1503 | } |
| 1504 | |
Blue Swirl | 2313086 | 2009-06-06 08:22:04 +0000 | [diff] [blame] | 1505 | #ifdef HAS_AUDIO |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1506 | static void do_stop_capture(Monitor *mon, const QDict *qdict) |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 1507 | { |
| 1508 | int i; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1509 | int n = qdict_get_int(qdict, "n"); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 1510 | CaptureState *s; |
| 1511 | |
| 1512 | for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) { |
| 1513 | if (i == n) { |
| 1514 | s->ops.destroy (s->opaque); |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1515 | QLIST_REMOVE (s, entries); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 1516 | qemu_free (s); |
| 1517 | return; |
| 1518 | } |
| 1519 | } |
| 1520 | } |
| 1521 | |
Luiz Capitulino | c192548 | 2009-08-28 15:27:19 -0300 | [diff] [blame] | 1522 | static void do_wav_capture(Monitor *mon, const QDict *qdict) |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 1523 | { |
Luiz Capitulino | c192548 | 2009-08-28 15:27:19 -0300 | [diff] [blame] | 1524 | const char *path = qdict_get_str(qdict, "path"); |
| 1525 | int has_freq = qdict_haskey(qdict, "freq"); |
| 1526 | int freq = qdict_get_try_int(qdict, "freq", -1); |
| 1527 | int has_bits = qdict_haskey(qdict, "bits"); |
| 1528 | int bits = qdict_get_try_int(qdict, "bits", -1); |
| 1529 | int has_channels = qdict_haskey(qdict, "nchannels"); |
| 1530 | int nchannels = qdict_get_try_int(qdict, "nchannels", -1); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 1531 | CaptureState *s; |
| 1532 | |
| 1533 | s = qemu_mallocz (sizeof (*s)); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 1534 | |
| 1535 | freq = has_freq ? freq : 44100; |
| 1536 | bits = has_bits ? bits : 16; |
| 1537 | nchannels = has_channels ? nchannels : 2; |
| 1538 | |
| 1539 | if (wav_start_capture (s, path, freq, bits, nchannels)) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1540 | monitor_printf(mon, "Faied to add wave capture\n"); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 1541 | qemu_free (s); |
| 1542 | } |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1543 | QLIST_INSERT_HEAD (&capture_head, s, entries); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 1544 | } |
| 1545 | #endif |
| 1546 | |
aurel32 | dc1c0b7 | 2008-04-27 23:52:12 +0000 | [diff] [blame] | 1547 | #if defined(TARGET_I386) |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1548 | static void do_inject_nmi(Monitor *mon, const QDict *qdict) |
aurel32 | dc1c0b7 | 2008-04-27 23:52:12 +0000 | [diff] [blame] | 1549 | { |
| 1550 | CPUState *env; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1551 | int cpu_index = qdict_get_int(qdict, "cpu_index"); |
aurel32 | dc1c0b7 | 2008-04-27 23:52:12 +0000 | [diff] [blame] | 1552 | |
| 1553 | for (env = first_cpu; env != NULL; env = env->next_cpu) |
| 1554 | if (env->cpu_index == cpu_index) { |
| 1555 | cpu_interrupt(env, CPU_INTERRUPT_NMI); |
| 1556 | break; |
| 1557 | } |
| 1558 | } |
| 1559 | #endif |
| 1560 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1561 | static void do_info_status(Monitor *mon) |
aurel32 | 6f9c5ee | 2008-12-18 22:43:56 +0000 | [diff] [blame] | 1562 | { |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 1563 | if (vm_running) { |
| 1564 | if (singlestep) { |
| 1565 | monitor_printf(mon, "VM status: running (single step mode)\n"); |
| 1566 | } else { |
| 1567 | monitor_printf(mon, "VM status: running\n"); |
| 1568 | } |
| 1569 | } else |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1570 | monitor_printf(mon, "VM status: paused\n"); |
aurel32 | 6f9c5ee | 2008-12-18 22:43:56 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1574 | static void do_balloon(Monitor *mon, const QDict *qdict) |
aliguori | df751fa | 2008-12-04 20:19:35 +0000 | [diff] [blame] | 1575 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1576 | int value = qdict_get_int(qdict, "value"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1577 | ram_addr_t target = value; |
aliguori | df751fa | 2008-12-04 20:19:35 +0000 | [diff] [blame] | 1578 | qemu_balloon(target << 20); |
| 1579 | } |
| 1580 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1581 | static void do_info_balloon(Monitor *mon) |
aliguori | df751fa | 2008-12-04 20:19:35 +0000 | [diff] [blame] | 1582 | { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1583 | ram_addr_t actual; |
aliguori | df751fa | 2008-12-04 20:19:35 +0000 | [diff] [blame] | 1584 | |
| 1585 | actual = qemu_balloon_status(); |
aliguori | bd32208 | 2008-12-04 20:33:06 +0000 | [diff] [blame] | 1586 | if (kvm_enabled() && !kvm_has_sync_mmu()) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1587 | monitor_printf(mon, "Using KVM without synchronous MMU, " |
| 1588 | "ballooning disabled\n"); |
aliguori | bd32208 | 2008-12-04 20:33:06 +0000 | [diff] [blame] | 1589 | else if (actual == 0) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1590 | monitor_printf(mon, "Ballooning not activated in VM\n"); |
aliguori | df751fa | 2008-12-04 20:19:35 +0000 | [diff] [blame] | 1591 | else |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1592 | monitor_printf(mon, "balloon: actual=%d\n", (int)(actual >> 20)); |
aliguori | df751fa | 2008-12-04 20:19:35 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1595 | static qemu_acl *find_acl(Monitor *mon, const char *name) |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 1596 | { |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1597 | qemu_acl *acl = qemu_acl_find(name); |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 1598 | |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 1599 | if (!acl) { |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1600 | monitor_printf(mon, "acl: unknown list '%s'\n", name); |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 1601 | } |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1602 | return acl; |
| 1603 | } |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 1604 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1605 | static void do_acl_show(Monitor *mon, const QDict *qdict) |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1606 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1607 | const char *aclname = qdict_get_str(qdict, "aclname"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1608 | qemu_acl *acl = find_acl(mon, aclname); |
| 1609 | qemu_acl_entry *entry; |
| 1610 | int i = 0; |
| 1611 | |
| 1612 | if (acl) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 1613 | monitor_printf(mon, "policy: %s\n", |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 1614 | acl->defaultDeny ? "deny" : "allow"); |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1615 | QTAILQ_FOREACH(entry, &acl->entries, next) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 1616 | i++; |
| 1617 | monitor_printf(mon, "%d: %s %s\n", i, |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1618 | entry->deny ? "deny" : "allow", entry->match); |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 1619 | } |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1620 | } |
| 1621 | } |
| 1622 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1623 | static void do_acl_reset(Monitor *mon, const QDict *qdict) |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1624 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1625 | const char *aclname = qdict_get_str(qdict, "aclname"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1626 | qemu_acl *acl = find_acl(mon, aclname); |
| 1627 | |
| 1628 | if (acl) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 1629 | qemu_acl_reset(acl); |
| 1630 | monitor_printf(mon, "acl: removed all rules\n"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1631 | } |
| 1632 | } |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 1633 | |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 1634 | static void do_acl_policy(Monitor *mon, const QDict *qdict) |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1635 | { |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 1636 | const char *aclname = qdict_get_str(qdict, "aclname"); |
| 1637 | const char *policy = qdict_get_str(qdict, "policy"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1638 | qemu_acl *acl = find_acl(mon, aclname); |
| 1639 | |
| 1640 | if (acl) { |
| 1641 | if (strcmp(policy, "allow") == 0) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 1642 | acl->defaultDeny = 0; |
| 1643 | monitor_printf(mon, "acl: policy set to 'allow'\n"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1644 | } else if (strcmp(policy, "deny") == 0) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 1645 | acl->defaultDeny = 1; |
| 1646 | monitor_printf(mon, "acl: policy set to 'deny'\n"); |
| 1647 | } else { |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1648 | monitor_printf(mon, "acl: unknown policy '%s', " |
| 1649 | "expected 'deny' or 'allow'\n", policy); |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 1650 | } |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1651 | } |
| 1652 | } |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 1653 | |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1654 | static void do_acl_add(Monitor *mon, const QDict *qdict) |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1655 | { |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1656 | const char *aclname = qdict_get_str(qdict, "aclname"); |
| 1657 | const char *match = qdict_get_str(qdict, "match"); |
| 1658 | const char *policy = qdict_get_str(qdict, "policy"); |
| 1659 | int has_index = qdict_haskey(qdict, "index"); |
| 1660 | int index = qdict_get_try_int(qdict, "index", -1); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1661 | qemu_acl *acl = find_acl(mon, aclname); |
| 1662 | int deny, ret; |
| 1663 | |
| 1664 | if (acl) { |
| 1665 | if (strcmp(policy, "allow") == 0) { |
| 1666 | deny = 0; |
| 1667 | } else if (strcmp(policy, "deny") == 0) { |
| 1668 | deny = 1; |
| 1669 | } else { |
| 1670 | monitor_printf(mon, "acl: unknown policy '%s', " |
| 1671 | "expected 'deny' or 'allow'\n", policy); |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 1672 | return; |
| 1673 | } |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 1674 | if (has_index) |
| 1675 | ret = qemu_acl_insert(acl, deny, match, index); |
| 1676 | else |
| 1677 | ret = qemu_acl_append(acl, deny, match); |
| 1678 | if (ret < 0) |
| 1679 | monitor_printf(mon, "acl: unable to add acl entry\n"); |
| 1680 | else |
| 1681 | monitor_printf(mon, "acl: added rule at position %d\n", ret); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1682 | } |
| 1683 | } |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 1684 | |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 1685 | static void do_acl_remove(Monitor *mon, const QDict *qdict) |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1686 | { |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 1687 | const char *aclname = qdict_get_str(qdict, "aclname"); |
| 1688 | const char *match = qdict_get_str(qdict, "match"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1689 | qemu_acl *acl = find_acl(mon, aclname); |
| 1690 | int ret; |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 1691 | |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 1692 | if (acl) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 1693 | ret = qemu_acl_remove(acl, match); |
| 1694 | if (ret < 0) |
| 1695 | monitor_printf(mon, "acl: no matching acl entry\n"); |
| 1696 | else |
| 1697 | monitor_printf(mon, "acl: removed rule at position %d\n", ret); |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 1698 | } |
| 1699 | } |
| 1700 | |
Huang Ying | 79c4f6b | 2009-06-23 10:05:14 +0800 | [diff] [blame] | 1701 | #if defined(TARGET_I386) |
Luiz Capitulino | 37b7ad4 | 2009-08-28 15:27:21 -0300 | [diff] [blame] | 1702 | static void do_inject_mce(Monitor *mon, const QDict *qdict) |
Huang Ying | 79c4f6b | 2009-06-23 10:05:14 +0800 | [diff] [blame] | 1703 | { |
| 1704 | CPUState *cenv; |
Luiz Capitulino | 37b7ad4 | 2009-08-28 15:27:21 -0300 | [diff] [blame] | 1705 | int cpu_index = qdict_get_int(qdict, "cpu_index"); |
| 1706 | int bank = qdict_get_int(qdict, "bank"); |
| 1707 | uint64_t status = qdict_get_int(qdict, "status"); |
| 1708 | uint64_t mcg_status = qdict_get_int(qdict, "mcg_status"); |
| 1709 | uint64_t addr = qdict_get_int(qdict, "addr"); |
| 1710 | uint64_t misc = qdict_get_int(qdict, "misc"); |
Huang Ying | 79c4f6b | 2009-06-23 10:05:14 +0800 | [diff] [blame] | 1711 | |
| 1712 | for (cenv = first_cpu; cenv != NULL; cenv = cenv->next_cpu) |
| 1713 | if (cenv->cpu_index == cpu_index && cenv->mcg_cap) { |
| 1714 | cpu_inject_x86_mce(cenv, bank, status, mcg_status, addr, misc); |
| 1715 | break; |
| 1716 | } |
| 1717 | } |
| 1718 | #endif |
| 1719 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1720 | static void do_getfd(Monitor *mon, const QDict *qdict) |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 1721 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1722 | const char *fdname = qdict_get_str(qdict, "fdname"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1723 | mon_fd_t *monfd; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 1724 | int fd; |
| 1725 | |
| 1726 | fd = qemu_chr_get_msgfd(mon->chr); |
| 1727 | if (fd == -1) { |
| 1728 | monitor_printf(mon, "getfd: no file descriptor supplied via SCM_RIGHTS\n"); |
| 1729 | return; |
| 1730 | } |
| 1731 | |
| 1732 | if (qemu_isdigit(fdname[0])) { |
| 1733 | monitor_printf(mon, "getfd: monitor names may not begin with a number\n"); |
| 1734 | return; |
| 1735 | } |
| 1736 | |
| 1737 | fd = dup(fd); |
| 1738 | if (fd == -1) { |
| 1739 | monitor_printf(mon, "Failed to dup() file descriptor: %s\n", |
| 1740 | strerror(errno)); |
| 1741 | return; |
| 1742 | } |
| 1743 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1744 | QLIST_FOREACH(monfd, &mon->fds, next) { |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 1745 | if (strcmp(monfd->name, fdname) != 0) { |
| 1746 | continue; |
| 1747 | } |
| 1748 | |
| 1749 | close(monfd->fd); |
| 1750 | monfd->fd = fd; |
| 1751 | return; |
| 1752 | } |
| 1753 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1754 | monfd = qemu_mallocz(sizeof(mon_fd_t)); |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 1755 | monfd->name = qemu_strdup(fdname); |
| 1756 | monfd->fd = fd; |
| 1757 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1758 | QLIST_INSERT_HEAD(&mon->fds, monfd, next); |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 1759 | } |
| 1760 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1761 | static void do_closefd(Monitor *mon, const QDict *qdict) |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 1762 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1763 | const char *fdname = qdict_get_str(qdict, "fdname"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1764 | mon_fd_t *monfd; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 1765 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1766 | QLIST_FOREACH(monfd, &mon->fds, next) { |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 1767 | if (strcmp(monfd->name, fdname) != 0) { |
| 1768 | continue; |
| 1769 | } |
| 1770 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1771 | QLIST_REMOVE(monfd, next); |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 1772 | close(monfd->fd); |
| 1773 | qemu_free(monfd->name); |
| 1774 | qemu_free(monfd); |
| 1775 | return; |
| 1776 | } |
| 1777 | |
| 1778 | monitor_printf(mon, "Failed to find file descriptor named %s\n", |
| 1779 | fdname); |
| 1780 | } |
| 1781 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1782 | static void do_loadvm(Monitor *mon, const QDict *qdict) |
Juan Quintela | c8d41b2 | 2009-08-20 19:42:21 +0200 | [diff] [blame] | 1783 | { |
| 1784 | int saved_vm_running = vm_running; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1785 | const char *name = qdict_get_str(qdict, "name"); |
Juan Quintela | c8d41b2 | 2009-08-20 19:42:21 +0200 | [diff] [blame] | 1786 | |
| 1787 | vm_stop(0); |
| 1788 | |
Juan Quintela | 05f2401 | 2009-08-20 19:42:22 +0200 | [diff] [blame] | 1789 | if (load_vmstate(mon, name) >= 0 && saved_vm_running) |
Juan Quintela | c8d41b2 | 2009-08-20 19:42:21 +0200 | [diff] [blame] | 1790 | vm_start(); |
| 1791 | } |
| 1792 | |
Mark McLoughlin | 7768e04 | 2009-07-22 09:11:41 +0100 | [diff] [blame] | 1793 | int monitor_get_fd(Monitor *mon, const char *fdname) |
| 1794 | { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1795 | mon_fd_t *monfd; |
Mark McLoughlin | 7768e04 | 2009-07-22 09:11:41 +0100 | [diff] [blame] | 1796 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1797 | QLIST_FOREACH(monfd, &mon->fds, next) { |
Mark McLoughlin | 7768e04 | 2009-07-22 09:11:41 +0100 | [diff] [blame] | 1798 | int fd; |
| 1799 | |
| 1800 | if (strcmp(monfd->name, fdname) != 0) { |
| 1801 | continue; |
| 1802 | } |
| 1803 | |
| 1804 | fd = monfd->fd; |
| 1805 | |
| 1806 | /* caller takes ownership of fd */ |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1807 | QLIST_REMOVE(monfd, next); |
Mark McLoughlin | 7768e04 | 2009-07-22 09:11:41 +0100 | [diff] [blame] | 1808 | qemu_free(monfd->name); |
| 1809 | qemu_free(monfd); |
| 1810 | |
| 1811 | return fd; |
| 1812 | } |
| 1813 | |
| 1814 | return -1; |
| 1815 | } |
| 1816 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1817 | static const mon_cmd_t mon_cmds[] = { |
Blue Swirl | 2313086 | 2009-06-06 08:22:04 +0000 | [diff] [blame] | 1818 | #include "qemu-monitor.h" |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1819 | { NULL, NULL, }, |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 1820 | }; |
| 1821 | |
Blue Swirl | 2313086 | 2009-06-06 08:22:04 +0000 | [diff] [blame] | 1822 | /* Please update qemu-monitor.hx when adding or changing commands */ |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1823 | static const mon_cmd_t info_cmds[] = { |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1824 | { |
| 1825 | .name = "version", |
| 1826 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1827 | .params = "", |
| 1828 | .help = "show the version of QEMU", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1829 | .mhandler.info = do_info_version, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1830 | }, |
| 1831 | { |
| 1832 | .name = "network", |
| 1833 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1834 | .params = "", |
| 1835 | .help = "show the network state", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1836 | .mhandler.info = do_info_network, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1837 | }, |
| 1838 | { |
| 1839 | .name = "chardev", |
| 1840 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1841 | .params = "", |
| 1842 | .help = "show the character devices", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1843 | .mhandler.info = qemu_chr_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1844 | }, |
| 1845 | { |
| 1846 | .name = "block", |
| 1847 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1848 | .params = "", |
| 1849 | .help = "show the block devices", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1850 | .mhandler.info = bdrv_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1851 | }, |
| 1852 | { |
| 1853 | .name = "blockstats", |
| 1854 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1855 | .params = "", |
| 1856 | .help = "show block device statistics", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1857 | .mhandler.info = bdrv_info_stats, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1858 | }, |
| 1859 | { |
| 1860 | .name = "registers", |
| 1861 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1862 | .params = "", |
| 1863 | .help = "show the cpu registers", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1864 | .mhandler.info = do_info_registers, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1865 | }, |
| 1866 | { |
| 1867 | .name = "cpus", |
| 1868 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1869 | .params = "", |
| 1870 | .help = "show infos for each CPU", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1871 | .mhandler.info = do_info_cpus, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1872 | }, |
| 1873 | { |
| 1874 | .name = "history", |
| 1875 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1876 | .params = "", |
| 1877 | .help = "show the command line history", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1878 | .mhandler.info = do_info_history, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1879 | }, |
| 1880 | { |
| 1881 | .name = "irq", |
| 1882 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1883 | .params = "", |
| 1884 | .help = "show the interrupts statistics (if available)", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1885 | .mhandler.info = irq_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1886 | }, |
| 1887 | { |
| 1888 | .name = "pic", |
| 1889 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1890 | .params = "", |
| 1891 | .help = "show i8259 (PIC) state", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1892 | .mhandler.info = pic_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1893 | }, |
| 1894 | { |
| 1895 | .name = "pci", |
| 1896 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1897 | .params = "", |
| 1898 | .help = "show PCI info", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1899 | .mhandler.info = pci_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1900 | }, |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 1901 | #if defined(TARGET_I386) || defined(TARGET_SH4) |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1902 | { |
| 1903 | .name = "tlb", |
| 1904 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1905 | .params = "", |
| 1906 | .help = "show virtual to physical memory mappings", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1907 | .mhandler.info = tlb_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1908 | }, |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 1909 | #endif |
| 1910 | #if defined(TARGET_I386) |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1911 | { |
| 1912 | .name = "mem", |
| 1913 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1914 | .params = "", |
| 1915 | .help = "show the active virtual memory mappings", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1916 | .mhandler.info = mem_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1917 | }, |
| 1918 | { |
| 1919 | .name = "hpet", |
| 1920 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1921 | .params = "", |
| 1922 | .help = "show state of HPET", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1923 | .mhandler.info = do_info_hpet, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1924 | }, |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1925 | #endif |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1926 | { |
| 1927 | .name = "jit", |
| 1928 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1929 | .params = "", |
| 1930 | .help = "show dynamic compiler info", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1931 | .mhandler.info = do_info_jit, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1932 | }, |
| 1933 | { |
| 1934 | .name = "kvm", |
| 1935 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1936 | .params = "", |
| 1937 | .help = "show KVM information", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1938 | .mhandler.info = do_info_kvm, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1939 | }, |
| 1940 | { |
| 1941 | .name = "numa", |
| 1942 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1943 | .params = "", |
| 1944 | .help = "show NUMA information", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1945 | .mhandler.info = do_info_numa, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1946 | }, |
| 1947 | { |
| 1948 | .name = "usb", |
| 1949 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1950 | .params = "", |
| 1951 | .help = "show guest USB devices", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1952 | .mhandler.info = usb_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1953 | }, |
| 1954 | { |
| 1955 | .name = "usbhost", |
| 1956 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1957 | .params = "", |
| 1958 | .help = "show host USB devices", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1959 | .mhandler.info = usb_host_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1960 | }, |
| 1961 | { |
| 1962 | .name = "profile", |
| 1963 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1964 | .params = "", |
| 1965 | .help = "show profiling information", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1966 | .mhandler.info = do_info_profile, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1967 | }, |
| 1968 | { |
| 1969 | .name = "capture", |
| 1970 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1971 | .params = "", |
| 1972 | .help = "show capture information", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1973 | .mhandler.info = do_info_capture, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1974 | }, |
| 1975 | { |
| 1976 | .name = "snapshots", |
| 1977 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1978 | .params = "", |
| 1979 | .help = "show the currently saved VM snapshots", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1980 | .mhandler.info = do_info_snapshots, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1981 | }, |
| 1982 | { |
| 1983 | .name = "status", |
| 1984 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1985 | .params = "", |
| 1986 | .help = "show the current VM status (running|paused)", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1987 | .mhandler.info = do_info_status, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1988 | }, |
| 1989 | { |
| 1990 | .name = "pcmcia", |
| 1991 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1992 | .params = "", |
| 1993 | .help = "show guest PCMCIA status", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 1994 | .mhandler.info = pcmcia_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1995 | }, |
| 1996 | { |
| 1997 | .name = "mice", |
| 1998 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 1999 | .params = "", |
| 2000 | .help = "show which guest mouse is receiving events", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2001 | .mhandler.info = do_info_mice, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2002 | }, |
| 2003 | { |
| 2004 | .name = "vnc", |
| 2005 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2006 | .params = "", |
| 2007 | .help = "show the vnc server status", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2008 | .mhandler.info = do_info_vnc, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2009 | }, |
| 2010 | { |
| 2011 | .name = "name", |
| 2012 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2013 | .params = "", |
| 2014 | .help = "show the current VM name", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2015 | .mhandler.info = do_info_name, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2016 | }, |
| 2017 | { |
| 2018 | .name = "uuid", |
| 2019 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2020 | .params = "", |
| 2021 | .help = "show the current VM UUID", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2022 | .mhandler.info = do_info_uuid, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2023 | }, |
j_mayer | 76a6625 | 2007-03-07 08:32:30 +0000 | [diff] [blame] | 2024 | #if defined(TARGET_PPC) |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2025 | { |
| 2026 | .name = "cpustats", |
| 2027 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2028 | .params = "", |
| 2029 | .help = "show CPU statistics", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2030 | .mhandler.info = do_info_cpu_stats, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2031 | }, |
j_mayer | 76a6625 | 2007-03-07 08:32:30 +0000 | [diff] [blame] | 2032 | #endif |
blueswir1 | 31a60e2 | 2007-10-26 18:42:59 +0000 | [diff] [blame] | 2033 | #if defined(CONFIG_SLIRP) |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2034 | { |
| 2035 | .name = "usernet", |
| 2036 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2037 | .params = "", |
| 2038 | .help = "show user network stack connection states", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2039 | .mhandler.info = do_info_usernet, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2040 | }, |
blueswir1 | 31a60e2 | 2007-10-26 18:42:59 +0000 | [diff] [blame] | 2041 | #endif |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2042 | { |
| 2043 | .name = "migrate", |
| 2044 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2045 | .params = "", |
| 2046 | .help = "show migration status", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2047 | .mhandler.info = do_info_migrate, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2048 | }, |
| 2049 | { |
| 2050 | .name = "balloon", |
| 2051 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2052 | .params = "", |
| 2053 | .help = "show balloon information", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2054 | .mhandler.info = do_info_balloon, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2055 | }, |
| 2056 | { |
| 2057 | .name = "qtree", |
| 2058 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2059 | .params = "", |
| 2060 | .help = "show device tree", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2061 | .mhandler.info = do_info_qtree, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2062 | }, |
| 2063 | { |
| 2064 | .name = "qdm", |
| 2065 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2066 | .params = "", |
| 2067 | .help = "show qdev device model list", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2068 | .mhandler.info = do_info_qdm, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2069 | }, |
| 2070 | { |
| 2071 | .name = "roms", |
| 2072 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2073 | .params = "", |
| 2074 | .help = "show roms", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2075 | .mhandler.info = do_info_roms, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2076 | }, |
| 2077 | { |
| 2078 | .name = NULL, |
| 2079 | }, |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 2080 | }; |
| 2081 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2082 | /*******************************************************************/ |
| 2083 | |
| 2084 | static const char *pch; |
| 2085 | static jmp_buf expr_env; |
| 2086 | |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2087 | #define MD_TLONG 0 |
| 2088 | #define MD_I32 1 |
| 2089 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2090 | typedef struct MonitorDef { |
| 2091 | const char *name; |
| 2092 | int offset; |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2093 | target_long (*get_value)(const struct MonitorDef *md, int val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2094 | int type; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2095 | } MonitorDef; |
| 2096 | |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2097 | #if defined(TARGET_I386) |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2098 | static target_long monitor_get_pc (const struct MonitorDef *md, int val) |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2099 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2100 | CPUState *env = mon_get_cpu(); |
| 2101 | if (!env) |
| 2102 | return 0; |
| 2103 | return env->eip + env->segs[R_CS].base; |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2104 | } |
| 2105 | #endif |
| 2106 | |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2107 | #if defined(TARGET_PPC) |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2108 | static target_long monitor_get_ccr (const struct MonitorDef *md, int val) |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2109 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2110 | CPUState *env = mon_get_cpu(); |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2111 | unsigned int u; |
| 2112 | int i; |
| 2113 | |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2114 | if (!env) |
| 2115 | return 0; |
| 2116 | |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2117 | u = 0; |
| 2118 | for (i = 0; i < 8; i++) |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2119 | u |= env->crf[i] << (32 - (4 * i)); |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2120 | |
| 2121 | return u; |
| 2122 | } |
| 2123 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2124 | static target_long monitor_get_msr (const struct MonitorDef *md, int val) |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2125 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2126 | CPUState *env = mon_get_cpu(); |
| 2127 | if (!env) |
| 2128 | return 0; |
j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 2129 | return env->msr; |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2130 | } |
| 2131 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2132 | static target_long monitor_get_xer (const struct MonitorDef *md, int val) |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2133 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2134 | CPUState *env = mon_get_cpu(); |
| 2135 | if (!env) |
| 2136 | return 0; |
aurel32 | 3d7b417 | 2008-10-21 11:28:46 +0000 | [diff] [blame] | 2137 | return env->xer; |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2138 | } |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2139 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2140 | static target_long monitor_get_decr (const struct MonitorDef *md, int val) |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2141 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2142 | CPUState *env = mon_get_cpu(); |
| 2143 | if (!env) |
| 2144 | return 0; |
| 2145 | return cpu_ppc_load_decr(env); |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2146 | } |
| 2147 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2148 | static target_long monitor_get_tbu (const struct MonitorDef *md, int val) |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2149 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2150 | CPUState *env = mon_get_cpu(); |
| 2151 | if (!env) |
| 2152 | return 0; |
| 2153 | return cpu_ppc_load_tbu(env); |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2156 | static target_long monitor_get_tbl (const struct MonitorDef *md, int val) |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2157 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2158 | CPUState *env = mon_get_cpu(); |
| 2159 | if (!env) |
| 2160 | return 0; |
| 2161 | return cpu_ppc_load_tbl(env); |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2162 | } |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2163 | #endif |
| 2164 | |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2165 | #if defined(TARGET_SPARC) |
bellard | 7b936c0 | 2005-10-30 17:05:13 +0000 | [diff] [blame] | 2166 | #ifndef TARGET_SPARC64 |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2167 | static target_long monitor_get_psr (const struct MonitorDef *md, int val) |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2168 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2169 | CPUState *env = mon_get_cpu(); |
| 2170 | if (!env) |
| 2171 | return 0; |
| 2172 | return GET_PSR(env); |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2173 | } |
bellard | 7b936c0 | 2005-10-30 17:05:13 +0000 | [diff] [blame] | 2174 | #endif |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2175 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2176 | static target_long monitor_get_reg(const struct MonitorDef *md, int val) |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2177 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2178 | CPUState *env = mon_get_cpu(); |
| 2179 | if (!env) |
| 2180 | return 0; |
| 2181 | return env->regwptr[val]; |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2182 | } |
| 2183 | #endif |
| 2184 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2185 | static const MonitorDef monitor_defs[] = { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2186 | #ifdef TARGET_I386 |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2187 | |
| 2188 | #define SEG(name, seg) \ |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2189 | { name, offsetof(CPUState, segs[seg].selector), NULL, MD_I32 },\ |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2190 | { name ".base", offsetof(CPUState, segs[seg].base) },\ |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2191 | { name ".limit", offsetof(CPUState, segs[seg].limit), NULL, MD_I32 }, |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2192 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2193 | { "eax", offsetof(CPUState, regs[0]) }, |
| 2194 | { "ecx", offsetof(CPUState, regs[1]) }, |
| 2195 | { "edx", offsetof(CPUState, regs[2]) }, |
| 2196 | { "ebx", offsetof(CPUState, regs[3]) }, |
| 2197 | { "esp|sp", offsetof(CPUState, regs[4]) }, |
| 2198 | { "ebp|fp", offsetof(CPUState, regs[5]) }, |
| 2199 | { "esi", offsetof(CPUState, regs[6]) }, |
bellard | 01038d2 | 2004-09-13 21:36:46 +0000 | [diff] [blame] | 2200 | { "edi", offsetof(CPUState, regs[7]) }, |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2201 | #ifdef TARGET_X86_64 |
| 2202 | { "r8", offsetof(CPUState, regs[8]) }, |
| 2203 | { "r9", offsetof(CPUState, regs[9]) }, |
| 2204 | { "r10", offsetof(CPUState, regs[10]) }, |
| 2205 | { "r11", offsetof(CPUState, regs[11]) }, |
| 2206 | { "r12", offsetof(CPUState, regs[12]) }, |
| 2207 | { "r13", offsetof(CPUState, regs[13]) }, |
| 2208 | { "r14", offsetof(CPUState, regs[14]) }, |
| 2209 | { "r15", offsetof(CPUState, regs[15]) }, |
| 2210 | #endif |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2211 | { "eflags", offsetof(CPUState, eflags) }, |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2212 | { "eip", offsetof(CPUState, eip) }, |
| 2213 | SEG("cs", R_CS) |
| 2214 | SEG("ds", R_DS) |
| 2215 | SEG("es", R_ES) |
bellard | 01038d2 | 2004-09-13 21:36:46 +0000 | [diff] [blame] | 2216 | SEG("ss", R_SS) |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2217 | SEG("fs", R_FS) |
| 2218 | SEG("gs", R_GS) |
| 2219 | { "pc", 0, monitor_get_pc, }, |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2220 | #elif defined(TARGET_PPC) |
j_mayer | ff937db | 2007-09-19 05:49:13 +0000 | [diff] [blame] | 2221 | /* General purpose registers */ |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2222 | { "r0", offsetof(CPUState, gpr[0]) }, |
| 2223 | { "r1", offsetof(CPUState, gpr[1]) }, |
| 2224 | { "r2", offsetof(CPUState, gpr[2]) }, |
| 2225 | { "r3", offsetof(CPUState, gpr[3]) }, |
| 2226 | { "r4", offsetof(CPUState, gpr[4]) }, |
| 2227 | { "r5", offsetof(CPUState, gpr[5]) }, |
| 2228 | { "r6", offsetof(CPUState, gpr[6]) }, |
| 2229 | { "r7", offsetof(CPUState, gpr[7]) }, |
| 2230 | { "r8", offsetof(CPUState, gpr[8]) }, |
| 2231 | { "r9", offsetof(CPUState, gpr[9]) }, |
| 2232 | { "r10", offsetof(CPUState, gpr[10]) }, |
| 2233 | { "r11", offsetof(CPUState, gpr[11]) }, |
| 2234 | { "r12", offsetof(CPUState, gpr[12]) }, |
| 2235 | { "r13", offsetof(CPUState, gpr[13]) }, |
| 2236 | { "r14", offsetof(CPUState, gpr[14]) }, |
| 2237 | { "r15", offsetof(CPUState, gpr[15]) }, |
| 2238 | { "r16", offsetof(CPUState, gpr[16]) }, |
| 2239 | { "r17", offsetof(CPUState, gpr[17]) }, |
| 2240 | { "r18", offsetof(CPUState, gpr[18]) }, |
| 2241 | { "r19", offsetof(CPUState, gpr[19]) }, |
| 2242 | { "r20", offsetof(CPUState, gpr[20]) }, |
| 2243 | { "r21", offsetof(CPUState, gpr[21]) }, |
| 2244 | { "r22", offsetof(CPUState, gpr[22]) }, |
| 2245 | { "r23", offsetof(CPUState, gpr[23]) }, |
| 2246 | { "r24", offsetof(CPUState, gpr[24]) }, |
| 2247 | { "r25", offsetof(CPUState, gpr[25]) }, |
| 2248 | { "r26", offsetof(CPUState, gpr[26]) }, |
| 2249 | { "r27", offsetof(CPUState, gpr[27]) }, |
| 2250 | { "r28", offsetof(CPUState, gpr[28]) }, |
| 2251 | { "r29", offsetof(CPUState, gpr[29]) }, |
| 2252 | { "r30", offsetof(CPUState, gpr[30]) }, |
| 2253 | { "r31", offsetof(CPUState, gpr[31]) }, |
j_mayer | ff937db | 2007-09-19 05:49:13 +0000 | [diff] [blame] | 2254 | /* Floating point registers */ |
| 2255 | { "f0", offsetof(CPUState, fpr[0]) }, |
| 2256 | { "f1", offsetof(CPUState, fpr[1]) }, |
| 2257 | { "f2", offsetof(CPUState, fpr[2]) }, |
| 2258 | { "f3", offsetof(CPUState, fpr[3]) }, |
| 2259 | { "f4", offsetof(CPUState, fpr[4]) }, |
| 2260 | { "f5", offsetof(CPUState, fpr[5]) }, |
| 2261 | { "f6", offsetof(CPUState, fpr[6]) }, |
| 2262 | { "f7", offsetof(CPUState, fpr[7]) }, |
| 2263 | { "f8", offsetof(CPUState, fpr[8]) }, |
| 2264 | { "f9", offsetof(CPUState, fpr[9]) }, |
| 2265 | { "f10", offsetof(CPUState, fpr[10]) }, |
| 2266 | { "f11", offsetof(CPUState, fpr[11]) }, |
| 2267 | { "f12", offsetof(CPUState, fpr[12]) }, |
| 2268 | { "f13", offsetof(CPUState, fpr[13]) }, |
| 2269 | { "f14", offsetof(CPUState, fpr[14]) }, |
| 2270 | { "f15", offsetof(CPUState, fpr[15]) }, |
| 2271 | { "f16", offsetof(CPUState, fpr[16]) }, |
| 2272 | { "f17", offsetof(CPUState, fpr[17]) }, |
| 2273 | { "f18", offsetof(CPUState, fpr[18]) }, |
| 2274 | { "f19", offsetof(CPUState, fpr[19]) }, |
| 2275 | { "f20", offsetof(CPUState, fpr[20]) }, |
| 2276 | { "f21", offsetof(CPUState, fpr[21]) }, |
| 2277 | { "f22", offsetof(CPUState, fpr[22]) }, |
| 2278 | { "f23", offsetof(CPUState, fpr[23]) }, |
| 2279 | { "f24", offsetof(CPUState, fpr[24]) }, |
| 2280 | { "f25", offsetof(CPUState, fpr[25]) }, |
| 2281 | { "f26", offsetof(CPUState, fpr[26]) }, |
| 2282 | { "f27", offsetof(CPUState, fpr[27]) }, |
| 2283 | { "f28", offsetof(CPUState, fpr[28]) }, |
| 2284 | { "f29", offsetof(CPUState, fpr[29]) }, |
| 2285 | { "f30", offsetof(CPUState, fpr[30]) }, |
| 2286 | { "f31", offsetof(CPUState, fpr[31]) }, |
| 2287 | { "fpscr", offsetof(CPUState, fpscr) }, |
| 2288 | /* Next instruction pointer */ |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2289 | { "nip|pc", offsetof(CPUState, nip) }, |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2290 | { "lr", offsetof(CPUState, lr) }, |
| 2291 | { "ctr", offsetof(CPUState, ctr) }, |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2292 | { "decr", 0, &monitor_get_decr, }, |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2293 | { "ccr", 0, &monitor_get_ccr, }, |
j_mayer | ff937db | 2007-09-19 05:49:13 +0000 | [diff] [blame] | 2294 | /* Machine state register */ |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2295 | { "msr", 0, &monitor_get_msr, }, |
| 2296 | { "xer", 0, &monitor_get_xer, }, |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2297 | { "tbu", 0, &monitor_get_tbu, }, |
| 2298 | { "tbl", 0, &monitor_get_tbl, }, |
j_mayer | ff937db | 2007-09-19 05:49:13 +0000 | [diff] [blame] | 2299 | #if defined(TARGET_PPC64) |
| 2300 | /* Address space register */ |
| 2301 | { "asr", offsetof(CPUState, asr) }, |
| 2302 | #endif |
| 2303 | /* Segment registers */ |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2304 | { "sdr1", offsetof(CPUState, sdr1) }, |
| 2305 | { "sr0", offsetof(CPUState, sr[0]) }, |
| 2306 | { "sr1", offsetof(CPUState, sr[1]) }, |
| 2307 | { "sr2", offsetof(CPUState, sr[2]) }, |
| 2308 | { "sr3", offsetof(CPUState, sr[3]) }, |
| 2309 | { "sr4", offsetof(CPUState, sr[4]) }, |
| 2310 | { "sr5", offsetof(CPUState, sr[5]) }, |
| 2311 | { "sr6", offsetof(CPUState, sr[6]) }, |
| 2312 | { "sr7", offsetof(CPUState, sr[7]) }, |
| 2313 | { "sr8", offsetof(CPUState, sr[8]) }, |
| 2314 | { "sr9", offsetof(CPUState, sr[9]) }, |
| 2315 | { "sr10", offsetof(CPUState, sr[10]) }, |
| 2316 | { "sr11", offsetof(CPUState, sr[11]) }, |
| 2317 | { "sr12", offsetof(CPUState, sr[12]) }, |
| 2318 | { "sr13", offsetof(CPUState, sr[13]) }, |
| 2319 | { "sr14", offsetof(CPUState, sr[14]) }, |
| 2320 | { "sr15", offsetof(CPUState, sr[15]) }, |
| 2321 | /* Too lazy to put BATs and SPRs ... */ |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2322 | #elif defined(TARGET_SPARC) |
| 2323 | { "g0", offsetof(CPUState, gregs[0]) }, |
| 2324 | { "g1", offsetof(CPUState, gregs[1]) }, |
| 2325 | { "g2", offsetof(CPUState, gregs[2]) }, |
| 2326 | { "g3", offsetof(CPUState, gregs[3]) }, |
| 2327 | { "g4", offsetof(CPUState, gregs[4]) }, |
| 2328 | { "g5", offsetof(CPUState, gregs[5]) }, |
| 2329 | { "g6", offsetof(CPUState, gregs[6]) }, |
| 2330 | { "g7", offsetof(CPUState, gregs[7]) }, |
| 2331 | { "o0", 0, monitor_get_reg }, |
| 2332 | { "o1", 1, monitor_get_reg }, |
| 2333 | { "o2", 2, monitor_get_reg }, |
| 2334 | { "o3", 3, monitor_get_reg }, |
| 2335 | { "o4", 4, monitor_get_reg }, |
| 2336 | { "o5", 5, monitor_get_reg }, |
| 2337 | { "o6", 6, monitor_get_reg }, |
| 2338 | { "o7", 7, monitor_get_reg }, |
| 2339 | { "l0", 8, monitor_get_reg }, |
| 2340 | { "l1", 9, monitor_get_reg }, |
| 2341 | { "l2", 10, monitor_get_reg }, |
| 2342 | { "l3", 11, monitor_get_reg }, |
| 2343 | { "l4", 12, monitor_get_reg }, |
| 2344 | { "l5", 13, monitor_get_reg }, |
| 2345 | { "l6", 14, monitor_get_reg }, |
| 2346 | { "l7", 15, monitor_get_reg }, |
| 2347 | { "i0", 16, monitor_get_reg }, |
| 2348 | { "i1", 17, monitor_get_reg }, |
| 2349 | { "i2", 18, monitor_get_reg }, |
| 2350 | { "i3", 19, monitor_get_reg }, |
| 2351 | { "i4", 20, monitor_get_reg }, |
| 2352 | { "i5", 21, monitor_get_reg }, |
| 2353 | { "i6", 22, monitor_get_reg }, |
| 2354 | { "i7", 23, monitor_get_reg }, |
| 2355 | { "pc", offsetof(CPUState, pc) }, |
| 2356 | { "npc", offsetof(CPUState, npc) }, |
| 2357 | { "y", offsetof(CPUState, y) }, |
bellard | 7b936c0 | 2005-10-30 17:05:13 +0000 | [diff] [blame] | 2358 | #ifndef TARGET_SPARC64 |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2359 | { "psr", 0, &monitor_get_psr, }, |
| 2360 | { "wim", offsetof(CPUState, wim) }, |
bellard | 7b936c0 | 2005-10-30 17:05:13 +0000 | [diff] [blame] | 2361 | #endif |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2362 | { "tbr", offsetof(CPUState, tbr) }, |
| 2363 | { "fsr", offsetof(CPUState, fsr) }, |
| 2364 | { "f0", offsetof(CPUState, fpr[0]) }, |
| 2365 | { "f1", offsetof(CPUState, fpr[1]) }, |
| 2366 | { "f2", offsetof(CPUState, fpr[2]) }, |
| 2367 | { "f3", offsetof(CPUState, fpr[3]) }, |
| 2368 | { "f4", offsetof(CPUState, fpr[4]) }, |
| 2369 | { "f5", offsetof(CPUState, fpr[5]) }, |
| 2370 | { "f6", offsetof(CPUState, fpr[6]) }, |
| 2371 | { "f7", offsetof(CPUState, fpr[7]) }, |
| 2372 | { "f8", offsetof(CPUState, fpr[8]) }, |
| 2373 | { "f9", offsetof(CPUState, fpr[9]) }, |
| 2374 | { "f10", offsetof(CPUState, fpr[10]) }, |
| 2375 | { "f11", offsetof(CPUState, fpr[11]) }, |
| 2376 | { "f12", offsetof(CPUState, fpr[12]) }, |
| 2377 | { "f13", offsetof(CPUState, fpr[13]) }, |
| 2378 | { "f14", offsetof(CPUState, fpr[14]) }, |
| 2379 | { "f15", offsetof(CPUState, fpr[15]) }, |
| 2380 | { "f16", offsetof(CPUState, fpr[16]) }, |
| 2381 | { "f17", offsetof(CPUState, fpr[17]) }, |
| 2382 | { "f18", offsetof(CPUState, fpr[18]) }, |
| 2383 | { "f19", offsetof(CPUState, fpr[19]) }, |
| 2384 | { "f20", offsetof(CPUState, fpr[20]) }, |
| 2385 | { "f21", offsetof(CPUState, fpr[21]) }, |
| 2386 | { "f22", offsetof(CPUState, fpr[22]) }, |
| 2387 | { "f23", offsetof(CPUState, fpr[23]) }, |
| 2388 | { "f24", offsetof(CPUState, fpr[24]) }, |
| 2389 | { "f25", offsetof(CPUState, fpr[25]) }, |
| 2390 | { "f26", offsetof(CPUState, fpr[26]) }, |
| 2391 | { "f27", offsetof(CPUState, fpr[27]) }, |
| 2392 | { "f28", offsetof(CPUState, fpr[28]) }, |
| 2393 | { "f29", offsetof(CPUState, fpr[29]) }, |
| 2394 | { "f30", offsetof(CPUState, fpr[30]) }, |
| 2395 | { "f31", offsetof(CPUState, fpr[31]) }, |
bellard | 7b936c0 | 2005-10-30 17:05:13 +0000 | [diff] [blame] | 2396 | #ifdef TARGET_SPARC64 |
| 2397 | { "f32", offsetof(CPUState, fpr[32]) }, |
| 2398 | { "f34", offsetof(CPUState, fpr[34]) }, |
| 2399 | { "f36", offsetof(CPUState, fpr[36]) }, |
| 2400 | { "f38", offsetof(CPUState, fpr[38]) }, |
| 2401 | { "f40", offsetof(CPUState, fpr[40]) }, |
| 2402 | { "f42", offsetof(CPUState, fpr[42]) }, |
| 2403 | { "f44", offsetof(CPUState, fpr[44]) }, |
| 2404 | { "f46", offsetof(CPUState, fpr[46]) }, |
| 2405 | { "f48", offsetof(CPUState, fpr[48]) }, |
| 2406 | { "f50", offsetof(CPUState, fpr[50]) }, |
| 2407 | { "f52", offsetof(CPUState, fpr[52]) }, |
| 2408 | { "f54", offsetof(CPUState, fpr[54]) }, |
| 2409 | { "f56", offsetof(CPUState, fpr[56]) }, |
| 2410 | { "f58", offsetof(CPUState, fpr[58]) }, |
| 2411 | { "f60", offsetof(CPUState, fpr[60]) }, |
| 2412 | { "f62", offsetof(CPUState, fpr[62]) }, |
| 2413 | { "asi", offsetof(CPUState, asi) }, |
| 2414 | { "pstate", offsetof(CPUState, pstate) }, |
| 2415 | { "cansave", offsetof(CPUState, cansave) }, |
| 2416 | { "canrestore", offsetof(CPUState, canrestore) }, |
| 2417 | { "otherwin", offsetof(CPUState, otherwin) }, |
| 2418 | { "wstate", offsetof(CPUState, wstate) }, |
| 2419 | { "cleanwin", offsetof(CPUState, cleanwin) }, |
| 2420 | { "fprs", offsetof(CPUState, fprs) }, |
| 2421 | #endif |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2422 | #endif |
| 2423 | { NULL }, |
| 2424 | }; |
| 2425 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2426 | static void expr_error(Monitor *mon, const char *msg) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 2427 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2428 | monitor_printf(mon, "%s\n", msg); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2429 | longjmp(expr_env, 1); |
| 2430 | } |
| 2431 | |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2432 | /* return 0 if OK, -1 if not found, -2 if no CPU defined */ |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2433 | static int get_monitor_def(target_long *pval, const char *name) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2434 | { |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2435 | const MonitorDef *md; |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2436 | void *ptr; |
| 2437 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2438 | for(md = monitor_defs; md->name != NULL; md++) { |
| 2439 | if (compare_cmd(name, md->name)) { |
| 2440 | if (md->get_value) { |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2441 | *pval = md->get_value(md, md->offset); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2442 | } else { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2443 | CPUState *env = mon_get_cpu(); |
| 2444 | if (!env) |
| 2445 | return -2; |
| 2446 | ptr = (uint8_t *)env + md->offset; |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2447 | switch(md->type) { |
| 2448 | case MD_I32: |
| 2449 | *pval = *(int32_t *)ptr; |
| 2450 | break; |
| 2451 | case MD_TLONG: |
| 2452 | *pval = *(target_long *)ptr; |
| 2453 | break; |
| 2454 | default: |
| 2455 | *pval = 0; |
| 2456 | break; |
| 2457 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2458 | } |
| 2459 | return 0; |
| 2460 | } |
| 2461 | } |
| 2462 | return -1; |
| 2463 | } |
| 2464 | |
| 2465 | static void next(void) |
| 2466 | { |
Blue Swirl | 660f11b | 2009-07-31 21:16:51 +0000 | [diff] [blame] | 2467 | if (*pch != '\0') { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2468 | pch++; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 2469 | while (qemu_isspace(*pch)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2470 | pch++; |
| 2471 | } |
| 2472 | } |
| 2473 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2474 | static int64_t expr_sum(Monitor *mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2475 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2476 | static int64_t expr_unary(Monitor *mon) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2477 | { |
blueswir1 | c2efc95 | 2007-09-25 17:28:42 +0000 | [diff] [blame] | 2478 | int64_t n; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2479 | char *p; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2480 | int ret; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2481 | |
| 2482 | switch(*pch) { |
| 2483 | case '+': |
| 2484 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2485 | n = expr_unary(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2486 | break; |
| 2487 | case '-': |
| 2488 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2489 | n = -expr_unary(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2490 | break; |
| 2491 | case '~': |
| 2492 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2493 | n = ~expr_unary(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2494 | break; |
| 2495 | case '(': |
| 2496 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2497 | n = expr_sum(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2498 | if (*pch != ')') { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2499 | expr_error(mon, "')' expected"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2500 | } |
| 2501 | next(); |
| 2502 | break; |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 2503 | case '\'': |
| 2504 | pch++; |
| 2505 | if (*pch == '\0') |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2506 | expr_error(mon, "character constant expected"); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 2507 | n = *pch; |
| 2508 | pch++; |
| 2509 | if (*pch != '\'') |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2510 | expr_error(mon, "missing terminating \' character"); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 2511 | next(); |
| 2512 | break; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2513 | case '$': |
| 2514 | { |
| 2515 | char buf[128], *q; |
ths | 69b3497 | 2007-12-17 03:15:52 +0000 | [diff] [blame] | 2516 | target_long reg=0; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2517 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2518 | pch++; |
| 2519 | q = buf; |
| 2520 | while ((*pch >= 'a' && *pch <= 'z') || |
| 2521 | (*pch >= 'A' && *pch <= 'Z') || |
| 2522 | (*pch >= '0' && *pch <= '9') || |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2523 | *pch == '_' || *pch == '.') { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2524 | if ((q - buf) < sizeof(buf) - 1) |
| 2525 | *q++ = *pch; |
| 2526 | pch++; |
| 2527 | } |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 2528 | while (qemu_isspace(*pch)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2529 | pch++; |
| 2530 | *q = 0; |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 2531 | ret = get_monitor_def(®, buf); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2532 | if (ret == -1) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2533 | expr_error(mon, "unknown register"); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 2534 | else if (ret == -2) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2535 | expr_error(mon, "no cpu defined"); |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 2536 | n = reg; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2537 | } |
| 2538 | break; |
| 2539 | case '\0': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2540 | expr_error(mon, "unexpected end of expression"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2541 | n = 0; |
| 2542 | break; |
| 2543 | default: |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 2544 | #if TARGET_PHYS_ADDR_BITS > 32 |
bellard | 4f4fbf7 | 2006-06-25 18:28:12 +0000 | [diff] [blame] | 2545 | n = strtoull(pch, &p, 0); |
| 2546 | #else |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2547 | n = strtoul(pch, &p, 0); |
bellard | 4f4fbf7 | 2006-06-25 18:28:12 +0000 | [diff] [blame] | 2548 | #endif |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2549 | if (pch == p) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2550 | expr_error(mon, "invalid char in expression"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2551 | } |
| 2552 | pch = p; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 2553 | while (qemu_isspace(*pch)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2554 | pch++; |
| 2555 | break; |
| 2556 | } |
| 2557 | return n; |
| 2558 | } |
| 2559 | |
| 2560 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2561 | static int64_t expr_prod(Monitor *mon) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2562 | { |
blueswir1 | c2efc95 | 2007-09-25 17:28:42 +0000 | [diff] [blame] | 2563 | int64_t val, val2; |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2564 | int op; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2565 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2566 | val = expr_unary(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2567 | for(;;) { |
| 2568 | op = *pch; |
| 2569 | if (op != '*' && op != '/' && op != '%') |
| 2570 | break; |
| 2571 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2572 | val2 = expr_unary(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2573 | switch(op) { |
| 2574 | default: |
| 2575 | case '*': |
| 2576 | val *= val2; |
| 2577 | break; |
| 2578 | case '/': |
| 2579 | case '%': |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 2580 | if (val2 == 0) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2581 | expr_error(mon, "division by zero"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2582 | if (op == '/') |
| 2583 | val /= val2; |
| 2584 | else |
| 2585 | val %= val2; |
| 2586 | break; |
| 2587 | } |
| 2588 | } |
| 2589 | return val; |
| 2590 | } |
| 2591 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2592 | static int64_t expr_logic(Monitor *mon) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2593 | { |
blueswir1 | c2efc95 | 2007-09-25 17:28:42 +0000 | [diff] [blame] | 2594 | int64_t val, val2; |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2595 | int op; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2596 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2597 | val = expr_prod(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2598 | for(;;) { |
| 2599 | op = *pch; |
| 2600 | if (op != '&' && op != '|' && op != '^') |
| 2601 | break; |
| 2602 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2603 | val2 = expr_prod(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2604 | switch(op) { |
| 2605 | default: |
| 2606 | case '&': |
| 2607 | val &= val2; |
| 2608 | break; |
| 2609 | case '|': |
| 2610 | val |= val2; |
| 2611 | break; |
| 2612 | case '^': |
| 2613 | val ^= val2; |
| 2614 | break; |
| 2615 | } |
| 2616 | } |
| 2617 | return val; |
| 2618 | } |
| 2619 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2620 | static int64_t expr_sum(Monitor *mon) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2621 | { |
blueswir1 | c2efc95 | 2007-09-25 17:28:42 +0000 | [diff] [blame] | 2622 | int64_t val, val2; |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2623 | int op; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2624 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2625 | val = expr_logic(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2626 | for(;;) { |
| 2627 | op = *pch; |
| 2628 | if (op != '+' && op != '-') |
| 2629 | break; |
| 2630 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2631 | val2 = expr_logic(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2632 | if (op == '+') |
| 2633 | val += val2; |
| 2634 | else |
| 2635 | val -= val2; |
| 2636 | } |
| 2637 | return val; |
| 2638 | } |
| 2639 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2640 | static int get_expr(Monitor *mon, int64_t *pval, const char **pp) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2641 | { |
| 2642 | pch = *pp; |
| 2643 | if (setjmp(expr_env)) { |
| 2644 | *pp = pch; |
| 2645 | return -1; |
| 2646 | } |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 2647 | while (qemu_isspace(*pch)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2648 | pch++; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2649 | *pval = expr_sum(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2650 | *pp = pch; |
| 2651 | return 0; |
| 2652 | } |
| 2653 | |
| 2654 | static int get_str(char *buf, int buf_size, const char **pp) |
| 2655 | { |
| 2656 | const char *p; |
| 2657 | char *q; |
| 2658 | int c; |
| 2659 | |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 2660 | q = buf; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2661 | p = *pp; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 2662 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2663 | p++; |
| 2664 | if (*p == '\0') { |
| 2665 | fail: |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 2666 | *q = '\0'; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2667 | *pp = p; |
| 2668 | return -1; |
| 2669 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2670 | if (*p == '\"') { |
| 2671 | p++; |
| 2672 | while (*p != '\0' && *p != '\"') { |
| 2673 | if (*p == '\\') { |
| 2674 | p++; |
| 2675 | c = *p++; |
| 2676 | switch(c) { |
| 2677 | case 'n': |
| 2678 | c = '\n'; |
| 2679 | break; |
| 2680 | case 'r': |
| 2681 | c = '\r'; |
| 2682 | break; |
| 2683 | case '\\': |
| 2684 | case '\'': |
| 2685 | case '\"': |
| 2686 | break; |
| 2687 | default: |
| 2688 | qemu_printf("unsupported escape code: '\\%c'\n", c); |
| 2689 | goto fail; |
| 2690 | } |
| 2691 | if ((q - buf) < buf_size - 1) { |
| 2692 | *q++ = c; |
| 2693 | } |
| 2694 | } else { |
| 2695 | if ((q - buf) < buf_size - 1) { |
| 2696 | *q++ = *p; |
| 2697 | } |
| 2698 | p++; |
| 2699 | } |
| 2700 | } |
| 2701 | if (*p != '\"') { |
bellard | 5b60212 | 2004-05-22 21:41:05 +0000 | [diff] [blame] | 2702 | qemu_printf("unterminated string\n"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2703 | goto fail; |
| 2704 | } |
| 2705 | p++; |
| 2706 | } else { |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 2707 | while (*p != '\0' && !qemu_isspace(*p)) { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2708 | if ((q - buf) < buf_size - 1) { |
| 2709 | *q++ = *p; |
| 2710 | } |
| 2711 | p++; |
| 2712 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2713 | } |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 2714 | *q = '\0'; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2715 | *pp = p; |
| 2716 | return 0; |
| 2717 | } |
| 2718 | |
Luiz Capitulino | 4590fd8 | 2009-06-09 18:21:30 -0300 | [diff] [blame] | 2719 | /* |
| 2720 | * Store the command-name in cmdname, and return a pointer to |
| 2721 | * the remaining of the command string. |
| 2722 | */ |
| 2723 | static const char *get_command_name(const char *cmdline, |
| 2724 | char *cmdname, size_t nlen) |
| 2725 | { |
| 2726 | size_t len; |
| 2727 | const char *p, *pstart; |
| 2728 | |
| 2729 | p = cmdline; |
| 2730 | while (qemu_isspace(*p)) |
| 2731 | p++; |
| 2732 | if (*p == '\0') |
| 2733 | return NULL; |
| 2734 | pstart = p; |
| 2735 | while (*p != '\0' && *p != '/' && !qemu_isspace(*p)) |
| 2736 | p++; |
| 2737 | len = p - pstart; |
| 2738 | if (len > nlen - 1) |
| 2739 | len = nlen - 1; |
| 2740 | memcpy(cmdname, pstart, len); |
| 2741 | cmdname[len] = '\0'; |
| 2742 | return p; |
| 2743 | } |
| 2744 | |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 2745 | /** |
| 2746 | * Read key of 'type' into 'key' and return the current |
| 2747 | * 'type' pointer. |
| 2748 | */ |
| 2749 | static char *key_get_info(const char *type, char **key) |
| 2750 | { |
| 2751 | size_t len; |
| 2752 | char *p, *str; |
| 2753 | |
| 2754 | if (*type == ',') |
| 2755 | type++; |
| 2756 | |
| 2757 | p = strchr(type, ':'); |
| 2758 | if (!p) { |
| 2759 | *key = NULL; |
| 2760 | return NULL; |
| 2761 | } |
| 2762 | len = p - type; |
| 2763 | |
| 2764 | str = qemu_malloc(len + 1); |
| 2765 | memcpy(str, type, len); |
| 2766 | str[len] = '\0'; |
| 2767 | |
| 2768 | *key = str; |
| 2769 | return ++p; |
| 2770 | } |
| 2771 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2772 | static int default_fmt_format = 'x'; |
| 2773 | static int default_fmt_size = 4; |
| 2774 | |
| 2775 | #define MAX_ARGS 16 |
| 2776 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2777 | static const mon_cmd_t *monitor_parse_command(Monitor *mon, |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 2778 | const char *cmdline, |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 2779 | QDict *qdict) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2780 | { |
Luiz Capitulino | 4590fd8 | 2009-06-09 18:21:30 -0300 | [diff] [blame] | 2781 | const char *p, *typestr; |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 2782 | int c; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2783 | const mon_cmd_t *cmd; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2784 | char cmdname[256]; |
| 2785 | char buf[1024]; |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 2786 | char *key; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 2787 | |
| 2788 | #ifdef DEBUG |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2789 | monitor_printf(mon, "command='%s'\n", cmdline); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 2790 | #endif |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2791 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2792 | /* extract the command name */ |
Luiz Capitulino | 4590fd8 | 2009-06-09 18:21:30 -0300 | [diff] [blame] | 2793 | p = get_command_name(cmdline, cmdname, sizeof(cmdname)); |
| 2794 | if (!p) |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 2795 | return NULL; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2796 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2797 | /* find the command */ |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2798 | for(cmd = mon_cmds; cmd->name != NULL; cmd++) { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 2799 | if (compare_cmd(cmdname, cmd->name)) |
Luiz Capitulino | d91d9bf | 2009-06-09 18:21:54 -0300 | [diff] [blame] | 2800 | break; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 2801 | } |
Luiz Capitulino | d91d9bf | 2009-06-09 18:21:54 -0300 | [diff] [blame] | 2802 | |
| 2803 | if (cmd->name == NULL) { |
| 2804 | monitor_printf(mon, "unknown command: '%s'\n", cmdname); |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 2805 | return NULL; |
Luiz Capitulino | d91d9bf | 2009-06-09 18:21:54 -0300 | [diff] [blame] | 2806 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2807 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2808 | /* parse the parameters */ |
| 2809 | typestr = cmd->args_type; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2810 | for(;;) { |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 2811 | typestr = key_get_info(typestr, &key); |
| 2812 | if (!typestr) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2813 | break; |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 2814 | c = *typestr; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2815 | typestr++; |
| 2816 | switch(c) { |
| 2817 | case 'F': |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 2818 | case 'B': |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2819 | case 's': |
| 2820 | { |
| 2821 | int ret; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2822 | |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 2823 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2824 | p++; |
| 2825 | if (*typestr == '?') { |
| 2826 | typestr++; |
| 2827 | if (*p == '\0') { |
| 2828 | /* no optional string: NULL argument */ |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 2829 | break; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2830 | } |
| 2831 | } |
| 2832 | ret = get_str(buf, sizeof(buf), &p); |
| 2833 | if (ret < 0) { |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 2834 | switch(c) { |
| 2835 | case 'F': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2836 | monitor_printf(mon, "%s: filename expected\n", |
| 2837 | cmdname); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 2838 | break; |
| 2839 | case 'B': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2840 | monitor_printf(mon, "%s: block device name expected\n", |
| 2841 | cmdname); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 2842 | break; |
| 2843 | default: |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2844 | monitor_printf(mon, "%s: string expected\n", cmdname); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 2845 | break; |
| 2846 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2847 | goto fail; |
| 2848 | } |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 2849 | qdict_put(qdict, key, qstring_from_str(buf)); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2850 | } |
| 2851 | break; |
| 2852 | case '/': |
| 2853 | { |
| 2854 | int count, format, size; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2855 | |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 2856 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2857 | p++; |
| 2858 | if (*p == '/') { |
| 2859 | /* format found */ |
| 2860 | p++; |
| 2861 | count = 1; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 2862 | if (qemu_isdigit(*p)) { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2863 | count = 0; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 2864 | while (qemu_isdigit(*p)) { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2865 | count = count * 10 + (*p - '0'); |
| 2866 | p++; |
| 2867 | } |
| 2868 | } |
| 2869 | size = -1; |
| 2870 | format = -1; |
| 2871 | for(;;) { |
| 2872 | switch(*p) { |
| 2873 | case 'o': |
| 2874 | case 'd': |
| 2875 | case 'u': |
| 2876 | case 'x': |
| 2877 | case 'i': |
| 2878 | case 'c': |
| 2879 | format = *p++; |
| 2880 | break; |
| 2881 | case 'b': |
| 2882 | size = 1; |
| 2883 | p++; |
| 2884 | break; |
| 2885 | case 'h': |
| 2886 | size = 2; |
| 2887 | p++; |
| 2888 | break; |
| 2889 | case 'w': |
| 2890 | size = 4; |
| 2891 | p++; |
| 2892 | break; |
| 2893 | case 'g': |
| 2894 | case 'L': |
| 2895 | size = 8; |
| 2896 | p++; |
| 2897 | break; |
| 2898 | default: |
| 2899 | goto next; |
| 2900 | } |
| 2901 | } |
| 2902 | next: |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 2903 | if (*p != '\0' && !qemu_isspace(*p)) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2904 | monitor_printf(mon, "invalid char in format: '%c'\n", |
| 2905 | *p); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2906 | goto fail; |
| 2907 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2908 | if (format < 0) |
| 2909 | format = default_fmt_format; |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 2910 | if (format != 'i') { |
| 2911 | /* for 'i', not specifying a size gives -1 as size */ |
| 2912 | if (size < 0) |
| 2913 | size = default_fmt_size; |
aurel32 | e90f009 | 2008-10-01 21:45:51 +0000 | [diff] [blame] | 2914 | default_fmt_size = size; |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 2915 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2916 | default_fmt_format = format; |
| 2917 | } else { |
| 2918 | count = 1; |
| 2919 | format = default_fmt_format; |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 2920 | if (format != 'i') { |
| 2921 | size = default_fmt_size; |
| 2922 | } else { |
| 2923 | size = -1; |
| 2924 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2925 | } |
Luiz Capitulino | f7188bb | 2009-08-28 15:27:10 -0300 | [diff] [blame] | 2926 | qdict_put(qdict, "count", qint_from_int(count)); |
| 2927 | qdict_put(qdict, "format", qint_from_int(format)); |
| 2928 | qdict_put(qdict, "size", qint_from_int(size)); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2929 | } |
| 2930 | break; |
| 2931 | case 'i': |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2932 | case 'l': |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2933 | { |
blueswir1 | c2efc95 | 2007-09-25 17:28:42 +0000 | [diff] [blame] | 2934 | int64_t val; |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 2935 | |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 2936 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2937 | p++; |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 2938 | if (*typestr == '?' || *typestr == '.') { |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 2939 | if (*typestr == '?') { |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 2940 | if (*p == '\0') { |
| 2941 | typestr++; |
| 2942 | break; |
| 2943 | } |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 2944 | } else { |
| 2945 | if (*p == '.') { |
| 2946 | p++; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 2947 | while (qemu_isspace(*p)) |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 2948 | p++; |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 2949 | } else { |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 2950 | typestr++; |
| 2951 | break; |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 2952 | } |
| 2953 | } |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 2954 | typestr++; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2955 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2956 | if (get_expr(mon, &val, &p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2957 | goto fail; |
Luiz Capitulino | 675ebef | 2009-08-28 15:27:26 -0300 | [diff] [blame] | 2958 | /* Check if 'i' is greater than 32-bit */ |
| 2959 | if ((c == 'i') && ((val >> 32) & 0xffffffff)) { |
| 2960 | monitor_printf(mon, "\'%s\' has failed: ", cmdname); |
| 2961 | monitor_printf(mon, "integer is for 32-bit values\n"); |
| 2962 | goto fail; |
| 2963 | } |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 2964 | qdict_put(qdict, key, qint_from_int(val)); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2965 | } |
| 2966 | break; |
| 2967 | case '-': |
| 2968 | { |
| 2969 | int has_option; |
| 2970 | /* option */ |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2971 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2972 | c = *typestr++; |
| 2973 | if (c == '\0') |
| 2974 | goto bad_type; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 2975 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2976 | p++; |
| 2977 | has_option = 0; |
| 2978 | if (*p == '-') { |
| 2979 | p++; |
| 2980 | if (*p != c) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2981 | monitor_printf(mon, "%s: unsupported option -%c\n", |
| 2982 | cmdname, *p); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2983 | goto fail; |
| 2984 | } |
| 2985 | p++; |
| 2986 | has_option = 1; |
| 2987 | } |
Luiz Capitulino | f7188bb | 2009-08-28 15:27:10 -0300 | [diff] [blame] | 2988 | qdict_put(qdict, key, qint_from_int(has_option)); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2989 | } |
| 2990 | break; |
| 2991 | default: |
| 2992 | bad_type: |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2993 | monitor_printf(mon, "%s: unknown type '%c'\n", cmdname, c); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2994 | goto fail; |
| 2995 | } |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 2996 | qemu_free(key); |
| 2997 | key = NULL; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2998 | } |
| 2999 | /* check that all arguments were parsed */ |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3000 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3001 | p++; |
| 3002 | if (*p != '\0') { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3003 | monitor_printf(mon, "%s: extraneous characters at the end of line\n", |
| 3004 | cmdname); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3005 | goto fail; |
| 3006 | } |
| 3007 | |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3008 | return cmd; |
Gerd Hoffmann | ac7531e | 2009-08-14 10:36:06 +0200 | [diff] [blame] | 3009 | |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3010 | fail: |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3011 | qemu_free(key); |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3012 | return NULL; |
| 3013 | } |
| 3014 | |
| 3015 | static void monitor_handle_command(Monitor *mon, const char *cmdline) |
| 3016 | { |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3017 | QDict *qdict; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 3018 | const mon_cmd_t *cmd; |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3019 | |
| 3020 | qdict = qdict_new(); |
| 3021 | |
Luiz Capitulino | 590fb3b | 2009-08-28 15:27:24 -0300 | [diff] [blame] | 3022 | cmd = monitor_parse_command(mon, cmdline, qdict); |
Luiz Capitulino | 13917be | 2009-10-07 13:41:54 -0300 | [diff] [blame^] | 3023 | if (!cmd) |
| 3024 | goto out; |
| 3025 | |
| 3026 | qemu_errors_to_mon(mon); |
| 3027 | |
| 3028 | if (monitor_handler_ported(cmd)) { |
| 3029 | QObject *data = NULL; |
| 3030 | |
| 3031 | cmd->mhandler.cmd_new(mon, qdict, &data); |
| 3032 | if (data) |
| 3033 | cmd->user_print(mon, data); |
| 3034 | |
| 3035 | qobject_decref(data); |
| 3036 | } else { |
Luiz Capitulino | af4ce88 | 2009-10-07 13:41:52 -0300 | [diff] [blame] | 3037 | cmd->mhandler.cmd(mon, qdict); |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3038 | } |
| 3039 | |
Luiz Capitulino | 13917be | 2009-10-07 13:41:54 -0300 | [diff] [blame^] | 3040 | qemu_errors_to_previous(); |
| 3041 | |
| 3042 | out: |
Luiz Capitulino | f7188bb | 2009-08-28 15:27:10 -0300 | [diff] [blame] | 3043 | QDECREF(qdict); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 3044 | } |
| 3045 | |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3046 | static void cmd_completion(const char *name, const char *list) |
| 3047 | { |
| 3048 | const char *p, *pstart; |
| 3049 | char cmd[128]; |
| 3050 | int len; |
| 3051 | |
| 3052 | p = list; |
| 3053 | for(;;) { |
| 3054 | pstart = p; |
| 3055 | p = strchr(p, '|'); |
| 3056 | if (!p) |
| 3057 | p = pstart + strlen(pstart); |
| 3058 | len = p - pstart; |
| 3059 | if (len > sizeof(cmd) - 2) |
| 3060 | len = sizeof(cmd) - 2; |
| 3061 | memcpy(cmd, pstart, len); |
| 3062 | cmd[len] = '\0'; |
| 3063 | if (name[0] == '\0' || !strncmp(name, cmd, strlen(name))) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3064 | readline_add_completion(cur_mon->rs, cmd); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3065 | } |
| 3066 | if (*p == '\0') |
| 3067 | break; |
| 3068 | p++; |
| 3069 | } |
| 3070 | } |
| 3071 | |
| 3072 | static void file_completion(const char *input) |
| 3073 | { |
| 3074 | DIR *ffs; |
| 3075 | struct dirent *d; |
| 3076 | char path[1024]; |
| 3077 | char file[1024], file_prefix[1024]; |
| 3078 | int input_path_len; |
| 3079 | const char *p; |
| 3080 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3081 | p = strrchr(input, '/'); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3082 | if (!p) { |
| 3083 | input_path_len = 0; |
| 3084 | pstrcpy(file_prefix, sizeof(file_prefix), input); |
blueswir1 | 363a37d | 2008-08-21 17:58:08 +0000 | [diff] [blame] | 3085 | pstrcpy(path, sizeof(path), "."); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3086 | } else { |
| 3087 | input_path_len = p - input + 1; |
| 3088 | memcpy(path, input, input_path_len); |
| 3089 | if (input_path_len > sizeof(path) - 1) |
| 3090 | input_path_len = sizeof(path) - 1; |
| 3091 | path[input_path_len] = '\0'; |
| 3092 | pstrcpy(file_prefix, sizeof(file_prefix), p + 1); |
| 3093 | } |
| 3094 | #ifdef DEBUG_COMPLETION |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3095 | monitor_printf(cur_mon, "input='%s' path='%s' prefix='%s'\n", |
| 3096 | input, path, file_prefix); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3097 | #endif |
| 3098 | ffs = opendir(path); |
| 3099 | if (!ffs) |
| 3100 | return; |
| 3101 | for(;;) { |
| 3102 | struct stat sb; |
| 3103 | d = readdir(ffs); |
| 3104 | if (!d) |
| 3105 | break; |
| 3106 | if (strstart(d->d_name, file_prefix, NULL)) { |
| 3107 | memcpy(file, input, input_path_len); |
blueswir1 | 363a37d | 2008-08-21 17:58:08 +0000 | [diff] [blame] | 3108 | if (input_path_len < sizeof(file)) |
| 3109 | pstrcpy(file + input_path_len, sizeof(file) - input_path_len, |
| 3110 | d->d_name); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3111 | /* stat the file to find out if it's a directory. |
| 3112 | * In that case add a slash to speed up typing long paths |
| 3113 | */ |
| 3114 | stat(file, &sb); |
| 3115 | if(S_ISDIR(sb.st_mode)) |
blueswir1 | 363a37d | 2008-08-21 17:58:08 +0000 | [diff] [blame] | 3116 | pstrcat(file, sizeof(file), "/"); |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3117 | readline_add_completion(cur_mon->rs, file); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3118 | } |
| 3119 | } |
| 3120 | closedir(ffs); |
| 3121 | } |
| 3122 | |
aliguori | 51de976 | 2009-03-05 23:00:43 +0000 | [diff] [blame] | 3123 | static void block_completion_it(void *opaque, BlockDriverState *bs) |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3124 | { |
aliguori | 51de976 | 2009-03-05 23:00:43 +0000 | [diff] [blame] | 3125 | const char *name = bdrv_get_device_name(bs); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3126 | const char *input = opaque; |
| 3127 | |
| 3128 | if (input[0] == '\0' || |
| 3129 | !strncmp(name, (char *)input, strlen(input))) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3130 | readline_add_completion(cur_mon->rs, name); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3131 | } |
| 3132 | } |
| 3133 | |
| 3134 | /* NOTE: this parser is an approximate form of the real command parser */ |
| 3135 | static void parse_cmdline(const char *cmdline, |
| 3136 | int *pnb_args, char **args) |
| 3137 | { |
| 3138 | const char *p; |
| 3139 | int nb_args, ret; |
| 3140 | char buf[1024]; |
| 3141 | |
| 3142 | p = cmdline; |
| 3143 | nb_args = 0; |
| 3144 | for(;;) { |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3145 | while (qemu_isspace(*p)) |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3146 | p++; |
| 3147 | if (*p == '\0') |
| 3148 | break; |
| 3149 | if (nb_args >= MAX_ARGS) |
| 3150 | break; |
| 3151 | ret = get_str(buf, sizeof(buf), &p); |
| 3152 | args[nb_args] = qemu_strdup(buf); |
| 3153 | nb_args++; |
| 3154 | if (ret < 0) |
| 3155 | break; |
| 3156 | } |
| 3157 | *pnb_args = nb_args; |
| 3158 | } |
| 3159 | |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3160 | static const char *next_arg_type(const char *typestr) |
| 3161 | { |
| 3162 | const char *p = strchr(typestr, ':'); |
| 3163 | return (p != NULL ? ++p : typestr); |
| 3164 | } |
| 3165 | |
aliguori | 4c36ba3 | 2009-03-05 23:01:37 +0000 | [diff] [blame] | 3166 | static void monitor_find_completion(const char *cmdline) |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3167 | { |
| 3168 | const char *cmdname; |
| 3169 | char *args[MAX_ARGS]; |
| 3170 | int nb_args, i, len; |
| 3171 | const char *ptype, *str; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 3172 | const mon_cmd_t *cmd; |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 3173 | const KeyDef *key; |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3174 | |
| 3175 | parse_cmdline(cmdline, &nb_args, args); |
| 3176 | #ifdef DEBUG_COMPLETION |
| 3177 | for(i = 0; i < nb_args; i++) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3178 | monitor_printf(cur_mon, "arg%d = '%s'\n", i, (char *)args[i]); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3179 | } |
| 3180 | #endif |
| 3181 | |
| 3182 | /* if the line ends with a space, it means we want to complete the |
| 3183 | next arg */ |
| 3184 | len = strlen(cmdline); |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3185 | if (len > 0 && qemu_isspace(cmdline[len - 1])) { |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3186 | if (nb_args >= MAX_ARGS) |
| 3187 | return; |
| 3188 | args[nb_args++] = qemu_strdup(""); |
| 3189 | } |
| 3190 | if (nb_args <= 1) { |
| 3191 | /* command completion */ |
| 3192 | if (nb_args == 0) |
| 3193 | cmdname = ""; |
| 3194 | else |
| 3195 | cmdname = args[0]; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3196 | readline_set_completion_index(cur_mon->rs, strlen(cmdname)); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3197 | for(cmd = mon_cmds; cmd->name != NULL; cmd++) { |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3198 | cmd_completion(cmdname, cmd->name); |
| 3199 | } |
| 3200 | } else { |
| 3201 | /* find the command */ |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3202 | for(cmd = mon_cmds; cmd->name != NULL; cmd++) { |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3203 | if (compare_cmd(args[0], cmd->name)) |
| 3204 | goto found; |
| 3205 | } |
| 3206 | return; |
| 3207 | found: |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3208 | ptype = next_arg_type(cmd->args_type); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3209 | for(i = 0; i < nb_args - 2; i++) { |
| 3210 | if (*ptype != '\0') { |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3211 | ptype = next_arg_type(ptype); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3212 | while (*ptype == '?') |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3213 | ptype = next_arg_type(ptype); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3214 | } |
| 3215 | } |
| 3216 | str = args[nb_args - 1]; |
Blue Swirl | 2a1704a | 2009-08-23 20:10:28 +0000 | [diff] [blame] | 3217 | if (*ptype == '-' && ptype[1] != '\0') { |
| 3218 | ptype += 2; |
| 3219 | } |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3220 | switch(*ptype) { |
| 3221 | case 'F': |
| 3222 | /* file completion */ |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3223 | readline_set_completion_index(cur_mon->rs, strlen(str)); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3224 | file_completion(str); |
| 3225 | break; |
| 3226 | case 'B': |
| 3227 | /* block device name completion */ |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3228 | readline_set_completion_index(cur_mon->rs, strlen(str)); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3229 | bdrv_iterate(block_completion_it, (void *)str); |
| 3230 | break; |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 3231 | case 's': |
| 3232 | /* XXX: more generic ? */ |
| 3233 | if (!strcmp(cmd->name, "info")) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3234 | readline_set_completion_index(cur_mon->rs, strlen(str)); |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 3235 | for(cmd = info_cmds; cmd->name != NULL; cmd++) { |
| 3236 | cmd_completion(str, cmd->name); |
| 3237 | } |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 3238 | } else if (!strcmp(cmd->name, "sendkey")) { |
blueswir1 | e600d1e | 2009-03-08 17:42:02 +0000 | [diff] [blame] | 3239 | char *sep = strrchr(str, '-'); |
| 3240 | if (sep) |
| 3241 | str = sep + 1; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3242 | readline_set_completion_index(cur_mon->rs, strlen(str)); |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 3243 | for(key = key_defs; key->name != NULL; key++) { |
| 3244 | cmd_completion(str, key->name); |
| 3245 | } |
Jan Kiszka | f3353c6 | 2009-06-25 08:22:02 +0200 | [diff] [blame] | 3246 | } else if (!strcmp(cmd->name, "help|?")) { |
| 3247 | readline_set_completion_index(cur_mon->rs, strlen(str)); |
| 3248 | for (cmd = mon_cmds; cmd->name != NULL; cmd++) { |
| 3249 | cmd_completion(str, cmd->name); |
| 3250 | } |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 3251 | } |
| 3252 | break; |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3253 | default: |
| 3254 | break; |
| 3255 | } |
| 3256 | } |
| 3257 | for(i = 0; i < nb_args; i++) |
| 3258 | qemu_free(args[i]); |
| 3259 | } |
| 3260 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3261 | static int monitor_can_read(void *opaque) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 3262 | { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3263 | Monitor *mon = opaque; |
| 3264 | |
| 3265 | return (mon->suspend_cnt == 0) ? 128 : 0; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 3266 | } |
| 3267 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3268 | static void monitor_read(void *opaque, const uint8_t *buf, int size) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 3269 | { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3270 | Monitor *old_mon = cur_mon; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 3271 | int i; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3272 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3273 | cur_mon = opaque; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 3274 | |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 3275 | if (cur_mon->rs) { |
| 3276 | for (i = 0; i < size; i++) |
| 3277 | readline_handle_byte(cur_mon->rs, buf[i]); |
| 3278 | } else { |
| 3279 | if (size == 0 || buf[size - 1] != 0) |
| 3280 | monitor_printf(cur_mon, "corrupted command\n"); |
| 3281 | else |
| 3282 | monitor_handle_command(cur_mon, (char *)buf); |
| 3283 | } |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3284 | |
| 3285 | cur_mon = old_mon; |
| 3286 | } |
aliguori | d8f4460 | 2008-10-06 13:52:44 +0000 | [diff] [blame] | 3287 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3288 | static void monitor_command_cb(Monitor *mon, const char *cmdline, void *opaque) |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 3289 | { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3290 | monitor_suspend(mon); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3291 | monitor_handle_command(mon, cmdline); |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3292 | monitor_resume(mon); |
aliguori | d8f4460 | 2008-10-06 13:52:44 +0000 | [diff] [blame] | 3293 | } |
| 3294 | |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 3295 | int monitor_suspend(Monitor *mon) |
aliguori | d8f4460 | 2008-10-06 13:52:44 +0000 | [diff] [blame] | 3296 | { |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 3297 | if (!mon->rs) |
| 3298 | return -ENOTTY; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3299 | mon->suspend_cnt++; |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 3300 | return 0; |
aliguori | d8f4460 | 2008-10-06 13:52:44 +0000 | [diff] [blame] | 3301 | } |
| 3302 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3303 | void monitor_resume(Monitor *mon) |
aliguori | d8f4460 | 2008-10-06 13:52:44 +0000 | [diff] [blame] | 3304 | { |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 3305 | if (!mon->rs) |
| 3306 | return; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3307 | if (--mon->suspend_cnt == 0) |
| 3308 | readline_show_prompt(mon->rs); |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 3309 | } |
| 3310 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3311 | static void monitor_event(void *opaque, int event) |
ths | 86e94de | 2007-01-05 22:01:59 +0000 | [diff] [blame] | 3312 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3313 | Monitor *mon = opaque; |
| 3314 | |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 3315 | switch (event) { |
| 3316 | case CHR_EVENT_MUX_IN: |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 3317 | mon->mux_out = 0; |
| 3318 | if (mon->reset_seen) { |
| 3319 | readline_restart(mon->rs); |
| 3320 | monitor_resume(mon); |
| 3321 | monitor_flush(mon); |
| 3322 | } else { |
| 3323 | mon->suspend_cnt = 0; |
| 3324 | } |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 3325 | break; |
ths | 86e94de | 2007-01-05 22:01:59 +0000 | [diff] [blame] | 3326 | |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 3327 | case CHR_EVENT_MUX_OUT: |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 3328 | if (mon->reset_seen) { |
| 3329 | if (mon->suspend_cnt == 0) { |
| 3330 | monitor_printf(mon, "\n"); |
| 3331 | } |
| 3332 | monitor_flush(mon); |
| 3333 | monitor_suspend(mon); |
| 3334 | } else { |
| 3335 | mon->suspend_cnt++; |
| 3336 | } |
| 3337 | mon->mux_out = 1; |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 3338 | break; |
| 3339 | |
| 3340 | case CHR_EVENT_RESET: |
| 3341 | monitor_printf(mon, "QEMU %s monitor - type 'help' for more " |
| 3342 | "information\n", QEMU_VERSION); |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 3343 | if (!mon->mux_out) { |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 3344 | readline_show_prompt(mon->rs); |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 3345 | } |
| 3346 | mon->reset_seen = 1; |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 3347 | break; |
| 3348 | } |
ths | 86e94de | 2007-01-05 22:01:59 +0000 | [diff] [blame] | 3349 | } |
| 3350 | |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 3351 | |
| 3352 | /* |
| 3353 | * Local variables: |
| 3354 | * c-indent-level: 4 |
| 3355 | * c-basic-offset: 4 |
| 3356 | * tab-width: 8 |
| 3357 | * End: |
| 3358 | */ |
| 3359 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3360 | void monitor_init(CharDriverState *chr, int flags) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 3361 | { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3362 | static int is_first_init = 1; |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 3363 | Monitor *mon; |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 3364 | |
| 3365 | if (is_first_init) { |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 3366 | key_timer = qemu_new_timer(vm_clock, release_keys, NULL); |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 3367 | is_first_init = 0; |
| 3368 | } |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 3369 | |
| 3370 | mon = qemu_mallocz(sizeof(*mon)); |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 3371 | |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 3372 | mon->chr = chr; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3373 | mon->flags = flags; |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 3374 | if (flags & MONITOR_USE_READLINE) { |
| 3375 | mon->rs = readline_init(mon, monitor_find_completion); |
| 3376 | monitor_read_command(mon, 0); |
| 3377 | } |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 3378 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3379 | qemu_chr_add_handlers(chr, monitor_can_read, monitor_read, monitor_event, |
| 3380 | mon); |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 3381 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 3382 | QLIST_INSERT_HEAD(&mon_list, mon, entry); |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3383 | if (!cur_mon || (flags & MONITOR_IS_DEFAULT)) |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 3384 | cur_mon = mon; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 3385 | } |
| 3386 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3387 | static void bdrv_password_cb(Monitor *mon, const char *password, void *opaque) |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 3388 | { |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 3389 | BlockDriverState *bs = opaque; |
| 3390 | int ret = 0; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 3391 | |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 3392 | if (bdrv_set_key(bs, password) != 0) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3393 | monitor_printf(mon, "invalid password\n"); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 3394 | ret = -EPERM; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 3395 | } |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3396 | if (mon->password_completion_cb) |
| 3397 | mon->password_completion_cb(mon->password_opaque, ret); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 3398 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3399 | monitor_read_command(mon, 1); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 3400 | } |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 3401 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3402 | void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 3403 | BlockDriverCompletionFunc *completion_cb, |
| 3404 | void *opaque) |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 3405 | { |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 3406 | int err; |
| 3407 | |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 3408 | if (!bdrv_key_required(bs)) { |
| 3409 | if (completion_cb) |
| 3410 | completion_cb(opaque, 0); |
| 3411 | return; |
| 3412 | } |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 3413 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3414 | monitor_printf(mon, "%s (%s) is encrypted.\n", bdrv_get_device_name(bs), |
| 3415 | bdrv_get_encrypted_filename(bs)); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 3416 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3417 | mon->password_completion_cb = completion_cb; |
| 3418 | mon->password_opaque = opaque; |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 3419 | |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 3420 | err = monitor_read_password(mon, bdrv_password_cb, bs); |
| 3421 | |
| 3422 | if (err && completion_cb) |
| 3423 | completion_cb(opaque, err); |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 3424 | } |
Gerd Hoffmann | ac7531e | 2009-08-14 10:36:06 +0200 | [diff] [blame] | 3425 | |
| 3426 | typedef struct QemuErrorSink QemuErrorSink; |
| 3427 | struct QemuErrorSink { |
| 3428 | enum { |
| 3429 | ERR_SINK_FILE, |
| 3430 | ERR_SINK_MONITOR, |
| 3431 | } dest; |
| 3432 | union { |
| 3433 | FILE *fp; |
| 3434 | Monitor *mon; |
| 3435 | }; |
| 3436 | QemuErrorSink *previous; |
| 3437 | }; |
| 3438 | |
Blue Swirl | 528e93a | 2009-08-31 15:14:40 +0000 | [diff] [blame] | 3439 | static QemuErrorSink *qemu_error_sink; |
Gerd Hoffmann | ac7531e | 2009-08-14 10:36:06 +0200 | [diff] [blame] | 3440 | |
| 3441 | void qemu_errors_to_file(FILE *fp) |
| 3442 | { |
| 3443 | QemuErrorSink *sink; |
| 3444 | |
| 3445 | sink = qemu_mallocz(sizeof(*sink)); |
| 3446 | sink->dest = ERR_SINK_FILE; |
| 3447 | sink->fp = fp; |
| 3448 | sink->previous = qemu_error_sink; |
| 3449 | qemu_error_sink = sink; |
| 3450 | } |
| 3451 | |
| 3452 | void qemu_errors_to_mon(Monitor *mon) |
| 3453 | { |
| 3454 | QemuErrorSink *sink; |
| 3455 | |
| 3456 | sink = qemu_mallocz(sizeof(*sink)); |
| 3457 | sink->dest = ERR_SINK_MONITOR; |
| 3458 | sink->mon = mon; |
| 3459 | sink->previous = qemu_error_sink; |
| 3460 | qemu_error_sink = sink; |
| 3461 | } |
| 3462 | |
| 3463 | void qemu_errors_to_previous(void) |
| 3464 | { |
| 3465 | QemuErrorSink *sink; |
| 3466 | |
| 3467 | assert(qemu_error_sink != NULL); |
| 3468 | sink = qemu_error_sink; |
| 3469 | qemu_error_sink = sink->previous; |
| 3470 | qemu_free(sink); |
| 3471 | } |
| 3472 | |
| 3473 | void qemu_error(const char *fmt, ...) |
| 3474 | { |
| 3475 | va_list args; |
| 3476 | |
| 3477 | assert(qemu_error_sink != NULL); |
| 3478 | switch (qemu_error_sink->dest) { |
| 3479 | case ERR_SINK_FILE: |
| 3480 | va_start(args, fmt); |
| 3481 | vfprintf(qemu_error_sink->fp, fmt, args); |
| 3482 | va_end(args); |
| 3483 | break; |
| 3484 | case ERR_SINK_MONITOR: |
| 3485 | va_start(args, fmt); |
| 3486 | monitor_vprintf(qemu_error_sink->mon, fmt, args); |
| 3487 | va_end(args); |
| 3488 | break; |
| 3489 | } |
| 3490 | } |