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"
30 #include "sysemu/seccomp.h"
33 #if defined(CONFIG_VDE)
34 #include <libvdeplug.h>
38 #if defined(__APPLE__) || defined(main)
40 int qemu_main(int argc
, char **argv
);
41 int main(int argc
, char **argv
)
43 return qemu_main(argc
, argv
);
46 #define main qemu_main
48 #endif /* CONFIG_SDL */
52 #define main qemu_main
53 #endif /* CONFIG_COCOA */
56 #include "qemu/error-report.h"
57 #include "qemu/sockets.h"
59 #include "hw/boards.h"
60 #include "sysemu/accel.h"
62 #include "hw/i386/pc.h"
63 #include "hw/isa/isa.h"
65 #include "sysemu/watchdog.h"
66 #include "hw/smbios/smbios.h"
67 #include "hw/xen/xen.h"
69 #include "hw/loader.h"
70 #include "monitor/qdev.h"
71 #include "sysemu/bt.h"
73 #include "net/slirp.h"
74 #include "monitor/monitor.h"
75 #include "ui/console.h"
77 #include "sysemu/sysemu.h"
78 #include "sysemu/numa.h"
79 #include "exec/gdbstub.h"
80 #include "qemu/timer.h"
81 #include "sysemu/char.h"
82 #include "qemu/bitmap.h"
84 #include "sysemu/blockdev.h"
85 #include "hw/block/block.h"
86 #include "migration/block.h"
87 #include "sysemu/tpm.h"
88 #include "sysemu/dma.h"
89 #include "audio/audio.h"
90 #include "migration/migration.h"
91 #include "sysemu/cpus.h"
92 #include "sysemu/kvm.h"
93 #include "qapi/qmp/qjson.h"
94 #include "qemu/option.h"
95 #include "qemu/config-file.h"
96 #include "qemu-options.h"
97 #include "qmp-commands.h"
98 #include "qemu/main-loop.h"
100 #include "fsdev/qemu-fsdev.h"
102 #include "sysemu/qtest.h"
104 #include "disas/disas.h"
107 #include "slirp/libslirp.h"
110 #include "trace/control.h"
111 #include "qemu/queue.h"
112 #include "sysemu/cpus.h"
113 #include "sysemu/arch_init.h"
115 #include "ui/qemu-spice.h"
116 #include "qapi/string-input-visitor.h"
117 #include "qapi/opts-visitor.h"
118 #include "qom/object_interfaces.h"
119 #include "qapi-event.h"
120 #include "exec/semihost.h"
121 #include "crypto/init.h"
122 #include "sysemu/replay.h"
123 #include "qapi/qmp/qerror.h"
125 #define MAX_VIRTIO_CONSOLES 1
126 #define MAX_SCLP_CONSOLES 1
128 static const char *data_dir
[16];
129 static int data_dir_idx
;
130 const char *bios_name
= NULL
;
131 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
132 int request_opengl
= -1;
134 const char* keyboard_layout
= NULL
;
136 const char *mem_path
= NULL
;
137 int mem_prealloc
= 0; /* force preallocation of physical target memory */
138 bool enable_mlock
= false;
140 NICInfo nd_table
[MAX_NICS
];
142 static int rtc_utc
= 1;
143 static int rtc_date_offset
= -1; /* -1 means no change */
144 QEMUClockType rtc_clock
;
145 int vga_interface_type
= VGA_NONE
;
146 static int full_screen
= 0;
147 static int no_frame
= 0;
149 static bool grab_on_hover
;
150 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
151 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
152 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
153 CharDriverState
*sclp_hds
[MAX_SCLP_CONSOLES
];
154 int win2k_install_hack
= 0;
160 int acpi_enabled
= 1;
163 static int no_reboot
;
166 int graphic_rotate
= 0;
167 const char *watchdog
;
168 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
171 const char *qemu_name
;
174 unsigned int nb_prom_envs
= 0;
175 const char *prom_envs
[MAX_PROM_ENVS
];
178 uint8_t *boot_splash_filedata
;
179 size_t boot_splash_filedata_size
;
180 uint8_t qemu_extra_params_fw
[2];
182 int icount_align_option
;
184 /* The bytes in qemu_uuid[] are in the order specified by RFC4122, _not_ in the
185 * little-endian "wire format" described in the SMBIOS 2.6 specification.
187 uint8_t qemu_uuid
[16];
190 /* Trace unassigned memory or i/o accesses. */
191 bool trace_unassigned
;
193 static NotifierList exit_notifiers
=
194 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
196 static NotifierList machine_init_done_notifiers
=
197 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
201 enum xen_mode xen_mode
= XEN_EMULATE
;
203 static int has_defaults
= 1;
204 static int default_serial
= 1;
205 static int default_parallel
= 1;
206 static int default_virtcon
= 1;
207 static int default_sclp
= 1;
208 static int default_monitor
= 1;
209 static int default_floppy
= 1;
210 static int default_cdrom
= 1;
211 static int default_sdcard
= 1;
212 static int default_vga
= 1;
213 static int default_net
= 1;
219 { .driver
= "isa-serial", .flag
= &default_serial
},
220 { .driver
= "isa-parallel", .flag
= &default_parallel
},
221 { .driver
= "isa-fdc", .flag
= &default_floppy
},
222 { .driver
= "ide-cd", .flag
= &default_cdrom
},
223 { .driver
= "ide-hd", .flag
= &default_cdrom
},
224 { .driver
= "ide-drive", .flag
= &default_cdrom
},
225 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
226 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
227 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
228 { .driver
= "VGA", .flag
= &default_vga
},
229 { .driver
= "isa-vga", .flag
= &default_vga
},
230 { .driver
= "cirrus-vga", .flag
= &default_vga
},
231 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
232 { .driver
= "vmware-svga", .flag
= &default_vga
},
233 { .driver
= "qxl-vga", .flag
= &default_vga
},
234 { .driver
= "virtio-vga", .flag
= &default_vga
},
237 static QemuOptsList qemu_rtc_opts
= {
239 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
243 .type
= QEMU_OPT_STRING
,
246 .type
= QEMU_OPT_STRING
,
249 .type
= QEMU_OPT_STRING
,
251 { /* end of list */ }
255 static QemuOptsList qemu_sandbox_opts
= {
257 .implied_opt_name
= "enable",
258 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
262 .type
= QEMU_OPT_BOOL
,
264 { /* end of list */ }
268 static QemuOptsList qemu_option_rom_opts
= {
269 .name
= "option-rom",
270 .implied_opt_name
= "romfile",
271 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
275 .type
= QEMU_OPT_NUMBER
,
278 .type
= QEMU_OPT_STRING
,
280 { /* end of list */ }
284 static QemuOptsList qemu_machine_opts
= {
286 .implied_opt_name
= "type",
288 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
291 * no elements => accept any
292 * sanity checking will happen later
293 * when setting machine properties
299 static QemuOptsList qemu_boot_opts
= {
301 .implied_opt_name
= "order",
303 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
307 .type
= QEMU_OPT_STRING
,
310 .type
= QEMU_OPT_STRING
,
313 .type
= QEMU_OPT_BOOL
,
316 .type
= QEMU_OPT_STRING
,
318 .name
= "splash-time",
319 .type
= QEMU_OPT_STRING
,
321 .name
= "reboot-timeout",
322 .type
= QEMU_OPT_STRING
,
325 .type
= QEMU_OPT_BOOL
,
331 static QemuOptsList qemu_add_fd_opts
= {
333 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
337 .type
= QEMU_OPT_NUMBER
,
338 .help
= "file descriptor of which a duplicate is added to fd set",
341 .type
= QEMU_OPT_NUMBER
,
342 .help
= "ID of the fd set to add fd to",
345 .type
= QEMU_OPT_STRING
,
346 .help
= "free-form string used to describe fd",
348 { /* end of list */ }
352 static QemuOptsList qemu_object_opts
= {
354 .implied_opt_name
= "qom-type",
355 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
361 static QemuOptsList qemu_tpmdev_opts
= {
363 .implied_opt_name
= "type",
364 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
366 /* options are defined in the TPM backends */
367 { /* end of list */ }
371 static QemuOptsList qemu_realtime_opts
= {
373 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
377 .type
= QEMU_OPT_BOOL
,
379 { /* end of list */ }
383 static QemuOptsList qemu_msg_opts
= {
385 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
389 .type
= QEMU_OPT_BOOL
,
391 { /* end of list */ }
395 static QemuOptsList qemu_name_opts
= {
397 .implied_opt_name
= "guest",
399 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
403 .type
= QEMU_OPT_STRING
,
404 .help
= "Sets the name of the guest.\n"
405 "This name will be displayed in the SDL window caption.\n"
406 "The name will also be used for the VNC server",
409 .type
= QEMU_OPT_STRING
,
410 .help
= "Sets the name of the QEMU process, as shown in top etc",
412 .name
= "debug-threads",
413 .type
= QEMU_OPT_BOOL
,
414 .help
= "When enabled, name the individual threads; defaults off.\n"
415 "NOTE: The thread names are for debugging and not a\n"
418 { /* End of list */ }
422 static QemuOptsList qemu_mem_opts
= {
424 .implied_opt_name
= "size",
425 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
430 .type
= QEMU_OPT_SIZE
,
434 .type
= QEMU_OPT_NUMBER
,
438 .type
= QEMU_OPT_SIZE
,
440 { /* end of list */ }
444 static QemuOptsList qemu_icount_opts
= {
446 .implied_opt_name
= "shift",
448 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
452 .type
= QEMU_OPT_STRING
,
455 .type
= QEMU_OPT_BOOL
,
458 .type
= QEMU_OPT_BOOL
,
461 .type
= QEMU_OPT_STRING
,
464 .type
= QEMU_OPT_STRING
,
466 { /* end of list */ }
470 static QemuOptsList qemu_semihosting_config_opts
= {
471 .name
= "semihosting-config",
472 .implied_opt_name
= "enable",
473 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
477 .type
= QEMU_OPT_BOOL
,
480 .type
= QEMU_OPT_STRING
,
483 .type
= QEMU_OPT_STRING
,
485 { /* end of list */ }
489 static QemuOptsList qemu_fw_cfg_opts
= {
491 .implied_opt_name
= "name",
492 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
496 .type
= QEMU_OPT_STRING
,
497 .help
= "Sets the fw_cfg name of the blob to be inserted",
500 .type
= QEMU_OPT_STRING
,
501 .help
= "Sets the name of the file from which\n"
502 "the fw_cfg blob will be loaded",
505 .type
= QEMU_OPT_STRING
,
506 .help
= "Sets content of the blob to be inserted from a string",
508 { /* end of list */ }
513 * Get machine options
515 * Returns: machine options (never null).
517 QemuOpts
*qemu_get_machine_opts(void)
519 return qemu_find_opts_singleton("machine");
522 const char *qemu_get_vm_name(void)
527 static void res_free(void)
529 g_free(boot_splash_filedata
);
530 boot_splash_filedata
= NULL
;
533 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
535 const char *driver
= qemu_opt_get(opts
, "driver");
540 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
541 if (strcmp(default_list
[i
].driver
, driver
) != 0)
543 *(default_list
[i
].flag
) = 0;
548 /***********************************************************/
551 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
553 /* We use RUN_STATE__MAX but any invalid value will do */
554 static RunState vmstop_requested
= RUN_STATE__MAX
;
555 static QemuMutex vmstop_lock
;
560 } RunStateTransition
;
562 static const RunStateTransition runstate_transitions_def
[] = {
564 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
565 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
566 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
568 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
569 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
570 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
571 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
572 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
573 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
574 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
575 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
576 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
577 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
578 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
580 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
581 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
582 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
584 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
585 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
586 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
588 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
589 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
590 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
592 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
593 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
594 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
596 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
597 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
598 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
600 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
601 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
602 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
604 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
605 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
607 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
608 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
609 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
610 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
611 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
612 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
613 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
614 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
615 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
616 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
618 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
620 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
621 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
622 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
624 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
625 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
626 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
627 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
628 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
630 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
631 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
632 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
634 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
635 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
636 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
638 { RUN_STATE__MAX
, RUN_STATE__MAX
},
641 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
643 bool runstate_check(RunState state
)
645 return current_run_state
== state
;
648 bool runstate_store(char *str
, size_t size
)
650 const char *state
= RunState_lookup
[current_run_state
];
651 size_t len
= strlen(state
) + 1;
656 memcpy(str
, state
, len
);
660 static void runstate_init(void)
662 const RunStateTransition
*p
;
664 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
665 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
666 runstate_valid_transitions
[p
->from
][p
->to
] = true;
669 qemu_mutex_init(&vmstop_lock
);
672 /* This function will abort() on invalid state transitions */
673 void runstate_set(RunState new_state
)
675 assert(new_state
< RUN_STATE__MAX
);
677 if (current_run_state
== new_state
) {
681 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
682 error_report("invalid runstate transition: '%s' -> '%s'",
683 RunState_lookup
[current_run_state
],
684 RunState_lookup
[new_state
]);
687 trace_runstate_set(new_state
);
688 current_run_state
= new_state
;
691 int runstate_is_running(void)
693 return runstate_check(RUN_STATE_RUNNING
);
696 bool runstate_needs_reset(void)
698 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
699 runstate_check(RUN_STATE_SHUTDOWN
);
702 StatusInfo
*qmp_query_status(Error
**errp
)
704 StatusInfo
*info
= g_malloc0(sizeof(*info
));
706 info
->running
= runstate_is_running();
707 info
->singlestep
= singlestep
;
708 info
->status
= current_run_state
;
713 static bool qemu_vmstop_requested(RunState
*r
)
715 qemu_mutex_lock(&vmstop_lock
);
716 *r
= vmstop_requested
;
717 vmstop_requested
= RUN_STATE__MAX
;
718 qemu_mutex_unlock(&vmstop_lock
);
719 return *r
< RUN_STATE__MAX
;
722 void qemu_system_vmstop_request_prepare(void)
724 qemu_mutex_lock(&vmstop_lock
);
727 void qemu_system_vmstop_request(RunState state
)
729 vmstop_requested
= state
;
730 qemu_mutex_unlock(&vmstop_lock
);
738 qemu_vmstop_requested(&requested
);
739 if (runstate_is_running() && requested
== RUN_STATE__MAX
) {
743 /* Ensure that a STOP/RESUME pair of events is emitted if a
744 * vmstop request was pending. The BLOCK_IO_ERROR event, for
745 * example, according to documentation is always followed by
748 if (runstate_is_running()) {
749 qapi_event_send_stop(&error_abort
);
752 runstate_set(RUN_STATE_RUNNING
);
753 vm_state_notify(1, RUN_STATE_RUNNING
);
757 qapi_event_send_resume(&error_abort
);
761 /***********************************************************/
762 /* real time host monotonic timer */
764 static time_t qemu_time(void)
766 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
769 /***********************************************************/
770 /* host time/date access */
771 void qemu_get_timedate(struct tm
*tm
, int offset
)
773 time_t ti
= qemu_time();
776 if (rtc_date_offset
== -1) {
780 localtime_r(&ti
, tm
);
782 ti
-= rtc_date_offset
;
787 int qemu_timedate_diff(struct tm
*tm
)
791 if (rtc_date_offset
== -1)
793 seconds
= mktimegm(tm
);
796 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
797 seconds
= mktime(&tmp
);
800 seconds
= mktimegm(tm
) + rtc_date_offset
;
802 return seconds
- qemu_time();
805 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
807 time_t rtc_start_date
;
810 if (!strcmp(startdate
, "now") && legacy
) {
811 rtc_date_offset
= -1;
813 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
821 } else if (sscanf(startdate
, "%d-%d-%d",
833 rtc_start_date
= mktimegm(&tm
);
834 if (rtc_start_date
== -1) {
836 error_report("invalid date format");
837 error_printf("valid formats: "
838 "'2006-06-17T16:01:21' or '2006-06-17'\n");
841 rtc_date_offset
= qemu_time() - rtc_start_date
;
845 static void configure_rtc(QemuOpts
*opts
)
849 value
= qemu_opt_get(opts
, "base");
851 if (!strcmp(value
, "utc")) {
853 } else if (!strcmp(value
, "localtime")) {
854 Error
*blocker
= NULL
;
856 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
857 "-rtc base=localtime");
858 replay_add_blocker(blocker
);
860 configure_rtc_date_offset(value
, 0);
863 value
= qemu_opt_get(opts
, "clock");
865 if (!strcmp(value
, "host")) {
866 rtc_clock
= QEMU_CLOCK_HOST
;
867 } else if (!strcmp(value
, "rt")) {
868 rtc_clock
= QEMU_CLOCK_REALTIME
;
869 } else if (!strcmp(value
, "vm")) {
870 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
872 error_report("invalid option value '%s'", value
);
876 value
= qemu_opt_get(opts
, "driftfix");
878 if (!strcmp(value
, "slew")) {
879 static GlobalProperty slew_lost_ticks
= {
880 .driver
= "mc146818rtc",
881 .property
= "lost_tick_policy",
885 qdev_prop_register_global(&slew_lost_ticks
);
886 } else if (!strcmp(value
, "none")) {
887 /* discard is default */
889 error_report("invalid option value '%s'", value
);
895 /***********************************************************/
896 /* Bluetooth support */
899 static struct HCIInfo
*hci_table
[MAX_NICS
];
901 struct HCIInfo
*qemu_next_hci(void)
903 if (cur_hci
== nb_hcis
)
906 return hci_table
[cur_hci
++];
909 static int bt_hci_parse(const char *str
)
914 if (nb_hcis
>= MAX_NICS
) {
915 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
928 bdaddr
.b
[5] = 0x56 + nb_hcis
;
929 hci
->bdaddr_set(hci
, bdaddr
.b
);
931 hci_table
[nb_hcis
++] = hci
;
936 static void bt_vhci_add(int vlan_id
)
938 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
941 error_report("warning: adding a VHCI to an empty scatternet %i",
944 bt_vhci_init(bt_new_hci(vlan
));
947 static struct bt_device_s
*bt_device_add(const char *opt
)
949 struct bt_scatternet_s
*vlan
;
951 char *endp
= strstr(opt
, ",vlan=");
952 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
955 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
958 vlan_id
= strtol(endp
+ 6, &endp
, 0);
960 error_report("unrecognised bluetooth vlan Id");
965 vlan
= qemu_find_bt_vlan(vlan_id
);
968 error_report("warning: adding a slave device to an empty scatternet %i",
971 if (!strcmp(devname
, "keyboard"))
972 return bt_keyboard_init(vlan
);
974 error_report("unsupported bluetooth device '%s'", devname
);
978 static int bt_parse(const char *opt
)
980 const char *endp
, *p
;
983 if (strstart(opt
, "hci", &endp
)) {
984 if (!*endp
|| *endp
== ',') {
986 if (!strstart(endp
, ",vlan=", 0))
989 return bt_hci_parse(opt
);
991 } else if (strstart(opt
, "vhci", &endp
)) {
992 if (!*endp
|| *endp
== ',') {
994 if (strstart(endp
, ",vlan=", &p
)) {
995 vlan
= strtol(p
, (char **) &endp
, 0);
997 error_report("bad scatternet '%s'", p
);
1001 error_report("bad parameter '%s'", endp
+ 1);
1010 } else if (strstart(opt
, "device:", &endp
))
1011 return !bt_device_add(endp
);
1013 error_report("bad bluetooth parameter '%s'", opt
);
1017 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1019 /* FIXME: change this to true for 1.3 */
1020 if (qemu_opt_get_bool(opts
, "enable", false)) {
1021 #ifdef CONFIG_SECCOMP
1022 if (seccomp_start() < 0) {
1023 error_report("failed to install seccomp syscall filter "
1028 error_report("seccomp support is disabled");
1036 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1038 const char *proc_name
;
1040 if (qemu_opt_get(opts
, "debug-threads")) {
1041 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1043 qemu_name
= qemu_opt_get(opts
, "guest");
1045 proc_name
= qemu_opt_get(opts
, "process");
1047 os_set_proc_name(proc_name
);
1053 bool defaults_enabled(void)
1055 return has_defaults
;
1059 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1061 int fd
, dupfd
, flags
;
1063 const char *fd_opaque
= NULL
;
1066 fd
= qemu_opt_get_number(opts
, "fd", -1);
1067 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1068 fd_opaque
= qemu_opt_get(opts
, "opaque");
1071 error_report("fd option is required and must be non-negative");
1075 if (fd
<= STDERR_FILENO
) {
1076 error_report("fd cannot be a standard I/O stream");
1081 * All fds inherited across exec() necessarily have FD_CLOEXEC
1082 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1084 flags
= fcntl(fd
, F_GETFD
);
1085 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1086 error_report("fd is not valid or already in use");
1091 error_report("set option is required and must be non-negative");
1095 #ifdef F_DUPFD_CLOEXEC
1096 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1100 qemu_set_cloexec(dupfd
);
1104 error_report("error duplicating fd: %s", strerror(errno
));
1108 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1109 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1116 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1120 fd
= qemu_opt_get_number(opts
, "fd", -1);
1127 /***********************************************************/
1128 /* QEMU Block devices */
1130 #define HD_OPTS "media=disk"
1131 #define CDROM_OPTS "media=cdrom"
1133 #define PFLASH_OPTS ""
1137 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1139 BlockInterfaceType
*block_default_type
= opaque
;
1141 return drive_new(opts
, *block_default_type
) == NULL
;
1144 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1146 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1147 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1152 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1153 int index
, const char *optstr
)
1158 if (!enable
|| drive_get_by_index(type
, index
)) {
1162 opts
= drive_add(type
, index
, NULL
, optstr
);
1164 drive_enable_snapshot(NULL
, opts
, NULL
);
1167 dinfo
= drive_new(opts
, type
);
1171 dinfo
->is_default
= true;
1175 static QemuOptsList qemu_smp_opts
= {
1177 .implied_opt_name
= "cpus",
1178 .merge_lists
= true,
1179 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1183 .type
= QEMU_OPT_NUMBER
,
1186 .type
= QEMU_OPT_NUMBER
,
1189 .type
= QEMU_OPT_NUMBER
,
1192 .type
= QEMU_OPT_NUMBER
,
1195 .type
= QEMU_OPT_NUMBER
,
1197 { /*End of list */ }
1201 static void smp_parse(QemuOpts
*opts
)
1204 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1205 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1206 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1207 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1209 /* compute missing values, prefer sockets over cores over threads */
1210 if (cpus
== 0 || sockets
== 0) {
1211 sockets
= sockets
> 0 ? sockets
: 1;
1212 cores
= cores
> 0 ? cores
: 1;
1213 threads
= threads
> 0 ? threads
: 1;
1215 cpus
= cores
* threads
* sockets
;
1217 } else if (cores
== 0) {
1218 threads
= threads
> 0 ? threads
: 1;
1219 cores
= cpus
/ (sockets
* threads
);
1220 cores
= cores
> 0 ? cores
: 1;
1221 } else if (threads
== 0) {
1222 threads
= cpus
/ (cores
* sockets
);
1223 threads
= threads
> 0 ? threads
: 1;
1224 } else if (sockets
* cores
* threads
< cpus
) {
1225 error_report("cpu topology: "
1226 "sockets (%u) * cores (%u) * threads (%u) < "
1228 sockets
, cores
, threads
, cpus
);
1232 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1234 if (max_cpus
> MAX_CPUMASK_BITS
) {
1235 error_report("unsupported number of maxcpus");
1239 if (max_cpus
< cpus
) {
1240 error_report("maxcpus must be equal to or greater than smp");
1244 if (sockets
* cores
* threads
> max_cpus
) {
1245 error_report("cpu topology: "
1246 "sockets (%u) * cores (%u) * threads (%u) > "
1248 sockets
, cores
, threads
, max_cpus
);
1254 smp_threads
= threads
;
1258 Error
*blocker
= NULL
;
1259 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1260 replay_add_blocker(blocker
);
1264 static void realtime_init(void)
1267 if (os_mlock() < 0) {
1268 error_report("locking memory failed");
1275 static void configure_msg(QemuOpts
*opts
)
1277 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1280 /***********************************************************/
1283 typedef struct SemihostingConfig
{
1285 SemihostingTarget target
;
1288 const char *cmdline
; /* concatenated argv */
1289 } SemihostingConfig
;
1291 static SemihostingConfig semihosting
;
1293 bool semihosting_enabled(void)
1295 return semihosting
.enabled
;
1298 SemihostingTarget
semihosting_get_target(void)
1300 return semihosting
.target
;
1303 const char *semihosting_get_arg(int i
)
1305 if (i
>= semihosting
.argc
) {
1308 return semihosting
.argv
[i
];
1311 int semihosting_get_argc(void)
1313 return semihosting
.argc
;
1316 const char *semihosting_get_cmdline(void)
1318 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1319 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1321 return semihosting
.cmdline
;
1324 static int add_semihosting_arg(void *opaque
,
1325 const char *name
, const char *val
,
1328 SemihostingConfig
*s
= opaque
;
1329 if (strcmp(name
, "arg") == 0) {
1331 /* one extra element as g_strjoinv() expects NULL-terminated array */
1332 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1333 s
->argv
[s
->argc
- 1] = val
;
1334 s
->argv
[s
->argc
] = NULL
;
1339 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1340 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1345 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1347 /* split -append and initialize argv[1..n] */
1348 cmd_token
= strtok(g_strdup(cmd
), " ");
1350 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1351 cmd_token
= strtok(NULL
, " ");
1355 /* Now we still need this for compatibility with XEN. */
1356 bool has_igd_gfx_passthru
;
1357 static void igd_gfx_passthru(void)
1359 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1362 /***********************************************************/
1365 static int usb_device_add(const char *devname
)
1367 USBDevice
*dev
= NULL
;
1368 #ifndef CONFIG_LINUX
1372 if (!machine_usb(current_machine
)) {
1376 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1377 dev
= usbdevice_create(devname
);
1381 /* the other ones */
1382 #ifndef CONFIG_LINUX
1383 /* only the linux version is qdev-ified, usb-bsd still needs this */
1384 if (strstart(devname
, "host:", &p
)) {
1385 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1395 static int usb_device_del(const char *devname
)
1400 if (strstart(devname
, "host:", &p
)) {
1404 if (!machine_usb(current_machine
)) {
1408 p
= strchr(devname
, '.');
1411 bus_num
= strtoul(devname
, NULL
, 0);
1412 addr
= strtoul(p
+ 1, NULL
, 0);
1414 return usb_device_delete_addr(bus_num
, addr
);
1417 static int usb_parse(const char *cmdline
)
1420 r
= usb_device_add(cmdline
);
1422 error_report("could not add USB device '%s'", cmdline
);
1427 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1429 const char *devname
= qdict_get_str(qdict
, "devname");
1430 if (usb_device_add(devname
) < 0) {
1431 error_report("could not add USB device '%s'", devname
);
1435 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1437 const char *devname
= qdict_get_str(qdict
, "devname");
1438 if (usb_device_del(devname
) < 0) {
1439 error_report("could not delete USB device '%s'", devname
);
1443 /***********************************************************/
1444 /* machine registration */
1446 MachineState
*current_machine
;
1448 static MachineClass
*find_machine(const char *name
)
1450 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1451 MachineClass
*mc
= NULL
;
1453 for (el
= machines
; el
; el
= el
->next
) {
1454 MachineClass
*temp
= el
->data
;
1456 if (!strcmp(temp
->name
, name
)) {
1461 !strcmp(temp
->alias
, name
)) {
1467 g_slist_free(machines
);
1471 MachineClass
*find_default_machine(void)
1473 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1474 MachineClass
*mc
= NULL
;
1476 for (el
= machines
; el
; el
= el
->next
) {
1477 MachineClass
*temp
= el
->data
;
1479 if (temp
->is_default
) {
1485 g_slist_free(machines
);
1489 MachineInfoList
*qmp_query_machines(Error
**errp
)
1491 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1492 MachineInfoList
*mach_list
= NULL
;
1494 for (el
= machines
; el
; el
= el
->next
) {
1495 MachineClass
*mc
= el
->data
;
1496 MachineInfoList
*entry
;
1499 info
= g_malloc0(sizeof(*info
));
1500 if (mc
->is_default
) {
1501 info
->has_is_default
= true;
1502 info
->is_default
= true;
1506 info
->has_alias
= true;
1507 info
->alias
= g_strdup(mc
->alias
);
1510 info
->name
= g_strdup(mc
->name
);
1511 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1512 info
->hotpluggable_cpus
= !!mc
->query_hotpluggable_cpus
;
1514 entry
= g_malloc0(sizeof(*entry
));
1515 entry
->value
= info
;
1516 entry
->next
= mach_list
;
1520 g_slist_free(machines
);
1524 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1526 ObjectProperty
*prop
;
1527 ObjectPropertyIterator iter
;
1529 if (!qemu_opt_has_help_opt(opts
)) {
1533 object_property_iter_init(&iter
, OBJECT(machine
));
1534 while ((prop
= object_property_iter_next(&iter
))) {
1539 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1540 prop
->name
, prop
->type
);
1541 if (prop
->description
) {
1542 error_printf(" (%s)\n", prop
->description
);
1551 /***********************************************************/
1552 /* main execution loop */
1554 struct vm_change_state_entry
{
1555 VMChangeStateHandler
*cb
;
1557 QLIST_ENTRY (vm_change_state_entry
) entries
;
1560 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1562 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1565 VMChangeStateEntry
*e
;
1567 e
= g_malloc0(sizeof (*e
));
1571 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1575 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1577 QLIST_REMOVE (e
, entries
);
1581 void vm_state_notify(int running
, RunState state
)
1583 VMChangeStateEntry
*e
, *next
;
1585 trace_vm_state_notify(running
, state
);
1587 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1588 e
->cb(e
->opaque
, running
, state
);
1592 /* reset/shutdown handler */
1594 typedef struct QEMUResetEntry
{
1595 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1596 QEMUResetHandler
*func
;
1600 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1601 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1602 static int reset_requested
;
1603 static int shutdown_requested
, shutdown_signal
= -1;
1604 static pid_t shutdown_pid
;
1605 static int powerdown_requested
;
1606 static int debug_requested
;
1607 static int suspend_requested
;
1608 static WakeupReason wakeup_reason
;
1609 static NotifierList powerdown_notifiers
=
1610 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1611 static NotifierList suspend_notifiers
=
1612 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1613 static NotifierList wakeup_notifiers
=
1614 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1615 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1617 int qemu_shutdown_requested_get(void)
1619 return shutdown_requested
;
1622 int qemu_reset_requested_get(void)
1624 return reset_requested
;
1627 static int qemu_shutdown_requested(void)
1629 return atomic_xchg(&shutdown_requested
, 0);
1632 static void qemu_kill_report(void)
1634 if (!qtest_driver() && shutdown_signal
!= -1) {
1635 if (shutdown_pid
== 0) {
1636 /* This happens for eg ^C at the terminal, so it's worth
1637 * avoiding printing an odd message in that case.
1639 error_report("terminating on signal %d", shutdown_signal
);
1641 error_report("terminating on signal %d from pid " FMT_pid
,
1642 shutdown_signal
, shutdown_pid
);
1644 shutdown_signal
= -1;
1648 static int qemu_reset_requested(void)
1650 int r
= reset_requested
;
1651 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1652 reset_requested
= 0;
1658 static int qemu_suspend_requested(void)
1660 int r
= suspend_requested
;
1661 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1662 suspend_requested
= 0;
1668 static WakeupReason
qemu_wakeup_requested(void)
1670 return wakeup_reason
;
1673 static int qemu_powerdown_requested(void)
1675 int r
= powerdown_requested
;
1676 powerdown_requested
= 0;
1680 static int qemu_debug_requested(void)
1682 int r
= debug_requested
;
1683 debug_requested
= 0;
1687 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1689 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1692 re
->opaque
= opaque
;
1693 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1696 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1700 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1701 if (re
->func
== func
&& re
->opaque
== opaque
) {
1702 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1709 void qemu_devices_reset(void)
1711 QEMUResetEntry
*re
, *nre
;
1713 /* reset all devices */
1714 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1715 re
->func(re
->opaque
);
1719 void qemu_system_reset(bool report
)
1723 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1725 cpu_synchronize_all_states();
1727 if (mc
&& mc
->reset
) {
1730 qemu_devices_reset();
1733 qapi_event_send_reset(&error_abort
);
1735 cpu_synchronize_all_post_reset();
1738 void qemu_system_guest_panicked(void)
1741 current_cpu
->crash_occurred
= true;
1743 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
, &error_abort
);
1744 vm_stop(RUN_STATE_GUEST_PANICKED
);
1747 void qemu_system_reset_request(void)
1750 shutdown_requested
= 1;
1752 reset_requested
= 1;
1755 qemu_notify_event();
1758 static void qemu_system_suspend(void)
1761 notifier_list_notify(&suspend_notifiers
, NULL
);
1762 runstate_set(RUN_STATE_SUSPENDED
);
1763 qapi_event_send_suspend(&error_abort
);
1766 void qemu_system_suspend_request(void)
1768 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1771 suspend_requested
= 1;
1773 qemu_notify_event();
1776 void qemu_register_suspend_notifier(Notifier
*notifier
)
1778 notifier_list_add(&suspend_notifiers
, notifier
);
1781 void qemu_system_wakeup_request(WakeupReason reason
)
1783 trace_system_wakeup_request(reason
);
1785 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1788 if (!(wakeup_reason_mask
& (1 << reason
))) {
1791 runstate_set(RUN_STATE_RUNNING
);
1792 wakeup_reason
= reason
;
1793 qemu_notify_event();
1796 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1799 wakeup_reason_mask
|= (1 << reason
);
1801 wakeup_reason_mask
&= ~(1 << reason
);
1805 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1807 notifier_list_add(&wakeup_notifiers
, notifier
);
1810 void qemu_system_killed(int signal
, pid_t pid
)
1812 shutdown_signal
= signal
;
1816 /* Cannot call qemu_system_shutdown_request directly because
1817 * we are in a signal handler.
1819 shutdown_requested
= 1;
1820 qemu_notify_event();
1823 void qemu_system_shutdown_request(void)
1825 trace_qemu_system_shutdown_request();
1826 replay_shutdown_request();
1827 shutdown_requested
= 1;
1828 qemu_notify_event();
1831 static void qemu_system_powerdown(void)
1833 qapi_event_send_powerdown(&error_abort
);
1834 notifier_list_notify(&powerdown_notifiers
, NULL
);
1837 void qemu_system_powerdown_request(void)
1839 trace_qemu_system_powerdown_request();
1840 powerdown_requested
= 1;
1841 qemu_notify_event();
1844 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1846 notifier_list_add(&powerdown_notifiers
, notifier
);
1849 void qemu_system_debug_request(void)
1851 debug_requested
= 1;
1852 qemu_notify_event();
1855 static bool main_loop_should_exit(void)
1858 if (qemu_debug_requested()) {
1859 vm_stop(RUN_STATE_DEBUG
);
1861 if (qemu_suspend_requested()) {
1862 qemu_system_suspend();
1864 if (qemu_shutdown_requested()) {
1866 qapi_event_send_shutdown(&error_abort
);
1868 vm_stop(RUN_STATE_SHUTDOWN
);
1873 if (qemu_reset_requested()) {
1875 qemu_system_reset(VMRESET_REPORT
);
1877 if (!runstate_check(RUN_STATE_RUNNING
) &&
1878 !runstate_check(RUN_STATE_INMIGRATE
)) {
1879 runstate_set(RUN_STATE_PRELAUNCH
);
1882 if (qemu_wakeup_requested()) {
1884 qemu_system_reset(VMRESET_SILENT
);
1885 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1886 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1888 qapi_event_send_wakeup(&error_abort
);
1890 if (qemu_powerdown_requested()) {
1891 qemu_system_powerdown();
1893 if (qemu_vmstop_requested(&r
)) {
1899 static void main_loop(void)
1903 #ifdef CONFIG_PROFILER
1907 nonblocking
= !kvm_enabled() && !xen_enabled() && last_io
> 0;
1908 #ifdef CONFIG_PROFILER
1909 ti
= profile_getclock();
1911 last_io
= main_loop_wait(nonblocking
);
1912 #ifdef CONFIG_PROFILER
1913 dev_time
+= profile_getclock() - ti
;
1915 } while (!main_loop_should_exit());
1918 static void version(void)
1920 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1923 static void QEMU_NORETURN
help(int exitcode
)
1926 printf("usage: %s [options] [disk_image]\n\n"
1927 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1928 error_get_progname());
1930 #define QEMU_OPTIONS_GENERATE_HELP
1931 #include "qemu-options-wrapper.h"
1933 printf("\nDuring emulation, the following keys are useful:\n"
1934 "ctrl-alt-f toggle full screen\n"
1935 "ctrl-alt-n switch to virtual console 'n'\n"
1936 "ctrl-alt toggle mouse and keyboard grab\n"
1938 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1943 #define HAS_ARG 0x0001
1945 typedef struct QEMUOption
{
1952 static const QEMUOption qemu_options
[] = {
1953 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1954 #define QEMU_OPTIONS_GENERATE_OPTIONS
1955 #include "qemu-options-wrapper.h"
1959 typedef struct VGAInterfaceInfo
{
1960 const char *opt_name
; /* option name */
1961 const char *name
; /* human-readable name */
1962 /* Class names indicating that support is available.
1963 * If no class is specified, the interface is always available */
1964 const char *class_names
[2];
1967 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1973 .name
= "standard VGA",
1974 .class_names
= { "VGA", "isa-vga" },
1977 .opt_name
= "cirrus",
1978 .name
= "Cirrus VGA",
1979 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1982 .opt_name
= "vmware",
1983 .name
= "VMWare SVGA",
1984 .class_names
= { "vmware-svga" },
1987 .opt_name
= "virtio",
1988 .name
= "Virtio VGA",
1989 .class_names
= { "virtio-vga" },
1994 .class_names
= { "qxl-vga" },
1998 .name
= "TCX framebuffer",
1999 .class_names
= { "SUNW,tcx" },
2003 .name
= "CG3 framebuffer",
2004 .class_names
= { "cgthree" },
2007 .opt_name
= "xenfb",
2011 static bool vga_interface_available(VGAInterfaceType t
)
2013 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2015 assert(t
< VGA_TYPE_MAX
);
2016 return !ti
->class_names
[0] ||
2017 object_class_by_name(ti
->class_names
[0]) ||
2018 object_class_by_name(ti
->class_names
[1]);
2021 static void select_vgahw(const char *p
)
2026 assert(vga_interface_type
== VGA_NONE
);
2027 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2028 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2029 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2030 if (!vga_interface_available(t
)) {
2031 error_report("%s not available", ti
->name
);
2034 vga_interface_type
= t
;
2038 if (t
== VGA_TYPE_MAX
) {
2040 error_report("unknown vga type: %s", p
);
2044 const char *nextopt
;
2046 if (strstart(opts
, ",retrace=", &nextopt
)) {
2048 if (strstart(opts
, "dumb", &nextopt
))
2049 vga_retrace_method
= VGA_RETRACE_DUMB
;
2050 else if (strstart(opts
, "precise", &nextopt
))
2051 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2052 else goto invalid_vga
;
2053 } else goto invalid_vga
;
2058 typedef enum DisplayType
{
2067 static DisplayType
select_display(const char *p
)
2070 DisplayType display
= DT_DEFAULT
;
2072 if (strstart(p
, "sdl", &opts
)) {
2076 const char *nextopt
;
2078 if (strstart(opts
, ",frame=", &nextopt
)) {
2080 if (strstart(opts
, "on", &nextopt
)) {
2082 } else if (strstart(opts
, "off", &nextopt
)) {
2085 goto invalid_sdl_args
;
2087 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2089 if (strstart(opts
, "on", &nextopt
)) {
2091 } else if (strstart(opts
, "off", &nextopt
)) {
2094 goto invalid_sdl_args
;
2096 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2098 if (strstart(opts
, "on", &nextopt
)) {
2100 } else if (strstart(opts
, "off", &nextopt
)) {
2103 goto invalid_sdl_args
;
2105 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2107 if (strstart(opts
, "on", &nextopt
)) {
2109 } else if (strstart(opts
, "off", &nextopt
)) {
2112 goto invalid_sdl_args
;
2114 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2116 if (strstart(opts
, "on", &nextopt
)) {
2118 } else if (strstart(opts
, "off", &nextopt
)) {
2121 goto invalid_sdl_args
;
2125 error_report("invalid SDL option string");
2131 error_report("SDL support is disabled");
2134 } else if (strstart(p
, "vnc", &opts
)) {
2136 vnc_parse(opts
+ 1, &error_fatal
);
2138 error_report("VNC requires a display argument vnc=<display>");
2141 } else if (strstart(p
, "curses", &opts
)) {
2142 #ifdef CONFIG_CURSES
2143 display
= DT_CURSES
;
2145 error_report("curses support is disabled");
2148 } else if (strstart(p
, "gtk", &opts
)) {
2152 const char *nextopt
;
2154 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2156 if (strstart(opts
, "on", &nextopt
)) {
2157 grab_on_hover
= true;
2158 } else if (strstart(opts
, "off", &nextopt
)) {
2159 grab_on_hover
= false;
2161 goto invalid_gtk_args
;
2163 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2165 if (strstart(opts
, "on", &nextopt
)) {
2167 } else if (strstart(opts
, "off", &nextopt
)) {
2170 goto invalid_gtk_args
;
2174 error_report("invalid GTK option string");
2180 error_report("GTK support is disabled");
2183 } else if (strstart(p
, "none", &opts
)) {
2186 error_report("unknown display type");
2193 static int balloon_parse(const char *arg
)
2197 if (strcmp(arg
, "none") == 0) {
2201 if (!strncmp(arg
, "virtio", 6)) {
2202 if (arg
[6] == ',') {
2203 /* have params -> parse them */
2204 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2209 /* create empty opts */
2210 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2213 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2220 #if defined(CONFIG_RUBY)
2221 /* Ruby interface for QEMU. See README.EXT for programming example. */
2225 static VALUE
qemu_open(int argc
, VALUE
*argv
, VALUE klass
)
2228 for (i
= 0; i
< argc
; i
++) {
2229 argv
[i
] = StringValue(argv
[i
]);
2230 fprintf(stderr
, "argv[%d] = %s\n", i
, StringValuePtr(argv
[i
]));
2232 //~ if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
2233 //~ mode = 0666; /* default value */
2235 return INT2FIX(argc
);
2238 void Init_qemu(void)
2240 printf("%s\n", __func__
);
2241 VALUE cQEMU
= rb_define_class("QEMU", rb_cObject
);
2242 rb_define_singleton_method(cQEMU
, "run", qemu_open
, -1);
2247 #endif /* CONFIG_RUBY */
2249 #if defined(CONFIG_DLL)
2250 BOOL APIENTRY
DllMain(HINSTANCE hModule
, DWORD ul_reason_for_call
, LPVOID data
)
2254 #endif /* CONFIG_DLL */
2256 char *qemu_find_file(int type
, const char *name
)
2262 /* Try the name as a straight path first */
2263 if (access(name
, R_OK
) == 0) {
2264 trace_load_file(name
, name
);
2265 return g_strdup(name
);
2269 case QEMU_FILE_TYPE_BIOS
:
2272 case QEMU_FILE_TYPE_KEYMAP
:
2273 subdir
= "keymaps/";
2279 for (i
= 0; i
< data_dir_idx
; i
++) {
2280 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2281 if (access(buf
, R_OK
) == 0) {
2282 trace_load_file(name
, buf
);
2290 static inline bool nonempty_str(const char *str
)
2295 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2299 const char *name
, *file
, *str
;
2300 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2302 if (fw_cfg
== NULL
) {
2303 error_report("fw_cfg device not available");
2306 name
= qemu_opt_get(opts
, "name");
2307 file
= qemu_opt_get(opts
, "file");
2308 str
= qemu_opt_get(opts
, "string");
2310 /* we need name and either a file or the content string */
2311 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2312 error_report("invalid argument(s)");
2315 if (nonempty_str(file
) && nonempty_str(str
)) {
2316 error_report("file and string are mutually exclusive");
2319 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2320 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2323 if (strncmp(name
, "opt/", 4) != 0) {
2324 error_report("warning: externally provided fw_cfg item names "
2325 "should be prefixed with \"opt/\"");
2327 if (nonempty_str(str
)) {
2328 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2329 buf
= g_memdup(str
, size
);
2331 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2332 error_report("can't load %s", file
);
2336 /* For legacy, keep user files in a specific global order. */
2337 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2338 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2339 fw_cfg_reset_order_override(fw_cfg
);
2343 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2345 return qdev_device_help(opts
);
2348 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2353 dev
= qdev_device_add(opts
, &err
);
2355 error_report_err(err
);
2358 object_unref(OBJECT(dev
));
2362 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2364 Error
*local_err
= NULL
;
2366 qemu_chr_new_from_opts(opts
, NULL
, &local_err
);
2368 error_report_err(local_err
);
2374 #ifdef CONFIG_VIRTFS
2375 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2377 return qemu_fsdev_add(opts
);
2381 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2383 CharDriverState
*chr
;
2384 const char *chardev
;
2388 mode
= qemu_opt_get(opts
, "mode");
2392 if (strcmp(mode
, "readline") == 0) {
2393 flags
= MONITOR_USE_READLINE
;
2394 } else if (strcmp(mode
, "control") == 0) {
2395 flags
= MONITOR_USE_CONTROL
;
2397 error_report("unknown monitor mode \"%s\"", mode
);
2401 if (qemu_opt_get_bool(opts
, "pretty", 0))
2402 flags
|= MONITOR_USE_PRETTY
;
2404 if (qemu_opt_get_bool(opts
, "default", 0))
2405 flags
|= MONITOR_IS_DEFAULT
;
2407 chardev
= qemu_opt_get(opts
, "chardev");
2408 chr
= qemu_chr_find(chardev
);
2410 error_report("chardev \"%s\" not found", chardev
);
2414 qemu_chr_fe_claim_no_fail(chr
);
2415 monitor_init(chr
, flags
);
2419 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2421 static int monitor_device_index
= 0;
2427 if (strstart(optarg
, "chardev:", &p
)) {
2428 snprintf(label
, sizeof(label
), "%s", p
);
2430 snprintf(label
, sizeof(label
), "compat_monitor%d",
2431 monitor_device_index
);
2432 if (monitor_device_index
== 0) {
2435 opts
= qemu_chr_parse_compat(label
, optarg
);
2437 error_report("parse error: %s", optarg
);
2442 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2443 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2444 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2445 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2447 qemu_opt_set(opts
, "default", "on", &error_abort
);
2448 monitor_device_index
++;
2451 struct device_config
{
2453 DEV_USB
, /* -usbdevice */
2455 DEV_SERIAL
, /* -serial */
2456 DEV_PARALLEL
, /* -parallel */
2457 DEV_VIRTCON
, /* -virtioconsole */
2458 DEV_DEBUGCON
, /* -debugcon */
2459 DEV_GDB
, /* -gdb, -s */
2460 DEV_SCLP
, /* s390 sclp */
2462 const char *cmdline
;
2464 QTAILQ_ENTRY(device_config
) next
;
2467 static QTAILQ_HEAD(, device_config
) device_configs
=
2468 QTAILQ_HEAD_INITIALIZER(device_configs
);
2470 static void add_device_config(int type
, const char *cmdline
)
2472 struct device_config
*conf
;
2474 conf
= g_malloc0(sizeof(*conf
));
2476 conf
->cmdline
= cmdline
;
2477 loc_save(&conf
->loc
);
2478 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2481 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2483 struct device_config
*conf
;
2486 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2487 if (conf
->type
!= type
)
2489 loc_push_restore(&conf
->loc
);
2490 rc
= func(conf
->cmdline
);
2491 loc_pop(&conf
->loc
);
2499 static int serial_parse(const char *devname
)
2501 static int index
= 0;
2504 if (strcmp(devname
, "none") == 0)
2506 if (index
== MAX_SERIAL_PORTS
) {
2507 error_report("too many serial ports");
2510 snprintf(label
, sizeof(label
), "serial%d", index
);
2511 serial_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2512 if (!serial_hds
[index
]) {
2513 error_report("could not connect serial device"
2514 " to character backend '%s'", devname
);
2521 static int parallel_parse(const char *devname
)
2523 static int index
= 0;
2526 if (strcmp(devname
, "none") == 0)
2528 if (index
== MAX_PARALLEL_PORTS
) {
2529 error_report("too many parallel ports");
2532 snprintf(label
, sizeof(label
), "parallel%d", index
);
2533 parallel_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2534 if (!parallel_hds
[index
]) {
2535 error_report("could not connect parallel device"
2536 " to character backend '%s'", devname
);
2543 static int virtcon_parse(const char *devname
)
2545 QemuOptsList
*device
= qemu_find_opts("device");
2546 static int index
= 0;
2548 QemuOpts
*bus_opts
, *dev_opts
;
2550 if (strcmp(devname
, "none") == 0)
2552 if (index
== MAX_VIRTIO_CONSOLES
) {
2553 error_report("too many virtio consoles");
2557 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2558 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2560 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2561 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2563 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2564 virtcon_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2565 if (!virtcon_hds
[index
]) {
2566 error_report("could not connect virtio console"
2567 " to character backend '%s'", devname
);
2570 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2576 static int sclp_parse(const char *devname
)
2578 QemuOptsList
*device
= qemu_find_opts("device");
2579 static int index
= 0;
2583 if (strcmp(devname
, "none") == 0) {
2586 if (index
== MAX_SCLP_CONSOLES
) {
2587 error_report("too many sclp consoles");
2591 assert(arch_type
== QEMU_ARCH_S390X
);
2593 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2594 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2596 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2597 sclp_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2598 if (!sclp_hds
[index
]) {
2599 error_report("could not connect sclp console"
2600 " to character backend '%s'", devname
);
2603 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2609 static int debugcon_parse(const char *devname
)
2613 if (!qemu_chr_new("debugcon", devname
, NULL
)) {
2616 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2618 error_report("already have a debugcon device");
2621 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2622 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2626 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2628 const MachineClass
*mc1
= a
, *mc2
= b
;
2631 if (mc1
->family
== NULL
) {
2632 if (mc2
->family
== NULL
) {
2633 /* Compare standalone machine types against each other; they sort
2634 * in increasing order.
2636 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2637 object_class_get_name(OBJECT_CLASS(mc2
)));
2640 /* Standalone machine types sort after families. */
2644 if (mc2
->family
== NULL
) {
2645 /* Families sort before standalone machine types. */
2649 /* Families sort between each other alphabetically increasingly. */
2650 res
= strcmp(mc1
->family
, mc2
->family
);
2655 /* Within the same family, machine types sort in decreasing order. */
2656 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2657 object_class_get_name(OBJECT_CLASS(mc1
)));
2660 static MachineClass
*machine_parse(const char *name
)
2662 MachineClass
*mc
= NULL
;
2663 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2666 mc
= find_machine(name
);
2669 g_slist_free(machines
);
2672 if (name
&& !is_help_option(name
)) {
2673 error_report("unsupported machine type");
2674 error_printf("Use -machine help to list supported machines\n");
2676 printf("Supported machines are:\n");
2677 machines
= g_slist_sort(machines
, machine_class_cmp
);
2678 for (el
= machines
; el
; el
= el
->next
) {
2679 MachineClass
*mc
= el
->data
;
2681 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2683 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2684 mc
->is_default
? " (default)" : "");
2688 g_slist_free(machines
);
2689 exit(!name
|| !is_help_option(name
));
2692 void qemu_add_exit_notifier(Notifier
*notify
)
2694 notifier_list_add(&exit_notifiers
, notify
);
2697 void qemu_remove_exit_notifier(Notifier
*notify
)
2699 notifier_remove(notify
);
2702 static void qemu_run_exit_notifiers(void)
2704 notifier_list_notify(&exit_notifiers
, NULL
);
2707 static bool machine_init_done
;
2709 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2711 notifier_list_add(&machine_init_done_notifiers
, notify
);
2712 if (machine_init_done
) {
2713 notify
->notify(notify
, NULL
);
2717 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2719 notifier_remove(notify
);
2722 static void qemu_run_machine_init_done_notifiers(void)
2724 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2725 machine_init_done
= true;
2728 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2729 const char **poptarg
, int *poptind
)
2731 const QEMUOption
*popt
;
2732 int optind
= *poptind
;
2733 char *r
= argv
[optind
];
2736 loc_set_cmdline(argv
, optind
, 1);
2738 /* Treat --foo the same as -foo. */
2741 popt
= qemu_options
;
2744 error_report("invalid option");
2747 if (!strcmp(popt
->name
, r
+ 1))
2751 if (popt
->flags
& HAS_ARG
) {
2752 if (optind
>= argc
) {
2753 error_report("requires an argument");
2756 optarg
= argv
[optind
++];
2757 loc_set_cmdline(argv
, optind
- 2, 2);
2768 static MachineClass
*select_machine(void)
2770 MachineClass
*machine_class
= find_default_machine();
2775 loc_push_none(&loc
);
2777 opts
= qemu_get_machine_opts();
2778 qemu_opts_loc_restore(opts
);
2780 optarg
= qemu_opt_get(opts
, "type");
2782 machine_class
= machine_parse(optarg
);
2785 if (!machine_class
) {
2786 error_report("No machine specified, and there is no default");
2787 error_printf("Use -machine help to list supported machines\n");
2792 return machine_class
;
2795 static int machine_set_property(void *opaque
,
2796 const char *name
, const char *value
,
2799 Object
*obj
= OBJECT(opaque
);
2800 Error
*local_err
= NULL
;
2803 if (strcmp(name
, "type") == 0) {
2807 qom_name
= g_strdup(name
);
2815 object_property_parse(obj
, value
, qom_name
, &local_err
);
2819 error_report_err(local_err
);
2828 * Initial object creation happens before all other
2829 * QEMU data types are created. The majority of objects
2830 * can be created at this point. The rng-egd object
2831 * cannot be created here, as it depends on the chardev
2834 static bool object_create_initial(const char *type
)
2836 if (g_str_equal(type
, "rng-egd")) {
2841 * return false for concrete netfilters since
2842 * they depend on netdevs already existing
2844 if (g_str_equal(type
, "filter-buffer") ||
2845 g_str_equal(type
, "filter-dump") ||
2846 g_str_equal(type
, "filter-mirror") ||
2847 g_str_equal(type
, "filter-redirector")) {
2856 * The remainder of object creation happens after the
2857 * creation of chardev, fsdev, net clients and device data types.
2859 static bool object_create_delayed(const char *type
)
2861 return !object_create_initial(type
);
2865 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2869 const char *mem_str
;
2870 const char *maxmem_str
, *slots_str
;
2871 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2872 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2875 loc_push_none(&loc
);
2876 qemu_opts_loc_restore(opts
);
2879 mem_str
= qemu_opt_get(opts
, "size");
2882 error_report("missing 'size' option value");
2886 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2888 /* Fix up legacy suffix-less format */
2889 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2890 uint64_t overflow_check
= sz
;
2893 if ((sz
>> 20) != overflow_check
) {
2894 error_report("too large 'size' option value");
2900 /* backward compatibility behaviour for case "-m 0" */
2902 sz
= default_ram_size
;
2905 sz
= QEMU_ALIGN_UP(sz
, 8192);
2907 if (ram_size
!= sz
) {
2908 error_report("ram size too large");
2912 /* store value for the future use */
2913 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2914 *maxram_size
= ram_size
;
2916 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2917 slots_str
= qemu_opt_get(opts
, "slots");
2918 if (maxmem_str
&& slots_str
) {
2921 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2922 slots
= qemu_opt_get_number(opts
, "slots", 0);
2923 if (sz
< ram_size
) {
2924 error_report("invalid value of -m option maxmem: "
2925 "maximum memory size (0x%" PRIx64
") must be at least "
2926 "the initial memory size (0x" RAM_ADDR_FMT
")",
2929 } else if (sz
> ram_size
) {
2931 error_report("invalid value of -m option: maxmem was "
2932 "specified, but no hotplug slots were specified");
2936 error_report("invalid value of -m option maxmem: "
2937 "memory slots were specified but maximum memory size "
2938 "(0x%" PRIx64
") is equal to the initial memory size "
2939 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2945 } else if ((!maxmem_str
&& slots_str
) ||
2946 (maxmem_str
&& !slots_str
)) {
2947 error_report("invalid -m option value: missing "
2948 "'%s' option", slots_str
? "maxmem" : "slots");
2955 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2959 g
= g_malloc0(sizeof(*g
));
2960 g
->driver
= qemu_opt_get(opts
, "driver");
2961 g
->property
= qemu_opt_get(opts
, "property");
2962 g
->value
= qemu_opt_get(opts
, "value");
2963 g
->user_provided
= true;
2964 qdev_prop_register_global(g
);
2968 int main(int argc
, char **argv
)
2971 int snapshot
, linux_boot
;
2972 const char *initrd_filename
;
2973 const char *kernel_filename
, *kernel_cmdline
;
2974 const char *boot_order
= NULL
;
2975 const char *boot_once
= NULL
;
2977 int cyls
, heads
, secs
, translation
;
2978 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
2979 QemuOptsList
*olist
;
2982 const char *loadvm
= NULL
;
2983 MachineClass
*machine_class
;
2984 const char *cpu_model
;
2985 const char *vga_model
= NULL
;
2986 const char *qtest_chrdev
= NULL
;
2987 const char *qtest_log
= NULL
;
2988 const char *pid_file
= NULL
;
2989 const char *incoming
= NULL
;
2990 bool defconfig
= true;
2991 bool userconfig
= true;
2992 bool nographic
= false;
2993 DisplayType display_type
= DT_DEFAULT
;
2994 int display_remote
= 0;
2995 const char *log_mask
= NULL
;
2996 const char *log_file
= NULL
;
2997 char *trace_file
= NULL
;
2998 ram_addr_t maxram_size
;
2999 uint64_t ram_slots
= 0;
3000 FILE *vmstate_dump_file
= NULL
;
3001 Error
*main_loop_err
= NULL
;
3003 bool list_data_dirs
= false;
3005 qemu_init_cpu_loop();
3006 qemu_mutex_lock_iothread();
3008 atexit(qemu_run_exit_notifiers
);
3009 error_set_progname(argv
[0]);
3010 qemu_init_exec_dir(argv
[0]);
3012 module_call_init(MODULE_INIT_QOM
);
3014 qemu_add_opts(&qemu_drive_opts
);
3015 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3016 qemu_add_drive_opts(&qemu_common_drive_opts
);
3017 qemu_add_drive_opts(&qemu_drive_opts
);
3018 qemu_add_opts(&qemu_chardev_opts
);
3019 qemu_add_opts(&qemu_device_opts
);
3020 qemu_add_opts(&qemu_netdev_opts
);
3021 qemu_add_opts(&qemu_net_opts
);
3022 qemu_add_opts(&qemu_rtc_opts
);
3023 qemu_add_opts(&qemu_global_opts
);
3024 qemu_add_opts(&qemu_mon_opts
);
3025 qemu_add_opts(&qemu_trace_opts
);
3026 qemu_add_opts(&qemu_option_rom_opts
);
3027 qemu_add_opts(&qemu_machine_opts
);
3028 qemu_add_opts(&qemu_mem_opts
);
3029 qemu_add_opts(&qemu_smp_opts
);
3030 qemu_add_opts(&qemu_boot_opts
);
3031 qemu_add_opts(&qemu_sandbox_opts
);
3032 qemu_add_opts(&qemu_add_fd_opts
);
3033 qemu_add_opts(&qemu_object_opts
);
3034 qemu_add_opts(&qemu_tpmdev_opts
);
3035 qemu_add_opts(&qemu_realtime_opts
);
3036 qemu_add_opts(&qemu_msg_opts
);
3037 qemu_add_opts(&qemu_name_opts
);
3038 qemu_add_opts(&qemu_numa_opts
);
3039 qemu_add_opts(&qemu_icount_opts
);
3040 qemu_add_opts(&qemu_semihosting_config_opts
);
3041 qemu_add_opts(&qemu_fw_cfg_opts
);
3042 module_call_init(MODULE_INIT_OPTS
);
3046 if (qcrypto_init(&err
) < 0) {
3047 error_reportf_err(err
, "cannot initialize crypto: ");
3050 rtc_clock
= QEMU_CLOCK_HOST
;
3052 QLIST_INIT (&vm_change_state_head
);
3053 os_setup_early_signal_handling();
3057 cyls
= heads
= secs
= 0;
3058 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3062 bdrv_init_with_whitelist();
3066 /* first pass of option parsing */
3068 while (optind
< argc
) {
3069 if (argv
[optind
][0] != '-') {
3073 const QEMUOption
*popt
;
3075 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3076 switch (popt
->index
) {
3077 case QEMU_OPTION_nodefconfig
:
3080 case QEMU_OPTION_nouserconfig
:
3089 ret
= qemu_read_default_config_files(userconfig
);
3095 /* second pass of option parsing */
3100 if (argv
[optind
][0] != '-') {
3101 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3103 const QEMUOption
*popt
;
3105 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3106 if (!(popt
->arch_mask
& arch_type
)) {
3107 error_report("Option not supported for this target");
3110 switch(popt
->index
) {
3111 case QEMU_OPTION_no_kvm_irqchip
: {
3112 olist
= qemu_find_opts("machine");
3113 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3116 case QEMU_OPTION_cpu
:
3117 /* hw initialization will check this */
3120 case QEMU_OPTION_hda
:
3124 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3126 snprintf(buf
, sizeof(buf
),
3127 "%s,cyls=%d,heads=%d,secs=%d%s",
3128 HD_OPTS
, cyls
, heads
, secs
,
3129 translation
== BIOS_ATA_TRANSLATION_LBA
?
3131 translation
== BIOS_ATA_TRANSLATION_NONE
?
3132 ",trans=none" : "");
3133 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3136 case QEMU_OPTION_hdb
:
3137 case QEMU_OPTION_hdc
:
3138 case QEMU_OPTION_hdd
:
3139 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3142 case QEMU_OPTION_drive
:
3143 if (drive_def(optarg
) == NULL
) {
3147 case QEMU_OPTION_set
:
3148 if (qemu_set_option(optarg
) != 0)
3151 case QEMU_OPTION_global
:
3152 if (qemu_global_option(optarg
) != 0)
3155 case QEMU_OPTION_mtdblock
:
3156 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3158 case QEMU_OPTION_sd
:
3159 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3161 case QEMU_OPTION_pflash
:
3162 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3164 case QEMU_OPTION_snapshot
:
3167 case QEMU_OPTION_hdachs
:
3171 cyls
= strtol(p
, (char **)&p
, 0);
3172 if (cyls
< 1 || cyls
> 16383)
3177 heads
= strtol(p
, (char **)&p
, 0);
3178 if (heads
< 1 || heads
> 16)
3183 secs
= strtol(p
, (char **)&p
, 0);
3184 if (secs
< 1 || secs
> 63)
3188 if (!strcmp(p
, "large")) {
3189 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3190 } else if (!strcmp(p
, "rechs")) {
3191 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3192 } else if (!strcmp(p
, "none")) {
3193 translation
= BIOS_ATA_TRANSLATION_NONE
;
3194 } else if (!strcmp(p
, "lba")) {
3195 translation
= BIOS_ATA_TRANSLATION_LBA
;
3196 } else if (!strcmp(p
, "auto")) {
3197 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3201 } else if (*p
!= '\0') {
3203 error_report("invalid physical CHS format");
3206 if (hda_opts
!= NULL
) {
3207 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3209 qemu_opt_set_number(hda_opts
, "heads", heads
,
3211 qemu_opt_set_number(hda_opts
, "secs", secs
,
3213 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3214 qemu_opt_set(hda_opts
, "trans", "large",
3216 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3217 qemu_opt_set(hda_opts
, "trans", "rechs",
3219 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3220 qemu_opt_set(hda_opts
, "trans", "lba",
3222 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3223 qemu_opt_set(hda_opts
, "trans", "none",
3229 case QEMU_OPTION_numa
:
3230 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3236 case QEMU_OPTION_display
:
3237 display_type
= select_display(optarg
);
3239 case QEMU_OPTION_nographic
:
3240 olist
= qemu_find_opts("machine");
3241 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3243 display_type
= DT_NONE
;
3245 case QEMU_OPTION_curses
:
3246 #ifdef CONFIG_CURSES
3247 display_type
= DT_CURSES
;
3249 error_report("curses support is disabled");
3253 case QEMU_OPTION_portrait
:
3254 graphic_rotate
= 90;
3256 case QEMU_OPTION_rotate
:
3257 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3258 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3259 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3260 error_report("only 90, 180, 270 deg rotation is available");
3264 case QEMU_OPTION_kernel
:
3265 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3268 case QEMU_OPTION_initrd
:
3269 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3272 case QEMU_OPTION_append
:
3273 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3276 case QEMU_OPTION_dtb
:
3277 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3280 case QEMU_OPTION_cdrom
:
3281 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3283 case QEMU_OPTION_boot
:
3284 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3290 case QEMU_OPTION_fda
:
3291 case QEMU_OPTION_fdb
:
3292 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3295 case QEMU_OPTION_no_fd_bootchk
:
3298 case QEMU_OPTION_netdev
:
3300 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3304 case QEMU_OPTION_net
:
3306 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3310 #ifdef CONFIG_LIBISCSI
3311 case QEMU_OPTION_iscsi
:
3312 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3320 case QEMU_OPTION_tftp
:
3321 error_report("The -tftp option is deprecated. "
3322 "Please use '-netdev user,tftp=...' instead.");
3323 legacy_tftp_prefix
= optarg
;
3325 case QEMU_OPTION_bootp
:
3326 error_report("The -bootp option is deprecated. "
3327 "Please use '-netdev user,bootfile=...' instead.");
3328 legacy_bootp_filename
= optarg
;
3330 case QEMU_OPTION_redir
:
3331 error_report("The -redir option is deprecated. "
3332 "Please use '-netdev user,hostfwd=...' instead.");
3333 if (net_slirp_redir(optarg
) < 0)
3337 case QEMU_OPTION_bt
:
3338 add_device_config(DEV_BT
, optarg
);
3340 case QEMU_OPTION_audio_help
:
3344 case QEMU_OPTION_soundhw
:
3345 select_soundhw (optarg
);
3350 case QEMU_OPTION_version
:
3355 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3362 case QEMU_OPTION_tpmdev
:
3363 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3368 case QEMU_OPTION_mempath
:
3371 case QEMU_OPTION_mem_prealloc
:
3380 case QEMU_OPTION_DFILTER
:
3381 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3384 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3386 case QEMU_OPTION_gdb
:
3387 add_device_config(DEV_GDB
, optarg
);
3390 if (is_help_option(optarg
)) {
3391 list_data_dirs
= true;
3392 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3393 data_dir
[data_dir_idx
++] = optarg
;
3396 case QEMU_OPTION_bios
:
3397 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3400 case QEMU_OPTION_singlestep
:
3407 keyboard_layout
= optarg
;
3409 case QEMU_OPTION_localtime
:
3412 case QEMU_OPTION_vga
:
3421 w
= strtol(p
, (char **)&p
, 10);
3424 error_report("invalid resolution or depth");
3430 h
= strtol(p
, (char **)&p
, 10);
3435 depth
= strtol(p
, (char **)&p
, 10);
3436 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3437 depth
!= 24 && depth
!= 32)
3439 } else if (*p
== '\0') {
3440 depth
= graphic_depth
;
3447 graphic_depth
= depth
;
3450 case QEMU_OPTION_echr
:
3453 term_escape_char
= strtol(optarg
, &r
, 0);
3455 printf("Bad argument to echr\n");
3458 case QEMU_OPTION_monitor
:
3459 default_monitor
= 0;
3460 if (strncmp(optarg
, "none", 4)) {
3461 monitor_parse(optarg
, "readline", false);
3464 case QEMU_OPTION_qmp
:
3465 monitor_parse(optarg
, "control", false);
3466 default_monitor
= 0;
3468 case QEMU_OPTION_qmp_pretty
:
3469 monitor_parse(optarg
, "control", true);
3470 default_monitor
= 0;
3472 case QEMU_OPTION_mon
:
3473 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3478 default_monitor
= 0;
3480 case QEMU_OPTION_chardev
:
3481 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3487 case QEMU_OPTION_fsdev
:
3488 olist
= qemu_find_opts("fsdev");
3490 error_report("fsdev support is disabled");
3493 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3498 case QEMU_OPTION_virtfs
: {
3501 const char *writeout
, *sock_fd
, *socket
;
3503 olist
= qemu_find_opts("virtfs");
3505 error_report("virtfs support is disabled");
3508 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3513 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3514 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3515 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3518 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3519 qemu_opt_get(opts
, "mount_tag"),
3522 error_report("duplicate fsdev id: %s",
3523 qemu_opt_get(opts
, "mount_tag"));
3527 writeout
= qemu_opt_get(opts
, "writeout");
3529 #ifdef CONFIG_SYNC_FILE_RANGE
3530 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3532 error_report("writeout=immediate not supported "
3533 "on this platform");
3537 qemu_opt_set(fsdev
, "fsdriver",
3538 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3539 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3541 qemu_opt_set(fsdev
, "security_model",
3542 qemu_opt_get(opts
, "security_model"),
3544 socket
= qemu_opt_get(opts
, "socket");
3546 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3548 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3550 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3553 qemu_opt_set_bool(fsdev
, "readonly",
3554 qemu_opt_get_bool(opts
, "readonly", 0),
3556 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3558 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3559 qemu_opt_set(device
, "fsdev",
3560 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3561 qemu_opt_set(device
, "mount_tag",
3562 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3565 case QEMU_OPTION_virtfs_synth
: {
3569 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3572 error_report("duplicate option: %s", "virtfs_synth");
3575 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3577 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3579 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3580 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3581 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3584 case QEMU_OPTION_serial
:
3585 add_device_config(DEV_SERIAL
, optarg
);
3587 if (strncmp(optarg
, "mon:", 4) == 0) {
3588 default_monitor
= 0;
3591 case QEMU_OPTION_watchdog
:
3593 error_report("only one watchdog option may be given");
3598 case QEMU_OPTION_watchdog_action
:
3599 if (select_watchdog_action(optarg
) == -1) {
3600 error_report("unknown -watchdog-action parameter");
3604 case QEMU_OPTION_virtiocon
:
3605 add_device_config(DEV_VIRTCON
, optarg
);
3606 default_virtcon
= 0;
3607 if (strncmp(optarg
, "mon:", 4) == 0) {
3608 default_monitor
= 0;
3611 case QEMU_OPTION_parallel
:
3612 add_device_config(DEV_PARALLEL
, optarg
);
3613 default_parallel
= 0;
3614 if (strncmp(optarg
, "mon:", 4) == 0) {
3615 default_monitor
= 0;
3618 case QEMU_OPTION_debugcon
:
3619 add_device_config(DEV_DEBUGCON
, optarg
);
3621 case QEMU_OPTION_loadvm
:
3624 case QEMU_OPTION_full_screen
:
3627 case QEMU_OPTION_no_frame
:
3630 case QEMU_OPTION_alt_grab
:
3633 case QEMU_OPTION_ctrl_grab
:
3636 case QEMU_OPTION_no_quit
:
3639 case QEMU_OPTION_sdl
:
3641 display_type
= DT_SDL
;
3644 error_report("SDL support is disabled");
3647 case QEMU_OPTION_pidfile
:
3650 case QEMU_OPTION_win2k_hack
:
3651 win2k_install_hack
= 1;
3653 case QEMU_OPTION_rtc_td_hack
: {
3654 static GlobalProperty slew_lost_ticks
= {
3655 .driver
= "mc146818rtc",
3656 .property
= "lost_tick_policy",
3660 qdev_prop_register_global(&slew_lost_ticks
);
3663 case QEMU_OPTION_acpitable
:
3664 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3669 do_acpitable_option(opts
);
3671 case QEMU_OPTION_smbios
:
3672 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3677 do_smbios_option(opts
);
3679 case QEMU_OPTION_fwcfg
:
3680 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3686 case QEMU_OPTION_enable_kvm
:
3687 olist
= qemu_find_opts("machine");
3688 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3691 case QEMU_OPTION_machine
:
3692 olist
= qemu_find_opts("machine");
3693 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3698 case QEMU_OPTION_no_kvm
:
3699 olist
= qemu_find_opts("machine");
3700 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3702 case QEMU_OPTION_no_kvm_pit
: {
3703 error_report("warning: ignoring deprecated option");
3706 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3707 static GlobalProperty kvm_pit_lost_tick_policy
= {
3708 .driver
= "kvm-pit",
3709 .property
= "lost_tick_policy",
3713 error_report("warning: deprecated, replaced by "
3714 "-global kvm-pit.lost_tick_policy=discard");
3715 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3718 case QEMU_OPTION_usb
:
3719 olist
= qemu_find_opts("machine");
3720 qemu_opts_parse_noisily(olist
, "usb=on", false);
3722 case QEMU_OPTION_usbdevice
:
3723 olist
= qemu_find_opts("machine");
3724 qemu_opts_parse_noisily(olist
, "usb=on", false);
3725 add_device_config(DEV_USB
, optarg
);
3727 case QEMU_OPTION_device
:
3728 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3733 case QEMU_OPTION_smp
:
3734 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3739 case QEMU_OPTION_vnc
:
3740 vnc_parse(optarg
, &error_fatal
);
3742 case QEMU_OPTION_no_acpi
:
3745 case QEMU_OPTION_no_hpet
:
3748 case QEMU_OPTION_balloon
:
3749 if (balloon_parse(optarg
) < 0) {
3750 error_report("unknown -balloon argument %s", optarg
);
3754 case QEMU_OPTION_no_reboot
:
3757 case QEMU_OPTION_no_shutdown
:
3760 case QEMU_OPTION_show_cursor
:
3763 case QEMU_OPTION_uuid
:
3764 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
3765 error_report("failed to parse UUID string: wrong format");
3768 qemu_uuid_set
= true;
3770 case QEMU_OPTION_option_rom
:
3771 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3772 error_report("too many option ROMs");
3775 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3780 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3781 option_rom
[nb_option_roms
].bootindex
=
3782 qemu_opt_get_number(opts
, "bootindex", -1);
3783 if (!option_rom
[nb_option_roms
].name
) {
3784 error_report("Option ROM file is not specified");
3789 case QEMU_OPTION_semihosting
:
3790 semihosting
.enabled
= true;
3791 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3793 case QEMU_OPTION_semihosting_config
:
3794 semihosting
.enabled
= true;
3795 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3798 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3800 const char *target
= qemu_opt_get(opts
, "target");
3801 if (target
!= NULL
) {
3802 if (strcmp("native", target
) == 0) {
3803 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3804 } else if (strcmp("gdb", target
) == 0) {
3805 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3806 } else if (strcmp("auto", target
) == 0) {
3807 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3809 error_report("unsupported semihosting-config %s",
3814 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3816 /* Set semihosting argument count and vector */
3817 qemu_opt_foreach(opts
, add_semihosting_arg
,
3818 &semihosting
, NULL
);
3820 error_report("unsupported semihosting-config %s", optarg
);
3824 case QEMU_OPTION_tdf
:
3825 error_report("warning: ignoring deprecated option");
3827 case QEMU_OPTION_name
:
3828 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3834 case QEMU_OPTION_prom_env
:
3835 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3836 error_report("too many prom variables");
3839 prom_envs
[nb_prom_envs
] = optarg
;
3842 case QEMU_OPTION_old_param
:
3845 case QEMU_OPTION_clock
:
3846 /* Clock options no longer exist. Keep this option for
3847 * backward compatibility.
3850 case QEMU_OPTION_startdate
:
3851 configure_rtc_date_offset(optarg
, 1);
3853 case QEMU_OPTION_rtc
:
3854 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3859 configure_rtc(opts
);
3861 case QEMU_OPTION_tb_size
:
3862 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3863 if (tcg_tb_size
< 0) {
3867 case QEMU_OPTION_icount
:
3868 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3874 case QEMU_OPTION_incoming
:
3876 runstate_set(RUN_STATE_INMIGRATE
);
3880 case QEMU_OPTION_nodefaults
:
3883 case QEMU_OPTION_xen_domid
:
3884 if (!(xen_available())) {
3885 error_report("Option not supported for this target");
3888 xen_domid
= atoi(optarg
);
3890 case QEMU_OPTION_xen_create
:
3891 if (!(xen_available())) {
3892 error_report("Option not supported for this target");
3895 xen_mode
= XEN_CREATE
;
3897 case QEMU_OPTION_xen_attach
:
3898 if (!(xen_available())) {
3899 error_report("Option not supported for this target");
3902 xen_mode
= XEN_ATTACH
;
3904 case QEMU_OPTION_trace
:
3906 trace_file
= trace_opt_parse(optarg
);
3908 case QEMU_OPTION_trace_unassigned
:
3909 trace_unassigned
= true;
3911 case QEMU_OPTION_readconfig
:
3913 int ret
= qemu_read_config_file(optarg
);
3915 error_report("read config %s: %s", optarg
,
3921 case QEMU_OPTION_spice
:
3922 olist
= qemu_find_opts("spice");
3924 error_report("spice support is disabled");
3927 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3933 case QEMU_OPTION_writeconfig
:
3936 if (strcmp(optarg
, "-") == 0) {
3939 fp
= fopen(optarg
, "w");
3941 error_report("open %s: %s", optarg
,
3946 qemu_config_write(fp
);
3952 case QEMU_OPTION_qtest
:
3953 qtest_chrdev
= optarg
;
3955 case QEMU_OPTION_qtest_log
:
3958 case QEMU_OPTION_sandbox
:
3959 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
3965 case QEMU_OPTION_add_fd
:
3967 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3973 error_report("File descriptor passing is disabled on this "
3978 case QEMU_OPTION_object
:
3979 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
3985 case QEMU_OPTION_realtime
:
3986 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
3991 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
3993 case QEMU_OPTION_msg
:
3994 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3999 configure_msg(opts
);
4001 case QEMU_OPTION_dump_vmstate
:
4002 if (vmstate_dump_file
) {
4003 error_report("only one '-dump-vmstate' "
4004 "option may be given");
4007 vmstate_dump_file
= fopen(optarg
, "w");
4008 if (vmstate_dump_file
== NULL
) {
4009 error_report("open %s: %s", optarg
, strerror(errno
));
4014 os_parse_cmd_args(popt
->index
, optarg
);
4019 * Clear error location left behind by the loop.
4020 * Best done right after the loop. Do not insert code here!
4024 replay_configure(icount_opts
);
4026 machine_class
= select_machine();
4028 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4032 if (qemu_init_main_loop(&main_loop_err
)) {
4033 error_report_err(main_loop_err
);
4037 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4038 parse_sandbox
, NULL
, NULL
)) {
4042 if (qemu_opts_foreach(qemu_find_opts("name"),
4043 parse_name
, NULL
, NULL
)) {
4048 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4049 parse_add_fd
, NULL
, NULL
)) {
4053 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4054 cleanup_add_fd
, NULL
, NULL
)) {
4059 current_machine
= MACHINE(object_new(object_class_get_name(
4060 OBJECT_CLASS(machine_class
))));
4061 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4064 object_property_add_child(object_get_root(), "machine",
4065 OBJECT(current_machine
), &error_abort
);
4066 cpu_exec_init_all();
4068 if (machine_class
->hw_version
) {
4069 qemu_set_hw_version(machine_class
->hw_version
);
4072 if (cpu_model
&& is_help_option(cpu_model
)) {
4073 list_cpus(stdout
, &fprintf
, cpu_model
);
4077 if (!trace_init_backends()) {
4080 trace_init_file(trace_file
);
4082 /* Open the logfile at this point and set the log mask if necessary.
4085 qemu_set_log_filename(log_file
, &error_fatal
);
4090 mask
= qemu_str_to_log_mask(log_mask
);
4092 qemu_print_log_usage(stdout
);
4100 /* If no data_dir is specified then try to find it relative to the
4102 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4103 data_dir
[data_dir_idx
] = os_find_datadir();
4104 if (data_dir
[data_dir_idx
] != NULL
) {
4108 /* If all else fails use the install path specified when building. */
4109 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4110 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4113 /* -L help lists the data directories and exits. */
4114 if (list_data_dirs
) {
4115 for (i
= 0; i
< data_dir_idx
; i
++) {
4116 printf("%s\n", data_dir
[i
]);
4121 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4123 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4124 if (max_cpus
> machine_class
->max_cpus
) {
4125 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4126 "supported by machine '%s' (%d)", max_cpus
,
4127 machine_class
->name
, machine_class
->max_cpus
);
4132 * Get the default machine options from the machine if it is not already
4133 * specified either by the configuration file or by the command line.
4135 if (machine_class
->default_machine_opts
) {
4136 qemu_opts_set_defaults(qemu_find_opts("machine"),
4137 machine_class
->default_machine_opts
, 0);
4140 qemu_opts_foreach(qemu_find_opts("device"),
4141 default_driver_check
, NULL
, NULL
);
4142 qemu_opts_foreach(qemu_find_opts("global"),
4143 default_driver_check
, NULL
, NULL
);
4145 if (!vga_model
&& !default_vga
) {
4146 vga_interface_type
= VGA_DEVICE
;
4148 if (!has_defaults
|| machine_class
->no_serial
) {
4151 if (!has_defaults
|| machine_class
->no_parallel
) {
4152 default_parallel
= 0;
4154 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4155 default_virtcon
= 0;
4157 if (!has_defaults
|| !machine_class
->use_sclp
) {
4160 if (!has_defaults
|| machine_class
->no_floppy
) {
4163 if (!has_defaults
|| machine_class
->no_cdrom
) {
4166 if (!has_defaults
|| machine_class
->no_sdcard
) {
4169 if (!has_defaults
) {
4170 default_monitor
= 0;
4175 if (is_daemonized()) {
4176 /* According to documentation and historically, -nographic redirects
4177 * serial port, parallel port and monitor to stdio, which does not work
4178 * with -daemonize. We can redirect these to null instead, but since
4179 * -nographic is legacy, let's just error out.
4180 * We disallow -nographic only if all other ports are not redirected
4181 * explicitly, to not break existing legacy setups which uses
4182 * -nographic _and_ redirects all ports explicitly - this is valid
4183 * usage, -nographic is just a no-op in this case.
4186 && (default_parallel
|| default_serial
4187 || default_monitor
|| default_virtcon
)) {
4188 error_report("-nographic cannot be used with -daemonize");
4191 #ifdef CONFIG_CURSES
4192 if (display_type
== DT_CURSES
) {
4193 error_report("curses display cannot be used with -daemonize");
4200 if (default_parallel
)
4201 add_device_config(DEV_PARALLEL
, "null");
4202 if (default_serial
&& default_monitor
) {
4203 add_device_config(DEV_SERIAL
, "mon:stdio");
4204 } else if (default_virtcon
&& default_monitor
) {
4205 add_device_config(DEV_VIRTCON
, "mon:stdio");
4206 } else if (default_sclp
&& default_monitor
) {
4207 add_device_config(DEV_SCLP
, "mon:stdio");
4210 add_device_config(DEV_SERIAL
, "stdio");
4211 if (default_virtcon
)
4212 add_device_config(DEV_VIRTCON
, "stdio");
4214 add_device_config(DEV_SCLP
, "stdio");
4216 if (default_monitor
)
4217 monitor_parse("stdio", "readline", false);
4221 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4222 if (default_parallel
)
4223 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4224 if (default_monitor
)
4225 monitor_parse("vc:80Cx24C", "readline", false);
4226 if (default_virtcon
)
4227 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4229 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4233 #if defined(CONFIG_VNC)
4234 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4238 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4239 #if defined(CONFIG_GTK)
4240 display_type
= DT_GTK
;
4241 #elif defined(CONFIG_SDL)
4242 display_type
= DT_SDL
;
4243 #elif defined(CONFIG_COCOA)
4244 display_type
= DT_COCOA
;
4245 #elif defined(CONFIG_VNC)
4246 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4248 display_type
= DT_NONE
;
4252 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4253 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4254 "for SDL, ignoring option");
4256 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4257 error_report("-no-quit is only valid for GTK and SDL, "
4261 if (display_type
== DT_GTK
) {
4262 early_gtk_display_init(request_opengl
);
4265 if (display_type
== DT_SDL
) {
4266 sdl_display_early_init(request_opengl
);
4269 if (request_opengl
== 1 && display_opengl
== 0) {
4270 #if defined(CONFIG_OPENGL)
4271 error_report("OpenGL is not supported by the display");
4273 error_report("OpenGL support is disabled");
4281 if (qemu_opts_foreach(qemu_find_opts("object"),
4282 user_creatable_add_opts_foreach
,
4283 object_create_initial
, NULL
)) {
4287 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4288 chardev_init_func
, NULL
, NULL
)) {
4292 #ifdef CONFIG_VIRTFS
4293 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4294 fsdev_init_func
, NULL
, NULL
)) {
4299 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4300 error_report("could not acquire pid file: %s", strerror(errno
));
4304 if (qemu_opts_foreach(qemu_find_opts("device"),
4305 device_help_func
, NULL
, NULL
)) {
4309 machine_opts
= qemu_get_machine_opts();
4310 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4312 object_unref(OBJECT(current_machine
));
4316 configure_accelerator(current_machine
);
4319 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4322 machine_opts
= qemu_get_machine_opts();
4323 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4324 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4325 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4326 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4328 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4330 boot_order
= qemu_opt_get(opts
, "order");
4332 validate_bootdevices(boot_order
, &error_fatal
);
4335 boot_once
= qemu_opt_get(opts
, "once");
4337 validate_bootdevices(boot_once
, &error_fatal
);
4340 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4341 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4345 boot_order
= machine_class
->default_boot_order
;
4348 if (!kernel_cmdline
) {
4349 kernel_cmdline
= "";
4350 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4353 linux_boot
= (kernel_filename
!= NULL
);
4355 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4356 error_report("-append only allowed with -kernel option");
4360 if (!linux_boot
&& initrd_filename
!= NULL
) {
4361 error_report("-initrd only allowed with -kernel option");
4365 if (!linux_boot
&& qemu_opt_get(machine_opts
, "dtb")) {
4366 error_report("-dtb only allowed with -kernel option");
4370 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4371 /* fall back to the -kernel/-append */
4372 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4375 os_set_line_buffering();
4377 /* spice needs the timers to be initialized by this point */
4382 if (kvm_enabled() || xen_enabled()) {
4383 error_report("-icount is not allowed with kvm or xen");
4386 configure_icount(icount_opts
, &error_abort
);
4387 qemu_opts_del(icount_opts
);
4391 QemuOptsList
*net
= qemu_find_opts("net");
4392 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4394 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4398 if (net_init_clients() < 0) {
4402 if (qemu_opts_foreach(qemu_find_opts("object"),
4403 user_creatable_add_opts_foreach
,
4404 object_create_delayed
, NULL
)) {
4409 if (tpm_init() < 0) {
4414 /* init the bluetooth world */
4415 if (foreach_device_config(DEV_BT
, bt_parse
))
4418 if (!xen_enabled()) {
4419 /* On 32-bit hosts, QEMU is limited by virtual address space */
4420 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4421 error_report("at most 2047 MB RAM can be simulated");
4429 /* If the currently selected machine wishes to override the units-per-bus
4430 * property of its default HBA interface type, do so now. */
4431 if (machine_class
->units_per_default_bus
) {
4432 override_max_devs(machine_class
->block_default_type
,
4433 machine_class
->units_per_default_bus
);
4436 /* open the virtual block devices */
4437 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4438 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4441 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4442 &machine_class
->block_default_type
, NULL
)) {
4446 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4448 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4449 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4451 parse_numa_opts(machine_class
);
4453 if (qemu_opts_foreach(qemu_find_opts("mon"),
4454 mon_init_func
, NULL
, NULL
)) {
4458 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4460 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4462 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4464 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4467 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4470 /* If no default VGA is requested, the default is "none". */
4472 if (machine_class
->default_display
) {
4473 vga_model
= machine_class
->default_display
;
4474 } else if (vga_interface_available(VGA_CIRRUS
)) {
4475 vga_model
= "cirrus";
4476 } else if (vga_interface_available(VGA_STD
)) {
4481 select_vgahw(vga_model
);
4485 i
= select_watchdog(watchdog
);
4487 exit (i
== 1 ? 1 : 0);
4490 machine_register_compat_props(current_machine
);
4492 qemu_opts_foreach(qemu_find_opts("global"),
4493 global_init_func
, NULL
, NULL
);
4495 /* This checkpoint is required by replay to separate prior clock
4496 reading from the other reads, because timer polling functions query
4497 clock values from the log. */
4498 replay_checkpoint(CHECKPOINT_INIT
);
4499 qdev_machine_init();
4501 current_machine
->ram_size
= ram_size
;
4502 current_machine
->maxram_size
= maxram_size
;
4503 current_machine
->ram_slots
= ram_slots
;
4504 current_machine
->boot_order
= boot_order
;
4505 current_machine
->cpu_model
= cpu_model
;
4507 machine_class
->init(current_machine
);
4513 cpu_synchronize_all_post_init();
4515 numa_post_machine_init();
4517 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4518 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4522 /* init USB devices */
4523 if (machine_usb(current_machine
)) {
4524 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4528 /* Check if IGD GFX passthrough. */
4531 /* init generic devices */
4532 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4533 if (qemu_opts_foreach(qemu_find_opts("device"),
4534 device_init_func
, NULL
, NULL
)) {
4537 rom_reset_order_override();
4539 /* Did we create any drives that we failed to create a device for? */
4540 drive_check_orphaned();
4542 /* Don't warn about the default network setup that you get if
4543 * no command line -net or -netdev options are specified. There
4544 * are two cases that we would otherwise complain about:
4545 * (1) board doesn't support a NIC but the implicit "-net nic"
4547 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4548 * sets up a nic that isn't connected to anything.
4551 net_check_clients();
4556 qemu_boot_set(boot_once
, &error_fatal
);
4557 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4560 ds
= init_displaystate();
4562 /* init local displays */
4563 switch (display_type
) {
4565 curses_display_init(ds
, full_screen
);
4568 sdl_display_init(ds
, full_screen
, no_frame
);
4571 cocoa_display_init(ds
, full_screen
);
4574 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4580 /* must be after terminal init, SDL library changes signal handlers */
4581 os_setup_signal_handling();
4583 /* init remote displays */
4585 qemu_opts_foreach(qemu_find_opts("vnc"),
4586 vnc_init_func
, NULL
, NULL
);
4590 qemu_spice_display_init();
4593 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4597 qdev_machine_creation_done();
4599 /* TODO: once all bus devices are qdevified, this should be done
4600 * when bus is created by qdev.c */
4601 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4602 qemu_run_machine_init_done_notifiers();
4604 if (rom_check_and_register_reset() != 0) {
4605 error_report("rom check and register reset failed");
4611 /* This checkpoint is required by replay to separate prior clock
4612 reading from the other reads, because timer polling functions query
4613 clock values from the log. */
4614 replay_checkpoint(CHECKPOINT_RESET
);
4615 qemu_system_reset(VMRESET_SILENT
);
4616 register_global_state();
4618 if (load_vmstate(loadvm
) < 0) {
4623 qdev_prop_check_globals();
4624 if (vmstate_dump_file
) {
4626 dump_vmstate_json_to_file(vmstate_dump_file
);
4631 Error
*local_err
= NULL
;
4632 qemu_start_incoming_migration(incoming
, &local_err
);
4634 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4637 } else if (autostart
) {
4643 trace_init_vcpu_events();
4645 replay_disable_events();
4654 /* vhost-user must be cleaned up before chardevs. */