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
32 /* Needed early for CONFIG_BSD etc. */
33 #include "config-host.h"
37 #include <sys/times.h>
41 #include <sys/ioctl.h>
42 #include <sys/resource.h>
43 #include <sys/socket.h>
44 #include <netinet/in.h>
46 #include <arpa/inet.h>
49 #include <sys/select.h>
52 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
54 #include <sys/sysctl.h>
63 #include <linux/ppdev.h>
64 #include <linux/parport.h>
68 #include <sys/ethernet.h>
69 #include <sys/sockio.h>
70 #include <netinet/arp.h>
71 #include <netinet/in_systm.h>
72 #include <netinet/ip.h>
73 #include <netinet/ip_icmp.h> // must come after ip.h
74 #include <netinet/udp.h>
75 #include <netinet/tcp.h>
79 /* See MySQL bug #7156 (http://bugs.mysql.com/bug.php?id=7156) for
80 discussion about Solaris header problems */
81 extern int madvise(caddr_t
, size_t, int);
86 #if defined(__OpenBSD__)
90 #if defined(CONFIG_VDE)
91 #include <libvdeplug.h>
99 #if defined(__APPLE__) || defined(main)
101 int qemu_main(int argc
, char **argv
, char **envp
);
102 int main(int argc
, char **argv
)
104 return qemu_main(argc
, argv
, NULL
);
107 #define main qemu_main
109 #endif /* CONFIG_SDL */
113 #define main qemu_main
114 #endif /* CONFIG_COCOA */
117 #include "hw/boards.h"
119 #include "hw/pcmcia.h"
124 #include "hw/watchdog.h"
125 #include "hw/smbios.h"
128 #include "hw/loader.h"
131 #include "net/slirp.h"
136 #include "qemu-timer.h"
137 #include "qemu-char.h"
138 #include "cache-utils.h"
140 #include "blockdev.h"
141 #include "block-migration.h"
143 #include "audio/audio.h"
144 #include "migration.h"
146 #include "qemu-option.h"
147 #include "qemu-config.h"
148 #include "qemu-objects.h"
149 #include "qemu-options.h"
150 #include "hw/device-assignment.h"
152 #include "fsdev/qemu-fsdev.h"
157 #include "qemu_socket.h"
159 #include "slirp/libslirp.h"
161 #include "qemu-queue.h"
163 #include "arch_init.h"
166 //#define DEBUG_SLIRP
168 #define DEFAULT_RAM_SIZE 128
170 #define MAX_VIRTIO_CONSOLES 1
172 static const char *data_dir
;
173 const char *bios_name
= NULL
;
174 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
175 DisplayType display_type
= DT_DEFAULT
;
176 const char* keyboard_layout
= NULL
;
178 const char *mem_path
= NULL
;
180 int mem_prealloc
= 0; /* force preallocation of physical target memory */
183 NICInfo nd_table
[MAX_NICS
];
186 static int rtc_utc
= 1;
187 static int rtc_date_offset
= -1; /* -1 means no change */
188 QEMUClock
*rtc_clock
;
189 int vga_interface_type
= VGA_NONE
;
190 static int full_screen
= 0;
192 static int no_frame
= 0;
195 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
196 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
197 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
198 int win2k_install_hack
= 0;
202 const char *assigned_devices
[MAX_DEV_ASSIGN_CMDLINE
];
203 int assigned_devices_index
;
208 const char *vnc_display
;
209 int acpi_enabled
= 1;
215 int graphic_rotate
= 0;
216 uint8_t irq0override
= 1;
217 const char *watchdog
;
218 const char *option_rom
[MAX_OPTION_ROMS
];
220 int semihosting_enabled
= 0;
221 int time_drift_fix
= 0;
222 unsigned int kvm_shadow_memory
= 0;
224 const char *qemu_name
;
227 unsigned int nb_prom_envs
= 0;
228 const char *prom_envs
[MAX_PROM_ENVS
];
229 const char *nvram
= NULL
;
233 uint64_t node_mem
[MAX_NODES
];
234 uint64_t node_cpumask
[MAX_NODES
];
236 static QEMUTimer
*nographic_timer
;
238 uint8_t qemu_uuid
[16];
240 static QEMUBootSetHandler
*boot_set_handler
;
241 static void *boot_set_opaque
;
243 static NotifierList exit_notifiers
=
244 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
248 enum xen_mode xen_mode
= XEN_EMULATE
;
250 static int default_serial
= 1;
251 static int default_parallel
= 1;
252 static int default_virtcon
= 1;
253 static int default_monitor
= 1;
254 static int default_vga
= 1;
255 static int default_floppy
= 1;
256 static int default_cdrom
= 1;
257 static int default_sdcard
= 1;
263 { .driver
= "isa-serial", .flag
= &default_serial
},
264 { .driver
= "isa-parallel", .flag
= &default_parallel
},
265 { .driver
= "isa-fdc", .flag
= &default_floppy
},
266 { .driver
= "ide-drive", .flag
= &default_cdrom
},
267 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
268 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
269 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
270 { .driver
= "VGA", .flag
= &default_vga
},
271 { .driver
= "cirrus-vga", .flag
= &default_vga
},
272 { .driver
= "vmware-svga", .flag
= &default_vga
},
275 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
277 const char *driver
= qemu_opt_get(opts
, "driver");
282 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
283 if (strcmp(default_list
[i
].driver
, driver
) != 0)
285 *(default_list
[i
].flag
) = 0;
290 /***********************************************************/
291 /* real time host monotonic timer */
293 /* compute with 96 bit intermediate result: (a*b)/c */
294 uint64_t muldiv64(uint64_t a
, uint32_t b
, uint32_t c
)
299 #ifdef HOST_WORDS_BIGENDIAN
309 rl
= (uint64_t)u
.l
.low
* (uint64_t)b
;
310 rh
= (uint64_t)u
.l
.high
* (uint64_t)b
;
313 res
.l
.low
= (((rh
% c
) << 32) + (rl
& 0xffffffff)) / c
;
317 /***********************************************************/
318 /* host time/date access */
319 void qemu_get_timedate(struct tm
*tm
, int offset
)
326 if (rtc_date_offset
== -1) {
330 ret
= localtime(&ti
);
332 ti
-= rtc_date_offset
;
336 memcpy(tm
, ret
, sizeof(struct tm
));
339 int qemu_timedate_diff(struct tm
*tm
)
343 if (rtc_date_offset
== -1)
345 seconds
= mktimegm(tm
);
347 seconds
= mktime(tm
);
349 seconds
= mktimegm(tm
) + rtc_date_offset
;
351 return seconds
- time(NULL
);
354 void rtc_change_mon_event(struct tm
*tm
)
358 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
359 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
360 qobject_decref(data
);
363 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
365 time_t rtc_start_date
;
368 if (!strcmp(startdate
, "now") && legacy
) {
369 rtc_date_offset
= -1;
371 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
379 } else if (sscanf(startdate
, "%d-%d-%d",
391 rtc_start_date
= mktimegm(&tm
);
392 if (rtc_start_date
== -1) {
394 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
395 "'2006-06-17T16:01:21' or '2006-06-17'\n");
398 rtc_date_offset
= time(NULL
) - rtc_start_date
;
402 static void configure_rtc(QemuOpts
*opts
)
406 value
= qemu_opt_get(opts
, "base");
408 if (!strcmp(value
, "utc")) {
410 } else if (!strcmp(value
, "localtime")) {
413 configure_rtc_date_offset(value
, 0);
416 value
= qemu_opt_get(opts
, "clock");
418 if (!strcmp(value
, "host")) {
419 rtc_clock
= host_clock
;
420 } else if (!strcmp(value
, "vm")) {
421 rtc_clock
= vm_clock
;
423 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
427 value
= qemu_opt_get(opts
, "driftfix");
429 if (!strcmp(value
, "slew")) {
431 } else if (!strcmp(value
, "none")) {
434 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
440 /***********************************************************/
441 /* Bluetooth support */
444 static struct HCIInfo
*hci_table
[MAX_NICS
];
446 static struct bt_vlan_s
{
447 struct bt_scatternet_s net
;
449 struct bt_vlan_s
*next
;
452 /* find or alloc a new bluetooth "VLAN" */
453 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
455 struct bt_vlan_s
**pvlan
, *vlan
;
456 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
460 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
462 pvlan
= &first_bt_vlan
;
463 while (*pvlan
!= NULL
)
464 pvlan
= &(*pvlan
)->next
;
469 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
473 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
478 static struct HCIInfo null_hci
= {
479 .cmd_send
= null_hci_send
,
480 .sco_send
= null_hci_send
,
481 .acl_send
= null_hci_send
,
482 .bdaddr_set
= null_hci_addr_set
,
485 struct HCIInfo
*qemu_next_hci(void)
487 if (cur_hci
== nb_hcis
)
490 return hci_table
[cur_hci
++];
493 static struct HCIInfo
*hci_init(const char *str
)
496 struct bt_scatternet_s
*vlan
= 0;
498 if (!strcmp(str
, "null"))
501 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
503 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
504 else if (!strncmp(str
, "hci", 3)) {
507 if (!strncmp(str
+ 3, ",vlan=", 6)) {
508 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
513 vlan
= qemu_find_bt_vlan(0);
515 return bt_new_hci(vlan
);
518 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
523 static int bt_hci_parse(const char *str
)
528 if (nb_hcis
>= MAX_NICS
) {
529 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
542 bdaddr
.b
[5] = 0x56 + nb_hcis
;
543 hci
->bdaddr_set(hci
, bdaddr
.b
);
545 hci_table
[nb_hcis
++] = hci
;
550 static void bt_vhci_add(int vlan_id
)
552 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
555 fprintf(stderr
, "qemu: warning: adding a VHCI to "
556 "an empty scatternet %i\n", vlan_id
);
558 bt_vhci_init(bt_new_hci(vlan
));
561 static struct bt_device_s
*bt_device_add(const char *opt
)
563 struct bt_scatternet_s
*vlan
;
565 char *endp
= strstr(opt
, ",vlan=");
566 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
569 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
572 vlan_id
= strtol(endp
+ 6, &endp
, 0);
574 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
579 vlan
= qemu_find_bt_vlan(vlan_id
);
582 fprintf(stderr
, "qemu: warning: adding a slave device to "
583 "an empty scatternet %i\n", vlan_id
);
585 if (!strcmp(devname
, "keyboard"))
586 return bt_keyboard_init(vlan
);
588 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
592 static int bt_parse(const char *opt
)
594 const char *endp
, *p
;
597 if (strstart(opt
, "hci", &endp
)) {
598 if (!*endp
|| *endp
== ',') {
600 if (!strstart(endp
, ",vlan=", 0))
603 return bt_hci_parse(opt
);
605 } else if (strstart(opt
, "vhci", &endp
)) {
606 if (!*endp
|| *endp
== ',') {
608 if (strstart(endp
, ",vlan=", &p
)) {
609 vlan
= strtol(p
, (char **) &endp
, 0);
611 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
615 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
624 } else if (strstart(opt
, "device:", &endp
))
625 return !bt_device_add(endp
);
627 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
631 /***********************************************************/
632 /* QEMU Block devices */
634 #define HD_ALIAS "index=%d,media=disk"
635 #define CDROM_ALIAS "index=2,media=cdrom"
636 #define FD_ALIAS "index=%d,if=floppy"
637 #define PFLASH_ALIAS "if=pflash"
638 #define MTD_ALIAS "if=mtd"
639 #define SD_ALIAS "index=0,if=sd"
641 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
643 int *use_scsi
= opaque
;
646 if (drive_init(opts
, *use_scsi
, &fatal_error
) == NULL
) {
653 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
655 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
656 qemu_opt_set(opts
, "snapshot", "on");
661 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
663 boot_set_handler
= func
;
664 boot_set_opaque
= opaque
;
667 int qemu_boot_set(const char *boot_devices
)
669 if (!boot_set_handler
) {
672 return boot_set_handler(boot_set_opaque
, boot_devices
);
675 static void validate_bootdevices(char *devices
)
677 /* We just do some generic consistency checks */
681 for (p
= devices
; *p
!= '\0'; p
++) {
682 /* Allowed boot devices are:
683 * a-b: floppy disk drives
684 * c-f: IDE disk drives
685 * g-m: machine implementation dependant drives
686 * n-p: network devices
687 * It's up to each machine implementation to check if the given boot
688 * devices match the actual hardware implementation and firmware
691 if (*p
< 'a' || *p
> 'p') {
692 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
695 if (bitmap
& (1 << (*p
- 'a'))) {
696 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
699 bitmap
|= 1 << (*p
- 'a');
703 static void restore_boot_devices(void *opaque
)
705 char *standard_boot_devices
= opaque
;
706 static int first
= 1;
708 /* Restore boot order and remove ourselves after the first boot */
714 qemu_boot_set(standard_boot_devices
);
716 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
717 qemu_free(standard_boot_devices
);
720 static void numa_add(const char *optarg
)
724 unsigned long long value
, endvalue
;
727 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
728 if (!strcmp(option
, "node")) {
729 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
730 nodenr
= nb_numa_nodes
;
732 nodenr
= strtoull(option
, NULL
, 10);
735 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
736 node_mem
[nodenr
] = 0;
738 value
= strtoull(option
, &endptr
, 0);
740 case 0: case 'M': case 'm':
747 node_mem
[nodenr
] = value
;
749 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
750 node_cpumask
[nodenr
] = 0;
752 value
= strtoull(option
, &endptr
, 10);
755 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
757 if (*endptr
== '-') {
758 endvalue
= strtoull(endptr
+1, &endptr
, 10);
759 if (endvalue
>= 63) {
762 "only 63 CPUs in NUMA mode supported.\n");
764 value
= (2ULL << endvalue
) - (1ULL << value
);
766 value
= 1ULL << value
;
769 node_cpumask
[nodenr
] = value
;
776 static void smp_parse(const char *optarg
)
778 int smp
, sockets
= 0, threads
= 0, cores
= 0;
782 smp
= strtoul(optarg
, &endptr
, 10);
783 if (endptr
!= optarg
) {
784 if (*endptr
== ',') {
788 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
789 sockets
= strtoull(option
, NULL
, 10);
790 if (get_param_value(option
, 128, "cores", endptr
) != 0)
791 cores
= strtoull(option
, NULL
, 10);
792 if (get_param_value(option
, 128, "threads", endptr
) != 0)
793 threads
= strtoull(option
, NULL
, 10);
794 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
795 max_cpus
= strtoull(option
, NULL
, 10);
797 /* compute missing values, prefer sockets over cores over threads */
798 if (smp
== 0 || sockets
== 0) {
799 sockets
= sockets
> 0 ? sockets
: 1;
800 cores
= cores
> 0 ? cores
: 1;
801 threads
= threads
> 0 ? threads
: 1;
803 smp
= cores
* threads
* sockets
;
807 threads
= threads
> 0 ? threads
: 1;
808 cores
= smp
/ (sockets
* threads
);
811 threads
= smp
/ (cores
* sockets
);
816 smp_cores
= cores
> 0 ? cores
: 1;
817 smp_threads
= threads
> 0 ? threads
: 1;
822 /***********************************************************/
825 static int usb_device_add(const char *devname
)
828 USBDevice
*dev
= NULL
;
833 /* drivers with .usbdevice_name entry in USBDeviceInfo */
834 dev
= usbdevice_create(devname
);
839 if (strstart(devname
, "host:", &p
)) {
840 dev
= usb_host_device_open(p
);
841 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
842 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
843 bt_new_hci(qemu_find_bt_vlan(0)));
854 static int usb_device_del(const char *devname
)
859 if (strstart(devname
, "host:", &p
))
860 return usb_host_device_close(p
);
865 p
= strchr(devname
, '.');
868 bus_num
= strtoul(devname
, NULL
, 0);
869 addr
= strtoul(p
+ 1, NULL
, 0);
871 return usb_device_delete_addr(bus_num
, addr
);
874 static int usb_parse(const char *cmdline
)
877 r
= usb_device_add(cmdline
);
879 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
884 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
886 const char *devname
= qdict_get_str(qdict
, "devname");
887 if (usb_device_add(devname
) < 0) {
888 error_report("could not add USB device '%s'", devname
);
892 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
894 const char *devname
= qdict_get_str(qdict
, "devname");
895 if (usb_device_del(devname
) < 0) {
896 error_report("could not delete USB device '%s'", devname
);
900 /***********************************************************/
903 static struct pcmcia_socket_entry_s
{
904 PCMCIASocket
*socket
;
905 struct pcmcia_socket_entry_s
*next
;
906 } *pcmcia_sockets
= 0;
908 void pcmcia_socket_register(PCMCIASocket
*socket
)
910 struct pcmcia_socket_entry_s
*entry
;
912 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
913 entry
->socket
= socket
;
914 entry
->next
= pcmcia_sockets
;
915 pcmcia_sockets
= entry
;
918 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
920 struct pcmcia_socket_entry_s
*entry
, **ptr
;
922 ptr
= &pcmcia_sockets
;
923 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
924 if (entry
->socket
== socket
) {
930 void pcmcia_info(Monitor
*mon
)
932 struct pcmcia_socket_entry_s
*iter
;
935 monitor_printf(mon
, "No PCMCIA sockets\n");
937 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
938 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
939 iter
->socket
->attached
? iter
->socket
->card_string
:
943 /***********************************************************/
946 typedef struct IOHandlerRecord
{
948 IOCanReadHandler
*fd_read_poll
;
955 QLIST_ENTRY(IOHandlerRecord
) next
;
958 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
959 QLIST_HEAD_INITIALIZER(io_handlers
);
962 /* XXX: fd_read_poll should be suppressed, but an API change is
963 necessary in the character devices to suppress fd_can_read(). */
964 int qemu_set_fd_handler2(int fd
,
965 IOCanReadHandler
*fd_read_poll
,
970 IOHandlerRecord
*ioh
;
972 if (!fd_read
&& !fd_write
) {
973 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
980 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
984 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
985 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
988 ioh
->fd_read_poll
= fd_read_poll
;
989 ioh
->fd_read
= fd_read
;
990 ioh
->fd_write
= fd_write
;
991 ioh
->opaque
= opaque
;
998 int qemu_set_fd_handler(int fd
,
1000 IOHandler
*fd_write
,
1003 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
1006 /***********************************************************/
1007 /* machine registration */
1009 static QEMUMachine
*first_machine
= NULL
;
1010 QEMUMachine
*current_machine
= NULL
;
1012 int qemu_register_machine(QEMUMachine
*m
)
1015 pm
= &first_machine
;
1023 static QEMUMachine
*find_machine(const char *name
)
1027 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1028 if (!strcmp(m
->name
, name
))
1030 if (m
->alias
&& !strcmp(m
->alias
, name
))
1036 static QEMUMachine
*find_default_machine(void)
1040 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1041 if (m
->is_default
) {
1048 /***********************************************************/
1049 /* main execution loop */
1051 static void gui_update(void *opaque
)
1053 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1054 DisplayState
*ds
= opaque
;
1055 DisplayChangeListener
*dcl
= ds
->listeners
;
1057 qemu_flush_coalesced_mmio_buffer();
1060 while (dcl
!= NULL
) {
1061 if (dcl
->gui_timer_interval
&&
1062 dcl
->gui_timer_interval
< interval
)
1063 interval
= dcl
->gui_timer_interval
;
1066 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1069 static void nographic_update(void *opaque
)
1071 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1073 qemu_flush_coalesced_mmio_buffer();
1074 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1077 struct vm_change_state_entry
{
1078 VMChangeStateHandler
*cb
;
1080 QLIST_ENTRY (vm_change_state_entry
) entries
;
1083 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1085 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1088 VMChangeStateEntry
*e
;
1090 e
= qemu_mallocz(sizeof (*e
));
1094 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1098 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1100 QLIST_REMOVE (e
, entries
);
1104 void vm_state_notify(int running
, int reason
)
1106 VMChangeStateEntry
*e
;
1108 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1109 e
->cb(e
->opaque
, running
, reason
);
1118 vm_state_notify(1, 0);
1120 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1124 /* reset/shutdown handler */
1126 typedef struct QEMUResetEntry
{
1127 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1128 QEMUResetHandler
*func
;
1132 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1133 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1134 static int reset_requested
;
1135 static int shutdown_requested
;
1136 static int powerdown_requested
;
1137 int debug_requested
;
1138 int vmstop_requested
;
1140 int qemu_no_shutdown(void)
1142 int r
= no_shutdown
;
1147 int qemu_shutdown_requested(void)
1149 int r
= shutdown_requested
;
1150 shutdown_requested
= 0;
1154 int qemu_reset_requested(void)
1156 int r
= reset_requested
;
1157 reset_requested
= 0;
1161 int qemu_powerdown_requested(void)
1163 int r
= powerdown_requested
;
1164 powerdown_requested
= 0;
1168 static int qemu_debug_requested(void)
1170 int r
= debug_requested
;
1171 debug_requested
= 0;
1175 static int qemu_vmstop_requested(void)
1177 int r
= vmstop_requested
;
1178 vmstop_requested
= 0;
1182 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1184 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1187 re
->opaque
= opaque
;
1188 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1191 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1195 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1196 if (re
->func
== func
&& re
->opaque
== opaque
) {
1197 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1204 void qemu_system_reset(void)
1206 QEMUResetEntry
*re
, *nre
;
1208 /* reset all devices */
1209 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1210 re
->func(re
->opaque
);
1212 monitor_protocol_event(QEVENT_RESET
, NULL
);
1213 cpu_synchronize_all_post_reset();
1216 void qemu_system_reset_request(void)
1219 shutdown_requested
= 1;
1221 reset_requested
= 1;
1223 if (cpu_single_env
) {
1224 cpu_single_env
->stopped
= 1;
1225 cpu_exit(cpu_single_env
);
1227 qemu_notify_event();
1230 void qemu_system_shutdown_request(void)
1232 shutdown_requested
= 1;
1233 qemu_notify_event();
1236 void qemu_system_powerdown_request(void)
1238 powerdown_requested
= 1;
1239 qemu_notify_event();
1242 void main_loop_wait(int nonblocking
)
1244 IOHandlerRecord
*ioh
;
1245 fd_set rfds
, wfds
, xfds
;
1253 timeout
= qemu_calculate_timeout();
1254 qemu_bh_update_timeout(&timeout
);
1257 os_host_main_loop_wait(&timeout
);
1259 /* poll any events */
1260 /* XXX: separate device handlers from system ones */
1265 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1269 (!ioh
->fd_read_poll
||
1270 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1271 FD_SET(ioh
->fd
, &rfds
);
1275 if (ioh
->fd_write
) {
1276 FD_SET(ioh
->fd
, &wfds
);
1282 tv
.tv_sec
= timeout
/ 1000;
1283 tv
.tv_usec
= (timeout
% 1000) * 1000;
1285 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1287 qemu_mutex_unlock_iothread();
1288 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1289 qemu_mutex_lock_iothread();
1291 IOHandlerRecord
*pioh
;
1293 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1295 QLIST_REMOVE(ioh
, next
);
1299 if (ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1300 ioh
->fd_read(ioh
->opaque
);
1301 if (!(ioh
->fd_read_poll
&& ioh
->fd_read_poll(ioh
->opaque
)))
1302 FD_CLR(ioh
->fd
, &rfds
);
1304 if (ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1305 ioh
->fd_write(ioh
->opaque
);
1310 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1312 qemu_run_all_timers();
1314 /* Check bottom-halves last in case any of the earlier events triggered
1320 static int vm_can_run(void)
1322 if (powerdown_requested
)
1324 if (reset_requested
)
1326 if (shutdown_requested
)
1328 if (debug_requested
)
1333 qemu_irq qemu_system_powerdown
;
1335 static void main_loop(void)
1339 if (kvm_enabled()) {
1341 cpu_disable_ticks();
1345 qemu_main_loop_start();
1349 bool nonblocking
= false;
1350 #ifdef CONFIG_PROFILER
1353 #ifndef CONFIG_IOTHREAD
1354 nonblocking
= tcg_cpu_exec();
1356 #ifdef CONFIG_PROFILER
1357 ti
= profile_getclock();
1359 main_loop_wait(nonblocking
);
1360 #ifdef CONFIG_PROFILER
1361 dev_time
+= profile_getclock() - ti
;
1363 } while (vm_can_run());
1365 if ((r
= qemu_debug_requested())) {
1368 if (qemu_shutdown_requested()) {
1369 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1376 if (qemu_reset_requested()) {
1378 qemu_system_reset();
1381 if (qemu_powerdown_requested()) {
1382 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1383 qemu_irq_raise(qemu_system_powerdown
);
1385 if ((r
= qemu_vmstop_requested())) {
1393 static void version(void)
1395 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1398 static void help(int exitcode
)
1400 const char *options_help
=
1401 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1403 #define DEFHEADING(text) stringify(text) "\n"
1404 #include "qemu-options.def"
1410 printf("usage: %s [options] [disk_image]\n"
1412 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1415 "During emulation, the following keys are useful:\n"
1416 "ctrl-alt-f toggle full screen\n"
1417 "ctrl-alt-n switch to virtual console 'n'\n"
1418 "ctrl-alt toggle mouse and keyboard grab\n"
1420 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1426 #define HAS_ARG 0x0001
1428 typedef struct QEMUOption
{
1435 static const QEMUOption qemu_options
[] = {
1436 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1437 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1438 { option, opt_arg, opt_enum, arch_mask },
1439 #define DEFHEADING(text)
1440 #include "qemu-options.def"
1446 static void select_vgahw (const char *p
)
1451 vga_interface_type
= VGA_NONE
;
1452 if (strstart(p
, "std", &opts
)) {
1453 vga_interface_type
= VGA_STD
;
1454 } else if (strstart(p
, "cirrus", &opts
)) {
1455 vga_interface_type
= VGA_CIRRUS
;
1456 } else if (strstart(p
, "vmware", &opts
)) {
1457 vga_interface_type
= VGA_VMWARE
;
1458 } else if (strstart(p
, "xenfb", &opts
)) {
1459 vga_interface_type
= VGA_XENFB
;
1460 } else if (!strstart(p
, "none", &opts
)) {
1462 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1466 const char *nextopt
;
1468 if (strstart(opts
, ",retrace=", &nextopt
)) {
1470 if (strstart(opts
, "dumb", &nextopt
))
1471 vga_retrace_method
= VGA_RETRACE_DUMB
;
1472 else if (strstart(opts
, "precise", &nextopt
))
1473 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1474 else goto invalid_vga
;
1475 } else goto invalid_vga
;
1480 static int balloon_parse(const char *arg
)
1484 if (strcmp(arg
, "none") == 0) {
1488 if (!strncmp(arg
, "virtio", 6)) {
1489 if (arg
[6] == ',') {
1490 /* have params -> parse them */
1491 opts
= qemu_opts_parse(&qemu_device_opts
, arg
+7, 0);
1495 /* create empty opts */
1496 opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1498 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1505 char *qemu_find_file(int type
, const char *name
)
1511 /* If name contains path separators then try it as a straight path. */
1512 if ((strchr(name
, '/') || strchr(name
, '\\'))
1513 && access(name
, R_OK
) == 0) {
1514 return qemu_strdup(name
);
1517 case QEMU_FILE_TYPE_BIOS
:
1520 case QEMU_FILE_TYPE_KEYMAP
:
1521 subdir
= "keymaps/";
1526 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1527 buf
= qemu_mallocz(len
);
1528 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1529 if (access(buf
, R_OK
)) {
1536 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1538 return qdev_device_help(opts
);
1541 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1545 dev
= qdev_device_add(opts
);
1551 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1553 CharDriverState
*chr
;
1555 chr
= qemu_chr_open_opts(opts
, NULL
);
1562 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1565 ret
= qemu_fsdev_add(opts
);
1571 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1573 CharDriverState
*chr
;
1574 const char *chardev
;
1578 mode
= qemu_opt_get(opts
, "mode");
1582 if (strcmp(mode
, "readline") == 0) {
1583 flags
= MONITOR_USE_READLINE
;
1584 } else if (strcmp(mode
, "control") == 0) {
1585 flags
= MONITOR_USE_CONTROL
;
1587 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1591 if (qemu_opt_get_bool(opts
, "default", 0))
1592 flags
|= MONITOR_IS_DEFAULT
;
1594 chardev
= qemu_opt_get(opts
, "chardev");
1595 chr
= qemu_chr_find(chardev
);
1597 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1601 monitor_init(chr
, flags
);
1605 static void monitor_parse(const char *optarg
, const char *mode
)
1607 static int monitor_device_index
= 0;
1613 if (strstart(optarg
, "chardev:", &p
)) {
1614 snprintf(label
, sizeof(label
), "%s", p
);
1616 snprintf(label
, sizeof(label
), "compat_monitor%d",
1617 monitor_device_index
);
1618 if (monitor_device_index
== 0) {
1621 opts
= qemu_chr_parse_compat(label
, optarg
);
1623 fprintf(stderr
, "parse error: %s\n", optarg
);
1628 opts
= qemu_opts_create(&qemu_mon_opts
, label
, 1);
1630 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1633 qemu_opt_set(opts
, "mode", mode
);
1634 qemu_opt_set(opts
, "chardev", label
);
1636 qemu_opt_set(opts
, "default", "on");
1637 monitor_device_index
++;
1640 struct device_config
{
1642 DEV_USB
, /* -usbdevice */
1644 DEV_SERIAL
, /* -serial */
1645 DEV_PARALLEL
, /* -parallel */
1646 DEV_VIRTCON
, /* -virtioconsole */
1647 DEV_DEBUGCON
, /* -debugcon */
1649 const char *cmdline
;
1650 QTAILQ_ENTRY(device_config
) next
;
1652 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1654 static void add_device_config(int type
, const char *cmdline
)
1656 struct device_config
*conf
;
1658 conf
= qemu_mallocz(sizeof(*conf
));
1660 conf
->cmdline
= cmdline
;
1661 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1664 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1666 struct device_config
*conf
;
1669 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1670 if (conf
->type
!= type
)
1672 rc
= func(conf
->cmdline
);
1679 static int serial_parse(const char *devname
)
1681 static int index
= 0;
1684 if (strcmp(devname
, "none") == 0)
1686 if (index
== MAX_SERIAL_PORTS
) {
1687 fprintf(stderr
, "qemu: too many serial ports\n");
1690 snprintf(label
, sizeof(label
), "serial%d", index
);
1691 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1692 if (!serial_hds
[index
]) {
1693 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1694 devname
, strerror(errno
));
1701 static int parallel_parse(const char *devname
)
1703 static int index
= 0;
1706 if (strcmp(devname
, "none") == 0)
1708 if (index
== MAX_PARALLEL_PORTS
) {
1709 fprintf(stderr
, "qemu: too many parallel ports\n");
1712 snprintf(label
, sizeof(label
), "parallel%d", index
);
1713 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1714 if (!parallel_hds
[index
]) {
1715 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1716 devname
, strerror(errno
));
1723 static int virtcon_parse(const char *devname
)
1725 static int index
= 0;
1727 QemuOpts
*bus_opts
, *dev_opts
;
1729 if (strcmp(devname
, "none") == 0)
1731 if (index
== MAX_VIRTIO_CONSOLES
) {
1732 fprintf(stderr
, "qemu: too many virtio consoles\n");
1736 bus_opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1737 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1739 dev_opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1740 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1742 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1743 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1744 if (!virtcon_hds
[index
]) {
1745 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1746 devname
, strerror(errno
));
1749 qemu_opt_set(dev_opts
, "chardev", label
);
1755 static int debugcon_parse(const char *devname
)
1759 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1762 opts
= qemu_opts_create(&qemu_device_opts
, "debugcon", 1);
1764 fprintf(stderr
, "qemu: already have a debugcon device\n");
1767 qemu_opt_set(opts
, "driver", "isa-debugcon");
1768 qemu_opt_set(opts
, "chardev", "debugcon");
1772 void qemu_add_exit_notifier(Notifier
*notify
)
1774 notifier_list_add(&exit_notifiers
, notify
);
1777 void qemu_remove_exit_notifier(Notifier
*notify
)
1779 notifier_list_remove(&exit_notifiers
, notify
);
1782 static void qemu_run_exit_notifiers(void)
1784 notifier_list_notify(&exit_notifiers
);
1787 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1788 const char **poptarg
, int *poptind
)
1790 const QEMUOption
*popt
;
1791 int optind
= *poptind
;
1792 char *r
= argv
[optind
];
1795 loc_set_cmdline(argv
, optind
, 1);
1797 /* Treat --foo the same as -foo. */
1800 popt
= qemu_options
;
1803 error_report("invalid option");
1806 if (!strcmp(popt
->name
, r
+ 1))
1810 if (popt
->flags
& HAS_ARG
) {
1811 if (optind
>= argc
) {
1812 error_report("requires an argument");
1815 optarg
= argv
[optind
++];
1816 loc_set_cmdline(argv
, optind
- 2, 2);
1827 int main(int argc
, char **argv
, char **envp
)
1829 const char *gdbstub_dev
= NULL
;
1831 int snapshot
, linux_boot
;
1832 const char *icount_option
= NULL
;
1833 const char *initrd_filename
;
1834 const char *kernel_filename
, *kernel_cmdline
;
1835 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1837 DisplayChangeListener
*dcl
;
1838 int cyls
, heads
, secs
, translation
;
1839 QemuOpts
*hda_opts
= NULL
, *opts
;
1842 const char *loadvm
= NULL
;
1843 QEMUMachine
*machine
;
1844 const char *cpu_model
;
1846 const char *pid_file
= NULL
;
1847 const char *incoming
= NULL
;
1848 int show_vnc_port
= 0;
1851 atexit(qemu_run_exit_notifiers
);
1852 error_set_progname(argv
[0]);
1856 qemu_cache_utils_init(envp
);
1858 QLIST_INIT (&vm_change_state_head
);
1859 os_setup_early_signal_handling();
1861 module_call_init(MODULE_INIT_MACHINE
);
1862 machine
= find_default_machine();
1864 initrd_filename
= NULL
;
1867 kernel_filename
= NULL
;
1868 kernel_cmdline
= "";
1869 cyls
= heads
= secs
= 0;
1870 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1872 for (i
= 0; i
< MAX_NODES
; i
++) {
1874 node_cpumask
[i
] = 0;
1877 assigned_devices_index
= 0;
1885 /* first pass of option parsing */
1887 while (optind
< argc
) {
1888 if (argv
[optind
][0] != '-') {
1893 const QEMUOption
*popt
;
1895 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1896 switch (popt
->index
) {
1897 case QEMU_OPTION_nodefconfig
:
1907 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1908 if (ret
< 0 && ret
!= -ENOENT
) {
1912 ret
= qemu_read_config_file(arch_config_name
);
1913 if (ret
< 0 && ret
!= -ENOENT
) {
1919 /* second pass of option parsing */
1924 if (argv
[optind
][0] != '-') {
1925 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1927 const QEMUOption
*popt
;
1929 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1930 if (!(popt
->arch_mask
& arch_type
)) {
1931 printf("Option %s not supported for this target\n", popt
->name
);
1934 switch(popt
->index
) {
1936 machine
= find_machine(optarg
);
1939 printf("Supported machines are:\n");
1940 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1942 printf("%-10s %s (alias of %s)\n",
1943 m
->alias
, m
->desc
, m
->name
);
1944 printf("%-10s %s%s\n",
1946 m
->is_default
? " (default)" : "");
1948 exit(*optarg
!= '?');
1951 case QEMU_OPTION_cpu
:
1952 /* hw initialization will check this */
1953 if (*optarg
== '?') {
1954 list_cpus(stdout
, &fprintf
, optarg
);
1960 case QEMU_OPTION_initrd
:
1961 initrd_filename
= optarg
;
1963 case QEMU_OPTION_hda
:
1965 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
1967 hda_opts
= drive_add(optarg
, HD_ALIAS
1968 ",cyls=%d,heads=%d,secs=%d%s",
1969 0, cyls
, heads
, secs
,
1970 translation
== BIOS_ATA_TRANSLATION_LBA
?
1972 translation
== BIOS_ATA_TRANSLATION_NONE
?
1973 ",trans=none" : "");
1975 case QEMU_OPTION_hdb
:
1976 case QEMU_OPTION_hdc
:
1977 case QEMU_OPTION_hdd
:
1978 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
1980 case QEMU_OPTION_drive
:
1981 drive_add(NULL
, "%s", optarg
);
1983 case QEMU_OPTION_set
:
1984 if (qemu_set_option(optarg
) != 0)
1987 case QEMU_OPTION_global
:
1988 if (qemu_global_option(optarg
) != 0)
1991 case QEMU_OPTION_mtdblock
:
1992 drive_add(optarg
, MTD_ALIAS
);
1994 case QEMU_OPTION_sd
:
1995 drive_add(optarg
, SD_ALIAS
);
1997 case QEMU_OPTION_pflash
:
1998 drive_add(optarg
, PFLASH_ALIAS
);
2000 case QEMU_OPTION_snapshot
:
2003 case QEMU_OPTION_hdachs
:
2007 cyls
= strtol(p
, (char **)&p
, 0);
2008 if (cyls
< 1 || cyls
> 16383)
2013 heads
= strtol(p
, (char **)&p
, 0);
2014 if (heads
< 1 || heads
> 16)
2019 secs
= strtol(p
, (char **)&p
, 0);
2020 if (secs
< 1 || secs
> 63)
2024 if (!strcmp(p
, "none"))
2025 translation
= BIOS_ATA_TRANSLATION_NONE
;
2026 else if (!strcmp(p
, "lba"))
2027 translation
= BIOS_ATA_TRANSLATION_LBA
;
2028 else if (!strcmp(p
, "auto"))
2029 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2032 } else if (*p
!= '\0') {
2034 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2037 if (hda_opts
!= NULL
) {
2039 snprintf(num
, sizeof(num
), "%d", cyls
);
2040 qemu_opt_set(hda_opts
, "cyls", num
);
2041 snprintf(num
, sizeof(num
), "%d", heads
);
2042 qemu_opt_set(hda_opts
, "heads", num
);
2043 snprintf(num
, sizeof(num
), "%d", secs
);
2044 qemu_opt_set(hda_opts
, "secs", num
);
2045 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2046 qemu_opt_set(hda_opts
, "trans", "lba");
2047 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2048 qemu_opt_set(hda_opts
, "trans", "none");
2052 case QEMU_OPTION_numa
:
2053 if (nb_numa_nodes
>= MAX_NODES
) {
2054 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2059 case QEMU_OPTION_nographic
:
2060 display_type
= DT_NOGRAPHIC
;
2062 #ifdef CONFIG_CURSES
2063 case QEMU_OPTION_curses
:
2064 display_type
= DT_CURSES
;
2067 case QEMU_OPTION_portrait
:
2070 case QEMU_OPTION_kernel
:
2071 kernel_filename
= optarg
;
2073 case QEMU_OPTION_append
:
2074 kernel_cmdline
= optarg
;
2076 case QEMU_OPTION_cdrom
:
2077 drive_add(optarg
, CDROM_ALIAS
);
2079 case QEMU_OPTION_boot
:
2081 static const char * const params
[] = {
2082 "order", "once", "menu", NULL
2084 char buf
[sizeof(boot_devices
)];
2085 char *standard_boot_devices
;
2088 if (!strchr(optarg
, '=')) {
2090 pstrcpy(buf
, sizeof(buf
), optarg
);
2091 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2093 "qemu: unknown boot parameter '%s' in '%s'\n",
2099 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2100 validate_bootdevices(buf
);
2101 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2104 if (get_param_value(buf
, sizeof(buf
),
2106 validate_bootdevices(buf
);
2107 standard_boot_devices
= qemu_strdup(boot_devices
);
2108 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2109 qemu_register_reset(restore_boot_devices
,
2110 standard_boot_devices
);
2112 if (get_param_value(buf
, sizeof(buf
),
2114 if (!strcmp(buf
, "on")) {
2116 } else if (!strcmp(buf
, "off")) {
2120 "qemu: invalid option value '%s'\n",
2128 case QEMU_OPTION_fda
:
2129 case QEMU_OPTION_fdb
:
2130 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2132 case QEMU_OPTION_no_fd_bootchk
:
2135 case QEMU_OPTION_netdev
:
2136 if (net_client_parse(&qemu_netdev_opts
, optarg
) == -1) {
2140 case QEMU_OPTION_net
:
2141 if (net_client_parse(&qemu_net_opts
, optarg
) == -1) {
2146 case QEMU_OPTION_tftp
:
2147 legacy_tftp_prefix
= optarg
;
2149 case QEMU_OPTION_bootp
:
2150 legacy_bootp_filename
= optarg
;
2152 case QEMU_OPTION_redir
:
2153 if (net_slirp_redir(optarg
) < 0)
2157 case QEMU_OPTION_bt
:
2158 add_device_config(DEV_BT
, optarg
);
2160 case QEMU_OPTION_audio_help
:
2161 if (!(audio_available())) {
2162 printf("Option %s not supported for this target\n", popt
->name
);
2168 case QEMU_OPTION_soundhw
:
2169 if (!(audio_available())) {
2170 printf("Option %s not supported for this target\n", popt
->name
);
2173 select_soundhw (optarg
);
2178 case QEMU_OPTION_version
:
2182 case QEMU_OPTION_m
: {
2186 value
= strtoul(optarg
, &ptr
, 10);
2188 case 0: case 'M': case 'm':
2195 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2199 /* On 32-bit hosts, QEMU is limited by virtual address space */
2200 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2201 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2204 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2205 fprintf(stderr
, "qemu: ram size too large\n");
2211 case QEMU_OPTION_mempath
:
2215 case QEMU_OPTION_mem_prealloc
:
2220 set_cpu_log(optarg
);
2223 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2225 case QEMU_OPTION_gdb
:
2226 gdbstub_dev
= optarg
;
2231 case QEMU_OPTION_bios
:
2234 case QEMU_OPTION_singlestep
:
2241 keyboard_layout
= optarg
;
2243 case QEMU_OPTION_localtime
:
2246 case QEMU_OPTION_vga
:
2247 select_vgahw (optarg
);
2254 w
= strtol(p
, (char **)&p
, 10);
2257 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2263 h
= strtol(p
, (char **)&p
, 10);
2268 depth
= strtol(p
, (char **)&p
, 10);
2269 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2270 depth
!= 24 && depth
!= 32)
2272 } else if (*p
== '\0') {
2273 depth
= graphic_depth
;
2280 graphic_depth
= depth
;
2283 case QEMU_OPTION_echr
:
2286 term_escape_char
= strtol(optarg
, &r
, 0);
2288 printf("Bad argument to echr\n");
2291 case QEMU_OPTION_monitor
:
2292 monitor_parse(optarg
, "readline");
2293 default_monitor
= 0;
2295 case QEMU_OPTION_qmp
:
2296 monitor_parse(optarg
, "control");
2297 default_monitor
= 0;
2299 case QEMU_OPTION_mon
:
2300 opts
= qemu_opts_parse(&qemu_mon_opts
, optarg
, 1);
2304 default_monitor
= 0;
2306 case QEMU_OPTION_chardev
:
2307 opts
= qemu_opts_parse(&qemu_chardev_opts
, optarg
, 1);
2313 case QEMU_OPTION_fsdev
:
2314 opts
= qemu_opts_parse(&qemu_fsdev_opts
, optarg
, 1);
2316 fprintf(stderr
, "parse error: %s\n", optarg
);
2320 case QEMU_OPTION_virtfs
: {
2321 char *arg_fsdev
= NULL
;
2322 char *arg_9p
= NULL
;
2325 opts
= qemu_opts_parse(&qemu_virtfs_opts
, optarg
, 1);
2327 fprintf(stderr
, "parse error: %s\n", optarg
);
2331 len
= strlen(",id=,path=");
2332 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2333 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2334 len
+= strlen(qemu_opt_get(opts
, "path"));
2335 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2338 fprintf(stderr
, "No memory to parse -fsdev for %s\n",
2343 sprintf(arg_fsdev
, "%s,id=%s,path=%s",
2344 qemu_opt_get(opts
, "fstype"),
2345 qemu_opt_get(opts
, "mount_tag"),
2346 qemu_opt_get(opts
, "path"));
2348 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2349 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2350 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2353 fprintf(stderr
, "No memory to parse -device for %s\n",
2358 sprintf(arg_9p
, "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2359 qemu_opt_get(opts
, "mount_tag"),
2360 qemu_opt_get(opts
, "mount_tag"));
2362 if (!qemu_opts_parse(&qemu_fsdev_opts
, arg_fsdev
, 1)) {
2363 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2367 if (!qemu_opts_parse(&qemu_device_opts
, arg_9p
, 1)) {
2368 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2372 qemu_free(arg_fsdev
);
2377 case QEMU_OPTION_serial
:
2378 add_device_config(DEV_SERIAL
, optarg
);
2380 if (strncmp(optarg
, "mon:", 4) == 0) {
2381 default_monitor
= 0;
2384 case QEMU_OPTION_watchdog
:
2387 "qemu: only one watchdog option may be given\n");
2392 case QEMU_OPTION_watchdog_action
:
2393 if (select_watchdog_action(optarg
) == -1) {
2394 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2398 case QEMU_OPTION_virtiocon
:
2399 add_device_config(DEV_VIRTCON
, optarg
);
2400 default_virtcon
= 0;
2401 if (strncmp(optarg
, "mon:", 4) == 0) {
2402 default_monitor
= 0;
2405 case QEMU_OPTION_parallel
:
2406 add_device_config(DEV_PARALLEL
, optarg
);
2407 default_parallel
= 0;
2408 if (strncmp(optarg
, "mon:", 4) == 0) {
2409 default_monitor
= 0;
2412 case QEMU_OPTION_debugcon
:
2413 add_device_config(DEV_DEBUGCON
, optarg
);
2415 case QEMU_OPTION_loadvm
:
2418 case QEMU_OPTION_full_screen
:
2422 case QEMU_OPTION_no_frame
:
2425 case QEMU_OPTION_alt_grab
:
2428 case QEMU_OPTION_ctrl_grab
:
2431 case QEMU_OPTION_no_quit
:
2434 case QEMU_OPTION_sdl
:
2435 display_type
= DT_SDL
;
2438 case QEMU_OPTION_pidfile
:
2441 case QEMU_OPTION_win2k_hack
:
2442 win2k_install_hack
= 1;
2444 case QEMU_OPTION_rtc_td_hack
:
2447 case QEMU_OPTION_acpitable
:
2448 do_acpitable_option(optarg
);
2450 case QEMU_OPTION_smbios
:
2451 do_smbios_option(optarg
);
2454 case QEMU_OPTION_enable_kvm
:
2458 case QEMU_OPTION_no_kvm
:
2462 case QEMU_OPTION_no_kvm_irqchip
: {
2467 case QEMU_OPTION_no_kvm_pit
: {
2471 case QEMU_OPTION_no_kvm_pit_reinjection
: {
2472 kvm_pit_reinject
= 0;
2475 case QEMU_OPTION_enable_nesting
: {
2480 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
2481 case QEMU_OPTION_pcidevice
:
2482 if (assigned_devices_index
>= MAX_DEV_ASSIGN_CMDLINE
) {
2483 fprintf(stderr
, "Too many assigned devices\n");
2486 assigned_devices
[assigned_devices_index
] = optarg
;
2487 assigned_devices_index
++;
2490 case QEMU_OPTION_usb
:
2493 case QEMU_OPTION_usbdevice
:
2495 add_device_config(DEV_USB
, optarg
);
2497 case QEMU_OPTION_device
:
2498 if (!qemu_opts_parse(&qemu_device_opts
, optarg
, 1)) {
2502 case QEMU_OPTION_smp
:
2505 fprintf(stderr
, "Invalid number of CPUs\n");
2508 if (max_cpus
< smp_cpus
) {
2509 fprintf(stderr
, "maxcpus must be equal to or greater than "
2513 if (max_cpus
> 255) {
2514 fprintf(stderr
, "Unsupported number of maxcpus\n");
2518 case QEMU_OPTION_vnc
:
2519 display_type
= DT_VNC
;
2520 vnc_display
= optarg
;
2522 case QEMU_OPTION_no_acpi
:
2525 case QEMU_OPTION_no_hpet
:
2528 case QEMU_OPTION_balloon
:
2529 if (balloon_parse(optarg
) < 0) {
2530 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2534 case QEMU_OPTION_no_reboot
:
2537 case QEMU_OPTION_no_shutdown
:
2540 case QEMU_OPTION_show_cursor
:
2543 case QEMU_OPTION_uuid
:
2544 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2545 fprintf(stderr
, "Fail to parse UUID string."
2546 " Wrong format.\n");
2550 case QEMU_OPTION_option_rom
:
2551 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2552 fprintf(stderr
, "Too many option ROMs\n");
2555 option_rom
[nb_option_roms
] = optarg
;
2558 case QEMU_OPTION_semihosting
:
2559 semihosting_enabled
= 1;
2561 case QEMU_OPTION_tdf
:
2564 case QEMU_OPTION_kvm_shadow_memory
:
2565 kvm_shadow_memory
= (int64_t)atoi(optarg
) * 1024 * 1024 / 4096;
2567 case QEMU_OPTION_name
:
2568 qemu_name
= qemu_strdup(optarg
);
2570 char *p
= strchr(qemu_name
, ',');
2573 if (strncmp(p
, "process=", 8)) {
2574 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2578 os_set_proc_name(p
);
2582 case QEMU_OPTION_prom_env
:
2583 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2584 fprintf(stderr
, "Too many prom variables\n");
2587 prom_envs
[nb_prom_envs
] = optarg
;
2590 case QEMU_OPTION_old_param
:
2593 case QEMU_OPTION_clock
:
2594 configure_alarms(optarg
);
2596 case QEMU_OPTION_startdate
:
2597 configure_rtc_date_offset(optarg
, 1);
2599 case QEMU_OPTION_rtc
:
2600 opts
= qemu_opts_parse(&qemu_rtc_opts
, optarg
, 0);
2604 configure_rtc(opts
);
2606 case QEMU_OPTION_tb_size
:
2607 tb_size
= strtol(optarg
, NULL
, 0);
2611 case QEMU_OPTION_icount
:
2612 icount_option
= optarg
;
2614 case QEMU_OPTION_incoming
:
2617 case QEMU_OPTION_nodefaults
:
2619 default_parallel
= 0;
2620 default_virtcon
= 0;
2621 default_monitor
= 0;
2629 case QEMU_OPTION_nvram
:
2633 case QEMU_OPTION_xen_domid
:
2634 if (!(xen_available())) {
2635 printf("Option %s not supported for this target\n", popt
->name
);
2638 xen_domid
= atoi(optarg
);
2640 case QEMU_OPTION_xen_create
:
2641 if (!(xen_available())) {
2642 printf("Option %s not supported for this target\n", popt
->name
);
2645 xen_mode
= XEN_CREATE
;
2647 case QEMU_OPTION_xen_attach
:
2648 if (!(xen_available())) {
2649 printf("Option %s not supported for this target\n", popt
->name
);
2652 xen_mode
= XEN_ATTACH
;
2654 case QEMU_OPTION_readconfig
:
2656 int ret
= qemu_read_config_file(optarg
);
2658 fprintf(stderr
, "read config %s: %s\n", optarg
,
2664 case QEMU_OPTION_writeconfig
:
2667 if (strcmp(optarg
, "-") == 0) {
2670 fp
= fopen(optarg
, "w");
2672 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2676 qemu_config_write(fp
);
2681 os_parse_cmd_args(popt
->index
, optarg
);
2687 /* If no data_dir is specified then try to find it relative to the
2690 data_dir
= os_find_datadir(argv
[0]);
2692 /* If all else fails use the install patch specified when building. */
2694 data_dir
= CONFIG_QEMU_DATADIR
;
2698 * Default to max_cpus = smp_cpus, in case the user doesn't
2699 * specify a max_cpus value.
2702 max_cpus
= smp_cpus
;
2704 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2705 if (smp_cpus
> machine
->max_cpus
) {
2706 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2707 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2712 qemu_opts_foreach(&qemu_device_opts
, default_driver_check
, NULL
, 0);
2713 qemu_opts_foreach(&qemu_global_opts
, default_driver_check
, NULL
, 0);
2715 if (machine
->no_serial
) {
2718 if (machine
->no_parallel
) {
2719 default_parallel
= 0;
2721 if (!machine
->use_virtcon
) {
2722 default_virtcon
= 0;
2724 if (machine
->no_vga
) {
2727 if (machine
->no_floppy
) {
2730 if (machine
->no_cdrom
) {
2733 if (machine
->no_sdcard
) {
2737 if (display_type
== DT_NOGRAPHIC
) {
2738 if (default_parallel
)
2739 add_device_config(DEV_PARALLEL
, "null");
2740 if (default_serial
&& default_monitor
) {
2741 add_device_config(DEV_SERIAL
, "mon:stdio");
2742 } else if (default_virtcon
&& default_monitor
) {
2743 add_device_config(DEV_VIRTCON
, "mon:stdio");
2746 add_device_config(DEV_SERIAL
, "stdio");
2747 if (default_virtcon
)
2748 add_device_config(DEV_VIRTCON
, "stdio");
2749 if (default_monitor
)
2750 monitor_parse("stdio", "readline");
2754 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2755 if (default_parallel
)
2756 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2757 if (default_monitor
)
2758 monitor_parse("vc:80Cx24C", "readline");
2759 if (default_virtcon
)
2760 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2763 vga_interface_type
= VGA_CIRRUS
;
2767 if (qemu_opts_foreach(&qemu_chardev_opts
, chardev_init_func
, NULL
, 1) != 0)
2770 if (qemu_opts_foreach(&qemu_fsdev_opts
, fsdev_init_func
, NULL
, 1) != 0) {
2777 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2783 int ret
= kvm_init(smp_cpus
);
2785 #if defined(KVM_UPSTREAM) || defined(CONFIG_NO_CPU_EMULATION)
2786 if (!kvm_available()) {
2787 printf("KVM not supported for this target\n");
2789 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2794 fprintf(stderr
, "Could not initialize KVM, will disable KVM support\n");
2800 if (qemu_init_main_loop()) {
2801 fprintf(stderr
, "qemu_init_main_loop failed\n");
2804 linux_boot
= (kernel_filename
!= NULL
);
2806 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2807 fprintf(stderr
, "-append only allowed with -kernel option\n");
2811 if (!linux_boot
&& initrd_filename
!= NULL
) {
2812 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2816 os_set_line_buffering();
2818 if (init_timer_alarm() < 0) {
2819 fprintf(stderr
, "could not initialize alarm timer\n");
2822 configure_icount(icount_option
);
2824 if (net_init_clients() < 0) {
2828 /* init the bluetooth world */
2829 if (foreach_device_config(DEV_BT
, bt_parse
))
2832 /* init the memory */
2834 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2836 /* init the dynamic translator */
2837 cpu_exec_init_all(tb_size
* 1024 * 1024);
2839 bdrv_init_with_whitelist();
2843 if (default_cdrom
) {
2844 /* we always create the cdrom drive, even if no disk is there */
2845 drive_add(NULL
, CDROM_ALIAS
);
2848 if (default_floppy
) {
2849 /* we always create at least one floppy */
2850 drive_add(NULL
, FD_ALIAS
, 0);
2853 if (default_sdcard
) {
2854 /* we always create one sd slot, even if no card is in it */
2855 drive_add(NULL
, SD_ALIAS
);
2858 /* open the virtual block devices */
2860 qemu_opts_foreach(&qemu_drive_opts
, drive_enable_snapshot
, NULL
, 0);
2861 if (qemu_opts_foreach(&qemu_drive_opts
, drive_init_func
, &machine
->use_scsi
, 1) != 0)
2864 register_savevm_live("ram", 0, 3, NULL
, ram_save_live
, NULL
,
2867 if (nb_numa_nodes
> 0) {
2870 if (nb_numa_nodes
> smp_cpus
) {
2871 nb_numa_nodes
= smp_cpus
;
2874 /* If no memory size if given for any node, assume the default case
2875 * and distribute the available memory equally across all nodes
2877 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2878 if (node_mem
[i
] != 0)
2881 if (i
== nb_numa_nodes
) {
2882 uint64_t usedmem
= 0;
2884 /* On Linux, the each node's border has to be 8MB aligned,
2885 * the final node gets the rest.
2887 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2888 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2889 usedmem
+= node_mem
[i
];
2891 node_mem
[i
] = ram_size
- usedmem
;
2894 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2895 if (node_cpumask
[i
] != 0)
2898 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2899 * must cope with this anyway, because there are BIOSes out there in
2900 * real machines which also use this scheme.
2902 if (i
== nb_numa_nodes
) {
2903 for (i
= 0; i
< smp_cpus
; i
++) {
2904 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2909 if (qemu_opts_foreach(&qemu_mon_opts
, mon_init_func
, NULL
, 1) != 0) {
2913 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2915 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2917 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2919 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2922 module_call_init(MODULE_INIT_DEVICE
);
2924 if (qemu_opts_foreach(&qemu_device_opts
, device_help_func
, NULL
, 0) != 0)
2928 i
= select_watchdog(watchdog
);
2930 exit (i
== 1 ? 1 : 0);
2933 if (machine
->compat_props
) {
2934 qdev_prop_register_global_list(machine
->compat_props
);
2938 machine
->init(ram_size
, boot_devices
,
2939 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2941 cpu_synchronize_all_post_init();
2943 /* must be after terminal init, SDL library changes signal handlers */
2944 os_setup_signal_handling();
2948 current_machine
= machine
;
2950 /* init USB devices */
2952 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2956 /* init generic devices */
2957 if (qemu_opts_foreach(&qemu_device_opts
, device_init_func
, NULL
, 1) != 0)
2960 net_check_clients();
2962 /* just use the first displaystate for the moment */
2963 ds
= get_displaystate();
2965 if (display_type
== DT_DEFAULT
) {
2966 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
2967 display_type
= DT_SDL
;
2969 display_type
= DT_VNC
;
2970 vnc_display
= "localhost:0,to=99";
2976 switch (display_type
) {
2979 #if defined(CONFIG_CURSES)
2981 curses_display_init(ds
, full_screen
);
2984 #if defined(CONFIG_SDL)
2986 sdl_display_init(ds
, full_screen
, no_frame
);
2988 #elif defined(CONFIG_COCOA)
2990 cocoa_display_init(ds
, full_screen
);
2994 vnc_display_init(ds
);
2995 if (vnc_display_open(ds
, vnc_display
) < 0)
2998 if (show_vnc_port
) {
2999 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3007 dcl
= ds
->listeners
;
3008 while (dcl
!= NULL
) {
3009 if (dcl
->dpy_refresh
!= NULL
) {
3010 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
3011 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
3017 if (display_type
== DT_NOGRAPHIC
|| display_type
== DT_VNC
) {
3018 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
3019 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
3022 text_consoles_set_display(ds
);
3024 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3025 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3030 qdev_machine_creation_done();
3032 if (rom_load_all() != 0) {
3033 fprintf(stderr
, "rom loading failed\n");
3037 qemu_system_reset();
3039 if (load_vmstate(loadvm
) < 0) {
3045 qemu_start_incoming_migration(incoming
);
3046 } else if (autostart
) {