4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "qemu/osdep.h"
25 #include "qemu-version.h"
26 #include "qemu/cutils.h"
27 #include "qemu/help_option.h"
28 #include "qemu/uuid.h"
31 #include "sysemu/seccomp.h"
34 #if defined(CONFIG_VDE)
35 #include <libvdeplug.h>
39 #if defined(__APPLE__) || defined(main)
41 int qemu_main(int argc
, char **argv
, char **envp
);
42 int main(int argc
, char **argv
)
44 return qemu_main(argc
, argv
, NULL
);
47 #define main qemu_main
49 #endif /* CONFIG_SDL */
53 #define main qemu_main
54 #endif /* CONFIG_COCOA */
57 #include "qemu/error-report.h"
58 #include "qemu/sockets.h"
60 #include "hw/boards.h"
61 #include "sysemu/accel.h"
63 #include "hw/i386/pc.h"
64 #include "hw/isa/isa.h"
65 #include "hw/scsi/scsi.h"
67 #include "sysemu/watchdog.h"
68 #include "hw/smbios/smbios.h"
69 #include "hw/acpi/acpi.h"
70 #include "hw/xen/xen.h"
72 #include "hw/loader.h"
73 #include "monitor/qdev.h"
74 #include "sysemu/bt.h"
76 #include "net/slirp.h"
77 #include "monitor/monitor.h"
78 #include "ui/console.h"
80 #include "sysemu/sysemu.h"
81 #include "sysemu/numa.h"
82 #include "exec/gdbstub.h"
83 #include "qemu/timer.h"
84 #include "sysemu/char.h"
85 #include "qemu/bitmap.h"
87 #include "sysemu/blockdev.h"
88 #include "hw/block/block.h"
89 #include "migration/block.h"
90 #include "sysemu/tpm.h"
91 #include "sysemu/dma.h"
92 #include "audio/audio.h"
93 #include "migration/migration.h"
94 #include "sysemu/cpus.h"
95 #include "migration/colo.h"
96 #include "sysemu/kvm.h"
97 #include "sysemu/hax.h"
98 #include "qapi/qobject-input-visitor.h"
99 #include "qapi/qobject-input-visitor.h"
100 #include "qapi-visit.h"
101 #include "qapi/qmp/qjson.h"
102 #include "qemu/option.h"
103 #include "qemu/config-file.h"
104 #include "qemu-options.h"
105 #include "qmp-commands.h"
106 #include "qemu/main-loop.h"
108 #include "fsdev/qemu-fsdev.h"
110 #include "sysemu/qtest.h"
112 #include "disas/disas.h"
115 #include "slirp/libslirp.h"
117 #include "trace-root.h"
118 #include "trace/control.h"
119 #include "qemu/queue.h"
120 #include "sysemu/arch_init.h"
122 #include "ui/qemu-spice.h"
123 #include "qapi/string-input-visitor.h"
124 #include "qapi/opts-visitor.h"
125 #include "qom/object_interfaces.h"
126 #include "qapi-event.h"
127 #include "exec/semihost.h"
128 #include "crypto/init.h"
129 #include "sysemu/replay.h"
130 #include "qapi/qmp/qerror.h"
131 #include "sysemu/iothread.h"
133 #define MAX_VIRTIO_CONSOLES 1
134 #define MAX_SCLP_CONSOLES 1
136 static const char *data_dir
[16];
137 static int data_dir_idx
;
138 const char *bios_name
= NULL
;
139 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
140 int request_opengl
= -1;
142 const char* keyboard_layout
= NULL
;
144 const char *mem_path
= NULL
;
145 int mem_prealloc
= 0; /* force preallocation of physical target memory */
146 bool enable_mlock
= false;
148 NICInfo nd_table
[MAX_NICS
];
150 static int rtc_utc
= 1;
151 static int rtc_date_offset
= -1; /* -1 means no change */
152 QEMUClockType rtc_clock
;
153 int vga_interface_type
= VGA_NONE
;
154 static int full_screen
= 0;
155 static int no_frame
= 0;
157 static bool grab_on_hover
;
158 Chardev
*serial_hds
[MAX_SERIAL_PORTS
];
159 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
160 Chardev
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
161 Chardev
*sclp_hds
[MAX_SCLP_CONSOLES
];
162 int win2k_install_hack
= 0;
168 int acpi_enabled
= 1;
171 static int no_reboot
;
174 int graphic_rotate
= 0;
175 const char *watchdog
;
176 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
179 const char *qemu_name
;
182 unsigned int nb_prom_envs
= 0;
183 const char *prom_envs
[MAX_PROM_ENVS
];
186 uint8_t *boot_splash_filedata
;
187 size_t boot_splash_filedata_size
;
188 uint8_t qemu_extra_params_fw
[2];
189 int only_migratable
; /* turn it off unless user states otherwise */
191 int icount_align_option
;
193 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
194 * little-endian "wire format" described in the SMBIOS 2.6 specification.
199 static NotifierList exit_notifiers
=
200 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
202 static NotifierList machine_init_done_notifiers
=
203 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
207 enum xen_mode xen_mode
= XEN_EMULATE
;
208 bool xen_domid_restrict
;
210 static int has_defaults
= 1;
211 static int default_serial
= 1;
212 static int default_parallel
= 1;
213 static int default_virtcon
= 1;
214 static int default_sclp
= 1;
215 static int default_monitor
= 1;
216 static int default_floppy
= 1;
217 static int default_cdrom
= 1;
218 static int default_sdcard
= 1;
219 static int default_vga
= 1;
220 static int default_net
= 1;
226 { .driver
= "isa-serial", .flag
= &default_serial
},
227 { .driver
= "isa-parallel", .flag
= &default_parallel
},
228 { .driver
= "isa-fdc", .flag
= &default_floppy
},
229 { .driver
= "floppy", .flag
= &default_floppy
},
230 { .driver
= "ide-cd", .flag
= &default_cdrom
},
231 { .driver
= "ide-hd", .flag
= &default_cdrom
},
232 { .driver
= "ide-drive", .flag
= &default_cdrom
},
233 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
234 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
235 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
236 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
237 { .driver
= "VGA", .flag
= &default_vga
},
238 { .driver
= "isa-vga", .flag
= &default_vga
},
239 { .driver
= "cirrus-vga", .flag
= &default_vga
},
240 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
241 { .driver
= "vmware-svga", .flag
= &default_vga
},
242 { .driver
= "qxl-vga", .flag
= &default_vga
},
243 { .driver
= "virtio-vga", .flag
= &default_vga
},
246 static QemuOptsList qemu_rtc_opts
= {
248 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
252 .type
= QEMU_OPT_STRING
,
255 .type
= QEMU_OPT_STRING
,
258 .type
= QEMU_OPT_STRING
,
260 { /* end of list */ }
264 static QemuOptsList qemu_sandbox_opts
= {
266 .implied_opt_name
= "enable",
267 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
271 .type
= QEMU_OPT_BOOL
,
273 { /* end of list */ }
277 static QemuOptsList qemu_option_rom_opts
= {
278 .name
= "option-rom",
279 .implied_opt_name
= "romfile",
280 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
284 .type
= QEMU_OPT_NUMBER
,
287 .type
= QEMU_OPT_STRING
,
289 { /* end of list */ }
293 static QemuOptsList qemu_machine_opts
= {
295 .implied_opt_name
= "type",
297 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
300 * no elements => accept any
301 * sanity checking will happen later
302 * when setting machine properties
308 static QemuOptsList qemu_accel_opts
= {
310 .implied_opt_name
= "accel",
311 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
316 .type
= QEMU_OPT_STRING
,
317 .help
= "Select the type of accelerator",
321 .type
= QEMU_OPT_STRING
,
322 .help
= "Enable/disable multi-threaded TCG",
324 { /* end of list */ }
328 static QemuOptsList qemu_boot_opts
= {
330 .implied_opt_name
= "order",
332 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
336 .type
= QEMU_OPT_STRING
,
339 .type
= QEMU_OPT_STRING
,
342 .type
= QEMU_OPT_BOOL
,
345 .type
= QEMU_OPT_STRING
,
347 .name
= "splash-time",
348 .type
= QEMU_OPT_STRING
,
350 .name
= "reboot-timeout",
351 .type
= QEMU_OPT_STRING
,
354 .type
= QEMU_OPT_BOOL
,
360 static QemuOptsList qemu_add_fd_opts
= {
362 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
366 .type
= QEMU_OPT_NUMBER
,
367 .help
= "file descriptor of which a duplicate is added to fd set",
370 .type
= QEMU_OPT_NUMBER
,
371 .help
= "ID of the fd set to add fd to",
374 .type
= QEMU_OPT_STRING
,
375 .help
= "free-form string used to describe fd",
377 { /* end of list */ }
381 static QemuOptsList qemu_object_opts
= {
383 .implied_opt_name
= "qom-type",
384 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
390 static QemuOptsList qemu_tpmdev_opts
= {
392 .implied_opt_name
= "type",
393 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
395 /* options are defined in the TPM backends */
396 { /* end of list */ }
400 static QemuOptsList qemu_realtime_opts
= {
402 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
406 .type
= QEMU_OPT_BOOL
,
408 { /* end of list */ }
412 static QemuOptsList qemu_msg_opts
= {
414 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
418 .type
= QEMU_OPT_BOOL
,
420 { /* end of list */ }
424 static QemuOptsList qemu_name_opts
= {
426 .implied_opt_name
= "guest",
428 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
432 .type
= QEMU_OPT_STRING
,
433 .help
= "Sets the name of the guest.\n"
434 "This name will be displayed in the SDL window caption.\n"
435 "The name will also be used for the VNC server",
438 .type
= QEMU_OPT_STRING
,
439 .help
= "Sets the name of the QEMU process, as shown in top etc",
441 .name
= "debug-threads",
442 .type
= QEMU_OPT_BOOL
,
443 .help
= "When enabled, name the individual threads; defaults off.\n"
444 "NOTE: The thread names are for debugging and not a\n"
447 { /* End of list */ }
451 static QemuOptsList qemu_mem_opts
= {
453 .implied_opt_name
= "size",
454 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
459 .type
= QEMU_OPT_SIZE
,
463 .type
= QEMU_OPT_NUMBER
,
467 .type
= QEMU_OPT_SIZE
,
469 { /* end of list */ }
473 static QemuOptsList qemu_icount_opts
= {
475 .implied_opt_name
= "shift",
477 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
481 .type
= QEMU_OPT_STRING
,
484 .type
= QEMU_OPT_BOOL
,
487 .type
= QEMU_OPT_BOOL
,
490 .type
= QEMU_OPT_STRING
,
493 .type
= QEMU_OPT_STRING
,
495 .name
= "rrsnapshot",
496 .type
= QEMU_OPT_STRING
,
498 { /* end of list */ }
502 static QemuOptsList qemu_semihosting_config_opts
= {
503 .name
= "semihosting-config",
504 .implied_opt_name
= "enable",
505 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
509 .type
= QEMU_OPT_BOOL
,
512 .type
= QEMU_OPT_STRING
,
515 .type
= QEMU_OPT_STRING
,
517 { /* end of list */ }
521 static QemuOptsList qemu_fw_cfg_opts
= {
523 .implied_opt_name
= "name",
524 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
528 .type
= QEMU_OPT_STRING
,
529 .help
= "Sets the fw_cfg name of the blob to be inserted",
532 .type
= QEMU_OPT_STRING
,
533 .help
= "Sets the name of the file from which\n"
534 "the fw_cfg blob will be loaded",
537 .type
= QEMU_OPT_STRING
,
538 .help
= "Sets content of the blob to be inserted from a string",
540 { /* end of list */ }
545 * Get machine options
547 * Returns: machine options (never null).
549 QemuOpts
*qemu_get_machine_opts(void)
551 return qemu_find_opts_singleton("machine");
554 const char *qemu_get_vm_name(void)
559 static void res_free(void)
561 g_free(boot_splash_filedata
);
562 boot_splash_filedata
= NULL
;
565 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
567 const char *driver
= qemu_opt_get(opts
, "driver");
572 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
573 if (strcmp(default_list
[i
].driver
, driver
) != 0)
575 *(default_list
[i
].flag
) = 0;
580 /***********************************************************/
583 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
585 /* We use RUN_STATE__MAX but any invalid value will do */
586 static RunState vmstop_requested
= RUN_STATE__MAX
;
587 static QemuMutex vmstop_lock
;
592 } RunStateTransition
;
594 static const RunStateTransition runstate_transitions_def
[] = {
596 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
597 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
598 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
600 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
601 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
602 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
603 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
604 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
605 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
606 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
607 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
608 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
609 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
610 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
611 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
613 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
614 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
615 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
617 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
618 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
619 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
621 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
622 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
623 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
624 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
626 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
627 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
628 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
630 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
631 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
632 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
634 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
635 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
636 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
637 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
639 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
640 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
642 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
644 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
645 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
646 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
647 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
648 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
649 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
650 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
651 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
652 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
653 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
654 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
656 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
658 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
659 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
660 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
662 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
663 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
664 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
665 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
666 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
667 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
669 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
670 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
671 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
672 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
674 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
675 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
676 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
678 { RUN_STATE__MAX
, RUN_STATE__MAX
},
681 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
683 bool runstate_check(RunState state
)
685 return current_run_state
== state
;
688 bool runstate_store(char *str
, size_t size
)
690 const char *state
= RunState_lookup
[current_run_state
];
691 size_t len
= strlen(state
) + 1;
696 memcpy(str
, state
, len
);
700 static void runstate_init(void)
702 const RunStateTransition
*p
;
704 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
705 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
706 runstate_valid_transitions
[p
->from
][p
->to
] = true;
709 qemu_mutex_init(&vmstop_lock
);
712 /* This function will abort() on invalid state transitions */
713 void runstate_set(RunState new_state
)
715 assert(new_state
< RUN_STATE__MAX
);
717 if (current_run_state
== new_state
) {
721 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
722 error_report("invalid runstate transition: '%s' -> '%s'",
723 RunState_lookup
[current_run_state
],
724 RunState_lookup
[new_state
]);
727 trace_runstate_set(new_state
);
728 current_run_state
= new_state
;
731 int runstate_is_running(void)
733 return runstate_check(RUN_STATE_RUNNING
);
736 bool runstate_needs_reset(void)
738 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
739 runstate_check(RUN_STATE_SHUTDOWN
);
742 StatusInfo
*qmp_query_status(Error
**errp
)
744 StatusInfo
*info
= g_malloc0(sizeof(*info
));
746 info
->running
= runstate_is_running();
747 info
->singlestep
= singlestep
;
748 info
->status
= current_run_state
;
753 bool qemu_vmstop_requested(RunState
*r
)
755 qemu_mutex_lock(&vmstop_lock
);
756 *r
= vmstop_requested
;
757 vmstop_requested
= RUN_STATE__MAX
;
758 qemu_mutex_unlock(&vmstop_lock
);
759 return *r
< RUN_STATE__MAX
;
762 void qemu_system_vmstop_request_prepare(void)
764 qemu_mutex_lock(&vmstop_lock
);
767 void qemu_system_vmstop_request(RunState state
)
769 vmstop_requested
= state
;
770 qemu_mutex_unlock(&vmstop_lock
);
774 /***********************************************************/
775 /* real time host monotonic timer */
777 static time_t qemu_time(void)
779 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
782 /***********************************************************/
783 /* host time/date access */
784 void qemu_get_timedate(struct tm
*tm
, int offset
)
786 time_t ti
= qemu_time();
789 if (rtc_date_offset
== -1) {
793 localtime_r(&ti
, tm
);
795 ti
-= rtc_date_offset
;
800 int qemu_timedate_diff(struct tm
*tm
)
804 if (rtc_date_offset
== -1)
806 seconds
= mktimegm(tm
);
809 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
810 seconds
= mktime(&tmp
);
813 seconds
= mktimegm(tm
) + rtc_date_offset
;
815 return seconds
- qemu_time();
818 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
820 time_t rtc_start_date
;
823 if (!strcmp(startdate
, "now") && legacy
) {
824 rtc_date_offset
= -1;
826 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
834 } else if (sscanf(startdate
, "%d-%d-%d",
846 rtc_start_date
= mktimegm(&tm
);
847 if (rtc_start_date
== -1) {
849 error_report("invalid date format");
850 error_printf("valid formats: "
851 "'2006-06-17T16:01:21' or '2006-06-17'\n");
854 rtc_date_offset
= qemu_time() - rtc_start_date
;
858 static void configure_rtc(QemuOpts
*opts
)
862 value
= qemu_opt_get(opts
, "base");
864 if (!strcmp(value
, "utc")) {
866 } else if (!strcmp(value
, "localtime")) {
867 Error
*blocker
= NULL
;
869 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
870 "-rtc base=localtime");
871 replay_add_blocker(blocker
);
873 configure_rtc_date_offset(value
, 0);
876 value
= qemu_opt_get(opts
, "clock");
878 if (!strcmp(value
, "host")) {
879 rtc_clock
= QEMU_CLOCK_HOST
;
880 } else if (!strcmp(value
, "rt")) {
881 rtc_clock
= QEMU_CLOCK_REALTIME
;
882 } else if (!strcmp(value
, "vm")) {
883 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
885 error_report("invalid option value '%s'", value
);
889 value
= qemu_opt_get(opts
, "driftfix");
891 if (!strcmp(value
, "slew")) {
892 static GlobalProperty slew_lost_ticks
= {
893 .driver
= "mc146818rtc",
894 .property
= "lost_tick_policy",
898 qdev_prop_register_global(&slew_lost_ticks
);
899 } else if (!strcmp(value
, "none")) {
900 /* discard is default */
902 error_report("invalid option value '%s'", value
);
908 /***********************************************************/
909 /* Bluetooth support */
912 static struct HCIInfo
*hci_table
[MAX_NICS
];
914 struct HCIInfo
*qemu_next_hci(void)
916 if (cur_hci
== nb_hcis
)
919 return hci_table
[cur_hci
++];
922 static int bt_hci_parse(const char *str
)
927 if (nb_hcis
>= MAX_NICS
) {
928 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
941 bdaddr
.b
[5] = 0x56 + nb_hcis
;
942 hci
->bdaddr_set(hci
, bdaddr
.b
);
944 hci_table
[nb_hcis
++] = hci
;
949 static void bt_vhci_add(int vlan_id
)
951 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
954 error_report("warning: adding a VHCI to an empty scatternet %i",
957 bt_vhci_init(bt_new_hci(vlan
));
960 static struct bt_device_s
*bt_device_add(const char *opt
)
962 struct bt_scatternet_s
*vlan
;
964 char *endp
= strstr(opt
, ",vlan=");
965 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
968 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
971 vlan_id
= strtol(endp
+ 6, &endp
, 0);
973 error_report("unrecognised bluetooth vlan Id");
978 vlan
= qemu_find_bt_vlan(vlan_id
);
981 error_report("warning: adding a slave device to an empty scatternet %i",
984 if (!strcmp(devname
, "keyboard"))
985 return bt_keyboard_init(vlan
);
987 error_report("unsupported bluetooth device '%s'", devname
);
991 static int bt_parse(const char *opt
)
993 const char *endp
, *p
;
996 if (strstart(opt
, "hci", &endp
)) {
997 if (!*endp
|| *endp
== ',') {
999 if (!strstart(endp
, ",vlan=", 0))
1002 return bt_hci_parse(opt
);
1004 } else if (strstart(opt
, "vhci", &endp
)) {
1005 if (!*endp
|| *endp
== ',') {
1007 if (strstart(endp
, ",vlan=", &p
)) {
1008 vlan
= strtol(p
, (char **) &endp
, 0);
1010 error_report("bad scatternet '%s'", p
);
1014 error_report("bad parameter '%s'", endp
+ 1);
1023 } else if (strstart(opt
, "device:", &endp
))
1024 return !bt_device_add(endp
);
1026 error_report("bad bluetooth parameter '%s'", opt
);
1030 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1032 /* FIXME: change this to true for 1.3 */
1033 if (qemu_opt_get_bool(opts
, "enable", false)) {
1034 #ifdef CONFIG_SECCOMP
1035 if (seccomp_start() < 0) {
1036 error_report("failed to install seccomp syscall filter "
1041 error_report("seccomp support is disabled");
1049 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1051 const char *proc_name
;
1053 if (qemu_opt_get(opts
, "debug-threads")) {
1054 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1056 qemu_name
= qemu_opt_get(opts
, "guest");
1058 proc_name
= qemu_opt_get(opts
, "process");
1060 os_set_proc_name(proc_name
);
1066 bool defaults_enabled(void)
1068 return has_defaults
;
1072 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1074 int fd
, dupfd
, flags
;
1076 const char *fd_opaque
= NULL
;
1079 fd
= qemu_opt_get_number(opts
, "fd", -1);
1080 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1081 fd_opaque
= qemu_opt_get(opts
, "opaque");
1084 error_report("fd option is required and must be non-negative");
1088 if (fd
<= STDERR_FILENO
) {
1089 error_report("fd cannot be a standard I/O stream");
1094 * All fds inherited across exec() necessarily have FD_CLOEXEC
1095 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1097 flags
= fcntl(fd
, F_GETFD
);
1098 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1099 error_report("fd is not valid or already in use");
1104 error_report("set option is required and must be non-negative");
1108 #ifdef F_DUPFD_CLOEXEC
1109 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1113 qemu_set_cloexec(dupfd
);
1117 error_report("error duplicating fd: %s", strerror(errno
));
1121 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1122 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1129 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1133 fd
= qemu_opt_get_number(opts
, "fd", -1);
1140 /***********************************************************/
1141 /* QEMU Block devices */
1143 #define HD_OPTS "media=disk"
1144 #define CDROM_OPTS "media=cdrom"
1146 #define PFLASH_OPTS ""
1150 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1152 BlockInterfaceType
*block_default_type
= opaque
;
1154 return drive_new(opts
, *block_default_type
) == NULL
;
1157 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1159 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1160 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1165 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1166 int index
, const char *optstr
)
1171 if (!enable
|| drive_get_by_index(type
, index
)) {
1175 opts
= drive_add(type
, index
, NULL
, optstr
);
1177 drive_enable_snapshot(NULL
, opts
, NULL
);
1180 dinfo
= drive_new(opts
, type
);
1184 dinfo
->is_default
= true;
1188 static QemuOptsList qemu_smp_opts
= {
1190 .implied_opt_name
= "cpus",
1191 .merge_lists
= true,
1192 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1196 .type
= QEMU_OPT_NUMBER
,
1199 .type
= QEMU_OPT_NUMBER
,
1202 .type
= QEMU_OPT_NUMBER
,
1205 .type
= QEMU_OPT_NUMBER
,
1208 .type
= QEMU_OPT_NUMBER
,
1210 { /*End of list */ }
1214 static void smp_parse(QemuOpts
*opts
)
1217 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1218 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1219 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1220 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1222 /* compute missing values, prefer sockets over cores over threads */
1223 if (cpus
== 0 || sockets
== 0) {
1224 sockets
= sockets
> 0 ? sockets
: 1;
1225 cores
= cores
> 0 ? cores
: 1;
1226 threads
= threads
> 0 ? threads
: 1;
1228 cpus
= cores
* threads
* sockets
;
1230 } else if (cores
== 0) {
1231 threads
= threads
> 0 ? threads
: 1;
1232 cores
= cpus
/ (sockets
* threads
);
1233 cores
= cores
> 0 ? cores
: 1;
1234 } else if (threads
== 0) {
1235 threads
= cpus
/ (cores
* sockets
);
1236 threads
= threads
> 0 ? threads
: 1;
1237 } else if (sockets
* cores
* threads
< cpus
) {
1238 error_report("cpu topology: "
1239 "sockets (%u) * cores (%u) * threads (%u) < "
1241 sockets
, cores
, threads
, cpus
);
1245 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1247 if (max_cpus
< cpus
) {
1248 error_report("maxcpus must be equal to or greater than smp");
1252 if (sockets
* cores
* threads
> max_cpus
) {
1253 error_report("cpu topology: "
1254 "sockets (%u) * cores (%u) * threads (%u) > "
1256 sockets
, cores
, threads
, max_cpus
);
1262 smp_threads
= threads
;
1266 Error
*blocker
= NULL
;
1267 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1268 replay_add_blocker(blocker
);
1272 static void realtime_init(void)
1275 if (os_mlock() < 0) {
1276 error_report("locking memory failed");
1283 static void configure_msg(QemuOpts
*opts
)
1285 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1288 /***********************************************************/
1291 typedef struct SemihostingConfig
{
1293 SemihostingTarget target
;
1296 const char *cmdline
; /* concatenated argv */
1297 } SemihostingConfig
;
1299 static SemihostingConfig semihosting
;
1301 bool semihosting_enabled(void)
1303 return semihosting
.enabled
;
1306 SemihostingTarget
semihosting_get_target(void)
1308 return semihosting
.target
;
1311 const char *semihosting_get_arg(int i
)
1313 if (i
>= semihosting
.argc
) {
1316 return semihosting
.argv
[i
];
1319 int semihosting_get_argc(void)
1321 return semihosting
.argc
;
1324 const char *semihosting_get_cmdline(void)
1326 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1327 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1329 return semihosting
.cmdline
;
1332 static int add_semihosting_arg(void *opaque
,
1333 const char *name
, const char *val
,
1336 SemihostingConfig
*s
= opaque
;
1337 if (strcmp(name
, "arg") == 0) {
1339 /* one extra element as g_strjoinv() expects NULL-terminated array */
1340 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1341 s
->argv
[s
->argc
- 1] = val
;
1342 s
->argv
[s
->argc
] = NULL
;
1347 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1348 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1353 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1355 /* split -append and initialize argv[1..n] */
1356 cmd_token
= strtok(g_strdup(cmd
), " ");
1358 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1359 cmd_token
= strtok(NULL
, " ");
1363 /* Now we still need this for compatibility with XEN. */
1364 bool has_igd_gfx_passthru
;
1365 static void igd_gfx_passthru(void)
1367 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1370 /***********************************************************/
1373 static int usb_device_add(const char *devname
)
1375 USBDevice
*dev
= NULL
;
1376 #ifndef CONFIG_LINUX
1380 if (!machine_usb(current_machine
)) {
1384 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1385 dev
= usbdevice_create(devname
);
1389 /* the other ones */
1390 #ifndef CONFIG_LINUX
1391 /* only the linux version is qdev-ified, usb-bsd still needs this */
1392 if (strstart(devname
, "host:", &p
)) {
1393 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1403 static int usb_device_del(const char *devname
)
1408 if (strstart(devname
, "host:", &p
)) {
1412 if (!machine_usb(current_machine
)) {
1416 p
= strchr(devname
, '.');
1419 bus_num
= strtoul(devname
, NULL
, 0);
1420 addr
= strtoul(p
+ 1, NULL
, 0);
1422 return usb_device_delete_addr(bus_num
, addr
);
1425 static int usb_parse(const char *cmdline
)
1428 r
= usb_device_add(cmdline
);
1430 error_report("could not add USB device '%s'", cmdline
);
1435 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1437 const char *devname
= qdict_get_str(qdict
, "devname");
1438 if (usb_device_add(devname
) < 0) {
1439 error_report("could not add USB device '%s'", devname
);
1443 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1445 const char *devname
= qdict_get_str(qdict
, "devname");
1446 if (usb_device_del(devname
) < 0) {
1447 error_report("could not delete USB device '%s'", devname
);
1451 /***********************************************************/
1452 /* machine registration */
1454 MachineState
*current_machine
;
1456 static MachineClass
*find_machine(const char *name
)
1458 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1459 MachineClass
*mc
= NULL
;
1461 for (el
= machines
; el
; el
= el
->next
) {
1462 MachineClass
*temp
= el
->data
;
1464 if (!strcmp(temp
->name
, name
)) {
1469 !strcmp(temp
->alias
, name
)) {
1475 g_slist_free(machines
);
1479 MachineClass
*find_default_machine(void)
1481 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1482 MachineClass
*mc
= NULL
;
1484 for (el
= machines
; el
; el
= el
->next
) {
1485 MachineClass
*temp
= el
->data
;
1487 if (temp
->is_default
) {
1493 g_slist_free(machines
);
1497 MachineInfoList
*qmp_query_machines(Error
**errp
)
1499 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1500 MachineInfoList
*mach_list
= NULL
;
1502 for (el
= machines
; el
; el
= el
->next
) {
1503 MachineClass
*mc
= el
->data
;
1504 MachineInfoList
*entry
;
1507 info
= g_malloc0(sizeof(*info
));
1508 if (mc
->is_default
) {
1509 info
->has_is_default
= true;
1510 info
->is_default
= true;
1514 info
->has_alias
= true;
1515 info
->alias
= g_strdup(mc
->alias
);
1518 info
->name
= g_strdup(mc
->name
);
1519 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1520 info
->hotpluggable_cpus
= mc
->has_hotpluggable_cpus
;
1522 entry
= g_malloc0(sizeof(*entry
));
1523 entry
->value
= info
;
1524 entry
->next
= mach_list
;
1528 g_slist_free(machines
);
1532 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1534 ObjectProperty
*prop
;
1535 ObjectPropertyIterator iter
;
1537 if (!qemu_opt_has_help_opt(opts
)) {
1541 object_property_iter_init(&iter
, OBJECT(machine
));
1542 while ((prop
= object_property_iter_next(&iter
))) {
1547 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1548 prop
->name
, prop
->type
);
1549 if (prop
->description
) {
1550 error_printf(" (%s)\n", prop
->description
);
1559 /***********************************************************/
1560 /* main execution loop */
1562 struct vm_change_state_entry
{
1563 VMChangeStateHandler
*cb
;
1565 QLIST_ENTRY (vm_change_state_entry
) entries
;
1568 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1570 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1573 VMChangeStateEntry
*e
;
1575 e
= g_malloc0(sizeof (*e
));
1579 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1583 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1585 QLIST_REMOVE (e
, entries
);
1589 void vm_state_notify(int running
, RunState state
)
1591 VMChangeStateEntry
*e
, *next
;
1593 trace_vm_state_notify(running
, state
);
1595 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1596 e
->cb(e
->opaque
, running
, state
);
1600 static ShutdownCause reset_requested
;
1601 static ShutdownCause shutdown_requested
;
1602 static int shutdown_signal
;
1603 static pid_t shutdown_pid
;
1604 static int powerdown_requested
;
1605 static int debug_requested
;
1606 static int suspend_requested
;
1607 static WakeupReason wakeup_reason
;
1608 static NotifierList powerdown_notifiers
=
1609 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1610 static NotifierList suspend_notifiers
=
1611 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1612 static NotifierList wakeup_notifiers
=
1613 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1614 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1616 ShutdownCause
qemu_shutdown_requested_get(void)
1618 return shutdown_requested
;
1621 ShutdownCause
qemu_reset_requested_get(void)
1623 return reset_requested
;
1626 static int qemu_shutdown_requested(void)
1628 return atomic_xchg(&shutdown_requested
, SHUTDOWN_CAUSE_NONE
);
1631 static void qemu_kill_report(void)
1633 if (!qtest_driver() && shutdown_signal
) {
1634 if (shutdown_pid
== 0) {
1635 /* This happens for eg ^C at the terminal, so it's worth
1636 * avoiding printing an odd message in that case.
1638 error_report("terminating on signal %d", shutdown_signal
);
1640 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1642 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1643 shutdown_signal
, shutdown_pid
,
1644 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1645 g_free(shutdown_cmd
);
1647 shutdown_signal
= 0;
1651 static ShutdownCause
qemu_reset_requested(void)
1653 ShutdownCause r
= reset_requested
;
1655 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1656 reset_requested
= SHUTDOWN_CAUSE_NONE
;
1659 return SHUTDOWN_CAUSE_NONE
;
1662 static int qemu_suspend_requested(void)
1664 int r
= suspend_requested
;
1665 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1666 suspend_requested
= 0;
1672 static WakeupReason
qemu_wakeup_requested(void)
1674 return wakeup_reason
;
1677 static int qemu_powerdown_requested(void)
1679 int r
= powerdown_requested
;
1680 powerdown_requested
= 0;
1684 static int qemu_debug_requested(void)
1686 int r
= debug_requested
;
1687 debug_requested
= 0;
1692 * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE.
1694 void qemu_system_reset(ShutdownCause reason
)
1698 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1700 cpu_synchronize_all_states();
1702 if (mc
&& mc
->reset
) {
1705 qemu_devices_reset();
1708 /* TODO update event based on reason */
1709 qapi_event_send_reset(&error_abort
);
1711 cpu_synchronize_all_post_reset();
1714 void qemu_system_guest_panicked(GuestPanicInformation
*info
)
1716 qemu_log_mask(LOG_GUEST_ERROR
, "Guest crashed\n");
1719 current_cpu
->crash_occurred
= true;
1721 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
,
1722 !!info
, info
, &error_abort
);
1723 vm_stop(RUN_STATE_GUEST_PANICKED
);
1725 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1726 !!info
, info
, &error_abort
);
1727 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC
);
1731 if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_HYPER_V
) {
1732 qemu_log_mask(LOG_GUEST_ERROR
, "HV crash parameters: (%#"PRIx64
1733 " %#"PRIx64
" %#"PRIx64
" %#"PRIx64
" %#"PRIx64
")\n",
1734 info
->u
.hyper_v
.arg1
,
1735 info
->u
.hyper_v
.arg2
,
1736 info
->u
.hyper_v
.arg3
,
1737 info
->u
.hyper_v
.arg4
,
1738 info
->u
.hyper_v
.arg5
);
1740 qapi_free_GuestPanicInformation(info
);
1744 void qemu_system_reset_request(ShutdownCause reason
)
1747 shutdown_requested
= reason
;
1749 reset_requested
= reason
;
1752 qemu_notify_event();
1755 static void qemu_system_suspend(void)
1758 notifier_list_notify(&suspend_notifiers
, NULL
);
1759 runstate_set(RUN_STATE_SUSPENDED
);
1760 qapi_event_send_suspend(&error_abort
);
1763 void qemu_system_suspend_request(void)
1765 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1768 suspend_requested
= 1;
1770 qemu_notify_event();
1773 void qemu_register_suspend_notifier(Notifier
*notifier
)
1775 notifier_list_add(&suspend_notifiers
, notifier
);
1778 void qemu_system_wakeup_request(WakeupReason reason
)
1780 trace_system_wakeup_request(reason
);
1782 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1785 if (!(wakeup_reason_mask
& (1 << reason
))) {
1788 runstate_set(RUN_STATE_RUNNING
);
1789 wakeup_reason
= reason
;
1790 qemu_notify_event();
1793 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1796 wakeup_reason_mask
|= (1 << reason
);
1798 wakeup_reason_mask
&= ~(1 << reason
);
1802 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1804 notifier_list_add(&wakeup_notifiers
, notifier
);
1807 void qemu_system_killed(int signal
, pid_t pid
)
1809 shutdown_signal
= signal
;
1813 /* Cannot call qemu_system_shutdown_request directly because
1814 * we are in a signal handler.
1816 shutdown_requested
= SHUTDOWN_CAUSE_HOST_SIGNAL
;
1817 qemu_notify_event();
1820 void qemu_system_shutdown_request(ShutdownCause reason
)
1822 trace_qemu_system_shutdown_request(reason
);
1823 replay_shutdown_request(reason
);
1824 shutdown_requested
= reason
;
1825 qemu_notify_event();
1828 static void qemu_system_powerdown(void)
1830 qapi_event_send_powerdown(&error_abort
);
1831 notifier_list_notify(&powerdown_notifiers
, NULL
);
1834 void qemu_system_powerdown_request(void)
1836 trace_qemu_system_powerdown_request();
1837 powerdown_requested
= 1;
1838 qemu_notify_event();
1841 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1843 notifier_list_add(&powerdown_notifiers
, notifier
);
1846 void qemu_system_debug_request(void)
1848 debug_requested
= 1;
1849 qemu_notify_event();
1852 static bool main_loop_should_exit(void)
1855 ShutdownCause request
;
1857 if (qemu_debug_requested()) {
1858 vm_stop(RUN_STATE_DEBUG
);
1860 if (qemu_suspend_requested()) {
1861 qemu_system_suspend();
1863 request
= qemu_shutdown_requested();
1866 /* TODO update event based on request */
1867 qapi_event_send_shutdown(&error_abort
);
1869 vm_stop(RUN_STATE_SHUTDOWN
);
1874 request
= qemu_reset_requested();
1877 qemu_system_reset(request
);
1879 if (!runstate_check(RUN_STATE_RUNNING
) &&
1880 !runstate_check(RUN_STATE_INMIGRATE
)) {
1881 runstate_set(RUN_STATE_PRELAUNCH
);
1884 if (qemu_wakeup_requested()) {
1886 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
1887 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1888 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1890 qapi_event_send_wakeup(&error_abort
);
1892 if (qemu_powerdown_requested()) {
1893 qemu_system_powerdown();
1895 if (qemu_vmstop_requested(&r
)) {
1901 static void main_loop(void)
1903 #ifdef CONFIG_PROFILER
1907 #ifdef CONFIG_PROFILER
1908 ti
= profile_getclock();
1910 main_loop_wait(false);
1911 #ifdef CONFIG_PROFILER
1912 dev_time
+= profile_getclock() - ti
;
1914 } while (!main_loop_should_exit());
1917 static void version(void)
1919 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1920 QEMU_COPYRIGHT
"\n");
1923 static void help(int exitcode
)
1926 printf("usage: %s [options] [disk_image]\n\n"
1927 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1928 error_get_progname());
1930 #define QEMU_OPTIONS_GENERATE_HELP
1931 #include "qemu-options-wrapper.h"
1933 printf("\nDuring emulation, the following keys are useful:\n"
1934 "ctrl-alt-f toggle full screen\n"
1935 "ctrl-alt-n switch to virtual console 'n'\n"
1936 "ctrl-alt toggle mouse and keyboard grab\n"
1938 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1943 #define HAS_ARG 0x0001
1945 typedef struct QEMUOption
{
1952 static const QEMUOption qemu_options
[] = {
1953 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1954 #define QEMU_OPTIONS_GENERATE_OPTIONS
1955 #include "qemu-options-wrapper.h"
1959 typedef struct VGAInterfaceInfo
{
1960 const char *opt_name
; /* option name */
1961 const char *name
; /* human-readable name */
1962 /* Class names indicating that support is available.
1963 * If no class is specified, the interface is always available */
1964 const char *class_names
[2];
1967 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1973 .name
= "standard VGA",
1974 .class_names
= { "VGA", "isa-vga" },
1977 .opt_name
= "cirrus",
1978 .name
= "Cirrus VGA",
1979 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1982 .opt_name
= "vmware",
1983 .name
= "VMWare SVGA",
1984 .class_names
= { "vmware-svga" },
1987 .opt_name
= "virtio",
1988 .name
= "Virtio VGA",
1989 .class_names
= { "virtio-vga" },
1994 .class_names
= { "qxl-vga" },
1998 .name
= "TCX framebuffer",
1999 .class_names
= { "SUNW,tcx" },
2003 .name
= "CG3 framebuffer",
2004 .class_names
= { "cgthree" },
2007 .opt_name
= "xenfb",
2011 static bool vga_interface_available(VGAInterfaceType t
)
2013 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2015 assert(t
< VGA_TYPE_MAX
);
2016 return !ti
->class_names
[0] ||
2017 object_class_by_name(ti
->class_names
[0]) ||
2018 object_class_by_name(ti
->class_names
[1]);
2021 static void select_vgahw(const char *p
)
2026 assert(vga_interface_type
== VGA_NONE
);
2027 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2028 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2029 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2030 if (!vga_interface_available(t
)) {
2031 error_report("%s not available", ti
->name
);
2034 vga_interface_type
= t
;
2038 if (t
== VGA_TYPE_MAX
) {
2040 error_report("unknown vga type: %s", p
);
2044 const char *nextopt
;
2046 if (strstart(opts
, ",retrace=", &nextopt
)) {
2048 if (strstart(opts
, "dumb", &nextopt
))
2049 vga_retrace_method
= VGA_RETRACE_DUMB
;
2050 else if (strstart(opts
, "precise", &nextopt
))
2051 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2052 else goto invalid_vga
;
2053 } else goto invalid_vga
;
2058 typedef enum DisplayType
{
2068 static DisplayType
select_display(const char *p
)
2071 DisplayType display
= DT_DEFAULT
;
2073 if (strstart(p
, "sdl", &opts
)) {
2077 const char *nextopt
;
2079 if (strstart(opts
, ",frame=", &nextopt
)) {
2081 if (strstart(opts
, "on", &nextopt
)) {
2083 } else if (strstart(opts
, "off", &nextopt
)) {
2086 goto invalid_sdl_args
;
2088 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2090 if (strstart(opts
, "on", &nextopt
)) {
2092 } else if (strstart(opts
, "off", &nextopt
)) {
2095 goto invalid_sdl_args
;
2097 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2099 if (strstart(opts
, "on", &nextopt
)) {
2101 } else if (strstart(opts
, "off", &nextopt
)) {
2104 goto invalid_sdl_args
;
2106 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2108 if (strstart(opts
, "on", &nextopt
)) {
2110 } else if (strstart(opts
, "off", &nextopt
)) {
2113 goto invalid_sdl_args
;
2115 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2117 if (strstart(opts
, "on", &nextopt
)) {
2119 } else if (strstart(opts
, "off", &nextopt
)) {
2122 goto invalid_sdl_args
;
2126 error_report("invalid SDL option string");
2132 error_report("SDL support is disabled");
2135 } else if (strstart(p
, "vnc", &opts
)) {
2137 vnc_parse(opts
+ 1, &error_fatal
);
2139 error_report("VNC requires a display argument vnc=<display>");
2142 } else if (strstart(p
, "egl-headless", &opts
)) {
2143 #ifdef CONFIG_OPENGL
2148 fprintf(stderr
, "egl support is disabled\n");
2151 } else if (strstart(p
, "curses", &opts
)) {
2152 #ifdef CONFIG_CURSES
2153 display
= DT_CURSES
;
2155 error_report("curses support is disabled");
2158 } else if (strstart(p
, "gtk", &opts
)) {
2162 const char *nextopt
;
2164 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2166 if (strstart(opts
, "on", &nextopt
)) {
2167 grab_on_hover
= true;
2168 } else if (strstart(opts
, "off", &nextopt
)) {
2169 grab_on_hover
= false;
2171 goto invalid_gtk_args
;
2173 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2175 if (strstart(opts
, "on", &nextopt
)) {
2177 } else if (strstart(opts
, "off", &nextopt
)) {
2180 goto invalid_gtk_args
;
2184 error_report("invalid GTK option string");
2190 error_report("GTK support is disabled");
2193 } else if (strstart(p
, "none", &opts
)) {
2196 error_report("unknown display type");
2203 static int balloon_parse(const char *arg
)
2207 if (strcmp(arg
, "none") == 0) {
2211 if (!strncmp(arg
, "virtio", 6)) {
2212 if (arg
[6] == ',') {
2213 /* have params -> parse them */
2214 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2219 /* create empty opts */
2220 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2223 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2230 char *qemu_find_file(int type
, const char *name
)
2236 /* Try the name as a straight path first */
2237 if (access(name
, R_OK
) == 0) {
2238 trace_load_file(name
, name
);
2239 return g_strdup(name
);
2243 case QEMU_FILE_TYPE_BIOS
:
2246 case QEMU_FILE_TYPE_KEYMAP
:
2247 subdir
= "keymaps/";
2253 for (i
= 0; i
< data_dir_idx
; i
++) {
2254 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2255 if (access(buf
, R_OK
) == 0) {
2256 trace_load_file(name
, buf
);
2264 static inline bool nonempty_str(const char *str
)
2269 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2273 const char *name
, *file
, *str
;
2274 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2276 if (fw_cfg
== NULL
) {
2277 error_report("fw_cfg device not available");
2280 name
= qemu_opt_get(opts
, "name");
2281 file
= qemu_opt_get(opts
, "file");
2282 str
= qemu_opt_get(opts
, "string");
2284 /* we need name and either a file or the content string */
2285 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2286 error_report("invalid argument(s)");
2289 if (nonempty_str(file
) && nonempty_str(str
)) {
2290 error_report("file and string are mutually exclusive");
2293 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2294 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2297 if (strncmp(name
, "opt/", 4) != 0) {
2298 error_report("warning: externally provided fw_cfg item names "
2299 "should be prefixed with \"opt/\"");
2301 if (nonempty_str(str
)) {
2302 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2303 buf
= g_memdup(str
, size
);
2305 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2306 error_report("can't load %s", file
);
2310 /* For legacy, keep user files in a specific global order. */
2311 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2312 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2313 fw_cfg_reset_order_override(fw_cfg
);
2317 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2319 return qdev_device_help(opts
);
2322 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2327 dev
= qdev_device_add(opts
, &err
);
2329 error_report_err(err
);
2332 object_unref(OBJECT(dev
));
2336 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2338 Error
*local_err
= NULL
;
2340 qemu_chr_new_from_opts(opts
, &local_err
);
2342 error_report_err(local_err
);
2348 #ifdef CONFIG_VIRTFS
2349 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2351 return qemu_fsdev_add(opts
);
2355 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2358 const char *chardev
;
2362 mode
= qemu_opt_get(opts
, "mode");
2366 if (strcmp(mode
, "readline") == 0) {
2367 flags
= MONITOR_USE_READLINE
;
2368 } else if (strcmp(mode
, "control") == 0) {
2369 flags
= MONITOR_USE_CONTROL
;
2371 error_report("unknown monitor mode \"%s\"", mode
);
2375 if (qemu_opt_get_bool(opts
, "pretty", 0))
2376 flags
|= MONITOR_USE_PRETTY
;
2378 if (qemu_opt_get_bool(opts
, "default", 0)) {
2379 error_report("option 'default' does nothing and is deprecated");
2382 chardev
= qemu_opt_get(opts
, "chardev");
2383 chr
= qemu_chr_find(chardev
);
2385 error_report("chardev \"%s\" not found", chardev
);
2389 monitor_init(chr
, flags
);
2393 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2395 static int monitor_device_index
= 0;
2400 if (strstart(optarg
, "chardev:", &p
)) {
2401 snprintf(label
, sizeof(label
), "%s", p
);
2403 snprintf(label
, sizeof(label
), "compat_monitor%d",
2404 monitor_device_index
);
2405 opts
= qemu_chr_parse_compat(label
, optarg
);
2407 error_report("parse error: %s", optarg
);
2412 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2413 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2414 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2415 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2416 monitor_device_index
++;
2419 struct device_config
{
2421 DEV_USB
, /* -usbdevice */
2423 DEV_SERIAL
, /* -serial */
2424 DEV_PARALLEL
, /* -parallel */
2425 DEV_VIRTCON
, /* -virtioconsole */
2426 DEV_DEBUGCON
, /* -debugcon */
2427 DEV_GDB
, /* -gdb, -s */
2428 DEV_SCLP
, /* s390 sclp */
2430 const char *cmdline
;
2432 QTAILQ_ENTRY(device_config
) next
;
2435 static QTAILQ_HEAD(, device_config
) device_configs
=
2436 QTAILQ_HEAD_INITIALIZER(device_configs
);
2438 static void add_device_config(int type
, const char *cmdline
)
2440 struct device_config
*conf
;
2442 conf
= g_malloc0(sizeof(*conf
));
2444 conf
->cmdline
= cmdline
;
2445 loc_save(&conf
->loc
);
2446 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2449 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2451 struct device_config
*conf
;
2454 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2455 if (conf
->type
!= type
)
2457 loc_push_restore(&conf
->loc
);
2458 rc
= func(conf
->cmdline
);
2459 loc_pop(&conf
->loc
);
2467 static int serial_parse(const char *devname
)
2469 static int index
= 0;
2472 if (strcmp(devname
, "none") == 0)
2474 if (index
== MAX_SERIAL_PORTS
) {
2475 error_report("too many serial ports");
2478 snprintf(label
, sizeof(label
), "serial%d", index
);
2479 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2480 if (!serial_hds
[index
]) {
2481 error_report("could not connect serial device"
2482 " to character backend '%s'", devname
);
2489 static int parallel_parse(const char *devname
)
2491 static int index
= 0;
2494 if (strcmp(devname
, "none") == 0)
2496 if (index
== MAX_PARALLEL_PORTS
) {
2497 error_report("too many parallel ports");
2500 snprintf(label
, sizeof(label
), "parallel%d", index
);
2501 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2502 if (!parallel_hds
[index
]) {
2503 error_report("could not connect parallel device"
2504 " to character backend '%s'", devname
);
2511 static int virtcon_parse(const char *devname
)
2513 QemuOptsList
*device
= qemu_find_opts("device");
2514 static int index
= 0;
2516 QemuOpts
*bus_opts
, *dev_opts
;
2518 if (strcmp(devname
, "none") == 0)
2520 if (index
== MAX_VIRTIO_CONSOLES
) {
2521 error_report("too many virtio consoles");
2525 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2526 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2528 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2529 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2531 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2532 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2533 if (!virtcon_hds
[index
]) {
2534 error_report("could not connect virtio console"
2535 " to character backend '%s'", devname
);
2538 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2544 static int sclp_parse(const char *devname
)
2546 QemuOptsList
*device
= qemu_find_opts("device");
2547 static int index
= 0;
2551 if (strcmp(devname
, "none") == 0) {
2554 if (index
== MAX_SCLP_CONSOLES
) {
2555 error_report("too many sclp consoles");
2559 assert(arch_type
== QEMU_ARCH_S390X
);
2561 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2562 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2564 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2565 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2566 if (!sclp_hds
[index
]) {
2567 error_report("could not connect sclp console"
2568 " to character backend '%s'", devname
);
2571 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2577 static int debugcon_parse(const char *devname
)
2581 if (!qemu_chr_new("debugcon", devname
)) {
2584 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2586 error_report("already have a debugcon device");
2589 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2590 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2594 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2596 const MachineClass
*mc1
= a
, *mc2
= b
;
2599 if (mc1
->family
== NULL
) {
2600 if (mc2
->family
== NULL
) {
2601 /* Compare standalone machine types against each other; they sort
2602 * in increasing order.
2604 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2605 object_class_get_name(OBJECT_CLASS(mc2
)));
2608 /* Standalone machine types sort after families. */
2612 if (mc2
->family
== NULL
) {
2613 /* Families sort before standalone machine types. */
2617 /* Families sort between each other alphabetically increasingly. */
2618 res
= strcmp(mc1
->family
, mc2
->family
);
2623 /* Within the same family, machine types sort in decreasing order. */
2624 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2625 object_class_get_name(OBJECT_CLASS(mc1
)));
2628 static MachineClass
*machine_parse(const char *name
)
2630 MachineClass
*mc
= NULL
;
2631 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2634 mc
= find_machine(name
);
2637 g_slist_free(machines
);
2640 if (name
&& !is_help_option(name
)) {
2641 error_report("unsupported machine type");
2642 error_printf("Use -machine help to list supported machines\n");
2644 printf("Supported machines are:\n");
2645 machines
= g_slist_sort(machines
, machine_class_cmp
);
2646 for (el
= machines
; el
; el
= el
->next
) {
2647 MachineClass
*mc
= el
->data
;
2649 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2651 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2652 mc
->is_default
? " (default)" : "");
2656 g_slist_free(machines
);
2657 exit(!name
|| !is_help_option(name
));
2660 void qemu_add_exit_notifier(Notifier
*notify
)
2662 notifier_list_add(&exit_notifiers
, notify
);
2665 void qemu_remove_exit_notifier(Notifier
*notify
)
2667 notifier_remove(notify
);
2670 static void qemu_run_exit_notifiers(void)
2672 notifier_list_notify(&exit_notifiers
, NULL
);
2675 static bool machine_init_done
;
2677 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2679 notifier_list_add(&machine_init_done_notifiers
, notify
);
2680 if (machine_init_done
) {
2681 notify
->notify(notify
, NULL
);
2685 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2687 notifier_remove(notify
);
2690 static void qemu_run_machine_init_done_notifiers(void)
2692 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2693 machine_init_done
= true;
2696 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2697 const char **poptarg
, int *poptind
)
2699 const QEMUOption
*popt
;
2700 int optind
= *poptind
;
2701 char *r
= argv
[optind
];
2704 loc_set_cmdline(argv
, optind
, 1);
2706 /* Treat --foo the same as -foo. */
2709 popt
= qemu_options
;
2712 error_report("invalid option");
2715 if (!strcmp(popt
->name
, r
+ 1))
2719 if (popt
->flags
& HAS_ARG
) {
2720 if (optind
>= argc
) {
2721 error_report("requires an argument");
2724 optarg
= argv
[optind
++];
2725 loc_set_cmdline(argv
, optind
- 2, 2);
2736 static MachineClass
*select_machine(void)
2738 MachineClass
*machine_class
= find_default_machine();
2743 loc_push_none(&loc
);
2745 opts
= qemu_get_machine_opts();
2746 qemu_opts_loc_restore(opts
);
2748 optarg
= qemu_opt_get(opts
, "type");
2750 machine_class
= machine_parse(optarg
);
2753 if (!machine_class
) {
2754 error_report("No machine specified, and there is no default");
2755 error_printf("Use -machine help to list supported machines\n");
2760 return machine_class
;
2763 static int machine_set_property(void *opaque
,
2764 const char *name
, const char *value
,
2767 Object
*obj
= OBJECT(opaque
);
2768 Error
*local_err
= NULL
;
2771 if (strcmp(name
, "type") == 0) {
2775 qom_name
= g_strdup(name
);
2776 for (p
= qom_name
; *p
; p
++) {
2782 object_property_parse(obj
, value
, qom_name
, &local_err
);
2786 error_report_err(local_err
);
2795 * Initial object creation happens before all other
2796 * QEMU data types are created. The majority of objects
2797 * can be created at this point. The rng-egd object
2798 * cannot be created here, as it depends on the chardev
2801 static bool object_create_initial(const char *type
)
2803 if (g_str_equal(type
, "rng-egd")) {
2808 * return false for concrete netfilters since
2809 * they depend on netdevs already existing
2811 if (g_str_equal(type
, "filter-buffer") ||
2812 g_str_equal(type
, "filter-dump") ||
2813 g_str_equal(type
, "filter-mirror") ||
2814 g_str_equal(type
, "filter-redirector") ||
2815 g_str_equal(type
, "colo-compare") ||
2816 g_str_equal(type
, "filter-rewriter") ||
2817 g_str_equal(type
, "filter-replay")) {
2821 /* Memory allocation by backends needs to be done
2822 * after configure_accelerator() (due to the tcg_enabled()
2823 * checks at memory_region_init_*()).
2825 * Also, allocation of large amounts of memory may delay
2826 * chardev initialization for too long, and trigger timeouts
2827 * on software that waits for a monitor socket to be created
2830 if (g_str_has_prefix(type
, "memory-backend-")) {
2839 * The remainder of object creation happens after the
2840 * creation of chardev, fsdev, net clients and device data types.
2842 static bool object_create_delayed(const char *type
)
2844 return !object_create_initial(type
);
2848 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2852 const char *mem_str
;
2853 const char *maxmem_str
, *slots_str
;
2854 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2855 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2858 loc_push_none(&loc
);
2859 qemu_opts_loc_restore(opts
);
2862 mem_str
= qemu_opt_get(opts
, "size");
2865 error_report("missing 'size' option value");
2869 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2871 /* Fix up legacy suffix-less format */
2872 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2873 uint64_t overflow_check
= sz
;
2876 if ((sz
>> 20) != overflow_check
) {
2877 error_report("too large 'size' option value");
2883 /* backward compatibility behaviour for case "-m 0" */
2885 sz
= default_ram_size
;
2888 sz
= QEMU_ALIGN_UP(sz
, 8192);
2890 if (ram_size
!= sz
) {
2891 error_report("ram size too large");
2895 /* store value for the future use */
2896 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2897 *maxram_size
= ram_size
;
2899 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2900 slots_str
= qemu_opt_get(opts
, "slots");
2901 if (maxmem_str
&& slots_str
) {
2904 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2905 slots
= qemu_opt_get_number(opts
, "slots", 0);
2906 if (sz
< ram_size
) {
2907 error_report("invalid value of -m option maxmem: "
2908 "maximum memory size (0x%" PRIx64
") must be at least "
2909 "the initial memory size (0x" RAM_ADDR_FMT
")",
2912 } else if (sz
> ram_size
) {
2914 error_report("invalid value of -m option: maxmem was "
2915 "specified, but no hotplug slots were specified");
2919 error_report("invalid value of -m option maxmem: "
2920 "memory slots were specified but maximum memory size "
2921 "(0x%" PRIx64
") is equal to the initial memory size "
2922 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2928 } else if ((!maxmem_str
&& slots_str
) ||
2929 (maxmem_str
&& !slots_str
)) {
2930 error_report("invalid -m option value: missing "
2931 "'%s' option", slots_str
? "maxmem" : "slots");
2938 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2942 g
= g_malloc0(sizeof(*g
));
2943 g
->driver
= qemu_opt_get(opts
, "driver");
2944 g
->property
= qemu_opt_get(opts
, "property");
2945 g
->value
= qemu_opt_get(opts
, "value");
2946 g
->user_provided
= true;
2947 g
->errp
= &error_fatal
;
2948 qdev_prop_register_global(g
);
2952 static int qemu_read_default_config_file(void)
2956 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2957 if (ret
< 0 && ret
!= -ENOENT
) {
2964 int main(int argc
, char **argv
, char **envp
)
2967 int snapshot
, linux_boot
;
2968 const char *initrd_filename
;
2969 const char *kernel_filename
, *kernel_cmdline
;
2970 const char *boot_order
= NULL
;
2971 const char *boot_once
= NULL
;
2973 int cyls
, heads
, secs
, translation
;
2974 QemuOpts
*opts
, *machine_opts
;
2975 QemuOpts
*hda_opts
= NULL
, *icount_opts
= NULL
, *accel_opts
= NULL
;
2976 QemuOptsList
*olist
;
2979 const char *loadvm
= NULL
;
2980 MachineClass
*machine_class
;
2981 const char *cpu_model
;
2982 const char *vga_model
= NULL
;
2983 const char *qtest_chrdev
= NULL
;
2984 const char *qtest_log
= NULL
;
2985 const char *pid_file
= NULL
;
2986 const char *incoming
= NULL
;
2987 bool defconfig
= true;
2988 bool userconfig
= true;
2989 bool nographic
= false;
2990 DisplayType display_type
= DT_DEFAULT
;
2991 int display_remote
= 0;
2992 const char *log_mask
= NULL
;
2993 const char *log_file
= NULL
;
2994 char *trace_file
= NULL
;
2995 ram_addr_t maxram_size
;
2996 uint64_t ram_slots
= 0;
2997 FILE *vmstate_dump_file
= NULL
;
2998 Error
*main_loop_err
= NULL
;
3000 bool list_data_dirs
= false;
3001 typedef struct BlockdevOptions_queue
{
3002 BlockdevOptions
*bdo
;
3004 QSIMPLEQ_ENTRY(BlockdevOptions_queue
) entry
;
3005 } BlockdevOptions_queue
;
3006 QSIMPLEQ_HEAD(, BlockdevOptions_queue
) bdo_queue
3007 = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
3009 module_call_init(MODULE_INIT_TRACE
);
3011 qemu_init_cpu_list();
3012 qemu_init_cpu_loop();
3013 qemu_mutex_lock_iothread();
3015 atexit(qemu_run_exit_notifiers
);
3016 error_set_progname(argv
[0]);
3017 qemu_init_exec_dir(argv
[0]);
3019 module_call_init(MODULE_INIT_QOM
);
3020 monitor_init_qmp_commands();
3022 qemu_add_opts(&qemu_drive_opts
);
3023 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3024 qemu_add_drive_opts(&qemu_common_drive_opts
);
3025 qemu_add_drive_opts(&qemu_drive_opts
);
3026 qemu_add_drive_opts(&bdrv_runtime_opts
);
3027 qemu_add_opts(&qemu_chardev_opts
);
3028 qemu_add_opts(&qemu_device_opts
);
3029 qemu_add_opts(&qemu_netdev_opts
);
3030 qemu_add_opts(&qemu_net_opts
);
3031 qemu_add_opts(&qemu_rtc_opts
);
3032 qemu_add_opts(&qemu_global_opts
);
3033 qemu_add_opts(&qemu_mon_opts
);
3034 qemu_add_opts(&qemu_trace_opts
);
3035 qemu_add_opts(&qemu_option_rom_opts
);
3036 qemu_add_opts(&qemu_machine_opts
);
3037 qemu_add_opts(&qemu_accel_opts
);
3038 qemu_add_opts(&qemu_mem_opts
);
3039 qemu_add_opts(&qemu_smp_opts
);
3040 qemu_add_opts(&qemu_boot_opts
);
3041 qemu_add_opts(&qemu_sandbox_opts
);
3042 qemu_add_opts(&qemu_add_fd_opts
);
3043 qemu_add_opts(&qemu_object_opts
);
3044 qemu_add_opts(&qemu_tpmdev_opts
);
3045 qemu_add_opts(&qemu_realtime_opts
);
3046 qemu_add_opts(&qemu_msg_opts
);
3047 qemu_add_opts(&qemu_name_opts
);
3048 qemu_add_opts(&qemu_numa_opts
);
3049 qemu_add_opts(&qemu_icount_opts
);
3050 qemu_add_opts(&qemu_semihosting_config_opts
);
3051 qemu_add_opts(&qemu_fw_cfg_opts
);
3052 module_call_init(MODULE_INIT_OPTS
);
3056 if (qcrypto_init(&err
) < 0) {
3057 error_reportf_err(err
, "cannot initialize crypto: ");
3060 rtc_clock
= QEMU_CLOCK_HOST
;
3062 QLIST_INIT (&vm_change_state_head
);
3063 os_setup_early_signal_handling();
3067 cyls
= heads
= secs
= 0;
3068 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3072 bdrv_init_with_whitelist();
3076 /* first pass of option parsing */
3078 while (optind
< argc
) {
3079 if (argv
[optind
][0] != '-') {
3083 const QEMUOption
*popt
;
3085 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3086 switch (popt
->index
) {
3087 case QEMU_OPTION_nodefconfig
:
3090 case QEMU_OPTION_nouserconfig
:
3097 if (defconfig
&& userconfig
) {
3098 if (qemu_read_default_config_file() < 0) {
3103 /* second pass of option parsing */
3108 if (argv
[optind
][0] != '-') {
3109 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3111 const QEMUOption
*popt
;
3113 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3114 if (!(popt
->arch_mask
& arch_type
)) {
3115 error_report("Option not supported for this target");
3118 switch(popt
->index
) {
3119 case QEMU_OPTION_no_kvm_irqchip
: {
3120 olist
= qemu_find_opts("machine");
3121 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3124 case QEMU_OPTION_cpu
:
3125 /* hw initialization will check this */
3128 case QEMU_OPTION_hda
:
3132 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3134 snprintf(buf
, sizeof(buf
),
3135 "%s,cyls=%d,heads=%d,secs=%d%s",
3136 HD_OPTS
, cyls
, heads
, secs
,
3137 translation
== BIOS_ATA_TRANSLATION_LBA
?
3139 translation
== BIOS_ATA_TRANSLATION_NONE
?
3140 ",trans=none" : "");
3141 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3144 case QEMU_OPTION_hdb
:
3145 case QEMU_OPTION_hdc
:
3146 case QEMU_OPTION_hdd
:
3147 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3150 case QEMU_OPTION_blockdev
:
3153 BlockdevOptions_queue
*bdo
;
3155 v
= qobject_input_visitor_new_str(optarg
, "driver", &err
);
3157 error_report_err(err
);
3161 bdo
= g_new(BlockdevOptions_queue
, 1);
3162 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
3165 loc_save(&bdo
->loc
);
3166 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
3169 case QEMU_OPTION_drive
:
3170 if (drive_def(optarg
) == NULL
) {
3174 case QEMU_OPTION_set
:
3175 if (qemu_set_option(optarg
) != 0)
3178 case QEMU_OPTION_global
:
3179 if (qemu_global_option(optarg
) != 0)
3182 case QEMU_OPTION_mtdblock
:
3183 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3185 case QEMU_OPTION_sd
:
3186 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3188 case QEMU_OPTION_pflash
:
3189 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3191 case QEMU_OPTION_snapshot
:
3194 case QEMU_OPTION_hdachs
:
3198 cyls
= strtol(p
, (char **)&p
, 0);
3199 if (cyls
< 1 || cyls
> 16383)
3204 heads
= strtol(p
, (char **)&p
, 0);
3205 if (heads
< 1 || heads
> 16)
3210 secs
= strtol(p
, (char **)&p
, 0);
3211 if (secs
< 1 || secs
> 63)
3215 if (!strcmp(p
, "large")) {
3216 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3217 } else if (!strcmp(p
, "rechs")) {
3218 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3219 } else if (!strcmp(p
, "none")) {
3220 translation
= BIOS_ATA_TRANSLATION_NONE
;
3221 } else if (!strcmp(p
, "lba")) {
3222 translation
= BIOS_ATA_TRANSLATION_LBA
;
3223 } else if (!strcmp(p
, "auto")) {
3224 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3228 } else if (*p
!= '\0') {
3230 error_report("invalid physical CHS format");
3233 if (hda_opts
!= NULL
) {
3234 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3236 qemu_opt_set_number(hda_opts
, "heads", heads
,
3238 qemu_opt_set_number(hda_opts
, "secs", secs
,
3240 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3241 qemu_opt_set(hda_opts
, "trans", "large",
3243 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3244 qemu_opt_set(hda_opts
, "trans", "rechs",
3246 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3247 qemu_opt_set(hda_opts
, "trans", "lba",
3249 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3250 qemu_opt_set(hda_opts
, "trans", "none",
3255 error_report("'-hdachs' is deprecated, please use '-device"
3256 " ide-hd,cyls=c,heads=h,secs=s,...' instead");
3258 case QEMU_OPTION_numa
:
3259 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3265 case QEMU_OPTION_display
:
3266 display_type
= select_display(optarg
);
3268 case QEMU_OPTION_nographic
:
3269 olist
= qemu_find_opts("machine");
3270 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3272 display_type
= DT_NONE
;
3274 case QEMU_OPTION_curses
:
3275 #ifdef CONFIG_CURSES
3276 display_type
= DT_CURSES
;
3278 error_report("curses support is disabled");
3282 case QEMU_OPTION_portrait
:
3283 graphic_rotate
= 90;
3285 case QEMU_OPTION_rotate
:
3286 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3287 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3288 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3289 error_report("only 90, 180, 270 deg rotation is available");
3293 case QEMU_OPTION_kernel
:
3294 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3297 case QEMU_OPTION_initrd
:
3298 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3301 case QEMU_OPTION_append
:
3302 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3305 case QEMU_OPTION_dtb
:
3306 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3309 case QEMU_OPTION_cdrom
:
3310 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3312 case QEMU_OPTION_boot
:
3313 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3319 case QEMU_OPTION_fda
:
3320 case QEMU_OPTION_fdb
:
3321 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3324 case QEMU_OPTION_no_fd_bootchk
:
3327 case QEMU_OPTION_netdev
:
3329 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3333 case QEMU_OPTION_net
:
3335 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3339 #ifdef CONFIG_LIBISCSI
3340 case QEMU_OPTION_iscsi
:
3341 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3349 case QEMU_OPTION_tftp
:
3350 error_report("The -tftp option is deprecated. "
3351 "Please use '-netdev user,tftp=...' instead.");
3352 legacy_tftp_prefix
= optarg
;
3354 case QEMU_OPTION_bootp
:
3355 error_report("The -bootp option is deprecated. "
3356 "Please use '-netdev user,bootfile=...' instead.");
3357 legacy_bootp_filename
= optarg
;
3359 case QEMU_OPTION_redir
:
3360 error_report("The -redir option is deprecated. "
3361 "Please use '-netdev user,hostfwd=...' instead.");
3362 if (net_slirp_redir(optarg
) < 0)
3366 case QEMU_OPTION_bt
:
3367 add_device_config(DEV_BT
, optarg
);
3369 case QEMU_OPTION_audio_help
:
3373 case QEMU_OPTION_soundhw
:
3374 select_soundhw (optarg
);
3379 case QEMU_OPTION_version
:
3384 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3391 case QEMU_OPTION_tpmdev
:
3392 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3397 case QEMU_OPTION_mempath
:
3400 case QEMU_OPTION_mem_prealloc
:
3409 case QEMU_OPTION_DFILTER
:
3410 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3413 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3415 case QEMU_OPTION_gdb
:
3416 add_device_config(DEV_GDB
, optarg
);
3419 if (is_help_option(optarg
)) {
3420 list_data_dirs
= true;
3421 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3422 data_dir
[data_dir_idx
++] = optarg
;
3425 case QEMU_OPTION_bios
:
3426 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3429 case QEMU_OPTION_singlestep
:
3436 keyboard_layout
= optarg
;
3438 case QEMU_OPTION_localtime
:
3441 case QEMU_OPTION_vga
:
3450 w
= strtol(p
, (char **)&p
, 10);
3453 error_report("invalid resolution or depth");
3459 h
= strtol(p
, (char **)&p
, 10);
3464 depth
= strtol(p
, (char **)&p
, 10);
3465 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3466 depth
!= 24 && depth
!= 32)
3468 } else if (*p
== '\0') {
3469 depth
= graphic_depth
;
3476 graphic_depth
= depth
;
3479 case QEMU_OPTION_echr
:
3482 term_escape_char
= strtol(optarg
, &r
, 0);
3484 printf("Bad argument to echr\n");
3487 case QEMU_OPTION_monitor
:
3488 default_monitor
= 0;
3489 if (strncmp(optarg
, "none", 4)) {
3490 monitor_parse(optarg
, "readline", false);
3493 case QEMU_OPTION_qmp
:
3494 monitor_parse(optarg
, "control", false);
3495 default_monitor
= 0;
3497 case QEMU_OPTION_qmp_pretty
:
3498 monitor_parse(optarg
, "control", true);
3499 default_monitor
= 0;
3501 case QEMU_OPTION_mon
:
3502 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3507 default_monitor
= 0;
3509 case QEMU_OPTION_chardev
:
3510 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3516 case QEMU_OPTION_fsdev
:
3517 olist
= qemu_find_opts("fsdev");
3519 error_report("fsdev support is disabled");
3522 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3527 case QEMU_OPTION_virtfs
: {
3530 const char *writeout
, *sock_fd
, *socket
;
3532 olist
= qemu_find_opts("virtfs");
3534 error_report("virtfs support is disabled");
3537 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3542 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3543 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3544 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3547 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3548 qemu_opts_id(opts
) ?:
3549 qemu_opt_get(opts
, "mount_tag"),
3552 error_report("duplicate or invalid fsdev id: %s",
3553 qemu_opt_get(opts
, "mount_tag"));
3557 writeout
= qemu_opt_get(opts
, "writeout");
3559 #ifdef CONFIG_SYNC_FILE_RANGE
3560 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3562 error_report("writeout=immediate not supported "
3563 "on this platform");
3567 qemu_opt_set(fsdev
, "fsdriver",
3568 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3569 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3571 qemu_opt_set(fsdev
, "security_model",
3572 qemu_opt_get(opts
, "security_model"),
3574 socket
= qemu_opt_get(opts
, "socket");
3576 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3578 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3580 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3583 qemu_opt_set_bool(fsdev
, "readonly",
3584 qemu_opt_get_bool(opts
, "readonly", 0),
3586 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3588 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3589 qemu_opt_set(device
, "fsdev",
3590 qemu_opts_id(fsdev
), &error_abort
);
3591 qemu_opt_set(device
, "mount_tag",
3592 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3595 case QEMU_OPTION_virtfs_synth
: {
3599 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3602 error_report("duplicate option: %s", "virtfs_synth");
3605 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3607 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3609 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3610 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3611 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3614 case QEMU_OPTION_serial
:
3615 add_device_config(DEV_SERIAL
, optarg
);
3617 if (strncmp(optarg
, "mon:", 4) == 0) {
3618 default_monitor
= 0;
3621 case QEMU_OPTION_watchdog
:
3623 error_report("only one watchdog option may be given");
3628 case QEMU_OPTION_watchdog_action
:
3629 if (select_watchdog_action(optarg
) == -1) {
3630 error_report("unknown -watchdog-action parameter");
3634 case QEMU_OPTION_virtiocon
:
3635 add_device_config(DEV_VIRTCON
, optarg
);
3636 default_virtcon
= 0;
3637 if (strncmp(optarg
, "mon:", 4) == 0) {
3638 default_monitor
= 0;
3641 case QEMU_OPTION_parallel
:
3642 add_device_config(DEV_PARALLEL
, optarg
);
3643 default_parallel
= 0;
3644 if (strncmp(optarg
, "mon:", 4) == 0) {
3645 default_monitor
= 0;
3648 case QEMU_OPTION_debugcon
:
3649 add_device_config(DEV_DEBUGCON
, optarg
);
3651 case QEMU_OPTION_loadvm
:
3654 case QEMU_OPTION_full_screen
:
3657 case QEMU_OPTION_no_frame
:
3660 case QEMU_OPTION_alt_grab
:
3663 case QEMU_OPTION_ctrl_grab
:
3666 case QEMU_OPTION_no_quit
:
3669 case QEMU_OPTION_sdl
:
3671 display_type
= DT_SDL
;
3674 error_report("SDL support is disabled");
3677 case QEMU_OPTION_pidfile
:
3680 case QEMU_OPTION_win2k_hack
:
3681 win2k_install_hack
= 1;
3683 case QEMU_OPTION_rtc_td_hack
: {
3684 static GlobalProperty slew_lost_ticks
= {
3685 .driver
= "mc146818rtc",
3686 .property
= "lost_tick_policy",
3690 qdev_prop_register_global(&slew_lost_ticks
);
3693 case QEMU_OPTION_acpitable
:
3694 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3699 acpi_table_add(opts
, &error_fatal
);
3701 case QEMU_OPTION_smbios
:
3702 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3707 smbios_entry_add(opts
, &error_fatal
);
3709 case QEMU_OPTION_fwcfg
:
3710 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3716 case QEMU_OPTION_enable_kvm
:
3717 olist
= qemu_find_opts("machine");
3718 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3720 case QEMU_OPTION_enable_hax
:
3721 olist
= qemu_find_opts("machine");
3722 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3725 case QEMU_OPTION_machine
:
3726 olist
= qemu_find_opts("machine");
3727 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3732 case QEMU_OPTION_no_kvm
:
3733 olist
= qemu_find_opts("machine");
3734 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3736 case QEMU_OPTION_no_kvm_pit
: {
3737 error_report("warning: ignoring deprecated option");
3740 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3741 static GlobalProperty kvm_pit_lost_tick_policy
= {
3742 .driver
= "kvm-pit",
3743 .property
= "lost_tick_policy",
3747 error_report("warning: deprecated, replaced by "
3748 "-global kvm-pit.lost_tick_policy=discard");
3749 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3752 case QEMU_OPTION_accel
: {
3753 QemuOpts
*accel_opts
;
3755 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3757 optarg
= qemu_opt_get(accel_opts
, "accel");
3758 if (!optarg
|| is_help_option(optarg
)) {
3759 error_printf("Possible accelerators: kvm, xen, hax, tcg\n");
3762 accel_opts
= qemu_opts_create(qemu_find_opts("machine"), NULL
,
3763 false, &error_abort
);
3764 qemu_opt_set(accel_opts
, "accel", optarg
, &error_abort
);
3767 case QEMU_OPTION_usb
:
3768 olist
= qemu_find_opts("machine");
3769 qemu_opts_parse_noisily(olist
, "usb=on", false);
3771 case QEMU_OPTION_usbdevice
:
3772 olist
= qemu_find_opts("machine");
3773 qemu_opts_parse_noisily(olist
, "usb=on", false);
3774 add_device_config(DEV_USB
, optarg
);
3776 case QEMU_OPTION_device
:
3777 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3782 case QEMU_OPTION_smp
:
3783 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3788 case QEMU_OPTION_vnc
:
3789 vnc_parse(optarg
, &error_fatal
);
3791 case QEMU_OPTION_no_acpi
:
3794 case QEMU_OPTION_no_hpet
:
3797 case QEMU_OPTION_balloon
:
3798 if (balloon_parse(optarg
) < 0) {
3799 error_report("unknown -balloon argument %s", optarg
);
3803 case QEMU_OPTION_no_reboot
:
3806 case QEMU_OPTION_no_shutdown
:
3809 case QEMU_OPTION_show_cursor
:
3812 case QEMU_OPTION_uuid
:
3813 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3814 error_report("failed to parse UUID string: wrong format");
3817 qemu_uuid_set
= true;
3819 case QEMU_OPTION_option_rom
:
3820 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3821 error_report("too many option ROMs");
3824 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3829 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3830 option_rom
[nb_option_roms
].bootindex
=
3831 qemu_opt_get_number(opts
, "bootindex", -1);
3832 if (!option_rom
[nb_option_roms
].name
) {
3833 error_report("Option ROM file is not specified");
3838 case QEMU_OPTION_semihosting
:
3839 semihosting
.enabled
= true;
3840 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3842 case QEMU_OPTION_semihosting_config
:
3843 semihosting
.enabled
= true;
3844 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3847 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3849 const char *target
= qemu_opt_get(opts
, "target");
3850 if (target
!= NULL
) {
3851 if (strcmp("native", target
) == 0) {
3852 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3853 } else if (strcmp("gdb", target
) == 0) {
3854 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3855 } else if (strcmp("auto", target
) == 0) {
3856 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3858 error_report("unsupported semihosting-config %s",
3863 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3865 /* Set semihosting argument count and vector */
3866 qemu_opt_foreach(opts
, add_semihosting_arg
,
3867 &semihosting
, NULL
);
3869 error_report("unsupported semihosting-config %s", optarg
);
3873 case QEMU_OPTION_tdf
:
3874 error_report("warning: ignoring deprecated option");
3876 case QEMU_OPTION_name
:
3877 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3883 case QEMU_OPTION_prom_env
:
3884 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3885 error_report("too many prom variables");
3888 prom_envs
[nb_prom_envs
] = optarg
;
3891 case QEMU_OPTION_old_param
:
3894 case QEMU_OPTION_clock
:
3895 /* Clock options no longer exist. Keep this option for
3896 * backward compatibility.
3899 case QEMU_OPTION_startdate
:
3900 configure_rtc_date_offset(optarg
, 1);
3902 case QEMU_OPTION_rtc
:
3903 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3908 configure_rtc(opts
);
3910 case QEMU_OPTION_tb_size
:
3911 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3912 if (tcg_tb_size
< 0) {
3916 case QEMU_OPTION_icount
:
3917 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3923 case QEMU_OPTION_incoming
:
3925 runstate_set(RUN_STATE_INMIGRATE
);
3929 case QEMU_OPTION_only_migratable
:
3930 only_migratable
= 1;
3932 case QEMU_OPTION_nodefaults
:
3935 case QEMU_OPTION_xen_domid
:
3936 if (!(xen_available())) {
3937 error_report("Option not supported for this target");
3940 xen_domid
= atoi(optarg
);
3942 case QEMU_OPTION_xen_create
:
3943 if (!(xen_available())) {
3944 error_report("Option not supported for this target");
3947 xen_mode
= XEN_CREATE
;
3949 case QEMU_OPTION_xen_attach
:
3950 if (!(xen_available())) {
3951 error_report("Option not supported for this target");
3954 xen_mode
= XEN_ATTACH
;
3956 case QEMU_OPTION_xen_domid_restrict
:
3957 if (!(xen_available())) {
3958 error_report("Option not supported for this target");
3961 xen_domid_restrict
= true;
3963 case QEMU_OPTION_trace
:
3965 trace_file
= trace_opt_parse(optarg
);
3967 case QEMU_OPTION_readconfig
:
3969 int ret
= qemu_read_config_file(optarg
);
3971 error_report("read config %s: %s", optarg
,
3977 case QEMU_OPTION_spice
:
3978 olist
= qemu_find_opts("spice");
3980 error_report("spice support is disabled");
3983 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3989 case QEMU_OPTION_writeconfig
:
3992 if (strcmp(optarg
, "-") == 0) {
3995 fp
= fopen(optarg
, "w");
3997 error_report("open %s: %s", optarg
,
4002 qemu_config_write(fp
);
4008 case QEMU_OPTION_qtest
:
4009 qtest_chrdev
= optarg
;
4011 case QEMU_OPTION_qtest_log
:
4014 case QEMU_OPTION_sandbox
:
4015 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4021 case QEMU_OPTION_add_fd
:
4023 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4029 error_report("File descriptor passing is disabled on this "
4034 case QEMU_OPTION_object
:
4035 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
4041 case QEMU_OPTION_realtime
:
4042 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4047 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4049 case QEMU_OPTION_msg
:
4050 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4055 configure_msg(opts
);
4057 case QEMU_OPTION_dump_vmstate
:
4058 if (vmstate_dump_file
) {
4059 error_report("only one '-dump-vmstate' "
4060 "option may be given");
4063 vmstate_dump_file
= fopen(optarg
, "w");
4064 if (vmstate_dump_file
== NULL
) {
4065 error_report("open %s: %s", optarg
, strerror(errno
));
4070 os_parse_cmd_args(popt
->index
, optarg
);
4075 * Clear error location left behind by the loop.
4076 * Best done right after the loop. Do not insert code here!
4080 replay_configure(icount_opts
);
4082 machine_class
= select_machine();
4084 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4088 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4089 error_report("could not acquire pid file: %s", strerror(errno
));
4093 if (qemu_init_main_loop(&main_loop_err
)) {
4094 error_report_err(main_loop_err
);
4098 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4099 parse_sandbox
, NULL
, NULL
)) {
4103 if (qemu_opts_foreach(qemu_find_opts("name"),
4104 parse_name
, NULL
, NULL
)) {
4109 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4110 parse_add_fd
, NULL
, NULL
)) {
4114 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4115 cleanup_add_fd
, NULL
, NULL
)) {
4120 current_machine
= MACHINE(object_new(object_class_get_name(
4121 OBJECT_CLASS(machine_class
))));
4122 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4125 object_property_add_child(object_get_root(), "machine",
4126 OBJECT(current_machine
), &error_abort
);
4128 if (machine_class
->minimum_page_bits
) {
4129 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4130 /* This would be a board error: specifying a minimum smaller than
4131 * a target's compile-time fixed setting.
4133 g_assert_not_reached();
4137 cpu_exec_init_all();
4139 if (machine_class
->hw_version
) {
4140 qemu_set_hw_version(machine_class
->hw_version
);
4143 if (cpu_model
&& is_help_option(cpu_model
)) {
4144 list_cpus(stdout
, &fprintf
, cpu_model
);
4148 if (!trace_init_backends()) {
4151 trace_init_file(trace_file
);
4153 /* Open the logfile at this point and set the log mask if necessary.
4156 qemu_set_log_filename(log_file
, &error_fatal
);
4161 mask
= qemu_str_to_log_mask(log_mask
);
4163 qemu_print_log_usage(stdout
);
4171 /* If no data_dir is specified then try to find it relative to the
4173 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4174 data_dir
[data_dir_idx
] = os_find_datadir();
4175 if (data_dir
[data_dir_idx
] != NULL
) {
4179 /* If all else fails use the install path specified when building. */
4180 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4181 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4184 /* -L help lists the data directories and exits. */
4185 if (list_data_dirs
) {
4186 for (i
= 0; i
< data_dir_idx
; i
++) {
4187 printf("%s\n", data_dir
[i
]);
4192 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4194 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4195 if (max_cpus
> machine_class
->max_cpus
) {
4196 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4197 "supported by machine '%s' (%d)", max_cpus
,
4198 machine_class
->name
, machine_class
->max_cpus
);
4203 * Get the default machine options from the machine if it is not already
4204 * specified either by the configuration file or by the command line.
4206 if (machine_class
->default_machine_opts
) {
4207 qemu_opts_set_defaults(qemu_find_opts("machine"),
4208 machine_class
->default_machine_opts
, 0);
4211 qemu_opts_foreach(qemu_find_opts("device"),
4212 default_driver_check
, NULL
, NULL
);
4213 qemu_opts_foreach(qemu_find_opts("global"),
4214 default_driver_check
, NULL
, NULL
);
4216 if (!vga_model
&& !default_vga
) {
4217 vga_interface_type
= VGA_DEVICE
;
4219 if (!has_defaults
|| machine_class
->no_serial
) {
4222 if (!has_defaults
|| machine_class
->no_parallel
) {
4223 default_parallel
= 0;
4225 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4226 default_virtcon
= 0;
4228 if (!has_defaults
|| !machine_class
->use_sclp
) {
4231 if (!has_defaults
|| machine_class
->no_floppy
) {
4234 if (!has_defaults
|| machine_class
->no_cdrom
) {
4237 if (!has_defaults
|| machine_class
->no_sdcard
) {
4240 if (!has_defaults
) {
4241 default_monitor
= 0;
4246 if (is_daemonized()) {
4247 /* According to documentation and historically, -nographic redirects
4248 * serial port, parallel port and monitor to stdio, which does not work
4249 * with -daemonize. We can redirect these to null instead, but since
4250 * -nographic is legacy, let's just error out.
4251 * We disallow -nographic only if all other ports are not redirected
4252 * explicitly, to not break existing legacy setups which uses
4253 * -nographic _and_ redirects all ports explicitly - this is valid
4254 * usage, -nographic is just a no-op in this case.
4257 && (default_parallel
|| default_serial
4258 || default_monitor
|| default_virtcon
)) {
4259 error_report("-nographic cannot be used with -daemonize");
4262 #ifdef CONFIG_CURSES
4263 if (display_type
== DT_CURSES
) {
4264 error_report("curses display cannot be used with -daemonize");
4271 if (default_parallel
)
4272 add_device_config(DEV_PARALLEL
, "null");
4273 if (default_serial
&& default_monitor
) {
4274 add_device_config(DEV_SERIAL
, "mon:stdio");
4275 } else if (default_virtcon
&& default_monitor
) {
4276 add_device_config(DEV_VIRTCON
, "mon:stdio");
4277 } else if (default_sclp
&& default_monitor
) {
4278 add_device_config(DEV_SCLP
, "mon:stdio");
4281 add_device_config(DEV_SERIAL
, "stdio");
4282 if (default_virtcon
)
4283 add_device_config(DEV_VIRTCON
, "stdio");
4285 add_device_config(DEV_SCLP
, "stdio");
4287 if (default_monitor
)
4288 monitor_parse("stdio", "readline", false);
4292 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4293 if (default_parallel
)
4294 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4295 if (default_monitor
)
4296 monitor_parse("vc:80Cx24C", "readline", false);
4297 if (default_virtcon
)
4298 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4300 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4304 #if defined(CONFIG_VNC)
4305 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4309 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4310 #if defined(CONFIG_GTK)
4311 display_type
= DT_GTK
;
4312 #elif defined(CONFIG_SDL)
4313 display_type
= DT_SDL
;
4314 #elif defined(CONFIG_COCOA)
4315 display_type
= DT_COCOA
;
4316 #elif defined(CONFIG_VNC)
4317 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4319 display_type
= DT_NONE
;
4323 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4324 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4325 "for SDL, ignoring option");
4327 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4328 error_report("-no-quit is only valid for GTK and SDL, "
4332 if (display_type
== DT_GTK
) {
4333 early_gtk_display_init(request_opengl
);
4336 if (display_type
== DT_SDL
) {
4337 sdl_display_early_init(request_opengl
);
4340 qemu_console_early_init();
4342 if (request_opengl
== 1 && display_opengl
== 0) {
4343 #if defined(CONFIG_OPENGL)
4344 error_report("OpenGL is not supported by the display");
4346 error_report("OpenGL support is disabled");
4354 if (qemu_opts_foreach(qemu_find_opts("object"),
4355 user_creatable_add_opts_foreach
,
4356 object_create_initial
, NULL
)) {
4360 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4361 chardev_init_func
, NULL
, NULL
)) {
4365 #ifdef CONFIG_VIRTFS
4366 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4367 fsdev_init_func
, NULL
, NULL
)) {
4372 if (qemu_opts_foreach(qemu_find_opts("device"),
4373 device_help_func
, NULL
, NULL
)) {
4377 machine_opts
= qemu_get_machine_opts();
4378 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4380 object_unref(OBJECT(current_machine
));
4384 configure_accelerator(current_machine
);
4387 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4390 machine_opts
= qemu_get_machine_opts();
4391 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4392 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4393 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4394 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4396 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4398 boot_order
= qemu_opt_get(opts
, "order");
4400 validate_bootdevices(boot_order
, &error_fatal
);
4403 boot_once
= qemu_opt_get(opts
, "once");
4405 validate_bootdevices(boot_once
, &error_fatal
);
4408 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4409 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4413 boot_order
= machine_class
->default_boot_order
;
4416 if (!kernel_cmdline
) {
4417 kernel_cmdline
= "";
4418 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4421 linux_boot
= (kernel_filename
!= NULL
);
4423 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4424 error_report("-append only allowed with -kernel option");
4428 if (!linux_boot
&& initrd_filename
!= NULL
) {
4429 error_report("-initrd only allowed with -kernel option");
4433 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4434 /* fall back to the -kernel/-append */
4435 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4438 os_set_line_buffering();
4440 /* spice needs the timers to be initialized by this point */
4445 if (!tcg_enabled()) {
4446 error_report("-icount is not allowed with hardware virtualization");
4449 configure_icount(icount_opts
, &error_abort
);
4450 qemu_opts_del(icount_opts
);
4453 qemu_tcg_configure(accel_opts
, &error_fatal
);
4456 QemuOptsList
*net
= qemu_find_opts("net");
4457 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4459 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4465 if (net_init_clients() < 0) {
4469 if (qemu_opts_foreach(qemu_find_opts("object"),
4470 user_creatable_add_opts_foreach
,
4471 object_create_delayed
, NULL
)) {
4476 if (tpm_init() < 0) {
4481 /* init the bluetooth world */
4482 if (foreach_device_config(DEV_BT
, bt_parse
))
4485 if (!xen_enabled()) {
4486 /* On 32-bit hosts, QEMU is limited by virtual address space */
4487 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4488 error_report("at most 2047 MB RAM can be simulated");
4496 /* If the currently selected machine wishes to override the units-per-bus
4497 * property of its default HBA interface type, do so now. */
4498 if (machine_class
->units_per_default_bus
) {
4499 override_max_devs(machine_class
->block_default_type
,
4500 machine_class
->units_per_default_bus
);
4503 /* open the virtual block devices */
4504 while (!QSIMPLEQ_EMPTY(&bdo_queue
)) {
4505 BlockdevOptions_queue
*bdo
= QSIMPLEQ_FIRST(&bdo_queue
);
4507 QSIMPLEQ_REMOVE_HEAD(&bdo_queue
, entry
);
4508 loc_push_restore(&bdo
->loc
);
4509 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
4511 qapi_free_BlockdevOptions(bdo
->bdo
);
4514 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4515 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4518 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4519 &machine_class
->block_default_type
, NULL
)) {
4523 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4525 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4526 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4528 parse_numa_opts(current_machine
);
4530 if (qemu_opts_foreach(qemu_find_opts("mon"),
4531 mon_init_func
, NULL
, NULL
)) {
4535 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4537 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4539 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4541 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4544 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4547 /* If no default VGA is requested, the default is "none". */
4549 if (machine_class
->default_display
) {
4550 vga_model
= machine_class
->default_display
;
4551 } else if (vga_interface_available(VGA_CIRRUS
)) {
4552 vga_model
= "cirrus";
4553 } else if (vga_interface_available(VGA_STD
)) {
4558 select_vgahw(vga_model
);
4562 i
= select_watchdog(watchdog
);
4564 exit (i
== 1 ? 1 : 0);
4567 machine_register_compat_props(current_machine
);
4569 qemu_opts_foreach(qemu_find_opts("global"),
4570 global_init_func
, NULL
, NULL
);
4572 /* This checkpoint is required by replay to separate prior clock
4573 reading from the other reads, because timer polling functions query
4574 clock values from the log. */
4575 replay_checkpoint(CHECKPOINT_INIT
);
4576 qdev_machine_init();
4578 current_machine
->ram_size
= ram_size
;
4579 current_machine
->maxram_size
= maxram_size
;
4580 current_machine
->ram_slots
= ram_slots
;
4581 current_machine
->boot_order
= boot_order
;
4582 current_machine
->cpu_model
= cpu_model
;
4584 machine_run_board_init(current_machine
);
4590 if (hax_enabled()) {
4594 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4595 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4599 /* init USB devices */
4600 if (machine_usb(current_machine
)) {
4601 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4605 /* Check if IGD GFX passthrough. */
4608 /* init generic devices */
4609 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4610 if (qemu_opts_foreach(qemu_find_opts("device"),
4611 device_init_func
, NULL
, NULL
)) {
4615 cpu_synchronize_all_post_init();
4617 rom_reset_order_override();
4620 * Create frontends for -drive if=scsi leftovers.
4621 * Normally, frontends for -drive get created by machine
4622 * initialization for onboard SCSI HBAs. However, we create a few
4623 * more ever since SCSI qdevification, but this is pretty much an
4624 * implementation accident, and deprecated.
4626 scsi_legacy_handle_cmdline();
4628 /* Did we create any drives that we failed to create a device for? */
4629 drive_check_orphaned();
4631 /* Don't warn about the default network setup that you get if
4632 * no command line -net or -netdev options are specified. There
4633 * are two cases that we would otherwise complain about:
4634 * (1) board doesn't support a NIC but the implicit "-net nic"
4636 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4637 * sets up a nic that isn't connected to anything.
4640 net_check_clients();
4645 qemu_boot_set(boot_once
, &error_fatal
);
4646 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4649 ds
= init_displaystate();
4651 /* init local displays */
4652 switch (display_type
) {
4654 curses_display_init(ds
, full_screen
);
4657 sdl_display_init(ds
, full_screen
, no_frame
);
4660 cocoa_display_init(ds
, full_screen
);
4663 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4669 /* must be after terminal init, SDL library changes signal handlers */
4670 os_setup_signal_handling();
4672 /* init remote displays */
4674 qemu_opts_foreach(qemu_find_opts("vnc"),
4675 vnc_init_func
, NULL
, NULL
);
4679 qemu_spice_display_init();
4682 #ifdef CONFIG_OPENGL
4683 if (display_type
== DT_EGL
) {
4684 egl_headless_init();
4688 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4692 qdev_machine_creation_done();
4694 /* TODO: once all bus devices are qdevified, this should be done
4695 * when bus is created by qdev.c */
4696 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4697 qemu_run_machine_init_done_notifiers();
4699 if (rom_check_and_register_reset() != 0) {
4700 error_report("rom check and register reset failed");
4706 /* This checkpoint is required by replay to separate prior clock
4707 reading from the other reads, because timer polling functions query
4708 clock values from the log. */
4709 replay_checkpoint(CHECKPOINT_RESET
);
4710 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
4711 register_global_state();
4712 if (replay_mode
!= REPLAY_MODE_NONE
) {
4713 replay_vmstate_init();
4714 } else if (loadvm
) {
4715 Error
*local_err
= NULL
;
4716 if (load_vmstate(loadvm
, &local_err
) < 0) {
4717 error_report_err(local_err
);
4722 qdev_prop_check_globals();
4723 if (vmstate_dump_file
) {
4725 dump_vmstate_json_to_file(vmstate_dump_file
);
4730 Error
*local_err
= NULL
;
4731 qemu_start_incoming_migration(incoming
, &local_err
);
4733 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4736 } else if (autostart
) {
4743 replay_disable_events();
4744 iothread_stop_all();
4750 /* vhost-user must be cleaned up before chardevs. */
4755 /* TODO: unref root container, check all devices are ok */