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"
37 #include "migration.h"
41 #ifdef CONFIG_PROFILER
42 #include "qemu-timer.h" /* for ticks_per_sec */
46 //#define DEBUG_COMPLETION
49 #define offsetof(type, field) ((size_t) &((type *)0)->field)
56 * 'B' block device name
57 * 's' string (accept optional quote)
59 * 'l' target long (32 or 64 bit)
60 * '/' optional gdb-like print format (like "/10x")
62 * '?' optional type (for 'F', 's' and 'i')
66 typedef struct term_cmd_t
{
68 const char *args_type
;
75 static CharDriverState
*monitor_hd
[MAX_MON
];
76 static int hide_banner
;
78 static term_cmd_t term_cmds
[];
79 static term_cmd_t info_cmds
[];
81 static uint8_t term_outbuf
[1024];
82 static int term_outbuf_index
;
84 static void monitor_start_input(void);
86 CPUState
*mon_cpu
= NULL
;
91 if (term_outbuf_index
> 0) {
92 for (i
= 0; i
< MAX_MON
; i
++)
93 if (monitor_hd
[i
] && monitor_hd
[i
]->focus
== 0)
94 qemu_chr_write(monitor_hd
[i
], term_outbuf
, term_outbuf_index
);
95 term_outbuf_index
= 0;
99 /* flush at every end of line or if the buffer is full */
100 void term_puts(const char *str
)
108 term_outbuf
[term_outbuf_index
++] = '\r';
109 term_outbuf
[term_outbuf_index
++] = c
;
110 if (term_outbuf_index
>= (sizeof(term_outbuf
) - 1) ||
116 void term_vprintf(const char *fmt
, va_list ap
)
119 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
123 void term_printf(const char *fmt
, ...)
127 term_vprintf(fmt
, ap
);
131 void term_print_filename(const char *filename
)
135 for (i
= 0; filename
[i
]; i
++) {
136 switch (filename
[i
]) {
140 term_printf("\\%c", filename
[i
]);
152 term_printf("%c", filename
[i
]);
158 static int monitor_fprintf(FILE *stream
, const char *fmt
, ...)
162 term_vprintf(fmt
, ap
);
167 static int compare_cmd(const char *name
, const char *list
)
169 const char *p
, *pstart
;
177 p
= pstart
+ strlen(pstart
);
178 if ((p
- pstart
) == len
&& !memcmp(pstart
, name
, len
))
187 static void help_cmd1(term_cmd_t
*cmds
, const char *prefix
, const char *name
)
191 for(cmd
= cmds
; cmd
->name
!= NULL
; cmd
++) {
192 if (!name
|| !strcmp(name
, cmd
->name
))
193 term_printf("%s%s %s -- %s\n", prefix
, cmd
->name
, cmd
->params
, cmd
->help
);
197 static void help_cmd(const char *name
)
199 if (name
&& !strcmp(name
, "info")) {
200 help_cmd1(info_cmds
, "info ", NULL
);
202 help_cmd1(term_cmds
, "", name
);
203 if (name
&& !strcmp(name
, "log")) {
205 term_printf("Log items (comma separated):\n");
206 term_printf("%-10s %s\n", "none", "remove all logs");
207 for(item
= cpu_log_items
; item
->mask
!= 0; item
++) {
208 term_printf("%-10s %s\n", item
->name
, item
->help
);
214 static void do_help(const char *name
)
219 static void do_commit(const char *device
)
223 all_devices
= !strcmp(device
, "all");
224 for (i
= 0; i
< nb_drives
; i
++) {
226 !strcmp(bdrv_get_device_name(drives_table
[i
].bdrv
), device
))
227 bdrv_commit(drives_table
[i
].bdrv
);
231 static void do_info(const char *item
)
237 for(cmd
= info_cmds
; cmd
->name
!= NULL
; cmd
++) {
238 if (compare_cmd(item
, cmd
->name
))
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 static void do_info_block(void)
264 static void do_info_blockstats(void)
269 /* get the current CPU defined by the user */
270 static int mon_set_cpu(int cpu_index
)
274 for(env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
275 if (env
->cpu_index
== cpu_index
) {
283 static CPUState
*mon_get_cpu(void)
290 kvm_save_registers(mon_cpu
);
295 static void do_info_registers(void)
302 cpu_dump_state(env
, NULL
, monitor_fprintf
,
305 cpu_dump_state(env
, NULL
, monitor_fprintf
,
310 static void do_info_cpus(void)
314 /* just to set the default cpu if not already done */
317 for(env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
318 term_printf("%c CPU #%d:",
319 (env
== mon_cpu
) ? '*' : ' ',
321 #if defined(TARGET_I386)
322 term_printf(" pc=0x" TARGET_FMT_lx
, env
->eip
+ env
->segs
[R_CS
].base
);
323 if (env
->hflags
& HF_HALTED_MASK
)
324 term_printf(" (halted)");
325 #elif defined(TARGET_PPC)
326 term_printf(" nip=0x" TARGET_FMT_lx
, env
->nip
);
328 term_printf(" (halted)");
329 #elif defined(TARGET_SPARC)
330 term_printf(" pc=0x" TARGET_FMT_lx
" npc=0x" TARGET_FMT_lx
, env
->pc
, env
->npc
);
332 term_printf(" (halted)");
333 #elif defined(TARGET_MIPS)
334 term_printf(" PC=0x" TARGET_FMT_lx
, env
->PC
[env
->current_tc
]);
336 term_printf(" (halted)");
338 term_printf(" thread_id=%d", env
->thread_id
);
343 static void do_cpu_set(int index
)
345 if (mon_set_cpu(index
) < 0)
346 term_printf("Invalid CPU index\n");
349 static void do_cpu_set_nr(int value
, const char *status
)
353 if (!strcmp(status
, "online"))
355 else if (!strcmp(status
, "offline"))
358 term_printf("invalid status: %s\n", status
);
361 #if defined(TARGET_I386) || defined(TARGET_X86_64)
362 qemu_system_cpu_hot_add(value
, state
);
366 static void do_info_jit(void)
368 dump_exec_info(NULL
, monitor_fprintf
);
371 static void do_info_history (void)
378 str
= readline_get_history(i
);
381 term_printf("%d: '%s'\n", i
, str
);
386 #if defined(TARGET_PPC)
387 /* XXX: not implemented in other targets */
388 static void do_info_cpu_stats (void)
393 cpu_dump_statistics(env
, NULL
, &monitor_fprintf
, 0);
397 static void do_quit(void)
402 static int eject_device(BlockDriverState
*bs
, int force
)
404 if (bdrv_is_inserted(bs
)) {
406 if (!bdrv_is_removable(bs
)) {
407 term_printf("device is not removable\n");
410 if (bdrv_is_locked(bs
)) {
411 term_printf("device is locked\n");
420 static void do_eject(int force
, const char *filename
)
422 BlockDriverState
*bs
;
424 bs
= bdrv_find(filename
);
426 term_printf("device not found\n");
429 eject_device(bs
, force
);
432 static void do_change_block(const char *device
, const char *filename
)
434 BlockDriverState
*bs
;
436 bs
= bdrv_find(device
);
438 term_printf("device not found\n");
441 if (eject_device(bs
, 0) < 0)
443 bdrv_open(bs
, filename
, 0);
444 qemu_key_check(bs
, filename
);
447 static void do_change_vnc(const char *target
)
449 if (strcmp(target
, "passwd") == 0 ||
450 strcmp(target
, "password") == 0) {
452 monitor_readline("Password: ", 1, password
, sizeof(password
)-1);
453 password
[sizeof(password
)-1] = '\0';
454 if (vnc_display_password(NULL
, password
) < 0)
455 term_printf("could not set VNC server password\n");
457 if (vnc_display_open(NULL
, target
) < 0)
458 term_printf("could not start VNC server on %s\n", target
);
462 static void do_change(const char *device
, const char *target
)
464 if (strcmp(device
, "vnc") == 0) {
465 do_change_vnc(target
);
467 do_change_block(device
, target
);
471 static void do_screen_dump(const char *filename
)
473 vga_hw_screen_dump(filename
);
476 static void do_logfile(const char *filename
)
478 cpu_set_log_filename(filename
);
481 static void do_log(const char *items
)
485 if (!strcmp(items
, "none")) {
488 mask
= cpu_str_to_log_mask(items
);
497 static void do_stop(void)
499 vm_stop(EXCP_INTERRUPT
);
502 static void do_cont(void)
507 #ifdef CONFIG_GDBSTUB
508 static void do_gdbserver(const char *port
)
511 port
= DEFAULT_GDBSTUB_PORT
;
512 if (gdbserver_start(port
) < 0) {
513 qemu_printf("Could not open gdbserver socket on port '%s'\n", port
);
515 qemu_printf("Waiting gdb connection on port '%s'\n", port
);
520 static void term_printc(int c
)
537 if (c
>= 32 && c
<= 126) {
538 term_printf("%c", c
);
540 term_printf("\\x%02x", c
);
547 static void memory_dump(int count
, int format
, int wsize
,
548 target_phys_addr_t addr
, int is_physical
)
551 int nb_per_line
, l
, line_size
, i
, max_digits
, len
;
559 if (!env
&& !is_physical
)
564 } else if (wsize
== 4) {
567 /* as default we use the current CS size */
571 if ((env
->efer
& MSR_EFER_LMA
) &&
572 (env
->segs
[R_CS
].flags
& DESC_L_MASK
))
576 if (!(env
->segs
[R_CS
].flags
& DESC_B_MASK
))
581 monitor_disas(env
, addr
, count
, is_physical
, flags
);
590 nb_per_line
= line_size
/ wsize
;
595 max_digits
= (wsize
* 8 + 2) / 3;
599 max_digits
= (wsize
* 8) / 4;
603 max_digits
= (wsize
* 8 * 10 + 32) / 33;
612 term_printf(TARGET_FMT_plx
":", addr
);
614 term_printf(TARGET_FMT_lx
":", (target_ulong
)addr
);
619 cpu_physical_memory_rw(addr
, buf
, l
, 0);
624 cpu_memory_rw_debug(env
, addr
, buf
, l
, 0);
631 v
= ldub_raw(buf
+ i
);
634 v
= lduw_raw(buf
+ i
);
637 v
= (uint32_t)ldl_raw(buf
+ i
);
640 v
= ldq_raw(buf
+ i
);
646 term_printf("%#*" PRIo64
, max_digits
, v
);
649 term_printf("0x%0*" PRIx64
, max_digits
, v
);
652 term_printf("%*" PRIu64
, max_digits
, v
);
655 term_printf("%*" PRId64
, max_digits
, v
);
669 #if TARGET_LONG_BITS == 64
670 #define GET_TLONG(h, l) (((uint64_t)(h) << 32) | (l))
672 #define GET_TLONG(h, l) (l)
675 static void do_memory_dump(int count
, int format
, int size
,
676 uint32_t addrh
, uint32_t addrl
)
678 target_long addr
= GET_TLONG(addrh
, addrl
);
679 memory_dump(count
, format
, size
, addr
, 0);
682 #if TARGET_PHYS_ADDR_BITS > 32
683 #define GET_TPHYSADDR(h, l) (((uint64_t)(h) << 32) | (l))
685 #define GET_TPHYSADDR(h, l) (l)
688 static void do_physical_memory_dump(int count
, int format
, int size
,
689 uint32_t addrh
, uint32_t addrl
)
692 target_phys_addr_t addr
= GET_TPHYSADDR(addrh
, addrl
);
693 memory_dump(count
, format
, size
, addr
, 1);
696 static void do_print(int count
, int format
, int size
, unsigned int valh
, unsigned int vall
)
698 target_phys_addr_t val
= GET_TPHYSADDR(valh
, vall
);
699 #if TARGET_PHYS_ADDR_BITS == 32
702 term_printf("%#o", val
);
705 term_printf("%#x", val
);
708 term_printf("%u", val
);
712 term_printf("%d", val
);
721 term_printf("%#" PRIo64
, val
);
724 term_printf("%#" PRIx64
, val
);
727 term_printf("%" PRIu64
, val
);
731 term_printf("%" PRId64
, val
);
741 static void do_memory_save(unsigned int valh
, unsigned int vall
,
742 uint32_t size
, const char *filename
)
745 target_long addr
= GET_TLONG(valh
, vall
);
754 f
= fopen(filename
, "wb");
756 term_printf("could not open '%s'\n", filename
);
763 cpu_memory_rw_debug(env
, addr
, buf
, l
, 0);
764 fwrite(buf
, 1, l
, f
);
771 static void do_sum(uint32_t start
, uint32_t size
)
778 for(addr
= start
; addr
< (start
+ size
); addr
++) {
779 cpu_physical_memory_rw(addr
, buf
, 1, 0);
780 /* BSD sum algorithm ('sum' Unix command) */
781 sum
= (sum
>> 1) | (sum
<< 15);
784 term_printf("%05d\n", sum
);
792 static const KeyDef key_defs
[] = {
817 { 0x0e, "backspace" },
851 { 0x37, "asterisk" },
854 { 0x3a, "caps_lock" },
865 { 0x45, "num_lock" },
866 { 0x46, "scroll_lock" },
868 { 0xb5, "kp_divide" },
869 { 0x37, "kp_multiply" },
870 { 0x4a, "kp_subtract" },
872 { 0x9c, "kp_enter" },
873 { 0x53, "kp_decimal" },
908 static int get_keycode(const char *key
)
914 for(p
= key_defs
; p
->name
!= NULL
; p
++) {
915 if (!strcmp(key
, p
->name
))
918 if (strstart(key
, "0x", NULL
)) {
919 ret
= strtoul(key
, &endp
, 0);
920 if (*endp
== '\0' && ret
>= 0x01 && ret
<= 0xff)
926 static void do_send_key(const char *string
)
929 uint8_t keycodes
[16];
931 int nb_keycodes
, keycode
, i
;
937 while (*p
!= '\0' && *p
!= '-') {
938 if ((q
- keybuf
) < sizeof(keybuf
) - 1) {
944 keycode
= get_keycode(keybuf
);
946 term_printf("unknown key: '%s'\n", keybuf
);
949 keycodes
[nb_keycodes
++] = keycode
;
954 /* key down events */
955 for(i
= 0; i
< nb_keycodes
; i
++) {
956 keycode
= keycodes
[i
];
958 kbd_put_keycode(0xe0);
959 kbd_put_keycode(keycode
& 0x7f);
962 for(i
= nb_keycodes
- 1; i
>= 0; i
--) {
963 keycode
= keycodes
[i
];
965 kbd_put_keycode(0xe0);
966 kbd_put_keycode(keycode
| 0x80);
970 static int mouse_button_state
;
972 static void do_mouse_move(const char *dx_str
, const char *dy_str
,
976 dx
= strtol(dx_str
, NULL
, 0);
977 dy
= strtol(dy_str
, NULL
, 0);
980 dz
= strtol(dz_str
, NULL
, 0);
981 kbd_mouse_event(dx
, dy
, dz
, mouse_button_state
);
984 static void do_mouse_button(int button_state
)
986 mouse_button_state
= button_state
;
987 kbd_mouse_event(0, 0, 0, mouse_button_state
);
990 static void do_ioport_read(int count
, int format
, int size
, int addr
, int has_index
, int index
)
996 cpu_outb(NULL
, addr
& 0xffff, index
& 0xff);
1004 val
= cpu_inb(NULL
, addr
);
1008 val
= cpu_inw(NULL
, addr
);
1012 val
= cpu_inl(NULL
, addr
);
1016 term_printf("port%c[0x%04x] = %#0*x\n",
1017 suffix
, addr
, size
* 2, val
);
1020 static void do_system_reset(void)
1022 qemu_system_reset_request();
1025 static void do_system_powerdown(void)
1027 qemu_system_powerdown_request();
1030 #if defined(TARGET_I386)
1031 static void print_pte(uint32_t addr
, uint32_t pte
, uint32_t mask
)
1033 term_printf("%08x: %08x %c%c%c%c%c%c%c%c\n",
1036 pte
& PG_GLOBAL_MASK
? 'G' : '-',
1037 pte
& PG_PSE_MASK
? 'P' : '-',
1038 pte
& PG_DIRTY_MASK
? 'D' : '-',
1039 pte
& PG_ACCESSED_MASK
? 'A' : '-',
1040 pte
& PG_PCD_MASK
? 'C' : '-',
1041 pte
& PG_PWT_MASK
? 'T' : '-',
1042 pte
& PG_USER_MASK
? 'U' : '-',
1043 pte
& PG_RW_MASK
? 'W' : '-');
1046 static void tlb_info(void)
1050 uint32_t pgd
, pde
, pte
;
1052 env
= mon_get_cpu();
1056 if (!(env
->cr
[0] & CR0_PG_MASK
)) {
1057 term_printf("PG disabled\n");
1060 pgd
= env
->cr
[3] & ~0xfff;
1061 for(l1
= 0; l1
< 1024; l1
++) {
1062 cpu_physical_memory_read(pgd
+ l1
* 4, (uint8_t *)&pde
, 4);
1063 pde
= le32_to_cpu(pde
);
1064 if (pde
& PG_PRESENT_MASK
) {
1065 if ((pde
& PG_PSE_MASK
) && (env
->cr
[4] & CR4_PSE_MASK
)) {
1066 print_pte((l1
<< 22), pde
, ~((1 << 20) - 1));
1068 for(l2
= 0; l2
< 1024; l2
++) {
1069 cpu_physical_memory_read((pde
& ~0xfff) + l2
* 4,
1070 (uint8_t *)&pte
, 4);
1071 pte
= le32_to_cpu(pte
);
1072 if (pte
& PG_PRESENT_MASK
) {
1073 print_pte((l1
<< 22) + (l2
<< 12),
1083 static void mem_print(uint32_t *pstart
, int *plast_prot
,
1084 uint32_t end
, int prot
)
1087 prot1
= *plast_prot
;
1088 if (prot
!= prot1
) {
1089 if (*pstart
!= -1) {
1090 term_printf("%08x-%08x %08x %c%c%c\n",
1091 *pstart
, end
, end
- *pstart
,
1092 prot1
& PG_USER_MASK
? 'u' : '-',
1094 prot1
& PG_RW_MASK
? 'w' : '-');
1104 static void mem_info(void)
1107 int l1
, l2
, prot
, last_prot
;
1108 uint32_t pgd
, pde
, pte
, start
, end
;
1110 env
= mon_get_cpu();
1114 if (!(env
->cr
[0] & CR0_PG_MASK
)) {
1115 term_printf("PG disabled\n");
1118 pgd
= env
->cr
[3] & ~0xfff;
1121 for(l1
= 0; l1
< 1024; l1
++) {
1122 cpu_physical_memory_read(pgd
+ l1
* 4, (uint8_t *)&pde
, 4);
1123 pde
= le32_to_cpu(pde
);
1125 if (pde
& PG_PRESENT_MASK
) {
1126 if ((pde
& PG_PSE_MASK
) && (env
->cr
[4] & CR4_PSE_MASK
)) {
1127 prot
= pde
& (PG_USER_MASK
| PG_RW_MASK
| PG_PRESENT_MASK
);
1128 mem_print(&start
, &last_prot
, end
, prot
);
1130 for(l2
= 0; l2
< 1024; l2
++) {
1131 cpu_physical_memory_read((pde
& ~0xfff) + l2
* 4,
1132 (uint8_t *)&pte
, 4);
1133 pte
= le32_to_cpu(pte
);
1134 end
= (l1
<< 22) + (l2
<< 12);
1135 if (pte
& PG_PRESENT_MASK
) {
1136 prot
= pte
& (PG_USER_MASK
| PG_RW_MASK
| PG_PRESENT_MASK
);
1140 mem_print(&start
, &last_prot
, end
, prot
);
1145 mem_print(&start
, &last_prot
, end
, prot
);
1151 static void do_info_kqemu(void)
1157 env
= mon_get_cpu();
1159 term_printf("No cpu initialized yet");
1162 val
= env
->kqemu_enabled
;
1163 term_printf("kqemu support: ");
1167 term_printf("disabled\n");
1170 term_printf("enabled for user code\n");
1173 term_printf("enabled for user and kernel code\n");
1177 term_printf("kqemu support: not compiled\n");
1181 #ifdef CONFIG_PROFILER
1185 int64_t kqemu_exec_count
;
1187 int64_t kqemu_ret_int_count
;
1188 int64_t kqemu_ret_excp_count
;
1189 int64_t kqemu_ret_intr_count
;
1191 static void do_info_profile(void)
1197 term_printf("async time %" PRId64
" (%0.3f)\n",
1198 dev_time
, dev_time
/ (double)ticks_per_sec
);
1199 term_printf("qemu time %" PRId64
" (%0.3f)\n",
1200 qemu_time
, qemu_time
/ (double)ticks_per_sec
);
1201 term_printf("kqemu time %" PRId64
" (%0.3f %0.1f%%) count=%" PRId64
" int=%" PRId64
" excp=%" PRId64
" intr=%" PRId64
"\n",
1202 kqemu_time
, kqemu_time
/ (double)ticks_per_sec
,
1203 kqemu_time
/ (double)total
* 100.0,
1205 kqemu_ret_int_count
,
1206 kqemu_ret_excp_count
,
1207 kqemu_ret_intr_count
);
1210 kqemu_exec_count
= 0;
1212 kqemu_ret_int_count
= 0;
1213 kqemu_ret_excp_count
= 0;
1214 kqemu_ret_intr_count
= 0;
1216 kqemu_record_dump();
1220 static void do_info_profile(void)
1222 term_printf("Internal profiler not compiled\n");
1226 /* Capture support */
1227 static LIST_HEAD (capture_list_head
, CaptureState
) capture_head
;
1229 static void do_info_capture (void)
1234 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
1235 term_printf ("[%d]: ", i
);
1236 s
->ops
.info (s
->opaque
);
1240 static void do_stop_capture (int n
)
1245 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
1247 s
->ops
.destroy (s
->opaque
);
1248 LIST_REMOVE (s
, entries
);
1256 int wav_start_capture (CaptureState
*s
, const char *path
, int freq
,
1257 int bits
, int nchannels
);
1259 static void do_wav_capture (const char *path
,
1260 int has_freq
, int freq
,
1261 int has_bits
, int bits
,
1262 int has_channels
, int nchannels
)
1266 s
= qemu_mallocz (sizeof (*s
));
1268 term_printf ("Not enough memory to add wave capture\n");
1272 freq
= has_freq
? freq
: 44100;
1273 bits
= has_bits
? bits
: 16;
1274 nchannels
= has_channels
? nchannels
: 2;
1276 if (wav_start_capture (s
, path
, freq
, bits
, nchannels
)) {
1277 term_printf ("Faied to add wave capture\n");
1280 LIST_INSERT_HEAD (&capture_head
, s
, entries
);
1284 static term_cmd_t term_cmds
[] = {
1285 { "help|?", "s?", do_help
,
1286 "[cmd]", "show the help" },
1287 { "commit", "s", do_commit
,
1288 "device|all", "commit changes to the disk images (if -snapshot is used) or backing files" },
1289 { "info", "s?", do_info
,
1290 "subcommand", "show various information about the system state" },
1291 { "q|quit", "", do_quit
,
1292 "", "quit the emulator" },
1293 { "eject", "-fB", do_eject
,
1294 "[-f] device", "eject a removable medium (use -f to force it)" },
1295 { "change", "BF", do_change
,
1296 "device filename", "change a removable medium" },
1297 { "screendump", "F", do_screen_dump
,
1298 "filename", "save screen into PPM image 'filename'" },
1299 { "logfile", "s", do_logfile
,
1300 "filename", "output logs to 'filename'" },
1301 { "log", "s", do_log
,
1302 "item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" },
1303 { "savevm", "s?", do_savevm
,
1304 "tag|id", "save a VM snapshot. If no tag or id are provided, a new snapshot is created" },
1305 { "loadvm", "s", do_loadvm
,
1306 "tag|id", "restore a VM snapshot from its tag or id" },
1307 { "delvm", "s", do_delvm
,
1308 "tag|id", "delete a VM snapshot from its tag or id" },
1309 { "stop", "", do_stop
,
1310 "", "stop emulation", },
1311 { "c|cont", "", do_cont
,
1312 "", "resume emulation", },
1313 #ifdef CONFIG_GDBSTUB
1314 { "gdbserver", "s?", do_gdbserver
,
1315 "[port]", "start gdbserver session (default port=1234)", },
1317 { "x", "/l", do_memory_dump
,
1318 "/fmt addr", "virtual memory dump starting at 'addr'", },
1319 { "xp", "/l", do_physical_memory_dump
,
1320 "/fmt addr", "physical memory dump starting at 'addr'", },
1321 { "p|print", "/l", do_print
,
1322 "/fmt expr", "print expression value (use $reg for CPU register access)", },
1323 { "i", "/ii.", do_ioport_read
,
1324 "/fmt addr", "I/O port read" },
1326 { "sendkey", "s", do_send_key
,
1327 "keys", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1')" },
1328 { "system_reset", "", do_system_reset
,
1329 "", "reset the system" },
1330 { "system_powerdown", "", do_system_powerdown
,
1331 "", "send system power down event" },
1332 { "sum", "ii", do_sum
,
1333 "addr size", "compute the checksum of a memory region" },
1334 { "usb_add", "s", do_usb_add
,
1335 "device", "add USB device (e.g. 'host:bus.addr' or 'host:vendor_id:product_id')" },
1336 { "usb_del", "s", do_usb_del
,
1337 "device", "remove USB device 'bus.addr'" },
1338 { "cpu", "i", do_cpu_set
,
1339 "index", "set the default CPU" },
1340 { "mouse_move", "sss?", do_mouse_move
,
1341 "dx dy [dz]", "send mouse move events" },
1342 { "mouse_button", "i", do_mouse_button
,
1343 "state", "change mouse button state (1=L, 2=M, 4=R)" },
1344 { "mouse_set", "i", do_mouse_set
,
1345 "index", "set which mouse device receives events" },
1347 { "wavcapture", "si?i?i?", do_wav_capture
,
1348 "path [frequency bits channels]",
1349 "capture audio to a wave file (default frequency=44100 bits=16 channels=2)" },
1351 { "stopcapture", "i", do_stop_capture
,
1352 "capture index", "stop capture" },
1353 { "memsave", "lis", do_memory_save
,
1354 "addr size file", "save to disk virtual memory dump starting at 'addr' of size 'size'", },
1355 { "migrate", "-ds", do_migrate
,
1356 "[-d] command", "migrate the VM using command (use -d to not wait for command to complete)" },
1357 { "migrate_cancel", "", do_migrate_cancel
,
1358 "", "cancel the current VM migration" },
1359 { "migrate_set_speed", "s", do_migrate_set_speed
,
1360 "value", "set maximum speed (in bytes) for migrations" },
1361 { "cpu_set", "is", do_cpu_set_nr
, "cpu [online|offline]", "change cpu state" },
1362 { "drive_add", "iss", drive_hot_add
, "pcibus pcidevfn [file=file][,if=type][,bus=n]\n"
1363 "[,unit=m][,media=d][index=i]\n"
1364 "[,cyls=c,heads=h,secs=s[,trans=t]]\n"
1365 "[snapshot=on|off][,cache=on|off]",
1366 "add drive to PCI storage controller" },
1367 { "pci_add", "iss", device_hot_add
, "bus nic|storage [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]...", "hot-add PCI device" },
1371 static term_cmd_t info_cmds
[] = {
1372 { "version", "", do_info_version
,
1373 "", "show the version of qemu" },
1374 { "network", "", do_info_network
,
1375 "", "show the network state" },
1376 { "block", "", do_info_block
,
1377 "", "show the block devices" },
1378 { "blockstats", "", do_info_blockstats
,
1379 "", "show block device statistics" },
1380 { "registers", "", do_info_registers
,
1381 "", "show the cpu registers" },
1382 { "cpus", "", do_info_cpus
,
1383 "", "show infos for each CPU" },
1384 { "history", "", do_info_history
,
1385 "", "show the command line history", },
1386 { "irq", "", irq_info
,
1387 "", "show the interrupts statistics (if available)", },
1388 { "pic", "", pic_info
,
1389 "", "show i8259 (PIC) state", },
1390 { "pci", "", pci_info
,
1391 "", "show PCI info", },
1392 #if defined(TARGET_I386)
1393 { "tlb", "", tlb_info
,
1394 "", "show virtual to physical memory mappings", },
1395 { "mem", "", mem_info
,
1396 "", "show the active virtual memory mappings", },
1398 { "jit", "", do_info_jit
,
1399 "", "show dynamic compiler info", },
1400 { "kqemu", "", do_info_kqemu
,
1401 "", "show kqemu information", },
1402 { "usb", "", usb_info
,
1403 "", "show guest USB devices", },
1404 { "usbhost", "", usb_host_info
,
1405 "", "show host USB devices", },
1406 { "profile", "", do_info_profile
,
1407 "", "show profiling information", },
1408 { "capture", "", do_info_capture
,
1409 "", "show capture information" },
1410 { "snapshots", "", do_info_snapshots
,
1411 "", "show the currently saved VM snapshots" },
1412 { "pcmcia", "", pcmcia_info
,
1413 "", "show guest PCMCIA status" },
1414 { "mice", "", do_info_mice
,
1415 "", "show which guest mouse is receiving events" },
1416 { "vnc", "", do_info_vnc
,
1417 "", "show the vnc server status"},
1418 { "name", "", do_info_name
,
1419 "", "show the current VM name" },
1420 #if defined(TARGET_PPC)
1421 { "cpustats", "", do_info_cpu_stats
,
1422 "", "show CPU statistics", },
1424 #if defined(CONFIG_SLIRP)
1425 { "slirp", "", do_info_slirp
,
1426 "", "show SLIRP statistics", },
1428 { "migration", "", do_info_migration
,
1429 "", "show migration information" },
1433 /*******************************************************************/
1435 static const char *pch
;
1436 static jmp_buf expr_env
;
1441 typedef struct MonitorDef
{
1444 target_long (*get_value
)(struct MonitorDef
*md
, int val
);
1448 #if defined(TARGET_I386)
1449 static target_long
monitor_get_pc (struct MonitorDef
*md
, int val
)
1451 CPUState
*env
= mon_get_cpu();
1454 return env
->eip
+ env
->segs
[R_CS
].base
;
1458 #if defined(TARGET_PPC)
1459 static target_long
monitor_get_ccr (struct MonitorDef
*md
, int val
)
1461 CPUState
*env
= mon_get_cpu();
1469 for (i
= 0; i
< 8; i
++)
1470 u
|= env
->crf
[i
] << (32 - (4 * i
));
1475 static target_long
monitor_get_msr (struct MonitorDef
*md
, int val
)
1477 CPUState
*env
= mon_get_cpu();
1483 static target_long
monitor_get_xer (struct MonitorDef
*md
, int val
)
1485 CPUState
*env
= mon_get_cpu();
1488 return ppc_load_xer(env
);
1491 static target_long
monitor_get_decr (struct MonitorDef
*md
, int val
)
1493 CPUState
*env
= mon_get_cpu();
1496 return cpu_ppc_load_decr(env
);
1499 static target_long
monitor_get_tbu (struct MonitorDef
*md
, int val
)
1501 CPUState
*env
= mon_get_cpu();
1504 return cpu_ppc_load_tbu(env
);
1507 static target_long
monitor_get_tbl (struct MonitorDef
*md
, int val
)
1509 CPUState
*env
= mon_get_cpu();
1512 return cpu_ppc_load_tbl(env
);
1516 #if defined(TARGET_SPARC)
1517 #ifndef TARGET_SPARC64
1518 static target_long
monitor_get_psr (struct MonitorDef
*md
, int val
)
1520 CPUState
*env
= mon_get_cpu();
1523 return GET_PSR(env
);
1527 static target_long
monitor_get_reg(struct MonitorDef
*md
, int val
)
1529 CPUState
*env
= mon_get_cpu();
1532 return env
->regwptr
[val
];
1536 static MonitorDef monitor_defs
[] = {
1539 #define SEG(name, seg) \
1540 { name, offsetof(CPUState, segs[seg].selector), NULL, MD_I32 },\
1541 { name ".base", offsetof(CPUState, segs[seg].base) },\
1542 { name ".limit", offsetof(CPUState, segs[seg].limit), NULL, MD_I32 },
1544 { "eax", offsetof(CPUState
, regs
[0]) },
1545 { "ecx", offsetof(CPUState
, regs
[1]) },
1546 { "edx", offsetof(CPUState
, regs
[2]) },
1547 { "ebx", offsetof(CPUState
, regs
[3]) },
1548 { "esp|sp", offsetof(CPUState
, regs
[4]) },
1549 { "ebp|fp", offsetof(CPUState
, regs
[5]) },
1550 { "esi", offsetof(CPUState
, regs
[6]) },
1551 { "edi", offsetof(CPUState
, regs
[7]) },
1552 #ifdef TARGET_X86_64
1553 { "r8", offsetof(CPUState
, regs
[8]) },
1554 { "r9", offsetof(CPUState
, regs
[9]) },
1555 { "r10", offsetof(CPUState
, regs
[10]) },
1556 { "r11", offsetof(CPUState
, regs
[11]) },
1557 { "r12", offsetof(CPUState
, regs
[12]) },
1558 { "r13", offsetof(CPUState
, regs
[13]) },
1559 { "r14", offsetof(CPUState
, regs
[14]) },
1560 { "r15", offsetof(CPUState
, regs
[15]) },
1562 { "eflags", offsetof(CPUState
, eflags
) },
1563 { "eip", offsetof(CPUState
, eip
) },
1570 { "pc", 0, monitor_get_pc
, },
1571 #elif defined(TARGET_PPC)
1572 /* General purpose registers */
1573 { "r0", offsetof(CPUState
, gpr
[0]) },
1574 { "r1", offsetof(CPUState
, gpr
[1]) },
1575 { "r2", offsetof(CPUState
, gpr
[2]) },
1576 { "r3", offsetof(CPUState
, gpr
[3]) },
1577 { "r4", offsetof(CPUState
, gpr
[4]) },
1578 { "r5", offsetof(CPUState
, gpr
[5]) },
1579 { "r6", offsetof(CPUState
, gpr
[6]) },
1580 { "r7", offsetof(CPUState
, gpr
[7]) },
1581 { "r8", offsetof(CPUState
, gpr
[8]) },
1582 { "r9", offsetof(CPUState
, gpr
[9]) },
1583 { "r10", offsetof(CPUState
, gpr
[10]) },
1584 { "r11", offsetof(CPUState
, gpr
[11]) },
1585 { "r12", offsetof(CPUState
, gpr
[12]) },
1586 { "r13", offsetof(CPUState
, gpr
[13]) },
1587 { "r14", offsetof(CPUState
, gpr
[14]) },
1588 { "r15", offsetof(CPUState
, gpr
[15]) },
1589 { "r16", offsetof(CPUState
, gpr
[16]) },
1590 { "r17", offsetof(CPUState
, gpr
[17]) },
1591 { "r18", offsetof(CPUState
, gpr
[18]) },
1592 { "r19", offsetof(CPUState
, gpr
[19]) },
1593 { "r20", offsetof(CPUState
, gpr
[20]) },
1594 { "r21", offsetof(CPUState
, gpr
[21]) },
1595 { "r22", offsetof(CPUState
, gpr
[22]) },
1596 { "r23", offsetof(CPUState
, gpr
[23]) },
1597 { "r24", offsetof(CPUState
, gpr
[24]) },
1598 { "r25", offsetof(CPUState
, gpr
[25]) },
1599 { "r26", offsetof(CPUState
, gpr
[26]) },
1600 { "r27", offsetof(CPUState
, gpr
[27]) },
1601 { "r28", offsetof(CPUState
, gpr
[28]) },
1602 { "r29", offsetof(CPUState
, gpr
[29]) },
1603 { "r30", offsetof(CPUState
, gpr
[30]) },
1604 { "r31", offsetof(CPUState
, gpr
[31]) },
1605 /* Floating point registers */
1606 { "f0", offsetof(CPUState
, fpr
[0]) },
1607 { "f1", offsetof(CPUState
, fpr
[1]) },
1608 { "f2", offsetof(CPUState
, fpr
[2]) },
1609 { "f3", offsetof(CPUState
, fpr
[3]) },
1610 { "f4", offsetof(CPUState
, fpr
[4]) },
1611 { "f5", offsetof(CPUState
, fpr
[5]) },
1612 { "f6", offsetof(CPUState
, fpr
[6]) },
1613 { "f7", offsetof(CPUState
, fpr
[7]) },
1614 { "f8", offsetof(CPUState
, fpr
[8]) },
1615 { "f9", offsetof(CPUState
, fpr
[9]) },
1616 { "f10", offsetof(CPUState
, fpr
[10]) },
1617 { "f11", offsetof(CPUState
, fpr
[11]) },
1618 { "f12", offsetof(CPUState
, fpr
[12]) },
1619 { "f13", offsetof(CPUState
, fpr
[13]) },
1620 { "f14", offsetof(CPUState
, fpr
[14]) },
1621 { "f15", offsetof(CPUState
, fpr
[15]) },
1622 { "f16", offsetof(CPUState
, fpr
[16]) },
1623 { "f17", offsetof(CPUState
, fpr
[17]) },
1624 { "f18", offsetof(CPUState
, fpr
[18]) },
1625 { "f19", offsetof(CPUState
, fpr
[19]) },
1626 { "f20", offsetof(CPUState
, fpr
[20]) },
1627 { "f21", offsetof(CPUState
, fpr
[21]) },
1628 { "f22", offsetof(CPUState
, fpr
[22]) },
1629 { "f23", offsetof(CPUState
, fpr
[23]) },
1630 { "f24", offsetof(CPUState
, fpr
[24]) },
1631 { "f25", offsetof(CPUState
, fpr
[25]) },
1632 { "f26", offsetof(CPUState
, fpr
[26]) },
1633 { "f27", offsetof(CPUState
, fpr
[27]) },
1634 { "f28", offsetof(CPUState
, fpr
[28]) },
1635 { "f29", offsetof(CPUState
, fpr
[29]) },
1636 { "f30", offsetof(CPUState
, fpr
[30]) },
1637 { "f31", offsetof(CPUState
, fpr
[31]) },
1638 { "fpscr", offsetof(CPUState
, fpscr
) },
1639 /* Next instruction pointer */
1640 { "nip|pc", offsetof(CPUState
, nip
) },
1641 { "lr", offsetof(CPUState
, lr
) },
1642 { "ctr", offsetof(CPUState
, ctr
) },
1643 { "decr", 0, &monitor_get_decr
, },
1644 { "ccr", 0, &monitor_get_ccr
, },
1645 /* Machine state register */
1646 { "msr", 0, &monitor_get_msr
, },
1647 { "xer", 0, &monitor_get_xer
, },
1648 { "tbu", 0, &monitor_get_tbu
, },
1649 { "tbl", 0, &monitor_get_tbl
, },
1650 #if defined(TARGET_PPC64)
1651 /* Address space register */
1652 { "asr", offsetof(CPUState
, asr
) },
1654 /* Segment registers */
1655 { "sdr1", offsetof(CPUState
, sdr1
) },
1656 { "sr0", offsetof(CPUState
, sr
[0]) },
1657 { "sr1", offsetof(CPUState
, sr
[1]) },
1658 { "sr2", offsetof(CPUState
, sr
[2]) },
1659 { "sr3", offsetof(CPUState
, sr
[3]) },
1660 { "sr4", offsetof(CPUState
, sr
[4]) },
1661 { "sr5", offsetof(CPUState
, sr
[5]) },
1662 { "sr6", offsetof(CPUState
, sr
[6]) },
1663 { "sr7", offsetof(CPUState
, sr
[7]) },
1664 { "sr8", offsetof(CPUState
, sr
[8]) },
1665 { "sr9", offsetof(CPUState
, sr
[9]) },
1666 { "sr10", offsetof(CPUState
, sr
[10]) },
1667 { "sr11", offsetof(CPUState
, sr
[11]) },
1668 { "sr12", offsetof(CPUState
, sr
[12]) },
1669 { "sr13", offsetof(CPUState
, sr
[13]) },
1670 { "sr14", offsetof(CPUState
, sr
[14]) },
1671 { "sr15", offsetof(CPUState
, sr
[15]) },
1672 /* Too lazy to put BATs and SPRs ... */
1673 #elif defined(TARGET_SPARC)
1674 { "g0", offsetof(CPUState
, gregs
[0]) },
1675 { "g1", offsetof(CPUState
, gregs
[1]) },
1676 { "g2", offsetof(CPUState
, gregs
[2]) },
1677 { "g3", offsetof(CPUState
, gregs
[3]) },
1678 { "g4", offsetof(CPUState
, gregs
[4]) },
1679 { "g5", offsetof(CPUState
, gregs
[5]) },
1680 { "g6", offsetof(CPUState
, gregs
[6]) },
1681 { "g7", offsetof(CPUState
, gregs
[7]) },
1682 { "o0", 0, monitor_get_reg
},
1683 { "o1", 1, monitor_get_reg
},
1684 { "o2", 2, monitor_get_reg
},
1685 { "o3", 3, monitor_get_reg
},
1686 { "o4", 4, monitor_get_reg
},
1687 { "o5", 5, monitor_get_reg
},
1688 { "o6", 6, monitor_get_reg
},
1689 { "o7", 7, monitor_get_reg
},
1690 { "l0", 8, monitor_get_reg
},
1691 { "l1", 9, monitor_get_reg
},
1692 { "l2", 10, monitor_get_reg
},
1693 { "l3", 11, monitor_get_reg
},
1694 { "l4", 12, monitor_get_reg
},
1695 { "l5", 13, monitor_get_reg
},
1696 { "l6", 14, monitor_get_reg
},
1697 { "l7", 15, monitor_get_reg
},
1698 { "i0", 16, monitor_get_reg
},
1699 { "i1", 17, monitor_get_reg
},
1700 { "i2", 18, monitor_get_reg
},
1701 { "i3", 19, monitor_get_reg
},
1702 { "i4", 20, monitor_get_reg
},
1703 { "i5", 21, monitor_get_reg
},
1704 { "i6", 22, monitor_get_reg
},
1705 { "i7", 23, monitor_get_reg
},
1706 { "pc", offsetof(CPUState
, pc
) },
1707 { "npc", offsetof(CPUState
, npc
) },
1708 { "y", offsetof(CPUState
, y
) },
1709 #ifndef TARGET_SPARC64
1710 { "psr", 0, &monitor_get_psr
, },
1711 { "wim", offsetof(CPUState
, wim
) },
1713 { "tbr", offsetof(CPUState
, tbr
) },
1714 { "fsr", offsetof(CPUState
, fsr
) },
1715 { "f0", offsetof(CPUState
, fpr
[0]) },
1716 { "f1", offsetof(CPUState
, fpr
[1]) },
1717 { "f2", offsetof(CPUState
, fpr
[2]) },
1718 { "f3", offsetof(CPUState
, fpr
[3]) },
1719 { "f4", offsetof(CPUState
, fpr
[4]) },
1720 { "f5", offsetof(CPUState
, fpr
[5]) },
1721 { "f6", offsetof(CPUState
, fpr
[6]) },
1722 { "f7", offsetof(CPUState
, fpr
[7]) },
1723 { "f8", offsetof(CPUState
, fpr
[8]) },
1724 { "f9", offsetof(CPUState
, fpr
[9]) },
1725 { "f10", offsetof(CPUState
, fpr
[10]) },
1726 { "f11", offsetof(CPUState
, fpr
[11]) },
1727 { "f12", offsetof(CPUState
, fpr
[12]) },
1728 { "f13", offsetof(CPUState
, fpr
[13]) },
1729 { "f14", offsetof(CPUState
, fpr
[14]) },
1730 { "f15", offsetof(CPUState
, fpr
[15]) },
1731 { "f16", offsetof(CPUState
, fpr
[16]) },
1732 { "f17", offsetof(CPUState
, fpr
[17]) },
1733 { "f18", offsetof(CPUState
, fpr
[18]) },
1734 { "f19", offsetof(CPUState
, fpr
[19]) },
1735 { "f20", offsetof(CPUState
, fpr
[20]) },
1736 { "f21", offsetof(CPUState
, fpr
[21]) },
1737 { "f22", offsetof(CPUState
, fpr
[22]) },
1738 { "f23", offsetof(CPUState
, fpr
[23]) },
1739 { "f24", offsetof(CPUState
, fpr
[24]) },
1740 { "f25", offsetof(CPUState
, fpr
[25]) },
1741 { "f26", offsetof(CPUState
, fpr
[26]) },
1742 { "f27", offsetof(CPUState
, fpr
[27]) },
1743 { "f28", offsetof(CPUState
, fpr
[28]) },
1744 { "f29", offsetof(CPUState
, fpr
[29]) },
1745 { "f30", offsetof(CPUState
, fpr
[30]) },
1746 { "f31", offsetof(CPUState
, fpr
[31]) },
1747 #ifdef TARGET_SPARC64
1748 { "f32", offsetof(CPUState
, fpr
[32]) },
1749 { "f34", offsetof(CPUState
, fpr
[34]) },
1750 { "f36", offsetof(CPUState
, fpr
[36]) },
1751 { "f38", offsetof(CPUState
, fpr
[38]) },
1752 { "f40", offsetof(CPUState
, fpr
[40]) },
1753 { "f42", offsetof(CPUState
, fpr
[42]) },
1754 { "f44", offsetof(CPUState
, fpr
[44]) },
1755 { "f46", offsetof(CPUState
, fpr
[46]) },
1756 { "f48", offsetof(CPUState
, fpr
[48]) },
1757 { "f50", offsetof(CPUState
, fpr
[50]) },
1758 { "f52", offsetof(CPUState
, fpr
[52]) },
1759 { "f54", offsetof(CPUState
, fpr
[54]) },
1760 { "f56", offsetof(CPUState
, fpr
[56]) },
1761 { "f58", offsetof(CPUState
, fpr
[58]) },
1762 { "f60", offsetof(CPUState
, fpr
[60]) },
1763 { "f62", offsetof(CPUState
, fpr
[62]) },
1764 { "asi", offsetof(CPUState
, asi
) },
1765 { "pstate", offsetof(CPUState
, pstate
) },
1766 { "cansave", offsetof(CPUState
, cansave
) },
1767 { "canrestore", offsetof(CPUState
, canrestore
) },
1768 { "otherwin", offsetof(CPUState
, otherwin
) },
1769 { "wstate", offsetof(CPUState
, wstate
) },
1770 { "cleanwin", offsetof(CPUState
, cleanwin
) },
1771 { "fprs", offsetof(CPUState
, fprs
) },
1777 static void expr_error(const char *fmt
)
1781 longjmp(expr_env
, 1);
1784 /* return 0 if OK, -1 if not found, -2 if no CPU defined */
1785 static int get_monitor_def(target_long
*pval
, const char *name
)
1790 for(md
= monitor_defs
; md
->name
!= NULL
; md
++) {
1791 if (compare_cmd(name
, md
->name
)) {
1792 if (md
->get_value
) {
1793 *pval
= md
->get_value(md
, md
->offset
);
1795 CPUState
*env
= mon_get_cpu();
1798 ptr
= (uint8_t *)env
+ md
->offset
;
1801 *pval
= *(int32_t *)ptr
;
1804 *pval
= *(target_long
*)ptr
;
1817 static void next(void)
1821 while (isspace(*pch
))
1826 static int64_t expr_sum(void);
1828 static int64_t expr_unary(void)
1851 expr_error("')' expected");
1858 expr_error("character constant expected");
1862 expr_error("missing terminating \' character");
1872 while ((*pch
>= 'a' && *pch
<= 'z') ||
1873 (*pch
>= 'A' && *pch
<= 'Z') ||
1874 (*pch
>= '0' && *pch
<= '9') ||
1875 *pch
== '_' || *pch
== '.') {
1876 if ((q
- buf
) < sizeof(buf
) - 1)
1880 while (isspace(*pch
))
1883 ret
= get_monitor_def(®
, buf
);
1885 expr_error("unknown register");
1887 expr_error("no cpu defined");
1892 expr_error("unexpected end of expression");
1896 #if TARGET_PHYS_ADDR_BITS > 32
1897 n
= strtoull(pch
, &p
, 0);
1899 n
= strtoul(pch
, &p
, 0);
1902 expr_error("invalid char in expression");
1905 while (isspace(*pch
))
1913 static int64_t expr_prod(void)
1921 if (op
!= '*' && op
!= '/' && op
!= '%')
1924 val2
= expr_unary();
1933 expr_error("division by zero");
1944 static int64_t expr_logic(void)
1952 if (op
!= '&' && op
!= '|' && op
!= '^')
1972 static int64_t expr_sum(void)
1980 if (op
!= '+' && op
!= '-')
1983 val2
= expr_logic();
1992 static int get_expr(int64_t *pval
, const char **pp
)
1995 if (setjmp(expr_env
)) {
1999 while (isspace(*pch
))
2006 static int get_str(char *buf
, int buf_size
, const char **pp
)
2024 while (*p
!= '\0' && *p
!= '\"') {
2040 qemu_printf("unsupported escape code: '\\%c'\n", c
);
2043 if ((q
- buf
) < buf_size
- 1) {
2047 if ((q
- buf
) < buf_size
- 1) {
2054 qemu_printf("unterminated string\n");
2059 while (*p
!= '\0' && !isspace(*p
)) {
2060 if ((q
- buf
) < buf_size
- 1) {
2071 static int default_fmt_format
= 'x';
2072 static int default_fmt_size
= 4;
2076 static void monitor_handle_command(const char *cmdline
)
2078 const char *p
, *pstart
, *typestr
;
2080 int c
, nb_args
, len
, i
, has_arg
;
2084 void *str_allocated
[MAX_ARGS
];
2085 void *args
[MAX_ARGS
];
2088 term_printf("command='%s'\n", cmdline
);
2091 /* extract the command name */
2099 while (*p
!= '\0' && *p
!= '/' && !isspace(*p
))
2102 if (len
> sizeof(cmdname
) - 1)
2103 len
= sizeof(cmdname
) - 1;
2104 memcpy(cmdname
, pstart
, len
);
2105 cmdname
[len
] = '\0';
2107 /* find the command */
2108 for(cmd
= term_cmds
; cmd
->name
!= NULL
; cmd
++) {
2109 if (compare_cmd(cmdname
, cmd
->name
))
2112 term_printf("unknown command: '%s'\n", cmdname
);
2116 for(i
= 0; i
< MAX_ARGS
; i
++)
2117 str_allocated
[i
] = NULL
;
2119 /* parse the parameters */
2120 typestr
= cmd
->args_type
;
2137 if (*typestr
== '?') {
2140 /* no optional string: NULL argument */
2145 ret
= get_str(buf
, sizeof(buf
), &p
);
2149 term_printf("%s: filename expected\n", cmdname
);
2152 term_printf("%s: block device name expected\n", cmdname
);
2155 term_printf("%s: string expected\n", cmdname
);
2160 str
= qemu_malloc(strlen(buf
) + 1);
2162 str_allocated
[nb_args
] = str
;
2164 if (nb_args
>= MAX_ARGS
) {
2166 term_printf("%s: too many arguments\n", cmdname
);
2169 args
[nb_args
++] = str
;
2174 int count
, format
, size
;
2184 while (isdigit(*p
)) {
2185 count
= count
* 10 + (*p
- '0');
2223 if (*p
!= '\0' && !isspace(*p
)) {
2224 term_printf("invalid char in format: '%c'\n", *p
);
2228 format
= default_fmt_format
;
2229 if (format
!= 'i') {
2230 /* for 'i', not specifying a size gives -1 as size */
2232 size
= default_fmt_size
;
2234 default_fmt_size
= size
;
2235 default_fmt_format
= format
;
2238 format
= default_fmt_format
;
2239 if (format
!= 'i') {
2240 size
= default_fmt_size
;
2245 if (nb_args
+ 3 > MAX_ARGS
)
2247 args
[nb_args
++] = (void*)(long)count
;
2248 args
[nb_args
++] = (void*)(long)format
;
2249 args
[nb_args
++] = (void*)(long)size
;
2259 if (*typestr
== '?' || *typestr
== '.') {
2260 if (*typestr
== '?') {
2276 if (nb_args
>= MAX_ARGS
)
2278 args
[nb_args
++] = (void *)(long)has_arg
;
2280 if (nb_args
>= MAX_ARGS
)
2286 if (get_expr(&val
, &p
))
2290 if (nb_args
>= MAX_ARGS
)
2292 args
[nb_args
++] = (void *)(long)val
;
2294 if ((nb_args
+ 1) >= MAX_ARGS
)
2296 #if TARGET_PHYS_ADDR_BITS > 32
2297 args
[nb_args
++] = (void *)(long)((val
>> 32) & 0xffffffff);
2299 args
[nb_args
++] = (void *)0;
2301 args
[nb_args
++] = (void *)(long)(val
& 0xffffffff);
2319 term_printf("%s: unsupported option -%c\n",
2326 if (nb_args
>= MAX_ARGS
)
2328 args
[nb_args
++] = (void *)(long)has_option
;
2333 term_printf("%s: unknown type '%c'\n", cmdname
, c
);
2337 /* check that all arguments were parsed */
2341 term_printf("%s: extraneous characters at the end of line\n",
2351 cmd
->handler(args
[0]);
2354 cmd
->handler(args
[0], args
[1]);
2357 cmd
->handler(args
[0], args
[1], args
[2]);
2360 cmd
->handler(args
[0], args
[1], args
[2], args
[3]);
2363 cmd
->handler(args
[0], args
[1], args
[2], args
[3], args
[4]);
2366 cmd
->handler(args
[0], args
[1], args
[2], args
[3], args
[4], args
[5]);
2369 cmd
->handler(args
[0], args
[1], args
[2], args
[3], args
[4], args
[5], args
[6]);
2372 term_printf("unsupported number of arguments: %d\n", nb_args
);
2376 for(i
= 0; i
< MAX_ARGS
; i
++)
2377 qemu_free(str_allocated
[i
]);
2381 static void cmd_completion(const char *name
, const char *list
)
2383 const char *p
, *pstart
;
2392 p
= pstart
+ strlen(pstart
);
2394 if (len
> sizeof(cmd
) - 2)
2395 len
= sizeof(cmd
) - 2;
2396 memcpy(cmd
, pstart
, len
);
2398 if (name
[0] == '\0' || !strncmp(name
, cmd
, strlen(name
))) {
2399 add_completion(cmd
);
2407 static void file_completion(const char *input
)
2412 char file
[1024], file_prefix
[1024];
2416 p
= strrchr(input
, '/');
2419 pstrcpy(file_prefix
, sizeof(file_prefix
), input
);
2422 input_path_len
= p
- input
+ 1;
2423 memcpy(path
, input
, input_path_len
);
2424 if (input_path_len
> sizeof(path
) - 1)
2425 input_path_len
= sizeof(path
) - 1;
2426 path
[input_path_len
] = '\0';
2427 pstrcpy(file_prefix
, sizeof(file_prefix
), p
+ 1);
2429 #ifdef DEBUG_COMPLETION
2430 term_printf("input='%s' path='%s' prefix='%s'\n", input
, path
, file_prefix
);
2432 ffs
= opendir(path
);
2440 if (strstart(d
->d_name
, file_prefix
, NULL
)) {
2441 memcpy(file
, input
, input_path_len
);
2442 strcpy(file
+ input_path_len
, d
->d_name
);
2443 /* stat the file to find out if it's a directory.
2444 * In that case add a slash to speed up typing long paths
2447 if(S_ISDIR(sb
.st_mode
))
2449 add_completion(file
);
2455 static void block_completion_it(void *opaque
, const char *name
)
2457 const char *input
= opaque
;
2459 if (input
[0] == '\0' ||
2460 !strncmp(name
, (char *)input
, strlen(input
))) {
2461 add_completion(name
);
2465 /* NOTE: this parser is an approximate form of the real command parser */
2466 static void parse_cmdline(const char *cmdline
,
2467 int *pnb_args
, char **args
)
2480 if (nb_args
>= MAX_ARGS
)
2482 ret
= get_str(buf
, sizeof(buf
), &p
);
2483 args
[nb_args
] = qemu_strdup(buf
);
2488 *pnb_args
= nb_args
;
2491 void readline_find_completion(const char *cmdline
)
2493 const char *cmdname
;
2494 char *args
[MAX_ARGS
];
2495 int nb_args
, i
, len
;
2496 const char *ptype
, *str
;
2500 parse_cmdline(cmdline
, &nb_args
, args
);
2501 #ifdef DEBUG_COMPLETION
2502 for(i
= 0; i
< nb_args
; i
++) {
2503 term_printf("arg%d = '%s'\n", i
, (char *)args
[i
]);
2507 /* if the line ends with a space, it means we want to complete the
2509 len
= strlen(cmdline
);
2510 if (len
> 0 && isspace(cmdline
[len
- 1])) {
2511 if (nb_args
>= MAX_ARGS
)
2513 args
[nb_args
++] = qemu_strdup("");
2516 /* command completion */
2521 completion_index
= strlen(cmdname
);
2522 for(cmd
= term_cmds
; cmd
->name
!= NULL
; cmd
++) {
2523 cmd_completion(cmdname
, cmd
->name
);
2526 /* find the command */
2527 for(cmd
= term_cmds
; cmd
->name
!= NULL
; cmd
++) {
2528 if (compare_cmd(args
[0], cmd
->name
))
2533 ptype
= cmd
->args_type
;
2534 for(i
= 0; i
< nb_args
- 2; i
++) {
2535 if (*ptype
!= '\0') {
2537 while (*ptype
== '?')
2541 str
= args
[nb_args
- 1];
2544 /* file completion */
2545 completion_index
= strlen(str
);
2546 file_completion(str
);
2549 /* block device name completion */
2550 completion_index
= strlen(str
);
2551 bdrv_iterate(block_completion_it
, (void *)str
);
2554 /* XXX: more generic ? */
2555 if (!strcmp(cmd
->name
, "info")) {
2556 completion_index
= strlen(str
);
2557 for(cmd
= info_cmds
; cmd
->name
!= NULL
; cmd
++) {
2558 cmd_completion(str
, cmd
->name
);
2560 } else if (!strcmp(cmd
->name
, "sendkey")) {
2561 completion_index
= strlen(str
);
2562 for(key
= key_defs
; key
->name
!= NULL
; key
++) {
2563 cmd_completion(str
, key
->name
);
2571 for(i
= 0; i
< nb_args
; i
++)
2575 static int term_can_read(void *opaque
)
2580 static void term_read(void *opaque
, const uint8_t *buf
, int size
)
2583 for(i
= 0; i
< size
; i
++)
2584 readline_handle_byte(buf
[i
]);
2587 static int monitor_suspended
;
2589 void monitor_suspend(void)
2591 monitor_suspended
= 1;
2594 void monitor_resume(void)
2596 monitor_suspended
= 0;
2597 monitor_start_input();
2600 static void monitor_start_input(void);
2602 static void monitor_handle_command1(void *opaque
, const char *cmdline
)
2604 monitor_handle_command(cmdline
);
2605 if (!monitor_suspended
)
2606 monitor_start_input();
2609 static void monitor_start_input(void)
2611 readline_start("(qemu) ", 0, monitor_handle_command1
, NULL
);
2614 static void term_event(void *opaque
, int event
)
2616 if (event
!= CHR_EVENT_RESET
)
2620 term_printf("QEMU %s monitor - type 'help' for more information\n",
2622 monitor_start_input();
2625 static int is_first_init
= 1;
2627 void monitor_init(CharDriverState
*hd
, int show_banner
)
2631 if (is_first_init
) {
2632 for (i
= 0; i
< MAX_MON
; i
++) {
2633 monitor_hd
[i
] = NULL
;
2637 for (i
= 0; i
< MAX_MON
; i
++) {
2638 if (monitor_hd
[i
] == NULL
) {
2644 hide_banner
= !show_banner
;
2646 qemu_chr_add_handlers(hd
, term_can_read
, term_read
, term_event
, NULL
);
2648 readline_start("", 0, monitor_handle_command1
, NULL
);
2651 /* XXX: use threads ? */
2652 /* modal monitor readline */
2653 static int monitor_readline_started
;
2654 static char *monitor_readline_buf
;
2655 static int monitor_readline_buf_size
;
2657 static void monitor_readline_cb(void *opaque
, const char *input
)
2659 pstrcpy(monitor_readline_buf
, monitor_readline_buf_size
, input
);
2660 monitor_readline_started
= 0;
2663 void monitor_readline(const char *prompt
, int is_password
,
2664 char *buf
, int buf_size
)
2669 for (i
= 0; i
< MAX_MON
; i
++)
2670 if (monitor_hd
[i
] && monitor_hd
[i
]->focus
== 0)
2671 qemu_chr_send_event(monitor_hd
[i
], CHR_EVENT_FOCUS
);
2673 readline_start(prompt
, is_password
, monitor_readline_cb
, NULL
);
2674 monitor_readline_buf
= buf
;
2675 monitor_readline_buf_size
= buf_size
;
2676 monitor_readline_started
= 1;
2677 while (monitor_readline_started
) {