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