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
24 #include "qemu/osdep.h"
25 #include "qemu-version.h"
26 #include "qemu/cutils.h"
27 #include "qemu/help_option.h"
28 #include "qemu/uuid.h"
31 #include "sysemu/seccomp.h"
34 #if defined(CONFIG_VDE)
35 #include <libvdeplug.h>
39 #if defined(__APPLE__) || defined(main)
41 int qemu_main(int argc
, char **argv
, char **envp
);
42 int main(int argc
, char **argv
)
44 return qemu_main(argc
, argv
, NULL
);
47 #define main qemu_main
49 #endif /* CONFIG_SDL */
53 #define main qemu_main
54 #endif /* CONFIG_COCOA */
57 #include "qemu/error-report.h"
58 #include "qemu/sockets.h"
60 #include "hw/boards.h"
61 #include "sysemu/accel.h"
63 #include "hw/i386/pc.h"
64 #include "hw/isa/isa.h"
66 #include "sysemu/watchdog.h"
67 #include "hw/smbios/smbios.h"
68 #include "hw/acpi/acpi.h"
69 #include "hw/xen/xen.h"
71 #include "hw/loader.h"
72 #include "monitor/qdev.h"
73 #include "sysemu/bt.h"
75 #include "net/slirp.h"
76 #include "monitor/monitor.h"
77 #include "ui/console.h"
79 #include "sysemu/sysemu.h"
80 #include "sysemu/numa.h"
81 #include "exec/gdbstub.h"
82 #include "qemu/timer.h"
83 #include "sysemu/char.h"
84 #include "qemu/bitmap.h"
86 #include "sysemu/blockdev.h"
87 #include "hw/block/block.h"
88 #include "migration/block.h"
89 #include "sysemu/tpm.h"
90 #include "sysemu/dma.h"
91 #include "audio/audio.h"
92 #include "migration/migration.h"
93 #include "sysemu/cpus.h"
94 #include "migration/colo.h"
95 #include "sysemu/kvm.h"
96 #include "sysemu/hax.h"
97 #include "qapi/qmp/qjson.h"
98 #include "qemu/option.h"
99 #include "qemu/config-file.h"
100 #include "qemu-options.h"
101 #include "qmp-commands.h"
102 #include "qemu/main-loop.h"
104 #include "fsdev/qemu-fsdev.h"
106 #include "sysemu/qtest.h"
108 #include "disas/disas.h"
111 #include "slirp/libslirp.h"
114 #include "trace/control.h"
115 #include "qemu/queue.h"
116 #include "sysemu/arch_init.h"
118 #include "ui/qemu-spice.h"
119 #include "qapi/string-input-visitor.h"
120 #include "qapi/opts-visitor.h"
121 #include "qom/object_interfaces.h"
122 #include "qapi-event.h"
123 #include "exec/semihost.h"
124 #include "crypto/init.h"
125 #include "sysemu/replay.h"
126 #include "qapi/qmp/qerror.h"
127 #include "sysemu/iothread.h"
129 #define MAX_VIRTIO_CONSOLES 1
130 #define MAX_SCLP_CONSOLES 1
132 static const char *data_dir
[16];
133 static int data_dir_idx
;
134 const char *bios_name
= NULL
;
135 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
136 int request_opengl
= -1;
138 const char* keyboard_layout
= NULL
;
140 const char *mem_path
= NULL
;
141 int mem_prealloc
= 0; /* force preallocation of physical target memory */
142 bool enable_mlock
= false;
144 NICInfo nd_table
[MAX_NICS
];
146 static int rtc_utc
= 1;
147 static int rtc_date_offset
= -1; /* -1 means no change */
148 QEMUClockType rtc_clock
;
149 int vga_interface_type
= VGA_NONE
;
150 static int full_screen
= 0;
151 static int no_frame
= 0;
153 static bool grab_on_hover
;
154 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
155 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
156 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
157 CharDriverState
*sclp_hds
[MAX_SCLP_CONSOLES
];
158 int win2k_install_hack
= 0;
164 int acpi_enabled
= 1;
167 static int no_reboot
;
170 int graphic_rotate
= 0;
171 const char *watchdog
;
172 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
175 const char *qemu_name
;
178 unsigned int nb_prom_envs
= 0;
179 const char *prom_envs
[MAX_PROM_ENVS
];
182 uint8_t *boot_splash_filedata
;
183 size_t boot_splash_filedata_size
;
184 uint8_t qemu_extra_params_fw
[2];
185 int only_migratable
; /* turn it off unless user states otherwise */
187 int icount_align_option
;
189 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
190 * little-endian "wire format" described in the SMBIOS 2.6 specification.
195 static NotifierList exit_notifiers
=
196 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
198 static NotifierList machine_init_done_notifiers
=
199 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
203 enum xen_mode xen_mode
= XEN_EMULATE
;
205 static int has_defaults
= 1;
206 static int default_serial
= 1;
207 static int default_parallel
= 1;
208 static int default_virtcon
= 1;
209 static int default_sclp
= 1;
210 static int default_monitor
= 1;
211 static int default_floppy
= 1;
212 static int default_cdrom
= 1;
213 static int default_sdcard
= 1;
214 static int default_vga
= 1;
215 static int default_net
= 1;
221 { .driver
= "isa-serial", .flag
= &default_serial
},
222 { .driver
= "isa-parallel", .flag
= &default_parallel
},
223 { .driver
= "isa-fdc", .flag
= &default_floppy
},
224 { .driver
= "floppy", .flag
= &default_floppy
},
225 { .driver
= "ide-cd", .flag
= &default_cdrom
},
226 { .driver
= "ide-hd", .flag
= &default_cdrom
},
227 { .driver
= "ide-drive", .flag
= &default_cdrom
},
228 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
229 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
230 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
231 { .driver
= "VGA", .flag
= &default_vga
},
232 { .driver
= "isa-vga", .flag
= &default_vga
},
233 { .driver
= "cirrus-vga", .flag
= &default_vga
},
234 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
235 { .driver
= "vmware-svga", .flag
= &default_vga
},
236 { .driver
= "qxl-vga", .flag
= &default_vga
},
237 { .driver
= "virtio-vga", .flag
= &default_vga
},
240 static QemuOptsList qemu_rtc_opts
= {
242 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
246 .type
= QEMU_OPT_STRING
,
249 .type
= QEMU_OPT_STRING
,
252 .type
= QEMU_OPT_STRING
,
254 { /* end of list */ }
258 static QemuOptsList qemu_sandbox_opts
= {
260 .implied_opt_name
= "enable",
261 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
265 .type
= QEMU_OPT_BOOL
,
267 { /* end of list */ }
271 static QemuOptsList qemu_option_rom_opts
= {
272 .name
= "option-rom",
273 .implied_opt_name
= "romfile",
274 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
278 .type
= QEMU_OPT_NUMBER
,
281 .type
= QEMU_OPT_STRING
,
283 { /* end of list */ }
287 static QemuOptsList qemu_machine_opts
= {
289 .implied_opt_name
= "type",
291 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
294 * no elements => accept any
295 * sanity checking will happen later
296 * when setting machine properties
302 static QemuOptsList qemu_boot_opts
= {
304 .implied_opt_name
= "order",
306 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
310 .type
= QEMU_OPT_STRING
,
313 .type
= QEMU_OPT_STRING
,
316 .type
= QEMU_OPT_BOOL
,
319 .type
= QEMU_OPT_STRING
,
321 .name
= "splash-time",
322 .type
= QEMU_OPT_STRING
,
324 .name
= "reboot-timeout",
325 .type
= QEMU_OPT_STRING
,
328 .type
= QEMU_OPT_BOOL
,
334 static QemuOptsList qemu_add_fd_opts
= {
336 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
340 .type
= QEMU_OPT_NUMBER
,
341 .help
= "file descriptor of which a duplicate is added to fd set",
344 .type
= QEMU_OPT_NUMBER
,
345 .help
= "ID of the fd set to add fd to",
348 .type
= QEMU_OPT_STRING
,
349 .help
= "free-form string used to describe fd",
351 { /* end of list */ }
355 static QemuOptsList qemu_object_opts
= {
357 .implied_opt_name
= "qom-type",
358 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
364 static QemuOptsList qemu_tpmdev_opts
= {
366 .implied_opt_name
= "type",
367 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
369 /* options are defined in the TPM backends */
370 { /* end of list */ }
374 static QemuOptsList qemu_realtime_opts
= {
376 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
380 .type
= QEMU_OPT_BOOL
,
382 { /* end of list */ }
386 static QemuOptsList qemu_msg_opts
= {
388 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
392 .type
= QEMU_OPT_BOOL
,
394 { /* end of list */ }
398 static QemuOptsList qemu_name_opts
= {
400 .implied_opt_name
= "guest",
402 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
406 .type
= QEMU_OPT_STRING
,
407 .help
= "Sets the name of the guest.\n"
408 "This name will be displayed in the SDL window caption.\n"
409 "The name will also be used for the VNC server",
412 .type
= QEMU_OPT_STRING
,
413 .help
= "Sets the name of the QEMU process, as shown in top etc",
415 .name
= "debug-threads",
416 .type
= QEMU_OPT_BOOL
,
417 .help
= "When enabled, name the individual threads; defaults off.\n"
418 "NOTE: The thread names are for debugging and not a\n"
421 { /* End of list */ }
425 static QemuOptsList qemu_mem_opts
= {
427 .implied_opt_name
= "size",
428 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
433 .type
= QEMU_OPT_SIZE
,
437 .type
= QEMU_OPT_NUMBER
,
441 .type
= QEMU_OPT_SIZE
,
443 { /* end of list */ }
447 static QemuOptsList qemu_icount_opts
= {
449 .implied_opt_name
= "shift",
451 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
455 .type
= QEMU_OPT_STRING
,
458 .type
= QEMU_OPT_BOOL
,
461 .type
= QEMU_OPT_BOOL
,
464 .type
= QEMU_OPT_STRING
,
467 .type
= QEMU_OPT_STRING
,
469 { /* end of list */ }
473 static QemuOptsList qemu_semihosting_config_opts
= {
474 .name
= "semihosting-config",
475 .implied_opt_name
= "enable",
476 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
480 .type
= QEMU_OPT_BOOL
,
483 .type
= QEMU_OPT_STRING
,
486 .type
= QEMU_OPT_STRING
,
488 { /* end of list */ }
492 static QemuOptsList qemu_fw_cfg_opts
= {
494 .implied_opt_name
= "name",
495 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
499 .type
= QEMU_OPT_STRING
,
500 .help
= "Sets the fw_cfg name of the blob to be inserted",
503 .type
= QEMU_OPT_STRING
,
504 .help
= "Sets the name of the file from which\n"
505 "the fw_cfg blob will be loaded",
508 .type
= QEMU_OPT_STRING
,
509 .help
= "Sets content of the blob to be inserted from a string",
511 { /* end of list */ }
515 #ifdef CONFIG_LIBISCSI
516 static QemuOptsList qemu_iscsi_opts
= {
518 .head
= QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts
.head
),
522 .type
= QEMU_OPT_STRING
,
523 .help
= "username for CHAP authentication to target",
526 .type
= QEMU_OPT_STRING
,
527 .help
= "password for CHAP authentication to target",
529 .name
= "password-secret",
530 .type
= QEMU_OPT_STRING
,
531 .help
= "ID of the secret providing password for CHAP "
532 "authentication to target",
534 .name
= "header-digest",
535 .type
= QEMU_OPT_STRING
,
536 .help
= "HeaderDigest setting. "
537 "{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
539 .name
= "initiator-name",
540 .type
= QEMU_OPT_STRING
,
541 .help
= "Initiator iqn name to use when connecting",
544 .type
= QEMU_OPT_NUMBER
,
545 .help
= "Request timeout in seconds (default 0 = no timeout)",
547 { /* end of list */ }
553 * Get machine options
555 * Returns: machine options (never null).
557 QemuOpts
*qemu_get_machine_opts(void)
559 return qemu_find_opts_singleton("machine");
562 const char *qemu_get_vm_name(void)
567 static void res_free(void)
569 g_free(boot_splash_filedata
);
570 boot_splash_filedata
= NULL
;
573 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
575 const char *driver
= qemu_opt_get(opts
, "driver");
580 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
581 if (strcmp(default_list
[i
].driver
, driver
) != 0)
583 *(default_list
[i
].flag
) = 0;
588 /***********************************************************/
591 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
593 /* We use RUN_STATE__MAX but any invalid value will do */
594 static RunState vmstop_requested
= RUN_STATE__MAX
;
595 static QemuMutex vmstop_lock
;
600 } RunStateTransition
;
602 static const RunStateTransition runstate_transitions_def
[] = {
604 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
605 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
606 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
608 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
609 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
610 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
611 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
612 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
613 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
614 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
615 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
616 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
617 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
618 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
619 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
621 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
622 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
623 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
625 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
626 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
627 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
629 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
630 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
631 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
632 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
634 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
635 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
636 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
638 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
639 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
640 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
642 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
643 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
644 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
645 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
647 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
648 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
650 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
652 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
653 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
654 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
655 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
656 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
657 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
658 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
659 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
660 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
661 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
662 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
664 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
666 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
667 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
668 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
670 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
671 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
672 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
673 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
674 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
675 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
677 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
678 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
679 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
680 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
682 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
683 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
684 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
686 { RUN_STATE__MAX
, RUN_STATE__MAX
},
689 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
691 bool runstate_check(RunState state
)
693 return current_run_state
== state
;
696 bool runstate_store(char *str
, size_t size
)
698 const char *state
= RunState_lookup
[current_run_state
];
699 size_t len
= strlen(state
) + 1;
704 memcpy(str
, state
, len
);
708 static void runstate_init(void)
710 const RunStateTransition
*p
;
712 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
713 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
714 runstate_valid_transitions
[p
->from
][p
->to
] = true;
717 qemu_mutex_init(&vmstop_lock
);
720 /* This function will abort() on invalid state transitions */
721 void runstate_set(RunState new_state
)
723 assert(new_state
< RUN_STATE__MAX
);
725 if (current_run_state
== new_state
) {
729 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
730 error_report("invalid runstate transition: '%s' -> '%s'",
731 RunState_lookup
[current_run_state
],
732 RunState_lookup
[new_state
]);
735 trace_runstate_set(new_state
);
736 current_run_state
= new_state
;
739 int runstate_is_running(void)
741 return runstate_check(RUN_STATE_RUNNING
);
744 bool runstate_needs_reset(void)
746 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
747 runstate_check(RUN_STATE_SHUTDOWN
);
750 StatusInfo
*qmp_query_status(Error
**errp
)
752 StatusInfo
*info
= g_malloc0(sizeof(*info
));
754 info
->running
= runstate_is_running();
755 info
->singlestep
= singlestep
;
756 info
->status
= current_run_state
;
761 static bool qemu_vmstop_requested(RunState
*r
)
763 qemu_mutex_lock(&vmstop_lock
);
764 *r
= vmstop_requested
;
765 vmstop_requested
= RUN_STATE__MAX
;
766 qemu_mutex_unlock(&vmstop_lock
);
767 return *r
< RUN_STATE__MAX
;
770 void qemu_system_vmstop_request_prepare(void)
772 qemu_mutex_lock(&vmstop_lock
);
775 void qemu_system_vmstop_request(RunState state
)
777 vmstop_requested
= state
;
778 qemu_mutex_unlock(&vmstop_lock
);
786 qemu_vmstop_requested(&requested
);
787 if (runstate_is_running() && requested
== RUN_STATE__MAX
) {
791 /* Ensure that a STOP/RESUME pair of events is emitted if a
792 * vmstop request was pending. The BLOCK_IO_ERROR event, for
793 * example, according to documentation is always followed by
796 if (runstate_is_running()) {
797 qapi_event_send_stop(&error_abort
);
799 replay_enable_events();
801 runstate_set(RUN_STATE_RUNNING
);
802 vm_state_notify(1, RUN_STATE_RUNNING
);
806 qapi_event_send_resume(&error_abort
);
810 /***********************************************************/
811 /* real time host monotonic timer */
813 static time_t qemu_time(void)
815 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
818 /***********************************************************/
819 /* host time/date access */
820 void qemu_get_timedate(struct tm
*tm
, int offset
)
822 time_t ti
= qemu_time();
825 if (rtc_date_offset
== -1) {
829 localtime_r(&ti
, tm
);
831 ti
-= rtc_date_offset
;
836 int qemu_timedate_diff(struct tm
*tm
)
840 if (rtc_date_offset
== -1)
842 seconds
= mktimegm(tm
);
845 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
846 seconds
= mktime(&tmp
);
849 seconds
= mktimegm(tm
) + rtc_date_offset
;
851 return seconds
- qemu_time();
854 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
856 time_t rtc_start_date
;
859 if (!strcmp(startdate
, "now") && legacy
) {
860 rtc_date_offset
= -1;
862 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
870 } else if (sscanf(startdate
, "%d-%d-%d",
882 rtc_start_date
= mktimegm(&tm
);
883 if (rtc_start_date
== -1) {
885 error_report("invalid date format");
886 error_printf("valid formats: "
887 "'2006-06-17T16:01:21' or '2006-06-17'\n");
890 rtc_date_offset
= qemu_time() - rtc_start_date
;
894 static void configure_rtc(QemuOpts
*opts
)
898 value
= qemu_opt_get(opts
, "base");
900 if (!strcmp(value
, "utc")) {
902 } else if (!strcmp(value
, "localtime")) {
903 Error
*blocker
= NULL
;
905 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
906 "-rtc base=localtime");
907 replay_add_blocker(blocker
);
909 configure_rtc_date_offset(value
, 0);
912 value
= qemu_opt_get(opts
, "clock");
914 if (!strcmp(value
, "host")) {
915 rtc_clock
= QEMU_CLOCK_HOST
;
916 } else if (!strcmp(value
, "rt")) {
917 rtc_clock
= QEMU_CLOCK_REALTIME
;
918 } else if (!strcmp(value
, "vm")) {
919 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
921 error_report("invalid option value '%s'", value
);
925 value
= qemu_opt_get(opts
, "driftfix");
927 if (!strcmp(value
, "slew")) {
928 static GlobalProperty slew_lost_ticks
= {
929 .driver
= "mc146818rtc",
930 .property
= "lost_tick_policy",
934 qdev_prop_register_global(&slew_lost_ticks
);
935 } else if (!strcmp(value
, "none")) {
936 /* discard is default */
938 error_report("invalid option value '%s'", value
);
944 /***********************************************************/
945 /* Bluetooth support */
948 static struct HCIInfo
*hci_table
[MAX_NICS
];
950 struct HCIInfo
*qemu_next_hci(void)
952 if (cur_hci
== nb_hcis
)
955 return hci_table
[cur_hci
++];
958 static int bt_hci_parse(const char *str
)
963 if (nb_hcis
>= MAX_NICS
) {
964 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
977 bdaddr
.b
[5] = 0x56 + nb_hcis
;
978 hci
->bdaddr_set(hci
, bdaddr
.b
);
980 hci_table
[nb_hcis
++] = hci
;
985 static void bt_vhci_add(int vlan_id
)
987 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
990 error_report("warning: adding a VHCI to an empty scatternet %i",
993 bt_vhci_init(bt_new_hci(vlan
));
996 static struct bt_device_s
*bt_device_add(const char *opt
)
998 struct bt_scatternet_s
*vlan
;
1000 char *endp
= strstr(opt
, ",vlan=");
1001 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
1004 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
1007 vlan_id
= strtol(endp
+ 6, &endp
, 0);
1009 error_report("unrecognised bluetooth vlan Id");
1014 vlan
= qemu_find_bt_vlan(vlan_id
);
1017 error_report("warning: adding a slave device to an empty scatternet %i",
1020 if (!strcmp(devname
, "keyboard"))
1021 return bt_keyboard_init(vlan
);
1023 error_report("unsupported bluetooth device '%s'", devname
);
1027 static int bt_parse(const char *opt
)
1029 const char *endp
, *p
;
1032 if (strstart(opt
, "hci", &endp
)) {
1033 if (!*endp
|| *endp
== ',') {
1035 if (!strstart(endp
, ",vlan=", 0))
1038 return bt_hci_parse(opt
);
1040 } else if (strstart(opt
, "vhci", &endp
)) {
1041 if (!*endp
|| *endp
== ',') {
1043 if (strstart(endp
, ",vlan=", &p
)) {
1044 vlan
= strtol(p
, (char **) &endp
, 0);
1046 error_report("bad scatternet '%s'", p
);
1050 error_report("bad parameter '%s'", endp
+ 1);
1059 } else if (strstart(opt
, "device:", &endp
))
1060 return !bt_device_add(endp
);
1062 error_report("bad bluetooth parameter '%s'", opt
);
1066 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1068 /* FIXME: change this to true for 1.3 */
1069 if (qemu_opt_get_bool(opts
, "enable", false)) {
1070 #ifdef CONFIG_SECCOMP
1071 if (seccomp_start() < 0) {
1072 error_report("failed to install seccomp syscall filter "
1077 error_report("seccomp support is disabled");
1085 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1087 const char *proc_name
;
1089 if (qemu_opt_get(opts
, "debug-threads")) {
1090 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1092 qemu_name
= qemu_opt_get(opts
, "guest");
1094 proc_name
= qemu_opt_get(opts
, "process");
1096 os_set_proc_name(proc_name
);
1102 bool defaults_enabled(void)
1104 return has_defaults
;
1108 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1110 int fd
, dupfd
, flags
;
1112 const char *fd_opaque
= NULL
;
1115 fd
= qemu_opt_get_number(opts
, "fd", -1);
1116 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1117 fd_opaque
= qemu_opt_get(opts
, "opaque");
1120 error_report("fd option is required and must be non-negative");
1124 if (fd
<= STDERR_FILENO
) {
1125 error_report("fd cannot be a standard I/O stream");
1130 * All fds inherited across exec() necessarily have FD_CLOEXEC
1131 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1133 flags
= fcntl(fd
, F_GETFD
);
1134 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1135 error_report("fd is not valid or already in use");
1140 error_report("set option is required and must be non-negative");
1144 #ifdef F_DUPFD_CLOEXEC
1145 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1149 qemu_set_cloexec(dupfd
);
1153 error_report("error duplicating fd: %s", strerror(errno
));
1157 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1158 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1165 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1169 fd
= qemu_opt_get_number(opts
, "fd", -1);
1176 /***********************************************************/
1177 /* QEMU Block devices */
1179 #define HD_OPTS "media=disk"
1180 #define CDROM_OPTS "media=cdrom"
1182 #define PFLASH_OPTS ""
1186 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1188 BlockInterfaceType
*block_default_type
= opaque
;
1190 return drive_new(opts
, *block_default_type
) == NULL
;
1193 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1195 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1196 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1201 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1202 int index
, const char *optstr
)
1207 if (!enable
|| drive_get_by_index(type
, index
)) {
1211 opts
= drive_add(type
, index
, NULL
, optstr
);
1213 drive_enable_snapshot(NULL
, opts
, NULL
);
1216 dinfo
= drive_new(opts
, type
);
1220 dinfo
->is_default
= true;
1224 static QemuOptsList qemu_smp_opts
= {
1226 .implied_opt_name
= "cpus",
1227 .merge_lists
= true,
1228 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1232 .type
= QEMU_OPT_NUMBER
,
1235 .type
= QEMU_OPT_NUMBER
,
1238 .type
= QEMU_OPT_NUMBER
,
1241 .type
= QEMU_OPT_NUMBER
,
1244 .type
= QEMU_OPT_NUMBER
,
1246 { /*End of list */ }
1250 static void smp_parse(QemuOpts
*opts
)
1253 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1254 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1255 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1256 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1258 /* compute missing values, prefer sockets over cores over threads */
1259 if (cpus
== 0 || sockets
== 0) {
1260 sockets
= sockets
> 0 ? sockets
: 1;
1261 cores
= cores
> 0 ? cores
: 1;
1262 threads
= threads
> 0 ? threads
: 1;
1264 cpus
= cores
* threads
* sockets
;
1266 } else if (cores
== 0) {
1267 threads
= threads
> 0 ? threads
: 1;
1268 cores
= cpus
/ (sockets
* threads
);
1269 cores
= cores
> 0 ? cores
: 1;
1270 } else if (threads
== 0) {
1271 threads
= cpus
/ (cores
* sockets
);
1272 threads
= threads
> 0 ? threads
: 1;
1273 } else if (sockets
* cores
* threads
< cpus
) {
1274 error_report("cpu topology: "
1275 "sockets (%u) * cores (%u) * threads (%u) < "
1277 sockets
, cores
, threads
, cpus
);
1281 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1283 if (max_cpus
< cpus
) {
1284 error_report("maxcpus must be equal to or greater than smp");
1288 if (sockets
* cores
* threads
> max_cpus
) {
1289 error_report("cpu topology: "
1290 "sockets (%u) * cores (%u) * threads (%u) > "
1292 sockets
, cores
, threads
, max_cpus
);
1298 smp_threads
= threads
;
1302 Error
*blocker
= NULL
;
1303 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1304 replay_add_blocker(blocker
);
1308 static void realtime_init(void)
1311 if (os_mlock() < 0) {
1312 error_report("locking memory failed");
1319 static void configure_msg(QemuOpts
*opts
)
1321 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1324 /***********************************************************/
1327 typedef struct SemihostingConfig
{
1329 SemihostingTarget target
;
1332 const char *cmdline
; /* concatenated argv */
1333 } SemihostingConfig
;
1335 static SemihostingConfig semihosting
;
1337 bool semihosting_enabled(void)
1339 return semihosting
.enabled
;
1342 SemihostingTarget
semihosting_get_target(void)
1344 return semihosting
.target
;
1347 const char *semihosting_get_arg(int i
)
1349 if (i
>= semihosting
.argc
) {
1352 return semihosting
.argv
[i
];
1355 int semihosting_get_argc(void)
1357 return semihosting
.argc
;
1360 const char *semihosting_get_cmdline(void)
1362 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1363 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1365 return semihosting
.cmdline
;
1368 static int add_semihosting_arg(void *opaque
,
1369 const char *name
, const char *val
,
1372 SemihostingConfig
*s
= opaque
;
1373 if (strcmp(name
, "arg") == 0) {
1375 /* one extra element as g_strjoinv() expects NULL-terminated array */
1376 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1377 s
->argv
[s
->argc
- 1] = val
;
1378 s
->argv
[s
->argc
] = NULL
;
1383 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1384 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1389 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1391 /* split -append and initialize argv[1..n] */
1392 cmd_token
= strtok(g_strdup(cmd
), " ");
1394 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1395 cmd_token
= strtok(NULL
, " ");
1399 /* Now we still need this for compatibility with XEN. */
1400 bool has_igd_gfx_passthru
;
1401 static void igd_gfx_passthru(void)
1403 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1406 /***********************************************************/
1409 static int usb_device_add(const char *devname
)
1411 USBDevice
*dev
= NULL
;
1412 #ifndef CONFIG_LINUX
1416 if (!machine_usb(current_machine
)) {
1420 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1421 dev
= usbdevice_create(devname
);
1425 /* the other ones */
1426 #ifndef CONFIG_LINUX
1427 /* only the linux version is qdev-ified, usb-bsd still needs this */
1428 if (strstart(devname
, "host:", &p
)) {
1429 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1439 static int usb_device_del(const char *devname
)
1444 if (strstart(devname
, "host:", &p
)) {
1448 if (!machine_usb(current_machine
)) {
1452 p
= strchr(devname
, '.');
1455 bus_num
= strtoul(devname
, NULL
, 0);
1456 addr
= strtoul(p
+ 1, NULL
, 0);
1458 return usb_device_delete_addr(bus_num
, addr
);
1461 static int usb_parse(const char *cmdline
)
1464 r
= usb_device_add(cmdline
);
1466 error_report("could not add USB device '%s'", cmdline
);
1471 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1473 const char *devname
= qdict_get_str(qdict
, "devname");
1474 if (usb_device_add(devname
) < 0) {
1475 error_report("could not add USB device '%s'", devname
);
1479 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1481 const char *devname
= qdict_get_str(qdict
, "devname");
1482 if (usb_device_del(devname
) < 0) {
1483 error_report("could not delete USB device '%s'", devname
);
1487 /***********************************************************/
1488 /* machine registration */
1490 MachineState
*current_machine
;
1492 static MachineClass
*find_machine(const char *name
)
1494 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1495 MachineClass
*mc
= NULL
;
1497 for (el
= machines
; el
; el
= el
->next
) {
1498 MachineClass
*temp
= el
->data
;
1500 if (!strcmp(temp
->name
, name
)) {
1505 !strcmp(temp
->alias
, name
)) {
1511 g_slist_free(machines
);
1515 MachineClass
*find_default_machine(void)
1517 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1518 MachineClass
*mc
= NULL
;
1520 for (el
= machines
; el
; el
= el
->next
) {
1521 MachineClass
*temp
= el
->data
;
1523 if (temp
->is_default
) {
1529 g_slist_free(machines
);
1533 MachineInfoList
*qmp_query_machines(Error
**errp
)
1535 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1536 MachineInfoList
*mach_list
= NULL
;
1538 for (el
= machines
; el
; el
= el
->next
) {
1539 MachineClass
*mc
= el
->data
;
1540 MachineInfoList
*entry
;
1543 info
= g_malloc0(sizeof(*info
));
1544 if (mc
->is_default
) {
1545 info
->has_is_default
= true;
1546 info
->is_default
= true;
1550 info
->has_alias
= true;
1551 info
->alias
= g_strdup(mc
->alias
);
1554 info
->name
= g_strdup(mc
->name
);
1555 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1556 info
->hotpluggable_cpus
= !!mc
->query_hotpluggable_cpus
;
1558 entry
= g_malloc0(sizeof(*entry
));
1559 entry
->value
= info
;
1560 entry
->next
= mach_list
;
1564 g_slist_free(machines
);
1568 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1570 ObjectProperty
*prop
;
1571 ObjectPropertyIterator iter
;
1573 if (!qemu_opt_has_help_opt(opts
)) {
1577 object_property_iter_init(&iter
, OBJECT(machine
));
1578 while ((prop
= object_property_iter_next(&iter
))) {
1583 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1584 prop
->name
, prop
->type
);
1585 if (prop
->description
) {
1586 error_printf(" (%s)\n", prop
->description
);
1595 /***********************************************************/
1596 /* main execution loop */
1598 struct vm_change_state_entry
{
1599 VMChangeStateHandler
*cb
;
1601 QLIST_ENTRY (vm_change_state_entry
) entries
;
1604 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1606 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1609 VMChangeStateEntry
*e
;
1611 e
= g_malloc0(sizeof (*e
));
1615 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1619 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1621 QLIST_REMOVE (e
, entries
);
1625 void vm_state_notify(int running
, RunState state
)
1627 VMChangeStateEntry
*e
, *next
;
1629 trace_vm_state_notify(running
, state
);
1631 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1632 e
->cb(e
->opaque
, running
, state
);
1636 static int reset_requested
;
1637 static int shutdown_requested
, shutdown_signal
= -1;
1638 static pid_t shutdown_pid
;
1639 static int powerdown_requested
;
1640 static int debug_requested
;
1641 static int suspend_requested
;
1642 static WakeupReason wakeup_reason
;
1643 static NotifierList powerdown_notifiers
=
1644 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1645 static NotifierList suspend_notifiers
=
1646 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1647 static NotifierList wakeup_notifiers
=
1648 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1649 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1651 int qemu_shutdown_requested_get(void)
1653 return shutdown_requested
;
1656 int qemu_reset_requested_get(void)
1658 return reset_requested
;
1661 static int qemu_shutdown_requested(void)
1663 return atomic_xchg(&shutdown_requested
, 0);
1666 static void qemu_kill_report(void)
1668 if (!qtest_driver() && shutdown_signal
!= -1) {
1669 if (shutdown_pid
== 0) {
1670 /* This happens for eg ^C at the terminal, so it's worth
1671 * avoiding printing an odd message in that case.
1673 error_report("terminating on signal %d", shutdown_signal
);
1675 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1677 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1678 shutdown_signal
, shutdown_pid
,
1679 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1680 g_free(shutdown_cmd
);
1682 shutdown_signal
= -1;
1686 static int qemu_reset_requested(void)
1688 int r
= reset_requested
;
1689 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1690 reset_requested
= 0;
1696 static int qemu_suspend_requested(void)
1698 int r
= suspend_requested
;
1699 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1700 suspend_requested
= 0;
1706 static WakeupReason
qemu_wakeup_requested(void)
1708 return wakeup_reason
;
1711 static int qemu_powerdown_requested(void)
1713 int r
= powerdown_requested
;
1714 powerdown_requested
= 0;
1718 static int qemu_debug_requested(void)
1720 int r
= debug_requested
;
1721 debug_requested
= 0;
1725 void qemu_system_reset(bool report
)
1729 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1731 cpu_synchronize_all_states();
1733 if (mc
&& mc
->reset
) {
1736 qemu_devices_reset();
1739 qapi_event_send_reset(&error_abort
);
1741 cpu_synchronize_all_post_reset();
1744 void qemu_system_guest_panicked(void)
1747 current_cpu
->crash_occurred
= true;
1749 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
, &error_abort
);
1750 vm_stop(RUN_STATE_GUEST_PANICKED
);
1752 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1754 qemu_system_shutdown_request();
1758 void qemu_system_reset_request(void)
1761 shutdown_requested
= 1;
1763 reset_requested
= 1;
1766 qemu_notify_event();
1769 static void qemu_system_suspend(void)
1772 notifier_list_notify(&suspend_notifiers
, NULL
);
1773 runstate_set(RUN_STATE_SUSPENDED
);
1774 qapi_event_send_suspend(&error_abort
);
1777 void qemu_system_suspend_request(void)
1779 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1782 suspend_requested
= 1;
1784 qemu_notify_event();
1787 void qemu_register_suspend_notifier(Notifier
*notifier
)
1789 notifier_list_add(&suspend_notifiers
, notifier
);
1792 void qemu_system_wakeup_request(WakeupReason reason
)
1794 trace_system_wakeup_request(reason
);
1796 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1799 if (!(wakeup_reason_mask
& (1 << reason
))) {
1802 runstate_set(RUN_STATE_RUNNING
);
1803 wakeup_reason
= reason
;
1804 qemu_notify_event();
1807 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1810 wakeup_reason_mask
|= (1 << reason
);
1812 wakeup_reason_mask
&= ~(1 << reason
);
1816 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1818 notifier_list_add(&wakeup_notifiers
, notifier
);
1821 void qemu_system_killed(int signal
, pid_t pid
)
1823 shutdown_signal
= signal
;
1827 /* Cannot call qemu_system_shutdown_request directly because
1828 * we are in a signal handler.
1830 shutdown_requested
= 1;
1831 qemu_notify_event();
1834 void qemu_system_shutdown_request(void)
1836 trace_qemu_system_shutdown_request();
1837 replay_shutdown_request();
1838 shutdown_requested
= 1;
1839 qemu_notify_event();
1842 static void qemu_system_powerdown(void)
1844 qapi_event_send_powerdown(&error_abort
);
1845 notifier_list_notify(&powerdown_notifiers
, NULL
);
1848 void qemu_system_powerdown_request(void)
1850 trace_qemu_system_powerdown_request();
1851 powerdown_requested
= 1;
1852 qemu_notify_event();
1855 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1857 notifier_list_add(&powerdown_notifiers
, notifier
);
1860 void qemu_system_debug_request(void)
1862 debug_requested
= 1;
1863 qemu_notify_event();
1866 static bool main_loop_should_exit(void)
1869 if (qemu_debug_requested()) {
1870 vm_stop(RUN_STATE_DEBUG
);
1872 if (qemu_suspend_requested()) {
1873 qemu_system_suspend();
1875 if (qemu_shutdown_requested()) {
1877 qapi_event_send_shutdown(&error_abort
);
1879 vm_stop(RUN_STATE_SHUTDOWN
);
1884 if (qemu_reset_requested()) {
1886 qemu_system_reset(VMRESET_REPORT
);
1888 if (!runstate_check(RUN_STATE_RUNNING
) &&
1889 !runstate_check(RUN_STATE_INMIGRATE
)) {
1890 runstate_set(RUN_STATE_PRELAUNCH
);
1893 if (qemu_wakeup_requested()) {
1895 qemu_system_reset(VMRESET_SILENT
);
1896 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1897 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1899 qapi_event_send_wakeup(&error_abort
);
1901 if (qemu_powerdown_requested()) {
1902 qemu_system_powerdown();
1904 if (qemu_vmstop_requested(&r
)) {
1910 static void main_loop(void)
1914 #ifdef CONFIG_PROFILER
1918 nonblocking
= tcg_enabled() && last_io
> 0;
1919 #ifdef CONFIG_PROFILER
1920 ti
= profile_getclock();
1922 last_io
= main_loop_wait(nonblocking
);
1923 #ifdef CONFIG_PROFILER
1924 dev_time
+= profile_getclock() - ti
;
1926 } while (!main_loop_should_exit());
1929 static void version(void)
1931 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1932 QEMU_COPYRIGHT
"\n");
1935 static void help(int exitcode
)
1938 printf("usage: %s [options] [disk_image]\n\n"
1939 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1940 error_get_progname());
1942 #define QEMU_OPTIONS_GENERATE_HELP
1943 #include "qemu-options-wrapper.h"
1945 printf("\nDuring emulation, the following keys are useful:\n"
1946 "ctrl-alt-f toggle full screen\n"
1947 "ctrl-alt-n switch to virtual console 'n'\n"
1948 "ctrl-alt toggle mouse and keyboard grab\n"
1950 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1955 #define HAS_ARG 0x0001
1957 typedef struct QEMUOption
{
1964 static const QEMUOption qemu_options
[] = {
1965 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1966 #define QEMU_OPTIONS_GENERATE_OPTIONS
1967 #include "qemu-options-wrapper.h"
1971 typedef struct VGAInterfaceInfo
{
1972 const char *opt_name
; /* option name */
1973 const char *name
; /* human-readable name */
1974 /* Class names indicating that support is available.
1975 * If no class is specified, the interface is always available */
1976 const char *class_names
[2];
1979 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1985 .name
= "standard VGA",
1986 .class_names
= { "VGA", "isa-vga" },
1989 .opt_name
= "cirrus",
1990 .name
= "Cirrus VGA",
1991 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1994 .opt_name
= "vmware",
1995 .name
= "VMWare SVGA",
1996 .class_names
= { "vmware-svga" },
1999 .opt_name
= "virtio",
2000 .name
= "Virtio VGA",
2001 .class_names
= { "virtio-vga" },
2006 .class_names
= { "qxl-vga" },
2010 .name
= "TCX framebuffer",
2011 .class_names
= { "SUNW,tcx" },
2015 .name
= "CG3 framebuffer",
2016 .class_names
= { "cgthree" },
2019 .opt_name
= "xenfb",
2023 static bool vga_interface_available(VGAInterfaceType t
)
2025 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2027 assert(t
< VGA_TYPE_MAX
);
2028 return !ti
->class_names
[0] ||
2029 object_class_by_name(ti
->class_names
[0]) ||
2030 object_class_by_name(ti
->class_names
[1]);
2033 static void select_vgahw(const char *p
)
2038 assert(vga_interface_type
== VGA_NONE
);
2039 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2040 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2041 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2042 if (!vga_interface_available(t
)) {
2043 error_report("%s not available", ti
->name
);
2046 vga_interface_type
= t
;
2050 if (t
== VGA_TYPE_MAX
) {
2052 error_report("unknown vga type: %s", p
);
2056 const char *nextopt
;
2058 if (strstart(opts
, ",retrace=", &nextopt
)) {
2060 if (strstart(opts
, "dumb", &nextopt
))
2061 vga_retrace_method
= VGA_RETRACE_DUMB
;
2062 else if (strstart(opts
, "precise", &nextopt
))
2063 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2064 else goto invalid_vga
;
2065 } else goto invalid_vga
;
2070 typedef enum DisplayType
{
2079 static DisplayType
select_display(const char *p
)
2082 DisplayType display
= DT_DEFAULT
;
2084 if (strstart(p
, "sdl", &opts
)) {
2088 const char *nextopt
;
2090 if (strstart(opts
, ",frame=", &nextopt
)) {
2092 if (strstart(opts
, "on", &nextopt
)) {
2094 } else if (strstart(opts
, "off", &nextopt
)) {
2097 goto invalid_sdl_args
;
2099 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2101 if (strstart(opts
, "on", &nextopt
)) {
2103 } else if (strstart(opts
, "off", &nextopt
)) {
2106 goto invalid_sdl_args
;
2108 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2110 if (strstart(opts
, "on", &nextopt
)) {
2112 } else if (strstart(opts
, "off", &nextopt
)) {
2115 goto invalid_sdl_args
;
2117 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2119 if (strstart(opts
, "on", &nextopt
)) {
2121 } else if (strstart(opts
, "off", &nextopt
)) {
2124 goto invalid_sdl_args
;
2126 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2128 if (strstart(opts
, "on", &nextopt
)) {
2130 } else if (strstart(opts
, "off", &nextopt
)) {
2133 goto invalid_sdl_args
;
2137 error_report("invalid SDL option string");
2143 error_report("SDL support is disabled");
2146 } else if (strstart(p
, "vnc", &opts
)) {
2148 vnc_parse(opts
+ 1, &error_fatal
);
2150 error_report("VNC requires a display argument vnc=<display>");
2153 } else if (strstart(p
, "curses", &opts
)) {
2154 #ifdef CONFIG_CURSES
2155 display
= DT_CURSES
;
2157 error_report("curses support is disabled");
2160 } else if (strstart(p
, "gtk", &opts
)) {
2164 const char *nextopt
;
2166 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2168 if (strstart(opts
, "on", &nextopt
)) {
2169 grab_on_hover
= true;
2170 } else if (strstart(opts
, "off", &nextopt
)) {
2171 grab_on_hover
= false;
2173 goto invalid_gtk_args
;
2175 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2177 if (strstart(opts
, "on", &nextopt
)) {
2179 } else if (strstart(opts
, "off", &nextopt
)) {
2182 goto invalid_gtk_args
;
2186 error_report("invalid GTK option string");
2192 error_report("GTK support is disabled");
2195 } else if (strstart(p
, "none", &opts
)) {
2198 error_report("unknown display type");
2205 static int balloon_parse(const char *arg
)
2209 if (strcmp(arg
, "none") == 0) {
2213 if (!strncmp(arg
, "virtio", 6)) {
2214 if (arg
[6] == ',') {
2215 /* have params -> parse them */
2216 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2221 /* create empty opts */
2222 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2225 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2232 char *qemu_find_file(int type
, const char *name
)
2238 /* Try the name as a straight path first */
2239 if (access(name
, R_OK
) == 0) {
2240 trace_load_file(name
, name
);
2241 return g_strdup(name
);
2245 case QEMU_FILE_TYPE_BIOS
:
2248 case QEMU_FILE_TYPE_KEYMAP
:
2249 subdir
= "keymaps/";
2255 for (i
= 0; i
< data_dir_idx
; i
++) {
2256 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2257 if (access(buf
, R_OK
) == 0) {
2258 trace_load_file(name
, buf
);
2266 static inline bool nonempty_str(const char *str
)
2271 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2275 const char *name
, *file
, *str
;
2276 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2278 if (fw_cfg
== NULL
) {
2279 error_report("fw_cfg device not available");
2282 name
= qemu_opt_get(opts
, "name");
2283 file
= qemu_opt_get(opts
, "file");
2284 str
= qemu_opt_get(opts
, "string");
2286 /* we need name and either a file or the content string */
2287 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2288 error_report("invalid argument(s)");
2291 if (nonempty_str(file
) && nonempty_str(str
)) {
2292 error_report("file and string are mutually exclusive");
2295 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2296 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2299 if (strncmp(name
, "opt/", 4) != 0) {
2300 error_report("warning: externally provided fw_cfg item names "
2301 "should be prefixed with \"opt/\"");
2303 if (nonempty_str(str
)) {
2304 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2305 buf
= g_memdup(str
, size
);
2307 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2308 error_report("can't load %s", file
);
2312 /* For legacy, keep user files in a specific global order. */
2313 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2314 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2315 fw_cfg_reset_order_override(fw_cfg
);
2319 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2321 return qdev_device_help(opts
);
2324 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2329 dev
= qdev_device_add(opts
, &err
);
2331 error_report_err(err
);
2334 object_unref(OBJECT(dev
));
2338 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2340 Error
*local_err
= NULL
;
2342 qemu_chr_new_from_opts(opts
, &local_err
);
2344 error_report_err(local_err
);
2350 #ifdef CONFIG_VIRTFS
2351 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2353 return qemu_fsdev_add(opts
);
2357 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2359 CharDriverState
*chr
;
2360 const char *chardev
;
2364 mode
= qemu_opt_get(opts
, "mode");
2368 if (strcmp(mode
, "readline") == 0) {
2369 flags
= MONITOR_USE_READLINE
;
2370 } else if (strcmp(mode
, "control") == 0) {
2371 flags
= MONITOR_USE_CONTROL
;
2373 error_report("unknown monitor mode \"%s\"", mode
);
2377 if (qemu_opt_get_bool(opts
, "pretty", 0))
2378 flags
|= MONITOR_USE_PRETTY
;
2380 if (qemu_opt_get_bool(opts
, "default", 0)) {
2381 error_report("option 'default' does nothing and is deprecated");
2384 chardev
= qemu_opt_get(opts
, "chardev");
2385 chr
= qemu_chr_find(chardev
);
2387 error_report("chardev \"%s\" not found", chardev
);
2391 monitor_init(chr
, flags
);
2395 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2397 static int monitor_device_index
= 0;
2402 if (strstart(optarg
, "chardev:", &p
)) {
2403 snprintf(label
, sizeof(label
), "%s", p
);
2405 snprintf(label
, sizeof(label
), "compat_monitor%d",
2406 monitor_device_index
);
2407 opts
= qemu_chr_parse_compat(label
, optarg
);
2409 error_report("parse error: %s", optarg
);
2414 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2415 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2416 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2417 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2418 monitor_device_index
++;
2421 struct device_config
{
2423 DEV_USB
, /* -usbdevice */
2425 DEV_SERIAL
, /* -serial */
2426 DEV_PARALLEL
, /* -parallel */
2427 DEV_VIRTCON
, /* -virtioconsole */
2428 DEV_DEBUGCON
, /* -debugcon */
2429 DEV_GDB
, /* -gdb, -s */
2430 DEV_SCLP
, /* s390 sclp */
2432 const char *cmdline
;
2434 QTAILQ_ENTRY(device_config
) next
;
2437 static QTAILQ_HEAD(, device_config
) device_configs
=
2438 QTAILQ_HEAD_INITIALIZER(device_configs
);
2440 static void add_device_config(int type
, const char *cmdline
)
2442 struct device_config
*conf
;
2444 conf
= g_malloc0(sizeof(*conf
));
2446 conf
->cmdline
= cmdline
;
2447 loc_save(&conf
->loc
);
2448 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2451 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2453 struct device_config
*conf
;
2456 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2457 if (conf
->type
!= type
)
2459 loc_push_restore(&conf
->loc
);
2460 rc
= func(conf
->cmdline
);
2461 loc_pop(&conf
->loc
);
2469 static int serial_parse(const char *devname
)
2471 static int index
= 0;
2474 if (strcmp(devname
, "none") == 0)
2476 if (index
== MAX_SERIAL_PORTS
) {
2477 error_report("too many serial ports");
2480 snprintf(label
, sizeof(label
), "serial%d", index
);
2481 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2482 if (!serial_hds
[index
]) {
2483 error_report("could not connect serial device"
2484 " to character backend '%s'", devname
);
2491 static int parallel_parse(const char *devname
)
2493 static int index
= 0;
2496 if (strcmp(devname
, "none") == 0)
2498 if (index
== MAX_PARALLEL_PORTS
) {
2499 error_report("too many parallel ports");
2502 snprintf(label
, sizeof(label
), "parallel%d", index
);
2503 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2504 if (!parallel_hds
[index
]) {
2505 error_report("could not connect parallel device"
2506 " to character backend '%s'", devname
);
2513 static int virtcon_parse(const char *devname
)
2515 QemuOptsList
*device
= qemu_find_opts("device");
2516 static int index
= 0;
2518 QemuOpts
*bus_opts
, *dev_opts
;
2520 if (strcmp(devname
, "none") == 0)
2522 if (index
== MAX_VIRTIO_CONSOLES
) {
2523 error_report("too many virtio consoles");
2527 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2528 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2530 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2531 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2533 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2534 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2535 if (!virtcon_hds
[index
]) {
2536 error_report("could not connect virtio console"
2537 " to character backend '%s'", devname
);
2540 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2546 static int sclp_parse(const char *devname
)
2548 QemuOptsList
*device
= qemu_find_opts("device");
2549 static int index
= 0;
2553 if (strcmp(devname
, "none") == 0) {
2556 if (index
== MAX_SCLP_CONSOLES
) {
2557 error_report("too many sclp consoles");
2561 assert(arch_type
== QEMU_ARCH_S390X
);
2563 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2564 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2566 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2567 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2568 if (!sclp_hds
[index
]) {
2569 error_report("could not connect sclp console"
2570 " to character backend '%s'", devname
);
2573 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2579 static int debugcon_parse(const char *devname
)
2583 if (!qemu_chr_new("debugcon", devname
)) {
2586 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2588 error_report("already have a debugcon device");
2591 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2592 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2596 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2598 const MachineClass
*mc1
= a
, *mc2
= b
;
2601 if (mc1
->family
== NULL
) {
2602 if (mc2
->family
== NULL
) {
2603 /* Compare standalone machine types against each other; they sort
2604 * in increasing order.
2606 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2607 object_class_get_name(OBJECT_CLASS(mc2
)));
2610 /* Standalone machine types sort after families. */
2614 if (mc2
->family
== NULL
) {
2615 /* Families sort before standalone machine types. */
2619 /* Families sort between each other alphabetically increasingly. */
2620 res
= strcmp(mc1
->family
, mc2
->family
);
2625 /* Within the same family, machine types sort in decreasing order. */
2626 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2627 object_class_get_name(OBJECT_CLASS(mc1
)));
2630 static MachineClass
*machine_parse(const char *name
)
2632 MachineClass
*mc
= NULL
;
2633 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2636 mc
= find_machine(name
);
2639 g_slist_free(machines
);
2642 if (name
&& !is_help_option(name
)) {
2643 error_report("unsupported machine type");
2644 error_printf("Use -machine help to list supported machines\n");
2646 printf("Supported machines are:\n");
2647 machines
= g_slist_sort(machines
, machine_class_cmp
);
2648 for (el
= machines
; el
; el
= el
->next
) {
2649 MachineClass
*mc
= el
->data
;
2651 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2653 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2654 mc
->is_default
? " (default)" : "");
2658 g_slist_free(machines
);
2659 exit(!name
|| !is_help_option(name
));
2662 void qemu_add_exit_notifier(Notifier
*notify
)
2664 notifier_list_add(&exit_notifiers
, notify
);
2667 void qemu_remove_exit_notifier(Notifier
*notify
)
2669 notifier_remove(notify
);
2672 static void qemu_run_exit_notifiers(void)
2674 notifier_list_notify(&exit_notifiers
, NULL
);
2677 static bool machine_init_done
;
2679 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2681 notifier_list_add(&machine_init_done_notifiers
, notify
);
2682 if (machine_init_done
) {
2683 notify
->notify(notify
, NULL
);
2687 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2689 notifier_remove(notify
);
2692 static void qemu_run_machine_init_done_notifiers(void)
2694 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2695 machine_init_done
= true;
2698 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2699 const char **poptarg
, int *poptind
)
2701 const QEMUOption
*popt
;
2702 int optind
= *poptind
;
2703 char *r
= argv
[optind
];
2706 loc_set_cmdline(argv
, optind
, 1);
2708 /* Treat --foo the same as -foo. */
2711 popt
= qemu_options
;
2714 error_report("invalid option");
2717 if (!strcmp(popt
->name
, r
+ 1))
2721 if (popt
->flags
& HAS_ARG
) {
2722 if (optind
>= argc
) {
2723 error_report("requires an argument");
2726 optarg
= argv
[optind
++];
2727 loc_set_cmdline(argv
, optind
- 2, 2);
2738 static MachineClass
*select_machine(void)
2740 MachineClass
*machine_class
= find_default_machine();
2745 loc_push_none(&loc
);
2747 opts
= qemu_get_machine_opts();
2748 qemu_opts_loc_restore(opts
);
2750 optarg
= qemu_opt_get(opts
, "type");
2752 machine_class
= machine_parse(optarg
);
2755 if (!machine_class
) {
2756 error_report("No machine specified, and there is no default");
2757 error_printf("Use -machine help to list supported machines\n");
2762 return machine_class
;
2765 static int machine_set_property(void *opaque
,
2766 const char *name
, const char *value
,
2769 Object
*obj
= OBJECT(opaque
);
2770 Error
*local_err
= NULL
;
2773 if (strcmp(name
, "type") == 0) {
2777 qom_name
= g_strdup(name
);
2778 for (p
= qom_name
; *p
; p
++) {
2784 object_property_parse(obj
, value
, qom_name
, &local_err
);
2788 error_report_err(local_err
);
2797 * Initial object creation happens before all other
2798 * QEMU data types are created. The majority of objects
2799 * can be created at this point. The rng-egd object
2800 * cannot be created here, as it depends on the chardev
2803 static bool object_create_initial(const char *type
)
2805 if (g_str_equal(type
, "rng-egd")) {
2810 * return false for concrete netfilters since
2811 * they depend on netdevs already existing
2813 if (g_str_equal(type
, "filter-buffer") ||
2814 g_str_equal(type
, "filter-dump") ||
2815 g_str_equal(type
, "filter-mirror") ||
2816 g_str_equal(type
, "filter-redirector") ||
2817 g_str_equal(type
, "colo-compare") ||
2818 g_str_equal(type
, "filter-rewriter") ||
2819 g_str_equal(type
, "filter-replay")) {
2823 /* Memory allocation by backends needs to be done
2824 * after configure_accelerator() (due to the tcg_enabled()
2825 * checks at memory_region_init_*()).
2827 * Also, allocation of large amounts of memory may delay
2828 * chardev initialization for too long, and trigger timeouts
2829 * on software that waits for a monitor socket to be created
2832 if (g_str_has_prefix(type
, "memory-backend-")) {
2841 * The remainder of object creation happens after the
2842 * creation of chardev, fsdev, net clients and device data types.
2844 static bool object_create_delayed(const char *type
)
2846 return !object_create_initial(type
);
2850 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2854 const char *mem_str
;
2855 const char *maxmem_str
, *slots_str
;
2856 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2857 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2860 loc_push_none(&loc
);
2861 qemu_opts_loc_restore(opts
);
2864 mem_str
= qemu_opt_get(opts
, "size");
2867 error_report("missing 'size' option value");
2871 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2873 /* Fix up legacy suffix-less format */
2874 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2875 uint64_t overflow_check
= sz
;
2878 if ((sz
>> 20) != overflow_check
) {
2879 error_report("too large 'size' option value");
2885 /* backward compatibility behaviour for case "-m 0" */
2887 sz
= default_ram_size
;
2890 sz
= QEMU_ALIGN_UP(sz
, 8192);
2892 if (ram_size
!= sz
) {
2893 error_report("ram size too large");
2897 /* store value for the future use */
2898 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2899 *maxram_size
= ram_size
;
2901 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2902 slots_str
= qemu_opt_get(opts
, "slots");
2903 if (maxmem_str
&& slots_str
) {
2906 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2907 slots
= qemu_opt_get_number(opts
, "slots", 0);
2908 if (sz
< ram_size
) {
2909 error_report("invalid value of -m option maxmem: "
2910 "maximum memory size (0x%" PRIx64
") must be at least "
2911 "the initial memory size (0x" RAM_ADDR_FMT
")",
2914 } else if (sz
> ram_size
) {
2916 error_report("invalid value of -m option: maxmem was "
2917 "specified, but no hotplug slots were specified");
2921 error_report("invalid value of -m option maxmem: "
2922 "memory slots were specified but maximum memory size "
2923 "(0x%" PRIx64
") is equal to the initial memory size "
2924 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2930 } else if ((!maxmem_str
&& slots_str
) ||
2931 (maxmem_str
&& !slots_str
)) {
2932 error_report("invalid -m option value: missing "
2933 "'%s' option", slots_str
? "maxmem" : "slots");
2940 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2944 g
= g_malloc0(sizeof(*g
));
2945 g
->driver
= qemu_opt_get(opts
, "driver");
2946 g
->property
= qemu_opt_get(opts
, "property");
2947 g
->value
= qemu_opt_get(opts
, "value");
2948 g
->user_provided
= true;
2949 g
->errp
= &error_fatal
;
2950 qdev_prop_register_global(g
);
2954 static int qemu_read_default_config_file(void)
2958 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2959 if (ret
< 0 && ret
!= -ENOENT
) {
2966 int main(int argc
, char **argv
, char **envp
)
2969 int snapshot
, linux_boot
;
2970 const char *initrd_filename
;
2971 const char *kernel_filename
, *kernel_cmdline
;
2972 const char *boot_order
= NULL
;
2973 const char *boot_once
= NULL
;
2975 int cyls
, heads
, secs
, translation
;
2976 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
2977 QemuOptsList
*olist
;
2980 const char *loadvm
= NULL
;
2981 MachineClass
*machine_class
;
2982 const char *cpu_model
;
2983 const char *vga_model
= NULL
;
2984 const char *qtest_chrdev
= NULL
;
2985 const char *qtest_log
= NULL
;
2986 const char *pid_file
= NULL
;
2987 const char *incoming
= NULL
;
2988 bool defconfig
= true;
2989 bool userconfig
= true;
2990 bool nographic
= false;
2991 DisplayType display_type
= DT_DEFAULT
;
2992 int display_remote
= 0;
2993 const char *log_mask
= NULL
;
2994 const char *log_file
= NULL
;
2995 char *trace_file
= NULL
;
2996 ram_addr_t maxram_size
;
2997 uint64_t ram_slots
= 0;
2998 FILE *vmstate_dump_file
= NULL
;
2999 Error
*main_loop_err
= NULL
;
3001 bool list_data_dirs
= false;
3003 module_call_init(MODULE_INIT_TRACE
);
3005 qemu_init_cpu_list();
3006 qemu_init_cpu_loop();
3007 qemu_mutex_lock_iothread();
3009 atexit(qemu_run_exit_notifiers
);
3010 error_set_progname(argv
[0]);
3011 qemu_init_exec_dir(argv
[0]);
3013 module_call_init(MODULE_INIT_QOM
);
3014 module_call_init(MODULE_INIT_QAPI
);
3016 qemu_add_opts(&qemu_drive_opts
);
3017 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3018 qemu_add_drive_opts(&qemu_common_drive_opts
);
3019 qemu_add_drive_opts(&qemu_drive_opts
);
3020 qemu_add_drive_opts(&bdrv_runtime_opts
);
3021 qemu_add_opts(&qemu_chardev_opts
);
3022 qemu_add_opts(&qemu_device_opts
);
3023 qemu_add_opts(&qemu_netdev_opts
);
3024 qemu_add_opts(&qemu_net_opts
);
3025 qemu_add_opts(&qemu_rtc_opts
);
3026 qemu_add_opts(&qemu_global_opts
);
3027 qemu_add_opts(&qemu_mon_opts
);
3028 qemu_add_opts(&qemu_trace_opts
);
3029 qemu_add_opts(&qemu_option_rom_opts
);
3030 qemu_add_opts(&qemu_machine_opts
);
3031 qemu_add_opts(&qemu_mem_opts
);
3032 qemu_add_opts(&qemu_smp_opts
);
3033 qemu_add_opts(&qemu_boot_opts
);
3034 qemu_add_opts(&qemu_sandbox_opts
);
3035 qemu_add_opts(&qemu_add_fd_opts
);
3036 qemu_add_opts(&qemu_object_opts
);
3037 qemu_add_opts(&qemu_tpmdev_opts
);
3038 qemu_add_opts(&qemu_realtime_opts
);
3039 qemu_add_opts(&qemu_msg_opts
);
3040 qemu_add_opts(&qemu_name_opts
);
3041 qemu_add_opts(&qemu_numa_opts
);
3042 qemu_add_opts(&qemu_icount_opts
);
3043 qemu_add_opts(&qemu_semihosting_config_opts
);
3044 qemu_add_opts(&qemu_fw_cfg_opts
);
3045 #ifdef CONFIG_LIBISCSI
3046 qemu_add_opts(&qemu_iscsi_opts
);
3048 module_call_init(MODULE_INIT_OPTS
);
3052 if (qcrypto_init(&err
) < 0) {
3053 error_reportf_err(err
, "cannot initialize crypto: ");
3056 rtc_clock
= QEMU_CLOCK_HOST
;
3058 QLIST_INIT (&vm_change_state_head
);
3059 os_setup_early_signal_handling();
3063 cyls
= heads
= secs
= 0;
3064 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3068 bdrv_init_with_whitelist();
3072 /* first pass of option parsing */
3074 while (optind
< argc
) {
3075 if (argv
[optind
][0] != '-') {
3079 const QEMUOption
*popt
;
3081 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3082 switch (popt
->index
) {
3083 case QEMU_OPTION_nodefconfig
:
3086 case QEMU_OPTION_nouserconfig
:
3093 if (defconfig
&& userconfig
) {
3094 if (qemu_read_default_config_file() < 0) {
3099 /* second pass of option parsing */
3104 if (argv
[optind
][0] != '-') {
3105 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3107 const QEMUOption
*popt
;
3109 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3110 if (!(popt
->arch_mask
& arch_type
)) {
3111 error_report("Option not supported for this target");
3114 switch(popt
->index
) {
3115 case QEMU_OPTION_no_kvm_irqchip
: {
3116 olist
= qemu_find_opts("machine");
3117 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3120 case QEMU_OPTION_cpu
:
3121 /* hw initialization will check this */
3124 case QEMU_OPTION_hda
:
3128 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3130 snprintf(buf
, sizeof(buf
),
3131 "%s,cyls=%d,heads=%d,secs=%d%s",
3132 HD_OPTS
, cyls
, heads
, secs
,
3133 translation
== BIOS_ATA_TRANSLATION_LBA
?
3135 translation
== BIOS_ATA_TRANSLATION_NONE
?
3136 ",trans=none" : "");
3137 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3140 case QEMU_OPTION_hdb
:
3141 case QEMU_OPTION_hdc
:
3142 case QEMU_OPTION_hdd
:
3143 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3146 case QEMU_OPTION_drive
:
3147 if (drive_def(optarg
) == NULL
) {
3151 case QEMU_OPTION_set
:
3152 if (qemu_set_option(optarg
) != 0)
3155 case QEMU_OPTION_global
:
3156 if (qemu_global_option(optarg
) != 0)
3159 case QEMU_OPTION_mtdblock
:
3160 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3162 case QEMU_OPTION_sd
:
3163 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3165 case QEMU_OPTION_pflash
:
3166 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3168 case QEMU_OPTION_snapshot
:
3171 case QEMU_OPTION_hdachs
:
3175 cyls
= strtol(p
, (char **)&p
, 0);
3176 if (cyls
< 1 || cyls
> 16383)
3181 heads
= strtol(p
, (char **)&p
, 0);
3182 if (heads
< 1 || heads
> 16)
3187 secs
= strtol(p
, (char **)&p
, 0);
3188 if (secs
< 1 || secs
> 63)
3192 if (!strcmp(p
, "large")) {
3193 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3194 } else if (!strcmp(p
, "rechs")) {
3195 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3196 } else if (!strcmp(p
, "none")) {
3197 translation
= BIOS_ATA_TRANSLATION_NONE
;
3198 } else if (!strcmp(p
, "lba")) {
3199 translation
= BIOS_ATA_TRANSLATION_LBA
;
3200 } else if (!strcmp(p
, "auto")) {
3201 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3205 } else if (*p
!= '\0') {
3207 error_report("invalid physical CHS format");
3210 if (hda_opts
!= NULL
) {
3211 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3213 qemu_opt_set_number(hda_opts
, "heads", heads
,
3215 qemu_opt_set_number(hda_opts
, "secs", secs
,
3217 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3218 qemu_opt_set(hda_opts
, "trans", "large",
3220 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3221 qemu_opt_set(hda_opts
, "trans", "rechs",
3223 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3224 qemu_opt_set(hda_opts
, "trans", "lba",
3226 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3227 qemu_opt_set(hda_opts
, "trans", "none",
3233 case QEMU_OPTION_numa
:
3234 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3240 case QEMU_OPTION_display
:
3241 display_type
= select_display(optarg
);
3243 case QEMU_OPTION_nographic
:
3244 olist
= qemu_find_opts("machine");
3245 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3247 display_type
= DT_NONE
;
3249 case QEMU_OPTION_curses
:
3250 #ifdef CONFIG_CURSES
3251 display_type
= DT_CURSES
;
3253 error_report("curses support is disabled");
3257 case QEMU_OPTION_portrait
:
3258 graphic_rotate
= 90;
3260 case QEMU_OPTION_rotate
:
3261 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3262 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3263 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3264 error_report("only 90, 180, 270 deg rotation is available");
3268 case QEMU_OPTION_kernel
:
3269 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3272 case QEMU_OPTION_initrd
:
3273 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3276 case QEMU_OPTION_append
:
3277 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3280 case QEMU_OPTION_dtb
:
3281 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3284 case QEMU_OPTION_cdrom
:
3285 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3287 case QEMU_OPTION_boot
:
3288 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3294 case QEMU_OPTION_fda
:
3295 case QEMU_OPTION_fdb
:
3296 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3299 case QEMU_OPTION_no_fd_bootchk
:
3302 case QEMU_OPTION_netdev
:
3304 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3308 case QEMU_OPTION_net
:
3310 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3314 #ifdef CONFIG_LIBISCSI
3315 case QEMU_OPTION_iscsi
:
3316 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3324 case QEMU_OPTION_tftp
:
3325 error_report("The -tftp option is deprecated. "
3326 "Please use '-netdev user,tftp=...' instead.");
3327 legacy_tftp_prefix
= optarg
;
3329 case QEMU_OPTION_bootp
:
3330 error_report("The -bootp option is deprecated. "
3331 "Please use '-netdev user,bootfile=...' instead.");
3332 legacy_bootp_filename
= optarg
;
3334 case QEMU_OPTION_redir
:
3335 error_report("The -redir option is deprecated. "
3336 "Please use '-netdev user,hostfwd=...' instead.");
3337 if (net_slirp_redir(optarg
) < 0)
3341 case QEMU_OPTION_bt
:
3342 add_device_config(DEV_BT
, optarg
);
3344 case QEMU_OPTION_audio_help
:
3348 case QEMU_OPTION_soundhw
:
3349 select_soundhw (optarg
);
3354 case QEMU_OPTION_version
:
3359 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3366 case QEMU_OPTION_tpmdev
:
3367 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3372 case QEMU_OPTION_mempath
:
3375 case QEMU_OPTION_mem_prealloc
:
3384 case QEMU_OPTION_DFILTER
:
3385 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3388 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3390 case QEMU_OPTION_gdb
:
3391 add_device_config(DEV_GDB
, optarg
);
3394 if (is_help_option(optarg
)) {
3395 list_data_dirs
= true;
3396 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3397 data_dir
[data_dir_idx
++] = optarg
;
3400 case QEMU_OPTION_bios
:
3401 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3404 case QEMU_OPTION_singlestep
:
3411 keyboard_layout
= optarg
;
3413 case QEMU_OPTION_localtime
:
3416 case QEMU_OPTION_vga
:
3425 w
= strtol(p
, (char **)&p
, 10);
3428 error_report("invalid resolution or depth");
3434 h
= strtol(p
, (char **)&p
, 10);
3439 depth
= strtol(p
, (char **)&p
, 10);
3440 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3441 depth
!= 24 && depth
!= 32)
3443 } else if (*p
== '\0') {
3444 depth
= graphic_depth
;
3451 graphic_depth
= depth
;
3454 case QEMU_OPTION_echr
:
3457 term_escape_char
= strtol(optarg
, &r
, 0);
3459 printf("Bad argument to echr\n");
3462 case QEMU_OPTION_monitor
:
3463 default_monitor
= 0;
3464 if (strncmp(optarg
, "none", 4)) {
3465 monitor_parse(optarg
, "readline", false);
3468 case QEMU_OPTION_qmp
:
3469 monitor_parse(optarg
, "control", false);
3470 default_monitor
= 0;
3472 case QEMU_OPTION_qmp_pretty
:
3473 monitor_parse(optarg
, "control", true);
3474 default_monitor
= 0;
3476 case QEMU_OPTION_mon
:
3477 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3482 default_monitor
= 0;
3484 case QEMU_OPTION_chardev
:
3485 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3491 case QEMU_OPTION_fsdev
:
3492 olist
= qemu_find_opts("fsdev");
3494 error_report("fsdev support is disabled");
3497 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3502 case QEMU_OPTION_virtfs
: {
3505 const char *writeout
, *sock_fd
, *socket
;
3507 olist
= qemu_find_opts("virtfs");
3509 error_report("virtfs support is disabled");
3512 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3517 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3518 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3519 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3522 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3523 qemu_opt_get(opts
, "mount_tag"),
3526 error_report("duplicate fsdev id: %s",
3527 qemu_opt_get(opts
, "mount_tag"));
3531 writeout
= qemu_opt_get(opts
, "writeout");
3533 #ifdef CONFIG_SYNC_FILE_RANGE
3534 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3536 error_report("writeout=immediate not supported "
3537 "on this platform");
3541 qemu_opt_set(fsdev
, "fsdriver",
3542 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3543 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3545 qemu_opt_set(fsdev
, "security_model",
3546 qemu_opt_get(opts
, "security_model"),
3548 socket
= qemu_opt_get(opts
, "socket");
3550 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3552 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3554 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3557 qemu_opt_set_bool(fsdev
, "readonly",
3558 qemu_opt_get_bool(opts
, "readonly", 0),
3560 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3562 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3563 qemu_opt_set(device
, "fsdev",
3564 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3565 qemu_opt_set(device
, "mount_tag",
3566 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3569 case QEMU_OPTION_virtfs_synth
: {
3573 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3576 error_report("duplicate option: %s", "virtfs_synth");
3579 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3581 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3583 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3584 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3585 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3588 case QEMU_OPTION_serial
:
3589 add_device_config(DEV_SERIAL
, optarg
);
3591 if (strncmp(optarg
, "mon:", 4) == 0) {
3592 default_monitor
= 0;
3595 case QEMU_OPTION_watchdog
:
3597 error_report("only one watchdog option may be given");
3602 case QEMU_OPTION_watchdog_action
:
3603 if (select_watchdog_action(optarg
) == -1) {
3604 error_report("unknown -watchdog-action parameter");
3608 case QEMU_OPTION_virtiocon
:
3609 add_device_config(DEV_VIRTCON
, optarg
);
3610 default_virtcon
= 0;
3611 if (strncmp(optarg
, "mon:", 4) == 0) {
3612 default_monitor
= 0;
3615 case QEMU_OPTION_parallel
:
3616 add_device_config(DEV_PARALLEL
, optarg
);
3617 default_parallel
= 0;
3618 if (strncmp(optarg
, "mon:", 4) == 0) {
3619 default_monitor
= 0;
3622 case QEMU_OPTION_debugcon
:
3623 add_device_config(DEV_DEBUGCON
, optarg
);
3625 case QEMU_OPTION_loadvm
:
3628 case QEMU_OPTION_full_screen
:
3631 case QEMU_OPTION_no_frame
:
3634 case QEMU_OPTION_alt_grab
:
3637 case QEMU_OPTION_ctrl_grab
:
3640 case QEMU_OPTION_no_quit
:
3643 case QEMU_OPTION_sdl
:
3645 display_type
= DT_SDL
;
3648 error_report("SDL support is disabled");
3651 case QEMU_OPTION_pidfile
:
3654 case QEMU_OPTION_win2k_hack
:
3655 win2k_install_hack
= 1;
3657 case QEMU_OPTION_rtc_td_hack
: {
3658 static GlobalProperty slew_lost_ticks
= {
3659 .driver
= "mc146818rtc",
3660 .property
= "lost_tick_policy",
3664 qdev_prop_register_global(&slew_lost_ticks
);
3667 case QEMU_OPTION_acpitable
:
3668 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3673 acpi_table_add(opts
, &error_fatal
);
3675 case QEMU_OPTION_smbios
:
3676 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3681 smbios_entry_add(opts
, &error_fatal
);
3683 case QEMU_OPTION_fwcfg
:
3684 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3690 case QEMU_OPTION_enable_kvm
:
3691 olist
= qemu_find_opts("machine");
3692 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3694 case QEMU_OPTION_enable_hax
:
3695 olist
= qemu_find_opts("machine");
3696 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3699 case QEMU_OPTION_machine
:
3700 olist
= qemu_find_opts("machine");
3701 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3706 case QEMU_OPTION_no_kvm
:
3707 olist
= qemu_find_opts("machine");
3708 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3710 case QEMU_OPTION_no_kvm_pit
: {
3711 error_report("warning: ignoring deprecated option");
3714 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3715 static GlobalProperty kvm_pit_lost_tick_policy
= {
3716 .driver
= "kvm-pit",
3717 .property
= "lost_tick_policy",
3721 error_report("warning: deprecated, replaced by "
3722 "-global kvm-pit.lost_tick_policy=discard");
3723 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3726 case QEMU_OPTION_usb
:
3727 olist
= qemu_find_opts("machine");
3728 qemu_opts_parse_noisily(olist
, "usb=on", false);
3730 case QEMU_OPTION_usbdevice
:
3731 olist
= qemu_find_opts("machine");
3732 qemu_opts_parse_noisily(olist
, "usb=on", false);
3733 add_device_config(DEV_USB
, optarg
);
3735 case QEMU_OPTION_device
:
3736 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3741 case QEMU_OPTION_smp
:
3742 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3747 case QEMU_OPTION_vnc
:
3748 vnc_parse(optarg
, &error_fatal
);
3750 case QEMU_OPTION_no_acpi
:
3753 case QEMU_OPTION_no_hpet
:
3756 case QEMU_OPTION_balloon
:
3757 if (balloon_parse(optarg
) < 0) {
3758 error_report("unknown -balloon argument %s", optarg
);
3762 case QEMU_OPTION_no_reboot
:
3765 case QEMU_OPTION_no_shutdown
:
3768 case QEMU_OPTION_show_cursor
:
3771 case QEMU_OPTION_uuid
:
3772 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3773 error_report("failed to parse UUID string: wrong format");
3776 qemu_uuid_set
= true;
3778 case QEMU_OPTION_option_rom
:
3779 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3780 error_report("too many option ROMs");
3783 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3788 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3789 option_rom
[nb_option_roms
].bootindex
=
3790 qemu_opt_get_number(opts
, "bootindex", -1);
3791 if (!option_rom
[nb_option_roms
].name
) {
3792 error_report("Option ROM file is not specified");
3797 case QEMU_OPTION_semihosting
:
3798 semihosting
.enabled
= true;
3799 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3801 case QEMU_OPTION_semihosting_config
:
3802 semihosting
.enabled
= true;
3803 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3806 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3808 const char *target
= qemu_opt_get(opts
, "target");
3809 if (target
!= NULL
) {
3810 if (strcmp("native", target
) == 0) {
3811 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3812 } else if (strcmp("gdb", target
) == 0) {
3813 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3814 } else if (strcmp("auto", target
) == 0) {
3815 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3817 error_report("unsupported semihosting-config %s",
3822 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3824 /* Set semihosting argument count and vector */
3825 qemu_opt_foreach(opts
, add_semihosting_arg
,
3826 &semihosting
, NULL
);
3828 error_report("unsupported semihosting-config %s", optarg
);
3832 case QEMU_OPTION_tdf
:
3833 error_report("warning: ignoring deprecated option");
3835 case QEMU_OPTION_name
:
3836 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3842 case QEMU_OPTION_prom_env
:
3843 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3844 error_report("too many prom variables");
3847 prom_envs
[nb_prom_envs
] = optarg
;
3850 case QEMU_OPTION_old_param
:
3853 case QEMU_OPTION_clock
:
3854 /* Clock options no longer exist. Keep this option for
3855 * backward compatibility.
3858 case QEMU_OPTION_startdate
:
3859 configure_rtc_date_offset(optarg
, 1);
3861 case QEMU_OPTION_rtc
:
3862 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3867 configure_rtc(opts
);
3869 case QEMU_OPTION_tb_size
:
3870 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3871 if (tcg_tb_size
< 0) {
3875 case QEMU_OPTION_icount
:
3876 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3882 case QEMU_OPTION_incoming
:
3884 runstate_set(RUN_STATE_INMIGRATE
);
3888 case QEMU_OPTION_only_migratable
:
3889 only_migratable
= 1;
3891 case QEMU_OPTION_nodefaults
:
3894 case QEMU_OPTION_xen_domid
:
3895 if (!(xen_available())) {
3896 error_report("Option not supported for this target");
3899 xen_domid
= atoi(optarg
);
3901 case QEMU_OPTION_xen_create
:
3902 if (!(xen_available())) {
3903 error_report("Option not supported for this target");
3906 xen_mode
= XEN_CREATE
;
3908 case QEMU_OPTION_xen_attach
:
3909 if (!(xen_available())) {
3910 error_report("Option not supported for this target");
3913 xen_mode
= XEN_ATTACH
;
3915 case QEMU_OPTION_trace
:
3917 trace_file
= trace_opt_parse(optarg
);
3919 case QEMU_OPTION_readconfig
:
3921 int ret
= qemu_read_config_file(optarg
);
3923 error_report("read config %s: %s", optarg
,
3929 case QEMU_OPTION_spice
:
3930 olist
= qemu_find_opts("spice");
3932 error_report("spice support is disabled");
3935 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3941 case QEMU_OPTION_writeconfig
:
3944 if (strcmp(optarg
, "-") == 0) {
3947 fp
= fopen(optarg
, "w");
3949 error_report("open %s: %s", optarg
,
3954 qemu_config_write(fp
);
3960 case QEMU_OPTION_qtest
:
3961 qtest_chrdev
= optarg
;
3963 case QEMU_OPTION_qtest_log
:
3966 case QEMU_OPTION_sandbox
:
3967 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
3973 case QEMU_OPTION_add_fd
:
3975 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3981 error_report("File descriptor passing is disabled on this "
3986 case QEMU_OPTION_object
:
3987 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
3993 case QEMU_OPTION_realtime
:
3994 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
3999 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4001 case QEMU_OPTION_msg
:
4002 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4007 configure_msg(opts
);
4009 case QEMU_OPTION_dump_vmstate
:
4010 if (vmstate_dump_file
) {
4011 error_report("only one '-dump-vmstate' "
4012 "option may be given");
4015 vmstate_dump_file
= fopen(optarg
, "w");
4016 if (vmstate_dump_file
== NULL
) {
4017 error_report("open %s: %s", optarg
, strerror(errno
));
4022 os_parse_cmd_args(popt
->index
, optarg
);
4027 * Clear error location left behind by the loop.
4028 * Best done right after the loop. Do not insert code here!
4032 replay_configure(icount_opts
);
4034 machine_class
= select_machine();
4036 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4040 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4041 error_report("could not acquire pid file: %s", strerror(errno
));
4045 if (qemu_init_main_loop(&main_loop_err
)) {
4046 error_report_err(main_loop_err
);
4050 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4051 parse_sandbox
, NULL
, NULL
)) {
4055 if (qemu_opts_foreach(qemu_find_opts("name"),
4056 parse_name
, NULL
, NULL
)) {
4061 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4062 parse_add_fd
, NULL
, NULL
)) {
4066 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4067 cleanup_add_fd
, NULL
, NULL
)) {
4072 current_machine
= MACHINE(object_new(object_class_get_name(
4073 OBJECT_CLASS(machine_class
))));
4074 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4077 object_property_add_child(object_get_root(), "machine",
4078 OBJECT(current_machine
), &error_abort
);
4080 if (machine_class
->minimum_page_bits
) {
4081 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4082 /* This would be a board error: specifying a minimum smaller than
4083 * a target's compile-time fixed setting.
4085 g_assert_not_reached();
4089 cpu_exec_init_all();
4091 if (machine_class
->hw_version
) {
4092 qemu_set_hw_version(machine_class
->hw_version
);
4095 if (cpu_model
&& is_help_option(cpu_model
)) {
4096 list_cpus(stdout
, &fprintf
, cpu_model
);
4100 if (!trace_init_backends()) {
4103 trace_init_file(trace_file
);
4105 /* Open the logfile at this point and set the log mask if necessary.
4108 qemu_set_log_filename(log_file
, &error_fatal
);
4113 mask
= qemu_str_to_log_mask(log_mask
);
4115 qemu_print_log_usage(stdout
);
4123 /* If no data_dir is specified then try to find it relative to the
4125 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4126 data_dir
[data_dir_idx
] = os_find_datadir();
4127 if (data_dir
[data_dir_idx
] != NULL
) {
4131 /* If all else fails use the install path specified when building. */
4132 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4133 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4136 /* -L help lists the data directories and exits. */
4137 if (list_data_dirs
) {
4138 for (i
= 0; i
< data_dir_idx
; i
++) {
4139 printf("%s\n", data_dir
[i
]);
4144 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4146 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4147 if (max_cpus
> machine_class
->max_cpus
) {
4148 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4149 "supported by machine '%s' (%d)", max_cpus
,
4150 machine_class
->name
, machine_class
->max_cpus
);
4155 * Get the default machine options from the machine if it is not already
4156 * specified either by the configuration file or by the command line.
4158 if (machine_class
->default_machine_opts
) {
4159 qemu_opts_set_defaults(qemu_find_opts("machine"),
4160 machine_class
->default_machine_opts
, 0);
4163 qemu_opts_foreach(qemu_find_opts("device"),
4164 default_driver_check
, NULL
, NULL
);
4165 qemu_opts_foreach(qemu_find_opts("global"),
4166 default_driver_check
, NULL
, NULL
);
4168 if (!vga_model
&& !default_vga
) {
4169 vga_interface_type
= VGA_DEVICE
;
4171 if (!has_defaults
|| machine_class
->no_serial
) {
4174 if (!has_defaults
|| machine_class
->no_parallel
) {
4175 default_parallel
= 0;
4177 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4178 default_virtcon
= 0;
4180 if (!has_defaults
|| !machine_class
->use_sclp
) {
4183 if (!has_defaults
|| machine_class
->no_floppy
) {
4186 if (!has_defaults
|| machine_class
->no_cdrom
) {
4189 if (!has_defaults
|| machine_class
->no_sdcard
) {
4192 if (!has_defaults
) {
4193 default_monitor
= 0;
4198 if (is_daemonized()) {
4199 /* According to documentation and historically, -nographic redirects
4200 * serial port, parallel port and monitor to stdio, which does not work
4201 * with -daemonize. We can redirect these to null instead, but since
4202 * -nographic is legacy, let's just error out.
4203 * We disallow -nographic only if all other ports are not redirected
4204 * explicitly, to not break existing legacy setups which uses
4205 * -nographic _and_ redirects all ports explicitly - this is valid
4206 * usage, -nographic is just a no-op in this case.
4209 && (default_parallel
|| default_serial
4210 || default_monitor
|| default_virtcon
)) {
4211 error_report("-nographic cannot be used with -daemonize");
4214 #ifdef CONFIG_CURSES
4215 if (display_type
== DT_CURSES
) {
4216 error_report("curses display cannot be used with -daemonize");
4223 if (default_parallel
)
4224 add_device_config(DEV_PARALLEL
, "null");
4225 if (default_serial
&& default_monitor
) {
4226 add_device_config(DEV_SERIAL
, "mon:stdio");
4227 } else if (default_virtcon
&& default_monitor
) {
4228 add_device_config(DEV_VIRTCON
, "mon:stdio");
4229 } else if (default_sclp
&& default_monitor
) {
4230 add_device_config(DEV_SCLP
, "mon:stdio");
4233 add_device_config(DEV_SERIAL
, "stdio");
4234 if (default_virtcon
)
4235 add_device_config(DEV_VIRTCON
, "stdio");
4237 add_device_config(DEV_SCLP
, "stdio");
4239 if (default_monitor
)
4240 monitor_parse("stdio", "readline", false);
4244 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4245 if (default_parallel
)
4246 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4247 if (default_monitor
)
4248 monitor_parse("vc:80Cx24C", "readline", false);
4249 if (default_virtcon
)
4250 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4252 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4256 #if defined(CONFIG_VNC)
4257 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4261 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4262 #if defined(CONFIG_GTK)
4263 display_type
= DT_GTK
;
4264 #elif defined(CONFIG_SDL)
4265 display_type
= DT_SDL
;
4266 #elif defined(CONFIG_COCOA)
4267 display_type
= DT_COCOA
;
4268 #elif defined(CONFIG_VNC)
4269 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4271 display_type
= DT_NONE
;
4275 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4276 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4277 "for SDL, ignoring option");
4279 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4280 error_report("-no-quit is only valid for GTK and SDL, "
4284 if (display_type
== DT_GTK
) {
4285 early_gtk_display_init(request_opengl
);
4288 if (display_type
== DT_SDL
) {
4289 sdl_display_early_init(request_opengl
);
4292 if (request_opengl
== 1 && display_opengl
== 0) {
4293 #if defined(CONFIG_OPENGL)
4294 error_report("OpenGL is not supported by the display");
4296 error_report("OpenGL support is disabled");
4304 if (qemu_opts_foreach(qemu_find_opts("object"),
4305 user_creatable_add_opts_foreach
,
4306 object_create_initial
, NULL
)) {
4310 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4311 chardev_init_func
, NULL
, NULL
)) {
4315 #ifdef CONFIG_VIRTFS
4316 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4317 fsdev_init_func
, NULL
, NULL
)) {
4322 if (qemu_opts_foreach(qemu_find_opts("device"),
4323 device_help_func
, NULL
, NULL
)) {
4327 machine_opts
= qemu_get_machine_opts();
4328 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4330 object_unref(OBJECT(current_machine
));
4334 configure_accelerator(current_machine
);
4337 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4340 machine_opts
= qemu_get_machine_opts();
4341 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4342 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4343 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4344 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4346 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4348 boot_order
= qemu_opt_get(opts
, "order");
4350 validate_bootdevices(boot_order
, &error_fatal
);
4353 boot_once
= qemu_opt_get(opts
, "once");
4355 validate_bootdevices(boot_once
, &error_fatal
);
4358 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4359 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4363 boot_order
= machine_class
->default_boot_order
;
4366 if (!kernel_cmdline
) {
4367 kernel_cmdline
= "";
4368 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4371 linux_boot
= (kernel_filename
!= NULL
);
4373 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4374 error_report("-append only allowed with -kernel option");
4378 if (!linux_boot
&& initrd_filename
!= NULL
) {
4379 error_report("-initrd only allowed with -kernel option");
4383 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4384 /* fall back to the -kernel/-append */
4385 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4388 os_set_line_buffering();
4390 /* spice needs the timers to be initialized by this point */
4395 if (!tcg_enabled()) {
4396 error_report("-icount is not allowed with hardware virtualization");
4399 configure_icount(icount_opts
, &error_abort
);
4400 qemu_opts_del(icount_opts
);
4404 QemuOptsList
*net
= qemu_find_opts("net");
4405 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4407 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4413 if (net_init_clients() < 0) {
4417 if (qemu_opts_foreach(qemu_find_opts("object"),
4418 user_creatable_add_opts_foreach
,
4419 object_create_delayed
, NULL
)) {
4424 if (tpm_init() < 0) {
4429 /* init the bluetooth world */
4430 if (foreach_device_config(DEV_BT
, bt_parse
))
4433 if (!xen_enabled()) {
4434 /* On 32-bit hosts, QEMU is limited by virtual address space */
4435 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4436 error_report("at most 2047 MB RAM can be simulated");
4444 /* If the currently selected machine wishes to override the units-per-bus
4445 * property of its default HBA interface type, do so now. */
4446 if (machine_class
->units_per_default_bus
) {
4447 override_max_devs(machine_class
->block_default_type
,
4448 machine_class
->units_per_default_bus
);
4451 /* open the virtual block devices */
4452 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4453 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4456 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4457 &machine_class
->block_default_type
, NULL
)) {
4461 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4463 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4464 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4466 parse_numa_opts(machine_class
);
4468 if (qemu_opts_foreach(qemu_find_opts("mon"),
4469 mon_init_func
, NULL
, NULL
)) {
4473 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4475 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4477 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4479 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4482 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4485 /* If no default VGA is requested, the default is "none". */
4487 if (machine_class
->default_display
) {
4488 vga_model
= machine_class
->default_display
;
4489 } else if (vga_interface_available(VGA_CIRRUS
)) {
4490 vga_model
= "cirrus";
4491 } else if (vga_interface_available(VGA_STD
)) {
4496 select_vgahw(vga_model
);
4500 i
= select_watchdog(watchdog
);
4502 exit (i
== 1 ? 1 : 0);
4505 machine_register_compat_props(current_machine
);
4507 qemu_opts_foreach(qemu_find_opts("global"),
4508 global_init_func
, NULL
, NULL
);
4510 /* This checkpoint is required by replay to separate prior clock
4511 reading from the other reads, because timer polling functions query
4512 clock values from the log. */
4513 replay_checkpoint(CHECKPOINT_INIT
);
4514 qdev_machine_init();
4516 current_machine
->ram_size
= ram_size
;
4517 current_machine
->maxram_size
= maxram_size
;
4518 current_machine
->ram_slots
= ram_slots
;
4519 current_machine
->boot_order
= boot_order
;
4520 current_machine
->cpu_model
= cpu_model
;
4522 machine_class
->init(current_machine
);
4528 cpu_synchronize_all_post_init();
4530 if (hax_enabled()) {
4534 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4535 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4539 /* init USB devices */
4540 if (machine_usb(current_machine
)) {
4541 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4545 /* Check if IGD GFX passthrough. */
4548 /* init generic devices */
4549 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4550 if (qemu_opts_foreach(qemu_find_opts("device"),
4551 device_init_func
, NULL
, NULL
)) {
4555 numa_post_machine_init();
4557 rom_reset_order_override();
4559 /* Did we create any drives that we failed to create a device for? */
4560 drive_check_orphaned();
4562 /* Don't warn about the default network setup that you get if
4563 * no command line -net or -netdev options are specified. There
4564 * are two cases that we would otherwise complain about:
4565 * (1) board doesn't support a NIC but the implicit "-net nic"
4567 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4568 * sets up a nic that isn't connected to anything.
4571 net_check_clients();
4576 qemu_boot_set(boot_once
, &error_fatal
);
4577 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4580 ds
= init_displaystate();
4582 /* init local displays */
4583 switch (display_type
) {
4585 curses_display_init(ds
, full_screen
);
4588 sdl_display_init(ds
, full_screen
, no_frame
);
4591 cocoa_display_init(ds
, full_screen
);
4594 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4600 /* must be after terminal init, SDL library changes signal handlers */
4601 os_setup_signal_handling();
4603 /* init remote displays */
4605 qemu_opts_foreach(qemu_find_opts("vnc"),
4606 vnc_init_func
, NULL
, NULL
);
4610 qemu_spice_display_init();
4613 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4617 qdev_machine_creation_done();
4619 /* TODO: once all bus devices are qdevified, this should be done
4620 * when bus is created by qdev.c */
4621 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4622 qemu_run_machine_init_done_notifiers();
4624 if (rom_check_and_register_reset() != 0) {
4625 error_report("rom check and register reset failed");
4631 /* This checkpoint is required by replay to separate prior clock
4632 reading from the other reads, because timer polling functions query
4633 clock values from the log. */
4634 replay_checkpoint(CHECKPOINT_RESET
);
4635 qemu_system_reset(VMRESET_SILENT
);
4636 register_global_state();
4638 if (load_vmstate(loadvm
) < 0) {
4643 qdev_prop_check_globals();
4644 if (vmstate_dump_file
) {
4646 dump_vmstate_json_to_file(vmstate_dump_file
);
4651 Error
*local_err
= NULL
;
4652 qemu_start_incoming_migration(incoming
, &local_err
);
4654 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4657 } else if (autostart
) {
4664 replay_disable_events();
4665 iothread_stop_all();
4671 /* vhost-user must be cleaned up before chardevs. */