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;
217 int graphic_rotate
= 0;
218 uint8_t irq0override
= 1;
219 const char *watchdog
;
220 const char *option_rom
[MAX_OPTION_ROMS
];
222 int semihosting_enabled
= 0;
223 int time_drift_fix
= 0;
224 unsigned int kvm_shadow_memory
= 0;
226 const char *qemu_name
;
229 unsigned int nb_prom_envs
= 0;
230 const char *prom_envs
[MAX_PROM_ENVS
];
231 const char *nvram
= NULL
;
235 uint64_t node_mem
[MAX_NODES
];
236 uint64_t node_cpumask
[MAX_NODES
];
238 static QEMUTimer
*nographic_timer
;
240 uint8_t qemu_uuid
[16];
242 static QEMUBootSetHandler
*boot_set_handler
;
243 static void *boot_set_opaque
;
245 static NotifierList exit_notifiers
=
246 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
250 enum xen_mode xen_mode
= XEN_EMULATE
;
252 static int default_serial
= 1;
253 static int default_parallel
= 1;
254 static int default_virtcon
= 1;
255 static int default_monitor
= 1;
256 static int default_vga
= 1;
257 static int default_floppy
= 1;
258 static int default_cdrom
= 1;
259 static int default_sdcard
= 1;
265 { .driver
= "isa-serial", .flag
= &default_serial
},
266 { .driver
= "isa-parallel", .flag
= &default_parallel
},
267 { .driver
= "isa-fdc", .flag
= &default_floppy
},
268 { .driver
= "ide-drive", .flag
= &default_cdrom
},
269 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
270 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
271 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
272 { .driver
= "VGA", .flag
= &default_vga
},
273 { .driver
= "cirrus-vga", .flag
= &default_vga
},
274 { .driver
= "vmware-svga", .flag
= &default_vga
},
277 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
279 const char *driver
= qemu_opt_get(opts
, "driver");
284 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
285 if (strcmp(default_list
[i
].driver
, driver
) != 0)
287 *(default_list
[i
].flag
) = 0;
292 /***********************************************************/
293 /* real time host monotonic timer */
295 /* compute with 96 bit intermediate result: (a*b)/c */
296 uint64_t muldiv64(uint64_t a
, uint32_t b
, uint32_t c
)
301 #ifdef HOST_WORDS_BIGENDIAN
311 rl
= (uint64_t)u
.l
.low
* (uint64_t)b
;
312 rh
= (uint64_t)u
.l
.high
* (uint64_t)b
;
315 res
.l
.low
= (((rh
% c
) << 32) + (rl
& 0xffffffff)) / c
;
319 /***********************************************************/
320 /* host time/date access */
321 void qemu_get_timedate(struct tm
*tm
, int offset
)
328 if (rtc_date_offset
== -1) {
332 ret
= localtime(&ti
);
334 ti
-= rtc_date_offset
;
338 memcpy(tm
, ret
, sizeof(struct tm
));
341 int qemu_timedate_diff(struct tm
*tm
)
345 if (rtc_date_offset
== -1)
347 seconds
= mktimegm(tm
);
349 seconds
= mktime(tm
);
351 seconds
= mktimegm(tm
) + rtc_date_offset
;
353 return seconds
- time(NULL
);
356 void rtc_change_mon_event(struct tm
*tm
)
360 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
361 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
362 qobject_decref(data
);
365 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
367 time_t rtc_start_date
;
370 if (!strcmp(startdate
, "now") && legacy
) {
371 rtc_date_offset
= -1;
373 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
381 } else if (sscanf(startdate
, "%d-%d-%d",
393 rtc_start_date
= mktimegm(&tm
);
394 if (rtc_start_date
== -1) {
396 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
397 "'2006-06-17T16:01:21' or '2006-06-17'\n");
400 rtc_date_offset
= time(NULL
) - rtc_start_date
;
404 static void configure_rtc(QemuOpts
*opts
)
408 value
= qemu_opt_get(opts
, "base");
410 if (!strcmp(value
, "utc")) {
412 } else if (!strcmp(value
, "localtime")) {
415 configure_rtc_date_offset(value
, 0);
418 value
= qemu_opt_get(opts
, "clock");
420 if (!strcmp(value
, "host")) {
421 rtc_clock
= host_clock
;
422 } else if (!strcmp(value
, "vm")) {
423 rtc_clock
= vm_clock
;
425 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
429 value
= qemu_opt_get(opts
, "driftfix");
431 if (!strcmp(value
, "slew")) {
433 } else if (!strcmp(value
, "none")) {
436 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
442 /***********************************************************/
443 /* Bluetooth support */
446 static struct HCIInfo
*hci_table
[MAX_NICS
];
448 static struct bt_vlan_s
{
449 struct bt_scatternet_s net
;
451 struct bt_vlan_s
*next
;
454 /* find or alloc a new bluetooth "VLAN" */
455 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
457 struct bt_vlan_s
**pvlan
, *vlan
;
458 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
462 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
464 pvlan
= &first_bt_vlan
;
465 while (*pvlan
!= NULL
)
466 pvlan
= &(*pvlan
)->next
;
471 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
475 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
480 static struct HCIInfo null_hci
= {
481 .cmd_send
= null_hci_send
,
482 .sco_send
= null_hci_send
,
483 .acl_send
= null_hci_send
,
484 .bdaddr_set
= null_hci_addr_set
,
487 struct HCIInfo
*qemu_next_hci(void)
489 if (cur_hci
== nb_hcis
)
492 return hci_table
[cur_hci
++];
495 static struct HCIInfo
*hci_init(const char *str
)
498 struct bt_scatternet_s
*vlan
= 0;
500 if (!strcmp(str
, "null"))
503 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
505 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
506 else if (!strncmp(str
, "hci", 3)) {
509 if (!strncmp(str
+ 3, ",vlan=", 6)) {
510 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
515 vlan
= qemu_find_bt_vlan(0);
517 return bt_new_hci(vlan
);
520 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
525 static int bt_hci_parse(const char *str
)
530 if (nb_hcis
>= MAX_NICS
) {
531 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
544 bdaddr
.b
[5] = 0x56 + nb_hcis
;
545 hci
->bdaddr_set(hci
, bdaddr
.b
);
547 hci_table
[nb_hcis
++] = hci
;
552 static void bt_vhci_add(int vlan_id
)
554 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
557 fprintf(stderr
, "qemu: warning: adding a VHCI to "
558 "an empty scatternet %i\n", vlan_id
);
560 bt_vhci_init(bt_new_hci(vlan
));
563 static struct bt_device_s
*bt_device_add(const char *opt
)
565 struct bt_scatternet_s
*vlan
;
567 char *endp
= strstr(opt
, ",vlan=");
568 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
571 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
574 vlan_id
= strtol(endp
+ 6, &endp
, 0);
576 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
581 vlan
= qemu_find_bt_vlan(vlan_id
);
584 fprintf(stderr
, "qemu: warning: adding a slave device to "
585 "an empty scatternet %i\n", vlan_id
);
587 if (!strcmp(devname
, "keyboard"))
588 return bt_keyboard_init(vlan
);
590 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
594 static int bt_parse(const char *opt
)
596 const char *endp
, *p
;
599 if (strstart(opt
, "hci", &endp
)) {
600 if (!*endp
|| *endp
== ',') {
602 if (!strstart(endp
, ",vlan=", 0))
605 return bt_hci_parse(opt
);
607 } else if (strstart(opt
, "vhci", &endp
)) {
608 if (!*endp
|| *endp
== ',') {
610 if (strstart(endp
, ",vlan=", &p
)) {
611 vlan
= strtol(p
, (char **) &endp
, 0);
613 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
617 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
626 } else if (strstart(opt
, "device:", &endp
))
627 return !bt_device_add(endp
);
629 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
633 /***********************************************************/
634 /* QEMU Block devices */
636 #define HD_ALIAS "index=%d,media=disk"
637 #define CDROM_ALIAS "index=2,media=cdrom"
638 #define FD_ALIAS "index=%d,if=floppy"
639 #define PFLASH_ALIAS "if=pflash"
640 #define MTD_ALIAS "if=mtd"
641 #define SD_ALIAS "index=0,if=sd"
643 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
645 int *use_scsi
= opaque
;
648 if (drive_init(opts
, *use_scsi
, &fatal_error
) == NULL
) {
655 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
657 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
658 qemu_opt_set(opts
, "snapshot", "on");
663 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
665 boot_set_handler
= func
;
666 boot_set_opaque
= opaque
;
669 int qemu_boot_set(const char *boot_devices
)
671 if (!boot_set_handler
) {
674 return boot_set_handler(boot_set_opaque
, boot_devices
);
677 static void validate_bootdevices(char *devices
)
679 /* We just do some generic consistency checks */
683 for (p
= devices
; *p
!= '\0'; p
++) {
684 /* Allowed boot devices are:
685 * a-b: floppy disk drives
686 * c-f: IDE disk drives
687 * g-m: machine implementation dependant drives
688 * n-p: network devices
689 * It's up to each machine implementation to check if the given boot
690 * devices match the actual hardware implementation and firmware
693 if (*p
< 'a' || *p
> 'p') {
694 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
697 if (bitmap
& (1 << (*p
- 'a'))) {
698 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
701 bitmap
|= 1 << (*p
- 'a');
705 static void restore_boot_devices(void *opaque
)
707 char *standard_boot_devices
= opaque
;
708 static int first
= 1;
710 /* Restore boot order and remove ourselves after the first boot */
716 qemu_boot_set(standard_boot_devices
);
718 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
719 qemu_free(standard_boot_devices
);
722 static void numa_add(const char *optarg
)
726 unsigned long long value
, endvalue
;
729 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
730 if (!strcmp(option
, "node")) {
731 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
732 nodenr
= nb_numa_nodes
;
734 nodenr
= strtoull(option
, NULL
, 10);
737 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
738 node_mem
[nodenr
] = 0;
740 value
= strtoull(option
, &endptr
, 0);
742 case 0: case 'M': case 'm':
749 node_mem
[nodenr
] = value
;
751 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
752 node_cpumask
[nodenr
] = 0;
754 value
= strtoull(option
, &endptr
, 10);
757 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
759 if (*endptr
== '-') {
760 endvalue
= strtoull(endptr
+1, &endptr
, 10);
761 if (endvalue
>= 63) {
764 "only 63 CPUs in NUMA mode supported.\n");
766 value
= (2ULL << endvalue
) - (1ULL << value
);
768 value
= 1ULL << value
;
771 node_cpumask
[nodenr
] = value
;
778 static void smp_parse(const char *optarg
)
780 int smp
, sockets
= 0, threads
= 0, cores
= 0;
784 smp
= strtoul(optarg
, &endptr
, 10);
785 if (endptr
!= optarg
) {
786 if (*endptr
== ',') {
790 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
791 sockets
= strtoull(option
, NULL
, 10);
792 if (get_param_value(option
, 128, "cores", endptr
) != 0)
793 cores
= strtoull(option
, NULL
, 10);
794 if (get_param_value(option
, 128, "threads", endptr
) != 0)
795 threads
= strtoull(option
, NULL
, 10);
796 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
797 max_cpus
= strtoull(option
, NULL
, 10);
799 /* compute missing values, prefer sockets over cores over threads */
800 if (smp
== 0 || sockets
== 0) {
801 sockets
= sockets
> 0 ? sockets
: 1;
802 cores
= cores
> 0 ? cores
: 1;
803 threads
= threads
> 0 ? threads
: 1;
805 smp
= cores
* threads
* sockets
;
809 threads
= threads
> 0 ? threads
: 1;
810 cores
= smp
/ (sockets
* threads
);
813 threads
= smp
/ (cores
* sockets
);
818 smp_cores
= cores
> 0 ? cores
: 1;
819 smp_threads
= threads
> 0 ? threads
: 1;
824 /***********************************************************/
827 static int usb_device_add(const char *devname
)
830 USBDevice
*dev
= NULL
;
835 /* drivers with .usbdevice_name entry in USBDeviceInfo */
836 dev
= usbdevice_create(devname
);
841 if (strstart(devname
, "host:", &p
)) {
842 dev
= usb_host_device_open(p
);
843 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
844 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
845 bt_new_hci(qemu_find_bt_vlan(0)));
856 static int usb_device_del(const char *devname
)
861 if (strstart(devname
, "host:", &p
))
862 return usb_host_device_close(p
);
867 p
= strchr(devname
, '.');
870 bus_num
= strtoul(devname
, NULL
, 0);
871 addr
= strtoul(p
+ 1, NULL
, 0);
873 return usb_device_delete_addr(bus_num
, addr
);
876 static int usb_parse(const char *cmdline
)
879 r
= usb_device_add(cmdline
);
881 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
886 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
888 const char *devname
= qdict_get_str(qdict
, "devname");
889 if (usb_device_add(devname
) < 0) {
890 error_report("could not add USB device '%s'", devname
);
894 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
896 const char *devname
= qdict_get_str(qdict
, "devname");
897 if (usb_device_del(devname
) < 0) {
898 error_report("could not delete USB device '%s'", devname
);
902 /***********************************************************/
905 static struct pcmcia_socket_entry_s
{
906 PCMCIASocket
*socket
;
907 struct pcmcia_socket_entry_s
*next
;
908 } *pcmcia_sockets
= 0;
910 void pcmcia_socket_register(PCMCIASocket
*socket
)
912 struct pcmcia_socket_entry_s
*entry
;
914 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
915 entry
->socket
= socket
;
916 entry
->next
= pcmcia_sockets
;
917 pcmcia_sockets
= entry
;
920 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
922 struct pcmcia_socket_entry_s
*entry
, **ptr
;
924 ptr
= &pcmcia_sockets
;
925 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
926 if (entry
->socket
== socket
) {
932 void pcmcia_info(Monitor
*mon
)
934 struct pcmcia_socket_entry_s
*iter
;
937 monitor_printf(mon
, "No PCMCIA sockets\n");
939 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
940 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
941 iter
->socket
->attached
? iter
->socket
->card_string
:
945 /***********************************************************/
948 typedef struct IOHandlerRecord
{
950 IOCanReadHandler
*fd_read_poll
;
957 QLIST_ENTRY(IOHandlerRecord
) next
;
960 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
961 QLIST_HEAD_INITIALIZER(io_handlers
);
964 /* XXX: fd_read_poll should be suppressed, but an API change is
965 necessary in the character devices to suppress fd_can_read(). */
966 int qemu_set_fd_handler2(int fd
,
967 IOCanReadHandler
*fd_read_poll
,
972 IOHandlerRecord
*ioh
;
974 if (!fd_read
&& !fd_write
) {
975 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
982 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
986 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
987 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
990 ioh
->fd_read_poll
= fd_read_poll
;
991 ioh
->fd_read
= fd_read
;
992 ioh
->fd_write
= fd_write
;
993 ioh
->opaque
= opaque
;
1000 int qemu_set_fd_handler(int fd
,
1002 IOHandler
*fd_write
,
1005 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
1008 /***********************************************************/
1009 /* machine registration */
1011 static QEMUMachine
*first_machine
= NULL
;
1012 QEMUMachine
*current_machine
= NULL
;
1014 int qemu_register_machine(QEMUMachine
*m
)
1017 pm
= &first_machine
;
1025 static QEMUMachine
*find_machine(const char *name
)
1029 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1030 if (!strcmp(m
->name
, name
))
1032 if (m
->alias
&& !strcmp(m
->alias
, name
))
1038 static QEMUMachine
*find_default_machine(void)
1042 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1043 if (m
->is_default
) {
1050 /***********************************************************/
1051 /* main execution loop */
1053 static void gui_update(void *opaque
)
1055 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1056 DisplayState
*ds
= opaque
;
1057 DisplayChangeListener
*dcl
= ds
->listeners
;
1059 qemu_flush_coalesced_mmio_buffer();
1062 while (dcl
!= NULL
) {
1063 if (dcl
->gui_timer_interval
&&
1064 dcl
->gui_timer_interval
< interval
)
1065 interval
= dcl
->gui_timer_interval
;
1068 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1071 static void nographic_update(void *opaque
)
1073 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1075 qemu_flush_coalesced_mmio_buffer();
1076 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1079 struct vm_change_state_entry
{
1080 VMChangeStateHandler
*cb
;
1082 QLIST_ENTRY (vm_change_state_entry
) entries
;
1085 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1087 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1090 VMChangeStateEntry
*e
;
1092 e
= qemu_mallocz(sizeof (*e
));
1096 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1100 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1102 QLIST_REMOVE (e
, entries
);
1106 void vm_state_notify(int running
, int reason
)
1108 VMChangeStateEntry
*e
;
1110 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1111 e
->cb(e
->opaque
, running
, reason
);
1120 vm_state_notify(1, 0);
1122 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1126 /* reset/shutdown handler */
1128 typedef struct QEMUResetEntry
{
1129 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1130 QEMUResetHandler
*func
;
1134 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1135 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1136 static int reset_requested
;
1137 static int shutdown_requested
;
1138 static int powerdown_requested
;
1139 int debug_requested
;
1140 int vmstop_requested
;
1142 int qemu_no_shutdown(void)
1144 int r
= no_shutdown
;
1149 int qemu_shutdown_requested(void)
1151 int r
= shutdown_requested
;
1152 shutdown_requested
= 0;
1156 int qemu_reset_requested(void)
1158 int r
= reset_requested
;
1159 reset_requested
= 0;
1163 int qemu_powerdown_requested(void)
1165 int r
= powerdown_requested
;
1166 powerdown_requested
= 0;
1170 static int qemu_debug_requested(void)
1172 int r
= debug_requested
;
1173 debug_requested
= 0;
1177 static int qemu_vmstop_requested(void)
1179 int r
= vmstop_requested
;
1180 vmstop_requested
= 0;
1184 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1186 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1189 re
->opaque
= opaque
;
1190 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1193 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1197 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1198 if (re
->func
== func
&& re
->opaque
== opaque
) {
1199 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1206 void qemu_system_reset(void)
1208 QEMUResetEntry
*re
, *nre
;
1210 /* reset all devices */
1211 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1212 re
->func(re
->opaque
);
1214 monitor_protocol_event(QEVENT_RESET
, NULL
);
1215 cpu_synchronize_all_post_reset();
1218 void qemu_system_reset_request(void)
1221 shutdown_requested
= 1;
1223 reset_requested
= 1;
1225 if (cpu_single_env
) {
1226 cpu_single_env
->stopped
= 1;
1228 qemu_notify_event();
1231 void qemu_system_shutdown_request(void)
1233 shutdown_requested
= 1;
1234 qemu_notify_event();
1237 void qemu_system_powerdown_request(void)
1239 powerdown_requested
= 1;
1240 qemu_notify_event();
1243 void main_loop_wait(int nonblocking
)
1245 IOHandlerRecord
*ioh
;
1246 fd_set rfds
, wfds
, xfds
;
1254 timeout
= qemu_calculate_timeout();
1255 qemu_bh_update_timeout(&timeout
);
1258 os_host_main_loop_wait(&timeout
);
1260 /* poll any events */
1261 /* XXX: separate device handlers from system ones */
1266 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1270 (!ioh
->fd_read_poll
||
1271 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1272 FD_SET(ioh
->fd
, &rfds
);
1276 if (ioh
->fd_write
) {
1277 FD_SET(ioh
->fd
, &wfds
);
1283 tv
.tv_sec
= timeout
/ 1000;
1284 tv
.tv_usec
= (timeout
% 1000) * 1000;
1286 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1288 qemu_mutex_unlock_iothread();
1289 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1290 qemu_mutex_lock_iothread();
1292 IOHandlerRecord
*pioh
;
1294 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1296 QLIST_REMOVE(ioh
, next
);
1300 if (ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1301 ioh
->fd_read(ioh
->opaque
);
1302 if (!(ioh
->fd_read_poll
&& ioh
->fd_read_poll(ioh
->opaque
)))
1303 FD_CLR(ioh
->fd
, &rfds
);
1305 if (ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1306 ioh
->fd_write(ioh
->opaque
);
1311 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1313 qemu_run_all_timers();
1315 /* Check bottom-halves last in case any of the earlier events triggered
1321 static int vm_can_run(void)
1323 if (powerdown_requested
)
1325 if (reset_requested
)
1327 if (shutdown_requested
)
1329 if (debug_requested
)
1334 qemu_irq qemu_system_powerdown
;
1336 static void main_loop(void)
1340 if (kvm_enabled()) {
1342 cpu_disable_ticks();
1346 qemu_main_loop_start();
1350 bool nonblocking
= false;
1351 #ifdef CONFIG_PROFILER
1354 #ifndef CONFIG_IOTHREAD
1355 nonblocking
= tcg_cpu_exec();
1357 #ifdef CONFIG_PROFILER
1358 ti
= profile_getclock();
1360 main_loop_wait(nonblocking
);
1361 #ifdef CONFIG_PROFILER
1362 dev_time
+= profile_getclock() - ti
;
1364 } while (vm_can_run());
1366 if ((r
= qemu_debug_requested())) {
1369 if (qemu_shutdown_requested()) {
1370 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1377 if (qemu_reset_requested()) {
1379 qemu_system_reset();
1382 if (qemu_powerdown_requested()) {
1383 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1384 qemu_irq_raise(qemu_system_powerdown
);
1386 if ((r
= qemu_vmstop_requested())) {
1394 static void version(void)
1396 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1399 static void help(int exitcode
)
1401 const char *options_help
=
1402 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1404 #define DEFHEADING(text) stringify(text) "\n"
1405 #include "qemu-options.def"
1411 printf("usage: %s [options] [disk_image]\n"
1413 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1416 "During emulation, the following keys are useful:\n"
1417 "ctrl-alt-f toggle full screen\n"
1418 "ctrl-alt-n switch to virtual console 'n'\n"
1419 "ctrl-alt toggle mouse and keyboard grab\n"
1421 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1427 #define HAS_ARG 0x0001
1429 typedef struct QEMUOption
{
1436 static const QEMUOption qemu_options
[] = {
1437 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1438 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1439 { option, opt_arg, opt_enum, arch_mask },
1440 #define DEFHEADING(text)
1441 #include "qemu-options.def"
1447 static void select_vgahw (const char *p
)
1452 vga_interface_type
= VGA_NONE
;
1453 if (strstart(p
, "std", &opts
)) {
1454 vga_interface_type
= VGA_STD
;
1455 } else if (strstart(p
, "cirrus", &opts
)) {
1456 vga_interface_type
= VGA_CIRRUS
;
1457 } else if (strstart(p
, "vmware", &opts
)) {
1458 vga_interface_type
= VGA_VMWARE
;
1459 } else if (strstart(p
, "xenfb", &opts
)) {
1460 vga_interface_type
= VGA_XENFB
;
1461 } else if (!strstart(p
, "none", &opts
)) {
1463 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1467 const char *nextopt
;
1469 if (strstart(opts
, ",retrace=", &nextopt
)) {
1471 if (strstart(opts
, "dumb", &nextopt
))
1472 vga_retrace_method
= VGA_RETRACE_DUMB
;
1473 else if (strstart(opts
, "precise", &nextopt
))
1474 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1475 else goto invalid_vga
;
1476 } else goto invalid_vga
;
1481 static int balloon_parse(const char *arg
)
1485 if (strcmp(arg
, "none") == 0) {
1489 if (!strncmp(arg
, "virtio", 6)) {
1490 if (arg
[6] == ',') {
1491 /* have params -> parse them */
1492 opts
= qemu_opts_parse(&qemu_device_opts
, arg
+7, 0);
1496 /* create empty opts */
1497 opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1499 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1506 char *qemu_find_file(int type
, const char *name
)
1512 /* If name contains path separators then try it as a straight path. */
1513 if ((strchr(name
, '/') || strchr(name
, '\\'))
1514 && access(name
, R_OK
) == 0) {
1515 return qemu_strdup(name
);
1518 case QEMU_FILE_TYPE_BIOS
:
1521 case QEMU_FILE_TYPE_KEYMAP
:
1522 subdir
= "keymaps/";
1527 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1528 buf
= qemu_mallocz(len
);
1529 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1530 if (access(buf
, R_OK
)) {
1537 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1539 return qdev_device_help(opts
);
1542 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1546 dev
= qdev_device_add(opts
);
1552 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1554 CharDriverState
*chr
;
1556 chr
= qemu_chr_open_opts(opts
, NULL
);
1563 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1566 ret
= qemu_fsdev_add(opts
);
1572 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1574 CharDriverState
*chr
;
1575 const char *chardev
;
1579 mode
= qemu_opt_get(opts
, "mode");
1583 if (strcmp(mode
, "readline") == 0) {
1584 flags
= MONITOR_USE_READLINE
;
1585 } else if (strcmp(mode
, "control") == 0) {
1586 flags
= MONITOR_USE_CONTROL
;
1588 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1592 if (qemu_opt_get_bool(opts
, "default", 0))
1593 flags
|= MONITOR_IS_DEFAULT
;
1595 chardev
= qemu_opt_get(opts
, "chardev");
1596 chr
= qemu_chr_find(chardev
);
1598 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1602 monitor_init(chr
, flags
);
1606 static void monitor_parse(const char *optarg
, const char *mode
)
1608 static int monitor_device_index
= 0;
1614 if (strstart(optarg
, "chardev:", &p
)) {
1615 snprintf(label
, sizeof(label
), "%s", p
);
1617 snprintf(label
, sizeof(label
), "compat_monitor%d",
1618 monitor_device_index
);
1619 if (monitor_device_index
== 0) {
1622 opts
= qemu_chr_parse_compat(label
, optarg
);
1624 fprintf(stderr
, "parse error: %s\n", optarg
);
1629 opts
= qemu_opts_create(&qemu_mon_opts
, label
, 1);
1631 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1634 qemu_opt_set(opts
, "mode", mode
);
1635 qemu_opt_set(opts
, "chardev", label
);
1637 qemu_opt_set(opts
, "default", "on");
1638 monitor_device_index
++;
1641 struct device_config
{
1643 DEV_USB
, /* -usbdevice */
1645 DEV_SERIAL
, /* -serial */
1646 DEV_PARALLEL
, /* -parallel */
1647 DEV_VIRTCON
, /* -virtioconsole */
1648 DEV_DEBUGCON
, /* -debugcon */
1650 const char *cmdline
;
1651 QTAILQ_ENTRY(device_config
) next
;
1653 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1655 static void add_device_config(int type
, const char *cmdline
)
1657 struct device_config
*conf
;
1659 conf
= qemu_mallocz(sizeof(*conf
));
1661 conf
->cmdline
= cmdline
;
1662 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1665 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1667 struct device_config
*conf
;
1670 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1671 if (conf
->type
!= type
)
1673 rc
= func(conf
->cmdline
);
1680 static int serial_parse(const char *devname
)
1682 static int index
= 0;
1685 if (strcmp(devname
, "none") == 0)
1687 if (index
== MAX_SERIAL_PORTS
) {
1688 fprintf(stderr
, "qemu: too many serial ports\n");
1691 snprintf(label
, sizeof(label
), "serial%d", index
);
1692 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1693 if (!serial_hds
[index
]) {
1694 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1695 devname
, strerror(errno
));
1702 static int parallel_parse(const char *devname
)
1704 static int index
= 0;
1707 if (strcmp(devname
, "none") == 0)
1709 if (index
== MAX_PARALLEL_PORTS
) {
1710 fprintf(stderr
, "qemu: too many parallel ports\n");
1713 snprintf(label
, sizeof(label
), "parallel%d", index
);
1714 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1715 if (!parallel_hds
[index
]) {
1716 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1717 devname
, strerror(errno
));
1724 static int virtcon_parse(const char *devname
)
1726 static int index
= 0;
1728 QemuOpts
*bus_opts
, *dev_opts
;
1730 if (strcmp(devname
, "none") == 0)
1732 if (index
== MAX_VIRTIO_CONSOLES
) {
1733 fprintf(stderr
, "qemu: too many virtio consoles\n");
1737 bus_opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1738 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1740 dev_opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1741 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1743 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1744 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1745 if (!virtcon_hds
[index
]) {
1746 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1747 devname
, strerror(errno
));
1750 qemu_opt_set(dev_opts
, "chardev", label
);
1756 static int debugcon_parse(const char *devname
)
1760 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1763 opts
= qemu_opts_create(&qemu_device_opts
, "debugcon", 1);
1765 fprintf(stderr
, "qemu: already have a debugcon device\n");
1768 qemu_opt_set(opts
, "driver", "isa-debugcon");
1769 qemu_opt_set(opts
, "chardev", "debugcon");
1773 void qemu_add_exit_notifier(Notifier
*notify
)
1775 notifier_list_add(&exit_notifiers
, notify
);
1778 void qemu_remove_exit_notifier(Notifier
*notify
)
1780 notifier_list_remove(&exit_notifiers
, notify
);
1783 static void qemu_run_exit_notifiers(void)
1785 notifier_list_notify(&exit_notifiers
);
1788 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1789 const char **poptarg
, int *poptind
)
1791 const QEMUOption
*popt
;
1792 int optind
= *poptind
;
1793 char *r
= argv
[optind
];
1796 loc_set_cmdline(argv
, optind
, 1);
1798 /* Treat --foo the same as -foo. */
1801 popt
= qemu_options
;
1804 error_report("invalid option");
1807 if (!strcmp(popt
->name
, r
+ 1))
1811 if (popt
->flags
& HAS_ARG
) {
1812 if (optind
>= argc
) {
1813 error_report("requires an argument");
1816 optarg
= argv
[optind
++];
1817 loc_set_cmdline(argv
, optind
- 2, 2);
1828 int main(int argc
, char **argv
, char **envp
)
1830 const char *gdbstub_dev
= NULL
;
1832 int snapshot
, linux_boot
;
1833 const char *icount_option
= NULL
;
1834 const char *initrd_filename
;
1835 const char *kernel_filename
, *kernel_cmdline
;
1836 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1838 DisplayChangeListener
*dcl
;
1839 int cyls
, heads
, secs
, translation
;
1840 QemuOpts
*hda_opts
= NULL
, *opts
;
1843 const char *loadvm
= NULL
;
1844 QEMUMachine
*machine
;
1845 const char *cpu_model
;
1847 const char *pid_file
= NULL
;
1848 const char *incoming
= NULL
;
1849 int show_vnc_port
= 0;
1852 atexit(qemu_run_exit_notifiers
);
1853 error_set_progname(argv
[0]);
1857 qemu_cache_utils_init(envp
);
1859 QLIST_INIT (&vm_change_state_head
);
1860 os_setup_early_signal_handling();
1862 module_call_init(MODULE_INIT_MACHINE
);
1863 machine
= find_default_machine();
1865 initrd_filename
= NULL
;
1868 kernel_filename
= NULL
;
1869 kernel_cmdline
= "";
1870 cyls
= heads
= secs
= 0;
1871 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1873 for (i
= 0; i
< MAX_NODES
; i
++) {
1875 node_cpumask
[i
] = 0;
1878 assigned_devices_index
= 0;
1886 /* first pass of option parsing */
1888 while (optind
< argc
) {
1889 if (argv
[optind
][0] != '-') {
1894 const QEMUOption
*popt
;
1896 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1897 switch (popt
->index
) {
1898 case QEMU_OPTION_nodefconfig
:
1908 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1909 if (ret
< 0 && ret
!= -ENOENT
) {
1913 ret
= qemu_read_config_file(arch_config_name
);
1914 if (ret
< 0 && ret
!= -ENOENT
) {
1920 /* second pass of option parsing */
1925 if (argv
[optind
][0] != '-') {
1926 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1928 const QEMUOption
*popt
;
1930 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1931 if (!(popt
->arch_mask
& arch_type
)) {
1932 printf("Option %s not supported for this target\n", popt
->name
);
1935 switch(popt
->index
) {
1937 machine
= find_machine(optarg
);
1940 printf("Supported machines are:\n");
1941 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1943 printf("%-10s %s (alias of %s)\n",
1944 m
->alias
, m
->desc
, m
->name
);
1945 printf("%-10s %s%s\n",
1947 m
->is_default
? " (default)" : "");
1949 exit(*optarg
!= '?');
1952 case QEMU_OPTION_cpu
:
1953 /* hw initialization will check this */
1954 if (*optarg
== '?') {
1955 list_cpus(stdout
, &fprintf
, optarg
);
1961 case QEMU_OPTION_initrd
:
1962 initrd_filename
= optarg
;
1964 case QEMU_OPTION_hda
:
1966 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
1968 hda_opts
= drive_add(optarg
, HD_ALIAS
1969 ",cyls=%d,heads=%d,secs=%d%s",
1970 0, cyls
, heads
, secs
,
1971 translation
== BIOS_ATA_TRANSLATION_LBA
?
1973 translation
== BIOS_ATA_TRANSLATION_NONE
?
1974 ",trans=none" : "");
1976 case QEMU_OPTION_hdb
:
1977 case QEMU_OPTION_hdc
:
1978 case QEMU_OPTION_hdd
:
1979 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
1981 case QEMU_OPTION_drive
:
1982 drive_add(NULL
, "%s", optarg
);
1984 case QEMU_OPTION_set
:
1985 if (qemu_set_option(optarg
) != 0)
1988 case QEMU_OPTION_global
:
1989 if (qemu_global_option(optarg
) != 0)
1992 case QEMU_OPTION_mtdblock
:
1993 drive_add(optarg
, MTD_ALIAS
);
1995 case QEMU_OPTION_sd
:
1996 drive_add(optarg
, SD_ALIAS
);
1998 case QEMU_OPTION_pflash
:
1999 drive_add(optarg
, PFLASH_ALIAS
);
2001 case QEMU_OPTION_snapshot
:
2004 case QEMU_OPTION_hdachs
:
2008 cyls
= strtol(p
, (char **)&p
, 0);
2009 if (cyls
< 1 || cyls
> 16383)
2014 heads
= strtol(p
, (char **)&p
, 0);
2015 if (heads
< 1 || heads
> 16)
2020 secs
= strtol(p
, (char **)&p
, 0);
2021 if (secs
< 1 || secs
> 63)
2025 if (!strcmp(p
, "none"))
2026 translation
= BIOS_ATA_TRANSLATION_NONE
;
2027 else if (!strcmp(p
, "lba"))
2028 translation
= BIOS_ATA_TRANSLATION_LBA
;
2029 else if (!strcmp(p
, "auto"))
2030 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2033 } else if (*p
!= '\0') {
2035 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2038 if (hda_opts
!= NULL
) {
2040 snprintf(num
, sizeof(num
), "%d", cyls
);
2041 qemu_opt_set(hda_opts
, "cyls", num
);
2042 snprintf(num
, sizeof(num
), "%d", heads
);
2043 qemu_opt_set(hda_opts
, "heads", num
);
2044 snprintf(num
, sizeof(num
), "%d", secs
);
2045 qemu_opt_set(hda_opts
, "secs", num
);
2046 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2047 qemu_opt_set(hda_opts
, "trans", "lba");
2048 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2049 qemu_opt_set(hda_opts
, "trans", "none");
2053 case QEMU_OPTION_numa
:
2054 if (nb_numa_nodes
>= MAX_NODES
) {
2055 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2060 case QEMU_OPTION_nographic
:
2061 display_type
= DT_NOGRAPHIC
;
2063 #ifdef CONFIG_CURSES
2064 case QEMU_OPTION_curses
:
2065 display_type
= DT_CURSES
;
2068 case QEMU_OPTION_portrait
:
2071 case QEMU_OPTION_kernel
:
2072 kernel_filename
= optarg
;
2074 case QEMU_OPTION_append
:
2075 kernel_cmdline
= optarg
;
2077 case QEMU_OPTION_cdrom
:
2078 drive_add(optarg
, CDROM_ALIAS
);
2080 case QEMU_OPTION_boot
:
2082 static const char * const params
[] = {
2083 "order", "once", "menu", NULL
2085 char buf
[sizeof(boot_devices
)];
2086 char *standard_boot_devices
;
2089 if (!strchr(optarg
, '=')) {
2091 pstrcpy(buf
, sizeof(buf
), optarg
);
2092 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2094 "qemu: unknown boot parameter '%s' in '%s'\n",
2100 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2101 validate_bootdevices(buf
);
2102 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2105 if (get_param_value(buf
, sizeof(buf
),
2107 validate_bootdevices(buf
);
2108 standard_boot_devices
= qemu_strdup(boot_devices
);
2109 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2110 qemu_register_reset(restore_boot_devices
,
2111 standard_boot_devices
);
2113 if (get_param_value(buf
, sizeof(buf
),
2115 if (!strcmp(buf
, "on")) {
2117 } else if (!strcmp(buf
, "off")) {
2121 "qemu: invalid option value '%s'\n",
2129 case QEMU_OPTION_fda
:
2130 case QEMU_OPTION_fdb
:
2131 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2133 case QEMU_OPTION_no_fd_bootchk
:
2136 case QEMU_OPTION_netdev
:
2137 if (net_client_parse(&qemu_netdev_opts
, optarg
) == -1) {
2141 case QEMU_OPTION_net
:
2142 if (net_client_parse(&qemu_net_opts
, optarg
) == -1) {
2147 case QEMU_OPTION_tftp
:
2148 legacy_tftp_prefix
= optarg
;
2150 case QEMU_OPTION_bootp
:
2151 legacy_bootp_filename
= optarg
;
2153 case QEMU_OPTION_redir
:
2154 if (net_slirp_redir(optarg
) < 0)
2158 case QEMU_OPTION_bt
:
2159 add_device_config(DEV_BT
, optarg
);
2161 case QEMU_OPTION_audio_help
:
2162 if (!(audio_available())) {
2163 printf("Option %s not supported for this target\n", popt
->name
);
2169 case QEMU_OPTION_soundhw
:
2170 if (!(audio_available())) {
2171 printf("Option %s not supported for this target\n", popt
->name
);
2174 select_soundhw (optarg
);
2179 case QEMU_OPTION_version
:
2183 case QEMU_OPTION_m
: {
2187 value
= strtoul(optarg
, &ptr
, 10);
2189 case 0: case 'M': case 'm':
2196 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2200 /* On 32-bit hosts, QEMU is limited by virtual address space */
2201 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2202 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2205 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2206 fprintf(stderr
, "qemu: ram size too large\n");
2212 case QEMU_OPTION_mempath
:
2216 case QEMU_OPTION_mem_prealloc
:
2221 set_cpu_log(optarg
);
2224 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2226 case QEMU_OPTION_gdb
:
2227 gdbstub_dev
= optarg
;
2232 case QEMU_OPTION_bios
:
2235 case QEMU_OPTION_singlestep
:
2242 keyboard_layout
= optarg
;
2244 case QEMU_OPTION_localtime
:
2247 case QEMU_OPTION_vga
:
2248 select_vgahw (optarg
);
2255 w
= strtol(p
, (char **)&p
, 10);
2258 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2264 h
= strtol(p
, (char **)&p
, 10);
2269 depth
= strtol(p
, (char **)&p
, 10);
2270 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2271 depth
!= 24 && depth
!= 32)
2273 } else if (*p
== '\0') {
2274 depth
= graphic_depth
;
2281 graphic_depth
= depth
;
2284 case QEMU_OPTION_echr
:
2287 term_escape_char
= strtol(optarg
, &r
, 0);
2289 printf("Bad argument to echr\n");
2292 case QEMU_OPTION_monitor
:
2293 monitor_parse(optarg
, "readline");
2294 default_monitor
= 0;
2296 case QEMU_OPTION_qmp
:
2297 monitor_parse(optarg
, "control");
2298 default_monitor
= 0;
2300 case QEMU_OPTION_mon
:
2301 opts
= qemu_opts_parse(&qemu_mon_opts
, optarg
, 1);
2305 default_monitor
= 0;
2307 case QEMU_OPTION_chardev
:
2308 opts
= qemu_opts_parse(&qemu_chardev_opts
, optarg
, 1);
2314 case QEMU_OPTION_fsdev
:
2315 opts
= qemu_opts_parse(&qemu_fsdev_opts
, optarg
, 1);
2317 fprintf(stderr
, "parse error: %s\n", optarg
);
2321 case QEMU_OPTION_virtfs
: {
2322 char *arg_fsdev
= NULL
;
2323 char *arg_9p
= NULL
;
2326 opts
= qemu_opts_parse(&qemu_virtfs_opts
, optarg
, 1);
2328 fprintf(stderr
, "parse error: %s\n", optarg
);
2332 len
= strlen(",id=,path=");
2333 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2334 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2335 len
+= strlen(qemu_opt_get(opts
, "path"));
2336 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2339 fprintf(stderr
, "No memory to parse -fsdev for %s\n",
2344 sprintf(arg_fsdev
, "%s,id=%s,path=%s",
2345 qemu_opt_get(opts
, "fstype"),
2346 qemu_opt_get(opts
, "mount_tag"),
2347 qemu_opt_get(opts
, "path"));
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
));
2354 fprintf(stderr
, "No memory to parse -device for %s\n",
2359 sprintf(arg_9p
, "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2360 qemu_opt_get(opts
, "mount_tag"),
2361 qemu_opt_get(opts
, "mount_tag"));
2363 if (!qemu_opts_parse(&qemu_fsdev_opts
, arg_fsdev
, 1)) {
2364 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2368 if (!qemu_opts_parse(&qemu_device_opts
, arg_9p
, 1)) {
2369 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2373 qemu_free(arg_fsdev
);
2378 case QEMU_OPTION_serial
:
2379 add_device_config(DEV_SERIAL
, optarg
);
2381 if (strncmp(optarg
, "mon:", 4) == 0) {
2382 default_monitor
= 0;
2385 case QEMU_OPTION_watchdog
:
2388 "qemu: only one watchdog option may be given\n");
2393 case QEMU_OPTION_watchdog_action
:
2394 if (select_watchdog_action(optarg
) == -1) {
2395 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2399 case QEMU_OPTION_virtiocon
:
2400 add_device_config(DEV_VIRTCON
, optarg
);
2401 default_virtcon
= 0;
2402 if (strncmp(optarg
, "mon:", 4) == 0) {
2403 default_monitor
= 0;
2406 case QEMU_OPTION_parallel
:
2407 add_device_config(DEV_PARALLEL
, optarg
);
2408 default_parallel
= 0;
2409 if (strncmp(optarg
, "mon:", 4) == 0) {
2410 default_monitor
= 0;
2413 case QEMU_OPTION_debugcon
:
2414 add_device_config(DEV_DEBUGCON
, optarg
);
2416 case QEMU_OPTION_loadvm
:
2419 case QEMU_OPTION_full_screen
:
2423 case QEMU_OPTION_no_frame
:
2426 case QEMU_OPTION_alt_grab
:
2429 case QEMU_OPTION_ctrl_grab
:
2432 case QEMU_OPTION_no_quit
:
2435 case QEMU_OPTION_sdl
:
2436 display_type
= DT_SDL
;
2439 case QEMU_OPTION_pidfile
:
2442 case QEMU_OPTION_win2k_hack
:
2443 win2k_install_hack
= 1;
2445 case QEMU_OPTION_rtc_td_hack
:
2448 case QEMU_OPTION_acpitable
:
2449 do_acpitable_option(optarg
);
2451 case QEMU_OPTION_smbios
:
2452 do_smbios_option(optarg
);
2455 case QEMU_OPTION_enable_kvm
:
2459 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
: {
2479 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
2480 case QEMU_OPTION_pcidevice
:
2481 if (assigned_devices_index
>= MAX_DEV_ASSIGN_CMDLINE
) {
2482 fprintf(stderr
, "Too many assigned devices\n");
2485 assigned_devices
[assigned_devices_index
] = optarg
;
2486 assigned_devices_index
++;
2489 case QEMU_OPTION_usb
:
2492 case QEMU_OPTION_usbdevice
:
2494 add_device_config(DEV_USB
, optarg
);
2496 case QEMU_OPTION_device
:
2497 if (!qemu_opts_parse(&qemu_device_opts
, optarg
, 1)) {
2501 case QEMU_OPTION_smp
:
2504 fprintf(stderr
, "Invalid number of CPUs\n");
2507 if (max_cpus
< smp_cpus
) {
2508 fprintf(stderr
, "maxcpus must be equal to or greater than "
2512 if (max_cpus
> 255) {
2513 fprintf(stderr
, "Unsupported number of maxcpus\n");
2517 case QEMU_OPTION_vnc
:
2518 display_type
= DT_VNC
;
2519 vnc_display
= optarg
;
2521 case QEMU_OPTION_no_acpi
:
2524 case QEMU_OPTION_no_hpet
:
2527 case QEMU_OPTION_balloon
:
2528 if (balloon_parse(optarg
) < 0) {
2529 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2533 case QEMU_OPTION_no_reboot
:
2536 case QEMU_OPTION_no_shutdown
:
2539 case QEMU_OPTION_show_cursor
:
2542 case QEMU_OPTION_uuid
:
2543 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2544 fprintf(stderr
, "Fail to parse UUID string."
2545 " Wrong format.\n");
2549 case QEMU_OPTION_option_rom
:
2550 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2551 fprintf(stderr
, "Too many option ROMs\n");
2554 option_rom
[nb_option_roms
] = optarg
;
2557 case QEMU_OPTION_semihosting
:
2558 semihosting_enabled
= 1;
2560 case QEMU_OPTION_tdf
:
2563 case QEMU_OPTION_kvm_shadow_memory
:
2564 kvm_shadow_memory
= (int64_t)atoi(optarg
) * 1024 * 1024 / 4096;
2566 case QEMU_OPTION_name
:
2567 qemu_name
= qemu_strdup(optarg
);
2569 char *p
= strchr(qemu_name
, ',');
2572 if (strncmp(p
, "process=", 8)) {
2573 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2577 os_set_proc_name(p
);
2581 case QEMU_OPTION_prom_env
:
2582 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2583 fprintf(stderr
, "Too many prom variables\n");
2586 prom_envs
[nb_prom_envs
] = optarg
;
2589 case QEMU_OPTION_old_param
:
2592 case QEMU_OPTION_clock
:
2593 configure_alarms(optarg
);
2595 case QEMU_OPTION_startdate
:
2596 configure_rtc_date_offset(optarg
, 1);
2598 case QEMU_OPTION_rtc
:
2599 opts
= qemu_opts_parse(&qemu_rtc_opts
, optarg
, 0);
2603 configure_rtc(opts
);
2605 case QEMU_OPTION_tb_size
:
2606 tb_size
= strtol(optarg
, NULL
, 0);
2610 case QEMU_OPTION_icount
:
2611 icount_option
= optarg
;
2613 case QEMU_OPTION_incoming
:
2616 case QEMU_OPTION_nodefaults
:
2618 default_parallel
= 0;
2619 default_virtcon
= 0;
2620 default_monitor
= 0;
2628 case QEMU_OPTION_nvram
:
2632 case QEMU_OPTION_xen_domid
:
2633 if (!(xen_available())) {
2634 printf("Option %s not supported for this target\n", popt
->name
);
2637 xen_domid
= atoi(optarg
);
2639 case QEMU_OPTION_xen_create
:
2640 if (!(xen_available())) {
2641 printf("Option %s not supported for this target\n", popt
->name
);
2644 xen_mode
= XEN_CREATE
;
2646 case QEMU_OPTION_xen_attach
:
2647 if (!(xen_available())) {
2648 printf("Option %s not supported for this target\n", popt
->name
);
2651 xen_mode
= XEN_ATTACH
;
2653 case QEMU_OPTION_readconfig
:
2655 int ret
= qemu_read_config_file(optarg
);
2657 fprintf(stderr
, "read config %s: %s\n", optarg
,
2663 case QEMU_OPTION_writeconfig
:
2666 if (strcmp(optarg
, "-") == 0) {
2669 fp
= fopen(optarg
, "w");
2671 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2675 qemu_config_write(fp
);
2680 os_parse_cmd_args(popt
->index
, optarg
);
2686 /* If no data_dir is specified then try to find it relative to the
2689 data_dir
= os_find_datadir(argv
[0]);
2691 /* If all else fails use the install patch specified when building. */
2693 data_dir
= CONFIG_QEMU_DATADIR
;
2697 * Default to max_cpus = smp_cpus, in case the user doesn't
2698 * specify a max_cpus value.
2701 max_cpus
= smp_cpus
;
2703 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2704 if (smp_cpus
> machine
->max_cpus
) {
2705 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2706 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2711 qemu_opts_foreach(&qemu_device_opts
, default_driver_check
, NULL
, 0);
2712 qemu_opts_foreach(&qemu_global_opts
, default_driver_check
, NULL
, 0);
2714 if (machine
->no_serial
) {
2717 if (machine
->no_parallel
) {
2718 default_parallel
= 0;
2720 if (!machine
->use_virtcon
) {
2721 default_virtcon
= 0;
2723 if (machine
->no_vga
) {
2726 if (machine
->no_floppy
) {
2729 if (machine
->no_cdrom
) {
2732 if (machine
->no_sdcard
) {
2736 if (display_type
== DT_NOGRAPHIC
) {
2737 if (default_parallel
)
2738 add_device_config(DEV_PARALLEL
, "null");
2739 if (default_serial
&& default_monitor
) {
2740 add_device_config(DEV_SERIAL
, "mon:stdio");
2741 } else if (default_virtcon
&& default_monitor
) {
2742 add_device_config(DEV_VIRTCON
, "mon:stdio");
2745 add_device_config(DEV_SERIAL
, "stdio");
2746 if (default_virtcon
)
2747 add_device_config(DEV_VIRTCON
, "stdio");
2748 if (default_monitor
)
2749 monitor_parse("stdio", "readline");
2753 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2754 if (default_parallel
)
2755 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2756 if (default_monitor
)
2757 monitor_parse("vc:80Cx24C", "readline");
2758 if (default_virtcon
)
2759 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2762 vga_interface_type
= VGA_CIRRUS
;
2766 if (qemu_opts_foreach(&qemu_chardev_opts
, chardev_init_func
, NULL
, 1) != 0)
2769 if (qemu_opts_foreach(&qemu_fsdev_opts
, fsdev_init_func
, NULL
, 1) != 0) {
2776 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2782 int ret
= kvm_init(smp_cpus
);
2784 #if defined(KVM_UPSTREAM) || defined(CONFIG_NO_CPU_EMULATION)
2785 if (!kvm_available()) {
2786 printf("KVM not supported for this target\n");
2788 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2793 fprintf(stderr
, "Could not initialize KVM, will disable KVM support\n");
2799 if (qemu_init_main_loop()) {
2800 fprintf(stderr
, "qemu_init_main_loop failed\n");
2803 linux_boot
= (kernel_filename
!= NULL
);
2805 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2806 fprintf(stderr
, "-append only allowed with -kernel option\n");
2810 if (!linux_boot
&& initrd_filename
!= NULL
) {
2811 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2815 os_set_line_buffering();
2817 if (init_timer_alarm() < 0) {
2818 fprintf(stderr
, "could not initialize alarm timer\n");
2821 configure_icount(icount_option
);
2823 if (net_init_clients() < 0) {
2827 /* init the bluetooth world */
2828 if (foreach_device_config(DEV_BT
, bt_parse
))
2831 /* init the memory */
2833 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2835 /* init the dynamic translator */
2836 cpu_exec_init_all(tb_size
* 1024 * 1024);
2838 bdrv_init_with_whitelist();
2842 if (default_cdrom
) {
2843 /* we always create the cdrom drive, even if no disk is there */
2844 drive_add(NULL
, CDROM_ALIAS
);
2847 if (default_floppy
) {
2848 /* we always create at least one floppy */
2849 drive_add(NULL
, FD_ALIAS
, 0);
2852 if (default_sdcard
) {
2853 /* we always create one sd slot, even if no card is in it */
2854 drive_add(NULL
, SD_ALIAS
);
2857 /* open the virtual block devices */
2859 qemu_opts_foreach(&qemu_drive_opts
, drive_enable_snapshot
, NULL
, 0);
2860 if (qemu_opts_foreach(&qemu_drive_opts
, drive_init_func
, &machine
->use_scsi
, 1) != 0)
2863 register_savevm_live("ram", 0, 3, NULL
, ram_save_live
, NULL
,
2866 if (nb_numa_nodes
> 0) {
2869 if (nb_numa_nodes
> smp_cpus
) {
2870 nb_numa_nodes
= smp_cpus
;
2873 /* If no memory size if given for any node, assume the default case
2874 * and distribute the available memory equally across all nodes
2876 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2877 if (node_mem
[i
] != 0)
2880 if (i
== nb_numa_nodes
) {
2881 uint64_t usedmem
= 0;
2883 /* On Linux, the each node's border has to be 8MB aligned,
2884 * the final node gets the rest.
2886 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2887 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2888 usedmem
+= node_mem
[i
];
2890 node_mem
[i
] = ram_size
- usedmem
;
2893 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2894 if (node_cpumask
[i
] != 0)
2897 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2898 * must cope with this anyway, because there are BIOSes out there in
2899 * real machines which also use this scheme.
2901 if (i
== nb_numa_nodes
) {
2902 for (i
= 0; i
< smp_cpus
; i
++) {
2903 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2908 if (qemu_opts_foreach(&qemu_mon_opts
, mon_init_func
, NULL
, 1) != 0) {
2912 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2914 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2916 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2918 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2921 module_call_init(MODULE_INIT_DEVICE
);
2923 if (qemu_opts_foreach(&qemu_device_opts
, device_help_func
, NULL
, 0) != 0)
2927 i
= select_watchdog(watchdog
);
2929 exit (i
== 1 ? 1 : 0);
2932 if (machine
->compat_props
) {
2933 qdev_prop_register_global_list(machine
->compat_props
);
2937 machine
->init(ram_size
, boot_devices
,
2938 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2940 cpu_synchronize_all_post_init();
2942 /* must be after terminal init, SDL library changes signal handlers */
2943 os_setup_signal_handling();
2947 current_machine
= machine
;
2949 /* init USB devices */
2951 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2955 /* init generic devices */
2956 if (qemu_opts_foreach(&qemu_device_opts
, device_init_func
, NULL
, 1) != 0)
2959 net_check_clients();
2961 /* just use the first displaystate for the moment */
2962 ds
= get_displaystate();
2964 if (display_type
== DT_DEFAULT
) {
2965 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
2966 display_type
= DT_SDL
;
2968 display_type
= DT_VNC
;
2969 vnc_display
= "localhost:0,to=99";
2975 switch (display_type
) {
2978 #if defined(CONFIG_CURSES)
2980 curses_display_init(ds
, full_screen
);
2983 #if defined(CONFIG_SDL)
2985 sdl_display_init(ds
, full_screen
, no_frame
);
2987 #elif defined(CONFIG_COCOA)
2989 cocoa_display_init(ds
, full_screen
);
2993 vnc_display_init(ds
);
2994 if (vnc_display_open(ds
, vnc_display
) < 0)
2997 if (show_vnc_port
) {
2998 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3006 dcl
= ds
->listeners
;
3007 while (dcl
!= NULL
) {
3008 if (dcl
->dpy_refresh
!= NULL
) {
3009 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
3010 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
3016 if (display_type
== DT_NOGRAPHIC
|| display_type
== DT_VNC
) {
3017 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
3018 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
3021 text_consoles_set_display(ds
);
3023 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3024 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3029 qdev_machine_creation_done();
3031 if (rom_load_all() != 0) {
3032 fprintf(stderr
, "rom loading failed\n");
3036 qemu_system_reset();
3038 if (load_vmstate(loadvm
) < 0) {
3044 qemu_start_incoming_migration(incoming
);
3045 } else if (autostart
) {