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"
32 #include "sys/prctl.h"
36 #if defined(__APPLE__) || defined(main)
38 int qemu_main(int argc
, char **argv
, char **envp
);
39 int main(int argc
, char **argv
)
41 return qemu_main(argc
, argv
, NULL
);
44 #define main qemu_main
46 #endif /* CONFIG_SDL */
50 #define main qemu_main
51 #endif /* CONFIG_COCOA */
54 #include "qemu/error-report.h"
55 #include "qemu/sockets.h"
57 #include "hw/boards.h"
58 #include "sysemu/accel.h"
60 #include "hw/isa/isa.h"
61 #include "hw/scsi/scsi.h"
62 #include "hw/display/vga.h"
64 #include "sysemu/watchdog.h"
65 #include "hw/smbios/smbios.h"
66 #include "hw/acpi/acpi.h"
67 #include "hw/xen/xen.h"
69 #include "hw/loader.h"
70 #include "monitor/qdev.h"
71 #include "sysemu/bt.h"
73 #include "net/slirp.h"
74 #include "monitor/monitor.h"
75 #include "ui/console.h"
77 #include "sysemu/sysemu.h"
78 #include "sysemu/numa.h"
79 #include "exec/gdbstub.h"
80 #include "qemu/timer.h"
81 #include "chardev/char.h"
82 #include "qemu/bitmap.h"
84 #include "sysemu/blockdev.h"
85 #include "hw/block/block.h"
86 #include "migration/misc.h"
87 #include "migration/snapshot.h"
88 #include "migration/global_state.h"
89 #include "sysemu/tpm.h"
90 #include "sysemu/dma.h"
91 #include "hw/audio/soundhw.h"
92 #include "audio/audio.h"
93 #include "sysemu/cpus.h"
94 #include "migration/colo.h"
95 #include "sysemu/kvm.h"
96 #include "sysemu/hax.h"
97 #include "qapi/qobject-input-visitor.h"
98 #include "qapi-visit.h"
99 #include "qapi/qmp/qjson.h"
100 #include "qemu/option.h"
101 #include "qemu/config-file.h"
102 #include "qemu-options.h"
103 #include "qmp-commands.h"
104 #include "qemu/main-loop.h"
106 #include "fsdev/qemu-fsdev.h"
108 #include "sysemu/qtest.h"
110 #include "disas/disas.h"
113 #include "slirp/libslirp.h"
115 #include "trace-root.h"
116 #include "trace/control.h"
117 #include "qemu/queue.h"
118 #include "sysemu/arch_init.h"
120 #include "ui/qemu-spice.h"
121 #include "qapi/string-input-visitor.h"
122 #include "qapi/opts-visitor.h"
123 #include "qom/object_interfaces.h"
124 #include "qapi-event.h"
125 #include "exec/semihost.h"
126 #include "crypto/init.h"
127 #include "sysemu/replay.h"
128 #include "qapi/qmp/qerror.h"
129 #include "sysemu/iothread.h"
131 #define MAX_VIRTIO_CONSOLES 1
132 #define MAX_SCLP_CONSOLES 1
134 static const char *data_dir
[16];
135 static int data_dir_idx
;
136 const char *bios_name
= NULL
;
137 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
138 int request_opengl
= -1;
140 const char* keyboard_layout
= NULL
;
142 const char *mem_path
= NULL
;
143 int mem_prealloc
= 0; /* force preallocation of physical target memory */
144 bool enable_mlock
= false;
146 NICInfo nd_table
[MAX_NICS
];
148 static int rtc_utc
= 1;
149 static int rtc_date_offset
= -1; /* -1 means no change */
150 QEMUClockType rtc_clock
;
151 int vga_interface_type
= VGA_NONE
;
152 static int full_screen
= 0;
155 static bool grab_on_hover
;
156 Chardev
*serial_hds
[MAX_SERIAL_PORTS
];
157 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
158 Chardev
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
159 Chardev
*sclp_hds
[MAX_SCLP_CONSOLES
];
160 int win2k_install_hack
= 0;
163 unsigned int max_cpus
;
166 int acpi_enabled
= 1;
169 static int no_reboot
;
172 int graphic_rotate
= 0;
173 const char *watchdog
;
174 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
177 const char *qemu_name
;
180 unsigned int nb_prom_envs
= 0;
181 const char *prom_envs
[MAX_PROM_ENVS
];
184 uint8_t *boot_splash_filedata
;
185 size_t boot_splash_filedata_size
;
186 uint8_t qemu_extra_params_fw
[2];
188 int icount_align_option
;
190 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
191 * little-endian "wire format" described in the SMBIOS 2.6 specification.
196 static NotifierList exit_notifiers
=
197 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
199 static NotifierList machine_init_done_notifiers
=
200 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
204 enum xen_mode xen_mode
= XEN_EMULATE
;
205 bool xen_domid_restrict
;
207 static int has_defaults
= 1;
208 static int default_serial
= 1;
209 static int default_parallel
= 1;
210 static int default_virtcon
= 1;
211 static int default_sclp
= 1;
212 static int default_monitor
= 1;
213 static int default_floppy
= 1;
214 static int default_cdrom
= 1;
215 static int default_sdcard
= 1;
216 static int default_vga
= 1;
217 static int default_net
= 1;
223 { .driver
= "isa-serial", .flag
= &default_serial
},
224 { .driver
= "isa-parallel", .flag
= &default_parallel
},
225 { .driver
= "isa-fdc", .flag
= &default_floppy
},
226 { .driver
= "floppy", .flag
= &default_floppy
},
227 { .driver
= "ide-cd", .flag
= &default_cdrom
},
228 { .driver
= "ide-hd", .flag
= &default_cdrom
},
229 { .driver
= "ide-drive", .flag
= &default_cdrom
},
230 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
231 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
232 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
233 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
234 { .driver
= "VGA", .flag
= &default_vga
},
235 { .driver
= "isa-vga", .flag
= &default_vga
},
236 { .driver
= "cirrus-vga", .flag
= &default_vga
},
237 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
238 { .driver
= "vmware-svga", .flag
= &default_vga
},
239 { .driver
= "qxl-vga", .flag
= &default_vga
},
240 { .driver
= "virtio-vga", .flag
= &default_vga
},
243 static QemuOptsList qemu_rtc_opts
= {
245 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
249 .type
= QEMU_OPT_STRING
,
252 .type
= QEMU_OPT_STRING
,
255 .type
= QEMU_OPT_STRING
,
257 { /* end of list */ }
261 static QemuOptsList qemu_sandbox_opts
= {
263 .implied_opt_name
= "enable",
264 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
268 .type
= QEMU_OPT_BOOL
,
272 .type
= QEMU_OPT_STRING
,
275 .name
= "elevateprivileges",
276 .type
= QEMU_OPT_STRING
,
280 .type
= QEMU_OPT_STRING
,
283 .name
= "resourcecontrol",
284 .type
= QEMU_OPT_STRING
,
286 { /* end of list */ }
290 static QemuOptsList qemu_option_rom_opts
= {
291 .name
= "option-rom",
292 .implied_opt_name
= "romfile",
293 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
297 .type
= QEMU_OPT_NUMBER
,
300 .type
= QEMU_OPT_STRING
,
302 { /* end of list */ }
306 static QemuOptsList qemu_machine_opts
= {
308 .implied_opt_name
= "type",
310 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
313 * no elements => accept any
314 * sanity checking will happen later
315 * when setting machine properties
321 static QemuOptsList qemu_accel_opts
= {
323 .implied_opt_name
= "accel",
324 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
329 .type
= QEMU_OPT_STRING
,
330 .help
= "Select the type of accelerator",
334 .type
= QEMU_OPT_STRING
,
335 .help
= "Enable/disable multi-threaded TCG",
337 { /* end of list */ }
341 static QemuOptsList qemu_boot_opts
= {
343 .implied_opt_name
= "order",
345 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
349 .type
= QEMU_OPT_STRING
,
352 .type
= QEMU_OPT_STRING
,
355 .type
= QEMU_OPT_BOOL
,
358 .type
= QEMU_OPT_STRING
,
360 .name
= "splash-time",
361 .type
= QEMU_OPT_STRING
,
363 .name
= "reboot-timeout",
364 .type
= QEMU_OPT_STRING
,
367 .type
= QEMU_OPT_BOOL
,
373 static QemuOptsList qemu_add_fd_opts
= {
375 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
379 .type
= QEMU_OPT_NUMBER
,
380 .help
= "file descriptor of which a duplicate is added to fd set",
383 .type
= QEMU_OPT_NUMBER
,
384 .help
= "ID of the fd set to add fd to",
387 .type
= QEMU_OPT_STRING
,
388 .help
= "free-form string used to describe fd",
390 { /* end of list */ }
394 static QemuOptsList qemu_object_opts
= {
396 .implied_opt_name
= "qom-type",
397 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
403 static QemuOptsList qemu_tpmdev_opts
= {
405 .implied_opt_name
= "type",
406 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
408 /* options are defined in the TPM backends */
409 { /* end of list */ }
413 static QemuOptsList qemu_realtime_opts
= {
415 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
419 .type
= QEMU_OPT_BOOL
,
421 { /* end of list */ }
425 static QemuOptsList qemu_msg_opts
= {
427 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
431 .type
= QEMU_OPT_BOOL
,
433 { /* end of list */ }
437 static QemuOptsList qemu_name_opts
= {
439 .implied_opt_name
= "guest",
441 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
445 .type
= QEMU_OPT_STRING
,
446 .help
= "Sets the name of the guest.\n"
447 "This name will be displayed in the SDL window caption.\n"
448 "The name will also be used for the VNC server",
451 .type
= QEMU_OPT_STRING
,
452 .help
= "Sets the name of the QEMU process, as shown in top etc",
454 .name
= "debug-threads",
455 .type
= QEMU_OPT_BOOL
,
456 .help
= "When enabled, name the individual threads; defaults off.\n"
457 "NOTE: The thread names are for debugging and not a\n"
460 { /* End of list */ }
464 static QemuOptsList qemu_mem_opts
= {
466 .implied_opt_name
= "size",
467 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
472 .type
= QEMU_OPT_SIZE
,
476 .type
= QEMU_OPT_NUMBER
,
480 .type
= QEMU_OPT_SIZE
,
482 { /* end of list */ }
486 static QemuOptsList qemu_icount_opts
= {
488 .implied_opt_name
= "shift",
490 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
494 .type
= QEMU_OPT_STRING
,
497 .type
= QEMU_OPT_BOOL
,
500 .type
= QEMU_OPT_BOOL
,
503 .type
= QEMU_OPT_STRING
,
506 .type
= QEMU_OPT_STRING
,
508 .name
= "rrsnapshot",
509 .type
= QEMU_OPT_STRING
,
511 { /* end of list */ }
515 static QemuOptsList qemu_semihosting_config_opts
= {
516 .name
= "semihosting-config",
517 .implied_opt_name
= "enable",
518 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
522 .type
= QEMU_OPT_BOOL
,
525 .type
= QEMU_OPT_STRING
,
528 .type
= QEMU_OPT_STRING
,
530 { /* end of list */ }
534 static QemuOptsList qemu_fw_cfg_opts
= {
536 .implied_opt_name
= "name",
537 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
541 .type
= QEMU_OPT_STRING
,
542 .help
= "Sets the fw_cfg name of the blob to be inserted",
545 .type
= QEMU_OPT_STRING
,
546 .help
= "Sets the name of the file from which\n"
547 "the fw_cfg blob will be loaded",
550 .type
= QEMU_OPT_STRING
,
551 .help
= "Sets content of the blob to be inserted from a string",
553 { /* end of list */ }
558 * Get machine options
560 * Returns: machine options (never null).
562 QemuOpts
*qemu_get_machine_opts(void)
564 return qemu_find_opts_singleton("machine");
567 const char *qemu_get_vm_name(void)
572 static void res_free(void)
574 g_free(boot_splash_filedata
);
575 boot_splash_filedata
= NULL
;
578 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
580 const char *driver
= qemu_opt_get(opts
, "driver");
585 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
586 if (strcmp(default_list
[i
].driver
, driver
) != 0)
588 *(default_list
[i
].flag
) = 0;
593 /***********************************************************/
596 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
598 /* We use RUN_STATE__MAX but any invalid value will do */
599 static RunState vmstop_requested
= RUN_STATE__MAX
;
600 static QemuMutex vmstop_lock
;
605 } RunStateTransition
;
607 static const RunStateTransition runstate_transitions_def
[] = {
609 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
610 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
611 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
613 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
614 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
615 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
616 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
617 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
618 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
619 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
620 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
621 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
622 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
623 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
624 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
626 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
627 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
628 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
630 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
631 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
632 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
634 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
635 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
636 { RUN_STATE_PAUSED
, RUN_STATE_POSTMIGRATE
},
637 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
638 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
640 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
641 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
642 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
644 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
645 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
646 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
648 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
649 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PAUSED
},
650 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
651 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
652 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
654 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
655 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
657 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
659 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
660 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
661 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
662 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
663 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
664 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
665 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
666 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
667 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
668 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
669 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
671 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
673 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
674 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
675 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
677 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
678 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
679 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
680 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
681 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
682 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
684 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
685 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
686 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
687 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
689 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
690 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
691 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
693 { RUN_STATE__MAX
, RUN_STATE__MAX
},
696 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
698 bool runstate_check(RunState state
)
700 return current_run_state
== state
;
703 bool runstate_store(char *str
, size_t size
)
705 const char *state
= RunState_str(current_run_state
);
706 size_t len
= strlen(state
) + 1;
711 memcpy(str
, state
, len
);
715 static void runstate_init(void)
717 const RunStateTransition
*p
;
719 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
720 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
721 runstate_valid_transitions
[p
->from
][p
->to
] = true;
724 qemu_mutex_init(&vmstop_lock
);
727 /* This function will abort() on invalid state transitions */
728 void runstate_set(RunState new_state
)
730 assert(new_state
< RUN_STATE__MAX
);
732 if (current_run_state
== new_state
) {
736 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
737 error_report("invalid runstate transition: '%s' -> '%s'",
738 RunState_str(current_run_state
),
739 RunState_str(new_state
));
742 trace_runstate_set(new_state
);
743 current_run_state
= new_state
;
746 int runstate_is_running(void)
748 return runstate_check(RUN_STATE_RUNNING
);
751 bool runstate_needs_reset(void)
753 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
754 runstate_check(RUN_STATE_SHUTDOWN
);
757 StatusInfo
*qmp_query_status(Error
**errp
)
759 StatusInfo
*info
= g_malloc0(sizeof(*info
));
761 info
->running
= runstate_is_running();
762 info
->singlestep
= singlestep
;
763 info
->status
= current_run_state
;
768 bool qemu_vmstop_requested(RunState
*r
)
770 qemu_mutex_lock(&vmstop_lock
);
771 *r
= vmstop_requested
;
772 vmstop_requested
= RUN_STATE__MAX
;
773 qemu_mutex_unlock(&vmstop_lock
);
774 return *r
< RUN_STATE__MAX
;
777 void qemu_system_vmstop_request_prepare(void)
779 qemu_mutex_lock(&vmstop_lock
);
782 void qemu_system_vmstop_request(RunState state
)
784 vmstop_requested
= state
;
785 qemu_mutex_unlock(&vmstop_lock
);
789 /***********************************************************/
790 /* real time host monotonic timer */
792 static time_t qemu_time(void)
794 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
797 /***********************************************************/
798 /* host time/date access */
799 void qemu_get_timedate(struct tm
*tm
, int offset
)
801 time_t ti
= qemu_time();
804 if (rtc_date_offset
== -1) {
808 localtime_r(&ti
, tm
);
810 ti
-= rtc_date_offset
;
815 int qemu_timedate_diff(struct tm
*tm
)
819 if (rtc_date_offset
== -1)
821 seconds
= mktimegm(tm
);
824 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
825 seconds
= mktime(&tmp
);
828 seconds
= mktimegm(tm
) + rtc_date_offset
;
830 return seconds
- qemu_time();
833 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
835 time_t rtc_start_date
;
838 if (!strcmp(startdate
, "now") && legacy
) {
839 rtc_date_offset
= -1;
841 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
849 } else if (sscanf(startdate
, "%d-%d-%d",
861 rtc_start_date
= mktimegm(&tm
);
862 if (rtc_start_date
== -1) {
864 error_report("invalid date format");
865 error_printf("valid formats: "
866 "'2006-06-17T16:01:21' or '2006-06-17'\n");
869 rtc_date_offset
= qemu_time() - rtc_start_date
;
873 static void configure_rtc(QemuOpts
*opts
)
877 value
= qemu_opt_get(opts
, "base");
879 if (!strcmp(value
, "utc")) {
881 } else if (!strcmp(value
, "localtime")) {
882 Error
*blocker
= NULL
;
884 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
885 "-rtc base=localtime");
886 replay_add_blocker(blocker
);
888 configure_rtc_date_offset(value
, 0);
891 value
= qemu_opt_get(opts
, "clock");
893 if (!strcmp(value
, "host")) {
894 rtc_clock
= QEMU_CLOCK_HOST
;
895 } else if (!strcmp(value
, "rt")) {
896 rtc_clock
= QEMU_CLOCK_REALTIME
;
897 } else if (!strcmp(value
, "vm")) {
898 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
900 error_report("invalid option value '%s'", value
);
904 value
= qemu_opt_get(opts
, "driftfix");
906 if (!strcmp(value
, "slew")) {
907 static GlobalProperty slew_lost_ticks
= {
908 .driver
= "mc146818rtc",
909 .property
= "lost_tick_policy",
913 qdev_prop_register_global(&slew_lost_ticks
);
914 } else if (!strcmp(value
, "none")) {
915 /* discard is default */
917 error_report("invalid option value '%s'", value
);
923 /***********************************************************/
924 /* Bluetooth support */
927 static struct HCIInfo
*hci_table
[MAX_NICS
];
929 struct HCIInfo
*qemu_next_hci(void)
931 if (cur_hci
== nb_hcis
)
934 return hci_table
[cur_hci
++];
937 static int bt_hci_parse(const char *str
)
942 if (nb_hcis
>= MAX_NICS
) {
943 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
956 bdaddr
.b
[5] = 0x56 + nb_hcis
;
957 hci
->bdaddr_set(hci
, bdaddr
.b
);
959 hci_table
[nb_hcis
++] = hci
;
964 static void bt_vhci_add(int vlan_id
)
966 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
969 warn_report("adding a VHCI to an empty scatternet %i",
972 bt_vhci_init(bt_new_hci(vlan
));
975 static struct bt_device_s
*bt_device_add(const char *opt
)
977 struct bt_scatternet_s
*vlan
;
979 char *endp
= strstr(opt
, ",vlan=");
980 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
983 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
986 vlan_id
= strtol(endp
+ 6, &endp
, 0);
988 error_report("unrecognised bluetooth vlan Id");
993 vlan
= qemu_find_bt_vlan(vlan_id
);
996 warn_report("adding a slave device to an empty scatternet %i",
999 if (!strcmp(devname
, "keyboard"))
1000 return bt_keyboard_init(vlan
);
1002 error_report("unsupported bluetooth device '%s'", devname
);
1006 static int bt_parse(const char *opt
)
1008 const char *endp
, *p
;
1011 if (strstart(opt
, "hci", &endp
)) {
1012 if (!*endp
|| *endp
== ',') {
1014 if (!strstart(endp
, ",vlan=", 0))
1017 return bt_hci_parse(opt
);
1019 } else if (strstart(opt
, "vhci", &endp
)) {
1020 if (!*endp
|| *endp
== ',') {
1022 if (strstart(endp
, ",vlan=", &p
)) {
1023 vlan
= strtol(p
, (char **) &endp
, 0);
1025 error_report("bad scatternet '%s'", p
);
1029 error_report("bad parameter '%s'", endp
+ 1);
1038 } else if (strstart(opt
, "device:", &endp
))
1039 return !bt_device_add(endp
);
1041 error_report("bad bluetooth parameter '%s'", opt
);
1045 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1047 if (qemu_opt_get_bool(opts
, "enable", false)) {
1048 #ifdef CONFIG_SECCOMP
1049 uint32_t seccomp_opts
= QEMU_SECCOMP_SET_DEFAULT
1050 | QEMU_SECCOMP_SET_OBSOLETE
;
1051 const char *value
= NULL
;
1053 value
= qemu_opt_get(opts
, "obsolete");
1055 if (g_str_equal(value
, "allow")) {
1056 seccomp_opts
&= ~QEMU_SECCOMP_SET_OBSOLETE
;
1057 } else if (g_str_equal(value
, "deny")) {
1058 /* this is the default option, this if is here
1059 * to provide a little bit of consistency for
1060 * the command line */
1062 error_report("invalid argument for obsolete");
1067 value
= qemu_opt_get(opts
, "elevateprivileges");
1069 if (g_str_equal(value
, "deny")) {
1070 seccomp_opts
|= QEMU_SECCOMP_SET_PRIVILEGED
;
1071 } else if (g_str_equal(value
, "children")) {
1072 seccomp_opts
|= QEMU_SECCOMP_SET_PRIVILEGED
;
1074 /* calling prctl directly because we're
1075 * not sure if host has CAP_SYS_ADMIN set*/
1076 if (prctl(PR_SET_NO_NEW_PRIVS
, 1)) {
1077 error_report("failed to set no_new_privs "
1081 } else if (g_str_equal(value
, "allow")) {
1084 error_report("invalid argument for elevateprivileges");
1089 value
= qemu_opt_get(opts
, "spawn");
1091 if (g_str_equal(value
, "deny")) {
1092 seccomp_opts
|= QEMU_SECCOMP_SET_SPAWN
;
1093 } else if (g_str_equal(value
, "allow")) {
1096 error_report("invalid argument for spawn");
1101 value
= qemu_opt_get(opts
, "resourcecontrol");
1103 if (g_str_equal(value
, "deny")) {
1104 seccomp_opts
|= QEMU_SECCOMP_SET_RESOURCECTL
;
1105 } else if (g_str_equal(value
, "allow")) {
1108 error_report("invalid argument for resourcecontrol");
1113 if (seccomp_start(seccomp_opts
) < 0) {
1114 error_report("failed to install seccomp syscall filter "
1119 error_report("seccomp support is disabled");
1127 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1129 const char *proc_name
;
1131 if (qemu_opt_get(opts
, "debug-threads")) {
1132 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1134 qemu_name
= qemu_opt_get(opts
, "guest");
1136 proc_name
= qemu_opt_get(opts
, "process");
1138 os_set_proc_name(proc_name
);
1144 bool defaults_enabled(void)
1146 return has_defaults
;
1150 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1152 int fd
, dupfd
, flags
;
1154 const char *fd_opaque
= NULL
;
1157 fd
= qemu_opt_get_number(opts
, "fd", -1);
1158 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1159 fd_opaque
= qemu_opt_get(opts
, "opaque");
1162 error_report("fd option is required and must be non-negative");
1166 if (fd
<= STDERR_FILENO
) {
1167 error_report("fd cannot be a standard I/O stream");
1172 * All fds inherited across exec() necessarily have FD_CLOEXEC
1173 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1175 flags
= fcntl(fd
, F_GETFD
);
1176 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1177 error_report("fd is not valid or already in use");
1182 error_report("set option is required and must be non-negative");
1186 #ifdef F_DUPFD_CLOEXEC
1187 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1191 qemu_set_cloexec(dupfd
);
1195 error_report("error duplicating fd: %s", strerror(errno
));
1199 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1200 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1207 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1211 fd
= qemu_opt_get_number(opts
, "fd", -1);
1218 /***********************************************************/
1219 /* QEMU Block devices */
1221 #define HD_OPTS "media=disk"
1222 #define CDROM_OPTS "media=cdrom"
1224 #define PFLASH_OPTS ""
1228 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1230 BlockInterfaceType
*block_default_type
= opaque
;
1232 return drive_new(opts
, *block_default_type
) == NULL
;
1235 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1237 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1238 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1243 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1244 int index
, const char *optstr
)
1249 if (!enable
|| drive_get_by_index(type
, index
)) {
1253 opts
= drive_add(type
, index
, NULL
, optstr
);
1255 drive_enable_snapshot(NULL
, opts
, NULL
);
1258 dinfo
= drive_new(opts
, type
);
1262 dinfo
->is_default
= true;
1266 static QemuOptsList qemu_smp_opts
= {
1268 .implied_opt_name
= "cpus",
1269 .merge_lists
= true,
1270 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1274 .type
= QEMU_OPT_NUMBER
,
1277 .type
= QEMU_OPT_NUMBER
,
1280 .type
= QEMU_OPT_NUMBER
,
1283 .type
= QEMU_OPT_NUMBER
,
1286 .type
= QEMU_OPT_NUMBER
,
1288 { /*End of list */ }
1292 static void smp_parse(QemuOpts
*opts
)
1295 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1296 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1297 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1298 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1300 /* compute missing values, prefer sockets over cores over threads */
1301 if (cpus
== 0 || sockets
== 0) {
1302 sockets
= sockets
> 0 ? sockets
: 1;
1303 cores
= cores
> 0 ? cores
: 1;
1304 threads
= threads
> 0 ? threads
: 1;
1306 cpus
= cores
* threads
* sockets
;
1308 } else if (cores
== 0) {
1309 threads
= threads
> 0 ? threads
: 1;
1310 cores
= cpus
/ (sockets
* threads
);
1311 cores
= cores
> 0 ? cores
: 1;
1312 } else if (threads
== 0) {
1313 threads
= cpus
/ (cores
* sockets
);
1314 threads
= threads
> 0 ? threads
: 1;
1315 } else if (sockets
* cores
* threads
< cpus
) {
1316 error_report("cpu topology: "
1317 "sockets (%u) * cores (%u) * threads (%u) < "
1319 sockets
, cores
, threads
, cpus
);
1323 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1325 if (max_cpus
< cpus
) {
1326 error_report("maxcpus must be equal to or greater than smp");
1330 if (sockets
* cores
* threads
> max_cpus
) {
1331 error_report("cpu topology: "
1332 "sockets (%u) * cores (%u) * threads (%u) > "
1334 sockets
, cores
, threads
, max_cpus
);
1340 smp_threads
= threads
;
1344 Error
*blocker
= NULL
;
1345 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1346 replay_add_blocker(blocker
);
1350 static void realtime_init(void)
1353 if (os_mlock() < 0) {
1354 error_report("locking memory failed");
1361 static void configure_msg(QemuOpts
*opts
)
1363 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1366 /***********************************************************/
1369 typedef struct SemihostingConfig
{
1371 SemihostingTarget target
;
1374 const char *cmdline
; /* concatenated argv */
1375 } SemihostingConfig
;
1377 static SemihostingConfig semihosting
;
1379 bool semihosting_enabled(void)
1381 return semihosting
.enabled
;
1384 SemihostingTarget
semihosting_get_target(void)
1386 return semihosting
.target
;
1389 const char *semihosting_get_arg(int i
)
1391 if (i
>= semihosting
.argc
) {
1394 return semihosting
.argv
[i
];
1397 int semihosting_get_argc(void)
1399 return semihosting
.argc
;
1402 const char *semihosting_get_cmdline(void)
1404 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1405 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1407 return semihosting
.cmdline
;
1410 static int add_semihosting_arg(void *opaque
,
1411 const char *name
, const char *val
,
1414 SemihostingConfig
*s
= opaque
;
1415 if (strcmp(name
, "arg") == 0) {
1417 /* one extra element as g_strjoinv() expects NULL-terminated array */
1418 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1419 s
->argv
[s
->argc
- 1] = val
;
1420 s
->argv
[s
->argc
] = NULL
;
1425 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1426 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1431 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1433 /* split -append and initialize argv[1..n] */
1434 cmd_token
= strtok(g_strdup(cmd
), " ");
1436 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1437 cmd_token
= strtok(NULL
, " ");
1441 /* Now we still need this for compatibility with XEN. */
1442 bool has_igd_gfx_passthru
;
1443 static void igd_gfx_passthru(void)
1445 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1448 /***********************************************************/
1451 static int usb_device_add(const char *devname
)
1453 USBDevice
*dev
= NULL
;
1455 if (!machine_usb(current_machine
)) {
1459 dev
= usbdevice_create(devname
);
1466 static int usb_parse(const char *cmdline
)
1469 r
= usb_device_add(cmdline
);
1471 error_report("could not add USB device '%s'", cmdline
);
1476 /***********************************************************/
1477 /* machine registration */
1479 MachineState
*current_machine
;
1481 static MachineClass
*find_machine(const char *name
)
1483 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1484 MachineClass
*mc
= NULL
;
1486 for (el
= machines
; el
; el
= el
->next
) {
1487 MachineClass
*temp
= el
->data
;
1489 if (!strcmp(temp
->name
, name
)) {
1494 !strcmp(temp
->alias
, name
)) {
1500 g_slist_free(machines
);
1504 MachineClass
*find_default_machine(void)
1506 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1507 MachineClass
*mc
= NULL
;
1509 for (el
= machines
; el
; el
= el
->next
) {
1510 MachineClass
*temp
= el
->data
;
1512 if (temp
->is_default
) {
1518 g_slist_free(machines
);
1522 MachineInfoList
*qmp_query_machines(Error
**errp
)
1524 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1525 MachineInfoList
*mach_list
= NULL
;
1527 for (el
= machines
; el
; el
= el
->next
) {
1528 MachineClass
*mc
= el
->data
;
1529 MachineInfoList
*entry
;
1532 info
= g_malloc0(sizeof(*info
));
1533 if (mc
->is_default
) {
1534 info
->has_is_default
= true;
1535 info
->is_default
= true;
1539 info
->has_alias
= true;
1540 info
->alias
= g_strdup(mc
->alias
);
1543 info
->name
= g_strdup(mc
->name
);
1544 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1545 info
->hotpluggable_cpus
= mc
->has_hotpluggable_cpus
;
1547 entry
= g_malloc0(sizeof(*entry
));
1548 entry
->value
= info
;
1549 entry
->next
= mach_list
;
1553 g_slist_free(machines
);
1557 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1559 ObjectProperty
*prop
;
1560 ObjectPropertyIterator iter
;
1562 if (!qemu_opt_has_help_opt(opts
)) {
1566 object_property_iter_init(&iter
, OBJECT(machine
));
1567 while ((prop
= object_property_iter_next(&iter
))) {
1572 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1573 prop
->name
, prop
->type
);
1574 if (prop
->description
) {
1575 error_printf(" (%s)\n", prop
->description
);
1584 /***********************************************************/
1585 /* main execution loop */
1587 struct vm_change_state_entry
{
1588 VMChangeStateHandler
*cb
;
1590 QLIST_ENTRY (vm_change_state_entry
) entries
;
1593 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1595 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1598 VMChangeStateEntry
*e
;
1600 e
= g_malloc0(sizeof (*e
));
1604 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1608 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1610 QLIST_REMOVE (e
, entries
);
1614 void vm_state_notify(int running
, RunState state
)
1616 VMChangeStateEntry
*e
, *next
;
1618 trace_vm_state_notify(running
, state
);
1620 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1621 e
->cb(e
->opaque
, running
, state
);
1625 static ShutdownCause reset_requested
;
1626 static ShutdownCause shutdown_requested
;
1627 static int shutdown_signal
;
1628 static pid_t shutdown_pid
;
1629 static int powerdown_requested
;
1630 static int debug_requested
;
1631 static int suspend_requested
;
1632 static WakeupReason wakeup_reason
;
1633 static NotifierList powerdown_notifiers
=
1634 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1635 static NotifierList suspend_notifiers
=
1636 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1637 static NotifierList wakeup_notifiers
=
1638 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1639 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1641 ShutdownCause
qemu_shutdown_requested_get(void)
1643 return shutdown_requested
;
1646 ShutdownCause
qemu_reset_requested_get(void)
1648 return reset_requested
;
1651 static int qemu_shutdown_requested(void)
1653 return atomic_xchg(&shutdown_requested
, SHUTDOWN_CAUSE_NONE
);
1656 static void qemu_kill_report(void)
1658 if (!qtest_driver() && shutdown_signal
) {
1659 if (shutdown_pid
== 0) {
1660 /* This happens for eg ^C at the terminal, so it's worth
1661 * avoiding printing an odd message in that case.
1663 error_report("terminating on signal %d", shutdown_signal
);
1665 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1667 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1668 shutdown_signal
, shutdown_pid
,
1669 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1670 g_free(shutdown_cmd
);
1672 shutdown_signal
= 0;
1676 static ShutdownCause
qemu_reset_requested(void)
1678 ShutdownCause r
= reset_requested
;
1680 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1681 reset_requested
= SHUTDOWN_CAUSE_NONE
;
1684 return SHUTDOWN_CAUSE_NONE
;
1687 static int qemu_suspend_requested(void)
1689 int r
= suspend_requested
;
1690 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1691 suspend_requested
= 0;
1697 static WakeupReason
qemu_wakeup_requested(void)
1699 return wakeup_reason
;
1702 static int qemu_powerdown_requested(void)
1704 int r
= powerdown_requested
;
1705 powerdown_requested
= 0;
1709 static int qemu_debug_requested(void)
1711 int r
= debug_requested
;
1712 debug_requested
= 0;
1717 * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE.
1719 void qemu_system_reset(ShutdownCause reason
)
1723 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1725 cpu_synchronize_all_states();
1727 if (mc
&& mc
->reset
) {
1730 qemu_devices_reset();
1733 qapi_event_send_reset(shutdown_caused_by_guest(reason
),
1736 cpu_synchronize_all_post_reset();
1739 void qemu_system_guest_panicked(GuestPanicInformation
*info
)
1741 qemu_log_mask(LOG_GUEST_ERROR
, "Guest crashed\n");
1744 current_cpu
->crash_occurred
= true;
1746 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
,
1747 !!info
, info
, &error_abort
);
1748 vm_stop(RUN_STATE_GUEST_PANICKED
);
1750 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1751 !!info
, info
, &error_abort
);
1752 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC
);
1756 if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_HYPER_V
) {
1757 qemu_log_mask(LOG_GUEST_ERROR
, "HV crash parameters: (%#"PRIx64
1758 " %#"PRIx64
" %#"PRIx64
" %#"PRIx64
" %#"PRIx64
")\n",
1759 info
->u
.hyper_v
.arg1
,
1760 info
->u
.hyper_v
.arg2
,
1761 info
->u
.hyper_v
.arg3
,
1762 info
->u
.hyper_v
.arg4
,
1763 info
->u
.hyper_v
.arg5
);
1765 qapi_free_GuestPanicInformation(info
);
1769 void qemu_system_reset_request(ShutdownCause reason
)
1772 shutdown_requested
= reason
;
1774 reset_requested
= reason
;
1777 qemu_notify_event();
1780 static void qemu_system_suspend(void)
1783 notifier_list_notify(&suspend_notifiers
, NULL
);
1784 runstate_set(RUN_STATE_SUSPENDED
);
1785 qapi_event_send_suspend(&error_abort
);
1788 void qemu_system_suspend_request(void)
1790 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1793 suspend_requested
= 1;
1795 qemu_notify_event();
1798 void qemu_register_suspend_notifier(Notifier
*notifier
)
1800 notifier_list_add(&suspend_notifiers
, notifier
);
1803 void qemu_system_wakeup_request(WakeupReason reason
)
1805 trace_system_wakeup_request(reason
);
1807 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1810 if (!(wakeup_reason_mask
& (1 << reason
))) {
1813 runstate_set(RUN_STATE_RUNNING
);
1814 wakeup_reason
= reason
;
1815 qemu_notify_event();
1818 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1821 wakeup_reason_mask
|= (1 << reason
);
1823 wakeup_reason_mask
&= ~(1 << reason
);
1827 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1829 notifier_list_add(&wakeup_notifiers
, notifier
);
1832 void qemu_system_killed(int signal
, pid_t pid
)
1834 shutdown_signal
= signal
;
1838 /* Cannot call qemu_system_shutdown_request directly because
1839 * we are in a signal handler.
1841 shutdown_requested
= SHUTDOWN_CAUSE_HOST_SIGNAL
;
1842 qemu_notify_event();
1845 void qemu_system_shutdown_request(ShutdownCause reason
)
1847 trace_qemu_system_shutdown_request(reason
);
1848 replay_shutdown_request(reason
);
1849 shutdown_requested
= reason
;
1850 qemu_notify_event();
1853 static void qemu_system_powerdown(void)
1855 qapi_event_send_powerdown(&error_abort
);
1856 notifier_list_notify(&powerdown_notifiers
, NULL
);
1859 void qemu_system_powerdown_request(void)
1861 trace_qemu_system_powerdown_request();
1862 powerdown_requested
= 1;
1863 qemu_notify_event();
1866 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1868 notifier_list_add(&powerdown_notifiers
, notifier
);
1871 void qemu_system_debug_request(void)
1873 debug_requested
= 1;
1874 qemu_notify_event();
1877 static bool main_loop_should_exit(void)
1880 ShutdownCause request
;
1882 if (qemu_debug_requested()) {
1883 vm_stop(RUN_STATE_DEBUG
);
1885 if (qemu_suspend_requested()) {
1886 qemu_system_suspend();
1888 request
= qemu_shutdown_requested();
1891 qapi_event_send_shutdown(shutdown_caused_by_guest(request
),
1894 vm_stop(RUN_STATE_SHUTDOWN
);
1899 request
= qemu_reset_requested();
1902 qemu_system_reset(request
);
1904 if (!runstate_check(RUN_STATE_RUNNING
) &&
1905 !runstate_check(RUN_STATE_INMIGRATE
)) {
1906 runstate_set(RUN_STATE_PRELAUNCH
);
1909 if (qemu_wakeup_requested()) {
1911 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
1912 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1913 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1915 qapi_event_send_wakeup(&error_abort
);
1917 if (qemu_powerdown_requested()) {
1918 qemu_system_powerdown();
1920 if (qemu_vmstop_requested(&r
)) {
1926 static void main_loop(void)
1928 #ifdef CONFIG_PROFILER
1932 #ifdef CONFIG_PROFILER
1933 ti
= profile_getclock();
1935 main_loop_wait(false);
1936 #ifdef CONFIG_PROFILER
1937 dev_time
+= profile_getclock() - ti
;
1939 } while (!main_loop_should_exit());
1942 static void version(void)
1944 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1945 QEMU_COPYRIGHT
"\n");
1948 static void help(int exitcode
)
1951 printf("usage: %s [options] [disk_image]\n\n"
1952 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1953 error_get_progname());
1955 #define QEMU_OPTIONS_GENERATE_HELP
1956 #include "qemu-options-wrapper.h"
1958 printf("\nDuring emulation, the following keys are useful:\n"
1959 "ctrl-alt-f toggle full screen\n"
1960 "ctrl-alt-n switch to virtual console 'n'\n"
1961 "ctrl-alt toggle mouse and keyboard grab\n"
1963 "When using -nographic, press 'ctrl-a h' to get some help.\n"
1965 QEMU_HELP_BOTTOM
"\n");
1970 #define HAS_ARG 0x0001
1972 typedef struct QEMUOption
{
1979 static const QEMUOption qemu_options
[] = {
1980 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1981 #define QEMU_OPTIONS_GENERATE_OPTIONS
1982 #include "qemu-options-wrapper.h"
1986 typedef struct VGAInterfaceInfo
{
1987 const char *opt_name
; /* option name */
1988 const char *name
; /* human-readable name */
1989 /* Class names indicating that support is available.
1990 * If no class is specified, the interface is always available */
1991 const char *class_names
[2];
1994 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
2000 .name
= "standard VGA",
2001 .class_names
= { "VGA", "isa-vga" },
2004 .opt_name
= "cirrus",
2005 .name
= "Cirrus VGA",
2006 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
2009 .opt_name
= "vmware",
2010 .name
= "VMWare SVGA",
2011 .class_names
= { "vmware-svga" },
2014 .opt_name
= "virtio",
2015 .name
= "Virtio VGA",
2016 .class_names
= { "virtio-vga" },
2021 .class_names
= { "qxl-vga" },
2025 .name
= "TCX framebuffer",
2026 .class_names
= { "SUNW,tcx" },
2030 .name
= "CG3 framebuffer",
2031 .class_names
= { "cgthree" },
2034 .opt_name
= "xenfb",
2038 static bool vga_interface_available(VGAInterfaceType t
)
2040 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2042 assert(t
< VGA_TYPE_MAX
);
2043 return !ti
->class_names
[0] ||
2044 object_class_by_name(ti
->class_names
[0]) ||
2045 object_class_by_name(ti
->class_names
[1]);
2048 static void select_vgahw(const char *p
)
2053 assert(vga_interface_type
== VGA_NONE
);
2054 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2055 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2056 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2057 if (!vga_interface_available(t
)) {
2058 error_report("%s not available", ti
->name
);
2061 vga_interface_type
= t
;
2065 if (t
== VGA_TYPE_MAX
) {
2067 error_report("unknown vga type: %s", p
);
2071 const char *nextopt
;
2073 if (strstart(opts
, ",retrace=", &nextopt
)) {
2075 if (strstart(opts
, "dumb", &nextopt
))
2076 vga_retrace_method
= VGA_RETRACE_DUMB
;
2077 else if (strstart(opts
, "precise", &nextopt
))
2078 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2079 else goto invalid_vga
;
2080 } else goto invalid_vga
;
2085 typedef enum DisplayType
{
2095 static DisplayType
select_display(const char *p
)
2098 DisplayType display
= DT_DEFAULT
;
2100 if (strstart(p
, "sdl", &opts
)) {
2104 const char *nextopt
;
2106 if (strstart(opts
, ",frame=", &nextopt
)) {
2108 if (strstart(opts
, "on", &nextopt
)) {
2110 } else if (strstart(opts
, "off", &nextopt
)) {
2113 goto invalid_sdl_args
;
2115 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2117 if (strstart(opts
, "on", &nextopt
)) {
2119 } else if (strstart(opts
, "off", &nextopt
)) {
2122 goto invalid_sdl_args
;
2124 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2126 if (strstart(opts
, "on", &nextopt
)) {
2128 } else if (strstart(opts
, "off", &nextopt
)) {
2131 goto invalid_sdl_args
;
2133 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2135 if (strstart(opts
, "on", &nextopt
)) {
2137 } else if (strstart(opts
, "off", &nextopt
)) {
2140 goto invalid_sdl_args
;
2142 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2144 if (strstart(opts
, "on", &nextopt
)) {
2146 } else if (strstart(opts
, "off", &nextopt
)) {
2149 goto invalid_sdl_args
;
2153 error_report("invalid SDL option string");
2159 error_report("SDL support is disabled");
2162 } else if (strstart(p
, "vnc", &opts
)) {
2164 vnc_parse(opts
+ 1, &error_fatal
);
2166 error_report("VNC requires a display argument vnc=<display>");
2169 } else if (strstart(p
, "egl-headless", &opts
)) {
2170 #ifdef CONFIG_OPENGL_DMABUF
2175 error_report("egl support is disabled");
2178 } else if (strstart(p
, "curses", &opts
)) {
2179 #ifdef CONFIG_CURSES
2180 display
= DT_CURSES
;
2182 error_report("curses support is disabled");
2185 } else if (strstart(p
, "gtk", &opts
)) {
2189 const char *nextopt
;
2191 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2193 if (strstart(opts
, "on", &nextopt
)) {
2194 grab_on_hover
= true;
2195 } else if (strstart(opts
, "off", &nextopt
)) {
2196 grab_on_hover
= false;
2198 goto invalid_gtk_args
;
2200 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2202 if (strstart(opts
, "on", &nextopt
)) {
2204 } else if (strstart(opts
, "off", &nextopt
)) {
2207 goto invalid_gtk_args
;
2211 error_report("invalid GTK option string");
2217 error_report("GTK support is disabled");
2220 } else if (strstart(p
, "none", &opts
)) {
2223 error_report("unknown display type");
2230 static int balloon_parse(const char *arg
)
2234 if (strcmp(arg
, "none") == 0) {
2238 if (!strncmp(arg
, "virtio", 6)) {
2239 if (arg
[6] == ',') {
2240 /* have params -> parse them */
2241 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2246 /* create empty opts */
2247 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2250 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2257 char *qemu_find_file(int type
, const char *name
)
2263 /* Try the name as a straight path first */
2264 if (access(name
, R_OK
) == 0) {
2265 trace_load_file(name
, name
);
2266 return g_strdup(name
);
2270 case QEMU_FILE_TYPE_BIOS
:
2273 case QEMU_FILE_TYPE_KEYMAP
:
2274 subdir
= "keymaps/";
2280 for (i
= 0; i
< data_dir_idx
; i
++) {
2281 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2282 if (access(buf
, R_OK
) == 0) {
2283 trace_load_file(name
, buf
);
2291 static void qemu_add_data_dir(const char *path
)
2298 if (data_dir_idx
== ARRAY_SIZE(data_dir
)) {
2301 for (i
= 0; i
< data_dir_idx
; i
++) {
2302 if (strcmp(data_dir
[i
], path
) == 0) {
2303 return; /* duplicate */
2306 data_dir
[data_dir_idx
++] = g_strdup(path
);
2309 static inline bool nonempty_str(const char *str
)
2314 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2318 const char *name
, *file
, *str
;
2319 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2321 if (fw_cfg
== NULL
) {
2322 error_report("fw_cfg device not available");
2325 name
= qemu_opt_get(opts
, "name");
2326 file
= qemu_opt_get(opts
, "file");
2327 str
= qemu_opt_get(opts
, "string");
2329 /* we need name and either a file or the content string */
2330 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2331 error_report("invalid argument(s)");
2334 if (nonempty_str(file
) && nonempty_str(str
)) {
2335 error_report("file and string are mutually exclusive");
2338 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2339 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2342 if (strncmp(name
, "opt/", 4) != 0) {
2343 warn_report("externally provided fw_cfg item names "
2344 "should be prefixed with \"opt/\"");
2346 if (nonempty_str(str
)) {
2347 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2348 buf
= g_memdup(str
, size
);
2350 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2351 error_report("can't load %s", file
);
2355 /* For legacy, keep user files in a specific global order. */
2356 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2357 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2358 fw_cfg_reset_order_override(fw_cfg
);
2362 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2364 return qdev_device_help(opts
);
2367 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2372 dev
= qdev_device_add(opts
, &err
);
2374 error_report_err(err
);
2377 object_unref(OBJECT(dev
));
2381 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2383 Error
*local_err
= NULL
;
2385 if (!qemu_chr_new_from_opts(opts
, &local_err
)) {
2387 error_report_err(local_err
);
2395 #ifdef CONFIG_VIRTFS
2396 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2398 return qemu_fsdev_add(opts
);
2402 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2405 const char *chardev
;
2409 mode
= qemu_opt_get(opts
, "mode");
2413 if (strcmp(mode
, "readline") == 0) {
2414 flags
= MONITOR_USE_READLINE
;
2415 } else if (strcmp(mode
, "control") == 0) {
2416 flags
= MONITOR_USE_CONTROL
;
2418 error_report("unknown monitor mode \"%s\"", mode
);
2422 if (qemu_opt_get_bool(opts
, "pretty", 0))
2423 flags
|= MONITOR_USE_PRETTY
;
2425 if (qemu_opt_get_bool(opts
, "default", 0)) {
2426 error_report("option 'default' does nothing and is deprecated");
2429 chardev
= qemu_opt_get(opts
, "chardev");
2430 chr
= qemu_chr_find(chardev
);
2432 error_report("chardev \"%s\" not found", chardev
);
2436 monitor_init(chr
, flags
);
2440 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2442 static int monitor_device_index
= 0;
2447 if (strstart(optarg
, "chardev:", &p
)) {
2448 snprintf(label
, sizeof(label
), "%s", p
);
2450 snprintf(label
, sizeof(label
), "compat_monitor%d",
2451 monitor_device_index
);
2452 opts
= qemu_chr_parse_compat(label
, optarg
);
2454 error_report("parse error: %s", optarg
);
2459 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2460 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2461 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2462 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2463 monitor_device_index
++;
2466 struct device_config
{
2468 DEV_USB
, /* -usbdevice */
2470 DEV_SERIAL
, /* -serial */
2471 DEV_PARALLEL
, /* -parallel */
2472 DEV_VIRTCON
, /* -virtioconsole */
2473 DEV_DEBUGCON
, /* -debugcon */
2474 DEV_GDB
, /* -gdb, -s */
2475 DEV_SCLP
, /* s390 sclp */
2477 const char *cmdline
;
2479 QTAILQ_ENTRY(device_config
) next
;
2482 static QTAILQ_HEAD(, device_config
) device_configs
=
2483 QTAILQ_HEAD_INITIALIZER(device_configs
);
2485 static void add_device_config(int type
, const char *cmdline
)
2487 struct device_config
*conf
;
2489 conf
= g_malloc0(sizeof(*conf
));
2491 conf
->cmdline
= cmdline
;
2492 loc_save(&conf
->loc
);
2493 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2496 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2498 struct device_config
*conf
;
2501 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2502 if (conf
->type
!= type
)
2504 loc_push_restore(&conf
->loc
);
2505 rc
= func(conf
->cmdline
);
2506 loc_pop(&conf
->loc
);
2514 static int serial_parse(const char *devname
)
2516 static int index
= 0;
2519 if (strcmp(devname
, "none") == 0)
2521 if (index
== MAX_SERIAL_PORTS
) {
2522 error_report("too many serial ports");
2525 snprintf(label
, sizeof(label
), "serial%d", index
);
2526 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2527 if (!serial_hds
[index
]) {
2528 error_report("could not connect serial device"
2529 " to character backend '%s'", devname
);
2536 static int parallel_parse(const char *devname
)
2538 static int index
= 0;
2541 if (strcmp(devname
, "none") == 0)
2543 if (index
== MAX_PARALLEL_PORTS
) {
2544 error_report("too many parallel ports");
2547 snprintf(label
, sizeof(label
), "parallel%d", index
);
2548 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2549 if (!parallel_hds
[index
]) {
2550 error_report("could not connect parallel device"
2551 " to character backend '%s'", devname
);
2558 static int virtcon_parse(const char *devname
)
2560 QemuOptsList
*device
= qemu_find_opts("device");
2561 static int index
= 0;
2563 QemuOpts
*bus_opts
, *dev_opts
;
2565 if (strcmp(devname
, "none") == 0)
2567 if (index
== MAX_VIRTIO_CONSOLES
) {
2568 error_report("too many virtio consoles");
2572 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2573 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2575 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2576 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2578 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2579 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2580 if (!virtcon_hds
[index
]) {
2581 error_report("could not connect virtio console"
2582 " to character backend '%s'", devname
);
2585 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2591 static int sclp_parse(const char *devname
)
2593 QemuOptsList
*device
= qemu_find_opts("device");
2594 static int index
= 0;
2598 if (strcmp(devname
, "none") == 0) {
2601 if (index
== MAX_SCLP_CONSOLES
) {
2602 error_report("too many sclp consoles");
2606 assert(arch_type
== QEMU_ARCH_S390X
);
2608 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2609 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2611 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2612 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2613 if (!sclp_hds
[index
]) {
2614 error_report("could not connect sclp console"
2615 " to character backend '%s'", devname
);
2618 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2624 static int debugcon_parse(const char *devname
)
2628 if (!qemu_chr_new("debugcon", devname
)) {
2631 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2633 error_report("already have a debugcon device");
2636 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2637 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2641 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2643 const MachineClass
*mc1
= a
, *mc2
= b
;
2646 if (mc1
->family
== NULL
) {
2647 if (mc2
->family
== NULL
) {
2648 /* Compare standalone machine types against each other; they sort
2649 * in increasing order.
2651 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2652 object_class_get_name(OBJECT_CLASS(mc2
)));
2655 /* Standalone machine types sort after families. */
2659 if (mc2
->family
== NULL
) {
2660 /* Families sort before standalone machine types. */
2664 /* Families sort between each other alphabetically increasingly. */
2665 res
= strcmp(mc1
->family
, mc2
->family
);
2670 /* Within the same family, machine types sort in decreasing order. */
2671 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2672 object_class_get_name(OBJECT_CLASS(mc1
)));
2675 static MachineClass
*machine_parse(const char *name
)
2677 MachineClass
*mc
= NULL
;
2678 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2681 mc
= find_machine(name
);
2684 g_slist_free(machines
);
2687 if (name
&& !is_help_option(name
)) {
2688 error_report("unsupported machine type");
2689 error_printf("Use -machine help to list supported machines\n");
2691 printf("Supported machines are:\n");
2692 machines
= g_slist_sort(machines
, machine_class_cmp
);
2693 for (el
= machines
; el
; el
= el
->next
) {
2694 MachineClass
*mc
= el
->data
;
2696 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2698 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2699 mc
->is_default
? " (default)" : "");
2703 g_slist_free(machines
);
2704 exit(!name
|| !is_help_option(name
));
2707 void qemu_add_exit_notifier(Notifier
*notify
)
2709 notifier_list_add(&exit_notifiers
, notify
);
2712 void qemu_remove_exit_notifier(Notifier
*notify
)
2714 notifier_remove(notify
);
2717 static void qemu_run_exit_notifiers(void)
2719 notifier_list_notify(&exit_notifiers
, NULL
);
2722 static bool machine_init_done
;
2724 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2726 notifier_list_add(&machine_init_done_notifiers
, notify
);
2727 if (machine_init_done
) {
2728 notify
->notify(notify
, NULL
);
2732 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2734 notifier_remove(notify
);
2737 static void qemu_run_machine_init_done_notifiers(void)
2739 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2740 machine_init_done
= true;
2743 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2744 const char **poptarg
, int *poptind
)
2746 const QEMUOption
*popt
;
2747 int optind
= *poptind
;
2748 char *r
= argv
[optind
];
2751 loc_set_cmdline(argv
, optind
, 1);
2753 /* Treat --foo the same as -foo. */
2756 popt
= qemu_options
;
2759 error_report("invalid option");
2762 if (!strcmp(popt
->name
, r
+ 1))
2766 if (popt
->flags
& HAS_ARG
) {
2767 if (optind
>= argc
) {
2768 error_report("requires an argument");
2771 optarg
= argv
[optind
++];
2772 loc_set_cmdline(argv
, optind
- 2, 2);
2783 static MachineClass
*select_machine(void)
2785 MachineClass
*machine_class
= find_default_machine();
2790 loc_push_none(&loc
);
2792 opts
= qemu_get_machine_opts();
2793 qemu_opts_loc_restore(opts
);
2795 optarg
= qemu_opt_get(opts
, "type");
2797 machine_class
= machine_parse(optarg
);
2800 if (!machine_class
) {
2801 error_report("No machine specified, and there is no default");
2802 error_printf("Use -machine help to list supported machines\n");
2807 return machine_class
;
2810 static int machine_set_property(void *opaque
,
2811 const char *name
, const char *value
,
2814 Object
*obj
= OBJECT(opaque
);
2815 Error
*local_err
= NULL
;
2818 if (strcmp(name
, "type") == 0) {
2822 qom_name
= g_strdup(name
);
2823 for (p
= qom_name
; *p
; p
++) {
2829 object_property_parse(obj
, value
, qom_name
, &local_err
);
2833 error_report_err(local_err
);
2842 * Initial object creation happens before all other
2843 * QEMU data types are created. The majority of objects
2844 * can be created at this point. The rng-egd object
2845 * cannot be created here, as it depends on the chardev
2848 static bool object_create_initial(const char *type
)
2850 if (g_str_equal(type
, "rng-egd") ||
2851 g_str_has_prefix(type
, "pr-manager-")) {
2856 * return false for concrete netfilters since
2857 * they depend on netdevs already existing
2859 if (g_str_equal(type
, "filter-buffer") ||
2860 g_str_equal(type
, "filter-dump") ||
2861 g_str_equal(type
, "filter-mirror") ||
2862 g_str_equal(type
, "filter-redirector") ||
2863 g_str_equal(type
, "colo-compare") ||
2864 g_str_equal(type
, "filter-rewriter") ||
2865 g_str_equal(type
, "filter-replay")) {
2869 /* Memory allocation by backends needs to be done
2870 * after configure_accelerator() (due to the tcg_enabled()
2871 * checks at memory_region_init_*()).
2873 * Also, allocation of large amounts of memory may delay
2874 * chardev initialization for too long, and trigger timeouts
2875 * on software that waits for a monitor socket to be created
2878 if (g_str_has_prefix(type
, "memory-backend-")) {
2887 * The remainder of object creation happens after the
2888 * creation of chardev, fsdev, net clients and device data types.
2890 static bool object_create_delayed(const char *type
)
2892 return !object_create_initial(type
);
2896 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2900 const char *mem_str
;
2901 const char *maxmem_str
, *slots_str
;
2902 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2903 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2906 loc_push_none(&loc
);
2907 qemu_opts_loc_restore(opts
);
2910 mem_str
= qemu_opt_get(opts
, "size");
2913 error_report("missing 'size' option value");
2917 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2919 /* Fix up legacy suffix-less format */
2920 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2921 uint64_t overflow_check
= sz
;
2924 if ((sz
>> 20) != overflow_check
) {
2925 error_report("too large 'size' option value");
2931 /* backward compatibility behaviour for case "-m 0" */
2933 sz
= default_ram_size
;
2936 sz
= QEMU_ALIGN_UP(sz
, 8192);
2938 if (ram_size
!= sz
) {
2939 error_report("ram size too large");
2943 /* store value for the future use */
2944 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2945 *maxram_size
= ram_size
;
2947 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2948 slots_str
= qemu_opt_get(opts
, "slots");
2949 if (maxmem_str
&& slots_str
) {
2952 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2953 slots
= qemu_opt_get_number(opts
, "slots", 0);
2954 if (sz
< ram_size
) {
2955 error_report("invalid value of -m option maxmem: "
2956 "maximum memory size (0x%" PRIx64
") must be at least "
2957 "the initial memory size (0x" RAM_ADDR_FMT
")",
2960 } else if (sz
> ram_size
) {
2962 error_report("invalid value of -m option: maxmem was "
2963 "specified, but no hotplug slots were specified");
2967 error_report("invalid value of -m option maxmem: "
2968 "memory slots were specified but maximum memory size "
2969 "(0x%" PRIx64
") is equal to the initial memory size "
2970 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2976 } else if ((!maxmem_str
&& slots_str
) ||
2977 (maxmem_str
&& !slots_str
)) {
2978 error_report("invalid -m option value: missing "
2979 "'%s' option", slots_str
? "maxmem" : "slots");
2986 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2990 g
= g_malloc0(sizeof(*g
));
2991 g
->driver
= qemu_opt_get(opts
, "driver");
2992 g
->property
= qemu_opt_get(opts
, "property");
2993 g
->value
= qemu_opt_get(opts
, "value");
2994 g
->user_provided
= true;
2995 g
->errp
= &error_fatal
;
2996 qdev_prop_register_global(g
);
3000 static int qemu_read_default_config_file(void)
3004 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
3005 if (ret
< 0 && ret
!= -ENOENT
) {
3012 static void user_register_global_props(void)
3014 qemu_opts_foreach(qemu_find_opts("global"),
3015 global_init_func
, NULL
, NULL
);
3019 * Note: we should see that these properties are actually having a
3020 * priority: accel < machine < user. This means e.g. when user
3021 * specifies something in "-global", it'll always be used with highest
3022 * priority than either machine/accelerator compat properties.
3024 static void register_global_properties(MachineState
*ms
)
3026 accel_register_compat_props(ms
->accelerator
);
3027 machine_register_compat_props(ms
);
3028 user_register_global_props();
3031 int main(int argc
, char **argv
, char **envp
)
3034 int snapshot
, linux_boot
;
3035 const char *initrd_filename
;
3036 const char *kernel_filename
, *kernel_cmdline
;
3037 const char *boot_order
= NULL
;
3038 const char *boot_once
= NULL
;
3040 QemuOpts
*opts
, *machine_opts
;
3041 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
3042 QemuOptsList
*olist
;
3045 const char *loadvm
= NULL
;
3046 MachineClass
*machine_class
;
3047 const char *cpu_model
;
3048 const char *vga_model
= NULL
;
3049 const char *qtest_chrdev
= NULL
;
3050 const char *qtest_log
= NULL
;
3051 const char *pid_file
= NULL
;
3052 const char *incoming
= NULL
;
3053 bool userconfig
= true;
3054 bool nographic
= false;
3055 DisplayType display_type
= DT_DEFAULT
;
3056 int display_remote
= 0;
3057 const char *log_mask
= NULL
;
3058 const char *log_file
= NULL
;
3059 char *trace_file
= NULL
;
3060 ram_addr_t maxram_size
;
3061 uint64_t ram_slots
= 0;
3062 FILE *vmstate_dump_file
= NULL
;
3063 Error
*main_loop_err
= NULL
;
3065 bool list_data_dirs
= false;
3067 typedef struct BlockdevOptions_queue
{
3068 BlockdevOptions
*bdo
;
3070 QSIMPLEQ_ENTRY(BlockdevOptions_queue
) entry
;
3071 } BlockdevOptions_queue
;
3072 QSIMPLEQ_HEAD(, BlockdevOptions_queue
) bdo_queue
3073 = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
3075 module_call_init(MODULE_INIT_TRACE
);
3077 qemu_init_cpu_list();
3078 qemu_init_cpu_loop();
3079 qemu_mutex_lock_iothread();
3081 atexit(qemu_run_exit_notifiers
);
3082 error_set_progname(argv
[0]);
3083 qemu_init_exec_dir(argv
[0]);
3085 module_call_init(MODULE_INIT_QOM
);
3086 monitor_init_qmp_commands();
3088 qemu_add_opts(&qemu_drive_opts
);
3089 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3090 qemu_add_drive_opts(&qemu_common_drive_opts
);
3091 qemu_add_drive_opts(&qemu_drive_opts
);
3092 qemu_add_drive_opts(&bdrv_runtime_opts
);
3093 qemu_add_opts(&qemu_chardev_opts
);
3094 qemu_add_opts(&qemu_device_opts
);
3095 qemu_add_opts(&qemu_netdev_opts
);
3096 qemu_add_opts(&qemu_net_opts
);
3097 qemu_add_opts(&qemu_rtc_opts
);
3098 qemu_add_opts(&qemu_global_opts
);
3099 qemu_add_opts(&qemu_mon_opts
);
3100 qemu_add_opts(&qemu_trace_opts
);
3101 qemu_add_opts(&qemu_option_rom_opts
);
3102 qemu_add_opts(&qemu_machine_opts
);
3103 qemu_add_opts(&qemu_accel_opts
);
3104 qemu_add_opts(&qemu_mem_opts
);
3105 qemu_add_opts(&qemu_smp_opts
);
3106 qemu_add_opts(&qemu_boot_opts
);
3107 qemu_add_opts(&qemu_sandbox_opts
);
3108 qemu_add_opts(&qemu_add_fd_opts
);
3109 qemu_add_opts(&qemu_object_opts
);
3110 qemu_add_opts(&qemu_tpmdev_opts
);
3111 qemu_add_opts(&qemu_realtime_opts
);
3112 qemu_add_opts(&qemu_msg_opts
);
3113 qemu_add_opts(&qemu_name_opts
);
3114 qemu_add_opts(&qemu_numa_opts
);
3115 qemu_add_opts(&qemu_icount_opts
);
3116 qemu_add_opts(&qemu_semihosting_config_opts
);
3117 qemu_add_opts(&qemu_fw_cfg_opts
);
3118 module_call_init(MODULE_INIT_OPTS
);
3122 if (qcrypto_init(&err
) < 0) {
3123 error_reportf_err(err
, "cannot initialize crypto: ");
3126 rtc_clock
= QEMU_CLOCK_HOST
;
3128 QLIST_INIT (&vm_change_state_head
);
3129 os_setup_early_signal_handling();
3136 bdrv_init_with_whitelist();
3140 /* first pass of option parsing */
3142 while (optind
< argc
) {
3143 if (argv
[optind
][0] != '-') {
3147 const QEMUOption
*popt
;
3149 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3150 switch (popt
->index
) {
3151 case QEMU_OPTION_nodefconfig
:
3152 case QEMU_OPTION_nouserconfig
:
3160 if (qemu_read_default_config_file() < 0) {
3165 /* second pass of option parsing */
3170 if (argv
[optind
][0] != '-') {
3171 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3173 const QEMUOption
*popt
;
3175 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3176 if (!(popt
->arch_mask
& arch_type
)) {
3177 error_report("Option not supported for this target");
3180 switch(popt
->index
) {
3181 case QEMU_OPTION_no_kvm_irqchip
: {
3182 olist
= qemu_find_opts("machine");
3183 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3186 case QEMU_OPTION_cpu
:
3187 /* hw initialization will check this */
3190 case QEMU_OPTION_hda
:
3191 case QEMU_OPTION_hdb
:
3192 case QEMU_OPTION_hdc
:
3193 case QEMU_OPTION_hdd
:
3194 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3197 case QEMU_OPTION_blockdev
:
3200 BlockdevOptions_queue
*bdo
;
3202 v
= qobject_input_visitor_new_str(optarg
, "driver", &err
);
3204 error_report_err(err
);
3208 bdo
= g_new(BlockdevOptions_queue
, 1);
3209 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
3212 loc_save(&bdo
->loc
);
3213 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
3216 case QEMU_OPTION_drive
:
3217 if (drive_def(optarg
) == NULL
) {
3221 case QEMU_OPTION_set
:
3222 if (qemu_set_option(optarg
) != 0)
3225 case QEMU_OPTION_global
:
3226 if (qemu_global_option(optarg
) != 0)
3229 case QEMU_OPTION_mtdblock
:
3230 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3232 case QEMU_OPTION_sd
:
3233 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3235 case QEMU_OPTION_pflash
:
3236 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3238 case QEMU_OPTION_snapshot
:
3241 case QEMU_OPTION_numa
:
3242 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3248 case QEMU_OPTION_display
:
3249 display_type
= select_display(optarg
);
3251 case QEMU_OPTION_nographic
:
3252 olist
= qemu_find_opts("machine");
3253 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3255 display_type
= DT_NONE
;
3257 case QEMU_OPTION_curses
:
3258 #ifdef CONFIG_CURSES
3259 display_type
= DT_CURSES
;
3261 error_report("curses support is disabled");
3265 case QEMU_OPTION_portrait
:
3266 graphic_rotate
= 90;
3268 case QEMU_OPTION_rotate
:
3269 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3270 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3271 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3272 error_report("only 90, 180, 270 deg rotation is available");
3276 case QEMU_OPTION_kernel
:
3277 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3280 case QEMU_OPTION_initrd
:
3281 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3284 case QEMU_OPTION_append
:
3285 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3288 case QEMU_OPTION_dtb
:
3289 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3292 case QEMU_OPTION_cdrom
:
3293 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3295 case QEMU_OPTION_boot
:
3296 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3302 case QEMU_OPTION_fda
:
3303 case QEMU_OPTION_fdb
:
3304 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3307 case QEMU_OPTION_no_fd_bootchk
:
3310 case QEMU_OPTION_netdev
:
3312 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3316 case QEMU_OPTION_net
:
3318 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3322 #ifdef CONFIG_LIBISCSI
3323 case QEMU_OPTION_iscsi
:
3324 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3332 case QEMU_OPTION_tftp
:
3333 error_report("The -tftp option is deprecated. "
3334 "Please use '-netdev user,tftp=...' instead.");
3335 legacy_tftp_prefix
= optarg
;
3337 case QEMU_OPTION_bootp
:
3338 error_report("The -bootp option is deprecated. "
3339 "Please use '-netdev user,bootfile=...' instead.");
3340 legacy_bootp_filename
= optarg
;
3342 case QEMU_OPTION_redir
:
3343 error_report("The -redir option is deprecated. "
3344 "Please use '-netdev user,hostfwd=...' instead.");
3345 if (net_slirp_redir(optarg
) < 0)
3349 case QEMU_OPTION_bt
:
3350 add_device_config(DEV_BT
, optarg
);
3352 case QEMU_OPTION_audio_help
:
3356 case QEMU_OPTION_soundhw
:
3357 select_soundhw (optarg
);
3362 case QEMU_OPTION_version
:
3367 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3374 case QEMU_OPTION_tpmdev
:
3375 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3380 case QEMU_OPTION_mempath
:
3383 case QEMU_OPTION_mem_prealloc
:
3392 case QEMU_OPTION_DFILTER
:
3393 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3396 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3398 case QEMU_OPTION_gdb
:
3399 add_device_config(DEV_GDB
, optarg
);
3402 if (is_help_option(optarg
)) {
3403 list_data_dirs
= true;
3405 qemu_add_data_dir(optarg
);
3408 case QEMU_OPTION_bios
:
3409 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3412 case QEMU_OPTION_singlestep
:
3419 keyboard_layout
= optarg
;
3421 case QEMU_OPTION_localtime
:
3424 case QEMU_OPTION_vga
:
3433 w
= strtol(p
, (char **)&p
, 10);
3436 error_report("invalid resolution or depth");
3442 h
= strtol(p
, (char **)&p
, 10);
3447 depth
= strtol(p
, (char **)&p
, 10);
3448 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3449 depth
!= 24 && depth
!= 32)
3451 } else if (*p
== '\0') {
3452 depth
= graphic_depth
;
3459 graphic_depth
= depth
;
3462 case QEMU_OPTION_echr
:
3465 term_escape_char
= strtol(optarg
, &r
, 0);
3467 printf("Bad argument to echr\n");
3470 case QEMU_OPTION_monitor
:
3471 default_monitor
= 0;
3472 if (strncmp(optarg
, "none", 4)) {
3473 monitor_parse(optarg
, "readline", false);
3476 case QEMU_OPTION_qmp
:
3477 monitor_parse(optarg
, "control", false);
3478 default_monitor
= 0;
3480 case QEMU_OPTION_qmp_pretty
:
3481 monitor_parse(optarg
, "control", true);
3482 default_monitor
= 0;
3484 case QEMU_OPTION_mon
:
3485 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3490 default_monitor
= 0;
3492 case QEMU_OPTION_chardev
:
3493 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3499 case QEMU_OPTION_fsdev
:
3500 olist
= qemu_find_opts("fsdev");
3502 error_report("fsdev support is disabled");
3505 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3510 case QEMU_OPTION_virtfs
: {
3513 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
;
3515 olist
= qemu_find_opts("virtfs");
3517 error_report("virtfs support is disabled");
3520 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3525 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3526 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3527 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3530 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3531 qemu_opts_id(opts
) ?:
3532 qemu_opt_get(opts
, "mount_tag"),
3535 error_report("duplicate or invalid fsdev id: %s",
3536 qemu_opt_get(opts
, "mount_tag"));
3540 writeout
= qemu_opt_get(opts
, "writeout");
3542 #ifdef CONFIG_SYNC_FILE_RANGE
3543 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3545 error_report("writeout=immediate not supported "
3546 "on this platform");
3550 qemu_opt_set(fsdev
, "fsdriver",
3551 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3552 path
= qemu_opt_get(opts
, "path");
3554 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3556 security_model
= qemu_opt_get(opts
, "security_model");
3557 if (security_model
) {
3558 qemu_opt_set(fsdev
, "security_model", security_model
,
3561 socket
= qemu_opt_get(opts
, "socket");
3563 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3565 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3567 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3570 qemu_opt_set_bool(fsdev
, "readonly",
3571 qemu_opt_get_bool(opts
, "readonly", 0),
3573 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3575 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3576 qemu_opt_set(device
, "fsdev",
3577 qemu_opts_id(fsdev
), &error_abort
);
3578 qemu_opt_set(device
, "mount_tag",
3579 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3582 case QEMU_OPTION_virtfs_synth
: {
3586 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3589 error_report("duplicate option: %s", "virtfs_synth");
3592 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3594 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3596 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3597 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3598 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3601 case QEMU_OPTION_serial
:
3602 add_device_config(DEV_SERIAL
, optarg
);
3604 if (strncmp(optarg
, "mon:", 4) == 0) {
3605 default_monitor
= 0;
3608 case QEMU_OPTION_watchdog
:
3610 error_report("only one watchdog option may be given");
3615 case QEMU_OPTION_watchdog_action
:
3616 if (select_watchdog_action(optarg
) == -1) {
3617 error_report("unknown -watchdog-action parameter");
3621 case QEMU_OPTION_virtiocon
:
3622 add_device_config(DEV_VIRTCON
, optarg
);
3623 default_virtcon
= 0;
3624 if (strncmp(optarg
, "mon:", 4) == 0) {
3625 default_monitor
= 0;
3628 case QEMU_OPTION_parallel
:
3629 add_device_config(DEV_PARALLEL
, optarg
);
3630 default_parallel
= 0;
3631 if (strncmp(optarg
, "mon:", 4) == 0) {
3632 default_monitor
= 0;
3635 case QEMU_OPTION_debugcon
:
3636 add_device_config(DEV_DEBUGCON
, optarg
);
3638 case QEMU_OPTION_loadvm
:
3641 case QEMU_OPTION_full_screen
:
3644 case QEMU_OPTION_no_frame
:
3647 case QEMU_OPTION_alt_grab
:
3650 case QEMU_OPTION_ctrl_grab
:
3653 case QEMU_OPTION_no_quit
:
3656 case QEMU_OPTION_sdl
:
3658 display_type
= DT_SDL
;
3661 error_report("SDL support is disabled");
3664 case QEMU_OPTION_pidfile
:
3667 case QEMU_OPTION_win2k_hack
:
3668 win2k_install_hack
= 1;
3670 case QEMU_OPTION_rtc_td_hack
: {
3671 static GlobalProperty slew_lost_ticks
= {
3672 .driver
= "mc146818rtc",
3673 .property
= "lost_tick_policy",
3677 qdev_prop_register_global(&slew_lost_ticks
);
3680 case QEMU_OPTION_acpitable
:
3681 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3686 acpi_table_add(opts
, &error_fatal
);
3688 case QEMU_OPTION_smbios
:
3689 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3694 smbios_entry_add(opts
, &error_fatal
);
3696 case QEMU_OPTION_fwcfg
:
3697 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3703 case QEMU_OPTION_enable_kvm
:
3704 olist
= qemu_find_opts("machine");
3705 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3707 case QEMU_OPTION_enable_hax
:
3708 olist
= qemu_find_opts("machine");
3709 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3712 case QEMU_OPTION_machine
:
3713 olist
= qemu_find_opts("machine");
3714 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3719 case QEMU_OPTION_no_kvm
:
3720 olist
= qemu_find_opts("machine");
3721 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3723 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3724 static GlobalProperty kvm_pit_lost_tick_policy
= {
3725 .driver
= "kvm-pit",
3726 .property
= "lost_tick_policy",
3730 warn_report("deprecated, replaced by "
3731 "-global kvm-pit.lost_tick_policy=discard");
3732 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3735 case QEMU_OPTION_accel
:
3736 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3738 optarg
= qemu_opt_get(accel_opts
, "accel");
3739 if (!optarg
|| is_help_option(optarg
)) {
3740 error_printf("Possible accelerators: kvm, xen, hax, tcg\n");
3743 opts
= qemu_opts_create(qemu_find_opts("machine"), NULL
,
3744 false, &error_abort
);
3745 qemu_opt_set(opts
, "accel", optarg
, &error_abort
);
3747 case QEMU_OPTION_usb
:
3748 olist
= qemu_find_opts("machine");
3749 qemu_opts_parse_noisily(olist
, "usb=on", false);
3751 case QEMU_OPTION_usbdevice
:
3752 error_report("'-usbdevice' is deprecated, please use "
3753 "'-device usb-...' instead");
3754 olist
= qemu_find_opts("machine");
3755 qemu_opts_parse_noisily(olist
, "usb=on", false);
3756 add_device_config(DEV_USB
, optarg
);
3758 case QEMU_OPTION_device
:
3759 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3764 case QEMU_OPTION_smp
:
3765 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3770 case QEMU_OPTION_vnc
:
3771 vnc_parse(optarg
, &error_fatal
);
3773 case QEMU_OPTION_no_acpi
:
3776 case QEMU_OPTION_no_hpet
:
3779 case QEMU_OPTION_balloon
:
3780 if (balloon_parse(optarg
) < 0) {
3781 error_report("unknown -balloon argument %s", optarg
);
3785 case QEMU_OPTION_no_reboot
:
3788 case QEMU_OPTION_no_shutdown
:
3791 case QEMU_OPTION_show_cursor
:
3794 case QEMU_OPTION_uuid
:
3795 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3796 error_report("failed to parse UUID string: wrong format");
3799 qemu_uuid_set
= true;
3801 case QEMU_OPTION_option_rom
:
3802 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3803 error_report("too many option ROMs");
3806 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3811 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3812 option_rom
[nb_option_roms
].bootindex
=
3813 qemu_opt_get_number(opts
, "bootindex", -1);
3814 if (!option_rom
[nb_option_roms
].name
) {
3815 error_report("Option ROM file is not specified");
3820 case QEMU_OPTION_semihosting
:
3821 semihosting
.enabled
= true;
3822 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3824 case QEMU_OPTION_semihosting_config
:
3825 semihosting
.enabled
= true;
3826 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3829 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3831 const char *target
= qemu_opt_get(opts
, "target");
3832 if (target
!= NULL
) {
3833 if (strcmp("native", target
) == 0) {
3834 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3835 } else if (strcmp("gdb", target
) == 0) {
3836 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3837 } else if (strcmp("auto", target
) == 0) {
3838 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3840 error_report("unsupported semihosting-config %s",
3845 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3847 /* Set semihosting argument count and vector */
3848 qemu_opt_foreach(opts
, add_semihosting_arg
,
3849 &semihosting
, NULL
);
3851 error_report("unsupported semihosting-config %s", optarg
);
3855 case QEMU_OPTION_tdf
:
3856 warn_report("ignoring deprecated option");
3858 case QEMU_OPTION_name
:
3859 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3865 case QEMU_OPTION_prom_env
:
3866 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3867 error_report("too many prom variables");
3870 prom_envs
[nb_prom_envs
] = optarg
;
3873 case QEMU_OPTION_old_param
:
3876 case QEMU_OPTION_clock
:
3877 /* Clock options no longer exist. Keep this option for
3878 * backward compatibility.
3881 case QEMU_OPTION_startdate
:
3882 configure_rtc_date_offset(optarg
, 1);
3884 case QEMU_OPTION_rtc
:
3885 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3890 configure_rtc(opts
);
3892 case QEMU_OPTION_tb_size
:
3894 error_report("TCG is disabled");
3897 if (qemu_strtoul(optarg
, NULL
, 0, &tcg_tb_size
) < 0) {
3898 error_report("Invalid argument to -tb-size");
3902 case QEMU_OPTION_icount
:
3903 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3909 case QEMU_OPTION_incoming
:
3911 runstate_set(RUN_STATE_INMIGRATE
);
3915 case QEMU_OPTION_only_migratable
:
3917 * TODO: we can remove this option one day, and we
3920 * "-global migration.only-migratable=true"
3922 qemu_global_option("migration.only-migratable=true");
3924 case QEMU_OPTION_nodefaults
:
3927 case QEMU_OPTION_xen_domid
:
3928 if (!(xen_available())) {
3929 error_report("Option not supported for this target");
3932 xen_domid
= atoi(optarg
);
3934 case QEMU_OPTION_xen_create
:
3935 if (!(xen_available())) {
3936 error_report("Option not supported for this target");
3939 xen_mode
= XEN_CREATE
;
3941 case QEMU_OPTION_xen_attach
:
3942 if (!(xen_available())) {
3943 error_report("Option not supported for this target");
3946 xen_mode
= XEN_ATTACH
;
3948 case QEMU_OPTION_xen_domid_restrict
:
3949 if (!(xen_available())) {
3950 error_report("Option not supported for this target");
3953 xen_domid_restrict
= true;
3955 case QEMU_OPTION_trace
:
3957 trace_file
= trace_opt_parse(optarg
);
3959 case QEMU_OPTION_readconfig
:
3961 int ret
= qemu_read_config_file(optarg
);
3963 error_report("read config %s: %s", optarg
,
3969 case QEMU_OPTION_spice
:
3970 olist
= qemu_find_opts("spice");
3972 error_report("spice support is disabled");
3975 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3981 case QEMU_OPTION_writeconfig
:
3984 if (strcmp(optarg
, "-") == 0) {
3987 fp
= fopen(optarg
, "w");
3989 error_report("open %s: %s", optarg
,
3994 qemu_config_write(fp
);
4000 case QEMU_OPTION_qtest
:
4001 qtest_chrdev
= optarg
;
4003 case QEMU_OPTION_qtest_log
:
4006 case QEMU_OPTION_sandbox
:
4007 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4013 case QEMU_OPTION_add_fd
:
4015 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4021 error_report("File descriptor passing is disabled on this "
4026 case QEMU_OPTION_object
:
4027 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
4033 case QEMU_OPTION_realtime
:
4034 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4039 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4041 case QEMU_OPTION_msg
:
4042 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4047 configure_msg(opts
);
4049 case QEMU_OPTION_dump_vmstate
:
4050 if (vmstate_dump_file
) {
4051 error_report("only one '-dump-vmstate' "
4052 "option may be given");
4055 vmstate_dump_file
= fopen(optarg
, "w");
4056 if (vmstate_dump_file
== NULL
) {
4057 error_report("open %s: %s", optarg
, strerror(errno
));
4062 os_parse_cmd_args(popt
->index
, optarg
);
4067 * Clear error location left behind by the loop.
4068 * Best done right after the loop. Do not insert code here!
4072 replay_configure(icount_opts
);
4074 machine_class
= select_machine();
4076 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4079 rcu_disable_atfork();
4081 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4082 error_report("could not acquire pid file: %s", strerror(errno
));
4086 if (qemu_init_main_loop(&main_loop_err
)) {
4087 error_report_err(main_loop_err
);
4091 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4092 parse_sandbox
, NULL
, NULL
)) {
4096 if (qemu_opts_foreach(qemu_find_opts("name"),
4097 parse_name
, NULL
, NULL
)) {
4102 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4103 parse_add_fd
, NULL
, NULL
)) {
4107 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4108 cleanup_add_fd
, NULL
, NULL
)) {
4113 current_machine
= MACHINE(object_new(object_class_get_name(
4114 OBJECT_CLASS(machine_class
))));
4115 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4118 object_property_add_child(object_get_root(), "machine",
4119 OBJECT(current_machine
), &error_abort
);
4121 if (machine_class
->minimum_page_bits
) {
4122 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4123 /* This would be a board error: specifying a minimum smaller than
4124 * a target's compile-time fixed setting.
4126 g_assert_not_reached();
4130 cpu_exec_init_all();
4132 if (machine_class
->hw_version
) {
4133 qemu_set_hw_version(machine_class
->hw_version
);
4136 if (cpu_model
&& is_help_option(cpu_model
)) {
4137 list_cpus(stdout
, &fprintf
, cpu_model
);
4141 if (!trace_init_backends()) {
4144 trace_init_file(trace_file
);
4146 /* Open the logfile at this point and set the log mask if necessary.
4149 qemu_set_log_filename(log_file
, &error_fatal
);
4154 mask
= qemu_str_to_log_mask(log_mask
);
4156 qemu_print_log_usage(stdout
);
4164 /* add configured firmware directories */
4165 dirs
= g_strsplit(CONFIG_QEMU_FIRMWAREPATH
, G_SEARCHPATH_SEPARATOR_S
, 0);
4166 for (i
= 0; dirs
[i
] != NULL
; i
++) {
4167 qemu_add_data_dir(dirs
[i
]);
4171 /* try to find datadir relative to the executable path */
4172 dir
= os_find_datadir();
4173 qemu_add_data_dir(dir
);
4176 /* add the datadir specified when building */
4177 qemu_add_data_dir(CONFIG_QEMU_DATADIR
);
4179 /* -L help lists the data directories and exits. */
4180 if (list_data_dirs
) {
4181 for (i
= 0; i
< data_dir_idx
; i
++) {
4182 printf("%s\n", data_dir
[i
]);
4187 /* machine_class: default to UP */
4188 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1;
4189 machine_class
->min_cpus
= machine_class
->min_cpus
?: 1;
4190 machine_class
->default_cpus
= machine_class
->default_cpus
?: 1;
4192 /* default to machine_class->default_cpus */
4193 smp_cpus
= machine_class
->default_cpus
;
4194 max_cpus
= machine_class
->default_cpus
;
4196 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4198 /* sanity-check smp_cpus and max_cpus against machine_class */
4199 if (smp_cpus
< machine_class
->min_cpus
) {
4200 error_report("Invalid SMP CPUs %d. The min CPUs "
4201 "supported by machine '%s' is %d", smp_cpus
,
4202 machine_class
->name
, machine_class
->min_cpus
);
4205 if (max_cpus
> machine_class
->max_cpus
) {
4206 error_report("Invalid SMP CPUs %d. The max CPUs "
4207 "supported by machine '%s' is %d", max_cpus
,
4208 machine_class
->name
, machine_class
->max_cpus
);
4213 * Get the default machine options from the machine if it is not already
4214 * specified either by the configuration file or by the command line.
4216 if (machine_class
->default_machine_opts
) {
4217 qemu_opts_set_defaults(qemu_find_opts("machine"),
4218 machine_class
->default_machine_opts
, 0);
4221 qemu_opts_foreach(qemu_find_opts("device"),
4222 default_driver_check
, NULL
, NULL
);
4223 qemu_opts_foreach(qemu_find_opts("global"),
4224 default_driver_check
, NULL
, NULL
);
4226 if (!vga_model
&& !default_vga
) {
4227 vga_interface_type
= VGA_DEVICE
;
4229 if (!has_defaults
|| machine_class
->no_serial
) {
4232 if (!has_defaults
|| machine_class
->no_parallel
) {
4233 default_parallel
= 0;
4235 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4236 default_virtcon
= 0;
4238 if (!has_defaults
|| !machine_class
->use_sclp
) {
4241 if (!has_defaults
|| machine_class
->no_floppy
) {
4244 if (!has_defaults
|| machine_class
->no_cdrom
) {
4247 if (!has_defaults
|| machine_class
->no_sdcard
) {
4250 if (!has_defaults
) {
4251 default_monitor
= 0;
4256 if (is_daemonized()) {
4257 /* According to documentation and historically, -nographic redirects
4258 * serial port, parallel port and monitor to stdio, which does not work
4259 * with -daemonize. We can redirect these to null instead, but since
4260 * -nographic is legacy, let's just error out.
4261 * We disallow -nographic only if all other ports are not redirected
4262 * explicitly, to not break existing legacy setups which uses
4263 * -nographic _and_ redirects all ports explicitly - this is valid
4264 * usage, -nographic is just a no-op in this case.
4267 && (default_parallel
|| default_serial
4268 || default_monitor
|| default_virtcon
)) {
4269 error_report("-nographic cannot be used with -daemonize");
4272 #ifdef CONFIG_CURSES
4273 if (display_type
== DT_CURSES
) {
4274 error_report("curses display cannot be used with -daemonize");
4281 if (default_parallel
)
4282 add_device_config(DEV_PARALLEL
, "null");
4283 if (default_serial
&& default_monitor
) {
4284 add_device_config(DEV_SERIAL
, "mon:stdio");
4285 } else if (default_virtcon
&& default_monitor
) {
4286 add_device_config(DEV_VIRTCON
, "mon:stdio");
4287 } else if (default_sclp
&& default_monitor
) {
4288 add_device_config(DEV_SCLP
, "mon:stdio");
4291 add_device_config(DEV_SERIAL
, "stdio");
4292 if (default_virtcon
)
4293 add_device_config(DEV_VIRTCON
, "stdio");
4295 add_device_config(DEV_SCLP
, "stdio");
4297 if (default_monitor
)
4298 monitor_parse("stdio", "readline", false);
4302 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4303 if (default_parallel
)
4304 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4305 if (default_monitor
)
4306 monitor_parse("vc:80Cx24C", "readline", false);
4307 if (default_virtcon
)
4308 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4310 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4314 #if defined(CONFIG_VNC)
4315 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4319 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4320 #if defined(CONFIG_GTK)
4321 display_type
= DT_GTK
;
4322 #elif defined(CONFIG_SDL)
4323 display_type
= DT_SDL
;
4324 #elif defined(CONFIG_COCOA)
4325 display_type
= DT_COCOA
;
4326 #elif defined(CONFIG_VNC)
4327 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4329 display_type
= DT_NONE
;
4333 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4334 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4335 "for SDL, ignoring option");
4337 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4338 error_report("-no-quit is only valid for GTK and SDL, "
4342 if (display_type
== DT_GTK
) {
4343 early_gtk_display_init(request_opengl
);
4346 if (display_type
== DT_SDL
) {
4347 sdl_display_early_init(request_opengl
);
4350 qemu_console_early_init();
4352 if (request_opengl
== 1 && display_opengl
== 0) {
4353 #if defined(CONFIG_OPENGL)
4354 error_report("OpenGL is not supported by the display");
4356 error_report("OpenGL support is disabled");
4364 if (qemu_opts_foreach(qemu_find_opts("object"),
4365 user_creatable_add_opts_foreach
,
4366 object_create_initial
, NULL
)) {
4370 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4371 chardev_init_func
, NULL
, NULL
)) {
4375 #ifdef CONFIG_VIRTFS
4376 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4377 fsdev_init_func
, NULL
, NULL
)) {
4382 if (qemu_opts_foreach(qemu_find_opts("device"),
4383 device_help_func
, NULL
, NULL
)) {
4387 machine_opts
= qemu_get_machine_opts();
4388 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4390 object_unref(OBJECT(current_machine
));
4394 configure_accelerator(current_machine
);
4397 * Register all the global properties, including accel properties,
4398 * machine properties, and user-specified ones.
4400 register_global_properties(current_machine
);
4403 * Migration object can only be created after global properties
4404 * are applied correctly.
4406 migration_object_init();
4409 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4412 machine_opts
= qemu_get_machine_opts();
4413 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4414 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4415 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4416 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4418 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4420 boot_order
= qemu_opt_get(opts
, "order");
4422 validate_bootdevices(boot_order
, &error_fatal
);
4425 boot_once
= qemu_opt_get(opts
, "once");
4427 validate_bootdevices(boot_once
, &error_fatal
);
4430 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4431 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4435 boot_order
= machine_class
->default_boot_order
;
4438 if (!kernel_cmdline
) {
4439 kernel_cmdline
= "";
4440 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4443 linux_boot
= (kernel_filename
!= NULL
);
4445 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4446 error_report("-append only allowed with -kernel option");
4450 if (!linux_boot
&& initrd_filename
!= NULL
) {
4451 error_report("-initrd only allowed with -kernel option");
4455 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4456 /* fall back to the -kernel/-append */
4457 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4460 os_set_line_buffering();
4462 /* spice needs the timers to be initialized by this point */
4467 if (!tcg_enabled()) {
4468 error_report("-icount is not allowed with hardware virtualization");
4471 configure_icount(icount_opts
, &error_abort
);
4472 qemu_opts_del(icount_opts
);
4475 if (tcg_enabled()) {
4476 qemu_tcg_configure(accel_opts
, &error_fatal
);
4480 QemuOptsList
*net
= qemu_find_opts("net");
4481 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4483 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4489 if (net_init_clients() < 0) {
4493 if (qemu_opts_foreach(qemu_find_opts("object"),
4494 user_creatable_add_opts_foreach
,
4495 object_create_delayed
, NULL
)) {
4499 if (tpm_init() < 0) {
4503 /* init the bluetooth world */
4504 if (foreach_device_config(DEV_BT
, bt_parse
))
4507 if (!xen_enabled()) {
4508 /* On 32-bit hosts, QEMU is limited by virtual address space */
4509 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4510 error_report("at most 2047 MB RAM can be simulated");
4518 /* If the currently selected machine wishes to override the units-per-bus
4519 * property of its default HBA interface type, do so now. */
4520 if (machine_class
->units_per_default_bus
) {
4521 override_max_devs(machine_class
->block_default_type
,
4522 machine_class
->units_per_default_bus
);
4525 /* open the virtual block devices */
4526 while (!QSIMPLEQ_EMPTY(&bdo_queue
)) {
4527 BlockdevOptions_queue
*bdo
= QSIMPLEQ_FIRST(&bdo_queue
);
4529 QSIMPLEQ_REMOVE_HEAD(&bdo_queue
, entry
);
4530 loc_push_restore(&bdo
->loc
);
4531 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
4533 qapi_free_BlockdevOptions(bdo
->bdo
);
4536 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4537 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4540 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4541 &machine_class
->block_default_type
, NULL
)) {
4545 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4547 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4548 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4550 if (qemu_opts_foreach(qemu_find_opts("mon"),
4551 mon_init_func
, NULL
, NULL
)) {
4555 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4557 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4559 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4561 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4564 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4567 /* If no default VGA is requested, the default is "none". */
4569 if (machine_class
->default_display
) {
4570 vga_model
= machine_class
->default_display
;
4571 } else if (vga_interface_available(VGA_CIRRUS
)) {
4572 vga_model
= "cirrus";
4573 } else if (vga_interface_available(VGA_STD
)) {
4578 select_vgahw(vga_model
);
4582 i
= select_watchdog(watchdog
);
4584 exit (i
== 1 ? 1 : 0);
4587 /* This checkpoint is required by replay to separate prior clock
4588 reading from the other reads, because timer polling functions query
4589 clock values from the log. */
4590 replay_checkpoint(CHECKPOINT_INIT
);
4591 qdev_machine_init();
4593 current_machine
->ram_size
= ram_size
;
4594 current_machine
->maxram_size
= maxram_size
;
4595 current_machine
->ram_slots
= ram_slots
;
4596 current_machine
->boot_order
= boot_order
;
4597 current_machine
->cpu_model
= cpu_model
;
4599 /* parse features once if machine provides default cpu_type */
4600 if (machine_class
->default_cpu_type
) {
4601 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
4603 current_machine
->cpu_type
=
4604 cpu_parse_cpu_model(machine_class
->default_cpu_type
, cpu_model
);
4607 parse_numa_opts(current_machine
);
4609 machine_run_board_init(current_machine
);
4615 if (hax_enabled()) {
4619 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4620 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4624 /* init USB devices */
4625 if (machine_usb(current_machine
)) {
4626 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4630 /* Check if IGD GFX passthrough. */
4633 /* init generic devices */
4634 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4635 if (qemu_opts_foreach(qemu_find_opts("device"),
4636 device_init_func
, NULL
, NULL
)) {
4640 cpu_synchronize_all_post_init();
4642 rom_reset_order_override();
4645 * Create frontends for -drive if=scsi leftovers.
4646 * Normally, frontends for -drive get created by machine
4647 * initialization for onboard SCSI HBAs. However, we create a few
4648 * more ever since SCSI qdevification, but this is pretty much an
4649 * implementation accident, and deprecated.
4651 scsi_legacy_handle_cmdline();
4653 /* Did we create any drives that we failed to create a device for? */
4654 drive_check_orphaned();
4656 /* Don't warn about the default network setup that you get if
4657 * no command line -net or -netdev options are specified. There
4658 * are two cases that we would otherwise complain about:
4659 * (1) board doesn't support a NIC but the implicit "-net nic"
4661 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4662 * sets up a nic that isn't connected to anything.
4665 net_check_clients();
4670 qemu_boot_set(boot_once
, &error_fatal
);
4671 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4674 ds
= init_displaystate();
4676 /* init local displays */
4677 switch (display_type
) {
4679 curses_display_init(ds
, full_screen
);
4682 sdl_display_init(ds
, full_screen
);
4685 cocoa_display_init(ds
, full_screen
);
4688 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4694 /* must be after terminal init, SDL library changes signal handlers */
4695 os_setup_signal_handling();
4697 /* init remote displays */
4699 qemu_opts_foreach(qemu_find_opts("vnc"),
4700 vnc_init_func
, NULL
, NULL
);
4704 qemu_spice_display_init();
4707 #ifdef CONFIG_OPENGL_DMABUF
4708 if (display_type
== DT_EGL
) {
4709 egl_headless_init();
4713 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4717 qdev_machine_creation_done();
4719 /* TODO: once all bus devices are qdevified, this should be done
4720 * when bus is created by qdev.c */
4721 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4722 qemu_run_machine_init_done_notifiers();
4724 if (rom_check_and_register_reset() != 0) {
4725 error_report("rom check and register reset failed");
4731 /* This checkpoint is required by replay to separate prior clock
4732 reading from the other reads, because timer polling functions query
4733 clock values from the log. */
4734 replay_checkpoint(CHECKPOINT_RESET
);
4735 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
4736 register_global_state();
4737 if (replay_mode
!= REPLAY_MODE_NONE
) {
4738 replay_vmstate_init();
4739 } else if (loadvm
) {
4740 Error
*local_err
= NULL
;
4741 if (load_snapshot(loadvm
, &local_err
) < 0) {
4742 error_report_err(local_err
);
4747 qdev_prop_check_globals();
4748 if (vmstate_dump_file
) {
4750 dump_vmstate_json_to_file(vmstate_dump_file
);
4755 Error
*local_err
= NULL
;
4756 qemu_start_incoming_migration(incoming
, &local_err
);
4758 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4761 } else if (autostart
) {
4768 replay_disable_events();
4769 iothread_stop_all();
4775 /* vhost-user must be cleaned up before chardevs. */
4781 user_creatable_cleanup();
4782 migration_object_finalize();
4783 /* TODO: unref root container, check all devices are ok */