4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "qemu/osdep.h"
25 #include "qemu-version.h"
26 #include "qemu/cutils.h"
27 #include "qemu/help_option.h"
28 #include "qemu/uuid.h"
31 #include "sysemu/seccomp.h"
34 #if defined(CONFIG_VDE)
35 #include <libvdeplug.h>
39 #if defined(__APPLE__) || defined(main)
40 #define SDL_MAIN_HANDLED
42 #if SDL_MAJOR_VERSION == 1
43 int qemu_main(int argc
, char **argv
);
44 int main(int argc
, char **argv
)
46 return qemu_main(argc
, argv
);
49 #define main qemu_main
50 #elif SDL_MAJOR_VERSION == 2
53 #error undefined SDL version
56 #endif /* CONFIG_SDL */
60 #define main qemu_main
61 #endif /* CONFIG_COCOA */
64 #include "qemu/error-report.h"
65 #include "qemu/sockets.h"
67 #include "hw/boards.h"
68 #include "sysemu/accel.h"
70 #include "hw/i386/pc.h"
71 #include "hw/isa/isa.h"
72 #include "hw/scsi/scsi.h"
74 #include "sysemu/watchdog.h"
75 #include "hw/smbios/smbios.h"
76 #include "hw/acpi/acpi.h"
77 #include "hw/xen/xen.h"
79 #include "hw/loader.h"
80 #include "monitor/qdev.h"
81 #include "sysemu/bt.h"
83 #include "net/slirp.h"
84 #include "monitor/monitor.h"
85 #include "ui/console.h"
87 #include "sysemu/sysemu.h"
88 #include "sysemu/numa.h"
89 #include "exec/gdbstub.h"
90 #include "qemu/timer.h"
91 #include "chardev/char.h"
92 #include "qemu/bitmap.h"
94 #include "sysemu/blockdev.h"
95 #include "hw/block/block.h"
96 #include "migration/misc.h"
97 #include "migration/snapshot.h"
98 #include "migration/global_state.h"
99 #include "sysemu/tpm.h"
100 #include "sysemu/dma.h"
101 #include "hw/audio/soundhw.h"
102 #include "audio/audio.h"
103 #include "sysemu/cpus.h"
104 #include "migration/colo.h"
105 #include "sysemu/kvm.h"
106 #include "sysemu/hax.h"
107 #include "qapi/qobject-input-visitor.h"
108 #include "qapi/qobject-input-visitor.h"
109 #include "qapi-visit.h"
110 #include "qapi/qmp/qjson.h"
111 #include "qemu/option.h"
112 #include "qemu/config-file.h"
113 #include "qemu-options.h"
114 #include "qmp-commands.h"
115 #include "qemu/main-loop.h"
117 #include "fsdev/qemu-fsdev.h"
119 #include "sysemu/qtest.h"
121 #include "disas/disas.h"
124 #include "slirp/libslirp.h"
126 #include "trace-root.h"
127 #include "trace/control.h"
128 #include "qemu/queue.h"
129 #include "sysemu/arch_init.h"
131 #include "ui/qemu-spice.h"
132 #include "qapi/string-input-visitor.h"
133 #include "qapi/opts-visitor.h"
134 #include "qom/object_interfaces.h"
135 #include "qapi-event.h"
136 #include "exec/semihost.h"
137 #include "crypto/init.h"
138 #include "sysemu/replay.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
;
149 int request_opengl
= -1;
151 const char* keyboard_layout
= NULL
;
153 const char *mem_path
= NULL
;
154 int mem_prealloc
= 0; /* force preallocation of physical target memory */
155 bool enable_mlock
= false;
157 NICInfo nd_table
[MAX_NICS
];
159 static int rtc_utc
= 1;
160 static int rtc_date_offset
= -1; /* -1 means no change */
161 QEMUClockType rtc_clock
;
162 int vga_interface_type
= VGA_NONE
;
163 static int full_screen
= 0;
164 static int no_frame
= 0;
166 static bool grab_on_hover
;
167 Chardev
*serial_hds
[MAX_SERIAL_PORTS
];
168 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
169 Chardev
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
170 Chardev
*sclp_hds
[MAX_SCLP_CONSOLES
];
171 int win2k_install_hack
= 0;
177 int acpi_enabled
= 1;
180 static int no_reboot
;
183 int graphic_rotate
= 0;
184 const char *watchdog
;
185 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
188 const char *qemu_name
;
191 unsigned int nb_prom_envs
= 0;
192 const char *prom_envs
[MAX_PROM_ENVS
];
195 uint8_t *boot_splash_filedata
;
196 size_t boot_splash_filedata_size
;
197 uint8_t qemu_extra_params_fw
[2];
199 int icount_align_option
;
201 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
202 * little-endian "wire format" described in the SMBIOS 2.6 specification.
207 /* Trace unassigned memory or i/o accesses. */
208 bool trace_unassigned
;
210 static NotifierList exit_notifiers
=
211 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
213 static NotifierList machine_init_done_notifiers
=
214 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
218 enum xen_mode xen_mode
= XEN_EMULATE
;
219 bool xen_domid_restrict
;
221 static int has_defaults
= 1;
222 static int default_serial
= 1;
223 static int default_parallel
= 1;
224 static int default_virtcon
= 1;
225 static int default_sclp
= 1;
226 static int default_monitor
= 1;
227 static int default_floppy
= 1;
228 static int default_cdrom
= 1;
229 static int default_sdcard
= 1;
230 static int default_vga
= 1;
231 static int default_net
= 1;
237 { .driver
= "isa-serial", .flag
= &default_serial
},
238 { .driver
= "isa-parallel", .flag
= &default_parallel
},
239 { .driver
= "isa-fdc", .flag
= &default_floppy
},
240 { .driver
= "floppy", .flag
= &default_floppy
},
241 { .driver
= "ide-cd", .flag
= &default_cdrom
},
242 { .driver
= "ide-hd", .flag
= &default_cdrom
},
243 { .driver
= "ide-drive", .flag
= &default_cdrom
},
244 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
245 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
246 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
247 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
248 { .driver
= "VGA", .flag
= &default_vga
},
249 { .driver
= "isa-vga", .flag
= &default_vga
},
250 { .driver
= "cirrus-vga", .flag
= &default_vga
},
251 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
252 { .driver
= "vmware-svga", .flag
= &default_vga
},
253 { .driver
= "qxl-vga", .flag
= &default_vga
},
254 { .driver
= "virtio-vga", .flag
= &default_vga
},
257 static QemuOptsList qemu_rtc_opts
= {
259 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
263 .type
= QEMU_OPT_STRING
,
266 .type
= QEMU_OPT_STRING
,
269 .type
= QEMU_OPT_STRING
,
271 { /* end of list */ }
275 static QemuOptsList qemu_sandbox_opts
= {
277 .implied_opt_name
= "enable",
278 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
282 .type
= QEMU_OPT_BOOL
,
284 { /* end of list */ }
288 static QemuOptsList qemu_option_rom_opts
= {
289 .name
= "option-rom",
290 .implied_opt_name
= "romfile",
291 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
295 .type
= QEMU_OPT_NUMBER
,
298 .type
= QEMU_OPT_STRING
,
300 { /* end of list */ }
304 static QemuOptsList qemu_machine_opts
= {
306 .implied_opt_name
= "type",
308 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
311 * no elements => accept any
312 * sanity checking will happen later
313 * when setting machine properties
319 static QemuOptsList qemu_accel_opts
= {
321 .implied_opt_name
= "accel",
322 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
327 .type
= QEMU_OPT_STRING
,
328 .help
= "Select the type of accelerator",
332 .type
= QEMU_OPT_STRING
,
333 .help
= "Enable/disable multi-threaded TCG",
335 { /* end of list */ }
339 static QemuOptsList qemu_boot_opts
= {
341 .implied_opt_name
= "order",
343 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
347 .type
= QEMU_OPT_STRING
,
350 .type
= QEMU_OPT_STRING
,
353 .type
= QEMU_OPT_BOOL
,
356 .type
= QEMU_OPT_STRING
,
358 .name
= "splash-time",
359 .type
= QEMU_OPT_STRING
,
361 .name
= "reboot-timeout",
362 .type
= QEMU_OPT_STRING
,
365 .type
= QEMU_OPT_BOOL
,
371 static QemuOptsList qemu_add_fd_opts
= {
373 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
377 .type
= QEMU_OPT_NUMBER
,
378 .help
= "file descriptor of which a duplicate is added to fd set",
381 .type
= QEMU_OPT_NUMBER
,
382 .help
= "ID of the fd set to add fd to",
385 .type
= QEMU_OPT_STRING
,
386 .help
= "free-form string used to describe fd",
388 { /* end of list */ }
392 static QemuOptsList qemu_object_opts
= {
394 .implied_opt_name
= "qom-type",
395 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
401 static QemuOptsList qemu_tpmdev_opts
= {
403 .implied_opt_name
= "type",
404 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
406 /* options are defined in the TPM backends */
407 { /* end of list */ }
411 static QemuOptsList qemu_realtime_opts
= {
413 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
417 .type
= QEMU_OPT_BOOL
,
419 { /* end of list */ }
423 static QemuOptsList qemu_msg_opts
= {
425 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
429 .type
= QEMU_OPT_BOOL
,
431 { /* end of list */ }
435 static QemuOptsList qemu_name_opts
= {
437 .implied_opt_name
= "guest",
439 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
443 .type
= QEMU_OPT_STRING
,
444 .help
= "Sets the name of the guest.\n"
445 "This name will be displayed in the SDL window caption.\n"
446 "The name will also be used for the VNC server",
449 .type
= QEMU_OPT_STRING
,
450 .help
= "Sets the name of the QEMU process, as shown in top etc",
452 .name
= "debug-threads",
453 .type
= QEMU_OPT_BOOL
,
454 .help
= "When enabled, name the individual threads; defaults off.\n"
455 "NOTE: The thread names are for debugging and not a\n"
458 { /* End of list */ }
462 static QemuOptsList qemu_mem_opts
= {
464 .implied_opt_name
= "size",
465 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
470 .type
= QEMU_OPT_SIZE
,
474 .type
= QEMU_OPT_NUMBER
,
478 .type
= QEMU_OPT_SIZE
,
480 { /* end of list */ }
484 static QemuOptsList qemu_icount_opts
= {
486 .implied_opt_name
= "shift",
488 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
492 .type
= QEMU_OPT_STRING
,
495 .type
= QEMU_OPT_BOOL
,
498 .type
= QEMU_OPT_BOOL
,
501 .type
= QEMU_OPT_STRING
,
504 .type
= QEMU_OPT_STRING
,
506 .name
= "rrsnapshot",
507 .type
= QEMU_OPT_STRING
,
509 { /* end of list */ }
513 static QemuOptsList qemu_semihosting_config_opts
= {
514 .name
= "semihosting-config",
515 .implied_opt_name
= "enable",
516 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
520 .type
= QEMU_OPT_BOOL
,
523 .type
= QEMU_OPT_STRING
,
526 .type
= QEMU_OPT_STRING
,
528 { /* end of list */ }
532 static QemuOptsList qemu_fw_cfg_opts
= {
534 .implied_opt_name
= "name",
535 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
539 .type
= QEMU_OPT_STRING
,
540 .help
= "Sets the fw_cfg name of the blob to be inserted",
543 .type
= QEMU_OPT_STRING
,
544 .help
= "Sets the name of the file from which\n"
545 "the fw_cfg blob will be loaded",
548 .type
= QEMU_OPT_STRING
,
549 .help
= "Sets content of the blob to be inserted from a string",
551 { /* end of list */ }
556 * Get machine options
558 * Returns: machine options (never null).
560 QemuOpts
*qemu_get_machine_opts(void)
562 return qemu_find_opts_singleton("machine");
565 const char *qemu_get_vm_name(void)
570 static void res_free(void)
572 g_free(boot_splash_filedata
);
573 boot_splash_filedata
= NULL
;
576 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
578 const char *driver
= qemu_opt_get(opts
, "driver");
583 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
584 if (strcmp(default_list
[i
].driver
, driver
) != 0)
586 *(default_list
[i
].flag
) = 0;
591 /***********************************************************/
594 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
596 /* We use RUN_STATE__MAX but any invalid value will do */
597 static RunState vmstop_requested
= RUN_STATE__MAX
;
598 static QemuMutex vmstop_lock
;
603 } RunStateTransition
;
605 static const RunStateTransition runstate_transitions_def
[] = {
607 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
608 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
609 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
611 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
612 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
613 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
614 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
615 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
616 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
617 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
618 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
619 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
620 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
621 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
622 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
624 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
625 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
626 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
628 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
629 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
630 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
632 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
633 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
634 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
635 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
637 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
638 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
639 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
641 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
642 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
643 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
645 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
646 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
647 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
648 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
650 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
651 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
653 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
655 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
656 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
657 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
658 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
659 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
660 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
661 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
662 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
663 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
664 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
665 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
667 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
669 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
670 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
671 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
673 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
674 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
675 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
676 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
677 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
678 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
680 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
681 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
682 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
683 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
685 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
686 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
687 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
689 { RUN_STATE__MAX
, RUN_STATE__MAX
},
692 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
694 bool runstate_check(RunState state
)
696 return current_run_state
== state
;
699 bool runstate_store(char *str
, size_t size
)
701 const char *state
= RunState_lookup
[current_run_state
];
702 size_t len
= strlen(state
) + 1;
707 memcpy(str
, state
, len
);
711 static void runstate_init(void)
713 const RunStateTransition
*p
;
715 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
716 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
717 runstate_valid_transitions
[p
->from
][p
->to
] = true;
720 qemu_mutex_init(&vmstop_lock
);
723 /* This function will abort() on invalid state transitions */
724 void runstate_set(RunState new_state
)
726 assert(new_state
< RUN_STATE__MAX
);
728 if (current_run_state
== new_state
) {
732 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
733 error_report("invalid runstate transition: '%s' -> '%s'",
734 RunState_lookup
[current_run_state
],
735 RunState_lookup
[new_state
]);
738 trace_runstate_set(new_state
);
739 current_run_state
= new_state
;
742 int runstate_is_running(void)
744 return runstate_check(RUN_STATE_RUNNING
);
747 bool runstate_needs_reset(void)
749 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
750 runstate_check(RUN_STATE_SHUTDOWN
);
753 StatusInfo
*qmp_query_status(Error
**errp
)
755 StatusInfo
*info
= g_malloc0(sizeof(*info
));
757 info
->running
= runstate_is_running();
758 info
->singlestep
= singlestep
;
759 info
->status
= current_run_state
;
764 bool qemu_vmstop_requested(RunState
*r
)
766 qemu_mutex_lock(&vmstop_lock
);
767 *r
= vmstop_requested
;
768 vmstop_requested
= RUN_STATE__MAX
;
769 qemu_mutex_unlock(&vmstop_lock
);
770 return *r
< RUN_STATE__MAX
;
773 void qemu_system_vmstop_request_prepare(void)
775 qemu_mutex_lock(&vmstop_lock
);
778 void qemu_system_vmstop_request(RunState state
)
780 vmstop_requested
= state
;
781 qemu_mutex_unlock(&vmstop_lock
);
785 /***********************************************************/
786 /* real time host monotonic timer */
788 static time_t qemu_time(void)
790 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
793 /***********************************************************/
794 /* host time/date access */
795 void qemu_get_timedate(struct tm
*tm
, int offset
)
797 time_t ti
= qemu_time();
800 if (rtc_date_offset
== -1) {
804 localtime_r(&ti
, tm
);
806 ti
-= rtc_date_offset
;
811 int qemu_timedate_diff(struct tm
*tm
)
815 if (rtc_date_offset
== -1)
817 seconds
= mktimegm(tm
);
820 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
821 seconds
= mktime(&tmp
);
824 seconds
= mktimegm(tm
) + rtc_date_offset
;
826 return seconds
- qemu_time();
829 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
831 time_t rtc_start_date
;
834 if (!strcmp(startdate
, "now") && legacy
) {
835 rtc_date_offset
= -1;
837 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
845 } else if (sscanf(startdate
, "%d-%d-%d",
857 rtc_start_date
= mktimegm(&tm
);
858 if (rtc_start_date
== -1) {
860 error_report("invalid date format");
861 error_printf("valid formats: "
862 "'2006-06-17T16:01:21' or '2006-06-17'\n");
865 rtc_date_offset
= qemu_time() - rtc_start_date
;
869 static void configure_rtc(QemuOpts
*opts
)
873 value
= qemu_opt_get(opts
, "base");
875 if (!strcmp(value
, "utc")) {
877 } else if (!strcmp(value
, "localtime")) {
878 Error
*blocker
= NULL
;
880 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
881 "-rtc base=localtime");
882 replay_add_blocker(blocker
);
884 configure_rtc_date_offset(value
, 0);
887 value
= qemu_opt_get(opts
, "clock");
889 if (!strcmp(value
, "host")) {
890 rtc_clock
= QEMU_CLOCK_HOST
;
891 } else if (!strcmp(value
, "rt")) {
892 rtc_clock
= QEMU_CLOCK_REALTIME
;
893 } else if (!strcmp(value
, "vm")) {
894 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
896 error_report("invalid option value '%s'", value
);
900 value
= qemu_opt_get(opts
, "driftfix");
902 if (!strcmp(value
, "slew")) {
903 static GlobalProperty slew_lost_ticks
= {
904 .driver
= "mc146818rtc",
905 .property
= "lost_tick_policy",
909 qdev_prop_register_global(&slew_lost_ticks
);
910 } else if (!strcmp(value
, "none")) {
911 /* discard is default */
913 error_report("invalid option value '%s'", value
);
919 /***********************************************************/
920 /* Bluetooth support */
923 static struct HCIInfo
*hci_table
[MAX_NICS
];
925 struct HCIInfo
*qemu_next_hci(void)
927 if (cur_hci
== nb_hcis
)
930 return hci_table
[cur_hci
++];
933 static int bt_hci_parse(const char *str
)
938 if (nb_hcis
>= MAX_NICS
) {
939 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
952 bdaddr
.b
[5] = 0x56 + nb_hcis
;
953 hci
->bdaddr_set(hci
, bdaddr
.b
);
955 hci_table
[nb_hcis
++] = hci
;
960 static void bt_vhci_add(int vlan_id
)
962 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
965 warn_report("adding a VHCI to an empty scatternet %i",
968 bt_vhci_init(bt_new_hci(vlan
));
971 static struct bt_device_s
*bt_device_add(const char *opt
)
973 struct bt_scatternet_s
*vlan
;
975 char *endp
= strstr(opt
, ",vlan=");
976 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
979 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
982 vlan_id
= strtol(endp
+ 6, &endp
, 0);
984 error_report("unrecognised bluetooth vlan Id");
989 vlan
= qemu_find_bt_vlan(vlan_id
);
992 warn_report("adding a slave device to an empty scatternet %i",
995 if (!strcmp(devname
, "keyboard"))
996 return bt_keyboard_init(vlan
);
998 error_report("unsupported bluetooth device '%s'", devname
);
1002 static int bt_parse(const char *opt
)
1004 const char *endp
, *p
;
1007 if (strstart(opt
, "hci", &endp
)) {
1008 if (!*endp
|| *endp
== ',') {
1010 if (!strstart(endp
, ",vlan=", 0))
1013 return bt_hci_parse(opt
);
1015 } else if (strstart(opt
, "vhci", &endp
)) {
1016 if (!*endp
|| *endp
== ',') {
1018 if (strstart(endp
, ",vlan=", &p
)) {
1019 vlan
= strtol(p
, (char **) &endp
, 0);
1021 error_report("bad scatternet '%s'", p
);
1025 error_report("bad parameter '%s'", endp
+ 1);
1034 } else if (strstart(opt
, "device:", &endp
))
1035 return !bt_device_add(endp
);
1037 error_report("bad bluetooth parameter '%s'", opt
);
1041 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1043 /* FIXME: change this to true for 1.3 */
1044 if (qemu_opt_get_bool(opts
, "enable", false)) {
1045 #ifdef CONFIG_SECCOMP
1046 if (seccomp_start() < 0) {
1047 error_report("failed to install seccomp syscall filter "
1052 error_report("seccomp support is disabled");
1060 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1062 const char *proc_name
;
1064 if (qemu_opt_get(opts
, "debug-threads")) {
1065 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1067 qemu_name
= qemu_opt_get(opts
, "guest");
1069 proc_name
= qemu_opt_get(opts
, "process");
1071 os_set_proc_name(proc_name
);
1077 bool defaults_enabled(void)
1079 return has_defaults
;
1083 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1085 int fd
, dupfd
, flags
;
1087 const char *fd_opaque
= NULL
;
1090 fd
= qemu_opt_get_number(opts
, "fd", -1);
1091 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1092 fd_opaque
= qemu_opt_get(opts
, "opaque");
1095 error_report("fd option is required and must be non-negative");
1099 if (fd
<= STDERR_FILENO
) {
1100 error_report("fd cannot be a standard I/O stream");
1105 * All fds inherited across exec() necessarily have FD_CLOEXEC
1106 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1108 flags
= fcntl(fd
, F_GETFD
);
1109 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1110 error_report("fd is not valid or already in use");
1115 error_report("set option is required and must be non-negative");
1119 #ifdef F_DUPFD_CLOEXEC
1120 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1124 qemu_set_cloexec(dupfd
);
1128 error_report("error duplicating fd: %s", strerror(errno
));
1132 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1133 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1140 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1144 fd
= qemu_opt_get_number(opts
, "fd", -1);
1151 /***********************************************************/
1152 /* QEMU Block devices */
1154 #define HD_OPTS "media=disk"
1155 #define CDROM_OPTS "media=cdrom"
1157 #define PFLASH_OPTS ""
1161 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1163 BlockInterfaceType
*block_default_type
= opaque
;
1165 return drive_new(opts
, *block_default_type
) == NULL
;
1168 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1170 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1171 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1176 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1177 int index
, const char *optstr
)
1182 if (!enable
|| drive_get_by_index(type
, index
)) {
1186 opts
= drive_add(type
, index
, NULL
, optstr
);
1188 drive_enable_snapshot(NULL
, opts
, NULL
);
1191 dinfo
= drive_new(opts
, type
);
1195 dinfo
->is_default
= true;
1199 static QemuOptsList qemu_smp_opts
= {
1201 .implied_opt_name
= "cpus",
1202 .merge_lists
= true,
1203 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1207 .type
= QEMU_OPT_NUMBER
,
1210 .type
= QEMU_OPT_NUMBER
,
1213 .type
= QEMU_OPT_NUMBER
,
1216 .type
= QEMU_OPT_NUMBER
,
1219 .type
= QEMU_OPT_NUMBER
,
1221 { /*End of list */ }
1225 static void smp_parse(QemuOpts
*opts
)
1228 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1229 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1230 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1231 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1233 /* compute missing values, prefer sockets over cores over threads */
1234 if (cpus
== 0 || sockets
== 0) {
1235 sockets
= sockets
> 0 ? sockets
: 1;
1236 cores
= cores
> 0 ? cores
: 1;
1237 threads
= threads
> 0 ? threads
: 1;
1239 cpus
= cores
* threads
* sockets
;
1241 } else if (cores
== 0) {
1242 threads
= threads
> 0 ? threads
: 1;
1243 cores
= cpus
/ (sockets
* threads
);
1244 cores
= cores
> 0 ? cores
: 1;
1245 } else if (threads
== 0) {
1246 threads
= cpus
/ (cores
* sockets
);
1247 threads
= threads
> 0 ? threads
: 1;
1248 } else if (sockets
* cores
* threads
< cpus
) {
1249 error_report("cpu topology: "
1250 "sockets (%u) * cores (%u) * threads (%u) < "
1252 sockets
, cores
, threads
, cpus
);
1256 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1258 if (max_cpus
< cpus
) {
1259 error_report("maxcpus must be equal to or greater than smp");
1263 if (sockets
* cores
* threads
> max_cpus
) {
1264 error_report("cpu topology: "
1265 "sockets (%u) * cores (%u) * threads (%u) > "
1267 sockets
, cores
, threads
, max_cpus
);
1273 smp_threads
= threads
;
1277 Error
*blocker
= NULL
;
1278 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1279 replay_add_blocker(blocker
);
1283 static void realtime_init(void)
1286 if (os_mlock() < 0) {
1287 error_report("locking memory failed");
1294 static void configure_msg(QemuOpts
*opts
)
1296 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1299 /***********************************************************/
1302 typedef struct SemihostingConfig
{
1304 SemihostingTarget target
;
1307 const char *cmdline
; /* concatenated argv */
1308 } SemihostingConfig
;
1310 static SemihostingConfig semihosting
;
1312 bool semihosting_enabled(void)
1314 return semihosting
.enabled
;
1317 SemihostingTarget
semihosting_get_target(void)
1319 return semihosting
.target
;
1322 const char *semihosting_get_arg(int i
)
1324 if (i
>= semihosting
.argc
) {
1327 return semihosting
.argv
[i
];
1330 int semihosting_get_argc(void)
1332 return semihosting
.argc
;
1335 const char *semihosting_get_cmdline(void)
1337 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1338 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1340 return semihosting
.cmdline
;
1343 static int add_semihosting_arg(void *opaque
,
1344 const char *name
, const char *val
,
1347 SemihostingConfig
*s
= opaque
;
1348 if (strcmp(name
, "arg") == 0) {
1350 /* one extra element as g_strjoinv() expects NULL-terminated array */
1351 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1352 s
->argv
[s
->argc
- 1] = val
;
1353 s
->argv
[s
->argc
] = NULL
;
1358 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1359 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1364 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1366 /* split -append and initialize argv[1..n] */
1367 cmd_token
= strtok(g_strdup(cmd
), " ");
1369 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1370 cmd_token
= strtok(NULL
, " ");
1374 /* Now we still need this for compatibility with XEN. */
1375 bool has_igd_gfx_passthru
;
1376 static void igd_gfx_passthru(void)
1378 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1381 /***********************************************************/
1384 static int usb_device_add(const char *devname
)
1386 USBDevice
*dev
= NULL
;
1387 #ifndef CONFIG_LINUX
1391 if (!machine_usb(current_machine
)) {
1395 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1396 dev
= usbdevice_create(devname
);
1400 /* the other ones */
1401 #ifndef CONFIG_LINUX
1402 /* only the linux version is qdev-ified, usb-bsd still needs this */
1403 if (strstart(devname
, "host:", &p
)) {
1404 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1414 static int usb_device_del(const char *devname
)
1419 if (strstart(devname
, "host:", &p
)) {
1423 if (!machine_usb(current_machine
)) {
1427 p
= strchr(devname
, '.');
1430 bus_num
= strtoul(devname
, NULL
, 0);
1431 addr
= strtoul(p
+ 1, NULL
, 0);
1433 return usb_device_delete_addr(bus_num
, addr
);
1436 static int usb_parse(const char *cmdline
)
1439 r
= usb_device_add(cmdline
);
1441 error_report("could not add USB device '%s'", cmdline
);
1446 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1448 const char *devname
= qdict_get_str(qdict
, "devname");
1450 error_report("usb_add is deprecated, please use device_add instead");
1452 if (usb_device_add(devname
) < 0) {
1453 error_report("could not add USB device '%s'", devname
);
1457 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1459 const char *devname
= qdict_get_str(qdict
, "devname");
1461 error_report("usb_del is deprecated, please use device_del instead");
1463 if (usb_device_del(devname
) < 0) {
1464 error_report("could not delete USB device '%s'", devname
);
1468 /***********************************************************/
1469 /* machine registration */
1471 MachineState
*current_machine
;
1473 static MachineClass
*find_machine(const char *name
)
1475 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1476 MachineClass
*mc
= NULL
;
1478 for (el
= machines
; el
; el
= el
->next
) {
1479 MachineClass
*temp
= el
->data
;
1481 if (!strcmp(temp
->name
, name
)) {
1486 !strcmp(temp
->alias
, name
)) {
1492 g_slist_free(machines
);
1496 MachineClass
*find_default_machine(void)
1498 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1499 MachineClass
*mc
= NULL
;
1501 for (el
= machines
; el
; el
= el
->next
) {
1502 MachineClass
*temp
= el
->data
;
1504 if (temp
->is_default
) {
1510 g_slist_free(machines
);
1514 MachineInfoList
*qmp_query_machines(Error
**errp
)
1516 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1517 MachineInfoList
*mach_list
= NULL
;
1519 for (el
= machines
; el
; el
= el
->next
) {
1520 MachineClass
*mc
= el
->data
;
1521 MachineInfoList
*entry
;
1524 info
= g_malloc0(sizeof(*info
));
1525 if (mc
->is_default
) {
1526 info
->has_is_default
= true;
1527 info
->is_default
= true;
1531 info
->has_alias
= true;
1532 info
->alias
= g_strdup(mc
->alias
);
1535 info
->name
= g_strdup(mc
->name
);
1536 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1537 info
->hotpluggable_cpus
= mc
->has_hotpluggable_cpus
;
1539 entry
= g_malloc0(sizeof(*entry
));
1540 entry
->value
= info
;
1541 entry
->next
= mach_list
;
1545 g_slist_free(machines
);
1549 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1551 ObjectProperty
*prop
;
1552 ObjectPropertyIterator iter
;
1554 if (!qemu_opt_has_help_opt(opts
)) {
1558 object_property_iter_init(&iter
, OBJECT(machine
));
1559 while ((prop
= object_property_iter_next(&iter
))) {
1564 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1565 prop
->name
, prop
->type
);
1566 if (prop
->description
) {
1567 error_printf(" (%s)\n", prop
->description
);
1576 /***********************************************************/
1577 /* main execution loop */
1579 struct vm_change_state_entry
{
1580 VMChangeStateHandler
*cb
;
1582 QLIST_ENTRY (vm_change_state_entry
) entries
;
1585 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1587 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1590 VMChangeStateEntry
*e
;
1592 e
= g_malloc0(sizeof (*e
));
1596 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1600 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1602 QLIST_REMOVE (e
, entries
);
1606 void vm_state_notify(int running
, RunState state
)
1608 VMChangeStateEntry
*e
, *next
;
1610 trace_vm_state_notify(running
, state
);
1612 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1613 e
->cb(e
->opaque
, running
, state
);
1617 static ShutdownCause reset_requested
;
1618 static ShutdownCause shutdown_requested
;
1619 static int shutdown_signal
;
1620 static pid_t shutdown_pid
;
1621 static int powerdown_requested
;
1622 static int debug_requested
;
1623 static int suspend_requested
;
1624 static WakeupReason wakeup_reason
;
1625 static NotifierList powerdown_notifiers
=
1626 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1627 static NotifierList suspend_notifiers
=
1628 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1629 static NotifierList wakeup_notifiers
=
1630 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1631 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1633 ShutdownCause
qemu_shutdown_requested_get(void)
1635 return shutdown_requested
;
1638 ShutdownCause
qemu_reset_requested_get(void)
1640 return reset_requested
;
1643 static int qemu_shutdown_requested(void)
1645 return atomic_xchg(&shutdown_requested
, SHUTDOWN_CAUSE_NONE
);
1648 static void qemu_kill_report(void)
1650 if (!qtest_driver() && shutdown_signal
) {
1651 if (shutdown_pid
== 0) {
1652 /* This happens for eg ^C at the terminal, so it's worth
1653 * avoiding printing an odd message in that case.
1655 error_report("terminating on signal %d", shutdown_signal
);
1657 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1659 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1660 shutdown_signal
, shutdown_pid
,
1661 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1662 g_free(shutdown_cmd
);
1664 shutdown_signal
= 0;
1668 static ShutdownCause
qemu_reset_requested(void)
1670 ShutdownCause r
= reset_requested
;
1672 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1673 reset_requested
= SHUTDOWN_CAUSE_NONE
;
1676 return SHUTDOWN_CAUSE_NONE
;
1679 static int qemu_suspend_requested(void)
1681 int r
= suspend_requested
;
1682 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1683 suspend_requested
= 0;
1689 static WakeupReason
qemu_wakeup_requested(void)
1691 return wakeup_reason
;
1694 static int qemu_powerdown_requested(void)
1696 int r
= powerdown_requested
;
1697 powerdown_requested
= 0;
1701 static int qemu_debug_requested(void)
1703 int r
= debug_requested
;
1704 debug_requested
= 0;
1709 * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE.
1711 void qemu_system_reset(ShutdownCause reason
)
1715 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1717 cpu_synchronize_all_states();
1719 if (mc
&& mc
->reset
) {
1722 qemu_devices_reset();
1725 qapi_event_send_reset(shutdown_caused_by_guest(reason
),
1728 cpu_synchronize_all_post_reset();
1731 void qemu_system_guest_panicked(GuestPanicInformation
*info
)
1733 qemu_log_mask(LOG_GUEST_ERROR
, "Guest crashed\n");
1736 current_cpu
->crash_occurred
= true;
1738 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
,
1739 !!info
, info
, &error_abort
);
1740 vm_stop(RUN_STATE_GUEST_PANICKED
);
1742 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1743 !!info
, info
, &error_abort
);
1744 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC
);
1748 if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_HYPER_V
) {
1749 qemu_log_mask(LOG_GUEST_ERROR
, "HV crash parameters: (%#"PRIx64
1750 " %#"PRIx64
" %#"PRIx64
" %#"PRIx64
" %#"PRIx64
")\n",
1751 info
->u
.hyper_v
.arg1
,
1752 info
->u
.hyper_v
.arg2
,
1753 info
->u
.hyper_v
.arg3
,
1754 info
->u
.hyper_v
.arg4
,
1755 info
->u
.hyper_v
.arg5
);
1757 qapi_free_GuestPanicInformation(info
);
1761 void qemu_system_reset_request(ShutdownCause reason
)
1764 shutdown_requested
= reason
;
1766 reset_requested
= reason
;
1769 qemu_notify_event();
1772 static void qemu_system_suspend(void)
1775 notifier_list_notify(&suspend_notifiers
, NULL
);
1776 runstate_set(RUN_STATE_SUSPENDED
);
1777 qapi_event_send_suspend(&error_abort
);
1780 void qemu_system_suspend_request(void)
1782 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1785 suspend_requested
= 1;
1787 qemu_notify_event();
1790 void qemu_register_suspend_notifier(Notifier
*notifier
)
1792 notifier_list_add(&suspend_notifiers
, notifier
);
1795 void qemu_system_wakeup_request(WakeupReason reason
)
1797 trace_system_wakeup_request(reason
);
1799 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1802 if (!(wakeup_reason_mask
& (1 << reason
))) {
1805 runstate_set(RUN_STATE_RUNNING
);
1806 wakeup_reason
= reason
;
1807 qemu_notify_event();
1810 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1813 wakeup_reason_mask
|= (1 << reason
);
1815 wakeup_reason_mask
&= ~(1 << reason
);
1819 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1821 notifier_list_add(&wakeup_notifiers
, notifier
);
1824 void qemu_system_killed(int signal
, pid_t pid
)
1826 shutdown_signal
= signal
;
1830 /* Cannot call qemu_system_shutdown_request directly because
1831 * we are in a signal handler.
1833 shutdown_requested
= SHUTDOWN_CAUSE_HOST_SIGNAL
;
1834 qemu_notify_event();
1837 void qemu_system_shutdown_request(ShutdownCause reason
)
1839 trace_qemu_system_shutdown_request(reason
);
1840 replay_shutdown_request(reason
);
1841 shutdown_requested
= reason
;
1842 qemu_notify_event();
1845 static void qemu_system_powerdown(void)
1847 qapi_event_send_powerdown(&error_abort
);
1848 notifier_list_notify(&powerdown_notifiers
, NULL
);
1851 void qemu_system_powerdown_request(void)
1853 trace_qemu_system_powerdown_request();
1854 powerdown_requested
= 1;
1855 qemu_notify_event();
1858 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1860 notifier_list_add(&powerdown_notifiers
, notifier
);
1863 void qemu_system_debug_request(void)
1865 debug_requested
= 1;
1866 qemu_notify_event();
1869 static bool main_loop_should_exit(void)
1872 ShutdownCause request
;
1874 if (qemu_debug_requested()) {
1875 vm_stop(RUN_STATE_DEBUG
);
1877 if (qemu_suspend_requested()) {
1878 qemu_system_suspend();
1880 request
= qemu_shutdown_requested();
1883 qapi_event_send_shutdown(shutdown_caused_by_guest(request
),
1886 vm_stop(RUN_STATE_SHUTDOWN
);
1891 request
= qemu_reset_requested();
1894 qemu_system_reset(request
);
1896 if (!runstate_check(RUN_STATE_RUNNING
) &&
1897 !runstate_check(RUN_STATE_INMIGRATE
)) {
1898 runstate_set(RUN_STATE_PRELAUNCH
);
1901 if (qemu_wakeup_requested()) {
1903 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
1904 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1905 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1907 qapi_event_send_wakeup(&error_abort
);
1909 if (qemu_powerdown_requested()) {
1910 qemu_system_powerdown();
1912 if (qemu_vmstop_requested(&r
)) {
1918 static void main_loop(void)
1920 #ifdef CONFIG_PROFILER
1924 #ifdef CONFIG_PROFILER
1925 ti
= profile_getclock();
1927 main_loop_wait(false);
1928 #ifdef CONFIG_PROFILER
1929 dev_time
+= profile_getclock() - ti
;
1931 } while (!main_loop_should_exit());
1934 static void version(void)
1936 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1937 QEMU_COPYRIGHT
"\n");
1940 static void QEMU_NORETURN
help(int exitcode
)
1943 printf("usage: %s [options] [disk_image]\n\n"
1944 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1945 error_get_progname());
1947 #define QEMU_OPTIONS_GENERATE_HELP
1948 #include "qemu-options-wrapper.h"
1950 printf("\nDuring emulation, the following keys are useful:\n"
1951 "ctrl-alt-f toggle full screen\n"
1952 "ctrl-alt-n switch to virtual console 'n'\n"
1953 "ctrl-alt toggle mouse and keyboard grab\n"
1955 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1960 #define HAS_ARG 0x0001
1962 typedef struct QEMUOption
{
1969 static const QEMUOption qemu_options
[] = {
1970 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1971 #define QEMU_OPTIONS_GENERATE_OPTIONS
1972 #include "qemu-options-wrapper.h"
1976 typedef struct VGAInterfaceInfo
{
1977 const char *opt_name
; /* option name */
1978 const char *name
; /* human-readable name */
1979 /* Class names indicating that support is available.
1980 * If no class is specified, the interface is always available */
1981 const char *class_names
[2];
1984 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1990 .name
= "standard VGA",
1991 .class_names
= { "VGA", "isa-vga" },
1994 .opt_name
= "cirrus",
1995 .name
= "Cirrus VGA",
1996 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1999 .opt_name
= "vmware",
2000 .name
= "VMWare SVGA",
2001 .class_names
= { "vmware-svga" },
2004 .opt_name
= "virtio",
2005 .name
= "Virtio VGA",
2006 .class_names
= { "virtio-vga" },
2011 .class_names
= { "qxl-vga" },
2015 .name
= "TCX framebuffer",
2016 .class_names
= { "SUNW,tcx" },
2020 .name
= "CG3 framebuffer",
2021 .class_names
= { "cgthree" },
2024 .opt_name
= "xenfb",
2028 static bool vga_interface_available(VGAInterfaceType t
)
2030 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2032 assert(t
< VGA_TYPE_MAX
);
2033 return !ti
->class_names
[0] ||
2034 object_class_by_name(ti
->class_names
[0]) ||
2035 object_class_by_name(ti
->class_names
[1]);
2038 static void select_vgahw(const char *p
)
2043 assert(vga_interface_type
== VGA_NONE
);
2044 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2045 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2046 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2047 if (!vga_interface_available(t
)) {
2048 error_report("%s not available", ti
->name
);
2051 vga_interface_type
= t
;
2055 if (t
== VGA_TYPE_MAX
) {
2057 error_report("unknown vga type: %s", p
);
2061 const char *nextopt
;
2063 if (strstart(opts
, ",retrace=", &nextopt
)) {
2065 if (strstart(opts
, "dumb", &nextopt
))
2066 vga_retrace_method
= VGA_RETRACE_DUMB
;
2067 else if (strstart(opts
, "precise", &nextopt
))
2068 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2069 else goto invalid_vga
;
2070 } else goto invalid_vga
;
2075 typedef enum DisplayType
{
2085 static DisplayType
select_display(const char *p
)
2088 DisplayType display
= DT_DEFAULT
;
2090 if (strstart(p
, "sdl", &opts
)) {
2094 const char *nextopt
;
2096 if (strstart(opts
, ",frame=", &nextopt
)) {
2098 if (strstart(opts
, "on", &nextopt
)) {
2100 } else if (strstart(opts
, "off", &nextopt
)) {
2103 goto invalid_sdl_args
;
2105 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2107 if (strstart(opts
, "on", &nextopt
)) {
2109 } else if (strstart(opts
, "off", &nextopt
)) {
2112 goto invalid_sdl_args
;
2114 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2116 if (strstart(opts
, "on", &nextopt
)) {
2118 } else if (strstart(opts
, "off", &nextopt
)) {
2121 goto invalid_sdl_args
;
2123 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2125 if (strstart(opts
, "on", &nextopt
)) {
2127 } else if (strstart(opts
, "off", &nextopt
)) {
2130 goto invalid_sdl_args
;
2132 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2134 if (strstart(opts
, "on", &nextopt
)) {
2136 } else if (strstart(opts
, "off", &nextopt
)) {
2139 goto invalid_sdl_args
;
2143 error_report("invalid SDL option string");
2149 error_report("SDL support is disabled");
2152 } else if (strstart(p
, "vnc", &opts
)) {
2154 vnc_parse(opts
+ 1, &error_fatal
);
2156 error_report("VNC requires a display argument vnc=<display>");
2159 } else if (strstart(p
, "egl-headless", &opts
)) {
2160 #ifdef CONFIG_OPENGL_DMABUF
2165 fprintf(stderr
, "egl support is disabled\n");
2168 } else if (strstart(p
, "curses", &opts
)) {
2169 #ifdef CONFIG_CURSES
2170 display
= DT_CURSES
;
2172 error_report("curses support is disabled");
2175 } else if (strstart(p
, "gtk", &opts
)) {
2179 const char *nextopt
;
2181 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2183 if (strstart(opts
, "on", &nextopt
)) {
2184 grab_on_hover
= true;
2185 } else if (strstart(opts
, "off", &nextopt
)) {
2186 grab_on_hover
= false;
2188 goto invalid_gtk_args
;
2190 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2192 if (strstart(opts
, "on", &nextopt
)) {
2194 } else if (strstart(opts
, "off", &nextopt
)) {
2197 goto invalid_gtk_args
;
2201 error_report("invalid GTK option string");
2207 error_report("GTK support is disabled");
2210 } else if (strstart(p
, "none", &opts
)) {
2213 error_report("unknown display type");
2220 static int balloon_parse(const char *arg
)
2224 if (strcmp(arg
, "none") == 0) {
2228 if (!strncmp(arg
, "virtio", 6)) {
2229 if (arg
[6] == ',') {
2230 /* have params -> parse them */
2231 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2236 /* create empty opts */
2237 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2240 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2247 #if defined(CONFIG_RUBY)
2248 /* Ruby interface for QEMU. See README.EXT for programming example. */
2252 static VALUE
qemu_open(int argc
, VALUE
*argv
, VALUE klass
)
2255 for (i
= 0; i
< argc
; i
++) {
2256 argv
[i
] = StringValue(argv
[i
]);
2257 fprintf(stderr
, "argv[%d] = %s\n", i
, StringValuePtr(argv
[i
]));
2259 //~ if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
2260 //~ mode = 0666; /* default value */
2262 return INT2FIX(argc
);
2265 void Init_qemu(void)
2267 printf("%s\n", __func__
);
2268 VALUE cQEMU
= rb_define_class("QEMU", rb_cObject
);
2269 rb_define_singleton_method(cQEMU
, "run", qemu_open
, -1);
2274 #endif /* CONFIG_RUBY */
2276 #if defined(CONFIG_DLL)
2277 BOOL APIENTRY
DllMain(HINSTANCE hModule
, DWORD ul_reason_for_call
, LPVOID data
)
2281 #endif /* CONFIG_DLL */
2283 char *qemu_find_file(int type
, const char *name
)
2289 /* Try the name as a straight path first */
2290 if (access(name
, R_OK
) == 0) {
2291 trace_load_file(name
, name
);
2292 return g_strdup(name
);
2296 case QEMU_FILE_TYPE_BIOS
:
2299 case QEMU_FILE_TYPE_KEYMAP
:
2300 subdir
= "keymaps/";
2306 for (i
= 0; i
< data_dir_idx
; i
++) {
2307 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2308 if (access(buf
, R_OK
) == 0) {
2309 trace_load_file(name
, buf
);
2317 static inline bool nonempty_str(const char *str
)
2322 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2326 const char *name
, *file
, *str
;
2327 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2329 if (fw_cfg
== NULL
) {
2330 error_report("fw_cfg device not available");
2333 name
= qemu_opt_get(opts
, "name");
2334 file
= qemu_opt_get(opts
, "file");
2335 str
= qemu_opt_get(opts
, "string");
2337 /* we need name and either a file or the content string */
2338 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2339 error_report("invalid argument(s)");
2342 if (nonempty_str(file
) && nonempty_str(str
)) {
2343 error_report("file and string are mutually exclusive");
2346 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2347 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2350 if (strncmp(name
, "opt/", 4) != 0) {
2351 warn_report("externally provided fw_cfg item names "
2352 "should be prefixed with \"opt/\"");
2354 if (nonempty_str(str
)) {
2355 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2356 buf
= g_memdup(str
, size
);
2358 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2359 error_report("can't load %s", file
);
2363 /* For legacy, keep user files in a specific global order. */
2364 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2365 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2366 fw_cfg_reset_order_override(fw_cfg
);
2370 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2372 return qdev_device_help(opts
);
2375 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2380 dev
= qdev_device_add(opts
, &err
);
2382 error_report_err(err
);
2385 object_unref(OBJECT(dev
));
2389 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2391 Error
*local_err
= NULL
;
2393 qemu_chr_new_from_opts(opts
, &local_err
);
2395 error_report_err(local_err
);
2401 #ifdef CONFIG_VIRTFS
2402 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2404 return qemu_fsdev_add(opts
);
2408 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2411 const char *chardev
;
2415 mode
= qemu_opt_get(opts
, "mode");
2419 if (strcmp(mode
, "readline") == 0) {
2420 flags
= MONITOR_USE_READLINE
;
2421 } else if (strcmp(mode
, "control") == 0) {
2422 flags
= MONITOR_USE_CONTROL
;
2424 error_report("unknown monitor mode \"%s\"", mode
);
2428 if (qemu_opt_get_bool(opts
, "pretty", 0))
2429 flags
|= MONITOR_USE_PRETTY
;
2431 if (qemu_opt_get_bool(opts
, "default", 0)) {
2432 error_report("option 'default' does nothing and is deprecated");
2435 chardev
= qemu_opt_get(opts
, "chardev");
2436 chr
= qemu_chr_find(chardev
);
2438 error_report("chardev \"%s\" not found", chardev
);
2442 monitor_init(chr
, flags
);
2446 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2448 static int monitor_device_index
= 0;
2453 if (strstart(optarg
, "chardev:", &p
)) {
2454 snprintf(label
, sizeof(label
), "%s", p
);
2456 snprintf(label
, sizeof(label
), "compat_monitor%d",
2457 monitor_device_index
);
2458 opts
= qemu_chr_parse_compat(label
, optarg
);
2460 error_report("parse error: %s", optarg
);
2465 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2466 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2467 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2468 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2469 monitor_device_index
++;
2472 struct device_config
{
2474 DEV_USB
, /* -usbdevice */
2476 DEV_SERIAL
, /* -serial */
2477 DEV_PARALLEL
, /* -parallel */
2478 DEV_VIRTCON
, /* -virtioconsole */
2479 DEV_DEBUGCON
, /* -debugcon */
2480 DEV_GDB
, /* -gdb, -s */
2481 DEV_SCLP
, /* s390 sclp */
2483 const char *cmdline
;
2485 QTAILQ_ENTRY(device_config
) next
;
2488 static QTAILQ_HEAD(, device_config
) device_configs
=
2489 QTAILQ_HEAD_INITIALIZER(device_configs
);
2491 static void add_device_config(int type
, const char *cmdline
)
2493 struct device_config
*conf
;
2495 conf
= g_malloc0(sizeof(*conf
));
2497 conf
->cmdline
= cmdline
;
2498 loc_save(&conf
->loc
);
2499 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2502 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2504 struct device_config
*conf
;
2507 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2508 if (conf
->type
!= type
)
2510 loc_push_restore(&conf
->loc
);
2511 rc
= func(conf
->cmdline
);
2512 loc_pop(&conf
->loc
);
2520 static int serial_parse(const char *devname
)
2522 static int index
= 0;
2525 if (strcmp(devname
, "none") == 0)
2527 if (index
== MAX_SERIAL_PORTS
) {
2528 error_report("too many serial ports");
2531 snprintf(label
, sizeof(label
), "serial%d", index
);
2532 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2533 if (!serial_hds
[index
]) {
2534 error_report("could not connect serial device"
2535 " to character backend '%s'", devname
);
2542 static int parallel_parse(const char *devname
)
2544 static int index
= 0;
2547 if (strcmp(devname
, "none") == 0)
2549 if (index
== MAX_PARALLEL_PORTS
) {
2550 error_report("too many parallel ports");
2553 snprintf(label
, sizeof(label
), "parallel%d", index
);
2554 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2555 if (!parallel_hds
[index
]) {
2556 error_report("could not connect parallel device"
2557 " to character backend '%s'", devname
);
2564 static int virtcon_parse(const char *devname
)
2566 QemuOptsList
*device
= qemu_find_opts("device");
2567 static int index
= 0;
2569 QemuOpts
*bus_opts
, *dev_opts
;
2571 if (strcmp(devname
, "none") == 0)
2573 if (index
== MAX_VIRTIO_CONSOLES
) {
2574 error_report("too many virtio consoles");
2578 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2579 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2581 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2582 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2584 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2585 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2586 if (!virtcon_hds
[index
]) {
2587 error_report("could not connect virtio console"
2588 " to character backend '%s'", devname
);
2591 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2597 static int sclp_parse(const char *devname
)
2599 QemuOptsList
*device
= qemu_find_opts("device");
2600 static int index
= 0;
2604 if (strcmp(devname
, "none") == 0) {
2607 if (index
== MAX_SCLP_CONSOLES
) {
2608 error_report("too many sclp consoles");
2612 assert(arch_type
== QEMU_ARCH_S390X
);
2614 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2615 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2617 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2618 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2619 if (!sclp_hds
[index
]) {
2620 error_report("could not connect sclp console"
2621 " to character backend '%s'", devname
);
2624 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2630 static int debugcon_parse(const char *devname
)
2634 if (!qemu_chr_new("debugcon", devname
)) {
2637 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2639 error_report("already have a debugcon device");
2642 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2643 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2647 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2649 const MachineClass
*mc1
= a
, *mc2
= b
;
2652 if (mc1
->family
== NULL
) {
2653 if (mc2
->family
== NULL
) {
2654 /* Compare standalone machine types against each other; they sort
2655 * in increasing order.
2657 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2658 object_class_get_name(OBJECT_CLASS(mc2
)));
2661 /* Standalone machine types sort after families. */
2665 if (mc2
->family
== NULL
) {
2666 /* Families sort before standalone machine types. */
2670 /* Families sort between each other alphabetically increasingly. */
2671 res
= strcmp(mc1
->family
, mc2
->family
);
2676 /* Within the same family, machine types sort in decreasing order. */
2677 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2678 object_class_get_name(OBJECT_CLASS(mc1
)));
2681 static MachineClass
*machine_parse(const char *name
)
2683 MachineClass
*mc
= NULL
;
2684 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2687 mc
= find_machine(name
);
2690 g_slist_free(machines
);
2693 if (name
&& !is_help_option(name
)) {
2694 error_report("unsupported machine type");
2695 error_printf("Use -machine help to list supported machines\n");
2697 printf("Supported machines are:\n");
2698 machines
= g_slist_sort(machines
, machine_class_cmp
);
2699 for (el
= machines
; el
; el
= el
->next
) {
2700 MachineClass
*mc
= el
->data
;
2702 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2704 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2705 mc
->is_default
? " (default)" : "");
2709 g_slist_free(machines
);
2710 exit(!name
|| !is_help_option(name
));
2713 void qemu_add_exit_notifier(Notifier
*notify
)
2715 notifier_list_add(&exit_notifiers
, notify
);
2718 void qemu_remove_exit_notifier(Notifier
*notify
)
2720 notifier_remove(notify
);
2723 static void qemu_run_exit_notifiers(void)
2725 notifier_list_notify(&exit_notifiers
, NULL
);
2728 static bool machine_init_done
;
2730 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2732 notifier_list_add(&machine_init_done_notifiers
, notify
);
2733 if (machine_init_done
) {
2734 notify
->notify(notify
, NULL
);
2738 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2740 notifier_remove(notify
);
2743 static void qemu_run_machine_init_done_notifiers(void)
2745 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2746 machine_init_done
= true;
2749 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2750 const char **poptarg
, int *poptind
)
2752 const QEMUOption
*popt
;
2753 int optind
= *poptind
;
2754 char *r
= argv
[optind
];
2757 loc_set_cmdline(argv
, optind
, 1);
2759 /* Treat --foo the same as -foo. */
2762 popt
= qemu_options
;
2765 error_report("invalid option");
2768 if (!strcmp(popt
->name
, r
+ 1))
2772 if (popt
->flags
& HAS_ARG
) {
2773 if (optind
>= argc
) {
2774 error_report("requires an argument");
2777 optarg
= argv
[optind
++];
2778 loc_set_cmdline(argv
, optind
- 2, 2);
2789 static MachineClass
*select_machine(void)
2791 MachineClass
*machine_class
= find_default_machine();
2796 loc_push_none(&loc
);
2798 opts
= qemu_get_machine_opts();
2799 qemu_opts_loc_restore(opts
);
2801 optarg
= qemu_opt_get(opts
, "type");
2803 machine_class
= machine_parse(optarg
);
2806 if (!machine_class
) {
2807 error_report("No machine specified, and there is no default");
2808 error_printf("Use -machine help to list supported machines\n");
2813 return machine_class
;
2816 static int machine_set_property(void *opaque
,
2817 const char *name
, const char *value
,
2820 Object
*obj
= OBJECT(opaque
);
2821 Error
*local_err
= NULL
;
2824 if (strcmp(name
, "type") == 0) {
2828 qom_name
= g_strdup(name
);
2829 for (p
= qom_name
; *p
; p
++) {
2835 object_property_parse(obj
, value
, qom_name
, &local_err
);
2839 error_report_err(local_err
);
2848 * Initial object creation happens before all other
2849 * QEMU data types are created. The majority of objects
2850 * can be created at this point. The rng-egd object
2851 * cannot be created here, as it depends on the chardev
2854 static bool object_create_initial(const char *type
)
2856 if (g_str_equal(type
, "rng-egd")) {
2861 * return false for concrete netfilters since
2862 * they depend on netdevs already existing
2864 if (g_str_equal(type
, "filter-buffer") ||
2865 g_str_equal(type
, "filter-dump") ||
2866 g_str_equal(type
, "filter-mirror") ||
2867 g_str_equal(type
, "filter-redirector") ||
2868 g_str_equal(type
, "colo-compare") ||
2869 g_str_equal(type
, "filter-rewriter") ||
2870 g_str_equal(type
, "filter-replay")) {
2874 /* Memory allocation by backends needs to be done
2875 * after configure_accelerator() (due to the tcg_enabled()
2876 * checks at memory_region_init_*()).
2878 * Also, allocation of large amounts of memory may delay
2879 * chardev initialization for too long, and trigger timeouts
2880 * on software that waits for a monitor socket to be created
2883 if (g_str_has_prefix(type
, "memory-backend-")) {
2892 * The remainder of object creation happens after the
2893 * creation of chardev, fsdev, net clients and device data types.
2895 static bool object_create_delayed(const char *type
)
2897 return !object_create_initial(type
);
2901 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2905 const char *mem_str
;
2906 const char *maxmem_str
, *slots_str
;
2907 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2908 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2911 loc_push_none(&loc
);
2912 qemu_opts_loc_restore(opts
);
2915 mem_str
= qemu_opt_get(opts
, "size");
2918 error_report("missing 'size' option value");
2922 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2924 /* Fix up legacy suffix-less format */
2925 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2926 uint64_t overflow_check
= sz
;
2929 if ((sz
>> 20) != overflow_check
) {
2930 error_report("too large 'size' option value");
2936 /* backward compatibility behaviour for case "-m 0" */
2938 sz
= default_ram_size
;
2941 sz
= QEMU_ALIGN_UP(sz
, 8192);
2943 if (ram_size
!= sz
) {
2944 error_report("ram size too large");
2948 /* store value for the future use */
2949 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2950 *maxram_size
= ram_size
;
2952 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2953 slots_str
= qemu_opt_get(opts
, "slots");
2954 if (maxmem_str
&& slots_str
) {
2957 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2958 slots
= qemu_opt_get_number(opts
, "slots", 0);
2959 if (sz
< ram_size
) {
2960 error_report("invalid value of -m option maxmem: "
2961 "maximum memory size (0x%" PRIx64
") must be at least "
2962 "the initial memory size (0x" RAM_ADDR_FMT
")",
2965 } else if (sz
> ram_size
) {
2967 error_report("invalid value of -m option: maxmem was "
2968 "specified, but no hotplug slots were specified");
2972 error_report("invalid value of -m option maxmem: "
2973 "memory slots were specified but maximum memory size "
2974 "(0x%" PRIx64
") is equal to the initial memory size "
2975 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2981 } else if ((!maxmem_str
&& slots_str
) ||
2982 (maxmem_str
&& !slots_str
)) {
2983 error_report("invalid -m option value: missing "
2984 "'%s' option", slots_str
? "maxmem" : "slots");
2991 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2995 g
= g_malloc0(sizeof(*g
));
2996 g
->driver
= qemu_opt_get(opts
, "driver");
2997 g
->property
= qemu_opt_get(opts
, "property");
2998 g
->value
= qemu_opt_get(opts
, "value");
2999 g
->user_provided
= true;
3000 g
->errp
= &error_fatal
;
3001 qdev_prop_register_global(g
);
3005 static int qemu_read_default_config_file(void)
3009 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
3010 if (ret
< 0 && ret
!= -ENOENT
) {
3017 static void user_register_global_props(void)
3019 qemu_opts_foreach(qemu_find_opts("global"),
3020 global_init_func
, NULL
, NULL
);
3024 * Note: we should see that these properties are actually having a
3025 * priority: accel < machine < user. This means e.g. when user
3026 * specifies something in "-global", it'll always be used with highest
3027 * priority than either machine/accelerator compat properties.
3029 static void register_global_properties(MachineState
*ms
)
3031 accel_register_compat_props(ms
->accelerator
);
3032 machine_register_compat_props(ms
);
3033 user_register_global_props();
3036 int main(int argc
, char **argv
)
3039 int snapshot
, linux_boot
;
3040 const char *initrd_filename
;
3041 const char *kernel_filename
, *kernel_cmdline
;
3042 const char *boot_order
= NULL
;
3043 const char *boot_once
= NULL
;
3045 int cyls
, heads
, secs
, translation
;
3046 QemuOpts
*opts
, *machine_opts
;
3047 QemuOpts
*hda_opts
= NULL
, *icount_opts
= NULL
, *accel_opts
= NULL
;
3048 QemuOptsList
*olist
;
3051 const char *loadvm
= NULL
;
3052 MachineClass
*machine_class
;
3053 const char *cpu_model
;
3054 const char *vga_model
= NULL
;
3055 const char *qtest_chrdev
= NULL
;
3056 const char *qtest_log
= NULL
;
3057 const char *pid_file
= NULL
;
3058 const char *incoming
= NULL
;
3059 bool defconfig
= true;
3060 bool userconfig
= true;
3061 bool nographic
= false;
3062 DisplayType display_type
= DT_DEFAULT
;
3063 int display_remote
= 0;
3064 const char *log_mask
= NULL
;
3065 const char *log_file
= NULL
;
3066 char *trace_file
= NULL
;
3067 ram_addr_t maxram_size
;
3068 uint64_t ram_slots
= 0;
3069 FILE *vmstate_dump_file
= NULL
;
3070 Error
*main_loop_err
= NULL
;
3072 bool list_data_dirs
= false;
3073 typedef struct BlockdevOptions_queue
{
3074 BlockdevOptions
*bdo
;
3076 QSIMPLEQ_ENTRY(BlockdevOptions_queue
) entry
;
3077 } BlockdevOptions_queue
;
3078 QSIMPLEQ_HEAD(, BlockdevOptions_queue
) bdo_queue
3079 = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
3081 module_call_init(MODULE_INIT_TRACE
);
3083 qemu_init_cpu_list();
3084 qemu_init_cpu_loop();
3085 qemu_mutex_lock_iothread();
3087 atexit(qemu_run_exit_notifiers
);
3088 error_set_progname(argv
[0]);
3089 qemu_init_exec_dir(argv
[0]);
3091 module_call_init(MODULE_INIT_QOM
);
3092 monitor_init_qmp_commands();
3094 qemu_add_opts(&qemu_drive_opts
);
3095 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3096 qemu_add_drive_opts(&qemu_common_drive_opts
);
3097 qemu_add_drive_opts(&qemu_drive_opts
);
3098 qemu_add_drive_opts(&bdrv_runtime_opts
);
3099 qemu_add_opts(&qemu_chardev_opts
);
3100 qemu_add_opts(&qemu_device_opts
);
3101 qemu_add_opts(&qemu_netdev_opts
);
3102 qemu_add_opts(&qemu_net_opts
);
3103 qemu_add_opts(&qemu_rtc_opts
);
3104 qemu_add_opts(&qemu_global_opts
);
3105 qemu_add_opts(&qemu_mon_opts
);
3106 qemu_add_opts(&qemu_trace_opts
);
3107 qemu_add_opts(&qemu_option_rom_opts
);
3108 qemu_add_opts(&qemu_machine_opts
);
3109 qemu_add_opts(&qemu_accel_opts
);
3110 qemu_add_opts(&qemu_mem_opts
);
3111 qemu_add_opts(&qemu_smp_opts
);
3112 qemu_add_opts(&qemu_boot_opts
);
3113 qemu_add_opts(&qemu_sandbox_opts
);
3114 qemu_add_opts(&qemu_add_fd_opts
);
3115 qemu_add_opts(&qemu_object_opts
);
3116 qemu_add_opts(&qemu_tpmdev_opts
);
3117 qemu_add_opts(&qemu_realtime_opts
);
3118 qemu_add_opts(&qemu_msg_opts
);
3119 qemu_add_opts(&qemu_name_opts
);
3120 qemu_add_opts(&qemu_numa_opts
);
3121 qemu_add_opts(&qemu_icount_opts
);
3122 qemu_add_opts(&qemu_semihosting_config_opts
);
3123 qemu_add_opts(&qemu_fw_cfg_opts
);
3124 module_call_init(MODULE_INIT_OPTS
);
3128 if (qcrypto_init(&err
) < 0) {
3129 error_reportf_err(err
, "cannot initialize crypto: ");
3132 rtc_clock
= QEMU_CLOCK_HOST
;
3134 QLIST_INIT (&vm_change_state_head
);
3135 os_setup_early_signal_handling();
3139 cyls
= heads
= secs
= 0;
3140 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3144 bdrv_init_with_whitelist();
3148 /* first pass of option parsing */
3150 while (optind
< argc
) {
3151 if (argv
[optind
][0] != '-') {
3155 const QEMUOption
*popt
;
3157 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3158 switch (popt
->index
) {
3159 case QEMU_OPTION_nodefconfig
:
3162 case QEMU_OPTION_nouserconfig
:
3169 if (defconfig
&& userconfig
) {
3170 if (qemu_read_default_config_file() < 0) {
3175 /* second pass of option parsing */
3180 if (argv
[optind
][0] != '-') {
3181 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3183 const QEMUOption
*popt
;
3185 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3186 if (!(popt
->arch_mask
& arch_type
)) {
3187 error_report("Option not supported for this target");
3190 switch(popt
->index
) {
3191 case QEMU_OPTION_no_kvm_irqchip
: {
3192 olist
= qemu_find_opts("machine");
3193 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3196 case QEMU_OPTION_cpu
:
3197 /* hw initialization will check this */
3200 case QEMU_OPTION_hda
:
3204 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3206 snprintf(buf
, sizeof(buf
),
3207 "%s,cyls=%d,heads=%d,secs=%d%s",
3208 HD_OPTS
, cyls
, heads
, secs
,
3209 translation
== BIOS_ATA_TRANSLATION_LBA
?
3211 translation
== BIOS_ATA_TRANSLATION_NONE
?
3212 ",trans=none" : "");
3213 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3216 case QEMU_OPTION_hdb
:
3217 case QEMU_OPTION_hdc
:
3218 case QEMU_OPTION_hdd
:
3219 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3222 case QEMU_OPTION_blockdev
:
3225 BlockdevOptions_queue
*bdo
;
3227 v
= qobject_input_visitor_new_str(optarg
, "driver", &err
);
3229 error_report_err(err
);
3233 bdo
= g_new(BlockdevOptions_queue
, 1);
3234 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
3237 loc_save(&bdo
->loc
);
3238 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
3241 case QEMU_OPTION_drive
:
3242 if (drive_def(optarg
) == NULL
) {
3246 case QEMU_OPTION_set
:
3247 if (qemu_set_option(optarg
) != 0)
3250 case QEMU_OPTION_global
:
3251 if (qemu_global_option(optarg
) != 0)
3254 case QEMU_OPTION_mtdblock
:
3255 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3257 case QEMU_OPTION_sd
:
3258 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3260 case QEMU_OPTION_pflash
:
3261 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3263 case QEMU_OPTION_snapshot
:
3266 case QEMU_OPTION_hdachs
:
3270 cyls
= strtol(p
, (char **)&p
, 0);
3271 if (cyls
< 1 || cyls
> 16383)
3276 heads
= strtol(p
, (char **)&p
, 0);
3277 if (heads
< 1 || heads
> 16)
3282 secs
= strtol(p
, (char **)&p
, 0);
3283 if (secs
< 1 || secs
> 63)
3287 if (!strcmp(p
, "large")) {
3288 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3289 } else if (!strcmp(p
, "rechs")) {
3290 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3291 } else if (!strcmp(p
, "none")) {
3292 translation
= BIOS_ATA_TRANSLATION_NONE
;
3293 } else if (!strcmp(p
, "lba")) {
3294 translation
= BIOS_ATA_TRANSLATION_LBA
;
3295 } else if (!strcmp(p
, "auto")) {
3296 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3300 } else if (*p
!= '\0') {
3302 error_report("invalid physical CHS format");
3305 if (hda_opts
!= NULL
) {
3306 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3308 qemu_opt_set_number(hda_opts
, "heads", heads
,
3310 qemu_opt_set_number(hda_opts
, "secs", secs
,
3312 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3313 qemu_opt_set(hda_opts
, "trans", "large",
3315 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3316 qemu_opt_set(hda_opts
, "trans", "rechs",
3318 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3319 qemu_opt_set(hda_opts
, "trans", "lba",
3321 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3322 qemu_opt_set(hda_opts
, "trans", "none",
3327 error_report("'-hdachs' is deprecated, please use '-device"
3328 " ide-hd,cyls=c,heads=h,secs=s,...' instead");
3330 case QEMU_OPTION_numa
:
3331 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3337 case QEMU_OPTION_display
:
3338 display_type
= select_display(optarg
);
3340 case QEMU_OPTION_nographic
:
3341 olist
= qemu_find_opts("machine");
3342 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3344 display_type
= DT_NONE
;
3346 case QEMU_OPTION_curses
:
3347 #ifdef CONFIG_CURSES
3348 display_type
= DT_CURSES
;
3350 error_report("curses support is disabled");
3354 case QEMU_OPTION_portrait
:
3355 graphic_rotate
= 90;
3357 case QEMU_OPTION_rotate
:
3358 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3359 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3360 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3361 error_report("only 90, 180, 270 deg rotation is available");
3365 case QEMU_OPTION_kernel
:
3366 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3369 case QEMU_OPTION_initrd
:
3370 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3373 case QEMU_OPTION_append
:
3374 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3377 case QEMU_OPTION_dtb
:
3378 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3381 case QEMU_OPTION_cdrom
:
3382 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3384 case QEMU_OPTION_boot
:
3385 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3391 case QEMU_OPTION_fda
:
3392 case QEMU_OPTION_fdb
:
3393 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3396 case QEMU_OPTION_no_fd_bootchk
:
3399 case QEMU_OPTION_netdev
:
3401 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3405 case QEMU_OPTION_net
:
3407 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3411 #ifdef CONFIG_LIBISCSI
3412 case QEMU_OPTION_iscsi
:
3413 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3421 case QEMU_OPTION_tftp
:
3422 error_report("The -tftp option is deprecated. "
3423 "Please use '-netdev user,tftp=...' instead.");
3424 legacy_tftp_prefix
= optarg
;
3426 case QEMU_OPTION_bootp
:
3427 error_report("The -bootp option is deprecated. "
3428 "Please use '-netdev user,bootfile=...' instead.");
3429 legacy_bootp_filename
= optarg
;
3431 case QEMU_OPTION_redir
:
3432 error_report("The -redir option is deprecated. "
3433 "Please use '-netdev user,hostfwd=...' instead.");
3434 if (net_slirp_redir(optarg
) < 0)
3438 case QEMU_OPTION_bt
:
3439 add_device_config(DEV_BT
, optarg
);
3441 case QEMU_OPTION_audio_help
:
3445 case QEMU_OPTION_soundhw
:
3446 select_soundhw (optarg
);
3451 case QEMU_OPTION_version
:
3456 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3463 case QEMU_OPTION_tpmdev
:
3464 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3469 case QEMU_OPTION_mempath
:
3472 case QEMU_OPTION_mem_prealloc
:
3481 case QEMU_OPTION_DFILTER
:
3482 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3485 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3487 case QEMU_OPTION_gdb
:
3488 add_device_config(DEV_GDB
, optarg
);
3491 if (is_help_option(optarg
)) {
3492 list_data_dirs
= true;
3493 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3494 data_dir
[data_dir_idx
++] = optarg
;
3497 case QEMU_OPTION_bios
:
3498 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3501 case QEMU_OPTION_singlestep
:
3508 keyboard_layout
= optarg
;
3510 case QEMU_OPTION_localtime
:
3513 case QEMU_OPTION_vga
:
3522 w
= strtol(p
, (char **)&p
, 10);
3525 error_report("invalid resolution or depth");
3531 h
= strtol(p
, (char **)&p
, 10);
3536 depth
= strtol(p
, (char **)&p
, 10);
3537 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3538 depth
!= 24 && depth
!= 32)
3540 } else if (*p
== '\0') {
3541 depth
= graphic_depth
;
3548 graphic_depth
= depth
;
3551 case QEMU_OPTION_echr
:
3554 term_escape_char
= strtol(optarg
, &r
, 0);
3556 printf("Bad argument to echr\n");
3559 case QEMU_OPTION_monitor
:
3560 default_monitor
= 0;
3561 if (strncmp(optarg
, "none", 4)) {
3562 monitor_parse(optarg
, "readline", false);
3565 case QEMU_OPTION_qmp
:
3566 monitor_parse(optarg
, "control", false);
3567 default_monitor
= 0;
3569 case QEMU_OPTION_qmp_pretty
:
3570 monitor_parse(optarg
, "control", true);
3571 default_monitor
= 0;
3573 case QEMU_OPTION_mon
:
3574 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3579 default_monitor
= 0;
3581 case QEMU_OPTION_chardev
:
3582 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3588 case QEMU_OPTION_fsdev
:
3589 olist
= qemu_find_opts("fsdev");
3591 error_report("fsdev support is disabled");
3594 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3599 case QEMU_OPTION_virtfs
: {
3602 const char *writeout
, *sock_fd
, *socket
;
3604 olist
= qemu_find_opts("virtfs");
3606 error_report("virtfs support is disabled");
3609 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3614 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3615 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3616 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3619 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3620 qemu_opts_id(opts
) ?:
3621 qemu_opt_get(opts
, "mount_tag"),
3624 error_report("duplicate or invalid fsdev id: %s",
3625 qemu_opt_get(opts
, "mount_tag"));
3629 writeout
= qemu_opt_get(opts
, "writeout");
3631 #ifdef CONFIG_SYNC_FILE_RANGE
3632 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3634 error_report("writeout=immediate not supported "
3635 "on this platform");
3639 qemu_opt_set(fsdev
, "fsdriver",
3640 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3641 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3643 qemu_opt_set(fsdev
, "security_model",
3644 qemu_opt_get(opts
, "security_model"),
3646 socket
= qemu_opt_get(opts
, "socket");
3648 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3650 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3652 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3655 qemu_opt_set_bool(fsdev
, "readonly",
3656 qemu_opt_get_bool(opts
, "readonly", 0),
3658 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3660 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3661 qemu_opt_set(device
, "fsdev",
3662 qemu_opts_id(fsdev
), &error_abort
);
3663 qemu_opt_set(device
, "mount_tag",
3664 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3667 case QEMU_OPTION_virtfs_synth
: {
3671 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3674 error_report("duplicate option: %s", "virtfs_synth");
3677 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3679 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3681 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3682 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3683 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3686 case QEMU_OPTION_serial
:
3687 add_device_config(DEV_SERIAL
, optarg
);
3689 if (strncmp(optarg
, "mon:", 4) == 0) {
3690 default_monitor
= 0;
3693 case QEMU_OPTION_watchdog
:
3695 error_report("only one watchdog option may be given");
3700 case QEMU_OPTION_watchdog_action
:
3701 if (select_watchdog_action(optarg
) == -1) {
3702 error_report("unknown -watchdog-action parameter");
3706 case QEMU_OPTION_virtiocon
:
3707 add_device_config(DEV_VIRTCON
, optarg
);
3708 default_virtcon
= 0;
3709 if (strncmp(optarg
, "mon:", 4) == 0) {
3710 default_monitor
= 0;
3713 case QEMU_OPTION_parallel
:
3714 add_device_config(DEV_PARALLEL
, optarg
);
3715 default_parallel
= 0;
3716 if (strncmp(optarg
, "mon:", 4) == 0) {
3717 default_monitor
= 0;
3720 case QEMU_OPTION_debugcon
:
3721 add_device_config(DEV_DEBUGCON
, optarg
);
3723 case QEMU_OPTION_loadvm
:
3726 case QEMU_OPTION_full_screen
:
3729 case QEMU_OPTION_no_frame
:
3732 case QEMU_OPTION_alt_grab
:
3735 case QEMU_OPTION_ctrl_grab
:
3738 case QEMU_OPTION_no_quit
:
3741 case QEMU_OPTION_sdl
:
3743 display_type
= DT_SDL
;
3746 error_report("SDL support is disabled");
3749 case QEMU_OPTION_pidfile
:
3752 case QEMU_OPTION_win2k_hack
:
3753 win2k_install_hack
= 1;
3755 case QEMU_OPTION_rtc_td_hack
: {
3756 static GlobalProperty slew_lost_ticks
= {
3757 .driver
= "mc146818rtc",
3758 .property
= "lost_tick_policy",
3762 qdev_prop_register_global(&slew_lost_ticks
);
3765 case QEMU_OPTION_acpitable
:
3766 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3771 acpi_table_add(opts
, &error_fatal
);
3773 case QEMU_OPTION_smbios
:
3774 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3779 smbios_entry_add(opts
, &error_fatal
);
3781 case QEMU_OPTION_fwcfg
:
3782 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3788 case QEMU_OPTION_enable_kvm
:
3789 olist
= qemu_find_opts("machine");
3790 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3792 case QEMU_OPTION_enable_hax
:
3793 olist
= qemu_find_opts("machine");
3794 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3797 case QEMU_OPTION_machine
:
3798 olist
= qemu_find_opts("machine");
3799 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3804 case QEMU_OPTION_no_kvm
:
3805 olist
= qemu_find_opts("machine");
3806 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3808 case QEMU_OPTION_no_kvm_pit
: {
3809 warn_report("ignoring deprecated option");
3812 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3813 static GlobalProperty kvm_pit_lost_tick_policy
= {
3814 .driver
= "kvm-pit",
3815 .property
= "lost_tick_policy",
3819 warn_report("deprecated, replaced by "
3820 "-global kvm-pit.lost_tick_policy=discard");
3821 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3824 case QEMU_OPTION_accel
:
3825 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3827 optarg
= qemu_opt_get(accel_opts
, "accel");
3828 if (!optarg
|| is_help_option(optarg
)) {
3829 error_printf("Possible accelerators: kvm, xen, hax, tcg\n");
3832 opts
= qemu_opts_create(qemu_find_opts("machine"), NULL
,
3833 false, &error_abort
);
3834 qemu_opt_set(opts
, "accel", optarg
, &error_abort
);
3836 case QEMU_OPTION_usb
:
3837 olist
= qemu_find_opts("machine");
3838 qemu_opts_parse_noisily(olist
, "usb=on", false);
3840 case QEMU_OPTION_usbdevice
:
3841 error_report("'-usbdevice' is deprecated, please use "
3842 "'-device usb-...' instead");
3843 olist
= qemu_find_opts("machine");
3844 qemu_opts_parse_noisily(olist
, "usb=on", false);
3845 add_device_config(DEV_USB
, optarg
);
3847 case QEMU_OPTION_device
:
3848 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3853 case QEMU_OPTION_smp
:
3854 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3859 case QEMU_OPTION_vnc
:
3860 vnc_parse(optarg
, &error_fatal
);
3862 case QEMU_OPTION_no_acpi
:
3865 case QEMU_OPTION_no_hpet
:
3868 case QEMU_OPTION_balloon
:
3869 if (balloon_parse(optarg
) < 0) {
3870 error_report("unknown -balloon argument %s", optarg
);
3874 case QEMU_OPTION_no_reboot
:
3877 case QEMU_OPTION_no_shutdown
:
3880 case QEMU_OPTION_show_cursor
:
3883 case QEMU_OPTION_uuid
:
3884 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3885 error_report("failed to parse UUID string: wrong format");
3888 qemu_uuid_set
= true;
3890 case QEMU_OPTION_option_rom
:
3891 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3892 error_report("too many option ROMs");
3895 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3900 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3901 option_rom
[nb_option_roms
].bootindex
=
3902 qemu_opt_get_number(opts
, "bootindex", -1);
3903 if (!option_rom
[nb_option_roms
].name
) {
3904 error_report("Option ROM file is not specified");
3909 case QEMU_OPTION_semihosting
:
3910 semihosting
.enabled
= true;
3911 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3913 case QEMU_OPTION_semihosting_config
:
3914 semihosting
.enabled
= true;
3915 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3918 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3920 const char *target
= qemu_opt_get(opts
, "target");
3921 if (target
!= NULL
) {
3922 if (strcmp("native", target
) == 0) {
3923 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3924 } else if (strcmp("gdb", target
) == 0) {
3925 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3926 } else if (strcmp("auto", target
) == 0) {
3927 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3929 error_report("unsupported semihosting-config %s",
3934 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3936 /* Set semihosting argument count and vector */
3937 qemu_opt_foreach(opts
, add_semihosting_arg
,
3938 &semihosting
, NULL
);
3940 error_report("unsupported semihosting-config %s", optarg
);
3944 case QEMU_OPTION_tdf
:
3945 warn_report("ignoring deprecated option");
3947 case QEMU_OPTION_name
:
3948 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3954 case QEMU_OPTION_prom_env
:
3955 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3956 error_report("too many prom variables");
3959 prom_envs
[nb_prom_envs
] = optarg
;
3962 case QEMU_OPTION_old_param
:
3965 case QEMU_OPTION_clock
:
3966 /* Clock options no longer exist. Keep this option for
3967 * backward compatibility.
3970 case QEMU_OPTION_startdate
:
3971 configure_rtc_date_offset(optarg
, 1);
3973 case QEMU_OPTION_rtc
:
3974 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3979 configure_rtc(opts
);
3981 case QEMU_OPTION_tb_size
:
3983 error_report("TCG is disabled");
3986 if (qemu_strtoul(optarg
, NULL
, 0, &tcg_tb_size
) < 0) {
3987 error_report("Invalid argument to -tb-size");
3991 case QEMU_OPTION_icount
:
3992 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3998 case QEMU_OPTION_incoming
:
4000 runstate_set(RUN_STATE_INMIGRATE
);
4004 case QEMU_OPTION_only_migratable
:
4006 * TODO: we can remove this option one day, and we
4009 * "-global migration.only-migratable=true"
4011 qemu_global_option("migration.only-migratable=true");
4013 case QEMU_OPTION_nodefaults
:
4016 case QEMU_OPTION_xen_domid
:
4017 if (!(xen_available())) {
4018 error_report("Option not supported for this target");
4021 xen_domid
= atoi(optarg
);
4023 case QEMU_OPTION_xen_create
:
4024 if (!(xen_available())) {
4025 error_report("Option not supported for this target");
4028 xen_mode
= XEN_CREATE
;
4030 case QEMU_OPTION_xen_attach
:
4031 if (!(xen_available())) {
4032 error_report("Option not supported for this target");
4035 xen_mode
= XEN_ATTACH
;
4037 case QEMU_OPTION_xen_domid_restrict
:
4038 if (!(xen_available())) {
4039 error_report("Option not supported for this target");
4042 xen_domid_restrict
= true;
4044 case QEMU_OPTION_trace
:
4046 trace_file
= trace_opt_parse(optarg
);
4048 case QEMU_OPTION_trace_unassigned
:
4049 trace_unassigned
= true;
4051 case QEMU_OPTION_readconfig
:
4053 int ret
= qemu_read_config_file(optarg
);
4055 error_report("read config %s: %s", optarg
,
4061 case QEMU_OPTION_spice
:
4062 olist
= qemu_find_opts("spice");
4064 error_report("spice support is disabled");
4067 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
4073 case QEMU_OPTION_writeconfig
:
4076 if (strcmp(optarg
, "-") == 0) {
4079 fp
= fopen(optarg
, "w");
4081 error_report("open %s: %s", optarg
,
4086 qemu_config_write(fp
);
4092 case QEMU_OPTION_qtest
:
4093 qtest_chrdev
= optarg
;
4095 case QEMU_OPTION_qtest_log
:
4098 case QEMU_OPTION_sandbox
:
4099 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4105 case QEMU_OPTION_add_fd
:
4107 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4113 error_report("File descriptor passing is disabled on this "
4118 case QEMU_OPTION_object
:
4119 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
4125 case QEMU_OPTION_realtime
:
4126 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4131 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4133 case QEMU_OPTION_msg
:
4134 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4139 configure_msg(opts
);
4141 case QEMU_OPTION_dump_vmstate
:
4142 if (vmstate_dump_file
) {
4143 error_report("only one '-dump-vmstate' "
4144 "option may be given");
4147 vmstate_dump_file
= fopen(optarg
, "w");
4148 if (vmstate_dump_file
== NULL
) {
4149 error_report("open %s: %s", optarg
, strerror(errno
));
4154 os_parse_cmd_args(popt
->index
, optarg
);
4159 * Clear error location left behind by the loop.
4160 * Best done right after the loop. Do not insert code here!
4164 replay_configure(icount_opts
);
4166 machine_class
= select_machine();
4168 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4172 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4173 error_report("could not acquire pid file: %s", strerror(errno
));
4177 if (qemu_init_main_loop(&main_loop_err
)) {
4178 error_report_err(main_loop_err
);
4182 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4183 parse_sandbox
, NULL
, NULL
)) {
4187 if (qemu_opts_foreach(qemu_find_opts("name"),
4188 parse_name
, NULL
, NULL
)) {
4193 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4194 parse_add_fd
, NULL
, NULL
)) {
4198 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4199 cleanup_add_fd
, NULL
, NULL
)) {
4204 current_machine
= MACHINE(object_new(object_class_get_name(
4205 OBJECT_CLASS(machine_class
))));
4206 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4209 object_property_add_child(object_get_root(), "machine",
4210 OBJECT(current_machine
), &error_abort
);
4212 if (machine_class
->minimum_page_bits
) {
4213 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4214 /* This would be a board error: specifying a minimum smaller than
4215 * a target's compile-time fixed setting.
4217 g_assert_not_reached();
4221 cpu_exec_init_all();
4223 if (machine_class
->hw_version
) {
4224 qemu_set_hw_version(machine_class
->hw_version
);
4227 if (cpu_model
&& is_help_option(cpu_model
)) {
4228 list_cpus(stdout
, &fprintf
, cpu_model
);
4232 if (!trace_init_backends()) {
4235 trace_init_file(trace_file
);
4237 /* Open the logfile at this point and set the log mask if necessary.
4240 qemu_set_log_filename(log_file
, &error_fatal
);
4245 mask
= qemu_str_to_log_mask(log_mask
);
4247 qemu_print_log_usage(stdout
);
4255 /* If no data_dir is specified then try to find it relative to the
4257 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4258 data_dir
[data_dir_idx
] = os_find_datadir();
4259 if (data_dir
[data_dir_idx
] != NULL
) {
4263 /* If all else fails use the install path specified when building. */
4264 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4265 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4268 /* -L help lists the data directories and exits. */
4269 if (list_data_dirs
) {
4270 for (i
= 0; i
< data_dir_idx
; i
++) {
4271 printf("%s\n", data_dir
[i
]);
4276 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4278 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4279 if (max_cpus
> machine_class
->max_cpus
) {
4280 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4281 "supported by machine '%s' (%d)", max_cpus
,
4282 machine_class
->name
, machine_class
->max_cpus
);
4287 * Get the default machine options from the machine if it is not already
4288 * specified either by the configuration file or by the command line.
4290 if (machine_class
->default_machine_opts
) {
4291 qemu_opts_set_defaults(qemu_find_opts("machine"),
4292 machine_class
->default_machine_opts
, 0);
4295 qemu_opts_foreach(qemu_find_opts("device"),
4296 default_driver_check
, NULL
, NULL
);
4297 qemu_opts_foreach(qemu_find_opts("global"),
4298 default_driver_check
, NULL
, NULL
);
4300 if (!vga_model
&& !default_vga
) {
4301 vga_interface_type
= VGA_DEVICE
;
4303 if (!has_defaults
|| machine_class
->no_serial
) {
4306 if (!has_defaults
|| machine_class
->no_parallel
) {
4307 default_parallel
= 0;
4309 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4310 default_virtcon
= 0;
4312 if (!has_defaults
|| !machine_class
->use_sclp
) {
4315 if (!has_defaults
|| machine_class
->no_floppy
) {
4318 if (!has_defaults
|| machine_class
->no_cdrom
) {
4321 if (!has_defaults
|| machine_class
->no_sdcard
) {
4324 if (!has_defaults
) {
4325 default_monitor
= 0;
4330 if (is_daemonized()) {
4331 /* According to documentation and historically, -nographic redirects
4332 * serial port, parallel port and monitor to stdio, which does not work
4333 * with -daemonize. We can redirect these to null instead, but since
4334 * -nographic is legacy, let's just error out.
4335 * We disallow -nographic only if all other ports are not redirected
4336 * explicitly, to not break existing legacy setups which uses
4337 * -nographic _and_ redirects all ports explicitly - this is valid
4338 * usage, -nographic is just a no-op in this case.
4341 && (default_parallel
|| default_serial
4342 || default_monitor
|| default_virtcon
)) {
4343 error_report("-nographic cannot be used with -daemonize");
4346 #ifdef CONFIG_CURSES
4347 if (display_type
== DT_CURSES
) {
4348 error_report("curses display cannot be used with -daemonize");
4355 if (default_parallel
)
4356 add_device_config(DEV_PARALLEL
, "null");
4357 if (default_serial
&& default_monitor
) {
4358 add_device_config(DEV_SERIAL
, "mon:stdio");
4359 } else if (default_virtcon
&& default_monitor
) {
4360 add_device_config(DEV_VIRTCON
, "mon:stdio");
4361 } else if (default_sclp
&& default_monitor
) {
4362 add_device_config(DEV_SCLP
, "mon:stdio");
4365 add_device_config(DEV_SERIAL
, "stdio");
4366 if (default_virtcon
)
4367 add_device_config(DEV_VIRTCON
, "stdio");
4369 add_device_config(DEV_SCLP
, "stdio");
4371 if (default_monitor
)
4372 monitor_parse("stdio", "readline", false);
4376 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4377 if (default_parallel
)
4378 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4379 if (default_monitor
)
4380 monitor_parse("vc:80Cx24C", "readline", false);
4381 if (default_virtcon
)
4382 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4384 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4388 #if defined(CONFIG_VNC)
4389 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4393 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4394 #if defined(CONFIG_GTK)
4395 display_type
= DT_GTK
;
4396 #elif defined(CONFIG_SDL)
4397 display_type
= DT_SDL
;
4398 #elif defined(CONFIG_COCOA)
4399 display_type
= DT_COCOA
;
4400 #elif defined(CONFIG_VNC)
4401 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4403 display_type
= DT_NONE
;
4407 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4408 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4409 "for SDL, ignoring option");
4411 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4412 error_report("-no-quit is only valid for GTK and SDL, "
4416 if (display_type
== DT_GTK
) {
4417 early_gtk_display_init(request_opengl
);
4420 if (display_type
== DT_SDL
) {
4421 sdl_display_early_init(request_opengl
);
4424 qemu_console_early_init();
4426 if (request_opengl
== 1 && display_opengl
== 0) {
4427 #if defined(CONFIG_OPENGL)
4428 error_report("OpenGL is not supported by the display");
4430 error_report("OpenGL support is disabled");
4438 if (qemu_opts_foreach(qemu_find_opts("object"),
4439 user_creatable_add_opts_foreach
,
4440 object_create_initial
, NULL
)) {
4444 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4445 chardev_init_func
, NULL
, NULL
)) {
4449 #ifdef CONFIG_VIRTFS
4450 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4451 fsdev_init_func
, NULL
, NULL
)) {
4456 if (qemu_opts_foreach(qemu_find_opts("device"),
4457 device_help_func
, NULL
, NULL
)) {
4461 machine_opts
= qemu_get_machine_opts();
4462 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4464 object_unref(OBJECT(current_machine
));
4468 configure_accelerator(current_machine
);
4471 * Register all the global properties, including accel properties,
4472 * machine properties, and user-specified ones.
4474 register_global_properties(current_machine
);
4477 * Migration object can only be created after global properties
4478 * are applied correctly.
4480 migration_object_init();
4483 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4486 machine_opts
= qemu_get_machine_opts();
4487 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4488 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4489 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4490 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4492 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4494 boot_order
= qemu_opt_get(opts
, "order");
4496 validate_bootdevices(boot_order
, &error_fatal
);
4499 boot_once
= qemu_opt_get(opts
, "once");
4501 validate_bootdevices(boot_once
, &error_fatal
);
4504 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4505 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4509 boot_order
= machine_class
->default_boot_order
;
4512 if (!kernel_cmdline
) {
4513 kernel_cmdline
= "";
4514 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4517 linux_boot
= (kernel_filename
!= NULL
);
4519 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4520 error_report("-append only allowed with -kernel option");
4524 if (!linux_boot
&& initrd_filename
!= NULL
) {
4525 error_report("-initrd only allowed with -kernel option");
4529 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4530 /* fall back to the -kernel/-append */
4531 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4534 os_set_line_buffering();
4536 /* spice needs the timers to be initialized by this point */
4541 if (!tcg_enabled()) {
4542 error_report("-icount is not allowed with hardware virtualization");
4545 configure_icount(icount_opts
, &error_abort
);
4546 qemu_opts_del(icount_opts
);
4549 if (tcg_enabled()) {
4550 qemu_tcg_configure(accel_opts
, &error_fatal
);
4554 QemuOptsList
*net
= qemu_find_opts("net");
4555 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4557 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4563 if (net_init_clients() < 0) {
4567 if (qemu_opts_foreach(qemu_find_opts("object"),
4568 user_creatable_add_opts_foreach
,
4569 object_create_delayed
, NULL
)) {
4574 if (tpm_init() < 0) {
4579 /* init the bluetooth world */
4580 if (foreach_device_config(DEV_BT
, bt_parse
))
4583 if (!xen_enabled()) {
4584 /* On 32-bit hosts, QEMU is limited by virtual address space */
4585 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4586 error_report("at most 2047 MB RAM can be simulated");
4594 /* If the currently selected machine wishes to override the units-per-bus
4595 * property of its default HBA interface type, do so now. */
4596 if (machine_class
->units_per_default_bus
) {
4597 override_max_devs(machine_class
->block_default_type
,
4598 machine_class
->units_per_default_bus
);
4601 /* open the virtual block devices */
4602 while (!QSIMPLEQ_EMPTY(&bdo_queue
)) {
4603 BlockdevOptions_queue
*bdo
= QSIMPLEQ_FIRST(&bdo_queue
);
4605 QSIMPLEQ_REMOVE_HEAD(&bdo_queue
, entry
);
4606 loc_push_restore(&bdo
->loc
);
4607 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
4609 qapi_free_BlockdevOptions(bdo
->bdo
);
4612 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4613 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4616 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4617 &machine_class
->block_default_type
, NULL
)) {
4621 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4623 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4624 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4626 parse_numa_opts(current_machine
);
4628 if (qemu_opts_foreach(qemu_find_opts("mon"),
4629 mon_init_func
, NULL
, NULL
)) {
4633 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4635 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4637 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4639 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4642 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4645 /* If no default VGA is requested, the default is "none". */
4647 if (machine_class
->default_display
) {
4648 vga_model
= machine_class
->default_display
;
4649 } else if (vga_interface_available(VGA_CIRRUS
)) {
4650 vga_model
= "cirrus";
4651 } else if (vga_interface_available(VGA_STD
)) {
4656 select_vgahw(vga_model
);
4660 i
= select_watchdog(watchdog
);
4662 exit (i
== 1 ? 1 : 0);
4665 /* This checkpoint is required by replay to separate prior clock
4666 reading from the other reads, because timer polling functions query
4667 clock values from the log. */
4668 replay_checkpoint(CHECKPOINT_INIT
);
4669 qdev_machine_init();
4671 current_machine
->ram_size
= ram_size
;
4672 current_machine
->maxram_size
= maxram_size
;
4673 current_machine
->ram_slots
= ram_slots
;
4674 current_machine
->boot_order
= boot_order
;
4675 current_machine
->cpu_model
= cpu_model
;
4677 machine_run_board_init(current_machine
);
4683 if (hax_enabled()) {
4687 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4688 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4692 /* init USB devices */
4693 if (machine_usb(current_machine
)) {
4694 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4698 /* Check if IGD GFX passthrough. */
4701 /* init generic devices */
4702 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4703 if (qemu_opts_foreach(qemu_find_opts("device"),
4704 device_init_func
, NULL
, NULL
)) {
4708 cpu_synchronize_all_post_init();
4710 rom_reset_order_override();
4713 * Create frontends for -drive if=scsi leftovers.
4714 * Normally, frontends for -drive get created by machine
4715 * initialization for onboard SCSI HBAs. However, we create a few
4716 * more ever since SCSI qdevification, but this is pretty much an
4717 * implementation accident, and deprecated.
4719 scsi_legacy_handle_cmdline();
4721 /* Did we create any drives that we failed to create a device for? */
4722 drive_check_orphaned();
4724 /* Don't warn about the default network setup that you get if
4725 * no command line -net or -netdev options are specified. There
4726 * are two cases that we would otherwise complain about:
4727 * (1) board doesn't support a NIC but the implicit "-net nic"
4729 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4730 * sets up a nic that isn't connected to anything.
4733 net_check_clients();
4738 qemu_boot_set(boot_once
, &error_fatal
);
4739 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4742 ds
= init_displaystate();
4744 /* init local displays */
4745 switch (display_type
) {
4747 curses_display_init(ds
, full_screen
);
4750 sdl_display_init(ds
, full_screen
, no_frame
);
4753 cocoa_display_init(ds
, full_screen
);
4756 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4762 /* must be after terminal init, SDL library changes signal handlers */
4763 os_setup_signal_handling();
4765 /* init remote displays */
4767 qemu_opts_foreach(qemu_find_opts("vnc"),
4768 vnc_init_func
, NULL
, NULL
);
4772 qemu_spice_display_init();
4775 #ifdef CONFIG_OPENGL_DMABUF
4776 if (display_type
== DT_EGL
) {
4777 egl_headless_init();
4781 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4785 qdev_machine_creation_done();
4787 /* TODO: once all bus devices are qdevified, this should be done
4788 * when bus is created by qdev.c */
4789 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4790 qemu_run_machine_init_done_notifiers();
4792 if (rom_check_and_register_reset() != 0) {
4793 error_report("rom check and register reset failed");
4799 /* This checkpoint is required by replay to separate prior clock
4800 reading from the other reads, because timer polling functions query
4801 clock values from the log. */
4802 replay_checkpoint(CHECKPOINT_RESET
);
4803 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
4804 register_global_state();
4805 if (replay_mode
!= REPLAY_MODE_NONE
) {
4806 replay_vmstate_init();
4807 } else if (loadvm
) {
4808 Error
*local_err
= NULL
;
4809 if (load_snapshot(loadvm
, &local_err
) < 0) {
4810 error_report_err(local_err
);
4815 qdev_prop_check_globals();
4816 if (vmstate_dump_file
) {
4818 dump_vmstate_json_to_file(vmstate_dump_file
);
4823 Error
*local_err
= NULL
;
4824 qemu_start_incoming_migration(incoming
, &local_err
);
4826 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4829 } else if (autostart
) {
4836 replay_disable_events();
4837 iothread_stop_all();
4843 /* vhost-user must be cleaned up before chardevs. */
4848 /* TODO: unref root container, check all devices are ok */