]> git.proxmox.com Git - mirror_qemu.git/blob - monitor.c
generate CRLF instead of LF
[mirror_qemu.git] / monitor.c
1 /*
2 * QEMU monitor
3 *
4 * Copyright (c) 2003-2004 Fabrice Bellard
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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
22 * THE SOFTWARE.
23 */
24 #include "vl.h"
25 #include "disas.h"
26 #include <dirent.h>
27
28 //#define DEBUG
29 //#define DEBUG_COMPLETION
30
31 #ifndef offsetof
32 #define offsetof(type, field) ((size_t) &((type *)0)->field)
33 #endif
34
35 /*
36 * Supported types:
37 *
38 * 'F' filename
39 * 'B' block device name
40 * 's' string (accept optional quote)
41 * 'i' 32 bit integer
42 * 'l' target long (32 or 64 bit)
43 * '/' optional gdb-like print format (like "/10x")
44 *
45 * '?' optional type (for 'F', 's' and 'i')
46 *
47 */
48
49 typedef struct term_cmd_t {
50 const char *name;
51 const char *args_type;
52 void (*handler)();
53 const char *params;
54 const char *help;
55 } term_cmd_t;
56
57 static CharDriverState *monitor_hd;
58
59 static term_cmd_t term_cmds[];
60 static term_cmd_t info_cmds[];
61
62 static char term_outbuf[1024];
63 static int term_outbuf_index;
64
65 static void monitor_start_input(void);
66
67 CPUState *mon_cpu = NULL;
68
69 void term_flush(void)
70 {
71 if (term_outbuf_index > 0) {
72 qemu_chr_write(monitor_hd, term_outbuf, term_outbuf_index);
73 term_outbuf_index = 0;
74 }
75 }
76
77 /* flush at every end of line or if the buffer is full */
78 void term_puts(const char *str)
79 {
80 int c;
81 for(;;) {
82 c = *str++;
83 if (c == '\0')
84 break;
85 if (c == '\n')
86 term_outbuf[term_outbuf_index++] = '\r';
87 term_outbuf[term_outbuf_index++] = c;
88 if (term_outbuf_index >= (sizeof(term_outbuf) - 1) ||
89 c == '\n')
90 term_flush();
91 }
92 }
93
94 void term_vprintf(const char *fmt, va_list ap)
95 {
96 char buf[4096];
97 vsnprintf(buf, sizeof(buf), fmt, ap);
98 term_puts(buf);
99 }
100
101 void term_printf(const char *fmt, ...)
102 {
103 va_list ap;
104 va_start(ap, fmt);
105 term_vprintf(fmt, ap);
106 va_end(ap);
107 }
108
109 static int monitor_fprintf(FILE *stream, const char *fmt, ...)
110 {
111 va_list ap;
112 va_start(ap, fmt);
113 term_vprintf(fmt, ap);
114 va_end(ap);
115 return 0;
116 }
117
118 static int compare_cmd(const char *name, const char *list)
119 {
120 const char *p, *pstart;
121 int len;
122 len = strlen(name);
123 p = list;
124 for(;;) {
125 pstart = p;
126 p = strchr(p, '|');
127 if (!p)
128 p = pstart + strlen(pstart);
129 if ((p - pstart) == len && !memcmp(pstart, name, len))
130 return 1;
131 if (*p == '\0')
132 break;
133 p++;
134 }
135 return 0;
136 }
137
138 static void help_cmd1(term_cmd_t *cmds, const char *prefix, const char *name)
139 {
140 term_cmd_t *cmd;
141
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);
145 }
146 }
147
148 static void help_cmd(const char *name)
149 {
150 if (name && !strcmp(name, "info")) {
151 help_cmd1(info_cmds, "info ", NULL);
152 } else {
153 help_cmd1(term_cmds, "", name);
154 if (name && !strcmp(name, "log")) {
155 CPULogItem *item;
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);
160 }
161 }
162 }
163 }
164
165 static void do_help(const char *name)
166 {
167 help_cmd(name);
168 }
169
170 static void do_commit(void)
171 {
172 int i;
173
174 for (i = 0; i < MAX_DISKS; i++) {
175 if (bs_table[i]) {
176 bdrv_commit(bs_table[i]);
177 }
178 }
179 }
180
181 static void do_info(const char *item)
182 {
183 term_cmd_t *cmd;
184
185 if (!item)
186 goto help;
187 for(cmd = info_cmds; cmd->name != NULL; cmd++) {
188 if (compare_cmd(item, cmd->name))
189 goto found;
190 }
191 help:
192 help_cmd("info");
193 return;
194 found:
195 cmd->handler();
196 }
197
198 static void do_info_version(void)
199 {
200 term_printf("%s\n", QEMU_VERSION);
201 }
202
203 static void do_info_block(void)
204 {
205 bdrv_info();
206 }
207
208 /* get the current CPU defined by the user */
209 int mon_set_cpu(int cpu_index)
210 {
211 CPUState *env;
212
213 for(env = first_cpu; env != NULL; env = env->next_cpu) {
214 if (env->cpu_index == cpu_index) {
215 mon_cpu = env;
216 return 0;
217 }
218 }
219 return -1;
220 }
221
222 CPUState *mon_get_cpu(void)
223 {
224 if (!mon_cpu) {
225 mon_set_cpu(0);
226 }
227 return mon_cpu;
228 }
229
230 static void do_info_registers(void)
231 {
232 CPUState *env;
233 env = mon_get_cpu();
234 if (!env)
235 return;
236 #ifdef TARGET_I386
237 cpu_dump_state(env, NULL, monitor_fprintf,
238 X86_DUMP_FPU);
239 #else
240 cpu_dump_state(env, NULL, monitor_fprintf,
241 0);
242 #endif
243 }
244
245 static void do_info_cpus(void)
246 {
247 CPUState *env;
248
249 /* just to set the default cpu if not already done */
250 mon_get_cpu();
251
252 for(env = first_cpu; env != NULL; env = env->next_cpu) {
253 term_printf("%c CPU #%d:",
254 (env == mon_cpu) ? '*' : ' ',
255 env->cpu_index);
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);
262 if (env->halted)
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);
266 if (env->halted)
267 term_printf(" (halted)");
268 #endif
269 term_printf("\n");
270 }
271 }
272
273 static void do_cpu_set(int index)
274 {
275 if (mon_set_cpu(index) < 0)
276 term_printf("Invalid CPU index\n");
277 }
278
279 static void do_info_jit(void)
280 {
281 dump_exec_info(NULL, monitor_fprintf);
282 }
283
284 static void do_info_history (void)
285 {
286 int i;
287 const char *str;
288
289 i = 0;
290 for(;;) {
291 str = readline_get_history(i);
292 if (!str)
293 break;
294 term_printf("%d: '%s'\n", i, str);
295 i++;
296 }
297 }
298
299 static void do_quit(void)
300 {
301 exit(0);
302 }
303
304 static int eject_device(BlockDriverState *bs, int force)
305 {
306 if (bdrv_is_inserted(bs)) {
307 if (!force) {
308 if (!bdrv_is_removable(bs)) {
309 term_printf("device is not removable\n");
310 return -1;
311 }
312 if (bdrv_is_locked(bs)) {
313 term_printf("device is locked\n");
314 return -1;
315 }
316 }
317 bdrv_close(bs);
318 }
319 return 0;
320 }
321
322 static void do_eject(int force, const char *filename)
323 {
324 BlockDriverState *bs;
325
326 bs = bdrv_find(filename);
327 if (!bs) {
328 term_printf("device not found\n");
329 return;
330 }
331 eject_device(bs, force);
332 }
333
334 static void do_change(const char *device, const char *filename)
335 {
336 BlockDriverState *bs;
337 int i;
338 char password[256];
339
340 bs = bdrv_find(device);
341 if (!bs) {
342 term_printf("device not found\n");
343 return;
344 }
345 if (eject_device(bs, 0) < 0)
346 return;
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)
353 break;
354 term_printf("invalid password\n");
355 }
356 }
357 }
358
359 static void do_screen_dump(const char *filename)
360 {
361 vga_hw_screen_dump(filename);
362 }
363
364 static void do_log(const char *items)
365 {
366 int mask;
367
368 if (!strcmp(items, "none")) {
369 mask = 0;
370 } else {
371 mask = cpu_str_to_log_mask(items);
372 if (!mask) {
373 help_cmd("log");
374 return;
375 }
376 }
377 cpu_set_log(mask);
378 }
379
380 static void do_savevm(const char *filename)
381 {
382 if (qemu_savevm(filename) < 0)
383 term_printf("I/O error when saving VM to '%s'\n", filename);
384 }
385
386 static void do_loadvm(const char *filename)
387 {
388 if (qemu_loadvm(filename) < 0)
389 term_printf("I/O error when loading VM from '%s'\n", filename);
390 }
391
392 static void do_stop(void)
393 {
394 vm_stop(EXCP_INTERRUPT);
395 }
396
397 static void do_cont(void)
398 {
399 vm_start();
400 }
401
402 #ifdef CONFIG_GDBSTUB
403 static void do_gdbserver(int has_port, int port)
404 {
405 if (!has_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);
409 } else {
410 qemu_printf("Waiting gdb connection on port %d\n", port);
411 }
412 }
413 #endif
414
415 static void term_printc(int c)
416 {
417 term_printf("'");
418 switch(c) {
419 case '\'':
420 term_printf("\\'");
421 break;
422 case '\\':
423 term_printf("\\\\");
424 break;
425 case '\n':
426 term_printf("\\n");
427 break;
428 case '\r':
429 term_printf("\\r");
430 break;
431 default:
432 if (c >= 32 && c <= 126) {
433 term_printf("%c", c);
434 } else {
435 term_printf("\\x%02x", c);
436 }
437 break;
438 }
439 term_printf("'");
440 }
441
442 static void memory_dump(int count, int format, int wsize,
443 target_ulong addr, int is_physical)
444 {
445 CPUState *env;
446 int nb_per_line, l, line_size, i, max_digits, len;
447 uint8_t buf[16];
448 uint64_t v;
449
450 if (format == 'i') {
451 int flags;
452 flags = 0;
453 env = mon_get_cpu();
454 if (!env && !is_physical)
455 return;
456 #ifdef TARGET_I386
457 if (wsize == 2) {
458 flags = 1;
459 } else if (wsize == 4) {
460 flags = 0;
461 } else {
462 /* as default we use the current CS size */
463 flags = 0;
464 if (env) {
465 #ifdef TARGET_X86_64
466 if ((env->efer & MSR_EFER_LMA) &&
467 (env->segs[R_CS].flags & DESC_L_MASK))
468 flags = 2;
469 else
470 #endif
471 if (!(env->segs[R_CS].flags & DESC_B_MASK))
472 flags = 1;
473 }
474 }
475 #endif
476 monitor_disas(env, addr, count, is_physical, flags);
477 return;
478 }
479
480 len = wsize * count;
481 if (wsize == 1)
482 line_size = 8;
483 else
484 line_size = 16;
485 nb_per_line = line_size / wsize;
486 max_digits = 0;
487
488 switch(format) {
489 case 'o':
490 max_digits = (wsize * 8 + 2) / 3;
491 break;
492 default:
493 case 'x':
494 max_digits = (wsize * 8) / 4;
495 break;
496 case 'u':
497 case 'd':
498 max_digits = (wsize * 8 * 10 + 32) / 33;
499 break;
500 case 'c':
501 wsize = 1;
502 break;
503 }
504
505 while (len > 0) {
506 term_printf(TARGET_FMT_lx ":", addr);
507 l = len;
508 if (l > line_size)
509 l = line_size;
510 if (is_physical) {
511 cpu_physical_memory_rw(addr, buf, l, 0);
512 } else {
513 env = mon_get_cpu();
514 if (!env)
515 break;
516 cpu_memory_rw_debug(env, addr, buf, l, 0);
517 }
518 i = 0;
519 while (i < l) {
520 switch(wsize) {
521 default:
522 case 1:
523 v = ldub_raw(buf + i);
524 break;
525 case 2:
526 v = lduw_raw(buf + i);
527 break;
528 case 4:
529 v = (uint32_t)ldl_raw(buf + i);
530 break;
531 case 8:
532 v = ldq_raw(buf + i);
533 break;
534 }
535 term_printf(" ");
536 switch(format) {
537 case 'o':
538 term_printf("%#*" PRIo64, max_digits, v);
539 break;
540 case 'x':
541 term_printf("0x%0*" PRIx64, max_digits, v);
542 break;
543 case 'u':
544 term_printf("%*" PRIu64, max_digits, v);
545 break;
546 case 'd':
547 term_printf("%*" PRId64, max_digits, v);
548 break;
549 case 'c':
550 term_printc(v);
551 break;
552 }
553 i += wsize;
554 }
555 term_printf("\n");
556 addr += l;
557 len -= l;
558 }
559 }
560
561 #if TARGET_LONG_BITS == 64
562 #define GET_TLONG(h, l) (((uint64_t)(h) << 32) | (l))
563 #else
564 #define GET_TLONG(h, l) (l)
565 #endif
566
567 static void do_memory_dump(int count, int format, int size,
568 uint32_t addrh, uint32_t addrl)
569 {
570 target_long addr = GET_TLONG(addrh, addrl);
571 memory_dump(count, format, size, addr, 0);
572 }
573
574 static void do_physical_memory_dump(int count, int format, int size,
575 uint32_t addrh, uint32_t addrl)
576
577 {
578 target_long addr = GET_TLONG(addrh, addrl);
579 memory_dump(count, format, size, addr, 1);
580 }
581
582 static void do_print(int count, int format, int size, unsigned int valh, unsigned int vall)
583 {
584 target_long val = GET_TLONG(valh, vall);
585 #if TARGET_LONG_BITS == 32
586 switch(format) {
587 case 'o':
588 term_printf("%#o", val);
589 break;
590 case 'x':
591 term_printf("%#x", val);
592 break;
593 case 'u':
594 term_printf("%u", val);
595 break;
596 default:
597 case 'd':
598 term_printf("%d", val);
599 break;
600 case 'c':
601 term_printc(val);
602 break;
603 }
604 #else
605 switch(format) {
606 case 'o':
607 term_printf("%#" PRIo64, val);
608 break;
609 case 'x':
610 term_printf("%#" PRIx64, val);
611 break;
612 case 'u':
613 term_printf("%" PRIu64, val);
614 break;
615 default:
616 case 'd':
617 term_printf("%" PRId64, val);
618 break;
619 case 'c':
620 term_printc(val);
621 break;
622 }
623 #endif
624 term_printf("\n");
625 }
626
627 static void do_sum(uint32_t start, uint32_t size)
628 {
629 uint32_t addr;
630 uint8_t buf[1];
631 uint16_t sum;
632
633 sum = 0;
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);
638 sum += buf[0];
639 }
640 term_printf("%05d\n", sum);
641 }
642
643 typedef struct {
644 int keycode;
645 const char *name;
646 } KeyDef;
647
648 static const KeyDef key_defs[] = {
649 { 0x2a, "shift" },
650 { 0x36, "shift_r" },
651
652 { 0x38, "alt" },
653 { 0xb8, "alt_r" },
654 { 0x1d, "ctrl" },
655 { 0x9d, "ctrl_r" },
656
657 { 0xdd, "menu" },
658
659 { 0x01, "esc" },
660
661 { 0x02, "1" },
662 { 0x03, "2" },
663 { 0x04, "3" },
664 { 0x05, "4" },
665 { 0x06, "5" },
666 { 0x07, "6" },
667 { 0x08, "7" },
668 { 0x09, "8" },
669 { 0x0a, "9" },
670 { 0x0b, "0" },
671 { 0x0c, "minus" },
672 { 0x0d, "equal" },
673 { 0x0e, "backspace" },
674
675 { 0x0f, "tab" },
676 { 0x10, "q" },
677 { 0x11, "w" },
678 { 0x12, "e" },
679 { 0x13, "r" },
680 { 0x14, "t" },
681 { 0x15, "y" },
682 { 0x16, "u" },
683 { 0x17, "i" },
684 { 0x18, "o" },
685 { 0x19, "p" },
686
687 { 0x1c, "ret" },
688
689 { 0x1e, "a" },
690 { 0x1f, "s" },
691 { 0x20, "d" },
692 { 0x21, "f" },
693 { 0x22, "g" },
694 { 0x23, "h" },
695 { 0x24, "j" },
696 { 0x25, "k" },
697 { 0x26, "l" },
698
699 { 0x2c, "z" },
700 { 0x2d, "x" },
701 { 0x2e, "c" },
702 { 0x2f, "v" },
703 { 0x30, "b" },
704 { 0x31, "n" },
705 { 0x32, "m" },
706
707 { 0x39, "spc" },
708 { 0x3a, "caps_lock" },
709 { 0x3b, "f1" },
710 { 0x3c, "f2" },
711 { 0x3d, "f3" },
712 { 0x3e, "f4" },
713 { 0x3f, "f5" },
714 { 0x40, "f6" },
715 { 0x41, "f7" },
716 { 0x42, "f8" },
717 { 0x43, "f9" },
718 { 0x44, "f10" },
719 { 0x45, "num_lock" },
720 { 0x46, "scroll_lock" },
721
722 { 0xb5, "kp_divide" },
723 { 0x37, "kp_multiply" },
724 { 0x4a, "kp_substract" },
725 { 0x4e, "kp_add" },
726 { 0x9c, "kp_enter" },
727 { 0x53, "kp_decimal" },
728
729 { 0x52, "kp_0" },
730 { 0x4f, "kp_1" },
731 { 0x50, "kp_2" },
732 { 0x51, "kp_3" },
733 { 0x4b, "kp_4" },
734 { 0x4c, "kp_5" },
735 { 0x4d, "kp_6" },
736 { 0x47, "kp_7" },
737 { 0x48, "kp_8" },
738 { 0x49, "kp_9" },
739
740 { 0x56, "<" },
741
742 { 0x57, "f11" },
743 { 0x58, "f12" },
744
745 { 0xb7, "print" },
746
747 { 0xc7, "home" },
748 { 0xc9, "pgup" },
749 { 0xd1, "pgdn" },
750 { 0xcf, "end" },
751
752 { 0xcb, "left" },
753 { 0xc8, "up" },
754 { 0xd0, "down" },
755 { 0xcd, "right" },
756
757 { 0xd2, "insert" },
758 { 0xd3, "delete" },
759 { 0, NULL },
760 };
761
762 static int get_keycode(const char *key)
763 {
764 const KeyDef *p;
765 char *endp;
766 int ret;
767
768 for(p = key_defs; p->name != NULL; p++) {
769 if (!strcmp(key, p->name))
770 return p->keycode;
771 }
772 if (strstart(key, "0x", NULL)) {
773 ret = strtoul(key, &endp, 0);
774 if (*endp == '\0' && ret >= 0x01 && ret <= 0xff)
775 return ret;
776 }
777 return -1;
778 }
779
780 static void do_send_key(const char *string)
781 {
782 char keybuf[16], *q;
783 uint8_t keycodes[16];
784 const char *p;
785 int nb_keycodes, keycode, i;
786
787 nb_keycodes = 0;
788 p = string;
789 while (*p != '\0') {
790 q = keybuf;
791 while (*p != '\0' && *p != '-') {
792 if ((q - keybuf) < sizeof(keybuf) - 1) {
793 *q++ = *p;
794 }
795 p++;
796 }
797 *q = '\0';
798 keycode = get_keycode(keybuf);
799 if (keycode < 0) {
800 term_printf("unknown key: '%s'\n", keybuf);
801 return;
802 }
803 keycodes[nb_keycodes++] = keycode;
804 if (*p == '\0')
805 break;
806 p++;
807 }
808 /* key down events */
809 for(i = 0; i < nb_keycodes; i++) {
810 keycode = keycodes[i];
811 if (keycode & 0x80)
812 kbd_put_keycode(0xe0);
813 kbd_put_keycode(keycode & 0x7f);
814 }
815 /* key up events */
816 for(i = nb_keycodes - 1; i >= 0; i--) {
817 keycode = keycodes[i];
818 if (keycode & 0x80)
819 kbd_put_keycode(0xe0);
820 kbd_put_keycode(keycode | 0x80);
821 }
822 }
823
824 static void do_ioport_read(int count, int format, int size, int addr, int has_index, int index)
825 {
826 uint32_t val;
827 int suffix;
828
829 if (has_index) {
830 cpu_outb(NULL, addr & 0xffff, index & 0xff);
831 addr++;
832 }
833 addr &= 0xffff;
834
835 switch(size) {
836 default:
837 case 1:
838 val = cpu_inb(NULL, addr);
839 suffix = 'b';
840 break;
841 case 2:
842 val = cpu_inw(NULL, addr);
843 suffix = 'w';
844 break;
845 case 4:
846 val = cpu_inl(NULL, addr);
847 suffix = 'l';
848 break;
849 }
850 term_printf("port%c[0x%04x] = %#0*x\n",
851 suffix, addr, size * 2, val);
852 }
853
854 static void do_system_reset(void)
855 {
856 qemu_system_reset_request();
857 }
858
859 static void do_system_powerdown(void)
860 {
861 qemu_system_powerdown_request();
862 }
863
864 #if defined(TARGET_I386)
865 static void print_pte(uint32_t addr, uint32_t pte, uint32_t mask)
866 {
867 term_printf("%08x: %08x %c%c%c%c%c%c%c%c\n",
868 addr,
869 pte & mask,
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' : '-');
878 }
879
880 static void tlb_info(void)
881 {
882 CPUState *env;
883 int l1, l2;
884 uint32_t pgd, pde, pte;
885
886 env = mon_get_cpu();
887 if (!env)
888 return;
889
890 if (!(env->cr[0] & CR0_PG_MASK)) {
891 term_printf("PG disabled\n");
892 return;
893 }
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));
901 } else {
902 for(l2 = 0; l2 < 1024; l2++) {
903 cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
904 (uint8_t *)&pte, 4);
905 pte = le32_to_cpu(pte);
906 if (pte & PG_PRESENT_MASK) {
907 print_pte((l1 << 22) + (l2 << 12),
908 pte & ~PG_PSE_MASK,
909 ~0xfff);
910 }
911 }
912 }
913 }
914 }
915 }
916
917 static void mem_print(uint32_t *pstart, int *plast_prot,
918 uint32_t end, int prot)
919 {
920 int prot1;
921 prot1 = *plast_prot;
922 if (prot != prot1) {
923 if (*pstart != -1) {
924 term_printf("%08x-%08x %08x %c%c%c\n",
925 *pstart, end, end - *pstart,
926 prot1 & PG_USER_MASK ? 'u' : '-',
927 'r',
928 prot1 & PG_RW_MASK ? 'w' : '-');
929 }
930 if (prot != 0)
931 *pstart = end;
932 else
933 *pstart = -1;
934 *plast_prot = prot;
935 }
936 }
937
938 static void mem_info(void)
939 {
940 CPUState *env;
941 int l1, l2, prot, last_prot;
942 uint32_t pgd, pde, pte, start, end;
943
944 env = mon_get_cpu();
945 if (!env)
946 return;
947
948 if (!(env->cr[0] & CR0_PG_MASK)) {
949 term_printf("PG disabled\n");
950 return;
951 }
952 pgd = env->cr[3] & ~0xfff;
953 last_prot = 0;
954 start = -1;
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);
958 end = l1 << 22;
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);
963 } else {
964 for(l2 = 0; l2 < 1024; l2++) {
965 cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
966 (uint8_t *)&pte, 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);
971 } else {
972 prot = 0;
973 }
974 mem_print(&start, &last_prot, end, prot);
975 }
976 }
977 } else {
978 prot = 0;
979 mem_print(&start, &last_prot, end, prot);
980 }
981 }
982 }
983 #endif
984
985 static void do_info_kqemu(void)
986 {
987 #ifdef USE_KQEMU
988 CPUState *env;
989 int val;
990 val = 0;
991 env = mon_get_cpu();
992 if (!env) {
993 term_printf("No cpu initialized yet");
994 return;
995 }
996 val = env->kqemu_enabled;
997 term_printf("kqemu support: ");
998 switch(val) {
999 default:
1000 case 0:
1001 term_printf("disabled\n");
1002 break;
1003 case 1:
1004 term_printf("enabled for user code\n");
1005 break;
1006 case 2:
1007 term_printf("enabled for user and kernel code\n");
1008 break;
1009 }
1010 #else
1011 term_printf("kqemu support: not compiled\n");
1012 #endif
1013 }
1014
1015 #ifdef CONFIG_PROFILER
1016
1017 int64_t kqemu_time;
1018 int64_t qemu_time;
1019 int64_t kqemu_exec_count;
1020 int64_t dev_time;
1021 int64_t kqemu_ret_int_count;
1022 int64_t kqemu_ret_excp_count;
1023 int64_t kqemu_ret_intr_count;
1024
1025 static void do_info_profile(void)
1026 {
1027 int64_t total;
1028 total = qemu_time;
1029 if (total == 0)
1030 total = 1;
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,
1038 kqemu_exec_count,
1039 kqemu_ret_int_count,
1040 kqemu_ret_excp_count,
1041 kqemu_ret_intr_count);
1042 qemu_time = 0;
1043 kqemu_time = 0;
1044 kqemu_exec_count = 0;
1045 dev_time = 0;
1046 kqemu_ret_int_count = 0;
1047 kqemu_ret_excp_count = 0;
1048 kqemu_ret_intr_count = 0;
1049 #ifdef USE_KQEMU
1050 kqemu_record_dump();
1051 #endif
1052 }
1053 #else
1054 static void do_info_profile(void)
1055 {
1056 term_printf("Internal profiler not compiled\n");
1057 }
1058 #endif
1059
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)", },
1088 #endif
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" },
1097
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" },
1112 { NULL, NULL, },
1113 };
1114
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", },
1139 #endif
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", },
1150 { NULL, NULL, },
1151 };
1152
1153 /*******************************************************************/
1154
1155 static const char *pch;
1156 static jmp_buf expr_env;
1157
1158 #define MD_TLONG 0
1159 #define MD_I32 1
1160
1161 typedef struct MonitorDef {
1162 const char *name;
1163 int offset;
1164 target_long (*get_value)(struct MonitorDef *md, int val);
1165 int type;
1166 } MonitorDef;
1167
1168 #if defined(TARGET_I386)
1169 static target_long monitor_get_pc (struct MonitorDef *md, int val)
1170 {
1171 CPUState *env = mon_get_cpu();
1172 if (!env)
1173 return 0;
1174 return env->eip + env->segs[R_CS].base;
1175 }
1176 #endif
1177
1178 #if defined(TARGET_PPC)
1179 static target_long monitor_get_ccr (struct MonitorDef *md, int val)
1180 {
1181 CPUState *env = mon_get_cpu();
1182 unsigned int u;
1183 int i;
1184
1185 if (!env)
1186 return 0;
1187
1188 u = 0;
1189 for (i = 0; i < 8; i++)
1190 u |= env->crf[i] << (32 - (4 * i));
1191
1192 return u;
1193 }
1194
1195 static target_long monitor_get_msr (struct MonitorDef *md, int val)
1196 {
1197 CPUState *env = mon_get_cpu();
1198 if (!env)
1199 return 0;
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);
1215 }
1216
1217 static target_long monitor_get_xer (struct MonitorDef *md, int val)
1218 {
1219 CPUState *env = mon_get_cpu();
1220 if (!env)
1221 return 0;
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);
1226 }
1227
1228 static target_long monitor_get_decr (struct MonitorDef *md, int val)
1229 {
1230 CPUState *env = mon_get_cpu();
1231 if (!env)
1232 return 0;
1233 return cpu_ppc_load_decr(env);
1234 }
1235
1236 static target_long monitor_get_tbu (struct MonitorDef *md, int val)
1237 {
1238 CPUState *env = mon_get_cpu();
1239 if (!env)
1240 return 0;
1241 return cpu_ppc_load_tbu(env);
1242 }
1243
1244 static target_long monitor_get_tbl (struct MonitorDef *md, int val)
1245 {
1246 CPUState *env = mon_get_cpu();
1247 if (!env)
1248 return 0;
1249 return cpu_ppc_load_tbl(env);
1250 }
1251 #endif
1252
1253 #if defined(TARGET_SPARC)
1254 #ifndef TARGET_SPARC64
1255 static target_long monitor_get_psr (struct MonitorDef *md, int val)
1256 {
1257 CPUState *env = mon_get_cpu();
1258 if (!env)
1259 return 0;
1260 return GET_PSR(env);
1261 }
1262 #endif
1263
1264 static target_long monitor_get_reg(struct MonitorDef *md, int val)
1265 {
1266 CPUState *env = mon_get_cpu();
1267 if (!env)
1268 return 0;
1269 return env->regwptr[val];
1270 }
1271 #endif
1272
1273 static MonitorDef monitor_defs[] = {
1274 #ifdef TARGET_I386
1275
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 },
1280
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]) },
1298 #endif
1299 { "eflags", offsetof(CPUState, eflags) },
1300 { "eip", offsetof(CPUState, eip) },
1301 SEG("cs", R_CS)
1302 SEG("ds", R_DS)
1303 SEG("es", R_ES)
1304 SEG("ss", R_SS)
1305 SEG("fs", R_FS)
1306 SEG("gs", R_GS)
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) },
1407 #endif
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) },
1467 #endif
1468 #endif
1469 { NULL },
1470 };
1471
1472 static void expr_error(const char *fmt)
1473 {
1474 term_printf(fmt);
1475 term_printf("\n");
1476 longjmp(expr_env, 1);
1477 }
1478
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)
1481 {
1482 MonitorDef *md;
1483 void *ptr;
1484
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);
1489 } else {
1490 CPUState *env = mon_get_cpu();
1491 if (!env)
1492 return -2;
1493 ptr = (uint8_t *)env + md->offset;
1494 switch(md->type) {
1495 case MD_I32:
1496 *pval = *(int32_t *)ptr;
1497 break;
1498 case MD_TLONG:
1499 *pval = *(target_long *)ptr;
1500 break;
1501 default:
1502 *pval = 0;
1503 break;
1504 }
1505 }
1506 return 0;
1507 }
1508 }
1509 return -1;
1510 }
1511
1512 static void next(void)
1513 {
1514 if (pch != '\0') {
1515 pch++;
1516 while (isspace(*pch))
1517 pch++;
1518 }
1519 }
1520
1521 static target_long expr_sum(void);
1522
1523 static target_long expr_unary(void)
1524 {
1525 target_long n;
1526 char *p;
1527 int ret;
1528
1529 switch(*pch) {
1530 case '+':
1531 next();
1532 n = expr_unary();
1533 break;
1534 case '-':
1535 next();
1536 n = -expr_unary();
1537 break;
1538 case '~':
1539 next();
1540 n = ~expr_unary();
1541 break;
1542 case '(':
1543 next();
1544 n = expr_sum();
1545 if (*pch != ')') {
1546 expr_error("')' expected");
1547 }
1548 next();
1549 break;
1550 case '\'':
1551 pch++;
1552 if (*pch == '\0')
1553 expr_error("character constant expected");
1554 n = *pch;
1555 pch++;
1556 if (*pch != '\'')
1557 expr_error("missing terminating \' character");
1558 next();
1559 break;
1560 case '$':
1561 {
1562 char buf[128], *q;
1563
1564 pch++;
1565 q = buf;
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)
1571 *q++ = *pch;
1572 pch++;
1573 }
1574 while (isspace(*pch))
1575 pch++;
1576 *q = 0;
1577 ret = get_monitor_def(&n, buf);
1578 if (ret == -1)
1579 expr_error("unknown register");
1580 else if (ret == -2)
1581 expr_error("no cpu defined");
1582 }
1583 break;
1584 case '\0':
1585 expr_error("unexpected end of expression");
1586 n = 0;
1587 break;
1588 default:
1589 #if TARGET_LONG_BITS == 64
1590 n = strtoull(pch, &p, 0);
1591 #else
1592 n = strtoul(pch, &p, 0);
1593 #endif
1594 if (pch == p) {
1595 expr_error("invalid char in expression");
1596 }
1597 pch = p;
1598 while (isspace(*pch))
1599 pch++;
1600 break;
1601 }
1602 return n;
1603 }
1604
1605
1606 static target_long expr_prod(void)
1607 {
1608 target_long val, val2;
1609 int op;
1610
1611 val = expr_unary();
1612 for(;;) {
1613 op = *pch;
1614 if (op != '*' && op != '/' && op != '%')
1615 break;
1616 next();
1617 val2 = expr_unary();
1618 switch(op) {
1619 default:
1620 case '*':
1621 val *= val2;
1622 break;
1623 case '/':
1624 case '%':
1625 if (val2 == 0)
1626 expr_error("division by zero");
1627 if (op == '/')
1628 val /= val2;
1629 else
1630 val %= val2;
1631 break;
1632 }
1633 }
1634 return val;
1635 }
1636
1637 static target_long expr_logic(void)
1638 {
1639 target_long val, val2;
1640 int op;
1641
1642 val = expr_prod();
1643 for(;;) {
1644 op = *pch;
1645 if (op != '&' && op != '|' && op != '^')
1646 break;
1647 next();
1648 val2 = expr_prod();
1649 switch(op) {
1650 default:
1651 case '&':
1652 val &= val2;
1653 break;
1654 case '|':
1655 val |= val2;
1656 break;
1657 case '^':
1658 val ^= val2;
1659 break;
1660 }
1661 }
1662 return val;
1663 }
1664
1665 static target_long expr_sum(void)
1666 {
1667 target_long val, val2;
1668 int op;
1669
1670 val = expr_logic();
1671 for(;;) {
1672 op = *pch;
1673 if (op != '+' && op != '-')
1674 break;
1675 next();
1676 val2 = expr_logic();
1677 if (op == '+')
1678 val += val2;
1679 else
1680 val -= val2;
1681 }
1682 return val;
1683 }
1684
1685 static int get_expr(target_long *pval, const char **pp)
1686 {
1687 pch = *pp;
1688 if (setjmp(expr_env)) {
1689 *pp = pch;
1690 return -1;
1691 }
1692 while (isspace(*pch))
1693 pch++;
1694 *pval = expr_sum();
1695 *pp = pch;
1696 return 0;
1697 }
1698
1699 static int get_str(char *buf, int buf_size, const char **pp)
1700 {
1701 const char *p;
1702 char *q;
1703 int c;
1704
1705 q = buf;
1706 p = *pp;
1707 while (isspace(*p))
1708 p++;
1709 if (*p == '\0') {
1710 fail:
1711 *q = '\0';
1712 *pp = p;
1713 return -1;
1714 }
1715 if (*p == '\"') {
1716 p++;
1717 while (*p != '\0' && *p != '\"') {
1718 if (*p == '\\') {
1719 p++;
1720 c = *p++;
1721 switch(c) {
1722 case 'n':
1723 c = '\n';
1724 break;
1725 case 'r':
1726 c = '\r';
1727 break;
1728 case '\\':
1729 case '\'':
1730 case '\"':
1731 break;
1732 default:
1733 qemu_printf("unsupported escape code: '\\%c'\n", c);
1734 goto fail;
1735 }
1736 if ((q - buf) < buf_size - 1) {
1737 *q++ = c;
1738 }
1739 } else {
1740 if ((q - buf) < buf_size - 1) {
1741 *q++ = *p;
1742 }
1743 p++;
1744 }
1745 }
1746 if (*p != '\"') {
1747 qemu_printf("unterminated string\n");
1748 goto fail;
1749 }
1750 p++;
1751 } else {
1752 while (*p != '\0' && !isspace(*p)) {
1753 if ((q - buf) < buf_size - 1) {
1754 *q++ = *p;
1755 }
1756 p++;
1757 }
1758 }
1759 *q = '\0';
1760 *pp = p;
1761 return 0;
1762 }
1763
1764 static int default_fmt_format = 'x';
1765 static int default_fmt_size = 4;
1766
1767 #define MAX_ARGS 16
1768
1769 static void monitor_handle_command(const char *cmdline)
1770 {
1771 const char *p, *pstart, *typestr;
1772 char *q;
1773 int c, nb_args, len, i, has_arg;
1774 term_cmd_t *cmd;
1775 char cmdname[256];
1776 char buf[1024];
1777 void *str_allocated[MAX_ARGS];
1778 void *args[MAX_ARGS];
1779
1780 #ifdef DEBUG
1781 term_printf("command='%s'\n", cmdline);
1782 #endif
1783
1784 /* extract the command name */
1785 p = cmdline;
1786 q = cmdname;
1787 while (isspace(*p))
1788 p++;
1789 if (*p == '\0')
1790 return;
1791 pstart = p;
1792 while (*p != '\0' && *p != '/' && !isspace(*p))
1793 p++;
1794 len = p - pstart;
1795 if (len > sizeof(cmdname) - 1)
1796 len = sizeof(cmdname) - 1;
1797 memcpy(cmdname, pstart, len);
1798 cmdname[len] = '\0';
1799
1800 /* find the command */
1801 for(cmd = term_cmds; cmd->name != NULL; cmd++) {
1802 if (compare_cmd(cmdname, cmd->name))
1803 goto found;
1804 }
1805 term_printf("unknown command: '%s'\n", cmdname);
1806 return;
1807 found:
1808
1809 for(i = 0; i < MAX_ARGS; i++)
1810 str_allocated[i] = NULL;
1811
1812 /* parse the parameters */
1813 typestr = cmd->args_type;
1814 nb_args = 0;
1815 for(;;) {
1816 c = *typestr;
1817 if (c == '\0')
1818 break;
1819 typestr++;
1820 switch(c) {
1821 case 'F':
1822 case 'B':
1823 case 's':
1824 {
1825 int ret;
1826 char *str;
1827
1828 while (isspace(*p))
1829 p++;
1830 if (*typestr == '?') {
1831 typestr++;
1832 if (*p == '\0') {
1833 /* no optional string: NULL argument */
1834 str = NULL;
1835 goto add_str;
1836 }
1837 }
1838 ret = get_str(buf, sizeof(buf), &p);
1839 if (ret < 0) {
1840 switch(c) {
1841 case 'F':
1842 term_printf("%s: filename expected\n", cmdname);
1843 break;
1844 case 'B':
1845 term_printf("%s: block device name expected\n", cmdname);
1846 break;
1847 default:
1848 term_printf("%s: string expected\n", cmdname);
1849 break;
1850 }
1851 goto fail;
1852 }
1853 str = qemu_malloc(strlen(buf) + 1);
1854 strcpy(str, buf);
1855 str_allocated[nb_args] = str;
1856 add_str:
1857 if (nb_args >= MAX_ARGS) {
1858 error_args:
1859 term_printf("%s: too many arguments\n", cmdname);
1860 goto fail;
1861 }
1862 args[nb_args++] = str;
1863 }
1864 break;
1865 case '/':
1866 {
1867 int count, format, size;
1868
1869 while (isspace(*p))
1870 p++;
1871 if (*p == '/') {
1872 /* format found */
1873 p++;
1874 count = 1;
1875 if (isdigit(*p)) {
1876 count = 0;
1877 while (isdigit(*p)) {
1878 count = count * 10 + (*p - '0');
1879 p++;
1880 }
1881 }
1882 size = -1;
1883 format = -1;
1884 for(;;) {
1885 switch(*p) {
1886 case 'o':
1887 case 'd':
1888 case 'u':
1889 case 'x':
1890 case 'i':
1891 case 'c':
1892 format = *p++;
1893 break;
1894 case 'b':
1895 size = 1;
1896 p++;
1897 break;
1898 case 'h':
1899 size = 2;
1900 p++;
1901 break;
1902 case 'w':
1903 size = 4;
1904 p++;
1905 break;
1906 case 'g':
1907 case 'L':
1908 size = 8;
1909 p++;
1910 break;
1911 default:
1912 goto next;
1913 }
1914 }
1915 next:
1916 if (*p != '\0' && !isspace(*p)) {
1917 term_printf("invalid char in format: '%c'\n", *p);
1918 goto fail;
1919 }
1920 if (format < 0)
1921 format = default_fmt_format;
1922 if (format != 'i') {
1923 /* for 'i', not specifying a size gives -1 as size */
1924 if (size < 0)
1925 size = default_fmt_size;
1926 }
1927 default_fmt_size = size;
1928 default_fmt_format = format;
1929 } else {
1930 count = 1;
1931 format = default_fmt_format;
1932 if (format != 'i') {
1933 size = default_fmt_size;
1934 } else {
1935 size = -1;
1936 }
1937 }
1938 if (nb_args + 3 > MAX_ARGS)
1939 goto error_args;
1940 args[nb_args++] = (void*)count;
1941 args[nb_args++] = (void*)format;
1942 args[nb_args++] = (void*)size;
1943 }
1944 break;
1945 case 'i':
1946 case 'l':
1947 {
1948 target_long val;
1949 while (isspace(*p))
1950 p++;
1951 if (*typestr == '?' || *typestr == '.') {
1952 typestr++;
1953 if (*typestr == '?') {
1954 if (*p == '\0')
1955 has_arg = 0;
1956 else
1957 has_arg = 1;
1958 } else {
1959 if (*p == '.') {
1960 p++;
1961 while (isspace(*p))
1962 p++;
1963 has_arg = 1;
1964 } else {
1965 has_arg = 0;
1966 }
1967 }
1968 if (nb_args >= MAX_ARGS)
1969 goto error_args;
1970 args[nb_args++] = (void *)has_arg;
1971 if (!has_arg) {
1972 if (nb_args >= MAX_ARGS)
1973 goto error_args;
1974 val = -1;
1975 goto add_num;
1976 }
1977 }
1978 if (get_expr(&val, &p))
1979 goto fail;
1980 add_num:
1981 if (c == 'i') {
1982 if (nb_args >= MAX_ARGS)
1983 goto error_args;
1984 args[nb_args++] = (void *)(int)val;
1985 } else {
1986 if ((nb_args + 1) >= MAX_ARGS)
1987 goto error_args;
1988 #if TARGET_LONG_BITS == 64
1989 args[nb_args++] = (void *)(int)((val >> 32) & 0xffffffff);
1990 #else
1991 args[nb_args++] = (void *)0;
1992 #endif
1993 args[nb_args++] = (void *)(int)(val & 0xffffffff);
1994 }
1995 }
1996 break;
1997 case '-':
1998 {
1999 int has_option;
2000 /* option */
2001
2002 c = *typestr++;
2003 if (c == '\0')
2004 goto bad_type;
2005 while (isspace(*p))
2006 p++;
2007 has_option = 0;
2008 if (*p == '-') {
2009 p++;
2010 if (*p != c) {
2011 term_printf("%s: unsupported option -%c\n",
2012 cmdname, *p);
2013 goto fail;
2014 }
2015 p++;
2016 has_option = 1;
2017 }
2018 if (nb_args >= MAX_ARGS)
2019 goto error_args;
2020 args[nb_args++] = (void *)has_option;
2021 }
2022 break;
2023 default:
2024 bad_type:
2025 term_printf("%s: unknown type '%c'\n", cmdname, c);
2026 goto fail;
2027 }
2028 }
2029 /* check that all arguments were parsed */
2030 while (isspace(*p))
2031 p++;
2032 if (*p != '\0') {
2033 term_printf("%s: extraneous characters at the end of line\n",
2034 cmdname);
2035 goto fail;
2036 }
2037
2038 switch(nb_args) {
2039 case 0:
2040 cmd->handler();
2041 break;
2042 case 1:
2043 cmd->handler(args[0]);
2044 break;
2045 case 2:
2046 cmd->handler(args[0], args[1]);
2047 break;
2048 case 3:
2049 cmd->handler(args[0], args[1], args[2]);
2050 break;
2051 case 4:
2052 cmd->handler(args[0], args[1], args[2], args[3]);
2053 break;
2054 case 5:
2055 cmd->handler(args[0], args[1], args[2], args[3], args[4]);
2056 break;
2057 case 6:
2058 cmd->handler(args[0], args[1], args[2], args[3], args[4], args[5]);
2059 break;
2060 default:
2061 term_printf("unsupported number of arguments: %d\n", nb_args);
2062 goto fail;
2063 }
2064 fail:
2065 for(i = 0; i < MAX_ARGS; i++)
2066 qemu_free(str_allocated[i]);
2067 return;
2068 }
2069
2070 static void cmd_completion(const char *name, const char *list)
2071 {
2072 const char *p, *pstart;
2073 char cmd[128];
2074 int len;
2075
2076 p = list;
2077 for(;;) {
2078 pstart = p;
2079 p = strchr(p, '|');
2080 if (!p)
2081 p = pstart + strlen(pstart);
2082 len = p - pstart;
2083 if (len > sizeof(cmd) - 2)
2084 len = sizeof(cmd) - 2;
2085 memcpy(cmd, pstart, len);
2086 cmd[len] = '\0';
2087 if (name[0] == '\0' || !strncmp(name, cmd, strlen(name))) {
2088 add_completion(cmd);
2089 }
2090 if (*p == '\0')
2091 break;
2092 p++;
2093 }
2094 }
2095
2096 static void file_completion(const char *input)
2097 {
2098 DIR *ffs;
2099 struct dirent *d;
2100 char path[1024];
2101 char file[1024], file_prefix[1024];
2102 int input_path_len;
2103 const char *p;
2104
2105 p = strrchr(input, '/');
2106 if (!p) {
2107 input_path_len = 0;
2108 pstrcpy(file_prefix, sizeof(file_prefix), input);
2109 strcpy(path, ".");
2110 } else {
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);
2117 }
2118 #ifdef DEBUG_COMPLETION
2119 term_printf("input='%s' path='%s' prefix='%s'\n", input, path, file_prefix);
2120 #endif
2121 ffs = opendir(path);
2122 if (!ffs)
2123 return;
2124 for(;;) {
2125 struct stat sb;
2126 d = readdir(ffs);
2127 if (!d)
2128 break;
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
2134 */
2135 stat(file, &sb);
2136 if(S_ISDIR(sb.st_mode))
2137 strcat(file, "/");
2138 add_completion(file);
2139 }
2140 }
2141 closedir(ffs);
2142 }
2143
2144 static void block_completion_it(void *opaque, const char *name)
2145 {
2146 const char *input = opaque;
2147
2148 if (input[0] == '\0' ||
2149 !strncmp(name, (char *)input, strlen(input))) {
2150 add_completion(name);
2151 }
2152 }
2153
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)
2157 {
2158 const char *p;
2159 int nb_args, ret;
2160 char buf[1024];
2161
2162 p = cmdline;
2163 nb_args = 0;
2164 for(;;) {
2165 while (isspace(*p))
2166 p++;
2167 if (*p == '\0')
2168 break;
2169 if (nb_args >= MAX_ARGS)
2170 break;
2171 ret = get_str(buf, sizeof(buf), &p);
2172 args[nb_args] = qemu_strdup(buf);
2173 nb_args++;
2174 if (ret < 0)
2175 break;
2176 }
2177 *pnb_args = nb_args;
2178 }
2179
2180 void readline_find_completion(const char *cmdline)
2181 {
2182 const char *cmdname;
2183 char *args[MAX_ARGS];
2184 int nb_args, i, len;
2185 const char *ptype, *str;
2186 term_cmd_t *cmd;
2187 const KeyDef *key;
2188
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]);
2193 }
2194 #endif
2195
2196 /* if the line ends with a space, it means we want to complete the
2197 next arg */
2198 len = strlen(cmdline);
2199 if (len > 0 && isspace(cmdline[len - 1])) {
2200 if (nb_args >= MAX_ARGS)
2201 return;
2202 args[nb_args++] = qemu_strdup("");
2203 }
2204 if (nb_args <= 1) {
2205 /* command completion */
2206 if (nb_args == 0)
2207 cmdname = "";
2208 else
2209 cmdname = args[0];
2210 completion_index = strlen(cmdname);
2211 for(cmd = term_cmds; cmd->name != NULL; cmd++) {
2212 cmd_completion(cmdname, cmd->name);
2213 }
2214 } else {
2215 /* find the command */
2216 for(cmd = term_cmds; cmd->name != NULL; cmd++) {
2217 if (compare_cmd(args[0], cmd->name))
2218 goto found;
2219 }
2220 return;
2221 found:
2222 ptype = cmd->args_type;
2223 for(i = 0; i < nb_args - 2; i++) {
2224 if (*ptype != '\0') {
2225 ptype++;
2226 while (*ptype == '?')
2227 ptype++;
2228 }
2229 }
2230 str = args[nb_args - 1];
2231 switch(*ptype) {
2232 case 'F':
2233 /* file completion */
2234 completion_index = strlen(str);
2235 file_completion(str);
2236 break;
2237 case 'B':
2238 /* block device name completion */
2239 completion_index = strlen(str);
2240 bdrv_iterate(block_completion_it, (void *)str);
2241 break;
2242 case 's':
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);
2248 }
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);
2253 }
2254 }
2255 break;
2256 default:
2257 break;
2258 }
2259 }
2260 for(i = 0; i < nb_args; i++)
2261 qemu_free(args[i]);
2262 }
2263
2264 static int term_can_read(void *opaque)
2265 {
2266 return 128;
2267 }
2268
2269 static void term_read(void *opaque, const uint8_t *buf, int size)
2270 {
2271 int i;
2272 for(i = 0; i < size; i++)
2273 readline_handle_byte(buf[i]);
2274 }
2275
2276 static void monitor_start_input(void);
2277
2278 static void monitor_handle_command1(void *opaque, const char *cmdline)
2279 {
2280 monitor_handle_command(cmdline);
2281 monitor_start_input();
2282 }
2283
2284 static void monitor_start_input(void)
2285 {
2286 readline_start("(qemu) ", 0, monitor_handle_command1, NULL);
2287 }
2288
2289 void monitor_init(CharDriverState *hd, int show_banner)
2290 {
2291 monitor_hd = hd;
2292 if (show_banner) {
2293 term_printf("QEMU %s monitor - type 'help' for more information\n",
2294 QEMU_VERSION);
2295 }
2296 qemu_chr_add_read_handler(hd, term_can_read, term_read, NULL);
2297 monitor_start_input();
2298 }
2299
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;
2305
2306 static void monitor_readline_cb(void *opaque, const char *input)
2307 {
2308 pstrcpy(monitor_readline_buf, monitor_readline_buf_size, input);
2309 monitor_readline_started = 0;
2310 }
2311
2312 void monitor_readline(const char *prompt, int is_password,
2313 char *buf, int buf_size)
2314 {
2315 if (is_password) {
2316 qemu_chr_send_event(monitor_hd, CHR_EVENT_FOCUS);
2317 }
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) {
2323 main_loop_wait(10);
2324 }
2325 }