blob: 342af32326e5d972e786f7f59edf9a2bdfe542a4 [file] [log] [blame]
bellard9dc39cb2004-03-14 21:38:27 +00001/*
2 * QEMU monitor
ths5fafdf22007-09-16 21:08:06 +00003 *
bellard9dc39cb2004-03-14 21:38:27 +00004 * Copyright (c) 2003-2004 Fabrice Bellard
ths5fafdf22007-09-16 21:08:06 +00005 *
bellard9dc39cb2004-03-14 21:38:27 +00006 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
blueswir1511d2b12009-03-07 15:32:56 +000024#include <dirent.h>
pbrook87ecb682007-11-17 17:14:51 +000025#include "hw/hw.h"
Gerd Hoffmanncae49562009-06-05 15:53:17 +010026#include "hw/qdev.h"
pbrook87ecb682007-11-17 17:14:51 +000027#include "hw/usb.h"
28#include "hw/pcmcia.h"
29#include "hw/pc.h"
30#include "hw/pci.h"
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +010031#include "hw/watchdog.h"
pbrook87ecb682007-11-17 17:14:51 +000032#include "gdbstub.h"
33#include "net.h"
34#include "qemu-char.h"
35#include "sysemu.h"
aliguori376253e2009-03-05 23:01:23 +000036#include "monitor.h"
37#include "readline.h"
pbrook87ecb682007-11-17 17:14:51 +000038#include "console.h"
39#include "block.h"
40#include "audio/audio.h"
bellard9307c4c2004-04-04 12:57:25 +000041#include "disas.h"
aliguoridf751fa2008-12-04 20:19:35 +000042#include "balloon.h"
balrogc8256f92008-06-08 22:45:01 +000043#include "qemu-timer.h"
aliguori5bb79102008-10-13 03:12:02 +000044#include "migration.h"
aliguori7ba1e612008-11-05 16:04:33 +000045#include "kvm.h"
aliguori76655d62009-03-06 20:27:37 +000046#include "acl.h"
ths6a5bd302007-12-03 17:05:38 +000047
bellard9dc39cb2004-03-14 21:38:27 +000048//#define DEBUG
bellard81d09122004-07-14 17:21:37 +000049//#define DEBUG_COMPLETION
bellard9dc39cb2004-03-14 21:38:27 +000050
bellard9307c4c2004-04-04 12:57:25 +000051/*
52 * Supported types:
ths5fafdf22007-09-16 21:08:06 +000053 *
bellard9307c4c2004-04-04 12:57:25 +000054 * 'F' filename
bellard81d09122004-07-14 17:21:37 +000055 * 'B' block device name
bellard9307c4c2004-04-04 12:57:25 +000056 * 's' string (accept optional quote)
bellard92a31b12005-02-10 22:00:52 +000057 * 'i' 32 bit integer
58 * 'l' target long (32 or 64 bit)
bellard9307c4c2004-04-04 12:57:25 +000059 * '/' optional gdb-like print format (like "/10x")
60 *
61 * '?' optional type (for 'F', 's' and 'i')
62 *
63 */
64
aliguori376253e2009-03-05 23:01:23 +000065typedef struct mon_cmd_t {
bellard9dc39cb2004-03-14 21:38:27 +000066 const char *name;
bellard9307c4c2004-04-04 12:57:25 +000067 const char *args_type;
blueswir1a5f1b962008-08-17 20:21:51 +000068 void *handler;
bellard9dc39cb2004-03-14 21:38:27 +000069 const char *params;
70 const char *help;
aliguori376253e2009-03-05 23:01:23 +000071} mon_cmd_t;
bellard9dc39cb2004-03-14 21:38:27 +000072
aliguori87127162009-03-05 23:01:29 +000073struct Monitor {
74 CharDriverState *chr;
aliguori731b0362009-03-05 23:01:42 +000075 int flags;
76 int suspend_cnt;
77 uint8_t outbuf[1024];
78 int outbuf_index;
79 ReadLineState *rs;
80 CPUState *mon_cpu;
81 BlockDriverCompletionFunc *password_completion_cb;
82 void *password_opaque;
aliguori87127162009-03-05 23:01:29 +000083 LIST_ENTRY(Monitor) entry;
84};
85
86static LIST_HEAD(mon_list, Monitor) mon_list;
bellard7e2515e2004-08-01 21:52:19 +000087
aliguori376253e2009-03-05 23:01:23 +000088static const mon_cmd_t mon_cmds[];
89static const mon_cmd_t info_cmds[];
bellard9dc39cb2004-03-14 21:38:27 +000090
aliguori87127162009-03-05 23:01:29 +000091Monitor *cur_mon = NULL;
aliguori376253e2009-03-05 23:01:23 +000092
aliguori731b0362009-03-05 23:01:42 +000093static void monitor_command_cb(Monitor *mon, const char *cmdline,
94 void *opaque);
aliguori83ab7952008-08-19 14:44:22 +000095
aliguori731b0362009-03-05 23:01:42 +000096static void monitor_read_command(Monitor *mon, int show_prompt)
97{
98 readline_start(mon->rs, "(qemu) ", 0, monitor_command_cb, NULL);
99 if (show_prompt)
100 readline_show_prompt(mon->rs);
101}
bellard6a00d602005-11-21 23:25:50 +0000102
aliguoricde76ee2009-03-05 23:01:51 +0000103static int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func,
104 void *opaque)
aliguoribb5fc202009-03-05 23:01:15 +0000105{
aliguoricde76ee2009-03-05 23:01:51 +0000106 if (mon->rs) {
107 readline_start(mon->rs, "Password: ", 1, readline_func, opaque);
108 /* prompt is printed on return from the command handler */
109 return 0;
110 } else {
111 monitor_printf(mon, "terminal does not support password prompting\n");
112 return -ENOTTY;
113 }
aliguoribb5fc202009-03-05 23:01:15 +0000114}
115
aliguori376253e2009-03-05 23:01:23 +0000116void monitor_flush(Monitor *mon)
bellard9dc39cb2004-03-14 21:38:27 +0000117{
aliguori731b0362009-03-05 23:01:42 +0000118 if (mon && mon->outbuf_index != 0 && mon->chr->focus == 0) {
119 qemu_chr_write(mon->chr, mon->outbuf, mon->outbuf_index);
120 mon->outbuf_index = 0;
bellard7e2515e2004-08-01 21:52:19 +0000121 }
122}
123
124/* flush at every end of line or if the buffer is full */
aliguori376253e2009-03-05 23:01:23 +0000125static void monitor_puts(Monitor *mon, const char *str)
bellard7e2515e2004-08-01 21:52:19 +0000126{
ths60fe76f2007-12-16 03:02:09 +0000127 char c;
aliguori731b0362009-03-05 23:01:42 +0000128
129 if (!mon)
130 return;
131
bellard7e2515e2004-08-01 21:52:19 +0000132 for(;;) {
133 c = *str++;
134 if (c == '\0')
135 break;
bellard7ba12602006-07-14 20:26:42 +0000136 if (c == '\n')
aliguori731b0362009-03-05 23:01:42 +0000137 mon->outbuf[mon->outbuf_index++] = '\r';
138 mon->outbuf[mon->outbuf_index++] = c;
139 if (mon->outbuf_index >= (sizeof(mon->outbuf) - 1)
140 || c == '\n')
aliguori376253e2009-03-05 23:01:23 +0000141 monitor_flush(mon);
bellard7e2515e2004-08-01 21:52:19 +0000142 }
143}
144
aliguori376253e2009-03-05 23:01:23 +0000145void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
bellard7e2515e2004-08-01 21:52:19 +0000146{
147 char buf[4096];
148 vsnprintf(buf, sizeof(buf), fmt, ap);
aliguori376253e2009-03-05 23:01:23 +0000149 monitor_puts(mon, buf);
bellard7e2515e2004-08-01 21:52:19 +0000150}
151
aliguori376253e2009-03-05 23:01:23 +0000152void monitor_printf(Monitor *mon, const char *fmt, ...)
bellard7e2515e2004-08-01 21:52:19 +0000153{
154 va_list ap;
155 va_start(ap, fmt);
aliguori376253e2009-03-05 23:01:23 +0000156 monitor_vprintf(mon, fmt, ap);
bellard7e2515e2004-08-01 21:52:19 +0000157 va_end(ap);
bellard9dc39cb2004-03-14 21:38:27 +0000158}
159
aliguori376253e2009-03-05 23:01:23 +0000160void monitor_print_filename(Monitor *mon, const char *filename)
thsfef30742006-12-22 14:11:32 +0000161{
162 int i;
163
164 for (i = 0; filename[i]; i++) {
aliguori28a76be2009-03-06 20:27:40 +0000165 switch (filename[i]) {
166 case ' ':
167 case '"':
168 case '\\':
169 monitor_printf(mon, "\\%c", filename[i]);
170 break;
171 case '\t':
172 monitor_printf(mon, "\\t");
173 break;
174 case '\r':
175 monitor_printf(mon, "\\r");
176 break;
177 case '\n':
178 monitor_printf(mon, "\\n");
179 break;
180 default:
181 monitor_printf(mon, "%c", filename[i]);
182 break;
183 }
thsfef30742006-12-22 14:11:32 +0000184 }
185}
186
bellard7fe48482004-10-09 18:08:01 +0000187static int monitor_fprintf(FILE *stream, const char *fmt, ...)
188{
189 va_list ap;
190 va_start(ap, fmt);
aliguori376253e2009-03-05 23:01:23 +0000191 monitor_vprintf((Monitor *)stream, fmt, ap);
bellard7fe48482004-10-09 18:08:01 +0000192 va_end(ap);
193 return 0;
194}
195
bellard9dc39cb2004-03-14 21:38:27 +0000196static int compare_cmd(const char *name, const char *list)
197{
198 const char *p, *pstart;
199 int len;
200 len = strlen(name);
201 p = list;
202 for(;;) {
203 pstart = p;
204 p = strchr(p, '|');
205 if (!p)
206 p = pstart + strlen(pstart);
207 if ((p - pstart) == len && !memcmp(pstart, name, len))
208 return 1;
209 if (*p == '\0')
210 break;
211 p++;
212 }
213 return 0;
214}
215
aliguori376253e2009-03-05 23:01:23 +0000216static void help_cmd_dump(Monitor *mon, const mon_cmd_t *cmds,
217 const char *prefix, const char *name)
bellard9dc39cb2004-03-14 21:38:27 +0000218{
aliguori376253e2009-03-05 23:01:23 +0000219 const mon_cmd_t *cmd;
bellard9dc39cb2004-03-14 21:38:27 +0000220
221 for(cmd = cmds; cmd->name != NULL; cmd++) {
222 if (!name || !strcmp(name, cmd->name))
aliguori376253e2009-03-05 23:01:23 +0000223 monitor_printf(mon, "%s%s %s -- %s\n", prefix, cmd->name,
224 cmd->params, cmd->help);
bellard9dc39cb2004-03-14 21:38:27 +0000225 }
226}
227
aliguori376253e2009-03-05 23:01:23 +0000228static void help_cmd(Monitor *mon, const char *name)
bellard9dc39cb2004-03-14 21:38:27 +0000229{
230 if (name && !strcmp(name, "info")) {
aliguori376253e2009-03-05 23:01:23 +0000231 help_cmd_dump(mon, info_cmds, "info ", NULL);
bellard9dc39cb2004-03-14 21:38:27 +0000232 } else {
aliguori376253e2009-03-05 23:01:23 +0000233 help_cmd_dump(mon, mon_cmds, "", name);
bellardf193c792004-03-21 17:06:25 +0000234 if (name && !strcmp(name, "log")) {
blueswir18662d652008-10-02 18:32:44 +0000235 const CPULogItem *item;
aliguori376253e2009-03-05 23:01:23 +0000236 monitor_printf(mon, "Log items (comma separated):\n");
237 monitor_printf(mon, "%-10s %s\n", "none", "remove all logs");
bellardf193c792004-03-21 17:06:25 +0000238 for(item = cpu_log_items; item->mask != 0; item++) {
aliguori376253e2009-03-05 23:01:23 +0000239 monitor_printf(mon, "%-10s %s\n", item->name, item->help);
bellardf193c792004-03-21 17:06:25 +0000240 }
241 }
bellard9dc39cb2004-03-14 21:38:27 +0000242 }
243}
244
aliguori376253e2009-03-05 23:01:23 +0000245static void do_commit(Monitor *mon, const char *device)
bellard9dc39cb2004-03-14 21:38:27 +0000246{
bellard7954c732006-08-01 15:52:40 +0000247 int i, all_devices;
balrog2dc7b602007-05-24 18:53:22 +0000248
bellard7954c732006-08-01 15:52:40 +0000249 all_devices = !strcmp(device, "all");
thse4bcb142007-12-02 04:51:10 +0000250 for (i = 0; i < nb_drives; i++) {
ths5fafdf22007-09-16 21:08:06 +0000251 if (all_devices ||
thse4bcb142007-12-02 04:51:10 +0000252 !strcmp(bdrv_get_device_name(drives_table[i].bdrv), device))
253 bdrv_commit(drives_table[i].bdrv);
bellard9dc39cb2004-03-14 21:38:27 +0000254 }
255}
256
aliguori376253e2009-03-05 23:01:23 +0000257static void do_info(Monitor *mon, const char *item)
bellard9dc39cb2004-03-14 21:38:27 +0000258{
aliguori376253e2009-03-05 23:01:23 +0000259 const mon_cmd_t *cmd;
260 void (*handler)(Monitor *);
bellard9dc39cb2004-03-14 21:38:27 +0000261
bellard9307c4c2004-04-04 12:57:25 +0000262 if (!item)
bellard9dc39cb2004-03-14 21:38:27 +0000263 goto help;
bellard9dc39cb2004-03-14 21:38:27 +0000264 for(cmd = info_cmds; cmd->name != NULL; cmd++) {
ths5fafdf22007-09-16 21:08:06 +0000265 if (compare_cmd(item, cmd->name))
bellard9dc39cb2004-03-14 21:38:27 +0000266 goto found;
267 }
268 help:
aliguori376253e2009-03-05 23:01:23 +0000269 help_cmd(mon, "info");
bellard9dc39cb2004-03-14 21:38:27 +0000270 return;
271 found:
blueswir1a5f1b962008-08-17 20:21:51 +0000272 handler = cmd->handler;
aliguori376253e2009-03-05 23:01:23 +0000273 handler(mon);
bellard9dc39cb2004-03-14 21:38:27 +0000274}
275
aliguori376253e2009-03-05 23:01:23 +0000276static void do_info_version(Monitor *mon)
bellard9bc9d1c2004-10-10 15:15:51 +0000277{
pbrook4a19f1e2009-04-07 23:17:49 +0000278 monitor_printf(mon, "%s\n", QEMU_VERSION QEMU_PKGVERSION);
bellard9bc9d1c2004-10-10 15:15:51 +0000279}
280
aliguori376253e2009-03-05 23:01:23 +0000281static void do_info_name(Monitor *mon)
thsc35734b2007-03-19 15:17:08 +0000282{
283 if (qemu_name)
aliguori376253e2009-03-05 23:01:23 +0000284 monitor_printf(mon, "%s\n", qemu_name);
thsc35734b2007-03-19 15:17:08 +0000285}
286
aurel32bf4f74c2008-12-18 22:42:34 +0000287#if defined(TARGET_I386)
aliguori376253e2009-03-05 23:01:23 +0000288static void do_info_hpet(Monitor *mon)
aliguori16b29ae2008-12-17 23:28:44 +0000289{
aliguori376253e2009-03-05 23:01:23 +0000290 monitor_printf(mon, "HPET is %s by QEMU\n",
291 (no_hpet) ? "disabled" : "enabled");
aliguori16b29ae2008-12-17 23:28:44 +0000292}
aurel32bf4f74c2008-12-18 22:42:34 +0000293#endif
aliguori16b29ae2008-12-17 23:28:44 +0000294
aliguori376253e2009-03-05 23:01:23 +0000295static void do_info_uuid(Monitor *mon)
blueswir1f1f23ad2008-09-18 18:30:20 +0000296{
aliguori376253e2009-03-05 23:01:23 +0000297 monitor_printf(mon, UUID_FMT "\n", qemu_uuid[0], qemu_uuid[1],
298 qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5],
299 qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9],
300 qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13],
301 qemu_uuid[14], qemu_uuid[15]);
thsa36e69d2007-12-02 05:18:19 +0000302}
303
bellard6a00d602005-11-21 23:25:50 +0000304/* get the current CPU defined by the user */
pbrook9596ebb2007-11-18 01:44:38 +0000305static int mon_set_cpu(int cpu_index)
bellard6a00d602005-11-21 23:25:50 +0000306{
307 CPUState *env;
308
309 for(env = first_cpu; env != NULL; env = env->next_cpu) {
310 if (env->cpu_index == cpu_index) {
aliguori731b0362009-03-05 23:01:42 +0000311 cur_mon->mon_cpu = env;
bellard6a00d602005-11-21 23:25:50 +0000312 return 0;
313 }
314 }
315 return -1;
316}
317
pbrook9596ebb2007-11-18 01:44:38 +0000318static CPUState *mon_get_cpu(void)
bellard6a00d602005-11-21 23:25:50 +0000319{
aliguori731b0362009-03-05 23:01:42 +0000320 if (!cur_mon->mon_cpu) {
bellard6a00d602005-11-21 23:25:50 +0000321 mon_set_cpu(0);
322 }
aliguorid1546152009-03-12 20:12:57 +0000323 cpu_synchronize_state(cur_mon->mon_cpu, 0);
aliguori731b0362009-03-05 23:01:42 +0000324 return cur_mon->mon_cpu;
bellard6a00d602005-11-21 23:25:50 +0000325}
326
aliguori376253e2009-03-05 23:01:23 +0000327static void do_info_registers(Monitor *mon)
bellard9307c4c2004-04-04 12:57:25 +0000328{
bellard6a00d602005-11-21 23:25:50 +0000329 CPUState *env;
330 env = mon_get_cpu();
331 if (!env)
332 return;
bellard9307c4c2004-04-04 12:57:25 +0000333#ifdef TARGET_I386
aliguori376253e2009-03-05 23:01:23 +0000334 cpu_dump_state(env, (FILE *)mon, monitor_fprintf,
bellardd24b15a2005-07-03 21:28:00 +0000335 X86_DUMP_FPU);
bellard9307c4c2004-04-04 12:57:25 +0000336#else
aliguori376253e2009-03-05 23:01:23 +0000337 cpu_dump_state(env, (FILE *)mon, monitor_fprintf,
bellard7fe48482004-10-09 18:08:01 +0000338 0);
bellard9307c4c2004-04-04 12:57:25 +0000339#endif
340}
341
aliguori376253e2009-03-05 23:01:23 +0000342static void do_info_cpus(Monitor *mon)
bellard6a00d602005-11-21 23:25:50 +0000343{
344 CPUState *env;
345
346 /* just to set the default cpu if not already done */
347 mon_get_cpu();
348
349 for(env = first_cpu; env != NULL; env = env->next_cpu) {
aliguorid1546152009-03-12 20:12:57 +0000350 cpu_synchronize_state(env, 0);
aliguori376253e2009-03-05 23:01:23 +0000351 monitor_printf(mon, "%c CPU #%d:",
aliguori731b0362009-03-05 23:01:42 +0000352 (env == mon->mon_cpu) ? '*' : ' ',
aliguori376253e2009-03-05 23:01:23 +0000353 env->cpu_index);
bellard6a00d602005-11-21 23:25:50 +0000354#if defined(TARGET_I386)
aliguori376253e2009-03-05 23:01:23 +0000355 monitor_printf(mon, " pc=0x" TARGET_FMT_lx,
356 env->eip + env->segs[R_CS].base);
bellarde80e1cc2005-11-23 22:05:28 +0000357#elif defined(TARGET_PPC)
aliguori376253e2009-03-05 23:01:23 +0000358 monitor_printf(mon, " nip=0x" TARGET_FMT_lx, env->nip);
bellardba3c64f2005-12-05 20:31:52 +0000359#elif defined(TARGET_SPARC)
aliguori376253e2009-03-05 23:01:23 +0000360 monitor_printf(mon, " pc=0x" TARGET_FMT_lx " npc=0x" TARGET_FMT_lx,
361 env->pc, env->npc);
thsead93602007-09-06 00:18:15 +0000362#elif defined(TARGET_MIPS)
aliguori376253e2009-03-05 23:01:23 +0000363 monitor_printf(mon, " PC=0x" TARGET_FMT_lx, env->active_tc.PC);
bellardce5232c2008-05-28 17:14:10 +0000364#endif
thsead93602007-09-06 00:18:15 +0000365 if (env->halted)
aliguori376253e2009-03-05 23:01:23 +0000366 monitor_printf(mon, " (halted)");
367 monitor_printf(mon, "\n");
bellard6a00d602005-11-21 23:25:50 +0000368 }
369}
370
aliguori376253e2009-03-05 23:01:23 +0000371static void do_cpu_set(Monitor *mon, int index)
bellard6a00d602005-11-21 23:25:50 +0000372{
373 if (mon_set_cpu(index) < 0)
aliguori376253e2009-03-05 23:01:23 +0000374 monitor_printf(mon, "Invalid CPU index\n");
bellard6a00d602005-11-21 23:25:50 +0000375}
376
aliguori376253e2009-03-05 23:01:23 +0000377static void do_info_jit(Monitor *mon)
bellarde3db7222005-01-26 22:00:47 +0000378{
aliguori376253e2009-03-05 23:01:23 +0000379 dump_exec_info((FILE *)mon, monitor_fprintf);
bellarde3db7222005-01-26 22:00:47 +0000380}
381
aliguori376253e2009-03-05 23:01:23 +0000382static void do_info_history(Monitor *mon)
bellardaa455482004-04-04 13:07:25 +0000383{
384 int i;
bellard7e2515e2004-08-01 21:52:19 +0000385 const char *str;
ths3b46e622007-09-17 08:09:54 +0000386
aliguoricde76ee2009-03-05 23:01:51 +0000387 if (!mon->rs)
388 return;
bellard7e2515e2004-08-01 21:52:19 +0000389 i = 0;
390 for(;;) {
aliguori731b0362009-03-05 23:01:42 +0000391 str = readline_get_history(mon->rs, i);
bellard7e2515e2004-08-01 21:52:19 +0000392 if (!str)
393 break;
aliguori376253e2009-03-05 23:01:23 +0000394 monitor_printf(mon, "%d: '%s'\n", i, str);
bellard8e3a9fd2004-10-09 17:32:58 +0000395 i++;
bellardaa455482004-04-04 13:07:25 +0000396 }
397}
398
j_mayer76a66252007-03-07 08:32:30 +0000399#if defined(TARGET_PPC)
400/* XXX: not implemented in other targets */
aliguori376253e2009-03-05 23:01:23 +0000401static void do_info_cpu_stats(Monitor *mon)
j_mayer76a66252007-03-07 08:32:30 +0000402{
403 CPUState *env;
404
405 env = mon_get_cpu();
aliguori376253e2009-03-05 23:01:23 +0000406 cpu_dump_statistics(env, (FILE *)mon, &monitor_fprintf, 0);
j_mayer76a66252007-03-07 08:32:30 +0000407}
408#endif
409
aliguori376253e2009-03-05 23:01:23 +0000410static void do_quit(Monitor *mon)
bellard9dc39cb2004-03-14 21:38:27 +0000411{
412 exit(0);
413}
414
aliguori376253e2009-03-05 23:01:23 +0000415static int eject_device(Monitor *mon, BlockDriverState *bs, int force)
bellard9dc39cb2004-03-14 21:38:27 +0000416{
417 if (bdrv_is_inserted(bs)) {
418 if (!force) {
419 if (!bdrv_is_removable(bs)) {
aliguori376253e2009-03-05 23:01:23 +0000420 monitor_printf(mon, "device is not removable\n");
bellard9dc39cb2004-03-14 21:38:27 +0000421 return -1;
422 }
423 if (bdrv_is_locked(bs)) {
aliguori376253e2009-03-05 23:01:23 +0000424 monitor_printf(mon, "device is locked\n");
bellard9dc39cb2004-03-14 21:38:27 +0000425 return -1;
426 }
427 }
428 bdrv_close(bs);
429 }
430 return 0;
431}
432
aliguori376253e2009-03-05 23:01:23 +0000433static void do_eject(Monitor *mon, int force, const char *filename)
bellard9dc39cb2004-03-14 21:38:27 +0000434{
435 BlockDriverState *bs;
bellard9dc39cb2004-03-14 21:38:27 +0000436
bellard9307c4c2004-04-04 12:57:25 +0000437 bs = bdrv_find(filename);
bellard9dc39cb2004-03-14 21:38:27 +0000438 if (!bs) {
aliguori376253e2009-03-05 23:01:23 +0000439 monitor_printf(mon, "device not found\n");
bellard9dc39cb2004-03-14 21:38:27 +0000440 return;
441 }
aliguori376253e2009-03-05 23:01:23 +0000442 eject_device(mon, bs, force);
bellard9dc39cb2004-03-14 21:38:27 +0000443}
444
aliguori376253e2009-03-05 23:01:23 +0000445static void do_change_block(Monitor *mon, const char *device,
446 const char *filename, const char *fmt)
bellard9dc39cb2004-03-14 21:38:27 +0000447{
448 BlockDriverState *bs;
aurel322ecea9b2008-06-18 22:10:01 +0000449 BlockDriver *drv = NULL;
bellard9dc39cb2004-03-14 21:38:27 +0000450
bellard9307c4c2004-04-04 12:57:25 +0000451 bs = bdrv_find(device);
bellard9dc39cb2004-03-14 21:38:27 +0000452 if (!bs) {
aliguori376253e2009-03-05 23:01:23 +0000453 monitor_printf(mon, "device not found\n");
bellard9dc39cb2004-03-14 21:38:27 +0000454 return;
455 }
aurel322ecea9b2008-06-18 22:10:01 +0000456 if (fmt) {
457 drv = bdrv_find_format(fmt);
458 if (!drv) {
aliguori376253e2009-03-05 23:01:23 +0000459 monitor_printf(mon, "invalid format %s\n", fmt);
aurel322ecea9b2008-06-18 22:10:01 +0000460 return;
461 }
462 }
aliguori376253e2009-03-05 23:01:23 +0000463 if (eject_device(mon, bs, 0) < 0)
bellard9dc39cb2004-03-14 21:38:27 +0000464 return;
aurel322ecea9b2008-06-18 22:10:01 +0000465 bdrv_open2(bs, filename, 0, drv);
aliguori376253e2009-03-05 23:01:23 +0000466 monitor_read_bdrv_key_start(mon, bs, NULL, NULL);
aliguoribb5fc202009-03-05 23:01:15 +0000467}
468
aliguori376253e2009-03-05 23:01:23 +0000469static void change_vnc_password_cb(Monitor *mon, const char *password,
470 void *opaque)
aliguoribb5fc202009-03-05 23:01:15 +0000471{
472 if (vnc_display_password(NULL, password) < 0)
aliguori376253e2009-03-05 23:01:23 +0000473 monitor_printf(mon, "could not set VNC server password\n");
aliguoribb5fc202009-03-05 23:01:15 +0000474
aliguori731b0362009-03-05 23:01:42 +0000475 monitor_read_command(mon, 1);
bellard9dc39cb2004-03-14 21:38:27 +0000476}
477
aliguori376253e2009-03-05 23:01:23 +0000478static void do_change_vnc(Monitor *mon, const char *target, const char *arg)
thse25a5822007-08-25 01:36:20 +0000479{
ths70848512007-08-25 01:37:05 +0000480 if (strcmp(target, "passwd") == 0 ||
aliguori28a76be2009-03-06 20:27:40 +0000481 strcmp(target, "password") == 0) {
482 if (arg) {
aliguoribb5fc202009-03-05 23:01:15 +0000483 char password[9];
aliguori28a76be2009-03-06 20:27:40 +0000484 strncpy(password, arg, sizeof(password));
485 password[sizeof(password) - 1] = '\0';
aliguori376253e2009-03-05 23:01:23 +0000486 change_vnc_password_cb(mon, password, NULL);
aliguoribb5fc202009-03-05 23:01:15 +0000487 } else {
aliguori376253e2009-03-05 23:01:23 +0000488 monitor_read_password(mon, change_vnc_password_cb, NULL);
aliguoribb5fc202009-03-05 23:01:15 +0000489 }
ths70848512007-08-25 01:37:05 +0000490 } else {
aliguori28a76be2009-03-06 20:27:40 +0000491 if (vnc_display_open(NULL, target) < 0)
aliguori376253e2009-03-05 23:01:23 +0000492 monitor_printf(mon, "could not start VNC server on %s\n", target);
ths70848512007-08-25 01:37:05 +0000493 }
thse25a5822007-08-25 01:36:20 +0000494}
495
aliguori376253e2009-03-05 23:01:23 +0000496static void do_change(Monitor *mon, const char *device, const char *target,
497 const char *arg)
thse25a5822007-08-25 01:36:20 +0000498{
499 if (strcmp(device, "vnc") == 0) {
aliguori28a76be2009-03-06 20:27:40 +0000500 do_change_vnc(mon, target, arg);
thse25a5822007-08-25 01:36:20 +0000501 } else {
aliguori28a76be2009-03-06 20:27:40 +0000502 do_change_block(mon, device, target, arg);
thse25a5822007-08-25 01:36:20 +0000503 }
504}
505
aliguori376253e2009-03-05 23:01:23 +0000506static void do_screen_dump(Monitor *mon, const char *filename)
bellard59a983b2004-03-17 23:17:16 +0000507{
pbrook95219892006-04-09 01:06:34 +0000508 vga_hw_screen_dump(filename);
bellard59a983b2004-03-17 23:17:16 +0000509}
510
aliguori376253e2009-03-05 23:01:23 +0000511static void do_logfile(Monitor *mon, const char *filename)
pbrooke735b912007-06-30 13:53:24 +0000512{
513 cpu_set_log_filename(filename);
514}
515
aliguori376253e2009-03-05 23:01:23 +0000516static void do_log(Monitor *mon, const char *items)
bellardf193c792004-03-21 17:06:25 +0000517{
518 int mask;
ths3b46e622007-09-17 08:09:54 +0000519
bellard9307c4c2004-04-04 12:57:25 +0000520 if (!strcmp(items, "none")) {
bellardf193c792004-03-21 17:06:25 +0000521 mask = 0;
522 } else {
bellard9307c4c2004-04-04 12:57:25 +0000523 mask = cpu_str_to_log_mask(items);
bellardf193c792004-03-21 17:06:25 +0000524 if (!mask) {
aliguori376253e2009-03-05 23:01:23 +0000525 help_cmd(mon, "log");
bellardf193c792004-03-21 17:06:25 +0000526 return;
527 }
528 }
529 cpu_set_log(mask);
530}
531
aurel321b530a62009-04-05 20:08:59 +0000532static void do_singlestep(Monitor *mon, const char *option)
533{
534 if (!option || !strcmp(option, "on")) {
535 singlestep = 1;
536 } else if (!strcmp(option, "off")) {
537 singlestep = 0;
538 } else {
539 monitor_printf(mon, "unexpected option %s\n", option);
540 }
541}
542
aliguori376253e2009-03-05 23:01:23 +0000543static void do_stop(Monitor *mon)
bellard8a7ddc32004-03-31 19:00:16 +0000544{
545 vm_stop(EXCP_INTERRUPT);
546}
547
aliguoribb5fc202009-03-05 23:01:15 +0000548static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs);
aliguoric0f4ce72009-03-05 23:01:01 +0000549
aliguori376253e2009-03-05 23:01:23 +0000550struct bdrv_iterate_context {
551 Monitor *mon;
552 int err;
553};
aliguoric0f4ce72009-03-05 23:01:01 +0000554
aliguori376253e2009-03-05 23:01:23 +0000555static void do_cont(Monitor *mon)
556{
557 struct bdrv_iterate_context context = { mon, 0 };
558
559 bdrv_iterate(encrypted_bdrv_it, &context);
aliguoric0f4ce72009-03-05 23:01:01 +0000560 /* only resume the vm if all keys are set and valid */
aliguori376253e2009-03-05 23:01:23 +0000561 if (!context.err)
aliguoric0f4ce72009-03-05 23:01:01 +0000562 vm_start();
bellard8a7ddc32004-03-31 19:00:16 +0000563}
564
aliguoribb5fc202009-03-05 23:01:15 +0000565static void bdrv_key_cb(void *opaque, int err)
566{
aliguori376253e2009-03-05 23:01:23 +0000567 Monitor *mon = opaque;
568
aliguoribb5fc202009-03-05 23:01:15 +0000569 /* another key was set successfully, retry to continue */
570 if (!err)
aliguori376253e2009-03-05 23:01:23 +0000571 do_cont(mon);
aliguoribb5fc202009-03-05 23:01:15 +0000572}
573
574static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs)
575{
aliguori376253e2009-03-05 23:01:23 +0000576 struct bdrv_iterate_context *context = opaque;
aliguoribb5fc202009-03-05 23:01:15 +0000577
aliguori376253e2009-03-05 23:01:23 +0000578 if (!context->err && bdrv_key_required(bs)) {
579 context->err = -EBUSY;
580 monitor_read_bdrv_key_start(context->mon, bs, bdrv_key_cb,
581 context->mon);
aliguoribb5fc202009-03-05 23:01:15 +0000582 }
583}
584
aliguori59030a82009-04-05 18:43:41 +0000585static void do_gdbserver(Monitor *mon, const char *device)
bellard8a7ddc32004-03-31 19:00:16 +0000586{
aliguori59030a82009-04-05 18:43:41 +0000587 if (!device)
588 device = "tcp::" DEFAULT_GDBSTUB_PORT;
589 if (gdbserver_start(device) < 0) {
590 monitor_printf(mon, "Could not open gdbserver on device '%s'\n",
591 device);
592 } else if (strcmp(device, "none") == 0) {
aliguori36556b22009-03-28 18:05:53 +0000593 monitor_printf(mon, "Disabled gdbserver\n");
bellard8a7ddc32004-03-31 19:00:16 +0000594 } else {
aliguori59030a82009-04-05 18:43:41 +0000595 monitor_printf(mon, "Waiting for gdb connection on device '%s'\n",
596 device);
bellard8a7ddc32004-03-31 19:00:16 +0000597 }
598}
599
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +0100600static void do_watchdog_action(Monitor *mon, const char *action)
601{
602 if (select_watchdog_action(action) == -1) {
603 monitor_printf(mon, "Unknown watchdog action '%s'\n", action);
604 }
605}
606
aliguori376253e2009-03-05 23:01:23 +0000607static void monitor_printc(Monitor *mon, int c)
bellard9307c4c2004-04-04 12:57:25 +0000608{
aliguori376253e2009-03-05 23:01:23 +0000609 monitor_printf(mon, "'");
bellard9307c4c2004-04-04 12:57:25 +0000610 switch(c) {
611 case '\'':
aliguori376253e2009-03-05 23:01:23 +0000612 monitor_printf(mon, "\\'");
bellard9307c4c2004-04-04 12:57:25 +0000613 break;
614 case '\\':
aliguori376253e2009-03-05 23:01:23 +0000615 monitor_printf(mon, "\\\\");
bellard9307c4c2004-04-04 12:57:25 +0000616 break;
617 case '\n':
aliguori376253e2009-03-05 23:01:23 +0000618 monitor_printf(mon, "\\n");
bellard9307c4c2004-04-04 12:57:25 +0000619 break;
620 case '\r':
aliguori376253e2009-03-05 23:01:23 +0000621 monitor_printf(mon, "\\r");
bellard9307c4c2004-04-04 12:57:25 +0000622 break;
623 default:
624 if (c >= 32 && c <= 126) {
aliguori376253e2009-03-05 23:01:23 +0000625 monitor_printf(mon, "%c", c);
bellard9307c4c2004-04-04 12:57:25 +0000626 } else {
aliguori376253e2009-03-05 23:01:23 +0000627 monitor_printf(mon, "\\x%02x", c);
bellard9307c4c2004-04-04 12:57:25 +0000628 }
629 break;
630 }
aliguori376253e2009-03-05 23:01:23 +0000631 monitor_printf(mon, "'");
bellard9307c4c2004-04-04 12:57:25 +0000632}
633
aliguori376253e2009-03-05 23:01:23 +0000634static void memory_dump(Monitor *mon, int count, int format, int wsize,
blueswir17743e582007-09-24 18:39:04 +0000635 target_phys_addr_t addr, int is_physical)
bellard9307c4c2004-04-04 12:57:25 +0000636{
bellard6a00d602005-11-21 23:25:50 +0000637 CPUState *env;
bellard9307c4c2004-04-04 12:57:25 +0000638 int nb_per_line, l, line_size, i, max_digits, len;
639 uint8_t buf[16];
640 uint64_t v;
641
642 if (format == 'i') {
643 int flags;
644 flags = 0;
bellard6a00d602005-11-21 23:25:50 +0000645 env = mon_get_cpu();
646 if (!env && !is_physical)
647 return;
bellard9307c4c2004-04-04 12:57:25 +0000648#ifdef TARGET_I386
bellard4c27ba22004-04-25 18:05:08 +0000649 if (wsize == 2) {
bellard9307c4c2004-04-04 12:57:25 +0000650 flags = 1;
bellard4c27ba22004-04-25 18:05:08 +0000651 } else if (wsize == 4) {
652 flags = 0;
653 } else {
bellard6a15fd12006-04-12 21:07:07 +0000654 /* as default we use the current CS size */
bellard4c27ba22004-04-25 18:05:08 +0000655 flags = 0;
bellard6a15fd12006-04-12 21:07:07 +0000656 if (env) {
657#ifdef TARGET_X86_64
ths5fafdf22007-09-16 21:08:06 +0000658 if ((env->efer & MSR_EFER_LMA) &&
bellard6a15fd12006-04-12 21:07:07 +0000659 (env->segs[R_CS].flags & DESC_L_MASK))
660 flags = 2;
661 else
662#endif
663 if (!(env->segs[R_CS].flags & DESC_B_MASK))
664 flags = 1;
665 }
bellard4c27ba22004-04-25 18:05:08 +0000666 }
667#endif
aliguori376253e2009-03-05 23:01:23 +0000668 monitor_disas(mon, env, addr, count, is_physical, flags);
bellard9307c4c2004-04-04 12:57:25 +0000669 return;
670 }
671
672 len = wsize * count;
673 if (wsize == 1)
674 line_size = 8;
675 else
676 line_size = 16;
677 nb_per_line = line_size / wsize;
678 max_digits = 0;
679
680 switch(format) {
681 case 'o':
682 max_digits = (wsize * 8 + 2) / 3;
683 break;
684 default:
685 case 'x':
686 max_digits = (wsize * 8) / 4;
687 break;
688 case 'u':
689 case 'd':
690 max_digits = (wsize * 8 * 10 + 32) / 33;
691 break;
692 case 'c':
693 wsize = 1;
694 break;
695 }
696
697 while (len > 0) {
blueswir17743e582007-09-24 18:39:04 +0000698 if (is_physical)
aliguori376253e2009-03-05 23:01:23 +0000699 monitor_printf(mon, TARGET_FMT_plx ":", addr);
blueswir17743e582007-09-24 18:39:04 +0000700 else
aliguori376253e2009-03-05 23:01:23 +0000701 monitor_printf(mon, TARGET_FMT_lx ":", (target_ulong)addr);
bellard9307c4c2004-04-04 12:57:25 +0000702 l = len;
703 if (l > line_size)
704 l = line_size;
705 if (is_physical) {
706 cpu_physical_memory_rw(addr, buf, l, 0);
707 } else {
bellard6a00d602005-11-21 23:25:50 +0000708 env = mon_get_cpu();
709 if (!env)
710 break;
aliguoric8f79b62008-08-18 14:00:20 +0000711 if (cpu_memory_rw_debug(env, addr, buf, l, 0) < 0) {
aliguori376253e2009-03-05 23:01:23 +0000712 monitor_printf(mon, " Cannot access memory\n");
aliguoric8f79b62008-08-18 14:00:20 +0000713 break;
714 }
bellard9307c4c2004-04-04 12:57:25 +0000715 }
ths5fafdf22007-09-16 21:08:06 +0000716 i = 0;
bellard9307c4c2004-04-04 12:57:25 +0000717 while (i < l) {
718 switch(wsize) {
719 default:
720 case 1:
721 v = ldub_raw(buf + i);
722 break;
723 case 2:
724 v = lduw_raw(buf + i);
725 break;
726 case 4:
bellard92a31b12005-02-10 22:00:52 +0000727 v = (uint32_t)ldl_raw(buf + i);
bellard9307c4c2004-04-04 12:57:25 +0000728 break;
729 case 8:
730 v = ldq_raw(buf + i);
731 break;
732 }
aliguori376253e2009-03-05 23:01:23 +0000733 monitor_printf(mon, " ");
bellard9307c4c2004-04-04 12:57:25 +0000734 switch(format) {
735 case 'o':
aliguori376253e2009-03-05 23:01:23 +0000736 monitor_printf(mon, "%#*" PRIo64, max_digits, v);
bellard9307c4c2004-04-04 12:57:25 +0000737 break;
738 case 'x':
aliguori376253e2009-03-05 23:01:23 +0000739 monitor_printf(mon, "0x%0*" PRIx64, max_digits, v);
bellard9307c4c2004-04-04 12:57:25 +0000740 break;
741 case 'u':
aliguori376253e2009-03-05 23:01:23 +0000742 monitor_printf(mon, "%*" PRIu64, max_digits, v);
bellard9307c4c2004-04-04 12:57:25 +0000743 break;
744 case 'd':
aliguori376253e2009-03-05 23:01:23 +0000745 monitor_printf(mon, "%*" PRId64, max_digits, v);
bellard9307c4c2004-04-04 12:57:25 +0000746 break;
747 case 'c':
aliguori376253e2009-03-05 23:01:23 +0000748 monitor_printc(mon, v);
bellard9307c4c2004-04-04 12:57:25 +0000749 break;
750 }
751 i += wsize;
752 }
aliguori376253e2009-03-05 23:01:23 +0000753 monitor_printf(mon, "\n");
bellard9307c4c2004-04-04 12:57:25 +0000754 addr += l;
755 len -= l;
756 }
757}
758
bellard92a31b12005-02-10 22:00:52 +0000759#if TARGET_LONG_BITS == 64
760#define GET_TLONG(h, l) (((uint64_t)(h) << 32) | (l))
761#else
762#define GET_TLONG(h, l) (l)
763#endif
764
aliguori376253e2009-03-05 23:01:23 +0000765static void do_memory_dump(Monitor *mon, int count, int format, int size,
bellard92a31b12005-02-10 22:00:52 +0000766 uint32_t addrh, uint32_t addrl)
bellard9307c4c2004-04-04 12:57:25 +0000767{
bellard92a31b12005-02-10 22:00:52 +0000768 target_long addr = GET_TLONG(addrh, addrl);
aliguori376253e2009-03-05 23:01:23 +0000769 memory_dump(mon, count, format, size, addr, 0);
bellard9307c4c2004-04-04 12:57:25 +0000770}
771
blueswir17743e582007-09-24 18:39:04 +0000772#if TARGET_PHYS_ADDR_BITS > 32
773#define GET_TPHYSADDR(h, l) (((uint64_t)(h) << 32) | (l))
774#else
775#define GET_TPHYSADDR(h, l) (l)
776#endif
777
aliguori376253e2009-03-05 23:01:23 +0000778static void do_physical_memory_dump(Monitor *mon, int count, int format,
779 int size, uint32_t addrh, uint32_t addrl)
bellard92a31b12005-02-10 22:00:52 +0000780
bellard9307c4c2004-04-04 12:57:25 +0000781{
blueswir17743e582007-09-24 18:39:04 +0000782 target_phys_addr_t addr = GET_TPHYSADDR(addrh, addrl);
aliguori376253e2009-03-05 23:01:23 +0000783 memory_dump(mon, count, format, size, addr, 1);
bellard9307c4c2004-04-04 12:57:25 +0000784}
785
aliguori376253e2009-03-05 23:01:23 +0000786static void do_print(Monitor *mon, int count, int format, int size,
787 unsigned int valh, unsigned int vall)
bellard9307c4c2004-04-04 12:57:25 +0000788{
blueswir17743e582007-09-24 18:39:04 +0000789 target_phys_addr_t val = GET_TPHYSADDR(valh, vall);
790#if TARGET_PHYS_ADDR_BITS == 32
bellard9307c4c2004-04-04 12:57:25 +0000791 switch(format) {
792 case 'o':
aliguori376253e2009-03-05 23:01:23 +0000793 monitor_printf(mon, "%#o", val);
bellard9307c4c2004-04-04 12:57:25 +0000794 break;
795 case 'x':
aliguori376253e2009-03-05 23:01:23 +0000796 monitor_printf(mon, "%#x", val);
bellard9307c4c2004-04-04 12:57:25 +0000797 break;
798 case 'u':
aliguori376253e2009-03-05 23:01:23 +0000799 monitor_printf(mon, "%u", val);
bellard9307c4c2004-04-04 12:57:25 +0000800 break;
801 default:
802 case 'd':
aliguori376253e2009-03-05 23:01:23 +0000803 monitor_printf(mon, "%d", val);
bellard9307c4c2004-04-04 12:57:25 +0000804 break;
805 case 'c':
aliguori376253e2009-03-05 23:01:23 +0000806 monitor_printc(mon, val);
bellard9307c4c2004-04-04 12:57:25 +0000807 break;
808 }
bellard92a31b12005-02-10 22:00:52 +0000809#else
810 switch(format) {
811 case 'o':
aliguori376253e2009-03-05 23:01:23 +0000812 monitor_printf(mon, "%#" PRIo64, val);
bellard92a31b12005-02-10 22:00:52 +0000813 break;
814 case 'x':
aliguori376253e2009-03-05 23:01:23 +0000815 monitor_printf(mon, "%#" PRIx64, val);
bellard92a31b12005-02-10 22:00:52 +0000816 break;
817 case 'u':
aliguori376253e2009-03-05 23:01:23 +0000818 monitor_printf(mon, "%" PRIu64, val);
bellard92a31b12005-02-10 22:00:52 +0000819 break;
820 default:
821 case 'd':
aliguori376253e2009-03-05 23:01:23 +0000822 monitor_printf(mon, "%" PRId64, val);
bellard92a31b12005-02-10 22:00:52 +0000823 break;
824 case 'c':
aliguori376253e2009-03-05 23:01:23 +0000825 monitor_printc(mon, val);
bellard92a31b12005-02-10 22:00:52 +0000826 break;
827 }
828#endif
aliguori376253e2009-03-05 23:01:23 +0000829 monitor_printf(mon, "\n");
bellard9307c4c2004-04-04 12:57:25 +0000830}
831
aliguori376253e2009-03-05 23:01:23 +0000832static void do_memory_save(Monitor *mon, unsigned int valh, unsigned int vall,
bellardb371dc52007-01-03 15:20:39 +0000833 uint32_t size, const char *filename)
834{
835 FILE *f;
836 target_long addr = GET_TLONG(valh, vall);
837 uint32_t l;
838 CPUState *env;
839 uint8_t buf[1024];
840
841 env = mon_get_cpu();
842 if (!env)
843 return;
844
845 f = fopen(filename, "wb");
846 if (!f) {
aliguori376253e2009-03-05 23:01:23 +0000847 monitor_printf(mon, "could not open '%s'\n", filename);
bellardb371dc52007-01-03 15:20:39 +0000848 return;
849 }
850 while (size != 0) {
851 l = sizeof(buf);
852 if (l > size)
853 l = size;
854 cpu_memory_rw_debug(env, addr, buf, l, 0);
855 fwrite(buf, 1, l, f);
856 addr += l;
857 size -= l;
858 }
859 fclose(f);
860}
861
aliguori376253e2009-03-05 23:01:23 +0000862static void do_physical_memory_save(Monitor *mon, unsigned int valh,
863 unsigned int vall, uint32_t size,
864 const char *filename)
aurel32a8bdf7a2008-04-11 21:36:14 +0000865{
866 FILE *f;
867 uint32_t l;
868 uint8_t buf[1024];
aurel32339dea22008-04-12 20:14:43 +0000869 target_phys_addr_t addr = GET_TPHYSADDR(valh, vall);
aurel32a8bdf7a2008-04-11 21:36:14 +0000870
871 f = fopen(filename, "wb");
872 if (!f) {
aliguori376253e2009-03-05 23:01:23 +0000873 monitor_printf(mon, "could not open '%s'\n", filename);
aurel32a8bdf7a2008-04-11 21:36:14 +0000874 return;
875 }
876 while (size != 0) {
877 l = sizeof(buf);
878 if (l > size)
879 l = size;
880 cpu_physical_memory_rw(addr, buf, l, 0);
881 fwrite(buf, 1, l, f);
882 fflush(f);
883 addr += l;
884 size -= l;
885 }
886 fclose(f);
887}
888
aliguori376253e2009-03-05 23:01:23 +0000889static void do_sum(Monitor *mon, uint32_t start, uint32_t size)
bellarde4cf1ad2005-06-04 20:15:57 +0000890{
891 uint32_t addr;
892 uint8_t buf[1];
893 uint16_t sum;
894
895 sum = 0;
896 for(addr = start; addr < (start + size); addr++) {
897 cpu_physical_memory_rw(addr, buf, 1, 0);
898 /* BSD sum algorithm ('sum' Unix command) */
899 sum = (sum >> 1) | (sum << 15);
900 sum += buf[0];
901 }
aliguori376253e2009-03-05 23:01:23 +0000902 monitor_printf(mon, "%05d\n", sum);
bellarde4cf1ad2005-06-04 20:15:57 +0000903}
904
bellarda3a91a32004-06-04 11:06:21 +0000905typedef struct {
906 int keycode;
907 const char *name;
908} KeyDef;
909
910static const KeyDef key_defs[] = {
911 { 0x2a, "shift" },
912 { 0x36, "shift_r" },
ths3b46e622007-09-17 08:09:54 +0000913
bellarda3a91a32004-06-04 11:06:21 +0000914 { 0x38, "alt" },
915 { 0xb8, "alt_r" },
ths2ba27c72008-08-13 12:54:23 +0000916 { 0x64, "altgr" },
917 { 0xe4, "altgr_r" },
bellarda3a91a32004-06-04 11:06:21 +0000918 { 0x1d, "ctrl" },
919 { 0x9d, "ctrl_r" },
920
921 { 0xdd, "menu" },
922
923 { 0x01, "esc" },
924
925 { 0x02, "1" },
926 { 0x03, "2" },
927 { 0x04, "3" },
928 { 0x05, "4" },
929 { 0x06, "5" },
930 { 0x07, "6" },
931 { 0x08, "7" },
932 { 0x09, "8" },
933 { 0x0a, "9" },
934 { 0x0b, "0" },
bellard64866c32006-05-07 18:03:31 +0000935 { 0x0c, "minus" },
936 { 0x0d, "equal" },
bellarda3a91a32004-06-04 11:06:21 +0000937 { 0x0e, "backspace" },
938
939 { 0x0f, "tab" },
940 { 0x10, "q" },
941 { 0x11, "w" },
942 { 0x12, "e" },
943 { 0x13, "r" },
944 { 0x14, "t" },
945 { 0x15, "y" },
946 { 0x16, "u" },
947 { 0x17, "i" },
948 { 0x18, "o" },
949 { 0x19, "p" },
950
951 { 0x1c, "ret" },
952
953 { 0x1e, "a" },
954 { 0x1f, "s" },
955 { 0x20, "d" },
956 { 0x21, "f" },
957 { 0x22, "g" },
958 { 0x23, "h" },
959 { 0x24, "j" },
960 { 0x25, "k" },
961 { 0x26, "l" },
962
963 { 0x2c, "z" },
964 { 0x2d, "x" },
965 { 0x2e, "c" },
966 { 0x2f, "v" },
967 { 0x30, "b" },
968 { 0x31, "n" },
969 { 0x32, "m" },
aurel329155fc42008-10-01 21:46:15 +0000970 { 0x33, "comma" },
971 { 0x34, "dot" },
972 { 0x35, "slash" },
ths3b46e622007-09-17 08:09:54 +0000973
balrog4d3b6f62008-02-10 16:33:14 +0000974 { 0x37, "asterisk" },
975
bellarda3a91a32004-06-04 11:06:21 +0000976 { 0x39, "spc" },
bellard00ffa622004-06-04 13:25:15 +0000977 { 0x3a, "caps_lock" },
bellarda3a91a32004-06-04 11:06:21 +0000978 { 0x3b, "f1" },
979 { 0x3c, "f2" },
980 { 0x3d, "f3" },
981 { 0x3e, "f4" },
982 { 0x3f, "f5" },
983 { 0x40, "f6" },
984 { 0x41, "f7" },
985 { 0x42, "f8" },
986 { 0x43, "f9" },
987 { 0x44, "f10" },
bellard00ffa622004-06-04 13:25:15 +0000988 { 0x45, "num_lock" },
bellarda3a91a32004-06-04 11:06:21 +0000989 { 0x46, "scroll_lock" },
990
bellard64866c32006-05-07 18:03:31 +0000991 { 0xb5, "kp_divide" },
992 { 0x37, "kp_multiply" },
ths0cfec832007-06-23 16:02:43 +0000993 { 0x4a, "kp_subtract" },
bellard64866c32006-05-07 18:03:31 +0000994 { 0x4e, "kp_add" },
995 { 0x9c, "kp_enter" },
996 { 0x53, "kp_decimal" },
balrogf2289cb2008-06-04 10:14:16 +0000997 { 0x54, "sysrq" },
bellard64866c32006-05-07 18:03:31 +0000998
999 { 0x52, "kp_0" },
1000 { 0x4f, "kp_1" },
1001 { 0x50, "kp_2" },
1002 { 0x51, "kp_3" },
1003 { 0x4b, "kp_4" },
1004 { 0x4c, "kp_5" },
1005 { 0x4d, "kp_6" },
1006 { 0x47, "kp_7" },
1007 { 0x48, "kp_8" },
1008 { 0x49, "kp_9" },
ths3b46e622007-09-17 08:09:54 +00001009
bellarda3a91a32004-06-04 11:06:21 +00001010 { 0x56, "<" },
1011
1012 { 0x57, "f11" },
1013 { 0x58, "f12" },
1014
1015 { 0xb7, "print" },
1016
1017 { 0xc7, "home" },
1018 { 0xc9, "pgup" },
1019 { 0xd1, "pgdn" },
1020 { 0xcf, "end" },
1021
1022 { 0xcb, "left" },
1023 { 0xc8, "up" },
1024 { 0xd0, "down" },
1025 { 0xcd, "right" },
1026
1027 { 0xd2, "insert" },
1028 { 0xd3, "delete" },
blueswir1c0b5b102008-06-22 07:45:42 +00001029#if defined(TARGET_SPARC) && !defined(TARGET_SPARC64)
1030 { 0xf0, "stop" },
1031 { 0xf1, "again" },
1032 { 0xf2, "props" },
1033 { 0xf3, "undo" },
1034 { 0xf4, "front" },
1035 { 0xf5, "copy" },
1036 { 0xf6, "open" },
1037 { 0xf7, "paste" },
1038 { 0xf8, "find" },
1039 { 0xf9, "cut" },
1040 { 0xfa, "lf" },
1041 { 0xfb, "help" },
1042 { 0xfc, "meta_l" },
1043 { 0xfd, "meta_r" },
1044 { 0xfe, "compose" },
1045#endif
bellarda3a91a32004-06-04 11:06:21 +00001046 { 0, NULL },
1047};
1048
1049static int get_keycode(const char *key)
1050{
1051 const KeyDef *p;
bellard64866c32006-05-07 18:03:31 +00001052 char *endp;
1053 int ret;
bellarda3a91a32004-06-04 11:06:21 +00001054
1055 for(p = key_defs; p->name != NULL; p++) {
1056 if (!strcmp(key, p->name))
1057 return p->keycode;
1058 }
bellard64866c32006-05-07 18:03:31 +00001059 if (strstart(key, "0x", NULL)) {
1060 ret = strtoul(key, &endp, 0);
1061 if (*endp == '\0' && ret >= 0x01 && ret <= 0xff)
1062 return ret;
1063 }
bellarda3a91a32004-06-04 11:06:21 +00001064 return -1;
1065}
1066
balrogc8256f92008-06-08 22:45:01 +00001067#define MAX_KEYCODES 16
1068static uint8_t keycodes[MAX_KEYCODES];
1069static int nb_pending_keycodes;
1070static QEMUTimer *key_timer;
1071
1072static void release_keys(void *opaque)
bellarda3a91a32004-06-04 11:06:21 +00001073{
balrogc8256f92008-06-08 22:45:01 +00001074 int keycode;
1075
1076 while (nb_pending_keycodes > 0) {
1077 nb_pending_keycodes--;
1078 keycode = keycodes[nb_pending_keycodes];
1079 if (keycode & 0x80)
1080 kbd_put_keycode(0xe0);
1081 kbd_put_keycode(keycode | 0x80);
1082 }
1083}
1084
aliguori376253e2009-03-05 23:01:23 +00001085static void do_sendkey(Monitor *mon, const char *string, int has_hold_time,
1086 int hold_time)
balrogc8256f92008-06-08 22:45:01 +00001087{
balrog3401c0d2008-06-04 10:05:59 +00001088 char keyname_buf[16];
1089 char *separator;
1090 int keyname_len, keycode, i;
ths3b46e622007-09-17 08:09:54 +00001091
balrogc8256f92008-06-08 22:45:01 +00001092 if (nb_pending_keycodes > 0) {
1093 qemu_del_timer(key_timer);
1094 release_keys(NULL);
1095 }
1096 if (!has_hold_time)
1097 hold_time = 100;
1098 i = 0;
balrog3401c0d2008-06-04 10:05:59 +00001099 while (1) {
1100 separator = strchr(string, '-');
1101 keyname_len = separator ? separator - string : strlen(string);
1102 if (keyname_len > 0) {
1103 pstrcpy(keyname_buf, sizeof(keyname_buf), string);
1104 if (keyname_len > sizeof(keyname_buf) - 1) {
aliguori376253e2009-03-05 23:01:23 +00001105 monitor_printf(mon, "invalid key: '%s...'\n", keyname_buf);
balrog3401c0d2008-06-04 10:05:59 +00001106 return;
bellarda3a91a32004-06-04 11:06:21 +00001107 }
balrogc8256f92008-06-08 22:45:01 +00001108 if (i == MAX_KEYCODES) {
aliguori376253e2009-03-05 23:01:23 +00001109 monitor_printf(mon, "too many keys\n");
balrog3401c0d2008-06-04 10:05:59 +00001110 return;
1111 }
1112 keyname_buf[keyname_len] = 0;
1113 keycode = get_keycode(keyname_buf);
1114 if (keycode < 0) {
aliguori376253e2009-03-05 23:01:23 +00001115 monitor_printf(mon, "unknown key: '%s'\n", keyname_buf);
balrog3401c0d2008-06-04 10:05:59 +00001116 return;
1117 }
balrogc8256f92008-06-08 22:45:01 +00001118 keycodes[i++] = keycode;
bellarda3a91a32004-06-04 11:06:21 +00001119 }
balrog3401c0d2008-06-04 10:05:59 +00001120 if (!separator)
bellarda3a91a32004-06-04 11:06:21 +00001121 break;
balrog3401c0d2008-06-04 10:05:59 +00001122 string = separator + 1;
bellarda3a91a32004-06-04 11:06:21 +00001123 }
balrogc8256f92008-06-08 22:45:01 +00001124 nb_pending_keycodes = i;
bellarda3a91a32004-06-04 11:06:21 +00001125 /* key down events */
balrogc8256f92008-06-08 22:45:01 +00001126 for (i = 0; i < nb_pending_keycodes; i++) {
bellarda3a91a32004-06-04 11:06:21 +00001127 keycode = keycodes[i];
1128 if (keycode & 0x80)
1129 kbd_put_keycode(0xe0);
1130 kbd_put_keycode(keycode & 0x7f);
1131 }
balrogc8256f92008-06-08 22:45:01 +00001132 /* delayed key up events */
balrogf227f172008-06-09 00:03:47 +00001133 qemu_mod_timer(key_timer, qemu_get_clock(vm_clock) +
1134 muldiv64(ticks_per_sec, hold_time, 1000));
bellarda3a91a32004-06-04 11:06:21 +00001135}
1136
bellard13224a82006-07-14 22:03:35 +00001137static int mouse_button_state;
1138
aliguori376253e2009-03-05 23:01:23 +00001139static void do_mouse_move(Monitor *mon, const char *dx_str, const char *dy_str,
bellard13224a82006-07-14 22:03:35 +00001140 const char *dz_str)
1141{
1142 int dx, dy, dz;
1143 dx = strtol(dx_str, NULL, 0);
1144 dy = strtol(dy_str, NULL, 0);
1145 dz = 0;
ths5fafdf22007-09-16 21:08:06 +00001146 if (dz_str)
bellard13224a82006-07-14 22:03:35 +00001147 dz = strtol(dz_str, NULL, 0);
1148 kbd_mouse_event(dx, dy, dz, mouse_button_state);
1149}
1150
aliguori376253e2009-03-05 23:01:23 +00001151static void do_mouse_button(Monitor *mon, int button_state)
bellard13224a82006-07-14 22:03:35 +00001152{
1153 mouse_button_state = button_state;
1154 kbd_mouse_event(0, 0, 0, mouse_button_state);
1155}
1156
aliguori376253e2009-03-05 23:01:23 +00001157static void do_ioport_read(Monitor *mon, int count, int format, int size,
1158 int addr, int has_index, int index)
bellard34405572004-06-08 00:55:58 +00001159{
1160 uint32_t val;
1161 int suffix;
1162
1163 if (has_index) {
Isaku Yamahatad56dd6c2009-07-02 19:32:07 +09001164 cpu_outb(NULL, addr & IOPORTS_MASK, index & 0xff);
bellard34405572004-06-08 00:55:58 +00001165 addr++;
1166 }
1167 addr &= 0xffff;
1168
1169 switch(size) {
1170 default:
1171 case 1:
1172 val = cpu_inb(NULL, addr);
1173 suffix = 'b';
1174 break;
1175 case 2:
1176 val = cpu_inw(NULL, addr);
1177 suffix = 'w';
1178 break;
1179 case 4:
1180 val = cpu_inl(NULL, addr);
1181 suffix = 'l';
1182 break;
1183 }
aliguori376253e2009-03-05 23:01:23 +00001184 monitor_printf(mon, "port%c[0x%04x] = %#0*x\n",
1185 suffix, addr, size * 2, val);
bellard34405572004-06-08 00:55:58 +00001186}
bellarda3a91a32004-06-04 11:06:21 +00001187
blueswir13b4366d2008-06-20 16:25:06 +00001188/* boot_set handler */
1189static QEMUBootSetHandler *qemu_boot_set_handler = NULL;
1190static void *boot_opaque;
1191
1192void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
1193{
1194 qemu_boot_set_handler = func;
1195 boot_opaque = opaque;
1196}
1197
aliguori376253e2009-03-05 23:01:23 +00001198static void do_boot_set(Monitor *mon, const char *bootdevice)
aurel320ecdffb2008-05-04 20:11:34 +00001199{
1200 int res;
1201
1202 if (qemu_boot_set_handler) {
blueswir13b4366d2008-06-20 16:25:06 +00001203 res = qemu_boot_set_handler(boot_opaque, bootdevice);
aurel320ecdffb2008-05-04 20:11:34 +00001204 if (res == 0)
aliguori376253e2009-03-05 23:01:23 +00001205 monitor_printf(mon, "boot device list now set to %s\n",
1206 bootdevice);
aurel320ecdffb2008-05-04 20:11:34 +00001207 else
aliguori376253e2009-03-05 23:01:23 +00001208 monitor_printf(mon, "setting boot device list failed with "
1209 "error %i\n", res);
aurel320ecdffb2008-05-04 20:11:34 +00001210 } else {
aliguori376253e2009-03-05 23:01:23 +00001211 monitor_printf(mon, "no function defined to set boot device list for "
1212 "this architecture\n");
aurel320ecdffb2008-05-04 20:11:34 +00001213 }
1214}
1215
aliguori376253e2009-03-05 23:01:23 +00001216static void do_system_reset(Monitor *mon)
bellarde4f90822004-06-20 12:35:44 +00001217{
1218 qemu_system_reset_request();
1219}
1220
aliguori376253e2009-03-05 23:01:23 +00001221static void do_system_powerdown(Monitor *mon)
bellard34751872005-07-02 14:31:34 +00001222{
1223 qemu_system_powerdown_request();
1224}
1225
bellardb86bda52004-09-18 19:32:46 +00001226#if defined(TARGET_I386)
aliguori376253e2009-03-05 23:01:23 +00001227static void print_pte(Monitor *mon, uint32_t addr, uint32_t pte, uint32_t mask)
bellardb86bda52004-09-18 19:32:46 +00001228{
aliguori376253e2009-03-05 23:01:23 +00001229 monitor_printf(mon, "%08x: %08x %c%c%c%c%c%c%c%c\n",
1230 addr,
1231 pte & mask,
1232 pte & PG_GLOBAL_MASK ? 'G' : '-',
1233 pte & PG_PSE_MASK ? 'P' : '-',
1234 pte & PG_DIRTY_MASK ? 'D' : '-',
1235 pte & PG_ACCESSED_MASK ? 'A' : '-',
1236 pte & PG_PCD_MASK ? 'C' : '-',
1237 pte & PG_PWT_MASK ? 'T' : '-',
1238 pte & PG_USER_MASK ? 'U' : '-',
1239 pte & PG_RW_MASK ? 'W' : '-');
bellardb86bda52004-09-18 19:32:46 +00001240}
1241
aliguori376253e2009-03-05 23:01:23 +00001242static void tlb_info(Monitor *mon)
bellardb86bda52004-09-18 19:32:46 +00001243{
bellard6a00d602005-11-21 23:25:50 +00001244 CPUState *env;
bellardb86bda52004-09-18 19:32:46 +00001245 int l1, l2;
1246 uint32_t pgd, pde, pte;
1247
bellard6a00d602005-11-21 23:25:50 +00001248 env = mon_get_cpu();
1249 if (!env)
1250 return;
1251
bellardb86bda52004-09-18 19:32:46 +00001252 if (!(env->cr[0] & CR0_PG_MASK)) {
aliguori376253e2009-03-05 23:01:23 +00001253 monitor_printf(mon, "PG disabled\n");
bellardb86bda52004-09-18 19:32:46 +00001254 return;
1255 }
1256 pgd = env->cr[3] & ~0xfff;
1257 for(l1 = 0; l1 < 1024; l1++) {
1258 cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4);
1259 pde = le32_to_cpu(pde);
1260 if (pde & PG_PRESENT_MASK) {
1261 if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
aliguori376253e2009-03-05 23:01:23 +00001262 print_pte(mon, (l1 << 22), pde, ~((1 << 20) - 1));
bellardb86bda52004-09-18 19:32:46 +00001263 } else {
1264 for(l2 = 0; l2 < 1024; l2++) {
ths5fafdf22007-09-16 21:08:06 +00001265 cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
bellardb86bda52004-09-18 19:32:46 +00001266 (uint8_t *)&pte, 4);
1267 pte = le32_to_cpu(pte);
1268 if (pte & PG_PRESENT_MASK) {
aliguori376253e2009-03-05 23:01:23 +00001269 print_pte(mon, (l1 << 22) + (l2 << 12),
ths5fafdf22007-09-16 21:08:06 +00001270 pte & ~PG_PSE_MASK,
bellardb86bda52004-09-18 19:32:46 +00001271 ~0xfff);
1272 }
1273 }
1274 }
1275 }
1276 }
1277}
1278
aliguori376253e2009-03-05 23:01:23 +00001279static void mem_print(Monitor *mon, uint32_t *pstart, int *plast_prot,
bellardb86bda52004-09-18 19:32:46 +00001280 uint32_t end, int prot)
1281{
bellard9746b152004-11-11 18:30:24 +00001282 int prot1;
1283 prot1 = *plast_prot;
1284 if (prot != prot1) {
bellardb86bda52004-09-18 19:32:46 +00001285 if (*pstart != -1) {
aliguori376253e2009-03-05 23:01:23 +00001286 monitor_printf(mon, "%08x-%08x %08x %c%c%c\n",
1287 *pstart, end, end - *pstart,
1288 prot1 & PG_USER_MASK ? 'u' : '-',
1289 'r',
1290 prot1 & PG_RW_MASK ? 'w' : '-');
bellardb86bda52004-09-18 19:32:46 +00001291 }
1292 if (prot != 0)
1293 *pstart = end;
1294 else
1295 *pstart = -1;
1296 *plast_prot = prot;
1297 }
1298}
1299
aliguori376253e2009-03-05 23:01:23 +00001300static void mem_info(Monitor *mon)
bellardb86bda52004-09-18 19:32:46 +00001301{
bellard6a00d602005-11-21 23:25:50 +00001302 CPUState *env;
bellardb86bda52004-09-18 19:32:46 +00001303 int l1, l2, prot, last_prot;
1304 uint32_t pgd, pde, pte, start, end;
1305
bellard6a00d602005-11-21 23:25:50 +00001306 env = mon_get_cpu();
1307 if (!env)
1308 return;
1309
bellardb86bda52004-09-18 19:32:46 +00001310 if (!(env->cr[0] & CR0_PG_MASK)) {
aliguori376253e2009-03-05 23:01:23 +00001311 monitor_printf(mon, "PG disabled\n");
bellardb86bda52004-09-18 19:32:46 +00001312 return;
1313 }
1314 pgd = env->cr[3] & ~0xfff;
1315 last_prot = 0;
1316 start = -1;
1317 for(l1 = 0; l1 < 1024; l1++) {
1318 cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4);
1319 pde = le32_to_cpu(pde);
1320 end = l1 << 22;
1321 if (pde & PG_PRESENT_MASK) {
1322 if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
1323 prot = pde & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK);
aliguori376253e2009-03-05 23:01:23 +00001324 mem_print(mon, &start, &last_prot, end, prot);
bellardb86bda52004-09-18 19:32:46 +00001325 } else {
1326 for(l2 = 0; l2 < 1024; l2++) {
ths5fafdf22007-09-16 21:08:06 +00001327 cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
bellardb86bda52004-09-18 19:32:46 +00001328 (uint8_t *)&pte, 4);
1329 pte = le32_to_cpu(pte);
1330 end = (l1 << 22) + (l2 << 12);
1331 if (pte & PG_PRESENT_MASK) {
1332 prot = pte & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK);
1333 } else {
1334 prot = 0;
1335 }
aliguori376253e2009-03-05 23:01:23 +00001336 mem_print(mon, &start, &last_prot, end, prot);
bellardb86bda52004-09-18 19:32:46 +00001337 }
1338 }
1339 } else {
1340 prot = 0;
aliguori376253e2009-03-05 23:01:23 +00001341 mem_print(mon, &start, &last_prot, end, prot);
bellardb86bda52004-09-18 19:32:46 +00001342 }
1343 }
1344}
1345#endif
1346
aurel327c664e22009-03-03 06:12:22 +00001347#if defined(TARGET_SH4)
1348
aliguori376253e2009-03-05 23:01:23 +00001349static void print_tlb(Monitor *mon, int idx, tlb_t *tlb)
aurel327c664e22009-03-03 06:12:22 +00001350{
aliguori376253e2009-03-05 23:01:23 +00001351 monitor_printf(mon, " tlb%i:\t"
1352 "asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t"
1353 "v=%hhu shared=%hhu cached=%hhu prot=%hhu "
1354 "dirty=%hhu writethrough=%hhu\n",
1355 idx,
1356 tlb->asid, tlb->vpn, tlb->ppn, tlb->sz, tlb->size,
1357 tlb->v, tlb->sh, tlb->c, tlb->pr,
1358 tlb->d, tlb->wt);
aurel327c664e22009-03-03 06:12:22 +00001359}
1360
aliguori376253e2009-03-05 23:01:23 +00001361static void tlb_info(Monitor *mon)
aurel327c664e22009-03-03 06:12:22 +00001362{
1363 CPUState *env = mon_get_cpu();
1364 int i;
1365
aliguori376253e2009-03-05 23:01:23 +00001366 monitor_printf (mon, "ITLB:\n");
aurel327c664e22009-03-03 06:12:22 +00001367 for (i = 0 ; i < ITLB_SIZE ; i++)
aliguori376253e2009-03-05 23:01:23 +00001368 print_tlb (mon, i, &env->itlb[i]);
1369 monitor_printf (mon, "UTLB:\n");
aurel327c664e22009-03-03 06:12:22 +00001370 for (i = 0 ; i < UTLB_SIZE ; i++)
aliguori376253e2009-03-05 23:01:23 +00001371 print_tlb (mon, i, &env->utlb[i]);
aurel327c664e22009-03-03 06:12:22 +00001372}
1373
1374#endif
1375
aliguori376253e2009-03-05 23:01:23 +00001376static void do_info_kqemu(Monitor *mon)
bellard0f4c6412005-07-24 18:10:56 +00001377{
blueswir1640f42e2009-04-19 10:18:01 +00001378#ifdef CONFIG_KQEMU
bellard6a00d602005-11-21 23:25:50 +00001379 CPUState *env;
bellard0f4c6412005-07-24 18:10:56 +00001380 int val;
1381 val = 0;
bellard6a00d602005-11-21 23:25:50 +00001382 env = mon_get_cpu();
1383 if (!env) {
aliguori376253e2009-03-05 23:01:23 +00001384 monitor_printf(mon, "No cpu initialized yet");
bellard6a00d602005-11-21 23:25:50 +00001385 return;
1386 }
1387 val = env->kqemu_enabled;
aliguori376253e2009-03-05 23:01:23 +00001388 monitor_printf(mon, "kqemu support: ");
bellard5f1ce942006-02-08 22:40:15 +00001389 switch(val) {
1390 default:
1391 case 0:
aliguori376253e2009-03-05 23:01:23 +00001392 monitor_printf(mon, "disabled\n");
bellard5f1ce942006-02-08 22:40:15 +00001393 break;
1394 case 1:
aliguori376253e2009-03-05 23:01:23 +00001395 monitor_printf(mon, "enabled for user code\n");
bellard5f1ce942006-02-08 22:40:15 +00001396 break;
1397 case 2:
aliguori376253e2009-03-05 23:01:23 +00001398 monitor_printf(mon, "enabled for user and kernel code\n");
bellard5f1ce942006-02-08 22:40:15 +00001399 break;
1400 }
bellard0f4c6412005-07-24 18:10:56 +00001401#else
aliguori376253e2009-03-05 23:01:23 +00001402 monitor_printf(mon, "kqemu support: not compiled\n");
bellard0f4c6412005-07-24 18:10:56 +00001403#endif
ths5fafdf22007-09-16 21:08:06 +00001404}
bellard0f4c6412005-07-24 18:10:56 +00001405
aliguori376253e2009-03-05 23:01:23 +00001406static void do_info_kvm(Monitor *mon)
aliguori7ba1e612008-11-05 16:04:33 +00001407{
1408#ifdef CONFIG_KVM
aliguori376253e2009-03-05 23:01:23 +00001409 monitor_printf(mon, "kvm support: ");
aliguori7ba1e612008-11-05 16:04:33 +00001410 if (kvm_enabled())
aliguori376253e2009-03-05 23:01:23 +00001411 monitor_printf(mon, "enabled\n");
aliguori7ba1e612008-11-05 16:04:33 +00001412 else
aliguori376253e2009-03-05 23:01:23 +00001413 monitor_printf(mon, "disabled\n");
aliguori7ba1e612008-11-05 16:04:33 +00001414#else
aliguori376253e2009-03-05 23:01:23 +00001415 monitor_printf(mon, "kvm support: not compiled\n");
aliguori7ba1e612008-11-05 16:04:33 +00001416#endif
1417}
1418
aliguori030ea372009-04-21 22:30:47 +00001419static void do_info_numa(Monitor *mon)
1420{
aliguorib28b6232009-04-22 20:20:29 +00001421 int i;
aliguori030ea372009-04-21 22:30:47 +00001422 CPUState *env;
1423
1424 monitor_printf(mon, "%d nodes\n", nb_numa_nodes);
1425 for (i = 0; i < nb_numa_nodes; i++) {
1426 monitor_printf(mon, "node %d cpus:", i);
1427 for (env = first_cpu; env != NULL; env = env->next_cpu) {
1428 if (env->numa_node == i) {
1429 monitor_printf(mon, " %d", env->cpu_index);
1430 }
1431 }
1432 monitor_printf(mon, "\n");
1433 monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i,
1434 node_mem[i] >> 20);
1435 }
1436}
1437
bellard5f1ce942006-02-08 22:40:15 +00001438#ifdef CONFIG_PROFILER
1439
1440int64_t kqemu_time;
1441int64_t qemu_time;
1442int64_t kqemu_exec_count;
1443int64_t dev_time;
1444int64_t kqemu_ret_int_count;
1445int64_t kqemu_ret_excp_count;
1446int64_t kqemu_ret_intr_count;
1447
aliguori376253e2009-03-05 23:01:23 +00001448static void do_info_profile(Monitor *mon)
bellard5f1ce942006-02-08 22:40:15 +00001449{
1450 int64_t total;
1451 total = qemu_time;
1452 if (total == 0)
1453 total = 1;
aliguori376253e2009-03-05 23:01:23 +00001454 monitor_printf(mon, "async time %" PRId64 " (%0.3f)\n",
1455 dev_time, dev_time / (double)ticks_per_sec);
1456 monitor_printf(mon, "qemu time %" PRId64 " (%0.3f)\n",
1457 qemu_time, qemu_time / (double)ticks_per_sec);
1458 monitor_printf(mon, "kqemu time %" PRId64 " (%0.3f %0.1f%%) count=%"
1459 PRId64 " int=%" PRId64 " excp=%" PRId64 " intr=%"
1460 PRId64 "\n",
1461 kqemu_time, kqemu_time / (double)ticks_per_sec,
1462 kqemu_time / (double)total * 100.0,
1463 kqemu_exec_count,
1464 kqemu_ret_int_count,
1465 kqemu_ret_excp_count,
1466 kqemu_ret_intr_count);
bellard5f1ce942006-02-08 22:40:15 +00001467 qemu_time = 0;
1468 kqemu_time = 0;
1469 kqemu_exec_count = 0;
1470 dev_time = 0;
1471 kqemu_ret_int_count = 0;
1472 kqemu_ret_excp_count = 0;
1473 kqemu_ret_intr_count = 0;
blueswir1640f42e2009-04-19 10:18:01 +00001474#ifdef CONFIG_KQEMU
bellard5f1ce942006-02-08 22:40:15 +00001475 kqemu_record_dump();
1476#endif
1477}
1478#else
aliguori376253e2009-03-05 23:01:23 +00001479static void do_info_profile(Monitor *mon)
bellard5f1ce942006-02-08 22:40:15 +00001480{
aliguori376253e2009-03-05 23:01:23 +00001481 monitor_printf(mon, "Internal profiler not compiled\n");
bellard5f1ce942006-02-08 22:40:15 +00001482}
1483#endif
1484
bellardec36b692006-07-16 18:57:03 +00001485/* Capture support */
1486static LIST_HEAD (capture_list_head, CaptureState) capture_head;
1487
aliguori376253e2009-03-05 23:01:23 +00001488static void do_info_capture(Monitor *mon)
bellardec36b692006-07-16 18:57:03 +00001489{
1490 int i;
1491 CaptureState *s;
1492
1493 for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) {
aliguori376253e2009-03-05 23:01:23 +00001494 monitor_printf(mon, "[%d]: ", i);
bellardec36b692006-07-16 18:57:03 +00001495 s->ops.info (s->opaque);
1496 }
1497}
1498
Blue Swirl23130862009-06-06 08:22:04 +00001499#ifdef HAS_AUDIO
aliguori376253e2009-03-05 23:01:23 +00001500static void do_stop_capture(Monitor *mon, int n)
bellardec36b692006-07-16 18:57:03 +00001501{
1502 int i;
1503 CaptureState *s;
1504
1505 for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) {
1506 if (i == n) {
1507 s->ops.destroy (s->opaque);
1508 LIST_REMOVE (s, entries);
1509 qemu_free (s);
1510 return;
1511 }
1512 }
1513}
1514
aliguori376253e2009-03-05 23:01:23 +00001515static void do_wav_capture(Monitor *mon, const char *path,
1516 int has_freq, int freq,
1517 int has_bits, int bits,
1518 int has_channels, int nchannels)
bellardec36b692006-07-16 18:57:03 +00001519{
1520 CaptureState *s;
1521
1522 s = qemu_mallocz (sizeof (*s));
bellardec36b692006-07-16 18:57:03 +00001523
1524 freq = has_freq ? freq : 44100;
1525 bits = has_bits ? bits : 16;
1526 nchannels = has_channels ? nchannels : 2;
1527
1528 if (wav_start_capture (s, path, freq, bits, nchannels)) {
aliguori376253e2009-03-05 23:01:23 +00001529 monitor_printf(mon, "Faied to add wave capture\n");
bellardec36b692006-07-16 18:57:03 +00001530 qemu_free (s);
1531 }
1532 LIST_INSERT_HEAD (&capture_head, s, entries);
1533}
1534#endif
1535
aurel32dc1c0b72008-04-27 23:52:12 +00001536#if defined(TARGET_I386)
aliguori376253e2009-03-05 23:01:23 +00001537static void do_inject_nmi(Monitor *mon, int cpu_index)
aurel32dc1c0b72008-04-27 23:52:12 +00001538{
1539 CPUState *env;
1540
1541 for (env = first_cpu; env != NULL; env = env->next_cpu)
1542 if (env->cpu_index == cpu_index) {
1543 cpu_interrupt(env, CPU_INTERRUPT_NMI);
1544 break;
1545 }
1546}
1547#endif
1548
aliguori376253e2009-03-05 23:01:23 +00001549static void do_info_status(Monitor *mon)
aurel326f9c5ee2008-12-18 22:43:56 +00001550{
aurel321b530a62009-04-05 20:08:59 +00001551 if (vm_running) {
1552 if (singlestep) {
1553 monitor_printf(mon, "VM status: running (single step mode)\n");
1554 } else {
1555 monitor_printf(mon, "VM status: running\n");
1556 }
1557 } else
aliguori376253e2009-03-05 23:01:23 +00001558 monitor_printf(mon, "VM status: paused\n");
aurel326f9c5ee2008-12-18 22:43:56 +00001559}
1560
1561
aliguori376253e2009-03-05 23:01:23 +00001562static void do_balloon(Monitor *mon, int value)
aliguoridf751fa2008-12-04 20:19:35 +00001563{
1564 ram_addr_t target = value;
1565 qemu_balloon(target << 20);
1566}
1567
aliguori376253e2009-03-05 23:01:23 +00001568static void do_info_balloon(Monitor *mon)
aliguoridf751fa2008-12-04 20:19:35 +00001569{
1570 ram_addr_t actual;
1571
1572 actual = qemu_balloon_status();
aliguoribd322082008-12-04 20:33:06 +00001573 if (kvm_enabled() && !kvm_has_sync_mmu())
aliguori376253e2009-03-05 23:01:23 +00001574 monitor_printf(mon, "Using KVM without synchronous MMU, "
1575 "ballooning disabled\n");
aliguoribd322082008-12-04 20:33:06 +00001576 else if (actual == 0)
aliguori376253e2009-03-05 23:01:23 +00001577 monitor_printf(mon, "Ballooning not activated in VM\n");
aliguoridf751fa2008-12-04 20:19:35 +00001578 else
aliguori376253e2009-03-05 23:01:23 +00001579 monitor_printf(mon, "balloon: actual=%d\n", (int)(actual >> 20));
aliguoridf751fa2008-12-04 20:19:35 +00001580}
1581
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001582static qemu_acl *find_acl(Monitor *mon, const char *name)
aliguori76655d62009-03-06 20:27:37 +00001583{
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001584 qemu_acl *acl = qemu_acl_find(name);
aliguori76655d62009-03-06 20:27:37 +00001585
aliguori76655d62009-03-06 20:27:37 +00001586 if (!acl) {
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001587 monitor_printf(mon, "acl: unknown list '%s'\n", name);
aliguori76655d62009-03-06 20:27:37 +00001588 }
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001589 return acl;
1590}
aliguori76655d62009-03-06 20:27:37 +00001591
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001592static void do_acl_show(Monitor *mon, const char *aclname)
1593{
1594 qemu_acl *acl = find_acl(mon, aclname);
1595 qemu_acl_entry *entry;
1596 int i = 0;
1597
1598 if (acl) {
aliguori28a76be2009-03-06 20:27:40 +00001599 monitor_printf(mon, "policy: %s\n",
aliguori76655d62009-03-06 20:27:37 +00001600 acl->defaultDeny ? "deny" : "allow");
aliguori28a76be2009-03-06 20:27:40 +00001601 TAILQ_FOREACH(entry, &acl->entries, next) {
1602 i++;
1603 monitor_printf(mon, "%d: %s %s\n", i,
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001604 entry->deny ? "deny" : "allow", entry->match);
aliguori28a76be2009-03-06 20:27:40 +00001605 }
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001606 }
1607}
1608
1609static void do_acl_reset(Monitor *mon, const char *aclname)
1610{
1611 qemu_acl *acl = find_acl(mon, aclname);
1612
1613 if (acl) {
aliguori28a76be2009-03-06 20:27:40 +00001614 qemu_acl_reset(acl);
1615 monitor_printf(mon, "acl: removed all rules\n");
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001616 }
1617}
aliguori76655d62009-03-06 20:27:37 +00001618
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001619static void do_acl_policy(Monitor *mon, const char *aclname,
1620 const char *policy)
1621{
1622 qemu_acl *acl = find_acl(mon, aclname);
1623
1624 if (acl) {
1625 if (strcmp(policy, "allow") == 0) {
aliguori28a76be2009-03-06 20:27:40 +00001626 acl->defaultDeny = 0;
1627 monitor_printf(mon, "acl: policy set to 'allow'\n");
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001628 } else if (strcmp(policy, "deny") == 0) {
aliguori28a76be2009-03-06 20:27:40 +00001629 acl->defaultDeny = 1;
1630 monitor_printf(mon, "acl: policy set to 'deny'\n");
1631 } else {
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001632 monitor_printf(mon, "acl: unknown policy '%s', "
1633 "expected 'deny' or 'allow'\n", policy);
aliguori28a76be2009-03-06 20:27:40 +00001634 }
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001635 }
1636}
aliguori76655d62009-03-06 20:27:37 +00001637
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001638static void do_acl_add(Monitor *mon, const char *aclname,
1639 const char *match, const char *policy,
1640 int has_index, int index)
1641{
1642 qemu_acl *acl = find_acl(mon, aclname);
1643 int deny, ret;
1644
1645 if (acl) {
1646 if (strcmp(policy, "allow") == 0) {
1647 deny = 0;
1648 } else if (strcmp(policy, "deny") == 0) {
1649 deny = 1;
1650 } else {
1651 monitor_printf(mon, "acl: unknown policy '%s', "
1652 "expected 'deny' or 'allow'\n", policy);
aliguori28a76be2009-03-06 20:27:40 +00001653 return;
1654 }
aliguori28a76be2009-03-06 20:27:40 +00001655 if (has_index)
1656 ret = qemu_acl_insert(acl, deny, match, index);
1657 else
1658 ret = qemu_acl_append(acl, deny, match);
1659 if (ret < 0)
1660 monitor_printf(mon, "acl: unable to add acl entry\n");
1661 else
1662 monitor_printf(mon, "acl: added rule at position %d\n", ret);
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001663 }
1664}
aliguori76655d62009-03-06 20:27:37 +00001665
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001666static void do_acl_remove(Monitor *mon, const char *aclname, const char *match)
1667{
1668 qemu_acl *acl = find_acl(mon, aclname);
1669 int ret;
aliguori76655d62009-03-06 20:27:37 +00001670
Jan Kiszka15dfcd42009-06-25 08:22:08 +02001671 if (acl) {
aliguori28a76be2009-03-06 20:27:40 +00001672 ret = qemu_acl_remove(acl, match);
1673 if (ret < 0)
1674 monitor_printf(mon, "acl: no matching acl entry\n");
1675 else
1676 monitor_printf(mon, "acl: removed rule at position %d\n", ret);
aliguori76655d62009-03-06 20:27:37 +00001677 }
1678}
1679
Huang Ying79c4f6b2009-06-23 10:05:14 +08001680#if defined(TARGET_I386)
1681static void do_inject_mce(Monitor *mon,
1682 int cpu_index, int bank,
1683 unsigned status_hi, unsigned status_lo,
1684 unsigned mcg_status_hi, unsigned mcg_status_lo,
1685 unsigned addr_hi, unsigned addr_lo,
1686 unsigned misc_hi, unsigned misc_lo)
1687{
1688 CPUState *cenv;
1689 uint64_t status = ((uint64_t)status_hi << 32) | status_lo;
1690 uint64_t mcg_status = ((uint64_t)mcg_status_hi << 32) | mcg_status_lo;
1691 uint64_t addr = ((uint64_t)addr_hi << 32) | addr_lo;
1692 uint64_t misc = ((uint64_t)misc_hi << 32) | misc_lo;
1693
1694 for (cenv = first_cpu; cenv != NULL; cenv = cenv->next_cpu)
1695 if (cenv->cpu_index == cpu_index && cenv->mcg_cap) {
1696 cpu_inject_x86_mce(cenv, bank, status, mcg_status, addr, misc);
1697 break;
1698 }
1699}
1700#endif
1701
aliguori376253e2009-03-05 23:01:23 +00001702static const mon_cmd_t mon_cmds[] = {
Blue Swirl23130862009-06-06 08:22:04 +00001703#include "qemu-monitor.h"
ths5fafdf22007-09-16 21:08:06 +00001704 { NULL, NULL, },
bellard9dc39cb2004-03-14 21:38:27 +00001705};
1706
Blue Swirl23130862009-06-06 08:22:04 +00001707/* Please update qemu-monitor.hx when adding or changing commands */
aliguori376253e2009-03-05 23:01:23 +00001708static const mon_cmd_t info_cmds[] = {
bellard9bc9d1c2004-10-10 15:15:51 +00001709 { "version", "", do_info_version,
blueswir1d2c639d2009-01-24 18:19:25 +00001710 "", "show the version of QEMU" },
bellard9307c4c2004-04-04 12:57:25 +00001711 { "network", "", do_info_network,
bellard9dc39cb2004-03-14 21:38:27 +00001712 "", "show the network state" },
aliguori5ccfae12008-10-31 17:31:29 +00001713 { "chardev", "", qemu_chr_info,
1714 "", "show the character devices" },
aliguori376253e2009-03-05 23:01:23 +00001715 { "block", "", bdrv_info,
bellard9dc39cb2004-03-14 21:38:27 +00001716 "", "show the block devices" },
aliguori376253e2009-03-05 23:01:23 +00001717 { "blockstats", "", bdrv_info_stats,
thsa36e69d2007-12-02 05:18:19 +00001718 "", "show block device statistics" },
bellard9307c4c2004-04-04 12:57:25 +00001719 { "registers", "", do_info_registers,
1720 "", "show the cpu registers" },
bellard6a00d602005-11-21 23:25:50 +00001721 { "cpus", "", do_info_cpus,
1722 "", "show infos for each CPU" },
bellardaa455482004-04-04 13:07:25 +00001723 { "history", "", do_info_history,
1724 "", "show the command line history", },
bellard4a0fb71e2004-05-21 11:39:07 +00001725 { "irq", "", irq_info,
1726 "", "show the interrupts statistics (if available)", },
bellard4c27ba22004-04-25 18:05:08 +00001727 { "pic", "", pic_info,
1728 "", "show i8259 (PIC) state", },
bellard86e0c042004-05-20 12:49:21 +00001729 { "pci", "", pci_info,
1730 "", "show PCI info", },
aurel327c664e22009-03-03 06:12:22 +00001731#if defined(TARGET_I386) || defined(TARGET_SH4)
bellardb86bda52004-09-18 19:32:46 +00001732 { "tlb", "", tlb_info,
1733 "", "show virtual to physical memory mappings", },
aurel327c664e22009-03-03 06:12:22 +00001734#endif
1735#if defined(TARGET_I386)
bellardb86bda52004-09-18 19:32:46 +00001736 { "mem", "", mem_info,
1737 "", "show the active virtual memory mappings", },
aliguori16b29ae2008-12-17 23:28:44 +00001738 { "hpet", "", do_info_hpet,
1739 "", "show state of HPET", },
bellardb86bda52004-09-18 19:32:46 +00001740#endif
bellarde3db7222005-01-26 22:00:47 +00001741 { "jit", "", do_info_jit,
1742 "", "show dynamic compiler info", },
bellard0f4c6412005-07-24 18:10:56 +00001743 { "kqemu", "", do_info_kqemu,
blueswir1d2c639d2009-01-24 18:19:25 +00001744 "", "show KQEMU information", },
aliguori7ba1e612008-11-05 16:04:33 +00001745 { "kvm", "", do_info_kvm,
blueswir1d2c639d2009-01-24 18:19:25 +00001746 "", "show KVM information", },
aliguori030ea372009-04-21 22:30:47 +00001747 { "numa", "", do_info_numa,
1748 "", "show NUMA information", },
bellarda594cfb2005-11-06 16:13:29 +00001749 { "usb", "", usb_info,
1750 "", "show guest USB devices", },
1751 { "usbhost", "", usb_host_info,
1752 "", "show host USB devices", },
bellard5f1ce942006-02-08 22:40:15 +00001753 { "profile", "", do_info_profile,
1754 "", "show profiling information", },
bellardec36b692006-07-16 18:57:03 +00001755 { "capture", "", do_info_capture,
bellard17100152006-09-25 21:33:49 +00001756 "", "show capture information" },
bellardfaea38e2006-08-05 21:31:00 +00001757 { "snapshots", "", do_info_snapshots,
bellard17100152006-09-25 21:33:49 +00001758 "", "show the currently saved VM snapshots" },
aurel326f9c5ee2008-12-18 22:43:56 +00001759 { "status", "", do_info_status,
1760 "", "show the current VM status (running|paused)" },
balrog201a51f2007-04-30 00:51:09 +00001761 { "pcmcia", "", pcmcia_info,
1762 "", "show guest PCMCIA status" },
ths455204e2007-01-05 16:42:13 +00001763 { "mice", "", do_info_mice,
1764 "", "show which guest mouse is receiving events" },
bellarda9ce8592007-02-05 20:20:30 +00001765 { "vnc", "", do_info_vnc,
1766 "", "show the vnc server status"},
thsc35734b2007-03-19 15:17:08 +00001767 { "name", "", do_info_name,
1768 "", "show the current VM name" },
blueswir1f1f23ad2008-09-18 18:30:20 +00001769 { "uuid", "", do_info_uuid,
1770 "", "show the current VM UUID" },
j_mayer76a66252007-03-07 08:32:30 +00001771#if defined(TARGET_PPC)
1772 { "cpustats", "", do_info_cpu_stats,
1773 "", "show CPU statistics", },
1774#endif
blueswir131a60e22007-10-26 18:42:59 +00001775#if defined(CONFIG_SLIRP)
Jan Kiszka6dbe5532009-06-24 14:42:29 +02001776 { "usernet", "", do_info_usernet,
1777 "", "show user network stack connection states", },
blueswir131a60e22007-10-26 18:42:59 +00001778#endif
aliguori5bb79102008-10-13 03:12:02 +00001779 { "migrate", "", do_info_migrate, "", "show migration status" },
aliguoridf751fa2008-12-04 20:19:35 +00001780 { "balloon", "", do_info_balloon,
1781 "", "show balloon information" },
Gerd Hoffmanncae49562009-06-05 15:53:17 +01001782 { "qtree", "", do_info_qtree,
1783 "", "show device tree" },
bellard9dc39cb2004-03-14 21:38:27 +00001784 { NULL, NULL, },
1785};
1786
bellard9307c4c2004-04-04 12:57:25 +00001787/*******************************************************************/
1788
1789static const char *pch;
1790static jmp_buf expr_env;
1791
bellard92a31b12005-02-10 22:00:52 +00001792#define MD_TLONG 0
1793#define MD_I32 1
1794
bellard9307c4c2004-04-04 12:57:25 +00001795typedef struct MonitorDef {
1796 const char *name;
1797 int offset;
blueswir18662d652008-10-02 18:32:44 +00001798 target_long (*get_value)(const struct MonitorDef *md, int val);
bellard92a31b12005-02-10 22:00:52 +00001799 int type;
bellard9307c4c2004-04-04 12:57:25 +00001800} MonitorDef;
1801
bellard57206fd2004-04-25 18:54:52 +00001802#if defined(TARGET_I386)
blueswir18662d652008-10-02 18:32:44 +00001803static target_long monitor_get_pc (const struct MonitorDef *md, int val)
bellard57206fd2004-04-25 18:54:52 +00001804{
bellard6a00d602005-11-21 23:25:50 +00001805 CPUState *env = mon_get_cpu();
1806 if (!env)
1807 return 0;
1808 return env->eip + env->segs[R_CS].base;
bellard57206fd2004-04-25 18:54:52 +00001809}
1810#endif
1811
bellarda541f292004-04-12 20:39:29 +00001812#if defined(TARGET_PPC)
blueswir18662d652008-10-02 18:32:44 +00001813static target_long monitor_get_ccr (const struct MonitorDef *md, int val)
bellarda541f292004-04-12 20:39:29 +00001814{
bellard6a00d602005-11-21 23:25:50 +00001815 CPUState *env = mon_get_cpu();
bellarda541f292004-04-12 20:39:29 +00001816 unsigned int u;
1817 int i;
1818
bellard6a00d602005-11-21 23:25:50 +00001819 if (!env)
1820 return 0;
1821
bellarda541f292004-04-12 20:39:29 +00001822 u = 0;
1823 for (i = 0; i < 8; i++)
aliguori28a76be2009-03-06 20:27:40 +00001824 u |= env->crf[i] << (32 - (4 * i));
bellarda541f292004-04-12 20:39:29 +00001825
1826 return u;
1827}
1828
blueswir18662d652008-10-02 18:32:44 +00001829static target_long monitor_get_msr (const struct MonitorDef *md, int val)
bellarda541f292004-04-12 20:39:29 +00001830{
bellard6a00d602005-11-21 23:25:50 +00001831 CPUState *env = mon_get_cpu();
1832 if (!env)
1833 return 0;
j_mayer0411a972007-10-25 21:35:50 +00001834 return env->msr;
bellarda541f292004-04-12 20:39:29 +00001835}
1836
blueswir18662d652008-10-02 18:32:44 +00001837static target_long monitor_get_xer (const struct MonitorDef *md, int val)
bellarda541f292004-04-12 20:39:29 +00001838{
bellard6a00d602005-11-21 23:25:50 +00001839 CPUState *env = mon_get_cpu();
1840 if (!env)
1841 return 0;
aurel323d7b4172008-10-21 11:28:46 +00001842 return env->xer;
bellarda541f292004-04-12 20:39:29 +00001843}
bellard9fddaa02004-05-21 12:59:32 +00001844
blueswir18662d652008-10-02 18:32:44 +00001845static target_long monitor_get_decr (const struct MonitorDef *md, int val)
bellard9fddaa02004-05-21 12:59:32 +00001846{
bellard6a00d602005-11-21 23:25:50 +00001847 CPUState *env = mon_get_cpu();
1848 if (!env)
1849 return 0;
1850 return cpu_ppc_load_decr(env);
bellard9fddaa02004-05-21 12:59:32 +00001851}
1852
blueswir18662d652008-10-02 18:32:44 +00001853static target_long monitor_get_tbu (const struct MonitorDef *md, int val)
bellard9fddaa02004-05-21 12:59:32 +00001854{
bellard6a00d602005-11-21 23:25:50 +00001855 CPUState *env = mon_get_cpu();
1856 if (!env)
1857 return 0;
1858 return cpu_ppc_load_tbu(env);
bellard9fddaa02004-05-21 12:59:32 +00001859}
1860
blueswir18662d652008-10-02 18:32:44 +00001861static target_long monitor_get_tbl (const struct MonitorDef *md, int val)
bellard9fddaa02004-05-21 12:59:32 +00001862{
bellard6a00d602005-11-21 23:25:50 +00001863 CPUState *env = mon_get_cpu();
1864 if (!env)
1865 return 0;
1866 return cpu_ppc_load_tbl(env);
bellard9fddaa02004-05-21 12:59:32 +00001867}
bellarda541f292004-04-12 20:39:29 +00001868#endif
1869
bellarde95c8d52004-09-30 22:22:08 +00001870#if defined(TARGET_SPARC)
bellard7b936c02005-10-30 17:05:13 +00001871#ifndef TARGET_SPARC64
blueswir18662d652008-10-02 18:32:44 +00001872static target_long monitor_get_psr (const struct MonitorDef *md, int val)
bellarde95c8d52004-09-30 22:22:08 +00001873{
bellard6a00d602005-11-21 23:25:50 +00001874 CPUState *env = mon_get_cpu();
1875 if (!env)
1876 return 0;
1877 return GET_PSR(env);
bellarde95c8d52004-09-30 22:22:08 +00001878}
bellard7b936c02005-10-30 17:05:13 +00001879#endif
bellarde95c8d52004-09-30 22:22:08 +00001880
blueswir18662d652008-10-02 18:32:44 +00001881static target_long monitor_get_reg(const struct MonitorDef *md, int val)
bellarde95c8d52004-09-30 22:22:08 +00001882{
bellard6a00d602005-11-21 23:25:50 +00001883 CPUState *env = mon_get_cpu();
1884 if (!env)
1885 return 0;
1886 return env->regwptr[val];
bellarde95c8d52004-09-30 22:22:08 +00001887}
1888#endif
1889
blueswir18662d652008-10-02 18:32:44 +00001890static const MonitorDef monitor_defs[] = {
bellard9307c4c2004-04-04 12:57:25 +00001891#ifdef TARGET_I386
bellard57206fd2004-04-25 18:54:52 +00001892
1893#define SEG(name, seg) \
bellard92a31b12005-02-10 22:00:52 +00001894 { name, offsetof(CPUState, segs[seg].selector), NULL, MD_I32 },\
bellard57206fd2004-04-25 18:54:52 +00001895 { name ".base", offsetof(CPUState, segs[seg].base) },\
bellard92a31b12005-02-10 22:00:52 +00001896 { name ".limit", offsetof(CPUState, segs[seg].limit), NULL, MD_I32 },
bellard57206fd2004-04-25 18:54:52 +00001897
bellard9307c4c2004-04-04 12:57:25 +00001898 { "eax", offsetof(CPUState, regs[0]) },
1899 { "ecx", offsetof(CPUState, regs[1]) },
1900 { "edx", offsetof(CPUState, regs[2]) },
1901 { "ebx", offsetof(CPUState, regs[3]) },
1902 { "esp|sp", offsetof(CPUState, regs[4]) },
1903 { "ebp|fp", offsetof(CPUState, regs[5]) },
1904 { "esi", offsetof(CPUState, regs[6]) },
bellard01038d22004-09-13 21:36:46 +00001905 { "edi", offsetof(CPUState, regs[7]) },
bellard92a31b12005-02-10 22:00:52 +00001906#ifdef TARGET_X86_64
1907 { "r8", offsetof(CPUState, regs[8]) },
1908 { "r9", offsetof(CPUState, regs[9]) },
1909 { "r10", offsetof(CPUState, regs[10]) },
1910 { "r11", offsetof(CPUState, regs[11]) },
1911 { "r12", offsetof(CPUState, regs[12]) },
1912 { "r13", offsetof(CPUState, regs[13]) },
1913 { "r14", offsetof(CPUState, regs[14]) },
1914 { "r15", offsetof(CPUState, regs[15]) },
1915#endif
bellard9307c4c2004-04-04 12:57:25 +00001916 { "eflags", offsetof(CPUState, eflags) },
bellard57206fd2004-04-25 18:54:52 +00001917 { "eip", offsetof(CPUState, eip) },
1918 SEG("cs", R_CS)
1919 SEG("ds", R_DS)
1920 SEG("es", R_ES)
bellard01038d22004-09-13 21:36:46 +00001921 SEG("ss", R_SS)
bellard57206fd2004-04-25 18:54:52 +00001922 SEG("fs", R_FS)
1923 SEG("gs", R_GS)
1924 { "pc", 0, monitor_get_pc, },
bellarda541f292004-04-12 20:39:29 +00001925#elif defined(TARGET_PPC)
j_mayerff937db2007-09-19 05:49:13 +00001926 /* General purpose registers */
bellarda541f292004-04-12 20:39:29 +00001927 { "r0", offsetof(CPUState, gpr[0]) },
1928 { "r1", offsetof(CPUState, gpr[1]) },
1929 { "r2", offsetof(CPUState, gpr[2]) },
1930 { "r3", offsetof(CPUState, gpr[3]) },
1931 { "r4", offsetof(CPUState, gpr[4]) },
1932 { "r5", offsetof(CPUState, gpr[5]) },
1933 { "r6", offsetof(CPUState, gpr[6]) },
1934 { "r7", offsetof(CPUState, gpr[7]) },
1935 { "r8", offsetof(CPUState, gpr[8]) },
1936 { "r9", offsetof(CPUState, gpr[9]) },
1937 { "r10", offsetof(CPUState, gpr[10]) },
1938 { "r11", offsetof(CPUState, gpr[11]) },
1939 { "r12", offsetof(CPUState, gpr[12]) },
1940 { "r13", offsetof(CPUState, gpr[13]) },
1941 { "r14", offsetof(CPUState, gpr[14]) },
1942 { "r15", offsetof(CPUState, gpr[15]) },
1943 { "r16", offsetof(CPUState, gpr[16]) },
1944 { "r17", offsetof(CPUState, gpr[17]) },
1945 { "r18", offsetof(CPUState, gpr[18]) },
1946 { "r19", offsetof(CPUState, gpr[19]) },
1947 { "r20", offsetof(CPUState, gpr[20]) },
1948 { "r21", offsetof(CPUState, gpr[21]) },
1949 { "r22", offsetof(CPUState, gpr[22]) },
1950 { "r23", offsetof(CPUState, gpr[23]) },
1951 { "r24", offsetof(CPUState, gpr[24]) },
1952 { "r25", offsetof(CPUState, gpr[25]) },
1953 { "r26", offsetof(CPUState, gpr[26]) },
1954 { "r27", offsetof(CPUState, gpr[27]) },
1955 { "r28", offsetof(CPUState, gpr[28]) },
1956 { "r29", offsetof(CPUState, gpr[29]) },
1957 { "r30", offsetof(CPUState, gpr[30]) },
1958 { "r31", offsetof(CPUState, gpr[31]) },
j_mayerff937db2007-09-19 05:49:13 +00001959 /* Floating point registers */
1960 { "f0", offsetof(CPUState, fpr[0]) },
1961 { "f1", offsetof(CPUState, fpr[1]) },
1962 { "f2", offsetof(CPUState, fpr[2]) },
1963 { "f3", offsetof(CPUState, fpr[3]) },
1964 { "f4", offsetof(CPUState, fpr[4]) },
1965 { "f5", offsetof(CPUState, fpr[5]) },
1966 { "f6", offsetof(CPUState, fpr[6]) },
1967 { "f7", offsetof(CPUState, fpr[7]) },
1968 { "f8", offsetof(CPUState, fpr[8]) },
1969 { "f9", offsetof(CPUState, fpr[9]) },
1970 { "f10", offsetof(CPUState, fpr[10]) },
1971 { "f11", offsetof(CPUState, fpr[11]) },
1972 { "f12", offsetof(CPUState, fpr[12]) },
1973 { "f13", offsetof(CPUState, fpr[13]) },
1974 { "f14", offsetof(CPUState, fpr[14]) },
1975 { "f15", offsetof(CPUState, fpr[15]) },
1976 { "f16", offsetof(CPUState, fpr[16]) },
1977 { "f17", offsetof(CPUState, fpr[17]) },
1978 { "f18", offsetof(CPUState, fpr[18]) },
1979 { "f19", offsetof(CPUState, fpr[19]) },
1980 { "f20", offsetof(CPUState, fpr[20]) },
1981 { "f21", offsetof(CPUState, fpr[21]) },
1982 { "f22", offsetof(CPUState, fpr[22]) },
1983 { "f23", offsetof(CPUState, fpr[23]) },
1984 { "f24", offsetof(CPUState, fpr[24]) },
1985 { "f25", offsetof(CPUState, fpr[25]) },
1986 { "f26", offsetof(CPUState, fpr[26]) },
1987 { "f27", offsetof(CPUState, fpr[27]) },
1988 { "f28", offsetof(CPUState, fpr[28]) },
1989 { "f29", offsetof(CPUState, fpr[29]) },
1990 { "f30", offsetof(CPUState, fpr[30]) },
1991 { "f31", offsetof(CPUState, fpr[31]) },
1992 { "fpscr", offsetof(CPUState, fpscr) },
1993 /* Next instruction pointer */
bellard57206fd2004-04-25 18:54:52 +00001994 { "nip|pc", offsetof(CPUState, nip) },
bellarda541f292004-04-12 20:39:29 +00001995 { "lr", offsetof(CPUState, lr) },
1996 { "ctr", offsetof(CPUState, ctr) },
bellard9fddaa02004-05-21 12:59:32 +00001997 { "decr", 0, &monitor_get_decr, },
bellarda541f292004-04-12 20:39:29 +00001998 { "ccr", 0, &monitor_get_ccr, },
j_mayerff937db2007-09-19 05:49:13 +00001999 /* Machine state register */
bellarda541f292004-04-12 20:39:29 +00002000 { "msr", 0, &monitor_get_msr, },
2001 { "xer", 0, &monitor_get_xer, },
bellard9fddaa02004-05-21 12:59:32 +00002002 { "tbu", 0, &monitor_get_tbu, },
2003 { "tbl", 0, &monitor_get_tbl, },
j_mayerff937db2007-09-19 05:49:13 +00002004#if defined(TARGET_PPC64)
2005 /* Address space register */
2006 { "asr", offsetof(CPUState, asr) },
2007#endif
2008 /* Segment registers */
bellarda541f292004-04-12 20:39:29 +00002009 { "sdr1", offsetof(CPUState, sdr1) },
2010 { "sr0", offsetof(CPUState, sr[0]) },
2011 { "sr1", offsetof(CPUState, sr[1]) },
2012 { "sr2", offsetof(CPUState, sr[2]) },
2013 { "sr3", offsetof(CPUState, sr[3]) },
2014 { "sr4", offsetof(CPUState, sr[4]) },
2015 { "sr5", offsetof(CPUState, sr[5]) },
2016 { "sr6", offsetof(CPUState, sr[6]) },
2017 { "sr7", offsetof(CPUState, sr[7]) },
2018 { "sr8", offsetof(CPUState, sr[8]) },
2019 { "sr9", offsetof(CPUState, sr[9]) },
2020 { "sr10", offsetof(CPUState, sr[10]) },
2021 { "sr11", offsetof(CPUState, sr[11]) },
2022 { "sr12", offsetof(CPUState, sr[12]) },
2023 { "sr13", offsetof(CPUState, sr[13]) },
2024 { "sr14", offsetof(CPUState, sr[14]) },
2025 { "sr15", offsetof(CPUState, sr[15]) },
2026 /* Too lazy to put BATs and SPRs ... */
bellarde95c8d52004-09-30 22:22:08 +00002027#elif defined(TARGET_SPARC)
2028 { "g0", offsetof(CPUState, gregs[0]) },
2029 { "g1", offsetof(CPUState, gregs[1]) },
2030 { "g2", offsetof(CPUState, gregs[2]) },
2031 { "g3", offsetof(CPUState, gregs[3]) },
2032 { "g4", offsetof(CPUState, gregs[4]) },
2033 { "g5", offsetof(CPUState, gregs[5]) },
2034 { "g6", offsetof(CPUState, gregs[6]) },
2035 { "g7", offsetof(CPUState, gregs[7]) },
2036 { "o0", 0, monitor_get_reg },
2037 { "o1", 1, monitor_get_reg },
2038 { "o2", 2, monitor_get_reg },
2039 { "o3", 3, monitor_get_reg },
2040 { "o4", 4, monitor_get_reg },
2041 { "o5", 5, monitor_get_reg },
2042 { "o6", 6, monitor_get_reg },
2043 { "o7", 7, monitor_get_reg },
2044 { "l0", 8, monitor_get_reg },
2045 { "l1", 9, monitor_get_reg },
2046 { "l2", 10, monitor_get_reg },
2047 { "l3", 11, monitor_get_reg },
2048 { "l4", 12, monitor_get_reg },
2049 { "l5", 13, monitor_get_reg },
2050 { "l6", 14, monitor_get_reg },
2051 { "l7", 15, monitor_get_reg },
2052 { "i0", 16, monitor_get_reg },
2053 { "i1", 17, monitor_get_reg },
2054 { "i2", 18, monitor_get_reg },
2055 { "i3", 19, monitor_get_reg },
2056 { "i4", 20, monitor_get_reg },
2057 { "i5", 21, monitor_get_reg },
2058 { "i6", 22, monitor_get_reg },
2059 { "i7", 23, monitor_get_reg },
2060 { "pc", offsetof(CPUState, pc) },
2061 { "npc", offsetof(CPUState, npc) },
2062 { "y", offsetof(CPUState, y) },
bellard7b936c02005-10-30 17:05:13 +00002063#ifndef TARGET_SPARC64
bellarde95c8d52004-09-30 22:22:08 +00002064 { "psr", 0, &monitor_get_psr, },
2065 { "wim", offsetof(CPUState, wim) },
bellard7b936c02005-10-30 17:05:13 +00002066#endif
bellarde95c8d52004-09-30 22:22:08 +00002067 { "tbr", offsetof(CPUState, tbr) },
2068 { "fsr", offsetof(CPUState, fsr) },
2069 { "f0", offsetof(CPUState, fpr[0]) },
2070 { "f1", offsetof(CPUState, fpr[1]) },
2071 { "f2", offsetof(CPUState, fpr[2]) },
2072 { "f3", offsetof(CPUState, fpr[3]) },
2073 { "f4", offsetof(CPUState, fpr[4]) },
2074 { "f5", offsetof(CPUState, fpr[5]) },
2075 { "f6", offsetof(CPUState, fpr[6]) },
2076 { "f7", offsetof(CPUState, fpr[7]) },
2077 { "f8", offsetof(CPUState, fpr[8]) },
2078 { "f9", offsetof(CPUState, fpr[9]) },
2079 { "f10", offsetof(CPUState, fpr[10]) },
2080 { "f11", offsetof(CPUState, fpr[11]) },
2081 { "f12", offsetof(CPUState, fpr[12]) },
2082 { "f13", offsetof(CPUState, fpr[13]) },
2083 { "f14", offsetof(CPUState, fpr[14]) },
2084 { "f15", offsetof(CPUState, fpr[15]) },
2085 { "f16", offsetof(CPUState, fpr[16]) },
2086 { "f17", offsetof(CPUState, fpr[17]) },
2087 { "f18", offsetof(CPUState, fpr[18]) },
2088 { "f19", offsetof(CPUState, fpr[19]) },
2089 { "f20", offsetof(CPUState, fpr[20]) },
2090 { "f21", offsetof(CPUState, fpr[21]) },
2091 { "f22", offsetof(CPUState, fpr[22]) },
2092 { "f23", offsetof(CPUState, fpr[23]) },
2093 { "f24", offsetof(CPUState, fpr[24]) },
2094 { "f25", offsetof(CPUState, fpr[25]) },
2095 { "f26", offsetof(CPUState, fpr[26]) },
2096 { "f27", offsetof(CPUState, fpr[27]) },
2097 { "f28", offsetof(CPUState, fpr[28]) },
2098 { "f29", offsetof(CPUState, fpr[29]) },
2099 { "f30", offsetof(CPUState, fpr[30]) },
2100 { "f31", offsetof(CPUState, fpr[31]) },
bellard7b936c02005-10-30 17:05:13 +00002101#ifdef TARGET_SPARC64
2102 { "f32", offsetof(CPUState, fpr[32]) },
2103 { "f34", offsetof(CPUState, fpr[34]) },
2104 { "f36", offsetof(CPUState, fpr[36]) },
2105 { "f38", offsetof(CPUState, fpr[38]) },
2106 { "f40", offsetof(CPUState, fpr[40]) },
2107 { "f42", offsetof(CPUState, fpr[42]) },
2108 { "f44", offsetof(CPUState, fpr[44]) },
2109 { "f46", offsetof(CPUState, fpr[46]) },
2110 { "f48", offsetof(CPUState, fpr[48]) },
2111 { "f50", offsetof(CPUState, fpr[50]) },
2112 { "f52", offsetof(CPUState, fpr[52]) },
2113 { "f54", offsetof(CPUState, fpr[54]) },
2114 { "f56", offsetof(CPUState, fpr[56]) },
2115 { "f58", offsetof(CPUState, fpr[58]) },
2116 { "f60", offsetof(CPUState, fpr[60]) },
2117 { "f62", offsetof(CPUState, fpr[62]) },
2118 { "asi", offsetof(CPUState, asi) },
2119 { "pstate", offsetof(CPUState, pstate) },
2120 { "cansave", offsetof(CPUState, cansave) },
2121 { "canrestore", offsetof(CPUState, canrestore) },
2122 { "otherwin", offsetof(CPUState, otherwin) },
2123 { "wstate", offsetof(CPUState, wstate) },
2124 { "cleanwin", offsetof(CPUState, cleanwin) },
2125 { "fprs", offsetof(CPUState, fprs) },
2126#endif
bellard9307c4c2004-04-04 12:57:25 +00002127#endif
2128 { NULL },
2129};
2130
aliguori376253e2009-03-05 23:01:23 +00002131static void expr_error(Monitor *mon, const char *msg)
bellard9dc39cb2004-03-14 21:38:27 +00002132{
aliguori376253e2009-03-05 23:01:23 +00002133 monitor_printf(mon, "%s\n", msg);
bellard9307c4c2004-04-04 12:57:25 +00002134 longjmp(expr_env, 1);
2135}
2136
bellard6a00d602005-11-21 23:25:50 +00002137/* return 0 if OK, -1 if not found, -2 if no CPU defined */
bellard92a31b12005-02-10 22:00:52 +00002138static int get_monitor_def(target_long *pval, const char *name)
bellard9307c4c2004-04-04 12:57:25 +00002139{
blueswir18662d652008-10-02 18:32:44 +00002140 const MonitorDef *md;
bellard92a31b12005-02-10 22:00:52 +00002141 void *ptr;
2142
bellard9307c4c2004-04-04 12:57:25 +00002143 for(md = monitor_defs; md->name != NULL; md++) {
2144 if (compare_cmd(name, md->name)) {
2145 if (md->get_value) {
bellarde95c8d52004-09-30 22:22:08 +00002146 *pval = md->get_value(md, md->offset);
bellard9307c4c2004-04-04 12:57:25 +00002147 } else {
bellard6a00d602005-11-21 23:25:50 +00002148 CPUState *env = mon_get_cpu();
2149 if (!env)
2150 return -2;
2151 ptr = (uint8_t *)env + md->offset;
bellard92a31b12005-02-10 22:00:52 +00002152 switch(md->type) {
2153 case MD_I32:
2154 *pval = *(int32_t *)ptr;
2155 break;
2156 case MD_TLONG:
2157 *pval = *(target_long *)ptr;
2158 break;
2159 default:
2160 *pval = 0;
2161 break;
2162 }
bellard9307c4c2004-04-04 12:57:25 +00002163 }
2164 return 0;
2165 }
2166 }
2167 return -1;
2168}
2169
2170static void next(void)
2171{
2172 if (pch != '\0') {
2173 pch++;
blueswir1cd390082008-11-16 13:53:32 +00002174 while (qemu_isspace(*pch))
bellard9307c4c2004-04-04 12:57:25 +00002175 pch++;
2176 }
2177}
2178
aliguori376253e2009-03-05 23:01:23 +00002179static int64_t expr_sum(Monitor *mon);
bellard9307c4c2004-04-04 12:57:25 +00002180
aliguori376253e2009-03-05 23:01:23 +00002181static int64_t expr_unary(Monitor *mon)
bellard9307c4c2004-04-04 12:57:25 +00002182{
blueswir1c2efc952007-09-25 17:28:42 +00002183 int64_t n;
bellard9307c4c2004-04-04 12:57:25 +00002184 char *p;
bellard6a00d602005-11-21 23:25:50 +00002185 int ret;
bellard9307c4c2004-04-04 12:57:25 +00002186
2187 switch(*pch) {
2188 case '+':
2189 next();
aliguori376253e2009-03-05 23:01:23 +00002190 n = expr_unary(mon);
bellard9307c4c2004-04-04 12:57:25 +00002191 break;
2192 case '-':
2193 next();
aliguori376253e2009-03-05 23:01:23 +00002194 n = -expr_unary(mon);
bellard9307c4c2004-04-04 12:57:25 +00002195 break;
2196 case '~':
2197 next();
aliguori376253e2009-03-05 23:01:23 +00002198 n = ~expr_unary(mon);
bellard9307c4c2004-04-04 12:57:25 +00002199 break;
2200 case '(':
2201 next();
aliguori376253e2009-03-05 23:01:23 +00002202 n = expr_sum(mon);
bellard9307c4c2004-04-04 12:57:25 +00002203 if (*pch != ')') {
aliguori376253e2009-03-05 23:01:23 +00002204 expr_error(mon, "')' expected");
bellard9307c4c2004-04-04 12:57:25 +00002205 }
2206 next();
2207 break;
bellard81d09122004-07-14 17:21:37 +00002208 case '\'':
2209 pch++;
2210 if (*pch == '\0')
aliguori376253e2009-03-05 23:01:23 +00002211 expr_error(mon, "character constant expected");
bellard81d09122004-07-14 17:21:37 +00002212 n = *pch;
2213 pch++;
2214 if (*pch != '\'')
aliguori376253e2009-03-05 23:01:23 +00002215 expr_error(mon, "missing terminating \' character");
bellard81d09122004-07-14 17:21:37 +00002216 next();
2217 break;
bellard9307c4c2004-04-04 12:57:25 +00002218 case '$':
2219 {
2220 char buf[128], *q;
ths69b34972007-12-17 03:15:52 +00002221 target_long reg=0;
ths3b46e622007-09-17 08:09:54 +00002222
bellard9307c4c2004-04-04 12:57:25 +00002223 pch++;
2224 q = buf;
2225 while ((*pch >= 'a' && *pch <= 'z') ||
2226 (*pch >= 'A' && *pch <= 'Z') ||
2227 (*pch >= '0' && *pch <= '9') ||
bellard57206fd2004-04-25 18:54:52 +00002228 *pch == '_' || *pch == '.') {
bellard9307c4c2004-04-04 12:57:25 +00002229 if ((q - buf) < sizeof(buf) - 1)
2230 *q++ = *pch;
2231 pch++;
2232 }
blueswir1cd390082008-11-16 13:53:32 +00002233 while (qemu_isspace(*pch))
bellard9307c4c2004-04-04 12:57:25 +00002234 pch++;
2235 *q = 0;
blueswir17743e582007-09-24 18:39:04 +00002236 ret = get_monitor_def(&reg, buf);
bellard6a00d602005-11-21 23:25:50 +00002237 if (ret == -1)
aliguori376253e2009-03-05 23:01:23 +00002238 expr_error(mon, "unknown register");
ths5fafdf22007-09-16 21:08:06 +00002239 else if (ret == -2)
aliguori376253e2009-03-05 23:01:23 +00002240 expr_error(mon, "no cpu defined");
blueswir17743e582007-09-24 18:39:04 +00002241 n = reg;
bellard9307c4c2004-04-04 12:57:25 +00002242 }
2243 break;
2244 case '\0':
aliguori376253e2009-03-05 23:01:23 +00002245 expr_error(mon, "unexpected end of expression");
bellard9307c4c2004-04-04 12:57:25 +00002246 n = 0;
2247 break;
2248 default:
blueswir17743e582007-09-24 18:39:04 +00002249#if TARGET_PHYS_ADDR_BITS > 32
bellard4f4fbf72006-06-25 18:28:12 +00002250 n = strtoull(pch, &p, 0);
2251#else
bellard9307c4c2004-04-04 12:57:25 +00002252 n = strtoul(pch, &p, 0);
bellard4f4fbf72006-06-25 18:28:12 +00002253#endif
bellard9307c4c2004-04-04 12:57:25 +00002254 if (pch == p) {
aliguori376253e2009-03-05 23:01:23 +00002255 expr_error(mon, "invalid char in expression");
bellard9307c4c2004-04-04 12:57:25 +00002256 }
2257 pch = p;
blueswir1cd390082008-11-16 13:53:32 +00002258 while (qemu_isspace(*pch))
bellard9307c4c2004-04-04 12:57:25 +00002259 pch++;
2260 break;
2261 }
2262 return n;
2263}
2264
2265
aliguori376253e2009-03-05 23:01:23 +00002266static int64_t expr_prod(Monitor *mon)
bellard9307c4c2004-04-04 12:57:25 +00002267{
blueswir1c2efc952007-09-25 17:28:42 +00002268 int64_t val, val2;
bellard92a31b12005-02-10 22:00:52 +00002269 int op;
ths3b46e622007-09-17 08:09:54 +00002270
aliguori376253e2009-03-05 23:01:23 +00002271 val = expr_unary(mon);
bellard9307c4c2004-04-04 12:57:25 +00002272 for(;;) {
2273 op = *pch;
2274 if (op != '*' && op != '/' && op != '%')
2275 break;
2276 next();
aliguori376253e2009-03-05 23:01:23 +00002277 val2 = expr_unary(mon);
bellard9307c4c2004-04-04 12:57:25 +00002278 switch(op) {
2279 default:
2280 case '*':
2281 val *= val2;
2282 break;
2283 case '/':
2284 case '%':
ths5fafdf22007-09-16 21:08:06 +00002285 if (val2 == 0)
aliguori376253e2009-03-05 23:01:23 +00002286 expr_error(mon, "division by zero");
bellard9307c4c2004-04-04 12:57:25 +00002287 if (op == '/')
2288 val /= val2;
2289 else
2290 val %= val2;
2291 break;
2292 }
2293 }
2294 return val;
2295}
2296
aliguori376253e2009-03-05 23:01:23 +00002297static int64_t expr_logic(Monitor *mon)
bellard9307c4c2004-04-04 12:57:25 +00002298{
blueswir1c2efc952007-09-25 17:28:42 +00002299 int64_t val, val2;
bellard92a31b12005-02-10 22:00:52 +00002300 int op;
bellard9307c4c2004-04-04 12:57:25 +00002301
aliguori376253e2009-03-05 23:01:23 +00002302 val = expr_prod(mon);
bellard9307c4c2004-04-04 12:57:25 +00002303 for(;;) {
2304 op = *pch;
2305 if (op != '&' && op != '|' && op != '^')
2306 break;
2307 next();
aliguori376253e2009-03-05 23:01:23 +00002308 val2 = expr_prod(mon);
bellard9307c4c2004-04-04 12:57:25 +00002309 switch(op) {
2310 default:
2311 case '&':
2312 val &= val2;
2313 break;
2314 case '|':
2315 val |= val2;
2316 break;
2317 case '^':
2318 val ^= val2;
2319 break;
2320 }
2321 }
2322 return val;
2323}
2324
aliguori376253e2009-03-05 23:01:23 +00002325static int64_t expr_sum(Monitor *mon)
bellard9307c4c2004-04-04 12:57:25 +00002326{
blueswir1c2efc952007-09-25 17:28:42 +00002327 int64_t val, val2;
bellard92a31b12005-02-10 22:00:52 +00002328 int op;
bellard9307c4c2004-04-04 12:57:25 +00002329
aliguori376253e2009-03-05 23:01:23 +00002330 val = expr_logic(mon);
bellard9307c4c2004-04-04 12:57:25 +00002331 for(;;) {
2332 op = *pch;
2333 if (op != '+' && op != '-')
2334 break;
2335 next();
aliguori376253e2009-03-05 23:01:23 +00002336 val2 = expr_logic(mon);
bellard9307c4c2004-04-04 12:57:25 +00002337 if (op == '+')
2338 val += val2;
2339 else
2340 val -= val2;
2341 }
2342 return val;
2343}
2344
aliguori376253e2009-03-05 23:01:23 +00002345static int get_expr(Monitor *mon, int64_t *pval, const char **pp)
bellard9307c4c2004-04-04 12:57:25 +00002346{
2347 pch = *pp;
2348 if (setjmp(expr_env)) {
2349 *pp = pch;
2350 return -1;
2351 }
blueswir1cd390082008-11-16 13:53:32 +00002352 while (qemu_isspace(*pch))
bellard9307c4c2004-04-04 12:57:25 +00002353 pch++;
aliguori376253e2009-03-05 23:01:23 +00002354 *pval = expr_sum(mon);
bellard9307c4c2004-04-04 12:57:25 +00002355 *pp = pch;
2356 return 0;
2357}
2358
2359static int get_str(char *buf, int buf_size, const char **pp)
2360{
2361 const char *p;
2362 char *q;
2363 int c;
2364
bellard81d09122004-07-14 17:21:37 +00002365 q = buf;
bellard9307c4c2004-04-04 12:57:25 +00002366 p = *pp;
blueswir1cd390082008-11-16 13:53:32 +00002367 while (qemu_isspace(*p))
bellard9307c4c2004-04-04 12:57:25 +00002368 p++;
2369 if (*p == '\0') {
2370 fail:
bellard81d09122004-07-14 17:21:37 +00002371 *q = '\0';
bellard9307c4c2004-04-04 12:57:25 +00002372 *pp = p;
2373 return -1;
2374 }
bellard9307c4c2004-04-04 12:57:25 +00002375 if (*p == '\"') {
2376 p++;
2377 while (*p != '\0' && *p != '\"') {
2378 if (*p == '\\') {
2379 p++;
2380 c = *p++;
2381 switch(c) {
2382 case 'n':
2383 c = '\n';
2384 break;
2385 case 'r':
2386 c = '\r';
2387 break;
2388 case '\\':
2389 case '\'':
2390 case '\"':
2391 break;
2392 default:
2393 qemu_printf("unsupported escape code: '\\%c'\n", c);
2394 goto fail;
2395 }
2396 if ((q - buf) < buf_size - 1) {
2397 *q++ = c;
2398 }
2399 } else {
2400 if ((q - buf) < buf_size - 1) {
2401 *q++ = *p;
2402 }
2403 p++;
2404 }
2405 }
2406 if (*p != '\"') {
bellard5b602122004-05-22 21:41:05 +00002407 qemu_printf("unterminated string\n");
bellard9307c4c2004-04-04 12:57:25 +00002408 goto fail;
2409 }
2410 p++;
2411 } else {
blueswir1cd390082008-11-16 13:53:32 +00002412 while (*p != '\0' && !qemu_isspace(*p)) {
bellard9307c4c2004-04-04 12:57:25 +00002413 if ((q - buf) < buf_size - 1) {
2414 *q++ = *p;
2415 }
2416 p++;
2417 }
bellard9307c4c2004-04-04 12:57:25 +00002418 }
bellard81d09122004-07-14 17:21:37 +00002419 *q = '\0';
bellard9307c4c2004-04-04 12:57:25 +00002420 *pp = p;
2421 return 0;
2422}
2423
Luiz Capitulino4590fd82009-06-09 18:21:30 -03002424/*
2425 * Store the command-name in cmdname, and return a pointer to
2426 * the remaining of the command string.
2427 */
2428static const char *get_command_name(const char *cmdline,
2429 char *cmdname, size_t nlen)
2430{
2431 size_t len;
2432 const char *p, *pstart;
2433
2434 p = cmdline;
2435 while (qemu_isspace(*p))
2436 p++;
2437 if (*p == '\0')
2438 return NULL;
2439 pstart = p;
2440 while (*p != '\0' && *p != '/' && !qemu_isspace(*p))
2441 p++;
2442 len = p - pstart;
2443 if (len > nlen - 1)
2444 len = nlen - 1;
2445 memcpy(cmdname, pstart, len);
2446 cmdname[len] = '\0';
2447 return p;
2448}
2449
bellard9307c4c2004-04-04 12:57:25 +00002450static int default_fmt_format = 'x';
2451static int default_fmt_size = 4;
2452
2453#define MAX_ARGS 16
2454
aliguori376253e2009-03-05 23:01:23 +00002455static void monitor_handle_command(Monitor *mon, const char *cmdline)
bellard9307c4c2004-04-04 12:57:25 +00002456{
Luiz Capitulino4590fd82009-06-09 18:21:30 -03002457 const char *p, *typestr;
2458 int c, nb_args, i, has_arg;
aliguori376253e2009-03-05 23:01:23 +00002459 const mon_cmd_t *cmd;
bellard9307c4c2004-04-04 12:57:25 +00002460 char cmdname[256];
2461 char buf[1024];
2462 void *str_allocated[MAX_ARGS];
2463 void *args[MAX_ARGS];
aliguori376253e2009-03-05 23:01:23 +00002464 void (*handler_0)(Monitor *mon);
2465 void (*handler_1)(Monitor *mon, void *arg0);
2466 void (*handler_2)(Monitor *mon, void *arg0, void *arg1);
2467 void (*handler_3)(Monitor *mon, void *arg0, void *arg1, void *arg2);
2468 void (*handler_4)(Monitor *mon, void *arg0, void *arg1, void *arg2,
2469 void *arg3);
2470 void (*handler_5)(Monitor *mon, void *arg0, void *arg1, void *arg2,
2471 void *arg3, void *arg4);
2472 void (*handler_6)(Monitor *mon, void *arg0, void *arg1, void *arg2,
2473 void *arg3, void *arg4, void *arg5);
2474 void (*handler_7)(Monitor *mon, void *arg0, void *arg1, void *arg2,
2475 void *arg3, void *arg4, void *arg5, void *arg6);
Huang Ying79c4f6b2009-06-23 10:05:14 +08002476 void (*handler_8)(Monitor *mon, void *arg0, void *arg1, void *arg2,
2477 void *arg3, void *arg4, void *arg5, void *arg6,
2478 void *arg7);
2479 void (*handler_9)(Monitor *mon, void *arg0, void *arg1, void *arg2,
2480 void *arg3, void *arg4, void *arg5, void *arg6,
2481 void *arg7, void *arg8);
2482 void (*handler_10)(Monitor *mon, void *arg0, void *arg1, void *arg2,
2483 void *arg3, void *arg4, void *arg5, void *arg6,
2484 void *arg7, void *arg8, void *arg9);
bellard9dc39cb2004-03-14 21:38:27 +00002485
2486#ifdef DEBUG
aliguori376253e2009-03-05 23:01:23 +00002487 monitor_printf(mon, "command='%s'\n", cmdline);
bellard9dc39cb2004-03-14 21:38:27 +00002488#endif
ths3b46e622007-09-17 08:09:54 +00002489
bellard9307c4c2004-04-04 12:57:25 +00002490 /* extract the command name */
Luiz Capitulino4590fd82009-06-09 18:21:30 -03002491 p = get_command_name(cmdline, cmdname, sizeof(cmdname));
2492 if (!p)
bellard9dc39cb2004-03-14 21:38:27 +00002493 return;
ths3b46e622007-09-17 08:09:54 +00002494
bellard9307c4c2004-04-04 12:57:25 +00002495 /* find the command */
aliguori376253e2009-03-05 23:01:23 +00002496 for(cmd = mon_cmds; cmd->name != NULL; cmd++) {
ths5fafdf22007-09-16 21:08:06 +00002497 if (compare_cmd(cmdname, cmd->name))
Luiz Capitulinod91d9bf2009-06-09 18:21:54 -03002498 break;
bellard9dc39cb2004-03-14 21:38:27 +00002499 }
Luiz Capitulinod91d9bf2009-06-09 18:21:54 -03002500
2501 if (cmd->name == NULL) {
2502 monitor_printf(mon, "unknown command: '%s'\n", cmdname);
2503 return;
2504 }
bellard9307c4c2004-04-04 12:57:25 +00002505
2506 for(i = 0; i < MAX_ARGS; i++)
2507 str_allocated[i] = NULL;
ths3b46e622007-09-17 08:09:54 +00002508
bellard9307c4c2004-04-04 12:57:25 +00002509 /* parse the parameters */
2510 typestr = cmd->args_type;
2511 nb_args = 0;
2512 for(;;) {
2513 c = *typestr;
2514 if (c == '\0')
2515 break;
2516 typestr++;
2517 switch(c) {
2518 case 'F':
bellard81d09122004-07-14 17:21:37 +00002519 case 'B':
bellard9307c4c2004-04-04 12:57:25 +00002520 case 's':
2521 {
2522 int ret;
2523 char *str;
ths3b46e622007-09-17 08:09:54 +00002524
blueswir1cd390082008-11-16 13:53:32 +00002525 while (qemu_isspace(*p))
bellard9307c4c2004-04-04 12:57:25 +00002526 p++;
2527 if (*typestr == '?') {
2528 typestr++;
2529 if (*p == '\0') {
2530 /* no optional string: NULL argument */
2531 str = NULL;
2532 goto add_str;
2533 }
2534 }
2535 ret = get_str(buf, sizeof(buf), &p);
2536 if (ret < 0) {
bellard81d09122004-07-14 17:21:37 +00002537 switch(c) {
2538 case 'F':
aliguori376253e2009-03-05 23:01:23 +00002539 monitor_printf(mon, "%s: filename expected\n",
2540 cmdname);
bellard81d09122004-07-14 17:21:37 +00002541 break;
2542 case 'B':
aliguori376253e2009-03-05 23:01:23 +00002543 monitor_printf(mon, "%s: block device name expected\n",
2544 cmdname);
bellard81d09122004-07-14 17:21:37 +00002545 break;
2546 default:
aliguori376253e2009-03-05 23:01:23 +00002547 monitor_printf(mon, "%s: string expected\n", cmdname);
bellard81d09122004-07-14 17:21:37 +00002548 break;
2549 }
bellard9307c4c2004-04-04 12:57:25 +00002550 goto fail;
2551 }
2552 str = qemu_malloc(strlen(buf) + 1);
blueswir1363a37d2008-08-21 17:58:08 +00002553 pstrcpy(str, sizeof(buf), buf);
bellard9307c4c2004-04-04 12:57:25 +00002554 str_allocated[nb_args] = str;
2555 add_str:
2556 if (nb_args >= MAX_ARGS) {
2557 error_args:
aliguori376253e2009-03-05 23:01:23 +00002558 monitor_printf(mon, "%s: too many arguments\n", cmdname);
bellard9307c4c2004-04-04 12:57:25 +00002559 goto fail;
2560 }
2561 args[nb_args++] = str;
2562 }
2563 break;
2564 case '/':
2565 {
2566 int count, format, size;
ths3b46e622007-09-17 08:09:54 +00002567
blueswir1cd390082008-11-16 13:53:32 +00002568 while (qemu_isspace(*p))
bellard9307c4c2004-04-04 12:57:25 +00002569 p++;
2570 if (*p == '/') {
2571 /* format found */
2572 p++;
2573 count = 1;
blueswir1cd390082008-11-16 13:53:32 +00002574 if (qemu_isdigit(*p)) {
bellard9307c4c2004-04-04 12:57:25 +00002575 count = 0;
blueswir1cd390082008-11-16 13:53:32 +00002576 while (qemu_isdigit(*p)) {
bellard9307c4c2004-04-04 12:57:25 +00002577 count = count * 10 + (*p - '0');
2578 p++;
2579 }
2580 }
2581 size = -1;
2582 format = -1;
2583 for(;;) {
2584 switch(*p) {
2585 case 'o':
2586 case 'd':
2587 case 'u':
2588 case 'x':
2589 case 'i':
2590 case 'c':
2591 format = *p++;
2592 break;
2593 case 'b':
2594 size = 1;
2595 p++;
2596 break;
2597 case 'h':
2598 size = 2;
2599 p++;
2600 break;
2601 case 'w':
2602 size = 4;
2603 p++;
2604 break;
2605 case 'g':
2606 case 'L':
2607 size = 8;
2608 p++;
2609 break;
2610 default:
2611 goto next;
2612 }
2613 }
2614 next:
blueswir1cd390082008-11-16 13:53:32 +00002615 if (*p != '\0' && !qemu_isspace(*p)) {
aliguori376253e2009-03-05 23:01:23 +00002616 monitor_printf(mon, "invalid char in format: '%c'\n",
2617 *p);
bellard9307c4c2004-04-04 12:57:25 +00002618 goto fail;
2619 }
bellard9307c4c2004-04-04 12:57:25 +00002620 if (format < 0)
2621 format = default_fmt_format;
bellard4c27ba22004-04-25 18:05:08 +00002622 if (format != 'i') {
2623 /* for 'i', not specifying a size gives -1 as size */
2624 if (size < 0)
2625 size = default_fmt_size;
aurel32e90f0092008-10-01 21:45:51 +00002626 default_fmt_size = size;
bellard4c27ba22004-04-25 18:05:08 +00002627 }
bellard9307c4c2004-04-04 12:57:25 +00002628 default_fmt_format = format;
2629 } else {
2630 count = 1;
2631 format = default_fmt_format;
bellard4c27ba22004-04-25 18:05:08 +00002632 if (format != 'i') {
2633 size = default_fmt_size;
2634 } else {
2635 size = -1;
2636 }
bellard9307c4c2004-04-04 12:57:25 +00002637 }
2638 if (nb_args + 3 > MAX_ARGS)
2639 goto error_args;
j_mayer1c5bf3b2007-04-14 12:17:59 +00002640 args[nb_args++] = (void*)(long)count;
2641 args[nb_args++] = (void*)(long)format;
2642 args[nb_args++] = (void*)(long)size;
bellard9307c4c2004-04-04 12:57:25 +00002643 }
2644 break;
2645 case 'i':
bellard92a31b12005-02-10 22:00:52 +00002646 case 'l':
bellard9307c4c2004-04-04 12:57:25 +00002647 {
blueswir1c2efc952007-09-25 17:28:42 +00002648 int64_t val;
blueswir17743e582007-09-24 18:39:04 +00002649
blueswir1cd390082008-11-16 13:53:32 +00002650 while (qemu_isspace(*p))
bellard9307c4c2004-04-04 12:57:25 +00002651 p++;
bellard34405572004-06-08 00:55:58 +00002652 if (*typestr == '?' || *typestr == '.') {
bellard34405572004-06-08 00:55:58 +00002653 if (*typestr == '?') {
2654 if (*p == '\0')
2655 has_arg = 0;
2656 else
2657 has_arg = 1;
2658 } else {
2659 if (*p == '.') {
2660 p++;
blueswir1cd390082008-11-16 13:53:32 +00002661 while (qemu_isspace(*p))
bellard34405572004-06-08 00:55:58 +00002662 p++;
2663 has_arg = 1;
2664 } else {
2665 has_arg = 0;
2666 }
2667 }
bellard13224a82006-07-14 22:03:35 +00002668 typestr++;
bellard9307c4c2004-04-04 12:57:25 +00002669 if (nb_args >= MAX_ARGS)
2670 goto error_args;
j_mayer1c5bf3b2007-04-14 12:17:59 +00002671 args[nb_args++] = (void *)(long)has_arg;
bellard9307c4c2004-04-04 12:57:25 +00002672 if (!has_arg) {
2673 if (nb_args >= MAX_ARGS)
2674 goto error_args;
2675 val = -1;
2676 goto add_num;
2677 }
2678 }
aliguori376253e2009-03-05 23:01:23 +00002679 if (get_expr(mon, &val, &p))
bellard9307c4c2004-04-04 12:57:25 +00002680 goto fail;
2681 add_num:
bellard92a31b12005-02-10 22:00:52 +00002682 if (c == 'i') {
2683 if (nb_args >= MAX_ARGS)
2684 goto error_args;
j_mayer1c5bf3b2007-04-14 12:17:59 +00002685 args[nb_args++] = (void *)(long)val;
bellard92a31b12005-02-10 22:00:52 +00002686 } else {
2687 if ((nb_args + 1) >= MAX_ARGS)
2688 goto error_args;
blueswir17743e582007-09-24 18:39:04 +00002689#if TARGET_PHYS_ADDR_BITS > 32
j_mayer1c5bf3b2007-04-14 12:17:59 +00002690 args[nb_args++] = (void *)(long)((val >> 32) & 0xffffffff);
bellard92a31b12005-02-10 22:00:52 +00002691#else
2692 args[nb_args++] = (void *)0;
2693#endif
j_mayer1c5bf3b2007-04-14 12:17:59 +00002694 args[nb_args++] = (void *)(long)(val & 0xffffffff);
bellard92a31b12005-02-10 22:00:52 +00002695 }
bellard9307c4c2004-04-04 12:57:25 +00002696 }
2697 break;
2698 case '-':
2699 {
2700 int has_option;
2701 /* option */
ths3b46e622007-09-17 08:09:54 +00002702
bellard9307c4c2004-04-04 12:57:25 +00002703 c = *typestr++;
2704 if (c == '\0')
2705 goto bad_type;
blueswir1cd390082008-11-16 13:53:32 +00002706 while (qemu_isspace(*p))
bellard9307c4c2004-04-04 12:57:25 +00002707 p++;
2708 has_option = 0;
2709 if (*p == '-') {
2710 p++;
2711 if (*p != c) {
aliguori376253e2009-03-05 23:01:23 +00002712 monitor_printf(mon, "%s: unsupported option -%c\n",
2713 cmdname, *p);
bellard9307c4c2004-04-04 12:57:25 +00002714 goto fail;
2715 }
2716 p++;
2717 has_option = 1;
2718 }
2719 if (nb_args >= MAX_ARGS)
2720 goto error_args;
j_mayer1c5bf3b2007-04-14 12:17:59 +00002721 args[nb_args++] = (void *)(long)has_option;
bellard9307c4c2004-04-04 12:57:25 +00002722 }
2723 break;
2724 default:
2725 bad_type:
aliguori376253e2009-03-05 23:01:23 +00002726 monitor_printf(mon, "%s: unknown type '%c'\n", cmdname, c);
bellard9307c4c2004-04-04 12:57:25 +00002727 goto fail;
2728 }
2729 }
2730 /* check that all arguments were parsed */
blueswir1cd390082008-11-16 13:53:32 +00002731 while (qemu_isspace(*p))
bellard9307c4c2004-04-04 12:57:25 +00002732 p++;
2733 if (*p != '\0') {
aliguori376253e2009-03-05 23:01:23 +00002734 monitor_printf(mon, "%s: extraneous characters at the end of line\n",
2735 cmdname);
bellard9307c4c2004-04-04 12:57:25 +00002736 goto fail;
2737 }
2738
2739 switch(nb_args) {
2740 case 0:
blueswir1a5f1b962008-08-17 20:21:51 +00002741 handler_0 = cmd->handler;
aliguori376253e2009-03-05 23:01:23 +00002742 handler_0(mon);
bellard9307c4c2004-04-04 12:57:25 +00002743 break;
2744 case 1:
blueswir1a5f1b962008-08-17 20:21:51 +00002745 handler_1 = cmd->handler;
aliguori376253e2009-03-05 23:01:23 +00002746 handler_1(mon, args[0]);
bellard9307c4c2004-04-04 12:57:25 +00002747 break;
2748 case 2:
blueswir1a5f1b962008-08-17 20:21:51 +00002749 handler_2 = cmd->handler;
aliguori376253e2009-03-05 23:01:23 +00002750 handler_2(mon, args[0], args[1]);
bellard9307c4c2004-04-04 12:57:25 +00002751 break;
2752 case 3:
blueswir1a5f1b962008-08-17 20:21:51 +00002753 handler_3 = cmd->handler;
aliguori376253e2009-03-05 23:01:23 +00002754 handler_3(mon, args[0], args[1], args[2]);
bellard9307c4c2004-04-04 12:57:25 +00002755 break;
2756 case 4:
blueswir1a5f1b962008-08-17 20:21:51 +00002757 handler_4 = cmd->handler;
aliguori376253e2009-03-05 23:01:23 +00002758 handler_4(mon, args[0], args[1], args[2], args[3]);
bellard9307c4c2004-04-04 12:57:25 +00002759 break;
2760 case 5:
blueswir1a5f1b962008-08-17 20:21:51 +00002761 handler_5 = cmd->handler;
aliguori376253e2009-03-05 23:01:23 +00002762 handler_5(mon, args[0], args[1], args[2], args[3], args[4]);
bellard9307c4c2004-04-04 12:57:25 +00002763 break;
bellard34405572004-06-08 00:55:58 +00002764 case 6:
blueswir1a5f1b962008-08-17 20:21:51 +00002765 handler_6 = cmd->handler;
aliguori376253e2009-03-05 23:01:23 +00002766 handler_6(mon, args[0], args[1], args[2], args[3], args[4], args[5]);
bellard34405572004-06-08 00:55:58 +00002767 break;
bellardec36b692006-07-16 18:57:03 +00002768 case 7:
blueswir1a5f1b962008-08-17 20:21:51 +00002769 handler_7 = cmd->handler;
aliguori376253e2009-03-05 23:01:23 +00002770 handler_7(mon, args[0], args[1], args[2], args[3], args[4], args[5],
2771 args[6]);
bellardec36b692006-07-16 18:57:03 +00002772 break;
Huang Ying79c4f6b2009-06-23 10:05:14 +08002773 case 8:
2774 handler_8 = cmd->handler;
2775 handler_8(mon, args[0], args[1], args[2], args[3], args[4], args[5],
2776 args[6], args[7]);
2777 break;
2778 case 9:
2779 handler_9 = cmd->handler;
2780 handler_9(mon, args[0], args[1], args[2], args[3], args[4], args[5],
2781 args[6], args[7], args[8]);
2782 break;
2783 case 10:
2784 handler_10 = cmd->handler;
2785 handler_10(mon, args[0], args[1], args[2], args[3], args[4], args[5],
2786 args[6], args[7], args[8], args[9]);
2787 break;
bellard9307c4c2004-04-04 12:57:25 +00002788 default:
aliguori376253e2009-03-05 23:01:23 +00002789 monitor_printf(mon, "unsupported number of arguments: %d\n", nb_args);
bellard9307c4c2004-04-04 12:57:25 +00002790 goto fail;
2791 }
2792 fail:
2793 for(i = 0; i < MAX_ARGS; i++)
2794 qemu_free(str_allocated[i]);
bellard9dc39cb2004-03-14 21:38:27 +00002795}
2796
bellard81d09122004-07-14 17:21:37 +00002797static void cmd_completion(const char *name, const char *list)
2798{
2799 const char *p, *pstart;
2800 char cmd[128];
2801 int len;
2802
2803 p = list;
2804 for(;;) {
2805 pstart = p;
2806 p = strchr(p, '|');
2807 if (!p)
2808 p = pstart + strlen(pstart);
2809 len = p - pstart;
2810 if (len > sizeof(cmd) - 2)
2811 len = sizeof(cmd) - 2;
2812 memcpy(cmd, pstart, len);
2813 cmd[len] = '\0';
2814 if (name[0] == '\0' || !strncmp(name, cmd, strlen(name))) {
aliguori731b0362009-03-05 23:01:42 +00002815 readline_add_completion(cur_mon->rs, cmd);
bellard81d09122004-07-14 17:21:37 +00002816 }
2817 if (*p == '\0')
2818 break;
2819 p++;
2820 }
2821}
2822
2823static void file_completion(const char *input)
2824{
2825 DIR *ffs;
2826 struct dirent *d;
2827 char path[1024];
2828 char file[1024], file_prefix[1024];
2829 int input_path_len;
2830 const char *p;
2831
ths5fafdf22007-09-16 21:08:06 +00002832 p = strrchr(input, '/');
bellard81d09122004-07-14 17:21:37 +00002833 if (!p) {
2834 input_path_len = 0;
2835 pstrcpy(file_prefix, sizeof(file_prefix), input);
blueswir1363a37d2008-08-21 17:58:08 +00002836 pstrcpy(path, sizeof(path), ".");
bellard81d09122004-07-14 17:21:37 +00002837 } else {
2838 input_path_len = p - input + 1;
2839 memcpy(path, input, input_path_len);
2840 if (input_path_len > sizeof(path) - 1)
2841 input_path_len = sizeof(path) - 1;
2842 path[input_path_len] = '\0';
2843 pstrcpy(file_prefix, sizeof(file_prefix), p + 1);
2844 }
2845#ifdef DEBUG_COMPLETION
aliguori376253e2009-03-05 23:01:23 +00002846 monitor_printf(cur_mon, "input='%s' path='%s' prefix='%s'\n",
2847 input, path, file_prefix);
bellard81d09122004-07-14 17:21:37 +00002848#endif
2849 ffs = opendir(path);
2850 if (!ffs)
2851 return;
2852 for(;;) {
2853 struct stat sb;
2854 d = readdir(ffs);
2855 if (!d)
2856 break;
2857 if (strstart(d->d_name, file_prefix, NULL)) {
2858 memcpy(file, input, input_path_len);
blueswir1363a37d2008-08-21 17:58:08 +00002859 if (input_path_len < sizeof(file))
2860 pstrcpy(file + input_path_len, sizeof(file) - input_path_len,
2861 d->d_name);
bellard81d09122004-07-14 17:21:37 +00002862 /* stat the file to find out if it's a directory.
2863 * In that case add a slash to speed up typing long paths
2864 */
2865 stat(file, &sb);
2866 if(S_ISDIR(sb.st_mode))
blueswir1363a37d2008-08-21 17:58:08 +00002867 pstrcat(file, sizeof(file), "/");
aliguori731b0362009-03-05 23:01:42 +00002868 readline_add_completion(cur_mon->rs, file);
bellard81d09122004-07-14 17:21:37 +00002869 }
2870 }
2871 closedir(ffs);
2872}
2873
aliguori51de9762009-03-05 23:00:43 +00002874static void block_completion_it(void *opaque, BlockDriverState *bs)
bellard81d09122004-07-14 17:21:37 +00002875{
aliguori51de9762009-03-05 23:00:43 +00002876 const char *name = bdrv_get_device_name(bs);
bellard81d09122004-07-14 17:21:37 +00002877 const char *input = opaque;
2878
2879 if (input[0] == '\0' ||
2880 !strncmp(name, (char *)input, strlen(input))) {
aliguori731b0362009-03-05 23:01:42 +00002881 readline_add_completion(cur_mon->rs, name);
bellard81d09122004-07-14 17:21:37 +00002882 }
2883}
2884
2885/* NOTE: this parser is an approximate form of the real command parser */
2886static void parse_cmdline(const char *cmdline,
2887 int *pnb_args, char **args)
2888{
2889 const char *p;
2890 int nb_args, ret;
2891 char buf[1024];
2892
2893 p = cmdline;
2894 nb_args = 0;
2895 for(;;) {
blueswir1cd390082008-11-16 13:53:32 +00002896 while (qemu_isspace(*p))
bellard81d09122004-07-14 17:21:37 +00002897 p++;
2898 if (*p == '\0')
2899 break;
2900 if (nb_args >= MAX_ARGS)
2901 break;
2902 ret = get_str(buf, sizeof(buf), &p);
2903 args[nb_args] = qemu_strdup(buf);
2904 nb_args++;
2905 if (ret < 0)
2906 break;
2907 }
2908 *pnb_args = nb_args;
2909}
2910
aliguori4c36ba32009-03-05 23:01:37 +00002911static void monitor_find_completion(const char *cmdline)
bellard81d09122004-07-14 17:21:37 +00002912{
2913 const char *cmdname;
2914 char *args[MAX_ARGS];
2915 int nb_args, i, len;
2916 const char *ptype, *str;
aliguori376253e2009-03-05 23:01:23 +00002917 const mon_cmd_t *cmd;
bellard64866c32006-05-07 18:03:31 +00002918 const KeyDef *key;
bellard81d09122004-07-14 17:21:37 +00002919
2920 parse_cmdline(cmdline, &nb_args, args);
2921#ifdef DEBUG_COMPLETION
2922 for(i = 0; i < nb_args; i++) {
aliguori376253e2009-03-05 23:01:23 +00002923 monitor_printf(cur_mon, "arg%d = '%s'\n", i, (char *)args[i]);
bellard81d09122004-07-14 17:21:37 +00002924 }
2925#endif
2926
2927 /* if the line ends with a space, it means we want to complete the
2928 next arg */
2929 len = strlen(cmdline);
blueswir1cd390082008-11-16 13:53:32 +00002930 if (len > 0 && qemu_isspace(cmdline[len - 1])) {
bellard81d09122004-07-14 17:21:37 +00002931 if (nb_args >= MAX_ARGS)
2932 return;
2933 args[nb_args++] = qemu_strdup("");
2934 }
2935 if (nb_args <= 1) {
2936 /* command completion */
2937 if (nb_args == 0)
2938 cmdname = "";
2939 else
2940 cmdname = args[0];
aliguori731b0362009-03-05 23:01:42 +00002941 readline_set_completion_index(cur_mon->rs, strlen(cmdname));
aliguori376253e2009-03-05 23:01:23 +00002942 for(cmd = mon_cmds; cmd->name != NULL; cmd++) {
bellard81d09122004-07-14 17:21:37 +00002943 cmd_completion(cmdname, cmd->name);
2944 }
2945 } else {
2946 /* find the command */
aliguori376253e2009-03-05 23:01:23 +00002947 for(cmd = mon_cmds; cmd->name != NULL; cmd++) {
bellard81d09122004-07-14 17:21:37 +00002948 if (compare_cmd(args[0], cmd->name))
2949 goto found;
2950 }
2951 return;
2952 found:
2953 ptype = cmd->args_type;
2954 for(i = 0; i < nb_args - 2; i++) {
2955 if (*ptype != '\0') {
2956 ptype++;
2957 while (*ptype == '?')
2958 ptype++;
2959 }
2960 }
2961 str = args[nb_args - 1];
2962 switch(*ptype) {
2963 case 'F':
2964 /* file completion */
aliguori731b0362009-03-05 23:01:42 +00002965 readline_set_completion_index(cur_mon->rs, strlen(str));
bellard81d09122004-07-14 17:21:37 +00002966 file_completion(str);
2967 break;
2968 case 'B':
2969 /* block device name completion */
aliguori731b0362009-03-05 23:01:42 +00002970 readline_set_completion_index(cur_mon->rs, strlen(str));
bellard81d09122004-07-14 17:21:37 +00002971 bdrv_iterate(block_completion_it, (void *)str);
2972 break;
bellard7fe48482004-10-09 18:08:01 +00002973 case 's':
2974 /* XXX: more generic ? */
2975 if (!strcmp(cmd->name, "info")) {
aliguori731b0362009-03-05 23:01:42 +00002976 readline_set_completion_index(cur_mon->rs, strlen(str));
bellard7fe48482004-10-09 18:08:01 +00002977 for(cmd = info_cmds; cmd->name != NULL; cmd++) {
2978 cmd_completion(str, cmd->name);
2979 }
bellard64866c32006-05-07 18:03:31 +00002980 } else if (!strcmp(cmd->name, "sendkey")) {
blueswir1e600d1e2009-03-08 17:42:02 +00002981 char *sep = strrchr(str, '-');
2982 if (sep)
2983 str = sep + 1;
aliguori731b0362009-03-05 23:01:42 +00002984 readline_set_completion_index(cur_mon->rs, strlen(str));
bellard64866c32006-05-07 18:03:31 +00002985 for(key = key_defs; key->name != NULL; key++) {
2986 cmd_completion(str, key->name);
2987 }
Jan Kiszkaf3353c62009-06-25 08:22:02 +02002988 } else if (!strcmp(cmd->name, "help|?")) {
2989 readline_set_completion_index(cur_mon->rs, strlen(str));
2990 for (cmd = mon_cmds; cmd->name != NULL; cmd++) {
2991 cmd_completion(str, cmd->name);
2992 }
bellard7fe48482004-10-09 18:08:01 +00002993 }
2994 break;
bellard81d09122004-07-14 17:21:37 +00002995 default:
2996 break;
2997 }
2998 }
2999 for(i = 0; i < nb_args; i++)
3000 qemu_free(args[i]);
3001}
3002
aliguori731b0362009-03-05 23:01:42 +00003003static int monitor_can_read(void *opaque)
bellard9dc39cb2004-03-14 21:38:27 +00003004{
aliguori731b0362009-03-05 23:01:42 +00003005 Monitor *mon = opaque;
3006
3007 return (mon->suspend_cnt == 0) ? 128 : 0;
bellard9dc39cb2004-03-14 21:38:27 +00003008}
3009
aliguori731b0362009-03-05 23:01:42 +00003010static void monitor_read(void *opaque, const uint8_t *buf, int size)
bellard9dc39cb2004-03-14 21:38:27 +00003011{
aliguori731b0362009-03-05 23:01:42 +00003012 Monitor *old_mon = cur_mon;
bellard9dc39cb2004-03-14 21:38:27 +00003013 int i;
aliguori376253e2009-03-05 23:01:23 +00003014
aliguori731b0362009-03-05 23:01:42 +00003015 cur_mon = opaque;
bellard7e2515e2004-08-01 21:52:19 +00003016
aliguoricde76ee2009-03-05 23:01:51 +00003017 if (cur_mon->rs) {
3018 for (i = 0; i < size; i++)
3019 readline_handle_byte(cur_mon->rs, buf[i]);
3020 } else {
3021 if (size == 0 || buf[size - 1] != 0)
3022 monitor_printf(cur_mon, "corrupted command\n");
3023 else
3024 monitor_handle_command(cur_mon, (char *)buf);
3025 }
aliguori731b0362009-03-05 23:01:42 +00003026
3027 cur_mon = old_mon;
3028}
aliguorid8f44602008-10-06 13:52:44 +00003029
aliguori376253e2009-03-05 23:01:23 +00003030static void monitor_command_cb(Monitor *mon, const char *cmdline, void *opaque)
bellard7e2515e2004-08-01 21:52:19 +00003031{
aliguori731b0362009-03-05 23:01:42 +00003032 monitor_suspend(mon);
aliguori376253e2009-03-05 23:01:23 +00003033 monitor_handle_command(mon, cmdline);
aliguori731b0362009-03-05 23:01:42 +00003034 monitor_resume(mon);
aliguorid8f44602008-10-06 13:52:44 +00003035}
3036
aliguoricde76ee2009-03-05 23:01:51 +00003037int monitor_suspend(Monitor *mon)
aliguorid8f44602008-10-06 13:52:44 +00003038{
aliguoricde76ee2009-03-05 23:01:51 +00003039 if (!mon->rs)
3040 return -ENOTTY;
aliguori731b0362009-03-05 23:01:42 +00003041 mon->suspend_cnt++;
aliguoricde76ee2009-03-05 23:01:51 +00003042 return 0;
aliguorid8f44602008-10-06 13:52:44 +00003043}
3044
aliguori376253e2009-03-05 23:01:23 +00003045void monitor_resume(Monitor *mon)
aliguorid8f44602008-10-06 13:52:44 +00003046{
aliguoricde76ee2009-03-05 23:01:51 +00003047 if (!mon->rs)
3048 return;
aliguori731b0362009-03-05 23:01:42 +00003049 if (--mon->suspend_cnt == 0)
3050 readline_show_prompt(mon->rs);
bellard7e2515e2004-08-01 21:52:19 +00003051}
3052
aliguori731b0362009-03-05 23:01:42 +00003053static void monitor_event(void *opaque, int event)
ths86e94de2007-01-05 22:01:59 +00003054{
aliguori376253e2009-03-05 23:01:23 +00003055 Monitor *mon = opaque;
3056
aliguori2724b182009-03-05 23:01:47 +00003057 switch (event) {
3058 case CHR_EVENT_MUX_IN:
3059 readline_restart(mon->rs);
3060 monitor_resume(mon);
3061 monitor_flush(mon);
3062 break;
ths86e94de2007-01-05 22:01:59 +00003063
aliguori2724b182009-03-05 23:01:47 +00003064 case CHR_EVENT_MUX_OUT:
3065 if (mon->suspend_cnt == 0)
3066 monitor_printf(mon, "\n");
3067 monitor_flush(mon);
3068 monitor_suspend(mon);
3069 break;
3070
3071 case CHR_EVENT_RESET:
3072 monitor_printf(mon, "QEMU %s monitor - type 'help' for more "
3073 "information\n", QEMU_VERSION);
3074 if (mon->chr->focus == 0)
3075 readline_show_prompt(mon->rs);
3076 break;
3077 }
ths86e94de2007-01-05 22:01:59 +00003078}
3079
aliguori76655d62009-03-06 20:27:37 +00003080
3081/*
3082 * Local variables:
3083 * c-indent-level: 4
3084 * c-basic-offset: 4
3085 * tab-width: 8
3086 * End:
3087 */
3088
aliguori731b0362009-03-05 23:01:42 +00003089void monitor_init(CharDriverState *chr, int flags)
bellard9dc39cb2004-03-14 21:38:27 +00003090{
aliguori731b0362009-03-05 23:01:42 +00003091 static int is_first_init = 1;
aliguori87127162009-03-05 23:01:29 +00003092 Monitor *mon;
ths20d8a3e2007-02-18 17:04:49 +00003093
3094 if (is_first_init) {
balrogc8256f92008-06-08 22:45:01 +00003095 key_timer = qemu_new_timer(vm_clock, release_keys, NULL);
ths20d8a3e2007-02-18 17:04:49 +00003096 is_first_init = 0;
3097 }
aliguori87127162009-03-05 23:01:29 +00003098
3099 mon = qemu_mallocz(sizeof(*mon));
ths20d8a3e2007-02-18 17:04:49 +00003100
aliguori87127162009-03-05 23:01:29 +00003101 mon->chr = chr;
aliguori731b0362009-03-05 23:01:42 +00003102 mon->flags = flags;
aliguori2724b182009-03-05 23:01:47 +00003103 if (mon->chr->focus != 0)
3104 mon->suspend_cnt = 1; /* mux'ed monitors start suspended */
aliguoricde76ee2009-03-05 23:01:51 +00003105 if (flags & MONITOR_USE_READLINE) {
3106 mon->rs = readline_init(mon, monitor_find_completion);
3107 monitor_read_command(mon, 0);
3108 }
aliguori87127162009-03-05 23:01:29 +00003109
aliguori731b0362009-03-05 23:01:42 +00003110 qemu_chr_add_handlers(chr, monitor_can_read, monitor_read, monitor_event,
3111 mon);
aliguori87127162009-03-05 23:01:29 +00003112
3113 LIST_INSERT_HEAD(&mon_list, mon, entry);
aliguori731b0362009-03-05 23:01:42 +00003114 if (!cur_mon || (flags & MONITOR_IS_DEFAULT))
aliguori87127162009-03-05 23:01:29 +00003115 cur_mon = mon;
bellard7e2515e2004-08-01 21:52:19 +00003116}
3117
aliguori376253e2009-03-05 23:01:23 +00003118static void bdrv_password_cb(Monitor *mon, const char *password, void *opaque)
bellard7e2515e2004-08-01 21:52:19 +00003119{
aliguoribb5fc202009-03-05 23:01:15 +00003120 BlockDriverState *bs = opaque;
3121 int ret = 0;
bellard7e2515e2004-08-01 21:52:19 +00003122
aliguoribb5fc202009-03-05 23:01:15 +00003123 if (bdrv_set_key(bs, password) != 0) {
aliguori376253e2009-03-05 23:01:23 +00003124 monitor_printf(mon, "invalid password\n");
aliguoribb5fc202009-03-05 23:01:15 +00003125 ret = -EPERM;
bellard7e2515e2004-08-01 21:52:19 +00003126 }
aliguori731b0362009-03-05 23:01:42 +00003127 if (mon->password_completion_cb)
3128 mon->password_completion_cb(mon->password_opaque, ret);
aliguoribb5fc202009-03-05 23:01:15 +00003129
aliguori731b0362009-03-05 23:01:42 +00003130 monitor_read_command(mon, 1);
bellard9dc39cb2004-03-14 21:38:27 +00003131}
aliguoric0f4ce72009-03-05 23:01:01 +00003132
aliguori376253e2009-03-05 23:01:23 +00003133void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
aliguoribb5fc202009-03-05 23:01:15 +00003134 BlockDriverCompletionFunc *completion_cb,
3135 void *opaque)
aliguoric0f4ce72009-03-05 23:01:01 +00003136{
aliguoricde76ee2009-03-05 23:01:51 +00003137 int err;
3138
aliguoribb5fc202009-03-05 23:01:15 +00003139 if (!bdrv_key_required(bs)) {
3140 if (completion_cb)
3141 completion_cb(opaque, 0);
3142 return;
3143 }
aliguoric0f4ce72009-03-05 23:01:01 +00003144
aliguori376253e2009-03-05 23:01:23 +00003145 monitor_printf(mon, "%s (%s) is encrypted.\n", bdrv_get_device_name(bs),
3146 bdrv_get_encrypted_filename(bs));
aliguoribb5fc202009-03-05 23:01:15 +00003147
aliguori731b0362009-03-05 23:01:42 +00003148 mon->password_completion_cb = completion_cb;
3149 mon->password_opaque = opaque;
aliguoribb5fc202009-03-05 23:01:15 +00003150
aliguoricde76ee2009-03-05 23:01:51 +00003151 err = monitor_read_password(mon, bdrv_password_cb, bs);
3152
3153 if (err && completion_cb)
3154 completion_cb(opaque, err);
aliguoric0f4ce72009-03-05 23:01:01 +00003155}