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