4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "qemu/osdep.h"
25 #include "qemu-version.h"
26 #include "qemu/cutils.h"
27 #include "qemu/help_option.h"
28 #include "qemu/uuid.h"
31 #include "sysemu/seccomp.h"
34 #if defined(CONFIG_VDE)
35 #include <libvdeplug.h>
39 #if defined(__APPLE__) || defined(main)
40 #define SDL_MAIN_HANDLED
42 #if SDL_MAJOR_VERSION == 1
43 int qemu_main(int argc
, char **argv
);
44 int main(int argc
, char **argv
)
46 return qemu_main(argc
, argv
);
49 #define main qemu_main
50 #elif SDL_MAJOR_VERSION == 2
53 #error undefined SDL version
56 #endif /* CONFIG_SDL */
60 #define main qemu_main
61 #endif /* CONFIG_COCOA */
64 #include "qemu/error-report.h"
65 #include "qemu/sockets.h"
67 #include "hw/boards.h"
68 #include "sysemu/accel.h"
70 #include "hw/i386/pc.h"
71 #include "hw/isa/isa.h"
72 #include "hw/scsi/scsi.h"
74 #include "sysemu/watchdog.h"
75 #include "hw/smbios/smbios.h"
76 #include "hw/acpi/acpi.h"
77 #include "hw/xen/xen.h"
79 #include "hw/loader.h"
80 #include "monitor/qdev.h"
81 #include "sysemu/bt.h"
83 #include "net/slirp.h"
84 #include "monitor/monitor.h"
85 #include "ui/console.h"
87 #include "sysemu/sysemu.h"
88 #include "sysemu/numa.h"
89 #include "exec/gdbstub.h"
90 #include "qemu/timer.h"
91 #include "sysemu/char.h"
92 #include "qemu/bitmap.h"
94 #include "sysemu/blockdev.h"
95 #include "hw/block/block.h"
96 #include "migration/block.h"
97 #include "sysemu/tpm.h"
98 #include "sysemu/dma.h"
99 #include "audio/audio.h"
100 #include "migration/migration.h"
101 #include "sysemu/cpus.h"
102 #include "migration/colo.h"
103 #include "sysemu/kvm.h"
104 #include "sysemu/hax.h"
105 #include "qapi/qobject-input-visitor.h"
106 #include "qapi/qobject-input-visitor.h"
107 #include "qapi-visit.h"
108 #include "qapi/qmp/qjson.h"
109 #include "qemu/option.h"
110 #include "qemu/config-file.h"
111 #include "qemu-options.h"
112 #include "qmp-commands.h"
113 #include "qemu/main-loop.h"
115 #include "fsdev/qemu-fsdev.h"
117 #include "sysemu/qtest.h"
119 #include "disas/disas.h"
122 #include "slirp/libslirp.h"
124 #include "trace-root.h"
125 #include "trace/control.h"
126 #include "qemu/queue.h"
127 #include "sysemu/arch_init.h"
129 #include "ui/qemu-spice.h"
130 #include "qapi/string-input-visitor.h"
131 #include "qapi/opts-visitor.h"
132 #include "qom/object_interfaces.h"
133 #include "qapi-event.h"
134 #include "exec/semihost.h"
135 #include "crypto/init.h"
136 #include "sysemu/replay.h"
137 #include "qapi/qmp/qerror.h"
138 #include "sysemu/iothread.h"
140 #define MAX_VIRTIO_CONSOLES 1
141 #define MAX_SCLP_CONSOLES 1
143 static const char *data_dir
[16];
144 static int data_dir_idx
;
145 const char *bios_name
= NULL
;
146 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
147 int request_opengl
= -1;
149 const char* keyboard_layout
= NULL
;
151 const char *mem_path
= NULL
;
152 int mem_prealloc
= 0; /* force preallocation of physical target memory */
153 bool enable_mlock
= false;
155 NICInfo nd_table
[MAX_NICS
];
157 static int rtc_utc
= 1;
158 static int rtc_date_offset
= -1; /* -1 means no change */
159 QEMUClockType rtc_clock
;
160 int vga_interface_type
= VGA_NONE
;
161 static int full_screen
= 0;
162 static int no_frame
= 0;
164 static bool grab_on_hover
;
165 Chardev
*serial_hds
[MAX_SERIAL_PORTS
];
166 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
167 Chardev
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
168 Chardev
*sclp_hds
[MAX_SCLP_CONSOLES
];
169 int win2k_install_hack
= 0;
175 int acpi_enabled
= 1;
178 static int no_reboot
;
181 int graphic_rotate
= 0;
182 const char *watchdog
;
183 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
186 const char *qemu_name
;
189 unsigned int nb_prom_envs
= 0;
190 const char *prom_envs
[MAX_PROM_ENVS
];
193 uint8_t *boot_splash_filedata
;
194 size_t boot_splash_filedata_size
;
195 uint8_t qemu_extra_params_fw
[2];
196 int only_migratable
; /* turn it off unless user states otherwise */
198 int icount_align_option
;
200 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
201 * little-endian "wire format" described in the SMBIOS 2.6 specification.
206 /* Trace unassigned memory or i/o accesses. */
207 bool trace_unassigned
;
209 static NotifierList exit_notifiers
=
210 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
212 static NotifierList machine_init_done_notifiers
=
213 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
217 enum xen_mode xen_mode
= XEN_EMULATE
;
219 static int has_defaults
= 1;
220 static int default_serial
= 1;
221 static int default_parallel
= 1;
222 static int default_virtcon
= 1;
223 static int default_sclp
= 1;
224 static int default_monitor
= 1;
225 static int default_floppy
= 1;
226 static int default_cdrom
= 1;
227 static int default_sdcard
= 1;
228 static int default_vga
= 1;
229 static int default_net
= 1;
235 { .driver
= "isa-serial", .flag
= &default_serial
},
236 { .driver
= "isa-parallel", .flag
= &default_parallel
},
237 { .driver
= "isa-fdc", .flag
= &default_floppy
},
238 { .driver
= "floppy", .flag
= &default_floppy
},
239 { .driver
= "ide-cd", .flag
= &default_cdrom
},
240 { .driver
= "ide-hd", .flag
= &default_cdrom
},
241 { .driver
= "ide-drive", .flag
= &default_cdrom
},
242 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
243 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
244 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
245 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
246 { .driver
= "VGA", .flag
= &default_vga
},
247 { .driver
= "isa-vga", .flag
= &default_vga
},
248 { .driver
= "cirrus-vga", .flag
= &default_vga
},
249 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
250 { .driver
= "vmware-svga", .flag
= &default_vga
},
251 { .driver
= "qxl-vga", .flag
= &default_vga
},
252 { .driver
= "virtio-vga", .flag
= &default_vga
},
255 static QemuOptsList qemu_rtc_opts
= {
257 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
261 .type
= QEMU_OPT_STRING
,
264 .type
= QEMU_OPT_STRING
,
267 .type
= QEMU_OPT_STRING
,
269 { /* end of list */ }
273 static QemuOptsList qemu_sandbox_opts
= {
275 .implied_opt_name
= "enable",
276 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
280 .type
= QEMU_OPT_BOOL
,
282 { /* end of list */ }
286 static QemuOptsList qemu_option_rom_opts
= {
287 .name
= "option-rom",
288 .implied_opt_name
= "romfile",
289 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
293 .type
= QEMU_OPT_NUMBER
,
296 .type
= QEMU_OPT_STRING
,
298 { /* end of list */ }
302 static QemuOptsList qemu_machine_opts
= {
304 .implied_opt_name
= "type",
306 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
309 * no elements => accept any
310 * sanity checking will happen later
311 * when setting machine properties
317 static QemuOptsList qemu_accel_opts
= {
319 .implied_opt_name
= "accel",
320 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
325 .type
= QEMU_OPT_STRING
,
326 .help
= "Select the type of accelerator",
330 .type
= QEMU_OPT_STRING
,
331 .help
= "Enable/disable multi-threaded TCG",
333 { /* end of list */ }
337 static QemuOptsList qemu_boot_opts
= {
339 .implied_opt_name
= "order",
341 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
345 .type
= QEMU_OPT_STRING
,
348 .type
= QEMU_OPT_STRING
,
351 .type
= QEMU_OPT_BOOL
,
354 .type
= QEMU_OPT_STRING
,
356 .name
= "splash-time",
357 .type
= QEMU_OPT_STRING
,
359 .name
= "reboot-timeout",
360 .type
= QEMU_OPT_STRING
,
363 .type
= QEMU_OPT_BOOL
,
369 static QemuOptsList qemu_add_fd_opts
= {
371 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
375 .type
= QEMU_OPT_NUMBER
,
376 .help
= "file descriptor of which a duplicate is added to fd set",
379 .type
= QEMU_OPT_NUMBER
,
380 .help
= "ID of the fd set to add fd to",
383 .type
= QEMU_OPT_STRING
,
384 .help
= "free-form string used to describe fd",
386 { /* end of list */ }
390 static QemuOptsList qemu_object_opts
= {
392 .implied_opt_name
= "qom-type",
393 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
399 static QemuOptsList qemu_tpmdev_opts
= {
401 .implied_opt_name
= "type",
402 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
404 /* options are defined in the TPM backends */
405 { /* end of list */ }
409 static QemuOptsList qemu_realtime_opts
= {
411 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
415 .type
= QEMU_OPT_BOOL
,
417 { /* end of list */ }
421 static QemuOptsList qemu_msg_opts
= {
423 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
427 .type
= QEMU_OPT_BOOL
,
429 { /* end of list */ }
433 static QemuOptsList qemu_name_opts
= {
435 .implied_opt_name
= "guest",
437 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
441 .type
= QEMU_OPT_STRING
,
442 .help
= "Sets the name of the guest.\n"
443 "This name will be displayed in the SDL window caption.\n"
444 "The name will also be used for the VNC server",
447 .type
= QEMU_OPT_STRING
,
448 .help
= "Sets the name of the QEMU process, as shown in top etc",
450 .name
= "debug-threads",
451 .type
= QEMU_OPT_BOOL
,
452 .help
= "When enabled, name the individual threads; defaults off.\n"
453 "NOTE: The thread names are for debugging and not a\n"
456 { /* End of list */ }
460 static QemuOptsList qemu_mem_opts
= {
462 .implied_opt_name
= "size",
463 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
468 .type
= QEMU_OPT_SIZE
,
472 .type
= QEMU_OPT_NUMBER
,
476 .type
= QEMU_OPT_SIZE
,
478 { /* end of list */ }
482 static QemuOptsList qemu_icount_opts
= {
484 .implied_opt_name
= "shift",
486 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
490 .type
= QEMU_OPT_STRING
,
493 .type
= QEMU_OPT_BOOL
,
496 .type
= QEMU_OPT_BOOL
,
499 .type
= QEMU_OPT_STRING
,
502 .type
= QEMU_OPT_STRING
,
504 .name
= "rrsnapshot",
505 .type
= QEMU_OPT_STRING
,
507 { /* end of list */ }
511 static QemuOptsList qemu_semihosting_config_opts
= {
512 .name
= "semihosting-config",
513 .implied_opt_name
= "enable",
514 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
518 .type
= QEMU_OPT_BOOL
,
521 .type
= QEMU_OPT_STRING
,
524 .type
= QEMU_OPT_STRING
,
526 { /* end of list */ }
530 static QemuOptsList qemu_fw_cfg_opts
= {
532 .implied_opt_name
= "name",
533 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
537 .type
= QEMU_OPT_STRING
,
538 .help
= "Sets the fw_cfg name of the blob to be inserted",
541 .type
= QEMU_OPT_STRING
,
542 .help
= "Sets the name of the file from which\n"
543 "the fw_cfg blob will be loaded",
546 .type
= QEMU_OPT_STRING
,
547 .help
= "Sets content of the blob to be inserted from a string",
549 { /* end of list */ }
554 * Get machine options
556 * Returns: machine options (never null).
558 QemuOpts
*qemu_get_machine_opts(void)
560 return qemu_find_opts_singleton("machine");
563 const char *qemu_get_vm_name(void)
568 static void res_free(void)
570 g_free(boot_splash_filedata
);
571 boot_splash_filedata
= NULL
;
574 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
576 const char *driver
= qemu_opt_get(opts
, "driver");
581 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
582 if (strcmp(default_list
[i
].driver
, driver
) != 0)
584 *(default_list
[i
].flag
) = 0;
589 /***********************************************************/
592 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
594 /* We use RUN_STATE__MAX but any invalid value will do */
595 static RunState vmstop_requested
= RUN_STATE__MAX
;
596 static QemuMutex vmstop_lock
;
601 } RunStateTransition
;
603 static const RunStateTransition runstate_transitions_def
[] = {
605 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
606 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
607 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
609 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
610 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
611 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
612 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
613 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
614 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
615 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
616 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
617 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
618 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
619 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
620 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
622 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
623 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
624 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
626 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
627 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
628 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
630 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
631 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
632 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
633 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
635 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
636 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
637 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
639 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
640 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
641 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
643 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
644 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
645 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
646 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
648 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
649 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
651 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
653 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
654 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
655 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
656 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
657 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
658 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
659 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
660 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
661 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
662 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
663 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
665 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
667 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
668 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
669 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
671 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
672 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
673 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
674 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
675 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
676 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
678 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
679 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
680 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
681 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
683 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
684 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
685 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
687 { RUN_STATE__MAX
, RUN_STATE__MAX
},
690 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
692 bool runstate_check(RunState state
)
694 return current_run_state
== state
;
697 bool runstate_store(char *str
, size_t size
)
699 const char *state
= RunState_lookup
[current_run_state
];
700 size_t len
= strlen(state
) + 1;
705 memcpy(str
, state
, len
);
709 static void runstate_init(void)
711 const RunStateTransition
*p
;
713 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
714 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
715 runstate_valid_transitions
[p
->from
][p
->to
] = true;
718 qemu_mutex_init(&vmstop_lock
);
721 /* This function will abort() on invalid state transitions */
722 void runstate_set(RunState new_state
)
724 assert(new_state
< RUN_STATE__MAX
);
726 if (current_run_state
== new_state
) {
730 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
731 error_report("invalid runstate transition: '%s' -> '%s'",
732 RunState_lookup
[current_run_state
],
733 RunState_lookup
[new_state
]);
736 trace_runstate_set(new_state
);
737 current_run_state
= new_state
;
740 int runstate_is_running(void)
742 return runstate_check(RUN_STATE_RUNNING
);
745 bool runstate_needs_reset(void)
747 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
748 runstate_check(RUN_STATE_SHUTDOWN
);
751 StatusInfo
*qmp_query_status(Error
**errp
)
753 StatusInfo
*info
= g_malloc0(sizeof(*info
));
755 info
->running
= runstate_is_running();
756 info
->singlestep
= singlestep
;
757 info
->status
= current_run_state
;
762 bool qemu_vmstop_requested(RunState
*r
)
764 qemu_mutex_lock(&vmstop_lock
);
765 *r
= vmstop_requested
;
766 vmstop_requested
= RUN_STATE__MAX
;
767 qemu_mutex_unlock(&vmstop_lock
);
768 return *r
< RUN_STATE__MAX
;
771 void qemu_system_vmstop_request_prepare(void)
773 qemu_mutex_lock(&vmstop_lock
);
776 void qemu_system_vmstop_request(RunState state
)
778 vmstop_requested
= state
;
779 qemu_mutex_unlock(&vmstop_lock
);
783 /***********************************************************/
784 /* real time host monotonic timer */
786 static time_t qemu_time(void)
788 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
791 /***********************************************************/
792 /* host time/date access */
793 void qemu_get_timedate(struct tm
*tm
, int offset
)
795 time_t ti
= qemu_time();
798 if (rtc_date_offset
== -1) {
802 localtime_r(&ti
, tm
);
804 ti
-= rtc_date_offset
;
809 int qemu_timedate_diff(struct tm
*tm
)
813 if (rtc_date_offset
== -1)
815 seconds
= mktimegm(tm
);
818 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
819 seconds
= mktime(&tmp
);
822 seconds
= mktimegm(tm
) + rtc_date_offset
;
824 return seconds
- qemu_time();
827 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
829 time_t rtc_start_date
;
832 if (!strcmp(startdate
, "now") && legacy
) {
833 rtc_date_offset
= -1;
835 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
843 } else if (sscanf(startdate
, "%d-%d-%d",
855 rtc_start_date
= mktimegm(&tm
);
856 if (rtc_start_date
== -1) {
858 error_report("invalid date format");
859 error_printf("valid formats: "
860 "'2006-06-17T16:01:21' or '2006-06-17'\n");
863 rtc_date_offset
= qemu_time() - rtc_start_date
;
867 static void configure_rtc(QemuOpts
*opts
)
871 value
= qemu_opt_get(opts
, "base");
873 if (!strcmp(value
, "utc")) {
875 } else if (!strcmp(value
, "localtime")) {
876 Error
*blocker
= NULL
;
878 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
879 "-rtc base=localtime");
880 replay_add_blocker(blocker
);
882 configure_rtc_date_offset(value
, 0);
885 value
= qemu_opt_get(opts
, "clock");
887 if (!strcmp(value
, "host")) {
888 rtc_clock
= QEMU_CLOCK_HOST
;
889 } else if (!strcmp(value
, "rt")) {
890 rtc_clock
= QEMU_CLOCK_REALTIME
;
891 } else if (!strcmp(value
, "vm")) {
892 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
894 error_report("invalid option value '%s'", value
);
898 value
= qemu_opt_get(opts
, "driftfix");
900 if (!strcmp(value
, "slew")) {
901 static GlobalProperty slew_lost_ticks
= {
902 .driver
= "mc146818rtc",
903 .property
= "lost_tick_policy",
907 qdev_prop_register_global(&slew_lost_ticks
);
908 } else if (!strcmp(value
, "none")) {
909 /* discard is default */
911 error_report("invalid option value '%s'", value
);
917 /***********************************************************/
918 /* Bluetooth support */
921 static struct HCIInfo
*hci_table
[MAX_NICS
];
923 struct HCIInfo
*qemu_next_hci(void)
925 if (cur_hci
== nb_hcis
)
928 return hci_table
[cur_hci
++];
931 static int bt_hci_parse(const char *str
)
936 if (nb_hcis
>= MAX_NICS
) {
937 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
950 bdaddr
.b
[5] = 0x56 + nb_hcis
;
951 hci
->bdaddr_set(hci
, bdaddr
.b
);
953 hci_table
[nb_hcis
++] = hci
;
958 static void bt_vhci_add(int vlan_id
)
960 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
963 error_report("warning: adding a VHCI to an empty scatternet %i",
966 bt_vhci_init(bt_new_hci(vlan
));
969 static struct bt_device_s
*bt_device_add(const char *opt
)
971 struct bt_scatternet_s
*vlan
;
973 char *endp
= strstr(opt
, ",vlan=");
974 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
977 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
980 vlan_id
= strtol(endp
+ 6, &endp
, 0);
982 error_report("unrecognised bluetooth vlan Id");
987 vlan
= qemu_find_bt_vlan(vlan_id
);
990 error_report("warning: adding a slave device to an empty scatternet %i",
993 if (!strcmp(devname
, "keyboard"))
994 return bt_keyboard_init(vlan
);
996 error_report("unsupported bluetooth device '%s'", devname
);
1000 static int bt_parse(const char *opt
)
1002 const char *endp
, *p
;
1005 if (strstart(opt
, "hci", &endp
)) {
1006 if (!*endp
|| *endp
== ',') {
1008 if (!strstart(endp
, ",vlan=", 0))
1011 return bt_hci_parse(opt
);
1013 } else if (strstart(opt
, "vhci", &endp
)) {
1014 if (!*endp
|| *endp
== ',') {
1016 if (strstart(endp
, ",vlan=", &p
)) {
1017 vlan
= strtol(p
, (char **) &endp
, 0);
1019 error_report("bad scatternet '%s'", p
);
1023 error_report("bad parameter '%s'", endp
+ 1);
1032 } else if (strstart(opt
, "device:", &endp
))
1033 return !bt_device_add(endp
);
1035 error_report("bad bluetooth parameter '%s'", opt
);
1039 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1041 /* FIXME: change this to true for 1.3 */
1042 if (qemu_opt_get_bool(opts
, "enable", false)) {
1043 #ifdef CONFIG_SECCOMP
1044 if (seccomp_start() < 0) {
1045 error_report("failed to install seccomp syscall filter "
1050 error_report("seccomp support is disabled");
1058 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1060 const char *proc_name
;
1062 if (qemu_opt_get(opts
, "debug-threads")) {
1063 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1065 qemu_name
= qemu_opt_get(opts
, "guest");
1067 proc_name
= qemu_opt_get(opts
, "process");
1069 os_set_proc_name(proc_name
);
1075 bool defaults_enabled(void)
1077 return has_defaults
;
1081 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1083 int fd
, dupfd
, flags
;
1085 const char *fd_opaque
= NULL
;
1088 fd
= qemu_opt_get_number(opts
, "fd", -1);
1089 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1090 fd_opaque
= qemu_opt_get(opts
, "opaque");
1093 error_report("fd option is required and must be non-negative");
1097 if (fd
<= STDERR_FILENO
) {
1098 error_report("fd cannot be a standard I/O stream");
1103 * All fds inherited across exec() necessarily have FD_CLOEXEC
1104 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1106 flags
= fcntl(fd
, F_GETFD
);
1107 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1108 error_report("fd is not valid or already in use");
1113 error_report("set option is required and must be non-negative");
1117 #ifdef F_DUPFD_CLOEXEC
1118 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1122 qemu_set_cloexec(dupfd
);
1126 error_report("error duplicating fd: %s", strerror(errno
));
1130 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1131 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1138 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1142 fd
= qemu_opt_get_number(opts
, "fd", -1);
1149 /***********************************************************/
1150 /* QEMU Block devices */
1152 #define HD_OPTS "media=disk"
1153 #define CDROM_OPTS "media=cdrom"
1155 #define PFLASH_OPTS ""
1159 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1161 BlockInterfaceType
*block_default_type
= opaque
;
1163 return drive_new(opts
, *block_default_type
) == NULL
;
1166 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1168 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1169 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1174 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1175 int index
, const char *optstr
)
1180 if (!enable
|| drive_get_by_index(type
, index
)) {
1184 opts
= drive_add(type
, index
, NULL
, optstr
);
1186 drive_enable_snapshot(NULL
, opts
, NULL
);
1189 dinfo
= drive_new(opts
, type
);
1193 dinfo
->is_default
= true;
1197 static QemuOptsList qemu_smp_opts
= {
1199 .implied_opt_name
= "cpus",
1200 .merge_lists
= true,
1201 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1205 .type
= QEMU_OPT_NUMBER
,
1208 .type
= QEMU_OPT_NUMBER
,
1211 .type
= QEMU_OPT_NUMBER
,
1214 .type
= QEMU_OPT_NUMBER
,
1217 .type
= QEMU_OPT_NUMBER
,
1219 { /*End of list */ }
1223 static void smp_parse(QemuOpts
*opts
)
1226 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1227 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1228 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1229 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1231 /* compute missing values, prefer sockets over cores over threads */
1232 if (cpus
== 0 || sockets
== 0) {
1233 sockets
= sockets
> 0 ? sockets
: 1;
1234 cores
= cores
> 0 ? cores
: 1;
1235 threads
= threads
> 0 ? threads
: 1;
1237 cpus
= cores
* threads
* sockets
;
1239 } else if (cores
== 0) {
1240 threads
= threads
> 0 ? threads
: 1;
1241 cores
= cpus
/ (sockets
* threads
);
1242 cores
= cores
> 0 ? cores
: 1;
1243 } else if (threads
== 0) {
1244 threads
= cpus
/ (cores
* sockets
);
1245 threads
= threads
> 0 ? threads
: 1;
1246 } else if (sockets
* cores
* threads
< cpus
) {
1247 error_report("cpu topology: "
1248 "sockets (%u) * cores (%u) * threads (%u) < "
1250 sockets
, cores
, threads
, cpus
);
1254 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1256 if (max_cpus
< cpus
) {
1257 error_report("maxcpus must be equal to or greater than smp");
1261 if (sockets
* cores
* threads
> max_cpus
) {
1262 error_report("cpu topology: "
1263 "sockets (%u) * cores (%u) * threads (%u) > "
1265 sockets
, cores
, threads
, max_cpus
);
1271 smp_threads
= threads
;
1275 Error
*blocker
= NULL
;
1276 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1277 replay_add_blocker(blocker
);
1281 static void realtime_init(void)
1284 if (os_mlock() < 0) {
1285 error_report("locking memory failed");
1292 static void configure_msg(QemuOpts
*opts
)
1294 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1297 /***********************************************************/
1300 typedef struct SemihostingConfig
{
1302 SemihostingTarget target
;
1305 const char *cmdline
; /* concatenated argv */
1306 } SemihostingConfig
;
1308 static SemihostingConfig semihosting
;
1310 bool semihosting_enabled(void)
1312 return semihosting
.enabled
;
1315 SemihostingTarget
semihosting_get_target(void)
1317 return semihosting
.target
;
1320 const char *semihosting_get_arg(int i
)
1322 if (i
>= semihosting
.argc
) {
1325 return semihosting
.argv
[i
];
1328 int semihosting_get_argc(void)
1330 return semihosting
.argc
;
1333 const char *semihosting_get_cmdline(void)
1335 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1336 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1338 return semihosting
.cmdline
;
1341 static int add_semihosting_arg(void *opaque
,
1342 const char *name
, const char *val
,
1345 SemihostingConfig
*s
= opaque
;
1346 if (strcmp(name
, "arg") == 0) {
1348 /* one extra element as g_strjoinv() expects NULL-terminated array */
1349 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1350 s
->argv
[s
->argc
- 1] = val
;
1351 s
->argv
[s
->argc
] = NULL
;
1356 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1357 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1362 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1364 /* split -append and initialize argv[1..n] */
1365 cmd_token
= strtok(g_strdup(cmd
), " ");
1367 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1368 cmd_token
= strtok(NULL
, " ");
1372 /* Now we still need this for compatibility with XEN. */
1373 bool has_igd_gfx_passthru
;
1374 static void igd_gfx_passthru(void)
1376 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1379 /***********************************************************/
1382 static int usb_device_add(const char *devname
)
1384 USBDevice
*dev
= NULL
;
1385 #ifndef CONFIG_LINUX
1389 if (!machine_usb(current_machine
)) {
1393 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1394 dev
= usbdevice_create(devname
);
1398 /* the other ones */
1399 #ifndef CONFIG_LINUX
1400 /* only the linux version is qdev-ified, usb-bsd still needs this */
1401 if (strstart(devname
, "host:", &p
)) {
1402 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1412 static int usb_device_del(const char *devname
)
1417 if (strstart(devname
, "host:", &p
)) {
1421 if (!machine_usb(current_machine
)) {
1425 p
= strchr(devname
, '.');
1428 bus_num
= strtoul(devname
, NULL
, 0);
1429 addr
= strtoul(p
+ 1, NULL
, 0);
1431 return usb_device_delete_addr(bus_num
, addr
);
1434 static int usb_parse(const char *cmdline
)
1437 r
= usb_device_add(cmdline
);
1439 error_report("could not add USB device '%s'", cmdline
);
1444 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1446 const char *devname
= qdict_get_str(qdict
, "devname");
1447 if (usb_device_add(devname
) < 0) {
1448 error_report("could not add USB device '%s'", devname
);
1452 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1454 const char *devname
= qdict_get_str(qdict
, "devname");
1455 if (usb_device_del(devname
) < 0) {
1456 error_report("could not delete USB device '%s'", devname
);
1460 /***********************************************************/
1461 /* machine registration */
1463 MachineState
*current_machine
;
1465 static MachineClass
*find_machine(const char *name
)
1467 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1468 MachineClass
*mc
= NULL
;
1470 for (el
= machines
; el
; el
= el
->next
) {
1471 MachineClass
*temp
= el
->data
;
1473 if (!strcmp(temp
->name
, name
)) {
1478 !strcmp(temp
->alias
, name
)) {
1484 g_slist_free(machines
);
1488 MachineClass
*find_default_machine(void)
1490 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1491 MachineClass
*mc
= NULL
;
1493 for (el
= machines
; el
; el
= el
->next
) {
1494 MachineClass
*temp
= el
->data
;
1496 if (temp
->is_default
) {
1502 g_slist_free(machines
);
1506 MachineInfoList
*qmp_query_machines(Error
**errp
)
1508 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1509 MachineInfoList
*mach_list
= NULL
;
1511 for (el
= machines
; el
; el
= el
->next
) {
1512 MachineClass
*mc
= el
->data
;
1513 MachineInfoList
*entry
;
1516 info
= g_malloc0(sizeof(*info
));
1517 if (mc
->is_default
) {
1518 info
->has_is_default
= true;
1519 info
->is_default
= true;
1523 info
->has_alias
= true;
1524 info
->alias
= g_strdup(mc
->alias
);
1527 info
->name
= g_strdup(mc
->name
);
1528 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1529 info
->hotpluggable_cpus
= mc
->has_hotpluggable_cpus
;
1531 entry
= g_malloc0(sizeof(*entry
));
1532 entry
->value
= info
;
1533 entry
->next
= mach_list
;
1537 g_slist_free(machines
);
1541 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1543 ObjectProperty
*prop
;
1544 ObjectPropertyIterator iter
;
1546 if (!qemu_opt_has_help_opt(opts
)) {
1550 object_property_iter_init(&iter
, OBJECT(machine
));
1551 while ((prop
= object_property_iter_next(&iter
))) {
1556 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1557 prop
->name
, prop
->type
);
1558 if (prop
->description
) {
1559 error_printf(" (%s)\n", prop
->description
);
1568 /***********************************************************/
1569 /* main execution loop */
1571 struct vm_change_state_entry
{
1572 VMChangeStateHandler
*cb
;
1574 QLIST_ENTRY (vm_change_state_entry
) entries
;
1577 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1579 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1582 VMChangeStateEntry
*e
;
1584 e
= g_malloc0(sizeof (*e
));
1588 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1592 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1594 QLIST_REMOVE (e
, entries
);
1598 void vm_state_notify(int running
, RunState state
)
1600 VMChangeStateEntry
*e
, *next
;
1602 trace_vm_state_notify(running
, state
);
1604 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1605 e
->cb(e
->opaque
, running
, state
);
1609 static int reset_requested
;
1610 static int shutdown_requested
, shutdown_signal
= -1;
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 int qemu_shutdown_requested_get(void)
1626 return shutdown_requested
;
1629 int qemu_reset_requested_get(void)
1631 return reset_requested
;
1634 static int qemu_shutdown_requested(void)
1636 return atomic_xchg(&shutdown_requested
, 0);
1639 static void qemu_kill_report(void)
1641 if (!qtest_driver() && shutdown_signal
!= -1) {
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
= -1;
1659 static int qemu_reset_requested(void)
1661 int r
= reset_requested
;
1662 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1663 reset_requested
= 0;
1669 static int qemu_suspend_requested(void)
1671 int r
= suspend_requested
;
1672 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1673 suspend_requested
= 0;
1679 static WakeupReason
qemu_wakeup_requested(void)
1681 return wakeup_reason
;
1684 static int qemu_powerdown_requested(void)
1686 int r
= powerdown_requested
;
1687 powerdown_requested
= 0;
1691 static int qemu_debug_requested(void)
1693 int r
= debug_requested
;
1694 debug_requested
= 0;
1698 void qemu_system_reset(bool report
)
1702 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1704 cpu_synchronize_all_states();
1706 if (mc
&& mc
->reset
) {
1709 qemu_devices_reset();
1712 qapi_event_send_reset(&error_abort
);
1714 cpu_synchronize_all_post_reset();
1717 void qemu_system_guest_panicked(GuestPanicInformation
*info
)
1719 qemu_log_mask(LOG_GUEST_ERROR
, "Guest crashed\n");
1722 current_cpu
->crash_occurred
= true;
1724 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
,
1725 !!info
, info
, &error_abort
);
1726 vm_stop(RUN_STATE_GUEST_PANICKED
);
1728 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1729 !!info
, info
, &error_abort
);
1730 qemu_system_shutdown_request();
1734 if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_HYPER_V
) {
1735 qemu_log_mask(LOG_GUEST_ERROR
, "HV crash parameters: (%#"PRIx64
1736 " %#"PRIx64
" %#"PRIx64
" %#"PRIx64
" %#"PRIx64
")\n",
1737 info
->u
.hyper_v
.arg1
,
1738 info
->u
.hyper_v
.arg2
,
1739 info
->u
.hyper_v
.arg3
,
1740 info
->u
.hyper_v
.arg4
,
1741 info
->u
.hyper_v
.arg5
);
1743 qapi_free_GuestPanicInformation(info
);
1747 void qemu_system_reset_request(void)
1750 shutdown_requested
= 1;
1752 reset_requested
= 1;
1755 qemu_notify_event();
1758 static void qemu_system_suspend(void)
1761 notifier_list_notify(&suspend_notifiers
, NULL
);
1762 runstate_set(RUN_STATE_SUSPENDED
);
1763 qapi_event_send_suspend(&error_abort
);
1766 void qemu_system_suspend_request(void)
1768 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1771 suspend_requested
= 1;
1773 qemu_notify_event();
1776 void qemu_register_suspend_notifier(Notifier
*notifier
)
1778 notifier_list_add(&suspend_notifiers
, notifier
);
1781 void qemu_system_wakeup_request(WakeupReason reason
)
1783 trace_system_wakeup_request(reason
);
1785 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1788 if (!(wakeup_reason_mask
& (1 << reason
))) {
1791 runstate_set(RUN_STATE_RUNNING
);
1792 wakeup_reason
= reason
;
1793 qemu_notify_event();
1796 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1799 wakeup_reason_mask
|= (1 << reason
);
1801 wakeup_reason_mask
&= ~(1 << reason
);
1805 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1807 notifier_list_add(&wakeup_notifiers
, notifier
);
1810 void qemu_system_killed(int signal
, pid_t pid
)
1812 shutdown_signal
= signal
;
1816 /* Cannot call qemu_system_shutdown_request directly because
1817 * we are in a signal handler.
1819 shutdown_requested
= 1;
1820 qemu_notify_event();
1823 void qemu_system_shutdown_request(void)
1825 trace_qemu_system_shutdown_request();
1826 replay_shutdown_request();
1827 shutdown_requested
= 1;
1828 qemu_notify_event();
1831 static void qemu_system_powerdown(void)
1833 qapi_event_send_powerdown(&error_abort
);
1834 notifier_list_notify(&powerdown_notifiers
, NULL
);
1837 void qemu_system_powerdown_request(void)
1839 trace_qemu_system_powerdown_request();
1840 powerdown_requested
= 1;
1841 qemu_notify_event();
1844 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1846 notifier_list_add(&powerdown_notifiers
, notifier
);
1849 void qemu_system_debug_request(void)
1851 debug_requested
= 1;
1852 qemu_notify_event();
1855 static bool main_loop_should_exit(void)
1858 if (qemu_debug_requested()) {
1859 vm_stop(RUN_STATE_DEBUG
);
1861 if (qemu_suspend_requested()) {
1862 qemu_system_suspend();
1864 if (qemu_shutdown_requested()) {
1866 qapi_event_send_shutdown(&error_abort
);
1868 vm_stop(RUN_STATE_SHUTDOWN
);
1873 if (qemu_reset_requested()) {
1875 qemu_system_reset(VMRESET_REPORT
);
1877 if (!runstate_check(RUN_STATE_RUNNING
) &&
1878 !runstate_check(RUN_STATE_INMIGRATE
)) {
1879 runstate_set(RUN_STATE_PRELAUNCH
);
1882 if (qemu_wakeup_requested()) {
1884 qemu_system_reset(VMRESET_SILENT
);
1885 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1886 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1888 qapi_event_send_wakeup(&error_abort
);
1890 if (qemu_powerdown_requested()) {
1891 qemu_system_powerdown();
1893 if (qemu_vmstop_requested(&r
)) {
1899 static void main_loop(void)
1903 #ifdef CONFIG_PROFILER
1907 nonblocking
= tcg_enabled() && last_io
> 0;
1908 #ifdef CONFIG_PROFILER
1909 ti
= profile_getclock();
1911 last_io
= main_loop_wait(nonblocking
);
1912 #ifdef CONFIG_PROFILER
1913 dev_time
+= profile_getclock() - ti
;
1915 } while (!main_loop_should_exit());
1918 static void version(void)
1920 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1921 QEMU_COPYRIGHT
"\n");
1924 static void QEMU_NORETURN
help(int exitcode
)
1927 printf("usage: %s [options] [disk_image]\n\n"
1928 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1929 error_get_progname());
1931 #define QEMU_OPTIONS_GENERATE_HELP
1932 #include "qemu-options-wrapper.h"
1934 printf("\nDuring emulation, the following keys are useful:\n"
1935 "ctrl-alt-f toggle full screen\n"
1936 "ctrl-alt-n switch to virtual console 'n'\n"
1937 "ctrl-alt toggle mouse and keyboard grab\n"
1939 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1944 #define HAS_ARG 0x0001
1946 typedef struct QEMUOption
{
1953 static const QEMUOption qemu_options
[] = {
1954 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1955 #define QEMU_OPTIONS_GENERATE_OPTIONS
1956 #include "qemu-options-wrapper.h"
1960 typedef struct VGAInterfaceInfo
{
1961 const char *opt_name
; /* option name */
1962 const char *name
; /* human-readable name */
1963 /* Class names indicating that support is available.
1964 * If no class is specified, the interface is always available */
1965 const char *class_names
[2];
1968 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1974 .name
= "standard VGA",
1975 .class_names
= { "VGA", "isa-vga" },
1978 .opt_name
= "cirrus",
1979 .name
= "Cirrus VGA",
1980 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1983 .opt_name
= "vmware",
1984 .name
= "VMWare SVGA",
1985 .class_names
= { "vmware-svga" },
1988 .opt_name
= "virtio",
1989 .name
= "Virtio VGA",
1990 .class_names
= { "virtio-vga" },
1995 .class_names
= { "qxl-vga" },
1999 .name
= "TCX framebuffer",
2000 .class_names
= { "SUNW,tcx" },
2004 .name
= "CG3 framebuffer",
2005 .class_names
= { "cgthree" },
2008 .opt_name
= "xenfb",
2012 static bool vga_interface_available(VGAInterfaceType t
)
2014 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2016 assert(t
< VGA_TYPE_MAX
);
2017 return !ti
->class_names
[0] ||
2018 object_class_by_name(ti
->class_names
[0]) ||
2019 object_class_by_name(ti
->class_names
[1]);
2022 static void select_vgahw(const char *p
)
2027 assert(vga_interface_type
== VGA_NONE
);
2028 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2029 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2030 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2031 if (!vga_interface_available(t
)) {
2032 error_report("%s not available", ti
->name
);
2035 vga_interface_type
= t
;
2039 if (t
== VGA_TYPE_MAX
) {
2041 error_report("unknown vga type: %s", p
);
2045 const char *nextopt
;
2047 if (strstart(opts
, ",retrace=", &nextopt
)) {
2049 if (strstart(opts
, "dumb", &nextopt
))
2050 vga_retrace_method
= VGA_RETRACE_DUMB
;
2051 else if (strstart(opts
, "precise", &nextopt
))
2052 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2053 else goto invalid_vga
;
2054 } else goto invalid_vga
;
2059 typedef enum DisplayType
{
2068 static DisplayType
select_display(const char *p
)
2071 DisplayType display
= DT_DEFAULT
;
2073 if (strstart(p
, "sdl", &opts
)) {
2077 const char *nextopt
;
2079 if (strstart(opts
, ",frame=", &nextopt
)) {
2081 if (strstart(opts
, "on", &nextopt
)) {
2083 } else if (strstart(opts
, "off", &nextopt
)) {
2086 goto invalid_sdl_args
;
2088 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2090 if (strstart(opts
, "on", &nextopt
)) {
2092 } else if (strstart(opts
, "off", &nextopt
)) {
2095 goto invalid_sdl_args
;
2097 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2099 if (strstart(opts
, "on", &nextopt
)) {
2101 } else if (strstart(opts
, "off", &nextopt
)) {
2104 goto invalid_sdl_args
;
2106 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2108 if (strstart(opts
, "on", &nextopt
)) {
2110 } else if (strstart(opts
, "off", &nextopt
)) {
2113 goto invalid_sdl_args
;
2115 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2117 if (strstart(opts
, "on", &nextopt
)) {
2119 } else if (strstart(opts
, "off", &nextopt
)) {
2122 goto invalid_sdl_args
;
2126 error_report("invalid SDL option string");
2132 error_report("SDL support is disabled");
2135 } else if (strstart(p
, "vnc", &opts
)) {
2137 vnc_parse(opts
+ 1, &error_fatal
);
2139 error_report("VNC requires a display argument vnc=<display>");
2142 } else if (strstart(p
, "curses", &opts
)) {
2143 #ifdef CONFIG_CURSES
2144 display
= DT_CURSES
;
2146 error_report("curses support is disabled");
2149 } else if (strstart(p
, "gtk", &opts
)) {
2153 const char *nextopt
;
2155 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2157 if (strstart(opts
, "on", &nextopt
)) {
2158 grab_on_hover
= true;
2159 } else if (strstart(opts
, "off", &nextopt
)) {
2160 grab_on_hover
= false;
2162 goto invalid_gtk_args
;
2164 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2166 if (strstart(opts
, "on", &nextopt
)) {
2168 } else if (strstart(opts
, "off", &nextopt
)) {
2171 goto invalid_gtk_args
;
2175 error_report("invalid GTK option string");
2181 error_report("GTK support is disabled");
2184 } else if (strstart(p
, "none", &opts
)) {
2187 error_report("unknown display type");
2194 static int balloon_parse(const char *arg
)
2198 if (strcmp(arg
, "none") == 0) {
2202 if (!strncmp(arg
, "virtio", 6)) {
2203 if (arg
[6] == ',') {
2204 /* have params -> parse them */
2205 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2210 /* create empty opts */
2211 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2214 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2221 #if defined(CONFIG_RUBY)
2222 /* Ruby interface for QEMU. See README.EXT for programming example. */
2226 static VALUE
qemu_open(int argc
, VALUE
*argv
, VALUE klass
)
2229 for (i
= 0; i
< argc
; i
++) {
2230 argv
[i
] = StringValue(argv
[i
]);
2231 fprintf(stderr
, "argv[%d] = %s\n", i
, StringValuePtr(argv
[i
]));
2233 //~ if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
2234 //~ mode = 0666; /* default value */
2236 return INT2FIX(argc
);
2239 void Init_qemu(void)
2241 printf("%s\n", __func__
);
2242 VALUE cQEMU
= rb_define_class("QEMU", rb_cObject
);
2243 rb_define_singleton_method(cQEMU
, "run", qemu_open
, -1);
2248 #endif /* CONFIG_RUBY */
2250 #if defined(CONFIG_DLL)
2251 BOOL APIENTRY
DllMain(HINSTANCE hModule
, DWORD ul_reason_for_call
, LPVOID data
)
2255 #endif /* CONFIG_DLL */
2257 char *qemu_find_file(int type
, const char *name
)
2263 /* Try the name as a straight path first */
2264 if (access(name
, R_OK
) == 0) {
2265 trace_load_file(name
, name
);
2266 return g_strdup(name
);
2270 case QEMU_FILE_TYPE_BIOS
:
2273 case QEMU_FILE_TYPE_KEYMAP
:
2274 subdir
= "keymaps/";
2280 for (i
= 0; i
< data_dir_idx
; i
++) {
2281 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2282 if (access(buf
, R_OK
) == 0) {
2283 trace_load_file(name
, buf
);
2291 static inline bool nonempty_str(const char *str
)
2296 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2300 const char *name
, *file
, *str
;
2301 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2303 if (fw_cfg
== NULL
) {
2304 error_report("fw_cfg device not available");
2307 name
= qemu_opt_get(opts
, "name");
2308 file
= qemu_opt_get(opts
, "file");
2309 str
= qemu_opt_get(opts
, "string");
2311 /* we need name and either a file or the content string */
2312 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2313 error_report("invalid argument(s)");
2316 if (nonempty_str(file
) && nonempty_str(str
)) {
2317 error_report("file and string are mutually exclusive");
2320 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2321 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2324 if (strncmp(name
, "opt/", 4) != 0) {
2325 error_report("warning: externally provided fw_cfg item names "
2326 "should be prefixed with \"opt/\"");
2328 if (nonempty_str(str
)) {
2329 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2330 buf
= g_memdup(str
, size
);
2332 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2333 error_report("can't load %s", file
);
2337 /* For legacy, keep user files in a specific global order. */
2338 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2339 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2340 fw_cfg_reset_order_override(fw_cfg
);
2344 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2346 return qdev_device_help(opts
);
2349 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2354 dev
= qdev_device_add(opts
, &err
);
2356 error_report_err(err
);
2359 object_unref(OBJECT(dev
));
2363 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2365 Error
*local_err
= NULL
;
2367 qemu_chr_new_from_opts(opts
, &local_err
);
2369 error_report_err(local_err
);
2375 #ifdef CONFIG_VIRTFS
2376 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2378 return qemu_fsdev_add(opts
);
2382 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2385 const char *chardev
;
2389 mode
= qemu_opt_get(opts
, "mode");
2393 if (strcmp(mode
, "readline") == 0) {
2394 flags
= MONITOR_USE_READLINE
;
2395 } else if (strcmp(mode
, "control") == 0) {
2396 flags
= MONITOR_USE_CONTROL
;
2398 error_report("unknown monitor mode \"%s\"", mode
);
2402 if (qemu_opt_get_bool(opts
, "pretty", 0))
2403 flags
|= MONITOR_USE_PRETTY
;
2405 if (qemu_opt_get_bool(opts
, "default", 0)) {
2406 error_report("option 'default' does nothing and is deprecated");
2409 chardev
= qemu_opt_get(opts
, "chardev");
2410 chr
= qemu_chr_find(chardev
);
2412 error_report("chardev \"%s\" not found", chardev
);
2416 monitor_init(chr
, flags
);
2420 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2422 static int monitor_device_index
= 0;
2427 if (strstart(optarg
, "chardev:", &p
)) {
2428 snprintf(label
, sizeof(label
), "%s", p
);
2430 snprintf(label
, sizeof(label
), "compat_monitor%d",
2431 monitor_device_index
);
2432 opts
= qemu_chr_parse_compat(label
, optarg
);
2434 error_report("parse error: %s", optarg
);
2439 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2440 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2441 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2442 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2443 monitor_device_index
++;
2446 struct device_config
{
2448 DEV_USB
, /* -usbdevice */
2450 DEV_SERIAL
, /* -serial */
2451 DEV_PARALLEL
, /* -parallel */
2452 DEV_VIRTCON
, /* -virtioconsole */
2453 DEV_DEBUGCON
, /* -debugcon */
2454 DEV_GDB
, /* -gdb, -s */
2455 DEV_SCLP
, /* s390 sclp */
2457 const char *cmdline
;
2459 QTAILQ_ENTRY(device_config
) next
;
2462 static QTAILQ_HEAD(, device_config
) device_configs
=
2463 QTAILQ_HEAD_INITIALIZER(device_configs
);
2465 static void add_device_config(int type
, const char *cmdline
)
2467 struct device_config
*conf
;
2469 conf
= g_malloc0(sizeof(*conf
));
2471 conf
->cmdline
= cmdline
;
2472 loc_save(&conf
->loc
);
2473 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2476 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2478 struct device_config
*conf
;
2481 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2482 if (conf
->type
!= type
)
2484 loc_push_restore(&conf
->loc
);
2485 rc
= func(conf
->cmdline
);
2486 loc_pop(&conf
->loc
);
2494 static int serial_parse(const char *devname
)
2496 static int index
= 0;
2499 if (strcmp(devname
, "none") == 0)
2501 if (index
== MAX_SERIAL_PORTS
) {
2502 error_report("too many serial ports");
2505 snprintf(label
, sizeof(label
), "serial%d", index
);
2506 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2507 if (!serial_hds
[index
]) {
2508 error_report("could not connect serial device"
2509 " to character backend '%s'", devname
);
2516 static int parallel_parse(const char *devname
)
2518 static int index
= 0;
2521 if (strcmp(devname
, "none") == 0)
2523 if (index
== MAX_PARALLEL_PORTS
) {
2524 error_report("too many parallel ports");
2527 snprintf(label
, sizeof(label
), "parallel%d", index
);
2528 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2529 if (!parallel_hds
[index
]) {
2530 error_report("could not connect parallel device"
2531 " to character backend '%s'", devname
);
2538 static int virtcon_parse(const char *devname
)
2540 QemuOptsList
*device
= qemu_find_opts("device");
2541 static int index
= 0;
2543 QemuOpts
*bus_opts
, *dev_opts
;
2545 if (strcmp(devname
, "none") == 0)
2547 if (index
== MAX_VIRTIO_CONSOLES
) {
2548 error_report("too many virtio consoles");
2552 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2553 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2555 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2556 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2558 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2559 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2560 if (!virtcon_hds
[index
]) {
2561 error_report("could not connect virtio console"
2562 " to character backend '%s'", devname
);
2565 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2571 static int sclp_parse(const char *devname
)
2573 QemuOptsList
*device
= qemu_find_opts("device");
2574 static int index
= 0;
2578 if (strcmp(devname
, "none") == 0) {
2581 if (index
== MAX_SCLP_CONSOLES
) {
2582 error_report("too many sclp consoles");
2586 assert(arch_type
== QEMU_ARCH_S390X
);
2588 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2589 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2591 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2592 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2593 if (!sclp_hds
[index
]) {
2594 error_report("could not connect sclp console"
2595 " to character backend '%s'", devname
);
2598 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2604 static int debugcon_parse(const char *devname
)
2608 if (!qemu_chr_new("debugcon", devname
)) {
2611 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2613 error_report("already have a debugcon device");
2616 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2617 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2621 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2623 const MachineClass
*mc1
= a
, *mc2
= b
;
2626 if (mc1
->family
== NULL
) {
2627 if (mc2
->family
== NULL
) {
2628 /* Compare standalone machine types against each other; they sort
2629 * in increasing order.
2631 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2632 object_class_get_name(OBJECT_CLASS(mc2
)));
2635 /* Standalone machine types sort after families. */
2639 if (mc2
->family
== NULL
) {
2640 /* Families sort before standalone machine types. */
2644 /* Families sort between each other alphabetically increasingly. */
2645 res
= strcmp(mc1
->family
, mc2
->family
);
2650 /* Within the same family, machine types sort in decreasing order. */
2651 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2652 object_class_get_name(OBJECT_CLASS(mc1
)));
2655 static MachineClass
*machine_parse(const char *name
)
2657 MachineClass
*mc
= NULL
;
2658 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2661 mc
= find_machine(name
);
2664 g_slist_free(machines
);
2667 if (name
&& !is_help_option(name
)) {
2668 error_report("unsupported machine type");
2669 error_printf("Use -machine help to list supported machines\n");
2671 printf("Supported machines are:\n");
2672 machines
= g_slist_sort(machines
, machine_class_cmp
);
2673 for (el
= machines
; el
; el
= el
->next
) {
2674 MachineClass
*mc
= el
->data
;
2676 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2678 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2679 mc
->is_default
? " (default)" : "");
2683 g_slist_free(machines
);
2684 exit(!name
|| !is_help_option(name
));
2687 void qemu_add_exit_notifier(Notifier
*notify
)
2689 notifier_list_add(&exit_notifiers
, notify
);
2692 void qemu_remove_exit_notifier(Notifier
*notify
)
2694 notifier_remove(notify
);
2697 static void qemu_run_exit_notifiers(void)
2699 notifier_list_notify(&exit_notifiers
, NULL
);
2702 static bool machine_init_done
;
2704 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2706 notifier_list_add(&machine_init_done_notifiers
, notify
);
2707 if (machine_init_done
) {
2708 notify
->notify(notify
, NULL
);
2712 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2714 notifier_remove(notify
);
2717 static void qemu_run_machine_init_done_notifiers(void)
2719 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2720 machine_init_done
= true;
2723 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2724 const char **poptarg
, int *poptind
)
2726 const QEMUOption
*popt
;
2727 int optind
= *poptind
;
2728 char *r
= argv
[optind
];
2731 loc_set_cmdline(argv
, optind
, 1);
2733 /* Treat --foo the same as -foo. */
2736 popt
= qemu_options
;
2739 error_report("invalid option");
2742 if (!strcmp(popt
->name
, r
+ 1))
2746 if (popt
->flags
& HAS_ARG
) {
2747 if (optind
>= argc
) {
2748 error_report("requires an argument");
2751 optarg
= argv
[optind
++];
2752 loc_set_cmdline(argv
, optind
- 2, 2);
2763 static MachineClass
*select_machine(void)
2765 MachineClass
*machine_class
= find_default_machine();
2770 loc_push_none(&loc
);
2772 opts
= qemu_get_machine_opts();
2773 qemu_opts_loc_restore(opts
);
2775 optarg
= qemu_opt_get(opts
, "type");
2777 machine_class
= machine_parse(optarg
);
2780 if (!machine_class
) {
2781 error_report("No machine specified, and there is no default");
2782 error_printf("Use -machine help to list supported machines\n");
2787 return machine_class
;
2790 static int machine_set_property(void *opaque
,
2791 const char *name
, const char *value
,
2794 Object
*obj
= OBJECT(opaque
);
2795 Error
*local_err
= NULL
;
2798 if (strcmp(name
, "type") == 0) {
2802 qom_name
= g_strdup(name
);
2803 for (p
= qom_name
; *p
; p
++) {
2809 object_property_parse(obj
, value
, qom_name
, &local_err
);
2813 error_report_err(local_err
);
2822 * Initial object creation happens before all other
2823 * QEMU data types are created. The majority of objects
2824 * can be created at this point. The rng-egd object
2825 * cannot be created here, as it depends on the chardev
2828 static bool object_create_initial(const char *type
)
2830 if (g_str_equal(type
, "rng-egd")) {
2835 * return false for concrete netfilters since
2836 * they depend on netdevs already existing
2838 if (g_str_equal(type
, "filter-buffer") ||
2839 g_str_equal(type
, "filter-dump") ||
2840 g_str_equal(type
, "filter-mirror") ||
2841 g_str_equal(type
, "filter-redirector") ||
2842 g_str_equal(type
, "colo-compare") ||
2843 g_str_equal(type
, "filter-rewriter") ||
2844 g_str_equal(type
, "filter-replay")) {
2848 /* Memory allocation by backends needs to be done
2849 * after configure_accelerator() (due to the tcg_enabled()
2850 * checks at memory_region_init_*()).
2852 * Also, allocation of large amounts of memory may delay
2853 * chardev initialization for too long, and trigger timeouts
2854 * on software that waits for a monitor socket to be created
2857 if (g_str_has_prefix(type
, "memory-backend-")) {
2866 * The remainder of object creation happens after the
2867 * creation of chardev, fsdev, net clients and device data types.
2869 static bool object_create_delayed(const char *type
)
2871 return !object_create_initial(type
);
2875 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2879 const char *mem_str
;
2880 const char *maxmem_str
, *slots_str
;
2881 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2882 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2885 loc_push_none(&loc
);
2886 qemu_opts_loc_restore(opts
);
2889 mem_str
= qemu_opt_get(opts
, "size");
2892 error_report("missing 'size' option value");
2896 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2898 /* Fix up legacy suffix-less format */
2899 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2900 uint64_t overflow_check
= sz
;
2903 if ((sz
>> 20) != overflow_check
) {
2904 error_report("too large 'size' option value");
2910 /* backward compatibility behaviour for case "-m 0" */
2912 sz
= default_ram_size
;
2915 sz
= QEMU_ALIGN_UP(sz
, 8192);
2917 if (ram_size
!= sz
) {
2918 error_report("ram size too large");
2922 /* store value for the future use */
2923 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2924 *maxram_size
= ram_size
;
2926 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2927 slots_str
= qemu_opt_get(opts
, "slots");
2928 if (maxmem_str
&& slots_str
) {
2931 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2932 slots
= qemu_opt_get_number(opts
, "slots", 0);
2933 if (sz
< ram_size
) {
2934 error_report("invalid value of -m option maxmem: "
2935 "maximum memory size (0x%" PRIx64
") must be at least "
2936 "the initial memory size (0x" RAM_ADDR_FMT
")",
2939 } else if (sz
> ram_size
) {
2941 error_report("invalid value of -m option: maxmem was "
2942 "specified, but no hotplug slots were specified");
2946 error_report("invalid value of -m option maxmem: "
2947 "memory slots were specified but maximum memory size "
2948 "(0x%" PRIx64
") is equal to the initial memory size "
2949 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2955 } else if ((!maxmem_str
&& slots_str
) ||
2956 (maxmem_str
&& !slots_str
)) {
2957 error_report("invalid -m option value: missing "
2958 "'%s' option", slots_str
? "maxmem" : "slots");
2965 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2969 g
= g_malloc0(sizeof(*g
));
2970 g
->driver
= qemu_opt_get(opts
, "driver");
2971 g
->property
= qemu_opt_get(opts
, "property");
2972 g
->value
= qemu_opt_get(opts
, "value");
2973 g
->user_provided
= true;
2974 g
->errp
= &error_fatal
;
2975 qdev_prop_register_global(g
);
2979 static int qemu_read_default_config_file(void)
2983 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2984 if (ret
< 0 && ret
!= -ENOENT
) {
2991 int main(int argc
, char **argv
)
2994 int snapshot
, linux_boot
;
2995 const char *initrd_filename
;
2996 const char *kernel_filename
, *kernel_cmdline
;
2997 const char *boot_order
= NULL
;
2998 const char *boot_once
= NULL
;
3000 int cyls
, heads
, secs
, translation
;
3001 QemuOpts
*opts
, *machine_opts
;
3002 QemuOpts
*hda_opts
= NULL
, *icount_opts
= NULL
, *accel_opts
= NULL
;
3003 QemuOptsList
*olist
;
3006 const char *loadvm
= NULL
;
3007 MachineClass
*machine_class
;
3008 const char *cpu_model
;
3009 const char *vga_model
= NULL
;
3010 const char *qtest_chrdev
= NULL
;
3011 const char *qtest_log
= NULL
;
3012 const char *pid_file
= NULL
;
3013 const char *incoming
= NULL
;
3014 bool defconfig
= true;
3015 bool userconfig
= true;
3016 bool nographic
= false;
3017 DisplayType display_type
= DT_DEFAULT
;
3018 int display_remote
= 0;
3019 const char *log_mask
= NULL
;
3020 const char *log_file
= NULL
;
3021 char *trace_file
= NULL
;
3022 ram_addr_t maxram_size
;
3023 uint64_t ram_slots
= 0;
3024 FILE *vmstate_dump_file
= NULL
;
3025 Error
*main_loop_err
= NULL
;
3027 bool list_data_dirs
= false;
3028 typedef struct BlockdevOptions_queue
{
3029 BlockdevOptions
*bdo
;
3031 QSIMPLEQ_ENTRY(BlockdevOptions_queue
) entry
;
3032 } BlockdevOptions_queue
;
3033 QSIMPLEQ_HEAD(, BlockdevOptions_queue
) bdo_queue
3034 = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
3036 module_call_init(MODULE_INIT_TRACE
);
3038 qemu_init_cpu_list();
3039 qemu_init_cpu_loop();
3040 qemu_mutex_lock_iothread();
3042 atexit(qemu_run_exit_notifiers
);
3043 error_set_progname(argv
[0]);
3044 qemu_init_exec_dir(argv
[0]);
3046 module_call_init(MODULE_INIT_QOM
);
3047 monitor_init_qmp_commands();
3049 qemu_add_opts(&qemu_drive_opts
);
3050 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3051 qemu_add_drive_opts(&qemu_common_drive_opts
);
3052 qemu_add_drive_opts(&qemu_drive_opts
);
3053 qemu_add_drive_opts(&bdrv_runtime_opts
);
3054 qemu_add_opts(&qemu_chardev_opts
);
3055 qemu_add_opts(&qemu_device_opts
);
3056 qemu_add_opts(&qemu_netdev_opts
);
3057 qemu_add_opts(&qemu_net_opts
);
3058 qemu_add_opts(&qemu_rtc_opts
);
3059 qemu_add_opts(&qemu_global_opts
);
3060 qemu_add_opts(&qemu_mon_opts
);
3061 qemu_add_opts(&qemu_trace_opts
);
3062 qemu_add_opts(&qemu_option_rom_opts
);
3063 qemu_add_opts(&qemu_machine_opts
);
3064 qemu_add_opts(&qemu_accel_opts
);
3065 qemu_add_opts(&qemu_mem_opts
);
3066 qemu_add_opts(&qemu_smp_opts
);
3067 qemu_add_opts(&qemu_boot_opts
);
3068 qemu_add_opts(&qemu_sandbox_opts
);
3069 qemu_add_opts(&qemu_add_fd_opts
);
3070 qemu_add_opts(&qemu_object_opts
);
3071 qemu_add_opts(&qemu_tpmdev_opts
);
3072 qemu_add_opts(&qemu_realtime_opts
);
3073 qemu_add_opts(&qemu_msg_opts
);
3074 qemu_add_opts(&qemu_name_opts
);
3075 qemu_add_opts(&qemu_numa_opts
);
3076 qemu_add_opts(&qemu_icount_opts
);
3077 qemu_add_opts(&qemu_semihosting_config_opts
);
3078 qemu_add_opts(&qemu_fw_cfg_opts
);
3079 module_call_init(MODULE_INIT_OPTS
);
3083 if (qcrypto_init(&err
) < 0) {
3084 error_reportf_err(err
, "cannot initialize crypto: ");
3087 rtc_clock
= QEMU_CLOCK_HOST
;
3089 QLIST_INIT (&vm_change_state_head
);
3090 os_setup_early_signal_handling();
3094 cyls
= heads
= secs
= 0;
3095 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3099 bdrv_init_with_whitelist();
3103 /* first pass of option parsing */
3105 while (optind
< argc
) {
3106 if (argv
[optind
][0] != '-') {
3110 const QEMUOption
*popt
;
3112 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3113 switch (popt
->index
) {
3114 case QEMU_OPTION_nodefconfig
:
3117 case QEMU_OPTION_nouserconfig
:
3124 if (defconfig
&& userconfig
) {
3125 if (qemu_read_default_config_file() < 0) {
3130 /* second pass of option parsing */
3135 if (argv
[optind
][0] != '-') {
3136 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3138 const QEMUOption
*popt
;
3140 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3141 if (!(popt
->arch_mask
& arch_type
)) {
3142 error_report("Option not supported for this target");
3145 switch(popt
->index
) {
3146 case QEMU_OPTION_no_kvm_irqchip
: {
3147 olist
= qemu_find_opts("machine");
3148 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3151 case QEMU_OPTION_cpu
:
3152 /* hw initialization will check this */
3155 case QEMU_OPTION_hda
:
3159 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3161 snprintf(buf
, sizeof(buf
),
3162 "%s,cyls=%d,heads=%d,secs=%d%s",
3163 HD_OPTS
, cyls
, heads
, secs
,
3164 translation
== BIOS_ATA_TRANSLATION_LBA
?
3166 translation
== BIOS_ATA_TRANSLATION_NONE
?
3167 ",trans=none" : "");
3168 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3171 case QEMU_OPTION_hdb
:
3172 case QEMU_OPTION_hdc
:
3173 case QEMU_OPTION_hdd
:
3174 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3177 case QEMU_OPTION_blockdev
:
3180 BlockdevOptions_queue
*bdo
;
3182 v
= qobject_input_visitor_new_str(optarg
, "driver", &err
);
3184 error_report_err(err
);
3188 bdo
= g_new(BlockdevOptions_queue
, 1);
3189 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
3192 loc_save(&bdo
->loc
);
3193 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
3196 case QEMU_OPTION_drive
:
3197 if (drive_def(optarg
) == NULL
) {
3201 case QEMU_OPTION_set
:
3202 if (qemu_set_option(optarg
) != 0)
3205 case QEMU_OPTION_global
:
3206 if (qemu_global_option(optarg
) != 0)
3209 case QEMU_OPTION_mtdblock
:
3210 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3212 case QEMU_OPTION_sd
:
3213 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3215 case QEMU_OPTION_pflash
:
3216 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3218 case QEMU_OPTION_snapshot
:
3221 case QEMU_OPTION_hdachs
:
3225 cyls
= strtol(p
, (char **)&p
, 0);
3226 if (cyls
< 1 || cyls
> 16383)
3231 heads
= strtol(p
, (char **)&p
, 0);
3232 if (heads
< 1 || heads
> 16)
3237 secs
= strtol(p
, (char **)&p
, 0);
3238 if (secs
< 1 || secs
> 63)
3242 if (!strcmp(p
, "large")) {
3243 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3244 } else if (!strcmp(p
, "rechs")) {
3245 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3246 } else if (!strcmp(p
, "none")) {
3247 translation
= BIOS_ATA_TRANSLATION_NONE
;
3248 } else if (!strcmp(p
, "lba")) {
3249 translation
= BIOS_ATA_TRANSLATION_LBA
;
3250 } else if (!strcmp(p
, "auto")) {
3251 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3255 } else if (*p
!= '\0') {
3257 error_report("invalid physical CHS format");
3260 if (hda_opts
!= NULL
) {
3261 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3263 qemu_opt_set_number(hda_opts
, "heads", heads
,
3265 qemu_opt_set_number(hda_opts
, "secs", secs
,
3267 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3268 qemu_opt_set(hda_opts
, "trans", "large",
3270 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3271 qemu_opt_set(hda_opts
, "trans", "rechs",
3273 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3274 qemu_opt_set(hda_opts
, "trans", "lba",
3276 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3277 qemu_opt_set(hda_opts
, "trans", "none",
3283 case QEMU_OPTION_numa
:
3284 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3290 case QEMU_OPTION_display
:
3291 display_type
= select_display(optarg
);
3293 case QEMU_OPTION_nographic
:
3294 olist
= qemu_find_opts("machine");
3295 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3297 display_type
= DT_NONE
;
3299 case QEMU_OPTION_curses
:
3300 #ifdef CONFIG_CURSES
3301 display_type
= DT_CURSES
;
3303 error_report("curses support is disabled");
3307 case QEMU_OPTION_portrait
:
3308 graphic_rotate
= 90;
3310 case QEMU_OPTION_rotate
:
3311 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3312 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3313 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3314 error_report("only 90, 180, 270 deg rotation is available");
3318 case QEMU_OPTION_kernel
:
3319 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3322 case QEMU_OPTION_initrd
:
3323 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3326 case QEMU_OPTION_append
:
3327 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3330 case QEMU_OPTION_dtb
:
3331 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3334 case QEMU_OPTION_cdrom
:
3335 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3337 case QEMU_OPTION_boot
:
3338 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3344 case QEMU_OPTION_fda
:
3345 case QEMU_OPTION_fdb
:
3346 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3349 case QEMU_OPTION_no_fd_bootchk
:
3352 case QEMU_OPTION_netdev
:
3354 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3358 case QEMU_OPTION_net
:
3360 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3364 #ifdef CONFIG_LIBISCSI
3365 case QEMU_OPTION_iscsi
:
3366 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3374 case QEMU_OPTION_tftp
:
3375 error_report("The -tftp option is deprecated. "
3376 "Please use '-netdev user,tftp=...' instead.");
3377 legacy_tftp_prefix
= optarg
;
3379 case QEMU_OPTION_bootp
:
3380 error_report("The -bootp option is deprecated. "
3381 "Please use '-netdev user,bootfile=...' instead.");
3382 legacy_bootp_filename
= optarg
;
3384 case QEMU_OPTION_redir
:
3385 error_report("The -redir option is deprecated. "
3386 "Please use '-netdev user,hostfwd=...' instead.");
3387 if (net_slirp_redir(optarg
) < 0)
3391 case QEMU_OPTION_bt
:
3392 add_device_config(DEV_BT
, optarg
);
3394 case QEMU_OPTION_audio_help
:
3398 case QEMU_OPTION_soundhw
:
3399 select_soundhw (optarg
);
3404 case QEMU_OPTION_version
:
3409 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3416 case QEMU_OPTION_tpmdev
:
3417 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3422 case QEMU_OPTION_mempath
:
3425 case QEMU_OPTION_mem_prealloc
:
3434 case QEMU_OPTION_DFILTER
:
3435 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3438 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3440 case QEMU_OPTION_gdb
:
3441 add_device_config(DEV_GDB
, optarg
);
3444 if (is_help_option(optarg
)) {
3445 list_data_dirs
= true;
3446 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3447 data_dir
[data_dir_idx
++] = optarg
;
3450 case QEMU_OPTION_bios
:
3451 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3454 case QEMU_OPTION_singlestep
:
3461 keyboard_layout
= optarg
;
3463 case QEMU_OPTION_localtime
:
3466 case QEMU_OPTION_vga
:
3475 w
= strtol(p
, (char **)&p
, 10);
3478 error_report("invalid resolution or depth");
3484 h
= strtol(p
, (char **)&p
, 10);
3489 depth
= strtol(p
, (char **)&p
, 10);
3490 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3491 depth
!= 24 && depth
!= 32)
3493 } else if (*p
== '\0') {
3494 depth
= graphic_depth
;
3501 graphic_depth
= depth
;
3504 case QEMU_OPTION_echr
:
3507 term_escape_char
= strtol(optarg
, &r
, 0);
3509 printf("Bad argument to echr\n");
3512 case QEMU_OPTION_monitor
:
3513 default_monitor
= 0;
3514 if (strncmp(optarg
, "none", 4)) {
3515 monitor_parse(optarg
, "readline", false);
3518 case QEMU_OPTION_qmp
:
3519 monitor_parse(optarg
, "control", false);
3520 default_monitor
= 0;
3522 case QEMU_OPTION_qmp_pretty
:
3523 monitor_parse(optarg
, "control", true);
3524 default_monitor
= 0;
3526 case QEMU_OPTION_mon
:
3527 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3532 default_monitor
= 0;
3534 case QEMU_OPTION_chardev
:
3535 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3541 case QEMU_OPTION_fsdev
:
3542 olist
= qemu_find_opts("fsdev");
3544 error_report("fsdev support is disabled");
3547 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3552 case QEMU_OPTION_virtfs
: {
3555 const char *writeout
, *sock_fd
, *socket
;
3557 olist
= qemu_find_opts("virtfs");
3559 error_report("virtfs support is disabled");
3562 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3567 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3568 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3569 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3572 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3573 qemu_opt_get(opts
, "mount_tag"),
3576 error_report("duplicate fsdev id: %s",
3577 qemu_opt_get(opts
, "mount_tag"));
3581 writeout
= qemu_opt_get(opts
, "writeout");
3583 #ifdef CONFIG_SYNC_FILE_RANGE
3584 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3586 error_report("writeout=immediate not supported "
3587 "on this platform");
3591 qemu_opt_set(fsdev
, "fsdriver",
3592 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3593 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3595 qemu_opt_set(fsdev
, "security_model",
3596 qemu_opt_get(opts
, "security_model"),
3598 socket
= qemu_opt_get(opts
, "socket");
3600 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3602 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3604 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3607 qemu_opt_set_bool(fsdev
, "readonly",
3608 qemu_opt_get_bool(opts
, "readonly", 0),
3610 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3612 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3613 qemu_opt_set(device
, "fsdev",
3614 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3615 qemu_opt_set(device
, "mount_tag",
3616 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3619 case QEMU_OPTION_virtfs_synth
: {
3623 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3626 error_report("duplicate option: %s", "virtfs_synth");
3629 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3631 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3633 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3634 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3635 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3638 case QEMU_OPTION_serial
:
3639 add_device_config(DEV_SERIAL
, optarg
);
3641 if (strncmp(optarg
, "mon:", 4) == 0) {
3642 default_monitor
= 0;
3645 case QEMU_OPTION_watchdog
:
3647 error_report("only one watchdog option may be given");
3652 case QEMU_OPTION_watchdog_action
:
3653 if (select_watchdog_action(optarg
) == -1) {
3654 error_report("unknown -watchdog-action parameter");
3658 case QEMU_OPTION_virtiocon
:
3659 add_device_config(DEV_VIRTCON
, optarg
);
3660 default_virtcon
= 0;
3661 if (strncmp(optarg
, "mon:", 4) == 0) {
3662 default_monitor
= 0;
3665 case QEMU_OPTION_parallel
:
3666 add_device_config(DEV_PARALLEL
, optarg
);
3667 default_parallel
= 0;
3668 if (strncmp(optarg
, "mon:", 4) == 0) {
3669 default_monitor
= 0;
3672 case QEMU_OPTION_debugcon
:
3673 add_device_config(DEV_DEBUGCON
, optarg
);
3675 case QEMU_OPTION_loadvm
:
3678 case QEMU_OPTION_full_screen
:
3681 case QEMU_OPTION_no_frame
:
3684 case QEMU_OPTION_alt_grab
:
3687 case QEMU_OPTION_ctrl_grab
:
3690 case QEMU_OPTION_no_quit
:
3693 case QEMU_OPTION_sdl
:
3695 display_type
= DT_SDL
;
3698 error_report("SDL support is disabled");
3701 case QEMU_OPTION_pidfile
:
3704 case QEMU_OPTION_win2k_hack
:
3705 win2k_install_hack
= 1;
3707 case QEMU_OPTION_rtc_td_hack
: {
3708 static GlobalProperty slew_lost_ticks
= {
3709 .driver
= "mc146818rtc",
3710 .property
= "lost_tick_policy",
3714 qdev_prop_register_global(&slew_lost_ticks
);
3717 case QEMU_OPTION_acpitable
:
3718 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3723 acpi_table_add(opts
, &error_fatal
);
3725 case QEMU_OPTION_smbios
:
3726 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3731 smbios_entry_add(opts
, &error_fatal
);
3733 case QEMU_OPTION_fwcfg
:
3734 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3740 case QEMU_OPTION_enable_kvm
:
3741 olist
= qemu_find_opts("machine");
3742 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3744 case QEMU_OPTION_enable_hax
:
3745 olist
= qemu_find_opts("machine");
3746 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3749 case QEMU_OPTION_machine
:
3750 olist
= qemu_find_opts("machine");
3751 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3756 case QEMU_OPTION_no_kvm
:
3757 olist
= qemu_find_opts("machine");
3758 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3760 case QEMU_OPTION_no_kvm_pit
: {
3761 error_report("warning: ignoring deprecated option");
3764 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3765 static GlobalProperty kvm_pit_lost_tick_policy
= {
3766 .driver
= "kvm-pit",
3767 .property
= "lost_tick_policy",
3771 error_report("warning: deprecated, replaced by "
3772 "-global kvm-pit.lost_tick_policy=discard");
3773 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3776 case QEMU_OPTION_accel
:
3777 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3779 optarg
= qemu_opt_get(accel_opts
, "accel");
3781 olist
= qemu_find_opts("machine");
3782 if (strcmp("kvm", optarg
) == 0) {
3783 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3784 } else if (strcmp("xen", optarg
) == 0) {
3785 qemu_opts_parse_noisily(olist
, "accel=xen", false);
3786 } else if (strcmp("tcg", optarg
) == 0) {
3787 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3789 if (!is_help_option(optarg
)) {
3790 error_printf("Unknown accelerator: %s", optarg
);
3792 error_printf("Supported accelerators: kvm, xen, tcg\n");
3796 case QEMU_OPTION_usb
:
3797 olist
= qemu_find_opts("machine");
3798 qemu_opts_parse_noisily(olist
, "usb=on", false);
3800 case QEMU_OPTION_usbdevice
:
3801 olist
= qemu_find_opts("machine");
3802 qemu_opts_parse_noisily(olist
, "usb=on", false);
3803 add_device_config(DEV_USB
, optarg
);
3805 case QEMU_OPTION_device
:
3806 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3811 case QEMU_OPTION_smp
:
3812 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3817 case QEMU_OPTION_vnc
:
3818 vnc_parse(optarg
, &error_fatal
);
3820 case QEMU_OPTION_no_acpi
:
3823 case QEMU_OPTION_no_hpet
:
3826 case QEMU_OPTION_balloon
:
3827 if (balloon_parse(optarg
) < 0) {
3828 error_report("unknown -balloon argument %s", optarg
);
3832 case QEMU_OPTION_no_reboot
:
3835 case QEMU_OPTION_no_shutdown
:
3838 case QEMU_OPTION_show_cursor
:
3841 case QEMU_OPTION_uuid
:
3842 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3843 error_report("failed to parse UUID string: wrong format");
3846 qemu_uuid_set
= true;
3848 case QEMU_OPTION_option_rom
:
3849 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3850 error_report("too many option ROMs");
3853 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3858 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3859 option_rom
[nb_option_roms
].bootindex
=
3860 qemu_opt_get_number(opts
, "bootindex", -1);
3861 if (!option_rom
[nb_option_roms
].name
) {
3862 error_report("Option ROM file is not specified");
3867 case QEMU_OPTION_semihosting
:
3868 semihosting
.enabled
= true;
3869 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3871 case QEMU_OPTION_semihosting_config
:
3872 semihosting
.enabled
= true;
3873 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3876 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3878 const char *target
= qemu_opt_get(opts
, "target");
3879 if (target
!= NULL
) {
3880 if (strcmp("native", target
) == 0) {
3881 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3882 } else if (strcmp("gdb", target
) == 0) {
3883 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3884 } else if (strcmp("auto", target
) == 0) {
3885 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3887 error_report("unsupported semihosting-config %s",
3892 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3894 /* Set semihosting argument count and vector */
3895 qemu_opt_foreach(opts
, add_semihosting_arg
,
3896 &semihosting
, NULL
);
3898 error_report("unsupported semihosting-config %s", optarg
);
3902 case QEMU_OPTION_tdf
:
3903 error_report("warning: ignoring deprecated option");
3905 case QEMU_OPTION_name
:
3906 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3912 case QEMU_OPTION_prom_env
:
3913 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3914 error_report("too many prom variables");
3917 prom_envs
[nb_prom_envs
] = optarg
;
3920 case QEMU_OPTION_old_param
:
3923 case QEMU_OPTION_clock
:
3924 /* Clock options no longer exist. Keep this option for
3925 * backward compatibility.
3928 case QEMU_OPTION_startdate
:
3929 configure_rtc_date_offset(optarg
, 1);
3931 case QEMU_OPTION_rtc
:
3932 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3937 configure_rtc(opts
);
3939 case QEMU_OPTION_tb_size
:
3940 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3941 if (tcg_tb_size
< 0) {
3945 case QEMU_OPTION_icount
:
3946 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3952 case QEMU_OPTION_incoming
:
3954 runstate_set(RUN_STATE_INMIGRATE
);
3958 case QEMU_OPTION_only_migratable
:
3959 only_migratable
= 1;
3961 case QEMU_OPTION_nodefaults
:
3964 case QEMU_OPTION_xen_domid
:
3965 if (!(xen_available())) {
3966 error_report("Option not supported for this target");
3969 xen_domid
= atoi(optarg
);
3971 case QEMU_OPTION_xen_create
:
3972 if (!(xen_available())) {
3973 error_report("Option not supported for this target");
3976 xen_mode
= XEN_CREATE
;
3978 case QEMU_OPTION_xen_attach
:
3979 if (!(xen_available())) {
3980 error_report("Option not supported for this target");
3983 xen_mode
= XEN_ATTACH
;
3985 case QEMU_OPTION_trace
:
3987 trace_file
= trace_opt_parse(optarg
);
3989 case QEMU_OPTION_trace_unassigned
:
3990 trace_unassigned
= true;
3992 case QEMU_OPTION_readconfig
:
3994 int ret
= qemu_read_config_file(optarg
);
3996 error_report("read config %s: %s", optarg
,
4002 case QEMU_OPTION_spice
:
4003 olist
= qemu_find_opts("spice");
4005 error_report("spice support is disabled");
4008 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
4014 case QEMU_OPTION_writeconfig
:
4017 if (strcmp(optarg
, "-") == 0) {
4020 fp
= fopen(optarg
, "w");
4022 error_report("open %s: %s", optarg
,
4027 qemu_config_write(fp
);
4033 case QEMU_OPTION_qtest
:
4034 qtest_chrdev
= optarg
;
4036 case QEMU_OPTION_qtest_log
:
4039 case QEMU_OPTION_sandbox
:
4040 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4046 case QEMU_OPTION_add_fd
:
4048 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4054 error_report("File descriptor passing is disabled on this "
4059 case QEMU_OPTION_object
:
4060 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
4066 case QEMU_OPTION_realtime
:
4067 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4072 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4074 case QEMU_OPTION_msg
:
4075 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4080 configure_msg(opts
);
4082 case QEMU_OPTION_dump_vmstate
:
4083 if (vmstate_dump_file
) {
4084 error_report("only one '-dump-vmstate' "
4085 "option may be given");
4088 vmstate_dump_file
= fopen(optarg
, "w");
4089 if (vmstate_dump_file
== NULL
) {
4090 error_report("open %s: %s", optarg
, strerror(errno
));
4095 os_parse_cmd_args(popt
->index
, optarg
);
4100 * Clear error location left behind by the loop.
4101 * Best done right after the loop. Do not insert code here!
4105 replay_configure(icount_opts
);
4107 qemu_tcg_configure(accel_opts
, &error_fatal
);
4109 machine_class
= select_machine();
4111 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4115 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4116 error_report("could not acquire pid file: %s", strerror(errno
));
4120 if (qemu_init_main_loop(&main_loop_err
)) {
4121 error_report_err(main_loop_err
);
4125 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4126 parse_sandbox
, NULL
, NULL
)) {
4130 if (qemu_opts_foreach(qemu_find_opts("name"),
4131 parse_name
, NULL
, NULL
)) {
4136 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4137 parse_add_fd
, NULL
, NULL
)) {
4141 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4142 cleanup_add_fd
, NULL
, NULL
)) {
4147 current_machine
= MACHINE(object_new(object_class_get_name(
4148 OBJECT_CLASS(machine_class
))));
4149 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4152 object_property_add_child(object_get_root(), "machine",
4153 OBJECT(current_machine
), &error_abort
);
4155 if (machine_class
->minimum_page_bits
) {
4156 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4157 /* This would be a board error: specifying a minimum smaller than
4158 * a target's compile-time fixed setting.
4160 g_assert_not_reached();
4164 cpu_exec_init_all();
4166 if (machine_class
->hw_version
) {
4167 qemu_set_hw_version(machine_class
->hw_version
);
4170 if (cpu_model
&& is_help_option(cpu_model
)) {
4171 list_cpus(stdout
, &fprintf
, cpu_model
);
4175 if (!trace_init_backends()) {
4178 trace_init_file(trace_file
);
4180 /* Open the logfile at this point and set the log mask if necessary.
4183 qemu_set_log_filename(log_file
, &error_fatal
);
4188 mask
= qemu_str_to_log_mask(log_mask
);
4190 qemu_print_log_usage(stdout
);
4198 /* If no data_dir is specified then try to find it relative to the
4200 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4201 data_dir
[data_dir_idx
] = os_find_datadir();
4202 if (data_dir
[data_dir_idx
] != NULL
) {
4206 /* If all else fails use the install path specified when building. */
4207 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4208 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4211 /* -L help lists the data directories and exits. */
4212 if (list_data_dirs
) {
4213 for (i
= 0; i
< data_dir_idx
; i
++) {
4214 printf("%s\n", data_dir
[i
]);
4219 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4221 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4222 if (max_cpus
> machine_class
->max_cpus
) {
4223 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4224 "supported by machine '%s' (%d)", max_cpus
,
4225 machine_class
->name
, machine_class
->max_cpus
);
4230 * Get the default machine options from the machine if it is not already
4231 * specified either by the configuration file or by the command line.
4233 if (machine_class
->default_machine_opts
) {
4234 qemu_opts_set_defaults(qemu_find_opts("machine"),
4235 machine_class
->default_machine_opts
, 0);
4238 qemu_opts_foreach(qemu_find_opts("device"),
4239 default_driver_check
, NULL
, NULL
);
4240 qemu_opts_foreach(qemu_find_opts("global"),
4241 default_driver_check
, NULL
, NULL
);
4243 if (!vga_model
&& !default_vga
) {
4244 vga_interface_type
= VGA_DEVICE
;
4246 if (!has_defaults
|| machine_class
->no_serial
) {
4249 if (!has_defaults
|| machine_class
->no_parallel
) {
4250 default_parallel
= 0;
4252 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4253 default_virtcon
= 0;
4255 if (!has_defaults
|| !machine_class
->use_sclp
) {
4258 if (!has_defaults
|| machine_class
->no_floppy
) {
4261 if (!has_defaults
|| machine_class
->no_cdrom
) {
4264 if (!has_defaults
|| machine_class
->no_sdcard
) {
4267 if (!has_defaults
) {
4268 default_monitor
= 0;
4273 if (is_daemonized()) {
4274 /* According to documentation and historically, -nographic redirects
4275 * serial port, parallel port and monitor to stdio, which does not work
4276 * with -daemonize. We can redirect these to null instead, but since
4277 * -nographic is legacy, let's just error out.
4278 * We disallow -nographic only if all other ports are not redirected
4279 * explicitly, to not break existing legacy setups which uses
4280 * -nographic _and_ redirects all ports explicitly - this is valid
4281 * usage, -nographic is just a no-op in this case.
4284 && (default_parallel
|| default_serial
4285 || default_monitor
|| default_virtcon
)) {
4286 error_report("-nographic cannot be used with -daemonize");
4289 #ifdef CONFIG_CURSES
4290 if (display_type
== DT_CURSES
) {
4291 error_report("curses display cannot be used with -daemonize");
4298 if (default_parallel
)
4299 add_device_config(DEV_PARALLEL
, "null");
4300 if (default_serial
&& default_monitor
) {
4301 add_device_config(DEV_SERIAL
, "mon:stdio");
4302 } else if (default_virtcon
&& default_monitor
) {
4303 add_device_config(DEV_VIRTCON
, "mon:stdio");
4304 } else if (default_sclp
&& default_monitor
) {
4305 add_device_config(DEV_SCLP
, "mon:stdio");
4308 add_device_config(DEV_SERIAL
, "stdio");
4309 if (default_virtcon
)
4310 add_device_config(DEV_VIRTCON
, "stdio");
4312 add_device_config(DEV_SCLP
, "stdio");
4314 if (default_monitor
)
4315 monitor_parse("stdio", "readline", false);
4319 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4320 if (default_parallel
)
4321 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4322 if (default_monitor
)
4323 monitor_parse("vc:80Cx24C", "readline", false);
4324 if (default_virtcon
)
4325 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4327 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4331 #if defined(CONFIG_VNC)
4332 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4336 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4337 #if defined(CONFIG_GTK)
4338 display_type
= DT_GTK
;
4339 #elif defined(CONFIG_SDL)
4340 display_type
= DT_SDL
;
4341 #elif defined(CONFIG_COCOA)
4342 display_type
= DT_COCOA
;
4343 #elif defined(CONFIG_VNC)
4344 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4346 display_type
= DT_NONE
;
4350 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4351 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4352 "for SDL, ignoring option");
4354 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4355 error_report("-no-quit is only valid for GTK and SDL, "
4359 if (display_type
== DT_GTK
) {
4360 early_gtk_display_init(request_opengl
);
4363 if (display_type
== DT_SDL
) {
4364 sdl_display_early_init(request_opengl
);
4367 qemu_console_early_init();
4369 if (request_opengl
== 1 && display_opengl
== 0) {
4370 #if defined(CONFIG_OPENGL)
4371 error_report("OpenGL is not supported by the display");
4373 error_report("OpenGL support is disabled");
4381 if (qemu_opts_foreach(qemu_find_opts("object"),
4382 user_creatable_add_opts_foreach
,
4383 object_create_initial
, NULL
)) {
4387 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4388 chardev_init_func
, NULL
, NULL
)) {
4392 #ifdef CONFIG_VIRTFS
4393 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4394 fsdev_init_func
, NULL
, NULL
)) {
4399 if (qemu_opts_foreach(qemu_find_opts("device"),
4400 device_help_func
, NULL
, NULL
)) {
4404 machine_opts
= qemu_get_machine_opts();
4405 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4407 object_unref(OBJECT(current_machine
));
4411 configure_accelerator(current_machine
);
4414 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4417 machine_opts
= qemu_get_machine_opts();
4418 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4419 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4420 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4421 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4423 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4425 boot_order
= qemu_opt_get(opts
, "order");
4427 validate_bootdevices(boot_order
, &error_fatal
);
4430 boot_once
= qemu_opt_get(opts
, "once");
4432 validate_bootdevices(boot_once
, &error_fatal
);
4435 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4436 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4440 boot_order
= machine_class
->default_boot_order
;
4443 if (!kernel_cmdline
) {
4444 kernel_cmdline
= "";
4445 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4448 linux_boot
= (kernel_filename
!= NULL
);
4450 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4451 error_report("-append only allowed with -kernel option");
4455 if (!linux_boot
&& initrd_filename
!= NULL
) {
4456 error_report("-initrd only allowed with -kernel option");
4460 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4461 /* fall back to the -kernel/-append */
4462 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4465 os_set_line_buffering();
4467 /* spice needs the timers to be initialized by this point */
4472 if (!tcg_enabled()) {
4473 error_report("-icount is not allowed with hardware virtualization");
4475 } else if (qemu_tcg_mttcg_enabled()) {
4476 error_report("-icount does not currently work with MTTCG");
4479 configure_icount(icount_opts
, &error_abort
);
4480 qemu_opts_del(icount_opts
);
4484 QemuOptsList
*net
= qemu_find_opts("net");
4485 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4487 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4493 if (net_init_clients() < 0) {
4497 if (qemu_opts_foreach(qemu_find_opts("object"),
4498 user_creatable_add_opts_foreach
,
4499 object_create_delayed
, NULL
)) {
4504 if (tpm_init() < 0) {
4509 /* init the bluetooth world */
4510 if (foreach_device_config(DEV_BT
, bt_parse
))
4513 if (!xen_enabled()) {
4514 /* On 32-bit hosts, QEMU is limited by virtual address space */
4515 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4516 error_report("at most 2047 MB RAM can be simulated");
4524 /* If the currently selected machine wishes to override the units-per-bus
4525 * property of its default HBA interface type, do so now. */
4526 if (machine_class
->units_per_default_bus
) {
4527 override_max_devs(machine_class
->block_default_type
,
4528 machine_class
->units_per_default_bus
);
4531 /* open the virtual block devices */
4532 while (!QSIMPLEQ_EMPTY(&bdo_queue
)) {
4533 BlockdevOptions_queue
*bdo
= QSIMPLEQ_FIRST(&bdo_queue
);
4535 QSIMPLEQ_REMOVE_HEAD(&bdo_queue
, entry
);
4536 loc_push_restore(&bdo
->loc
);
4537 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
4539 qapi_free_BlockdevOptions(bdo
->bdo
);
4542 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4543 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4546 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4547 &machine_class
->block_default_type
, NULL
)) {
4551 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4553 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4554 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4556 parse_numa_opts(machine_class
);
4558 if (qemu_opts_foreach(qemu_find_opts("mon"),
4559 mon_init_func
, NULL
, NULL
)) {
4563 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4565 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4567 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4569 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4572 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4575 /* If no default VGA is requested, the default is "none". */
4577 if (machine_class
->default_display
) {
4578 vga_model
= machine_class
->default_display
;
4579 } else if (vga_interface_available(VGA_CIRRUS
)) {
4580 vga_model
= "cirrus";
4581 } else if (vga_interface_available(VGA_STD
)) {
4586 select_vgahw(vga_model
);
4590 i
= select_watchdog(watchdog
);
4592 exit (i
== 1 ? 1 : 0);
4595 machine_register_compat_props(current_machine
);
4597 qemu_opts_foreach(qemu_find_opts("global"),
4598 global_init_func
, NULL
, NULL
);
4600 /* This checkpoint is required by replay to separate prior clock
4601 reading from the other reads, because timer polling functions query
4602 clock values from the log. */
4603 replay_checkpoint(CHECKPOINT_INIT
);
4604 qdev_machine_init();
4606 current_machine
->ram_size
= ram_size
;
4607 current_machine
->maxram_size
= maxram_size
;
4608 current_machine
->ram_slots
= ram_slots
;
4609 current_machine
->boot_order
= boot_order
;
4610 current_machine
->cpu_model
= cpu_model
;
4612 machine_class
->init(current_machine
);
4618 if (hax_enabled()) {
4622 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4623 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4627 /* init USB devices */
4628 if (machine_usb(current_machine
)) {
4629 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4633 /* Check if IGD GFX passthrough. */
4636 /* init generic devices */
4637 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4638 if (qemu_opts_foreach(qemu_find_opts("device"),
4639 device_init_func
, NULL
, NULL
)) {
4643 cpu_synchronize_all_post_init();
4645 numa_post_machine_init();
4647 rom_reset_order_override();
4650 * Create frontends for -drive if=scsi leftovers.
4651 * Normally, frontends for -drive get created by machine
4652 * initialization for onboard SCSI HBAs. However, we create a few
4653 * more ever since SCSI qdevification, but this is pretty much an
4654 * implementation accident, and deprecated.
4656 scsi_legacy_handle_cmdline();
4658 /* Did we create any drives that we failed to create a device for? */
4659 drive_check_orphaned();
4661 /* Don't warn about the default network setup that you get if
4662 * no command line -net or -netdev options are specified. There
4663 * are two cases that we would otherwise complain about:
4664 * (1) board doesn't support a NIC but the implicit "-net nic"
4666 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4667 * sets up a nic that isn't connected to anything.
4670 net_check_clients();
4675 qemu_boot_set(boot_once
, &error_fatal
);
4676 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4679 ds
= init_displaystate();
4681 /* init local displays */
4682 switch (display_type
) {
4684 curses_display_init(ds
, full_screen
);
4687 sdl_display_init(ds
, full_screen
, no_frame
);
4690 cocoa_display_init(ds
, full_screen
);
4693 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4699 /* must be after terminal init, SDL library changes signal handlers */
4700 os_setup_signal_handling();
4702 /* init remote displays */
4704 qemu_opts_foreach(qemu_find_opts("vnc"),
4705 vnc_init_func
, NULL
, NULL
);
4709 qemu_spice_display_init();
4712 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4716 qdev_machine_creation_done();
4718 /* TODO: once all bus devices are qdevified, this should be done
4719 * when bus is created by qdev.c */
4720 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4721 qemu_run_machine_init_done_notifiers();
4723 if (rom_check_and_register_reset() != 0) {
4724 error_report("rom check and register reset failed");
4730 /* This checkpoint is required by replay to separate prior clock
4731 reading from the other reads, because timer polling functions query
4732 clock values from the log. */
4733 replay_checkpoint(CHECKPOINT_RESET
);
4734 qemu_system_reset(VMRESET_SILENT
);
4735 register_global_state();
4736 if (replay_mode
!= REPLAY_MODE_NONE
) {
4737 replay_vmstate_init();
4738 } else if (loadvm
) {
4739 if (load_vmstate(loadvm
) < 0) {
4744 qdev_prop_check_globals();
4745 if (vmstate_dump_file
) {
4747 dump_vmstate_json_to_file(vmstate_dump_file
);
4752 Error
*local_err
= NULL
;
4753 qemu_start_incoming_migration(incoming
, &local_err
);
4755 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4758 } else if (autostart
) {
4765 replay_disable_events();
4766 iothread_stop_all();
4772 /* vhost-user must be cleaned up before chardevs. */