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>
50 #ifdef CONFIG_SIMPLE_TRACE
56 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
58 #include <sys/sysctl.h>
67 #include <linux/ppdev.h>
68 #include <linux/parport.h>
72 #include <sys/ethernet.h>
73 #include <sys/sockio.h>
74 #include <netinet/arp.h>
75 #include <netinet/in_systm.h>
76 #include <netinet/ip.h>
77 #include <netinet/ip_icmp.h> // must come after ip.h
78 #include <netinet/udp.h>
79 #include <netinet/tcp.h>
87 #if defined(__OpenBSD__)
91 #if defined(CONFIG_VDE)
92 #include <libvdeplug.h>
100 #if defined(__APPLE__) || defined(main)
102 int qemu_main(int argc
, char **argv
, char **envp
);
103 int main(int argc
, char **argv
)
105 return qemu_main(argc
, argv
, NULL
);
108 #define main qemu_main
110 #endif /* CONFIG_SDL */
114 #define main qemu_main
115 #endif /* CONFIG_COCOA */
118 #include "hw/boards.h"
120 #include "hw/pcmcia.h"
125 #include "hw/watchdog.h"
126 #include "hw/smbios.h"
129 #include "hw/loader.h"
132 #include "net/slirp.h"
137 #include "qemu-timer.h"
138 #include "qemu-char.h"
139 #include "cache-utils.h"
141 #include "blockdev.h"
142 #include "block-migration.h"
144 #include "audio/audio.h"
145 #include "migration.h"
147 #include "qemu-option.h"
148 #include "qemu-config.h"
149 #include "qemu-objects.h"
150 #include "qemu-options.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 int incoming_expected
; /* Started with -incoming and waiting for incoming */
187 static int rtc_utc
= 1;
188 static int rtc_date_offset
= -1; /* -1 means no change */
189 QEMUClock
*rtc_clock
;
190 int vga_interface_type
= VGA_NONE
;
191 static int full_screen
= 0;
193 static int no_frame
= 0;
196 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
197 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
198 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
199 int win2k_install_hack
= 0;
207 const char *vnc_display
;
208 int acpi_enabled
= 1;
214 int graphic_rotate
= 0;
215 uint8_t irq0override
= 1;
216 const char *watchdog
;
217 const char *option_rom
[MAX_OPTION_ROMS
];
219 int semihosting_enabled
= 0;
221 const char *qemu_name
;
224 unsigned int nb_prom_envs
= 0;
225 const char *prom_envs
[MAX_PROM_ENVS
];
229 uint64_t node_mem
[MAX_NODES
];
230 uint64_t node_cpumask
[MAX_NODES
];
232 static QEMUTimer
*nographic_timer
;
234 uint8_t qemu_uuid
[16];
236 static QEMUBootSetHandler
*boot_set_handler
;
237 static void *boot_set_opaque
;
239 static NotifierList exit_notifiers
=
240 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
244 enum xen_mode xen_mode
= XEN_EMULATE
;
246 static int default_serial
= 1;
247 static int default_parallel
= 1;
248 static int default_virtcon
= 1;
249 static int default_monitor
= 1;
250 static int default_vga
= 1;
251 static int default_floppy
= 1;
252 static int default_cdrom
= 1;
253 static int default_sdcard
= 1;
259 { .driver
= "isa-serial", .flag
= &default_serial
},
260 { .driver
= "isa-parallel", .flag
= &default_parallel
},
261 { .driver
= "isa-fdc", .flag
= &default_floppy
},
262 { .driver
= "ide-drive", .flag
= &default_cdrom
},
263 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
264 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
265 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
266 { .driver
= "VGA", .flag
= &default_vga
},
267 { .driver
= "cirrus-vga", .flag
= &default_vga
},
268 { .driver
= "vmware-svga", .flag
= &default_vga
},
271 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
273 const char *driver
= qemu_opt_get(opts
, "driver");
278 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
279 if (strcmp(default_list
[i
].driver
, driver
) != 0)
281 *(default_list
[i
].flag
) = 0;
286 /***********************************************************/
287 /* real time host monotonic timer */
289 /* compute with 96 bit intermediate result: (a*b)/c */
290 uint64_t muldiv64(uint64_t a
, uint32_t b
, uint32_t c
)
295 #ifdef HOST_WORDS_BIGENDIAN
305 rl
= (uint64_t)u
.l
.low
* (uint64_t)b
;
306 rh
= (uint64_t)u
.l
.high
* (uint64_t)b
;
309 res
.l
.low
= (((rh
% c
) << 32) + (rl
& 0xffffffff)) / c
;
313 /***********************************************************/
314 /* host time/date access */
315 void qemu_get_timedate(struct tm
*tm
, int offset
)
322 if (rtc_date_offset
== -1) {
326 ret
= localtime(&ti
);
328 ti
-= rtc_date_offset
;
332 memcpy(tm
, ret
, sizeof(struct tm
));
335 int qemu_timedate_diff(struct tm
*tm
)
339 if (rtc_date_offset
== -1)
341 seconds
= mktimegm(tm
);
343 seconds
= mktime(tm
);
345 seconds
= mktimegm(tm
) + rtc_date_offset
;
347 return seconds
- time(NULL
);
350 void rtc_change_mon_event(struct tm
*tm
)
354 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
355 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
356 qobject_decref(data
);
359 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
361 time_t rtc_start_date
;
364 if (!strcmp(startdate
, "now") && legacy
) {
365 rtc_date_offset
= -1;
367 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
375 } else if (sscanf(startdate
, "%d-%d-%d",
387 rtc_start_date
= mktimegm(&tm
);
388 if (rtc_start_date
== -1) {
390 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
391 "'2006-06-17T16:01:21' or '2006-06-17'\n");
394 rtc_date_offset
= time(NULL
) - rtc_start_date
;
398 static void configure_rtc(QemuOpts
*opts
)
402 value
= qemu_opt_get(opts
, "base");
404 if (!strcmp(value
, "utc")) {
406 } else if (!strcmp(value
, "localtime")) {
409 configure_rtc_date_offset(value
, 0);
412 value
= qemu_opt_get(opts
, "clock");
414 if (!strcmp(value
, "host")) {
415 rtc_clock
= host_clock
;
416 } else if (!strcmp(value
, "vm")) {
417 rtc_clock
= vm_clock
;
419 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
423 value
= qemu_opt_get(opts
, "driftfix");
425 if (!strcmp(value
, "slew")) {
427 } else if (!strcmp(value
, "none")) {
430 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
436 /***********************************************************/
437 /* Bluetooth support */
440 static struct HCIInfo
*hci_table
[MAX_NICS
];
442 static struct bt_vlan_s
{
443 struct bt_scatternet_s net
;
445 struct bt_vlan_s
*next
;
448 /* find or alloc a new bluetooth "VLAN" */
449 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
451 struct bt_vlan_s
**pvlan
, *vlan
;
452 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
456 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
458 pvlan
= &first_bt_vlan
;
459 while (*pvlan
!= NULL
)
460 pvlan
= &(*pvlan
)->next
;
465 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
469 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
474 static struct HCIInfo null_hci
= {
475 .cmd_send
= null_hci_send
,
476 .sco_send
= null_hci_send
,
477 .acl_send
= null_hci_send
,
478 .bdaddr_set
= null_hci_addr_set
,
481 struct HCIInfo
*qemu_next_hci(void)
483 if (cur_hci
== nb_hcis
)
486 return hci_table
[cur_hci
++];
489 static struct HCIInfo
*hci_init(const char *str
)
492 struct bt_scatternet_s
*vlan
= 0;
494 if (!strcmp(str
, "null"))
497 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
499 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
500 else if (!strncmp(str
, "hci", 3)) {
503 if (!strncmp(str
+ 3, ",vlan=", 6)) {
504 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
509 vlan
= qemu_find_bt_vlan(0);
511 return bt_new_hci(vlan
);
514 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
519 static int bt_hci_parse(const char *str
)
524 if (nb_hcis
>= MAX_NICS
) {
525 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
538 bdaddr
.b
[5] = 0x56 + nb_hcis
;
539 hci
->bdaddr_set(hci
, bdaddr
.b
);
541 hci_table
[nb_hcis
++] = hci
;
546 static void bt_vhci_add(int vlan_id
)
548 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
551 fprintf(stderr
, "qemu: warning: adding a VHCI to "
552 "an empty scatternet %i\n", vlan_id
);
554 bt_vhci_init(bt_new_hci(vlan
));
557 static struct bt_device_s
*bt_device_add(const char *opt
)
559 struct bt_scatternet_s
*vlan
;
561 char *endp
= strstr(opt
, ",vlan=");
562 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
565 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
568 vlan_id
= strtol(endp
+ 6, &endp
, 0);
570 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
575 vlan
= qemu_find_bt_vlan(vlan_id
);
578 fprintf(stderr
, "qemu: warning: adding a slave device to "
579 "an empty scatternet %i\n", vlan_id
);
581 if (!strcmp(devname
, "keyboard"))
582 return bt_keyboard_init(vlan
);
584 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
588 static int bt_parse(const char *opt
)
590 const char *endp
, *p
;
593 if (strstart(opt
, "hci", &endp
)) {
594 if (!*endp
|| *endp
== ',') {
596 if (!strstart(endp
, ",vlan=", 0))
599 return bt_hci_parse(opt
);
601 } else if (strstart(opt
, "vhci", &endp
)) {
602 if (!*endp
|| *endp
== ',') {
604 if (strstart(endp
, ",vlan=", &p
)) {
605 vlan
= strtol(p
, (char **) &endp
, 0);
607 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
611 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
620 } else if (strstart(opt
, "device:", &endp
))
621 return !bt_device_add(endp
);
623 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
627 /***********************************************************/
628 /* QEMU Block devices */
630 #define HD_ALIAS "index=%d,media=disk"
631 #define CDROM_ALIAS "index=2,media=cdrom"
632 #define FD_ALIAS "index=%d,if=floppy"
633 #define PFLASH_ALIAS "if=pflash"
634 #define MTD_ALIAS "if=mtd"
635 #define SD_ALIAS "index=0,if=sd"
637 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
639 int *use_scsi
= opaque
;
642 if (drive_init(opts
, *use_scsi
, &fatal_error
) == NULL
) {
649 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
651 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
652 qemu_opt_set(opts
, "snapshot", "on");
657 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
659 boot_set_handler
= func
;
660 boot_set_opaque
= opaque
;
663 int qemu_boot_set(const char *boot_devices
)
665 if (!boot_set_handler
) {
668 return boot_set_handler(boot_set_opaque
, boot_devices
);
671 static void validate_bootdevices(char *devices
)
673 /* We just do some generic consistency checks */
677 for (p
= devices
; *p
!= '\0'; p
++) {
678 /* Allowed boot devices are:
679 * a-b: floppy disk drives
680 * c-f: IDE disk drives
681 * g-m: machine implementation dependant drives
682 * n-p: network devices
683 * It's up to each machine implementation to check if the given boot
684 * devices match the actual hardware implementation and firmware
687 if (*p
< 'a' || *p
> 'p') {
688 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
691 if (bitmap
& (1 << (*p
- 'a'))) {
692 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
695 bitmap
|= 1 << (*p
- 'a');
699 static void restore_boot_devices(void *opaque
)
701 char *standard_boot_devices
= opaque
;
702 static int first
= 1;
704 /* Restore boot order and remove ourselves after the first boot */
710 qemu_boot_set(standard_boot_devices
);
712 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
713 qemu_free(standard_boot_devices
);
716 static void numa_add(const char *optarg
)
720 unsigned long long value
, endvalue
;
723 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
724 if (!strcmp(option
, "node")) {
725 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
726 nodenr
= nb_numa_nodes
;
728 nodenr
= strtoull(option
, NULL
, 10);
731 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
732 node_mem
[nodenr
] = 0;
734 value
= strtoull(option
, &endptr
, 0);
736 case 0: case 'M': case 'm':
743 node_mem
[nodenr
] = value
;
745 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
746 node_cpumask
[nodenr
] = 0;
748 value
= strtoull(option
, &endptr
, 10);
751 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
753 if (*endptr
== '-') {
754 endvalue
= strtoull(endptr
+1, &endptr
, 10);
755 if (endvalue
>= 63) {
758 "only 63 CPUs in NUMA mode supported.\n");
760 value
= (2ULL << endvalue
) - (1ULL << value
);
762 value
= 1ULL << value
;
765 node_cpumask
[nodenr
] = value
;
772 static void smp_parse(const char *optarg
)
774 int smp
, sockets
= 0, threads
= 0, cores
= 0;
778 smp
= strtoul(optarg
, &endptr
, 10);
779 if (endptr
!= optarg
) {
780 if (*endptr
== ',') {
784 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
785 sockets
= strtoull(option
, NULL
, 10);
786 if (get_param_value(option
, 128, "cores", endptr
) != 0)
787 cores
= strtoull(option
, NULL
, 10);
788 if (get_param_value(option
, 128, "threads", endptr
) != 0)
789 threads
= strtoull(option
, NULL
, 10);
790 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
791 max_cpus
= strtoull(option
, NULL
, 10);
793 /* compute missing values, prefer sockets over cores over threads */
794 if (smp
== 0 || sockets
== 0) {
795 sockets
= sockets
> 0 ? sockets
: 1;
796 cores
= cores
> 0 ? cores
: 1;
797 threads
= threads
> 0 ? threads
: 1;
799 smp
= cores
* threads
* sockets
;
803 threads
= threads
> 0 ? threads
: 1;
804 cores
= smp
/ (sockets
* threads
);
806 threads
= smp
/ (cores
* sockets
);
810 smp_cores
= cores
> 0 ? cores
: 1;
811 smp_threads
= threads
> 0 ? threads
: 1;
816 /***********************************************************/
819 static int usb_device_add(const char *devname
)
822 USBDevice
*dev
= NULL
;
827 /* drivers with .usbdevice_name entry in USBDeviceInfo */
828 dev
= usbdevice_create(devname
);
833 if (strstart(devname
, "host:", &p
)) {
834 dev
= usb_host_device_open(p
);
835 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
836 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
837 bt_new_hci(qemu_find_bt_vlan(0)));
848 static int usb_device_del(const char *devname
)
853 if (strstart(devname
, "host:", &p
))
854 return usb_host_device_close(p
);
859 p
= strchr(devname
, '.');
862 bus_num
= strtoul(devname
, NULL
, 0);
863 addr
= strtoul(p
+ 1, NULL
, 0);
865 return usb_device_delete_addr(bus_num
, addr
);
868 static int usb_parse(const char *cmdline
)
871 r
= usb_device_add(cmdline
);
873 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
878 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
880 const char *devname
= qdict_get_str(qdict
, "devname");
881 if (usb_device_add(devname
) < 0) {
882 error_report("could not add USB device '%s'", devname
);
886 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
888 const char *devname
= qdict_get_str(qdict
, "devname");
889 if (usb_device_del(devname
) < 0) {
890 error_report("could not delete USB device '%s'", devname
);
894 /***********************************************************/
897 static struct pcmcia_socket_entry_s
{
898 PCMCIASocket
*socket
;
899 struct pcmcia_socket_entry_s
*next
;
900 } *pcmcia_sockets
= 0;
902 void pcmcia_socket_register(PCMCIASocket
*socket
)
904 struct pcmcia_socket_entry_s
*entry
;
906 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
907 entry
->socket
= socket
;
908 entry
->next
= pcmcia_sockets
;
909 pcmcia_sockets
= entry
;
912 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
914 struct pcmcia_socket_entry_s
*entry
, **ptr
;
916 ptr
= &pcmcia_sockets
;
917 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
918 if (entry
->socket
== socket
) {
924 void pcmcia_info(Monitor
*mon
)
926 struct pcmcia_socket_entry_s
*iter
;
929 monitor_printf(mon
, "No PCMCIA sockets\n");
931 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
932 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
933 iter
->socket
->attached
? iter
->socket
->card_string
:
937 /***********************************************************/
940 typedef struct IOHandlerRecord
{
942 IOCanReadHandler
*fd_read_poll
;
949 QLIST_ENTRY(IOHandlerRecord
) next
;
952 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
953 QLIST_HEAD_INITIALIZER(io_handlers
);
956 /* XXX: fd_read_poll should be suppressed, but an API change is
957 necessary in the character devices to suppress fd_can_read(). */
958 int qemu_set_fd_handler2(int fd
,
959 IOCanReadHandler
*fd_read_poll
,
964 IOHandlerRecord
*ioh
;
966 if (!fd_read
&& !fd_write
) {
967 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
974 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
978 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
979 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
982 ioh
->fd_read_poll
= fd_read_poll
;
983 ioh
->fd_read
= fd_read
;
984 ioh
->fd_write
= fd_write
;
985 ioh
->opaque
= opaque
;
991 int qemu_set_fd_handler(int fd
,
996 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
999 /***********************************************************/
1000 /* machine registration */
1002 static QEMUMachine
*first_machine
= NULL
;
1003 QEMUMachine
*current_machine
= NULL
;
1005 int qemu_register_machine(QEMUMachine
*m
)
1008 pm
= &first_machine
;
1016 static QEMUMachine
*find_machine(const char *name
)
1020 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1021 if (!strcmp(m
->name
, name
))
1023 if (m
->alias
&& !strcmp(m
->alias
, name
))
1029 static QEMUMachine
*find_default_machine(void)
1033 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1034 if (m
->is_default
) {
1041 /***********************************************************/
1042 /* main execution loop */
1044 static void gui_update(void *opaque
)
1046 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1047 DisplayState
*ds
= opaque
;
1048 DisplayChangeListener
*dcl
= ds
->listeners
;
1050 qemu_flush_coalesced_mmio_buffer();
1053 while (dcl
!= NULL
) {
1054 if (dcl
->gui_timer_interval
&&
1055 dcl
->gui_timer_interval
< interval
)
1056 interval
= dcl
->gui_timer_interval
;
1059 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1062 static void nographic_update(void *opaque
)
1064 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1066 qemu_flush_coalesced_mmio_buffer();
1067 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1070 struct vm_change_state_entry
{
1071 VMChangeStateHandler
*cb
;
1073 QLIST_ENTRY (vm_change_state_entry
) entries
;
1076 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1078 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1081 VMChangeStateEntry
*e
;
1083 e
= qemu_mallocz(sizeof (*e
));
1087 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1091 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1093 QLIST_REMOVE (e
, entries
);
1097 void vm_state_notify(int running
, int reason
)
1099 VMChangeStateEntry
*e
;
1101 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1102 e
->cb(e
->opaque
, running
, reason
);
1111 vm_state_notify(1, 0);
1113 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1117 /* reset/shutdown handler */
1119 typedef struct QEMUResetEntry
{
1120 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1121 QEMUResetHandler
*func
;
1125 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1126 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1127 static int reset_requested
;
1128 static int shutdown_requested
;
1129 static int powerdown_requested
;
1130 int debug_requested
;
1131 int vmstop_requested
;
1133 int qemu_shutdown_requested(void)
1135 int r
= shutdown_requested
;
1136 shutdown_requested
= 0;
1140 int qemu_reset_requested(void)
1142 int r
= reset_requested
;
1143 reset_requested
= 0;
1147 int qemu_powerdown_requested(void)
1149 int r
= powerdown_requested
;
1150 powerdown_requested
= 0;
1154 static int qemu_debug_requested(void)
1156 int r
= debug_requested
;
1157 debug_requested
= 0;
1161 static int qemu_vmstop_requested(void)
1163 int r
= vmstop_requested
;
1164 vmstop_requested
= 0;
1168 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1170 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1173 re
->opaque
= opaque
;
1174 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1177 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1181 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1182 if (re
->func
== func
&& re
->opaque
== opaque
) {
1183 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1190 void qemu_system_reset(void)
1192 QEMUResetEntry
*re
, *nre
;
1194 /* reset all devices */
1195 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1196 re
->func(re
->opaque
);
1198 monitor_protocol_event(QEVENT_RESET
, NULL
);
1199 cpu_synchronize_all_post_reset();
1202 void qemu_system_reset_request(void)
1205 shutdown_requested
= 1;
1207 reset_requested
= 1;
1209 qemu_notify_event();
1212 void qemu_system_shutdown_request(void)
1214 shutdown_requested
= 1;
1215 qemu_notify_event();
1218 void qemu_system_powerdown_request(void)
1220 powerdown_requested
= 1;
1221 qemu_notify_event();
1224 void main_loop_wait(int nonblocking
)
1226 IOHandlerRecord
*ioh
;
1227 fd_set rfds
, wfds
, xfds
;
1235 timeout
= qemu_calculate_timeout();
1236 qemu_bh_update_timeout(&timeout
);
1239 os_host_main_loop_wait(&timeout
);
1241 /* poll any events */
1242 /* XXX: separate device handlers from system ones */
1247 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1251 (!ioh
->fd_read_poll
||
1252 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1253 FD_SET(ioh
->fd
, &rfds
);
1257 if (ioh
->fd_write
) {
1258 FD_SET(ioh
->fd
, &wfds
);
1264 tv
.tv_sec
= timeout
/ 1000;
1265 tv
.tv_usec
= (timeout
% 1000) * 1000;
1267 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1269 qemu_mutex_unlock_iothread();
1270 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1271 qemu_mutex_lock_iothread();
1273 IOHandlerRecord
*pioh
;
1275 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1277 QLIST_REMOVE(ioh
, next
);
1281 if (ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1282 ioh
->fd_read(ioh
->opaque
);
1284 if (ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1285 ioh
->fd_write(ioh
->opaque
);
1290 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1292 qemu_run_all_timers();
1294 /* Check bottom-halves last in case any of the earlier events triggered
1300 static int vm_can_run(void)
1302 if (powerdown_requested
)
1304 if (reset_requested
)
1306 if (shutdown_requested
)
1308 if (debug_requested
)
1313 qemu_irq qemu_system_powerdown
;
1315 static void main_loop(void)
1319 qemu_main_loop_start();
1323 bool nonblocking
= false;
1324 #ifdef CONFIG_PROFILER
1327 #ifndef CONFIG_IOTHREAD
1328 nonblocking
= cpu_exec_all();
1330 #ifdef CONFIG_PROFILER
1331 ti
= profile_getclock();
1333 main_loop_wait(nonblocking
);
1334 #ifdef CONFIG_PROFILER
1335 dev_time
+= profile_getclock() - ti
;
1337 } while (vm_can_run());
1339 if ((r
= qemu_debug_requested())) {
1342 if (qemu_shutdown_requested()) {
1343 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1350 if (qemu_reset_requested()) {
1352 qemu_system_reset();
1355 if (qemu_powerdown_requested()) {
1356 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1357 qemu_irq_raise(qemu_system_powerdown
);
1359 if ((r
= qemu_vmstop_requested())) {
1367 static void version(void)
1369 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1372 static void help(int exitcode
)
1374 const char *options_help
=
1375 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1377 #define DEFHEADING(text) stringify(text) "\n"
1378 #include "qemu-options.def"
1384 printf("usage: %s [options] [disk_image]\n"
1386 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1389 "During emulation, the following keys are useful:\n"
1390 "ctrl-alt-f toggle full screen\n"
1391 "ctrl-alt-n switch to virtual console 'n'\n"
1392 "ctrl-alt toggle mouse and keyboard grab\n"
1394 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1400 #define HAS_ARG 0x0001
1402 typedef struct QEMUOption
{
1409 static const QEMUOption qemu_options
[] = {
1410 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1411 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1412 { option, opt_arg, opt_enum, arch_mask },
1413 #define DEFHEADING(text)
1414 #include "qemu-options.def"
1420 static void select_vgahw (const char *p
)
1425 vga_interface_type
= VGA_NONE
;
1426 if (strstart(p
, "std", &opts
)) {
1427 vga_interface_type
= VGA_STD
;
1428 } else if (strstart(p
, "cirrus", &opts
)) {
1429 vga_interface_type
= VGA_CIRRUS
;
1430 } else if (strstart(p
, "vmware", &opts
)) {
1431 vga_interface_type
= VGA_VMWARE
;
1432 } else if (strstart(p
, "xenfb", &opts
)) {
1433 vga_interface_type
= VGA_XENFB
;
1434 } else if (!strstart(p
, "none", &opts
)) {
1436 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1440 const char *nextopt
;
1442 if (strstart(opts
, ",retrace=", &nextopt
)) {
1444 if (strstart(opts
, "dumb", &nextopt
))
1445 vga_retrace_method
= VGA_RETRACE_DUMB
;
1446 else if (strstart(opts
, "precise", &nextopt
))
1447 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1448 else goto invalid_vga
;
1449 } else goto invalid_vga
;
1454 static int balloon_parse(const char *arg
)
1458 if (strcmp(arg
, "none") == 0) {
1462 if (!strncmp(arg
, "virtio", 6)) {
1463 if (arg
[6] == ',') {
1464 /* have params -> parse them */
1465 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1469 /* create empty opts */
1470 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1472 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1479 char *qemu_find_file(int type
, const char *name
)
1485 /* If name contains path separators then try it as a straight path. */
1486 if ((strchr(name
, '/') || strchr(name
, '\\'))
1487 && access(name
, R_OK
) == 0) {
1488 return qemu_strdup(name
);
1491 case QEMU_FILE_TYPE_BIOS
:
1494 case QEMU_FILE_TYPE_KEYMAP
:
1495 subdir
= "keymaps/";
1500 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1501 buf
= qemu_mallocz(len
);
1502 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1503 if (access(buf
, R_OK
)) {
1510 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1512 return qdev_device_help(opts
);
1515 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1519 dev
= qdev_device_add(opts
);
1525 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1527 CharDriverState
*chr
;
1529 chr
= qemu_chr_open_opts(opts
, NULL
);
1535 #ifdef CONFIG_VIRTFS
1536 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1539 ret
= qemu_fsdev_add(opts
);
1545 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1547 CharDriverState
*chr
;
1548 const char *chardev
;
1552 mode
= qemu_opt_get(opts
, "mode");
1556 if (strcmp(mode
, "readline") == 0) {
1557 flags
= MONITOR_USE_READLINE
;
1558 } else if (strcmp(mode
, "control") == 0) {
1559 flags
= MONITOR_USE_CONTROL
;
1561 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1565 if (qemu_opt_get_bool(opts
, "pretty", 0))
1566 flags
|= MONITOR_USE_PRETTY
;
1568 if (qemu_opt_get_bool(opts
, "default", 0))
1569 flags
|= MONITOR_IS_DEFAULT
;
1571 chardev
= qemu_opt_get(opts
, "chardev");
1572 chr
= qemu_chr_find(chardev
);
1574 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1578 monitor_init(chr
, flags
);
1582 static void monitor_parse(const char *optarg
, const char *mode
)
1584 static int monitor_device_index
= 0;
1590 if (strstart(optarg
, "chardev:", &p
)) {
1591 snprintf(label
, sizeof(label
), "%s", p
);
1593 snprintf(label
, sizeof(label
), "compat_monitor%d",
1594 monitor_device_index
);
1595 if (monitor_device_index
== 0) {
1598 opts
= qemu_chr_parse_compat(label
, optarg
);
1600 fprintf(stderr
, "parse error: %s\n", optarg
);
1605 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1607 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1610 qemu_opt_set(opts
, "mode", mode
);
1611 qemu_opt_set(opts
, "chardev", label
);
1613 qemu_opt_set(opts
, "default", "on");
1614 monitor_device_index
++;
1617 struct device_config
{
1619 DEV_USB
, /* -usbdevice */
1621 DEV_SERIAL
, /* -serial */
1622 DEV_PARALLEL
, /* -parallel */
1623 DEV_VIRTCON
, /* -virtioconsole */
1624 DEV_DEBUGCON
, /* -debugcon */
1626 const char *cmdline
;
1627 QTAILQ_ENTRY(device_config
) next
;
1629 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1631 static void add_device_config(int type
, const char *cmdline
)
1633 struct device_config
*conf
;
1635 conf
= qemu_mallocz(sizeof(*conf
));
1637 conf
->cmdline
= cmdline
;
1638 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1641 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1643 struct device_config
*conf
;
1646 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1647 if (conf
->type
!= type
)
1649 rc
= func(conf
->cmdline
);
1656 static int serial_parse(const char *devname
)
1658 static int index
= 0;
1661 if (strcmp(devname
, "none") == 0)
1663 if (index
== MAX_SERIAL_PORTS
) {
1664 fprintf(stderr
, "qemu: too many serial ports\n");
1667 snprintf(label
, sizeof(label
), "serial%d", index
);
1668 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1669 if (!serial_hds
[index
]) {
1670 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1671 devname
, strerror(errno
));
1678 static int parallel_parse(const char *devname
)
1680 static int index
= 0;
1683 if (strcmp(devname
, "none") == 0)
1685 if (index
== MAX_PARALLEL_PORTS
) {
1686 fprintf(stderr
, "qemu: too many parallel ports\n");
1689 snprintf(label
, sizeof(label
), "parallel%d", index
);
1690 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1691 if (!parallel_hds
[index
]) {
1692 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1693 devname
, strerror(errno
));
1700 static int virtcon_parse(const char *devname
)
1702 QemuOptsList
*device
= qemu_find_opts("device");
1703 static int index
= 0;
1705 QemuOpts
*bus_opts
, *dev_opts
;
1707 if (strcmp(devname
, "none") == 0)
1709 if (index
== MAX_VIRTIO_CONSOLES
) {
1710 fprintf(stderr
, "qemu: too many virtio consoles\n");
1714 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1715 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1717 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1718 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1720 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1721 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1722 if (!virtcon_hds
[index
]) {
1723 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1724 devname
, strerror(errno
));
1727 qemu_opt_set(dev_opts
, "chardev", label
);
1733 static int debugcon_parse(const char *devname
)
1737 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1740 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1742 fprintf(stderr
, "qemu: already have a debugcon device\n");
1745 qemu_opt_set(opts
, "driver", "isa-debugcon");
1746 qemu_opt_set(opts
, "chardev", "debugcon");
1750 void qemu_add_exit_notifier(Notifier
*notify
)
1752 notifier_list_add(&exit_notifiers
, notify
);
1755 void qemu_remove_exit_notifier(Notifier
*notify
)
1757 notifier_list_remove(&exit_notifiers
, notify
);
1760 static void qemu_run_exit_notifiers(void)
1762 notifier_list_notify(&exit_notifiers
);
1765 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1766 const char **poptarg
, int *poptind
)
1768 const QEMUOption
*popt
;
1769 int optind
= *poptind
;
1770 char *r
= argv
[optind
];
1773 loc_set_cmdline(argv
, optind
, 1);
1775 /* Treat --foo the same as -foo. */
1778 popt
= qemu_options
;
1781 error_report("invalid option");
1784 if (!strcmp(popt
->name
, r
+ 1))
1788 if (popt
->flags
& HAS_ARG
) {
1789 if (optind
>= argc
) {
1790 error_report("requires an argument");
1793 optarg
= argv
[optind
++];
1794 loc_set_cmdline(argv
, optind
- 2, 2);
1805 int main(int argc
, char **argv
, char **envp
)
1807 const char *gdbstub_dev
= NULL
;
1809 int snapshot
, linux_boot
;
1810 const char *icount_option
= NULL
;
1811 const char *initrd_filename
;
1812 const char *kernel_filename
, *kernel_cmdline
;
1813 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1815 DisplayChangeListener
*dcl
;
1816 int cyls
, heads
, secs
, translation
;
1817 QemuOpts
*hda_opts
= NULL
, *opts
;
1818 QemuOptsList
*olist
;
1821 const char *loadvm
= NULL
;
1822 QEMUMachine
*machine
;
1823 const char *cpu_model
;
1825 const char *pid_file
= NULL
;
1826 const char *incoming
= NULL
;
1827 int show_vnc_port
= 0;
1830 #ifdef CONFIG_SIMPLE_TRACE
1831 const char *trace_file
= NULL
;
1833 atexit(qemu_run_exit_notifiers
);
1834 error_set_progname(argv
[0]);
1838 qemu_cache_utils_init(envp
);
1840 QLIST_INIT (&vm_change_state_head
);
1841 os_setup_early_signal_handling();
1843 module_call_init(MODULE_INIT_MACHINE
);
1844 machine
= find_default_machine();
1846 initrd_filename
= NULL
;
1849 kernel_filename
= NULL
;
1850 kernel_cmdline
= "";
1851 cyls
= heads
= secs
= 0;
1852 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1854 for (i
= 0; i
< MAX_NODES
; i
++) {
1856 node_cpumask
[i
] = 0;
1865 #ifdef CONFIG_VIRTFS
1866 qemu_add_opts(&qemu_fsdev_opts
);
1867 qemu_add_opts(&qemu_virtfs_opts
);
1870 /* first pass of option parsing */
1872 while (optind
< argc
) {
1873 if (argv
[optind
][0] != '-') {
1878 const QEMUOption
*popt
;
1880 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1881 switch (popt
->index
) {
1882 case QEMU_OPTION_nodefconfig
:
1892 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1893 if (ret
< 0 && ret
!= -ENOENT
) {
1897 ret
= qemu_read_config_file(arch_config_name
);
1898 if (ret
< 0 && ret
!= -ENOENT
) {
1904 /* second pass of option parsing */
1909 if (argv
[optind
][0] != '-') {
1910 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1912 const QEMUOption
*popt
;
1914 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1915 if (!(popt
->arch_mask
& arch_type
)) {
1916 printf("Option %s not supported for this target\n", popt
->name
);
1919 switch(popt
->index
) {
1921 machine
= find_machine(optarg
);
1924 printf("Supported machines are:\n");
1925 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1927 printf("%-10s %s (alias of %s)\n",
1928 m
->alias
, m
->desc
, m
->name
);
1929 printf("%-10s %s%s\n",
1931 m
->is_default
? " (default)" : "");
1933 exit(*optarg
!= '?');
1936 case QEMU_OPTION_cpu
:
1937 /* hw initialization will check this */
1938 if (*optarg
== '?') {
1939 list_cpus(stdout
, &fprintf
, optarg
);
1945 case QEMU_OPTION_initrd
:
1946 initrd_filename
= optarg
;
1948 case QEMU_OPTION_hda
:
1950 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
1952 hda_opts
= drive_add(optarg
, HD_ALIAS
1953 ",cyls=%d,heads=%d,secs=%d%s",
1954 0, cyls
, heads
, secs
,
1955 translation
== BIOS_ATA_TRANSLATION_LBA
?
1957 translation
== BIOS_ATA_TRANSLATION_NONE
?
1958 ",trans=none" : "");
1960 case QEMU_OPTION_hdb
:
1961 case QEMU_OPTION_hdc
:
1962 case QEMU_OPTION_hdd
:
1963 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
1965 case QEMU_OPTION_drive
:
1966 drive_add(NULL
, "%s", optarg
);
1968 case QEMU_OPTION_set
:
1969 if (qemu_set_option(optarg
) != 0)
1972 case QEMU_OPTION_global
:
1973 if (qemu_global_option(optarg
) != 0)
1976 case QEMU_OPTION_mtdblock
:
1977 drive_add(optarg
, MTD_ALIAS
);
1979 case QEMU_OPTION_sd
:
1980 drive_add(optarg
, SD_ALIAS
);
1982 case QEMU_OPTION_pflash
:
1983 drive_add(optarg
, PFLASH_ALIAS
);
1985 case QEMU_OPTION_snapshot
:
1988 case QEMU_OPTION_hdachs
:
1992 cyls
= strtol(p
, (char **)&p
, 0);
1993 if (cyls
< 1 || cyls
> 16383)
1998 heads
= strtol(p
, (char **)&p
, 0);
1999 if (heads
< 1 || heads
> 16)
2004 secs
= strtol(p
, (char **)&p
, 0);
2005 if (secs
< 1 || secs
> 63)
2009 if (!strcmp(p
, "none"))
2010 translation
= BIOS_ATA_TRANSLATION_NONE
;
2011 else if (!strcmp(p
, "lba"))
2012 translation
= BIOS_ATA_TRANSLATION_LBA
;
2013 else if (!strcmp(p
, "auto"))
2014 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2017 } else if (*p
!= '\0') {
2019 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2022 if (hda_opts
!= NULL
) {
2024 snprintf(num
, sizeof(num
), "%d", cyls
);
2025 qemu_opt_set(hda_opts
, "cyls", num
);
2026 snprintf(num
, sizeof(num
), "%d", heads
);
2027 qemu_opt_set(hda_opts
, "heads", num
);
2028 snprintf(num
, sizeof(num
), "%d", secs
);
2029 qemu_opt_set(hda_opts
, "secs", num
);
2030 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2031 qemu_opt_set(hda_opts
, "trans", "lba");
2032 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2033 qemu_opt_set(hda_opts
, "trans", "none");
2037 case QEMU_OPTION_numa
:
2038 if (nb_numa_nodes
>= MAX_NODES
) {
2039 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2044 case QEMU_OPTION_nographic
:
2045 display_type
= DT_NOGRAPHIC
;
2047 #ifdef CONFIG_CURSES
2048 case QEMU_OPTION_curses
:
2049 display_type
= DT_CURSES
;
2052 case QEMU_OPTION_portrait
:
2055 case QEMU_OPTION_kernel
:
2056 kernel_filename
= optarg
;
2058 case QEMU_OPTION_append
:
2059 kernel_cmdline
= optarg
;
2061 case QEMU_OPTION_cdrom
:
2062 drive_add(optarg
, CDROM_ALIAS
);
2064 case QEMU_OPTION_boot
:
2066 static const char * const params
[] = {
2067 "order", "once", "menu", NULL
2069 char buf
[sizeof(boot_devices
)];
2070 char *standard_boot_devices
;
2073 if (!strchr(optarg
, '=')) {
2075 pstrcpy(buf
, sizeof(buf
), optarg
);
2076 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2078 "qemu: unknown boot parameter '%s' in '%s'\n",
2084 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2085 validate_bootdevices(buf
);
2086 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2089 if (get_param_value(buf
, sizeof(buf
),
2091 validate_bootdevices(buf
);
2092 standard_boot_devices
= qemu_strdup(boot_devices
);
2093 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2094 qemu_register_reset(restore_boot_devices
,
2095 standard_boot_devices
);
2097 if (get_param_value(buf
, sizeof(buf
),
2099 if (!strcmp(buf
, "on")) {
2101 } else if (!strcmp(buf
, "off")) {
2105 "qemu: invalid option value '%s'\n",
2113 case QEMU_OPTION_fda
:
2114 case QEMU_OPTION_fdb
:
2115 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2117 case QEMU_OPTION_no_fd_bootchk
:
2120 case QEMU_OPTION_netdev
:
2121 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2125 case QEMU_OPTION_net
:
2126 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2131 case QEMU_OPTION_tftp
:
2132 legacy_tftp_prefix
= optarg
;
2134 case QEMU_OPTION_bootp
:
2135 legacy_bootp_filename
= optarg
;
2137 case QEMU_OPTION_redir
:
2138 if (net_slirp_redir(optarg
) < 0)
2142 case QEMU_OPTION_bt
:
2143 add_device_config(DEV_BT
, optarg
);
2145 case QEMU_OPTION_audio_help
:
2146 if (!(audio_available())) {
2147 printf("Option %s not supported for this target\n", popt
->name
);
2153 case QEMU_OPTION_soundhw
:
2154 if (!(audio_available())) {
2155 printf("Option %s not supported for this target\n", popt
->name
);
2158 select_soundhw (optarg
);
2163 case QEMU_OPTION_version
:
2167 case QEMU_OPTION_m
: {
2171 value
= strtoul(optarg
, &ptr
, 10);
2173 case 0: case 'M': case 'm':
2180 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2184 /* On 32-bit hosts, QEMU is limited by virtual address space */
2185 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2186 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2189 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2190 fprintf(stderr
, "qemu: ram size too large\n");
2196 case QEMU_OPTION_mempath
:
2200 case QEMU_OPTION_mem_prealloc
:
2205 set_cpu_log(optarg
);
2208 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2210 case QEMU_OPTION_gdb
:
2211 gdbstub_dev
= optarg
;
2216 case QEMU_OPTION_bios
:
2219 case QEMU_OPTION_singlestep
:
2226 keyboard_layout
= optarg
;
2228 case QEMU_OPTION_localtime
:
2231 case QEMU_OPTION_vga
:
2232 select_vgahw (optarg
);
2239 w
= strtol(p
, (char **)&p
, 10);
2242 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2248 h
= strtol(p
, (char **)&p
, 10);
2253 depth
= strtol(p
, (char **)&p
, 10);
2254 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2255 depth
!= 24 && depth
!= 32)
2257 } else if (*p
== '\0') {
2258 depth
= graphic_depth
;
2265 graphic_depth
= depth
;
2268 case QEMU_OPTION_echr
:
2271 term_escape_char
= strtol(optarg
, &r
, 0);
2273 printf("Bad argument to echr\n");
2276 case QEMU_OPTION_monitor
:
2277 monitor_parse(optarg
, "readline");
2278 default_monitor
= 0;
2280 case QEMU_OPTION_qmp
:
2281 monitor_parse(optarg
, "control");
2282 default_monitor
= 0;
2284 case QEMU_OPTION_mon
:
2285 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2289 default_monitor
= 0;
2291 case QEMU_OPTION_chardev
:
2292 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2297 case QEMU_OPTION_fsdev
:
2298 olist
= qemu_find_opts("fsdev");
2300 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2303 opts
= qemu_opts_parse(olist
, optarg
, 1);
2305 fprintf(stderr
, "parse error: %s\n", optarg
);
2309 case QEMU_OPTION_virtfs
: {
2310 char *arg_fsdev
= NULL
;
2311 char *arg_9p
= NULL
;
2314 olist
= qemu_find_opts("virtfs");
2316 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2319 opts
= qemu_opts_parse(olist
, optarg
, 1);
2321 fprintf(stderr
, "parse error: %s\n", optarg
);
2325 if (qemu_opt_get(opts
, "fstype") == NULL
||
2326 qemu_opt_get(opts
, "mount_tag") == NULL
||
2327 qemu_opt_get(opts
, "path") == NULL
||
2328 qemu_opt_get(opts
, "security_model") == NULL
) {
2329 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2330 "security_model=[mapped|passthrough|none],"
2335 len
= strlen(",id=,path=,security_model=");
2336 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2337 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2338 len
+= strlen(qemu_opt_get(opts
, "path"));
2339 len
+= strlen(qemu_opt_get(opts
, "security_model"));
2340 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2342 snprintf(arg_fsdev
, (len
+ 1) * sizeof(*arg_fsdev
),
2343 "%s,id=%s,path=%s,security_model=%s",
2344 qemu_opt_get(opts
, "fstype"),
2345 qemu_opt_get(opts
, "mount_tag"),
2346 qemu_opt_get(opts
, "path"),
2347 qemu_opt_get(opts
, "security_model"));
2349 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2350 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2351 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2353 snprintf(arg_9p
, (len
+ 1) * sizeof(*arg_9p
),
2354 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2355 qemu_opt_get(opts
, "mount_tag"),
2356 qemu_opt_get(opts
, "mount_tag"));
2358 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev
, 1)) {
2359 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2363 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p
, 1)) {
2364 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2368 qemu_free(arg_fsdev
);
2372 case QEMU_OPTION_serial
:
2373 add_device_config(DEV_SERIAL
, optarg
);
2375 if (strncmp(optarg
, "mon:", 4) == 0) {
2376 default_monitor
= 0;
2379 case QEMU_OPTION_watchdog
:
2382 "qemu: only one watchdog option may be given\n");
2387 case QEMU_OPTION_watchdog_action
:
2388 if (select_watchdog_action(optarg
) == -1) {
2389 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2393 case QEMU_OPTION_virtiocon
:
2394 add_device_config(DEV_VIRTCON
, optarg
);
2395 default_virtcon
= 0;
2396 if (strncmp(optarg
, "mon:", 4) == 0) {
2397 default_monitor
= 0;
2400 case QEMU_OPTION_parallel
:
2401 add_device_config(DEV_PARALLEL
, optarg
);
2402 default_parallel
= 0;
2403 if (strncmp(optarg
, "mon:", 4) == 0) {
2404 default_monitor
= 0;
2407 case QEMU_OPTION_debugcon
:
2408 add_device_config(DEV_DEBUGCON
, optarg
);
2410 case QEMU_OPTION_loadvm
:
2413 case QEMU_OPTION_full_screen
:
2417 case QEMU_OPTION_no_frame
:
2420 case QEMU_OPTION_alt_grab
:
2423 case QEMU_OPTION_ctrl_grab
:
2426 case QEMU_OPTION_no_quit
:
2429 case QEMU_OPTION_sdl
:
2430 display_type
= DT_SDL
;
2433 case QEMU_OPTION_pidfile
:
2436 case QEMU_OPTION_win2k_hack
:
2437 win2k_install_hack
= 1;
2439 case QEMU_OPTION_rtc_td_hack
:
2442 case QEMU_OPTION_acpitable
:
2443 do_acpitable_option(optarg
);
2445 case QEMU_OPTION_smbios
:
2446 do_smbios_option(optarg
);
2448 case QEMU_OPTION_enable_kvm
:
2451 case QEMU_OPTION_usb
:
2454 case QEMU_OPTION_usbdevice
:
2456 add_device_config(DEV_USB
, optarg
);
2458 case QEMU_OPTION_device
:
2459 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2463 case QEMU_OPTION_smp
:
2466 fprintf(stderr
, "Invalid number of CPUs\n");
2469 if (max_cpus
< smp_cpus
) {
2470 fprintf(stderr
, "maxcpus must be equal to or greater than "
2474 if (max_cpus
> 255) {
2475 fprintf(stderr
, "Unsupported number of maxcpus\n");
2479 case QEMU_OPTION_vnc
:
2480 display_type
= DT_VNC
;
2481 vnc_display
= optarg
;
2483 case QEMU_OPTION_no_acpi
:
2486 case QEMU_OPTION_no_hpet
:
2489 case QEMU_OPTION_balloon
:
2490 if (balloon_parse(optarg
) < 0) {
2491 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2495 case QEMU_OPTION_no_reboot
:
2498 case QEMU_OPTION_no_shutdown
:
2501 case QEMU_OPTION_show_cursor
:
2504 case QEMU_OPTION_uuid
:
2505 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2506 fprintf(stderr
, "Fail to parse UUID string."
2507 " Wrong format.\n");
2511 case QEMU_OPTION_option_rom
:
2512 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2513 fprintf(stderr
, "Too many option ROMs\n");
2516 option_rom
[nb_option_roms
] = optarg
;
2519 case QEMU_OPTION_semihosting
:
2520 semihosting_enabled
= 1;
2522 case QEMU_OPTION_name
:
2523 qemu_name
= qemu_strdup(optarg
);
2525 char *p
= strchr(qemu_name
, ',');
2528 if (strncmp(p
, "process=", 8)) {
2529 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2533 os_set_proc_name(p
);
2537 case QEMU_OPTION_prom_env
:
2538 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2539 fprintf(stderr
, "Too many prom variables\n");
2542 prom_envs
[nb_prom_envs
] = optarg
;
2545 case QEMU_OPTION_old_param
:
2548 case QEMU_OPTION_clock
:
2549 configure_alarms(optarg
);
2551 case QEMU_OPTION_startdate
:
2552 configure_rtc_date_offset(optarg
, 1);
2554 case QEMU_OPTION_rtc
:
2555 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2559 configure_rtc(opts
);
2561 case QEMU_OPTION_tb_size
:
2562 tb_size
= strtol(optarg
, NULL
, 0);
2566 case QEMU_OPTION_icount
:
2567 icount_option
= optarg
;
2569 case QEMU_OPTION_incoming
:
2571 incoming_expected
= true;
2573 case QEMU_OPTION_nodefaults
:
2575 default_parallel
= 0;
2576 default_virtcon
= 0;
2577 default_monitor
= 0;
2584 case QEMU_OPTION_xen_domid
:
2585 if (!(xen_available())) {
2586 printf("Option %s not supported for this target\n", popt
->name
);
2589 xen_domid
= atoi(optarg
);
2591 case QEMU_OPTION_xen_create
:
2592 if (!(xen_available())) {
2593 printf("Option %s not supported for this target\n", popt
->name
);
2596 xen_mode
= XEN_CREATE
;
2598 case QEMU_OPTION_xen_attach
:
2599 if (!(xen_available())) {
2600 printf("Option %s not supported for this target\n", popt
->name
);
2603 xen_mode
= XEN_ATTACH
;
2605 #ifdef CONFIG_SIMPLE_TRACE
2606 case QEMU_OPTION_trace
:
2607 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2609 trace_file
= qemu_opt_get(opts
, "file");
2613 case QEMU_OPTION_readconfig
:
2615 int ret
= qemu_read_config_file(optarg
);
2617 fprintf(stderr
, "read config %s: %s\n", optarg
,
2623 case QEMU_OPTION_writeconfig
:
2626 if (strcmp(optarg
, "-") == 0) {
2629 fp
= fopen(optarg
, "w");
2631 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2635 qemu_config_write(fp
);
2640 os_parse_cmd_args(popt
->index
, optarg
);
2646 /* If no data_dir is specified then try to find it relative to the
2649 data_dir
= os_find_datadir(argv
[0]);
2651 /* If all else fails use the install patch specified when building. */
2653 data_dir
= CONFIG_QEMU_DATADIR
;
2656 #ifdef CONFIG_SIMPLE_TRACE
2658 * Set the trace file name, if specified.
2660 st_set_trace_file(trace_file
);
2663 * Default to max_cpus = smp_cpus, in case the user doesn't
2664 * specify a max_cpus value.
2667 max_cpus
= smp_cpus
;
2669 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2670 if (smp_cpus
> machine
->max_cpus
) {
2671 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2672 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2677 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2678 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2680 if (machine
->no_serial
) {
2683 if (machine
->no_parallel
) {
2684 default_parallel
= 0;
2686 if (!machine
->use_virtcon
) {
2687 default_virtcon
= 0;
2689 if (machine
->no_vga
) {
2692 if (machine
->no_floppy
) {
2695 if (machine
->no_cdrom
) {
2698 if (machine
->no_sdcard
) {
2702 if (display_type
== DT_NOGRAPHIC
) {
2703 if (default_parallel
)
2704 add_device_config(DEV_PARALLEL
, "null");
2705 if (default_serial
&& default_monitor
) {
2706 add_device_config(DEV_SERIAL
, "mon:stdio");
2707 } else if (default_virtcon
&& default_monitor
) {
2708 add_device_config(DEV_VIRTCON
, "mon:stdio");
2711 add_device_config(DEV_SERIAL
, "stdio");
2712 if (default_virtcon
)
2713 add_device_config(DEV_VIRTCON
, "stdio");
2714 if (default_monitor
)
2715 monitor_parse("stdio", "readline");
2719 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2720 if (default_parallel
)
2721 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2722 if (default_monitor
)
2723 monitor_parse("vc:80Cx24C", "readline");
2724 if (default_virtcon
)
2725 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2728 vga_interface_type
= VGA_CIRRUS
;
2732 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
2734 #ifdef CONFIG_VIRTFS
2735 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
2742 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2748 int ret
= kvm_init(smp_cpus
);
2750 if (!kvm_available()) {
2751 printf("KVM not supported for this target\n");
2753 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2759 if (qemu_init_main_loop()) {
2760 fprintf(stderr
, "qemu_init_main_loop failed\n");
2763 linux_boot
= (kernel_filename
!= NULL
);
2765 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2766 fprintf(stderr
, "-append only allowed with -kernel option\n");
2770 if (!linux_boot
&& initrd_filename
!= NULL
) {
2771 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2775 os_set_line_buffering();
2777 if (init_timer_alarm() < 0) {
2778 fprintf(stderr
, "could not initialize alarm timer\n");
2781 configure_icount(icount_option
);
2783 if (net_init_clients() < 0) {
2787 /* init the bluetooth world */
2788 if (foreach_device_config(DEV_BT
, bt_parse
))
2791 /* init the memory */
2793 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2795 /* init the dynamic translator */
2796 cpu_exec_init_all(tb_size
* 1024 * 1024);
2798 bdrv_init_with_whitelist();
2802 if (default_cdrom
) {
2803 /* we always create the cdrom drive, even if no disk is there */
2804 drive_add(NULL
, CDROM_ALIAS
);
2807 if (default_floppy
) {
2808 /* we always create at least one floppy */
2809 drive_add(NULL
, FD_ALIAS
, 0);
2812 if (default_sdcard
) {
2813 /* we always create one sd slot, even if no card is in it */
2814 drive_add(NULL
, SD_ALIAS
);
2817 /* open the virtual block devices */
2819 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
2820 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
2823 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2826 if (nb_numa_nodes
> 0) {
2829 if (nb_numa_nodes
> smp_cpus
) {
2830 nb_numa_nodes
= smp_cpus
;
2833 /* If no memory size if given for any node, assume the default case
2834 * and distribute the available memory equally across all nodes
2836 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2837 if (node_mem
[i
] != 0)
2840 if (i
== nb_numa_nodes
) {
2841 uint64_t usedmem
= 0;
2843 /* On Linux, the each node's border has to be 8MB aligned,
2844 * the final node gets the rest.
2846 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2847 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2848 usedmem
+= node_mem
[i
];
2850 node_mem
[i
] = ram_size
- usedmem
;
2853 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2854 if (node_cpumask
[i
] != 0)
2857 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2858 * must cope with this anyway, because there are BIOSes out there in
2859 * real machines which also use this scheme.
2861 if (i
== nb_numa_nodes
) {
2862 for (i
= 0; i
< smp_cpus
; i
++) {
2863 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2868 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
2872 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2874 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2876 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2878 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2881 module_call_init(MODULE_INIT_DEVICE
);
2883 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
2887 i
= select_watchdog(watchdog
);
2889 exit (i
== 1 ? 1 : 0);
2892 if (machine
->compat_props
) {
2893 qdev_prop_register_global_list(machine
->compat_props
);
2897 machine
->init(ram_size
, boot_devices
,
2898 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2900 cpu_synchronize_all_post_init();
2902 /* must be after terminal init, SDL library changes signal handlers */
2903 os_setup_signal_handling();
2907 current_machine
= machine
;
2909 /* init USB devices */
2911 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2915 /* init generic devices */
2916 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
2919 net_check_clients();
2921 /* just use the first displaystate for the moment */
2922 ds
= get_displaystate();
2924 if (display_type
== DT_DEFAULT
) {
2925 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
2926 display_type
= DT_SDL
;
2928 display_type
= DT_VNC
;
2929 vnc_display
= "localhost:0,to=99";
2935 switch (display_type
) {
2938 #if defined(CONFIG_CURSES)
2940 curses_display_init(ds
, full_screen
);
2943 #if defined(CONFIG_SDL)
2945 sdl_display_init(ds
, full_screen
, no_frame
);
2947 #elif defined(CONFIG_COCOA)
2949 cocoa_display_init(ds
, full_screen
);
2953 vnc_display_init(ds
);
2954 if (vnc_display_open(ds
, vnc_display
) < 0)
2957 if (show_vnc_port
) {
2958 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
2966 dcl
= ds
->listeners
;
2967 while (dcl
!= NULL
) {
2968 if (dcl
->dpy_refresh
!= NULL
) {
2969 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
2970 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
2976 if (display_type
== DT_NOGRAPHIC
|| display_type
== DT_VNC
) {
2977 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
2978 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
2981 text_consoles_set_display(ds
);
2983 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
2984 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
2989 qdev_machine_creation_done();
2991 if (rom_load_all() != 0) {
2992 fprintf(stderr
, "rom loading failed\n");
2996 qemu_system_reset();
2998 if (load_vmstate(loadvm
) < 0) {
3004 int ret
= qemu_start_incoming_migration(incoming
);
3006 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3010 } else if (autostart
) {