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 .name
= "rrsnapshot",
470 .type
= QEMU_OPT_STRING
,
472 { /* end of list */ }
476 static QemuOptsList qemu_semihosting_config_opts
= {
477 .name
= "semihosting-config",
478 .implied_opt_name
= "enable",
479 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
483 .type
= QEMU_OPT_BOOL
,
486 .type
= QEMU_OPT_STRING
,
489 .type
= QEMU_OPT_STRING
,
491 { /* end of list */ }
495 static QemuOptsList qemu_fw_cfg_opts
= {
497 .implied_opt_name
= "name",
498 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
502 .type
= QEMU_OPT_STRING
,
503 .help
= "Sets the fw_cfg name of the blob to be inserted",
506 .type
= QEMU_OPT_STRING
,
507 .help
= "Sets the name of the file from which\n"
508 "the fw_cfg blob will be loaded",
511 .type
= QEMU_OPT_STRING
,
512 .help
= "Sets content of the blob to be inserted from a string",
514 { /* end of list */ }
518 #ifdef CONFIG_LIBISCSI
519 static QemuOptsList qemu_iscsi_opts
= {
521 .head
= QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts
.head
),
525 .type
= QEMU_OPT_STRING
,
526 .help
= "username for CHAP authentication to target",
529 .type
= QEMU_OPT_STRING
,
530 .help
= "password for CHAP authentication to target",
532 .name
= "password-secret",
533 .type
= QEMU_OPT_STRING
,
534 .help
= "ID of the secret providing password for CHAP "
535 "authentication to target",
537 .name
= "header-digest",
538 .type
= QEMU_OPT_STRING
,
539 .help
= "HeaderDigest setting. "
540 "{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
542 .name
= "initiator-name",
543 .type
= QEMU_OPT_STRING
,
544 .help
= "Initiator iqn name to use when connecting",
547 .type
= QEMU_OPT_NUMBER
,
548 .help
= "Request timeout in seconds (default 0 = no timeout)",
550 { /* end of list */ }
556 * Get machine options
558 * Returns: machine options (never null).
560 QemuOpts
*qemu_get_machine_opts(void)
562 return qemu_find_opts_singleton("machine");
565 const char *qemu_get_vm_name(void)
570 static void res_free(void)
572 g_free(boot_splash_filedata
);
573 boot_splash_filedata
= NULL
;
576 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
578 const char *driver
= qemu_opt_get(opts
, "driver");
583 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
584 if (strcmp(default_list
[i
].driver
, driver
) != 0)
586 *(default_list
[i
].flag
) = 0;
591 /***********************************************************/
594 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
596 /* We use RUN_STATE__MAX but any invalid value will do */
597 static RunState vmstop_requested
= RUN_STATE__MAX
;
598 static QemuMutex vmstop_lock
;
603 } RunStateTransition
;
605 static const RunStateTransition runstate_transitions_def
[] = {
607 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
608 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
609 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
611 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
612 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
613 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
614 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
615 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
616 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
617 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
618 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
619 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
620 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
621 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
622 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
624 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
625 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
626 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
628 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
629 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
630 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
632 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
633 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
634 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
635 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
637 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
638 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
639 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
641 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
642 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
643 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
645 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
646 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
647 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
648 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
650 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
651 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
653 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
655 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
656 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
657 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
658 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
659 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
660 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
661 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
662 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
663 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
664 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
665 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
667 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
669 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
670 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
671 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
673 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
674 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
675 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
676 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
677 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
678 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
680 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
681 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
682 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
683 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
685 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
686 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
687 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
689 { RUN_STATE__MAX
, RUN_STATE__MAX
},
692 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
694 bool runstate_check(RunState state
)
696 return current_run_state
== state
;
699 bool runstate_store(char *str
, size_t size
)
701 const char *state
= RunState_lookup
[current_run_state
];
702 size_t len
= strlen(state
) + 1;
707 memcpy(str
, state
, len
);
711 static void runstate_init(void)
713 const RunStateTransition
*p
;
715 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
716 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
717 runstate_valid_transitions
[p
->from
][p
->to
] = true;
720 qemu_mutex_init(&vmstop_lock
);
723 /* This function will abort() on invalid state transitions */
724 void runstate_set(RunState new_state
)
726 assert(new_state
< RUN_STATE__MAX
);
728 if (current_run_state
== new_state
) {
732 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
733 error_report("invalid runstate transition: '%s' -> '%s'",
734 RunState_lookup
[current_run_state
],
735 RunState_lookup
[new_state
]);
738 trace_runstate_set(new_state
);
739 current_run_state
= new_state
;
742 int runstate_is_running(void)
744 return runstate_check(RUN_STATE_RUNNING
);
747 bool runstate_needs_reset(void)
749 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
750 runstate_check(RUN_STATE_SHUTDOWN
);
753 StatusInfo
*qmp_query_status(Error
**errp
)
755 StatusInfo
*info
= g_malloc0(sizeof(*info
));
757 info
->running
= runstate_is_running();
758 info
->singlestep
= singlestep
;
759 info
->status
= current_run_state
;
764 static bool qemu_vmstop_requested(RunState
*r
)
766 qemu_mutex_lock(&vmstop_lock
);
767 *r
= vmstop_requested
;
768 vmstop_requested
= RUN_STATE__MAX
;
769 qemu_mutex_unlock(&vmstop_lock
);
770 return *r
< RUN_STATE__MAX
;
773 void qemu_system_vmstop_request_prepare(void)
775 qemu_mutex_lock(&vmstop_lock
);
778 void qemu_system_vmstop_request(RunState state
)
780 vmstop_requested
= state
;
781 qemu_mutex_unlock(&vmstop_lock
);
789 qemu_vmstop_requested(&requested
);
790 if (runstate_is_running() && requested
== RUN_STATE__MAX
) {
794 /* Ensure that a STOP/RESUME pair of events is emitted if a
795 * vmstop request was pending. The BLOCK_IO_ERROR event, for
796 * example, according to documentation is always followed by
799 if (runstate_is_running()) {
800 qapi_event_send_stop(&error_abort
);
802 replay_enable_events();
804 runstate_set(RUN_STATE_RUNNING
);
805 vm_state_notify(1, RUN_STATE_RUNNING
);
809 qapi_event_send_resume(&error_abort
);
813 /***********************************************************/
814 /* real time host monotonic timer */
816 static time_t qemu_time(void)
818 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
821 /***********************************************************/
822 /* host time/date access */
823 void qemu_get_timedate(struct tm
*tm
, int offset
)
825 time_t ti
= qemu_time();
828 if (rtc_date_offset
== -1) {
832 localtime_r(&ti
, tm
);
834 ti
-= rtc_date_offset
;
839 int qemu_timedate_diff(struct tm
*tm
)
843 if (rtc_date_offset
== -1)
845 seconds
= mktimegm(tm
);
848 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
849 seconds
= mktime(&tmp
);
852 seconds
= mktimegm(tm
) + rtc_date_offset
;
854 return seconds
- qemu_time();
857 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
859 time_t rtc_start_date
;
862 if (!strcmp(startdate
, "now") && legacy
) {
863 rtc_date_offset
= -1;
865 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
873 } else if (sscanf(startdate
, "%d-%d-%d",
885 rtc_start_date
= mktimegm(&tm
);
886 if (rtc_start_date
== -1) {
888 error_report("invalid date format");
889 error_printf("valid formats: "
890 "'2006-06-17T16:01:21' or '2006-06-17'\n");
893 rtc_date_offset
= qemu_time() - rtc_start_date
;
897 static void configure_rtc(QemuOpts
*opts
)
901 value
= qemu_opt_get(opts
, "base");
903 if (!strcmp(value
, "utc")) {
905 } else if (!strcmp(value
, "localtime")) {
906 Error
*blocker
= NULL
;
908 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
909 "-rtc base=localtime");
910 replay_add_blocker(blocker
);
912 configure_rtc_date_offset(value
, 0);
915 value
= qemu_opt_get(opts
, "clock");
917 if (!strcmp(value
, "host")) {
918 rtc_clock
= QEMU_CLOCK_HOST
;
919 } else if (!strcmp(value
, "rt")) {
920 rtc_clock
= QEMU_CLOCK_REALTIME
;
921 } else if (!strcmp(value
, "vm")) {
922 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
924 error_report("invalid option value '%s'", value
);
928 value
= qemu_opt_get(opts
, "driftfix");
930 if (!strcmp(value
, "slew")) {
931 static GlobalProperty slew_lost_ticks
= {
932 .driver
= "mc146818rtc",
933 .property
= "lost_tick_policy",
937 qdev_prop_register_global(&slew_lost_ticks
);
938 } else if (!strcmp(value
, "none")) {
939 /* discard is default */
941 error_report("invalid option value '%s'", value
);
947 /***********************************************************/
948 /* Bluetooth support */
951 static struct HCIInfo
*hci_table
[MAX_NICS
];
953 struct HCIInfo
*qemu_next_hci(void)
955 if (cur_hci
== nb_hcis
)
958 return hci_table
[cur_hci
++];
961 static int bt_hci_parse(const char *str
)
966 if (nb_hcis
>= MAX_NICS
) {
967 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
980 bdaddr
.b
[5] = 0x56 + nb_hcis
;
981 hci
->bdaddr_set(hci
, bdaddr
.b
);
983 hci_table
[nb_hcis
++] = hci
;
988 static void bt_vhci_add(int vlan_id
)
990 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
993 error_report("warning: adding a VHCI to an empty scatternet %i",
996 bt_vhci_init(bt_new_hci(vlan
));
999 static struct bt_device_s
*bt_device_add(const char *opt
)
1001 struct bt_scatternet_s
*vlan
;
1003 char *endp
= strstr(opt
, ",vlan=");
1004 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
1007 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
1010 vlan_id
= strtol(endp
+ 6, &endp
, 0);
1012 error_report("unrecognised bluetooth vlan Id");
1017 vlan
= qemu_find_bt_vlan(vlan_id
);
1020 error_report("warning: adding a slave device to an empty scatternet %i",
1023 if (!strcmp(devname
, "keyboard"))
1024 return bt_keyboard_init(vlan
);
1026 error_report("unsupported bluetooth device '%s'", devname
);
1030 static int bt_parse(const char *opt
)
1032 const char *endp
, *p
;
1035 if (strstart(opt
, "hci", &endp
)) {
1036 if (!*endp
|| *endp
== ',') {
1038 if (!strstart(endp
, ",vlan=", 0))
1041 return bt_hci_parse(opt
);
1043 } else if (strstart(opt
, "vhci", &endp
)) {
1044 if (!*endp
|| *endp
== ',') {
1046 if (strstart(endp
, ",vlan=", &p
)) {
1047 vlan
= strtol(p
, (char **) &endp
, 0);
1049 error_report("bad scatternet '%s'", p
);
1053 error_report("bad parameter '%s'", endp
+ 1);
1062 } else if (strstart(opt
, "device:", &endp
))
1063 return !bt_device_add(endp
);
1065 error_report("bad bluetooth parameter '%s'", opt
);
1069 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1071 /* FIXME: change this to true for 1.3 */
1072 if (qemu_opt_get_bool(opts
, "enable", false)) {
1073 #ifdef CONFIG_SECCOMP
1074 if (seccomp_start() < 0) {
1075 error_report("failed to install seccomp syscall filter "
1080 error_report("seccomp support is disabled");
1088 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1090 const char *proc_name
;
1092 if (qemu_opt_get(opts
, "debug-threads")) {
1093 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1095 qemu_name
= qemu_opt_get(opts
, "guest");
1097 proc_name
= qemu_opt_get(opts
, "process");
1099 os_set_proc_name(proc_name
);
1105 bool defaults_enabled(void)
1107 return has_defaults
;
1111 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1113 int fd
, dupfd
, flags
;
1115 const char *fd_opaque
= NULL
;
1118 fd
= qemu_opt_get_number(opts
, "fd", -1);
1119 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1120 fd_opaque
= qemu_opt_get(opts
, "opaque");
1123 error_report("fd option is required and must be non-negative");
1127 if (fd
<= STDERR_FILENO
) {
1128 error_report("fd cannot be a standard I/O stream");
1133 * All fds inherited across exec() necessarily have FD_CLOEXEC
1134 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1136 flags
= fcntl(fd
, F_GETFD
);
1137 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1138 error_report("fd is not valid or already in use");
1143 error_report("set option is required and must be non-negative");
1147 #ifdef F_DUPFD_CLOEXEC
1148 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1152 qemu_set_cloexec(dupfd
);
1156 error_report("error duplicating fd: %s", strerror(errno
));
1160 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1161 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1168 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1172 fd
= qemu_opt_get_number(opts
, "fd", -1);
1179 /***********************************************************/
1180 /* QEMU Block devices */
1182 #define HD_OPTS "media=disk"
1183 #define CDROM_OPTS "media=cdrom"
1185 #define PFLASH_OPTS ""
1189 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1191 BlockInterfaceType
*block_default_type
= opaque
;
1193 return drive_new(opts
, *block_default_type
) == NULL
;
1196 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1198 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1199 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1204 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1205 int index
, const char *optstr
)
1210 if (!enable
|| drive_get_by_index(type
, index
)) {
1214 opts
= drive_add(type
, index
, NULL
, optstr
);
1216 drive_enable_snapshot(NULL
, opts
, NULL
);
1219 dinfo
= drive_new(opts
, type
);
1223 dinfo
->is_default
= true;
1227 static QemuOptsList qemu_smp_opts
= {
1229 .implied_opt_name
= "cpus",
1230 .merge_lists
= true,
1231 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1235 .type
= QEMU_OPT_NUMBER
,
1238 .type
= QEMU_OPT_NUMBER
,
1241 .type
= QEMU_OPT_NUMBER
,
1244 .type
= QEMU_OPT_NUMBER
,
1247 .type
= QEMU_OPT_NUMBER
,
1249 { /*End of list */ }
1253 static void smp_parse(QemuOpts
*opts
)
1256 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1257 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1258 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1259 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1261 /* compute missing values, prefer sockets over cores over threads */
1262 if (cpus
== 0 || sockets
== 0) {
1263 sockets
= sockets
> 0 ? sockets
: 1;
1264 cores
= cores
> 0 ? cores
: 1;
1265 threads
= threads
> 0 ? threads
: 1;
1267 cpus
= cores
* threads
* sockets
;
1269 } else if (cores
== 0) {
1270 threads
= threads
> 0 ? threads
: 1;
1271 cores
= cpus
/ (sockets
* threads
);
1272 cores
= cores
> 0 ? cores
: 1;
1273 } else if (threads
== 0) {
1274 threads
= cpus
/ (cores
* sockets
);
1275 threads
= threads
> 0 ? threads
: 1;
1276 } else if (sockets
* cores
* threads
< cpus
) {
1277 error_report("cpu topology: "
1278 "sockets (%u) * cores (%u) * threads (%u) < "
1280 sockets
, cores
, threads
, cpus
);
1284 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1286 if (max_cpus
< cpus
) {
1287 error_report("maxcpus must be equal to or greater than smp");
1291 if (sockets
* cores
* threads
> max_cpus
) {
1292 error_report("cpu topology: "
1293 "sockets (%u) * cores (%u) * threads (%u) > "
1295 sockets
, cores
, threads
, max_cpus
);
1301 smp_threads
= threads
;
1305 Error
*blocker
= NULL
;
1306 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1307 replay_add_blocker(blocker
);
1311 static void realtime_init(void)
1314 if (os_mlock() < 0) {
1315 error_report("locking memory failed");
1322 static void configure_msg(QemuOpts
*opts
)
1324 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1327 /***********************************************************/
1330 typedef struct SemihostingConfig
{
1332 SemihostingTarget target
;
1335 const char *cmdline
; /* concatenated argv */
1336 } SemihostingConfig
;
1338 static SemihostingConfig semihosting
;
1340 bool semihosting_enabled(void)
1342 return semihosting
.enabled
;
1345 SemihostingTarget
semihosting_get_target(void)
1347 return semihosting
.target
;
1350 const char *semihosting_get_arg(int i
)
1352 if (i
>= semihosting
.argc
) {
1355 return semihosting
.argv
[i
];
1358 int semihosting_get_argc(void)
1360 return semihosting
.argc
;
1363 const char *semihosting_get_cmdline(void)
1365 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1366 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1368 return semihosting
.cmdline
;
1371 static int add_semihosting_arg(void *opaque
,
1372 const char *name
, const char *val
,
1375 SemihostingConfig
*s
= opaque
;
1376 if (strcmp(name
, "arg") == 0) {
1378 /* one extra element as g_strjoinv() expects NULL-terminated array */
1379 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1380 s
->argv
[s
->argc
- 1] = val
;
1381 s
->argv
[s
->argc
] = NULL
;
1386 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1387 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1392 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1394 /* split -append and initialize argv[1..n] */
1395 cmd_token
= strtok(g_strdup(cmd
), " ");
1397 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1398 cmd_token
= strtok(NULL
, " ");
1402 /* Now we still need this for compatibility with XEN. */
1403 bool has_igd_gfx_passthru
;
1404 static void igd_gfx_passthru(void)
1406 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1409 /***********************************************************/
1412 static int usb_device_add(const char *devname
)
1414 USBDevice
*dev
= NULL
;
1415 #ifndef CONFIG_LINUX
1419 if (!machine_usb(current_machine
)) {
1423 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1424 dev
= usbdevice_create(devname
);
1428 /* the other ones */
1429 #ifndef CONFIG_LINUX
1430 /* only the linux version is qdev-ified, usb-bsd still needs this */
1431 if (strstart(devname
, "host:", &p
)) {
1432 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1442 static int usb_device_del(const char *devname
)
1447 if (strstart(devname
, "host:", &p
)) {
1451 if (!machine_usb(current_machine
)) {
1455 p
= strchr(devname
, '.');
1458 bus_num
= strtoul(devname
, NULL
, 0);
1459 addr
= strtoul(p
+ 1, NULL
, 0);
1461 return usb_device_delete_addr(bus_num
, addr
);
1464 static int usb_parse(const char *cmdline
)
1467 r
= usb_device_add(cmdline
);
1469 error_report("could not add USB device '%s'", cmdline
);
1474 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1476 const char *devname
= qdict_get_str(qdict
, "devname");
1477 if (usb_device_add(devname
) < 0) {
1478 error_report("could not add USB device '%s'", devname
);
1482 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1484 const char *devname
= qdict_get_str(qdict
, "devname");
1485 if (usb_device_del(devname
) < 0) {
1486 error_report("could not delete USB device '%s'", devname
);
1490 /***********************************************************/
1491 /* machine registration */
1493 MachineState
*current_machine
;
1495 static MachineClass
*find_machine(const char *name
)
1497 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1498 MachineClass
*mc
= NULL
;
1500 for (el
= machines
; el
; el
= el
->next
) {
1501 MachineClass
*temp
= el
->data
;
1503 if (!strcmp(temp
->name
, name
)) {
1508 !strcmp(temp
->alias
, name
)) {
1514 g_slist_free(machines
);
1518 MachineClass
*find_default_machine(void)
1520 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1521 MachineClass
*mc
= NULL
;
1523 for (el
= machines
; el
; el
= el
->next
) {
1524 MachineClass
*temp
= el
->data
;
1526 if (temp
->is_default
) {
1532 g_slist_free(machines
);
1536 MachineInfoList
*qmp_query_machines(Error
**errp
)
1538 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1539 MachineInfoList
*mach_list
= NULL
;
1541 for (el
= machines
; el
; el
= el
->next
) {
1542 MachineClass
*mc
= el
->data
;
1543 MachineInfoList
*entry
;
1546 info
= g_malloc0(sizeof(*info
));
1547 if (mc
->is_default
) {
1548 info
->has_is_default
= true;
1549 info
->is_default
= true;
1553 info
->has_alias
= true;
1554 info
->alias
= g_strdup(mc
->alias
);
1557 info
->name
= g_strdup(mc
->name
);
1558 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1559 info
->hotpluggable_cpus
= !!mc
->query_hotpluggable_cpus
;
1561 entry
= g_malloc0(sizeof(*entry
));
1562 entry
->value
= info
;
1563 entry
->next
= mach_list
;
1567 g_slist_free(machines
);
1571 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1573 ObjectProperty
*prop
;
1574 ObjectPropertyIterator iter
;
1576 if (!qemu_opt_has_help_opt(opts
)) {
1580 object_property_iter_init(&iter
, OBJECT(machine
));
1581 while ((prop
= object_property_iter_next(&iter
))) {
1586 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1587 prop
->name
, prop
->type
);
1588 if (prop
->description
) {
1589 error_printf(" (%s)\n", prop
->description
);
1598 /***********************************************************/
1599 /* main execution loop */
1601 struct vm_change_state_entry
{
1602 VMChangeStateHandler
*cb
;
1604 QLIST_ENTRY (vm_change_state_entry
) entries
;
1607 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1609 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1612 VMChangeStateEntry
*e
;
1614 e
= g_malloc0(sizeof (*e
));
1618 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1622 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1624 QLIST_REMOVE (e
, entries
);
1628 void vm_state_notify(int running
, RunState state
)
1630 VMChangeStateEntry
*e
, *next
;
1632 trace_vm_state_notify(running
, state
);
1634 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1635 e
->cb(e
->opaque
, running
, state
);
1639 static int reset_requested
;
1640 static int shutdown_requested
, shutdown_signal
= -1;
1641 static pid_t shutdown_pid
;
1642 static int powerdown_requested
;
1643 static int debug_requested
;
1644 static int suspend_requested
;
1645 static WakeupReason wakeup_reason
;
1646 static NotifierList powerdown_notifiers
=
1647 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1648 static NotifierList suspend_notifiers
=
1649 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1650 static NotifierList wakeup_notifiers
=
1651 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1652 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1654 int qemu_shutdown_requested_get(void)
1656 return shutdown_requested
;
1659 int qemu_reset_requested_get(void)
1661 return reset_requested
;
1664 static int qemu_shutdown_requested(void)
1666 return atomic_xchg(&shutdown_requested
, 0);
1669 static void qemu_kill_report(void)
1671 if (!qtest_driver() && shutdown_signal
!= -1) {
1672 if (shutdown_pid
== 0) {
1673 /* This happens for eg ^C at the terminal, so it's worth
1674 * avoiding printing an odd message in that case.
1676 error_report("terminating on signal %d", shutdown_signal
);
1678 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1680 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1681 shutdown_signal
, shutdown_pid
,
1682 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1683 g_free(shutdown_cmd
);
1685 shutdown_signal
= -1;
1689 static int qemu_reset_requested(void)
1691 int r
= reset_requested
;
1692 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1693 reset_requested
= 0;
1699 static int qemu_suspend_requested(void)
1701 int r
= suspend_requested
;
1702 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1703 suspend_requested
= 0;
1709 static WakeupReason
qemu_wakeup_requested(void)
1711 return wakeup_reason
;
1714 static int qemu_powerdown_requested(void)
1716 int r
= powerdown_requested
;
1717 powerdown_requested
= 0;
1721 static int qemu_debug_requested(void)
1723 int r
= debug_requested
;
1724 debug_requested
= 0;
1728 void qemu_system_reset(bool report
)
1732 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1734 cpu_synchronize_all_states();
1736 if (mc
&& mc
->reset
) {
1739 qemu_devices_reset();
1742 qapi_event_send_reset(&error_abort
);
1744 cpu_synchronize_all_post_reset();
1747 void qemu_system_guest_panicked(void)
1750 current_cpu
->crash_occurred
= true;
1752 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
, &error_abort
);
1753 vm_stop(RUN_STATE_GUEST_PANICKED
);
1755 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1757 qemu_system_shutdown_request();
1761 void qemu_system_reset_request(void)
1764 shutdown_requested
= 1;
1766 reset_requested
= 1;
1769 qemu_notify_event();
1772 static void qemu_system_suspend(void)
1775 notifier_list_notify(&suspend_notifiers
, NULL
);
1776 runstate_set(RUN_STATE_SUSPENDED
);
1777 qapi_event_send_suspend(&error_abort
);
1780 void qemu_system_suspend_request(void)
1782 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1785 suspend_requested
= 1;
1787 qemu_notify_event();
1790 void qemu_register_suspend_notifier(Notifier
*notifier
)
1792 notifier_list_add(&suspend_notifiers
, notifier
);
1795 void qemu_system_wakeup_request(WakeupReason reason
)
1797 trace_system_wakeup_request(reason
);
1799 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1802 if (!(wakeup_reason_mask
& (1 << reason
))) {
1805 runstate_set(RUN_STATE_RUNNING
);
1806 wakeup_reason
= reason
;
1807 qemu_notify_event();
1810 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1813 wakeup_reason_mask
|= (1 << reason
);
1815 wakeup_reason_mask
&= ~(1 << reason
);
1819 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1821 notifier_list_add(&wakeup_notifiers
, notifier
);
1824 void qemu_system_killed(int signal
, pid_t pid
)
1826 shutdown_signal
= signal
;
1830 /* Cannot call qemu_system_shutdown_request directly because
1831 * we are in a signal handler.
1833 shutdown_requested
= 1;
1834 qemu_notify_event();
1837 void qemu_system_shutdown_request(void)
1839 trace_qemu_system_shutdown_request();
1840 replay_shutdown_request();
1841 shutdown_requested
= 1;
1842 qemu_notify_event();
1845 static void qemu_system_powerdown(void)
1847 qapi_event_send_powerdown(&error_abort
);
1848 notifier_list_notify(&powerdown_notifiers
, NULL
);
1851 void qemu_system_powerdown_request(void)
1853 trace_qemu_system_powerdown_request();
1854 powerdown_requested
= 1;
1855 qemu_notify_event();
1858 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1860 notifier_list_add(&powerdown_notifiers
, notifier
);
1863 void qemu_system_debug_request(void)
1865 debug_requested
= 1;
1866 qemu_notify_event();
1869 static bool main_loop_should_exit(void)
1872 if (qemu_debug_requested()) {
1873 vm_stop(RUN_STATE_DEBUG
);
1875 if (qemu_suspend_requested()) {
1876 qemu_system_suspend();
1878 if (qemu_shutdown_requested()) {
1880 qapi_event_send_shutdown(&error_abort
);
1882 vm_stop(RUN_STATE_SHUTDOWN
);
1887 if (qemu_reset_requested()) {
1889 qemu_system_reset(VMRESET_REPORT
);
1891 if (!runstate_check(RUN_STATE_RUNNING
) &&
1892 !runstate_check(RUN_STATE_INMIGRATE
)) {
1893 runstate_set(RUN_STATE_PRELAUNCH
);
1896 if (qemu_wakeup_requested()) {
1898 qemu_system_reset(VMRESET_SILENT
);
1899 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1900 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1902 qapi_event_send_wakeup(&error_abort
);
1904 if (qemu_powerdown_requested()) {
1905 qemu_system_powerdown();
1907 if (qemu_vmstop_requested(&r
)) {
1913 static void main_loop(void)
1917 #ifdef CONFIG_PROFILER
1921 nonblocking
= tcg_enabled() && last_io
> 0;
1922 #ifdef CONFIG_PROFILER
1923 ti
= profile_getclock();
1925 last_io
= main_loop_wait(nonblocking
);
1926 #ifdef CONFIG_PROFILER
1927 dev_time
+= profile_getclock() - ti
;
1929 } while (!main_loop_should_exit());
1932 static void version(void)
1934 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1935 QEMU_COPYRIGHT
"\n");
1938 static void help(int exitcode
)
1941 printf("usage: %s [options] [disk_image]\n\n"
1942 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1943 error_get_progname());
1945 #define QEMU_OPTIONS_GENERATE_HELP
1946 #include "qemu-options-wrapper.h"
1948 printf("\nDuring emulation, the following keys are useful:\n"
1949 "ctrl-alt-f toggle full screen\n"
1950 "ctrl-alt-n switch to virtual console 'n'\n"
1951 "ctrl-alt toggle mouse and keyboard grab\n"
1953 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1958 #define HAS_ARG 0x0001
1960 typedef struct QEMUOption
{
1967 static const QEMUOption qemu_options
[] = {
1968 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1969 #define QEMU_OPTIONS_GENERATE_OPTIONS
1970 #include "qemu-options-wrapper.h"
1974 typedef struct VGAInterfaceInfo
{
1975 const char *opt_name
; /* option name */
1976 const char *name
; /* human-readable name */
1977 /* Class names indicating that support is available.
1978 * If no class is specified, the interface is always available */
1979 const char *class_names
[2];
1982 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1988 .name
= "standard VGA",
1989 .class_names
= { "VGA", "isa-vga" },
1992 .opt_name
= "cirrus",
1993 .name
= "Cirrus VGA",
1994 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1997 .opt_name
= "vmware",
1998 .name
= "VMWare SVGA",
1999 .class_names
= { "vmware-svga" },
2002 .opt_name
= "virtio",
2003 .name
= "Virtio VGA",
2004 .class_names
= { "virtio-vga" },
2009 .class_names
= { "qxl-vga" },
2013 .name
= "TCX framebuffer",
2014 .class_names
= { "SUNW,tcx" },
2018 .name
= "CG3 framebuffer",
2019 .class_names
= { "cgthree" },
2022 .opt_name
= "xenfb",
2026 static bool vga_interface_available(VGAInterfaceType t
)
2028 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2030 assert(t
< VGA_TYPE_MAX
);
2031 return !ti
->class_names
[0] ||
2032 object_class_by_name(ti
->class_names
[0]) ||
2033 object_class_by_name(ti
->class_names
[1]);
2036 static void select_vgahw(const char *p
)
2041 assert(vga_interface_type
== VGA_NONE
);
2042 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2043 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2044 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2045 if (!vga_interface_available(t
)) {
2046 error_report("%s not available", ti
->name
);
2049 vga_interface_type
= t
;
2053 if (t
== VGA_TYPE_MAX
) {
2055 error_report("unknown vga type: %s", p
);
2059 const char *nextopt
;
2061 if (strstart(opts
, ",retrace=", &nextopt
)) {
2063 if (strstart(opts
, "dumb", &nextopt
))
2064 vga_retrace_method
= VGA_RETRACE_DUMB
;
2065 else if (strstart(opts
, "precise", &nextopt
))
2066 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2067 else goto invalid_vga
;
2068 } else goto invalid_vga
;
2073 typedef enum DisplayType
{
2082 static DisplayType
select_display(const char *p
)
2085 DisplayType display
= DT_DEFAULT
;
2087 if (strstart(p
, "sdl", &opts
)) {
2091 const char *nextopt
;
2093 if (strstart(opts
, ",frame=", &nextopt
)) {
2095 if (strstart(opts
, "on", &nextopt
)) {
2097 } else if (strstart(opts
, "off", &nextopt
)) {
2100 goto invalid_sdl_args
;
2102 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2104 if (strstart(opts
, "on", &nextopt
)) {
2106 } else if (strstart(opts
, "off", &nextopt
)) {
2109 goto invalid_sdl_args
;
2111 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2113 if (strstart(opts
, "on", &nextopt
)) {
2115 } else if (strstart(opts
, "off", &nextopt
)) {
2118 goto invalid_sdl_args
;
2120 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2122 if (strstart(opts
, "on", &nextopt
)) {
2124 } else if (strstart(opts
, "off", &nextopt
)) {
2127 goto invalid_sdl_args
;
2129 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2131 if (strstart(opts
, "on", &nextopt
)) {
2133 } else if (strstart(opts
, "off", &nextopt
)) {
2136 goto invalid_sdl_args
;
2140 error_report("invalid SDL option string");
2146 error_report("SDL support is disabled");
2149 } else if (strstart(p
, "vnc", &opts
)) {
2151 vnc_parse(opts
+ 1, &error_fatal
);
2153 error_report("VNC requires a display argument vnc=<display>");
2156 } else if (strstart(p
, "curses", &opts
)) {
2157 #ifdef CONFIG_CURSES
2158 display
= DT_CURSES
;
2160 error_report("curses support is disabled");
2163 } else if (strstart(p
, "gtk", &opts
)) {
2167 const char *nextopt
;
2169 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2171 if (strstart(opts
, "on", &nextopt
)) {
2172 grab_on_hover
= true;
2173 } else if (strstart(opts
, "off", &nextopt
)) {
2174 grab_on_hover
= false;
2176 goto invalid_gtk_args
;
2178 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2180 if (strstart(opts
, "on", &nextopt
)) {
2182 } else if (strstart(opts
, "off", &nextopt
)) {
2185 goto invalid_gtk_args
;
2189 error_report("invalid GTK option string");
2195 error_report("GTK support is disabled");
2198 } else if (strstart(p
, "none", &opts
)) {
2201 error_report("unknown display type");
2208 static int balloon_parse(const char *arg
)
2212 if (strcmp(arg
, "none") == 0) {
2216 if (!strncmp(arg
, "virtio", 6)) {
2217 if (arg
[6] == ',') {
2218 /* have params -> parse them */
2219 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2224 /* create empty opts */
2225 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2228 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2235 char *qemu_find_file(int type
, const char *name
)
2241 /* Try the name as a straight path first */
2242 if (access(name
, R_OK
) == 0) {
2243 trace_load_file(name
, name
);
2244 return g_strdup(name
);
2248 case QEMU_FILE_TYPE_BIOS
:
2251 case QEMU_FILE_TYPE_KEYMAP
:
2252 subdir
= "keymaps/";
2258 for (i
= 0; i
< data_dir_idx
; i
++) {
2259 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2260 if (access(buf
, R_OK
) == 0) {
2261 trace_load_file(name
, buf
);
2269 static inline bool nonempty_str(const char *str
)
2274 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2278 const char *name
, *file
, *str
;
2279 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2281 if (fw_cfg
== NULL
) {
2282 error_report("fw_cfg device not available");
2285 name
= qemu_opt_get(opts
, "name");
2286 file
= qemu_opt_get(opts
, "file");
2287 str
= qemu_opt_get(opts
, "string");
2289 /* we need name and either a file or the content string */
2290 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2291 error_report("invalid argument(s)");
2294 if (nonempty_str(file
) && nonempty_str(str
)) {
2295 error_report("file and string are mutually exclusive");
2298 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2299 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2302 if (strncmp(name
, "opt/", 4) != 0) {
2303 error_report("warning: externally provided fw_cfg item names "
2304 "should be prefixed with \"opt/\"");
2306 if (nonempty_str(str
)) {
2307 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2308 buf
= g_memdup(str
, size
);
2310 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2311 error_report("can't load %s", file
);
2315 /* For legacy, keep user files in a specific global order. */
2316 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2317 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2318 fw_cfg_reset_order_override(fw_cfg
);
2322 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2324 return qdev_device_help(opts
);
2327 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2332 dev
= qdev_device_add(opts
, &err
);
2334 error_report_err(err
);
2337 object_unref(OBJECT(dev
));
2341 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2343 Error
*local_err
= NULL
;
2345 qemu_chr_new_from_opts(opts
, &local_err
);
2347 error_report_err(local_err
);
2353 #ifdef CONFIG_VIRTFS
2354 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2356 return qemu_fsdev_add(opts
);
2360 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2362 CharDriverState
*chr
;
2363 const char *chardev
;
2367 mode
= qemu_opt_get(opts
, "mode");
2371 if (strcmp(mode
, "readline") == 0) {
2372 flags
= MONITOR_USE_READLINE
;
2373 } else if (strcmp(mode
, "control") == 0) {
2374 flags
= MONITOR_USE_CONTROL
;
2376 error_report("unknown monitor mode \"%s\"", mode
);
2380 if (qemu_opt_get_bool(opts
, "pretty", 0))
2381 flags
|= MONITOR_USE_PRETTY
;
2383 if (qemu_opt_get_bool(opts
, "default", 0)) {
2384 error_report("option 'default' does nothing and is deprecated");
2387 chardev
= qemu_opt_get(opts
, "chardev");
2388 chr
= qemu_chr_find(chardev
);
2390 error_report("chardev \"%s\" not found", chardev
);
2394 monitor_init(chr
, flags
);
2398 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2400 static int monitor_device_index
= 0;
2405 if (strstart(optarg
, "chardev:", &p
)) {
2406 snprintf(label
, sizeof(label
), "%s", p
);
2408 snprintf(label
, sizeof(label
), "compat_monitor%d",
2409 monitor_device_index
);
2410 opts
= qemu_chr_parse_compat(label
, optarg
);
2412 error_report("parse error: %s", optarg
);
2417 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2418 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2419 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2420 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2421 monitor_device_index
++;
2424 struct device_config
{
2426 DEV_USB
, /* -usbdevice */
2428 DEV_SERIAL
, /* -serial */
2429 DEV_PARALLEL
, /* -parallel */
2430 DEV_VIRTCON
, /* -virtioconsole */
2431 DEV_DEBUGCON
, /* -debugcon */
2432 DEV_GDB
, /* -gdb, -s */
2433 DEV_SCLP
, /* s390 sclp */
2435 const char *cmdline
;
2437 QTAILQ_ENTRY(device_config
) next
;
2440 static QTAILQ_HEAD(, device_config
) device_configs
=
2441 QTAILQ_HEAD_INITIALIZER(device_configs
);
2443 static void add_device_config(int type
, const char *cmdline
)
2445 struct device_config
*conf
;
2447 conf
= g_malloc0(sizeof(*conf
));
2449 conf
->cmdline
= cmdline
;
2450 loc_save(&conf
->loc
);
2451 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2454 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2456 struct device_config
*conf
;
2459 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2460 if (conf
->type
!= type
)
2462 loc_push_restore(&conf
->loc
);
2463 rc
= func(conf
->cmdline
);
2464 loc_pop(&conf
->loc
);
2472 static int serial_parse(const char *devname
)
2474 static int index
= 0;
2477 if (strcmp(devname
, "none") == 0)
2479 if (index
== MAX_SERIAL_PORTS
) {
2480 error_report("too many serial ports");
2483 snprintf(label
, sizeof(label
), "serial%d", index
);
2484 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2485 if (!serial_hds
[index
]) {
2486 error_report("could not connect serial device"
2487 " to character backend '%s'", devname
);
2494 static int parallel_parse(const char *devname
)
2496 static int index
= 0;
2499 if (strcmp(devname
, "none") == 0)
2501 if (index
== MAX_PARALLEL_PORTS
) {
2502 error_report("too many parallel ports");
2505 snprintf(label
, sizeof(label
), "parallel%d", index
);
2506 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2507 if (!parallel_hds
[index
]) {
2508 error_report("could not connect parallel device"
2509 " to character backend '%s'", devname
);
2516 static int virtcon_parse(const char *devname
)
2518 QemuOptsList
*device
= qemu_find_opts("device");
2519 static int index
= 0;
2521 QemuOpts
*bus_opts
, *dev_opts
;
2523 if (strcmp(devname
, "none") == 0)
2525 if (index
== MAX_VIRTIO_CONSOLES
) {
2526 error_report("too many virtio consoles");
2530 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2531 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2533 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2534 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2536 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2537 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2538 if (!virtcon_hds
[index
]) {
2539 error_report("could not connect virtio console"
2540 " to character backend '%s'", devname
);
2543 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2549 static int sclp_parse(const char *devname
)
2551 QemuOptsList
*device
= qemu_find_opts("device");
2552 static int index
= 0;
2556 if (strcmp(devname
, "none") == 0) {
2559 if (index
== MAX_SCLP_CONSOLES
) {
2560 error_report("too many sclp consoles");
2564 assert(arch_type
== QEMU_ARCH_S390X
);
2566 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2567 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2569 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2570 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2571 if (!sclp_hds
[index
]) {
2572 error_report("could not connect sclp console"
2573 " to character backend '%s'", devname
);
2576 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2582 static int debugcon_parse(const char *devname
)
2586 if (!qemu_chr_new("debugcon", devname
)) {
2589 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2591 error_report("already have a debugcon device");
2594 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2595 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2599 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2601 const MachineClass
*mc1
= a
, *mc2
= b
;
2604 if (mc1
->family
== NULL
) {
2605 if (mc2
->family
== NULL
) {
2606 /* Compare standalone machine types against each other; they sort
2607 * in increasing order.
2609 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2610 object_class_get_name(OBJECT_CLASS(mc2
)));
2613 /* Standalone machine types sort after families. */
2617 if (mc2
->family
== NULL
) {
2618 /* Families sort before standalone machine types. */
2622 /* Families sort between each other alphabetically increasingly. */
2623 res
= strcmp(mc1
->family
, mc2
->family
);
2628 /* Within the same family, machine types sort in decreasing order. */
2629 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2630 object_class_get_name(OBJECT_CLASS(mc1
)));
2633 static MachineClass
*machine_parse(const char *name
)
2635 MachineClass
*mc
= NULL
;
2636 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2639 mc
= find_machine(name
);
2642 g_slist_free(machines
);
2645 if (name
&& !is_help_option(name
)) {
2646 error_report("unsupported machine type");
2647 error_printf("Use -machine help to list supported machines\n");
2649 printf("Supported machines are:\n");
2650 machines
= g_slist_sort(machines
, machine_class_cmp
);
2651 for (el
= machines
; el
; el
= el
->next
) {
2652 MachineClass
*mc
= el
->data
;
2654 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2656 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2657 mc
->is_default
? " (default)" : "");
2661 g_slist_free(machines
);
2662 exit(!name
|| !is_help_option(name
));
2665 void qemu_add_exit_notifier(Notifier
*notify
)
2667 notifier_list_add(&exit_notifiers
, notify
);
2670 void qemu_remove_exit_notifier(Notifier
*notify
)
2672 notifier_remove(notify
);
2675 static void qemu_run_exit_notifiers(void)
2677 notifier_list_notify(&exit_notifiers
, NULL
);
2680 static bool machine_init_done
;
2682 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2684 notifier_list_add(&machine_init_done_notifiers
, notify
);
2685 if (machine_init_done
) {
2686 notify
->notify(notify
, NULL
);
2690 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2692 notifier_remove(notify
);
2695 static void qemu_run_machine_init_done_notifiers(void)
2697 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2698 machine_init_done
= true;
2701 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2702 const char **poptarg
, int *poptind
)
2704 const QEMUOption
*popt
;
2705 int optind
= *poptind
;
2706 char *r
= argv
[optind
];
2709 loc_set_cmdline(argv
, optind
, 1);
2711 /* Treat --foo the same as -foo. */
2714 popt
= qemu_options
;
2717 error_report("invalid option");
2720 if (!strcmp(popt
->name
, r
+ 1))
2724 if (popt
->flags
& HAS_ARG
) {
2725 if (optind
>= argc
) {
2726 error_report("requires an argument");
2729 optarg
= argv
[optind
++];
2730 loc_set_cmdline(argv
, optind
- 2, 2);
2741 static MachineClass
*select_machine(void)
2743 MachineClass
*machine_class
= find_default_machine();
2748 loc_push_none(&loc
);
2750 opts
= qemu_get_machine_opts();
2751 qemu_opts_loc_restore(opts
);
2753 optarg
= qemu_opt_get(opts
, "type");
2755 machine_class
= machine_parse(optarg
);
2758 if (!machine_class
) {
2759 error_report("No machine specified, and there is no default");
2760 error_printf("Use -machine help to list supported machines\n");
2765 return machine_class
;
2768 static int machine_set_property(void *opaque
,
2769 const char *name
, const char *value
,
2772 Object
*obj
= OBJECT(opaque
);
2773 Error
*local_err
= NULL
;
2776 if (strcmp(name
, "type") == 0) {
2780 qom_name
= g_strdup(name
);
2781 for (p
= qom_name
; *p
; p
++) {
2787 object_property_parse(obj
, value
, qom_name
, &local_err
);
2791 error_report_err(local_err
);
2800 * Initial object creation happens before all other
2801 * QEMU data types are created. The majority of objects
2802 * can be created at this point. The rng-egd object
2803 * cannot be created here, as it depends on the chardev
2806 static bool object_create_initial(const char *type
)
2808 if (g_str_equal(type
, "rng-egd")) {
2813 * return false for concrete netfilters since
2814 * they depend on netdevs already existing
2816 if (g_str_equal(type
, "filter-buffer") ||
2817 g_str_equal(type
, "filter-dump") ||
2818 g_str_equal(type
, "filter-mirror") ||
2819 g_str_equal(type
, "filter-redirector") ||
2820 g_str_equal(type
, "colo-compare") ||
2821 g_str_equal(type
, "filter-rewriter") ||
2822 g_str_equal(type
, "filter-replay")) {
2826 /* Memory allocation by backends needs to be done
2827 * after configure_accelerator() (due to the tcg_enabled()
2828 * checks at memory_region_init_*()).
2830 * Also, allocation of large amounts of memory may delay
2831 * chardev initialization for too long, and trigger timeouts
2832 * on software that waits for a monitor socket to be created
2835 if (g_str_has_prefix(type
, "memory-backend-")) {
2844 * The remainder of object creation happens after the
2845 * creation of chardev, fsdev, net clients and device data types.
2847 static bool object_create_delayed(const char *type
)
2849 return !object_create_initial(type
);
2853 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2857 const char *mem_str
;
2858 const char *maxmem_str
, *slots_str
;
2859 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2860 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2863 loc_push_none(&loc
);
2864 qemu_opts_loc_restore(opts
);
2867 mem_str
= qemu_opt_get(opts
, "size");
2870 error_report("missing 'size' option value");
2874 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2876 /* Fix up legacy suffix-less format */
2877 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2878 uint64_t overflow_check
= sz
;
2881 if ((sz
>> 20) != overflow_check
) {
2882 error_report("too large 'size' option value");
2888 /* backward compatibility behaviour for case "-m 0" */
2890 sz
= default_ram_size
;
2893 sz
= QEMU_ALIGN_UP(sz
, 8192);
2895 if (ram_size
!= sz
) {
2896 error_report("ram size too large");
2900 /* store value for the future use */
2901 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2902 *maxram_size
= ram_size
;
2904 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2905 slots_str
= qemu_opt_get(opts
, "slots");
2906 if (maxmem_str
&& slots_str
) {
2909 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2910 slots
= qemu_opt_get_number(opts
, "slots", 0);
2911 if (sz
< ram_size
) {
2912 error_report("invalid value of -m option maxmem: "
2913 "maximum memory size (0x%" PRIx64
") must be at least "
2914 "the initial memory size (0x" RAM_ADDR_FMT
")",
2917 } else if (sz
> ram_size
) {
2919 error_report("invalid value of -m option: maxmem was "
2920 "specified, but no hotplug slots were specified");
2924 error_report("invalid value of -m option maxmem: "
2925 "memory slots were specified but maximum memory size "
2926 "(0x%" PRIx64
") is equal to the initial memory size "
2927 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2933 } else if ((!maxmem_str
&& slots_str
) ||
2934 (maxmem_str
&& !slots_str
)) {
2935 error_report("invalid -m option value: missing "
2936 "'%s' option", slots_str
? "maxmem" : "slots");
2943 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2947 g
= g_malloc0(sizeof(*g
));
2948 g
->driver
= qemu_opt_get(opts
, "driver");
2949 g
->property
= qemu_opt_get(opts
, "property");
2950 g
->value
= qemu_opt_get(opts
, "value");
2951 g
->user_provided
= true;
2952 g
->errp
= &error_fatal
;
2953 qdev_prop_register_global(g
);
2957 static int qemu_read_default_config_file(void)
2961 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2962 if (ret
< 0 && ret
!= -ENOENT
) {
2969 int main(int argc
, char **argv
, char **envp
)
2972 int snapshot
, linux_boot
;
2973 const char *initrd_filename
;
2974 const char *kernel_filename
, *kernel_cmdline
;
2975 const char *boot_order
= NULL
;
2976 const char *boot_once
= NULL
;
2978 int cyls
, heads
, secs
, translation
;
2979 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
2980 QemuOptsList
*olist
;
2983 const char *loadvm
= NULL
;
2984 MachineClass
*machine_class
;
2985 const char *cpu_model
;
2986 const char *vga_model
= NULL
;
2987 const char *qtest_chrdev
= NULL
;
2988 const char *qtest_log
= NULL
;
2989 const char *pid_file
= NULL
;
2990 const char *incoming
= NULL
;
2991 bool defconfig
= true;
2992 bool userconfig
= true;
2993 bool nographic
= false;
2994 DisplayType display_type
= DT_DEFAULT
;
2995 int display_remote
= 0;
2996 const char *log_mask
= NULL
;
2997 const char *log_file
= NULL
;
2998 char *trace_file
= NULL
;
2999 ram_addr_t maxram_size
;
3000 uint64_t ram_slots
= 0;
3001 FILE *vmstate_dump_file
= NULL
;
3002 Error
*main_loop_err
= NULL
;
3004 bool list_data_dirs
= false;
3006 module_call_init(MODULE_INIT_TRACE
);
3008 qemu_init_cpu_list();
3009 qemu_init_cpu_loop();
3010 qemu_mutex_lock_iothread();
3012 atexit(qemu_run_exit_notifiers
);
3013 error_set_progname(argv
[0]);
3014 qemu_init_exec_dir(argv
[0]);
3016 module_call_init(MODULE_INIT_QOM
);
3017 module_call_init(MODULE_INIT_QAPI
);
3019 qemu_add_opts(&qemu_drive_opts
);
3020 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3021 qemu_add_drive_opts(&qemu_common_drive_opts
);
3022 qemu_add_drive_opts(&qemu_drive_opts
);
3023 qemu_add_drive_opts(&bdrv_runtime_opts
);
3024 qemu_add_opts(&qemu_chardev_opts
);
3025 qemu_add_opts(&qemu_device_opts
);
3026 qemu_add_opts(&qemu_netdev_opts
);
3027 qemu_add_opts(&qemu_net_opts
);
3028 qemu_add_opts(&qemu_rtc_opts
);
3029 qemu_add_opts(&qemu_global_opts
);
3030 qemu_add_opts(&qemu_mon_opts
);
3031 qemu_add_opts(&qemu_trace_opts
);
3032 qemu_add_opts(&qemu_option_rom_opts
);
3033 qemu_add_opts(&qemu_machine_opts
);
3034 qemu_add_opts(&qemu_mem_opts
);
3035 qemu_add_opts(&qemu_smp_opts
);
3036 qemu_add_opts(&qemu_boot_opts
);
3037 qemu_add_opts(&qemu_sandbox_opts
);
3038 qemu_add_opts(&qemu_add_fd_opts
);
3039 qemu_add_opts(&qemu_object_opts
);
3040 qemu_add_opts(&qemu_tpmdev_opts
);
3041 qemu_add_opts(&qemu_realtime_opts
);
3042 qemu_add_opts(&qemu_msg_opts
);
3043 qemu_add_opts(&qemu_name_opts
);
3044 qemu_add_opts(&qemu_numa_opts
);
3045 qemu_add_opts(&qemu_icount_opts
);
3046 qemu_add_opts(&qemu_semihosting_config_opts
);
3047 qemu_add_opts(&qemu_fw_cfg_opts
);
3048 #ifdef CONFIG_LIBISCSI
3049 qemu_add_opts(&qemu_iscsi_opts
);
3051 module_call_init(MODULE_INIT_OPTS
);
3055 if (qcrypto_init(&err
) < 0) {
3056 error_reportf_err(err
, "cannot initialize crypto: ");
3059 rtc_clock
= QEMU_CLOCK_HOST
;
3061 QLIST_INIT (&vm_change_state_head
);
3062 os_setup_early_signal_handling();
3066 cyls
= heads
= secs
= 0;
3067 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3071 bdrv_init_with_whitelist();
3075 /* first pass of option parsing */
3077 while (optind
< argc
) {
3078 if (argv
[optind
][0] != '-') {
3082 const QEMUOption
*popt
;
3084 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3085 switch (popt
->index
) {
3086 case QEMU_OPTION_nodefconfig
:
3089 case QEMU_OPTION_nouserconfig
:
3096 if (defconfig
&& userconfig
) {
3097 if (qemu_read_default_config_file() < 0) {
3102 /* second pass of option parsing */
3107 if (argv
[optind
][0] != '-') {
3108 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3110 const QEMUOption
*popt
;
3112 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3113 if (!(popt
->arch_mask
& arch_type
)) {
3114 error_report("Option not supported for this target");
3117 switch(popt
->index
) {
3118 case QEMU_OPTION_no_kvm_irqchip
: {
3119 olist
= qemu_find_opts("machine");
3120 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3123 case QEMU_OPTION_cpu
:
3124 /* hw initialization will check this */
3127 case QEMU_OPTION_hda
:
3131 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3133 snprintf(buf
, sizeof(buf
),
3134 "%s,cyls=%d,heads=%d,secs=%d%s",
3135 HD_OPTS
, cyls
, heads
, secs
,
3136 translation
== BIOS_ATA_TRANSLATION_LBA
?
3138 translation
== BIOS_ATA_TRANSLATION_NONE
?
3139 ",trans=none" : "");
3140 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3143 case QEMU_OPTION_hdb
:
3144 case QEMU_OPTION_hdc
:
3145 case QEMU_OPTION_hdd
:
3146 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3149 case QEMU_OPTION_drive
:
3150 if (drive_def(optarg
) == NULL
) {
3154 case QEMU_OPTION_set
:
3155 if (qemu_set_option(optarg
) != 0)
3158 case QEMU_OPTION_global
:
3159 if (qemu_global_option(optarg
) != 0)
3162 case QEMU_OPTION_mtdblock
:
3163 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3165 case QEMU_OPTION_sd
:
3166 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3168 case QEMU_OPTION_pflash
:
3169 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3171 case QEMU_OPTION_snapshot
:
3174 case QEMU_OPTION_hdachs
:
3178 cyls
= strtol(p
, (char **)&p
, 0);
3179 if (cyls
< 1 || cyls
> 16383)
3184 heads
= strtol(p
, (char **)&p
, 0);
3185 if (heads
< 1 || heads
> 16)
3190 secs
= strtol(p
, (char **)&p
, 0);
3191 if (secs
< 1 || secs
> 63)
3195 if (!strcmp(p
, "large")) {
3196 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3197 } else if (!strcmp(p
, "rechs")) {
3198 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3199 } else if (!strcmp(p
, "none")) {
3200 translation
= BIOS_ATA_TRANSLATION_NONE
;
3201 } else if (!strcmp(p
, "lba")) {
3202 translation
= BIOS_ATA_TRANSLATION_LBA
;
3203 } else if (!strcmp(p
, "auto")) {
3204 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3208 } else if (*p
!= '\0') {
3210 error_report("invalid physical CHS format");
3213 if (hda_opts
!= NULL
) {
3214 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3216 qemu_opt_set_number(hda_opts
, "heads", heads
,
3218 qemu_opt_set_number(hda_opts
, "secs", secs
,
3220 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3221 qemu_opt_set(hda_opts
, "trans", "large",
3223 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3224 qemu_opt_set(hda_opts
, "trans", "rechs",
3226 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3227 qemu_opt_set(hda_opts
, "trans", "lba",
3229 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3230 qemu_opt_set(hda_opts
, "trans", "none",
3236 case QEMU_OPTION_numa
:
3237 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3243 case QEMU_OPTION_display
:
3244 display_type
= select_display(optarg
);
3246 case QEMU_OPTION_nographic
:
3247 olist
= qemu_find_opts("machine");
3248 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3250 display_type
= DT_NONE
;
3252 case QEMU_OPTION_curses
:
3253 #ifdef CONFIG_CURSES
3254 display_type
= DT_CURSES
;
3256 error_report("curses support is disabled");
3260 case QEMU_OPTION_portrait
:
3261 graphic_rotate
= 90;
3263 case QEMU_OPTION_rotate
:
3264 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3265 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3266 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3267 error_report("only 90, 180, 270 deg rotation is available");
3271 case QEMU_OPTION_kernel
:
3272 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3275 case QEMU_OPTION_initrd
:
3276 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3279 case QEMU_OPTION_append
:
3280 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3283 case QEMU_OPTION_dtb
:
3284 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3287 case QEMU_OPTION_cdrom
:
3288 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3290 case QEMU_OPTION_boot
:
3291 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3297 case QEMU_OPTION_fda
:
3298 case QEMU_OPTION_fdb
:
3299 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3302 case QEMU_OPTION_no_fd_bootchk
:
3305 case QEMU_OPTION_netdev
:
3307 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3311 case QEMU_OPTION_net
:
3313 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3317 #ifdef CONFIG_LIBISCSI
3318 case QEMU_OPTION_iscsi
:
3319 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3327 case QEMU_OPTION_tftp
:
3328 error_report("The -tftp option is deprecated. "
3329 "Please use '-netdev user,tftp=...' instead.");
3330 legacy_tftp_prefix
= optarg
;
3332 case QEMU_OPTION_bootp
:
3333 error_report("The -bootp option is deprecated. "
3334 "Please use '-netdev user,bootfile=...' instead.");
3335 legacy_bootp_filename
= optarg
;
3337 case QEMU_OPTION_redir
:
3338 error_report("The -redir option is deprecated. "
3339 "Please use '-netdev user,hostfwd=...' instead.");
3340 if (net_slirp_redir(optarg
) < 0)
3344 case QEMU_OPTION_bt
:
3345 add_device_config(DEV_BT
, optarg
);
3347 case QEMU_OPTION_audio_help
:
3351 case QEMU_OPTION_soundhw
:
3352 select_soundhw (optarg
);
3357 case QEMU_OPTION_version
:
3362 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3369 case QEMU_OPTION_tpmdev
:
3370 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3375 case QEMU_OPTION_mempath
:
3378 case QEMU_OPTION_mem_prealloc
:
3387 case QEMU_OPTION_DFILTER
:
3388 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3391 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3393 case QEMU_OPTION_gdb
:
3394 add_device_config(DEV_GDB
, optarg
);
3397 if (is_help_option(optarg
)) {
3398 list_data_dirs
= true;
3399 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3400 data_dir
[data_dir_idx
++] = optarg
;
3403 case QEMU_OPTION_bios
:
3404 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3407 case QEMU_OPTION_singlestep
:
3414 keyboard_layout
= optarg
;
3416 case QEMU_OPTION_localtime
:
3419 case QEMU_OPTION_vga
:
3428 w
= strtol(p
, (char **)&p
, 10);
3431 error_report("invalid resolution or depth");
3437 h
= strtol(p
, (char **)&p
, 10);
3442 depth
= strtol(p
, (char **)&p
, 10);
3443 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3444 depth
!= 24 && depth
!= 32)
3446 } else if (*p
== '\0') {
3447 depth
= graphic_depth
;
3454 graphic_depth
= depth
;
3457 case QEMU_OPTION_echr
:
3460 term_escape_char
= strtol(optarg
, &r
, 0);
3462 printf("Bad argument to echr\n");
3465 case QEMU_OPTION_monitor
:
3466 default_monitor
= 0;
3467 if (strncmp(optarg
, "none", 4)) {
3468 monitor_parse(optarg
, "readline", false);
3471 case QEMU_OPTION_qmp
:
3472 monitor_parse(optarg
, "control", false);
3473 default_monitor
= 0;
3475 case QEMU_OPTION_qmp_pretty
:
3476 monitor_parse(optarg
, "control", true);
3477 default_monitor
= 0;
3479 case QEMU_OPTION_mon
:
3480 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3485 default_monitor
= 0;
3487 case QEMU_OPTION_chardev
:
3488 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3494 case QEMU_OPTION_fsdev
:
3495 olist
= qemu_find_opts("fsdev");
3497 error_report("fsdev support is disabled");
3500 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3505 case QEMU_OPTION_virtfs
: {
3508 const char *writeout
, *sock_fd
, *socket
;
3510 olist
= qemu_find_opts("virtfs");
3512 error_report("virtfs support is disabled");
3515 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3520 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3521 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3522 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3525 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3526 qemu_opt_get(opts
, "mount_tag"),
3529 error_report("duplicate fsdev id: %s",
3530 qemu_opt_get(opts
, "mount_tag"));
3534 writeout
= qemu_opt_get(opts
, "writeout");
3536 #ifdef CONFIG_SYNC_FILE_RANGE
3537 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3539 error_report("writeout=immediate not supported "
3540 "on this platform");
3544 qemu_opt_set(fsdev
, "fsdriver",
3545 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3546 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3548 qemu_opt_set(fsdev
, "security_model",
3549 qemu_opt_get(opts
, "security_model"),
3551 socket
= qemu_opt_get(opts
, "socket");
3553 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3555 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3557 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3560 qemu_opt_set_bool(fsdev
, "readonly",
3561 qemu_opt_get_bool(opts
, "readonly", 0),
3563 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3565 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3566 qemu_opt_set(device
, "fsdev",
3567 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3568 qemu_opt_set(device
, "mount_tag",
3569 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3572 case QEMU_OPTION_virtfs_synth
: {
3576 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3579 error_report("duplicate option: %s", "virtfs_synth");
3582 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3584 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3586 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3587 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3588 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3591 case QEMU_OPTION_serial
:
3592 add_device_config(DEV_SERIAL
, optarg
);
3594 if (strncmp(optarg
, "mon:", 4) == 0) {
3595 default_monitor
= 0;
3598 case QEMU_OPTION_watchdog
:
3600 error_report("only one watchdog option may be given");
3605 case QEMU_OPTION_watchdog_action
:
3606 if (select_watchdog_action(optarg
) == -1) {
3607 error_report("unknown -watchdog-action parameter");
3611 case QEMU_OPTION_virtiocon
:
3612 add_device_config(DEV_VIRTCON
, optarg
);
3613 default_virtcon
= 0;
3614 if (strncmp(optarg
, "mon:", 4) == 0) {
3615 default_monitor
= 0;
3618 case QEMU_OPTION_parallel
:
3619 add_device_config(DEV_PARALLEL
, optarg
);
3620 default_parallel
= 0;
3621 if (strncmp(optarg
, "mon:", 4) == 0) {
3622 default_monitor
= 0;
3625 case QEMU_OPTION_debugcon
:
3626 add_device_config(DEV_DEBUGCON
, optarg
);
3628 case QEMU_OPTION_loadvm
:
3631 case QEMU_OPTION_full_screen
:
3634 case QEMU_OPTION_no_frame
:
3637 case QEMU_OPTION_alt_grab
:
3640 case QEMU_OPTION_ctrl_grab
:
3643 case QEMU_OPTION_no_quit
:
3646 case QEMU_OPTION_sdl
:
3648 display_type
= DT_SDL
;
3651 error_report("SDL support is disabled");
3654 case QEMU_OPTION_pidfile
:
3657 case QEMU_OPTION_win2k_hack
:
3658 win2k_install_hack
= 1;
3660 case QEMU_OPTION_rtc_td_hack
: {
3661 static GlobalProperty slew_lost_ticks
= {
3662 .driver
= "mc146818rtc",
3663 .property
= "lost_tick_policy",
3667 qdev_prop_register_global(&slew_lost_ticks
);
3670 case QEMU_OPTION_acpitable
:
3671 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3676 acpi_table_add(opts
, &error_fatal
);
3678 case QEMU_OPTION_smbios
:
3679 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3684 smbios_entry_add(opts
, &error_fatal
);
3686 case QEMU_OPTION_fwcfg
:
3687 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3693 case QEMU_OPTION_enable_kvm
:
3694 olist
= qemu_find_opts("machine");
3695 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3697 case QEMU_OPTION_enable_hax
:
3698 olist
= qemu_find_opts("machine");
3699 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3702 case QEMU_OPTION_machine
:
3703 olist
= qemu_find_opts("machine");
3704 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3709 case QEMU_OPTION_no_kvm
:
3710 olist
= qemu_find_opts("machine");
3711 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3713 case QEMU_OPTION_no_kvm_pit
: {
3714 error_report("warning: ignoring deprecated option");
3717 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3718 static GlobalProperty kvm_pit_lost_tick_policy
= {
3719 .driver
= "kvm-pit",
3720 .property
= "lost_tick_policy",
3724 error_report("warning: deprecated, replaced by "
3725 "-global kvm-pit.lost_tick_policy=discard");
3726 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3729 case QEMU_OPTION_usb
:
3730 olist
= qemu_find_opts("machine");
3731 qemu_opts_parse_noisily(olist
, "usb=on", false);
3733 case QEMU_OPTION_usbdevice
:
3734 olist
= qemu_find_opts("machine");
3735 qemu_opts_parse_noisily(olist
, "usb=on", false);
3736 add_device_config(DEV_USB
, optarg
);
3738 case QEMU_OPTION_device
:
3739 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3744 case QEMU_OPTION_smp
:
3745 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3750 case QEMU_OPTION_vnc
:
3751 vnc_parse(optarg
, &error_fatal
);
3753 case QEMU_OPTION_no_acpi
:
3756 case QEMU_OPTION_no_hpet
:
3759 case QEMU_OPTION_balloon
:
3760 if (balloon_parse(optarg
) < 0) {
3761 error_report("unknown -balloon argument %s", optarg
);
3765 case QEMU_OPTION_no_reboot
:
3768 case QEMU_OPTION_no_shutdown
:
3771 case QEMU_OPTION_show_cursor
:
3774 case QEMU_OPTION_uuid
:
3775 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3776 error_report("failed to parse UUID string: wrong format");
3779 qemu_uuid_set
= true;
3781 case QEMU_OPTION_option_rom
:
3782 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3783 error_report("too many option ROMs");
3786 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3791 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3792 option_rom
[nb_option_roms
].bootindex
=
3793 qemu_opt_get_number(opts
, "bootindex", -1);
3794 if (!option_rom
[nb_option_roms
].name
) {
3795 error_report("Option ROM file is not specified");
3800 case QEMU_OPTION_semihosting
:
3801 semihosting
.enabled
= true;
3802 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3804 case QEMU_OPTION_semihosting_config
:
3805 semihosting
.enabled
= true;
3806 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3809 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3811 const char *target
= qemu_opt_get(opts
, "target");
3812 if (target
!= NULL
) {
3813 if (strcmp("native", target
) == 0) {
3814 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3815 } else if (strcmp("gdb", target
) == 0) {
3816 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3817 } else if (strcmp("auto", target
) == 0) {
3818 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3820 error_report("unsupported semihosting-config %s",
3825 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3827 /* Set semihosting argument count and vector */
3828 qemu_opt_foreach(opts
, add_semihosting_arg
,
3829 &semihosting
, NULL
);
3831 error_report("unsupported semihosting-config %s", optarg
);
3835 case QEMU_OPTION_tdf
:
3836 error_report("warning: ignoring deprecated option");
3838 case QEMU_OPTION_name
:
3839 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3845 case QEMU_OPTION_prom_env
:
3846 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3847 error_report("too many prom variables");
3850 prom_envs
[nb_prom_envs
] = optarg
;
3853 case QEMU_OPTION_old_param
:
3856 case QEMU_OPTION_clock
:
3857 /* Clock options no longer exist. Keep this option for
3858 * backward compatibility.
3861 case QEMU_OPTION_startdate
:
3862 configure_rtc_date_offset(optarg
, 1);
3864 case QEMU_OPTION_rtc
:
3865 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3870 configure_rtc(opts
);
3872 case QEMU_OPTION_tb_size
:
3873 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3874 if (tcg_tb_size
< 0) {
3878 case QEMU_OPTION_icount
:
3879 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3885 case QEMU_OPTION_incoming
:
3887 runstate_set(RUN_STATE_INMIGRATE
);
3891 case QEMU_OPTION_only_migratable
:
3892 only_migratable
= 1;
3894 case QEMU_OPTION_nodefaults
:
3897 case QEMU_OPTION_xen_domid
:
3898 if (!(xen_available())) {
3899 error_report("Option not supported for this target");
3902 xen_domid
= atoi(optarg
);
3904 case QEMU_OPTION_xen_create
:
3905 if (!(xen_available())) {
3906 error_report("Option not supported for this target");
3909 xen_mode
= XEN_CREATE
;
3911 case QEMU_OPTION_xen_attach
:
3912 if (!(xen_available())) {
3913 error_report("Option not supported for this target");
3916 xen_mode
= XEN_ATTACH
;
3918 case QEMU_OPTION_trace
:
3920 trace_file
= trace_opt_parse(optarg
);
3922 case QEMU_OPTION_readconfig
:
3924 int ret
= qemu_read_config_file(optarg
);
3926 error_report("read config %s: %s", optarg
,
3932 case QEMU_OPTION_spice
:
3933 olist
= qemu_find_opts("spice");
3935 error_report("spice support is disabled");
3938 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3944 case QEMU_OPTION_writeconfig
:
3947 if (strcmp(optarg
, "-") == 0) {
3950 fp
= fopen(optarg
, "w");
3952 error_report("open %s: %s", optarg
,
3957 qemu_config_write(fp
);
3963 case QEMU_OPTION_qtest
:
3964 qtest_chrdev
= optarg
;
3966 case QEMU_OPTION_qtest_log
:
3969 case QEMU_OPTION_sandbox
:
3970 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
3976 case QEMU_OPTION_add_fd
:
3978 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3984 error_report("File descriptor passing is disabled on this "
3989 case QEMU_OPTION_object
:
3990 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
3996 case QEMU_OPTION_realtime
:
3997 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4002 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4004 case QEMU_OPTION_msg
:
4005 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4010 configure_msg(opts
);
4012 case QEMU_OPTION_dump_vmstate
:
4013 if (vmstate_dump_file
) {
4014 error_report("only one '-dump-vmstate' "
4015 "option may be given");
4018 vmstate_dump_file
= fopen(optarg
, "w");
4019 if (vmstate_dump_file
== NULL
) {
4020 error_report("open %s: %s", optarg
, strerror(errno
));
4025 os_parse_cmd_args(popt
->index
, optarg
);
4030 * Clear error location left behind by the loop.
4031 * Best done right after the loop. Do not insert code here!
4035 replay_configure(icount_opts
);
4037 machine_class
= select_machine();
4039 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4043 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4044 error_report("could not acquire pid file: %s", strerror(errno
));
4048 if (qemu_init_main_loop(&main_loop_err
)) {
4049 error_report_err(main_loop_err
);
4053 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4054 parse_sandbox
, NULL
, NULL
)) {
4058 if (qemu_opts_foreach(qemu_find_opts("name"),
4059 parse_name
, NULL
, NULL
)) {
4064 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4065 parse_add_fd
, NULL
, NULL
)) {
4069 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4070 cleanup_add_fd
, NULL
, NULL
)) {
4075 current_machine
= MACHINE(object_new(object_class_get_name(
4076 OBJECT_CLASS(machine_class
))));
4077 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4080 object_property_add_child(object_get_root(), "machine",
4081 OBJECT(current_machine
), &error_abort
);
4083 if (machine_class
->minimum_page_bits
) {
4084 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4085 /* This would be a board error: specifying a minimum smaller than
4086 * a target's compile-time fixed setting.
4088 g_assert_not_reached();
4092 cpu_exec_init_all();
4094 if (machine_class
->hw_version
) {
4095 qemu_set_hw_version(machine_class
->hw_version
);
4098 if (cpu_model
&& is_help_option(cpu_model
)) {
4099 list_cpus(stdout
, &fprintf
, cpu_model
);
4103 if (!trace_init_backends()) {
4106 trace_init_file(trace_file
);
4108 /* Open the logfile at this point and set the log mask if necessary.
4111 qemu_set_log_filename(log_file
, &error_fatal
);
4116 mask
= qemu_str_to_log_mask(log_mask
);
4118 qemu_print_log_usage(stdout
);
4126 /* If no data_dir is specified then try to find it relative to the
4128 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4129 data_dir
[data_dir_idx
] = os_find_datadir();
4130 if (data_dir
[data_dir_idx
] != NULL
) {
4134 /* If all else fails use the install path specified when building. */
4135 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4136 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4139 /* -L help lists the data directories and exits. */
4140 if (list_data_dirs
) {
4141 for (i
= 0; i
< data_dir_idx
; i
++) {
4142 printf("%s\n", data_dir
[i
]);
4147 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4149 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4150 if (max_cpus
> machine_class
->max_cpus
) {
4151 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4152 "supported by machine '%s' (%d)", max_cpus
,
4153 machine_class
->name
, machine_class
->max_cpus
);
4158 * Get the default machine options from the machine if it is not already
4159 * specified either by the configuration file or by the command line.
4161 if (machine_class
->default_machine_opts
) {
4162 qemu_opts_set_defaults(qemu_find_opts("machine"),
4163 machine_class
->default_machine_opts
, 0);
4166 qemu_opts_foreach(qemu_find_opts("device"),
4167 default_driver_check
, NULL
, NULL
);
4168 qemu_opts_foreach(qemu_find_opts("global"),
4169 default_driver_check
, NULL
, NULL
);
4171 if (!vga_model
&& !default_vga
) {
4172 vga_interface_type
= VGA_DEVICE
;
4174 if (!has_defaults
|| machine_class
->no_serial
) {
4177 if (!has_defaults
|| machine_class
->no_parallel
) {
4178 default_parallel
= 0;
4180 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4181 default_virtcon
= 0;
4183 if (!has_defaults
|| !machine_class
->use_sclp
) {
4186 if (!has_defaults
|| machine_class
->no_floppy
) {
4189 if (!has_defaults
|| machine_class
->no_cdrom
) {
4192 if (!has_defaults
|| machine_class
->no_sdcard
) {
4195 if (!has_defaults
) {
4196 default_monitor
= 0;
4201 if (is_daemonized()) {
4202 /* According to documentation and historically, -nographic redirects
4203 * serial port, parallel port and monitor to stdio, which does not work
4204 * with -daemonize. We can redirect these to null instead, but since
4205 * -nographic is legacy, let's just error out.
4206 * We disallow -nographic only if all other ports are not redirected
4207 * explicitly, to not break existing legacy setups which uses
4208 * -nographic _and_ redirects all ports explicitly - this is valid
4209 * usage, -nographic is just a no-op in this case.
4212 && (default_parallel
|| default_serial
4213 || default_monitor
|| default_virtcon
)) {
4214 error_report("-nographic cannot be used with -daemonize");
4217 #ifdef CONFIG_CURSES
4218 if (display_type
== DT_CURSES
) {
4219 error_report("curses display cannot be used with -daemonize");
4226 if (default_parallel
)
4227 add_device_config(DEV_PARALLEL
, "null");
4228 if (default_serial
&& default_monitor
) {
4229 add_device_config(DEV_SERIAL
, "mon:stdio");
4230 } else if (default_virtcon
&& default_monitor
) {
4231 add_device_config(DEV_VIRTCON
, "mon:stdio");
4232 } else if (default_sclp
&& default_monitor
) {
4233 add_device_config(DEV_SCLP
, "mon:stdio");
4236 add_device_config(DEV_SERIAL
, "stdio");
4237 if (default_virtcon
)
4238 add_device_config(DEV_VIRTCON
, "stdio");
4240 add_device_config(DEV_SCLP
, "stdio");
4242 if (default_monitor
)
4243 monitor_parse("stdio", "readline", false);
4247 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4248 if (default_parallel
)
4249 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4250 if (default_monitor
)
4251 monitor_parse("vc:80Cx24C", "readline", false);
4252 if (default_virtcon
)
4253 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4255 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4259 #if defined(CONFIG_VNC)
4260 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4264 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4265 #if defined(CONFIG_GTK)
4266 display_type
= DT_GTK
;
4267 #elif defined(CONFIG_SDL)
4268 display_type
= DT_SDL
;
4269 #elif defined(CONFIG_COCOA)
4270 display_type
= DT_COCOA
;
4271 #elif defined(CONFIG_VNC)
4272 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4274 display_type
= DT_NONE
;
4278 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4279 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4280 "for SDL, ignoring option");
4282 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4283 error_report("-no-quit is only valid for GTK and SDL, "
4287 if (display_type
== DT_GTK
) {
4288 early_gtk_display_init(request_opengl
);
4291 if (display_type
== DT_SDL
) {
4292 sdl_display_early_init(request_opengl
);
4295 if (request_opengl
== 1 && display_opengl
== 0) {
4296 #if defined(CONFIG_OPENGL)
4297 error_report("OpenGL is not supported by the display");
4299 error_report("OpenGL support is disabled");
4307 if (qemu_opts_foreach(qemu_find_opts("object"),
4308 user_creatable_add_opts_foreach
,
4309 object_create_initial
, NULL
)) {
4313 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4314 chardev_init_func
, NULL
, NULL
)) {
4318 #ifdef CONFIG_VIRTFS
4319 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4320 fsdev_init_func
, NULL
, NULL
)) {
4325 if (qemu_opts_foreach(qemu_find_opts("device"),
4326 device_help_func
, NULL
, NULL
)) {
4330 machine_opts
= qemu_get_machine_opts();
4331 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4333 object_unref(OBJECT(current_machine
));
4337 configure_accelerator(current_machine
);
4340 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4343 machine_opts
= qemu_get_machine_opts();
4344 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4345 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4346 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4347 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4349 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4351 boot_order
= qemu_opt_get(opts
, "order");
4353 validate_bootdevices(boot_order
, &error_fatal
);
4356 boot_once
= qemu_opt_get(opts
, "once");
4358 validate_bootdevices(boot_once
, &error_fatal
);
4361 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4362 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4366 boot_order
= machine_class
->default_boot_order
;
4369 if (!kernel_cmdline
) {
4370 kernel_cmdline
= "";
4371 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4374 linux_boot
= (kernel_filename
!= NULL
);
4376 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4377 error_report("-append only allowed with -kernel option");
4381 if (!linux_boot
&& initrd_filename
!= NULL
) {
4382 error_report("-initrd only allowed with -kernel option");
4386 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4387 /* fall back to the -kernel/-append */
4388 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4391 os_set_line_buffering();
4393 /* spice needs the timers to be initialized by this point */
4398 if (!tcg_enabled()) {
4399 error_report("-icount is not allowed with hardware virtualization");
4402 configure_icount(icount_opts
, &error_abort
);
4403 qemu_opts_del(icount_opts
);
4407 QemuOptsList
*net
= qemu_find_opts("net");
4408 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4410 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4416 if (net_init_clients() < 0) {
4420 if (qemu_opts_foreach(qemu_find_opts("object"),
4421 user_creatable_add_opts_foreach
,
4422 object_create_delayed
, NULL
)) {
4427 if (tpm_init() < 0) {
4432 /* init the bluetooth world */
4433 if (foreach_device_config(DEV_BT
, bt_parse
))
4436 if (!xen_enabled()) {
4437 /* On 32-bit hosts, QEMU is limited by virtual address space */
4438 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4439 error_report("at most 2047 MB RAM can be simulated");
4447 /* If the currently selected machine wishes to override the units-per-bus
4448 * property of its default HBA interface type, do so now. */
4449 if (machine_class
->units_per_default_bus
) {
4450 override_max_devs(machine_class
->block_default_type
,
4451 machine_class
->units_per_default_bus
);
4454 /* open the virtual block devices */
4455 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4456 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4459 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4460 &machine_class
->block_default_type
, NULL
)) {
4464 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4466 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4467 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4469 parse_numa_opts(machine_class
);
4471 if (qemu_opts_foreach(qemu_find_opts("mon"),
4472 mon_init_func
, NULL
, NULL
)) {
4476 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4478 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4480 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4482 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4485 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4488 /* If no default VGA is requested, the default is "none". */
4490 if (machine_class
->default_display
) {
4491 vga_model
= machine_class
->default_display
;
4492 } else if (vga_interface_available(VGA_CIRRUS
)) {
4493 vga_model
= "cirrus";
4494 } else if (vga_interface_available(VGA_STD
)) {
4499 select_vgahw(vga_model
);
4503 i
= select_watchdog(watchdog
);
4505 exit (i
== 1 ? 1 : 0);
4508 machine_register_compat_props(current_machine
);
4510 qemu_opts_foreach(qemu_find_opts("global"),
4511 global_init_func
, NULL
, NULL
);
4513 /* This checkpoint is required by replay to separate prior clock
4514 reading from the other reads, because timer polling functions query
4515 clock values from the log. */
4516 replay_checkpoint(CHECKPOINT_INIT
);
4517 qdev_machine_init();
4519 current_machine
->ram_size
= ram_size
;
4520 current_machine
->maxram_size
= maxram_size
;
4521 current_machine
->ram_slots
= ram_slots
;
4522 current_machine
->boot_order
= boot_order
;
4523 current_machine
->cpu_model
= cpu_model
;
4525 machine_class
->init(current_machine
);
4531 cpu_synchronize_all_post_init();
4533 if (hax_enabled()) {
4537 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4538 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4542 /* init USB devices */
4543 if (machine_usb(current_machine
)) {
4544 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4548 /* Check if IGD GFX passthrough. */
4551 /* init generic devices */
4552 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4553 if (qemu_opts_foreach(qemu_find_opts("device"),
4554 device_init_func
, NULL
, NULL
)) {
4558 numa_post_machine_init();
4560 rom_reset_order_override();
4562 /* Did we create any drives that we failed to create a device for? */
4563 drive_check_orphaned();
4565 /* Don't warn about the default network setup that you get if
4566 * no command line -net or -netdev options are specified. There
4567 * are two cases that we would otherwise complain about:
4568 * (1) board doesn't support a NIC but the implicit "-net nic"
4570 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4571 * sets up a nic that isn't connected to anything.
4574 net_check_clients();
4579 qemu_boot_set(boot_once
, &error_fatal
);
4580 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4583 ds
= init_displaystate();
4585 /* init local displays */
4586 switch (display_type
) {
4588 curses_display_init(ds
, full_screen
);
4591 sdl_display_init(ds
, full_screen
, no_frame
);
4594 cocoa_display_init(ds
, full_screen
);
4597 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4603 /* must be after terminal init, SDL library changes signal handlers */
4604 os_setup_signal_handling();
4606 /* init remote displays */
4608 qemu_opts_foreach(qemu_find_opts("vnc"),
4609 vnc_init_func
, NULL
, NULL
);
4613 qemu_spice_display_init();
4616 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4620 qdev_machine_creation_done();
4622 /* TODO: once all bus devices are qdevified, this should be done
4623 * when bus is created by qdev.c */
4624 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4625 qemu_run_machine_init_done_notifiers();
4627 if (rom_check_and_register_reset() != 0) {
4628 error_report("rom check and register reset failed");
4634 /* This checkpoint is required by replay to separate prior clock
4635 reading from the other reads, because timer polling functions query
4636 clock values from the log. */
4637 replay_checkpoint(CHECKPOINT_RESET
);
4638 qemu_system_reset(VMRESET_SILENT
);
4639 register_global_state();
4640 if (replay_mode
!= REPLAY_MODE_NONE
) {
4641 replay_vmstate_init();
4642 } else if (loadvm
) {
4643 if (load_vmstate(loadvm
) < 0) {
4648 qdev_prop_check_globals();
4649 if (vmstate_dump_file
) {
4651 dump_vmstate_json_to_file(vmstate_dump_file
);
4656 Error
*local_err
= NULL
;
4657 qemu_start_incoming_migration(incoming
, &local_err
);
4659 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4662 } else if (autostart
) {
4669 replay_disable_events();
4670 iothread_stop_all();
4676 /* vhost-user must be cleaned up before chardevs. */