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
29 //#define DEBUG_COMPLETION
32 #define offsetof(type, field) ((size_t) &((type *)0)->field)
39 * 'B' block device name
40 * 's' string (accept optional quote)
42 * 'l' target long (32 or 64 bit)
43 * '/' optional gdb-like print format (like "/10x")
45 * '?' optional type (for 'F', 's' and 'i')
49 typedef struct term_cmd_t
{
51 const char *args_type
;
57 static CharDriverState
*monitor_hd
;
59 static term_cmd_t term_cmds
[];
60 static term_cmd_t info_cmds
[];
62 static char term_outbuf
[1024];
63 static int term_outbuf_index
;
65 static void monitor_start_input(void);
67 CPUState
*mon_cpu
= NULL
;
71 if (term_outbuf_index
> 0) {
72 qemu_chr_write(monitor_hd
, term_outbuf
, term_outbuf_index
);
73 term_outbuf_index
= 0;
77 /* flush at every end of line or if the buffer is full */
78 void term_puts(const char *str
)
86 term_outbuf
[term_outbuf_index
++] = '\r';
87 term_outbuf
[term_outbuf_index
++] = c
;
88 if (term_outbuf_index
>= (sizeof(term_outbuf
) - 1) ||
94 void term_vprintf(const char *fmt
, va_list ap
)
97 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
101 void term_printf(const char *fmt
, ...)
105 term_vprintf(fmt
, ap
);
109 static int monitor_fprintf(FILE *stream
, const char *fmt
, ...)
113 term_vprintf(fmt
, ap
);
118 static int compare_cmd(const char *name
, const char *list
)
120 const char *p
, *pstart
;
128 p
= pstart
+ strlen(pstart
);
129 if ((p
- pstart
) == len
&& !memcmp(pstart
, name
, len
))
138 static void help_cmd1(term_cmd_t
*cmds
, const char *prefix
, const char *name
)
142 for(cmd
= cmds
; cmd
->name
!= NULL
; cmd
++) {
143 if (!name
|| !strcmp(name
, cmd
->name
))
144 term_printf("%s%s %s -- %s\n", prefix
, cmd
->name
, cmd
->params
, cmd
->help
);
148 static void help_cmd(const char *name
)
150 if (name
&& !strcmp(name
, "info")) {
151 help_cmd1(info_cmds
, "info ", NULL
);
153 help_cmd1(term_cmds
, "", name
);
154 if (name
&& !strcmp(name
, "log")) {
156 term_printf("Log items (comma separated):\n");
157 term_printf("%-10s %s\n", "none", "remove all logs");
158 for(item
= cpu_log_items
; item
->mask
!= 0; item
++) {
159 term_printf("%-10s %s\n", item
->name
, item
->help
);
165 static void do_help(const char *name
)
170 static void do_commit(void)
174 for (i
= 0; i
< MAX_DISKS
; i
++) {
176 bdrv_commit(bs_table
[i
]);
181 static void do_info(const char *item
)
187 for(cmd
= info_cmds
; cmd
->name
!= NULL
; cmd
++) {
188 if (compare_cmd(item
, cmd
->name
))
198 static void do_info_version(void)
200 term_printf("%s\n", QEMU_VERSION
);
203 static void do_info_block(void)
208 /* get the current CPU defined by the user */
209 int mon_set_cpu(int cpu_index
)
213 for(env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
214 if (env
->cpu_index
== cpu_index
) {
222 CPUState
*mon_get_cpu(void)
230 static void do_info_registers(void)
237 cpu_dump_state(env
, NULL
, monitor_fprintf
,
240 cpu_dump_state(env
, NULL
, monitor_fprintf
,
245 static void do_info_cpus(void)
249 /* just to set the default cpu if not already done */
252 for(env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
253 term_printf("%c CPU #%d:",
254 (env
== mon_cpu
) ? '*' : ' ',
256 #if defined(TARGET_I386)
257 term_printf(" pc=0x" TARGET_FMT_lx
, env
->eip
+ env
->segs
[R_CS
].base
);
258 if (env
->hflags
& HF_HALTED_MASK
)
259 term_printf(" (halted)");
260 #elif defined(TARGET_PPC)
261 term_printf(" nip=0x" TARGET_FMT_lx
, env
->nip
);
263 term_printf(" (halted)");
264 #elif defined(TARGET_SPARC)
265 term_printf(" pc=0x" TARGET_FMT_lx
" npc=0x" TARGET_FMT_lx
, env
->pc
, env
->npc
);
267 term_printf(" (halted)");
273 static void do_cpu_set(int index
)
275 if (mon_set_cpu(index
) < 0)
276 term_printf("Invalid CPU index\n");
279 static void do_info_jit(void)
281 dump_exec_info(NULL
, monitor_fprintf
);
284 static void do_info_history (void)
291 str
= readline_get_history(i
);
294 term_printf("%d: '%s'\n", i
, str
);
299 static void do_quit(void)
304 static int eject_device(BlockDriverState
*bs
, int force
)
306 if (bdrv_is_inserted(bs
)) {
308 if (!bdrv_is_removable(bs
)) {
309 term_printf("device is not removable\n");
312 if (bdrv_is_locked(bs
)) {
313 term_printf("device is locked\n");
322 static void do_eject(int force
, const char *filename
)
324 BlockDriverState
*bs
;
326 bs
= bdrv_find(filename
);
328 term_printf("device not found\n");
331 eject_device(bs
, force
);
334 static void do_change(const char *device
, const char *filename
)
336 BlockDriverState
*bs
;
340 bs
= bdrv_find(device
);
342 term_printf("device not found\n");
345 if (eject_device(bs
, 0) < 0)
347 bdrv_open(bs
, filename
, 0);
348 if (bdrv_is_encrypted(bs
)) {
349 term_printf("%s is encrypted.\n", device
);
350 for(i
= 0; i
< 3; i
++) {
351 monitor_readline("Password: ", 1, password
, sizeof(password
));
352 if (bdrv_set_key(bs
, password
) == 0)
354 term_printf("invalid password\n");
359 static void do_screen_dump(const char *filename
)
361 vga_hw_screen_dump(filename
);
364 static void do_log(const char *items
)
368 if (!strcmp(items
, "none")) {
371 mask
= cpu_str_to_log_mask(items
);
380 static void do_savevm(const char *filename
)
382 if (qemu_savevm(filename
) < 0)
383 term_printf("I/O error when saving VM to '%s'\n", filename
);
386 static void do_loadvm(const char *filename
)
388 if (qemu_loadvm(filename
) < 0)
389 term_printf("I/O error when loading VM from '%s'\n", filename
);
392 static void do_stop(void)
394 vm_stop(EXCP_INTERRUPT
);
397 static void do_cont(void)
402 #ifdef CONFIG_GDBSTUB
403 static void do_gdbserver(int has_port
, int port
)
406 port
= DEFAULT_GDBSTUB_PORT
;
407 if (gdbserver_start(port
) < 0) {
408 qemu_printf("Could not open gdbserver socket on port %d\n", port
);
410 qemu_printf("Waiting gdb connection on port %d\n", port
);
415 static void term_printc(int c
)
432 if (c
>= 32 && c
<= 126) {
433 term_printf("%c", c
);
435 term_printf("\\x%02x", c
);
442 static void memory_dump(int count
, int format
, int wsize
,
443 target_ulong addr
, int is_physical
)
446 int nb_per_line
, l
, line_size
, i
, max_digits
, len
;
454 if (!env
&& !is_physical
)
459 } else if (wsize
== 4) {
462 /* as default we use the current CS size */
466 if ((env
->efer
& MSR_EFER_LMA
) &&
467 (env
->segs
[R_CS
].flags
& DESC_L_MASK
))
471 if (!(env
->segs
[R_CS
].flags
& DESC_B_MASK
))
476 monitor_disas(env
, addr
, count
, is_physical
, flags
);
485 nb_per_line
= line_size
/ wsize
;
490 max_digits
= (wsize
* 8 + 2) / 3;
494 max_digits
= (wsize
* 8) / 4;
498 max_digits
= (wsize
* 8 * 10 + 32) / 33;
506 term_printf(TARGET_FMT_lx
":", addr
);
511 cpu_physical_memory_rw(addr
, buf
, l
, 0);
516 cpu_memory_rw_debug(env
, addr
, buf
, l
, 0);
523 v
= ldub_raw(buf
+ i
);
526 v
= lduw_raw(buf
+ i
);
529 v
= (uint32_t)ldl_raw(buf
+ i
);
532 v
= ldq_raw(buf
+ i
);
538 term_printf("%#*" PRIo64
, max_digits
, v
);
541 term_printf("0x%0*" PRIx64
, max_digits
, v
);
544 term_printf("%*" PRIu64
, max_digits
, v
);
547 term_printf("%*" PRId64
, max_digits
, v
);
561 #if TARGET_LONG_BITS == 64
562 #define GET_TLONG(h, l) (((uint64_t)(h) << 32) | (l))
564 #define GET_TLONG(h, l) (l)
567 static void do_memory_dump(int count
, int format
, int size
,
568 uint32_t addrh
, uint32_t addrl
)
570 target_long addr
= GET_TLONG(addrh
, addrl
);
571 memory_dump(count
, format
, size
, addr
, 0);
574 static void do_physical_memory_dump(int count
, int format
, int size
,
575 uint32_t addrh
, uint32_t addrl
)
578 target_long addr
= GET_TLONG(addrh
, addrl
);
579 memory_dump(count
, format
, size
, addr
, 1);
582 static void do_print(int count
, int format
, int size
, unsigned int valh
, unsigned int vall
)
584 target_long val
= GET_TLONG(valh
, vall
);
585 #if TARGET_LONG_BITS == 32
588 term_printf("%#o", val
);
591 term_printf("%#x", val
);
594 term_printf("%u", val
);
598 term_printf("%d", val
);
607 term_printf("%#" PRIo64
, val
);
610 term_printf("%#" PRIx64
, val
);
613 term_printf("%" PRIu64
, val
);
617 term_printf("%" PRId64
, val
);
627 static void do_sum(uint32_t start
, uint32_t size
)
634 for(addr
= start
; addr
< (start
+ size
); addr
++) {
635 cpu_physical_memory_rw(addr
, buf
, 1, 0);
636 /* BSD sum algorithm ('sum' Unix command) */
637 sum
= (sum
>> 1) | (sum
<< 15);
640 term_printf("%05d\n", sum
);
648 static const KeyDef key_defs
[] = {
673 { 0x0e, "backspace" },
708 { 0x3a, "caps_lock" },
719 { 0x45, "num_lock" },
720 { 0x46, "scroll_lock" },
722 { 0xb5, "kp_divide" },
723 { 0x37, "kp_multiply" },
724 { 0x4a, "kp_substract" },
726 { 0x9c, "kp_enter" },
727 { 0x53, "kp_decimal" },
762 static int get_keycode(const char *key
)
768 for(p
= key_defs
; p
->name
!= NULL
; p
++) {
769 if (!strcmp(key
, p
->name
))
772 if (strstart(key
, "0x", NULL
)) {
773 ret
= strtoul(key
, &endp
, 0);
774 if (*endp
== '\0' && ret
>= 0x01 && ret
<= 0xff)
780 static void do_send_key(const char *string
)
783 uint8_t keycodes
[16];
785 int nb_keycodes
, keycode
, i
;
791 while (*p
!= '\0' && *p
!= '-') {
792 if ((q
- keybuf
) < sizeof(keybuf
) - 1) {
798 keycode
= get_keycode(keybuf
);
800 term_printf("unknown key: '%s'\n", keybuf
);
803 keycodes
[nb_keycodes
++] = keycode
;
808 /* key down events */
809 for(i
= 0; i
< nb_keycodes
; i
++) {
810 keycode
= keycodes
[i
];
812 kbd_put_keycode(0xe0);
813 kbd_put_keycode(keycode
& 0x7f);
816 for(i
= nb_keycodes
- 1; i
>= 0; i
--) {
817 keycode
= keycodes
[i
];
819 kbd_put_keycode(0xe0);
820 kbd_put_keycode(keycode
| 0x80);
824 static void do_ioport_read(int count
, int format
, int size
, int addr
, int has_index
, int index
)
830 cpu_outb(NULL
, addr
& 0xffff, index
& 0xff);
838 val
= cpu_inb(NULL
, addr
);
842 val
= cpu_inw(NULL
, addr
);
846 val
= cpu_inl(NULL
, addr
);
850 term_printf("port%c[0x%04x] = %#0*x\n",
851 suffix
, addr
, size
* 2, val
);
854 static void do_system_reset(void)
856 qemu_system_reset_request();
859 static void do_system_powerdown(void)
861 qemu_system_powerdown_request();
864 #if defined(TARGET_I386)
865 static void print_pte(uint32_t addr
, uint32_t pte
, uint32_t mask
)
867 term_printf("%08x: %08x %c%c%c%c%c%c%c%c\n",
870 pte
& PG_GLOBAL_MASK
? 'G' : '-',
871 pte
& PG_PSE_MASK
? 'P' : '-',
872 pte
& PG_DIRTY_MASK
? 'D' : '-',
873 pte
& PG_ACCESSED_MASK
? 'A' : '-',
874 pte
& PG_PCD_MASK
? 'C' : '-',
875 pte
& PG_PWT_MASK
? 'T' : '-',
876 pte
& PG_USER_MASK
? 'U' : '-',
877 pte
& PG_RW_MASK
? 'W' : '-');
880 static void tlb_info(void)
884 uint32_t pgd
, pde
, pte
;
890 if (!(env
->cr
[0] & CR0_PG_MASK
)) {
891 term_printf("PG disabled\n");
894 pgd
= env
->cr
[3] & ~0xfff;
895 for(l1
= 0; l1
< 1024; l1
++) {
896 cpu_physical_memory_read(pgd
+ l1
* 4, (uint8_t *)&pde
, 4);
897 pde
= le32_to_cpu(pde
);
898 if (pde
& PG_PRESENT_MASK
) {
899 if ((pde
& PG_PSE_MASK
) && (env
->cr
[4] & CR4_PSE_MASK
)) {
900 print_pte((l1
<< 22), pde
, ~((1 << 20) - 1));
902 for(l2
= 0; l2
< 1024; l2
++) {
903 cpu_physical_memory_read((pde
& ~0xfff) + l2
* 4,
905 pte
= le32_to_cpu(pte
);
906 if (pte
& PG_PRESENT_MASK
) {
907 print_pte((l1
<< 22) + (l2
<< 12),
917 static void mem_print(uint32_t *pstart
, int *plast_prot
,
918 uint32_t end
, int prot
)
924 term_printf("%08x-%08x %08x %c%c%c\n",
925 *pstart
, end
, end
- *pstart
,
926 prot1
& PG_USER_MASK
? 'u' : '-',
928 prot1
& PG_RW_MASK
? 'w' : '-');
938 static void mem_info(void)
941 int l1
, l2
, prot
, last_prot
;
942 uint32_t pgd
, pde
, pte
, start
, end
;
948 if (!(env
->cr
[0] & CR0_PG_MASK
)) {
949 term_printf("PG disabled\n");
952 pgd
= env
->cr
[3] & ~0xfff;
955 for(l1
= 0; l1
< 1024; l1
++) {
956 cpu_physical_memory_read(pgd
+ l1
* 4, (uint8_t *)&pde
, 4);
957 pde
= le32_to_cpu(pde
);
959 if (pde
& PG_PRESENT_MASK
) {
960 if ((pde
& PG_PSE_MASK
) && (env
->cr
[4] & CR4_PSE_MASK
)) {
961 prot
= pde
& (PG_USER_MASK
| PG_RW_MASK
| PG_PRESENT_MASK
);
962 mem_print(&start
, &last_prot
, end
, prot
);
964 for(l2
= 0; l2
< 1024; l2
++) {
965 cpu_physical_memory_read((pde
& ~0xfff) + l2
* 4,
967 pte
= le32_to_cpu(pte
);
968 end
= (l1
<< 22) + (l2
<< 12);
969 if (pte
& PG_PRESENT_MASK
) {
970 prot
= pte
& (PG_USER_MASK
| PG_RW_MASK
| PG_PRESENT_MASK
);
974 mem_print(&start
, &last_prot
, end
, prot
);
979 mem_print(&start
, &last_prot
, end
, prot
);
985 static void do_info_kqemu(void)
993 term_printf("No cpu initialized yet");
996 val
= env
->kqemu_enabled
;
997 term_printf("kqemu support: ");
1001 term_printf("disabled\n");
1004 term_printf("enabled for user code\n");
1007 term_printf("enabled for user and kernel code\n");
1011 term_printf("kqemu support: not compiled\n");
1015 #ifdef CONFIG_PROFILER
1019 int64_t kqemu_exec_count
;
1021 int64_t kqemu_ret_int_count
;
1022 int64_t kqemu_ret_excp_count
;
1023 int64_t kqemu_ret_intr_count
;
1025 static void do_info_profile(void)
1031 term_printf("async time %" PRId64
" (%0.3f)\n",
1032 dev_time
, dev_time
/ (double)ticks_per_sec
);
1033 term_printf("qemu time %" PRId64
" (%0.3f)\n",
1034 qemu_time
, qemu_time
/ (double)ticks_per_sec
);
1035 term_printf("kqemu time %" PRId64
" (%0.3f %0.1f%%) count=%" PRId64
" int=%" PRId64
" excp=%" PRId64
" intr=%" PRId64
"\n",
1036 kqemu_time
, kqemu_time
/ (double)ticks_per_sec
,
1037 kqemu_time
/ (double)total
* 100.0,
1039 kqemu_ret_int_count
,
1040 kqemu_ret_excp_count
,
1041 kqemu_ret_intr_count
);
1044 kqemu_exec_count
= 0;
1046 kqemu_ret_int_count
= 0;
1047 kqemu_ret_excp_count
= 0;
1048 kqemu_ret_intr_count
= 0;
1050 kqemu_record_dump();
1054 static void do_info_profile(void)
1056 term_printf("Internal profiler not compiled\n");
1060 static term_cmd_t term_cmds
[] = {
1061 { "help|?", "s?", do_help
,
1062 "[cmd]", "show the help" },
1063 { "commit", "", do_commit
,
1064 "", "commit changes to the disk images (if -snapshot is used)" },
1065 { "info", "s?", do_info
,
1066 "subcommand", "show various information about the system state" },
1067 { "q|quit", "", do_quit
,
1068 "", "quit the emulator" },
1069 { "eject", "-fB", do_eject
,
1070 "[-f] device", "eject a removable media (use -f to force it)" },
1071 { "change", "BF", do_change
,
1072 "device filename", "change a removable media" },
1073 { "screendump", "F", do_screen_dump
,
1074 "filename", "save screen into PPM image 'filename'" },
1075 { "log", "s", do_log
,
1076 "item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" },
1077 { "savevm", "F", do_savevm
,
1078 "filename", "save the whole virtual machine state to 'filename'" },
1079 { "loadvm", "F", do_loadvm
,
1080 "filename", "restore the whole virtual machine state from 'filename'" },
1081 { "stop", "", do_stop
,
1082 "", "stop emulation", },
1083 { "c|cont", "", do_cont
,
1084 "", "resume emulation", },
1085 #ifdef CONFIG_GDBSTUB
1086 { "gdbserver", "i?", do_gdbserver
,
1087 "[port]", "start gdbserver session (default port=1234)", },
1089 { "x", "/l", do_memory_dump
,
1090 "/fmt addr", "virtual memory dump starting at 'addr'", },
1091 { "xp", "/l", do_physical_memory_dump
,
1092 "/fmt addr", "physical memory dump starting at 'addr'", },
1093 { "p|print", "/l", do_print
,
1094 "/fmt expr", "print expression value (use $reg for CPU register access)", },
1095 { "i", "/ii.", do_ioport_read
,
1096 "/fmt addr", "I/O port read" },
1098 { "sendkey", "s", do_send_key
,
1099 "keys", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1')" },
1100 { "system_reset", "", do_system_reset
,
1101 "", "reset the system" },
1102 { "system_powerdown", "", do_system_powerdown
,
1103 "", "send system power down event" },
1104 { "sum", "ii", do_sum
,
1105 "addr size", "compute the checksum of a memory region" },
1106 { "usb_add", "s", do_usb_add
,
1107 "device", "add USB device (e.g. 'host:bus.addr' or 'host:vendor_id:product_id')" },
1108 { "usb_del", "s", do_usb_del
,
1109 "device", "remove USB device 'bus.addr'" },
1110 { "cpu", "i", do_cpu_set
,
1111 "index", "set the default CPU" },
1115 static term_cmd_t info_cmds
[] = {
1116 { "version", "", do_info_version
,
1117 "", "show the version of qemu" },
1118 { "network", "", do_info_network
,
1119 "", "show the network state" },
1120 { "block", "", do_info_block
,
1121 "", "show the block devices" },
1122 { "registers", "", do_info_registers
,
1123 "", "show the cpu registers" },
1124 { "cpus", "", do_info_cpus
,
1125 "", "show infos for each CPU" },
1126 { "history", "", do_info_history
,
1127 "", "show the command line history", },
1128 { "irq", "", irq_info
,
1129 "", "show the interrupts statistics (if available)", },
1130 { "pic", "", pic_info
,
1131 "", "show i8259 (PIC) state", },
1132 { "pci", "", pci_info
,
1133 "", "show PCI info", },
1134 #if defined(TARGET_I386)
1135 { "tlb", "", tlb_info
,
1136 "", "show virtual to physical memory mappings", },
1137 { "mem", "", mem_info
,
1138 "", "show the active virtual memory mappings", },
1140 { "jit", "", do_info_jit
,
1141 "", "show dynamic compiler info", },
1142 { "kqemu", "", do_info_kqemu
,
1143 "", "show kqemu information", },
1144 { "usb", "", usb_info
,
1145 "", "show guest USB devices", },
1146 { "usbhost", "", usb_host_info
,
1147 "", "show host USB devices", },
1148 { "profile", "", do_info_profile
,
1149 "", "show profiling information", },
1153 /*******************************************************************/
1155 static const char *pch
;
1156 static jmp_buf expr_env
;
1161 typedef struct MonitorDef
{
1164 target_long (*get_value
)(struct MonitorDef
*md
, int val
);
1168 #if defined(TARGET_I386)
1169 static target_long
monitor_get_pc (struct MonitorDef
*md
, int val
)
1171 CPUState
*env
= mon_get_cpu();
1174 return env
->eip
+ env
->segs
[R_CS
].base
;
1178 #if defined(TARGET_PPC)
1179 static target_long
monitor_get_ccr (struct MonitorDef
*md
, int val
)
1181 CPUState
*env
= mon_get_cpu();
1189 for (i
= 0; i
< 8; i
++)
1190 u
|= env
->crf
[i
] << (32 - (4 * i
));
1195 static target_long
monitor_get_msr (struct MonitorDef
*md
, int val
)
1197 CPUState
*env
= mon_get_cpu();
1200 return (env
->msr
[MSR_POW
] << MSR_POW
) |
1201 (env
->msr
[MSR_ILE
] << MSR_ILE
) |
1202 (env
->msr
[MSR_EE
] << MSR_EE
) |
1203 (env
->msr
[MSR_PR
] << MSR_PR
) |
1204 (env
->msr
[MSR_FP
] << MSR_FP
) |
1205 (env
->msr
[MSR_ME
] << MSR_ME
) |
1206 (env
->msr
[MSR_FE0
] << MSR_FE0
) |
1207 (env
->msr
[MSR_SE
] << MSR_SE
) |
1208 (env
->msr
[MSR_BE
] << MSR_BE
) |
1209 (env
->msr
[MSR_FE1
] << MSR_FE1
) |
1210 (env
->msr
[MSR_IP
] << MSR_IP
) |
1211 (env
->msr
[MSR_IR
] << MSR_IR
) |
1212 (env
->msr
[MSR_DR
] << MSR_DR
) |
1213 (env
->msr
[MSR_RI
] << MSR_RI
) |
1214 (env
->msr
[MSR_LE
] << MSR_LE
);
1217 static target_long
monitor_get_xer (struct MonitorDef
*md
, int val
)
1219 CPUState
*env
= mon_get_cpu();
1222 return (env
->xer
[XER_SO
] << XER_SO
) |
1223 (env
->xer
[XER_OV
] << XER_OV
) |
1224 (env
->xer
[XER_CA
] << XER_CA
) |
1225 (env
->xer
[XER_BC
] << XER_BC
);
1228 static target_long
monitor_get_decr (struct MonitorDef
*md
, int val
)
1230 CPUState
*env
= mon_get_cpu();
1233 return cpu_ppc_load_decr(env
);
1236 static target_long
monitor_get_tbu (struct MonitorDef
*md
, int val
)
1238 CPUState
*env
= mon_get_cpu();
1241 return cpu_ppc_load_tbu(env
);
1244 static target_long
monitor_get_tbl (struct MonitorDef
*md
, int val
)
1246 CPUState
*env
= mon_get_cpu();
1249 return cpu_ppc_load_tbl(env
);
1253 #if defined(TARGET_SPARC)
1254 #ifndef TARGET_SPARC64
1255 static target_long
monitor_get_psr (struct MonitorDef
*md
, int val
)
1257 CPUState
*env
= mon_get_cpu();
1260 return GET_PSR(env
);
1264 static target_long
monitor_get_reg(struct MonitorDef
*md
, int val
)
1266 CPUState
*env
= mon_get_cpu();
1269 return env
->regwptr
[val
];
1273 static MonitorDef monitor_defs
[] = {
1276 #define SEG(name, seg) \
1277 { name, offsetof(CPUState, segs[seg].selector), NULL, MD_I32 },\
1278 { name ".base", offsetof(CPUState, segs[seg].base) },\
1279 { name ".limit", offsetof(CPUState, segs[seg].limit), NULL, MD_I32 },
1281 { "eax", offsetof(CPUState
, regs
[0]) },
1282 { "ecx", offsetof(CPUState
, regs
[1]) },
1283 { "edx", offsetof(CPUState
, regs
[2]) },
1284 { "ebx", offsetof(CPUState
, regs
[3]) },
1285 { "esp|sp", offsetof(CPUState
, regs
[4]) },
1286 { "ebp|fp", offsetof(CPUState
, regs
[5]) },
1287 { "esi", offsetof(CPUState
, regs
[6]) },
1288 { "edi", offsetof(CPUState
, regs
[7]) },
1289 #ifdef TARGET_X86_64
1290 { "r8", offsetof(CPUState
, regs
[8]) },
1291 { "r9", offsetof(CPUState
, regs
[9]) },
1292 { "r10", offsetof(CPUState
, regs
[10]) },
1293 { "r11", offsetof(CPUState
, regs
[11]) },
1294 { "r12", offsetof(CPUState
, regs
[12]) },
1295 { "r13", offsetof(CPUState
, regs
[13]) },
1296 { "r14", offsetof(CPUState
, regs
[14]) },
1297 { "r15", offsetof(CPUState
, regs
[15]) },
1299 { "eflags", offsetof(CPUState
, eflags
) },
1300 { "eip", offsetof(CPUState
, eip
) },
1307 { "pc", 0, monitor_get_pc
, },
1308 #elif defined(TARGET_PPC)
1309 { "r0", offsetof(CPUState
, gpr
[0]) },
1310 { "r1", offsetof(CPUState
, gpr
[1]) },
1311 { "r2", offsetof(CPUState
, gpr
[2]) },
1312 { "r3", offsetof(CPUState
, gpr
[3]) },
1313 { "r4", offsetof(CPUState
, gpr
[4]) },
1314 { "r5", offsetof(CPUState
, gpr
[5]) },
1315 { "r6", offsetof(CPUState
, gpr
[6]) },
1316 { "r7", offsetof(CPUState
, gpr
[7]) },
1317 { "r8", offsetof(CPUState
, gpr
[8]) },
1318 { "r9", offsetof(CPUState
, gpr
[9]) },
1319 { "r10", offsetof(CPUState
, gpr
[10]) },
1320 { "r11", offsetof(CPUState
, gpr
[11]) },
1321 { "r12", offsetof(CPUState
, gpr
[12]) },
1322 { "r13", offsetof(CPUState
, gpr
[13]) },
1323 { "r14", offsetof(CPUState
, gpr
[14]) },
1324 { "r15", offsetof(CPUState
, gpr
[15]) },
1325 { "r16", offsetof(CPUState
, gpr
[16]) },
1326 { "r17", offsetof(CPUState
, gpr
[17]) },
1327 { "r18", offsetof(CPUState
, gpr
[18]) },
1328 { "r19", offsetof(CPUState
, gpr
[19]) },
1329 { "r20", offsetof(CPUState
, gpr
[20]) },
1330 { "r21", offsetof(CPUState
, gpr
[21]) },
1331 { "r22", offsetof(CPUState
, gpr
[22]) },
1332 { "r23", offsetof(CPUState
, gpr
[23]) },
1333 { "r24", offsetof(CPUState
, gpr
[24]) },
1334 { "r25", offsetof(CPUState
, gpr
[25]) },
1335 { "r26", offsetof(CPUState
, gpr
[26]) },
1336 { "r27", offsetof(CPUState
, gpr
[27]) },
1337 { "r28", offsetof(CPUState
, gpr
[28]) },
1338 { "r29", offsetof(CPUState
, gpr
[29]) },
1339 { "r30", offsetof(CPUState
, gpr
[30]) },
1340 { "r31", offsetof(CPUState
, gpr
[31]) },
1341 { "nip|pc", offsetof(CPUState
, nip
) },
1342 { "lr", offsetof(CPUState
, lr
) },
1343 { "ctr", offsetof(CPUState
, ctr
) },
1344 { "decr", 0, &monitor_get_decr
, },
1345 { "ccr", 0, &monitor_get_ccr
, },
1346 { "msr", 0, &monitor_get_msr
, },
1347 { "xer", 0, &monitor_get_xer
, },
1348 { "tbu", 0, &monitor_get_tbu
, },
1349 { "tbl", 0, &monitor_get_tbl
, },
1350 { "sdr1", offsetof(CPUState
, sdr1
) },
1351 { "sr0", offsetof(CPUState
, sr
[0]) },
1352 { "sr1", offsetof(CPUState
, sr
[1]) },
1353 { "sr2", offsetof(CPUState
, sr
[2]) },
1354 { "sr3", offsetof(CPUState
, sr
[3]) },
1355 { "sr4", offsetof(CPUState
, sr
[4]) },
1356 { "sr5", offsetof(CPUState
, sr
[5]) },
1357 { "sr6", offsetof(CPUState
, sr
[6]) },
1358 { "sr7", offsetof(CPUState
, sr
[7]) },
1359 { "sr8", offsetof(CPUState
, sr
[8]) },
1360 { "sr9", offsetof(CPUState
, sr
[9]) },
1361 { "sr10", offsetof(CPUState
, sr
[10]) },
1362 { "sr11", offsetof(CPUState
, sr
[11]) },
1363 { "sr12", offsetof(CPUState
, sr
[12]) },
1364 { "sr13", offsetof(CPUState
, sr
[13]) },
1365 { "sr14", offsetof(CPUState
, sr
[14]) },
1366 { "sr15", offsetof(CPUState
, sr
[15]) },
1367 /* Too lazy to put BATs and SPRs ... */
1368 #elif defined(TARGET_SPARC)
1369 { "g0", offsetof(CPUState
, gregs
[0]) },
1370 { "g1", offsetof(CPUState
, gregs
[1]) },
1371 { "g2", offsetof(CPUState
, gregs
[2]) },
1372 { "g3", offsetof(CPUState
, gregs
[3]) },
1373 { "g4", offsetof(CPUState
, gregs
[4]) },
1374 { "g5", offsetof(CPUState
, gregs
[5]) },
1375 { "g6", offsetof(CPUState
, gregs
[6]) },
1376 { "g7", offsetof(CPUState
, gregs
[7]) },
1377 { "o0", 0, monitor_get_reg
},
1378 { "o1", 1, monitor_get_reg
},
1379 { "o2", 2, monitor_get_reg
},
1380 { "o3", 3, monitor_get_reg
},
1381 { "o4", 4, monitor_get_reg
},
1382 { "o5", 5, monitor_get_reg
},
1383 { "o6", 6, monitor_get_reg
},
1384 { "o7", 7, monitor_get_reg
},
1385 { "l0", 8, monitor_get_reg
},
1386 { "l1", 9, monitor_get_reg
},
1387 { "l2", 10, monitor_get_reg
},
1388 { "l3", 11, monitor_get_reg
},
1389 { "l4", 12, monitor_get_reg
},
1390 { "l5", 13, monitor_get_reg
},
1391 { "l6", 14, monitor_get_reg
},
1392 { "l7", 15, monitor_get_reg
},
1393 { "i0", 16, monitor_get_reg
},
1394 { "i1", 17, monitor_get_reg
},
1395 { "i2", 18, monitor_get_reg
},
1396 { "i3", 19, monitor_get_reg
},
1397 { "i4", 20, monitor_get_reg
},
1398 { "i5", 21, monitor_get_reg
},
1399 { "i6", 22, monitor_get_reg
},
1400 { "i7", 23, monitor_get_reg
},
1401 { "pc", offsetof(CPUState
, pc
) },
1402 { "npc", offsetof(CPUState
, npc
) },
1403 { "y", offsetof(CPUState
, y
) },
1404 #ifndef TARGET_SPARC64
1405 { "psr", 0, &monitor_get_psr
, },
1406 { "wim", offsetof(CPUState
, wim
) },
1408 { "tbr", offsetof(CPUState
, tbr
) },
1409 { "fsr", offsetof(CPUState
, fsr
) },
1410 { "f0", offsetof(CPUState
, fpr
[0]) },
1411 { "f1", offsetof(CPUState
, fpr
[1]) },
1412 { "f2", offsetof(CPUState
, fpr
[2]) },
1413 { "f3", offsetof(CPUState
, fpr
[3]) },
1414 { "f4", offsetof(CPUState
, fpr
[4]) },
1415 { "f5", offsetof(CPUState
, fpr
[5]) },
1416 { "f6", offsetof(CPUState
, fpr
[6]) },
1417 { "f7", offsetof(CPUState
, fpr
[7]) },
1418 { "f8", offsetof(CPUState
, fpr
[8]) },
1419 { "f9", offsetof(CPUState
, fpr
[9]) },
1420 { "f10", offsetof(CPUState
, fpr
[10]) },
1421 { "f11", offsetof(CPUState
, fpr
[11]) },
1422 { "f12", offsetof(CPUState
, fpr
[12]) },
1423 { "f13", offsetof(CPUState
, fpr
[13]) },
1424 { "f14", offsetof(CPUState
, fpr
[14]) },
1425 { "f15", offsetof(CPUState
, fpr
[15]) },
1426 { "f16", offsetof(CPUState
, fpr
[16]) },
1427 { "f17", offsetof(CPUState
, fpr
[17]) },
1428 { "f18", offsetof(CPUState
, fpr
[18]) },
1429 { "f19", offsetof(CPUState
, fpr
[19]) },
1430 { "f20", offsetof(CPUState
, fpr
[20]) },
1431 { "f21", offsetof(CPUState
, fpr
[21]) },
1432 { "f22", offsetof(CPUState
, fpr
[22]) },
1433 { "f23", offsetof(CPUState
, fpr
[23]) },
1434 { "f24", offsetof(CPUState
, fpr
[24]) },
1435 { "f25", offsetof(CPUState
, fpr
[25]) },
1436 { "f26", offsetof(CPUState
, fpr
[26]) },
1437 { "f27", offsetof(CPUState
, fpr
[27]) },
1438 { "f28", offsetof(CPUState
, fpr
[28]) },
1439 { "f29", offsetof(CPUState
, fpr
[29]) },
1440 { "f30", offsetof(CPUState
, fpr
[30]) },
1441 { "f31", offsetof(CPUState
, fpr
[31]) },
1442 #ifdef TARGET_SPARC64
1443 { "f32", offsetof(CPUState
, fpr
[32]) },
1444 { "f34", offsetof(CPUState
, fpr
[34]) },
1445 { "f36", offsetof(CPUState
, fpr
[36]) },
1446 { "f38", offsetof(CPUState
, fpr
[38]) },
1447 { "f40", offsetof(CPUState
, fpr
[40]) },
1448 { "f42", offsetof(CPUState
, fpr
[42]) },
1449 { "f44", offsetof(CPUState
, fpr
[44]) },
1450 { "f46", offsetof(CPUState
, fpr
[46]) },
1451 { "f48", offsetof(CPUState
, fpr
[48]) },
1452 { "f50", offsetof(CPUState
, fpr
[50]) },
1453 { "f52", offsetof(CPUState
, fpr
[52]) },
1454 { "f54", offsetof(CPUState
, fpr
[54]) },
1455 { "f56", offsetof(CPUState
, fpr
[56]) },
1456 { "f58", offsetof(CPUState
, fpr
[58]) },
1457 { "f60", offsetof(CPUState
, fpr
[60]) },
1458 { "f62", offsetof(CPUState
, fpr
[62]) },
1459 { "asi", offsetof(CPUState
, asi
) },
1460 { "pstate", offsetof(CPUState
, pstate
) },
1461 { "cansave", offsetof(CPUState
, cansave
) },
1462 { "canrestore", offsetof(CPUState
, canrestore
) },
1463 { "otherwin", offsetof(CPUState
, otherwin
) },
1464 { "wstate", offsetof(CPUState
, wstate
) },
1465 { "cleanwin", offsetof(CPUState
, cleanwin
) },
1466 { "fprs", offsetof(CPUState
, fprs
) },
1472 static void expr_error(const char *fmt
)
1476 longjmp(expr_env
, 1);
1479 /* return 0 if OK, -1 if not found, -2 if no CPU defined */
1480 static int get_monitor_def(target_long
*pval
, const char *name
)
1485 for(md
= monitor_defs
; md
->name
!= NULL
; md
++) {
1486 if (compare_cmd(name
, md
->name
)) {
1487 if (md
->get_value
) {
1488 *pval
= md
->get_value(md
, md
->offset
);
1490 CPUState
*env
= mon_get_cpu();
1493 ptr
= (uint8_t *)env
+ md
->offset
;
1496 *pval
= *(int32_t *)ptr
;
1499 *pval
= *(target_long
*)ptr
;
1512 static void next(void)
1516 while (isspace(*pch
))
1521 static target_long
expr_sum(void);
1523 static target_long
expr_unary(void)
1546 expr_error("')' expected");
1553 expr_error("character constant expected");
1557 expr_error("missing terminating \' character");
1566 while ((*pch
>= 'a' && *pch
<= 'z') ||
1567 (*pch
>= 'A' && *pch
<= 'Z') ||
1568 (*pch
>= '0' && *pch
<= '9') ||
1569 *pch
== '_' || *pch
== '.') {
1570 if ((q
- buf
) < sizeof(buf
) - 1)
1574 while (isspace(*pch
))
1577 ret
= get_monitor_def(&n
, buf
);
1579 expr_error("unknown register");
1581 expr_error("no cpu defined");
1585 expr_error("unexpected end of expression");
1589 #if TARGET_LONG_BITS == 64
1590 n
= strtoull(pch
, &p
, 0);
1592 n
= strtoul(pch
, &p
, 0);
1595 expr_error("invalid char in expression");
1598 while (isspace(*pch
))
1606 static target_long
expr_prod(void)
1608 target_long val
, val2
;
1614 if (op
!= '*' && op
!= '/' && op
!= '%')
1617 val2
= expr_unary();
1626 expr_error("division by zero");
1637 static target_long
expr_logic(void)
1639 target_long val
, val2
;
1645 if (op
!= '&' && op
!= '|' && op
!= '^')
1665 static target_long
expr_sum(void)
1667 target_long val
, val2
;
1673 if (op
!= '+' && op
!= '-')
1676 val2
= expr_logic();
1685 static int get_expr(target_long
*pval
, const char **pp
)
1688 if (setjmp(expr_env
)) {
1692 while (isspace(*pch
))
1699 static int get_str(char *buf
, int buf_size
, const char **pp
)
1717 while (*p
!= '\0' && *p
!= '\"') {
1733 qemu_printf("unsupported escape code: '\\%c'\n", c
);
1736 if ((q
- buf
) < buf_size
- 1) {
1740 if ((q
- buf
) < buf_size
- 1) {
1747 qemu_printf("unterminated string\n");
1752 while (*p
!= '\0' && !isspace(*p
)) {
1753 if ((q
- buf
) < buf_size
- 1) {
1764 static int default_fmt_format
= 'x';
1765 static int default_fmt_size
= 4;
1769 static void monitor_handle_command(const char *cmdline
)
1771 const char *p
, *pstart
, *typestr
;
1773 int c
, nb_args
, len
, i
, has_arg
;
1777 void *str_allocated
[MAX_ARGS
];
1778 void *args
[MAX_ARGS
];
1781 term_printf("command='%s'\n", cmdline
);
1784 /* extract the command name */
1792 while (*p
!= '\0' && *p
!= '/' && !isspace(*p
))
1795 if (len
> sizeof(cmdname
) - 1)
1796 len
= sizeof(cmdname
) - 1;
1797 memcpy(cmdname
, pstart
, len
);
1798 cmdname
[len
] = '\0';
1800 /* find the command */
1801 for(cmd
= term_cmds
; cmd
->name
!= NULL
; cmd
++) {
1802 if (compare_cmd(cmdname
, cmd
->name
))
1805 term_printf("unknown command: '%s'\n", cmdname
);
1809 for(i
= 0; i
< MAX_ARGS
; i
++)
1810 str_allocated
[i
] = NULL
;
1812 /* parse the parameters */
1813 typestr
= cmd
->args_type
;
1830 if (*typestr
== '?') {
1833 /* no optional string: NULL argument */
1838 ret
= get_str(buf
, sizeof(buf
), &p
);
1842 term_printf("%s: filename expected\n", cmdname
);
1845 term_printf("%s: block device name expected\n", cmdname
);
1848 term_printf("%s: string expected\n", cmdname
);
1853 str
= qemu_malloc(strlen(buf
) + 1);
1855 str_allocated
[nb_args
] = str
;
1857 if (nb_args
>= MAX_ARGS
) {
1859 term_printf("%s: too many arguments\n", cmdname
);
1862 args
[nb_args
++] = str
;
1867 int count
, format
, size
;
1877 while (isdigit(*p
)) {
1878 count
= count
* 10 + (*p
- '0');
1916 if (*p
!= '\0' && !isspace(*p
)) {
1917 term_printf("invalid char in format: '%c'\n", *p
);
1921 format
= default_fmt_format
;
1922 if (format
!= 'i') {
1923 /* for 'i', not specifying a size gives -1 as size */
1925 size
= default_fmt_size
;
1927 default_fmt_size
= size
;
1928 default_fmt_format
= format
;
1931 format
= default_fmt_format
;
1932 if (format
!= 'i') {
1933 size
= default_fmt_size
;
1938 if (nb_args
+ 3 > MAX_ARGS
)
1940 args
[nb_args
++] = (void*)count
;
1941 args
[nb_args
++] = (void*)format
;
1942 args
[nb_args
++] = (void*)size
;
1951 if (*typestr
== '?' || *typestr
== '.') {
1953 if (*typestr
== '?') {
1968 if (nb_args
>= MAX_ARGS
)
1970 args
[nb_args
++] = (void *)has_arg
;
1972 if (nb_args
>= MAX_ARGS
)
1978 if (get_expr(&val
, &p
))
1982 if (nb_args
>= MAX_ARGS
)
1984 args
[nb_args
++] = (void *)(int)val
;
1986 if ((nb_args
+ 1) >= MAX_ARGS
)
1988 #if TARGET_LONG_BITS == 64
1989 args
[nb_args
++] = (void *)(int)((val
>> 32) & 0xffffffff);
1991 args
[nb_args
++] = (void *)0;
1993 args
[nb_args
++] = (void *)(int)(val
& 0xffffffff);
2011 term_printf("%s: unsupported option -%c\n",
2018 if (nb_args
>= MAX_ARGS
)
2020 args
[nb_args
++] = (void *)has_option
;
2025 term_printf("%s: unknown type '%c'\n", cmdname
, c
);
2029 /* check that all arguments were parsed */
2033 term_printf("%s: extraneous characters at the end of line\n",
2043 cmd
->handler(args
[0]);
2046 cmd
->handler(args
[0], args
[1]);
2049 cmd
->handler(args
[0], args
[1], args
[2]);
2052 cmd
->handler(args
[0], args
[1], args
[2], args
[3]);
2055 cmd
->handler(args
[0], args
[1], args
[2], args
[3], args
[4]);
2058 cmd
->handler(args
[0], args
[1], args
[2], args
[3], args
[4], args
[5]);
2061 term_printf("unsupported number of arguments: %d\n", nb_args
);
2065 for(i
= 0; i
< MAX_ARGS
; i
++)
2066 qemu_free(str_allocated
[i
]);
2070 static void cmd_completion(const char *name
, const char *list
)
2072 const char *p
, *pstart
;
2081 p
= pstart
+ strlen(pstart
);
2083 if (len
> sizeof(cmd
) - 2)
2084 len
= sizeof(cmd
) - 2;
2085 memcpy(cmd
, pstart
, len
);
2087 if (name
[0] == '\0' || !strncmp(name
, cmd
, strlen(name
))) {
2088 add_completion(cmd
);
2096 static void file_completion(const char *input
)
2101 char file
[1024], file_prefix
[1024];
2105 p
= strrchr(input
, '/');
2108 pstrcpy(file_prefix
, sizeof(file_prefix
), input
);
2111 input_path_len
= p
- input
+ 1;
2112 memcpy(path
, input
, input_path_len
);
2113 if (input_path_len
> sizeof(path
) - 1)
2114 input_path_len
= sizeof(path
) - 1;
2115 path
[input_path_len
] = '\0';
2116 pstrcpy(file_prefix
, sizeof(file_prefix
), p
+ 1);
2118 #ifdef DEBUG_COMPLETION
2119 term_printf("input='%s' path='%s' prefix='%s'\n", input
, path
, file_prefix
);
2121 ffs
= opendir(path
);
2129 if (strstart(d
->d_name
, file_prefix
, NULL
)) {
2130 memcpy(file
, input
, input_path_len
);
2131 strcpy(file
+ input_path_len
, d
->d_name
);
2132 /* stat the file to find out if it's a directory.
2133 * In that case add a slash to speed up typing long paths
2136 if(S_ISDIR(sb
.st_mode
))
2138 add_completion(file
);
2144 static void block_completion_it(void *opaque
, const char *name
)
2146 const char *input
= opaque
;
2148 if (input
[0] == '\0' ||
2149 !strncmp(name
, (char *)input
, strlen(input
))) {
2150 add_completion(name
);
2154 /* NOTE: this parser is an approximate form of the real command parser */
2155 static void parse_cmdline(const char *cmdline
,
2156 int *pnb_args
, char **args
)
2169 if (nb_args
>= MAX_ARGS
)
2171 ret
= get_str(buf
, sizeof(buf
), &p
);
2172 args
[nb_args
] = qemu_strdup(buf
);
2177 *pnb_args
= nb_args
;
2180 void readline_find_completion(const char *cmdline
)
2182 const char *cmdname
;
2183 char *args
[MAX_ARGS
];
2184 int nb_args
, i
, len
;
2185 const char *ptype
, *str
;
2189 parse_cmdline(cmdline
, &nb_args
, args
);
2190 #ifdef DEBUG_COMPLETION
2191 for(i
= 0; i
< nb_args
; i
++) {
2192 term_printf("arg%d = '%s'\n", i
, (char *)args
[i
]);
2196 /* if the line ends with a space, it means we want to complete the
2198 len
= strlen(cmdline
);
2199 if (len
> 0 && isspace(cmdline
[len
- 1])) {
2200 if (nb_args
>= MAX_ARGS
)
2202 args
[nb_args
++] = qemu_strdup("");
2205 /* command completion */
2210 completion_index
= strlen(cmdname
);
2211 for(cmd
= term_cmds
; cmd
->name
!= NULL
; cmd
++) {
2212 cmd_completion(cmdname
, cmd
->name
);
2215 /* find the command */
2216 for(cmd
= term_cmds
; cmd
->name
!= NULL
; cmd
++) {
2217 if (compare_cmd(args
[0], cmd
->name
))
2222 ptype
= cmd
->args_type
;
2223 for(i
= 0; i
< nb_args
- 2; i
++) {
2224 if (*ptype
!= '\0') {
2226 while (*ptype
== '?')
2230 str
= args
[nb_args
- 1];
2233 /* file completion */
2234 completion_index
= strlen(str
);
2235 file_completion(str
);
2238 /* block device name completion */
2239 completion_index
= strlen(str
);
2240 bdrv_iterate(block_completion_it
, (void *)str
);
2243 /* XXX: more generic ? */
2244 if (!strcmp(cmd
->name
, "info")) {
2245 completion_index
= strlen(str
);
2246 for(cmd
= info_cmds
; cmd
->name
!= NULL
; cmd
++) {
2247 cmd_completion(str
, cmd
->name
);
2249 } else if (!strcmp(cmd
->name
, "sendkey")) {
2250 completion_index
= strlen(str
);
2251 for(key
= key_defs
; key
->name
!= NULL
; key
++) {
2252 cmd_completion(str
, key
->name
);
2260 for(i
= 0; i
< nb_args
; i
++)
2264 static int term_can_read(void *opaque
)
2269 static void term_read(void *opaque
, const uint8_t *buf
, int size
)
2272 for(i
= 0; i
< size
; i
++)
2273 readline_handle_byte(buf
[i
]);
2276 static void monitor_start_input(void);
2278 static void monitor_handle_command1(void *opaque
, const char *cmdline
)
2280 monitor_handle_command(cmdline
);
2281 monitor_start_input();
2284 static void monitor_start_input(void)
2286 readline_start("(qemu) ", 0, monitor_handle_command1
, NULL
);
2289 void monitor_init(CharDriverState
*hd
, int show_banner
)
2293 term_printf("QEMU %s monitor - type 'help' for more information\n",
2296 qemu_chr_add_read_handler(hd
, term_can_read
, term_read
, NULL
);
2297 monitor_start_input();
2300 /* XXX: use threads ? */
2301 /* modal monitor readline */
2302 static int monitor_readline_started
;
2303 static char *monitor_readline_buf
;
2304 static int monitor_readline_buf_size
;
2306 static void monitor_readline_cb(void *opaque
, const char *input
)
2308 pstrcpy(monitor_readline_buf
, monitor_readline_buf_size
, input
);
2309 monitor_readline_started
= 0;
2312 void monitor_readline(const char *prompt
, int is_password
,
2313 char *buf
, int buf_size
)
2316 qemu_chr_send_event(monitor_hd
, CHR_EVENT_FOCUS
);
2318 readline_start(prompt
, is_password
, monitor_readline_cb
, NULL
);
2319 monitor_readline_buf
= buf
;
2320 monitor_readline_buf_size
= buf_size
;
2321 monitor_readline_started
= 1;
2322 while (monitor_readline_started
) {