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