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"
35 #if defined(CONFIG_VDE)
36 #include <libvdeplug.h>
40 #if defined(__APPLE__) || defined(main)
42 int qemu_main(int argc
, char **argv
, char **envp
);
43 int main(int argc
, char **argv
)
45 return qemu_main(argc
, argv
, NULL
);
48 #define main qemu_main
50 #endif /* CONFIG_SDL */
54 #define main qemu_main
55 #endif /* CONFIG_COCOA */
58 #include "qemu/error-report.h"
59 #include "qemu/sockets.h"
61 #include "hw/boards.h"
62 #include "sysemu/accel.h"
64 #include "hw/i386/pc.h"
65 #include "hw/isa/isa.h"
66 #include "hw/scsi/scsi.h"
68 #include "sysemu/watchdog.h"
69 #include "hw/smbios/smbios.h"
70 #include "hw/acpi/acpi.h"
71 #include "hw/xen/xen.h"
73 #include "hw/loader.h"
74 #include "monitor/qdev.h"
75 #include "sysemu/bt.h"
77 #include "net/slirp.h"
78 #include "monitor/monitor.h"
79 #include "ui/console.h"
81 #include "sysemu/sysemu.h"
82 #include "sysemu/numa.h"
83 #include "exec/gdbstub.h"
84 #include "qemu/timer.h"
85 #include "chardev/char.h"
86 #include "qemu/bitmap.h"
88 #include "sysemu/blockdev.h"
89 #include "hw/block/block.h"
90 #include "migration/misc.h"
91 #include "migration/snapshot.h"
92 #include "migration/global_state.h"
93 #include "sysemu/tpm.h"
94 #include "sysemu/dma.h"
95 #include "hw/audio/soundhw.h"
96 #include "audio/audio.h"
97 #include "sysemu/cpus.h"
98 #include "migration/colo.h"
99 #include "sysemu/kvm.h"
100 #include "sysemu/hax.h"
101 #include "qapi/qobject-input-visitor.h"
102 #include "qapi/qobject-input-visitor.h"
103 #include "qapi-visit.h"
104 #include "qapi/qmp/qjson.h"
105 #include "qemu/option.h"
106 #include "qemu/config-file.h"
107 #include "qemu-options.h"
108 #include "qmp-commands.h"
109 #include "qemu/main-loop.h"
111 #include "fsdev/qemu-fsdev.h"
113 #include "sysemu/qtest.h"
115 #include "disas/disas.h"
118 #include "slirp/libslirp.h"
120 #include "trace-root.h"
121 #include "trace/control.h"
122 #include "qemu/queue.h"
123 #include "sysemu/arch_init.h"
125 #include "ui/qemu-spice.h"
126 #include "qapi/string-input-visitor.h"
127 #include "qapi/opts-visitor.h"
128 #include "qom/object_interfaces.h"
129 #include "qapi-event.h"
130 #include "exec/semihost.h"
131 #include "crypto/init.h"
132 #include "sysemu/replay.h"
133 #include "qapi/qmp/qerror.h"
134 #include "sysemu/iothread.h"
136 #define MAX_VIRTIO_CONSOLES 1
137 #define MAX_SCLP_CONSOLES 1
139 static const char *data_dir
[16];
140 static int data_dir_idx
;
141 const char *bios_name
= NULL
;
142 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
143 int request_opengl
= -1;
145 const char* keyboard_layout
= NULL
;
147 const char *mem_path
= NULL
;
148 int mem_prealloc
= 0; /* force preallocation of physical target memory */
149 bool enable_mlock
= false;
151 NICInfo nd_table
[MAX_NICS
];
153 static int rtc_utc
= 1;
154 static int rtc_date_offset
= -1; /* -1 means no change */
155 QEMUClockType rtc_clock
;
156 int vga_interface_type
= VGA_NONE
;
157 static int full_screen
= 0;
158 static int no_frame
= 0;
160 static bool grab_on_hover
;
161 Chardev
*serial_hds
[MAX_SERIAL_PORTS
];
162 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
163 Chardev
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
164 Chardev
*sclp_hds
[MAX_SCLP_CONSOLES
];
165 int win2k_install_hack
= 0;
171 int acpi_enabled
= 1;
174 static int no_reboot
;
177 int graphic_rotate
= 0;
178 const char *watchdog
;
179 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
182 const char *qemu_name
;
185 unsigned int nb_prom_envs
= 0;
186 const char *prom_envs
[MAX_PROM_ENVS
];
189 uint8_t *boot_splash_filedata
;
190 size_t boot_splash_filedata_size
;
191 uint8_t qemu_extra_params_fw
[2];
193 int icount_align_option
;
195 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
196 * little-endian "wire format" described in the SMBIOS 2.6 specification.
201 static NotifierList exit_notifiers
=
202 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
204 static NotifierList machine_init_done_notifiers
=
205 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
209 enum xen_mode xen_mode
= XEN_EMULATE
;
210 bool xen_domid_restrict
;
212 static int has_defaults
= 1;
213 static int default_serial
= 1;
214 static int default_parallel
= 1;
215 static int default_virtcon
= 1;
216 static int default_sclp
= 1;
217 static int default_monitor
= 1;
218 static int default_floppy
= 1;
219 static int default_cdrom
= 1;
220 static int default_sdcard
= 1;
221 static int default_vga
= 1;
222 static int default_net
= 1;
228 { .driver
= "isa-serial", .flag
= &default_serial
},
229 { .driver
= "isa-parallel", .flag
= &default_parallel
},
230 { .driver
= "isa-fdc", .flag
= &default_floppy
},
231 { .driver
= "floppy", .flag
= &default_floppy
},
232 { .driver
= "ide-cd", .flag
= &default_cdrom
},
233 { .driver
= "ide-hd", .flag
= &default_cdrom
},
234 { .driver
= "ide-drive", .flag
= &default_cdrom
},
235 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
236 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
237 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
238 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
239 { .driver
= "VGA", .flag
= &default_vga
},
240 { .driver
= "isa-vga", .flag
= &default_vga
},
241 { .driver
= "cirrus-vga", .flag
= &default_vga
},
242 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
243 { .driver
= "vmware-svga", .flag
= &default_vga
},
244 { .driver
= "qxl-vga", .flag
= &default_vga
},
245 { .driver
= "virtio-vga", .flag
= &default_vga
},
248 static QemuOptsList qemu_rtc_opts
= {
250 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
254 .type
= QEMU_OPT_STRING
,
257 .type
= QEMU_OPT_STRING
,
260 .type
= QEMU_OPT_STRING
,
262 { /* end of list */ }
266 static QemuOptsList qemu_sandbox_opts
= {
268 .implied_opt_name
= "enable",
269 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
273 .type
= QEMU_OPT_BOOL
,
277 .type
= QEMU_OPT_STRING
,
280 .name
= "elevateprivileges",
281 .type
= QEMU_OPT_STRING
,
285 .type
= QEMU_OPT_STRING
,
288 .name
= "resourcecontrol",
289 .type
= QEMU_OPT_STRING
,
291 { /* end of list */ }
295 static QemuOptsList qemu_option_rom_opts
= {
296 .name
= "option-rom",
297 .implied_opt_name
= "romfile",
298 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
302 .type
= QEMU_OPT_NUMBER
,
305 .type
= QEMU_OPT_STRING
,
307 { /* end of list */ }
311 static QemuOptsList qemu_machine_opts
= {
313 .implied_opt_name
= "type",
315 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
318 * no elements => accept any
319 * sanity checking will happen later
320 * when setting machine properties
326 static QemuOptsList qemu_accel_opts
= {
328 .implied_opt_name
= "accel",
329 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
334 .type
= QEMU_OPT_STRING
,
335 .help
= "Select the type of accelerator",
339 .type
= QEMU_OPT_STRING
,
340 .help
= "Enable/disable multi-threaded TCG",
342 { /* end of list */ }
346 static QemuOptsList qemu_boot_opts
= {
348 .implied_opt_name
= "order",
350 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
354 .type
= QEMU_OPT_STRING
,
357 .type
= QEMU_OPT_STRING
,
360 .type
= QEMU_OPT_BOOL
,
363 .type
= QEMU_OPT_STRING
,
365 .name
= "splash-time",
366 .type
= QEMU_OPT_STRING
,
368 .name
= "reboot-timeout",
369 .type
= QEMU_OPT_STRING
,
372 .type
= QEMU_OPT_BOOL
,
378 static QemuOptsList qemu_add_fd_opts
= {
380 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
384 .type
= QEMU_OPT_NUMBER
,
385 .help
= "file descriptor of which a duplicate is added to fd set",
388 .type
= QEMU_OPT_NUMBER
,
389 .help
= "ID of the fd set to add fd to",
392 .type
= QEMU_OPT_STRING
,
393 .help
= "free-form string used to describe fd",
395 { /* end of list */ }
399 static QemuOptsList qemu_object_opts
= {
401 .implied_opt_name
= "qom-type",
402 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
408 static QemuOptsList qemu_tpmdev_opts
= {
410 .implied_opt_name
= "type",
411 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
413 /* options are defined in the TPM backends */
414 { /* end of list */ }
418 static QemuOptsList qemu_realtime_opts
= {
420 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
424 .type
= QEMU_OPT_BOOL
,
426 { /* end of list */ }
430 static QemuOptsList qemu_msg_opts
= {
432 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
436 .type
= QEMU_OPT_BOOL
,
438 { /* end of list */ }
442 static QemuOptsList qemu_name_opts
= {
444 .implied_opt_name
= "guest",
446 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
450 .type
= QEMU_OPT_STRING
,
451 .help
= "Sets the name of the guest.\n"
452 "This name will be displayed in the SDL window caption.\n"
453 "The name will also be used for the VNC server",
456 .type
= QEMU_OPT_STRING
,
457 .help
= "Sets the name of the QEMU process, as shown in top etc",
459 .name
= "debug-threads",
460 .type
= QEMU_OPT_BOOL
,
461 .help
= "When enabled, name the individual threads; defaults off.\n"
462 "NOTE: The thread names are for debugging and not a\n"
465 { /* End of list */ }
469 static QemuOptsList qemu_mem_opts
= {
471 .implied_opt_name
= "size",
472 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
477 .type
= QEMU_OPT_SIZE
,
481 .type
= QEMU_OPT_NUMBER
,
485 .type
= QEMU_OPT_SIZE
,
487 { /* end of list */ }
491 static QemuOptsList qemu_icount_opts
= {
493 .implied_opt_name
= "shift",
495 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
499 .type
= QEMU_OPT_STRING
,
502 .type
= QEMU_OPT_BOOL
,
505 .type
= QEMU_OPT_BOOL
,
508 .type
= QEMU_OPT_STRING
,
511 .type
= QEMU_OPT_STRING
,
513 .name
= "rrsnapshot",
514 .type
= QEMU_OPT_STRING
,
516 { /* end of list */ }
520 static QemuOptsList qemu_semihosting_config_opts
= {
521 .name
= "semihosting-config",
522 .implied_opt_name
= "enable",
523 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
527 .type
= QEMU_OPT_BOOL
,
530 .type
= QEMU_OPT_STRING
,
533 .type
= QEMU_OPT_STRING
,
535 { /* end of list */ }
539 static QemuOptsList qemu_fw_cfg_opts
= {
541 .implied_opt_name
= "name",
542 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
546 .type
= QEMU_OPT_STRING
,
547 .help
= "Sets the fw_cfg name of the blob to be inserted",
550 .type
= QEMU_OPT_STRING
,
551 .help
= "Sets the name of the file from which\n"
552 "the fw_cfg blob will be loaded",
555 .type
= QEMU_OPT_STRING
,
556 .help
= "Sets content of the blob to be inserted from a string",
558 { /* end of list */ }
563 * Get machine options
565 * Returns: machine options (never null).
567 QemuOpts
*qemu_get_machine_opts(void)
569 return qemu_find_opts_singleton("machine");
572 const char *qemu_get_vm_name(void)
577 static void res_free(void)
579 g_free(boot_splash_filedata
);
580 boot_splash_filedata
= NULL
;
583 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
585 const char *driver
= qemu_opt_get(opts
, "driver");
590 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
591 if (strcmp(default_list
[i
].driver
, driver
) != 0)
593 *(default_list
[i
].flag
) = 0;
598 /***********************************************************/
601 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
603 /* We use RUN_STATE__MAX but any invalid value will do */
604 static RunState vmstop_requested
= RUN_STATE__MAX
;
605 static QemuMutex vmstop_lock
;
610 } RunStateTransition
;
612 static const RunStateTransition runstate_transitions_def
[] = {
614 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
615 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
616 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
618 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
619 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
620 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
621 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
622 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
623 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
624 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
625 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
626 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
627 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
628 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
629 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
631 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
632 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
633 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
635 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
636 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
637 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
639 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
640 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
641 { RUN_STATE_PAUSED
, RUN_STATE_POSTMIGRATE
},
642 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
643 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
645 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
646 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
647 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
649 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
650 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
651 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
653 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
654 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PAUSED
},
655 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
656 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
657 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
659 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
660 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
662 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
664 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
665 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
666 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
667 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
668 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
669 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
670 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
671 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
672 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
673 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
674 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
676 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
678 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
679 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
680 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
682 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
683 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
684 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
685 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
686 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
687 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
689 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
690 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
691 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
692 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
694 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
695 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
696 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
698 { RUN_STATE__MAX
, RUN_STATE__MAX
},
701 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
703 bool runstate_check(RunState state
)
705 return current_run_state
== state
;
708 bool runstate_store(char *str
, size_t size
)
710 const char *state
= RunState_str(current_run_state
);
711 size_t len
= strlen(state
) + 1;
716 memcpy(str
, state
, len
);
720 static void runstate_init(void)
722 const RunStateTransition
*p
;
724 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
725 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
726 runstate_valid_transitions
[p
->from
][p
->to
] = true;
729 qemu_mutex_init(&vmstop_lock
);
732 /* This function will abort() on invalid state transitions */
733 void runstate_set(RunState new_state
)
735 assert(new_state
< RUN_STATE__MAX
);
737 if (current_run_state
== new_state
) {
741 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
742 error_report("invalid runstate transition: '%s' -> '%s'",
743 RunState_str(current_run_state
),
744 RunState_str(new_state
));
747 trace_runstate_set(new_state
);
748 current_run_state
= new_state
;
751 int runstate_is_running(void)
753 return runstate_check(RUN_STATE_RUNNING
);
756 bool runstate_needs_reset(void)
758 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
759 runstate_check(RUN_STATE_SHUTDOWN
);
762 StatusInfo
*qmp_query_status(Error
**errp
)
764 StatusInfo
*info
= g_malloc0(sizeof(*info
));
766 info
->running
= runstate_is_running();
767 info
->singlestep
= singlestep
;
768 info
->status
= current_run_state
;
773 bool qemu_vmstop_requested(RunState
*r
)
775 qemu_mutex_lock(&vmstop_lock
);
776 *r
= vmstop_requested
;
777 vmstop_requested
= RUN_STATE__MAX
;
778 qemu_mutex_unlock(&vmstop_lock
);
779 return *r
< RUN_STATE__MAX
;
782 void qemu_system_vmstop_request_prepare(void)
784 qemu_mutex_lock(&vmstop_lock
);
787 void qemu_system_vmstop_request(RunState state
)
789 vmstop_requested
= state
;
790 qemu_mutex_unlock(&vmstop_lock
);
794 /***********************************************************/
795 /* real time host monotonic timer */
797 static time_t qemu_time(void)
799 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
802 /***********************************************************/
803 /* host time/date access */
804 void qemu_get_timedate(struct tm
*tm
, int offset
)
806 time_t ti
= qemu_time();
809 if (rtc_date_offset
== -1) {
813 localtime_r(&ti
, tm
);
815 ti
-= rtc_date_offset
;
820 int qemu_timedate_diff(struct tm
*tm
)
824 if (rtc_date_offset
== -1)
826 seconds
= mktimegm(tm
);
829 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
830 seconds
= mktime(&tmp
);
833 seconds
= mktimegm(tm
) + rtc_date_offset
;
835 return seconds
- qemu_time();
838 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
840 time_t rtc_start_date
;
843 if (!strcmp(startdate
, "now") && legacy
) {
844 rtc_date_offset
= -1;
846 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
854 } else if (sscanf(startdate
, "%d-%d-%d",
866 rtc_start_date
= mktimegm(&tm
);
867 if (rtc_start_date
== -1) {
869 error_report("invalid date format");
870 error_printf("valid formats: "
871 "'2006-06-17T16:01:21' or '2006-06-17'\n");
874 rtc_date_offset
= qemu_time() - rtc_start_date
;
878 static void configure_rtc(QemuOpts
*opts
)
882 value
= qemu_opt_get(opts
, "base");
884 if (!strcmp(value
, "utc")) {
886 } else if (!strcmp(value
, "localtime")) {
887 Error
*blocker
= NULL
;
889 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
890 "-rtc base=localtime");
891 replay_add_blocker(blocker
);
893 configure_rtc_date_offset(value
, 0);
896 value
= qemu_opt_get(opts
, "clock");
898 if (!strcmp(value
, "host")) {
899 rtc_clock
= QEMU_CLOCK_HOST
;
900 } else if (!strcmp(value
, "rt")) {
901 rtc_clock
= QEMU_CLOCK_REALTIME
;
902 } else if (!strcmp(value
, "vm")) {
903 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
905 error_report("invalid option value '%s'", value
);
909 value
= qemu_opt_get(opts
, "driftfix");
911 if (!strcmp(value
, "slew")) {
912 static GlobalProperty slew_lost_ticks
= {
913 .driver
= "mc146818rtc",
914 .property
= "lost_tick_policy",
918 qdev_prop_register_global(&slew_lost_ticks
);
919 } else if (!strcmp(value
, "none")) {
920 /* discard is default */
922 error_report("invalid option value '%s'", value
);
928 /***********************************************************/
929 /* Bluetooth support */
932 static struct HCIInfo
*hci_table
[MAX_NICS
];
934 struct HCIInfo
*qemu_next_hci(void)
936 if (cur_hci
== nb_hcis
)
939 return hci_table
[cur_hci
++];
942 static int bt_hci_parse(const char *str
)
947 if (nb_hcis
>= MAX_NICS
) {
948 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
961 bdaddr
.b
[5] = 0x56 + nb_hcis
;
962 hci
->bdaddr_set(hci
, bdaddr
.b
);
964 hci_table
[nb_hcis
++] = hci
;
969 static void bt_vhci_add(int vlan_id
)
971 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
974 warn_report("adding a VHCI to an empty scatternet %i",
977 bt_vhci_init(bt_new_hci(vlan
));
980 static struct bt_device_s
*bt_device_add(const char *opt
)
982 struct bt_scatternet_s
*vlan
;
984 char *endp
= strstr(opt
, ",vlan=");
985 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
988 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
991 vlan_id
= strtol(endp
+ 6, &endp
, 0);
993 error_report("unrecognised bluetooth vlan Id");
998 vlan
= qemu_find_bt_vlan(vlan_id
);
1001 warn_report("adding a slave device to an empty scatternet %i",
1004 if (!strcmp(devname
, "keyboard"))
1005 return bt_keyboard_init(vlan
);
1007 error_report("unsupported bluetooth device '%s'", devname
);
1011 static int bt_parse(const char *opt
)
1013 const char *endp
, *p
;
1016 if (strstart(opt
, "hci", &endp
)) {
1017 if (!*endp
|| *endp
== ',') {
1019 if (!strstart(endp
, ",vlan=", 0))
1022 return bt_hci_parse(opt
);
1024 } else if (strstart(opt
, "vhci", &endp
)) {
1025 if (!*endp
|| *endp
== ',') {
1027 if (strstart(endp
, ",vlan=", &p
)) {
1028 vlan
= strtol(p
, (char **) &endp
, 0);
1030 error_report("bad scatternet '%s'", p
);
1034 error_report("bad parameter '%s'", endp
+ 1);
1043 } else if (strstart(opt
, "device:", &endp
))
1044 return !bt_device_add(endp
);
1046 error_report("bad bluetooth parameter '%s'", opt
);
1050 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1052 if (qemu_opt_get_bool(opts
, "enable", false)) {
1053 #ifdef CONFIG_SECCOMP
1054 uint32_t seccomp_opts
= QEMU_SECCOMP_SET_DEFAULT
1055 | QEMU_SECCOMP_SET_OBSOLETE
;
1056 const char *value
= NULL
;
1058 value
= qemu_opt_get(opts
, "obsolete");
1060 if (g_str_equal(value
, "allow")) {
1061 seccomp_opts
&= ~QEMU_SECCOMP_SET_OBSOLETE
;
1062 } else if (g_str_equal(value
, "deny")) {
1063 /* this is the default option, this if is here
1064 * to provide a little bit of consistency for
1065 * the command line */
1067 error_report("invalid argument for obsolete");
1072 value
= qemu_opt_get(opts
, "elevateprivileges");
1074 if (g_str_equal(value
, "deny")) {
1075 seccomp_opts
|= QEMU_SECCOMP_SET_PRIVILEGED
;
1076 } else if (g_str_equal(value
, "children")) {
1077 seccomp_opts
|= QEMU_SECCOMP_SET_PRIVILEGED
;
1079 /* calling prctl directly because we're
1080 * not sure if host has CAP_SYS_ADMIN set*/
1081 if (prctl(PR_SET_NO_NEW_PRIVS
, 1)) {
1082 error_report("failed to set no_new_privs "
1086 } else if (g_str_equal(value
, "allow")) {
1089 error_report("invalid argument for elevateprivileges");
1094 value
= qemu_opt_get(opts
, "spawn");
1096 if (g_str_equal(value
, "deny")) {
1097 seccomp_opts
|= QEMU_SECCOMP_SET_SPAWN
;
1098 } else if (g_str_equal(value
, "allow")) {
1101 error_report("invalid argument for spawn");
1106 value
= qemu_opt_get(opts
, "resourcecontrol");
1108 if (g_str_equal(value
, "deny")) {
1109 seccomp_opts
|= QEMU_SECCOMP_SET_RESOURCECTL
;
1110 } else if (g_str_equal(value
, "allow")) {
1113 error_report("invalid argument for resourcecontrol");
1118 if (seccomp_start(seccomp_opts
) < 0) {
1119 error_report("failed to install seccomp syscall filter "
1124 error_report("seccomp support is disabled");
1132 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1134 const char *proc_name
;
1136 if (qemu_opt_get(opts
, "debug-threads")) {
1137 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1139 qemu_name
= qemu_opt_get(opts
, "guest");
1141 proc_name
= qemu_opt_get(opts
, "process");
1143 os_set_proc_name(proc_name
);
1149 bool defaults_enabled(void)
1151 return has_defaults
;
1155 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1157 int fd
, dupfd
, flags
;
1159 const char *fd_opaque
= NULL
;
1162 fd
= qemu_opt_get_number(opts
, "fd", -1);
1163 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1164 fd_opaque
= qemu_opt_get(opts
, "opaque");
1167 error_report("fd option is required and must be non-negative");
1171 if (fd
<= STDERR_FILENO
) {
1172 error_report("fd cannot be a standard I/O stream");
1177 * All fds inherited across exec() necessarily have FD_CLOEXEC
1178 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1180 flags
= fcntl(fd
, F_GETFD
);
1181 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1182 error_report("fd is not valid or already in use");
1187 error_report("set option is required and must be non-negative");
1191 #ifdef F_DUPFD_CLOEXEC
1192 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1196 qemu_set_cloexec(dupfd
);
1200 error_report("error duplicating fd: %s", strerror(errno
));
1204 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1205 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1212 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1216 fd
= qemu_opt_get_number(opts
, "fd", -1);
1223 /***********************************************************/
1224 /* QEMU Block devices */
1226 #define HD_OPTS "media=disk"
1227 #define CDROM_OPTS "media=cdrom"
1229 #define PFLASH_OPTS ""
1233 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1235 BlockInterfaceType
*block_default_type
= opaque
;
1237 return drive_new(opts
, *block_default_type
) == NULL
;
1240 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1242 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1243 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1248 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1249 int index
, const char *optstr
)
1254 if (!enable
|| drive_get_by_index(type
, index
)) {
1258 opts
= drive_add(type
, index
, NULL
, optstr
);
1260 drive_enable_snapshot(NULL
, opts
, NULL
);
1263 dinfo
= drive_new(opts
, type
);
1267 dinfo
->is_default
= true;
1271 static QemuOptsList qemu_smp_opts
= {
1273 .implied_opt_name
= "cpus",
1274 .merge_lists
= true,
1275 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1279 .type
= QEMU_OPT_NUMBER
,
1282 .type
= QEMU_OPT_NUMBER
,
1285 .type
= QEMU_OPT_NUMBER
,
1288 .type
= QEMU_OPT_NUMBER
,
1291 .type
= QEMU_OPT_NUMBER
,
1293 { /*End of list */ }
1297 static void smp_parse(QemuOpts
*opts
)
1300 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1301 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1302 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1303 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1305 /* compute missing values, prefer sockets over cores over threads */
1306 if (cpus
== 0 || sockets
== 0) {
1307 sockets
= sockets
> 0 ? sockets
: 1;
1308 cores
= cores
> 0 ? cores
: 1;
1309 threads
= threads
> 0 ? threads
: 1;
1311 cpus
= cores
* threads
* sockets
;
1313 } else if (cores
== 0) {
1314 threads
= threads
> 0 ? threads
: 1;
1315 cores
= cpus
/ (sockets
* threads
);
1316 cores
= cores
> 0 ? cores
: 1;
1317 } else if (threads
== 0) {
1318 threads
= cpus
/ (cores
* sockets
);
1319 threads
= threads
> 0 ? threads
: 1;
1320 } else if (sockets
* cores
* threads
< cpus
) {
1321 error_report("cpu topology: "
1322 "sockets (%u) * cores (%u) * threads (%u) < "
1324 sockets
, cores
, threads
, cpus
);
1328 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1330 if (max_cpus
< cpus
) {
1331 error_report("maxcpus must be equal to or greater than smp");
1335 if (sockets
* cores
* threads
> max_cpus
) {
1336 error_report("cpu topology: "
1337 "sockets (%u) * cores (%u) * threads (%u) > "
1339 sockets
, cores
, threads
, max_cpus
);
1345 smp_threads
= threads
;
1349 Error
*blocker
= NULL
;
1350 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1351 replay_add_blocker(blocker
);
1355 static void realtime_init(void)
1358 if (os_mlock() < 0) {
1359 error_report("locking memory failed");
1366 static void configure_msg(QemuOpts
*opts
)
1368 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1371 /***********************************************************/
1374 typedef struct SemihostingConfig
{
1376 SemihostingTarget target
;
1379 const char *cmdline
; /* concatenated argv */
1380 } SemihostingConfig
;
1382 static SemihostingConfig semihosting
;
1384 bool semihosting_enabled(void)
1386 return semihosting
.enabled
;
1389 SemihostingTarget
semihosting_get_target(void)
1391 return semihosting
.target
;
1394 const char *semihosting_get_arg(int i
)
1396 if (i
>= semihosting
.argc
) {
1399 return semihosting
.argv
[i
];
1402 int semihosting_get_argc(void)
1404 return semihosting
.argc
;
1407 const char *semihosting_get_cmdline(void)
1409 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1410 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1412 return semihosting
.cmdline
;
1415 static int add_semihosting_arg(void *opaque
,
1416 const char *name
, const char *val
,
1419 SemihostingConfig
*s
= opaque
;
1420 if (strcmp(name
, "arg") == 0) {
1422 /* one extra element as g_strjoinv() expects NULL-terminated array */
1423 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1424 s
->argv
[s
->argc
- 1] = val
;
1425 s
->argv
[s
->argc
] = NULL
;
1430 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1431 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1436 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1438 /* split -append and initialize argv[1..n] */
1439 cmd_token
= strtok(g_strdup(cmd
), " ");
1441 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1442 cmd_token
= strtok(NULL
, " ");
1446 /* Now we still need this for compatibility with XEN. */
1447 bool has_igd_gfx_passthru
;
1448 static void igd_gfx_passthru(void)
1450 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1453 /***********************************************************/
1456 static int usb_device_add(const char *devname
)
1458 USBDevice
*dev
= NULL
;
1459 #ifndef CONFIG_LINUX
1463 if (!machine_usb(current_machine
)) {
1467 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1468 dev
= usbdevice_create(devname
);
1472 /* the other ones */
1473 #ifndef CONFIG_LINUX
1474 /* only the linux version is qdev-ified, usb-bsd still needs this */
1475 if (strstart(devname
, "host:", &p
)) {
1476 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1486 static int usb_device_del(const char *devname
)
1491 if (strstart(devname
, "host:", &p
)) {
1495 if (!machine_usb(current_machine
)) {
1499 p
= strchr(devname
, '.');
1502 bus_num
= strtoul(devname
, NULL
, 0);
1503 addr
= strtoul(p
+ 1, NULL
, 0);
1505 return usb_device_delete_addr(bus_num
, addr
);
1508 static int usb_parse(const char *cmdline
)
1511 r
= usb_device_add(cmdline
);
1513 error_report("could not add USB device '%s'", cmdline
);
1518 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1520 const char *devname
= qdict_get_str(qdict
, "devname");
1522 error_report("usb_add is deprecated, please use device_add instead");
1524 if (usb_device_add(devname
) < 0) {
1525 error_report("could not add USB device '%s'", devname
);
1529 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1531 const char *devname
= qdict_get_str(qdict
, "devname");
1533 error_report("usb_del is deprecated, please use device_del instead");
1535 if (usb_device_del(devname
) < 0) {
1536 error_report("could not delete USB device '%s'", devname
);
1540 /***********************************************************/
1541 /* machine registration */
1543 MachineState
*current_machine
;
1545 static MachineClass
*find_machine(const char *name
)
1547 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1548 MachineClass
*mc
= NULL
;
1550 for (el
= machines
; el
; el
= el
->next
) {
1551 MachineClass
*temp
= el
->data
;
1553 if (!strcmp(temp
->name
, name
)) {
1558 !strcmp(temp
->alias
, name
)) {
1564 g_slist_free(machines
);
1568 MachineClass
*find_default_machine(void)
1570 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1571 MachineClass
*mc
= NULL
;
1573 for (el
= machines
; el
; el
= el
->next
) {
1574 MachineClass
*temp
= el
->data
;
1576 if (temp
->is_default
) {
1582 g_slist_free(machines
);
1586 MachineInfoList
*qmp_query_machines(Error
**errp
)
1588 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1589 MachineInfoList
*mach_list
= NULL
;
1591 for (el
= machines
; el
; el
= el
->next
) {
1592 MachineClass
*mc
= el
->data
;
1593 MachineInfoList
*entry
;
1596 info
= g_malloc0(sizeof(*info
));
1597 if (mc
->is_default
) {
1598 info
->has_is_default
= true;
1599 info
->is_default
= true;
1603 info
->has_alias
= true;
1604 info
->alias
= g_strdup(mc
->alias
);
1607 info
->name
= g_strdup(mc
->name
);
1608 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1609 info
->hotpluggable_cpus
= mc
->has_hotpluggable_cpus
;
1611 entry
= g_malloc0(sizeof(*entry
));
1612 entry
->value
= info
;
1613 entry
->next
= mach_list
;
1617 g_slist_free(machines
);
1621 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1623 ObjectProperty
*prop
;
1624 ObjectPropertyIterator iter
;
1626 if (!qemu_opt_has_help_opt(opts
)) {
1630 object_property_iter_init(&iter
, OBJECT(machine
));
1631 while ((prop
= object_property_iter_next(&iter
))) {
1636 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1637 prop
->name
, prop
->type
);
1638 if (prop
->description
) {
1639 error_printf(" (%s)\n", prop
->description
);
1648 /***********************************************************/
1649 /* main execution loop */
1651 struct vm_change_state_entry
{
1652 VMChangeStateHandler
*cb
;
1654 QLIST_ENTRY (vm_change_state_entry
) entries
;
1657 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1659 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1662 VMChangeStateEntry
*e
;
1664 e
= g_malloc0(sizeof (*e
));
1668 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1672 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1674 QLIST_REMOVE (e
, entries
);
1678 void vm_state_notify(int running
, RunState state
)
1680 VMChangeStateEntry
*e
, *next
;
1682 trace_vm_state_notify(running
, state
);
1684 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1685 e
->cb(e
->opaque
, running
, state
);
1689 static ShutdownCause reset_requested
;
1690 static ShutdownCause shutdown_requested
;
1691 static int shutdown_signal
;
1692 static pid_t shutdown_pid
;
1693 static int powerdown_requested
;
1694 static int debug_requested
;
1695 static int suspend_requested
;
1696 static WakeupReason wakeup_reason
;
1697 static NotifierList powerdown_notifiers
=
1698 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1699 static NotifierList suspend_notifiers
=
1700 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1701 static NotifierList wakeup_notifiers
=
1702 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1703 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1705 ShutdownCause
qemu_shutdown_requested_get(void)
1707 return shutdown_requested
;
1710 ShutdownCause
qemu_reset_requested_get(void)
1712 return reset_requested
;
1715 static int qemu_shutdown_requested(void)
1717 return atomic_xchg(&shutdown_requested
, SHUTDOWN_CAUSE_NONE
);
1720 static void qemu_kill_report(void)
1722 if (!qtest_driver() && shutdown_signal
) {
1723 if (shutdown_pid
== 0) {
1724 /* This happens for eg ^C at the terminal, so it's worth
1725 * avoiding printing an odd message in that case.
1727 error_report("terminating on signal %d", shutdown_signal
);
1729 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1731 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1732 shutdown_signal
, shutdown_pid
,
1733 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1734 g_free(shutdown_cmd
);
1736 shutdown_signal
= 0;
1740 static ShutdownCause
qemu_reset_requested(void)
1742 ShutdownCause r
= reset_requested
;
1744 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1745 reset_requested
= SHUTDOWN_CAUSE_NONE
;
1748 return SHUTDOWN_CAUSE_NONE
;
1751 static int qemu_suspend_requested(void)
1753 int r
= suspend_requested
;
1754 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1755 suspend_requested
= 0;
1761 static WakeupReason
qemu_wakeup_requested(void)
1763 return wakeup_reason
;
1766 static int qemu_powerdown_requested(void)
1768 int r
= powerdown_requested
;
1769 powerdown_requested
= 0;
1773 static int qemu_debug_requested(void)
1775 int r
= debug_requested
;
1776 debug_requested
= 0;
1781 * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE.
1783 void qemu_system_reset(ShutdownCause reason
)
1787 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1789 cpu_synchronize_all_states();
1791 if (mc
&& mc
->reset
) {
1794 qemu_devices_reset();
1797 qapi_event_send_reset(shutdown_caused_by_guest(reason
),
1800 cpu_synchronize_all_post_reset();
1803 void qemu_system_guest_panicked(GuestPanicInformation
*info
)
1805 qemu_log_mask(LOG_GUEST_ERROR
, "Guest crashed\n");
1808 current_cpu
->crash_occurred
= true;
1810 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
,
1811 !!info
, info
, &error_abort
);
1812 vm_stop(RUN_STATE_GUEST_PANICKED
);
1814 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1815 !!info
, info
, &error_abort
);
1816 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC
);
1820 if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_HYPER_V
) {
1821 qemu_log_mask(LOG_GUEST_ERROR
, "HV crash parameters: (%#"PRIx64
1822 " %#"PRIx64
" %#"PRIx64
" %#"PRIx64
" %#"PRIx64
")\n",
1823 info
->u
.hyper_v
.arg1
,
1824 info
->u
.hyper_v
.arg2
,
1825 info
->u
.hyper_v
.arg3
,
1826 info
->u
.hyper_v
.arg4
,
1827 info
->u
.hyper_v
.arg5
);
1829 qapi_free_GuestPanicInformation(info
);
1833 void qemu_system_reset_request(ShutdownCause reason
)
1836 shutdown_requested
= reason
;
1838 reset_requested
= reason
;
1841 qemu_notify_event();
1844 static void qemu_system_suspend(void)
1847 notifier_list_notify(&suspend_notifiers
, NULL
);
1848 runstate_set(RUN_STATE_SUSPENDED
);
1849 qapi_event_send_suspend(&error_abort
);
1852 void qemu_system_suspend_request(void)
1854 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1857 suspend_requested
= 1;
1859 qemu_notify_event();
1862 void qemu_register_suspend_notifier(Notifier
*notifier
)
1864 notifier_list_add(&suspend_notifiers
, notifier
);
1867 void qemu_system_wakeup_request(WakeupReason reason
)
1869 trace_system_wakeup_request(reason
);
1871 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1874 if (!(wakeup_reason_mask
& (1 << reason
))) {
1877 runstate_set(RUN_STATE_RUNNING
);
1878 wakeup_reason
= reason
;
1879 qemu_notify_event();
1882 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1885 wakeup_reason_mask
|= (1 << reason
);
1887 wakeup_reason_mask
&= ~(1 << reason
);
1891 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1893 notifier_list_add(&wakeup_notifiers
, notifier
);
1896 void qemu_system_killed(int signal
, pid_t pid
)
1898 shutdown_signal
= signal
;
1902 /* Cannot call qemu_system_shutdown_request directly because
1903 * we are in a signal handler.
1905 shutdown_requested
= SHUTDOWN_CAUSE_HOST_SIGNAL
;
1906 qemu_notify_event();
1909 void qemu_system_shutdown_request(ShutdownCause reason
)
1911 trace_qemu_system_shutdown_request(reason
);
1912 replay_shutdown_request(reason
);
1913 shutdown_requested
= reason
;
1914 qemu_notify_event();
1917 static void qemu_system_powerdown(void)
1919 qapi_event_send_powerdown(&error_abort
);
1920 notifier_list_notify(&powerdown_notifiers
, NULL
);
1923 void qemu_system_powerdown_request(void)
1925 trace_qemu_system_powerdown_request();
1926 powerdown_requested
= 1;
1927 qemu_notify_event();
1930 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1932 notifier_list_add(&powerdown_notifiers
, notifier
);
1935 void qemu_system_debug_request(void)
1937 debug_requested
= 1;
1938 qemu_notify_event();
1941 static bool main_loop_should_exit(void)
1944 ShutdownCause request
;
1946 if (qemu_debug_requested()) {
1947 vm_stop(RUN_STATE_DEBUG
);
1949 if (qemu_suspend_requested()) {
1950 qemu_system_suspend();
1952 request
= qemu_shutdown_requested();
1955 qapi_event_send_shutdown(shutdown_caused_by_guest(request
),
1958 vm_stop(RUN_STATE_SHUTDOWN
);
1963 request
= qemu_reset_requested();
1966 qemu_system_reset(request
);
1968 if (!runstate_check(RUN_STATE_RUNNING
) &&
1969 !runstate_check(RUN_STATE_INMIGRATE
)) {
1970 runstate_set(RUN_STATE_PRELAUNCH
);
1973 if (qemu_wakeup_requested()) {
1975 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
1976 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1977 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1979 qapi_event_send_wakeup(&error_abort
);
1981 if (qemu_powerdown_requested()) {
1982 qemu_system_powerdown();
1984 if (qemu_vmstop_requested(&r
)) {
1990 static void main_loop(void)
1992 #ifdef CONFIG_PROFILER
1996 #ifdef CONFIG_PROFILER
1997 ti
= profile_getclock();
1999 main_loop_wait(false);
2000 #ifdef CONFIG_PROFILER
2001 dev_time
+= profile_getclock() - ti
;
2003 } while (!main_loop_should_exit());
2006 static void version(void)
2008 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
2009 QEMU_COPYRIGHT
"\n");
2012 static void help(int exitcode
)
2015 printf("usage: %s [options] [disk_image]\n\n"
2016 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
2017 error_get_progname());
2019 #define QEMU_OPTIONS_GENERATE_HELP
2020 #include "qemu-options-wrapper.h"
2022 printf("\nDuring emulation, the following keys are useful:\n"
2023 "ctrl-alt-f toggle full screen\n"
2024 "ctrl-alt-n switch to virtual console 'n'\n"
2025 "ctrl-alt toggle mouse and keyboard grab\n"
2027 "When using -nographic, press 'ctrl-a h' to get some help.\n"
2029 QEMU_HELP_BOTTOM
"\n");
2034 #define HAS_ARG 0x0001
2036 typedef struct QEMUOption
{
2043 static const QEMUOption qemu_options
[] = {
2044 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
2045 #define QEMU_OPTIONS_GENERATE_OPTIONS
2046 #include "qemu-options-wrapper.h"
2050 typedef struct VGAInterfaceInfo
{
2051 const char *opt_name
; /* option name */
2052 const char *name
; /* human-readable name */
2053 /* Class names indicating that support is available.
2054 * If no class is specified, the interface is always available */
2055 const char *class_names
[2];
2058 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
2064 .name
= "standard VGA",
2065 .class_names
= { "VGA", "isa-vga" },
2068 .opt_name
= "cirrus",
2069 .name
= "Cirrus VGA",
2070 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
2073 .opt_name
= "vmware",
2074 .name
= "VMWare SVGA",
2075 .class_names
= { "vmware-svga" },
2078 .opt_name
= "virtio",
2079 .name
= "Virtio VGA",
2080 .class_names
= { "virtio-vga" },
2085 .class_names
= { "qxl-vga" },
2089 .name
= "TCX framebuffer",
2090 .class_names
= { "SUNW,tcx" },
2094 .name
= "CG3 framebuffer",
2095 .class_names
= { "cgthree" },
2098 .opt_name
= "xenfb",
2102 static bool vga_interface_available(VGAInterfaceType t
)
2104 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2106 assert(t
< VGA_TYPE_MAX
);
2107 return !ti
->class_names
[0] ||
2108 object_class_by_name(ti
->class_names
[0]) ||
2109 object_class_by_name(ti
->class_names
[1]);
2112 static void select_vgahw(const char *p
)
2117 assert(vga_interface_type
== VGA_NONE
);
2118 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2119 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2120 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2121 if (!vga_interface_available(t
)) {
2122 error_report("%s not available", ti
->name
);
2125 vga_interface_type
= t
;
2129 if (t
== VGA_TYPE_MAX
) {
2131 error_report("unknown vga type: %s", p
);
2135 const char *nextopt
;
2137 if (strstart(opts
, ",retrace=", &nextopt
)) {
2139 if (strstart(opts
, "dumb", &nextopt
))
2140 vga_retrace_method
= VGA_RETRACE_DUMB
;
2141 else if (strstart(opts
, "precise", &nextopt
))
2142 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2143 else goto invalid_vga
;
2144 } else goto invalid_vga
;
2149 typedef enum DisplayType
{
2159 static DisplayType
select_display(const char *p
)
2162 DisplayType display
= DT_DEFAULT
;
2164 if (strstart(p
, "sdl", &opts
)) {
2168 const char *nextopt
;
2170 if (strstart(opts
, ",frame=", &nextopt
)) {
2172 if (strstart(opts
, "on", &nextopt
)) {
2174 } else if (strstart(opts
, "off", &nextopt
)) {
2177 goto invalid_sdl_args
;
2179 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2181 if (strstart(opts
, "on", &nextopt
)) {
2183 } else if (strstart(opts
, "off", &nextopt
)) {
2186 goto invalid_sdl_args
;
2188 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2190 if (strstart(opts
, "on", &nextopt
)) {
2192 } else if (strstart(opts
, "off", &nextopt
)) {
2195 goto invalid_sdl_args
;
2197 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2199 if (strstart(opts
, "on", &nextopt
)) {
2201 } else if (strstart(opts
, "off", &nextopt
)) {
2204 goto invalid_sdl_args
;
2206 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2208 if (strstart(opts
, "on", &nextopt
)) {
2210 } else if (strstart(opts
, "off", &nextopt
)) {
2213 goto invalid_sdl_args
;
2217 error_report("invalid SDL option string");
2223 error_report("SDL support is disabled");
2226 } else if (strstart(p
, "vnc", &opts
)) {
2228 vnc_parse(opts
+ 1, &error_fatal
);
2230 error_report("VNC requires a display argument vnc=<display>");
2233 } else if (strstart(p
, "egl-headless", &opts
)) {
2234 #ifdef CONFIG_OPENGL_DMABUF
2239 fprintf(stderr
, "egl support is disabled\n");
2242 } else if (strstart(p
, "curses", &opts
)) {
2243 #ifdef CONFIG_CURSES
2244 display
= DT_CURSES
;
2246 error_report("curses support is disabled");
2249 } else if (strstart(p
, "gtk", &opts
)) {
2253 const char *nextopt
;
2255 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2257 if (strstart(opts
, "on", &nextopt
)) {
2258 grab_on_hover
= true;
2259 } else if (strstart(opts
, "off", &nextopt
)) {
2260 grab_on_hover
= false;
2262 goto invalid_gtk_args
;
2264 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2266 if (strstart(opts
, "on", &nextopt
)) {
2268 } else if (strstart(opts
, "off", &nextopt
)) {
2271 goto invalid_gtk_args
;
2275 error_report("invalid GTK option string");
2281 error_report("GTK support is disabled");
2284 } else if (strstart(p
, "none", &opts
)) {
2287 error_report("unknown display type");
2294 static int balloon_parse(const char *arg
)
2298 if (strcmp(arg
, "none") == 0) {
2302 if (!strncmp(arg
, "virtio", 6)) {
2303 if (arg
[6] == ',') {
2304 /* have params -> parse them */
2305 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2310 /* create empty opts */
2311 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2314 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2321 char *qemu_find_file(int type
, const char *name
)
2327 /* Try the name as a straight path first */
2328 if (access(name
, R_OK
) == 0) {
2329 trace_load_file(name
, name
);
2330 return g_strdup(name
);
2334 case QEMU_FILE_TYPE_BIOS
:
2337 case QEMU_FILE_TYPE_KEYMAP
:
2338 subdir
= "keymaps/";
2344 for (i
= 0; i
< data_dir_idx
; i
++) {
2345 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2346 if (access(buf
, R_OK
) == 0) {
2347 trace_load_file(name
, buf
);
2355 static inline bool nonempty_str(const char *str
)
2360 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2364 const char *name
, *file
, *str
;
2365 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2367 if (fw_cfg
== NULL
) {
2368 error_report("fw_cfg device not available");
2371 name
= qemu_opt_get(opts
, "name");
2372 file
= qemu_opt_get(opts
, "file");
2373 str
= qemu_opt_get(opts
, "string");
2375 /* we need name and either a file or the content string */
2376 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2377 error_report("invalid argument(s)");
2380 if (nonempty_str(file
) && nonempty_str(str
)) {
2381 error_report("file and string are mutually exclusive");
2384 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2385 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2388 if (strncmp(name
, "opt/", 4) != 0) {
2389 warn_report("externally provided fw_cfg item names "
2390 "should be prefixed with \"opt/\"");
2392 if (nonempty_str(str
)) {
2393 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2394 buf
= g_memdup(str
, size
);
2396 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2397 error_report("can't load %s", file
);
2401 /* For legacy, keep user files in a specific global order. */
2402 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2403 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2404 fw_cfg_reset_order_override(fw_cfg
);
2408 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2410 return qdev_device_help(opts
);
2413 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2418 dev
= qdev_device_add(opts
, &err
);
2420 error_report_err(err
);
2423 object_unref(OBJECT(dev
));
2427 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2429 Error
*local_err
= NULL
;
2431 if (!qemu_chr_new_from_opts(opts
, &local_err
)) {
2433 error_report_err(local_err
);
2441 #ifdef CONFIG_VIRTFS
2442 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2444 return qemu_fsdev_add(opts
);
2448 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2451 const char *chardev
;
2455 mode
= qemu_opt_get(opts
, "mode");
2459 if (strcmp(mode
, "readline") == 0) {
2460 flags
= MONITOR_USE_READLINE
;
2461 } else if (strcmp(mode
, "control") == 0) {
2462 flags
= MONITOR_USE_CONTROL
;
2464 error_report("unknown monitor mode \"%s\"", mode
);
2468 if (qemu_opt_get_bool(opts
, "pretty", 0))
2469 flags
|= MONITOR_USE_PRETTY
;
2471 if (qemu_opt_get_bool(opts
, "default", 0)) {
2472 error_report("option 'default' does nothing and is deprecated");
2475 chardev
= qemu_opt_get(opts
, "chardev");
2476 chr
= qemu_chr_find(chardev
);
2478 error_report("chardev \"%s\" not found", chardev
);
2482 monitor_init(chr
, flags
);
2486 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2488 static int monitor_device_index
= 0;
2493 if (strstart(optarg
, "chardev:", &p
)) {
2494 snprintf(label
, sizeof(label
), "%s", p
);
2496 snprintf(label
, sizeof(label
), "compat_monitor%d",
2497 monitor_device_index
);
2498 opts
= qemu_chr_parse_compat(label
, optarg
);
2500 error_report("parse error: %s", optarg
);
2505 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2506 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2507 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2508 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2509 monitor_device_index
++;
2512 struct device_config
{
2514 DEV_USB
, /* -usbdevice */
2516 DEV_SERIAL
, /* -serial */
2517 DEV_PARALLEL
, /* -parallel */
2518 DEV_VIRTCON
, /* -virtioconsole */
2519 DEV_DEBUGCON
, /* -debugcon */
2520 DEV_GDB
, /* -gdb, -s */
2521 DEV_SCLP
, /* s390 sclp */
2523 const char *cmdline
;
2525 QTAILQ_ENTRY(device_config
) next
;
2528 static QTAILQ_HEAD(, device_config
) device_configs
=
2529 QTAILQ_HEAD_INITIALIZER(device_configs
);
2531 static void add_device_config(int type
, const char *cmdline
)
2533 struct device_config
*conf
;
2535 conf
= g_malloc0(sizeof(*conf
));
2537 conf
->cmdline
= cmdline
;
2538 loc_save(&conf
->loc
);
2539 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2542 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2544 struct device_config
*conf
;
2547 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2548 if (conf
->type
!= type
)
2550 loc_push_restore(&conf
->loc
);
2551 rc
= func(conf
->cmdline
);
2552 loc_pop(&conf
->loc
);
2560 static int serial_parse(const char *devname
)
2562 static int index
= 0;
2565 if (strcmp(devname
, "none") == 0)
2567 if (index
== MAX_SERIAL_PORTS
) {
2568 error_report("too many serial ports");
2571 snprintf(label
, sizeof(label
), "serial%d", index
);
2572 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2573 if (!serial_hds
[index
]) {
2574 error_report("could not connect serial device"
2575 " to character backend '%s'", devname
);
2582 static int parallel_parse(const char *devname
)
2584 static int index
= 0;
2587 if (strcmp(devname
, "none") == 0)
2589 if (index
== MAX_PARALLEL_PORTS
) {
2590 error_report("too many parallel ports");
2593 snprintf(label
, sizeof(label
), "parallel%d", index
);
2594 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2595 if (!parallel_hds
[index
]) {
2596 error_report("could not connect parallel device"
2597 " to character backend '%s'", devname
);
2604 static int virtcon_parse(const char *devname
)
2606 QemuOptsList
*device
= qemu_find_opts("device");
2607 static int index
= 0;
2609 QemuOpts
*bus_opts
, *dev_opts
;
2611 if (strcmp(devname
, "none") == 0)
2613 if (index
== MAX_VIRTIO_CONSOLES
) {
2614 error_report("too many virtio consoles");
2618 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2619 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2621 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2622 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2624 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2625 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2626 if (!virtcon_hds
[index
]) {
2627 error_report("could not connect virtio console"
2628 " to character backend '%s'", devname
);
2631 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2637 static int sclp_parse(const char *devname
)
2639 QemuOptsList
*device
= qemu_find_opts("device");
2640 static int index
= 0;
2644 if (strcmp(devname
, "none") == 0) {
2647 if (index
== MAX_SCLP_CONSOLES
) {
2648 error_report("too many sclp consoles");
2652 assert(arch_type
== QEMU_ARCH_S390X
);
2654 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2655 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2657 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2658 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2659 if (!sclp_hds
[index
]) {
2660 error_report("could not connect sclp console"
2661 " to character backend '%s'", devname
);
2664 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2670 static int debugcon_parse(const char *devname
)
2674 if (!qemu_chr_new("debugcon", devname
)) {
2677 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2679 error_report("already have a debugcon device");
2682 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2683 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2687 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2689 const MachineClass
*mc1
= a
, *mc2
= b
;
2692 if (mc1
->family
== NULL
) {
2693 if (mc2
->family
== NULL
) {
2694 /* Compare standalone machine types against each other; they sort
2695 * in increasing order.
2697 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2698 object_class_get_name(OBJECT_CLASS(mc2
)));
2701 /* Standalone machine types sort after families. */
2705 if (mc2
->family
== NULL
) {
2706 /* Families sort before standalone machine types. */
2710 /* Families sort between each other alphabetically increasingly. */
2711 res
= strcmp(mc1
->family
, mc2
->family
);
2716 /* Within the same family, machine types sort in decreasing order. */
2717 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2718 object_class_get_name(OBJECT_CLASS(mc1
)));
2721 static MachineClass
*machine_parse(const char *name
)
2723 MachineClass
*mc
= NULL
;
2724 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2727 mc
= find_machine(name
);
2730 g_slist_free(machines
);
2733 if (name
&& !is_help_option(name
)) {
2734 error_report("unsupported machine type");
2735 error_printf("Use -machine help to list supported machines\n");
2737 printf("Supported machines are:\n");
2738 machines
= g_slist_sort(machines
, machine_class_cmp
);
2739 for (el
= machines
; el
; el
= el
->next
) {
2740 MachineClass
*mc
= el
->data
;
2742 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2744 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2745 mc
->is_default
? " (default)" : "");
2749 g_slist_free(machines
);
2750 exit(!name
|| !is_help_option(name
));
2753 void qemu_add_exit_notifier(Notifier
*notify
)
2755 notifier_list_add(&exit_notifiers
, notify
);
2758 void qemu_remove_exit_notifier(Notifier
*notify
)
2760 notifier_remove(notify
);
2763 static void qemu_run_exit_notifiers(void)
2765 notifier_list_notify(&exit_notifiers
, NULL
);
2768 static bool machine_init_done
;
2770 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2772 notifier_list_add(&machine_init_done_notifiers
, notify
);
2773 if (machine_init_done
) {
2774 notify
->notify(notify
, NULL
);
2778 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2780 notifier_remove(notify
);
2783 static void qemu_run_machine_init_done_notifiers(void)
2785 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2786 machine_init_done
= true;
2789 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2790 const char **poptarg
, int *poptind
)
2792 const QEMUOption
*popt
;
2793 int optind
= *poptind
;
2794 char *r
= argv
[optind
];
2797 loc_set_cmdline(argv
, optind
, 1);
2799 /* Treat --foo the same as -foo. */
2802 popt
= qemu_options
;
2805 error_report("invalid option");
2808 if (!strcmp(popt
->name
, r
+ 1))
2812 if (popt
->flags
& HAS_ARG
) {
2813 if (optind
>= argc
) {
2814 error_report("requires an argument");
2817 optarg
= argv
[optind
++];
2818 loc_set_cmdline(argv
, optind
- 2, 2);
2829 static MachineClass
*select_machine(void)
2831 MachineClass
*machine_class
= find_default_machine();
2836 loc_push_none(&loc
);
2838 opts
= qemu_get_machine_opts();
2839 qemu_opts_loc_restore(opts
);
2841 optarg
= qemu_opt_get(opts
, "type");
2843 machine_class
= machine_parse(optarg
);
2846 if (!machine_class
) {
2847 error_report("No machine specified, and there is no default");
2848 error_printf("Use -machine help to list supported machines\n");
2853 return machine_class
;
2856 static int machine_set_property(void *opaque
,
2857 const char *name
, const char *value
,
2860 Object
*obj
= OBJECT(opaque
);
2861 Error
*local_err
= NULL
;
2864 if (strcmp(name
, "type") == 0) {
2868 qom_name
= g_strdup(name
);
2869 for (p
= qom_name
; *p
; p
++) {
2875 object_property_parse(obj
, value
, qom_name
, &local_err
);
2879 error_report_err(local_err
);
2888 * Initial object creation happens before all other
2889 * QEMU data types are created. The majority of objects
2890 * can be created at this point. The rng-egd object
2891 * cannot be created here, as it depends on the chardev
2894 static bool object_create_initial(const char *type
)
2896 if (g_str_equal(type
, "rng-egd") ||
2897 g_str_has_prefix(type
, "pr-manager-")) {
2902 * return false for concrete netfilters since
2903 * they depend on netdevs already existing
2905 if (g_str_equal(type
, "filter-buffer") ||
2906 g_str_equal(type
, "filter-dump") ||
2907 g_str_equal(type
, "filter-mirror") ||
2908 g_str_equal(type
, "filter-redirector") ||
2909 g_str_equal(type
, "colo-compare") ||
2910 g_str_equal(type
, "filter-rewriter") ||
2911 g_str_equal(type
, "filter-replay")) {
2915 /* Memory allocation by backends needs to be done
2916 * after configure_accelerator() (due to the tcg_enabled()
2917 * checks at memory_region_init_*()).
2919 * Also, allocation of large amounts of memory may delay
2920 * chardev initialization for too long, and trigger timeouts
2921 * on software that waits for a monitor socket to be created
2924 if (g_str_has_prefix(type
, "memory-backend-")) {
2933 * The remainder of object creation happens after the
2934 * creation of chardev, fsdev, net clients and device data types.
2936 static bool object_create_delayed(const char *type
)
2938 return !object_create_initial(type
);
2942 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2946 const char *mem_str
;
2947 const char *maxmem_str
, *slots_str
;
2948 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2949 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2952 loc_push_none(&loc
);
2953 qemu_opts_loc_restore(opts
);
2956 mem_str
= qemu_opt_get(opts
, "size");
2959 error_report("missing 'size' option value");
2963 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2965 /* Fix up legacy suffix-less format */
2966 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2967 uint64_t overflow_check
= sz
;
2970 if ((sz
>> 20) != overflow_check
) {
2971 error_report("too large 'size' option value");
2977 /* backward compatibility behaviour for case "-m 0" */
2979 sz
= default_ram_size
;
2982 sz
= QEMU_ALIGN_UP(sz
, 8192);
2984 if (ram_size
!= sz
) {
2985 error_report("ram size too large");
2989 /* store value for the future use */
2990 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2991 *maxram_size
= ram_size
;
2993 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2994 slots_str
= qemu_opt_get(opts
, "slots");
2995 if (maxmem_str
&& slots_str
) {
2998 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2999 slots
= qemu_opt_get_number(opts
, "slots", 0);
3000 if (sz
< ram_size
) {
3001 error_report("invalid value of -m option maxmem: "
3002 "maximum memory size (0x%" PRIx64
") must be at least "
3003 "the initial memory size (0x" RAM_ADDR_FMT
")",
3006 } else if (sz
> ram_size
) {
3008 error_report("invalid value of -m option: maxmem was "
3009 "specified, but no hotplug slots were specified");
3013 error_report("invalid value of -m option maxmem: "
3014 "memory slots were specified but maximum memory size "
3015 "(0x%" PRIx64
") is equal to the initial memory size "
3016 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
3022 } else if ((!maxmem_str
&& slots_str
) ||
3023 (maxmem_str
&& !slots_str
)) {
3024 error_report("invalid -m option value: missing "
3025 "'%s' option", slots_str
? "maxmem" : "slots");
3032 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
3036 g
= g_malloc0(sizeof(*g
));
3037 g
->driver
= qemu_opt_get(opts
, "driver");
3038 g
->property
= qemu_opt_get(opts
, "property");
3039 g
->value
= qemu_opt_get(opts
, "value");
3040 g
->user_provided
= true;
3041 g
->errp
= &error_fatal
;
3042 qdev_prop_register_global(g
);
3046 static int qemu_read_default_config_file(void)
3050 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
3051 if (ret
< 0 && ret
!= -ENOENT
) {
3058 static void user_register_global_props(void)
3060 qemu_opts_foreach(qemu_find_opts("global"),
3061 global_init_func
, NULL
, NULL
);
3065 * Note: we should see that these properties are actually having a
3066 * priority: accel < machine < user. This means e.g. when user
3067 * specifies something in "-global", it'll always be used with highest
3068 * priority than either machine/accelerator compat properties.
3070 static void register_global_properties(MachineState
*ms
)
3072 accel_register_compat_props(ms
->accelerator
);
3073 machine_register_compat_props(ms
);
3074 user_register_global_props();
3077 int main(int argc
, char **argv
, char **envp
)
3080 int snapshot
, linux_boot
;
3081 const char *initrd_filename
;
3082 const char *kernel_filename
, *kernel_cmdline
;
3083 const char *boot_order
= NULL
;
3084 const char *boot_once
= NULL
;
3086 int cyls
, heads
, secs
, translation
;
3087 QemuOpts
*opts
, *machine_opts
;
3088 QemuOpts
*hda_opts
= NULL
, *icount_opts
= NULL
, *accel_opts
= NULL
;
3089 QemuOptsList
*olist
;
3092 const char *loadvm
= NULL
;
3093 MachineClass
*machine_class
;
3094 const char *cpu_model
;
3095 const char *vga_model
= NULL
;
3096 const char *qtest_chrdev
= NULL
;
3097 const char *qtest_log
= NULL
;
3098 const char *pid_file
= NULL
;
3099 const char *incoming
= NULL
;
3100 bool defconfig
= true;
3101 bool userconfig
= true;
3102 bool nographic
= false;
3103 DisplayType display_type
= DT_DEFAULT
;
3104 int display_remote
= 0;
3105 const char *log_mask
= NULL
;
3106 const char *log_file
= NULL
;
3107 char *trace_file
= NULL
;
3108 ram_addr_t maxram_size
;
3109 uint64_t ram_slots
= 0;
3110 FILE *vmstate_dump_file
= NULL
;
3111 Error
*main_loop_err
= NULL
;
3113 bool list_data_dirs
= false;
3114 typedef struct BlockdevOptions_queue
{
3115 BlockdevOptions
*bdo
;
3117 QSIMPLEQ_ENTRY(BlockdevOptions_queue
) entry
;
3118 } BlockdevOptions_queue
;
3119 QSIMPLEQ_HEAD(, BlockdevOptions_queue
) bdo_queue
3120 = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
3122 module_call_init(MODULE_INIT_TRACE
);
3124 qemu_init_cpu_list();
3125 qemu_init_cpu_loop();
3126 qemu_mutex_lock_iothread();
3128 atexit(qemu_run_exit_notifiers
);
3129 error_set_progname(argv
[0]);
3130 qemu_init_exec_dir(argv
[0]);
3132 module_call_init(MODULE_INIT_QOM
);
3133 monitor_init_qmp_commands();
3135 qemu_add_opts(&qemu_drive_opts
);
3136 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3137 qemu_add_drive_opts(&qemu_common_drive_opts
);
3138 qemu_add_drive_opts(&qemu_drive_opts
);
3139 qemu_add_drive_opts(&bdrv_runtime_opts
);
3140 qemu_add_opts(&qemu_chardev_opts
);
3141 qemu_add_opts(&qemu_device_opts
);
3142 qemu_add_opts(&qemu_netdev_opts
);
3143 qemu_add_opts(&qemu_net_opts
);
3144 qemu_add_opts(&qemu_rtc_opts
);
3145 qemu_add_opts(&qemu_global_opts
);
3146 qemu_add_opts(&qemu_mon_opts
);
3147 qemu_add_opts(&qemu_trace_opts
);
3148 qemu_add_opts(&qemu_option_rom_opts
);
3149 qemu_add_opts(&qemu_machine_opts
);
3150 qemu_add_opts(&qemu_accel_opts
);
3151 qemu_add_opts(&qemu_mem_opts
);
3152 qemu_add_opts(&qemu_smp_opts
);
3153 qemu_add_opts(&qemu_boot_opts
);
3154 qemu_add_opts(&qemu_sandbox_opts
);
3155 qemu_add_opts(&qemu_add_fd_opts
);
3156 qemu_add_opts(&qemu_object_opts
);
3157 qemu_add_opts(&qemu_tpmdev_opts
);
3158 qemu_add_opts(&qemu_realtime_opts
);
3159 qemu_add_opts(&qemu_msg_opts
);
3160 qemu_add_opts(&qemu_name_opts
);
3161 qemu_add_opts(&qemu_numa_opts
);
3162 qemu_add_opts(&qemu_icount_opts
);
3163 qemu_add_opts(&qemu_semihosting_config_opts
);
3164 qemu_add_opts(&qemu_fw_cfg_opts
);
3165 module_call_init(MODULE_INIT_OPTS
);
3169 if (qcrypto_init(&err
) < 0) {
3170 error_reportf_err(err
, "cannot initialize crypto: ");
3173 rtc_clock
= QEMU_CLOCK_HOST
;
3175 QLIST_INIT (&vm_change_state_head
);
3176 os_setup_early_signal_handling();
3180 cyls
= heads
= secs
= 0;
3181 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3185 bdrv_init_with_whitelist();
3189 /* first pass of option parsing */
3191 while (optind
< argc
) {
3192 if (argv
[optind
][0] != '-') {
3196 const QEMUOption
*popt
;
3198 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3199 switch (popt
->index
) {
3200 case QEMU_OPTION_nodefconfig
:
3203 case QEMU_OPTION_nouserconfig
:
3210 if (defconfig
&& userconfig
) {
3211 if (qemu_read_default_config_file() < 0) {
3216 /* second pass of option parsing */
3221 if (argv
[optind
][0] != '-') {
3222 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3224 const QEMUOption
*popt
;
3226 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3227 if (!(popt
->arch_mask
& arch_type
)) {
3228 error_report("Option not supported for this target");
3231 switch(popt
->index
) {
3232 case QEMU_OPTION_no_kvm_irqchip
: {
3233 olist
= qemu_find_opts("machine");
3234 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3237 case QEMU_OPTION_cpu
:
3238 /* hw initialization will check this */
3241 case QEMU_OPTION_hda
:
3245 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3247 snprintf(buf
, sizeof(buf
),
3248 "%s,cyls=%d,heads=%d,secs=%d%s",
3249 HD_OPTS
, cyls
, heads
, secs
,
3250 translation
== BIOS_ATA_TRANSLATION_LBA
?
3252 translation
== BIOS_ATA_TRANSLATION_NONE
?
3253 ",trans=none" : "");
3254 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3257 case QEMU_OPTION_hdb
:
3258 case QEMU_OPTION_hdc
:
3259 case QEMU_OPTION_hdd
:
3260 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3263 case QEMU_OPTION_blockdev
:
3266 BlockdevOptions_queue
*bdo
;
3268 v
= qobject_input_visitor_new_str(optarg
, "driver", &err
);
3270 error_report_err(err
);
3274 bdo
= g_new(BlockdevOptions_queue
, 1);
3275 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
3278 loc_save(&bdo
->loc
);
3279 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
3282 case QEMU_OPTION_drive
:
3283 if (drive_def(optarg
) == NULL
) {
3287 case QEMU_OPTION_set
:
3288 if (qemu_set_option(optarg
) != 0)
3291 case QEMU_OPTION_global
:
3292 if (qemu_global_option(optarg
) != 0)
3295 case QEMU_OPTION_mtdblock
:
3296 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3298 case QEMU_OPTION_sd
:
3299 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3301 case QEMU_OPTION_pflash
:
3302 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3304 case QEMU_OPTION_snapshot
:
3307 case QEMU_OPTION_hdachs
:
3311 cyls
= strtol(p
, (char **)&p
, 0);
3312 if (cyls
< 1 || cyls
> 16383)
3317 heads
= strtol(p
, (char **)&p
, 0);
3318 if (heads
< 1 || heads
> 16)
3323 secs
= strtol(p
, (char **)&p
, 0);
3324 if (secs
< 1 || secs
> 63)
3328 if (!strcmp(p
, "large")) {
3329 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3330 } else if (!strcmp(p
, "rechs")) {
3331 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3332 } else if (!strcmp(p
, "none")) {
3333 translation
= BIOS_ATA_TRANSLATION_NONE
;
3334 } else if (!strcmp(p
, "lba")) {
3335 translation
= BIOS_ATA_TRANSLATION_LBA
;
3336 } else if (!strcmp(p
, "auto")) {
3337 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3341 } else if (*p
!= '\0') {
3343 error_report("invalid physical CHS format");
3346 if (hda_opts
!= NULL
) {
3347 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3349 qemu_opt_set_number(hda_opts
, "heads", heads
,
3351 qemu_opt_set_number(hda_opts
, "secs", secs
,
3353 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3354 qemu_opt_set(hda_opts
, "trans", "large",
3356 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3357 qemu_opt_set(hda_opts
, "trans", "rechs",
3359 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3360 qemu_opt_set(hda_opts
, "trans", "lba",
3362 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3363 qemu_opt_set(hda_opts
, "trans", "none",
3368 error_report("'-hdachs' is deprecated, please use '-device"
3369 " ide-hd,cyls=c,heads=h,secs=s,...' instead");
3371 case QEMU_OPTION_numa
:
3372 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3378 case QEMU_OPTION_display
:
3379 display_type
= select_display(optarg
);
3381 case QEMU_OPTION_nographic
:
3382 olist
= qemu_find_opts("machine");
3383 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3385 display_type
= DT_NONE
;
3387 case QEMU_OPTION_curses
:
3388 #ifdef CONFIG_CURSES
3389 display_type
= DT_CURSES
;
3391 error_report("curses support is disabled");
3395 case QEMU_OPTION_portrait
:
3396 graphic_rotate
= 90;
3398 case QEMU_OPTION_rotate
:
3399 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3400 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3401 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3402 error_report("only 90, 180, 270 deg rotation is available");
3406 case QEMU_OPTION_kernel
:
3407 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3410 case QEMU_OPTION_initrd
:
3411 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3414 case QEMU_OPTION_append
:
3415 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3418 case QEMU_OPTION_dtb
:
3419 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3422 case QEMU_OPTION_cdrom
:
3423 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3425 case QEMU_OPTION_boot
:
3426 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3432 case QEMU_OPTION_fda
:
3433 case QEMU_OPTION_fdb
:
3434 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3437 case QEMU_OPTION_no_fd_bootchk
:
3440 case QEMU_OPTION_netdev
:
3442 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3446 case QEMU_OPTION_net
:
3448 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3452 #ifdef CONFIG_LIBISCSI
3453 case QEMU_OPTION_iscsi
:
3454 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3462 case QEMU_OPTION_tftp
:
3463 error_report("The -tftp option is deprecated. "
3464 "Please use '-netdev user,tftp=...' instead.");
3465 legacy_tftp_prefix
= optarg
;
3467 case QEMU_OPTION_bootp
:
3468 error_report("The -bootp option is deprecated. "
3469 "Please use '-netdev user,bootfile=...' instead.");
3470 legacy_bootp_filename
= optarg
;
3472 case QEMU_OPTION_redir
:
3473 error_report("The -redir option is deprecated. "
3474 "Please use '-netdev user,hostfwd=...' instead.");
3475 if (net_slirp_redir(optarg
) < 0)
3479 case QEMU_OPTION_bt
:
3480 add_device_config(DEV_BT
, optarg
);
3482 case QEMU_OPTION_audio_help
:
3486 case QEMU_OPTION_soundhw
:
3487 select_soundhw (optarg
);
3492 case QEMU_OPTION_version
:
3497 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3504 case QEMU_OPTION_tpmdev
:
3505 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3510 case QEMU_OPTION_mempath
:
3513 case QEMU_OPTION_mem_prealloc
:
3522 case QEMU_OPTION_DFILTER
:
3523 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3526 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3528 case QEMU_OPTION_gdb
:
3529 add_device_config(DEV_GDB
, optarg
);
3532 if (is_help_option(optarg
)) {
3533 list_data_dirs
= true;
3534 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3535 data_dir
[data_dir_idx
++] = optarg
;
3538 case QEMU_OPTION_bios
:
3539 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3542 case QEMU_OPTION_singlestep
:
3549 keyboard_layout
= optarg
;
3551 case QEMU_OPTION_localtime
:
3554 case QEMU_OPTION_vga
:
3563 w
= strtol(p
, (char **)&p
, 10);
3566 error_report("invalid resolution or depth");
3572 h
= strtol(p
, (char **)&p
, 10);
3577 depth
= strtol(p
, (char **)&p
, 10);
3578 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3579 depth
!= 24 && depth
!= 32)
3581 } else if (*p
== '\0') {
3582 depth
= graphic_depth
;
3589 graphic_depth
= depth
;
3592 case QEMU_OPTION_echr
:
3595 term_escape_char
= strtol(optarg
, &r
, 0);
3597 printf("Bad argument to echr\n");
3600 case QEMU_OPTION_monitor
:
3601 default_monitor
= 0;
3602 if (strncmp(optarg
, "none", 4)) {
3603 monitor_parse(optarg
, "readline", false);
3606 case QEMU_OPTION_qmp
:
3607 monitor_parse(optarg
, "control", false);
3608 default_monitor
= 0;
3610 case QEMU_OPTION_qmp_pretty
:
3611 monitor_parse(optarg
, "control", true);
3612 default_monitor
= 0;
3614 case QEMU_OPTION_mon
:
3615 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3620 default_monitor
= 0;
3622 case QEMU_OPTION_chardev
:
3623 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3629 case QEMU_OPTION_fsdev
:
3630 olist
= qemu_find_opts("fsdev");
3632 error_report("fsdev support is disabled");
3635 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3640 case QEMU_OPTION_virtfs
: {
3643 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
;
3645 olist
= qemu_find_opts("virtfs");
3647 error_report("virtfs support is disabled");
3650 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3655 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3656 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3657 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3660 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3661 qemu_opts_id(opts
) ?:
3662 qemu_opt_get(opts
, "mount_tag"),
3665 error_report("duplicate or invalid fsdev id: %s",
3666 qemu_opt_get(opts
, "mount_tag"));
3670 writeout
= qemu_opt_get(opts
, "writeout");
3672 #ifdef CONFIG_SYNC_FILE_RANGE
3673 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3675 error_report("writeout=immediate not supported "
3676 "on this platform");
3680 qemu_opt_set(fsdev
, "fsdriver",
3681 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3682 path
= qemu_opt_get(opts
, "path");
3684 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3686 security_model
= qemu_opt_get(opts
, "security_model");
3687 if (security_model
) {
3688 qemu_opt_set(fsdev
, "security_model", security_model
,
3691 socket
= qemu_opt_get(opts
, "socket");
3693 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3695 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3697 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3700 qemu_opt_set_bool(fsdev
, "readonly",
3701 qemu_opt_get_bool(opts
, "readonly", 0),
3703 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3705 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3706 qemu_opt_set(device
, "fsdev",
3707 qemu_opts_id(fsdev
), &error_abort
);
3708 qemu_opt_set(device
, "mount_tag",
3709 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3712 case QEMU_OPTION_virtfs_synth
: {
3716 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3719 error_report("duplicate option: %s", "virtfs_synth");
3722 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3724 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3726 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3727 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3728 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3731 case QEMU_OPTION_serial
:
3732 add_device_config(DEV_SERIAL
, optarg
);
3734 if (strncmp(optarg
, "mon:", 4) == 0) {
3735 default_monitor
= 0;
3738 case QEMU_OPTION_watchdog
:
3740 error_report("only one watchdog option may be given");
3745 case QEMU_OPTION_watchdog_action
:
3746 if (select_watchdog_action(optarg
) == -1) {
3747 error_report("unknown -watchdog-action parameter");
3751 case QEMU_OPTION_virtiocon
:
3752 add_device_config(DEV_VIRTCON
, optarg
);
3753 default_virtcon
= 0;
3754 if (strncmp(optarg
, "mon:", 4) == 0) {
3755 default_monitor
= 0;
3758 case QEMU_OPTION_parallel
:
3759 add_device_config(DEV_PARALLEL
, optarg
);
3760 default_parallel
= 0;
3761 if (strncmp(optarg
, "mon:", 4) == 0) {
3762 default_monitor
= 0;
3765 case QEMU_OPTION_debugcon
:
3766 add_device_config(DEV_DEBUGCON
, optarg
);
3768 case QEMU_OPTION_loadvm
:
3771 case QEMU_OPTION_full_screen
:
3774 case QEMU_OPTION_no_frame
:
3777 case QEMU_OPTION_alt_grab
:
3780 case QEMU_OPTION_ctrl_grab
:
3783 case QEMU_OPTION_no_quit
:
3786 case QEMU_OPTION_sdl
:
3788 display_type
= DT_SDL
;
3791 error_report("SDL support is disabled");
3794 case QEMU_OPTION_pidfile
:
3797 case QEMU_OPTION_win2k_hack
:
3798 win2k_install_hack
= 1;
3800 case QEMU_OPTION_rtc_td_hack
: {
3801 static GlobalProperty slew_lost_ticks
= {
3802 .driver
= "mc146818rtc",
3803 .property
= "lost_tick_policy",
3807 qdev_prop_register_global(&slew_lost_ticks
);
3810 case QEMU_OPTION_acpitable
:
3811 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3816 acpi_table_add(opts
, &error_fatal
);
3818 case QEMU_OPTION_smbios
:
3819 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3824 smbios_entry_add(opts
, &error_fatal
);
3826 case QEMU_OPTION_fwcfg
:
3827 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3833 case QEMU_OPTION_enable_kvm
:
3834 olist
= qemu_find_opts("machine");
3835 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3837 case QEMU_OPTION_enable_hax
:
3838 olist
= qemu_find_opts("machine");
3839 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3842 case QEMU_OPTION_machine
:
3843 olist
= qemu_find_opts("machine");
3844 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3849 case QEMU_OPTION_no_kvm
:
3850 olist
= qemu_find_opts("machine");
3851 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3853 case QEMU_OPTION_no_kvm_pit
: {
3854 warn_report("ignoring deprecated option");
3857 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3858 static GlobalProperty kvm_pit_lost_tick_policy
= {
3859 .driver
= "kvm-pit",
3860 .property
= "lost_tick_policy",
3864 warn_report("deprecated, replaced by "
3865 "-global kvm-pit.lost_tick_policy=discard");
3866 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3869 case QEMU_OPTION_accel
:
3870 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3872 optarg
= qemu_opt_get(accel_opts
, "accel");
3873 if (!optarg
|| is_help_option(optarg
)) {
3874 error_printf("Possible accelerators: kvm, xen, hax, tcg\n");
3877 opts
= qemu_opts_create(qemu_find_opts("machine"), NULL
,
3878 false, &error_abort
);
3879 qemu_opt_set(opts
, "accel", optarg
, &error_abort
);
3881 case QEMU_OPTION_usb
:
3882 olist
= qemu_find_opts("machine");
3883 qemu_opts_parse_noisily(olist
, "usb=on", false);
3885 case QEMU_OPTION_usbdevice
:
3886 error_report("'-usbdevice' is deprecated, please use "
3887 "'-device usb-...' instead");
3888 olist
= qemu_find_opts("machine");
3889 qemu_opts_parse_noisily(olist
, "usb=on", false);
3890 add_device_config(DEV_USB
, optarg
);
3892 case QEMU_OPTION_device
:
3893 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3898 case QEMU_OPTION_smp
:
3899 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3904 case QEMU_OPTION_vnc
:
3905 vnc_parse(optarg
, &error_fatal
);
3907 case QEMU_OPTION_no_acpi
:
3910 case QEMU_OPTION_no_hpet
:
3913 case QEMU_OPTION_balloon
:
3914 if (balloon_parse(optarg
) < 0) {
3915 error_report("unknown -balloon argument %s", optarg
);
3919 case QEMU_OPTION_no_reboot
:
3922 case QEMU_OPTION_no_shutdown
:
3925 case QEMU_OPTION_show_cursor
:
3928 case QEMU_OPTION_uuid
:
3929 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3930 error_report("failed to parse UUID string: wrong format");
3933 qemu_uuid_set
= true;
3935 case QEMU_OPTION_option_rom
:
3936 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3937 error_report("too many option ROMs");
3940 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3945 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3946 option_rom
[nb_option_roms
].bootindex
=
3947 qemu_opt_get_number(opts
, "bootindex", -1);
3948 if (!option_rom
[nb_option_roms
].name
) {
3949 error_report("Option ROM file is not specified");
3954 case QEMU_OPTION_semihosting
:
3955 semihosting
.enabled
= true;
3956 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3958 case QEMU_OPTION_semihosting_config
:
3959 semihosting
.enabled
= true;
3960 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3963 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3965 const char *target
= qemu_opt_get(opts
, "target");
3966 if (target
!= NULL
) {
3967 if (strcmp("native", target
) == 0) {
3968 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3969 } else if (strcmp("gdb", target
) == 0) {
3970 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3971 } else if (strcmp("auto", target
) == 0) {
3972 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3974 error_report("unsupported semihosting-config %s",
3979 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3981 /* Set semihosting argument count and vector */
3982 qemu_opt_foreach(opts
, add_semihosting_arg
,
3983 &semihosting
, NULL
);
3985 error_report("unsupported semihosting-config %s", optarg
);
3989 case QEMU_OPTION_tdf
:
3990 warn_report("ignoring deprecated option");
3992 case QEMU_OPTION_name
:
3993 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3999 case QEMU_OPTION_prom_env
:
4000 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
4001 error_report("too many prom variables");
4004 prom_envs
[nb_prom_envs
] = optarg
;
4007 case QEMU_OPTION_old_param
:
4010 case QEMU_OPTION_clock
:
4011 /* Clock options no longer exist. Keep this option for
4012 * backward compatibility.
4015 case QEMU_OPTION_startdate
:
4016 configure_rtc_date_offset(optarg
, 1);
4018 case QEMU_OPTION_rtc
:
4019 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
4024 configure_rtc(opts
);
4026 case QEMU_OPTION_tb_size
:
4028 error_report("TCG is disabled");
4031 if (qemu_strtoul(optarg
, NULL
, 0, &tcg_tb_size
) < 0) {
4032 error_report("Invalid argument to -tb-size");
4036 case QEMU_OPTION_icount
:
4037 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
4043 case QEMU_OPTION_incoming
:
4045 runstate_set(RUN_STATE_INMIGRATE
);
4049 case QEMU_OPTION_only_migratable
:
4051 * TODO: we can remove this option one day, and we
4054 * "-global migration.only-migratable=true"
4056 qemu_global_option("migration.only-migratable=true");
4058 case QEMU_OPTION_nodefaults
:
4061 case QEMU_OPTION_xen_domid
:
4062 if (!(xen_available())) {
4063 error_report("Option not supported for this target");
4066 xen_domid
= atoi(optarg
);
4068 case QEMU_OPTION_xen_create
:
4069 if (!(xen_available())) {
4070 error_report("Option not supported for this target");
4073 xen_mode
= XEN_CREATE
;
4075 case QEMU_OPTION_xen_attach
:
4076 if (!(xen_available())) {
4077 error_report("Option not supported for this target");
4080 xen_mode
= XEN_ATTACH
;
4082 case QEMU_OPTION_xen_domid_restrict
:
4083 if (!(xen_available())) {
4084 error_report("Option not supported for this target");
4087 xen_domid_restrict
= true;
4089 case QEMU_OPTION_trace
:
4091 trace_file
= trace_opt_parse(optarg
);
4093 case QEMU_OPTION_readconfig
:
4095 int ret
= qemu_read_config_file(optarg
);
4097 error_report("read config %s: %s", optarg
,
4103 case QEMU_OPTION_spice
:
4104 olist
= qemu_find_opts("spice");
4106 error_report("spice support is disabled");
4109 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
4115 case QEMU_OPTION_writeconfig
:
4118 if (strcmp(optarg
, "-") == 0) {
4121 fp
= fopen(optarg
, "w");
4123 error_report("open %s: %s", optarg
,
4128 qemu_config_write(fp
);
4134 case QEMU_OPTION_qtest
:
4135 qtest_chrdev
= optarg
;
4137 case QEMU_OPTION_qtest_log
:
4140 case QEMU_OPTION_sandbox
:
4141 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4147 case QEMU_OPTION_add_fd
:
4149 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4155 error_report("File descriptor passing is disabled on this "
4160 case QEMU_OPTION_object
:
4161 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
4167 case QEMU_OPTION_realtime
:
4168 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4173 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4175 case QEMU_OPTION_msg
:
4176 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4181 configure_msg(opts
);
4183 case QEMU_OPTION_dump_vmstate
:
4184 if (vmstate_dump_file
) {
4185 error_report("only one '-dump-vmstate' "
4186 "option may be given");
4189 vmstate_dump_file
= fopen(optarg
, "w");
4190 if (vmstate_dump_file
== NULL
) {
4191 error_report("open %s: %s", optarg
, strerror(errno
));
4196 os_parse_cmd_args(popt
->index
, optarg
);
4201 * Clear error location left behind by the loop.
4202 * Best done right after the loop. Do not insert code here!
4206 replay_configure(icount_opts
);
4208 machine_class
= select_machine();
4210 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4213 rcu_disable_atfork();
4215 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4216 error_report("could not acquire pid file: %s", strerror(errno
));
4220 if (qemu_init_main_loop(&main_loop_err
)) {
4221 error_report_err(main_loop_err
);
4225 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4226 parse_sandbox
, NULL
, NULL
)) {
4230 if (qemu_opts_foreach(qemu_find_opts("name"),
4231 parse_name
, NULL
, NULL
)) {
4236 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4237 parse_add_fd
, NULL
, NULL
)) {
4241 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4242 cleanup_add_fd
, NULL
, NULL
)) {
4247 current_machine
= MACHINE(object_new(object_class_get_name(
4248 OBJECT_CLASS(machine_class
))));
4249 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4252 object_property_add_child(object_get_root(), "machine",
4253 OBJECT(current_machine
), &error_abort
);
4255 if (machine_class
->minimum_page_bits
) {
4256 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4257 /* This would be a board error: specifying a minimum smaller than
4258 * a target's compile-time fixed setting.
4260 g_assert_not_reached();
4264 cpu_exec_init_all();
4266 if (machine_class
->hw_version
) {
4267 qemu_set_hw_version(machine_class
->hw_version
);
4270 if (cpu_model
&& is_help_option(cpu_model
)) {
4271 list_cpus(stdout
, &fprintf
, cpu_model
);
4275 if (!trace_init_backends()) {
4278 trace_init_file(trace_file
);
4280 /* Open the logfile at this point and set the log mask if necessary.
4283 qemu_set_log_filename(log_file
, &error_fatal
);
4288 mask
= qemu_str_to_log_mask(log_mask
);
4290 qemu_print_log_usage(stdout
);
4298 /* If no data_dir is specified then try to find it relative to the
4300 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4301 data_dir
[data_dir_idx
] = os_find_datadir();
4302 if (data_dir
[data_dir_idx
] != NULL
) {
4306 /* If all else fails use the install path specified when building. */
4307 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4308 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4311 /* -L help lists the data directories and exits. */
4312 if (list_data_dirs
) {
4313 for (i
= 0; i
< data_dir_idx
; i
++) {
4314 printf("%s\n", data_dir
[i
]);
4319 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4321 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4322 if (max_cpus
> machine_class
->max_cpus
) {
4323 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4324 "supported by machine '%s' (%d)", max_cpus
,
4325 machine_class
->name
, machine_class
->max_cpus
);
4330 * Get the default machine options from the machine if it is not already
4331 * specified either by the configuration file or by the command line.
4333 if (machine_class
->default_machine_opts
) {
4334 qemu_opts_set_defaults(qemu_find_opts("machine"),
4335 machine_class
->default_machine_opts
, 0);
4338 qemu_opts_foreach(qemu_find_opts("device"),
4339 default_driver_check
, NULL
, NULL
);
4340 qemu_opts_foreach(qemu_find_opts("global"),
4341 default_driver_check
, NULL
, NULL
);
4343 if (!vga_model
&& !default_vga
) {
4344 vga_interface_type
= VGA_DEVICE
;
4346 if (!has_defaults
|| machine_class
->no_serial
) {
4349 if (!has_defaults
|| machine_class
->no_parallel
) {
4350 default_parallel
= 0;
4352 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4353 default_virtcon
= 0;
4355 if (!has_defaults
|| !machine_class
->use_sclp
) {
4358 if (!has_defaults
|| machine_class
->no_floppy
) {
4361 if (!has_defaults
|| machine_class
->no_cdrom
) {
4364 if (!has_defaults
|| machine_class
->no_sdcard
) {
4367 if (!has_defaults
) {
4368 default_monitor
= 0;
4373 if (is_daemonized()) {
4374 /* According to documentation and historically, -nographic redirects
4375 * serial port, parallel port and monitor to stdio, which does not work
4376 * with -daemonize. We can redirect these to null instead, but since
4377 * -nographic is legacy, let's just error out.
4378 * We disallow -nographic only if all other ports are not redirected
4379 * explicitly, to not break existing legacy setups which uses
4380 * -nographic _and_ redirects all ports explicitly - this is valid
4381 * usage, -nographic is just a no-op in this case.
4384 && (default_parallel
|| default_serial
4385 || default_monitor
|| default_virtcon
)) {
4386 error_report("-nographic cannot be used with -daemonize");
4389 #ifdef CONFIG_CURSES
4390 if (display_type
== DT_CURSES
) {
4391 error_report("curses display cannot be used with -daemonize");
4398 if (default_parallel
)
4399 add_device_config(DEV_PARALLEL
, "null");
4400 if (default_serial
&& default_monitor
) {
4401 add_device_config(DEV_SERIAL
, "mon:stdio");
4402 } else if (default_virtcon
&& default_monitor
) {
4403 add_device_config(DEV_VIRTCON
, "mon:stdio");
4404 } else if (default_sclp
&& default_monitor
) {
4405 add_device_config(DEV_SCLP
, "mon:stdio");
4408 add_device_config(DEV_SERIAL
, "stdio");
4409 if (default_virtcon
)
4410 add_device_config(DEV_VIRTCON
, "stdio");
4412 add_device_config(DEV_SCLP
, "stdio");
4414 if (default_monitor
)
4415 monitor_parse("stdio", "readline", false);
4419 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4420 if (default_parallel
)
4421 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4422 if (default_monitor
)
4423 monitor_parse("vc:80Cx24C", "readline", false);
4424 if (default_virtcon
)
4425 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4427 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4431 #if defined(CONFIG_VNC)
4432 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4436 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4437 #if defined(CONFIG_GTK)
4438 display_type
= DT_GTK
;
4439 #elif defined(CONFIG_SDL)
4440 display_type
= DT_SDL
;
4441 #elif defined(CONFIG_COCOA)
4442 display_type
= DT_COCOA
;
4443 #elif defined(CONFIG_VNC)
4444 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4446 display_type
= DT_NONE
;
4450 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4451 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4452 "for SDL, ignoring option");
4454 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4455 error_report("-no-quit is only valid for GTK and SDL, "
4459 if (display_type
== DT_GTK
) {
4460 early_gtk_display_init(request_opengl
);
4463 if (display_type
== DT_SDL
) {
4464 sdl_display_early_init(request_opengl
);
4467 qemu_console_early_init();
4469 if (request_opengl
== 1 && display_opengl
== 0) {
4470 #if defined(CONFIG_OPENGL)
4471 error_report("OpenGL is not supported by the display");
4473 error_report("OpenGL support is disabled");
4481 if (qemu_opts_foreach(qemu_find_opts("object"),
4482 user_creatable_add_opts_foreach
,
4483 object_create_initial
, NULL
)) {
4487 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4488 chardev_init_func
, NULL
, NULL
)) {
4492 #ifdef CONFIG_VIRTFS
4493 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4494 fsdev_init_func
, NULL
, NULL
)) {
4499 if (qemu_opts_foreach(qemu_find_opts("device"),
4500 device_help_func
, NULL
, NULL
)) {
4504 machine_opts
= qemu_get_machine_opts();
4505 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4507 object_unref(OBJECT(current_machine
));
4511 configure_accelerator(current_machine
);
4514 * Register all the global properties, including accel properties,
4515 * machine properties, and user-specified ones.
4517 register_global_properties(current_machine
);
4520 * Migration object can only be created after global properties
4521 * are applied correctly.
4523 migration_object_init();
4526 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4529 machine_opts
= qemu_get_machine_opts();
4530 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4531 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4532 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4533 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4535 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4537 boot_order
= qemu_opt_get(opts
, "order");
4539 validate_bootdevices(boot_order
, &error_fatal
);
4542 boot_once
= qemu_opt_get(opts
, "once");
4544 validate_bootdevices(boot_once
, &error_fatal
);
4547 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4548 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4552 boot_order
= machine_class
->default_boot_order
;
4555 if (!kernel_cmdline
) {
4556 kernel_cmdline
= "";
4557 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4560 linux_boot
= (kernel_filename
!= NULL
);
4562 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4563 error_report("-append only allowed with -kernel option");
4567 if (!linux_boot
&& initrd_filename
!= NULL
) {
4568 error_report("-initrd only allowed with -kernel option");
4572 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4573 /* fall back to the -kernel/-append */
4574 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4577 os_set_line_buffering();
4579 /* spice needs the timers to be initialized by this point */
4584 if (!tcg_enabled()) {
4585 error_report("-icount is not allowed with hardware virtualization");
4588 configure_icount(icount_opts
, &error_abort
);
4589 qemu_opts_del(icount_opts
);
4592 if (tcg_enabled()) {
4593 qemu_tcg_configure(accel_opts
, &error_fatal
);
4597 QemuOptsList
*net
= qemu_find_opts("net");
4598 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4600 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4606 if (net_init_clients() < 0) {
4610 if (qemu_opts_foreach(qemu_find_opts("object"),
4611 user_creatable_add_opts_foreach
,
4612 object_create_delayed
, NULL
)) {
4617 if (tpm_init() < 0) {
4622 /* init the bluetooth world */
4623 if (foreach_device_config(DEV_BT
, bt_parse
))
4626 if (!xen_enabled()) {
4627 /* On 32-bit hosts, QEMU is limited by virtual address space */
4628 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4629 error_report("at most 2047 MB RAM can be simulated");
4637 /* If the currently selected machine wishes to override the units-per-bus
4638 * property of its default HBA interface type, do so now. */
4639 if (machine_class
->units_per_default_bus
) {
4640 override_max_devs(machine_class
->block_default_type
,
4641 machine_class
->units_per_default_bus
);
4644 /* open the virtual block devices */
4645 while (!QSIMPLEQ_EMPTY(&bdo_queue
)) {
4646 BlockdevOptions_queue
*bdo
= QSIMPLEQ_FIRST(&bdo_queue
);
4648 QSIMPLEQ_REMOVE_HEAD(&bdo_queue
, entry
);
4649 loc_push_restore(&bdo
->loc
);
4650 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
4652 qapi_free_BlockdevOptions(bdo
->bdo
);
4655 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4656 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4659 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4660 &machine_class
->block_default_type
, NULL
)) {
4664 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4666 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4667 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4669 parse_numa_opts(current_machine
);
4671 if (qemu_opts_foreach(qemu_find_opts("mon"),
4672 mon_init_func
, NULL
, NULL
)) {
4676 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4678 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4680 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4682 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4685 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4688 /* If no default VGA is requested, the default is "none". */
4690 if (machine_class
->default_display
) {
4691 vga_model
= machine_class
->default_display
;
4692 } else if (vga_interface_available(VGA_CIRRUS
)) {
4693 vga_model
= "cirrus";
4694 } else if (vga_interface_available(VGA_STD
)) {
4699 select_vgahw(vga_model
);
4703 i
= select_watchdog(watchdog
);
4705 exit (i
== 1 ? 1 : 0);
4708 /* This checkpoint is required by replay to separate prior clock
4709 reading from the other reads, because timer polling functions query
4710 clock values from the log. */
4711 replay_checkpoint(CHECKPOINT_INIT
);
4712 qdev_machine_init();
4714 current_machine
->ram_size
= ram_size
;
4715 current_machine
->maxram_size
= maxram_size
;
4716 current_machine
->ram_slots
= ram_slots
;
4717 current_machine
->boot_order
= boot_order
;
4718 current_machine
->cpu_model
= cpu_model
;
4721 /* parse features once if machine provides default cpu_type */
4722 if (machine_class
->default_cpu_type
) {
4723 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
4725 current_machine
->cpu_type
=
4726 cpu_parse_cpu_model(machine_class
->default_cpu_type
, cpu_model
);
4730 machine_run_board_init(current_machine
);
4736 if (hax_enabled()) {
4740 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4741 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4745 /* init USB devices */
4746 if (machine_usb(current_machine
)) {
4747 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4751 /* Check if IGD GFX passthrough. */
4754 /* init generic devices */
4755 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4756 if (qemu_opts_foreach(qemu_find_opts("device"),
4757 device_init_func
, NULL
, NULL
)) {
4761 cpu_synchronize_all_post_init();
4763 rom_reset_order_override();
4766 * Create frontends for -drive if=scsi leftovers.
4767 * Normally, frontends for -drive get created by machine
4768 * initialization for onboard SCSI HBAs. However, we create a few
4769 * more ever since SCSI qdevification, but this is pretty much an
4770 * implementation accident, and deprecated.
4772 scsi_legacy_handle_cmdline();
4774 /* Did we create any drives that we failed to create a device for? */
4775 drive_check_orphaned();
4777 /* Don't warn about the default network setup that you get if
4778 * no command line -net or -netdev options are specified. There
4779 * are two cases that we would otherwise complain about:
4780 * (1) board doesn't support a NIC but the implicit "-net nic"
4782 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4783 * sets up a nic that isn't connected to anything.
4786 net_check_clients();
4791 qemu_boot_set(boot_once
, &error_fatal
);
4792 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4795 ds
= init_displaystate();
4797 /* init local displays */
4798 switch (display_type
) {
4800 curses_display_init(ds
, full_screen
);
4803 sdl_display_init(ds
, full_screen
, no_frame
);
4806 cocoa_display_init(ds
, full_screen
);
4809 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4815 /* must be after terminal init, SDL library changes signal handlers */
4816 os_setup_signal_handling();
4818 /* init remote displays */
4820 qemu_opts_foreach(qemu_find_opts("vnc"),
4821 vnc_init_func
, NULL
, NULL
);
4825 qemu_spice_display_init();
4828 #ifdef CONFIG_OPENGL_DMABUF
4829 if (display_type
== DT_EGL
) {
4830 egl_headless_init();
4834 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4838 qdev_machine_creation_done();
4840 /* TODO: once all bus devices are qdevified, this should be done
4841 * when bus is created by qdev.c */
4842 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4843 qemu_run_machine_init_done_notifiers();
4845 if (rom_check_and_register_reset() != 0) {
4846 error_report("rom check and register reset failed");
4852 /* This checkpoint is required by replay to separate prior clock
4853 reading from the other reads, because timer polling functions query
4854 clock values from the log. */
4855 replay_checkpoint(CHECKPOINT_RESET
);
4856 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
4857 register_global_state();
4858 if (replay_mode
!= REPLAY_MODE_NONE
) {
4859 replay_vmstate_init();
4860 } else if (loadvm
) {
4861 Error
*local_err
= NULL
;
4862 if (load_snapshot(loadvm
, &local_err
) < 0) {
4863 error_report_err(local_err
);
4868 qdev_prop_check_globals();
4869 if (vmstate_dump_file
) {
4871 dump_vmstate_json_to_file(vmstate_dump_file
);
4876 Error
*local_err
= NULL
;
4877 qemu_start_incoming_migration(incoming
, &local_err
);
4879 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4882 } else if (autostart
) {
4889 replay_disable_events();
4890 iothread_stop_all();
4896 /* vhost-user must be cleaned up before chardevs. */
4901 user_creatable_cleanup();
4902 /* TODO: unref root container, check all devices are ok */