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 bootpath
= qemu_malloc(strlen(devpath
) + strlen(i
->suffix
) + 1);
763 sprintf(bootpath
, "%s%s", devpath
, i
->suffix
);
765 } else if (devpath
) {
768 bootpath
= strdup(i
->suffix
);
773 list
[total
-1] = '\n';
775 len
= strlen(bootpath
) + 1;
776 list
= qemu_realloc(list
, total
+ len
);
777 memcpy(&list
[total
], bootpath
, len
);
787 static void numa_add(const char *optarg
)
791 unsigned long long value
, endvalue
;
794 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
795 if (!strcmp(option
, "node")) {
796 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
797 nodenr
= nb_numa_nodes
;
799 nodenr
= strtoull(option
, NULL
, 10);
802 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
803 node_mem
[nodenr
] = 0;
806 sval
= strtosz(option
, NULL
);
808 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
811 node_mem
[nodenr
] = sval
;
813 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
814 node_cpumask
[nodenr
] = 0;
816 value
= strtoull(option
, &endptr
, 10);
819 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
821 if (*endptr
== '-') {
822 endvalue
= strtoull(endptr
+1, &endptr
, 10);
823 if (endvalue
>= 63) {
826 "only 63 CPUs in NUMA mode supported.\n");
828 value
= (2ULL << endvalue
) - (1ULL << value
);
830 value
= 1ULL << value
;
833 node_cpumask
[nodenr
] = value
;
840 static void smp_parse(const char *optarg
)
842 int smp
, sockets
= 0, threads
= 0, cores
= 0;
846 smp
= strtoul(optarg
, &endptr
, 10);
847 if (endptr
!= optarg
) {
848 if (*endptr
== ',') {
852 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
853 sockets
= strtoull(option
, NULL
, 10);
854 if (get_param_value(option
, 128, "cores", endptr
) != 0)
855 cores
= strtoull(option
, NULL
, 10);
856 if (get_param_value(option
, 128, "threads", endptr
) != 0)
857 threads
= strtoull(option
, NULL
, 10);
858 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
859 max_cpus
= strtoull(option
, NULL
, 10);
861 /* compute missing values, prefer sockets over cores over threads */
862 if (smp
== 0 || sockets
== 0) {
863 sockets
= sockets
> 0 ? sockets
: 1;
864 cores
= cores
> 0 ? cores
: 1;
865 threads
= threads
> 0 ? threads
: 1;
867 smp
= cores
* threads
* sockets
;
871 threads
= threads
> 0 ? threads
: 1;
872 cores
= smp
/ (sockets
* threads
);
874 threads
= smp
/ (cores
* sockets
);
878 smp_cores
= cores
> 0 ? cores
: 1;
879 smp_threads
= threads
> 0 ? threads
: 1;
884 /***********************************************************/
887 static int usb_device_add(const char *devname
)
890 USBDevice
*dev
= NULL
;
895 /* drivers with .usbdevice_name entry in USBDeviceInfo */
896 dev
= usbdevice_create(devname
);
901 if (strstart(devname
, "host:", &p
)) {
902 dev
= usb_host_device_open(p
);
903 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
904 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
905 bt_new_hci(qemu_find_bt_vlan(0)));
916 static int usb_device_del(const char *devname
)
921 if (strstart(devname
, "host:", &p
))
922 return usb_host_device_close(p
);
927 p
= strchr(devname
, '.');
930 bus_num
= strtoul(devname
, NULL
, 0);
931 addr
= strtoul(p
+ 1, NULL
, 0);
933 return usb_device_delete_addr(bus_num
, addr
);
936 static int usb_parse(const char *cmdline
)
939 r
= usb_device_add(cmdline
);
941 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
946 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
948 const char *devname
= qdict_get_str(qdict
, "devname");
949 if (usb_device_add(devname
) < 0) {
950 error_report("could not add USB device '%s'", devname
);
954 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
956 const char *devname
= qdict_get_str(qdict
, "devname");
957 if (usb_device_del(devname
) < 0) {
958 error_report("could not delete USB device '%s'", devname
);
962 /***********************************************************/
965 static struct pcmcia_socket_entry_s
{
966 PCMCIASocket
*socket
;
967 struct pcmcia_socket_entry_s
*next
;
968 } *pcmcia_sockets
= 0;
970 void pcmcia_socket_register(PCMCIASocket
*socket
)
972 struct pcmcia_socket_entry_s
*entry
;
974 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
975 entry
->socket
= socket
;
976 entry
->next
= pcmcia_sockets
;
977 pcmcia_sockets
= entry
;
980 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
982 struct pcmcia_socket_entry_s
*entry
, **ptr
;
984 ptr
= &pcmcia_sockets
;
985 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
986 if (entry
->socket
== socket
) {
992 void pcmcia_info(Monitor
*mon
)
994 struct pcmcia_socket_entry_s
*iter
;
997 monitor_printf(mon
, "No PCMCIA sockets\n");
999 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1000 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1001 iter
->socket
->attached
? iter
->socket
->card_string
:
1005 /***********************************************************/
1008 typedef struct IOHandlerRecord
{
1010 IOCanReadHandler
*fd_read_poll
;
1012 IOHandler
*fd_write
;
1015 /* temporary data */
1017 QLIST_ENTRY(IOHandlerRecord
) next
;
1020 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
1021 QLIST_HEAD_INITIALIZER(io_handlers
);
1024 /* XXX: fd_read_poll should be suppressed, but an API change is
1025 necessary in the character devices to suppress fd_can_read(). */
1026 int qemu_set_fd_handler2(int fd
,
1027 IOCanReadHandler
*fd_read_poll
,
1029 IOHandler
*fd_write
,
1032 IOHandlerRecord
*ioh
;
1034 if (!fd_read
&& !fd_write
) {
1035 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1036 if (ioh
->fd
== fd
) {
1042 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1046 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
1047 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
1050 ioh
->fd_read_poll
= fd_read_poll
;
1051 ioh
->fd_read
= fd_read
;
1052 ioh
->fd_write
= fd_write
;
1053 ioh
->opaque
= opaque
;
1059 int qemu_set_fd_handler(int fd
,
1061 IOHandler
*fd_write
,
1064 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
1067 /***********************************************************/
1068 /* machine registration */
1070 static QEMUMachine
*first_machine
= NULL
;
1071 QEMUMachine
*current_machine
= NULL
;
1073 int qemu_register_machine(QEMUMachine
*m
)
1076 pm
= &first_machine
;
1084 static QEMUMachine
*find_machine(const char *name
)
1088 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1089 if (!strcmp(m
->name
, name
))
1091 if (m
->alias
&& !strcmp(m
->alias
, name
))
1097 static QEMUMachine
*find_default_machine(void)
1101 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1102 if (m
->is_default
) {
1109 /***********************************************************/
1110 /* main execution loop */
1112 static void gui_update(void *opaque
)
1114 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1115 DisplayState
*ds
= opaque
;
1116 DisplayChangeListener
*dcl
= ds
->listeners
;
1118 qemu_flush_coalesced_mmio_buffer();
1121 while (dcl
!= NULL
) {
1122 if (dcl
->gui_timer_interval
&&
1123 dcl
->gui_timer_interval
< interval
)
1124 interval
= dcl
->gui_timer_interval
;
1127 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1130 static void nographic_update(void *opaque
)
1132 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1134 qemu_flush_coalesced_mmio_buffer();
1135 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1138 struct vm_change_state_entry
{
1139 VMChangeStateHandler
*cb
;
1141 QLIST_ENTRY (vm_change_state_entry
) entries
;
1144 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1146 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1149 VMChangeStateEntry
*e
;
1151 e
= qemu_mallocz(sizeof (*e
));
1155 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1159 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1161 QLIST_REMOVE (e
, entries
);
1165 void vm_state_notify(int running
, int reason
)
1167 VMChangeStateEntry
*e
;
1169 trace_vm_state_notify(running
, reason
);
1171 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1172 e
->cb(e
->opaque
, running
, reason
);
1181 vm_state_notify(1, 0);
1183 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1187 /* reset/shutdown handler */
1189 typedef struct QEMUResetEntry
{
1190 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1191 QEMUResetHandler
*func
;
1195 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1196 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1197 static int reset_requested
;
1198 static int shutdown_requested
;
1199 static int powerdown_requested
;
1200 int debug_requested
;
1201 int vmstop_requested
;
1203 int qemu_shutdown_requested(void)
1205 int r
= shutdown_requested
;
1206 shutdown_requested
= 0;
1210 int qemu_reset_requested(void)
1212 int r
= reset_requested
;
1213 reset_requested
= 0;
1217 int qemu_powerdown_requested(void)
1219 int r
= powerdown_requested
;
1220 powerdown_requested
= 0;
1224 static int qemu_debug_requested(void)
1226 int r
= debug_requested
;
1227 debug_requested
= 0;
1231 static int qemu_vmstop_requested(void)
1233 int r
= vmstop_requested
;
1234 vmstop_requested
= 0;
1238 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1240 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1243 re
->opaque
= opaque
;
1244 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1247 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1251 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1252 if (re
->func
== func
&& re
->opaque
== opaque
) {
1253 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1260 void qemu_system_reset(void)
1262 QEMUResetEntry
*re
, *nre
;
1264 /* reset all devices */
1265 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1266 re
->func(re
->opaque
);
1268 monitor_protocol_event(QEVENT_RESET
, NULL
);
1269 cpu_synchronize_all_post_reset();
1272 void qemu_system_reset_request(void)
1275 shutdown_requested
= 1;
1277 reset_requested
= 1;
1279 qemu_notify_event();
1282 void qemu_system_shutdown_request(void)
1284 shutdown_requested
= 1;
1285 qemu_notify_event();
1288 void qemu_system_powerdown_request(void)
1290 powerdown_requested
= 1;
1291 qemu_notify_event();
1294 void main_loop_wait(int nonblocking
)
1296 IOHandlerRecord
*ioh
;
1297 fd_set rfds
, wfds
, xfds
;
1305 timeout
= qemu_calculate_timeout();
1306 qemu_bh_update_timeout(&timeout
);
1309 os_host_main_loop_wait(&timeout
);
1311 /* poll any events */
1312 /* XXX: separate device handlers from system ones */
1317 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1321 (!ioh
->fd_read_poll
||
1322 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1323 FD_SET(ioh
->fd
, &rfds
);
1327 if (ioh
->fd_write
) {
1328 FD_SET(ioh
->fd
, &wfds
);
1334 tv
.tv_sec
= timeout
/ 1000;
1335 tv
.tv_usec
= (timeout
% 1000) * 1000;
1337 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1339 qemu_mutex_unlock_iothread();
1340 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1341 qemu_mutex_lock_iothread();
1343 IOHandlerRecord
*pioh
;
1345 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1346 if (!ioh
->deleted
&& ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1347 ioh
->fd_read(ioh
->opaque
);
1349 if (!ioh
->deleted
&& ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1350 ioh
->fd_write(ioh
->opaque
);
1353 /* Do this last in case read/write handlers marked it for deletion */
1355 QLIST_REMOVE(ioh
, next
);
1361 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1363 qemu_run_all_timers();
1365 /* Check bottom-halves last in case any of the earlier events triggered
1371 static int vm_can_run(void)
1373 if (powerdown_requested
)
1375 if (reset_requested
)
1377 if (shutdown_requested
)
1379 if (debug_requested
)
1384 qemu_irq qemu_system_powerdown
;
1386 static void main_loop(void)
1390 qemu_main_loop_start();
1394 bool nonblocking
= false;
1395 #ifdef CONFIG_PROFILER
1398 #ifndef CONFIG_IOTHREAD
1399 nonblocking
= cpu_exec_all();
1401 #ifdef CONFIG_PROFILER
1402 ti
= profile_getclock();
1404 main_loop_wait(nonblocking
);
1405 #ifdef CONFIG_PROFILER
1406 dev_time
+= profile_getclock() - ti
;
1408 } while (vm_can_run());
1410 if ((r
= qemu_debug_requested())) {
1413 if (qemu_shutdown_requested()) {
1414 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1421 if (qemu_reset_requested()) {
1423 qemu_system_reset();
1426 if (qemu_powerdown_requested()) {
1427 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1428 qemu_irq_raise(qemu_system_powerdown
);
1430 if ((r
= qemu_vmstop_requested())) {
1438 static void version(void)
1440 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1443 static void help(int exitcode
)
1445 const char *options_help
=
1446 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1448 #define DEFHEADING(text) stringify(text) "\n"
1449 #include "qemu-options.def"
1455 printf("usage: %s [options] [disk_image]\n"
1457 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1460 "During emulation, the following keys are useful:\n"
1461 "ctrl-alt-f toggle full screen\n"
1462 "ctrl-alt-n switch to virtual console 'n'\n"
1463 "ctrl-alt toggle mouse and keyboard grab\n"
1465 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1471 #define HAS_ARG 0x0001
1473 typedef struct QEMUOption
{
1480 static const QEMUOption qemu_options
[] = {
1481 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1482 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1483 { option, opt_arg, opt_enum, arch_mask },
1484 #define DEFHEADING(text)
1485 #include "qemu-options.def"
1491 static void select_vgahw (const char *p
)
1496 vga_interface_type
= VGA_NONE
;
1497 if (strstart(p
, "std", &opts
)) {
1498 vga_interface_type
= VGA_STD
;
1499 } else if (strstart(p
, "cirrus", &opts
)) {
1500 vga_interface_type
= VGA_CIRRUS
;
1501 } else if (strstart(p
, "vmware", &opts
)) {
1502 vga_interface_type
= VGA_VMWARE
;
1503 } else if (strstart(p
, "xenfb", &opts
)) {
1504 vga_interface_type
= VGA_XENFB
;
1505 } else if (!strstart(p
, "none", &opts
)) {
1507 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1511 const char *nextopt
;
1513 if (strstart(opts
, ",retrace=", &nextopt
)) {
1515 if (strstart(opts
, "dumb", &nextopt
))
1516 vga_retrace_method
= VGA_RETRACE_DUMB
;
1517 else if (strstart(opts
, "precise", &nextopt
))
1518 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1519 else goto invalid_vga
;
1520 } else goto invalid_vga
;
1525 static int balloon_parse(const char *arg
)
1529 if (strcmp(arg
, "none") == 0) {
1533 if (!strncmp(arg
, "virtio", 6)) {
1534 if (arg
[6] == ',') {
1535 /* have params -> parse them */
1536 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1540 /* create empty opts */
1541 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1543 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1550 char *qemu_find_file(int type
, const char *name
)
1556 /* If name contains path separators then try it as a straight path. */
1557 if ((strchr(name
, '/') || strchr(name
, '\\'))
1558 && access(name
, R_OK
) == 0) {
1559 return qemu_strdup(name
);
1562 case QEMU_FILE_TYPE_BIOS
:
1565 case QEMU_FILE_TYPE_KEYMAP
:
1566 subdir
= "keymaps/";
1571 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1572 buf
= qemu_mallocz(len
);
1573 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1574 if (access(buf
, R_OK
)) {
1581 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1583 return qdev_device_help(opts
);
1586 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1590 dev
= qdev_device_add(opts
);
1596 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1598 CharDriverState
*chr
;
1600 chr
= qemu_chr_open_opts(opts
, NULL
);
1606 #ifdef CONFIG_VIRTFS
1607 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1610 ret
= qemu_fsdev_add(opts
);
1616 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1618 CharDriverState
*chr
;
1619 const char *chardev
;
1623 mode
= qemu_opt_get(opts
, "mode");
1627 if (strcmp(mode
, "readline") == 0) {
1628 flags
= MONITOR_USE_READLINE
;
1629 } else if (strcmp(mode
, "control") == 0) {
1630 flags
= MONITOR_USE_CONTROL
;
1632 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1636 if (qemu_opt_get_bool(opts
, "pretty", 0))
1637 flags
|= MONITOR_USE_PRETTY
;
1639 if (qemu_opt_get_bool(opts
, "default", 0))
1640 flags
|= MONITOR_IS_DEFAULT
;
1642 chardev
= qemu_opt_get(opts
, "chardev");
1643 chr
= qemu_chr_find(chardev
);
1645 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1649 monitor_init(chr
, flags
);
1653 static void monitor_parse(const char *optarg
, const char *mode
)
1655 static int monitor_device_index
= 0;
1661 if (strstart(optarg
, "chardev:", &p
)) {
1662 snprintf(label
, sizeof(label
), "%s", p
);
1664 snprintf(label
, sizeof(label
), "compat_monitor%d",
1665 monitor_device_index
);
1666 if (monitor_device_index
== 0) {
1669 opts
= qemu_chr_parse_compat(label
, optarg
);
1671 fprintf(stderr
, "parse error: %s\n", optarg
);
1676 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1678 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1681 qemu_opt_set(opts
, "mode", mode
);
1682 qemu_opt_set(opts
, "chardev", label
);
1684 qemu_opt_set(opts
, "default", "on");
1685 monitor_device_index
++;
1688 struct device_config
{
1690 DEV_USB
, /* -usbdevice */
1692 DEV_SERIAL
, /* -serial */
1693 DEV_PARALLEL
, /* -parallel */
1694 DEV_VIRTCON
, /* -virtioconsole */
1695 DEV_DEBUGCON
, /* -debugcon */
1697 const char *cmdline
;
1698 QTAILQ_ENTRY(device_config
) next
;
1700 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1702 static void add_device_config(int type
, const char *cmdline
)
1704 struct device_config
*conf
;
1706 conf
= qemu_mallocz(sizeof(*conf
));
1708 conf
->cmdline
= cmdline
;
1709 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1712 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1714 struct device_config
*conf
;
1717 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1718 if (conf
->type
!= type
)
1720 rc
= func(conf
->cmdline
);
1727 static int serial_parse(const char *devname
)
1729 static int index
= 0;
1732 if (strcmp(devname
, "none") == 0)
1734 if (index
== MAX_SERIAL_PORTS
) {
1735 fprintf(stderr
, "qemu: too many serial ports\n");
1738 snprintf(label
, sizeof(label
), "serial%d", index
);
1739 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1740 if (!serial_hds
[index
]) {
1741 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1742 devname
, strerror(errno
));
1749 static int parallel_parse(const char *devname
)
1751 static int index
= 0;
1754 if (strcmp(devname
, "none") == 0)
1756 if (index
== MAX_PARALLEL_PORTS
) {
1757 fprintf(stderr
, "qemu: too many parallel ports\n");
1760 snprintf(label
, sizeof(label
), "parallel%d", index
);
1761 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1762 if (!parallel_hds
[index
]) {
1763 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1764 devname
, strerror(errno
));
1771 static int virtcon_parse(const char *devname
)
1773 QemuOptsList
*device
= qemu_find_opts("device");
1774 static int index
= 0;
1776 QemuOpts
*bus_opts
, *dev_opts
;
1778 if (strcmp(devname
, "none") == 0)
1780 if (index
== MAX_VIRTIO_CONSOLES
) {
1781 fprintf(stderr
, "qemu: too many virtio consoles\n");
1785 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1786 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1788 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1789 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1791 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1792 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1793 if (!virtcon_hds
[index
]) {
1794 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1795 devname
, strerror(errno
));
1798 qemu_opt_set(dev_opts
, "chardev", label
);
1804 static int debugcon_parse(const char *devname
)
1808 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1811 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1813 fprintf(stderr
, "qemu: already have a debugcon device\n");
1816 qemu_opt_set(opts
, "driver", "isa-debugcon");
1817 qemu_opt_set(opts
, "chardev", "debugcon");
1821 void qemu_add_exit_notifier(Notifier
*notify
)
1823 notifier_list_add(&exit_notifiers
, notify
);
1826 void qemu_remove_exit_notifier(Notifier
*notify
)
1828 notifier_list_remove(&exit_notifiers
, notify
);
1831 static void qemu_run_exit_notifiers(void)
1833 notifier_list_notify(&exit_notifiers
);
1836 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
1838 notifier_list_add(&machine_init_done_notifiers
, notify
);
1841 static void qemu_run_machine_init_done_notifiers(void)
1843 notifier_list_notify(&machine_init_done_notifiers
);
1846 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1847 const char **poptarg
, int *poptind
)
1849 const QEMUOption
*popt
;
1850 int optind
= *poptind
;
1851 char *r
= argv
[optind
];
1854 loc_set_cmdline(argv
, optind
, 1);
1856 /* Treat --foo the same as -foo. */
1859 popt
= qemu_options
;
1862 error_report("invalid option");
1865 if (!strcmp(popt
->name
, r
+ 1))
1869 if (popt
->flags
& HAS_ARG
) {
1870 if (optind
>= argc
) {
1871 error_report("requires an argument");
1874 optarg
= argv
[optind
++];
1875 loc_set_cmdline(argv
, optind
- 2, 2);
1886 int main(int argc
, char **argv
, char **envp
)
1888 const char *gdbstub_dev
= NULL
;
1890 int snapshot
, linux_boot
;
1891 const char *icount_option
= NULL
;
1892 const char *initrd_filename
;
1893 const char *kernel_filename
, *kernel_cmdline
;
1894 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1896 DisplayChangeListener
*dcl
;
1897 int cyls
, heads
, secs
, translation
;
1898 QemuOpts
*hda_opts
= NULL
, *opts
;
1899 QemuOptsList
*olist
;
1902 const char *loadvm
= NULL
;
1903 QEMUMachine
*machine
;
1904 const char *cpu_model
;
1906 const char *pid_file
= NULL
;
1907 const char *incoming
= NULL
;
1908 int show_vnc_port
= 0;
1911 #ifdef CONFIG_SIMPLE_TRACE
1912 const char *trace_file
= NULL
;
1914 atexit(qemu_run_exit_notifiers
);
1915 error_set_progname(argv
[0]);
1919 qemu_cache_utils_init(envp
);
1921 QLIST_INIT (&vm_change_state_head
);
1922 os_setup_early_signal_handling();
1924 module_call_init(MODULE_INIT_MACHINE
);
1925 machine
= find_default_machine();
1927 initrd_filename
= NULL
;
1930 kernel_filename
= NULL
;
1931 kernel_cmdline
= "";
1932 cyls
= heads
= secs
= 0;
1933 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1935 for (i
= 0; i
< MAX_NODES
; i
++) {
1937 node_cpumask
[i
] = 0;
1946 /* first pass of option parsing */
1948 while (optind
< argc
) {
1949 if (argv
[optind
][0] != '-') {
1954 const QEMUOption
*popt
;
1956 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1957 switch (popt
->index
) {
1958 case QEMU_OPTION_nodefconfig
:
1968 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1969 if (ret
< 0 && ret
!= -ENOENT
) {
1973 ret
= qemu_read_config_file(arch_config_name
);
1974 if (ret
< 0 && ret
!= -ENOENT
) {
1980 /* second pass of option parsing */
1985 if (argv
[optind
][0] != '-') {
1986 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1988 const QEMUOption
*popt
;
1990 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1991 if (!(popt
->arch_mask
& arch_type
)) {
1992 printf("Option %s not supported for this target\n", popt
->name
);
1995 switch(popt
->index
) {
1997 machine
= find_machine(optarg
);
2000 printf("Supported machines are:\n");
2001 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
2003 printf("%-10s %s (alias of %s)\n",
2004 m
->alias
, m
->desc
, m
->name
);
2005 printf("%-10s %s%s\n",
2007 m
->is_default
? " (default)" : "");
2009 exit(*optarg
!= '?');
2012 case QEMU_OPTION_cpu
:
2013 /* hw initialization will check this */
2014 if (*optarg
== '?') {
2015 list_cpus(stdout
, &fprintf
, optarg
);
2021 case QEMU_OPTION_initrd
:
2022 initrd_filename
= optarg
;
2024 case QEMU_OPTION_hda
:
2026 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
2028 hda_opts
= drive_add(optarg
, HD_ALIAS
2029 ",cyls=%d,heads=%d,secs=%d%s",
2030 0, cyls
, heads
, secs
,
2031 translation
== BIOS_ATA_TRANSLATION_LBA
?
2033 translation
== BIOS_ATA_TRANSLATION_NONE
?
2034 ",trans=none" : "");
2036 case QEMU_OPTION_hdb
:
2037 case QEMU_OPTION_hdc
:
2038 case QEMU_OPTION_hdd
:
2039 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
2041 case QEMU_OPTION_drive
:
2042 drive_add(NULL
, "%s", optarg
);
2044 case QEMU_OPTION_set
:
2045 if (qemu_set_option(optarg
) != 0)
2048 case QEMU_OPTION_global
:
2049 if (qemu_global_option(optarg
) != 0)
2052 case QEMU_OPTION_mtdblock
:
2053 drive_add(optarg
, MTD_ALIAS
);
2055 case QEMU_OPTION_sd
:
2056 drive_add(optarg
, SD_ALIAS
);
2058 case QEMU_OPTION_pflash
:
2059 drive_add(optarg
, PFLASH_ALIAS
);
2061 case QEMU_OPTION_snapshot
:
2064 case QEMU_OPTION_hdachs
:
2068 cyls
= strtol(p
, (char **)&p
, 0);
2069 if (cyls
< 1 || cyls
> 16383)
2074 heads
= strtol(p
, (char **)&p
, 0);
2075 if (heads
< 1 || heads
> 16)
2080 secs
= strtol(p
, (char **)&p
, 0);
2081 if (secs
< 1 || secs
> 63)
2085 if (!strcmp(p
, "none"))
2086 translation
= BIOS_ATA_TRANSLATION_NONE
;
2087 else if (!strcmp(p
, "lba"))
2088 translation
= BIOS_ATA_TRANSLATION_LBA
;
2089 else if (!strcmp(p
, "auto"))
2090 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2093 } else if (*p
!= '\0') {
2095 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2098 if (hda_opts
!= NULL
) {
2100 snprintf(num
, sizeof(num
), "%d", cyls
);
2101 qemu_opt_set(hda_opts
, "cyls", num
);
2102 snprintf(num
, sizeof(num
), "%d", heads
);
2103 qemu_opt_set(hda_opts
, "heads", num
);
2104 snprintf(num
, sizeof(num
), "%d", secs
);
2105 qemu_opt_set(hda_opts
, "secs", num
);
2106 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2107 qemu_opt_set(hda_opts
, "trans", "lba");
2108 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2109 qemu_opt_set(hda_opts
, "trans", "none");
2113 case QEMU_OPTION_numa
:
2114 if (nb_numa_nodes
>= MAX_NODES
) {
2115 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2120 case QEMU_OPTION_nographic
:
2121 display_type
= DT_NOGRAPHIC
;
2123 #ifdef CONFIG_CURSES
2124 case QEMU_OPTION_curses
:
2125 display_type
= DT_CURSES
;
2128 case QEMU_OPTION_portrait
:
2131 case QEMU_OPTION_kernel
:
2132 kernel_filename
= optarg
;
2134 case QEMU_OPTION_append
:
2135 kernel_cmdline
= optarg
;
2137 case QEMU_OPTION_cdrom
:
2138 drive_add(optarg
, CDROM_ALIAS
);
2140 case QEMU_OPTION_boot
:
2142 static const char * const params
[] = {
2143 "order", "once", "menu", NULL
2145 char buf
[sizeof(boot_devices
)];
2146 char *standard_boot_devices
;
2149 if (!strchr(optarg
, '=')) {
2151 pstrcpy(buf
, sizeof(buf
), optarg
);
2152 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2154 "qemu: unknown boot parameter '%s' in '%s'\n",
2160 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2161 validate_bootdevices(buf
);
2162 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2165 if (get_param_value(buf
, sizeof(buf
),
2167 validate_bootdevices(buf
);
2168 standard_boot_devices
= qemu_strdup(boot_devices
);
2169 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2170 qemu_register_reset(restore_boot_devices
,
2171 standard_boot_devices
);
2173 if (get_param_value(buf
, sizeof(buf
),
2175 if (!strcmp(buf
, "on")) {
2177 } else if (!strcmp(buf
, "off")) {
2181 "qemu: invalid option value '%s'\n",
2189 case QEMU_OPTION_fda
:
2190 case QEMU_OPTION_fdb
:
2191 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2193 case QEMU_OPTION_no_fd_bootchk
:
2196 case QEMU_OPTION_netdev
:
2197 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2201 case QEMU_OPTION_net
:
2202 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2207 case QEMU_OPTION_tftp
:
2208 legacy_tftp_prefix
= optarg
;
2210 case QEMU_OPTION_bootp
:
2211 legacy_bootp_filename
= optarg
;
2213 case QEMU_OPTION_redir
:
2214 if (net_slirp_redir(optarg
) < 0)
2218 case QEMU_OPTION_bt
:
2219 add_device_config(DEV_BT
, optarg
);
2221 case QEMU_OPTION_audio_help
:
2222 if (!(audio_available())) {
2223 printf("Option %s not supported for this target\n", popt
->name
);
2229 case QEMU_OPTION_soundhw
:
2230 if (!(audio_available())) {
2231 printf("Option %s not supported for this target\n", popt
->name
);
2234 select_soundhw (optarg
);
2239 case QEMU_OPTION_version
:
2243 case QEMU_OPTION_m
: {
2246 value
= strtosz(optarg
, NULL
);
2248 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2252 /* On 32-bit hosts, QEMU is limited by virtual address space */
2253 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2254 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2257 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2258 fprintf(stderr
, "qemu: ram size too large\n");
2264 case QEMU_OPTION_mempath
:
2268 case QEMU_OPTION_mem_prealloc
:
2273 set_cpu_log(optarg
);
2276 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2278 case QEMU_OPTION_gdb
:
2279 gdbstub_dev
= optarg
;
2284 case QEMU_OPTION_bios
:
2287 case QEMU_OPTION_singlestep
:
2294 keyboard_layout
= optarg
;
2296 case QEMU_OPTION_localtime
:
2299 case QEMU_OPTION_vga
:
2300 select_vgahw (optarg
);
2307 w
= strtol(p
, (char **)&p
, 10);
2310 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2316 h
= strtol(p
, (char **)&p
, 10);
2321 depth
= strtol(p
, (char **)&p
, 10);
2322 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2323 depth
!= 24 && depth
!= 32)
2325 } else if (*p
== '\0') {
2326 depth
= graphic_depth
;
2333 graphic_depth
= depth
;
2336 case QEMU_OPTION_echr
:
2339 term_escape_char
= strtol(optarg
, &r
, 0);
2341 printf("Bad argument to echr\n");
2344 case QEMU_OPTION_monitor
:
2345 monitor_parse(optarg
, "readline");
2346 default_monitor
= 0;
2348 case QEMU_OPTION_qmp
:
2349 monitor_parse(optarg
, "control");
2350 default_monitor
= 0;
2352 case QEMU_OPTION_mon
:
2353 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2357 default_monitor
= 0;
2359 case QEMU_OPTION_chardev
:
2360 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2365 case QEMU_OPTION_fsdev
:
2366 olist
= qemu_find_opts("fsdev");
2368 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2371 opts
= qemu_opts_parse(olist
, optarg
, 1);
2373 fprintf(stderr
, "parse error: %s\n", optarg
);
2377 case QEMU_OPTION_virtfs
: {
2378 char *arg_fsdev
= NULL
;
2379 char *arg_9p
= NULL
;
2382 olist
= qemu_find_opts("virtfs");
2384 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2387 opts
= qemu_opts_parse(olist
, optarg
, 1);
2389 fprintf(stderr
, "parse error: %s\n", optarg
);
2393 if (qemu_opt_get(opts
, "fstype") == NULL
||
2394 qemu_opt_get(opts
, "mount_tag") == NULL
||
2395 qemu_opt_get(opts
, "path") == NULL
||
2396 qemu_opt_get(opts
, "security_model") == NULL
) {
2397 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2398 "security_model=[mapped|passthrough|none],"
2403 len
= strlen(",id=,path=,security_model=");
2404 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2405 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2406 len
+= strlen(qemu_opt_get(opts
, "path"));
2407 len
+= strlen(qemu_opt_get(opts
, "security_model"));
2408 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2410 snprintf(arg_fsdev
, (len
+ 1) * sizeof(*arg_fsdev
),
2411 "%s,id=%s,path=%s,security_model=%s",
2412 qemu_opt_get(opts
, "fstype"),
2413 qemu_opt_get(opts
, "mount_tag"),
2414 qemu_opt_get(opts
, "path"),
2415 qemu_opt_get(opts
, "security_model"));
2417 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2418 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2419 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2421 snprintf(arg_9p
, (len
+ 1) * sizeof(*arg_9p
),
2422 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2423 qemu_opt_get(opts
, "mount_tag"),
2424 qemu_opt_get(opts
, "mount_tag"));
2426 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev
, 1)) {
2427 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2431 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p
, 1)) {
2432 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2436 qemu_free(arg_fsdev
);
2440 case QEMU_OPTION_serial
:
2441 add_device_config(DEV_SERIAL
, optarg
);
2443 if (strncmp(optarg
, "mon:", 4) == 0) {
2444 default_monitor
= 0;
2447 case QEMU_OPTION_watchdog
:
2450 "qemu: only one watchdog option may be given\n");
2455 case QEMU_OPTION_watchdog_action
:
2456 if (select_watchdog_action(optarg
) == -1) {
2457 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2461 case QEMU_OPTION_virtiocon
:
2462 add_device_config(DEV_VIRTCON
, optarg
);
2463 default_virtcon
= 0;
2464 if (strncmp(optarg
, "mon:", 4) == 0) {
2465 default_monitor
= 0;
2468 case QEMU_OPTION_parallel
:
2469 add_device_config(DEV_PARALLEL
, optarg
);
2470 default_parallel
= 0;
2471 if (strncmp(optarg
, "mon:", 4) == 0) {
2472 default_monitor
= 0;
2475 case QEMU_OPTION_debugcon
:
2476 add_device_config(DEV_DEBUGCON
, optarg
);
2478 case QEMU_OPTION_loadvm
:
2481 case QEMU_OPTION_full_screen
:
2485 case QEMU_OPTION_no_frame
:
2488 case QEMU_OPTION_alt_grab
:
2491 case QEMU_OPTION_ctrl_grab
:
2494 case QEMU_OPTION_no_quit
:
2497 case QEMU_OPTION_sdl
:
2498 display_type
= DT_SDL
;
2501 case QEMU_OPTION_pidfile
:
2504 case QEMU_OPTION_win2k_hack
:
2505 win2k_install_hack
= 1;
2507 case QEMU_OPTION_rtc_td_hack
:
2510 case QEMU_OPTION_acpitable
:
2511 do_acpitable_option(optarg
);
2513 case QEMU_OPTION_smbios
:
2514 do_smbios_option(optarg
);
2516 case QEMU_OPTION_enable_kvm
:
2519 case QEMU_OPTION_usb
:
2522 case QEMU_OPTION_usbdevice
:
2524 add_device_config(DEV_USB
, optarg
);
2526 case QEMU_OPTION_device
:
2527 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2531 case QEMU_OPTION_smp
:
2534 fprintf(stderr
, "Invalid number of CPUs\n");
2537 if (max_cpus
< smp_cpus
) {
2538 fprintf(stderr
, "maxcpus must be equal to or greater than "
2542 if (max_cpus
> 255) {
2543 fprintf(stderr
, "Unsupported number of maxcpus\n");
2547 case QEMU_OPTION_vnc
:
2549 vnc_display
= optarg
;
2551 case QEMU_OPTION_no_acpi
:
2554 case QEMU_OPTION_no_hpet
:
2557 case QEMU_OPTION_balloon
:
2558 if (balloon_parse(optarg
) < 0) {
2559 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2563 case QEMU_OPTION_no_reboot
:
2566 case QEMU_OPTION_no_shutdown
:
2569 case QEMU_OPTION_show_cursor
:
2572 case QEMU_OPTION_uuid
:
2573 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2574 fprintf(stderr
, "Fail to parse UUID string."
2575 " Wrong format.\n");
2579 case QEMU_OPTION_option_rom
:
2580 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2581 fprintf(stderr
, "Too many option ROMs\n");
2584 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
2585 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
2586 option_rom
[nb_option_roms
].bootindex
=
2587 qemu_opt_get_number(opts
, "bootindex", -1);
2588 if (!option_rom
[nb_option_roms
].name
) {
2589 fprintf(stderr
, "Option ROM file is not specified\n");
2594 case QEMU_OPTION_semihosting
:
2595 semihosting_enabled
= 1;
2597 case QEMU_OPTION_name
:
2598 qemu_name
= qemu_strdup(optarg
);
2600 char *p
= strchr(qemu_name
, ',');
2603 if (strncmp(p
, "process=", 8)) {
2604 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2608 os_set_proc_name(p
);
2612 case QEMU_OPTION_prom_env
:
2613 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2614 fprintf(stderr
, "Too many prom variables\n");
2617 prom_envs
[nb_prom_envs
] = optarg
;
2620 case QEMU_OPTION_old_param
:
2623 case QEMU_OPTION_clock
:
2624 configure_alarms(optarg
);
2626 case QEMU_OPTION_startdate
:
2627 configure_rtc_date_offset(optarg
, 1);
2629 case QEMU_OPTION_rtc
:
2630 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2634 configure_rtc(opts
);
2636 case QEMU_OPTION_tb_size
:
2637 tb_size
= strtol(optarg
, NULL
, 0);
2641 case QEMU_OPTION_icount
:
2642 icount_option
= optarg
;
2644 case QEMU_OPTION_incoming
:
2646 incoming_expected
= true;
2648 case QEMU_OPTION_nodefaults
:
2650 default_parallel
= 0;
2651 default_virtcon
= 0;
2652 default_monitor
= 0;
2659 case QEMU_OPTION_xen_domid
:
2660 if (!(xen_available())) {
2661 printf("Option %s not supported for this target\n", popt
->name
);
2664 xen_domid
= atoi(optarg
);
2666 case QEMU_OPTION_xen_create
:
2667 if (!(xen_available())) {
2668 printf("Option %s not supported for this target\n", popt
->name
);
2671 xen_mode
= XEN_CREATE
;
2673 case QEMU_OPTION_xen_attach
:
2674 if (!(xen_available())) {
2675 printf("Option %s not supported for this target\n", popt
->name
);
2678 xen_mode
= XEN_ATTACH
;
2680 #ifdef CONFIG_SIMPLE_TRACE
2681 case QEMU_OPTION_trace
:
2682 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2684 trace_file
= qemu_opt_get(opts
, "file");
2688 case QEMU_OPTION_readconfig
:
2690 int ret
= qemu_read_config_file(optarg
);
2692 fprintf(stderr
, "read config %s: %s\n", optarg
,
2698 case QEMU_OPTION_spice
:
2699 olist
= qemu_find_opts("spice");
2701 fprintf(stderr
, "spice is not supported by this qemu build.\n");
2704 opts
= qemu_opts_parse(olist
, optarg
, 0);
2706 fprintf(stderr
, "parse error: %s\n", optarg
);
2710 case QEMU_OPTION_writeconfig
:
2713 if (strcmp(optarg
, "-") == 0) {
2716 fp
= fopen(optarg
, "w");
2718 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2722 qemu_config_write(fp
);
2727 os_parse_cmd_args(popt
->index
, optarg
);
2733 /* If no data_dir is specified then try to find it relative to the
2736 data_dir
= os_find_datadir(argv
[0]);
2738 /* If all else fails use the install patch specified when building. */
2740 data_dir
= CONFIG_QEMU_DATADIR
;
2743 #ifdef CONFIG_SIMPLE_TRACE
2745 * Set the trace file name, if specified.
2747 st_set_trace_file(trace_file
);
2750 * Default to max_cpus = smp_cpus, in case the user doesn't
2751 * specify a max_cpus value.
2754 max_cpus
= smp_cpus
;
2756 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2757 if (smp_cpus
> machine
->max_cpus
) {
2758 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2759 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2764 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2765 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2767 if (machine
->no_serial
) {
2770 if (machine
->no_parallel
) {
2771 default_parallel
= 0;
2773 if (!machine
->use_virtcon
) {
2774 default_virtcon
= 0;
2776 if (machine
->no_vga
) {
2779 if (machine
->no_floppy
) {
2782 if (machine
->no_cdrom
) {
2785 if (machine
->no_sdcard
) {
2789 if (display_type
== DT_NOGRAPHIC
) {
2790 if (default_parallel
)
2791 add_device_config(DEV_PARALLEL
, "null");
2792 if (default_serial
&& default_monitor
) {
2793 add_device_config(DEV_SERIAL
, "mon:stdio");
2794 } else if (default_virtcon
&& default_monitor
) {
2795 add_device_config(DEV_VIRTCON
, "mon:stdio");
2798 add_device_config(DEV_SERIAL
, "stdio");
2799 if (default_virtcon
)
2800 add_device_config(DEV_VIRTCON
, "stdio");
2801 if (default_monitor
)
2802 monitor_parse("stdio", "readline");
2806 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2807 if (default_parallel
)
2808 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2809 if (default_monitor
)
2810 monitor_parse("vc:80Cx24C", "readline");
2811 if (default_virtcon
)
2812 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2815 vga_interface_type
= VGA_CIRRUS
;
2819 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
2821 #ifdef CONFIG_VIRTFS
2822 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
2829 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2835 int ret
= kvm_init(smp_cpus
);
2837 if (!kvm_available()) {
2838 printf("KVM not supported for this target\n");
2840 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2846 if (qemu_init_main_loop()) {
2847 fprintf(stderr
, "qemu_init_main_loop failed\n");
2850 linux_boot
= (kernel_filename
!= NULL
);
2852 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2853 fprintf(stderr
, "-append only allowed with -kernel option\n");
2857 if (!linux_boot
&& initrd_filename
!= NULL
) {
2858 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2862 os_set_line_buffering();
2864 if (init_timer_alarm() < 0) {
2865 fprintf(stderr
, "could not initialize alarm timer\n");
2868 configure_icount(icount_option
);
2870 if (net_init_clients() < 0) {
2874 /* init the bluetooth world */
2875 if (foreach_device_config(DEV_BT
, bt_parse
))
2878 /* init the memory */
2880 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2882 /* init the dynamic translator */
2883 cpu_exec_init_all(tb_size
* 1024 * 1024);
2885 bdrv_init_with_whitelist();
2889 if (default_cdrom
) {
2890 /* we always create the cdrom drive, even if no disk is there */
2891 drive_add(NULL
, CDROM_ALIAS
);
2894 if (default_floppy
) {
2895 /* we always create at least one floppy */
2896 drive_add(NULL
, FD_ALIAS
, 0);
2899 if (default_sdcard
) {
2900 /* we always create one sd slot, even if no card is in it */
2901 drive_add(NULL
, SD_ALIAS
);
2904 /* open the virtual block devices */
2906 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
2907 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
2910 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2913 if (nb_numa_nodes
> 0) {
2916 if (nb_numa_nodes
> smp_cpus
) {
2917 nb_numa_nodes
= smp_cpus
;
2920 /* If no memory size if given for any node, assume the default case
2921 * and distribute the available memory equally across all nodes
2923 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2924 if (node_mem
[i
] != 0)
2927 if (i
== nb_numa_nodes
) {
2928 uint64_t usedmem
= 0;
2930 /* On Linux, the each node's border has to be 8MB aligned,
2931 * the final node gets the rest.
2933 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2934 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2935 usedmem
+= node_mem
[i
];
2937 node_mem
[i
] = ram_size
- usedmem
;
2940 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2941 if (node_cpumask
[i
] != 0)
2944 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2945 * must cope with this anyway, because there are BIOSes out there in
2946 * real machines which also use this scheme.
2948 if (i
== nb_numa_nodes
) {
2949 for (i
= 0; i
< smp_cpus
; i
++) {
2950 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2955 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
2959 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2961 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2963 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2965 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2968 module_call_init(MODULE_INIT_DEVICE
);
2970 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
2974 i
= select_watchdog(watchdog
);
2976 exit (i
== 1 ? 1 : 0);
2979 if (machine
->compat_props
) {
2980 qdev_prop_register_global_list(machine
->compat_props
);
2984 machine
->init(ram_size
, boot_devices
,
2985 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2987 cpu_synchronize_all_post_init();
2989 /* must be after terminal init, SDL library changes signal handlers */
2990 os_setup_signal_handling();
2994 current_machine
= machine
;
2996 /* init USB devices */
2998 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
3002 /* init generic devices */
3003 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3006 net_check_clients();
3008 /* just use the first displaystate for the moment */
3009 ds
= get_displaystate();
3013 if (display_type
== DT_DEFAULT
&& !display_remote
) {
3014 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3015 display_type
= DT_SDL
;
3017 vnc_display
= "localhost:0,to=99";
3023 /* init local displays */
3024 switch (display_type
) {
3027 #if defined(CONFIG_CURSES)
3029 curses_display_init(ds
, full_screen
);
3032 #if defined(CONFIG_SDL)
3034 sdl_display_init(ds
, full_screen
, no_frame
);
3036 #elif defined(CONFIG_COCOA)
3038 cocoa_display_init(ds
, full_screen
);
3045 /* init remote displays */
3047 vnc_display_init(ds
);
3048 if (vnc_display_open(ds
, vnc_display
) < 0)
3051 if (show_vnc_port
) {
3052 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3057 qemu_spice_display_init(ds
);
3063 dcl
= ds
->listeners
;
3064 while (dcl
!= NULL
) {
3065 if (dcl
->dpy_refresh
!= NULL
) {
3066 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
3067 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
3072 if (ds
->gui_timer
== NULL
) {
3073 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
3074 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
3076 text_consoles_set_display(ds
);
3078 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3079 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3084 qdev_machine_creation_done();
3086 if (rom_load_all() != 0) {
3087 fprintf(stderr
, "rom loading failed\n");
3091 qemu_register_reset((void *)qbus_reset_all
, sysbus_get_default());
3092 qemu_run_machine_init_done_notifiers();
3094 qemu_system_reset();
3096 if (load_vmstate(loadvm
) < 0) {
3102 int ret
= qemu_start_incoming_migration(incoming
);
3104 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3108 } else if (autostart
) {