4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 /* Needed early for CONFIG_BSD etc. */
33 #include "config-host.h"
37 #include <sys/times.h>
41 #include <sys/ioctl.h>
42 #include <sys/resource.h>
43 #include <sys/socket.h>
44 #include <netinet/in.h>
46 #include <arpa/inet.h>
49 #include <sys/select.h>
50 #ifdef CONFIG_SIMPLE_TRACE
56 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
58 #include <sys/sysctl.h>
67 #include <linux/ppdev.h>
68 #include <linux/parport.h>
72 #include <sys/ethernet.h>
73 #include <sys/sockio.h>
74 #include <netinet/arp.h>
75 #include <netinet/in_systm.h>
76 #include <netinet/ip.h>
77 #include <netinet/ip_icmp.h> // must come after ip.h
78 #include <netinet/udp.h>
79 #include <netinet/tcp.h>
87 #if defined(__OpenBSD__)
91 #if defined(CONFIG_VDE)
92 #include <libvdeplug.h>
100 #if defined(__APPLE__) || defined(main)
102 int qemu_main(int argc
, char **argv
, char **envp
);
103 int main(int argc
, char **argv
)
105 return qemu_main(argc
, argv
, NULL
);
108 #define main qemu_main
110 #endif /* CONFIG_SDL */
114 #define main qemu_main
115 #endif /* CONFIG_COCOA */
118 #include "hw/boards.h"
120 #include "hw/pcmcia.h"
125 #include "hw/watchdog.h"
126 #include "hw/smbios.h"
129 #include "hw/loader.h"
132 #include "net/slirp.h"
137 #include "qemu-timer.h"
138 #include "qemu-char.h"
139 #include "cache-utils.h"
141 #include "blockdev.h"
142 #include "block-migration.h"
144 #include "audio/audio.h"
145 #include "migration.h"
147 #include "qemu-option.h"
148 #include "qemu-config.h"
149 #include "qemu-objects.h"
150 #include "qemu-options.h"
152 #include "fsdev/qemu-fsdev.h"
157 #include "qemu_socket.h"
159 #include "slirp/libslirp.h"
162 #include "qemu-queue.h"
164 #include "arch_init.h"
166 #include "ui/qemu-spice.h"
169 //#define DEBUG_SLIRP
171 #define DEFAULT_RAM_SIZE 128
173 #define MAX_VIRTIO_CONSOLES 1
175 static const char *data_dir
;
176 const char *bios_name
= NULL
;
177 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
178 DisplayType display_type
= DT_DEFAULT
;
179 int display_remote
= 0;
180 const char* keyboard_layout
= NULL
;
182 const char *mem_path
= NULL
;
184 int mem_prealloc
= 0; /* force preallocation of physical target memory */
187 NICInfo nd_table
[MAX_NICS
];
190 int incoming_expected
; /* Started with -incoming and waiting for incoming */
191 static int rtc_utc
= 1;
192 static int rtc_date_offset
= -1; /* -1 means no change */
193 QEMUClock
*rtc_clock
;
194 int vga_interface_type
= VGA_NONE
;
195 static int full_screen
= 0;
197 static int no_frame
= 0;
200 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
201 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
202 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
203 int win2k_install_hack
= 0;
211 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
);
262 enum xen_mode xen_mode
= XEN_EMULATE
;
264 static int default_serial
= 1;
265 static int default_parallel
= 1;
266 static int default_virtcon
= 1;
267 static int default_monitor
= 1;
268 static int default_vga
= 1;
269 static int default_floppy
= 1;
270 static int default_cdrom
= 1;
271 static int default_sdcard
= 1;
277 { .driver
= "isa-serial", .flag
= &default_serial
},
278 { .driver
= "isa-parallel", .flag
= &default_parallel
},
279 { .driver
= "isa-fdc", .flag
= &default_floppy
},
280 { .driver
= "ide-drive", .flag
= &default_cdrom
},
281 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
282 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
283 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
284 { .driver
= "VGA", .flag
= &default_vga
},
285 { .driver
= "cirrus-vga", .flag
= &default_vga
},
286 { .driver
= "vmware-svga", .flag
= &default_vga
},
289 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
291 const char *driver
= qemu_opt_get(opts
, "driver");
296 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
297 if (strcmp(default_list
[i
].driver
, driver
) != 0)
299 *(default_list
[i
].flag
) = 0;
304 /***********************************************************/
305 /* real time host monotonic timer */
307 /***********************************************************/
308 /* host time/date access */
309 void qemu_get_timedate(struct tm
*tm
, int offset
)
316 if (rtc_date_offset
== -1) {
320 ret
= localtime(&ti
);
322 ti
-= rtc_date_offset
;
326 memcpy(tm
, ret
, sizeof(struct tm
));
329 int qemu_timedate_diff(struct tm
*tm
)
333 if (rtc_date_offset
== -1)
335 seconds
= mktimegm(tm
);
337 seconds
= mktime(tm
);
339 seconds
= mktimegm(tm
) + rtc_date_offset
;
341 return seconds
- time(NULL
);
344 void rtc_change_mon_event(struct tm
*tm
)
348 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
349 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
350 qobject_decref(data
);
353 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
355 time_t rtc_start_date
;
358 if (!strcmp(startdate
, "now") && legacy
) {
359 rtc_date_offset
= -1;
361 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
369 } else if (sscanf(startdate
, "%d-%d-%d",
381 rtc_start_date
= mktimegm(&tm
);
382 if (rtc_start_date
== -1) {
384 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
385 "'2006-06-17T16:01:21' or '2006-06-17'\n");
388 rtc_date_offset
= time(NULL
) - rtc_start_date
;
392 static void configure_rtc(QemuOpts
*opts
)
396 value
= qemu_opt_get(opts
, "base");
398 if (!strcmp(value
, "utc")) {
400 } else if (!strcmp(value
, "localtime")) {
403 configure_rtc_date_offset(value
, 0);
406 value
= qemu_opt_get(opts
, "clock");
408 if (!strcmp(value
, "host")) {
409 rtc_clock
= host_clock
;
410 } else if (!strcmp(value
, "vm")) {
411 rtc_clock
= vm_clock
;
413 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
417 value
= qemu_opt_get(opts
, "driftfix");
419 if (!strcmp(value
, "slew")) {
421 } else if (!strcmp(value
, "none")) {
424 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
430 /***********************************************************/
431 /* Bluetooth support */
434 static struct HCIInfo
*hci_table
[MAX_NICS
];
436 static struct bt_vlan_s
{
437 struct bt_scatternet_s net
;
439 struct bt_vlan_s
*next
;
442 /* find or alloc a new bluetooth "VLAN" */
443 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
445 struct bt_vlan_s
**pvlan
, *vlan
;
446 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
450 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
452 pvlan
= &first_bt_vlan
;
453 while (*pvlan
!= NULL
)
454 pvlan
= &(*pvlan
)->next
;
459 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
463 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
468 static struct HCIInfo null_hci
= {
469 .cmd_send
= null_hci_send
,
470 .sco_send
= null_hci_send
,
471 .acl_send
= null_hci_send
,
472 .bdaddr_set
= null_hci_addr_set
,
475 struct HCIInfo
*qemu_next_hci(void)
477 if (cur_hci
== nb_hcis
)
480 return hci_table
[cur_hci
++];
483 static struct HCIInfo
*hci_init(const char *str
)
486 struct bt_scatternet_s
*vlan
= 0;
488 if (!strcmp(str
, "null"))
491 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
493 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
494 else if (!strncmp(str
, "hci", 3)) {
497 if (!strncmp(str
+ 3, ",vlan=", 6)) {
498 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
503 vlan
= qemu_find_bt_vlan(0);
505 return bt_new_hci(vlan
);
508 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
513 static int bt_hci_parse(const char *str
)
518 if (nb_hcis
>= MAX_NICS
) {
519 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
532 bdaddr
.b
[5] = 0x56 + nb_hcis
;
533 hci
->bdaddr_set(hci
, bdaddr
.b
);
535 hci_table
[nb_hcis
++] = hci
;
540 static void bt_vhci_add(int vlan_id
)
542 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
545 fprintf(stderr
, "qemu: warning: adding a VHCI to "
546 "an empty scatternet %i\n", vlan_id
);
548 bt_vhci_init(bt_new_hci(vlan
));
551 static struct bt_device_s
*bt_device_add(const char *opt
)
553 struct bt_scatternet_s
*vlan
;
555 char *endp
= strstr(opt
, ",vlan=");
556 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
559 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
562 vlan_id
= strtol(endp
+ 6, &endp
, 0);
564 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
569 vlan
= qemu_find_bt_vlan(vlan_id
);
572 fprintf(stderr
, "qemu: warning: adding a slave device to "
573 "an empty scatternet %i\n", vlan_id
);
575 if (!strcmp(devname
, "keyboard"))
576 return bt_keyboard_init(vlan
);
578 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
582 static int bt_parse(const char *opt
)
584 const char *endp
, *p
;
587 if (strstart(opt
, "hci", &endp
)) {
588 if (!*endp
|| *endp
== ',') {
590 if (!strstart(endp
, ",vlan=", 0))
593 return bt_hci_parse(opt
);
595 } else if (strstart(opt
, "vhci", &endp
)) {
596 if (!*endp
|| *endp
== ',') {
598 if (strstart(endp
, ",vlan=", &p
)) {
599 vlan
= strtol(p
, (char **) &endp
, 0);
601 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
605 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
614 } else if (strstart(opt
, "device:", &endp
))
615 return !bt_device_add(endp
);
617 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
621 /***********************************************************/
622 /* QEMU Block devices */
624 #define HD_OPTS "media=disk"
625 #define CDROM_OPTS "media=cdrom"
627 #define PFLASH_OPTS ""
631 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
633 int *use_scsi
= opaque
;
635 return drive_init(opts
, *use_scsi
) == NULL
;
638 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
640 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
641 qemu_opt_set(opts
, "snapshot", "on");
646 static void default_drive(int enable
, int snapshot
, int use_scsi
,
647 BlockInterfaceType type
, int index
,
652 if (type
== IF_DEFAULT
) {
653 type
= use_scsi
? IF_SCSI
: IF_IDE
;
656 if (!enable
|| drive_get_by_index(type
, index
)) {
660 opts
= drive_add(type
, index
, NULL
, optstr
);
662 drive_enable_snapshot(opts
, NULL
);
664 if (!drive_init(opts
, use_scsi
)) {
669 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
671 boot_set_handler
= func
;
672 boot_set_opaque
= opaque
;
675 int qemu_boot_set(const char *boot_devices
)
677 if (!boot_set_handler
) {
680 return boot_set_handler(boot_set_opaque
, boot_devices
);
683 static void validate_bootdevices(char *devices
)
685 /* We just do some generic consistency checks */
689 for (p
= devices
; *p
!= '\0'; p
++) {
690 /* Allowed boot devices are:
691 * a-b: floppy disk drives
692 * c-f: IDE disk drives
693 * g-m: machine implementation dependant drives
694 * n-p: network devices
695 * It's up to each machine implementation to check if the given boot
696 * devices match the actual hardware implementation and firmware
699 if (*p
< 'a' || *p
> 'p') {
700 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
703 if (bitmap
& (1 << (*p
- 'a'))) {
704 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
707 bitmap
|= 1 << (*p
- 'a');
711 static void restore_boot_devices(void *opaque
)
713 char *standard_boot_devices
= opaque
;
714 static int first
= 1;
716 /* Restore boot order and remove ourselves after the first boot */
722 qemu_boot_set(standard_boot_devices
);
724 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
725 qemu_free(standard_boot_devices
);
728 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
731 FWBootEntry
*node
, *i
;
737 assert(dev
!= NULL
|| suffix
!= NULL
);
739 node
= qemu_mallocz(sizeof(FWBootEntry
));
740 node
->bootindex
= bootindex
;
741 node
->suffix
= suffix
? qemu_strdup(suffix
) : NULL
;
744 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
745 if (i
->bootindex
== bootindex
) {
746 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
748 } else if (i
->bootindex
< bootindex
) {
751 QTAILQ_INSERT_BEFORE(i
, node
, link
);
754 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
758 * This function returns null terminated string that consist of new line
759 * separated device pathes.
761 * memory pointed by "size" is assigned total length of the array in bytes
764 char *get_boot_devices_list(uint32_t *size
)
770 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
771 char *devpath
= NULL
, *bootpath
;
775 devpath
= qdev_get_fw_dev_path(i
->dev
);
779 if (i
->suffix
&& devpath
) {
780 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
782 bootpath
= qemu_malloc(bootpathlen
);
783 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
785 } else if (devpath
) {
788 bootpath
= qemu_strdup(i
->suffix
);
793 list
[total
-1] = '\n';
795 len
= strlen(bootpath
) + 1;
796 list
= qemu_realloc(list
, total
+ len
);
797 memcpy(&list
[total
], bootpath
, len
);
807 static void numa_add(const char *optarg
)
811 unsigned long long value
, endvalue
;
814 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
815 if (!strcmp(option
, "node")) {
816 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
817 nodenr
= nb_numa_nodes
;
819 nodenr
= strtoull(option
, NULL
, 10);
822 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
823 node_mem
[nodenr
] = 0;
826 sval
= strtosz(option
, NULL
);
828 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
831 node_mem
[nodenr
] = sval
;
833 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
834 node_cpumask
[nodenr
] = 0;
836 value
= strtoull(option
, &endptr
, 10);
839 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
841 if (*endptr
== '-') {
842 endvalue
= strtoull(endptr
+1, &endptr
, 10);
843 if (endvalue
>= 63) {
846 "only 63 CPUs in NUMA mode supported.\n");
848 value
= (2ULL << endvalue
) - (1ULL << value
);
850 value
= 1ULL << value
;
853 node_cpumask
[nodenr
] = value
;
860 static void smp_parse(const char *optarg
)
862 int smp
, sockets
= 0, threads
= 0, cores
= 0;
866 smp
= strtoul(optarg
, &endptr
, 10);
867 if (endptr
!= optarg
) {
868 if (*endptr
== ',') {
872 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
873 sockets
= strtoull(option
, NULL
, 10);
874 if (get_param_value(option
, 128, "cores", endptr
) != 0)
875 cores
= strtoull(option
, NULL
, 10);
876 if (get_param_value(option
, 128, "threads", endptr
) != 0)
877 threads
= strtoull(option
, NULL
, 10);
878 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
879 max_cpus
= strtoull(option
, NULL
, 10);
881 /* compute missing values, prefer sockets over cores over threads */
882 if (smp
== 0 || sockets
== 0) {
883 sockets
= sockets
> 0 ? sockets
: 1;
884 cores
= cores
> 0 ? cores
: 1;
885 threads
= threads
> 0 ? threads
: 1;
887 smp
= cores
* threads
* sockets
;
891 threads
= threads
> 0 ? threads
: 1;
892 cores
= smp
/ (sockets
* threads
);
894 threads
= smp
/ (cores
* sockets
);
898 smp_cores
= cores
> 0 ? cores
: 1;
899 smp_threads
= threads
> 0 ? threads
: 1;
904 /***********************************************************/
907 static int usb_device_add(const char *devname
)
910 USBDevice
*dev
= NULL
;
915 /* drivers with .usbdevice_name entry in USBDeviceInfo */
916 dev
= usbdevice_create(devname
);
921 if (strstart(devname
, "host:", &p
)) {
922 dev
= usb_host_device_open(p
);
923 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
924 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
925 bt_new_hci(qemu_find_bt_vlan(0)));
936 static int usb_device_del(const char *devname
)
941 if (strstart(devname
, "host:", &p
))
942 return usb_host_device_close(p
);
947 p
= strchr(devname
, '.');
950 bus_num
= strtoul(devname
, NULL
, 0);
951 addr
= strtoul(p
+ 1, NULL
, 0);
953 return usb_device_delete_addr(bus_num
, addr
);
956 static int usb_parse(const char *cmdline
)
959 r
= usb_device_add(cmdline
);
961 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
966 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
968 const char *devname
= qdict_get_str(qdict
, "devname");
969 if (usb_device_add(devname
) < 0) {
970 error_report("could not add USB device '%s'", devname
);
974 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
976 const char *devname
= qdict_get_str(qdict
, "devname");
977 if (usb_device_del(devname
) < 0) {
978 error_report("could not delete USB device '%s'", devname
);
982 /***********************************************************/
985 static struct pcmcia_socket_entry_s
{
986 PCMCIASocket
*socket
;
987 struct pcmcia_socket_entry_s
*next
;
988 } *pcmcia_sockets
= 0;
990 void pcmcia_socket_register(PCMCIASocket
*socket
)
992 struct pcmcia_socket_entry_s
*entry
;
994 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
995 entry
->socket
= socket
;
996 entry
->next
= pcmcia_sockets
;
997 pcmcia_sockets
= entry
;
1000 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
1002 struct pcmcia_socket_entry_s
*entry
, **ptr
;
1004 ptr
= &pcmcia_sockets
;
1005 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
1006 if (entry
->socket
== socket
) {
1012 void pcmcia_info(Monitor
*mon
)
1014 struct pcmcia_socket_entry_s
*iter
;
1016 if (!pcmcia_sockets
)
1017 monitor_printf(mon
, "No PCMCIA sockets\n");
1019 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1020 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1021 iter
->socket
->attached
? iter
->socket
->card_string
:
1025 /***********************************************************/
1028 typedef struct IOHandlerRecord
{
1030 IOCanReadHandler
*fd_read_poll
;
1032 IOHandler
*fd_write
;
1035 /* temporary data */
1037 QLIST_ENTRY(IOHandlerRecord
) next
;
1040 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
1041 QLIST_HEAD_INITIALIZER(io_handlers
);
1044 /* XXX: fd_read_poll should be suppressed, but an API change is
1045 necessary in the character devices to suppress fd_can_read(). */
1046 int qemu_set_fd_handler2(int fd
,
1047 IOCanReadHandler
*fd_read_poll
,
1049 IOHandler
*fd_write
,
1052 IOHandlerRecord
*ioh
;
1054 if (!fd_read
&& !fd_write
) {
1055 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1056 if (ioh
->fd
== fd
) {
1062 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1066 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
1067 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
1070 ioh
->fd_read_poll
= fd_read_poll
;
1071 ioh
->fd_read
= fd_read
;
1072 ioh
->fd_write
= fd_write
;
1073 ioh
->opaque
= opaque
;
1079 int qemu_set_fd_handler(int fd
,
1081 IOHandler
*fd_write
,
1084 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
1087 /***********************************************************/
1088 /* machine registration */
1090 static QEMUMachine
*first_machine
= NULL
;
1091 QEMUMachine
*current_machine
= NULL
;
1093 int qemu_register_machine(QEMUMachine
*m
)
1096 pm
= &first_machine
;
1104 static QEMUMachine
*find_machine(const char *name
)
1108 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1109 if (!strcmp(m
->name
, name
))
1111 if (m
->alias
&& !strcmp(m
->alias
, name
))
1117 static QEMUMachine
*find_default_machine(void)
1121 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1122 if (m
->is_default
) {
1129 /***********************************************************/
1130 /* main execution loop */
1132 static void gui_update(void *opaque
)
1134 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1135 DisplayState
*ds
= opaque
;
1136 DisplayChangeListener
*dcl
= ds
->listeners
;
1138 qemu_flush_coalesced_mmio_buffer();
1141 while (dcl
!= NULL
) {
1142 if (dcl
->gui_timer_interval
&&
1143 dcl
->gui_timer_interval
< interval
)
1144 interval
= dcl
->gui_timer_interval
;
1147 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1150 static void nographic_update(void *opaque
)
1152 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1154 qemu_flush_coalesced_mmio_buffer();
1155 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1158 struct vm_change_state_entry
{
1159 VMChangeStateHandler
*cb
;
1161 QLIST_ENTRY (vm_change_state_entry
) entries
;
1164 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1166 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1169 VMChangeStateEntry
*e
;
1171 e
= qemu_mallocz(sizeof (*e
));
1175 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1179 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1181 QLIST_REMOVE (e
, entries
);
1185 void vm_state_notify(int running
, int reason
)
1187 VMChangeStateEntry
*e
;
1189 trace_vm_state_notify(running
, reason
);
1191 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1192 e
->cb(e
->opaque
, running
, reason
);
1201 vm_state_notify(1, 0);
1203 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1207 /* reset/shutdown handler */
1209 typedef struct QEMUResetEntry
{
1210 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1211 QEMUResetHandler
*func
;
1215 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1216 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1217 static int reset_requested
;
1218 static int shutdown_requested
;
1219 static int powerdown_requested
;
1220 static int debug_requested
;
1221 static int vmstop_requested
;
1223 int qemu_shutdown_requested(void)
1225 int r
= shutdown_requested
;
1226 shutdown_requested
= 0;
1230 int qemu_reset_requested(void)
1232 int r
= reset_requested
;
1233 reset_requested
= 0;
1237 int qemu_powerdown_requested(void)
1239 int r
= powerdown_requested
;
1240 powerdown_requested
= 0;
1244 static int qemu_debug_requested(void)
1246 int r
= debug_requested
;
1247 debug_requested
= 0;
1251 static int qemu_vmstop_requested(void)
1253 int r
= vmstop_requested
;
1254 vmstop_requested
= 0;
1258 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1260 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1263 re
->opaque
= opaque
;
1264 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1267 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1271 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1272 if (re
->func
== func
&& re
->opaque
== opaque
) {
1273 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1280 void qemu_system_reset(void)
1282 QEMUResetEntry
*re
, *nre
;
1284 /* reset all devices */
1285 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1286 re
->func(re
->opaque
);
1288 monitor_protocol_event(QEVENT_RESET
, NULL
);
1289 cpu_synchronize_all_post_reset();
1292 void qemu_system_reset_request(void)
1295 shutdown_requested
= 1;
1297 reset_requested
= 1;
1300 qemu_notify_event();
1303 void qemu_system_shutdown_request(void)
1305 shutdown_requested
= 1;
1306 qemu_notify_event();
1309 void qemu_system_powerdown_request(void)
1311 powerdown_requested
= 1;
1312 qemu_notify_event();
1315 void qemu_system_debug_request(void)
1317 debug_requested
= 1;
1318 qemu_notify_event();
1321 void qemu_system_vmstop_request(int reason
)
1323 vmstop_requested
= reason
;
1324 qemu_notify_event();
1327 void main_loop_wait(int nonblocking
)
1329 IOHandlerRecord
*ioh
;
1330 fd_set rfds
, wfds
, xfds
;
1338 timeout
= qemu_calculate_timeout();
1339 qemu_bh_update_timeout(&timeout
);
1342 os_host_main_loop_wait(&timeout
);
1344 /* poll any events */
1345 /* XXX: separate device handlers from system ones */
1350 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1354 (!ioh
->fd_read_poll
||
1355 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1356 FD_SET(ioh
->fd
, &rfds
);
1360 if (ioh
->fd_write
) {
1361 FD_SET(ioh
->fd
, &wfds
);
1367 tv
.tv_sec
= timeout
/ 1000;
1368 tv
.tv_usec
= (timeout
% 1000) * 1000;
1370 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1372 qemu_mutex_unlock_iothread();
1373 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1374 qemu_mutex_lock_iothread();
1376 IOHandlerRecord
*pioh
;
1378 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1379 if (!ioh
->deleted
&& ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1380 ioh
->fd_read(ioh
->opaque
);
1382 if (!ioh
->deleted
&& ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1383 ioh
->fd_write(ioh
->opaque
);
1386 /* Do this last in case read/write handlers marked it for deletion */
1388 QLIST_REMOVE(ioh
, next
);
1394 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1396 qemu_run_all_timers();
1398 /* Check bottom-halves last in case any of the earlier events triggered
1404 #ifndef CONFIG_IOTHREAD
1405 static int vm_request_pending(void)
1407 return powerdown_requested
||
1409 shutdown_requested
||
1415 qemu_irq qemu_system_powerdown
;
1417 static void main_loop(void)
1419 bool nonblocking
= false;
1420 #ifdef CONFIG_PROFILER
1425 qemu_main_loop_start();
1428 #ifndef CONFIG_IOTHREAD
1429 nonblocking
= cpu_exec_all();
1430 if (vm_request_pending()) {
1434 #ifdef CONFIG_PROFILER
1435 ti
= profile_getclock();
1437 main_loop_wait(nonblocking
);
1438 #ifdef CONFIG_PROFILER
1439 dev_time
+= profile_getclock() - ti
;
1442 if (qemu_debug_requested()) {
1443 vm_stop(VMSTOP_DEBUG
);
1445 if (qemu_shutdown_requested()) {
1446 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1448 vm_stop(VMSTOP_SHUTDOWN
);
1453 if (qemu_reset_requested()) {
1455 qemu_system_reset();
1458 if (qemu_powerdown_requested()) {
1459 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1460 qemu_irq_raise(qemu_system_powerdown
);
1462 if ((r
= qemu_vmstop_requested())) {
1470 static void version(void)
1472 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1475 static void help(int exitcode
)
1477 const char *options_help
=
1478 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1480 #define DEFHEADING(text) stringify(text) "\n"
1481 #include "qemu-options.def"
1487 printf("usage: %s [options] [disk_image]\n"
1489 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1492 "During emulation, the following keys are useful:\n"
1493 "ctrl-alt-f toggle full screen\n"
1494 "ctrl-alt-n switch to virtual console 'n'\n"
1495 "ctrl-alt toggle mouse and keyboard grab\n"
1497 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1503 #define HAS_ARG 0x0001
1505 typedef struct QEMUOption
{
1512 static const QEMUOption qemu_options
[] = {
1513 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1514 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1515 { option, opt_arg, opt_enum, arch_mask },
1516 #define DEFHEADING(text)
1517 #include "qemu-options.def"
1523 static void select_vgahw (const char *p
)
1528 vga_interface_type
= VGA_NONE
;
1529 if (strstart(p
, "std", &opts
)) {
1530 vga_interface_type
= VGA_STD
;
1531 } else if (strstart(p
, "cirrus", &opts
)) {
1532 vga_interface_type
= VGA_CIRRUS
;
1533 } else if (strstart(p
, "vmware", &opts
)) {
1534 vga_interface_type
= VGA_VMWARE
;
1535 } else if (strstart(p
, "xenfb", &opts
)) {
1536 vga_interface_type
= VGA_XENFB
;
1537 } else if (strstart(p
, "qxl", &opts
)) {
1538 vga_interface_type
= VGA_QXL
;
1539 } else if (!strstart(p
, "none", &opts
)) {
1541 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1545 const char *nextopt
;
1547 if (strstart(opts
, ",retrace=", &nextopt
)) {
1549 if (strstart(opts
, "dumb", &nextopt
))
1550 vga_retrace_method
= VGA_RETRACE_DUMB
;
1551 else if (strstart(opts
, "precise", &nextopt
))
1552 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1553 else goto invalid_vga
;
1554 } else goto invalid_vga
;
1559 static int balloon_parse(const char *arg
)
1563 if (strcmp(arg
, "none") == 0) {
1567 if (!strncmp(arg
, "virtio", 6)) {
1568 if (arg
[6] == ',') {
1569 /* have params -> parse them */
1570 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1574 /* create empty opts */
1575 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1577 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1584 char *qemu_find_file(int type
, const char *name
)
1590 /* If name contains path separators then try it as a straight path. */
1591 if ((strchr(name
, '/') || strchr(name
, '\\'))
1592 && access(name
, R_OK
) == 0) {
1593 return qemu_strdup(name
);
1596 case QEMU_FILE_TYPE_BIOS
:
1599 case QEMU_FILE_TYPE_KEYMAP
:
1600 subdir
= "keymaps/";
1605 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1606 buf
= qemu_mallocz(len
);
1607 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1608 if (access(buf
, R_OK
)) {
1615 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1617 return qdev_device_help(opts
);
1620 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1624 dev
= qdev_device_add(opts
);
1630 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1632 CharDriverState
*chr
;
1634 chr
= qemu_chr_open_opts(opts
, NULL
);
1640 #ifdef CONFIG_VIRTFS
1641 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1644 ret
= qemu_fsdev_add(opts
);
1650 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1652 CharDriverState
*chr
;
1653 const char *chardev
;
1657 mode
= qemu_opt_get(opts
, "mode");
1661 if (strcmp(mode
, "readline") == 0) {
1662 flags
= MONITOR_USE_READLINE
;
1663 } else if (strcmp(mode
, "control") == 0) {
1664 flags
= MONITOR_USE_CONTROL
;
1666 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1670 if (qemu_opt_get_bool(opts
, "pretty", 0))
1671 flags
|= MONITOR_USE_PRETTY
;
1673 if (qemu_opt_get_bool(opts
, "default", 0))
1674 flags
|= MONITOR_IS_DEFAULT
;
1676 chardev
= qemu_opt_get(opts
, "chardev");
1677 chr
= qemu_chr_find(chardev
);
1679 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1683 monitor_init(chr
, flags
);
1687 static void monitor_parse(const char *optarg
, const char *mode
)
1689 static int monitor_device_index
= 0;
1695 if (strstart(optarg
, "chardev:", &p
)) {
1696 snprintf(label
, sizeof(label
), "%s", p
);
1698 snprintf(label
, sizeof(label
), "compat_monitor%d",
1699 monitor_device_index
);
1700 if (monitor_device_index
== 0) {
1703 opts
= qemu_chr_parse_compat(label
, optarg
);
1705 fprintf(stderr
, "parse error: %s\n", optarg
);
1710 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1712 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1715 qemu_opt_set(opts
, "mode", mode
);
1716 qemu_opt_set(opts
, "chardev", label
);
1718 qemu_opt_set(opts
, "default", "on");
1719 monitor_device_index
++;
1722 struct device_config
{
1724 DEV_USB
, /* -usbdevice */
1726 DEV_SERIAL
, /* -serial */
1727 DEV_PARALLEL
, /* -parallel */
1728 DEV_VIRTCON
, /* -virtioconsole */
1729 DEV_DEBUGCON
, /* -debugcon */
1731 const char *cmdline
;
1732 QTAILQ_ENTRY(device_config
) next
;
1734 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1736 static void add_device_config(int type
, const char *cmdline
)
1738 struct device_config
*conf
;
1740 conf
= qemu_mallocz(sizeof(*conf
));
1742 conf
->cmdline
= cmdline
;
1743 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1746 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1748 struct device_config
*conf
;
1751 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1752 if (conf
->type
!= type
)
1754 rc
= func(conf
->cmdline
);
1761 static int serial_parse(const char *devname
)
1763 static int index
= 0;
1766 if (strcmp(devname
, "none") == 0)
1768 if (index
== MAX_SERIAL_PORTS
) {
1769 fprintf(stderr
, "qemu: too many serial ports\n");
1772 snprintf(label
, sizeof(label
), "serial%d", index
);
1773 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1774 if (!serial_hds
[index
]) {
1775 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1776 devname
, strerror(errno
));
1783 static int parallel_parse(const char *devname
)
1785 static int index
= 0;
1788 if (strcmp(devname
, "none") == 0)
1790 if (index
== MAX_PARALLEL_PORTS
) {
1791 fprintf(stderr
, "qemu: too many parallel ports\n");
1794 snprintf(label
, sizeof(label
), "parallel%d", index
);
1795 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1796 if (!parallel_hds
[index
]) {
1797 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1798 devname
, strerror(errno
));
1805 static int virtcon_parse(const char *devname
)
1807 QemuOptsList
*device
= qemu_find_opts("device");
1808 static int index
= 0;
1810 QemuOpts
*bus_opts
, *dev_opts
;
1812 if (strcmp(devname
, "none") == 0)
1814 if (index
== MAX_VIRTIO_CONSOLES
) {
1815 fprintf(stderr
, "qemu: too many virtio consoles\n");
1819 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1820 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1822 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1823 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1825 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1826 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1827 if (!virtcon_hds
[index
]) {
1828 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1829 devname
, strerror(errno
));
1832 qemu_opt_set(dev_opts
, "chardev", label
);
1838 static int debugcon_parse(const char *devname
)
1842 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1845 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1847 fprintf(stderr
, "qemu: already have a debugcon device\n");
1850 qemu_opt_set(opts
, "driver", "isa-debugcon");
1851 qemu_opt_set(opts
, "chardev", "debugcon");
1855 void qemu_add_exit_notifier(Notifier
*notify
)
1857 notifier_list_add(&exit_notifiers
, notify
);
1860 void qemu_remove_exit_notifier(Notifier
*notify
)
1862 notifier_list_remove(&exit_notifiers
, notify
);
1865 static void qemu_run_exit_notifiers(void)
1867 notifier_list_notify(&exit_notifiers
);
1870 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
1872 notifier_list_add(&machine_init_done_notifiers
, notify
);
1875 static void qemu_run_machine_init_done_notifiers(void)
1877 notifier_list_notify(&machine_init_done_notifiers
);
1880 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1881 const char **poptarg
, int *poptind
)
1883 const QEMUOption
*popt
;
1884 int optind
= *poptind
;
1885 char *r
= argv
[optind
];
1888 loc_set_cmdline(argv
, optind
, 1);
1890 /* Treat --foo the same as -foo. */
1893 popt
= qemu_options
;
1896 error_report("invalid option");
1899 if (!strcmp(popt
->name
, r
+ 1))
1903 if (popt
->flags
& HAS_ARG
) {
1904 if (optind
>= argc
) {
1905 error_report("requires an argument");
1908 optarg
= argv
[optind
++];
1909 loc_set_cmdline(argv
, optind
- 2, 2);
1920 int main(int argc
, char **argv
, char **envp
)
1922 const char *gdbstub_dev
= NULL
;
1924 int snapshot
, linux_boot
;
1925 const char *icount_option
= NULL
;
1926 const char *initrd_filename
;
1927 const char *kernel_filename
, *kernel_cmdline
;
1928 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1930 DisplayChangeListener
*dcl
;
1931 int cyls
, heads
, secs
, translation
;
1932 QemuOpts
*hda_opts
= NULL
, *opts
;
1933 QemuOptsList
*olist
;
1936 const char *loadvm
= NULL
;
1937 QEMUMachine
*machine
;
1938 const char *cpu_model
;
1940 const char *pid_file
= NULL
;
1941 const char *incoming
= NULL
;
1942 int show_vnc_port
= 0;
1945 #ifdef CONFIG_SIMPLE_TRACE
1946 const char *trace_file
= NULL
;
1948 atexit(qemu_run_exit_notifiers
);
1949 error_set_progname(argv
[0]);
1953 qemu_cache_utils_init(envp
);
1955 QLIST_INIT (&vm_change_state_head
);
1956 os_setup_early_signal_handling();
1958 module_call_init(MODULE_INIT_MACHINE
);
1959 machine
= find_default_machine();
1961 initrd_filename
= NULL
;
1964 kernel_filename
= NULL
;
1965 kernel_cmdline
= "";
1966 cyls
= heads
= secs
= 0;
1967 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1969 for (i
= 0; i
< MAX_NODES
; i
++) {
1971 node_cpumask
[i
] = 0;
1980 /* first pass of option parsing */
1982 while (optind
< argc
) {
1983 if (argv
[optind
][0] != '-') {
1988 const QEMUOption
*popt
;
1990 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1991 switch (popt
->index
) {
1992 case QEMU_OPTION_nodefconfig
:
2002 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2003 if (ret
< 0 && ret
!= -ENOENT
) {
2007 ret
= qemu_read_config_file(arch_config_name
);
2008 if (ret
< 0 && ret
!= -ENOENT
) {
2014 /* second pass of option parsing */
2019 if (argv
[optind
][0] != '-') {
2020 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2022 const QEMUOption
*popt
;
2024 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2025 if (!(popt
->arch_mask
& arch_type
)) {
2026 printf("Option %s not supported for this target\n", popt
->name
);
2029 switch(popt
->index
) {
2031 machine
= find_machine(optarg
);
2034 printf("Supported machines are:\n");
2035 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
2037 printf("%-10s %s (alias of %s)\n",
2038 m
->alias
, m
->desc
, m
->name
);
2039 printf("%-10s %s%s\n",
2041 m
->is_default
? " (default)" : "");
2043 exit(*optarg
!= '?');
2046 case QEMU_OPTION_cpu
:
2047 /* hw initialization will check this */
2048 if (*optarg
== '?') {
2049 list_cpus(stdout
, &fprintf
, optarg
);
2055 case QEMU_OPTION_initrd
:
2056 initrd_filename
= optarg
;
2058 case QEMU_OPTION_hda
:
2062 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
2064 snprintf(buf
, sizeof(buf
),
2065 "%s,cyls=%d,heads=%d,secs=%d%s",
2066 HD_OPTS
, cyls
, heads
, secs
,
2067 translation
== BIOS_ATA_TRANSLATION_LBA
?
2069 translation
== BIOS_ATA_TRANSLATION_NONE
?
2070 ",trans=none" : "");
2071 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
2074 case QEMU_OPTION_hdb
:
2075 case QEMU_OPTION_hdc
:
2076 case QEMU_OPTION_hdd
:
2077 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2080 case QEMU_OPTION_drive
:
2083 case QEMU_OPTION_set
:
2084 if (qemu_set_option(optarg
) != 0)
2087 case QEMU_OPTION_global
:
2088 if (qemu_global_option(optarg
) != 0)
2091 case QEMU_OPTION_mtdblock
:
2092 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2094 case QEMU_OPTION_sd
:
2095 drive_add(IF_SD
, 0, optarg
, SD_OPTS
);
2097 case QEMU_OPTION_pflash
:
2098 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2100 case QEMU_OPTION_snapshot
:
2103 case QEMU_OPTION_hdachs
:
2107 cyls
= strtol(p
, (char **)&p
, 0);
2108 if (cyls
< 1 || cyls
> 16383)
2113 heads
= strtol(p
, (char **)&p
, 0);
2114 if (heads
< 1 || heads
> 16)
2119 secs
= strtol(p
, (char **)&p
, 0);
2120 if (secs
< 1 || secs
> 63)
2124 if (!strcmp(p
, "none"))
2125 translation
= BIOS_ATA_TRANSLATION_NONE
;
2126 else if (!strcmp(p
, "lba"))
2127 translation
= BIOS_ATA_TRANSLATION_LBA
;
2128 else if (!strcmp(p
, "auto"))
2129 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2132 } else if (*p
!= '\0') {
2134 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2137 if (hda_opts
!= NULL
) {
2139 snprintf(num
, sizeof(num
), "%d", cyls
);
2140 qemu_opt_set(hda_opts
, "cyls", num
);
2141 snprintf(num
, sizeof(num
), "%d", heads
);
2142 qemu_opt_set(hda_opts
, "heads", num
);
2143 snprintf(num
, sizeof(num
), "%d", secs
);
2144 qemu_opt_set(hda_opts
, "secs", num
);
2145 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2146 qemu_opt_set(hda_opts
, "trans", "lba");
2147 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2148 qemu_opt_set(hda_opts
, "trans", "none");
2152 case QEMU_OPTION_numa
:
2153 if (nb_numa_nodes
>= MAX_NODES
) {
2154 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2159 case QEMU_OPTION_nographic
:
2160 display_type
= DT_NOGRAPHIC
;
2162 #ifdef CONFIG_CURSES
2163 case QEMU_OPTION_curses
:
2164 display_type
= DT_CURSES
;
2167 case QEMU_OPTION_portrait
:
2170 case QEMU_OPTION_kernel
:
2171 kernel_filename
= optarg
;
2173 case QEMU_OPTION_append
:
2174 kernel_cmdline
= optarg
;
2176 case QEMU_OPTION_cdrom
:
2177 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2179 case QEMU_OPTION_boot
:
2181 static const char * const params
[] = {
2182 "order", "once", "menu", NULL
2184 char buf
[sizeof(boot_devices
)];
2185 char *standard_boot_devices
;
2188 if (!strchr(optarg
, '=')) {
2190 pstrcpy(buf
, sizeof(buf
), optarg
);
2191 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2193 "qemu: unknown boot parameter '%s' in '%s'\n",
2199 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2200 validate_bootdevices(buf
);
2201 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2204 if (get_param_value(buf
, sizeof(buf
),
2206 validate_bootdevices(buf
);
2207 standard_boot_devices
= qemu_strdup(boot_devices
);
2208 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2209 qemu_register_reset(restore_boot_devices
,
2210 standard_boot_devices
);
2212 if (get_param_value(buf
, sizeof(buf
),
2214 if (!strcmp(buf
, "on")) {
2216 } else if (!strcmp(buf
, "off")) {
2220 "qemu: invalid option value '%s'\n",
2228 case QEMU_OPTION_fda
:
2229 case QEMU_OPTION_fdb
:
2230 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2233 case QEMU_OPTION_no_fd_bootchk
:
2236 case QEMU_OPTION_netdev
:
2237 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2241 case QEMU_OPTION_net
:
2242 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2247 case QEMU_OPTION_tftp
:
2248 legacy_tftp_prefix
= optarg
;
2250 case QEMU_OPTION_bootp
:
2251 legacy_bootp_filename
= optarg
;
2253 case QEMU_OPTION_redir
:
2254 if (net_slirp_redir(optarg
) < 0)
2258 case QEMU_OPTION_bt
:
2259 add_device_config(DEV_BT
, optarg
);
2261 case QEMU_OPTION_audio_help
:
2262 if (!(audio_available())) {
2263 printf("Option %s not supported for this target\n", popt
->name
);
2269 case QEMU_OPTION_soundhw
:
2270 if (!(audio_available())) {
2271 printf("Option %s not supported for this target\n", popt
->name
);
2274 select_soundhw (optarg
);
2279 case QEMU_OPTION_version
:
2283 case QEMU_OPTION_m
: {
2286 value
= strtosz(optarg
, NULL
);
2288 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2292 /* On 32-bit hosts, QEMU is limited by virtual address space */
2293 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2294 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2297 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2298 fprintf(stderr
, "qemu: ram size too large\n");
2304 case QEMU_OPTION_mempath
:
2308 case QEMU_OPTION_mem_prealloc
:
2313 set_cpu_log(optarg
);
2316 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2318 case QEMU_OPTION_gdb
:
2319 gdbstub_dev
= optarg
;
2324 case QEMU_OPTION_bios
:
2327 case QEMU_OPTION_singlestep
:
2334 keyboard_layout
= optarg
;
2336 case QEMU_OPTION_localtime
:
2339 case QEMU_OPTION_vga
:
2340 select_vgahw (optarg
);
2347 w
= strtol(p
, (char **)&p
, 10);
2350 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2356 h
= strtol(p
, (char **)&p
, 10);
2361 depth
= strtol(p
, (char **)&p
, 10);
2362 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2363 depth
!= 24 && depth
!= 32)
2365 } else if (*p
== '\0') {
2366 depth
= graphic_depth
;
2373 graphic_depth
= depth
;
2376 case QEMU_OPTION_echr
:
2379 term_escape_char
= strtol(optarg
, &r
, 0);
2381 printf("Bad argument to echr\n");
2384 case QEMU_OPTION_monitor
:
2385 monitor_parse(optarg
, "readline");
2386 default_monitor
= 0;
2388 case QEMU_OPTION_qmp
:
2389 monitor_parse(optarg
, "control");
2390 default_monitor
= 0;
2392 case QEMU_OPTION_mon
:
2393 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2397 default_monitor
= 0;
2399 case QEMU_OPTION_chardev
:
2400 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2405 case QEMU_OPTION_fsdev
:
2406 olist
= qemu_find_opts("fsdev");
2408 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2411 opts
= qemu_opts_parse(olist
, optarg
, 1);
2413 fprintf(stderr
, "parse error: %s\n", optarg
);
2417 case QEMU_OPTION_virtfs
: {
2418 char *arg_fsdev
= NULL
;
2419 char *arg_9p
= NULL
;
2422 olist
= qemu_find_opts("virtfs");
2424 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2427 opts
= qemu_opts_parse(olist
, optarg
, 1);
2429 fprintf(stderr
, "parse error: %s\n", optarg
);
2433 if (qemu_opt_get(opts
, "fstype") == NULL
||
2434 qemu_opt_get(opts
, "mount_tag") == NULL
||
2435 qemu_opt_get(opts
, "path") == NULL
||
2436 qemu_opt_get(opts
, "security_model") == NULL
) {
2437 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2438 "security_model=[mapped|passthrough|none],"
2443 len
= strlen(",id=,path=,security_model=");
2444 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2445 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2446 len
+= strlen(qemu_opt_get(opts
, "path"));
2447 len
+= strlen(qemu_opt_get(opts
, "security_model"));
2448 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2450 snprintf(arg_fsdev
, (len
+ 1) * sizeof(*arg_fsdev
),
2451 "%s,id=%s,path=%s,security_model=%s",
2452 qemu_opt_get(opts
, "fstype"),
2453 qemu_opt_get(opts
, "mount_tag"),
2454 qemu_opt_get(opts
, "path"),
2455 qemu_opt_get(opts
, "security_model"));
2457 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2458 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2459 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2461 snprintf(arg_9p
, (len
+ 1) * sizeof(*arg_9p
),
2462 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2463 qemu_opt_get(opts
, "mount_tag"),
2464 qemu_opt_get(opts
, "mount_tag"));
2466 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev
, 1)) {
2467 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2471 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p
, 1)) {
2472 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2476 qemu_free(arg_fsdev
);
2480 case QEMU_OPTION_serial
:
2481 add_device_config(DEV_SERIAL
, optarg
);
2483 if (strncmp(optarg
, "mon:", 4) == 0) {
2484 default_monitor
= 0;
2487 case QEMU_OPTION_watchdog
:
2490 "qemu: only one watchdog option may be given\n");
2495 case QEMU_OPTION_watchdog_action
:
2496 if (select_watchdog_action(optarg
) == -1) {
2497 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2501 case QEMU_OPTION_virtiocon
:
2502 add_device_config(DEV_VIRTCON
, optarg
);
2503 default_virtcon
= 0;
2504 if (strncmp(optarg
, "mon:", 4) == 0) {
2505 default_monitor
= 0;
2508 case QEMU_OPTION_parallel
:
2509 add_device_config(DEV_PARALLEL
, optarg
);
2510 default_parallel
= 0;
2511 if (strncmp(optarg
, "mon:", 4) == 0) {
2512 default_monitor
= 0;
2515 case QEMU_OPTION_debugcon
:
2516 add_device_config(DEV_DEBUGCON
, optarg
);
2518 case QEMU_OPTION_loadvm
:
2521 case QEMU_OPTION_full_screen
:
2525 case QEMU_OPTION_no_frame
:
2528 case QEMU_OPTION_alt_grab
:
2531 case QEMU_OPTION_ctrl_grab
:
2534 case QEMU_OPTION_no_quit
:
2537 case QEMU_OPTION_sdl
:
2538 display_type
= DT_SDL
;
2541 case QEMU_OPTION_pidfile
:
2544 case QEMU_OPTION_win2k_hack
:
2545 win2k_install_hack
= 1;
2547 case QEMU_OPTION_rtc_td_hack
:
2550 case QEMU_OPTION_acpitable
:
2551 do_acpitable_option(optarg
);
2553 case QEMU_OPTION_smbios
:
2554 do_smbios_option(optarg
);
2556 case QEMU_OPTION_enable_kvm
:
2559 case QEMU_OPTION_usb
:
2562 case QEMU_OPTION_usbdevice
:
2564 add_device_config(DEV_USB
, optarg
);
2566 case QEMU_OPTION_device
:
2567 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2571 case QEMU_OPTION_smp
:
2574 fprintf(stderr
, "Invalid number of CPUs\n");
2577 if (max_cpus
< smp_cpus
) {
2578 fprintf(stderr
, "maxcpus must be equal to or greater than "
2582 if (max_cpus
> 255) {
2583 fprintf(stderr
, "Unsupported number of maxcpus\n");
2587 case QEMU_OPTION_vnc
:
2589 vnc_display
= optarg
;
2591 case QEMU_OPTION_no_acpi
:
2594 case QEMU_OPTION_no_hpet
:
2597 case QEMU_OPTION_balloon
:
2598 if (balloon_parse(optarg
) < 0) {
2599 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2603 case QEMU_OPTION_no_reboot
:
2606 case QEMU_OPTION_no_shutdown
:
2609 case QEMU_OPTION_show_cursor
:
2612 case QEMU_OPTION_uuid
:
2613 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2614 fprintf(stderr
, "Fail to parse UUID string."
2615 " Wrong format.\n");
2619 case QEMU_OPTION_option_rom
:
2620 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2621 fprintf(stderr
, "Too many option ROMs\n");
2624 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
2625 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
2626 option_rom
[nb_option_roms
].bootindex
=
2627 qemu_opt_get_number(opts
, "bootindex", -1);
2628 if (!option_rom
[nb_option_roms
].name
) {
2629 fprintf(stderr
, "Option ROM file is not specified\n");
2634 case QEMU_OPTION_semihosting
:
2635 semihosting_enabled
= 1;
2637 case QEMU_OPTION_name
:
2638 qemu_name
= qemu_strdup(optarg
);
2640 char *p
= strchr(qemu_name
, ',');
2643 if (strncmp(p
, "process=", 8)) {
2644 fprintf(stderr
, "Unknown subargument %s to -name\n", p
);
2648 os_set_proc_name(p
);
2652 case QEMU_OPTION_prom_env
:
2653 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2654 fprintf(stderr
, "Too many prom variables\n");
2657 prom_envs
[nb_prom_envs
] = optarg
;
2660 case QEMU_OPTION_old_param
:
2663 case QEMU_OPTION_clock
:
2664 configure_alarms(optarg
);
2666 case QEMU_OPTION_startdate
:
2667 configure_rtc_date_offset(optarg
, 1);
2669 case QEMU_OPTION_rtc
:
2670 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2674 configure_rtc(opts
);
2676 case QEMU_OPTION_tb_size
:
2677 tb_size
= strtol(optarg
, NULL
, 0);
2681 case QEMU_OPTION_icount
:
2682 icount_option
= optarg
;
2684 case QEMU_OPTION_incoming
:
2686 incoming_expected
= true;
2688 case QEMU_OPTION_nodefaults
:
2690 default_parallel
= 0;
2691 default_virtcon
= 0;
2692 default_monitor
= 0;
2699 case QEMU_OPTION_xen_domid
:
2700 if (!(xen_available())) {
2701 printf("Option %s not supported for this target\n", popt
->name
);
2704 xen_domid
= atoi(optarg
);
2706 case QEMU_OPTION_xen_create
:
2707 if (!(xen_available())) {
2708 printf("Option %s not supported for this target\n", popt
->name
);
2711 xen_mode
= XEN_CREATE
;
2713 case QEMU_OPTION_xen_attach
:
2714 if (!(xen_available())) {
2715 printf("Option %s not supported for this target\n", popt
->name
);
2718 xen_mode
= XEN_ATTACH
;
2720 #ifdef CONFIG_SIMPLE_TRACE
2721 case QEMU_OPTION_trace
:
2722 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2724 trace_file
= qemu_opt_get(opts
, "file");
2728 case QEMU_OPTION_readconfig
:
2730 int ret
= qemu_read_config_file(optarg
);
2732 fprintf(stderr
, "read config %s: %s\n", optarg
,
2738 case QEMU_OPTION_spice
:
2739 olist
= qemu_find_opts("spice");
2741 fprintf(stderr
, "spice is not supported by this qemu build.\n");
2744 opts
= qemu_opts_parse(olist
, optarg
, 0);
2746 fprintf(stderr
, "parse error: %s\n", optarg
);
2750 case QEMU_OPTION_writeconfig
:
2753 if (strcmp(optarg
, "-") == 0) {
2756 fp
= fopen(optarg
, "w");
2758 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2762 qemu_config_write(fp
);
2767 os_parse_cmd_args(popt
->index
, optarg
);
2773 /* If no data_dir is specified then try to find it relative to the
2776 data_dir
= os_find_datadir(argv
[0]);
2778 /* If all else fails use the install patch specified when building. */
2780 data_dir
= CONFIG_QEMU_DATADIR
;
2783 #ifdef CONFIG_SIMPLE_TRACE
2785 * Set the trace file name, if specified.
2787 st_set_trace_file(trace_file
);
2790 * Default to max_cpus = smp_cpus, in case the user doesn't
2791 * specify a max_cpus value.
2794 max_cpus
= smp_cpus
;
2796 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2797 if (smp_cpus
> machine
->max_cpus
) {
2798 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2799 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2804 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2805 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2807 if (machine
->no_serial
) {
2810 if (machine
->no_parallel
) {
2811 default_parallel
= 0;
2813 if (!machine
->use_virtcon
) {
2814 default_virtcon
= 0;
2816 if (machine
->no_vga
) {
2819 if (machine
->no_floppy
) {
2822 if (machine
->no_cdrom
) {
2825 if (machine
->no_sdcard
) {
2829 if (display_type
== DT_NOGRAPHIC
) {
2830 if (default_parallel
)
2831 add_device_config(DEV_PARALLEL
, "null");
2832 if (default_serial
&& default_monitor
) {
2833 add_device_config(DEV_SERIAL
, "mon:stdio");
2834 } else if (default_virtcon
&& default_monitor
) {
2835 add_device_config(DEV_VIRTCON
, "mon:stdio");
2838 add_device_config(DEV_SERIAL
, "stdio");
2839 if (default_virtcon
)
2840 add_device_config(DEV_VIRTCON
, "stdio");
2841 if (default_monitor
)
2842 monitor_parse("stdio", "readline");
2846 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2847 if (default_parallel
)
2848 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2849 if (default_monitor
)
2850 monitor_parse("vc:80Cx24C", "readline");
2851 if (default_virtcon
)
2852 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2855 vga_interface_type
= VGA_CIRRUS
;
2859 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
2861 #ifdef CONFIG_VIRTFS
2862 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
2869 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2875 int ret
= kvm_init();
2877 if (!kvm_available()) {
2878 printf("KVM not supported for this target\n");
2880 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2886 if (qemu_init_main_loop()) {
2887 fprintf(stderr
, "qemu_init_main_loop failed\n");
2890 linux_boot
= (kernel_filename
!= NULL
);
2892 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2893 fprintf(stderr
, "-append only allowed with -kernel option\n");
2897 if (!linux_boot
&& initrd_filename
!= NULL
) {
2898 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2902 os_set_line_buffering();
2904 if (init_timer_alarm() < 0) {
2905 fprintf(stderr
, "could not initialize alarm timer\n");
2908 configure_icount(icount_option
);
2910 if (net_init_clients() < 0) {
2914 /* init the bluetooth world */
2915 if (foreach_device_config(DEV_BT
, bt_parse
))
2918 /* init the memory */
2920 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2922 /* init the dynamic translator */
2923 cpu_exec_init_all(tb_size
* 1024 * 1024);
2925 bdrv_init_with_whitelist();
2929 /* open the virtual block devices */
2931 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
2932 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
2935 default_drive(default_cdrom
, snapshot
, machine
->use_scsi
,
2936 IF_DEFAULT
, 2, CDROM_OPTS
);
2937 default_drive(default_floppy
, snapshot
, machine
->use_scsi
,
2938 IF_FLOPPY
, 0, FD_OPTS
);
2939 default_drive(default_sdcard
, snapshot
, machine
->use_scsi
,
2942 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2945 if (nb_numa_nodes
> 0) {
2948 if (nb_numa_nodes
> smp_cpus
) {
2949 nb_numa_nodes
= smp_cpus
;
2952 /* If no memory size if given for any node, assume the default case
2953 * and distribute the available memory equally across all nodes
2955 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2956 if (node_mem
[i
] != 0)
2959 if (i
== nb_numa_nodes
) {
2960 uint64_t usedmem
= 0;
2962 /* On Linux, the each node's border has to be 8MB aligned,
2963 * the final node gets the rest.
2965 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2966 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2967 usedmem
+= node_mem
[i
];
2969 node_mem
[i
] = ram_size
- usedmem
;
2972 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2973 if (node_cpumask
[i
] != 0)
2976 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2977 * must cope with this anyway, because there are BIOSes out there in
2978 * real machines which also use this scheme.
2980 if (i
== nb_numa_nodes
) {
2981 for (i
= 0; i
< smp_cpus
; i
++) {
2982 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2987 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
2991 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2993 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2995 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2997 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
3000 module_call_init(MODULE_INIT_DEVICE
);
3002 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
3006 i
= select_watchdog(watchdog
);
3008 exit (i
== 1 ? 1 : 0);
3011 if (machine
->compat_props
) {
3012 qdev_prop_register_global_list(machine
->compat_props
);
3016 machine
->init(ram_size
, boot_devices
,
3017 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
3019 cpu_synchronize_all_post_init();
3021 /* must be after terminal init, SDL library changes signal handlers */
3022 os_setup_signal_handling();
3026 current_machine
= machine
;
3028 /* init USB devices */
3030 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
3034 /* init generic devices */
3035 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3038 net_check_clients();
3040 /* just use the first displaystate for the moment */
3041 ds
= get_displaystate();
3045 if (display_type
== DT_DEFAULT
&& !display_remote
) {
3046 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3047 display_type
= DT_SDL
;
3049 vnc_display
= "localhost:0,to=99";
3055 /* init local displays */
3056 switch (display_type
) {
3059 #if defined(CONFIG_CURSES)
3061 curses_display_init(ds
, full_screen
);
3064 #if defined(CONFIG_SDL)
3066 sdl_display_init(ds
, full_screen
, no_frame
);
3068 #elif defined(CONFIG_COCOA)
3070 cocoa_display_init(ds
, full_screen
);
3077 /* init remote displays */
3079 vnc_display_init(ds
);
3080 if (vnc_display_open(ds
, vnc_display
) < 0)
3083 if (show_vnc_port
) {
3084 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3088 if (using_spice
&& !qxl_enabled
) {
3089 qemu_spice_display_init(ds
);
3095 dcl
= ds
->listeners
;
3096 while (dcl
!= NULL
) {
3097 if (dcl
->dpy_refresh
!= NULL
) {
3098 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
3099 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
3104 if (ds
->gui_timer
== NULL
) {
3105 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
3106 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
3108 text_consoles_set_display(ds
);
3110 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3111 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3116 qdev_machine_creation_done();
3118 if (rom_load_all() != 0) {
3119 fprintf(stderr
, "rom loading failed\n");
3123 /* TODO: once all bus devices are qdevified, this should be done
3124 * when bus is created by qdev.c */
3125 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
3126 qemu_run_machine_init_done_notifiers();
3128 qemu_system_reset();
3130 if (load_vmstate(loadvm
) < 0) {
3136 int ret
= qemu_start_incoming_migration(incoming
);
3138 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3142 } else if (autostart
) {