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)
165 #define DEFAULT_RAM_SIZE 144
167 #define DEFAULT_RAM_SIZE 128
170 /* Max number of USB devices that can be specified on the commandline. */
171 #define MAX_USB_CMDLINE 8
173 /* Max number of bluetooth switches on the commandline. */
174 #define MAX_BT_CMDLINE 10
176 /* XXX: use a two level table to limit memory usage */
177 #define MAX_IOPORTS 65536
179 const char *bios_dir
= CONFIG_QEMU_SHAREDIR
;
180 const char *bios_name
= NULL
;
181 static void *ioport_opaque
[MAX_IOPORTS
];
182 static IOPortReadFunc
*ioport_read_table
[3][MAX_IOPORTS
];
183 static IOPortWriteFunc
*ioport_write_table
[3][MAX_IOPORTS
];
184 /* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available
185 to store the VM snapshots */
186 DriveInfo drives_table
[MAX_DRIVES
+1];
188 static int vga_ram_size
;
189 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
190 static DisplayState
*display_state
;
194 const char* keyboard_layout
= NULL
;
195 int64_t ticks_per_sec
;
198 NICInfo nd_table
[MAX_NICS
];
200 static int rtc_utc
= 1;
201 static int rtc_date_offset
= -1; /* -1 means no change */
202 int cirrus_vga_enabled
= 1;
203 int std_vga_enabled
= 0;
204 int vmsvga_enabled
= 0;
206 int graphic_width
= 1024;
207 int graphic_height
= 768;
208 int graphic_depth
= 8;
210 int graphic_width
= 800;
211 int graphic_height
= 600;
212 int graphic_depth
= 15;
214 static int full_screen
= 0;
216 static int no_frame
= 0;
219 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
220 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
221 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
223 int win2k_install_hack
= 0;
228 const char *vnc_display
;
229 int acpi_enabled
= 1;
235 int graphic_rotate
= 0;
237 const char *option_rom
[MAX_OPTION_ROMS
];
239 int semihosting_enabled
= 0;
243 const char *qemu_name
;
245 #if defined(TARGET_SPARC) || defined(TARGET_PPC)
246 unsigned int nb_prom_envs
= 0;
247 const char *prom_envs
[MAX_PROM_ENVS
];
249 static int nb_drives_opt
;
250 static struct drive_opt
{
253 } drives_opt
[MAX_DRIVES
];
255 static CPUState
*cur_cpu
;
256 static CPUState
*next_cpu
;
257 static int event_pending
= 1;
258 /* Conversion factor from emulated instructions to virtual clock ticks. */
259 static int icount_time_shift
;
260 /* Arbitrarily pick 1MIPS as the minimum allowable speed. */
261 #define MAX_ICOUNT_SHIFT 10
262 /* Compensate for varying guest execution speed. */
263 static int64_t qemu_icount_bias
;
264 static QEMUTimer
*icount_rt_timer
;
265 static QEMUTimer
*icount_vm_timer
;
266 static QEMUTimer
*nographic_timer
;
268 uint8_t qemu_uuid
[16];
270 /***********************************************************/
271 /* x86 ISA bus support */
273 target_phys_addr_t isa_mem_base
= 0;
276 static IOPortReadFunc default_ioport_readb
, default_ioport_readw
, default_ioport_readl
;
277 static IOPortWriteFunc default_ioport_writeb
, default_ioport_writew
, default_ioport_writel
;
279 static uint32_t ioport_read(int index
, uint32_t address
)
281 static IOPortReadFunc
*default_func
[3] = {
282 default_ioport_readb
,
283 default_ioport_readw
,
286 IOPortReadFunc
*func
= ioport_read_table
[index
][address
];
288 func
= default_func
[index
];
289 return func(ioport_opaque
[address
], address
);
292 static void ioport_write(int index
, uint32_t address
, uint32_t data
)
294 static IOPortWriteFunc
*default_func
[3] = {
295 default_ioport_writeb
,
296 default_ioport_writew
,
297 default_ioport_writel
299 IOPortWriteFunc
*func
= ioport_write_table
[index
][address
];
301 func
= default_func
[index
];
302 func(ioport_opaque
[address
], address
, data
);
305 static uint32_t default_ioport_readb(void *opaque
, uint32_t address
)
307 #ifdef DEBUG_UNUSED_IOPORT
308 fprintf(stderr
, "unused inb: port=0x%04x\n", address
);
313 static void default_ioport_writeb(void *opaque
, uint32_t address
, uint32_t data
)
315 #ifdef DEBUG_UNUSED_IOPORT
316 fprintf(stderr
, "unused outb: port=0x%04x data=0x%02x\n", address
, data
);
320 /* default is to make two byte accesses */
321 static uint32_t default_ioport_readw(void *opaque
, uint32_t address
)
324 data
= ioport_read(0, address
);
325 address
= (address
+ 1) & (MAX_IOPORTS
- 1);
326 data
|= ioport_read(0, address
) << 8;
330 static void default_ioport_writew(void *opaque
, uint32_t address
, uint32_t data
)
332 ioport_write(0, address
, data
& 0xff);
333 address
= (address
+ 1) & (MAX_IOPORTS
- 1);
334 ioport_write(0, address
, (data
>> 8) & 0xff);
337 static uint32_t default_ioport_readl(void *opaque
, uint32_t address
)
339 #ifdef DEBUG_UNUSED_IOPORT
340 fprintf(stderr
, "unused inl: port=0x%04x\n", address
);
345 static void default_ioport_writel(void *opaque
, uint32_t address
, uint32_t data
)
347 #ifdef DEBUG_UNUSED_IOPORT
348 fprintf(stderr
, "unused outl: port=0x%04x data=0x%02x\n", address
, data
);
352 /* size is the word size in byte */
353 int register_ioport_read(int start
, int length
, int size
,
354 IOPortReadFunc
*func
, void *opaque
)
360 } else if (size
== 2) {
362 } else if (size
== 4) {
365 hw_error("register_ioport_read: invalid size");
368 for(i
= start
; i
< start
+ length
; i
+= size
) {
369 ioport_read_table
[bsize
][i
] = func
;
370 if (ioport_opaque
[i
] != NULL
&& ioport_opaque
[i
] != opaque
)
371 hw_error("register_ioport_read: invalid opaque");
372 ioport_opaque
[i
] = opaque
;
377 /* size is the word size in byte */
378 int register_ioport_write(int start
, int length
, int size
,
379 IOPortWriteFunc
*func
, void *opaque
)
385 } else if (size
== 2) {
387 } else if (size
== 4) {
390 hw_error("register_ioport_write: invalid size");
393 for(i
= start
; i
< start
+ length
; i
+= size
) {
394 ioport_write_table
[bsize
][i
] = func
;
395 if (ioport_opaque
[i
] != NULL
&& ioport_opaque
[i
] != opaque
)
396 hw_error("register_ioport_write: invalid opaque");
397 ioport_opaque
[i
] = opaque
;
402 void isa_unassign_ioport(int start
, int length
)
406 for(i
= start
; i
< start
+ length
; i
++) {
407 ioport_read_table
[0][i
] = default_ioport_readb
;
408 ioport_read_table
[1][i
] = default_ioport_readw
;
409 ioport_read_table
[2][i
] = default_ioport_readl
;
411 ioport_write_table
[0][i
] = default_ioport_writeb
;
412 ioport_write_table
[1][i
] = default_ioport_writew
;
413 ioport_write_table
[2][i
] = default_ioport_writel
;
417 /***********************************************************/
419 void cpu_outb(CPUState
*env
, int addr
, int val
)
421 LOG_IOPORT("outb: %04x %02x\n", addr
, val
);
422 ioport_write(0, addr
, val
);
425 env
->last_io_time
= cpu_get_time_fast();
429 void cpu_outw(CPUState
*env
, int addr
, int val
)
431 LOG_IOPORT("outw: %04x %04x\n", addr
, val
);
432 ioport_write(1, addr
, val
);
435 env
->last_io_time
= cpu_get_time_fast();
439 void cpu_outl(CPUState
*env
, int addr
, int val
)
441 LOG_IOPORT("outl: %04x %08x\n", addr
, val
);
442 ioport_write(2, addr
, val
);
445 env
->last_io_time
= cpu_get_time_fast();
449 int cpu_inb(CPUState
*env
, int addr
)
452 val
= ioport_read(0, addr
);
453 LOG_IOPORT("inb : %04x %02x\n", addr
, val
);
456 env
->last_io_time
= cpu_get_time_fast();
461 int cpu_inw(CPUState
*env
, int addr
)
464 val
= ioport_read(1, addr
);
465 LOG_IOPORT("inw : %04x %04x\n", addr
, val
);
468 env
->last_io_time
= cpu_get_time_fast();
473 int cpu_inl(CPUState
*env
, int addr
)
476 val
= ioport_read(2, addr
);
477 LOG_IOPORT("inl : %04x %08x\n", addr
, val
);
480 env
->last_io_time
= cpu_get_time_fast();
485 /***********************************************************/
486 void hw_error(const char *fmt
, ...)
492 fprintf(stderr
, "qemu: hardware error: ");
493 vfprintf(stderr
, fmt
, ap
);
494 fprintf(stderr
, "\n");
495 for(env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
496 fprintf(stderr
, "CPU #%d:\n", env
->cpu_index
);
498 cpu_dump_state(env
, stderr
, fprintf
, X86_DUMP_FPU
);
500 cpu_dump_state(env
, stderr
, fprintf
, 0);
510 static QEMUBalloonEvent
*qemu_balloon_event
;
511 void *qemu_balloon_event_opaque
;
513 void qemu_add_balloon_handler(QEMUBalloonEvent
*func
, void *opaque
)
515 qemu_balloon_event
= func
;
516 qemu_balloon_event_opaque
= opaque
;
519 void qemu_balloon(ram_addr_t target
)
521 if (qemu_balloon_event
)
522 qemu_balloon_event(qemu_balloon_event_opaque
, target
);
525 ram_addr_t
qemu_balloon_status(void)
527 if (qemu_balloon_event
)
528 return qemu_balloon_event(qemu_balloon_event_opaque
, 0);
532 /***********************************************************/
535 static QEMUPutKBDEvent
*qemu_put_kbd_event
;
536 static void *qemu_put_kbd_event_opaque
;
537 static QEMUPutMouseEntry
*qemu_put_mouse_event_head
;
538 static QEMUPutMouseEntry
*qemu_put_mouse_event_current
;
540 void qemu_add_kbd_event_handler(QEMUPutKBDEvent
*func
, void *opaque
)
542 qemu_put_kbd_event_opaque
= opaque
;
543 qemu_put_kbd_event
= func
;
546 QEMUPutMouseEntry
*qemu_add_mouse_event_handler(QEMUPutMouseEvent
*func
,
547 void *opaque
, int absolute
,
550 QEMUPutMouseEntry
*s
, *cursor
;
552 s
= qemu_mallocz(sizeof(QEMUPutMouseEntry
));
556 s
->qemu_put_mouse_event
= func
;
557 s
->qemu_put_mouse_event_opaque
= opaque
;
558 s
->qemu_put_mouse_event_absolute
= absolute
;
559 s
->qemu_put_mouse_event_name
= qemu_strdup(name
);
562 if (!qemu_put_mouse_event_head
) {
563 qemu_put_mouse_event_head
= qemu_put_mouse_event_current
= s
;
567 cursor
= qemu_put_mouse_event_head
;
568 while (cursor
->next
!= NULL
)
569 cursor
= cursor
->next
;
572 qemu_put_mouse_event_current
= s
;
577 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry
*entry
)
579 QEMUPutMouseEntry
*prev
= NULL
, *cursor
;
581 if (!qemu_put_mouse_event_head
|| entry
== NULL
)
584 cursor
= qemu_put_mouse_event_head
;
585 while (cursor
!= NULL
&& cursor
!= entry
) {
587 cursor
= cursor
->next
;
590 if (cursor
== NULL
) // does not exist or list empty
592 else if (prev
== NULL
) { // entry is head
593 qemu_put_mouse_event_head
= cursor
->next
;
594 if (qemu_put_mouse_event_current
== entry
)
595 qemu_put_mouse_event_current
= cursor
->next
;
596 qemu_free(entry
->qemu_put_mouse_event_name
);
601 prev
->next
= entry
->next
;
603 if (qemu_put_mouse_event_current
== entry
)
604 qemu_put_mouse_event_current
= prev
;
606 qemu_free(entry
->qemu_put_mouse_event_name
);
610 void kbd_put_keycode(int keycode
)
612 if (qemu_put_kbd_event
) {
613 qemu_put_kbd_event(qemu_put_kbd_event_opaque
, keycode
);
617 void kbd_mouse_event(int dx
, int dy
, int dz
, int buttons_state
)
619 QEMUPutMouseEvent
*mouse_event
;
620 void *mouse_event_opaque
;
623 if (!qemu_put_mouse_event_current
) {
628 qemu_put_mouse_event_current
->qemu_put_mouse_event
;
630 qemu_put_mouse_event_current
->qemu_put_mouse_event_opaque
;
633 if (graphic_rotate
) {
634 if (qemu_put_mouse_event_current
->qemu_put_mouse_event_absolute
)
637 width
= graphic_width
- 1;
638 mouse_event(mouse_event_opaque
,
639 width
- dy
, dx
, dz
, buttons_state
);
641 mouse_event(mouse_event_opaque
,
642 dx
, dy
, dz
, buttons_state
);
646 int kbd_mouse_is_absolute(void)
648 if (!qemu_put_mouse_event_current
)
651 return qemu_put_mouse_event_current
->qemu_put_mouse_event_absolute
;
654 void do_info_mice(void)
656 QEMUPutMouseEntry
*cursor
;
659 if (!qemu_put_mouse_event_head
) {
660 term_printf("No mouse devices connected\n");
664 term_printf("Mouse devices available:\n");
665 cursor
= qemu_put_mouse_event_head
;
666 while (cursor
!= NULL
) {
667 term_printf("%c Mouse #%d: %s\n",
668 (cursor
== qemu_put_mouse_event_current
? '*' : ' '),
669 index
, cursor
->qemu_put_mouse_event_name
);
671 cursor
= cursor
->next
;
675 void do_mouse_set(int index
)
677 QEMUPutMouseEntry
*cursor
;
680 if (!qemu_put_mouse_event_head
) {
681 term_printf("No mouse devices connected\n");
685 cursor
= qemu_put_mouse_event_head
;
686 while (cursor
!= NULL
&& index
!= i
) {
688 cursor
= cursor
->next
;
692 qemu_put_mouse_event_current
= cursor
;
694 term_printf("Mouse at given index not found\n");
697 /* compute with 96 bit intermediate result: (a*b)/c */
698 uint64_t muldiv64(uint64_t a
, uint32_t b
, uint32_t c
)
703 #ifdef WORDS_BIGENDIAN
713 rl
= (uint64_t)u
.l
.low
* (uint64_t)b
;
714 rh
= (uint64_t)u
.l
.high
* (uint64_t)b
;
717 res
.l
.low
= (((rh
% c
) << 32) + (rl
& 0xffffffff)) / c
;
721 /***********************************************************/
722 /* real time host monotonic timer */
724 #define QEMU_TIMER_BASE 1000000000LL
728 static int64_t clock_freq
;
730 static void init_get_clock(void)
734 ret
= QueryPerformanceFrequency(&freq
);
736 fprintf(stderr
, "Could not calibrate ticks\n");
739 clock_freq
= freq
.QuadPart
;
742 static int64_t get_clock(void)
745 QueryPerformanceCounter(&ti
);
746 return muldiv64(ti
.QuadPart
, QEMU_TIMER_BASE
, clock_freq
);
751 static int use_rt_clock
;
753 static void init_get_clock(void)
756 #if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 500000)
759 if (clock_gettime(CLOCK_MONOTONIC
, &ts
) == 0) {
766 static int64_t get_clock(void)
768 #if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 500000)
771 clock_gettime(CLOCK_MONOTONIC
, &ts
);
772 return ts
.tv_sec
* 1000000000LL + ts
.tv_nsec
;
776 /* XXX: using gettimeofday leads to problems if the date
777 changes, so it should be avoided. */
779 gettimeofday(&tv
, NULL
);
780 return tv
.tv_sec
* 1000000000LL + (tv
.tv_usec
* 1000);
785 /* Return the virtual CPU time, based on the instruction counter. */
786 static int64_t cpu_get_icount(void)
789 CPUState
*env
= cpu_single_env
;;
790 icount
= qemu_icount
;
793 fprintf(stderr
, "Bad clock read\n");
794 icount
-= (env
->icount_decr
.u16
.low
+ env
->icount_extra
);
796 return qemu_icount_bias
+ (icount
<< icount_time_shift
);
799 /***********************************************************/
800 /* guest cycle counter */
802 static int64_t cpu_ticks_prev
;
803 static int64_t cpu_ticks_offset
;
804 static int64_t cpu_clock_offset
;
805 static int cpu_ticks_enabled
;
807 /* return the host CPU cycle counter and handle stop/restart */
808 int64_t cpu_get_ticks(void)
811 return cpu_get_icount();
813 if (!cpu_ticks_enabled
) {
814 return cpu_ticks_offset
;
817 ticks
= cpu_get_real_ticks();
818 if (cpu_ticks_prev
> ticks
) {
819 /* Note: non increasing ticks may happen if the host uses
821 cpu_ticks_offset
+= cpu_ticks_prev
- ticks
;
823 cpu_ticks_prev
= ticks
;
824 return ticks
+ cpu_ticks_offset
;
828 /* return the host CPU monotonic timer and handle stop/restart */
829 static int64_t cpu_get_clock(void)
832 if (!cpu_ticks_enabled
) {
833 return cpu_clock_offset
;
836 return ti
+ cpu_clock_offset
;
840 /* enable cpu_get_ticks() */
841 void cpu_enable_ticks(void)
843 if (!cpu_ticks_enabled
) {
844 cpu_ticks_offset
-= cpu_get_real_ticks();
845 cpu_clock_offset
-= get_clock();
846 cpu_ticks_enabled
= 1;
850 /* disable cpu_get_ticks() : the clock is stopped. You must not call
851 cpu_get_ticks() after that. */
852 void cpu_disable_ticks(void)
854 if (cpu_ticks_enabled
) {
855 cpu_ticks_offset
= cpu_get_ticks();
856 cpu_clock_offset
= cpu_get_clock();
857 cpu_ticks_enabled
= 0;
861 /***********************************************************/
864 #define QEMU_TIMER_REALTIME 0
865 #define QEMU_TIMER_VIRTUAL 1
869 /* XXX: add frequency */
877 struct QEMUTimer
*next
;
880 struct qemu_alarm_timer
{
884 int (*start
)(struct qemu_alarm_timer
*t
);
885 void (*stop
)(struct qemu_alarm_timer
*t
);
886 void (*rearm
)(struct qemu_alarm_timer
*t
);
890 #define ALARM_FLAG_DYNTICKS 0x1
891 #define ALARM_FLAG_EXPIRED 0x2
893 static inline int alarm_has_dynticks(struct qemu_alarm_timer
*t
)
895 return t
->flags
& ALARM_FLAG_DYNTICKS
;
898 static void qemu_rearm_alarm_timer(struct qemu_alarm_timer
*t
)
900 if (!alarm_has_dynticks(t
))
906 /* TODO: MIN_TIMER_REARM_US should be optimized */
907 #define MIN_TIMER_REARM_US 250
909 static struct qemu_alarm_timer
*alarm_timer
;
911 static int alarm_timer_rfd
, alarm_timer_wfd
;
916 struct qemu_alarm_win32
{
920 } alarm_win32_data
= {0, NULL
, -1};
922 static int win32_start_timer(struct qemu_alarm_timer
*t
);
923 static void win32_stop_timer(struct qemu_alarm_timer
*t
);
924 static void win32_rearm_timer(struct qemu_alarm_timer
*t
);
928 static int unix_start_timer(struct qemu_alarm_timer
*t
);
929 static void unix_stop_timer(struct qemu_alarm_timer
*t
);
933 static int dynticks_start_timer(struct qemu_alarm_timer
*t
);
934 static void dynticks_stop_timer(struct qemu_alarm_timer
*t
);
935 static void dynticks_rearm_timer(struct qemu_alarm_timer
*t
);
937 static int hpet_start_timer(struct qemu_alarm_timer
*t
);
938 static void hpet_stop_timer(struct qemu_alarm_timer
*t
);
940 static int rtc_start_timer(struct qemu_alarm_timer
*t
);
941 static void rtc_stop_timer(struct qemu_alarm_timer
*t
);
943 #endif /* __linux__ */
947 /* Correlation between real and virtual time is always going to be
948 fairly approximate, so ignore small variation.
949 When the guest is idle real and virtual time will be aligned in
951 #define ICOUNT_WOBBLE (QEMU_TIMER_BASE / 10)
953 static void icount_adjust(void)
958 static int64_t last_delta
;
959 /* If the VM is not running, then do nothing. */
963 cur_time
= cpu_get_clock();
964 cur_icount
= qemu_get_clock(vm_clock
);
965 delta
= cur_icount
- cur_time
;
966 /* FIXME: This is a very crude algorithm, somewhat prone to oscillation. */
968 && last_delta
+ ICOUNT_WOBBLE
< delta
* 2
969 && icount_time_shift
> 0) {
970 /* The guest is getting too far ahead. Slow time down. */
974 && last_delta
- ICOUNT_WOBBLE
> delta
* 2
975 && icount_time_shift
< MAX_ICOUNT_SHIFT
) {
976 /* The guest is getting too far behind. Speed time up. */
980 qemu_icount_bias
= cur_icount
- (qemu_icount
<< icount_time_shift
);
983 static void icount_adjust_rt(void * opaque
)
985 qemu_mod_timer(icount_rt_timer
,
986 qemu_get_clock(rt_clock
) + 1000);
990 static void icount_adjust_vm(void * opaque
)
992 qemu_mod_timer(icount_vm_timer
,
993 qemu_get_clock(vm_clock
) + QEMU_TIMER_BASE
/ 10);
997 static void init_icount_adjust(void)
999 /* Have both realtime and virtual time triggers for speed adjustment.
1000 The realtime trigger catches emulated time passing too slowly,
1001 the virtual time trigger catches emulated time passing too fast.
1002 Realtime triggers occur even when idle, so use them less frequently
1003 than VM triggers. */
1004 icount_rt_timer
= qemu_new_timer(rt_clock
, icount_adjust_rt
, NULL
);
1005 qemu_mod_timer(icount_rt_timer
,
1006 qemu_get_clock(rt_clock
) + 1000);
1007 icount_vm_timer
= qemu_new_timer(vm_clock
, icount_adjust_vm
, NULL
);
1008 qemu_mod_timer(icount_vm_timer
,
1009 qemu_get_clock(vm_clock
) + QEMU_TIMER_BASE
/ 10);
1012 static struct qemu_alarm_timer alarm_timers
[] = {
1015 {"dynticks", ALARM_FLAG_DYNTICKS
, dynticks_start_timer
,
1016 dynticks_stop_timer
, dynticks_rearm_timer
, NULL
},
1017 /* HPET - if available - is preferred */
1018 {"hpet", 0, hpet_start_timer
, hpet_stop_timer
, NULL
, NULL
},
1019 /* ...otherwise try RTC */
1020 {"rtc", 0, rtc_start_timer
, rtc_stop_timer
, NULL
, NULL
},
1022 {"unix", 0, unix_start_timer
, unix_stop_timer
, NULL
, NULL
},
1024 {"dynticks", ALARM_FLAG_DYNTICKS
, win32_start_timer
,
1025 win32_stop_timer
, win32_rearm_timer
, &alarm_win32_data
},
1026 {"win32", 0, win32_start_timer
,
1027 win32_stop_timer
, NULL
, &alarm_win32_data
},
1032 static void show_available_alarms(void)
1036 printf("Available alarm timers, in order of precedence:\n");
1037 for (i
= 0; alarm_timers
[i
].name
; i
++)
1038 printf("%s\n", alarm_timers
[i
].name
);
1041 static void configure_alarms(char const *opt
)
1045 int count
= ARRAY_SIZE(alarm_timers
) - 1;
1048 struct qemu_alarm_timer tmp
;
1050 if (!strcmp(opt
, "?")) {
1051 show_available_alarms();
1057 /* Reorder the array */
1058 name
= strtok(arg
, ",");
1060 for (i
= 0; i
< count
&& alarm_timers
[i
].name
; i
++) {
1061 if (!strcmp(alarm_timers
[i
].name
, name
))
1066 fprintf(stderr
, "Unknown clock %s\n", name
);
1075 tmp
= alarm_timers
[i
];
1076 alarm_timers
[i
] = alarm_timers
[cur
];
1077 alarm_timers
[cur
] = tmp
;
1081 name
= strtok(NULL
, ",");
1087 /* Disable remaining timers */
1088 for (i
= cur
; i
< count
; i
++)
1089 alarm_timers
[i
].name
= NULL
;
1091 show_available_alarms();
1096 QEMUClock
*rt_clock
;
1097 QEMUClock
*vm_clock
;
1099 static QEMUTimer
*active_timers
[2];
1101 static QEMUClock
*qemu_new_clock(int type
)
1104 clock
= qemu_mallocz(sizeof(QEMUClock
));
1111 QEMUTimer
*qemu_new_timer(QEMUClock
*clock
, QEMUTimerCB
*cb
, void *opaque
)
1115 ts
= qemu_mallocz(sizeof(QEMUTimer
));
1118 ts
->opaque
= opaque
;
1122 void qemu_free_timer(QEMUTimer
*ts
)
1127 /* stop a timer, but do not dealloc it */
1128 void qemu_del_timer(QEMUTimer
*ts
)
1132 /* NOTE: this code must be signal safe because
1133 qemu_timer_expired() can be called from a signal. */
1134 pt
= &active_timers
[ts
->clock
->type
];
1147 /* modify the current timer so that it will be fired when current_time
1148 >= expire_time. The corresponding callback will be called. */
1149 void qemu_mod_timer(QEMUTimer
*ts
, int64_t expire_time
)
1155 /* add the timer in the sorted list */
1156 /* NOTE: this code must be signal safe because
1157 qemu_timer_expired() can be called from a signal. */
1158 pt
= &active_timers
[ts
->clock
->type
];
1163 if (t
->expire_time
> expire_time
)
1167 ts
->expire_time
= expire_time
;
1171 /* Rearm if necessary */
1172 if (pt
== &active_timers
[ts
->clock
->type
]) {
1173 if ((alarm_timer
->flags
& ALARM_FLAG_EXPIRED
) == 0) {
1174 qemu_rearm_alarm_timer(alarm_timer
);
1176 /* Interrupt execution to force deadline recalculation. */
1177 if (use_icount
&& cpu_single_env
) {
1178 cpu_interrupt(cpu_single_env
, CPU_INTERRUPT_EXIT
);
1183 int qemu_timer_pending(QEMUTimer
*ts
)
1186 for(t
= active_timers
[ts
->clock
->type
]; t
!= NULL
; t
= t
->next
) {
1193 static inline int qemu_timer_expired(QEMUTimer
*timer_head
, int64_t current_time
)
1197 return (timer_head
->expire_time
<= current_time
);
1200 static void qemu_run_timers(QEMUTimer
**ptimer_head
, int64_t current_time
)
1206 if (!ts
|| ts
->expire_time
> current_time
)
1208 /* remove timer from the list before calling the callback */
1209 *ptimer_head
= ts
->next
;
1212 /* run the callback (the timer list can be modified) */
1217 int64_t qemu_get_clock(QEMUClock
*clock
)
1219 switch(clock
->type
) {
1220 case QEMU_TIMER_REALTIME
:
1221 return get_clock() / 1000000;
1223 case QEMU_TIMER_VIRTUAL
:
1225 return cpu_get_icount();
1227 return cpu_get_clock();
1232 static void init_timers(void)
1235 ticks_per_sec
= QEMU_TIMER_BASE
;
1236 rt_clock
= qemu_new_clock(QEMU_TIMER_REALTIME
);
1237 vm_clock
= qemu_new_clock(QEMU_TIMER_VIRTUAL
);
1241 void qemu_put_timer(QEMUFile
*f
, QEMUTimer
*ts
)
1243 uint64_t expire_time
;
1245 if (qemu_timer_pending(ts
)) {
1246 expire_time
= ts
->expire_time
;
1250 qemu_put_be64(f
, expire_time
);
1253 void qemu_get_timer(QEMUFile
*f
, QEMUTimer
*ts
)
1255 uint64_t expire_time
;
1257 expire_time
= qemu_get_be64(f
);
1258 if (expire_time
!= -1) {
1259 qemu_mod_timer(ts
, expire_time
);
1265 static void timer_save(QEMUFile
*f
, void *opaque
)
1267 if (cpu_ticks_enabled
) {
1268 hw_error("cannot save state if virtual timers are running");
1270 qemu_put_be64(f
, cpu_ticks_offset
);
1271 qemu_put_be64(f
, ticks_per_sec
);
1272 qemu_put_be64(f
, cpu_clock_offset
);
1275 static int timer_load(QEMUFile
*f
, void *opaque
, int version_id
)
1277 if (version_id
!= 1 && version_id
!= 2)
1279 if (cpu_ticks_enabled
) {
1282 cpu_ticks_offset
=qemu_get_be64(f
);
1283 ticks_per_sec
=qemu_get_be64(f
);
1284 if (version_id
== 2) {
1285 cpu_clock_offset
=qemu_get_be64(f
);
1291 void CALLBACK
host_alarm_handler(UINT uTimerID
, UINT uMsg
,
1292 DWORD_PTR dwUser
, DWORD_PTR dw1
, DWORD_PTR dw2
)
1294 static void host_alarm_handler(int host_signum
)
1298 #define DISP_FREQ 1000
1300 static int64_t delta_min
= INT64_MAX
;
1301 static int64_t delta_max
, delta_cum
, last_clock
, delta
, ti
;
1303 ti
= qemu_get_clock(vm_clock
);
1304 if (last_clock
!= 0) {
1305 delta
= ti
- last_clock
;
1306 if (delta
< delta_min
)
1308 if (delta
> delta_max
)
1311 if (++count
== DISP_FREQ
) {
1312 printf("timer: min=%" PRId64
" us max=%" PRId64
" us avg=%" PRId64
" us avg_freq=%0.3f Hz\n",
1313 muldiv64(delta_min
, 1000000, ticks_per_sec
),
1314 muldiv64(delta_max
, 1000000, ticks_per_sec
),
1315 muldiv64(delta_cum
, 1000000 / DISP_FREQ
, ticks_per_sec
),
1316 (double)ticks_per_sec
/ ((double)delta_cum
/ DISP_FREQ
));
1318 delta_min
= INT64_MAX
;
1326 if (alarm_has_dynticks(alarm_timer
) ||
1328 qemu_timer_expired(active_timers
[QEMU_TIMER_VIRTUAL
],
1329 qemu_get_clock(vm_clock
))) ||
1330 qemu_timer_expired(active_timers
[QEMU_TIMER_REALTIME
],
1331 qemu_get_clock(rt_clock
))) {
1332 CPUState
*env
= next_cpu
;
1335 struct qemu_alarm_win32
*data
= ((struct qemu_alarm_timer
*)dwUser
)->priv
;
1336 SetEvent(data
->host_alarm
);
1338 static const char byte
= 0;
1339 write(alarm_timer_wfd
, &byte
, sizeof(byte
));
1341 alarm_timer
->flags
|= ALARM_FLAG_EXPIRED
;
1344 /* stop the currently executing cpu because a timer occured */
1345 cpu_interrupt(env
, CPU_INTERRUPT_EXIT
);
1347 if (env
->kqemu_enabled
) {
1348 kqemu_cpu_interrupt(env
);
1356 static int64_t qemu_next_deadline(void)
1360 if (active_timers
[QEMU_TIMER_VIRTUAL
]) {
1361 delta
= active_timers
[QEMU_TIMER_VIRTUAL
]->expire_time
-
1362 qemu_get_clock(vm_clock
);
1364 /* To avoid problems with overflow limit this to 2^32. */
1374 #if defined(__linux__) || defined(_WIN32)
1375 static uint64_t qemu_next_deadline_dyntick(void)
1383 delta
= (qemu_next_deadline() + 999) / 1000;
1385 if (active_timers
[QEMU_TIMER_REALTIME
]) {
1386 rtdelta
= (active_timers
[QEMU_TIMER_REALTIME
]->expire_time
-
1387 qemu_get_clock(rt_clock
))*1000;
1388 if (rtdelta
< delta
)
1392 if (delta
< MIN_TIMER_REARM_US
)
1393 delta
= MIN_TIMER_REARM_US
;
1401 /* Sets a specific flag */
1402 static int fcntl_setfl(int fd
, int flag
)
1406 flags
= fcntl(fd
, F_GETFL
);
1410 if (fcntl(fd
, F_SETFL
, flags
| flag
) == -1)
1416 #if defined(__linux__)
1418 #define RTC_FREQ 1024
1420 static void enable_sigio_timer(int fd
)
1422 struct sigaction act
;
1425 sigfillset(&act
.sa_mask
);
1427 act
.sa_handler
= host_alarm_handler
;
1429 sigaction(SIGIO
, &act
, NULL
);
1430 fcntl_setfl(fd
, O_ASYNC
);
1431 fcntl(fd
, F_SETOWN
, getpid());
1434 static int hpet_start_timer(struct qemu_alarm_timer
*t
)
1436 struct hpet_info info
;
1439 fd
= open("/dev/hpet", O_RDONLY
);
1444 r
= ioctl(fd
, HPET_IRQFREQ
, RTC_FREQ
);
1446 fprintf(stderr
, "Could not configure '/dev/hpet' to have a 1024Hz timer. This is not a fatal\n"
1447 "error, but for better emulation accuracy type:\n"
1448 "'echo 1024 > /proc/sys/dev/hpet/max-user-freq' as root.\n");
1452 /* Check capabilities */
1453 r
= ioctl(fd
, HPET_INFO
, &info
);
1457 /* Enable periodic mode */
1458 r
= ioctl(fd
, HPET_EPI
, 0);
1459 if (info
.hi_flags
&& (r
< 0))
1462 /* Enable interrupt */
1463 r
= ioctl(fd
, HPET_IE_ON
, 0);
1467 enable_sigio_timer(fd
);
1468 t
->priv
= (void *)(long)fd
;
1476 static void hpet_stop_timer(struct qemu_alarm_timer
*t
)
1478 int fd
= (long)t
->priv
;
1483 static int rtc_start_timer(struct qemu_alarm_timer
*t
)
1486 unsigned long current_rtc_freq
= 0;
1488 TFR(rtc_fd
= open("/dev/rtc", O_RDONLY
));
1491 ioctl(rtc_fd
, RTC_IRQP_READ
, ¤t_rtc_freq
);
1492 if (current_rtc_freq
!= RTC_FREQ
&&
1493 ioctl(rtc_fd
, RTC_IRQP_SET
, RTC_FREQ
) < 0) {
1494 fprintf(stderr
, "Could not configure '/dev/rtc' to have a 1024 Hz timer. This is not a fatal\n"
1495 "error, but for better emulation accuracy either use a 2.6 host Linux kernel or\n"
1496 "type 'echo 1024 > /proc/sys/dev/rtc/max-user-freq' as root.\n");
1499 if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
1505 enable_sigio_timer(rtc_fd
);
1507 t
->priv
= (void *)(long)rtc_fd
;
1512 static void rtc_stop_timer(struct qemu_alarm_timer
*t
)
1514 int rtc_fd
= (long)t
->priv
;
1519 static int dynticks_start_timer(struct qemu_alarm_timer
*t
)
1523 struct sigaction act
;
1525 sigfillset(&act
.sa_mask
);
1527 act
.sa_handler
= host_alarm_handler
;
1529 sigaction(SIGALRM
, &act
, NULL
);
1531 ev
.sigev_value
.sival_int
= 0;
1532 ev
.sigev_notify
= SIGEV_SIGNAL
;
1533 ev
.sigev_signo
= SIGALRM
;
1535 if (timer_create(CLOCK_REALTIME
, &ev
, &host_timer
)) {
1536 perror("timer_create");
1538 /* disable dynticks */
1539 fprintf(stderr
, "Dynamic Ticks disabled\n");
1544 t
->priv
= (void *)(long)host_timer
;
1549 static void dynticks_stop_timer(struct qemu_alarm_timer
*t
)
1551 timer_t host_timer
= (timer_t
)(long)t
->priv
;
1553 timer_delete(host_timer
);
1556 static void dynticks_rearm_timer(struct qemu_alarm_timer
*t
)
1558 timer_t host_timer
= (timer_t
)(long)t
->priv
;
1559 struct itimerspec timeout
;
1560 int64_t nearest_delta_us
= INT64_MAX
;
1563 if (!active_timers
[QEMU_TIMER_REALTIME
] &&
1564 !active_timers
[QEMU_TIMER_VIRTUAL
])
1567 nearest_delta_us
= qemu_next_deadline_dyntick();
1569 /* check whether a timer is already running */
1570 if (timer_gettime(host_timer
, &timeout
)) {
1572 fprintf(stderr
, "Internal timer error: aborting\n");
1575 current_us
= timeout
.it_value
.tv_sec
* 1000000 + timeout
.it_value
.tv_nsec
/1000;
1576 if (current_us
&& current_us
<= nearest_delta_us
)
1579 timeout
.it_interval
.tv_sec
= 0;
1580 timeout
.it_interval
.tv_nsec
= 0; /* 0 for one-shot timer */
1581 timeout
.it_value
.tv_sec
= nearest_delta_us
/ 1000000;
1582 timeout
.it_value
.tv_nsec
= (nearest_delta_us
% 1000000) * 1000;
1583 if (timer_settime(host_timer
, 0 /* RELATIVE */, &timeout
, NULL
)) {
1585 fprintf(stderr
, "Internal timer error: aborting\n");
1590 #endif /* defined(__linux__) */
1592 static int unix_start_timer(struct qemu_alarm_timer
*t
)
1594 struct sigaction act
;
1595 struct itimerval itv
;
1599 sigfillset(&act
.sa_mask
);
1601 act
.sa_handler
= host_alarm_handler
;
1603 sigaction(SIGALRM
, &act
, NULL
);
1605 itv
.it_interval
.tv_sec
= 0;
1606 /* for i386 kernel 2.6 to get 1 ms */
1607 itv
.it_interval
.tv_usec
= 999;
1608 itv
.it_value
.tv_sec
= 0;
1609 itv
.it_value
.tv_usec
= 10 * 1000;
1611 err
= setitimer(ITIMER_REAL
, &itv
, NULL
);
1618 static void unix_stop_timer(struct qemu_alarm_timer
*t
)
1620 struct itimerval itv
;
1622 memset(&itv
, 0, sizeof(itv
));
1623 setitimer(ITIMER_REAL
, &itv
, NULL
);
1626 #endif /* !defined(_WIN32) */
1628 static void try_to_rearm_timer(void *opaque
)
1630 struct qemu_alarm_timer
*t
= opaque
;
1634 /* Drain the notify pipe */
1637 len
= read(alarm_timer_rfd
, buffer
, sizeof(buffer
));
1638 } while ((len
== -1 && errno
== EINTR
) || len
> 0);
1641 if (t
->flags
& ALARM_FLAG_EXPIRED
) {
1642 alarm_timer
->flags
&= ~ALARM_FLAG_EXPIRED
;
1643 qemu_rearm_alarm_timer(alarm_timer
);
1649 static int win32_start_timer(struct qemu_alarm_timer
*t
)
1652 struct qemu_alarm_win32
*data
= t
->priv
;
1655 data
->host_alarm
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
1656 if (!data
->host_alarm
) {
1657 perror("Failed CreateEvent");
1661 memset(&tc
, 0, sizeof(tc
));
1662 timeGetDevCaps(&tc
, sizeof(tc
));
1664 if (data
->period
< tc
.wPeriodMin
)
1665 data
->period
= tc
.wPeriodMin
;
1667 timeBeginPeriod(data
->period
);
1669 flags
= TIME_CALLBACK_FUNCTION
;
1670 if (alarm_has_dynticks(t
))
1671 flags
|= TIME_ONESHOT
;
1673 flags
|= TIME_PERIODIC
;
1675 data
->timerId
= timeSetEvent(1, // interval (ms)
1676 data
->period
, // resolution
1677 host_alarm_handler
, // function
1678 (DWORD
)t
, // parameter
1681 if (!data
->timerId
) {
1682 perror("Failed to initialize win32 alarm timer");
1684 timeEndPeriod(data
->period
);
1685 CloseHandle(data
->host_alarm
);
1689 qemu_add_wait_object(data
->host_alarm
, try_to_rearm_timer
, t
);
1694 static void win32_stop_timer(struct qemu_alarm_timer
*t
)
1696 struct qemu_alarm_win32
*data
= t
->priv
;
1698 timeKillEvent(data
->timerId
);
1699 timeEndPeriod(data
->period
);
1701 CloseHandle(data
->host_alarm
);
1704 static void win32_rearm_timer(struct qemu_alarm_timer
*t
)
1706 struct qemu_alarm_win32
*data
= t
->priv
;
1707 uint64_t nearest_delta_us
;
1709 if (!active_timers
[QEMU_TIMER_REALTIME
] &&
1710 !active_timers
[QEMU_TIMER_VIRTUAL
])
1713 nearest_delta_us
= qemu_next_deadline_dyntick();
1714 nearest_delta_us
/= 1000;
1716 timeKillEvent(data
->timerId
);
1718 data
->timerId
= timeSetEvent(1,
1722 TIME_ONESHOT
| TIME_PERIODIC
);
1724 if (!data
->timerId
) {
1725 perror("Failed to re-arm win32 alarm timer");
1727 timeEndPeriod(data
->period
);
1728 CloseHandle(data
->host_alarm
);
1735 static int init_timer_alarm(void)
1737 struct qemu_alarm_timer
*t
= NULL
;
1747 err
= fcntl_setfl(fds
[0], O_NONBLOCK
);
1751 err
= fcntl_setfl(fds
[1], O_NONBLOCK
);
1755 alarm_timer_rfd
= fds
[0];
1756 alarm_timer_wfd
= fds
[1];
1759 for (i
= 0; alarm_timers
[i
].name
; i
++) {
1760 t
= &alarm_timers
[i
];
1773 qemu_set_fd_handler2(alarm_timer_rfd
, NULL
,
1774 try_to_rearm_timer
, NULL
, t
);
1789 static void quit_timers(void)
1791 alarm_timer
->stop(alarm_timer
);
1795 /***********************************************************/
1796 /* host time/date access */
1797 void qemu_get_timedate(struct tm
*tm
, int offset
)
1804 if (rtc_date_offset
== -1) {
1808 ret
= localtime(&ti
);
1810 ti
-= rtc_date_offset
;
1814 memcpy(tm
, ret
, sizeof(struct tm
));
1817 int qemu_timedate_diff(struct tm
*tm
)
1821 if (rtc_date_offset
== -1)
1823 seconds
= mktimegm(tm
);
1825 seconds
= mktime(tm
);
1827 seconds
= mktimegm(tm
) + rtc_date_offset
;
1829 return seconds
- time(NULL
);
1833 static void socket_cleanup(void)
1838 static int socket_init(void)
1843 ret
= WSAStartup(MAKEWORD(2,2), &Data
);
1845 err
= WSAGetLastError();
1846 fprintf(stderr
, "WSAStartup: %d\n", err
);
1849 atexit(socket_cleanup
);
1854 const char *get_opt_name(char *buf
, int buf_size
, const char *p
)
1859 while (*p
!= '\0' && *p
!= '=') {
1860 if (q
&& (q
- buf
) < buf_size
- 1)
1870 const char *get_opt_value(char *buf
, int buf_size
, const char *p
)
1875 while (*p
!= '\0') {
1877 if (*(p
+ 1) != ',')
1881 if (q
&& (q
- buf
) < buf_size
- 1)
1891 int get_param_value(char *buf
, int buf_size
,
1892 const char *tag
, const char *str
)
1899 p
= get_opt_name(option
, sizeof(option
), p
);
1903 if (!strcmp(tag
, option
)) {
1904 (void)get_opt_value(buf
, buf_size
, p
);
1907 p
= get_opt_value(NULL
, 0, p
);
1916 int check_params(char *buf
, int buf_size
,
1917 const char * const *params
, const char *str
)
1924 p
= get_opt_name(buf
, buf_size
, p
);
1928 for(i
= 0; params
[i
] != NULL
; i
++)
1929 if (!strcmp(params
[i
], buf
))
1931 if (params
[i
] == NULL
)
1933 p
= get_opt_value(NULL
, 0, p
);
1941 /***********************************************************/
1942 /* Bluetooth support */
1945 static struct HCIInfo
*hci_table
[MAX_NICS
];
1947 static struct bt_vlan_s
{
1948 struct bt_scatternet_s net
;
1950 struct bt_vlan_s
*next
;
1953 /* find or alloc a new bluetooth "VLAN" */
1954 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
1956 struct bt_vlan_s
**pvlan
, *vlan
;
1957 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
1961 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
1963 pvlan
= &first_bt_vlan
;
1964 while (*pvlan
!= NULL
)
1965 pvlan
= &(*pvlan
)->next
;
1970 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
1974 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
1979 static struct HCIInfo null_hci
= {
1980 .cmd_send
= null_hci_send
,
1981 .sco_send
= null_hci_send
,
1982 .acl_send
= null_hci_send
,
1983 .bdaddr_set
= null_hci_addr_set
,
1986 struct HCIInfo
*qemu_next_hci(void)
1988 if (cur_hci
== nb_hcis
)
1991 return hci_table
[cur_hci
++];
1994 static struct HCIInfo
*hci_init(const char *str
)
1997 struct bt_scatternet_s
*vlan
= 0;
1999 if (!strcmp(str
, "null"))
2002 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
2004 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
2005 else if (!strncmp(str
, "hci", 3)) {
2008 if (!strncmp(str
+ 3, ",vlan=", 6)) {
2009 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
2014 vlan
= qemu_find_bt_vlan(0);
2016 return bt_new_hci(vlan
);
2019 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
2024 static int bt_hci_parse(const char *str
)
2026 struct HCIInfo
*hci
;
2029 if (nb_hcis
>= MAX_NICS
) {
2030 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
2034 hci
= hci_init(str
);
2043 bdaddr
.b
[5] = 0x56 + nb_hcis
;
2044 hci
->bdaddr_set(hci
, bdaddr
.b
);
2046 hci_table
[nb_hcis
++] = hci
;
2051 static void bt_vhci_add(int vlan_id
)
2053 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
2056 fprintf(stderr
, "qemu: warning: adding a VHCI to "
2057 "an empty scatternet %i\n", vlan_id
);
2059 bt_vhci_init(bt_new_hci(vlan
));
2062 static struct bt_device_s
*bt_device_add(const char *opt
)
2064 struct bt_scatternet_s
*vlan
;
2066 char *endp
= strstr(opt
, ",vlan=");
2067 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
2070 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
2073 vlan_id
= strtol(endp
+ 6, &endp
, 0);
2075 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
2080 vlan
= qemu_find_bt_vlan(vlan_id
);
2083 fprintf(stderr
, "qemu: warning: adding a slave device to "
2084 "an empty scatternet %i\n", vlan_id
);
2086 if (!strcmp(devname
, "keyboard"))
2087 return bt_keyboard_init(vlan
);
2089 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
2093 static int bt_parse(const char *opt
)
2095 const char *endp
, *p
;
2098 if (strstart(opt
, "hci", &endp
)) {
2099 if (!*endp
|| *endp
== ',') {
2101 if (!strstart(endp
, ",vlan=", 0))
2104 return bt_hci_parse(opt
);
2106 } else if (strstart(opt
, "vhci", &endp
)) {
2107 if (!*endp
|| *endp
== ',') {
2109 if (strstart(endp
, ",vlan=", &p
)) {
2110 vlan
= strtol(p
, (char **) &endp
, 0);
2112 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
2116 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
2125 } else if (strstart(opt
, "device:", &endp
))
2126 return !bt_device_add(endp
);
2128 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
2132 /***********************************************************/
2133 /* QEMU Block devices */
2135 #define HD_ALIAS "index=%d,media=disk"
2137 #define CDROM_ALIAS "index=1,media=cdrom"
2139 #define CDROM_ALIAS "index=2,media=cdrom"
2141 #define FD_ALIAS "index=%d,if=floppy"
2142 #define PFLASH_ALIAS "if=pflash"
2143 #define MTD_ALIAS "if=mtd"
2144 #define SD_ALIAS "index=0,if=sd"
2146 static int drive_add(const char *file
, const char *fmt
, ...)
2150 if (nb_drives_opt
>= MAX_DRIVES
) {
2151 fprintf(stderr
, "qemu: too many drives\n");
2155 drives_opt
[nb_drives_opt
].file
= file
;
2157 vsnprintf(drives_opt
[nb_drives_opt
].opt
,
2158 sizeof(drives_opt
[0].opt
), fmt
, ap
);
2161 return nb_drives_opt
++;
2164 int drive_get_index(BlockInterfaceType type
, int bus
, int unit
)
2168 /* seek interface, bus and unit */
2170 for (index
= 0; index
< nb_drives
; index
++)
2171 if (drives_table
[index
].type
== type
&&
2172 drives_table
[index
].bus
== bus
&&
2173 drives_table
[index
].unit
== unit
)
2179 int drive_get_max_bus(BlockInterfaceType type
)
2185 for (index
= 0; index
< nb_drives
; index
++) {
2186 if(drives_table
[index
].type
== type
&&
2187 drives_table
[index
].bus
> max_bus
)
2188 max_bus
= drives_table
[index
].bus
;
2193 const char *drive_get_serial(BlockDriverState
*bdrv
)
2197 for (index
= 0; index
< nb_drives
; index
++)
2198 if (drives_table
[index
].bdrv
== bdrv
)
2199 return drives_table
[index
].serial
;
2204 BlockInterfaceErrorAction
drive_get_onerror(BlockDriverState
*bdrv
)
2208 for (index
= 0; index
< nb_drives
; index
++)
2209 if (drives_table
[index
].bdrv
== bdrv
)
2210 return drives_table
[index
].onerror
;
2212 return BLOCK_ERR_REPORT
;
2215 static void bdrv_format_print(void *opaque
, const char *name
)
2217 fprintf(stderr
, " %s", name
);
2220 static int drive_init(struct drive_opt
*arg
, int snapshot
,
2221 QEMUMachine
*machine
)
2227 const char *mediastr
= "";
2228 BlockInterfaceType type
;
2229 enum { MEDIA_DISK
, MEDIA_CDROM
} media
;
2230 int bus_id
, unit_id
;
2231 int cyls
, heads
, secs
, translation
;
2232 BlockDriverState
*bdrv
;
2233 BlockDriver
*drv
= NULL
;
2237 int bdrv_flags
, onerror
;
2238 char *str
= arg
->opt
;
2239 static const char * const params
[] = { "bus", "unit", "if", "index",
2240 "cyls", "heads", "secs", "trans",
2241 "media", "snapshot", "file",
2242 "cache", "format", "serial", "werror",
2245 if (check_params(buf
, sizeof(buf
), params
, str
) < 0) {
2246 fprintf(stderr
, "qemu: unknown parameter '%s' in '%s'\n",
2252 cyls
= heads
= secs
= 0;
2255 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2259 if (machine
->use_scsi
) {
2261 max_devs
= MAX_SCSI_DEVS
;
2262 pstrcpy(devname
, sizeof(devname
), "scsi");
2265 max_devs
= MAX_IDE_DEVS
;
2266 pstrcpy(devname
, sizeof(devname
), "ide");
2270 /* extract parameters */
2272 if (get_param_value(buf
, sizeof(buf
), "bus", str
)) {
2273 bus_id
= strtol(buf
, NULL
, 0);
2275 fprintf(stderr
, "qemu: '%s' invalid bus id\n", str
);
2280 if (get_param_value(buf
, sizeof(buf
), "unit", str
)) {
2281 unit_id
= strtol(buf
, NULL
, 0);
2283 fprintf(stderr
, "qemu: '%s' invalid unit id\n", str
);
2288 if (get_param_value(buf
, sizeof(buf
), "if", str
)) {
2289 pstrcpy(devname
, sizeof(devname
), buf
);
2290 if (!strcmp(buf
, "ide")) {
2292 max_devs
= MAX_IDE_DEVS
;
2293 } else if (!strcmp(buf
, "scsi")) {
2295 max_devs
= MAX_SCSI_DEVS
;
2296 } else if (!strcmp(buf
, "floppy")) {
2299 } else if (!strcmp(buf
, "pflash")) {
2302 } else if (!strcmp(buf
, "mtd")) {
2305 } else if (!strcmp(buf
, "sd")) {
2308 } else if (!strcmp(buf
, "virtio")) {
2312 fprintf(stderr
, "qemu: '%s' unsupported bus type '%s'\n", str
, buf
);
2317 if (get_param_value(buf
, sizeof(buf
), "index", str
)) {
2318 index
= strtol(buf
, NULL
, 0);
2320 fprintf(stderr
, "qemu: '%s' invalid index\n", str
);
2325 if (get_param_value(buf
, sizeof(buf
), "cyls", str
)) {
2326 cyls
= strtol(buf
, NULL
, 0);
2329 if (get_param_value(buf
, sizeof(buf
), "heads", str
)) {
2330 heads
= strtol(buf
, NULL
, 0);
2333 if (get_param_value(buf
, sizeof(buf
), "secs", str
)) {
2334 secs
= strtol(buf
, NULL
, 0);
2337 if (cyls
|| heads
|| secs
) {
2338 if (cyls
< 1 || cyls
> 16383) {
2339 fprintf(stderr
, "qemu: '%s' invalid physical cyls number\n", str
);
2342 if (heads
< 1 || heads
> 16) {
2343 fprintf(stderr
, "qemu: '%s' invalid physical heads number\n", str
);
2346 if (secs
< 1 || secs
> 63) {
2347 fprintf(stderr
, "qemu: '%s' invalid physical secs number\n", str
);
2352 if (get_param_value(buf
, sizeof(buf
), "trans", str
)) {
2355 "qemu: '%s' trans must be used with cyls,heads and secs\n",
2359 if (!strcmp(buf
, "none"))
2360 translation
= BIOS_ATA_TRANSLATION_NONE
;
2361 else if (!strcmp(buf
, "lba"))
2362 translation
= BIOS_ATA_TRANSLATION_LBA
;
2363 else if (!strcmp(buf
, "auto"))
2364 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2366 fprintf(stderr
, "qemu: '%s' invalid translation type\n", str
);
2371 if (get_param_value(buf
, sizeof(buf
), "media", str
)) {
2372 if (!strcmp(buf
, "disk")) {
2374 } else if (!strcmp(buf
, "cdrom")) {
2375 if (cyls
|| secs
|| heads
) {
2377 "qemu: '%s' invalid physical CHS format\n", str
);
2380 media
= MEDIA_CDROM
;
2382 fprintf(stderr
, "qemu: '%s' invalid media\n", str
);
2387 if (get_param_value(buf
, sizeof(buf
), "snapshot", str
)) {
2388 if (!strcmp(buf
, "on"))
2390 else if (!strcmp(buf
, "off"))
2393 fprintf(stderr
, "qemu: '%s' invalid snapshot option\n", str
);
2398 if (get_param_value(buf
, sizeof(buf
), "cache", str
)) {
2399 if (!strcmp(buf
, "off") || !strcmp(buf
, "none"))
2401 else if (!strcmp(buf
, "writethrough"))
2403 else if (!strcmp(buf
, "writeback"))
2406 fprintf(stderr
, "qemu: invalid cache option\n");
2411 if (get_param_value(buf
, sizeof(buf
), "format", str
)) {
2412 if (strcmp(buf
, "?") == 0) {
2413 fprintf(stderr
, "qemu: Supported formats:");
2414 bdrv_iterate_format(bdrv_format_print
, NULL
);
2415 fprintf(stderr
, "\n");
2418 drv
= bdrv_find_format(buf
);
2420 fprintf(stderr
, "qemu: '%s' invalid format\n", buf
);
2425 if (arg
->file
== NULL
)
2426 get_param_value(file
, sizeof(file
), "file", str
);
2428 pstrcpy(file
, sizeof(file
), arg
->file
);
2430 if (!get_param_value(serial
, sizeof(serial
), "serial", str
))
2431 memset(serial
, 0, sizeof(serial
));
2433 onerror
= BLOCK_ERR_REPORT
;
2434 if (get_param_value(buf
, sizeof(serial
), "werror", str
)) {
2435 if (type
!= IF_IDE
&& type
!= IF_SCSI
&& type
!= IF_VIRTIO
) {
2436 fprintf(stderr
, "werror is no supported by this format\n");
2439 if (!strcmp(buf
, "ignore"))
2440 onerror
= BLOCK_ERR_IGNORE
;
2441 else if (!strcmp(buf
, "enospc"))
2442 onerror
= BLOCK_ERR_STOP_ENOSPC
;
2443 else if (!strcmp(buf
, "stop"))
2444 onerror
= BLOCK_ERR_STOP_ANY
;
2445 else if (!strcmp(buf
, "report"))
2446 onerror
= BLOCK_ERR_REPORT
;
2448 fprintf(stderr
, "qemu: '%s' invalid write error action\n", buf
);
2453 /* compute bus and unit according index */
2456 if (bus_id
!= 0 || unit_id
!= -1) {
2458 "qemu: '%s' index cannot be used with bus and unit\n", str
);
2466 unit_id
= index
% max_devs
;
2467 bus_id
= index
/ max_devs
;
2471 /* if user doesn't specify a unit_id,
2472 * try to find the first free
2475 if (unit_id
== -1) {
2477 while (drive_get_index(type
, bus_id
, unit_id
) != -1) {
2479 if (max_devs
&& unit_id
>= max_devs
) {
2480 unit_id
-= max_devs
;
2488 if (max_devs
&& unit_id
>= max_devs
) {
2489 fprintf(stderr
, "qemu: '%s' unit %d too big (max is %d)\n",
2490 str
, unit_id
, max_devs
- 1);
2495 * ignore multiple definitions
2498 if (drive_get_index(type
, bus_id
, unit_id
) != -1)
2503 if (type
== IF_IDE
|| type
== IF_SCSI
)
2504 mediastr
= (media
== MEDIA_CDROM
) ? "-cd" : "-hd";
2506 snprintf(buf
, sizeof(buf
), "%s%i%s%i",
2507 devname
, bus_id
, mediastr
, unit_id
);
2509 snprintf(buf
, sizeof(buf
), "%s%s%i",
2510 devname
, mediastr
, unit_id
);
2511 bdrv
= bdrv_new(buf
);
2512 drives_table
[nb_drives
].bdrv
= bdrv
;
2513 drives_table
[nb_drives
].type
= type
;
2514 drives_table
[nb_drives
].bus
= bus_id
;
2515 drives_table
[nb_drives
].unit
= unit_id
;
2516 drives_table
[nb_drives
].onerror
= onerror
;
2517 strncpy(drives_table
[nb_drives
].serial
, serial
, sizeof(serial
));
2526 bdrv_set_geometry_hint(bdrv
, cyls
, heads
, secs
);
2527 bdrv_set_translation_hint(bdrv
, translation
);
2531 bdrv_set_type_hint(bdrv
, BDRV_TYPE_CDROM
);
2536 /* FIXME: This isn't really a floppy, but it's a reasonable
2539 bdrv_set_type_hint(bdrv
, BDRV_TYPE_FLOPPY
);
2550 bdrv_flags
|= BDRV_O_SNAPSHOT
;
2551 cache
= 2; /* always use write-back with snapshot */
2553 if (cache
== 0) /* no caching */
2554 bdrv_flags
|= BDRV_O_NOCACHE
;
2555 else if (cache
== 2) /* write-back */
2556 bdrv_flags
|= BDRV_O_CACHE_WB
;
2557 else if (cache
== 3) /* not specified */
2558 bdrv_flags
|= BDRV_O_CACHE_DEF
;
2559 if (bdrv_open2(bdrv
, file
, bdrv_flags
, drv
) < 0 || qemu_key_check(bdrv
, file
)) {
2560 fprintf(stderr
, "qemu: could not open disk image %s\n",
2567 /***********************************************************/
2570 static USBPort
*used_usb_ports
;
2571 static USBPort
*free_usb_ports
;
2573 /* ??? Maybe change this to register a hub to keep track of the topology. */
2574 void qemu_register_usb_port(USBPort
*port
, void *opaque
, int index
,
2575 usb_attachfn attach
)
2577 port
->opaque
= opaque
;
2578 port
->index
= index
;
2579 port
->attach
= attach
;
2580 port
->next
= free_usb_ports
;
2581 free_usb_ports
= port
;
2584 int usb_device_add_dev(USBDevice
*dev
)
2588 /* Find a USB port to add the device to. */
2589 port
= free_usb_ports
;
2593 /* Create a new hub and chain it on. */
2594 free_usb_ports
= NULL
;
2595 port
->next
= used_usb_ports
;
2596 used_usb_ports
= port
;
2598 hub
= usb_hub_init(VM_USB_HUB_SIZE
);
2599 usb_attach(port
, hub
);
2600 port
= free_usb_ports
;
2603 free_usb_ports
= port
->next
;
2604 port
->next
= used_usb_ports
;
2605 used_usb_ports
= port
;
2606 usb_attach(port
, dev
);
2610 static int usb_device_add(const char *devname
)
2615 if (!free_usb_ports
)
2618 if (strstart(devname
, "host:", &p
)) {
2619 dev
= usb_host_device_open(p
);
2620 } else if (!strcmp(devname
, "mouse")) {
2621 dev
= usb_mouse_init();
2622 } else if (!strcmp(devname
, "tablet")) {
2623 dev
= usb_tablet_init();
2624 } else if (!strcmp(devname
, "keyboard")) {
2625 dev
= usb_keyboard_init();
2626 } else if (strstart(devname
, "disk:", &p
)) {
2627 dev
= usb_msd_init(p
);
2628 } else if (!strcmp(devname
, "wacom-tablet")) {
2629 dev
= usb_wacom_init();
2630 } else if (strstart(devname
, "serial:", &p
)) {
2631 dev
= usb_serial_init(p
);
2632 #ifdef CONFIG_BRLAPI
2633 } else if (!strcmp(devname
, "braille")) {
2634 dev
= usb_baum_init();
2636 } else if (strstart(devname
, "net:", &p
)) {
2639 if (net_client_init("nic", p
) < 0)
2641 nd_table
[nic
].model
= "usb";
2642 dev
= usb_net_init(&nd_table
[nic
]);
2643 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
2644 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
2645 bt_new_hci(qemu_find_bt_vlan(0)));
2652 return usb_device_add_dev(dev
);
2655 int usb_device_del_addr(int bus_num
, int addr
)
2661 if (!used_usb_ports
)
2667 lastp
= &used_usb_ports
;
2668 port
= used_usb_ports
;
2669 while (port
&& port
->dev
->addr
!= addr
) {
2670 lastp
= &port
->next
;
2678 *lastp
= port
->next
;
2679 usb_attach(port
, NULL
);
2680 dev
->handle_destroy(dev
);
2681 port
->next
= free_usb_ports
;
2682 free_usb_ports
= port
;
2686 static int usb_device_del(const char *devname
)
2691 if (strstart(devname
, "host:", &p
))
2692 return usb_host_device_close(p
);
2694 if (!used_usb_ports
)
2697 p
= strchr(devname
, '.');
2700 bus_num
= strtoul(devname
, NULL
, 0);
2701 addr
= strtoul(p
+ 1, NULL
, 0);
2703 return usb_device_del_addr(bus_num
, addr
);
2706 void do_usb_add(const char *devname
)
2708 usb_device_add(devname
);
2711 void do_usb_del(const char *devname
)
2713 usb_device_del(devname
);
2720 const char *speed_str
;
2723 term_printf("USB support not enabled\n");
2727 for (port
= used_usb_ports
; port
; port
= port
->next
) {
2731 switch(dev
->speed
) {
2735 case USB_SPEED_FULL
:
2738 case USB_SPEED_HIGH
:
2745 term_printf(" Device %d.%d, Speed %s Mb/s, Product %s\n",
2746 0, dev
->addr
, speed_str
, dev
->devname
);
2750 /***********************************************************/
2751 /* PCMCIA/Cardbus */
2753 static struct pcmcia_socket_entry_s
{
2754 struct pcmcia_socket_s
*socket
;
2755 struct pcmcia_socket_entry_s
*next
;
2756 } *pcmcia_sockets
= 0;
2758 void pcmcia_socket_register(struct pcmcia_socket_s
*socket
)
2760 struct pcmcia_socket_entry_s
*entry
;
2762 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
2763 entry
->socket
= socket
;
2764 entry
->next
= pcmcia_sockets
;
2765 pcmcia_sockets
= entry
;
2768 void pcmcia_socket_unregister(struct pcmcia_socket_s
*socket
)
2770 struct pcmcia_socket_entry_s
*entry
, **ptr
;
2772 ptr
= &pcmcia_sockets
;
2773 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
2774 if (entry
->socket
== socket
) {
2780 void pcmcia_info(void)
2782 struct pcmcia_socket_entry_s
*iter
;
2783 if (!pcmcia_sockets
)
2784 term_printf("No PCMCIA sockets\n");
2786 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
2787 term_printf("%s: %s\n", iter
->socket
->slot_string
,
2788 iter
->socket
->attached
? iter
->socket
->card_string
:
2792 /***********************************************************/
2793 /* register display */
2795 void register_displaystate(DisplayState
*ds
)
2805 DisplayState
*get_displaystate(void)
2807 return display_state
;
2812 static void dumb_display_init(void)
2814 DisplayState
*ds
= qemu_mallocz(sizeof(DisplayState
));
2816 fprintf(stderr
, "dumb_display_init: DisplayState allocation failed\n");
2819 ds
->surface
= qemu_create_displaysurface(640, 480, 32, 640 * 4);
2820 register_displaystate(ds
);
2823 /***********************************************************/
2826 #define MAX_IO_HANDLERS 64
2828 typedef struct IOHandlerRecord
{
2830 IOCanRWHandler
*fd_read_poll
;
2832 IOHandler
*fd_write
;
2835 /* temporary data */
2837 struct IOHandlerRecord
*next
;
2840 static IOHandlerRecord
*first_io_handler
;
2842 /* XXX: fd_read_poll should be suppressed, but an API change is
2843 necessary in the character devices to suppress fd_can_read(). */
2844 int qemu_set_fd_handler2(int fd
,
2845 IOCanRWHandler
*fd_read_poll
,
2847 IOHandler
*fd_write
,
2850 IOHandlerRecord
**pioh
, *ioh
;
2852 if (!fd_read
&& !fd_write
) {
2853 pioh
= &first_io_handler
;
2858 if (ioh
->fd
== fd
) {
2865 for(ioh
= first_io_handler
; ioh
!= NULL
; ioh
= ioh
->next
) {
2869 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
2872 ioh
->next
= first_io_handler
;
2873 first_io_handler
= ioh
;
2876 ioh
->fd_read_poll
= fd_read_poll
;
2877 ioh
->fd_read
= fd_read
;
2878 ioh
->fd_write
= fd_write
;
2879 ioh
->opaque
= opaque
;
2885 int qemu_set_fd_handler(int fd
,
2887 IOHandler
*fd_write
,
2890 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
2894 /***********************************************************/
2895 /* Polling handling */
2897 typedef struct PollingEntry
{
2900 struct PollingEntry
*next
;
2903 static PollingEntry
*first_polling_entry
;
2905 int qemu_add_polling_cb(PollingFunc
*func
, void *opaque
)
2907 PollingEntry
**ppe
, *pe
;
2908 pe
= qemu_mallocz(sizeof(PollingEntry
));
2912 pe
->opaque
= opaque
;
2913 for(ppe
= &first_polling_entry
; *ppe
!= NULL
; ppe
= &(*ppe
)->next
);
2918 void qemu_del_polling_cb(PollingFunc
*func
, void *opaque
)
2920 PollingEntry
**ppe
, *pe
;
2921 for(ppe
= &first_polling_entry
; *ppe
!= NULL
; ppe
= &(*ppe
)->next
) {
2923 if (pe
->func
== func
&& pe
->opaque
== opaque
) {
2931 /***********************************************************/
2932 /* Wait objects support */
2933 typedef struct WaitObjects
{
2935 HANDLE events
[MAXIMUM_WAIT_OBJECTS
+ 1];
2936 WaitObjectFunc
*func
[MAXIMUM_WAIT_OBJECTS
+ 1];
2937 void *opaque
[MAXIMUM_WAIT_OBJECTS
+ 1];
2940 static WaitObjects wait_objects
= {0};
2942 int qemu_add_wait_object(HANDLE handle
, WaitObjectFunc
*func
, void *opaque
)
2944 WaitObjects
*w
= &wait_objects
;
2946 if (w
->num
>= MAXIMUM_WAIT_OBJECTS
)
2948 w
->events
[w
->num
] = handle
;
2949 w
->func
[w
->num
] = func
;
2950 w
->opaque
[w
->num
] = opaque
;
2955 void qemu_del_wait_object(HANDLE handle
, WaitObjectFunc
*func
, void *opaque
)
2958 WaitObjects
*w
= &wait_objects
;
2961 for (i
= 0; i
< w
->num
; i
++) {
2962 if (w
->events
[i
] == handle
)
2965 w
->events
[i
] = w
->events
[i
+ 1];
2966 w
->func
[i
] = w
->func
[i
+ 1];
2967 w
->opaque
[i
] = w
->opaque
[i
+ 1];
2975 /***********************************************************/
2976 /* ram save/restore */
2978 static int ram_get_page(QEMUFile
*f
, uint8_t *buf
, int len
)
2982 v
= qemu_get_byte(f
);
2985 if (qemu_get_buffer(f
, buf
, len
) != len
)
2989 v
= qemu_get_byte(f
);
2990 memset(buf
, v
, len
);
2996 if (qemu_file_has_error(f
))
3002 static int ram_load_v1(QEMUFile
*f
, void *opaque
)
3007 if (qemu_get_be32(f
) != phys_ram_size
)
3009 for(i
= 0; i
< phys_ram_size
; i
+= TARGET_PAGE_SIZE
) {
3010 ret
= ram_get_page(f
, phys_ram_base
+ i
, TARGET_PAGE_SIZE
);
3017 #define BDRV_HASH_BLOCK_SIZE 1024
3018 #define IOBUF_SIZE 4096
3019 #define RAM_CBLOCK_MAGIC 0xfabe
3021 typedef struct RamDecompressState
{
3024 uint8_t buf
[IOBUF_SIZE
];
3025 } RamDecompressState
;
3027 static int ram_decompress_open(RamDecompressState
*s
, QEMUFile
*f
)
3030 memset(s
, 0, sizeof(*s
));
3032 ret
= inflateInit(&s
->zstream
);
3038 static int ram_decompress_buf(RamDecompressState
*s
, uint8_t *buf
, int len
)
3042 s
->zstream
.avail_out
= len
;
3043 s
->zstream
.next_out
= buf
;
3044 while (s
->zstream
.avail_out
> 0) {
3045 if (s
->zstream
.avail_in
== 0) {
3046 if (qemu_get_be16(s
->f
) != RAM_CBLOCK_MAGIC
)
3048 clen
= qemu_get_be16(s
->f
);
3049 if (clen
> IOBUF_SIZE
)
3051 qemu_get_buffer(s
->f
, s
->buf
, clen
);
3052 s
->zstream
.avail_in
= clen
;
3053 s
->zstream
.next_in
= s
->buf
;
3055 ret
= inflate(&s
->zstream
, Z_PARTIAL_FLUSH
);
3056 if (ret
!= Z_OK
&& ret
!= Z_STREAM_END
) {
3063 static void ram_decompress_close(RamDecompressState
*s
)
3065 inflateEnd(&s
->zstream
);
3068 #define RAM_SAVE_FLAG_FULL 0x01
3069 #define RAM_SAVE_FLAG_COMPRESS 0x02
3070 #define RAM_SAVE_FLAG_MEM_SIZE 0x04
3071 #define RAM_SAVE_FLAG_PAGE 0x08
3072 #define RAM_SAVE_FLAG_EOS 0x10
3074 static int is_dup_page(uint8_t *page
, uint8_t ch
)
3076 uint32_t val
= ch
<< 24 | ch
<< 16 | ch
<< 8 | ch
;
3077 uint32_t *array
= (uint32_t *)page
;
3080 for (i
= 0; i
< (TARGET_PAGE_SIZE
/ 4); i
++) {
3081 if (array
[i
] != val
)
3088 static int ram_save_block(QEMUFile
*f
)
3090 static ram_addr_t current_addr
= 0;
3091 ram_addr_t saved_addr
= current_addr
;
3092 ram_addr_t addr
= 0;
3095 while (addr
< phys_ram_size
) {
3096 if (cpu_physical_memory_get_dirty(current_addr
, MIGRATION_DIRTY_FLAG
)) {
3099 cpu_physical_memory_reset_dirty(current_addr
,
3100 current_addr
+ TARGET_PAGE_SIZE
,
3101 MIGRATION_DIRTY_FLAG
);
3103 ch
= *(phys_ram_base
+ current_addr
);
3105 if (is_dup_page(phys_ram_base
+ current_addr
, ch
)) {
3106 qemu_put_be64(f
, current_addr
| RAM_SAVE_FLAG_COMPRESS
);
3107 qemu_put_byte(f
, ch
);
3109 qemu_put_be64(f
, current_addr
| RAM_SAVE_FLAG_PAGE
);
3110 qemu_put_buffer(f
, phys_ram_base
+ current_addr
, TARGET_PAGE_SIZE
);
3116 addr
+= TARGET_PAGE_SIZE
;
3117 current_addr
= (saved_addr
+ addr
) % phys_ram_size
;
3123 static ram_addr_t ram_save_threshold
= 10;
3125 static ram_addr_t
ram_save_remaining(void)
3128 ram_addr_t count
= 0;
3130 for (addr
= 0; addr
< phys_ram_size
; addr
+= TARGET_PAGE_SIZE
) {
3131 if (cpu_physical_memory_get_dirty(addr
, MIGRATION_DIRTY_FLAG
))
3138 static int ram_save_live(QEMUFile
*f
, int stage
, void *opaque
)
3143 /* Make sure all dirty bits are set */
3144 for (addr
= 0; addr
< phys_ram_size
; addr
+= TARGET_PAGE_SIZE
) {
3145 if (!cpu_physical_memory_get_dirty(addr
, MIGRATION_DIRTY_FLAG
))
3146 cpu_physical_memory_set_dirty(addr
);
3149 /* Enable dirty memory tracking */
3150 cpu_physical_memory_set_dirty_tracking(1);
3152 qemu_put_be64(f
, phys_ram_size
| RAM_SAVE_FLAG_MEM_SIZE
);
3155 while (!qemu_file_rate_limit(f
)) {
3158 ret
= ram_save_block(f
);
3159 if (ret
== 0) /* no more blocks */
3163 /* try transferring iterative blocks of memory */
3166 cpu_physical_memory_set_dirty_tracking(0);
3168 /* flush all remaining blocks regardless of rate limiting */
3169 while (ram_save_block(f
) != 0);
3172 qemu_put_be64(f
, RAM_SAVE_FLAG_EOS
);
3174 return (stage
== 2) && (ram_save_remaining() < ram_save_threshold
);
3177 static int ram_load_dead(QEMUFile
*f
, void *opaque
)
3179 RamDecompressState s1
, *s
= &s1
;
3183 if (ram_decompress_open(s
, f
) < 0)
3185 for(i
= 0; i
< phys_ram_size
; i
+= BDRV_HASH_BLOCK_SIZE
) {
3186 if (ram_decompress_buf(s
, buf
, 1) < 0) {
3187 fprintf(stderr
, "Error while reading ram block header\n");
3191 if (ram_decompress_buf(s
, phys_ram_base
+ i
, BDRV_HASH_BLOCK_SIZE
) < 0) {
3192 fprintf(stderr
, "Error while reading ram block address=0x%08" PRIx64
, (uint64_t)i
);
3197 printf("Error block header\n");
3201 ram_decompress_close(s
);
3206 static int ram_load(QEMUFile
*f
, void *opaque
, int version_id
)
3211 if (version_id
== 1)
3212 return ram_load_v1(f
, opaque
);
3214 if (version_id
== 2) {
3215 if (qemu_get_be32(f
) != phys_ram_size
)
3217 return ram_load_dead(f
, opaque
);
3220 if (version_id
!= 3)
3224 addr
= qemu_get_be64(f
);
3226 flags
= addr
& ~TARGET_PAGE_MASK
;
3227 addr
&= TARGET_PAGE_MASK
;
3229 if (flags
& RAM_SAVE_FLAG_MEM_SIZE
) {
3230 if (addr
!= phys_ram_size
)
3234 if (flags
& RAM_SAVE_FLAG_FULL
) {
3235 if (ram_load_dead(f
, opaque
) < 0)
3239 if (flags
& RAM_SAVE_FLAG_COMPRESS
) {
3240 uint8_t ch
= qemu_get_byte(f
);
3241 memset(phys_ram_base
+ addr
, ch
, TARGET_PAGE_SIZE
);
3242 } else if (flags
& RAM_SAVE_FLAG_PAGE
)
3243 qemu_get_buffer(f
, phys_ram_base
+ addr
, TARGET_PAGE_SIZE
);
3244 } while (!(flags
& RAM_SAVE_FLAG_EOS
));
3249 void qemu_service_io(void)
3251 CPUState
*env
= cpu_single_env
;
3253 cpu_interrupt(env
, CPU_INTERRUPT_EXIT
);
3255 if (env
->kqemu_enabled
) {
3256 kqemu_cpu_interrupt(env
);
3262 /***********************************************************/
3263 /* bottom halves (can be seen as timers which expire ASAP) */
3274 static QEMUBH
*first_bh
= NULL
;
3276 QEMUBH
*qemu_bh_new(QEMUBHFunc
*cb
, void *opaque
)
3279 bh
= qemu_mallocz(sizeof(QEMUBH
));
3283 bh
->opaque
= opaque
;
3284 bh
->next
= first_bh
;
3289 int qemu_bh_poll(void)
3295 for (bh
= first_bh
; bh
; bh
= bh
->next
) {
3296 if (!bh
->deleted
&& bh
->scheduled
) {
3305 /* remove deleted bhs */
3319 void qemu_bh_schedule_idle(QEMUBH
*bh
)
3327 void qemu_bh_schedule(QEMUBH
*bh
)
3329 CPUState
*env
= cpu_single_env
;
3334 /* stop the currently executing CPU to execute the BH ASAP */
3336 cpu_interrupt(env
, CPU_INTERRUPT_EXIT
);
3340 void qemu_bh_cancel(QEMUBH
*bh
)
3345 void qemu_bh_delete(QEMUBH
*bh
)
3351 static void qemu_bh_update_timeout(int *timeout
)
3355 for (bh
= first_bh
; bh
; bh
= bh
->next
) {
3356 if (!bh
->deleted
&& bh
->scheduled
) {
3358 /* idle bottom halves will be polled at least
3360 *timeout
= MIN(10, *timeout
);
3362 /* non-idle bottom halves will be executed
3371 /***********************************************************/
3372 /* machine registration */
3374 static QEMUMachine
*first_machine
= NULL
;
3376 int qemu_register_machine(QEMUMachine
*m
)
3379 pm
= &first_machine
;
3387 static QEMUMachine
*find_machine(const char *name
)
3391 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
3392 if (!strcmp(m
->name
, name
))
3398 /***********************************************************/
3399 /* main execution loop */
3401 static void gui_update(void *opaque
)
3403 uint64_t interval
= GUI_REFRESH_INTERVAL
;
3404 DisplayState
*ds
= opaque
;
3405 DisplayChangeListener
*dcl
= ds
->listeners
;
3409 while (dcl
!= NULL
) {
3410 if (dcl
->gui_timer_interval
&&
3411 dcl
->gui_timer_interval
< interval
)
3412 interval
= dcl
->gui_timer_interval
;
3415 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
3418 static void nographic_update(void *opaque
)
3420 uint64_t interval
= GUI_REFRESH_INTERVAL
;
3422 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
3425 struct vm_change_state_entry
{
3426 VMChangeStateHandler
*cb
;
3428 LIST_ENTRY (vm_change_state_entry
) entries
;
3431 static LIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
3433 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
3436 VMChangeStateEntry
*e
;
3438 e
= qemu_mallocz(sizeof (*e
));
3444 LIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
3448 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
3450 LIST_REMOVE (e
, entries
);
3454 static void vm_state_notify(int running
, int reason
)
3456 VMChangeStateEntry
*e
;
3458 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
3459 e
->cb(e
->opaque
, running
, reason
);
3468 vm_state_notify(1, 0);
3469 qemu_rearm_alarm_timer(alarm_timer
);
3473 void vm_stop(int reason
)
3476 cpu_disable_ticks();
3478 vm_state_notify(0, reason
);
3482 /* reset/shutdown handler */
3484 typedef struct QEMUResetEntry
{
3485 QEMUResetHandler
*func
;
3487 struct QEMUResetEntry
*next
;
3490 static QEMUResetEntry
*first_reset_entry
;
3491 static int reset_requested
;
3492 static int shutdown_requested
;
3493 static int powerdown_requested
;
3495 int qemu_shutdown_requested(void)
3497 int r
= shutdown_requested
;
3498 shutdown_requested
= 0;
3502 int qemu_reset_requested(void)
3504 int r
= reset_requested
;
3505 reset_requested
= 0;
3509 int qemu_powerdown_requested(void)
3511 int r
= powerdown_requested
;
3512 powerdown_requested
= 0;
3516 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
3518 QEMUResetEntry
**pre
, *re
;
3520 pre
= &first_reset_entry
;
3521 while (*pre
!= NULL
)
3522 pre
= &(*pre
)->next
;
3523 re
= qemu_mallocz(sizeof(QEMUResetEntry
));
3525 re
->opaque
= opaque
;
3530 void qemu_system_reset(void)
3534 /* reset all devices */
3535 for(re
= first_reset_entry
; re
!= NULL
; re
= re
->next
) {
3536 re
->func(re
->opaque
);
3540 void qemu_system_reset_request(void)
3543 shutdown_requested
= 1;
3545 reset_requested
= 1;
3548 cpu_interrupt(cpu_single_env
, CPU_INTERRUPT_EXIT
);
3551 void qemu_system_shutdown_request(void)
3553 shutdown_requested
= 1;
3555 cpu_interrupt(cpu_single_env
, CPU_INTERRUPT_EXIT
);
3558 void qemu_system_powerdown_request(void)
3560 powerdown_requested
= 1;
3562 cpu_interrupt(cpu_single_env
, CPU_INTERRUPT_EXIT
);
3566 static void host_main_loop_wait(int *timeout
)
3572 /* XXX: need to suppress polling by better using win32 events */
3574 for(pe
= first_polling_entry
; pe
!= NULL
; pe
= pe
->next
) {
3575 ret
|= pe
->func(pe
->opaque
);
3579 WaitObjects
*w
= &wait_objects
;
3581 ret
= WaitForMultipleObjects(w
->num
, w
->events
, FALSE
, *timeout
);
3582 if (WAIT_OBJECT_0
+ 0 <= ret
&& ret
<= WAIT_OBJECT_0
+ w
->num
- 1) {
3583 if (w
->func
[ret
- WAIT_OBJECT_0
])
3584 w
->func
[ret
- WAIT_OBJECT_0
](w
->opaque
[ret
- WAIT_OBJECT_0
]);
3586 /* Check for additional signaled events */
3587 for(i
= (ret
- WAIT_OBJECT_0
+ 1); i
< w
->num
; i
++) {
3589 /* Check if event is signaled */
3590 ret2
= WaitForSingleObject(w
->events
[i
], 0);
3591 if(ret2
== WAIT_OBJECT_0
) {
3593 w
->func
[i
](w
->opaque
[i
]);
3594 } else if (ret2
== WAIT_TIMEOUT
) {
3596 err
= GetLastError();
3597 fprintf(stderr
, "WaitForSingleObject error %d %d\n", i
, err
);
3600 } else if (ret
== WAIT_TIMEOUT
) {
3602 err
= GetLastError();
3603 fprintf(stderr
, "WaitForMultipleObjects error %d %d\n", ret
, err
);
3610 static void host_main_loop_wait(int *timeout
)
3615 void main_loop_wait(int timeout
)
3617 IOHandlerRecord
*ioh
;
3618 fd_set rfds
, wfds
, xfds
;
3622 qemu_bh_update_timeout(&timeout
);
3624 host_main_loop_wait(&timeout
);
3626 /* poll any events */
3627 /* XXX: separate device handlers from system ones */
3632 for(ioh
= first_io_handler
; ioh
!= NULL
; ioh
= ioh
->next
) {
3636 (!ioh
->fd_read_poll
||
3637 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
3638 FD_SET(ioh
->fd
, &rfds
);
3642 if (ioh
->fd_write
) {
3643 FD_SET(ioh
->fd
, &wfds
);
3649 tv
.tv_sec
= timeout
/ 1000;
3650 tv
.tv_usec
= (timeout
% 1000) * 1000;
3652 #if defined(CONFIG_SLIRP)
3653 if (slirp_is_inited()) {
3654 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
3657 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
3659 IOHandlerRecord
**pioh
;
3661 for(ioh
= first_io_handler
; ioh
!= NULL
; ioh
= ioh
->next
) {
3662 if (!ioh
->deleted
&& ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
3663 ioh
->fd_read(ioh
->opaque
);
3665 if (!ioh
->deleted
&& ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
3666 ioh
->fd_write(ioh
->opaque
);
3670 /* remove deleted IO handlers */
3671 pioh
= &first_io_handler
;
3681 #if defined(CONFIG_SLIRP)
3682 if (slirp_is_inited()) {
3688 slirp_select_poll(&rfds
, &wfds
, &xfds
);
3692 /* vm time timers */
3693 if (vm_running
&& likely(!(cur_cpu
->singlestep_enabled
& SSTEP_NOTIMER
)))
3694 qemu_run_timers(&active_timers
[QEMU_TIMER_VIRTUAL
],
3695 qemu_get_clock(vm_clock
));
3697 /* real time timers */
3698 qemu_run_timers(&active_timers
[QEMU_TIMER_REALTIME
],
3699 qemu_get_clock(rt_clock
));
3701 /* Check bottom-halves last in case any of the earlier events triggered
3707 static int main_loop(void)
3710 #ifdef CONFIG_PROFILER
3715 cur_cpu
= first_cpu
;
3716 next_cpu
= cur_cpu
->next_cpu
?: first_cpu
;
3723 #ifdef CONFIG_PROFILER
3724 ti
= profile_getclock();
3729 qemu_icount
-= (env
->icount_decr
.u16
.low
+ env
->icount_extra
);
3730 env
->icount_decr
.u16
.low
= 0;
3731 env
->icount_extra
= 0;
3732 count
= qemu_next_deadline();
3733 count
= (count
+ (1 << icount_time_shift
) - 1)
3734 >> icount_time_shift
;
3735 qemu_icount
+= count
;
3736 decr
= (count
> 0xffff) ? 0xffff : count
;
3738 env
->icount_decr
.u16
.low
= decr
;
3739 env
->icount_extra
= count
;
3741 ret
= cpu_exec(env
);
3742 #ifdef CONFIG_PROFILER
3743 qemu_time
+= profile_getclock() - ti
;
3746 /* Fold pending instructions back into the
3747 instruction counter, and clear the interrupt flag. */
3748 qemu_icount
-= (env
->icount_decr
.u16
.low
3749 + env
->icount_extra
);
3750 env
->icount_decr
.u32
= 0;
3751 env
->icount_extra
= 0;
3753 next_cpu
= env
->next_cpu
?: first_cpu
;
3754 if (event_pending
&& likely(ret
!= EXCP_DEBUG
)) {
3755 ret
= EXCP_INTERRUPT
;
3759 if (ret
== EXCP_HLT
) {
3760 /* Give the next CPU a chance to run. */
3764 if (ret
!= EXCP_HALTED
)
3766 /* all CPUs are halted ? */
3772 if (shutdown_requested
) {
3773 ret
= EXCP_INTERRUPT
;
3781 if (reset_requested
) {
3782 reset_requested
= 0;
3783 qemu_system_reset();
3784 ret
= EXCP_INTERRUPT
;
3786 if (powerdown_requested
) {
3787 powerdown_requested
= 0;
3788 qemu_system_powerdown();
3789 ret
= EXCP_INTERRUPT
;
3791 if (unlikely(ret
== EXCP_DEBUG
)) {
3792 gdb_set_stop_cpu(cur_cpu
);
3793 vm_stop(EXCP_DEBUG
);
3795 /* If all cpus are halted then wait until the next IRQ */
3796 /* XXX: use timeout computed from timers */
3797 if (ret
== EXCP_HALTED
) {
3801 /* Advance virtual time to the next event. */
3802 if (use_icount
== 1) {
3803 /* When not using an adaptive execution frequency
3804 we tend to get badly out of sync with real time,
3805 so just delay for a reasonable amount of time. */
3808 delta
= cpu_get_icount() - cpu_get_clock();
3811 /* If virtual time is ahead of real time then just
3813 timeout
= (delta
/ 1000000) + 1;
3815 /* Wait for either IO to occur or the next
3817 add
= qemu_next_deadline();
3818 /* We advance the timer before checking for IO.
3819 Limit the amount we advance so that early IO
3820 activity won't get the guest too far ahead. */
3824 add
= (add
+ (1 << icount_time_shift
) - 1)
3825 >> icount_time_shift
;
3827 timeout
= delta
/ 1000000;
3838 if (shutdown_requested
) {
3839 ret
= EXCP_INTERRUPT
;
3844 #ifdef CONFIG_PROFILER
3845 ti
= profile_getclock();
3847 main_loop_wait(timeout
);
3848 #ifdef CONFIG_PROFILER
3849 dev_time
+= profile_getclock() - ti
;
3852 cpu_disable_ticks();
3856 static void help(int exitcode
)
3858 printf("QEMU PC emulator version " QEMU_VERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n"
3859 "usage: %s [options] [disk_image]\n"
3861 "'disk_image' is a raw hard image image for IDE hard disk 0\n"
3863 "Standard options:\n"
3864 "-M machine select emulated machine (-M ? for list)\n"
3865 "-cpu cpu select CPU (-cpu ? for list)\n"
3866 "-fda/-fdb file use 'file' as floppy disk 0/1 image\n"
3867 "-hda/-hdb file use 'file' as IDE hard disk 0/1 image\n"
3868 "-hdc/-hdd file use 'file' as IDE hard disk 2/3 image\n"
3869 "-cdrom file use 'file' as IDE cdrom image (cdrom is ide1 master)\n"
3870 "-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n"
3871 " [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n"
3872 " [,cache=writethrough|writeback|none][,format=f][,serial=s]\n"
3873 " use 'file' as a drive image\n"
3874 "-mtdblock file use 'file' as on-board Flash memory image\n"
3875 "-sd file use 'file' as SecureDigital card image\n"
3876 "-pflash file use 'file' as a parallel flash image\n"
3877 "-boot [a|c|d|n] boot on floppy (a), hard disk (c), CD-ROM (d), or network (n)\n"
3878 "-snapshot write to temporary files instead of disk image files\n"
3880 "-no-frame open SDL window without a frame and window decorations\n"
3881 "-alt-grab use Ctrl-Alt-Shift to grab mouse (instead of Ctrl-Alt)\n"
3882 "-no-quit disable SDL window close capability\n"
3886 "-no-fd-bootchk disable boot signature checking for floppy disks\n"
3888 "-m megs set virtual RAM size to megs MB [default=%d]\n"
3889 "-smp n set the number of CPUs to 'n' [default=1]\n"
3890 "-nographic disable graphical output and redirect serial I/Os to console\n"
3891 "-portrait rotate graphical output 90 deg left (only PXA LCD)\n"
3893 "-k language use keyboard layout (for example \"fr\" for French)\n"
3896 "-audio-help print list of audio drivers and their options\n"
3897 "-soundhw c1,... enable audio support\n"
3898 " and only specified sound cards (comma separated list)\n"
3899 " use -soundhw ? to get the list of supported cards\n"
3900 " use -soundhw all to enable all of them\n"
3902 "-vga [std|cirrus|vmware|none]\n"
3903 " select video card type\n"
3904 "-localtime set the real time clock to local time [default=utc]\n"
3905 "-full-screen start in full screen\n"
3907 "-win2k-hack use it when installing Windows 2000 to avoid a disk full bug\n"
3908 "-rtc-td-hack use it to fix time drift in Windows ACPI HAL\n"
3910 "-usb enable the USB driver (will be the default soon)\n"
3911 "-usbdevice name add the host or guest USB device 'name'\n"
3912 #if defined(TARGET_PPC) || defined(TARGET_SPARC)
3913 "-g WxH[xDEPTH] Set the initial graphical resolution and depth\n"
3915 "-name string set the name of the guest\n"
3916 "-uuid %%08x-%%04x-%%04x-%%04x-%%012x specify machine UUID\n"
3918 "Network options:\n"
3919 "-net nic[,vlan=n][,macaddr=addr][,model=type][,name=str]\n"
3920 " create a new Network Interface Card and connect it to VLAN 'n'\n"
3922 "-net user[,vlan=n][,name=str][,hostname=host]\n"
3923 " connect the user mode network stack to VLAN 'n' and send\n"
3924 " hostname 'host' to DHCP clients\n"
3927 "-net tap[,vlan=n][,name=str],ifname=name\n"
3928 " connect the host TAP network interface to VLAN 'n'\n"
3930 "-net tap[,vlan=n][,name=str][,fd=h][,ifname=name][,script=file][,downscript=dfile]\n"
3931 " connect the host TAP network interface to VLAN 'n' and use the\n"
3932 " network scripts 'file' (default=%s)\n"
3933 " and 'dfile' (default=%s);\n"
3934 " use '[down]script=no' to disable script execution;\n"
3935 " use 'fd=h' to connect to an already opened TAP interface\n"
3937 "-net socket[,vlan=n][,name=str][,fd=h][,listen=[host]:port][,connect=host:port]\n"
3938 " connect the vlan 'n' to another VLAN using a socket connection\n"
3939 "-net socket[,vlan=n][,name=str][,fd=h][,mcast=maddr:port]\n"
3940 " connect the vlan 'n' to multicast maddr and port\n"
3942 "-net vde[,vlan=n][,name=str][,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]\n"
3943 " connect the vlan 'n' to port 'n' of a vde switch running\n"
3944 " on host and listening for incoming connections on 'socketpath'.\n"
3945 " Use group 'groupname' and mode 'octalmode' to change default\n"
3946 " ownership and permissions for communication port.\n"
3948 "-net none use it alone to have zero network devices; if no -net option\n"
3949 " is provided, the default is '-net nic -net user'\n"
3951 "-bt hci,null Dumb bluetooth HCI - doesn't respond to commands\n"
3952 "-bt hci,host[:id]\n"
3953 " Use host's HCI with the given name\n"
3954 "-bt hci[,vlan=n]\n"
3955 " Emulate a standard HCI in virtual scatternet 'n'\n"
3956 "-bt vhci[,vlan=n]\n"
3957 " Add host computer to virtual scatternet 'n' using VHCI\n"
3958 "-bt device:dev[,vlan=n]\n"
3959 " Emulate a bluetooth device 'dev' in scatternet 'n'\n"
3962 "-tftp dir allow tftp access to files in dir [-net user]\n"
3963 "-bootp file advertise file in BOOTP replies\n"
3965 "-smb dir allow SMB access to files in 'dir' [-net user]\n"
3967 "-redir [tcp|udp]:host-port:[guest-host]:guest-port\n"
3968 " redirect TCP or UDP connections from host to guest [-net user]\n"
3971 "Linux boot specific:\n"
3972 "-kernel bzImage use 'bzImage' as kernel image\n"
3973 "-append cmdline use 'cmdline' as kernel command line\n"
3974 "-initrd file use 'file' as initial ram disk\n"
3976 "Debug/Expert options:\n"
3977 "-monitor dev redirect the monitor to char device 'dev'\n"
3978 "-serial dev redirect the serial port to char device 'dev'\n"
3979 "-parallel dev redirect the parallel port to char device 'dev'\n"
3980 "-pidfile file Write PID to 'file'\n"
3981 "-S freeze CPU at startup (use 'c' to start execution)\n"
3982 "-s wait gdb connection to port\n"
3983 "-p port set gdb connection port [default=%s]\n"
3984 "-d item1,... output log to %s (use -d ? for a list of log items)\n"
3985 "-hdachs c,h,s[,t] force hard disk 0 physical geometry and the optional BIOS\n"
3986 " translation (t=none or lba) (usually qemu can guess them)\n"
3987 "-L path set the directory for the BIOS, VGA BIOS and keymaps\n"
3989 "-kernel-kqemu enable KQEMU full virtualization (default is user mode only)\n"
3990 "-no-kqemu disable KQEMU kernel module usage\n"
3993 "-enable-kvm enable KVM full virtualization support\n"
3996 "-no-acpi disable ACPI\n"
3997 "-no-hpet disable HPET\n"
3999 #ifdef CONFIG_CURSES
4000 "-curses use a curses/ncurses interface instead of SDL\n"
4002 "-no-reboot exit instead of rebooting\n"
4003 "-no-shutdown stop before shutdown\n"
4004 "-loadvm [tag|id] start right away with a saved state (loadvm in monitor)\n"
4005 "-vnc display start a VNC server on display\n"
4007 "-daemonize daemonize QEMU after initializing\n"
4009 "-option-rom rom load a file, rom, into the option ROM space\n"
4011 "-prom-env variable=value set OpenBIOS nvram variables\n"
4013 "-clock force the use of the given methods for timer alarm.\n"
4014 " To see what timers are available use -clock ?\n"
4015 "-startdate select initial date of the clock\n"
4016 "-icount [N|auto]\n"
4017 " Enable virtual instruction counter with 2^N clock ticks per instruction\n"
4019 "During emulation, the following keys are useful:\n"
4020 "ctrl-alt-f toggle full screen\n"
4021 "ctrl-alt-n switch to virtual console 'n'\n"
4022 "ctrl-alt toggle mouse and keyboard grab\n"
4024 "When using -nographic, press 'ctrl-a h' to get some help.\n"
4029 DEFAULT_NETWORK_SCRIPT
,
4030 DEFAULT_NETWORK_DOWN_SCRIPT
,
4032 DEFAULT_GDBSTUB_PORT
,
4037 #define HAS_ARG 0x0001
4052 QEMU_OPTION_mtdblock
,
4056 QEMU_OPTION_snapshot
,
4058 QEMU_OPTION_no_fd_bootchk
,
4061 QEMU_OPTION_nographic
,
4062 QEMU_OPTION_portrait
,
4064 QEMU_OPTION_audio_help
,
4065 QEMU_OPTION_soundhw
,
4087 QEMU_OPTION_localtime
,
4091 QEMU_OPTION_monitor
,
4093 QEMU_OPTION_virtiocon
,
4094 QEMU_OPTION_parallel
,
4096 QEMU_OPTION_full_screen
,
4097 QEMU_OPTION_no_frame
,
4098 QEMU_OPTION_alt_grab
,
4099 QEMU_OPTION_no_quit
,
4101 QEMU_OPTION_pidfile
,
4102 QEMU_OPTION_no_kqemu
,
4103 QEMU_OPTION_kernel_kqemu
,
4104 QEMU_OPTION_enable_kvm
,
4105 QEMU_OPTION_win2k_hack
,
4106 QEMU_OPTION_rtc_td_hack
,
4108 QEMU_OPTION_usbdevice
,
4111 QEMU_OPTION_no_acpi
,
4112 QEMU_OPTION_no_hpet
,
4114 QEMU_OPTION_no_reboot
,
4115 QEMU_OPTION_no_shutdown
,
4116 QEMU_OPTION_show_cursor
,
4117 QEMU_OPTION_daemonize
,
4118 QEMU_OPTION_option_rom
,
4119 QEMU_OPTION_semihosting
,
4121 QEMU_OPTION_prom_env
,
4122 QEMU_OPTION_old_param
,
4124 QEMU_OPTION_startdate
,
4125 QEMU_OPTION_tb_size
,
4128 QEMU_OPTION_incoming
,
4131 typedef struct QEMUOption
{
4137 static const QEMUOption qemu_options
[] = {
4138 { "h", 0, QEMU_OPTION_h
},
4139 { "help", 0, QEMU_OPTION_h
},
4141 { "M", HAS_ARG
, QEMU_OPTION_M
},
4142 { "cpu", HAS_ARG
, QEMU_OPTION_cpu
},
4143 { "fda", HAS_ARG
, QEMU_OPTION_fda
},
4144 { "fdb", HAS_ARG
, QEMU_OPTION_fdb
},
4145 { "hda", HAS_ARG
, QEMU_OPTION_hda
},
4146 { "hdb", HAS_ARG
, QEMU_OPTION_hdb
},
4147 { "hdc", HAS_ARG
, QEMU_OPTION_hdc
},
4148 { "hdd", HAS_ARG
, QEMU_OPTION_hdd
},
4149 { "drive", HAS_ARG
, QEMU_OPTION_drive
},
4150 { "cdrom", HAS_ARG
, QEMU_OPTION_cdrom
},
4151 { "mtdblock", HAS_ARG
, QEMU_OPTION_mtdblock
},
4152 { "sd", HAS_ARG
, QEMU_OPTION_sd
},
4153 { "pflash", HAS_ARG
, QEMU_OPTION_pflash
},
4154 { "boot", HAS_ARG
, QEMU_OPTION_boot
},
4155 { "snapshot", 0, QEMU_OPTION_snapshot
},
4157 { "no-fd-bootchk", 0, QEMU_OPTION_no_fd_bootchk
},
4159 { "m", HAS_ARG
, QEMU_OPTION_m
},
4160 { "nographic", 0, QEMU_OPTION_nographic
},
4161 { "portrait", 0, QEMU_OPTION_portrait
},
4162 { "k", HAS_ARG
, QEMU_OPTION_k
},
4164 { "audio-help", 0, QEMU_OPTION_audio_help
},
4165 { "soundhw", HAS_ARG
, QEMU_OPTION_soundhw
},
4168 { "net", HAS_ARG
, QEMU_OPTION_net
},
4170 { "tftp", HAS_ARG
, QEMU_OPTION_tftp
},
4171 { "bootp", HAS_ARG
, QEMU_OPTION_bootp
},
4173 { "smb", HAS_ARG
, QEMU_OPTION_smb
},
4175 { "redir", HAS_ARG
, QEMU_OPTION_redir
},
4177 { "bt", HAS_ARG
, QEMU_OPTION_bt
},
4179 { "kernel", HAS_ARG
, QEMU_OPTION_kernel
},
4180 { "append", HAS_ARG
, QEMU_OPTION_append
},
4181 { "initrd", HAS_ARG
, QEMU_OPTION_initrd
},
4183 { "S", 0, QEMU_OPTION_S
},
4184 { "s", 0, QEMU_OPTION_s
},
4185 { "p", HAS_ARG
, QEMU_OPTION_p
},
4186 { "d", HAS_ARG
, QEMU_OPTION_d
},
4187 { "hdachs", HAS_ARG
, QEMU_OPTION_hdachs
},
4188 { "L", HAS_ARG
, QEMU_OPTION_L
},
4189 { "bios", HAS_ARG
, QEMU_OPTION_bios
},
4191 { "no-kqemu", 0, QEMU_OPTION_no_kqemu
},
4192 { "kernel-kqemu", 0, QEMU_OPTION_kernel_kqemu
},
4195 { "enable-kvm", 0, QEMU_OPTION_enable_kvm
},
4197 #if defined(TARGET_PPC) || defined(TARGET_SPARC)
4198 { "g", 1, QEMU_OPTION_g
},
4200 { "localtime", 0, QEMU_OPTION_localtime
},
4201 { "vga", HAS_ARG
, QEMU_OPTION_vga
},
4202 { "echr", HAS_ARG
, QEMU_OPTION_echr
},
4203 { "monitor", HAS_ARG
, QEMU_OPTION_monitor
},
4204 { "serial", HAS_ARG
, QEMU_OPTION_serial
},
4205 { "virtioconsole", HAS_ARG
, QEMU_OPTION_virtiocon
},
4206 { "parallel", HAS_ARG
, QEMU_OPTION_parallel
},
4207 { "loadvm", HAS_ARG
, QEMU_OPTION_loadvm
},
4208 { "full-screen", 0, QEMU_OPTION_full_screen
},
4210 { "no-frame", 0, QEMU_OPTION_no_frame
},
4211 { "alt-grab", 0, QEMU_OPTION_alt_grab
},
4212 { "no-quit", 0, QEMU_OPTION_no_quit
},
4213 { "sdl", 0, QEMU_OPTION_sdl
},
4215 { "pidfile", HAS_ARG
, QEMU_OPTION_pidfile
},
4216 { "win2k-hack", 0, QEMU_OPTION_win2k_hack
},
4217 { "rtc-td-hack", 0, QEMU_OPTION_rtc_td_hack
},
4218 { "usbdevice", HAS_ARG
, QEMU_OPTION_usbdevice
},
4219 { "smp", HAS_ARG
, QEMU_OPTION_smp
},
4220 { "vnc", HAS_ARG
, QEMU_OPTION_vnc
},
4221 #ifdef CONFIG_CURSES
4222 { "curses", 0, QEMU_OPTION_curses
},
4224 { "uuid", HAS_ARG
, QEMU_OPTION_uuid
},
4226 /* temporary options */
4227 { "usb", 0, QEMU_OPTION_usb
},
4228 { "no-acpi", 0, QEMU_OPTION_no_acpi
},
4229 { "no-hpet", 0, QEMU_OPTION_no_hpet
},
4230 { "no-reboot", 0, QEMU_OPTION_no_reboot
},
4231 { "no-shutdown", 0, QEMU_OPTION_no_shutdown
},
4232 { "show-cursor", 0, QEMU_OPTION_show_cursor
},
4233 { "daemonize", 0, QEMU_OPTION_daemonize
},
4234 { "option-rom", HAS_ARG
, QEMU_OPTION_option_rom
},
4235 #if defined(TARGET_ARM) || defined(TARGET_M68K)
4236 { "semihosting", 0, QEMU_OPTION_semihosting
},
4238 { "name", HAS_ARG
, QEMU_OPTION_name
},
4239 #if defined(TARGET_SPARC) || defined(TARGET_PPC)
4240 { "prom-env", HAS_ARG
, QEMU_OPTION_prom_env
},
4242 #if defined(TARGET_ARM)
4243 { "old-param", 0, QEMU_OPTION_old_param
},
4245 { "clock", HAS_ARG
, QEMU_OPTION_clock
},
4246 { "startdate", HAS_ARG
, QEMU_OPTION_startdate
},
4247 { "tb-size", HAS_ARG
, QEMU_OPTION_tb_size
},
4248 { "icount", HAS_ARG
, QEMU_OPTION_icount
},
4249 { "incoming", HAS_ARG
, QEMU_OPTION_incoming
},
4253 /* password input */
4255 int qemu_key_check(BlockDriverState
*bs
, const char *name
)
4260 if (!bdrv_is_encrypted(bs
))
4263 term_printf("%s is encrypted.\n", name
);
4264 for(i
= 0; i
< 3; i
++) {
4265 monitor_readline("Password: ", 1, password
, sizeof(password
));
4266 if (bdrv_set_key(bs
, password
) == 0)
4268 term_printf("invalid password\n");
4273 static BlockDriverState
*get_bdrv(int index
)
4275 if (index
> nb_drives
)
4277 return drives_table
[index
].bdrv
;
4280 static void read_passwords(void)
4282 BlockDriverState
*bs
;
4285 for(i
= 0; i
< 6; i
++) {
4288 qemu_key_check(bs
, bdrv_get_device_name(bs
));
4293 struct soundhw soundhw
[] = {
4294 #ifdef HAS_AUDIO_CHOICE
4295 #if defined(TARGET_I386) || defined(TARGET_MIPS)
4301 { .init_isa
= pcspk_audio_init
}
4308 "Creative Sound Blaster 16",
4311 { .init_isa
= SB16_init
}
4315 #ifdef CONFIG_CS4231A
4321 { .init_isa
= cs4231a_init
}
4329 "Yamaha YMF262 (OPL3)",
4331 "Yamaha YM3812 (OPL2)",
4335 { .init_isa
= Adlib_init
}
4342 "Gravis Ultrasound GF1",
4345 { .init_isa
= GUS_init
}
4352 "Intel 82801AA AC97 Audio",
4355 { .init_pci
= ac97_init
}
4359 #ifdef CONFIG_ES1370
4362 "ENSONIQ AudioPCI ES1370",
4365 { .init_pci
= es1370_init
}
4369 #endif /* HAS_AUDIO_CHOICE */
4371 { NULL
, NULL
, 0, 0, { NULL
} }
4374 static void select_soundhw (const char *optarg
)
4378 if (*optarg
== '?') {
4381 printf ("Valid sound card names (comma separated):\n");
4382 for (c
= soundhw
; c
->name
; ++c
) {
4383 printf ("%-11s %s\n", c
->name
, c
->descr
);
4385 printf ("\n-soundhw all will enable all of the above\n");
4386 exit (*optarg
!= '?');
4394 if (!strcmp (optarg
, "all")) {
4395 for (c
= soundhw
; c
->name
; ++c
) {
4403 e
= strchr (p
, ',');
4404 l
= !e
? strlen (p
) : (size_t) (e
- p
);
4406 for (c
= soundhw
; c
->name
; ++c
) {
4407 if (!strncmp (c
->name
, p
, l
)) {
4416 "Unknown sound card name (too big to show)\n");
4419 fprintf (stderr
, "Unknown sound card name `%.*s'\n",
4424 p
+= l
+ (e
!= NULL
);
4428 goto show_valid_cards
;
4433 static void select_vgahw (const char *p
)
4437 if (strstart(p
, "std", &opts
)) {
4438 std_vga_enabled
= 1;
4439 cirrus_vga_enabled
= 0;
4441 } else if (strstart(p
, "cirrus", &opts
)) {
4442 cirrus_vga_enabled
= 1;
4443 std_vga_enabled
= 0;
4445 } else if (strstart(p
, "vmware", &opts
)) {
4446 cirrus_vga_enabled
= 0;
4447 std_vga_enabled
= 0;
4449 } else if (strstart(p
, "none", &opts
)) {
4450 cirrus_vga_enabled
= 0;
4451 std_vga_enabled
= 0;
4455 fprintf(stderr
, "Unknown vga type: %s\n", p
);
4459 const char *nextopt
;
4461 if (strstart(opts
, ",retrace=", &nextopt
)) {
4463 if (strstart(opts
, "dumb", &nextopt
))
4464 vga_retrace_method
= VGA_RETRACE_DUMB
;
4465 else if (strstart(opts
, "precise", &nextopt
))
4466 vga_retrace_method
= VGA_RETRACE_PRECISE
;
4467 else goto invalid_vga
;
4468 } else goto invalid_vga
;
4474 static BOOL WINAPI
qemu_ctrl_handler(DWORD type
)
4476 exit(STATUS_CONTROL_C_EXIT
);
4481 static int qemu_uuid_parse(const char *str
, uint8_t *uuid
)
4485 if(strlen(str
) != 36)
4488 ret
= sscanf(str
, UUID_FMT
, &uuid
[0], &uuid
[1], &uuid
[2], &uuid
[3],
4489 &uuid
[4], &uuid
[5], &uuid
[6], &uuid
[7], &uuid
[8], &uuid
[9],
4490 &uuid
[10], &uuid
[11], &uuid
[12], &uuid
[13], &uuid
[14], &uuid
[15]);
4498 #define MAX_NET_CLIENTS 32
4502 static void termsig_handler(int signal
)
4504 qemu_system_shutdown_request();
4507 static void termsig_setup(void)
4509 struct sigaction act
;
4511 memset(&act
, 0, sizeof(act
));
4512 act
.sa_handler
= termsig_handler
;
4513 sigaction(SIGINT
, &act
, NULL
);
4514 sigaction(SIGHUP
, &act
, NULL
);
4515 sigaction(SIGTERM
, &act
, NULL
);
4520 int main(int argc
, char **argv
, char **envp
)
4522 #ifdef CONFIG_GDBSTUB
4524 const char *gdbstub_port
;
4526 uint32_t boot_devices_bitmap
= 0;
4528 int snapshot
, linux_boot
, net_boot
;
4529 const char *initrd_filename
;
4530 const char *kernel_filename
, *kernel_cmdline
;
4531 const char *boot_devices
= "";
4533 DisplayChangeListener
*dcl
;
4534 int cyls
, heads
, secs
, translation
;
4535 const char *net_clients
[MAX_NET_CLIENTS
];
4537 const char *bt_opts
[MAX_BT_CMDLINE
];
4541 const char *r
, *optarg
;
4542 CharDriverState
*monitor_hd
= NULL
;
4543 const char *monitor_device
;
4544 const char *serial_devices
[MAX_SERIAL_PORTS
];
4545 int serial_device_index
;
4546 const char *parallel_devices
[MAX_PARALLEL_PORTS
];
4547 int parallel_device_index
;
4548 const char *virtio_consoles
[MAX_VIRTIO_CONSOLES
];
4549 int virtio_console_index
;
4550 const char *loadvm
= NULL
;
4551 QEMUMachine
*machine
;
4552 const char *cpu_model
;
4553 const char *usb_devices
[MAX_USB_CMDLINE
];
4554 int usb_devices_index
;
4557 const char *pid_file
= NULL
;
4559 const char *incoming
= NULL
;
4561 qemu_cache_utils_init(envp
);
4563 LIST_INIT (&vm_change_state_head
);
4566 struct sigaction act
;
4567 sigfillset(&act
.sa_mask
);
4569 act
.sa_handler
= SIG_IGN
;
4570 sigaction(SIGPIPE
, &act
, NULL
);
4573 SetConsoleCtrlHandler(qemu_ctrl_handler
, TRUE
);
4574 /* Note: cpu_interrupt() is currently not SMP safe, so we force
4575 QEMU to run on a single CPU */
4580 h
= GetCurrentProcess();
4581 if (GetProcessAffinityMask(h
, &mask
, &smask
)) {
4582 for(i
= 0; i
< 32; i
++) {
4583 if (mask
& (1 << i
))
4588 SetProcessAffinityMask(h
, mask
);
4594 register_machines();
4595 machine
= first_machine
;
4597 initrd_filename
= NULL
;
4599 vga_ram_size
= VGA_RAM_SIZE
;
4600 #ifdef CONFIG_GDBSTUB
4602 gdbstub_port
= DEFAULT_GDBSTUB_PORT
;
4607 kernel_filename
= NULL
;
4608 kernel_cmdline
= "";
4609 cyls
= heads
= secs
= 0;
4610 translation
= BIOS_ATA_TRANSLATION_AUTO
;
4611 monitor_device
= "vc";
4613 serial_devices
[0] = "vc:80Cx24C";
4614 for(i
= 1; i
< MAX_SERIAL_PORTS
; i
++)
4615 serial_devices
[i
] = NULL
;
4616 serial_device_index
= 0;
4618 parallel_devices
[0] = "vc:640x480";
4619 for(i
= 1; i
< MAX_PARALLEL_PORTS
; i
++)
4620 parallel_devices
[i
] = NULL
;
4621 parallel_device_index
= 0;
4623 virtio_consoles
[0] = "vc:80Cx24C";
4624 for(i
= 1; i
< MAX_VIRTIO_CONSOLES
; i
++)
4625 virtio_consoles
[i
] = NULL
;
4626 virtio_console_index
= 0;
4628 usb_devices_index
= 0;
4647 hda_index
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
4649 const QEMUOption
*popt
;
4652 /* Treat --foo the same as -foo. */
4655 popt
= qemu_options
;
4658 fprintf(stderr
, "%s: invalid option -- '%s'\n",
4662 if (!strcmp(popt
->name
, r
+ 1))
4666 if (popt
->flags
& HAS_ARG
) {
4667 if (optind
>= argc
) {
4668 fprintf(stderr
, "%s: option '%s' requires an argument\n",
4672 optarg
= argv
[optind
++];
4677 switch(popt
->index
) {
4679 machine
= find_machine(optarg
);
4682 printf("Supported machines are:\n");
4683 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
4684 printf("%-10s %s%s\n",
4686 m
== first_machine
? " (default)" : "");
4688 exit(*optarg
!= '?');
4691 case QEMU_OPTION_cpu
:
4692 /* hw initialization will check this */
4693 if (*optarg
== '?') {
4694 /* XXX: implement xxx_cpu_list for targets that still miss it */
4695 #if defined(cpu_list)
4696 cpu_list(stdout
, &fprintf
);
4703 case QEMU_OPTION_initrd
:
4704 initrd_filename
= optarg
;
4706 case QEMU_OPTION_hda
:
4708 hda_index
= drive_add(optarg
, HD_ALIAS
, 0);
4710 hda_index
= drive_add(optarg
, HD_ALIAS
4711 ",cyls=%d,heads=%d,secs=%d%s",
4712 0, cyls
, heads
, secs
,
4713 translation
== BIOS_ATA_TRANSLATION_LBA
?
4715 translation
== BIOS_ATA_TRANSLATION_NONE
?
4716 ",trans=none" : "");
4718 case QEMU_OPTION_hdb
:
4719 case QEMU_OPTION_hdc
:
4720 case QEMU_OPTION_hdd
:
4721 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
4723 case QEMU_OPTION_drive
:
4724 drive_add(NULL
, "%s", optarg
);
4726 case QEMU_OPTION_mtdblock
:
4727 drive_add(optarg
, MTD_ALIAS
);
4729 case QEMU_OPTION_sd
:
4730 drive_add(optarg
, SD_ALIAS
);
4732 case QEMU_OPTION_pflash
:
4733 drive_add(optarg
, PFLASH_ALIAS
);
4735 case QEMU_OPTION_snapshot
:
4738 case QEMU_OPTION_hdachs
:
4742 cyls
= strtol(p
, (char **)&p
, 0);
4743 if (cyls
< 1 || cyls
> 16383)
4748 heads
= strtol(p
, (char **)&p
, 0);
4749 if (heads
< 1 || heads
> 16)
4754 secs
= strtol(p
, (char **)&p
, 0);
4755 if (secs
< 1 || secs
> 63)
4759 if (!strcmp(p
, "none"))
4760 translation
= BIOS_ATA_TRANSLATION_NONE
;
4761 else if (!strcmp(p
, "lba"))
4762 translation
= BIOS_ATA_TRANSLATION_LBA
;
4763 else if (!strcmp(p
, "auto"))
4764 translation
= BIOS_ATA_TRANSLATION_AUTO
;
4767 } else if (*p
!= '\0') {
4769 fprintf(stderr
, "qemu: invalid physical CHS format\n");
4772 if (hda_index
!= -1)
4773 snprintf(drives_opt
[hda_index
].opt
,
4774 sizeof(drives_opt
[hda_index
].opt
),
4775 HD_ALIAS
",cyls=%d,heads=%d,secs=%d%s",
4776 0, cyls
, heads
, secs
,
4777 translation
== BIOS_ATA_TRANSLATION_LBA
?
4779 translation
== BIOS_ATA_TRANSLATION_NONE
?
4780 ",trans=none" : "");
4783 case QEMU_OPTION_nographic
:
4786 #ifdef CONFIG_CURSES
4787 case QEMU_OPTION_curses
:
4791 case QEMU_OPTION_portrait
:
4794 case QEMU_OPTION_kernel
:
4795 kernel_filename
= optarg
;
4797 case QEMU_OPTION_append
:
4798 kernel_cmdline
= optarg
;
4800 case QEMU_OPTION_cdrom
:
4801 drive_add(optarg
, CDROM_ALIAS
);
4803 case QEMU_OPTION_boot
:
4804 boot_devices
= optarg
;
4805 /* We just do some generic consistency checks */
4807 /* Could easily be extended to 64 devices if needed */
4810 boot_devices_bitmap
= 0;
4811 for (p
= boot_devices
; *p
!= '\0'; p
++) {
4812 /* Allowed boot devices are:
4813 * a b : floppy disk drives
4814 * c ... f : IDE disk drives
4815 * g ... m : machine implementation dependant drives
4816 * n ... p : network devices
4817 * It's up to each machine implementation to check
4818 * if the given boot devices match the actual hardware
4819 * implementation and firmware features.
4821 if (*p
< 'a' || *p
> 'q') {
4822 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
4825 if (boot_devices_bitmap
& (1 << (*p
- 'a'))) {
4827 "Boot device '%c' was given twice\n",*p
);
4830 boot_devices_bitmap
|= 1 << (*p
- 'a');
4834 case QEMU_OPTION_fda
:
4835 case QEMU_OPTION_fdb
:
4836 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
4839 case QEMU_OPTION_no_fd_bootchk
:
4843 case QEMU_OPTION_net
:
4844 if (nb_net_clients
>= MAX_NET_CLIENTS
) {
4845 fprintf(stderr
, "qemu: too many network clients\n");
4848 net_clients
[nb_net_clients
] = optarg
;
4852 case QEMU_OPTION_tftp
:
4853 tftp_prefix
= optarg
;
4855 case QEMU_OPTION_bootp
:
4856 bootp_filename
= optarg
;
4859 case QEMU_OPTION_smb
:
4860 net_slirp_smb(optarg
);
4863 case QEMU_OPTION_redir
:
4864 net_slirp_redir(optarg
);
4867 case QEMU_OPTION_bt
:
4868 if (nb_bt_opts
>= MAX_BT_CMDLINE
) {
4869 fprintf(stderr
, "qemu: too many bluetooth options\n");
4872 bt_opts
[nb_bt_opts
++] = optarg
;
4875 case QEMU_OPTION_audio_help
:
4879 case QEMU_OPTION_soundhw
:
4880 select_soundhw (optarg
);
4886 case QEMU_OPTION_m
: {
4890 value
= strtoul(optarg
, &ptr
, 10);
4892 case 0: case 'M': case 'm':
4899 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
4903 /* On 32-bit hosts, QEMU is limited by virtual address space */
4904 if (value
> (2047 << 20)
4906 && HOST_LONG_BITS
== 32
4909 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
4912 if (value
!= (uint64_t)(ram_addr_t
)value
) {
4913 fprintf(stderr
, "qemu: ram size too large\n");
4922 const CPULogItem
*item
;
4924 mask
= cpu_str_to_log_mask(optarg
);
4926 printf("Log items (comma separated):\n");
4927 for(item
= cpu_log_items
; item
->mask
!= 0; item
++) {
4928 printf("%-10s %s\n", item
->name
, item
->help
);
4935 #ifdef CONFIG_GDBSTUB
4940 gdbstub_port
= optarg
;
4946 case QEMU_OPTION_bios
:
4953 keyboard_layout
= optarg
;
4955 case QEMU_OPTION_localtime
:
4958 case QEMU_OPTION_vga
:
4959 select_vgahw (optarg
);
4966 w
= strtol(p
, (char **)&p
, 10);
4969 fprintf(stderr
, "qemu: invalid resolution or depth\n");
4975 h
= strtol(p
, (char **)&p
, 10);
4980 depth
= strtol(p
, (char **)&p
, 10);
4981 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
4982 depth
!= 24 && depth
!= 32)
4984 } else if (*p
== '\0') {
4985 depth
= graphic_depth
;
4992 graphic_depth
= depth
;
4995 case QEMU_OPTION_echr
:
4998 term_escape_char
= strtol(optarg
, &r
, 0);
5000 printf("Bad argument to echr\n");
5003 case QEMU_OPTION_monitor
:
5004 monitor_device
= optarg
;
5006 case QEMU_OPTION_serial
:
5007 if (serial_device_index
>= MAX_SERIAL_PORTS
) {
5008 fprintf(stderr
, "qemu: too many serial ports\n");
5011 serial_devices
[serial_device_index
] = optarg
;
5012 serial_device_index
++;
5014 case QEMU_OPTION_virtiocon
:
5015 if (virtio_console_index
>= MAX_VIRTIO_CONSOLES
) {
5016 fprintf(stderr
, "qemu: too many virtio consoles\n");
5019 virtio_consoles
[virtio_console_index
] = optarg
;
5020 virtio_console_index
++;
5022 case QEMU_OPTION_parallel
:
5023 if (parallel_device_index
>= MAX_PARALLEL_PORTS
) {
5024 fprintf(stderr
, "qemu: too many parallel ports\n");
5027 parallel_devices
[parallel_device_index
] = optarg
;
5028 parallel_device_index
++;
5030 case QEMU_OPTION_loadvm
:
5033 case QEMU_OPTION_full_screen
:
5037 case QEMU_OPTION_no_frame
:
5040 case QEMU_OPTION_alt_grab
:
5043 case QEMU_OPTION_no_quit
:
5046 case QEMU_OPTION_sdl
:
5050 case QEMU_OPTION_pidfile
:
5054 case QEMU_OPTION_win2k_hack
:
5055 win2k_install_hack
= 1;
5057 case QEMU_OPTION_rtc_td_hack
:
5062 case QEMU_OPTION_no_kqemu
:
5065 case QEMU_OPTION_kernel_kqemu
:
5070 case QEMU_OPTION_enable_kvm
:
5077 case QEMU_OPTION_usb
:
5080 case QEMU_OPTION_usbdevice
:
5082 if (usb_devices_index
>= MAX_USB_CMDLINE
) {
5083 fprintf(stderr
, "Too many USB devices\n");
5086 usb_devices
[usb_devices_index
] = optarg
;
5087 usb_devices_index
++;
5089 case QEMU_OPTION_smp
:
5090 smp_cpus
= atoi(optarg
);
5092 fprintf(stderr
, "Invalid number of CPUs\n");
5096 case QEMU_OPTION_vnc
:
5097 vnc_display
= optarg
;
5099 case QEMU_OPTION_no_acpi
:
5102 case QEMU_OPTION_no_hpet
:
5105 case QEMU_OPTION_no_reboot
:
5108 case QEMU_OPTION_no_shutdown
:
5111 case QEMU_OPTION_show_cursor
:
5114 case QEMU_OPTION_uuid
:
5115 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
5116 fprintf(stderr
, "Fail to parse UUID string."
5117 " Wrong format.\n");
5121 case QEMU_OPTION_daemonize
:
5124 case QEMU_OPTION_option_rom
:
5125 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
5126 fprintf(stderr
, "Too many option ROMs\n");
5129 option_rom
[nb_option_roms
] = optarg
;
5132 case QEMU_OPTION_semihosting
:
5133 semihosting_enabled
= 1;
5135 case QEMU_OPTION_name
:
5138 #if defined(TARGET_SPARC) || defined(TARGET_PPC)
5139 case QEMU_OPTION_prom_env
:
5140 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
5141 fprintf(stderr
, "Too many prom variables\n");
5144 prom_envs
[nb_prom_envs
] = optarg
;
5149 case QEMU_OPTION_old_param
:
5153 case QEMU_OPTION_clock
:
5154 configure_alarms(optarg
);
5156 case QEMU_OPTION_startdate
:
5159 time_t rtc_start_date
;
5160 if (!strcmp(optarg
, "now")) {
5161 rtc_date_offset
= -1;
5163 if (sscanf(optarg
, "%d-%d-%dT%d:%d:%d",
5171 } else if (sscanf(optarg
, "%d-%d-%d",
5174 &tm
.tm_mday
) == 3) {
5183 rtc_start_date
= mktimegm(&tm
);
5184 if (rtc_start_date
== -1) {
5186 fprintf(stderr
, "Invalid date format. Valid format are:\n"
5187 "'now' or '2006-06-17T16:01:21' or '2006-06-17'\n");
5190 rtc_date_offset
= time(NULL
) - rtc_start_date
;
5194 case QEMU_OPTION_tb_size
:
5195 tb_size
= strtol(optarg
, NULL
, 0);
5199 case QEMU_OPTION_icount
:
5201 if (strcmp(optarg
, "auto") == 0) {
5202 icount_time_shift
= -1;
5204 icount_time_shift
= strtol(optarg
, NULL
, 0);
5207 case QEMU_OPTION_incoming
:
5214 #if defined(CONFIG_KVM) && defined(USE_KQEMU)
5215 if (kvm_allowed
&& kqemu_allowed
) {
5217 "You can not enable both KVM and kqemu at the same time\n");
5222 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
5223 if (smp_cpus
> machine
->max_cpus
) {
5224 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
5225 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
5231 if (serial_device_index
== 0)
5232 serial_devices
[0] = "stdio";
5233 if (parallel_device_index
== 0)
5234 parallel_devices
[0] = "null";
5235 if (strncmp(monitor_device
, "vc", 2) == 0)
5236 monitor_device
= "stdio";
5237 if (virtio_console_index
== 0)
5238 virtio_consoles
[0] = "null";
5245 if (pipe(fds
) == -1)
5256 len
= read(fds
[0], &status
, 1);
5257 if (len
== -1 && (errno
== EINTR
))
5262 else if (status
== 1) {
5263 fprintf(stderr
, "Could not acquire pidfile\n");
5280 signal(SIGTSTP
, SIG_IGN
);
5281 signal(SIGTTOU
, SIG_IGN
);
5282 signal(SIGTTIN
, SIG_IGN
);
5286 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
5289 write(fds
[1], &status
, 1);
5291 fprintf(stderr
, "Could not acquire pid file\n");
5299 linux_boot
= (kernel_filename
!= NULL
);
5300 net_boot
= (boot_devices_bitmap
>> ('n' - 'a')) & 0xF;
5302 if (!linux_boot
&& net_boot
== 0 &&
5303 !machine
->nodisk_ok
&& nb_drives_opt
== 0)
5306 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
5307 fprintf(stderr
, "-append only allowed with -kernel option\n");
5311 if (!linux_boot
&& initrd_filename
!= NULL
) {
5312 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
5316 /* boot to floppy or the default cd if no hard disk defined yet */
5317 if (!boot_devices
[0]) {
5318 boot_devices
= "cad";
5320 setvbuf(stdout
, NULL
, _IOLBF
, 0);
5323 if (init_timer_alarm() < 0) {
5324 fprintf(stderr
, "could not initialize alarm timer\n");
5327 if (use_icount
&& icount_time_shift
< 0) {
5329 /* 125MIPS seems a reasonable initial guess at the guest speed.
5330 It will be corrected fairly quickly anyway. */
5331 icount_time_shift
= 3;
5332 init_icount_adjust();
5339 /* init network clients */
5340 if (nb_net_clients
== 0) {
5341 /* if no clients, we use a default config */
5342 net_clients
[nb_net_clients
++] = "nic";
5344 net_clients
[nb_net_clients
++] = "user";
5348 for(i
= 0;i
< nb_net_clients
; i
++) {
5349 if (net_client_parse(net_clients
[i
]) < 0)
5355 /* XXX: this should be moved in the PC machine instantiation code */
5356 if (net_boot
!= 0) {
5358 for (i
= 0; i
< nb_nics
&& i
< 4; i
++) {
5359 const char *model
= nd_table
[i
].model
;
5361 if (net_boot
& (1 << i
)) {
5364 snprintf(buf
, sizeof(buf
), "%s/pxe-%s.bin", bios_dir
, model
);
5365 if (get_image_size(buf
) > 0) {
5366 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
5367 fprintf(stderr
, "Too many option ROMs\n");
5370 option_rom
[nb_option_roms
] = strdup(buf
);
5377 fprintf(stderr
, "No valid PXE rom found for network device\n");
5383 /* init the bluetooth world */
5384 for (i
= 0; i
< nb_bt_opts
; i
++)
5385 if (bt_parse(bt_opts
[i
]))
5388 /* init the memory */
5389 phys_ram_size
= machine
->ram_require
& ~RAMSIZE_FIXED
;
5391 if (machine
->ram_require
& RAMSIZE_FIXED
) {
5393 if (ram_size
< phys_ram_size
) {
5394 fprintf(stderr
, "Machine `%s' requires %llu bytes of memory\n",
5395 machine
->name
, (unsigned long long) phys_ram_size
);
5399 phys_ram_size
= ram_size
;
5401 ram_size
= phys_ram_size
;
5404 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
5406 phys_ram_size
+= ram_size
;
5409 phys_ram_base
= qemu_vmalloc(phys_ram_size
);
5410 if (!phys_ram_base
) {
5411 fprintf(stderr
, "Could not allocate physical memory\n");
5415 /* init the dynamic translator */
5416 cpu_exec_init_all(tb_size
* 1024 * 1024);
5420 /* we always create the cdrom drive, even if no disk is there */
5422 if (nb_drives_opt
< MAX_DRIVES
)
5423 drive_add(NULL
, CDROM_ALIAS
);
5425 /* we always create at least one floppy */
5427 if (nb_drives_opt
< MAX_DRIVES
)
5428 drive_add(NULL
, FD_ALIAS
, 0);
5430 /* we always create one sd slot, even if no card is in it */
5432 if (nb_drives_opt
< MAX_DRIVES
)
5433 drive_add(NULL
, SD_ALIAS
);
5435 /* open the virtual block devices */
5437 for(i
= 0; i
< nb_drives_opt
; i
++)
5438 if (drive_init(&drives_opt
[i
], snapshot
, machine
) == -1)
5441 register_savevm("timer", 0, 2, timer_save
, timer_load
, NULL
);
5442 register_savevm_live("ram", 0, 3, ram_save_live
, NULL
, ram_load
, NULL
);
5445 /* must be after terminal init, SDL library changes signal handlers */
5449 /* Maintain compatibility with multiple stdio monitors */
5450 if (!strcmp(monitor_device
,"stdio")) {
5451 for (i
= 0; i
< MAX_SERIAL_PORTS
; i
++) {
5452 const char *devname
= serial_devices
[i
];
5453 if (devname
&& !strcmp(devname
,"mon:stdio")) {
5454 monitor_device
= NULL
;
5456 } else if (devname
&& !strcmp(devname
,"stdio")) {
5457 monitor_device
= NULL
;
5458 serial_devices
[i
] = "mon:stdio";
5464 if (kvm_enabled()) {
5467 ret
= kvm_init(smp_cpus
);
5469 fprintf(stderr
, "failed to initialize KVM\n");
5474 if (monitor_device
) {
5475 monitor_hd
= qemu_chr_open("monitor", monitor_device
, NULL
);
5477 fprintf(stderr
, "qemu: could not open monitor device '%s'\n", monitor_device
);
5482 for(i
= 0; i
< MAX_SERIAL_PORTS
; i
++) {
5483 const char *devname
= serial_devices
[i
];
5484 if (devname
&& strcmp(devname
, "none")) {
5486 snprintf(label
, sizeof(label
), "serial%d", i
);
5487 serial_hds
[i
] = qemu_chr_open(label
, devname
, NULL
);
5488 if (!serial_hds
[i
]) {
5489 fprintf(stderr
, "qemu: could not open serial device '%s'\n",
5496 for(i
= 0; i
< MAX_PARALLEL_PORTS
; i
++) {
5497 const char *devname
= parallel_devices
[i
];
5498 if (devname
&& strcmp(devname
, "none")) {
5500 snprintf(label
, sizeof(label
), "parallel%d", i
);
5501 parallel_hds
[i
] = qemu_chr_open(label
, devname
, NULL
);
5502 if (!parallel_hds
[i
]) {
5503 fprintf(stderr
, "qemu: could not open parallel device '%s'\n",
5510 for(i
= 0; i
< MAX_VIRTIO_CONSOLES
; i
++) {
5511 const char *devname
= virtio_consoles
[i
];
5512 if (devname
&& strcmp(devname
, "none")) {
5514 snprintf(label
, sizeof(label
), "virtcon%d", i
);
5515 virtcon_hds
[i
] = qemu_chr_open(label
, devname
, NULL
);
5516 if (!virtcon_hds
[i
]) {
5517 fprintf(stderr
, "qemu: could not open virtio console '%s'\n",
5524 machine
->init(ram_size
, vga_ram_size
, boot_devices
,
5525 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
5527 /* Set KVM's vcpu state to qemu's initial CPUState. */
5528 if (kvm_enabled()) {
5531 ret
= kvm_sync_vcpus();
5533 fprintf(stderr
, "failed to initialize vcpus\n");
5538 /* init USB devices */
5540 for(i
= 0; i
< usb_devices_index
; i
++) {
5541 if (usb_device_add(usb_devices
[i
]) < 0) {
5542 fprintf(stderr
, "Warning: could not add USB device %s\n",
5549 dumb_display_init();
5550 /* just use the first displaystate for the moment */
5555 fprintf(stderr
, "fatal: -nographic can't be used with -curses\n");
5559 #if defined(CONFIG_CURSES)
5561 /* At the moment curses cannot be used with other displays */
5562 curses_display_init(ds
, full_screen
);
5566 if (vnc_display
!= NULL
) {
5567 vnc_display_init(ds
);
5568 if (vnc_display_open(ds
, vnc_display
) < 0)
5571 #if defined(CONFIG_SDL)
5572 if (sdl
|| !vnc_display
)
5573 sdl_display_init(ds
, full_screen
, no_frame
);
5574 #elif defined(CONFIG_COCOA)
5575 if (sdl
|| !vnc_display
)
5576 cocoa_display_init(ds
, full_screen
);
5582 dcl
= ds
->listeners
;
5583 while (dcl
!= NULL
) {
5584 if (dcl
->dpy_refresh
!= NULL
) {
5585 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
5586 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
5591 if (nographic
|| (vnc_display
&& !sdl
)) {
5592 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
5593 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
5596 text_consoles_set_display(display_state
);
5598 if (monitor_device
&& monitor_hd
)
5599 monitor_init(monitor_hd
, !nographic
);
5601 for(i
= 0; i
< MAX_SERIAL_PORTS
; i
++) {
5602 const char *devname
= serial_devices
[i
];
5603 if (devname
&& strcmp(devname
, "none")) {
5605 snprintf(label
, sizeof(label
), "serial%d", i
);
5606 if (strstart(devname
, "vc", 0))
5607 qemu_chr_printf(serial_hds
[i
], "serial%d console\r\n", i
);
5611 for(i
= 0; i
< MAX_PARALLEL_PORTS
; i
++) {
5612 const char *devname
= parallel_devices
[i
];
5613 if (devname
&& strcmp(devname
, "none")) {
5615 snprintf(label
, sizeof(label
), "parallel%d", i
);
5616 if (strstart(devname
, "vc", 0))
5617 qemu_chr_printf(parallel_hds
[i
], "parallel%d console\r\n", i
);
5621 for(i
= 0; i
< MAX_VIRTIO_CONSOLES
; i
++) {
5622 const char *devname
= virtio_consoles
[i
];
5623 if (virtcon_hds
[i
] && devname
) {
5625 snprintf(label
, sizeof(label
), "virtcon%d", i
);
5626 if (strstart(devname
, "vc", 0))
5627 qemu_chr_printf(virtcon_hds
[i
], "virtio console%d\r\n", i
);
5631 #ifdef CONFIG_GDBSTUB
5633 /* XXX: use standard host:port notation and modify options
5635 if (gdbserver_start(gdbstub_port
) < 0) {
5636 fprintf(stderr
, "qemu: could not open gdbstub device on port '%s'\n",
5647 autostart
= 0; /* fixme how to deal with -daemonize */
5648 qemu_start_incoming_migration(incoming
);
5652 /* XXX: simplify init */
5665 len
= write(fds
[1], &status
, 1);
5666 if (len
== -1 && (errno
== EINTR
))
5673 TFR(fd
= open("/dev/null", O_RDWR
));