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"
73 #include "sysemu/watchdog.h"
74 #include "hw/smbios/smbios.h"
75 #include "hw/xen/xen.h"
77 #include "hw/loader.h"
78 #include "monitor/qdev.h"
79 #include "sysemu/bt.h"
81 #include "net/slirp.h"
82 #include "monitor/monitor.h"
83 #include "ui/console.h"
85 #include "sysemu/sysemu.h"
86 #include "sysemu/numa.h"
87 #include "exec/gdbstub.h"
88 #include "qemu/timer.h"
89 #include "sysemu/char.h"
90 #include "qemu/bitmap.h"
92 #include "sysemu/blockdev.h"
93 #include "hw/block/block.h"
94 #include "migration/block.h"
95 #include "sysemu/tpm.h"
96 #include "sysemu/dma.h"
97 #include "audio/audio.h"
98 #include "migration/migration.h"
99 #include "sysemu/cpus.h"
100 #include "migration/colo.h"
101 #include "sysemu/kvm.h"
102 #include "sysemu/hax.h"
103 #include "qapi/qmp/qjson.h"
104 #include "qemu/option.h"
105 #include "qemu/config-file.h"
106 #include "qemu-options.h"
107 #include "qmp-commands.h"
108 #include "qemu/main-loop.h"
110 #include "fsdev/qemu-fsdev.h"
112 #include "sysemu/qtest.h"
114 #include "disas/disas.h"
117 #include "slirp/libslirp.h"
120 #include "trace/control.h"
121 #include "qemu/queue.h"
122 #include "sysemu/arch_init.h"
124 #include "ui/qemu-spice.h"
125 #include "qapi/string-input-visitor.h"
126 #include "qapi/opts-visitor.h"
127 #include "qom/object_interfaces.h"
128 #include "qapi-event.h"
129 #include "exec/semihost.h"
130 #include "crypto/init.h"
131 #include "sysemu/replay.h"
132 #include "qapi/qmp/qerror.h"
133 #include "sysemu/iothread.h"
135 #define MAX_VIRTIO_CONSOLES 1
136 #define MAX_SCLP_CONSOLES 1
138 static const char *data_dir
[16];
139 static int data_dir_idx
;
140 const char *bios_name
= NULL
;
141 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
142 int request_opengl
= -1;
144 const char* keyboard_layout
= NULL
;
146 const char *mem_path
= NULL
;
147 int mem_prealloc
= 0; /* force preallocation of physical target memory */
148 bool enable_mlock
= false;
150 NICInfo nd_table
[MAX_NICS
];
152 static int rtc_utc
= 1;
153 static int rtc_date_offset
= -1; /* -1 means no change */
154 QEMUClockType rtc_clock
;
155 int vga_interface_type
= VGA_NONE
;
156 static int full_screen
= 0;
157 static int no_frame
= 0;
159 static bool grab_on_hover
;
160 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
161 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
162 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
163 CharDriverState
*sclp_hds
[MAX_SCLP_CONSOLES
];
164 int win2k_install_hack
= 0;
170 int acpi_enabled
= 1;
173 static int no_reboot
;
176 int graphic_rotate
= 0;
177 const char *watchdog
;
178 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
181 const char *qemu_name
;
184 unsigned int nb_prom_envs
= 0;
185 const char *prom_envs
[MAX_PROM_ENVS
];
188 uint8_t *boot_splash_filedata
;
189 size_t boot_splash_filedata_size
;
190 uint8_t qemu_extra_params_fw
[2];
192 int icount_align_option
;
194 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
195 * little-endian "wire format" described in the SMBIOS 2.6 specification.
200 /* Trace unassigned memory or i/o accesses. */
201 bool trace_unassigned
;
203 static NotifierList exit_notifiers
=
204 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
206 static NotifierList machine_init_done_notifiers
=
207 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
211 enum xen_mode xen_mode
= XEN_EMULATE
;
213 static int has_defaults
= 1;
214 static int default_serial
= 1;
215 static int default_parallel
= 1;
216 static int default_virtcon
= 1;
217 static int default_sclp
= 1;
218 static int default_monitor
= 1;
219 static int default_floppy
= 1;
220 static int default_cdrom
= 1;
221 static int default_sdcard
= 1;
222 static int default_vga
= 1;
223 static int default_net
= 1;
229 { .driver
= "isa-serial", .flag
= &default_serial
},
230 { .driver
= "isa-parallel", .flag
= &default_parallel
},
231 { .driver
= "isa-fdc", .flag
= &default_floppy
},
232 { .driver
= "floppy", .flag
= &default_floppy
},
233 { .driver
= "ide-cd", .flag
= &default_cdrom
},
234 { .driver
= "ide-hd", .flag
= &default_cdrom
},
235 { .driver
= "ide-drive", .flag
= &default_cdrom
},
236 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
237 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
238 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
239 { .driver
= "VGA", .flag
= &default_vga
},
240 { .driver
= "isa-vga", .flag
= &default_vga
},
241 { .driver
= "cirrus-vga", .flag
= &default_vga
},
242 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
243 { .driver
= "vmware-svga", .flag
= &default_vga
},
244 { .driver
= "qxl-vga", .flag
= &default_vga
},
245 { .driver
= "virtio-vga", .flag
= &default_vga
},
248 static QemuOptsList qemu_rtc_opts
= {
250 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
254 .type
= QEMU_OPT_STRING
,
257 .type
= QEMU_OPT_STRING
,
260 .type
= QEMU_OPT_STRING
,
262 { /* end of list */ }
266 static QemuOptsList qemu_sandbox_opts
= {
268 .implied_opt_name
= "enable",
269 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
273 .type
= QEMU_OPT_BOOL
,
275 { /* end of list */ }
279 static QemuOptsList qemu_option_rom_opts
= {
280 .name
= "option-rom",
281 .implied_opt_name
= "romfile",
282 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
286 .type
= QEMU_OPT_NUMBER
,
289 .type
= QEMU_OPT_STRING
,
291 { /* end of list */ }
295 static QemuOptsList qemu_machine_opts
= {
297 .implied_opt_name
= "type",
299 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
302 * no elements => accept any
303 * sanity checking will happen later
304 * when setting machine properties
310 static QemuOptsList qemu_boot_opts
= {
312 .implied_opt_name
= "order",
314 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
318 .type
= QEMU_OPT_STRING
,
321 .type
= QEMU_OPT_STRING
,
324 .type
= QEMU_OPT_BOOL
,
327 .type
= QEMU_OPT_STRING
,
329 .name
= "splash-time",
330 .type
= QEMU_OPT_STRING
,
332 .name
= "reboot-timeout",
333 .type
= QEMU_OPT_STRING
,
336 .type
= QEMU_OPT_BOOL
,
342 static QemuOptsList qemu_add_fd_opts
= {
344 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
348 .type
= QEMU_OPT_NUMBER
,
349 .help
= "file descriptor of which a duplicate is added to fd set",
352 .type
= QEMU_OPT_NUMBER
,
353 .help
= "ID of the fd set to add fd to",
356 .type
= QEMU_OPT_STRING
,
357 .help
= "free-form string used to describe fd",
359 { /* end of list */ }
363 static QemuOptsList qemu_object_opts
= {
365 .implied_opt_name
= "qom-type",
366 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
372 static QemuOptsList qemu_tpmdev_opts
= {
374 .implied_opt_name
= "type",
375 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
377 /* options are defined in the TPM backends */
378 { /* end of list */ }
382 static QemuOptsList qemu_realtime_opts
= {
384 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
388 .type
= QEMU_OPT_BOOL
,
390 { /* end of list */ }
394 static QemuOptsList qemu_msg_opts
= {
396 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
400 .type
= QEMU_OPT_BOOL
,
402 { /* end of list */ }
406 static QemuOptsList qemu_name_opts
= {
408 .implied_opt_name
= "guest",
410 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
414 .type
= QEMU_OPT_STRING
,
415 .help
= "Sets the name of the guest.\n"
416 "This name will be displayed in the SDL window caption.\n"
417 "The name will also be used for the VNC server",
420 .type
= QEMU_OPT_STRING
,
421 .help
= "Sets the name of the QEMU process, as shown in top etc",
423 .name
= "debug-threads",
424 .type
= QEMU_OPT_BOOL
,
425 .help
= "When enabled, name the individual threads; defaults off.\n"
426 "NOTE: The thread names are for debugging and not a\n"
429 { /* End of list */ }
433 static QemuOptsList qemu_mem_opts
= {
435 .implied_opt_name
= "size",
436 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
441 .type
= QEMU_OPT_SIZE
,
445 .type
= QEMU_OPT_NUMBER
,
449 .type
= QEMU_OPT_SIZE
,
451 { /* end of list */ }
455 static QemuOptsList qemu_icount_opts
= {
457 .implied_opt_name
= "shift",
459 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
463 .type
= QEMU_OPT_STRING
,
466 .type
= QEMU_OPT_BOOL
,
469 .type
= QEMU_OPT_BOOL
,
472 .type
= QEMU_OPT_STRING
,
475 .type
= QEMU_OPT_STRING
,
477 { /* end of list */ }
481 static QemuOptsList qemu_semihosting_config_opts
= {
482 .name
= "semihosting-config",
483 .implied_opt_name
= "enable",
484 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
488 .type
= QEMU_OPT_BOOL
,
491 .type
= QEMU_OPT_STRING
,
494 .type
= QEMU_OPT_STRING
,
496 { /* end of list */ }
500 static QemuOptsList qemu_fw_cfg_opts
= {
502 .implied_opt_name
= "name",
503 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
507 .type
= QEMU_OPT_STRING
,
508 .help
= "Sets the fw_cfg name of the blob to be inserted",
511 .type
= QEMU_OPT_STRING
,
512 .help
= "Sets the name of the file from which\n"
513 "the fw_cfg blob will be loaded",
516 .type
= QEMU_OPT_STRING
,
517 .help
= "Sets content of the blob to be inserted from a string",
519 { /* end of list */ }
523 #ifdef CONFIG_LIBISCSI
524 static QemuOptsList qemu_iscsi_opts
= {
526 .head
= QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts
.head
),
530 .type
= QEMU_OPT_STRING
,
531 .help
= "username for CHAP authentication to target",
534 .type
= QEMU_OPT_STRING
,
535 .help
= "password for CHAP authentication to target",
537 .name
= "password-secret",
538 .type
= QEMU_OPT_STRING
,
539 .help
= "ID of the secret providing password for CHAP "
540 "authentication to target",
542 .name
= "header-digest",
543 .type
= QEMU_OPT_STRING
,
544 .help
= "HeaderDigest setting. "
545 "{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
547 .name
= "initiator-name",
548 .type
= QEMU_OPT_STRING
,
549 .help
= "Initiator iqn name to use when connecting",
552 .type
= QEMU_OPT_NUMBER
,
553 .help
= "Request timeout in seconds (default 0 = no timeout)",
555 { /* end of list */ }
561 * Get machine options
563 * Returns: machine options (never null).
565 QemuOpts
*qemu_get_machine_opts(void)
567 return qemu_find_opts_singleton("machine");
570 const char *qemu_get_vm_name(void)
575 static void res_free(void)
577 g_free(boot_splash_filedata
);
578 boot_splash_filedata
= NULL
;
581 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
583 const char *driver
= qemu_opt_get(opts
, "driver");
588 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
589 if (strcmp(default_list
[i
].driver
, driver
) != 0)
591 *(default_list
[i
].flag
) = 0;
596 /***********************************************************/
599 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
601 /* We use RUN_STATE__MAX but any invalid value will do */
602 static RunState vmstop_requested
= RUN_STATE__MAX
;
603 static QemuMutex vmstop_lock
;
608 } RunStateTransition
;
610 static const RunStateTransition runstate_transitions_def
[] = {
612 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
613 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
614 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
616 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
617 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
618 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
619 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
620 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
621 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
622 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
623 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
624 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
625 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
626 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
627 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
629 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
630 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
631 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
633 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
634 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
635 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
637 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
638 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
639 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
640 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
642 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
643 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
644 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
646 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
647 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
648 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
650 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
651 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
652 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
653 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
655 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
656 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
658 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
660 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
661 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
662 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
663 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
664 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
665 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
666 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
667 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
668 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
669 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
670 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
672 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
674 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
675 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
676 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
678 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
679 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
680 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
681 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
682 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
683 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
685 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
686 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
687 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
688 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
690 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
691 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
692 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
694 { RUN_STATE__MAX
, RUN_STATE__MAX
},
697 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
699 bool runstate_check(RunState state
)
701 return current_run_state
== state
;
704 bool runstate_store(char *str
, size_t size
)
706 const char *state
= RunState_lookup
[current_run_state
];
707 size_t len
= strlen(state
) + 1;
712 memcpy(str
, state
, len
);
716 static void runstate_init(void)
718 const RunStateTransition
*p
;
720 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
721 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
722 runstate_valid_transitions
[p
->from
][p
->to
] = true;
725 qemu_mutex_init(&vmstop_lock
);
728 /* This function will abort() on invalid state transitions */
729 void runstate_set(RunState new_state
)
731 assert(new_state
< RUN_STATE__MAX
);
733 if (current_run_state
== new_state
) {
737 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
738 error_report("invalid runstate transition: '%s' -> '%s'",
739 RunState_lookup
[current_run_state
],
740 RunState_lookup
[new_state
]);
743 trace_runstate_set(new_state
);
744 current_run_state
= new_state
;
747 int runstate_is_running(void)
749 return runstate_check(RUN_STATE_RUNNING
);
752 bool runstate_needs_reset(void)
754 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
755 runstate_check(RUN_STATE_SHUTDOWN
);
758 StatusInfo
*qmp_query_status(Error
**errp
)
760 StatusInfo
*info
= g_malloc0(sizeof(*info
));
762 info
->running
= runstate_is_running();
763 info
->singlestep
= singlestep
;
764 info
->status
= current_run_state
;
769 static bool qemu_vmstop_requested(RunState
*r
)
771 qemu_mutex_lock(&vmstop_lock
);
772 *r
= vmstop_requested
;
773 vmstop_requested
= RUN_STATE__MAX
;
774 qemu_mutex_unlock(&vmstop_lock
);
775 return *r
< RUN_STATE__MAX
;
778 void qemu_system_vmstop_request_prepare(void)
780 qemu_mutex_lock(&vmstop_lock
);
783 void qemu_system_vmstop_request(RunState state
)
785 vmstop_requested
= state
;
786 qemu_mutex_unlock(&vmstop_lock
);
794 qemu_vmstop_requested(&requested
);
795 if (runstate_is_running() && requested
== RUN_STATE__MAX
) {
799 /* Ensure that a STOP/RESUME pair of events is emitted if a
800 * vmstop request was pending. The BLOCK_IO_ERROR event, for
801 * example, according to documentation is always followed by
804 if (runstate_is_running()) {
805 qapi_event_send_stop(&error_abort
);
807 replay_enable_events();
809 runstate_set(RUN_STATE_RUNNING
);
810 vm_state_notify(1, RUN_STATE_RUNNING
);
814 qapi_event_send_resume(&error_abort
);
818 /***********************************************************/
819 /* real time host monotonic timer */
821 static time_t qemu_time(void)
823 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
826 /***********************************************************/
827 /* host time/date access */
828 void qemu_get_timedate(struct tm
*tm
, int offset
)
830 time_t ti
= qemu_time();
833 if (rtc_date_offset
== -1) {
837 localtime_r(&ti
, tm
);
839 ti
-= rtc_date_offset
;
844 int qemu_timedate_diff(struct tm
*tm
)
848 if (rtc_date_offset
== -1)
850 seconds
= mktimegm(tm
);
853 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
854 seconds
= mktime(&tmp
);
857 seconds
= mktimegm(tm
) + rtc_date_offset
;
859 return seconds
- qemu_time();
862 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
864 time_t rtc_start_date
;
867 if (!strcmp(startdate
, "now") && legacy
) {
868 rtc_date_offset
= -1;
870 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
878 } else if (sscanf(startdate
, "%d-%d-%d",
890 rtc_start_date
= mktimegm(&tm
);
891 if (rtc_start_date
== -1) {
893 error_report("invalid date format");
894 error_printf("valid formats: "
895 "'2006-06-17T16:01:21' or '2006-06-17'\n");
898 rtc_date_offset
= qemu_time() - rtc_start_date
;
902 static void configure_rtc(QemuOpts
*opts
)
906 value
= qemu_opt_get(opts
, "base");
908 if (!strcmp(value
, "utc")) {
910 } else if (!strcmp(value
, "localtime")) {
911 Error
*blocker
= NULL
;
913 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
914 "-rtc base=localtime");
915 replay_add_blocker(blocker
);
917 configure_rtc_date_offset(value
, 0);
920 value
= qemu_opt_get(opts
, "clock");
922 if (!strcmp(value
, "host")) {
923 rtc_clock
= QEMU_CLOCK_HOST
;
924 } else if (!strcmp(value
, "rt")) {
925 rtc_clock
= QEMU_CLOCK_REALTIME
;
926 } else if (!strcmp(value
, "vm")) {
927 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
929 error_report("invalid option value '%s'", value
);
933 value
= qemu_opt_get(opts
, "driftfix");
935 if (!strcmp(value
, "slew")) {
936 static GlobalProperty slew_lost_ticks
= {
937 .driver
= "mc146818rtc",
938 .property
= "lost_tick_policy",
942 qdev_prop_register_global(&slew_lost_ticks
);
943 } else if (!strcmp(value
, "none")) {
944 /* discard is default */
946 error_report("invalid option value '%s'", value
);
952 /***********************************************************/
953 /* Bluetooth support */
956 static struct HCIInfo
*hci_table
[MAX_NICS
];
958 struct HCIInfo
*qemu_next_hci(void)
960 if (cur_hci
== nb_hcis
)
963 return hci_table
[cur_hci
++];
966 static int bt_hci_parse(const char *str
)
971 if (nb_hcis
>= MAX_NICS
) {
972 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
985 bdaddr
.b
[5] = 0x56 + nb_hcis
;
986 hci
->bdaddr_set(hci
, bdaddr
.b
);
988 hci_table
[nb_hcis
++] = hci
;
993 static void bt_vhci_add(int vlan_id
)
995 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
998 error_report("warning: adding a VHCI to an empty scatternet %i",
1001 bt_vhci_init(bt_new_hci(vlan
));
1004 static struct bt_device_s
*bt_device_add(const char *opt
)
1006 struct bt_scatternet_s
*vlan
;
1008 char *endp
= strstr(opt
, ",vlan=");
1009 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
1012 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
1015 vlan_id
= strtol(endp
+ 6, &endp
, 0);
1017 error_report("unrecognised bluetooth vlan Id");
1022 vlan
= qemu_find_bt_vlan(vlan_id
);
1025 error_report("warning: adding a slave device to an empty scatternet %i",
1028 if (!strcmp(devname
, "keyboard"))
1029 return bt_keyboard_init(vlan
);
1031 error_report("unsupported bluetooth device '%s'", devname
);
1035 static int bt_parse(const char *opt
)
1037 const char *endp
, *p
;
1040 if (strstart(opt
, "hci", &endp
)) {
1041 if (!*endp
|| *endp
== ',') {
1043 if (!strstart(endp
, ",vlan=", 0))
1046 return bt_hci_parse(opt
);
1048 } else if (strstart(opt
, "vhci", &endp
)) {
1049 if (!*endp
|| *endp
== ',') {
1051 if (strstart(endp
, ",vlan=", &p
)) {
1052 vlan
= strtol(p
, (char **) &endp
, 0);
1054 error_report("bad scatternet '%s'", p
);
1058 error_report("bad parameter '%s'", endp
+ 1);
1067 } else if (strstart(opt
, "device:", &endp
))
1068 return !bt_device_add(endp
);
1070 error_report("bad bluetooth parameter '%s'", opt
);
1074 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1076 /* FIXME: change this to true for 1.3 */
1077 if (qemu_opt_get_bool(opts
, "enable", false)) {
1078 #ifdef CONFIG_SECCOMP
1079 if (seccomp_start() < 0) {
1080 error_report("failed to install seccomp syscall filter "
1085 error_report("seccomp support is disabled");
1093 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1095 const char *proc_name
;
1097 if (qemu_opt_get(opts
, "debug-threads")) {
1098 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1100 qemu_name
= qemu_opt_get(opts
, "guest");
1102 proc_name
= qemu_opt_get(opts
, "process");
1104 os_set_proc_name(proc_name
);
1110 bool defaults_enabled(void)
1112 return has_defaults
;
1116 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1118 int fd
, dupfd
, flags
;
1120 const char *fd_opaque
= NULL
;
1123 fd
= qemu_opt_get_number(opts
, "fd", -1);
1124 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1125 fd_opaque
= qemu_opt_get(opts
, "opaque");
1128 error_report("fd option is required and must be non-negative");
1132 if (fd
<= STDERR_FILENO
) {
1133 error_report("fd cannot be a standard I/O stream");
1138 * All fds inherited across exec() necessarily have FD_CLOEXEC
1139 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1141 flags
= fcntl(fd
, F_GETFD
);
1142 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1143 error_report("fd is not valid or already in use");
1148 error_report("set option is required and must be non-negative");
1152 #ifdef F_DUPFD_CLOEXEC
1153 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1157 qemu_set_cloexec(dupfd
);
1161 error_report("error duplicating fd: %s", strerror(errno
));
1165 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1166 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1173 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1177 fd
= qemu_opt_get_number(opts
, "fd", -1);
1184 /***********************************************************/
1185 /* QEMU Block devices */
1187 #define HD_OPTS "media=disk"
1188 #define CDROM_OPTS "media=cdrom"
1190 #define PFLASH_OPTS ""
1194 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1196 BlockInterfaceType
*block_default_type
= opaque
;
1198 return drive_new(opts
, *block_default_type
) == NULL
;
1201 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1203 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1204 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1209 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1210 int index
, const char *optstr
)
1215 if (!enable
|| drive_get_by_index(type
, index
)) {
1219 opts
= drive_add(type
, index
, NULL
, optstr
);
1221 drive_enable_snapshot(NULL
, opts
, NULL
);
1224 dinfo
= drive_new(opts
, type
);
1228 dinfo
->is_default
= true;
1232 static QemuOptsList qemu_smp_opts
= {
1234 .implied_opt_name
= "cpus",
1235 .merge_lists
= true,
1236 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1240 .type
= QEMU_OPT_NUMBER
,
1243 .type
= QEMU_OPT_NUMBER
,
1246 .type
= QEMU_OPT_NUMBER
,
1249 .type
= QEMU_OPT_NUMBER
,
1252 .type
= QEMU_OPT_NUMBER
,
1254 { /*End of list */ }
1258 static void smp_parse(QemuOpts
*opts
)
1261 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1262 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1263 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1264 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1266 /* compute missing values, prefer sockets over cores over threads */
1267 if (cpus
== 0 || sockets
== 0) {
1268 sockets
= sockets
> 0 ? sockets
: 1;
1269 cores
= cores
> 0 ? cores
: 1;
1270 threads
= threads
> 0 ? threads
: 1;
1272 cpus
= cores
* threads
* sockets
;
1274 } else if (cores
== 0) {
1275 threads
= threads
> 0 ? threads
: 1;
1276 cores
= cpus
/ (sockets
* threads
);
1277 cores
= cores
> 0 ? cores
: 1;
1278 } else if (threads
== 0) {
1279 threads
= cpus
/ (cores
* sockets
);
1280 threads
= threads
> 0 ? threads
: 1;
1281 } else if (sockets
* cores
* threads
< cpus
) {
1282 error_report("cpu topology: "
1283 "sockets (%u) * cores (%u) * threads (%u) < "
1285 sockets
, cores
, threads
, cpus
);
1289 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1291 if (max_cpus
> MAX_CPUMASK_BITS
) {
1292 error_report("unsupported number of maxcpus");
1296 if (max_cpus
< cpus
) {
1297 error_report("maxcpus must be equal to or greater than smp");
1301 if (sockets
* cores
* threads
> max_cpus
) {
1302 error_report("cpu topology: "
1303 "sockets (%u) * cores (%u) * threads (%u) > "
1305 sockets
, cores
, threads
, max_cpus
);
1311 smp_threads
= threads
;
1315 Error
*blocker
= NULL
;
1316 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1317 replay_add_blocker(blocker
);
1321 static void realtime_init(void)
1324 if (os_mlock() < 0) {
1325 error_report("locking memory failed");
1332 static void configure_msg(QemuOpts
*opts
)
1334 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1337 /***********************************************************/
1340 typedef struct SemihostingConfig
{
1342 SemihostingTarget target
;
1345 const char *cmdline
; /* concatenated argv */
1346 } SemihostingConfig
;
1348 static SemihostingConfig semihosting
;
1350 bool semihosting_enabled(void)
1352 return semihosting
.enabled
;
1355 SemihostingTarget
semihosting_get_target(void)
1357 return semihosting
.target
;
1360 const char *semihosting_get_arg(int i
)
1362 if (i
>= semihosting
.argc
) {
1365 return semihosting
.argv
[i
];
1368 int semihosting_get_argc(void)
1370 return semihosting
.argc
;
1373 const char *semihosting_get_cmdline(void)
1375 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1376 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1378 return semihosting
.cmdline
;
1381 static int add_semihosting_arg(void *opaque
,
1382 const char *name
, const char *val
,
1385 SemihostingConfig
*s
= opaque
;
1386 if (strcmp(name
, "arg") == 0) {
1388 /* one extra element as g_strjoinv() expects NULL-terminated array */
1389 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1390 s
->argv
[s
->argc
- 1] = val
;
1391 s
->argv
[s
->argc
] = NULL
;
1396 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1397 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1402 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1404 /* split -append and initialize argv[1..n] */
1405 cmd_token
= strtok(g_strdup(cmd
), " ");
1407 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1408 cmd_token
= strtok(NULL
, " ");
1412 /* Now we still need this for compatibility with XEN. */
1413 bool has_igd_gfx_passthru
;
1414 static void igd_gfx_passthru(void)
1416 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1419 /***********************************************************/
1422 static int usb_device_add(const char *devname
)
1424 USBDevice
*dev
= NULL
;
1425 #ifndef CONFIG_LINUX
1429 if (!machine_usb(current_machine
)) {
1433 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1434 dev
= usbdevice_create(devname
);
1438 /* the other ones */
1439 #ifndef CONFIG_LINUX
1440 /* only the linux version is qdev-ified, usb-bsd still needs this */
1441 if (strstart(devname
, "host:", &p
)) {
1442 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1452 static int usb_device_del(const char *devname
)
1457 if (strstart(devname
, "host:", &p
)) {
1461 if (!machine_usb(current_machine
)) {
1465 p
= strchr(devname
, '.');
1468 bus_num
= strtoul(devname
, NULL
, 0);
1469 addr
= strtoul(p
+ 1, NULL
, 0);
1471 return usb_device_delete_addr(bus_num
, addr
);
1474 static int usb_parse(const char *cmdline
)
1477 r
= usb_device_add(cmdline
);
1479 error_report("could not add USB device '%s'", cmdline
);
1484 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1486 const char *devname
= qdict_get_str(qdict
, "devname");
1487 if (usb_device_add(devname
) < 0) {
1488 error_report("could not add USB device '%s'", devname
);
1492 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1494 const char *devname
= qdict_get_str(qdict
, "devname");
1495 if (usb_device_del(devname
) < 0) {
1496 error_report("could not delete USB device '%s'", devname
);
1500 /***********************************************************/
1501 /* machine registration */
1503 MachineState
*current_machine
;
1505 static MachineClass
*find_machine(const char *name
)
1507 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1508 MachineClass
*mc
= NULL
;
1510 for (el
= machines
; el
; el
= el
->next
) {
1511 MachineClass
*temp
= el
->data
;
1513 if (!strcmp(temp
->name
, name
)) {
1518 !strcmp(temp
->alias
, name
)) {
1524 g_slist_free(machines
);
1528 MachineClass
*find_default_machine(void)
1530 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1531 MachineClass
*mc
= NULL
;
1533 for (el
= machines
; el
; el
= el
->next
) {
1534 MachineClass
*temp
= el
->data
;
1536 if (temp
->is_default
) {
1542 g_slist_free(machines
);
1546 MachineInfoList
*qmp_query_machines(Error
**errp
)
1548 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1549 MachineInfoList
*mach_list
= NULL
;
1551 for (el
= machines
; el
; el
= el
->next
) {
1552 MachineClass
*mc
= el
->data
;
1553 MachineInfoList
*entry
;
1556 info
= g_malloc0(sizeof(*info
));
1557 if (mc
->is_default
) {
1558 info
->has_is_default
= true;
1559 info
->is_default
= true;
1563 info
->has_alias
= true;
1564 info
->alias
= g_strdup(mc
->alias
);
1567 info
->name
= g_strdup(mc
->name
);
1568 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1569 info
->hotpluggable_cpus
= !!mc
->query_hotpluggable_cpus
;
1571 entry
= g_malloc0(sizeof(*entry
));
1572 entry
->value
= info
;
1573 entry
->next
= mach_list
;
1577 g_slist_free(machines
);
1581 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1583 ObjectProperty
*prop
;
1584 ObjectPropertyIterator iter
;
1586 if (!qemu_opt_has_help_opt(opts
)) {
1590 object_property_iter_init(&iter
, OBJECT(machine
));
1591 while ((prop
= object_property_iter_next(&iter
))) {
1596 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1597 prop
->name
, prop
->type
);
1598 if (prop
->description
) {
1599 error_printf(" (%s)\n", prop
->description
);
1608 /***********************************************************/
1609 /* main execution loop */
1611 struct vm_change_state_entry
{
1612 VMChangeStateHandler
*cb
;
1614 QLIST_ENTRY (vm_change_state_entry
) entries
;
1617 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1619 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1622 VMChangeStateEntry
*e
;
1624 e
= g_malloc0(sizeof (*e
));
1628 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1632 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1634 QLIST_REMOVE (e
, entries
);
1638 void vm_state_notify(int running
, RunState state
)
1640 VMChangeStateEntry
*e
, *next
;
1642 trace_vm_state_notify(running
, state
);
1644 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1645 e
->cb(e
->opaque
, running
, state
);
1649 /* reset/shutdown handler */
1651 typedef struct QEMUResetEntry
{
1652 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1653 QEMUResetHandler
*func
;
1657 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1658 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1659 static int reset_requested
;
1660 static int shutdown_requested
, shutdown_signal
= -1;
1661 static pid_t shutdown_pid
;
1662 static int powerdown_requested
;
1663 static int debug_requested
;
1664 static int suspend_requested
;
1665 static WakeupReason wakeup_reason
;
1666 static NotifierList powerdown_notifiers
=
1667 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1668 static NotifierList suspend_notifiers
=
1669 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1670 static NotifierList wakeup_notifiers
=
1671 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1672 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1674 int qemu_shutdown_requested_get(void)
1676 return shutdown_requested
;
1679 int qemu_reset_requested_get(void)
1681 return reset_requested
;
1684 static int qemu_shutdown_requested(void)
1686 return atomic_xchg(&shutdown_requested
, 0);
1689 static void qemu_kill_report(void)
1691 if (!qtest_driver() && shutdown_signal
!= -1) {
1692 if (shutdown_pid
== 0) {
1693 /* This happens for eg ^C at the terminal, so it's worth
1694 * avoiding printing an odd message in that case.
1696 error_report("terminating on signal %d", shutdown_signal
);
1698 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1700 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1701 shutdown_signal
, shutdown_pid
,
1702 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1703 g_free(shutdown_cmd
);
1705 shutdown_signal
= -1;
1709 static int qemu_reset_requested(void)
1711 int r
= reset_requested
;
1712 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1713 reset_requested
= 0;
1719 static int qemu_suspend_requested(void)
1721 int r
= suspend_requested
;
1722 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1723 suspend_requested
= 0;
1729 static WakeupReason
qemu_wakeup_requested(void)
1731 return wakeup_reason
;
1734 static int qemu_powerdown_requested(void)
1736 int r
= powerdown_requested
;
1737 powerdown_requested
= 0;
1741 static int qemu_debug_requested(void)
1743 int r
= debug_requested
;
1744 debug_requested
= 0;
1748 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1750 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1753 re
->opaque
= opaque
;
1754 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1757 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1761 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1762 if (re
->func
== func
&& re
->opaque
== opaque
) {
1763 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1770 void qemu_devices_reset(void)
1772 QEMUResetEntry
*re
, *nre
;
1774 /* reset all devices */
1775 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1776 re
->func(re
->opaque
);
1780 void qemu_system_reset(bool report
)
1784 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1786 cpu_synchronize_all_states();
1788 if (mc
&& mc
->reset
) {
1791 qemu_devices_reset();
1794 qapi_event_send_reset(&error_abort
);
1796 cpu_synchronize_all_post_reset();
1799 void qemu_system_guest_panicked(void)
1802 current_cpu
->crash_occurred
= true;
1804 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
, &error_abort
);
1805 vm_stop(RUN_STATE_GUEST_PANICKED
);
1807 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1809 qemu_system_shutdown_request();
1813 void qemu_system_reset_request(void)
1816 shutdown_requested
= 1;
1818 reset_requested
= 1;
1821 qemu_notify_event();
1824 static void qemu_system_suspend(void)
1827 notifier_list_notify(&suspend_notifiers
, NULL
);
1828 runstate_set(RUN_STATE_SUSPENDED
);
1829 qapi_event_send_suspend(&error_abort
);
1832 void qemu_system_suspend_request(void)
1834 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1837 suspend_requested
= 1;
1839 qemu_notify_event();
1842 void qemu_register_suspend_notifier(Notifier
*notifier
)
1844 notifier_list_add(&suspend_notifiers
, notifier
);
1847 void qemu_system_wakeup_request(WakeupReason reason
)
1849 trace_system_wakeup_request(reason
);
1851 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1854 if (!(wakeup_reason_mask
& (1 << reason
))) {
1857 runstate_set(RUN_STATE_RUNNING
);
1858 wakeup_reason
= reason
;
1859 qemu_notify_event();
1862 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1865 wakeup_reason_mask
|= (1 << reason
);
1867 wakeup_reason_mask
&= ~(1 << reason
);
1871 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1873 notifier_list_add(&wakeup_notifiers
, notifier
);
1876 void qemu_system_killed(int signal
, pid_t pid
)
1878 shutdown_signal
= signal
;
1882 /* Cannot call qemu_system_shutdown_request directly because
1883 * we are in a signal handler.
1885 shutdown_requested
= 1;
1886 qemu_notify_event();
1889 void qemu_system_shutdown_request(void)
1891 trace_qemu_system_shutdown_request();
1892 replay_shutdown_request();
1893 shutdown_requested
= 1;
1894 qemu_notify_event();
1897 static void qemu_system_powerdown(void)
1899 qapi_event_send_powerdown(&error_abort
);
1900 notifier_list_notify(&powerdown_notifiers
, NULL
);
1903 void qemu_system_powerdown_request(void)
1905 trace_qemu_system_powerdown_request();
1906 powerdown_requested
= 1;
1907 qemu_notify_event();
1910 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1912 notifier_list_add(&powerdown_notifiers
, notifier
);
1915 void qemu_system_debug_request(void)
1917 debug_requested
= 1;
1918 qemu_notify_event();
1921 static bool main_loop_should_exit(void)
1924 if (qemu_debug_requested()) {
1925 vm_stop(RUN_STATE_DEBUG
);
1927 if (qemu_suspend_requested()) {
1928 qemu_system_suspend();
1930 if (qemu_shutdown_requested()) {
1932 qapi_event_send_shutdown(&error_abort
);
1934 vm_stop(RUN_STATE_SHUTDOWN
);
1939 if (qemu_reset_requested()) {
1941 qemu_system_reset(VMRESET_REPORT
);
1943 if (!runstate_check(RUN_STATE_RUNNING
) &&
1944 !runstate_check(RUN_STATE_INMIGRATE
)) {
1945 runstate_set(RUN_STATE_PRELAUNCH
);
1948 if (qemu_wakeup_requested()) {
1950 qemu_system_reset(VMRESET_SILENT
);
1951 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1952 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1954 qapi_event_send_wakeup(&error_abort
);
1956 if (qemu_powerdown_requested()) {
1957 qemu_system_powerdown();
1959 if (qemu_vmstop_requested(&r
)) {
1965 static void main_loop(void)
1969 #ifdef CONFIG_PROFILER
1973 nonblocking
= tcg_enabled() && last_io
> 0;
1974 #ifdef CONFIG_PROFILER
1975 ti
= profile_getclock();
1977 last_io
= main_loop_wait(nonblocking
);
1978 #ifdef CONFIG_PROFILER
1979 dev_time
+= profile_getclock() - ti
;
1981 } while (!main_loop_should_exit());
1984 static void version(void)
1986 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1987 QEMU_COPYRIGHT
"\n");
1990 static void QEMU_NORETURN
help(int exitcode
)
1993 printf("usage: %s [options] [disk_image]\n\n"
1994 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1995 error_get_progname());
1997 #define QEMU_OPTIONS_GENERATE_HELP
1998 #include "qemu-options-wrapper.h"
2000 printf("\nDuring emulation, the following keys are useful:\n"
2001 "ctrl-alt-f toggle full screen\n"
2002 "ctrl-alt-n switch to virtual console 'n'\n"
2003 "ctrl-alt toggle mouse and keyboard grab\n"
2005 "When using -nographic, press 'ctrl-a h' to get some help.\n");
2010 #define HAS_ARG 0x0001
2012 typedef struct QEMUOption
{
2019 static const QEMUOption qemu_options
[] = {
2020 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
2021 #define QEMU_OPTIONS_GENERATE_OPTIONS
2022 #include "qemu-options-wrapper.h"
2026 typedef struct VGAInterfaceInfo
{
2027 const char *opt_name
; /* option name */
2028 const char *name
; /* human-readable name */
2029 /* Class names indicating that support is available.
2030 * If no class is specified, the interface is always available */
2031 const char *class_names
[2];
2034 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
2040 .name
= "standard VGA",
2041 .class_names
= { "VGA", "isa-vga" },
2044 .opt_name
= "cirrus",
2045 .name
= "Cirrus VGA",
2046 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
2049 .opt_name
= "vmware",
2050 .name
= "VMWare SVGA",
2051 .class_names
= { "vmware-svga" },
2054 .opt_name
= "virtio",
2055 .name
= "Virtio VGA",
2056 .class_names
= { "virtio-vga" },
2061 .class_names
= { "qxl-vga" },
2065 .name
= "TCX framebuffer",
2066 .class_names
= { "SUNW,tcx" },
2070 .name
= "CG3 framebuffer",
2071 .class_names
= { "cgthree" },
2074 .opt_name
= "xenfb",
2078 static bool vga_interface_available(VGAInterfaceType t
)
2080 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2082 assert(t
< VGA_TYPE_MAX
);
2083 return !ti
->class_names
[0] ||
2084 object_class_by_name(ti
->class_names
[0]) ||
2085 object_class_by_name(ti
->class_names
[1]);
2088 static void select_vgahw(const char *p
)
2093 assert(vga_interface_type
== VGA_NONE
);
2094 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2095 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2096 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2097 if (!vga_interface_available(t
)) {
2098 error_report("%s not available", ti
->name
);
2101 vga_interface_type
= t
;
2105 if (t
== VGA_TYPE_MAX
) {
2107 error_report("unknown vga type: %s", p
);
2111 const char *nextopt
;
2113 if (strstart(opts
, ",retrace=", &nextopt
)) {
2115 if (strstart(opts
, "dumb", &nextopt
))
2116 vga_retrace_method
= VGA_RETRACE_DUMB
;
2117 else if (strstart(opts
, "precise", &nextopt
))
2118 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2119 else goto invalid_vga
;
2120 } else goto invalid_vga
;
2125 typedef enum DisplayType
{
2134 static DisplayType
select_display(const char *p
)
2137 DisplayType display
= DT_DEFAULT
;
2139 if (strstart(p
, "sdl", &opts
)) {
2143 const char *nextopt
;
2145 if (strstart(opts
, ",frame=", &nextopt
)) {
2147 if (strstart(opts
, "on", &nextopt
)) {
2149 } else if (strstart(opts
, "off", &nextopt
)) {
2152 goto invalid_sdl_args
;
2154 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2156 if (strstart(opts
, "on", &nextopt
)) {
2158 } else if (strstart(opts
, "off", &nextopt
)) {
2161 goto invalid_sdl_args
;
2163 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2165 if (strstart(opts
, "on", &nextopt
)) {
2167 } else if (strstart(opts
, "off", &nextopt
)) {
2170 goto invalid_sdl_args
;
2172 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2174 if (strstart(opts
, "on", &nextopt
)) {
2176 } else if (strstart(opts
, "off", &nextopt
)) {
2179 goto invalid_sdl_args
;
2181 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2183 if (strstart(opts
, "on", &nextopt
)) {
2185 } else if (strstart(opts
, "off", &nextopt
)) {
2188 goto invalid_sdl_args
;
2192 error_report("invalid SDL option string");
2198 error_report("SDL support is disabled");
2201 } else if (strstart(p
, "vnc", &opts
)) {
2203 vnc_parse(opts
+ 1, &error_fatal
);
2205 error_report("VNC requires a display argument vnc=<display>");
2208 } else if (strstart(p
, "curses", &opts
)) {
2209 #ifdef CONFIG_CURSES
2210 display
= DT_CURSES
;
2212 error_report("curses support is disabled");
2215 } else if (strstart(p
, "gtk", &opts
)) {
2219 const char *nextopt
;
2221 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2223 if (strstart(opts
, "on", &nextopt
)) {
2224 grab_on_hover
= true;
2225 } else if (strstart(opts
, "off", &nextopt
)) {
2226 grab_on_hover
= false;
2228 goto invalid_gtk_args
;
2230 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2232 if (strstart(opts
, "on", &nextopt
)) {
2234 } else if (strstart(opts
, "off", &nextopt
)) {
2237 goto invalid_gtk_args
;
2241 error_report("invalid GTK option string");
2247 error_report("GTK support is disabled");
2250 } else if (strstart(p
, "none", &opts
)) {
2253 error_report("unknown display type");
2260 static int balloon_parse(const char *arg
)
2264 if (strcmp(arg
, "none") == 0) {
2268 if (!strncmp(arg
, "virtio", 6)) {
2269 if (arg
[6] == ',') {
2270 /* have params -> parse them */
2271 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2276 /* create empty opts */
2277 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2280 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2287 #if defined(CONFIG_RUBY)
2288 /* Ruby interface for QEMU. See README.EXT for programming example. */
2292 static VALUE
qemu_open(int argc
, VALUE
*argv
, VALUE klass
)
2295 for (i
= 0; i
< argc
; i
++) {
2296 argv
[i
] = StringValue(argv
[i
]);
2297 fprintf(stderr
, "argv[%d] = %s\n", i
, StringValuePtr(argv
[i
]));
2299 //~ if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
2300 //~ mode = 0666; /* default value */
2302 return INT2FIX(argc
);
2305 void Init_qemu(void)
2307 printf("%s\n", __func__
);
2308 VALUE cQEMU
= rb_define_class("QEMU", rb_cObject
);
2309 rb_define_singleton_method(cQEMU
, "run", qemu_open
, -1);
2314 #endif /* CONFIG_RUBY */
2316 #if defined(CONFIG_DLL)
2317 BOOL APIENTRY
DllMain(HINSTANCE hModule
, DWORD ul_reason_for_call
, LPVOID data
)
2321 #endif /* CONFIG_DLL */
2323 char *qemu_find_file(int type
, const char *name
)
2329 /* Try the name as a straight path first */
2330 if (access(name
, R_OK
) == 0) {
2331 trace_load_file(name
, name
);
2332 return g_strdup(name
);
2336 case QEMU_FILE_TYPE_BIOS
:
2339 case QEMU_FILE_TYPE_KEYMAP
:
2340 subdir
= "keymaps/";
2346 for (i
= 0; i
< data_dir_idx
; i
++) {
2347 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2348 if (access(buf
, R_OK
) == 0) {
2349 trace_load_file(name
, buf
);
2357 static inline bool nonempty_str(const char *str
)
2362 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2366 const char *name
, *file
, *str
;
2367 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2369 if (fw_cfg
== NULL
) {
2370 error_report("fw_cfg device not available");
2373 name
= qemu_opt_get(opts
, "name");
2374 file
= qemu_opt_get(opts
, "file");
2375 str
= qemu_opt_get(opts
, "string");
2377 /* we need name and either a file or the content string */
2378 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2379 error_report("invalid argument(s)");
2382 if (nonempty_str(file
) && nonempty_str(str
)) {
2383 error_report("file and string are mutually exclusive");
2386 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2387 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2390 if (strncmp(name
, "opt/", 4) != 0) {
2391 error_report("warning: externally provided fw_cfg item names "
2392 "should be prefixed with \"opt/\"");
2394 if (nonempty_str(str
)) {
2395 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2396 buf
= g_memdup(str
, size
);
2398 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2399 error_report("can't load %s", file
);
2403 /* For legacy, keep user files in a specific global order. */
2404 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2405 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2406 fw_cfg_reset_order_override(fw_cfg
);
2410 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2412 return qdev_device_help(opts
);
2415 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2420 dev
= qdev_device_add(opts
, &err
);
2422 error_report_err(err
);
2425 object_unref(OBJECT(dev
));
2429 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2431 Error
*local_err
= NULL
;
2433 qemu_chr_new_from_opts(opts
, &local_err
);
2435 error_report_err(local_err
);
2441 #ifdef CONFIG_VIRTFS
2442 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2444 return qemu_fsdev_add(opts
);
2448 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2450 CharDriverState
*chr
;
2451 const char *chardev
;
2455 mode
= qemu_opt_get(opts
, "mode");
2459 if (strcmp(mode
, "readline") == 0) {
2460 flags
= MONITOR_USE_READLINE
;
2461 } else if (strcmp(mode
, "control") == 0) {
2462 flags
= MONITOR_USE_CONTROL
;
2464 error_report("unknown monitor mode \"%s\"", mode
);
2468 if (qemu_opt_get_bool(opts
, "pretty", 0))
2469 flags
|= MONITOR_USE_PRETTY
;
2471 if (qemu_opt_get_bool(opts
, "default", 0)) {
2472 error_report("option 'default' does nothing and is deprecated");
2475 chardev
= qemu_opt_get(opts
, "chardev");
2476 chr
= qemu_chr_find(chardev
);
2478 error_report("chardev \"%s\" not found", chardev
);
2482 monitor_init(chr
, flags
);
2486 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2488 static int monitor_device_index
= 0;
2493 if (strstart(optarg
, "chardev:", &p
)) {
2494 snprintf(label
, sizeof(label
), "%s", p
);
2496 snprintf(label
, sizeof(label
), "compat_monitor%d",
2497 monitor_device_index
);
2498 opts
= qemu_chr_parse_compat(label
, optarg
);
2500 error_report("parse error: %s", optarg
);
2505 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2506 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2507 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2508 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2509 monitor_device_index
++;
2512 struct device_config
{
2514 DEV_USB
, /* -usbdevice */
2516 DEV_SERIAL
, /* -serial */
2517 DEV_PARALLEL
, /* -parallel */
2518 DEV_VIRTCON
, /* -virtioconsole */
2519 DEV_DEBUGCON
, /* -debugcon */
2520 DEV_GDB
, /* -gdb, -s */
2521 DEV_SCLP
, /* s390 sclp */
2523 const char *cmdline
;
2525 QTAILQ_ENTRY(device_config
) next
;
2528 static QTAILQ_HEAD(, device_config
) device_configs
=
2529 QTAILQ_HEAD_INITIALIZER(device_configs
);
2531 static void add_device_config(int type
, const char *cmdline
)
2533 struct device_config
*conf
;
2535 conf
= g_malloc0(sizeof(*conf
));
2537 conf
->cmdline
= cmdline
;
2538 loc_save(&conf
->loc
);
2539 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2542 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2544 struct device_config
*conf
;
2547 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2548 if (conf
->type
!= type
)
2550 loc_push_restore(&conf
->loc
);
2551 rc
= func(conf
->cmdline
);
2552 loc_pop(&conf
->loc
);
2560 static int serial_parse(const char *devname
)
2562 static int index
= 0;
2565 if (strcmp(devname
, "none") == 0)
2567 if (index
== MAX_SERIAL_PORTS
) {
2568 error_report("too many serial ports");
2571 snprintf(label
, sizeof(label
), "serial%d", index
);
2572 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2573 if (!serial_hds
[index
]) {
2574 error_report("could not connect serial device"
2575 " to character backend '%s'", devname
);
2582 static int parallel_parse(const char *devname
)
2584 static int index
= 0;
2587 if (strcmp(devname
, "none") == 0)
2589 if (index
== MAX_PARALLEL_PORTS
) {
2590 error_report("too many parallel ports");
2593 snprintf(label
, sizeof(label
), "parallel%d", index
);
2594 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2595 if (!parallel_hds
[index
]) {
2596 error_report("could not connect parallel device"
2597 " to character backend '%s'", devname
);
2604 static int virtcon_parse(const char *devname
)
2606 QemuOptsList
*device
= qemu_find_opts("device");
2607 static int index
= 0;
2609 QemuOpts
*bus_opts
, *dev_opts
;
2611 if (strcmp(devname
, "none") == 0)
2613 if (index
== MAX_VIRTIO_CONSOLES
) {
2614 error_report("too many virtio consoles");
2618 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2619 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2621 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2622 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2624 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2625 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2626 if (!virtcon_hds
[index
]) {
2627 error_report("could not connect virtio console"
2628 " to character backend '%s'", devname
);
2631 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2637 static int sclp_parse(const char *devname
)
2639 QemuOptsList
*device
= qemu_find_opts("device");
2640 static int index
= 0;
2644 if (strcmp(devname
, "none") == 0) {
2647 if (index
== MAX_SCLP_CONSOLES
) {
2648 error_report("too many sclp consoles");
2652 assert(arch_type
== QEMU_ARCH_S390X
);
2654 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2655 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2657 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2658 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2659 if (!sclp_hds
[index
]) {
2660 error_report("could not connect sclp console"
2661 " to character backend '%s'", devname
);
2664 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2670 static int debugcon_parse(const char *devname
)
2674 if (!qemu_chr_new("debugcon", devname
)) {
2677 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2679 error_report("already have a debugcon device");
2682 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2683 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2687 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2689 const MachineClass
*mc1
= a
, *mc2
= b
;
2692 if (mc1
->family
== NULL
) {
2693 if (mc2
->family
== NULL
) {
2694 /* Compare standalone machine types against each other; they sort
2695 * in increasing order.
2697 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2698 object_class_get_name(OBJECT_CLASS(mc2
)));
2701 /* Standalone machine types sort after families. */
2705 if (mc2
->family
== NULL
) {
2706 /* Families sort before standalone machine types. */
2710 /* Families sort between each other alphabetically increasingly. */
2711 res
= strcmp(mc1
->family
, mc2
->family
);
2716 /* Within the same family, machine types sort in decreasing order. */
2717 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2718 object_class_get_name(OBJECT_CLASS(mc1
)));
2721 static MachineClass
*machine_parse(const char *name
)
2723 MachineClass
*mc
= NULL
;
2724 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2727 mc
= find_machine(name
);
2730 g_slist_free(machines
);
2733 if (name
&& !is_help_option(name
)) {
2734 error_report("unsupported machine type");
2735 error_printf("Use -machine help to list supported machines\n");
2737 printf("Supported machines are:\n");
2738 machines
= g_slist_sort(machines
, machine_class_cmp
);
2739 for (el
= machines
; el
; el
= el
->next
) {
2740 MachineClass
*mc
= el
->data
;
2742 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2744 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2745 mc
->is_default
? " (default)" : "");
2749 g_slist_free(machines
);
2750 exit(!name
|| !is_help_option(name
));
2753 void qemu_add_exit_notifier(Notifier
*notify
)
2755 notifier_list_add(&exit_notifiers
, notify
);
2758 void qemu_remove_exit_notifier(Notifier
*notify
)
2760 notifier_remove(notify
);
2763 static void qemu_run_exit_notifiers(void)
2765 notifier_list_notify(&exit_notifiers
, NULL
);
2768 static bool machine_init_done
;
2770 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2772 notifier_list_add(&machine_init_done_notifiers
, notify
);
2773 if (machine_init_done
) {
2774 notify
->notify(notify
, NULL
);
2778 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2780 notifier_remove(notify
);
2783 static void qemu_run_machine_init_done_notifiers(void)
2785 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2786 machine_init_done
= true;
2789 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2790 const char **poptarg
, int *poptind
)
2792 const QEMUOption
*popt
;
2793 int optind
= *poptind
;
2794 char *r
= argv
[optind
];
2797 loc_set_cmdline(argv
, optind
, 1);
2799 /* Treat --foo the same as -foo. */
2802 popt
= qemu_options
;
2805 error_report("invalid option");
2808 if (!strcmp(popt
->name
, r
+ 1))
2812 if (popt
->flags
& HAS_ARG
) {
2813 if (optind
>= argc
) {
2814 error_report("requires an argument");
2817 optarg
= argv
[optind
++];
2818 loc_set_cmdline(argv
, optind
- 2, 2);
2829 static MachineClass
*select_machine(void)
2831 MachineClass
*machine_class
= find_default_machine();
2836 loc_push_none(&loc
);
2838 opts
= qemu_get_machine_opts();
2839 qemu_opts_loc_restore(opts
);
2841 optarg
= qemu_opt_get(opts
, "type");
2843 machine_class
= machine_parse(optarg
);
2846 if (!machine_class
) {
2847 error_report("No machine specified, and there is no default");
2848 error_printf("Use -machine help to list supported machines\n");
2853 return machine_class
;
2856 static int machine_set_property(void *opaque
,
2857 const char *name
, const char *value
,
2860 Object
*obj
= OBJECT(opaque
);
2861 Error
*local_err
= NULL
;
2864 if (strcmp(name
, "type") == 0) {
2868 qom_name
= g_strdup(name
);
2869 for (p
= qom_name
; *p
; p
++) {
2875 object_property_parse(obj
, value
, qom_name
, &local_err
);
2879 error_report_err(local_err
);
2888 * Initial object creation happens before all other
2889 * QEMU data types are created. The majority of objects
2890 * can be created at this point. The rng-egd object
2891 * cannot be created here, as it depends on the chardev
2894 static bool object_create_initial(const char *type
)
2896 if (g_str_equal(type
, "rng-egd")) {
2901 * return false for concrete netfilters since
2902 * they depend on netdevs already existing
2904 if (g_str_equal(type
, "filter-buffer") ||
2905 g_str_equal(type
, "filter-dump") ||
2906 g_str_equal(type
, "filter-mirror") ||
2907 g_str_equal(type
, "filter-redirector") ||
2908 g_str_equal(type
, "colo-compare") ||
2909 g_str_equal(type
, "filter-rewriter") ||
2910 g_str_equal(type
, "filter-replay")) {
2914 /* Memory allocation by backends needs to be done
2915 * after configure_accelerator() (due to the tcg_enabled()
2916 * checks at memory_region_init_*()).
2918 * Also, allocation of large amounts of memory may delay
2919 * chardev initialization for too long, and trigger timeouts
2920 * on software that waits for a monitor socket to be created
2923 if (g_str_has_prefix(type
, "memory-backend-")) {
2932 * The remainder of object creation happens after the
2933 * creation of chardev, fsdev, net clients and device data types.
2935 static bool object_create_delayed(const char *type
)
2937 return !object_create_initial(type
);
2941 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2945 const char *mem_str
;
2946 const char *maxmem_str
, *slots_str
;
2947 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2948 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2951 loc_push_none(&loc
);
2952 qemu_opts_loc_restore(opts
);
2955 mem_str
= qemu_opt_get(opts
, "size");
2958 error_report("missing 'size' option value");
2962 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2964 /* Fix up legacy suffix-less format */
2965 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2966 uint64_t overflow_check
= sz
;
2969 if ((sz
>> 20) != overflow_check
) {
2970 error_report("too large 'size' option value");
2976 /* backward compatibility behaviour for case "-m 0" */
2978 sz
= default_ram_size
;
2981 sz
= QEMU_ALIGN_UP(sz
, 8192);
2983 if (ram_size
!= sz
) {
2984 error_report("ram size too large");
2988 /* store value for the future use */
2989 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2990 *maxram_size
= ram_size
;
2992 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2993 slots_str
= qemu_opt_get(opts
, "slots");
2994 if (maxmem_str
&& slots_str
) {
2997 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2998 slots
= qemu_opt_get_number(opts
, "slots", 0);
2999 if (sz
< ram_size
) {
3000 error_report("invalid value of -m option maxmem: "
3001 "maximum memory size (0x%" PRIx64
") must be at least "
3002 "the initial memory size (0x" RAM_ADDR_FMT
")",
3005 } else if (sz
> ram_size
) {
3007 error_report("invalid value of -m option: maxmem was "
3008 "specified, but no hotplug slots were specified");
3012 error_report("invalid value of -m option maxmem: "
3013 "memory slots were specified but maximum memory size "
3014 "(0x%" PRIx64
") is equal to the initial memory size "
3015 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
3021 } else if ((!maxmem_str
&& slots_str
) ||
3022 (maxmem_str
&& !slots_str
)) {
3023 error_report("invalid -m option value: missing "
3024 "'%s' option", slots_str
? "maxmem" : "slots");
3031 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
3035 g
= g_malloc0(sizeof(*g
));
3036 g
->driver
= qemu_opt_get(opts
, "driver");
3037 g
->property
= qemu_opt_get(opts
, "property");
3038 g
->value
= qemu_opt_get(opts
, "value");
3039 g
->user_provided
= true;
3040 g
->errp
= &error_fatal
;
3041 qdev_prop_register_global(g
);
3045 int main(int argc
, char **argv
)
3048 int snapshot
, linux_boot
;
3049 const char *initrd_filename
;
3050 const char *kernel_filename
, *kernel_cmdline
;
3051 const char *boot_order
= NULL
;
3052 const char *boot_once
= NULL
;
3054 int cyls
, heads
, secs
, translation
;
3055 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
3056 QemuOptsList
*olist
;
3059 const char *loadvm
= NULL
;
3060 MachineClass
*machine_class
;
3061 const char *cpu_model
;
3062 const char *vga_model
= NULL
;
3063 const char *qtest_chrdev
= NULL
;
3064 const char *qtest_log
= NULL
;
3065 const char *pid_file
= NULL
;
3066 const char *incoming
= NULL
;
3067 bool defconfig
= true;
3068 bool userconfig
= true;
3069 bool nographic
= false;
3070 DisplayType display_type
= DT_DEFAULT
;
3071 int display_remote
= 0;
3072 const char *log_mask
= NULL
;
3073 const char *log_file
= NULL
;
3074 char *trace_file
= NULL
;
3075 ram_addr_t maxram_size
;
3076 uint64_t ram_slots
= 0;
3077 FILE *vmstate_dump_file
= NULL
;
3078 Error
*main_loop_err
= NULL
;
3080 bool list_data_dirs
= false;
3082 module_call_init(MODULE_INIT_TRACE
);
3084 qemu_init_cpu_list();
3085 qemu_init_cpu_loop();
3086 qemu_mutex_lock_iothread();
3088 atexit(qemu_run_exit_notifiers
);
3089 error_set_progname(argv
[0]);
3090 qemu_init_exec_dir(argv
[0]);
3092 module_call_init(MODULE_INIT_QOM
);
3093 module_call_init(MODULE_INIT_QAPI
);
3095 qemu_add_opts(&qemu_drive_opts
);
3096 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3097 qemu_add_drive_opts(&qemu_common_drive_opts
);
3098 qemu_add_drive_opts(&qemu_drive_opts
);
3099 qemu_add_drive_opts(&bdrv_runtime_opts
);
3100 qemu_add_opts(&qemu_chardev_opts
);
3101 qemu_add_opts(&qemu_device_opts
);
3102 qemu_add_opts(&qemu_netdev_opts
);
3103 qemu_add_opts(&qemu_net_opts
);
3104 qemu_add_opts(&qemu_rtc_opts
);
3105 qemu_add_opts(&qemu_global_opts
);
3106 qemu_add_opts(&qemu_mon_opts
);
3107 qemu_add_opts(&qemu_trace_opts
);
3108 qemu_add_opts(&qemu_option_rom_opts
);
3109 qemu_add_opts(&qemu_machine_opts
);
3110 qemu_add_opts(&qemu_mem_opts
);
3111 qemu_add_opts(&qemu_smp_opts
);
3112 qemu_add_opts(&qemu_boot_opts
);
3113 qemu_add_opts(&qemu_sandbox_opts
);
3114 qemu_add_opts(&qemu_add_fd_opts
);
3115 qemu_add_opts(&qemu_object_opts
);
3116 qemu_add_opts(&qemu_tpmdev_opts
);
3117 qemu_add_opts(&qemu_realtime_opts
);
3118 qemu_add_opts(&qemu_msg_opts
);
3119 qemu_add_opts(&qemu_name_opts
);
3120 qemu_add_opts(&qemu_numa_opts
);
3121 qemu_add_opts(&qemu_icount_opts
);
3122 qemu_add_opts(&qemu_semihosting_config_opts
);
3123 qemu_add_opts(&qemu_fw_cfg_opts
);
3124 #ifdef CONFIG_LIBISCSI
3125 qemu_add_opts(&qemu_iscsi_opts
);
3127 module_call_init(MODULE_INIT_OPTS
);
3131 if (qcrypto_init(&err
) < 0) {
3132 error_reportf_err(err
, "cannot initialize crypto: ");
3135 rtc_clock
= QEMU_CLOCK_HOST
;
3137 QLIST_INIT (&vm_change_state_head
);
3138 os_setup_early_signal_handling();
3142 cyls
= heads
= secs
= 0;
3143 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3147 bdrv_init_with_whitelist();
3151 /* first pass of option parsing */
3153 while (optind
< argc
) {
3154 if (argv
[optind
][0] != '-') {
3158 const QEMUOption
*popt
;
3160 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3161 switch (popt
->index
) {
3162 case QEMU_OPTION_nodefconfig
:
3165 case QEMU_OPTION_nouserconfig
:
3174 ret
= qemu_read_default_config_files(userconfig
);
3180 /* second pass of option parsing */
3185 if (argv
[optind
][0] != '-') {
3186 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3188 const QEMUOption
*popt
;
3190 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3191 if (!(popt
->arch_mask
& arch_type
)) {
3192 error_report("Option not supported for this target");
3195 switch(popt
->index
) {
3196 case QEMU_OPTION_no_kvm_irqchip
: {
3197 olist
= qemu_find_opts("machine");
3198 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3201 case QEMU_OPTION_cpu
:
3202 /* hw initialization will check this */
3205 case QEMU_OPTION_hda
:
3209 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3211 snprintf(buf
, sizeof(buf
),
3212 "%s,cyls=%d,heads=%d,secs=%d%s",
3213 HD_OPTS
, cyls
, heads
, secs
,
3214 translation
== BIOS_ATA_TRANSLATION_LBA
?
3216 translation
== BIOS_ATA_TRANSLATION_NONE
?
3217 ",trans=none" : "");
3218 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3221 case QEMU_OPTION_hdb
:
3222 case QEMU_OPTION_hdc
:
3223 case QEMU_OPTION_hdd
:
3224 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3227 case QEMU_OPTION_drive
:
3228 if (drive_def(optarg
) == NULL
) {
3232 case QEMU_OPTION_set
:
3233 if (qemu_set_option(optarg
) != 0)
3236 case QEMU_OPTION_global
:
3237 if (qemu_global_option(optarg
) != 0)
3240 case QEMU_OPTION_mtdblock
:
3241 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3243 case QEMU_OPTION_sd
:
3244 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3246 case QEMU_OPTION_pflash
:
3247 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3249 case QEMU_OPTION_snapshot
:
3252 case QEMU_OPTION_hdachs
:
3256 cyls
= strtol(p
, (char **)&p
, 0);
3257 if (cyls
< 1 || cyls
> 16383)
3262 heads
= strtol(p
, (char **)&p
, 0);
3263 if (heads
< 1 || heads
> 16)
3268 secs
= strtol(p
, (char **)&p
, 0);
3269 if (secs
< 1 || secs
> 63)
3273 if (!strcmp(p
, "large")) {
3274 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3275 } else if (!strcmp(p
, "rechs")) {
3276 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3277 } else if (!strcmp(p
, "none")) {
3278 translation
= BIOS_ATA_TRANSLATION_NONE
;
3279 } else if (!strcmp(p
, "lba")) {
3280 translation
= BIOS_ATA_TRANSLATION_LBA
;
3281 } else if (!strcmp(p
, "auto")) {
3282 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3286 } else if (*p
!= '\0') {
3288 error_report("invalid physical CHS format");
3291 if (hda_opts
!= NULL
) {
3292 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3294 qemu_opt_set_number(hda_opts
, "heads", heads
,
3296 qemu_opt_set_number(hda_opts
, "secs", secs
,
3298 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3299 qemu_opt_set(hda_opts
, "trans", "large",
3301 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3302 qemu_opt_set(hda_opts
, "trans", "rechs",
3304 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3305 qemu_opt_set(hda_opts
, "trans", "lba",
3307 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3308 qemu_opt_set(hda_opts
, "trans", "none",
3314 case QEMU_OPTION_numa
:
3315 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3321 case QEMU_OPTION_display
:
3322 display_type
= select_display(optarg
);
3324 case QEMU_OPTION_nographic
:
3325 olist
= qemu_find_opts("machine");
3326 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3328 display_type
= DT_NONE
;
3330 case QEMU_OPTION_curses
:
3331 #ifdef CONFIG_CURSES
3332 display_type
= DT_CURSES
;
3334 error_report("curses support is disabled");
3338 case QEMU_OPTION_portrait
:
3339 graphic_rotate
= 90;
3341 case QEMU_OPTION_rotate
:
3342 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3343 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3344 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3345 error_report("only 90, 180, 270 deg rotation is available");
3349 case QEMU_OPTION_kernel
:
3350 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3353 case QEMU_OPTION_initrd
:
3354 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3357 case QEMU_OPTION_append
:
3358 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3361 case QEMU_OPTION_dtb
:
3362 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3365 case QEMU_OPTION_cdrom
:
3366 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3368 case QEMU_OPTION_boot
:
3369 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3375 case QEMU_OPTION_fda
:
3376 case QEMU_OPTION_fdb
:
3377 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3380 case QEMU_OPTION_no_fd_bootchk
:
3383 case QEMU_OPTION_netdev
:
3385 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3389 case QEMU_OPTION_net
:
3391 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3395 #ifdef CONFIG_LIBISCSI
3396 case QEMU_OPTION_iscsi
:
3397 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3405 case QEMU_OPTION_tftp
:
3406 error_report("The -tftp option is deprecated. "
3407 "Please use '-netdev user,tftp=...' instead.");
3408 legacy_tftp_prefix
= optarg
;
3410 case QEMU_OPTION_bootp
:
3411 error_report("The -bootp option is deprecated. "
3412 "Please use '-netdev user,bootfile=...' instead.");
3413 legacy_bootp_filename
= optarg
;
3415 case QEMU_OPTION_redir
:
3416 error_report("The -redir option is deprecated. "
3417 "Please use '-netdev user,hostfwd=...' instead.");
3418 if (net_slirp_redir(optarg
) < 0)
3422 case QEMU_OPTION_bt
:
3423 add_device_config(DEV_BT
, optarg
);
3425 case QEMU_OPTION_audio_help
:
3429 case QEMU_OPTION_soundhw
:
3430 select_soundhw (optarg
);
3435 case QEMU_OPTION_version
:
3440 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3447 case QEMU_OPTION_tpmdev
:
3448 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3453 case QEMU_OPTION_mempath
:
3456 case QEMU_OPTION_mem_prealloc
:
3465 case QEMU_OPTION_DFILTER
:
3466 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3469 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3471 case QEMU_OPTION_gdb
:
3472 add_device_config(DEV_GDB
, optarg
);
3475 if (is_help_option(optarg
)) {
3476 list_data_dirs
= true;
3477 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3478 data_dir
[data_dir_idx
++] = optarg
;
3481 case QEMU_OPTION_bios
:
3482 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3485 case QEMU_OPTION_singlestep
:
3492 keyboard_layout
= optarg
;
3494 case QEMU_OPTION_localtime
:
3497 case QEMU_OPTION_vga
:
3506 w
= strtol(p
, (char **)&p
, 10);
3509 error_report("invalid resolution or depth");
3515 h
= strtol(p
, (char **)&p
, 10);
3520 depth
= strtol(p
, (char **)&p
, 10);
3521 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3522 depth
!= 24 && depth
!= 32)
3524 } else if (*p
== '\0') {
3525 depth
= graphic_depth
;
3532 graphic_depth
= depth
;
3535 case QEMU_OPTION_echr
:
3538 term_escape_char
= strtol(optarg
, &r
, 0);
3540 printf("Bad argument to echr\n");
3543 case QEMU_OPTION_monitor
:
3544 default_monitor
= 0;
3545 if (strncmp(optarg
, "none", 4)) {
3546 monitor_parse(optarg
, "readline", false);
3549 case QEMU_OPTION_qmp
:
3550 monitor_parse(optarg
, "control", false);
3551 default_monitor
= 0;
3553 case QEMU_OPTION_qmp_pretty
:
3554 monitor_parse(optarg
, "control", true);
3555 default_monitor
= 0;
3557 case QEMU_OPTION_mon
:
3558 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3563 default_monitor
= 0;
3565 case QEMU_OPTION_chardev
:
3566 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3572 case QEMU_OPTION_fsdev
:
3573 olist
= qemu_find_opts("fsdev");
3575 error_report("fsdev support is disabled");
3578 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3583 case QEMU_OPTION_virtfs
: {
3586 const char *writeout
, *sock_fd
, *socket
;
3588 olist
= qemu_find_opts("virtfs");
3590 error_report("virtfs support is disabled");
3593 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3598 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3599 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3600 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3603 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3604 qemu_opt_get(opts
, "mount_tag"),
3607 error_report("duplicate fsdev id: %s",
3608 qemu_opt_get(opts
, "mount_tag"));
3612 writeout
= qemu_opt_get(opts
, "writeout");
3614 #ifdef CONFIG_SYNC_FILE_RANGE
3615 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3617 error_report("writeout=immediate not supported "
3618 "on this platform");
3622 qemu_opt_set(fsdev
, "fsdriver",
3623 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3624 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3626 qemu_opt_set(fsdev
, "security_model",
3627 qemu_opt_get(opts
, "security_model"),
3629 socket
= qemu_opt_get(opts
, "socket");
3631 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3633 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3635 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3638 qemu_opt_set_bool(fsdev
, "readonly",
3639 qemu_opt_get_bool(opts
, "readonly", 0),
3641 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3643 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3644 qemu_opt_set(device
, "fsdev",
3645 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3646 qemu_opt_set(device
, "mount_tag",
3647 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3650 case QEMU_OPTION_virtfs_synth
: {
3654 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3657 error_report("duplicate option: %s", "virtfs_synth");
3660 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3662 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3664 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3665 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3666 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3669 case QEMU_OPTION_serial
:
3670 add_device_config(DEV_SERIAL
, optarg
);
3672 if (strncmp(optarg
, "mon:", 4) == 0) {
3673 default_monitor
= 0;
3676 case QEMU_OPTION_watchdog
:
3678 error_report("only one watchdog option may be given");
3683 case QEMU_OPTION_watchdog_action
:
3684 if (select_watchdog_action(optarg
) == -1) {
3685 error_report("unknown -watchdog-action parameter");
3689 case QEMU_OPTION_virtiocon
:
3690 add_device_config(DEV_VIRTCON
, optarg
);
3691 default_virtcon
= 0;
3692 if (strncmp(optarg
, "mon:", 4) == 0) {
3693 default_monitor
= 0;
3696 case QEMU_OPTION_parallel
:
3697 add_device_config(DEV_PARALLEL
, optarg
);
3698 default_parallel
= 0;
3699 if (strncmp(optarg
, "mon:", 4) == 0) {
3700 default_monitor
= 0;
3703 case QEMU_OPTION_debugcon
:
3704 add_device_config(DEV_DEBUGCON
, optarg
);
3706 case QEMU_OPTION_loadvm
:
3709 case QEMU_OPTION_full_screen
:
3712 case QEMU_OPTION_no_frame
:
3715 case QEMU_OPTION_alt_grab
:
3718 case QEMU_OPTION_ctrl_grab
:
3721 case QEMU_OPTION_no_quit
:
3724 case QEMU_OPTION_sdl
:
3726 display_type
= DT_SDL
;
3729 error_report("SDL support is disabled");
3732 case QEMU_OPTION_pidfile
:
3735 case QEMU_OPTION_win2k_hack
:
3736 win2k_install_hack
= 1;
3738 case QEMU_OPTION_rtc_td_hack
: {
3739 static GlobalProperty slew_lost_ticks
= {
3740 .driver
= "mc146818rtc",
3741 .property
= "lost_tick_policy",
3745 qdev_prop_register_global(&slew_lost_ticks
);
3748 case QEMU_OPTION_acpitable
:
3749 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3754 do_acpitable_option(opts
);
3756 case QEMU_OPTION_smbios
:
3757 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3762 do_smbios_option(opts
);
3764 case QEMU_OPTION_fwcfg
:
3765 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3771 case QEMU_OPTION_enable_kvm
:
3772 olist
= qemu_find_opts("machine");
3773 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3775 case QEMU_OPTION_enable_hax
:
3776 olist
= qemu_find_opts("machine");
3777 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3780 case QEMU_OPTION_machine
:
3781 olist
= qemu_find_opts("machine");
3782 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3787 case QEMU_OPTION_no_kvm
:
3788 olist
= qemu_find_opts("machine");
3789 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3791 case QEMU_OPTION_no_kvm_pit
: {
3792 error_report("warning: ignoring deprecated option");
3795 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3796 static GlobalProperty kvm_pit_lost_tick_policy
= {
3797 .driver
= "kvm-pit",
3798 .property
= "lost_tick_policy",
3802 error_report("warning: deprecated, replaced by "
3803 "-global kvm-pit.lost_tick_policy=discard");
3804 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3807 case QEMU_OPTION_usb
:
3808 olist
= qemu_find_opts("machine");
3809 qemu_opts_parse_noisily(olist
, "usb=on", false);
3811 case QEMU_OPTION_usbdevice
:
3812 olist
= qemu_find_opts("machine");
3813 qemu_opts_parse_noisily(olist
, "usb=on", false);
3814 add_device_config(DEV_USB
, optarg
);
3816 case QEMU_OPTION_device
:
3817 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3822 case QEMU_OPTION_smp
:
3823 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3828 case QEMU_OPTION_vnc
:
3829 vnc_parse(optarg
, &error_fatal
);
3831 case QEMU_OPTION_no_acpi
:
3834 case QEMU_OPTION_no_hpet
:
3837 case QEMU_OPTION_balloon
:
3838 if (balloon_parse(optarg
) < 0) {
3839 error_report("unknown -balloon argument %s", optarg
);
3843 case QEMU_OPTION_no_reboot
:
3846 case QEMU_OPTION_no_shutdown
:
3849 case QEMU_OPTION_show_cursor
:
3852 case QEMU_OPTION_uuid
:
3853 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3854 error_report("failed to parse UUID string: wrong format");
3857 qemu_uuid_set
= true;
3859 case QEMU_OPTION_option_rom
:
3860 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3861 error_report("too many option ROMs");
3864 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3869 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3870 option_rom
[nb_option_roms
].bootindex
=
3871 qemu_opt_get_number(opts
, "bootindex", -1);
3872 if (!option_rom
[nb_option_roms
].name
) {
3873 error_report("Option ROM file is not specified");
3878 case QEMU_OPTION_semihosting
:
3879 semihosting
.enabled
= true;
3880 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3882 case QEMU_OPTION_semihosting_config
:
3883 semihosting
.enabled
= true;
3884 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3887 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3889 const char *target
= qemu_opt_get(opts
, "target");
3890 if (target
!= NULL
) {
3891 if (strcmp("native", target
) == 0) {
3892 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3893 } else if (strcmp("gdb", target
) == 0) {
3894 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3895 } else if (strcmp("auto", target
) == 0) {
3896 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3898 error_report("unsupported semihosting-config %s",
3903 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3905 /* Set semihosting argument count and vector */
3906 qemu_opt_foreach(opts
, add_semihosting_arg
,
3907 &semihosting
, NULL
);
3909 error_report("unsupported semihosting-config %s", optarg
);
3913 case QEMU_OPTION_tdf
:
3914 error_report("warning: ignoring deprecated option");
3916 case QEMU_OPTION_name
:
3917 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3923 case QEMU_OPTION_prom_env
:
3924 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3925 error_report("too many prom variables");
3928 prom_envs
[nb_prom_envs
] = optarg
;
3931 case QEMU_OPTION_old_param
:
3934 case QEMU_OPTION_clock
:
3935 /* Clock options no longer exist. Keep this option for
3936 * backward compatibility.
3939 case QEMU_OPTION_startdate
:
3940 configure_rtc_date_offset(optarg
, 1);
3942 case QEMU_OPTION_rtc
:
3943 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3948 configure_rtc(opts
);
3950 case QEMU_OPTION_tb_size
:
3951 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3952 if (tcg_tb_size
< 0) {
3956 case QEMU_OPTION_icount
:
3957 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3963 case QEMU_OPTION_incoming
:
3965 runstate_set(RUN_STATE_INMIGRATE
);
3969 case QEMU_OPTION_nodefaults
:
3972 case QEMU_OPTION_xen_domid
:
3973 if (!(xen_available())) {
3974 error_report("Option not supported for this target");
3977 xen_domid
= atoi(optarg
);
3979 case QEMU_OPTION_xen_create
:
3980 if (!(xen_available())) {
3981 error_report("Option not supported for this target");
3984 xen_mode
= XEN_CREATE
;
3986 case QEMU_OPTION_xen_attach
:
3987 if (!(xen_available())) {
3988 error_report("Option not supported for this target");
3991 xen_mode
= XEN_ATTACH
;
3993 case QEMU_OPTION_trace
:
3995 trace_file
= trace_opt_parse(optarg
);
3997 case QEMU_OPTION_trace_unassigned
:
3998 trace_unassigned
= true;
4000 case QEMU_OPTION_readconfig
:
4002 int ret
= qemu_read_config_file(optarg
);
4004 error_report("read config %s: %s", optarg
,
4010 case QEMU_OPTION_spice
:
4011 olist
= qemu_find_opts("spice");
4013 error_report("spice support is disabled");
4016 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
4022 case QEMU_OPTION_writeconfig
:
4025 if (strcmp(optarg
, "-") == 0) {
4028 fp
= fopen(optarg
, "w");
4030 error_report("open %s: %s", optarg
,
4035 qemu_config_write(fp
);
4041 case QEMU_OPTION_qtest
:
4042 qtest_chrdev
= optarg
;
4044 case QEMU_OPTION_qtest_log
:
4047 case QEMU_OPTION_sandbox
:
4048 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4054 case QEMU_OPTION_add_fd
:
4056 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4062 error_report("File descriptor passing is disabled on this "
4067 case QEMU_OPTION_object
:
4068 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
4074 case QEMU_OPTION_realtime
:
4075 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4080 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4082 case QEMU_OPTION_msg
:
4083 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4088 configure_msg(opts
);
4090 case QEMU_OPTION_dump_vmstate
:
4091 if (vmstate_dump_file
) {
4092 error_report("only one '-dump-vmstate' "
4093 "option may be given");
4096 vmstate_dump_file
= fopen(optarg
, "w");
4097 if (vmstate_dump_file
== NULL
) {
4098 error_report("open %s: %s", optarg
, strerror(errno
));
4103 os_parse_cmd_args(popt
->index
, optarg
);
4108 * Clear error location left behind by the loop.
4109 * Best done right after the loop. Do not insert code here!
4113 replay_configure(icount_opts
);
4115 machine_class
= select_machine();
4117 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4121 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4122 error_report("could not acquire pid file: %s", strerror(errno
));
4126 if (qemu_init_main_loop(&main_loop_err
)) {
4127 error_report_err(main_loop_err
);
4131 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4132 parse_sandbox
, NULL
, NULL
)) {
4136 if (qemu_opts_foreach(qemu_find_opts("name"),
4137 parse_name
, NULL
, NULL
)) {
4142 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4143 parse_add_fd
, NULL
, NULL
)) {
4147 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4148 cleanup_add_fd
, NULL
, NULL
)) {
4153 current_machine
= MACHINE(object_new(object_class_get_name(
4154 OBJECT_CLASS(machine_class
))));
4155 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4158 object_property_add_child(object_get_root(), "machine",
4159 OBJECT(current_machine
), &error_abort
);
4161 if (machine_class
->minimum_page_bits
) {
4162 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4163 /* This would be a board error: specifying a minimum smaller than
4164 * a target's compile-time fixed setting.
4166 g_assert_not_reached();
4170 cpu_exec_init_all();
4172 if (machine_class
->hw_version
) {
4173 qemu_set_hw_version(machine_class
->hw_version
);
4176 if (cpu_model
&& is_help_option(cpu_model
)) {
4177 list_cpus(stdout
, &fprintf
, cpu_model
);
4181 if (!trace_init_backends()) {
4184 trace_init_file(trace_file
);
4186 /* Open the logfile at this point and set the log mask if necessary.
4189 qemu_set_log_filename(log_file
, &error_fatal
);
4194 mask
= qemu_str_to_log_mask(log_mask
);
4196 qemu_print_log_usage(stdout
);
4204 /* If no data_dir is specified then try to find it relative to the
4206 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4207 data_dir
[data_dir_idx
] = os_find_datadir();
4208 if (data_dir
[data_dir_idx
] != NULL
) {
4212 /* If all else fails use the install path specified when building. */
4213 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4214 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4217 /* -L help lists the data directories and exits. */
4218 if (list_data_dirs
) {
4219 for (i
= 0; i
< data_dir_idx
; i
++) {
4220 printf("%s\n", data_dir
[i
]);
4225 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4227 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4228 if (max_cpus
> machine_class
->max_cpus
) {
4229 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4230 "supported by machine '%s' (%d)", max_cpus
,
4231 machine_class
->name
, machine_class
->max_cpus
);
4236 * Get the default machine options from the machine if it is not already
4237 * specified either by the configuration file or by the command line.
4239 if (machine_class
->default_machine_opts
) {
4240 qemu_opts_set_defaults(qemu_find_opts("machine"),
4241 machine_class
->default_machine_opts
, 0);
4244 qemu_opts_foreach(qemu_find_opts("device"),
4245 default_driver_check
, NULL
, NULL
);
4246 qemu_opts_foreach(qemu_find_opts("global"),
4247 default_driver_check
, NULL
, NULL
);
4249 if (!vga_model
&& !default_vga
) {
4250 vga_interface_type
= VGA_DEVICE
;
4252 if (!has_defaults
|| machine_class
->no_serial
) {
4255 if (!has_defaults
|| machine_class
->no_parallel
) {
4256 default_parallel
= 0;
4258 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4259 default_virtcon
= 0;
4261 if (!has_defaults
|| !machine_class
->use_sclp
) {
4264 if (!has_defaults
|| machine_class
->no_floppy
) {
4267 if (!has_defaults
|| machine_class
->no_cdrom
) {
4270 if (!has_defaults
|| machine_class
->no_sdcard
) {
4273 if (!has_defaults
) {
4274 default_monitor
= 0;
4279 if (is_daemonized()) {
4280 /* According to documentation and historically, -nographic redirects
4281 * serial port, parallel port and monitor to stdio, which does not work
4282 * with -daemonize. We can redirect these to null instead, but since
4283 * -nographic is legacy, let's just error out.
4284 * We disallow -nographic only if all other ports are not redirected
4285 * explicitly, to not break existing legacy setups which uses
4286 * -nographic _and_ redirects all ports explicitly - this is valid
4287 * usage, -nographic is just a no-op in this case.
4290 && (default_parallel
|| default_serial
4291 || default_monitor
|| default_virtcon
)) {
4292 error_report("-nographic cannot be used with -daemonize");
4295 #ifdef CONFIG_CURSES
4296 if (display_type
== DT_CURSES
) {
4297 error_report("curses display cannot be used with -daemonize");
4304 if (default_parallel
)
4305 add_device_config(DEV_PARALLEL
, "null");
4306 if (default_serial
&& default_monitor
) {
4307 add_device_config(DEV_SERIAL
, "mon:stdio");
4308 } else if (default_virtcon
&& default_monitor
) {
4309 add_device_config(DEV_VIRTCON
, "mon:stdio");
4310 } else if (default_sclp
&& default_monitor
) {
4311 add_device_config(DEV_SCLP
, "mon:stdio");
4314 add_device_config(DEV_SERIAL
, "stdio");
4315 if (default_virtcon
)
4316 add_device_config(DEV_VIRTCON
, "stdio");
4318 add_device_config(DEV_SCLP
, "stdio");
4320 if (default_monitor
)
4321 monitor_parse("stdio", "readline", false);
4325 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4326 if (default_parallel
)
4327 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4328 if (default_monitor
)
4329 monitor_parse("vc:80Cx24C", "readline", false);
4330 if (default_virtcon
)
4331 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4333 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4337 #if defined(CONFIG_VNC)
4338 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4342 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4343 #if defined(CONFIG_GTK)
4344 display_type
= DT_GTK
;
4345 #elif defined(CONFIG_SDL)
4346 display_type
= DT_SDL
;
4347 #elif defined(CONFIG_COCOA)
4348 display_type
= DT_COCOA
;
4349 #elif defined(CONFIG_VNC)
4350 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4352 display_type
= DT_NONE
;
4356 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4357 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4358 "for SDL, ignoring option");
4360 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4361 error_report("-no-quit is only valid for GTK and SDL, "
4365 if (display_type
== DT_GTK
) {
4366 early_gtk_display_init(request_opengl
);
4369 if (display_type
== DT_SDL
) {
4370 sdl_display_early_init(request_opengl
);
4373 if (request_opengl
== 1 && display_opengl
== 0) {
4374 #if defined(CONFIG_OPENGL)
4375 error_report("OpenGL is not supported by the display");
4377 error_report("OpenGL support is disabled");
4385 if (qemu_opts_foreach(qemu_find_opts("object"),
4386 user_creatable_add_opts_foreach
,
4387 object_create_initial
, NULL
)) {
4391 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4392 chardev_init_func
, NULL
, NULL
)) {
4396 #ifdef CONFIG_VIRTFS
4397 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4398 fsdev_init_func
, NULL
, NULL
)) {
4403 if (qemu_opts_foreach(qemu_find_opts("device"),
4404 device_help_func
, NULL
, NULL
)) {
4408 machine_opts
= qemu_get_machine_opts();
4409 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4411 object_unref(OBJECT(current_machine
));
4415 configure_accelerator(current_machine
);
4418 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4421 machine_opts
= qemu_get_machine_opts();
4422 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4423 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4424 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4425 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4427 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4429 boot_order
= qemu_opt_get(opts
, "order");
4431 validate_bootdevices(boot_order
, &error_fatal
);
4434 boot_once
= qemu_opt_get(opts
, "once");
4436 validate_bootdevices(boot_once
, &error_fatal
);
4439 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4440 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4444 boot_order
= machine_class
->default_boot_order
;
4447 if (!kernel_cmdline
) {
4448 kernel_cmdline
= "";
4449 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4452 linux_boot
= (kernel_filename
!= NULL
);
4454 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4455 error_report("-append only allowed with -kernel option");
4459 if (!linux_boot
&& initrd_filename
!= NULL
) {
4460 error_report("-initrd only allowed with -kernel option");
4464 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4465 /* fall back to the -kernel/-append */
4466 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4469 os_set_line_buffering();
4471 /* spice needs the timers to be initialized by this point */
4476 if (!tcg_enabled()) {
4477 error_report("-icount is not allowed with hardware virtualization");
4480 configure_icount(icount_opts
, &error_abort
);
4481 qemu_opts_del(icount_opts
);
4485 QemuOptsList
*net
= qemu_find_opts("net");
4486 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4488 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4494 if (net_init_clients() < 0) {
4498 if (qemu_opts_foreach(qemu_find_opts("object"),
4499 user_creatable_add_opts_foreach
,
4500 object_create_delayed
, NULL
)) {
4505 if (tpm_init() < 0) {
4510 /* init the bluetooth world */
4511 if (foreach_device_config(DEV_BT
, bt_parse
))
4514 if (!xen_enabled()) {
4515 /* On 32-bit hosts, QEMU is limited by virtual address space */
4516 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4517 error_report("at most 2047 MB RAM can be simulated");
4525 /* If the currently selected machine wishes to override the units-per-bus
4526 * property of its default HBA interface type, do so now. */
4527 if (machine_class
->units_per_default_bus
) {
4528 override_max_devs(machine_class
->block_default_type
,
4529 machine_class
->units_per_default_bus
);
4532 /* open the virtual block devices */
4533 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4534 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4537 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4538 &machine_class
->block_default_type
, NULL
)) {
4542 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4544 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4545 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4547 parse_numa_opts(machine_class
);
4549 if (qemu_opts_foreach(qemu_find_opts("mon"),
4550 mon_init_func
, NULL
, NULL
)) {
4554 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4556 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4558 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4560 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4563 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4566 /* If no default VGA is requested, the default is "none". */
4568 if (machine_class
->default_display
) {
4569 vga_model
= machine_class
->default_display
;
4570 } else if (vga_interface_available(VGA_CIRRUS
)) {
4571 vga_model
= "cirrus";
4572 } else if (vga_interface_available(VGA_STD
)) {
4577 select_vgahw(vga_model
);
4581 i
= select_watchdog(watchdog
);
4583 exit (i
== 1 ? 1 : 0);
4586 machine_register_compat_props(current_machine
);
4588 qemu_opts_foreach(qemu_find_opts("global"),
4589 global_init_func
, NULL
, NULL
);
4591 /* This checkpoint is required by replay to separate prior clock
4592 reading from the other reads, because timer polling functions query
4593 clock values from the log. */
4594 replay_checkpoint(CHECKPOINT_INIT
);
4595 qdev_machine_init();
4597 current_machine
->ram_size
= ram_size
;
4598 current_machine
->maxram_size
= maxram_size
;
4599 current_machine
->ram_slots
= ram_slots
;
4600 current_machine
->boot_order
= boot_order
;
4601 current_machine
->cpu_model
= cpu_model
;
4603 machine_class
->init(current_machine
);
4609 cpu_synchronize_all_post_init();
4611 numa_post_machine_init();
4613 if (hax_enabled()) {
4617 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4618 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4622 /* init USB devices */
4623 if (machine_usb(current_machine
)) {
4624 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4628 /* Check if IGD GFX passthrough. */
4631 /* init generic devices */
4632 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4633 if (qemu_opts_foreach(qemu_find_opts("device"),
4634 device_init_func
, NULL
, NULL
)) {
4637 rom_reset_order_override();
4639 /* Did we create any drives that we failed to create a device for? */
4640 drive_check_orphaned();
4642 /* Don't warn about the default network setup that you get if
4643 * no command line -net or -netdev options are specified. There
4644 * are two cases that we would otherwise complain about:
4645 * (1) board doesn't support a NIC but the implicit "-net nic"
4647 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4648 * sets up a nic that isn't connected to anything.
4651 net_check_clients();
4656 qemu_boot_set(boot_once
, &error_fatal
);
4657 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4660 ds
= init_displaystate();
4662 /* init local displays */
4663 switch (display_type
) {
4665 curses_display_init(ds
, full_screen
);
4668 sdl_display_init(ds
, full_screen
, no_frame
);
4671 cocoa_display_init(ds
, full_screen
);
4674 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4680 /* must be after terminal init, SDL library changes signal handlers */
4681 os_setup_signal_handling();
4683 /* init remote displays */
4685 qemu_opts_foreach(qemu_find_opts("vnc"),
4686 vnc_init_func
, NULL
, NULL
);
4690 qemu_spice_display_init();
4693 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4697 qdev_machine_creation_done();
4699 /* TODO: once all bus devices are qdevified, this should be done
4700 * when bus is created by qdev.c */
4701 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4702 qemu_run_machine_init_done_notifiers();
4704 if (rom_check_and_register_reset() != 0) {
4705 error_report("rom check and register reset failed");
4711 /* This checkpoint is required by replay to separate prior clock
4712 reading from the other reads, because timer polling functions query
4713 clock values from the log. */
4714 replay_checkpoint(CHECKPOINT_RESET
);
4715 qemu_system_reset(VMRESET_SILENT
);
4716 register_global_state();
4718 if (load_vmstate(loadvm
) < 0) {
4723 qdev_prop_check_globals();
4724 if (vmstate_dump_file
) {
4726 dump_vmstate_json_to_file(vmstate_dump_file
);
4731 Error
*local_err
= NULL
;
4732 qemu_start_incoming_migration(incoming
, &local_err
);
4734 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4737 } else if (autostart
) {
4744 replay_disable_events();
4745 iothread_stop_all();
4751 /* vhost-user must be cleaned up before chardevs. */