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
];
232 typedef struct FWBootEntry FWBootEntry
;
235 QTAILQ_ENTRY(FWBootEntry
) link
;
241 QTAILQ_HEAD(, FWBootEntry
) fw_boot_order
= QTAILQ_HEAD_INITIALIZER(fw_boot_order
);
244 uint64_t node_mem
[MAX_NODES
];
245 uint64_t node_cpumask
[MAX_NODES
];
247 static QEMUTimer
*nographic_timer
;
249 uint8_t qemu_uuid
[16];
251 static QEMUBootSetHandler
*boot_set_handler
;
252 static void *boot_set_opaque
;
254 static NotifierList exit_notifiers
=
255 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
257 static NotifierList machine_init_done_notifiers
=
258 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
260 static int tcg_allowed
= 1;
264 enum xen_mode xen_mode
= XEN_EMULATE
;
266 static int default_serial
= 1;
267 static int default_parallel
= 1;
268 static int default_virtcon
= 1;
269 static int default_monitor
= 1;
270 static int default_vga
= 1;
271 static int default_floppy
= 1;
272 static int default_cdrom
= 1;
273 static int default_sdcard
= 1;
279 { .driver
= "isa-serial", .flag
= &default_serial
},
280 { .driver
= "isa-parallel", .flag
= &default_parallel
},
281 { .driver
= "isa-fdc", .flag
= &default_floppy
},
282 { .driver
= "ide-cd", .flag
= &default_cdrom
},
283 { .driver
= "ide-hd", .flag
= &default_cdrom
},
284 { .driver
= "ide-drive", .flag
= &default_cdrom
},
285 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
286 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
287 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
288 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
289 { .driver
= "VGA", .flag
= &default_vga
},
290 { .driver
= "cirrus-vga", .flag
= &default_vga
},
291 { .driver
= "vmware-svga", .flag
= &default_vga
},
292 { .driver
= "isa-vga", .flag
= &default_vga
},
295 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
297 const char *driver
= qemu_opt_get(opts
, "driver");
302 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
303 if (strcmp(default_list
[i
].driver
, driver
) != 0)
305 *(default_list
[i
].flag
) = 0;
310 /***********************************************************/
311 /* real time host monotonic timer */
313 /***********************************************************/
314 /* host time/date access */
315 void qemu_get_timedate(struct tm
*tm
, int offset
)
322 if (rtc_date_offset
== -1) {
326 ret
= localtime(&ti
);
328 ti
-= rtc_date_offset
;
332 memcpy(tm
, ret
, sizeof(struct tm
));
335 int qemu_timedate_diff(struct tm
*tm
)
339 if (rtc_date_offset
== -1)
341 seconds
= mktimegm(tm
);
343 seconds
= mktime(tm
);
345 seconds
= mktimegm(tm
) + rtc_date_offset
;
347 return seconds
- time(NULL
);
350 void rtc_change_mon_event(struct tm
*tm
)
354 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
355 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
356 qobject_decref(data
);
359 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
361 time_t rtc_start_date
;
364 if (!strcmp(startdate
, "now") && legacy
) {
365 rtc_date_offset
= -1;
367 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
375 } else if (sscanf(startdate
, "%d-%d-%d",
387 rtc_start_date
= mktimegm(&tm
);
388 if (rtc_start_date
== -1) {
390 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
391 "'2006-06-17T16:01:21' or '2006-06-17'\n");
394 rtc_date_offset
= time(NULL
) - rtc_start_date
;
398 static void configure_rtc(QemuOpts
*opts
)
402 value
= qemu_opt_get(opts
, "base");
404 if (!strcmp(value
, "utc")) {
406 } else if (!strcmp(value
, "localtime")) {
409 configure_rtc_date_offset(value
, 0);
412 value
= qemu_opt_get(opts
, "clock");
414 if (!strcmp(value
, "host")) {
415 rtc_clock
= host_clock
;
416 } else if (!strcmp(value
, "vm")) {
417 rtc_clock
= vm_clock
;
419 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
423 value
= qemu_opt_get(opts
, "driftfix");
425 if (!strcmp(value
, "slew")) {
427 } else if (!strcmp(value
, "none")) {
430 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
436 /***********************************************************/
437 /* Bluetooth support */
440 static struct HCIInfo
*hci_table
[MAX_NICS
];
442 static struct bt_vlan_s
{
443 struct bt_scatternet_s net
;
445 struct bt_vlan_s
*next
;
448 /* find or alloc a new bluetooth "VLAN" */
449 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
451 struct bt_vlan_s
**pvlan
, *vlan
;
452 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
456 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
458 pvlan
= &first_bt_vlan
;
459 while (*pvlan
!= NULL
)
460 pvlan
= &(*pvlan
)->next
;
465 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
469 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
474 static struct HCIInfo null_hci
= {
475 .cmd_send
= null_hci_send
,
476 .sco_send
= null_hci_send
,
477 .acl_send
= null_hci_send
,
478 .bdaddr_set
= null_hci_addr_set
,
481 struct HCIInfo
*qemu_next_hci(void)
483 if (cur_hci
== nb_hcis
)
486 return hci_table
[cur_hci
++];
489 static struct HCIInfo
*hci_init(const char *str
)
492 struct bt_scatternet_s
*vlan
= 0;
494 if (!strcmp(str
, "null"))
497 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
499 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
500 else if (!strncmp(str
, "hci", 3)) {
503 if (!strncmp(str
+ 3, ",vlan=", 6)) {
504 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
509 vlan
= qemu_find_bt_vlan(0);
511 return bt_new_hci(vlan
);
514 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
519 static int bt_hci_parse(const char *str
)
524 if (nb_hcis
>= MAX_NICS
) {
525 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
538 bdaddr
.b
[5] = 0x56 + nb_hcis
;
539 hci
->bdaddr_set(hci
, bdaddr
.b
);
541 hci_table
[nb_hcis
++] = hci
;
546 static void bt_vhci_add(int vlan_id
)
548 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
551 fprintf(stderr
, "qemu: warning: adding a VHCI to "
552 "an empty scatternet %i\n", vlan_id
);
554 bt_vhci_init(bt_new_hci(vlan
));
557 static struct bt_device_s
*bt_device_add(const char *opt
)
559 struct bt_scatternet_s
*vlan
;
561 char *endp
= strstr(opt
, ",vlan=");
562 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
565 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
568 vlan_id
= strtol(endp
+ 6, &endp
, 0);
570 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
575 vlan
= qemu_find_bt_vlan(vlan_id
);
578 fprintf(stderr
, "qemu: warning: adding a slave device to "
579 "an empty scatternet %i\n", vlan_id
);
581 if (!strcmp(devname
, "keyboard"))
582 return bt_keyboard_init(vlan
);
584 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
588 static int bt_parse(const char *opt
)
590 const char *endp
, *p
;
593 if (strstart(opt
, "hci", &endp
)) {
594 if (!*endp
|| *endp
== ',') {
596 if (!strstart(endp
, ",vlan=", 0))
599 return bt_hci_parse(opt
);
601 } else if (strstart(opt
, "vhci", &endp
)) {
602 if (!*endp
|| *endp
== ',') {
604 if (strstart(endp
, ",vlan=", &p
)) {
605 vlan
= strtol(p
, (char **) &endp
, 0);
607 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
611 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
620 } else if (strstart(opt
, "device:", &endp
))
621 return !bt_device_add(endp
);
623 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
627 /***********************************************************/
628 /* QEMU Block devices */
630 #define HD_OPTS "media=disk"
631 #define CDROM_OPTS "media=cdrom"
633 #define PFLASH_OPTS ""
637 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
639 int *use_scsi
= opaque
;
641 return drive_init(opts
, *use_scsi
) == NULL
;
644 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
646 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
647 qemu_opt_set(opts
, "snapshot", "on");
652 static void default_drive(int enable
, int snapshot
, int use_scsi
,
653 BlockInterfaceType type
, int index
,
658 if (type
== IF_DEFAULT
) {
659 type
= use_scsi
? IF_SCSI
: IF_IDE
;
662 if (!enable
|| drive_get_by_index(type
, index
)) {
666 opts
= drive_add(type
, index
, NULL
, optstr
);
668 drive_enable_snapshot(opts
, NULL
);
670 if (!drive_init(opts
, use_scsi
)) {
675 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
677 boot_set_handler
= func
;
678 boot_set_opaque
= opaque
;
681 int qemu_boot_set(const char *boot_devices
)
683 if (!boot_set_handler
) {
686 return boot_set_handler(boot_set_opaque
, boot_devices
);
689 static void validate_bootdevices(char *devices
)
691 /* We just do some generic consistency checks */
695 for (p
= devices
; *p
!= '\0'; p
++) {
696 /* Allowed boot devices are:
697 * a-b: floppy disk drives
698 * c-f: IDE disk drives
699 * g-m: machine implementation dependant drives
700 * n-p: network devices
701 * It's up to each machine implementation to check if the given boot
702 * devices match the actual hardware implementation and firmware
705 if (*p
< 'a' || *p
> 'p') {
706 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
709 if (bitmap
& (1 << (*p
- 'a'))) {
710 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
713 bitmap
|= 1 << (*p
- 'a');
717 static void restore_boot_devices(void *opaque
)
719 char *standard_boot_devices
= opaque
;
720 static int first
= 1;
722 /* Restore boot order and remove ourselves after the first boot */
728 qemu_boot_set(standard_boot_devices
);
730 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
731 qemu_free(standard_boot_devices
);
734 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
737 FWBootEntry
*node
, *i
;
743 assert(dev
!= NULL
|| suffix
!= NULL
);
745 node
= qemu_mallocz(sizeof(FWBootEntry
));
746 node
->bootindex
= bootindex
;
747 node
->suffix
= suffix
? qemu_strdup(suffix
) : NULL
;
750 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
751 if (i
->bootindex
== bootindex
) {
752 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
754 } else if (i
->bootindex
< bootindex
) {
757 QTAILQ_INSERT_BEFORE(i
, node
, link
);
760 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
764 * This function returns null terminated string that consist of new line
765 * separated device paths.
767 * memory pointed by "size" is assigned total length of the array in bytes
770 char *get_boot_devices_list(uint32_t *size
)
776 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
777 char *devpath
= NULL
, *bootpath
;
781 devpath
= qdev_get_fw_dev_path(i
->dev
);
785 if (i
->suffix
&& devpath
) {
786 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
788 bootpath
= qemu_malloc(bootpathlen
);
789 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
791 } else if (devpath
) {
794 bootpath
= qemu_strdup(i
->suffix
);
799 list
[total
-1] = '\n';
801 len
= strlen(bootpath
) + 1;
802 list
= qemu_realloc(list
, total
+ len
);
803 memcpy(&list
[total
], bootpath
, len
);
813 static void numa_add(const char *optarg
)
817 unsigned long long value
, endvalue
;
820 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
821 if (!strcmp(option
, "node")) {
822 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
823 nodenr
= nb_numa_nodes
;
825 nodenr
= strtoull(option
, NULL
, 10);
828 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
829 node_mem
[nodenr
] = 0;
832 sval
= strtosz(option
, NULL
);
834 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
837 node_mem
[nodenr
] = sval
;
839 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
840 node_cpumask
[nodenr
] = 0;
842 value
= strtoull(option
, &endptr
, 10);
845 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
847 if (*endptr
== '-') {
848 endvalue
= strtoull(endptr
+1, &endptr
, 10);
849 if (endvalue
>= 63) {
852 "only 63 CPUs in NUMA mode supported.\n");
854 value
= (2ULL << endvalue
) - (1ULL << value
);
856 value
= 1ULL << value
;
859 node_cpumask
[nodenr
] = value
;
866 static void smp_parse(const char *optarg
)
868 int smp
, sockets
= 0, threads
= 0, cores
= 0;
872 smp
= strtoul(optarg
, &endptr
, 10);
873 if (endptr
!= optarg
) {
874 if (*endptr
== ',') {
878 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
879 sockets
= strtoull(option
, NULL
, 10);
880 if (get_param_value(option
, 128, "cores", endptr
) != 0)
881 cores
= strtoull(option
, NULL
, 10);
882 if (get_param_value(option
, 128, "threads", endptr
) != 0)
883 threads
= strtoull(option
, NULL
, 10);
884 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
885 max_cpus
= strtoull(option
, NULL
, 10);
887 /* compute missing values, prefer sockets over cores over threads */
888 if (smp
== 0 || sockets
== 0) {
889 sockets
= sockets
> 0 ? sockets
: 1;
890 cores
= cores
> 0 ? cores
: 1;
891 threads
= threads
> 0 ? threads
: 1;
893 smp
= cores
* threads
* sockets
;
897 threads
= threads
> 0 ? threads
: 1;
898 cores
= smp
/ (sockets
* threads
);
900 threads
= smp
/ (cores
* sockets
);
904 smp_cores
= cores
> 0 ? cores
: 1;
905 smp_threads
= threads
> 0 ? threads
: 1;
910 /***********************************************************/
913 static int usb_device_add(const char *devname
)
916 USBDevice
*dev
= NULL
;
921 /* drivers with .usbdevice_name entry in USBDeviceInfo */
922 dev
= usbdevice_create(devname
);
927 if (strstart(devname
, "host:", &p
)) {
928 dev
= usb_host_device_open(p
);
929 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
930 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
931 bt_new_hci(qemu_find_bt_vlan(0)));
942 static int usb_device_del(const char *devname
)
947 if (strstart(devname
, "host:", &p
))
948 return usb_host_device_close(p
);
953 p
= strchr(devname
, '.');
956 bus_num
= strtoul(devname
, NULL
, 0);
957 addr
= strtoul(p
+ 1, NULL
, 0);
959 return usb_device_delete_addr(bus_num
, addr
);
962 static int usb_parse(const char *cmdline
)
965 r
= usb_device_add(cmdline
);
967 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
972 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
974 const char *devname
= qdict_get_str(qdict
, "devname");
975 if (usb_device_add(devname
) < 0) {
976 error_report("could not add USB device '%s'", devname
);
980 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
982 const char *devname
= qdict_get_str(qdict
, "devname");
983 if (usb_device_del(devname
) < 0) {
984 error_report("could not delete USB device '%s'", devname
);
988 /***********************************************************/
991 static struct pcmcia_socket_entry_s
{
992 PCMCIASocket
*socket
;
993 struct pcmcia_socket_entry_s
*next
;
994 } *pcmcia_sockets
= 0;
996 void pcmcia_socket_register(PCMCIASocket
*socket
)
998 struct pcmcia_socket_entry_s
*entry
;
1000 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
1001 entry
->socket
= socket
;
1002 entry
->next
= pcmcia_sockets
;
1003 pcmcia_sockets
= entry
;
1006 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
1008 struct pcmcia_socket_entry_s
*entry
, **ptr
;
1010 ptr
= &pcmcia_sockets
;
1011 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
1012 if (entry
->socket
== socket
) {
1018 void pcmcia_info(Monitor
*mon
)
1020 struct pcmcia_socket_entry_s
*iter
;
1022 if (!pcmcia_sockets
)
1023 monitor_printf(mon
, "No PCMCIA sockets\n");
1025 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1026 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1027 iter
->socket
->attached
? iter
->socket
->card_string
:
1031 /***********************************************************/
1032 /* machine registration */
1034 static QEMUMachine
*first_machine
= NULL
;
1035 QEMUMachine
*current_machine
= NULL
;
1037 int qemu_register_machine(QEMUMachine
*m
)
1040 pm
= &first_machine
;
1048 static QEMUMachine
*find_machine(const char *name
)
1052 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1053 if (!strcmp(m
->name
, name
))
1055 if (m
->alias
&& !strcmp(m
->alias
, name
))
1061 static QEMUMachine
*find_default_machine(void)
1065 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1066 if (m
->is_default
) {
1073 /***********************************************************/
1074 /* main execution loop */
1076 static void gui_update(void *opaque
)
1078 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1079 DisplayState
*ds
= opaque
;
1080 DisplayChangeListener
*dcl
= ds
->listeners
;
1082 qemu_flush_coalesced_mmio_buffer();
1085 while (dcl
!= NULL
) {
1086 if (dcl
->gui_timer_interval
&&
1087 dcl
->gui_timer_interval
< interval
)
1088 interval
= dcl
->gui_timer_interval
;
1091 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock_ms(rt_clock
));
1094 static void nographic_update(void *opaque
)
1096 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1098 qemu_flush_coalesced_mmio_buffer();
1099 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock_ms(rt_clock
));
1102 struct vm_change_state_entry
{
1103 VMChangeStateHandler
*cb
;
1105 QLIST_ENTRY (vm_change_state_entry
) entries
;
1108 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1110 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1113 VMChangeStateEntry
*e
;
1115 e
= qemu_mallocz(sizeof (*e
));
1119 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1123 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1125 QLIST_REMOVE (e
, entries
);
1129 void vm_state_notify(int running
, int reason
)
1131 VMChangeStateEntry
*e
;
1133 trace_vm_state_notify(running
, reason
);
1135 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1136 e
->cb(e
->opaque
, running
, reason
);
1145 vm_state_notify(1, 0);
1147 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1151 /* reset/shutdown handler */
1153 typedef struct QEMUResetEntry
{
1154 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1155 QEMUResetHandler
*func
;
1159 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1160 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1161 static int reset_requested
;
1162 static int shutdown_requested
, shutdown_signal
= -1;
1163 static pid_t shutdown_pid
;
1164 static int powerdown_requested
;
1165 static int debug_requested
;
1166 static int vmstop_requested
;
1168 int qemu_shutdown_requested_get(void)
1170 return shutdown_requested
;
1173 int qemu_reset_requested_get(void)
1175 return reset_requested
;
1178 int qemu_shutdown_requested(void)
1180 int r
= shutdown_requested
;
1181 shutdown_requested
= 0;
1185 void qemu_kill_report(void)
1187 if (shutdown_signal
!= -1) {
1188 fprintf(stderr
, "qemu: terminating on signal %d", shutdown_signal
);
1189 if (shutdown_pid
== 0) {
1190 /* This happens for eg ^C at the terminal, so it's worth
1191 * avoiding printing an odd message in that case.
1193 fputc('\n', stderr
);
1195 fprintf(stderr
, " from pid %d\n", shutdown_pid
);
1197 shutdown_signal
= -1;
1201 int qemu_reset_requested(void)
1203 int r
= reset_requested
;
1204 reset_requested
= 0;
1208 int qemu_powerdown_requested(void)
1210 int r
= powerdown_requested
;
1211 powerdown_requested
= 0;
1215 static int qemu_debug_requested(void)
1217 int r
= debug_requested
;
1218 debug_requested
= 0;
1222 static int qemu_vmstop_requested(void)
1224 int r
= vmstop_requested
;
1225 vmstop_requested
= 0;
1229 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1231 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1234 re
->opaque
= opaque
;
1235 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1238 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1242 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1243 if (re
->func
== func
&& re
->opaque
== opaque
) {
1244 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1251 void qemu_system_reset(void)
1253 QEMUResetEntry
*re
, *nre
;
1255 /* reset all devices */
1256 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1257 re
->func(re
->opaque
);
1259 monitor_protocol_event(QEVENT_RESET
, NULL
);
1260 cpu_synchronize_all_post_reset();
1263 void qemu_system_reset_request(void)
1266 shutdown_requested
= 1;
1268 reset_requested
= 1;
1271 qemu_notify_event();
1274 void qemu_system_killed(int signal
, pid_t pid
)
1276 shutdown_signal
= signal
;
1278 qemu_system_shutdown_request();
1281 void qemu_system_shutdown_request(void)
1283 shutdown_requested
= 1;
1284 qemu_notify_event();
1287 void qemu_system_powerdown_request(void)
1289 powerdown_requested
= 1;
1290 qemu_notify_event();
1293 void qemu_system_debug_request(void)
1295 debug_requested
= 1;
1296 qemu_notify_event();
1299 void qemu_system_vmstop_request(int reason
)
1301 vmstop_requested
= reason
;
1302 qemu_notify_event();
1305 void main_loop_wait(int nonblocking
)
1307 fd_set rfds
, wfds
, xfds
;
1315 timeout
= qemu_calculate_timeout();
1316 qemu_bh_update_timeout(&timeout
);
1319 os_host_main_loop_wait(&timeout
);
1321 tv
.tv_sec
= timeout
/ 1000;
1322 tv
.tv_usec
= (timeout
% 1000) * 1000;
1324 /* poll any events */
1325 /* XXX: separate device handlers from system ones */
1330 qemu_iohandler_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1331 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1333 qemu_mutex_unlock_iothread();
1334 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1335 qemu_mutex_lock_iothread();
1337 qemu_iohandler_poll(&rfds
, &wfds
, &xfds
, ret
);
1338 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1340 qemu_run_all_timers();
1342 /* Check bottom-halves last in case any of the earlier events triggered
1348 #ifndef CONFIG_IOTHREAD
1349 static int vm_request_pending(void)
1351 return powerdown_requested
||
1353 shutdown_requested
||
1359 qemu_irq qemu_system_powerdown
;
1361 static void main_loop(void)
1363 bool nonblocking
= false;
1364 #ifdef CONFIG_PROFILER
1369 qemu_main_loop_start();
1372 #ifndef CONFIG_IOTHREAD
1373 nonblocking
= cpu_exec_all();
1374 if (vm_request_pending()) {
1378 #ifdef CONFIG_PROFILER
1379 ti
= profile_getclock();
1381 main_loop_wait(nonblocking
);
1382 #ifdef CONFIG_PROFILER
1383 dev_time
+= profile_getclock() - ti
;
1386 if (qemu_debug_requested()) {
1387 vm_stop(VMSTOP_DEBUG
);
1389 if (qemu_shutdown_requested()) {
1391 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1393 vm_stop(VMSTOP_SHUTDOWN
);
1398 if (qemu_reset_requested()) {
1400 cpu_synchronize_all_states();
1401 qemu_system_reset();
1404 if (qemu_powerdown_requested()) {
1405 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1406 qemu_irq_raise(qemu_system_powerdown
);
1408 if ((r
= qemu_vmstop_requested())) {
1416 static void version(void)
1418 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1421 static void help(int exitcode
)
1423 const char *options_help
=
1424 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1426 #define DEFHEADING(text) stringify(text) "\n"
1427 #include "qemu-options.def"
1433 printf("usage: %s [options] [disk_image]\n"
1435 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1438 "During emulation, the following keys are useful:\n"
1439 "ctrl-alt-f toggle full screen\n"
1440 "ctrl-alt-n switch to virtual console 'n'\n"
1441 "ctrl-alt toggle mouse and keyboard grab\n"
1443 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1449 #define HAS_ARG 0x0001
1451 typedef struct QEMUOption
{
1458 static const QEMUOption qemu_options
[] = {
1459 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1460 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1461 { option, opt_arg, opt_enum, arch_mask },
1462 #define DEFHEADING(text)
1463 #include "qemu-options.def"
1469 static void select_vgahw (const char *p
)
1474 vga_interface_type
= VGA_NONE
;
1475 if (strstart(p
, "std", &opts
)) {
1476 vga_interface_type
= VGA_STD
;
1477 } else if (strstart(p
, "cirrus", &opts
)) {
1478 vga_interface_type
= VGA_CIRRUS
;
1479 } else if (strstart(p
, "vmware", &opts
)) {
1480 vga_interface_type
= VGA_VMWARE
;
1481 } else if (strstart(p
, "xenfb", &opts
)) {
1482 vga_interface_type
= VGA_XENFB
;
1483 } else if (strstart(p
, "qxl", &opts
)) {
1484 vga_interface_type
= VGA_QXL
;
1485 } else if (!strstart(p
, "none", &opts
)) {
1487 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1491 const char *nextopt
;
1493 if (strstart(opts
, ",retrace=", &nextopt
)) {
1495 if (strstart(opts
, "dumb", &nextopt
))
1496 vga_retrace_method
= VGA_RETRACE_DUMB
;
1497 else if (strstart(opts
, "precise", &nextopt
))
1498 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1499 else goto invalid_vga
;
1500 } else goto invalid_vga
;
1505 static DisplayType
select_display(const char *p
)
1508 DisplayType display
= DT_DEFAULT
;
1510 if (strstart(p
, "sdl", &opts
)) {
1514 const char *nextopt
;
1516 if (strstart(opts
, ",frame=", &nextopt
)) {
1518 if (strstart(opts
, "on", &nextopt
)) {
1520 } else if (strstart(opts
, "off", &nextopt
)) {
1523 goto invalid_sdl_args
;
1525 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1527 if (strstart(opts
, "on", &nextopt
)) {
1529 } else if (strstart(opts
, "off", &nextopt
)) {
1532 goto invalid_sdl_args
;
1534 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1536 if (strstart(opts
, "on", &nextopt
)) {
1538 } else if (strstart(opts
, "off", &nextopt
)) {
1541 goto invalid_sdl_args
;
1543 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
1545 if (strstart(opts
, "on", &nextopt
)) {
1547 } else if (strstart(opts
, "off", &nextopt
)) {
1550 goto invalid_sdl_args
;
1554 fprintf(stderr
, "Invalid SDL option string: %s\n", p
);
1560 fprintf(stderr
, "SDL support is disabled\n");
1563 } else if (strstart(p
, "vnc", &opts
)) {
1568 const char *nextopt
;
1570 if (strstart(opts
, "=", &nextopt
)) {
1571 vnc_display
= nextopt
;
1575 fprintf(stderr
, "VNC requires a display argument vnc=<display>\n");
1579 fprintf(stderr
, "VNC support is disabled\n");
1582 } else if (strstart(p
, "curses", &opts
)) {
1583 #ifdef CONFIG_CURSES
1584 display
= DT_CURSES
;
1586 fprintf(stderr
, "Curses support is disabled\n");
1589 } else if (strstart(p
, "none", &opts
)) {
1592 fprintf(stderr
, "Unknown display type: %s\n", p
);
1599 static int balloon_parse(const char *arg
)
1603 if (strcmp(arg
, "none") == 0) {
1607 if (!strncmp(arg
, "virtio", 6)) {
1608 if (arg
[6] == ',') {
1609 /* have params -> parse them */
1610 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1614 /* create empty opts */
1615 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1617 qemu_opt_set(opts
, "driver", "virtio-balloon");
1624 char *qemu_find_file(int type
, const char *name
)
1630 /* If name contains path separators then try it as a straight path. */
1631 if ((strchr(name
, '/') || strchr(name
, '\\'))
1632 && access(name
, R_OK
) == 0) {
1633 return qemu_strdup(name
);
1636 case QEMU_FILE_TYPE_BIOS
:
1639 case QEMU_FILE_TYPE_KEYMAP
:
1640 subdir
= "keymaps/";
1645 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1646 buf
= qemu_mallocz(len
);
1647 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1648 if (access(buf
, R_OK
)) {
1655 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1657 return qdev_device_help(opts
);
1660 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1664 dev
= qdev_device_add(opts
);
1670 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1672 CharDriverState
*chr
;
1674 chr
= qemu_chr_open_opts(opts
, NULL
);
1680 #ifdef CONFIG_VIRTFS
1681 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1684 ret
= qemu_fsdev_add(opts
);
1690 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1692 CharDriverState
*chr
;
1693 const char *chardev
;
1697 mode
= qemu_opt_get(opts
, "mode");
1701 if (strcmp(mode
, "readline") == 0) {
1702 flags
= MONITOR_USE_READLINE
;
1703 } else if (strcmp(mode
, "control") == 0) {
1704 flags
= MONITOR_USE_CONTROL
;
1706 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1710 if (qemu_opt_get_bool(opts
, "pretty", 0))
1711 flags
|= MONITOR_USE_PRETTY
;
1713 if (qemu_opt_get_bool(opts
, "default", 0))
1714 flags
|= MONITOR_IS_DEFAULT
;
1716 chardev
= qemu_opt_get(opts
, "chardev");
1717 chr
= qemu_chr_find(chardev
);
1719 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1723 monitor_init(chr
, flags
);
1727 static void monitor_parse(const char *optarg
, const char *mode
)
1729 static int monitor_device_index
= 0;
1735 if (strstart(optarg
, "chardev:", &p
)) {
1736 snprintf(label
, sizeof(label
), "%s", p
);
1738 snprintf(label
, sizeof(label
), "compat_monitor%d",
1739 monitor_device_index
);
1740 if (monitor_device_index
== 0) {
1743 opts
= qemu_chr_parse_compat(label
, optarg
);
1745 fprintf(stderr
, "parse error: %s\n", optarg
);
1750 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1752 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1755 qemu_opt_set(opts
, "mode", mode
);
1756 qemu_opt_set(opts
, "chardev", label
);
1758 qemu_opt_set(opts
, "default", "on");
1759 monitor_device_index
++;
1762 struct device_config
{
1764 DEV_USB
, /* -usbdevice */
1766 DEV_SERIAL
, /* -serial */
1767 DEV_PARALLEL
, /* -parallel */
1768 DEV_VIRTCON
, /* -virtioconsole */
1769 DEV_DEBUGCON
, /* -debugcon */
1771 const char *cmdline
;
1772 QTAILQ_ENTRY(device_config
) next
;
1774 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1776 static void add_device_config(int type
, const char *cmdline
)
1778 struct device_config
*conf
;
1780 conf
= qemu_mallocz(sizeof(*conf
));
1782 conf
->cmdline
= cmdline
;
1783 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1786 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1788 struct device_config
*conf
;
1791 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1792 if (conf
->type
!= type
)
1794 rc
= func(conf
->cmdline
);
1801 static int serial_parse(const char *devname
)
1803 static int index
= 0;
1806 if (strcmp(devname
, "none") == 0)
1808 if (index
== MAX_SERIAL_PORTS
) {
1809 fprintf(stderr
, "qemu: too many serial ports\n");
1812 snprintf(label
, sizeof(label
), "serial%d", index
);
1813 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1814 if (!serial_hds
[index
]) {
1815 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1816 devname
, strerror(errno
));
1823 static int parallel_parse(const char *devname
)
1825 static int index
= 0;
1828 if (strcmp(devname
, "none") == 0)
1830 if (index
== MAX_PARALLEL_PORTS
) {
1831 fprintf(stderr
, "qemu: too many parallel ports\n");
1834 snprintf(label
, sizeof(label
), "parallel%d", index
);
1835 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1836 if (!parallel_hds
[index
]) {
1837 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1838 devname
, strerror(errno
));
1845 static int virtcon_parse(const char *devname
)
1847 QemuOptsList
*device
= qemu_find_opts("device");
1848 static int index
= 0;
1850 QemuOpts
*bus_opts
, *dev_opts
;
1852 if (strcmp(devname
, "none") == 0)
1854 if (index
== MAX_VIRTIO_CONSOLES
) {
1855 fprintf(stderr
, "qemu: too many virtio consoles\n");
1859 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1860 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1862 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1863 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1865 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1866 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1867 if (!virtcon_hds
[index
]) {
1868 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1869 devname
, strerror(errno
));
1872 qemu_opt_set(dev_opts
, "chardev", label
);
1878 static int debugcon_parse(const char *devname
)
1882 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1885 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1887 fprintf(stderr
, "qemu: already have a debugcon device\n");
1890 qemu_opt_set(opts
, "driver", "isa-debugcon");
1891 qemu_opt_set(opts
, "chardev", "debugcon");
1895 static int tcg_init(void)
1901 const char *opt_name
;
1903 int (*available
)(void);
1907 { "tcg", "tcg", tcg_available
, tcg_init
, &tcg_allowed
},
1908 { "xen", "Xen", xen_available
, xen_init
, &xen_allowed
},
1909 { "kvm", "KVM", kvm_available
, kvm_init
, &kvm_allowed
},
1912 static int configure_accelerator(void)
1914 const char *p
= NULL
;
1917 bool accel_initalised
= 0;
1918 bool init_failed
= 0;
1920 QemuOptsList
*list
= qemu_find_opts("machine");
1921 if (!QTAILQ_EMPTY(&list
->head
)) {
1922 p
= qemu_opt_get(QTAILQ_FIRST(&list
->head
), "accel");
1926 /* Use the default "accelerator", tcg */
1930 while (!accel_initalised
&& *p
!= '\0') {
1934 p
= get_opt_name(buf
, sizeof (buf
), p
, ':');
1935 for (i
= 0; i
< ARRAY_SIZE(accel_list
); i
++) {
1936 if (strcmp(accel_list
[i
].opt_name
, buf
) == 0) {
1937 *(accel_list
[i
].allowed
) = 1;
1938 ret
= accel_list
[i
].init();
1941 if (!accel_list
[i
].available()) {
1942 printf("%s not supported for this target\n",
1943 accel_list
[i
].name
);
1945 fprintf(stderr
, "failed to initialize %s: %s\n",
1949 *(accel_list
[i
].allowed
) = 0;
1951 accel_initalised
= 1;
1956 if (i
== ARRAY_SIZE(accel_list
)) {
1957 fprintf(stderr
, "\"%s\" accelerator does not exist.\n", buf
);
1961 if (!accel_initalised
) {
1962 fprintf(stderr
, "No accelerator found!\n");
1967 fprintf(stderr
, "Back to %s accelerator.\n", accel_list
[i
].name
);
1970 return !accel_initalised
;
1973 void qemu_add_exit_notifier(Notifier
*notify
)
1975 notifier_list_add(&exit_notifiers
, notify
);
1978 void qemu_remove_exit_notifier(Notifier
*notify
)
1980 notifier_list_remove(&exit_notifiers
, notify
);
1983 static void qemu_run_exit_notifiers(void)
1985 notifier_list_notify(&exit_notifiers
);
1988 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
1990 notifier_list_add(&machine_init_done_notifiers
, notify
);
1993 static void qemu_run_machine_init_done_notifiers(void)
1995 notifier_list_notify(&machine_init_done_notifiers
);
1998 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1999 const char **poptarg
, int *poptind
)
2001 const QEMUOption
*popt
;
2002 int optind
= *poptind
;
2003 char *r
= argv
[optind
];
2006 loc_set_cmdline(argv
, optind
, 1);
2008 /* Treat --foo the same as -foo. */
2011 popt
= qemu_options
;
2014 error_report("invalid option");
2017 if (!strcmp(popt
->name
, r
+ 1))
2021 if (popt
->flags
& HAS_ARG
) {
2022 if (optind
>= argc
) {
2023 error_report("requires an argument");
2026 optarg
= argv
[optind
++];
2027 loc_set_cmdline(argv
, optind
- 2, 2);
2038 int main(int argc
, char **argv
, char **envp
)
2040 const char *gdbstub_dev
= NULL
;
2042 int snapshot
, linux_boot
;
2043 const char *icount_option
= NULL
;
2044 const char *initrd_filename
;
2045 const char *kernel_filename
, *kernel_cmdline
;
2046 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
2048 DisplayChangeListener
*dcl
;
2049 int cyls
, heads
, secs
, translation
;
2050 QemuOpts
*hda_opts
= NULL
, *opts
;
2051 QemuOptsList
*olist
;
2054 const char *loadvm
= NULL
;
2055 QEMUMachine
*machine
;
2056 const char *cpu_model
;
2058 const char *pid_file
= NULL
;
2059 const char *incoming
= NULL
;
2061 int show_vnc_port
= 0;
2064 const char *trace_file
= NULL
;
2066 atexit(qemu_run_exit_notifiers
);
2067 error_set_progname(argv
[0]);
2071 qemu_cache_utils_init(envp
);
2073 QLIST_INIT (&vm_change_state_head
);
2074 os_setup_early_signal_handling();
2076 module_call_init(MODULE_INIT_MACHINE
);
2077 machine
= find_default_machine();
2079 initrd_filename
= NULL
;
2082 kernel_filename
= NULL
;
2083 kernel_cmdline
= "";
2084 cyls
= heads
= secs
= 0;
2085 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2087 for (i
= 0; i
< MAX_NODES
; i
++) {
2089 node_cpumask
[i
] = 0;
2098 /* first pass of option parsing */
2100 while (optind
< argc
) {
2101 if (argv
[optind
][0] != '-') {
2106 const QEMUOption
*popt
;
2108 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2109 switch (popt
->index
) {
2110 case QEMU_OPTION_nodefconfig
:
2120 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2121 if (ret
< 0 && ret
!= -ENOENT
) {
2125 ret
= qemu_read_config_file(arch_config_name
);
2126 if (ret
< 0 && ret
!= -ENOENT
) {
2132 /* second pass of option parsing */
2137 if (argv
[optind
][0] != '-') {
2138 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2140 const QEMUOption
*popt
;
2142 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2143 if (!(popt
->arch_mask
& arch_type
)) {
2144 printf("Option %s not supported for this target\n", popt
->name
);
2147 switch(popt
->index
) {
2149 machine
= find_machine(optarg
);
2152 printf("Supported machines are:\n");
2153 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
2155 printf("%-10s %s (alias of %s)\n",
2156 m
->alias
, m
->desc
, m
->name
);
2157 printf("%-10s %s%s\n",
2159 m
->is_default
? " (default)" : "");
2161 exit(*optarg
!= '?');
2164 case QEMU_OPTION_cpu
:
2165 /* hw initialization will check this */
2166 if (*optarg
== '?') {
2167 list_cpus(stdout
, &fprintf
, optarg
);
2173 case QEMU_OPTION_initrd
:
2174 initrd_filename
= optarg
;
2176 case QEMU_OPTION_hda
:
2180 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
2182 snprintf(buf
, sizeof(buf
),
2183 "%s,cyls=%d,heads=%d,secs=%d%s",
2184 HD_OPTS
, cyls
, heads
, secs
,
2185 translation
== BIOS_ATA_TRANSLATION_LBA
?
2187 translation
== BIOS_ATA_TRANSLATION_NONE
?
2188 ",trans=none" : "");
2189 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
2192 case QEMU_OPTION_hdb
:
2193 case QEMU_OPTION_hdc
:
2194 case QEMU_OPTION_hdd
:
2195 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2198 case QEMU_OPTION_drive
:
2199 if (drive_def(optarg
) == NULL
) {
2203 case QEMU_OPTION_set
:
2204 if (qemu_set_option(optarg
) != 0)
2207 case QEMU_OPTION_global
:
2208 if (qemu_global_option(optarg
) != 0)
2211 case QEMU_OPTION_mtdblock
:
2212 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2214 case QEMU_OPTION_sd
:
2215 drive_add(IF_SD
, 0, optarg
, SD_OPTS
);
2217 case QEMU_OPTION_pflash
:
2218 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2220 case QEMU_OPTION_snapshot
:
2223 case QEMU_OPTION_hdachs
:
2227 cyls
= strtol(p
, (char **)&p
, 0);
2228 if (cyls
< 1 || cyls
> 16383)
2233 heads
= strtol(p
, (char **)&p
, 0);
2234 if (heads
< 1 || heads
> 16)
2239 secs
= strtol(p
, (char **)&p
, 0);
2240 if (secs
< 1 || secs
> 63)
2244 if (!strcmp(p
, "none"))
2245 translation
= BIOS_ATA_TRANSLATION_NONE
;
2246 else if (!strcmp(p
, "lba"))
2247 translation
= BIOS_ATA_TRANSLATION_LBA
;
2248 else if (!strcmp(p
, "auto"))
2249 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2252 } else if (*p
!= '\0') {
2254 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2257 if (hda_opts
!= NULL
) {
2259 snprintf(num
, sizeof(num
), "%d", cyls
);
2260 qemu_opt_set(hda_opts
, "cyls", num
);
2261 snprintf(num
, sizeof(num
), "%d", heads
);
2262 qemu_opt_set(hda_opts
, "heads", num
);
2263 snprintf(num
, sizeof(num
), "%d", secs
);
2264 qemu_opt_set(hda_opts
, "secs", num
);
2265 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2266 qemu_opt_set(hda_opts
, "trans", "lba");
2267 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2268 qemu_opt_set(hda_opts
, "trans", "none");
2272 case QEMU_OPTION_numa
:
2273 if (nb_numa_nodes
>= MAX_NODES
) {
2274 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2279 case QEMU_OPTION_display
:
2280 display_type
= select_display(optarg
);
2282 case QEMU_OPTION_nographic
:
2283 display_type
= DT_NOGRAPHIC
;
2285 case QEMU_OPTION_curses
:
2286 #ifdef CONFIG_CURSES
2287 display_type
= DT_CURSES
;
2289 fprintf(stderr
, "Curses support is disabled\n");
2293 case QEMU_OPTION_portrait
:
2296 case QEMU_OPTION_kernel
:
2297 kernel_filename
= optarg
;
2299 case QEMU_OPTION_append
:
2300 kernel_cmdline
= optarg
;
2302 case QEMU_OPTION_cdrom
:
2303 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2305 case QEMU_OPTION_boot
:
2307 static const char * const params
[] = {
2308 "order", "once", "menu", NULL
2310 char buf
[sizeof(boot_devices
)];
2311 char *standard_boot_devices
;
2314 if (!strchr(optarg
, '=')) {
2316 pstrcpy(buf
, sizeof(buf
), optarg
);
2317 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2319 "qemu: unknown boot parameter '%s' in '%s'\n",
2325 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2326 validate_bootdevices(buf
);
2327 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2330 if (get_param_value(buf
, sizeof(buf
),
2332 validate_bootdevices(buf
);
2333 standard_boot_devices
= qemu_strdup(boot_devices
);
2334 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2335 qemu_register_reset(restore_boot_devices
,
2336 standard_boot_devices
);
2338 if (get_param_value(buf
, sizeof(buf
),
2340 if (!strcmp(buf
, "on")) {
2342 } else if (!strcmp(buf
, "off")) {
2346 "qemu: invalid option value '%s'\n",
2354 case QEMU_OPTION_fda
:
2355 case QEMU_OPTION_fdb
:
2356 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2359 case QEMU_OPTION_no_fd_bootchk
:
2362 case QEMU_OPTION_netdev
:
2363 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2367 case QEMU_OPTION_net
:
2368 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2373 case QEMU_OPTION_tftp
:
2374 legacy_tftp_prefix
= optarg
;
2376 case QEMU_OPTION_bootp
:
2377 legacy_bootp_filename
= optarg
;
2379 case QEMU_OPTION_redir
:
2380 if (net_slirp_redir(optarg
) < 0)
2384 case QEMU_OPTION_bt
:
2385 add_device_config(DEV_BT
, optarg
);
2387 case QEMU_OPTION_audio_help
:
2388 if (!(audio_available())) {
2389 printf("Option %s not supported for this target\n", popt
->name
);
2395 case QEMU_OPTION_soundhw
:
2396 if (!(audio_available())) {
2397 printf("Option %s not supported for this target\n", popt
->name
);
2400 select_soundhw (optarg
);
2405 case QEMU_OPTION_version
:
2409 case QEMU_OPTION_m
: {
2412 value
= strtosz(optarg
, NULL
);
2414 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2418 /* On 32-bit hosts, QEMU is limited by virtual address space */
2419 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2420 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2423 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2424 fprintf(stderr
, "qemu: ram size too large\n");
2430 case QEMU_OPTION_mempath
:
2434 case QEMU_OPTION_mem_prealloc
:
2439 set_cpu_log(optarg
);
2442 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2444 case QEMU_OPTION_gdb
:
2445 gdbstub_dev
= optarg
;
2450 case QEMU_OPTION_bios
:
2453 case QEMU_OPTION_singlestep
:
2460 keyboard_layout
= optarg
;
2462 case QEMU_OPTION_localtime
:
2465 case QEMU_OPTION_vga
:
2466 select_vgahw (optarg
);
2473 w
= strtol(p
, (char **)&p
, 10);
2476 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2482 h
= strtol(p
, (char **)&p
, 10);
2487 depth
= strtol(p
, (char **)&p
, 10);
2488 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2489 depth
!= 24 && depth
!= 32)
2491 } else if (*p
== '\0') {
2492 depth
= graphic_depth
;
2499 graphic_depth
= depth
;
2502 case QEMU_OPTION_echr
:
2505 term_escape_char
= strtol(optarg
, &r
, 0);
2507 printf("Bad argument to echr\n");
2510 case QEMU_OPTION_monitor
:
2511 monitor_parse(optarg
, "readline");
2512 default_monitor
= 0;
2514 case QEMU_OPTION_qmp
:
2515 monitor_parse(optarg
, "control");
2516 default_monitor
= 0;
2518 case QEMU_OPTION_mon
:
2519 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2523 default_monitor
= 0;
2525 case QEMU_OPTION_chardev
:
2526 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2531 case QEMU_OPTION_fsdev
:
2532 olist
= qemu_find_opts("fsdev");
2534 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2537 opts
= qemu_opts_parse(olist
, optarg
, 1);
2539 fprintf(stderr
, "parse error: %s\n", optarg
);
2543 case QEMU_OPTION_virtfs
: {
2547 olist
= qemu_find_opts("virtfs");
2549 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2552 opts
= qemu_opts_parse(olist
, optarg
, 1);
2554 fprintf(stderr
, "parse error: %s\n", optarg
);
2558 if (qemu_opt_get(opts
, "fstype") == NULL
||
2559 qemu_opt_get(opts
, "mount_tag") == NULL
||
2560 qemu_opt_get(opts
, "path") == NULL
||
2561 qemu_opt_get(opts
, "security_model") == NULL
) {
2562 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2563 "security_model=[mapped|passthrough|none],"
2564 "mount_tag=tag.\n");
2568 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
2569 qemu_opt_get(opts
, "mount_tag"), 1);
2571 fprintf(stderr
, "duplicate fsdev id: %s\n",
2572 qemu_opt_get(opts
, "mount_tag"));
2575 qemu_opt_set(fsdev
, "fstype", qemu_opt_get(opts
, "fstype"));
2576 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"));
2577 qemu_opt_set(fsdev
, "security_model",
2578 qemu_opt_get(opts
, "security_model"));
2580 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
2581 qemu_opt_set(device
, "driver", "virtio-9p-pci");
2582 qemu_opt_set(device
, "fsdev",
2583 qemu_opt_get(opts
, "mount_tag"));
2584 qemu_opt_set(device
, "mount_tag",
2585 qemu_opt_get(opts
, "mount_tag"));
2588 case QEMU_OPTION_serial
:
2589 add_device_config(DEV_SERIAL
, optarg
);
2591 if (strncmp(optarg
, "mon:", 4) == 0) {
2592 default_monitor
= 0;
2595 case QEMU_OPTION_watchdog
:
2598 "qemu: only one watchdog option may be given\n");
2603 case QEMU_OPTION_watchdog_action
:
2604 if (select_watchdog_action(optarg
) == -1) {
2605 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2609 case QEMU_OPTION_virtiocon
:
2610 add_device_config(DEV_VIRTCON
, optarg
);
2611 default_virtcon
= 0;
2612 if (strncmp(optarg
, "mon:", 4) == 0) {
2613 default_monitor
= 0;
2616 case QEMU_OPTION_parallel
:
2617 add_device_config(DEV_PARALLEL
, optarg
);
2618 default_parallel
= 0;
2619 if (strncmp(optarg
, "mon:", 4) == 0) {
2620 default_monitor
= 0;
2623 case QEMU_OPTION_debugcon
:
2624 add_device_config(DEV_DEBUGCON
, optarg
);
2626 case QEMU_OPTION_loadvm
:
2629 case QEMU_OPTION_full_screen
:
2633 case QEMU_OPTION_no_frame
:
2636 case QEMU_OPTION_alt_grab
:
2639 case QEMU_OPTION_ctrl_grab
:
2642 case QEMU_OPTION_no_quit
:
2645 case QEMU_OPTION_sdl
:
2646 display_type
= DT_SDL
;
2649 case QEMU_OPTION_no_frame
:
2650 case QEMU_OPTION_alt_grab
:
2651 case QEMU_OPTION_ctrl_grab
:
2652 case QEMU_OPTION_no_quit
:
2653 case QEMU_OPTION_sdl
:
2654 fprintf(stderr
, "SDL support is disabled\n");
2657 case QEMU_OPTION_pidfile
:
2660 case QEMU_OPTION_win2k_hack
:
2661 win2k_install_hack
= 1;
2663 case QEMU_OPTION_rtc_td_hack
:
2666 case QEMU_OPTION_acpitable
:
2667 do_acpitable_option(optarg
);
2669 case QEMU_OPTION_smbios
:
2670 do_smbios_option(optarg
);
2672 case QEMU_OPTION_enable_kvm
:
2673 olist
= qemu_find_opts("machine");
2674 qemu_opts_reset(olist
);
2675 qemu_opts_parse(olist
, "accel=kvm", 0);
2677 case QEMU_OPTION_machine
:
2678 olist
= qemu_find_opts("machine");
2679 qemu_opts_reset(olist
);
2680 opts
= qemu_opts_parse(olist
, optarg
, 0);
2682 fprintf(stderr
, "parse error: %s\n", optarg
);
2686 case QEMU_OPTION_usb
:
2689 case QEMU_OPTION_usbdevice
:
2691 add_device_config(DEV_USB
, optarg
);
2693 case QEMU_OPTION_device
:
2694 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2698 case QEMU_OPTION_smp
:
2701 fprintf(stderr
, "Invalid number of CPUs\n");
2704 if (max_cpus
< smp_cpus
) {
2705 fprintf(stderr
, "maxcpus must be equal to or greater than "
2709 if (max_cpus
> 255) {
2710 fprintf(stderr
, "Unsupported number of maxcpus\n");
2714 case QEMU_OPTION_vnc
:
2717 vnc_display
= optarg
;
2719 fprintf(stderr
, "VNC support is disabled\n");
2723 case QEMU_OPTION_no_acpi
:
2726 case QEMU_OPTION_no_hpet
:
2729 case QEMU_OPTION_balloon
:
2730 if (balloon_parse(optarg
) < 0) {
2731 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2735 case QEMU_OPTION_no_reboot
:
2738 case QEMU_OPTION_no_shutdown
:
2741 case QEMU_OPTION_show_cursor
:
2744 case QEMU_OPTION_uuid
:
2745 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2746 fprintf(stderr
, "Fail to parse UUID string."
2747 " Wrong format.\n");
2751 case QEMU_OPTION_option_rom
:
2752 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2753 fprintf(stderr
, "Too many option ROMs\n");
2756 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
2757 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
2758 option_rom
[nb_option_roms
].bootindex
=
2759 qemu_opt_get_number(opts
, "bootindex", -1);
2760 if (!option_rom
[nb_option_roms
].name
) {
2761 fprintf(stderr
, "Option ROM file is not specified\n");
2766 case QEMU_OPTION_semihosting
:
2767 semihosting_enabled
= 1;
2769 case QEMU_OPTION_name
:
2770 qemu_name
= qemu_strdup(optarg
);
2772 char *p
= strchr(qemu_name
, ',');
2775 if (strncmp(p
, "process=", 8)) {
2776 fprintf(stderr
, "Unknown subargument %s to -name\n", p
);
2780 os_set_proc_name(p
);
2784 case QEMU_OPTION_prom_env
:
2785 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2786 fprintf(stderr
, "Too many prom variables\n");
2789 prom_envs
[nb_prom_envs
] = optarg
;
2792 case QEMU_OPTION_old_param
:
2795 case QEMU_OPTION_clock
:
2796 configure_alarms(optarg
);
2798 case QEMU_OPTION_startdate
:
2799 configure_rtc_date_offset(optarg
, 1);
2801 case QEMU_OPTION_rtc
:
2802 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2806 configure_rtc(opts
);
2808 case QEMU_OPTION_tb_size
:
2809 tb_size
= strtol(optarg
, NULL
, 0);
2813 case QEMU_OPTION_icount
:
2814 icount_option
= optarg
;
2816 case QEMU_OPTION_incoming
:
2818 incoming_expected
= true;
2820 case QEMU_OPTION_nodefaults
:
2822 default_parallel
= 0;
2823 default_virtcon
= 0;
2824 default_monitor
= 0;
2831 case QEMU_OPTION_xen_domid
:
2832 if (!(xen_available())) {
2833 printf("Option %s not supported for this target\n", popt
->name
);
2836 xen_domid
= atoi(optarg
);
2838 case QEMU_OPTION_xen_create
:
2839 if (!(xen_available())) {
2840 printf("Option %s not supported for this target\n", popt
->name
);
2843 xen_mode
= XEN_CREATE
;
2845 case QEMU_OPTION_xen_attach
:
2846 if (!(xen_available())) {
2847 printf("Option %s not supported for this target\n", popt
->name
);
2850 xen_mode
= XEN_ATTACH
;
2852 #ifdef CONFIG_SIMPLE_TRACE
2853 case QEMU_OPTION_trace
:
2854 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2856 trace_file
= qemu_opt_get(opts
, "file");
2860 case QEMU_OPTION_readconfig
:
2862 int ret
= qemu_read_config_file(optarg
);
2864 fprintf(stderr
, "read config %s: %s\n", optarg
,
2870 case QEMU_OPTION_spice
:
2871 olist
= qemu_find_opts("spice");
2873 fprintf(stderr
, "spice is not supported by this qemu build.\n");
2876 opts
= qemu_opts_parse(olist
, optarg
, 0);
2878 fprintf(stderr
, "parse error: %s\n", optarg
);
2882 case QEMU_OPTION_writeconfig
:
2885 if (strcmp(optarg
, "-") == 0) {
2888 fp
= fopen(optarg
, "w");
2890 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2894 qemu_config_write(fp
);
2899 os_parse_cmd_args(popt
->index
, optarg
);
2905 if (!st_init(trace_file
)) {
2906 fprintf(stderr
, "warning: unable to initialize simple trace backend\n");
2909 /* If no data_dir is specified then try to find it relative to the
2912 data_dir
= os_find_datadir(argv
[0]);
2914 /* If all else fails use the install patch specified when building. */
2916 data_dir
= CONFIG_QEMU_DATADIR
;
2920 * Default to max_cpus = smp_cpus, in case the user doesn't
2921 * specify a max_cpus value.
2924 max_cpus
= smp_cpus
;
2926 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2927 if (smp_cpus
> machine
->max_cpus
) {
2928 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2929 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2935 * Get the default machine options from the machine if it is not already
2936 * specified either by the configuration file or by the command line.
2938 if (machine
->default_machine_opts
) {
2939 QemuOptsList
*list
= qemu_find_opts("machine");
2940 const char *p
= NULL
;
2942 if (!QTAILQ_EMPTY(&list
->head
)) {
2943 p
= qemu_opt_get(QTAILQ_FIRST(&list
->head
), "accel");
2946 opts
= qemu_opts_parse(qemu_find_opts("machine"),
2947 machine
->default_machine_opts
, 0);
2949 fprintf(stderr
, "parse error for machine %s: %s\n",
2950 machine
->name
, machine
->default_machine_opts
);
2956 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2957 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2959 if (machine
->no_serial
) {
2962 if (machine
->no_parallel
) {
2963 default_parallel
= 0;
2965 if (!machine
->use_virtcon
) {
2966 default_virtcon
= 0;
2968 if (machine
->no_vga
) {
2971 if (machine
->no_floppy
) {
2974 if (machine
->no_cdrom
) {
2977 if (machine
->no_sdcard
) {
2981 if (display_type
== DT_NOGRAPHIC
) {
2982 if (default_parallel
)
2983 add_device_config(DEV_PARALLEL
, "null");
2984 if (default_serial
&& default_monitor
) {
2985 add_device_config(DEV_SERIAL
, "mon:stdio");
2986 } else if (default_virtcon
&& default_monitor
) {
2987 add_device_config(DEV_VIRTCON
, "mon:stdio");
2990 add_device_config(DEV_SERIAL
, "stdio");
2991 if (default_virtcon
)
2992 add_device_config(DEV_VIRTCON
, "stdio");
2993 if (default_monitor
)
2994 monitor_parse("stdio", "readline");
2998 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2999 if (default_parallel
)
3000 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
3001 if (default_monitor
)
3002 monitor_parse("vc:80Cx24C", "readline");
3003 if (default_virtcon
)
3004 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
3007 vga_interface_type
= VGA_CIRRUS
;
3011 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
3013 #ifdef CONFIG_VIRTFS
3014 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
3021 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
3026 configure_accelerator();
3028 if (qemu_init_main_loop()) {
3029 fprintf(stderr
, "qemu_init_main_loop failed\n");
3032 linux_boot
= (kernel_filename
!= NULL
);
3034 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
3035 fprintf(stderr
, "-append only allowed with -kernel option\n");
3039 if (!linux_boot
&& initrd_filename
!= NULL
) {
3040 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
3044 os_set_line_buffering();
3046 if (init_timer_alarm() < 0) {
3047 fprintf(stderr
, "could not initialize alarm timer\n");
3050 configure_icount(icount_option
);
3052 if (net_init_clients() < 0) {
3056 /* init the bluetooth world */
3057 if (foreach_device_config(DEV_BT
, bt_parse
))
3060 /* init the memory */
3062 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
3064 /* init the dynamic translator */
3065 cpu_exec_init_all(tb_size
* 1024 * 1024);
3067 bdrv_init_with_whitelist();
3071 /* open the virtual block devices */
3073 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
3074 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
3077 default_drive(default_cdrom
, snapshot
, machine
->use_scsi
,
3078 IF_DEFAULT
, 2, CDROM_OPTS
);
3079 default_drive(default_floppy
, snapshot
, machine
->use_scsi
,
3080 IF_FLOPPY
, 0, FD_OPTS
);
3081 default_drive(default_sdcard
, snapshot
, machine
->use_scsi
,
3084 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
3087 if (nb_numa_nodes
> 0) {
3090 if (nb_numa_nodes
> smp_cpus
) {
3091 nb_numa_nodes
= smp_cpus
;
3094 /* If no memory size if given for any node, assume the default case
3095 * and distribute the available memory equally across all nodes
3097 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3098 if (node_mem
[i
] != 0)
3101 if (i
== nb_numa_nodes
) {
3102 uint64_t usedmem
= 0;
3104 /* On Linux, the each node's border has to be 8MB aligned,
3105 * the final node gets the rest.
3107 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
3108 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
3109 usedmem
+= node_mem
[i
];
3111 node_mem
[i
] = ram_size
- usedmem
;
3114 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3115 if (node_cpumask
[i
] != 0)
3118 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3119 * must cope with this anyway, because there are BIOSes out there in
3120 * real machines which also use this scheme.
3122 if (i
== nb_numa_nodes
) {
3123 for (i
= 0; i
< smp_cpus
; i
++) {
3124 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
3129 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
3133 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
3135 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
3137 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
3139 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
3142 module_call_init(MODULE_INIT_DEVICE
);
3144 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
3148 i
= select_watchdog(watchdog
);
3150 exit (i
== 1 ? 1 : 0);
3153 if (machine
->compat_props
) {
3154 qdev_prop_register_global_list(machine
->compat_props
);
3158 machine
->init(ram_size
, boot_devices
,
3159 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
3161 cpu_synchronize_all_post_init();
3165 current_machine
= machine
;
3167 /* init USB devices */
3169 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
3173 /* init generic devices */
3174 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3177 net_check_clients();
3179 /* just use the first displaystate for the moment */
3180 ds
= get_displaystate();
3184 if (display_type
== DT_DEFAULT
&& !display_remote
) {
3185 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3186 display_type
= DT_SDL
;
3187 #elif defined(CONFIG_VNC)
3188 vnc_display
= "localhost:0,to=99";
3191 display_type
= DT_NONE
;
3196 /* init local displays */
3197 switch (display_type
) {
3200 #if defined(CONFIG_CURSES)
3202 curses_display_init(ds
, full_screen
);
3205 #if defined(CONFIG_SDL)
3207 sdl_display_init(ds
, full_screen
, no_frame
);
3209 #elif defined(CONFIG_COCOA)
3211 cocoa_display_init(ds
, full_screen
);
3218 /* must be after terminal init, SDL library changes signal handlers */
3219 os_setup_signal_handling();
3222 /* init remote displays */
3224 vnc_display_init(ds
);
3225 if (vnc_display_open(ds
, vnc_display
) < 0)
3228 if (show_vnc_port
) {
3229 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3234 if (using_spice
&& !qxl_enabled
) {
3235 qemu_spice_display_init(ds
);
3241 dcl
= ds
->listeners
;
3242 while (dcl
!= NULL
) {
3243 if (dcl
->dpy_refresh
!= NULL
) {
3244 ds
->gui_timer
= qemu_new_timer_ms(rt_clock
, gui_update
, ds
);
3245 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock_ms(rt_clock
));
3250 if (ds
->gui_timer
== NULL
) {
3251 nographic_timer
= qemu_new_timer_ms(rt_clock
, nographic_update
, NULL
);
3252 qemu_mod_timer(nographic_timer
, qemu_get_clock_ms(rt_clock
));
3254 text_consoles_set_display(ds
);
3256 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3257 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3262 qdev_machine_creation_done();
3264 if (rom_load_all() != 0) {
3265 fprintf(stderr
, "rom loading failed\n");
3269 /* TODO: once all bus devices are qdevified, this should be done
3270 * when bus is created by qdev.c */
3271 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
3272 qemu_run_machine_init_done_notifiers();
3274 qemu_system_reset();
3276 if (load_vmstate(loadvm
) < 0) {
3282 int ret
= qemu_start_incoming_migration(incoming
);
3284 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3288 } else if (autostart
) {