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_ALIAS "index=%d,media=disk"
625 #define CDROM_ALIAS "index=2,media=cdrom"
626 #define FD_ALIAS "index=%d,if=floppy"
627 #define PFLASH_ALIAS "if=pflash"
628 #define MTD_ALIAS "if=mtd"
629 #define SD_ALIAS "index=0,if=sd"
631 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
633 int *use_scsi
= opaque
;
636 if (drive_init(opts
, *use_scsi
, &fatal_error
) == NULL
) {
643 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
645 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
646 qemu_opt_set(opts
, "snapshot", "on");
651 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
653 boot_set_handler
= func
;
654 boot_set_opaque
= opaque
;
657 int qemu_boot_set(const char *boot_devices
)
659 if (!boot_set_handler
) {
662 return boot_set_handler(boot_set_opaque
, boot_devices
);
665 static void validate_bootdevices(char *devices
)
667 /* We just do some generic consistency checks */
671 for (p
= devices
; *p
!= '\0'; p
++) {
672 /* Allowed boot devices are:
673 * a-b: floppy disk drives
674 * c-f: IDE disk drives
675 * g-m: machine implementation dependant drives
676 * n-p: network devices
677 * It's up to each machine implementation to check if the given boot
678 * devices match the actual hardware implementation and firmware
681 if (*p
< 'a' || *p
> 'p') {
682 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
685 if (bitmap
& (1 << (*p
- 'a'))) {
686 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
689 bitmap
|= 1 << (*p
- 'a');
693 static void restore_boot_devices(void *opaque
)
695 char *standard_boot_devices
= opaque
;
696 static int first
= 1;
698 /* Restore boot order and remove ourselves after the first boot */
704 qemu_boot_set(standard_boot_devices
);
706 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
707 qemu_free(standard_boot_devices
);
710 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
713 FWBootEntry
*node
, *i
;
719 assert(dev
!= NULL
|| suffix
!= NULL
);
721 node
= qemu_mallocz(sizeof(FWBootEntry
));
722 node
->bootindex
= bootindex
;
723 node
->suffix
= strdup(suffix
);
726 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
727 if (i
->bootindex
== bootindex
) {
728 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
730 } else if (i
->bootindex
< bootindex
) {
733 QTAILQ_INSERT_BEFORE(i
, node
, link
);
736 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
740 * This function returns null terminated string that consist of new line
741 * separated device pathes.
743 * memory pointed by "size" is assigned total length of the array in bytes
746 char *get_boot_devices_list(uint32_t *size
)
752 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
753 char *devpath
= NULL
, *bootpath
;
757 devpath
= qdev_get_fw_dev_path(i
->dev
);
761 if (i
->suffix
&& devpath
) {
762 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
764 bootpath
= qemu_malloc(bootpathlen
);
765 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
767 } else if (devpath
) {
770 bootpath
= strdup(i
->suffix
);
775 list
[total
-1] = '\n';
777 len
= strlen(bootpath
) + 1;
778 list
= qemu_realloc(list
, total
+ len
);
779 memcpy(&list
[total
], bootpath
, len
);
789 static void numa_add(const char *optarg
)
793 unsigned long long value
, endvalue
;
796 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
797 if (!strcmp(option
, "node")) {
798 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
799 nodenr
= nb_numa_nodes
;
801 nodenr
= strtoull(option
, NULL
, 10);
804 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
805 node_mem
[nodenr
] = 0;
808 sval
= strtosz(option
, NULL
);
810 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
813 node_mem
[nodenr
] = sval
;
815 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
816 node_cpumask
[nodenr
] = 0;
818 value
= strtoull(option
, &endptr
, 10);
821 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
823 if (*endptr
== '-') {
824 endvalue
= strtoull(endptr
+1, &endptr
, 10);
825 if (endvalue
>= 63) {
828 "only 63 CPUs in NUMA mode supported.\n");
830 value
= (2ULL << endvalue
) - (1ULL << value
);
832 value
= 1ULL << value
;
835 node_cpumask
[nodenr
] = value
;
842 static void smp_parse(const char *optarg
)
844 int smp
, sockets
= 0, threads
= 0, cores
= 0;
848 smp
= strtoul(optarg
, &endptr
, 10);
849 if (endptr
!= optarg
) {
850 if (*endptr
== ',') {
854 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
855 sockets
= strtoull(option
, NULL
, 10);
856 if (get_param_value(option
, 128, "cores", endptr
) != 0)
857 cores
= strtoull(option
, NULL
, 10);
858 if (get_param_value(option
, 128, "threads", endptr
) != 0)
859 threads
= strtoull(option
, NULL
, 10);
860 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
861 max_cpus
= strtoull(option
, NULL
, 10);
863 /* compute missing values, prefer sockets over cores over threads */
864 if (smp
== 0 || sockets
== 0) {
865 sockets
= sockets
> 0 ? sockets
: 1;
866 cores
= cores
> 0 ? cores
: 1;
867 threads
= threads
> 0 ? threads
: 1;
869 smp
= cores
* threads
* sockets
;
873 threads
= threads
> 0 ? threads
: 1;
874 cores
= smp
/ (sockets
* threads
);
876 threads
= smp
/ (cores
* sockets
);
880 smp_cores
= cores
> 0 ? cores
: 1;
881 smp_threads
= threads
> 0 ? threads
: 1;
886 /***********************************************************/
889 static int usb_device_add(const char *devname
)
892 USBDevice
*dev
= NULL
;
897 /* drivers with .usbdevice_name entry in USBDeviceInfo */
898 dev
= usbdevice_create(devname
);
903 if (strstart(devname
, "host:", &p
)) {
904 dev
= usb_host_device_open(p
);
905 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
906 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
907 bt_new_hci(qemu_find_bt_vlan(0)));
918 static int usb_device_del(const char *devname
)
923 if (strstart(devname
, "host:", &p
))
924 return usb_host_device_close(p
);
929 p
= strchr(devname
, '.');
932 bus_num
= strtoul(devname
, NULL
, 0);
933 addr
= strtoul(p
+ 1, NULL
, 0);
935 return usb_device_delete_addr(bus_num
, addr
);
938 static int usb_parse(const char *cmdline
)
941 r
= usb_device_add(cmdline
);
943 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
948 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
950 const char *devname
= qdict_get_str(qdict
, "devname");
951 if (usb_device_add(devname
) < 0) {
952 error_report("could not add USB device '%s'", devname
);
956 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
958 const char *devname
= qdict_get_str(qdict
, "devname");
959 if (usb_device_del(devname
) < 0) {
960 error_report("could not delete USB device '%s'", devname
);
964 /***********************************************************/
967 static struct pcmcia_socket_entry_s
{
968 PCMCIASocket
*socket
;
969 struct pcmcia_socket_entry_s
*next
;
970 } *pcmcia_sockets
= 0;
972 void pcmcia_socket_register(PCMCIASocket
*socket
)
974 struct pcmcia_socket_entry_s
*entry
;
976 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
977 entry
->socket
= socket
;
978 entry
->next
= pcmcia_sockets
;
979 pcmcia_sockets
= entry
;
982 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
984 struct pcmcia_socket_entry_s
*entry
, **ptr
;
986 ptr
= &pcmcia_sockets
;
987 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
988 if (entry
->socket
== socket
) {
994 void pcmcia_info(Monitor
*mon
)
996 struct pcmcia_socket_entry_s
*iter
;
999 monitor_printf(mon
, "No PCMCIA sockets\n");
1001 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1002 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1003 iter
->socket
->attached
? iter
->socket
->card_string
:
1007 /***********************************************************/
1010 typedef struct IOHandlerRecord
{
1012 IOCanReadHandler
*fd_read_poll
;
1014 IOHandler
*fd_write
;
1017 /* temporary data */
1019 QLIST_ENTRY(IOHandlerRecord
) next
;
1022 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
1023 QLIST_HEAD_INITIALIZER(io_handlers
);
1026 /* XXX: fd_read_poll should be suppressed, but an API change is
1027 necessary in the character devices to suppress fd_can_read(). */
1028 int qemu_set_fd_handler2(int fd
,
1029 IOCanReadHandler
*fd_read_poll
,
1031 IOHandler
*fd_write
,
1034 IOHandlerRecord
*ioh
;
1036 if (!fd_read
&& !fd_write
) {
1037 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1038 if (ioh
->fd
== fd
) {
1044 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1048 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
1049 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
1052 ioh
->fd_read_poll
= fd_read_poll
;
1053 ioh
->fd_read
= fd_read
;
1054 ioh
->fd_write
= fd_write
;
1055 ioh
->opaque
= opaque
;
1061 int qemu_set_fd_handler(int fd
,
1063 IOHandler
*fd_write
,
1066 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
1069 /***********************************************************/
1070 /* machine registration */
1072 static QEMUMachine
*first_machine
= NULL
;
1073 QEMUMachine
*current_machine
= NULL
;
1075 int qemu_register_machine(QEMUMachine
*m
)
1078 pm
= &first_machine
;
1086 static QEMUMachine
*find_machine(const char *name
)
1090 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1091 if (!strcmp(m
->name
, name
))
1093 if (m
->alias
&& !strcmp(m
->alias
, name
))
1099 static QEMUMachine
*find_default_machine(void)
1103 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1104 if (m
->is_default
) {
1111 /***********************************************************/
1112 /* main execution loop */
1114 static void gui_update(void *opaque
)
1116 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1117 DisplayState
*ds
= opaque
;
1118 DisplayChangeListener
*dcl
= ds
->listeners
;
1120 qemu_flush_coalesced_mmio_buffer();
1123 while (dcl
!= NULL
) {
1124 if (dcl
->gui_timer_interval
&&
1125 dcl
->gui_timer_interval
< interval
)
1126 interval
= dcl
->gui_timer_interval
;
1129 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1132 static void nographic_update(void *opaque
)
1134 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1136 qemu_flush_coalesced_mmio_buffer();
1137 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1140 struct vm_change_state_entry
{
1141 VMChangeStateHandler
*cb
;
1143 QLIST_ENTRY (vm_change_state_entry
) entries
;
1146 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1148 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1151 VMChangeStateEntry
*e
;
1153 e
= qemu_mallocz(sizeof (*e
));
1157 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1161 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1163 QLIST_REMOVE (e
, entries
);
1167 void vm_state_notify(int running
, int reason
)
1169 VMChangeStateEntry
*e
;
1171 trace_vm_state_notify(running
, reason
);
1173 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1174 e
->cb(e
->opaque
, running
, reason
);
1183 vm_state_notify(1, 0);
1185 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1189 /* reset/shutdown handler */
1191 typedef struct QEMUResetEntry
{
1192 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1193 QEMUResetHandler
*func
;
1197 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1198 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1199 static int reset_requested
;
1200 static int shutdown_requested
;
1201 static int powerdown_requested
;
1202 int debug_requested
;
1203 int vmstop_requested
;
1205 int qemu_shutdown_requested(void)
1207 int r
= shutdown_requested
;
1208 shutdown_requested
= 0;
1212 int qemu_reset_requested(void)
1214 int r
= reset_requested
;
1215 reset_requested
= 0;
1219 int qemu_powerdown_requested(void)
1221 int r
= powerdown_requested
;
1222 powerdown_requested
= 0;
1226 static int qemu_debug_requested(void)
1228 int r
= debug_requested
;
1229 debug_requested
= 0;
1233 static int qemu_vmstop_requested(void)
1235 int r
= vmstop_requested
;
1236 vmstop_requested
= 0;
1240 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1242 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1245 re
->opaque
= opaque
;
1246 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1249 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1253 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1254 if (re
->func
== func
&& re
->opaque
== opaque
) {
1255 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1262 void qemu_system_reset(void)
1264 QEMUResetEntry
*re
, *nre
;
1266 /* reset all devices */
1267 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1268 re
->func(re
->opaque
);
1270 monitor_protocol_event(QEVENT_RESET
, NULL
);
1271 cpu_synchronize_all_post_reset();
1274 void qemu_system_reset_request(void)
1277 shutdown_requested
= 1;
1279 reset_requested
= 1;
1281 qemu_notify_event();
1284 void qemu_system_shutdown_request(void)
1286 shutdown_requested
= 1;
1287 qemu_notify_event();
1290 void qemu_system_powerdown_request(void)
1292 powerdown_requested
= 1;
1293 qemu_notify_event();
1296 void main_loop_wait(int nonblocking
)
1298 IOHandlerRecord
*ioh
;
1299 fd_set rfds
, wfds
, xfds
;
1307 timeout
= qemu_calculate_timeout();
1308 qemu_bh_update_timeout(&timeout
);
1311 os_host_main_loop_wait(&timeout
);
1313 /* poll any events */
1314 /* XXX: separate device handlers from system ones */
1319 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1323 (!ioh
->fd_read_poll
||
1324 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1325 FD_SET(ioh
->fd
, &rfds
);
1329 if (ioh
->fd_write
) {
1330 FD_SET(ioh
->fd
, &wfds
);
1336 tv
.tv_sec
= timeout
/ 1000;
1337 tv
.tv_usec
= (timeout
% 1000) * 1000;
1339 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1341 qemu_mutex_unlock_iothread();
1342 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1343 qemu_mutex_lock_iothread();
1345 IOHandlerRecord
*pioh
;
1347 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1348 if (!ioh
->deleted
&& ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1349 ioh
->fd_read(ioh
->opaque
);
1351 if (!ioh
->deleted
&& ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1352 ioh
->fd_write(ioh
->opaque
);
1355 /* Do this last in case read/write handlers marked it for deletion */
1357 QLIST_REMOVE(ioh
, next
);
1363 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1365 qemu_run_all_timers();
1367 /* Check bottom-halves last in case any of the earlier events triggered
1373 static int vm_can_run(void)
1375 if (powerdown_requested
)
1377 if (reset_requested
)
1379 if (shutdown_requested
)
1381 if (debug_requested
)
1386 qemu_irq qemu_system_powerdown
;
1388 static void main_loop(void)
1392 qemu_main_loop_start();
1396 bool nonblocking
= false;
1397 #ifdef CONFIG_PROFILER
1400 #ifndef CONFIG_IOTHREAD
1401 nonblocking
= cpu_exec_all();
1403 #ifdef CONFIG_PROFILER
1404 ti
= profile_getclock();
1406 main_loop_wait(nonblocking
);
1407 #ifdef CONFIG_PROFILER
1408 dev_time
+= profile_getclock() - ti
;
1410 } while (vm_can_run());
1412 if ((r
= qemu_debug_requested())) {
1415 if (qemu_shutdown_requested()) {
1416 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1423 if (qemu_reset_requested()) {
1425 qemu_system_reset();
1428 if (qemu_powerdown_requested()) {
1429 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1430 qemu_irq_raise(qemu_system_powerdown
);
1432 if ((r
= qemu_vmstop_requested())) {
1440 static void version(void)
1442 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1445 static void help(int exitcode
)
1447 const char *options_help
=
1448 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1450 #define DEFHEADING(text) stringify(text) "\n"
1451 #include "qemu-options.def"
1457 printf("usage: %s [options] [disk_image]\n"
1459 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1462 "During emulation, the following keys are useful:\n"
1463 "ctrl-alt-f toggle full screen\n"
1464 "ctrl-alt-n switch to virtual console 'n'\n"
1465 "ctrl-alt toggle mouse and keyboard grab\n"
1467 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1473 #define HAS_ARG 0x0001
1475 typedef struct QEMUOption
{
1482 static const QEMUOption qemu_options
[] = {
1483 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1484 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1485 { option, opt_arg, opt_enum, arch_mask },
1486 #define DEFHEADING(text)
1487 #include "qemu-options.def"
1493 static void select_vgahw (const char *p
)
1498 vga_interface_type
= VGA_NONE
;
1499 if (strstart(p
, "std", &opts
)) {
1500 vga_interface_type
= VGA_STD
;
1501 } else if (strstart(p
, "cirrus", &opts
)) {
1502 vga_interface_type
= VGA_CIRRUS
;
1503 } else if (strstart(p
, "vmware", &opts
)) {
1504 vga_interface_type
= VGA_VMWARE
;
1505 } else if (strstart(p
, "xenfb", &opts
)) {
1506 vga_interface_type
= VGA_XENFB
;
1507 } else if (strstart(p
, "qxl", &opts
)) {
1508 vga_interface_type
= VGA_QXL
;
1509 } else if (!strstart(p
, "none", &opts
)) {
1511 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1515 const char *nextopt
;
1517 if (strstart(opts
, ",retrace=", &nextopt
)) {
1519 if (strstart(opts
, "dumb", &nextopt
))
1520 vga_retrace_method
= VGA_RETRACE_DUMB
;
1521 else if (strstart(opts
, "precise", &nextopt
))
1522 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1523 else goto invalid_vga
;
1524 } else goto invalid_vga
;
1529 static int balloon_parse(const char *arg
)
1533 if (strcmp(arg
, "none") == 0) {
1537 if (!strncmp(arg
, "virtio", 6)) {
1538 if (arg
[6] == ',') {
1539 /* have params -> parse them */
1540 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1544 /* create empty opts */
1545 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1547 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1554 char *qemu_find_file(int type
, const char *name
)
1560 /* If name contains path separators then try it as a straight path. */
1561 if ((strchr(name
, '/') || strchr(name
, '\\'))
1562 && access(name
, R_OK
) == 0) {
1563 return qemu_strdup(name
);
1566 case QEMU_FILE_TYPE_BIOS
:
1569 case QEMU_FILE_TYPE_KEYMAP
:
1570 subdir
= "keymaps/";
1575 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1576 buf
= qemu_mallocz(len
);
1577 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1578 if (access(buf
, R_OK
)) {
1585 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1587 return qdev_device_help(opts
);
1590 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1594 dev
= qdev_device_add(opts
);
1600 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1602 CharDriverState
*chr
;
1604 chr
= qemu_chr_open_opts(opts
, NULL
);
1610 #ifdef CONFIG_VIRTFS
1611 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1614 ret
= qemu_fsdev_add(opts
);
1620 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1622 CharDriverState
*chr
;
1623 const char *chardev
;
1627 mode
= qemu_opt_get(opts
, "mode");
1631 if (strcmp(mode
, "readline") == 0) {
1632 flags
= MONITOR_USE_READLINE
;
1633 } else if (strcmp(mode
, "control") == 0) {
1634 flags
= MONITOR_USE_CONTROL
;
1636 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1640 if (qemu_opt_get_bool(opts
, "pretty", 0))
1641 flags
|= MONITOR_USE_PRETTY
;
1643 if (qemu_opt_get_bool(opts
, "default", 0))
1644 flags
|= MONITOR_IS_DEFAULT
;
1646 chardev
= qemu_opt_get(opts
, "chardev");
1647 chr
= qemu_chr_find(chardev
);
1649 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1653 monitor_init(chr
, flags
);
1657 static void monitor_parse(const char *optarg
, const char *mode
)
1659 static int monitor_device_index
= 0;
1665 if (strstart(optarg
, "chardev:", &p
)) {
1666 snprintf(label
, sizeof(label
), "%s", p
);
1668 snprintf(label
, sizeof(label
), "compat_monitor%d",
1669 monitor_device_index
);
1670 if (monitor_device_index
== 0) {
1673 opts
= qemu_chr_parse_compat(label
, optarg
);
1675 fprintf(stderr
, "parse error: %s\n", optarg
);
1680 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1682 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1685 qemu_opt_set(opts
, "mode", mode
);
1686 qemu_opt_set(opts
, "chardev", label
);
1688 qemu_opt_set(opts
, "default", "on");
1689 monitor_device_index
++;
1692 struct device_config
{
1694 DEV_USB
, /* -usbdevice */
1696 DEV_SERIAL
, /* -serial */
1697 DEV_PARALLEL
, /* -parallel */
1698 DEV_VIRTCON
, /* -virtioconsole */
1699 DEV_DEBUGCON
, /* -debugcon */
1701 const char *cmdline
;
1702 QTAILQ_ENTRY(device_config
) next
;
1704 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1706 static void add_device_config(int type
, const char *cmdline
)
1708 struct device_config
*conf
;
1710 conf
= qemu_mallocz(sizeof(*conf
));
1712 conf
->cmdline
= cmdline
;
1713 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1716 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1718 struct device_config
*conf
;
1721 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1722 if (conf
->type
!= type
)
1724 rc
= func(conf
->cmdline
);
1731 static int serial_parse(const char *devname
)
1733 static int index
= 0;
1736 if (strcmp(devname
, "none") == 0)
1738 if (index
== MAX_SERIAL_PORTS
) {
1739 fprintf(stderr
, "qemu: too many serial ports\n");
1742 snprintf(label
, sizeof(label
), "serial%d", index
);
1743 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1744 if (!serial_hds
[index
]) {
1745 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1746 devname
, strerror(errno
));
1753 static int parallel_parse(const char *devname
)
1755 static int index
= 0;
1758 if (strcmp(devname
, "none") == 0)
1760 if (index
== MAX_PARALLEL_PORTS
) {
1761 fprintf(stderr
, "qemu: too many parallel ports\n");
1764 snprintf(label
, sizeof(label
), "parallel%d", index
);
1765 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1766 if (!parallel_hds
[index
]) {
1767 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1768 devname
, strerror(errno
));
1775 static int virtcon_parse(const char *devname
)
1777 QemuOptsList
*device
= qemu_find_opts("device");
1778 static int index
= 0;
1780 QemuOpts
*bus_opts
, *dev_opts
;
1782 if (strcmp(devname
, "none") == 0)
1784 if (index
== MAX_VIRTIO_CONSOLES
) {
1785 fprintf(stderr
, "qemu: too many virtio consoles\n");
1789 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1790 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1792 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1793 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1795 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1796 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1797 if (!virtcon_hds
[index
]) {
1798 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1799 devname
, strerror(errno
));
1802 qemu_opt_set(dev_opts
, "chardev", label
);
1808 static int debugcon_parse(const char *devname
)
1812 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1815 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1817 fprintf(stderr
, "qemu: already have a debugcon device\n");
1820 qemu_opt_set(opts
, "driver", "isa-debugcon");
1821 qemu_opt_set(opts
, "chardev", "debugcon");
1825 void qemu_add_exit_notifier(Notifier
*notify
)
1827 notifier_list_add(&exit_notifiers
, notify
);
1830 void qemu_remove_exit_notifier(Notifier
*notify
)
1832 notifier_list_remove(&exit_notifiers
, notify
);
1835 static void qemu_run_exit_notifiers(void)
1837 notifier_list_notify(&exit_notifiers
);
1840 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
1842 notifier_list_add(&machine_init_done_notifiers
, notify
);
1845 static void qemu_run_machine_init_done_notifiers(void)
1847 notifier_list_notify(&machine_init_done_notifiers
);
1850 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1851 const char **poptarg
, int *poptind
)
1853 const QEMUOption
*popt
;
1854 int optind
= *poptind
;
1855 char *r
= argv
[optind
];
1858 loc_set_cmdline(argv
, optind
, 1);
1860 /* Treat --foo the same as -foo. */
1863 popt
= qemu_options
;
1866 error_report("invalid option");
1869 if (!strcmp(popt
->name
, r
+ 1))
1873 if (popt
->flags
& HAS_ARG
) {
1874 if (optind
>= argc
) {
1875 error_report("requires an argument");
1878 optarg
= argv
[optind
++];
1879 loc_set_cmdline(argv
, optind
- 2, 2);
1890 int main(int argc
, char **argv
, char **envp
)
1892 const char *gdbstub_dev
= NULL
;
1894 int snapshot
, linux_boot
;
1895 const char *icount_option
= NULL
;
1896 const char *initrd_filename
;
1897 const char *kernel_filename
, *kernel_cmdline
;
1898 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1900 DisplayChangeListener
*dcl
;
1901 int cyls
, heads
, secs
, translation
;
1902 QemuOpts
*hda_opts
= NULL
, *opts
;
1903 QemuOptsList
*olist
;
1906 const char *loadvm
= NULL
;
1907 QEMUMachine
*machine
;
1908 const char *cpu_model
;
1910 const char *pid_file
= NULL
;
1911 const char *incoming
= NULL
;
1912 int show_vnc_port
= 0;
1915 #ifdef CONFIG_SIMPLE_TRACE
1916 const char *trace_file
= NULL
;
1918 atexit(qemu_run_exit_notifiers
);
1919 error_set_progname(argv
[0]);
1923 qemu_cache_utils_init(envp
);
1925 QLIST_INIT (&vm_change_state_head
);
1926 os_setup_early_signal_handling();
1928 module_call_init(MODULE_INIT_MACHINE
);
1929 machine
= find_default_machine();
1931 initrd_filename
= NULL
;
1934 kernel_filename
= NULL
;
1935 kernel_cmdline
= "";
1936 cyls
= heads
= secs
= 0;
1937 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1939 for (i
= 0; i
< MAX_NODES
; i
++) {
1941 node_cpumask
[i
] = 0;
1950 /* first pass of option parsing */
1952 while (optind
< argc
) {
1953 if (argv
[optind
][0] != '-') {
1958 const QEMUOption
*popt
;
1960 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1961 switch (popt
->index
) {
1962 case QEMU_OPTION_nodefconfig
:
1972 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1973 if (ret
< 0 && ret
!= -ENOENT
) {
1977 ret
= qemu_read_config_file(arch_config_name
);
1978 if (ret
< 0 && ret
!= -ENOENT
) {
1984 /* second pass of option parsing */
1989 if (argv
[optind
][0] != '-') {
1990 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1992 const QEMUOption
*popt
;
1994 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1995 if (!(popt
->arch_mask
& arch_type
)) {
1996 printf("Option %s not supported for this target\n", popt
->name
);
1999 switch(popt
->index
) {
2001 machine
= find_machine(optarg
);
2004 printf("Supported machines are:\n");
2005 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
2007 printf("%-10s %s (alias of %s)\n",
2008 m
->alias
, m
->desc
, m
->name
);
2009 printf("%-10s %s%s\n",
2011 m
->is_default
? " (default)" : "");
2013 exit(*optarg
!= '?');
2016 case QEMU_OPTION_cpu
:
2017 /* hw initialization will check this */
2018 if (*optarg
== '?') {
2019 list_cpus(stdout
, &fprintf
, optarg
);
2025 case QEMU_OPTION_initrd
:
2026 initrd_filename
= optarg
;
2028 case QEMU_OPTION_hda
:
2030 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
2032 hda_opts
= drive_add(optarg
, HD_ALIAS
2033 ",cyls=%d,heads=%d,secs=%d%s",
2034 0, cyls
, heads
, secs
,
2035 translation
== BIOS_ATA_TRANSLATION_LBA
?
2037 translation
== BIOS_ATA_TRANSLATION_NONE
?
2038 ",trans=none" : "");
2040 case QEMU_OPTION_hdb
:
2041 case QEMU_OPTION_hdc
:
2042 case QEMU_OPTION_hdd
:
2043 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
2045 case QEMU_OPTION_drive
:
2046 drive_add(NULL
, "%s", optarg
);
2048 case QEMU_OPTION_set
:
2049 if (qemu_set_option(optarg
) != 0)
2052 case QEMU_OPTION_global
:
2053 if (qemu_global_option(optarg
) != 0)
2056 case QEMU_OPTION_mtdblock
:
2057 drive_add(optarg
, MTD_ALIAS
);
2059 case QEMU_OPTION_sd
:
2060 drive_add(optarg
, SD_ALIAS
);
2062 case QEMU_OPTION_pflash
:
2063 drive_add(optarg
, PFLASH_ALIAS
);
2065 case QEMU_OPTION_snapshot
:
2068 case QEMU_OPTION_hdachs
:
2072 cyls
= strtol(p
, (char **)&p
, 0);
2073 if (cyls
< 1 || cyls
> 16383)
2078 heads
= strtol(p
, (char **)&p
, 0);
2079 if (heads
< 1 || heads
> 16)
2084 secs
= strtol(p
, (char **)&p
, 0);
2085 if (secs
< 1 || secs
> 63)
2089 if (!strcmp(p
, "none"))
2090 translation
= BIOS_ATA_TRANSLATION_NONE
;
2091 else if (!strcmp(p
, "lba"))
2092 translation
= BIOS_ATA_TRANSLATION_LBA
;
2093 else if (!strcmp(p
, "auto"))
2094 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2097 } else if (*p
!= '\0') {
2099 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2102 if (hda_opts
!= NULL
) {
2104 snprintf(num
, sizeof(num
), "%d", cyls
);
2105 qemu_opt_set(hda_opts
, "cyls", num
);
2106 snprintf(num
, sizeof(num
), "%d", heads
);
2107 qemu_opt_set(hda_opts
, "heads", num
);
2108 snprintf(num
, sizeof(num
), "%d", secs
);
2109 qemu_opt_set(hda_opts
, "secs", num
);
2110 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2111 qemu_opt_set(hda_opts
, "trans", "lba");
2112 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2113 qemu_opt_set(hda_opts
, "trans", "none");
2117 case QEMU_OPTION_numa
:
2118 if (nb_numa_nodes
>= MAX_NODES
) {
2119 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2124 case QEMU_OPTION_nographic
:
2125 display_type
= DT_NOGRAPHIC
;
2127 #ifdef CONFIG_CURSES
2128 case QEMU_OPTION_curses
:
2129 display_type
= DT_CURSES
;
2132 case QEMU_OPTION_portrait
:
2135 case QEMU_OPTION_kernel
:
2136 kernel_filename
= optarg
;
2138 case QEMU_OPTION_append
:
2139 kernel_cmdline
= optarg
;
2141 case QEMU_OPTION_cdrom
:
2142 drive_add(optarg
, CDROM_ALIAS
);
2144 case QEMU_OPTION_boot
:
2146 static const char * const params
[] = {
2147 "order", "once", "menu", NULL
2149 char buf
[sizeof(boot_devices
)];
2150 char *standard_boot_devices
;
2153 if (!strchr(optarg
, '=')) {
2155 pstrcpy(buf
, sizeof(buf
), optarg
);
2156 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2158 "qemu: unknown boot parameter '%s' in '%s'\n",
2164 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2165 validate_bootdevices(buf
);
2166 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2169 if (get_param_value(buf
, sizeof(buf
),
2171 validate_bootdevices(buf
);
2172 standard_boot_devices
= qemu_strdup(boot_devices
);
2173 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2174 qemu_register_reset(restore_boot_devices
,
2175 standard_boot_devices
);
2177 if (get_param_value(buf
, sizeof(buf
),
2179 if (!strcmp(buf
, "on")) {
2181 } else if (!strcmp(buf
, "off")) {
2185 "qemu: invalid option value '%s'\n",
2193 case QEMU_OPTION_fda
:
2194 case QEMU_OPTION_fdb
:
2195 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2197 case QEMU_OPTION_no_fd_bootchk
:
2200 case QEMU_OPTION_netdev
:
2201 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2205 case QEMU_OPTION_net
:
2206 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2211 case QEMU_OPTION_tftp
:
2212 legacy_tftp_prefix
= optarg
;
2214 case QEMU_OPTION_bootp
:
2215 legacy_bootp_filename
= optarg
;
2217 case QEMU_OPTION_redir
:
2218 if (net_slirp_redir(optarg
) < 0)
2222 case QEMU_OPTION_bt
:
2223 add_device_config(DEV_BT
, optarg
);
2225 case QEMU_OPTION_audio_help
:
2226 if (!(audio_available())) {
2227 printf("Option %s not supported for this target\n", popt
->name
);
2233 case QEMU_OPTION_soundhw
:
2234 if (!(audio_available())) {
2235 printf("Option %s not supported for this target\n", popt
->name
);
2238 select_soundhw (optarg
);
2243 case QEMU_OPTION_version
:
2247 case QEMU_OPTION_m
: {
2250 value
= strtosz(optarg
, NULL
);
2252 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2256 /* On 32-bit hosts, QEMU is limited by virtual address space */
2257 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2258 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2261 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2262 fprintf(stderr
, "qemu: ram size too large\n");
2268 case QEMU_OPTION_mempath
:
2272 case QEMU_OPTION_mem_prealloc
:
2277 set_cpu_log(optarg
);
2280 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2282 case QEMU_OPTION_gdb
:
2283 gdbstub_dev
= optarg
;
2288 case QEMU_OPTION_bios
:
2291 case QEMU_OPTION_singlestep
:
2298 keyboard_layout
= optarg
;
2300 case QEMU_OPTION_localtime
:
2303 case QEMU_OPTION_vga
:
2304 select_vgahw (optarg
);
2311 w
= strtol(p
, (char **)&p
, 10);
2314 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2320 h
= strtol(p
, (char **)&p
, 10);
2325 depth
= strtol(p
, (char **)&p
, 10);
2326 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2327 depth
!= 24 && depth
!= 32)
2329 } else if (*p
== '\0') {
2330 depth
= graphic_depth
;
2337 graphic_depth
= depth
;
2340 case QEMU_OPTION_echr
:
2343 term_escape_char
= strtol(optarg
, &r
, 0);
2345 printf("Bad argument to echr\n");
2348 case QEMU_OPTION_monitor
:
2349 monitor_parse(optarg
, "readline");
2350 default_monitor
= 0;
2352 case QEMU_OPTION_qmp
:
2353 monitor_parse(optarg
, "control");
2354 default_monitor
= 0;
2356 case QEMU_OPTION_mon
:
2357 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2361 default_monitor
= 0;
2363 case QEMU_OPTION_chardev
:
2364 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2369 case QEMU_OPTION_fsdev
:
2370 olist
= qemu_find_opts("fsdev");
2372 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2375 opts
= qemu_opts_parse(olist
, optarg
, 1);
2377 fprintf(stderr
, "parse error: %s\n", optarg
);
2381 case QEMU_OPTION_virtfs
: {
2382 char *arg_fsdev
= NULL
;
2383 char *arg_9p
= NULL
;
2386 olist
= qemu_find_opts("virtfs");
2388 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2391 opts
= qemu_opts_parse(olist
, optarg
, 1);
2393 fprintf(stderr
, "parse error: %s\n", optarg
);
2397 if (qemu_opt_get(opts
, "fstype") == NULL
||
2398 qemu_opt_get(opts
, "mount_tag") == NULL
||
2399 qemu_opt_get(opts
, "path") == NULL
||
2400 qemu_opt_get(opts
, "security_model") == NULL
) {
2401 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2402 "security_model=[mapped|passthrough|none],"
2407 len
= strlen(",id=,path=,security_model=");
2408 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2409 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2410 len
+= strlen(qemu_opt_get(opts
, "path"));
2411 len
+= strlen(qemu_opt_get(opts
, "security_model"));
2412 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2414 snprintf(arg_fsdev
, (len
+ 1) * sizeof(*arg_fsdev
),
2415 "%s,id=%s,path=%s,security_model=%s",
2416 qemu_opt_get(opts
, "fstype"),
2417 qemu_opt_get(opts
, "mount_tag"),
2418 qemu_opt_get(opts
, "path"),
2419 qemu_opt_get(opts
, "security_model"));
2421 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2422 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2423 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2425 snprintf(arg_9p
, (len
+ 1) * sizeof(*arg_9p
),
2426 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2427 qemu_opt_get(opts
, "mount_tag"),
2428 qemu_opt_get(opts
, "mount_tag"));
2430 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev
, 1)) {
2431 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2435 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p
, 1)) {
2436 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2440 qemu_free(arg_fsdev
);
2444 case QEMU_OPTION_serial
:
2445 add_device_config(DEV_SERIAL
, optarg
);
2447 if (strncmp(optarg
, "mon:", 4) == 0) {
2448 default_monitor
= 0;
2451 case QEMU_OPTION_watchdog
:
2454 "qemu: only one watchdog option may be given\n");
2459 case QEMU_OPTION_watchdog_action
:
2460 if (select_watchdog_action(optarg
) == -1) {
2461 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2465 case QEMU_OPTION_virtiocon
:
2466 add_device_config(DEV_VIRTCON
, optarg
);
2467 default_virtcon
= 0;
2468 if (strncmp(optarg
, "mon:", 4) == 0) {
2469 default_monitor
= 0;
2472 case QEMU_OPTION_parallel
:
2473 add_device_config(DEV_PARALLEL
, optarg
);
2474 default_parallel
= 0;
2475 if (strncmp(optarg
, "mon:", 4) == 0) {
2476 default_monitor
= 0;
2479 case QEMU_OPTION_debugcon
:
2480 add_device_config(DEV_DEBUGCON
, optarg
);
2482 case QEMU_OPTION_loadvm
:
2485 case QEMU_OPTION_full_screen
:
2489 case QEMU_OPTION_no_frame
:
2492 case QEMU_OPTION_alt_grab
:
2495 case QEMU_OPTION_ctrl_grab
:
2498 case QEMU_OPTION_no_quit
:
2501 case QEMU_OPTION_sdl
:
2502 display_type
= DT_SDL
;
2505 case QEMU_OPTION_pidfile
:
2508 case QEMU_OPTION_win2k_hack
:
2509 win2k_install_hack
= 1;
2511 case QEMU_OPTION_rtc_td_hack
:
2514 case QEMU_OPTION_acpitable
:
2515 do_acpitable_option(optarg
);
2517 case QEMU_OPTION_smbios
:
2518 do_smbios_option(optarg
);
2520 case QEMU_OPTION_enable_kvm
:
2523 case QEMU_OPTION_usb
:
2526 case QEMU_OPTION_usbdevice
:
2528 add_device_config(DEV_USB
, optarg
);
2530 case QEMU_OPTION_device
:
2531 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2535 case QEMU_OPTION_smp
:
2538 fprintf(stderr
, "Invalid number of CPUs\n");
2541 if (max_cpus
< smp_cpus
) {
2542 fprintf(stderr
, "maxcpus must be equal to or greater than "
2546 if (max_cpus
> 255) {
2547 fprintf(stderr
, "Unsupported number of maxcpus\n");
2551 case QEMU_OPTION_vnc
:
2553 vnc_display
= optarg
;
2555 case QEMU_OPTION_no_acpi
:
2558 case QEMU_OPTION_no_hpet
:
2561 case QEMU_OPTION_balloon
:
2562 if (balloon_parse(optarg
) < 0) {
2563 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2567 case QEMU_OPTION_no_reboot
:
2570 case QEMU_OPTION_no_shutdown
:
2573 case QEMU_OPTION_show_cursor
:
2576 case QEMU_OPTION_uuid
:
2577 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2578 fprintf(stderr
, "Fail to parse UUID string."
2579 " Wrong format.\n");
2583 case QEMU_OPTION_option_rom
:
2584 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2585 fprintf(stderr
, "Too many option ROMs\n");
2588 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
2589 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
2590 option_rom
[nb_option_roms
].bootindex
=
2591 qemu_opt_get_number(opts
, "bootindex", -1);
2592 if (!option_rom
[nb_option_roms
].name
) {
2593 fprintf(stderr
, "Option ROM file is not specified\n");
2598 case QEMU_OPTION_semihosting
:
2599 semihosting_enabled
= 1;
2601 case QEMU_OPTION_name
:
2602 qemu_name
= qemu_strdup(optarg
);
2604 char *p
= strchr(qemu_name
, ',');
2607 if (strncmp(p
, "process=", 8)) {
2608 fprintf(stderr
, "Unknown subargument %s to -name\n", p
);
2612 os_set_proc_name(p
);
2616 case QEMU_OPTION_prom_env
:
2617 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2618 fprintf(stderr
, "Too many prom variables\n");
2621 prom_envs
[nb_prom_envs
] = optarg
;
2624 case QEMU_OPTION_old_param
:
2627 case QEMU_OPTION_clock
:
2628 configure_alarms(optarg
);
2630 case QEMU_OPTION_startdate
:
2631 configure_rtc_date_offset(optarg
, 1);
2633 case QEMU_OPTION_rtc
:
2634 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2638 configure_rtc(opts
);
2640 case QEMU_OPTION_tb_size
:
2641 tb_size
= strtol(optarg
, NULL
, 0);
2645 case QEMU_OPTION_icount
:
2646 icount_option
= optarg
;
2648 case QEMU_OPTION_incoming
:
2650 incoming_expected
= true;
2652 case QEMU_OPTION_nodefaults
:
2654 default_parallel
= 0;
2655 default_virtcon
= 0;
2656 default_monitor
= 0;
2663 case QEMU_OPTION_xen_domid
:
2664 if (!(xen_available())) {
2665 printf("Option %s not supported for this target\n", popt
->name
);
2668 xen_domid
= atoi(optarg
);
2670 case QEMU_OPTION_xen_create
:
2671 if (!(xen_available())) {
2672 printf("Option %s not supported for this target\n", popt
->name
);
2675 xen_mode
= XEN_CREATE
;
2677 case QEMU_OPTION_xen_attach
:
2678 if (!(xen_available())) {
2679 printf("Option %s not supported for this target\n", popt
->name
);
2682 xen_mode
= XEN_ATTACH
;
2684 #ifdef CONFIG_SIMPLE_TRACE
2685 case QEMU_OPTION_trace
:
2686 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2688 trace_file
= qemu_opt_get(opts
, "file");
2692 case QEMU_OPTION_readconfig
:
2694 int ret
= qemu_read_config_file(optarg
);
2696 fprintf(stderr
, "read config %s: %s\n", optarg
,
2702 case QEMU_OPTION_spice
:
2703 olist
= qemu_find_opts("spice");
2705 fprintf(stderr
, "spice is not supported by this qemu build.\n");
2708 opts
= qemu_opts_parse(olist
, optarg
, 0);
2710 fprintf(stderr
, "parse error: %s\n", optarg
);
2714 case QEMU_OPTION_writeconfig
:
2717 if (strcmp(optarg
, "-") == 0) {
2720 fp
= fopen(optarg
, "w");
2722 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2726 qemu_config_write(fp
);
2731 os_parse_cmd_args(popt
->index
, optarg
);
2737 /* If no data_dir is specified then try to find it relative to the
2740 data_dir
= os_find_datadir(argv
[0]);
2742 /* If all else fails use the install patch specified when building. */
2744 data_dir
= CONFIG_QEMU_DATADIR
;
2747 #ifdef CONFIG_SIMPLE_TRACE
2749 * Set the trace file name, if specified.
2751 st_set_trace_file(trace_file
);
2754 * Default to max_cpus = smp_cpus, in case the user doesn't
2755 * specify a max_cpus value.
2758 max_cpus
= smp_cpus
;
2760 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2761 if (smp_cpus
> machine
->max_cpus
) {
2762 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2763 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2768 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2769 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2771 if (machine
->no_serial
) {
2774 if (machine
->no_parallel
) {
2775 default_parallel
= 0;
2777 if (!machine
->use_virtcon
) {
2778 default_virtcon
= 0;
2780 if (machine
->no_vga
) {
2783 if (machine
->no_floppy
) {
2786 if (machine
->no_cdrom
) {
2789 if (machine
->no_sdcard
) {
2793 if (display_type
== DT_NOGRAPHIC
) {
2794 if (default_parallel
)
2795 add_device_config(DEV_PARALLEL
, "null");
2796 if (default_serial
&& default_monitor
) {
2797 add_device_config(DEV_SERIAL
, "mon:stdio");
2798 } else if (default_virtcon
&& default_monitor
) {
2799 add_device_config(DEV_VIRTCON
, "mon:stdio");
2802 add_device_config(DEV_SERIAL
, "stdio");
2803 if (default_virtcon
)
2804 add_device_config(DEV_VIRTCON
, "stdio");
2805 if (default_monitor
)
2806 monitor_parse("stdio", "readline");
2810 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2811 if (default_parallel
)
2812 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2813 if (default_monitor
)
2814 monitor_parse("vc:80Cx24C", "readline");
2815 if (default_virtcon
)
2816 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2819 vga_interface_type
= VGA_CIRRUS
;
2823 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
2825 #ifdef CONFIG_VIRTFS
2826 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
2833 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2839 int ret
= kvm_init(smp_cpus
);
2841 if (!kvm_available()) {
2842 printf("KVM not supported for this target\n");
2844 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2850 if (qemu_init_main_loop()) {
2851 fprintf(stderr
, "qemu_init_main_loop failed\n");
2854 linux_boot
= (kernel_filename
!= NULL
);
2856 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2857 fprintf(stderr
, "-append only allowed with -kernel option\n");
2861 if (!linux_boot
&& initrd_filename
!= NULL
) {
2862 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2866 os_set_line_buffering();
2868 if (init_timer_alarm() < 0) {
2869 fprintf(stderr
, "could not initialize alarm timer\n");
2872 configure_icount(icount_option
);
2874 if (net_init_clients() < 0) {
2878 /* init the bluetooth world */
2879 if (foreach_device_config(DEV_BT
, bt_parse
))
2882 /* init the memory */
2884 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2886 /* init the dynamic translator */
2887 cpu_exec_init_all(tb_size
* 1024 * 1024);
2889 bdrv_init_with_whitelist();
2893 if (default_cdrom
) {
2894 /* we always create the cdrom drive, even if no disk is there */
2895 drive_add(NULL
, CDROM_ALIAS
);
2898 if (default_floppy
) {
2899 /* we always create at least one floppy */
2900 drive_add(NULL
, FD_ALIAS
, 0);
2903 if (default_sdcard
) {
2904 /* we always create one sd slot, even if no card is in it */
2905 drive_add(NULL
, SD_ALIAS
);
2908 /* open the virtual block devices */
2910 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
2911 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
2914 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2917 if (nb_numa_nodes
> 0) {
2920 if (nb_numa_nodes
> smp_cpus
) {
2921 nb_numa_nodes
= smp_cpus
;
2924 /* If no memory size if given for any node, assume the default case
2925 * and distribute the available memory equally across all nodes
2927 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2928 if (node_mem
[i
] != 0)
2931 if (i
== nb_numa_nodes
) {
2932 uint64_t usedmem
= 0;
2934 /* On Linux, the each node's border has to be 8MB aligned,
2935 * the final node gets the rest.
2937 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2938 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2939 usedmem
+= node_mem
[i
];
2941 node_mem
[i
] = ram_size
- usedmem
;
2944 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2945 if (node_cpumask
[i
] != 0)
2948 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2949 * must cope with this anyway, because there are BIOSes out there in
2950 * real machines which also use this scheme.
2952 if (i
== nb_numa_nodes
) {
2953 for (i
= 0; i
< smp_cpus
; i
++) {
2954 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2959 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
2963 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2965 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2967 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2969 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2972 module_call_init(MODULE_INIT_DEVICE
);
2974 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
2978 i
= select_watchdog(watchdog
);
2980 exit (i
== 1 ? 1 : 0);
2983 if (machine
->compat_props
) {
2984 qdev_prop_register_global_list(machine
->compat_props
);
2988 machine
->init(ram_size
, boot_devices
,
2989 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2991 cpu_synchronize_all_post_init();
2993 /* must be after terminal init, SDL library changes signal handlers */
2994 os_setup_signal_handling();
2998 current_machine
= machine
;
3000 /* init USB devices */
3002 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
3006 /* init generic devices */
3007 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3010 net_check_clients();
3012 /* just use the first displaystate for the moment */
3013 ds
= get_displaystate();
3017 if (display_type
== DT_DEFAULT
&& !display_remote
) {
3018 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3019 display_type
= DT_SDL
;
3021 vnc_display
= "localhost:0,to=99";
3027 /* init local displays */
3028 switch (display_type
) {
3031 #if defined(CONFIG_CURSES)
3033 curses_display_init(ds
, full_screen
);
3036 #if defined(CONFIG_SDL)
3038 sdl_display_init(ds
, full_screen
, no_frame
);
3040 #elif defined(CONFIG_COCOA)
3042 cocoa_display_init(ds
, full_screen
);
3049 /* init remote displays */
3051 vnc_display_init(ds
);
3052 if (vnc_display_open(ds
, vnc_display
) < 0)
3055 if (show_vnc_port
) {
3056 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3060 if (using_spice
&& !qxl_enabled
) {
3061 qemu_spice_display_init(ds
);
3067 dcl
= ds
->listeners
;
3068 while (dcl
!= NULL
) {
3069 if (dcl
->dpy_refresh
!= NULL
) {
3070 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
3071 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
3076 if (ds
->gui_timer
== NULL
) {
3077 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
3078 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
3080 text_consoles_set_display(ds
);
3082 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3083 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3088 qdev_machine_creation_done();
3090 if (rom_load_all() != 0) {
3091 fprintf(stderr
, "rom loading failed\n");
3095 /* TODO: once all bus devices are qdevified, this should be done
3096 * when bus is created by qdev.c */
3097 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
3098 qemu_run_machine_init_done_notifiers();
3100 qemu_system_reset();
3102 if (load_vmstate(loadvm
) < 0) {
3108 int ret
= qemu_start_incoming_migration(incoming
);
3110 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3114 } else if (autostart
) {