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 "chardev/char.h"
85 #include "qemu/bitmap.h"
87 #include "sysemu/blockdev.h"
88 #include "hw/block/block.h"
89 #include "migration/misc.h"
90 #include "migration/snapshot.h"
91 #include "migration/global_state.h"
92 #include "sysemu/tpm.h"
93 #include "sysemu/dma.h"
94 #include "hw/audio/soundhw.h"
95 #include "audio/audio.h"
96 #include "sysemu/cpus.h"
97 #include "migration/colo.h"
98 #include "sysemu/kvm.h"
99 #include "sysemu/hax.h"
100 #include "qapi/qobject-input-visitor.h"
101 #include "qapi/qobject-input-visitor.h"
102 #include "qapi-visit.h"
103 #include "qapi/qmp/qjson.h"
104 #include "qemu/option.h"
105 #include "qemu/config-file.h"
106 #include "qemu-options.h"
107 #include "qmp-commands.h"
108 #include "qemu/main-loop.h"
110 #include "fsdev/qemu-fsdev.h"
112 #include "sysemu/qtest.h"
114 #include "disas/disas.h"
117 #include "slirp/libslirp.h"
119 #include "trace-root.h"
120 #include "trace/control.h"
121 #include "qemu/queue.h"
122 #include "sysemu/arch_init.h"
124 #include "ui/qemu-spice.h"
125 #include "qapi/string-input-visitor.h"
126 #include "qapi/opts-visitor.h"
127 #include "qom/object_interfaces.h"
128 #include "qapi-event.h"
129 #include "exec/semihost.h"
130 #include "crypto/init.h"
131 #include "sysemu/replay.h"
132 #include "qapi/qmp/qerror.h"
133 #include "sysemu/iothread.h"
135 #define MAX_VIRTIO_CONSOLES 1
136 #define MAX_SCLP_CONSOLES 1
138 static const char *data_dir
[16];
139 static int data_dir_idx
;
140 const char *bios_name
= NULL
;
141 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
142 int request_opengl
= -1;
144 const char* keyboard_layout
= NULL
;
146 const char *mem_path
= NULL
;
147 int mem_prealloc
= 0; /* force preallocation of physical target memory */
148 bool enable_mlock
= false;
150 NICInfo nd_table
[MAX_NICS
];
152 static int rtc_utc
= 1;
153 static int rtc_date_offset
= -1; /* -1 means no change */
154 QEMUClockType rtc_clock
;
155 int vga_interface_type
= VGA_NONE
;
156 static int full_screen
= 0;
157 static int no_frame
= 0;
159 static bool grab_on_hover
;
160 Chardev
*serial_hds
[MAX_SERIAL_PORTS
];
161 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
162 Chardev
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
163 Chardev
*sclp_hds
[MAX_SCLP_CONSOLES
];
164 int win2k_install_hack
= 0;
170 int acpi_enabled
= 1;
173 static int no_reboot
;
176 int graphic_rotate
= 0;
177 const char *watchdog
;
178 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
181 const char *qemu_name
;
184 unsigned int nb_prom_envs
= 0;
185 const char *prom_envs
[MAX_PROM_ENVS
];
188 uint8_t *boot_splash_filedata
;
189 size_t boot_splash_filedata_size
;
190 uint8_t qemu_extra_params_fw
[2];
191 int only_migratable
; /* turn it off unless user states otherwise */
193 int icount_align_option
;
195 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
196 * little-endian "wire format" described in the SMBIOS 2.6 specification.
201 static NotifierList exit_notifiers
=
202 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
204 static NotifierList machine_init_done_notifiers
=
205 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
209 enum xen_mode xen_mode
= XEN_EMULATE
;
210 bool xen_domid_restrict
;
212 static int has_defaults
= 1;
213 static int default_serial
= 1;
214 static int default_parallel
= 1;
215 static int default_virtcon
= 1;
216 static int default_sclp
= 1;
217 static int default_monitor
= 1;
218 static int default_floppy
= 1;
219 static int default_cdrom
= 1;
220 static int default_sdcard
= 1;
221 static int default_vga
= 1;
222 static int default_net
= 1;
228 { .driver
= "isa-serial", .flag
= &default_serial
},
229 { .driver
= "isa-parallel", .flag
= &default_parallel
},
230 { .driver
= "isa-fdc", .flag
= &default_floppy
},
231 { .driver
= "floppy", .flag
= &default_floppy
},
232 { .driver
= "ide-cd", .flag
= &default_cdrom
},
233 { .driver
= "ide-hd", .flag
= &default_cdrom
},
234 { .driver
= "ide-drive", .flag
= &default_cdrom
},
235 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
236 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
237 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
238 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
239 { .driver
= "VGA", .flag
= &default_vga
},
240 { .driver
= "isa-vga", .flag
= &default_vga
},
241 { .driver
= "cirrus-vga", .flag
= &default_vga
},
242 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
243 { .driver
= "vmware-svga", .flag
= &default_vga
},
244 { .driver
= "qxl-vga", .flag
= &default_vga
},
245 { .driver
= "virtio-vga", .flag
= &default_vga
},
248 static QemuOptsList qemu_rtc_opts
= {
250 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
254 .type
= QEMU_OPT_STRING
,
257 .type
= QEMU_OPT_STRING
,
260 .type
= QEMU_OPT_STRING
,
262 { /* end of list */ }
266 static QemuOptsList qemu_sandbox_opts
= {
268 .implied_opt_name
= "enable",
269 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
273 .type
= QEMU_OPT_BOOL
,
275 { /* end of list */ }
279 static QemuOptsList qemu_option_rom_opts
= {
280 .name
= "option-rom",
281 .implied_opt_name
= "romfile",
282 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
286 .type
= QEMU_OPT_NUMBER
,
289 .type
= QEMU_OPT_STRING
,
291 { /* end of list */ }
295 static QemuOptsList qemu_machine_opts
= {
297 .implied_opt_name
= "type",
299 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
302 * no elements => accept any
303 * sanity checking will happen later
304 * when setting machine properties
310 static QemuOptsList qemu_accel_opts
= {
312 .implied_opt_name
= "accel",
313 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
318 .type
= QEMU_OPT_STRING
,
319 .help
= "Select the type of accelerator",
323 .type
= QEMU_OPT_STRING
,
324 .help
= "Enable/disable multi-threaded TCG",
326 { /* end of list */ }
330 static QemuOptsList qemu_boot_opts
= {
332 .implied_opt_name
= "order",
334 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
338 .type
= QEMU_OPT_STRING
,
341 .type
= QEMU_OPT_STRING
,
344 .type
= QEMU_OPT_BOOL
,
347 .type
= QEMU_OPT_STRING
,
349 .name
= "splash-time",
350 .type
= QEMU_OPT_STRING
,
352 .name
= "reboot-timeout",
353 .type
= QEMU_OPT_STRING
,
356 .type
= QEMU_OPT_BOOL
,
362 static QemuOptsList qemu_add_fd_opts
= {
364 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
368 .type
= QEMU_OPT_NUMBER
,
369 .help
= "file descriptor of which a duplicate is added to fd set",
372 .type
= QEMU_OPT_NUMBER
,
373 .help
= "ID of the fd set to add fd to",
376 .type
= QEMU_OPT_STRING
,
377 .help
= "free-form string used to describe fd",
379 { /* end of list */ }
383 static QemuOptsList qemu_object_opts
= {
385 .implied_opt_name
= "qom-type",
386 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
392 static QemuOptsList qemu_tpmdev_opts
= {
394 .implied_opt_name
= "type",
395 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
397 /* options are defined in the TPM backends */
398 { /* end of list */ }
402 static QemuOptsList qemu_realtime_opts
= {
404 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
408 .type
= QEMU_OPT_BOOL
,
410 { /* end of list */ }
414 static QemuOptsList qemu_msg_opts
= {
416 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
420 .type
= QEMU_OPT_BOOL
,
422 { /* end of list */ }
426 static QemuOptsList qemu_name_opts
= {
428 .implied_opt_name
= "guest",
430 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
434 .type
= QEMU_OPT_STRING
,
435 .help
= "Sets the name of the guest.\n"
436 "This name will be displayed in the SDL window caption.\n"
437 "The name will also be used for the VNC server",
440 .type
= QEMU_OPT_STRING
,
441 .help
= "Sets the name of the QEMU process, as shown in top etc",
443 .name
= "debug-threads",
444 .type
= QEMU_OPT_BOOL
,
445 .help
= "When enabled, name the individual threads; defaults off.\n"
446 "NOTE: The thread names are for debugging and not a\n"
449 { /* End of list */ }
453 static QemuOptsList qemu_mem_opts
= {
455 .implied_opt_name
= "size",
456 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
461 .type
= QEMU_OPT_SIZE
,
465 .type
= QEMU_OPT_NUMBER
,
469 .type
= QEMU_OPT_SIZE
,
471 { /* end of list */ }
475 static QemuOptsList qemu_icount_opts
= {
477 .implied_opt_name
= "shift",
479 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
483 .type
= QEMU_OPT_STRING
,
486 .type
= QEMU_OPT_BOOL
,
489 .type
= QEMU_OPT_BOOL
,
492 .type
= QEMU_OPT_STRING
,
495 .type
= QEMU_OPT_STRING
,
497 .name
= "rrsnapshot",
498 .type
= QEMU_OPT_STRING
,
500 { /* end of list */ }
504 static QemuOptsList qemu_semihosting_config_opts
= {
505 .name
= "semihosting-config",
506 .implied_opt_name
= "enable",
507 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
511 .type
= QEMU_OPT_BOOL
,
514 .type
= QEMU_OPT_STRING
,
517 .type
= QEMU_OPT_STRING
,
519 { /* end of list */ }
523 static QemuOptsList qemu_fw_cfg_opts
= {
525 .implied_opt_name
= "name",
526 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
530 .type
= QEMU_OPT_STRING
,
531 .help
= "Sets the fw_cfg name of the blob to be inserted",
534 .type
= QEMU_OPT_STRING
,
535 .help
= "Sets the name of the file from which\n"
536 "the fw_cfg blob will be loaded",
539 .type
= QEMU_OPT_STRING
,
540 .help
= "Sets content of the blob to be inserted from a string",
542 { /* end of list */ }
547 * Get machine options
549 * Returns: machine options (never null).
551 QemuOpts
*qemu_get_machine_opts(void)
553 return qemu_find_opts_singleton("machine");
556 const char *qemu_get_vm_name(void)
561 static void res_free(void)
563 g_free(boot_splash_filedata
);
564 boot_splash_filedata
= NULL
;
567 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
569 const char *driver
= qemu_opt_get(opts
, "driver");
574 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
575 if (strcmp(default_list
[i
].driver
, driver
) != 0)
577 *(default_list
[i
].flag
) = 0;
582 /***********************************************************/
585 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
587 /* We use RUN_STATE__MAX but any invalid value will do */
588 static RunState vmstop_requested
= RUN_STATE__MAX
;
589 static QemuMutex vmstop_lock
;
594 } RunStateTransition
;
596 static const RunStateTransition runstate_transitions_def
[] = {
598 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
599 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
600 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
602 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
603 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
604 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
605 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
606 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
607 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
608 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
609 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
610 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
611 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
612 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
613 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
615 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
616 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
617 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
619 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
620 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
621 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
623 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
624 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
625 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
626 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
628 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
629 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
630 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
632 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
633 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
634 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
636 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
637 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
638 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
639 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
641 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
642 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
644 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
646 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
647 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
648 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
649 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
650 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
651 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
652 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
653 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
654 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
655 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
656 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
658 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
660 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
661 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
662 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
664 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
665 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
666 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
667 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
668 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
669 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
671 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
672 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
673 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
674 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
676 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
677 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
678 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
680 { RUN_STATE__MAX
, RUN_STATE__MAX
},
683 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
685 bool runstate_check(RunState state
)
687 return current_run_state
== state
;
690 bool runstate_store(char *str
, size_t size
)
692 const char *state
= RunState_lookup
[current_run_state
];
693 size_t len
= strlen(state
) + 1;
698 memcpy(str
, state
, len
);
702 static void runstate_init(void)
704 const RunStateTransition
*p
;
706 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
707 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
708 runstate_valid_transitions
[p
->from
][p
->to
] = true;
711 qemu_mutex_init(&vmstop_lock
);
714 /* This function will abort() on invalid state transitions */
715 void runstate_set(RunState new_state
)
717 assert(new_state
< RUN_STATE__MAX
);
719 if (current_run_state
== new_state
) {
723 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
724 error_report("invalid runstate transition: '%s' -> '%s'",
725 RunState_lookup
[current_run_state
],
726 RunState_lookup
[new_state
]);
729 trace_runstate_set(new_state
);
730 current_run_state
= new_state
;
733 int runstate_is_running(void)
735 return runstate_check(RUN_STATE_RUNNING
);
738 bool runstate_needs_reset(void)
740 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
741 runstate_check(RUN_STATE_SHUTDOWN
);
744 StatusInfo
*qmp_query_status(Error
**errp
)
746 StatusInfo
*info
= g_malloc0(sizeof(*info
));
748 info
->running
= runstate_is_running();
749 info
->singlestep
= singlestep
;
750 info
->status
= current_run_state
;
755 bool qemu_vmstop_requested(RunState
*r
)
757 qemu_mutex_lock(&vmstop_lock
);
758 *r
= vmstop_requested
;
759 vmstop_requested
= RUN_STATE__MAX
;
760 qemu_mutex_unlock(&vmstop_lock
);
761 return *r
< RUN_STATE__MAX
;
764 void qemu_system_vmstop_request_prepare(void)
766 qemu_mutex_lock(&vmstop_lock
);
769 void qemu_system_vmstop_request(RunState state
)
771 vmstop_requested
= state
;
772 qemu_mutex_unlock(&vmstop_lock
);
776 /***********************************************************/
777 /* real time host monotonic timer */
779 static time_t qemu_time(void)
781 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
784 /***********************************************************/
785 /* host time/date access */
786 void qemu_get_timedate(struct tm
*tm
, int offset
)
788 time_t ti
= qemu_time();
791 if (rtc_date_offset
== -1) {
795 localtime_r(&ti
, tm
);
797 ti
-= rtc_date_offset
;
802 int qemu_timedate_diff(struct tm
*tm
)
806 if (rtc_date_offset
== -1)
808 seconds
= mktimegm(tm
);
811 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
812 seconds
= mktime(&tmp
);
815 seconds
= mktimegm(tm
) + rtc_date_offset
;
817 return seconds
- qemu_time();
820 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
822 time_t rtc_start_date
;
825 if (!strcmp(startdate
, "now") && legacy
) {
826 rtc_date_offset
= -1;
828 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
836 } else if (sscanf(startdate
, "%d-%d-%d",
848 rtc_start_date
= mktimegm(&tm
);
849 if (rtc_start_date
== -1) {
851 error_report("invalid date format");
852 error_printf("valid formats: "
853 "'2006-06-17T16:01:21' or '2006-06-17'\n");
856 rtc_date_offset
= qemu_time() - rtc_start_date
;
860 static void configure_rtc(QemuOpts
*opts
)
864 value
= qemu_opt_get(opts
, "base");
866 if (!strcmp(value
, "utc")) {
868 } else if (!strcmp(value
, "localtime")) {
869 Error
*blocker
= NULL
;
871 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
872 "-rtc base=localtime");
873 replay_add_blocker(blocker
);
875 configure_rtc_date_offset(value
, 0);
878 value
= qemu_opt_get(opts
, "clock");
880 if (!strcmp(value
, "host")) {
881 rtc_clock
= QEMU_CLOCK_HOST
;
882 } else if (!strcmp(value
, "rt")) {
883 rtc_clock
= QEMU_CLOCK_REALTIME
;
884 } else if (!strcmp(value
, "vm")) {
885 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
887 error_report("invalid option value '%s'", value
);
891 value
= qemu_opt_get(opts
, "driftfix");
893 if (!strcmp(value
, "slew")) {
894 static GlobalProperty slew_lost_ticks
= {
895 .driver
= "mc146818rtc",
896 .property
= "lost_tick_policy",
900 qdev_prop_register_global(&slew_lost_ticks
);
901 } else if (!strcmp(value
, "none")) {
902 /* discard is default */
904 error_report("invalid option value '%s'", value
);
910 /***********************************************************/
911 /* Bluetooth support */
914 static struct HCIInfo
*hci_table
[MAX_NICS
];
916 struct HCIInfo
*qemu_next_hci(void)
918 if (cur_hci
== nb_hcis
)
921 return hci_table
[cur_hci
++];
924 static int bt_hci_parse(const char *str
)
929 if (nb_hcis
>= MAX_NICS
) {
930 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
943 bdaddr
.b
[5] = 0x56 + nb_hcis
;
944 hci
->bdaddr_set(hci
, bdaddr
.b
);
946 hci_table
[nb_hcis
++] = hci
;
951 static void bt_vhci_add(int vlan_id
)
953 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
956 error_report("warning: adding a VHCI to an empty scatternet %i",
959 bt_vhci_init(bt_new_hci(vlan
));
962 static struct bt_device_s
*bt_device_add(const char *opt
)
964 struct bt_scatternet_s
*vlan
;
966 char *endp
= strstr(opt
, ",vlan=");
967 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
970 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
973 vlan_id
= strtol(endp
+ 6, &endp
, 0);
975 error_report("unrecognised bluetooth vlan Id");
980 vlan
= qemu_find_bt_vlan(vlan_id
);
983 error_report("warning: adding a slave device to an empty scatternet %i",
986 if (!strcmp(devname
, "keyboard"))
987 return bt_keyboard_init(vlan
);
989 error_report("unsupported bluetooth device '%s'", devname
);
993 static int bt_parse(const char *opt
)
995 const char *endp
, *p
;
998 if (strstart(opt
, "hci", &endp
)) {
999 if (!*endp
|| *endp
== ',') {
1001 if (!strstart(endp
, ",vlan=", 0))
1004 return bt_hci_parse(opt
);
1006 } else if (strstart(opt
, "vhci", &endp
)) {
1007 if (!*endp
|| *endp
== ',') {
1009 if (strstart(endp
, ",vlan=", &p
)) {
1010 vlan
= strtol(p
, (char **) &endp
, 0);
1012 error_report("bad scatternet '%s'", p
);
1016 error_report("bad parameter '%s'", endp
+ 1);
1025 } else if (strstart(opt
, "device:", &endp
))
1026 return !bt_device_add(endp
);
1028 error_report("bad bluetooth parameter '%s'", opt
);
1032 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1034 /* FIXME: change this to true for 1.3 */
1035 if (qemu_opt_get_bool(opts
, "enable", false)) {
1036 #ifdef CONFIG_SECCOMP
1037 if (seccomp_start() < 0) {
1038 error_report("failed to install seccomp syscall filter "
1043 error_report("seccomp support is disabled");
1051 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1053 const char *proc_name
;
1055 if (qemu_opt_get(opts
, "debug-threads")) {
1056 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1058 qemu_name
= qemu_opt_get(opts
, "guest");
1060 proc_name
= qemu_opt_get(opts
, "process");
1062 os_set_proc_name(proc_name
);
1068 bool defaults_enabled(void)
1070 return has_defaults
;
1074 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1076 int fd
, dupfd
, flags
;
1078 const char *fd_opaque
= NULL
;
1081 fd
= qemu_opt_get_number(opts
, "fd", -1);
1082 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1083 fd_opaque
= qemu_opt_get(opts
, "opaque");
1086 error_report("fd option is required and must be non-negative");
1090 if (fd
<= STDERR_FILENO
) {
1091 error_report("fd cannot be a standard I/O stream");
1096 * All fds inherited across exec() necessarily have FD_CLOEXEC
1097 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1099 flags
= fcntl(fd
, F_GETFD
);
1100 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1101 error_report("fd is not valid or already in use");
1106 error_report("set option is required and must be non-negative");
1110 #ifdef F_DUPFD_CLOEXEC
1111 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1115 qemu_set_cloexec(dupfd
);
1119 error_report("error duplicating fd: %s", strerror(errno
));
1123 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1124 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1131 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1135 fd
= qemu_opt_get_number(opts
, "fd", -1);
1142 /***********************************************************/
1143 /* QEMU Block devices */
1145 #define HD_OPTS "media=disk"
1146 #define CDROM_OPTS "media=cdrom"
1148 #define PFLASH_OPTS ""
1152 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1154 BlockInterfaceType
*block_default_type
= opaque
;
1156 return drive_new(opts
, *block_default_type
) == NULL
;
1159 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1161 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1162 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1167 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1168 int index
, const char *optstr
)
1173 if (!enable
|| drive_get_by_index(type
, index
)) {
1177 opts
= drive_add(type
, index
, NULL
, optstr
);
1179 drive_enable_snapshot(NULL
, opts
, NULL
);
1182 dinfo
= drive_new(opts
, type
);
1186 dinfo
->is_default
= true;
1190 static QemuOptsList qemu_smp_opts
= {
1192 .implied_opt_name
= "cpus",
1193 .merge_lists
= true,
1194 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1198 .type
= QEMU_OPT_NUMBER
,
1201 .type
= QEMU_OPT_NUMBER
,
1204 .type
= QEMU_OPT_NUMBER
,
1207 .type
= QEMU_OPT_NUMBER
,
1210 .type
= QEMU_OPT_NUMBER
,
1212 { /*End of list */ }
1216 static void smp_parse(QemuOpts
*opts
)
1219 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1220 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1221 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1222 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1224 /* compute missing values, prefer sockets over cores over threads */
1225 if (cpus
== 0 || sockets
== 0) {
1226 sockets
= sockets
> 0 ? sockets
: 1;
1227 cores
= cores
> 0 ? cores
: 1;
1228 threads
= threads
> 0 ? threads
: 1;
1230 cpus
= cores
* threads
* sockets
;
1232 } else if (cores
== 0) {
1233 threads
= threads
> 0 ? threads
: 1;
1234 cores
= cpus
/ (sockets
* threads
);
1235 cores
= cores
> 0 ? cores
: 1;
1236 } else if (threads
== 0) {
1237 threads
= cpus
/ (cores
* sockets
);
1238 threads
= threads
> 0 ? threads
: 1;
1239 } else if (sockets
* cores
* threads
< cpus
) {
1240 error_report("cpu topology: "
1241 "sockets (%u) * cores (%u) * threads (%u) < "
1243 sockets
, cores
, threads
, cpus
);
1247 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1249 if (max_cpus
< cpus
) {
1250 error_report("maxcpus must be equal to or greater than smp");
1254 if (sockets
* cores
* threads
> max_cpus
) {
1255 error_report("cpu topology: "
1256 "sockets (%u) * cores (%u) * threads (%u) > "
1258 sockets
, cores
, threads
, max_cpus
);
1264 smp_threads
= threads
;
1268 Error
*blocker
= NULL
;
1269 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1270 replay_add_blocker(blocker
);
1274 static void realtime_init(void)
1277 if (os_mlock() < 0) {
1278 error_report("locking memory failed");
1285 static void configure_msg(QemuOpts
*opts
)
1287 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1290 /***********************************************************/
1293 typedef struct SemihostingConfig
{
1295 SemihostingTarget target
;
1298 const char *cmdline
; /* concatenated argv */
1299 } SemihostingConfig
;
1301 static SemihostingConfig semihosting
;
1303 bool semihosting_enabled(void)
1305 return semihosting
.enabled
;
1308 SemihostingTarget
semihosting_get_target(void)
1310 return semihosting
.target
;
1313 const char *semihosting_get_arg(int i
)
1315 if (i
>= semihosting
.argc
) {
1318 return semihosting
.argv
[i
];
1321 int semihosting_get_argc(void)
1323 return semihosting
.argc
;
1326 const char *semihosting_get_cmdline(void)
1328 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1329 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1331 return semihosting
.cmdline
;
1334 static int add_semihosting_arg(void *opaque
,
1335 const char *name
, const char *val
,
1338 SemihostingConfig
*s
= opaque
;
1339 if (strcmp(name
, "arg") == 0) {
1341 /* one extra element as g_strjoinv() expects NULL-terminated array */
1342 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1343 s
->argv
[s
->argc
- 1] = val
;
1344 s
->argv
[s
->argc
] = NULL
;
1349 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1350 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1355 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1357 /* split -append and initialize argv[1..n] */
1358 cmd_token
= strtok(g_strdup(cmd
), " ");
1360 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1361 cmd_token
= strtok(NULL
, " ");
1365 /* Now we still need this for compatibility with XEN. */
1366 bool has_igd_gfx_passthru
;
1367 static void igd_gfx_passthru(void)
1369 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1372 /***********************************************************/
1375 static int usb_device_add(const char *devname
)
1377 USBDevice
*dev
= NULL
;
1378 #ifndef CONFIG_LINUX
1382 if (!machine_usb(current_machine
)) {
1386 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1387 dev
= usbdevice_create(devname
);
1391 /* the other ones */
1392 #ifndef CONFIG_LINUX
1393 /* only the linux version is qdev-ified, usb-bsd still needs this */
1394 if (strstart(devname
, "host:", &p
)) {
1395 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1405 static int usb_device_del(const char *devname
)
1410 if (strstart(devname
, "host:", &p
)) {
1414 if (!machine_usb(current_machine
)) {
1418 p
= strchr(devname
, '.');
1421 bus_num
= strtoul(devname
, NULL
, 0);
1422 addr
= strtoul(p
+ 1, NULL
, 0);
1424 return usb_device_delete_addr(bus_num
, addr
);
1427 static int usb_parse(const char *cmdline
)
1430 r
= usb_device_add(cmdline
);
1432 error_report("could not add USB device '%s'", cmdline
);
1437 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1439 const char *devname
= qdict_get_str(qdict
, "devname");
1441 error_report("usb_add is deprecated, please use device_add instead");
1443 if (usb_device_add(devname
) < 0) {
1444 error_report("could not add USB device '%s'", devname
);
1448 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1450 const char *devname
= qdict_get_str(qdict
, "devname");
1452 error_report("usb_del is deprecated, please use device_del instead");
1454 if (usb_device_del(devname
) < 0) {
1455 error_report("could not delete USB device '%s'", devname
);
1459 /***********************************************************/
1460 /* machine registration */
1462 MachineState
*current_machine
;
1464 static MachineClass
*find_machine(const char *name
)
1466 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1467 MachineClass
*mc
= NULL
;
1469 for (el
= machines
; el
; el
= el
->next
) {
1470 MachineClass
*temp
= el
->data
;
1472 if (!strcmp(temp
->name
, name
)) {
1477 !strcmp(temp
->alias
, name
)) {
1483 g_slist_free(machines
);
1487 MachineClass
*find_default_machine(void)
1489 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1490 MachineClass
*mc
= NULL
;
1492 for (el
= machines
; el
; el
= el
->next
) {
1493 MachineClass
*temp
= el
->data
;
1495 if (temp
->is_default
) {
1501 g_slist_free(machines
);
1505 MachineInfoList
*qmp_query_machines(Error
**errp
)
1507 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1508 MachineInfoList
*mach_list
= NULL
;
1510 for (el
= machines
; el
; el
= el
->next
) {
1511 MachineClass
*mc
= el
->data
;
1512 MachineInfoList
*entry
;
1515 info
= g_malloc0(sizeof(*info
));
1516 if (mc
->is_default
) {
1517 info
->has_is_default
= true;
1518 info
->is_default
= true;
1522 info
->has_alias
= true;
1523 info
->alias
= g_strdup(mc
->alias
);
1526 info
->name
= g_strdup(mc
->name
);
1527 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1528 info
->hotpluggable_cpus
= mc
->has_hotpluggable_cpus
;
1530 entry
= g_malloc0(sizeof(*entry
));
1531 entry
->value
= info
;
1532 entry
->next
= mach_list
;
1536 g_slist_free(machines
);
1540 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1542 ObjectProperty
*prop
;
1543 ObjectPropertyIterator iter
;
1545 if (!qemu_opt_has_help_opt(opts
)) {
1549 object_property_iter_init(&iter
, OBJECT(machine
));
1550 while ((prop
= object_property_iter_next(&iter
))) {
1555 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1556 prop
->name
, prop
->type
);
1557 if (prop
->description
) {
1558 error_printf(" (%s)\n", prop
->description
);
1567 /***********************************************************/
1568 /* main execution loop */
1570 struct vm_change_state_entry
{
1571 VMChangeStateHandler
*cb
;
1573 QLIST_ENTRY (vm_change_state_entry
) entries
;
1576 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1578 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1581 VMChangeStateEntry
*e
;
1583 e
= g_malloc0(sizeof (*e
));
1587 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1591 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1593 QLIST_REMOVE (e
, entries
);
1597 void vm_state_notify(int running
, RunState state
)
1599 VMChangeStateEntry
*e
, *next
;
1601 trace_vm_state_notify(running
, state
);
1603 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1604 e
->cb(e
->opaque
, running
, state
);
1608 static ShutdownCause reset_requested
;
1609 static ShutdownCause shutdown_requested
;
1610 static int shutdown_signal
;
1611 static pid_t shutdown_pid
;
1612 static int powerdown_requested
;
1613 static int debug_requested
;
1614 static int suspend_requested
;
1615 static WakeupReason wakeup_reason
;
1616 static NotifierList powerdown_notifiers
=
1617 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1618 static NotifierList suspend_notifiers
=
1619 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1620 static NotifierList wakeup_notifiers
=
1621 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1622 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1624 ShutdownCause
qemu_shutdown_requested_get(void)
1626 return shutdown_requested
;
1629 ShutdownCause
qemu_reset_requested_get(void)
1631 return reset_requested
;
1634 static int qemu_shutdown_requested(void)
1636 return atomic_xchg(&shutdown_requested
, SHUTDOWN_CAUSE_NONE
);
1639 static void qemu_kill_report(void)
1641 if (!qtest_driver() && shutdown_signal
) {
1642 if (shutdown_pid
== 0) {
1643 /* This happens for eg ^C at the terminal, so it's worth
1644 * avoiding printing an odd message in that case.
1646 error_report("terminating on signal %d", shutdown_signal
);
1648 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1650 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1651 shutdown_signal
, shutdown_pid
,
1652 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1653 g_free(shutdown_cmd
);
1655 shutdown_signal
= 0;
1659 static ShutdownCause
qemu_reset_requested(void)
1661 ShutdownCause r
= reset_requested
;
1663 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1664 reset_requested
= SHUTDOWN_CAUSE_NONE
;
1667 return SHUTDOWN_CAUSE_NONE
;
1670 static int qemu_suspend_requested(void)
1672 int r
= suspend_requested
;
1673 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1674 suspend_requested
= 0;
1680 static WakeupReason
qemu_wakeup_requested(void)
1682 return wakeup_reason
;
1685 static int qemu_powerdown_requested(void)
1687 int r
= powerdown_requested
;
1688 powerdown_requested
= 0;
1692 static int qemu_debug_requested(void)
1694 int r
= debug_requested
;
1695 debug_requested
= 0;
1700 * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE.
1702 void qemu_system_reset(ShutdownCause reason
)
1706 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1708 cpu_synchronize_all_states();
1710 if (mc
&& mc
->reset
) {
1713 qemu_devices_reset();
1716 qapi_event_send_reset(shutdown_caused_by_guest(reason
),
1719 cpu_synchronize_all_post_reset();
1722 void qemu_system_guest_panicked(GuestPanicInformation
*info
)
1724 qemu_log_mask(LOG_GUEST_ERROR
, "Guest crashed\n");
1727 current_cpu
->crash_occurred
= true;
1729 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
,
1730 !!info
, info
, &error_abort
);
1731 vm_stop(RUN_STATE_GUEST_PANICKED
);
1733 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1734 !!info
, info
, &error_abort
);
1735 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC
);
1739 if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_HYPER_V
) {
1740 qemu_log_mask(LOG_GUEST_ERROR
, "HV crash parameters: (%#"PRIx64
1741 " %#"PRIx64
" %#"PRIx64
" %#"PRIx64
" %#"PRIx64
")\n",
1742 info
->u
.hyper_v
.arg1
,
1743 info
->u
.hyper_v
.arg2
,
1744 info
->u
.hyper_v
.arg3
,
1745 info
->u
.hyper_v
.arg4
,
1746 info
->u
.hyper_v
.arg5
);
1748 qapi_free_GuestPanicInformation(info
);
1752 void qemu_system_reset_request(ShutdownCause reason
)
1755 shutdown_requested
= reason
;
1757 reset_requested
= reason
;
1760 qemu_notify_event();
1763 static void qemu_system_suspend(void)
1766 notifier_list_notify(&suspend_notifiers
, NULL
);
1767 runstate_set(RUN_STATE_SUSPENDED
);
1768 qapi_event_send_suspend(&error_abort
);
1771 void qemu_system_suspend_request(void)
1773 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1776 suspend_requested
= 1;
1778 qemu_notify_event();
1781 void qemu_register_suspend_notifier(Notifier
*notifier
)
1783 notifier_list_add(&suspend_notifiers
, notifier
);
1786 void qemu_system_wakeup_request(WakeupReason reason
)
1788 trace_system_wakeup_request(reason
);
1790 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1793 if (!(wakeup_reason_mask
& (1 << reason
))) {
1796 runstate_set(RUN_STATE_RUNNING
);
1797 wakeup_reason
= reason
;
1798 qemu_notify_event();
1801 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1804 wakeup_reason_mask
|= (1 << reason
);
1806 wakeup_reason_mask
&= ~(1 << reason
);
1810 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1812 notifier_list_add(&wakeup_notifiers
, notifier
);
1815 void qemu_system_killed(int signal
, pid_t pid
)
1817 shutdown_signal
= signal
;
1821 /* Cannot call qemu_system_shutdown_request directly because
1822 * we are in a signal handler.
1824 shutdown_requested
= SHUTDOWN_CAUSE_HOST_SIGNAL
;
1825 qemu_notify_event();
1828 void qemu_system_shutdown_request(ShutdownCause reason
)
1830 trace_qemu_system_shutdown_request(reason
);
1831 replay_shutdown_request(reason
);
1832 shutdown_requested
= reason
;
1833 qemu_notify_event();
1836 static void qemu_system_powerdown(void)
1838 qapi_event_send_powerdown(&error_abort
);
1839 notifier_list_notify(&powerdown_notifiers
, NULL
);
1842 void qemu_system_powerdown_request(void)
1844 trace_qemu_system_powerdown_request();
1845 powerdown_requested
= 1;
1846 qemu_notify_event();
1849 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1851 notifier_list_add(&powerdown_notifiers
, notifier
);
1854 void qemu_system_debug_request(void)
1856 debug_requested
= 1;
1857 qemu_notify_event();
1860 static bool main_loop_should_exit(void)
1863 ShutdownCause request
;
1865 if (qemu_debug_requested()) {
1866 vm_stop(RUN_STATE_DEBUG
);
1868 if (qemu_suspend_requested()) {
1869 qemu_system_suspend();
1871 request
= qemu_shutdown_requested();
1874 qapi_event_send_shutdown(shutdown_caused_by_guest(request
),
1877 vm_stop(RUN_STATE_SHUTDOWN
);
1882 request
= qemu_reset_requested();
1885 qemu_system_reset(request
);
1887 if (!runstate_check(RUN_STATE_RUNNING
) &&
1888 !runstate_check(RUN_STATE_INMIGRATE
)) {
1889 runstate_set(RUN_STATE_PRELAUNCH
);
1892 if (qemu_wakeup_requested()) {
1894 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
1895 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1896 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1898 qapi_event_send_wakeup(&error_abort
);
1900 if (qemu_powerdown_requested()) {
1901 qemu_system_powerdown();
1903 if (qemu_vmstop_requested(&r
)) {
1909 static void main_loop(void)
1911 #ifdef CONFIG_PROFILER
1915 #ifdef CONFIG_PROFILER
1916 ti
= profile_getclock();
1918 main_loop_wait(false);
1919 #ifdef CONFIG_PROFILER
1920 dev_time
+= profile_getclock() - ti
;
1922 } while (!main_loop_should_exit());
1925 static void version(void)
1927 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1928 QEMU_COPYRIGHT
"\n");
1931 static void help(int exitcode
)
1934 printf("usage: %s [options] [disk_image]\n\n"
1935 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1936 error_get_progname());
1938 #define QEMU_OPTIONS_GENERATE_HELP
1939 #include "qemu-options-wrapper.h"
1941 printf("\nDuring emulation, the following keys are useful:\n"
1942 "ctrl-alt-f toggle full screen\n"
1943 "ctrl-alt-n switch to virtual console 'n'\n"
1944 "ctrl-alt toggle mouse and keyboard grab\n"
1946 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1951 #define HAS_ARG 0x0001
1953 typedef struct QEMUOption
{
1960 static const QEMUOption qemu_options
[] = {
1961 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1962 #define QEMU_OPTIONS_GENERATE_OPTIONS
1963 #include "qemu-options-wrapper.h"
1967 typedef struct VGAInterfaceInfo
{
1968 const char *opt_name
; /* option name */
1969 const char *name
; /* human-readable name */
1970 /* Class names indicating that support is available.
1971 * If no class is specified, the interface is always available */
1972 const char *class_names
[2];
1975 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1981 .name
= "standard VGA",
1982 .class_names
= { "VGA", "isa-vga" },
1985 .opt_name
= "cirrus",
1986 .name
= "Cirrus VGA",
1987 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1990 .opt_name
= "vmware",
1991 .name
= "VMWare SVGA",
1992 .class_names
= { "vmware-svga" },
1995 .opt_name
= "virtio",
1996 .name
= "Virtio VGA",
1997 .class_names
= { "virtio-vga" },
2002 .class_names
= { "qxl-vga" },
2006 .name
= "TCX framebuffer",
2007 .class_names
= { "SUNW,tcx" },
2011 .name
= "CG3 framebuffer",
2012 .class_names
= { "cgthree" },
2015 .opt_name
= "xenfb",
2019 static bool vga_interface_available(VGAInterfaceType t
)
2021 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2023 assert(t
< VGA_TYPE_MAX
);
2024 return !ti
->class_names
[0] ||
2025 object_class_by_name(ti
->class_names
[0]) ||
2026 object_class_by_name(ti
->class_names
[1]);
2029 static void select_vgahw(const char *p
)
2034 assert(vga_interface_type
== VGA_NONE
);
2035 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2036 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2037 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2038 if (!vga_interface_available(t
)) {
2039 error_report("%s not available", ti
->name
);
2042 vga_interface_type
= t
;
2046 if (t
== VGA_TYPE_MAX
) {
2048 error_report("unknown vga type: %s", p
);
2052 const char *nextopt
;
2054 if (strstart(opts
, ",retrace=", &nextopt
)) {
2056 if (strstart(opts
, "dumb", &nextopt
))
2057 vga_retrace_method
= VGA_RETRACE_DUMB
;
2058 else if (strstart(opts
, "precise", &nextopt
))
2059 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2060 else goto invalid_vga
;
2061 } else goto invalid_vga
;
2066 typedef enum DisplayType
{
2076 static DisplayType
select_display(const char *p
)
2079 DisplayType display
= DT_DEFAULT
;
2081 if (strstart(p
, "sdl", &opts
)) {
2085 const char *nextopt
;
2087 if (strstart(opts
, ",frame=", &nextopt
)) {
2089 if (strstart(opts
, "on", &nextopt
)) {
2091 } else if (strstart(opts
, "off", &nextopt
)) {
2094 goto invalid_sdl_args
;
2096 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2098 if (strstart(opts
, "on", &nextopt
)) {
2100 } else if (strstart(opts
, "off", &nextopt
)) {
2103 goto invalid_sdl_args
;
2105 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2107 if (strstart(opts
, "on", &nextopt
)) {
2109 } else if (strstart(opts
, "off", &nextopt
)) {
2112 goto invalid_sdl_args
;
2114 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2116 if (strstart(opts
, "on", &nextopt
)) {
2118 } else if (strstart(opts
, "off", &nextopt
)) {
2121 goto invalid_sdl_args
;
2123 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2125 if (strstart(opts
, "on", &nextopt
)) {
2127 } else if (strstart(opts
, "off", &nextopt
)) {
2130 goto invalid_sdl_args
;
2134 error_report("invalid SDL option string");
2140 error_report("SDL support is disabled");
2143 } else if (strstart(p
, "vnc", &opts
)) {
2145 vnc_parse(opts
+ 1, &error_fatal
);
2147 error_report("VNC requires a display argument vnc=<display>");
2150 } else if (strstart(p
, "egl-headless", &opts
)) {
2151 #ifdef CONFIG_OPENGL_DMABUF
2156 fprintf(stderr
, "egl support is disabled\n");
2159 } else if (strstart(p
, "curses", &opts
)) {
2160 #ifdef CONFIG_CURSES
2161 display
= DT_CURSES
;
2163 error_report("curses support is disabled");
2166 } else if (strstart(p
, "gtk", &opts
)) {
2170 const char *nextopt
;
2172 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2174 if (strstart(opts
, "on", &nextopt
)) {
2175 grab_on_hover
= true;
2176 } else if (strstart(opts
, "off", &nextopt
)) {
2177 grab_on_hover
= false;
2179 goto invalid_gtk_args
;
2181 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2183 if (strstart(opts
, "on", &nextopt
)) {
2185 } else if (strstart(opts
, "off", &nextopt
)) {
2188 goto invalid_gtk_args
;
2192 error_report("invalid GTK option string");
2198 error_report("GTK support is disabled");
2201 } else if (strstart(p
, "none", &opts
)) {
2204 error_report("unknown display type");
2211 static int balloon_parse(const char *arg
)
2215 if (strcmp(arg
, "none") == 0) {
2219 if (!strncmp(arg
, "virtio", 6)) {
2220 if (arg
[6] == ',') {
2221 /* have params -> parse them */
2222 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2227 /* create empty opts */
2228 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2231 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2238 char *qemu_find_file(int type
, const char *name
)
2244 /* Try the name as a straight path first */
2245 if (access(name
, R_OK
) == 0) {
2246 trace_load_file(name
, name
);
2247 return g_strdup(name
);
2251 case QEMU_FILE_TYPE_BIOS
:
2254 case QEMU_FILE_TYPE_KEYMAP
:
2255 subdir
= "keymaps/";
2261 for (i
= 0; i
< data_dir_idx
; i
++) {
2262 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2263 if (access(buf
, R_OK
) == 0) {
2264 trace_load_file(name
, buf
);
2272 static inline bool nonempty_str(const char *str
)
2277 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2281 const char *name
, *file
, *str
;
2282 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2284 if (fw_cfg
== NULL
) {
2285 error_report("fw_cfg device not available");
2288 name
= qemu_opt_get(opts
, "name");
2289 file
= qemu_opt_get(opts
, "file");
2290 str
= qemu_opt_get(opts
, "string");
2292 /* we need name and either a file or the content string */
2293 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2294 error_report("invalid argument(s)");
2297 if (nonempty_str(file
) && nonempty_str(str
)) {
2298 error_report("file and string are mutually exclusive");
2301 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2302 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2305 if (strncmp(name
, "opt/", 4) != 0) {
2306 error_report("warning: externally provided fw_cfg item names "
2307 "should be prefixed with \"opt/\"");
2309 if (nonempty_str(str
)) {
2310 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2311 buf
= g_memdup(str
, size
);
2313 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2314 error_report("can't load %s", file
);
2318 /* For legacy, keep user files in a specific global order. */
2319 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2320 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2321 fw_cfg_reset_order_override(fw_cfg
);
2325 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2327 return qdev_device_help(opts
);
2330 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2335 dev
= qdev_device_add(opts
, &err
);
2337 error_report_err(err
);
2340 object_unref(OBJECT(dev
));
2344 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2346 Error
*local_err
= NULL
;
2348 qemu_chr_new_from_opts(opts
, &local_err
);
2350 error_report_err(local_err
);
2356 #ifdef CONFIG_VIRTFS
2357 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2359 return qemu_fsdev_add(opts
);
2363 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2366 const char *chardev
;
2370 mode
= qemu_opt_get(opts
, "mode");
2374 if (strcmp(mode
, "readline") == 0) {
2375 flags
= MONITOR_USE_READLINE
;
2376 } else if (strcmp(mode
, "control") == 0) {
2377 flags
= MONITOR_USE_CONTROL
;
2379 error_report("unknown monitor mode \"%s\"", mode
);
2383 if (qemu_opt_get_bool(opts
, "pretty", 0))
2384 flags
|= MONITOR_USE_PRETTY
;
2386 if (qemu_opt_get_bool(opts
, "default", 0)) {
2387 error_report("option 'default' does nothing and is deprecated");
2390 chardev
= qemu_opt_get(opts
, "chardev");
2391 chr
= qemu_chr_find(chardev
);
2393 error_report("chardev \"%s\" not found", chardev
);
2397 monitor_init(chr
, flags
);
2401 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2403 static int monitor_device_index
= 0;
2408 if (strstart(optarg
, "chardev:", &p
)) {
2409 snprintf(label
, sizeof(label
), "%s", p
);
2411 snprintf(label
, sizeof(label
), "compat_monitor%d",
2412 monitor_device_index
);
2413 opts
= qemu_chr_parse_compat(label
, optarg
);
2415 error_report("parse error: %s", optarg
);
2420 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2421 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2422 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2423 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2424 monitor_device_index
++;
2427 struct device_config
{
2429 DEV_USB
, /* -usbdevice */
2431 DEV_SERIAL
, /* -serial */
2432 DEV_PARALLEL
, /* -parallel */
2433 DEV_VIRTCON
, /* -virtioconsole */
2434 DEV_DEBUGCON
, /* -debugcon */
2435 DEV_GDB
, /* -gdb, -s */
2436 DEV_SCLP
, /* s390 sclp */
2438 const char *cmdline
;
2440 QTAILQ_ENTRY(device_config
) next
;
2443 static QTAILQ_HEAD(, device_config
) device_configs
=
2444 QTAILQ_HEAD_INITIALIZER(device_configs
);
2446 static void add_device_config(int type
, const char *cmdline
)
2448 struct device_config
*conf
;
2450 conf
= g_malloc0(sizeof(*conf
));
2452 conf
->cmdline
= cmdline
;
2453 loc_save(&conf
->loc
);
2454 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2457 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2459 struct device_config
*conf
;
2462 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2463 if (conf
->type
!= type
)
2465 loc_push_restore(&conf
->loc
);
2466 rc
= func(conf
->cmdline
);
2467 loc_pop(&conf
->loc
);
2475 static int serial_parse(const char *devname
)
2477 static int index
= 0;
2480 if (strcmp(devname
, "none") == 0)
2482 if (index
== MAX_SERIAL_PORTS
) {
2483 error_report("too many serial ports");
2486 snprintf(label
, sizeof(label
), "serial%d", index
);
2487 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2488 if (!serial_hds
[index
]) {
2489 error_report("could not connect serial device"
2490 " to character backend '%s'", devname
);
2497 static int parallel_parse(const char *devname
)
2499 static int index
= 0;
2502 if (strcmp(devname
, "none") == 0)
2504 if (index
== MAX_PARALLEL_PORTS
) {
2505 error_report("too many parallel ports");
2508 snprintf(label
, sizeof(label
), "parallel%d", index
);
2509 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2510 if (!parallel_hds
[index
]) {
2511 error_report("could not connect parallel device"
2512 " to character backend '%s'", devname
);
2519 static int virtcon_parse(const char *devname
)
2521 QemuOptsList
*device
= qemu_find_opts("device");
2522 static int index
= 0;
2524 QemuOpts
*bus_opts
, *dev_opts
;
2526 if (strcmp(devname
, "none") == 0)
2528 if (index
== MAX_VIRTIO_CONSOLES
) {
2529 error_report("too many virtio consoles");
2533 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2534 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2536 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2537 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2539 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2540 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2541 if (!virtcon_hds
[index
]) {
2542 error_report("could not connect virtio console"
2543 " to character backend '%s'", devname
);
2546 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2552 static int sclp_parse(const char *devname
)
2554 QemuOptsList
*device
= qemu_find_opts("device");
2555 static int index
= 0;
2559 if (strcmp(devname
, "none") == 0) {
2562 if (index
== MAX_SCLP_CONSOLES
) {
2563 error_report("too many sclp consoles");
2567 assert(arch_type
== QEMU_ARCH_S390X
);
2569 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2570 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2572 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2573 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2574 if (!sclp_hds
[index
]) {
2575 error_report("could not connect sclp console"
2576 " to character backend '%s'", devname
);
2579 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2585 static int debugcon_parse(const char *devname
)
2589 if (!qemu_chr_new("debugcon", devname
)) {
2592 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2594 error_report("already have a debugcon device");
2597 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2598 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2602 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2604 const MachineClass
*mc1
= a
, *mc2
= b
;
2607 if (mc1
->family
== NULL
) {
2608 if (mc2
->family
== NULL
) {
2609 /* Compare standalone machine types against each other; they sort
2610 * in increasing order.
2612 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2613 object_class_get_name(OBJECT_CLASS(mc2
)));
2616 /* Standalone machine types sort after families. */
2620 if (mc2
->family
== NULL
) {
2621 /* Families sort before standalone machine types. */
2625 /* Families sort between each other alphabetically increasingly. */
2626 res
= strcmp(mc1
->family
, mc2
->family
);
2631 /* Within the same family, machine types sort in decreasing order. */
2632 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2633 object_class_get_name(OBJECT_CLASS(mc1
)));
2636 static MachineClass
*machine_parse(const char *name
)
2638 MachineClass
*mc
= NULL
;
2639 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2642 mc
= find_machine(name
);
2645 g_slist_free(machines
);
2648 if (name
&& !is_help_option(name
)) {
2649 error_report("unsupported machine type");
2650 error_printf("Use -machine help to list supported machines\n");
2652 printf("Supported machines are:\n");
2653 machines
= g_slist_sort(machines
, machine_class_cmp
);
2654 for (el
= machines
; el
; el
= el
->next
) {
2655 MachineClass
*mc
= el
->data
;
2657 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2659 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2660 mc
->is_default
? " (default)" : "");
2664 g_slist_free(machines
);
2665 exit(!name
|| !is_help_option(name
));
2668 void qemu_add_exit_notifier(Notifier
*notify
)
2670 notifier_list_add(&exit_notifiers
, notify
);
2673 void qemu_remove_exit_notifier(Notifier
*notify
)
2675 notifier_remove(notify
);
2678 static void qemu_run_exit_notifiers(void)
2680 notifier_list_notify(&exit_notifiers
, NULL
);
2683 static bool machine_init_done
;
2685 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2687 notifier_list_add(&machine_init_done_notifiers
, notify
);
2688 if (machine_init_done
) {
2689 notify
->notify(notify
, NULL
);
2693 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2695 notifier_remove(notify
);
2698 static void qemu_run_machine_init_done_notifiers(void)
2700 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2701 machine_init_done
= true;
2704 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2705 const char **poptarg
, int *poptind
)
2707 const QEMUOption
*popt
;
2708 int optind
= *poptind
;
2709 char *r
= argv
[optind
];
2712 loc_set_cmdline(argv
, optind
, 1);
2714 /* Treat --foo the same as -foo. */
2717 popt
= qemu_options
;
2720 error_report("invalid option");
2723 if (!strcmp(popt
->name
, r
+ 1))
2727 if (popt
->flags
& HAS_ARG
) {
2728 if (optind
>= argc
) {
2729 error_report("requires an argument");
2732 optarg
= argv
[optind
++];
2733 loc_set_cmdline(argv
, optind
- 2, 2);
2744 static MachineClass
*select_machine(void)
2746 MachineClass
*machine_class
= find_default_machine();
2751 loc_push_none(&loc
);
2753 opts
= qemu_get_machine_opts();
2754 qemu_opts_loc_restore(opts
);
2756 optarg
= qemu_opt_get(opts
, "type");
2758 machine_class
= machine_parse(optarg
);
2761 if (!machine_class
) {
2762 error_report("No machine specified, and there is no default");
2763 error_printf("Use -machine help to list supported machines\n");
2768 return machine_class
;
2771 static int machine_set_property(void *opaque
,
2772 const char *name
, const char *value
,
2775 Object
*obj
= OBJECT(opaque
);
2776 Error
*local_err
= NULL
;
2779 if (strcmp(name
, "type") == 0) {
2783 qom_name
= g_strdup(name
);
2784 for (p
= qom_name
; *p
; p
++) {
2790 object_property_parse(obj
, value
, qom_name
, &local_err
);
2794 error_report_err(local_err
);
2803 * Initial object creation happens before all other
2804 * QEMU data types are created. The majority of objects
2805 * can be created at this point. The rng-egd object
2806 * cannot be created here, as it depends on the chardev
2809 static bool object_create_initial(const char *type
)
2811 if (g_str_equal(type
, "rng-egd")) {
2816 * return false for concrete netfilters since
2817 * they depend on netdevs already existing
2819 if (g_str_equal(type
, "filter-buffer") ||
2820 g_str_equal(type
, "filter-dump") ||
2821 g_str_equal(type
, "filter-mirror") ||
2822 g_str_equal(type
, "filter-redirector") ||
2823 g_str_equal(type
, "colo-compare") ||
2824 g_str_equal(type
, "filter-rewriter") ||
2825 g_str_equal(type
, "filter-replay")) {
2829 /* Memory allocation by backends needs to be done
2830 * after configure_accelerator() (due to the tcg_enabled()
2831 * checks at memory_region_init_*()).
2833 * Also, allocation of large amounts of memory may delay
2834 * chardev initialization for too long, and trigger timeouts
2835 * on software that waits for a monitor socket to be created
2838 if (g_str_has_prefix(type
, "memory-backend-")) {
2847 * The remainder of object creation happens after the
2848 * creation of chardev, fsdev, net clients and device data types.
2850 static bool object_create_delayed(const char *type
)
2852 return !object_create_initial(type
);
2856 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2860 const char *mem_str
;
2861 const char *maxmem_str
, *slots_str
;
2862 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2863 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2866 loc_push_none(&loc
);
2867 qemu_opts_loc_restore(opts
);
2870 mem_str
= qemu_opt_get(opts
, "size");
2873 error_report("missing 'size' option value");
2877 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2879 /* Fix up legacy suffix-less format */
2880 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2881 uint64_t overflow_check
= sz
;
2884 if ((sz
>> 20) != overflow_check
) {
2885 error_report("too large 'size' option value");
2891 /* backward compatibility behaviour for case "-m 0" */
2893 sz
= default_ram_size
;
2896 sz
= QEMU_ALIGN_UP(sz
, 8192);
2898 if (ram_size
!= sz
) {
2899 error_report("ram size too large");
2903 /* store value for the future use */
2904 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2905 *maxram_size
= ram_size
;
2907 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2908 slots_str
= qemu_opt_get(opts
, "slots");
2909 if (maxmem_str
&& slots_str
) {
2912 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2913 slots
= qemu_opt_get_number(opts
, "slots", 0);
2914 if (sz
< ram_size
) {
2915 error_report("invalid value of -m option maxmem: "
2916 "maximum memory size (0x%" PRIx64
") must be at least "
2917 "the initial memory size (0x" RAM_ADDR_FMT
")",
2920 } else if (sz
> ram_size
) {
2922 error_report("invalid value of -m option: maxmem was "
2923 "specified, but no hotplug slots were specified");
2927 error_report("invalid value of -m option maxmem: "
2928 "memory slots were specified but maximum memory size "
2929 "(0x%" PRIx64
") is equal to the initial memory size "
2930 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2936 } else if ((!maxmem_str
&& slots_str
) ||
2937 (maxmem_str
&& !slots_str
)) {
2938 error_report("invalid -m option value: missing "
2939 "'%s' option", slots_str
? "maxmem" : "slots");
2946 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2950 g
= g_malloc0(sizeof(*g
));
2951 g
->driver
= qemu_opt_get(opts
, "driver");
2952 g
->property
= qemu_opt_get(opts
, "property");
2953 g
->value
= qemu_opt_get(opts
, "value");
2954 g
->user_provided
= true;
2955 g
->errp
= &error_fatal
;
2956 qdev_prop_register_global(g
);
2960 static int qemu_read_default_config_file(void)
2964 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2965 if (ret
< 0 && ret
!= -ENOENT
) {
2972 int main(int argc
, char **argv
, char **envp
)
2975 int snapshot
, linux_boot
;
2976 const char *initrd_filename
;
2977 const char *kernel_filename
, *kernel_cmdline
;
2978 const char *boot_order
= NULL
;
2979 const char *boot_once
= NULL
;
2981 int cyls
, heads
, secs
, translation
;
2982 QemuOpts
*opts
, *machine_opts
;
2983 QemuOpts
*hda_opts
= NULL
, *icount_opts
= NULL
, *accel_opts
= NULL
;
2984 QemuOptsList
*olist
;
2987 const char *loadvm
= NULL
;
2988 MachineClass
*machine_class
;
2989 const char *cpu_model
;
2990 const char *vga_model
= NULL
;
2991 const char *qtest_chrdev
= NULL
;
2992 const char *qtest_log
= NULL
;
2993 const char *pid_file
= NULL
;
2994 const char *incoming
= NULL
;
2995 bool defconfig
= true;
2996 bool userconfig
= true;
2997 bool nographic
= false;
2998 DisplayType display_type
= DT_DEFAULT
;
2999 int display_remote
= 0;
3000 const char *log_mask
= NULL
;
3001 const char *log_file
= NULL
;
3002 char *trace_file
= NULL
;
3003 ram_addr_t maxram_size
;
3004 uint64_t ram_slots
= 0;
3005 FILE *vmstate_dump_file
= NULL
;
3006 Error
*main_loop_err
= NULL
;
3008 bool list_data_dirs
= false;
3009 typedef struct BlockdevOptions_queue
{
3010 BlockdevOptions
*bdo
;
3012 QSIMPLEQ_ENTRY(BlockdevOptions_queue
) entry
;
3013 } BlockdevOptions_queue
;
3014 QSIMPLEQ_HEAD(, BlockdevOptions_queue
) bdo_queue
3015 = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
3017 module_call_init(MODULE_INIT_TRACE
);
3019 qemu_init_cpu_list();
3020 qemu_init_cpu_loop();
3021 qemu_mutex_lock_iothread();
3023 atexit(qemu_run_exit_notifiers
);
3024 error_set_progname(argv
[0]);
3025 qemu_init_exec_dir(argv
[0]);
3027 module_call_init(MODULE_INIT_QOM
);
3028 monitor_init_qmp_commands();
3030 qemu_add_opts(&qemu_drive_opts
);
3031 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3032 qemu_add_drive_opts(&qemu_common_drive_opts
);
3033 qemu_add_drive_opts(&qemu_drive_opts
);
3034 qemu_add_drive_opts(&bdrv_runtime_opts
);
3035 qemu_add_opts(&qemu_chardev_opts
);
3036 qemu_add_opts(&qemu_device_opts
);
3037 qemu_add_opts(&qemu_netdev_opts
);
3038 qemu_add_opts(&qemu_net_opts
);
3039 qemu_add_opts(&qemu_rtc_opts
);
3040 qemu_add_opts(&qemu_global_opts
);
3041 qemu_add_opts(&qemu_mon_opts
);
3042 qemu_add_opts(&qemu_trace_opts
);
3043 qemu_add_opts(&qemu_option_rom_opts
);
3044 qemu_add_opts(&qemu_machine_opts
);
3045 qemu_add_opts(&qemu_accel_opts
);
3046 qemu_add_opts(&qemu_mem_opts
);
3047 qemu_add_opts(&qemu_smp_opts
);
3048 qemu_add_opts(&qemu_boot_opts
);
3049 qemu_add_opts(&qemu_sandbox_opts
);
3050 qemu_add_opts(&qemu_add_fd_opts
);
3051 qemu_add_opts(&qemu_object_opts
);
3052 qemu_add_opts(&qemu_tpmdev_opts
);
3053 qemu_add_opts(&qemu_realtime_opts
);
3054 qemu_add_opts(&qemu_msg_opts
);
3055 qemu_add_opts(&qemu_name_opts
);
3056 qemu_add_opts(&qemu_numa_opts
);
3057 qemu_add_opts(&qemu_icount_opts
);
3058 qemu_add_opts(&qemu_semihosting_config_opts
);
3059 qemu_add_opts(&qemu_fw_cfg_opts
);
3060 module_call_init(MODULE_INIT_OPTS
);
3064 if (qcrypto_init(&err
) < 0) {
3065 error_reportf_err(err
, "cannot initialize crypto: ");
3068 rtc_clock
= QEMU_CLOCK_HOST
;
3070 QLIST_INIT (&vm_change_state_head
);
3071 os_setup_early_signal_handling();
3075 cyls
= heads
= secs
= 0;
3076 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3080 bdrv_init_with_whitelist();
3084 /* first pass of option parsing */
3086 while (optind
< argc
) {
3087 if (argv
[optind
][0] != '-') {
3091 const QEMUOption
*popt
;
3093 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3094 switch (popt
->index
) {
3095 case QEMU_OPTION_nodefconfig
:
3098 case QEMU_OPTION_nouserconfig
:
3105 if (defconfig
&& userconfig
) {
3106 if (qemu_read_default_config_file() < 0) {
3111 /* second pass of option parsing */
3116 if (argv
[optind
][0] != '-') {
3117 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3119 const QEMUOption
*popt
;
3121 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3122 if (!(popt
->arch_mask
& arch_type
)) {
3123 error_report("Option not supported for this target");
3126 switch(popt
->index
) {
3127 case QEMU_OPTION_no_kvm_irqchip
: {
3128 olist
= qemu_find_opts("machine");
3129 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3132 case QEMU_OPTION_cpu
:
3133 /* hw initialization will check this */
3136 case QEMU_OPTION_hda
:
3140 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3142 snprintf(buf
, sizeof(buf
),
3143 "%s,cyls=%d,heads=%d,secs=%d%s",
3144 HD_OPTS
, cyls
, heads
, secs
,
3145 translation
== BIOS_ATA_TRANSLATION_LBA
?
3147 translation
== BIOS_ATA_TRANSLATION_NONE
?
3148 ",trans=none" : "");
3149 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3152 case QEMU_OPTION_hdb
:
3153 case QEMU_OPTION_hdc
:
3154 case QEMU_OPTION_hdd
:
3155 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3158 case QEMU_OPTION_blockdev
:
3161 BlockdevOptions_queue
*bdo
;
3163 v
= qobject_input_visitor_new_str(optarg
, "driver", &err
);
3165 error_report_err(err
);
3169 bdo
= g_new(BlockdevOptions_queue
, 1);
3170 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
3173 loc_save(&bdo
->loc
);
3174 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
3177 case QEMU_OPTION_drive
:
3178 if (drive_def(optarg
) == NULL
) {
3182 case QEMU_OPTION_set
:
3183 if (qemu_set_option(optarg
) != 0)
3186 case QEMU_OPTION_global
:
3187 if (qemu_global_option(optarg
) != 0)
3190 case QEMU_OPTION_mtdblock
:
3191 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3193 case QEMU_OPTION_sd
:
3194 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3196 case QEMU_OPTION_pflash
:
3197 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3199 case QEMU_OPTION_snapshot
:
3202 case QEMU_OPTION_hdachs
:
3206 cyls
= strtol(p
, (char **)&p
, 0);
3207 if (cyls
< 1 || cyls
> 16383)
3212 heads
= strtol(p
, (char **)&p
, 0);
3213 if (heads
< 1 || heads
> 16)
3218 secs
= strtol(p
, (char **)&p
, 0);
3219 if (secs
< 1 || secs
> 63)
3223 if (!strcmp(p
, "large")) {
3224 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3225 } else if (!strcmp(p
, "rechs")) {
3226 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3227 } else if (!strcmp(p
, "none")) {
3228 translation
= BIOS_ATA_TRANSLATION_NONE
;
3229 } else if (!strcmp(p
, "lba")) {
3230 translation
= BIOS_ATA_TRANSLATION_LBA
;
3231 } else if (!strcmp(p
, "auto")) {
3232 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3236 } else if (*p
!= '\0') {
3238 error_report("invalid physical CHS format");
3241 if (hda_opts
!= NULL
) {
3242 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3244 qemu_opt_set_number(hda_opts
, "heads", heads
,
3246 qemu_opt_set_number(hda_opts
, "secs", secs
,
3248 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3249 qemu_opt_set(hda_opts
, "trans", "large",
3251 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3252 qemu_opt_set(hda_opts
, "trans", "rechs",
3254 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3255 qemu_opt_set(hda_opts
, "trans", "lba",
3257 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3258 qemu_opt_set(hda_opts
, "trans", "none",
3263 error_report("'-hdachs' is deprecated, please use '-device"
3264 " ide-hd,cyls=c,heads=h,secs=s,...' instead");
3266 case QEMU_OPTION_numa
:
3267 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3273 case QEMU_OPTION_display
:
3274 display_type
= select_display(optarg
);
3276 case QEMU_OPTION_nographic
:
3277 olist
= qemu_find_opts("machine");
3278 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3280 display_type
= DT_NONE
;
3282 case QEMU_OPTION_curses
:
3283 #ifdef CONFIG_CURSES
3284 display_type
= DT_CURSES
;
3286 error_report("curses support is disabled");
3290 case QEMU_OPTION_portrait
:
3291 graphic_rotate
= 90;
3293 case QEMU_OPTION_rotate
:
3294 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3295 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3296 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3297 error_report("only 90, 180, 270 deg rotation is available");
3301 case QEMU_OPTION_kernel
:
3302 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3305 case QEMU_OPTION_initrd
:
3306 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3309 case QEMU_OPTION_append
:
3310 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3313 case QEMU_OPTION_dtb
:
3314 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3317 case QEMU_OPTION_cdrom
:
3318 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3320 case QEMU_OPTION_boot
:
3321 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3327 case QEMU_OPTION_fda
:
3328 case QEMU_OPTION_fdb
:
3329 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3332 case QEMU_OPTION_no_fd_bootchk
:
3335 case QEMU_OPTION_netdev
:
3337 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3341 case QEMU_OPTION_net
:
3343 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3347 #ifdef CONFIG_LIBISCSI
3348 case QEMU_OPTION_iscsi
:
3349 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3357 case QEMU_OPTION_tftp
:
3358 error_report("The -tftp option is deprecated. "
3359 "Please use '-netdev user,tftp=...' instead.");
3360 legacy_tftp_prefix
= optarg
;
3362 case QEMU_OPTION_bootp
:
3363 error_report("The -bootp option is deprecated. "
3364 "Please use '-netdev user,bootfile=...' instead.");
3365 legacy_bootp_filename
= optarg
;
3367 case QEMU_OPTION_redir
:
3368 error_report("The -redir option is deprecated. "
3369 "Please use '-netdev user,hostfwd=...' instead.");
3370 if (net_slirp_redir(optarg
) < 0)
3374 case QEMU_OPTION_bt
:
3375 add_device_config(DEV_BT
, optarg
);
3377 case QEMU_OPTION_audio_help
:
3381 case QEMU_OPTION_soundhw
:
3382 select_soundhw (optarg
);
3387 case QEMU_OPTION_version
:
3392 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3399 case QEMU_OPTION_tpmdev
:
3400 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3405 case QEMU_OPTION_mempath
:
3408 case QEMU_OPTION_mem_prealloc
:
3417 case QEMU_OPTION_DFILTER
:
3418 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3421 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3423 case QEMU_OPTION_gdb
:
3424 add_device_config(DEV_GDB
, optarg
);
3427 if (is_help_option(optarg
)) {
3428 list_data_dirs
= true;
3429 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3430 data_dir
[data_dir_idx
++] = optarg
;
3433 case QEMU_OPTION_bios
:
3434 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3437 case QEMU_OPTION_singlestep
:
3444 keyboard_layout
= optarg
;
3446 case QEMU_OPTION_localtime
:
3449 case QEMU_OPTION_vga
:
3458 w
= strtol(p
, (char **)&p
, 10);
3461 error_report("invalid resolution or depth");
3467 h
= strtol(p
, (char **)&p
, 10);
3472 depth
= strtol(p
, (char **)&p
, 10);
3473 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3474 depth
!= 24 && depth
!= 32)
3476 } else if (*p
== '\0') {
3477 depth
= graphic_depth
;
3484 graphic_depth
= depth
;
3487 case QEMU_OPTION_echr
:
3490 term_escape_char
= strtol(optarg
, &r
, 0);
3492 printf("Bad argument to echr\n");
3495 case QEMU_OPTION_monitor
:
3496 default_monitor
= 0;
3497 if (strncmp(optarg
, "none", 4)) {
3498 monitor_parse(optarg
, "readline", false);
3501 case QEMU_OPTION_qmp
:
3502 monitor_parse(optarg
, "control", false);
3503 default_monitor
= 0;
3505 case QEMU_OPTION_qmp_pretty
:
3506 monitor_parse(optarg
, "control", true);
3507 default_monitor
= 0;
3509 case QEMU_OPTION_mon
:
3510 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3515 default_monitor
= 0;
3517 case QEMU_OPTION_chardev
:
3518 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3524 case QEMU_OPTION_fsdev
:
3525 olist
= qemu_find_opts("fsdev");
3527 error_report("fsdev support is disabled");
3530 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3535 case QEMU_OPTION_virtfs
: {
3538 const char *writeout
, *sock_fd
, *socket
;
3540 olist
= qemu_find_opts("virtfs");
3542 error_report("virtfs support is disabled");
3545 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3550 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3551 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3552 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3555 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3556 qemu_opts_id(opts
) ?:
3557 qemu_opt_get(opts
, "mount_tag"),
3560 error_report("duplicate or invalid fsdev id: %s",
3561 qemu_opt_get(opts
, "mount_tag"));
3565 writeout
= qemu_opt_get(opts
, "writeout");
3567 #ifdef CONFIG_SYNC_FILE_RANGE
3568 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3570 error_report("writeout=immediate not supported "
3571 "on this platform");
3575 qemu_opt_set(fsdev
, "fsdriver",
3576 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3577 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3579 qemu_opt_set(fsdev
, "security_model",
3580 qemu_opt_get(opts
, "security_model"),
3582 socket
= qemu_opt_get(opts
, "socket");
3584 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3586 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3588 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3591 qemu_opt_set_bool(fsdev
, "readonly",
3592 qemu_opt_get_bool(opts
, "readonly", 0),
3594 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3596 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3597 qemu_opt_set(device
, "fsdev",
3598 qemu_opts_id(fsdev
), &error_abort
);
3599 qemu_opt_set(device
, "mount_tag",
3600 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3603 case QEMU_OPTION_virtfs_synth
: {
3607 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3610 error_report("duplicate option: %s", "virtfs_synth");
3613 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3615 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3617 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3618 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3619 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3622 case QEMU_OPTION_serial
:
3623 add_device_config(DEV_SERIAL
, optarg
);
3625 if (strncmp(optarg
, "mon:", 4) == 0) {
3626 default_monitor
= 0;
3629 case QEMU_OPTION_watchdog
:
3631 error_report("only one watchdog option may be given");
3636 case QEMU_OPTION_watchdog_action
:
3637 if (select_watchdog_action(optarg
) == -1) {
3638 error_report("unknown -watchdog-action parameter");
3642 case QEMU_OPTION_virtiocon
:
3643 add_device_config(DEV_VIRTCON
, optarg
);
3644 default_virtcon
= 0;
3645 if (strncmp(optarg
, "mon:", 4) == 0) {
3646 default_monitor
= 0;
3649 case QEMU_OPTION_parallel
:
3650 add_device_config(DEV_PARALLEL
, optarg
);
3651 default_parallel
= 0;
3652 if (strncmp(optarg
, "mon:", 4) == 0) {
3653 default_monitor
= 0;
3656 case QEMU_OPTION_debugcon
:
3657 add_device_config(DEV_DEBUGCON
, optarg
);
3659 case QEMU_OPTION_loadvm
:
3662 case QEMU_OPTION_full_screen
:
3665 case QEMU_OPTION_no_frame
:
3668 case QEMU_OPTION_alt_grab
:
3671 case QEMU_OPTION_ctrl_grab
:
3674 case QEMU_OPTION_no_quit
:
3677 case QEMU_OPTION_sdl
:
3679 display_type
= DT_SDL
;
3682 error_report("SDL support is disabled");
3685 case QEMU_OPTION_pidfile
:
3688 case QEMU_OPTION_win2k_hack
:
3689 win2k_install_hack
= 1;
3691 case QEMU_OPTION_rtc_td_hack
: {
3692 static GlobalProperty slew_lost_ticks
= {
3693 .driver
= "mc146818rtc",
3694 .property
= "lost_tick_policy",
3698 qdev_prop_register_global(&slew_lost_ticks
);
3701 case QEMU_OPTION_acpitable
:
3702 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3707 acpi_table_add(opts
, &error_fatal
);
3709 case QEMU_OPTION_smbios
:
3710 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3715 smbios_entry_add(opts
, &error_fatal
);
3717 case QEMU_OPTION_fwcfg
:
3718 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3724 case QEMU_OPTION_enable_kvm
:
3725 olist
= qemu_find_opts("machine");
3726 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3728 case QEMU_OPTION_enable_hax
:
3729 olist
= qemu_find_opts("machine");
3730 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3733 case QEMU_OPTION_machine
:
3734 olist
= qemu_find_opts("machine");
3735 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3740 case QEMU_OPTION_no_kvm
:
3741 olist
= qemu_find_opts("machine");
3742 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3744 case QEMU_OPTION_no_kvm_pit
: {
3745 error_report("warning: ignoring deprecated option");
3748 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3749 static GlobalProperty kvm_pit_lost_tick_policy
= {
3750 .driver
= "kvm-pit",
3751 .property
= "lost_tick_policy",
3755 error_report("warning: deprecated, replaced by "
3756 "-global kvm-pit.lost_tick_policy=discard");
3757 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3760 case QEMU_OPTION_accel
:
3761 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3763 optarg
= qemu_opt_get(accel_opts
, "accel");
3764 if (!optarg
|| is_help_option(optarg
)) {
3765 error_printf("Possible accelerators: kvm, xen, hax, tcg\n");
3768 opts
= qemu_opts_create(qemu_find_opts("machine"), NULL
,
3769 false, &error_abort
);
3770 qemu_opt_set(opts
, "accel", optarg
, &error_abort
);
3772 case QEMU_OPTION_usb
:
3773 olist
= qemu_find_opts("machine");
3774 qemu_opts_parse_noisily(olist
, "usb=on", false);
3776 case QEMU_OPTION_usbdevice
:
3777 error_report("'-usbdevice' is deprecated, please use "
3778 "'-device usb-...' instead");
3779 olist
= qemu_find_opts("machine");
3780 qemu_opts_parse_noisily(olist
, "usb=on", false);
3781 add_device_config(DEV_USB
, optarg
);
3783 case QEMU_OPTION_device
:
3784 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3789 case QEMU_OPTION_smp
:
3790 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3795 case QEMU_OPTION_vnc
:
3796 vnc_parse(optarg
, &error_fatal
);
3798 case QEMU_OPTION_no_acpi
:
3801 case QEMU_OPTION_no_hpet
:
3804 case QEMU_OPTION_balloon
:
3805 if (balloon_parse(optarg
) < 0) {
3806 error_report("unknown -balloon argument %s", optarg
);
3810 case QEMU_OPTION_no_reboot
:
3813 case QEMU_OPTION_no_shutdown
:
3816 case QEMU_OPTION_show_cursor
:
3819 case QEMU_OPTION_uuid
:
3820 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3821 error_report("failed to parse UUID string: wrong format");
3824 qemu_uuid_set
= true;
3826 case QEMU_OPTION_option_rom
:
3827 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3828 error_report("too many option ROMs");
3831 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3836 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3837 option_rom
[nb_option_roms
].bootindex
=
3838 qemu_opt_get_number(opts
, "bootindex", -1);
3839 if (!option_rom
[nb_option_roms
].name
) {
3840 error_report("Option ROM file is not specified");
3845 case QEMU_OPTION_semihosting
:
3846 semihosting
.enabled
= true;
3847 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3849 case QEMU_OPTION_semihosting_config
:
3850 semihosting
.enabled
= true;
3851 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3854 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3856 const char *target
= qemu_opt_get(opts
, "target");
3857 if (target
!= NULL
) {
3858 if (strcmp("native", target
) == 0) {
3859 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3860 } else if (strcmp("gdb", target
) == 0) {
3861 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3862 } else if (strcmp("auto", target
) == 0) {
3863 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3865 error_report("unsupported semihosting-config %s",
3870 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3872 /* Set semihosting argument count and vector */
3873 qemu_opt_foreach(opts
, add_semihosting_arg
,
3874 &semihosting
, NULL
);
3876 error_report("unsupported semihosting-config %s", optarg
);
3880 case QEMU_OPTION_tdf
:
3881 error_report("warning: ignoring deprecated option");
3883 case QEMU_OPTION_name
:
3884 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3890 case QEMU_OPTION_prom_env
:
3891 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3892 error_report("too many prom variables");
3895 prom_envs
[nb_prom_envs
] = optarg
;
3898 case QEMU_OPTION_old_param
:
3901 case QEMU_OPTION_clock
:
3902 /* Clock options no longer exist. Keep this option for
3903 * backward compatibility.
3906 case QEMU_OPTION_startdate
:
3907 configure_rtc_date_offset(optarg
, 1);
3909 case QEMU_OPTION_rtc
:
3910 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3915 configure_rtc(opts
);
3917 case QEMU_OPTION_tb_size
:
3918 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3919 if (tcg_tb_size
< 0) {
3923 case QEMU_OPTION_icount
:
3924 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3930 case QEMU_OPTION_incoming
:
3932 runstate_set(RUN_STATE_INMIGRATE
);
3936 case QEMU_OPTION_only_migratable
:
3937 only_migratable
= 1;
3939 case QEMU_OPTION_nodefaults
:
3942 case QEMU_OPTION_xen_domid
:
3943 if (!(xen_available())) {
3944 error_report("Option not supported for this target");
3947 xen_domid
= atoi(optarg
);
3949 case QEMU_OPTION_xen_create
:
3950 if (!(xen_available())) {
3951 error_report("Option not supported for this target");
3954 xen_mode
= XEN_CREATE
;
3956 case QEMU_OPTION_xen_attach
:
3957 if (!(xen_available())) {
3958 error_report("Option not supported for this target");
3961 xen_mode
= XEN_ATTACH
;
3963 case QEMU_OPTION_xen_domid_restrict
:
3964 if (!(xen_available())) {
3965 error_report("Option not supported for this target");
3968 xen_domid_restrict
= true;
3970 case QEMU_OPTION_trace
:
3972 trace_file
= trace_opt_parse(optarg
);
3974 case QEMU_OPTION_readconfig
:
3976 int ret
= qemu_read_config_file(optarg
);
3978 error_report("read config %s: %s", optarg
,
3984 case QEMU_OPTION_spice
:
3985 olist
= qemu_find_opts("spice");
3987 error_report("spice support is disabled");
3990 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3996 case QEMU_OPTION_writeconfig
:
3999 if (strcmp(optarg
, "-") == 0) {
4002 fp
= fopen(optarg
, "w");
4004 error_report("open %s: %s", optarg
,
4009 qemu_config_write(fp
);
4015 case QEMU_OPTION_qtest
:
4016 qtest_chrdev
= optarg
;
4018 case QEMU_OPTION_qtest_log
:
4021 case QEMU_OPTION_sandbox
:
4022 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4028 case QEMU_OPTION_add_fd
:
4030 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4036 error_report("File descriptor passing is disabled on this "
4041 case QEMU_OPTION_object
:
4042 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
4048 case QEMU_OPTION_realtime
:
4049 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4054 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4056 case QEMU_OPTION_msg
:
4057 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4062 configure_msg(opts
);
4064 case QEMU_OPTION_dump_vmstate
:
4065 if (vmstate_dump_file
) {
4066 error_report("only one '-dump-vmstate' "
4067 "option may be given");
4070 vmstate_dump_file
= fopen(optarg
, "w");
4071 if (vmstate_dump_file
== NULL
) {
4072 error_report("open %s: %s", optarg
, strerror(errno
));
4077 os_parse_cmd_args(popt
->index
, optarg
);
4082 * Clear error location left behind by the loop.
4083 * Best done right after the loop. Do not insert code here!
4087 replay_configure(icount_opts
);
4089 machine_class
= select_machine();
4091 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4095 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4096 error_report("could not acquire pid file: %s", strerror(errno
));
4100 if (qemu_init_main_loop(&main_loop_err
)) {
4101 error_report_err(main_loop_err
);
4105 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4106 parse_sandbox
, NULL
, NULL
)) {
4110 if (qemu_opts_foreach(qemu_find_opts("name"),
4111 parse_name
, NULL
, NULL
)) {
4116 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4117 parse_add_fd
, NULL
, NULL
)) {
4121 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4122 cleanup_add_fd
, NULL
, NULL
)) {
4127 current_machine
= MACHINE(object_new(object_class_get_name(
4128 OBJECT_CLASS(machine_class
))));
4129 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4132 object_property_add_child(object_get_root(), "machine",
4133 OBJECT(current_machine
), &error_abort
);
4135 if (machine_class
->minimum_page_bits
) {
4136 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4137 /* This would be a board error: specifying a minimum smaller than
4138 * a target's compile-time fixed setting.
4140 g_assert_not_reached();
4144 cpu_exec_init_all();
4146 if (machine_class
->hw_version
) {
4147 qemu_set_hw_version(machine_class
->hw_version
);
4150 if (cpu_model
&& is_help_option(cpu_model
)) {
4151 list_cpus(stdout
, &fprintf
, cpu_model
);
4155 if (!trace_init_backends()) {
4158 trace_init_file(trace_file
);
4160 /* Open the logfile at this point and set the log mask if necessary.
4163 qemu_set_log_filename(log_file
, &error_fatal
);
4168 mask
= qemu_str_to_log_mask(log_mask
);
4170 qemu_print_log_usage(stdout
);
4178 /* If no data_dir is specified then try to find it relative to the
4180 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4181 data_dir
[data_dir_idx
] = os_find_datadir();
4182 if (data_dir
[data_dir_idx
] != NULL
) {
4186 /* If all else fails use the install path specified when building. */
4187 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4188 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4191 /* -L help lists the data directories and exits. */
4192 if (list_data_dirs
) {
4193 for (i
= 0; i
< data_dir_idx
; i
++) {
4194 printf("%s\n", data_dir
[i
]);
4199 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4201 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4202 if (max_cpus
> machine_class
->max_cpus
) {
4203 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4204 "supported by machine '%s' (%d)", max_cpus
,
4205 machine_class
->name
, machine_class
->max_cpus
);
4210 * Get the default machine options from the machine if it is not already
4211 * specified either by the configuration file or by the command line.
4213 if (machine_class
->default_machine_opts
) {
4214 qemu_opts_set_defaults(qemu_find_opts("machine"),
4215 machine_class
->default_machine_opts
, 0);
4218 qemu_opts_foreach(qemu_find_opts("device"),
4219 default_driver_check
, NULL
, NULL
);
4220 qemu_opts_foreach(qemu_find_opts("global"),
4221 default_driver_check
, NULL
, NULL
);
4223 if (!vga_model
&& !default_vga
) {
4224 vga_interface_type
= VGA_DEVICE
;
4226 if (!has_defaults
|| machine_class
->no_serial
) {
4229 if (!has_defaults
|| machine_class
->no_parallel
) {
4230 default_parallel
= 0;
4232 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4233 default_virtcon
= 0;
4235 if (!has_defaults
|| !machine_class
->use_sclp
) {
4238 if (!has_defaults
|| machine_class
->no_floppy
) {
4241 if (!has_defaults
|| machine_class
->no_cdrom
) {
4244 if (!has_defaults
|| machine_class
->no_sdcard
) {
4247 if (!has_defaults
) {
4248 default_monitor
= 0;
4253 if (is_daemonized()) {
4254 /* According to documentation and historically, -nographic redirects
4255 * serial port, parallel port and monitor to stdio, which does not work
4256 * with -daemonize. We can redirect these to null instead, but since
4257 * -nographic is legacy, let's just error out.
4258 * We disallow -nographic only if all other ports are not redirected
4259 * explicitly, to not break existing legacy setups which uses
4260 * -nographic _and_ redirects all ports explicitly - this is valid
4261 * usage, -nographic is just a no-op in this case.
4264 && (default_parallel
|| default_serial
4265 || default_monitor
|| default_virtcon
)) {
4266 error_report("-nographic cannot be used with -daemonize");
4269 #ifdef CONFIG_CURSES
4270 if (display_type
== DT_CURSES
) {
4271 error_report("curses display cannot be used with -daemonize");
4278 if (default_parallel
)
4279 add_device_config(DEV_PARALLEL
, "null");
4280 if (default_serial
&& default_monitor
) {
4281 add_device_config(DEV_SERIAL
, "mon:stdio");
4282 } else if (default_virtcon
&& default_monitor
) {
4283 add_device_config(DEV_VIRTCON
, "mon:stdio");
4284 } else if (default_sclp
&& default_monitor
) {
4285 add_device_config(DEV_SCLP
, "mon:stdio");
4288 add_device_config(DEV_SERIAL
, "stdio");
4289 if (default_virtcon
)
4290 add_device_config(DEV_VIRTCON
, "stdio");
4292 add_device_config(DEV_SCLP
, "stdio");
4294 if (default_monitor
)
4295 monitor_parse("stdio", "readline", false);
4299 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4300 if (default_parallel
)
4301 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4302 if (default_monitor
)
4303 monitor_parse("vc:80Cx24C", "readline", false);
4304 if (default_virtcon
)
4305 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4307 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4311 #if defined(CONFIG_VNC)
4312 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4316 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4317 #if defined(CONFIG_GTK)
4318 display_type
= DT_GTK
;
4319 #elif defined(CONFIG_SDL)
4320 display_type
= DT_SDL
;
4321 #elif defined(CONFIG_COCOA)
4322 display_type
= DT_COCOA
;
4323 #elif defined(CONFIG_VNC)
4324 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4326 display_type
= DT_NONE
;
4330 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4331 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4332 "for SDL, ignoring option");
4334 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4335 error_report("-no-quit is only valid for GTK and SDL, "
4339 if (display_type
== DT_GTK
) {
4340 early_gtk_display_init(request_opengl
);
4343 if (display_type
== DT_SDL
) {
4344 sdl_display_early_init(request_opengl
);
4347 qemu_console_early_init();
4349 if (request_opengl
== 1 && display_opengl
== 0) {
4350 #if defined(CONFIG_OPENGL)
4351 error_report("OpenGL is not supported by the display");
4353 error_report("OpenGL support is disabled");
4361 if (qemu_opts_foreach(qemu_find_opts("object"),
4362 user_creatable_add_opts_foreach
,
4363 object_create_initial
, NULL
)) {
4367 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4368 chardev_init_func
, NULL
, NULL
)) {
4372 #ifdef CONFIG_VIRTFS
4373 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4374 fsdev_init_func
, NULL
, NULL
)) {
4379 if (qemu_opts_foreach(qemu_find_opts("device"),
4380 device_help_func
, NULL
, NULL
)) {
4384 machine_opts
= qemu_get_machine_opts();
4385 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4387 object_unref(OBJECT(current_machine
));
4391 configure_accelerator(current_machine
);
4394 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4397 machine_opts
= qemu_get_machine_opts();
4398 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4399 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4400 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4401 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4403 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4405 boot_order
= qemu_opt_get(opts
, "order");
4407 validate_bootdevices(boot_order
, &error_fatal
);
4410 boot_once
= qemu_opt_get(opts
, "once");
4412 validate_bootdevices(boot_once
, &error_fatal
);
4415 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4416 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4420 boot_order
= machine_class
->default_boot_order
;
4423 if (!kernel_cmdline
) {
4424 kernel_cmdline
= "";
4425 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4428 linux_boot
= (kernel_filename
!= NULL
);
4430 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4431 error_report("-append only allowed with -kernel option");
4435 if (!linux_boot
&& initrd_filename
!= NULL
) {
4436 error_report("-initrd only allowed with -kernel option");
4440 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4441 /* fall back to the -kernel/-append */
4442 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4445 os_set_line_buffering();
4447 /* spice needs the timers to be initialized by this point */
4452 if (!tcg_enabled()) {
4453 error_report("-icount is not allowed with hardware virtualization");
4456 configure_icount(icount_opts
, &error_abort
);
4457 qemu_opts_del(icount_opts
);
4460 qemu_tcg_configure(accel_opts
, &error_fatal
);
4463 QemuOptsList
*net
= qemu_find_opts("net");
4464 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4466 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4472 if (net_init_clients() < 0) {
4476 if (qemu_opts_foreach(qemu_find_opts("object"),
4477 user_creatable_add_opts_foreach
,
4478 object_create_delayed
, NULL
)) {
4483 if (tpm_init() < 0) {
4488 /* init the bluetooth world */
4489 if (foreach_device_config(DEV_BT
, bt_parse
))
4492 if (!xen_enabled()) {
4493 /* On 32-bit hosts, QEMU is limited by virtual address space */
4494 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4495 error_report("at most 2047 MB RAM can be simulated");
4503 /* If the currently selected machine wishes to override the units-per-bus
4504 * property of its default HBA interface type, do so now. */
4505 if (machine_class
->units_per_default_bus
) {
4506 override_max_devs(machine_class
->block_default_type
,
4507 machine_class
->units_per_default_bus
);
4510 /* open the virtual block devices */
4511 while (!QSIMPLEQ_EMPTY(&bdo_queue
)) {
4512 BlockdevOptions_queue
*bdo
= QSIMPLEQ_FIRST(&bdo_queue
);
4514 QSIMPLEQ_REMOVE_HEAD(&bdo_queue
, entry
);
4515 loc_push_restore(&bdo
->loc
);
4516 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
4518 qapi_free_BlockdevOptions(bdo
->bdo
);
4521 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4522 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4525 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4526 &machine_class
->block_default_type
, NULL
)) {
4530 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4532 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4533 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4535 parse_numa_opts(current_machine
);
4537 if (qemu_opts_foreach(qemu_find_opts("mon"),
4538 mon_init_func
, NULL
, NULL
)) {
4542 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4544 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4546 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4548 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4551 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4554 /* If no default VGA is requested, the default is "none". */
4556 if (machine_class
->default_display
) {
4557 vga_model
= machine_class
->default_display
;
4558 } else if (vga_interface_available(VGA_CIRRUS
)) {
4559 vga_model
= "cirrus";
4560 } else if (vga_interface_available(VGA_STD
)) {
4565 select_vgahw(vga_model
);
4569 i
= select_watchdog(watchdog
);
4571 exit (i
== 1 ? 1 : 0);
4574 machine_register_compat_props(current_machine
);
4576 qemu_opts_foreach(qemu_find_opts("global"),
4577 global_init_func
, NULL
, NULL
);
4579 /* This checkpoint is required by replay to separate prior clock
4580 reading from the other reads, because timer polling functions query
4581 clock values from the log. */
4582 replay_checkpoint(CHECKPOINT_INIT
);
4583 qdev_machine_init();
4585 current_machine
->ram_size
= ram_size
;
4586 current_machine
->maxram_size
= maxram_size
;
4587 current_machine
->ram_slots
= ram_slots
;
4588 current_machine
->boot_order
= boot_order
;
4589 current_machine
->cpu_model
= cpu_model
;
4591 machine_run_board_init(current_machine
);
4597 if (hax_enabled()) {
4601 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4602 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4606 /* init USB devices */
4607 if (machine_usb(current_machine
)) {
4608 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4612 /* Check if IGD GFX passthrough. */
4615 /* init generic devices */
4616 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4617 if (qemu_opts_foreach(qemu_find_opts("device"),
4618 device_init_func
, NULL
, NULL
)) {
4622 cpu_synchronize_all_post_init();
4624 rom_reset_order_override();
4627 * Create frontends for -drive if=scsi leftovers.
4628 * Normally, frontends for -drive get created by machine
4629 * initialization for onboard SCSI HBAs. However, we create a few
4630 * more ever since SCSI qdevification, but this is pretty much an
4631 * implementation accident, and deprecated.
4633 scsi_legacy_handle_cmdline();
4635 /* Did we create any drives that we failed to create a device for? */
4636 drive_check_orphaned();
4638 /* Don't warn about the default network setup that you get if
4639 * no command line -net or -netdev options are specified. There
4640 * are two cases that we would otherwise complain about:
4641 * (1) board doesn't support a NIC but the implicit "-net nic"
4643 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4644 * sets up a nic that isn't connected to anything.
4647 net_check_clients();
4652 qemu_boot_set(boot_once
, &error_fatal
);
4653 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4656 ds
= init_displaystate();
4658 /* init local displays */
4659 switch (display_type
) {
4661 curses_display_init(ds
, full_screen
);
4664 sdl_display_init(ds
, full_screen
, no_frame
);
4667 cocoa_display_init(ds
, full_screen
);
4670 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4676 /* must be after terminal init, SDL library changes signal handlers */
4677 os_setup_signal_handling();
4679 /* init remote displays */
4681 qemu_opts_foreach(qemu_find_opts("vnc"),
4682 vnc_init_func
, NULL
, NULL
);
4686 qemu_spice_display_init();
4689 #ifdef CONFIG_OPENGL_DMABUF
4690 if (display_type
== DT_EGL
) {
4691 egl_headless_init();
4695 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4699 qdev_machine_creation_done();
4701 /* TODO: once all bus devices are qdevified, this should be done
4702 * when bus is created by qdev.c */
4703 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4704 qemu_run_machine_init_done_notifiers();
4706 if (rom_check_and_register_reset() != 0) {
4707 error_report("rom check and register reset failed");
4713 /* This checkpoint is required by replay to separate prior clock
4714 reading from the other reads, because timer polling functions query
4715 clock values from the log. */
4716 replay_checkpoint(CHECKPOINT_RESET
);
4717 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
4718 register_global_state();
4719 if (replay_mode
!= REPLAY_MODE_NONE
) {
4720 replay_vmstate_init();
4721 } else if (loadvm
) {
4722 Error
*local_err
= NULL
;
4723 if (load_snapshot(loadvm
, &local_err
) < 0) {
4724 error_report_err(local_err
);
4729 qdev_prop_check_globals();
4730 if (vmstate_dump_file
) {
4732 dump_vmstate_json_to_file(vmstate_dump_file
);
4737 Error
*local_err
= NULL
;
4738 qemu_start_incoming_migration(incoming
, &local_err
);
4740 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4743 } else if (autostart
) {
4750 replay_disable_events();
4751 iothread_stop_all();
4757 /* vhost-user must be cleaned up before chardevs. */
4762 /* TODO: unref root container, check all devices are ok */