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
31 #include "config-host.h"
34 #include "sysemu/seccomp.h"
37 #if defined(CONFIG_VDE)
38 #include <libvdeplug.h>
42 #if defined(__APPLE__) || defined(main)
45 int qemu_main(int argc, char **argv, char **envp);
46 int main(int argc, char **argv)
48 return qemu_main(argc, argv, NULL);
51 #define main qemu_main
54 #endif /* CONFIG_SDL */
58 #define main qemu_main
59 #endif /* CONFIG_COCOA */
65 int qemu_main(int argc, char **argv, char **envp);
66 #define main qemu_main
71 #include "qemu/sockets.h"
73 #include "hw/boards.h"
74 #include "sysemu/accel.h"
76 #include "hw/i386/pc.h"
77 #include "hw/isa/isa.h"
79 #include "sysemu/watchdog.h"
80 #include "hw/i386/smbios.h"
81 #include "hw/xen/xen.h"
83 #include "hw/loader.h"
84 #include "monitor/qdev.h"
85 #include "sysemu/bt.h"
87 #include "net/slirp.h"
88 #include "monitor/monitor.h"
89 #include "ui/console.h"
90 #include "sysemu/sysemu.h"
91 #include "exec/gdbstub.h"
92 #include "qemu/timer.h"
93 #include "sysemu/char.h"
94 #include "qemu/bitmap.h"
95 #include "sysemu/blockdev.h"
96 #include "hw/block/block.h"
97 #include "migration/block.h"
98 #include "sysemu/tpm.h"
99 #include "sysemu/dma.h"
100 #include "audio/audio.h"
101 #include "migration/migration.h"
102 #include "sysemu/kvm.h"
103 #include "sysemu/hax.h"
104 #include "qapi/qmp/qjson.h"
105 #include "qemu/option.h"
106 #include "qemu/config-file.h"
107 #include "qemu-options.h"
108 #include "qmp-commands.h"
109 #include "qemu/main-loop.h"
111 #include "fsdev/qemu-fsdev.h"
113 #include "sysemu/qtest.h"
115 #include "disas/disas.h"
118 #include "slirp/libslirp.h"
121 #include "trace/control.h"
122 #include "qemu/queue.h"
123 #include "sysemu/cpus.h"
124 #include "sysemu/arch_init.h"
125 #include "qemu/osdep.h"
127 #include "ui/qemu-spice.h"
128 #include "qapi/string-input-visitor.h"
129 #include "qapi/opts-visitor.h"
130 #include "qom/object_interfaces.h"
131 #include "qapi-event.h"
134 #include "tizen/src/emulator.h"
135 #include "tizen/src/util/maru_err_table.h"
136 #include "tizen/src/emul_state.h"
137 #include "tizen/src/display/maru_display.h"
138 #include "tizen/src/skin/maruskin_operation.h"
139 #include "tizen/src/ecs/ecs.h"
142 #define DEFAULT_RAM_SIZE 128
144 #define MAX_VIRTIO_CONSOLES 1
145 #define MAX_SCLP_CONSOLES 1
148 static int enable_yagl = 0;
149 static const char *yagl_backend = NULL;
151 bool yagl_enabled(void); /* prototype to make gcc happy */
152 bool yagl_enabled(void)
156 #endif /* CONFIG_YAGL */
159 static int enable_vigs = 0;
160 static char *vigs_backend = NULL;
161 #endif /* CONFIG_VIGS */
164 int skin_disabled = 0;
165 extern int enable_spice;
166 #if defined(CONFIG_SPICE) && defined(CONFIG_LINUX)
167 extern void websocket_init(void);
168 extern void nodejs_init(void);
169 extern void spice_pkg_install(void);
173 static const char *data_dir[16];
174 static int data_dir_idx;
175 const char *bios_name = NULL;
176 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
177 DisplayType display_type = DT_DEFAULT;
178 static int display_remote;
179 const char* keyboard_layout = NULL;
181 const char *mem_path = NULL;
182 int mem_prealloc = 0; /* force preallocation of physical target memory */
183 bool enable_mlock = false;
185 NICInfo nd_table[MAX_NICS];
187 static int rtc_utc = 1;
188 static int rtc_date_offset = -1; /* -1 means no change */
189 QEMUClockType rtc_clock;
190 int vga_interface_type = VGA_NONE;
191 static int full_screen = 0;
192 static int no_frame = 0;
195 static bool grab_on_hover;
197 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
198 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
199 CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
200 CharDriverState *sclp_hds[MAX_SCLP_CONSOLES];
201 int win2k_install_hack = 0;
208 const char *vnc_display;
210 int acpi_enabled = 1;
213 static int no_reboot;
216 int graphic_rotate = 0;
217 const char *watchdog;
218 QEMUOptionRom option_rom[MAX_OPTION_ROMS];
220 int semihosting_enabled = 0;
222 const char *qemu_name;
225 unsigned int nb_prom_envs = 0;
226 const char *prom_envs[MAX_PROM_ENVS];
229 uint8_t *boot_splash_filedata;
230 size_t boot_splash_filedata_size;
231 uint8_t qemu_extra_params_fw[2];
233 int icount_align_option;
237 NodeInfo numa_info[MAX_NODES];
239 /* The bytes in qemu_uuid[] are in the order specified by RFC4122, _not_ in the
240 * little-endian "wire format" described in the SMBIOS 2.6 specification.
242 uint8_t qemu_uuid[16];
245 static QEMUBootSetHandler *boot_set_handler;
246 static void *boot_set_opaque;
248 static NotifierList exit_notifiers =
249 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
251 static NotifierList machine_init_done_notifiers =
252 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
256 enum xen_mode xen_mode = XEN_EMULATE;
258 static int has_defaults = 1;
259 static int default_serial = 1;
260 static int default_parallel = 1;
261 static int default_virtcon = 1;
262 static int default_sclp = 1;
263 static int default_monitor = 1;
264 static int default_floppy = 1;
265 static int default_cdrom = 1;
266 static int default_sdcard = 1;
267 static int default_vga = 1;
273 { .driver = "isa-serial", .flag = &default_serial },
274 { .driver = "isa-parallel", .flag = &default_parallel },
275 { .driver = "isa-fdc", .flag = &default_floppy },
276 { .driver = "ide-cd", .flag = &default_cdrom },
277 { .driver = "ide-hd", .flag = &default_cdrom },
278 { .driver = "ide-drive", .flag = &default_cdrom },
279 { .driver = "scsi-cd", .flag = &default_cdrom },
280 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
281 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
282 { .driver = "virtio-serial", .flag = &default_virtcon },
283 { .driver = "VGA", .flag = &default_vga },
284 { .driver = "isa-vga", .flag = &default_vga },
285 { .driver = "cirrus-vga", .flag = &default_vga },
286 { .driver = "isa-cirrus-vga", .flag = &default_vga },
287 { .driver = "vmware-svga", .flag = &default_vga },
288 { .driver = "qxl-vga", .flag = &default_vga },
291 static QemuOptsList qemu_rtc_opts = {
293 .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head),
297 .type = QEMU_OPT_STRING,
300 .type = QEMU_OPT_STRING,
303 .type = QEMU_OPT_STRING,
305 { /* end of list */ }
309 static QemuOptsList qemu_sandbox_opts = {
311 .implied_opt_name = "enable",
312 .head = QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts.head),
316 .type = QEMU_OPT_BOOL,
318 { /* end of list */ }
322 static QemuOptsList qemu_trace_opts = {
324 .implied_opt_name = "trace",
325 .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
329 .type = QEMU_OPT_STRING,
332 .type = QEMU_OPT_STRING,
334 { /* end of list */ }
338 static QemuOptsList qemu_option_rom_opts = {
339 .name = "option-rom",
340 .implied_opt_name = "romfile",
341 .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head),
345 .type = QEMU_OPT_NUMBER,
348 .type = QEMU_OPT_STRING,
350 { /* end of list */ }
354 static QemuOptsList qemu_machine_opts = {
356 .implied_opt_name = "type",
358 .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
362 .type = QEMU_OPT_STRING,
363 .help = "emulated machine"
366 .type = QEMU_OPT_STRING,
367 .help = "accelerator list",
369 .name = "kernel_irqchip",
370 .type = QEMU_OPT_BOOL,
371 .help = "use KVM in-kernel irqchip",
373 .name = "kvm_shadow_mem",
374 .type = QEMU_OPT_SIZE,
375 .help = "KVM shadow MMU size",
378 .type = QEMU_OPT_STRING,
379 .help = "Linux kernel image file",
382 .type = QEMU_OPT_STRING,
383 .help = "Linux initial ramdisk file",
386 .type = QEMU_OPT_STRING,
387 .help = "Linux kernel command line",
390 .type = QEMU_OPT_STRING,
391 .help = "Linux kernel device tree file",
394 .type = QEMU_OPT_STRING,
395 .help = "Dump current dtb to a file and quit",
397 .name = "phandle_start",
398 .type = QEMU_OPT_NUMBER,
399 .help = "The first phandle ID we may generate dynamically",
401 .name = "dt_compatible",
402 .type = QEMU_OPT_STRING,
403 .help = "Overrides the \"compatible\" property of the dt root node",
405 .name = "dump-guest-core",
406 .type = QEMU_OPT_BOOL,
407 .help = "Include guest memory in a core dump",
410 .type = QEMU_OPT_BOOL,
411 .help = "enable/disable memory merge support",
414 .type = QEMU_OPT_BOOL,
415 .help = "Set on/off to enable/disable usb",
418 .type = QEMU_OPT_STRING,
419 .help = "firmware image",
422 .type = QEMU_OPT_STRING,
423 .help = "Specifies the KVM virtualization mode (HV, PR)",
425 .name = PC_MACHINE_MAX_RAM_BELOW_4G,
426 .type = QEMU_OPT_SIZE,
427 .help = "maximum ram below the 4G boundary (32bit boundary)",
429 .name = PC_MACHINE_VMPORT,
430 .type = QEMU_OPT_STRING,
431 .help = "Enable vmport (pc & q35)",
434 .type = QEMU_OPT_BOOL,
435 .help = "Set on/off to enable/disable Intel IOMMU (VT-d)",
437 { /* End of list */ }
441 static QemuOptsList qemu_boot_opts = {
443 .implied_opt_name = "order",
445 .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head),
449 .type = QEMU_OPT_STRING,
452 .type = QEMU_OPT_STRING,
455 .type = QEMU_OPT_BOOL,
458 .type = QEMU_OPT_STRING,
460 .name = "splash-time",
461 .type = QEMU_OPT_STRING,
463 .name = "reboot-timeout",
464 .type = QEMU_OPT_STRING,
467 .type = QEMU_OPT_BOOL,
473 static QemuOptsList qemu_add_fd_opts = {
475 .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head),
479 .type = QEMU_OPT_NUMBER,
480 .help = "file descriptor of which a duplicate is added to fd set",
483 .type = QEMU_OPT_NUMBER,
484 .help = "ID of the fd set to add fd to",
487 .type = QEMU_OPT_STRING,
488 .help = "free-form string used to describe fd",
490 { /* end of list */ }
494 static QemuOptsList qemu_object_opts = {
496 .implied_opt_name = "qom-type",
497 .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
503 static QemuOptsList qemu_tpmdev_opts = {
505 .implied_opt_name = "type",
506 .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head),
508 /* options are defined in the TPM backends */
509 { /* end of list */ }
513 static QemuOptsList qemu_realtime_opts = {
515 .head = QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts.head),
519 .type = QEMU_OPT_BOOL,
521 { /* end of list */ }
525 static QemuOptsList qemu_msg_opts = {
527 .head = QTAILQ_HEAD_INITIALIZER(qemu_msg_opts.head),
531 .type = QEMU_OPT_BOOL,
533 { /* end of list */ }
537 static QemuOptsList qemu_name_opts = {
539 .implied_opt_name = "guest",
541 .head = QTAILQ_HEAD_INITIALIZER(qemu_name_opts.head),
545 .type = QEMU_OPT_STRING,
546 .help = "Sets the name of the guest.\n"
547 "This name will be displayed in the SDL window caption.\n"
548 "The name will also be used for the VNC server",
551 .type = QEMU_OPT_STRING,
552 .help = "Sets the name of the QEMU process, as shown in top etc",
554 .name = "debug-threads",
555 .type = QEMU_OPT_BOOL,
556 .help = "When enabled, name the individual threads; defaults off.\n"
557 "NOTE: The thread names are for debugging and not a\n"
560 { /* End of list */ }
564 static QemuOptsList qemu_mem_opts = {
566 .implied_opt_name = "size",
567 .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head),
572 .type = QEMU_OPT_SIZE,
576 .type = QEMU_OPT_NUMBER,
580 .type = QEMU_OPT_SIZE,
582 { /* end of list */ }
586 static QemuOptsList qemu_icount_opts = {
588 .implied_opt_name = "shift",
590 .head = QTAILQ_HEAD_INITIALIZER(qemu_icount_opts.head),
594 .type = QEMU_OPT_STRING,
597 .type = QEMU_OPT_BOOL,
599 { /* end of list */ }
604 * Get machine options
606 * Returns: machine options (never null).
608 QemuOpts *qemu_get_machine_opts(void)
610 return qemu_find_opts_singleton("machine");
613 const char *qemu_get_vm_name(void)
618 static void res_free(void)
620 if (boot_splash_filedata != NULL) {
621 g_free(boot_splash_filedata);
622 boot_splash_filedata = NULL;
626 static int default_driver_check(QemuOpts *opts, void *opaque)
628 const char *driver = qemu_opt_get(opts, "driver");
633 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
634 if (strcmp(default_list[i].driver, driver) != 0)
636 *(default_list[i].flag) = 0;
641 /***********************************************************/
644 static RunState current_run_state = RUN_STATE_PRELAUNCH;
646 /* We use RUN_STATE_MAX but any invalid value will do */
647 static RunState vmstop_requested = RUN_STATE_MAX;
648 static QemuMutex vmstop_lock;
653 } RunStateTransition;
655 static const RunStateTransition runstate_transitions_def[] = {
657 { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
658 { RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE },
660 { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },
661 { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED },
663 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
664 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
666 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
667 { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE },
669 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
670 { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
672 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
673 { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
675 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
676 { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
677 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
679 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
680 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
682 { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
684 { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
685 { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
686 { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
687 { RUN_STATE_RUNNING, RUN_STATE_PAUSED },
688 { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE },
689 { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM },
690 { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM },
691 { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
692 { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
693 { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED },
695 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
697 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
698 { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
700 { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
701 { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
702 { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },
703 { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
705 { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
706 { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
708 { RUN_STATE_GUEST_PANICKED, RUN_STATE_RUNNING },
709 { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE },
711 { RUN_STATE_MAX, RUN_STATE_MAX },
714 static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX];
716 bool runstate_check(RunState state)
718 return current_run_state == state;
721 static void runstate_init(void)
723 const RunStateTransition *p;
725 memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions));
726 for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) {
727 runstate_valid_transitions[p->from][p->to] = true;
730 qemu_mutex_init(&vmstop_lock);
733 /* This function will abort() on invalid state transitions */
734 void runstate_set(RunState new_state)
736 assert(new_state < RUN_STATE_MAX);
738 if (!runstate_valid_transitions[current_run_state][new_state]) {
739 fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
740 RunState_lookup[current_run_state],
741 RunState_lookup[new_state]);
744 trace_runstate_set(new_state);
745 current_run_state = new_state;
748 int runstate_is_running(void)
750 return runstate_check(RUN_STATE_RUNNING);
753 bool runstate_needs_reset(void)
755 return runstate_check(RUN_STATE_INTERNAL_ERROR) ||
756 runstate_check(RUN_STATE_SHUTDOWN);
759 StatusInfo *qmp_query_status(Error **errp)
761 StatusInfo *info = g_malloc0(sizeof(*info));
763 info->running = runstate_is_running();
764 info->singlestep = singlestep;
765 info->status = current_run_state;
770 static bool qemu_vmstop_requested(RunState *r)
772 qemu_mutex_lock(&vmstop_lock);
773 *r = vmstop_requested;
774 vmstop_requested = RUN_STATE_MAX;
775 qemu_mutex_unlock(&vmstop_lock);
776 return *r < RUN_STATE_MAX;
779 void qemu_system_vmstop_request_prepare(void)
781 qemu_mutex_lock(&vmstop_lock);
784 void qemu_system_vmstop_request(RunState state)
786 vmstop_requested = state;
787 qemu_mutex_unlock(&vmstop_lock);
795 qemu_vmstop_requested(&requested);
796 if (runstate_is_running() && requested == RUN_STATE_MAX) {
800 /* Ensure that a STOP/RESUME pair of events is emitted if a
801 * vmstop request was pending. The BLOCK_IO_ERROR event, for
802 * example, according to documentation is always followed by
805 if (runstate_is_running()) {
806 qapi_event_send_stop(&error_abort);
809 runstate_set(RUN_STATE_RUNNING);
810 vm_state_notify(1, RUN_STATE_RUNNING);
814 qapi_event_send_resume(&error_abort);
818 /***********************************************************/
819 /* real time host monotonic timer */
821 /***********************************************************/
822 /* host time/date access */
823 void qemu_get_timedate(struct tm *tm, int offset)
829 if (rtc_date_offset == -1) {
833 localtime_r(&ti, tm);
835 ti -= rtc_date_offset;
840 int qemu_timedate_diff(struct tm *tm)
844 if (rtc_date_offset == -1)
846 seconds = mktimegm(tm);
849 tmp.tm_isdst = -1; /* use timezone to figure it out */
850 seconds = mktime(&tmp);
853 seconds = mktimegm(tm) + rtc_date_offset;
855 return seconds - time(NULL);
858 static void configure_rtc_date_offset(const char *startdate, int legacy)
860 time_t rtc_start_date;
863 if (!strcmp(startdate, "now") && legacy) {
864 rtc_date_offset = -1;
866 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
874 } else if (sscanf(startdate, "%d-%d-%d",
886 rtc_start_date = mktimegm(&tm);
887 if (rtc_start_date == -1) {
889 fprintf(stderr, "Invalid date format. Valid formats are:\n"
890 "'2006-06-17T16:01:21' or '2006-06-17'\n");
893 rtc_date_offset = time(NULL) - rtc_start_date;
897 static void configure_rtc(QemuOpts *opts)
901 value = qemu_opt_get(opts, "base");
903 if (!strcmp(value, "utc")) {
905 } else if (!strcmp(value, "localtime")) {
908 configure_rtc_date_offset(value, 0);
911 value = qemu_opt_get(opts, "clock");
913 if (!strcmp(value, "host")) {
914 rtc_clock = QEMU_CLOCK_HOST;
915 } else if (!strcmp(value, "rt")) {
916 rtc_clock = QEMU_CLOCK_REALTIME;
917 } else if (!strcmp(value, "vm")) {
918 rtc_clock = QEMU_CLOCK_VIRTUAL;
920 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
924 value = qemu_opt_get(opts, "driftfix");
926 if (!strcmp(value, "slew")) {
927 static GlobalProperty slew_lost_ticks[] = {
929 .driver = "mc146818rtc",
930 .property = "lost_tick_policy",
933 { /* end of list */ }
936 qdev_prop_register_global_list(slew_lost_ticks);
937 } else if (!strcmp(value, "none")) {
938 /* discard is default */
940 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
946 /***********************************************************/
947 /* Bluetooth support */
950 static struct HCIInfo *hci_table[MAX_NICS];
952 struct HCIInfo *qemu_next_hci(void)
954 if (cur_hci == nb_hcis)
957 return hci_table[cur_hci++];
960 static int bt_hci_parse(const char *str)
965 if (nb_hcis >= MAX_NICS) {
966 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
979 bdaddr.b[5] = 0x56 + nb_hcis;
980 hci->bdaddr_set(hci, bdaddr.b);
982 hci_table[nb_hcis++] = hci;
987 static void bt_vhci_add(int vlan_id)
989 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
992 fprintf(stderr, "qemu: warning: adding a VHCI to "
993 "an empty scatternet %i\n", vlan_id);
995 bt_vhci_init(bt_new_hci(vlan));
998 static struct bt_device_s *bt_device_add(const char *opt)
1000 struct bt_scatternet_s *vlan;
1002 char *endp = strstr(opt, ",vlan=");
1003 int len = (endp ? endp - opt : strlen(opt)) + 1;
1006 pstrcpy(devname, MIN(sizeof(devname), len), opt);
1009 vlan_id = strtol(endp + 6, &endp, 0);
1011 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
1016 vlan = qemu_find_bt_vlan(vlan_id);
1019 fprintf(stderr, "qemu: warning: adding a slave device to "
1020 "an empty scatternet %i\n", vlan_id);
1022 if (!strcmp(devname, "keyboard"))
1023 return bt_keyboard_init(vlan);
1025 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
1029 static int bt_parse(const char *opt)
1031 const char *endp, *p;
1034 if (strstart(opt, "hci", &endp)) {
1035 if (!*endp || *endp == ',') {
1037 if (!strstart(endp, ",vlan=", 0))
1040 return bt_hci_parse(opt);
1042 } else if (strstart(opt, "vhci", &endp)) {
1043 if (!*endp || *endp == ',') {
1045 if (strstart(endp, ",vlan=", &p)) {
1046 vlan = strtol(p, (char **) &endp, 0);
1048 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
1052 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
1061 } else if (strstart(opt, "device:", &endp))
1062 return !bt_device_add(endp);
1064 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
1068 static int parse_sandbox(QemuOpts *opts, void *opaque)
1070 /* FIXME: change this to true for 1.3 */
1071 if (qemu_opt_get_bool(opts, "enable", false)) {
1072 #ifdef CONFIG_SECCOMP
1073 if (seccomp_start() < 0) {
1074 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1075 "failed to install seccomp syscall filter in the kernel");
1079 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1080 "sandboxing request but seccomp is not compiled into this build");
1088 static int parse_name(QemuOpts *opts, void *opaque)
1090 const char *proc_name;
1092 if (qemu_opt_get(opts, "debug-threads")) {
1093 qemu_thread_naming(qemu_opt_get_bool(opts, "debug-threads", false));
1095 qemu_name = qemu_opt_get(opts, "guest");
1097 proc_name = qemu_opt_get(opts, "process");
1099 os_set_proc_name(proc_name);
1105 bool usb_enabled(bool default_usb)
1107 return qemu_opt_get_bool(qemu_get_machine_opts(), "usb",
1108 has_defaults && default_usb);
1112 static int parse_add_fd(QemuOpts *opts, void *opaque)
1114 int fd, dupfd, flags;
1116 const char *fd_opaque = NULL;
1118 fd = qemu_opt_get_number(opts, "fd", -1);
1119 fdset_id = qemu_opt_get_number(opts, "set", -1);
1120 fd_opaque = qemu_opt_get(opts, "opaque");
1123 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1124 "fd option is required and must be non-negative");
1128 if (fd <= STDERR_FILENO) {
1129 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1130 "fd cannot be a standard I/O stream");
1135 * All fds inherited across exec() necessarily have FD_CLOEXEC
1136 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1138 flags = fcntl(fd, F_GETFD);
1139 if (flags == -1 || (flags & FD_CLOEXEC)) {
1140 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1141 "fd is not valid or already in use");
1146 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1147 "set option is required and must be non-negative");
1151 #ifdef F_DUPFD_CLOEXEC
1152 dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
1156 qemu_set_cloexec(dupfd);
1160 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1161 "Error duplicating fd: %s", strerror(errno));
1165 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1166 monitor_fdset_add_fd(dupfd, true, fdset_id, fd_opaque ? true : false,
1172 static int cleanup_add_fd(QemuOpts *opts, void *opaque)
1176 fd = qemu_opt_get_number(opts, "fd", -1);
1183 /***********************************************************/
1184 /* QEMU Block devices */
1186 #define HD_OPTS "media=disk"
1187 #define CDROM_OPTS "media=cdrom"
1189 #define PFLASH_OPTS ""
1193 static int drive_init_func(QemuOpts *opts, void *opaque)
1195 BlockInterfaceType *block_default_type = opaque;
1197 return drive_new(opts, *block_default_type) == NULL;
1200 static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
1202 if (qemu_opt_get(opts, "snapshot") == NULL) {
1203 qemu_opt_set(opts, "snapshot", "on");
1208 static void default_drive(int enable, int snapshot, BlockInterfaceType type,
1209 int index, const char *optstr)
1214 if (!enable || drive_get_by_index(type, index)) {
1218 opts = drive_add(type, index, NULL, optstr);
1220 drive_enable_snapshot(opts, NULL);
1223 dinfo = drive_new(opts, type);
1227 dinfo->is_default = true;
1231 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
1233 boot_set_handler = func;
1234 boot_set_opaque = opaque;
1237 int qemu_boot_set(const char *boot_order)
1239 if (!boot_set_handler) {
1242 return boot_set_handler(boot_set_opaque, boot_order);
1245 static void validate_bootdevices(const char *devices)
1247 /* We just do some generic consistency checks */
1251 for (p = devices; *p != '\0'; p++) {
1252 /* Allowed boot devices are:
1253 * a-b: floppy disk drives
1254 * c-f: IDE disk drives
1255 * g-m: machine implementation dependent drives
1256 * n-p: network devices
1257 * It's up to each machine implementation to check if the given boot
1258 * devices match the actual hardware implementation and firmware
1261 if (*p < 'a' || *p > 'p') {
1262 fprintf(stderr, "Invalid boot device '%c'\n", *p);
1265 if (bitmap & (1 << (*p - 'a'))) {
1266 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
1269 bitmap |= 1 << (*p - 'a');
1273 static void restore_boot_order(void *opaque)
1275 char *normal_boot_order = opaque;
1276 static int first = 1;
1278 /* Restore boot order and remove ourselves after the first boot */
1284 qemu_boot_set(normal_boot_order);
1286 qemu_unregister_reset(restore_boot_order, normal_boot_order);
1287 g_free(normal_boot_order);
1290 static QemuOptsList qemu_smp_opts = {
1292 .implied_opt_name = "cpus",
1293 .merge_lists = true,
1294 .head = QTAILQ_HEAD_INITIALIZER(qemu_smp_opts.head),
1298 .type = QEMU_OPT_NUMBER,
1301 .type = QEMU_OPT_NUMBER,
1304 .type = QEMU_OPT_NUMBER,
1307 .type = QEMU_OPT_NUMBER,
1310 .type = QEMU_OPT_NUMBER,
1312 { /*End of list */ }
1316 static void smp_parse(QemuOpts *opts)
1320 unsigned cpus = qemu_opt_get_number(opts, "cpus", 0);
1321 unsigned sockets = qemu_opt_get_number(opts, "sockets", 0);
1322 unsigned cores = qemu_opt_get_number(opts, "cores", 0);
1323 unsigned threads = qemu_opt_get_number(opts, "threads", 0);
1325 /* compute missing values, prefer sockets over cores over threads */
1326 if (cpus == 0 || sockets == 0) {
1327 sockets = sockets > 0 ? sockets : 1;
1328 cores = cores > 0 ? cores : 1;
1329 threads = threads > 0 ? threads : 1;
1331 cpus = cores * threads * sockets;
1335 threads = threads > 0 ? threads : 1;
1336 cores = cpus / (sockets * threads);
1338 threads = cpus / (cores * sockets);
1342 max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
1345 smp_cores = cores > 0 ? cores : 1;
1346 smp_threads = threads > 0 ? threads : 1;
1350 if (max_cpus == 0) {
1351 max_cpus = smp_cpus;
1354 if (max_cpus > MAX_CPUMASK_BITS) {
1355 fprintf(stderr, "Unsupported number of maxcpus\n");
1358 if (max_cpus < smp_cpus) {
1359 fprintf(stderr, "maxcpus must be equal to or greater than smp\n");
1365 static void realtime_init(void)
1368 if (os_mlock() < 0) {
1369 fprintf(stderr, "qemu: locking memory failed\n");
1376 static void configure_msg(QemuOpts *opts)
1378 enable_timestamp_msg = qemu_opt_get_bool(opts, "timestamp", true);
1381 /***********************************************************/
1384 static int usb_device_add(const char *devname)
1386 USBDevice *dev = NULL;
1387 #ifndef CONFIG_LINUX
1391 if (!usb_enabled(false)) {
1395 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1396 dev = usbdevice_create(devname);
1400 /* the other ones */
1401 #ifndef CONFIG_LINUX
1402 /* only the linux version is qdev-ified, usb-bsd still needs this */
1403 if (strstart(devname, "host:", &p)) {
1404 dev = usb_host_device_open(usb_bus_find(-1), p);
1414 static int usb_device_del(const char *devname)
1419 if (strstart(devname, "host:", &p)) {
1423 if (!usb_enabled(false)) {
1427 p = strchr(devname, '.');
1430 bus_num = strtoul(devname, NULL, 0);
1431 addr = strtoul(p + 1, NULL, 0);
1433 return usb_device_delete_addr(bus_num, addr);
1436 static int usb_parse(const char *cmdline)
1439 r = usb_device_add(cmdline);
1441 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
1446 void do_usb_add(Monitor *mon, const QDict *qdict)
1448 const char *devname = qdict_get_str(qdict, "devname");
1449 if (usb_device_add(devname) < 0) {
1450 error_report("could not add USB device '%s'", devname);
1454 void do_usb_del(Monitor *mon, const QDict *qdict)
1456 const char *devname = qdict_get_str(qdict, "devname");
1457 if (usb_device_del(devname) < 0) {
1458 error_report("could not delete USB device '%s'", devname);
1462 /***********************************************************/
1463 /* machine registration */
1465 MachineState *current_machine;
1467 static void machine_class_init(ObjectClass *oc, void *data)
1469 MachineClass *mc = MACHINE_CLASS(oc);
1470 QEMUMachine *qm = data;
1472 mc->family = qm->family;
1473 mc->name = qm->name;
1474 mc->alias = qm->alias;
1475 mc->desc = qm->desc;
1476 mc->init = qm->init;
1477 mc->reset = qm->reset;
1478 mc->hot_add_cpu = qm->hot_add_cpu;
1479 mc->kvm_type = qm->kvm_type;
1480 mc->block_default_type = qm->block_default_type;
1481 mc->units_per_default_bus = qm->units_per_default_bus;
1482 mc->max_cpus = qm->max_cpus;
1483 mc->no_serial = qm->no_serial;
1484 mc->no_parallel = qm->no_parallel;
1485 mc->use_virtcon = qm->use_virtcon;
1486 mc->use_sclp = qm->use_sclp;
1487 mc->no_floppy = qm->no_floppy;
1488 mc->no_cdrom = qm->no_cdrom;
1489 mc->no_sdcard = qm->no_sdcard;
1490 mc->has_dynamic_sysbus = qm->has_dynamic_sysbus;
1491 mc->is_default = qm->is_default;
1492 mc->default_machine_opts = qm->default_machine_opts;
1493 mc->default_boot_order = qm->default_boot_order;
1494 mc->default_display = qm->default_display;
1495 mc->compat_props = qm->compat_props;
1496 mc->hw_version = qm->hw_version;
1499 int qemu_register_machine(QEMUMachine *m)
1501 char *name = g_strconcat(m->name, TYPE_MACHINE_SUFFIX, NULL);
1504 .parent = TYPE_MACHINE,
1505 .class_init = machine_class_init,
1506 .class_data = (void *)m,
1515 static MachineClass *find_machine(const char *name)
1517 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1518 MachineClass *mc = NULL;
1520 for (el = machines; el; el = el->next) {
1521 MachineClass *temp = el->data;
1523 if (!strcmp(temp->name, name)) {
1528 !strcmp(temp->alias, name)) {
1534 g_slist_free(machines);
1538 MachineClass *find_default_machine(void)
1540 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1541 MachineClass *mc = NULL;
1543 for (el = machines; el; el = el->next) {
1544 MachineClass *temp = el->data;
1546 if (temp->is_default) {
1552 g_slist_free(machines);
1556 MachineInfoList *qmp_query_machines(Error **errp)
1558 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1559 MachineInfoList *mach_list = NULL;
1561 for (el = machines; el; el = el->next) {
1562 MachineClass *mc = el->data;
1563 MachineInfoList *entry;
1566 info = g_malloc0(sizeof(*info));
1567 if (mc->is_default) {
1568 info->has_is_default = true;
1569 info->is_default = true;
1573 info->has_alias = true;
1574 info->alias = g_strdup(mc->alias);
1577 info->name = g_strdup(mc->name);
1578 info->cpu_max = !mc->max_cpus ? 1 : mc->max_cpus;
1580 entry = g_malloc0(sizeof(*entry));
1581 entry->value = info;
1582 entry->next = mach_list;
1586 g_slist_free(machines);
1590 /***********************************************************/
1591 /* main execution loop */
1593 struct vm_change_state_entry {
1594 VMChangeStateHandler *cb;
1596 QLIST_ENTRY (vm_change_state_entry) entries;
1599 static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
1601 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1604 VMChangeStateEntry *e;
1606 e = g_malloc0(sizeof (*e));
1610 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
1614 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1616 QLIST_REMOVE (e, entries);
1620 void vm_state_notify(int running, RunState state)
1622 VMChangeStateEntry *e, *next;
1624 trace_vm_state_notify(running, state);
1626 QLIST_FOREACH_SAFE(e, &vm_change_state_head, entries, next) {
1627 e->cb(e->opaque, running, state);
1631 /* reset/shutdown handler */
1633 typedef struct QEMUResetEntry {
1634 QTAILQ_ENTRY(QEMUResetEntry) entry;
1635 QEMUResetHandler *func;
1639 static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1640 QTAILQ_HEAD_INITIALIZER(reset_handlers);
1641 static int reset_requested;
1642 static int shutdown_requested, shutdown_signal = -1;
1643 static pid_t shutdown_pid;
1644 static int powerdown_requested;
1645 static int debug_requested;
1646 static int suspend_requested;
1647 static WakeupReason wakeup_reason;
1648 static NotifierList powerdown_notifiers =
1649 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
1650 static NotifierList suspend_notifiers =
1651 NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
1652 static NotifierList wakeup_notifiers =
1653 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
1654 static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE);
1656 int qemu_shutdown_requested_get(void)
1658 return shutdown_requested;
1661 int qemu_reset_requested_get(void)
1663 return reset_requested;
1666 static int qemu_shutdown_requested(void)
1668 return atomic_xchg(&shutdown_requested, 0);
1671 static void qemu_kill_report(void)
1673 if (!qtest_driver() && shutdown_signal != -1) {
1674 fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal);
1675 if (shutdown_pid == 0) {
1676 /* This happens for eg ^C at the terminal, so it's worth
1677 * avoiding printing an odd message in that case.
1679 fputc('\n', stderr);
1681 fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid);
1683 shutdown_signal = -1;
1687 static int qemu_reset_requested(void)
1689 int r = reset_requested;
1690 reset_requested = 0;
1694 static int qemu_suspend_requested(void)
1696 int r = suspend_requested;
1697 suspend_requested = 0;
1701 static WakeupReason qemu_wakeup_requested(void)
1703 return wakeup_reason;
1706 static int qemu_powerdown_requested(void)
1708 int r = powerdown_requested;
1709 powerdown_requested = 0;
1713 static int qemu_debug_requested(void)
1715 int r = debug_requested;
1716 debug_requested = 0;
1720 void qemu_register_reset(QEMUResetHandler *func, void *opaque)
1722 QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
1725 re->opaque = opaque;
1726 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
1729 void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
1733 QTAILQ_FOREACH(re, &reset_handlers, entry) {
1734 if (re->func == func && re->opaque == opaque) {
1735 QTAILQ_REMOVE(&reset_handlers, re, entry);
1742 void qemu_devices_reset(void)
1744 QEMUResetEntry *re, *nre;
1746 /* reset all devices */
1747 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
1748 re->func(re->opaque);
1752 void qemu_system_reset(bool report)
1756 mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL;
1758 if (mc && mc->reset) {
1761 qemu_devices_reset();
1764 qapi_event_send_reset(&error_abort);
1766 cpu_synchronize_all_post_reset();
1769 void qemu_system_reset_request(void)
1772 shutdown_requested = 1;
1774 reset_requested = 1;
1777 qemu_notify_event();
1780 static void qemu_system_suspend(void)
1783 notifier_list_notify(&suspend_notifiers, NULL);
1784 runstate_set(RUN_STATE_SUSPENDED);
1785 qapi_event_send_suspend(&error_abort);
1788 void qemu_system_suspend_request(void)
1790 if (runstate_check(RUN_STATE_SUSPENDED)) {
1793 suspend_requested = 1;
1795 qemu_notify_event();
1798 void qemu_register_suspend_notifier(Notifier *notifier)
1800 notifier_list_add(&suspend_notifiers, notifier);
1803 void qemu_system_wakeup_request(WakeupReason reason)
1805 trace_system_wakeup_request(reason);
1807 if (!runstate_check(RUN_STATE_SUSPENDED)) {
1810 if (!(wakeup_reason_mask & (1 << reason))) {
1813 runstate_set(RUN_STATE_RUNNING);
1814 wakeup_reason = reason;
1815 qemu_notify_event();
1818 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
1821 wakeup_reason_mask |= (1 << reason);
1823 wakeup_reason_mask &= ~(1 << reason);
1827 void qemu_register_wakeup_notifier(Notifier *notifier)
1829 notifier_list_add(&wakeup_notifiers, notifier);
1832 void qemu_system_killed(int signal, pid_t pid)
1834 shutdown_signal = signal;
1839 shutdown_qemu_gracefully();
1841 qemu_system_shutdown_request();
1845 void qemu_system_shutdown_request(void)
1847 trace_qemu_system_shutdown_request();
1848 shutdown_requested = 1;
1849 qemu_notify_event();
1852 static void qemu_system_powerdown(void)
1854 qapi_event_send_powerdown(&error_abort);
1855 notifier_list_notify(&powerdown_notifiers, NULL);
1858 void qemu_system_powerdown_request(void)
1860 trace_qemu_system_powerdown_request();
1861 powerdown_requested = 1;
1862 qemu_notify_event();
1865 void qemu_register_powerdown_notifier(Notifier *notifier)
1867 notifier_list_add(&powerdown_notifiers, notifier);
1870 void qemu_system_debug_request(void)
1872 debug_requested = 1;
1873 qemu_notify_event();
1876 static bool main_loop_should_exit(void)
1879 if (qemu_debug_requested()) {
1880 vm_stop(RUN_STATE_DEBUG);
1882 if (qemu_suspend_requested()) {
1883 qemu_system_suspend();
1885 if (qemu_shutdown_requested()) {
1887 qapi_event_send_shutdown(&error_abort);
1889 vm_stop(RUN_STATE_SHUTDOWN);
1894 if (qemu_reset_requested()) {
1896 cpu_synchronize_all_states();
1897 qemu_system_reset(VMRESET_REPORT);
1899 if (runstate_needs_reset()) {
1900 runstate_set(RUN_STATE_PAUSED);
1903 if (qemu_wakeup_requested()) {
1905 cpu_synchronize_all_states();
1907 // A "system reset" causes "virtio_queue" malfunction.
1908 // It might be a bug of virtio bus or virtio devices.
1909 // We don't want suspend(deep sleep), so It's OK now.
1910 // However, we should fix it later.
1911 qemu_system_reset(VMRESET_SILENT);
1913 notifier_list_notify(&wakeup_notifiers, &wakeup_reason);
1914 wakeup_reason = QEMU_WAKEUP_REASON_NONE;
1916 qapi_event_send_wakeup(&error_abort);
1918 if (qemu_powerdown_requested()) {
1919 qemu_system_powerdown();
1921 if (qemu_vmstop_requested(&r)) {
1927 static void main_loop(void)
1931 #ifdef CONFIG_PROFILER
1938 nonblocking = !kvm_enabled() && !xen_enabled() && !hax_enabled() && last_io > 0;
1939 #ifdef CONFIG_PROFILER
1940 ti = profile_getclock();
1942 last_io = main_loop_wait(nonblocking);
1943 #ifdef CONFIG_PROFILER
1944 dev_time += profile_getclock() - ti;
1946 } while (!main_loop_should_exit());
1949 static void version(void)
1951 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
1954 static void help(int exitcode)
1957 printf("usage: %s [options] [disk_image]\n\n"
1958 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1959 error_get_progname());
1961 #define QEMU_OPTIONS_GENERATE_HELP
1962 #include "qemu-options-wrapper.h"
1964 printf("\nDuring emulation, the following keys are useful:\n"
1965 "ctrl-alt-f toggle full screen\n"
1966 "ctrl-alt-n switch to virtual console 'n'\n"
1967 "ctrl-alt toggle mouse and keyboard grab\n"
1969 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1974 #define HAS_ARG 0x0001
1976 typedef struct QEMUOption {
1983 static const QEMUOption qemu_options[] = {
1984 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1985 #define QEMU_OPTIONS_GENERATE_OPTIONS
1986 #include "qemu-options-wrapper.h"
1990 static bool vga_available(void)
1992 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
1995 static bool cirrus_vga_available(void)
1997 return object_class_by_name("cirrus-vga")
1998 || object_class_by_name("isa-cirrus-vga");
2001 static bool vmware_vga_available(void)
2003 return object_class_by_name("vmware-svga");
2006 static bool qxl_vga_available(void)
2008 return object_class_by_name("qxl-vga");
2011 static bool tcx_vga_available(void)
2013 return object_class_by_name("SUNW,tcx");
2016 static bool cg3_vga_available(void)
2018 return object_class_by_name("cgthree");
2021 static void select_vgahw (const char *p)
2025 assert(vga_interface_type == VGA_NONE);
2026 if (strstart(p, "std", &opts)) {
2027 if (vga_available()) {
2028 vga_interface_type = VGA_STD;
2030 fprintf(stderr, "Error: standard VGA not available\n");
2033 } else if (strstart(p, "cirrus", &opts)) {
2034 if (cirrus_vga_available()) {
2035 vga_interface_type = VGA_CIRRUS;
2037 fprintf(stderr, "Error: Cirrus VGA not available\n");
2040 } else if (strstart(p, "vmware", &opts)) {
2041 if (vmware_vga_available()) {
2042 vga_interface_type = VGA_VMWARE;
2044 fprintf(stderr, "Error: VMWare SVGA not available\n");
2047 } else if (strstart(p, "xenfb", &opts)) {
2048 vga_interface_type = VGA_XENFB;
2049 } else if (strstart(p, "qxl", &opts)) {
2050 if (qxl_vga_available()) {
2051 vga_interface_type = VGA_QXL;
2053 fprintf(stderr, "Error: QXL VGA not available\n");
2056 } else if (strstart(p, "tcx", &opts)) {
2057 if (tcx_vga_available()) {
2058 vga_interface_type = VGA_TCX;
2060 fprintf(stderr, "Error: TCX framebuffer not available\n");
2063 } else if (strstart(p, "cg3", &opts)) {
2064 if (cg3_vga_available()) {
2065 vga_interface_type = VGA_CG3;
2067 fprintf(stderr, "Error: CG3 framebuffer not available\n");
2070 } else if (!strstart(p, "none", &opts)) {
2072 fprintf(stderr, "Unknown vga type: %s\n", p);
2076 const char *nextopt;
2078 if (strstart(opts, ",retrace=", &nextopt)) {
2080 if (strstart(opts, "dumb", &nextopt))
2081 vga_retrace_method = VGA_RETRACE_DUMB;
2082 else if (strstart(opts, "precise", &nextopt))
2083 vga_retrace_method = VGA_RETRACE_PRECISE;
2084 else goto invalid_vga;
2085 } else goto invalid_vga;
2090 static DisplayType select_display(const char *p)
2093 DisplayType display = DT_DEFAULT;
2095 if (strstart(p, "sdl", &opts)) {
2099 const char *nextopt;
2101 if (strstart(opts, ",frame=", &nextopt)) {
2103 if (strstart(opts, "on", &nextopt)) {
2105 } else if (strstart(opts, "off", &nextopt)) {
2108 goto invalid_sdl_args;
2110 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
2112 if (strstart(opts, "on", &nextopt)) {
2114 } else if (strstart(opts, "off", &nextopt)) {
2117 goto invalid_sdl_args;
2119 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
2121 if (strstart(opts, "on", &nextopt)) {
2123 } else if (strstart(opts, "off", &nextopt)) {
2126 goto invalid_sdl_args;
2128 } else if (strstart(opts, ",window_close=", &nextopt)) {
2130 if (strstart(opts, "on", &nextopt)) {
2132 } else if (strstart(opts, "off", &nextopt)) {
2135 goto invalid_sdl_args;
2139 fprintf(stderr, "Invalid SDL option string: %s\n", p);
2145 fprintf(stderr, "SDL support is disabled\n");
2148 } else if (strstart(p, "vnc", &opts)) {
2153 const char *nextopt;
2155 if (strstart(opts, "=", &nextopt)) {
2156 vnc_display = nextopt;
2160 fprintf(stderr, "VNC requires a display argument vnc=<display>\n");
2164 fprintf(stderr, "VNC support is disabled\n");
2167 } else if (strstart(p, "curses", &opts)) {
2168 #ifdef CONFIG_CURSES
2169 display = DT_CURSES;
2171 fprintf(stderr, "Curses support is disabled\n");
2174 } else if (strstart(p, "gtk", &opts)) {
2178 const char *nextopt;
2180 if (strstart(opts, ",grab_on_hover=", &nextopt)) {
2182 if (strstart(opts, "on", &nextopt)) {
2183 grab_on_hover = true;
2184 } else if (strstart(opts, "off", &nextopt)) {
2185 grab_on_hover = false;
2187 goto invalid_gtk_args;
2191 fprintf(stderr, "Invalid GTK option string: %s\n", p);
2197 fprintf(stderr, "GTK support is disabled\n");
2202 } else if (strstart(p, "maru_sdl", &opts)) {
2203 display = DT_MARU_SDL;
2205 # ifdef CONFIG_USE_SHM
2206 } else if (strstart(p, "maru_shm", &opts)) {
2207 display = DT_MARU_SHM;
2209 #endif /* CONFIG_MARU */
2210 } else if (strstart(p, "none", &opts)) {
2213 fprintf(stderr, "Unknown display type: %s\n", p);
2220 static int balloon_parse(const char *arg)
2224 if (strcmp(arg, "none") == 0) {
2228 if (!strncmp(arg, "virtio", 6)) {
2229 if (arg[6] == ',') {
2230 /* have params -> parse them */
2231 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
2235 /* create empty opts */
2236 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
2239 qemu_opt_set(opts, "driver", "virtio-balloon");
2246 char *qemu_find_file(int type, const char *name)
2252 /* Try the name as a straight path first */
2253 if (access(name, R_OK) == 0) {
2254 trace_load_file(name, name);
2255 return g_strdup(name);
2259 case QEMU_FILE_TYPE_BIOS:
2262 case QEMU_FILE_TYPE_KEYMAP:
2263 subdir = "keymaps/";
2269 for (i = 0; i < data_dir_idx; i++) {
2270 buf = g_strdup_printf("%s/%s%s", data_dir[i], subdir, name);
2271 if (access(buf, R_OK) == 0) {
2272 trace_load_file(name, buf);
2280 static int device_help_func(QemuOpts *opts, void *opaque)
2282 return qdev_device_help(opts);
2285 static int device_init_func(QemuOpts *opts, void *opaque)
2289 dev = qdev_device_add(opts);
2292 object_unref(OBJECT(dev));
2296 static int chardev_init_func(QemuOpts *opts, void *opaque)
2298 Error *local_err = NULL;
2300 qemu_chr_new_from_opts(opts, NULL, &local_err);
2302 error_report("%s", error_get_pretty(local_err));
2303 error_free(local_err);
2309 #ifdef CONFIG_VIRTFS
2310 static int fsdev_init_func(QemuOpts *opts, void *opaque)
2313 ret = qemu_fsdev_add(opts);
2319 static int mon_init_func(QemuOpts *opts, void *opaque)
2321 CharDriverState *chr;
2322 const char *chardev;
2326 mode = qemu_opt_get(opts, "mode");
2330 if (strcmp(mode, "readline") == 0) {
2331 flags = MONITOR_USE_READLINE;
2332 } else if (strcmp(mode, "control") == 0) {
2333 flags = MONITOR_USE_CONTROL;
2335 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
2339 if (qemu_opt_get_bool(opts, "pretty", 0))
2340 flags |= MONITOR_USE_PRETTY;
2342 if (qemu_opt_get_bool(opts, "default", 0))
2343 flags |= MONITOR_IS_DEFAULT;
2345 chardev = qemu_opt_get(opts, "chardev");
2346 chr = qemu_chr_find(chardev);
2348 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
2352 qemu_chr_fe_claim_no_fail(chr);
2353 monitor_init(chr, flags);
2357 static void monitor_parse(const char *optarg, const char *mode)
2359 static int monitor_device_index = 0;
2365 if (strstart(optarg, "chardev:", &p)) {
2366 snprintf(label, sizeof(label), "%s", p);
2368 snprintf(label, sizeof(label), "compat_monitor%d",
2369 monitor_device_index);
2370 if (monitor_device_index == 0) {
2373 opts = qemu_chr_parse_compat(label, optarg);
2375 fprintf(stderr, "parse error: %s\n", optarg);
2380 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, NULL);
2382 fprintf(stderr, "duplicate chardev: %s\n", label);
2385 qemu_opt_set(opts, "mode", mode);
2386 qemu_opt_set(opts, "chardev", label);
2388 qemu_opt_set(opts, "default", "on");
2389 monitor_device_index++;
2392 struct device_config {
2394 DEV_USB, /* -usbdevice */
2396 DEV_SERIAL, /* -serial */
2397 DEV_PARALLEL, /* -parallel */
2398 DEV_VIRTCON, /* -virtioconsole */
2399 DEV_DEBUGCON, /* -debugcon */
2400 DEV_GDB, /* -gdb, -s */
2401 DEV_SCLP, /* s390 sclp */
2403 const char *cmdline;
2405 QTAILQ_ENTRY(device_config) next;
2408 static QTAILQ_HEAD(, device_config) device_configs =
2409 QTAILQ_HEAD_INITIALIZER(device_configs);
2411 static void add_device_config(int type, const char *cmdline)
2413 struct device_config *conf;
2415 conf = g_malloc0(sizeof(*conf));
2417 conf->cmdline = cmdline;
2418 loc_save(&conf->loc);
2419 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
2422 static int foreach_device_config(int type, int (*func)(const char *cmdline))
2424 struct device_config *conf;
2427 QTAILQ_FOREACH(conf, &device_configs, next) {
2428 if (conf->type != type)
2430 loc_push_restore(&conf->loc);
2431 rc = func(conf->cmdline);
2432 loc_pop(&conf->loc);
2440 static int serial_parse(const char *devname)
2442 static int index = 0;
2445 if (strcmp(devname, "none") == 0)
2447 if (index == MAX_SERIAL_PORTS) {
2448 fprintf(stderr, "qemu: too many serial ports\n");
2451 snprintf(label, sizeof(label), "serial%d", index);
2452 serial_hds[index] = qemu_chr_new(label, devname, NULL);
2453 if (!serial_hds[index]) {
2454 fprintf(stderr, "qemu: could not connect serial device"
2455 " to character backend '%s'\n", devname);
2462 static int parallel_parse(const char *devname)
2464 static int index = 0;
2467 if (strcmp(devname, "none") == 0)
2469 if (index == MAX_PARALLEL_PORTS) {
2470 fprintf(stderr, "qemu: too many parallel ports\n");
2473 snprintf(label, sizeof(label), "parallel%d", index);
2474 parallel_hds[index] = qemu_chr_new(label, devname, NULL);
2475 if (!parallel_hds[index]) {
2476 fprintf(stderr, "qemu: could not connect parallel device"
2477 " to character backend '%s'\n", devname);
2484 static int virtcon_parse(const char *devname)
2486 QemuOptsList *device = qemu_find_opts("device");
2487 static int index = 0;
2489 QemuOpts *bus_opts, *dev_opts;
2491 if (strcmp(devname, "none") == 0)
2493 if (index == MAX_VIRTIO_CONSOLES) {
2494 fprintf(stderr, "qemu: too many virtio consoles\n");
2498 bus_opts = qemu_opts_create(device, NULL, 0, &error_abort);
2499 if (arch_type == QEMU_ARCH_S390X) {
2500 qemu_opt_set(bus_opts, "driver", "virtio-serial-s390");
2502 qemu_opt_set(bus_opts, "driver", "virtio-serial-pci");
2505 dev_opts = qemu_opts_create(device, NULL, 0, &error_abort);
2506 qemu_opt_set(dev_opts, "driver", "virtconsole");
2508 snprintf(label, sizeof(label), "virtcon%d", index);
2509 virtcon_hds[index] = qemu_chr_new(label, devname, NULL);
2510 if (!virtcon_hds[index]) {
2511 fprintf(stderr, "qemu: could not connect virtio console"
2512 " to character backend '%s'\n", devname);
2515 qemu_opt_set(dev_opts, "chardev", label);
2521 static int sclp_parse(const char *devname)
2523 QemuOptsList *device = qemu_find_opts("device");
2524 static int index = 0;
2528 if (strcmp(devname, "none") == 0) {
2531 if (index == MAX_SCLP_CONSOLES) {
2532 fprintf(stderr, "qemu: too many sclp consoles\n");
2536 assert(arch_type == QEMU_ARCH_S390X);
2538 dev_opts = qemu_opts_create(device, NULL, 0, NULL);
2539 qemu_opt_set(dev_opts, "driver", "sclpconsole");
2541 snprintf(label, sizeof(label), "sclpcon%d", index);
2542 sclp_hds[index] = qemu_chr_new(label, devname, NULL);
2543 if (!sclp_hds[index]) {
2544 fprintf(stderr, "qemu: could not connect sclp console"
2545 " to character backend '%s'\n", devname);
2548 qemu_opt_set(dev_opts, "chardev", label);
2554 static int debugcon_parse(const char *devname)
2558 if (!qemu_chr_new("debugcon", devname, NULL)) {
2561 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL);
2563 fprintf(stderr, "qemu: already have a debugcon device\n");
2566 qemu_opt_set(opts, "driver", "isa-debugcon");
2567 qemu_opt_set(opts, "chardev", "debugcon");
2571 static gint machine_class_cmp(gconstpointer a, gconstpointer b)
2573 const MachineClass *mc1 = a, *mc2 = b;
2576 if (mc1->family == NULL) {
2577 if (mc2->family == NULL) {
2578 /* Compare standalone machine types against each other; they sort
2579 * in increasing order.
2581 return strcmp(object_class_get_name(OBJECT_CLASS(mc1)),
2582 object_class_get_name(OBJECT_CLASS(mc2)));
2585 /* Standalone machine types sort after families. */
2589 if (mc2->family == NULL) {
2590 /* Families sort before standalone machine types. */
2594 /* Families sort between each other alphabetically increasingly. */
2595 res = strcmp(mc1->family, mc2->family);
2600 /* Within the same family, machine types sort in decreasing order. */
2601 return strcmp(object_class_get_name(OBJECT_CLASS(mc2)),
2602 object_class_get_name(OBJECT_CLASS(mc1)));
2605 static MachineClass *machine_parse(const char *name)
2607 MachineClass *mc = NULL;
2608 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
2611 mc = find_machine(name);
2616 if (name && !is_help_option(name)) {
2617 error_report("Unsupported machine type");
2618 error_printf("Use -machine help to list supported machines!\n");
2620 printf("Supported machines are:\n");
2621 machines = g_slist_sort(machines, machine_class_cmp);
2622 for (el = machines; el; el = el->next) {
2623 MachineClass *mc = el->data;
2625 printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name);
2627 printf("%-20s %s%s\n", mc->name, mc->desc,
2628 mc->is_default ? " (default)" : "");
2632 g_slist_free(machines);
2633 exit(!name || !is_help_option(name));
2636 void qemu_add_exit_notifier(Notifier *notify)
2638 notifier_list_add(&exit_notifiers, notify);
2641 void qemu_remove_exit_notifier(Notifier *notify)
2643 notifier_remove(notify);
2646 static void qemu_run_exit_notifiers(void)
2648 notifier_list_notify(&exit_notifiers, NULL);
2651 void qemu_add_machine_init_done_notifier(Notifier *notify)
2653 notifier_list_add(&machine_init_done_notifiers, notify);
2656 static void qemu_run_machine_init_done_notifiers(void)
2658 notifier_list_notify(&machine_init_done_notifiers, NULL);
2661 static const QEMUOption *lookup_opt(int argc, char **argv,
2662 const char **poptarg, int *poptind)
2664 const QEMUOption *popt;
2665 int optind = *poptind;
2666 char *r = argv[optind];
2669 loc_set_cmdline(argv, optind, 1);
2671 /* Treat --foo the same as -foo. */
2674 popt = qemu_options;
2677 error_report("invalid option");
2679 maru_register_exit_msg(MARU_EXIT_UNKNOWN, "invalid option.");
2683 if (!strcmp(popt->name, r + 1))
2687 if (popt->flags & HAS_ARG) {
2688 if (optind >= argc) {
2689 error_report("requires an argument");
2691 maru_register_exit_msg(MARU_EXIT_UNKNOWN, "requires an argument.");
2695 optarg = argv[optind++];
2696 loc_set_cmdline(argv, optind - 2, 2);
2707 static gpointer malloc_and_trace(gsize n_bytes)
2709 void *ptr = malloc(n_bytes);
2710 trace_g_malloc(n_bytes, ptr);
2714 static gpointer realloc_and_trace(gpointer mem, gsize n_bytes)
2716 void *ptr = realloc(mem, n_bytes);
2717 trace_g_realloc(mem, n_bytes, ptr);
2721 static void free_and_trace(gpointer mem)
2727 static int machine_set_property(const char *name, const char *value,
2730 Object *obj = OBJECT(opaque);
2731 StringInputVisitor *siv;
2732 Error *local_err = NULL;
2735 if (strcmp(name, "type") == 0) {
2739 qom_name = g_strdup(name);
2747 siv = string_input_visitor_new(value);
2748 object_property_set(obj, string_input_get_visitor(siv), qom_name, &local_err);
2749 string_input_visitor_cleanup(siv);
2753 qerror_report_err(local_err);
2754 error_free(local_err);
2761 static int object_create(QemuOpts *opts, void *opaque)
2770 ov = opts_visitor_new(opts);
2771 pdict = qemu_opts_to_qdict(opts, NULL);
2773 visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
2778 qdict_del(pdict, "qom-type");
2779 visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
2784 qdict_del(pdict, "id");
2785 visit_type_str(opts_get_visitor(ov), &id, "id", &err);
2790 object_add(type, id, pdict, opts_get_visitor(ov), &err);
2794 visit_end_struct(opts_get_visitor(ov), &err);
2796 qmp_object_del(id, NULL);
2800 opts_visitor_cleanup(ov);
2807 qerror_report_err(err);
2815 // W/A for preserve larger continuous heap for RAM.
2816 extern void *preallocated_ram_ptr;
2817 extern int preallocated_ram_size;
2820 int main(int argc, char **argv, char **envp)
2823 int snapshot, linux_boot;
2824 const char *initrd_filename;
2825 const char *kernel_filename, *kernel_cmdline;
2826 const char *boot_order;
2828 int cyls, heads, secs, translation;
2829 QemuOpts *hda_opts = NULL, *opts, *machine_opts, *icount_opts = NULL;
2830 QemuOptsList *olist;
2833 const char *loadvm = NULL;
2834 MachineClass *machine_class;
2835 const char *cpu_model;
2836 const char *vga_model = NULL;
2837 const char *qtest_chrdev = NULL;
2838 const char *qtest_log = NULL;
2839 const char *pid_file = NULL;
2840 const char *incoming = NULL;
2842 int show_vnc_port = 0;
2844 bool defconfig = true;
2845 bool userconfig = true;
2846 const char *log_mask = NULL;
2847 const char *log_file = NULL;
2848 GMemVTable mem_trace = {
2849 .malloc = malloc_and_trace,
2850 .realloc = realloc_and_trace,
2851 .free = free_and_trace,
2853 const char *trace_events = NULL;
2854 const char *trace_file = NULL;
2855 const ram_addr_t default_ram_size = (ram_addr_t)DEFAULT_RAM_SIZE *
2857 ram_addr_t maxram_size = default_ram_size;
2858 uint64_t ram_slots = 0;
2859 FILE *vmstate_dump_file = NULL;
2860 Error *main_loop_err = NULL;
2862 atexit(qemu_run_exit_notifiers);
2863 error_set_progname(argv[0]);
2864 qemu_init_exec_dir(argv[0]);
2866 g_mem_set_vtable(&mem_trace);
2868 module_call_init(MODULE_INIT_QOM);
2870 qemu_add_opts(&qemu_drive_opts);
2871 qemu_add_drive_opts(&qemu_legacy_drive_opts);
2872 qemu_add_drive_opts(&qemu_common_drive_opts);
2873 qemu_add_drive_opts(&qemu_drive_opts);
2874 qemu_add_opts(&qemu_chardev_opts);
2875 qemu_add_opts(&qemu_device_opts);
2876 qemu_add_opts(&qemu_netdev_opts);
2877 qemu_add_opts(&qemu_net_opts);
2878 qemu_add_opts(&qemu_rtc_opts);
2879 qemu_add_opts(&qemu_global_opts);
2880 qemu_add_opts(&qemu_mon_opts);
2881 qemu_add_opts(&qemu_trace_opts);
2882 qemu_add_opts(&qemu_option_rom_opts);
2883 qemu_add_opts(&qemu_machine_opts);
2884 qemu_add_opts(&qemu_mem_opts);
2885 qemu_add_opts(&qemu_smp_opts);
2886 qemu_add_opts(&qemu_boot_opts);
2887 qemu_add_opts(&qemu_sandbox_opts);
2888 qemu_add_opts(&qemu_add_fd_opts);
2889 qemu_add_opts(&qemu_object_opts);
2890 qemu_add_opts(&qemu_tpmdev_opts);
2891 qemu_add_opts(&qemu_realtime_opts);
2892 qemu_add_opts(&qemu_msg_opts);
2893 qemu_add_opts(&qemu_name_opts);
2894 qemu_add_opts(&qemu_numa_opts);
2895 qemu_add_opts(&qemu_icount_opts);
2899 rtc_clock = QEMU_CLOCK_HOST;
2901 QLIST_INIT (&vm_change_state_head);
2902 os_setup_early_signal_handling();
2904 module_call_init(MODULE_INIT_MACHINE);
2905 machine_class = find_default_machine();
2907 ram_size = default_ram_size;
2909 cyls = heads = secs = 0;
2910 translation = BIOS_ATA_TRANSLATION_AUTO;
2912 for (i = 0; i < MAX_NODES; i++) {
2913 numa_info[i].node_mem = 0;
2914 numa_info[i].present = false;
2915 bitmap_zero(numa_info[i].node_cpu, MAX_CPUMASK_BITS);
2919 max_numa_nodeid = 0;
2922 bdrv_init_with_whitelist();
2926 /* first pass of option parsing */
2928 while (optind < argc) {
2929 if (argv[optind][0] != '-') {
2933 const QEMUOption *popt;
2935 popt = lookup_opt(argc, argv, &optarg, &optind);
2936 switch (popt->index) {
2937 case QEMU_OPTION_nodefconfig:
2940 case QEMU_OPTION_nouserconfig:
2949 ret = qemu_read_default_config_files(userconfig);
2955 /* second pass of option parsing */
2960 if (argv[optind][0] != '-') {
2961 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
2963 const QEMUOption *popt;
2965 popt = lookup_opt(argc, argv, &optarg, &optind);
2966 if (!(popt->arch_mask & arch_type)) {
2967 printf("Option %s not supported for this target\n", popt->name);
2970 switch(popt->index) {
2972 machine_class = machine_parse(optarg);
2974 case QEMU_OPTION_no_kvm_irqchip: {
2975 olist = qemu_find_opts("machine");
2976 qemu_opts_parse(olist, "kernel_irqchip=off", 0);
2979 case QEMU_OPTION_cpu:
2980 /* hw initialization will check this */
2983 case QEMU_OPTION_hda:
2987 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2989 snprintf(buf, sizeof(buf),
2990 "%s,cyls=%d,heads=%d,secs=%d%s",
2991 HD_OPTS , cyls, heads, secs,
2992 translation == BIOS_ATA_TRANSLATION_LBA ?
2994 translation == BIOS_ATA_TRANSLATION_NONE ?
2995 ",trans=none" : "");
2996 drive_add(IF_DEFAULT, 0, optarg, buf);
2999 case QEMU_OPTION_hdb:
3000 case QEMU_OPTION_hdc:
3001 case QEMU_OPTION_hdd:
3002 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
3005 case QEMU_OPTION_drive:
3006 if (drive_def(optarg) == NULL) {
3010 case QEMU_OPTION_set:
3011 if (qemu_set_option(optarg) != 0)
3014 case QEMU_OPTION_global:
3015 if (qemu_global_option(optarg) != 0)
3018 case QEMU_OPTION_mtdblock:
3019 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
3021 case QEMU_OPTION_sd:
3022 drive_add(IF_SD, -1, optarg, SD_OPTS);
3024 case QEMU_OPTION_pflash:
3025 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
3027 case QEMU_OPTION_snapshot:
3030 case QEMU_OPTION_hdachs:
3034 cyls = strtol(p, (char **)&p, 0);
3035 if (cyls < 1 || cyls > 16383)
3040 heads = strtol(p, (char **)&p, 0);
3041 if (heads < 1 || heads > 16)
3046 secs = strtol(p, (char **)&p, 0);
3047 if (secs < 1 || secs > 63)
3051 if (!strcmp(p, "large")) {
3052 translation = BIOS_ATA_TRANSLATION_LARGE;
3053 } else if (!strcmp(p, "rechs")) {
3054 translation = BIOS_ATA_TRANSLATION_RECHS;
3055 } else if (!strcmp(p, "none")) {
3056 translation = BIOS_ATA_TRANSLATION_NONE;
3057 } else if (!strcmp(p, "lba")) {
3058 translation = BIOS_ATA_TRANSLATION_LBA;
3059 } else if (!strcmp(p, "auto")) {
3060 translation = BIOS_ATA_TRANSLATION_AUTO;
3064 } else if (*p != '\0') {
3066 fprintf(stderr, "qemu: invalid physical CHS format\n");
3069 if (hda_opts != NULL) {
3071 snprintf(num, sizeof(num), "%d", cyls);
3072 qemu_opt_set(hda_opts, "cyls", num);
3073 snprintf(num, sizeof(num), "%d", heads);
3074 qemu_opt_set(hda_opts, "heads", num);
3075 snprintf(num, sizeof(num), "%d", secs);
3076 qemu_opt_set(hda_opts, "secs", num);
3077 if (translation == BIOS_ATA_TRANSLATION_LARGE) {
3078 qemu_opt_set(hda_opts, "trans", "large");
3079 } else if (translation == BIOS_ATA_TRANSLATION_RECHS) {
3080 qemu_opt_set(hda_opts, "trans", "rechs");
3081 } else if (translation == BIOS_ATA_TRANSLATION_LBA) {
3082 qemu_opt_set(hda_opts, "trans", "lba");
3083 } else if (translation == BIOS_ATA_TRANSLATION_NONE) {
3084 qemu_opt_set(hda_opts, "trans", "none");
3089 case QEMU_OPTION_numa:
3090 opts = qemu_opts_parse(qemu_find_opts("numa"), optarg, 1);
3095 case QEMU_OPTION_display:
3096 display_type = select_display(optarg);
3098 case QEMU_OPTION_nographic:
3099 display_type = DT_NOGRAPHIC;
3101 case QEMU_OPTION_curses:
3102 #ifdef CONFIG_CURSES
3103 display_type = DT_CURSES;
3105 fprintf(stderr, "Curses support is disabled\n");
3109 case QEMU_OPTION_portrait:
3110 graphic_rotate = 90;
3112 case QEMU_OPTION_rotate:
3113 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
3114 if (graphic_rotate != 0 && graphic_rotate != 90 &&
3115 graphic_rotate != 180 && graphic_rotate != 270) {
3117 "qemu: only 90, 180, 270 deg rotation is available\n");
3121 case QEMU_OPTION_kernel:
3122 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg);
3124 case QEMU_OPTION_initrd:
3125 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg);
3127 case QEMU_OPTION_append:
3128 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg);
3130 case QEMU_OPTION_dtb:
3131 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg);
3133 case QEMU_OPTION_cdrom:
3134 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
3136 case QEMU_OPTION_boot:
3137 opts = qemu_opts_parse(qemu_find_opts("boot-opts"), optarg, 1);
3142 case QEMU_OPTION_fda:
3143 case QEMU_OPTION_fdb:
3144 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
3147 case QEMU_OPTION_no_fd_bootchk:
3150 case QEMU_OPTION_netdev:
3151 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
3155 case QEMU_OPTION_net:
3156 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
3160 #ifdef CONFIG_LIBISCSI
3161 case QEMU_OPTION_iscsi:
3162 opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0);
3169 case QEMU_OPTION_tftp:
3170 legacy_tftp_prefix = optarg;
3172 case QEMU_OPTION_bootp:
3173 legacy_bootp_filename = optarg;
3175 case QEMU_OPTION_redir:
3176 if (net_slirp_redir(optarg) < 0)
3180 case QEMU_OPTION_bt:
3181 add_device_config(DEV_BT, optarg);
3183 case QEMU_OPTION_audio_help:
3187 case QEMU_OPTION_soundhw:
3188 select_soundhw (optarg);
3193 case QEMU_OPTION_version:
3197 case QEMU_OPTION_m: {
3199 const char *mem_str;
3200 const char *maxmem_str, *slots_str;
3202 opts = qemu_opts_parse(qemu_find_opts("memory"),
3208 mem_str = qemu_opt_get(opts, "size");
3210 error_report("invalid -m option, missing 'size' option");
3214 error_report("missing 'size' option value");
3218 sz = qemu_opt_get_size(opts, "size", ram_size);
3220 /* Fix up legacy suffix-less format */
3221 if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) {
3222 uint64_t overflow_check = sz;
3225 if ((sz >> 20) != overflow_check) {
3226 error_report("too large 'size' option value");
3231 /* backward compatibility behaviour for case "-m 0" */
3233 sz = default_ram_size;
3236 sz = QEMU_ALIGN_UP(sz, 8192);
3238 if (ram_size != sz) {
3239 error_report("ram size too large");
3242 maxram_size = ram_size;
3244 maxmem_str = qemu_opt_get(opts, "maxmem");
3245 slots_str = qemu_opt_get(opts, "slots");
3246 if (maxmem_str && slots_str) {
3249 sz = qemu_opt_get_size(opts, "maxmem", 0);
3250 if (sz < ram_size) {
3251 error_report("invalid -m option value: maxmem "
3252 "(0x%" PRIx64 ") <= initial memory (0x"
3253 RAM_ADDR_FMT ")", sz, ram_size);
3257 slots = qemu_opt_get_number(opts, "slots", 0);
3258 if ((sz > ram_size) && !slots) {
3259 error_report("invalid -m option value: maxmem "
3260 "(0x%" PRIx64 ") more than initial memory (0x"
3261 RAM_ADDR_FMT ") but no hotplug slots where "
3262 "specified", sz, ram_size);
3266 if ((sz <= ram_size) && slots) {
3267 error_report("invalid -m option value: %"
3268 PRIu64 " hotplug slots where specified but "
3269 "maxmem (0x%" PRIx64 ") <= initial memory (0x"
3270 RAM_ADDR_FMT ")", slots, sz, ram_size);
3275 } else if ((!maxmem_str && slots_str) ||
3276 (maxmem_str && !slots_str)) {
3277 error_report("invalid -m option value: missing "
3278 "'%s' option", slots_str ? "maxmem" : "slots");
3284 case QEMU_OPTION_tpmdev:
3285 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
3290 case QEMU_OPTION_mempath:
3293 case QEMU_OPTION_mem_prealloc:
3303 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
3305 case QEMU_OPTION_gdb:
3306 add_device_config(DEV_GDB, optarg);
3309 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
3310 data_dir[data_dir_idx++] = optarg;
3313 case QEMU_OPTION_bios:
3314 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg);
3316 case QEMU_OPTION_singlestep:
3323 keyboard_layout = optarg;
3325 case QEMU_OPTION_localtime:
3328 case QEMU_OPTION_vga:
3337 w = strtol(p, (char **)&p, 10);
3340 fprintf(stderr, "qemu: invalid resolution or depth\n");
3346 h = strtol(p, (char **)&p, 10);
3351 depth = strtol(p, (char **)&p, 10);
3352 if (depth != 8 && depth != 15 && depth != 16 &&
3353 depth != 24 && depth != 32)
3355 } else if (*p == '\0') {
3356 depth = graphic_depth;
3363 graphic_depth = depth;
3366 case QEMU_OPTION_echr:
3369 term_escape_char = strtol(optarg, &r, 0);
3371 printf("Bad argument to echr\n");
3374 case QEMU_OPTION_monitor:
3375 default_monitor = 0;
3376 if (strncmp(optarg, "none", 4)) {
3377 monitor_parse(optarg, "readline");
3380 case QEMU_OPTION_qmp:
3381 monitor_parse(optarg, "control");
3382 default_monitor = 0;
3384 case QEMU_OPTION_mon:
3385 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
3389 default_monitor = 0;
3391 case QEMU_OPTION_chardev:
3392 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
3397 case QEMU_OPTION_fsdev:
3398 olist = qemu_find_opts("fsdev");
3400 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
3403 opts = qemu_opts_parse(olist, optarg, 1);
3408 case QEMU_OPTION_virtfs: {
3411 const char *writeout, *sock_fd, *socket;
3413 olist = qemu_find_opts("virtfs");
3415 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
3418 opts = qemu_opts_parse(olist, optarg, 1);
3423 if (qemu_opt_get(opts, "fsdriver") == NULL ||
3424 qemu_opt_get(opts, "mount_tag") == NULL) {
3425 fprintf(stderr, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
3428 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
3429 qemu_opt_get(opts, "mount_tag"),
3432 fprintf(stderr, "duplicate fsdev id: %s\n",
3433 qemu_opt_get(opts, "mount_tag"));
3437 writeout = qemu_opt_get(opts, "writeout");
3439 #ifdef CONFIG_SYNC_FILE_RANGE
3440 qemu_opt_set(fsdev, "writeout", writeout);
3442 fprintf(stderr, "writeout=immediate not supported on "
3447 qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver"));
3448 qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"));
3449 qemu_opt_set(fsdev, "security_model",
3450 qemu_opt_get(opts, "security_model"));
3451 socket = qemu_opt_get(opts, "socket");
3453 qemu_opt_set(fsdev, "socket", socket);
3455 sock_fd = qemu_opt_get(opts, "sock_fd");
3457 qemu_opt_set(fsdev, "sock_fd", sock_fd);
3460 qemu_opt_set_bool(fsdev, "readonly",
3461 qemu_opt_get_bool(opts, "readonly", 0));
3462 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3464 qemu_opt_set(device, "driver", "virtio-9p-pci");
3465 qemu_opt_set(device, "fsdev",
3466 qemu_opt_get(opts, "mount_tag"));
3467 qemu_opt_set(device, "mount_tag",
3468 qemu_opt_get(opts, "mount_tag"));
3471 case QEMU_OPTION_virtfs_synth: {
3475 fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3478 fprintf(stderr, "duplicate option: %s\n", "virtfs_synth");
3481 qemu_opt_set(fsdev, "fsdriver", "synth");
3483 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3485 qemu_opt_set(device, "driver", "virtio-9p-pci");
3486 qemu_opt_set(device, "fsdev", "v_synth");
3487 qemu_opt_set(device, "mount_tag", "v_synth");
3490 case QEMU_OPTION_serial:
3491 add_device_config(DEV_SERIAL, optarg);
3493 if (strncmp(optarg, "mon:", 4) == 0) {
3494 default_monitor = 0;
3497 case QEMU_OPTION_watchdog:
3500 "qemu: only one watchdog option may be given\n");
3505 case QEMU_OPTION_watchdog_action:
3506 if (select_watchdog_action(optarg) == -1) {
3507 fprintf(stderr, "Unknown -watchdog-action parameter\n");
3511 case QEMU_OPTION_virtiocon:
3512 add_device_config(DEV_VIRTCON, optarg);
3513 default_virtcon = 0;
3514 if (strncmp(optarg, "mon:", 4) == 0) {
3515 default_monitor = 0;
3518 case QEMU_OPTION_parallel:
3519 add_device_config(DEV_PARALLEL, optarg);
3520 default_parallel = 0;
3521 if (strncmp(optarg, "mon:", 4) == 0) {
3522 default_monitor = 0;
3525 case QEMU_OPTION_debugcon:
3526 add_device_config(DEV_DEBUGCON, optarg);
3528 case QEMU_OPTION_loadvm:
3531 case QEMU_OPTION_full_screen:
3534 case QEMU_OPTION_no_frame:
3537 case QEMU_OPTION_alt_grab:
3540 case QEMU_OPTION_ctrl_grab:
3543 case QEMU_OPTION_no_quit:
3546 case QEMU_OPTION_sdl:
3548 display_type = DT_SDL;
3551 fprintf(stderr, "SDL support is disabled\n");
3554 case QEMU_OPTION_pidfile:
3557 case QEMU_OPTION_win2k_hack:
3558 win2k_install_hack = 1;
3560 case QEMU_OPTION_rtc_td_hack: {
3561 static GlobalProperty slew_lost_ticks[] = {
3563 .driver = "mc146818rtc",
3564 .property = "lost_tick_policy",
3567 { /* end of list */ }
3570 qdev_prop_register_global_list(slew_lost_ticks);
3573 case QEMU_OPTION_acpitable:
3574 opts = qemu_opts_parse(qemu_find_opts("acpi"), optarg, 1);
3578 do_acpitable_option(opts);
3580 case QEMU_OPTION_smbios:
3581 opts = qemu_opts_parse(qemu_find_opts("smbios"), optarg, 0);
3585 do_smbios_option(opts);
3587 case QEMU_OPTION_enable_kvm:
3588 olist = qemu_find_opts("machine");
3589 qemu_opts_parse(olist, "accel=kvm", 0);
3591 case QEMU_OPTION_enable_yagl:
3592 #if defined(CONFIG_YAGL)
3595 fprintf(stderr, "YaGL openGLES passthrough support is disabled,"
3596 " ignoring -enable-yagl\n");
3599 case QEMU_OPTION_yagl_backend:
3600 #if defined(CONFIG_YAGL)
3601 yagl_backend = optarg;
3603 fprintf(stderr, "YaGL openGLES passthrough support is disabled,"
3604 " ignoring -yagl-backend\n");
3607 case QEMU_OPTION_enable_vigs:
3608 #if defined(CONFIG_VIGS)
3611 fprintf(stderr, "VIGS support is disabled,"
3612 " ignoring -enable-vigs\n");
3615 case QEMU_OPTION_vigs_backend:
3616 #if defined(CONFIG_VIGS)
3617 vigs_backend = g_strdup(optarg);
3619 fprintf(stderr, "VIGS support is disabled,"
3620 " ignoring -vigs-backend\n");
3623 case QEMU_OPTION_machine:
3624 olist = qemu_find_opts("machine");
3625 opts = qemu_opts_parse(olist, optarg, 1);
3629 optarg = qemu_opt_get(opts, "type");
3631 machine_class = machine_parse(optarg);
3634 case QEMU_OPTION_no_kvm:
3635 olist = qemu_find_opts("machine");
3636 qemu_opts_parse(olist, "accel=tcg", 0);
3638 case QEMU_OPTION_no_kvm_pit: {
3639 fprintf(stderr, "Warning: KVM PIT can no longer be disabled "
3643 case QEMU_OPTION_no_kvm_pit_reinjection: {
3644 static GlobalProperty kvm_pit_lost_tick_policy[] = {
3646 .driver = "kvm-pit",
3647 .property = "lost_tick_policy",
3650 { /* end of list */ }
3653 fprintf(stderr, "Warning: option deprecated, use "
3654 "lost_tick_policy property of kvm-pit instead.\n");
3655 qdev_prop_register_global_list(kvm_pit_lost_tick_policy);
3658 case QEMU_OPTION_usb:
3659 olist = qemu_find_opts("machine");
3660 qemu_opts_parse(olist, "usb=on", 0);
3662 case QEMU_OPTION_usbdevice:
3663 olist = qemu_find_opts("machine");
3664 qemu_opts_parse(olist, "usb=on", 0);
3665 add_device_config(DEV_USB, optarg);
3667 case QEMU_OPTION_device:
3668 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
3672 case QEMU_OPTION_smp:
3673 if (!qemu_opts_parse(qemu_find_opts("smp-opts"), optarg, 1)) {
3677 case QEMU_OPTION_vnc:
3680 vnc_display = optarg;
3682 fprintf(stderr, "VNC support is disabled\n");
3686 case QEMU_OPTION_no_acpi:
3689 case QEMU_OPTION_no_hpet:
3692 case QEMU_OPTION_balloon:
3693 if (balloon_parse(optarg) < 0) {
3694 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
3698 case QEMU_OPTION_no_reboot:
3701 case QEMU_OPTION_no_shutdown:
3704 case QEMU_OPTION_show_cursor:
3707 case QEMU_OPTION_uuid:
3708 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
3709 fprintf(stderr, "Fail to parse UUID string."
3710 " Wrong format.\n");
3713 qemu_uuid_set = true;
3715 case QEMU_OPTION_option_rom:
3716 if (nb_option_roms >= MAX_OPTION_ROMS) {
3717 fprintf(stderr, "Too many option ROMs\n");
3720 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
3724 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
3725 option_rom[nb_option_roms].bootindex =
3726 qemu_opt_get_number(opts, "bootindex", -1);
3727 if (!option_rom[nb_option_roms].name) {
3728 fprintf(stderr, "Option ROM file is not specified\n");
3733 case QEMU_OPTION_semihosting:
3734 semihosting_enabled = 1;
3736 case QEMU_OPTION_tdf:
3737 fprintf(stderr, "Warning: user space PIT time drift fix "
3738 "is no longer supported.\n");
3740 case QEMU_OPTION_name:
3741 opts = qemu_opts_parse(qemu_find_opts("name"), optarg, 1);
3746 case QEMU_OPTION_prom_env:
3747 if (nb_prom_envs >= MAX_PROM_ENVS) {
3748 fprintf(stderr, "Too many prom variables\n");
3751 prom_envs[nb_prom_envs] = optarg;
3754 case QEMU_OPTION_old_param:
3757 case QEMU_OPTION_clock:
3758 /* Clock options no longer exist. Keep this option for
3759 * backward compatibility.
3762 case QEMU_OPTION_startdate:
3763 configure_rtc_date_offset(optarg, 1);
3765 case QEMU_OPTION_rtc:
3766 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
3770 configure_rtc(opts);
3772 case QEMU_OPTION_tb_size:
3773 tcg_tb_size = strtol(optarg, NULL, 0);
3774 if (tcg_tb_size < 0) {
3778 case QEMU_OPTION_icount:
3779 icount_opts = qemu_opts_parse(qemu_find_opts("icount"),
3785 case QEMU_OPTION_incoming:
3787 runstate_set(RUN_STATE_INMIGRATE);
3789 case QEMU_OPTION_nodefaults:
3792 case QEMU_OPTION_xen_domid:
3793 if (!(xen_available())) {
3794 printf("Option %s not supported for this target\n", popt->name);
3797 xen_domid = atoi(optarg);
3799 case QEMU_OPTION_xen_create:
3800 if (!(xen_available())) {
3801 printf("Option %s not supported for this target\n", popt->name);
3804 xen_mode = XEN_CREATE;
3806 case QEMU_OPTION_xen_attach:
3807 if (!(xen_available())) {
3808 printf("Option %s not supported for this target\n", popt->name);
3811 xen_mode = XEN_ATTACH;
3813 case QEMU_OPTION_trace:
3815 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
3819 trace_events = qemu_opt_get(opts, "events");
3820 trace_file = qemu_opt_get(opts, "file");
3823 case QEMU_OPTION_readconfig:
3825 int ret = qemu_read_config_file(optarg);
3827 fprintf(stderr, "read config %s: %s\n", optarg,
3833 case QEMU_OPTION_spice:
3834 olist = qemu_find_opts("spice");
3836 fprintf(stderr, "spice is not supported by this qemu build.\n");
3842 opts = qemu_opts_parse(olist, optarg, 0);
3848 case QEMU_OPTION_writeconfig:
3851 if (strcmp(optarg, "-") == 0) {
3854 fp = fopen(optarg, "w");
3856 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
3860 qemu_config_write(fp);
3866 case QEMU_OPTION_qtest:
3867 qtest_chrdev = optarg;
3869 case QEMU_OPTION_qtest_log:
3872 case QEMU_OPTION_sandbox:
3873 opts = qemu_opts_parse(qemu_find_opts("sandbox"), optarg, 1);
3878 case QEMU_OPTION_enable_hax:
3879 olist = qemu_find_opts("machine");
3880 qemu_opts_parse(olist, "accel=hax", 0);
3882 case QEMU_OPTION_add_fd:
3884 opts = qemu_opts_parse(qemu_find_opts("add-fd"), optarg, 0);
3889 error_report("File descriptor passing is disabled on this "
3895 case QEMU_OPTION_disable_skin:
3898 case QEMU_OPTION_enable_suspend:
3899 ecs_set_suspend_state(SUSPEND_UNLOCK);
3902 case QEMU_OPTION_object:
3903 opts = qemu_opts_parse(qemu_find_opts("object"), optarg, 1);
3908 case QEMU_OPTION_realtime:
3909 opts = qemu_opts_parse(qemu_find_opts("realtime"), optarg, 0);
3913 enable_mlock = qemu_opt_get_bool(opts, "mlock", true);
3915 case QEMU_OPTION_msg:
3916 opts = qemu_opts_parse(qemu_find_opts("msg"), optarg, 0);
3920 configure_msg(opts);
3922 case QEMU_OPTION_dump_vmstate:
3923 if (vmstate_dump_file) {
3924 fprintf(stderr, "qemu: only one '-dump-vmstate' "
3925 "option may be given\n");
3928 vmstate_dump_file = fopen(optarg, "w");
3929 if (vmstate_dump_file == NULL) {
3930 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
3935 os_parse_cmd_args(popt->index, optarg);
3943 if (qemu_init_main_loop(&main_loop_err)) {
3944 error_report("%s", error_get_pretty(main_loop_err));
3948 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 0)) {
3952 if (qemu_opts_foreach(qemu_find_opts("name"), parse_name, NULL, 1)) {
3957 if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL, 1)) {
3961 if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd, NULL, 1)) {
3966 if (machine_class == NULL) {
3967 fprintf(stderr, "No machine specified, and there is no default.\n"
3968 "Use -machine help to list supported machines!\n");
3972 current_machine = MACHINE(object_new(object_class_get_name(
3973 OBJECT_CLASS(machine_class))));
3974 object_property_add_child(object_get_root(), "machine",
3975 OBJECT(current_machine), &error_abort);
3976 cpu_exec_init_all();
3978 if (machine_class->hw_version) {
3979 qemu_set_version(machine_class->hw_version);
3982 /* Init CPU def lists, based on config
3983 * - Must be called after all the qemu_read_config_file() calls
3984 * - Must be called before list_cpus()
3985 * - Must be called before machine->init()
3989 if (cpu_model && is_help_option(cpu_model)) {
3990 list_cpus(stdout, &fprintf, cpu_model);
3994 #if defined(CONFIG_MARU)
3995 preallocated_ram_ptr = qemu_anon_ram_alloc(ram_size, NULL);
3996 if (preallocated_ram_ptr) {
3997 preallocated_ram_size = ram_size;
4000 kernel_cmdline = qemu_opt_get(qemu_get_machine_opts(), "append");
4001 // Returned variable points different address from input variable.
4002 kernel_cmdline = prepare_maru(kernel_cmdline);
4003 qemu_opt_set(qemu_get_machine_opts(), "append", kernel_cmdline);
4006 /* Open the logfile at this point, if necessary. We can't open the logfile
4007 * when encountering either of the logging options (-d or -D) because the
4008 * other one may be encountered later on the command line, changing the
4009 * location or level of logging.
4014 qemu_set_log_filename(log_file);
4017 mask = qemu_str_to_log_mask(log_mask);
4019 qemu_print_log_usage(stdout);
4025 if (!is_daemonized()) {
4026 if (!trace_init_backends(trace_events, trace_file)) {
4031 /* If no data_dir is specified then try to find it relative to the
4033 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
4034 data_dir[data_dir_idx] = os_find_datadir();
4035 if (data_dir[data_dir_idx] != NULL) {
4039 /* If all else fails use the install path specified when building. */
4040 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
4041 data_dir[data_dir_idx++] = CONFIG_QEMU_DATADIR;
4044 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
4046 machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */
4047 if (smp_cpus > machine_class->max_cpus) {
4048 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
4049 "supported by machine `%s' (%d)\n", smp_cpus,
4050 machine_class->name, machine_class->max_cpus);
4055 * Get the default machine options from the machine if it is not already
4056 * specified either by the configuration file or by the command line.
4058 if (machine_class->default_machine_opts) {
4059 qemu_opts_set_defaults(qemu_find_opts("machine"),
4060 machine_class->default_machine_opts, 0);
4063 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
4064 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
4066 if (!vga_model && !default_vga) {
4067 vga_interface_type = VGA_DEVICE;
4069 if (!has_defaults || machine_class->no_serial) {
4072 if (!has_defaults || machine_class->no_parallel) {
4073 default_parallel = 0;
4075 if (!has_defaults || !machine_class->use_virtcon) {
4076 default_virtcon = 0;
4078 if (!has_defaults || !machine_class->use_sclp) {
4081 if (!has_defaults || machine_class->no_floppy) {
4084 if (!has_defaults || machine_class->no_cdrom) {
4087 if (!has_defaults || machine_class->no_sdcard) {
4090 if (!has_defaults) {
4091 default_monitor = 0;
4096 if (is_daemonized()) {
4097 /* According to documentation and historically, -nographic redirects
4098 * serial port, parallel port and monitor to stdio, which does not work
4099 * with -daemonize. We can redirect these to null instead, but since
4100 * -nographic is legacy, let's just error out.
4101 * We disallow -nographic only if all other ports are not redirected
4102 * explicitly, to not break existing legacy setups which uses
4103 * -nographic _and_ redirects all ports explicitly - this is valid
4104 * usage, -nographic is just a no-op in this case.
4106 if (display_type == DT_NOGRAPHIC
4107 && (default_parallel || default_serial
4108 || default_monitor || default_virtcon)) {
4109 fprintf(stderr, "-nographic can not be used with -daemonize\n");
4112 #ifdef CONFIG_CURSES
4113 if (display_type == DT_CURSES) {
4114 fprintf(stderr, "curses display can not be used with -daemonize\n");
4120 if (display_type == DT_NOGRAPHIC) {
4121 if (default_parallel)
4122 add_device_config(DEV_PARALLEL, "null");
4123 if (default_serial && default_monitor) {
4124 add_device_config(DEV_SERIAL, "mon:stdio");
4125 } else if (default_virtcon && default_monitor) {
4126 add_device_config(DEV_VIRTCON, "mon:stdio");
4127 } else if (default_sclp && default_monitor) {
4128 add_device_config(DEV_SCLP, "mon:stdio");
4131 add_device_config(DEV_SERIAL, "stdio");
4132 if (default_virtcon)
4133 add_device_config(DEV_VIRTCON, "stdio");
4135 add_device_config(DEV_SCLP, "stdio");
4137 if (default_monitor)
4138 monitor_parse("stdio", "readline");
4142 add_device_config(DEV_SERIAL, "vc:80Cx24C");
4143 if (default_parallel)
4144 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
4145 if (default_monitor)
4146 monitor_parse("vc:80Cx24C", "readline");
4147 if (default_virtcon)
4148 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
4150 add_device_config(DEV_SCLP, "vc:80Cx24C");
4154 if (display_type == DT_DEFAULT && !display_remote) {
4155 #if defined(CONFIG_MARU)
4156 // FIXME: for compatibility...
4157 // If no display_type is specified,
4158 // we use DT_MARU_SDL on Linux, Windows and
4159 // use DT_MARU_SHM on MacOS.
4160 #if defined(CONFIG_SDL)
4161 display_type = DT_MARU_SDL;
4162 #elif defined(CONFIG_USE_SHM)
4163 display_type = DT_MARU_SHM;
4165 #elif defined(CONFIG_GTK)
4166 display_type = DT_GTK;
4167 #elif defined(CONFIG_SDL) || defined(CONFIG_COCOA)
4168 display_type = DT_SDL;
4169 #elif defined(CONFIG_VNC)
4170 vnc_display = "localhost:0,to=99";
4173 display_type = DT_NONE;
4177 if ((no_frame || alt_grab || ctrl_grab) && display_type != DT_SDL) {
4178 fprintf(stderr, "-no-frame, -alt-grab and -ctrl-grab are only valid "
4179 "for SDL, ignoring option\n");
4181 if (no_quit && (display_type != DT_GTK && display_type != DT_SDL)) {
4182 fprintf(stderr, "-no-quit is only valid for GTK and SDL, "
4183 "ignoring option\n");
4186 #if defined(CONFIG_GTK)
4187 if (display_type == DT_GTK) {
4188 early_gtk_display_init();
4196 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
4198 #ifdef CONFIG_VIRTFS
4199 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
4204 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
4205 fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
4209 /* store value for the future use */
4210 qemu_opt_set_number(qemu_find_opts_singleton("memory"), "size", ram_size);
4212 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0)
4217 if (qemu_opts_foreach(qemu_find_opts("object"),
4218 object_create, NULL, 0) != 0) {
4222 machine_opts = qemu_get_machine_opts();
4223 if (qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
4225 object_unref(OBJECT(current_machine));
4229 configure_accelerator(current_machine);
4232 Error *local_err = NULL;
4233 qtest_init(qtest_chrdev, qtest_log, &local_err);
4235 error_report("%s", error_get_pretty(local_err));
4236 error_free(local_err);
4241 machine_opts = qemu_get_machine_opts();
4242 kernel_filename = qemu_opt_get(machine_opts, "kernel");
4243 initrd_filename = qemu_opt_get(machine_opts, "initrd");
4244 kernel_cmdline = qemu_opt_get(machine_opts, "append");
4245 bios_name = qemu_opt_get(machine_opts, "firmware");
4247 boot_order = machine_class->default_boot_order;
4248 opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
4250 char *normal_boot_order;
4251 const char *order, *once;
4253 order = qemu_opt_get(opts, "order");
4255 validate_bootdevices(order);
4259 once = qemu_opt_get(opts, "once");
4261 validate_bootdevices(once);
4262 normal_boot_order = g_strdup(boot_order);
4264 qemu_register_reset(restore_boot_order, normal_boot_order);
4267 boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu);
4268 boot_strict = qemu_opt_get_bool(opts, "strict", false);
4271 if (!kernel_cmdline) {
4272 kernel_cmdline = "";
4273 current_machine->kernel_cmdline = (char *)kernel_cmdline;
4276 linux_boot = (kernel_filename != NULL);
4278 if (!linux_boot && *kernel_cmdline != '\0') {
4279 fprintf(stderr, "-append only allowed with -kernel option\n");
4283 if (!linux_boot && initrd_filename != NULL) {
4284 fprintf(stderr, "-initrd only allowed with -kernel option\n");
4288 if (!linux_boot && qemu_opt_get(machine_opts, "dtb")) {
4289 fprintf(stderr, "-dtb only allowed with -kernel option\n");
4293 os_set_line_buffering();
4295 qemu_init_cpu_loop();
4296 qemu_mutex_lock_iothread();
4299 #if defined(CONFIG_MARU) && defined(CONFIG_LINUX)
4303 /* spice needs the timers to be initialized by this point */
4309 if (kvm_enabled() || xen_enabled() || hax_enabled()) {
4310 fprintf(stderr, "-icount is not allowed with kvm or xen\n");
4313 configure_icount(icount_opts, &error_abort);
4314 qemu_opts_del(icount_opts);
4317 /* clean up network at qemu process termination */
4318 atexit(&net_cleanup);
4320 if (net_init_clients() < 0) {
4325 if (tpm_init() < 0) {
4330 /* init the bluetooth world */
4331 if (foreach_device_config(DEV_BT, bt_parse))
4334 if (!xen_enabled()) {
4335 /* On 32-bit hosts, QEMU is limited by virtual address space */
4336 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
4337 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
4345 /* If the currently selected machine wishes to override the units-per-bus
4346 * property of its default HBA interface type, do so now. */
4347 if (machine_class->units_per_default_bus) {
4348 override_max_devs(machine_class->block_default_type,
4349 machine_class->units_per_default_bus);
4352 /* open the virtual block devices */
4354 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
4355 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func,
4356 &machine_class->block_default_type, 1) != 0) {
4360 default_drive(default_cdrom, snapshot, machine_class->block_default_type, 2,
4362 default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS);
4363 default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS);
4365 if (qemu_opts_foreach(qemu_find_opts("numa"), numa_init_func,
4372 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
4376 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
4378 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
4380 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
4382 if (foreach_device_config(DEV_SCLP, sclp_parse) < 0) {
4385 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
4388 /* If no default VGA is requested, the default is "none". */
4390 if (machine_class->default_display) {
4391 vga_model = machine_class->default_display;
4392 } else if (cirrus_vga_available()) {
4393 vga_model = "cirrus";
4394 } else if (vga_available()) {
4399 select_vgahw(vga_model);
4403 i = select_watchdog(watchdog);
4405 exit (i == 1 ? 1 : 0);
4408 if (machine_class->compat_props) {
4409 qdev_prop_register_global_list(machine_class->compat_props);
4413 qdev_machine_init();
4415 current_machine->ram_size = ram_size;
4416 current_machine->maxram_size = maxram_size;
4417 current_machine->ram_slots = ram_slots;
4418 current_machine->boot_order = boot_order;
4419 current_machine->cpu_model = cpu_model;
4421 machine_class->init(current_machine);
4425 // TODO: Check about it...
4428 cpu_synchronize_all_post_init();
4432 if (hax_enabled()) {
4436 /* init USB devices */
4437 if (usb_enabled(false)) {
4438 if (foreach_device_config(DEV_USB, usb_parse) < 0)
4442 /* init generic devices */
4443 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
4447 // To support legacy VIGS options
4449 PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
4450 PCIDevice *pci_dev = pci_create(pci_bus, -1, "vigs");
4452 qdev_prop_set_string(&pci_dev->qdev, "backend", vigs_backend);
4454 qdev_prop_set_string(&pci_dev->qdev, "backend", "gl");
4456 qdev_prop_set_string(&pci_dev->qdev, "wsi", "wsi0");
4457 qdev_init_nofail(&pci_dev->qdev);
4461 // To support legacy YaGL options
4462 if (yagl_enabled()) {
4463 PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
4464 PCIDevice *pci_dev = pci_create(pci_bus, -1, "yagl");
4466 qdev_prop_set_string(&pci_dev->qdev, "wsi", "wsi0");
4468 qdev_init_nofail(&pci_dev->qdev);
4472 /* Did we create any drives that we failed to create a device for? */
4473 drive_check_orphaned();
4475 net_check_clients();
4477 ds = init_displaystate();
4479 /* init local displays */
4480 switch (display_type) {
4482 (void)ds; /* avoid warning if no display is configured */
4484 #if defined(CONFIG_CURSES)
4486 curses_display_init(ds, full_screen);
4489 #if defined(CONFIG_SDL)
4491 sdl_display_init(ds, full_screen, no_frame);
4493 #elif defined(CONFIG_COCOA)
4495 cocoa_display_init(ds, full_screen);
4498 #if defined(CONFIG_GTK)
4500 gtk_display_init(ds, full_screen, grab_on_hover);
4503 #if defined(CONFIG_MARU)
4504 #if defined(CONFIG_SDL) || defined(CONFIG_USE_SHM)
4507 maru_display_init(ds, display_type, full_screen);
4508 if (skin_disabled == 1) {
4509 /* do not start skin client process */
4510 set_emul_skin_enable(false);
4512 set_emul_skin_enable(true);
4522 /* must be after terminal init, SDL library changes signal handlers */
4523 os_setup_signal_handling();
4526 /* init remote displays */
4528 Error *local_err = NULL;
4529 vnc_display_init(ds);
4530 vnc_display_open(ds, vnc_display, &local_err);
4531 if (local_err != NULL) {
4532 error_report("Failed to start VNC server on `%s': %s",
4533 vnc_display, error_get_pretty(local_err));
4534 error_free(local_err);
4538 if (show_vnc_port) {
4539 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
4545 qemu_spice_display_init();
4546 #if defined(CONFIG_MARU) && defined(CONFIG_LINUX)
4547 spice_pkg_install();
4553 if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
4557 qdev_machine_creation_done();
4559 if (rom_load_all() != 0) {
4560 fprintf(stderr, "rom loading failed\n");
4564 /* TODO: once all bus devices are qdevified, this should be done
4565 * when bus is created by qdev.c */
4566 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
4567 qemu_run_machine_init_done_notifiers();
4569 /* Done notifiers can load ROMs */
4572 qemu_system_reset(VMRESET_SILENT);
4574 if (load_vmstate(loadvm) < 0) {
4579 qdev_prop_check_globals();
4580 if (vmstate_dump_file) {
4582 dump_vmstate_json_to_file(vmstate_dump_file);
4587 Error *local_err = NULL;
4588 qemu_start_incoming_migration(incoming, &local_err);
4590 error_report("-incoming %s: %s", incoming,
4591 error_get_pretty(local_err));
4592 error_free(local_err);
4595 } else if (autostart) {
4601 if (is_daemonized()) {
4602 if (!trace_init_backends(trace_events, trace_file)) {