4 * Copyright (c) 2003-2008 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
25 #include "hw/boards.h"
27 #include "hw/pcmcia.h"
29 #include "hw/audiodev.h"
37 #include "qemu-timer.h"
38 #include "qemu-char.h"
39 #include "cache-utils.h"
41 #include "audio/audio.h"
42 #include "migration.h"
55 #include <sys/times.h>
59 #include <sys/ioctl.h>
60 #include <sys/resource.h>
61 #include <sys/socket.h>
62 #include <netinet/in.h>
64 #if defined(__NetBSD__)
65 #include <net/if_tap.h>
68 #include <linux/if_tun.h>
70 #include <arpa/inet.h>
73 #include <sys/select.h>
81 #elif defined (__GLIBC__) && defined (__FreeBSD_kernel__)
82 #include <freebsd/stdlib.h>
87 #include <linux/rtc.h>
89 /* For the benefit of older linux systems which don't supply it,
90 we use a local copy of hpet.h. */
91 /* #include <linux/hpet.h> */
94 #include <linux/ppdev.h>
95 #include <linux/parport.h>
99 #include <sys/ethernet.h>
100 #include <sys/sockio.h>
101 #include <netinet/arp.h>
102 #include <netinet/in.h>
103 #include <netinet/in_systm.h>
104 #include <netinet/ip.h>
105 #include <netinet/ip_icmp.h> // must come after ip.h
106 #include <netinet/udp.h>
107 #include <netinet/tcp.h>
115 #include "qemu_socket.h"
117 #if defined(CONFIG_SLIRP)
118 #include "libslirp.h"
121 #if defined(__OpenBSD__)
125 #if defined(CONFIG_VDE)
126 #include <libvdeplug.h>
131 #include <sys/timeb.h>
132 #include <mmsystem.h>
133 #define getopt_long_only getopt_long
134 #define memalign(align, size) malloc(size)
141 #endif /* CONFIG_SDL */
145 #define main qemu_main
146 #endif /* CONFIG_COCOA */
150 #include "exec-all.h"
152 //#define DEBUG_UNUSED_IOPORT
153 //#define DEBUG_IOPORT
155 //#define DEBUG_SLIRP
159 # define LOG_IOPORT(...) qemu_log_mask(CPU_LOG_IOPORT, ## __VA_ARGS__)
161 # define LOG_IOPORT(...) do { } while (0)
164 #define DEFAULT_RAM_SIZE 128
166 /* Max number of USB devices that can be specified on the commandline. */
167 #define MAX_USB_CMDLINE 8
169 /* Max number of bluetooth switches on the commandline. */
170 #define MAX_BT_CMDLINE 10
172 /* XXX: use a two level table to limit memory usage */
173 #define MAX_IOPORTS 65536
175 const char *bios_dir
= CONFIG_QEMU_SHAREDIR
;
176 const char *bios_name
= NULL
;
177 static void *ioport_opaque
[MAX_IOPORTS
];
178 static IOPortReadFunc
*ioport_read_table
[3][MAX_IOPORTS
];
179 static IOPortWriteFunc
*ioport_write_table
[3][MAX_IOPORTS
];
180 /* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available
181 to store the VM snapshots */
182 DriveInfo drives_table
[MAX_DRIVES
+1];
184 static int vga_ram_size
;
185 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
186 static DisplayState
*display_state
;
190 const char* keyboard_layout
= NULL
;
191 int64_t ticks_per_sec
;
194 NICInfo nd_table
[MAX_NICS
];
196 static int rtc_utc
= 1;
197 static int rtc_date_offset
= -1; /* -1 means no change */
198 int cirrus_vga_enabled
= 1;
199 int std_vga_enabled
= 0;
200 int vmsvga_enabled
= 0;
202 int graphic_width
= 1024;
203 int graphic_height
= 768;
204 int graphic_depth
= 8;
206 int graphic_width
= 800;
207 int graphic_height
= 600;
208 int graphic_depth
= 15;
210 static int full_screen
= 0;
212 static int no_frame
= 0;
215 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
216 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
217 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
219 int win2k_install_hack
= 0;
224 const char *vnc_display
;
225 int acpi_enabled
= 1;
231 int graphic_rotate
= 0;
233 const char *option_rom
[MAX_OPTION_ROMS
];
235 int semihosting_enabled
= 0;
239 const char *qemu_name
;
241 #if defined(TARGET_SPARC) || defined(TARGET_PPC)
242 unsigned int nb_prom_envs
= 0;
243 const char *prom_envs
[MAX_PROM_ENVS
];
245 static int nb_drives_opt
;
246 static struct drive_opt
{
249 } drives_opt
[MAX_DRIVES
];
251 static CPUState
*cur_cpu
;
252 static CPUState
*next_cpu
;
253 static int event_pending
= 1;
254 /* Conversion factor from emulated instructions to virtual clock ticks. */
255 static int icount_time_shift
;
256 /* Arbitrarily pick 1MIPS as the minimum allowable speed. */
257 #define MAX_ICOUNT_SHIFT 10
258 /* Compensate for varying guest execution speed. */
259 static int64_t qemu_icount_bias
;
260 static QEMUTimer
*icount_rt_timer
;
261 static QEMUTimer
*icount_vm_timer
;
262 static QEMUTimer
*nographic_timer
;
264 uint8_t qemu_uuid
[16];
266 /***********************************************************/
267 /* x86 ISA bus support */
269 target_phys_addr_t isa_mem_base
= 0;
272 static IOPortReadFunc default_ioport_readb
, default_ioport_readw
, default_ioport_readl
;
273 static IOPortWriteFunc default_ioport_writeb
, default_ioport_writew
, default_ioport_writel
;
275 static uint32_t ioport_read(int index
, uint32_t address
)
277 static IOPortReadFunc
*default_func
[3] = {
278 default_ioport_readb
,
279 default_ioport_readw
,
282 IOPortReadFunc
*func
= ioport_read_table
[index
][address
];
284 func
= default_func
[index
];
285 return func(ioport_opaque
[address
], address
);
288 static void ioport_write(int index
, uint32_t address
, uint32_t data
)
290 static IOPortWriteFunc
*default_func
[3] = {
291 default_ioport_writeb
,
292 default_ioport_writew
,
293 default_ioport_writel
295 IOPortWriteFunc
*func
= ioport_write_table
[index
][address
];
297 func
= default_func
[index
];
298 func(ioport_opaque
[address
], address
, data
);
301 static uint32_t default_ioport_readb(void *opaque
, uint32_t address
)
303 #ifdef DEBUG_UNUSED_IOPORT
304 fprintf(stderr
, "unused inb: port=0x%04x\n", address
);
309 static void default_ioport_writeb(void *opaque
, uint32_t address
, uint32_t data
)
311 #ifdef DEBUG_UNUSED_IOPORT
312 fprintf(stderr
, "unused outb: port=0x%04x data=0x%02x\n", address
, data
);
316 /* default is to make two byte accesses */
317 static uint32_t default_ioport_readw(void *opaque
, uint32_t address
)
320 data
= ioport_read(0, address
);
321 address
= (address
+ 1) & (MAX_IOPORTS
- 1);
322 data
|= ioport_read(0, address
) << 8;
326 static void default_ioport_writew(void *opaque
, uint32_t address
, uint32_t data
)
328 ioport_write(0, address
, data
& 0xff);
329 address
= (address
+ 1) & (MAX_IOPORTS
- 1);
330 ioport_write(0, address
, (data
>> 8) & 0xff);
333 static uint32_t default_ioport_readl(void *opaque
, uint32_t address
)
335 #ifdef DEBUG_UNUSED_IOPORT
336 fprintf(stderr
, "unused inl: port=0x%04x\n", address
);
341 static void default_ioport_writel(void *opaque
, uint32_t address
, uint32_t data
)
343 #ifdef DEBUG_UNUSED_IOPORT
344 fprintf(stderr
, "unused outl: port=0x%04x data=0x%02x\n", address
, data
);
348 /* size is the word size in byte */
349 int register_ioport_read(int start
, int length
, int size
,
350 IOPortReadFunc
*func
, void *opaque
)
356 } else if (size
== 2) {
358 } else if (size
== 4) {
361 hw_error("register_ioport_read: invalid size");
364 for(i
= start
; i
< start
+ length
; i
+= size
) {
365 ioport_read_table
[bsize
][i
] = func
;
366 if (ioport_opaque
[i
] != NULL
&& ioport_opaque
[i
] != opaque
)
367 hw_error("register_ioport_read: invalid opaque");
368 ioport_opaque
[i
] = opaque
;
373 /* size is the word size in byte */
374 int register_ioport_write(int start
, int length
, int size
,
375 IOPortWriteFunc
*func
, void *opaque
)
381 } else if (size
== 2) {
383 } else if (size
== 4) {
386 hw_error("register_ioport_write: invalid size");
389 for(i
= start
; i
< start
+ length
; i
+= size
) {
390 ioport_write_table
[bsize
][i
] = func
;
391 if (ioport_opaque
[i
] != NULL
&& ioport_opaque
[i
] != opaque
)
392 hw_error("register_ioport_write: invalid opaque");
393 ioport_opaque
[i
] = opaque
;
398 void isa_unassign_ioport(int start
, int length
)
402 for(i
= start
; i
< start
+ length
; i
++) {
403 ioport_read_table
[0][i
] = default_ioport_readb
;
404 ioport_read_table
[1][i
] = default_ioport_readw
;
405 ioport_read_table
[2][i
] = default_ioport_readl
;
407 ioport_write_table
[0][i
] = default_ioport_writeb
;
408 ioport_write_table
[1][i
] = default_ioport_writew
;
409 ioport_write_table
[2][i
] = default_ioport_writel
;
413 /***********************************************************/
415 void cpu_outb(CPUState
*env
, int addr
, int val
)
417 LOG_IOPORT("outb: %04x %02x\n", addr
, val
);
418 ioport_write(0, addr
, val
);
421 env
->last_io_time
= cpu_get_time_fast();
425 void cpu_outw(CPUState
*env
, int addr
, int val
)
427 LOG_IOPORT("outw: %04x %04x\n", addr
, val
);
428 ioport_write(1, addr
, val
);
431 env
->last_io_time
= cpu_get_time_fast();
435 void cpu_outl(CPUState
*env
, int addr
, int val
)
437 LOG_IOPORT("outl: %04x %08x\n", addr
, val
);
438 ioport_write(2, addr
, val
);
441 env
->last_io_time
= cpu_get_time_fast();
445 int cpu_inb(CPUState
*env
, int addr
)
448 val
= ioport_read(0, addr
);
449 LOG_IOPORT("inb : %04x %02x\n", addr
, val
);
452 env
->last_io_time
= cpu_get_time_fast();
457 int cpu_inw(CPUState
*env
, int addr
)
460 val
= ioport_read(1, addr
);
461 LOG_IOPORT("inw : %04x %04x\n", addr
, val
);
464 env
->last_io_time
= cpu_get_time_fast();
469 int cpu_inl(CPUState
*env
, int addr
)
472 val
= ioport_read(2, addr
);
473 LOG_IOPORT("inl : %04x %08x\n", addr
, val
);
476 env
->last_io_time
= cpu_get_time_fast();
481 /***********************************************************/
482 void hw_error(const char *fmt
, ...)
488 fprintf(stderr
, "qemu: hardware error: ");
489 vfprintf(stderr
, fmt
, ap
);
490 fprintf(stderr
, "\n");
491 for(env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
492 fprintf(stderr
, "CPU #%d:\n", env
->cpu_index
);
494 cpu_dump_state(env
, stderr
, fprintf
, X86_DUMP_FPU
);
496 cpu_dump_state(env
, stderr
, fprintf
, 0);
506 static QEMUBalloonEvent
*qemu_balloon_event
;
507 void *qemu_balloon_event_opaque
;
509 void qemu_add_balloon_handler(QEMUBalloonEvent
*func
, void *opaque
)
511 qemu_balloon_event
= func
;
512 qemu_balloon_event_opaque
= opaque
;
515 void qemu_balloon(ram_addr_t target
)
517 if (qemu_balloon_event
)
518 qemu_balloon_event(qemu_balloon_event_opaque
, target
);
521 ram_addr_t
qemu_balloon_status(void)
523 if (qemu_balloon_event
)
524 return qemu_balloon_event(qemu_balloon_event_opaque
, 0);
528 /***********************************************************/
531 static QEMUPutKBDEvent
*qemu_put_kbd_event
;
532 static void *qemu_put_kbd_event_opaque
;
533 static QEMUPutMouseEntry
*qemu_put_mouse_event_head
;
534 static QEMUPutMouseEntry
*qemu_put_mouse_event_current
;
536 void qemu_add_kbd_event_handler(QEMUPutKBDEvent
*func
, void *opaque
)
538 qemu_put_kbd_event_opaque
= opaque
;
539 qemu_put_kbd_event
= func
;
542 QEMUPutMouseEntry
*qemu_add_mouse_event_handler(QEMUPutMouseEvent
*func
,
543 void *opaque
, int absolute
,
546 QEMUPutMouseEntry
*s
, *cursor
;
548 s
= qemu_mallocz(sizeof(QEMUPutMouseEntry
));
552 s
->qemu_put_mouse_event
= func
;
553 s
->qemu_put_mouse_event_opaque
= opaque
;
554 s
->qemu_put_mouse_event_absolute
= absolute
;
555 s
->qemu_put_mouse_event_name
= qemu_strdup(name
);
558 if (!qemu_put_mouse_event_head
) {
559 qemu_put_mouse_event_head
= qemu_put_mouse_event_current
= s
;
563 cursor
= qemu_put_mouse_event_head
;
564 while (cursor
->next
!= NULL
)
565 cursor
= cursor
->next
;
568 qemu_put_mouse_event_current
= s
;
573 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry
*entry
)
575 QEMUPutMouseEntry
*prev
= NULL
, *cursor
;
577 if (!qemu_put_mouse_event_head
|| entry
== NULL
)
580 cursor
= qemu_put_mouse_event_head
;
581 while (cursor
!= NULL
&& cursor
!= entry
) {
583 cursor
= cursor
->next
;
586 if (cursor
== NULL
) // does not exist or list empty
588 else if (prev
== NULL
) { // entry is head
589 qemu_put_mouse_event_head
= cursor
->next
;
590 if (qemu_put_mouse_event_current
== entry
)
591 qemu_put_mouse_event_current
= cursor
->next
;
592 qemu_free(entry
->qemu_put_mouse_event_name
);
597 prev
->next
= entry
->next
;
599 if (qemu_put_mouse_event_current
== entry
)
600 qemu_put_mouse_event_current
= prev
;
602 qemu_free(entry
->qemu_put_mouse_event_name
);
606 void kbd_put_keycode(int keycode
)
608 if (qemu_put_kbd_event
) {
609 qemu_put_kbd_event(qemu_put_kbd_event_opaque
, keycode
);
613 void kbd_mouse_event(int dx
, int dy
, int dz
, int buttons_state
)
615 QEMUPutMouseEvent
*mouse_event
;
616 void *mouse_event_opaque
;
619 if (!qemu_put_mouse_event_current
) {
624 qemu_put_mouse_event_current
->qemu_put_mouse_event
;
626 qemu_put_mouse_event_current
->qemu_put_mouse_event_opaque
;
629 if (graphic_rotate
) {
630 if (qemu_put_mouse_event_current
->qemu_put_mouse_event_absolute
)
633 width
= graphic_width
- 1;
634 mouse_event(mouse_event_opaque
,
635 width
- dy
, dx
, dz
, buttons_state
);
637 mouse_event(mouse_event_opaque
,
638 dx
, dy
, dz
, buttons_state
);
642 int kbd_mouse_is_absolute(void)
644 if (!qemu_put_mouse_event_current
)
647 return qemu_put_mouse_event_current
->qemu_put_mouse_event_absolute
;
650 void do_info_mice(void)
652 QEMUPutMouseEntry
*cursor
;
655 if (!qemu_put_mouse_event_head
) {
656 term_printf("No mouse devices connected\n");
660 term_printf("Mouse devices available:\n");
661 cursor
= qemu_put_mouse_event_head
;
662 while (cursor
!= NULL
) {
663 term_printf("%c Mouse #%d: %s\n",
664 (cursor
== qemu_put_mouse_event_current
? '*' : ' '),
665 index
, cursor
->qemu_put_mouse_event_name
);
667 cursor
= cursor
->next
;
671 void do_mouse_set(int index
)
673 QEMUPutMouseEntry
*cursor
;
676 if (!qemu_put_mouse_event_head
) {
677 term_printf("No mouse devices connected\n");
681 cursor
= qemu_put_mouse_event_head
;
682 while (cursor
!= NULL
&& index
!= i
) {
684 cursor
= cursor
->next
;
688 qemu_put_mouse_event_current
= cursor
;
690 term_printf("Mouse at given index not found\n");
693 /* compute with 96 bit intermediate result: (a*b)/c */
694 uint64_t muldiv64(uint64_t a
, uint32_t b
, uint32_t c
)
699 #ifdef WORDS_BIGENDIAN
709 rl
= (uint64_t)u
.l
.low
* (uint64_t)b
;
710 rh
= (uint64_t)u
.l
.high
* (uint64_t)b
;
713 res
.l
.low
= (((rh
% c
) << 32) + (rl
& 0xffffffff)) / c
;
717 /***********************************************************/
718 /* real time host monotonic timer */
720 #define QEMU_TIMER_BASE 1000000000LL
724 static int64_t clock_freq
;
726 static void init_get_clock(void)
730 ret
= QueryPerformanceFrequency(&freq
);
732 fprintf(stderr
, "Could not calibrate ticks\n");
735 clock_freq
= freq
.QuadPart
;
738 static int64_t get_clock(void)
741 QueryPerformanceCounter(&ti
);
742 return muldiv64(ti
.QuadPart
, QEMU_TIMER_BASE
, clock_freq
);
747 static int use_rt_clock
;
749 static void init_get_clock(void)
752 #if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 500000)
755 if (clock_gettime(CLOCK_MONOTONIC
, &ts
) == 0) {
762 static int64_t get_clock(void)
764 #if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 500000)
767 clock_gettime(CLOCK_MONOTONIC
, &ts
);
768 return ts
.tv_sec
* 1000000000LL + ts
.tv_nsec
;
772 /* XXX: using gettimeofday leads to problems if the date
773 changes, so it should be avoided. */
775 gettimeofday(&tv
, NULL
);
776 return tv
.tv_sec
* 1000000000LL + (tv
.tv_usec
* 1000);
781 /* Return the virtual CPU time, based on the instruction counter. */
782 static int64_t cpu_get_icount(void)
785 CPUState
*env
= cpu_single_env
;;
786 icount
= qemu_icount
;
789 fprintf(stderr
, "Bad clock read\n");
790 icount
-= (env
->icount_decr
.u16
.low
+ env
->icount_extra
);
792 return qemu_icount_bias
+ (icount
<< icount_time_shift
);
795 /***********************************************************/
796 /* guest cycle counter */
798 static int64_t cpu_ticks_prev
;
799 static int64_t cpu_ticks_offset
;
800 static int64_t cpu_clock_offset
;
801 static int cpu_ticks_enabled
;
803 /* return the host CPU cycle counter and handle stop/restart */
804 int64_t cpu_get_ticks(void)
807 return cpu_get_icount();
809 if (!cpu_ticks_enabled
) {
810 return cpu_ticks_offset
;
813 ticks
= cpu_get_real_ticks();
814 if (cpu_ticks_prev
> ticks
) {
815 /* Note: non increasing ticks may happen if the host uses
817 cpu_ticks_offset
+= cpu_ticks_prev
- ticks
;
819 cpu_ticks_prev
= ticks
;
820 return ticks
+ cpu_ticks_offset
;
824 /* return the host CPU monotonic timer and handle stop/restart */
825 static int64_t cpu_get_clock(void)
828 if (!cpu_ticks_enabled
) {
829 return cpu_clock_offset
;
832 return ti
+ cpu_clock_offset
;
836 /* enable cpu_get_ticks() */
837 void cpu_enable_ticks(void)
839 if (!cpu_ticks_enabled
) {
840 cpu_ticks_offset
-= cpu_get_real_ticks();
841 cpu_clock_offset
-= get_clock();
842 cpu_ticks_enabled
= 1;
846 /* disable cpu_get_ticks() : the clock is stopped. You must not call
847 cpu_get_ticks() after that. */
848 void cpu_disable_ticks(void)
850 if (cpu_ticks_enabled
) {
851 cpu_ticks_offset
= cpu_get_ticks();
852 cpu_clock_offset
= cpu_get_clock();
853 cpu_ticks_enabled
= 0;
857 /***********************************************************/
860 #define QEMU_TIMER_REALTIME 0
861 #define QEMU_TIMER_VIRTUAL 1
865 /* XXX: add frequency */
873 struct QEMUTimer
*next
;
876 struct qemu_alarm_timer
{
880 int (*start
)(struct qemu_alarm_timer
*t
);
881 void (*stop
)(struct qemu_alarm_timer
*t
);
882 void (*rearm
)(struct qemu_alarm_timer
*t
);
886 #define ALARM_FLAG_DYNTICKS 0x1
887 #define ALARM_FLAG_EXPIRED 0x2
889 static inline int alarm_has_dynticks(struct qemu_alarm_timer
*t
)
891 return t
->flags
& ALARM_FLAG_DYNTICKS
;
894 static void qemu_rearm_alarm_timer(struct qemu_alarm_timer
*t
)
896 if (!alarm_has_dynticks(t
))
902 /* TODO: MIN_TIMER_REARM_US should be optimized */
903 #define MIN_TIMER_REARM_US 250
905 static struct qemu_alarm_timer
*alarm_timer
;
907 static int alarm_timer_rfd
, alarm_timer_wfd
;
912 struct qemu_alarm_win32
{
916 } alarm_win32_data
= {0, NULL
, -1};
918 static int win32_start_timer(struct qemu_alarm_timer
*t
);
919 static void win32_stop_timer(struct qemu_alarm_timer
*t
);
920 static void win32_rearm_timer(struct qemu_alarm_timer
*t
);
924 static int unix_start_timer(struct qemu_alarm_timer
*t
);
925 static void unix_stop_timer(struct qemu_alarm_timer
*t
);
929 static int dynticks_start_timer(struct qemu_alarm_timer
*t
);
930 static void dynticks_stop_timer(struct qemu_alarm_timer
*t
);
931 static void dynticks_rearm_timer(struct qemu_alarm_timer
*t
);
933 static int hpet_start_timer(struct qemu_alarm_timer
*t
);
934 static void hpet_stop_timer(struct qemu_alarm_timer
*t
);
936 static int rtc_start_timer(struct qemu_alarm_timer
*t
);
937 static void rtc_stop_timer(struct qemu_alarm_timer
*t
);
939 #endif /* __linux__ */
943 /* Correlation between real and virtual time is always going to be
944 fairly approximate, so ignore small variation.
945 When the guest is idle real and virtual time will be aligned in
947 #define ICOUNT_WOBBLE (QEMU_TIMER_BASE / 10)
949 static void icount_adjust(void)
954 static int64_t last_delta
;
955 /* If the VM is not running, then do nothing. */
959 cur_time
= cpu_get_clock();
960 cur_icount
= qemu_get_clock(vm_clock
);
961 delta
= cur_icount
- cur_time
;
962 /* FIXME: This is a very crude algorithm, somewhat prone to oscillation. */
964 && last_delta
+ ICOUNT_WOBBLE
< delta
* 2
965 && icount_time_shift
> 0) {
966 /* The guest is getting too far ahead. Slow time down. */
970 && last_delta
- ICOUNT_WOBBLE
> delta
* 2
971 && icount_time_shift
< MAX_ICOUNT_SHIFT
) {
972 /* The guest is getting too far behind. Speed time up. */
976 qemu_icount_bias
= cur_icount
- (qemu_icount
<< icount_time_shift
);
979 static void icount_adjust_rt(void * opaque
)
981 qemu_mod_timer(icount_rt_timer
,
982 qemu_get_clock(rt_clock
) + 1000);
986 static void icount_adjust_vm(void * opaque
)
988 qemu_mod_timer(icount_vm_timer
,
989 qemu_get_clock(vm_clock
) + QEMU_TIMER_BASE
/ 10);
993 static void init_icount_adjust(void)
995 /* Have both realtime and virtual time triggers for speed adjustment.
996 The realtime trigger catches emulated time passing too slowly,
997 the virtual time trigger catches emulated time passing too fast.
998 Realtime triggers occur even when idle, so use them less frequently
1000 icount_rt_timer
= qemu_new_timer(rt_clock
, icount_adjust_rt
, NULL
);
1001 qemu_mod_timer(icount_rt_timer
,
1002 qemu_get_clock(rt_clock
) + 1000);
1003 icount_vm_timer
= qemu_new_timer(vm_clock
, icount_adjust_vm
, NULL
);
1004 qemu_mod_timer(icount_vm_timer
,
1005 qemu_get_clock(vm_clock
) + QEMU_TIMER_BASE
/ 10);
1008 static struct qemu_alarm_timer alarm_timers
[] = {
1011 {"dynticks", ALARM_FLAG_DYNTICKS
, dynticks_start_timer
,
1012 dynticks_stop_timer
, dynticks_rearm_timer
, NULL
},
1013 /* HPET - if available - is preferred */
1014 {"hpet", 0, hpet_start_timer
, hpet_stop_timer
, NULL
, NULL
},
1015 /* ...otherwise try RTC */
1016 {"rtc", 0, rtc_start_timer
, rtc_stop_timer
, NULL
, NULL
},
1018 {"unix", 0, unix_start_timer
, unix_stop_timer
, NULL
, NULL
},
1020 {"dynticks", ALARM_FLAG_DYNTICKS
, win32_start_timer
,
1021 win32_stop_timer
, win32_rearm_timer
, &alarm_win32_data
},
1022 {"win32", 0, win32_start_timer
,
1023 win32_stop_timer
, NULL
, &alarm_win32_data
},
1028 static void show_available_alarms(void)
1032 printf("Available alarm timers, in order of precedence:\n");
1033 for (i
= 0; alarm_timers
[i
].name
; i
++)
1034 printf("%s\n", alarm_timers
[i
].name
);
1037 static void configure_alarms(char const *opt
)
1041 int count
= ARRAY_SIZE(alarm_timers
) - 1;
1044 struct qemu_alarm_timer tmp
;
1046 if (!strcmp(opt
, "?")) {
1047 show_available_alarms();
1053 /* Reorder the array */
1054 name
= strtok(arg
, ",");
1056 for (i
= 0; i
< count
&& alarm_timers
[i
].name
; i
++) {
1057 if (!strcmp(alarm_timers
[i
].name
, name
))
1062 fprintf(stderr
, "Unknown clock %s\n", name
);
1071 tmp
= alarm_timers
[i
];
1072 alarm_timers
[i
] = alarm_timers
[cur
];
1073 alarm_timers
[cur
] = tmp
;
1077 name
= strtok(NULL
, ",");
1083 /* Disable remaining timers */
1084 for (i
= cur
; i
< count
; i
++)
1085 alarm_timers
[i
].name
= NULL
;
1087 show_available_alarms();
1092 QEMUClock
*rt_clock
;
1093 QEMUClock
*vm_clock
;
1095 static QEMUTimer
*active_timers
[2];
1097 static QEMUClock
*qemu_new_clock(int type
)
1100 clock
= qemu_mallocz(sizeof(QEMUClock
));
1107 QEMUTimer
*qemu_new_timer(QEMUClock
*clock
, QEMUTimerCB
*cb
, void *opaque
)
1111 ts
= qemu_mallocz(sizeof(QEMUTimer
));
1114 ts
->opaque
= opaque
;
1118 void qemu_free_timer(QEMUTimer
*ts
)
1123 /* stop a timer, but do not dealloc it */
1124 void qemu_del_timer(QEMUTimer
*ts
)
1128 /* NOTE: this code must be signal safe because
1129 qemu_timer_expired() can be called from a signal. */
1130 pt
= &active_timers
[ts
->clock
->type
];
1143 /* modify the current timer so that it will be fired when current_time
1144 >= expire_time. The corresponding callback will be called. */
1145 void qemu_mod_timer(QEMUTimer
*ts
, int64_t expire_time
)
1151 /* add the timer in the sorted list */
1152 /* NOTE: this code must be signal safe because
1153 qemu_timer_expired() can be called from a signal. */
1154 pt
= &active_timers
[ts
->clock
->type
];
1159 if (t
->expire_time
> expire_time
)
1163 ts
->expire_time
= expire_time
;
1167 /* Rearm if necessary */
1168 if (pt
== &active_timers
[ts
->clock
->type
]) {
1169 if ((alarm_timer
->flags
& ALARM_FLAG_EXPIRED
) == 0) {
1170 qemu_rearm_alarm_timer(alarm_timer
);
1172 /* Interrupt execution to force deadline recalculation. */
1173 if (use_icount
&& cpu_single_env
) {
1174 cpu_interrupt(cpu_single_env
, CPU_INTERRUPT_EXIT
);
1179 int qemu_timer_pending(QEMUTimer
*ts
)
1182 for(t
= active_timers
[ts
->clock
->type
]; t
!= NULL
; t
= t
->next
) {
1189 static inline int qemu_timer_expired(QEMUTimer
*timer_head
, int64_t current_time
)
1193 return (timer_head
->expire_time
<= current_time
);
1196 static void qemu_run_timers(QEMUTimer
**ptimer_head
, int64_t current_time
)
1202 if (!ts
|| ts
->expire_time
> current_time
)
1204 /* remove timer from the list before calling the callback */
1205 *ptimer_head
= ts
->next
;
1208 /* run the callback (the timer list can be modified) */
1213 int64_t qemu_get_clock(QEMUClock
*clock
)
1215 switch(clock
->type
) {
1216 case QEMU_TIMER_REALTIME
:
1217 return get_clock() / 1000000;
1219 case QEMU_TIMER_VIRTUAL
:
1221 return cpu_get_icount();
1223 return cpu_get_clock();
1228 static void init_timers(void)
1231 ticks_per_sec
= QEMU_TIMER_BASE
;
1232 rt_clock
= qemu_new_clock(QEMU_TIMER_REALTIME
);
1233 vm_clock
= qemu_new_clock(QEMU_TIMER_VIRTUAL
);
1237 void qemu_put_timer(QEMUFile
*f
, QEMUTimer
*ts
)
1239 uint64_t expire_time
;
1241 if (qemu_timer_pending(ts
)) {
1242 expire_time
= ts
->expire_time
;
1246 qemu_put_be64(f
, expire_time
);
1249 void qemu_get_timer(QEMUFile
*f
, QEMUTimer
*ts
)
1251 uint64_t expire_time
;
1253 expire_time
= qemu_get_be64(f
);
1254 if (expire_time
!= -1) {
1255 qemu_mod_timer(ts
, expire_time
);
1261 static void timer_save(QEMUFile
*f
, void *opaque
)
1263 if (cpu_ticks_enabled
) {
1264 hw_error("cannot save state if virtual timers are running");
1266 qemu_put_be64(f
, cpu_ticks_offset
);
1267 qemu_put_be64(f
, ticks_per_sec
);
1268 qemu_put_be64(f
, cpu_clock_offset
);
1271 static int timer_load(QEMUFile
*f
, void *opaque
, int version_id
)
1273 if (version_id
!= 1 && version_id
!= 2)
1275 if (cpu_ticks_enabled
) {
1278 cpu_ticks_offset
=qemu_get_be64(f
);
1279 ticks_per_sec
=qemu_get_be64(f
);
1280 if (version_id
== 2) {
1281 cpu_clock_offset
=qemu_get_be64(f
);
1287 void CALLBACK
host_alarm_handler(UINT uTimerID
, UINT uMsg
,
1288 DWORD_PTR dwUser
, DWORD_PTR dw1
, DWORD_PTR dw2
)
1290 static void host_alarm_handler(int host_signum
)
1294 #define DISP_FREQ 1000
1296 static int64_t delta_min
= INT64_MAX
;
1297 static int64_t delta_max
, delta_cum
, last_clock
, delta
, ti
;
1299 ti
= qemu_get_clock(vm_clock
);
1300 if (last_clock
!= 0) {
1301 delta
= ti
- last_clock
;
1302 if (delta
< delta_min
)
1304 if (delta
> delta_max
)
1307 if (++count
== DISP_FREQ
) {
1308 printf("timer: min=%" PRId64
" us max=%" PRId64
" us avg=%" PRId64
" us avg_freq=%0.3f Hz\n",
1309 muldiv64(delta_min
, 1000000, ticks_per_sec
),
1310 muldiv64(delta_max
, 1000000, ticks_per_sec
),
1311 muldiv64(delta_cum
, 1000000 / DISP_FREQ
, ticks_per_sec
),
1312 (double)ticks_per_sec
/ ((double)delta_cum
/ DISP_FREQ
));
1314 delta_min
= INT64_MAX
;
1322 if (alarm_has_dynticks(alarm_timer
) ||
1324 qemu_timer_expired(active_timers
[QEMU_TIMER_VIRTUAL
],
1325 qemu_get_clock(vm_clock
))) ||
1326 qemu_timer_expired(active_timers
[QEMU_TIMER_REALTIME
],
1327 qemu_get_clock(rt_clock
))) {
1328 CPUState
*env
= next_cpu
;
1331 struct qemu_alarm_win32
*data
= ((struct qemu_alarm_timer
*)dwUser
)->priv
;
1332 SetEvent(data
->host_alarm
);
1334 static const char byte
= 0;
1335 write(alarm_timer_wfd
, &byte
, sizeof(byte
));
1337 alarm_timer
->flags
|= ALARM_FLAG_EXPIRED
;
1340 /* stop the currently executing cpu because a timer occured */
1341 cpu_interrupt(env
, CPU_INTERRUPT_EXIT
);
1343 if (env
->kqemu_enabled
) {
1344 kqemu_cpu_interrupt(env
);
1352 static int64_t qemu_next_deadline(void)
1356 if (active_timers
[QEMU_TIMER_VIRTUAL
]) {
1357 delta
= active_timers
[QEMU_TIMER_VIRTUAL
]->expire_time
-
1358 qemu_get_clock(vm_clock
);
1360 /* To avoid problems with overflow limit this to 2^32. */
1370 #if defined(__linux__) || defined(_WIN32)
1371 static uint64_t qemu_next_deadline_dyntick(void)
1379 delta
= (qemu_next_deadline() + 999) / 1000;
1381 if (active_timers
[QEMU_TIMER_REALTIME
]) {
1382 rtdelta
= (active_timers
[QEMU_TIMER_REALTIME
]->expire_time
-
1383 qemu_get_clock(rt_clock
))*1000;
1384 if (rtdelta
< delta
)
1388 if (delta
< MIN_TIMER_REARM_US
)
1389 delta
= MIN_TIMER_REARM_US
;
1397 /* Sets a specific flag */
1398 static int fcntl_setfl(int fd
, int flag
)
1402 flags
= fcntl(fd
, F_GETFL
);
1406 if (fcntl(fd
, F_SETFL
, flags
| flag
) == -1)
1412 #if defined(__linux__)
1414 #define RTC_FREQ 1024
1416 static void enable_sigio_timer(int fd
)
1418 struct sigaction act
;
1421 sigfillset(&act
.sa_mask
);
1423 act
.sa_handler
= host_alarm_handler
;
1425 sigaction(SIGIO
, &act
, NULL
);
1426 fcntl_setfl(fd
, O_ASYNC
);
1427 fcntl(fd
, F_SETOWN
, getpid());
1430 static int hpet_start_timer(struct qemu_alarm_timer
*t
)
1432 struct hpet_info info
;
1435 fd
= open("/dev/hpet", O_RDONLY
);
1440 r
= ioctl(fd
, HPET_IRQFREQ
, RTC_FREQ
);
1442 fprintf(stderr
, "Could not configure '/dev/hpet' to have a 1024Hz timer. This is not a fatal\n"
1443 "error, but for better emulation accuracy type:\n"
1444 "'echo 1024 > /proc/sys/dev/hpet/max-user-freq' as root.\n");
1448 /* Check capabilities */
1449 r
= ioctl(fd
, HPET_INFO
, &info
);
1453 /* Enable periodic mode */
1454 r
= ioctl(fd
, HPET_EPI
, 0);
1455 if (info
.hi_flags
&& (r
< 0))
1458 /* Enable interrupt */
1459 r
= ioctl(fd
, HPET_IE_ON
, 0);
1463 enable_sigio_timer(fd
);
1464 t
->priv
= (void *)(long)fd
;
1472 static void hpet_stop_timer(struct qemu_alarm_timer
*t
)
1474 int fd
= (long)t
->priv
;
1479 static int rtc_start_timer(struct qemu_alarm_timer
*t
)
1482 unsigned long current_rtc_freq
= 0;
1484 TFR(rtc_fd
= open("/dev/rtc", O_RDONLY
));
1487 ioctl(rtc_fd
, RTC_IRQP_READ
, ¤t_rtc_freq
);
1488 if (current_rtc_freq
!= RTC_FREQ
&&
1489 ioctl(rtc_fd
, RTC_IRQP_SET
, RTC_FREQ
) < 0) {
1490 fprintf(stderr
, "Could not configure '/dev/rtc' to have a 1024 Hz timer. This is not a fatal\n"
1491 "error, but for better emulation accuracy either use a 2.6 host Linux kernel or\n"
1492 "type 'echo 1024 > /proc/sys/dev/rtc/max-user-freq' as root.\n");
1495 if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
1501 enable_sigio_timer(rtc_fd
);
1503 t
->priv
= (void *)(long)rtc_fd
;
1508 static void rtc_stop_timer(struct qemu_alarm_timer
*t
)
1510 int rtc_fd
= (long)t
->priv
;
1515 static int dynticks_start_timer(struct qemu_alarm_timer
*t
)
1519 struct sigaction act
;
1521 sigfillset(&act
.sa_mask
);
1523 act
.sa_handler
= host_alarm_handler
;
1525 sigaction(SIGALRM
, &act
, NULL
);
1527 ev
.sigev_value
.sival_int
= 0;
1528 ev
.sigev_notify
= SIGEV_SIGNAL
;
1529 ev
.sigev_signo
= SIGALRM
;
1531 if (timer_create(CLOCK_REALTIME
, &ev
, &host_timer
)) {
1532 perror("timer_create");
1534 /* disable dynticks */
1535 fprintf(stderr
, "Dynamic Ticks disabled\n");
1540 t
->priv
= (void *)(long)host_timer
;
1545 static void dynticks_stop_timer(struct qemu_alarm_timer
*t
)
1547 timer_t host_timer
= (timer_t
)(long)t
->priv
;
1549 timer_delete(host_timer
);
1552 static void dynticks_rearm_timer(struct qemu_alarm_timer
*t
)
1554 timer_t host_timer
= (timer_t
)(long)t
->priv
;
1555 struct itimerspec timeout
;
1556 int64_t nearest_delta_us
= INT64_MAX
;
1559 if (!active_timers
[QEMU_TIMER_REALTIME
] &&
1560 !active_timers
[QEMU_TIMER_VIRTUAL
])
1563 nearest_delta_us
= qemu_next_deadline_dyntick();
1565 /* check whether a timer is already running */
1566 if (timer_gettime(host_timer
, &timeout
)) {
1568 fprintf(stderr
, "Internal timer error: aborting\n");
1571 current_us
= timeout
.it_value
.tv_sec
* 1000000 + timeout
.it_value
.tv_nsec
/1000;
1572 if (current_us
&& current_us
<= nearest_delta_us
)
1575 timeout
.it_interval
.tv_sec
= 0;
1576 timeout
.it_interval
.tv_nsec
= 0; /* 0 for one-shot timer */
1577 timeout
.it_value
.tv_sec
= nearest_delta_us
/ 1000000;
1578 timeout
.it_value
.tv_nsec
= (nearest_delta_us
% 1000000) * 1000;
1579 if (timer_settime(host_timer
, 0 /* RELATIVE */, &timeout
, NULL
)) {
1581 fprintf(stderr
, "Internal timer error: aborting\n");
1586 #endif /* defined(__linux__) */
1588 static int unix_start_timer(struct qemu_alarm_timer
*t
)
1590 struct sigaction act
;
1591 struct itimerval itv
;
1595 sigfillset(&act
.sa_mask
);
1597 act
.sa_handler
= host_alarm_handler
;
1599 sigaction(SIGALRM
, &act
, NULL
);
1601 itv
.it_interval
.tv_sec
= 0;
1602 /* for i386 kernel 2.6 to get 1 ms */
1603 itv
.it_interval
.tv_usec
= 999;
1604 itv
.it_value
.tv_sec
= 0;
1605 itv
.it_value
.tv_usec
= 10 * 1000;
1607 err
= setitimer(ITIMER_REAL
, &itv
, NULL
);
1614 static void unix_stop_timer(struct qemu_alarm_timer
*t
)
1616 struct itimerval itv
;
1618 memset(&itv
, 0, sizeof(itv
));
1619 setitimer(ITIMER_REAL
, &itv
, NULL
);
1622 #endif /* !defined(_WIN32) */
1624 static void try_to_rearm_timer(void *opaque
)
1626 struct qemu_alarm_timer
*t
= opaque
;
1630 /* Drain the notify pipe */
1633 len
= read(alarm_timer_rfd
, buffer
, sizeof(buffer
));
1634 } while ((len
== -1 && errno
== EINTR
) || len
> 0);
1637 if (t
->flags
& ALARM_FLAG_EXPIRED
) {
1638 alarm_timer
->flags
&= ~ALARM_FLAG_EXPIRED
;
1639 qemu_rearm_alarm_timer(alarm_timer
);
1645 static int win32_start_timer(struct qemu_alarm_timer
*t
)
1648 struct qemu_alarm_win32
*data
= t
->priv
;
1651 data
->host_alarm
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
1652 if (!data
->host_alarm
) {
1653 perror("Failed CreateEvent");
1657 memset(&tc
, 0, sizeof(tc
));
1658 timeGetDevCaps(&tc
, sizeof(tc
));
1660 if (data
->period
< tc
.wPeriodMin
)
1661 data
->period
= tc
.wPeriodMin
;
1663 timeBeginPeriod(data
->period
);
1665 flags
= TIME_CALLBACK_FUNCTION
;
1666 if (alarm_has_dynticks(t
))
1667 flags
|= TIME_ONESHOT
;
1669 flags
|= TIME_PERIODIC
;
1671 data
->timerId
= timeSetEvent(1, // interval (ms)
1672 data
->period
, // resolution
1673 host_alarm_handler
, // function
1674 (DWORD
)t
, // parameter
1677 if (!data
->timerId
) {
1678 perror("Failed to initialize win32 alarm timer");
1680 timeEndPeriod(data
->period
);
1681 CloseHandle(data
->host_alarm
);
1685 qemu_add_wait_object(data
->host_alarm
, try_to_rearm_timer
, t
);
1690 static void win32_stop_timer(struct qemu_alarm_timer
*t
)
1692 struct qemu_alarm_win32
*data
= t
->priv
;
1694 timeKillEvent(data
->timerId
);
1695 timeEndPeriod(data
->period
);
1697 CloseHandle(data
->host_alarm
);
1700 static void win32_rearm_timer(struct qemu_alarm_timer
*t
)
1702 struct qemu_alarm_win32
*data
= t
->priv
;
1703 uint64_t nearest_delta_us
;
1705 if (!active_timers
[QEMU_TIMER_REALTIME
] &&
1706 !active_timers
[QEMU_TIMER_VIRTUAL
])
1709 nearest_delta_us
= qemu_next_deadline_dyntick();
1710 nearest_delta_us
/= 1000;
1712 timeKillEvent(data
->timerId
);
1714 data
->timerId
= timeSetEvent(1,
1718 TIME_ONESHOT
| TIME_PERIODIC
);
1720 if (!data
->timerId
) {
1721 perror("Failed to re-arm win32 alarm timer");
1723 timeEndPeriod(data
->period
);
1724 CloseHandle(data
->host_alarm
);
1731 static int init_timer_alarm(void)
1733 struct qemu_alarm_timer
*t
= NULL
;
1743 err
= fcntl_setfl(fds
[0], O_NONBLOCK
);
1747 err
= fcntl_setfl(fds
[1], O_NONBLOCK
);
1751 alarm_timer_rfd
= fds
[0];
1752 alarm_timer_wfd
= fds
[1];
1755 for (i
= 0; alarm_timers
[i
].name
; i
++) {
1756 t
= &alarm_timers
[i
];
1769 qemu_set_fd_handler2(alarm_timer_rfd
, NULL
,
1770 try_to_rearm_timer
, NULL
, t
);
1785 static void quit_timers(void)
1787 alarm_timer
->stop(alarm_timer
);
1791 /***********************************************************/
1792 /* host time/date access */
1793 void qemu_get_timedate(struct tm
*tm
, int offset
)
1800 if (rtc_date_offset
== -1) {
1804 ret
= localtime(&ti
);
1806 ti
-= rtc_date_offset
;
1810 memcpy(tm
, ret
, sizeof(struct tm
));
1813 int qemu_timedate_diff(struct tm
*tm
)
1817 if (rtc_date_offset
== -1)
1819 seconds
= mktimegm(tm
);
1821 seconds
= mktime(tm
);
1823 seconds
= mktimegm(tm
) + rtc_date_offset
;
1825 return seconds
- time(NULL
);
1829 static void socket_cleanup(void)
1834 static int socket_init(void)
1839 ret
= WSAStartup(MAKEWORD(2,2), &Data
);
1841 err
= WSAGetLastError();
1842 fprintf(stderr
, "WSAStartup: %d\n", err
);
1845 atexit(socket_cleanup
);
1850 const char *get_opt_name(char *buf
, int buf_size
, const char *p
)
1855 while (*p
!= '\0' && *p
!= '=') {
1856 if (q
&& (q
- buf
) < buf_size
- 1)
1866 const char *get_opt_value(char *buf
, int buf_size
, const char *p
)
1871 while (*p
!= '\0') {
1873 if (*(p
+ 1) != ',')
1877 if (q
&& (q
- buf
) < buf_size
- 1)
1887 int get_param_value(char *buf
, int buf_size
,
1888 const char *tag
, const char *str
)
1895 p
= get_opt_name(option
, sizeof(option
), p
);
1899 if (!strcmp(tag
, option
)) {
1900 (void)get_opt_value(buf
, buf_size
, p
);
1903 p
= get_opt_value(NULL
, 0, p
);
1912 int check_params(char *buf
, int buf_size
,
1913 const char * const *params
, const char *str
)
1920 p
= get_opt_name(buf
, buf_size
, p
);
1924 for(i
= 0; params
[i
] != NULL
; i
++)
1925 if (!strcmp(params
[i
], buf
))
1927 if (params
[i
] == NULL
)
1929 p
= get_opt_value(NULL
, 0, p
);
1937 /***********************************************************/
1938 /* Bluetooth support */
1941 static struct HCIInfo
*hci_table
[MAX_NICS
];
1943 static struct bt_vlan_s
{
1944 struct bt_scatternet_s net
;
1946 struct bt_vlan_s
*next
;
1949 /* find or alloc a new bluetooth "VLAN" */
1950 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
1952 struct bt_vlan_s
**pvlan
, *vlan
;
1953 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
1957 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
1959 pvlan
= &first_bt_vlan
;
1960 while (*pvlan
!= NULL
)
1961 pvlan
= &(*pvlan
)->next
;
1966 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
1970 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
1975 static struct HCIInfo null_hci
= {
1976 .cmd_send
= null_hci_send
,
1977 .sco_send
= null_hci_send
,
1978 .acl_send
= null_hci_send
,
1979 .bdaddr_set
= null_hci_addr_set
,
1982 struct HCIInfo
*qemu_next_hci(void)
1984 if (cur_hci
== nb_hcis
)
1987 return hci_table
[cur_hci
++];
1990 static struct HCIInfo
*hci_init(const char *str
)
1993 struct bt_scatternet_s
*vlan
= 0;
1995 if (!strcmp(str
, "null"))
1998 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
2000 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
2001 else if (!strncmp(str
, "hci", 3)) {
2004 if (!strncmp(str
+ 3, ",vlan=", 6)) {
2005 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
2010 vlan
= qemu_find_bt_vlan(0);
2012 return bt_new_hci(vlan
);
2015 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
2020 static int bt_hci_parse(const char *str
)
2022 struct HCIInfo
*hci
;
2025 if (nb_hcis
>= MAX_NICS
) {
2026 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
2030 hci
= hci_init(str
);
2039 bdaddr
.b
[5] = 0x56 + nb_hcis
;
2040 hci
->bdaddr_set(hci
, bdaddr
.b
);
2042 hci_table
[nb_hcis
++] = hci
;
2047 static void bt_vhci_add(int vlan_id
)
2049 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
2052 fprintf(stderr
, "qemu: warning: adding a VHCI to "
2053 "an empty scatternet %i\n", vlan_id
);
2055 bt_vhci_init(bt_new_hci(vlan
));
2058 static struct bt_device_s
*bt_device_add(const char *opt
)
2060 struct bt_scatternet_s
*vlan
;
2062 char *endp
= strstr(opt
, ",vlan=");
2063 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
2066 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
2069 vlan_id
= strtol(endp
+ 6, &endp
, 0);
2071 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
2076 vlan
= qemu_find_bt_vlan(vlan_id
);
2079 fprintf(stderr
, "qemu: warning: adding a slave device to "
2080 "an empty scatternet %i\n", vlan_id
);
2082 if (!strcmp(devname
, "keyboard"))
2083 return bt_keyboard_init(vlan
);
2085 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
2089 static int bt_parse(const char *opt
)
2091 const char *endp
, *p
;
2094 if (strstart(opt
, "hci", &endp
)) {
2095 if (!*endp
|| *endp
== ',') {
2097 if (!strstart(endp
, ",vlan=", 0))
2100 return bt_hci_parse(opt
);
2102 } else if (strstart(opt
, "vhci", &endp
)) {
2103 if (!*endp
|| *endp
== ',') {
2105 if (strstart(endp
, ",vlan=", &p
)) {
2106 vlan
= strtol(p
, (char **) &endp
, 0);
2108 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
2112 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
2121 } else if (strstart(opt
, "device:", &endp
))
2122 return !bt_device_add(endp
);
2124 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
2128 /***********************************************************/
2129 /* QEMU Block devices */
2131 #define HD_ALIAS "index=%d,media=disk"
2133 #define CDROM_ALIAS "index=1,media=cdrom"
2135 #define CDROM_ALIAS "index=2,media=cdrom"
2137 #define FD_ALIAS "index=%d,if=floppy"
2138 #define PFLASH_ALIAS "if=pflash"
2139 #define MTD_ALIAS "if=mtd"
2140 #define SD_ALIAS "index=0,if=sd"
2142 static int drive_add(const char *file
, const char *fmt
, ...)
2146 if (nb_drives_opt
>= MAX_DRIVES
) {
2147 fprintf(stderr
, "qemu: too many drives\n");
2151 drives_opt
[nb_drives_opt
].file
= file
;
2153 vsnprintf(drives_opt
[nb_drives_opt
].opt
,
2154 sizeof(drives_opt
[0].opt
), fmt
, ap
);
2157 return nb_drives_opt
++;
2160 int drive_get_index(BlockInterfaceType type
, int bus
, int unit
)
2164 /* seek interface, bus and unit */
2166 for (index
= 0; index
< nb_drives
; index
++)
2167 if (drives_table
[index
].type
== type
&&
2168 drives_table
[index
].bus
== bus
&&
2169 drives_table
[index
].unit
== unit
)
2175 int drive_get_max_bus(BlockInterfaceType type
)
2181 for (index
= 0; index
< nb_drives
; index
++) {
2182 if(drives_table
[index
].type
== type
&&
2183 drives_table
[index
].bus
> max_bus
)
2184 max_bus
= drives_table
[index
].bus
;
2189 const char *drive_get_serial(BlockDriverState
*bdrv
)
2193 for (index
= 0; index
< nb_drives
; index
++)
2194 if (drives_table
[index
].bdrv
== bdrv
)
2195 return drives_table
[index
].serial
;
2200 BlockInterfaceErrorAction
drive_get_onerror(BlockDriverState
*bdrv
)
2204 for (index
= 0; index
< nb_drives
; index
++)
2205 if (drives_table
[index
].bdrv
== bdrv
)
2206 return drives_table
[index
].onerror
;
2208 return BLOCK_ERR_REPORT
;
2211 static void bdrv_format_print(void *opaque
, const char *name
)
2213 fprintf(stderr
, " %s", name
);
2216 static int drive_init(struct drive_opt
*arg
, int snapshot
,
2217 QEMUMachine
*machine
)
2223 const char *mediastr
= "";
2224 BlockInterfaceType type
;
2225 enum { MEDIA_DISK
, MEDIA_CDROM
} media
;
2226 int bus_id
, unit_id
;
2227 int cyls
, heads
, secs
, translation
;
2228 BlockDriverState
*bdrv
;
2229 BlockDriver
*drv
= NULL
;
2233 int bdrv_flags
, onerror
;
2234 char *str
= arg
->opt
;
2235 static const char * const params
[] = { "bus", "unit", "if", "index",
2236 "cyls", "heads", "secs", "trans",
2237 "media", "snapshot", "file",
2238 "cache", "format", "serial", "werror",
2241 if (check_params(buf
, sizeof(buf
), params
, str
) < 0) {
2242 fprintf(stderr
, "qemu: unknown parameter '%s' in '%s'\n",
2248 cyls
= heads
= secs
= 0;
2251 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2255 if (machine
->use_scsi
) {
2257 max_devs
= MAX_SCSI_DEVS
;
2258 pstrcpy(devname
, sizeof(devname
), "scsi");
2261 max_devs
= MAX_IDE_DEVS
;
2262 pstrcpy(devname
, sizeof(devname
), "ide");
2266 /* extract parameters */
2268 if (get_param_value(buf
, sizeof(buf
), "bus", str
)) {
2269 bus_id
= strtol(buf
, NULL
, 0);
2271 fprintf(stderr
, "qemu: '%s' invalid bus id\n", str
);
2276 if (get_param_value(buf
, sizeof(buf
), "unit", str
)) {
2277 unit_id
= strtol(buf
, NULL
, 0);
2279 fprintf(stderr
, "qemu: '%s' invalid unit id\n", str
);
2284 if (get_param_value(buf
, sizeof(buf
), "if", str
)) {
2285 pstrcpy(devname
, sizeof(devname
), buf
);
2286 if (!strcmp(buf
, "ide")) {
2288 max_devs
= MAX_IDE_DEVS
;
2289 } else if (!strcmp(buf
, "scsi")) {
2291 max_devs
= MAX_SCSI_DEVS
;
2292 } else if (!strcmp(buf
, "floppy")) {
2295 } else if (!strcmp(buf
, "pflash")) {
2298 } else if (!strcmp(buf
, "mtd")) {
2301 } else if (!strcmp(buf
, "sd")) {
2304 } else if (!strcmp(buf
, "virtio")) {
2308 fprintf(stderr
, "qemu: '%s' unsupported bus type '%s'\n", str
, buf
);
2313 if (get_param_value(buf
, sizeof(buf
), "index", str
)) {
2314 index
= strtol(buf
, NULL
, 0);
2316 fprintf(stderr
, "qemu: '%s' invalid index\n", str
);
2321 if (get_param_value(buf
, sizeof(buf
), "cyls", str
)) {
2322 cyls
= strtol(buf
, NULL
, 0);
2325 if (get_param_value(buf
, sizeof(buf
), "heads", str
)) {
2326 heads
= strtol(buf
, NULL
, 0);
2329 if (get_param_value(buf
, sizeof(buf
), "secs", str
)) {
2330 secs
= strtol(buf
, NULL
, 0);
2333 if (cyls
|| heads
|| secs
) {
2334 if (cyls
< 1 || cyls
> 16383) {
2335 fprintf(stderr
, "qemu: '%s' invalid physical cyls number\n", str
);
2338 if (heads
< 1 || heads
> 16) {
2339 fprintf(stderr
, "qemu: '%s' invalid physical heads number\n", str
);
2342 if (secs
< 1 || secs
> 63) {
2343 fprintf(stderr
, "qemu: '%s' invalid physical secs number\n", str
);
2348 if (get_param_value(buf
, sizeof(buf
), "trans", str
)) {
2351 "qemu: '%s' trans must be used with cyls,heads and secs\n",
2355 if (!strcmp(buf
, "none"))
2356 translation
= BIOS_ATA_TRANSLATION_NONE
;
2357 else if (!strcmp(buf
, "lba"))
2358 translation
= BIOS_ATA_TRANSLATION_LBA
;
2359 else if (!strcmp(buf
, "auto"))
2360 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2362 fprintf(stderr
, "qemu: '%s' invalid translation type\n", str
);
2367 if (get_param_value(buf
, sizeof(buf
), "media", str
)) {
2368 if (!strcmp(buf
, "disk")) {
2370 } else if (!strcmp(buf
, "cdrom")) {
2371 if (cyls
|| secs
|| heads
) {
2373 "qemu: '%s' invalid physical CHS format\n", str
);
2376 media
= MEDIA_CDROM
;
2378 fprintf(stderr
, "qemu: '%s' invalid media\n", str
);
2383 if (get_param_value(buf
, sizeof(buf
), "snapshot", str
)) {
2384 if (!strcmp(buf
, "on"))
2386 else if (!strcmp(buf
, "off"))
2389 fprintf(stderr
, "qemu: '%s' invalid snapshot option\n", str
);
2394 if (get_param_value(buf
, sizeof(buf
), "cache", str
)) {
2395 if (!strcmp(buf
, "off") || !strcmp(buf
, "none"))
2397 else if (!strcmp(buf
, "writethrough"))
2399 else if (!strcmp(buf
, "writeback"))
2402 fprintf(stderr
, "qemu: invalid cache option\n");
2407 if (get_param_value(buf
, sizeof(buf
), "format", str
)) {
2408 if (strcmp(buf
, "?") == 0) {
2409 fprintf(stderr
, "qemu: Supported formats:");
2410 bdrv_iterate_format(bdrv_format_print
, NULL
);
2411 fprintf(stderr
, "\n");
2414 drv
= bdrv_find_format(buf
);
2416 fprintf(stderr
, "qemu: '%s' invalid format\n", buf
);
2421 if (arg
->file
== NULL
)
2422 get_param_value(file
, sizeof(file
), "file", str
);
2424 pstrcpy(file
, sizeof(file
), arg
->file
);
2426 if (!get_param_value(serial
, sizeof(serial
), "serial", str
))
2427 memset(serial
, 0, sizeof(serial
));
2429 onerror
= BLOCK_ERR_REPORT
;
2430 if (get_param_value(buf
, sizeof(serial
), "werror", str
)) {
2431 if (type
!= IF_IDE
&& type
!= IF_SCSI
&& type
!= IF_VIRTIO
) {
2432 fprintf(stderr
, "werror is no supported by this format\n");
2435 if (!strcmp(buf
, "ignore"))
2436 onerror
= BLOCK_ERR_IGNORE
;
2437 else if (!strcmp(buf
, "enospc"))
2438 onerror
= BLOCK_ERR_STOP_ENOSPC
;
2439 else if (!strcmp(buf
, "stop"))
2440 onerror
= BLOCK_ERR_STOP_ANY
;
2441 else if (!strcmp(buf
, "report"))
2442 onerror
= BLOCK_ERR_REPORT
;
2444 fprintf(stderr
, "qemu: '%s' invalid write error action\n", buf
);
2449 /* compute bus and unit according index */
2452 if (bus_id
!= 0 || unit_id
!= -1) {
2454 "qemu: '%s' index cannot be used with bus and unit\n", str
);
2462 unit_id
= index
% max_devs
;
2463 bus_id
= index
/ max_devs
;
2467 /* if user doesn't specify a unit_id,
2468 * try to find the first free
2471 if (unit_id
== -1) {
2473 while (drive_get_index(type
, bus_id
, unit_id
) != -1) {
2475 if (max_devs
&& unit_id
>= max_devs
) {
2476 unit_id
-= max_devs
;
2484 if (max_devs
&& unit_id
>= max_devs
) {
2485 fprintf(stderr
, "qemu: '%s' unit %d too big (max is %d)\n",
2486 str
, unit_id
, max_devs
- 1);
2491 * ignore multiple definitions
2494 if (drive_get_index(type
, bus_id
, unit_id
) != -1)
2499 if (type
== IF_IDE
|| type
== IF_SCSI
)
2500 mediastr
= (media
== MEDIA_CDROM
) ? "-cd" : "-hd";
2502 snprintf(buf
, sizeof(buf
), "%s%i%s%i",
2503 devname
, bus_id
, mediastr
, unit_id
);
2505 snprintf(buf
, sizeof(buf
), "%s%s%i",
2506 devname
, mediastr
, unit_id
);
2507 bdrv
= bdrv_new(buf
);
2508 drives_table
[nb_drives
].bdrv
= bdrv
;
2509 drives_table
[nb_drives
].type
= type
;
2510 drives_table
[nb_drives
].bus
= bus_id
;
2511 drives_table
[nb_drives
].unit
= unit_id
;
2512 drives_table
[nb_drives
].onerror
= onerror
;
2513 strncpy(drives_table
[nb_drives
].serial
, serial
, sizeof(serial
));
2522 bdrv_set_geometry_hint(bdrv
, cyls
, heads
, secs
);
2523 bdrv_set_translation_hint(bdrv
, translation
);
2527 bdrv_set_type_hint(bdrv
, BDRV_TYPE_CDROM
);
2532 /* FIXME: This isn't really a floppy, but it's a reasonable
2535 bdrv_set_type_hint(bdrv
, BDRV_TYPE_FLOPPY
);
2546 bdrv_flags
|= BDRV_O_SNAPSHOT
;
2547 cache
= 2; /* always use write-back with snapshot */
2549 if (cache
== 0) /* no caching */
2550 bdrv_flags
|= BDRV_O_NOCACHE
;
2551 else if (cache
== 2) /* write-back */
2552 bdrv_flags
|= BDRV_O_CACHE_WB
;
2553 else if (cache
== 3) /* not specified */
2554 bdrv_flags
|= BDRV_O_CACHE_DEF
;
2555 if (bdrv_open2(bdrv
, file
, bdrv_flags
, drv
) < 0 || qemu_key_check(bdrv
, file
)) {
2556 fprintf(stderr
, "qemu: could not open disk image %s\n",
2563 /***********************************************************/
2566 static USBPort
*used_usb_ports
;
2567 static USBPort
*free_usb_ports
;
2569 /* ??? Maybe change this to register a hub to keep track of the topology. */
2570 void qemu_register_usb_port(USBPort
*port
, void *opaque
, int index
,
2571 usb_attachfn attach
)
2573 port
->opaque
= opaque
;
2574 port
->index
= index
;
2575 port
->attach
= attach
;
2576 port
->next
= free_usb_ports
;
2577 free_usb_ports
= port
;
2580 int usb_device_add_dev(USBDevice
*dev
)
2584 /* Find a USB port to add the device to. */
2585 port
= free_usb_ports
;
2589 /* Create a new hub and chain it on. */
2590 free_usb_ports
= NULL
;
2591 port
->next
= used_usb_ports
;
2592 used_usb_ports
= port
;
2594 hub
= usb_hub_init(VM_USB_HUB_SIZE
);
2595 usb_attach(port
, hub
);
2596 port
= free_usb_ports
;
2599 free_usb_ports
= port
->next
;
2600 port
->next
= used_usb_ports
;
2601 used_usb_ports
= port
;
2602 usb_attach(port
, dev
);
2606 static int usb_device_add(const char *devname
)
2611 if (!free_usb_ports
)
2614 if (strstart(devname
, "host:", &p
)) {
2615 dev
= usb_host_device_open(p
);
2616 } else if (!strcmp(devname
, "mouse")) {
2617 dev
= usb_mouse_init();
2618 } else if (!strcmp(devname
, "tablet")) {
2619 dev
= usb_tablet_init();
2620 } else if (!strcmp(devname
, "keyboard")) {
2621 dev
= usb_keyboard_init();
2622 } else if (strstart(devname
, "disk:", &p
)) {
2623 dev
= usb_msd_init(p
);
2624 } else if (!strcmp(devname
, "wacom-tablet")) {
2625 dev
= usb_wacom_init();
2626 } else if (strstart(devname
, "serial:", &p
)) {
2627 dev
= usb_serial_init(p
);
2628 #ifdef CONFIG_BRLAPI
2629 } else if (!strcmp(devname
, "braille")) {
2630 dev
= usb_baum_init();
2632 } else if (strstart(devname
, "net:", &p
)) {
2635 if (net_client_init("nic", p
) < 0)
2637 nd_table
[nic
].model
= "usb";
2638 dev
= usb_net_init(&nd_table
[nic
]);
2639 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
2640 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
2641 bt_new_hci(qemu_find_bt_vlan(0)));
2648 return usb_device_add_dev(dev
);
2651 int usb_device_del_addr(int bus_num
, int addr
)
2657 if (!used_usb_ports
)
2663 lastp
= &used_usb_ports
;
2664 port
= used_usb_ports
;
2665 while (port
&& port
->dev
->addr
!= addr
) {
2666 lastp
= &port
->next
;
2674 *lastp
= port
->next
;
2675 usb_attach(port
, NULL
);
2676 dev
->handle_destroy(dev
);
2677 port
->next
= free_usb_ports
;
2678 free_usb_ports
= port
;
2682 static int usb_device_del(const char *devname
)
2687 if (strstart(devname
, "host:", &p
))
2688 return usb_host_device_close(p
);
2690 if (!used_usb_ports
)
2693 p
= strchr(devname
, '.');
2696 bus_num
= strtoul(devname
, NULL
, 0);
2697 addr
= strtoul(p
+ 1, NULL
, 0);
2699 return usb_device_del_addr(bus_num
, addr
);
2702 void do_usb_add(const char *devname
)
2704 usb_device_add(devname
);
2707 void do_usb_del(const char *devname
)
2709 usb_device_del(devname
);
2716 const char *speed_str
;
2719 term_printf("USB support not enabled\n");
2723 for (port
= used_usb_ports
; port
; port
= port
->next
) {
2727 switch(dev
->speed
) {
2731 case USB_SPEED_FULL
:
2734 case USB_SPEED_HIGH
:
2741 term_printf(" Device %d.%d, Speed %s Mb/s, Product %s\n",
2742 0, dev
->addr
, speed_str
, dev
->devname
);
2746 /***********************************************************/
2747 /* PCMCIA/Cardbus */
2749 static struct pcmcia_socket_entry_s
{
2750 struct pcmcia_socket_s
*socket
;
2751 struct pcmcia_socket_entry_s
*next
;
2752 } *pcmcia_sockets
= 0;
2754 void pcmcia_socket_register(struct pcmcia_socket_s
*socket
)
2756 struct pcmcia_socket_entry_s
*entry
;
2758 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
2759 entry
->socket
= socket
;
2760 entry
->next
= pcmcia_sockets
;
2761 pcmcia_sockets
= entry
;
2764 void pcmcia_socket_unregister(struct pcmcia_socket_s
*socket
)
2766 struct pcmcia_socket_entry_s
*entry
, **ptr
;
2768 ptr
= &pcmcia_sockets
;
2769 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
2770 if (entry
->socket
== socket
) {
2776 void pcmcia_info(void)
2778 struct pcmcia_socket_entry_s
*iter
;
2779 if (!pcmcia_sockets
)
2780 term_printf("No PCMCIA sockets\n");
2782 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
2783 term_printf("%s: %s\n", iter
->socket
->slot_string
,
2784 iter
->socket
->attached
? iter
->socket
->card_string
:
2788 /***********************************************************/
2789 /* register display */
2791 void register_displaystate(DisplayState
*ds
)
2801 DisplayState
*get_displaystate(void)
2803 return display_state
;
2808 static void dumb_display_init(void)
2810 DisplayState
*ds
= qemu_mallocz(sizeof(DisplayState
));
2812 fprintf(stderr
, "dumb_display_init: DisplayState allocation failed\n");
2815 ds
->surface
= qemu_create_displaysurface(640, 480, 32, 640 * 4);
2816 register_displaystate(ds
);
2819 /***********************************************************/
2822 #define MAX_IO_HANDLERS 64
2824 typedef struct IOHandlerRecord
{
2826 IOCanRWHandler
*fd_read_poll
;
2828 IOHandler
*fd_write
;
2831 /* temporary data */
2833 struct IOHandlerRecord
*next
;
2836 static IOHandlerRecord
*first_io_handler
;
2838 /* XXX: fd_read_poll should be suppressed, but an API change is
2839 necessary in the character devices to suppress fd_can_read(). */
2840 int qemu_set_fd_handler2(int fd
,
2841 IOCanRWHandler
*fd_read_poll
,
2843 IOHandler
*fd_write
,
2846 IOHandlerRecord
**pioh
, *ioh
;
2848 if (!fd_read
&& !fd_write
) {
2849 pioh
= &first_io_handler
;
2854 if (ioh
->fd
== fd
) {
2861 for(ioh
= first_io_handler
; ioh
!= NULL
; ioh
= ioh
->next
) {
2865 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
2868 ioh
->next
= first_io_handler
;
2869 first_io_handler
= ioh
;
2872 ioh
->fd_read_poll
= fd_read_poll
;
2873 ioh
->fd_read
= fd_read
;
2874 ioh
->fd_write
= fd_write
;
2875 ioh
->opaque
= opaque
;
2881 int qemu_set_fd_handler(int fd
,
2883 IOHandler
*fd_write
,
2886 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
2890 /***********************************************************/
2891 /* Polling handling */
2893 typedef struct PollingEntry
{
2896 struct PollingEntry
*next
;
2899 static PollingEntry
*first_polling_entry
;
2901 int qemu_add_polling_cb(PollingFunc
*func
, void *opaque
)
2903 PollingEntry
**ppe
, *pe
;
2904 pe
= qemu_mallocz(sizeof(PollingEntry
));
2908 pe
->opaque
= opaque
;
2909 for(ppe
= &first_polling_entry
; *ppe
!= NULL
; ppe
= &(*ppe
)->next
);
2914 void qemu_del_polling_cb(PollingFunc
*func
, void *opaque
)
2916 PollingEntry
**ppe
, *pe
;
2917 for(ppe
= &first_polling_entry
; *ppe
!= NULL
; ppe
= &(*ppe
)->next
) {
2919 if (pe
->func
== func
&& pe
->opaque
== opaque
) {
2927 /***********************************************************/
2928 /* Wait objects support */
2929 typedef struct WaitObjects
{
2931 HANDLE events
[MAXIMUM_WAIT_OBJECTS
+ 1];
2932 WaitObjectFunc
*func
[MAXIMUM_WAIT_OBJECTS
+ 1];
2933 void *opaque
[MAXIMUM_WAIT_OBJECTS
+ 1];
2936 static WaitObjects wait_objects
= {0};
2938 int qemu_add_wait_object(HANDLE handle
, WaitObjectFunc
*func
, void *opaque
)
2940 WaitObjects
*w
= &wait_objects
;
2942 if (w
->num
>= MAXIMUM_WAIT_OBJECTS
)
2944 w
->events
[w
->num
] = handle
;
2945 w
->func
[w
->num
] = func
;
2946 w
->opaque
[w
->num
] = opaque
;
2951 void qemu_del_wait_object(HANDLE handle
, WaitObjectFunc
*func
, void *opaque
)
2954 WaitObjects
*w
= &wait_objects
;
2957 for (i
= 0; i
< w
->num
; i
++) {
2958 if (w
->events
[i
] == handle
)
2961 w
->events
[i
] = w
->events
[i
+ 1];
2962 w
->func
[i
] = w
->func
[i
+ 1];
2963 w
->opaque
[i
] = w
->opaque
[i
+ 1];
2971 /***********************************************************/
2972 /* ram save/restore */
2974 static int ram_get_page(QEMUFile
*f
, uint8_t *buf
, int len
)
2978 v
= qemu_get_byte(f
);
2981 if (qemu_get_buffer(f
, buf
, len
) != len
)
2985 v
= qemu_get_byte(f
);
2986 memset(buf
, v
, len
);
2992 if (qemu_file_has_error(f
))
2998 static int ram_load_v1(QEMUFile
*f
, void *opaque
)
3003 if (qemu_get_be32(f
) != phys_ram_size
)
3005 for(i
= 0; i
< phys_ram_size
; i
+= TARGET_PAGE_SIZE
) {
3006 ret
= ram_get_page(f
, phys_ram_base
+ i
, TARGET_PAGE_SIZE
);
3013 #define BDRV_HASH_BLOCK_SIZE 1024
3014 #define IOBUF_SIZE 4096
3015 #define RAM_CBLOCK_MAGIC 0xfabe
3017 typedef struct RamDecompressState
{
3020 uint8_t buf
[IOBUF_SIZE
];
3021 } RamDecompressState
;
3023 static int ram_decompress_open(RamDecompressState
*s
, QEMUFile
*f
)
3026 memset(s
, 0, sizeof(*s
));
3028 ret
= inflateInit(&s
->zstream
);
3034 static int ram_decompress_buf(RamDecompressState
*s
, uint8_t *buf
, int len
)
3038 s
->zstream
.avail_out
= len
;
3039 s
->zstream
.next_out
= buf
;
3040 while (s
->zstream
.avail_out
> 0) {
3041 if (s
->zstream
.avail_in
== 0) {
3042 if (qemu_get_be16(s
->f
) != RAM_CBLOCK_MAGIC
)
3044 clen
= qemu_get_be16(s
->f
);
3045 if (clen
> IOBUF_SIZE
)
3047 qemu_get_buffer(s
->f
, s
->buf
, clen
);
3048 s
->zstream
.avail_in
= clen
;
3049 s
->zstream
.next_in
= s
->buf
;
3051 ret
= inflate(&s
->zstream
, Z_PARTIAL_FLUSH
);
3052 if (ret
!= Z_OK
&& ret
!= Z_STREAM_END
) {
3059 static void ram_decompress_close(RamDecompressState
*s
)
3061 inflateEnd(&s
->zstream
);
3064 #define RAM_SAVE_FLAG_FULL 0x01
3065 #define RAM_SAVE_FLAG_COMPRESS 0x02
3066 #define RAM_SAVE_FLAG_MEM_SIZE 0x04
3067 #define RAM_SAVE_FLAG_PAGE 0x08
3068 #define RAM_SAVE_FLAG_EOS 0x10
3070 static int is_dup_page(uint8_t *page
, uint8_t ch
)
3072 uint32_t val
= ch
<< 24 | ch
<< 16 | ch
<< 8 | ch
;
3073 uint32_t *array
= (uint32_t *)page
;
3076 for (i
= 0; i
< (TARGET_PAGE_SIZE
/ 4); i
++) {
3077 if (array
[i
] != val
)
3084 static int ram_save_block(QEMUFile
*f
)
3086 static ram_addr_t current_addr
= 0;
3087 ram_addr_t saved_addr
= current_addr
;
3088 ram_addr_t addr
= 0;
3091 while (addr
< phys_ram_size
) {
3092 if (cpu_physical_memory_get_dirty(current_addr
, MIGRATION_DIRTY_FLAG
)) {
3095 cpu_physical_memory_reset_dirty(current_addr
,
3096 current_addr
+ TARGET_PAGE_SIZE
,
3097 MIGRATION_DIRTY_FLAG
);
3099 ch
= *(phys_ram_base
+ current_addr
);
3101 if (is_dup_page(phys_ram_base
+ current_addr
, ch
)) {
3102 qemu_put_be64(f
, current_addr
| RAM_SAVE_FLAG_COMPRESS
);
3103 qemu_put_byte(f
, ch
);
3105 qemu_put_be64(f
, current_addr
| RAM_SAVE_FLAG_PAGE
);
3106 qemu_put_buffer(f
, phys_ram_base
+ current_addr
, TARGET_PAGE_SIZE
);
3112 addr
+= TARGET_PAGE_SIZE
;
3113 current_addr
= (saved_addr
+ addr
) % phys_ram_size
;
3119 static ram_addr_t ram_save_threshold
= 10;
3121 static ram_addr_t
ram_save_remaining(void)
3124 ram_addr_t count
= 0;
3126 for (addr
= 0; addr
< phys_ram_size
; addr
+= TARGET_PAGE_SIZE
) {
3127 if (cpu_physical_memory_get_dirty(addr
, MIGRATION_DIRTY_FLAG
))
3134 static int ram_save_live(QEMUFile
*f
, int stage
, void *opaque
)
3139 /* Make sure all dirty bits are set */
3140 for (addr
= 0; addr
< phys_ram_size
; addr
+= TARGET_PAGE_SIZE
) {
3141 if (!cpu_physical_memory_get_dirty(addr
, MIGRATION_DIRTY_FLAG
))
3142 cpu_physical_memory_set_dirty(addr
);
3145 /* Enable dirty memory tracking */
3146 cpu_physical_memory_set_dirty_tracking(1);
3148 qemu_put_be64(f
, phys_ram_size
| RAM_SAVE_FLAG_MEM_SIZE
);
3151 while (!qemu_file_rate_limit(f
)) {
3154 ret
= ram_save_block(f
);
3155 if (ret
== 0) /* no more blocks */
3159 /* try transferring iterative blocks of memory */
3162 cpu_physical_memory_set_dirty_tracking(0);
3164 /* flush all remaining blocks regardless of rate limiting */
3165 while (ram_save_block(f
) != 0);
3168 qemu_put_be64(f
, RAM_SAVE_FLAG_EOS
);
3170 return (stage
== 2) && (ram_save_remaining() < ram_save_threshold
);
3173 static int ram_load_dead(QEMUFile
*f
, void *opaque
)
3175 RamDecompressState s1
, *s
= &s1
;
3179 if (ram_decompress_open(s
, f
) < 0)
3181 for(i
= 0; i
< phys_ram_size
; i
+= BDRV_HASH_BLOCK_SIZE
) {
3182 if (ram_decompress_buf(s
, buf
, 1) < 0) {
3183 fprintf(stderr
, "Error while reading ram block header\n");
3187 if (ram_decompress_buf(s
, phys_ram_base
+ i
, BDRV_HASH_BLOCK_SIZE
) < 0) {
3188 fprintf(stderr
, "Error while reading ram block address=0x%08" PRIx64
, (uint64_t)i
);
3193 printf("Error block header\n");
3197 ram_decompress_close(s
);
3202 static int ram_load(QEMUFile
*f
, void *opaque
, int version_id
)
3207 if (version_id
== 1)
3208 return ram_load_v1(f
, opaque
);
3210 if (version_id
== 2) {
3211 if (qemu_get_be32(f
) != phys_ram_size
)
3213 return ram_load_dead(f
, opaque
);
3216 if (version_id
!= 3)
3220 addr
= qemu_get_be64(f
);
3222 flags
= addr
& ~TARGET_PAGE_MASK
;
3223 addr
&= TARGET_PAGE_MASK
;
3225 if (flags
& RAM_SAVE_FLAG_MEM_SIZE
) {
3226 if (addr
!= phys_ram_size
)
3230 if (flags
& RAM_SAVE_FLAG_FULL
) {
3231 if (ram_load_dead(f
, opaque
) < 0)
3235 if (flags
& RAM_SAVE_FLAG_COMPRESS
) {
3236 uint8_t ch
= qemu_get_byte(f
);
3237 memset(phys_ram_base
+ addr
, ch
, TARGET_PAGE_SIZE
);
3238 } else if (flags
& RAM_SAVE_FLAG_PAGE
)
3239 qemu_get_buffer(f
, phys_ram_base
+ addr
, TARGET_PAGE_SIZE
);
3240 } while (!(flags
& RAM_SAVE_FLAG_EOS
));
3245 void qemu_service_io(void)
3247 CPUState
*env
= cpu_single_env
;
3249 cpu_interrupt(env
, CPU_INTERRUPT_EXIT
);
3251 if (env
->kqemu_enabled
) {
3252 kqemu_cpu_interrupt(env
);
3258 /***********************************************************/
3259 /* bottom halves (can be seen as timers which expire ASAP) */
3270 static QEMUBH
*first_bh
= NULL
;
3272 QEMUBH
*qemu_bh_new(QEMUBHFunc
*cb
, void *opaque
)
3275 bh
= qemu_mallocz(sizeof(QEMUBH
));
3279 bh
->opaque
= opaque
;
3280 bh
->next
= first_bh
;
3285 int qemu_bh_poll(void)
3291 for (bh
= first_bh
; bh
; bh
= bh
->next
) {
3292 if (!bh
->deleted
&& bh
->scheduled
) {
3301 /* remove deleted bhs */
3315 void qemu_bh_schedule_idle(QEMUBH
*bh
)
3323 void qemu_bh_schedule(QEMUBH
*bh
)
3325 CPUState
*env
= cpu_single_env
;
3330 /* stop the currently executing CPU to execute the BH ASAP */
3332 cpu_interrupt(env
, CPU_INTERRUPT_EXIT
);
3336 void qemu_bh_cancel(QEMUBH
*bh
)
3341 void qemu_bh_delete(QEMUBH
*bh
)
3347 static void qemu_bh_update_timeout(int *timeout
)
3351 for (bh
= first_bh
; bh
; bh
= bh
->next
) {
3352 if (!bh
->deleted
&& bh
->scheduled
) {
3354 /* idle bottom halves will be polled at least
3356 *timeout
= MIN(10, *timeout
);
3358 /* non-idle bottom halves will be executed
3367 /***********************************************************/
3368 /* machine registration */
3370 static QEMUMachine
*first_machine
= NULL
;
3372 int qemu_register_machine(QEMUMachine
*m
)
3375 pm
= &first_machine
;
3383 static QEMUMachine
*find_machine(const char *name
)
3387 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
3388 if (!strcmp(m
->name
, name
))
3394 /***********************************************************/
3395 /* main execution loop */
3397 static void gui_update(void *opaque
)
3399 uint64_t interval
= GUI_REFRESH_INTERVAL
;
3400 DisplayState
*ds
= opaque
;
3401 DisplayChangeListener
*dcl
= ds
->listeners
;
3405 while (dcl
!= NULL
) {
3406 if (dcl
->gui_timer_interval
&&
3407 dcl
->gui_timer_interval
< interval
)
3408 interval
= dcl
->gui_timer_interval
;
3411 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
3414 static void nographic_update(void *opaque
)
3416 uint64_t interval
= GUI_REFRESH_INTERVAL
;
3418 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
3421 struct vm_change_state_entry
{
3422 VMChangeStateHandler
*cb
;
3424 LIST_ENTRY (vm_change_state_entry
) entries
;
3427 static LIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
3429 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
3432 VMChangeStateEntry
*e
;
3434 e
= qemu_mallocz(sizeof (*e
));
3440 LIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
3444 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
3446 LIST_REMOVE (e
, entries
);
3450 static void vm_state_notify(int running
, int reason
)
3452 VMChangeStateEntry
*e
;
3454 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
3455 e
->cb(e
->opaque
, running
, reason
);
3464 vm_state_notify(1, 0);
3465 qemu_rearm_alarm_timer(alarm_timer
);
3469 void vm_stop(int reason
)
3472 cpu_disable_ticks();
3474 vm_state_notify(0, reason
);
3478 /* reset/shutdown handler */
3480 typedef struct QEMUResetEntry
{
3481 QEMUResetHandler
*func
;
3483 struct QEMUResetEntry
*next
;
3486 static QEMUResetEntry
*first_reset_entry
;
3487 static int reset_requested
;
3488 static int shutdown_requested
;
3489 static int powerdown_requested
;
3491 int qemu_shutdown_requested(void)
3493 int r
= shutdown_requested
;
3494 shutdown_requested
= 0;
3498 int qemu_reset_requested(void)
3500 int r
= reset_requested
;
3501 reset_requested
= 0;
3505 int qemu_powerdown_requested(void)
3507 int r
= powerdown_requested
;
3508 powerdown_requested
= 0;
3512 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
3514 QEMUResetEntry
**pre
, *re
;
3516 pre
= &first_reset_entry
;
3517 while (*pre
!= NULL
)
3518 pre
= &(*pre
)->next
;
3519 re
= qemu_mallocz(sizeof(QEMUResetEntry
));
3521 re
->opaque
= opaque
;
3526 void qemu_system_reset(void)
3530 /* reset all devices */
3531 for(re
= first_reset_entry
; re
!= NULL
; re
= re
->next
) {
3532 re
->func(re
->opaque
);
3536 void qemu_system_reset_request(void)
3539 shutdown_requested
= 1;
3541 reset_requested
= 1;
3544 cpu_interrupt(cpu_single_env
, CPU_INTERRUPT_EXIT
);
3547 void qemu_system_shutdown_request(void)
3549 shutdown_requested
= 1;
3551 cpu_interrupt(cpu_single_env
, CPU_INTERRUPT_EXIT
);
3554 void qemu_system_powerdown_request(void)
3556 powerdown_requested
= 1;
3558 cpu_interrupt(cpu_single_env
, CPU_INTERRUPT_EXIT
);
3562 static void host_main_loop_wait(int *timeout
)
3568 /* XXX: need to suppress polling by better using win32 events */
3570 for(pe
= first_polling_entry
; pe
!= NULL
; pe
= pe
->next
) {
3571 ret
|= pe
->func(pe
->opaque
);
3575 WaitObjects
*w
= &wait_objects
;
3577 ret
= WaitForMultipleObjects(w
->num
, w
->events
, FALSE
, *timeout
);
3578 if (WAIT_OBJECT_0
+ 0 <= ret
&& ret
<= WAIT_OBJECT_0
+ w
->num
- 1) {
3579 if (w
->func
[ret
- WAIT_OBJECT_0
])
3580 w
->func
[ret
- WAIT_OBJECT_0
](w
->opaque
[ret
- WAIT_OBJECT_0
]);
3582 /* Check for additional signaled events */
3583 for(i
= (ret
- WAIT_OBJECT_0
+ 1); i
< w
->num
; i
++) {
3585 /* Check if event is signaled */
3586 ret2
= WaitForSingleObject(w
->events
[i
], 0);
3587 if(ret2
== WAIT_OBJECT_0
) {
3589 w
->func
[i
](w
->opaque
[i
]);
3590 } else if (ret2
== WAIT_TIMEOUT
) {
3592 err
= GetLastError();
3593 fprintf(stderr
, "WaitForSingleObject error %d %d\n", i
, err
);
3596 } else if (ret
== WAIT_TIMEOUT
) {
3598 err
= GetLastError();
3599 fprintf(stderr
, "WaitForMultipleObjects error %d %d\n", ret
, err
);
3606 static void host_main_loop_wait(int *timeout
)
3611 void main_loop_wait(int timeout
)
3613 IOHandlerRecord
*ioh
;
3614 fd_set rfds
, wfds
, xfds
;
3618 qemu_bh_update_timeout(&timeout
);
3620 host_main_loop_wait(&timeout
);
3622 /* poll any events */
3623 /* XXX: separate device handlers from system ones */
3628 for(ioh
= first_io_handler
; ioh
!= NULL
; ioh
= ioh
->next
) {
3632 (!ioh
->fd_read_poll
||
3633 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
3634 FD_SET(ioh
->fd
, &rfds
);
3638 if (ioh
->fd_write
) {
3639 FD_SET(ioh
->fd
, &wfds
);
3645 tv
.tv_sec
= timeout
/ 1000;
3646 tv
.tv_usec
= (timeout
% 1000) * 1000;
3648 #if defined(CONFIG_SLIRP)
3649 if (slirp_is_inited()) {
3650 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
3653 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
3655 IOHandlerRecord
**pioh
;
3657 for(ioh
= first_io_handler
; ioh
!= NULL
; ioh
= ioh
->next
) {
3658 if (!ioh
->deleted
&& ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
3659 ioh
->fd_read(ioh
->opaque
);
3661 if (!ioh
->deleted
&& ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
3662 ioh
->fd_write(ioh
->opaque
);
3666 /* remove deleted IO handlers */
3667 pioh
= &first_io_handler
;
3677 #if defined(CONFIG_SLIRP)
3678 if (slirp_is_inited()) {
3684 slirp_select_poll(&rfds
, &wfds
, &xfds
);
3688 /* vm time timers */
3689 if (vm_running
&& likely(!(cur_cpu
->singlestep_enabled
& SSTEP_NOTIMER
)))
3690 qemu_run_timers(&active_timers
[QEMU_TIMER_VIRTUAL
],
3691 qemu_get_clock(vm_clock
));
3693 /* real time timers */
3694 qemu_run_timers(&active_timers
[QEMU_TIMER_REALTIME
],
3695 qemu_get_clock(rt_clock
));
3697 /* Check bottom-halves last in case any of the earlier events triggered
3703 static int main_loop(void)
3706 #ifdef CONFIG_PROFILER
3711 cur_cpu
= first_cpu
;
3712 next_cpu
= cur_cpu
->next_cpu
?: first_cpu
;
3719 #ifdef CONFIG_PROFILER
3720 ti
= profile_getclock();
3725 qemu_icount
-= (env
->icount_decr
.u16
.low
+ env
->icount_extra
);
3726 env
->icount_decr
.u16
.low
= 0;
3727 env
->icount_extra
= 0;
3728 count
= qemu_next_deadline();
3729 count
= (count
+ (1 << icount_time_shift
) - 1)
3730 >> icount_time_shift
;
3731 qemu_icount
+= count
;
3732 decr
= (count
> 0xffff) ? 0xffff : count
;
3734 env
->icount_decr
.u16
.low
= decr
;
3735 env
->icount_extra
= count
;
3737 ret
= cpu_exec(env
);
3738 #ifdef CONFIG_PROFILER
3739 qemu_time
+= profile_getclock() - ti
;
3742 /* Fold pending instructions back into the
3743 instruction counter, and clear the interrupt flag. */
3744 qemu_icount
-= (env
->icount_decr
.u16
.low
3745 + env
->icount_extra
);
3746 env
->icount_decr
.u32
= 0;
3747 env
->icount_extra
= 0;
3749 next_cpu
= env
->next_cpu
?: first_cpu
;
3750 if (event_pending
&& likely(ret
!= EXCP_DEBUG
)) {
3751 ret
= EXCP_INTERRUPT
;
3755 if (ret
== EXCP_HLT
) {
3756 /* Give the next CPU a chance to run. */
3760 if (ret
!= EXCP_HALTED
)
3762 /* all CPUs are halted ? */
3768 if (shutdown_requested
) {
3769 ret
= EXCP_INTERRUPT
;
3777 if (reset_requested
) {
3778 reset_requested
= 0;
3779 qemu_system_reset();
3780 ret
= EXCP_INTERRUPT
;
3782 if (powerdown_requested
) {
3783 powerdown_requested
= 0;
3784 qemu_system_powerdown();
3785 ret
= EXCP_INTERRUPT
;
3787 if (unlikely(ret
== EXCP_DEBUG
)) {
3788 gdb_set_stop_cpu(cur_cpu
);
3789 vm_stop(EXCP_DEBUG
);
3791 /* If all cpus are halted then wait until the next IRQ */
3792 /* XXX: use timeout computed from timers */
3793 if (ret
== EXCP_HALTED
) {
3797 /* Advance virtual time to the next event. */
3798 if (use_icount
== 1) {
3799 /* When not using an adaptive execution frequency
3800 we tend to get badly out of sync with real time,
3801 so just delay for a reasonable amount of time. */
3804 delta
= cpu_get_icount() - cpu_get_clock();
3807 /* If virtual time is ahead of real time then just
3809 timeout
= (delta
/ 1000000) + 1;
3811 /* Wait for either IO to occur or the next
3813 add
= qemu_next_deadline();
3814 /* We advance the timer before checking for IO.
3815 Limit the amount we advance so that early IO
3816 activity won't get the guest too far ahead. */
3820 add
= (add
+ (1 << icount_time_shift
) - 1)
3821 >> icount_time_shift
;
3823 timeout
= delta
/ 1000000;
3834 if (shutdown_requested
) {
3835 ret
= EXCP_INTERRUPT
;
3840 #ifdef CONFIG_PROFILER
3841 ti
= profile_getclock();
3843 main_loop_wait(timeout
);
3844 #ifdef CONFIG_PROFILER
3845 dev_time
+= profile_getclock() - ti
;
3848 cpu_disable_ticks();
3852 static void help(int exitcode
)
3854 printf("QEMU PC emulator version " QEMU_VERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n"
3855 "usage: %s [options] [disk_image]\n"
3857 "'disk_image' is a raw hard image image for IDE hard disk 0\n"
3859 "Standard options:\n"
3860 "-M machine select emulated machine (-M ? for list)\n"
3861 "-cpu cpu select CPU (-cpu ? for list)\n"
3862 "-fda/-fdb file use 'file' as floppy disk 0/1 image\n"
3863 "-hda/-hdb file use 'file' as IDE hard disk 0/1 image\n"
3864 "-hdc/-hdd file use 'file' as IDE hard disk 2/3 image\n"
3865 "-cdrom file use 'file' as IDE cdrom image (cdrom is ide1 master)\n"
3866 "-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n"
3867 " [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n"
3868 " [,cache=writethrough|writeback|none][,format=f][,serial=s]\n"
3869 " use 'file' as a drive image\n"
3870 "-mtdblock file use 'file' as on-board Flash memory image\n"
3871 "-sd file use 'file' as SecureDigital card image\n"
3872 "-pflash file use 'file' as a parallel flash image\n"
3873 "-boot [a|c|d|n] boot on floppy (a), hard disk (c), CD-ROM (d), or network (n)\n"
3874 "-snapshot write to temporary files instead of disk image files\n"
3876 "-no-frame open SDL window without a frame and window decorations\n"
3877 "-alt-grab use Ctrl-Alt-Shift to grab mouse (instead of Ctrl-Alt)\n"
3878 "-no-quit disable SDL window close capability\n"
3882 "-no-fd-bootchk disable boot signature checking for floppy disks\n"
3884 "-m megs set virtual RAM size to megs MB [default=%d]\n"
3885 "-smp n set the number of CPUs to 'n' [default=1]\n"
3886 "-nographic disable graphical output and redirect serial I/Os to console\n"
3887 "-portrait rotate graphical output 90 deg left (only PXA LCD)\n"
3889 "-k language use keyboard layout (for example \"fr\" for French)\n"
3892 "-audio-help print list of audio drivers and their options\n"
3893 "-soundhw c1,... enable audio support\n"
3894 " and only specified sound cards (comma separated list)\n"
3895 " use -soundhw ? to get the list of supported cards\n"
3896 " use -soundhw all to enable all of them\n"
3898 "-vga [std|cirrus|vmware|none]\n"
3899 " select video card type\n"
3900 "-localtime set the real time clock to local time [default=utc]\n"
3901 "-full-screen start in full screen\n"
3903 "-win2k-hack use it when installing Windows 2000 to avoid a disk full bug\n"
3904 "-rtc-td-hack use it to fix time drift in Windows ACPI HAL\n"
3906 "-usb enable the USB driver (will be the default soon)\n"
3907 "-usbdevice name add the host or guest USB device 'name'\n"
3908 #if defined(TARGET_PPC) || defined(TARGET_SPARC)
3909 "-g WxH[xDEPTH] Set the initial graphical resolution and depth\n"
3911 "-name string set the name of the guest\n"
3912 "-uuid %%08x-%%04x-%%04x-%%04x-%%012x specify machine UUID\n"
3914 "Network options:\n"
3915 "-net nic[,vlan=n][,macaddr=addr][,model=type][,name=str]\n"
3916 " create a new Network Interface Card and connect it to VLAN 'n'\n"
3918 "-net user[,vlan=n][,name=str][,hostname=host]\n"
3919 " connect the user mode network stack to VLAN 'n' and send\n"
3920 " hostname 'host' to DHCP clients\n"
3923 "-net tap[,vlan=n][,name=str],ifname=name\n"
3924 " connect the host TAP network interface to VLAN 'n'\n"
3926 "-net tap[,vlan=n][,name=str][,fd=h][,ifname=name][,script=file][,downscript=dfile]\n"
3927 " connect the host TAP network interface to VLAN 'n' and use the\n"
3928 " network scripts 'file' (default=%s)\n"
3929 " and 'dfile' (default=%s);\n"
3930 " use '[down]script=no' to disable script execution;\n"
3931 " use 'fd=h' to connect to an already opened TAP interface\n"
3933 "-net socket[,vlan=n][,name=str][,fd=h][,listen=[host]:port][,connect=host:port]\n"
3934 " connect the vlan 'n' to another VLAN using a socket connection\n"
3935 "-net socket[,vlan=n][,name=str][,fd=h][,mcast=maddr:port]\n"
3936 " connect the vlan 'n' to multicast maddr and port\n"
3938 "-net vde[,vlan=n][,name=str][,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]\n"
3939 " connect the vlan 'n' to port 'n' of a vde switch running\n"
3940 " on host and listening for incoming connections on 'socketpath'.\n"
3941 " Use group 'groupname' and mode 'octalmode' to change default\n"
3942 " ownership and permissions for communication port.\n"
3944 "-net none use it alone to have zero network devices; if no -net option\n"
3945 " is provided, the default is '-net nic -net user'\n"
3947 "-bt hci,null Dumb bluetooth HCI - doesn't respond to commands\n"
3948 "-bt hci,host[:id]\n"
3949 " Use host's HCI with the given name\n"
3950 "-bt hci[,vlan=n]\n"
3951 " Emulate a standard HCI in virtual scatternet 'n'\n"
3952 "-bt vhci[,vlan=n]\n"
3953 " Add host computer to virtual scatternet 'n' using VHCI\n"
3954 "-bt device:dev[,vlan=n]\n"
3955 " Emulate a bluetooth device 'dev' in scatternet 'n'\n"
3958 "-tftp dir allow tftp access to files in dir [-net user]\n"
3959 "-bootp file advertise file in BOOTP replies\n"
3961 "-smb dir allow SMB access to files in 'dir' [-net user]\n"
3963 "-redir [tcp|udp]:host-port:[guest-host]:guest-port\n"
3964 " redirect TCP or UDP connections from host to guest [-net user]\n"
3967 "Linux boot specific:\n"
3968 "-kernel bzImage use 'bzImage' as kernel image\n"
3969 "-append cmdline use 'cmdline' as kernel command line\n"
3970 "-initrd file use 'file' as initial ram disk\n"
3972 "Debug/Expert options:\n"
3973 "-monitor dev redirect the monitor to char device 'dev'\n"
3974 "-serial dev redirect the serial port to char device 'dev'\n"
3975 "-parallel dev redirect the parallel port to char device 'dev'\n"
3976 "-pidfile file Write PID to 'file'\n"
3977 "-S freeze CPU at startup (use 'c' to start execution)\n"
3978 "-s wait gdb connection to port\n"
3979 "-p port set gdb connection port [default=%s]\n"
3980 "-d item1,... output log to %s (use -d ? for a list of log items)\n"
3981 "-hdachs c,h,s[,t] force hard disk 0 physical geometry and the optional BIOS\n"
3982 " translation (t=none or lba) (usually qemu can guess them)\n"
3983 "-L path set the directory for the BIOS, VGA BIOS and keymaps\n"
3985 "-kernel-kqemu enable KQEMU full virtualization (default is user mode only)\n"
3986 "-no-kqemu disable KQEMU kernel module usage\n"
3989 "-enable-kvm enable KVM full virtualization support\n"
3992 "-no-acpi disable ACPI\n"
3993 "-no-hpet disable HPET\n"
3995 #ifdef CONFIG_CURSES
3996 "-curses use a curses/ncurses interface instead of SDL\n"
3998 "-no-reboot exit instead of rebooting\n"
3999 "-no-shutdown stop before shutdown\n"
4000 "-loadvm [tag|id] start right away with a saved state (loadvm in monitor)\n"
4001 "-vnc display start a VNC server on display\n"
4003 "-daemonize daemonize QEMU after initializing\n"
4005 "-option-rom rom load a file, rom, into the option ROM space\n"
4007 "-prom-env variable=value set OpenBIOS nvram variables\n"
4009 "-clock force the use of the given methods for timer alarm.\n"
4010 " To see what timers are available use -clock ?\n"
4011 "-startdate select initial date of the clock\n"
4012 "-icount [N|auto]\n"
4013 " Enable virtual instruction counter with 2^N clock ticks per instruction\n"
4015 "During emulation, the following keys are useful:\n"
4016 "ctrl-alt-f toggle full screen\n"
4017 "ctrl-alt-n switch to virtual console 'n'\n"
4018 "ctrl-alt toggle mouse and keyboard grab\n"
4020 "When using -nographic, press 'ctrl-a h' to get some help.\n"
4025 DEFAULT_NETWORK_SCRIPT
,
4026 DEFAULT_NETWORK_DOWN_SCRIPT
,
4028 DEFAULT_GDBSTUB_PORT
,
4033 #define HAS_ARG 0x0001
4048 QEMU_OPTION_mtdblock
,
4052 QEMU_OPTION_snapshot
,
4054 QEMU_OPTION_no_fd_bootchk
,
4057 QEMU_OPTION_nographic
,
4058 QEMU_OPTION_portrait
,
4060 QEMU_OPTION_audio_help
,
4061 QEMU_OPTION_soundhw
,
4083 QEMU_OPTION_localtime
,
4087 QEMU_OPTION_monitor
,
4089 QEMU_OPTION_virtiocon
,
4090 QEMU_OPTION_parallel
,
4092 QEMU_OPTION_full_screen
,
4093 QEMU_OPTION_no_frame
,
4094 QEMU_OPTION_alt_grab
,
4095 QEMU_OPTION_no_quit
,
4097 QEMU_OPTION_pidfile
,
4098 QEMU_OPTION_no_kqemu
,
4099 QEMU_OPTION_kernel_kqemu
,
4100 QEMU_OPTION_enable_kvm
,
4101 QEMU_OPTION_win2k_hack
,
4102 QEMU_OPTION_rtc_td_hack
,
4104 QEMU_OPTION_usbdevice
,
4107 QEMU_OPTION_no_acpi
,
4108 QEMU_OPTION_no_hpet
,
4110 QEMU_OPTION_no_reboot
,
4111 QEMU_OPTION_no_shutdown
,
4112 QEMU_OPTION_show_cursor
,
4113 QEMU_OPTION_daemonize
,
4114 QEMU_OPTION_option_rom
,
4115 QEMU_OPTION_semihosting
,
4117 QEMU_OPTION_prom_env
,
4118 QEMU_OPTION_old_param
,
4120 QEMU_OPTION_startdate
,
4121 QEMU_OPTION_tb_size
,
4124 QEMU_OPTION_incoming
,
4127 typedef struct QEMUOption
{
4133 static const QEMUOption qemu_options
[] = {
4134 { "h", 0, QEMU_OPTION_h
},
4135 { "help", 0, QEMU_OPTION_h
},
4137 { "M", HAS_ARG
, QEMU_OPTION_M
},
4138 { "cpu", HAS_ARG
, QEMU_OPTION_cpu
},
4139 { "fda", HAS_ARG
, QEMU_OPTION_fda
},
4140 { "fdb", HAS_ARG
, QEMU_OPTION_fdb
},
4141 { "hda", HAS_ARG
, QEMU_OPTION_hda
},
4142 { "hdb", HAS_ARG
, QEMU_OPTION_hdb
},
4143 { "hdc", HAS_ARG
, QEMU_OPTION_hdc
},
4144 { "hdd", HAS_ARG
, QEMU_OPTION_hdd
},
4145 { "drive", HAS_ARG
, QEMU_OPTION_drive
},
4146 { "cdrom", HAS_ARG
, QEMU_OPTION_cdrom
},
4147 { "mtdblock", HAS_ARG
, QEMU_OPTION_mtdblock
},
4148 { "sd", HAS_ARG
, QEMU_OPTION_sd
},
4149 { "pflash", HAS_ARG
, QEMU_OPTION_pflash
},
4150 { "boot", HAS_ARG
, QEMU_OPTION_boot
},
4151 { "snapshot", 0, QEMU_OPTION_snapshot
},
4153 { "no-fd-bootchk", 0, QEMU_OPTION_no_fd_bootchk
},
4155 { "m", HAS_ARG
, QEMU_OPTION_m
},
4156 { "nographic", 0, QEMU_OPTION_nographic
},
4157 { "portrait", 0, QEMU_OPTION_portrait
},
4158 { "k", HAS_ARG
, QEMU_OPTION_k
},
4160 { "audio-help", 0, QEMU_OPTION_audio_help
},
4161 { "soundhw", HAS_ARG
, QEMU_OPTION_soundhw
},
4164 { "net", HAS_ARG
, QEMU_OPTION_net
},
4166 { "tftp", HAS_ARG
, QEMU_OPTION_tftp
},
4167 { "bootp", HAS_ARG
, QEMU_OPTION_bootp
},
4169 { "smb", HAS_ARG
, QEMU_OPTION_smb
},
4171 { "redir", HAS_ARG
, QEMU_OPTION_redir
},
4173 { "bt", HAS_ARG
, QEMU_OPTION_bt
},
4175 { "kernel", HAS_ARG
, QEMU_OPTION_kernel
},
4176 { "append", HAS_ARG
, QEMU_OPTION_append
},
4177 { "initrd", HAS_ARG
, QEMU_OPTION_initrd
},
4179 { "S", 0, QEMU_OPTION_S
},
4180 { "s", 0, QEMU_OPTION_s
},
4181 { "p", HAS_ARG
, QEMU_OPTION_p
},
4182 { "d", HAS_ARG
, QEMU_OPTION_d
},
4183 { "hdachs", HAS_ARG
, QEMU_OPTION_hdachs
},
4184 { "L", HAS_ARG
, QEMU_OPTION_L
},
4185 { "bios", HAS_ARG
, QEMU_OPTION_bios
},
4187 { "no-kqemu", 0, QEMU_OPTION_no_kqemu
},
4188 { "kernel-kqemu", 0, QEMU_OPTION_kernel_kqemu
},
4191 { "enable-kvm", 0, QEMU_OPTION_enable_kvm
},
4193 #if defined(TARGET_PPC) || defined(TARGET_SPARC)
4194 { "g", 1, QEMU_OPTION_g
},
4196 { "localtime", 0, QEMU_OPTION_localtime
},
4197 { "vga", HAS_ARG
, QEMU_OPTION_vga
},
4198 { "echr", HAS_ARG
, QEMU_OPTION_echr
},
4199 { "monitor", HAS_ARG
, QEMU_OPTION_monitor
},
4200 { "serial", HAS_ARG
, QEMU_OPTION_serial
},
4201 { "virtioconsole", HAS_ARG
, QEMU_OPTION_virtiocon
},
4202 { "parallel", HAS_ARG
, QEMU_OPTION_parallel
},
4203 { "loadvm", HAS_ARG
, QEMU_OPTION_loadvm
},
4204 { "full-screen", 0, QEMU_OPTION_full_screen
},
4206 { "no-frame", 0, QEMU_OPTION_no_frame
},
4207 { "alt-grab", 0, QEMU_OPTION_alt_grab
},
4208 { "no-quit", 0, QEMU_OPTION_no_quit
},
4209 { "sdl", 0, QEMU_OPTION_sdl
},
4211 { "pidfile", HAS_ARG
, QEMU_OPTION_pidfile
},
4212 { "win2k-hack", 0, QEMU_OPTION_win2k_hack
},
4213 { "rtc-td-hack", 0, QEMU_OPTION_rtc_td_hack
},
4214 { "usbdevice", HAS_ARG
, QEMU_OPTION_usbdevice
},
4215 { "smp", HAS_ARG
, QEMU_OPTION_smp
},
4216 { "vnc", HAS_ARG
, QEMU_OPTION_vnc
},
4217 #ifdef CONFIG_CURSES
4218 { "curses", 0, QEMU_OPTION_curses
},
4220 { "uuid", HAS_ARG
, QEMU_OPTION_uuid
},
4222 /* temporary options */
4223 { "usb", 0, QEMU_OPTION_usb
},
4224 { "no-acpi", 0, QEMU_OPTION_no_acpi
},
4225 { "no-hpet", 0, QEMU_OPTION_no_hpet
},
4226 { "no-reboot", 0, QEMU_OPTION_no_reboot
},
4227 { "no-shutdown", 0, QEMU_OPTION_no_shutdown
},
4228 { "show-cursor", 0, QEMU_OPTION_show_cursor
},
4229 { "daemonize", 0, QEMU_OPTION_daemonize
},
4230 { "option-rom", HAS_ARG
, QEMU_OPTION_option_rom
},
4231 #if defined(TARGET_ARM) || defined(TARGET_M68K)
4232 { "semihosting", 0, QEMU_OPTION_semihosting
},
4234 { "name", HAS_ARG
, QEMU_OPTION_name
},
4235 #if defined(TARGET_SPARC) || defined(TARGET_PPC)
4236 { "prom-env", HAS_ARG
, QEMU_OPTION_prom_env
},
4238 #if defined(TARGET_ARM)
4239 { "old-param", 0, QEMU_OPTION_old_param
},
4241 { "clock", HAS_ARG
, QEMU_OPTION_clock
},
4242 { "startdate", HAS_ARG
, QEMU_OPTION_startdate
},
4243 { "tb-size", HAS_ARG
, QEMU_OPTION_tb_size
},
4244 { "icount", HAS_ARG
, QEMU_OPTION_icount
},
4245 { "incoming", HAS_ARG
, QEMU_OPTION_incoming
},
4249 /* password input */
4251 int qemu_key_check(BlockDriverState
*bs
, const char *name
)
4256 if (!bdrv_is_encrypted(bs
))
4259 term_printf("%s is encrypted.\n", name
);
4260 for(i
= 0; i
< 3; i
++) {
4261 monitor_readline("Password: ", 1, password
, sizeof(password
));
4262 if (bdrv_set_key(bs
, password
) == 0)
4264 term_printf("invalid password\n");
4269 static BlockDriverState
*get_bdrv(int index
)
4271 if (index
> nb_drives
)
4273 return drives_table
[index
].bdrv
;
4276 static void read_passwords(void)
4278 BlockDriverState
*bs
;
4281 for(i
= 0; i
< 6; i
++) {
4284 qemu_key_check(bs
, bdrv_get_device_name(bs
));
4289 struct soundhw soundhw
[] = {
4290 #ifdef HAS_AUDIO_CHOICE
4291 #if defined(TARGET_I386) || defined(TARGET_MIPS)
4297 { .init_isa
= pcspk_audio_init
}
4304 "Creative Sound Blaster 16",
4307 { .init_isa
= SB16_init
}
4311 #ifdef CONFIG_CS4231A
4317 { .init_isa
= cs4231a_init
}
4325 "Yamaha YMF262 (OPL3)",
4327 "Yamaha YM3812 (OPL2)",
4331 { .init_isa
= Adlib_init
}
4338 "Gravis Ultrasound GF1",
4341 { .init_isa
= GUS_init
}
4348 "Intel 82801AA AC97 Audio",
4351 { .init_pci
= ac97_init
}
4355 #ifdef CONFIG_ES1370
4358 "ENSONIQ AudioPCI ES1370",
4361 { .init_pci
= es1370_init
}
4365 #endif /* HAS_AUDIO_CHOICE */
4367 { NULL
, NULL
, 0, 0, { NULL
} }
4370 static void select_soundhw (const char *optarg
)
4374 if (*optarg
== '?') {
4377 printf ("Valid sound card names (comma separated):\n");
4378 for (c
= soundhw
; c
->name
; ++c
) {
4379 printf ("%-11s %s\n", c
->name
, c
->descr
);
4381 printf ("\n-soundhw all will enable all of the above\n");
4382 exit (*optarg
!= '?');
4390 if (!strcmp (optarg
, "all")) {
4391 for (c
= soundhw
; c
->name
; ++c
) {
4399 e
= strchr (p
, ',');
4400 l
= !e
? strlen (p
) : (size_t) (e
- p
);
4402 for (c
= soundhw
; c
->name
; ++c
) {
4403 if (!strncmp (c
->name
, p
, l
)) {
4412 "Unknown sound card name (too big to show)\n");
4415 fprintf (stderr
, "Unknown sound card name `%.*s'\n",
4420 p
+= l
+ (e
!= NULL
);
4424 goto show_valid_cards
;
4429 static void select_vgahw (const char *p
)
4433 if (strstart(p
, "std", &opts
)) {
4434 std_vga_enabled
= 1;
4435 cirrus_vga_enabled
= 0;
4437 } else if (strstart(p
, "cirrus", &opts
)) {
4438 cirrus_vga_enabled
= 1;
4439 std_vga_enabled
= 0;
4441 } else if (strstart(p
, "vmware", &opts
)) {
4442 cirrus_vga_enabled
= 0;
4443 std_vga_enabled
= 0;
4445 } else if (strstart(p
, "none", &opts
)) {
4446 cirrus_vga_enabled
= 0;
4447 std_vga_enabled
= 0;
4451 fprintf(stderr
, "Unknown vga type: %s\n", p
);
4455 const char *nextopt
;
4457 if (strstart(opts
, ",retrace=", &nextopt
)) {
4459 if (strstart(opts
, "dumb", &nextopt
))
4460 vga_retrace_method
= VGA_RETRACE_DUMB
;
4461 else if (strstart(opts
, "precise", &nextopt
))
4462 vga_retrace_method
= VGA_RETRACE_PRECISE
;
4463 else goto invalid_vga
;
4464 } else goto invalid_vga
;
4470 static BOOL WINAPI
qemu_ctrl_handler(DWORD type
)
4472 exit(STATUS_CONTROL_C_EXIT
);
4477 static int qemu_uuid_parse(const char *str
, uint8_t *uuid
)
4481 if(strlen(str
) != 36)
4484 ret
= sscanf(str
, UUID_FMT
, &uuid
[0], &uuid
[1], &uuid
[2], &uuid
[3],
4485 &uuid
[4], &uuid
[5], &uuid
[6], &uuid
[7], &uuid
[8], &uuid
[9],
4486 &uuid
[10], &uuid
[11], &uuid
[12], &uuid
[13], &uuid
[14], &uuid
[15]);
4494 #define MAX_NET_CLIENTS 32
4498 static void termsig_handler(int signal
)
4500 qemu_system_shutdown_request();
4503 static void termsig_setup(void)
4505 struct sigaction act
;
4507 memset(&act
, 0, sizeof(act
));
4508 act
.sa_handler
= termsig_handler
;
4509 sigaction(SIGINT
, &act
, NULL
);
4510 sigaction(SIGHUP
, &act
, NULL
);
4511 sigaction(SIGTERM
, &act
, NULL
);
4516 int main(int argc
, char **argv
, char **envp
)
4518 #ifdef CONFIG_GDBSTUB
4520 const char *gdbstub_port
;
4522 uint32_t boot_devices_bitmap
= 0;
4524 int snapshot
, linux_boot
, net_boot
;
4525 const char *initrd_filename
;
4526 const char *kernel_filename
, *kernel_cmdline
;
4527 const char *boot_devices
= "";
4529 DisplayChangeListener
*dcl
;
4530 int cyls
, heads
, secs
, translation
;
4531 const char *net_clients
[MAX_NET_CLIENTS
];
4533 const char *bt_opts
[MAX_BT_CMDLINE
];
4537 const char *r
, *optarg
;
4538 CharDriverState
*monitor_hd
= NULL
;
4539 const char *monitor_device
;
4540 const char *serial_devices
[MAX_SERIAL_PORTS
];
4541 int serial_device_index
;
4542 const char *parallel_devices
[MAX_PARALLEL_PORTS
];
4543 int parallel_device_index
;
4544 const char *virtio_consoles
[MAX_VIRTIO_CONSOLES
];
4545 int virtio_console_index
;
4546 const char *loadvm
= NULL
;
4547 QEMUMachine
*machine
;
4548 const char *cpu_model
;
4549 const char *usb_devices
[MAX_USB_CMDLINE
];
4550 int usb_devices_index
;
4553 const char *pid_file
= NULL
;
4555 const char *incoming
= NULL
;
4557 qemu_cache_utils_init(envp
);
4559 LIST_INIT (&vm_change_state_head
);
4562 struct sigaction act
;
4563 sigfillset(&act
.sa_mask
);
4565 act
.sa_handler
= SIG_IGN
;
4566 sigaction(SIGPIPE
, &act
, NULL
);
4569 SetConsoleCtrlHandler(qemu_ctrl_handler
, TRUE
);
4570 /* Note: cpu_interrupt() is currently not SMP safe, so we force
4571 QEMU to run on a single CPU */
4576 h
= GetCurrentProcess();
4577 if (GetProcessAffinityMask(h
, &mask
, &smask
)) {
4578 for(i
= 0; i
< 32; i
++) {
4579 if (mask
& (1 << i
))
4584 SetProcessAffinityMask(h
, mask
);
4590 register_machines();
4591 machine
= first_machine
;
4593 initrd_filename
= NULL
;
4595 vga_ram_size
= VGA_RAM_SIZE
;
4596 #ifdef CONFIG_GDBSTUB
4598 gdbstub_port
= DEFAULT_GDBSTUB_PORT
;
4603 kernel_filename
= NULL
;
4604 kernel_cmdline
= "";
4605 cyls
= heads
= secs
= 0;
4606 translation
= BIOS_ATA_TRANSLATION_AUTO
;
4607 monitor_device
= "vc";
4609 serial_devices
[0] = "vc:80Cx24C";
4610 for(i
= 1; i
< MAX_SERIAL_PORTS
; i
++)
4611 serial_devices
[i
] = NULL
;
4612 serial_device_index
= 0;
4614 parallel_devices
[0] = "vc:640x480";
4615 for(i
= 1; i
< MAX_PARALLEL_PORTS
; i
++)
4616 parallel_devices
[i
] = NULL
;
4617 parallel_device_index
= 0;
4619 virtio_consoles
[0] = "vc:80Cx24C";
4620 for(i
= 1; i
< MAX_VIRTIO_CONSOLES
; i
++)
4621 virtio_consoles
[i
] = NULL
;
4622 virtio_console_index
= 0;
4624 usb_devices_index
= 0;
4643 hda_index
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
4645 const QEMUOption
*popt
;
4648 /* Treat --foo the same as -foo. */
4651 popt
= qemu_options
;
4654 fprintf(stderr
, "%s: invalid option -- '%s'\n",
4658 if (!strcmp(popt
->name
, r
+ 1))
4662 if (popt
->flags
& HAS_ARG
) {
4663 if (optind
>= argc
) {
4664 fprintf(stderr
, "%s: option '%s' requires an argument\n",
4668 optarg
= argv
[optind
++];
4673 switch(popt
->index
) {
4675 machine
= find_machine(optarg
);
4678 printf("Supported machines are:\n");
4679 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
4680 printf("%-10s %s%s\n",
4682 m
== first_machine
? " (default)" : "");
4684 exit(*optarg
!= '?');
4687 case QEMU_OPTION_cpu
:
4688 /* hw initialization will check this */
4689 if (*optarg
== '?') {
4690 /* XXX: implement xxx_cpu_list for targets that still miss it */
4691 #if defined(cpu_list)
4692 cpu_list(stdout
, &fprintf
);
4699 case QEMU_OPTION_initrd
:
4700 initrd_filename
= optarg
;
4702 case QEMU_OPTION_hda
:
4704 hda_index
= drive_add(optarg
, HD_ALIAS
, 0);
4706 hda_index
= drive_add(optarg
, HD_ALIAS
4707 ",cyls=%d,heads=%d,secs=%d%s",
4708 0, cyls
, heads
, secs
,
4709 translation
== BIOS_ATA_TRANSLATION_LBA
?
4711 translation
== BIOS_ATA_TRANSLATION_NONE
?
4712 ",trans=none" : "");
4714 case QEMU_OPTION_hdb
:
4715 case QEMU_OPTION_hdc
:
4716 case QEMU_OPTION_hdd
:
4717 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
4719 case QEMU_OPTION_drive
:
4720 drive_add(NULL
, "%s", optarg
);
4722 case QEMU_OPTION_mtdblock
:
4723 drive_add(optarg
, MTD_ALIAS
);
4725 case QEMU_OPTION_sd
:
4726 drive_add(optarg
, SD_ALIAS
);
4728 case QEMU_OPTION_pflash
:
4729 drive_add(optarg
, PFLASH_ALIAS
);
4731 case QEMU_OPTION_snapshot
:
4734 case QEMU_OPTION_hdachs
:
4738 cyls
= strtol(p
, (char **)&p
, 0);
4739 if (cyls
< 1 || cyls
> 16383)
4744 heads
= strtol(p
, (char **)&p
, 0);
4745 if (heads
< 1 || heads
> 16)
4750 secs
= strtol(p
, (char **)&p
, 0);
4751 if (secs
< 1 || secs
> 63)
4755 if (!strcmp(p
, "none"))
4756 translation
= BIOS_ATA_TRANSLATION_NONE
;
4757 else if (!strcmp(p
, "lba"))
4758 translation
= BIOS_ATA_TRANSLATION_LBA
;
4759 else if (!strcmp(p
, "auto"))
4760 translation
= BIOS_ATA_TRANSLATION_AUTO
;
4763 } else if (*p
!= '\0') {
4765 fprintf(stderr
, "qemu: invalid physical CHS format\n");
4768 if (hda_index
!= -1)
4769 snprintf(drives_opt
[hda_index
].opt
,
4770 sizeof(drives_opt
[hda_index
].opt
),
4771 HD_ALIAS
",cyls=%d,heads=%d,secs=%d%s",
4772 0, cyls
, heads
, secs
,
4773 translation
== BIOS_ATA_TRANSLATION_LBA
?
4775 translation
== BIOS_ATA_TRANSLATION_NONE
?
4776 ",trans=none" : "");
4779 case QEMU_OPTION_nographic
:
4782 #ifdef CONFIG_CURSES
4783 case QEMU_OPTION_curses
:
4787 case QEMU_OPTION_portrait
:
4790 case QEMU_OPTION_kernel
:
4791 kernel_filename
= optarg
;
4793 case QEMU_OPTION_append
:
4794 kernel_cmdline
= optarg
;
4796 case QEMU_OPTION_cdrom
:
4797 drive_add(optarg
, CDROM_ALIAS
);
4799 case QEMU_OPTION_boot
:
4800 boot_devices
= optarg
;
4801 /* We just do some generic consistency checks */
4803 /* Could easily be extended to 64 devices if needed */
4806 boot_devices_bitmap
= 0;
4807 for (p
= boot_devices
; *p
!= '\0'; p
++) {
4808 /* Allowed boot devices are:
4809 * a b : floppy disk drives
4810 * c ... f : IDE disk drives
4811 * g ... m : machine implementation dependant drives
4812 * n ... p : network devices
4813 * It's up to each machine implementation to check
4814 * if the given boot devices match the actual hardware
4815 * implementation and firmware features.
4817 if (*p
< 'a' || *p
> 'q') {
4818 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
4821 if (boot_devices_bitmap
& (1 << (*p
- 'a'))) {
4823 "Boot device '%c' was given twice\n",*p
);
4826 boot_devices_bitmap
|= 1 << (*p
- 'a');
4830 case QEMU_OPTION_fda
:
4831 case QEMU_OPTION_fdb
:
4832 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
4835 case QEMU_OPTION_no_fd_bootchk
:
4839 case QEMU_OPTION_net
:
4840 if (nb_net_clients
>= MAX_NET_CLIENTS
) {
4841 fprintf(stderr
, "qemu: too many network clients\n");
4844 net_clients
[nb_net_clients
] = optarg
;
4848 case QEMU_OPTION_tftp
:
4849 tftp_prefix
= optarg
;
4851 case QEMU_OPTION_bootp
:
4852 bootp_filename
= optarg
;
4855 case QEMU_OPTION_smb
:
4856 net_slirp_smb(optarg
);
4859 case QEMU_OPTION_redir
:
4860 net_slirp_redir(optarg
);
4863 case QEMU_OPTION_bt
:
4864 if (nb_bt_opts
>= MAX_BT_CMDLINE
) {
4865 fprintf(stderr
, "qemu: too many bluetooth options\n");
4868 bt_opts
[nb_bt_opts
++] = optarg
;
4871 case QEMU_OPTION_audio_help
:
4875 case QEMU_OPTION_soundhw
:
4876 select_soundhw (optarg
);
4882 case QEMU_OPTION_m
: {
4886 value
= strtoul(optarg
, &ptr
, 10);
4888 case 0: case 'M': case 'm':
4895 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
4899 /* On 32-bit hosts, QEMU is limited by virtual address space */
4900 if (value
> (2047 << 20)
4902 && HOST_LONG_BITS
== 32
4905 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
4908 if (value
!= (uint64_t)(ram_addr_t
)value
) {
4909 fprintf(stderr
, "qemu: ram size too large\n");
4918 const CPULogItem
*item
;
4920 mask
= cpu_str_to_log_mask(optarg
);
4922 printf("Log items (comma separated):\n");
4923 for(item
= cpu_log_items
; item
->mask
!= 0; item
++) {
4924 printf("%-10s %s\n", item
->name
, item
->help
);
4931 #ifdef CONFIG_GDBSTUB
4936 gdbstub_port
= optarg
;
4942 case QEMU_OPTION_bios
:
4949 keyboard_layout
= optarg
;
4951 case QEMU_OPTION_localtime
:
4954 case QEMU_OPTION_vga
:
4955 select_vgahw (optarg
);
4962 w
= strtol(p
, (char **)&p
, 10);
4965 fprintf(stderr
, "qemu: invalid resolution or depth\n");
4971 h
= strtol(p
, (char **)&p
, 10);
4976 depth
= strtol(p
, (char **)&p
, 10);
4977 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
4978 depth
!= 24 && depth
!= 32)
4980 } else if (*p
== '\0') {
4981 depth
= graphic_depth
;
4988 graphic_depth
= depth
;
4991 case QEMU_OPTION_echr
:
4994 term_escape_char
= strtol(optarg
, &r
, 0);
4996 printf("Bad argument to echr\n");
4999 case QEMU_OPTION_monitor
:
5000 monitor_device
= optarg
;
5002 case QEMU_OPTION_serial
:
5003 if (serial_device_index
>= MAX_SERIAL_PORTS
) {
5004 fprintf(stderr
, "qemu: too many serial ports\n");
5007 serial_devices
[serial_device_index
] = optarg
;
5008 serial_device_index
++;
5010 case QEMU_OPTION_virtiocon
:
5011 if (virtio_console_index
>= MAX_VIRTIO_CONSOLES
) {
5012 fprintf(stderr
, "qemu: too many virtio consoles\n");
5015 virtio_consoles
[virtio_console_index
] = optarg
;
5016 virtio_console_index
++;
5018 case QEMU_OPTION_parallel
:
5019 if (parallel_device_index
>= MAX_PARALLEL_PORTS
) {
5020 fprintf(stderr
, "qemu: too many parallel ports\n");
5023 parallel_devices
[parallel_device_index
] = optarg
;
5024 parallel_device_index
++;
5026 case QEMU_OPTION_loadvm
:
5029 case QEMU_OPTION_full_screen
:
5033 case QEMU_OPTION_no_frame
:
5036 case QEMU_OPTION_alt_grab
:
5039 case QEMU_OPTION_no_quit
:
5042 case QEMU_OPTION_sdl
:
5046 case QEMU_OPTION_pidfile
:
5050 case QEMU_OPTION_win2k_hack
:
5051 win2k_install_hack
= 1;
5053 case QEMU_OPTION_rtc_td_hack
:
5058 case QEMU_OPTION_no_kqemu
:
5061 case QEMU_OPTION_kernel_kqemu
:
5066 case QEMU_OPTION_enable_kvm
:
5073 case QEMU_OPTION_usb
:
5076 case QEMU_OPTION_usbdevice
:
5078 if (usb_devices_index
>= MAX_USB_CMDLINE
) {
5079 fprintf(stderr
, "Too many USB devices\n");
5082 usb_devices
[usb_devices_index
] = optarg
;
5083 usb_devices_index
++;
5085 case QEMU_OPTION_smp
:
5086 smp_cpus
= atoi(optarg
);
5088 fprintf(stderr
, "Invalid number of CPUs\n");
5092 case QEMU_OPTION_vnc
:
5093 vnc_display
= optarg
;
5095 case QEMU_OPTION_no_acpi
:
5098 case QEMU_OPTION_no_hpet
:
5101 case QEMU_OPTION_no_reboot
:
5104 case QEMU_OPTION_no_shutdown
:
5107 case QEMU_OPTION_show_cursor
:
5110 case QEMU_OPTION_uuid
:
5111 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
5112 fprintf(stderr
, "Fail to parse UUID string."
5113 " Wrong format.\n");
5117 case QEMU_OPTION_daemonize
:
5120 case QEMU_OPTION_option_rom
:
5121 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
5122 fprintf(stderr
, "Too many option ROMs\n");
5125 option_rom
[nb_option_roms
] = optarg
;
5128 case QEMU_OPTION_semihosting
:
5129 semihosting_enabled
= 1;
5131 case QEMU_OPTION_name
:
5134 #if defined(TARGET_SPARC) || defined(TARGET_PPC)
5135 case QEMU_OPTION_prom_env
:
5136 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
5137 fprintf(stderr
, "Too many prom variables\n");
5140 prom_envs
[nb_prom_envs
] = optarg
;
5145 case QEMU_OPTION_old_param
:
5149 case QEMU_OPTION_clock
:
5150 configure_alarms(optarg
);
5152 case QEMU_OPTION_startdate
:
5155 time_t rtc_start_date
;
5156 if (!strcmp(optarg
, "now")) {
5157 rtc_date_offset
= -1;
5159 if (sscanf(optarg
, "%d-%d-%dT%d:%d:%d",
5167 } else if (sscanf(optarg
, "%d-%d-%d",
5170 &tm
.tm_mday
) == 3) {
5179 rtc_start_date
= mktimegm(&tm
);
5180 if (rtc_start_date
== -1) {
5182 fprintf(stderr
, "Invalid date format. Valid format are:\n"
5183 "'now' or '2006-06-17T16:01:21' or '2006-06-17'\n");
5186 rtc_date_offset
= time(NULL
) - rtc_start_date
;
5190 case QEMU_OPTION_tb_size
:
5191 tb_size
= strtol(optarg
, NULL
, 0);
5195 case QEMU_OPTION_icount
:
5197 if (strcmp(optarg
, "auto") == 0) {
5198 icount_time_shift
= -1;
5200 icount_time_shift
= strtol(optarg
, NULL
, 0);
5203 case QEMU_OPTION_incoming
:
5210 #if defined(CONFIG_KVM) && defined(USE_KQEMU)
5211 if (kvm_allowed
&& kqemu_allowed
) {
5213 "You can not enable both KVM and kqemu at the same time\n");
5218 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
5219 if (smp_cpus
> machine
->max_cpus
) {
5220 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
5221 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
5227 if (serial_device_index
== 0)
5228 serial_devices
[0] = "stdio";
5229 if (parallel_device_index
== 0)
5230 parallel_devices
[0] = "null";
5231 if (strncmp(monitor_device
, "vc", 2) == 0)
5232 monitor_device
= "stdio";
5233 if (virtio_console_index
== 0)
5234 virtio_consoles
[0] = "null";
5241 if (pipe(fds
) == -1)
5252 len
= read(fds
[0], &status
, 1);
5253 if (len
== -1 && (errno
== EINTR
))
5258 else if (status
== 1) {
5259 fprintf(stderr
, "Could not acquire pidfile\n");
5276 signal(SIGTSTP
, SIG_IGN
);
5277 signal(SIGTTOU
, SIG_IGN
);
5278 signal(SIGTTIN
, SIG_IGN
);
5282 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
5285 write(fds
[1], &status
, 1);
5287 fprintf(stderr
, "Could not acquire pid file\n");
5295 linux_boot
= (kernel_filename
!= NULL
);
5296 net_boot
= (boot_devices_bitmap
>> ('n' - 'a')) & 0xF;
5298 if (!linux_boot
&& net_boot
== 0 &&
5299 !machine
->nodisk_ok
&& nb_drives_opt
== 0)
5302 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
5303 fprintf(stderr
, "-append only allowed with -kernel option\n");
5307 if (!linux_boot
&& initrd_filename
!= NULL
) {
5308 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
5312 /* boot to floppy or the default cd if no hard disk defined yet */
5313 if (!boot_devices
[0]) {
5314 boot_devices
= "cad";
5316 setvbuf(stdout
, NULL
, _IOLBF
, 0);
5319 if (init_timer_alarm() < 0) {
5320 fprintf(stderr
, "could not initialize alarm timer\n");
5323 if (use_icount
&& icount_time_shift
< 0) {
5325 /* 125MIPS seems a reasonable initial guess at the guest speed.
5326 It will be corrected fairly quickly anyway. */
5327 icount_time_shift
= 3;
5328 init_icount_adjust();
5335 /* init network clients */
5336 if (nb_net_clients
== 0) {
5337 /* if no clients, we use a default config */
5338 net_clients
[nb_net_clients
++] = "nic";
5340 net_clients
[nb_net_clients
++] = "user";
5344 for(i
= 0;i
< nb_net_clients
; i
++) {
5345 if (net_client_parse(net_clients
[i
]) < 0)
5351 /* XXX: this should be moved in the PC machine instantiation code */
5352 if (net_boot
!= 0) {
5354 for (i
= 0; i
< nb_nics
&& i
< 4; i
++) {
5355 const char *model
= nd_table
[i
].model
;
5357 if (net_boot
& (1 << i
)) {
5360 snprintf(buf
, sizeof(buf
), "%s/pxe-%s.bin", bios_dir
, model
);
5361 if (get_image_size(buf
) > 0) {
5362 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
5363 fprintf(stderr
, "Too many option ROMs\n");
5366 option_rom
[nb_option_roms
] = strdup(buf
);
5373 fprintf(stderr
, "No valid PXE rom found for network device\n");
5379 /* init the bluetooth world */
5380 for (i
= 0; i
< nb_bt_opts
; i
++)
5381 if (bt_parse(bt_opts
[i
]))
5384 /* init the memory */
5385 phys_ram_size
= machine
->ram_require
& ~RAMSIZE_FIXED
;
5387 if (machine
->ram_require
& RAMSIZE_FIXED
) {
5389 if (ram_size
< phys_ram_size
) {
5390 fprintf(stderr
, "Machine `%s' requires %llu bytes of memory\n",
5391 machine
->name
, (unsigned long long) phys_ram_size
);
5395 phys_ram_size
= ram_size
;
5397 ram_size
= phys_ram_size
;
5400 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
5402 phys_ram_size
+= ram_size
;
5405 phys_ram_base
= qemu_vmalloc(phys_ram_size
);
5406 if (!phys_ram_base
) {
5407 fprintf(stderr
, "Could not allocate physical memory\n");
5411 /* init the dynamic translator */
5412 cpu_exec_init_all(tb_size
* 1024 * 1024);
5416 /* we always create the cdrom drive, even if no disk is there */
5418 if (nb_drives_opt
< MAX_DRIVES
)
5419 drive_add(NULL
, CDROM_ALIAS
);
5421 /* we always create at least one floppy */
5423 if (nb_drives_opt
< MAX_DRIVES
)
5424 drive_add(NULL
, FD_ALIAS
, 0);
5426 /* we always create one sd slot, even if no card is in it */
5428 if (nb_drives_opt
< MAX_DRIVES
)
5429 drive_add(NULL
, SD_ALIAS
);
5431 /* open the virtual block devices */
5433 for(i
= 0; i
< nb_drives_opt
; i
++)
5434 if (drive_init(&drives_opt
[i
], snapshot
, machine
) == -1)
5437 register_savevm("timer", 0, 2, timer_save
, timer_load
, NULL
);
5438 register_savevm_live("ram", 0, 3, ram_save_live
, NULL
, ram_load
, NULL
);
5441 /* must be after terminal init, SDL library changes signal handlers */
5445 /* Maintain compatibility with multiple stdio monitors */
5446 if (!strcmp(monitor_device
,"stdio")) {
5447 for (i
= 0; i
< MAX_SERIAL_PORTS
; i
++) {
5448 const char *devname
= serial_devices
[i
];
5449 if (devname
&& !strcmp(devname
,"mon:stdio")) {
5450 monitor_device
= NULL
;
5452 } else if (devname
&& !strcmp(devname
,"stdio")) {
5453 monitor_device
= NULL
;
5454 serial_devices
[i
] = "mon:stdio";
5460 if (kvm_enabled()) {
5463 ret
= kvm_init(smp_cpus
);
5465 fprintf(stderr
, "failed to initialize KVM\n");
5470 if (monitor_device
) {
5471 monitor_hd
= qemu_chr_open("monitor", monitor_device
, NULL
);
5473 fprintf(stderr
, "qemu: could not open monitor device '%s'\n", monitor_device
);
5478 for(i
= 0; i
< MAX_SERIAL_PORTS
; i
++) {
5479 const char *devname
= serial_devices
[i
];
5480 if (devname
&& strcmp(devname
, "none")) {
5482 snprintf(label
, sizeof(label
), "serial%d", i
);
5483 serial_hds
[i
] = qemu_chr_open(label
, devname
, NULL
);
5484 if (!serial_hds
[i
]) {
5485 fprintf(stderr
, "qemu: could not open serial device '%s'\n",
5492 for(i
= 0; i
< MAX_PARALLEL_PORTS
; i
++) {
5493 const char *devname
= parallel_devices
[i
];
5494 if (devname
&& strcmp(devname
, "none")) {
5496 snprintf(label
, sizeof(label
), "parallel%d", i
);
5497 parallel_hds
[i
] = qemu_chr_open(label
, devname
, NULL
);
5498 if (!parallel_hds
[i
]) {
5499 fprintf(stderr
, "qemu: could not open parallel device '%s'\n",
5506 for(i
= 0; i
< MAX_VIRTIO_CONSOLES
; i
++) {
5507 const char *devname
= virtio_consoles
[i
];
5508 if (devname
&& strcmp(devname
, "none")) {
5510 snprintf(label
, sizeof(label
), "virtcon%d", i
);
5511 virtcon_hds
[i
] = qemu_chr_open(label
, devname
, NULL
);
5512 if (!virtcon_hds
[i
]) {
5513 fprintf(stderr
, "qemu: could not open virtio console '%s'\n",
5520 machine
->init(ram_size
, vga_ram_size
, boot_devices
,
5521 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
5523 /* Set KVM's vcpu state to qemu's initial CPUState. */
5524 if (kvm_enabled()) {
5527 ret
= kvm_sync_vcpus();
5529 fprintf(stderr
, "failed to initialize vcpus\n");
5534 /* init USB devices */
5536 for(i
= 0; i
< usb_devices_index
; i
++) {
5537 if (usb_device_add(usb_devices
[i
]) < 0) {
5538 fprintf(stderr
, "Warning: could not add USB device %s\n",
5545 dumb_display_init();
5546 /* just use the first displaystate for the moment */
5551 fprintf(stderr
, "fatal: -nographic can't be used with -curses\n");
5555 #if defined(CONFIG_CURSES)
5557 /* At the moment curses cannot be used with other displays */
5558 curses_display_init(ds
, full_screen
);
5562 if (vnc_display
!= NULL
) {
5563 vnc_display_init(ds
);
5564 if (vnc_display_open(ds
, vnc_display
) < 0)
5567 #if defined(CONFIG_SDL)
5568 if (sdl
|| !vnc_display
)
5569 sdl_display_init(ds
, full_screen
, no_frame
);
5570 #elif defined(CONFIG_COCOA)
5571 if (sdl
|| !vnc_display
)
5572 cocoa_display_init(ds
, full_screen
);
5578 dcl
= ds
->listeners
;
5579 while (dcl
!= NULL
) {
5580 if (dcl
->dpy_refresh
!= NULL
) {
5581 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
5582 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
5587 if (nographic
|| (vnc_display
&& !sdl
)) {
5588 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
5589 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
5592 text_consoles_set_display(display_state
);
5594 if (monitor_device
&& monitor_hd
)
5595 monitor_init(monitor_hd
, !nographic
);
5597 for(i
= 0; i
< MAX_SERIAL_PORTS
; i
++) {
5598 const char *devname
= serial_devices
[i
];
5599 if (devname
&& strcmp(devname
, "none")) {
5601 snprintf(label
, sizeof(label
), "serial%d", i
);
5602 if (strstart(devname
, "vc", 0))
5603 qemu_chr_printf(serial_hds
[i
], "serial%d console\r\n", i
);
5607 for(i
= 0; i
< MAX_PARALLEL_PORTS
; i
++) {
5608 const char *devname
= parallel_devices
[i
];
5609 if (devname
&& strcmp(devname
, "none")) {
5611 snprintf(label
, sizeof(label
), "parallel%d", i
);
5612 if (strstart(devname
, "vc", 0))
5613 qemu_chr_printf(parallel_hds
[i
], "parallel%d console\r\n", i
);
5617 for(i
= 0; i
< MAX_VIRTIO_CONSOLES
; i
++) {
5618 const char *devname
= virtio_consoles
[i
];
5619 if (virtcon_hds
[i
] && devname
) {
5621 snprintf(label
, sizeof(label
), "virtcon%d", i
);
5622 if (strstart(devname
, "vc", 0))
5623 qemu_chr_printf(virtcon_hds
[i
], "virtio console%d\r\n", i
);
5627 #ifdef CONFIG_GDBSTUB
5629 /* XXX: use standard host:port notation and modify options
5631 if (gdbserver_start(gdbstub_port
) < 0) {
5632 fprintf(stderr
, "qemu: could not open gdbstub device on port '%s'\n",
5643 autostart
= 0; /* fixme how to deal with -daemonize */
5644 qemu_start_incoming_migration(incoming
);
5648 /* XXX: simplify init */
5661 len
= write(fds
[1], &status
, 1);
5662 if (len
== -1 && (errno
== EINTR
))
5669 TFR(fd
= open("/dev/null", O_RDWR
));