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" |
Mark McLoughlin | 68ac40d | 2009-11-25 18:48:54 +0000 | [diff] [blame] | 35 | #include "net/slirp.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 36 | #include "qemu-char.h" |
Gerd Hoffmann | 7572150 | 2010-10-07 12:22:54 +0200 | [diff] [blame] | 37 | #include "ui/qemu-spice.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 38 | #include "sysemu.h" |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 39 | #include "monitor.h" |
| 40 | #include "readline.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 41 | #include "console.h" |
Markus Armbruster | 666daa6 | 2010-06-02 18:48:27 +0200 | [diff] [blame] | 42 | #include "blockdev.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 43 | #include "audio/audio.h" |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 44 | #include "disas.h" |
aliguori | df751fa | 2008-12-04 20:19:35 +0000 | [diff] [blame] | 45 | #include "balloon.h" |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 46 | #include "qemu-timer.h" |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 47 | #include "migration.h" |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 48 | #include "kvm.h" |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 49 | #include "acl.h" |
Luiz Capitulino | f7188bb | 2009-08-28 15:27:10 -0300 | [diff] [blame] | 50 | #include "qint.h" |
Markus Armbruster | 3350a4d | 2010-01-25 14:23:03 +0100 | [diff] [blame] | 51 | #include "qfloat.h" |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 52 | #include "qlist.h" |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 53 | #include "qbool.h" |
Luiz Capitulino | f7188bb | 2009-08-28 15:27:10 -0300 | [diff] [blame] | 54 | #include "qstring.h" |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 55 | #include "qjson.h" |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 56 | #include "json-streamer.h" |
| 57 | #include "json-parser.h" |
Blue Swirl | d08d6f0 | 2009-12-04 18:06:39 +0000 | [diff] [blame] | 58 | #include "osdep.h" |
Blue Swirl | 2b41f10 | 2011-06-19 20:38:22 +0000 | [diff] [blame] | 59 | #include "cpu.h" |
Stefan Hajnoczi | 89bd820 | 2011-09-23 08:23:06 +0100 | [diff] [blame] | 60 | #include "trace.h" |
Lluís | 31965ae | 2011-08-31 20:31:24 +0200 | [diff] [blame] | 61 | #include "trace/control.h" |
Lluís | 6d8a764 | 2011-08-31 20:30:43 +0200 | [diff] [blame] | 62 | #ifdef CONFIG_TRACE_SIMPLE |
Lluís | 31965ae | 2011-08-31 20:31:24 +0200 | [diff] [blame] | 63 | #include "trace/simple.h" |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 64 | #endif |
Gerd Hoffmann | 6f8c63f | 2010-10-11 18:03:51 +0200 | [diff] [blame] | 65 | #include "ui/qemu-spice.h" |
Blue Swirl | 314e298 | 2011-09-11 20:22:05 +0000 | [diff] [blame] | 66 | #include "memory.h" |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 67 | #include "qmp-commands.h" |
| 68 | #include "hmp.h" |
ths | 6a5bd30 | 2007-12-03 17:05:38 +0000 | [diff] [blame] | 69 | |
Jan Kiszka | 661f192 | 2011-10-16 11:53:13 +0200 | [diff] [blame] | 70 | /* for pic/irq_info */ |
| 71 | #if defined(TARGET_SPARC) |
| 72 | #include "hw/sun4m.h" |
| 73 | #endif |
| 74 | #include "hw/lm32_pic.h" |
| 75 | |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 76 | //#define DEBUG |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 77 | //#define DEBUG_COMPLETION |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 78 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 79 | /* |
| 80 | * Supported types: |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 81 | * |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 82 | * 'F' filename |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 83 | * 'B' block device name |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 84 | * 's' string (accept optional quote) |
Markus Armbruster | 361127d | 2010-02-10 20:24:35 +0100 | [diff] [blame] | 85 | * 'O' option string of the form NAME=VALUE,... |
| 86 | * parsed according to QemuOptsList given by its name |
| 87 | * Example: 'device:O' uses qemu_device_opts. |
| 88 | * Restriction: only lists with empty desc are supported |
| 89 | * TODO lift the restriction |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 90 | * 'i' 32 bit integer |
| 91 | * 'l' target long (32 or 64 bit) |
Markus Armbruster | 9fec543 | 2010-01-25 14:23:01 +0100 | [diff] [blame] | 92 | * 'M' just like 'l', except in user mode the value is |
| 93 | * multiplied by 2^20 (think Mebibyte) |
Jes Sorensen | dbc0c67 | 2010-10-21 17:15:47 +0200 | [diff] [blame] | 94 | * 'o' octets (aka bytes) |
| 95 | * user mode accepts an optional T, t, G, g, M, m, K, k |
| 96 | * suffix, which multiplies the value by 2^40 for |
| 97 | * suffixes T and t, 2^30 for suffixes G and g, 2^20 for |
| 98 | * M and m, 2^10 for K and k |
Markus Armbruster | fccfb11e | 2010-01-25 14:23:06 +0100 | [diff] [blame] | 99 | * 'T' double |
| 100 | * user mode accepts an optional ms, us, ns suffix, |
| 101 | * which divides the value by 1e3, 1e6, 1e9, respectively |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 102 | * '/' optional gdb-like print format (like "/10x") |
| 103 | * |
Luiz Capitulino | fb46660 | 2009-08-28 15:27:27 -0300 | [diff] [blame] | 104 | * '?' optional type (for all types, except '/') |
| 105 | * '.' other form of optional type (for 'i' and 'l') |
Markus Armbruster | 942cd1f | 2010-03-26 09:07:09 +0100 | [diff] [blame] | 106 | * 'b' boolean |
| 107 | * user mode accepts "on" or "off" |
Luiz Capitulino | fb46660 | 2009-08-28 15:27:27 -0300 | [diff] [blame] | 108 | * '-' optional parameter (eg. '-f') |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 109 | * |
| 110 | */ |
| 111 | |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 112 | typedef struct MonitorCompletionData MonitorCompletionData; |
| 113 | struct MonitorCompletionData { |
| 114 | Monitor *mon; |
| 115 | void (*user_print)(Monitor *mon, const QObject *data); |
| 116 | }; |
| 117 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 118 | typedef struct mon_cmd_t { |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 119 | const char *name; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 120 | const char *args_type; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 121 | const char *params; |
| 122 | const char *help; |
Luiz Capitulino | a2876f5 | 2009-10-07 13:41:53 -0300 | [diff] [blame] | 123 | void (*user_print)(Monitor *mon, const QObject *data); |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 124 | union { |
| 125 | void (*info)(Monitor *mon); |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 126 | void (*info_new)(Monitor *mon, QObject **ret_data); |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 127 | int (*info_async)(Monitor *mon, MonitorCompletion *cb, void *opaque); |
Luiz Capitulino | af4ce88 | 2009-10-07 13:41:52 -0300 | [diff] [blame] | 128 | void (*cmd)(Monitor *mon, const QDict *qdict); |
Luiz Capitulino | 261394d | 2010-02-10 23:50:02 -0200 | [diff] [blame] | 129 | int (*cmd_new)(Monitor *mon, const QDict *params, QObject **ret_data); |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 130 | int (*cmd_async)(Monitor *mon, const QDict *params, |
| 131 | MonitorCompletion *cb, void *opaque); |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 132 | } mhandler; |
Anthony Liguori | e319360 | 2011-09-02 12:34:47 -0500 | [diff] [blame] | 133 | bool qapi; |
Jan Kiszka | 8ac470c | 2010-06-16 00:38:39 +0200 | [diff] [blame] | 134 | int flags; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 135 | } mon_cmd_t; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 136 | |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 137 | /* file descriptors passed via SCM_RIGHTS */ |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 138 | typedef struct mon_fd_t mon_fd_t; |
| 139 | struct mon_fd_t { |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 140 | char *name; |
| 141 | int fd; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 142 | QLIST_ENTRY(mon_fd_t) next; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 143 | }; |
| 144 | |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 145 | typedef struct MonitorControl { |
| 146 | QObject *id; |
| 147 | JSONMessageParser parser; |
Luiz Capitulino | 4a7e119 | 2010-02-04 18:10:05 -0200 | [diff] [blame] | 148 | int command_mode; |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 149 | } MonitorControl; |
| 150 | |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 151 | struct Monitor { |
| 152 | CharDriverState *chr; |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 153 | int mux_out; |
| 154 | int reset_seen; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 155 | int flags; |
| 156 | int suspend_cnt; |
| 157 | uint8_t outbuf[1024]; |
| 158 | int outbuf_index; |
| 159 | ReadLineState *rs; |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 160 | MonitorControl *mc; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 161 | CPUState *mon_cpu; |
| 162 | BlockDriverCompletionFunc *password_completion_cb; |
| 163 | void *password_opaque; |
Luiz Capitulino | 10e4f60 | 2010-02-10 23:50:06 -0200 | [diff] [blame] | 164 | #ifdef CONFIG_DEBUG_MONITOR |
| 165 | int print_calls_nr; |
| 166 | #endif |
Luiz Capitulino | 8204a91 | 2009-11-18 23:05:31 -0200 | [diff] [blame] | 167 | QError *error; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 168 | QLIST_HEAD(,mon_fd_t) fds; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 169 | QLIST_ENTRY(Monitor) entry; |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 170 | }; |
| 171 | |
Luiz Capitulino | b4475aa | 2010-02-10 23:50:03 -0200 | [diff] [blame] | 172 | #ifdef CONFIG_DEBUG_MONITOR |
| 173 | #define MON_DEBUG(fmt, ...) do { \ |
| 174 | fprintf(stderr, "Monitor: "); \ |
| 175 | fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) |
Luiz Capitulino | 10e4f60 | 2010-02-10 23:50:06 -0200 | [diff] [blame] | 176 | |
| 177 | static inline void mon_print_count_inc(Monitor *mon) |
| 178 | { |
| 179 | mon->print_calls_nr++; |
| 180 | } |
| 181 | |
| 182 | static inline void mon_print_count_init(Monitor *mon) |
| 183 | { |
| 184 | mon->print_calls_nr = 0; |
| 185 | } |
| 186 | |
| 187 | static inline int mon_print_count_get(const Monitor *mon) |
| 188 | { |
| 189 | return mon->print_calls_nr; |
| 190 | } |
| 191 | |
Luiz Capitulino | b4475aa | 2010-02-10 23:50:03 -0200 | [diff] [blame] | 192 | #else /* !CONFIG_DEBUG_MONITOR */ |
| 193 | #define MON_DEBUG(fmt, ...) do { } while (0) |
Luiz Capitulino | 10e4f60 | 2010-02-10 23:50:06 -0200 | [diff] [blame] | 194 | static inline void mon_print_count_inc(Monitor *mon) { } |
| 195 | static inline void mon_print_count_init(Monitor *mon) { } |
| 196 | static inline int mon_print_count_get(const Monitor *mon) { return 0; } |
Luiz Capitulino | b4475aa | 2010-02-10 23:50:03 -0200 | [diff] [blame] | 197 | #endif /* CONFIG_DEBUG_MONITOR */ |
| 198 | |
Luiz Capitulino | 2dbc8db | 2010-05-26 16:13:09 -0300 | [diff] [blame] | 199 | /* QMP checker flags */ |
| 200 | #define QMP_ACCEPT_UNKNOWNS 1 |
| 201 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 202 | static QLIST_HEAD(mon_list, Monitor) mon_list; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 203 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 204 | static const mon_cmd_t mon_cmds[]; |
| 205 | static const mon_cmd_t info_cmds[]; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 206 | |
Luiz Capitulino | f36b4af | 2010-09-15 17:17:45 -0300 | [diff] [blame] | 207 | static const mon_cmd_t qmp_cmds[]; |
Luiz Capitulino | 3e12a75 | 2010-09-15 17:20:33 -0300 | [diff] [blame] | 208 | static const mon_cmd_t qmp_query_cmds[]; |
Luiz Capitulino | f36b4af | 2010-09-15 17:17:45 -0300 | [diff] [blame] | 209 | |
Markus Armbruster | 8631b60 | 2010-02-18 11:41:55 +0100 | [diff] [blame] | 210 | Monitor *cur_mon; |
| 211 | Monitor *default_mon; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 212 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 213 | static void monitor_command_cb(Monitor *mon, const char *cmdline, |
| 214 | void *opaque); |
aliguori | 83ab795 | 2008-08-19 14:44:22 +0000 | [diff] [blame] | 215 | |
Luiz Capitulino | 09069b1 | 2010-02-04 18:10:06 -0200 | [diff] [blame] | 216 | static inline int qmp_cmd_mode(const Monitor *mon) |
| 217 | { |
| 218 | return (mon->mc ? mon->mc->command_mode : 0); |
| 219 | } |
| 220 | |
Luiz Capitulino | 418173c | 2009-11-26 22:58:51 -0200 | [diff] [blame] | 221 | /* Return true if in control mode, false otherwise */ |
| 222 | static inline int monitor_ctrl_mode(const Monitor *mon) |
| 223 | { |
| 224 | return (mon->flags & MONITOR_USE_CONTROL); |
| 225 | } |
| 226 | |
Markus Armbruster | 6620d3c | 2010-02-11 17:05:43 +0100 | [diff] [blame] | 227 | /* Return non-zero iff we have a current monitor, and it is in QMP mode. */ |
| 228 | int monitor_cur_is_qmp(void) |
| 229 | { |
| 230 | return cur_mon && monitor_ctrl_mode(cur_mon); |
| 231 | } |
| 232 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 233 | static void monitor_read_command(Monitor *mon, int show_prompt) |
| 234 | { |
Luiz Capitulino | 183e6e5 | 2009-12-14 18:53:23 -0200 | [diff] [blame] | 235 | if (!mon->rs) |
| 236 | return; |
| 237 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 238 | readline_start(mon->rs, "(qemu) ", 0, monitor_command_cb, NULL); |
| 239 | if (show_prompt) |
| 240 | readline_show_prompt(mon->rs); |
| 241 | } |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 242 | |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 243 | static int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, |
| 244 | void *opaque) |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 245 | { |
Luiz Capitulino | 94171e1 | 2009-12-07 21:37:00 +0100 | [diff] [blame] | 246 | if (monitor_ctrl_mode(mon)) { |
Markus Armbruster | ab5b027 | 2010-03-02 18:15:09 +0100 | [diff] [blame] | 247 | qerror_report(QERR_MISSING_PARAMETER, "password"); |
Luiz Capitulino | 94171e1 | 2009-12-07 21:37:00 +0100 | [diff] [blame] | 248 | return -EINVAL; |
| 249 | } else if (mon->rs) { |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 250 | readline_start(mon->rs, "Password: ", 1, readline_func, opaque); |
| 251 | /* prompt is printed on return from the command handler */ |
| 252 | return 0; |
| 253 | } else { |
| 254 | monitor_printf(mon, "terminal does not support password prompting\n"); |
| 255 | return -ENOTTY; |
| 256 | } |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 257 | } |
| 258 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 259 | void monitor_flush(Monitor *mon) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 260 | { |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 261 | if (mon && mon->outbuf_index != 0 && !mon->mux_out) { |
Anthony Liguori | 2cc6e0a | 2011-08-15 11:17:28 -0500 | [diff] [blame] | 262 | qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index); |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 263 | mon->outbuf_index = 0; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
| 267 | /* flush at every end of line or if the buffer is full */ |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 268 | static void monitor_puts(Monitor *mon, const char *str) |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 269 | { |
ths | 60fe76f | 2007-12-16 03:02:09 +0000 | [diff] [blame] | 270 | char c; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 271 | |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 272 | for(;;) { |
| 273 | c = *str++; |
| 274 | if (c == '\0') |
| 275 | break; |
bellard | 7ba1260 | 2006-07-14 20:26:42 +0000 | [diff] [blame] | 276 | if (c == '\n') |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 277 | mon->outbuf[mon->outbuf_index++] = '\r'; |
| 278 | mon->outbuf[mon->outbuf_index++] = c; |
| 279 | if (mon->outbuf_index >= (sizeof(mon->outbuf) - 1) |
| 280 | || c == '\n') |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 281 | monitor_flush(mon); |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 285 | void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 286 | { |
Luiz Capitulino | b8b0826 | 2010-02-10 23:50:04 -0200 | [diff] [blame] | 287 | char buf[4096]; |
| 288 | |
Luiz Capitulino | 2daa119 | 2009-12-14 18:53:24 -0200 | [diff] [blame] | 289 | if (!mon) |
| 290 | return; |
| 291 | |
Luiz Capitulino | 10e4f60 | 2010-02-10 23:50:06 -0200 | [diff] [blame] | 292 | mon_print_count_inc(mon); |
| 293 | |
Luiz Capitulino | b8b0826 | 2010-02-10 23:50:04 -0200 | [diff] [blame] | 294 | if (monitor_ctrl_mode(mon)) { |
Luiz Capitulino | b8b0826 | 2010-02-10 23:50:04 -0200 | [diff] [blame] | 295 | return; |
Luiz Capitulino | 4a29a85 | 2009-11-26 22:59:05 -0200 | [diff] [blame] | 296 | } |
Luiz Capitulino | b8b0826 | 2010-02-10 23:50:04 -0200 | [diff] [blame] | 297 | |
| 298 | vsnprintf(buf, sizeof(buf), fmt, ap); |
| 299 | monitor_puts(mon, buf); |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 300 | } |
| 301 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 302 | void monitor_printf(Monitor *mon, const char *fmt, ...) |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 303 | { |
| 304 | va_list ap; |
| 305 | va_start(ap, fmt); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 306 | monitor_vprintf(mon, fmt, ap); |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 307 | va_end(ap); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 308 | } |
| 309 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 310 | void monitor_print_filename(Monitor *mon, const char *filename) |
ths | fef3074 | 2006-12-22 14:11:32 +0000 | [diff] [blame] | 311 | { |
| 312 | int i; |
| 313 | |
| 314 | for (i = 0; filename[i]; i++) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 315 | switch (filename[i]) { |
| 316 | case ' ': |
| 317 | case '"': |
| 318 | case '\\': |
| 319 | monitor_printf(mon, "\\%c", filename[i]); |
| 320 | break; |
| 321 | case '\t': |
| 322 | monitor_printf(mon, "\\t"); |
| 323 | break; |
| 324 | case '\r': |
| 325 | monitor_printf(mon, "\\r"); |
| 326 | break; |
| 327 | case '\n': |
| 328 | monitor_printf(mon, "\\n"); |
| 329 | break; |
| 330 | default: |
| 331 | monitor_printf(mon, "%c", filename[i]); |
| 332 | break; |
| 333 | } |
ths | fef3074 | 2006-12-22 14:11:32 +0000 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
Stefan Weil | 8b7968f | 2010-09-23 21:28:05 +0200 | [diff] [blame] | 337 | static int GCC_FMT_ATTR(2, 3) monitor_fprintf(FILE *stream, |
| 338 | const char *fmt, ...) |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 339 | { |
| 340 | va_list ap; |
| 341 | va_start(ap, fmt); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 342 | monitor_vprintf((Monitor *)stream, fmt, ap); |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 343 | va_end(ap); |
| 344 | return 0; |
| 345 | } |
| 346 | |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 347 | static void monitor_user_noop(Monitor *mon, const QObject *data) { } |
| 348 | |
Luiz Capitulino | 9e80721 | 2010-09-16 10:58:59 -0300 | [diff] [blame] | 349 | static inline int handler_is_qobject(const mon_cmd_t *cmd) |
Luiz Capitulino | 13917be | 2009-10-07 13:41:54 -0300 | [diff] [blame] | 350 | { |
| 351 | return cmd->user_print != NULL; |
| 352 | } |
| 353 | |
Luiz Capitulino | 4903de0 | 2010-09-16 11:01:32 -0300 | [diff] [blame] | 354 | static inline bool handler_is_async(const mon_cmd_t *cmd) |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 355 | { |
Jan Kiszka | 8ac470c | 2010-06-16 00:38:39 +0200 | [diff] [blame] | 356 | return cmd->flags & MONITOR_CMD_ASYNC; |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 357 | } |
| 358 | |
Luiz Capitulino | 8204a91 | 2009-11-18 23:05:31 -0200 | [diff] [blame] | 359 | static inline int monitor_has_error(const Monitor *mon) |
| 360 | { |
| 361 | return mon->error != NULL; |
| 362 | } |
| 363 | |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 364 | static void monitor_json_emitter(Monitor *mon, const QObject *data) |
| 365 | { |
| 366 | QString *json; |
| 367 | |
Luiz Capitulino | 83a27d4 | 2010-11-22 17:10:37 -0200 | [diff] [blame] | 368 | json = mon->flags & MONITOR_USE_PRETTY ? qobject_to_json_pretty(data) : |
| 369 | qobject_to_json(data); |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 370 | assert(json != NULL); |
| 371 | |
Luiz Capitulino | b8b0826 | 2010-02-10 23:50:04 -0200 | [diff] [blame] | 372 | qstring_append_chr(json, '\n'); |
| 373 | monitor_puts(mon, qstring_get_str(json)); |
Luiz Capitulino | 4a29a85 | 2009-11-26 22:59:05 -0200 | [diff] [blame] | 374 | |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 375 | QDECREF(json); |
| 376 | } |
| 377 | |
Luiz Capitulino | 25b422e | 2009-11-26 22:58:59 -0200 | [diff] [blame] | 378 | static void monitor_protocol_emitter(Monitor *mon, QObject *data) |
| 379 | { |
| 380 | QDict *qmp; |
| 381 | |
Stefan Hajnoczi | 89bd820 | 2011-09-23 08:23:06 +0100 | [diff] [blame] | 382 | trace_monitor_protocol_emitter(mon); |
| 383 | |
Luiz Capitulino | 25b422e | 2009-11-26 22:58:59 -0200 | [diff] [blame] | 384 | qmp = qdict_new(); |
| 385 | |
| 386 | if (!monitor_has_error(mon)) { |
| 387 | /* success response */ |
| 388 | if (data) { |
| 389 | qobject_incref(data); |
| 390 | qdict_put_obj(qmp, "return", data); |
| 391 | } else { |
Luiz Capitulino | 0abc657 | 2009-12-18 13:25:00 -0200 | [diff] [blame] | 392 | /* return an empty QDict by default */ |
| 393 | qdict_put(qmp, "return", qdict_new()); |
Luiz Capitulino | 25b422e | 2009-11-26 22:58:59 -0200 | [diff] [blame] | 394 | } |
| 395 | } else { |
| 396 | /* error response */ |
Markus Armbruster | 77e595e | 2009-12-07 21:37:16 +0100 | [diff] [blame] | 397 | qdict_put(mon->error->error, "desc", qerror_human(mon->error)); |
Luiz Capitulino | 25b422e | 2009-11-26 22:58:59 -0200 | [diff] [blame] | 398 | qdict_put(qmp, "error", mon->error->error); |
| 399 | QINCREF(mon->error->error); |
| 400 | QDECREF(mon->error); |
| 401 | mon->error = NULL; |
| 402 | } |
| 403 | |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 404 | if (mon->mc->id) { |
| 405 | qdict_put_obj(qmp, "id", mon->mc->id); |
| 406 | mon->mc->id = NULL; |
| 407 | } |
| 408 | |
Luiz Capitulino | 25b422e | 2009-11-26 22:58:59 -0200 | [diff] [blame] | 409 | monitor_json_emitter(mon, QOBJECT(qmp)); |
| 410 | QDECREF(qmp); |
| 411 | } |
| 412 | |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 413 | static void timestamp_put(QDict *qdict) |
| 414 | { |
| 415 | int err; |
| 416 | QObject *obj; |
Blue Swirl | d08d6f0 | 2009-12-04 18:06:39 +0000 | [diff] [blame] | 417 | qemu_timeval tv; |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 418 | |
Blue Swirl | d08d6f0 | 2009-12-04 18:06:39 +0000 | [diff] [blame] | 419 | err = qemu_gettimeofday(&tv); |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 420 | if (err < 0) |
| 421 | return; |
| 422 | |
| 423 | obj = qobject_from_jsonf("{ 'seconds': %" PRId64 ", " |
| 424 | "'microseconds': %" PRId64 " }", |
| 425 | (int64_t) tv.tv_sec, (int64_t) tv.tv_usec); |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 426 | qdict_put_obj(qdict, "timestamp", obj); |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * monitor_protocol_event(): Generate a Monitor event |
| 431 | * |
| 432 | * Event-specific data can be emitted through the (optional) 'data' parameter. |
| 433 | */ |
| 434 | void monitor_protocol_event(MonitorEvent event, QObject *data) |
| 435 | { |
| 436 | QDict *qmp; |
| 437 | const char *event_name; |
Adam Litke | f039a56 | 2010-01-15 08:34:02 -0600 | [diff] [blame] | 438 | Monitor *mon; |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 439 | |
Blue Swirl | 242cd00 | 2009-12-04 18:05:45 +0000 | [diff] [blame] | 440 | assert(event < QEVENT_MAX); |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 441 | |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 442 | switch (event) { |
Blue Swirl | 242cd00 | 2009-12-04 18:05:45 +0000 | [diff] [blame] | 443 | case QEVENT_SHUTDOWN: |
Luiz Capitulino | b1a15e7 | 2009-11-26 22:59:04 -0200 | [diff] [blame] | 444 | event_name = "SHUTDOWN"; |
| 445 | break; |
Blue Swirl | 242cd00 | 2009-12-04 18:05:45 +0000 | [diff] [blame] | 446 | case QEVENT_RESET: |
Luiz Capitulino | b1a15e7 | 2009-11-26 22:59:04 -0200 | [diff] [blame] | 447 | event_name = "RESET"; |
| 448 | break; |
Blue Swirl | 242cd00 | 2009-12-04 18:05:45 +0000 | [diff] [blame] | 449 | case QEVENT_POWERDOWN: |
Luiz Capitulino | b1a15e7 | 2009-11-26 22:59:04 -0200 | [diff] [blame] | 450 | event_name = "POWERDOWN"; |
| 451 | break; |
Blue Swirl | 242cd00 | 2009-12-04 18:05:45 +0000 | [diff] [blame] | 452 | case QEVENT_STOP: |
Luiz Capitulino | b1a15e7 | 2009-11-26 22:59:04 -0200 | [diff] [blame] | 453 | event_name = "STOP"; |
| 454 | break; |
Luiz Capitulino | 6ed2c48 | 2010-04-27 20:35:59 -0300 | [diff] [blame] | 455 | case QEVENT_RESUME: |
| 456 | event_name = "RESUME"; |
| 457 | break; |
Luiz Capitulino | 586153d | 2010-01-14 14:50:57 -0200 | [diff] [blame] | 458 | case QEVENT_VNC_CONNECTED: |
| 459 | event_name = "VNC_CONNECTED"; |
| 460 | break; |
Luiz Capitulino | 0d2ed46 | 2010-01-14 14:50:59 -0200 | [diff] [blame] | 461 | case QEVENT_VNC_INITIALIZED: |
| 462 | event_name = "VNC_INITIALIZED"; |
| 463 | break; |
Luiz Capitulino | 0d72f3d | 2010-01-14 14:50:58 -0200 | [diff] [blame] | 464 | case QEVENT_VNC_DISCONNECTED: |
| 465 | event_name = "VNC_DISCONNECTED"; |
| 466 | break; |
Luiz Capitulino | aa1db6e | 2010-02-03 12:41:00 -0200 | [diff] [blame] | 467 | case QEVENT_BLOCK_IO_ERROR: |
| 468 | event_name = "BLOCK_IO_ERROR"; |
| 469 | break; |
Luiz Capitulino | 80cd347 | 2010-02-25 12:11:44 -0300 | [diff] [blame] | 470 | case QEVENT_RTC_CHANGE: |
| 471 | event_name = "RTC_CHANGE"; |
| 472 | break; |
Luiz Capitulino | 9eedeb3 | 2010-02-25 12:13:04 -0300 | [diff] [blame] | 473 | case QEVENT_WATCHDOG: |
| 474 | event_name = "WATCHDOG"; |
| 475 | break; |
Gerd Hoffmann | 6f8c63f | 2010-10-11 18:03:51 +0200 | [diff] [blame] | 476 | case QEVENT_SPICE_CONNECTED: |
| 477 | event_name = "SPICE_CONNECTED"; |
| 478 | break; |
| 479 | case QEVENT_SPICE_INITIALIZED: |
| 480 | event_name = "SPICE_INITIALIZED"; |
| 481 | break; |
| 482 | case QEVENT_SPICE_DISCONNECTED: |
| 483 | event_name = "SPICE_DISCONNECTED"; |
| 484 | break; |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 485 | default: |
| 486 | abort(); |
| 487 | break; |
| 488 | } |
| 489 | |
| 490 | qmp = qdict_new(); |
| 491 | timestamp_put(qmp); |
| 492 | qdict_put(qmp, "event", qstring_from_str(event_name)); |
Luiz Capitulino | 3d72f9a | 2010-01-08 16:45:53 -0200 | [diff] [blame] | 493 | if (data) { |
| 494 | qobject_incref(data); |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 495 | qdict_put_obj(qmp, "data", data); |
Luiz Capitulino | 3d72f9a | 2010-01-08 16:45:53 -0200 | [diff] [blame] | 496 | } |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 497 | |
Adam Litke | f039a56 | 2010-01-15 08:34:02 -0600 | [diff] [blame] | 498 | QLIST_FOREACH(mon, &mon_list, entry) { |
Luiz Capitulino | 09069b1 | 2010-02-04 18:10:06 -0200 | [diff] [blame] | 499 | if (monitor_ctrl_mode(mon) && qmp_cmd_mode(mon)) { |
Luiz Capitulino | 23fabed | 2010-01-20 10:37:59 -0200 | [diff] [blame] | 500 | monitor_json_emitter(mon, QOBJECT(qmp)); |
| 501 | } |
Adam Litke | f039a56 | 2010-01-15 08:34:02 -0600 | [diff] [blame] | 502 | } |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 503 | QDECREF(qmp); |
| 504 | } |
| 505 | |
Luiz Capitulino | ef4b7ee | 2010-02-10 23:49:48 -0200 | [diff] [blame] | 506 | static int do_qmp_capabilities(Monitor *mon, const QDict *params, |
| 507 | QObject **ret_data) |
Luiz Capitulino | 4a7e119 | 2010-02-04 18:10:05 -0200 | [diff] [blame] | 508 | { |
| 509 | /* Will setup QMP capabilities in the future */ |
| 510 | if (monitor_ctrl_mode(mon)) { |
| 511 | mon->mc->command_mode = 1; |
| 512 | } |
Luiz Capitulino | ef4b7ee | 2010-02-10 23:49:48 -0200 | [diff] [blame] | 513 | |
| 514 | return 0; |
Luiz Capitulino | 4a7e119 | 2010-02-04 18:10:05 -0200 | [diff] [blame] | 515 | } |
| 516 | |
Luiz Capitulino | 0268d97 | 2010-10-22 10:08:02 -0200 | [diff] [blame] | 517 | static int mon_set_cpu(int cpu_index); |
| 518 | static void handle_user_command(Monitor *mon, const char *cmdline); |
| 519 | |
| 520 | static int do_hmp_passthrough(Monitor *mon, const QDict *params, |
| 521 | QObject **ret_data) |
| 522 | { |
| 523 | int ret = 0; |
| 524 | Monitor *old_mon, hmp; |
| 525 | CharDriverState mchar; |
| 526 | |
| 527 | memset(&hmp, 0, sizeof(hmp)); |
| 528 | qemu_chr_init_mem(&mchar); |
| 529 | hmp.chr = &mchar; |
| 530 | |
| 531 | old_mon = cur_mon; |
| 532 | cur_mon = &hmp; |
| 533 | |
| 534 | if (qdict_haskey(params, "cpu-index")) { |
| 535 | ret = mon_set_cpu(qdict_get_int(params, "cpu-index")); |
| 536 | if (ret < 0) { |
| 537 | cur_mon = old_mon; |
| 538 | qerror_report(QERR_INVALID_PARAMETER_VALUE, "cpu-index", "a CPU number"); |
| 539 | goto out; |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | handle_user_command(&hmp, qdict_get_str(params, "command-line")); |
| 544 | cur_mon = old_mon; |
| 545 | |
| 546 | if (qemu_chr_mem_osize(hmp.chr) > 0) { |
| 547 | *ret_data = QOBJECT(qemu_chr_mem_to_qs(hmp.chr)); |
| 548 | } |
| 549 | |
| 550 | out: |
| 551 | qemu_chr_close_mem(hmp.chr); |
| 552 | return ret; |
| 553 | } |
| 554 | |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 555 | static int compare_cmd(const char *name, const char *list) |
| 556 | { |
| 557 | const char *p, *pstart; |
| 558 | int len; |
| 559 | len = strlen(name); |
| 560 | p = list; |
| 561 | for(;;) { |
| 562 | pstart = p; |
| 563 | p = strchr(p, '|'); |
| 564 | if (!p) |
| 565 | p = pstart + strlen(pstart); |
| 566 | if ((p - pstart) == len && !memcmp(pstart, name, len)) |
| 567 | return 1; |
| 568 | if (*p == '\0') |
| 569 | break; |
| 570 | p++; |
| 571 | } |
| 572 | return 0; |
| 573 | } |
| 574 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 575 | static void help_cmd_dump(Monitor *mon, const mon_cmd_t *cmds, |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 576 | const char *prefix, const char *name) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 577 | { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 578 | const mon_cmd_t *cmd; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 579 | |
| 580 | for(cmd = cmds; cmd->name != NULL; cmd++) { |
| 581 | if (!name || !strcmp(name, cmd->name)) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 582 | monitor_printf(mon, "%s%s %s -- %s\n", prefix, cmd->name, |
| 583 | cmd->params, cmd->help); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 587 | static void help_cmd(Monitor *mon, const char *name) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 588 | { |
| 589 | if (name && !strcmp(name, "info")) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 590 | help_cmd_dump(mon, info_cmds, "info ", NULL); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 591 | } else { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 592 | help_cmd_dump(mon, mon_cmds, "", name); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 593 | if (name && !strcmp(name, "log")) { |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 594 | const CPULogItem *item; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 595 | monitor_printf(mon, "Log items (comma separated):\n"); |
| 596 | monitor_printf(mon, "%-10s %s\n", "none", "remove all logs"); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 597 | for(item = cpu_log_items; item->mask != 0; item++) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 598 | monitor_printf(mon, "%-10s %s\n", item->name, item->help); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 599 | } |
| 600 | } |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 604 | static void do_help_cmd(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | 3818318 | 2009-08-28 15:27:08 -0300 | [diff] [blame] | 605 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 606 | help_cmd(mon, qdict_get_try_str(qdict, "name")); |
Luiz Capitulino | 3818318 | 2009-08-28 15:27:08 -0300 | [diff] [blame] | 607 | } |
| 608 | |
Lluís | fc76410 | 2011-08-31 20:31:18 +0200 | [diff] [blame] | 609 | static void do_trace_event_set_state(Monitor *mon, const QDict *qdict) |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 610 | { |
| 611 | const char *tp_name = qdict_get_str(qdict, "name"); |
| 612 | bool new_state = qdict_get_bool(qdict, "option"); |
Lluís | fc76410 | 2011-08-31 20:31:18 +0200 | [diff] [blame] | 613 | int ret = trace_event_set_state(tp_name, new_state); |
Blue Swirl | f871d68 | 2010-10-13 19:14:29 +0000 | [diff] [blame] | 614 | |
| 615 | if (!ret) { |
| 616 | monitor_printf(mon, "unknown event name \"%s\"\n", tp_name); |
| 617 | } |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 618 | } |
Stefan Hajnoczi | c5ceb52 | 2010-07-13 09:26:33 +0100 | [diff] [blame] | 619 | |
Michael Roth | c45a816 | 2011-10-02 08:44:37 -0500 | [diff] [blame] | 620 | #ifdef CONFIG_TRACE_SIMPLE |
Stefan Hajnoczi | c5ceb52 | 2010-07-13 09:26:33 +0100 | [diff] [blame] | 621 | static void do_trace_file(Monitor *mon, const QDict *qdict) |
| 622 | { |
| 623 | const char *op = qdict_get_try_str(qdict, "op"); |
| 624 | const char *arg = qdict_get_try_str(qdict, "arg"); |
| 625 | |
| 626 | if (!op) { |
| 627 | st_print_trace_file_status((FILE *)mon, &monitor_fprintf); |
| 628 | } else if (!strcmp(op, "on")) { |
| 629 | st_set_trace_file_enabled(true); |
| 630 | } else if (!strcmp(op, "off")) { |
| 631 | st_set_trace_file_enabled(false); |
| 632 | } else if (!strcmp(op, "flush")) { |
| 633 | st_flush_trace_buffer(); |
| 634 | } else if (!strcmp(op, "set")) { |
| 635 | if (arg) { |
| 636 | st_set_trace_file(arg); |
| 637 | } |
| 638 | } else { |
| 639 | monitor_printf(mon, "unexpected argument \"%s\"\n", op); |
| 640 | help_cmd(mon, "trace-file"); |
| 641 | } |
| 642 | } |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 643 | #endif |
| 644 | |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 645 | static void user_monitor_complete(void *opaque, QObject *ret_data) |
| 646 | { |
| 647 | MonitorCompletionData *data = (MonitorCompletionData *)opaque; |
| 648 | |
| 649 | if (ret_data) { |
| 650 | data->user_print(data->mon, ret_data); |
| 651 | } |
| 652 | monitor_resume(data->mon); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 653 | g_free(data); |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | static void qmp_monitor_complete(void *opaque, QObject *ret_data) |
| 657 | { |
| 658 | monitor_protocol_emitter(opaque, ret_data); |
| 659 | } |
| 660 | |
Luiz Capitulino | 5af7bba | 2010-06-22 19:10:46 -0300 | [diff] [blame] | 661 | static int qmp_async_cmd_handler(Monitor *mon, const mon_cmd_t *cmd, |
| 662 | const QDict *params) |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 663 | { |
Luiz Capitulino | 5af7bba | 2010-06-22 19:10:46 -0300 | [diff] [blame] | 664 | return cmd->mhandler.cmd_async(mon, params, qmp_monitor_complete, mon); |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | static void qmp_async_info_handler(Monitor *mon, const mon_cmd_t *cmd) |
| 668 | { |
| 669 | cmd->mhandler.info_async(mon, qmp_monitor_complete, mon); |
| 670 | } |
| 671 | |
| 672 | static void user_async_cmd_handler(Monitor *mon, const mon_cmd_t *cmd, |
| 673 | const QDict *params) |
| 674 | { |
| 675 | int ret; |
| 676 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 677 | MonitorCompletionData *cb_data = g_malloc(sizeof(*cb_data)); |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 678 | cb_data->mon = mon; |
| 679 | cb_data->user_print = cmd->user_print; |
| 680 | monitor_suspend(mon); |
| 681 | ret = cmd->mhandler.cmd_async(mon, params, |
| 682 | user_monitor_complete, cb_data); |
| 683 | if (ret < 0) { |
| 684 | monitor_resume(mon); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 685 | g_free(cb_data); |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 686 | } |
| 687 | } |
| 688 | |
| 689 | static void user_async_info_handler(Monitor *mon, const mon_cmd_t *cmd) |
| 690 | { |
| 691 | int ret; |
| 692 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 693 | MonitorCompletionData *cb_data = g_malloc(sizeof(*cb_data)); |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 694 | cb_data->mon = mon; |
| 695 | cb_data->user_print = cmd->user_print; |
| 696 | monitor_suspend(mon); |
| 697 | ret = cmd->mhandler.info_async(mon, user_monitor_complete, cb_data); |
| 698 | if (ret < 0) { |
| 699 | monitor_resume(mon); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 700 | g_free(cb_data); |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 701 | } |
| 702 | } |
| 703 | |
Luiz Capitulino | 1162daa | 2010-09-13 12:15:26 -0300 | [diff] [blame] | 704 | static void do_info(Monitor *mon, const QDict *qdict) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 705 | { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 706 | const mon_cmd_t *cmd; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 707 | const char *item = qdict_get_try_str(qdict, "item"); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 708 | |
Luiz Capitulino | 956f1a0 | 2009-11-26 22:59:00 -0200 | [diff] [blame] | 709 | if (!item) { |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 710 | goto help; |
Luiz Capitulino | 956f1a0 | 2009-11-26 22:59:00 -0200 | [diff] [blame] | 711 | } |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 712 | |
| 713 | for (cmd = info_cmds; cmd->name != NULL; cmd++) { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 714 | if (compare_cmd(item, cmd->name)) |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 715 | break; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 716 | } |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 717 | |
Luiz Capitulino | 956f1a0 | 2009-11-26 22:59:00 -0200 | [diff] [blame] | 718 | if (cmd->name == NULL) { |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 719 | goto help; |
Luiz Capitulino | 956f1a0 | 2009-11-26 22:59:00 -0200 | [diff] [blame] | 720 | } |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 721 | |
Luiz Capitulino | 4903de0 | 2010-09-16 11:01:32 -0300 | [diff] [blame] | 722 | if (handler_is_async(cmd)) { |
Luiz Capitulino | 1dcbd6f | 2010-09-10 17:00:16 -0300 | [diff] [blame] | 723 | user_async_info_handler(mon, cmd); |
Luiz Capitulino | 9e80721 | 2010-09-16 10:58:59 -0300 | [diff] [blame] | 724 | } else if (handler_is_qobject(cmd)) { |
Luiz Capitulino | 1dcbd6f | 2010-09-10 17:00:16 -0300 | [diff] [blame] | 725 | QObject *info_data = NULL; |
Jan Kiszka | a6c4d36 | 2010-06-28 18:27:47 +0200 | [diff] [blame] | 726 | |
Luiz Capitulino | 1dcbd6f | 2010-09-10 17:00:16 -0300 | [diff] [blame] | 727 | cmd->mhandler.info_new(mon, &info_data); |
| 728 | if (info_data) { |
| 729 | cmd->user_print(mon, info_data); |
| 730 | qobject_decref(info_data); |
Luiz Capitulino | 25b422e | 2009-11-26 22:58:59 -0200 | [diff] [blame] | 731 | } |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 732 | } else { |
Luiz Capitulino | 1dcbd6f | 2010-09-10 17:00:16 -0300 | [diff] [blame] | 733 | cmd->mhandler.info(mon); |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 734 | } |
| 735 | |
Luiz Capitulino | 1162daa | 2010-09-13 12:15:26 -0300 | [diff] [blame] | 736 | return; |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 737 | |
| 738 | help: |
| 739 | help_cmd(mon, "info"); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 740 | } |
| 741 | |
Luiz Capitulino | aa9b79b | 2011-09-21 14:31:51 -0300 | [diff] [blame] | 742 | static CommandInfoList *alloc_cmd_entry(const char *cmd_name) |
Luiz Capitulino | 45e914c | 2009-12-10 17:15:58 -0200 | [diff] [blame] | 743 | { |
Luiz Capitulino | aa9b79b | 2011-09-21 14:31:51 -0300 | [diff] [blame] | 744 | CommandInfoList *info; |
Luiz Capitulino | 45e914c | 2009-12-10 17:15:58 -0200 | [diff] [blame] | 745 | |
Luiz Capitulino | aa9b79b | 2011-09-21 14:31:51 -0300 | [diff] [blame] | 746 | info = g_malloc0(sizeof(*info)); |
| 747 | info->value = g_malloc0(sizeof(*info->value)); |
| 748 | info->value->name = g_strdup(cmd_name); |
Luiz Capitulino | 45e914c | 2009-12-10 17:15:58 -0200 | [diff] [blame] | 749 | |
Luiz Capitulino | aa9b79b | 2011-09-21 14:31:51 -0300 | [diff] [blame] | 750 | return info; |
Luiz Capitulino | 45e914c | 2009-12-10 17:15:58 -0200 | [diff] [blame] | 751 | } |
| 752 | |
Luiz Capitulino | aa9b79b | 2011-09-21 14:31:51 -0300 | [diff] [blame] | 753 | CommandInfoList *qmp_query_commands(Error **errp) |
bellard | 9bc9d1c | 2004-10-10 15:15:51 +0000 | [diff] [blame] | 754 | { |
Luiz Capitulino | aa9b79b | 2011-09-21 14:31:51 -0300 | [diff] [blame] | 755 | CommandInfoList *info, *cmd_list = NULL; |
Luiz Capitulino | e3bba9d | 2009-11-26 22:58:56 -0200 | [diff] [blame] | 756 | const mon_cmd_t *cmd; |
| 757 | |
Luiz Capitulino | f36b4af | 2010-09-15 17:17:45 -0300 | [diff] [blame] | 758 | for (cmd = qmp_cmds; cmd->name != NULL; cmd++) { |
Luiz Capitulino | aa9b79b | 2011-09-21 14:31:51 -0300 | [diff] [blame] | 759 | info = alloc_cmd_entry(cmd->name); |
| 760 | info->next = cmd_list; |
| 761 | cmd_list = info; |
Luiz Capitulino | e3bba9d | 2009-11-26 22:58:56 -0200 | [diff] [blame] | 762 | } |
| 763 | |
Luiz Capitulino | 3e12a75 | 2010-09-15 17:20:33 -0300 | [diff] [blame] | 764 | for (cmd = qmp_query_cmds; cmd->name != NULL; cmd++) { |
Luiz Capitulino | 2e061a7 | 2010-09-16 10:36:54 -0300 | [diff] [blame] | 765 | char buf[128]; |
| 766 | snprintf(buf, sizeof(buf), "query-%s", cmd->name); |
Luiz Capitulino | aa9b79b | 2011-09-21 14:31:51 -0300 | [diff] [blame] | 767 | info = alloc_cmd_entry(buf); |
| 768 | info->next = cmd_list; |
| 769 | cmd_list = info; |
Luiz Capitulino | e3bba9d | 2009-11-26 22:58:56 -0200 | [diff] [blame] | 770 | } |
| 771 | |
Luiz Capitulino | aa9b79b | 2011-09-21 14:31:51 -0300 | [diff] [blame] | 772 | return cmd_list; |
ths | a36e69d | 2007-12-02 05:18:19 +0000 | [diff] [blame] | 773 | } |
| 774 | |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 775 | /* get the current CPU defined by the user */ |
pbrook | 9596ebb | 2007-11-18 01:44:38 +0000 | [diff] [blame] | 776 | static int mon_set_cpu(int cpu_index) |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 777 | { |
| 778 | CPUState *env; |
| 779 | |
| 780 | for(env = first_cpu; env != NULL; env = env->next_cpu) { |
| 781 | if (env->cpu_index == cpu_index) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 782 | cur_mon->mon_cpu = env; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 783 | return 0; |
| 784 | } |
| 785 | } |
| 786 | return -1; |
| 787 | } |
| 788 | |
pbrook | 9596ebb | 2007-11-18 01:44:38 +0000 | [diff] [blame] | 789 | static CPUState *mon_get_cpu(void) |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 790 | { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 791 | if (!cur_mon->mon_cpu) { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 792 | mon_set_cpu(0); |
| 793 | } |
Avi Kivity | 4c0960c | 2009-08-17 23:19:53 +0300 | [diff] [blame] | 794 | cpu_synchronize_state(cur_mon->mon_cpu); |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 795 | return cur_mon->mon_cpu; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 796 | } |
| 797 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 798 | static void do_info_registers(Monitor *mon) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 799 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 800 | CPUState *env; |
| 801 | env = mon_get_cpu(); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 802 | #ifdef TARGET_I386 |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 803 | cpu_dump_state(env, (FILE *)mon, monitor_fprintf, |
bellard | d24b15a | 2005-07-03 21:28:00 +0000 | [diff] [blame] | 804 | X86_DUMP_FPU); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 805 | #else |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 806 | cpu_dump_state(env, (FILE *)mon, monitor_fprintf, |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 807 | 0); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 808 | #endif |
| 809 | } |
| 810 | |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 811 | static void print_cpu_iter(QObject *obj, void *opaque) |
| 812 | { |
| 813 | QDict *cpu; |
| 814 | int active = ' '; |
| 815 | Monitor *mon = opaque; |
| 816 | |
| 817 | assert(qobject_type(obj) == QTYPE_QDICT); |
| 818 | cpu = qobject_to_qdict(obj); |
| 819 | |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 820 | if (qdict_get_bool(cpu, "current")) { |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 821 | active = '*'; |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 822 | } |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 823 | |
| 824 | monitor_printf(mon, "%c CPU #%d: ", active, (int)qdict_get_int(cpu, "CPU")); |
| 825 | |
| 826 | #if defined(TARGET_I386) |
| 827 | monitor_printf(mon, "pc=0x" TARGET_FMT_lx, |
| 828 | (target_ulong) qdict_get_int(cpu, "pc")); |
| 829 | #elif defined(TARGET_PPC) |
| 830 | monitor_printf(mon, "nip=0x" TARGET_FMT_lx, |
| 831 | (target_long) qdict_get_int(cpu, "nip")); |
| 832 | #elif defined(TARGET_SPARC) |
Nathan Kunkee | 3f9c359 | 2011-09-08 21:58:31 -0500 | [diff] [blame] | 833 | monitor_printf(mon, "pc=0x" TARGET_FMT_lx, |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 834 | (target_long) qdict_get_int(cpu, "pc")); |
| 835 | monitor_printf(mon, "npc=0x" TARGET_FMT_lx, |
| 836 | (target_long) qdict_get_int(cpu, "npc")); |
| 837 | #elif defined(TARGET_MIPS) |
| 838 | monitor_printf(mon, "PC=0x" TARGET_FMT_lx, |
| 839 | (target_long) qdict_get_int(cpu, "PC")); |
| 840 | #endif |
| 841 | |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 842 | if (qdict_get_bool(cpu, "halted")) { |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 843 | monitor_printf(mon, " (halted)"); |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 844 | } |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 845 | |
Jan Kiszka | dc7a09c | 2011-03-15 12:26:31 +0100 | [diff] [blame] | 846 | monitor_printf(mon, " thread_id=%" PRId64 " ", |
| 847 | qdict_get_int(cpu, "thread_id")); |
| 848 | |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 849 | monitor_printf(mon, "\n"); |
| 850 | } |
| 851 | |
| 852 | static void monitor_print_cpus(Monitor *mon, const QObject *data) |
| 853 | { |
| 854 | QList *cpu_list; |
| 855 | |
| 856 | assert(qobject_type(data) == QTYPE_QLIST); |
| 857 | cpu_list = qobject_to_qlist(data); |
| 858 | qlist_iter(cpu_list, print_cpu_iter, mon); |
| 859 | } |
| 860 | |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 861 | static void do_info_cpus(Monitor *mon, QObject **ret_data) |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 862 | { |
| 863 | CPUState *env; |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 864 | QList *cpu_list; |
| 865 | |
| 866 | cpu_list = qlist_new(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 867 | |
| 868 | /* just to set the default cpu if not already done */ |
| 869 | mon_get_cpu(); |
| 870 | |
| 871 | for(env = first_cpu; env != NULL; env = env->next_cpu) { |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 872 | QDict *cpu; |
| 873 | QObject *obj; |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 874 | |
Avi Kivity | 4c0960c | 2009-08-17 23:19:53 +0300 | [diff] [blame] | 875 | cpu_synchronize_state(env); |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 876 | |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 877 | obj = qobject_from_jsonf("{ 'CPU': %d, 'current': %i, 'halted': %i }", |
| 878 | env->cpu_index, env == mon->mon_cpu, |
| 879 | env->halted); |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 880 | |
| 881 | cpu = qobject_to_qdict(obj); |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 882 | |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 883 | #if defined(TARGET_I386) |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 884 | qdict_put(cpu, "pc", qint_from_int(env->eip + env->segs[R_CS].base)); |
bellard | e80e1cc | 2005-11-23 22:05:28 +0000 | [diff] [blame] | 885 | #elif defined(TARGET_PPC) |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 886 | qdict_put(cpu, "nip", qint_from_int(env->nip)); |
bellard | ba3c64f | 2005-12-05 20:31:52 +0000 | [diff] [blame] | 887 | #elif defined(TARGET_SPARC) |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 888 | qdict_put(cpu, "pc", qint_from_int(env->pc)); |
| 889 | qdict_put(cpu, "npc", qint_from_int(env->npc)); |
ths | ead9360 | 2007-09-06 00:18:15 +0000 | [diff] [blame] | 890 | #elif defined(TARGET_MIPS) |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 891 | qdict_put(cpu, "PC", qint_from_int(env->active_tc.PC)); |
bellard | ce5232c | 2008-05-28 17:14:10 +0000 | [diff] [blame] | 892 | #endif |
Jan Kiszka | dc7a09c | 2011-03-15 12:26:31 +0100 | [diff] [blame] | 893 | qdict_put(cpu, "thread_id", qint_from_int(env->thread_id)); |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 894 | |
| 895 | qlist_append(cpu_list, cpu); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 896 | } |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 897 | |
| 898 | *ret_data = QOBJECT(cpu_list); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Luiz Capitulino | 584cbdb | 2010-02-10 23:49:51 -0200 | [diff] [blame] | 901 | static int do_cpu_set(Monitor *mon, const QDict *qdict, QObject **ret_data) |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 902 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 903 | int index = qdict_get_int(qdict, "index"); |
Luiz Capitulino | 584cbdb | 2010-02-10 23:49:51 -0200 | [diff] [blame] | 904 | if (mon_set_cpu(index) < 0) { |
Markus Armbruster | e17ba87 | 2010-03-25 17:22:36 +0100 | [diff] [blame] | 905 | qerror_report(QERR_INVALID_PARAMETER_VALUE, "index", |
| 906 | "a CPU number"); |
Luiz Capitulino | 584cbdb | 2010-02-10 23:49:51 -0200 | [diff] [blame] | 907 | return -1; |
| 908 | } |
| 909 | return 0; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 910 | } |
| 911 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 912 | static void do_info_jit(Monitor *mon) |
bellard | e3db722 | 2005-01-26 22:00:47 +0000 | [diff] [blame] | 913 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 914 | dump_exec_info((FILE *)mon, monitor_fprintf); |
bellard | e3db722 | 2005-01-26 22:00:47 +0000 | [diff] [blame] | 915 | } |
| 916 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 917 | static void do_info_history(Monitor *mon) |
bellard | aa45548 | 2004-04-04 13:07:25 +0000 | [diff] [blame] | 918 | { |
| 919 | int i; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 920 | const char *str; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 921 | |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 922 | if (!mon->rs) |
| 923 | return; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 924 | i = 0; |
| 925 | for(;;) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 926 | str = readline_get_history(mon->rs, i); |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 927 | if (!str) |
| 928 | break; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 929 | monitor_printf(mon, "%d: '%s'\n", i, str); |
bellard | 8e3a9fd | 2004-10-09 17:32:58 +0000 | [diff] [blame] | 930 | i++; |
bellard | aa45548 | 2004-04-04 13:07:25 +0000 | [diff] [blame] | 931 | } |
| 932 | } |
| 933 | |
j_mayer | 76a6625 | 2007-03-07 08:32:30 +0000 | [diff] [blame] | 934 | #if defined(TARGET_PPC) |
| 935 | /* XXX: not implemented in other targets */ |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 936 | static void do_info_cpu_stats(Monitor *mon) |
j_mayer | 76a6625 | 2007-03-07 08:32:30 +0000 | [diff] [blame] | 937 | { |
| 938 | CPUState *env; |
| 939 | |
| 940 | env = mon_get_cpu(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 941 | cpu_dump_statistics(env, (FILE *)mon, &monitor_fprintf, 0); |
j_mayer | 76a6625 | 2007-03-07 08:32:30 +0000 | [diff] [blame] | 942 | } |
| 943 | #endif |
| 944 | |
Lluís | 6d8a764 | 2011-08-31 20:30:43 +0200 | [diff] [blame] | 945 | #if defined(CONFIG_TRACE_SIMPLE) |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 946 | static void do_info_trace(Monitor *mon) |
| 947 | { |
| 948 | st_print_trace((FILE *)mon, &monitor_fprintf); |
| 949 | } |
Lluís | 31965ae | 2011-08-31 20:31:24 +0200 | [diff] [blame] | 950 | #endif |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 951 | |
Lluís | fc76410 | 2011-08-31 20:31:18 +0200 | [diff] [blame] | 952 | static void do_trace_print_events(Monitor *mon) |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 953 | { |
Lluís | fc76410 | 2011-08-31 20:31:18 +0200 | [diff] [blame] | 954 | trace_print_events((FILE *)mon, &monitor_fprintf); |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 955 | } |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 956 | |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 957 | #ifdef CONFIG_VNC |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 958 | static int change_vnc_password(const char *password) |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 959 | { |
Anthony Liguori | 1cd20f8 | 2011-01-31 14:27:36 -0600 | [diff] [blame] | 960 | if (!password || !password[0]) { |
| 961 | if (vnc_display_disable_login(NULL)) { |
| 962 | qerror_report(QERR_SET_PASSWD_FAILED); |
| 963 | return -1; |
| 964 | } |
| 965 | return 0; |
| 966 | } |
| 967 | |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 968 | if (vnc_display_password(NULL, password) < 0) { |
Markus Armbruster | ab5b027 | 2010-03-02 18:15:09 +0100 | [diff] [blame] | 969 | qerror_report(QERR_SET_PASSWD_FAILED); |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 970 | return -1; |
| 971 | } |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 972 | |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 973 | return 0; |
Markus Armbruster | 2895e07 | 2009-12-07 21:37:01 +0100 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | static void change_vnc_password_cb(Monitor *mon, const char *password, |
| 977 | void *opaque) |
| 978 | { |
Markus Armbruster | ec3b82a | 2009-12-07 21:37:09 +0100 | [diff] [blame] | 979 | change_vnc_password(password); |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 980 | monitor_read_command(mon, 1); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 981 | } |
| 982 | |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 983 | static int do_change_vnc(Monitor *mon, const char *target, const char *arg) |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 984 | { |
ths | 7084851 | 2007-08-25 01:37:05 +0000 | [diff] [blame] | 985 | if (strcmp(target, "passwd") == 0 || |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 986 | strcmp(target, "password") == 0) { |
| 987 | if (arg) { |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 988 | char password[9]; |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 989 | strncpy(password, arg, sizeof(password)); |
| 990 | password[sizeof(password) - 1] = '\0'; |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 991 | return change_vnc_password(password); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 992 | } else { |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 993 | return monitor_read_password(mon, change_vnc_password_cb, NULL); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 994 | } |
ths | 7084851 | 2007-08-25 01:37:05 +0000 | [diff] [blame] | 995 | } else { |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 996 | if (vnc_display_open(NULL, target) < 0) { |
Markus Armbruster | ab5b027 | 2010-03-02 18:15:09 +0100 | [diff] [blame] | 997 | qerror_report(QERR_VNC_SERVER_FAILED, target); |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 998 | return -1; |
| 999 | } |
ths | 7084851 | 2007-08-25 01:37:05 +0000 | [diff] [blame] | 1000 | } |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 1001 | |
| 1002 | return 0; |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 1003 | } |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 1004 | #else |
| 1005 | static int do_change_vnc(Monitor *mon, const char *target, const char *arg) |
| 1006 | { |
| 1007 | qerror_report(QERR_FEATURE_DISABLED, "vnc"); |
| 1008 | return -ENODEV; |
| 1009 | } |
| 1010 | #endif |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 1011 | |
Markus Armbruster | ec3b82a | 2009-12-07 21:37:09 +0100 | [diff] [blame] | 1012 | /** |
| 1013 | * do_change(): Change a removable medium, or VNC configuration |
| 1014 | */ |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 1015 | static int do_change(Monitor *mon, const QDict *qdict, QObject **ret_data) |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 1016 | { |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 1017 | const char *device = qdict_get_str(qdict, "device"); |
| 1018 | const char *target = qdict_get_str(qdict, "target"); |
| 1019 | const char *arg = qdict_get_try_str(qdict, "arg"); |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 1020 | int ret; |
| 1021 | |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 1022 | if (strcmp(device, "vnc") == 0) { |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 1023 | ret = do_change_vnc(mon, target, arg); |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 1024 | } else { |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 1025 | ret = do_change_block(mon, device, target, arg); |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 1026 | } |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 1027 | |
| 1028 | return ret; |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
Gerd Hoffmann | 7572150 | 2010-10-07 12:22:54 +0200 | [diff] [blame] | 1031 | static int set_password(Monitor *mon, const QDict *qdict, QObject **ret_data) |
| 1032 | { |
| 1033 | const char *protocol = qdict_get_str(qdict, "protocol"); |
| 1034 | const char *password = qdict_get_str(qdict, "password"); |
| 1035 | const char *connected = qdict_get_try_str(qdict, "connected"); |
| 1036 | int disconnect_if_connected = 0; |
| 1037 | int fail_if_connected = 0; |
| 1038 | int rc; |
| 1039 | |
| 1040 | if (connected) { |
| 1041 | if (strcmp(connected, "fail") == 0) { |
| 1042 | fail_if_connected = 1; |
| 1043 | } else if (strcmp(connected, "disconnect") == 0) { |
| 1044 | disconnect_if_connected = 1; |
| 1045 | } else if (strcmp(connected, "keep") == 0) { |
| 1046 | /* nothing */ |
| 1047 | } else { |
| 1048 | qerror_report(QERR_INVALID_PARAMETER, "connected"); |
| 1049 | return -1; |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | if (strcmp(protocol, "spice") == 0) { |
| 1054 | if (!using_spice) { |
| 1055 | /* correct one? spice isn't a device ,,, */ |
| 1056 | qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice"); |
| 1057 | return -1; |
| 1058 | } |
| 1059 | rc = qemu_spice_set_passwd(password, fail_if_connected, |
| 1060 | disconnect_if_connected); |
| 1061 | if (rc != 0) { |
| 1062 | qerror_report(QERR_SET_PASSWD_FAILED); |
| 1063 | return -1; |
| 1064 | } |
| 1065 | return 0; |
| 1066 | } |
| 1067 | |
| 1068 | if (strcmp(protocol, "vnc") == 0) { |
| 1069 | if (fail_if_connected || disconnect_if_connected) { |
| 1070 | /* vnc supports "connected=keep" only */ |
| 1071 | qerror_report(QERR_INVALID_PARAMETER, "connected"); |
| 1072 | return -1; |
| 1073 | } |
Anthony Liguori | 1cd20f8 | 2011-01-31 14:27:36 -0600 | [diff] [blame] | 1074 | /* Note that setting an empty password will not disable login through |
| 1075 | * this interface. */ |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 1076 | return vnc_display_password(NULL, password); |
Gerd Hoffmann | 7572150 | 2010-10-07 12:22:54 +0200 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | qerror_report(QERR_INVALID_PARAMETER, "protocol"); |
| 1080 | return -1; |
| 1081 | } |
| 1082 | |
| 1083 | static int expire_password(Monitor *mon, const QDict *qdict, QObject **ret_data) |
| 1084 | { |
| 1085 | const char *protocol = qdict_get_str(qdict, "protocol"); |
| 1086 | const char *whenstr = qdict_get_str(qdict, "time"); |
| 1087 | time_t when; |
| 1088 | int rc; |
| 1089 | |
Marc-André Lureau | 8d86e2b | 2011-01-06 11:43:17 +0100 | [diff] [blame] | 1090 | if (strcmp(whenstr, "now") == 0) { |
Gerd Hoffmann | 7572150 | 2010-10-07 12:22:54 +0200 | [diff] [blame] | 1091 | when = 0; |
Marc-André Lureau | 8d86e2b | 2011-01-06 11:43:17 +0100 | [diff] [blame] | 1092 | } else if (strcmp(whenstr, "never") == 0) { |
Gerd Hoffmann | 7572150 | 2010-10-07 12:22:54 +0200 | [diff] [blame] | 1093 | when = TIME_MAX; |
| 1094 | } else if (whenstr[0] == '+') { |
| 1095 | when = time(NULL) + strtoull(whenstr+1, NULL, 10); |
| 1096 | } else { |
| 1097 | when = strtoull(whenstr, NULL, 10); |
| 1098 | } |
| 1099 | |
| 1100 | if (strcmp(protocol, "spice") == 0) { |
| 1101 | if (!using_spice) { |
| 1102 | /* correct one? spice isn't a device ,,, */ |
| 1103 | qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice"); |
| 1104 | return -1; |
| 1105 | } |
| 1106 | rc = qemu_spice_set_pw_expire(when); |
| 1107 | if (rc != 0) { |
| 1108 | qerror_report(QERR_SET_PASSWD_FAILED); |
| 1109 | return -1; |
| 1110 | } |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
| 1114 | if (strcmp(protocol, "vnc") == 0) { |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 1115 | return vnc_display_pw_expire(NULL, when); |
Gerd Hoffmann | 7572150 | 2010-10-07 12:22:54 +0200 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | qerror_report(QERR_INVALID_PARAMETER, "protocol"); |
| 1119 | return -1; |
| 1120 | } |
| 1121 | |
Daniel P. Berrange | 1366108 | 2011-06-23 13:31:42 +0100 | [diff] [blame] | 1122 | static int add_graphics_client(Monitor *mon, const QDict *qdict, QObject **ret_data) |
| 1123 | { |
| 1124 | const char *protocol = qdict_get_str(qdict, "protocol"); |
| 1125 | const char *fdname = qdict_get_str(qdict, "fdname"); |
Daniel P. Berrange | 1366108 | 2011-06-23 13:31:42 +0100 | [diff] [blame] | 1126 | CharDriverState *s; |
| 1127 | |
| 1128 | if (strcmp(protocol, "spice") == 0) { |
| 1129 | if (!using_spice) { |
| 1130 | /* correct one? spice isn't a device ,,, */ |
| 1131 | qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice"); |
| 1132 | return -1; |
| 1133 | } |
| 1134 | qerror_report(QERR_ADD_CLIENT_FAILED); |
| 1135 | return -1; |
TeLeMan | c62f6d1 | 2011-07-25 16:29:14 +0800 | [diff] [blame] | 1136 | #ifdef CONFIG_VNC |
Daniel P. Berrange | 1366108 | 2011-06-23 13:31:42 +0100 | [diff] [blame] | 1137 | } else if (strcmp(protocol, "vnc") == 0) { |
| 1138 | int fd = monitor_get_fd(mon, fdname); |
Jamie Iles | 860341f | 2011-08-10 15:18:42 +0100 | [diff] [blame] | 1139 | int skipauth = qdict_get_try_bool(qdict, "skipauth", 0); |
Daniel P. Berrange | 1366108 | 2011-06-23 13:31:42 +0100 | [diff] [blame] | 1140 | vnc_display_add_client(NULL, fd, skipauth); |
| 1141 | return 0; |
TeLeMan | c62f6d1 | 2011-07-25 16:29:14 +0800 | [diff] [blame] | 1142 | #endif |
Daniel P. Berrange | 1366108 | 2011-06-23 13:31:42 +0100 | [diff] [blame] | 1143 | } else if ((s = qemu_chr_find(protocol)) != NULL) { |
| 1144 | int fd = monitor_get_fd(mon, fdname); |
| 1145 | if (qemu_chr_add_client(s, fd) < 0) { |
| 1146 | qerror_report(QERR_ADD_CLIENT_FAILED); |
| 1147 | return -1; |
| 1148 | } |
| 1149 | return 0; |
| 1150 | } |
| 1151 | |
| 1152 | qerror_report(QERR_INVALID_PARAMETER, "protocol"); |
| 1153 | return -1; |
| 1154 | } |
| 1155 | |
Gerd Hoffmann | e866e23 | 2010-04-23 13:28:21 +0200 | [diff] [blame] | 1156 | static int client_migrate_info(Monitor *mon, const QDict *qdict, QObject **ret_data) |
| 1157 | { |
| 1158 | const char *protocol = qdict_get_str(qdict, "protocol"); |
| 1159 | const char *hostname = qdict_get_str(qdict, "hostname"); |
| 1160 | const char *subject = qdict_get_try_str(qdict, "cert-subject"); |
| 1161 | int port = qdict_get_try_int(qdict, "port", -1); |
| 1162 | int tls_port = qdict_get_try_int(qdict, "tls-port", -1); |
| 1163 | int ret; |
| 1164 | |
| 1165 | if (strcmp(protocol, "spice") == 0) { |
| 1166 | if (!using_spice) { |
| 1167 | qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice"); |
| 1168 | return -1; |
| 1169 | } |
| 1170 | |
| 1171 | ret = qemu_spice_migrate_info(hostname, port, tls_port, subject); |
| 1172 | if (ret != 0) { |
| 1173 | qerror_report(QERR_UNDEFINED_ERROR); |
| 1174 | return -1; |
| 1175 | } |
| 1176 | return 0; |
| 1177 | } |
| 1178 | |
| 1179 | qerror_report(QERR_INVALID_PARAMETER, "protocol"); |
| 1180 | return -1; |
| 1181 | } |
| 1182 | |
Luiz Capitulino | f1dc58e | 2010-03-31 15:21:49 -0300 | [diff] [blame] | 1183 | static int do_screen_dump(Monitor *mon, const QDict *qdict, QObject **ret_data) |
bellard | 59a983b | 2004-03-17 23:17:16 +0000 | [diff] [blame] | 1184 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1185 | vga_hw_screen_dump(qdict_get_str(qdict, "filename")); |
Luiz Capitulino | f1dc58e | 2010-03-31 15:21:49 -0300 | [diff] [blame] | 1186 | return 0; |
bellard | 59a983b | 2004-03-17 23:17:16 +0000 | [diff] [blame] | 1187 | } |
| 1188 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1189 | static void do_logfile(Monitor *mon, const QDict *qdict) |
pbrook | e735b91 | 2007-06-30 13:53:24 +0000 | [diff] [blame] | 1190 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1191 | cpu_set_log_filename(qdict_get_str(qdict, "filename")); |
pbrook | e735b91 | 2007-06-30 13:53:24 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1194 | static void do_log(Monitor *mon, const QDict *qdict) |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 1195 | { |
| 1196 | int mask; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1197 | const char *items = qdict_get_str(qdict, "items"); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1198 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1199 | if (!strcmp(items, "none")) { |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 1200 | mask = 0; |
| 1201 | } else { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1202 | mask = cpu_str_to_log_mask(items); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 1203 | if (!mask) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1204 | help_cmd(mon, "log"); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 1205 | return; |
| 1206 | } |
| 1207 | } |
| 1208 | cpu_set_log(mask); |
| 1209 | } |
| 1210 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1211 | static void do_singlestep(Monitor *mon, const QDict *qdict) |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 1212 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1213 | const char *option = qdict_get_try_str(qdict, "option"); |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 1214 | if (!option || !strcmp(option, "on")) { |
| 1215 | singlestep = 1; |
| 1216 | } else if (!strcmp(option, "off")) { |
| 1217 | singlestep = 0; |
| 1218 | } else { |
| 1219 | monitor_printf(mon, "unexpected option %s\n", option); |
| 1220 | } |
| 1221 | } |
| 1222 | |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1223 | static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs); |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 1224 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1225 | struct bdrv_iterate_context { |
| 1226 | Monitor *mon; |
| 1227 | int err; |
| 1228 | }; |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 1229 | |
Luiz Capitulino | 28a7282 | 2011-09-26 17:43:50 -0300 | [diff] [blame] | 1230 | static void iostatus_bdrv_it(void *opaque, BlockDriverState *bs) |
| 1231 | { |
| 1232 | bdrv_iostatus_reset(bs); |
| 1233 | } |
| 1234 | |
Luiz Capitulino | a1f896a | 2009-10-07 13:42:00 -0300 | [diff] [blame] | 1235 | /** |
| 1236 | * do_cont(): Resume emulation. |
| 1237 | */ |
Luiz Capitulino | d5a7b38 | 2010-02-10 23:49:49 -0200 | [diff] [blame] | 1238 | static int do_cont(Monitor *mon, const QDict *qdict, QObject **ret_data) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1239 | { |
| 1240 | struct bdrv_iterate_context context = { mon, 0 }; |
| 1241 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 1242 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
Amit Shah | 8e84865 | 2010-07-27 15:49:19 +0530 | [diff] [blame] | 1243 | qerror_report(QERR_MIGRATION_EXPECTED); |
| 1244 | return -1; |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 1245 | } else if (runstate_check(RUN_STATE_INTERNAL_ERROR) || |
| 1246 | runstate_check(RUN_STATE_SHUTDOWN)) { |
Luiz Capitulino | 6667b23 | 2011-07-29 15:57:54 -0300 | [diff] [blame] | 1247 | qerror_report(QERR_RESET_REQUIRED); |
| 1248 | return -1; |
Amit Shah | 8e84865 | 2010-07-27 15:49:19 +0530 | [diff] [blame] | 1249 | } |
Luiz Capitulino | 6667b23 | 2011-07-29 15:57:54 -0300 | [diff] [blame] | 1250 | |
Luiz Capitulino | 28a7282 | 2011-09-26 17:43:50 -0300 | [diff] [blame] | 1251 | bdrv_iterate(iostatus_bdrv_it, NULL); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1252 | bdrv_iterate(encrypted_bdrv_it, &context); |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 1253 | /* only resume the vm if all keys are set and valid */ |
Luiz Capitulino | d5a7b38 | 2010-02-10 23:49:49 -0200 | [diff] [blame] | 1254 | if (!context.err) { |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 1255 | vm_start(); |
Luiz Capitulino | d5a7b38 | 2010-02-10 23:49:49 -0200 | [diff] [blame] | 1256 | return 0; |
| 1257 | } else { |
| 1258 | return -1; |
| 1259 | } |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1262 | static void bdrv_key_cb(void *opaque, int err) |
| 1263 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1264 | Monitor *mon = opaque; |
| 1265 | |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1266 | /* another key was set successfully, retry to continue */ |
| 1267 | if (!err) |
Luiz Capitulino | a1f896a | 2009-10-07 13:42:00 -0300 | [diff] [blame] | 1268 | do_cont(mon, NULL, NULL); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs) |
| 1272 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1273 | struct bdrv_iterate_context *context = opaque; |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1274 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1275 | if (!context->err && bdrv_key_required(bs)) { |
| 1276 | context->err = -EBUSY; |
| 1277 | monitor_read_bdrv_key_start(context->mon, bs, bdrv_key_cb, |
| 1278 | context->mon); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1279 | } |
| 1280 | } |
| 1281 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1282 | static void do_gdbserver(Monitor *mon, const QDict *qdict) |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1283 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1284 | const char *device = qdict_get_try_str(qdict, "device"); |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 1285 | if (!device) |
| 1286 | device = "tcp::" DEFAULT_GDBSTUB_PORT; |
| 1287 | if (gdbserver_start(device) < 0) { |
| 1288 | monitor_printf(mon, "Could not open gdbserver on device '%s'\n", |
| 1289 | device); |
| 1290 | } else if (strcmp(device, "none") == 0) { |
aliguori | 36556b2 | 2009-03-28 18:05:53 +0000 | [diff] [blame] | 1291 | monitor_printf(mon, "Disabled gdbserver\n"); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1292 | } else { |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 1293 | monitor_printf(mon, "Waiting for gdb connection on device '%s'\n", |
| 1294 | device); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1295 | } |
| 1296 | } |
| 1297 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1298 | static void do_watchdog_action(Monitor *mon, const QDict *qdict) |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 1299 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1300 | const char *action = qdict_get_str(qdict, "action"); |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 1301 | if (select_watchdog_action(action) == -1) { |
| 1302 | monitor_printf(mon, "Unknown watchdog action '%s'\n", action); |
| 1303 | } |
| 1304 | } |
| 1305 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1306 | static void monitor_printc(Monitor *mon, int c) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1307 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1308 | monitor_printf(mon, "'"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1309 | switch(c) { |
| 1310 | case '\'': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1311 | monitor_printf(mon, "\\'"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1312 | break; |
| 1313 | case '\\': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1314 | monitor_printf(mon, "\\\\"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1315 | break; |
| 1316 | case '\n': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1317 | monitor_printf(mon, "\\n"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1318 | break; |
| 1319 | case '\r': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1320 | monitor_printf(mon, "\\r"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1321 | break; |
| 1322 | default: |
| 1323 | if (c >= 32 && c <= 126) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1324 | monitor_printf(mon, "%c", c); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1325 | } else { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1326 | monitor_printf(mon, "\\x%02x", c); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1327 | } |
| 1328 | break; |
| 1329 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1330 | monitor_printf(mon, "'"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1333 | static void memory_dump(Monitor *mon, int count, int format, int wsize, |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1334 | target_phys_addr_t addr, int is_physical) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1335 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1336 | CPUState *env; |
Blue Swirl | 23842aa | 2010-01-12 20:27:43 +0000 | [diff] [blame] | 1337 | int l, line_size, i, max_digits, len; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1338 | uint8_t buf[16]; |
| 1339 | uint64_t v; |
| 1340 | |
| 1341 | if (format == 'i') { |
| 1342 | int flags; |
| 1343 | flags = 0; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1344 | env = mon_get_cpu(); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1345 | #ifdef TARGET_I386 |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 1346 | if (wsize == 2) { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1347 | flags = 1; |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 1348 | } else if (wsize == 4) { |
| 1349 | flags = 0; |
| 1350 | } else { |
bellard | 6a15fd1 | 2006-04-12 21:07:07 +0000 | [diff] [blame] | 1351 | /* as default we use the current CS size */ |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 1352 | flags = 0; |
bellard | 6a15fd1 | 2006-04-12 21:07:07 +0000 | [diff] [blame] | 1353 | if (env) { |
| 1354 | #ifdef TARGET_X86_64 |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1355 | if ((env->efer & MSR_EFER_LMA) && |
bellard | 6a15fd1 | 2006-04-12 21:07:07 +0000 | [diff] [blame] | 1356 | (env->segs[R_CS].flags & DESC_L_MASK)) |
| 1357 | flags = 2; |
| 1358 | else |
| 1359 | #endif |
| 1360 | if (!(env->segs[R_CS].flags & DESC_B_MASK)) |
| 1361 | flags = 1; |
| 1362 | } |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 1363 | } |
| 1364 | #endif |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1365 | monitor_disas(mon, env, addr, count, is_physical, flags); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1366 | return; |
| 1367 | } |
| 1368 | |
| 1369 | len = wsize * count; |
| 1370 | if (wsize == 1) |
| 1371 | line_size = 8; |
| 1372 | else |
| 1373 | line_size = 16; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1374 | max_digits = 0; |
| 1375 | |
| 1376 | switch(format) { |
| 1377 | case 'o': |
| 1378 | max_digits = (wsize * 8 + 2) / 3; |
| 1379 | break; |
| 1380 | default: |
| 1381 | case 'x': |
| 1382 | max_digits = (wsize * 8) / 4; |
| 1383 | break; |
| 1384 | case 'u': |
| 1385 | case 'd': |
| 1386 | max_digits = (wsize * 8 * 10 + 32) / 33; |
| 1387 | break; |
| 1388 | case 'c': |
| 1389 | wsize = 1; |
| 1390 | break; |
| 1391 | } |
| 1392 | |
| 1393 | while (len > 0) { |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 1394 | if (is_physical) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1395 | monitor_printf(mon, TARGET_FMT_plx ":", addr); |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 1396 | else |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1397 | monitor_printf(mon, TARGET_FMT_lx ":", (target_ulong)addr); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1398 | l = len; |
| 1399 | if (l > line_size) |
| 1400 | l = line_size; |
| 1401 | if (is_physical) { |
Stefan Weil | 54f7b4a | 2011-04-10 18:23:39 +0200 | [diff] [blame] | 1402 | cpu_physical_memory_read(addr, buf, l); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1403 | } else { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1404 | env = mon_get_cpu(); |
aliguori | c8f79b6 | 2008-08-18 14:00:20 +0000 | [diff] [blame] | 1405 | if (cpu_memory_rw_debug(env, addr, buf, l, 0) < 0) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1406 | monitor_printf(mon, " Cannot access memory\n"); |
aliguori | c8f79b6 | 2008-08-18 14:00:20 +0000 | [diff] [blame] | 1407 | break; |
| 1408 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1409 | } |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1410 | i = 0; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1411 | while (i < l) { |
| 1412 | switch(wsize) { |
| 1413 | default: |
| 1414 | case 1: |
| 1415 | v = ldub_raw(buf + i); |
| 1416 | break; |
| 1417 | case 2: |
| 1418 | v = lduw_raw(buf + i); |
| 1419 | break; |
| 1420 | case 4: |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 1421 | v = (uint32_t)ldl_raw(buf + i); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1422 | break; |
| 1423 | case 8: |
| 1424 | v = ldq_raw(buf + i); |
| 1425 | break; |
| 1426 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1427 | monitor_printf(mon, " "); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1428 | switch(format) { |
| 1429 | case 'o': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1430 | monitor_printf(mon, "%#*" PRIo64, max_digits, v); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1431 | break; |
| 1432 | case 'x': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1433 | monitor_printf(mon, "0x%0*" PRIx64, max_digits, v); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1434 | break; |
| 1435 | case 'u': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1436 | monitor_printf(mon, "%*" PRIu64, max_digits, v); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1437 | break; |
| 1438 | case 'd': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1439 | monitor_printf(mon, "%*" PRId64, max_digits, v); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1440 | break; |
| 1441 | case 'c': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1442 | monitor_printc(mon, v); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1443 | break; |
| 1444 | } |
| 1445 | i += wsize; |
| 1446 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1447 | monitor_printf(mon, "\n"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1448 | addr += l; |
| 1449 | len -= l; |
| 1450 | } |
| 1451 | } |
| 1452 | |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1453 | static void do_memory_dump(Monitor *mon, const QDict *qdict) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1454 | { |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1455 | int count = qdict_get_int(qdict, "count"); |
| 1456 | int format = qdict_get_int(qdict, "format"); |
| 1457 | int size = qdict_get_int(qdict, "size"); |
| 1458 | target_long addr = qdict_get_int(qdict, "addr"); |
| 1459 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1460 | memory_dump(mon, count, format, size, addr, 0); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1463 | static void do_physical_memory_dump(Monitor *mon, const QDict *qdict) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1464 | { |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1465 | int count = qdict_get_int(qdict, "count"); |
| 1466 | int format = qdict_get_int(qdict, "format"); |
| 1467 | int size = qdict_get_int(qdict, "size"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1468 | target_phys_addr_t addr = qdict_get_int(qdict, "addr"); |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1469 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1470 | memory_dump(mon, count, format, size, addr, 1); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1473 | static void do_print(Monitor *mon, const QDict *qdict) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1474 | { |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1475 | int format = qdict_get_int(qdict, "format"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1476 | target_phys_addr_t val = qdict_get_int(qdict, "val"); |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1477 | |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 1478 | #if TARGET_PHYS_ADDR_BITS == 32 |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1479 | switch(format) { |
| 1480 | case 'o': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1481 | monitor_printf(mon, "%#o", val); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1482 | break; |
| 1483 | case 'x': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1484 | monitor_printf(mon, "%#x", val); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1485 | break; |
| 1486 | case 'u': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1487 | monitor_printf(mon, "%u", val); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1488 | break; |
| 1489 | default: |
| 1490 | case 'd': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1491 | monitor_printf(mon, "%d", val); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1492 | break; |
| 1493 | case 'c': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1494 | monitor_printc(mon, val); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1495 | break; |
| 1496 | } |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 1497 | #else |
| 1498 | switch(format) { |
| 1499 | case 'o': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1500 | monitor_printf(mon, "%#" PRIo64, val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 1501 | break; |
| 1502 | case 'x': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1503 | monitor_printf(mon, "%#" PRIx64, val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 1504 | break; |
| 1505 | case 'u': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1506 | monitor_printf(mon, "%" PRIu64, val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 1507 | break; |
| 1508 | default: |
| 1509 | case 'd': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1510 | monitor_printf(mon, "%" PRId64, val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 1511 | break; |
| 1512 | case 'c': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1513 | monitor_printc(mon, val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 1514 | break; |
| 1515 | } |
| 1516 | #endif |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1517 | monitor_printf(mon, "\n"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1518 | } |
| 1519 | |
Luiz Capitulino | 9869622 | 2010-02-10 23:49:58 -0200 | [diff] [blame] | 1520 | static int do_memory_save(Monitor *mon, const QDict *qdict, QObject **ret_data) |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1521 | { |
| 1522 | FILE *f; |
Luiz Capitulino | afe67ef | 2009-08-28 15:27:16 -0300 | [diff] [blame] | 1523 | uint32_t size = qdict_get_int(qdict, "size"); |
| 1524 | const char *filename = qdict_get_str(qdict, "filename"); |
| 1525 | target_long addr = qdict_get_int(qdict, "val"); |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1526 | uint32_t l; |
| 1527 | CPUState *env; |
| 1528 | uint8_t buf[1024]; |
Luiz Capitulino | 9869622 | 2010-02-10 23:49:58 -0200 | [diff] [blame] | 1529 | int ret = -1; |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1530 | |
| 1531 | env = mon_get_cpu(); |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1532 | |
| 1533 | f = fopen(filename, "wb"); |
| 1534 | if (!f) { |
Markus Armbruster | ab5b027 | 2010-03-02 18:15:09 +0100 | [diff] [blame] | 1535 | qerror_report(QERR_OPEN_FILE_FAILED, filename); |
Luiz Capitulino | 9869622 | 2010-02-10 23:49:58 -0200 | [diff] [blame] | 1536 | return -1; |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1537 | } |
| 1538 | while (size != 0) { |
| 1539 | l = sizeof(buf); |
| 1540 | if (l > size) |
| 1541 | l = size; |
| 1542 | cpu_memory_rw_debug(env, addr, buf, l, 0); |
Kirill A. Shutemov | 27e3ddd | 2010-01-20 00:56:19 +0100 | [diff] [blame] | 1543 | if (fwrite(buf, 1, l, f) != l) { |
| 1544 | monitor_printf(mon, "fwrite() error in do_memory_save\n"); |
| 1545 | goto exit; |
| 1546 | } |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1547 | addr += l; |
| 1548 | size -= l; |
| 1549 | } |
Luiz Capitulino | 9869622 | 2010-02-10 23:49:58 -0200 | [diff] [blame] | 1550 | |
| 1551 | ret = 0; |
| 1552 | |
Kirill A. Shutemov | 27e3ddd | 2010-01-20 00:56:19 +0100 | [diff] [blame] | 1553 | exit: |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1554 | fclose(f); |
Luiz Capitulino | 9869622 | 2010-02-10 23:49:58 -0200 | [diff] [blame] | 1555 | return ret; |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
Luiz Capitulino | fe38a32 | 2010-02-10 23:49:59 -0200 | [diff] [blame] | 1558 | static int do_physical_memory_save(Monitor *mon, const QDict *qdict, |
Luiz Capitulino | 18f5a8b | 2009-10-16 12:23:44 -0300 | [diff] [blame] | 1559 | QObject **ret_data) |
aurel32 | a8bdf7a | 2008-04-11 21:36:14 +0000 | [diff] [blame] | 1560 | { |
| 1561 | FILE *f; |
| 1562 | uint32_t l; |
| 1563 | uint8_t buf[1024]; |
Luiz Capitulino | afe67ef | 2009-08-28 15:27:16 -0300 | [diff] [blame] | 1564 | uint32_t size = qdict_get_int(qdict, "size"); |
| 1565 | const char *filename = qdict_get_str(qdict, "filename"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1566 | target_phys_addr_t addr = qdict_get_int(qdict, "val"); |
Luiz Capitulino | fe38a32 | 2010-02-10 23:49:59 -0200 | [diff] [blame] | 1567 | int ret = -1; |
aurel32 | a8bdf7a | 2008-04-11 21:36:14 +0000 | [diff] [blame] | 1568 | |
| 1569 | f = fopen(filename, "wb"); |
| 1570 | if (!f) { |
Markus Armbruster | ab5b027 | 2010-03-02 18:15:09 +0100 | [diff] [blame] | 1571 | qerror_report(QERR_OPEN_FILE_FAILED, filename); |
Luiz Capitulino | fe38a32 | 2010-02-10 23:49:59 -0200 | [diff] [blame] | 1572 | return -1; |
aurel32 | a8bdf7a | 2008-04-11 21:36:14 +0000 | [diff] [blame] | 1573 | } |
| 1574 | while (size != 0) { |
| 1575 | l = sizeof(buf); |
| 1576 | if (l > size) |
| 1577 | l = size; |
Stefan Weil | 54f7b4a | 2011-04-10 18:23:39 +0200 | [diff] [blame] | 1578 | cpu_physical_memory_read(addr, buf, l); |
Kirill A. Shutemov | 27e3ddd | 2010-01-20 00:56:19 +0100 | [diff] [blame] | 1579 | if (fwrite(buf, 1, l, f) != l) { |
| 1580 | monitor_printf(mon, "fwrite() error in do_physical_memory_save\n"); |
| 1581 | goto exit; |
| 1582 | } |
aurel32 | a8bdf7a | 2008-04-11 21:36:14 +0000 | [diff] [blame] | 1583 | fflush(f); |
| 1584 | addr += l; |
| 1585 | size -= l; |
| 1586 | } |
Luiz Capitulino | fe38a32 | 2010-02-10 23:49:59 -0200 | [diff] [blame] | 1587 | |
| 1588 | ret = 0; |
| 1589 | |
Kirill A. Shutemov | 27e3ddd | 2010-01-20 00:56:19 +0100 | [diff] [blame] | 1590 | exit: |
aurel32 | a8bdf7a | 2008-04-11 21:36:14 +0000 | [diff] [blame] | 1591 | fclose(f); |
Luiz Capitulino | fe38a32 | 2010-02-10 23:49:59 -0200 | [diff] [blame] | 1592 | return ret; |
aurel32 | a8bdf7a | 2008-04-11 21:36:14 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 1595 | static void do_sum(Monitor *mon, const QDict *qdict) |
bellard | e4cf1ad | 2005-06-04 20:15:57 +0000 | [diff] [blame] | 1596 | { |
| 1597 | uint32_t addr; |
bellard | e4cf1ad | 2005-06-04 20:15:57 +0000 | [diff] [blame] | 1598 | uint16_t sum; |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 1599 | uint32_t start = qdict_get_int(qdict, "start"); |
| 1600 | uint32_t size = qdict_get_int(qdict, "size"); |
bellard | e4cf1ad | 2005-06-04 20:15:57 +0000 | [diff] [blame] | 1601 | |
| 1602 | sum = 0; |
| 1603 | for(addr = start; addr < (start + size); addr++) { |
Stefan Weil | 54f7b4a | 2011-04-10 18:23:39 +0200 | [diff] [blame] | 1604 | uint8_t val = ldub_phys(addr); |
bellard | e4cf1ad | 2005-06-04 20:15:57 +0000 | [diff] [blame] | 1605 | /* BSD sum algorithm ('sum' Unix command) */ |
| 1606 | sum = (sum >> 1) | (sum << 15); |
Stefan Weil | 54f7b4a | 2011-04-10 18:23:39 +0200 | [diff] [blame] | 1607 | sum += val; |
bellard | e4cf1ad | 2005-06-04 20:15:57 +0000 | [diff] [blame] | 1608 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1609 | monitor_printf(mon, "%05d\n", sum); |
bellard | e4cf1ad | 2005-06-04 20:15:57 +0000 | [diff] [blame] | 1610 | } |
| 1611 | |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1612 | typedef struct { |
| 1613 | int keycode; |
| 1614 | const char *name; |
| 1615 | } KeyDef; |
| 1616 | |
| 1617 | static const KeyDef key_defs[] = { |
| 1618 | { 0x2a, "shift" }, |
| 1619 | { 0x36, "shift_r" }, |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1620 | |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1621 | { 0x38, "alt" }, |
| 1622 | { 0xb8, "alt_r" }, |
ths | 2ba27c7 | 2008-08-13 12:54:23 +0000 | [diff] [blame] | 1623 | { 0x64, "altgr" }, |
| 1624 | { 0xe4, "altgr_r" }, |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1625 | { 0x1d, "ctrl" }, |
| 1626 | { 0x9d, "ctrl_r" }, |
| 1627 | |
| 1628 | { 0xdd, "menu" }, |
| 1629 | |
| 1630 | { 0x01, "esc" }, |
| 1631 | |
| 1632 | { 0x02, "1" }, |
| 1633 | { 0x03, "2" }, |
| 1634 | { 0x04, "3" }, |
| 1635 | { 0x05, "4" }, |
| 1636 | { 0x06, "5" }, |
| 1637 | { 0x07, "6" }, |
| 1638 | { 0x08, "7" }, |
| 1639 | { 0x09, "8" }, |
| 1640 | { 0x0a, "9" }, |
| 1641 | { 0x0b, "0" }, |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1642 | { 0x0c, "minus" }, |
| 1643 | { 0x0d, "equal" }, |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1644 | { 0x0e, "backspace" }, |
| 1645 | |
| 1646 | { 0x0f, "tab" }, |
| 1647 | { 0x10, "q" }, |
| 1648 | { 0x11, "w" }, |
| 1649 | { 0x12, "e" }, |
| 1650 | { 0x13, "r" }, |
| 1651 | { 0x14, "t" }, |
| 1652 | { 0x15, "y" }, |
| 1653 | { 0x16, "u" }, |
| 1654 | { 0x17, "i" }, |
| 1655 | { 0x18, "o" }, |
| 1656 | { 0x19, "p" }, |
Bernhard M. Wiedemann | 49b586a | 2010-06-02 05:32:30 +0200 | [diff] [blame] | 1657 | { 0x1a, "bracket_left" }, |
| 1658 | { 0x1b, "bracket_right" }, |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1659 | { 0x1c, "ret" }, |
| 1660 | |
| 1661 | { 0x1e, "a" }, |
| 1662 | { 0x1f, "s" }, |
| 1663 | { 0x20, "d" }, |
| 1664 | { 0x21, "f" }, |
| 1665 | { 0x22, "g" }, |
| 1666 | { 0x23, "h" }, |
| 1667 | { 0x24, "j" }, |
| 1668 | { 0x25, "k" }, |
| 1669 | { 0x26, "l" }, |
Bernhard M. Wiedemann | 49b586a | 2010-06-02 05:32:30 +0200 | [diff] [blame] | 1670 | { 0x27, "semicolon" }, |
| 1671 | { 0x28, "apostrophe" }, |
| 1672 | { 0x29, "grave_accent" }, |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1673 | |
Bernhard M. Wiedemann | 49b586a | 2010-06-02 05:32:30 +0200 | [diff] [blame] | 1674 | { 0x2b, "backslash" }, |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1675 | { 0x2c, "z" }, |
| 1676 | { 0x2d, "x" }, |
| 1677 | { 0x2e, "c" }, |
| 1678 | { 0x2f, "v" }, |
| 1679 | { 0x30, "b" }, |
| 1680 | { 0x31, "n" }, |
| 1681 | { 0x32, "m" }, |
aurel32 | 9155fc4 | 2008-10-01 21:46:15 +0000 | [diff] [blame] | 1682 | { 0x33, "comma" }, |
| 1683 | { 0x34, "dot" }, |
| 1684 | { 0x35, "slash" }, |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1685 | |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 1686 | { 0x37, "asterisk" }, |
| 1687 | |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1688 | { 0x39, "spc" }, |
bellard | 00ffa62 | 2004-06-04 13:25:15 +0000 | [diff] [blame] | 1689 | { 0x3a, "caps_lock" }, |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1690 | { 0x3b, "f1" }, |
| 1691 | { 0x3c, "f2" }, |
| 1692 | { 0x3d, "f3" }, |
| 1693 | { 0x3e, "f4" }, |
| 1694 | { 0x3f, "f5" }, |
| 1695 | { 0x40, "f6" }, |
| 1696 | { 0x41, "f7" }, |
| 1697 | { 0x42, "f8" }, |
| 1698 | { 0x43, "f9" }, |
| 1699 | { 0x44, "f10" }, |
bellard | 00ffa62 | 2004-06-04 13:25:15 +0000 | [diff] [blame] | 1700 | { 0x45, "num_lock" }, |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1701 | { 0x46, "scroll_lock" }, |
| 1702 | |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1703 | { 0xb5, "kp_divide" }, |
| 1704 | { 0x37, "kp_multiply" }, |
ths | 0cfec83 | 2007-06-23 16:02:43 +0000 | [diff] [blame] | 1705 | { 0x4a, "kp_subtract" }, |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1706 | { 0x4e, "kp_add" }, |
| 1707 | { 0x9c, "kp_enter" }, |
| 1708 | { 0x53, "kp_decimal" }, |
balrog | f2289cb | 2008-06-04 10:14:16 +0000 | [diff] [blame] | 1709 | { 0x54, "sysrq" }, |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1710 | |
| 1711 | { 0x52, "kp_0" }, |
| 1712 | { 0x4f, "kp_1" }, |
| 1713 | { 0x50, "kp_2" }, |
| 1714 | { 0x51, "kp_3" }, |
| 1715 | { 0x4b, "kp_4" }, |
| 1716 | { 0x4c, "kp_5" }, |
| 1717 | { 0x4d, "kp_6" }, |
| 1718 | { 0x47, "kp_7" }, |
| 1719 | { 0x48, "kp_8" }, |
| 1720 | { 0x49, "kp_9" }, |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1721 | |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1722 | { 0x56, "<" }, |
| 1723 | |
| 1724 | { 0x57, "f11" }, |
| 1725 | { 0x58, "f12" }, |
| 1726 | |
| 1727 | { 0xb7, "print" }, |
| 1728 | |
| 1729 | { 0xc7, "home" }, |
| 1730 | { 0xc9, "pgup" }, |
| 1731 | { 0xd1, "pgdn" }, |
| 1732 | { 0xcf, "end" }, |
| 1733 | |
| 1734 | { 0xcb, "left" }, |
| 1735 | { 0xc8, "up" }, |
| 1736 | { 0xd0, "down" }, |
| 1737 | { 0xcd, "right" }, |
| 1738 | |
| 1739 | { 0xd2, "insert" }, |
| 1740 | { 0xd3, "delete" }, |
blueswir1 | c0b5b10 | 2008-06-22 07:45:42 +0000 | [diff] [blame] | 1741 | #if defined(TARGET_SPARC) && !defined(TARGET_SPARC64) |
| 1742 | { 0xf0, "stop" }, |
| 1743 | { 0xf1, "again" }, |
| 1744 | { 0xf2, "props" }, |
| 1745 | { 0xf3, "undo" }, |
| 1746 | { 0xf4, "front" }, |
| 1747 | { 0xf5, "copy" }, |
| 1748 | { 0xf6, "open" }, |
| 1749 | { 0xf7, "paste" }, |
| 1750 | { 0xf8, "find" }, |
| 1751 | { 0xf9, "cut" }, |
| 1752 | { 0xfa, "lf" }, |
| 1753 | { 0xfb, "help" }, |
| 1754 | { 0xfc, "meta_l" }, |
| 1755 | { 0xfd, "meta_r" }, |
| 1756 | { 0xfe, "compose" }, |
| 1757 | #endif |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1758 | { 0, NULL }, |
| 1759 | }; |
| 1760 | |
| 1761 | static int get_keycode(const char *key) |
| 1762 | { |
| 1763 | const KeyDef *p; |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1764 | char *endp; |
| 1765 | int ret; |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1766 | |
| 1767 | for(p = key_defs; p->name != NULL; p++) { |
| 1768 | if (!strcmp(key, p->name)) |
| 1769 | return p->keycode; |
| 1770 | } |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1771 | if (strstart(key, "0x", NULL)) { |
| 1772 | ret = strtoul(key, &endp, 0); |
| 1773 | if (*endp == '\0' && ret >= 0x01 && ret <= 0xff) |
| 1774 | return ret; |
| 1775 | } |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1776 | return -1; |
| 1777 | } |
| 1778 | |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1779 | #define MAX_KEYCODES 16 |
| 1780 | static uint8_t keycodes[MAX_KEYCODES]; |
| 1781 | static int nb_pending_keycodes; |
| 1782 | static QEMUTimer *key_timer; |
| 1783 | |
| 1784 | static void release_keys(void *opaque) |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1785 | { |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1786 | int keycode; |
| 1787 | |
| 1788 | while (nb_pending_keycodes > 0) { |
| 1789 | nb_pending_keycodes--; |
| 1790 | keycode = keycodes[nb_pending_keycodes]; |
| 1791 | if (keycode & 0x80) |
| 1792 | kbd_put_keycode(0xe0); |
| 1793 | kbd_put_keycode(keycode | 0x80); |
| 1794 | } |
| 1795 | } |
| 1796 | |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 1797 | static void do_sendkey(Monitor *mon, const QDict *qdict) |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1798 | { |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1799 | char keyname_buf[16]; |
| 1800 | char *separator; |
| 1801 | int keyname_len, keycode, i; |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 1802 | const char *string = qdict_get_str(qdict, "string"); |
| 1803 | int has_hold_time = qdict_haskey(qdict, "hold_time"); |
| 1804 | int hold_time = qdict_get_try_int(qdict, "hold_time", -1); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1805 | |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1806 | if (nb_pending_keycodes > 0) { |
| 1807 | qemu_del_timer(key_timer); |
| 1808 | release_keys(NULL); |
| 1809 | } |
| 1810 | if (!has_hold_time) |
| 1811 | hold_time = 100; |
| 1812 | i = 0; |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1813 | while (1) { |
| 1814 | separator = strchr(string, '-'); |
| 1815 | keyname_len = separator ? separator - string : strlen(string); |
| 1816 | if (keyname_len > 0) { |
| 1817 | pstrcpy(keyname_buf, sizeof(keyname_buf), string); |
| 1818 | if (keyname_len > sizeof(keyname_buf) - 1) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1819 | monitor_printf(mon, "invalid key: '%s...'\n", keyname_buf); |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1820 | return; |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1821 | } |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1822 | if (i == MAX_KEYCODES) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1823 | monitor_printf(mon, "too many keys\n"); |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1824 | return; |
| 1825 | } |
| 1826 | keyname_buf[keyname_len] = 0; |
| 1827 | keycode = get_keycode(keyname_buf); |
| 1828 | if (keycode < 0) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1829 | monitor_printf(mon, "unknown key: '%s'\n", keyname_buf); |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1830 | return; |
| 1831 | } |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1832 | keycodes[i++] = keycode; |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1833 | } |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1834 | if (!separator) |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1835 | break; |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1836 | string = separator + 1; |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1837 | } |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1838 | nb_pending_keycodes = i; |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1839 | /* key down events */ |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1840 | for (i = 0; i < nb_pending_keycodes; i++) { |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1841 | keycode = keycodes[i]; |
| 1842 | if (keycode & 0x80) |
| 1843 | kbd_put_keycode(0xe0); |
| 1844 | kbd_put_keycode(keycode & 0x7f); |
| 1845 | } |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1846 | /* delayed key up events */ |
Paolo Bonzini | 7447545 | 2011-03-11 16:47:48 +0100 | [diff] [blame] | 1847 | qemu_mod_timer(key_timer, qemu_get_clock_ns(vm_clock) + |
Juan Quintela | 6ee093c | 2009-09-10 03:04:26 +0200 | [diff] [blame] | 1848 | muldiv64(get_ticks_per_sec(), hold_time, 1000)); |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1849 | } |
| 1850 | |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1851 | static int mouse_button_state; |
| 1852 | |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 1853 | static void do_mouse_move(Monitor *mon, const QDict *qdict) |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1854 | { |
| 1855 | int dx, dy, dz; |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 1856 | const char *dx_str = qdict_get_str(qdict, "dx_str"); |
| 1857 | const char *dy_str = qdict_get_str(qdict, "dy_str"); |
| 1858 | const char *dz_str = qdict_get_try_str(qdict, "dz_str"); |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1859 | dx = strtol(dx_str, NULL, 0); |
| 1860 | dy = strtol(dy_str, NULL, 0); |
| 1861 | dz = 0; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1862 | if (dz_str) |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1863 | dz = strtol(dz_str, NULL, 0); |
| 1864 | kbd_mouse_event(dx, dy, dz, mouse_button_state); |
| 1865 | } |
| 1866 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1867 | static void do_mouse_button(Monitor *mon, const QDict *qdict) |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1868 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1869 | int button_state = qdict_get_int(qdict, "button_state"); |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1870 | mouse_button_state = button_state; |
| 1871 | kbd_mouse_event(0, 0, 0, mouse_button_state); |
| 1872 | } |
| 1873 | |
Luiz Capitulino | aa93e39 | 2009-08-28 15:27:18 -0300 | [diff] [blame] | 1874 | static void do_ioport_read(Monitor *mon, const QDict *qdict) |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1875 | { |
Luiz Capitulino | aa93e39 | 2009-08-28 15:27:18 -0300 | [diff] [blame] | 1876 | int size = qdict_get_int(qdict, "size"); |
| 1877 | int addr = qdict_get_int(qdict, "addr"); |
| 1878 | int has_index = qdict_haskey(qdict, "index"); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1879 | uint32_t val; |
| 1880 | int suffix; |
| 1881 | |
| 1882 | if (has_index) { |
Luiz Capitulino | aa93e39 | 2009-08-28 15:27:18 -0300 | [diff] [blame] | 1883 | int index = qdict_get_int(qdict, "index"); |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1884 | cpu_outb(addr & IOPORTS_MASK, index & 0xff); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1885 | addr++; |
| 1886 | } |
| 1887 | addr &= 0xffff; |
| 1888 | |
| 1889 | switch(size) { |
| 1890 | default: |
| 1891 | case 1: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1892 | val = cpu_inb(addr); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1893 | suffix = 'b'; |
| 1894 | break; |
| 1895 | case 2: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1896 | val = cpu_inw(addr); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1897 | suffix = 'w'; |
| 1898 | break; |
| 1899 | case 4: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1900 | val = cpu_inl(addr); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1901 | suffix = 'l'; |
| 1902 | break; |
| 1903 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1904 | monitor_printf(mon, "port%c[0x%04x] = %#0*x\n", |
| 1905 | suffix, addr, size * 2, val); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1906 | } |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1907 | |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1908 | static void do_ioport_write(Monitor *mon, const QDict *qdict) |
Jan Kiszka | f114784 | 2009-07-14 10:20:11 +0200 | [diff] [blame] | 1909 | { |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1910 | int size = qdict_get_int(qdict, "size"); |
| 1911 | int addr = qdict_get_int(qdict, "addr"); |
| 1912 | int val = qdict_get_int(qdict, "val"); |
| 1913 | |
Jan Kiszka | f114784 | 2009-07-14 10:20:11 +0200 | [diff] [blame] | 1914 | addr &= IOPORTS_MASK; |
| 1915 | |
| 1916 | switch (size) { |
| 1917 | default: |
| 1918 | case 1: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1919 | cpu_outb(addr, val); |
Jan Kiszka | f114784 | 2009-07-14 10:20:11 +0200 | [diff] [blame] | 1920 | break; |
| 1921 | case 2: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1922 | cpu_outw(addr, val); |
Jan Kiszka | f114784 | 2009-07-14 10:20:11 +0200 | [diff] [blame] | 1923 | break; |
| 1924 | case 4: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1925 | cpu_outl(addr, val); |
Jan Kiszka | f114784 | 2009-07-14 10:20:11 +0200 | [diff] [blame] | 1926 | break; |
| 1927 | } |
| 1928 | } |
| 1929 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1930 | static void do_boot_set(Monitor *mon, const QDict *qdict) |
aurel32 | 0ecdffb | 2008-05-04 20:11:34 +0000 | [diff] [blame] | 1931 | { |
| 1932 | int res; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1933 | const char *bootdevice = qdict_get_str(qdict, "bootdevice"); |
aurel32 | 0ecdffb | 2008-05-04 20:11:34 +0000 | [diff] [blame] | 1934 | |
Jan Kiszka | 76e30d0 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1935 | res = qemu_boot_set(bootdevice); |
| 1936 | if (res == 0) { |
| 1937 | monitor_printf(mon, "boot device list now set to %s\n", bootdevice); |
| 1938 | } else if (res > 0) { |
| 1939 | monitor_printf(mon, "setting boot device list failed\n"); |
aurel32 | 0ecdffb | 2008-05-04 20:11:34 +0000 | [diff] [blame] | 1940 | } else { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1941 | monitor_printf(mon, "no function defined to set boot device list for " |
| 1942 | "this architecture\n"); |
aurel32 | 0ecdffb | 2008-05-04 20:11:34 +0000 | [diff] [blame] | 1943 | } |
| 1944 | } |
| 1945 | |
Luiz Capitulino | c80d259 | 2009-10-07 13:41:58 -0300 | [diff] [blame] | 1946 | /** |
Luiz Capitulino | 4307666 | 2009-10-07 13:41:59 -0300 | [diff] [blame] | 1947 | * do_system_powerdown(): Issue a machine powerdown |
| 1948 | */ |
Luiz Capitulino | ef4b7ee | 2010-02-10 23:49:48 -0200 | [diff] [blame] | 1949 | static int do_system_powerdown(Monitor *mon, const QDict *qdict, |
| 1950 | QObject **ret_data) |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 1951 | { |
| 1952 | qemu_system_powerdown_request(); |
Luiz Capitulino | ef4b7ee | 2010-02-10 23:49:48 -0200 | [diff] [blame] | 1953 | return 0; |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1956 | #if defined(TARGET_I386) |
Blue Swirl | d65aaf3 | 2010-12-11 18:56:24 +0000 | [diff] [blame] | 1957 | static void print_pte(Monitor *mon, target_phys_addr_t addr, |
| 1958 | target_phys_addr_t pte, |
| 1959 | target_phys_addr_t mask) |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1960 | { |
Blue Swirl | d65aaf3 | 2010-12-11 18:56:24 +0000 | [diff] [blame] | 1961 | #ifdef TARGET_X86_64 |
| 1962 | if (addr & (1ULL << 47)) { |
| 1963 | addr |= -1LL << 48; |
| 1964 | } |
| 1965 | #endif |
| 1966 | monitor_printf(mon, TARGET_FMT_plx ": " TARGET_FMT_plx |
| 1967 | " %c%c%c%c%c%c%c%c%c\n", |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1968 | addr, |
| 1969 | pte & mask, |
Blue Swirl | d65aaf3 | 2010-12-11 18:56:24 +0000 | [diff] [blame] | 1970 | pte & PG_NX_MASK ? 'X' : '-', |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1971 | pte & PG_GLOBAL_MASK ? 'G' : '-', |
| 1972 | pte & PG_PSE_MASK ? 'P' : '-', |
| 1973 | pte & PG_DIRTY_MASK ? 'D' : '-', |
| 1974 | pte & PG_ACCESSED_MASK ? 'A' : '-', |
| 1975 | pte & PG_PCD_MASK ? 'C' : '-', |
| 1976 | pte & PG_PWT_MASK ? 'T' : '-', |
| 1977 | pte & PG_USER_MASK ? 'U' : '-', |
| 1978 | pte & PG_RW_MASK ? 'W' : '-'); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1979 | } |
| 1980 | |
Blue Swirl | d65aaf3 | 2010-12-11 18:56:24 +0000 | [diff] [blame] | 1981 | static void tlb_info_32(Monitor *mon, CPUState *env) |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1982 | { |
Austin Clements | 94ac5cd | 2011-08-21 14:49:45 -0400 | [diff] [blame] | 1983 | unsigned int l1, l2; |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1984 | uint32_t pgd, pde, pte; |
| 1985 | |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1986 | pgd = env->cr[3] & ~0xfff; |
| 1987 | for(l1 = 0; l1 < 1024; l1++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 1988 | cpu_physical_memory_read(pgd + l1 * 4, &pde, 4); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1989 | pde = le32_to_cpu(pde); |
| 1990 | if (pde & PG_PRESENT_MASK) { |
| 1991 | if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { |
Blue Swirl | d65aaf3 | 2010-12-11 18:56:24 +0000 | [diff] [blame] | 1992 | /* 4M pages */ |
| 1993 | print_pte(mon, (l1 << 22), pde, ~((1 << 21) - 1)); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1994 | } else { |
| 1995 | for(l2 = 0; l2 < 1024; l2++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 1996 | cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, &pte, 4); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1997 | pte = le32_to_cpu(pte); |
| 1998 | if (pte & PG_PRESENT_MASK) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1999 | print_pte(mon, (l1 << 22) + (l2 << 12), |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 2000 | pte & ~PG_PSE_MASK, |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2001 | ~0xfff); |
| 2002 | } |
| 2003 | } |
| 2004 | } |
| 2005 | } |
| 2006 | } |
| 2007 | } |
| 2008 | |
Blue Swirl | d65aaf3 | 2010-12-11 18:56:24 +0000 | [diff] [blame] | 2009 | static void tlb_info_pae32(Monitor *mon, CPUState *env) |
| 2010 | { |
Austin Clements | 94ac5cd | 2011-08-21 14:49:45 -0400 | [diff] [blame] | 2011 | unsigned int l1, l2, l3; |
Blue Swirl | d65aaf3 | 2010-12-11 18:56:24 +0000 | [diff] [blame] | 2012 | uint64_t pdpe, pde, pte; |
| 2013 | uint64_t pdp_addr, pd_addr, pt_addr; |
| 2014 | |
| 2015 | pdp_addr = env->cr[3] & ~0x1f; |
| 2016 | for (l1 = 0; l1 < 4; l1++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2017 | cpu_physical_memory_read(pdp_addr + l1 * 8, &pdpe, 8); |
Blue Swirl | d65aaf3 | 2010-12-11 18:56:24 +0000 | [diff] [blame] | 2018 | pdpe = le64_to_cpu(pdpe); |
| 2019 | if (pdpe & PG_PRESENT_MASK) { |
| 2020 | pd_addr = pdpe & 0x3fffffffff000ULL; |
| 2021 | for (l2 = 0; l2 < 512; l2++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2022 | cpu_physical_memory_read(pd_addr + l2 * 8, &pde, 8); |
Blue Swirl | d65aaf3 | 2010-12-11 18:56:24 +0000 | [diff] [blame] | 2023 | pde = le64_to_cpu(pde); |
| 2024 | if (pde & PG_PRESENT_MASK) { |
| 2025 | if (pde & PG_PSE_MASK) { |
| 2026 | /* 2M pages with PAE, CR4.PSE is ignored */ |
| 2027 | print_pte(mon, (l1 << 30 ) + (l2 << 21), pde, |
| 2028 | ~((target_phys_addr_t)(1 << 20) - 1)); |
| 2029 | } else { |
| 2030 | pt_addr = pde & 0x3fffffffff000ULL; |
| 2031 | for (l3 = 0; l3 < 512; l3++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2032 | cpu_physical_memory_read(pt_addr + l3 * 8, &pte, 8); |
Blue Swirl | d65aaf3 | 2010-12-11 18:56:24 +0000 | [diff] [blame] | 2033 | pte = le64_to_cpu(pte); |
| 2034 | if (pte & PG_PRESENT_MASK) { |
| 2035 | print_pte(mon, (l1 << 30 ) + (l2 << 21) |
| 2036 | + (l3 << 12), |
| 2037 | pte & ~PG_PSE_MASK, |
| 2038 | ~(target_phys_addr_t)0xfff); |
| 2039 | } |
| 2040 | } |
| 2041 | } |
| 2042 | } |
| 2043 | } |
| 2044 | } |
| 2045 | } |
| 2046 | } |
| 2047 | |
| 2048 | #ifdef TARGET_X86_64 |
| 2049 | static void tlb_info_64(Monitor *mon, CPUState *env) |
| 2050 | { |
| 2051 | uint64_t l1, l2, l3, l4; |
| 2052 | uint64_t pml4e, pdpe, pde, pte; |
| 2053 | uint64_t pml4_addr, pdp_addr, pd_addr, pt_addr; |
| 2054 | |
| 2055 | pml4_addr = env->cr[3] & 0x3fffffffff000ULL; |
| 2056 | for (l1 = 0; l1 < 512; l1++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2057 | cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8); |
Blue Swirl | d65aaf3 | 2010-12-11 18:56:24 +0000 | [diff] [blame] | 2058 | pml4e = le64_to_cpu(pml4e); |
| 2059 | if (pml4e & PG_PRESENT_MASK) { |
| 2060 | pdp_addr = pml4e & 0x3fffffffff000ULL; |
| 2061 | for (l2 = 0; l2 < 512; l2++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2062 | cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8); |
Blue Swirl | d65aaf3 | 2010-12-11 18:56:24 +0000 | [diff] [blame] | 2063 | pdpe = le64_to_cpu(pdpe); |
| 2064 | if (pdpe & PG_PRESENT_MASK) { |
| 2065 | if (pdpe & PG_PSE_MASK) { |
| 2066 | /* 1G pages, CR4.PSE is ignored */ |
| 2067 | print_pte(mon, (l1 << 39) + (l2 << 30), pdpe, |
| 2068 | 0x3ffffc0000000ULL); |
| 2069 | } else { |
| 2070 | pd_addr = pdpe & 0x3fffffffff000ULL; |
| 2071 | for (l3 = 0; l3 < 512; l3++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2072 | cpu_physical_memory_read(pd_addr + l3 * 8, &pde, 8); |
Blue Swirl | d65aaf3 | 2010-12-11 18:56:24 +0000 | [diff] [blame] | 2073 | pde = le64_to_cpu(pde); |
| 2074 | if (pde & PG_PRESENT_MASK) { |
| 2075 | if (pde & PG_PSE_MASK) { |
| 2076 | /* 2M pages, CR4.PSE is ignored */ |
| 2077 | print_pte(mon, (l1 << 39) + (l2 << 30) + |
| 2078 | (l3 << 21), pde, |
| 2079 | 0x3ffffffe00000ULL); |
| 2080 | } else { |
| 2081 | pt_addr = pde & 0x3fffffffff000ULL; |
| 2082 | for (l4 = 0; l4 < 512; l4++) { |
| 2083 | cpu_physical_memory_read(pt_addr |
| 2084 | + l4 * 8, |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2085 | &pte, 8); |
Blue Swirl | d65aaf3 | 2010-12-11 18:56:24 +0000 | [diff] [blame] | 2086 | pte = le64_to_cpu(pte); |
| 2087 | if (pte & PG_PRESENT_MASK) { |
| 2088 | print_pte(mon, (l1 << 39) + |
| 2089 | (l2 << 30) + |
| 2090 | (l3 << 21) + (l4 << 12), |
| 2091 | pte & ~PG_PSE_MASK, |
| 2092 | 0x3fffffffff000ULL); |
| 2093 | } |
| 2094 | } |
| 2095 | } |
| 2096 | } |
| 2097 | } |
| 2098 | } |
| 2099 | } |
| 2100 | } |
| 2101 | } |
| 2102 | } |
| 2103 | } |
| 2104 | #endif |
| 2105 | |
| 2106 | static void tlb_info(Monitor *mon) |
| 2107 | { |
| 2108 | CPUState *env; |
| 2109 | |
| 2110 | env = mon_get_cpu(); |
| 2111 | |
| 2112 | if (!(env->cr[0] & CR0_PG_MASK)) { |
| 2113 | monitor_printf(mon, "PG disabled\n"); |
| 2114 | return; |
| 2115 | } |
| 2116 | if (env->cr[4] & CR4_PAE_MASK) { |
| 2117 | #ifdef TARGET_X86_64 |
| 2118 | if (env->hflags & HF_LMA_MASK) { |
| 2119 | tlb_info_64(mon, env); |
| 2120 | } else |
| 2121 | #endif |
| 2122 | { |
| 2123 | tlb_info_pae32(mon, env); |
| 2124 | } |
| 2125 | } else { |
| 2126 | tlb_info_32(mon, env); |
| 2127 | } |
| 2128 | } |
| 2129 | |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2130 | static void mem_print(Monitor *mon, target_phys_addr_t *pstart, |
| 2131 | int *plast_prot, |
| 2132 | target_phys_addr_t end, int prot) |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2133 | { |
bellard | 9746b15 | 2004-11-11 18:30:24 +0000 | [diff] [blame] | 2134 | int prot1; |
| 2135 | prot1 = *plast_prot; |
| 2136 | if (prot != prot1) { |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2137 | if (*pstart != -1) { |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2138 | monitor_printf(mon, TARGET_FMT_plx "-" TARGET_FMT_plx " " |
| 2139 | TARGET_FMT_plx " %c%c%c\n", |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2140 | *pstart, end, end - *pstart, |
| 2141 | prot1 & PG_USER_MASK ? 'u' : '-', |
| 2142 | 'r', |
| 2143 | prot1 & PG_RW_MASK ? 'w' : '-'); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2144 | } |
| 2145 | if (prot != 0) |
| 2146 | *pstart = end; |
| 2147 | else |
| 2148 | *pstart = -1; |
| 2149 | *plast_prot = prot; |
| 2150 | } |
| 2151 | } |
| 2152 | |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2153 | static void mem_info_32(Monitor *mon, CPUState *env) |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2154 | { |
Austin Clements | b49ca72 | 2011-08-14 23:19:21 -0400 | [diff] [blame] | 2155 | unsigned int l1, l2; |
| 2156 | int prot, last_prot; |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2157 | uint32_t pgd, pde, pte; |
| 2158 | target_phys_addr_t start, end; |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2159 | |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2160 | pgd = env->cr[3] & ~0xfff; |
| 2161 | last_prot = 0; |
| 2162 | start = -1; |
| 2163 | for(l1 = 0; l1 < 1024; l1++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2164 | cpu_physical_memory_read(pgd + l1 * 4, &pde, 4); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2165 | pde = le32_to_cpu(pde); |
| 2166 | end = l1 << 22; |
| 2167 | if (pde & PG_PRESENT_MASK) { |
| 2168 | if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { |
| 2169 | prot = pde & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2170 | mem_print(mon, &start, &last_prot, end, prot); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2171 | } else { |
| 2172 | for(l2 = 0; l2 < 1024; l2++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2173 | cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, &pte, 4); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2174 | pte = le32_to_cpu(pte); |
| 2175 | end = (l1 << 22) + (l2 << 12); |
| 2176 | if (pte & PG_PRESENT_MASK) { |
Austin Clements | c76c841 | 2011-08-14 23:22:28 -0400 | [diff] [blame] | 2177 | prot = pte & pde & |
| 2178 | (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2179 | } else { |
| 2180 | prot = 0; |
| 2181 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2182 | mem_print(mon, &start, &last_prot, end, prot); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2183 | } |
| 2184 | } |
| 2185 | } else { |
| 2186 | prot = 0; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2187 | mem_print(mon, &start, &last_prot, end, prot); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2188 | } |
| 2189 | } |
Austin Clements | 8a94b8ca | 2011-08-14 23:22:04 -0400 | [diff] [blame] | 2190 | /* Flush last range */ |
| 2191 | mem_print(mon, &start, &last_prot, (target_phys_addr_t)1 << 32, 0); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2192 | } |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2193 | |
| 2194 | static void mem_info_pae32(Monitor *mon, CPUState *env) |
| 2195 | { |
Austin Clements | b49ca72 | 2011-08-14 23:19:21 -0400 | [diff] [blame] | 2196 | unsigned int l1, l2, l3; |
| 2197 | int prot, last_prot; |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2198 | uint64_t pdpe, pde, pte; |
| 2199 | uint64_t pdp_addr, pd_addr, pt_addr; |
| 2200 | target_phys_addr_t start, end; |
| 2201 | |
| 2202 | pdp_addr = env->cr[3] & ~0x1f; |
| 2203 | last_prot = 0; |
| 2204 | start = -1; |
| 2205 | for (l1 = 0; l1 < 4; l1++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2206 | cpu_physical_memory_read(pdp_addr + l1 * 8, &pdpe, 8); |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2207 | pdpe = le64_to_cpu(pdpe); |
| 2208 | end = l1 << 30; |
| 2209 | if (pdpe & PG_PRESENT_MASK) { |
| 2210 | pd_addr = pdpe & 0x3fffffffff000ULL; |
| 2211 | for (l2 = 0; l2 < 512; l2++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2212 | cpu_physical_memory_read(pd_addr + l2 * 8, &pde, 8); |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2213 | pde = le64_to_cpu(pde); |
| 2214 | end = (l1 << 30) + (l2 << 21); |
| 2215 | if (pde & PG_PRESENT_MASK) { |
| 2216 | if (pde & PG_PSE_MASK) { |
| 2217 | prot = pde & (PG_USER_MASK | PG_RW_MASK | |
| 2218 | PG_PRESENT_MASK); |
| 2219 | mem_print(mon, &start, &last_prot, end, prot); |
| 2220 | } else { |
| 2221 | pt_addr = pde & 0x3fffffffff000ULL; |
| 2222 | for (l3 = 0; l3 < 512; l3++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2223 | cpu_physical_memory_read(pt_addr + l3 * 8, &pte, 8); |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2224 | pte = le64_to_cpu(pte); |
| 2225 | end = (l1 << 30) + (l2 << 21) + (l3 << 12); |
| 2226 | if (pte & PG_PRESENT_MASK) { |
Austin Clements | c76c841 | 2011-08-14 23:22:28 -0400 | [diff] [blame] | 2227 | prot = pte & pde & (PG_USER_MASK | PG_RW_MASK | |
| 2228 | PG_PRESENT_MASK); |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2229 | } else { |
| 2230 | prot = 0; |
| 2231 | } |
| 2232 | mem_print(mon, &start, &last_prot, end, prot); |
| 2233 | } |
| 2234 | } |
| 2235 | } else { |
| 2236 | prot = 0; |
| 2237 | mem_print(mon, &start, &last_prot, end, prot); |
| 2238 | } |
| 2239 | } |
| 2240 | } else { |
| 2241 | prot = 0; |
| 2242 | mem_print(mon, &start, &last_prot, end, prot); |
| 2243 | } |
| 2244 | } |
Austin Clements | 8a94b8ca | 2011-08-14 23:22:04 -0400 | [diff] [blame] | 2245 | /* Flush last range */ |
| 2246 | mem_print(mon, &start, &last_prot, (target_phys_addr_t)1 << 32, 0); |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2247 | } |
| 2248 | |
| 2249 | |
| 2250 | #ifdef TARGET_X86_64 |
| 2251 | static void mem_info_64(Monitor *mon, CPUState *env) |
| 2252 | { |
| 2253 | int prot, last_prot; |
| 2254 | uint64_t l1, l2, l3, l4; |
| 2255 | uint64_t pml4e, pdpe, pde, pte; |
| 2256 | uint64_t pml4_addr, pdp_addr, pd_addr, pt_addr, start, end; |
| 2257 | |
| 2258 | pml4_addr = env->cr[3] & 0x3fffffffff000ULL; |
| 2259 | last_prot = 0; |
| 2260 | start = -1; |
| 2261 | for (l1 = 0; l1 < 512; l1++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2262 | cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8); |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2263 | pml4e = le64_to_cpu(pml4e); |
| 2264 | end = l1 << 39; |
| 2265 | if (pml4e & PG_PRESENT_MASK) { |
| 2266 | pdp_addr = pml4e & 0x3fffffffff000ULL; |
| 2267 | for (l2 = 0; l2 < 512; l2++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2268 | cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8); |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2269 | pdpe = le64_to_cpu(pdpe); |
| 2270 | end = (l1 << 39) + (l2 << 30); |
| 2271 | if (pdpe & PG_PRESENT_MASK) { |
| 2272 | if (pdpe & PG_PSE_MASK) { |
Blue Swirl | 2d5b507 | 2011-01-15 08:31:00 +0000 | [diff] [blame] | 2273 | prot = pdpe & (PG_USER_MASK | PG_RW_MASK | |
| 2274 | PG_PRESENT_MASK); |
Austin Clements | c76c841 | 2011-08-14 23:22:28 -0400 | [diff] [blame] | 2275 | prot &= pml4e; |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2276 | mem_print(mon, &start, &last_prot, end, prot); |
| 2277 | } else { |
| 2278 | pd_addr = pdpe & 0x3fffffffff000ULL; |
| 2279 | for (l3 = 0; l3 < 512; l3++) { |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2280 | cpu_physical_memory_read(pd_addr + l3 * 8, &pde, 8); |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2281 | pde = le64_to_cpu(pde); |
| 2282 | end = (l1 << 39) + (l2 << 30) + (l3 << 21); |
| 2283 | if (pde & PG_PRESENT_MASK) { |
| 2284 | if (pde & PG_PSE_MASK) { |
| 2285 | prot = pde & (PG_USER_MASK | PG_RW_MASK | |
| 2286 | PG_PRESENT_MASK); |
Austin Clements | c76c841 | 2011-08-14 23:22:28 -0400 | [diff] [blame] | 2287 | prot &= pml4e & pdpe; |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2288 | mem_print(mon, &start, &last_prot, end, prot); |
| 2289 | } else { |
| 2290 | pt_addr = pde & 0x3fffffffff000ULL; |
| 2291 | for (l4 = 0; l4 < 512; l4++) { |
| 2292 | cpu_physical_memory_read(pt_addr |
| 2293 | + l4 * 8, |
Stefan Weil | b8b7932 | 2011-03-26 21:11:05 +0100 | [diff] [blame] | 2294 | &pte, 8); |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2295 | pte = le64_to_cpu(pte); |
| 2296 | end = (l1 << 39) + (l2 << 30) + |
| 2297 | (l3 << 21) + (l4 << 12); |
| 2298 | if (pte & PG_PRESENT_MASK) { |
| 2299 | prot = pte & (PG_USER_MASK | PG_RW_MASK | |
| 2300 | PG_PRESENT_MASK); |
Austin Clements | c76c841 | 2011-08-14 23:22:28 -0400 | [diff] [blame] | 2301 | prot &= pml4e & pdpe & pde; |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2302 | } else { |
| 2303 | prot = 0; |
| 2304 | } |
| 2305 | mem_print(mon, &start, &last_prot, end, prot); |
| 2306 | } |
| 2307 | } |
| 2308 | } else { |
| 2309 | prot = 0; |
| 2310 | mem_print(mon, &start, &last_prot, end, prot); |
| 2311 | } |
| 2312 | } |
| 2313 | } |
| 2314 | } else { |
| 2315 | prot = 0; |
| 2316 | mem_print(mon, &start, &last_prot, end, prot); |
| 2317 | } |
| 2318 | } |
| 2319 | } else { |
| 2320 | prot = 0; |
| 2321 | mem_print(mon, &start, &last_prot, end, prot); |
| 2322 | } |
| 2323 | } |
Austin Clements | 8a94b8ca | 2011-08-14 23:22:04 -0400 | [diff] [blame] | 2324 | /* Flush last range */ |
| 2325 | mem_print(mon, &start, &last_prot, (target_phys_addr_t)1 << 48, 0); |
Blue Swirl | 1b3cba6 | 2010-12-11 18:56:27 +0000 | [diff] [blame] | 2326 | } |
| 2327 | #endif |
| 2328 | |
| 2329 | static void mem_info(Monitor *mon) |
| 2330 | { |
| 2331 | CPUState *env; |
| 2332 | |
| 2333 | env = mon_get_cpu(); |
| 2334 | |
| 2335 | if (!(env->cr[0] & CR0_PG_MASK)) { |
| 2336 | monitor_printf(mon, "PG disabled\n"); |
| 2337 | return; |
| 2338 | } |
| 2339 | if (env->cr[4] & CR4_PAE_MASK) { |
| 2340 | #ifdef TARGET_X86_64 |
| 2341 | if (env->hflags & HF_LMA_MASK) { |
| 2342 | mem_info_64(mon, env); |
| 2343 | } else |
| 2344 | #endif |
| 2345 | { |
| 2346 | mem_info_pae32(mon, env); |
| 2347 | } |
| 2348 | } else { |
| 2349 | mem_info_32(mon, env); |
| 2350 | } |
| 2351 | } |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2352 | #endif |
| 2353 | |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2354 | #if defined(TARGET_SH4) |
| 2355 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2356 | static void print_tlb(Monitor *mon, int idx, tlb_t *tlb) |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2357 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2358 | monitor_printf(mon, " tlb%i:\t" |
| 2359 | "asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t" |
| 2360 | "v=%hhu shared=%hhu cached=%hhu prot=%hhu " |
| 2361 | "dirty=%hhu writethrough=%hhu\n", |
| 2362 | idx, |
| 2363 | tlb->asid, tlb->vpn, tlb->ppn, tlb->sz, tlb->size, |
| 2364 | tlb->v, tlb->sh, tlb->c, tlb->pr, |
| 2365 | tlb->d, tlb->wt); |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2366 | } |
| 2367 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2368 | static void tlb_info(Monitor *mon) |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2369 | { |
| 2370 | CPUState *env = mon_get_cpu(); |
| 2371 | int i; |
| 2372 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2373 | monitor_printf (mon, "ITLB:\n"); |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2374 | for (i = 0 ; i < ITLB_SIZE ; i++) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2375 | print_tlb (mon, i, &env->itlb[i]); |
| 2376 | monitor_printf (mon, "UTLB:\n"); |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2377 | for (i = 0 ; i < UTLB_SIZE ; i++) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2378 | print_tlb (mon, i, &env->utlb[i]); |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | #endif |
| 2382 | |
Scott Wood | bebabbc | 2011-08-18 10:38:42 +0000 | [diff] [blame] | 2383 | #if defined(TARGET_SPARC) || defined(TARGET_PPC) |
Blue Swirl | d41160a | 2010-12-19 13:42:56 +0000 | [diff] [blame] | 2384 | static void tlb_info(Monitor *mon) |
| 2385 | { |
| 2386 | CPUState *env1 = mon_get_cpu(); |
| 2387 | |
| 2388 | dump_mmu((FILE*)mon, (fprintf_function)monitor_printf, env1); |
| 2389 | } |
| 2390 | #endif |
| 2391 | |
Blue Swirl | 314e298 | 2011-09-11 20:22:05 +0000 | [diff] [blame] | 2392 | static void do_info_mtree(Monitor *mon) |
| 2393 | { |
| 2394 | mtree_info((fprintf_function)monitor_printf, mon); |
| 2395 | } |
| 2396 | |
aliguori | 030ea37 | 2009-04-21 22:30:47 +0000 | [diff] [blame] | 2397 | static void do_info_numa(Monitor *mon) |
| 2398 | { |
aliguori | b28b623 | 2009-04-22 20:20:29 +0000 | [diff] [blame] | 2399 | int i; |
aliguori | 030ea37 | 2009-04-21 22:30:47 +0000 | [diff] [blame] | 2400 | CPUState *env; |
| 2401 | |
| 2402 | monitor_printf(mon, "%d nodes\n", nb_numa_nodes); |
| 2403 | for (i = 0; i < nb_numa_nodes; i++) { |
| 2404 | monitor_printf(mon, "node %d cpus:", i); |
| 2405 | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
| 2406 | if (env->numa_node == i) { |
| 2407 | monitor_printf(mon, " %d", env->cpu_index); |
| 2408 | } |
| 2409 | } |
| 2410 | monitor_printf(mon, "\n"); |
| 2411 | monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i, |
| 2412 | node_mem[i] >> 20); |
| 2413 | } |
| 2414 | } |
| 2415 | |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 2416 | #ifdef CONFIG_PROFILER |
| 2417 | |
Aurelien Jarno | e9a6625 | 2009-09-30 14:09:52 +0200 | [diff] [blame] | 2418 | int64_t qemu_time; |
| 2419 | int64_t dev_time; |
| 2420 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2421 | static void do_info_profile(Monitor *mon) |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 2422 | { |
| 2423 | int64_t total; |
| 2424 | total = qemu_time; |
| 2425 | if (total == 0) |
| 2426 | total = 1; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2427 | monitor_printf(mon, "async time %" PRId64 " (%0.3f)\n", |
Juan Quintela | 6ee093c | 2009-09-10 03:04:26 +0200 | [diff] [blame] | 2428 | dev_time, dev_time / (double)get_ticks_per_sec()); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2429 | monitor_printf(mon, "qemu time %" PRId64 " (%0.3f)\n", |
Juan Quintela | 6ee093c | 2009-09-10 03:04:26 +0200 | [diff] [blame] | 2430 | qemu_time, qemu_time / (double)get_ticks_per_sec()); |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 2431 | qemu_time = 0; |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 2432 | dev_time = 0; |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 2433 | } |
| 2434 | #else |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2435 | static void do_info_profile(Monitor *mon) |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 2436 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2437 | monitor_printf(mon, "Internal profiler not compiled\n"); |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 2438 | } |
| 2439 | #endif |
| 2440 | |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2441 | /* Capture support */ |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2442 | static QLIST_HEAD (capture_list_head, CaptureState) capture_head; |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2443 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2444 | static void do_info_capture(Monitor *mon) |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2445 | { |
| 2446 | int i; |
| 2447 | CaptureState *s; |
| 2448 | |
| 2449 | 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] | 2450 | monitor_printf(mon, "[%d]: ", i); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2451 | s->ops.info (s->opaque); |
| 2452 | } |
| 2453 | } |
| 2454 | |
Blue Swirl | 2313086 | 2009-06-06 08:22:04 +0000 | [diff] [blame] | 2455 | #ifdef HAS_AUDIO |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2456 | static void do_stop_capture(Monitor *mon, const QDict *qdict) |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2457 | { |
| 2458 | int i; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2459 | int n = qdict_get_int(qdict, "n"); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2460 | CaptureState *s; |
| 2461 | |
| 2462 | for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) { |
| 2463 | if (i == n) { |
| 2464 | s->ops.destroy (s->opaque); |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2465 | QLIST_REMOVE (s, entries); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 2466 | g_free (s); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2467 | return; |
| 2468 | } |
| 2469 | } |
| 2470 | } |
| 2471 | |
Luiz Capitulino | c192548 | 2009-08-28 15:27:19 -0300 | [diff] [blame] | 2472 | static void do_wav_capture(Monitor *mon, const QDict *qdict) |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2473 | { |
Luiz Capitulino | c192548 | 2009-08-28 15:27:19 -0300 | [diff] [blame] | 2474 | const char *path = qdict_get_str(qdict, "path"); |
| 2475 | int has_freq = qdict_haskey(qdict, "freq"); |
| 2476 | int freq = qdict_get_try_int(qdict, "freq", -1); |
| 2477 | int has_bits = qdict_haskey(qdict, "bits"); |
| 2478 | int bits = qdict_get_try_int(qdict, "bits", -1); |
| 2479 | int has_channels = qdict_haskey(qdict, "nchannels"); |
| 2480 | int nchannels = qdict_get_try_int(qdict, "nchannels", -1); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2481 | CaptureState *s; |
| 2482 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 2483 | s = g_malloc0 (sizeof (*s)); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2484 | |
| 2485 | freq = has_freq ? freq : 44100; |
| 2486 | bits = has_bits ? bits : 16; |
| 2487 | nchannels = has_channels ? nchannels : 2; |
| 2488 | |
| 2489 | if (wav_start_capture (s, path, freq, bits, nchannels)) { |
Isaku Yamahata | d00b261 | 2011-01-21 19:53:55 +0900 | [diff] [blame] | 2490 | monitor_printf(mon, "Failed to add wave capture\n"); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 2491 | g_free (s); |
Isaku Yamahata | d00b261 | 2011-01-21 19:53:55 +0900 | [diff] [blame] | 2492 | return; |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2493 | } |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2494 | QLIST_INSERT_HEAD (&capture_head, s, entries); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2495 | } |
| 2496 | #endif |
| 2497 | |
aurel32 | dc1c0b7 | 2008-04-27 23:52:12 +0000 | [diff] [blame] | 2498 | #if defined(TARGET_I386) |
Luiz Capitulino | e9b4b43 | 2011-04-29 12:11:50 -0300 | [diff] [blame] | 2499 | static int do_inject_nmi(Monitor *mon, const QDict *qdict, QObject **ret_data) |
Lai Jiangshan | a404666 | 2011-03-07 17:05:15 +0800 | [diff] [blame] | 2500 | { |
| 2501 | CPUState *env; |
| 2502 | |
| 2503 | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
| 2504 | cpu_interrupt(env, CPU_INTERRUPT_NMI); |
| 2505 | } |
| 2506 | |
| 2507 | return 0; |
| 2508 | } |
| 2509 | #else |
Luiz Capitulino | e9b4b43 | 2011-04-29 12:11:50 -0300 | [diff] [blame] | 2510 | static int do_inject_nmi(Monitor *mon, const QDict *qdict, QObject **ret_data) |
Lai Jiangshan | a404666 | 2011-03-07 17:05:15 +0800 | [diff] [blame] | 2511 | { |
| 2512 | qerror_report(QERR_UNSUPPORTED); |
| 2513 | return -1; |
| 2514 | } |
aurel32 | dc1c0b7 | 2008-04-27 23:52:12 +0000 | [diff] [blame] | 2515 | #endif |
| 2516 | |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2517 | static qemu_acl *find_acl(Monitor *mon, const char *name) |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2518 | { |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2519 | qemu_acl *acl = qemu_acl_find(name); |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2520 | |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2521 | if (!acl) { |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2522 | monitor_printf(mon, "acl: unknown list '%s'\n", name); |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2523 | } |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2524 | return acl; |
| 2525 | } |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2526 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2527 | static void do_acl_show(Monitor *mon, const QDict *qdict) |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2528 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2529 | const char *aclname = qdict_get_str(qdict, "aclname"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2530 | qemu_acl *acl = find_acl(mon, aclname); |
| 2531 | qemu_acl_entry *entry; |
| 2532 | int i = 0; |
| 2533 | |
| 2534 | if (acl) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2535 | monitor_printf(mon, "policy: %s\n", |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2536 | acl->defaultDeny ? "deny" : "allow"); |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2537 | QTAILQ_FOREACH(entry, &acl->entries, next) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2538 | i++; |
| 2539 | monitor_printf(mon, "%d: %s %s\n", i, |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2540 | entry->deny ? "deny" : "allow", entry->match); |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2541 | } |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2542 | } |
| 2543 | } |
| 2544 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2545 | static void do_acl_reset(Monitor *mon, const QDict *qdict) |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2546 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2547 | const char *aclname = qdict_get_str(qdict, "aclname"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2548 | qemu_acl *acl = find_acl(mon, aclname); |
| 2549 | |
| 2550 | if (acl) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2551 | qemu_acl_reset(acl); |
| 2552 | monitor_printf(mon, "acl: removed all rules\n"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2553 | } |
| 2554 | } |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2555 | |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 2556 | static void do_acl_policy(Monitor *mon, const QDict *qdict) |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2557 | { |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 2558 | const char *aclname = qdict_get_str(qdict, "aclname"); |
| 2559 | const char *policy = qdict_get_str(qdict, "policy"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2560 | qemu_acl *acl = find_acl(mon, aclname); |
| 2561 | |
| 2562 | if (acl) { |
| 2563 | if (strcmp(policy, "allow") == 0) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2564 | acl->defaultDeny = 0; |
| 2565 | monitor_printf(mon, "acl: policy set to 'allow'\n"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2566 | } else if (strcmp(policy, "deny") == 0) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2567 | acl->defaultDeny = 1; |
| 2568 | monitor_printf(mon, "acl: policy set to 'deny'\n"); |
| 2569 | } else { |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2570 | monitor_printf(mon, "acl: unknown policy '%s', " |
| 2571 | "expected 'deny' or 'allow'\n", policy); |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2572 | } |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2573 | } |
| 2574 | } |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2575 | |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 2576 | static void do_acl_add(Monitor *mon, const QDict *qdict) |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2577 | { |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 2578 | const char *aclname = qdict_get_str(qdict, "aclname"); |
| 2579 | const char *match = qdict_get_str(qdict, "match"); |
| 2580 | const char *policy = qdict_get_str(qdict, "policy"); |
| 2581 | int has_index = qdict_haskey(qdict, "index"); |
| 2582 | int index = qdict_get_try_int(qdict, "index", -1); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2583 | qemu_acl *acl = find_acl(mon, aclname); |
| 2584 | int deny, ret; |
| 2585 | |
| 2586 | if (acl) { |
| 2587 | if (strcmp(policy, "allow") == 0) { |
| 2588 | deny = 0; |
| 2589 | } else if (strcmp(policy, "deny") == 0) { |
| 2590 | deny = 1; |
| 2591 | } else { |
| 2592 | monitor_printf(mon, "acl: unknown policy '%s', " |
| 2593 | "expected 'deny' or 'allow'\n", policy); |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2594 | return; |
| 2595 | } |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2596 | if (has_index) |
| 2597 | ret = qemu_acl_insert(acl, deny, match, index); |
| 2598 | else |
| 2599 | ret = qemu_acl_append(acl, deny, match); |
| 2600 | if (ret < 0) |
| 2601 | monitor_printf(mon, "acl: unable to add acl entry\n"); |
| 2602 | else |
| 2603 | monitor_printf(mon, "acl: added rule at position %d\n", ret); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2604 | } |
| 2605 | } |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2606 | |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 2607 | static void do_acl_remove(Monitor *mon, const QDict *qdict) |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2608 | { |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 2609 | const char *aclname = qdict_get_str(qdict, "aclname"); |
| 2610 | const char *match = qdict_get_str(qdict, "match"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2611 | qemu_acl *acl = find_acl(mon, aclname); |
| 2612 | int ret; |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2613 | |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2614 | if (acl) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2615 | ret = qemu_acl_remove(acl, match); |
| 2616 | if (ret < 0) |
| 2617 | monitor_printf(mon, "acl: no matching acl entry\n"); |
| 2618 | else |
| 2619 | monitor_printf(mon, "acl: removed rule at position %d\n", ret); |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2620 | } |
| 2621 | } |
| 2622 | |
Huang Ying | 79c4f6b | 2009-06-23 10:05:14 +0800 | [diff] [blame] | 2623 | #if defined(TARGET_I386) |
Luiz Capitulino | 37b7ad4 | 2009-08-28 15:27:21 -0300 | [diff] [blame] | 2624 | static void do_inject_mce(Monitor *mon, const QDict *qdict) |
Huang Ying | 79c4f6b | 2009-06-23 10:05:14 +0800 | [diff] [blame] | 2625 | { |
| 2626 | CPUState *cenv; |
Luiz Capitulino | 37b7ad4 | 2009-08-28 15:27:21 -0300 | [diff] [blame] | 2627 | int cpu_index = qdict_get_int(qdict, "cpu_index"); |
| 2628 | int bank = qdict_get_int(qdict, "bank"); |
| 2629 | uint64_t status = qdict_get_int(qdict, "status"); |
| 2630 | uint64_t mcg_status = qdict_get_int(qdict, "mcg_status"); |
| 2631 | uint64_t addr = qdict_get_int(qdict, "addr"); |
| 2632 | uint64_t misc = qdict_get_int(qdict, "misc"); |
Jan Kiszka | 747461c | 2011-03-02 08:56:10 +0100 | [diff] [blame] | 2633 | int flags = MCE_INJECT_UNCOND_AO; |
Huang Ying | 79c4f6b | 2009-06-23 10:05:14 +0800 | [diff] [blame] | 2634 | |
Jan Kiszka | 747461c | 2011-03-02 08:56:10 +0100 | [diff] [blame] | 2635 | if (qdict_get_try_bool(qdict, "broadcast", 0)) { |
| 2636 | flags |= MCE_INJECT_BROADCAST; |
| 2637 | } |
Jin Dongming | 31ce5e0 | 2010-12-10 17:21:02 +0900 | [diff] [blame] | 2638 | for (cenv = first_cpu; cenv != NULL; cenv = cenv->next_cpu) { |
Jan Kiszka | 316378e | 2011-03-02 08:56:09 +0100 | [diff] [blame] | 2639 | if (cenv->cpu_index == cpu_index) { |
| 2640 | cpu_x86_inject_mce(mon, cenv, bank, status, mcg_status, addr, misc, |
Jan Kiszka | 747461c | 2011-03-02 08:56:10 +0100 | [diff] [blame] | 2641 | flags); |
Huang Ying | 79c4f6b | 2009-06-23 10:05:14 +0800 | [diff] [blame] | 2642 | break; |
| 2643 | } |
Jin Dongming | 31ce5e0 | 2010-12-10 17:21:02 +0900 | [diff] [blame] | 2644 | } |
Huang Ying | 79c4f6b | 2009-06-23 10:05:14 +0800 | [diff] [blame] | 2645 | } |
| 2646 | #endif |
| 2647 | |
Luiz Capitulino | 6ad3ebd | 2010-02-10 23:49:53 -0200 | [diff] [blame] | 2648 | static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data) |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2649 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2650 | const char *fdname = qdict_get_str(qdict, "fdname"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2651 | mon_fd_t *monfd; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2652 | int fd; |
| 2653 | |
Anthony Liguori | 74c0d6f | 2011-08-15 11:17:39 -0500 | [diff] [blame] | 2654 | fd = qemu_chr_fe_get_msgfd(mon->chr); |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2655 | if (fd == -1) { |
Markus Armbruster | ab5b027 | 2010-03-02 18:15:09 +0100 | [diff] [blame] | 2656 | qerror_report(QERR_FD_NOT_SUPPLIED); |
Luiz Capitulino | 6ad3ebd | 2010-02-10 23:49:53 -0200 | [diff] [blame] | 2657 | return -1; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | if (qemu_isdigit(fdname[0])) { |
Markus Armbruster | e17ba87 | 2010-03-25 17:22:36 +0100 | [diff] [blame] | 2661 | qerror_report(QERR_INVALID_PARAMETER_VALUE, "fdname", |
| 2662 | "a name not starting with a digit"); |
Luiz Capitulino | 6ad3ebd | 2010-02-10 23:49:53 -0200 | [diff] [blame] | 2663 | return -1; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2664 | } |
| 2665 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2666 | QLIST_FOREACH(monfd, &mon->fds, next) { |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2667 | if (strcmp(monfd->name, fdname) != 0) { |
| 2668 | continue; |
| 2669 | } |
| 2670 | |
| 2671 | close(monfd->fd); |
| 2672 | monfd->fd = fd; |
Luiz Capitulino | 6ad3ebd | 2010-02-10 23:49:53 -0200 | [diff] [blame] | 2673 | return 0; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2674 | } |
| 2675 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 2676 | monfd = g_malloc0(sizeof(mon_fd_t)); |
| 2677 | monfd->name = g_strdup(fdname); |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2678 | monfd->fd = fd; |
| 2679 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2680 | QLIST_INSERT_HEAD(&mon->fds, monfd, next); |
Luiz Capitulino | 6ad3ebd | 2010-02-10 23:49:53 -0200 | [diff] [blame] | 2681 | return 0; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2682 | } |
| 2683 | |
Luiz Capitulino | aeb91c1 | 2010-02-10 23:49:54 -0200 | [diff] [blame] | 2684 | static int do_closefd(Monitor *mon, const QDict *qdict, QObject **ret_data) |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2685 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2686 | const char *fdname = qdict_get_str(qdict, "fdname"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2687 | mon_fd_t *monfd; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2688 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2689 | QLIST_FOREACH(monfd, &mon->fds, next) { |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2690 | if (strcmp(monfd->name, fdname) != 0) { |
| 2691 | continue; |
| 2692 | } |
| 2693 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2694 | QLIST_REMOVE(monfd, next); |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2695 | close(monfd->fd); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 2696 | g_free(monfd->name); |
| 2697 | g_free(monfd); |
Luiz Capitulino | aeb91c1 | 2010-02-10 23:49:54 -0200 | [diff] [blame] | 2698 | return 0; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2699 | } |
| 2700 | |
Markus Armbruster | ab5b027 | 2010-03-02 18:15:09 +0100 | [diff] [blame] | 2701 | qerror_report(QERR_FD_NOT_FOUND, fdname); |
Luiz Capitulino | aeb91c1 | 2010-02-10 23:49:54 -0200 | [diff] [blame] | 2702 | return -1; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2703 | } |
| 2704 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2705 | static void do_loadvm(Monitor *mon, const QDict *qdict) |
Juan Quintela | c8d41b2 | 2009-08-20 19:42:21 +0200 | [diff] [blame] | 2706 | { |
Luiz Capitulino | 1354869 | 2011-07-29 15:36:43 -0300 | [diff] [blame] | 2707 | int saved_vm_running = runstate_is_running(); |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2708 | const char *name = qdict_get_str(qdict, "name"); |
Juan Quintela | c8d41b2 | 2009-08-20 19:42:21 +0200 | [diff] [blame] | 2709 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 2710 | vm_stop(RUN_STATE_RESTORE_VM); |
Juan Quintela | c8d41b2 | 2009-08-20 19:42:21 +0200 | [diff] [blame] | 2711 | |
Miguel Di Ciurcio Filho | f0aa7a8 | 2010-07-19 15:25:01 -0300 | [diff] [blame] | 2712 | if (load_vmstate(name) == 0 && saved_vm_running) { |
Juan Quintela | c8d41b2 | 2009-08-20 19:42:21 +0200 | [diff] [blame] | 2713 | vm_start(); |
Miguel Di Ciurcio Filho | f0aa7a8 | 2010-07-19 15:25:01 -0300 | [diff] [blame] | 2714 | } |
Juan Quintela | c8d41b2 | 2009-08-20 19:42:21 +0200 | [diff] [blame] | 2715 | } |
| 2716 | |
Mark McLoughlin | 7768e04 | 2009-07-22 09:11:41 +0100 | [diff] [blame] | 2717 | int monitor_get_fd(Monitor *mon, const char *fdname) |
| 2718 | { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2719 | mon_fd_t *monfd; |
Mark McLoughlin | 7768e04 | 2009-07-22 09:11:41 +0100 | [diff] [blame] | 2720 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2721 | QLIST_FOREACH(monfd, &mon->fds, next) { |
Mark McLoughlin | 7768e04 | 2009-07-22 09:11:41 +0100 | [diff] [blame] | 2722 | int fd; |
| 2723 | |
| 2724 | if (strcmp(monfd->name, fdname) != 0) { |
| 2725 | continue; |
| 2726 | } |
| 2727 | |
| 2728 | fd = monfd->fd; |
| 2729 | |
| 2730 | /* caller takes ownership of fd */ |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2731 | QLIST_REMOVE(monfd, next); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 2732 | g_free(monfd->name); |
| 2733 | g_free(monfd); |
Mark McLoughlin | 7768e04 | 2009-07-22 09:11:41 +0100 | [diff] [blame] | 2734 | |
| 2735 | return fd; |
| 2736 | } |
| 2737 | |
| 2738 | return -1; |
| 2739 | } |
| 2740 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2741 | static const mon_cmd_t mon_cmds[] = { |
Luiz Capitulino | acd0a09 | 2010-09-30 16:00:22 -0300 | [diff] [blame] | 2742 | #include "hmp-commands.h" |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 2743 | { NULL, NULL, }, |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 2744 | }; |
| 2745 | |
Luiz Capitulino | acd0a09 | 2010-09-30 16:00:22 -0300 | [diff] [blame] | 2746 | /* Please update hmp-commands.hx when adding or changing commands */ |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2747 | static const mon_cmd_t info_cmds[] = { |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2748 | { |
| 2749 | .name = "version", |
| 2750 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2751 | .params = "", |
| 2752 | .help = "show the version of QEMU", |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 2753 | .mhandler.info = hmp_info_version, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2754 | }, |
| 2755 | { |
| 2756 | .name = "network", |
| 2757 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2758 | .params = "", |
| 2759 | .help = "show the network state", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2760 | .mhandler.info = do_info_network, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2761 | }, |
| 2762 | { |
| 2763 | .name = "chardev", |
| 2764 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2765 | .params = "", |
| 2766 | .help = "show the character devices", |
Luiz Capitulino | c5a415a | 2011-09-14 16:05:49 -0300 | [diff] [blame] | 2767 | .mhandler.info = hmp_info_chardev, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2768 | }, |
| 2769 | { |
| 2770 | .name = "block", |
| 2771 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2772 | .params = "", |
| 2773 | .help = "show the block devices", |
Luiz Capitulino | d15e546 | 2009-12-10 17:16:06 -0200 | [diff] [blame] | 2774 | .user_print = bdrv_info_print, |
| 2775 | .mhandler.info_new = bdrv_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2776 | }, |
| 2777 | { |
| 2778 | .name = "blockstats", |
| 2779 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2780 | .params = "", |
| 2781 | .help = "show block device statistics", |
Luiz Capitulino | 218a536 | 2009-12-10 17:16:07 -0200 | [diff] [blame] | 2782 | .user_print = bdrv_stats_print, |
| 2783 | .mhandler.info_new = bdrv_info_stats, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2784 | }, |
| 2785 | { |
| 2786 | .name = "registers", |
| 2787 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2788 | .params = "", |
| 2789 | .help = "show the cpu registers", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2790 | .mhandler.info = do_info_registers, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2791 | }, |
| 2792 | { |
| 2793 | .name = "cpus", |
| 2794 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2795 | .params = "", |
| 2796 | .help = "show infos for each CPU", |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 2797 | .user_print = monitor_print_cpus, |
| 2798 | .mhandler.info_new = do_info_cpus, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2799 | }, |
| 2800 | { |
| 2801 | .name = "history", |
| 2802 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2803 | .params = "", |
| 2804 | .help = "show the command line history", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2805 | .mhandler.info = do_info_history, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2806 | }, |
Jan Kiszka | 661f192 | 2011-10-16 11:53:13 +0200 | [diff] [blame] | 2807 | #if defined(TARGET_I386) || defined(TARGET_PPC) || defined(TARGET_MIPS) || \ |
| 2808 | defined(TARGET_LM32) || (defined(TARGET_SPARC) && !defined(TARGET_SPARC64)) |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2809 | { |
| 2810 | .name = "irq", |
| 2811 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2812 | .params = "", |
| 2813 | .help = "show the interrupts statistics (if available)", |
Jan Kiszka | 661f192 | 2011-10-16 11:53:13 +0200 | [diff] [blame] | 2814 | #ifdef TARGET_SPARC |
| 2815 | .mhandler.info = sun4m_irq_info, |
| 2816 | #elif defined(TARGET_LM32) |
| 2817 | .mhandler.info = lm32_irq_info, |
| 2818 | #else |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2819 | .mhandler.info = irq_info, |
Jan Kiszka | 661f192 | 2011-10-16 11:53:13 +0200 | [diff] [blame] | 2820 | #endif |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2821 | }, |
| 2822 | { |
| 2823 | .name = "pic", |
| 2824 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2825 | .params = "", |
| 2826 | .help = "show i8259 (PIC) state", |
Jan Kiszka | 661f192 | 2011-10-16 11:53:13 +0200 | [diff] [blame] | 2827 | #ifdef TARGET_SPARC |
| 2828 | .mhandler.info = sun4m_pic_info, |
| 2829 | #elif defined(TARGET_LM32) |
| 2830 | .mhandler.info = lm32_do_pic_info, |
| 2831 | #else |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2832 | .mhandler.info = pic_info, |
Jan Kiszka | 661f192 | 2011-10-16 11:53:13 +0200 | [diff] [blame] | 2833 | #endif |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2834 | }, |
Jan Kiszka | 661f192 | 2011-10-16 11:53:13 +0200 | [diff] [blame] | 2835 | #endif |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2836 | { |
| 2837 | .name = "pci", |
| 2838 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2839 | .params = "", |
| 2840 | .help = "show PCI info", |
Luiz Capitulino | 163c8a5 | 2010-01-21 19:15:40 -0200 | [diff] [blame] | 2841 | .user_print = do_pci_info_print, |
| 2842 | .mhandler.info_new = do_pci_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2843 | }, |
Scott Wood | bebabbc | 2011-08-18 10:38:42 +0000 | [diff] [blame] | 2844 | #if defined(TARGET_I386) || defined(TARGET_SH4) || defined(TARGET_SPARC) || \ |
| 2845 | defined(TARGET_PPC) |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2846 | { |
| 2847 | .name = "tlb", |
| 2848 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2849 | .params = "", |
| 2850 | .help = "show virtual to physical memory mappings", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2851 | .mhandler.info = tlb_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2852 | }, |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2853 | #endif |
| 2854 | #if defined(TARGET_I386) |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2855 | { |
| 2856 | .name = "mem", |
| 2857 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2858 | .params = "", |
| 2859 | .help = "show the active virtual memory mappings", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2860 | .mhandler.info = mem_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2861 | }, |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2862 | #endif |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2863 | { |
Blue Swirl | 314e298 | 2011-09-11 20:22:05 +0000 | [diff] [blame] | 2864 | .name = "mtree", |
| 2865 | .args_type = "", |
| 2866 | .params = "", |
| 2867 | .help = "show memory tree", |
| 2868 | .mhandler.info = do_info_mtree, |
| 2869 | }, |
| 2870 | { |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2871 | .name = "jit", |
| 2872 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2873 | .params = "", |
| 2874 | .help = "show dynamic compiler info", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2875 | .mhandler.info = do_info_jit, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2876 | }, |
| 2877 | { |
| 2878 | .name = "kvm", |
| 2879 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2880 | .params = "", |
| 2881 | .help = "show KVM information", |
Luiz Capitulino | 292a260 | 2011-09-12 15:10:53 -0300 | [diff] [blame] | 2882 | .mhandler.info = hmp_info_kvm, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2883 | }, |
| 2884 | { |
| 2885 | .name = "numa", |
| 2886 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2887 | .params = "", |
| 2888 | .help = "show NUMA information", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2889 | .mhandler.info = do_info_numa, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2890 | }, |
| 2891 | { |
| 2892 | .name = "usb", |
| 2893 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2894 | .params = "", |
| 2895 | .help = "show guest USB devices", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2896 | .mhandler.info = usb_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2897 | }, |
| 2898 | { |
| 2899 | .name = "usbhost", |
| 2900 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2901 | .params = "", |
| 2902 | .help = "show host USB devices", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2903 | .mhandler.info = usb_host_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2904 | }, |
| 2905 | { |
| 2906 | .name = "profile", |
| 2907 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2908 | .params = "", |
| 2909 | .help = "show profiling information", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2910 | .mhandler.info = do_info_profile, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2911 | }, |
| 2912 | { |
| 2913 | .name = "capture", |
| 2914 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2915 | .params = "", |
| 2916 | .help = "show capture information", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2917 | .mhandler.info = do_info_capture, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2918 | }, |
| 2919 | { |
| 2920 | .name = "snapshots", |
| 2921 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2922 | .params = "", |
| 2923 | .help = "show the currently saved VM snapshots", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2924 | .mhandler.info = do_info_snapshots, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2925 | }, |
| 2926 | { |
| 2927 | .name = "status", |
| 2928 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2929 | .params = "", |
| 2930 | .help = "show the current VM status (running|paused)", |
Luiz Capitulino | 1fa9a5e | 2011-09-12 17:54:20 -0300 | [diff] [blame] | 2931 | .mhandler.info = hmp_info_status, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2932 | }, |
| 2933 | { |
| 2934 | .name = "pcmcia", |
| 2935 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2936 | .params = "", |
| 2937 | .help = "show guest PCMCIA status", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2938 | .mhandler.info = pcmcia_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2939 | }, |
| 2940 | { |
| 2941 | .name = "mice", |
| 2942 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2943 | .params = "", |
| 2944 | .help = "show which guest mouse is receiving events", |
Luiz Capitulino | e78c48e | 2009-12-10 17:16:04 -0200 | [diff] [blame] | 2945 | .user_print = do_info_mice_print, |
| 2946 | .mhandler.info_new = do_info_mice, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2947 | }, |
| 2948 | { |
| 2949 | .name = "vnc", |
| 2950 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2951 | .params = "", |
| 2952 | .help = "show the vnc server status", |
Luiz Capitulino | d96fd29 | 2009-12-10 17:16:10 -0200 | [diff] [blame] | 2953 | .user_print = do_info_vnc_print, |
| 2954 | .mhandler.info_new = do_info_vnc, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2955 | }, |
Gerd Hoffmann | cb42a87 | 2010-11-30 11:02:51 +0100 | [diff] [blame] | 2956 | #if defined(CONFIG_SPICE) |
| 2957 | { |
| 2958 | .name = "spice", |
| 2959 | .args_type = "", |
| 2960 | .params = "", |
| 2961 | .help = "show the spice server status", |
| 2962 | .user_print = do_info_spice_print, |
| 2963 | .mhandler.info_new = do_info_spice, |
| 2964 | }, |
| 2965 | #endif |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2966 | { |
| 2967 | .name = "name", |
| 2968 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2969 | .params = "", |
| 2970 | .help = "show the current VM name", |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 2971 | .mhandler.info = hmp_info_name, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2972 | }, |
| 2973 | { |
| 2974 | .name = "uuid", |
| 2975 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2976 | .params = "", |
| 2977 | .help = "show the current VM UUID", |
Luiz Capitulino | efab767 | 2011-09-13 17:16:25 -0300 | [diff] [blame] | 2978 | .mhandler.info = hmp_info_uuid, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2979 | }, |
j_mayer | 76a6625 | 2007-03-07 08:32:30 +0000 | [diff] [blame] | 2980 | #if defined(TARGET_PPC) |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2981 | { |
| 2982 | .name = "cpustats", |
| 2983 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2984 | .params = "", |
| 2985 | .help = "show CPU statistics", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2986 | .mhandler.info = do_info_cpu_stats, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2987 | }, |
j_mayer | 76a6625 | 2007-03-07 08:32:30 +0000 | [diff] [blame] | 2988 | #endif |
blueswir1 | 31a60e2 | 2007-10-26 18:42:59 +0000 | [diff] [blame] | 2989 | #if defined(CONFIG_SLIRP) |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2990 | { |
| 2991 | .name = "usernet", |
| 2992 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2993 | .params = "", |
| 2994 | .help = "show user network stack connection states", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2995 | .mhandler.info = do_info_usernet, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2996 | }, |
blueswir1 | 31a60e2 | 2007-10-26 18:42:59 +0000 | [diff] [blame] | 2997 | #endif |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2998 | { |
| 2999 | .name = "migrate", |
| 3000 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 3001 | .params = "", |
| 3002 | .help = "show migration status", |
Luiz Capitulino | c86a668 | 2009-12-10 17:16:05 -0200 | [diff] [blame] | 3003 | .user_print = do_info_migrate_print, |
| 3004 | .mhandler.info_new = do_info_migrate, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 3005 | }, |
| 3006 | { |
| 3007 | .name = "balloon", |
| 3008 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 3009 | .params = "", |
| 3010 | .help = "show balloon information", |
Luiz Capitulino | cc1d9c7 | 2009-10-07 13:42:03 -0300 | [diff] [blame] | 3011 | .user_print = monitor_print_balloon, |
Adam Litke | 625a5be | 2010-01-26 14:17:35 -0600 | [diff] [blame] | 3012 | .mhandler.info_async = do_info_balloon, |
Jan Kiszka | 8ac470c | 2010-06-16 00:38:39 +0200 | [diff] [blame] | 3013 | .flags = MONITOR_CMD_ASYNC, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 3014 | }, |
| 3015 | { |
| 3016 | .name = "qtree", |
| 3017 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 3018 | .params = "", |
| 3019 | .help = "show device tree", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 3020 | .mhandler.info = do_info_qtree, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 3021 | }, |
| 3022 | { |
| 3023 | .name = "qdm", |
| 3024 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 3025 | .params = "", |
| 3026 | .help = "show qdev device model list", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 3027 | .mhandler.info = do_info_qdm, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 3028 | }, |
| 3029 | { |
| 3030 | .name = "roms", |
| 3031 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 3032 | .params = "", |
| 3033 | .help = "show roms", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 3034 | .mhandler.info = do_info_roms, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 3035 | }, |
Lluís | 6d8a764 | 2011-08-31 20:30:43 +0200 | [diff] [blame] | 3036 | #if defined(CONFIG_TRACE_SIMPLE) |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 3037 | { |
| 3038 | .name = "trace", |
| 3039 | .args_type = "", |
| 3040 | .params = "", |
| 3041 | .help = "show current contents of trace buffer", |
| 3042 | .mhandler.info = do_info_trace, |
| 3043 | }, |
Lluís | 31965ae | 2011-08-31 20:31:24 +0200 | [diff] [blame] | 3044 | #endif |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 3045 | { |
| 3046 | .name = "trace-events", |
| 3047 | .args_type = "", |
| 3048 | .params = "", |
| 3049 | .help = "show available trace-events & their state", |
Lluís | fc76410 | 2011-08-31 20:31:18 +0200 | [diff] [blame] | 3050 | .mhandler.info = do_trace_print_events, |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 3051 | }, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 3052 | { |
| 3053 | .name = NULL, |
| 3054 | }, |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 3055 | }; |
| 3056 | |
Luiz Capitulino | f36b4af | 2010-09-15 17:17:45 -0300 | [diff] [blame] | 3057 | static const mon_cmd_t qmp_cmds[] = { |
Anthony Liguori | e319360 | 2011-09-02 12:34:47 -0500 | [diff] [blame] | 3058 | #include "qmp-commands-old.h" |
Luiz Capitulino | f36b4af | 2010-09-15 17:17:45 -0300 | [diff] [blame] | 3059 | { /* NULL */ }, |
| 3060 | }; |
| 3061 | |
Luiz Capitulino | 3e12a75 | 2010-09-15 17:20:33 -0300 | [diff] [blame] | 3062 | static const mon_cmd_t qmp_query_cmds[] = { |
| 3063 | { |
Luiz Capitulino | 3e12a75 | 2010-09-15 17:20:33 -0300 | [diff] [blame] | 3064 | .name = "block", |
| 3065 | .args_type = "", |
| 3066 | .params = "", |
| 3067 | .help = "show the block devices", |
| 3068 | .user_print = bdrv_info_print, |
| 3069 | .mhandler.info_new = bdrv_info, |
| 3070 | }, |
| 3071 | { |
| 3072 | .name = "blockstats", |
| 3073 | .args_type = "", |
| 3074 | .params = "", |
| 3075 | .help = "show block device statistics", |
| 3076 | .user_print = bdrv_stats_print, |
| 3077 | .mhandler.info_new = bdrv_info_stats, |
| 3078 | }, |
| 3079 | { |
| 3080 | .name = "cpus", |
| 3081 | .args_type = "", |
| 3082 | .params = "", |
| 3083 | .help = "show infos for each CPU", |
| 3084 | .user_print = monitor_print_cpus, |
| 3085 | .mhandler.info_new = do_info_cpus, |
| 3086 | }, |
| 3087 | { |
| 3088 | .name = "pci", |
| 3089 | .args_type = "", |
| 3090 | .params = "", |
| 3091 | .help = "show PCI info", |
| 3092 | .user_print = do_pci_info_print, |
| 3093 | .mhandler.info_new = do_pci_info, |
| 3094 | }, |
| 3095 | { |
Luiz Capitulino | 3e12a75 | 2010-09-15 17:20:33 -0300 | [diff] [blame] | 3096 | .name = "mice", |
| 3097 | .args_type = "", |
| 3098 | .params = "", |
| 3099 | .help = "show which guest mouse is receiving events", |
| 3100 | .user_print = do_info_mice_print, |
| 3101 | .mhandler.info_new = do_info_mice, |
| 3102 | }, |
| 3103 | { |
| 3104 | .name = "vnc", |
| 3105 | .args_type = "", |
| 3106 | .params = "", |
| 3107 | .help = "show the vnc server status", |
| 3108 | .user_print = do_info_vnc_print, |
| 3109 | .mhandler.info_new = do_info_vnc, |
| 3110 | }, |
Gerd Hoffmann | cb42a87 | 2010-11-30 11:02:51 +0100 | [diff] [blame] | 3111 | #if defined(CONFIG_SPICE) |
| 3112 | { |
| 3113 | .name = "spice", |
| 3114 | .args_type = "", |
| 3115 | .params = "", |
| 3116 | .help = "show the spice server status", |
| 3117 | .user_print = do_info_spice_print, |
| 3118 | .mhandler.info_new = do_info_spice, |
| 3119 | }, |
| 3120 | #endif |
Luiz Capitulino | 3e12a75 | 2010-09-15 17:20:33 -0300 | [diff] [blame] | 3121 | { |
Luiz Capitulino | 3e12a75 | 2010-09-15 17:20:33 -0300 | [diff] [blame] | 3122 | .name = "migrate", |
| 3123 | .args_type = "", |
| 3124 | .params = "", |
| 3125 | .help = "show migration status", |
| 3126 | .user_print = do_info_migrate_print, |
| 3127 | .mhandler.info_new = do_info_migrate, |
| 3128 | }, |
| 3129 | { |
| 3130 | .name = "balloon", |
| 3131 | .args_type = "", |
| 3132 | .params = "", |
| 3133 | .help = "show balloon information", |
| 3134 | .user_print = monitor_print_balloon, |
| 3135 | .mhandler.info_async = do_info_balloon, |
| 3136 | .flags = MONITOR_CMD_ASYNC, |
| 3137 | }, |
| 3138 | { /* NULL */ }, |
| 3139 | }; |
| 3140 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3141 | /*******************************************************************/ |
| 3142 | |
| 3143 | static const char *pch; |
| 3144 | static jmp_buf expr_env; |
| 3145 | |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3146 | #define MD_TLONG 0 |
| 3147 | #define MD_I32 1 |
| 3148 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3149 | typedef struct MonitorDef { |
| 3150 | const char *name; |
| 3151 | int offset; |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 3152 | target_long (*get_value)(const struct MonitorDef *md, int val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3153 | int type; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3154 | } MonitorDef; |
| 3155 | |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 3156 | #if defined(TARGET_I386) |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 3157 | static target_long monitor_get_pc (const struct MonitorDef *md, int val) |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 3158 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3159 | CPUState *env = mon_get_cpu(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3160 | return env->eip + env->segs[R_CS].base; |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 3161 | } |
| 3162 | #endif |
| 3163 | |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3164 | #if defined(TARGET_PPC) |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 3165 | static target_long monitor_get_ccr (const struct MonitorDef *md, int val) |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3166 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3167 | CPUState *env = mon_get_cpu(); |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3168 | unsigned int u; |
| 3169 | int i; |
| 3170 | |
| 3171 | u = 0; |
| 3172 | for (i = 0; i < 8; i++) |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 3173 | u |= env->crf[i] << (32 - (4 * i)); |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3174 | |
| 3175 | return u; |
| 3176 | } |
| 3177 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 3178 | static target_long monitor_get_msr (const struct MonitorDef *md, int val) |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3179 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3180 | CPUState *env = mon_get_cpu(); |
j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 3181 | return env->msr; |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3182 | } |
| 3183 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 3184 | static target_long monitor_get_xer (const struct MonitorDef *md, int val) |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3185 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3186 | CPUState *env = mon_get_cpu(); |
aurel32 | 3d7b417 | 2008-10-21 11:28:46 +0000 | [diff] [blame] | 3187 | return env->xer; |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3188 | } |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 3189 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 3190 | static target_long monitor_get_decr (const struct MonitorDef *md, int val) |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 3191 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3192 | CPUState *env = mon_get_cpu(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3193 | return cpu_ppc_load_decr(env); |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 3194 | } |
| 3195 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 3196 | static target_long monitor_get_tbu (const struct MonitorDef *md, int val) |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 3197 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3198 | CPUState *env = mon_get_cpu(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3199 | return cpu_ppc_load_tbu(env); |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 3200 | } |
| 3201 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 3202 | static target_long monitor_get_tbl (const struct MonitorDef *md, int val) |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 3203 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3204 | CPUState *env = mon_get_cpu(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3205 | return cpu_ppc_load_tbl(env); |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 3206 | } |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3207 | #endif |
| 3208 | |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 3209 | #if defined(TARGET_SPARC) |
bellard | 7b936c0 | 2005-10-30 17:05:13 +0000 | [diff] [blame] | 3210 | #ifndef TARGET_SPARC64 |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 3211 | static target_long monitor_get_psr (const struct MonitorDef *md, int val) |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 3212 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3213 | CPUState *env = mon_get_cpu(); |
Blue Swirl | 5a834bb | 2010-05-09 20:19:04 +0000 | [diff] [blame] | 3214 | |
| 3215 | return cpu_get_psr(env); |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 3216 | } |
bellard | 7b936c0 | 2005-10-30 17:05:13 +0000 | [diff] [blame] | 3217 | #endif |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 3218 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 3219 | static target_long monitor_get_reg(const struct MonitorDef *md, int val) |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 3220 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3221 | CPUState *env = mon_get_cpu(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3222 | return env->regwptr[val]; |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 3223 | } |
| 3224 | #endif |
| 3225 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 3226 | static const MonitorDef monitor_defs[] = { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3227 | #ifdef TARGET_I386 |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 3228 | |
| 3229 | #define SEG(name, seg) \ |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3230 | { name, offsetof(CPUState, segs[seg].selector), NULL, MD_I32 },\ |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 3231 | { name ".base", offsetof(CPUState, segs[seg].base) },\ |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3232 | { name ".limit", offsetof(CPUState, segs[seg].limit), NULL, MD_I32 }, |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 3233 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3234 | { "eax", offsetof(CPUState, regs[0]) }, |
| 3235 | { "ecx", offsetof(CPUState, regs[1]) }, |
| 3236 | { "edx", offsetof(CPUState, regs[2]) }, |
| 3237 | { "ebx", offsetof(CPUState, regs[3]) }, |
| 3238 | { "esp|sp", offsetof(CPUState, regs[4]) }, |
| 3239 | { "ebp|fp", offsetof(CPUState, regs[5]) }, |
| 3240 | { "esi", offsetof(CPUState, regs[6]) }, |
bellard | 01038d2 | 2004-09-13 21:36:46 +0000 | [diff] [blame] | 3241 | { "edi", offsetof(CPUState, regs[7]) }, |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3242 | #ifdef TARGET_X86_64 |
| 3243 | { "r8", offsetof(CPUState, regs[8]) }, |
| 3244 | { "r9", offsetof(CPUState, regs[9]) }, |
| 3245 | { "r10", offsetof(CPUState, regs[10]) }, |
| 3246 | { "r11", offsetof(CPUState, regs[11]) }, |
| 3247 | { "r12", offsetof(CPUState, regs[12]) }, |
| 3248 | { "r13", offsetof(CPUState, regs[13]) }, |
| 3249 | { "r14", offsetof(CPUState, regs[14]) }, |
| 3250 | { "r15", offsetof(CPUState, regs[15]) }, |
| 3251 | #endif |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3252 | { "eflags", offsetof(CPUState, eflags) }, |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 3253 | { "eip", offsetof(CPUState, eip) }, |
| 3254 | SEG("cs", R_CS) |
| 3255 | SEG("ds", R_DS) |
| 3256 | SEG("es", R_ES) |
bellard | 01038d2 | 2004-09-13 21:36:46 +0000 | [diff] [blame] | 3257 | SEG("ss", R_SS) |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 3258 | SEG("fs", R_FS) |
| 3259 | SEG("gs", R_GS) |
| 3260 | { "pc", 0, monitor_get_pc, }, |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3261 | #elif defined(TARGET_PPC) |
j_mayer | ff937db | 2007-09-19 05:49:13 +0000 | [diff] [blame] | 3262 | /* General purpose registers */ |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3263 | { "r0", offsetof(CPUState, gpr[0]) }, |
| 3264 | { "r1", offsetof(CPUState, gpr[1]) }, |
| 3265 | { "r2", offsetof(CPUState, gpr[2]) }, |
| 3266 | { "r3", offsetof(CPUState, gpr[3]) }, |
| 3267 | { "r4", offsetof(CPUState, gpr[4]) }, |
| 3268 | { "r5", offsetof(CPUState, gpr[5]) }, |
| 3269 | { "r6", offsetof(CPUState, gpr[6]) }, |
| 3270 | { "r7", offsetof(CPUState, gpr[7]) }, |
| 3271 | { "r8", offsetof(CPUState, gpr[8]) }, |
| 3272 | { "r9", offsetof(CPUState, gpr[9]) }, |
| 3273 | { "r10", offsetof(CPUState, gpr[10]) }, |
| 3274 | { "r11", offsetof(CPUState, gpr[11]) }, |
| 3275 | { "r12", offsetof(CPUState, gpr[12]) }, |
| 3276 | { "r13", offsetof(CPUState, gpr[13]) }, |
| 3277 | { "r14", offsetof(CPUState, gpr[14]) }, |
| 3278 | { "r15", offsetof(CPUState, gpr[15]) }, |
| 3279 | { "r16", offsetof(CPUState, gpr[16]) }, |
| 3280 | { "r17", offsetof(CPUState, gpr[17]) }, |
| 3281 | { "r18", offsetof(CPUState, gpr[18]) }, |
| 3282 | { "r19", offsetof(CPUState, gpr[19]) }, |
| 3283 | { "r20", offsetof(CPUState, gpr[20]) }, |
| 3284 | { "r21", offsetof(CPUState, gpr[21]) }, |
| 3285 | { "r22", offsetof(CPUState, gpr[22]) }, |
| 3286 | { "r23", offsetof(CPUState, gpr[23]) }, |
| 3287 | { "r24", offsetof(CPUState, gpr[24]) }, |
| 3288 | { "r25", offsetof(CPUState, gpr[25]) }, |
| 3289 | { "r26", offsetof(CPUState, gpr[26]) }, |
| 3290 | { "r27", offsetof(CPUState, gpr[27]) }, |
| 3291 | { "r28", offsetof(CPUState, gpr[28]) }, |
| 3292 | { "r29", offsetof(CPUState, gpr[29]) }, |
| 3293 | { "r30", offsetof(CPUState, gpr[30]) }, |
| 3294 | { "r31", offsetof(CPUState, gpr[31]) }, |
j_mayer | ff937db | 2007-09-19 05:49:13 +0000 | [diff] [blame] | 3295 | /* Floating point registers */ |
| 3296 | { "f0", offsetof(CPUState, fpr[0]) }, |
| 3297 | { "f1", offsetof(CPUState, fpr[1]) }, |
| 3298 | { "f2", offsetof(CPUState, fpr[2]) }, |
| 3299 | { "f3", offsetof(CPUState, fpr[3]) }, |
| 3300 | { "f4", offsetof(CPUState, fpr[4]) }, |
| 3301 | { "f5", offsetof(CPUState, fpr[5]) }, |
| 3302 | { "f6", offsetof(CPUState, fpr[6]) }, |
| 3303 | { "f7", offsetof(CPUState, fpr[7]) }, |
| 3304 | { "f8", offsetof(CPUState, fpr[8]) }, |
| 3305 | { "f9", offsetof(CPUState, fpr[9]) }, |
| 3306 | { "f10", offsetof(CPUState, fpr[10]) }, |
| 3307 | { "f11", offsetof(CPUState, fpr[11]) }, |
| 3308 | { "f12", offsetof(CPUState, fpr[12]) }, |
| 3309 | { "f13", offsetof(CPUState, fpr[13]) }, |
| 3310 | { "f14", offsetof(CPUState, fpr[14]) }, |
| 3311 | { "f15", offsetof(CPUState, fpr[15]) }, |
| 3312 | { "f16", offsetof(CPUState, fpr[16]) }, |
| 3313 | { "f17", offsetof(CPUState, fpr[17]) }, |
| 3314 | { "f18", offsetof(CPUState, fpr[18]) }, |
| 3315 | { "f19", offsetof(CPUState, fpr[19]) }, |
| 3316 | { "f20", offsetof(CPUState, fpr[20]) }, |
| 3317 | { "f21", offsetof(CPUState, fpr[21]) }, |
| 3318 | { "f22", offsetof(CPUState, fpr[22]) }, |
| 3319 | { "f23", offsetof(CPUState, fpr[23]) }, |
| 3320 | { "f24", offsetof(CPUState, fpr[24]) }, |
| 3321 | { "f25", offsetof(CPUState, fpr[25]) }, |
| 3322 | { "f26", offsetof(CPUState, fpr[26]) }, |
| 3323 | { "f27", offsetof(CPUState, fpr[27]) }, |
| 3324 | { "f28", offsetof(CPUState, fpr[28]) }, |
| 3325 | { "f29", offsetof(CPUState, fpr[29]) }, |
| 3326 | { "f30", offsetof(CPUState, fpr[30]) }, |
| 3327 | { "f31", offsetof(CPUState, fpr[31]) }, |
| 3328 | { "fpscr", offsetof(CPUState, fpscr) }, |
| 3329 | /* Next instruction pointer */ |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 3330 | { "nip|pc", offsetof(CPUState, nip) }, |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3331 | { "lr", offsetof(CPUState, lr) }, |
| 3332 | { "ctr", offsetof(CPUState, ctr) }, |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 3333 | { "decr", 0, &monitor_get_decr, }, |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3334 | { "ccr", 0, &monitor_get_ccr, }, |
j_mayer | ff937db | 2007-09-19 05:49:13 +0000 | [diff] [blame] | 3335 | /* Machine state register */ |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3336 | { "msr", 0, &monitor_get_msr, }, |
| 3337 | { "xer", 0, &monitor_get_xer, }, |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 3338 | { "tbu", 0, &monitor_get_tbu, }, |
| 3339 | { "tbl", 0, &monitor_get_tbl, }, |
j_mayer | ff937db | 2007-09-19 05:49:13 +0000 | [diff] [blame] | 3340 | #if defined(TARGET_PPC64) |
| 3341 | /* Address space register */ |
| 3342 | { "asr", offsetof(CPUState, asr) }, |
| 3343 | #endif |
| 3344 | /* Segment registers */ |
David Gibson | bb59390 | 2011-04-01 15:15:15 +1100 | [diff] [blame] | 3345 | { "sdr1", offsetof(CPUState, spr[SPR_SDR1]) }, |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3346 | { "sr0", offsetof(CPUState, sr[0]) }, |
| 3347 | { "sr1", offsetof(CPUState, sr[1]) }, |
| 3348 | { "sr2", offsetof(CPUState, sr[2]) }, |
| 3349 | { "sr3", offsetof(CPUState, sr[3]) }, |
| 3350 | { "sr4", offsetof(CPUState, sr[4]) }, |
| 3351 | { "sr5", offsetof(CPUState, sr[5]) }, |
| 3352 | { "sr6", offsetof(CPUState, sr[6]) }, |
| 3353 | { "sr7", offsetof(CPUState, sr[7]) }, |
| 3354 | { "sr8", offsetof(CPUState, sr[8]) }, |
| 3355 | { "sr9", offsetof(CPUState, sr[9]) }, |
| 3356 | { "sr10", offsetof(CPUState, sr[10]) }, |
| 3357 | { "sr11", offsetof(CPUState, sr[11]) }, |
| 3358 | { "sr12", offsetof(CPUState, sr[12]) }, |
| 3359 | { "sr13", offsetof(CPUState, sr[13]) }, |
| 3360 | { "sr14", offsetof(CPUState, sr[14]) }, |
| 3361 | { "sr15", offsetof(CPUState, sr[15]) }, |
Scott Wood | 90dc881 | 2011-04-29 17:10:23 -0500 | [diff] [blame] | 3362 | /* Too lazy to put BATs... */ |
| 3363 | { "pvr", offsetof(CPUState, spr[SPR_PVR]) }, |
| 3364 | |
| 3365 | { "srr0", offsetof(CPUState, spr[SPR_SRR0]) }, |
| 3366 | { "srr1", offsetof(CPUState, spr[SPR_SRR1]) }, |
| 3367 | { "sprg0", offsetof(CPUState, spr[SPR_SPRG0]) }, |
| 3368 | { "sprg1", offsetof(CPUState, spr[SPR_SPRG1]) }, |
| 3369 | { "sprg2", offsetof(CPUState, spr[SPR_SPRG2]) }, |
| 3370 | { "sprg3", offsetof(CPUState, spr[SPR_SPRG3]) }, |
| 3371 | { "sprg4", offsetof(CPUState, spr[SPR_SPRG4]) }, |
| 3372 | { "sprg5", offsetof(CPUState, spr[SPR_SPRG5]) }, |
| 3373 | { "sprg6", offsetof(CPUState, spr[SPR_SPRG6]) }, |
| 3374 | { "sprg7", offsetof(CPUState, spr[SPR_SPRG7]) }, |
| 3375 | { "pid", offsetof(CPUState, spr[SPR_BOOKE_PID]) }, |
| 3376 | { "csrr0", offsetof(CPUState, spr[SPR_BOOKE_CSRR0]) }, |
| 3377 | { "csrr1", offsetof(CPUState, spr[SPR_BOOKE_CSRR1]) }, |
| 3378 | { "esr", offsetof(CPUState, spr[SPR_BOOKE_ESR]) }, |
| 3379 | { "dear", offsetof(CPUState, spr[SPR_BOOKE_DEAR]) }, |
| 3380 | { "mcsr", offsetof(CPUState, spr[SPR_BOOKE_MCSR]) }, |
| 3381 | { "tsr", offsetof(CPUState, spr[SPR_BOOKE_TSR]) }, |
| 3382 | { "tcr", offsetof(CPUState, spr[SPR_BOOKE_TCR]) }, |
| 3383 | { "vrsave", offsetof(CPUState, spr[SPR_VRSAVE]) }, |
| 3384 | { "pir", offsetof(CPUState, spr[SPR_BOOKE_PIR]) }, |
| 3385 | { "mcsrr0", offsetof(CPUState, spr[SPR_BOOKE_MCSRR0]) }, |
| 3386 | { "mcsrr1", offsetof(CPUState, spr[SPR_BOOKE_MCSRR1]) }, |
| 3387 | { "decar", offsetof(CPUState, spr[SPR_BOOKE_DECAR]) }, |
| 3388 | { "ivpr", offsetof(CPUState, spr[SPR_BOOKE_IVPR]) }, |
| 3389 | { "epcr", offsetof(CPUState, spr[SPR_BOOKE_EPCR]) }, |
| 3390 | { "sprg8", offsetof(CPUState, spr[SPR_BOOKE_SPRG8]) }, |
| 3391 | { "ivor0", offsetof(CPUState, spr[SPR_BOOKE_IVOR0]) }, |
| 3392 | { "ivor1", offsetof(CPUState, spr[SPR_BOOKE_IVOR1]) }, |
| 3393 | { "ivor2", offsetof(CPUState, spr[SPR_BOOKE_IVOR2]) }, |
| 3394 | { "ivor3", offsetof(CPUState, spr[SPR_BOOKE_IVOR3]) }, |
| 3395 | { "ivor4", offsetof(CPUState, spr[SPR_BOOKE_IVOR4]) }, |
| 3396 | { "ivor5", offsetof(CPUState, spr[SPR_BOOKE_IVOR5]) }, |
| 3397 | { "ivor6", offsetof(CPUState, spr[SPR_BOOKE_IVOR6]) }, |
| 3398 | { "ivor7", offsetof(CPUState, spr[SPR_BOOKE_IVOR7]) }, |
| 3399 | { "ivor8", offsetof(CPUState, spr[SPR_BOOKE_IVOR8]) }, |
| 3400 | { "ivor9", offsetof(CPUState, spr[SPR_BOOKE_IVOR9]) }, |
| 3401 | { "ivor10", offsetof(CPUState, spr[SPR_BOOKE_IVOR10]) }, |
| 3402 | { "ivor11", offsetof(CPUState, spr[SPR_BOOKE_IVOR11]) }, |
| 3403 | { "ivor12", offsetof(CPUState, spr[SPR_BOOKE_IVOR12]) }, |
| 3404 | { "ivor13", offsetof(CPUState, spr[SPR_BOOKE_IVOR13]) }, |
| 3405 | { "ivor14", offsetof(CPUState, spr[SPR_BOOKE_IVOR14]) }, |
| 3406 | { "ivor15", offsetof(CPUState, spr[SPR_BOOKE_IVOR15]) }, |
| 3407 | { "ivor32", offsetof(CPUState, spr[SPR_BOOKE_IVOR32]) }, |
| 3408 | { "ivor33", offsetof(CPUState, spr[SPR_BOOKE_IVOR33]) }, |
| 3409 | { "ivor34", offsetof(CPUState, spr[SPR_BOOKE_IVOR34]) }, |
| 3410 | { "ivor35", offsetof(CPUState, spr[SPR_BOOKE_IVOR35]) }, |
| 3411 | { "ivor36", offsetof(CPUState, spr[SPR_BOOKE_IVOR36]) }, |
| 3412 | { "ivor37", offsetof(CPUState, spr[SPR_BOOKE_IVOR37]) }, |
| 3413 | { "mas0", offsetof(CPUState, spr[SPR_BOOKE_MAS0]) }, |
| 3414 | { "mas1", offsetof(CPUState, spr[SPR_BOOKE_MAS1]) }, |
| 3415 | { "mas2", offsetof(CPUState, spr[SPR_BOOKE_MAS2]) }, |
| 3416 | { "mas3", offsetof(CPUState, spr[SPR_BOOKE_MAS3]) }, |
| 3417 | { "mas4", offsetof(CPUState, spr[SPR_BOOKE_MAS4]) }, |
| 3418 | { "mas6", offsetof(CPUState, spr[SPR_BOOKE_MAS6]) }, |
| 3419 | { "mas7", offsetof(CPUState, spr[SPR_BOOKE_MAS7]) }, |
| 3420 | { "mmucfg", offsetof(CPUState, spr[SPR_MMUCFG]) }, |
| 3421 | { "tlb0cfg", offsetof(CPUState, spr[SPR_BOOKE_TLB0CFG]) }, |
| 3422 | { "tlb1cfg", offsetof(CPUState, spr[SPR_BOOKE_TLB1CFG]) }, |
| 3423 | { "epr", offsetof(CPUState, spr[SPR_BOOKE_EPR]) }, |
| 3424 | { "eplc", offsetof(CPUState, spr[SPR_BOOKE_EPLC]) }, |
| 3425 | { "epsc", offsetof(CPUState, spr[SPR_BOOKE_EPSC]) }, |
| 3426 | { "svr", offsetof(CPUState, spr[SPR_E500_SVR]) }, |
| 3427 | { "mcar", offsetof(CPUState, spr[SPR_Exxx_MCAR]) }, |
| 3428 | { "pid1", offsetof(CPUState, spr[SPR_BOOKE_PID1]) }, |
| 3429 | { "pid2", offsetof(CPUState, spr[SPR_BOOKE_PID2]) }, |
| 3430 | { "hid0", offsetof(CPUState, spr[SPR_HID0]) }, |
| 3431 | |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 3432 | #elif defined(TARGET_SPARC) |
| 3433 | { "g0", offsetof(CPUState, gregs[0]) }, |
| 3434 | { "g1", offsetof(CPUState, gregs[1]) }, |
| 3435 | { "g2", offsetof(CPUState, gregs[2]) }, |
| 3436 | { "g3", offsetof(CPUState, gregs[3]) }, |
| 3437 | { "g4", offsetof(CPUState, gregs[4]) }, |
| 3438 | { "g5", offsetof(CPUState, gregs[5]) }, |
| 3439 | { "g6", offsetof(CPUState, gregs[6]) }, |
| 3440 | { "g7", offsetof(CPUState, gregs[7]) }, |
| 3441 | { "o0", 0, monitor_get_reg }, |
| 3442 | { "o1", 1, monitor_get_reg }, |
| 3443 | { "o2", 2, monitor_get_reg }, |
| 3444 | { "o3", 3, monitor_get_reg }, |
| 3445 | { "o4", 4, monitor_get_reg }, |
| 3446 | { "o5", 5, monitor_get_reg }, |
| 3447 | { "o6", 6, monitor_get_reg }, |
| 3448 | { "o7", 7, monitor_get_reg }, |
| 3449 | { "l0", 8, monitor_get_reg }, |
| 3450 | { "l1", 9, monitor_get_reg }, |
| 3451 | { "l2", 10, monitor_get_reg }, |
| 3452 | { "l3", 11, monitor_get_reg }, |
| 3453 | { "l4", 12, monitor_get_reg }, |
| 3454 | { "l5", 13, monitor_get_reg }, |
| 3455 | { "l6", 14, monitor_get_reg }, |
| 3456 | { "l7", 15, monitor_get_reg }, |
| 3457 | { "i0", 16, monitor_get_reg }, |
| 3458 | { "i1", 17, monitor_get_reg }, |
| 3459 | { "i2", 18, monitor_get_reg }, |
| 3460 | { "i3", 19, monitor_get_reg }, |
| 3461 | { "i4", 20, monitor_get_reg }, |
| 3462 | { "i5", 21, monitor_get_reg }, |
| 3463 | { "i6", 22, monitor_get_reg }, |
| 3464 | { "i7", 23, monitor_get_reg }, |
| 3465 | { "pc", offsetof(CPUState, pc) }, |
| 3466 | { "npc", offsetof(CPUState, npc) }, |
| 3467 | { "y", offsetof(CPUState, y) }, |
bellard | 7b936c0 | 2005-10-30 17:05:13 +0000 | [diff] [blame] | 3468 | #ifndef TARGET_SPARC64 |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 3469 | { "psr", 0, &monitor_get_psr, }, |
| 3470 | { "wim", offsetof(CPUState, wim) }, |
bellard | 7b936c0 | 2005-10-30 17:05:13 +0000 | [diff] [blame] | 3471 | #endif |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 3472 | { "tbr", offsetof(CPUState, tbr) }, |
| 3473 | { "fsr", offsetof(CPUState, fsr) }, |
| 3474 | { "f0", offsetof(CPUState, fpr[0]) }, |
| 3475 | { "f1", offsetof(CPUState, fpr[1]) }, |
| 3476 | { "f2", offsetof(CPUState, fpr[2]) }, |
| 3477 | { "f3", offsetof(CPUState, fpr[3]) }, |
| 3478 | { "f4", offsetof(CPUState, fpr[4]) }, |
| 3479 | { "f5", offsetof(CPUState, fpr[5]) }, |
| 3480 | { "f6", offsetof(CPUState, fpr[6]) }, |
| 3481 | { "f7", offsetof(CPUState, fpr[7]) }, |
| 3482 | { "f8", offsetof(CPUState, fpr[8]) }, |
| 3483 | { "f9", offsetof(CPUState, fpr[9]) }, |
| 3484 | { "f10", offsetof(CPUState, fpr[10]) }, |
| 3485 | { "f11", offsetof(CPUState, fpr[11]) }, |
| 3486 | { "f12", offsetof(CPUState, fpr[12]) }, |
| 3487 | { "f13", offsetof(CPUState, fpr[13]) }, |
| 3488 | { "f14", offsetof(CPUState, fpr[14]) }, |
| 3489 | { "f15", offsetof(CPUState, fpr[15]) }, |
| 3490 | { "f16", offsetof(CPUState, fpr[16]) }, |
| 3491 | { "f17", offsetof(CPUState, fpr[17]) }, |
| 3492 | { "f18", offsetof(CPUState, fpr[18]) }, |
| 3493 | { "f19", offsetof(CPUState, fpr[19]) }, |
| 3494 | { "f20", offsetof(CPUState, fpr[20]) }, |
| 3495 | { "f21", offsetof(CPUState, fpr[21]) }, |
| 3496 | { "f22", offsetof(CPUState, fpr[22]) }, |
| 3497 | { "f23", offsetof(CPUState, fpr[23]) }, |
| 3498 | { "f24", offsetof(CPUState, fpr[24]) }, |
| 3499 | { "f25", offsetof(CPUState, fpr[25]) }, |
| 3500 | { "f26", offsetof(CPUState, fpr[26]) }, |
| 3501 | { "f27", offsetof(CPUState, fpr[27]) }, |
| 3502 | { "f28", offsetof(CPUState, fpr[28]) }, |
| 3503 | { "f29", offsetof(CPUState, fpr[29]) }, |
| 3504 | { "f30", offsetof(CPUState, fpr[30]) }, |
| 3505 | { "f31", offsetof(CPUState, fpr[31]) }, |
bellard | 7b936c0 | 2005-10-30 17:05:13 +0000 | [diff] [blame] | 3506 | #ifdef TARGET_SPARC64 |
| 3507 | { "f32", offsetof(CPUState, fpr[32]) }, |
| 3508 | { "f34", offsetof(CPUState, fpr[34]) }, |
| 3509 | { "f36", offsetof(CPUState, fpr[36]) }, |
| 3510 | { "f38", offsetof(CPUState, fpr[38]) }, |
| 3511 | { "f40", offsetof(CPUState, fpr[40]) }, |
| 3512 | { "f42", offsetof(CPUState, fpr[42]) }, |
| 3513 | { "f44", offsetof(CPUState, fpr[44]) }, |
| 3514 | { "f46", offsetof(CPUState, fpr[46]) }, |
| 3515 | { "f48", offsetof(CPUState, fpr[48]) }, |
| 3516 | { "f50", offsetof(CPUState, fpr[50]) }, |
| 3517 | { "f52", offsetof(CPUState, fpr[52]) }, |
| 3518 | { "f54", offsetof(CPUState, fpr[54]) }, |
| 3519 | { "f56", offsetof(CPUState, fpr[56]) }, |
| 3520 | { "f58", offsetof(CPUState, fpr[58]) }, |
| 3521 | { "f60", offsetof(CPUState, fpr[60]) }, |
| 3522 | { "f62", offsetof(CPUState, fpr[62]) }, |
| 3523 | { "asi", offsetof(CPUState, asi) }, |
| 3524 | { "pstate", offsetof(CPUState, pstate) }, |
| 3525 | { "cansave", offsetof(CPUState, cansave) }, |
| 3526 | { "canrestore", offsetof(CPUState, canrestore) }, |
| 3527 | { "otherwin", offsetof(CPUState, otherwin) }, |
| 3528 | { "wstate", offsetof(CPUState, wstate) }, |
| 3529 | { "cleanwin", offsetof(CPUState, cleanwin) }, |
| 3530 | { "fprs", offsetof(CPUState, fprs) }, |
| 3531 | #endif |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3532 | #endif |
| 3533 | { NULL }, |
| 3534 | }; |
| 3535 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3536 | static void expr_error(Monitor *mon, const char *msg) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 3537 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3538 | monitor_printf(mon, "%s\n", msg); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3539 | longjmp(expr_env, 1); |
| 3540 | } |
| 3541 | |
Markus Armbruster | 09b9418 | 2010-01-20 13:07:30 +0100 | [diff] [blame] | 3542 | /* return 0 if OK, -1 if not found */ |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3543 | static int get_monitor_def(target_long *pval, const char *name) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3544 | { |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 3545 | const MonitorDef *md; |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3546 | void *ptr; |
| 3547 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3548 | for(md = monitor_defs; md->name != NULL; md++) { |
| 3549 | if (compare_cmd(name, md->name)) { |
| 3550 | if (md->get_value) { |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 3551 | *pval = md->get_value(md, md->offset); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3552 | } else { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3553 | CPUState *env = mon_get_cpu(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3554 | ptr = (uint8_t *)env + md->offset; |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3555 | switch(md->type) { |
| 3556 | case MD_I32: |
| 3557 | *pval = *(int32_t *)ptr; |
| 3558 | break; |
| 3559 | case MD_TLONG: |
| 3560 | *pval = *(target_long *)ptr; |
| 3561 | break; |
| 3562 | default: |
| 3563 | *pval = 0; |
| 3564 | break; |
| 3565 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3566 | } |
| 3567 | return 0; |
| 3568 | } |
| 3569 | } |
| 3570 | return -1; |
| 3571 | } |
| 3572 | |
| 3573 | static void next(void) |
| 3574 | { |
Blue Swirl | 660f11b | 2009-07-31 21:16:51 +0000 | [diff] [blame] | 3575 | if (*pch != '\0') { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3576 | pch++; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3577 | while (qemu_isspace(*pch)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3578 | pch++; |
| 3579 | } |
| 3580 | } |
| 3581 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3582 | static int64_t expr_sum(Monitor *mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3583 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3584 | static int64_t expr_unary(Monitor *mon) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3585 | { |
blueswir1 | c2efc95 | 2007-09-25 17:28:42 +0000 | [diff] [blame] | 3586 | int64_t n; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3587 | char *p; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3588 | int ret; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3589 | |
| 3590 | switch(*pch) { |
| 3591 | case '+': |
| 3592 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3593 | n = expr_unary(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3594 | break; |
| 3595 | case '-': |
| 3596 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3597 | n = -expr_unary(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3598 | break; |
| 3599 | case '~': |
| 3600 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3601 | n = ~expr_unary(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3602 | break; |
| 3603 | case '(': |
| 3604 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3605 | n = expr_sum(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3606 | if (*pch != ')') { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3607 | expr_error(mon, "')' expected"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3608 | } |
| 3609 | next(); |
| 3610 | break; |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3611 | case '\'': |
| 3612 | pch++; |
| 3613 | if (*pch == '\0') |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3614 | expr_error(mon, "character constant expected"); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3615 | n = *pch; |
| 3616 | pch++; |
| 3617 | if (*pch != '\'') |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3618 | expr_error(mon, "missing terminating \' character"); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3619 | next(); |
| 3620 | break; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3621 | case '$': |
| 3622 | { |
| 3623 | char buf[128], *q; |
ths | 69b3497 | 2007-12-17 03:15:52 +0000 | [diff] [blame] | 3624 | target_long reg=0; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3625 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3626 | pch++; |
| 3627 | q = buf; |
| 3628 | while ((*pch >= 'a' && *pch <= 'z') || |
| 3629 | (*pch >= 'A' && *pch <= 'Z') || |
| 3630 | (*pch >= '0' && *pch <= '9') || |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 3631 | *pch == '_' || *pch == '.') { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3632 | if ((q - buf) < sizeof(buf) - 1) |
| 3633 | *q++ = *pch; |
| 3634 | pch++; |
| 3635 | } |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3636 | while (qemu_isspace(*pch)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3637 | pch++; |
| 3638 | *q = 0; |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 3639 | ret = get_monitor_def(®, buf); |
Markus Armbruster | 09b9418 | 2010-01-20 13:07:30 +0100 | [diff] [blame] | 3640 | if (ret < 0) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3641 | expr_error(mon, "unknown register"); |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 3642 | n = reg; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3643 | } |
| 3644 | break; |
| 3645 | case '\0': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3646 | expr_error(mon, "unexpected end of expression"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3647 | n = 0; |
| 3648 | break; |
| 3649 | default: |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 3650 | #if TARGET_PHYS_ADDR_BITS > 32 |
bellard | 4f4fbf7 | 2006-06-25 18:28:12 +0000 | [diff] [blame] | 3651 | n = strtoull(pch, &p, 0); |
| 3652 | #else |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3653 | n = strtoul(pch, &p, 0); |
bellard | 4f4fbf7 | 2006-06-25 18:28:12 +0000 | [diff] [blame] | 3654 | #endif |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3655 | if (pch == p) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3656 | expr_error(mon, "invalid char in expression"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3657 | } |
| 3658 | pch = p; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3659 | while (qemu_isspace(*pch)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3660 | pch++; |
| 3661 | break; |
| 3662 | } |
| 3663 | return n; |
| 3664 | } |
| 3665 | |
| 3666 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3667 | static int64_t expr_prod(Monitor *mon) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3668 | { |
blueswir1 | c2efc95 | 2007-09-25 17:28:42 +0000 | [diff] [blame] | 3669 | int64_t val, val2; |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3670 | int op; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3671 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3672 | val = expr_unary(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3673 | for(;;) { |
| 3674 | op = *pch; |
| 3675 | if (op != '*' && op != '/' && op != '%') |
| 3676 | break; |
| 3677 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3678 | val2 = expr_unary(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3679 | switch(op) { |
| 3680 | default: |
| 3681 | case '*': |
| 3682 | val *= val2; |
| 3683 | break; |
| 3684 | case '/': |
| 3685 | case '%': |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3686 | if (val2 == 0) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3687 | expr_error(mon, "division by zero"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3688 | if (op == '/') |
| 3689 | val /= val2; |
| 3690 | else |
| 3691 | val %= val2; |
| 3692 | break; |
| 3693 | } |
| 3694 | } |
| 3695 | return val; |
| 3696 | } |
| 3697 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3698 | static int64_t expr_logic(Monitor *mon) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3699 | { |
blueswir1 | c2efc95 | 2007-09-25 17:28:42 +0000 | [diff] [blame] | 3700 | int64_t val, val2; |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3701 | int op; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3702 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3703 | val = expr_prod(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3704 | for(;;) { |
| 3705 | op = *pch; |
| 3706 | if (op != '&' && op != '|' && op != '^') |
| 3707 | break; |
| 3708 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3709 | val2 = expr_prod(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3710 | switch(op) { |
| 3711 | default: |
| 3712 | case '&': |
| 3713 | val &= val2; |
| 3714 | break; |
| 3715 | case '|': |
| 3716 | val |= val2; |
| 3717 | break; |
| 3718 | case '^': |
| 3719 | val ^= val2; |
| 3720 | break; |
| 3721 | } |
| 3722 | } |
| 3723 | return val; |
| 3724 | } |
| 3725 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3726 | static int64_t expr_sum(Monitor *mon) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3727 | { |
blueswir1 | c2efc95 | 2007-09-25 17:28:42 +0000 | [diff] [blame] | 3728 | int64_t val, val2; |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3729 | int op; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3730 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3731 | val = expr_logic(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3732 | for(;;) { |
| 3733 | op = *pch; |
| 3734 | if (op != '+' && op != '-') |
| 3735 | break; |
| 3736 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3737 | val2 = expr_logic(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3738 | if (op == '+') |
| 3739 | val += val2; |
| 3740 | else |
| 3741 | val -= val2; |
| 3742 | } |
| 3743 | return val; |
| 3744 | } |
| 3745 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3746 | static int get_expr(Monitor *mon, int64_t *pval, const char **pp) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3747 | { |
| 3748 | pch = *pp; |
| 3749 | if (setjmp(expr_env)) { |
| 3750 | *pp = pch; |
| 3751 | return -1; |
| 3752 | } |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3753 | while (qemu_isspace(*pch)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3754 | pch++; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3755 | *pval = expr_sum(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3756 | *pp = pch; |
| 3757 | return 0; |
| 3758 | } |
| 3759 | |
Markus Armbruster | 3350a4d | 2010-01-25 14:23:03 +0100 | [diff] [blame] | 3760 | static int get_double(Monitor *mon, double *pval, const char **pp) |
| 3761 | { |
| 3762 | const char *p = *pp; |
| 3763 | char *tailp; |
| 3764 | double d; |
| 3765 | |
| 3766 | d = strtod(p, &tailp); |
| 3767 | if (tailp == p) { |
| 3768 | monitor_printf(mon, "Number expected\n"); |
| 3769 | return -1; |
| 3770 | } |
| 3771 | if (d != d || d - d != 0) { |
| 3772 | /* NaN or infinity */ |
| 3773 | monitor_printf(mon, "Bad number\n"); |
| 3774 | return -1; |
| 3775 | } |
| 3776 | *pval = d; |
| 3777 | *pp = tailp; |
| 3778 | return 0; |
| 3779 | } |
| 3780 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3781 | static int get_str(char *buf, int buf_size, const char **pp) |
| 3782 | { |
| 3783 | const char *p; |
| 3784 | char *q; |
| 3785 | int c; |
| 3786 | |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3787 | q = buf; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3788 | p = *pp; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3789 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3790 | p++; |
| 3791 | if (*p == '\0') { |
| 3792 | fail: |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3793 | *q = '\0'; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3794 | *pp = p; |
| 3795 | return -1; |
| 3796 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3797 | if (*p == '\"') { |
| 3798 | p++; |
| 3799 | while (*p != '\0' && *p != '\"') { |
| 3800 | if (*p == '\\') { |
| 3801 | p++; |
| 3802 | c = *p++; |
| 3803 | switch(c) { |
| 3804 | case 'n': |
| 3805 | c = '\n'; |
| 3806 | break; |
| 3807 | case 'r': |
| 3808 | c = '\r'; |
| 3809 | break; |
| 3810 | case '\\': |
| 3811 | case '\'': |
| 3812 | case '\"': |
| 3813 | break; |
| 3814 | default: |
| 3815 | qemu_printf("unsupported escape code: '\\%c'\n", c); |
| 3816 | goto fail; |
| 3817 | } |
| 3818 | if ((q - buf) < buf_size - 1) { |
| 3819 | *q++ = c; |
| 3820 | } |
| 3821 | } else { |
| 3822 | if ((q - buf) < buf_size - 1) { |
| 3823 | *q++ = *p; |
| 3824 | } |
| 3825 | p++; |
| 3826 | } |
| 3827 | } |
| 3828 | if (*p != '\"') { |
bellard | 5b60212 | 2004-05-22 21:41:05 +0000 | [diff] [blame] | 3829 | qemu_printf("unterminated string\n"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3830 | goto fail; |
| 3831 | } |
| 3832 | p++; |
| 3833 | } else { |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3834 | while (*p != '\0' && !qemu_isspace(*p)) { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3835 | if ((q - buf) < buf_size - 1) { |
| 3836 | *q++ = *p; |
| 3837 | } |
| 3838 | p++; |
| 3839 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3840 | } |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3841 | *q = '\0'; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3842 | *pp = p; |
| 3843 | return 0; |
| 3844 | } |
| 3845 | |
Luiz Capitulino | 4590fd8 | 2009-06-09 18:21:30 -0300 | [diff] [blame] | 3846 | /* |
| 3847 | * Store the command-name in cmdname, and return a pointer to |
| 3848 | * the remaining of the command string. |
| 3849 | */ |
| 3850 | static const char *get_command_name(const char *cmdline, |
| 3851 | char *cmdname, size_t nlen) |
| 3852 | { |
| 3853 | size_t len; |
| 3854 | const char *p, *pstart; |
| 3855 | |
| 3856 | p = cmdline; |
| 3857 | while (qemu_isspace(*p)) |
| 3858 | p++; |
| 3859 | if (*p == '\0') |
| 3860 | return NULL; |
| 3861 | pstart = p; |
| 3862 | while (*p != '\0' && *p != '/' && !qemu_isspace(*p)) |
| 3863 | p++; |
| 3864 | len = p - pstart; |
| 3865 | if (len > nlen - 1) |
| 3866 | len = nlen - 1; |
| 3867 | memcpy(cmdname, pstart, len); |
| 3868 | cmdname[len] = '\0'; |
| 3869 | return p; |
| 3870 | } |
| 3871 | |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3872 | /** |
| 3873 | * Read key of 'type' into 'key' and return the current |
| 3874 | * 'type' pointer. |
| 3875 | */ |
| 3876 | static char *key_get_info(const char *type, char **key) |
| 3877 | { |
| 3878 | size_t len; |
| 3879 | char *p, *str; |
| 3880 | |
| 3881 | if (*type == ',') |
| 3882 | type++; |
| 3883 | |
| 3884 | p = strchr(type, ':'); |
| 3885 | if (!p) { |
| 3886 | *key = NULL; |
| 3887 | return NULL; |
| 3888 | } |
| 3889 | len = p - type; |
| 3890 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 3891 | str = g_malloc(len + 1); |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3892 | memcpy(str, type, len); |
| 3893 | str[len] = '\0'; |
| 3894 | |
| 3895 | *key = str; |
| 3896 | return ++p; |
| 3897 | } |
| 3898 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3899 | static int default_fmt_format = 'x'; |
| 3900 | static int default_fmt_size = 4; |
| 3901 | |
| 3902 | #define MAX_ARGS 16 |
| 3903 | |
lirans@il.ibm.com | fbc3d96 | 2009-11-02 15:41:13 +0200 | [diff] [blame] | 3904 | static int is_valid_option(const char *c, const char *typestr) |
| 3905 | { |
| 3906 | char option[3]; |
| 3907 | |
| 3908 | option[0] = '-'; |
| 3909 | option[1] = *c; |
| 3910 | option[2] = '\0'; |
| 3911 | |
| 3912 | typestr = strstr(typestr, option); |
| 3913 | return (typestr != NULL); |
| 3914 | } |
| 3915 | |
Luiz Capitulino | 945c5ac | 2010-09-13 13:17:58 -0300 | [diff] [blame] | 3916 | static const mon_cmd_t *search_dispatch_table(const mon_cmd_t *disp_table, |
| 3917 | const char *cmdname) |
Luiz Capitulino | 7fd669a | 2009-11-26 22:58:54 -0200 | [diff] [blame] | 3918 | { |
| 3919 | const mon_cmd_t *cmd; |
| 3920 | |
Luiz Capitulino | 945c5ac | 2010-09-13 13:17:58 -0300 | [diff] [blame] | 3921 | for (cmd = disp_table; cmd->name != NULL; cmd++) { |
Luiz Capitulino | 7fd669a | 2009-11-26 22:58:54 -0200 | [diff] [blame] | 3922 | if (compare_cmd(cmdname, cmd->name)) { |
| 3923 | return cmd; |
| 3924 | } |
| 3925 | } |
| 3926 | |
| 3927 | return NULL; |
| 3928 | } |
| 3929 | |
Luiz Capitulino | 945c5ac | 2010-09-13 13:17:58 -0300 | [diff] [blame] | 3930 | static const mon_cmd_t *monitor_find_command(const char *cmdname) |
| 3931 | { |
| 3932 | return search_dispatch_table(mon_cmds, cmdname); |
| 3933 | } |
| 3934 | |
Luiz Capitulino | 030db6e | 2010-09-10 16:03:38 -0300 | [diff] [blame] | 3935 | static const mon_cmd_t *qmp_find_query_cmd(const char *info_item) |
| 3936 | { |
Luiz Capitulino | 3e12a75 | 2010-09-15 17:20:33 -0300 | [diff] [blame] | 3937 | return search_dispatch_table(qmp_query_cmds, info_item); |
Luiz Capitulino | 030db6e | 2010-09-10 16:03:38 -0300 | [diff] [blame] | 3938 | } |
| 3939 | |
Luiz Capitulino | bead3ce | 2010-09-15 17:08:39 -0300 | [diff] [blame] | 3940 | static const mon_cmd_t *qmp_find_cmd(const char *cmdname) |
| 3941 | { |
Luiz Capitulino | f36b4af | 2010-09-15 17:17:45 -0300 | [diff] [blame] | 3942 | return search_dispatch_table(qmp_cmds, cmdname); |
Luiz Capitulino | bead3ce | 2010-09-15 17:08:39 -0300 | [diff] [blame] | 3943 | } |
| 3944 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 3945 | static const mon_cmd_t *monitor_parse_command(Monitor *mon, |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3946 | const char *cmdline, |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3947 | QDict *qdict) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3948 | { |
Luiz Capitulino | 4590fd8 | 2009-06-09 18:21:30 -0300 | [diff] [blame] | 3949 | const char *p, *typestr; |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 3950 | int c; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 3951 | const mon_cmd_t *cmd; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3952 | char cmdname[256]; |
| 3953 | char buf[1024]; |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3954 | char *key; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 3955 | |
| 3956 | #ifdef DEBUG |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3957 | monitor_printf(mon, "command='%s'\n", cmdline); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 3958 | #endif |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3959 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3960 | /* extract the command name */ |
Luiz Capitulino | 4590fd8 | 2009-06-09 18:21:30 -0300 | [diff] [blame] | 3961 | p = get_command_name(cmdline, cmdname, sizeof(cmdname)); |
| 3962 | if (!p) |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3963 | return NULL; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3964 | |
Luiz Capitulino | 7fd669a | 2009-11-26 22:58:54 -0200 | [diff] [blame] | 3965 | cmd = monitor_find_command(cmdname); |
| 3966 | if (!cmd) { |
Luiz Capitulino | d91d9bf | 2009-06-09 18:21:54 -0300 | [diff] [blame] | 3967 | monitor_printf(mon, "unknown command: '%s'\n", cmdname); |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3968 | return NULL; |
Luiz Capitulino | d91d9bf | 2009-06-09 18:21:54 -0300 | [diff] [blame] | 3969 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3970 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3971 | /* parse the parameters */ |
| 3972 | typestr = cmd->args_type; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3973 | for(;;) { |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3974 | typestr = key_get_info(typestr, &key); |
| 3975 | if (!typestr) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3976 | break; |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3977 | c = *typestr; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3978 | typestr++; |
| 3979 | switch(c) { |
| 3980 | case 'F': |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3981 | case 'B': |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3982 | case 's': |
| 3983 | { |
| 3984 | int ret; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3985 | |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3986 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3987 | p++; |
| 3988 | if (*typestr == '?') { |
| 3989 | typestr++; |
| 3990 | if (*p == '\0') { |
| 3991 | /* no optional string: NULL argument */ |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 3992 | break; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3993 | } |
| 3994 | } |
| 3995 | ret = get_str(buf, sizeof(buf), &p); |
| 3996 | if (ret < 0) { |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3997 | switch(c) { |
| 3998 | case 'F': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3999 | monitor_printf(mon, "%s: filename expected\n", |
| 4000 | cmdname); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4001 | break; |
| 4002 | case 'B': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4003 | monitor_printf(mon, "%s: block device name expected\n", |
| 4004 | cmdname); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4005 | break; |
| 4006 | default: |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4007 | monitor_printf(mon, "%s: string expected\n", cmdname); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4008 | break; |
| 4009 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4010 | goto fail; |
| 4011 | } |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 4012 | qdict_put(qdict, key, qstring_from_str(buf)); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4013 | } |
| 4014 | break; |
Markus Armbruster | 361127d | 2010-02-10 20:24:35 +0100 | [diff] [blame] | 4015 | case 'O': |
| 4016 | { |
| 4017 | QemuOptsList *opts_list; |
| 4018 | QemuOpts *opts; |
| 4019 | |
| 4020 | opts_list = qemu_find_opts(key); |
| 4021 | if (!opts_list || opts_list->desc->name) { |
| 4022 | goto bad_type; |
| 4023 | } |
| 4024 | while (qemu_isspace(*p)) { |
| 4025 | p++; |
| 4026 | } |
| 4027 | if (!*p) |
| 4028 | break; |
| 4029 | if (get_str(buf, sizeof(buf), &p) < 0) { |
| 4030 | goto fail; |
| 4031 | } |
| 4032 | opts = qemu_opts_parse(opts_list, buf, 1); |
| 4033 | if (!opts) { |
| 4034 | goto fail; |
| 4035 | } |
| 4036 | qemu_opts_to_qdict(opts, qdict); |
| 4037 | qemu_opts_del(opts); |
| 4038 | } |
| 4039 | break; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4040 | case '/': |
| 4041 | { |
| 4042 | int count, format, size; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4043 | |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 4044 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4045 | p++; |
| 4046 | if (*p == '/') { |
| 4047 | /* format found */ |
| 4048 | p++; |
| 4049 | count = 1; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 4050 | if (qemu_isdigit(*p)) { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4051 | count = 0; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 4052 | while (qemu_isdigit(*p)) { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4053 | count = count * 10 + (*p - '0'); |
| 4054 | p++; |
| 4055 | } |
| 4056 | } |
| 4057 | size = -1; |
| 4058 | format = -1; |
| 4059 | for(;;) { |
| 4060 | switch(*p) { |
| 4061 | case 'o': |
| 4062 | case 'd': |
| 4063 | case 'u': |
| 4064 | case 'x': |
| 4065 | case 'i': |
| 4066 | case 'c': |
| 4067 | format = *p++; |
| 4068 | break; |
| 4069 | case 'b': |
| 4070 | size = 1; |
| 4071 | p++; |
| 4072 | break; |
| 4073 | case 'h': |
| 4074 | size = 2; |
| 4075 | p++; |
| 4076 | break; |
| 4077 | case 'w': |
| 4078 | size = 4; |
| 4079 | p++; |
| 4080 | break; |
| 4081 | case 'g': |
| 4082 | case 'L': |
| 4083 | size = 8; |
| 4084 | p++; |
| 4085 | break; |
| 4086 | default: |
| 4087 | goto next; |
| 4088 | } |
| 4089 | } |
| 4090 | next: |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 4091 | if (*p != '\0' && !qemu_isspace(*p)) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4092 | monitor_printf(mon, "invalid char in format: '%c'\n", |
| 4093 | *p); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4094 | goto fail; |
| 4095 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4096 | if (format < 0) |
| 4097 | format = default_fmt_format; |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 4098 | if (format != 'i') { |
| 4099 | /* for 'i', not specifying a size gives -1 as size */ |
| 4100 | if (size < 0) |
| 4101 | size = default_fmt_size; |
aurel32 | e90f009 | 2008-10-01 21:45:51 +0000 | [diff] [blame] | 4102 | default_fmt_size = size; |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 4103 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4104 | default_fmt_format = format; |
| 4105 | } else { |
| 4106 | count = 1; |
| 4107 | format = default_fmt_format; |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 4108 | if (format != 'i') { |
| 4109 | size = default_fmt_size; |
| 4110 | } else { |
| 4111 | size = -1; |
| 4112 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4113 | } |
Luiz Capitulino | f7188bb | 2009-08-28 15:27:10 -0300 | [diff] [blame] | 4114 | qdict_put(qdict, "count", qint_from_int(count)); |
| 4115 | qdict_put(qdict, "format", qint_from_int(format)); |
| 4116 | qdict_put(qdict, "size", qint_from_int(size)); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4117 | } |
| 4118 | break; |
| 4119 | case 'i': |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 4120 | case 'l': |
Luiz Capitulino | b6e098d | 2009-12-18 13:25:04 -0200 | [diff] [blame] | 4121 | case 'M': |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4122 | { |
blueswir1 | c2efc95 | 2007-09-25 17:28:42 +0000 | [diff] [blame] | 4123 | int64_t val; |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 4124 | |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 4125 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4126 | p++; |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 4127 | if (*typestr == '?' || *typestr == '.') { |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 4128 | if (*typestr == '?') { |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 4129 | if (*p == '\0') { |
| 4130 | typestr++; |
| 4131 | break; |
| 4132 | } |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 4133 | } else { |
| 4134 | if (*p == '.') { |
| 4135 | p++; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 4136 | while (qemu_isspace(*p)) |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 4137 | p++; |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 4138 | } else { |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 4139 | typestr++; |
| 4140 | break; |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 4141 | } |
| 4142 | } |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 4143 | typestr++; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4144 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4145 | if (get_expr(mon, &val, &p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4146 | goto fail; |
Luiz Capitulino | 675ebef | 2009-08-28 15:27:26 -0300 | [diff] [blame] | 4147 | /* Check if 'i' is greater than 32-bit */ |
| 4148 | if ((c == 'i') && ((val >> 32) & 0xffffffff)) { |
| 4149 | monitor_printf(mon, "\'%s\' has failed: ", cmdname); |
| 4150 | monitor_printf(mon, "integer is for 32-bit values\n"); |
| 4151 | goto fail; |
Luiz Capitulino | b6e098d | 2009-12-18 13:25:04 -0200 | [diff] [blame] | 4152 | } else if (c == 'M') { |
| 4153 | val <<= 20; |
Luiz Capitulino | 675ebef | 2009-08-28 15:27:26 -0300 | [diff] [blame] | 4154 | } |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 4155 | qdict_put(qdict, key, qint_from_int(val)); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4156 | } |
| 4157 | break; |
Jes Sorensen | dbc0c67 | 2010-10-21 17:15:47 +0200 | [diff] [blame] | 4158 | case 'o': |
| 4159 | { |
Jes Sorensen | 70b4f4b | 2011-01-05 11:41:02 +0100 | [diff] [blame] | 4160 | int64_t val; |
Jes Sorensen | dbc0c67 | 2010-10-21 17:15:47 +0200 | [diff] [blame] | 4161 | char *end; |
| 4162 | |
| 4163 | while (qemu_isspace(*p)) { |
| 4164 | p++; |
| 4165 | } |
| 4166 | if (*typestr == '?') { |
| 4167 | typestr++; |
| 4168 | if (*p == '\0') { |
| 4169 | break; |
| 4170 | } |
| 4171 | } |
| 4172 | val = strtosz(p, &end); |
| 4173 | if (val < 0) { |
| 4174 | monitor_printf(mon, "invalid size\n"); |
| 4175 | goto fail; |
| 4176 | } |
| 4177 | qdict_put(qdict, key, qint_from_int(val)); |
| 4178 | p = end; |
| 4179 | } |
| 4180 | break; |
Markus Armbruster | fccfb11e | 2010-01-25 14:23:06 +0100 | [diff] [blame] | 4181 | case 'T': |
Markus Armbruster | 3350a4d | 2010-01-25 14:23:03 +0100 | [diff] [blame] | 4182 | { |
| 4183 | double val; |
| 4184 | |
| 4185 | while (qemu_isspace(*p)) |
| 4186 | p++; |
| 4187 | if (*typestr == '?') { |
| 4188 | typestr++; |
| 4189 | if (*p == '\0') { |
| 4190 | break; |
| 4191 | } |
| 4192 | } |
| 4193 | if (get_double(mon, &val, &p) < 0) { |
| 4194 | goto fail; |
| 4195 | } |
Jes Sorensen | 07de3e6 | 2010-10-21 17:15:49 +0200 | [diff] [blame] | 4196 | if (p[0] && p[1] == 's') { |
Markus Armbruster | fccfb11e | 2010-01-25 14:23:06 +0100 | [diff] [blame] | 4197 | switch (*p) { |
| 4198 | case 'm': |
| 4199 | val /= 1e3; p += 2; break; |
| 4200 | case 'u': |
| 4201 | val /= 1e6; p += 2; break; |
| 4202 | case 'n': |
| 4203 | val /= 1e9; p += 2; break; |
| 4204 | } |
| 4205 | } |
Markus Armbruster | 3350a4d | 2010-01-25 14:23:03 +0100 | [diff] [blame] | 4206 | if (*p && !qemu_isspace(*p)) { |
| 4207 | monitor_printf(mon, "Unknown unit suffix\n"); |
| 4208 | goto fail; |
| 4209 | } |
| 4210 | qdict_put(qdict, key, qfloat_from_double(val)); |
| 4211 | } |
| 4212 | break; |
Markus Armbruster | 942cd1f | 2010-03-26 09:07:09 +0100 | [diff] [blame] | 4213 | case 'b': |
| 4214 | { |
| 4215 | const char *beg; |
| 4216 | int val; |
| 4217 | |
| 4218 | while (qemu_isspace(*p)) { |
| 4219 | p++; |
| 4220 | } |
| 4221 | beg = p; |
| 4222 | while (qemu_isgraph(*p)) { |
| 4223 | p++; |
| 4224 | } |
| 4225 | if (p - beg == 2 && !memcmp(beg, "on", p - beg)) { |
| 4226 | val = 1; |
| 4227 | } else if (p - beg == 3 && !memcmp(beg, "off", p - beg)) { |
| 4228 | val = 0; |
| 4229 | } else { |
| 4230 | monitor_printf(mon, "Expected 'on' or 'off'\n"); |
| 4231 | goto fail; |
| 4232 | } |
| 4233 | qdict_put(qdict, key, qbool_from_int(val)); |
| 4234 | } |
| 4235 | break; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4236 | case '-': |
| 4237 | { |
lirans@il.ibm.com | fbc3d96 | 2009-11-02 15:41:13 +0200 | [diff] [blame] | 4238 | const char *tmp = p; |
Luiz Capitulino | eb159d1 | 2010-05-28 15:25:24 -0300 | [diff] [blame] | 4239 | int skip_key = 0; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4240 | /* option */ |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4241 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4242 | c = *typestr++; |
| 4243 | if (c == '\0') |
| 4244 | goto bad_type; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 4245 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4246 | p++; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4247 | if (*p == '-') { |
| 4248 | p++; |
lirans@il.ibm.com | fbc3d96 | 2009-11-02 15:41:13 +0200 | [diff] [blame] | 4249 | if(c != *p) { |
| 4250 | if(!is_valid_option(p, typestr)) { |
| 4251 | |
| 4252 | monitor_printf(mon, "%s: unsupported option -%c\n", |
| 4253 | cmdname, *p); |
| 4254 | goto fail; |
| 4255 | } else { |
| 4256 | skip_key = 1; |
| 4257 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4258 | } |
lirans@il.ibm.com | fbc3d96 | 2009-11-02 15:41:13 +0200 | [diff] [blame] | 4259 | if(skip_key) { |
| 4260 | p = tmp; |
| 4261 | } else { |
Luiz Capitulino | eb159d1 | 2010-05-28 15:25:24 -0300 | [diff] [blame] | 4262 | /* has option */ |
lirans@il.ibm.com | fbc3d96 | 2009-11-02 15:41:13 +0200 | [diff] [blame] | 4263 | p++; |
Luiz Capitulino | eb159d1 | 2010-05-28 15:25:24 -0300 | [diff] [blame] | 4264 | qdict_put(qdict, key, qbool_from_int(1)); |
lirans@il.ibm.com | fbc3d96 | 2009-11-02 15:41:13 +0200 | [diff] [blame] | 4265 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4266 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4267 | } |
| 4268 | break; |
| 4269 | default: |
| 4270 | bad_type: |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4271 | monitor_printf(mon, "%s: unknown type '%c'\n", cmdname, c); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4272 | goto fail; |
| 4273 | } |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 4274 | g_free(key); |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 4275 | key = NULL; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4276 | } |
| 4277 | /* check that all arguments were parsed */ |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 4278 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4279 | p++; |
| 4280 | if (*p != '\0') { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4281 | monitor_printf(mon, "%s: extraneous characters at the end of line\n", |
| 4282 | cmdname); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 4283 | goto fail; |
| 4284 | } |
| 4285 | |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 4286 | return cmd; |
Gerd Hoffmann | ac7531e | 2009-08-14 10:36:06 +0200 | [diff] [blame] | 4287 | |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 4288 | fail: |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 4289 | g_free(key); |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 4290 | return NULL; |
| 4291 | } |
| 4292 | |
Markus Armbruster | d6f4683 | 2010-02-17 10:52:26 +0100 | [diff] [blame] | 4293 | void monitor_set_error(Monitor *mon, QError *qerror) |
| 4294 | { |
| 4295 | /* report only the first error */ |
| 4296 | if (!mon->error) { |
| 4297 | mon->error = qerror; |
| 4298 | } else { |
| 4299 | MON_DEBUG("Additional error report at %s:%d\n", |
| 4300 | qerror->file, qerror->linenr); |
| 4301 | QDECREF(qerror); |
| 4302 | } |
| 4303 | } |
| 4304 | |
Luiz Capitulino | bb89c2e | 2010-02-10 23:50:05 -0200 | [diff] [blame] | 4305 | static void handler_audit(Monitor *mon, const mon_cmd_t *cmd, int ret) |
| 4306 | { |
Luiz Capitulino | 6d44143 | 2010-11-22 16:35:09 -0200 | [diff] [blame] | 4307 | if (ret && !monitor_has_error(mon)) { |
| 4308 | /* |
| 4309 | * If it returns failure, it must have passed on error. |
| 4310 | * |
| 4311 | * Action: Report an internal error to the client if in QMP. |
| 4312 | */ |
| 4313 | qerror_report(QERR_UNDEFINED_ERROR); |
| 4314 | MON_DEBUG("command '%s' returned failure but did not pass an error\n", |
| 4315 | cmd->name); |
| 4316 | } |
Luiz Capitulino | bb89c2e | 2010-02-10 23:50:05 -0200 | [diff] [blame] | 4317 | |
| 4318 | #ifdef CONFIG_DEBUG_MONITOR |
Luiz Capitulino | 6d44143 | 2010-11-22 16:35:09 -0200 | [diff] [blame] | 4319 | if (!ret && monitor_has_error(mon)) { |
| 4320 | /* |
| 4321 | * If it returns success, it must not have passed an error. |
| 4322 | * |
| 4323 | * Action: Report the passed error to the client. |
| 4324 | */ |
| 4325 | MON_DEBUG("command '%s' returned success but passed an error\n", |
| 4326 | cmd->name); |
Markus Armbruster | cde0fc7 | 2010-03-02 14:56:34 +0100 | [diff] [blame] | 4327 | } |
Luiz Capitulino | 6d44143 | 2010-11-22 16:35:09 -0200 | [diff] [blame] | 4328 | |
| 4329 | if (mon_print_count_get(mon) > 0 && strcmp(cmd->name, "info") != 0) { |
| 4330 | /* |
| 4331 | * Handlers should not call Monitor print functions. |
| 4332 | * |
| 4333 | * Action: Ignore them in QMP. |
| 4334 | * |
| 4335 | * (XXX: we don't check any 'info' or 'query' command here |
| 4336 | * because the user print function _is_ called by do_info(), hence |
| 4337 | * we will trigger this check. This problem will go away when we |
| 4338 | * make 'query' commands real and kill do_info()) |
| 4339 | */ |
| 4340 | MON_DEBUG("command '%s' called print functions %d time(s)\n", |
| 4341 | cmd->name, mon_print_count_get(mon)); |
| 4342 | } |
| 4343 | #endif |
Luiz Capitulino | bb89c2e | 2010-02-10 23:50:05 -0200 | [diff] [blame] | 4344 | } |
| 4345 | |
Luiz Capitulino | f3c157c | 2009-11-26 22:58:55 -0200 | [diff] [blame] | 4346 | static void handle_user_command(Monitor *mon, const char *cmdline) |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 4347 | { |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 4348 | QDict *qdict; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 4349 | const mon_cmd_t *cmd; |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 4350 | |
| 4351 | qdict = qdict_new(); |
| 4352 | |
Luiz Capitulino | 590fb3b | 2009-08-28 15:27:24 -0300 | [diff] [blame] | 4353 | cmd = monitor_parse_command(mon, cmdline, qdict); |
Luiz Capitulino | 13917be | 2009-10-07 13:41:54 -0300 | [diff] [blame] | 4354 | if (!cmd) |
| 4355 | goto out; |
| 4356 | |
Luiz Capitulino | 4903de0 | 2010-09-16 11:01:32 -0300 | [diff] [blame] | 4357 | if (handler_is_async(cmd)) { |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 4358 | user_async_cmd_handler(mon, cmd, qdict); |
Luiz Capitulino | 9e80721 | 2010-09-16 10:58:59 -0300 | [diff] [blame] | 4359 | } else if (handler_is_qobject(cmd)) { |
Luiz Capitulino | de79ba6 | 2010-09-16 11:06:11 -0300 | [diff] [blame] | 4360 | QObject *data = NULL; |
| 4361 | |
| 4362 | /* XXX: ignores the error code */ |
| 4363 | cmd->mhandler.cmd_new(mon, qdict, &data); |
| 4364 | assert(!monitor_has_error(mon)); |
| 4365 | if (data) { |
| 4366 | cmd->user_print(mon, data); |
| 4367 | qobject_decref(data); |
| 4368 | } |
Luiz Capitulino | 13917be | 2009-10-07 13:41:54 -0300 | [diff] [blame] | 4369 | } else { |
Luiz Capitulino | af4ce88 | 2009-10-07 13:41:52 -0300 | [diff] [blame] | 4370 | cmd->mhandler.cmd(mon, qdict); |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 4371 | } |
| 4372 | |
Luiz Capitulino | 13917be | 2009-10-07 13:41:54 -0300 | [diff] [blame] | 4373 | out: |
Luiz Capitulino | f7188bb | 2009-08-28 15:27:10 -0300 | [diff] [blame] | 4374 | QDECREF(qdict); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 4375 | } |
| 4376 | |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4377 | static void cmd_completion(const char *name, const char *list) |
| 4378 | { |
| 4379 | const char *p, *pstart; |
| 4380 | char cmd[128]; |
| 4381 | int len; |
| 4382 | |
| 4383 | p = list; |
| 4384 | for(;;) { |
| 4385 | pstart = p; |
| 4386 | p = strchr(p, '|'); |
| 4387 | if (!p) |
| 4388 | p = pstart + strlen(pstart); |
| 4389 | len = p - pstart; |
| 4390 | if (len > sizeof(cmd) - 2) |
| 4391 | len = sizeof(cmd) - 2; |
| 4392 | memcpy(cmd, pstart, len); |
| 4393 | cmd[len] = '\0'; |
| 4394 | if (name[0] == '\0' || !strncmp(name, cmd, strlen(name))) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4395 | readline_add_completion(cur_mon->rs, cmd); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4396 | } |
| 4397 | if (*p == '\0') |
| 4398 | break; |
| 4399 | p++; |
| 4400 | } |
| 4401 | } |
| 4402 | |
| 4403 | static void file_completion(const char *input) |
| 4404 | { |
| 4405 | DIR *ffs; |
| 4406 | struct dirent *d; |
| 4407 | char path[1024]; |
| 4408 | char file[1024], file_prefix[1024]; |
| 4409 | int input_path_len; |
| 4410 | const char *p; |
| 4411 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4412 | p = strrchr(input, '/'); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4413 | if (!p) { |
| 4414 | input_path_len = 0; |
| 4415 | pstrcpy(file_prefix, sizeof(file_prefix), input); |
blueswir1 | 363a37d | 2008-08-21 17:58:08 +0000 | [diff] [blame] | 4416 | pstrcpy(path, sizeof(path), "."); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4417 | } else { |
| 4418 | input_path_len = p - input + 1; |
| 4419 | memcpy(path, input, input_path_len); |
| 4420 | if (input_path_len > sizeof(path) - 1) |
| 4421 | input_path_len = sizeof(path) - 1; |
| 4422 | path[input_path_len] = '\0'; |
| 4423 | pstrcpy(file_prefix, sizeof(file_prefix), p + 1); |
| 4424 | } |
| 4425 | #ifdef DEBUG_COMPLETION |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4426 | monitor_printf(cur_mon, "input='%s' path='%s' prefix='%s'\n", |
| 4427 | input, path, file_prefix); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4428 | #endif |
| 4429 | ffs = opendir(path); |
| 4430 | if (!ffs) |
| 4431 | return; |
| 4432 | for(;;) { |
| 4433 | struct stat sb; |
| 4434 | d = readdir(ffs); |
| 4435 | if (!d) |
| 4436 | break; |
Kusanagi Kouichi | 46c7fc1 | 2010-10-20 18:00:01 +0900 | [diff] [blame] | 4437 | |
| 4438 | if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) { |
| 4439 | continue; |
| 4440 | } |
| 4441 | |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4442 | if (strstart(d->d_name, file_prefix, NULL)) { |
| 4443 | memcpy(file, input, input_path_len); |
blueswir1 | 363a37d | 2008-08-21 17:58:08 +0000 | [diff] [blame] | 4444 | if (input_path_len < sizeof(file)) |
| 4445 | pstrcpy(file + input_path_len, sizeof(file) - input_path_len, |
| 4446 | d->d_name); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4447 | /* stat the file to find out if it's a directory. |
| 4448 | * In that case add a slash to speed up typing long paths |
| 4449 | */ |
| 4450 | stat(file, &sb); |
| 4451 | if(S_ISDIR(sb.st_mode)) |
blueswir1 | 363a37d | 2008-08-21 17:58:08 +0000 | [diff] [blame] | 4452 | pstrcat(file, sizeof(file), "/"); |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4453 | readline_add_completion(cur_mon->rs, file); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4454 | } |
| 4455 | } |
| 4456 | closedir(ffs); |
| 4457 | } |
| 4458 | |
aliguori | 51de976 | 2009-03-05 23:00:43 +0000 | [diff] [blame] | 4459 | static void block_completion_it(void *opaque, BlockDriverState *bs) |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4460 | { |
aliguori | 51de976 | 2009-03-05 23:00:43 +0000 | [diff] [blame] | 4461 | const char *name = bdrv_get_device_name(bs); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4462 | const char *input = opaque; |
| 4463 | |
| 4464 | if (input[0] == '\0' || |
| 4465 | !strncmp(name, (char *)input, strlen(input))) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4466 | readline_add_completion(cur_mon->rs, name); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4467 | } |
| 4468 | } |
| 4469 | |
| 4470 | /* NOTE: this parser is an approximate form of the real command parser */ |
| 4471 | static void parse_cmdline(const char *cmdline, |
| 4472 | int *pnb_args, char **args) |
| 4473 | { |
| 4474 | const char *p; |
| 4475 | int nb_args, ret; |
| 4476 | char buf[1024]; |
| 4477 | |
| 4478 | p = cmdline; |
| 4479 | nb_args = 0; |
| 4480 | for(;;) { |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 4481 | while (qemu_isspace(*p)) |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4482 | p++; |
| 4483 | if (*p == '\0') |
| 4484 | break; |
| 4485 | if (nb_args >= MAX_ARGS) |
| 4486 | break; |
| 4487 | ret = get_str(buf, sizeof(buf), &p); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 4488 | args[nb_args] = g_strdup(buf); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4489 | nb_args++; |
| 4490 | if (ret < 0) |
| 4491 | break; |
| 4492 | } |
| 4493 | *pnb_args = nb_args; |
| 4494 | } |
| 4495 | |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 4496 | static const char *next_arg_type(const char *typestr) |
| 4497 | { |
| 4498 | const char *p = strchr(typestr, ':'); |
| 4499 | return (p != NULL ? ++p : typestr); |
| 4500 | } |
| 4501 | |
aliguori | 4c36ba3 | 2009-03-05 23:01:37 +0000 | [diff] [blame] | 4502 | static void monitor_find_completion(const char *cmdline) |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4503 | { |
| 4504 | const char *cmdname; |
| 4505 | char *args[MAX_ARGS]; |
| 4506 | int nb_args, i, len; |
| 4507 | const char *ptype, *str; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 4508 | const mon_cmd_t *cmd; |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 4509 | const KeyDef *key; |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4510 | |
| 4511 | parse_cmdline(cmdline, &nb_args, args); |
| 4512 | #ifdef DEBUG_COMPLETION |
| 4513 | for(i = 0; i < nb_args; i++) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4514 | monitor_printf(cur_mon, "arg%d = '%s'\n", i, (char *)args[i]); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4515 | } |
| 4516 | #endif |
| 4517 | |
| 4518 | /* if the line ends with a space, it means we want to complete the |
| 4519 | next arg */ |
| 4520 | len = strlen(cmdline); |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 4521 | if (len > 0 && qemu_isspace(cmdline[len - 1])) { |
Jan Kiszka | 03a6348 | 2010-06-16 00:38:33 +0200 | [diff] [blame] | 4522 | if (nb_args >= MAX_ARGS) { |
| 4523 | goto cleanup; |
| 4524 | } |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 4525 | args[nb_args++] = g_strdup(""); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4526 | } |
| 4527 | if (nb_args <= 1) { |
| 4528 | /* command completion */ |
| 4529 | if (nb_args == 0) |
| 4530 | cmdname = ""; |
| 4531 | else |
| 4532 | cmdname = args[0]; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4533 | readline_set_completion_index(cur_mon->rs, strlen(cmdname)); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4534 | for(cmd = mon_cmds; cmd->name != NULL; cmd++) { |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4535 | cmd_completion(cmdname, cmd->name); |
| 4536 | } |
| 4537 | } else { |
| 4538 | /* find the command */ |
Jan Kiszka | 03a6348 | 2010-06-16 00:38:33 +0200 | [diff] [blame] | 4539 | for (cmd = mon_cmds; cmd->name != NULL; cmd++) { |
| 4540 | if (compare_cmd(args[0], cmd->name)) { |
| 4541 | break; |
| 4542 | } |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4543 | } |
Jan Kiszka | 03a6348 | 2010-06-16 00:38:33 +0200 | [diff] [blame] | 4544 | if (!cmd->name) { |
| 4545 | goto cleanup; |
| 4546 | } |
| 4547 | |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 4548 | ptype = next_arg_type(cmd->args_type); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4549 | for(i = 0; i < nb_args - 2; i++) { |
| 4550 | if (*ptype != '\0') { |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 4551 | ptype = next_arg_type(ptype); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4552 | while (*ptype == '?') |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 4553 | ptype = next_arg_type(ptype); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4554 | } |
| 4555 | } |
| 4556 | str = args[nb_args - 1]; |
Blue Swirl | 2a1704a | 2009-08-23 20:10:28 +0000 | [diff] [blame] | 4557 | if (*ptype == '-' && ptype[1] != '\0') { |
Jan Kiszka | 3b6dbf2 | 2010-06-16 00:38:34 +0200 | [diff] [blame] | 4558 | ptype = next_arg_type(ptype); |
Blue Swirl | 2a1704a | 2009-08-23 20:10:28 +0000 | [diff] [blame] | 4559 | } |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4560 | switch(*ptype) { |
| 4561 | case 'F': |
| 4562 | /* file completion */ |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4563 | readline_set_completion_index(cur_mon->rs, strlen(str)); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4564 | file_completion(str); |
| 4565 | break; |
| 4566 | case 'B': |
| 4567 | /* block device name completion */ |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4568 | readline_set_completion_index(cur_mon->rs, strlen(str)); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4569 | bdrv_iterate(block_completion_it, (void *)str); |
| 4570 | break; |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 4571 | case 's': |
| 4572 | /* XXX: more generic ? */ |
| 4573 | if (!strcmp(cmd->name, "info")) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4574 | readline_set_completion_index(cur_mon->rs, strlen(str)); |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 4575 | for(cmd = info_cmds; cmd->name != NULL; cmd++) { |
| 4576 | cmd_completion(str, cmd->name); |
| 4577 | } |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 4578 | } else if (!strcmp(cmd->name, "sendkey")) { |
blueswir1 | e600d1e | 2009-03-08 17:42:02 +0000 | [diff] [blame] | 4579 | char *sep = strrchr(str, '-'); |
| 4580 | if (sep) |
| 4581 | str = sep + 1; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4582 | readline_set_completion_index(cur_mon->rs, strlen(str)); |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 4583 | for(key = key_defs; key->name != NULL; key++) { |
| 4584 | cmd_completion(str, key->name); |
| 4585 | } |
Jan Kiszka | f3353c6 | 2009-06-25 08:22:02 +0200 | [diff] [blame] | 4586 | } else if (!strcmp(cmd->name, "help|?")) { |
| 4587 | readline_set_completion_index(cur_mon->rs, strlen(str)); |
| 4588 | for (cmd = mon_cmds; cmd->name != NULL; cmd++) { |
| 4589 | cmd_completion(str, cmd->name); |
| 4590 | } |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 4591 | } |
| 4592 | break; |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4593 | default: |
| 4594 | break; |
| 4595 | } |
| 4596 | } |
Jan Kiszka | 03a6348 | 2010-06-16 00:38:33 +0200 | [diff] [blame] | 4597 | |
| 4598 | cleanup: |
| 4599 | for (i = 0; i < nb_args; i++) { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 4600 | g_free(args[i]); |
Jan Kiszka | 03a6348 | 2010-06-16 00:38:33 +0200 | [diff] [blame] | 4601 | } |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4602 | } |
| 4603 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4604 | static int monitor_can_read(void *opaque) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 4605 | { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4606 | Monitor *mon = opaque; |
| 4607 | |
Jan Kiszka | c62313b | 2009-12-04 14:05:29 +0100 | [diff] [blame] | 4608 | return (mon->suspend_cnt == 0) ? 1 : 0; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 4609 | } |
| 4610 | |
Luiz Capitulino | 09069b1 | 2010-02-04 18:10:06 -0200 | [diff] [blame] | 4611 | static int invalid_qmp_mode(const Monitor *mon, const char *cmd_name) |
| 4612 | { |
| 4613 | int is_cap = compare_cmd(cmd_name, "qmp_capabilities"); |
| 4614 | return (qmp_cmd_mode(mon) ? is_cap : !is_cap); |
| 4615 | } |
| 4616 | |
Luiz Capitulino | 2dbc8db | 2010-05-26 16:13:09 -0300 | [diff] [blame] | 4617 | /* |
Luiz Capitulino | 4af9193 | 2010-06-22 11:44:05 -0300 | [diff] [blame] | 4618 | * Argument validation rules: |
| 4619 | * |
| 4620 | * 1. The argument must exist in cmd_args qdict |
| 4621 | * 2. The argument type must be the expected one |
| 4622 | * |
| 4623 | * Special case: If the argument doesn't exist in cmd_args and |
| 4624 | * the QMP_ACCEPT_UNKNOWNS flag is set, then the |
| 4625 | * checking is skipped for it. |
| 4626 | */ |
| 4627 | static int check_client_args_type(const QDict *client_args, |
| 4628 | const QDict *cmd_args, int flags) |
| 4629 | { |
| 4630 | const QDictEntry *ent; |
| 4631 | |
| 4632 | for (ent = qdict_first(client_args); ent;ent = qdict_next(client_args,ent)){ |
| 4633 | QObject *obj; |
| 4634 | QString *arg_type; |
| 4635 | const QObject *client_arg = qdict_entry_value(ent); |
| 4636 | const char *client_arg_name = qdict_entry_key(ent); |
| 4637 | |
| 4638 | obj = qdict_get(cmd_args, client_arg_name); |
| 4639 | if (!obj) { |
| 4640 | if (flags & QMP_ACCEPT_UNKNOWNS) { |
| 4641 | /* handler accepts unknowns */ |
| 4642 | continue; |
| 4643 | } |
| 4644 | /* client arg doesn't exist */ |
| 4645 | qerror_report(QERR_INVALID_PARAMETER, client_arg_name); |
| 4646 | return -1; |
| 4647 | } |
| 4648 | |
| 4649 | arg_type = qobject_to_qstring(obj); |
| 4650 | assert(arg_type != NULL); |
| 4651 | |
| 4652 | /* check if argument's type is correct */ |
| 4653 | switch (qstring_get_str(arg_type)[0]) { |
| 4654 | case 'F': |
| 4655 | case 'B': |
| 4656 | case 's': |
| 4657 | if (qobject_type(client_arg) != QTYPE_QSTRING) { |
| 4658 | qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name, |
| 4659 | "string"); |
| 4660 | return -1; |
| 4661 | } |
| 4662 | break; |
| 4663 | case 'i': |
| 4664 | case 'l': |
| 4665 | case 'M': |
Jes Sorensen | dbc0c67 | 2010-10-21 17:15:47 +0200 | [diff] [blame] | 4666 | case 'o': |
Luiz Capitulino | 4af9193 | 2010-06-22 11:44:05 -0300 | [diff] [blame] | 4667 | if (qobject_type(client_arg) != QTYPE_QINT) { |
| 4668 | qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name, |
| 4669 | "int"); |
| 4670 | return -1; |
| 4671 | } |
| 4672 | break; |
Luiz Capitulino | 4af9193 | 2010-06-22 11:44:05 -0300 | [diff] [blame] | 4673 | case 'T': |
| 4674 | if (qobject_type(client_arg) != QTYPE_QINT && |
| 4675 | qobject_type(client_arg) != QTYPE_QFLOAT) { |
| 4676 | qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name, |
| 4677 | "number"); |
| 4678 | return -1; |
| 4679 | } |
| 4680 | break; |
| 4681 | case 'b': |
| 4682 | case '-': |
| 4683 | if (qobject_type(client_arg) != QTYPE_QBOOL) { |
| 4684 | qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name, |
| 4685 | "bool"); |
| 4686 | return -1; |
| 4687 | } |
| 4688 | break; |
| 4689 | case 'O': |
| 4690 | assert(flags & QMP_ACCEPT_UNKNOWNS); |
| 4691 | break; |
| 4692 | case '/': |
| 4693 | case '.': |
| 4694 | /* |
| 4695 | * These types are not supported by QMP and thus are not |
| 4696 | * handled here. Fall through. |
| 4697 | */ |
| 4698 | default: |
| 4699 | abort(); |
| 4700 | } |
| 4701 | } |
| 4702 | |
| 4703 | return 0; |
| 4704 | } |
| 4705 | |
| 4706 | /* |
Luiz Capitulino | 2dbc8db | 2010-05-26 16:13:09 -0300 | [diff] [blame] | 4707 | * - Check if the client has passed all mandatory args |
| 4708 | * - Set special flags for argument validation |
| 4709 | */ |
| 4710 | static int check_mandatory_args(const QDict *cmd_args, |
| 4711 | const QDict *client_args, int *flags) |
| 4712 | { |
| 4713 | const QDictEntry *ent; |
| 4714 | |
| 4715 | for (ent = qdict_first(cmd_args); ent; ent = qdict_next(cmd_args, ent)) { |
| 4716 | const char *cmd_arg_name = qdict_entry_key(ent); |
| 4717 | QString *type = qobject_to_qstring(qdict_entry_value(ent)); |
| 4718 | assert(type != NULL); |
| 4719 | |
| 4720 | if (qstring_get_str(type)[0] == 'O') { |
| 4721 | assert((*flags & QMP_ACCEPT_UNKNOWNS) == 0); |
| 4722 | *flags |= QMP_ACCEPT_UNKNOWNS; |
| 4723 | } else if (qstring_get_str(type)[0] != '-' && |
| 4724 | qstring_get_str(type)[1] != '?' && |
| 4725 | !qdict_haskey(client_args, cmd_arg_name)) { |
| 4726 | qerror_report(QERR_MISSING_PARAMETER, cmd_arg_name); |
| 4727 | return -1; |
| 4728 | } |
| 4729 | } |
| 4730 | |
| 4731 | return 0; |
| 4732 | } |
| 4733 | |
| 4734 | static QDict *qdict_from_args_type(const char *args_type) |
| 4735 | { |
| 4736 | int i; |
| 4737 | QDict *qdict; |
| 4738 | QString *key, *type, *cur_qs; |
| 4739 | |
| 4740 | assert(args_type != NULL); |
| 4741 | |
| 4742 | qdict = qdict_new(); |
| 4743 | |
| 4744 | if (args_type == NULL || args_type[0] == '\0') { |
| 4745 | /* no args, empty qdict */ |
| 4746 | goto out; |
| 4747 | } |
| 4748 | |
| 4749 | key = qstring_new(); |
| 4750 | type = qstring_new(); |
| 4751 | |
| 4752 | cur_qs = key; |
| 4753 | |
| 4754 | for (i = 0;; i++) { |
| 4755 | switch (args_type[i]) { |
| 4756 | case ',': |
| 4757 | case '\0': |
| 4758 | qdict_put(qdict, qstring_get_str(key), type); |
| 4759 | QDECREF(key); |
| 4760 | if (args_type[i] == '\0') { |
| 4761 | goto out; |
| 4762 | } |
| 4763 | type = qstring_new(); /* qdict has ref */ |
| 4764 | cur_qs = key = qstring_new(); |
| 4765 | break; |
| 4766 | case ':': |
| 4767 | cur_qs = type; |
| 4768 | break; |
| 4769 | default: |
| 4770 | qstring_append_chr(cur_qs, args_type[i]); |
| 4771 | break; |
| 4772 | } |
| 4773 | } |
| 4774 | |
| 4775 | out: |
| 4776 | return qdict; |
| 4777 | } |
| 4778 | |
| 4779 | /* |
| 4780 | * Client argument checking rules: |
| 4781 | * |
| 4782 | * 1. Client must provide all mandatory arguments |
Luiz Capitulino | 4af9193 | 2010-06-22 11:44:05 -0300 | [diff] [blame] | 4783 | * 2. Each argument provided by the client must be expected |
| 4784 | * 3. Each argument provided by the client must have the type expected |
| 4785 | * by the command |
Luiz Capitulino | 2dbc8db | 2010-05-26 16:13:09 -0300 | [diff] [blame] | 4786 | */ |
| 4787 | static int qmp_check_client_args(const mon_cmd_t *cmd, QDict *client_args) |
| 4788 | { |
| 4789 | int flags, err; |
| 4790 | QDict *cmd_args; |
| 4791 | |
| 4792 | cmd_args = qdict_from_args_type(cmd->args_type); |
| 4793 | |
| 4794 | flags = 0; |
| 4795 | err = check_mandatory_args(cmd_args, client_args, &flags); |
| 4796 | if (err) { |
| 4797 | goto out; |
| 4798 | } |
| 4799 | |
Luiz Capitulino | 4af9193 | 2010-06-22 11:44:05 -0300 | [diff] [blame] | 4800 | err = check_client_args_type(client_args, cmd_args, flags); |
Luiz Capitulino | 2dbc8db | 2010-05-26 16:13:09 -0300 | [diff] [blame] | 4801 | |
| 4802 | out: |
| 4803 | QDECREF(cmd_args); |
| 4804 | return err; |
| 4805 | } |
| 4806 | |
Luiz Capitulino | c917c8f | 2010-05-31 17:28:01 -0300 | [diff] [blame] | 4807 | /* |
| 4808 | * Input object checking rules |
| 4809 | * |
| 4810 | * 1. Input object must be a dict |
| 4811 | * 2. The "execute" key must exist |
| 4812 | * 3. The "execute" key must be a string |
| 4813 | * 4. If the "arguments" key exists, it must be a dict |
| 4814 | * 5. If the "id" key exists, it can be anything (ie. json-value) |
| 4815 | * 6. Any argument not listed above is considered invalid |
| 4816 | */ |
| 4817 | static QDict *qmp_check_input_obj(QObject *input_obj) |
| 4818 | { |
| 4819 | const QDictEntry *ent; |
| 4820 | int has_exec_key = 0; |
| 4821 | QDict *input_dict; |
| 4822 | |
| 4823 | if (qobject_type(input_obj) != QTYPE_QDICT) { |
| 4824 | qerror_report(QERR_QMP_BAD_INPUT_OBJECT, "object"); |
| 4825 | return NULL; |
| 4826 | } |
| 4827 | |
| 4828 | input_dict = qobject_to_qdict(input_obj); |
| 4829 | |
| 4830 | for (ent = qdict_first(input_dict); ent; ent = qdict_next(input_dict, ent)){ |
| 4831 | const char *arg_name = qdict_entry_key(ent); |
| 4832 | const QObject *arg_obj = qdict_entry_value(ent); |
| 4833 | |
| 4834 | if (!strcmp(arg_name, "execute")) { |
| 4835 | if (qobject_type(arg_obj) != QTYPE_QSTRING) { |
| 4836 | qerror_report(QERR_QMP_BAD_INPUT_OBJECT_MEMBER, "execute", |
| 4837 | "string"); |
| 4838 | return NULL; |
| 4839 | } |
| 4840 | has_exec_key = 1; |
| 4841 | } else if (!strcmp(arg_name, "arguments")) { |
| 4842 | if (qobject_type(arg_obj) != QTYPE_QDICT) { |
| 4843 | qerror_report(QERR_QMP_BAD_INPUT_OBJECT_MEMBER, "arguments", |
| 4844 | "object"); |
| 4845 | return NULL; |
| 4846 | } |
| 4847 | } else if (!strcmp(arg_name, "id")) { |
| 4848 | /* FIXME: check duplicated IDs for async commands */ |
| 4849 | } else { |
| 4850 | qerror_report(QERR_QMP_EXTRA_MEMBER, arg_name); |
| 4851 | return NULL; |
| 4852 | } |
| 4853 | } |
| 4854 | |
| 4855 | if (!has_exec_key) { |
| 4856 | qerror_report(QERR_QMP_BAD_INPUT_OBJECT, "execute"); |
| 4857 | return NULL; |
| 4858 | } |
| 4859 | |
| 4860 | return input_dict; |
| 4861 | } |
| 4862 | |
Luiz Capitulino | 030db6e | 2010-09-10 16:03:38 -0300 | [diff] [blame] | 4863 | static void qmp_call_query_cmd(Monitor *mon, const mon_cmd_t *cmd) |
| 4864 | { |
| 4865 | QObject *ret_data = NULL; |
| 4866 | |
Luiz Capitulino | 4903de0 | 2010-09-16 11:01:32 -0300 | [diff] [blame] | 4867 | if (handler_is_async(cmd)) { |
Luiz Capitulino | 030db6e | 2010-09-10 16:03:38 -0300 | [diff] [blame] | 4868 | qmp_async_info_handler(mon, cmd); |
| 4869 | if (monitor_has_error(mon)) { |
| 4870 | monitor_protocol_emitter(mon, NULL); |
| 4871 | } |
| 4872 | } else { |
| 4873 | cmd->mhandler.info_new(mon, &ret_data); |
Luiz Capitulino | c01e688 | 2010-11-22 16:22:47 -0200 | [diff] [blame] | 4874 | monitor_protocol_emitter(mon, ret_data); |
| 4875 | qobject_decref(ret_data); |
Luiz Capitulino | 030db6e | 2010-09-10 16:03:38 -0300 | [diff] [blame] | 4876 | } |
| 4877 | } |
| 4878 | |
Luiz Capitulino | fc29df7 | 2010-09-16 11:11:18 -0300 | [diff] [blame] | 4879 | static void qmp_call_cmd(Monitor *mon, const mon_cmd_t *cmd, |
| 4880 | const QDict *params) |
| 4881 | { |
| 4882 | int ret; |
| 4883 | QObject *data = NULL; |
| 4884 | |
| 4885 | mon_print_count_init(mon); |
| 4886 | |
| 4887 | ret = cmd->mhandler.cmd_new(mon, params, &data); |
| 4888 | handler_audit(mon, cmd, ret); |
| 4889 | monitor_protocol_emitter(mon, data); |
| 4890 | qobject_decref(data); |
| 4891 | } |
| 4892 | |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4893 | static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) |
| 4894 | { |
| 4895 | int err; |
| 4896 | QObject *obj; |
| 4897 | QDict *input, *args; |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4898 | const mon_cmd_t *cmd; |
| 4899 | Monitor *mon = cur_mon; |
Luiz Capitulino | 030db6e | 2010-09-10 16:03:38 -0300 | [diff] [blame] | 4900 | const char *cmd_name, *query_cmd; |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4901 | |
Luiz Capitulino | 030db6e | 2010-09-10 16:03:38 -0300 | [diff] [blame] | 4902 | query_cmd = NULL; |
Luiz Capitulino | e4940c6 | 2010-06-24 17:58:20 -0300 | [diff] [blame] | 4903 | args = input = NULL; |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4904 | |
| 4905 | obj = json_parser_parse(tokens, NULL); |
| 4906 | if (!obj) { |
| 4907 | // FIXME: should be triggered in json_parser_parse() |
Markus Armbruster | ab5b027 | 2010-03-02 18:15:09 +0100 | [diff] [blame] | 4908 | qerror_report(QERR_JSON_PARSING); |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4909 | goto err_out; |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4910 | } |
| 4911 | |
Luiz Capitulino | c917c8f | 2010-05-31 17:28:01 -0300 | [diff] [blame] | 4912 | input = qmp_check_input_obj(obj); |
| 4913 | if (!input) { |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4914 | qobject_decref(obj); |
| 4915 | goto err_out; |
| 4916 | } |
| 4917 | |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4918 | mon->mc->id = qdict_get(input, "id"); |
| 4919 | qobject_incref(mon->mc->id); |
| 4920 | |
Luiz Capitulino | 0bbab46 | 2010-05-31 17:32:50 -0300 | [diff] [blame] | 4921 | cmd_name = qdict_get_str(input, "execute"); |
Stefan Hajnoczi | 89bd820 | 2011-09-23 08:23:06 +0100 | [diff] [blame] | 4922 | trace_handle_qmp_command(mon, cmd_name); |
Luiz Capitulino | 09069b1 | 2010-02-04 18:10:06 -0200 | [diff] [blame] | 4923 | if (invalid_qmp_mode(mon, cmd_name)) { |
Markus Armbruster | ab5b027 | 2010-03-02 18:15:09 +0100 | [diff] [blame] | 4924 | qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name); |
Luiz Capitulino | e4940c6 | 2010-06-24 17:58:20 -0300 | [diff] [blame] | 4925 | goto err_out; |
Luiz Capitulino | 09069b1 | 2010-02-04 18:10:06 -0200 | [diff] [blame] | 4926 | } |
| 4927 | |
Anthony Liguori | e319360 | 2011-09-02 12:34:47 -0500 | [diff] [blame] | 4928 | cmd = qmp_find_cmd(cmd_name); |
| 4929 | if (!cmd && strstart(cmd_name, "query-", &query_cmd)) { |
Luiz Capitulino | 030db6e | 2010-09-10 16:03:38 -0300 | [diff] [blame] | 4930 | cmd = qmp_find_query_cmd(query_cmd); |
Luiz Capitulino | 0fb8858 | 2010-09-15 10:56:17 -0300 | [diff] [blame] | 4931 | } |
Luiz Capitulino | d1249ea | 2010-09-13 14:44:27 -0300 | [diff] [blame] | 4932 | if (!cmd) { |
Markus Armbruster | ab5b027 | 2010-03-02 18:15:09 +0100 | [diff] [blame] | 4933 | qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name); |
Luiz Capitulino | e4940c6 | 2010-06-24 17:58:20 -0300 | [diff] [blame] | 4934 | goto err_out; |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4935 | } |
| 4936 | |
| 4937 | obj = qdict_get(input, "arguments"); |
| 4938 | if (!obj) { |
| 4939 | args = qdict_new(); |
| 4940 | } else { |
| 4941 | args = qobject_to_qdict(obj); |
| 4942 | QINCREF(args); |
| 4943 | } |
| 4944 | |
Luiz Capitulino | 2dbc8db | 2010-05-26 16:13:09 -0300 | [diff] [blame] | 4945 | err = qmp_check_client_args(cmd, args); |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4946 | if (err < 0) { |
| 4947 | goto err_out; |
| 4948 | } |
| 4949 | |
Luiz Capitulino | 030db6e | 2010-09-10 16:03:38 -0300 | [diff] [blame] | 4950 | if (query_cmd) { |
| 4951 | qmp_call_query_cmd(mon, cmd); |
Luiz Capitulino | 4903de0 | 2010-09-16 11:01:32 -0300 | [diff] [blame] | 4952 | } else if (handler_is_async(cmd)) { |
Luiz Capitulino | 5af7bba | 2010-06-22 19:10:46 -0300 | [diff] [blame] | 4953 | err = qmp_async_cmd_handler(mon, cmd, args); |
| 4954 | if (err) { |
| 4955 | /* emit the error response */ |
| 4956 | goto err_out; |
| 4957 | } |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 4958 | } else { |
Luiz Capitulino | fc29df7 | 2010-09-16 11:11:18 -0300 | [diff] [blame] | 4959 | qmp_call_cmd(mon, cmd, args); |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 4960 | } |
Luiz Capitulino | e4940c6 | 2010-06-24 17:58:20 -0300 | [diff] [blame] | 4961 | |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4962 | goto out; |
| 4963 | |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4964 | err_out: |
| 4965 | monitor_protocol_emitter(mon, NULL); |
| 4966 | out: |
Luiz Capitulino | e4940c6 | 2010-06-24 17:58:20 -0300 | [diff] [blame] | 4967 | QDECREF(input); |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4968 | QDECREF(args); |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4969 | } |
| 4970 | |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 4971 | /** |
| 4972 | * monitor_control_read(): Read and handle QMP input |
| 4973 | */ |
| 4974 | static void monitor_control_read(void *opaque, const uint8_t *buf, int size) |
| 4975 | { |
| 4976 | Monitor *old_mon = cur_mon; |
| 4977 | |
| 4978 | cur_mon = opaque; |
| 4979 | |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4980 | json_message_parser_feed(&cur_mon->mc->parser, (const char *) buf, size); |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 4981 | |
| 4982 | cur_mon = old_mon; |
| 4983 | } |
| 4984 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4985 | static void monitor_read(void *opaque, const uint8_t *buf, int size) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 4986 | { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4987 | Monitor *old_mon = cur_mon; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 4988 | int i; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4989 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4990 | cur_mon = opaque; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 4991 | |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 4992 | if (cur_mon->rs) { |
| 4993 | for (i = 0; i < size; i++) |
| 4994 | readline_handle_byte(cur_mon->rs, buf[i]); |
| 4995 | } else { |
| 4996 | if (size == 0 || buf[size - 1] != 0) |
| 4997 | monitor_printf(cur_mon, "corrupted command\n"); |
| 4998 | else |
Luiz Capitulino | f3c157c | 2009-11-26 22:58:55 -0200 | [diff] [blame] | 4999 | handle_user_command(cur_mon, (char *)buf); |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 5000 | } |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 5001 | |
| 5002 | cur_mon = old_mon; |
| 5003 | } |
aliguori | d8f4460 | 2008-10-06 13:52:44 +0000 | [diff] [blame] | 5004 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 5005 | static void monitor_command_cb(Monitor *mon, const char *cmdline, void *opaque) |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 5006 | { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 5007 | monitor_suspend(mon); |
Luiz Capitulino | f3c157c | 2009-11-26 22:58:55 -0200 | [diff] [blame] | 5008 | handle_user_command(mon, cmdline); |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 5009 | monitor_resume(mon); |
aliguori | d8f4460 | 2008-10-06 13:52:44 +0000 | [diff] [blame] | 5010 | } |
| 5011 | |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 5012 | int monitor_suspend(Monitor *mon) |
aliguori | d8f4460 | 2008-10-06 13:52:44 +0000 | [diff] [blame] | 5013 | { |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 5014 | if (!mon->rs) |
| 5015 | return -ENOTTY; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 5016 | mon->suspend_cnt++; |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 5017 | return 0; |
aliguori | d8f4460 | 2008-10-06 13:52:44 +0000 | [diff] [blame] | 5018 | } |
| 5019 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 5020 | void monitor_resume(Monitor *mon) |
aliguori | d8f4460 | 2008-10-06 13:52:44 +0000 | [diff] [blame] | 5021 | { |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 5022 | if (!mon->rs) |
| 5023 | return; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 5024 | if (--mon->suspend_cnt == 0) |
| 5025 | readline_show_prompt(mon->rs); |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 5026 | } |
| 5027 | |
Luiz Capitulino | ca9567e | 2010-02-04 18:10:04 -0200 | [diff] [blame] | 5028 | static QObject *get_qmp_greeting(void) |
| 5029 | { |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 5030 | QObject *ver = NULL; |
Luiz Capitulino | ca9567e | 2010-02-04 18:10:04 -0200 | [diff] [blame] | 5031 | |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 5032 | qmp_marshal_input_query_version(NULL, NULL, &ver); |
Luiz Capitulino | ca9567e | 2010-02-04 18:10:04 -0200 | [diff] [blame] | 5033 | return qobject_from_jsonf("{'QMP':{'version': %p,'capabilities': []}}",ver); |
| 5034 | } |
| 5035 | |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 5036 | /** |
| 5037 | * monitor_control_event(): Print QMP gretting |
| 5038 | */ |
| 5039 | static void monitor_control_event(void *opaque, int event) |
| 5040 | { |
Luiz Capitulino | 47116d1 | 2010-02-08 17:01:30 -0200 | [diff] [blame] | 5041 | QObject *data; |
| 5042 | Monitor *mon = opaque; |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 5043 | |
Luiz Capitulino | 47116d1 | 2010-02-08 17:01:30 -0200 | [diff] [blame] | 5044 | switch (event) { |
| 5045 | case CHR_EVENT_OPENED: |
Luiz Capitulino | 4a7e119 | 2010-02-04 18:10:05 -0200 | [diff] [blame] | 5046 | mon->mc->command_mode = 0; |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 5047 | json_message_parser_init(&mon->mc->parser, handle_qmp_command); |
Luiz Capitulino | ca9567e | 2010-02-04 18:10:04 -0200 | [diff] [blame] | 5048 | data = get_qmp_greeting(); |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 5049 | monitor_json_emitter(mon, data); |
| 5050 | qobject_decref(data); |
Luiz Capitulino | 47116d1 | 2010-02-08 17:01:30 -0200 | [diff] [blame] | 5051 | break; |
| 5052 | case CHR_EVENT_CLOSED: |
| 5053 | json_message_parser_destroy(&mon->mc->parser); |
| 5054 | break; |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 5055 | } |
| 5056 | } |
| 5057 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 5058 | static void monitor_event(void *opaque, int event) |
ths | 86e94de | 2007-01-05 22:01:59 +0000 | [diff] [blame] | 5059 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 5060 | Monitor *mon = opaque; |
| 5061 | |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 5062 | switch (event) { |
| 5063 | case CHR_EVENT_MUX_IN: |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 5064 | mon->mux_out = 0; |
| 5065 | if (mon->reset_seen) { |
| 5066 | readline_restart(mon->rs); |
| 5067 | monitor_resume(mon); |
| 5068 | monitor_flush(mon); |
| 5069 | } else { |
| 5070 | mon->suspend_cnt = 0; |
| 5071 | } |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 5072 | break; |
ths | 86e94de | 2007-01-05 22:01:59 +0000 | [diff] [blame] | 5073 | |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 5074 | case CHR_EVENT_MUX_OUT: |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 5075 | if (mon->reset_seen) { |
| 5076 | if (mon->suspend_cnt == 0) { |
| 5077 | monitor_printf(mon, "\n"); |
| 5078 | } |
| 5079 | monitor_flush(mon); |
| 5080 | monitor_suspend(mon); |
| 5081 | } else { |
| 5082 | mon->suspend_cnt++; |
| 5083 | } |
| 5084 | mon->mux_out = 1; |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 5085 | break; |
| 5086 | |
Amit Shah | b6b8df5 | 2009-10-07 18:31:16 +0530 | [diff] [blame] | 5087 | case CHR_EVENT_OPENED: |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 5088 | monitor_printf(mon, "QEMU %s monitor - type 'help' for more " |
| 5089 | "information\n", QEMU_VERSION); |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 5090 | if (!mon->mux_out) { |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 5091 | readline_show_prompt(mon->rs); |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 5092 | } |
| 5093 | mon->reset_seen = 1; |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 5094 | break; |
| 5095 | } |
ths | 86e94de | 2007-01-05 22:01:59 +0000 | [diff] [blame] | 5096 | } |
| 5097 | |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 5098 | |
| 5099 | /* |
| 5100 | * Local variables: |
| 5101 | * c-indent-level: 4 |
| 5102 | * c-basic-offset: 4 |
| 5103 | * tab-width: 8 |
| 5104 | * End: |
| 5105 | */ |
| 5106 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 5107 | void monitor_init(CharDriverState *chr, int flags) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 5108 | { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 5109 | static int is_first_init = 1; |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 5110 | Monitor *mon; |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 5111 | |
| 5112 | if (is_first_init) { |
Paolo Bonzini | 7447545 | 2011-03-11 16:47:48 +0100 | [diff] [blame] | 5113 | key_timer = qemu_new_timer_ns(vm_clock, release_keys, NULL); |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 5114 | is_first_init = 0; |
| 5115 | } |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 5116 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 5117 | mon = g_malloc0(sizeof(*mon)); |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 5118 | |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 5119 | mon->chr = chr; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 5120 | mon->flags = flags; |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 5121 | if (flags & MONITOR_USE_READLINE) { |
| 5122 | mon->rs = readline_init(mon, monitor_find_completion); |
| 5123 | monitor_read_command(mon, 0); |
| 5124 | } |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 5125 | |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 5126 | if (monitor_ctrl_mode(mon)) { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 5127 | mon->mc = g_malloc0(sizeof(MonitorControl)); |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 5128 | /* Control mode requires special handlers */ |
| 5129 | qemu_chr_add_handlers(chr, monitor_can_read, monitor_control_read, |
| 5130 | monitor_control_event, mon); |
Anthony Liguori | 15f3151 | 2011-08-15 11:17:35 -0500 | [diff] [blame] | 5131 | qemu_chr_fe_set_echo(chr, true); |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 5132 | } else { |
| 5133 | qemu_chr_add_handlers(chr, monitor_can_read, monitor_read, |
| 5134 | monitor_event, mon); |
| 5135 | } |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 5136 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 5137 | QLIST_INSERT_HEAD(&mon_list, mon, entry); |
Markus Armbruster | 8631b60 | 2010-02-18 11:41:55 +0100 | [diff] [blame] | 5138 | if (!default_mon || (flags & MONITOR_IS_DEFAULT)) |
| 5139 | default_mon = mon; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 5140 | } |
| 5141 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 5142 | static void bdrv_password_cb(Monitor *mon, const char *password, void *opaque) |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 5143 | { |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 5144 | BlockDriverState *bs = opaque; |
| 5145 | int ret = 0; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 5146 | |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 5147 | if (bdrv_set_key(bs, password) != 0) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 5148 | monitor_printf(mon, "invalid password\n"); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 5149 | ret = -EPERM; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 5150 | } |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 5151 | if (mon->password_completion_cb) |
| 5152 | mon->password_completion_cb(mon->password_opaque, ret); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 5153 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 5154 | monitor_read_command(mon, 1); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 5155 | } |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 5156 | |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 5157 | int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, |
| 5158 | BlockDriverCompletionFunc *completion_cb, |
| 5159 | void *opaque) |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 5160 | { |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 5161 | int err; |
| 5162 | |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 5163 | if (!bdrv_key_required(bs)) { |
| 5164 | if (completion_cb) |
| 5165 | completion_cb(opaque, 0); |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 5166 | return 0; |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 5167 | } |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 5168 | |
Luiz Capitulino | 94171e1 | 2009-12-07 21:37:00 +0100 | [diff] [blame] | 5169 | if (monitor_ctrl_mode(mon)) { |
Markus Armbruster | ab5b027 | 2010-03-02 18:15:09 +0100 | [diff] [blame] | 5170 | qerror_report(QERR_DEVICE_ENCRYPTED, bdrv_get_device_name(bs)); |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 5171 | return -1; |
Luiz Capitulino | 94171e1 | 2009-12-07 21:37:00 +0100 | [diff] [blame] | 5172 | } |
| 5173 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 5174 | monitor_printf(mon, "%s (%s) is encrypted.\n", bdrv_get_device_name(bs), |
| 5175 | bdrv_get_encrypted_filename(bs)); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 5176 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 5177 | mon->password_completion_cb = completion_cb; |
| 5178 | mon->password_opaque = opaque; |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 5179 | |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 5180 | err = monitor_read_password(mon, bdrv_password_cb, bs); |
| 5181 | |
| 5182 | if (err && completion_cb) |
| 5183 | completion_cb(opaque, err); |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame] | 5184 | |
| 5185 | return err; |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 5186 | } |