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>
53 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
55 #include <sys/sysctl.h>
64 #include <linux/ppdev.h>
65 #include <linux/parport.h>
69 #include <sys/ethernet.h>
70 #include <sys/sockio.h>
71 #include <netinet/arp.h>
72 #include <netinet/in_systm.h>
73 #include <netinet/ip.h>
74 #include <netinet/ip_icmp.h> // must come after ip.h
75 #include <netinet/udp.h>
76 #include <netinet/tcp.h>
84 #if defined(__OpenBSD__)
88 #if defined(CONFIG_VDE)
89 #include <libvdeplug.h>
97 #if defined(__APPLE__) || defined(main)
99 int qemu_main(int argc
, char **argv
, char **envp
);
100 int main(int argc
, char **argv
)
102 return qemu_main(argc
, argv
, NULL
);
105 #define main qemu_main
107 #endif /* CONFIG_SDL */
111 #define main qemu_main
112 #endif /* CONFIG_COCOA */
115 #include "hw/boards.h"
117 #include "hw/pcmcia.h"
122 #include "hw/watchdog.h"
123 #include "hw/smbios.h"
126 #include "hw/loader.h"
129 #include "net/slirp.h"
134 #include "qemu-timer.h"
135 #include "qemu-char.h"
136 #include "cache-utils.h"
138 #include "blockdev.h"
139 #include "block-migration.h"
141 #include "audio/audio.h"
142 #include "migration.h"
144 #include "qemu-option.h"
145 #include "qemu-config.h"
146 #include "qemu-objects.h"
147 #include "qemu-options.h"
149 #include "fsdev/qemu-fsdev.h"
154 #include "qemu_socket.h"
156 #include "slirp/libslirp.h"
159 #include "simpletrace.h"
160 #include "qemu-queue.h"
162 #include "arch_init.h"
164 #include "ui/qemu-spice.h"
167 //#define DEBUG_SLIRP
169 #define DEFAULT_RAM_SIZE 128
171 #define MAX_VIRTIO_CONSOLES 1
173 static const char *data_dir
;
174 const char *bios_name
= NULL
;
175 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
176 DisplayType display_type
= DT_DEFAULT
;
177 int display_remote
= 0;
178 const char* keyboard_layout
= NULL
;
180 const char *mem_path
= NULL
;
182 int mem_prealloc
= 0; /* force preallocation of physical target memory */
185 NICInfo nd_table
[MAX_NICS
];
188 int incoming_expected
; /* Started with -incoming and waiting for incoming */
189 static int rtc_utc
= 1;
190 static int rtc_date_offset
= -1; /* -1 means no change */
191 QEMUClock
*rtc_clock
;
192 int vga_interface_type
= VGA_NONE
;
193 static int full_screen
= 0;
195 static int no_frame
= 0;
198 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
199 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
200 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
201 int win2k_install_hack
= 0;
210 const char *vnc_display
;
212 int acpi_enabled
= 1;
218 int graphic_rotate
= 0;
219 uint8_t irq0override
= 1;
220 const char *watchdog
;
221 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
223 int semihosting_enabled
= 0;
225 const char *qemu_name
;
228 unsigned int nb_prom_envs
= 0;
229 const char *prom_envs
[MAX_PROM_ENVS
];
231 uint8_t *boot_splash_filedata
;
232 int boot_splash_filedata_size
;
233 uint8_t qemu_extra_params_fw
[2];
235 typedef struct FWBootEntry FWBootEntry
;
238 QTAILQ_ENTRY(FWBootEntry
) link
;
244 QTAILQ_HEAD(, FWBootEntry
) fw_boot_order
= QTAILQ_HEAD_INITIALIZER(fw_boot_order
);
247 uint64_t node_mem
[MAX_NODES
];
248 uint64_t node_cpumask
[MAX_NODES
];
250 static QEMUTimer
*nographic_timer
;
252 uint8_t qemu_uuid
[16];
254 static QEMUBootSetHandler
*boot_set_handler
;
255 static void *boot_set_opaque
;
257 static NotifierList exit_notifiers
=
258 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
260 static NotifierList machine_init_done_notifiers
=
261 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
263 static int tcg_allowed
= 1;
267 enum xen_mode xen_mode
= XEN_EMULATE
;
269 static int default_serial
= 1;
270 static int default_parallel
= 1;
271 static int default_virtcon
= 1;
272 static int default_monitor
= 1;
273 static int default_vga
= 1;
274 static int default_floppy
= 1;
275 static int default_cdrom
= 1;
276 static int default_sdcard
= 1;
282 { .driver
= "isa-serial", .flag
= &default_serial
},
283 { .driver
= "isa-parallel", .flag
= &default_parallel
},
284 { .driver
= "isa-fdc", .flag
= &default_floppy
},
285 { .driver
= "ide-cd", .flag
= &default_cdrom
},
286 { .driver
= "ide-hd", .flag
= &default_cdrom
},
287 { .driver
= "ide-drive", .flag
= &default_cdrom
},
288 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
289 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
290 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
291 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
292 { .driver
= "VGA", .flag
= &default_vga
},
293 { .driver
= "cirrus-vga", .flag
= &default_vga
},
294 { .driver
= "vmware-svga", .flag
= &default_vga
},
295 { .driver
= "isa-vga", .flag
= &default_vga
},
296 { .driver
= "qxl-vga", .flag
= &default_vga
},
299 static void res_free(void)
301 if (boot_splash_filedata
!= NULL
) {
302 qemu_free(boot_splash_filedata
);
303 boot_splash_filedata
= NULL
;
307 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
309 const char *driver
= qemu_opt_get(opts
, "driver");
314 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
315 if (strcmp(default_list
[i
].driver
, driver
) != 0)
317 *(default_list
[i
].flag
) = 0;
322 /***********************************************************/
323 /* real time host monotonic timer */
325 /***********************************************************/
326 /* host time/date access */
327 void qemu_get_timedate(struct tm
*tm
, int offset
)
334 if (rtc_date_offset
== -1) {
338 ret
= localtime(&ti
);
340 ti
-= rtc_date_offset
;
344 memcpy(tm
, ret
, sizeof(struct tm
));
347 int qemu_timedate_diff(struct tm
*tm
)
351 if (rtc_date_offset
== -1)
353 seconds
= mktimegm(tm
);
355 seconds
= mktime(tm
);
357 seconds
= mktimegm(tm
) + rtc_date_offset
;
359 return seconds
- time(NULL
);
362 void rtc_change_mon_event(struct tm
*tm
)
366 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
367 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
368 qobject_decref(data
);
371 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
373 time_t rtc_start_date
;
376 if (!strcmp(startdate
, "now") && legacy
) {
377 rtc_date_offset
= -1;
379 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
387 } else if (sscanf(startdate
, "%d-%d-%d",
399 rtc_start_date
= mktimegm(&tm
);
400 if (rtc_start_date
== -1) {
402 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
403 "'2006-06-17T16:01:21' or '2006-06-17'\n");
406 rtc_date_offset
= time(NULL
) - rtc_start_date
;
410 static void configure_rtc(QemuOpts
*opts
)
414 value
= qemu_opt_get(opts
, "base");
416 if (!strcmp(value
, "utc")) {
418 } else if (!strcmp(value
, "localtime")) {
421 configure_rtc_date_offset(value
, 0);
424 value
= qemu_opt_get(opts
, "clock");
426 if (!strcmp(value
, "host")) {
427 rtc_clock
= host_clock
;
428 } else if (!strcmp(value
, "vm")) {
429 rtc_clock
= vm_clock
;
431 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
435 value
= qemu_opt_get(opts
, "driftfix");
437 if (!strcmp(value
, "slew")) {
439 } else if (!strcmp(value
, "none")) {
442 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
448 /***********************************************************/
449 /* Bluetooth support */
452 static struct HCIInfo
*hci_table
[MAX_NICS
];
454 static struct bt_vlan_s
{
455 struct bt_scatternet_s net
;
457 struct bt_vlan_s
*next
;
460 /* find or alloc a new bluetooth "VLAN" */
461 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
463 struct bt_vlan_s
**pvlan
, *vlan
;
464 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
468 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
470 pvlan
= &first_bt_vlan
;
471 while (*pvlan
!= NULL
)
472 pvlan
= &(*pvlan
)->next
;
477 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
481 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
486 static struct HCIInfo null_hci
= {
487 .cmd_send
= null_hci_send
,
488 .sco_send
= null_hci_send
,
489 .acl_send
= null_hci_send
,
490 .bdaddr_set
= null_hci_addr_set
,
493 struct HCIInfo
*qemu_next_hci(void)
495 if (cur_hci
== nb_hcis
)
498 return hci_table
[cur_hci
++];
501 static struct HCIInfo
*hci_init(const char *str
)
504 struct bt_scatternet_s
*vlan
= 0;
506 if (!strcmp(str
, "null"))
509 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
511 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
512 else if (!strncmp(str
, "hci", 3)) {
515 if (!strncmp(str
+ 3, ",vlan=", 6)) {
516 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
521 vlan
= qemu_find_bt_vlan(0);
523 return bt_new_hci(vlan
);
526 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
531 static int bt_hci_parse(const char *str
)
536 if (nb_hcis
>= MAX_NICS
) {
537 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
550 bdaddr
.b
[5] = 0x56 + nb_hcis
;
551 hci
->bdaddr_set(hci
, bdaddr
.b
);
553 hci_table
[nb_hcis
++] = hci
;
558 static void bt_vhci_add(int vlan_id
)
560 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
563 fprintf(stderr
, "qemu: warning: adding a VHCI to "
564 "an empty scatternet %i\n", vlan_id
);
566 bt_vhci_init(bt_new_hci(vlan
));
569 static struct bt_device_s
*bt_device_add(const char *opt
)
571 struct bt_scatternet_s
*vlan
;
573 char *endp
= strstr(opt
, ",vlan=");
574 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
577 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
580 vlan_id
= strtol(endp
+ 6, &endp
, 0);
582 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
587 vlan
= qemu_find_bt_vlan(vlan_id
);
590 fprintf(stderr
, "qemu: warning: adding a slave device to "
591 "an empty scatternet %i\n", vlan_id
);
593 if (!strcmp(devname
, "keyboard"))
594 return bt_keyboard_init(vlan
);
596 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
600 static int bt_parse(const char *opt
)
602 const char *endp
, *p
;
605 if (strstart(opt
, "hci", &endp
)) {
606 if (!*endp
|| *endp
== ',') {
608 if (!strstart(endp
, ",vlan=", 0))
611 return bt_hci_parse(opt
);
613 } else if (strstart(opt
, "vhci", &endp
)) {
614 if (!*endp
|| *endp
== ',') {
616 if (strstart(endp
, ",vlan=", &p
)) {
617 vlan
= strtol(p
, (char **) &endp
, 0);
619 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
623 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
632 } else if (strstart(opt
, "device:", &endp
))
633 return !bt_device_add(endp
);
635 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
639 /***********************************************************/
640 /* QEMU Block devices */
642 #define HD_OPTS "media=disk"
643 #define CDROM_OPTS "media=cdrom"
645 #define PFLASH_OPTS ""
649 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
651 int *use_scsi
= opaque
;
653 return drive_init(opts
, *use_scsi
) == NULL
;
656 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
658 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
659 qemu_opt_set(opts
, "snapshot", "on");
664 static void default_drive(int enable
, int snapshot
, int use_scsi
,
665 BlockInterfaceType type
, int index
,
670 if (type
== IF_DEFAULT
) {
671 type
= use_scsi
? IF_SCSI
: IF_IDE
;
674 if (!enable
|| drive_get_by_index(type
, index
)) {
678 opts
= drive_add(type
, index
, NULL
, optstr
);
680 drive_enable_snapshot(opts
, NULL
);
682 if (!drive_init(opts
, use_scsi
)) {
687 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
689 boot_set_handler
= func
;
690 boot_set_opaque
= opaque
;
693 int qemu_boot_set(const char *boot_devices
)
695 if (!boot_set_handler
) {
698 return boot_set_handler(boot_set_opaque
, boot_devices
);
701 static void validate_bootdevices(char *devices
)
703 /* We just do some generic consistency checks */
707 for (p
= devices
; *p
!= '\0'; p
++) {
708 /* Allowed boot devices are:
709 * a-b: floppy disk drives
710 * c-f: IDE disk drives
711 * g-m: machine implementation dependant drives
712 * n-p: network devices
713 * It's up to each machine implementation to check if the given boot
714 * devices match the actual hardware implementation and firmware
717 if (*p
< 'a' || *p
> 'p') {
718 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
721 if (bitmap
& (1 << (*p
- 'a'))) {
722 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
725 bitmap
|= 1 << (*p
- 'a');
729 static void restore_boot_devices(void *opaque
)
731 char *standard_boot_devices
= opaque
;
732 static int first
= 1;
734 /* Restore boot order and remove ourselves after the first boot */
740 qemu_boot_set(standard_boot_devices
);
742 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
743 qemu_free(standard_boot_devices
);
746 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
749 FWBootEntry
*node
, *i
;
755 assert(dev
!= NULL
|| suffix
!= NULL
);
757 node
= qemu_mallocz(sizeof(FWBootEntry
));
758 node
->bootindex
= bootindex
;
759 node
->suffix
= suffix
? qemu_strdup(suffix
) : NULL
;
762 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
763 if (i
->bootindex
== bootindex
) {
764 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
766 } else if (i
->bootindex
< bootindex
) {
769 QTAILQ_INSERT_BEFORE(i
, node
, link
);
772 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
776 * This function returns null terminated string that consist of new line
777 * separated device paths.
779 * memory pointed by "size" is assigned total length of the array in bytes
782 char *get_boot_devices_list(uint32_t *size
)
788 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
789 char *devpath
= NULL
, *bootpath
;
793 devpath
= qdev_get_fw_dev_path(i
->dev
);
797 if (i
->suffix
&& devpath
) {
798 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
800 bootpath
= qemu_malloc(bootpathlen
);
801 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
803 } else if (devpath
) {
806 bootpath
= qemu_strdup(i
->suffix
);
811 list
[total
-1] = '\n';
813 len
= strlen(bootpath
) + 1;
814 list
= qemu_realloc(list
, total
+ len
);
815 memcpy(&list
[total
], bootpath
, len
);
825 static void numa_add(const char *optarg
)
829 unsigned long long value
, endvalue
;
832 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
833 if (!strcmp(option
, "node")) {
834 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
835 nodenr
= nb_numa_nodes
;
837 nodenr
= strtoull(option
, NULL
, 10);
840 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
841 node_mem
[nodenr
] = 0;
844 sval
= strtosz(option
, NULL
);
846 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
849 node_mem
[nodenr
] = sval
;
851 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
852 node_cpumask
[nodenr
] = 0;
854 value
= strtoull(option
, &endptr
, 10);
857 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
859 if (*endptr
== '-') {
860 endvalue
= strtoull(endptr
+1, &endptr
, 10);
861 if (endvalue
>= 63) {
864 "only 63 CPUs in NUMA mode supported.\n");
866 value
= (2ULL << endvalue
) - (1ULL << value
);
868 value
= 1ULL << value
;
871 node_cpumask
[nodenr
] = value
;
878 static void smp_parse(const char *optarg
)
880 int smp
, sockets
= 0, threads
= 0, cores
= 0;
884 smp
= strtoul(optarg
, &endptr
, 10);
885 if (endptr
!= optarg
) {
886 if (*endptr
== ',') {
890 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
891 sockets
= strtoull(option
, NULL
, 10);
892 if (get_param_value(option
, 128, "cores", endptr
) != 0)
893 cores
= strtoull(option
, NULL
, 10);
894 if (get_param_value(option
, 128, "threads", endptr
) != 0)
895 threads
= strtoull(option
, NULL
, 10);
896 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
897 max_cpus
= strtoull(option
, NULL
, 10);
899 /* compute missing values, prefer sockets over cores over threads */
900 if (smp
== 0 || sockets
== 0) {
901 sockets
= sockets
> 0 ? sockets
: 1;
902 cores
= cores
> 0 ? cores
: 1;
903 threads
= threads
> 0 ? threads
: 1;
905 smp
= cores
* threads
* sockets
;
909 threads
= threads
> 0 ? threads
: 1;
910 cores
= smp
/ (sockets
* threads
);
912 threads
= smp
/ (cores
* sockets
);
916 smp_cores
= cores
> 0 ? cores
: 1;
917 smp_threads
= threads
> 0 ? threads
: 1;
922 /***********************************************************/
925 static int usb_device_add(const char *devname
)
928 USBDevice
*dev
= NULL
;
933 /* drivers with .usbdevice_name entry in USBDeviceInfo */
934 dev
= usbdevice_create(devname
);
940 /* only the linux version is qdev-ified, usb-bsd still needs this */
941 if (strstart(devname
, "host:", &p
)) {
942 dev
= usb_host_device_open(p
);
945 if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
946 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
947 bt_new_hci(qemu_find_bt_vlan(0)));
958 static int usb_device_del(const char *devname
)
963 if (strstart(devname
, "host:", &p
))
964 return usb_host_device_close(p
);
969 p
= strchr(devname
, '.');
972 bus_num
= strtoul(devname
, NULL
, 0);
973 addr
= strtoul(p
+ 1, NULL
, 0);
975 return usb_device_delete_addr(bus_num
, addr
);
978 static int usb_parse(const char *cmdline
)
981 r
= usb_device_add(cmdline
);
983 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
988 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
990 const char *devname
= qdict_get_str(qdict
, "devname");
991 if (usb_device_add(devname
) < 0) {
992 error_report("could not add USB device '%s'", devname
);
996 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
998 const char *devname
= qdict_get_str(qdict
, "devname");
999 if (usb_device_del(devname
) < 0) {
1000 error_report("could not delete USB device '%s'", devname
);
1004 /***********************************************************/
1005 /* PCMCIA/Cardbus */
1007 static struct pcmcia_socket_entry_s
{
1008 PCMCIASocket
*socket
;
1009 struct pcmcia_socket_entry_s
*next
;
1010 } *pcmcia_sockets
= 0;
1012 void pcmcia_socket_register(PCMCIASocket
*socket
)
1014 struct pcmcia_socket_entry_s
*entry
;
1016 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
1017 entry
->socket
= socket
;
1018 entry
->next
= pcmcia_sockets
;
1019 pcmcia_sockets
= entry
;
1022 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
1024 struct pcmcia_socket_entry_s
*entry
, **ptr
;
1026 ptr
= &pcmcia_sockets
;
1027 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
1028 if (entry
->socket
== socket
) {
1034 void pcmcia_info(Monitor
*mon
)
1036 struct pcmcia_socket_entry_s
*iter
;
1038 if (!pcmcia_sockets
)
1039 monitor_printf(mon
, "No PCMCIA sockets\n");
1041 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1042 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1043 iter
->socket
->attached
? iter
->socket
->card_string
:
1047 /***********************************************************/
1048 /* machine registration */
1050 static QEMUMachine
*first_machine
= NULL
;
1051 QEMUMachine
*current_machine
= NULL
;
1053 int qemu_register_machine(QEMUMachine
*m
)
1056 pm
= &first_machine
;
1064 static QEMUMachine
*find_machine(const char *name
)
1068 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1069 if (!strcmp(m
->name
, name
))
1071 if (m
->alias
&& !strcmp(m
->alias
, name
))
1077 static QEMUMachine
*find_default_machine(void)
1081 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1082 if (m
->is_default
) {
1089 /***********************************************************/
1090 /* main execution loop */
1092 static void gui_update(void *opaque
)
1094 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1095 DisplayState
*ds
= opaque
;
1096 DisplayChangeListener
*dcl
= ds
->listeners
;
1098 qemu_flush_coalesced_mmio_buffer();
1101 while (dcl
!= NULL
) {
1102 if (dcl
->gui_timer_interval
&&
1103 dcl
->gui_timer_interval
< interval
)
1104 interval
= dcl
->gui_timer_interval
;
1107 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock_ms(rt_clock
));
1110 static void nographic_update(void *opaque
)
1112 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1114 qemu_flush_coalesced_mmio_buffer();
1115 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock_ms(rt_clock
));
1118 struct vm_change_state_entry
{
1119 VMChangeStateHandler
*cb
;
1121 QLIST_ENTRY (vm_change_state_entry
) entries
;
1124 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1126 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1129 VMChangeStateEntry
*e
;
1131 e
= qemu_mallocz(sizeof (*e
));
1135 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1139 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1141 QLIST_REMOVE (e
, entries
);
1145 void vm_state_notify(int running
, int reason
)
1147 VMChangeStateEntry
*e
;
1149 trace_vm_state_notify(running
, reason
);
1151 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1152 e
->cb(e
->opaque
, running
, reason
);
1161 vm_state_notify(1, 0);
1163 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1167 /* reset/shutdown handler */
1169 typedef struct QEMUResetEntry
{
1170 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1171 QEMUResetHandler
*func
;
1175 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1176 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1177 static int reset_requested
;
1178 static int shutdown_requested
, shutdown_signal
= -1;
1179 static pid_t shutdown_pid
;
1180 static int powerdown_requested
;
1181 static int debug_requested
;
1182 static int vmstop_requested
;
1184 int qemu_shutdown_requested_get(void)
1186 return shutdown_requested
;
1189 int qemu_reset_requested_get(void)
1191 return reset_requested
;
1194 int qemu_shutdown_requested(void)
1196 int r
= shutdown_requested
;
1197 shutdown_requested
= 0;
1201 void qemu_kill_report(void)
1203 if (shutdown_signal
!= -1) {
1204 fprintf(stderr
, "qemu: terminating on signal %d", shutdown_signal
);
1205 if (shutdown_pid
== 0) {
1206 /* This happens for eg ^C at the terminal, so it's worth
1207 * avoiding printing an odd message in that case.
1209 fputc('\n', stderr
);
1211 fprintf(stderr
, " from pid " FMT_pid
"\n", shutdown_pid
);
1213 shutdown_signal
= -1;
1217 int qemu_reset_requested(void)
1219 int r
= reset_requested
;
1220 reset_requested
= 0;
1224 int qemu_powerdown_requested(void)
1226 int r
= powerdown_requested
;
1227 powerdown_requested
= 0;
1231 static int qemu_debug_requested(void)
1233 int r
= debug_requested
;
1234 debug_requested
= 0;
1238 static int qemu_vmstop_requested(void)
1240 int r
= vmstop_requested
;
1241 vmstop_requested
= 0;
1245 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1247 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1250 re
->opaque
= opaque
;
1251 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1254 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1258 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1259 if (re
->func
== func
&& re
->opaque
== opaque
) {
1260 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1267 void qemu_system_reset(bool report
)
1269 QEMUResetEntry
*re
, *nre
;
1271 /* reset all devices */
1272 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1273 re
->func(re
->opaque
);
1276 monitor_protocol_event(QEVENT_RESET
, NULL
);
1278 cpu_synchronize_all_post_reset();
1281 void qemu_system_reset_request(void)
1284 shutdown_requested
= 1;
1286 reset_requested
= 1;
1289 qemu_notify_event();
1292 void qemu_system_killed(int signal
, pid_t pid
)
1294 shutdown_signal
= signal
;
1296 qemu_system_shutdown_request();
1299 void qemu_system_shutdown_request(void)
1301 shutdown_requested
= 1;
1302 qemu_notify_event();
1305 void qemu_system_powerdown_request(void)
1307 powerdown_requested
= 1;
1308 qemu_notify_event();
1311 void qemu_system_debug_request(void)
1313 debug_requested
= 1;
1314 qemu_notify_event();
1317 void qemu_system_vmstop_request(int reason
)
1319 vmstop_requested
= reason
;
1320 qemu_notify_event();
1323 void main_loop_wait(int nonblocking
)
1325 fd_set rfds
, wfds
, xfds
;
1333 timeout
= qemu_calculate_timeout();
1334 qemu_bh_update_timeout(&timeout
);
1337 os_host_main_loop_wait(&timeout
);
1339 tv
.tv_sec
= timeout
/ 1000;
1340 tv
.tv_usec
= (timeout
% 1000) * 1000;
1342 /* poll any events */
1343 /* XXX: separate device handlers from system ones */
1348 qemu_iohandler_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1349 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1351 qemu_mutex_unlock_iothread();
1352 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1353 qemu_mutex_lock_iothread();
1355 qemu_iohandler_poll(&rfds
, &wfds
, &xfds
, ret
);
1356 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1358 qemu_run_all_timers();
1360 /* Check bottom-halves last in case any of the earlier events triggered
1366 #ifndef CONFIG_IOTHREAD
1367 static int vm_request_pending(void)
1369 return powerdown_requested
||
1371 shutdown_requested
||
1377 qemu_irq qemu_system_powerdown
;
1379 static void main_loop(void)
1381 bool nonblocking
= false;
1382 #ifdef CONFIG_PROFILER
1387 qemu_main_loop_start();
1390 #ifndef CONFIG_IOTHREAD
1391 nonblocking
= cpu_exec_all();
1392 if (vm_request_pending()) {
1396 #ifdef CONFIG_PROFILER
1397 ti
= profile_getclock();
1399 main_loop_wait(nonblocking
);
1400 #ifdef CONFIG_PROFILER
1401 dev_time
+= profile_getclock() - ti
;
1404 if (qemu_debug_requested()) {
1405 vm_stop(VMSTOP_DEBUG
);
1407 if (qemu_shutdown_requested()) {
1409 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1411 vm_stop(VMSTOP_SHUTDOWN
);
1415 if (qemu_reset_requested()) {
1417 cpu_synchronize_all_states();
1418 qemu_system_reset(VMRESET_REPORT
);
1421 if (qemu_powerdown_requested()) {
1422 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1423 qemu_irq_raise(qemu_system_powerdown
);
1425 if ((r
= qemu_vmstop_requested())) {
1433 static void version(void)
1435 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1438 static void help(int exitcode
)
1440 const char *options_help
=
1441 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1443 #define DEFHEADING(text) stringify(text) "\n"
1444 #include "qemu-options.def"
1450 printf("usage: %s [options] [disk_image]\n"
1452 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1455 "During emulation, the following keys are useful:\n"
1456 "ctrl-alt-f toggle full screen\n"
1457 "ctrl-alt-n switch to virtual console 'n'\n"
1458 "ctrl-alt toggle mouse and keyboard grab\n"
1460 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1466 #define HAS_ARG 0x0001
1468 typedef struct QEMUOption
{
1475 static const QEMUOption qemu_options
[] = {
1476 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1477 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1478 { option, opt_arg, opt_enum, arch_mask },
1479 #define DEFHEADING(text)
1480 #include "qemu-options.def"
1486 static void select_vgahw (const char *p
)
1491 vga_interface_type
= VGA_NONE
;
1492 if (strstart(p
, "std", &opts
)) {
1493 vga_interface_type
= VGA_STD
;
1494 } else if (strstart(p
, "cirrus", &opts
)) {
1495 vga_interface_type
= VGA_CIRRUS
;
1496 } else if (strstart(p
, "vmware", &opts
)) {
1497 vga_interface_type
= VGA_VMWARE
;
1498 } else if (strstart(p
, "xenfb", &opts
)) {
1499 vga_interface_type
= VGA_XENFB
;
1500 } else if (strstart(p
, "qxl", &opts
)) {
1501 vga_interface_type
= VGA_QXL
;
1502 } else if (!strstart(p
, "none", &opts
)) {
1504 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1508 const char *nextopt
;
1510 if (strstart(opts
, ",retrace=", &nextopt
)) {
1512 if (strstart(opts
, "dumb", &nextopt
))
1513 vga_retrace_method
= VGA_RETRACE_DUMB
;
1514 else if (strstart(opts
, "precise", &nextopt
))
1515 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1516 else goto invalid_vga
;
1517 } else goto invalid_vga
;
1522 static DisplayType
select_display(const char *p
)
1525 DisplayType display
= DT_DEFAULT
;
1527 if (strstart(p
, "sdl", &opts
)) {
1531 const char *nextopt
;
1533 if (strstart(opts
, ",frame=", &nextopt
)) {
1535 if (strstart(opts
, "on", &nextopt
)) {
1537 } else if (strstart(opts
, "off", &nextopt
)) {
1540 goto invalid_sdl_args
;
1542 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1544 if (strstart(opts
, "on", &nextopt
)) {
1546 } else if (strstart(opts
, "off", &nextopt
)) {
1549 goto invalid_sdl_args
;
1551 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1553 if (strstart(opts
, "on", &nextopt
)) {
1555 } else if (strstart(opts
, "off", &nextopt
)) {
1558 goto invalid_sdl_args
;
1560 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
1562 if (strstart(opts
, "on", &nextopt
)) {
1564 } else if (strstart(opts
, "off", &nextopt
)) {
1567 goto invalid_sdl_args
;
1571 fprintf(stderr
, "Invalid SDL option string: %s\n", p
);
1577 fprintf(stderr
, "SDL support is disabled\n");
1580 } else if (strstart(p
, "vnc", &opts
)) {
1585 const char *nextopt
;
1587 if (strstart(opts
, "=", &nextopt
)) {
1588 vnc_display
= nextopt
;
1592 fprintf(stderr
, "VNC requires a display argument vnc=<display>\n");
1596 fprintf(stderr
, "VNC support is disabled\n");
1599 } else if (strstart(p
, "curses", &opts
)) {
1600 #ifdef CONFIG_CURSES
1601 display
= DT_CURSES
;
1603 fprintf(stderr
, "Curses support is disabled\n");
1606 } else if (strstart(p
, "none", &opts
)) {
1609 fprintf(stderr
, "Unknown display type: %s\n", p
);
1616 static int balloon_parse(const char *arg
)
1620 if (strcmp(arg
, "none") == 0) {
1624 if (!strncmp(arg
, "virtio", 6)) {
1625 if (arg
[6] == ',') {
1626 /* have params -> parse them */
1627 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1631 /* create empty opts */
1632 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1634 qemu_opt_set(opts
, "driver", "virtio-balloon");
1641 char *qemu_find_file(int type
, const char *name
)
1647 /* If name contains path separators then try it as a straight path. */
1648 if ((strchr(name
, '/') || strchr(name
, '\\'))
1649 && access(name
, R_OK
) == 0) {
1650 return qemu_strdup(name
);
1653 case QEMU_FILE_TYPE_BIOS
:
1656 case QEMU_FILE_TYPE_KEYMAP
:
1657 subdir
= "keymaps/";
1662 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1663 buf
= qemu_mallocz(len
);
1664 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1665 if (access(buf
, R_OK
)) {
1672 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1674 return qdev_device_help(opts
);
1677 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1681 dev
= qdev_device_add(opts
);
1687 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1689 CharDriverState
*chr
;
1691 chr
= qemu_chr_open_opts(opts
, NULL
);
1697 #ifdef CONFIG_VIRTFS
1698 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1701 ret
= qemu_fsdev_add(opts
);
1707 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1709 CharDriverState
*chr
;
1710 const char *chardev
;
1714 mode
= qemu_opt_get(opts
, "mode");
1718 if (strcmp(mode
, "readline") == 0) {
1719 flags
= MONITOR_USE_READLINE
;
1720 } else if (strcmp(mode
, "control") == 0) {
1721 flags
= MONITOR_USE_CONTROL
;
1723 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1727 if (qemu_opt_get_bool(opts
, "pretty", 0))
1728 flags
|= MONITOR_USE_PRETTY
;
1730 if (qemu_opt_get_bool(opts
, "default", 0))
1731 flags
|= MONITOR_IS_DEFAULT
;
1733 chardev
= qemu_opt_get(opts
, "chardev");
1734 chr
= qemu_chr_find(chardev
);
1736 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1740 monitor_init(chr
, flags
);
1744 static void monitor_parse(const char *optarg
, const char *mode
)
1746 static int monitor_device_index
= 0;
1752 if (strstart(optarg
, "chardev:", &p
)) {
1753 snprintf(label
, sizeof(label
), "%s", p
);
1755 snprintf(label
, sizeof(label
), "compat_monitor%d",
1756 monitor_device_index
);
1757 if (monitor_device_index
== 0) {
1760 opts
= qemu_chr_parse_compat(label
, optarg
);
1762 fprintf(stderr
, "parse error: %s\n", optarg
);
1767 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1769 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1772 qemu_opt_set(opts
, "mode", mode
);
1773 qemu_opt_set(opts
, "chardev", label
);
1775 qemu_opt_set(opts
, "default", "on");
1776 monitor_device_index
++;
1779 struct device_config
{
1781 DEV_USB
, /* -usbdevice */
1783 DEV_SERIAL
, /* -serial */
1784 DEV_PARALLEL
, /* -parallel */
1785 DEV_VIRTCON
, /* -virtioconsole */
1786 DEV_DEBUGCON
, /* -debugcon */
1788 const char *cmdline
;
1789 QTAILQ_ENTRY(device_config
) next
;
1791 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1793 static void add_device_config(int type
, const char *cmdline
)
1795 struct device_config
*conf
;
1797 conf
= qemu_mallocz(sizeof(*conf
));
1799 conf
->cmdline
= cmdline
;
1800 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1803 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1805 struct device_config
*conf
;
1808 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1809 if (conf
->type
!= type
)
1811 rc
= func(conf
->cmdline
);
1818 static int serial_parse(const char *devname
)
1820 static int index
= 0;
1823 if (strcmp(devname
, "none") == 0)
1825 if (index
== MAX_SERIAL_PORTS
) {
1826 fprintf(stderr
, "qemu: too many serial ports\n");
1829 snprintf(label
, sizeof(label
), "serial%d", index
);
1830 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1831 if (!serial_hds
[index
]) {
1832 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1833 devname
, strerror(errno
));
1840 static int parallel_parse(const char *devname
)
1842 static int index
= 0;
1845 if (strcmp(devname
, "none") == 0)
1847 if (index
== MAX_PARALLEL_PORTS
) {
1848 fprintf(stderr
, "qemu: too many parallel ports\n");
1851 snprintf(label
, sizeof(label
), "parallel%d", index
);
1852 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1853 if (!parallel_hds
[index
]) {
1854 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1855 devname
, strerror(errno
));
1862 static int virtcon_parse(const char *devname
)
1864 QemuOptsList
*device
= qemu_find_opts("device");
1865 static int index
= 0;
1867 QemuOpts
*bus_opts
, *dev_opts
;
1869 if (strcmp(devname
, "none") == 0)
1871 if (index
== MAX_VIRTIO_CONSOLES
) {
1872 fprintf(stderr
, "qemu: too many virtio consoles\n");
1876 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1877 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1879 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1880 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1882 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1883 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1884 if (!virtcon_hds
[index
]) {
1885 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1886 devname
, strerror(errno
));
1889 qemu_opt_set(dev_opts
, "chardev", label
);
1895 static int debugcon_parse(const char *devname
)
1899 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1902 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1904 fprintf(stderr
, "qemu: already have a debugcon device\n");
1907 qemu_opt_set(opts
, "driver", "isa-debugcon");
1908 qemu_opt_set(opts
, "chardev", "debugcon");
1912 static QEMUMachine
*machine_parse(const char *name
)
1914 QEMUMachine
*m
, *machine
= NULL
;
1917 machine
= find_machine(name
);
1922 printf("Supported machines are:\n");
1923 for (m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1925 printf("%-10s %s (alias of %s)\n", m
->alias
, m
->desc
, m
->name
);
1927 printf("%-10s %s%s\n", m
->name
, m
->desc
,
1928 m
->is_default
? " (default)" : "");
1930 exit(!name
|| *name
!= '?');
1933 static int tcg_init(void)
1939 const char *opt_name
;
1941 int (*available
)(void);
1945 { "tcg", "tcg", tcg_available
, tcg_init
, &tcg_allowed
},
1946 { "xen", "Xen", xen_available
, xen_init
, &xen_allowed
},
1947 { "kvm", "KVM", kvm_available
, kvm_init
, &kvm_allowed
},
1950 static int configure_accelerator(void)
1952 const char *p
= NULL
;
1955 bool accel_initalised
= 0;
1956 bool init_failed
= 0;
1958 QemuOptsList
*list
= qemu_find_opts("machine");
1959 if (!QTAILQ_EMPTY(&list
->head
)) {
1960 p
= qemu_opt_get(QTAILQ_FIRST(&list
->head
), "accel");
1964 /* Use the default "accelerator", tcg */
1968 while (!accel_initalised
&& *p
!= '\0') {
1972 p
= get_opt_name(buf
, sizeof (buf
), p
, ':');
1973 for (i
= 0; i
< ARRAY_SIZE(accel_list
); i
++) {
1974 if (strcmp(accel_list
[i
].opt_name
, buf
) == 0) {
1975 *(accel_list
[i
].allowed
) = 1;
1976 ret
= accel_list
[i
].init();
1979 if (!accel_list
[i
].available()) {
1980 printf("%s not supported for this target\n",
1981 accel_list
[i
].name
);
1983 fprintf(stderr
, "failed to initialize %s: %s\n",
1987 *(accel_list
[i
].allowed
) = 0;
1989 accel_initalised
= 1;
1994 if (i
== ARRAY_SIZE(accel_list
)) {
1995 fprintf(stderr
, "\"%s\" accelerator does not exist.\n", buf
);
1999 if (!accel_initalised
) {
2000 fprintf(stderr
, "No accelerator found!\n");
2005 fprintf(stderr
, "Back to %s accelerator.\n", accel_list
[i
].name
);
2008 return !accel_initalised
;
2011 void qemu_add_exit_notifier(Notifier
*notify
)
2013 notifier_list_add(&exit_notifiers
, notify
);
2016 void qemu_remove_exit_notifier(Notifier
*notify
)
2018 notifier_list_remove(&exit_notifiers
, notify
);
2021 static void qemu_run_exit_notifiers(void)
2023 notifier_list_notify(&exit_notifiers
, NULL
);
2026 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2028 notifier_list_add(&machine_init_done_notifiers
, notify
);
2031 static void qemu_run_machine_init_done_notifiers(void)
2033 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2036 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2037 const char **poptarg
, int *poptind
)
2039 const QEMUOption
*popt
;
2040 int optind
= *poptind
;
2041 char *r
= argv
[optind
];
2044 loc_set_cmdline(argv
, optind
, 1);
2046 /* Treat --foo the same as -foo. */
2049 popt
= qemu_options
;
2052 error_report("invalid option");
2055 if (!strcmp(popt
->name
, r
+ 1))
2059 if (popt
->flags
& HAS_ARG
) {
2060 if (optind
>= argc
) {
2061 error_report("requires an argument");
2064 optarg
= argv
[optind
++];
2065 loc_set_cmdline(argv
, optind
- 2, 2);
2076 int main(int argc
, char **argv
, char **envp
)
2078 const char *gdbstub_dev
= NULL
;
2080 int snapshot
, linux_boot
;
2081 const char *icount_option
= NULL
;
2082 const char *initrd_filename
;
2083 const char *kernel_filename
, *kernel_cmdline
;
2084 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
2086 DisplayChangeListener
*dcl
;
2087 int cyls
, heads
, secs
, translation
;
2088 QemuOpts
*hda_opts
= NULL
, *opts
;
2089 QemuOptsList
*olist
;
2092 const char *loadvm
= NULL
;
2093 QEMUMachine
*machine
;
2094 const char *cpu_model
;
2096 const char *pid_file
= NULL
;
2097 const char *incoming
= NULL
;
2099 int show_vnc_port
= 0;
2102 const char *trace_file
= NULL
;
2103 const char *log_mask
= NULL
;
2104 const char *log_file
= NULL
;
2106 atexit(qemu_run_exit_notifiers
);
2107 error_set_progname(argv
[0]);
2111 qemu_cache_utils_init(envp
);
2113 QLIST_INIT (&vm_change_state_head
);
2114 os_setup_early_signal_handling();
2116 module_call_init(MODULE_INIT_MACHINE
);
2117 machine
= find_default_machine();
2119 initrd_filename
= NULL
;
2122 kernel_filename
= NULL
;
2123 kernel_cmdline
= "";
2124 cyls
= heads
= secs
= 0;
2125 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2127 for (i
= 0; i
< MAX_NODES
; i
++) {
2129 node_cpumask
[i
] = 0;
2138 /* first pass of option parsing */
2140 while (optind
< argc
) {
2141 if (argv
[optind
][0] != '-') {
2146 const QEMUOption
*popt
;
2148 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2149 switch (popt
->index
) {
2150 case QEMU_OPTION_nodefconfig
:
2160 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2161 if (ret
< 0 && ret
!= -ENOENT
) {
2165 ret
= qemu_read_config_file(arch_config_name
);
2166 if (ret
< 0 && ret
!= -ENOENT
) {
2172 /* second pass of option parsing */
2177 if (argv
[optind
][0] != '-') {
2178 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2180 const QEMUOption
*popt
;
2182 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2183 if (!(popt
->arch_mask
& arch_type
)) {
2184 printf("Option %s not supported for this target\n", popt
->name
);
2187 switch(popt
->index
) {
2189 machine
= machine_parse(optarg
);
2191 case QEMU_OPTION_cpu
:
2192 /* hw initialization will check this */
2193 if (*optarg
== '?') {
2194 list_cpus(stdout
, &fprintf
, optarg
);
2200 case QEMU_OPTION_initrd
:
2201 initrd_filename
= optarg
;
2203 case QEMU_OPTION_hda
:
2207 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
2209 snprintf(buf
, sizeof(buf
),
2210 "%s,cyls=%d,heads=%d,secs=%d%s",
2211 HD_OPTS
, cyls
, heads
, secs
,
2212 translation
== BIOS_ATA_TRANSLATION_LBA
?
2214 translation
== BIOS_ATA_TRANSLATION_NONE
?
2215 ",trans=none" : "");
2216 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
2219 case QEMU_OPTION_hdb
:
2220 case QEMU_OPTION_hdc
:
2221 case QEMU_OPTION_hdd
:
2222 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2225 case QEMU_OPTION_drive
:
2226 if (drive_def(optarg
) == NULL
) {
2230 case QEMU_OPTION_set
:
2231 if (qemu_set_option(optarg
) != 0)
2234 case QEMU_OPTION_global
:
2235 if (qemu_global_option(optarg
) != 0)
2238 case QEMU_OPTION_mtdblock
:
2239 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2241 case QEMU_OPTION_sd
:
2242 drive_add(IF_SD
, 0, optarg
, SD_OPTS
);
2244 case QEMU_OPTION_pflash
:
2245 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2247 case QEMU_OPTION_snapshot
:
2250 case QEMU_OPTION_hdachs
:
2254 cyls
= strtol(p
, (char **)&p
, 0);
2255 if (cyls
< 1 || cyls
> 16383)
2260 heads
= strtol(p
, (char **)&p
, 0);
2261 if (heads
< 1 || heads
> 16)
2266 secs
= strtol(p
, (char **)&p
, 0);
2267 if (secs
< 1 || secs
> 63)
2271 if (!strcmp(p
, "none"))
2272 translation
= BIOS_ATA_TRANSLATION_NONE
;
2273 else if (!strcmp(p
, "lba"))
2274 translation
= BIOS_ATA_TRANSLATION_LBA
;
2275 else if (!strcmp(p
, "auto"))
2276 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2279 } else if (*p
!= '\0') {
2281 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2284 if (hda_opts
!= NULL
) {
2286 snprintf(num
, sizeof(num
), "%d", cyls
);
2287 qemu_opt_set(hda_opts
, "cyls", num
);
2288 snprintf(num
, sizeof(num
), "%d", heads
);
2289 qemu_opt_set(hda_opts
, "heads", num
);
2290 snprintf(num
, sizeof(num
), "%d", secs
);
2291 qemu_opt_set(hda_opts
, "secs", num
);
2292 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2293 qemu_opt_set(hda_opts
, "trans", "lba");
2294 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2295 qemu_opt_set(hda_opts
, "trans", "none");
2299 case QEMU_OPTION_numa
:
2300 if (nb_numa_nodes
>= MAX_NODES
) {
2301 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2306 case QEMU_OPTION_display
:
2307 display_type
= select_display(optarg
);
2309 case QEMU_OPTION_nographic
:
2310 display_type
= DT_NOGRAPHIC
;
2312 case QEMU_OPTION_curses
:
2313 #ifdef CONFIG_CURSES
2314 display_type
= DT_CURSES
;
2316 fprintf(stderr
, "Curses support is disabled\n");
2320 case QEMU_OPTION_portrait
:
2321 graphic_rotate
= 90;
2323 case QEMU_OPTION_rotate
:
2324 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2325 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2326 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2328 "qemu: only 90, 180, 270 deg rotation is available\n");
2332 case QEMU_OPTION_kernel
:
2333 kernel_filename
= optarg
;
2335 case QEMU_OPTION_append
:
2336 kernel_cmdline
= optarg
;
2338 case QEMU_OPTION_cdrom
:
2339 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2341 case QEMU_OPTION_boot
:
2343 static const char * const params
[] = {
2344 "order", "once", "menu",
2345 "splash", "splash-time", NULL
2347 char buf
[sizeof(boot_devices
)];
2348 char *standard_boot_devices
;
2351 if (!strchr(optarg
, '=')) {
2353 pstrcpy(buf
, sizeof(buf
), optarg
);
2354 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2356 "qemu: unknown boot parameter '%s' in '%s'\n",
2362 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2363 validate_bootdevices(buf
);
2364 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2367 if (get_param_value(buf
, sizeof(buf
),
2369 validate_bootdevices(buf
);
2370 standard_boot_devices
= qemu_strdup(boot_devices
);
2371 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2372 qemu_register_reset(restore_boot_devices
,
2373 standard_boot_devices
);
2375 if (get_param_value(buf
, sizeof(buf
),
2377 if (!strcmp(buf
, "on")) {
2379 } else if (!strcmp(buf
, "off")) {
2383 "qemu: invalid option value '%s'\n",
2388 qemu_opts_parse(qemu_find_opts("boot-opts"),
2393 case QEMU_OPTION_fda
:
2394 case QEMU_OPTION_fdb
:
2395 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2398 case QEMU_OPTION_no_fd_bootchk
:
2401 case QEMU_OPTION_netdev
:
2402 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2406 case QEMU_OPTION_net
:
2407 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2412 case QEMU_OPTION_tftp
:
2413 legacy_tftp_prefix
= optarg
;
2415 case QEMU_OPTION_bootp
:
2416 legacy_bootp_filename
= optarg
;
2418 case QEMU_OPTION_redir
:
2419 if (net_slirp_redir(optarg
) < 0)
2423 case QEMU_OPTION_bt
:
2424 add_device_config(DEV_BT
, optarg
);
2426 case QEMU_OPTION_audio_help
:
2427 if (!(audio_available())) {
2428 printf("Option %s not supported for this target\n", popt
->name
);
2434 case QEMU_OPTION_soundhw
:
2435 if (!(audio_available())) {
2436 printf("Option %s not supported for this target\n", popt
->name
);
2439 select_soundhw (optarg
);
2444 case QEMU_OPTION_version
:
2448 case QEMU_OPTION_m
: {
2451 value
= strtosz(optarg
, NULL
);
2453 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2457 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2458 fprintf(stderr
, "qemu: ram size too large\n");
2464 case QEMU_OPTION_mempath
:
2468 case QEMU_OPTION_mem_prealloc
:
2479 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2481 case QEMU_OPTION_gdb
:
2482 gdbstub_dev
= optarg
;
2487 case QEMU_OPTION_bios
:
2490 case QEMU_OPTION_singlestep
:
2497 keyboard_layout
= optarg
;
2499 case QEMU_OPTION_localtime
:
2502 case QEMU_OPTION_vga
:
2503 select_vgahw (optarg
);
2510 w
= strtol(p
, (char **)&p
, 10);
2513 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2519 h
= strtol(p
, (char **)&p
, 10);
2524 depth
= strtol(p
, (char **)&p
, 10);
2525 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2526 depth
!= 24 && depth
!= 32)
2528 } else if (*p
== '\0') {
2529 depth
= graphic_depth
;
2536 graphic_depth
= depth
;
2539 case QEMU_OPTION_echr
:
2542 term_escape_char
= strtol(optarg
, &r
, 0);
2544 printf("Bad argument to echr\n");
2547 case QEMU_OPTION_monitor
:
2548 monitor_parse(optarg
, "readline");
2549 default_monitor
= 0;
2551 case QEMU_OPTION_qmp
:
2552 monitor_parse(optarg
, "control");
2553 default_monitor
= 0;
2555 case QEMU_OPTION_mon
:
2556 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2560 default_monitor
= 0;
2562 case QEMU_OPTION_chardev
:
2563 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2568 case QEMU_OPTION_fsdev
:
2569 olist
= qemu_find_opts("fsdev");
2571 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2574 opts
= qemu_opts_parse(olist
, optarg
, 1);
2576 fprintf(stderr
, "parse error: %s\n", optarg
);
2580 case QEMU_OPTION_virtfs
: {
2584 olist
= qemu_find_opts("virtfs");
2586 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2589 opts
= qemu_opts_parse(olist
, optarg
, 1);
2591 fprintf(stderr
, "parse error: %s\n", optarg
);
2595 if (qemu_opt_get(opts
, "fstype") == NULL
||
2596 qemu_opt_get(opts
, "mount_tag") == NULL
||
2597 qemu_opt_get(opts
, "path") == NULL
||
2598 qemu_opt_get(opts
, "security_model") == NULL
) {
2599 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2600 "security_model=[mapped|passthrough|none],"
2601 "mount_tag=tag.\n");
2605 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
2606 qemu_opt_get(opts
, "mount_tag"), 1);
2608 fprintf(stderr
, "duplicate fsdev id: %s\n",
2609 qemu_opt_get(opts
, "mount_tag"));
2612 qemu_opt_set(fsdev
, "fstype", qemu_opt_get(opts
, "fstype"));
2613 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"));
2614 qemu_opt_set(fsdev
, "security_model",
2615 qemu_opt_get(opts
, "security_model"));
2617 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
2618 qemu_opt_set(device
, "driver", "virtio-9p-pci");
2619 qemu_opt_set(device
, "fsdev",
2620 qemu_opt_get(opts
, "mount_tag"));
2621 qemu_opt_set(device
, "mount_tag",
2622 qemu_opt_get(opts
, "mount_tag"));
2625 case QEMU_OPTION_serial
:
2626 add_device_config(DEV_SERIAL
, optarg
);
2628 if (strncmp(optarg
, "mon:", 4) == 0) {
2629 default_monitor
= 0;
2632 case QEMU_OPTION_watchdog
:
2635 "qemu: only one watchdog option may be given\n");
2640 case QEMU_OPTION_watchdog_action
:
2641 if (select_watchdog_action(optarg
) == -1) {
2642 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2646 case QEMU_OPTION_virtiocon
:
2647 add_device_config(DEV_VIRTCON
, optarg
);
2648 default_virtcon
= 0;
2649 if (strncmp(optarg
, "mon:", 4) == 0) {
2650 default_monitor
= 0;
2653 case QEMU_OPTION_parallel
:
2654 add_device_config(DEV_PARALLEL
, optarg
);
2655 default_parallel
= 0;
2656 if (strncmp(optarg
, "mon:", 4) == 0) {
2657 default_monitor
= 0;
2660 case QEMU_OPTION_debugcon
:
2661 add_device_config(DEV_DEBUGCON
, optarg
);
2663 case QEMU_OPTION_loadvm
:
2666 case QEMU_OPTION_full_screen
:
2670 case QEMU_OPTION_no_frame
:
2673 case QEMU_OPTION_alt_grab
:
2676 case QEMU_OPTION_ctrl_grab
:
2679 case QEMU_OPTION_no_quit
:
2682 case QEMU_OPTION_sdl
:
2683 display_type
= DT_SDL
;
2686 case QEMU_OPTION_no_frame
:
2687 case QEMU_OPTION_alt_grab
:
2688 case QEMU_OPTION_ctrl_grab
:
2689 case QEMU_OPTION_no_quit
:
2690 case QEMU_OPTION_sdl
:
2691 fprintf(stderr
, "SDL support is disabled\n");
2694 case QEMU_OPTION_pidfile
:
2697 case QEMU_OPTION_win2k_hack
:
2698 win2k_install_hack
= 1;
2700 case QEMU_OPTION_rtc_td_hack
:
2703 case QEMU_OPTION_acpitable
:
2704 do_acpitable_option(optarg
);
2706 case QEMU_OPTION_smbios
:
2707 do_smbios_option(optarg
);
2709 case QEMU_OPTION_enable_kvm
:
2710 olist
= qemu_find_opts("machine");
2711 qemu_opts_reset(olist
);
2712 qemu_opts_parse(olist
, "accel=kvm", 0);
2714 case QEMU_OPTION_machine
:
2715 olist
= qemu_find_opts("machine");
2716 qemu_opts_reset(olist
);
2717 opts
= qemu_opts_parse(olist
, optarg
, 1);
2719 fprintf(stderr
, "parse error: %s\n", optarg
);
2722 optarg
= qemu_opt_get(opts
, "type");
2724 machine
= machine_parse(optarg
);
2727 case QEMU_OPTION_usb
:
2730 case QEMU_OPTION_usbdevice
:
2732 add_device_config(DEV_USB
, optarg
);
2734 case QEMU_OPTION_device
:
2735 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2739 case QEMU_OPTION_smp
:
2742 fprintf(stderr
, "Invalid number of CPUs\n");
2745 if (max_cpus
< smp_cpus
) {
2746 fprintf(stderr
, "maxcpus must be equal to or greater than "
2750 if (max_cpus
> 255) {
2751 fprintf(stderr
, "Unsupported number of maxcpus\n");
2755 case QEMU_OPTION_vnc
:
2758 vnc_display
= optarg
;
2760 fprintf(stderr
, "VNC support is disabled\n");
2764 case QEMU_OPTION_no_acpi
:
2767 case QEMU_OPTION_no_hpet
:
2770 case QEMU_OPTION_balloon
:
2771 if (balloon_parse(optarg
) < 0) {
2772 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2776 case QEMU_OPTION_no_reboot
:
2779 case QEMU_OPTION_no_shutdown
:
2782 case QEMU_OPTION_show_cursor
:
2785 case QEMU_OPTION_uuid
:
2786 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2787 fprintf(stderr
, "Fail to parse UUID string."
2788 " Wrong format.\n");
2792 case QEMU_OPTION_option_rom
:
2793 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2794 fprintf(stderr
, "Too many option ROMs\n");
2797 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
2798 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
2799 option_rom
[nb_option_roms
].bootindex
=
2800 qemu_opt_get_number(opts
, "bootindex", -1);
2801 if (!option_rom
[nb_option_roms
].name
) {
2802 fprintf(stderr
, "Option ROM file is not specified\n");
2807 case QEMU_OPTION_semihosting
:
2808 semihosting_enabled
= 1;
2810 case QEMU_OPTION_name
:
2811 qemu_name
= qemu_strdup(optarg
);
2813 char *p
= strchr(qemu_name
, ',');
2816 if (strncmp(p
, "process=", 8)) {
2817 fprintf(stderr
, "Unknown subargument %s to -name\n", p
);
2821 os_set_proc_name(p
);
2825 case QEMU_OPTION_prom_env
:
2826 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2827 fprintf(stderr
, "Too many prom variables\n");
2830 prom_envs
[nb_prom_envs
] = optarg
;
2833 case QEMU_OPTION_old_param
:
2836 case QEMU_OPTION_clock
:
2837 configure_alarms(optarg
);
2839 case QEMU_OPTION_startdate
:
2840 configure_rtc_date_offset(optarg
, 1);
2842 case QEMU_OPTION_rtc
:
2843 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2847 configure_rtc(opts
);
2849 case QEMU_OPTION_tb_size
:
2850 tb_size
= strtol(optarg
, NULL
, 0);
2854 case QEMU_OPTION_icount
:
2855 icount_option
= optarg
;
2857 case QEMU_OPTION_incoming
:
2859 incoming_expected
= true;
2861 case QEMU_OPTION_nodefaults
:
2863 default_parallel
= 0;
2864 default_virtcon
= 0;
2865 default_monitor
= 0;
2872 case QEMU_OPTION_xen_domid
:
2873 if (!(xen_available())) {
2874 printf("Option %s not supported for this target\n", popt
->name
);
2877 xen_domid
= atoi(optarg
);
2879 case QEMU_OPTION_xen_create
:
2880 if (!(xen_available())) {
2881 printf("Option %s not supported for this target\n", popt
->name
);
2884 xen_mode
= XEN_CREATE
;
2886 case QEMU_OPTION_xen_attach
:
2887 if (!(xen_available())) {
2888 printf("Option %s not supported for this target\n", popt
->name
);
2891 xen_mode
= XEN_ATTACH
;
2893 #ifdef CONFIG_SIMPLE_TRACE
2894 case QEMU_OPTION_trace
:
2895 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2897 trace_file
= qemu_opt_get(opts
, "file");
2901 case QEMU_OPTION_readconfig
:
2903 int ret
= qemu_read_config_file(optarg
);
2905 fprintf(stderr
, "read config %s: %s\n", optarg
,
2911 case QEMU_OPTION_spice
:
2912 olist
= qemu_find_opts("spice");
2914 fprintf(stderr
, "spice is not supported by this qemu build.\n");
2917 opts
= qemu_opts_parse(olist
, optarg
, 0);
2919 fprintf(stderr
, "parse error: %s\n", optarg
);
2923 case QEMU_OPTION_writeconfig
:
2926 if (strcmp(optarg
, "-") == 0) {
2929 fp
= fopen(optarg
, "w");
2931 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2935 qemu_config_write(fp
);
2940 os_parse_cmd_args(popt
->index
, optarg
);
2946 /* Open the logfile at this point, if necessary. We can't open the logfile
2947 * when encountering either of the logging options (-d or -D) because the
2948 * other one may be encountered later on the command line, changing the
2949 * location or level of logging.
2953 set_cpu_log_filename(log_file
);
2955 set_cpu_log(log_mask
);
2958 if (!st_init(trace_file
)) {
2959 fprintf(stderr
, "warning: unable to initialize simple trace backend\n");
2962 /* If no data_dir is specified then try to find it relative to the
2965 data_dir
= os_find_datadir(argv
[0]);
2967 /* If all else fails use the install patch specified when building. */
2969 data_dir
= CONFIG_QEMU_DATADIR
;
2973 * Default to max_cpus = smp_cpus, in case the user doesn't
2974 * specify a max_cpus value.
2977 max_cpus
= smp_cpus
;
2979 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2980 if (smp_cpus
> machine
->max_cpus
) {
2981 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2982 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2988 * Get the default machine options from the machine if it is not already
2989 * specified either by the configuration file or by the command line.
2991 if (machine
->default_machine_opts
) {
2992 QemuOptsList
*list
= qemu_find_opts("machine");
2993 const char *p
= NULL
;
2995 if (!QTAILQ_EMPTY(&list
->head
)) {
2996 p
= qemu_opt_get(QTAILQ_FIRST(&list
->head
), "accel");
2999 qemu_opts_reset(list
);
3000 opts
= qemu_opts_parse(list
, machine
->default_machine_opts
, 0);
3002 fprintf(stderr
, "parse error for machine %s: %s\n",
3003 machine
->name
, machine
->default_machine_opts
);
3009 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
3010 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
3012 if (machine
->no_serial
) {
3015 if (machine
->no_parallel
) {
3016 default_parallel
= 0;
3018 if (!machine
->use_virtcon
) {
3019 default_virtcon
= 0;
3021 if (machine
->no_vga
) {
3024 if (machine
->no_floppy
) {
3027 if (machine
->no_cdrom
) {
3030 if (machine
->no_sdcard
) {
3034 if (display_type
== DT_NOGRAPHIC
) {
3035 if (default_parallel
)
3036 add_device_config(DEV_PARALLEL
, "null");
3037 if (default_serial
&& default_monitor
) {
3038 add_device_config(DEV_SERIAL
, "mon:stdio");
3039 } else if (default_virtcon
&& default_monitor
) {
3040 add_device_config(DEV_VIRTCON
, "mon:stdio");
3043 add_device_config(DEV_SERIAL
, "stdio");
3044 if (default_virtcon
)
3045 add_device_config(DEV_VIRTCON
, "stdio");
3046 if (default_monitor
)
3047 monitor_parse("stdio", "readline");
3051 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
3052 if (default_parallel
)
3053 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
3054 if (default_monitor
)
3055 monitor_parse("vc:80Cx24C", "readline");
3056 if (default_virtcon
)
3057 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
3060 vga_interface_type
= VGA_CIRRUS
;
3064 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
3066 #ifdef CONFIG_VIRTFS
3067 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
3074 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
3079 configure_accelerator();
3081 if (qemu_init_main_loop()) {
3082 fprintf(stderr
, "qemu_init_main_loop failed\n");
3085 linux_boot
= (kernel_filename
!= NULL
);
3087 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
3088 fprintf(stderr
, "-append only allowed with -kernel option\n");
3092 if (!linux_boot
&& initrd_filename
!= NULL
) {
3093 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
3097 os_set_line_buffering();
3099 if (init_timer_alarm() < 0) {
3100 fprintf(stderr
, "could not initialize alarm timer\n");
3103 configure_icount(icount_option
);
3105 if (net_init_clients() < 0) {
3109 /* init the bluetooth world */
3110 if (foreach_device_config(DEV_BT
, bt_parse
))
3113 /* init the memory */
3114 if (ram_size
== 0) {
3115 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
3118 if (!xen_enabled()) {
3119 /* On 32-bit hosts, QEMU is limited by virtual address space */
3120 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
3121 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
3126 /* init the dynamic translator */
3127 cpu_exec_init_all(tb_size
* 1024 * 1024);
3129 bdrv_init_with_whitelist();
3133 /* open the virtual block devices */
3135 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
3136 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
3139 default_drive(default_cdrom
, snapshot
, machine
->use_scsi
,
3140 IF_DEFAULT
, 2, CDROM_OPTS
);
3141 default_drive(default_floppy
, snapshot
, machine
->use_scsi
,
3142 IF_FLOPPY
, 0, FD_OPTS
);
3143 default_drive(default_sdcard
, snapshot
, machine
->use_scsi
,
3146 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
3149 if (nb_numa_nodes
> 0) {
3152 if (nb_numa_nodes
> MAX_NODES
) {
3153 nb_numa_nodes
= MAX_NODES
;
3156 /* If no memory size if given for any node, assume the default case
3157 * and distribute the available memory equally across all nodes
3159 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3160 if (node_mem
[i
] != 0)
3163 if (i
== nb_numa_nodes
) {
3164 uint64_t usedmem
= 0;
3166 /* On Linux, the each node's border has to be 8MB aligned,
3167 * the final node gets the rest.
3169 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
3170 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
3171 usedmem
+= node_mem
[i
];
3173 node_mem
[i
] = ram_size
- usedmem
;
3176 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3177 if (node_cpumask
[i
] != 0)
3180 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3181 * must cope with this anyway, because there are BIOSes out there in
3182 * real machines which also use this scheme.
3184 if (i
== nb_numa_nodes
) {
3185 for (i
= 0; i
< smp_cpus
; i
++) {
3186 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
3191 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
3195 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
3197 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
3199 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
3201 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
3204 module_call_init(MODULE_INIT_DEVICE
);
3206 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
3210 i
= select_watchdog(watchdog
);
3212 exit (i
== 1 ? 1 : 0);
3215 if (machine
->compat_props
) {
3216 qdev_prop_register_global_list(machine
->compat_props
);
3220 machine
->init(ram_size
, boot_devices
,
3221 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
3223 cpu_synchronize_all_post_init();
3227 current_machine
= machine
;
3229 /* init USB devices */
3231 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
3235 /* init generic devices */
3236 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3239 net_check_clients();
3241 /* just use the first displaystate for the moment */
3242 ds
= get_displaystate();
3246 if (display_type
== DT_DEFAULT
&& !display_remote
) {
3247 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3248 display_type
= DT_SDL
;
3249 #elif defined(CONFIG_VNC)
3250 vnc_display
= "localhost:0,to=99";
3253 display_type
= DT_NONE
;
3258 /* init local displays */
3259 switch (display_type
) {
3262 #if defined(CONFIG_CURSES)
3264 curses_display_init(ds
, full_screen
);
3267 #if defined(CONFIG_SDL)
3269 sdl_display_init(ds
, full_screen
, no_frame
);
3271 #elif defined(CONFIG_COCOA)
3273 cocoa_display_init(ds
, full_screen
);
3280 /* must be after terminal init, SDL library changes signal handlers */
3281 os_setup_signal_handling();
3284 /* init remote displays */
3286 vnc_display_init(ds
);
3287 if (vnc_display_open(ds
, vnc_display
) < 0)
3290 if (show_vnc_port
) {
3291 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3296 if (using_spice
&& !qxl_enabled
) {
3297 qemu_spice_display_init(ds
);
3303 dcl
= ds
->listeners
;
3304 while (dcl
!= NULL
) {
3305 if (dcl
->dpy_refresh
!= NULL
) {
3306 ds
->gui_timer
= qemu_new_timer_ms(rt_clock
, gui_update
, ds
);
3307 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock_ms(rt_clock
));
3312 if (ds
->gui_timer
== NULL
) {
3313 nographic_timer
= qemu_new_timer_ms(rt_clock
, nographic_update
, NULL
);
3314 qemu_mod_timer(nographic_timer
, qemu_get_clock_ms(rt_clock
));
3316 text_consoles_set_display(ds
);
3318 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3319 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3324 qdev_machine_creation_done();
3326 if (rom_load_all() != 0) {
3327 fprintf(stderr
, "rom loading failed\n");
3331 /* TODO: once all bus devices are qdevified, this should be done
3332 * when bus is created by qdev.c */
3333 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
3334 qemu_run_machine_init_done_notifiers();
3336 qemu_system_reset(VMRESET_SILENT
);
3338 if (load_vmstate(loadvm
) < 0) {
3344 int ret
= qemu_start_incoming_migration(incoming
);
3346 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3350 } else if (autostart
) {