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
33 /* Needed early for CONFIG_BSD etc. */
34 #include "config-host.h"
38 #include <sys/times.h>
42 #include <sys/ioctl.h>
43 #include <sys/resource.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
47 #include <arpa/inet.h>
50 #include <sys/select.h>
54 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
55 #include <sys/sysctl.h>
63 #include <linux/ppdev.h>
64 #include <linux/parport.h>
68 #include "qemu-seccomp.h"
73 #include <sys/ethernet.h>
74 #include <sys/sockio.h>
75 #include <netinet/arp.h>
76 #include <netinet/in_systm.h>
77 #include <netinet/ip.h>
78 #include <netinet/ip_icmp.h> // must come after ip.h
79 #include <netinet/udp.h>
80 #include <netinet/tcp.h>
88 #if defined(CONFIG_VDE)
89 #include <libvdeplug.h>
97 #if defined(__APPLE__) || defined(main)
99 int qemu_main(int argc
, char **argv
, char **envp
);
100 int main(int argc
, char **argv
)
102 return qemu_main(argc
, argv
, NULL
);
105 #define main qemu_main
107 #endif /* CONFIG_SDL */
111 #define main qemu_main
112 #endif /* CONFIG_COCOA */
117 #include "hw/boards.h"
119 #include "hw/pcmcia.h"
124 #include "hw/watchdog.h"
125 #include "hw/smbios.h"
128 #include "hw/loader.h"
131 #include "net/slirp.h"
136 #include "qemu-timer.h"
137 #include "qemu-char.h"
138 #include "cache-utils.h"
139 #include "blockdev.h"
140 #include "hw/block-common.h"
141 #include "block-migration.h"
143 #include "audio/audio.h"
144 #include "migration.h"
147 #include "qemu-option.h"
148 #include "qemu-config.h"
149 #include "qemu-options.h"
150 #include "qmp-commands.h"
151 #include "main-loop.h"
153 #include "fsdev/qemu-fsdev.h"
159 #include "qemu_socket.h"
161 #include "slirp/libslirp.h"
164 #include "trace/control.h"
165 #include "qemu-queue.h"
167 #include "arch_init.h"
170 #include "ui/qemu-spice.h"
171 #include "qapi/string-input-visitor.h"
174 //#define DEBUG_SLIRP
176 #define DEFAULT_RAM_SIZE 128
178 #define MAX_VIRTIO_CONSOLES 1
180 static const char *data_dir
;
181 const char *bios_name
= NULL
;
182 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
183 DisplayType display_type
= DT_DEFAULT
;
184 static int display_remote
;
185 const char* keyboard_layout
= NULL
;
187 const char *mem_path
= NULL
;
189 int mem_prealloc
= 0; /* force preallocation of physical target memory */
192 NICInfo nd_table
[MAX_NICS
];
194 static int rtc_utc
= 1;
195 static int rtc_date_offset
= -1; /* -1 means no change */
196 QEMUClock
*rtc_clock
;
197 int vga_interface_type
= VGA_NONE
;
198 static int full_screen
= 0;
200 static int no_frame
= 0;
203 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
204 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
205 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
206 int win2k_install_hack
= 0;
213 const char *vnc_display
;
215 int acpi_enabled
= 1;
218 static int no_reboot
;
221 int graphic_rotate
= 0;
222 const char *watchdog
;
223 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
225 int semihosting_enabled
= 0;
227 const char *qemu_name
;
230 unsigned int nb_prom_envs
= 0;
231 const char *prom_envs
[MAX_PROM_ENVS
];
233 uint8_t *boot_splash_filedata
;
234 int boot_splash_filedata_size
;
235 uint8_t qemu_extra_params_fw
[2];
237 typedef struct FWBootEntry FWBootEntry
;
240 QTAILQ_ENTRY(FWBootEntry
) link
;
246 static QTAILQ_HEAD(, FWBootEntry
) fw_boot_order
=
247 QTAILQ_HEAD_INITIALIZER(fw_boot_order
);
250 uint64_t node_mem
[MAX_NODES
];
251 unsigned long *node_cpumask
[MAX_NODES
];
253 uint8_t qemu_uuid
[16];
255 static QEMUBootSetHandler
*boot_set_handler
;
256 static void *boot_set_opaque
;
258 static NotifierList exit_notifiers
=
259 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
261 static NotifierList machine_init_done_notifiers
=
262 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
264 static int tcg_allowed
= 1;
268 enum xen_mode xen_mode
= XEN_EMULATE
;
269 static int tcg_tb_size
;
271 static int default_serial
= 1;
272 static int default_parallel
= 1;
273 static int default_virtcon
= 1;
274 static int default_monitor
= 1;
275 static int default_floppy
= 1;
276 static int default_cdrom
= 1;
277 static int default_sdcard
= 1;
278 static int default_vga
= 1;
284 { .driver
= "isa-serial", .flag
= &default_serial
},
285 { .driver
= "isa-parallel", .flag
= &default_parallel
},
286 { .driver
= "isa-fdc", .flag
= &default_floppy
},
287 { .driver
= "ide-cd", .flag
= &default_cdrom
},
288 { .driver
= "ide-hd", .flag
= &default_cdrom
},
289 { .driver
= "ide-drive", .flag
= &default_cdrom
},
290 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
291 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
292 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
293 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
294 { .driver
= "VGA", .flag
= &default_vga
},
295 { .driver
= "isa-vga", .flag
= &default_vga
},
296 { .driver
= "cirrus-vga", .flag
= &default_vga
},
297 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
298 { .driver
= "vmware-svga", .flag
= &default_vga
},
299 { .driver
= "qxl-vga", .flag
= &default_vga
},
302 const char *qemu_get_vm_name(void)
307 static void res_free(void)
309 if (boot_splash_filedata
!= NULL
) {
310 g_free(boot_splash_filedata
);
311 boot_splash_filedata
= NULL
;
315 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
317 const char *driver
= qemu_opt_get(opts
, "driver");
322 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
323 if (strcmp(default_list
[i
].driver
, driver
) != 0)
325 *(default_list
[i
].flag
) = 0;
330 /***********************************************************/
333 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
338 } RunStateTransition
;
340 static const RunStateTransition runstate_transitions_def
[] = {
342 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
344 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
345 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
347 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
348 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
350 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
351 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
353 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
354 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
356 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
357 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
359 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
360 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
361 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
363 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
364 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
366 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
368 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
369 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
370 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
371 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
372 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
373 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
374 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
375 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
376 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
378 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
380 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
381 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
383 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
384 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
385 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
386 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
388 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
389 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
391 { RUN_STATE_MAX
, RUN_STATE_MAX
},
394 static bool runstate_valid_transitions
[RUN_STATE_MAX
][RUN_STATE_MAX
];
396 bool runstate_check(RunState state
)
398 return current_run_state
== state
;
401 static void runstate_init(void)
403 const RunStateTransition
*p
;
405 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
407 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE_MAX
; p
++) {
408 runstate_valid_transitions
[p
->from
][p
->to
] = true;
412 /* This function will abort() on invalid state transitions */
413 void runstate_set(RunState new_state
)
415 assert(new_state
< RUN_STATE_MAX
);
417 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
418 fprintf(stderr
, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
419 RunState_lookup
[current_run_state
],
420 RunState_lookup
[new_state
]);
424 current_run_state
= new_state
;
427 int runstate_is_running(void)
429 return runstate_check(RUN_STATE_RUNNING
);
432 StatusInfo
*qmp_query_status(Error
**errp
)
434 StatusInfo
*info
= g_malloc0(sizeof(*info
));
436 info
->running
= runstate_is_running();
437 info
->singlestep
= singlestep
;
438 info
->status
= current_run_state
;
443 /***********************************************************/
444 /* real time host monotonic timer */
446 /***********************************************************/
447 /* host time/date access */
448 void qemu_get_timedate(struct tm
*tm
, int offset
)
455 if (rtc_date_offset
== -1) {
459 ret
= localtime(&ti
);
461 ti
-= rtc_date_offset
;
465 memcpy(tm
, ret
, sizeof(struct tm
));
468 int qemu_timedate_diff(struct tm
*tm
)
472 if (rtc_date_offset
== -1)
474 seconds
= mktimegm(tm
);
477 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
478 seconds
= mktime(&tmp
);
481 seconds
= mktimegm(tm
) + rtc_date_offset
;
483 return seconds
- time(NULL
);
486 void rtc_change_mon_event(struct tm
*tm
)
490 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
491 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
492 qobject_decref(data
);
495 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
497 time_t rtc_start_date
;
500 if (!strcmp(startdate
, "now") && legacy
) {
501 rtc_date_offset
= -1;
503 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
511 } else if (sscanf(startdate
, "%d-%d-%d",
523 rtc_start_date
= mktimegm(&tm
);
524 if (rtc_start_date
== -1) {
526 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
527 "'2006-06-17T16:01:21' or '2006-06-17'\n");
530 rtc_date_offset
= time(NULL
) - rtc_start_date
;
534 static void configure_rtc(QemuOpts
*opts
)
538 value
= qemu_opt_get(opts
, "base");
540 if (!strcmp(value
, "utc")) {
542 } else if (!strcmp(value
, "localtime")) {
545 configure_rtc_date_offset(value
, 0);
548 value
= qemu_opt_get(opts
, "clock");
550 if (!strcmp(value
, "host")) {
551 rtc_clock
= host_clock
;
552 } else if (!strcmp(value
, "rt")) {
553 rtc_clock
= rt_clock
;
554 } else if (!strcmp(value
, "vm")) {
555 rtc_clock
= vm_clock
;
557 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
561 value
= qemu_opt_get(opts
, "driftfix");
563 if (!strcmp(value
, "slew")) {
564 static GlobalProperty slew_lost_ticks
[] = {
566 .driver
= "mc146818rtc",
567 .property
= "lost_tick_policy",
570 { /* end of list */ }
573 qdev_prop_register_global_list(slew_lost_ticks
);
574 } else if (!strcmp(value
, "none")) {
575 /* discard is default */
577 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
583 /***********************************************************/
584 /* Bluetooth support */
587 static struct HCIInfo
*hci_table
[MAX_NICS
];
589 static struct bt_vlan_s
{
590 struct bt_scatternet_s net
;
592 struct bt_vlan_s
*next
;
595 /* find or alloc a new bluetooth "VLAN" */
596 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
598 struct bt_vlan_s
**pvlan
, *vlan
;
599 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
603 vlan
= g_malloc0(sizeof(struct bt_vlan_s
));
605 pvlan
= &first_bt_vlan
;
606 while (*pvlan
!= NULL
)
607 pvlan
= &(*pvlan
)->next
;
612 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
616 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
621 static struct HCIInfo null_hci
= {
622 .cmd_send
= null_hci_send
,
623 .sco_send
= null_hci_send
,
624 .acl_send
= null_hci_send
,
625 .bdaddr_set
= null_hci_addr_set
,
628 struct HCIInfo
*qemu_next_hci(void)
630 if (cur_hci
== nb_hcis
)
633 return hci_table
[cur_hci
++];
636 static struct HCIInfo
*hci_init(const char *str
)
639 struct bt_scatternet_s
*vlan
= 0;
641 if (!strcmp(str
, "null"))
644 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
646 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
647 else if (!strncmp(str
, "hci", 3)) {
650 if (!strncmp(str
+ 3, ",vlan=", 6)) {
651 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
656 vlan
= qemu_find_bt_vlan(0);
658 return bt_new_hci(vlan
);
661 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
666 static int bt_hci_parse(const char *str
)
671 if (nb_hcis
>= MAX_NICS
) {
672 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
685 bdaddr
.b
[5] = 0x56 + nb_hcis
;
686 hci
->bdaddr_set(hci
, bdaddr
.b
);
688 hci_table
[nb_hcis
++] = hci
;
693 static void bt_vhci_add(int vlan_id
)
695 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
698 fprintf(stderr
, "qemu: warning: adding a VHCI to "
699 "an empty scatternet %i\n", vlan_id
);
701 bt_vhci_init(bt_new_hci(vlan
));
704 static struct bt_device_s
*bt_device_add(const char *opt
)
706 struct bt_scatternet_s
*vlan
;
708 char *endp
= strstr(opt
, ",vlan=");
709 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
712 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
715 vlan_id
= strtol(endp
+ 6, &endp
, 0);
717 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
722 vlan
= qemu_find_bt_vlan(vlan_id
);
725 fprintf(stderr
, "qemu: warning: adding a slave device to "
726 "an empty scatternet %i\n", vlan_id
);
728 if (!strcmp(devname
, "keyboard"))
729 return bt_keyboard_init(vlan
);
731 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
735 static int bt_parse(const char *opt
)
737 const char *endp
, *p
;
740 if (strstart(opt
, "hci", &endp
)) {
741 if (!*endp
|| *endp
== ',') {
743 if (!strstart(endp
, ",vlan=", 0))
746 return bt_hci_parse(opt
);
748 } else if (strstart(opt
, "vhci", &endp
)) {
749 if (!*endp
|| *endp
== ',') {
751 if (strstart(endp
, ",vlan=", &p
)) {
752 vlan
= strtol(p
, (char **) &endp
, 0);
754 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
758 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
767 } else if (strstart(opt
, "device:", &endp
))
768 return !bt_device_add(endp
);
770 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
774 static int parse_sandbox(QemuOpts
*opts
, void *opaque
)
776 /* FIXME: change this to true for 1.3 */
777 if (qemu_opt_get_bool(opts
, "enable", false)) {
778 #ifdef CONFIG_SECCOMP
779 if (seccomp_start() < 0) {
780 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
781 "failed to install seccomp syscall filter in the kernel");
785 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
786 "sandboxing request but seccomp is not compiled into this build");
794 /*********QEMU USB setting******/
795 bool usb_enabled(bool default_usb
)
798 mach_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
800 return qemu_opt_get_bool(mach_opts
, "usb", default_usb
);
806 static int parse_add_fd(QemuOpts
*opts
, void *opaque
)
808 int fd
, dupfd
, flags
;
810 const char *fd_opaque
= NULL
;
812 fd
= qemu_opt_get_number(opts
, "fd", -1);
813 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
814 fd_opaque
= qemu_opt_get(opts
, "opaque");
817 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
818 "fd option is required and must be non-negative");
822 if (fd
<= STDERR_FILENO
) {
823 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
824 "fd cannot be a standard I/O stream");
829 * All fds inherited across exec() necessarily have FD_CLOEXEC
830 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
832 flags
= fcntl(fd
, F_GETFD
);
833 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
834 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
835 "fd is not valid or already in use");
840 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
841 "set option is required and must be non-negative");
845 #ifdef F_DUPFD_CLOEXEC
846 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
850 qemu_set_cloexec(dupfd
);
854 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
855 "Error duplicating fd: %s", strerror(errno
));
859 /* add the duplicate fd, and optionally the opaque string, to the fd set */
860 monitor_fdset_add_fd(dupfd
, true, fdset_id
, fd_opaque
? true : false,
866 static int cleanup_add_fd(QemuOpts
*opts
, void *opaque
)
870 fd
= qemu_opt_get_number(opts
, "fd", -1);
877 /***********************************************************/
878 /* QEMU Block devices */
880 #define HD_OPTS "media=disk"
881 #define CDROM_OPTS "media=cdrom"
883 #define PFLASH_OPTS ""
887 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
889 BlockInterfaceType
*block_default_type
= opaque
;
891 return drive_init(opts
, *block_default_type
) == NULL
;
894 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
896 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
897 qemu_opt_set(opts
, "snapshot", "on");
902 static void default_drive(int enable
, int snapshot
,
903 BlockInterfaceType block_default_type
,
904 BlockInterfaceType type
, int index
,
909 if (type
== IF_DEFAULT
) {
910 type
= block_default_type
;
913 if (!enable
|| drive_get_by_index(type
, index
)) {
917 opts
= drive_add(type
, index
, NULL
, optstr
);
919 drive_enable_snapshot(opts
, NULL
);
921 if (!drive_init(opts
, type
)) {
926 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
928 boot_set_handler
= func
;
929 boot_set_opaque
= opaque
;
932 int qemu_boot_set(const char *boot_devices
)
934 if (!boot_set_handler
) {
937 return boot_set_handler(boot_set_opaque
, boot_devices
);
940 static void validate_bootdevices(char *devices
)
942 /* We just do some generic consistency checks */
946 for (p
= devices
; *p
!= '\0'; p
++) {
947 /* Allowed boot devices are:
948 * a-b: floppy disk drives
949 * c-f: IDE disk drives
950 * g-m: machine implementation dependent drives
951 * n-p: network devices
952 * It's up to each machine implementation to check if the given boot
953 * devices match the actual hardware implementation and firmware
956 if (*p
< 'a' || *p
> 'p') {
957 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
960 if (bitmap
& (1 << (*p
- 'a'))) {
961 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
964 bitmap
|= 1 << (*p
- 'a');
968 static void restore_boot_devices(void *opaque
)
970 char *standard_boot_devices
= opaque
;
971 static int first
= 1;
973 /* Restore boot order and remove ourselves after the first boot */
979 qemu_boot_set(standard_boot_devices
);
981 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
982 g_free(standard_boot_devices
);
985 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
988 FWBootEntry
*node
, *i
;
994 assert(dev
!= NULL
|| suffix
!= NULL
);
996 node
= g_malloc0(sizeof(FWBootEntry
));
997 node
->bootindex
= bootindex
;
998 node
->suffix
= suffix
? g_strdup(suffix
) : NULL
;
1001 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
1002 if (i
->bootindex
== bootindex
) {
1003 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
1005 } else if (i
->bootindex
< bootindex
) {
1008 QTAILQ_INSERT_BEFORE(i
, node
, link
);
1011 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
1015 * This function returns null terminated string that consist of new line
1016 * separated device paths.
1018 * memory pointed by "size" is assigned total length of the array in bytes
1021 char *get_boot_devices_list(uint32_t *size
)
1027 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
1028 char *devpath
= NULL
, *bootpath
;
1032 devpath
= qdev_get_fw_dev_path(i
->dev
);
1036 if (i
->suffix
&& devpath
) {
1037 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
1039 bootpath
= g_malloc(bootpathlen
);
1040 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
1042 } else if (devpath
) {
1046 bootpath
= g_strdup(i
->suffix
);
1050 list
[total
-1] = '\n';
1052 len
= strlen(bootpath
) + 1;
1053 list
= g_realloc(list
, total
+ len
);
1054 memcpy(&list
[total
], bootpath
, len
);
1064 static void numa_add(const char *optarg
)
1068 unsigned long long value
, endvalue
;
1071 value
= endvalue
= 0ULL;
1073 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
1074 if (!strcmp(option
, "node")) {
1075 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
1076 nodenr
= nb_numa_nodes
;
1078 nodenr
= strtoull(option
, NULL
, 10);
1081 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
1082 node_mem
[nodenr
] = 0;
1085 sval
= strtosz(option
, &endptr
);
1086 if (sval
< 0 || *endptr
) {
1087 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
1090 node_mem
[nodenr
] = sval
;
1092 if (get_param_value(option
, 128, "cpus", optarg
) != 0) {
1093 value
= strtoull(option
, &endptr
, 10);
1094 if (*endptr
== '-') {
1095 endvalue
= strtoull(endptr
+1, &endptr
, 10);
1100 if (!(endvalue
< MAX_CPUMASK_BITS
)) {
1101 endvalue
= MAX_CPUMASK_BITS
- 1;
1103 "A max of %d CPUs are supported in a guest\n",
1107 bitmap_set(node_cpumask
[nodenr
], value
, endvalue
-value
+1);
1113 static void smp_parse(const char *optarg
)
1115 int smp
, sockets
= 0, threads
= 0, cores
= 0;
1119 smp
= strtoul(optarg
, &endptr
, 10);
1120 if (endptr
!= optarg
) {
1121 if (*endptr
== ',') {
1125 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
1126 sockets
= strtoull(option
, NULL
, 10);
1127 if (get_param_value(option
, 128, "cores", endptr
) != 0)
1128 cores
= strtoull(option
, NULL
, 10);
1129 if (get_param_value(option
, 128, "threads", endptr
) != 0)
1130 threads
= strtoull(option
, NULL
, 10);
1131 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
1132 max_cpus
= strtoull(option
, NULL
, 10);
1134 /* compute missing values, prefer sockets over cores over threads */
1135 if (smp
== 0 || sockets
== 0) {
1136 sockets
= sockets
> 0 ? sockets
: 1;
1137 cores
= cores
> 0 ? cores
: 1;
1138 threads
= threads
> 0 ? threads
: 1;
1140 smp
= cores
* threads
* sockets
;
1144 threads
= threads
> 0 ? threads
: 1;
1145 cores
= smp
/ (sockets
* threads
);
1147 threads
= smp
/ (cores
* sockets
);
1151 smp_cores
= cores
> 0 ? cores
: 1;
1152 smp_threads
= threads
> 0 ? threads
: 1;
1154 max_cpus
= smp_cpus
;
1157 /***********************************************************/
1160 static int usb_device_add(const char *devname
)
1163 USBDevice
*dev
= NULL
;
1165 if (!usb_enabled(false)) {
1169 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1170 dev
= usbdevice_create(devname
);
1174 /* the other ones */
1175 #ifndef CONFIG_LINUX
1176 /* only the linux version is qdev-ified, usb-bsd still needs this */
1177 if (strstart(devname
, "host:", &p
)) {
1178 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1181 if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
1182 dev
= usb_bt_init(usb_bus_find(-1),
1183 devname
[2] ? hci_init(p
)
1184 : bt_new_hci(qemu_find_bt_vlan(0)));
1195 static int usb_device_del(const char *devname
)
1200 if (strstart(devname
, "host:", &p
))
1201 return usb_host_device_close(p
);
1203 if (!usb_enabled(false)) {
1207 p
= strchr(devname
, '.');
1210 bus_num
= strtoul(devname
, NULL
, 0);
1211 addr
= strtoul(p
+ 1, NULL
, 0);
1213 return usb_device_delete_addr(bus_num
, addr
);
1216 static int usb_parse(const char *cmdline
)
1219 r
= usb_device_add(cmdline
);
1221 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
1226 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
1228 const char *devname
= qdict_get_str(qdict
, "devname");
1229 if (usb_device_add(devname
) < 0) {
1230 error_report("could not add USB device '%s'", devname
);
1234 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
1236 const char *devname
= qdict_get_str(qdict
, "devname");
1237 if (usb_device_del(devname
) < 0) {
1238 error_report("could not delete USB device '%s'", devname
);
1242 /***********************************************************/
1243 /* PCMCIA/Cardbus */
1245 static struct pcmcia_socket_entry_s
{
1246 PCMCIASocket
*socket
;
1247 struct pcmcia_socket_entry_s
*next
;
1248 } *pcmcia_sockets
= 0;
1250 void pcmcia_socket_register(PCMCIASocket
*socket
)
1252 struct pcmcia_socket_entry_s
*entry
;
1254 entry
= g_malloc(sizeof(struct pcmcia_socket_entry_s
));
1255 entry
->socket
= socket
;
1256 entry
->next
= pcmcia_sockets
;
1257 pcmcia_sockets
= entry
;
1260 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
1262 struct pcmcia_socket_entry_s
*entry
, **ptr
;
1264 ptr
= &pcmcia_sockets
;
1265 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
1266 if (entry
->socket
== socket
) {
1272 void pcmcia_info(Monitor
*mon
)
1274 struct pcmcia_socket_entry_s
*iter
;
1276 if (!pcmcia_sockets
)
1277 monitor_printf(mon
, "No PCMCIA sockets\n");
1279 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1280 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1281 iter
->socket
->attached
? iter
->socket
->card_string
:
1285 /***********************************************************/
1286 /* machine registration */
1288 static QEMUMachine
*first_machine
= NULL
;
1289 QEMUMachine
*current_machine
= NULL
;
1291 int qemu_register_machine(QEMUMachine
*m
)
1294 pm
= &first_machine
;
1302 static QEMUMachine
*find_machine(const char *name
)
1306 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1307 if (!strcmp(m
->name
, name
))
1309 if (m
->alias
&& !strcmp(m
->alias
, name
))
1315 QEMUMachine
*find_default_machine(void)
1319 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1320 if (m
->is_default
) {
1327 MachineInfoList
*qmp_query_machines(Error
**errp
)
1329 MachineInfoList
*mach_list
= NULL
;
1332 for (m
= first_machine
; m
; m
= m
->next
) {
1333 MachineInfoList
*entry
;
1336 info
= g_malloc0(sizeof(*info
));
1337 if (m
->is_default
) {
1338 info
->has_is_default
= true;
1339 info
->is_default
= true;
1343 info
->has_alias
= true;
1344 info
->alias
= g_strdup(m
->alias
);
1347 info
->name
= g_strdup(m
->name
);
1349 entry
= g_malloc0(sizeof(*entry
));
1350 entry
->value
= info
;
1351 entry
->next
= mach_list
;
1358 /***********************************************************/
1359 /* main execution loop */
1361 static void gui_update(void *opaque
)
1363 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1364 DisplayState
*ds
= opaque
;
1365 DisplayChangeListener
*dcl
;
1369 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
1370 if (dcl
->gui_timer_interval
&&
1371 dcl
->gui_timer_interval
< interval
)
1372 interval
= dcl
->gui_timer_interval
;
1374 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock_ms(rt_clock
));
1377 void gui_setup_refresh(DisplayState
*ds
)
1379 DisplayChangeListener
*dcl
;
1380 bool need_timer
= false;
1381 bool have_gfx
= false;
1382 bool have_text
= false;
1384 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
1385 if (dcl
->dpy_refresh
!= NULL
) {
1388 if (dcl
->dpy_gfx_update
!= NULL
) {
1391 if (dcl
->dpy_text_update
!= NULL
) {
1396 if (need_timer
&& ds
->gui_timer
== NULL
) {
1397 ds
->gui_timer
= qemu_new_timer_ms(rt_clock
, gui_update
, ds
);
1398 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock_ms(rt_clock
));
1400 if (!need_timer
&& ds
->gui_timer
!= NULL
) {
1401 qemu_del_timer(ds
->gui_timer
);
1402 qemu_free_timer(ds
->gui_timer
);
1403 ds
->gui_timer
= NULL
;
1406 ds
->have_gfx
= have_gfx
;
1407 ds
->have_text
= have_text
;
1410 struct vm_change_state_entry
{
1411 VMChangeStateHandler
*cb
;
1413 QLIST_ENTRY (vm_change_state_entry
) entries
;
1416 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1418 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1421 VMChangeStateEntry
*e
;
1423 e
= g_malloc0(sizeof (*e
));
1427 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1431 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1433 QLIST_REMOVE (e
, entries
);
1437 void vm_state_notify(int running
, RunState state
)
1439 VMChangeStateEntry
*e
;
1441 trace_vm_state_notify(running
, state
);
1443 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1444 e
->cb(e
->opaque
, running
, state
);
1450 if (!runstate_is_running()) {
1452 runstate_set(RUN_STATE_RUNNING
);
1453 vm_state_notify(1, RUN_STATE_RUNNING
);
1455 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1459 /* reset/shutdown handler */
1461 typedef struct QEMUResetEntry
{
1462 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1463 QEMUResetHandler
*func
;
1467 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1468 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1469 static int reset_requested
;
1470 static int shutdown_requested
, shutdown_signal
= -1;
1471 static pid_t shutdown_pid
;
1472 static int powerdown_requested
;
1473 static int debug_requested
;
1474 static int suspend_requested
;
1475 static int wakeup_requested
;
1476 static NotifierList powerdown_notifiers
=
1477 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1478 static NotifierList suspend_notifiers
=
1479 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1480 static NotifierList wakeup_notifiers
=
1481 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1482 static uint32_t wakeup_reason_mask
= ~0;
1483 static RunState vmstop_requested
= RUN_STATE_MAX
;
1485 int qemu_shutdown_requested_get(void)
1487 return shutdown_requested
;
1490 int qemu_reset_requested_get(void)
1492 return reset_requested
;
1495 static int qemu_shutdown_requested(void)
1497 int r
= shutdown_requested
;
1498 shutdown_requested
= 0;
1502 static void qemu_kill_report(void)
1504 if (!qtest_enabled() && shutdown_signal
!= -1) {
1505 fprintf(stderr
, "qemu: terminating on signal %d", shutdown_signal
);
1506 if (shutdown_pid
== 0) {
1507 /* This happens for eg ^C at the terminal, so it's worth
1508 * avoiding printing an odd message in that case.
1510 fputc('\n', stderr
);
1512 fprintf(stderr
, " from pid " FMT_pid
"\n", shutdown_pid
);
1514 shutdown_signal
= -1;
1518 static int qemu_reset_requested(void)
1520 int r
= reset_requested
;
1521 reset_requested
= 0;
1525 static int qemu_suspend_requested(void)
1527 int r
= suspend_requested
;
1528 suspend_requested
= 0;
1532 static int qemu_wakeup_requested(void)
1534 int r
= wakeup_requested
;
1535 wakeup_requested
= 0;
1539 static int qemu_powerdown_requested(void)
1541 int r
= powerdown_requested
;
1542 powerdown_requested
= 0;
1546 static int qemu_debug_requested(void)
1548 int r
= debug_requested
;
1549 debug_requested
= 0;
1553 /* We use RUN_STATE_MAX but any invalid value will do */
1554 static bool qemu_vmstop_requested(RunState
*r
)
1556 if (vmstop_requested
< RUN_STATE_MAX
) {
1557 *r
= vmstop_requested
;
1558 vmstop_requested
= RUN_STATE_MAX
;
1565 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1567 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1570 re
->opaque
= opaque
;
1571 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1574 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1578 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1579 if (re
->func
== func
&& re
->opaque
== opaque
) {
1580 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1587 void qemu_devices_reset(void)
1589 QEMUResetEntry
*re
, *nre
;
1591 /* reset all devices */
1592 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1593 re
->func(re
->opaque
);
1597 void qemu_system_reset(bool report
)
1599 if (current_machine
&& current_machine
->reset
) {
1600 current_machine
->reset();
1602 qemu_devices_reset();
1605 monitor_protocol_event(QEVENT_RESET
, NULL
);
1607 cpu_synchronize_all_post_reset();
1610 void qemu_system_reset_request(void)
1613 shutdown_requested
= 1;
1615 reset_requested
= 1;
1618 qemu_notify_event();
1621 static void qemu_system_suspend(void)
1624 notifier_list_notify(&suspend_notifiers
, NULL
);
1625 runstate_set(RUN_STATE_SUSPENDED
);
1626 monitor_protocol_event(QEVENT_SUSPEND
, NULL
);
1629 void qemu_system_suspend_request(void)
1631 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1634 suspend_requested
= 1;
1636 qemu_notify_event();
1639 void qemu_register_suspend_notifier(Notifier
*notifier
)
1641 notifier_list_add(&suspend_notifiers
, notifier
);
1644 void qemu_system_wakeup_request(WakeupReason reason
)
1646 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1649 if (!(wakeup_reason_mask
& (1 << reason
))) {
1652 runstate_set(RUN_STATE_RUNNING
);
1653 notifier_list_notify(&wakeup_notifiers
, &reason
);
1654 wakeup_requested
= 1;
1655 qemu_notify_event();
1658 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1661 wakeup_reason_mask
|= (1 << reason
);
1663 wakeup_reason_mask
&= ~(1 << reason
);
1667 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1669 notifier_list_add(&wakeup_notifiers
, notifier
);
1672 void qemu_system_killed(int signal
, pid_t pid
)
1674 shutdown_signal
= signal
;
1677 qemu_system_shutdown_request();
1680 void qemu_system_shutdown_request(void)
1682 shutdown_requested
= 1;
1683 qemu_notify_event();
1686 static void qemu_system_powerdown(void)
1688 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1689 notifier_list_notify(&powerdown_notifiers
, NULL
);
1692 void qemu_system_powerdown_request(void)
1694 powerdown_requested
= 1;
1695 qemu_notify_event();
1698 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1700 notifier_list_add(&powerdown_notifiers
, notifier
);
1703 void qemu_system_debug_request(void)
1705 debug_requested
= 1;
1706 qemu_notify_event();
1709 void qemu_system_vmstop_request(RunState state
)
1711 vmstop_requested
= state
;
1712 qemu_notify_event();
1715 static bool main_loop_should_exit(void)
1718 if (qemu_debug_requested()) {
1719 vm_stop(RUN_STATE_DEBUG
);
1721 if (qemu_suspend_requested()) {
1722 qemu_system_suspend();
1724 if (qemu_shutdown_requested()) {
1726 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1728 vm_stop(RUN_STATE_SHUTDOWN
);
1733 if (qemu_reset_requested()) {
1735 cpu_synchronize_all_states();
1736 qemu_system_reset(VMRESET_REPORT
);
1738 if (runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
1739 runstate_check(RUN_STATE_SHUTDOWN
)) {
1740 runstate_set(RUN_STATE_PAUSED
);
1743 if (qemu_wakeup_requested()) {
1745 cpu_synchronize_all_states();
1746 qemu_system_reset(VMRESET_SILENT
);
1748 monitor_protocol_event(QEVENT_WAKEUP
, NULL
);
1750 if (qemu_powerdown_requested()) {
1751 qemu_system_powerdown();
1753 if (qemu_vmstop_requested(&r
)) {
1759 static void main_loop(void)
1763 #ifdef CONFIG_PROFILER
1767 nonblocking
= !kvm_enabled() && last_io
> 0;
1768 #ifdef CONFIG_PROFILER
1769 ti
= profile_getclock();
1771 last_io
= main_loop_wait(nonblocking
);
1772 #ifdef CONFIG_PROFILER
1773 dev_time
+= profile_getclock() - ti
;
1775 } while (!main_loop_should_exit());
1778 static void version(void)
1780 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1783 static void help(int exitcode
)
1786 printf("usage: %s [options] [disk_image]\n\n"
1787 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1788 error_get_progname());
1790 #define QEMU_OPTIONS_GENERATE_HELP
1791 #include "qemu-options-wrapper.h"
1793 printf("\nDuring emulation, the following keys are useful:\n"
1794 "ctrl-alt-f toggle full screen\n"
1795 "ctrl-alt-n switch to virtual console 'n'\n"
1796 "ctrl-alt toggle mouse and keyboard grab\n"
1798 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1803 #define HAS_ARG 0x0001
1805 typedef struct QEMUOption
{
1812 static const QEMUOption qemu_options
[] = {
1813 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1814 #define QEMU_OPTIONS_GENERATE_OPTIONS
1815 #include "qemu-options-wrapper.h"
1819 static bool vga_available(void)
1821 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
1824 static bool cirrus_vga_available(void)
1826 return object_class_by_name("cirrus-vga")
1827 || object_class_by_name("isa-cirrus-vga");
1830 static bool vmware_vga_available(void)
1832 return object_class_by_name("vmware-svga");
1835 static bool qxl_vga_available(void)
1837 return object_class_by_name("qxl-vga");
1840 static void select_vgahw (const char *p
)
1844 vga_interface_type
= VGA_NONE
;
1845 if (strstart(p
, "std", &opts
)) {
1846 if (vga_available()) {
1847 vga_interface_type
= VGA_STD
;
1849 fprintf(stderr
, "Error: standard VGA not available\n");
1852 } else if (strstart(p
, "cirrus", &opts
)) {
1853 if (cirrus_vga_available()) {
1854 vga_interface_type
= VGA_CIRRUS
;
1856 fprintf(stderr
, "Error: Cirrus VGA not available\n");
1859 } else if (strstart(p
, "vmware", &opts
)) {
1860 if (vmware_vga_available()) {
1861 vga_interface_type
= VGA_VMWARE
;
1863 fprintf(stderr
, "Error: VMWare SVGA not available\n");
1866 } else if (strstart(p
, "xenfb", &opts
)) {
1867 vga_interface_type
= VGA_XENFB
;
1868 } else if (strstart(p
, "qxl", &opts
)) {
1869 if (qxl_vga_available()) {
1870 vga_interface_type
= VGA_QXL
;
1872 fprintf(stderr
, "Error: QXL VGA not available\n");
1875 } else if (!strstart(p
, "none", &opts
)) {
1877 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1881 const char *nextopt
;
1883 if (strstart(opts
, ",retrace=", &nextopt
)) {
1885 if (strstart(opts
, "dumb", &nextopt
))
1886 vga_retrace_method
= VGA_RETRACE_DUMB
;
1887 else if (strstart(opts
, "precise", &nextopt
))
1888 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1889 else goto invalid_vga
;
1890 } else goto invalid_vga
;
1895 static DisplayType
select_display(const char *p
)
1898 DisplayType display
= DT_DEFAULT
;
1900 if (strstart(p
, "sdl", &opts
)) {
1904 const char *nextopt
;
1906 if (strstart(opts
, ",frame=", &nextopt
)) {
1908 if (strstart(opts
, "on", &nextopt
)) {
1910 } else if (strstart(opts
, "off", &nextopt
)) {
1913 goto invalid_sdl_args
;
1915 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1917 if (strstart(opts
, "on", &nextopt
)) {
1919 } else if (strstart(opts
, "off", &nextopt
)) {
1922 goto invalid_sdl_args
;
1924 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1926 if (strstart(opts
, "on", &nextopt
)) {
1928 } else if (strstart(opts
, "off", &nextopt
)) {
1931 goto invalid_sdl_args
;
1933 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
1935 if (strstart(opts
, "on", &nextopt
)) {
1937 } else if (strstart(opts
, "off", &nextopt
)) {
1940 goto invalid_sdl_args
;
1944 fprintf(stderr
, "Invalid SDL option string: %s\n", p
);
1950 fprintf(stderr
, "SDL support is disabled\n");
1953 } else if (strstart(p
, "vnc", &opts
)) {
1958 const char *nextopt
;
1960 if (strstart(opts
, "=", &nextopt
)) {
1961 vnc_display
= nextopt
;
1965 fprintf(stderr
, "VNC requires a display argument vnc=<display>\n");
1969 fprintf(stderr
, "VNC support is disabled\n");
1972 } else if (strstart(p
, "curses", &opts
)) {
1973 #ifdef CONFIG_CURSES
1974 display
= DT_CURSES
;
1976 fprintf(stderr
, "Curses support is disabled\n");
1979 } else if (strstart(p
, "none", &opts
)) {
1982 fprintf(stderr
, "Unknown display type: %s\n", p
);
1989 static int balloon_parse(const char *arg
)
1993 if (strcmp(arg
, "none") == 0) {
1997 if (!strncmp(arg
, "virtio", 6)) {
1998 if (arg
[6] == ',') {
1999 /* have params -> parse them */
2000 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
2004 /* create empty opts */
2005 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0, NULL
);
2007 qemu_opt_set(opts
, "driver", "virtio-balloon");
2014 char *qemu_find_file(int type
, const char *name
)
2020 /* Try the name as a straight path first */
2021 if (access(name
, R_OK
) == 0) {
2022 return g_strdup(name
);
2025 case QEMU_FILE_TYPE_BIOS
:
2028 case QEMU_FILE_TYPE_KEYMAP
:
2029 subdir
= "keymaps/";
2034 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
2035 buf
= g_malloc0(len
);
2036 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
2037 if (access(buf
, R_OK
)) {
2044 static int device_help_func(QemuOpts
*opts
, void *opaque
)
2046 return qdev_device_help(opts
);
2049 static int device_init_func(QemuOpts
*opts
, void *opaque
)
2053 dev
= qdev_device_add(opts
);
2059 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
2061 CharDriverState
*chr
;
2063 chr
= qemu_chr_new_from_opts(opts
, NULL
);
2069 #ifdef CONFIG_VIRTFS
2070 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
2073 ret
= qemu_fsdev_add(opts
);
2079 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
2081 CharDriverState
*chr
;
2082 const char *chardev
;
2086 mode
= qemu_opt_get(opts
, "mode");
2090 if (strcmp(mode
, "readline") == 0) {
2091 flags
= MONITOR_USE_READLINE
;
2092 } else if (strcmp(mode
, "control") == 0) {
2093 flags
= MONITOR_USE_CONTROL
;
2095 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
2099 if (qemu_opt_get_bool(opts
, "pretty", 0))
2100 flags
|= MONITOR_USE_PRETTY
;
2102 if (qemu_opt_get_bool(opts
, "default", 0))
2103 flags
|= MONITOR_IS_DEFAULT
;
2105 chardev
= qemu_opt_get(opts
, "chardev");
2106 chr
= qemu_chr_find(chardev
);
2108 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
2112 monitor_init(chr
, flags
);
2116 static void monitor_parse(const char *optarg
, const char *mode
)
2118 static int monitor_device_index
= 0;
2124 if (strstart(optarg
, "chardev:", &p
)) {
2125 snprintf(label
, sizeof(label
), "%s", p
);
2127 snprintf(label
, sizeof(label
), "compat_monitor%d",
2128 monitor_device_index
);
2129 if (monitor_device_index
== 0) {
2132 opts
= qemu_chr_parse_compat(label
, optarg
);
2134 fprintf(stderr
, "parse error: %s\n", optarg
);
2139 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, NULL
);
2141 fprintf(stderr
, "duplicate chardev: %s\n", label
);
2144 qemu_opt_set(opts
, "mode", mode
);
2145 qemu_opt_set(opts
, "chardev", label
);
2147 qemu_opt_set(opts
, "default", "on");
2148 monitor_device_index
++;
2151 struct device_config
{
2153 DEV_USB
, /* -usbdevice */
2155 DEV_SERIAL
, /* -serial */
2156 DEV_PARALLEL
, /* -parallel */
2157 DEV_VIRTCON
, /* -virtioconsole */
2158 DEV_DEBUGCON
, /* -debugcon */
2159 DEV_GDB
, /* -gdb, -s */
2161 const char *cmdline
;
2163 QTAILQ_ENTRY(device_config
) next
;
2166 static QTAILQ_HEAD(, device_config
) device_configs
=
2167 QTAILQ_HEAD_INITIALIZER(device_configs
);
2169 static void add_device_config(int type
, const char *cmdline
)
2171 struct device_config
*conf
;
2173 conf
= g_malloc0(sizeof(*conf
));
2175 conf
->cmdline
= cmdline
;
2176 loc_save(&conf
->loc
);
2177 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2180 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2182 struct device_config
*conf
;
2185 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2186 if (conf
->type
!= type
)
2188 loc_push_restore(&conf
->loc
);
2189 rc
= func(conf
->cmdline
);
2190 loc_pop(&conf
->loc
);
2197 static int serial_parse(const char *devname
)
2199 static int index
= 0;
2202 if (strcmp(devname
, "none") == 0)
2204 if (index
== MAX_SERIAL_PORTS
) {
2205 fprintf(stderr
, "qemu: too many serial ports\n");
2208 snprintf(label
, sizeof(label
), "serial%d", index
);
2209 serial_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2210 if (!serial_hds
[index
]) {
2211 fprintf(stderr
, "qemu: could not connect serial device"
2212 " to character backend '%s'\n", devname
);
2219 static int parallel_parse(const char *devname
)
2221 static int index
= 0;
2224 if (strcmp(devname
, "none") == 0)
2226 if (index
== MAX_PARALLEL_PORTS
) {
2227 fprintf(stderr
, "qemu: too many parallel ports\n");
2230 snprintf(label
, sizeof(label
), "parallel%d", index
);
2231 parallel_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2232 if (!parallel_hds
[index
]) {
2233 fprintf(stderr
, "qemu: could not connect parallel device"
2234 " to character backend '%s'\n", devname
);
2241 static int virtcon_parse(const char *devname
)
2243 QemuOptsList
*device
= qemu_find_opts("device");
2244 static int index
= 0;
2246 QemuOpts
*bus_opts
, *dev_opts
;
2248 if (strcmp(devname
, "none") == 0)
2250 if (index
== MAX_VIRTIO_CONSOLES
) {
2251 fprintf(stderr
, "qemu: too many virtio consoles\n");
2255 bus_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2256 if (arch_type
== QEMU_ARCH_S390X
) {
2257 qemu_opt_set(bus_opts
, "driver", "virtio-serial-s390");
2259 qemu_opt_set(bus_opts
, "driver", "virtio-serial-pci");
2262 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2263 qemu_opt_set(dev_opts
, "driver", "virtconsole");
2265 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2266 virtcon_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2267 if (!virtcon_hds
[index
]) {
2268 fprintf(stderr
, "qemu: could not connect virtio console"
2269 " to character backend '%s'\n", devname
);
2272 qemu_opt_set(dev_opts
, "chardev", label
);
2278 static int debugcon_parse(const char *devname
)
2282 if (!qemu_chr_new("debugcon", devname
, NULL
)) {
2285 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2287 fprintf(stderr
, "qemu: already have a debugcon device\n");
2290 qemu_opt_set(opts
, "driver", "isa-debugcon");
2291 qemu_opt_set(opts
, "chardev", "debugcon");
2295 static QEMUMachine
*machine_parse(const char *name
)
2297 QEMUMachine
*m
, *machine
= NULL
;
2300 machine
= find_machine(name
);
2305 printf("Supported machines are:\n");
2306 for (m
= first_machine
; m
!= NULL
; m
= m
->next
) {
2308 printf("%-20s %s (alias of %s)\n", m
->alias
, m
->desc
, m
->name
);
2310 printf("%-20s %s%s\n", m
->name
, m
->desc
,
2311 m
->is_default
? " (default)" : "");
2313 exit(!name
|| !is_help_option(name
));
2316 static int tcg_init(void)
2318 tcg_exec_init(tcg_tb_size
* 1024 * 1024);
2323 const char *opt_name
;
2325 int (*available
)(void);
2329 { "tcg", "tcg", tcg_available
, tcg_init
, &tcg_allowed
},
2330 { "xen", "Xen", xen_available
, xen_init
, &xen_allowed
},
2331 { "kvm", "KVM", kvm_available
, kvm_init
, &kvm_allowed
},
2332 { "qtest", "QTest", qtest_available
, qtest_init
, &qtest_allowed
},
2335 static int configure_accelerator(void)
2337 const char *p
= NULL
;
2340 bool accel_initialised
= 0;
2341 bool init_failed
= 0;
2343 QemuOptsList
*list
= qemu_find_opts("machine");
2344 if (!QTAILQ_EMPTY(&list
->head
)) {
2345 p
= qemu_opt_get(QTAILQ_FIRST(&list
->head
), "accel");
2349 /* Use the default "accelerator", tcg */
2353 while (!accel_initialised
&& *p
!= '\0') {
2357 p
= get_opt_name(buf
, sizeof (buf
), p
, ':');
2358 for (i
= 0; i
< ARRAY_SIZE(accel_list
); i
++) {
2359 if (strcmp(accel_list
[i
].opt_name
, buf
) == 0) {
2360 *(accel_list
[i
].allowed
) = 1;
2361 ret
= accel_list
[i
].init();
2364 if (!accel_list
[i
].available()) {
2365 printf("%s not supported for this target\n",
2366 accel_list
[i
].name
);
2368 fprintf(stderr
, "failed to initialize %s: %s\n",
2372 *(accel_list
[i
].allowed
) = 0;
2374 accel_initialised
= 1;
2379 if (i
== ARRAY_SIZE(accel_list
)) {
2380 fprintf(stderr
, "\"%s\" accelerator does not exist.\n", buf
);
2384 if (!accel_initialised
) {
2385 fprintf(stderr
, "No accelerator found!\n");
2390 fprintf(stderr
, "Back to %s accelerator.\n", accel_list
[i
].name
);
2393 return !accel_initialised
;
2396 void qemu_add_exit_notifier(Notifier
*notify
)
2398 notifier_list_add(&exit_notifiers
, notify
);
2401 void qemu_remove_exit_notifier(Notifier
*notify
)
2403 notifier_remove(notify
);
2406 static void qemu_run_exit_notifiers(void)
2408 notifier_list_notify(&exit_notifiers
, NULL
);
2411 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2413 notifier_list_add(&machine_init_done_notifiers
, notify
);
2416 static void qemu_run_machine_init_done_notifiers(void)
2418 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2421 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2422 const char **poptarg
, int *poptind
)
2424 const QEMUOption
*popt
;
2425 int optind
= *poptind
;
2426 char *r
= argv
[optind
];
2429 loc_set_cmdline(argv
, optind
, 1);
2431 /* Treat --foo the same as -foo. */
2434 popt
= qemu_options
;
2437 error_report("invalid option");
2440 if (!strcmp(popt
->name
, r
+ 1))
2444 if (popt
->flags
& HAS_ARG
) {
2445 if (optind
>= argc
) {
2446 error_report("requires an argument");
2449 optarg
= argv
[optind
++];
2450 loc_set_cmdline(argv
, optind
- 2, 2);
2461 static gpointer
malloc_and_trace(gsize n_bytes
)
2463 void *ptr
= malloc(n_bytes
);
2464 trace_g_malloc(n_bytes
, ptr
);
2468 static gpointer
realloc_and_trace(gpointer mem
, gsize n_bytes
)
2470 void *ptr
= realloc(mem
, n_bytes
);
2471 trace_g_realloc(mem
, n_bytes
, ptr
);
2475 static void free_and_trace(gpointer mem
)
2481 static int object_set_property(const char *name
, const char *value
, void *opaque
)
2483 Object
*obj
= OBJECT(opaque
);
2484 StringInputVisitor
*siv
;
2485 Error
*local_err
= NULL
;
2487 if (strcmp(name
, "qom-type") == 0 || strcmp(name
, "id") == 0) {
2491 siv
= string_input_visitor_new(value
);
2492 object_property_set(obj
, string_input_get_visitor(siv
), name
, &local_err
);
2493 string_input_visitor_cleanup(siv
);
2496 qerror_report_err(local_err
);
2497 error_free(local_err
);
2504 static int object_create(QemuOpts
*opts
, void *opaque
)
2506 const char *type
= qemu_opt_get(opts
, "qom-type");
2507 const char *id
= qemu_opts_id(opts
);
2510 g_assert(type
!= NULL
);
2513 qerror_report(QERR_MISSING_PARAMETER
, "id");
2517 obj
= object_new(type
);
2518 if (qemu_opt_foreach(opts
, object_set_property
, obj
, 1) < 0) {
2522 object_property_add_child(container_get(object_get_root(), "/objects"),
2528 int main(int argc
, char **argv
, char **envp
)
2531 int snapshot
, linux_boot
;
2532 const char *icount_option
= NULL
;
2533 const char *initrd_filename
;
2534 const char *kernel_filename
, *kernel_cmdline
;
2535 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
2537 int cyls
, heads
, secs
, translation
;
2538 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
;
2539 QemuOptsList
*olist
;
2542 const char *loadvm
= NULL
;
2543 QEMUMachine
*machine
;
2544 const char *cpu_model
;
2545 const char *vga_model
= "none";
2546 const char *pid_file
= NULL
;
2547 const char *incoming
= NULL
;
2549 int show_vnc_port
= 0;
2551 bool defconfig
= true;
2552 bool userconfig
= true;
2553 const char *log_mask
= NULL
;
2554 const char *log_file
= NULL
;
2555 GMemVTable mem_trace
= {
2556 .malloc
= malloc_and_trace
,
2557 .realloc
= realloc_and_trace
,
2558 .free
= free_and_trace
,
2560 const char *trace_events
= NULL
;
2561 const char *trace_file
= NULL
;
2563 atexit(qemu_run_exit_notifiers
);
2564 error_set_progname(argv
[0]);
2566 g_mem_set_vtable(&mem_trace
);
2567 if (!g_thread_supported()) {
2568 #if !GLIB_CHECK_VERSION(2, 31, 0)
2569 g_thread_init(NULL
);
2571 fprintf(stderr
, "glib threading failed to initialize.\n");
2576 module_call_init(MODULE_INIT_QOM
);
2581 rtc_clock
= host_clock
;
2583 qemu_cache_utils_init(envp
);
2585 QLIST_INIT (&vm_change_state_head
);
2586 os_setup_early_signal_handling();
2588 module_call_init(MODULE_INIT_MACHINE
);
2589 machine
= find_default_machine();
2593 cyls
= heads
= secs
= 0;
2594 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2596 for (i
= 0; i
< MAX_NODES
; i
++) {
2598 node_cpumask
[i
] = bitmap_new(MAX_CPUMASK_BITS
);
2606 /* first pass of option parsing */
2608 while (optind
< argc
) {
2609 if (argv
[optind
][0] != '-') {
2614 const QEMUOption
*popt
;
2616 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2617 switch (popt
->index
) {
2618 case QEMU_OPTION_nodefconfig
:
2621 case QEMU_OPTION_nouserconfig
:
2630 ret
= qemu_read_default_config_files(userconfig
);
2636 /* second pass of option parsing */
2641 if (argv
[optind
][0] != '-') {
2642 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2644 const QEMUOption
*popt
;
2646 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2647 if (!(popt
->arch_mask
& arch_type
)) {
2648 printf("Option %s not supported for this target\n", popt
->name
);
2651 switch(popt
->index
) {
2653 machine
= machine_parse(optarg
);
2655 case QEMU_OPTION_no_kvm_irqchip
: {
2656 olist
= qemu_find_opts("machine");
2657 qemu_opts_parse(olist
, "kernel_irqchip=off", 0);
2660 case QEMU_OPTION_cpu
:
2661 /* hw initialization will check this */
2664 case QEMU_OPTION_hda
:
2668 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
2670 snprintf(buf
, sizeof(buf
),
2671 "%s,cyls=%d,heads=%d,secs=%d%s",
2672 HD_OPTS
, cyls
, heads
, secs
,
2673 translation
== BIOS_ATA_TRANSLATION_LBA
?
2675 translation
== BIOS_ATA_TRANSLATION_NONE
?
2676 ",trans=none" : "");
2677 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
2680 case QEMU_OPTION_hdb
:
2681 case QEMU_OPTION_hdc
:
2682 case QEMU_OPTION_hdd
:
2683 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2686 case QEMU_OPTION_drive
:
2687 if (drive_def(optarg
) == NULL
) {
2691 case QEMU_OPTION_set
:
2692 if (qemu_set_option(optarg
) != 0)
2695 case QEMU_OPTION_global
:
2696 if (qemu_global_option(optarg
) != 0)
2699 case QEMU_OPTION_mtdblock
:
2700 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2702 case QEMU_OPTION_sd
:
2703 drive_add(IF_SD
, 0, optarg
, SD_OPTS
);
2705 case QEMU_OPTION_pflash
:
2706 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2708 case QEMU_OPTION_snapshot
:
2711 case QEMU_OPTION_hdachs
:
2715 cyls
= strtol(p
, (char **)&p
, 0);
2716 if (cyls
< 1 || cyls
> 16383)
2721 heads
= strtol(p
, (char **)&p
, 0);
2722 if (heads
< 1 || heads
> 16)
2727 secs
= strtol(p
, (char **)&p
, 0);
2728 if (secs
< 1 || secs
> 63)
2732 if (!strcmp(p
, "none"))
2733 translation
= BIOS_ATA_TRANSLATION_NONE
;
2734 else if (!strcmp(p
, "lba"))
2735 translation
= BIOS_ATA_TRANSLATION_LBA
;
2736 else if (!strcmp(p
, "auto"))
2737 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2740 } else if (*p
!= '\0') {
2742 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2745 if (hda_opts
!= NULL
) {
2747 snprintf(num
, sizeof(num
), "%d", cyls
);
2748 qemu_opt_set(hda_opts
, "cyls", num
);
2749 snprintf(num
, sizeof(num
), "%d", heads
);
2750 qemu_opt_set(hda_opts
, "heads", num
);
2751 snprintf(num
, sizeof(num
), "%d", secs
);
2752 qemu_opt_set(hda_opts
, "secs", num
);
2753 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2754 qemu_opt_set(hda_opts
, "trans", "lba");
2755 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2756 qemu_opt_set(hda_opts
, "trans", "none");
2760 case QEMU_OPTION_numa
:
2761 if (nb_numa_nodes
>= MAX_NODES
) {
2762 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2767 case QEMU_OPTION_display
:
2768 display_type
= select_display(optarg
);
2770 case QEMU_OPTION_nographic
:
2771 display_type
= DT_NOGRAPHIC
;
2773 case QEMU_OPTION_curses
:
2774 #ifdef CONFIG_CURSES
2775 display_type
= DT_CURSES
;
2777 fprintf(stderr
, "Curses support is disabled\n");
2781 case QEMU_OPTION_portrait
:
2782 graphic_rotate
= 90;
2784 case QEMU_OPTION_rotate
:
2785 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2786 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2787 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2789 "qemu: only 90, 180, 270 deg rotation is available\n");
2793 case QEMU_OPTION_kernel
:
2794 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
);
2796 case QEMU_OPTION_initrd
:
2797 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
);
2799 case QEMU_OPTION_append
:
2800 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
);
2802 case QEMU_OPTION_dtb
:
2803 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
);
2805 case QEMU_OPTION_cdrom
:
2806 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2808 case QEMU_OPTION_boot
:
2810 static const char * const params
[] = {
2811 "order", "once", "menu",
2812 "splash", "splash-time",
2813 "reboot-timeout", NULL
2815 char buf
[sizeof(boot_devices
)];
2816 char *standard_boot_devices
;
2819 if (!strchr(optarg
, '=')) {
2821 pstrcpy(buf
, sizeof(buf
), optarg
);
2822 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2824 "qemu: unknown boot parameter '%s' in '%s'\n",
2830 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2831 validate_bootdevices(buf
);
2832 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2835 if (get_param_value(buf
, sizeof(buf
),
2837 validate_bootdevices(buf
);
2838 standard_boot_devices
= g_strdup(boot_devices
);
2839 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2840 qemu_register_reset(restore_boot_devices
,
2841 standard_boot_devices
);
2843 if (get_param_value(buf
, sizeof(buf
),
2845 if (!strcmp(buf
, "on")) {
2847 } else if (!strcmp(buf
, "off")) {
2851 "qemu: invalid option value '%s'\n",
2856 qemu_opts_parse(qemu_find_opts("boot-opts"),
2861 case QEMU_OPTION_fda
:
2862 case QEMU_OPTION_fdb
:
2863 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2866 case QEMU_OPTION_no_fd_bootchk
:
2869 case QEMU_OPTION_netdev
:
2870 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2874 case QEMU_OPTION_net
:
2875 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2879 #ifdef CONFIG_LIBISCSI
2880 case QEMU_OPTION_iscsi
:
2881 opts
= qemu_opts_parse(qemu_find_opts("iscsi"), optarg
, 0);
2888 case QEMU_OPTION_tftp
:
2889 legacy_tftp_prefix
= optarg
;
2891 case QEMU_OPTION_bootp
:
2892 legacy_bootp_filename
= optarg
;
2894 case QEMU_OPTION_redir
:
2895 if (net_slirp_redir(optarg
) < 0)
2899 case QEMU_OPTION_bt
:
2900 add_device_config(DEV_BT
, optarg
);
2902 case QEMU_OPTION_audio_help
:
2903 if (!(audio_available())) {
2904 printf("Option %s not supported for this target\n", popt
->name
);
2910 case QEMU_OPTION_soundhw
:
2911 if (!(audio_available())) {
2912 printf("Option %s not supported for this target\n", popt
->name
);
2915 select_soundhw (optarg
);
2920 case QEMU_OPTION_version
:
2924 case QEMU_OPTION_m
: {
2929 value
= strtosz(optarg
, &end
);
2930 if (value
< 0 || *end
) {
2931 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2934 sz
= QEMU_ALIGN_UP((uint64_t)value
, 8192);
2936 if (ram_size
!= sz
) {
2937 fprintf(stderr
, "qemu: ram size too large\n");
2942 case QEMU_OPTION_mempath
:
2946 case QEMU_OPTION_mem_prealloc
:
2957 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
2959 case QEMU_OPTION_gdb
:
2960 add_device_config(DEV_GDB
, optarg
);
2965 case QEMU_OPTION_bios
:
2968 case QEMU_OPTION_singlestep
:
2975 keyboard_layout
= optarg
;
2977 case QEMU_OPTION_localtime
:
2980 case QEMU_OPTION_vga
:
2989 w
= strtol(p
, (char **)&p
, 10);
2992 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2998 h
= strtol(p
, (char **)&p
, 10);
3003 depth
= strtol(p
, (char **)&p
, 10);
3004 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3005 depth
!= 24 && depth
!= 32)
3007 } else if (*p
== '\0') {
3008 depth
= graphic_depth
;
3015 graphic_depth
= depth
;
3018 case QEMU_OPTION_echr
:
3021 term_escape_char
= strtol(optarg
, &r
, 0);
3023 printf("Bad argument to echr\n");
3026 case QEMU_OPTION_monitor
:
3027 monitor_parse(optarg
, "readline");
3028 default_monitor
= 0;
3030 case QEMU_OPTION_qmp
:
3031 monitor_parse(optarg
, "control");
3032 default_monitor
= 0;
3034 case QEMU_OPTION_mon
:
3035 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
3039 default_monitor
= 0;
3041 case QEMU_OPTION_chardev
:
3042 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
3047 case QEMU_OPTION_fsdev
:
3048 olist
= qemu_find_opts("fsdev");
3050 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
3053 opts
= qemu_opts_parse(olist
, optarg
, 1);
3055 fprintf(stderr
, "parse error: %s\n", optarg
);
3059 case QEMU_OPTION_virtfs
: {
3062 const char *writeout
, *sock_fd
, *socket
;
3064 olist
= qemu_find_opts("virtfs");
3066 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
3069 opts
= qemu_opts_parse(olist
, optarg
, 1);
3071 fprintf(stderr
, "parse error: %s\n", optarg
);
3075 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3076 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3077 fprintf(stderr
, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
3080 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3081 qemu_opt_get(opts
, "mount_tag"),
3084 fprintf(stderr
, "duplicate fsdev id: %s\n",
3085 qemu_opt_get(opts
, "mount_tag"));
3089 writeout
= qemu_opt_get(opts
, "writeout");
3091 #ifdef CONFIG_SYNC_FILE_RANGE
3092 qemu_opt_set(fsdev
, "writeout", writeout
);
3094 fprintf(stderr
, "writeout=immediate not supported on "
3099 qemu_opt_set(fsdev
, "fsdriver", qemu_opt_get(opts
, "fsdriver"));
3100 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"));
3101 qemu_opt_set(fsdev
, "security_model",
3102 qemu_opt_get(opts
, "security_model"));
3103 socket
= qemu_opt_get(opts
, "socket");
3105 qemu_opt_set(fsdev
, "socket", socket
);
3107 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3109 qemu_opt_set(fsdev
, "sock_fd", sock_fd
);
3112 qemu_opt_set_bool(fsdev
, "readonly",
3113 qemu_opt_get_bool(opts
, "readonly", 0));
3114 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3116 qemu_opt_set(device
, "driver", "virtio-9p-pci");
3117 qemu_opt_set(device
, "fsdev",
3118 qemu_opt_get(opts
, "mount_tag"));
3119 qemu_opt_set(device
, "mount_tag",
3120 qemu_opt_get(opts
, "mount_tag"));
3123 case QEMU_OPTION_virtfs_synth
: {
3127 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3130 fprintf(stderr
, "duplicate option: %s\n", "virtfs_synth");
3133 qemu_opt_set(fsdev
, "fsdriver", "synth");
3135 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3137 qemu_opt_set(device
, "driver", "virtio-9p-pci");
3138 qemu_opt_set(device
, "fsdev", "v_synth");
3139 qemu_opt_set(device
, "mount_tag", "v_synth");
3142 case QEMU_OPTION_serial
:
3143 add_device_config(DEV_SERIAL
, optarg
);
3145 if (strncmp(optarg
, "mon:", 4) == 0) {
3146 default_monitor
= 0;
3149 case QEMU_OPTION_watchdog
:
3152 "qemu: only one watchdog option may be given\n");
3157 case QEMU_OPTION_watchdog_action
:
3158 if (select_watchdog_action(optarg
) == -1) {
3159 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
3163 case QEMU_OPTION_virtiocon
:
3164 add_device_config(DEV_VIRTCON
, optarg
);
3165 default_virtcon
= 0;
3166 if (strncmp(optarg
, "mon:", 4) == 0) {
3167 default_monitor
= 0;
3170 case QEMU_OPTION_parallel
:
3171 add_device_config(DEV_PARALLEL
, optarg
);
3172 default_parallel
= 0;
3173 if (strncmp(optarg
, "mon:", 4) == 0) {
3174 default_monitor
= 0;
3177 case QEMU_OPTION_debugcon
:
3178 add_device_config(DEV_DEBUGCON
, optarg
);
3180 case QEMU_OPTION_loadvm
:
3183 case QEMU_OPTION_full_screen
:
3187 case QEMU_OPTION_no_frame
:
3190 case QEMU_OPTION_alt_grab
:
3193 case QEMU_OPTION_ctrl_grab
:
3196 case QEMU_OPTION_no_quit
:
3199 case QEMU_OPTION_sdl
:
3200 display_type
= DT_SDL
;
3203 case QEMU_OPTION_no_frame
:
3204 case QEMU_OPTION_alt_grab
:
3205 case QEMU_OPTION_ctrl_grab
:
3206 case QEMU_OPTION_no_quit
:
3207 case QEMU_OPTION_sdl
:
3208 fprintf(stderr
, "SDL support is disabled\n");
3211 case QEMU_OPTION_pidfile
:
3214 case QEMU_OPTION_win2k_hack
:
3215 win2k_install_hack
= 1;
3217 case QEMU_OPTION_rtc_td_hack
: {
3218 static GlobalProperty slew_lost_ticks
[] = {
3220 .driver
= "mc146818rtc",
3221 .property
= "lost_tick_policy",
3224 { /* end of list */ }
3227 qdev_prop_register_global_list(slew_lost_ticks
);
3230 case QEMU_OPTION_acpitable
:
3231 do_acpitable_option(optarg
);
3233 case QEMU_OPTION_smbios
:
3234 do_smbios_option(optarg
);
3236 case QEMU_OPTION_enable_kvm
:
3237 olist
= qemu_find_opts("machine");
3238 qemu_opts_parse(olist
, "accel=kvm", 0);
3240 case QEMU_OPTION_machine
:
3241 olist
= qemu_find_opts("machine");
3242 opts
= qemu_opts_parse(olist
, optarg
, 1);
3244 fprintf(stderr
, "parse error: %s\n", optarg
);
3247 optarg
= qemu_opt_get(opts
, "type");
3249 machine
= machine_parse(optarg
);
3252 case QEMU_OPTION_no_kvm
:
3253 olist
= qemu_find_opts("machine");
3254 qemu_opts_parse(olist
, "accel=tcg", 0);
3256 case QEMU_OPTION_no_kvm_pit
: {
3257 fprintf(stderr
, "Warning: KVM PIT can no longer be disabled "
3261 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3262 static GlobalProperty kvm_pit_lost_tick_policy
[] = {
3264 .driver
= "kvm-pit",
3265 .property
= "lost_tick_policy",
3268 { /* end of list */ }
3271 fprintf(stderr
, "Warning: option deprecated, use "
3272 "lost_tick_policy property of kvm-pit instead.\n");
3273 qdev_prop_register_global_list(kvm_pit_lost_tick_policy
);
3276 case QEMU_OPTION_usb
:
3277 olist
= qemu_find_opts("machine");
3278 qemu_opts_parse(olist
, "usb=on", 0);
3280 case QEMU_OPTION_usbdevice
:
3281 olist
= qemu_find_opts("machine");
3282 qemu_opts_parse(olist
, "usb=on", 0);
3283 add_device_config(DEV_USB
, optarg
);
3285 case QEMU_OPTION_device
:
3286 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
3290 case QEMU_OPTION_smp
:
3293 fprintf(stderr
, "Invalid number of CPUs\n");
3296 if (max_cpus
< smp_cpus
) {
3297 fprintf(stderr
, "maxcpus must be equal to or greater than "
3301 if (max_cpus
> 255) {
3302 fprintf(stderr
, "Unsupported number of maxcpus\n");
3306 case QEMU_OPTION_vnc
:
3309 vnc_display
= optarg
;
3311 fprintf(stderr
, "VNC support is disabled\n");
3315 case QEMU_OPTION_no_acpi
:
3318 case QEMU_OPTION_no_hpet
:
3321 case QEMU_OPTION_balloon
:
3322 if (balloon_parse(optarg
) < 0) {
3323 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
3327 case QEMU_OPTION_no_reboot
:
3330 case QEMU_OPTION_no_shutdown
:
3333 case QEMU_OPTION_show_cursor
:
3336 case QEMU_OPTION_uuid
:
3337 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
3338 fprintf(stderr
, "Fail to parse UUID string."
3339 " Wrong format.\n");
3343 case QEMU_OPTION_option_rom
:
3344 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3345 fprintf(stderr
, "Too many option ROMs\n");
3348 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
3349 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3350 option_rom
[nb_option_roms
].bootindex
=
3351 qemu_opt_get_number(opts
, "bootindex", -1);
3352 if (!option_rom
[nb_option_roms
].name
) {
3353 fprintf(stderr
, "Option ROM file is not specified\n");
3358 case QEMU_OPTION_semihosting
:
3359 semihosting_enabled
= 1;
3361 case QEMU_OPTION_tdf
:
3362 fprintf(stderr
, "Warning: user space PIT time drift fix "
3363 "is no longer supported.\n");
3365 case QEMU_OPTION_name
:
3366 qemu_name
= g_strdup(optarg
);
3368 char *p
= strchr(qemu_name
, ',');
3371 if (strncmp(p
, "process=", 8)) {
3372 fprintf(stderr
, "Unknown subargument %s to -name\n", p
);
3376 os_set_proc_name(p
);
3380 case QEMU_OPTION_prom_env
:
3381 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3382 fprintf(stderr
, "Too many prom variables\n");
3385 prom_envs
[nb_prom_envs
] = optarg
;
3388 case QEMU_OPTION_old_param
:
3391 case QEMU_OPTION_clock
:
3392 configure_alarms(optarg
);
3394 case QEMU_OPTION_startdate
:
3395 configure_rtc_date_offset(optarg
, 1);
3397 case QEMU_OPTION_rtc
:
3398 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
3402 configure_rtc(opts
);
3404 case QEMU_OPTION_tb_size
:
3405 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3406 if (tcg_tb_size
< 0) {
3410 case QEMU_OPTION_icount
:
3411 icount_option
= optarg
;
3413 case QEMU_OPTION_incoming
:
3415 runstate_set(RUN_STATE_INMIGRATE
);
3417 case QEMU_OPTION_nodefaults
:
3419 default_parallel
= 0;
3420 default_virtcon
= 0;
3421 default_monitor
= 0;
3428 case QEMU_OPTION_xen_domid
:
3429 if (!(xen_available())) {
3430 printf("Option %s not supported for this target\n", popt
->name
);
3433 xen_domid
= atoi(optarg
);
3435 case QEMU_OPTION_xen_create
:
3436 if (!(xen_available())) {
3437 printf("Option %s not supported for this target\n", popt
->name
);
3440 xen_mode
= XEN_CREATE
;
3442 case QEMU_OPTION_xen_attach
:
3443 if (!(xen_available())) {
3444 printf("Option %s not supported for this target\n", popt
->name
);
3447 xen_mode
= XEN_ATTACH
;
3449 case QEMU_OPTION_trace
:
3451 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
3455 trace_events
= qemu_opt_get(opts
, "events");
3456 trace_file
= qemu_opt_get(opts
, "file");
3459 case QEMU_OPTION_readconfig
:
3461 int ret
= qemu_read_config_file(optarg
);
3463 fprintf(stderr
, "read config %s: %s\n", optarg
,
3469 case QEMU_OPTION_spice
:
3470 olist
= qemu_find_opts("spice");
3472 fprintf(stderr
, "spice is not supported by this qemu build.\n");
3475 opts
= qemu_opts_parse(olist
, optarg
, 0);
3477 fprintf(stderr
, "parse error: %s\n", optarg
);
3481 case QEMU_OPTION_writeconfig
:
3484 if (strcmp(optarg
, "-") == 0) {
3487 fp
= fopen(optarg
, "w");
3489 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
3493 qemu_config_write(fp
);
3497 case QEMU_OPTION_qtest
:
3498 qtest_chrdev
= optarg
;
3500 case QEMU_OPTION_qtest_log
:
3503 case QEMU_OPTION_sandbox
:
3504 opts
= qemu_opts_parse(qemu_find_opts("sandbox"), optarg
, 1);
3509 case QEMU_OPTION_add_fd
:
3511 opts
= qemu_opts_parse(qemu_find_opts("add-fd"), optarg
, 0);
3516 error_report("File descriptor passing is disabled on this "
3521 case QEMU_OPTION_object
:
3522 opts
= qemu_opts_parse(qemu_find_opts("object"), optarg
, 1);
3525 os_parse_cmd_args(popt
->index
, optarg
);
3531 if (qemu_init_main_loop()) {
3532 fprintf(stderr
, "qemu_init_main_loop failed\n");
3536 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox
, NULL
, 0)) {
3541 if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd
, NULL
, 1)) {
3545 if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd
, NULL
, 1)) {
3550 if (machine
== NULL
) {
3551 fprintf(stderr
, "No machine found.\n");
3555 if (machine
->hw_version
) {
3556 qemu_set_version(machine
->hw_version
);
3559 if (qemu_opts_foreach(qemu_find_opts("object"),
3560 object_create
, NULL
, 0) != 0) {
3564 /* Init CPU def lists, based on config
3565 * - Must be called after all the qemu_read_config_file() calls
3566 * - Must be called before list_cpus()
3567 * - Must be called before machine->init()
3571 if (cpu_model
&& is_help_option(cpu_model
)) {
3572 list_cpus(stdout
, &fprintf
, cpu_model
);
3576 /* Open the logfile at this point, if necessary. We can't open the logfile
3577 * when encountering either of the logging options (-d or -D) because the
3578 * other one may be encountered later on the command line, changing the
3579 * location or level of logging.
3583 set_cpu_log_filename(log_file
);
3585 set_cpu_log(log_mask
);
3588 if (!trace_backend_init(trace_events
, trace_file
)) {
3592 /* If no data_dir is specified then try to find it relative to the
3595 data_dir
= os_find_datadir(argv
[0]);
3597 /* If all else fails use the install path specified when building. */
3599 data_dir
= CONFIG_QEMU_DATADIR
;
3603 * Default to max_cpus = smp_cpus, in case the user doesn't
3604 * specify a max_cpus value.
3607 max_cpus
= smp_cpus
;
3609 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
3610 if (smp_cpus
> machine
->max_cpus
) {
3611 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
3612 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
3618 * Get the default machine options from the machine if it is not already
3619 * specified either by the configuration file or by the command line.
3621 if (machine
->default_machine_opts
) {
3622 qemu_opts_set_defaults(qemu_find_opts("machine"),
3623 machine
->default_machine_opts
, 0);
3626 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
3627 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
3629 if (machine
->no_serial
) {
3632 if (machine
->no_parallel
) {
3633 default_parallel
= 0;
3635 if (!machine
->use_virtcon
) {
3636 default_virtcon
= 0;
3638 if (machine
->no_floppy
) {
3641 if (machine
->no_cdrom
) {
3644 if (machine
->no_sdcard
) {
3648 if (display_type
== DT_NOGRAPHIC
) {
3649 if (default_parallel
)
3650 add_device_config(DEV_PARALLEL
, "null");
3651 if (default_serial
&& default_monitor
) {
3652 add_device_config(DEV_SERIAL
, "mon:stdio");
3653 } else if (default_virtcon
&& default_monitor
) {
3654 add_device_config(DEV_VIRTCON
, "mon:stdio");
3657 add_device_config(DEV_SERIAL
, "stdio");
3658 if (default_virtcon
)
3659 add_device_config(DEV_VIRTCON
, "stdio");
3660 if (default_monitor
)
3661 monitor_parse("stdio", "readline");
3665 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
3666 if (default_parallel
)
3667 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
3668 if (default_monitor
)
3669 monitor_parse("vc:80Cx24C", "readline");
3670 if (default_virtcon
)
3671 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
3676 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
3678 #ifdef CONFIG_VIRTFS
3679 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
3686 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
3691 /* init the memory */
3692 if (ram_size
== 0) {
3693 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
3696 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0)
3701 configure_accelerator();
3703 machine_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
3705 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
3706 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
3707 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
3709 kernel_filename
= initrd_filename
= kernel_cmdline
= NULL
;
3712 if (!kernel_cmdline
) {
3713 kernel_cmdline
= "";
3716 linux_boot
= (kernel_filename
!= NULL
);
3718 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
3719 fprintf(stderr
, "-append only allowed with -kernel option\n");
3723 if (!linux_boot
&& initrd_filename
!= NULL
) {
3724 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
3728 if (!linux_boot
&& machine_opts
&& qemu_opt_get(machine_opts
, "dtb")) {
3729 fprintf(stderr
, "-dtb only allowed with -kernel option\n");
3733 os_set_line_buffering();
3735 qemu_init_cpu_loop();
3736 qemu_mutex_lock_iothread();
3739 /* spice needs the timers to be initialized by this point */
3743 if (icount_option
&& (kvm_enabled() || xen_enabled())) {
3744 fprintf(stderr
, "-icount is not allowed with kvm or xen\n");
3747 configure_icount(icount_option
);
3749 if (net_init_clients() < 0) {
3753 /* init the bluetooth world */
3754 if (foreach_device_config(DEV_BT
, bt_parse
))
3757 if (!xen_enabled()) {
3758 /* On 32-bit hosts, QEMU is limited by virtual address space */
3759 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
3760 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
3765 cpu_exec_init_all();
3767 bdrv_init_with_whitelist();
3771 /* open the virtual block devices */
3773 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
3774 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
3775 &machine
->block_default_type
, 1) != 0) {
3779 default_drive(default_cdrom
, snapshot
, machine
->block_default_type
,
3780 IF_DEFAULT
, 2, CDROM_OPTS
);
3781 default_drive(default_floppy
, snapshot
, machine
->block_default_type
,
3782 IF_FLOPPY
, 0, FD_OPTS
);
3783 default_drive(default_sdcard
, snapshot
, machine
->block_default_type
,
3786 register_savevm_live(NULL
, "ram", 0, 4, &savevm_ram_handlers
, NULL
);
3788 if (nb_numa_nodes
> 0) {
3791 if (nb_numa_nodes
> MAX_NODES
) {
3792 nb_numa_nodes
= MAX_NODES
;
3795 /* If no memory size if given for any node, assume the default case
3796 * and distribute the available memory equally across all nodes
3798 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3799 if (node_mem
[i
] != 0)
3802 if (i
== nb_numa_nodes
) {
3803 uint64_t usedmem
= 0;
3805 /* On Linux, the each node's border has to be 8MB aligned,
3806 * the final node gets the rest.
3808 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
3809 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
3810 usedmem
+= node_mem
[i
];
3812 node_mem
[i
] = ram_size
- usedmem
;
3815 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3816 if (!bitmap_empty(node_cpumask
[i
], MAX_CPUMASK_BITS
)) {
3820 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3821 * must cope with this anyway, because there are BIOSes out there in
3822 * real machines which also use this scheme.
3824 if (i
== nb_numa_nodes
) {
3825 for (i
= 0; i
< max_cpus
; i
++) {
3826 set_bit(i
, node_cpumask
[i
% nb_numa_nodes
]);
3831 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
3835 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
3837 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
3839 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
3841 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
3844 /* If no default VGA is requested, the default is "none". */
3846 if (cirrus_vga_available()) {
3847 vga_model
= "cirrus";
3848 } else if (vga_available()) {
3852 select_vgahw(vga_model
);
3855 i
= select_watchdog(watchdog
);
3857 exit (i
== 1 ? 1 : 0);
3860 if (machine
->compat_props
) {
3861 qdev_prop_register_global_list(machine
->compat_props
);
3865 qdev_machine_init();
3867 QEMUMachineInitArgs args
= { .ram_size
= ram_size
,
3868 .boot_device
= boot_devices
,
3869 .kernel_filename
= kernel_filename
,
3870 .kernel_cmdline
= kernel_cmdline
,
3871 .initrd_filename
= initrd_filename
,
3872 .cpu_model
= cpu_model
};
3873 machine
->init(&args
);
3875 cpu_synchronize_all_post_init();
3879 current_machine
= machine
;
3881 /* init USB devices */
3882 if (usb_enabled(false)) {
3883 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
3887 /* init generic devices */
3888 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3891 net_check_clients();
3893 /* just use the first displaystate for the moment */
3894 ds
= get_displaystate();
3898 if (display_type
== DT_DEFAULT
&& !display_remote
) {
3899 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3900 display_type
= DT_SDL
;
3901 #elif defined(CONFIG_VNC)
3902 vnc_display
= "localhost:0,to=99";
3905 display_type
= DT_NONE
;
3910 /* init local displays */
3911 switch (display_type
) {
3914 #if defined(CONFIG_CURSES)
3916 if (!is_daemonized()) {
3917 curses_display_init(ds
, full_screen
);
3921 #if defined(CONFIG_SDL)
3923 sdl_display_init(ds
, full_screen
, no_frame
);
3925 #elif defined(CONFIG_COCOA)
3927 cocoa_display_init(ds
, full_screen
);
3934 /* must be after terminal init, SDL library changes signal handlers */
3935 os_setup_signal_handling();
3938 /* init remote displays */
3940 Error
*local_err
= NULL
;
3941 vnc_display_init(ds
);
3942 vnc_display_open(ds
, vnc_display
, &local_err
);
3943 if (local_err
!= NULL
) {
3944 fprintf(stderr
, "Failed to start VNC server on `%s': %s\n",
3945 vnc_display
, error_get_pretty(local_err
));
3946 error_free(local_err
);
3950 if (show_vnc_port
) {
3951 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3956 if (using_spice
&& !qxl_enabled
) {
3957 qemu_spice_display_init(ds
);
3962 text_consoles_set_display(ds
);
3964 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
3968 qdev_machine_creation_done();
3970 if (rom_load_all() != 0) {
3971 fprintf(stderr
, "rom loading failed\n");
3975 /* TODO: once all bus devices are qdevified, this should be done
3976 * when bus is created by qdev.c */
3977 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
3978 qemu_run_machine_init_done_notifiers();
3980 qemu_system_reset(VMRESET_SILENT
);
3982 if (load_vmstate(loadvm
) < 0) {
3988 Error
*local_err
= NULL
;
3989 qemu_start_incoming_migration(incoming
, &local_err
);
3991 fprintf(stderr
, "-incoming %s: %s\n", incoming
, error_get_pretty(local_err
));
3992 error_free(local_err
);
3995 } else if (autostart
) {