4 * Copyright (c) 2003-2004 Fabrice Bellard
6 * 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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
26 #include "hw/pcmcia.h"
31 #include "qemu-char.h"
37 #include "audio/audio.h"
41 #include "qemu-timer.h"
42 #include "migration.h"
46 //#define DEBUG_COMPLETION
52 * 'B' block device name
53 * 's' string (accept optional quote)
55 * 'l' target long (32 or 64 bit)
56 * '/' optional gdb-like print format (like "/10x")
58 * '?' optional type (for 'F', 's' and 'i')
62 typedef struct mon_cmd_t
{
64 const char *args_type
;
72 LIST_ENTRY(Monitor
) entry
;
75 static LIST_HEAD(mon_list
, Monitor
) mon_list
;
76 static int hide_banner
;
78 static const mon_cmd_t mon_cmds
[];
79 static const mon_cmd_t info_cmds
[];
81 static uint8_t term_outbuf
[1024];
82 static int term_outbuf_index
;
83 static BlockDriverCompletionFunc
*password_completion_cb
;
84 static void *password_opaque
;
86 Monitor
*cur_mon
= NULL
;
88 static void monitor_start_input(void);
90 static CPUState
*mon_cpu
= NULL
;
92 static void monitor_read_password(Monitor
*mon
, ReadLineFunc
*readline_func
,
95 readline_start("Password: ", 1, readline_func
, opaque
);
98 void monitor_flush(Monitor
*mon
)
102 if (term_outbuf_index
> 0) {
103 LIST_FOREACH(m
, &mon_list
, entry
) {
104 if (m
->chr
->focus
== 0)
105 qemu_chr_write(m
->chr
, term_outbuf
, term_outbuf_index
);
107 term_outbuf_index
= 0;
111 /* flush at every end of line or if the buffer is full */
112 static void monitor_puts(Monitor
*mon
, const char *str
)
120 term_outbuf
[term_outbuf_index
++] = '\r';
121 term_outbuf
[term_outbuf_index
++] = c
;
122 if (term_outbuf_index
>= (sizeof(term_outbuf
) - 1) ||
128 void monitor_vprintf(Monitor
*mon
, const char *fmt
, va_list ap
)
131 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
132 monitor_puts(mon
, buf
);
135 void monitor_printf(Monitor
*mon
, const char *fmt
, ...)
139 monitor_vprintf(mon
, fmt
, ap
);
143 void monitor_print_filename(Monitor
*mon
, const char *filename
)
147 for (i
= 0; filename
[i
]; i
++) {
148 switch (filename
[i
]) {
152 monitor_printf(mon
, "\\%c", filename
[i
]);
155 monitor_printf(mon
, "\\t");
158 monitor_printf(mon
, "\\r");
161 monitor_printf(mon
, "\\n");
164 monitor_printf(mon
, "%c", filename
[i
]);
170 static int monitor_fprintf(FILE *stream
, const char *fmt
, ...)
174 monitor_vprintf((Monitor
*)stream
, fmt
, ap
);
179 static int compare_cmd(const char *name
, const char *list
)
181 const char *p
, *pstart
;
189 p
= pstart
+ strlen(pstart
);
190 if ((p
- pstart
) == len
&& !memcmp(pstart
, name
, len
))
199 static void help_cmd_dump(Monitor
*mon
, const mon_cmd_t
*cmds
,
200 const char *prefix
, const char *name
)
202 const mon_cmd_t
*cmd
;
204 for(cmd
= cmds
; cmd
->name
!= NULL
; cmd
++) {
205 if (!name
|| !strcmp(name
, cmd
->name
))
206 monitor_printf(mon
, "%s%s %s -- %s\n", prefix
, cmd
->name
,
207 cmd
->params
, cmd
->help
);
211 static void help_cmd(Monitor
*mon
, const char *name
)
213 if (name
&& !strcmp(name
, "info")) {
214 help_cmd_dump(mon
, info_cmds
, "info ", NULL
);
216 help_cmd_dump(mon
, mon_cmds
, "", name
);
217 if (name
&& !strcmp(name
, "log")) {
218 const CPULogItem
*item
;
219 monitor_printf(mon
, "Log items (comma separated):\n");
220 monitor_printf(mon
, "%-10s %s\n", "none", "remove all logs");
221 for(item
= cpu_log_items
; item
->mask
!= 0; item
++) {
222 monitor_printf(mon
, "%-10s %s\n", item
->name
, item
->help
);
228 static void do_commit(Monitor
*mon
, const char *device
)
232 all_devices
= !strcmp(device
, "all");
233 for (i
= 0; i
< nb_drives
; i
++) {
235 !strcmp(bdrv_get_device_name(drives_table
[i
].bdrv
), device
))
236 bdrv_commit(drives_table
[i
].bdrv
);
240 static void do_info(Monitor
*mon
, const char *item
)
242 const mon_cmd_t
*cmd
;
243 void (*handler
)(Monitor
*);
247 for(cmd
= info_cmds
; cmd
->name
!= NULL
; cmd
++) {
248 if (compare_cmd(item
, cmd
->name
))
252 help_cmd(mon
, "info");
255 handler
= cmd
->handler
;
259 static void do_info_version(Monitor
*mon
)
261 monitor_printf(mon
, "%s\n", QEMU_VERSION
);
264 static void do_info_name(Monitor
*mon
)
267 monitor_printf(mon
, "%s\n", qemu_name
);
270 #if defined(TARGET_I386)
271 static void do_info_hpet(Monitor
*mon
)
273 monitor_printf(mon
, "HPET is %s by QEMU\n",
274 (no_hpet
) ? "disabled" : "enabled");
278 static void do_info_uuid(Monitor
*mon
)
280 monitor_printf(mon
, UUID_FMT
"\n", qemu_uuid
[0], qemu_uuid
[1],
281 qemu_uuid
[2], qemu_uuid
[3], qemu_uuid
[4], qemu_uuid
[5],
282 qemu_uuid
[6], qemu_uuid
[7], qemu_uuid
[8], qemu_uuid
[9],
283 qemu_uuid
[10], qemu_uuid
[11], qemu_uuid
[12], qemu_uuid
[13],
284 qemu_uuid
[14], qemu_uuid
[15]);
287 /* get the current CPU defined by the user */
288 static int mon_set_cpu(int cpu_index
)
292 for(env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
293 if (env
->cpu_index
== cpu_index
) {
301 static CPUState
*mon_get_cpu(void)
309 static void do_info_registers(Monitor
*mon
)
316 cpu_dump_state(env
, (FILE *)mon
, monitor_fprintf
,
319 cpu_dump_state(env
, (FILE *)mon
, monitor_fprintf
,
324 static void do_info_cpus(Monitor
*mon
)
328 /* just to set the default cpu if not already done */
331 for(env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
332 monitor_printf(mon
, "%c CPU #%d:",
333 (env
== mon_cpu
) ? '*' : ' ',
335 #if defined(TARGET_I386)
336 monitor_printf(mon
, " pc=0x" TARGET_FMT_lx
,
337 env
->eip
+ env
->segs
[R_CS
].base
);
338 #elif defined(TARGET_PPC)
339 monitor_printf(mon
, " nip=0x" TARGET_FMT_lx
, env
->nip
);
340 #elif defined(TARGET_SPARC)
341 monitor_printf(mon
, " pc=0x" TARGET_FMT_lx
" npc=0x" TARGET_FMT_lx
,
343 #elif defined(TARGET_MIPS)
344 monitor_printf(mon
, " PC=0x" TARGET_FMT_lx
, env
->active_tc
.PC
);
347 monitor_printf(mon
, " (halted)");
348 monitor_printf(mon
, "\n");
352 static void do_cpu_set(Monitor
*mon
, int index
)
354 if (mon_set_cpu(index
) < 0)
355 monitor_printf(mon
, "Invalid CPU index\n");
358 static void do_info_jit(Monitor
*mon
)
360 dump_exec_info((FILE *)mon
, monitor_fprintf
);
363 static void do_info_history(Monitor
*mon
)
370 str
= readline_get_history(i
);
373 monitor_printf(mon
, "%d: '%s'\n", i
, str
);
378 #if defined(TARGET_PPC)
379 /* XXX: not implemented in other targets */
380 static void do_info_cpu_stats(Monitor
*mon
)
385 cpu_dump_statistics(env
, (FILE *)mon
, &monitor_fprintf
, 0);
389 static void do_quit(Monitor
*mon
)
394 static int eject_device(Monitor
*mon
, BlockDriverState
*bs
, int force
)
396 if (bdrv_is_inserted(bs
)) {
398 if (!bdrv_is_removable(bs
)) {
399 monitor_printf(mon
, "device is not removable\n");
402 if (bdrv_is_locked(bs
)) {
403 monitor_printf(mon
, "device is locked\n");
412 static void do_eject(Monitor
*mon
, int force
, const char *filename
)
414 BlockDriverState
*bs
;
416 bs
= bdrv_find(filename
);
418 monitor_printf(mon
, "device not found\n");
421 eject_device(mon
, bs
, force
);
424 static void do_change_block(Monitor
*mon
, const char *device
,
425 const char *filename
, const char *fmt
)
427 BlockDriverState
*bs
;
428 BlockDriver
*drv
= NULL
;
430 bs
= bdrv_find(device
);
432 monitor_printf(mon
, "device not found\n");
436 drv
= bdrv_find_format(fmt
);
438 monitor_printf(mon
, "invalid format %s\n", fmt
);
442 if (eject_device(mon
, bs
, 0) < 0)
444 bdrv_open2(bs
, filename
, 0, drv
);
445 monitor_read_bdrv_key_start(mon
, bs
, NULL
, NULL
);
448 static void change_vnc_password_cb(Monitor
*mon
, const char *password
,
451 if (vnc_display_password(NULL
, password
) < 0)
452 monitor_printf(mon
, "could not set VNC server password\n");
454 monitor_start_input();
457 static void do_change_vnc(Monitor
*mon
, const char *target
, const char *arg
)
459 if (strcmp(target
, "passwd") == 0 ||
460 strcmp(target
, "password") == 0) {
463 strncpy(password
, arg
, sizeof(password
));
464 password
[sizeof(password
) - 1] = '\0';
465 change_vnc_password_cb(mon
, password
, NULL
);
467 monitor_read_password(mon
, change_vnc_password_cb
, NULL
);
470 if (vnc_display_open(NULL
, target
) < 0)
471 monitor_printf(mon
, "could not start VNC server on %s\n", target
);
475 static void do_change(Monitor
*mon
, const char *device
, const char *target
,
478 if (strcmp(device
, "vnc") == 0) {
479 do_change_vnc(mon
, target
, arg
);
481 do_change_block(mon
, device
, target
, arg
);
485 static void do_screen_dump(Monitor
*mon
, const char *filename
)
487 vga_hw_screen_dump(filename
);
490 static void do_logfile(Monitor
*mon
, const char *filename
)
492 cpu_set_log_filename(filename
);
495 static void do_log(Monitor
*mon
, const char *items
)
499 if (!strcmp(items
, "none")) {
502 mask
= cpu_str_to_log_mask(items
);
504 help_cmd(mon
, "log");
511 static void do_stop(Monitor
*mon
)
513 vm_stop(EXCP_INTERRUPT
);
516 static void encrypted_bdrv_it(void *opaque
, BlockDriverState
*bs
);
518 struct bdrv_iterate_context
{
523 static void do_cont(Monitor
*mon
)
525 struct bdrv_iterate_context context
= { mon
, 0 };
527 bdrv_iterate(encrypted_bdrv_it
, &context
);
528 /* only resume the vm if all keys are set and valid */
533 static void bdrv_key_cb(void *opaque
, int err
)
535 Monitor
*mon
= opaque
;
537 /* another key was set successfully, retry to continue */
542 static void encrypted_bdrv_it(void *opaque
, BlockDriverState
*bs
)
544 struct bdrv_iterate_context
*context
= opaque
;
546 if (!context
->err
&& bdrv_key_required(bs
)) {
547 context
->err
= -EBUSY
;
548 monitor_read_bdrv_key_start(context
->mon
, bs
, bdrv_key_cb
,
553 #ifdef CONFIG_GDBSTUB
554 static void do_gdbserver(Monitor
*mon
, const char *port
)
557 port
= DEFAULT_GDBSTUB_PORT
;
558 if (gdbserver_start(port
) < 0) {
559 monitor_printf(mon
, "Could not open gdbserver socket on port '%s'\n",
562 monitor_printf(mon
, "Waiting gdb connection on port '%s'\n", port
);
567 static void monitor_printc(Monitor
*mon
, int c
)
569 monitor_printf(mon
, "'");
572 monitor_printf(mon
, "\\'");
575 monitor_printf(mon
, "\\\\");
578 monitor_printf(mon
, "\\n");
581 monitor_printf(mon
, "\\r");
584 if (c
>= 32 && c
<= 126) {
585 monitor_printf(mon
, "%c", c
);
587 monitor_printf(mon
, "\\x%02x", c
);
591 monitor_printf(mon
, "'");
594 static void memory_dump(Monitor
*mon
, int count
, int format
, int wsize
,
595 target_phys_addr_t addr
, int is_physical
)
598 int nb_per_line
, l
, line_size
, i
, max_digits
, len
;
606 if (!env
&& !is_physical
)
611 } else if (wsize
== 4) {
614 /* as default we use the current CS size */
618 if ((env
->efer
& MSR_EFER_LMA
) &&
619 (env
->segs
[R_CS
].flags
& DESC_L_MASK
))
623 if (!(env
->segs
[R_CS
].flags
& DESC_B_MASK
))
628 monitor_disas(mon
, env
, addr
, count
, is_physical
, flags
);
637 nb_per_line
= line_size
/ wsize
;
642 max_digits
= (wsize
* 8 + 2) / 3;
646 max_digits
= (wsize
* 8) / 4;
650 max_digits
= (wsize
* 8 * 10 + 32) / 33;
659 monitor_printf(mon
, TARGET_FMT_plx
":", addr
);
661 monitor_printf(mon
, TARGET_FMT_lx
":", (target_ulong
)addr
);
666 cpu_physical_memory_rw(addr
, buf
, l
, 0);
671 if (cpu_memory_rw_debug(env
, addr
, buf
, l
, 0) < 0) {
672 monitor_printf(mon
, " Cannot access memory\n");
681 v
= ldub_raw(buf
+ i
);
684 v
= lduw_raw(buf
+ i
);
687 v
= (uint32_t)ldl_raw(buf
+ i
);
690 v
= ldq_raw(buf
+ i
);
693 monitor_printf(mon
, " ");
696 monitor_printf(mon
, "%#*" PRIo64
, max_digits
, v
);
699 monitor_printf(mon
, "0x%0*" PRIx64
, max_digits
, v
);
702 monitor_printf(mon
, "%*" PRIu64
, max_digits
, v
);
705 monitor_printf(mon
, "%*" PRId64
, max_digits
, v
);
708 monitor_printc(mon
, v
);
713 monitor_printf(mon
, "\n");
719 #if TARGET_LONG_BITS == 64
720 #define GET_TLONG(h, l) (((uint64_t)(h) << 32) | (l))
722 #define GET_TLONG(h, l) (l)
725 static void do_memory_dump(Monitor
*mon
, int count
, int format
, int size
,
726 uint32_t addrh
, uint32_t addrl
)
728 target_long addr
= GET_TLONG(addrh
, addrl
);
729 memory_dump(mon
, count
, format
, size
, addr
, 0);
732 #if TARGET_PHYS_ADDR_BITS > 32
733 #define GET_TPHYSADDR(h, l) (((uint64_t)(h) << 32) | (l))
735 #define GET_TPHYSADDR(h, l) (l)
738 static void do_physical_memory_dump(Monitor
*mon
, int count
, int format
,
739 int size
, uint32_t addrh
, uint32_t addrl
)
742 target_phys_addr_t addr
= GET_TPHYSADDR(addrh
, addrl
);
743 memory_dump(mon
, count
, format
, size
, addr
, 1);
746 static void do_print(Monitor
*mon
, int count
, int format
, int size
,
747 unsigned int valh
, unsigned int vall
)
749 target_phys_addr_t val
= GET_TPHYSADDR(valh
, vall
);
750 #if TARGET_PHYS_ADDR_BITS == 32
753 monitor_printf(mon
, "%#o", val
);
756 monitor_printf(mon
, "%#x", val
);
759 monitor_printf(mon
, "%u", val
);
763 monitor_printf(mon
, "%d", val
);
766 monitor_printc(mon
, val
);
772 monitor_printf(mon
, "%#" PRIo64
, val
);
775 monitor_printf(mon
, "%#" PRIx64
, val
);
778 monitor_printf(mon
, "%" PRIu64
, val
);
782 monitor_printf(mon
, "%" PRId64
, val
);
785 monitor_printc(mon
, val
);
789 monitor_printf(mon
, "\n");
792 static void do_memory_save(Monitor
*mon
, unsigned int valh
, unsigned int vall
,
793 uint32_t size
, const char *filename
)
796 target_long addr
= GET_TLONG(valh
, vall
);
805 f
= fopen(filename
, "wb");
807 monitor_printf(mon
, "could not open '%s'\n", filename
);
814 cpu_memory_rw_debug(env
, addr
, buf
, l
, 0);
815 fwrite(buf
, 1, l
, f
);
822 static void do_physical_memory_save(Monitor
*mon
, unsigned int valh
,
823 unsigned int vall
, uint32_t size
,
824 const char *filename
)
829 target_phys_addr_t addr
= GET_TPHYSADDR(valh
, vall
);
831 f
= fopen(filename
, "wb");
833 monitor_printf(mon
, "could not open '%s'\n", filename
);
840 cpu_physical_memory_rw(addr
, buf
, l
, 0);
841 fwrite(buf
, 1, l
, f
);
849 static void do_sum(Monitor
*mon
, uint32_t start
, uint32_t size
)
856 for(addr
= start
; addr
< (start
+ size
); addr
++) {
857 cpu_physical_memory_rw(addr
, buf
, 1, 0);
858 /* BSD sum algorithm ('sum' Unix command) */
859 sum
= (sum
>> 1) | (sum
<< 15);
862 monitor_printf(mon
, "%05d\n", sum
);
870 static const KeyDef key_defs
[] = {
897 { 0x0e, "backspace" },
934 { 0x37, "asterisk" },
937 { 0x3a, "caps_lock" },
948 { 0x45, "num_lock" },
949 { 0x46, "scroll_lock" },
951 { 0xb5, "kp_divide" },
952 { 0x37, "kp_multiply" },
953 { 0x4a, "kp_subtract" },
955 { 0x9c, "kp_enter" },
956 { 0x53, "kp_decimal" },
989 #if defined(TARGET_SPARC) && !defined(TARGET_SPARC64)
1004 { 0xfe, "compose" },
1009 static int get_keycode(const char *key
)
1015 for(p
= key_defs
; p
->name
!= NULL
; p
++) {
1016 if (!strcmp(key
, p
->name
))
1019 if (strstart(key
, "0x", NULL
)) {
1020 ret
= strtoul(key
, &endp
, 0);
1021 if (*endp
== '\0' && ret
>= 0x01 && ret
<= 0xff)
1027 #define MAX_KEYCODES 16
1028 static uint8_t keycodes
[MAX_KEYCODES
];
1029 static int nb_pending_keycodes
;
1030 static QEMUTimer
*key_timer
;
1032 static void release_keys(void *opaque
)
1036 while (nb_pending_keycodes
> 0) {
1037 nb_pending_keycodes
--;
1038 keycode
= keycodes
[nb_pending_keycodes
];
1040 kbd_put_keycode(0xe0);
1041 kbd_put_keycode(keycode
| 0x80);
1045 static void do_sendkey(Monitor
*mon
, const char *string
, int has_hold_time
,
1048 char keyname_buf
[16];
1050 int keyname_len
, keycode
, i
;
1052 if (nb_pending_keycodes
> 0) {
1053 qemu_del_timer(key_timer
);
1060 separator
= strchr(string
, '-');
1061 keyname_len
= separator
? separator
- string
: strlen(string
);
1062 if (keyname_len
> 0) {
1063 pstrcpy(keyname_buf
, sizeof(keyname_buf
), string
);
1064 if (keyname_len
> sizeof(keyname_buf
) - 1) {
1065 monitor_printf(mon
, "invalid key: '%s...'\n", keyname_buf
);
1068 if (i
== MAX_KEYCODES
) {
1069 monitor_printf(mon
, "too many keys\n");
1072 keyname_buf
[keyname_len
] = 0;
1073 keycode
= get_keycode(keyname_buf
);
1075 monitor_printf(mon
, "unknown key: '%s'\n", keyname_buf
);
1078 keycodes
[i
++] = keycode
;
1082 string
= separator
+ 1;
1084 nb_pending_keycodes
= i
;
1085 /* key down events */
1086 for (i
= 0; i
< nb_pending_keycodes
; i
++) {
1087 keycode
= keycodes
[i
];
1089 kbd_put_keycode(0xe0);
1090 kbd_put_keycode(keycode
& 0x7f);
1092 /* delayed key up events */
1093 qemu_mod_timer(key_timer
, qemu_get_clock(vm_clock
) +
1094 muldiv64(ticks_per_sec
, hold_time
, 1000));
1097 static int mouse_button_state
;
1099 static void do_mouse_move(Monitor
*mon
, const char *dx_str
, const char *dy_str
,
1103 dx
= strtol(dx_str
, NULL
, 0);
1104 dy
= strtol(dy_str
, NULL
, 0);
1107 dz
= strtol(dz_str
, NULL
, 0);
1108 kbd_mouse_event(dx
, dy
, dz
, mouse_button_state
);
1111 static void do_mouse_button(Monitor
*mon
, int button_state
)
1113 mouse_button_state
= button_state
;
1114 kbd_mouse_event(0, 0, 0, mouse_button_state
);
1117 static void do_ioport_read(Monitor
*mon
, int count
, int format
, int size
,
1118 int addr
, int has_index
, int index
)
1124 cpu_outb(NULL
, addr
& 0xffff, index
& 0xff);
1132 val
= cpu_inb(NULL
, addr
);
1136 val
= cpu_inw(NULL
, addr
);
1140 val
= cpu_inl(NULL
, addr
);
1144 monitor_printf(mon
, "port%c[0x%04x] = %#0*x\n",
1145 suffix
, addr
, size
* 2, val
);
1148 /* boot_set handler */
1149 static QEMUBootSetHandler
*qemu_boot_set_handler
= NULL
;
1150 static void *boot_opaque
;
1152 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
1154 qemu_boot_set_handler
= func
;
1155 boot_opaque
= opaque
;
1158 static void do_boot_set(Monitor
*mon
, const char *bootdevice
)
1162 if (qemu_boot_set_handler
) {
1163 res
= qemu_boot_set_handler(boot_opaque
, bootdevice
);
1165 monitor_printf(mon
, "boot device list now set to %s\n",
1168 monitor_printf(mon
, "setting boot device list failed with "
1171 monitor_printf(mon
, "no function defined to set boot device list for "
1172 "this architecture\n");
1176 static void do_system_reset(Monitor
*mon
)
1178 qemu_system_reset_request();
1181 static void do_system_powerdown(Monitor
*mon
)
1183 qemu_system_powerdown_request();
1186 #if defined(TARGET_I386)
1187 static void print_pte(Monitor
*mon
, uint32_t addr
, uint32_t pte
, uint32_t mask
)
1189 monitor_printf(mon
, "%08x: %08x %c%c%c%c%c%c%c%c\n",
1192 pte
& PG_GLOBAL_MASK
? 'G' : '-',
1193 pte
& PG_PSE_MASK
? 'P' : '-',
1194 pte
& PG_DIRTY_MASK
? 'D' : '-',
1195 pte
& PG_ACCESSED_MASK
? 'A' : '-',
1196 pte
& PG_PCD_MASK
? 'C' : '-',
1197 pte
& PG_PWT_MASK
? 'T' : '-',
1198 pte
& PG_USER_MASK
? 'U' : '-',
1199 pte
& PG_RW_MASK
? 'W' : '-');
1202 static void tlb_info(Monitor
*mon
)
1206 uint32_t pgd
, pde
, pte
;
1208 env
= mon_get_cpu();
1212 if (!(env
->cr
[0] & CR0_PG_MASK
)) {
1213 monitor_printf(mon
, "PG disabled\n");
1216 pgd
= env
->cr
[3] & ~0xfff;
1217 for(l1
= 0; l1
< 1024; l1
++) {
1218 cpu_physical_memory_read(pgd
+ l1
* 4, (uint8_t *)&pde
, 4);
1219 pde
= le32_to_cpu(pde
);
1220 if (pde
& PG_PRESENT_MASK
) {
1221 if ((pde
& PG_PSE_MASK
) && (env
->cr
[4] & CR4_PSE_MASK
)) {
1222 print_pte(mon
, (l1
<< 22), pde
, ~((1 << 20) - 1));
1224 for(l2
= 0; l2
< 1024; l2
++) {
1225 cpu_physical_memory_read((pde
& ~0xfff) + l2
* 4,
1226 (uint8_t *)&pte
, 4);
1227 pte
= le32_to_cpu(pte
);
1228 if (pte
& PG_PRESENT_MASK
) {
1229 print_pte(mon
, (l1
<< 22) + (l2
<< 12),
1239 static void mem_print(Monitor
*mon
, uint32_t *pstart
, int *plast_prot
,
1240 uint32_t end
, int prot
)
1243 prot1
= *plast_prot
;
1244 if (prot
!= prot1
) {
1245 if (*pstart
!= -1) {
1246 monitor_printf(mon
, "%08x-%08x %08x %c%c%c\n",
1247 *pstart
, end
, end
- *pstart
,
1248 prot1
& PG_USER_MASK
? 'u' : '-',
1250 prot1
& PG_RW_MASK
? 'w' : '-');
1260 static void mem_info(Monitor
*mon
)
1263 int l1
, l2
, prot
, last_prot
;
1264 uint32_t pgd
, pde
, pte
, start
, end
;
1266 env
= mon_get_cpu();
1270 if (!(env
->cr
[0] & CR0_PG_MASK
)) {
1271 monitor_printf(mon
, "PG disabled\n");
1274 pgd
= env
->cr
[3] & ~0xfff;
1277 for(l1
= 0; l1
< 1024; l1
++) {
1278 cpu_physical_memory_read(pgd
+ l1
* 4, (uint8_t *)&pde
, 4);
1279 pde
= le32_to_cpu(pde
);
1281 if (pde
& PG_PRESENT_MASK
) {
1282 if ((pde
& PG_PSE_MASK
) && (env
->cr
[4] & CR4_PSE_MASK
)) {
1283 prot
= pde
& (PG_USER_MASK
| PG_RW_MASK
| PG_PRESENT_MASK
);
1284 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1286 for(l2
= 0; l2
< 1024; l2
++) {
1287 cpu_physical_memory_read((pde
& ~0xfff) + l2
* 4,
1288 (uint8_t *)&pte
, 4);
1289 pte
= le32_to_cpu(pte
);
1290 end
= (l1
<< 22) + (l2
<< 12);
1291 if (pte
& PG_PRESENT_MASK
) {
1292 prot
= pte
& (PG_USER_MASK
| PG_RW_MASK
| PG_PRESENT_MASK
);
1296 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1301 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1307 #if defined(TARGET_SH4)
1309 static void print_tlb(Monitor
*mon
, int idx
, tlb_t
*tlb
)
1311 monitor_printf(mon
, " tlb%i:\t"
1312 "asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t"
1313 "v=%hhu shared=%hhu cached=%hhu prot=%hhu "
1314 "dirty=%hhu writethrough=%hhu\n",
1316 tlb
->asid
, tlb
->vpn
, tlb
->ppn
, tlb
->sz
, tlb
->size
,
1317 tlb
->v
, tlb
->sh
, tlb
->c
, tlb
->pr
,
1321 static void tlb_info(Monitor
*mon
)
1323 CPUState
*env
= mon_get_cpu();
1326 monitor_printf (mon
, "ITLB:\n");
1327 for (i
= 0 ; i
< ITLB_SIZE
; i
++)
1328 print_tlb (mon
, i
, &env
->itlb
[i
]);
1329 monitor_printf (mon
, "UTLB:\n");
1330 for (i
= 0 ; i
< UTLB_SIZE
; i
++)
1331 print_tlb (mon
, i
, &env
->utlb
[i
]);
1336 static void do_info_kqemu(Monitor
*mon
)
1342 env
= mon_get_cpu();
1344 monitor_printf(mon
, "No cpu initialized yet");
1347 val
= env
->kqemu_enabled
;
1348 monitor_printf(mon
, "kqemu support: ");
1352 monitor_printf(mon
, "disabled\n");
1355 monitor_printf(mon
, "enabled for user code\n");
1358 monitor_printf(mon
, "enabled for user and kernel code\n");
1362 monitor_printf(mon
, "kqemu support: not compiled\n");
1366 static void do_info_kvm(Monitor
*mon
)
1369 monitor_printf(mon
, "kvm support: ");
1371 monitor_printf(mon
, "enabled\n");
1373 monitor_printf(mon
, "disabled\n");
1375 monitor_printf(mon
, "kvm support: not compiled\n");
1379 #ifdef CONFIG_PROFILER
1383 int64_t kqemu_exec_count
;
1385 int64_t kqemu_ret_int_count
;
1386 int64_t kqemu_ret_excp_count
;
1387 int64_t kqemu_ret_intr_count
;
1389 static void do_info_profile(Monitor
*mon
)
1395 monitor_printf(mon
, "async time %" PRId64
" (%0.3f)\n",
1396 dev_time
, dev_time
/ (double)ticks_per_sec
);
1397 monitor_printf(mon
, "qemu time %" PRId64
" (%0.3f)\n",
1398 qemu_time
, qemu_time
/ (double)ticks_per_sec
);
1399 monitor_printf(mon
, "kqemu time %" PRId64
" (%0.3f %0.1f%%) count=%"
1400 PRId64
" int=%" PRId64
" excp=%" PRId64
" intr=%"
1402 kqemu_time
, kqemu_time
/ (double)ticks_per_sec
,
1403 kqemu_time
/ (double)total
* 100.0,
1405 kqemu_ret_int_count
,
1406 kqemu_ret_excp_count
,
1407 kqemu_ret_intr_count
);
1410 kqemu_exec_count
= 0;
1412 kqemu_ret_int_count
= 0;
1413 kqemu_ret_excp_count
= 0;
1414 kqemu_ret_intr_count
= 0;
1416 kqemu_record_dump();
1420 static void do_info_profile(Monitor
*mon
)
1422 monitor_printf(mon
, "Internal profiler not compiled\n");
1426 /* Capture support */
1427 static LIST_HEAD (capture_list_head
, CaptureState
) capture_head
;
1429 static void do_info_capture(Monitor
*mon
)
1434 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
1435 monitor_printf(mon
, "[%d]: ", i
);
1436 s
->ops
.info (s
->opaque
);
1440 static void do_stop_capture(Monitor
*mon
, int n
)
1445 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
1447 s
->ops
.destroy (s
->opaque
);
1448 LIST_REMOVE (s
, entries
);
1456 static void do_wav_capture(Monitor
*mon
, const char *path
,
1457 int has_freq
, int freq
,
1458 int has_bits
, int bits
,
1459 int has_channels
, int nchannels
)
1463 s
= qemu_mallocz (sizeof (*s
));
1465 freq
= has_freq
? freq
: 44100;
1466 bits
= has_bits
? bits
: 16;
1467 nchannels
= has_channels
? nchannels
: 2;
1469 if (wav_start_capture (s
, path
, freq
, bits
, nchannels
)) {
1470 monitor_printf(mon
, "Faied to add wave capture\n");
1473 LIST_INSERT_HEAD (&capture_head
, s
, entries
);
1477 #if defined(TARGET_I386)
1478 static void do_inject_nmi(Monitor
*mon
, int cpu_index
)
1482 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
)
1483 if (env
->cpu_index
== cpu_index
) {
1484 cpu_interrupt(env
, CPU_INTERRUPT_NMI
);
1490 static void do_info_status(Monitor
*mon
)
1493 monitor_printf(mon
, "VM status: running\n");
1495 monitor_printf(mon
, "VM status: paused\n");
1499 static void do_balloon(Monitor
*mon
, int value
)
1501 ram_addr_t target
= value
;
1502 qemu_balloon(target
<< 20);
1505 static void do_info_balloon(Monitor
*mon
)
1509 actual
= qemu_balloon_status();
1510 if (kvm_enabled() && !kvm_has_sync_mmu())
1511 monitor_printf(mon
, "Using KVM without synchronous MMU, "
1512 "ballooning disabled\n");
1513 else if (actual
== 0)
1514 monitor_printf(mon
, "Ballooning not activated in VM\n");
1516 monitor_printf(mon
, "balloon: actual=%d\n", (int)(actual
>> 20));
1519 /* Please update qemu-doc.texi when adding or changing commands */
1520 static const mon_cmd_t mon_cmds
[] = {
1521 { "help|?", "s?", help_cmd
,
1522 "[cmd]", "show the help" },
1523 { "commit", "s", do_commit
,
1524 "device|all", "commit changes to the disk images (if -snapshot is used) or backing files" },
1525 { "info", "s?", do_info
,
1526 "subcommand", "show various information about the system state" },
1527 { "q|quit", "", do_quit
,
1528 "", "quit the emulator" },
1529 { "eject", "-fB", do_eject
,
1530 "[-f] device", "eject a removable medium (use -f to force it)" },
1531 { "change", "BFs?", do_change
,
1532 "device filename [format]", "change a removable medium, optional format" },
1533 { "screendump", "F", do_screen_dump
,
1534 "filename", "save screen into PPM image 'filename'" },
1535 { "logfile", "F", do_logfile
,
1536 "filename", "output logs to 'filename'" },
1537 { "log", "s", do_log
,
1538 "item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" },
1539 { "savevm", "s?", do_savevm
,
1540 "tag|id", "save a VM snapshot. If no tag or id are provided, a new snapshot is created" },
1541 { "loadvm", "s", do_loadvm
,
1542 "tag|id", "restore a VM snapshot from its tag or id" },
1543 { "delvm", "s", do_delvm
,
1544 "tag|id", "delete a VM snapshot from its tag or id" },
1545 { "stop", "", do_stop
,
1546 "", "stop emulation", },
1547 { "c|cont", "", do_cont
,
1548 "", "resume emulation", },
1549 #ifdef CONFIG_GDBSTUB
1550 { "gdbserver", "s?", do_gdbserver
,
1551 "[port]", "start gdbserver session (default port=1234)", },
1553 { "x", "/l", do_memory_dump
,
1554 "/fmt addr", "virtual memory dump starting at 'addr'", },
1555 { "xp", "/l", do_physical_memory_dump
,
1556 "/fmt addr", "physical memory dump starting at 'addr'", },
1557 { "p|print", "/l", do_print
,
1558 "/fmt expr", "print expression value (use $reg for CPU register access)", },
1559 { "i", "/ii.", do_ioport_read
,
1560 "/fmt addr", "I/O port read" },
1562 { "sendkey", "si?", do_sendkey
,
1563 "keys [hold_ms]", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1', default hold time=100 ms)" },
1564 { "system_reset", "", do_system_reset
,
1565 "", "reset the system" },
1566 { "system_powerdown", "", do_system_powerdown
,
1567 "", "send system power down event" },
1568 { "sum", "ii", do_sum
,
1569 "addr size", "compute the checksum of a memory region" },
1570 { "usb_add", "s", do_usb_add
,
1571 "device", "add USB device (e.g. 'host:bus.addr' or 'host:vendor_id:product_id')" },
1572 { "usb_del", "s", do_usb_del
,
1573 "device", "remove USB device 'bus.addr'" },
1574 { "cpu", "i", do_cpu_set
,
1575 "index", "set the default CPU" },
1576 { "mouse_move", "sss?", do_mouse_move
,
1577 "dx dy [dz]", "send mouse move events" },
1578 { "mouse_button", "i", do_mouse_button
,
1579 "state", "change mouse button state (1=L, 2=M, 4=R)" },
1580 { "mouse_set", "i", do_mouse_set
,
1581 "index", "set which mouse device receives events" },
1583 { "wavcapture", "si?i?i?", do_wav_capture
,
1584 "path [frequency bits channels]",
1585 "capture audio to a wave file (default frequency=44100 bits=16 channels=2)" },
1587 { "stopcapture", "i", do_stop_capture
,
1588 "capture index", "stop capture" },
1589 { "memsave", "lis", do_memory_save
,
1590 "addr size file", "save to disk virtual memory dump starting at 'addr' of size 'size'", },
1591 { "pmemsave", "lis", do_physical_memory_save
,
1592 "addr size file", "save to disk physical memory dump starting at 'addr' of size 'size'", },
1593 { "boot_set", "s", do_boot_set
,
1594 "bootdevice", "define new values for the boot device list" },
1595 #if defined(TARGET_I386)
1596 { "nmi", "i", do_inject_nmi
,
1597 "cpu", "inject an NMI on the given CPU", },
1599 { "migrate", "-ds", do_migrate
,
1600 "[-d] uri", "migrate to URI (using -d to not wait for completion)" },
1601 { "migrate_cancel", "", do_migrate_cancel
,
1602 "", "cancel the current VM migration" },
1603 { "migrate_set_speed", "s", do_migrate_set_speed
,
1604 "value", "set maximum speed (in bytes) for migrations" },
1605 #if defined(TARGET_I386)
1606 { "drive_add", "ss", drive_hot_add
, "pci_addr=[[<domain>:]<bus>:]<slot>\n"
1607 "[file=file][,if=type][,bus=n]\n"
1608 "[,unit=m][,media=d][index=i]\n"
1609 "[,cyls=c,heads=h,secs=s[,trans=t]]\n"
1610 "[snapshot=on|off][,cache=on|off]",
1611 "add drive to PCI storage controller" },
1612 { "pci_add", "sss", pci_device_hot_add
, "pci_addr=auto|[[<domain>:]<bus>:]<slot> nic|storage [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]...", "hot-add PCI device" },
1613 { "pci_del", "s", pci_device_hot_remove
, "pci_addr=[[<domain>:]<bus>:]<slot>", "hot remove PCI device" },
1614 { "host_net_add", "ss", net_host_device_add
,
1615 "[tap,user,socket,vde] options", "add host VLAN client" },
1616 { "host_net_remove", "is", net_host_device_remove
,
1617 "vlan_id name", "remove host VLAN client" },
1619 { "balloon", "i", do_balloon
,
1620 "target", "request VM to change it's memory allocation (in MB)" },
1621 { "set_link", "ss", do_set_link
,
1622 "name [up|down]", "change the link status of a network adapter" },
1626 /* Please update qemu-doc.texi when adding or changing commands */
1627 static const mon_cmd_t info_cmds
[] = {
1628 { "version", "", do_info_version
,
1629 "", "show the version of QEMU" },
1630 { "network", "", do_info_network
,
1631 "", "show the network state" },
1632 { "chardev", "", qemu_chr_info
,
1633 "", "show the character devices" },
1634 { "block", "", bdrv_info
,
1635 "", "show the block devices" },
1636 { "blockstats", "", bdrv_info_stats
,
1637 "", "show block device statistics" },
1638 { "registers", "", do_info_registers
,
1639 "", "show the cpu registers" },
1640 { "cpus", "", do_info_cpus
,
1641 "", "show infos for each CPU" },
1642 { "history", "", do_info_history
,
1643 "", "show the command line history", },
1644 { "irq", "", irq_info
,
1645 "", "show the interrupts statistics (if available)", },
1646 { "pic", "", pic_info
,
1647 "", "show i8259 (PIC) state", },
1648 { "pci", "", pci_info
,
1649 "", "show PCI info", },
1650 #if defined(TARGET_I386) || defined(TARGET_SH4)
1651 { "tlb", "", tlb_info
,
1652 "", "show virtual to physical memory mappings", },
1654 #if defined(TARGET_I386)
1655 { "mem", "", mem_info
,
1656 "", "show the active virtual memory mappings", },
1657 { "hpet", "", do_info_hpet
,
1658 "", "show state of HPET", },
1660 { "jit", "", do_info_jit
,
1661 "", "show dynamic compiler info", },
1662 { "kqemu", "", do_info_kqemu
,
1663 "", "show KQEMU information", },
1664 { "kvm", "", do_info_kvm
,
1665 "", "show KVM information", },
1666 { "usb", "", usb_info
,
1667 "", "show guest USB devices", },
1668 { "usbhost", "", usb_host_info
,
1669 "", "show host USB devices", },
1670 { "profile", "", do_info_profile
,
1671 "", "show profiling information", },
1672 { "capture", "", do_info_capture
,
1673 "", "show capture information" },
1674 { "snapshots", "", do_info_snapshots
,
1675 "", "show the currently saved VM snapshots" },
1676 { "status", "", do_info_status
,
1677 "", "show the current VM status (running|paused)" },
1678 { "pcmcia", "", pcmcia_info
,
1679 "", "show guest PCMCIA status" },
1680 { "mice", "", do_info_mice
,
1681 "", "show which guest mouse is receiving events" },
1682 { "vnc", "", do_info_vnc
,
1683 "", "show the vnc server status"},
1684 { "name", "", do_info_name
,
1685 "", "show the current VM name" },
1686 { "uuid", "", do_info_uuid
,
1687 "", "show the current VM UUID" },
1688 #if defined(TARGET_PPC)
1689 { "cpustats", "", do_info_cpu_stats
,
1690 "", "show CPU statistics", },
1692 #if defined(CONFIG_SLIRP)
1693 { "slirp", "", do_info_slirp
,
1694 "", "show SLIRP statistics", },
1696 { "migrate", "", do_info_migrate
, "", "show migration status" },
1697 { "balloon", "", do_info_balloon
,
1698 "", "show balloon information" },
1702 /*******************************************************************/
1704 static const char *pch
;
1705 static jmp_buf expr_env
;
1710 typedef struct MonitorDef
{
1713 target_long (*get_value
)(const struct MonitorDef
*md
, int val
);
1717 #if defined(TARGET_I386)
1718 static target_long
monitor_get_pc (const struct MonitorDef
*md
, int val
)
1720 CPUState
*env
= mon_get_cpu();
1723 return env
->eip
+ env
->segs
[R_CS
].base
;
1727 #if defined(TARGET_PPC)
1728 static target_long
monitor_get_ccr (const struct MonitorDef
*md
, int val
)
1730 CPUState
*env
= mon_get_cpu();
1738 for (i
= 0; i
< 8; i
++)
1739 u
|= env
->crf
[i
] << (32 - (4 * i
));
1744 static target_long
monitor_get_msr (const struct MonitorDef
*md
, int val
)
1746 CPUState
*env
= mon_get_cpu();
1752 static target_long
monitor_get_xer (const struct MonitorDef
*md
, int val
)
1754 CPUState
*env
= mon_get_cpu();
1760 static target_long
monitor_get_decr (const struct MonitorDef
*md
, int val
)
1762 CPUState
*env
= mon_get_cpu();
1765 return cpu_ppc_load_decr(env
);
1768 static target_long
monitor_get_tbu (const struct MonitorDef
*md
, int val
)
1770 CPUState
*env
= mon_get_cpu();
1773 return cpu_ppc_load_tbu(env
);
1776 static target_long
monitor_get_tbl (const struct MonitorDef
*md
, int val
)
1778 CPUState
*env
= mon_get_cpu();
1781 return cpu_ppc_load_tbl(env
);
1785 #if defined(TARGET_SPARC)
1786 #ifndef TARGET_SPARC64
1787 static target_long
monitor_get_psr (const struct MonitorDef
*md
, int val
)
1789 CPUState
*env
= mon_get_cpu();
1792 return GET_PSR(env
);
1796 static target_long
monitor_get_reg(const struct MonitorDef
*md
, int val
)
1798 CPUState
*env
= mon_get_cpu();
1801 return env
->regwptr
[val
];
1805 static const MonitorDef monitor_defs
[] = {
1808 #define SEG(name, seg) \
1809 { name, offsetof(CPUState, segs[seg].selector), NULL, MD_I32 },\
1810 { name ".base", offsetof(CPUState, segs[seg].base) },\
1811 { name ".limit", offsetof(CPUState, segs[seg].limit), NULL, MD_I32 },
1813 { "eax", offsetof(CPUState
, regs
[0]) },
1814 { "ecx", offsetof(CPUState
, regs
[1]) },
1815 { "edx", offsetof(CPUState
, regs
[2]) },
1816 { "ebx", offsetof(CPUState
, regs
[3]) },
1817 { "esp|sp", offsetof(CPUState
, regs
[4]) },
1818 { "ebp|fp", offsetof(CPUState
, regs
[5]) },
1819 { "esi", offsetof(CPUState
, regs
[6]) },
1820 { "edi", offsetof(CPUState
, regs
[7]) },
1821 #ifdef TARGET_X86_64
1822 { "r8", offsetof(CPUState
, regs
[8]) },
1823 { "r9", offsetof(CPUState
, regs
[9]) },
1824 { "r10", offsetof(CPUState
, regs
[10]) },
1825 { "r11", offsetof(CPUState
, regs
[11]) },
1826 { "r12", offsetof(CPUState
, regs
[12]) },
1827 { "r13", offsetof(CPUState
, regs
[13]) },
1828 { "r14", offsetof(CPUState
, regs
[14]) },
1829 { "r15", offsetof(CPUState
, regs
[15]) },
1831 { "eflags", offsetof(CPUState
, eflags
) },
1832 { "eip", offsetof(CPUState
, eip
) },
1839 { "pc", 0, monitor_get_pc
, },
1840 #elif defined(TARGET_PPC)
1841 /* General purpose registers */
1842 { "r0", offsetof(CPUState
, gpr
[0]) },
1843 { "r1", offsetof(CPUState
, gpr
[1]) },
1844 { "r2", offsetof(CPUState
, gpr
[2]) },
1845 { "r3", offsetof(CPUState
, gpr
[3]) },
1846 { "r4", offsetof(CPUState
, gpr
[4]) },
1847 { "r5", offsetof(CPUState
, gpr
[5]) },
1848 { "r6", offsetof(CPUState
, gpr
[6]) },
1849 { "r7", offsetof(CPUState
, gpr
[7]) },
1850 { "r8", offsetof(CPUState
, gpr
[8]) },
1851 { "r9", offsetof(CPUState
, gpr
[9]) },
1852 { "r10", offsetof(CPUState
, gpr
[10]) },
1853 { "r11", offsetof(CPUState
, gpr
[11]) },
1854 { "r12", offsetof(CPUState
, gpr
[12]) },
1855 { "r13", offsetof(CPUState
, gpr
[13]) },
1856 { "r14", offsetof(CPUState
, gpr
[14]) },
1857 { "r15", offsetof(CPUState
, gpr
[15]) },
1858 { "r16", offsetof(CPUState
, gpr
[16]) },
1859 { "r17", offsetof(CPUState
, gpr
[17]) },
1860 { "r18", offsetof(CPUState
, gpr
[18]) },
1861 { "r19", offsetof(CPUState
, gpr
[19]) },
1862 { "r20", offsetof(CPUState
, gpr
[20]) },
1863 { "r21", offsetof(CPUState
, gpr
[21]) },
1864 { "r22", offsetof(CPUState
, gpr
[22]) },
1865 { "r23", offsetof(CPUState
, gpr
[23]) },
1866 { "r24", offsetof(CPUState
, gpr
[24]) },
1867 { "r25", offsetof(CPUState
, gpr
[25]) },
1868 { "r26", offsetof(CPUState
, gpr
[26]) },
1869 { "r27", offsetof(CPUState
, gpr
[27]) },
1870 { "r28", offsetof(CPUState
, gpr
[28]) },
1871 { "r29", offsetof(CPUState
, gpr
[29]) },
1872 { "r30", offsetof(CPUState
, gpr
[30]) },
1873 { "r31", offsetof(CPUState
, gpr
[31]) },
1874 /* Floating point registers */
1875 { "f0", offsetof(CPUState
, fpr
[0]) },
1876 { "f1", offsetof(CPUState
, fpr
[1]) },
1877 { "f2", offsetof(CPUState
, fpr
[2]) },
1878 { "f3", offsetof(CPUState
, fpr
[3]) },
1879 { "f4", offsetof(CPUState
, fpr
[4]) },
1880 { "f5", offsetof(CPUState
, fpr
[5]) },
1881 { "f6", offsetof(CPUState
, fpr
[6]) },
1882 { "f7", offsetof(CPUState
, fpr
[7]) },
1883 { "f8", offsetof(CPUState
, fpr
[8]) },
1884 { "f9", offsetof(CPUState
, fpr
[9]) },
1885 { "f10", offsetof(CPUState
, fpr
[10]) },
1886 { "f11", offsetof(CPUState
, fpr
[11]) },
1887 { "f12", offsetof(CPUState
, fpr
[12]) },
1888 { "f13", offsetof(CPUState
, fpr
[13]) },
1889 { "f14", offsetof(CPUState
, fpr
[14]) },
1890 { "f15", offsetof(CPUState
, fpr
[15]) },
1891 { "f16", offsetof(CPUState
, fpr
[16]) },
1892 { "f17", offsetof(CPUState
, fpr
[17]) },
1893 { "f18", offsetof(CPUState
, fpr
[18]) },
1894 { "f19", offsetof(CPUState
, fpr
[19]) },
1895 { "f20", offsetof(CPUState
, fpr
[20]) },
1896 { "f21", offsetof(CPUState
, fpr
[21]) },
1897 { "f22", offsetof(CPUState
, fpr
[22]) },
1898 { "f23", offsetof(CPUState
, fpr
[23]) },
1899 { "f24", offsetof(CPUState
, fpr
[24]) },
1900 { "f25", offsetof(CPUState
, fpr
[25]) },
1901 { "f26", offsetof(CPUState
, fpr
[26]) },
1902 { "f27", offsetof(CPUState
, fpr
[27]) },
1903 { "f28", offsetof(CPUState
, fpr
[28]) },
1904 { "f29", offsetof(CPUState
, fpr
[29]) },
1905 { "f30", offsetof(CPUState
, fpr
[30]) },
1906 { "f31", offsetof(CPUState
, fpr
[31]) },
1907 { "fpscr", offsetof(CPUState
, fpscr
) },
1908 /* Next instruction pointer */
1909 { "nip|pc", offsetof(CPUState
, nip
) },
1910 { "lr", offsetof(CPUState
, lr
) },
1911 { "ctr", offsetof(CPUState
, ctr
) },
1912 { "decr", 0, &monitor_get_decr
, },
1913 { "ccr", 0, &monitor_get_ccr
, },
1914 /* Machine state register */
1915 { "msr", 0, &monitor_get_msr
, },
1916 { "xer", 0, &monitor_get_xer
, },
1917 { "tbu", 0, &monitor_get_tbu
, },
1918 { "tbl", 0, &monitor_get_tbl
, },
1919 #if defined(TARGET_PPC64)
1920 /* Address space register */
1921 { "asr", offsetof(CPUState
, asr
) },
1923 /* Segment registers */
1924 { "sdr1", offsetof(CPUState
, sdr1
) },
1925 { "sr0", offsetof(CPUState
, sr
[0]) },
1926 { "sr1", offsetof(CPUState
, sr
[1]) },
1927 { "sr2", offsetof(CPUState
, sr
[2]) },
1928 { "sr3", offsetof(CPUState
, sr
[3]) },
1929 { "sr4", offsetof(CPUState
, sr
[4]) },
1930 { "sr5", offsetof(CPUState
, sr
[5]) },
1931 { "sr6", offsetof(CPUState
, sr
[6]) },
1932 { "sr7", offsetof(CPUState
, sr
[7]) },
1933 { "sr8", offsetof(CPUState
, sr
[8]) },
1934 { "sr9", offsetof(CPUState
, sr
[9]) },
1935 { "sr10", offsetof(CPUState
, sr
[10]) },
1936 { "sr11", offsetof(CPUState
, sr
[11]) },
1937 { "sr12", offsetof(CPUState
, sr
[12]) },
1938 { "sr13", offsetof(CPUState
, sr
[13]) },
1939 { "sr14", offsetof(CPUState
, sr
[14]) },
1940 { "sr15", offsetof(CPUState
, sr
[15]) },
1941 /* Too lazy to put BATs and SPRs ... */
1942 #elif defined(TARGET_SPARC)
1943 { "g0", offsetof(CPUState
, gregs
[0]) },
1944 { "g1", offsetof(CPUState
, gregs
[1]) },
1945 { "g2", offsetof(CPUState
, gregs
[2]) },
1946 { "g3", offsetof(CPUState
, gregs
[3]) },
1947 { "g4", offsetof(CPUState
, gregs
[4]) },
1948 { "g5", offsetof(CPUState
, gregs
[5]) },
1949 { "g6", offsetof(CPUState
, gregs
[6]) },
1950 { "g7", offsetof(CPUState
, gregs
[7]) },
1951 { "o0", 0, monitor_get_reg
},
1952 { "o1", 1, monitor_get_reg
},
1953 { "o2", 2, monitor_get_reg
},
1954 { "o3", 3, monitor_get_reg
},
1955 { "o4", 4, monitor_get_reg
},
1956 { "o5", 5, monitor_get_reg
},
1957 { "o6", 6, monitor_get_reg
},
1958 { "o7", 7, monitor_get_reg
},
1959 { "l0", 8, monitor_get_reg
},
1960 { "l1", 9, monitor_get_reg
},
1961 { "l2", 10, monitor_get_reg
},
1962 { "l3", 11, monitor_get_reg
},
1963 { "l4", 12, monitor_get_reg
},
1964 { "l5", 13, monitor_get_reg
},
1965 { "l6", 14, monitor_get_reg
},
1966 { "l7", 15, monitor_get_reg
},
1967 { "i0", 16, monitor_get_reg
},
1968 { "i1", 17, monitor_get_reg
},
1969 { "i2", 18, monitor_get_reg
},
1970 { "i3", 19, monitor_get_reg
},
1971 { "i4", 20, monitor_get_reg
},
1972 { "i5", 21, monitor_get_reg
},
1973 { "i6", 22, monitor_get_reg
},
1974 { "i7", 23, monitor_get_reg
},
1975 { "pc", offsetof(CPUState
, pc
) },
1976 { "npc", offsetof(CPUState
, npc
) },
1977 { "y", offsetof(CPUState
, y
) },
1978 #ifndef TARGET_SPARC64
1979 { "psr", 0, &monitor_get_psr
, },
1980 { "wim", offsetof(CPUState
, wim
) },
1982 { "tbr", offsetof(CPUState
, tbr
) },
1983 { "fsr", offsetof(CPUState
, fsr
) },
1984 { "f0", offsetof(CPUState
, fpr
[0]) },
1985 { "f1", offsetof(CPUState
, fpr
[1]) },
1986 { "f2", offsetof(CPUState
, fpr
[2]) },
1987 { "f3", offsetof(CPUState
, fpr
[3]) },
1988 { "f4", offsetof(CPUState
, fpr
[4]) },
1989 { "f5", offsetof(CPUState
, fpr
[5]) },
1990 { "f6", offsetof(CPUState
, fpr
[6]) },
1991 { "f7", offsetof(CPUState
, fpr
[7]) },
1992 { "f8", offsetof(CPUState
, fpr
[8]) },
1993 { "f9", offsetof(CPUState
, fpr
[9]) },
1994 { "f10", offsetof(CPUState
, fpr
[10]) },
1995 { "f11", offsetof(CPUState
, fpr
[11]) },
1996 { "f12", offsetof(CPUState
, fpr
[12]) },
1997 { "f13", offsetof(CPUState
, fpr
[13]) },
1998 { "f14", offsetof(CPUState
, fpr
[14]) },
1999 { "f15", offsetof(CPUState
, fpr
[15]) },
2000 { "f16", offsetof(CPUState
, fpr
[16]) },
2001 { "f17", offsetof(CPUState
, fpr
[17]) },
2002 { "f18", offsetof(CPUState
, fpr
[18]) },
2003 { "f19", offsetof(CPUState
, fpr
[19]) },
2004 { "f20", offsetof(CPUState
, fpr
[20]) },
2005 { "f21", offsetof(CPUState
, fpr
[21]) },
2006 { "f22", offsetof(CPUState
, fpr
[22]) },
2007 { "f23", offsetof(CPUState
, fpr
[23]) },
2008 { "f24", offsetof(CPUState
, fpr
[24]) },
2009 { "f25", offsetof(CPUState
, fpr
[25]) },
2010 { "f26", offsetof(CPUState
, fpr
[26]) },
2011 { "f27", offsetof(CPUState
, fpr
[27]) },
2012 { "f28", offsetof(CPUState
, fpr
[28]) },
2013 { "f29", offsetof(CPUState
, fpr
[29]) },
2014 { "f30", offsetof(CPUState
, fpr
[30]) },
2015 { "f31", offsetof(CPUState
, fpr
[31]) },
2016 #ifdef TARGET_SPARC64
2017 { "f32", offsetof(CPUState
, fpr
[32]) },
2018 { "f34", offsetof(CPUState
, fpr
[34]) },
2019 { "f36", offsetof(CPUState
, fpr
[36]) },
2020 { "f38", offsetof(CPUState
, fpr
[38]) },
2021 { "f40", offsetof(CPUState
, fpr
[40]) },
2022 { "f42", offsetof(CPUState
, fpr
[42]) },
2023 { "f44", offsetof(CPUState
, fpr
[44]) },
2024 { "f46", offsetof(CPUState
, fpr
[46]) },
2025 { "f48", offsetof(CPUState
, fpr
[48]) },
2026 { "f50", offsetof(CPUState
, fpr
[50]) },
2027 { "f52", offsetof(CPUState
, fpr
[52]) },
2028 { "f54", offsetof(CPUState
, fpr
[54]) },
2029 { "f56", offsetof(CPUState
, fpr
[56]) },
2030 { "f58", offsetof(CPUState
, fpr
[58]) },
2031 { "f60", offsetof(CPUState
, fpr
[60]) },
2032 { "f62", offsetof(CPUState
, fpr
[62]) },
2033 { "asi", offsetof(CPUState
, asi
) },
2034 { "pstate", offsetof(CPUState
, pstate
) },
2035 { "cansave", offsetof(CPUState
, cansave
) },
2036 { "canrestore", offsetof(CPUState
, canrestore
) },
2037 { "otherwin", offsetof(CPUState
, otherwin
) },
2038 { "wstate", offsetof(CPUState
, wstate
) },
2039 { "cleanwin", offsetof(CPUState
, cleanwin
) },
2040 { "fprs", offsetof(CPUState
, fprs
) },
2046 static void expr_error(Monitor
*mon
, const char *msg
)
2048 monitor_printf(mon
, "%s\n", msg
);
2049 longjmp(expr_env
, 1);
2052 /* return 0 if OK, -1 if not found, -2 if no CPU defined */
2053 static int get_monitor_def(target_long
*pval
, const char *name
)
2055 const MonitorDef
*md
;
2058 for(md
= monitor_defs
; md
->name
!= NULL
; md
++) {
2059 if (compare_cmd(name
, md
->name
)) {
2060 if (md
->get_value
) {
2061 *pval
= md
->get_value(md
, md
->offset
);
2063 CPUState
*env
= mon_get_cpu();
2066 ptr
= (uint8_t *)env
+ md
->offset
;
2069 *pval
= *(int32_t *)ptr
;
2072 *pval
= *(target_long
*)ptr
;
2085 static void next(void)
2089 while (qemu_isspace(*pch
))
2094 static int64_t expr_sum(Monitor
*mon
);
2096 static int64_t expr_unary(Monitor
*mon
)
2105 n
= expr_unary(mon
);
2109 n
= -expr_unary(mon
);
2113 n
= ~expr_unary(mon
);
2119 expr_error(mon
, "')' expected");
2126 expr_error(mon
, "character constant expected");
2130 expr_error(mon
, "missing terminating \' character");
2140 while ((*pch
>= 'a' && *pch
<= 'z') ||
2141 (*pch
>= 'A' && *pch
<= 'Z') ||
2142 (*pch
>= '0' && *pch
<= '9') ||
2143 *pch
== '_' || *pch
== '.') {
2144 if ((q
- buf
) < sizeof(buf
) - 1)
2148 while (qemu_isspace(*pch
))
2151 ret
= get_monitor_def(®
, buf
);
2153 expr_error(mon
, "unknown register");
2155 expr_error(mon
, "no cpu defined");
2160 expr_error(mon
, "unexpected end of expression");
2164 #if TARGET_PHYS_ADDR_BITS > 32
2165 n
= strtoull(pch
, &p
, 0);
2167 n
= strtoul(pch
, &p
, 0);
2170 expr_error(mon
, "invalid char in expression");
2173 while (qemu_isspace(*pch
))
2181 static int64_t expr_prod(Monitor
*mon
)
2186 val
= expr_unary(mon
);
2189 if (op
!= '*' && op
!= '/' && op
!= '%')
2192 val2
= expr_unary(mon
);
2201 expr_error(mon
, "division by zero");
2212 static int64_t expr_logic(Monitor
*mon
)
2217 val
= expr_prod(mon
);
2220 if (op
!= '&' && op
!= '|' && op
!= '^')
2223 val2
= expr_prod(mon
);
2240 static int64_t expr_sum(Monitor
*mon
)
2245 val
= expr_logic(mon
);
2248 if (op
!= '+' && op
!= '-')
2251 val2
= expr_logic(mon
);
2260 static int get_expr(Monitor
*mon
, int64_t *pval
, const char **pp
)
2263 if (setjmp(expr_env
)) {
2267 while (qemu_isspace(*pch
))
2269 *pval
= expr_sum(mon
);
2274 static int get_str(char *buf
, int buf_size
, const char **pp
)
2282 while (qemu_isspace(*p
))
2292 while (*p
!= '\0' && *p
!= '\"') {
2308 qemu_printf("unsupported escape code: '\\%c'\n", c
);
2311 if ((q
- buf
) < buf_size
- 1) {
2315 if ((q
- buf
) < buf_size
- 1) {
2322 qemu_printf("unterminated string\n");
2327 while (*p
!= '\0' && !qemu_isspace(*p
)) {
2328 if ((q
- buf
) < buf_size
- 1) {
2339 static int default_fmt_format
= 'x';
2340 static int default_fmt_size
= 4;
2344 static void monitor_handle_command(Monitor
*mon
, const char *cmdline
)
2346 const char *p
, *pstart
, *typestr
;
2348 int c
, nb_args
, len
, i
, has_arg
;
2349 const mon_cmd_t
*cmd
;
2352 void *str_allocated
[MAX_ARGS
];
2353 void *args
[MAX_ARGS
];
2354 void (*handler_0
)(Monitor
*mon
);
2355 void (*handler_1
)(Monitor
*mon
, void *arg0
);
2356 void (*handler_2
)(Monitor
*mon
, void *arg0
, void *arg1
);
2357 void (*handler_3
)(Monitor
*mon
, void *arg0
, void *arg1
, void *arg2
);
2358 void (*handler_4
)(Monitor
*mon
, void *arg0
, void *arg1
, void *arg2
,
2360 void (*handler_5
)(Monitor
*mon
, void *arg0
, void *arg1
, void *arg2
,
2361 void *arg3
, void *arg4
);
2362 void (*handler_6
)(Monitor
*mon
, void *arg0
, void *arg1
, void *arg2
,
2363 void *arg3
, void *arg4
, void *arg5
);
2364 void (*handler_7
)(Monitor
*mon
, void *arg0
, void *arg1
, void *arg2
,
2365 void *arg3
, void *arg4
, void *arg5
, void *arg6
);
2368 monitor_printf(mon
, "command='%s'\n", cmdline
);
2371 /* extract the command name */
2374 while (qemu_isspace(*p
))
2379 while (*p
!= '\0' && *p
!= '/' && !qemu_isspace(*p
))
2382 if (len
> sizeof(cmdname
) - 1)
2383 len
= sizeof(cmdname
) - 1;
2384 memcpy(cmdname
, pstart
, len
);
2385 cmdname
[len
] = '\0';
2387 /* find the command */
2388 for(cmd
= mon_cmds
; cmd
->name
!= NULL
; cmd
++) {
2389 if (compare_cmd(cmdname
, cmd
->name
))
2392 monitor_printf(mon
, "unknown command: '%s'\n", cmdname
);
2396 for(i
= 0; i
< MAX_ARGS
; i
++)
2397 str_allocated
[i
] = NULL
;
2399 /* parse the parameters */
2400 typestr
= cmd
->args_type
;
2415 while (qemu_isspace(*p
))
2417 if (*typestr
== '?') {
2420 /* no optional string: NULL argument */
2425 ret
= get_str(buf
, sizeof(buf
), &p
);
2429 monitor_printf(mon
, "%s: filename expected\n",
2433 monitor_printf(mon
, "%s: block device name expected\n",
2437 monitor_printf(mon
, "%s: string expected\n", cmdname
);
2442 str
= qemu_malloc(strlen(buf
) + 1);
2443 pstrcpy(str
, sizeof(buf
), buf
);
2444 str_allocated
[nb_args
] = str
;
2446 if (nb_args
>= MAX_ARGS
) {
2448 monitor_printf(mon
, "%s: too many arguments\n", cmdname
);
2451 args
[nb_args
++] = str
;
2456 int count
, format
, size
;
2458 while (qemu_isspace(*p
))
2464 if (qemu_isdigit(*p
)) {
2466 while (qemu_isdigit(*p
)) {
2467 count
= count
* 10 + (*p
- '0');
2505 if (*p
!= '\0' && !qemu_isspace(*p
)) {
2506 monitor_printf(mon
, "invalid char in format: '%c'\n",
2511 format
= default_fmt_format
;
2512 if (format
!= 'i') {
2513 /* for 'i', not specifying a size gives -1 as size */
2515 size
= default_fmt_size
;
2516 default_fmt_size
= size
;
2518 default_fmt_format
= format
;
2521 format
= default_fmt_format
;
2522 if (format
!= 'i') {
2523 size
= default_fmt_size
;
2528 if (nb_args
+ 3 > MAX_ARGS
)
2530 args
[nb_args
++] = (void*)(long)count
;
2531 args
[nb_args
++] = (void*)(long)format
;
2532 args
[nb_args
++] = (void*)(long)size
;
2540 while (qemu_isspace(*p
))
2542 if (*typestr
== '?' || *typestr
== '.') {
2543 if (*typestr
== '?') {
2551 while (qemu_isspace(*p
))
2559 if (nb_args
>= MAX_ARGS
)
2561 args
[nb_args
++] = (void *)(long)has_arg
;
2563 if (nb_args
>= MAX_ARGS
)
2569 if (get_expr(mon
, &val
, &p
))
2573 if (nb_args
>= MAX_ARGS
)
2575 args
[nb_args
++] = (void *)(long)val
;
2577 if ((nb_args
+ 1) >= MAX_ARGS
)
2579 #if TARGET_PHYS_ADDR_BITS > 32
2580 args
[nb_args
++] = (void *)(long)((val
>> 32) & 0xffffffff);
2582 args
[nb_args
++] = (void *)0;
2584 args
[nb_args
++] = (void *)(long)(val
& 0xffffffff);
2596 while (qemu_isspace(*p
))
2602 monitor_printf(mon
, "%s: unsupported option -%c\n",
2609 if (nb_args
>= MAX_ARGS
)
2611 args
[nb_args
++] = (void *)(long)has_option
;
2616 monitor_printf(mon
, "%s: unknown type '%c'\n", cmdname
, c
);
2620 /* check that all arguments were parsed */
2621 while (qemu_isspace(*p
))
2624 monitor_printf(mon
, "%s: extraneous characters at the end of line\n",
2631 handler_0
= cmd
->handler
;
2635 handler_1
= cmd
->handler
;
2636 handler_1(mon
, args
[0]);
2639 handler_2
= cmd
->handler
;
2640 handler_2(mon
, args
[0], args
[1]);
2643 handler_3
= cmd
->handler
;
2644 handler_3(mon
, args
[0], args
[1], args
[2]);
2647 handler_4
= cmd
->handler
;
2648 handler_4(mon
, args
[0], args
[1], args
[2], args
[3]);
2651 handler_5
= cmd
->handler
;
2652 handler_5(mon
, args
[0], args
[1], args
[2], args
[3], args
[4]);
2655 handler_6
= cmd
->handler
;
2656 handler_6(mon
, args
[0], args
[1], args
[2], args
[3], args
[4], args
[5]);
2659 handler_7
= cmd
->handler
;
2660 handler_7(mon
, args
[0], args
[1], args
[2], args
[3], args
[4], args
[5],
2664 monitor_printf(mon
, "unsupported number of arguments: %d\n", nb_args
);
2668 for(i
= 0; i
< MAX_ARGS
; i
++)
2669 qemu_free(str_allocated
[i
]);
2673 static void cmd_completion(const char *name
, const char *list
)
2675 const char *p
, *pstart
;
2684 p
= pstart
+ strlen(pstart
);
2686 if (len
> sizeof(cmd
) - 2)
2687 len
= sizeof(cmd
) - 2;
2688 memcpy(cmd
, pstart
, len
);
2690 if (name
[0] == '\0' || !strncmp(name
, cmd
, strlen(name
))) {
2691 readline_add_completion(cmd
);
2699 static void file_completion(const char *input
)
2704 char file
[1024], file_prefix
[1024];
2708 p
= strrchr(input
, '/');
2711 pstrcpy(file_prefix
, sizeof(file_prefix
), input
);
2712 pstrcpy(path
, sizeof(path
), ".");
2714 input_path_len
= p
- input
+ 1;
2715 memcpy(path
, input
, input_path_len
);
2716 if (input_path_len
> sizeof(path
) - 1)
2717 input_path_len
= sizeof(path
) - 1;
2718 path
[input_path_len
] = '\0';
2719 pstrcpy(file_prefix
, sizeof(file_prefix
), p
+ 1);
2721 #ifdef DEBUG_COMPLETION
2722 monitor_printf(cur_mon
, "input='%s' path='%s' prefix='%s'\n",
2723 input
, path
, file_prefix
);
2725 ffs
= opendir(path
);
2733 if (strstart(d
->d_name
, file_prefix
, NULL
)) {
2734 memcpy(file
, input
, input_path_len
);
2735 if (input_path_len
< sizeof(file
))
2736 pstrcpy(file
+ input_path_len
, sizeof(file
) - input_path_len
,
2738 /* stat the file to find out if it's a directory.
2739 * In that case add a slash to speed up typing long paths
2742 if(S_ISDIR(sb
.st_mode
))
2743 pstrcat(file
, sizeof(file
), "/");
2744 readline_add_completion(file
);
2750 static void block_completion_it(void *opaque
, BlockDriverState
*bs
)
2752 const char *name
= bdrv_get_device_name(bs
);
2753 const char *input
= opaque
;
2755 if (input
[0] == '\0' ||
2756 !strncmp(name
, (char *)input
, strlen(input
))) {
2757 readline_add_completion(name
);
2761 /* NOTE: this parser is an approximate form of the real command parser */
2762 static void parse_cmdline(const char *cmdline
,
2763 int *pnb_args
, char **args
)
2772 while (qemu_isspace(*p
))
2776 if (nb_args
>= MAX_ARGS
)
2778 ret
= get_str(buf
, sizeof(buf
), &p
);
2779 args
[nb_args
] = qemu_strdup(buf
);
2784 *pnb_args
= nb_args
;
2787 void readline_find_completion(const char *cmdline
)
2789 const char *cmdname
;
2790 char *args
[MAX_ARGS
];
2791 int nb_args
, i
, len
;
2792 const char *ptype
, *str
;
2793 const mon_cmd_t
*cmd
;
2796 parse_cmdline(cmdline
, &nb_args
, args
);
2797 #ifdef DEBUG_COMPLETION
2798 for(i
= 0; i
< nb_args
; i
++) {
2799 monitor_printf(cur_mon
, "arg%d = '%s'\n", i
, (char *)args
[i
]);
2803 /* if the line ends with a space, it means we want to complete the
2805 len
= strlen(cmdline
);
2806 if (len
> 0 && qemu_isspace(cmdline
[len
- 1])) {
2807 if (nb_args
>= MAX_ARGS
)
2809 args
[nb_args
++] = qemu_strdup("");
2812 /* command completion */
2817 readline_set_completion_index(strlen(cmdname
));
2818 for(cmd
= mon_cmds
; cmd
->name
!= NULL
; cmd
++) {
2819 cmd_completion(cmdname
, cmd
->name
);
2822 /* find the command */
2823 for(cmd
= mon_cmds
; cmd
->name
!= NULL
; cmd
++) {
2824 if (compare_cmd(args
[0], cmd
->name
))
2829 ptype
= cmd
->args_type
;
2830 for(i
= 0; i
< nb_args
- 2; i
++) {
2831 if (*ptype
!= '\0') {
2833 while (*ptype
== '?')
2837 str
= args
[nb_args
- 1];
2840 /* file completion */
2841 readline_set_completion_index(strlen(str
));
2842 file_completion(str
);
2845 /* block device name completion */
2846 readline_set_completion_index(strlen(str
));
2847 bdrv_iterate(block_completion_it
, (void *)str
);
2850 /* XXX: more generic ? */
2851 if (!strcmp(cmd
->name
, "info")) {
2852 readline_set_completion_index(strlen(str
));
2853 for(cmd
= info_cmds
; cmd
->name
!= NULL
; cmd
++) {
2854 cmd_completion(str
, cmd
->name
);
2856 } else if (!strcmp(cmd
->name
, "sendkey")) {
2857 readline_set_completion_index(strlen(str
));
2858 for(key
= key_defs
; key
->name
!= NULL
; key
++) {
2859 cmd_completion(str
, key
->name
);
2867 for(i
= 0; i
< nb_args
; i
++)
2871 static int term_can_read(void *opaque
)
2876 static void term_read(void *opaque
, const uint8_t *buf
, int size
)
2880 for (i
= 0; i
< size
; i
++)
2881 readline_handle_byte(buf
[i
]);
2884 static int monitor_suspended
;
2886 static void monitor_command_cb(Monitor
*mon
, const char *cmdline
, void *opaque
)
2888 monitor_handle_command(mon
, cmdline
);
2889 if (!monitor_suspended
)
2890 readline_show_prompt();
2892 monitor_suspended
= 2;
2895 void monitor_suspend(Monitor
*mon
)
2897 monitor_suspended
= 1;
2900 void monitor_resume(Monitor
*mon
)
2902 if (monitor_suspended
== 2)
2903 monitor_start_input();
2904 monitor_suspended
= 0;
2907 static void monitor_start_input(void)
2909 readline_start("(qemu) ", 0, monitor_command_cb
, NULL
);
2910 readline_show_prompt();
2913 static void term_event(void *opaque
, int event
)
2915 Monitor
*mon
= opaque
;
2917 if (event
!= CHR_EVENT_RESET
)
2921 monitor_printf(mon
, "QEMU %s monitor - type 'help' for more "
2922 "information\n", QEMU_VERSION
);
2923 monitor_start_input();
2926 static int is_first_init
= 1;
2928 void monitor_init(CharDriverState
*chr
, int show_banner
)
2932 if (is_first_init
) {
2933 key_timer
= qemu_new_timer(vm_clock
, release_keys
, NULL
);
2937 mon
= qemu_mallocz(sizeof(*mon
));
2939 hide_banner
= !show_banner
;
2943 qemu_chr_add_handlers(chr
, term_can_read
, term_read
, term_event
, mon
);
2945 LIST_INSERT_HEAD(&mon_list
, mon
, entry
);
2949 readline_start("", 0, monitor_command_cb
, NULL
);
2952 static void bdrv_password_cb(Monitor
*mon
, const char *password
, void *opaque
)
2954 BlockDriverState
*bs
= opaque
;
2957 if (bdrv_set_key(bs
, password
) != 0) {
2958 monitor_printf(mon
, "invalid password\n");
2961 if (password_completion_cb
)
2962 password_completion_cb(password_opaque
, ret
);
2964 monitor_start_input();
2967 void monitor_read_bdrv_key_start(Monitor
*mon
, BlockDriverState
*bs
,
2968 BlockDriverCompletionFunc
*completion_cb
,
2971 if (!bdrv_key_required(bs
)) {
2973 completion_cb(opaque
, 0);
2977 monitor_printf(mon
, "%s (%s) is encrypted.\n", bdrv_get_device_name(bs
),
2978 bdrv_get_encrypted_filename(bs
));
2980 password_completion_cb
= completion_cb
;
2981 password_opaque
= opaque
;
2983 monitor_read_password(mon
, bdrv_password_cb
, bs
);