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
},
294 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
296 const char *driver
= qemu_opt_get(opts
, "driver");
301 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
302 if (strcmp(default_list
[i
].driver
, driver
) != 0)
304 *(default_list
[i
].flag
) = 0;
309 /***********************************************************/
310 /* real time host monotonic timer */
312 /***********************************************************/
313 /* host time/date access */
314 void qemu_get_timedate(struct tm
*tm
, int offset
)
321 if (rtc_date_offset
== -1) {
325 ret
= localtime(&ti
);
327 ti
-= rtc_date_offset
;
331 memcpy(tm
, ret
, sizeof(struct tm
));
334 int qemu_timedate_diff(struct tm
*tm
)
338 if (rtc_date_offset
== -1)
340 seconds
= mktimegm(tm
);
342 seconds
= mktime(tm
);
344 seconds
= mktimegm(tm
) + rtc_date_offset
;
346 return seconds
- time(NULL
);
349 void rtc_change_mon_event(struct tm
*tm
)
353 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
354 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
355 qobject_decref(data
);
358 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
360 time_t rtc_start_date
;
363 if (!strcmp(startdate
, "now") && legacy
) {
364 rtc_date_offset
= -1;
366 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
374 } else if (sscanf(startdate
, "%d-%d-%d",
386 rtc_start_date
= mktimegm(&tm
);
387 if (rtc_start_date
== -1) {
389 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
390 "'2006-06-17T16:01:21' or '2006-06-17'\n");
393 rtc_date_offset
= time(NULL
) - rtc_start_date
;
397 static void configure_rtc(QemuOpts
*opts
)
401 value
= qemu_opt_get(opts
, "base");
403 if (!strcmp(value
, "utc")) {
405 } else if (!strcmp(value
, "localtime")) {
408 configure_rtc_date_offset(value
, 0);
411 value
= qemu_opt_get(opts
, "clock");
413 if (!strcmp(value
, "host")) {
414 rtc_clock
= host_clock
;
415 } else if (!strcmp(value
, "vm")) {
416 rtc_clock
= vm_clock
;
418 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
422 value
= qemu_opt_get(opts
, "driftfix");
424 if (!strcmp(value
, "slew")) {
426 } else if (!strcmp(value
, "none")) {
429 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
435 /***********************************************************/
436 /* Bluetooth support */
439 static struct HCIInfo
*hci_table
[MAX_NICS
];
441 static struct bt_vlan_s
{
442 struct bt_scatternet_s net
;
444 struct bt_vlan_s
*next
;
447 /* find or alloc a new bluetooth "VLAN" */
448 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
450 struct bt_vlan_s
**pvlan
, *vlan
;
451 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
455 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
457 pvlan
= &first_bt_vlan
;
458 while (*pvlan
!= NULL
)
459 pvlan
= &(*pvlan
)->next
;
464 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
468 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
473 static struct HCIInfo null_hci
= {
474 .cmd_send
= null_hci_send
,
475 .sco_send
= null_hci_send
,
476 .acl_send
= null_hci_send
,
477 .bdaddr_set
= null_hci_addr_set
,
480 struct HCIInfo
*qemu_next_hci(void)
482 if (cur_hci
== nb_hcis
)
485 return hci_table
[cur_hci
++];
488 static struct HCIInfo
*hci_init(const char *str
)
491 struct bt_scatternet_s
*vlan
= 0;
493 if (!strcmp(str
, "null"))
496 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
498 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
499 else if (!strncmp(str
, "hci", 3)) {
502 if (!strncmp(str
+ 3, ",vlan=", 6)) {
503 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
508 vlan
= qemu_find_bt_vlan(0);
510 return bt_new_hci(vlan
);
513 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
518 static int bt_hci_parse(const char *str
)
523 if (nb_hcis
>= MAX_NICS
) {
524 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
537 bdaddr
.b
[5] = 0x56 + nb_hcis
;
538 hci
->bdaddr_set(hci
, bdaddr
.b
);
540 hci_table
[nb_hcis
++] = hci
;
545 static void bt_vhci_add(int vlan_id
)
547 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
550 fprintf(stderr
, "qemu: warning: adding a VHCI to "
551 "an empty scatternet %i\n", vlan_id
);
553 bt_vhci_init(bt_new_hci(vlan
));
556 static struct bt_device_s
*bt_device_add(const char *opt
)
558 struct bt_scatternet_s
*vlan
;
560 char *endp
= strstr(opt
, ",vlan=");
561 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
564 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
567 vlan_id
= strtol(endp
+ 6, &endp
, 0);
569 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
574 vlan
= qemu_find_bt_vlan(vlan_id
);
577 fprintf(stderr
, "qemu: warning: adding a slave device to "
578 "an empty scatternet %i\n", vlan_id
);
580 if (!strcmp(devname
, "keyboard"))
581 return bt_keyboard_init(vlan
);
583 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
587 static int bt_parse(const char *opt
)
589 const char *endp
, *p
;
592 if (strstart(opt
, "hci", &endp
)) {
593 if (!*endp
|| *endp
== ',') {
595 if (!strstart(endp
, ",vlan=", 0))
598 return bt_hci_parse(opt
);
600 } else if (strstart(opt
, "vhci", &endp
)) {
601 if (!*endp
|| *endp
== ',') {
603 if (strstart(endp
, ",vlan=", &p
)) {
604 vlan
= strtol(p
, (char **) &endp
, 0);
606 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
610 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
619 } else if (strstart(opt
, "device:", &endp
))
620 return !bt_device_add(endp
);
622 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
626 /***********************************************************/
627 /* QEMU Block devices */
629 #define HD_OPTS "media=disk"
630 #define CDROM_OPTS "media=cdrom"
632 #define PFLASH_OPTS ""
636 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
638 int *use_scsi
= opaque
;
640 return drive_init(opts
, *use_scsi
) == NULL
;
643 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
645 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
646 qemu_opt_set(opts
, "snapshot", "on");
651 static void default_drive(int enable
, int snapshot
, int use_scsi
,
652 BlockInterfaceType type
, int index
,
657 if (type
== IF_DEFAULT
) {
658 type
= use_scsi
? IF_SCSI
: IF_IDE
;
661 if (!enable
|| drive_get_by_index(type
, index
)) {
665 opts
= drive_add(type
, index
, NULL
, optstr
);
667 drive_enable_snapshot(opts
, NULL
);
669 if (!drive_init(opts
, use_scsi
)) {
674 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
676 boot_set_handler
= func
;
677 boot_set_opaque
= opaque
;
680 int qemu_boot_set(const char *boot_devices
)
682 if (!boot_set_handler
) {
685 return boot_set_handler(boot_set_opaque
, boot_devices
);
688 static void validate_bootdevices(char *devices
)
690 /* We just do some generic consistency checks */
694 for (p
= devices
; *p
!= '\0'; p
++) {
695 /* Allowed boot devices are:
696 * a-b: floppy disk drives
697 * c-f: IDE disk drives
698 * g-m: machine implementation dependant drives
699 * n-p: network devices
700 * It's up to each machine implementation to check if the given boot
701 * devices match the actual hardware implementation and firmware
704 if (*p
< 'a' || *p
> 'p') {
705 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
708 if (bitmap
& (1 << (*p
- 'a'))) {
709 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
712 bitmap
|= 1 << (*p
- 'a');
716 static void restore_boot_devices(void *opaque
)
718 char *standard_boot_devices
= opaque
;
719 static int first
= 1;
721 /* Restore boot order and remove ourselves after the first boot */
727 qemu_boot_set(standard_boot_devices
);
729 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
730 qemu_free(standard_boot_devices
);
733 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
736 FWBootEntry
*node
, *i
;
742 assert(dev
!= NULL
|| suffix
!= NULL
);
744 node
= qemu_mallocz(sizeof(FWBootEntry
));
745 node
->bootindex
= bootindex
;
746 node
->suffix
= suffix
? qemu_strdup(suffix
) : NULL
;
749 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
750 if (i
->bootindex
== bootindex
) {
751 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
753 } else if (i
->bootindex
< bootindex
) {
756 QTAILQ_INSERT_BEFORE(i
, node
, link
);
759 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
763 * This function returns null terminated string that consist of new line
764 * separated device paths.
766 * memory pointed by "size" is assigned total length of the array in bytes
769 char *get_boot_devices_list(uint32_t *size
)
775 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
776 char *devpath
= NULL
, *bootpath
;
780 devpath
= qdev_get_fw_dev_path(i
->dev
);
784 if (i
->suffix
&& devpath
) {
785 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
787 bootpath
= qemu_malloc(bootpathlen
);
788 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
790 } else if (devpath
) {
793 bootpath
= qemu_strdup(i
->suffix
);
798 list
[total
-1] = '\n';
800 len
= strlen(bootpath
) + 1;
801 list
= qemu_realloc(list
, total
+ len
);
802 memcpy(&list
[total
], bootpath
, len
);
812 static void numa_add(const char *optarg
)
816 unsigned long long value
, endvalue
;
819 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
820 if (!strcmp(option
, "node")) {
821 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
822 nodenr
= nb_numa_nodes
;
824 nodenr
= strtoull(option
, NULL
, 10);
827 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
828 node_mem
[nodenr
] = 0;
831 sval
= strtosz(option
, NULL
);
833 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
836 node_mem
[nodenr
] = sval
;
838 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
839 node_cpumask
[nodenr
] = 0;
841 value
= strtoull(option
, &endptr
, 10);
844 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
846 if (*endptr
== '-') {
847 endvalue
= strtoull(endptr
+1, &endptr
, 10);
848 if (endvalue
>= 63) {
851 "only 63 CPUs in NUMA mode supported.\n");
853 value
= (2ULL << endvalue
) - (1ULL << value
);
855 value
= 1ULL << value
;
858 node_cpumask
[nodenr
] = value
;
865 static void smp_parse(const char *optarg
)
867 int smp
, sockets
= 0, threads
= 0, cores
= 0;
871 smp
= strtoul(optarg
, &endptr
, 10);
872 if (endptr
!= optarg
) {
873 if (*endptr
== ',') {
877 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
878 sockets
= strtoull(option
, NULL
, 10);
879 if (get_param_value(option
, 128, "cores", endptr
) != 0)
880 cores
= strtoull(option
, NULL
, 10);
881 if (get_param_value(option
, 128, "threads", endptr
) != 0)
882 threads
= strtoull(option
, NULL
, 10);
883 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
884 max_cpus
= strtoull(option
, NULL
, 10);
886 /* compute missing values, prefer sockets over cores over threads */
887 if (smp
== 0 || sockets
== 0) {
888 sockets
= sockets
> 0 ? sockets
: 1;
889 cores
= cores
> 0 ? cores
: 1;
890 threads
= threads
> 0 ? threads
: 1;
892 smp
= cores
* threads
* sockets
;
896 threads
= threads
> 0 ? threads
: 1;
897 cores
= smp
/ (sockets
* threads
);
899 threads
= smp
/ (cores
* sockets
);
903 smp_cores
= cores
> 0 ? cores
: 1;
904 smp_threads
= threads
> 0 ? threads
: 1;
909 /***********************************************************/
912 static int usb_device_add(const char *devname
)
915 USBDevice
*dev
= NULL
;
920 /* drivers with .usbdevice_name entry in USBDeviceInfo */
921 dev
= usbdevice_create(devname
);
926 if (strstart(devname
, "host:", &p
)) {
927 dev
= usb_host_device_open(p
);
928 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
929 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
930 bt_new_hci(qemu_find_bt_vlan(0)));
941 static int usb_device_del(const char *devname
)
946 if (strstart(devname
, "host:", &p
))
947 return usb_host_device_close(p
);
952 p
= strchr(devname
, '.');
955 bus_num
= strtoul(devname
, NULL
, 0);
956 addr
= strtoul(p
+ 1, NULL
, 0);
958 return usb_device_delete_addr(bus_num
, addr
);
961 static int usb_parse(const char *cmdline
)
964 r
= usb_device_add(cmdline
);
966 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
971 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
973 const char *devname
= qdict_get_str(qdict
, "devname");
974 if (usb_device_add(devname
) < 0) {
975 error_report("could not add USB device '%s'", devname
);
979 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
981 const char *devname
= qdict_get_str(qdict
, "devname");
982 if (usb_device_del(devname
) < 0) {
983 error_report("could not delete USB device '%s'", devname
);
987 /***********************************************************/
990 static struct pcmcia_socket_entry_s
{
991 PCMCIASocket
*socket
;
992 struct pcmcia_socket_entry_s
*next
;
993 } *pcmcia_sockets
= 0;
995 void pcmcia_socket_register(PCMCIASocket
*socket
)
997 struct pcmcia_socket_entry_s
*entry
;
999 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
1000 entry
->socket
= socket
;
1001 entry
->next
= pcmcia_sockets
;
1002 pcmcia_sockets
= entry
;
1005 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
1007 struct pcmcia_socket_entry_s
*entry
, **ptr
;
1009 ptr
= &pcmcia_sockets
;
1010 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
1011 if (entry
->socket
== socket
) {
1017 void pcmcia_info(Monitor
*mon
)
1019 struct pcmcia_socket_entry_s
*iter
;
1021 if (!pcmcia_sockets
)
1022 monitor_printf(mon
, "No PCMCIA sockets\n");
1024 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1025 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1026 iter
->socket
->attached
? iter
->socket
->card_string
:
1030 /***********************************************************/
1031 /* machine registration */
1033 static QEMUMachine
*first_machine
= NULL
;
1034 QEMUMachine
*current_machine
= NULL
;
1036 int qemu_register_machine(QEMUMachine
*m
)
1039 pm
= &first_machine
;
1047 static QEMUMachine
*find_machine(const char *name
)
1051 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1052 if (!strcmp(m
->name
, name
))
1054 if (m
->alias
&& !strcmp(m
->alias
, name
))
1060 static QEMUMachine
*find_default_machine(void)
1064 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1065 if (m
->is_default
) {
1072 /***********************************************************/
1073 /* main execution loop */
1075 static void gui_update(void *opaque
)
1077 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1078 DisplayState
*ds
= opaque
;
1079 DisplayChangeListener
*dcl
= ds
->listeners
;
1081 qemu_flush_coalesced_mmio_buffer();
1084 while (dcl
!= NULL
) {
1085 if (dcl
->gui_timer_interval
&&
1086 dcl
->gui_timer_interval
< interval
)
1087 interval
= dcl
->gui_timer_interval
;
1090 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock_ms(rt_clock
));
1093 static void nographic_update(void *opaque
)
1095 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1097 qemu_flush_coalesced_mmio_buffer();
1098 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock_ms(rt_clock
));
1101 struct vm_change_state_entry
{
1102 VMChangeStateHandler
*cb
;
1104 QLIST_ENTRY (vm_change_state_entry
) entries
;
1107 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1109 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1112 VMChangeStateEntry
*e
;
1114 e
= qemu_mallocz(sizeof (*e
));
1118 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1122 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1124 QLIST_REMOVE (e
, entries
);
1128 void vm_state_notify(int running
, int reason
)
1130 VMChangeStateEntry
*e
;
1132 trace_vm_state_notify(running
, reason
);
1134 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1135 e
->cb(e
->opaque
, running
, reason
);
1144 vm_state_notify(1, 0);
1146 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1150 /* reset/shutdown handler */
1152 typedef struct QEMUResetEntry
{
1153 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1154 QEMUResetHandler
*func
;
1158 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1159 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1160 static int reset_requested
;
1161 static int shutdown_requested
, shutdown_signal
= -1;
1162 static pid_t shutdown_pid
;
1163 static int powerdown_requested
;
1164 static int debug_requested
;
1165 static int vmstop_requested
;
1167 int qemu_shutdown_requested_get(void)
1169 return shutdown_requested
;
1172 int qemu_reset_requested_get(void)
1174 return reset_requested
;
1177 int qemu_shutdown_requested(void)
1179 int r
= shutdown_requested
;
1180 shutdown_requested
= 0;
1184 void qemu_kill_report(void)
1186 if (shutdown_signal
!= -1) {
1187 fprintf(stderr
, "qemu: terminating on signal %d", shutdown_signal
);
1188 if (shutdown_pid
== 0) {
1189 /* This happens for eg ^C at the terminal, so it's worth
1190 * avoiding printing an odd message in that case.
1192 fputc('\n', stderr
);
1194 fprintf(stderr
, " from pid %d\n", shutdown_pid
);
1196 shutdown_signal
= -1;
1200 int qemu_reset_requested(void)
1202 int r
= reset_requested
;
1203 reset_requested
= 0;
1207 int qemu_powerdown_requested(void)
1209 int r
= powerdown_requested
;
1210 powerdown_requested
= 0;
1214 static int qemu_debug_requested(void)
1216 int r
= debug_requested
;
1217 debug_requested
= 0;
1221 static int qemu_vmstop_requested(void)
1223 int r
= vmstop_requested
;
1224 vmstop_requested
= 0;
1228 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1230 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1233 re
->opaque
= opaque
;
1234 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1237 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1241 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1242 if (re
->func
== func
&& re
->opaque
== opaque
) {
1243 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1250 void qemu_system_reset(void)
1252 QEMUResetEntry
*re
, *nre
;
1254 /* reset all devices */
1255 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1256 re
->func(re
->opaque
);
1258 monitor_protocol_event(QEVENT_RESET
, NULL
);
1259 cpu_synchronize_all_post_reset();
1262 void qemu_system_reset_request(void)
1265 shutdown_requested
= 1;
1267 reset_requested
= 1;
1270 qemu_notify_event();
1273 void qemu_system_killed(int signal
, pid_t pid
)
1275 shutdown_signal
= signal
;
1277 qemu_system_shutdown_request();
1280 void qemu_system_shutdown_request(void)
1282 shutdown_requested
= 1;
1283 qemu_notify_event();
1286 void qemu_system_powerdown_request(void)
1288 powerdown_requested
= 1;
1289 qemu_notify_event();
1292 void qemu_system_debug_request(void)
1294 debug_requested
= 1;
1295 qemu_notify_event();
1298 void qemu_system_vmstop_request(int reason
)
1300 vmstop_requested
= reason
;
1301 qemu_notify_event();
1304 void main_loop_wait(int nonblocking
)
1306 fd_set rfds
, wfds
, xfds
;
1314 timeout
= qemu_calculate_timeout();
1315 qemu_bh_update_timeout(&timeout
);
1318 os_host_main_loop_wait(&timeout
);
1320 tv
.tv_sec
= timeout
/ 1000;
1321 tv
.tv_usec
= (timeout
% 1000) * 1000;
1323 /* poll any events */
1324 /* XXX: separate device handlers from system ones */
1329 qemu_iohandler_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1330 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1332 qemu_mutex_unlock_iothread();
1333 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1334 qemu_mutex_lock_iothread();
1336 qemu_iohandler_poll(&rfds
, &wfds
, &xfds
, ret
);
1337 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1339 qemu_run_all_timers();
1341 /* Check bottom-halves last in case any of the earlier events triggered
1347 #ifndef CONFIG_IOTHREAD
1348 static int vm_request_pending(void)
1350 return powerdown_requested
||
1352 shutdown_requested
||
1358 qemu_irq qemu_system_powerdown
;
1360 static void main_loop(void)
1362 bool nonblocking
= false;
1363 #ifdef CONFIG_PROFILER
1368 qemu_main_loop_start();
1371 #ifndef CONFIG_IOTHREAD
1372 nonblocking
= cpu_exec_all();
1373 if (vm_request_pending()) {
1377 #ifdef CONFIG_PROFILER
1378 ti
= profile_getclock();
1380 main_loop_wait(nonblocking
);
1381 #ifdef CONFIG_PROFILER
1382 dev_time
+= profile_getclock() - ti
;
1385 if (qemu_debug_requested()) {
1386 vm_stop(VMSTOP_DEBUG
);
1388 if (qemu_shutdown_requested()) {
1390 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1392 vm_stop(VMSTOP_SHUTDOWN
);
1397 if (qemu_reset_requested()) {
1399 cpu_synchronize_all_states();
1400 qemu_system_reset();
1403 if (qemu_powerdown_requested()) {
1404 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1405 qemu_irq_raise(qemu_system_powerdown
);
1407 if ((r
= qemu_vmstop_requested())) {
1415 static void version(void)
1417 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1420 static void help(int exitcode
)
1422 const char *options_help
=
1423 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1425 #define DEFHEADING(text) stringify(text) "\n"
1426 #include "qemu-options.def"
1432 printf("usage: %s [options] [disk_image]\n"
1434 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1437 "During emulation, the following keys are useful:\n"
1438 "ctrl-alt-f toggle full screen\n"
1439 "ctrl-alt-n switch to virtual console 'n'\n"
1440 "ctrl-alt toggle mouse and keyboard grab\n"
1442 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1448 #define HAS_ARG 0x0001
1450 typedef struct QEMUOption
{
1457 static const QEMUOption qemu_options
[] = {
1458 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1459 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1460 { option, opt_arg, opt_enum, arch_mask },
1461 #define DEFHEADING(text)
1462 #include "qemu-options.def"
1468 static void select_vgahw (const char *p
)
1473 vga_interface_type
= VGA_NONE
;
1474 if (strstart(p
, "std", &opts
)) {
1475 vga_interface_type
= VGA_STD
;
1476 } else if (strstart(p
, "cirrus", &opts
)) {
1477 vga_interface_type
= VGA_CIRRUS
;
1478 } else if (strstart(p
, "vmware", &opts
)) {
1479 vga_interface_type
= VGA_VMWARE
;
1480 } else if (strstart(p
, "xenfb", &opts
)) {
1481 vga_interface_type
= VGA_XENFB
;
1482 } else if (strstart(p
, "qxl", &opts
)) {
1483 vga_interface_type
= VGA_QXL
;
1484 } else if (!strstart(p
, "none", &opts
)) {
1486 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1490 const char *nextopt
;
1492 if (strstart(opts
, ",retrace=", &nextopt
)) {
1494 if (strstart(opts
, "dumb", &nextopt
))
1495 vga_retrace_method
= VGA_RETRACE_DUMB
;
1496 else if (strstart(opts
, "precise", &nextopt
))
1497 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1498 else goto invalid_vga
;
1499 } else goto invalid_vga
;
1504 static DisplayType
select_display(const char *p
)
1507 DisplayType display
= DT_DEFAULT
;
1509 if (strstart(p
, "sdl", &opts
)) {
1513 const char *nextopt
;
1515 if (strstart(opts
, ",frame=", &nextopt
)) {
1517 if (strstart(opts
, "on", &nextopt
)) {
1519 } else if (strstart(opts
, "off", &nextopt
)) {
1522 goto invalid_sdl_args
;
1524 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1526 if (strstart(opts
, "on", &nextopt
)) {
1528 } else if (strstart(opts
, "off", &nextopt
)) {
1531 goto invalid_sdl_args
;
1533 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1535 if (strstart(opts
, "on", &nextopt
)) {
1537 } else if (strstart(opts
, "off", &nextopt
)) {
1540 goto invalid_sdl_args
;
1542 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
1544 if (strstart(opts
, "on", &nextopt
)) {
1546 } else if (strstart(opts
, "off", &nextopt
)) {
1549 goto invalid_sdl_args
;
1553 fprintf(stderr
, "Invalid SDL option string: %s\n", p
);
1559 fprintf(stderr
, "SDL support is disabled\n");
1562 } else if (strstart(p
, "vnc", &opts
)) {
1567 const char *nextopt
;
1569 if (strstart(opts
, "=", &nextopt
)) {
1570 vnc_display
= nextopt
;
1574 fprintf(stderr
, "VNC requires a display argument vnc=<display>\n");
1578 fprintf(stderr
, "VNC support is disabled\n");
1581 } else if (strstart(p
, "curses", &opts
)) {
1582 #ifdef CONFIG_CURSES
1583 display
= DT_CURSES
;
1585 fprintf(stderr
, "Curses support is disabled\n");
1588 } else if (strstart(p
, "none", &opts
)) {
1591 fprintf(stderr
, "Unknown display type: %s\n", p
);
1598 static int balloon_parse(const char *arg
)
1602 if (strcmp(arg
, "none") == 0) {
1606 if (!strncmp(arg
, "virtio", 6)) {
1607 if (arg
[6] == ',') {
1608 /* have params -> parse them */
1609 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1613 /* create empty opts */
1614 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1616 qemu_opt_set(opts
, "driver", "virtio-balloon");
1623 char *qemu_find_file(int type
, const char *name
)
1629 /* If name contains path separators then try it as a straight path. */
1630 if ((strchr(name
, '/') || strchr(name
, '\\'))
1631 && access(name
, R_OK
) == 0) {
1632 return qemu_strdup(name
);
1635 case QEMU_FILE_TYPE_BIOS
:
1638 case QEMU_FILE_TYPE_KEYMAP
:
1639 subdir
= "keymaps/";
1644 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1645 buf
= qemu_mallocz(len
);
1646 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1647 if (access(buf
, R_OK
)) {
1654 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1656 return qdev_device_help(opts
);
1659 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1663 dev
= qdev_device_add(opts
);
1669 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1671 CharDriverState
*chr
;
1673 chr
= qemu_chr_open_opts(opts
, NULL
);
1679 #ifdef CONFIG_VIRTFS
1680 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1683 ret
= qemu_fsdev_add(opts
);
1689 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1691 CharDriverState
*chr
;
1692 const char *chardev
;
1696 mode
= qemu_opt_get(opts
, "mode");
1700 if (strcmp(mode
, "readline") == 0) {
1701 flags
= MONITOR_USE_READLINE
;
1702 } else if (strcmp(mode
, "control") == 0) {
1703 flags
= MONITOR_USE_CONTROL
;
1705 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1709 if (qemu_opt_get_bool(opts
, "pretty", 0))
1710 flags
|= MONITOR_USE_PRETTY
;
1712 if (qemu_opt_get_bool(opts
, "default", 0))
1713 flags
|= MONITOR_IS_DEFAULT
;
1715 chardev
= qemu_opt_get(opts
, "chardev");
1716 chr
= qemu_chr_find(chardev
);
1718 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1722 monitor_init(chr
, flags
);
1726 static void monitor_parse(const char *optarg
, const char *mode
)
1728 static int monitor_device_index
= 0;
1734 if (strstart(optarg
, "chardev:", &p
)) {
1735 snprintf(label
, sizeof(label
), "%s", p
);
1737 snprintf(label
, sizeof(label
), "compat_monitor%d",
1738 monitor_device_index
);
1739 if (monitor_device_index
== 0) {
1742 opts
= qemu_chr_parse_compat(label
, optarg
);
1744 fprintf(stderr
, "parse error: %s\n", optarg
);
1749 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1751 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1754 qemu_opt_set(opts
, "mode", mode
);
1755 qemu_opt_set(opts
, "chardev", label
);
1757 qemu_opt_set(opts
, "default", "on");
1758 monitor_device_index
++;
1761 struct device_config
{
1763 DEV_USB
, /* -usbdevice */
1765 DEV_SERIAL
, /* -serial */
1766 DEV_PARALLEL
, /* -parallel */
1767 DEV_VIRTCON
, /* -virtioconsole */
1768 DEV_DEBUGCON
, /* -debugcon */
1770 const char *cmdline
;
1771 QTAILQ_ENTRY(device_config
) next
;
1773 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1775 static void add_device_config(int type
, const char *cmdline
)
1777 struct device_config
*conf
;
1779 conf
= qemu_mallocz(sizeof(*conf
));
1781 conf
->cmdline
= cmdline
;
1782 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1785 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1787 struct device_config
*conf
;
1790 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1791 if (conf
->type
!= type
)
1793 rc
= func(conf
->cmdline
);
1800 static int serial_parse(const char *devname
)
1802 static int index
= 0;
1805 if (strcmp(devname
, "none") == 0)
1807 if (index
== MAX_SERIAL_PORTS
) {
1808 fprintf(stderr
, "qemu: too many serial ports\n");
1811 snprintf(label
, sizeof(label
), "serial%d", index
);
1812 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1813 if (!serial_hds
[index
]) {
1814 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1815 devname
, strerror(errno
));
1822 static int parallel_parse(const char *devname
)
1824 static int index
= 0;
1827 if (strcmp(devname
, "none") == 0)
1829 if (index
== MAX_PARALLEL_PORTS
) {
1830 fprintf(stderr
, "qemu: too many parallel ports\n");
1833 snprintf(label
, sizeof(label
), "parallel%d", index
);
1834 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1835 if (!parallel_hds
[index
]) {
1836 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1837 devname
, strerror(errno
));
1844 static int virtcon_parse(const char *devname
)
1846 QemuOptsList
*device
= qemu_find_opts("device");
1847 static int index
= 0;
1849 QemuOpts
*bus_opts
, *dev_opts
;
1851 if (strcmp(devname
, "none") == 0)
1853 if (index
== MAX_VIRTIO_CONSOLES
) {
1854 fprintf(stderr
, "qemu: too many virtio consoles\n");
1858 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1859 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1861 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1862 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1864 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1865 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1866 if (!virtcon_hds
[index
]) {
1867 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1868 devname
, strerror(errno
));
1871 qemu_opt_set(dev_opts
, "chardev", label
);
1877 static int debugcon_parse(const char *devname
)
1881 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1884 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1886 fprintf(stderr
, "qemu: already have a debugcon device\n");
1889 qemu_opt_set(opts
, "driver", "isa-debugcon");
1890 qemu_opt_set(opts
, "chardev", "debugcon");
1894 static int tcg_init(void)
1900 const char *opt_name
;
1902 int (*available
)(void);
1906 { "tcg", "tcg", tcg_available
, tcg_init
, &tcg_allowed
},
1907 { "xen", "Xen", xen_available
, xen_init
, &xen_allowed
},
1908 { "kvm", "KVM", kvm_available
, kvm_init
, &kvm_allowed
},
1911 static int configure_accelerator(void)
1913 const char *p
= NULL
;
1916 bool accel_initalised
= 0;
1917 bool init_failed
= 0;
1919 QemuOptsList
*list
= qemu_find_opts("machine");
1920 if (!QTAILQ_EMPTY(&list
->head
)) {
1921 p
= qemu_opt_get(QTAILQ_FIRST(&list
->head
), "accel");
1925 /* Use the default "accelerator", tcg */
1929 while (!accel_initalised
&& *p
!= '\0') {
1933 p
= get_opt_name(buf
, sizeof (buf
), p
, ':');
1934 for (i
= 0; i
< ARRAY_SIZE(accel_list
); i
++) {
1935 if (strcmp(accel_list
[i
].opt_name
, buf
) == 0) {
1936 ret
= accel_list
[i
].init();
1939 if (!accel_list
[i
].available()) {
1940 printf("%s not supported for this target\n",
1941 accel_list
[i
].name
);
1943 fprintf(stderr
, "failed to initialize %s: %s\n",
1948 accel_initalised
= 1;
1949 *(accel_list
[i
].allowed
) = 1;
1954 if (i
== ARRAY_SIZE(accel_list
)) {
1955 fprintf(stderr
, "\"%s\" accelerator does not exist.\n", buf
);
1959 if (!accel_initalised
) {
1960 fprintf(stderr
, "No accelerator found!\n");
1965 fprintf(stderr
, "Back to %s accelerator.\n", accel_list
[i
].name
);
1968 return !accel_initalised
;
1971 void qemu_add_exit_notifier(Notifier
*notify
)
1973 notifier_list_add(&exit_notifiers
, notify
);
1976 void qemu_remove_exit_notifier(Notifier
*notify
)
1978 notifier_list_remove(&exit_notifiers
, notify
);
1981 static void qemu_run_exit_notifiers(void)
1983 notifier_list_notify(&exit_notifiers
);
1986 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
1988 notifier_list_add(&machine_init_done_notifiers
, notify
);
1991 static void qemu_run_machine_init_done_notifiers(void)
1993 notifier_list_notify(&machine_init_done_notifiers
);
1996 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1997 const char **poptarg
, int *poptind
)
1999 const QEMUOption
*popt
;
2000 int optind
= *poptind
;
2001 char *r
= argv
[optind
];
2004 loc_set_cmdline(argv
, optind
, 1);
2006 /* Treat --foo the same as -foo. */
2009 popt
= qemu_options
;
2012 error_report("invalid option");
2015 if (!strcmp(popt
->name
, r
+ 1))
2019 if (popt
->flags
& HAS_ARG
) {
2020 if (optind
>= argc
) {
2021 error_report("requires an argument");
2024 optarg
= argv
[optind
++];
2025 loc_set_cmdline(argv
, optind
- 2, 2);
2036 int main(int argc
, char **argv
, char **envp
)
2038 const char *gdbstub_dev
= NULL
;
2040 int snapshot
, linux_boot
;
2041 const char *icount_option
= NULL
;
2042 const char *initrd_filename
;
2043 const char *kernel_filename
, *kernel_cmdline
;
2044 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
2046 DisplayChangeListener
*dcl
;
2047 int cyls
, heads
, secs
, translation
;
2048 QemuOpts
*hda_opts
= NULL
, *opts
;
2049 QemuOptsList
*olist
;
2052 const char *loadvm
= NULL
;
2053 QEMUMachine
*machine
;
2054 const char *cpu_model
;
2056 const char *pid_file
= NULL
;
2057 const char *incoming
= NULL
;
2059 int show_vnc_port
= 0;
2062 const char *trace_file
= NULL
;
2064 atexit(qemu_run_exit_notifiers
);
2065 error_set_progname(argv
[0]);
2069 qemu_cache_utils_init(envp
);
2071 QLIST_INIT (&vm_change_state_head
);
2072 os_setup_early_signal_handling();
2074 module_call_init(MODULE_INIT_MACHINE
);
2075 machine
= find_default_machine();
2077 initrd_filename
= NULL
;
2080 kernel_filename
= NULL
;
2081 kernel_cmdline
= "";
2082 cyls
= heads
= secs
= 0;
2083 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2085 for (i
= 0; i
< MAX_NODES
; i
++) {
2087 node_cpumask
[i
] = 0;
2096 /* first pass of option parsing */
2098 while (optind
< argc
) {
2099 if (argv
[optind
][0] != '-') {
2104 const QEMUOption
*popt
;
2106 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2107 switch (popt
->index
) {
2108 case QEMU_OPTION_nodefconfig
:
2118 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2119 if (ret
< 0 && ret
!= -ENOENT
) {
2123 ret
= qemu_read_config_file(arch_config_name
);
2124 if (ret
< 0 && ret
!= -ENOENT
) {
2130 /* second pass of option parsing */
2135 if (argv
[optind
][0] != '-') {
2136 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2138 const QEMUOption
*popt
;
2140 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2141 if (!(popt
->arch_mask
& arch_type
)) {
2142 printf("Option %s not supported for this target\n", popt
->name
);
2145 switch(popt
->index
) {
2147 machine
= find_machine(optarg
);
2150 printf("Supported machines are:\n");
2151 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
2153 printf("%-10s %s (alias of %s)\n",
2154 m
->alias
, m
->desc
, m
->name
);
2155 printf("%-10s %s%s\n",
2157 m
->is_default
? " (default)" : "");
2159 exit(*optarg
!= '?');
2162 case QEMU_OPTION_cpu
:
2163 /* hw initialization will check this */
2164 if (*optarg
== '?') {
2165 list_cpus(stdout
, &fprintf
, optarg
);
2171 case QEMU_OPTION_initrd
:
2172 initrd_filename
= optarg
;
2174 case QEMU_OPTION_hda
:
2178 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
2180 snprintf(buf
, sizeof(buf
),
2181 "%s,cyls=%d,heads=%d,secs=%d%s",
2182 HD_OPTS
, cyls
, heads
, secs
,
2183 translation
== BIOS_ATA_TRANSLATION_LBA
?
2185 translation
== BIOS_ATA_TRANSLATION_NONE
?
2186 ",trans=none" : "");
2187 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
2190 case QEMU_OPTION_hdb
:
2191 case QEMU_OPTION_hdc
:
2192 case QEMU_OPTION_hdd
:
2193 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2196 case QEMU_OPTION_drive
:
2197 if (drive_def(optarg
) == NULL
) {
2201 case QEMU_OPTION_set
:
2202 if (qemu_set_option(optarg
) != 0)
2205 case QEMU_OPTION_global
:
2206 if (qemu_global_option(optarg
) != 0)
2209 case QEMU_OPTION_mtdblock
:
2210 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2212 case QEMU_OPTION_sd
:
2213 drive_add(IF_SD
, 0, optarg
, SD_OPTS
);
2215 case QEMU_OPTION_pflash
:
2216 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2218 case QEMU_OPTION_snapshot
:
2221 case QEMU_OPTION_hdachs
:
2225 cyls
= strtol(p
, (char **)&p
, 0);
2226 if (cyls
< 1 || cyls
> 16383)
2231 heads
= strtol(p
, (char **)&p
, 0);
2232 if (heads
< 1 || heads
> 16)
2237 secs
= strtol(p
, (char **)&p
, 0);
2238 if (secs
< 1 || secs
> 63)
2242 if (!strcmp(p
, "none"))
2243 translation
= BIOS_ATA_TRANSLATION_NONE
;
2244 else if (!strcmp(p
, "lba"))
2245 translation
= BIOS_ATA_TRANSLATION_LBA
;
2246 else if (!strcmp(p
, "auto"))
2247 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2250 } else if (*p
!= '\0') {
2252 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2255 if (hda_opts
!= NULL
) {
2257 snprintf(num
, sizeof(num
), "%d", cyls
);
2258 qemu_opt_set(hda_opts
, "cyls", num
);
2259 snprintf(num
, sizeof(num
), "%d", heads
);
2260 qemu_opt_set(hda_opts
, "heads", num
);
2261 snprintf(num
, sizeof(num
), "%d", secs
);
2262 qemu_opt_set(hda_opts
, "secs", num
);
2263 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2264 qemu_opt_set(hda_opts
, "trans", "lba");
2265 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2266 qemu_opt_set(hda_opts
, "trans", "none");
2270 case QEMU_OPTION_numa
:
2271 if (nb_numa_nodes
>= MAX_NODES
) {
2272 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2277 case QEMU_OPTION_display
:
2278 display_type
= select_display(optarg
);
2280 case QEMU_OPTION_nographic
:
2281 display_type
= DT_NOGRAPHIC
;
2283 case QEMU_OPTION_curses
:
2284 #ifdef CONFIG_CURSES
2285 display_type
= DT_CURSES
;
2287 fprintf(stderr
, "Curses support is disabled\n");
2291 case QEMU_OPTION_portrait
:
2294 case QEMU_OPTION_kernel
:
2295 kernel_filename
= optarg
;
2297 case QEMU_OPTION_append
:
2298 kernel_cmdline
= optarg
;
2300 case QEMU_OPTION_cdrom
:
2301 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2303 case QEMU_OPTION_boot
:
2305 static const char * const params
[] = {
2306 "order", "once", "menu", NULL
2308 char buf
[sizeof(boot_devices
)];
2309 char *standard_boot_devices
;
2312 if (!strchr(optarg
, '=')) {
2314 pstrcpy(buf
, sizeof(buf
), optarg
);
2315 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2317 "qemu: unknown boot parameter '%s' in '%s'\n",
2323 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2324 validate_bootdevices(buf
);
2325 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2328 if (get_param_value(buf
, sizeof(buf
),
2330 validate_bootdevices(buf
);
2331 standard_boot_devices
= qemu_strdup(boot_devices
);
2332 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2333 qemu_register_reset(restore_boot_devices
,
2334 standard_boot_devices
);
2336 if (get_param_value(buf
, sizeof(buf
),
2338 if (!strcmp(buf
, "on")) {
2340 } else if (!strcmp(buf
, "off")) {
2344 "qemu: invalid option value '%s'\n",
2352 case QEMU_OPTION_fda
:
2353 case QEMU_OPTION_fdb
:
2354 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2357 case QEMU_OPTION_no_fd_bootchk
:
2360 case QEMU_OPTION_netdev
:
2361 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2365 case QEMU_OPTION_net
:
2366 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2371 case QEMU_OPTION_tftp
:
2372 legacy_tftp_prefix
= optarg
;
2374 case QEMU_OPTION_bootp
:
2375 legacy_bootp_filename
= optarg
;
2377 case QEMU_OPTION_redir
:
2378 if (net_slirp_redir(optarg
) < 0)
2382 case QEMU_OPTION_bt
:
2383 add_device_config(DEV_BT
, optarg
);
2385 case QEMU_OPTION_audio_help
:
2386 if (!(audio_available())) {
2387 printf("Option %s not supported for this target\n", popt
->name
);
2393 case QEMU_OPTION_soundhw
:
2394 if (!(audio_available())) {
2395 printf("Option %s not supported for this target\n", popt
->name
);
2398 select_soundhw (optarg
);
2403 case QEMU_OPTION_version
:
2407 case QEMU_OPTION_m
: {
2410 value
= strtosz(optarg
, NULL
);
2412 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2416 /* On 32-bit hosts, QEMU is limited by virtual address space */
2417 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2418 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2421 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2422 fprintf(stderr
, "qemu: ram size too large\n");
2428 case QEMU_OPTION_mempath
:
2432 case QEMU_OPTION_mem_prealloc
:
2437 set_cpu_log(optarg
);
2440 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2442 case QEMU_OPTION_gdb
:
2443 gdbstub_dev
= optarg
;
2448 case QEMU_OPTION_bios
:
2451 case QEMU_OPTION_singlestep
:
2458 keyboard_layout
= optarg
;
2460 case QEMU_OPTION_localtime
:
2463 case QEMU_OPTION_vga
:
2464 select_vgahw (optarg
);
2471 w
= strtol(p
, (char **)&p
, 10);
2474 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2480 h
= strtol(p
, (char **)&p
, 10);
2485 depth
= strtol(p
, (char **)&p
, 10);
2486 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2487 depth
!= 24 && depth
!= 32)
2489 } else if (*p
== '\0') {
2490 depth
= graphic_depth
;
2497 graphic_depth
= depth
;
2500 case QEMU_OPTION_echr
:
2503 term_escape_char
= strtol(optarg
, &r
, 0);
2505 printf("Bad argument to echr\n");
2508 case QEMU_OPTION_monitor
:
2509 monitor_parse(optarg
, "readline");
2510 default_monitor
= 0;
2512 case QEMU_OPTION_qmp
:
2513 monitor_parse(optarg
, "control");
2514 default_monitor
= 0;
2516 case QEMU_OPTION_mon
:
2517 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2521 default_monitor
= 0;
2523 case QEMU_OPTION_chardev
:
2524 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2529 case QEMU_OPTION_fsdev
:
2530 olist
= qemu_find_opts("fsdev");
2532 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2535 opts
= qemu_opts_parse(olist
, optarg
, 1);
2537 fprintf(stderr
, "parse error: %s\n", optarg
);
2541 case QEMU_OPTION_virtfs
: {
2545 olist
= qemu_find_opts("virtfs");
2547 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2550 opts
= qemu_opts_parse(olist
, optarg
, 1);
2552 fprintf(stderr
, "parse error: %s\n", optarg
);
2556 if (qemu_opt_get(opts
, "fstype") == NULL
||
2557 qemu_opt_get(opts
, "mount_tag") == NULL
||
2558 qemu_opt_get(opts
, "path") == NULL
||
2559 qemu_opt_get(opts
, "security_model") == NULL
) {
2560 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2561 "security_model=[mapped|passthrough|none],"
2562 "mount_tag=tag.\n");
2566 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
2567 qemu_opt_get(opts
, "mount_tag"), 1);
2569 fprintf(stderr
, "duplicate fsdev id: %s\n",
2570 qemu_opt_get(opts
, "mount_tag"));
2573 qemu_opt_set(fsdev
, "fstype", qemu_opt_get(opts
, "fstype"));
2574 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"));
2575 qemu_opt_set(fsdev
, "security_model",
2576 qemu_opt_get(opts
, "security_model"));
2578 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
2579 qemu_opt_set(device
, "driver", "virtio-9p-pci");
2580 qemu_opt_set(device
, "fsdev",
2581 qemu_opt_get(opts
, "mount_tag"));
2582 qemu_opt_set(device
, "mount_tag",
2583 qemu_opt_get(opts
, "mount_tag"));
2586 case QEMU_OPTION_serial
:
2587 add_device_config(DEV_SERIAL
, optarg
);
2589 if (strncmp(optarg
, "mon:", 4) == 0) {
2590 default_monitor
= 0;
2593 case QEMU_OPTION_watchdog
:
2596 "qemu: only one watchdog option may be given\n");
2601 case QEMU_OPTION_watchdog_action
:
2602 if (select_watchdog_action(optarg
) == -1) {
2603 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2607 case QEMU_OPTION_virtiocon
:
2608 add_device_config(DEV_VIRTCON
, optarg
);
2609 default_virtcon
= 0;
2610 if (strncmp(optarg
, "mon:", 4) == 0) {
2611 default_monitor
= 0;
2614 case QEMU_OPTION_parallel
:
2615 add_device_config(DEV_PARALLEL
, optarg
);
2616 default_parallel
= 0;
2617 if (strncmp(optarg
, "mon:", 4) == 0) {
2618 default_monitor
= 0;
2621 case QEMU_OPTION_debugcon
:
2622 add_device_config(DEV_DEBUGCON
, optarg
);
2624 case QEMU_OPTION_loadvm
:
2627 case QEMU_OPTION_full_screen
:
2631 case QEMU_OPTION_no_frame
:
2634 case QEMU_OPTION_alt_grab
:
2637 case QEMU_OPTION_ctrl_grab
:
2640 case QEMU_OPTION_no_quit
:
2643 case QEMU_OPTION_sdl
:
2644 display_type
= DT_SDL
;
2647 case QEMU_OPTION_no_frame
:
2648 case QEMU_OPTION_alt_grab
:
2649 case QEMU_OPTION_ctrl_grab
:
2650 case QEMU_OPTION_no_quit
:
2651 case QEMU_OPTION_sdl
:
2652 fprintf(stderr
, "SDL support is disabled\n");
2655 case QEMU_OPTION_pidfile
:
2658 case QEMU_OPTION_win2k_hack
:
2659 win2k_install_hack
= 1;
2661 case QEMU_OPTION_rtc_td_hack
:
2664 case QEMU_OPTION_acpitable
:
2665 do_acpitable_option(optarg
);
2667 case QEMU_OPTION_smbios
:
2668 do_smbios_option(optarg
);
2670 case QEMU_OPTION_enable_kvm
:
2671 olist
= qemu_find_opts("machine");
2672 qemu_opts_reset(olist
);
2673 qemu_opts_parse(olist
, "accel=kvm", 0);
2675 case QEMU_OPTION_machine
:
2676 olist
= qemu_find_opts("machine");
2677 qemu_opts_reset(olist
);
2678 opts
= qemu_opts_parse(olist
, optarg
, 0);
2680 fprintf(stderr
, "parse error: %s\n", optarg
);
2684 case QEMU_OPTION_usb
:
2687 case QEMU_OPTION_usbdevice
:
2689 add_device_config(DEV_USB
, optarg
);
2691 case QEMU_OPTION_device
:
2692 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2696 case QEMU_OPTION_smp
:
2699 fprintf(stderr
, "Invalid number of CPUs\n");
2702 if (max_cpus
< smp_cpus
) {
2703 fprintf(stderr
, "maxcpus must be equal to or greater than "
2707 if (max_cpus
> 255) {
2708 fprintf(stderr
, "Unsupported number of maxcpus\n");
2712 case QEMU_OPTION_vnc
:
2715 vnc_display
= optarg
;
2717 fprintf(stderr
, "VNC support is disabled\n");
2721 case QEMU_OPTION_no_acpi
:
2724 case QEMU_OPTION_no_hpet
:
2727 case QEMU_OPTION_balloon
:
2728 if (balloon_parse(optarg
) < 0) {
2729 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2733 case QEMU_OPTION_no_reboot
:
2736 case QEMU_OPTION_no_shutdown
:
2739 case QEMU_OPTION_show_cursor
:
2742 case QEMU_OPTION_uuid
:
2743 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2744 fprintf(stderr
, "Fail to parse UUID string."
2745 " Wrong format.\n");
2749 case QEMU_OPTION_option_rom
:
2750 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2751 fprintf(stderr
, "Too many option ROMs\n");
2754 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
2755 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
2756 option_rom
[nb_option_roms
].bootindex
=
2757 qemu_opt_get_number(opts
, "bootindex", -1);
2758 if (!option_rom
[nb_option_roms
].name
) {
2759 fprintf(stderr
, "Option ROM file is not specified\n");
2764 case QEMU_OPTION_semihosting
:
2765 semihosting_enabled
= 1;
2767 case QEMU_OPTION_name
:
2768 qemu_name
= qemu_strdup(optarg
);
2770 char *p
= strchr(qemu_name
, ',');
2773 if (strncmp(p
, "process=", 8)) {
2774 fprintf(stderr
, "Unknown subargument %s to -name\n", p
);
2778 os_set_proc_name(p
);
2782 case QEMU_OPTION_prom_env
:
2783 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2784 fprintf(stderr
, "Too many prom variables\n");
2787 prom_envs
[nb_prom_envs
] = optarg
;
2790 case QEMU_OPTION_old_param
:
2793 case QEMU_OPTION_clock
:
2794 configure_alarms(optarg
);
2796 case QEMU_OPTION_startdate
:
2797 configure_rtc_date_offset(optarg
, 1);
2799 case QEMU_OPTION_rtc
:
2800 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2804 configure_rtc(opts
);
2806 case QEMU_OPTION_tb_size
:
2807 tb_size
= strtol(optarg
, NULL
, 0);
2811 case QEMU_OPTION_icount
:
2812 icount_option
= optarg
;
2814 case QEMU_OPTION_incoming
:
2816 incoming_expected
= true;
2818 case QEMU_OPTION_nodefaults
:
2820 default_parallel
= 0;
2821 default_virtcon
= 0;
2822 default_monitor
= 0;
2829 case QEMU_OPTION_xen_domid
:
2830 if (!(xen_available())) {
2831 printf("Option %s not supported for this target\n", popt
->name
);
2834 xen_domid
= atoi(optarg
);
2836 case QEMU_OPTION_xen_create
:
2837 if (!(xen_available())) {
2838 printf("Option %s not supported for this target\n", popt
->name
);
2841 xen_mode
= XEN_CREATE
;
2843 case QEMU_OPTION_xen_attach
:
2844 if (!(xen_available())) {
2845 printf("Option %s not supported for this target\n", popt
->name
);
2848 xen_mode
= XEN_ATTACH
;
2850 #ifdef CONFIG_SIMPLE_TRACE
2851 case QEMU_OPTION_trace
:
2852 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2854 trace_file
= qemu_opt_get(opts
, "file");
2858 case QEMU_OPTION_readconfig
:
2860 int ret
= qemu_read_config_file(optarg
);
2862 fprintf(stderr
, "read config %s: %s\n", optarg
,
2868 case QEMU_OPTION_spice
:
2869 olist
= qemu_find_opts("spice");
2871 fprintf(stderr
, "spice is not supported by this qemu build.\n");
2874 opts
= qemu_opts_parse(olist
, optarg
, 0);
2876 fprintf(stderr
, "parse error: %s\n", optarg
);
2880 case QEMU_OPTION_writeconfig
:
2883 if (strcmp(optarg
, "-") == 0) {
2886 fp
= fopen(optarg
, "w");
2888 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2892 qemu_config_write(fp
);
2897 os_parse_cmd_args(popt
->index
, optarg
);
2903 if (!st_init(trace_file
)) {
2904 fprintf(stderr
, "warning: unable to initialize simple trace backend\n");
2907 /* If no data_dir is specified then try to find it relative to the
2910 data_dir
= os_find_datadir(argv
[0]);
2912 /* If all else fails use the install patch specified when building. */
2914 data_dir
= CONFIG_QEMU_DATADIR
;
2918 * Default to max_cpus = smp_cpus, in case the user doesn't
2919 * specify a max_cpus value.
2922 max_cpus
= smp_cpus
;
2924 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2925 if (smp_cpus
> machine
->max_cpus
) {
2926 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2927 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2933 * Get the default machine options from the machine if it is not already
2934 * specified either by the configuration file or by the command line.
2936 if (machine
->default_machine_opts
) {
2937 QemuOptsList
*list
= qemu_find_opts("machine");
2938 const char *p
= NULL
;
2940 if (!QTAILQ_EMPTY(&list
->head
)) {
2941 p
= qemu_opt_get(QTAILQ_FIRST(&list
->head
), "accel");
2944 opts
= qemu_opts_parse(qemu_find_opts("machine"),
2945 machine
->default_machine_opts
, 0);
2947 fprintf(stderr
, "parse error for machine %s: %s\n",
2948 machine
->name
, machine
->default_machine_opts
);
2954 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2955 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2957 if (machine
->no_serial
) {
2960 if (machine
->no_parallel
) {
2961 default_parallel
= 0;
2963 if (!machine
->use_virtcon
) {
2964 default_virtcon
= 0;
2966 if (machine
->no_vga
) {
2969 if (machine
->no_floppy
) {
2972 if (machine
->no_cdrom
) {
2975 if (machine
->no_sdcard
) {
2979 if (display_type
== DT_NOGRAPHIC
) {
2980 if (default_parallel
)
2981 add_device_config(DEV_PARALLEL
, "null");
2982 if (default_serial
&& default_monitor
) {
2983 add_device_config(DEV_SERIAL
, "mon:stdio");
2984 } else if (default_virtcon
&& default_monitor
) {
2985 add_device_config(DEV_VIRTCON
, "mon:stdio");
2988 add_device_config(DEV_SERIAL
, "stdio");
2989 if (default_virtcon
)
2990 add_device_config(DEV_VIRTCON
, "stdio");
2991 if (default_monitor
)
2992 monitor_parse("stdio", "readline");
2996 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2997 if (default_parallel
)
2998 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2999 if (default_monitor
)
3000 monitor_parse("vc:80Cx24C", "readline");
3001 if (default_virtcon
)
3002 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
3005 vga_interface_type
= VGA_CIRRUS
;
3009 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
3011 #ifdef CONFIG_VIRTFS
3012 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
3019 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
3024 configure_accelerator();
3026 if (qemu_init_main_loop()) {
3027 fprintf(stderr
, "qemu_init_main_loop failed\n");
3030 linux_boot
= (kernel_filename
!= NULL
);
3032 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
3033 fprintf(stderr
, "-append only allowed with -kernel option\n");
3037 if (!linux_boot
&& initrd_filename
!= NULL
) {
3038 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
3042 os_set_line_buffering();
3044 if (init_timer_alarm() < 0) {
3045 fprintf(stderr
, "could not initialize alarm timer\n");
3048 configure_icount(icount_option
);
3050 if (net_init_clients() < 0) {
3054 /* init the bluetooth world */
3055 if (foreach_device_config(DEV_BT
, bt_parse
))
3058 /* init the memory */
3060 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
3062 /* init the dynamic translator */
3063 cpu_exec_init_all(tb_size
* 1024 * 1024);
3065 bdrv_init_with_whitelist();
3069 /* open the virtual block devices */
3071 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
3072 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
3075 default_drive(default_cdrom
, snapshot
, machine
->use_scsi
,
3076 IF_DEFAULT
, 2, CDROM_OPTS
);
3077 default_drive(default_floppy
, snapshot
, machine
->use_scsi
,
3078 IF_FLOPPY
, 0, FD_OPTS
);
3079 default_drive(default_sdcard
, snapshot
, machine
->use_scsi
,
3082 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
3085 if (nb_numa_nodes
> 0) {
3088 if (nb_numa_nodes
> smp_cpus
) {
3089 nb_numa_nodes
= smp_cpus
;
3092 /* If no memory size if given for any node, assume the default case
3093 * and distribute the available memory equally across all nodes
3095 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3096 if (node_mem
[i
] != 0)
3099 if (i
== nb_numa_nodes
) {
3100 uint64_t usedmem
= 0;
3102 /* On Linux, the each node's border has to be 8MB aligned,
3103 * the final node gets the rest.
3105 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
3106 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
3107 usedmem
+= node_mem
[i
];
3109 node_mem
[i
] = ram_size
- usedmem
;
3112 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3113 if (node_cpumask
[i
] != 0)
3116 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3117 * must cope with this anyway, because there are BIOSes out there in
3118 * real machines which also use this scheme.
3120 if (i
== nb_numa_nodes
) {
3121 for (i
= 0; i
< smp_cpus
; i
++) {
3122 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
3127 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
3131 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
3133 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
3135 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
3137 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
3140 module_call_init(MODULE_INIT_DEVICE
);
3142 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
3146 i
= select_watchdog(watchdog
);
3148 exit (i
== 1 ? 1 : 0);
3151 if (machine
->compat_props
) {
3152 qdev_prop_register_global_list(machine
->compat_props
);
3156 machine
->init(ram_size
, boot_devices
,
3157 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
3159 cpu_synchronize_all_post_init();
3163 current_machine
= machine
;
3165 /* init USB devices */
3167 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
3171 /* init generic devices */
3172 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3175 net_check_clients();
3177 /* just use the first displaystate for the moment */
3178 ds
= get_displaystate();
3182 if (display_type
== DT_DEFAULT
&& !display_remote
) {
3183 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3184 display_type
= DT_SDL
;
3185 #elif defined(CONFIG_VNC)
3186 vnc_display
= "localhost:0,to=99";
3189 display_type
= DT_NONE
;
3194 /* init local displays */
3195 switch (display_type
) {
3198 #if defined(CONFIG_CURSES)
3200 curses_display_init(ds
, full_screen
);
3203 #if defined(CONFIG_SDL)
3205 sdl_display_init(ds
, full_screen
, no_frame
);
3207 #elif defined(CONFIG_COCOA)
3209 cocoa_display_init(ds
, full_screen
);
3216 /* must be after terminal init, SDL library changes signal handlers */
3217 os_setup_signal_handling();
3220 /* init remote displays */
3222 vnc_display_init(ds
);
3223 if (vnc_display_open(ds
, vnc_display
) < 0)
3226 if (show_vnc_port
) {
3227 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3232 if (using_spice
&& !qxl_enabled
) {
3233 qemu_spice_display_init(ds
);
3239 dcl
= ds
->listeners
;
3240 while (dcl
!= NULL
) {
3241 if (dcl
->dpy_refresh
!= NULL
) {
3242 ds
->gui_timer
= qemu_new_timer_ms(rt_clock
, gui_update
, ds
);
3243 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock_ms(rt_clock
));
3248 if (ds
->gui_timer
== NULL
) {
3249 nographic_timer
= qemu_new_timer_ms(rt_clock
, nographic_update
, NULL
);
3250 qemu_mod_timer(nographic_timer
, qemu_get_clock_ms(rt_clock
));
3252 text_consoles_set_display(ds
);
3254 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3255 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3260 qdev_machine_creation_done();
3262 if (rom_load_all() != 0) {
3263 fprintf(stderr
, "rom loading failed\n");
3267 /* TODO: once all bus devices are qdevified, this should be done
3268 * when bus is created by qdev.c */
3269 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
3270 qemu_run_machine_init_done_notifiers();
3272 qemu_system_reset();
3274 if (load_vmstate(loadvm
) < 0) {
3280 int ret
= qemu_start_incoming_migration(incoming
);
3282 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3286 } else if (autostart
) {