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