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"
35 #include "audio/audio.h"
39 #include "qemu-timer.h"
40 #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 term_cmd_t
{
64 const char *args_type
;
71 static CharDriverState
*monitor_hd
[MAX_MON
];
72 static int hide_banner
;
74 static const term_cmd_t term_cmds
[];
75 static const term_cmd_t info_cmds
[];
77 static uint8_t term_outbuf
[1024];
78 static int term_outbuf_index
;
80 static void monitor_start_input(void);
81 static void monitor_readline(const char *prompt
, int is_password
,
82 char *buf
, int buf_size
);
84 static CPUState
*mon_cpu
= NULL
;
89 if (term_outbuf_index
> 0) {
90 for (i
= 0; i
< MAX_MON
; i
++)
91 if (monitor_hd
[i
] && monitor_hd
[i
]->focus
== 0)
92 qemu_chr_write(monitor_hd
[i
], term_outbuf
, term_outbuf_index
);
93 term_outbuf_index
= 0;
97 /* flush at every end of line or if the buffer is full */
98 void term_puts(const char *str
)
106 term_outbuf
[term_outbuf_index
++] = '\r';
107 term_outbuf
[term_outbuf_index
++] = c
;
108 if (term_outbuf_index
>= (sizeof(term_outbuf
) - 1) ||
114 void term_vprintf(const char *fmt
, va_list ap
)
117 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
121 void term_printf(const char *fmt
, ...)
125 term_vprintf(fmt
, ap
);
129 void term_print_filename(const char *filename
)
133 for (i
= 0; filename
[i
]; i
++) {
134 switch (filename
[i
]) {
138 term_printf("\\%c", filename
[i
]);
150 term_printf("%c", filename
[i
]);
156 static int monitor_fprintf(FILE *stream
, const char *fmt
, ...)
160 term_vprintf(fmt
, ap
);
165 static int compare_cmd(const char *name
, const char *list
)
167 const char *p
, *pstart
;
175 p
= pstart
+ strlen(pstart
);
176 if ((p
- pstart
) == len
&& !memcmp(pstart
, name
, len
))
185 static void help_cmd1(const term_cmd_t
*cmds
, const char *prefix
, const char *name
)
187 const term_cmd_t
*cmd
;
189 for(cmd
= cmds
; cmd
->name
!= NULL
; cmd
++) {
190 if (!name
|| !strcmp(name
, cmd
->name
))
191 term_printf("%s%s %s -- %s\n", prefix
, cmd
->name
, cmd
->params
, cmd
->help
);
195 static void help_cmd(const char *name
)
197 if (name
&& !strcmp(name
, "info")) {
198 help_cmd1(info_cmds
, "info ", NULL
);
200 help_cmd1(term_cmds
, "", name
);
201 if (name
&& !strcmp(name
, "log")) {
202 const CPULogItem
*item
;
203 term_printf("Log items (comma separated):\n");
204 term_printf("%-10s %s\n", "none", "remove all logs");
205 for(item
= cpu_log_items
; item
->mask
!= 0; item
++) {
206 term_printf("%-10s %s\n", item
->name
, item
->help
);
212 static void do_help(const char *name
)
217 static void do_commit(const char *device
)
221 all_devices
= !strcmp(device
, "all");
222 for (i
= 0; i
< nb_drives
; i
++) {
224 !strcmp(bdrv_get_device_name(drives_table
[i
].bdrv
), device
))
225 bdrv_commit(drives_table
[i
].bdrv
);
229 static void do_info(const char *item
)
231 const term_cmd_t
*cmd
;
232 void (*handler
)(void);
236 for(cmd
= info_cmds
; cmd
->name
!= NULL
; cmd
++) {
237 if (compare_cmd(item
, cmd
->name
))
244 handler
= cmd
->handler
;
248 static void do_info_version(void)
250 term_printf("%s\n", QEMU_VERSION
);
253 static void do_info_name(void)
256 term_printf("%s\n", qemu_name
);
259 #if defined(TARGET_I386)
260 static void do_info_hpet(void)
262 term_printf("HPET is %s by QEMU\n", (no_hpet
) ? "disabled" : "enabled");
266 static void do_info_uuid(void)
268 term_printf(UUID_FMT
"\n", qemu_uuid
[0], qemu_uuid
[1], qemu_uuid
[2],
269 qemu_uuid
[3], qemu_uuid
[4], qemu_uuid
[5], qemu_uuid
[6],
270 qemu_uuid
[7], qemu_uuid
[8], qemu_uuid
[9], qemu_uuid
[10],
271 qemu_uuid
[11], qemu_uuid
[12], qemu_uuid
[13], qemu_uuid
[14],
275 static void do_info_block(void)
280 static void do_info_blockstats(void)
285 /* get the current CPU defined by the user */
286 static int mon_set_cpu(int cpu_index
)
290 for(env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
291 if (env
->cpu_index
== cpu_index
) {
299 static CPUState
*mon_get_cpu(void)
305 kvm_save_registers(mon_cpu
);
310 static void do_info_registers(void)
317 cpu_dump_state(env
, NULL
, monitor_fprintf
,
320 cpu_dump_state(env
, NULL
, monitor_fprintf
,
325 static void do_info_cpus(void)
329 /* just to set the default cpu if not already done */
332 for(env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
333 kvm_save_registers(env
);
334 term_printf("%c CPU #%d:",
335 (env
== mon_cpu
) ? '*' : ' ',
337 #if defined(TARGET_I386)
338 term_printf(" pc=0x" TARGET_FMT_lx
, env
->eip
+ env
->segs
[R_CS
].base
);
339 #elif defined(TARGET_PPC)
340 term_printf(" nip=0x" TARGET_FMT_lx
, env
->nip
);
341 #elif defined(TARGET_SPARC)
342 term_printf(" pc=0x" TARGET_FMT_lx
" npc=0x" TARGET_FMT_lx
, env
->pc
, env
->npc
);
343 #elif defined(TARGET_MIPS)
344 term_printf(" PC=0x" TARGET_FMT_lx
, env
->active_tc
.PC
);
347 term_printf(" (halted)");
348 term_printf(" thread_id=%d", env
->thread_id
);
353 static void do_cpu_set(int index
)
355 if (mon_set_cpu(index
) < 0)
356 term_printf("Invalid CPU index\n");
359 static void do_cpu_set_nr(int value
, const char *status
)
363 if (!strcmp(status
, "online"))
365 else if (!strcmp(status
, "offline"))
368 term_printf("invalid status: %s\n", status
);
371 #if defined(TARGET_I386) || defined(TARGET_X86_64)
372 qemu_system_cpu_hot_add(value
, state
);
376 static void do_info_jit(void)
378 dump_exec_info(NULL
, monitor_fprintf
);
381 static void do_info_history (void)
388 str
= readline_get_history(i
);
391 term_printf("%d: '%s'\n", i
, str
);
396 #if defined(TARGET_PPC)
397 /* XXX: not implemented in other targets */
398 static void do_info_cpu_stats (void)
403 cpu_dump_statistics(env
, NULL
, &monitor_fprintf
, 0);
407 static void do_quit(void)
412 static int eject_device(BlockDriverState
*bs
, int force
)
414 if (bdrv_is_inserted(bs
)) {
416 if (!bdrv_is_removable(bs
)) {
417 term_printf("device is not removable\n");
420 if (bdrv_is_locked(bs
)) {
421 term_printf("device is locked\n");
430 static void do_eject(int force
, const char *filename
)
432 BlockDriverState
*bs
;
434 bs
= bdrv_find(filename
);
436 term_printf("device not found\n");
439 eject_device(bs
, force
);
442 static void do_change_block(const char *device
, const char *filename
, const char *fmt
)
444 BlockDriverState
*bs
;
445 BlockDriver
*drv
= NULL
;
447 bs
= bdrv_find(device
);
449 term_printf("device not found\n");
453 drv
= bdrv_find_format(fmt
);
455 term_printf("invalid format %s\n", fmt
);
459 if (eject_device(bs
, 0) < 0)
461 bdrv_open2(bs
, filename
, 0, drv
);
462 monitor_read_bdrv_key(bs
);
465 static void do_change_vnc(const char *target
, const char *arg
)
467 if (strcmp(target
, "passwd") == 0 ||
468 strcmp(target
, "password") == 0) {
471 strncpy(password
, arg
, sizeof(password
));
472 password
[sizeof(password
) - 1] = '\0';
474 monitor_readline("Password: ", 1, password
, sizeof(password
));
475 if (vnc_display_password(NULL
, password
) < 0)
476 term_printf("could not set VNC server password\n");
478 if (vnc_display_open(NULL
, target
) < 0)
479 term_printf("could not start VNC server on %s\n", target
);
483 static void do_change(const char *device
, const char *target
, const char *arg
)
485 if (strcmp(device
, "vnc") == 0) {
486 do_change_vnc(target
, arg
);
488 do_change_block(device
, target
, arg
);
492 static void do_screen_dump(const char *filename
)
494 vga_hw_screen_dump(filename
);
497 static void do_logfile(const char *filename
)
499 cpu_set_log_filename(filename
);
502 static void do_log(const char *items
)
506 if (!strcmp(items
, "none")) {
509 mask
= cpu_str_to_log_mask(items
);
518 static void do_stop(void)
520 vm_stop(EXCP_INTERRUPT
);
523 static void encrypted_bdrv_it(void *opaque
, BlockDriverState
*bs
)
527 if (bdrv_key_required(bs
))
528 *err
= monitor_read_bdrv_key(bs
);
533 static void do_cont(void)
537 bdrv_iterate(encrypted_bdrv_it
, &err
);
538 /* only resume the vm if all keys are set and valid */
543 #ifdef CONFIG_GDBSTUB
544 static void do_gdbserver(const char *port
)
547 port
= DEFAULT_GDBSTUB_PORT
;
548 if (gdbserver_start(port
) < 0) {
549 qemu_printf("Could not open gdbserver socket on port '%s'\n", port
);
551 qemu_printf("Waiting gdb connection on port '%s'\n", port
);
556 static void term_printc(int c
)
573 if (c
>= 32 && c
<= 126) {
574 term_printf("%c", c
);
576 term_printf("\\x%02x", c
);
583 static void memory_dump(int count
, int format
, int wsize
,
584 target_phys_addr_t addr
, int is_physical
)
587 int nb_per_line
, l
, line_size
, i
, max_digits
, len
;
595 if (!env
&& !is_physical
)
600 } else if (wsize
== 4) {
603 /* as default we use the current CS size */
607 if ((env
->efer
& MSR_EFER_LMA
) &&
608 (env
->segs
[R_CS
].flags
& DESC_L_MASK
))
612 if (!(env
->segs
[R_CS
].flags
& DESC_B_MASK
))
617 monitor_disas(env
, addr
, count
, is_physical
, flags
);
626 nb_per_line
= line_size
/ wsize
;
631 max_digits
= (wsize
* 8 + 2) / 3;
635 max_digits
= (wsize
* 8) / 4;
639 max_digits
= (wsize
* 8 * 10 + 32) / 33;
648 term_printf(TARGET_FMT_plx
":", addr
);
650 term_printf(TARGET_FMT_lx
":", (target_ulong
)addr
);
655 cpu_physical_memory_rw(addr
, buf
, l
, 0);
660 if (cpu_memory_rw_debug(env
, addr
, buf
, l
, 0) < 0) {
661 term_printf(" Cannot access memory\n");
670 v
= ldub_raw(buf
+ i
);
673 v
= lduw_raw(buf
+ i
);
676 v
= (uint32_t)ldl_raw(buf
+ i
);
679 v
= ldq_raw(buf
+ i
);
685 term_printf("%#*" PRIo64
, max_digits
, v
);
688 term_printf("0x%0*" PRIx64
, max_digits
, v
);
691 term_printf("%*" PRIu64
, max_digits
, v
);
694 term_printf("%*" PRId64
, max_digits
, v
);
708 #if TARGET_LONG_BITS == 64
709 #define GET_TLONG(h, l) (((uint64_t)(h) << 32) | (l))
711 #define GET_TLONG(h, l) (l)
714 static void do_memory_dump(int count
, int format
, int size
,
715 uint32_t addrh
, uint32_t addrl
)
717 target_long addr
= GET_TLONG(addrh
, addrl
);
718 memory_dump(count
, format
, size
, addr
, 0);
721 #if TARGET_PHYS_ADDR_BITS > 32
722 #define GET_TPHYSADDR(h, l) (((uint64_t)(h) << 32) | (l))
724 #define GET_TPHYSADDR(h, l) (l)
727 static void do_physical_memory_dump(int count
, int format
, int size
,
728 uint32_t addrh
, uint32_t addrl
)
731 target_phys_addr_t addr
= GET_TPHYSADDR(addrh
, addrl
);
732 memory_dump(count
, format
, size
, addr
, 1);
735 static void do_print(int count
, int format
, int size
, unsigned int valh
, unsigned int vall
)
737 target_phys_addr_t val
= GET_TPHYSADDR(valh
, vall
);
738 #if TARGET_PHYS_ADDR_BITS == 32
741 term_printf("%#o", val
);
744 term_printf("%#x", val
);
747 term_printf("%u", val
);
751 term_printf("%d", val
);
760 term_printf("%#" PRIo64
, val
);
763 term_printf("%#" PRIx64
, val
);
766 term_printf("%" PRIu64
, val
);
770 term_printf("%" PRId64
, val
);
780 static void do_memory_save(unsigned int valh
, unsigned int vall
,
781 uint32_t size
, const char *filename
)
784 target_long addr
= GET_TLONG(valh
, vall
);
793 f
= fopen(filename
, "wb");
795 term_printf("could not open '%s'\n", filename
);
802 cpu_memory_rw_debug(env
, addr
, buf
, l
, 0);
803 fwrite(buf
, 1, l
, f
);
810 static void do_physical_memory_save(unsigned int valh
, unsigned int vall
,
811 uint32_t size
, const char *filename
)
816 target_phys_addr_t addr
= GET_TPHYSADDR(valh
, vall
);
818 f
= fopen(filename
, "wb");
820 term_printf("could not open '%s'\n", filename
);
827 cpu_physical_memory_rw(addr
, buf
, l
, 0);
828 fwrite(buf
, 1, l
, f
);
836 static void do_sum(uint32_t start
, uint32_t size
)
843 for(addr
= start
; addr
< (start
+ size
); addr
++) {
844 cpu_physical_memory_rw(addr
, buf
, 1, 0);
845 /* BSD sum algorithm ('sum' Unix command) */
846 sum
= (sum
>> 1) | (sum
<< 15);
849 term_printf("%05d\n", sum
);
857 static const KeyDef key_defs
[] = {
884 { 0x0e, "backspace" },
921 { 0x37, "asterisk" },
924 { 0x3a, "caps_lock" },
935 { 0x45, "num_lock" },
936 { 0x46, "scroll_lock" },
938 { 0xb5, "kp_divide" },
939 { 0x37, "kp_multiply" },
940 { 0x4a, "kp_subtract" },
942 { 0x9c, "kp_enter" },
943 { 0x53, "kp_decimal" },
976 #if defined(TARGET_SPARC) && !defined(TARGET_SPARC64)
996 static int get_keycode(const char *key
)
1002 for(p
= key_defs
; p
->name
!= NULL
; p
++) {
1003 if (!strcmp(key
, p
->name
))
1006 if (strstart(key
, "0x", NULL
)) {
1007 ret
= strtoul(key
, &endp
, 0);
1008 if (*endp
== '\0' && ret
>= 0x01 && ret
<= 0xff)
1014 #define MAX_KEYCODES 16
1015 static uint8_t keycodes
[MAX_KEYCODES
];
1016 static int nb_pending_keycodes
;
1017 static QEMUTimer
*key_timer
;
1019 static void release_keys(void *opaque
)
1023 while (nb_pending_keycodes
> 0) {
1024 nb_pending_keycodes
--;
1025 keycode
= keycodes
[nb_pending_keycodes
];
1027 kbd_put_keycode(0xe0);
1028 kbd_put_keycode(keycode
| 0x80);
1032 static void do_sendkey(const char *string
, int has_hold_time
, int hold_time
)
1034 char keyname_buf
[16];
1036 int keyname_len
, keycode
, i
;
1038 if (nb_pending_keycodes
> 0) {
1039 qemu_del_timer(key_timer
);
1046 separator
= strchr(string
, '-');
1047 keyname_len
= separator
? separator
- string
: strlen(string
);
1048 if (keyname_len
> 0) {
1049 pstrcpy(keyname_buf
, sizeof(keyname_buf
), string
);
1050 if (keyname_len
> sizeof(keyname_buf
) - 1) {
1051 term_printf("invalid key: '%s...'\n", keyname_buf
);
1054 if (i
== MAX_KEYCODES
) {
1055 term_printf("too many keys\n");
1058 keyname_buf
[keyname_len
] = 0;
1059 keycode
= get_keycode(keyname_buf
);
1061 term_printf("unknown key: '%s'\n", keyname_buf
);
1064 keycodes
[i
++] = keycode
;
1068 string
= separator
+ 1;
1070 nb_pending_keycodes
= i
;
1071 /* key down events */
1072 for (i
= 0; i
< nb_pending_keycodes
; i
++) {
1073 keycode
= keycodes
[i
];
1075 kbd_put_keycode(0xe0);
1076 kbd_put_keycode(keycode
& 0x7f);
1078 /* delayed key up events */
1079 qemu_mod_timer(key_timer
, qemu_get_clock(vm_clock
) +
1080 muldiv64(ticks_per_sec
, hold_time
, 1000));
1083 static int mouse_button_state
;
1085 static void do_mouse_move(const char *dx_str
, const char *dy_str
,
1089 dx
= strtol(dx_str
, NULL
, 0);
1090 dy
= strtol(dy_str
, NULL
, 0);
1093 dz
= strtol(dz_str
, NULL
, 0);
1094 kbd_mouse_event(dx
, dy
, dz
, mouse_button_state
);
1097 static void do_mouse_button(int button_state
)
1099 mouse_button_state
= button_state
;
1100 kbd_mouse_event(0, 0, 0, mouse_button_state
);
1103 static void do_ioport_read(int count
, int format
, int size
, int addr
, int has_index
, int index
)
1109 cpu_outb(NULL
, addr
& 0xffff, index
& 0xff);
1117 val
= cpu_inb(NULL
, addr
);
1121 val
= cpu_inw(NULL
, addr
);
1125 val
= cpu_inl(NULL
, addr
);
1129 term_printf("port%c[0x%04x] = %#0*x\n",
1130 suffix
, addr
, size
* 2, val
);
1133 /* boot_set handler */
1134 static QEMUBootSetHandler
*qemu_boot_set_handler
= NULL
;
1135 static void *boot_opaque
;
1137 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
1139 qemu_boot_set_handler
= func
;
1140 boot_opaque
= opaque
;
1143 static void do_boot_set(const char *bootdevice
)
1147 if (qemu_boot_set_handler
) {
1148 res
= qemu_boot_set_handler(boot_opaque
, bootdevice
);
1150 term_printf("boot device list now set to %s\n", bootdevice
);
1152 term_printf("setting boot device list failed with error %i\n", res
);
1154 term_printf("no function defined to set boot device list for this architecture\n");
1158 static void do_system_reset(void)
1160 qemu_system_reset_request();
1163 static void do_system_powerdown(void)
1165 qemu_system_powerdown_request();
1168 #if defined(TARGET_I386)
1169 static void print_pte(uint32_t addr
, uint32_t pte
, uint32_t mask
)
1171 term_printf("%08x: %08x %c%c%c%c%c%c%c%c\n",
1174 pte
& PG_GLOBAL_MASK
? 'G' : '-',
1175 pte
& PG_PSE_MASK
? 'P' : '-',
1176 pte
& PG_DIRTY_MASK
? 'D' : '-',
1177 pte
& PG_ACCESSED_MASK
? 'A' : '-',
1178 pte
& PG_PCD_MASK
? 'C' : '-',
1179 pte
& PG_PWT_MASK
? 'T' : '-',
1180 pte
& PG_USER_MASK
? 'U' : '-',
1181 pte
& PG_RW_MASK
? 'W' : '-');
1184 static void tlb_info(void)
1188 uint32_t pgd
, pde
, pte
;
1190 env
= mon_get_cpu();
1194 if (!(env
->cr
[0] & CR0_PG_MASK
)) {
1195 term_printf("PG disabled\n");
1198 pgd
= env
->cr
[3] & ~0xfff;
1199 for(l1
= 0; l1
< 1024; l1
++) {
1200 cpu_physical_memory_read(pgd
+ l1
* 4, (uint8_t *)&pde
, 4);
1201 pde
= le32_to_cpu(pde
);
1202 if (pde
& PG_PRESENT_MASK
) {
1203 if ((pde
& PG_PSE_MASK
) && (env
->cr
[4] & CR4_PSE_MASK
)) {
1204 print_pte((l1
<< 22), pde
, ~((1 << 20) - 1));
1206 for(l2
= 0; l2
< 1024; l2
++) {
1207 cpu_physical_memory_read((pde
& ~0xfff) + l2
* 4,
1208 (uint8_t *)&pte
, 4);
1209 pte
= le32_to_cpu(pte
);
1210 if (pte
& PG_PRESENT_MASK
) {
1211 print_pte((l1
<< 22) + (l2
<< 12),
1221 static void mem_print(uint32_t *pstart
, int *plast_prot
,
1222 uint32_t end
, int prot
)
1225 prot1
= *plast_prot
;
1226 if (prot
!= prot1
) {
1227 if (*pstart
!= -1) {
1228 term_printf("%08x-%08x %08x %c%c%c\n",
1229 *pstart
, end
, end
- *pstart
,
1230 prot1
& PG_USER_MASK
? 'u' : '-',
1232 prot1
& PG_RW_MASK
? 'w' : '-');
1242 static void mem_info(void)
1245 int l1
, l2
, prot
, last_prot
;
1246 uint32_t pgd
, pde
, pte
, start
, end
;
1248 env
= mon_get_cpu();
1252 if (!(env
->cr
[0] & CR0_PG_MASK
)) {
1253 term_printf("PG disabled\n");
1256 pgd
= env
->cr
[3] & ~0xfff;
1259 for(l1
= 0; l1
< 1024; l1
++) {
1260 cpu_physical_memory_read(pgd
+ l1
* 4, (uint8_t *)&pde
, 4);
1261 pde
= le32_to_cpu(pde
);
1263 if (pde
& PG_PRESENT_MASK
) {
1264 if ((pde
& PG_PSE_MASK
) && (env
->cr
[4] & CR4_PSE_MASK
)) {
1265 prot
= pde
& (PG_USER_MASK
| PG_RW_MASK
| PG_PRESENT_MASK
);
1266 mem_print(&start
, &last_prot
, end
, prot
);
1268 for(l2
= 0; l2
< 1024; l2
++) {
1269 cpu_physical_memory_read((pde
& ~0xfff) + l2
* 4,
1270 (uint8_t *)&pte
, 4);
1271 pte
= le32_to_cpu(pte
);
1272 end
= (l1
<< 22) + (l2
<< 12);
1273 if (pte
& PG_PRESENT_MASK
) {
1274 prot
= pte
& (PG_USER_MASK
| PG_RW_MASK
| PG_PRESENT_MASK
);
1278 mem_print(&start
, &last_prot
, end
, prot
);
1283 mem_print(&start
, &last_prot
, end
, prot
);
1289 #if defined(TARGET_SH4)
1291 static void print_tlb(int idx
, tlb_t
*tlb
)
1293 term_printf(" tlb%i:\t"
1294 "asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t"
1295 "v=%hhu shared=%hhu cached=%hhu prot=%hhu "
1296 "dirty=%hhu writethrough=%hhu\n",
1298 tlb
->asid
, tlb
->vpn
, tlb
->ppn
, tlb
->sz
, tlb
->size
,
1299 tlb
->v
, tlb
->sh
, tlb
->c
, tlb
->pr
,
1303 static void tlb_info(void)
1305 CPUState
*env
= mon_get_cpu();
1308 term_printf ("ITLB:\n");
1309 for (i
= 0 ; i
< ITLB_SIZE
; i
++)
1310 print_tlb (i
, &env
->itlb
[i
]);
1311 term_printf ("UTLB:\n");
1312 for (i
= 0 ; i
< UTLB_SIZE
; i
++)
1313 print_tlb (i
, &env
->utlb
[i
]);
1318 static void do_info_kqemu(void)
1324 env
= mon_get_cpu();
1326 term_printf("No cpu initialized yet");
1329 val
= env
->kqemu_enabled
;
1330 term_printf("kqemu support: ");
1334 term_printf("disabled\n");
1337 term_printf("enabled for user code\n");
1340 term_printf("enabled for user and kernel code\n");
1344 term_printf("kqemu support: not compiled\n");
1348 static void do_info_kvm(void)
1350 #if defined(USE_KVM) || defined(CONFIG_KVM)
1351 term_printf("kvm support: ");
1353 term_printf("enabled\n");
1355 term_printf("disabled\n");
1357 term_printf("kvm support: not compiled\n");
1361 #ifdef CONFIG_PROFILER
1365 int64_t kqemu_exec_count
;
1367 int64_t kqemu_ret_int_count
;
1368 int64_t kqemu_ret_excp_count
;
1369 int64_t kqemu_ret_intr_count
;
1371 static void do_info_profile(void)
1377 term_printf("async time %" PRId64
" (%0.3f)\n",
1378 dev_time
, dev_time
/ (double)ticks_per_sec
);
1379 term_printf("qemu time %" PRId64
" (%0.3f)\n",
1380 qemu_time
, qemu_time
/ (double)ticks_per_sec
);
1381 term_printf("kqemu time %" PRId64
" (%0.3f %0.1f%%) count=%" PRId64
" int=%" PRId64
" excp=%" PRId64
" intr=%" PRId64
"\n",
1382 kqemu_time
, kqemu_time
/ (double)ticks_per_sec
,
1383 kqemu_time
/ (double)total
* 100.0,
1385 kqemu_ret_int_count
,
1386 kqemu_ret_excp_count
,
1387 kqemu_ret_intr_count
);
1390 kqemu_exec_count
= 0;
1392 kqemu_ret_int_count
= 0;
1393 kqemu_ret_excp_count
= 0;
1394 kqemu_ret_intr_count
= 0;
1396 kqemu_record_dump();
1400 static void do_info_profile(void)
1402 term_printf("Internal profiler not compiled\n");
1406 /* Capture support */
1407 static LIST_HEAD (capture_list_head
, CaptureState
) capture_head
;
1409 static void do_info_capture (void)
1414 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
1415 term_printf ("[%d]: ", i
);
1416 s
->ops
.info (s
->opaque
);
1420 static void do_stop_capture (int n
)
1425 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
1427 s
->ops
.destroy (s
->opaque
);
1428 LIST_REMOVE (s
, entries
);
1436 static void do_wav_capture (const char *path
,
1437 int has_freq
, int freq
,
1438 int has_bits
, int bits
,
1439 int has_channels
, int nchannels
)
1443 s
= qemu_mallocz (sizeof (*s
));
1445 freq
= has_freq
? freq
: 44100;
1446 bits
= has_bits
? bits
: 16;
1447 nchannels
= has_channels
? nchannels
: 2;
1449 if (wav_start_capture (s
, path
, freq
, bits
, nchannels
)) {
1450 term_printf ("Faied to add wave capture\n");
1453 LIST_INSERT_HEAD (&capture_head
, s
, entries
);
1457 #if defined(TARGET_I386)
1458 static void do_inject_nmi(int cpu_index
)
1462 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
)
1463 if (env
->cpu_index
== cpu_index
) {
1465 kvm_inject_interrupt(env
, CPU_INTERRUPT_NMI
);
1467 cpu_interrupt(env
, CPU_INTERRUPT_NMI
);
1473 static void do_info_status(void)
1476 term_printf("VM status: running\n");
1478 term_printf("VM status: paused\n");
1482 static void do_balloon(int value
)
1484 ram_addr_t target
= value
;
1485 qemu_balloon(target
<< 20);
1488 static void do_info_balloon(void)
1492 actual
= qemu_balloon_status();
1493 if (kvm_enabled() && !kvm_has_sync_mmu())
1494 term_printf("Using KVM without synchronous MMU, ballooning disabled\n");
1495 else if (actual
== 0)
1496 term_printf("Ballooning not activated in VM\n");
1498 term_printf("balloon: actual=%d\n", (int)(actual
>> 20));
1501 /* Please update qemu-doc.texi when adding or changing commands */
1502 static const term_cmd_t term_cmds
[] = {
1503 { "help|?", "s?", do_help
,
1504 "[cmd]", "show the help" },
1505 { "commit", "s", do_commit
,
1506 "device|all", "commit changes to the disk images (if -snapshot is used) or backing files" },
1507 { "info", "s?", do_info
,
1508 "subcommand", "show various information about the system state" },
1509 { "q|quit", "", do_quit
,
1510 "", "quit the emulator" },
1511 { "eject", "-fB", do_eject
,
1512 "[-f] device", "eject a removable medium (use -f to force it)" },
1513 { "change", "BFs?", do_change
,
1514 "device filename [format]", "change a removable medium, optional format" },
1515 { "screendump", "F", do_screen_dump
,
1516 "filename", "save screen into PPM image 'filename'" },
1517 { "logfile", "F", do_logfile
,
1518 "filename", "output logs to 'filename'" },
1519 { "log", "s", do_log
,
1520 "item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" },
1521 { "savevm", "s?", do_savevm
,
1522 "tag|id", "save a VM snapshot. If no tag or id are provided, a new snapshot is created" },
1523 { "loadvm", "s", do_loadvm
,
1524 "tag|id", "restore a VM snapshot from its tag or id" },
1525 { "delvm", "s", do_delvm
,
1526 "tag|id", "delete a VM snapshot from its tag or id" },
1527 { "stop", "", do_stop
,
1528 "", "stop emulation", },
1529 { "c|cont", "", do_cont
,
1530 "", "resume emulation", },
1531 #ifdef CONFIG_GDBSTUB
1532 { "gdbserver", "s?", do_gdbserver
,
1533 "[port]", "start gdbserver session (default port=1234)", },
1535 { "x", "/l", do_memory_dump
,
1536 "/fmt addr", "virtual memory dump starting at 'addr'", },
1537 { "xp", "/l", do_physical_memory_dump
,
1538 "/fmt addr", "physical memory dump starting at 'addr'", },
1539 { "p|print", "/l", do_print
,
1540 "/fmt expr", "print expression value (use $reg for CPU register access)", },
1541 { "i", "/ii.", do_ioport_read
,
1542 "/fmt addr", "I/O port read" },
1544 { "sendkey", "si?", do_sendkey
,
1545 "keys [hold_ms]", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1', default hold time=100 ms)" },
1546 { "system_reset", "", do_system_reset
,
1547 "", "reset the system" },
1548 { "system_powerdown", "", do_system_powerdown
,
1549 "", "send system power down event" },
1550 { "sum", "ii", do_sum
,
1551 "addr size", "compute the checksum of a memory region" },
1552 { "usb_add", "s", do_usb_add
,
1553 "device", "add USB device (e.g. 'host:bus.addr' or 'host:vendor_id:product_id')" },
1554 { "usb_del", "s", do_usb_del
,
1555 "device", "remove USB device 'bus.addr'" },
1556 { "cpu", "i", do_cpu_set
,
1557 "index", "set the default CPU" },
1558 { "mouse_move", "sss?", do_mouse_move
,
1559 "dx dy [dz]", "send mouse move events" },
1560 { "mouse_button", "i", do_mouse_button
,
1561 "state", "change mouse button state (1=L, 2=M, 4=R)" },
1562 { "mouse_set", "i", do_mouse_set
,
1563 "index", "set which mouse device receives events" },
1565 { "wavcapture", "si?i?i?", do_wav_capture
,
1566 "path [frequency bits channels]",
1567 "capture audio to a wave file (default frequency=44100 bits=16 channels=2)" },
1569 { "stopcapture", "i", do_stop_capture
,
1570 "capture index", "stop capture" },
1571 { "memsave", "lis", do_memory_save
,
1572 "addr size file", "save to disk virtual memory dump starting at 'addr' of size 'size'", },
1573 { "pmemsave", "lis", do_physical_memory_save
,
1574 "addr size file", "save to disk physical memory dump starting at 'addr' of size 'size'", },
1575 { "boot_set", "s", do_boot_set
,
1576 "bootdevice", "define new values for the boot device list" },
1577 #if defined(TARGET_I386)
1578 { "nmi", "i", do_inject_nmi
,
1579 "cpu", "inject an NMI on the given CPU", },
1581 { "migrate", "-ds", do_migrate
,
1582 "[-d] uri", "migrate to URI (using -d to not wait for completion)" },
1583 { "migrate_cancel", "", do_migrate_cancel
,
1584 "", "cancel the current VM migration" },
1585 { "migrate_set_speed", "s", do_migrate_set_speed
,
1586 "value", "set maximum speed (in bytes) for migrations" },
1587 #if defined(TARGET_I386)
1588 { "drive_add", "ss", drive_hot_add
, "pci_addr=[[<domain>:]<bus>:]<slot>\n"
1589 "[file=file][,if=type][,bus=n]\n"
1590 "[,unit=m][,media=d][index=i]\n"
1591 "[,cyls=c,heads=h,secs=s[,trans=t]]\n"
1592 "[snapshot=on|off][,cache=on|off]",
1593 "add drive to PCI storage controller" },
1594 { "pci_add", "sss", pci_device_hot_add
, "pci_addr=auto|[[<domain>:]<bus>:]<slot> nic|storage|host [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]... [host=02:00.0[,name=string][,dma=none]", "hot-add PCI device" },
1595 { "pci_del", "s", pci_device_hot_remove
, "pci_addr=[[<domain>:]<bus>:]<slot>", "hot remove PCI device" },
1596 { "host_net_add", "ss", net_host_device_add
,
1597 "[tap,user,socket,vde] options", "add host VLAN client" },
1598 { "host_net_remove", "is", net_host_device_remove
,
1599 "vlan_id name", "remove host VLAN client" },
1601 { "balloon", "i", do_balloon
,
1602 "target", "request VM to change it's memory allocation (in MB)" },
1603 { "set_link", "ss", do_set_link
,
1604 "name [up|down]", "change the link status of a network adapter" },
1605 { "set_link", "ss", do_set_link
, "name [up|down]" },
1606 { "cpu_set", "is", do_cpu_set_nr
, "cpu [online|offline]", "change cpu state" },
1607 #if defined(TARGET_I386) || defined(TARGET_X86_64)
1608 { "drive_add", "iss", drive_hot_add
, "pcibus pcidevfn [file=file][,if=type][,bus=n]\n"
1609 "[,unit=m][,media=d][index=i]\n"
1610 "[,cyls=c,heads=h,secs=s[,trans=t]]\n"
1611 "[snapshot=on|off][,cache=on|off]",
1612 "add drive to PCI storage controller" },
1617 /* Please update qemu-doc.texi when adding or changing commands */
1618 static const term_cmd_t info_cmds
[] = {
1619 { "version", "", do_info_version
,
1620 "", "show the version of QEMU" },
1621 { "network", "", do_info_network
,
1622 "", "show the network state" },
1623 { "chardev", "", qemu_chr_info
,
1624 "", "show the character devices" },
1625 { "block", "", do_info_block
,
1626 "", "show the block devices" },
1627 { "blockstats", "", do_info_blockstats
,
1628 "", "show block device statistics" },
1629 { "registers", "", do_info_registers
,
1630 "", "show the cpu registers" },
1631 { "cpus", "", do_info_cpus
,
1632 "", "show infos for each CPU" },
1633 { "history", "", do_info_history
,
1634 "", "show the command line history", },
1635 { "irq", "", irq_info
,
1636 "", "show the interrupts statistics (if available)", },
1637 { "pic", "", pic_info
,
1638 "", "show i8259 (PIC) state", },
1639 { "pci", "", pci_info
,
1640 "", "show PCI info", },
1641 #if defined(TARGET_I386) || defined(TARGET_SH4)
1642 { "tlb", "", tlb_info
,
1643 "", "show virtual to physical memory mappings", },
1645 #if defined(TARGET_I386)
1646 { "mem", "", mem_info
,
1647 "", "show the active virtual memory mappings", },
1648 { "hpet", "", do_info_hpet
,
1649 "", "show state of HPET", },
1651 { "jit", "", do_info_jit
,
1652 "", "show dynamic compiler info", },
1653 { "kqemu", "", do_info_kqemu
,
1654 "", "show KQEMU information", },
1655 { "kvm", "", do_info_kvm
,
1656 "", "show KVM information", },
1657 { "usb", "", usb_info
,
1658 "", "show guest USB devices", },
1659 { "usbhost", "", usb_host_info
,
1660 "", "show host USB devices", },
1661 { "profile", "", do_info_profile
,
1662 "", "show profiling information", },
1663 { "capture", "", do_info_capture
,
1664 "", "show capture information" },
1665 { "snapshots", "", do_info_snapshots
,
1666 "", "show the currently saved VM snapshots" },
1667 { "status", "", do_info_status
,
1668 "", "show the current VM status (running|paused)" },
1669 { "pcmcia", "", pcmcia_info
,
1670 "", "show guest PCMCIA status" },
1671 { "mice", "", do_info_mice
,
1672 "", "show which guest mouse is receiving events" },
1673 { "vnc", "", do_info_vnc
,
1674 "", "show the vnc server status"},
1675 { "name", "", do_info_name
,
1676 "", "show the current VM name" },
1677 { "uuid", "", do_info_uuid
,
1678 "", "show the current VM UUID" },
1679 #if defined(TARGET_PPC)
1680 { "cpustats", "", do_info_cpu_stats
,
1681 "", "show CPU statistics", },
1683 #if defined(CONFIG_SLIRP)
1684 { "slirp", "", do_info_slirp
,
1685 "", "show SLIRP statistics", },
1687 { "migrate", "", do_info_migrate
, "", "show migration status" },
1688 { "balloon", "", do_info_balloon
,
1689 "", "show balloon information" },
1693 /*******************************************************************/
1695 static const char *pch
;
1696 static jmp_buf expr_env
;
1701 typedef struct MonitorDef
{
1704 target_long (*get_value
)(const struct MonitorDef
*md
, int val
);
1708 #if defined(TARGET_I386)
1709 static target_long
monitor_get_pc (const struct MonitorDef
*md
, int val
)
1711 CPUState
*env
= mon_get_cpu();
1714 return env
->eip
+ env
->segs
[R_CS
].base
;
1718 #if defined(TARGET_PPC)
1719 static target_long
monitor_get_ccr (const struct MonitorDef
*md
, int val
)
1721 CPUState
*env
= mon_get_cpu();
1729 for (i
= 0; i
< 8; i
++)
1730 u
|= env
->crf
[i
] << (32 - (4 * i
));
1735 static target_long
monitor_get_msr (const struct MonitorDef
*md
, int val
)
1737 CPUState
*env
= mon_get_cpu();
1743 static target_long
monitor_get_xer (const struct MonitorDef
*md
, int val
)
1745 CPUState
*env
= mon_get_cpu();
1751 static target_long
monitor_get_decr (const struct MonitorDef
*md
, int val
)
1753 CPUState
*env
= mon_get_cpu();
1756 return cpu_ppc_load_decr(env
);
1759 static target_long
monitor_get_tbu (const struct MonitorDef
*md
, int val
)
1761 CPUState
*env
= mon_get_cpu();
1764 return cpu_ppc_load_tbu(env
);
1767 static target_long
monitor_get_tbl (const struct MonitorDef
*md
, int val
)
1769 CPUState
*env
= mon_get_cpu();
1772 return cpu_ppc_load_tbl(env
);
1776 #if defined(TARGET_SPARC)
1777 #ifndef TARGET_SPARC64
1778 static target_long
monitor_get_psr (const struct MonitorDef
*md
, int val
)
1780 CPUState
*env
= mon_get_cpu();
1783 return GET_PSR(env
);
1787 static target_long
monitor_get_reg(const struct MonitorDef
*md
, int val
)
1789 CPUState
*env
= mon_get_cpu();
1792 return env
->regwptr
[val
];
1796 static const MonitorDef monitor_defs
[] = {
1799 #define SEG(name, seg) \
1800 { name, offsetof(CPUState, segs[seg].selector), NULL, MD_I32 },\
1801 { name ".base", offsetof(CPUState, segs[seg].base) },\
1802 { name ".limit", offsetof(CPUState, segs[seg].limit), NULL, MD_I32 },
1804 { "eax", offsetof(CPUState
, regs
[0]) },
1805 { "ecx", offsetof(CPUState
, regs
[1]) },
1806 { "edx", offsetof(CPUState
, regs
[2]) },
1807 { "ebx", offsetof(CPUState
, regs
[3]) },
1808 { "esp|sp", offsetof(CPUState
, regs
[4]) },
1809 { "ebp|fp", offsetof(CPUState
, regs
[5]) },
1810 { "esi", offsetof(CPUState
, regs
[6]) },
1811 { "edi", offsetof(CPUState
, regs
[7]) },
1812 #ifdef TARGET_X86_64
1813 { "r8", offsetof(CPUState
, regs
[8]) },
1814 { "r9", offsetof(CPUState
, regs
[9]) },
1815 { "r10", offsetof(CPUState
, regs
[10]) },
1816 { "r11", offsetof(CPUState
, regs
[11]) },
1817 { "r12", offsetof(CPUState
, regs
[12]) },
1818 { "r13", offsetof(CPUState
, regs
[13]) },
1819 { "r14", offsetof(CPUState
, regs
[14]) },
1820 { "r15", offsetof(CPUState
, regs
[15]) },
1822 { "eflags", offsetof(CPUState
, eflags
) },
1823 { "eip", offsetof(CPUState
, eip
) },
1830 { "pc", 0, monitor_get_pc
, },
1831 #elif defined(TARGET_PPC)
1832 /* General purpose registers */
1833 { "r0", offsetof(CPUState
, gpr
[0]) },
1834 { "r1", offsetof(CPUState
, gpr
[1]) },
1835 { "r2", offsetof(CPUState
, gpr
[2]) },
1836 { "r3", offsetof(CPUState
, gpr
[3]) },
1837 { "r4", offsetof(CPUState
, gpr
[4]) },
1838 { "r5", offsetof(CPUState
, gpr
[5]) },
1839 { "r6", offsetof(CPUState
, gpr
[6]) },
1840 { "r7", offsetof(CPUState
, gpr
[7]) },
1841 { "r8", offsetof(CPUState
, gpr
[8]) },
1842 { "r9", offsetof(CPUState
, gpr
[9]) },
1843 { "r10", offsetof(CPUState
, gpr
[10]) },
1844 { "r11", offsetof(CPUState
, gpr
[11]) },
1845 { "r12", offsetof(CPUState
, gpr
[12]) },
1846 { "r13", offsetof(CPUState
, gpr
[13]) },
1847 { "r14", offsetof(CPUState
, gpr
[14]) },
1848 { "r15", offsetof(CPUState
, gpr
[15]) },
1849 { "r16", offsetof(CPUState
, gpr
[16]) },
1850 { "r17", offsetof(CPUState
, gpr
[17]) },
1851 { "r18", offsetof(CPUState
, gpr
[18]) },
1852 { "r19", offsetof(CPUState
, gpr
[19]) },
1853 { "r20", offsetof(CPUState
, gpr
[20]) },
1854 { "r21", offsetof(CPUState
, gpr
[21]) },
1855 { "r22", offsetof(CPUState
, gpr
[22]) },
1856 { "r23", offsetof(CPUState
, gpr
[23]) },
1857 { "r24", offsetof(CPUState
, gpr
[24]) },
1858 { "r25", offsetof(CPUState
, gpr
[25]) },
1859 { "r26", offsetof(CPUState
, gpr
[26]) },
1860 { "r27", offsetof(CPUState
, gpr
[27]) },
1861 { "r28", offsetof(CPUState
, gpr
[28]) },
1862 { "r29", offsetof(CPUState
, gpr
[29]) },
1863 { "r30", offsetof(CPUState
, gpr
[30]) },
1864 { "r31", offsetof(CPUState
, gpr
[31]) },
1865 /* Floating point registers */
1866 { "f0", offsetof(CPUState
, fpr
[0]) },
1867 { "f1", offsetof(CPUState
, fpr
[1]) },
1868 { "f2", offsetof(CPUState
, fpr
[2]) },
1869 { "f3", offsetof(CPUState
, fpr
[3]) },
1870 { "f4", offsetof(CPUState
, fpr
[4]) },
1871 { "f5", offsetof(CPUState
, fpr
[5]) },
1872 { "f6", offsetof(CPUState
, fpr
[6]) },
1873 { "f7", offsetof(CPUState
, fpr
[7]) },
1874 { "f8", offsetof(CPUState
, fpr
[8]) },
1875 { "f9", offsetof(CPUState
, fpr
[9]) },
1876 { "f10", offsetof(CPUState
, fpr
[10]) },
1877 { "f11", offsetof(CPUState
, fpr
[11]) },
1878 { "f12", offsetof(CPUState
, fpr
[12]) },
1879 { "f13", offsetof(CPUState
, fpr
[13]) },
1880 { "f14", offsetof(CPUState
, fpr
[14]) },
1881 { "f15", offsetof(CPUState
, fpr
[15]) },
1882 { "f16", offsetof(CPUState
, fpr
[16]) },
1883 { "f17", offsetof(CPUState
, fpr
[17]) },
1884 { "f18", offsetof(CPUState
, fpr
[18]) },
1885 { "f19", offsetof(CPUState
, fpr
[19]) },
1886 { "f20", offsetof(CPUState
, fpr
[20]) },
1887 { "f21", offsetof(CPUState
, fpr
[21]) },
1888 { "f22", offsetof(CPUState
, fpr
[22]) },
1889 { "f23", offsetof(CPUState
, fpr
[23]) },
1890 { "f24", offsetof(CPUState
, fpr
[24]) },
1891 { "f25", offsetof(CPUState
, fpr
[25]) },
1892 { "f26", offsetof(CPUState
, fpr
[26]) },
1893 { "f27", offsetof(CPUState
, fpr
[27]) },
1894 { "f28", offsetof(CPUState
, fpr
[28]) },
1895 { "f29", offsetof(CPUState
, fpr
[29]) },
1896 { "f30", offsetof(CPUState
, fpr
[30]) },
1897 { "f31", offsetof(CPUState
, fpr
[31]) },
1898 { "fpscr", offsetof(CPUState
, fpscr
) },
1899 /* Next instruction pointer */
1900 { "nip|pc", offsetof(CPUState
, nip
) },
1901 { "lr", offsetof(CPUState
, lr
) },
1902 { "ctr", offsetof(CPUState
, ctr
) },
1903 { "decr", 0, &monitor_get_decr
, },
1904 { "ccr", 0, &monitor_get_ccr
, },
1905 /* Machine state register */
1906 { "msr", 0, &monitor_get_msr
, },
1907 { "xer", 0, &monitor_get_xer
, },
1908 { "tbu", 0, &monitor_get_tbu
, },
1909 { "tbl", 0, &monitor_get_tbl
, },
1910 #if defined(TARGET_PPC64)
1911 /* Address space register */
1912 { "asr", offsetof(CPUState
, asr
) },
1914 /* Segment registers */
1915 { "sdr1", offsetof(CPUState
, sdr1
) },
1916 { "sr0", offsetof(CPUState
, sr
[0]) },
1917 { "sr1", offsetof(CPUState
, sr
[1]) },
1918 { "sr2", offsetof(CPUState
, sr
[2]) },
1919 { "sr3", offsetof(CPUState
, sr
[3]) },
1920 { "sr4", offsetof(CPUState
, sr
[4]) },
1921 { "sr5", offsetof(CPUState
, sr
[5]) },
1922 { "sr6", offsetof(CPUState
, sr
[6]) },
1923 { "sr7", offsetof(CPUState
, sr
[7]) },
1924 { "sr8", offsetof(CPUState
, sr
[8]) },
1925 { "sr9", offsetof(CPUState
, sr
[9]) },
1926 { "sr10", offsetof(CPUState
, sr
[10]) },
1927 { "sr11", offsetof(CPUState
, sr
[11]) },
1928 { "sr12", offsetof(CPUState
, sr
[12]) },
1929 { "sr13", offsetof(CPUState
, sr
[13]) },
1930 { "sr14", offsetof(CPUState
, sr
[14]) },
1931 { "sr15", offsetof(CPUState
, sr
[15]) },
1932 /* Too lazy to put BATs and SPRs ... */
1933 #elif defined(TARGET_SPARC)
1934 { "g0", offsetof(CPUState
, gregs
[0]) },
1935 { "g1", offsetof(CPUState
, gregs
[1]) },
1936 { "g2", offsetof(CPUState
, gregs
[2]) },
1937 { "g3", offsetof(CPUState
, gregs
[3]) },
1938 { "g4", offsetof(CPUState
, gregs
[4]) },
1939 { "g5", offsetof(CPUState
, gregs
[5]) },
1940 { "g6", offsetof(CPUState
, gregs
[6]) },
1941 { "g7", offsetof(CPUState
, gregs
[7]) },
1942 { "o0", 0, monitor_get_reg
},
1943 { "o1", 1, monitor_get_reg
},
1944 { "o2", 2, monitor_get_reg
},
1945 { "o3", 3, monitor_get_reg
},
1946 { "o4", 4, monitor_get_reg
},
1947 { "o5", 5, monitor_get_reg
},
1948 { "o6", 6, monitor_get_reg
},
1949 { "o7", 7, monitor_get_reg
},
1950 { "l0", 8, monitor_get_reg
},
1951 { "l1", 9, monitor_get_reg
},
1952 { "l2", 10, monitor_get_reg
},
1953 { "l3", 11, monitor_get_reg
},
1954 { "l4", 12, monitor_get_reg
},
1955 { "l5", 13, monitor_get_reg
},
1956 { "l6", 14, monitor_get_reg
},
1957 { "l7", 15, monitor_get_reg
},
1958 { "i0", 16, monitor_get_reg
},
1959 { "i1", 17, monitor_get_reg
},
1960 { "i2", 18, monitor_get_reg
},
1961 { "i3", 19, monitor_get_reg
},
1962 { "i4", 20, monitor_get_reg
},
1963 { "i5", 21, monitor_get_reg
},
1964 { "i6", 22, monitor_get_reg
},
1965 { "i7", 23, monitor_get_reg
},
1966 { "pc", offsetof(CPUState
, pc
) },
1967 { "npc", offsetof(CPUState
, npc
) },
1968 { "y", offsetof(CPUState
, y
) },
1969 #ifndef TARGET_SPARC64
1970 { "psr", 0, &monitor_get_psr
, },
1971 { "wim", offsetof(CPUState
, wim
) },
1973 { "tbr", offsetof(CPUState
, tbr
) },
1974 { "fsr", offsetof(CPUState
, fsr
) },
1975 { "f0", offsetof(CPUState
, fpr
[0]) },
1976 { "f1", offsetof(CPUState
, fpr
[1]) },
1977 { "f2", offsetof(CPUState
, fpr
[2]) },
1978 { "f3", offsetof(CPUState
, fpr
[3]) },
1979 { "f4", offsetof(CPUState
, fpr
[4]) },
1980 { "f5", offsetof(CPUState
, fpr
[5]) },
1981 { "f6", offsetof(CPUState
, fpr
[6]) },
1982 { "f7", offsetof(CPUState
, fpr
[7]) },
1983 { "f8", offsetof(CPUState
, fpr
[8]) },
1984 { "f9", offsetof(CPUState
, fpr
[9]) },
1985 { "f10", offsetof(CPUState
, fpr
[10]) },
1986 { "f11", offsetof(CPUState
, fpr
[11]) },
1987 { "f12", offsetof(CPUState
, fpr
[12]) },
1988 { "f13", offsetof(CPUState
, fpr
[13]) },
1989 { "f14", offsetof(CPUState
, fpr
[14]) },
1990 { "f15", offsetof(CPUState
, fpr
[15]) },
1991 { "f16", offsetof(CPUState
, fpr
[16]) },
1992 { "f17", offsetof(CPUState
, fpr
[17]) },
1993 { "f18", offsetof(CPUState
, fpr
[18]) },
1994 { "f19", offsetof(CPUState
, fpr
[19]) },
1995 { "f20", offsetof(CPUState
, fpr
[20]) },
1996 { "f21", offsetof(CPUState
, fpr
[21]) },
1997 { "f22", offsetof(CPUState
, fpr
[22]) },
1998 { "f23", offsetof(CPUState
, fpr
[23]) },
1999 { "f24", offsetof(CPUState
, fpr
[24]) },
2000 { "f25", offsetof(CPUState
, fpr
[25]) },
2001 { "f26", offsetof(CPUState
, fpr
[26]) },
2002 { "f27", offsetof(CPUState
, fpr
[27]) },
2003 { "f28", offsetof(CPUState
, fpr
[28]) },
2004 { "f29", offsetof(CPUState
, fpr
[29]) },
2005 { "f30", offsetof(CPUState
, fpr
[30]) },
2006 { "f31", offsetof(CPUState
, fpr
[31]) },
2007 #ifdef TARGET_SPARC64
2008 { "f32", offsetof(CPUState
, fpr
[32]) },
2009 { "f34", offsetof(CPUState
, fpr
[34]) },
2010 { "f36", offsetof(CPUState
, fpr
[36]) },
2011 { "f38", offsetof(CPUState
, fpr
[38]) },
2012 { "f40", offsetof(CPUState
, fpr
[40]) },
2013 { "f42", offsetof(CPUState
, fpr
[42]) },
2014 { "f44", offsetof(CPUState
, fpr
[44]) },
2015 { "f46", offsetof(CPUState
, fpr
[46]) },
2016 { "f48", offsetof(CPUState
, fpr
[48]) },
2017 { "f50", offsetof(CPUState
, fpr
[50]) },
2018 { "f52", offsetof(CPUState
, fpr
[52]) },
2019 { "f54", offsetof(CPUState
, fpr
[54]) },
2020 { "f56", offsetof(CPUState
, fpr
[56]) },
2021 { "f58", offsetof(CPUState
, fpr
[58]) },
2022 { "f60", offsetof(CPUState
, fpr
[60]) },
2023 { "f62", offsetof(CPUState
, fpr
[62]) },
2024 { "asi", offsetof(CPUState
, asi
) },
2025 { "pstate", offsetof(CPUState
, pstate
) },
2026 { "cansave", offsetof(CPUState
, cansave
) },
2027 { "canrestore", offsetof(CPUState
, canrestore
) },
2028 { "otherwin", offsetof(CPUState
, otherwin
) },
2029 { "wstate", offsetof(CPUState
, wstate
) },
2030 { "cleanwin", offsetof(CPUState
, cleanwin
) },
2031 { "fprs", offsetof(CPUState
, fprs
) },
2037 static void expr_error(const char *msg
)
2039 term_printf("%s\n", msg
);
2040 longjmp(expr_env
, 1);
2043 /* return 0 if OK, -1 if not found, -2 if no CPU defined */
2044 static int get_monitor_def(target_long
*pval
, const char *name
)
2046 const MonitorDef
*md
;
2049 for(md
= monitor_defs
; md
->name
!= NULL
; md
++) {
2050 if (compare_cmd(name
, md
->name
)) {
2051 if (md
->get_value
) {
2052 *pval
= md
->get_value(md
, md
->offset
);
2054 CPUState
*env
= mon_get_cpu();
2057 ptr
= (uint8_t *)env
+ md
->offset
;
2060 *pval
= *(int32_t *)ptr
;
2063 *pval
= *(target_long
*)ptr
;
2076 static void next(void)
2080 while (qemu_isspace(*pch
))
2085 static int64_t expr_sum(void);
2087 static int64_t expr_unary(void)
2110 expr_error("')' expected");
2117 expr_error("character constant expected");
2121 expr_error("missing terminating \' character");
2131 while ((*pch
>= 'a' && *pch
<= 'z') ||
2132 (*pch
>= 'A' && *pch
<= 'Z') ||
2133 (*pch
>= '0' && *pch
<= '9') ||
2134 *pch
== '_' || *pch
== '.') {
2135 if ((q
- buf
) < sizeof(buf
) - 1)
2139 while (qemu_isspace(*pch
))
2142 ret
= get_monitor_def(®
, buf
);
2144 expr_error("unknown register");
2146 expr_error("no cpu defined");
2151 expr_error("unexpected end of expression");
2155 #if TARGET_PHYS_ADDR_BITS > 32
2156 n
= strtoull(pch
, &p
, 0);
2158 n
= strtoul(pch
, &p
, 0);
2161 expr_error("invalid char in expression");
2164 while (qemu_isspace(*pch
))
2172 static int64_t expr_prod(void)
2180 if (op
!= '*' && op
!= '/' && op
!= '%')
2183 val2
= expr_unary();
2192 expr_error("division by zero");
2203 static int64_t expr_logic(void)
2211 if (op
!= '&' && op
!= '|' && op
!= '^')
2231 static int64_t expr_sum(void)
2239 if (op
!= '+' && op
!= '-')
2242 val2
= expr_logic();
2251 static int get_expr(int64_t *pval
, const char **pp
)
2254 if (setjmp(expr_env
)) {
2258 while (qemu_isspace(*pch
))
2265 static int get_str(char *buf
, int buf_size
, const char **pp
)
2273 while (qemu_isspace(*p
))
2283 while (*p
!= '\0' && *p
!= '\"') {
2299 qemu_printf("unsupported escape code: '\\%c'\n", c
);
2302 if ((q
- buf
) < buf_size
- 1) {
2306 if ((q
- buf
) < buf_size
- 1) {
2313 qemu_printf("unterminated string\n");
2318 while (*p
!= '\0' && !qemu_isspace(*p
)) {
2319 if ((q
- buf
) < buf_size
- 1) {
2330 static int default_fmt_format
= 'x';
2331 static int default_fmt_size
= 4;
2335 static void monitor_handle_command(const char *cmdline
)
2337 const char *p
, *pstart
, *typestr
;
2339 int c
, nb_args
, len
, i
, has_arg
;
2340 const term_cmd_t
*cmd
;
2343 void *str_allocated
[MAX_ARGS
];
2344 void *args
[MAX_ARGS
];
2345 void (*handler_0
)(void);
2346 void (*handler_1
)(void *arg0
);
2347 void (*handler_2
)(void *arg0
, void *arg1
);
2348 void (*handler_3
)(void *arg0
, void *arg1
, void *arg2
);
2349 void (*handler_4
)(void *arg0
, void *arg1
, void *arg2
, void *arg3
);
2350 void (*handler_5
)(void *arg0
, void *arg1
, void *arg2
, void *arg3
,
2352 void (*handler_6
)(void *arg0
, void *arg1
, void *arg2
, void *arg3
,
2353 void *arg4
, void *arg5
);
2354 void (*handler_7
)(void *arg0
, void *arg1
, void *arg2
, void *arg3
,
2355 void *arg4
, void *arg5
, void *arg6
);
2358 term_printf("command='%s'\n", cmdline
);
2361 /* extract the command name */
2364 while (qemu_isspace(*p
))
2369 while (*p
!= '\0' && *p
!= '/' && !qemu_isspace(*p
))
2372 if (len
> sizeof(cmdname
) - 1)
2373 len
= sizeof(cmdname
) - 1;
2374 memcpy(cmdname
, pstart
, len
);
2375 cmdname
[len
] = '\0';
2377 /* find the command */
2378 for(cmd
= term_cmds
; cmd
->name
!= NULL
; cmd
++) {
2379 if (compare_cmd(cmdname
, cmd
->name
))
2382 term_printf("unknown command: '%s'\n", cmdname
);
2386 for(i
= 0; i
< MAX_ARGS
; i
++)
2387 str_allocated
[i
] = NULL
;
2389 /* parse the parameters */
2390 typestr
= cmd
->args_type
;
2405 while (qemu_isspace(*p
))
2407 if (*typestr
== '?') {
2410 /* no optional string: NULL argument */
2415 ret
= get_str(buf
, sizeof(buf
), &p
);
2419 term_printf("%s: filename expected\n", cmdname
);
2422 term_printf("%s: block device name expected\n", cmdname
);
2425 term_printf("%s: string expected\n", cmdname
);
2430 str
= qemu_malloc(strlen(buf
) + 1);
2431 pstrcpy(str
, sizeof(buf
), buf
);
2432 str_allocated
[nb_args
] = str
;
2434 if (nb_args
>= MAX_ARGS
) {
2436 term_printf("%s: too many arguments\n", cmdname
);
2439 args
[nb_args
++] = str
;
2444 int count
, format
, size
;
2446 while (qemu_isspace(*p
))
2452 if (qemu_isdigit(*p
)) {
2454 while (qemu_isdigit(*p
)) {
2455 count
= count
* 10 + (*p
- '0');
2493 if (*p
!= '\0' && !qemu_isspace(*p
)) {
2494 term_printf("invalid char in format: '%c'\n", *p
);
2498 format
= default_fmt_format
;
2499 if (format
!= 'i') {
2500 /* for 'i', not specifying a size gives -1 as size */
2502 size
= default_fmt_size
;
2503 default_fmt_size
= size
;
2505 default_fmt_format
= format
;
2508 format
= default_fmt_format
;
2509 if (format
!= 'i') {
2510 size
= default_fmt_size
;
2515 if (nb_args
+ 3 > MAX_ARGS
)
2517 args
[nb_args
++] = (void*)(long)count
;
2518 args
[nb_args
++] = (void*)(long)format
;
2519 args
[nb_args
++] = (void*)(long)size
;
2527 while (qemu_isspace(*p
))
2529 if (*typestr
== '?' || *typestr
== '.') {
2530 if (*typestr
== '?') {
2538 while (qemu_isspace(*p
))
2546 if (nb_args
>= MAX_ARGS
)
2548 args
[nb_args
++] = (void *)(long)has_arg
;
2550 if (nb_args
>= MAX_ARGS
)
2556 if (get_expr(&val
, &p
))
2560 if (nb_args
>= MAX_ARGS
)
2562 args
[nb_args
++] = (void *)(long)val
;
2564 if ((nb_args
+ 1) >= MAX_ARGS
)
2566 #if TARGET_PHYS_ADDR_BITS > 32
2567 args
[nb_args
++] = (void *)(long)((val
>> 32) & 0xffffffff);
2569 args
[nb_args
++] = (void *)0;
2571 args
[nb_args
++] = (void *)(long)(val
& 0xffffffff);
2583 while (qemu_isspace(*p
))
2589 term_printf("%s: unsupported option -%c\n",
2596 if (nb_args
>= MAX_ARGS
)
2598 args
[nb_args
++] = (void *)(long)has_option
;
2603 term_printf("%s: unknown type '%c'\n", cmdname
, c
);
2607 /* check that all arguments were parsed */
2608 while (qemu_isspace(*p
))
2611 term_printf("%s: extraneous characters at the end of line\n",
2618 handler_0
= cmd
->handler
;
2622 handler_1
= cmd
->handler
;
2626 handler_2
= cmd
->handler
;
2627 handler_2(args
[0], args
[1]);
2630 handler_3
= cmd
->handler
;
2631 handler_3(args
[0], args
[1], args
[2]);
2634 handler_4
= cmd
->handler
;
2635 handler_4(args
[0], args
[1], args
[2], args
[3]);
2638 handler_5
= cmd
->handler
;
2639 handler_5(args
[0], args
[1], args
[2], args
[3], args
[4]);
2642 handler_6
= cmd
->handler
;
2643 handler_6(args
[0], args
[1], args
[2], args
[3], args
[4], args
[5]);
2646 handler_7
= cmd
->handler
;
2647 handler_7(args
[0], args
[1], args
[2], args
[3], args
[4], args
[5], args
[6]);
2650 term_printf("unsupported number of arguments: %d\n", nb_args
);
2654 for(i
= 0; i
< MAX_ARGS
; i
++)
2655 qemu_free(str_allocated
[i
]);
2659 static void cmd_completion(const char *name
, const char *list
)
2661 const char *p
, *pstart
;
2670 p
= pstart
+ strlen(pstart
);
2672 if (len
> sizeof(cmd
) - 2)
2673 len
= sizeof(cmd
) - 2;
2674 memcpy(cmd
, pstart
, len
);
2676 if (name
[0] == '\0' || !strncmp(name
, cmd
, strlen(name
))) {
2677 add_completion(cmd
);
2685 static void file_completion(const char *input
)
2690 char file
[1024], file_prefix
[1024];
2694 p
= strrchr(input
, '/');
2697 pstrcpy(file_prefix
, sizeof(file_prefix
), input
);
2698 pstrcpy(path
, sizeof(path
), ".");
2700 input_path_len
= p
- input
+ 1;
2701 memcpy(path
, input
, input_path_len
);
2702 if (input_path_len
> sizeof(path
) - 1)
2703 input_path_len
= sizeof(path
) - 1;
2704 path
[input_path_len
] = '\0';
2705 pstrcpy(file_prefix
, sizeof(file_prefix
), p
+ 1);
2707 #ifdef DEBUG_COMPLETION
2708 term_printf("input='%s' path='%s' prefix='%s'\n", input
, path
, file_prefix
);
2710 ffs
= opendir(path
);
2718 if (strstart(d
->d_name
, file_prefix
, NULL
)) {
2719 memcpy(file
, input
, input_path_len
);
2720 if (input_path_len
< sizeof(file
))
2721 pstrcpy(file
+ input_path_len
, sizeof(file
) - input_path_len
,
2723 /* stat the file to find out if it's a directory.
2724 * In that case add a slash to speed up typing long paths
2727 if(S_ISDIR(sb
.st_mode
))
2728 pstrcat(file
, sizeof(file
), "/");
2729 add_completion(file
);
2735 static void block_completion_it(void *opaque
, BlockDriverState
*bs
)
2737 const char *name
= bdrv_get_device_name(bs
);
2738 const char *input
= opaque
;
2740 if (input
[0] == '\0' ||
2741 !strncmp(name
, (char *)input
, strlen(input
))) {
2742 add_completion(name
);
2746 /* NOTE: this parser is an approximate form of the real command parser */
2747 static void parse_cmdline(const char *cmdline
,
2748 int *pnb_args
, char **args
)
2757 while (qemu_isspace(*p
))
2761 if (nb_args
>= MAX_ARGS
)
2763 ret
= get_str(buf
, sizeof(buf
), &p
);
2764 args
[nb_args
] = qemu_strdup(buf
);
2769 *pnb_args
= nb_args
;
2772 void readline_find_completion(const char *cmdline
)
2774 const char *cmdname
;
2775 char *args
[MAX_ARGS
];
2776 int nb_args
, i
, len
;
2777 const char *ptype
, *str
;
2778 const term_cmd_t
*cmd
;
2781 parse_cmdline(cmdline
, &nb_args
, args
);
2782 #ifdef DEBUG_COMPLETION
2783 for(i
= 0; i
< nb_args
; i
++) {
2784 term_printf("arg%d = '%s'\n", i
, (char *)args
[i
]);
2788 /* if the line ends with a space, it means we want to complete the
2790 len
= strlen(cmdline
);
2791 if (len
> 0 && qemu_isspace(cmdline
[len
- 1])) {
2792 if (nb_args
>= MAX_ARGS
)
2794 args
[nb_args
++] = qemu_strdup("");
2797 /* command completion */
2802 completion_index
= strlen(cmdname
);
2803 for(cmd
= term_cmds
; cmd
->name
!= NULL
; cmd
++) {
2804 cmd_completion(cmdname
, cmd
->name
);
2807 /* find the command */
2808 for(cmd
= term_cmds
; cmd
->name
!= NULL
; cmd
++) {
2809 if (compare_cmd(args
[0], cmd
->name
))
2814 ptype
= cmd
->args_type
;
2815 for(i
= 0; i
< nb_args
- 2; i
++) {
2816 if (*ptype
!= '\0') {
2818 while (*ptype
== '?')
2822 str
= args
[nb_args
- 1];
2825 /* file completion */
2826 completion_index
= strlen(str
);
2827 file_completion(str
);
2830 /* block device name completion */
2831 completion_index
= strlen(str
);
2832 bdrv_iterate(block_completion_it
, (void *)str
);
2835 /* XXX: more generic ? */
2836 if (!strcmp(cmd
->name
, "info")) {
2837 completion_index
= strlen(str
);
2838 for(cmd
= info_cmds
; cmd
->name
!= NULL
; cmd
++) {
2839 cmd_completion(str
, cmd
->name
);
2841 } else if (!strcmp(cmd
->name
, "sendkey")) {
2842 completion_index
= strlen(str
);
2843 for(key
= key_defs
; key
->name
!= NULL
; key
++) {
2844 cmd_completion(str
, key
->name
);
2852 for(i
= 0; i
< nb_args
; i
++)
2856 static int term_can_read(void *opaque
)
2861 static void term_read(void *opaque
, const uint8_t *buf
, int size
)
2864 for(i
= 0; i
< size
; i
++)
2865 readline_handle_byte(buf
[i
]);
2868 static int monitor_suspended
;
2870 static void monitor_handle_command1(void *opaque
, const char *cmdline
)
2872 monitor_handle_command(cmdline
);
2873 if (!monitor_suspended
)
2874 monitor_start_input();
2876 monitor_suspended
= 2;
2879 void monitor_suspend(void)
2881 monitor_suspended
= 1;
2884 void monitor_resume(void)
2886 if (monitor_suspended
== 2)
2887 monitor_start_input();
2888 monitor_suspended
= 0;
2891 static void monitor_start_input(void)
2893 readline_start("(qemu) ", 0, monitor_handle_command1
, NULL
);
2896 static void term_event(void *opaque
, int event
)
2898 if (event
!= CHR_EVENT_RESET
)
2902 term_printf("QEMU %s monitor - type 'help' for more information\n",
2904 monitor_start_input();
2907 static int is_first_init
= 1;
2909 void monitor_init(CharDriverState
*hd
, int show_banner
)
2913 if (is_first_init
) {
2914 key_timer
= qemu_new_timer(vm_clock
, release_keys
, NULL
);
2917 for (i
= 0; i
< MAX_MON
; i
++) {
2918 monitor_hd
[i
] = NULL
;
2922 for (i
= 0; i
< MAX_MON
; i
++) {
2923 if (monitor_hd
[i
] == NULL
) {
2929 hide_banner
= !show_banner
;
2931 qemu_chr_add_handlers(hd
, term_can_read
, term_read
, term_event
, NULL
);
2933 readline_start("", 0, monitor_handle_command1
, NULL
);
2936 /* XXX: use threads ? */
2937 /* modal monitor readline */
2938 static int monitor_readline_started
;
2939 static char *monitor_readline_buf
;
2940 static int monitor_readline_buf_size
;
2942 static void monitor_readline_cb(void *opaque
, const char *input
)
2944 pstrcpy(monitor_readline_buf
, monitor_readline_buf_size
, input
);
2945 monitor_readline_started
= 0;
2948 static void monitor_readline(const char *prompt
, int is_password
,
2949 char *buf
, int buf_size
)
2952 int old_focus
[MAX_MON
];
2955 for (i
= 0; i
< MAX_MON
; i
++) {
2957 if (monitor_hd
[i
]) {
2958 old_focus
[i
] = monitor_hd
[i
]->focus
;
2959 monitor_hd
[i
]->focus
= 0;
2960 qemu_chr_send_event(monitor_hd
[i
], CHR_EVENT_FOCUS
);
2965 readline_start(prompt
, is_password
, monitor_readline_cb
, NULL
);
2966 monitor_readline_buf
= buf
;
2967 monitor_readline_buf_size
= buf_size
;
2968 monitor_readline_started
= 1;
2969 while (monitor_readline_started
) {
2972 /* restore original focus */
2974 for (i
= 0; i
< MAX_MON
; i
++)
2976 monitor_hd
[i
]->focus
= old_focus
[i
];
2980 int monitor_read_bdrv_key(BlockDriverState
*bs
)
2985 if (!bdrv_is_encrypted(bs
))
2988 term_printf("%s (%s) is encrypted.\n", bdrv_get_device_name(bs
),
2989 bdrv_get_encrypted_filename(bs
));
2990 for(i
= 0; i
< 3; i
++) {
2991 monitor_readline("Password: ", 1, password
, sizeof(password
));
2992 if (bdrv_set_key(bs
, password
) == 0)
2994 term_printf("invalid password\n");