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