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