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