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;
263 enum xen_mode xen_mode
= XEN_EMULATE
;
265 static int default_serial
= 1;
266 static int default_parallel
= 1;
267 static int default_virtcon
= 1;
268 static int default_monitor
= 1;
269 static int default_vga
= 1;
270 static int default_floppy
= 1;
271 static int default_cdrom
= 1;
272 static int default_sdcard
= 1;
278 { .driver
= "isa-serial", .flag
= &default_serial
},
279 { .driver
= "isa-parallel", .flag
= &default_parallel
},
280 { .driver
= "isa-fdc", .flag
= &default_floppy
},
281 { .driver
= "ide-drive", .flag
= &default_cdrom
},
282 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
283 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
284 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
285 { .driver
= "VGA", .flag
= &default_vga
},
286 { .driver
= "cirrus-vga", .flag
= &default_vga
},
287 { .driver
= "vmware-svga", .flag
= &default_vga
},
290 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
292 const char *driver
= qemu_opt_get(opts
, "driver");
297 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
298 if (strcmp(default_list
[i
].driver
, driver
) != 0)
300 *(default_list
[i
].flag
) = 0;
305 /***********************************************************/
306 /* real time host monotonic timer */
308 /***********************************************************/
309 /* host time/date access */
310 void qemu_get_timedate(struct tm
*tm
, int offset
)
317 if (rtc_date_offset
== -1) {
321 ret
= localtime(&ti
);
323 ti
-= rtc_date_offset
;
327 memcpy(tm
, ret
, sizeof(struct tm
));
330 int qemu_timedate_diff(struct tm
*tm
)
334 if (rtc_date_offset
== -1)
336 seconds
= mktimegm(tm
);
338 seconds
= mktime(tm
);
340 seconds
= mktimegm(tm
) + rtc_date_offset
;
342 return seconds
- time(NULL
);
345 void rtc_change_mon_event(struct tm
*tm
)
349 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
350 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
351 qobject_decref(data
);
354 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
356 time_t rtc_start_date
;
359 if (!strcmp(startdate
, "now") && legacy
) {
360 rtc_date_offset
= -1;
362 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
370 } else if (sscanf(startdate
, "%d-%d-%d",
382 rtc_start_date
= mktimegm(&tm
);
383 if (rtc_start_date
== -1) {
385 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
386 "'2006-06-17T16:01:21' or '2006-06-17'\n");
389 rtc_date_offset
= time(NULL
) - rtc_start_date
;
393 static void configure_rtc(QemuOpts
*opts
)
397 value
= qemu_opt_get(opts
, "base");
399 if (!strcmp(value
, "utc")) {
401 } else if (!strcmp(value
, "localtime")) {
404 configure_rtc_date_offset(value
, 0);
407 value
= qemu_opt_get(opts
, "clock");
409 if (!strcmp(value
, "host")) {
410 rtc_clock
= host_clock
;
411 } else if (!strcmp(value
, "vm")) {
412 rtc_clock
= vm_clock
;
414 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
418 value
= qemu_opt_get(opts
, "driftfix");
420 if (!strcmp(value
, "slew")) {
422 } else if (!strcmp(value
, "none")) {
425 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
431 /***********************************************************/
432 /* Bluetooth support */
435 static struct HCIInfo
*hci_table
[MAX_NICS
];
437 static struct bt_vlan_s
{
438 struct bt_scatternet_s net
;
440 struct bt_vlan_s
*next
;
443 /* find or alloc a new bluetooth "VLAN" */
444 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
446 struct bt_vlan_s
**pvlan
, *vlan
;
447 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
451 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
453 pvlan
= &first_bt_vlan
;
454 while (*pvlan
!= NULL
)
455 pvlan
= &(*pvlan
)->next
;
460 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
464 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
469 static struct HCIInfo null_hci
= {
470 .cmd_send
= null_hci_send
,
471 .sco_send
= null_hci_send
,
472 .acl_send
= null_hci_send
,
473 .bdaddr_set
= null_hci_addr_set
,
476 struct HCIInfo
*qemu_next_hci(void)
478 if (cur_hci
== nb_hcis
)
481 return hci_table
[cur_hci
++];
484 static struct HCIInfo
*hci_init(const char *str
)
487 struct bt_scatternet_s
*vlan
= 0;
489 if (!strcmp(str
, "null"))
492 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
494 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
495 else if (!strncmp(str
, "hci", 3)) {
498 if (!strncmp(str
+ 3, ",vlan=", 6)) {
499 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
504 vlan
= qemu_find_bt_vlan(0);
506 return bt_new_hci(vlan
);
509 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
514 static int bt_hci_parse(const char *str
)
519 if (nb_hcis
>= MAX_NICS
) {
520 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
533 bdaddr
.b
[5] = 0x56 + nb_hcis
;
534 hci
->bdaddr_set(hci
, bdaddr
.b
);
536 hci_table
[nb_hcis
++] = hci
;
541 static void bt_vhci_add(int vlan_id
)
543 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
546 fprintf(stderr
, "qemu: warning: adding a VHCI to "
547 "an empty scatternet %i\n", vlan_id
);
549 bt_vhci_init(bt_new_hci(vlan
));
552 static struct bt_device_s
*bt_device_add(const char *opt
)
554 struct bt_scatternet_s
*vlan
;
556 char *endp
= strstr(opt
, ",vlan=");
557 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
560 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
563 vlan_id
= strtol(endp
+ 6, &endp
, 0);
565 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
570 vlan
= qemu_find_bt_vlan(vlan_id
);
573 fprintf(stderr
, "qemu: warning: adding a slave device to "
574 "an empty scatternet %i\n", vlan_id
);
576 if (!strcmp(devname
, "keyboard"))
577 return bt_keyboard_init(vlan
);
579 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
583 static int bt_parse(const char *opt
)
585 const char *endp
, *p
;
588 if (strstart(opt
, "hci", &endp
)) {
589 if (!*endp
|| *endp
== ',') {
591 if (!strstart(endp
, ",vlan=", 0))
594 return bt_hci_parse(opt
);
596 } else if (strstart(opt
, "vhci", &endp
)) {
597 if (!*endp
|| *endp
== ',') {
599 if (strstart(endp
, ",vlan=", &p
)) {
600 vlan
= strtol(p
, (char **) &endp
, 0);
602 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
606 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
615 } else if (strstart(opt
, "device:", &endp
))
616 return !bt_device_add(endp
);
618 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
622 /***********************************************************/
623 /* QEMU Block devices */
625 #define HD_OPTS "media=disk"
626 #define CDROM_OPTS "media=cdrom"
628 #define PFLASH_OPTS ""
632 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
634 int *use_scsi
= opaque
;
636 return drive_init(opts
, *use_scsi
) == NULL
;
639 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
641 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
642 qemu_opt_set(opts
, "snapshot", "on");
647 static void default_drive(int enable
, int snapshot
, int use_scsi
,
648 BlockInterfaceType type
, int index
,
653 if (type
== IF_DEFAULT
) {
654 type
= use_scsi
? IF_SCSI
: IF_IDE
;
657 if (!enable
|| drive_get_by_index(type
, index
)) {
661 opts
= drive_add(type
, index
, NULL
, optstr
);
663 drive_enable_snapshot(opts
, NULL
);
665 if (!drive_init(opts
, use_scsi
)) {
670 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
672 boot_set_handler
= func
;
673 boot_set_opaque
= opaque
;
676 int qemu_boot_set(const char *boot_devices
)
678 if (!boot_set_handler
) {
681 return boot_set_handler(boot_set_opaque
, boot_devices
);
684 static void validate_bootdevices(char *devices
)
686 /* We just do some generic consistency checks */
690 for (p
= devices
; *p
!= '\0'; p
++) {
691 /* Allowed boot devices are:
692 * a-b: floppy disk drives
693 * c-f: IDE disk drives
694 * g-m: machine implementation dependant drives
695 * n-p: network devices
696 * It's up to each machine implementation to check if the given boot
697 * devices match the actual hardware implementation and firmware
700 if (*p
< 'a' || *p
> 'p') {
701 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
704 if (bitmap
& (1 << (*p
- 'a'))) {
705 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
708 bitmap
|= 1 << (*p
- 'a');
712 static void restore_boot_devices(void *opaque
)
714 char *standard_boot_devices
= opaque
;
715 static int first
= 1;
717 /* Restore boot order and remove ourselves after the first boot */
723 qemu_boot_set(standard_boot_devices
);
725 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
726 qemu_free(standard_boot_devices
);
729 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
732 FWBootEntry
*node
, *i
;
738 assert(dev
!= NULL
|| suffix
!= NULL
);
740 node
= qemu_mallocz(sizeof(FWBootEntry
));
741 node
->bootindex
= bootindex
;
742 node
->suffix
= suffix
? qemu_strdup(suffix
) : NULL
;
745 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
746 if (i
->bootindex
== bootindex
) {
747 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
749 } else if (i
->bootindex
< bootindex
) {
752 QTAILQ_INSERT_BEFORE(i
, node
, link
);
755 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
759 * This function returns null terminated string that consist of new line
760 * separated device paths.
762 * memory pointed by "size" is assigned total length of the array in bytes
765 char *get_boot_devices_list(uint32_t *size
)
771 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
772 char *devpath
= NULL
, *bootpath
;
776 devpath
= qdev_get_fw_dev_path(i
->dev
);
780 if (i
->suffix
&& devpath
) {
781 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
783 bootpath
= qemu_malloc(bootpathlen
);
784 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
786 } else if (devpath
) {
789 bootpath
= qemu_strdup(i
->suffix
);
794 list
[total
-1] = '\n';
796 len
= strlen(bootpath
) + 1;
797 list
= qemu_realloc(list
, total
+ len
);
798 memcpy(&list
[total
], bootpath
, len
);
808 static void numa_add(const char *optarg
)
812 unsigned long long value
, endvalue
;
815 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
816 if (!strcmp(option
, "node")) {
817 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
818 nodenr
= nb_numa_nodes
;
820 nodenr
= strtoull(option
, NULL
, 10);
823 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
824 node_mem
[nodenr
] = 0;
827 sval
= strtosz(option
, NULL
);
829 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
832 node_mem
[nodenr
] = sval
;
834 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
835 node_cpumask
[nodenr
] = 0;
837 value
= strtoull(option
, &endptr
, 10);
840 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
842 if (*endptr
== '-') {
843 endvalue
= strtoull(endptr
+1, &endptr
, 10);
844 if (endvalue
>= 63) {
847 "only 63 CPUs in NUMA mode supported.\n");
849 value
= (2ULL << endvalue
) - (1ULL << value
);
851 value
= 1ULL << value
;
854 node_cpumask
[nodenr
] = value
;
861 static void smp_parse(const char *optarg
)
863 int smp
, sockets
= 0, threads
= 0, cores
= 0;
867 smp
= strtoul(optarg
, &endptr
, 10);
868 if (endptr
!= optarg
) {
869 if (*endptr
== ',') {
873 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
874 sockets
= strtoull(option
, NULL
, 10);
875 if (get_param_value(option
, 128, "cores", endptr
) != 0)
876 cores
= strtoull(option
, NULL
, 10);
877 if (get_param_value(option
, 128, "threads", endptr
) != 0)
878 threads
= strtoull(option
, NULL
, 10);
879 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
880 max_cpus
= strtoull(option
, NULL
, 10);
882 /* compute missing values, prefer sockets over cores over threads */
883 if (smp
== 0 || sockets
== 0) {
884 sockets
= sockets
> 0 ? sockets
: 1;
885 cores
= cores
> 0 ? cores
: 1;
886 threads
= threads
> 0 ? threads
: 1;
888 smp
= cores
* threads
* sockets
;
892 threads
= threads
> 0 ? threads
: 1;
893 cores
= smp
/ (sockets
* threads
);
895 threads
= smp
/ (cores
* sockets
);
899 smp_cores
= cores
> 0 ? cores
: 1;
900 smp_threads
= threads
> 0 ? threads
: 1;
905 /***********************************************************/
908 static int usb_device_add(const char *devname
)
911 USBDevice
*dev
= NULL
;
916 /* drivers with .usbdevice_name entry in USBDeviceInfo */
917 dev
= usbdevice_create(devname
);
922 if (strstart(devname
, "host:", &p
)) {
923 dev
= usb_host_device_open(p
);
924 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
925 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
926 bt_new_hci(qemu_find_bt_vlan(0)));
937 static int usb_device_del(const char *devname
)
942 if (strstart(devname
, "host:", &p
))
943 return usb_host_device_close(p
);
948 p
= strchr(devname
, '.');
951 bus_num
= strtoul(devname
, NULL
, 0);
952 addr
= strtoul(p
+ 1, NULL
, 0);
954 return usb_device_delete_addr(bus_num
, addr
);
957 static int usb_parse(const char *cmdline
)
960 r
= usb_device_add(cmdline
);
962 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
967 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
969 const char *devname
= qdict_get_str(qdict
, "devname");
970 if (usb_device_add(devname
) < 0) {
971 error_report("could not add USB device '%s'", devname
);
975 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
977 const char *devname
= qdict_get_str(qdict
, "devname");
978 if (usb_device_del(devname
) < 0) {
979 error_report("could not delete USB device '%s'", devname
);
983 /***********************************************************/
986 static struct pcmcia_socket_entry_s
{
987 PCMCIASocket
*socket
;
988 struct pcmcia_socket_entry_s
*next
;
989 } *pcmcia_sockets
= 0;
991 void pcmcia_socket_register(PCMCIASocket
*socket
)
993 struct pcmcia_socket_entry_s
*entry
;
995 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
996 entry
->socket
= socket
;
997 entry
->next
= pcmcia_sockets
;
998 pcmcia_sockets
= entry
;
1001 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
1003 struct pcmcia_socket_entry_s
*entry
, **ptr
;
1005 ptr
= &pcmcia_sockets
;
1006 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
1007 if (entry
->socket
== socket
) {
1013 void pcmcia_info(Monitor
*mon
)
1015 struct pcmcia_socket_entry_s
*iter
;
1017 if (!pcmcia_sockets
)
1018 monitor_printf(mon
, "No PCMCIA sockets\n");
1020 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1021 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1022 iter
->socket
->attached
? iter
->socket
->card_string
:
1026 /***********************************************************/
1027 /* machine registration */
1029 static QEMUMachine
*first_machine
= NULL
;
1030 QEMUMachine
*current_machine
= NULL
;
1032 int qemu_register_machine(QEMUMachine
*m
)
1035 pm
= &first_machine
;
1043 static QEMUMachine
*find_machine(const char *name
)
1047 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1048 if (!strcmp(m
->name
, name
))
1050 if (m
->alias
&& !strcmp(m
->alias
, name
))
1056 static QEMUMachine
*find_default_machine(void)
1060 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1061 if (m
->is_default
) {
1068 /***********************************************************/
1069 /* main execution loop */
1071 static void gui_update(void *opaque
)
1073 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1074 DisplayState
*ds
= opaque
;
1075 DisplayChangeListener
*dcl
= ds
->listeners
;
1077 qemu_flush_coalesced_mmio_buffer();
1080 while (dcl
!= NULL
) {
1081 if (dcl
->gui_timer_interval
&&
1082 dcl
->gui_timer_interval
< interval
)
1083 interval
= dcl
->gui_timer_interval
;
1086 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock_ms(rt_clock
));
1089 static void nographic_update(void *opaque
)
1091 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1093 qemu_flush_coalesced_mmio_buffer();
1094 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock_ms(rt_clock
));
1097 struct vm_change_state_entry
{
1098 VMChangeStateHandler
*cb
;
1100 QLIST_ENTRY (vm_change_state_entry
) entries
;
1103 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1105 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1108 VMChangeStateEntry
*e
;
1110 e
= qemu_mallocz(sizeof (*e
));
1114 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1118 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1120 QLIST_REMOVE (e
, entries
);
1124 void vm_state_notify(int running
, int reason
)
1126 VMChangeStateEntry
*e
;
1128 trace_vm_state_notify(running
, reason
);
1130 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1131 e
->cb(e
->opaque
, running
, reason
);
1140 vm_state_notify(1, 0);
1142 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1146 /* reset/shutdown handler */
1148 typedef struct QEMUResetEntry
{
1149 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1150 QEMUResetHandler
*func
;
1154 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1155 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1156 static int reset_requested
;
1157 static int shutdown_requested
, shutdown_signal
= -1;
1158 static pid_t shutdown_pid
;
1159 static int powerdown_requested
;
1160 static int debug_requested
;
1161 static int vmstop_requested
;
1163 int qemu_shutdown_requested(void)
1165 int r
= shutdown_requested
;
1166 shutdown_requested
= 0;
1170 void qemu_kill_report(void)
1172 if (shutdown_signal
!= -1) {
1173 fprintf(stderr
, "qemu: terminating on signal %d", shutdown_signal
);
1174 if (shutdown_pid
== 0) {
1175 /* This happens for eg ^C at the terminal, so it's worth
1176 * avoiding printing an odd message in that case.
1178 fputc('\n', stderr
);
1180 fprintf(stderr
, " from pid %d\n", shutdown_pid
);
1182 shutdown_signal
= -1;
1186 int qemu_reset_requested(void)
1188 int r
= reset_requested
;
1189 reset_requested
= 0;
1193 int qemu_powerdown_requested(void)
1195 int r
= powerdown_requested
;
1196 powerdown_requested
= 0;
1200 static int qemu_debug_requested(void)
1202 int r
= debug_requested
;
1203 debug_requested
= 0;
1207 static int qemu_vmstop_requested(void)
1209 int r
= vmstop_requested
;
1210 vmstop_requested
= 0;
1214 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1216 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1219 re
->opaque
= opaque
;
1220 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1223 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1227 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1228 if (re
->func
== func
&& re
->opaque
== opaque
) {
1229 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1236 void qemu_system_reset(void)
1238 QEMUResetEntry
*re
, *nre
;
1240 /* reset all devices */
1241 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1242 re
->func(re
->opaque
);
1244 monitor_protocol_event(QEVENT_RESET
, NULL
);
1245 cpu_synchronize_all_post_reset();
1248 void qemu_system_reset_request(void)
1251 shutdown_requested
= 1;
1253 reset_requested
= 1;
1256 qemu_notify_event();
1259 void qemu_system_killed(int signal
, pid_t pid
)
1261 shutdown_signal
= signal
;
1263 qemu_system_shutdown_request();
1266 void qemu_system_shutdown_request(void)
1268 shutdown_requested
= 1;
1269 qemu_notify_event();
1272 void qemu_system_powerdown_request(void)
1274 powerdown_requested
= 1;
1275 qemu_notify_event();
1278 void qemu_system_debug_request(void)
1280 debug_requested
= 1;
1281 qemu_notify_event();
1284 void qemu_system_vmstop_request(int reason
)
1286 vmstop_requested
= reason
;
1287 qemu_notify_event();
1290 void main_loop_wait(int nonblocking
)
1292 fd_set rfds
, wfds
, xfds
;
1300 timeout
= qemu_calculate_timeout();
1301 qemu_bh_update_timeout(&timeout
);
1304 os_host_main_loop_wait(&timeout
);
1306 tv
.tv_sec
= timeout
/ 1000;
1307 tv
.tv_usec
= (timeout
% 1000) * 1000;
1309 /* poll any events */
1310 /* XXX: separate device handlers from system ones */
1315 qemu_iohandler_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1316 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1318 qemu_mutex_unlock_iothread();
1319 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1320 qemu_mutex_lock_iothread();
1322 qemu_iohandler_poll(&rfds
, &wfds
, &xfds
, ret
);
1323 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1325 qemu_run_all_timers();
1327 /* Check bottom-halves last in case any of the earlier events triggered
1333 #ifndef CONFIG_IOTHREAD
1334 static int vm_request_pending(void)
1336 return powerdown_requested
||
1338 shutdown_requested
||
1344 qemu_irq qemu_system_powerdown
;
1346 static void main_loop(void)
1348 bool nonblocking
= false;
1349 #ifdef CONFIG_PROFILER
1354 qemu_main_loop_start();
1357 #ifndef CONFIG_IOTHREAD
1358 nonblocking
= cpu_exec_all();
1359 if (vm_request_pending()) {
1363 #ifdef CONFIG_PROFILER
1364 ti
= profile_getclock();
1366 main_loop_wait(nonblocking
);
1367 #ifdef CONFIG_PROFILER
1368 dev_time
+= profile_getclock() - ti
;
1371 if (qemu_debug_requested()) {
1372 vm_stop(VMSTOP_DEBUG
);
1374 if (qemu_shutdown_requested()) {
1376 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1378 vm_stop(VMSTOP_SHUTDOWN
);
1383 if (qemu_reset_requested()) {
1385 cpu_synchronize_all_states();
1386 qemu_system_reset();
1389 if (qemu_powerdown_requested()) {
1390 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1391 qemu_irq_raise(qemu_system_powerdown
);
1393 if ((r
= qemu_vmstop_requested())) {
1401 static void version(void)
1403 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1406 static void help(int exitcode
)
1408 const char *options_help
=
1409 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1411 #define DEFHEADING(text) stringify(text) "\n"
1412 #include "qemu-options.def"
1418 printf("usage: %s [options] [disk_image]\n"
1420 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1423 "During emulation, the following keys are useful:\n"
1424 "ctrl-alt-f toggle full screen\n"
1425 "ctrl-alt-n switch to virtual console 'n'\n"
1426 "ctrl-alt toggle mouse and keyboard grab\n"
1428 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1434 #define HAS_ARG 0x0001
1436 typedef struct QEMUOption
{
1443 static const QEMUOption qemu_options
[] = {
1444 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1445 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1446 { option, opt_arg, opt_enum, arch_mask },
1447 #define DEFHEADING(text)
1448 #include "qemu-options.def"
1454 static void select_vgahw (const char *p
)
1459 vga_interface_type
= VGA_NONE
;
1460 if (strstart(p
, "std", &opts
)) {
1461 vga_interface_type
= VGA_STD
;
1462 } else if (strstart(p
, "cirrus", &opts
)) {
1463 vga_interface_type
= VGA_CIRRUS
;
1464 } else if (strstart(p
, "vmware", &opts
)) {
1465 vga_interface_type
= VGA_VMWARE
;
1466 } else if (strstart(p
, "xenfb", &opts
)) {
1467 vga_interface_type
= VGA_XENFB
;
1468 } else if (strstart(p
, "qxl", &opts
)) {
1469 vga_interface_type
= VGA_QXL
;
1470 } else if (!strstart(p
, "none", &opts
)) {
1472 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1476 const char *nextopt
;
1478 if (strstart(opts
, ",retrace=", &nextopt
)) {
1480 if (strstart(opts
, "dumb", &nextopt
))
1481 vga_retrace_method
= VGA_RETRACE_DUMB
;
1482 else if (strstart(opts
, "precise", &nextopt
))
1483 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1484 else goto invalid_vga
;
1485 } else goto invalid_vga
;
1490 static DisplayType
select_display(const char *p
)
1493 DisplayType display
= DT_DEFAULT
;
1495 if (strstart(p
, "sdl", &opts
)) {
1499 const char *nextopt
;
1501 if (strstart(opts
, ",frame=", &nextopt
)) {
1503 if (strstart(opts
, "on", &nextopt
)) {
1505 } else if (strstart(opts
, "off", &nextopt
)) {
1508 goto invalid_sdl_args
;
1510 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1512 if (strstart(opts
, "on", &nextopt
)) {
1514 } else if (strstart(opts
, "off", &nextopt
)) {
1517 goto invalid_sdl_args
;
1519 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1521 if (strstart(opts
, "on", &nextopt
)) {
1523 } else if (strstart(opts
, "off", &nextopt
)) {
1526 goto invalid_sdl_args
;
1528 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
1530 if (strstart(opts
, "on", &nextopt
)) {
1532 } else if (strstart(opts
, "off", &nextopt
)) {
1535 goto invalid_sdl_args
;
1539 fprintf(stderr
, "Invalid SDL option string: %s\n", p
);
1545 fprintf(stderr
, "SDL support is disabled\n");
1548 } else if (strstart(p
, "vnc", &opts
)) {
1553 const char *nextopt
;
1555 if (strstart(opts
, "=", &nextopt
)) {
1556 vnc_display
= nextopt
;
1560 fprintf(stderr
, "VNC requires a display argument vnc=<display>\n");
1564 fprintf(stderr
, "VNC support is disabled\n");
1567 } else if (strstart(p
, "curses", &opts
)) {
1568 #ifdef CONFIG_CURSES
1569 display
= DT_CURSES
;
1571 fprintf(stderr
, "Curses support is disabled\n");
1574 } else if (strstart(p
, "none", &opts
)) {
1577 fprintf(stderr
, "Unknown display type: %s\n", p
);
1584 static int balloon_parse(const char *arg
)
1588 if (strcmp(arg
, "none") == 0) {
1592 if (!strncmp(arg
, "virtio", 6)) {
1593 if (arg
[6] == ',') {
1594 /* have params -> parse them */
1595 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1599 /* create empty opts */
1600 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1602 qemu_opt_set(opts
, "driver", "virtio-balloon");
1609 char *qemu_find_file(int type
, const char *name
)
1615 /* If name contains path separators then try it as a straight path. */
1616 if ((strchr(name
, '/') || strchr(name
, '\\'))
1617 && access(name
, R_OK
) == 0) {
1618 return qemu_strdup(name
);
1621 case QEMU_FILE_TYPE_BIOS
:
1624 case QEMU_FILE_TYPE_KEYMAP
:
1625 subdir
= "keymaps/";
1630 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1631 buf
= qemu_mallocz(len
);
1632 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1633 if (access(buf
, R_OK
)) {
1640 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1642 return qdev_device_help(opts
);
1645 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1649 dev
= qdev_device_add(opts
);
1655 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1657 CharDriverState
*chr
;
1659 chr
= qemu_chr_open_opts(opts
, NULL
);
1665 #ifdef CONFIG_VIRTFS
1666 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1669 ret
= qemu_fsdev_add(opts
);
1675 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1677 CharDriverState
*chr
;
1678 const char *chardev
;
1682 mode
= qemu_opt_get(opts
, "mode");
1686 if (strcmp(mode
, "readline") == 0) {
1687 flags
= MONITOR_USE_READLINE
;
1688 } else if (strcmp(mode
, "control") == 0) {
1689 flags
= MONITOR_USE_CONTROL
;
1691 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1695 if (qemu_opt_get_bool(opts
, "pretty", 0))
1696 flags
|= MONITOR_USE_PRETTY
;
1698 if (qemu_opt_get_bool(opts
, "default", 0))
1699 flags
|= MONITOR_IS_DEFAULT
;
1701 chardev
= qemu_opt_get(opts
, "chardev");
1702 chr
= qemu_chr_find(chardev
);
1704 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1708 monitor_init(chr
, flags
);
1712 static void monitor_parse(const char *optarg
, const char *mode
)
1714 static int monitor_device_index
= 0;
1720 if (strstart(optarg
, "chardev:", &p
)) {
1721 snprintf(label
, sizeof(label
), "%s", p
);
1723 snprintf(label
, sizeof(label
), "compat_monitor%d",
1724 monitor_device_index
);
1725 if (monitor_device_index
== 0) {
1728 opts
= qemu_chr_parse_compat(label
, optarg
);
1730 fprintf(stderr
, "parse error: %s\n", optarg
);
1735 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1737 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1740 qemu_opt_set(opts
, "mode", mode
);
1741 qemu_opt_set(opts
, "chardev", label
);
1743 qemu_opt_set(opts
, "default", "on");
1744 monitor_device_index
++;
1747 struct device_config
{
1749 DEV_USB
, /* -usbdevice */
1751 DEV_SERIAL
, /* -serial */
1752 DEV_PARALLEL
, /* -parallel */
1753 DEV_VIRTCON
, /* -virtioconsole */
1754 DEV_DEBUGCON
, /* -debugcon */
1756 const char *cmdline
;
1757 QTAILQ_ENTRY(device_config
) next
;
1759 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1761 static void add_device_config(int type
, const char *cmdline
)
1763 struct device_config
*conf
;
1765 conf
= qemu_mallocz(sizeof(*conf
));
1767 conf
->cmdline
= cmdline
;
1768 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1771 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1773 struct device_config
*conf
;
1776 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1777 if (conf
->type
!= type
)
1779 rc
= func(conf
->cmdline
);
1786 static int serial_parse(const char *devname
)
1788 static int index
= 0;
1791 if (strcmp(devname
, "none") == 0)
1793 if (index
== MAX_SERIAL_PORTS
) {
1794 fprintf(stderr
, "qemu: too many serial ports\n");
1797 snprintf(label
, sizeof(label
), "serial%d", index
);
1798 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1799 if (!serial_hds
[index
]) {
1800 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1801 devname
, strerror(errno
));
1808 static int parallel_parse(const char *devname
)
1810 static int index
= 0;
1813 if (strcmp(devname
, "none") == 0)
1815 if (index
== MAX_PARALLEL_PORTS
) {
1816 fprintf(stderr
, "qemu: too many parallel ports\n");
1819 snprintf(label
, sizeof(label
), "parallel%d", index
);
1820 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1821 if (!parallel_hds
[index
]) {
1822 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1823 devname
, strerror(errno
));
1830 static int virtcon_parse(const char *devname
)
1832 QemuOptsList
*device
= qemu_find_opts("device");
1833 static int index
= 0;
1835 QemuOpts
*bus_opts
, *dev_opts
;
1837 if (strcmp(devname
, "none") == 0)
1839 if (index
== MAX_VIRTIO_CONSOLES
) {
1840 fprintf(stderr
, "qemu: too many virtio consoles\n");
1844 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1845 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1847 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1848 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1850 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1851 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1852 if (!virtcon_hds
[index
]) {
1853 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1854 devname
, strerror(errno
));
1857 qemu_opt_set(dev_opts
, "chardev", label
);
1863 static int debugcon_parse(const char *devname
)
1867 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1870 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1872 fprintf(stderr
, "qemu: already have a debugcon device\n");
1875 qemu_opt_set(opts
, "driver", "isa-debugcon");
1876 qemu_opt_set(opts
, "chardev", "debugcon");
1880 static int tcg_init(void)
1886 const char *opt_name
;
1888 int (*available
)(void);
1892 { "tcg", "tcg", tcg_available
, tcg_init
, &tcg_allowed
},
1893 { "kvm", "KVM", kvm_available
, kvm_init
, &kvm_allowed
},
1896 static int configure_accelerator(void)
1898 const char *p
= NULL
;
1901 bool accel_initalised
= 0;
1902 bool init_failed
= 0;
1904 QemuOptsList
*list
= qemu_find_opts("machine");
1905 if (!QTAILQ_EMPTY(&list
->head
)) {
1906 p
= qemu_opt_get(QTAILQ_FIRST(&list
->head
), "accel");
1910 /* Use the default "accelerator", tcg */
1914 while (!accel_initalised
&& *p
!= '\0') {
1918 p
= get_opt_name(buf
, sizeof (buf
), p
, ':');
1919 for (i
= 0; i
< ARRAY_SIZE(accel_list
); i
++) {
1920 if (strcmp(accel_list
[i
].opt_name
, buf
) == 0) {
1921 ret
= accel_list
[i
].init();
1924 if (!accel_list
[i
].available()) {
1925 printf("%s not supported for this target\n",
1926 accel_list
[i
].name
);
1928 fprintf(stderr
, "failed to initialize %s: %s\n",
1933 accel_initalised
= 1;
1934 *(accel_list
[i
].allowed
) = 1;
1939 if (i
== ARRAY_SIZE(accel_list
)) {
1940 fprintf(stderr
, "\"%s\" accelerator does not exist.\n", buf
);
1944 if (!accel_initalised
) {
1945 fprintf(stderr
, "No accelerator found!\n");
1950 fprintf(stderr
, "Back to %s accelerator.\n", accel_list
[i
].name
);
1953 return !accel_initalised
;
1956 void qemu_add_exit_notifier(Notifier
*notify
)
1958 notifier_list_add(&exit_notifiers
, notify
);
1961 void qemu_remove_exit_notifier(Notifier
*notify
)
1963 notifier_list_remove(&exit_notifiers
, notify
);
1966 static void qemu_run_exit_notifiers(void)
1968 notifier_list_notify(&exit_notifiers
);
1971 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
1973 notifier_list_add(&machine_init_done_notifiers
, notify
);
1976 static void qemu_run_machine_init_done_notifiers(void)
1978 notifier_list_notify(&machine_init_done_notifiers
);
1981 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1982 const char **poptarg
, int *poptind
)
1984 const QEMUOption
*popt
;
1985 int optind
= *poptind
;
1986 char *r
= argv
[optind
];
1989 loc_set_cmdline(argv
, optind
, 1);
1991 /* Treat --foo the same as -foo. */
1994 popt
= qemu_options
;
1997 error_report("invalid option");
2000 if (!strcmp(popt
->name
, r
+ 1))
2004 if (popt
->flags
& HAS_ARG
) {
2005 if (optind
>= argc
) {
2006 error_report("requires an argument");
2009 optarg
= argv
[optind
++];
2010 loc_set_cmdline(argv
, optind
- 2, 2);
2021 int main(int argc
, char **argv
, char **envp
)
2023 const char *gdbstub_dev
= NULL
;
2025 int snapshot
, linux_boot
;
2026 const char *icount_option
= NULL
;
2027 const char *initrd_filename
;
2028 const char *kernel_filename
, *kernel_cmdline
;
2029 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
2031 DisplayChangeListener
*dcl
;
2032 int cyls
, heads
, secs
, translation
;
2033 QemuOpts
*hda_opts
= NULL
, *opts
;
2034 QemuOptsList
*olist
;
2037 const char *loadvm
= NULL
;
2038 QEMUMachine
*machine
;
2039 const char *cpu_model
;
2041 const char *pid_file
= NULL
;
2042 const char *incoming
= NULL
;
2044 int show_vnc_port
= 0;
2047 const char *trace_file
= NULL
;
2049 atexit(qemu_run_exit_notifiers
);
2050 error_set_progname(argv
[0]);
2054 qemu_cache_utils_init(envp
);
2056 QLIST_INIT (&vm_change_state_head
);
2057 os_setup_early_signal_handling();
2059 module_call_init(MODULE_INIT_MACHINE
);
2060 machine
= find_default_machine();
2062 initrd_filename
= NULL
;
2065 kernel_filename
= NULL
;
2066 kernel_cmdline
= "";
2067 cyls
= heads
= secs
= 0;
2068 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2070 for (i
= 0; i
< MAX_NODES
; i
++) {
2072 node_cpumask
[i
] = 0;
2081 /* first pass of option parsing */
2083 while (optind
< argc
) {
2084 if (argv
[optind
][0] != '-') {
2089 const QEMUOption
*popt
;
2091 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2092 switch (popt
->index
) {
2093 case QEMU_OPTION_nodefconfig
:
2103 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2104 if (ret
< 0 && ret
!= -ENOENT
) {
2108 ret
= qemu_read_config_file(arch_config_name
);
2109 if (ret
< 0 && ret
!= -ENOENT
) {
2115 /* second pass of option parsing */
2120 if (argv
[optind
][0] != '-') {
2121 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2123 const QEMUOption
*popt
;
2125 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2126 if (!(popt
->arch_mask
& arch_type
)) {
2127 printf("Option %s not supported for this target\n", popt
->name
);
2130 switch(popt
->index
) {
2132 machine
= find_machine(optarg
);
2135 printf("Supported machines are:\n");
2136 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
2138 printf("%-10s %s (alias of %s)\n",
2139 m
->alias
, m
->desc
, m
->name
);
2140 printf("%-10s %s%s\n",
2142 m
->is_default
? " (default)" : "");
2144 exit(*optarg
!= '?');
2147 case QEMU_OPTION_cpu
:
2148 /* hw initialization will check this */
2149 if (*optarg
== '?') {
2150 list_cpus(stdout
, &fprintf
, optarg
);
2156 case QEMU_OPTION_initrd
:
2157 initrd_filename
= optarg
;
2159 case QEMU_OPTION_hda
:
2163 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
2165 snprintf(buf
, sizeof(buf
),
2166 "%s,cyls=%d,heads=%d,secs=%d%s",
2167 HD_OPTS
, cyls
, heads
, secs
,
2168 translation
== BIOS_ATA_TRANSLATION_LBA
?
2170 translation
== BIOS_ATA_TRANSLATION_NONE
?
2171 ",trans=none" : "");
2172 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
2175 case QEMU_OPTION_hdb
:
2176 case QEMU_OPTION_hdc
:
2177 case QEMU_OPTION_hdd
:
2178 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2181 case QEMU_OPTION_drive
:
2182 if (drive_def(optarg
) == NULL
) {
2186 case QEMU_OPTION_set
:
2187 if (qemu_set_option(optarg
) != 0)
2190 case QEMU_OPTION_global
:
2191 if (qemu_global_option(optarg
) != 0)
2194 case QEMU_OPTION_mtdblock
:
2195 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2197 case QEMU_OPTION_sd
:
2198 drive_add(IF_SD
, 0, optarg
, SD_OPTS
);
2200 case QEMU_OPTION_pflash
:
2201 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2203 case QEMU_OPTION_snapshot
:
2206 case QEMU_OPTION_hdachs
:
2210 cyls
= strtol(p
, (char **)&p
, 0);
2211 if (cyls
< 1 || cyls
> 16383)
2216 heads
= strtol(p
, (char **)&p
, 0);
2217 if (heads
< 1 || heads
> 16)
2222 secs
= strtol(p
, (char **)&p
, 0);
2223 if (secs
< 1 || secs
> 63)
2227 if (!strcmp(p
, "none"))
2228 translation
= BIOS_ATA_TRANSLATION_NONE
;
2229 else if (!strcmp(p
, "lba"))
2230 translation
= BIOS_ATA_TRANSLATION_LBA
;
2231 else if (!strcmp(p
, "auto"))
2232 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2235 } else if (*p
!= '\0') {
2237 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2240 if (hda_opts
!= NULL
) {
2242 snprintf(num
, sizeof(num
), "%d", cyls
);
2243 qemu_opt_set(hda_opts
, "cyls", num
);
2244 snprintf(num
, sizeof(num
), "%d", heads
);
2245 qemu_opt_set(hda_opts
, "heads", num
);
2246 snprintf(num
, sizeof(num
), "%d", secs
);
2247 qemu_opt_set(hda_opts
, "secs", num
);
2248 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2249 qemu_opt_set(hda_opts
, "trans", "lba");
2250 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2251 qemu_opt_set(hda_opts
, "trans", "none");
2255 case QEMU_OPTION_numa
:
2256 if (nb_numa_nodes
>= MAX_NODES
) {
2257 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2262 case QEMU_OPTION_display
:
2263 display_type
= select_display(optarg
);
2265 case QEMU_OPTION_nographic
:
2266 display_type
= DT_NOGRAPHIC
;
2268 case QEMU_OPTION_curses
:
2269 #ifdef CONFIG_CURSES
2270 display_type
= DT_CURSES
;
2272 fprintf(stderr
, "Curses support is disabled\n");
2276 case QEMU_OPTION_portrait
:
2279 case QEMU_OPTION_kernel
:
2280 kernel_filename
= optarg
;
2282 case QEMU_OPTION_append
:
2283 kernel_cmdline
= optarg
;
2285 case QEMU_OPTION_cdrom
:
2286 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2288 case QEMU_OPTION_boot
:
2290 static const char * const params
[] = {
2291 "order", "once", "menu", NULL
2293 char buf
[sizeof(boot_devices
)];
2294 char *standard_boot_devices
;
2297 if (!strchr(optarg
, '=')) {
2299 pstrcpy(buf
, sizeof(buf
), optarg
);
2300 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2302 "qemu: unknown boot parameter '%s' in '%s'\n",
2308 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2309 validate_bootdevices(buf
);
2310 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2313 if (get_param_value(buf
, sizeof(buf
),
2315 validate_bootdevices(buf
);
2316 standard_boot_devices
= qemu_strdup(boot_devices
);
2317 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2318 qemu_register_reset(restore_boot_devices
,
2319 standard_boot_devices
);
2321 if (get_param_value(buf
, sizeof(buf
),
2323 if (!strcmp(buf
, "on")) {
2325 } else if (!strcmp(buf
, "off")) {
2329 "qemu: invalid option value '%s'\n",
2337 case QEMU_OPTION_fda
:
2338 case QEMU_OPTION_fdb
:
2339 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2342 case QEMU_OPTION_no_fd_bootchk
:
2345 case QEMU_OPTION_netdev
:
2346 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2350 case QEMU_OPTION_net
:
2351 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2356 case QEMU_OPTION_tftp
:
2357 legacy_tftp_prefix
= optarg
;
2359 case QEMU_OPTION_bootp
:
2360 legacy_bootp_filename
= optarg
;
2362 case QEMU_OPTION_redir
:
2363 if (net_slirp_redir(optarg
) < 0)
2367 case QEMU_OPTION_bt
:
2368 add_device_config(DEV_BT
, optarg
);
2370 case QEMU_OPTION_audio_help
:
2371 if (!(audio_available())) {
2372 printf("Option %s not supported for this target\n", popt
->name
);
2378 case QEMU_OPTION_soundhw
:
2379 if (!(audio_available())) {
2380 printf("Option %s not supported for this target\n", popt
->name
);
2383 select_soundhw (optarg
);
2388 case QEMU_OPTION_version
:
2392 case QEMU_OPTION_m
: {
2395 value
= strtosz(optarg
, NULL
);
2397 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2401 /* On 32-bit hosts, QEMU is limited by virtual address space */
2402 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2403 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2406 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2407 fprintf(stderr
, "qemu: ram size too large\n");
2413 case QEMU_OPTION_mempath
:
2417 case QEMU_OPTION_mem_prealloc
:
2422 set_cpu_log(optarg
);
2425 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2427 case QEMU_OPTION_gdb
:
2428 gdbstub_dev
= optarg
;
2433 case QEMU_OPTION_bios
:
2436 case QEMU_OPTION_singlestep
:
2443 keyboard_layout
= optarg
;
2445 case QEMU_OPTION_localtime
:
2448 case QEMU_OPTION_vga
:
2449 select_vgahw (optarg
);
2456 w
= strtol(p
, (char **)&p
, 10);
2459 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2465 h
= strtol(p
, (char **)&p
, 10);
2470 depth
= strtol(p
, (char **)&p
, 10);
2471 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2472 depth
!= 24 && depth
!= 32)
2474 } else if (*p
== '\0') {
2475 depth
= graphic_depth
;
2482 graphic_depth
= depth
;
2485 case QEMU_OPTION_echr
:
2488 term_escape_char
= strtol(optarg
, &r
, 0);
2490 printf("Bad argument to echr\n");
2493 case QEMU_OPTION_monitor
:
2494 monitor_parse(optarg
, "readline");
2495 default_monitor
= 0;
2497 case QEMU_OPTION_qmp
:
2498 monitor_parse(optarg
, "control");
2499 default_monitor
= 0;
2501 case QEMU_OPTION_mon
:
2502 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2506 default_monitor
= 0;
2508 case QEMU_OPTION_chardev
:
2509 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2514 case QEMU_OPTION_fsdev
:
2515 olist
= qemu_find_opts("fsdev");
2517 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2520 opts
= qemu_opts_parse(olist
, optarg
, 1);
2522 fprintf(stderr
, "parse error: %s\n", optarg
);
2526 case QEMU_OPTION_virtfs
: {
2530 olist
= qemu_find_opts("virtfs");
2532 fprintf(stderr
, "virtfs 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 if (qemu_opt_get(opts
, "fstype") == NULL
||
2542 qemu_opt_get(opts
, "mount_tag") == NULL
||
2543 qemu_opt_get(opts
, "path") == NULL
||
2544 qemu_opt_get(opts
, "security_model") == NULL
) {
2545 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2546 "security_model=[mapped|passthrough|none],"
2547 "mount_tag=tag.\n");
2551 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
2552 qemu_opt_get(opts
, "mount_tag"), 1);
2554 fprintf(stderr
, "duplicate fsdev id: %s\n",
2555 qemu_opt_get(opts
, "mount_tag"));
2558 qemu_opt_set(fsdev
, "fstype", qemu_opt_get(opts
, "fstype"));
2559 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"));
2560 qemu_opt_set(fsdev
, "security_model",
2561 qemu_opt_get(opts
, "security_model"));
2563 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
2564 qemu_opt_set(device
, "driver", "virtio-9p-pci");
2565 qemu_opt_set(device
, "fsdev",
2566 qemu_opt_get(opts
, "mount_tag"));
2567 qemu_opt_set(device
, "mount_tag",
2568 qemu_opt_get(opts
, "mount_tag"));
2571 case QEMU_OPTION_serial
:
2572 add_device_config(DEV_SERIAL
, optarg
);
2574 if (strncmp(optarg
, "mon:", 4) == 0) {
2575 default_monitor
= 0;
2578 case QEMU_OPTION_watchdog
:
2581 "qemu: only one watchdog option may be given\n");
2586 case QEMU_OPTION_watchdog_action
:
2587 if (select_watchdog_action(optarg
) == -1) {
2588 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2592 case QEMU_OPTION_virtiocon
:
2593 add_device_config(DEV_VIRTCON
, optarg
);
2594 default_virtcon
= 0;
2595 if (strncmp(optarg
, "mon:", 4) == 0) {
2596 default_monitor
= 0;
2599 case QEMU_OPTION_parallel
:
2600 add_device_config(DEV_PARALLEL
, optarg
);
2601 default_parallel
= 0;
2602 if (strncmp(optarg
, "mon:", 4) == 0) {
2603 default_monitor
= 0;
2606 case QEMU_OPTION_debugcon
:
2607 add_device_config(DEV_DEBUGCON
, optarg
);
2609 case QEMU_OPTION_loadvm
:
2612 case QEMU_OPTION_full_screen
:
2616 case QEMU_OPTION_no_frame
:
2619 case QEMU_OPTION_alt_grab
:
2622 case QEMU_OPTION_ctrl_grab
:
2625 case QEMU_OPTION_no_quit
:
2628 case QEMU_OPTION_sdl
:
2629 display_type
= DT_SDL
;
2632 case QEMU_OPTION_no_frame
:
2633 case QEMU_OPTION_alt_grab
:
2634 case QEMU_OPTION_ctrl_grab
:
2635 case QEMU_OPTION_no_quit
:
2636 case QEMU_OPTION_sdl
:
2637 fprintf(stderr
, "SDL support is disabled\n");
2640 case QEMU_OPTION_pidfile
:
2643 case QEMU_OPTION_win2k_hack
:
2644 win2k_install_hack
= 1;
2646 case QEMU_OPTION_rtc_td_hack
:
2649 case QEMU_OPTION_acpitable
:
2650 do_acpitable_option(optarg
);
2652 case QEMU_OPTION_smbios
:
2653 do_smbios_option(optarg
);
2655 case QEMU_OPTION_enable_kvm
:
2656 olist
= qemu_find_opts("machine");
2657 qemu_opts_reset(olist
);
2658 qemu_opts_parse(olist
, "accel=kvm", 0);
2660 case QEMU_OPTION_machine
:
2661 olist
= qemu_find_opts("machine");
2662 qemu_opts_reset(olist
);
2663 opts
= qemu_opts_parse(olist
, optarg
, 0);
2665 fprintf(stderr
, "parse error: %s\n", optarg
);
2669 case QEMU_OPTION_usb
:
2672 case QEMU_OPTION_usbdevice
:
2674 add_device_config(DEV_USB
, optarg
);
2676 case QEMU_OPTION_device
:
2677 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2681 case QEMU_OPTION_smp
:
2684 fprintf(stderr
, "Invalid number of CPUs\n");
2687 if (max_cpus
< smp_cpus
) {
2688 fprintf(stderr
, "maxcpus must be equal to or greater than "
2692 if (max_cpus
> 255) {
2693 fprintf(stderr
, "Unsupported number of maxcpus\n");
2697 case QEMU_OPTION_vnc
:
2700 vnc_display
= optarg
;
2702 fprintf(stderr
, "VNC support is disabled\n");
2706 case QEMU_OPTION_no_acpi
:
2709 case QEMU_OPTION_no_hpet
:
2712 case QEMU_OPTION_balloon
:
2713 if (balloon_parse(optarg
) < 0) {
2714 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2718 case QEMU_OPTION_no_reboot
:
2721 case QEMU_OPTION_no_shutdown
:
2724 case QEMU_OPTION_show_cursor
:
2727 case QEMU_OPTION_uuid
:
2728 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2729 fprintf(stderr
, "Fail to parse UUID string."
2730 " Wrong format.\n");
2734 case QEMU_OPTION_option_rom
:
2735 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2736 fprintf(stderr
, "Too many option ROMs\n");
2739 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
2740 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
2741 option_rom
[nb_option_roms
].bootindex
=
2742 qemu_opt_get_number(opts
, "bootindex", -1);
2743 if (!option_rom
[nb_option_roms
].name
) {
2744 fprintf(stderr
, "Option ROM file is not specified\n");
2749 case QEMU_OPTION_semihosting
:
2750 semihosting_enabled
= 1;
2752 case QEMU_OPTION_name
:
2753 qemu_name
= qemu_strdup(optarg
);
2755 char *p
= strchr(qemu_name
, ',');
2758 if (strncmp(p
, "process=", 8)) {
2759 fprintf(stderr
, "Unknown subargument %s to -name\n", p
);
2763 os_set_proc_name(p
);
2767 case QEMU_OPTION_prom_env
:
2768 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2769 fprintf(stderr
, "Too many prom variables\n");
2772 prom_envs
[nb_prom_envs
] = optarg
;
2775 case QEMU_OPTION_old_param
:
2778 case QEMU_OPTION_clock
:
2779 configure_alarms(optarg
);
2781 case QEMU_OPTION_startdate
:
2782 configure_rtc_date_offset(optarg
, 1);
2784 case QEMU_OPTION_rtc
:
2785 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2789 configure_rtc(opts
);
2791 case QEMU_OPTION_tb_size
:
2792 tb_size
= strtol(optarg
, NULL
, 0);
2796 case QEMU_OPTION_icount
:
2797 icount_option
= optarg
;
2799 case QEMU_OPTION_incoming
:
2801 incoming_expected
= true;
2803 case QEMU_OPTION_nodefaults
:
2805 default_parallel
= 0;
2806 default_virtcon
= 0;
2807 default_monitor
= 0;
2814 case QEMU_OPTION_xen_domid
:
2815 if (!(xen_available())) {
2816 printf("Option %s not supported for this target\n", popt
->name
);
2819 xen_domid
= atoi(optarg
);
2821 case QEMU_OPTION_xen_create
:
2822 if (!(xen_available())) {
2823 printf("Option %s not supported for this target\n", popt
->name
);
2826 xen_mode
= XEN_CREATE
;
2828 case QEMU_OPTION_xen_attach
:
2829 if (!(xen_available())) {
2830 printf("Option %s not supported for this target\n", popt
->name
);
2833 xen_mode
= XEN_ATTACH
;
2835 #ifdef CONFIG_SIMPLE_TRACE
2836 case QEMU_OPTION_trace
:
2837 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2839 trace_file
= qemu_opt_get(opts
, "file");
2843 case QEMU_OPTION_readconfig
:
2845 int ret
= qemu_read_config_file(optarg
);
2847 fprintf(stderr
, "read config %s: %s\n", optarg
,
2853 case QEMU_OPTION_spice
:
2854 olist
= qemu_find_opts("spice");
2856 fprintf(stderr
, "spice is not supported by this qemu build.\n");
2859 opts
= qemu_opts_parse(olist
, optarg
, 0);
2861 fprintf(stderr
, "parse error: %s\n", optarg
);
2865 case QEMU_OPTION_writeconfig
:
2868 if (strcmp(optarg
, "-") == 0) {
2871 fp
= fopen(optarg
, "w");
2873 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2877 qemu_config_write(fp
);
2882 os_parse_cmd_args(popt
->index
, optarg
);
2888 if (!st_init(trace_file
)) {
2889 fprintf(stderr
, "warning: unable to initialize simple trace backend\n");
2892 /* If no data_dir is specified then try to find it relative to the
2895 data_dir
= os_find_datadir(argv
[0]);
2897 /* If all else fails use the install patch specified when building. */
2899 data_dir
= CONFIG_QEMU_DATADIR
;
2903 * Default to max_cpus = smp_cpus, in case the user doesn't
2904 * specify a max_cpus value.
2907 max_cpus
= smp_cpus
;
2909 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2910 if (smp_cpus
> machine
->max_cpus
) {
2911 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2912 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2917 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2918 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2920 if (machine
->no_serial
) {
2923 if (machine
->no_parallel
) {
2924 default_parallel
= 0;
2926 if (!machine
->use_virtcon
) {
2927 default_virtcon
= 0;
2929 if (machine
->no_vga
) {
2932 if (machine
->no_floppy
) {
2935 if (machine
->no_cdrom
) {
2938 if (machine
->no_sdcard
) {
2942 if (display_type
== DT_NOGRAPHIC
) {
2943 if (default_parallel
)
2944 add_device_config(DEV_PARALLEL
, "null");
2945 if (default_serial
&& default_monitor
) {
2946 add_device_config(DEV_SERIAL
, "mon:stdio");
2947 } else if (default_virtcon
&& default_monitor
) {
2948 add_device_config(DEV_VIRTCON
, "mon:stdio");
2951 add_device_config(DEV_SERIAL
, "stdio");
2952 if (default_virtcon
)
2953 add_device_config(DEV_VIRTCON
, "stdio");
2954 if (default_monitor
)
2955 monitor_parse("stdio", "readline");
2959 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2960 if (default_parallel
)
2961 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2962 if (default_monitor
)
2963 monitor_parse("vc:80Cx24C", "readline");
2964 if (default_virtcon
)
2965 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2968 vga_interface_type
= VGA_CIRRUS
;
2972 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
2974 #ifdef CONFIG_VIRTFS
2975 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
2982 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2987 configure_accelerator();
2989 if (qemu_init_main_loop()) {
2990 fprintf(stderr
, "qemu_init_main_loop failed\n");
2993 linux_boot
= (kernel_filename
!= NULL
);
2995 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2996 fprintf(stderr
, "-append only allowed with -kernel option\n");
3000 if (!linux_boot
&& initrd_filename
!= NULL
) {
3001 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
3005 os_set_line_buffering();
3007 if (init_timer_alarm() < 0) {
3008 fprintf(stderr
, "could not initialize alarm timer\n");
3011 configure_icount(icount_option
);
3013 if (net_init_clients() < 0) {
3017 /* init the bluetooth world */
3018 if (foreach_device_config(DEV_BT
, bt_parse
))
3021 /* init the memory */
3023 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
3025 /* init the dynamic translator */
3026 cpu_exec_init_all(tb_size
* 1024 * 1024);
3028 bdrv_init_with_whitelist();
3032 /* open the virtual block devices */
3034 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
3035 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
3038 default_drive(default_cdrom
, snapshot
, machine
->use_scsi
,
3039 IF_DEFAULT
, 2, CDROM_OPTS
);
3040 default_drive(default_floppy
, snapshot
, machine
->use_scsi
,
3041 IF_FLOPPY
, 0, FD_OPTS
);
3042 default_drive(default_sdcard
, snapshot
, machine
->use_scsi
,
3045 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
3048 if (nb_numa_nodes
> 0) {
3051 if (nb_numa_nodes
> smp_cpus
) {
3052 nb_numa_nodes
= smp_cpus
;
3055 /* If no memory size if given for any node, assume the default case
3056 * and distribute the available memory equally across all nodes
3058 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3059 if (node_mem
[i
] != 0)
3062 if (i
== nb_numa_nodes
) {
3063 uint64_t usedmem
= 0;
3065 /* On Linux, the each node's border has to be 8MB aligned,
3066 * the final node gets the rest.
3068 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
3069 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
3070 usedmem
+= node_mem
[i
];
3072 node_mem
[i
] = ram_size
- usedmem
;
3075 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3076 if (node_cpumask
[i
] != 0)
3079 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3080 * must cope with this anyway, because there are BIOSes out there in
3081 * real machines which also use this scheme.
3083 if (i
== nb_numa_nodes
) {
3084 for (i
= 0; i
< smp_cpus
; i
++) {
3085 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
3090 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
3094 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
3096 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
3098 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
3100 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
3103 module_call_init(MODULE_INIT_DEVICE
);
3105 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
3109 i
= select_watchdog(watchdog
);
3111 exit (i
== 1 ? 1 : 0);
3114 if (machine
->compat_props
) {
3115 qdev_prop_register_global_list(machine
->compat_props
);
3119 machine
->init(ram_size
, boot_devices
,
3120 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
3122 cpu_synchronize_all_post_init();
3126 current_machine
= machine
;
3128 /* init USB devices */
3130 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
3134 /* init generic devices */
3135 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3138 net_check_clients();
3140 /* just use the first displaystate for the moment */
3141 ds
= get_displaystate();
3145 if (display_type
== DT_DEFAULT
&& !display_remote
) {
3146 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3147 display_type
= DT_SDL
;
3148 #elif defined(CONFIG_VNC)
3149 vnc_display
= "localhost:0,to=99";
3152 display_type
= DT_NONE
;
3157 /* init local displays */
3158 switch (display_type
) {
3161 #if defined(CONFIG_CURSES)
3163 curses_display_init(ds
, full_screen
);
3166 #if defined(CONFIG_SDL)
3168 sdl_display_init(ds
, full_screen
, no_frame
);
3170 #elif defined(CONFIG_COCOA)
3172 cocoa_display_init(ds
, full_screen
);
3179 /* must be after terminal init, SDL library changes signal handlers */
3180 os_setup_signal_handling();
3183 /* init remote displays */
3185 vnc_display_init(ds
);
3186 if (vnc_display_open(ds
, vnc_display
) < 0)
3189 if (show_vnc_port
) {
3190 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3195 if (using_spice
&& !qxl_enabled
) {
3196 qemu_spice_display_init(ds
);
3202 dcl
= ds
->listeners
;
3203 while (dcl
!= NULL
) {
3204 if (dcl
->dpy_refresh
!= NULL
) {
3205 ds
->gui_timer
= qemu_new_timer_ms(rt_clock
, gui_update
, ds
);
3206 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock_ms(rt_clock
));
3211 if (ds
->gui_timer
== NULL
) {
3212 nographic_timer
= qemu_new_timer_ms(rt_clock
, nographic_update
, NULL
);
3213 qemu_mod_timer(nographic_timer
, qemu_get_clock_ms(rt_clock
));
3215 text_consoles_set_display(ds
);
3217 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3218 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3223 qdev_machine_creation_done();
3225 if (rom_load_all() != 0) {
3226 fprintf(stderr
, "rom loading failed\n");
3230 /* TODO: once all bus devices are qdevified, this should be done
3231 * when bus is created by qdev.c */
3232 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
3233 qemu_run_machine_init_done_notifiers();
3235 qemu_system_reset();
3237 if (load_vmstate(loadvm
) < 0) {
3243 int ret
= qemu_start_incoming_migration(incoming
);
3245 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3249 } else if (autostart
) {