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