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
25 #include "qemu/osdep.h"
26 #include "qapi/error.h"
27 #include "qemu-version.h"
28 #include "qemu/cutils.h"
29 #include "qemu/help_option.h"
30 #include "qemu/uuid.h"
33 #include <sys/prctl.h>
34 #include "sysemu/seccomp.h"
38 #if defined(__APPLE__) || defined(main)
39 #define SDL_MAIN_HANDLED
41 #if SDL_MAJOR_VERSION == 1
42 int qemu_main(int argc
, char **argv
);
43 int main(int argc
, char **argv
)
45 return qemu_main(argc
, argv
);
48 #define main qemu_main
49 #elif SDL_MAJOR_VERSION == 2
52 #error undefined SDL version
55 #endif /* CONFIG_SDL */
59 #define main qemu_main
60 #endif /* CONFIG_COCOA */
63 #include "qemu/error-report.h"
64 #include "qemu/sockets.h"
66 #include "hw/boards.h"
67 #include "sysemu/accel.h"
69 #include "hw/isa/isa.h"
70 #include "hw/scsi/scsi.h"
71 #include "hw/display/vga.h"
73 #include "sysemu/watchdog.h"
74 #include "hw/smbios/smbios.h"
75 #include "hw/acpi/acpi.h"
76 #include "hw/xen/xen.h"
78 #include "hw/loader.h"
79 #include "monitor/qdev.h"
80 #include "sysemu/bt.h"
82 #include "net/slirp.h"
83 #include "monitor/monitor.h"
84 #include "ui/console.h"
86 #include "sysemu/sysemu.h"
87 #include "sysemu/numa.h"
88 #include "exec/gdbstub.h"
89 #include "qemu/timer.h"
90 #include "chardev/char.h"
91 #include "qemu/bitmap.h"
93 #include "sysemu/blockdev.h"
94 #include "hw/block/block.h"
95 #include "migration/misc.h"
96 #include "migration/snapshot.h"
97 #include "migration/global_state.h"
98 #include "sysemu/tpm.h"
99 #include "sysemu/dma.h"
100 #include "hw/audio/soundhw.h"
101 #include "audio/audio.h"
102 #include "sysemu/cpus.h"
103 #include "migration/colo.h"
104 #include "migration/postcopy-ram.h"
105 #include "sysemu/kvm.h"
106 #include "sysemu/hax.h"
107 #include "qapi/qobject-input-visitor.h"
108 #include "qemu/option.h"
109 #include "qemu/config-file.h"
110 #include "qemu-options.h"
111 #include "qemu/main-loop.h"
113 #include "fsdev/qemu-fsdev.h"
115 #include "sysemu/qtest.h"
117 #include "disas/disas.h"
120 #include "slirp/libslirp.h"
122 #include "trace-root.h"
123 #include "trace/control.h"
124 #include "qemu/queue.h"
125 #include "sysemu/arch_init.h"
127 #include "ui/qemu-spice.h"
128 #include "qapi/string-input-visitor.h"
129 #include "qapi/opts-visitor.h"
130 #include "qom/object_interfaces.h"
131 #include "exec/semihost.h"
132 #include "crypto/init.h"
133 #include "sysemu/replay.h"
134 #include "qapi/qapi-events-run-state.h"
135 #include "qapi/qapi-visit-block-core.h"
136 #include "qapi/qapi-commands-block-core.h"
137 #include "qapi/qapi-commands-misc.h"
138 #include "qapi/qapi-commands-run-state.h"
139 #include "qapi/qmp/qerror.h"
140 #include "sysemu/iothread.h"
142 #define MAX_VIRTIO_CONSOLES 1
143 #define MAX_SCLP_CONSOLES 1
145 static const char *data_dir
[16];
146 static int data_dir_idx
;
147 const char *bios_name
= NULL
;
148 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
150 const char* keyboard_layout
= NULL
;
152 const char *mem_path
= NULL
;
153 int mem_prealloc
= 0; /* force preallocation of physical target memory */
154 bool enable_mlock
= false;
156 NICInfo nd_table
[MAX_NICS
];
158 static int rtc_utc
= 1;
159 static int rtc_date_offset
= -1; /* -1 means no change */
160 QEMUClockType rtc_clock
;
161 int vga_interface_type
= VGA_NONE
;
162 static DisplayOptions dpy
;
164 Chardev
*serial_hds
[MAX_SERIAL_PORTS
];
165 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
166 Chardev
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
167 Chardev
*sclp_hds
[MAX_SCLP_CONSOLES
];
168 int win2k_install_hack
= 0;
171 unsigned int max_cpus
;
174 int acpi_enabled
= 1;
177 static int no_reboot
;
180 int graphic_rotate
= 0;
181 const char *watchdog
;
182 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
185 const char *qemu_name
;
188 unsigned int nb_prom_envs
= 0;
189 const char *prom_envs
[MAX_PROM_ENVS
];
192 uint8_t *boot_splash_filedata
;
193 size_t boot_splash_filedata_size
;
194 uint8_t qemu_extra_params_fw
[2];
196 int icount_align_option
;
198 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
199 * little-endian "wire format" described in the SMBIOS 2.6 specification.
204 /* Trace unassigned memory or i/o accesses. */
205 bool trace_unassigned
;
207 static NotifierList exit_notifiers
=
208 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
210 static NotifierList machine_init_done_notifiers
=
211 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
215 enum xen_mode xen_mode
= XEN_EMULATE
;
216 bool xen_domid_restrict
;
218 static int has_defaults
= 1;
219 static int default_serial
= 1;
220 static int default_parallel
= 1;
221 static int default_virtcon
= 1;
222 static int default_sclp
= 1;
223 static int default_monitor
= 1;
224 static int default_floppy
= 1;
225 static int default_cdrom
= 1;
226 static int default_sdcard
= 1;
227 static int default_vga
= 1;
228 static int default_net
= 1;
234 { .driver
= "isa-serial", .flag
= &default_serial
},
235 { .driver
= "isa-parallel", .flag
= &default_parallel
},
236 { .driver
= "isa-fdc", .flag
= &default_floppy
},
237 { .driver
= "floppy", .flag
= &default_floppy
},
238 { .driver
= "ide-cd", .flag
= &default_cdrom
},
239 { .driver
= "ide-hd", .flag
= &default_cdrom
},
240 { .driver
= "ide-drive", .flag
= &default_cdrom
},
241 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
242 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
243 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
244 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
245 { .driver
= "VGA", .flag
= &default_vga
},
246 { .driver
= "isa-vga", .flag
= &default_vga
},
247 { .driver
= "cirrus-vga", .flag
= &default_vga
},
248 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
249 { .driver
= "vmware-svga", .flag
= &default_vga
},
250 { .driver
= "qxl-vga", .flag
= &default_vga
},
251 { .driver
= "virtio-vga", .flag
= &default_vga
},
254 static QemuOptsList qemu_rtc_opts
= {
256 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
260 .type
= QEMU_OPT_STRING
,
263 .type
= QEMU_OPT_STRING
,
266 .type
= QEMU_OPT_STRING
,
268 { /* end of list */ }
272 static QemuOptsList qemu_sandbox_opts
= {
274 .implied_opt_name
= "enable",
275 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
279 .type
= QEMU_OPT_BOOL
,
283 .type
= QEMU_OPT_STRING
,
286 .name
= "elevateprivileges",
287 .type
= QEMU_OPT_STRING
,
291 .type
= QEMU_OPT_STRING
,
294 .name
= "resourcecontrol",
295 .type
= QEMU_OPT_STRING
,
297 { /* end of list */ }
301 static QemuOptsList qemu_option_rom_opts
= {
302 .name
= "option-rom",
303 .implied_opt_name
= "romfile",
304 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
308 .type
= QEMU_OPT_NUMBER
,
311 .type
= QEMU_OPT_STRING
,
313 { /* end of list */ }
317 static QemuOptsList qemu_machine_opts
= {
319 .implied_opt_name
= "type",
321 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
324 * no elements => accept any
325 * sanity checking will happen later
326 * when setting machine properties
332 static QemuOptsList qemu_accel_opts
= {
334 .implied_opt_name
= "accel",
335 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
340 .type
= QEMU_OPT_STRING
,
341 .help
= "Select the type of accelerator",
345 .type
= QEMU_OPT_STRING
,
346 .help
= "Enable/disable multi-threaded TCG",
348 { /* end of list */ }
352 static QemuOptsList qemu_boot_opts
= {
354 .implied_opt_name
= "order",
356 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
360 .type
= QEMU_OPT_STRING
,
363 .type
= QEMU_OPT_STRING
,
366 .type
= QEMU_OPT_BOOL
,
369 .type
= QEMU_OPT_STRING
,
371 .name
= "splash-time",
372 .type
= QEMU_OPT_STRING
,
374 .name
= "reboot-timeout",
375 .type
= QEMU_OPT_STRING
,
378 .type
= QEMU_OPT_BOOL
,
384 static QemuOptsList qemu_add_fd_opts
= {
386 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
390 .type
= QEMU_OPT_NUMBER
,
391 .help
= "file descriptor of which a duplicate is added to fd set",
394 .type
= QEMU_OPT_NUMBER
,
395 .help
= "ID of the fd set to add fd to",
398 .type
= QEMU_OPT_STRING
,
399 .help
= "free-form string used to describe fd",
401 { /* end of list */ }
405 static QemuOptsList qemu_object_opts
= {
407 .implied_opt_name
= "qom-type",
408 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
414 static QemuOptsList qemu_tpmdev_opts
= {
416 .implied_opt_name
= "type",
417 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
419 /* options are defined in the TPM backends */
420 { /* end of list */ }
424 static QemuOptsList qemu_realtime_opts
= {
426 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
430 .type
= QEMU_OPT_BOOL
,
432 { /* end of list */ }
436 static QemuOptsList qemu_msg_opts
= {
438 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
442 .type
= QEMU_OPT_BOOL
,
444 { /* end of list */ }
448 static QemuOptsList qemu_name_opts
= {
450 .implied_opt_name
= "guest",
452 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
456 .type
= QEMU_OPT_STRING
,
457 .help
= "Sets the name of the guest.\n"
458 "This name will be displayed in the SDL window caption.\n"
459 "The name will also be used for the VNC server",
462 .type
= QEMU_OPT_STRING
,
463 .help
= "Sets the name of the QEMU process, as shown in top etc",
465 .name
= "debug-threads",
466 .type
= QEMU_OPT_BOOL
,
467 .help
= "When enabled, name the individual threads; defaults off.\n"
468 "NOTE: The thread names are for debugging and not a\n"
471 { /* End of list */ }
475 static QemuOptsList qemu_mem_opts
= {
477 .implied_opt_name
= "size",
478 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
483 .type
= QEMU_OPT_SIZE
,
487 .type
= QEMU_OPT_NUMBER
,
491 .type
= QEMU_OPT_SIZE
,
493 { /* end of list */ }
497 static QemuOptsList qemu_icount_opts
= {
499 .implied_opt_name
= "shift",
501 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
505 .type
= QEMU_OPT_STRING
,
508 .type
= QEMU_OPT_BOOL
,
511 .type
= QEMU_OPT_BOOL
,
514 .type
= QEMU_OPT_STRING
,
517 .type
= QEMU_OPT_STRING
,
519 .name
= "rrsnapshot",
520 .type
= QEMU_OPT_STRING
,
522 { /* end of list */ }
526 static QemuOptsList qemu_semihosting_config_opts
= {
527 .name
= "semihosting-config",
528 .implied_opt_name
= "enable",
529 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
533 .type
= QEMU_OPT_BOOL
,
536 .type
= QEMU_OPT_STRING
,
539 .type
= QEMU_OPT_STRING
,
541 { /* end of list */ }
545 static QemuOptsList qemu_fw_cfg_opts
= {
547 .implied_opt_name
= "name",
548 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
552 .type
= QEMU_OPT_STRING
,
553 .help
= "Sets the fw_cfg name of the blob to be inserted",
556 .type
= QEMU_OPT_STRING
,
557 .help
= "Sets the name of the file from which\n"
558 "the fw_cfg blob will be loaded",
561 .type
= QEMU_OPT_STRING
,
562 .help
= "Sets content of the blob to be inserted from a string",
564 { /* end of list */ }
569 * Get machine options
571 * Returns: machine options (never null).
573 QemuOpts
*qemu_get_machine_opts(void)
575 return qemu_find_opts_singleton("machine");
578 const char *qemu_get_vm_name(void)
583 static void res_free(void)
585 g_free(boot_splash_filedata
);
586 boot_splash_filedata
= NULL
;
589 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
591 const char *driver
= qemu_opt_get(opts
, "driver");
596 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
597 if (strcmp(default_list
[i
].driver
, driver
) != 0)
599 *(default_list
[i
].flag
) = 0;
604 /***********************************************************/
607 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
609 /* We use RUN_STATE__MAX but any invalid value will do */
610 static RunState vmstop_requested
= RUN_STATE__MAX
;
611 static QemuMutex vmstop_lock
;
616 } RunStateTransition
;
618 static const RunStateTransition runstate_transitions_def
[] = {
620 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
621 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
622 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
624 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
625 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
626 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
627 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
628 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
629 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
630 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
631 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
632 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
633 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
634 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
635 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
637 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
638 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
639 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
641 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
642 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
643 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
645 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
646 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
647 { RUN_STATE_PAUSED
, RUN_STATE_POSTMIGRATE
},
648 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
649 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
651 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
652 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
653 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
655 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
656 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
657 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
659 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
660 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PAUSED
},
661 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
662 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
663 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
665 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
666 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
668 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
670 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
671 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
672 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
673 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
674 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
675 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
676 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
677 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
678 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
679 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
680 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
682 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
684 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
685 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
686 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
688 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
689 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
690 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
691 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
692 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
693 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
695 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
696 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
697 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
698 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
700 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
701 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
702 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
704 { RUN_STATE__MAX
, RUN_STATE__MAX
},
707 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
709 bool runstate_check(RunState state
)
711 return current_run_state
== state
;
714 bool runstate_store(char *str
, size_t size
)
716 const char *state
= RunState_str(current_run_state
);
717 size_t len
= strlen(state
) + 1;
722 memcpy(str
, state
, len
);
726 static void runstate_init(void)
728 const RunStateTransition
*p
;
730 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
731 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
732 runstate_valid_transitions
[p
->from
][p
->to
] = true;
735 qemu_mutex_init(&vmstop_lock
);
738 /* This function will abort() on invalid state transitions */
739 void runstate_set(RunState new_state
)
741 assert(new_state
< RUN_STATE__MAX
);
743 if (current_run_state
== new_state
) {
747 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
748 error_report("invalid runstate transition: '%s' -> '%s'",
749 RunState_str(current_run_state
),
750 RunState_str(new_state
));
753 trace_runstate_set(new_state
);
754 current_run_state
= new_state
;
757 int runstate_is_running(void)
759 return runstate_check(RUN_STATE_RUNNING
);
762 bool runstate_needs_reset(void)
764 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
765 runstate_check(RUN_STATE_SHUTDOWN
);
768 StatusInfo
*qmp_query_status(Error
**errp
)
770 StatusInfo
*info
= g_malloc0(sizeof(*info
));
772 info
->running
= runstate_is_running();
773 info
->singlestep
= singlestep
;
774 info
->status
= current_run_state
;
779 bool qemu_vmstop_requested(RunState
*r
)
781 qemu_mutex_lock(&vmstop_lock
);
782 *r
= vmstop_requested
;
783 vmstop_requested
= RUN_STATE__MAX
;
784 qemu_mutex_unlock(&vmstop_lock
);
785 return *r
< RUN_STATE__MAX
;
788 void qemu_system_vmstop_request_prepare(void)
790 qemu_mutex_lock(&vmstop_lock
);
793 void qemu_system_vmstop_request(RunState state
)
795 vmstop_requested
= state
;
796 qemu_mutex_unlock(&vmstop_lock
);
800 /***********************************************************/
801 /* real time host monotonic timer */
803 static time_t qemu_time(void)
805 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
808 /***********************************************************/
809 /* host time/date access */
810 void qemu_get_timedate(struct tm
*tm
, int offset
)
812 time_t ti
= qemu_time();
815 if (rtc_date_offset
== -1) {
819 localtime_r(&ti
, tm
);
821 ti
-= rtc_date_offset
;
826 int qemu_timedate_diff(struct tm
*tm
)
830 if (rtc_date_offset
== -1)
832 seconds
= mktimegm(tm
);
835 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
836 seconds
= mktime(&tmp
);
839 seconds
= mktimegm(tm
) + rtc_date_offset
;
841 return seconds
- qemu_time();
844 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
846 time_t rtc_start_date
;
849 if (!strcmp(startdate
, "now") && legacy
) {
850 rtc_date_offset
= -1;
852 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
860 } else if (sscanf(startdate
, "%d-%d-%d",
872 rtc_start_date
= mktimegm(&tm
);
873 if (rtc_start_date
== -1) {
875 error_report("invalid date format");
876 error_printf("valid formats: "
877 "'2006-06-17T16:01:21' or '2006-06-17'\n");
880 rtc_date_offset
= qemu_time() - rtc_start_date
;
884 static void configure_rtc(QemuOpts
*opts
)
888 value
= qemu_opt_get(opts
, "base");
890 if (!strcmp(value
, "utc")) {
892 } else if (!strcmp(value
, "localtime")) {
893 Error
*blocker
= NULL
;
895 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
896 "-rtc base=localtime");
897 replay_add_blocker(blocker
);
899 configure_rtc_date_offset(value
, 0);
902 value
= qemu_opt_get(opts
, "clock");
904 if (!strcmp(value
, "host")) {
905 rtc_clock
= QEMU_CLOCK_HOST
;
906 } else if (!strcmp(value
, "rt")) {
907 rtc_clock
= QEMU_CLOCK_REALTIME
;
908 } else if (!strcmp(value
, "vm")) {
909 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
911 error_report("invalid option value '%s'", value
);
915 value
= qemu_opt_get(opts
, "driftfix");
917 if (!strcmp(value
, "slew")) {
918 static GlobalProperty slew_lost_ticks
= {
919 .driver
= "mc146818rtc",
920 .property
= "lost_tick_policy",
924 qdev_prop_register_global(&slew_lost_ticks
);
925 } else if (!strcmp(value
, "none")) {
926 /* discard is default */
928 error_report("invalid option value '%s'", value
);
934 /***********************************************************/
935 /* Bluetooth support */
938 static struct HCIInfo
*hci_table
[MAX_NICS
];
940 struct HCIInfo
*qemu_next_hci(void)
942 if (cur_hci
== nb_hcis
)
945 return hci_table
[cur_hci
++];
948 static int bt_hci_parse(const char *str
)
953 if (nb_hcis
>= MAX_NICS
) {
954 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
967 bdaddr
.b
[5] = 0x56 + nb_hcis
;
968 hci
->bdaddr_set(hci
, bdaddr
.b
);
970 hci_table
[nb_hcis
++] = hci
;
975 static void bt_vhci_add(int vlan_id
)
977 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
980 warn_report("adding a VHCI to an empty scatternet %i",
983 bt_vhci_init(bt_new_hci(vlan
));
986 static struct bt_device_s
*bt_device_add(const char *opt
)
988 struct bt_scatternet_s
*vlan
;
990 char *endp
= strstr(opt
, ",vlan=");
991 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
994 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
997 vlan_id
= strtol(endp
+ 6, &endp
, 0);
999 error_report("unrecognised bluetooth vlan Id");
1004 vlan
= qemu_find_bt_vlan(vlan_id
);
1007 warn_report("adding a slave device to an empty scatternet %i",
1010 if (!strcmp(devname
, "keyboard"))
1011 return bt_keyboard_init(vlan
);
1013 error_report("unsupported bluetooth device '%s'", devname
);
1017 static int bt_parse(const char *opt
)
1019 const char *endp
, *p
;
1022 if (strstart(opt
, "hci", &endp
)) {
1023 if (!*endp
|| *endp
== ',') {
1025 if (!strstart(endp
, ",vlan=", 0))
1028 return bt_hci_parse(opt
);
1030 } else if (strstart(opt
, "vhci", &endp
)) {
1031 if (!*endp
|| *endp
== ',') {
1033 if (strstart(endp
, ",vlan=", &p
)) {
1034 vlan
= strtol(p
, (char **) &endp
, 0);
1036 error_report("bad scatternet '%s'", p
);
1040 error_report("bad parameter '%s'", endp
+ 1);
1049 } else if (strstart(opt
, "device:", &endp
))
1050 return !bt_device_add(endp
);
1052 error_report("bad bluetooth parameter '%s'", opt
);
1056 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1058 if (qemu_opt_get_bool(opts
, "enable", false)) {
1059 #ifdef CONFIG_SECCOMP
1060 uint32_t seccomp_opts
= QEMU_SECCOMP_SET_DEFAULT
1061 | QEMU_SECCOMP_SET_OBSOLETE
;
1062 const char *value
= NULL
;
1064 value
= qemu_opt_get(opts
, "obsolete");
1066 if (g_str_equal(value
, "allow")) {
1067 seccomp_opts
&= ~QEMU_SECCOMP_SET_OBSOLETE
;
1068 } else if (g_str_equal(value
, "deny")) {
1069 /* this is the default option, this if is here
1070 * to provide a little bit of consistency for
1071 * the command line */
1073 error_report("invalid argument for obsolete");
1078 value
= qemu_opt_get(opts
, "elevateprivileges");
1080 if (g_str_equal(value
, "deny")) {
1081 seccomp_opts
|= QEMU_SECCOMP_SET_PRIVILEGED
;
1082 } else if (g_str_equal(value
, "children")) {
1083 seccomp_opts
|= QEMU_SECCOMP_SET_PRIVILEGED
;
1085 /* calling prctl directly because we're
1086 * not sure if host has CAP_SYS_ADMIN set*/
1087 if (prctl(PR_SET_NO_NEW_PRIVS
, 1)) {
1088 error_report("failed to set no_new_privs "
1092 } else if (g_str_equal(value
, "allow")) {
1095 error_report("invalid argument for elevateprivileges");
1100 value
= qemu_opt_get(opts
, "spawn");
1102 if (g_str_equal(value
, "deny")) {
1103 seccomp_opts
|= QEMU_SECCOMP_SET_SPAWN
;
1104 } else if (g_str_equal(value
, "allow")) {
1107 error_report("invalid argument for spawn");
1112 value
= qemu_opt_get(opts
, "resourcecontrol");
1114 if (g_str_equal(value
, "deny")) {
1115 seccomp_opts
|= QEMU_SECCOMP_SET_RESOURCECTL
;
1116 } else if (g_str_equal(value
, "allow")) {
1119 error_report("invalid argument for resourcecontrol");
1124 if (seccomp_start(seccomp_opts
) < 0) {
1125 error_report("failed to install seccomp syscall filter "
1130 error_report("seccomp support is disabled");
1138 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1140 const char *proc_name
;
1142 if (qemu_opt_get(opts
, "debug-threads")) {
1143 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1145 qemu_name
= qemu_opt_get(opts
, "guest");
1147 proc_name
= qemu_opt_get(opts
, "process");
1149 os_set_proc_name(proc_name
);
1155 bool defaults_enabled(void)
1157 return has_defaults
;
1161 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1163 int fd
, dupfd
, flags
;
1165 const char *fd_opaque
= NULL
;
1168 fd
= qemu_opt_get_number(opts
, "fd", -1);
1169 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1170 fd_opaque
= qemu_opt_get(opts
, "opaque");
1173 error_report("fd option is required and must be non-negative");
1177 if (fd
<= STDERR_FILENO
) {
1178 error_report("fd cannot be a standard I/O stream");
1183 * All fds inherited across exec() necessarily have FD_CLOEXEC
1184 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1186 flags
= fcntl(fd
, F_GETFD
);
1187 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1188 error_report("fd is not valid or already in use");
1193 error_report("set option is required and must be non-negative");
1197 #ifdef F_DUPFD_CLOEXEC
1198 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1202 qemu_set_cloexec(dupfd
);
1206 error_report("error duplicating fd: %s", strerror(errno
));
1210 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1211 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1218 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1222 fd
= qemu_opt_get_number(opts
, "fd", -1);
1229 /***********************************************************/
1230 /* QEMU Block devices */
1232 #define HD_OPTS "media=disk"
1233 #define CDROM_OPTS "media=cdrom"
1235 #define PFLASH_OPTS ""
1239 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1241 BlockInterfaceType
*block_default_type
= opaque
;
1243 return drive_new(opts
, *block_default_type
) == NULL
;
1246 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1248 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1249 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1254 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1255 int index
, const char *optstr
)
1260 if (!enable
|| drive_get_by_index(type
, index
)) {
1264 opts
= drive_add(type
, index
, NULL
, optstr
);
1266 drive_enable_snapshot(NULL
, opts
, NULL
);
1269 dinfo
= drive_new(opts
, type
);
1273 dinfo
->is_default
= true;
1277 static QemuOptsList qemu_smp_opts
= {
1279 .implied_opt_name
= "cpus",
1280 .merge_lists
= true,
1281 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1285 .type
= QEMU_OPT_NUMBER
,
1288 .type
= QEMU_OPT_NUMBER
,
1291 .type
= QEMU_OPT_NUMBER
,
1294 .type
= QEMU_OPT_NUMBER
,
1297 .type
= QEMU_OPT_NUMBER
,
1299 { /*End of list */ }
1303 static void smp_parse(QemuOpts
*opts
)
1306 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1307 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1308 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1309 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1311 /* compute missing values, prefer sockets over cores over threads */
1312 if (cpus
== 0 || sockets
== 0) {
1313 sockets
= sockets
> 0 ? sockets
: 1;
1314 cores
= cores
> 0 ? cores
: 1;
1315 threads
= threads
> 0 ? threads
: 1;
1317 cpus
= cores
* threads
* sockets
;
1319 } else if (cores
== 0) {
1320 threads
= threads
> 0 ? threads
: 1;
1321 cores
= cpus
/ (sockets
* threads
);
1322 cores
= cores
> 0 ? cores
: 1;
1323 } else if (threads
== 0) {
1324 threads
= cpus
/ (cores
* sockets
);
1325 threads
= threads
> 0 ? threads
: 1;
1326 } else if (sockets
* cores
* threads
< cpus
) {
1327 error_report("cpu topology: "
1328 "sockets (%u) * cores (%u) * threads (%u) < "
1330 sockets
, cores
, threads
, cpus
);
1334 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1336 if (max_cpus
< cpus
) {
1337 error_report("maxcpus must be equal to or greater than smp");
1341 if (sockets
* cores
* threads
> max_cpus
) {
1342 error_report("cpu topology: "
1343 "sockets (%u) * cores (%u) * threads (%u) > "
1345 sockets
, cores
, threads
, max_cpus
);
1351 smp_threads
= threads
;
1355 Error
*blocker
= NULL
;
1356 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1357 replay_add_blocker(blocker
);
1361 static void realtime_init(void)
1364 if (os_mlock() < 0) {
1365 error_report("locking memory failed");
1372 static void configure_msg(QemuOpts
*opts
)
1374 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1377 /***********************************************************/
1380 typedef struct SemihostingConfig
{
1382 SemihostingTarget target
;
1385 const char *cmdline
; /* concatenated argv */
1386 } SemihostingConfig
;
1388 static SemihostingConfig semihosting
;
1390 bool semihosting_enabled(void)
1392 return semihosting
.enabled
;
1395 SemihostingTarget
semihosting_get_target(void)
1397 return semihosting
.target
;
1400 const char *semihosting_get_arg(int i
)
1402 if (i
>= semihosting
.argc
) {
1405 return semihosting
.argv
[i
];
1408 int semihosting_get_argc(void)
1410 return semihosting
.argc
;
1413 const char *semihosting_get_cmdline(void)
1415 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1416 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1418 return semihosting
.cmdline
;
1421 static int add_semihosting_arg(void *opaque
,
1422 const char *name
, const char *val
,
1425 SemihostingConfig
*s
= opaque
;
1426 if (strcmp(name
, "arg") == 0) {
1428 /* one extra element as g_strjoinv() expects NULL-terminated array */
1429 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1430 s
->argv
[s
->argc
- 1] = val
;
1431 s
->argv
[s
->argc
] = NULL
;
1436 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1437 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1442 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1444 /* split -append and initialize argv[1..n] */
1445 cmd_token
= strtok(g_strdup(cmd
), " ");
1447 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1448 cmd_token
= strtok(NULL
, " ");
1452 /* Now we still need this for compatibility with XEN. */
1453 bool has_igd_gfx_passthru
;
1454 static void igd_gfx_passthru(void)
1456 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1459 /***********************************************************/
1462 static int usb_device_add(const char *devname
)
1464 USBDevice
*dev
= NULL
;
1466 if (!machine_usb(current_machine
)) {
1470 dev
= usbdevice_create(devname
);
1477 static int usb_parse(const char *cmdline
)
1480 r
= usb_device_add(cmdline
);
1482 error_report("could not add USB device '%s'", cmdline
);
1487 /***********************************************************/
1488 /* machine registration */
1490 MachineState
*current_machine
;
1492 static MachineClass
*find_machine(const char *name
)
1494 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1495 MachineClass
*mc
= NULL
;
1497 for (el
= machines
; el
; el
= el
->next
) {
1498 MachineClass
*temp
= el
->data
;
1500 if (!strcmp(temp
->name
, name
)) {
1505 !strcmp(temp
->alias
, name
)) {
1511 g_slist_free(machines
);
1515 MachineClass
*find_default_machine(void)
1517 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1518 MachineClass
*mc
= NULL
;
1520 for (el
= machines
; el
; el
= el
->next
) {
1521 MachineClass
*temp
= el
->data
;
1523 if (temp
->is_default
) {
1529 g_slist_free(machines
);
1533 MachineInfoList
*qmp_query_machines(Error
**errp
)
1535 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1536 MachineInfoList
*mach_list
= NULL
;
1538 for (el
= machines
; el
; el
= el
->next
) {
1539 MachineClass
*mc
= el
->data
;
1540 MachineInfoList
*entry
;
1543 info
= g_malloc0(sizeof(*info
));
1544 if (mc
->is_default
) {
1545 info
->has_is_default
= true;
1546 info
->is_default
= true;
1550 info
->has_alias
= true;
1551 info
->alias
= g_strdup(mc
->alias
);
1554 info
->name
= g_strdup(mc
->name
);
1555 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1556 info
->hotpluggable_cpus
= mc
->has_hotpluggable_cpus
;
1558 entry
= g_malloc0(sizeof(*entry
));
1559 entry
->value
= info
;
1560 entry
->next
= mach_list
;
1564 g_slist_free(machines
);
1568 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1570 ObjectProperty
*prop
;
1571 ObjectPropertyIterator iter
;
1573 if (!qemu_opt_has_help_opt(opts
)) {
1577 object_property_iter_init(&iter
, OBJECT(machine
));
1578 while ((prop
= object_property_iter_next(&iter
))) {
1583 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1584 prop
->name
, prop
->type
);
1585 if (prop
->description
) {
1586 error_printf(" (%s)\n", prop
->description
);
1595 /***********************************************************/
1596 /* main execution loop */
1598 struct vm_change_state_entry
{
1599 VMChangeStateHandler
*cb
;
1601 QLIST_ENTRY (vm_change_state_entry
) entries
;
1604 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1606 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1609 VMChangeStateEntry
*e
;
1611 e
= g_malloc0(sizeof (*e
));
1615 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1619 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1621 QLIST_REMOVE (e
, entries
);
1625 void vm_state_notify(int running
, RunState state
)
1627 VMChangeStateEntry
*e
, *next
;
1629 trace_vm_state_notify(running
, state
);
1631 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1632 e
->cb(e
->opaque
, running
, state
);
1636 static ShutdownCause reset_requested
;
1637 static ShutdownCause shutdown_requested
;
1638 static int shutdown_signal
;
1639 static pid_t shutdown_pid
;
1640 static int powerdown_requested
;
1641 static int debug_requested
;
1642 static int suspend_requested
;
1643 static WakeupReason wakeup_reason
;
1644 static NotifierList powerdown_notifiers
=
1645 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1646 static NotifierList suspend_notifiers
=
1647 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1648 static NotifierList wakeup_notifiers
=
1649 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1650 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1652 ShutdownCause
qemu_shutdown_requested_get(void)
1654 return shutdown_requested
;
1657 ShutdownCause
qemu_reset_requested_get(void)
1659 return reset_requested
;
1662 static int qemu_shutdown_requested(void)
1664 return atomic_xchg(&shutdown_requested
, SHUTDOWN_CAUSE_NONE
);
1667 static void qemu_kill_report(void)
1669 if (!qtest_driver() && shutdown_signal
) {
1670 if (shutdown_pid
== 0) {
1671 /* This happens for eg ^C at the terminal, so it's worth
1672 * avoiding printing an odd message in that case.
1674 error_report("terminating on signal %d", shutdown_signal
);
1676 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1678 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1679 shutdown_signal
, shutdown_pid
,
1680 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1681 g_free(shutdown_cmd
);
1683 shutdown_signal
= 0;
1687 static ShutdownCause
qemu_reset_requested(void)
1689 ShutdownCause r
= reset_requested
;
1691 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1692 reset_requested
= SHUTDOWN_CAUSE_NONE
;
1695 return SHUTDOWN_CAUSE_NONE
;
1698 static int qemu_suspend_requested(void)
1700 int r
= suspend_requested
;
1701 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1702 suspend_requested
= 0;
1708 static WakeupReason
qemu_wakeup_requested(void)
1710 return wakeup_reason
;
1713 static int qemu_powerdown_requested(void)
1715 int r
= powerdown_requested
;
1716 powerdown_requested
= 0;
1720 static int qemu_debug_requested(void)
1722 int r
= debug_requested
;
1723 debug_requested
= 0;
1728 * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE.
1730 void qemu_system_reset(ShutdownCause reason
)
1734 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1736 cpu_synchronize_all_states();
1738 if (mc
&& mc
->reset
) {
1741 qemu_devices_reset();
1744 qapi_event_send_reset(shutdown_caused_by_guest(reason
),
1747 cpu_synchronize_all_post_reset();
1750 void qemu_system_guest_panicked(GuestPanicInformation
*info
)
1752 qemu_log_mask(LOG_GUEST_ERROR
, "Guest crashed");
1755 current_cpu
->crash_occurred
= true;
1757 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
,
1758 !!info
, info
, &error_abort
);
1759 vm_stop(RUN_STATE_GUEST_PANICKED
);
1761 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1762 !!info
, info
, &error_abort
);
1763 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC
);
1767 if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_HYPER_V
) {
1768 qemu_log_mask(LOG_GUEST_ERROR
, "\nHV crash parameters: (%#"PRIx64
1769 " %#"PRIx64
" %#"PRIx64
" %#"PRIx64
" %#"PRIx64
")\n",
1770 info
->u
.hyper_v
.arg1
,
1771 info
->u
.hyper_v
.arg2
,
1772 info
->u
.hyper_v
.arg3
,
1773 info
->u
.hyper_v
.arg4
,
1774 info
->u
.hyper_v
.arg5
);
1775 } else if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_S390
) {
1776 qemu_log_mask(LOG_GUEST_ERROR
, " on cpu %d: %s\n"
1777 "PSW: 0x%016" PRIx64
" 0x%016" PRIx64
"\n",
1779 S390CrashReason_str(info
->u
.s390
.reason
),
1780 info
->u
.s390
.psw_mask
,
1781 info
->u
.s390
.psw_addr
);
1783 qapi_free_GuestPanicInformation(info
);
1787 void qemu_system_reset_request(ShutdownCause reason
)
1790 shutdown_requested
= reason
;
1792 reset_requested
= reason
;
1795 qemu_notify_event();
1798 static void qemu_system_suspend(void)
1801 notifier_list_notify(&suspend_notifiers
, NULL
);
1802 runstate_set(RUN_STATE_SUSPENDED
);
1803 qapi_event_send_suspend(&error_abort
);
1806 void qemu_system_suspend_request(void)
1808 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1811 suspend_requested
= 1;
1813 qemu_notify_event();
1816 void qemu_register_suspend_notifier(Notifier
*notifier
)
1818 notifier_list_add(&suspend_notifiers
, notifier
);
1821 void qemu_system_wakeup_request(WakeupReason reason
)
1823 trace_system_wakeup_request(reason
);
1825 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1828 if (!(wakeup_reason_mask
& (1 << reason
))) {
1831 runstate_set(RUN_STATE_RUNNING
);
1832 wakeup_reason
= reason
;
1833 qemu_notify_event();
1836 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1839 wakeup_reason_mask
|= (1 << reason
);
1841 wakeup_reason_mask
&= ~(1 << reason
);
1845 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1847 notifier_list_add(&wakeup_notifiers
, notifier
);
1850 void qemu_system_killed(int signal
, pid_t pid
)
1852 shutdown_signal
= signal
;
1856 /* Cannot call qemu_system_shutdown_request directly because
1857 * we are in a signal handler.
1859 shutdown_requested
= SHUTDOWN_CAUSE_HOST_SIGNAL
;
1860 qemu_notify_event();
1863 void qemu_system_shutdown_request(ShutdownCause reason
)
1865 trace_qemu_system_shutdown_request(reason
);
1866 replay_shutdown_request(reason
);
1867 shutdown_requested
= reason
;
1868 qemu_notify_event();
1871 static void qemu_system_powerdown(void)
1873 qapi_event_send_powerdown(&error_abort
);
1874 notifier_list_notify(&powerdown_notifiers
, NULL
);
1877 void qemu_system_powerdown_request(void)
1879 trace_qemu_system_powerdown_request();
1880 powerdown_requested
= 1;
1881 qemu_notify_event();
1884 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1886 notifier_list_add(&powerdown_notifiers
, notifier
);
1889 void qemu_system_debug_request(void)
1891 debug_requested
= 1;
1892 qemu_notify_event();
1895 static bool main_loop_should_exit(void)
1898 ShutdownCause request
;
1900 if (qemu_debug_requested()) {
1901 vm_stop(RUN_STATE_DEBUG
);
1903 if (qemu_suspend_requested()) {
1904 qemu_system_suspend();
1906 request
= qemu_shutdown_requested();
1909 qapi_event_send_shutdown(shutdown_caused_by_guest(request
),
1912 vm_stop(RUN_STATE_SHUTDOWN
);
1917 request
= qemu_reset_requested();
1920 qemu_system_reset(request
);
1922 if (!runstate_check(RUN_STATE_RUNNING
) &&
1923 !runstate_check(RUN_STATE_INMIGRATE
)) {
1924 runstate_set(RUN_STATE_PRELAUNCH
);
1927 if (qemu_wakeup_requested()) {
1929 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
1930 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1931 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1933 qapi_event_send_wakeup(&error_abort
);
1935 if (qemu_powerdown_requested()) {
1936 qemu_system_powerdown();
1938 if (qemu_vmstop_requested(&r
)) {
1944 static void main_loop(void)
1946 #ifdef CONFIG_PROFILER
1950 #ifdef CONFIG_PROFILER
1951 ti
= profile_getclock();
1953 main_loop_wait(false);
1954 #ifdef CONFIG_PROFILER
1955 dev_time
+= profile_getclock() - ti
;
1957 } while (!main_loop_should_exit());
1960 static void version(void)
1962 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
1963 QEMU_COPYRIGHT
"\n");
1966 static void QEMU_NORETURN
help(int exitcode
)
1969 printf("usage: %s [options] [disk_image]\n\n"
1970 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1971 error_get_progname());
1973 #define QEMU_OPTIONS_GENERATE_HELP
1974 #include "qemu-options-wrapper.h"
1976 printf("\nDuring emulation, the following keys are useful:\n"
1977 "ctrl-alt-f toggle full screen\n"
1978 "ctrl-alt-n switch to virtual console 'n'\n"
1979 "ctrl-alt toggle mouse and keyboard grab\n"
1981 "When using -nographic, press 'ctrl-a h' to get some help.\n"
1983 QEMU_HELP_BOTTOM
"\n");
1988 #define HAS_ARG 0x0001
1990 typedef struct QEMUOption
{
1997 static const QEMUOption qemu_options
[] = {
1998 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1999 #define QEMU_OPTIONS_GENERATE_OPTIONS
2000 #include "qemu-options-wrapper.h"
2004 typedef struct VGAInterfaceInfo
{
2005 const char *opt_name
; /* option name */
2006 const char *name
; /* human-readable name */
2007 /* Class names indicating that support is available.
2008 * If no class is specified, the interface is always available */
2009 const char *class_names
[2];
2012 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
2018 .name
= "standard VGA",
2019 .class_names
= { "VGA", "isa-vga" },
2022 .opt_name
= "cirrus",
2023 .name
= "Cirrus VGA",
2024 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
2027 .opt_name
= "vmware",
2028 .name
= "VMWare SVGA",
2029 .class_names
= { "vmware-svga" },
2032 .opt_name
= "virtio",
2033 .name
= "Virtio VGA",
2034 .class_names
= { "virtio-vga" },
2039 .class_names
= { "qxl-vga" },
2043 .name
= "TCX framebuffer",
2044 .class_names
= { "SUNW,tcx" },
2048 .name
= "CG3 framebuffer",
2049 .class_names
= { "cgthree" },
2052 .opt_name
= "xenfb",
2056 static bool vga_interface_available(VGAInterfaceType t
)
2058 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2060 assert(t
< VGA_TYPE_MAX
);
2061 return !ti
->class_names
[0] ||
2062 object_class_by_name(ti
->class_names
[0]) ||
2063 object_class_by_name(ti
->class_names
[1]);
2066 static void select_vgahw(const char *p
)
2071 assert(vga_interface_type
== VGA_NONE
);
2072 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2073 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2074 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2075 if (!vga_interface_available(t
)) {
2076 error_report("%s not available", ti
->name
);
2079 vga_interface_type
= t
;
2083 if (t
== VGA_TYPE_MAX
) {
2085 error_report("unknown vga type: %s", p
);
2089 const char *nextopt
;
2091 if (strstart(opts
, ",retrace=", &nextopt
)) {
2093 if (strstart(opts
, "dumb", &nextopt
))
2094 vga_retrace_method
= VGA_RETRACE_DUMB
;
2095 else if (strstart(opts
, "precise", &nextopt
))
2096 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2097 else goto invalid_vga
;
2098 } else goto invalid_vga
;
2103 static void parse_display(const char *p
)
2107 if (strstart(p
, "sdl", &opts
)) {
2108 dpy
.type
= DISPLAY_TYPE_SDL
;
2110 const char *nextopt
;
2112 if (strstart(opts
, ",frame=", &nextopt
)) {
2113 g_printerr("The frame= sdl option is deprecated, and will be\n"
2114 "removed in a future release.\n");
2116 if (strstart(opts
, "on", &nextopt
)) {
2118 } else if (strstart(opts
, "off", &nextopt
)) {
2121 goto invalid_sdl_args
;
2123 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2125 if (strstart(opts
, "on", &nextopt
)) {
2127 } else if (strstart(opts
, "off", &nextopt
)) {
2130 goto invalid_sdl_args
;
2132 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2134 if (strstart(opts
, "on", &nextopt
)) {
2136 } else if (strstart(opts
, "off", &nextopt
)) {
2139 goto invalid_sdl_args
;
2141 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2143 dpy
.has_window_close
= true;
2144 if (strstart(opts
, "on", &nextopt
)) {
2145 dpy
.window_close
= true;
2146 } else if (strstart(opts
, "off", &nextopt
)) {
2147 dpy
.window_close
= false;
2149 goto invalid_sdl_args
;
2151 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2154 if (strstart(opts
, "on", &nextopt
)) {
2156 } else if (strstart(opts
, "off", &nextopt
)) {
2159 goto invalid_sdl_args
;
2163 error_report("invalid SDL option string");
2168 } else if (strstart(p
, "vnc", &opts
)) {
2170 vnc_parse(opts
+ 1, &error_fatal
);
2172 error_report("VNC requires a display argument vnc=<display>");
2175 } else if (strstart(p
, "egl-headless", &opts
)) {
2176 dpy
.type
= DISPLAY_TYPE_EGL_HEADLESS
;
2177 } else if (strstart(p
, "curses", &opts
)) {
2178 dpy
.type
= DISPLAY_TYPE_CURSES
;
2179 } else if (strstart(p
, "gtk", &opts
)) {
2180 dpy
.type
= DISPLAY_TYPE_GTK
;
2182 const char *nextopt
;
2184 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2186 dpy
.u
.gtk
.has_grab_on_hover
= true;
2187 if (strstart(opts
, "on", &nextopt
)) {
2188 dpy
.u
.gtk
.grab_on_hover
= true;
2189 } else if (strstart(opts
, "off", &nextopt
)) {
2190 dpy
.u
.gtk
.grab_on_hover
= false;
2192 goto invalid_gtk_args
;
2194 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2197 if (strstart(opts
, "on", &nextopt
)) {
2199 } else if (strstart(opts
, "off", &nextopt
)) {
2202 goto invalid_gtk_args
;
2206 error_report("invalid GTK option string");
2211 } else if (strstart(p
, "none", &opts
)) {
2212 dpy
.type
= DISPLAY_TYPE_NONE
;
2214 error_report("unknown display type");
2219 static int balloon_parse(const char *arg
)
2223 warn_report("This option is deprecated. "
2224 "Use '--device virtio-balloon' to enable the balloon device.");
2226 if (strcmp(arg
, "none") == 0) {
2230 if (!strncmp(arg
, "virtio", 6)) {
2231 if (arg
[6] == ',') {
2232 /* have params -> parse them */
2233 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2238 /* create empty opts */
2239 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2242 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2249 #if defined(CONFIG_RUBY)
2250 /* Ruby interface for QEMU. See README.EXT for programming example. */
2254 static VALUE
qemu_open(int argc
, VALUE
*argv
, VALUE klass
)
2257 for (i
= 0; i
< argc
; i
++) {
2258 argv
[i
] = StringValue(argv
[i
]);
2259 fprintf(stderr
, "argv[%d] = %s\n", i
, StringValuePtr(argv
[i
]));
2261 //~ if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
2262 //~ mode = 0666; /* default value */
2264 return INT2FIX(argc
);
2267 void Init_qemu(void)
2269 printf("%s\n", __func__
);
2270 VALUE cQEMU
= rb_define_class("QEMU", rb_cObject
);
2271 rb_define_singleton_method(cQEMU
, "run", qemu_open
, -1);
2276 #endif /* CONFIG_RUBY */
2278 #if defined(CONFIG_DLL)
2279 BOOL APIENTRY
DllMain(HINSTANCE hModule
, DWORD ul_reason_for_call
, LPVOID data
)
2283 #endif /* CONFIG_DLL */
2285 char *qemu_find_file(int type
, const char *name
)
2291 /* Try the name as a straight path first */
2292 if (access(name
, R_OK
) == 0) {
2293 trace_load_file(name
, name
);
2294 return g_strdup(name
);
2298 case QEMU_FILE_TYPE_BIOS
:
2301 case QEMU_FILE_TYPE_KEYMAP
:
2302 subdir
= "keymaps/";
2308 for (i
= 0; i
< data_dir_idx
; i
++) {
2309 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2310 if (access(buf
, R_OK
) == 0) {
2311 trace_load_file(name
, buf
);
2319 static void qemu_add_data_dir(const char *path
)
2326 if (data_dir_idx
== ARRAY_SIZE(data_dir
)) {
2329 for (i
= 0; i
< data_dir_idx
; i
++) {
2330 if (strcmp(data_dir
[i
], path
) == 0) {
2331 return; /* duplicate */
2334 data_dir
[data_dir_idx
++] = g_strdup(path
);
2337 static inline bool nonempty_str(const char *str
)
2342 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2346 const char *name
, *file
, *str
;
2347 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2349 if (fw_cfg
== NULL
) {
2350 error_report("fw_cfg device not available");
2353 name
= qemu_opt_get(opts
, "name");
2354 file
= qemu_opt_get(opts
, "file");
2355 str
= qemu_opt_get(opts
, "string");
2357 /* we need name and either a file or the content string */
2358 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2359 error_report("invalid argument(s)");
2362 if (nonempty_str(file
) && nonempty_str(str
)) {
2363 error_report("file and string are mutually exclusive");
2366 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2367 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2370 if (strncmp(name
, "opt/", 4) != 0) {
2371 warn_report("externally provided fw_cfg item names "
2372 "should be prefixed with \"opt/\"");
2374 if (nonempty_str(str
)) {
2375 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2376 buf
= g_memdup(str
, size
);
2378 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2379 error_report("can't load %s", file
);
2383 /* For legacy, keep user files in a specific global order. */
2384 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2385 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2386 fw_cfg_reset_order_override(fw_cfg
);
2390 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2392 return qdev_device_help(opts
);
2395 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2400 dev
= qdev_device_add(opts
, &err
);
2402 error_report_err(err
);
2405 object_unref(OBJECT(dev
));
2409 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2411 Error
*local_err
= NULL
;
2413 if (!qemu_chr_new_from_opts(opts
, &local_err
)) {
2415 error_report_err(local_err
);
2423 #ifdef CONFIG_VIRTFS
2424 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2426 return qemu_fsdev_add(opts
);
2430 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2433 const char *chardev
;
2437 mode
= qemu_opt_get(opts
, "mode");
2441 if (strcmp(mode
, "readline") == 0) {
2442 flags
= MONITOR_USE_READLINE
;
2443 } else if (strcmp(mode
, "control") == 0) {
2444 flags
= MONITOR_USE_CONTROL
;
2446 error_report("unknown monitor mode \"%s\"", mode
);
2450 if (qemu_opt_get_bool(opts
, "pretty", 0))
2451 flags
|= MONITOR_USE_PRETTY
;
2453 /* OOB is off by default */
2454 if (qemu_opt_get_bool(opts
, "x-oob", 0)) {
2455 flags
|= MONITOR_USE_OOB
;
2458 chardev
= qemu_opt_get(opts
, "chardev");
2459 chr
= qemu_chr_find(chardev
);
2461 error_report("chardev \"%s\" not found", chardev
);
2465 monitor_init(chr
, flags
);
2469 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2471 static int monitor_device_index
= 0;
2476 if (strstart(optarg
, "chardev:", &p
)) {
2477 snprintf(label
, sizeof(label
), "%s", p
);
2479 snprintf(label
, sizeof(label
), "compat_monitor%d",
2480 monitor_device_index
);
2481 opts
= qemu_chr_parse_compat(label
, optarg
);
2483 error_report("parse error: %s", optarg
);
2488 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2489 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2490 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2491 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2492 monitor_device_index
++;
2495 struct device_config
{
2497 DEV_USB
, /* -usbdevice */
2499 DEV_SERIAL
, /* -serial */
2500 DEV_PARALLEL
, /* -parallel */
2501 DEV_VIRTCON
, /* -virtioconsole */
2502 DEV_DEBUGCON
, /* -debugcon */
2503 DEV_GDB
, /* -gdb, -s */
2504 DEV_SCLP
, /* s390 sclp */
2506 const char *cmdline
;
2508 QTAILQ_ENTRY(device_config
) next
;
2511 static QTAILQ_HEAD(, device_config
) device_configs
=
2512 QTAILQ_HEAD_INITIALIZER(device_configs
);
2514 static void add_device_config(int type
, const char *cmdline
)
2516 struct device_config
*conf
;
2518 conf
= g_malloc0(sizeof(*conf
));
2520 conf
->cmdline
= cmdline
;
2521 loc_save(&conf
->loc
);
2522 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2525 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2527 struct device_config
*conf
;
2530 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2531 if (conf
->type
!= type
)
2533 loc_push_restore(&conf
->loc
);
2534 rc
= func(conf
->cmdline
);
2535 loc_pop(&conf
->loc
);
2543 static int serial_parse(const char *devname
)
2545 static int index
= 0;
2548 if (strcmp(devname
, "none") == 0)
2550 if (index
== MAX_SERIAL_PORTS
) {
2551 error_report("too many serial ports");
2554 snprintf(label
, sizeof(label
), "serial%d", index
);
2555 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2556 if (!serial_hds
[index
]) {
2557 error_report("could not connect serial device"
2558 " to character backend '%s'", devname
);
2565 static int parallel_parse(const char *devname
)
2567 static int index
= 0;
2570 if (strcmp(devname
, "none") == 0)
2572 if (index
== MAX_PARALLEL_PORTS
) {
2573 error_report("too many parallel ports");
2576 snprintf(label
, sizeof(label
), "parallel%d", index
);
2577 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2578 if (!parallel_hds
[index
]) {
2579 error_report("could not connect parallel device"
2580 " to character backend '%s'", devname
);
2587 static int virtcon_parse(const char *devname
)
2589 QemuOptsList
*device
= qemu_find_opts("device");
2590 static int index
= 0;
2592 QemuOpts
*bus_opts
, *dev_opts
;
2594 if (strcmp(devname
, "none") == 0)
2596 if (index
== MAX_VIRTIO_CONSOLES
) {
2597 error_report("too many virtio consoles");
2601 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2602 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2604 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2605 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2607 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2608 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2609 if (!virtcon_hds
[index
]) {
2610 error_report("could not connect virtio console"
2611 " to character backend '%s'", devname
);
2614 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2620 static int sclp_parse(const char *devname
)
2622 QemuOptsList
*device
= qemu_find_opts("device");
2623 static int index
= 0;
2627 if (strcmp(devname
, "none") == 0) {
2630 if (index
== MAX_SCLP_CONSOLES
) {
2631 error_report("too many sclp consoles");
2635 assert(arch_type
== QEMU_ARCH_S390X
);
2637 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2638 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2640 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2641 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2642 if (!sclp_hds
[index
]) {
2643 error_report("could not connect sclp console"
2644 " to character backend '%s'", devname
);
2647 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2653 static int debugcon_parse(const char *devname
)
2657 if (!qemu_chr_new("debugcon", devname
)) {
2660 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2662 error_report("already have a debugcon device");
2665 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2666 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2670 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2672 const MachineClass
*mc1
= a
, *mc2
= b
;
2675 if (mc1
->family
== NULL
) {
2676 if (mc2
->family
== NULL
) {
2677 /* Compare standalone machine types against each other; they sort
2678 * in increasing order.
2680 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2681 object_class_get_name(OBJECT_CLASS(mc2
)));
2684 /* Standalone machine types sort after families. */
2688 if (mc2
->family
== NULL
) {
2689 /* Families sort before standalone machine types. */
2693 /* Families sort between each other alphabetically increasingly. */
2694 res
= strcmp(mc1
->family
, mc2
->family
);
2699 /* Within the same family, machine types sort in decreasing order. */
2700 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2701 object_class_get_name(OBJECT_CLASS(mc1
)));
2704 static MachineClass
*machine_parse(const char *name
)
2706 MachineClass
*mc
= NULL
;
2707 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2710 mc
= find_machine(name
);
2713 g_slist_free(machines
);
2716 if (name
&& !is_help_option(name
)) {
2717 error_report("unsupported machine type");
2718 error_printf("Use -machine help to list supported machines\n");
2720 printf("Supported machines are:\n");
2721 machines
= g_slist_sort(machines
, machine_class_cmp
);
2722 for (el
= machines
; el
; el
= el
->next
) {
2723 MachineClass
*mc
= el
->data
;
2725 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2727 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2728 mc
->is_default
? " (default)" : "");
2732 g_slist_free(machines
);
2733 exit(!name
|| !is_help_option(name
));
2736 void qemu_add_exit_notifier(Notifier
*notify
)
2738 notifier_list_add(&exit_notifiers
, notify
);
2741 void qemu_remove_exit_notifier(Notifier
*notify
)
2743 notifier_remove(notify
);
2746 static void qemu_run_exit_notifiers(void)
2748 notifier_list_notify(&exit_notifiers
, NULL
);
2751 bool machine_init_done
;
2753 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2755 notifier_list_add(&machine_init_done_notifiers
, notify
);
2756 if (machine_init_done
) {
2757 notify
->notify(notify
, NULL
);
2761 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2763 notifier_remove(notify
);
2766 static void qemu_run_machine_init_done_notifiers(void)
2768 machine_init_done
= true;
2769 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2772 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2773 const char **poptarg
, int *poptind
)
2775 const QEMUOption
*popt
;
2776 int optind
= *poptind
;
2777 char *r
= argv
[optind
];
2780 loc_set_cmdline(argv
, optind
, 1);
2782 /* Treat --foo the same as -foo. */
2785 popt
= qemu_options
;
2788 error_report("invalid option");
2791 if (!strcmp(popt
->name
, r
+ 1))
2795 if (popt
->flags
& HAS_ARG
) {
2796 if (optind
>= argc
) {
2797 error_report("requires an argument");
2800 optarg
= argv
[optind
++];
2801 loc_set_cmdline(argv
, optind
- 2, 2);
2812 static MachineClass
*select_machine(void)
2814 MachineClass
*machine_class
= find_default_machine();
2819 loc_push_none(&loc
);
2821 opts
= qemu_get_machine_opts();
2822 qemu_opts_loc_restore(opts
);
2824 optarg
= qemu_opt_get(opts
, "type");
2826 machine_class
= machine_parse(optarg
);
2829 if (!machine_class
) {
2830 error_report("No machine specified, and there is no default");
2831 error_printf("Use -machine help to list supported machines\n");
2836 return machine_class
;
2839 static int machine_set_property(void *opaque
,
2840 const char *name
, const char *value
,
2843 Object
*obj
= OBJECT(opaque
);
2844 Error
*local_err
= NULL
;
2847 if (strcmp(name
, "type") == 0) {
2851 qom_name
= g_strdup(name
);
2852 for (p
= qom_name
; *p
; p
++) {
2858 object_property_parse(obj
, value
, qom_name
, &local_err
);
2862 error_report_err(local_err
);
2871 * Initial object creation happens before all other
2872 * QEMU data types are created. The majority of objects
2873 * can be created at this point. The rng-egd object
2874 * cannot be created here, as it depends on the chardev
2877 static bool object_create_initial(const char *type
)
2879 if (g_str_equal(type
, "rng-egd") ||
2880 g_str_has_prefix(type
, "pr-manager-")) {
2884 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
2885 if (g_str_equal(type
, "cryptodev-vhost-user")) {
2891 * return false for concrete netfilters since
2892 * they depend on netdevs already existing
2894 if (g_str_equal(type
, "filter-buffer") ||
2895 g_str_equal(type
, "filter-dump") ||
2896 g_str_equal(type
, "filter-mirror") ||
2897 g_str_equal(type
, "filter-redirector") ||
2898 g_str_equal(type
, "colo-compare") ||
2899 g_str_equal(type
, "filter-rewriter") ||
2900 g_str_equal(type
, "filter-replay")) {
2904 /* Memory allocation by backends needs to be done
2905 * after configure_accelerator() (due to the tcg_enabled()
2906 * checks at memory_region_init_*()).
2908 * Also, allocation of large amounts of memory may delay
2909 * chardev initialization for too long, and trigger timeouts
2910 * on software that waits for a monitor socket to be created
2913 if (g_str_has_prefix(type
, "memory-backend-")) {
2922 * The remainder of object creation happens after the
2923 * creation of chardev, fsdev, net clients and device data types.
2925 static bool object_create_delayed(const char *type
)
2927 return !object_create_initial(type
);
2931 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2935 const char *mem_str
;
2936 const char *maxmem_str
, *slots_str
;
2937 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2938 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2941 loc_push_none(&loc
);
2942 qemu_opts_loc_restore(opts
);
2945 mem_str
= qemu_opt_get(opts
, "size");
2948 error_report("missing 'size' option value");
2952 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2954 /* Fix up legacy suffix-less format */
2955 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2956 uint64_t overflow_check
= sz
;
2959 if ((sz
>> 20) != overflow_check
) {
2960 error_report("too large 'size' option value");
2966 /* backward compatibility behaviour for case "-m 0" */
2968 sz
= default_ram_size
;
2971 sz
= QEMU_ALIGN_UP(sz
, 8192);
2973 if (ram_size
!= sz
) {
2974 error_report("ram size too large");
2978 /* store value for the future use */
2979 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2980 *maxram_size
= ram_size
;
2982 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2983 slots_str
= qemu_opt_get(opts
, "slots");
2984 if (maxmem_str
&& slots_str
) {
2987 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2988 slots
= qemu_opt_get_number(opts
, "slots", 0);
2989 if (sz
< ram_size
) {
2990 error_report("invalid value of -m option maxmem: "
2991 "maximum memory size (0x%" PRIx64
") must be at least "
2992 "the initial memory size (0x" RAM_ADDR_FMT
")",
2995 } else if (sz
> ram_size
) {
2997 error_report("invalid value of -m option: maxmem was "
2998 "specified, but no hotplug slots were specified");
3002 error_report("invalid value of -m option maxmem: "
3003 "memory slots were specified but maximum memory size "
3004 "(0x%" PRIx64
") is equal to the initial memory size "
3005 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
3011 } else if ((!maxmem_str
&& slots_str
) ||
3012 (maxmem_str
&& !slots_str
)) {
3013 error_report("invalid -m option value: missing "
3014 "'%s' option", slots_str
? "maxmem" : "slots");
3021 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
3025 g
= g_malloc0(sizeof(*g
));
3026 g
->driver
= qemu_opt_get(opts
, "driver");
3027 g
->property
= qemu_opt_get(opts
, "property");
3028 g
->value
= qemu_opt_get(opts
, "value");
3029 g
->user_provided
= true;
3030 g
->errp
= &error_fatal
;
3031 qdev_prop_register_global(g
);
3035 static int qemu_read_default_config_file(void)
3039 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
3040 if (ret
< 0 && ret
!= -ENOENT
) {
3047 static void user_register_global_props(void)
3049 qemu_opts_foreach(qemu_find_opts("global"),
3050 global_init_func
, NULL
, NULL
);
3054 * Note: we should see that these properties are actually having a
3055 * priority: accel < machine < user. This means e.g. when user
3056 * specifies something in "-global", it'll always be used with highest
3057 * priority than either machine/accelerator compat properties.
3059 static void register_global_properties(MachineState
*ms
)
3061 accel_register_compat_props(ms
->accelerator
);
3062 machine_register_compat_props(ms
);
3063 user_register_global_props();
3066 int main(int argc
, char **argv
)
3069 int snapshot
, linux_boot
;
3070 const char *initrd_filename
;
3071 const char *kernel_filename
, *kernel_cmdline
;
3072 const char *boot_order
= NULL
;
3073 const char *boot_once
= NULL
;
3075 QemuOpts
*opts
, *machine_opts
;
3076 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
3077 QemuOptsList
*olist
;
3080 const char *loadvm
= NULL
;
3081 MachineClass
*machine_class
;
3082 const char *cpu_model
;
3083 const char *vga_model
= NULL
;
3084 const char *qtest_chrdev
= NULL
;
3085 const char *qtest_log
= NULL
;
3086 const char *pid_file
= NULL
;
3087 const char *incoming
= NULL
;
3088 bool userconfig
= true;
3089 bool nographic
= false;
3090 int display_remote
= 0;
3091 const char *log_mask
= NULL
;
3092 const char *log_file
= NULL
;
3093 char *trace_file
= NULL
;
3094 ram_addr_t maxram_size
;
3095 uint64_t ram_slots
= 0;
3096 FILE *vmstate_dump_file
= NULL
;
3097 Error
*main_loop_err
= NULL
;
3099 bool list_data_dirs
= false;
3101 typedef struct BlockdevOptions_queue
{
3102 BlockdevOptions
*bdo
;
3104 QSIMPLEQ_ENTRY(BlockdevOptions_queue
) entry
;
3105 } BlockdevOptions_queue
;
3106 QSIMPLEQ_HEAD(, BlockdevOptions_queue
) bdo_queue
3107 = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
3109 module_call_init(MODULE_INIT_TRACE
);
3111 qemu_init_cpu_list();
3112 qemu_init_cpu_loop();
3114 qemu_mutex_lock_iothread();
3116 atexit(qemu_run_exit_notifiers
);
3117 error_set_progname(argv
[0]);
3118 qemu_init_exec_dir(argv
[0]);
3120 module_call_init(MODULE_INIT_QOM
);
3122 qemu_add_opts(&qemu_drive_opts
);
3123 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3124 qemu_add_drive_opts(&qemu_common_drive_opts
);
3125 qemu_add_drive_opts(&qemu_drive_opts
);
3126 qemu_add_drive_opts(&bdrv_runtime_opts
);
3127 qemu_add_opts(&qemu_chardev_opts
);
3128 qemu_add_opts(&qemu_device_opts
);
3129 qemu_add_opts(&qemu_netdev_opts
);
3130 qemu_add_opts(&qemu_nic_opts
);
3131 qemu_add_opts(&qemu_net_opts
);
3132 qemu_add_opts(&qemu_rtc_opts
);
3133 qemu_add_opts(&qemu_global_opts
);
3134 qemu_add_opts(&qemu_mon_opts
);
3135 qemu_add_opts(&qemu_trace_opts
);
3136 qemu_add_opts(&qemu_option_rom_opts
);
3137 qemu_add_opts(&qemu_machine_opts
);
3138 qemu_add_opts(&qemu_accel_opts
);
3139 qemu_add_opts(&qemu_mem_opts
);
3140 qemu_add_opts(&qemu_smp_opts
);
3141 qemu_add_opts(&qemu_boot_opts
);
3142 qemu_add_opts(&qemu_sandbox_opts
);
3143 qemu_add_opts(&qemu_add_fd_opts
);
3144 qemu_add_opts(&qemu_object_opts
);
3145 qemu_add_opts(&qemu_tpmdev_opts
);
3146 qemu_add_opts(&qemu_realtime_opts
);
3147 qemu_add_opts(&qemu_msg_opts
);
3148 qemu_add_opts(&qemu_name_opts
);
3149 qemu_add_opts(&qemu_numa_opts
);
3150 qemu_add_opts(&qemu_icount_opts
);
3151 qemu_add_opts(&qemu_semihosting_config_opts
);
3152 qemu_add_opts(&qemu_fw_cfg_opts
);
3153 module_call_init(MODULE_INIT_OPTS
);
3156 postcopy_infrastructure_init();
3158 if (qcrypto_init(&err
) < 0) {
3159 error_reportf_err(err
, "cannot initialize crypto: ");
3162 rtc_clock
= QEMU_CLOCK_HOST
;
3164 QLIST_INIT (&vm_change_state_head
);
3165 os_setup_early_signal_handling();
3172 bdrv_init_with_whitelist();
3176 /* first pass of option parsing */
3178 while (optind
< argc
) {
3179 if (argv
[optind
][0] != '-') {
3183 const QEMUOption
*popt
;
3185 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3186 switch (popt
->index
) {
3187 case QEMU_OPTION_nodefconfig
:
3188 case QEMU_OPTION_nouserconfig
:
3196 if (qemu_read_default_config_file() < 0) {
3201 /* second pass of option parsing */
3206 if (argv
[optind
][0] != '-') {
3207 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3209 const QEMUOption
*popt
;
3211 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3212 if (!(popt
->arch_mask
& arch_type
)) {
3213 error_report("Option not supported for this target");
3216 switch(popt
->index
) {
3217 case QEMU_OPTION_no_kvm_irqchip
: {
3218 olist
= qemu_find_opts("machine");
3219 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3222 case QEMU_OPTION_cpu
:
3223 /* hw initialization will check this */
3226 case QEMU_OPTION_hda
:
3227 case QEMU_OPTION_hdb
:
3228 case QEMU_OPTION_hdc
:
3229 case QEMU_OPTION_hdd
:
3230 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3233 case QEMU_OPTION_blockdev
:
3236 BlockdevOptions_queue
*bdo
;
3238 v
= qobject_input_visitor_new_str(optarg
, "driver", &err
);
3240 error_report_err(err
);
3244 bdo
= g_new(BlockdevOptions_queue
, 1);
3245 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
3248 loc_save(&bdo
->loc
);
3249 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
3252 case QEMU_OPTION_drive
:
3253 if (drive_def(optarg
) == NULL
) {
3257 case QEMU_OPTION_set
:
3258 if (qemu_set_option(optarg
) != 0)
3261 case QEMU_OPTION_global
:
3262 if (qemu_global_option(optarg
) != 0)
3265 case QEMU_OPTION_mtdblock
:
3266 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3268 case QEMU_OPTION_sd
:
3269 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3271 case QEMU_OPTION_pflash
:
3272 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3274 case QEMU_OPTION_snapshot
:
3277 case QEMU_OPTION_numa
:
3278 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3284 case QEMU_OPTION_display
:
3285 parse_display(optarg
);
3287 case QEMU_OPTION_nographic
:
3288 olist
= qemu_find_opts("machine");
3289 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3291 dpy
.type
= DISPLAY_TYPE_NONE
;
3293 case QEMU_OPTION_curses
:
3294 #ifdef CONFIG_CURSES
3295 dpy
.type
= DISPLAY_TYPE_CURSES
;
3297 error_report("curses support is disabled");
3301 case QEMU_OPTION_portrait
:
3302 graphic_rotate
= 90;
3304 case QEMU_OPTION_rotate
:
3305 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3306 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3307 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3308 error_report("only 90, 180, 270 deg rotation is available");
3312 case QEMU_OPTION_kernel
:
3313 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3316 case QEMU_OPTION_initrd
:
3317 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3320 case QEMU_OPTION_append
:
3321 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3324 case QEMU_OPTION_dtb
:
3325 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3328 case QEMU_OPTION_cdrom
:
3329 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3331 case QEMU_OPTION_boot
:
3332 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3338 case QEMU_OPTION_fda
:
3339 case QEMU_OPTION_fdb
:
3340 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3343 case QEMU_OPTION_no_fd_bootchk
:
3346 case QEMU_OPTION_netdev
:
3348 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3352 case QEMU_OPTION_nic
:
3354 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
3358 case QEMU_OPTION_net
:
3360 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3364 #ifdef CONFIG_LIBISCSI
3365 case QEMU_OPTION_iscsi
:
3366 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3374 case QEMU_OPTION_tftp
:
3375 error_report("The -tftp option is deprecated. "
3376 "Please use '-netdev user,tftp=...' instead.");
3377 legacy_tftp_prefix
= optarg
;
3379 case QEMU_OPTION_bootp
:
3380 error_report("The -bootp option is deprecated. "
3381 "Please use '-netdev user,bootfile=...' instead.");
3382 legacy_bootp_filename
= optarg
;
3384 case QEMU_OPTION_redir
:
3385 error_report("The -redir option is deprecated. "
3386 "Please use '-netdev user,hostfwd=...' instead.");
3387 if (net_slirp_redir(optarg
) < 0)
3391 case QEMU_OPTION_bt
:
3392 add_device_config(DEV_BT
, optarg
);
3394 case QEMU_OPTION_audio_help
:
3398 case QEMU_OPTION_soundhw
:
3399 select_soundhw (optarg
);
3404 case QEMU_OPTION_version
:
3409 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3416 case QEMU_OPTION_tpmdev
:
3417 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3422 case QEMU_OPTION_mempath
:
3425 case QEMU_OPTION_mem_prealloc
:
3434 case QEMU_OPTION_DFILTER
:
3435 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3438 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3440 case QEMU_OPTION_gdb
:
3441 add_device_config(DEV_GDB
, optarg
);
3444 if (is_help_option(optarg
)) {
3445 list_data_dirs
= true;
3447 qemu_add_data_dir(optarg
);
3450 case QEMU_OPTION_bios
:
3451 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3454 case QEMU_OPTION_singlestep
:
3461 keyboard_layout
= optarg
;
3463 case QEMU_OPTION_localtime
:
3465 warn_report("This option is deprecated, "
3466 "use '-rtc base=localtime' instead.");
3468 case QEMU_OPTION_vga
:
3477 w
= strtol(p
, (char **)&p
, 10);
3480 error_report("invalid resolution or depth");
3486 h
= strtol(p
, (char **)&p
, 10);
3491 depth
= strtol(p
, (char **)&p
, 10);
3492 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3493 depth
!= 24 && depth
!= 32)
3495 } else if (*p
== '\0') {
3496 depth
= graphic_depth
;
3503 graphic_depth
= depth
;
3506 case QEMU_OPTION_echr
:
3509 term_escape_char
= strtol(optarg
, &r
, 0);
3511 printf("Bad argument to echr\n");
3514 case QEMU_OPTION_monitor
:
3515 default_monitor
= 0;
3516 if (strncmp(optarg
, "none", 4)) {
3517 monitor_parse(optarg
, "readline", false);
3520 case QEMU_OPTION_qmp
:
3521 monitor_parse(optarg
, "control", false);
3522 default_monitor
= 0;
3524 case QEMU_OPTION_qmp_pretty
:
3525 monitor_parse(optarg
, "control", true);
3526 default_monitor
= 0;
3528 case QEMU_OPTION_mon
:
3529 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3534 default_monitor
= 0;
3536 case QEMU_OPTION_chardev
:
3537 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3543 case QEMU_OPTION_fsdev
:
3544 olist
= qemu_find_opts("fsdev");
3546 error_report("fsdev support is disabled");
3549 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3554 case QEMU_OPTION_virtfs
: {
3557 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
;
3559 olist
= qemu_find_opts("virtfs");
3561 error_report("virtfs support is disabled");
3564 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3569 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3570 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3571 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3574 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3575 qemu_opts_id(opts
) ?:
3576 qemu_opt_get(opts
, "mount_tag"),
3579 error_report("duplicate or invalid fsdev id: %s",
3580 qemu_opt_get(opts
, "mount_tag"));
3584 writeout
= qemu_opt_get(opts
, "writeout");
3586 #ifdef CONFIG_SYNC_FILE_RANGE
3587 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3589 error_report("writeout=immediate not supported "
3590 "on this platform");
3594 qemu_opt_set(fsdev
, "fsdriver",
3595 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3596 path
= qemu_opt_get(opts
, "path");
3598 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3600 security_model
= qemu_opt_get(opts
, "security_model");
3601 if (security_model
) {
3602 qemu_opt_set(fsdev
, "security_model", security_model
,
3605 socket
= qemu_opt_get(opts
, "socket");
3607 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3609 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3611 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3614 qemu_opt_set_bool(fsdev
, "readonly",
3615 qemu_opt_get_bool(opts
, "readonly", 0),
3617 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3619 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3620 qemu_opt_set(device
, "fsdev",
3621 qemu_opts_id(fsdev
), &error_abort
);
3622 qemu_opt_set(device
, "mount_tag",
3623 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3626 case QEMU_OPTION_virtfs_synth
: {
3630 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3633 error_report("duplicate option: %s", "virtfs_synth");
3636 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3638 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3640 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3641 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3642 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3645 case QEMU_OPTION_serial
:
3646 add_device_config(DEV_SERIAL
, optarg
);
3648 if (strncmp(optarg
, "mon:", 4) == 0) {
3649 default_monitor
= 0;
3652 case QEMU_OPTION_watchdog
:
3654 error_report("only one watchdog option may be given");
3659 case QEMU_OPTION_watchdog_action
:
3660 if (select_watchdog_action(optarg
) == -1) {
3661 error_report("unknown -watchdog-action parameter");
3665 case QEMU_OPTION_virtiocon
:
3666 add_device_config(DEV_VIRTCON
, optarg
);
3667 default_virtcon
= 0;
3668 if (strncmp(optarg
, "mon:", 4) == 0) {
3669 default_monitor
= 0;
3672 case QEMU_OPTION_parallel
:
3673 add_device_config(DEV_PARALLEL
, optarg
);
3674 default_parallel
= 0;
3675 if (strncmp(optarg
, "mon:", 4) == 0) {
3676 default_monitor
= 0;
3679 case QEMU_OPTION_debugcon
:
3680 add_device_config(DEV_DEBUGCON
, optarg
);
3682 case QEMU_OPTION_loadvm
:
3685 case QEMU_OPTION_full_screen
:
3686 dpy
.has_full_screen
= true;
3687 dpy
.full_screen
= true;
3689 case QEMU_OPTION_no_frame
:
3690 g_printerr("The -no-frame switch is deprecated, and will be\n"
3691 "removed in a future release.\n");
3694 case QEMU_OPTION_alt_grab
:
3697 case QEMU_OPTION_ctrl_grab
:
3700 case QEMU_OPTION_no_quit
:
3701 dpy
.has_window_close
= true;
3702 dpy
.window_close
= false;
3704 case QEMU_OPTION_sdl
:
3706 dpy
.type
= DISPLAY_TYPE_SDL
;
3709 error_report("SDL support is disabled");
3712 case QEMU_OPTION_pidfile
:
3715 case QEMU_OPTION_win2k_hack
:
3716 win2k_install_hack
= 1;
3718 case QEMU_OPTION_rtc_td_hack
: {
3719 static GlobalProperty slew_lost_ticks
= {
3720 .driver
= "mc146818rtc",
3721 .property
= "lost_tick_policy",
3725 qdev_prop_register_global(&slew_lost_ticks
);
3726 warn_report("This option is deprecated, "
3727 "use '-rtc driftfix=slew' instead.");
3730 case QEMU_OPTION_acpitable
:
3731 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3736 acpi_table_add(opts
, &error_fatal
);
3738 case QEMU_OPTION_smbios
:
3739 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3744 smbios_entry_add(opts
, &error_fatal
);
3746 case QEMU_OPTION_fwcfg
:
3747 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3753 case QEMU_OPTION_enable_kvm
:
3754 olist
= qemu_find_opts("machine");
3755 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3757 case QEMU_OPTION_enable_hax
:
3758 olist
= qemu_find_opts("machine");
3759 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3762 case QEMU_OPTION_machine
:
3763 olist
= qemu_find_opts("machine");
3764 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3769 case QEMU_OPTION_no_kvm
:
3770 olist
= qemu_find_opts("machine");
3771 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3773 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3774 static GlobalProperty kvm_pit_lost_tick_policy
= {
3775 .driver
= "kvm-pit",
3776 .property
= "lost_tick_policy",
3780 warn_report("deprecated, replaced by "
3781 "-global kvm-pit.lost_tick_policy=discard");
3782 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3785 case QEMU_OPTION_accel
:
3786 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3788 optarg
= qemu_opt_get(accel_opts
, "accel");
3789 if (!optarg
|| is_help_option(optarg
)) {
3790 error_printf("Possible accelerators: kvm, xen, hax, tcg\n");
3793 opts
= qemu_opts_create(qemu_find_opts("machine"), NULL
,
3794 false, &error_abort
);
3795 qemu_opt_set(opts
, "accel", optarg
, &error_abort
);
3797 case QEMU_OPTION_usb
:
3798 olist
= qemu_find_opts("machine");
3799 qemu_opts_parse_noisily(olist
, "usb=on", false);
3801 case QEMU_OPTION_usbdevice
:
3802 error_report("'-usbdevice' is deprecated, please use "
3803 "'-device usb-...' instead");
3804 olist
= qemu_find_opts("machine");
3805 qemu_opts_parse_noisily(olist
, "usb=on", false);
3806 add_device_config(DEV_USB
, optarg
);
3808 case QEMU_OPTION_device
:
3809 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3814 case QEMU_OPTION_smp
:
3815 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3820 case QEMU_OPTION_vnc
:
3821 vnc_parse(optarg
, &error_fatal
);
3823 case QEMU_OPTION_no_acpi
:
3826 case QEMU_OPTION_no_hpet
:
3829 case QEMU_OPTION_balloon
:
3830 if (balloon_parse(optarg
) < 0) {
3831 error_report("unknown -balloon argument %s", optarg
);
3835 case QEMU_OPTION_no_reboot
:
3838 case QEMU_OPTION_no_shutdown
:
3841 case QEMU_OPTION_show_cursor
:
3844 case QEMU_OPTION_uuid
:
3845 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3846 error_report("failed to parse UUID string: wrong format");
3849 qemu_uuid_set
= true;
3851 case QEMU_OPTION_option_rom
:
3852 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3853 error_report("too many option ROMs");
3856 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3861 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3862 option_rom
[nb_option_roms
].bootindex
=
3863 qemu_opt_get_number(opts
, "bootindex", -1);
3864 if (!option_rom
[nb_option_roms
].name
) {
3865 error_report("Option ROM file is not specified");
3870 case QEMU_OPTION_semihosting
:
3871 semihosting
.enabled
= true;
3872 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3874 case QEMU_OPTION_semihosting_config
:
3875 semihosting
.enabled
= true;
3876 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3879 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3881 const char *target
= qemu_opt_get(opts
, "target");
3882 if (target
!= NULL
) {
3883 if (strcmp("native", target
) == 0) {
3884 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3885 } else if (strcmp("gdb", target
) == 0) {
3886 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3887 } else if (strcmp("auto", target
) == 0) {
3888 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3890 error_report("unsupported semihosting-config %s",
3895 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3897 /* Set semihosting argument count and vector */
3898 qemu_opt_foreach(opts
, add_semihosting_arg
,
3899 &semihosting
, NULL
);
3901 error_report("unsupported semihosting-config %s", optarg
);
3905 case QEMU_OPTION_name
:
3906 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3912 case QEMU_OPTION_prom_env
:
3913 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3914 error_report("too many prom variables");
3917 prom_envs
[nb_prom_envs
] = optarg
;
3920 case QEMU_OPTION_old_param
:
3923 case QEMU_OPTION_clock
:
3924 /* Clock options no longer exist. Keep this option for
3925 * backward compatibility.
3928 case QEMU_OPTION_startdate
:
3929 warn_report("This option is deprecated, use '-rtc base=' instead.");
3930 configure_rtc_date_offset(optarg
, 1);
3932 case QEMU_OPTION_rtc
:
3933 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3938 configure_rtc(opts
);
3940 case QEMU_OPTION_tb_size
:
3942 error_report("TCG is disabled");
3945 if (qemu_strtoul(optarg
, NULL
, 0, &tcg_tb_size
) < 0) {
3946 error_report("Invalid argument to -tb-size");
3950 case QEMU_OPTION_icount
:
3951 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3957 case QEMU_OPTION_incoming
:
3959 runstate_set(RUN_STATE_INMIGRATE
);
3963 case QEMU_OPTION_only_migratable
:
3965 * TODO: we can remove this option one day, and we
3968 * "-global migration.only-migratable=true"
3970 qemu_global_option("migration.only-migratable=true");
3972 case QEMU_OPTION_nodefaults
:
3975 case QEMU_OPTION_xen_domid
:
3976 if (!(xen_available())) {
3977 error_report("Option not supported for this target");
3980 xen_domid
= atoi(optarg
);
3982 case QEMU_OPTION_xen_create
:
3983 if (!(xen_available())) {
3984 error_report("Option not supported for this target");
3987 xen_mode
= XEN_CREATE
;
3989 case QEMU_OPTION_xen_attach
:
3990 if (!(xen_available())) {
3991 error_report("Option not supported for this target");
3994 xen_mode
= XEN_ATTACH
;
3996 case QEMU_OPTION_xen_domid_restrict
:
3997 if (!(xen_available())) {
3998 error_report("Option not supported for this target");
4001 xen_domid_restrict
= true;
4003 case QEMU_OPTION_trace
:
4005 trace_file
= trace_opt_parse(optarg
);
4007 case QEMU_OPTION_trace_unassigned
:
4008 trace_unassigned
= true;
4010 case QEMU_OPTION_readconfig
:
4012 int ret
= qemu_read_config_file(optarg
);
4014 error_report("read config %s: %s", optarg
,
4020 case QEMU_OPTION_spice
:
4021 olist
= qemu_find_opts("spice");
4023 error_report("spice support is disabled");
4026 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
4032 case QEMU_OPTION_writeconfig
:
4035 if (strcmp(optarg
, "-") == 0) {
4038 fp
= fopen(optarg
, "w");
4040 error_report("open %s: %s", optarg
,
4045 qemu_config_write(fp
);
4051 case QEMU_OPTION_qtest
:
4052 qtest_chrdev
= optarg
;
4054 case QEMU_OPTION_qtest_log
:
4057 case QEMU_OPTION_sandbox
:
4058 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4064 case QEMU_OPTION_add_fd
:
4066 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4072 error_report("File descriptor passing is disabled on this "
4077 case QEMU_OPTION_object
:
4078 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
4084 case QEMU_OPTION_realtime
:
4085 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4090 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4092 case QEMU_OPTION_msg
:
4093 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4098 configure_msg(opts
);
4100 case QEMU_OPTION_dump_vmstate
:
4101 if (vmstate_dump_file
) {
4102 error_report("only one '-dump-vmstate' "
4103 "option may be given");
4106 vmstate_dump_file
= fopen(optarg
, "w");
4107 if (vmstate_dump_file
== NULL
) {
4108 error_report("open %s: %s", optarg
, strerror(errno
));
4113 os_parse_cmd_args(popt
->index
, optarg
);
4118 * Clear error location left behind by the loop.
4119 * Best done right after the loop. Do not insert code here!
4123 replay_configure(icount_opts
);
4125 machine_class
= select_machine();
4127 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4130 rcu_disable_atfork();
4132 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4133 error_report("could not acquire pid file: %s", strerror(errno
));
4137 if (qemu_init_main_loop(&main_loop_err
)) {
4138 error_report_err(main_loop_err
);
4142 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4143 parse_sandbox
, NULL
, NULL
)) {
4147 if (qemu_opts_foreach(qemu_find_opts("name"),
4148 parse_name
, NULL
, NULL
)) {
4153 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4154 parse_add_fd
, NULL
, NULL
)) {
4158 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4159 cleanup_add_fd
, NULL
, NULL
)) {
4164 current_machine
= MACHINE(object_new(object_class_get_name(
4165 OBJECT_CLASS(machine_class
))));
4166 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4169 object_property_add_child(object_get_root(), "machine",
4170 OBJECT(current_machine
), &error_abort
);
4172 if (machine_class
->minimum_page_bits
) {
4173 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4174 /* This would be a board error: specifying a minimum smaller than
4175 * a target's compile-time fixed setting.
4177 g_assert_not_reached();
4181 cpu_exec_init_all();
4183 if (machine_class
->hw_version
) {
4184 qemu_set_hw_version(machine_class
->hw_version
);
4187 if (cpu_model
&& is_help_option(cpu_model
)) {
4188 list_cpus(stdout
, &fprintf
, cpu_model
);
4192 if (!trace_init_backends()) {
4195 trace_init_file(trace_file
);
4197 /* Open the logfile at this point and set the log mask if necessary.
4200 qemu_set_log_filename(log_file
, &error_fatal
);
4205 mask
= qemu_str_to_log_mask(log_mask
);
4207 qemu_print_log_usage(stdout
);
4215 /* add configured firmware directories */
4216 dirs
= g_strsplit(CONFIG_QEMU_FIRMWAREPATH
, G_SEARCHPATH_SEPARATOR_S
, 0);
4217 for (i
= 0; dirs
[i
] != NULL
; i
++) {
4218 qemu_add_data_dir(dirs
[i
]);
4222 /* try to find datadir relative to the executable path */
4223 dir
= os_find_datadir();
4224 qemu_add_data_dir(dir
);
4227 /* add the datadir specified when building */
4228 qemu_add_data_dir(CONFIG_QEMU_DATADIR
);
4230 /* -L help lists the data directories and exits. */
4231 if (list_data_dirs
) {
4232 for (i
= 0; i
< data_dir_idx
; i
++) {
4233 printf("%s\n", data_dir
[i
]);
4238 /* machine_class: default to UP */
4239 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1;
4240 machine_class
->min_cpus
= machine_class
->min_cpus
?: 1;
4241 machine_class
->default_cpus
= machine_class
->default_cpus
?: 1;
4243 /* default to machine_class->default_cpus */
4244 smp_cpus
= machine_class
->default_cpus
;
4245 max_cpus
= machine_class
->default_cpus
;
4247 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4249 /* sanity-check smp_cpus and max_cpus against machine_class */
4250 if (smp_cpus
< machine_class
->min_cpus
) {
4251 error_report("Invalid SMP CPUs %d. The min CPUs "
4252 "supported by machine '%s' is %d", smp_cpus
,
4253 machine_class
->name
, machine_class
->min_cpus
);
4256 if (max_cpus
> machine_class
->max_cpus
) {
4257 error_report("Invalid SMP CPUs %d. The max CPUs "
4258 "supported by machine '%s' is %d", max_cpus
,
4259 machine_class
->name
, machine_class
->max_cpus
);
4264 * Get the default machine options from the machine if it is not already
4265 * specified either by the configuration file or by the command line.
4267 if (machine_class
->default_machine_opts
) {
4268 qemu_opts_set_defaults(qemu_find_opts("machine"),
4269 machine_class
->default_machine_opts
, 0);
4272 qemu_opts_foreach(qemu_find_opts("device"),
4273 default_driver_check
, NULL
, NULL
);
4274 qemu_opts_foreach(qemu_find_opts("global"),
4275 default_driver_check
, NULL
, NULL
);
4277 if (!vga_model
&& !default_vga
) {
4278 vga_interface_type
= VGA_DEVICE
;
4280 if (!has_defaults
|| machine_class
->no_serial
) {
4283 if (!has_defaults
|| machine_class
->no_parallel
) {
4284 default_parallel
= 0;
4286 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4287 default_virtcon
= 0;
4289 if (!has_defaults
|| !machine_class
->use_sclp
) {
4292 if (!has_defaults
|| machine_class
->no_floppy
) {
4295 if (!has_defaults
|| machine_class
->no_cdrom
) {
4298 if (!has_defaults
|| machine_class
->no_sdcard
) {
4301 if (!has_defaults
) {
4302 default_monitor
= 0;
4307 if (is_daemonized()) {
4308 /* According to documentation and historically, -nographic redirects
4309 * serial port, parallel port and monitor to stdio, which does not work
4310 * with -daemonize. We can redirect these to null instead, but since
4311 * -nographic is legacy, let's just error out.
4312 * We disallow -nographic only if all other ports are not redirected
4313 * explicitly, to not break existing legacy setups which uses
4314 * -nographic _and_ redirects all ports explicitly - this is valid
4315 * usage, -nographic is just a no-op in this case.
4318 && (default_parallel
|| default_serial
4319 || default_monitor
|| default_virtcon
)) {
4320 error_report("-nographic cannot be used with -daemonize");
4323 #ifdef CONFIG_CURSES
4324 if (dpy
.type
== DISPLAY_TYPE_CURSES
) {
4325 error_report("curses display cannot be used with -daemonize");
4332 if (default_parallel
)
4333 add_device_config(DEV_PARALLEL
, "null");
4334 if (default_serial
&& default_monitor
) {
4335 add_device_config(DEV_SERIAL
, "mon:stdio");
4336 } else if (default_virtcon
&& default_monitor
) {
4337 add_device_config(DEV_VIRTCON
, "mon:stdio");
4338 } else if (default_sclp
&& default_monitor
) {
4339 add_device_config(DEV_SCLP
, "mon:stdio");
4342 add_device_config(DEV_SERIAL
, "stdio");
4343 if (default_virtcon
)
4344 add_device_config(DEV_VIRTCON
, "stdio");
4346 add_device_config(DEV_SCLP
, "stdio");
4348 if (default_monitor
)
4349 monitor_parse("stdio", "readline", false);
4353 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4354 if (default_parallel
)
4355 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4356 if (default_monitor
)
4357 monitor_parse("vc:80Cx24C", "readline", false);
4358 if (default_virtcon
)
4359 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4361 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4365 #if defined(CONFIG_VNC)
4366 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4370 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
4371 if (!qemu_display_find_default(&dpy
)) {
4372 dpy
.type
= DISPLAY_TYPE_NONE
;
4373 #if defined(CONFIG_VNC)
4374 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4378 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
4379 dpy
.type
= DISPLAY_TYPE_NONE
;
4382 if ((no_frame
|| alt_grab
|| ctrl_grab
) && dpy
.type
!= DISPLAY_TYPE_SDL
) {
4383 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4384 "for SDL, ignoring option");
4386 if (dpy
.has_window_close
&&
4387 (dpy
.type
!= DISPLAY_TYPE_GTK
&& dpy
.type
!= DISPLAY_TYPE_SDL
)) {
4388 error_report("-no-quit is only valid for GTK and SDL, "
4392 qemu_display_early_init(&dpy
);
4393 qemu_console_early_init();
4395 if (dpy
.has_gl
&& dpy
.gl
&& display_opengl
== 0) {
4396 #if defined(CONFIG_OPENGL)
4397 error_report("OpenGL is not supported by the display");
4399 error_report("OpenGL support is disabled");
4407 if (qemu_opts_foreach(qemu_find_opts("object"),
4408 user_creatable_add_opts_foreach
,
4409 object_create_initial
, NULL
)) {
4413 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4414 chardev_init_func
, NULL
, NULL
)) {
4418 #ifdef CONFIG_VIRTFS
4419 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4420 fsdev_init_func
, NULL
, NULL
)) {
4425 if (qemu_opts_foreach(qemu_find_opts("device"),
4426 device_help_func
, NULL
, NULL
)) {
4430 machine_opts
= qemu_get_machine_opts();
4431 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4433 object_unref(OBJECT(current_machine
));
4437 configure_accelerator(current_machine
);
4440 * Register all the global properties, including accel properties,
4441 * machine properties, and user-specified ones.
4443 register_global_properties(current_machine
);
4446 * Migration object can only be created after global properties
4447 * are applied correctly.
4449 migration_object_init();
4452 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4455 machine_opts
= qemu_get_machine_opts();
4456 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4457 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4458 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4459 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4461 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4463 boot_order
= qemu_opt_get(opts
, "order");
4465 validate_bootdevices(boot_order
, &error_fatal
);
4468 boot_once
= qemu_opt_get(opts
, "once");
4470 validate_bootdevices(boot_once
, &error_fatal
);
4473 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4474 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4478 boot_order
= machine_class
->default_boot_order
;
4481 if (!kernel_cmdline
) {
4482 kernel_cmdline
= "";
4483 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4486 linux_boot
= (kernel_filename
!= NULL
);
4488 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4489 error_report("-append only allowed with -kernel option");
4493 if (!linux_boot
&& initrd_filename
!= NULL
) {
4494 error_report("-initrd only allowed with -kernel option");
4498 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4499 /* fall back to the -kernel/-append */
4500 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4503 os_set_line_buffering();
4505 /* spice needs the timers to be initialized by this point */
4510 if (!tcg_enabled()) {
4511 error_report("-icount is not allowed with hardware virtualization");
4514 configure_icount(icount_opts
, &error_abort
);
4515 qemu_opts_del(icount_opts
);
4518 if (tcg_enabled()) {
4519 qemu_tcg_configure(accel_opts
, &error_fatal
);
4523 QemuOptsList
*net
= qemu_find_opts("net");
4524 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4526 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4532 if (net_init_clients(&err
) < 0) {
4533 error_report_err(err
);
4537 if (qemu_opts_foreach(qemu_find_opts("object"),
4538 user_creatable_add_opts_foreach
,
4539 object_create_delayed
, NULL
)) {
4543 if (tpm_init() < 0) {
4547 /* init the bluetooth world */
4548 if (foreach_device_config(DEV_BT
, bt_parse
))
4551 if (!xen_enabled()) {
4552 /* On 32-bit hosts, QEMU is limited by virtual address space */
4553 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4554 error_report("at most 2047 MB RAM can be simulated");
4561 dirty_bitmap_mig_init();
4563 /* If the currently selected machine wishes to override the units-per-bus
4564 * property of its default HBA interface type, do so now. */
4565 if (machine_class
->units_per_default_bus
) {
4566 override_max_devs(machine_class
->block_default_type
,
4567 machine_class
->units_per_default_bus
);
4570 /* open the virtual block devices */
4571 while (!QSIMPLEQ_EMPTY(&bdo_queue
)) {
4572 BlockdevOptions_queue
*bdo
= QSIMPLEQ_FIRST(&bdo_queue
);
4574 QSIMPLEQ_REMOVE_HEAD(&bdo_queue
, entry
);
4575 loc_push_restore(&bdo
->loc
);
4576 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
4578 qapi_free_BlockdevOptions(bdo
->bdo
);
4581 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4582 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4585 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4586 &machine_class
->block_default_type
, NULL
)) {
4590 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4592 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4593 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4596 * Note: qtest_enabled() (which is used in monitor_qapi_event_init())
4597 * depends on configure_accelerator() above.
4599 monitor_init_globals();
4601 if (qemu_opts_foreach(qemu_find_opts("mon"),
4602 mon_init_func
, NULL
, NULL
)) {
4606 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4608 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4610 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4612 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4615 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4618 /* If no default VGA is requested, the default is "none". */
4620 if (machine_class
->default_display
) {
4621 vga_model
= machine_class
->default_display
;
4622 } else if (vga_interface_available(VGA_CIRRUS
)) {
4623 vga_model
= "cirrus";
4624 } else if (vga_interface_available(VGA_STD
)) {
4629 select_vgahw(vga_model
);
4633 i
= select_watchdog(watchdog
);
4635 exit (i
== 1 ? 1 : 0);
4638 /* This checkpoint is required by replay to separate prior clock
4639 reading from the other reads, because timer polling functions query
4640 clock values from the log. */
4641 replay_checkpoint(CHECKPOINT_INIT
);
4642 qdev_machine_init();
4644 current_machine
->ram_size
= ram_size
;
4645 current_machine
->maxram_size
= maxram_size
;
4646 current_machine
->ram_slots
= ram_slots
;
4647 current_machine
->boot_order
= boot_order
;
4649 /* parse features once if machine provides default cpu_type */
4650 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
4652 current_machine
->cpu_type
= parse_cpu_model(cpu_model
);
4654 parse_numa_opts(current_machine
);
4656 machine_run_board_init(current_machine
);
4662 if (hax_enabled()) {
4666 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4667 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4671 /* init USB devices */
4672 if (machine_usb(current_machine
)) {
4673 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4677 /* Check if IGD GFX passthrough. */
4680 /* init generic devices */
4681 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4682 if (qemu_opts_foreach(qemu_find_opts("device"),
4683 device_init_func
, NULL
, NULL
)) {
4687 cpu_synchronize_all_post_init();
4689 rom_reset_order_override();
4691 /* Did we create any drives that we failed to create a device for? */
4692 drive_check_orphaned();
4694 /* Don't warn about the default network setup that you get if
4695 * no command line -net or -netdev options are specified. There
4696 * are two cases that we would otherwise complain about:
4697 * (1) board doesn't support a NIC but the implicit "-net nic"
4699 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4700 * sets up a nic that isn't connected to anything.
4703 net_check_clients();
4708 qemu_boot_set(boot_once
, &error_fatal
);
4709 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4712 /* init local displays */
4713 ds
= init_displaystate();
4714 qemu_display_init(ds
, &dpy
);
4716 /* must be after terminal init, SDL library changes signal handlers */
4717 os_setup_signal_handling();
4719 /* init remote displays */
4721 qemu_opts_foreach(qemu_find_opts("vnc"),
4722 vnc_init_func
, NULL
, NULL
);
4726 qemu_spice_display_init();
4729 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4733 qdev_machine_creation_done();
4735 /* TODO: once all bus devices are qdevified, this should be done
4736 * when bus is created by qdev.c */
4737 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4738 qemu_run_machine_init_done_notifiers();
4740 if (rom_check_and_register_reset() != 0) {
4741 error_report("rom check and register reset failed");
4747 /* This checkpoint is required by replay to separate prior clock
4748 reading from the other reads, because timer polling functions query
4749 clock values from the log. */
4750 replay_checkpoint(CHECKPOINT_RESET
);
4751 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
4752 register_global_state();
4753 if (replay_mode
!= REPLAY_MODE_NONE
) {
4754 replay_vmstate_init();
4755 } else if (loadvm
) {
4756 Error
*local_err
= NULL
;
4757 if (load_snapshot(loadvm
, &local_err
) < 0) {
4758 error_report_err(local_err
);
4763 qdev_prop_check_globals();
4764 if (vmstate_dump_file
) {
4766 dump_vmstate_json_to_file(vmstate_dump_file
);
4771 Error
*local_err
= NULL
;
4772 qemu_start_incoming_migration(incoming
, &local_err
);
4774 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4777 } else if (autostart
) {
4785 gdbserver_cleanup();
4787 /* No more vcpu or device emulation activity beyond this point */
4794 /* vhost-user must be cleaned up before chardevs. */
4800 user_creatable_cleanup();
4801 migration_object_finalize();
4802 /* TODO: unref root container, check all devices are ok */