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"
47 //#define DEBUG_COMPLETION
53 * 'B' block device name
54 * 's' string (accept optional quote)
56 * 'l' target long (32 or 64 bit)
57 * '/' optional gdb-like print format (like "/10x")
59 * '?' optional type (for 'F', 's' and 'i')
63 typedef struct term_cmd_t
{
65 const char *args_type
;
72 static CharDriverState
*monitor_hd
[MAX_MON
];
73 static int hide_banner
;
75 static const term_cmd_t term_cmds
[];
76 static const term_cmd_t info_cmds
[];
78 static uint8_t term_outbuf
[1024];
79 static int term_outbuf_index
;
81 static void monitor_start_input(void);
82 static void monitor_readline(const char *prompt
, int is_password
,
83 char *buf
, int buf_size
);
85 static CPUState
*mon_cpu
= NULL
;
90 if (term_outbuf_index
> 0) {
91 for (i
= 0; i
< MAX_MON
; i
++)
92 if (monitor_hd
[i
] && monitor_hd
[i
]->focus
== 0)
93 qemu_chr_write(monitor_hd
[i
], term_outbuf
, term_outbuf_index
);
94 term_outbuf_index
= 0;
98 /* flush at every end of line or if the buffer is full */
99 void term_puts(const char *str
)
107 term_outbuf
[term_outbuf_index
++] = '\r';
108 term_outbuf
[term_outbuf_index
++] = c
;
109 if (term_outbuf_index
>= (sizeof(term_outbuf
) - 1) ||
115 void term_vprintf(const char *fmt
, va_list ap
)
118 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
122 void term_printf(const char *fmt
, ...)
126 term_vprintf(fmt
, ap
);
130 void term_print_filename(const char *filename
)
134 for (i
= 0; filename
[i
]; i
++) {
135 switch (filename
[i
]) {
139 term_printf("\\%c", filename
[i
]);
151 term_printf("%c", filename
[i
]);
157 static int monitor_fprintf(FILE *stream
, const char *fmt
, ...)
161 term_vprintf(fmt
, ap
);
166 static int compare_cmd(const char *name
, const char *list
)
168 const char *p
, *pstart
;
176 p
= pstart
+ strlen(pstart
);
177 if ((p
- pstart
) == len
&& !memcmp(pstart
, name
, len
))
186 static void help_cmd1(const term_cmd_t
*cmds
, const char *prefix
, const char *name
)
188 const term_cmd_t
*cmd
;
190 for(cmd
= cmds
; cmd
->name
!= NULL
; cmd
++) {
191 if (!name
|| !strcmp(name
, cmd
->name
))
192 term_printf("%s%s %s -- %s\n", prefix
, cmd
->name
, cmd
->params
, cmd
->help
);
196 static void help_cmd(const char *name
)
198 if (name
&& !strcmp(name
, "info")) {
199 help_cmd1(info_cmds
, "info ", NULL
);
201 help_cmd1(term_cmds
, "", name
);
202 if (name
&& !strcmp(name
, "log")) {
203 const CPULogItem
*item
;
204 term_printf("Log items (comma separated):\n");
205 term_printf("%-10s %s\n", "none", "remove all logs");
206 for(item
= cpu_log_items
; item
->mask
!= 0; item
++) {
207 term_printf("%-10s %s\n", item
->name
, item
->help
);
213 static void do_help(const char *name
)
218 static void do_commit(const char *device
)
222 all_devices
= !strcmp(device
, "all");
223 for (i
= 0; i
< nb_drives
; i
++) {
225 !strcmp(bdrv_get_device_name(drives_table
[i
].bdrv
), device
))
226 bdrv_commit(drives_table
[i
].bdrv
);
230 static void do_info(const char *item
)
232 const term_cmd_t
*cmd
;
233 void (*handler
)(void);
237 for(cmd
= info_cmds
; cmd
->name
!= NULL
; cmd
++) {
238 if (compare_cmd(item
, cmd
->name
))
245 handler
= cmd
->handler
;
249 static void do_info_version(void)
251 term_printf("%s\n", QEMU_VERSION
);
254 static void do_info_name(void)
257 term_printf("%s\n", qemu_name
);
260 #if defined(TARGET_I386)
261 static void do_info_hpet(void)
263 term_printf("HPET is %s by QEMU\n", (no_hpet
) ? "disabled" : "enabled");
267 static void do_info_uuid(void)
269 term_printf(UUID_FMT
"\n", qemu_uuid
[0], qemu_uuid
[1], qemu_uuid
[2],
270 qemu_uuid
[3], qemu_uuid
[4], qemu_uuid
[5], qemu_uuid
[6],
271 qemu_uuid
[7], qemu_uuid
[8], qemu_uuid
[9], qemu_uuid
[10],
272 qemu_uuid
[11], qemu_uuid
[12], qemu_uuid
[13], qemu_uuid
[14],
276 static void do_info_block(void)
281 static void do_info_blockstats(void)
286 /* get the current CPU defined by the user */
287 static int mon_set_cpu(int cpu_index
)
291 for(env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
292 if (env
->cpu_index
== cpu_index
) {
300 static CPUState
*mon_get_cpu(void)
306 kvm_save_registers(mon_cpu
);
311 static void do_info_registers(void)
318 cpu_dump_state(env
, NULL
, monitor_fprintf
,
321 cpu_dump_state(env
, NULL
, monitor_fprintf
,
326 static void do_info_cpus(void)
330 /* just to set the default cpu if not already done */
333 for(env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
334 kvm_save_registers(env
);
335 term_printf("%c CPU #%d:",
336 (env
== mon_cpu
) ? '*' : ' ',
338 #if defined(TARGET_I386)
339 term_printf(" pc=0x" TARGET_FMT_lx
, env
->eip
+ env
->segs
[R_CS
].base
);
340 #elif defined(TARGET_PPC)
341 term_printf(" nip=0x" TARGET_FMT_lx
, env
->nip
);
342 #elif defined(TARGET_SPARC)
343 term_printf(" pc=0x" TARGET_FMT_lx
" npc=0x" TARGET_FMT_lx
, env
->pc
, env
->npc
);
344 #elif defined(TARGET_MIPS)
345 term_printf(" PC=0x" TARGET_FMT_lx
, env
->active_tc
.PC
);
348 term_printf(" (halted)");
349 term_printf(" thread_id=%d", env
->thread_id
);
354 static void do_cpu_set(int index
)
356 if (mon_set_cpu(index
) < 0)
357 term_printf("Invalid CPU index\n");
360 static void do_cpu_set_nr(int value
, const char *status
)
364 if (!strcmp(status
, "online"))
366 else if (!strcmp(status
, "offline"))
369 term_printf("invalid status: %s\n", status
);
372 #if defined(TARGET_I386) || defined(TARGET_X86_64)
373 qemu_system_cpu_hot_add(value
, state
);
377 static void do_info_jit(void)
379 dump_exec_info(NULL
, monitor_fprintf
);
382 static void do_info_history (void)
389 str
= readline_get_history(i
);
392 term_printf("%d: '%s'\n", i
, str
);
397 #if defined(TARGET_PPC)
398 /* XXX: not implemented in other targets */
399 static void do_info_cpu_stats (void)
404 cpu_dump_statistics(env
, NULL
, &monitor_fprintf
, 0);
408 static void do_quit(void)
413 static int eject_device(BlockDriverState
*bs
, int force
)
415 if (bdrv_is_inserted(bs
)) {
417 if (!bdrv_is_removable(bs
)) {
418 term_printf("device is not removable\n");
421 if (bdrv_is_locked(bs
)) {
422 term_printf("device is locked\n");
431 static void do_eject(int force
, const char *filename
)
433 BlockDriverState
*bs
;
435 bs
= bdrv_find(filename
);
437 term_printf("device not found\n");
440 eject_device(bs
, force
);
443 static void do_change_block(const char *device
, const char *filename
, const char *fmt
)
445 BlockDriverState
*bs
;
446 BlockDriver
*drv
= NULL
;
448 bs
= bdrv_find(device
);
450 term_printf("device not found\n");
454 drv
= bdrv_find_format(fmt
);
456 term_printf("invalid format %s\n", fmt
);
460 if (eject_device(bs
, 0) < 0)
462 bdrv_open2(bs
, filename
, 0, drv
);
463 monitor_read_bdrv_key(bs
);
466 static void do_change_vnc(const char *target
, const char *arg
)
468 if (strcmp(target
, "passwd") == 0 ||
469 strcmp(target
, "password") == 0) {
472 strncpy(password
, arg
, sizeof(password
));
473 password
[sizeof(password
) - 1] = '\0';
475 monitor_readline("Password: ", 1, password
, sizeof(password
));
476 if (vnc_display_password(NULL
, password
) < 0)
477 term_printf("could not set VNC server password\n");
479 if (vnc_display_open(NULL
, target
) < 0)
480 term_printf("could not start VNC server on %s\n", target
);
484 static void do_change(const char *device
, const char *target
, const char *arg
)
486 if (strcmp(device
, "vnc") == 0) {
487 do_change_vnc(target
, arg
);
489 do_change_block(device
, target
, arg
);
493 static void do_screen_dump(const char *filename
)
495 vga_hw_screen_dump(filename
);
498 static void do_logfile(const char *filename
)
500 cpu_set_log_filename(filename
);
503 static void do_log(const char *items
)
507 if (!strcmp(items
, "none")) {
510 mask
= cpu_str_to_log_mask(items
);
519 static void do_stop(void)
521 vm_stop(EXCP_INTERRUPT
);
524 static void encrypted_bdrv_it(void *opaque
, BlockDriverState
*bs
)
528 if (bdrv_key_required(bs
))
529 *err
= monitor_read_bdrv_key(bs
);
534 static void do_cont(void)
538 bdrv_iterate(encrypted_bdrv_it
, &err
);
539 /* only resume the vm if all keys are set and valid */
544 #ifdef CONFIG_GDBSTUB
545 static void do_gdbserver(const char *port
)
548 port
= DEFAULT_GDBSTUB_PORT
;
549 if (gdbserver_start(port
) < 0) {
550 qemu_printf("Could not open gdbserver socket on port '%s'\n", port
);
552 qemu_printf("Waiting gdb connection on port '%s'\n", port
);
557 static void term_printc(int c
)
574 if (c
>= 32 && c
<= 126) {
575 term_printf("%c", c
);
577 term_printf("\\x%02x", c
);
584 static void memory_dump(int count
, int format
, int wsize
,
585 target_phys_addr_t addr
, int is_physical
)
588 int nb_per_line
, l
, line_size
, i
, max_digits
, len
;
596 if (!env
&& !is_physical
)
601 } else if (wsize
== 4) {
604 /* as default we use the current CS size */
608 if ((env
->efer
& MSR_EFER_LMA
) &&
609 (env
->segs
[R_CS
].flags
& DESC_L_MASK
))
613 if (!(env
->segs
[R_CS
].flags
& DESC_B_MASK
))
618 monitor_disas(env
, addr
, count
, is_physical
, flags
);
627 nb_per_line
= line_size
/ wsize
;
632 max_digits
= (wsize
* 8 + 2) / 3;
636 max_digits
= (wsize
* 8) / 4;
640 max_digits
= (wsize
* 8 * 10 + 32) / 33;
649 term_printf(TARGET_FMT_plx
":", addr
);
651 term_printf(TARGET_FMT_lx
":", (target_ulong
)addr
);
656 cpu_physical_memory_rw(addr
, buf
, l
, 0);
661 if (cpu_memory_rw_debug(env
, addr
, buf
, l
, 0) < 0) {
662 term_printf(" Cannot access memory\n");
671 v
= ldub_raw(buf
+ i
);
674 v
= lduw_raw(buf
+ i
);
677 v
= (uint32_t)ldl_raw(buf
+ i
);
680 v
= ldq_raw(buf
+ i
);
686 term_printf("%#*" PRIo64
, max_digits
, v
);
689 term_printf("0x%0*" PRIx64
, max_digits
, v
);
692 term_printf("%*" PRIu64
, max_digits
, v
);
695 term_printf("%*" PRId64
, max_digits
, v
);
709 #if TARGET_LONG_BITS == 64
710 #define GET_TLONG(h, l) (((uint64_t)(h) << 32) | (l))
712 #define GET_TLONG(h, l) (l)
715 static void do_memory_dump(int count
, int format
, int size
,
716 uint32_t addrh
, uint32_t addrl
)
718 target_long addr
= GET_TLONG(addrh
, addrl
);
719 memory_dump(count
, format
, size
, addr
, 0);
722 #if TARGET_PHYS_ADDR_BITS > 32
723 #define GET_TPHYSADDR(h, l) (((uint64_t)(h) << 32) | (l))
725 #define GET_TPHYSADDR(h, l) (l)
728 static void do_physical_memory_dump(int count
, int format
, int size
,
729 uint32_t addrh
, uint32_t addrl
)
732 target_phys_addr_t addr
= GET_TPHYSADDR(addrh
, addrl
);
733 memory_dump(count
, format
, size
, addr
, 1);
736 static void do_print(int count
, int format
, int size
, unsigned int valh
, unsigned int vall
)
738 target_phys_addr_t val
= GET_TPHYSADDR(valh
, vall
);
739 #if TARGET_PHYS_ADDR_BITS == 32
742 term_printf("%#o", val
);
745 term_printf("%#x", val
);
748 term_printf("%u", val
);
752 term_printf("%d", val
);
761 term_printf("%#" PRIo64
, val
);
764 term_printf("%#" PRIx64
, val
);
767 term_printf("%" PRIu64
, val
);
771 term_printf("%" PRId64
, val
);
781 static void do_memory_save(unsigned int valh
, unsigned int vall
,
782 uint32_t size
, const char *filename
)
785 target_long addr
= GET_TLONG(valh
, vall
);
794 f
= fopen(filename
, "wb");
796 term_printf("could not open '%s'\n", filename
);
803 cpu_memory_rw_debug(env
, addr
, buf
, l
, 0);
804 fwrite(buf
, 1, l
, f
);
811 static void do_physical_memory_save(unsigned int valh
, unsigned int vall
,
812 uint32_t size
, const char *filename
)
817 target_phys_addr_t addr
= GET_TPHYSADDR(valh
, vall
);
819 f
= fopen(filename
, "wb");
821 term_printf("could not open '%s'\n", filename
);
828 cpu_physical_memory_rw(addr
, buf
, l
, 0);
829 fwrite(buf
, 1, l
, f
);
837 static void do_sum(uint32_t start
, uint32_t size
)
844 for(addr
= start
; addr
< (start
+ size
); addr
++) {
845 cpu_physical_memory_rw(addr
, buf
, 1, 0);
846 /* BSD sum algorithm ('sum' Unix command) */
847 sum
= (sum
>> 1) | (sum
<< 15);
850 term_printf("%05d\n", sum
);
858 static const KeyDef key_defs
[] = {
885 { 0x0e, "backspace" },
922 { 0x37, "asterisk" },
925 { 0x3a, "caps_lock" },
936 { 0x45, "num_lock" },
937 { 0x46, "scroll_lock" },
939 { 0xb5, "kp_divide" },
940 { 0x37, "kp_multiply" },
941 { 0x4a, "kp_subtract" },
943 { 0x9c, "kp_enter" },
944 { 0x53, "kp_decimal" },
977 #if defined(TARGET_SPARC) && !defined(TARGET_SPARC64)
997 static int get_keycode(const char *key
)
1003 for(p
= key_defs
; p
->name
!= NULL
; p
++) {
1004 if (!strcmp(key
, p
->name
))
1007 if (strstart(key
, "0x", NULL
)) {
1008 ret
= strtoul(key
, &endp
, 0);
1009 if (*endp
== '\0' && ret
>= 0x01 && ret
<= 0xff)
1015 #define MAX_KEYCODES 16
1016 static uint8_t keycodes
[MAX_KEYCODES
];
1017 static int nb_pending_keycodes
;
1018 static QEMUTimer
*key_timer
;
1020 static void release_keys(void *opaque
)
1024 while (nb_pending_keycodes
> 0) {
1025 nb_pending_keycodes
--;
1026 keycode
= keycodes
[nb_pending_keycodes
];
1028 kbd_put_keycode(0xe0);
1029 kbd_put_keycode(keycode
| 0x80);
1033 static void do_sendkey(const char *string
, int has_hold_time
, int hold_time
)
1035 char keyname_buf
[16];
1037 int keyname_len
, keycode
, i
;
1039 if (nb_pending_keycodes
> 0) {
1040 qemu_del_timer(key_timer
);
1047 separator
= strchr(string
, '-');
1048 keyname_len
= separator
? separator
- string
: strlen(string
);
1049 if (keyname_len
> 0) {
1050 pstrcpy(keyname_buf
, sizeof(keyname_buf
), string
);
1051 if (keyname_len
> sizeof(keyname_buf
) - 1) {
1052 term_printf("invalid key: '%s...'\n", keyname_buf
);
1055 if (i
== MAX_KEYCODES
) {
1056 term_printf("too many keys\n");
1059 keyname_buf
[keyname_len
] = 0;
1060 keycode
= get_keycode(keyname_buf
);
1062 term_printf("unknown key: '%s'\n", keyname_buf
);
1065 keycodes
[i
++] = keycode
;
1069 string
= separator
+ 1;
1071 nb_pending_keycodes
= i
;
1072 /* key down events */
1073 for (i
= 0; i
< nb_pending_keycodes
; i
++) {
1074 keycode
= keycodes
[i
];
1076 kbd_put_keycode(0xe0);
1077 kbd_put_keycode(keycode
& 0x7f);
1079 /* delayed key up events */
1080 qemu_mod_timer(key_timer
, qemu_get_clock(vm_clock
) +
1081 muldiv64(ticks_per_sec
, hold_time
, 1000));
1084 static int mouse_button_state
;
1086 static void do_mouse_move(const char *dx_str
, const char *dy_str
,
1090 dx
= strtol(dx_str
, NULL
, 0);
1091 dy
= strtol(dy_str
, NULL
, 0);
1094 dz
= strtol(dz_str
, NULL
, 0);
1095 kbd_mouse_event(dx
, dy
, dz
, mouse_button_state
);
1098 static void do_mouse_button(int button_state
)
1100 mouse_button_state
= button_state
;
1101 kbd_mouse_event(0, 0, 0, mouse_button_state
);
1104 static void do_ioport_read(int count
, int format
, int size
, int addr
, int has_index
, int index
)
1110 cpu_outb(NULL
, addr
& 0xffff, index
& 0xff);
1118 val
= cpu_inb(NULL
, addr
);
1122 val
= cpu_inw(NULL
, addr
);
1126 val
= cpu_inl(NULL
, addr
);
1130 term_printf("port%c[0x%04x] = %#0*x\n",
1131 suffix
, addr
, size
* 2, val
);
1134 /* boot_set handler */
1135 static QEMUBootSetHandler
*qemu_boot_set_handler
= NULL
;
1136 static void *boot_opaque
;
1138 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
1140 qemu_boot_set_handler
= func
;
1141 boot_opaque
= opaque
;
1144 static void do_boot_set(const char *bootdevice
)
1148 if (qemu_boot_set_handler
) {
1149 res
= qemu_boot_set_handler(boot_opaque
, bootdevice
);
1151 term_printf("boot device list now set to %s\n", bootdevice
);
1153 term_printf("setting boot device list failed with error %i\n", res
);
1155 term_printf("no function defined to set boot device list for this architecture\n");
1159 static void do_system_reset(void)
1161 qemu_system_reset_request();
1164 static void do_system_powerdown(void)
1166 qemu_system_powerdown_request();
1169 #if defined(TARGET_I386)
1170 static void print_pte(uint32_t addr
, uint32_t pte
, uint32_t mask
)
1172 term_printf("%08x: %08x %c%c%c%c%c%c%c%c\n",
1175 pte
& PG_GLOBAL_MASK
? 'G' : '-',
1176 pte
& PG_PSE_MASK
? 'P' : '-',
1177 pte
& PG_DIRTY_MASK
? 'D' : '-',
1178 pte
& PG_ACCESSED_MASK
? 'A' : '-',
1179 pte
& PG_PCD_MASK
? 'C' : '-',
1180 pte
& PG_PWT_MASK
? 'T' : '-',
1181 pte
& PG_USER_MASK
? 'U' : '-',
1182 pte
& PG_RW_MASK
? 'W' : '-');
1185 static void tlb_info(void)
1189 uint32_t pgd
, pde
, pte
;
1191 env
= mon_get_cpu();
1195 if (!(env
->cr
[0] & CR0_PG_MASK
)) {
1196 term_printf("PG disabled\n");
1199 pgd
= env
->cr
[3] & ~0xfff;
1200 for(l1
= 0; l1
< 1024; l1
++) {
1201 cpu_physical_memory_read(pgd
+ l1
* 4, (uint8_t *)&pde
, 4);
1202 pde
= le32_to_cpu(pde
);
1203 if (pde
& PG_PRESENT_MASK
) {
1204 if ((pde
& PG_PSE_MASK
) && (env
->cr
[4] & CR4_PSE_MASK
)) {
1205 print_pte((l1
<< 22), pde
, ~((1 << 20) - 1));
1207 for(l2
= 0; l2
< 1024; l2
++) {
1208 cpu_physical_memory_read((pde
& ~0xfff) + l2
* 4,
1209 (uint8_t *)&pte
, 4);
1210 pte
= le32_to_cpu(pte
);
1211 if (pte
& PG_PRESENT_MASK
) {
1212 print_pte((l1
<< 22) + (l2
<< 12),
1222 static void mem_print(uint32_t *pstart
, int *plast_prot
,
1223 uint32_t end
, int prot
)
1226 prot1
= *plast_prot
;
1227 if (prot
!= prot1
) {
1228 if (*pstart
!= -1) {
1229 term_printf("%08x-%08x %08x %c%c%c\n",
1230 *pstart
, end
, end
- *pstart
,
1231 prot1
& PG_USER_MASK
? 'u' : '-',
1233 prot1
& PG_RW_MASK
? 'w' : '-');
1243 static void mem_info(void)
1246 int l1
, l2
, prot
, last_prot
;
1247 uint32_t pgd
, pde
, pte
, start
, end
;
1249 env
= mon_get_cpu();
1253 if (!(env
->cr
[0] & CR0_PG_MASK
)) {
1254 term_printf("PG disabled\n");
1257 pgd
= env
->cr
[3] & ~0xfff;
1260 for(l1
= 0; l1
< 1024; l1
++) {
1261 cpu_physical_memory_read(pgd
+ l1
* 4, (uint8_t *)&pde
, 4);
1262 pde
= le32_to_cpu(pde
);
1264 if (pde
& PG_PRESENT_MASK
) {
1265 if ((pde
& PG_PSE_MASK
) && (env
->cr
[4] & CR4_PSE_MASK
)) {
1266 prot
= pde
& (PG_USER_MASK
| PG_RW_MASK
| PG_PRESENT_MASK
);
1267 mem_print(&start
, &last_prot
, end
, prot
);
1269 for(l2
= 0; l2
< 1024; l2
++) {
1270 cpu_physical_memory_read((pde
& ~0xfff) + l2
* 4,
1271 (uint8_t *)&pte
, 4);
1272 pte
= le32_to_cpu(pte
);
1273 end
= (l1
<< 22) + (l2
<< 12);
1274 if (pte
& PG_PRESENT_MASK
) {
1275 prot
= pte
& (PG_USER_MASK
| PG_RW_MASK
| PG_PRESENT_MASK
);
1279 mem_print(&start
, &last_prot
, end
, prot
);
1284 mem_print(&start
, &last_prot
, end
, prot
);
1290 #if defined(TARGET_SH4)
1292 static void print_tlb(int idx
, tlb_t
*tlb
)
1294 term_printf(" tlb%i:\t"
1295 "asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t"
1296 "v=%hhu shared=%hhu cached=%hhu prot=%hhu "
1297 "dirty=%hhu writethrough=%hhu\n",
1299 tlb
->asid
, tlb
->vpn
, tlb
->ppn
, tlb
->sz
, tlb
->size
,
1300 tlb
->v
, tlb
->sh
, tlb
->c
, tlb
->pr
,
1304 static void tlb_info(void)
1306 CPUState
*env
= mon_get_cpu();
1309 term_printf ("ITLB:\n");
1310 for (i
= 0 ; i
< ITLB_SIZE
; i
++)
1311 print_tlb (i
, &env
->itlb
[i
]);
1312 term_printf ("UTLB:\n");
1313 for (i
= 0 ; i
< UTLB_SIZE
; i
++)
1314 print_tlb (i
, &env
->utlb
[i
]);
1319 static void do_info_kqemu(void)
1325 env
= mon_get_cpu();
1327 term_printf("No cpu initialized yet");
1330 val
= env
->kqemu_enabled
;
1331 term_printf("kqemu support: ");
1335 term_printf("disabled\n");
1338 term_printf("enabled for user code\n");
1341 term_printf("enabled for user and kernel code\n");
1345 term_printf("kqemu support: not compiled\n");
1349 static void do_info_kvm(void)
1351 #if defined(USE_KVM) || defined(CONFIG_KVM)
1352 term_printf("kvm support: ");
1354 term_printf("enabled\n");
1356 term_printf("disabled\n");
1358 term_printf("kvm support: not compiled\n");
1362 #ifdef CONFIG_PROFILER
1366 int64_t kqemu_exec_count
;
1368 int64_t kqemu_ret_int_count
;
1369 int64_t kqemu_ret_excp_count
;
1370 int64_t kqemu_ret_intr_count
;
1372 static void do_info_profile(void)
1378 term_printf("async time %" PRId64
" (%0.3f)\n",
1379 dev_time
, dev_time
/ (double)ticks_per_sec
);
1380 term_printf("qemu time %" PRId64
" (%0.3f)\n",
1381 qemu_time
, qemu_time
/ (double)ticks_per_sec
);
1382 term_printf("kqemu time %" PRId64
" (%0.3f %0.1f%%) count=%" PRId64
" int=%" PRId64
" excp=%" PRId64
" intr=%" PRId64
"\n",
1383 kqemu_time
, kqemu_time
/ (double)ticks_per_sec
,
1384 kqemu_time
/ (double)total
* 100.0,
1386 kqemu_ret_int_count
,
1387 kqemu_ret_excp_count
,
1388 kqemu_ret_intr_count
);
1391 kqemu_exec_count
= 0;
1393 kqemu_ret_int_count
= 0;
1394 kqemu_ret_excp_count
= 0;
1395 kqemu_ret_intr_count
= 0;
1397 kqemu_record_dump();
1401 static void do_info_profile(void)
1403 term_printf("Internal profiler not compiled\n");
1407 /* Capture support */
1408 static LIST_HEAD (capture_list_head
, CaptureState
) capture_head
;
1410 static void do_info_capture (void)
1415 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
1416 term_printf ("[%d]: ", i
);
1417 s
->ops
.info (s
->opaque
);
1421 static void do_stop_capture (int n
)
1426 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
1428 s
->ops
.destroy (s
->opaque
);
1429 LIST_REMOVE (s
, entries
);
1437 static void do_wav_capture (const char *path
,
1438 int has_freq
, int freq
,
1439 int has_bits
, int bits
,
1440 int has_channels
, int nchannels
)
1444 s
= qemu_mallocz (sizeof (*s
));
1446 freq
= has_freq
? freq
: 44100;
1447 bits
= has_bits
? bits
: 16;
1448 nchannels
= has_channels
? nchannels
: 2;
1450 if (wav_start_capture (s
, path
, freq
, bits
, nchannels
)) {
1451 term_printf ("Faied to add wave capture\n");
1454 LIST_INSERT_HEAD (&capture_head
, s
, entries
);
1458 #if defined(TARGET_I386)
1459 static void do_inject_nmi(int cpu_index
)
1463 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
)
1464 if (env
->cpu_index
== cpu_index
) {
1466 kvm_inject_interrupt(env
, CPU_INTERRUPT_NMI
);
1468 cpu_interrupt(env
, CPU_INTERRUPT_NMI
);
1474 static void do_info_status(void)
1477 term_printf("VM status: running\n");
1479 term_printf("VM status: paused\n");
1483 static void do_balloon(int value
)
1485 ram_addr_t target
= value
;
1486 qemu_balloon(target
<< 20);
1489 static void do_info_balloon(void)
1493 actual
= qemu_balloon_status();
1494 if (kvm_enabled() && !kvm_has_sync_mmu())
1495 term_printf("Using KVM without synchronous MMU, ballooning disabled\n");
1496 else if (actual
== 0)
1497 term_printf("Ballooning not activated in VM\n");
1499 term_printf("balloon: actual=%d\n", (int)(actual
>> 20));
1502 static void do_acl(const char *command
,
1503 const char *aclname
,
1510 acl
= qemu_acl_find(aclname
);
1512 term_printf("acl: unknown list '%s'\n", aclname
);
1516 if (strcmp(command
, "show") == 0) {
1518 qemu_acl_entry
*entry
;
1519 term_printf("policy: %s\n",
1520 acl
->defaultDeny
? "deny" : "allow");
1521 TAILQ_FOREACH(entry
, &acl
->entries
, next
) {
1523 term_printf("%d: %s %s\n", i
,
1524 entry
->deny
? "deny" : "allow",
1527 } else if (strcmp(command
, "reset") == 0) {
1528 qemu_acl_reset(acl
);
1529 term_printf("acl: removed all rules\n");
1530 } else if (strcmp(command
, "policy") == 0) {
1532 term_printf("acl: missing policy parameter\n");
1536 if (strcmp(match
, "allow") == 0) {
1537 acl
->defaultDeny
= 0;
1538 term_printf("acl: policy set to 'allow'\n");
1539 } else if (strcmp(match
, "deny") == 0) {
1540 acl
->defaultDeny
= 1;
1541 term_printf("acl: policy set to 'deny'\n");
1543 term_printf("acl: unknown policy '%s', expected 'deny' or 'allow'\n", match
);
1545 } else if ((strcmp(command
, "allow") == 0) ||
1546 (strcmp(command
, "deny") == 0)) {
1547 int deny
= strcmp(command
, "deny") == 0 ? 1 : 0;
1551 term_printf("acl: missing match parameter\n");
1556 ret
= qemu_acl_insert(acl
, deny
, match
, index
);
1558 ret
= qemu_acl_append(acl
, deny
, match
);
1560 term_printf("acl: unable to add acl entry\n");
1562 term_printf("acl: added rule at position %d\n", ret
);
1563 } else if (strcmp(command
, "remove") == 0) {
1567 term_printf("acl: missing match parameter\n");
1571 ret
= qemu_acl_remove(acl
, match
);
1573 term_printf("acl: no matching acl entry\n");
1575 term_printf("acl: removed rule at position %d\n", ret
);
1577 term_printf("acl: unknown command '%s'\n", command
);
1581 /* Please update qemu-doc.texi when adding or changing commands */
1582 static const term_cmd_t term_cmds
[] = {
1583 { "help|?", "s?", do_help
,
1584 "[cmd]", "show the help" },
1585 { "commit", "s", do_commit
,
1586 "device|all", "commit changes to the disk images (if -snapshot is used) or backing files" },
1587 { "info", "s?", do_info
,
1588 "subcommand", "show various information about the system state" },
1589 { "q|quit", "", do_quit
,
1590 "", "quit the emulator" },
1591 { "eject", "-fB", do_eject
,
1592 "[-f] device", "eject a removable medium (use -f to force it)" },
1593 { "change", "BFs?", do_change
,
1594 "device filename [format]", "change a removable medium, optional format" },
1595 { "screendump", "F", do_screen_dump
,
1596 "filename", "save screen into PPM image 'filename'" },
1597 { "logfile", "F", do_logfile
,
1598 "filename", "output logs to 'filename'" },
1599 { "log", "s", do_log
,
1600 "item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" },
1601 { "savevm", "s?", do_savevm
,
1602 "tag|id", "save a VM snapshot. If no tag or id are provided, a new snapshot is created" },
1603 { "loadvm", "s", do_loadvm
,
1604 "tag|id", "restore a VM snapshot from its tag or id" },
1605 { "delvm", "s", do_delvm
,
1606 "tag|id", "delete a VM snapshot from its tag or id" },
1607 { "stop", "", do_stop
,
1608 "", "stop emulation", },
1609 { "c|cont", "", do_cont
,
1610 "", "resume emulation", },
1611 #ifdef CONFIG_GDBSTUB
1612 { "gdbserver", "s?", do_gdbserver
,
1613 "[port]", "start gdbserver session (default port=1234)", },
1615 { "x", "/l", do_memory_dump
,
1616 "/fmt addr", "virtual memory dump starting at 'addr'", },
1617 { "xp", "/l", do_physical_memory_dump
,
1618 "/fmt addr", "physical memory dump starting at 'addr'", },
1619 { "p|print", "/l", do_print
,
1620 "/fmt expr", "print expression value (use $reg for CPU register access)", },
1621 { "i", "/ii.", do_ioport_read
,
1622 "/fmt addr", "I/O port read" },
1624 { "sendkey", "si?", do_sendkey
,
1625 "keys [hold_ms]", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1', default hold time=100 ms)" },
1626 { "system_reset", "", do_system_reset
,
1627 "", "reset the system" },
1628 { "system_powerdown", "", do_system_powerdown
,
1629 "", "send system power down event" },
1630 { "sum", "ii", do_sum
,
1631 "addr size", "compute the checksum of a memory region" },
1632 { "usb_add", "s", do_usb_add
,
1633 "device", "add USB device (e.g. 'host:bus.addr' or 'host:vendor_id:product_id')" },
1634 { "usb_del", "s", do_usb_del
,
1635 "device", "remove USB device 'bus.addr'" },
1636 { "cpu", "i", do_cpu_set
,
1637 "index", "set the default CPU" },
1638 { "mouse_move", "sss?", do_mouse_move
,
1639 "dx dy [dz]", "send mouse move events" },
1640 { "mouse_button", "i", do_mouse_button
,
1641 "state", "change mouse button state (1=L, 2=M, 4=R)" },
1642 { "mouse_set", "i", do_mouse_set
,
1643 "index", "set which mouse device receives events" },
1645 { "wavcapture", "si?i?i?", do_wav_capture
,
1646 "path [frequency bits channels]",
1647 "capture audio to a wave file (default frequency=44100 bits=16 channels=2)" },
1649 { "stopcapture", "i", do_stop_capture
,
1650 "capture index", "stop capture" },
1651 { "memsave", "lis", do_memory_save
,
1652 "addr size file", "save to disk virtual memory dump starting at 'addr' of size 'size'", },
1653 { "pmemsave", "lis", do_physical_memory_save
,
1654 "addr size file", "save to disk physical memory dump starting at 'addr' of size 'size'", },
1655 { "boot_set", "s", do_boot_set
,
1656 "bootdevice", "define new values for the boot device list" },
1657 #if defined(TARGET_I386)
1658 { "nmi", "i", do_inject_nmi
,
1659 "cpu", "inject an NMI on the given CPU", },
1661 { "migrate", "-ds", do_migrate
,
1662 "[-d] uri", "migrate to URI (using -d to not wait for completion)" },
1663 { "migrate_cancel", "", do_migrate_cancel
,
1664 "", "cancel the current VM migration" },
1665 { "migrate_set_speed", "s", do_migrate_set_speed
,
1666 "value", "set maximum speed (in bytes) for migrations" },
1667 #if defined(TARGET_I386)
1668 { "drive_add", "ss", drive_hot_add
, "pci_addr=[[<domain>:]<bus>:]<slot>\n"
1669 "[file=file][,if=type][,bus=n]\n"
1670 "[,unit=m][,media=d][index=i]\n"
1671 "[,cyls=c,heads=h,secs=s[,trans=t]]\n"
1672 "[snapshot=on|off][,cache=on|off]",
1673 "add drive to PCI storage controller" },
1674 { "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" },
1675 { "pci_del", "s", pci_device_hot_remove
, "pci_addr=[[<domain>:]<bus>:]<slot>", "hot remove PCI device" },
1676 { "host_net_add", "ss", net_host_device_add
,
1677 "[tap,user,socket,vde] options", "add host VLAN client" },
1678 { "host_net_remove", "is", net_host_device_remove
,
1679 "vlan_id name", "remove host VLAN client" },
1681 { "balloon", "i", do_balloon
,
1682 "target", "request VM to change it's memory allocation (in MB)" },
1683 { "set_link", "ss", do_set_link
,
1684 "name [up|down]", "change the link status of a network adapter" },
1685 { "set_link", "ss", do_set_link
, "name [up|down]" },
1686 { "acl", "sss?i?", do_acl
, "<command> <aclname> [<match>] [<index>]\n",
1687 "acl show vnc.username\n"
1688 "acl policy vnc.username deny\n"
1689 "acl allow vnc.username fred\n"
1690 "acl deny vnc.username bob\n"
1691 "acl reset vnc.username\n" },
1692 { "cpu_set", "is", do_cpu_set_nr
, "cpu [online|offline]", "change cpu state" },
1693 #if defined(TARGET_I386) || defined(TARGET_X86_64)
1694 { "drive_add", "iss", drive_hot_add
, "pcibus pcidevfn [file=file][,if=type][,bus=n]\n"
1695 "[,unit=m][,media=d][index=i]\n"
1696 "[,cyls=c,heads=h,secs=s[,trans=t]]\n"
1697 "[snapshot=on|off][,cache=on|off]",
1698 "add drive to PCI storage controller" },
1704 /* Please update qemu-doc.texi when adding or changing commands */
1705 static const term_cmd_t info_cmds
[] = {
1706 { "version", "", do_info_version
,
1707 "", "show the version of QEMU" },
1708 { "network", "", do_info_network
,
1709 "", "show the network state" },
1710 { "chardev", "", qemu_chr_info
,
1711 "", "show the character devices" },
1712 { "block", "", do_info_block
,
1713 "", "show the block devices" },
1714 { "blockstats", "", do_info_blockstats
,
1715 "", "show block device statistics" },
1716 { "registers", "", do_info_registers
,
1717 "", "show the cpu registers" },
1718 { "cpus", "", do_info_cpus
,
1719 "", "show infos for each CPU" },
1720 { "history", "", do_info_history
,
1721 "", "show the command line history", },
1722 { "irq", "", irq_info
,
1723 "", "show the interrupts statistics (if available)", },
1724 { "pic", "", pic_info
,
1725 "", "show i8259 (PIC) state", },
1726 { "pci", "", pci_info
,
1727 "", "show PCI info", },
1728 #if defined(TARGET_I386) || defined(TARGET_SH4)
1729 { "tlb", "", tlb_info
,
1730 "", "show virtual to physical memory mappings", },
1732 #if defined(TARGET_I386)
1733 { "mem", "", mem_info
,
1734 "", "show the active virtual memory mappings", },
1735 { "hpet", "", do_info_hpet
,
1736 "", "show state of HPET", },
1738 { "jit", "", do_info_jit
,
1739 "", "show dynamic compiler info", },
1740 { "kqemu", "", do_info_kqemu
,
1741 "", "show KQEMU information", },
1742 { "kvm", "", do_info_kvm
,
1743 "", "show KVM information", },
1744 { "usb", "", usb_info
,
1745 "", "show guest USB devices", },
1746 { "usbhost", "", usb_host_info
,
1747 "", "show host USB devices", },
1748 { "profile", "", do_info_profile
,
1749 "", "show profiling information", },
1750 { "capture", "", do_info_capture
,
1751 "", "show capture information" },
1752 { "snapshots", "", do_info_snapshots
,
1753 "", "show the currently saved VM snapshots" },
1754 { "status", "", do_info_status
,
1755 "", "show the current VM status (running|paused)" },
1756 { "pcmcia", "", pcmcia_info
,
1757 "", "show guest PCMCIA status" },
1758 { "mice", "", do_info_mice
,
1759 "", "show which guest mouse is receiving events" },
1760 { "vnc", "", do_info_vnc
,
1761 "", "show the vnc server status"},
1762 { "name", "", do_info_name
,
1763 "", "show the current VM name" },
1764 { "uuid", "", do_info_uuid
,
1765 "", "show the current VM UUID" },
1766 #if defined(TARGET_PPC)
1767 { "cpustats", "", do_info_cpu_stats
,
1768 "", "show CPU statistics", },
1770 #if defined(CONFIG_SLIRP)
1771 { "slirp", "", do_info_slirp
,
1772 "", "show SLIRP statistics", },
1774 { "migrate", "", do_info_migrate
, "", "show migration status" },
1775 { "balloon", "", do_info_balloon
,
1776 "", "show balloon information" },
1780 /*******************************************************************/
1782 static const char *pch
;
1783 static jmp_buf expr_env
;
1788 typedef struct MonitorDef
{
1791 target_long (*get_value
)(const struct MonitorDef
*md
, int val
);
1795 #if defined(TARGET_I386)
1796 static target_long
monitor_get_pc (const struct MonitorDef
*md
, int val
)
1798 CPUState
*env
= mon_get_cpu();
1801 return env
->eip
+ env
->segs
[R_CS
].base
;
1805 #if defined(TARGET_PPC)
1806 static target_long
monitor_get_ccr (const struct MonitorDef
*md
, int val
)
1808 CPUState
*env
= mon_get_cpu();
1816 for (i
= 0; i
< 8; i
++)
1817 u
|= env
->crf
[i
] << (32 - (4 * i
));
1822 static target_long
monitor_get_msr (const struct MonitorDef
*md
, int val
)
1824 CPUState
*env
= mon_get_cpu();
1830 static target_long
monitor_get_xer (const struct MonitorDef
*md
, int val
)
1832 CPUState
*env
= mon_get_cpu();
1838 static target_long
monitor_get_decr (const struct MonitorDef
*md
, int val
)
1840 CPUState
*env
= mon_get_cpu();
1843 return cpu_ppc_load_decr(env
);
1846 static target_long
monitor_get_tbu (const struct MonitorDef
*md
, int val
)
1848 CPUState
*env
= mon_get_cpu();
1851 return cpu_ppc_load_tbu(env
);
1854 static target_long
monitor_get_tbl (const struct MonitorDef
*md
, int val
)
1856 CPUState
*env
= mon_get_cpu();
1859 return cpu_ppc_load_tbl(env
);
1863 #if defined(TARGET_SPARC)
1864 #ifndef TARGET_SPARC64
1865 static target_long
monitor_get_psr (const struct MonitorDef
*md
, int val
)
1867 CPUState
*env
= mon_get_cpu();
1870 return GET_PSR(env
);
1874 static target_long
monitor_get_reg(const struct MonitorDef
*md
, int val
)
1876 CPUState
*env
= mon_get_cpu();
1879 return env
->regwptr
[val
];
1883 static const MonitorDef monitor_defs
[] = {
1886 #define SEG(name, seg) \
1887 { name, offsetof(CPUState, segs[seg].selector), NULL, MD_I32 },\
1888 { name ".base", offsetof(CPUState, segs[seg].base) },\
1889 { name ".limit", offsetof(CPUState, segs[seg].limit), NULL, MD_I32 },
1891 { "eax", offsetof(CPUState
, regs
[0]) },
1892 { "ecx", offsetof(CPUState
, regs
[1]) },
1893 { "edx", offsetof(CPUState
, regs
[2]) },
1894 { "ebx", offsetof(CPUState
, regs
[3]) },
1895 { "esp|sp", offsetof(CPUState
, regs
[4]) },
1896 { "ebp|fp", offsetof(CPUState
, regs
[5]) },
1897 { "esi", offsetof(CPUState
, regs
[6]) },
1898 { "edi", offsetof(CPUState
, regs
[7]) },
1899 #ifdef TARGET_X86_64
1900 { "r8", offsetof(CPUState
, regs
[8]) },
1901 { "r9", offsetof(CPUState
, regs
[9]) },
1902 { "r10", offsetof(CPUState
, regs
[10]) },
1903 { "r11", offsetof(CPUState
, regs
[11]) },
1904 { "r12", offsetof(CPUState
, regs
[12]) },
1905 { "r13", offsetof(CPUState
, regs
[13]) },
1906 { "r14", offsetof(CPUState
, regs
[14]) },
1907 { "r15", offsetof(CPUState
, regs
[15]) },
1909 { "eflags", offsetof(CPUState
, eflags
) },
1910 { "eip", offsetof(CPUState
, eip
) },
1917 { "pc", 0, monitor_get_pc
, },
1918 #elif defined(TARGET_PPC)
1919 /* General purpose registers */
1920 { "r0", offsetof(CPUState
, gpr
[0]) },
1921 { "r1", offsetof(CPUState
, gpr
[1]) },
1922 { "r2", offsetof(CPUState
, gpr
[2]) },
1923 { "r3", offsetof(CPUState
, gpr
[3]) },
1924 { "r4", offsetof(CPUState
, gpr
[4]) },
1925 { "r5", offsetof(CPUState
, gpr
[5]) },
1926 { "r6", offsetof(CPUState
, gpr
[6]) },
1927 { "r7", offsetof(CPUState
, gpr
[7]) },
1928 { "r8", offsetof(CPUState
, gpr
[8]) },
1929 { "r9", offsetof(CPUState
, gpr
[9]) },
1930 { "r10", offsetof(CPUState
, gpr
[10]) },
1931 { "r11", offsetof(CPUState
, gpr
[11]) },
1932 { "r12", offsetof(CPUState
, gpr
[12]) },
1933 { "r13", offsetof(CPUState
, gpr
[13]) },
1934 { "r14", offsetof(CPUState
, gpr
[14]) },
1935 { "r15", offsetof(CPUState
, gpr
[15]) },
1936 { "r16", offsetof(CPUState
, gpr
[16]) },
1937 { "r17", offsetof(CPUState
, gpr
[17]) },
1938 { "r18", offsetof(CPUState
, gpr
[18]) },
1939 { "r19", offsetof(CPUState
, gpr
[19]) },
1940 { "r20", offsetof(CPUState
, gpr
[20]) },
1941 { "r21", offsetof(CPUState
, gpr
[21]) },
1942 { "r22", offsetof(CPUState
, gpr
[22]) },
1943 { "r23", offsetof(CPUState
, gpr
[23]) },
1944 { "r24", offsetof(CPUState
, gpr
[24]) },
1945 { "r25", offsetof(CPUState
, gpr
[25]) },
1946 { "r26", offsetof(CPUState
, gpr
[26]) },
1947 { "r27", offsetof(CPUState
, gpr
[27]) },
1948 { "r28", offsetof(CPUState
, gpr
[28]) },
1949 { "r29", offsetof(CPUState
, gpr
[29]) },
1950 { "r30", offsetof(CPUState
, gpr
[30]) },
1951 { "r31", offsetof(CPUState
, gpr
[31]) },
1952 /* Floating point registers */
1953 { "f0", offsetof(CPUState
, fpr
[0]) },
1954 { "f1", offsetof(CPUState
, fpr
[1]) },
1955 { "f2", offsetof(CPUState
, fpr
[2]) },
1956 { "f3", offsetof(CPUState
, fpr
[3]) },
1957 { "f4", offsetof(CPUState
, fpr
[4]) },
1958 { "f5", offsetof(CPUState
, fpr
[5]) },
1959 { "f6", offsetof(CPUState
, fpr
[6]) },
1960 { "f7", offsetof(CPUState
, fpr
[7]) },
1961 { "f8", offsetof(CPUState
, fpr
[8]) },
1962 { "f9", offsetof(CPUState
, fpr
[9]) },
1963 { "f10", offsetof(CPUState
, fpr
[10]) },
1964 { "f11", offsetof(CPUState
, fpr
[11]) },
1965 { "f12", offsetof(CPUState
, fpr
[12]) },
1966 { "f13", offsetof(CPUState
, fpr
[13]) },
1967 { "f14", offsetof(CPUState
, fpr
[14]) },
1968 { "f15", offsetof(CPUState
, fpr
[15]) },
1969 { "f16", offsetof(CPUState
, fpr
[16]) },
1970 { "f17", offsetof(CPUState
, fpr
[17]) },
1971 { "f18", offsetof(CPUState
, fpr
[18]) },
1972 { "f19", offsetof(CPUState
, fpr
[19]) },
1973 { "f20", offsetof(CPUState
, fpr
[20]) },
1974 { "f21", offsetof(CPUState
, fpr
[21]) },
1975 { "f22", offsetof(CPUState
, fpr
[22]) },
1976 { "f23", offsetof(CPUState
, fpr
[23]) },
1977 { "f24", offsetof(CPUState
, fpr
[24]) },
1978 { "f25", offsetof(CPUState
, fpr
[25]) },
1979 { "f26", offsetof(CPUState
, fpr
[26]) },
1980 { "f27", offsetof(CPUState
, fpr
[27]) },
1981 { "f28", offsetof(CPUState
, fpr
[28]) },
1982 { "f29", offsetof(CPUState
, fpr
[29]) },
1983 { "f30", offsetof(CPUState
, fpr
[30]) },
1984 { "f31", offsetof(CPUState
, fpr
[31]) },
1985 { "fpscr", offsetof(CPUState
, fpscr
) },
1986 /* Next instruction pointer */
1987 { "nip|pc", offsetof(CPUState
, nip
) },
1988 { "lr", offsetof(CPUState
, lr
) },
1989 { "ctr", offsetof(CPUState
, ctr
) },
1990 { "decr", 0, &monitor_get_decr
, },
1991 { "ccr", 0, &monitor_get_ccr
, },
1992 /* Machine state register */
1993 { "msr", 0, &monitor_get_msr
, },
1994 { "xer", 0, &monitor_get_xer
, },
1995 { "tbu", 0, &monitor_get_tbu
, },
1996 { "tbl", 0, &monitor_get_tbl
, },
1997 #if defined(TARGET_PPC64)
1998 /* Address space register */
1999 { "asr", offsetof(CPUState
, asr
) },
2001 /* Segment registers */
2002 { "sdr1", offsetof(CPUState
, sdr1
) },
2003 { "sr0", offsetof(CPUState
, sr
[0]) },
2004 { "sr1", offsetof(CPUState
, sr
[1]) },
2005 { "sr2", offsetof(CPUState
, sr
[2]) },
2006 { "sr3", offsetof(CPUState
, sr
[3]) },
2007 { "sr4", offsetof(CPUState
, sr
[4]) },
2008 { "sr5", offsetof(CPUState
, sr
[5]) },
2009 { "sr6", offsetof(CPUState
, sr
[6]) },
2010 { "sr7", offsetof(CPUState
, sr
[7]) },
2011 { "sr8", offsetof(CPUState
, sr
[8]) },
2012 { "sr9", offsetof(CPUState
, sr
[9]) },
2013 { "sr10", offsetof(CPUState
, sr
[10]) },
2014 { "sr11", offsetof(CPUState
, sr
[11]) },
2015 { "sr12", offsetof(CPUState
, sr
[12]) },
2016 { "sr13", offsetof(CPUState
, sr
[13]) },
2017 { "sr14", offsetof(CPUState
, sr
[14]) },
2018 { "sr15", offsetof(CPUState
, sr
[15]) },
2019 /* Too lazy to put BATs and SPRs ... */
2020 #elif defined(TARGET_SPARC)
2021 { "g0", offsetof(CPUState
, gregs
[0]) },
2022 { "g1", offsetof(CPUState
, gregs
[1]) },
2023 { "g2", offsetof(CPUState
, gregs
[2]) },
2024 { "g3", offsetof(CPUState
, gregs
[3]) },
2025 { "g4", offsetof(CPUState
, gregs
[4]) },
2026 { "g5", offsetof(CPUState
, gregs
[5]) },
2027 { "g6", offsetof(CPUState
, gregs
[6]) },
2028 { "g7", offsetof(CPUState
, gregs
[7]) },
2029 { "o0", 0, monitor_get_reg
},
2030 { "o1", 1, monitor_get_reg
},
2031 { "o2", 2, monitor_get_reg
},
2032 { "o3", 3, monitor_get_reg
},
2033 { "o4", 4, monitor_get_reg
},
2034 { "o5", 5, monitor_get_reg
},
2035 { "o6", 6, monitor_get_reg
},
2036 { "o7", 7, monitor_get_reg
},
2037 { "l0", 8, monitor_get_reg
},
2038 { "l1", 9, monitor_get_reg
},
2039 { "l2", 10, monitor_get_reg
},
2040 { "l3", 11, monitor_get_reg
},
2041 { "l4", 12, monitor_get_reg
},
2042 { "l5", 13, monitor_get_reg
},
2043 { "l6", 14, monitor_get_reg
},
2044 { "l7", 15, monitor_get_reg
},
2045 { "i0", 16, monitor_get_reg
},
2046 { "i1", 17, monitor_get_reg
},
2047 { "i2", 18, monitor_get_reg
},
2048 { "i3", 19, monitor_get_reg
},
2049 { "i4", 20, monitor_get_reg
},
2050 { "i5", 21, monitor_get_reg
},
2051 { "i6", 22, monitor_get_reg
},
2052 { "i7", 23, monitor_get_reg
},
2053 { "pc", offsetof(CPUState
, pc
) },
2054 { "npc", offsetof(CPUState
, npc
) },
2055 { "y", offsetof(CPUState
, y
) },
2056 #ifndef TARGET_SPARC64
2057 { "psr", 0, &monitor_get_psr
, },
2058 { "wim", offsetof(CPUState
, wim
) },
2060 { "tbr", offsetof(CPUState
, tbr
) },
2061 { "fsr", offsetof(CPUState
, fsr
) },
2062 { "f0", offsetof(CPUState
, fpr
[0]) },
2063 { "f1", offsetof(CPUState
, fpr
[1]) },
2064 { "f2", offsetof(CPUState
, fpr
[2]) },
2065 { "f3", offsetof(CPUState
, fpr
[3]) },
2066 { "f4", offsetof(CPUState
, fpr
[4]) },
2067 { "f5", offsetof(CPUState
, fpr
[5]) },
2068 { "f6", offsetof(CPUState
, fpr
[6]) },
2069 { "f7", offsetof(CPUState
, fpr
[7]) },
2070 { "f8", offsetof(CPUState
, fpr
[8]) },
2071 { "f9", offsetof(CPUState
, fpr
[9]) },
2072 { "f10", offsetof(CPUState
, fpr
[10]) },
2073 { "f11", offsetof(CPUState
, fpr
[11]) },
2074 { "f12", offsetof(CPUState
, fpr
[12]) },
2075 { "f13", offsetof(CPUState
, fpr
[13]) },
2076 { "f14", offsetof(CPUState
, fpr
[14]) },
2077 { "f15", offsetof(CPUState
, fpr
[15]) },
2078 { "f16", offsetof(CPUState
, fpr
[16]) },
2079 { "f17", offsetof(CPUState
, fpr
[17]) },
2080 { "f18", offsetof(CPUState
, fpr
[18]) },
2081 { "f19", offsetof(CPUState
, fpr
[19]) },
2082 { "f20", offsetof(CPUState
, fpr
[20]) },
2083 { "f21", offsetof(CPUState
, fpr
[21]) },
2084 { "f22", offsetof(CPUState
, fpr
[22]) },
2085 { "f23", offsetof(CPUState
, fpr
[23]) },
2086 { "f24", offsetof(CPUState
, fpr
[24]) },
2087 { "f25", offsetof(CPUState
, fpr
[25]) },
2088 { "f26", offsetof(CPUState
, fpr
[26]) },
2089 { "f27", offsetof(CPUState
, fpr
[27]) },
2090 { "f28", offsetof(CPUState
, fpr
[28]) },
2091 { "f29", offsetof(CPUState
, fpr
[29]) },
2092 { "f30", offsetof(CPUState
, fpr
[30]) },
2093 { "f31", offsetof(CPUState
, fpr
[31]) },
2094 #ifdef TARGET_SPARC64
2095 { "f32", offsetof(CPUState
, fpr
[32]) },
2096 { "f34", offsetof(CPUState
, fpr
[34]) },
2097 { "f36", offsetof(CPUState
, fpr
[36]) },
2098 { "f38", offsetof(CPUState
, fpr
[38]) },
2099 { "f40", offsetof(CPUState
, fpr
[40]) },
2100 { "f42", offsetof(CPUState
, fpr
[42]) },
2101 { "f44", offsetof(CPUState
, fpr
[44]) },
2102 { "f46", offsetof(CPUState
, fpr
[46]) },
2103 { "f48", offsetof(CPUState
, fpr
[48]) },
2104 { "f50", offsetof(CPUState
, fpr
[50]) },
2105 { "f52", offsetof(CPUState
, fpr
[52]) },
2106 { "f54", offsetof(CPUState
, fpr
[54]) },
2107 { "f56", offsetof(CPUState
, fpr
[56]) },
2108 { "f58", offsetof(CPUState
, fpr
[58]) },
2109 { "f60", offsetof(CPUState
, fpr
[60]) },
2110 { "f62", offsetof(CPUState
, fpr
[62]) },
2111 { "asi", offsetof(CPUState
, asi
) },
2112 { "pstate", offsetof(CPUState
, pstate
) },
2113 { "cansave", offsetof(CPUState
, cansave
) },
2114 { "canrestore", offsetof(CPUState
, canrestore
) },
2115 { "otherwin", offsetof(CPUState
, otherwin
) },
2116 { "wstate", offsetof(CPUState
, wstate
) },
2117 { "cleanwin", offsetof(CPUState
, cleanwin
) },
2118 { "fprs", offsetof(CPUState
, fprs
) },
2124 static void expr_error(const char *msg
)
2126 term_printf("%s\n", msg
);
2127 longjmp(expr_env
, 1);
2130 /* return 0 if OK, -1 if not found, -2 if no CPU defined */
2131 static int get_monitor_def(target_long
*pval
, const char *name
)
2133 const MonitorDef
*md
;
2136 for(md
= monitor_defs
; md
->name
!= NULL
; md
++) {
2137 if (compare_cmd(name
, md
->name
)) {
2138 if (md
->get_value
) {
2139 *pval
= md
->get_value(md
, md
->offset
);
2141 CPUState
*env
= mon_get_cpu();
2144 ptr
= (uint8_t *)env
+ md
->offset
;
2147 *pval
= *(int32_t *)ptr
;
2150 *pval
= *(target_long
*)ptr
;
2163 static void next(void)
2167 while (qemu_isspace(*pch
))
2172 static int64_t expr_sum(void);
2174 static int64_t expr_unary(void)
2197 expr_error("')' expected");
2204 expr_error("character constant expected");
2208 expr_error("missing terminating \' character");
2218 while ((*pch
>= 'a' && *pch
<= 'z') ||
2219 (*pch
>= 'A' && *pch
<= 'Z') ||
2220 (*pch
>= '0' && *pch
<= '9') ||
2221 *pch
== '_' || *pch
== '.') {
2222 if ((q
- buf
) < sizeof(buf
) - 1)
2226 while (qemu_isspace(*pch
))
2229 ret
= get_monitor_def(®
, buf
);
2231 expr_error("unknown register");
2233 expr_error("no cpu defined");
2238 expr_error("unexpected end of expression");
2242 #if TARGET_PHYS_ADDR_BITS > 32
2243 n
= strtoull(pch
, &p
, 0);
2245 n
= strtoul(pch
, &p
, 0);
2248 expr_error("invalid char in expression");
2251 while (qemu_isspace(*pch
))
2259 static int64_t expr_prod(void)
2267 if (op
!= '*' && op
!= '/' && op
!= '%')
2270 val2
= expr_unary();
2279 expr_error("division by zero");
2290 static int64_t expr_logic(void)
2298 if (op
!= '&' && op
!= '|' && op
!= '^')
2318 static int64_t expr_sum(void)
2326 if (op
!= '+' && op
!= '-')
2329 val2
= expr_logic();
2338 static int get_expr(int64_t *pval
, const char **pp
)
2341 if (setjmp(expr_env
)) {
2345 while (qemu_isspace(*pch
))
2352 static int get_str(char *buf
, int buf_size
, const char **pp
)
2360 while (qemu_isspace(*p
))
2370 while (*p
!= '\0' && *p
!= '\"') {
2386 qemu_printf("unsupported escape code: '\\%c'\n", c
);
2389 if ((q
- buf
) < buf_size
- 1) {
2393 if ((q
- buf
) < buf_size
- 1) {
2400 qemu_printf("unterminated string\n");
2405 while (*p
!= '\0' && !qemu_isspace(*p
)) {
2406 if ((q
- buf
) < buf_size
- 1) {
2417 static int default_fmt_format
= 'x';
2418 static int default_fmt_size
= 4;
2422 static void monitor_handle_command(const char *cmdline
)
2424 const char *p
, *pstart
, *typestr
;
2426 int c
, nb_args
, len
, i
, has_arg
;
2427 const term_cmd_t
*cmd
;
2430 void *str_allocated
[MAX_ARGS
];
2431 void *args
[MAX_ARGS
];
2432 void (*handler_0
)(void);
2433 void (*handler_1
)(void *arg0
);
2434 void (*handler_2
)(void *arg0
, void *arg1
);
2435 void (*handler_3
)(void *arg0
, void *arg1
, void *arg2
);
2436 void (*handler_4
)(void *arg0
, void *arg1
, void *arg2
, void *arg3
);
2437 void (*handler_5
)(void *arg0
, void *arg1
, void *arg2
, void *arg3
,
2439 void (*handler_6
)(void *arg0
, void *arg1
, void *arg2
, void *arg3
,
2440 void *arg4
, void *arg5
);
2441 void (*handler_7
)(void *arg0
, void *arg1
, void *arg2
, void *arg3
,
2442 void *arg4
, void *arg5
, void *arg6
);
2445 term_printf("command='%s'\n", cmdline
);
2448 /* extract the command name */
2451 while (qemu_isspace(*p
))
2456 while (*p
!= '\0' && *p
!= '/' && !qemu_isspace(*p
))
2459 if (len
> sizeof(cmdname
) - 1)
2460 len
= sizeof(cmdname
) - 1;
2461 memcpy(cmdname
, pstart
, len
);
2462 cmdname
[len
] = '\0';
2464 /* find the command */
2465 for(cmd
= term_cmds
; cmd
->name
!= NULL
; cmd
++) {
2466 if (compare_cmd(cmdname
, cmd
->name
))
2469 term_printf("unknown command: '%s'\n", cmdname
);
2473 for(i
= 0; i
< MAX_ARGS
; i
++)
2474 str_allocated
[i
] = NULL
;
2476 /* parse the parameters */
2477 typestr
= cmd
->args_type
;
2492 while (qemu_isspace(*p
))
2494 if (*typestr
== '?') {
2497 /* no optional string: NULL argument */
2502 ret
= get_str(buf
, sizeof(buf
), &p
);
2506 term_printf("%s: filename expected\n", cmdname
);
2509 term_printf("%s: block device name expected\n", cmdname
);
2512 term_printf("%s: string expected\n", cmdname
);
2517 str
= qemu_malloc(strlen(buf
) + 1);
2518 pstrcpy(str
, sizeof(buf
), buf
);
2519 str_allocated
[nb_args
] = str
;
2521 if (nb_args
>= MAX_ARGS
) {
2523 term_printf("%s: too many arguments\n", cmdname
);
2526 args
[nb_args
++] = str
;
2531 int count
, format
, size
;
2533 while (qemu_isspace(*p
))
2539 if (qemu_isdigit(*p
)) {
2541 while (qemu_isdigit(*p
)) {
2542 count
= count
* 10 + (*p
- '0');
2580 if (*p
!= '\0' && !qemu_isspace(*p
)) {
2581 term_printf("invalid char in format: '%c'\n", *p
);
2585 format
= default_fmt_format
;
2586 if (format
!= 'i') {
2587 /* for 'i', not specifying a size gives -1 as size */
2589 size
= default_fmt_size
;
2590 default_fmt_size
= size
;
2592 default_fmt_format
= format
;
2595 format
= default_fmt_format
;
2596 if (format
!= 'i') {
2597 size
= default_fmt_size
;
2602 if (nb_args
+ 3 > MAX_ARGS
)
2604 args
[nb_args
++] = (void*)(long)count
;
2605 args
[nb_args
++] = (void*)(long)format
;
2606 args
[nb_args
++] = (void*)(long)size
;
2614 while (qemu_isspace(*p
))
2616 if (*typestr
== '?' || *typestr
== '.') {
2617 if (*typestr
== '?') {
2625 while (qemu_isspace(*p
))
2633 if (nb_args
>= MAX_ARGS
)
2635 args
[nb_args
++] = (void *)(long)has_arg
;
2637 if (nb_args
>= MAX_ARGS
)
2643 if (get_expr(&val
, &p
))
2647 if (nb_args
>= MAX_ARGS
)
2649 args
[nb_args
++] = (void *)(long)val
;
2651 if ((nb_args
+ 1) >= MAX_ARGS
)
2653 #if TARGET_PHYS_ADDR_BITS > 32
2654 args
[nb_args
++] = (void *)(long)((val
>> 32) & 0xffffffff);
2656 args
[nb_args
++] = (void *)0;
2658 args
[nb_args
++] = (void *)(long)(val
& 0xffffffff);
2670 while (qemu_isspace(*p
))
2676 term_printf("%s: unsupported option -%c\n",
2683 if (nb_args
>= MAX_ARGS
)
2685 args
[nb_args
++] = (void *)(long)has_option
;
2690 term_printf("%s: unknown type '%c'\n", cmdname
, c
);
2694 /* check that all arguments were parsed */
2695 while (qemu_isspace(*p
))
2698 term_printf("%s: extraneous characters at the end of line\n",
2705 handler_0
= cmd
->handler
;
2709 handler_1
= cmd
->handler
;
2713 handler_2
= cmd
->handler
;
2714 handler_2(args
[0], args
[1]);
2717 handler_3
= cmd
->handler
;
2718 handler_3(args
[0], args
[1], args
[2]);
2721 handler_4
= cmd
->handler
;
2722 handler_4(args
[0], args
[1], args
[2], args
[3]);
2725 handler_5
= cmd
->handler
;
2726 handler_5(args
[0], args
[1], args
[2], args
[3], args
[4]);
2729 handler_6
= cmd
->handler
;
2730 handler_6(args
[0], args
[1], args
[2], args
[3], args
[4], args
[5]);
2733 handler_7
= cmd
->handler
;
2734 handler_7(args
[0], args
[1], args
[2], args
[3], args
[4], args
[5], args
[6]);
2737 term_printf("unsupported number of arguments: %d\n", nb_args
);
2741 for(i
= 0; i
< MAX_ARGS
; i
++)
2742 qemu_free(str_allocated
[i
]);
2746 static void cmd_completion(const char *name
, const char *list
)
2748 const char *p
, *pstart
;
2757 p
= pstart
+ strlen(pstart
);
2759 if (len
> sizeof(cmd
) - 2)
2760 len
= sizeof(cmd
) - 2;
2761 memcpy(cmd
, pstart
, len
);
2763 if (name
[0] == '\0' || !strncmp(name
, cmd
, strlen(name
))) {
2764 add_completion(cmd
);
2772 static void file_completion(const char *input
)
2777 char file
[1024], file_prefix
[1024];
2781 p
= strrchr(input
, '/');
2784 pstrcpy(file_prefix
, sizeof(file_prefix
), input
);
2785 pstrcpy(path
, sizeof(path
), ".");
2787 input_path_len
= p
- input
+ 1;
2788 memcpy(path
, input
, input_path_len
);
2789 if (input_path_len
> sizeof(path
) - 1)
2790 input_path_len
= sizeof(path
) - 1;
2791 path
[input_path_len
] = '\0';
2792 pstrcpy(file_prefix
, sizeof(file_prefix
), p
+ 1);
2794 #ifdef DEBUG_COMPLETION
2795 term_printf("input='%s' path='%s' prefix='%s'\n", input
, path
, file_prefix
);
2797 ffs
= opendir(path
);
2805 if (strstart(d
->d_name
, file_prefix
, NULL
)) {
2806 memcpy(file
, input
, input_path_len
);
2807 if (input_path_len
< sizeof(file
))
2808 pstrcpy(file
+ input_path_len
, sizeof(file
) - input_path_len
,
2810 /* stat the file to find out if it's a directory.
2811 * In that case add a slash to speed up typing long paths
2814 if(S_ISDIR(sb
.st_mode
))
2815 pstrcat(file
, sizeof(file
), "/");
2816 add_completion(file
);
2822 static void block_completion_it(void *opaque
, BlockDriverState
*bs
)
2824 const char *name
= bdrv_get_device_name(bs
);
2825 const char *input
= opaque
;
2827 if (input
[0] == '\0' ||
2828 !strncmp(name
, (char *)input
, strlen(input
))) {
2829 add_completion(name
);
2833 /* NOTE: this parser is an approximate form of the real command parser */
2834 static void parse_cmdline(const char *cmdline
,
2835 int *pnb_args
, char **args
)
2844 while (qemu_isspace(*p
))
2848 if (nb_args
>= MAX_ARGS
)
2850 ret
= get_str(buf
, sizeof(buf
), &p
);
2851 args
[nb_args
] = qemu_strdup(buf
);
2856 *pnb_args
= nb_args
;
2859 void readline_find_completion(const char *cmdline
)
2861 const char *cmdname
;
2862 char *args
[MAX_ARGS
];
2863 int nb_args
, i
, len
;
2864 const char *ptype
, *str
;
2865 const term_cmd_t
*cmd
;
2868 parse_cmdline(cmdline
, &nb_args
, args
);
2869 #ifdef DEBUG_COMPLETION
2870 for(i
= 0; i
< nb_args
; i
++) {
2871 term_printf("arg%d = '%s'\n", i
, (char *)args
[i
]);
2875 /* if the line ends with a space, it means we want to complete the
2877 len
= strlen(cmdline
);
2878 if (len
> 0 && qemu_isspace(cmdline
[len
- 1])) {
2879 if (nb_args
>= MAX_ARGS
)
2881 args
[nb_args
++] = qemu_strdup("");
2884 /* command completion */
2889 completion_index
= strlen(cmdname
);
2890 for(cmd
= term_cmds
; cmd
->name
!= NULL
; cmd
++) {
2891 cmd_completion(cmdname
, cmd
->name
);
2894 /* find the command */
2895 for(cmd
= term_cmds
; cmd
->name
!= NULL
; cmd
++) {
2896 if (compare_cmd(args
[0], cmd
->name
))
2901 ptype
= cmd
->args_type
;
2902 for(i
= 0; i
< nb_args
- 2; i
++) {
2903 if (*ptype
!= '\0') {
2905 while (*ptype
== '?')
2909 str
= args
[nb_args
- 1];
2912 /* file completion */
2913 completion_index
= strlen(str
);
2914 file_completion(str
);
2917 /* block device name completion */
2918 completion_index
= strlen(str
);
2919 bdrv_iterate(block_completion_it
, (void *)str
);
2922 /* XXX: more generic ? */
2923 if (!strcmp(cmd
->name
, "info")) {
2924 completion_index
= strlen(str
);
2925 for(cmd
= info_cmds
; cmd
->name
!= NULL
; cmd
++) {
2926 cmd_completion(str
, cmd
->name
);
2928 } else if (!strcmp(cmd
->name
, "sendkey")) {
2929 completion_index
= strlen(str
);
2930 for(key
= key_defs
; key
->name
!= NULL
; key
++) {
2931 cmd_completion(str
, key
->name
);
2939 for(i
= 0; i
< nb_args
; i
++)
2943 static int term_can_read(void *opaque
)
2948 static void term_read(void *opaque
, const uint8_t *buf
, int size
)
2951 for(i
= 0; i
< size
; i
++)
2952 readline_handle_byte(buf
[i
]);
2955 static int monitor_suspended
;
2957 static void monitor_handle_command1(void *opaque
, const char *cmdline
)
2959 monitor_handle_command(cmdline
);
2960 if (!monitor_suspended
)
2961 monitor_start_input();
2963 monitor_suspended
= 2;
2966 void monitor_suspend(void)
2968 monitor_suspended
= 1;
2971 void monitor_resume(void)
2973 if (monitor_suspended
== 2)
2974 monitor_start_input();
2975 monitor_suspended
= 0;
2978 static void monitor_start_input(void)
2980 readline_start("(qemu) ", 0, monitor_handle_command1
, NULL
);
2983 static void term_event(void *opaque
, int event
)
2985 if (event
!= CHR_EVENT_RESET
)
2989 term_printf("QEMU %s monitor - type 'help' for more information\n",
2991 monitor_start_input();
2994 static int is_first_init
= 1;
2996 void monitor_init(CharDriverState
*hd
, int show_banner
)
3000 if (is_first_init
) {
3001 key_timer
= qemu_new_timer(vm_clock
, release_keys
, NULL
);
3004 for (i
= 0; i
< MAX_MON
; i
++) {
3005 monitor_hd
[i
] = NULL
;
3009 for (i
= 0; i
< MAX_MON
; i
++) {
3010 if (monitor_hd
[i
] == NULL
) {
3016 hide_banner
= !show_banner
;
3018 qemu_chr_add_handlers(hd
, term_can_read
, term_read
, term_event
, NULL
);
3020 readline_start("", 0, monitor_handle_command1
, NULL
);
3023 /* XXX: use threads ? */
3024 /* modal monitor readline */
3025 static int monitor_readline_started
;
3026 static char *monitor_readline_buf
;
3027 static int monitor_readline_buf_size
;
3029 static void monitor_readline_cb(void *opaque
, const char *input
)
3031 pstrcpy(monitor_readline_buf
, monitor_readline_buf_size
, input
);
3032 monitor_readline_started
= 0;
3035 static void monitor_readline(const char *prompt
, int is_password
,
3036 char *buf
, int buf_size
)
3039 int old_focus
[MAX_MON
];
3042 for (i
= 0; i
< MAX_MON
; i
++) {
3044 if (monitor_hd
[i
]) {
3045 old_focus
[i
] = monitor_hd
[i
]->focus
;
3046 monitor_hd
[i
]->focus
= 0;
3047 qemu_chr_send_event(monitor_hd
[i
], CHR_EVENT_FOCUS
);
3052 readline_start(prompt
, is_password
, monitor_readline_cb
, NULL
);
3053 monitor_readline_buf
= buf
;
3054 monitor_readline_buf_size
= buf_size
;
3055 monitor_readline_started
= 1;
3056 while (monitor_readline_started
) {
3059 /* restore original focus */
3061 for (i
= 0; i
< MAX_MON
; i
++)
3063 monitor_hd
[i
]->focus
= old_focus
[i
];
3067 int monitor_read_bdrv_key(BlockDriverState
*bs
)
3072 if (!bdrv_is_encrypted(bs
))
3075 term_printf("%s (%s) is encrypted.\n", bdrv_get_device_name(bs
),
3076 bdrv_get_encrypted_filename(bs
));
3077 for(i
= 0; i
< 3; i
++) {
3078 monitor_readline("Password: ", 1, password
, sizeof(password
));
3079 if (bdrv_set_key(bs
, password
) == 0)
3081 term_printf("invalid password\n");