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