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/emul_state.h"
136 #include "tizen/src/ui/qt5.h"
137 #include "tizen/src/util/ui_operations.h"
138 #include "tizen/src/ecs/ecs.h"
139 #include "tizen/src/util/error_handler.h"
140 # ifdef CONFIG_JAVA_UI
141 #include "tizen/src/display/maru_display.h"
145 #define DEFAULT_RAM_SIZE 128
147 #define MAX_VIRTIO_CONSOLES 1
148 #define MAX_SCLP_CONSOLES 1
150 static const char *data_dir[16];
151 static int data_dir_idx;
152 const char *bios_name = NULL;
153 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
154 DisplayType display_type = DT_DEFAULT;
155 static int display_remote;
156 const char* keyboard_layout = NULL;
158 const char *mem_path = NULL;
159 int mem_prealloc = 0; /* force preallocation of physical target memory */
160 bool enable_mlock = false;
162 NICInfo nd_table[MAX_NICS];
164 static int rtc_utc = 1;
165 static int rtc_date_offset = -1; /* -1 means no change */
166 QEMUClockType rtc_clock;
167 int vga_interface_type = VGA_NONE;
168 static int full_screen = 0;
169 static int no_frame = 0;
172 static bool grab_on_hover;
174 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
175 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
176 CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
177 CharDriverState *sclp_hds[MAX_SCLP_CONSOLES];
178 int win2k_install_hack = 0;
185 const char *vnc_display;
187 int acpi_enabled = 1;
190 static int no_reboot;
193 int graphic_rotate = 0;
194 const char *watchdog;
195 QEMUOptionRom option_rom[MAX_OPTION_ROMS];
197 int semihosting_enabled = 0;
199 const char *qemu_name;
202 unsigned int nb_prom_envs = 0;
203 const char *prom_envs[MAX_PROM_ENVS];
206 uint8_t *boot_splash_filedata;
207 size_t boot_splash_filedata_size;
208 uint8_t qemu_extra_params_fw[2];
210 int icount_align_option;
214 NodeInfo numa_info[MAX_NODES];
216 /* The bytes in qemu_uuid[] are in the order specified by RFC4122, _not_ in the
217 * little-endian "wire format" described in the SMBIOS 2.6 specification.
219 uint8_t qemu_uuid[16];
222 static QEMUBootSetHandler *boot_set_handler;
223 static void *boot_set_opaque;
225 static NotifierList exit_notifiers =
226 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
228 static NotifierList machine_init_done_notifiers =
229 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
233 enum xen_mode xen_mode = XEN_EMULATE;
235 static int has_defaults = 1;
236 static int default_serial = 1;
237 static int default_parallel = 1;
238 static int default_virtcon = 1;
239 static int default_sclp = 1;
240 static int default_monitor = 1;
241 static int default_floppy = 1;
242 static int default_cdrom = 1;
243 static int default_sdcard = 1;
244 static int default_vga = 1;
250 { .driver = "isa-serial", .flag = &default_serial },
251 { .driver = "isa-parallel", .flag = &default_parallel },
252 { .driver = "isa-fdc", .flag = &default_floppy },
253 { .driver = "ide-cd", .flag = &default_cdrom },
254 { .driver = "ide-hd", .flag = &default_cdrom },
255 { .driver = "ide-drive", .flag = &default_cdrom },
256 { .driver = "scsi-cd", .flag = &default_cdrom },
257 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
258 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
259 { .driver = "virtio-serial", .flag = &default_virtcon },
260 { .driver = "VGA", .flag = &default_vga },
261 { .driver = "isa-vga", .flag = &default_vga },
262 { .driver = "cirrus-vga", .flag = &default_vga },
263 { .driver = "isa-cirrus-vga", .flag = &default_vga },
264 { .driver = "vmware-svga", .flag = &default_vga },
265 { .driver = "qxl-vga", .flag = &default_vga },
268 static QemuOptsList qemu_rtc_opts = {
270 .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head),
274 .type = QEMU_OPT_STRING,
277 .type = QEMU_OPT_STRING,
280 .type = QEMU_OPT_STRING,
282 { /* end of list */ }
286 static QemuOptsList qemu_sandbox_opts = {
288 .implied_opt_name = "enable",
289 .head = QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts.head),
293 .type = QEMU_OPT_BOOL,
295 { /* end of list */ }
299 static QemuOptsList qemu_trace_opts = {
301 .implied_opt_name = "trace",
302 .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
306 .type = QEMU_OPT_STRING,
309 .type = QEMU_OPT_STRING,
311 { /* end of list */ }
315 static QemuOptsList qemu_option_rom_opts = {
316 .name = "option-rom",
317 .implied_opt_name = "romfile",
318 .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head),
322 .type = QEMU_OPT_NUMBER,
325 .type = QEMU_OPT_STRING,
327 { /* end of list */ }
331 static QemuOptsList qemu_machine_opts = {
333 .implied_opt_name = "type",
335 .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
339 .type = QEMU_OPT_STRING,
340 .help = "emulated machine"
343 .type = QEMU_OPT_STRING,
344 .help = "accelerator list",
346 .name = "kernel_irqchip",
347 .type = QEMU_OPT_BOOL,
348 .help = "use KVM in-kernel irqchip",
350 .name = "kvm_shadow_mem",
351 .type = QEMU_OPT_SIZE,
352 .help = "KVM shadow MMU size",
355 .type = QEMU_OPT_STRING,
356 .help = "Linux kernel image file",
359 .type = QEMU_OPT_STRING,
360 .help = "Linux initial ramdisk file",
363 .type = QEMU_OPT_STRING,
364 .help = "Linux kernel command line",
367 .type = QEMU_OPT_STRING,
368 .help = "Linux kernel device tree file",
371 .type = QEMU_OPT_STRING,
372 .help = "Dump current dtb to a file and quit",
374 .name = "phandle_start",
375 .type = QEMU_OPT_NUMBER,
376 .help = "The first phandle ID we may generate dynamically",
378 .name = "dt_compatible",
379 .type = QEMU_OPT_STRING,
380 .help = "Overrides the \"compatible\" property of the dt root node",
382 .name = "dump-guest-core",
383 .type = QEMU_OPT_BOOL,
384 .help = "Include guest memory in a core dump",
387 .type = QEMU_OPT_BOOL,
388 .help = "enable/disable memory merge support",
391 .type = QEMU_OPT_BOOL,
392 .help = "Set on/off to enable/disable usb",
395 .type = QEMU_OPT_STRING,
396 .help = "firmware image",
399 .type = QEMU_OPT_STRING,
400 .help = "Specifies the KVM virtualization mode (HV, PR)",
402 .name = PC_MACHINE_MAX_RAM_BELOW_4G,
403 .type = QEMU_OPT_SIZE,
404 .help = "maximum ram below the 4G boundary (32bit boundary)",
406 .name = PC_MACHINE_VMPORT,
407 .type = QEMU_OPT_STRING,
408 .help = "Enable vmport (pc & q35)",
411 .type = QEMU_OPT_BOOL,
412 .help = "Set on/off to enable/disable Intel IOMMU (VT-d)",
414 { /* End of list */ }
418 static QemuOptsList qemu_boot_opts = {
420 .implied_opt_name = "order",
422 .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head),
426 .type = QEMU_OPT_STRING,
429 .type = QEMU_OPT_STRING,
432 .type = QEMU_OPT_BOOL,
435 .type = QEMU_OPT_STRING,
437 .name = "splash-time",
438 .type = QEMU_OPT_STRING,
440 .name = "reboot-timeout",
441 .type = QEMU_OPT_STRING,
444 .type = QEMU_OPT_BOOL,
450 static QemuOptsList qemu_add_fd_opts = {
452 .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head),
456 .type = QEMU_OPT_NUMBER,
457 .help = "file descriptor of which a duplicate is added to fd set",
460 .type = QEMU_OPT_NUMBER,
461 .help = "ID of the fd set to add fd to",
464 .type = QEMU_OPT_STRING,
465 .help = "free-form string used to describe fd",
467 { /* end of list */ }
471 static QemuOptsList qemu_object_opts = {
473 .implied_opt_name = "qom-type",
474 .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
480 static QemuOptsList qemu_tpmdev_opts = {
482 .implied_opt_name = "type",
483 .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head),
485 /* options are defined in the TPM backends */
486 { /* end of list */ }
490 static QemuOptsList qemu_realtime_opts = {
492 .head = QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts.head),
496 .type = QEMU_OPT_BOOL,
498 { /* end of list */ }
502 static QemuOptsList qemu_msg_opts = {
504 .head = QTAILQ_HEAD_INITIALIZER(qemu_msg_opts.head),
508 .type = QEMU_OPT_BOOL,
510 { /* end of list */ }
514 static QemuOptsList qemu_name_opts = {
516 .implied_opt_name = "guest",
518 .head = QTAILQ_HEAD_INITIALIZER(qemu_name_opts.head),
522 .type = QEMU_OPT_STRING,
523 .help = "Sets the name of the guest.\n"
524 "This name will be displayed in the SDL window caption.\n"
525 "The name will also be used for the VNC server",
528 .type = QEMU_OPT_STRING,
529 .help = "Sets the name of the QEMU process, as shown in top etc",
531 .name = "debug-threads",
532 .type = QEMU_OPT_BOOL,
533 .help = "When enabled, name the individual threads; defaults off.\n"
534 "NOTE: The thread names are for debugging and not a\n"
537 { /* End of list */ }
541 static QemuOptsList qemu_mem_opts = {
543 .implied_opt_name = "size",
544 .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head),
549 .type = QEMU_OPT_SIZE,
553 .type = QEMU_OPT_NUMBER,
557 .type = QEMU_OPT_SIZE,
559 { /* end of list */ }
563 static QemuOptsList qemu_icount_opts = {
565 .implied_opt_name = "shift",
567 .head = QTAILQ_HEAD_INITIALIZER(qemu_icount_opts.head),
571 .type = QEMU_OPT_STRING,
574 .type = QEMU_OPT_BOOL,
576 { /* end of list */ }
581 * Get machine options
583 * Returns: machine options (never null).
585 QemuOpts *qemu_get_machine_opts(void)
587 return qemu_find_opts_singleton("machine");
590 const char *qemu_get_vm_name(void)
595 static void res_free(void)
597 if (boot_splash_filedata != NULL) {
598 g_free(boot_splash_filedata);
599 boot_splash_filedata = NULL;
603 static int default_driver_check(QemuOpts *opts, void *opaque)
605 const char *driver = qemu_opt_get(opts, "driver");
610 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
611 if (strcmp(default_list[i].driver, driver) != 0)
613 *(default_list[i].flag) = 0;
618 /***********************************************************/
621 static RunState current_run_state = RUN_STATE_PRELAUNCH;
623 /* We use RUN_STATE_MAX but any invalid value will do */
624 static RunState vmstop_requested = RUN_STATE_MAX;
625 static QemuMutex vmstop_lock;
630 } RunStateTransition;
632 static const RunStateTransition runstate_transitions_def[] = {
634 { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
635 { RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE },
637 { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },
638 { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED },
640 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
641 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
643 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
644 { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE },
646 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
647 { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
649 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
650 { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
652 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
653 { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
654 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
656 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
657 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
659 { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
661 { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
662 { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
663 { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
664 { RUN_STATE_RUNNING, RUN_STATE_PAUSED },
665 { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE },
666 { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM },
667 { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM },
668 { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
669 { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
670 { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED },
672 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
674 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
675 { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
677 { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
678 { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
679 { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },
680 { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
682 { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
683 { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
685 { RUN_STATE_GUEST_PANICKED, RUN_STATE_RUNNING },
686 { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE },
688 { RUN_STATE_MAX, RUN_STATE_MAX },
691 static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX];
693 bool runstate_check(RunState state)
695 return current_run_state == state;
698 static void runstate_init(void)
700 const RunStateTransition *p;
702 memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions));
703 for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) {
704 runstate_valid_transitions[p->from][p->to] = true;
707 qemu_mutex_init(&vmstop_lock);
710 /* This function will abort() on invalid state transitions */
711 void runstate_set(RunState new_state)
713 assert(new_state < RUN_STATE_MAX);
715 if (!runstate_valid_transitions[current_run_state][new_state]) {
716 fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
717 RunState_lookup[current_run_state],
718 RunState_lookup[new_state]);
721 trace_runstate_set(new_state);
722 current_run_state = new_state;
725 int runstate_is_running(void)
727 return runstate_check(RUN_STATE_RUNNING);
730 bool runstate_needs_reset(void)
732 return runstate_check(RUN_STATE_INTERNAL_ERROR) ||
733 runstate_check(RUN_STATE_SHUTDOWN);
736 StatusInfo *qmp_query_status(Error **errp)
738 StatusInfo *info = g_malloc0(sizeof(*info));
740 info->running = runstate_is_running();
741 info->singlestep = singlestep;
742 info->status = current_run_state;
747 static bool qemu_vmstop_requested(RunState *r)
749 qemu_mutex_lock(&vmstop_lock);
750 *r = vmstop_requested;
751 vmstop_requested = RUN_STATE_MAX;
752 qemu_mutex_unlock(&vmstop_lock);
753 return *r < RUN_STATE_MAX;
756 void qemu_system_vmstop_request_prepare(void)
758 qemu_mutex_lock(&vmstop_lock);
761 void qemu_system_vmstop_request(RunState state)
763 vmstop_requested = state;
764 qemu_mutex_unlock(&vmstop_lock);
772 qemu_vmstop_requested(&requested);
773 if (runstate_is_running() && requested == RUN_STATE_MAX) {
777 /* Ensure that a STOP/RESUME pair of events is emitted if a
778 * vmstop request was pending. The BLOCK_IO_ERROR event, for
779 * example, according to documentation is always followed by
782 if (runstate_is_running()) {
783 qapi_event_send_stop(&error_abort);
786 runstate_set(RUN_STATE_RUNNING);
787 vm_state_notify(1, RUN_STATE_RUNNING);
791 qapi_event_send_resume(&error_abort);
795 /***********************************************************/
796 /* real time host monotonic timer */
798 /***********************************************************/
799 /* host time/date access */
800 void qemu_get_timedate(struct tm *tm, int offset)
806 if (rtc_date_offset == -1) {
810 localtime_r(&ti, tm);
812 ti -= rtc_date_offset;
817 int qemu_timedate_diff(struct tm *tm)
821 if (rtc_date_offset == -1)
823 seconds = mktimegm(tm);
826 tmp.tm_isdst = -1; /* use timezone to figure it out */
827 seconds = mktime(&tmp);
830 seconds = mktimegm(tm) + rtc_date_offset;
832 return seconds - time(NULL);
835 static void configure_rtc_date_offset(const char *startdate, int legacy)
837 time_t rtc_start_date;
840 if (!strcmp(startdate, "now") && legacy) {
841 rtc_date_offset = -1;
843 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
851 } else if (sscanf(startdate, "%d-%d-%d",
863 rtc_start_date = mktimegm(&tm);
864 if (rtc_start_date == -1) {
866 fprintf(stderr, "Invalid date format. Valid formats are:\n"
867 "'2006-06-17T16:01:21' or '2006-06-17'\n");
870 rtc_date_offset = time(NULL) - rtc_start_date;
874 static void configure_rtc(QemuOpts *opts)
878 value = qemu_opt_get(opts, "base");
880 if (!strcmp(value, "utc")) {
882 } else if (!strcmp(value, "localtime")) {
885 configure_rtc_date_offset(value, 0);
888 value = qemu_opt_get(opts, "clock");
890 if (!strcmp(value, "host")) {
891 rtc_clock = QEMU_CLOCK_HOST;
892 } else if (!strcmp(value, "rt")) {
893 rtc_clock = QEMU_CLOCK_REALTIME;
894 } else if (!strcmp(value, "vm")) {
895 rtc_clock = QEMU_CLOCK_VIRTUAL;
897 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
901 value = qemu_opt_get(opts, "driftfix");
903 if (!strcmp(value, "slew")) {
904 static GlobalProperty slew_lost_ticks[] = {
906 .driver = "mc146818rtc",
907 .property = "lost_tick_policy",
910 { /* end of list */ }
913 qdev_prop_register_global_list(slew_lost_ticks);
914 } else if (!strcmp(value, "none")) {
915 /* discard is default */
917 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
923 /***********************************************************/
924 /* Bluetooth support */
927 static struct HCIInfo *hci_table[MAX_NICS];
929 struct HCIInfo *qemu_next_hci(void)
931 if (cur_hci == nb_hcis)
934 return hci_table[cur_hci++];
937 static int bt_hci_parse(const char *str)
942 if (nb_hcis >= MAX_NICS) {
943 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
956 bdaddr.b[5] = 0x56 + nb_hcis;
957 hci->bdaddr_set(hci, bdaddr.b);
959 hci_table[nb_hcis++] = hci;
964 static void bt_vhci_add(int vlan_id)
966 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
969 fprintf(stderr, "qemu: warning: adding a VHCI to "
970 "an empty scatternet %i\n", vlan_id);
972 bt_vhci_init(bt_new_hci(vlan));
975 static struct bt_device_s *bt_device_add(const char *opt)
977 struct bt_scatternet_s *vlan;
979 char *endp = strstr(opt, ",vlan=");
980 int len = (endp ? endp - opt : strlen(opt)) + 1;
983 pstrcpy(devname, MIN(sizeof(devname), len), opt);
986 vlan_id = strtol(endp + 6, &endp, 0);
988 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
993 vlan = qemu_find_bt_vlan(vlan_id);
996 fprintf(stderr, "qemu: warning: adding a slave device to "
997 "an empty scatternet %i\n", vlan_id);
999 if (!strcmp(devname, "keyboard"))
1000 return bt_keyboard_init(vlan);
1002 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
1006 static int bt_parse(const char *opt)
1008 const char *endp, *p;
1011 if (strstart(opt, "hci", &endp)) {
1012 if (!*endp || *endp == ',') {
1014 if (!strstart(endp, ",vlan=", 0))
1017 return bt_hci_parse(opt);
1019 } else if (strstart(opt, "vhci", &endp)) {
1020 if (!*endp || *endp == ',') {
1022 if (strstart(endp, ",vlan=", &p)) {
1023 vlan = strtol(p, (char **) &endp, 0);
1025 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
1029 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
1038 } else if (strstart(opt, "device:", &endp))
1039 return !bt_device_add(endp);
1041 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
1045 static int parse_sandbox(QemuOpts *opts, void *opaque)
1047 /* FIXME: change this to true for 1.3 */
1048 if (qemu_opt_get_bool(opts, "enable", false)) {
1049 #ifdef CONFIG_SECCOMP
1050 if (seccomp_start() < 0) {
1051 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1052 "failed to install seccomp syscall filter in the kernel");
1056 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1057 "sandboxing request but seccomp is not compiled into this build");
1065 static int parse_name(QemuOpts *opts, void *opaque)
1067 const char *proc_name;
1069 if (qemu_opt_get(opts, "debug-threads")) {
1070 qemu_thread_naming(qemu_opt_get_bool(opts, "debug-threads", false));
1072 qemu_name = qemu_opt_get(opts, "guest");
1074 proc_name = qemu_opt_get(opts, "process");
1076 os_set_proc_name(proc_name);
1082 bool usb_enabled(bool default_usb)
1084 return qemu_opt_get_bool(qemu_get_machine_opts(), "usb",
1085 has_defaults && default_usb);
1089 static int parse_add_fd(QemuOpts *opts, void *opaque)
1091 int fd, dupfd, flags;
1093 const char *fd_opaque = NULL;
1095 fd = qemu_opt_get_number(opts, "fd", -1);
1096 fdset_id = qemu_opt_get_number(opts, "set", -1);
1097 fd_opaque = qemu_opt_get(opts, "opaque");
1100 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1101 "fd option is required and must be non-negative");
1105 if (fd <= STDERR_FILENO) {
1106 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1107 "fd cannot be a standard I/O stream");
1112 * All fds inherited across exec() necessarily have FD_CLOEXEC
1113 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1115 flags = fcntl(fd, F_GETFD);
1116 if (flags == -1 || (flags & FD_CLOEXEC)) {
1117 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1118 "fd is not valid or already in use");
1123 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1124 "set option is required and must be non-negative");
1128 #ifdef F_DUPFD_CLOEXEC
1129 dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
1133 qemu_set_cloexec(dupfd);
1137 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1138 "Error duplicating fd: %s", strerror(errno));
1142 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1143 monitor_fdset_add_fd(dupfd, true, fdset_id, fd_opaque ? true : false,
1149 static int cleanup_add_fd(QemuOpts *opts, void *opaque)
1153 fd = qemu_opt_get_number(opts, "fd", -1);
1160 /***********************************************************/
1161 /* QEMU Block devices */
1163 #define HD_OPTS "media=disk"
1164 #define CDROM_OPTS "media=cdrom"
1166 #define PFLASH_OPTS ""
1170 static int drive_init_func(QemuOpts *opts, void *opaque)
1172 BlockInterfaceType *block_default_type = opaque;
1174 return drive_new(opts, *block_default_type) == NULL;
1177 static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
1179 if (qemu_opt_get(opts, "snapshot") == NULL) {
1180 qemu_opt_set(opts, "snapshot", "on");
1185 static void default_drive(int enable, int snapshot, BlockInterfaceType type,
1186 int index, const char *optstr)
1191 if (!enable || drive_get_by_index(type, index)) {
1195 opts = drive_add(type, index, NULL, optstr);
1197 drive_enable_snapshot(opts, NULL);
1200 dinfo = drive_new(opts, type);
1204 dinfo->is_default = true;
1208 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
1210 boot_set_handler = func;
1211 boot_set_opaque = opaque;
1214 int qemu_boot_set(const char *boot_order)
1216 if (!boot_set_handler) {
1219 return boot_set_handler(boot_set_opaque, boot_order);
1222 static void validate_bootdevices(const char *devices)
1224 /* We just do some generic consistency checks */
1228 for (p = devices; *p != '\0'; p++) {
1229 /* Allowed boot devices are:
1230 * a-b: floppy disk drives
1231 * c-f: IDE disk drives
1232 * g-m: machine implementation dependent drives
1233 * n-p: network devices
1234 * It's up to each machine implementation to check if the given boot
1235 * devices match the actual hardware implementation and firmware
1238 if (*p < 'a' || *p > 'p') {
1239 fprintf(stderr, "Invalid boot device '%c'\n", *p);
1242 if (bitmap & (1 << (*p - 'a'))) {
1243 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
1246 bitmap |= 1 << (*p - 'a');
1250 static void restore_boot_order(void *opaque)
1252 char *normal_boot_order = opaque;
1253 static int first = 1;
1255 /* Restore boot order and remove ourselves after the first boot */
1261 qemu_boot_set(normal_boot_order);
1263 qemu_unregister_reset(restore_boot_order, normal_boot_order);
1264 g_free(normal_boot_order);
1267 static QemuOptsList qemu_smp_opts = {
1269 .implied_opt_name = "cpus",
1270 .merge_lists = true,
1271 .head = QTAILQ_HEAD_INITIALIZER(qemu_smp_opts.head),
1275 .type = QEMU_OPT_NUMBER,
1278 .type = QEMU_OPT_NUMBER,
1281 .type = QEMU_OPT_NUMBER,
1284 .type = QEMU_OPT_NUMBER,
1287 .type = QEMU_OPT_NUMBER,
1289 { /*End of list */ }
1293 static void smp_parse(QemuOpts *opts)
1297 unsigned cpus = qemu_opt_get_number(opts, "cpus", 0);
1298 unsigned sockets = qemu_opt_get_number(opts, "sockets", 0);
1299 unsigned cores = qemu_opt_get_number(opts, "cores", 0);
1300 unsigned threads = qemu_opt_get_number(opts, "threads", 0);
1302 /* compute missing values, prefer sockets over cores over threads */
1303 if (cpus == 0 || sockets == 0) {
1304 sockets = sockets > 0 ? sockets : 1;
1305 cores = cores > 0 ? cores : 1;
1306 threads = threads > 0 ? threads : 1;
1308 cpus = cores * threads * sockets;
1312 threads = threads > 0 ? threads : 1;
1313 cores = cpus / (sockets * threads);
1315 threads = cpus / (cores * sockets);
1319 max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
1322 smp_cores = cores > 0 ? cores : 1;
1323 smp_threads = threads > 0 ? threads : 1;
1327 if (max_cpus == 0) {
1328 max_cpus = smp_cpus;
1331 if (max_cpus > MAX_CPUMASK_BITS) {
1332 fprintf(stderr, "Unsupported number of maxcpus\n");
1335 if (max_cpus < smp_cpus) {
1336 fprintf(stderr, "maxcpus must be equal to or greater than smp\n");
1342 static void realtime_init(void)
1345 if (os_mlock() < 0) {
1346 fprintf(stderr, "qemu: locking memory failed\n");
1353 static void configure_msg(QemuOpts *opts)
1355 enable_timestamp_msg = qemu_opt_get_bool(opts, "timestamp", true);
1358 /***********************************************************/
1361 static int usb_device_add(const char *devname)
1363 USBDevice *dev = NULL;
1364 #ifndef CONFIG_LINUX
1368 if (!usb_enabled(false)) {
1372 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1373 dev = usbdevice_create(devname);
1377 /* the other ones */
1378 #ifndef CONFIG_LINUX
1379 /* only the linux version is qdev-ified, usb-bsd still needs this */
1380 if (strstart(devname, "host:", &p)) {
1381 dev = usb_host_device_open(usb_bus_find(-1), p);
1391 static int usb_device_del(const char *devname)
1396 if (strstart(devname, "host:", &p)) {
1400 if (!usb_enabled(false)) {
1404 p = strchr(devname, '.');
1407 bus_num = strtoul(devname, NULL, 0);
1408 addr = strtoul(p + 1, NULL, 0);
1410 return usb_device_delete_addr(bus_num, addr);
1413 static int usb_parse(const char *cmdline)
1416 r = usb_device_add(cmdline);
1418 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
1423 void do_usb_add(Monitor *mon, const QDict *qdict)
1425 const char *devname = qdict_get_str(qdict, "devname");
1426 if (usb_device_add(devname) < 0) {
1427 error_report("could not add USB device '%s'", devname);
1431 void do_usb_del(Monitor *mon, const QDict *qdict)
1433 const char *devname = qdict_get_str(qdict, "devname");
1434 if (usb_device_del(devname) < 0) {
1435 error_report("could not delete USB device '%s'", devname);
1439 /***********************************************************/
1440 /* machine registration */
1442 MachineState *current_machine;
1444 static void machine_class_init(ObjectClass *oc, void *data)
1446 MachineClass *mc = MACHINE_CLASS(oc);
1447 QEMUMachine *qm = data;
1449 mc->family = qm->family;
1450 mc->name = qm->name;
1451 mc->alias = qm->alias;
1452 mc->desc = qm->desc;
1453 mc->init = qm->init;
1454 mc->reset = qm->reset;
1455 mc->hot_add_cpu = qm->hot_add_cpu;
1456 mc->kvm_type = qm->kvm_type;
1457 mc->block_default_type = qm->block_default_type;
1458 mc->units_per_default_bus = qm->units_per_default_bus;
1459 mc->max_cpus = qm->max_cpus;
1460 mc->no_serial = qm->no_serial;
1461 mc->no_parallel = qm->no_parallel;
1462 mc->use_virtcon = qm->use_virtcon;
1463 mc->use_sclp = qm->use_sclp;
1464 mc->no_floppy = qm->no_floppy;
1465 mc->no_cdrom = qm->no_cdrom;
1466 mc->no_sdcard = qm->no_sdcard;
1467 mc->has_dynamic_sysbus = qm->has_dynamic_sysbus;
1468 mc->is_default = qm->is_default;
1469 mc->default_machine_opts = qm->default_machine_opts;
1470 mc->default_boot_order = qm->default_boot_order;
1471 mc->default_display = qm->default_display;
1472 mc->compat_props = qm->compat_props;
1473 mc->hw_version = qm->hw_version;
1476 int qemu_register_machine(QEMUMachine *m)
1478 char *name = g_strconcat(m->name, TYPE_MACHINE_SUFFIX, NULL);
1481 .parent = TYPE_MACHINE,
1482 .class_init = machine_class_init,
1483 .class_data = (void *)m,
1492 static MachineClass *find_machine(const char *name)
1494 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1495 MachineClass *mc = NULL;
1497 for (el = machines; el; el = el->next) {
1498 MachineClass *temp = el->data;
1500 if (!strcmp(temp->name, name)) {
1505 !strcmp(temp->alias, name)) {
1511 g_slist_free(machines);
1515 MachineClass *find_default_machine(void)
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 (temp->is_default) {
1529 g_slist_free(machines);
1533 MachineInfoList *qmp_query_machines(Error **errp)
1535 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1536 MachineInfoList *mach_list = NULL;
1538 for (el = machines; el; el = el->next) {
1539 MachineClass *mc = el->data;
1540 MachineInfoList *entry;
1543 info = g_malloc0(sizeof(*info));
1544 if (mc->is_default) {
1545 info->has_is_default = true;
1546 info->is_default = true;
1550 info->has_alias = true;
1551 info->alias = g_strdup(mc->alias);
1554 info->name = g_strdup(mc->name);
1555 info->cpu_max = !mc->max_cpus ? 1 : mc->max_cpus;
1557 entry = g_malloc0(sizeof(*entry));
1558 entry->value = info;
1559 entry->next = mach_list;
1563 g_slist_free(machines);
1567 /***********************************************************/
1568 /* main execution loop */
1570 struct vm_change_state_entry {
1571 VMChangeStateHandler *cb;
1573 QLIST_ENTRY (vm_change_state_entry) entries;
1576 static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
1578 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1581 VMChangeStateEntry *e;
1583 e = g_malloc0(sizeof (*e));
1587 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
1591 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1593 QLIST_REMOVE (e, entries);
1597 void vm_state_notify(int running, RunState state)
1599 VMChangeStateEntry *e, *next;
1601 trace_vm_state_notify(running, state);
1603 QLIST_FOREACH_SAFE(e, &vm_change_state_head, entries, next) {
1604 e->cb(e->opaque, running, state);
1608 /* reset/shutdown handler */
1610 typedef struct QEMUResetEntry {
1611 QTAILQ_ENTRY(QEMUResetEntry) entry;
1612 QEMUResetHandler *func;
1616 static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1617 QTAILQ_HEAD_INITIALIZER(reset_handlers);
1618 static int reset_requested;
1619 static int shutdown_requested, shutdown_signal = -1;
1620 static pid_t shutdown_pid;
1621 static int powerdown_requested;
1622 static int debug_requested;
1623 static int suspend_requested;
1624 static WakeupReason wakeup_reason;
1625 static NotifierList powerdown_notifiers =
1626 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
1627 static NotifierList suspend_notifiers =
1628 NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
1629 static NotifierList wakeup_notifiers =
1630 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
1631 static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE);
1633 int qemu_shutdown_requested_get(void)
1635 return shutdown_requested;
1638 int qemu_reset_requested_get(void)
1640 return reset_requested;
1643 static int qemu_shutdown_requested(void)
1645 return atomic_xchg(&shutdown_requested, 0);
1648 static void qemu_kill_report(void)
1650 if (!qtest_driver() && shutdown_signal != -1) {
1651 fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal);
1652 if (shutdown_pid == 0) {
1653 /* This happens for eg ^C at the terminal, so it's worth
1654 * avoiding printing an odd message in that case.
1656 fputc('\n', stderr);
1658 fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid);
1660 shutdown_signal = -1;
1664 static int qemu_reset_requested(void)
1666 int r = reset_requested;
1667 reset_requested = 0;
1671 static int qemu_suspend_requested(void)
1673 int r = suspend_requested;
1674 suspend_requested = 0;
1678 static WakeupReason qemu_wakeup_requested(void)
1680 return wakeup_reason;
1683 static int qemu_powerdown_requested(void)
1685 int r = powerdown_requested;
1686 powerdown_requested = 0;
1690 static int qemu_debug_requested(void)
1692 int r = debug_requested;
1693 debug_requested = 0;
1697 void qemu_register_reset(QEMUResetHandler *func, void *opaque)
1699 QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
1702 re->opaque = opaque;
1703 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
1706 void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
1710 QTAILQ_FOREACH(re, &reset_handlers, entry) {
1711 if (re->func == func && re->opaque == opaque) {
1712 QTAILQ_REMOVE(&reset_handlers, re, entry);
1719 void qemu_devices_reset(void)
1721 QEMUResetEntry *re, *nre;
1723 /* reset all devices */
1724 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
1725 re->func(re->opaque);
1729 void qemu_system_reset(bool report)
1733 mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL;
1735 if (mc && mc->reset) {
1738 qemu_devices_reset();
1741 qapi_event_send_reset(&error_abort);
1743 cpu_synchronize_all_post_reset();
1746 void qemu_system_reset_request(void)
1749 shutdown_requested = 1;
1751 reset_requested = 1;
1754 qemu_notify_event();
1757 static void qemu_system_suspend(void)
1760 notifier_list_notify(&suspend_notifiers, NULL);
1761 runstate_set(RUN_STATE_SUSPENDED);
1762 qapi_event_send_suspend(&error_abort);
1765 void qemu_system_suspend_request(void)
1767 if (runstate_check(RUN_STATE_SUSPENDED)) {
1770 suspend_requested = 1;
1772 qemu_notify_event();
1775 void qemu_register_suspend_notifier(Notifier *notifier)
1777 notifier_list_add(&suspend_notifiers, notifier);
1780 void qemu_system_wakeup_request(WakeupReason reason)
1782 trace_system_wakeup_request(reason);
1784 if (!runstate_check(RUN_STATE_SUSPENDED)) {
1787 if (!(wakeup_reason_mask & (1 << reason))) {
1790 runstate_set(RUN_STATE_RUNNING);
1791 wakeup_reason = reason;
1792 qemu_notify_event();
1795 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
1798 wakeup_reason_mask |= (1 << reason);
1800 wakeup_reason_mask &= ~(1 << reason);
1804 void qemu_register_wakeup_notifier(Notifier *notifier)
1806 notifier_list_add(&wakeup_notifiers, notifier);
1809 void qemu_system_killed(int signal, pid_t pid)
1811 shutdown_signal = signal;
1816 qemu_system_graceful_shutdown_request(TIMEOUT_FOR_SHUTDOWN);
1818 qemu_system_shutdown_request();
1822 void qemu_system_shutdown_request(void)
1824 trace_qemu_system_shutdown_request();
1825 shutdown_requested = 1;
1826 qemu_notify_event();
1829 static void qemu_system_powerdown(void)
1831 qapi_event_send_powerdown(&error_abort);
1832 notifier_list_notify(&powerdown_notifiers, NULL);
1835 void qemu_system_powerdown_request(void)
1837 trace_qemu_system_powerdown_request();
1838 powerdown_requested = 1;
1839 qemu_notify_event();
1842 void qemu_register_powerdown_notifier(Notifier *notifier)
1844 notifier_list_add(&powerdown_notifiers, notifier);
1847 void qemu_system_debug_request(void)
1849 debug_requested = 1;
1850 qemu_notify_event();
1853 static bool main_loop_should_exit(void)
1856 if (qemu_debug_requested()) {
1857 vm_stop(RUN_STATE_DEBUG);
1859 if (qemu_suspend_requested()) {
1860 qemu_system_suspend();
1862 if (qemu_shutdown_requested()) {
1864 qapi_event_send_shutdown(&error_abort);
1866 vm_stop(RUN_STATE_SHUTDOWN);
1871 if (qemu_reset_requested()) {
1873 cpu_synchronize_all_states();
1874 qemu_system_reset(VMRESET_REPORT);
1876 if (runstate_needs_reset()) {
1877 runstate_set(RUN_STATE_PAUSED);
1880 if (qemu_wakeup_requested()) {
1882 cpu_synchronize_all_states();
1883 qemu_system_reset(VMRESET_SILENT);
1884 notifier_list_notify(&wakeup_notifiers, &wakeup_reason);
1885 wakeup_reason = QEMU_WAKEUP_REASON_NONE;
1887 qapi_event_send_wakeup(&error_abort);
1889 if (qemu_powerdown_requested()) {
1890 qemu_system_powerdown();
1892 if (qemu_vmstop_requested(&r)) {
1898 static void main_loop(void)
1902 #ifdef CONFIG_PROFILER
1909 nonblocking = !kvm_enabled() && !xen_enabled() && !hax_enabled() && last_io > 0;
1910 #ifdef CONFIG_PROFILER
1911 ti = profile_getclock();
1913 last_io = main_loop_wait(nonblocking);
1914 #ifdef CONFIG_PROFILER
1915 dev_time += profile_getclock() - ti;
1917 } while (!main_loop_should_exit());
1920 static void version(void)
1922 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
1925 static void help(int exitcode)
1928 printf("usage: %s [options] [disk_image]\n\n"
1929 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1930 error_get_progname());
1932 #define QEMU_OPTIONS_GENERATE_HELP
1933 #include "qemu-options-wrapper.h"
1935 printf("\nDuring emulation, the following keys are useful:\n"
1936 "ctrl-alt-f toggle full screen\n"
1937 "ctrl-alt-n switch to virtual console 'n'\n"
1938 "ctrl-alt toggle mouse and keyboard grab\n"
1940 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1945 #define HAS_ARG 0x0001
1947 typedef struct QEMUOption {
1954 static const QEMUOption qemu_options[] = {
1955 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1956 #define QEMU_OPTIONS_GENERATE_OPTIONS
1957 #include "qemu-options-wrapper.h"
1961 static bool vga_available(void)
1963 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
1966 static bool cirrus_vga_available(void)
1968 return object_class_by_name("cirrus-vga")
1969 || object_class_by_name("isa-cirrus-vga");
1972 static bool vmware_vga_available(void)
1974 return object_class_by_name("vmware-svga");
1977 static bool qxl_vga_available(void)
1979 return object_class_by_name("qxl-vga");
1982 static bool tcx_vga_available(void)
1984 return object_class_by_name("SUNW,tcx");
1987 static bool cg3_vga_available(void)
1989 return object_class_by_name("cgthree");
1992 static void select_vgahw (const char *p)
1996 assert(vga_interface_type == VGA_NONE);
1997 if (strstart(p, "std", &opts)) {
1998 if (vga_available()) {
1999 vga_interface_type = VGA_STD;
2001 fprintf(stderr, "Error: standard VGA not available\n");
2004 } else if (strstart(p, "cirrus", &opts)) {
2005 if (cirrus_vga_available()) {
2006 vga_interface_type = VGA_CIRRUS;
2008 fprintf(stderr, "Error: Cirrus VGA not available\n");
2011 } else if (strstart(p, "vmware", &opts)) {
2012 if (vmware_vga_available()) {
2013 vga_interface_type = VGA_VMWARE;
2015 fprintf(stderr, "Error: VMWare SVGA not available\n");
2018 } else if (strstart(p, "xenfb", &opts)) {
2019 vga_interface_type = VGA_XENFB;
2020 } else if (strstart(p, "qxl", &opts)) {
2021 if (qxl_vga_available()) {
2022 vga_interface_type = VGA_QXL;
2024 fprintf(stderr, "Error: QXL VGA not available\n");
2027 } else if (strstart(p, "tcx", &opts)) {
2028 if (tcx_vga_available()) {
2029 vga_interface_type = VGA_TCX;
2031 fprintf(stderr, "Error: TCX framebuffer not available\n");
2034 } else if (strstart(p, "cg3", &opts)) {
2035 if (cg3_vga_available()) {
2036 vga_interface_type = VGA_CG3;
2038 fprintf(stderr, "Error: CG3 framebuffer not available\n");
2041 } else if (!strstart(p, "none", &opts)) {
2043 fprintf(stderr, "Unknown vga type: %s\n", p);
2047 const char *nextopt;
2049 if (strstart(opts, ",retrace=", &nextopt)) {
2051 if (strstart(opts, "dumb", &nextopt))
2052 vga_retrace_method = VGA_RETRACE_DUMB;
2053 else if (strstart(opts, "precise", &nextopt))
2054 vga_retrace_method = VGA_RETRACE_PRECISE;
2055 else goto invalid_vga;
2056 } else goto invalid_vga;
2061 static DisplayType select_display(const char *p)
2064 DisplayType display = DT_DEFAULT;
2066 if (strstart(p, "sdl", &opts)) {
2070 const char *nextopt;
2072 if (strstart(opts, ",frame=", &nextopt)) {
2074 if (strstart(opts, "on", &nextopt)) {
2076 } else if (strstart(opts, "off", &nextopt)) {
2079 goto invalid_sdl_args;
2081 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
2083 if (strstart(opts, "on", &nextopt)) {
2085 } else if (strstart(opts, "off", &nextopt)) {
2088 goto invalid_sdl_args;
2090 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
2092 if (strstart(opts, "on", &nextopt)) {
2094 } else if (strstart(opts, "off", &nextopt)) {
2097 goto invalid_sdl_args;
2099 } else if (strstart(opts, ",window_close=", &nextopt)) {
2101 if (strstart(opts, "on", &nextopt)) {
2103 } else if (strstart(opts, "off", &nextopt)) {
2106 goto invalid_sdl_args;
2110 fprintf(stderr, "Invalid SDL option string: %s\n", p);
2116 fprintf(stderr, "SDL support is disabled\n");
2119 } else if (strstart(p, "vnc", &opts)) {
2124 const char *nextopt;
2126 if (strstart(opts, "=", &nextopt)) {
2127 vnc_display = nextopt;
2131 fprintf(stderr, "VNC requires a display argument vnc=<display>\n");
2135 fprintf(stderr, "VNC support is disabled\n");
2138 } else if (strstart(p, "curses", &opts)) {
2139 #ifdef CONFIG_CURSES
2140 display = DT_CURSES;
2142 fprintf(stderr, "Curses support is disabled\n");
2145 } else if (strstart(p, "gtk", &opts)) {
2149 const char *nextopt;
2151 if (strstart(opts, ",grab_on_hover=", &nextopt)) {
2153 if (strstart(opts, "on", &nextopt)) {
2154 grab_on_hover = true;
2155 } else if (strstart(opts, "off", &nextopt)) {
2156 grab_on_hover = false;
2158 goto invalid_gtk_args;
2162 fprintf(stderr, "Invalid GTK option string: %s\n", p);
2168 fprintf(stderr, "GTK support is disabled\n");
2172 } else if (strstart(p, "maru_sdl", &opts)) {
2173 # if defined(CONFIG_SDL) && defined(CONFIG_JAVA_UI)
2174 display = DT_MARU_SDL;
2176 fprintf(stderr, "maru_sdl support is disabled\n");
2179 } else if (strstart(p, "maru_shm", &opts)) {
2180 # if defined(CONFIG_USE_SHM) && defined(CONFIG_JAVA_UI)
2181 display = DT_MARU_SHM;
2183 fprintf(stderr, "maru_shm is disabled\n");
2186 } else if (strstart(p, "maru_qt", &opts)) {
2188 display = DT_MARU_QT_ONSCREEN;
2190 const char *nextopt;
2191 if (strstart(opts, ",rendering=", &nextopt)) {
2193 if (strstart(opts, "onscreen", &nextopt)) {
2194 display = DT_MARU_QT_ONSCREEN;
2195 } else if (strstart(opts, "offscreen", &nextopt)) {
2196 display = DT_MARU_QT_OFFSCREEN;
2198 goto invalid_maru_qt_args;
2200 } else if (strstart(opts, ",resolution=", &nextopt)) {
2202 char *endptr = NULL;
2203 // Resolution should be formed "640x480" or "640*480".
2204 int width = (int)g_ascii_strtoll(opts, &endptr, 10);
2205 int height = (int)g_ascii_strtoll(++endptr, &endptr, 10);
2206 if (width <= 0 || height <= 0) {
2207 goto invalid_maru_qt_args;
2209 set_initial_display_resolution(width, height);
2211 } else if (strstart(opts, ",dpi=", &nextopt)) {
2213 char *endptr = NULL;
2214 int dpi = (int)g_ascii_strtoll(opts, &endptr, 10);
2216 goto invalid_maru_qt_args;
2218 set_display_pixel_density(dpi);
2221 invalid_maru_qt_args:
2222 fprintf(stderr, "Invalid maru_qt option string: %s\n", p);
2228 error_report("maru_qt is disabled.\n");
2232 #endif /* CONFIG_MARU */
2233 } else if (strstart(p, "none", &opts)) {
2236 fprintf(stderr, "Unknown display type: %s\n", p);
2243 static int balloon_parse(const char *arg)
2247 if (strcmp(arg, "none") == 0) {
2251 if (!strncmp(arg, "virtio", 6)) {
2252 if (arg[6] == ',') {
2253 /* have params -> parse them */
2254 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
2258 /* create empty opts */
2259 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
2262 qemu_opt_set(opts, "driver", "virtio-balloon");
2269 char *qemu_find_file(int type, const char *name)
2275 /* Try the name as a straight path first */
2276 if (access(name, R_OK) == 0) {
2277 trace_load_file(name, name);
2278 return g_strdup(name);
2282 case QEMU_FILE_TYPE_BIOS:
2285 case QEMU_FILE_TYPE_KEYMAP:
2286 subdir = "keymaps/";
2292 for (i = 0; i < data_dir_idx; i++) {
2293 buf = g_strdup_printf("%s/%s%s", data_dir[i], subdir, name);
2294 if (access(buf, R_OK) == 0) {
2295 trace_load_file(name, buf);
2303 static int device_help_func(QemuOpts *opts, void *opaque)
2305 return qdev_device_help(opts);
2308 static int device_init_func(QemuOpts *opts, void *opaque)
2312 dev = qdev_device_add(opts);
2315 object_unref(OBJECT(dev));
2319 static int chardev_init_func(QemuOpts *opts, void *opaque)
2321 Error *local_err = NULL;
2323 qemu_chr_new_from_opts(opts, NULL, &local_err);
2325 error_report("%s", error_get_pretty(local_err));
2326 error_free(local_err);
2332 #ifdef CONFIG_VIRTFS
2333 static int fsdev_init_func(QemuOpts *opts, void *opaque)
2336 ret = qemu_fsdev_add(opts);
2342 static int mon_init_func(QemuOpts *opts, void *opaque)
2344 CharDriverState *chr;
2345 const char *chardev;
2349 mode = qemu_opt_get(opts, "mode");
2353 if (strcmp(mode, "readline") == 0) {
2354 flags = MONITOR_USE_READLINE;
2355 } else if (strcmp(mode, "control") == 0) {
2356 flags = MONITOR_USE_CONTROL;
2358 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
2362 if (qemu_opt_get_bool(opts, "pretty", 0))
2363 flags |= MONITOR_USE_PRETTY;
2365 if (qemu_opt_get_bool(opts, "default", 0))
2366 flags |= MONITOR_IS_DEFAULT;
2368 chardev = qemu_opt_get(opts, "chardev");
2369 chr = qemu_chr_find(chardev);
2371 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
2375 qemu_chr_fe_claim_no_fail(chr);
2376 monitor_init(chr, flags);
2380 static void monitor_parse(const char *optarg, const char *mode)
2382 static int monitor_device_index = 0;
2388 if (strstart(optarg, "chardev:", &p)) {
2389 snprintf(label, sizeof(label), "%s", p);
2391 snprintf(label, sizeof(label), "compat_monitor%d",
2392 monitor_device_index);
2393 if (monitor_device_index == 0) {
2396 opts = qemu_chr_parse_compat(label, optarg);
2398 fprintf(stderr, "parse error: %s\n", optarg);
2403 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, NULL);
2405 fprintf(stderr, "duplicate chardev: %s\n", label);
2408 qemu_opt_set(opts, "mode", mode);
2409 qemu_opt_set(opts, "chardev", label);
2411 qemu_opt_set(opts, "default", "on");
2412 monitor_device_index++;
2415 struct device_config {
2417 DEV_USB, /* -usbdevice */
2419 DEV_SERIAL, /* -serial */
2420 DEV_PARALLEL, /* -parallel */
2421 DEV_VIRTCON, /* -virtioconsole */
2422 DEV_DEBUGCON, /* -debugcon */
2423 DEV_GDB, /* -gdb, -s */
2424 DEV_SCLP, /* s390 sclp */
2426 const char *cmdline;
2428 QTAILQ_ENTRY(device_config) next;
2431 static QTAILQ_HEAD(, device_config) device_configs =
2432 QTAILQ_HEAD_INITIALIZER(device_configs);
2434 static void add_device_config(int type, const char *cmdline)
2436 struct device_config *conf;
2438 conf = g_malloc0(sizeof(*conf));
2440 conf->cmdline = cmdline;
2441 loc_save(&conf->loc);
2442 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
2445 static int foreach_device_config(int type, int (*func)(const char *cmdline))
2447 struct device_config *conf;
2450 QTAILQ_FOREACH(conf, &device_configs, next) {
2451 if (conf->type != type)
2453 loc_push_restore(&conf->loc);
2454 rc = func(conf->cmdline);
2455 loc_pop(&conf->loc);
2463 static int serial_parse(const char *devname)
2465 static int index = 0;
2468 if (strcmp(devname, "none") == 0)
2470 if (index == MAX_SERIAL_PORTS) {
2471 fprintf(stderr, "qemu: too many serial ports\n");
2474 snprintf(label, sizeof(label), "serial%d", index);
2475 serial_hds[index] = qemu_chr_new(label, devname, NULL);
2476 if (!serial_hds[index]) {
2477 fprintf(stderr, "qemu: could not connect serial device"
2478 " to character backend '%s'\n", devname);
2485 static int parallel_parse(const char *devname)
2487 static int index = 0;
2490 if (strcmp(devname, "none") == 0)
2492 if (index == MAX_PARALLEL_PORTS) {
2493 fprintf(stderr, "qemu: too many parallel ports\n");
2496 snprintf(label, sizeof(label), "parallel%d", index);
2497 parallel_hds[index] = qemu_chr_new(label, devname, NULL);
2498 if (!parallel_hds[index]) {
2499 fprintf(stderr, "qemu: could not connect parallel device"
2500 " to character backend '%s'\n", devname);
2507 static int virtcon_parse(const char *devname)
2509 QemuOptsList *device = qemu_find_opts("device");
2510 static int index = 0;
2512 QemuOpts *bus_opts, *dev_opts;
2514 if (strcmp(devname, "none") == 0)
2516 if (index == MAX_VIRTIO_CONSOLES) {
2517 fprintf(stderr, "qemu: too many virtio consoles\n");
2521 bus_opts = qemu_opts_create(device, NULL, 0, &error_abort);
2522 if (arch_type == QEMU_ARCH_S390X) {
2523 qemu_opt_set(bus_opts, "driver", "virtio-serial-s390");
2525 qemu_opt_set(bus_opts, "driver", "virtio-serial-pci");
2528 dev_opts = qemu_opts_create(device, NULL, 0, &error_abort);
2529 qemu_opt_set(dev_opts, "driver", "virtconsole");
2531 snprintf(label, sizeof(label), "virtcon%d", index);
2532 virtcon_hds[index] = qemu_chr_new(label, devname, NULL);
2533 if (!virtcon_hds[index]) {
2534 fprintf(stderr, "qemu: could not connect virtio console"
2535 " to character backend '%s'\n", devname);
2538 qemu_opt_set(dev_opts, "chardev", label);
2544 static int sclp_parse(const char *devname)
2546 QemuOptsList *device = qemu_find_opts("device");
2547 static int index = 0;
2551 if (strcmp(devname, "none") == 0) {
2554 if (index == MAX_SCLP_CONSOLES) {
2555 fprintf(stderr, "qemu: too many sclp consoles\n");
2559 assert(arch_type == QEMU_ARCH_S390X);
2561 dev_opts = qemu_opts_create(device, NULL, 0, NULL);
2562 qemu_opt_set(dev_opts, "driver", "sclpconsole");
2564 snprintf(label, sizeof(label), "sclpcon%d", index);
2565 sclp_hds[index] = qemu_chr_new(label, devname, NULL);
2566 if (!sclp_hds[index]) {
2567 fprintf(stderr, "qemu: could not connect sclp console"
2568 " to character backend '%s'\n", devname);
2571 qemu_opt_set(dev_opts, "chardev", label);
2577 static int debugcon_parse(const char *devname)
2581 if (!qemu_chr_new("debugcon", devname, NULL)) {
2584 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL);
2586 fprintf(stderr, "qemu: already have a debugcon device\n");
2589 qemu_opt_set(opts, "driver", "isa-debugcon");
2590 qemu_opt_set(opts, "chardev", "debugcon");
2594 static gint machine_class_cmp(gconstpointer a, gconstpointer b)
2596 const MachineClass *mc1 = a, *mc2 = b;
2599 if (mc1->family == NULL) {
2600 if (mc2->family == NULL) {
2601 /* Compare standalone machine types against each other; they sort
2602 * in increasing order.
2604 return strcmp(object_class_get_name(OBJECT_CLASS(mc1)),
2605 object_class_get_name(OBJECT_CLASS(mc2)));
2608 /* Standalone machine types sort after families. */
2612 if (mc2->family == NULL) {
2613 /* Families sort before standalone machine types. */
2617 /* Families sort between each other alphabetically increasingly. */
2618 res = strcmp(mc1->family, mc2->family);
2623 /* Within the same family, machine types sort in decreasing order. */
2624 return strcmp(object_class_get_name(OBJECT_CLASS(mc2)),
2625 object_class_get_name(OBJECT_CLASS(mc1)));
2628 static MachineClass *machine_parse(const char *name)
2630 MachineClass *mc = NULL;
2631 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
2634 mc = find_machine(name);
2639 if (name && !is_help_option(name)) {
2640 error_report("Unsupported machine type");
2641 error_printf("Use -machine help to list supported machines!\n");
2643 printf("Supported machines are:\n");
2644 machines = g_slist_sort(machines, machine_class_cmp);
2645 for (el = machines; el; el = el->next) {
2646 MachineClass *mc = el->data;
2648 printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name);
2650 printf("%-20s %s%s\n", mc->name, mc->desc,
2651 mc->is_default ? " (default)" : "");
2655 g_slist_free(machines);
2656 exit(!name || !is_help_option(name));
2659 void qemu_add_exit_notifier(Notifier *notify)
2661 notifier_list_add(&exit_notifiers, notify);
2664 void qemu_remove_exit_notifier(Notifier *notify)
2666 notifier_remove(notify);
2669 static void qemu_run_exit_notifiers(void)
2671 notifier_list_notify(&exit_notifiers, NULL);
2674 void qemu_add_machine_init_done_notifier(Notifier *notify)
2676 notifier_list_add(&machine_init_done_notifiers, notify);
2679 static void qemu_run_machine_init_done_notifiers(void)
2681 notifier_list_notify(&machine_init_done_notifiers, NULL);
2684 static const QEMUOption *lookup_opt(int argc, char **argv,
2685 const char **poptarg, int *poptind)
2687 const QEMUOption *popt;
2688 int optind = *poptind;
2689 char *r = argv[optind];
2692 loc_set_cmdline(argv, optind, 1);
2694 /* Treat --foo the same as -foo. */
2697 popt = qemu_options;
2700 error_report("invalid option");
2703 if (!strcmp(popt->name, r + 1))
2707 if (popt->flags & HAS_ARG) {
2708 if (optind >= argc) {
2709 error_report("requires an argument");
2712 optarg = argv[optind++];
2713 loc_set_cmdline(argv, optind - 2, 2);
2724 static gpointer malloc_and_trace(gsize n_bytes)
2726 void *ptr = malloc(n_bytes);
2727 trace_g_malloc(n_bytes, ptr);
2731 static gpointer realloc_and_trace(gpointer mem, gsize n_bytes)
2733 void *ptr = realloc(mem, n_bytes);
2734 trace_g_realloc(mem, n_bytes, ptr);
2738 static void free_and_trace(gpointer mem)
2744 static int machine_set_property(const char *name, const char *value,
2747 Object *obj = OBJECT(opaque);
2748 StringInputVisitor *siv;
2749 Error *local_err = NULL;
2752 if (strcmp(name, "type") == 0) {
2756 qom_name = g_strdup(name);
2764 siv = string_input_visitor_new(value);
2765 object_property_set(obj, string_input_get_visitor(siv), qom_name, &local_err);
2766 string_input_visitor_cleanup(siv);
2770 qerror_report_err(local_err);
2771 error_free(local_err);
2778 static int object_create(QemuOpts *opts, void *opaque)
2787 ov = opts_visitor_new(opts);
2788 pdict = qemu_opts_to_qdict(opts, NULL);
2790 visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
2795 qdict_del(pdict, "qom-type");
2796 visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
2801 qdict_del(pdict, "id");
2802 visit_type_str(opts_get_visitor(ov), &id, "id", &err);
2807 object_add(type, id, pdict, opts_get_visitor(ov), &err);
2811 visit_end_struct(opts_get_visitor(ov), &err);
2813 qmp_object_del(id, NULL);
2817 opts_visitor_cleanup(ov);
2824 qerror_report_err(err);
2832 // W/A for preserve larger continuous heap for RAM.
2833 extern void *preallocated_ram_ptr;
2834 extern int preallocated_ram_size;
2837 int main(int argc, char **argv, char **envp)
2840 int snapshot, linux_boot;
2841 const char *initrd_filename;
2842 const char *kernel_filename, *kernel_cmdline;
2843 const char *boot_order;
2845 int cyls, heads, secs, translation;
2846 QemuOpts *hda_opts = NULL, *opts, *machine_opts, *icount_opts = NULL;
2847 QemuOptsList *olist;
2850 const char *loadvm = NULL;
2851 MachineClass *machine_class;
2852 const char *cpu_model;
2853 const char *vga_model = NULL;
2854 const char *qtest_chrdev = NULL;
2855 const char *qtest_log = NULL;
2856 const char *pid_file = NULL;
2857 const char *incoming = NULL;
2859 int show_vnc_port = 0;
2861 bool defconfig = true;
2862 bool userconfig = true;
2863 const char *log_mask = NULL;
2864 const char *log_file = NULL;
2865 GMemVTable mem_trace = {
2866 .malloc = malloc_and_trace,
2867 .realloc = realloc_and_trace,
2868 .free = free_and_trace,
2870 const char *trace_events = NULL;
2871 const char *trace_file = NULL;
2872 const ram_addr_t default_ram_size = (ram_addr_t)DEFAULT_RAM_SIZE *
2874 ram_addr_t maxram_size = default_ram_size;
2875 uint64_t ram_slots = 0;
2876 FILE *vmstate_dump_file = NULL;
2877 Error *main_loop_err = NULL;
2879 static bool yagl_enabled = false;
2880 #endif /* CONFIG_YAGL */
2882 static bool vigs_enabled = false;
2883 static char *vigs_backend = NULL;
2884 #endif /* CONFIG_VIGS */
2885 #if defined(CONFIG_MARU) && defined(CONFIG_JAVA_UI)
2886 static bool skin_enabled = true;
2887 #endif /* CONFIG_MARU */
2889 atexit(qemu_run_exit_notifiers);
2890 error_set_progname(argv[0]);
2891 qemu_init_exec_dir(argv[0]);
2893 g_mem_set_vtable(&mem_trace);
2895 module_call_init(MODULE_INIT_QOM);
2897 qemu_add_opts(&qemu_drive_opts);
2898 qemu_add_drive_opts(&qemu_legacy_drive_opts);
2899 qemu_add_drive_opts(&qemu_common_drive_opts);
2900 qemu_add_drive_opts(&qemu_drive_opts);
2901 qemu_add_opts(&qemu_chardev_opts);
2902 qemu_add_opts(&qemu_device_opts);
2903 qemu_add_opts(&qemu_netdev_opts);
2904 qemu_add_opts(&qemu_net_opts);
2905 qemu_add_opts(&qemu_rtc_opts);
2906 qemu_add_opts(&qemu_global_opts);
2907 qemu_add_opts(&qemu_mon_opts);
2908 qemu_add_opts(&qemu_trace_opts);
2909 qemu_add_opts(&qemu_option_rom_opts);
2910 qemu_add_opts(&qemu_machine_opts);
2911 qemu_add_opts(&qemu_mem_opts);
2912 qemu_add_opts(&qemu_smp_opts);
2913 qemu_add_opts(&qemu_boot_opts);
2914 qemu_add_opts(&qemu_sandbox_opts);
2915 qemu_add_opts(&qemu_add_fd_opts);
2916 qemu_add_opts(&qemu_object_opts);
2917 qemu_add_opts(&qemu_tpmdev_opts);
2918 qemu_add_opts(&qemu_realtime_opts);
2919 qemu_add_opts(&qemu_msg_opts);
2920 qemu_add_opts(&qemu_name_opts);
2921 qemu_add_opts(&qemu_numa_opts);
2922 qemu_add_opts(&qemu_icount_opts);
2926 rtc_clock = QEMU_CLOCK_HOST;
2928 QLIST_INIT (&vm_change_state_head);
2929 os_setup_early_signal_handling();
2931 module_call_init(MODULE_INIT_MACHINE);
2932 machine_class = find_default_machine();
2934 ram_size = default_ram_size;
2936 cyls = heads = secs = 0;
2937 translation = BIOS_ATA_TRANSLATION_AUTO;
2939 for (i = 0; i < MAX_NODES; i++) {
2940 numa_info[i].node_mem = 0;
2941 numa_info[i].present = false;
2942 bitmap_zero(numa_info[i].node_cpu, MAX_CPUMASK_BITS);
2946 max_numa_nodeid = 0;
2949 bdrv_init_with_whitelist();
2953 /* first pass of option parsing */
2955 while (optind < argc) {
2956 if (argv[optind][0] != '-') {
2960 const QEMUOption *popt;
2962 popt = lookup_opt(argc, argv, &optarg, &optind);
2963 switch (popt->index) {
2964 case QEMU_OPTION_nodefconfig:
2967 case QEMU_OPTION_nouserconfig:
2976 ret = qemu_read_default_config_files(userconfig);
2982 /* second pass of option parsing */
2987 if (argv[optind][0] != '-') {
2988 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
2990 const QEMUOption *popt;
2992 popt = lookup_opt(argc, argv, &optarg, &optind);
2993 if (!(popt->arch_mask & arch_type)) {
2994 printf("Option %s not supported for this target\n", popt->name);
2997 switch(popt->index) {
2999 machine_class = machine_parse(optarg);
3001 case QEMU_OPTION_no_kvm_irqchip: {
3002 olist = qemu_find_opts("machine");
3003 qemu_opts_parse(olist, "kernel_irqchip=off", 0);
3006 case QEMU_OPTION_cpu:
3007 /* hw initialization will check this */
3010 case QEMU_OPTION_hda:
3014 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
3016 snprintf(buf, sizeof(buf),
3017 "%s,cyls=%d,heads=%d,secs=%d%s",
3018 HD_OPTS , cyls, heads, secs,
3019 translation == BIOS_ATA_TRANSLATION_LBA ?
3021 translation == BIOS_ATA_TRANSLATION_NONE ?
3022 ",trans=none" : "");
3023 drive_add(IF_DEFAULT, 0, optarg, buf);
3026 case QEMU_OPTION_hdb:
3027 case QEMU_OPTION_hdc:
3028 case QEMU_OPTION_hdd:
3029 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
3032 case QEMU_OPTION_drive:
3033 if (drive_def(optarg) == NULL) {
3037 case QEMU_OPTION_set:
3038 if (qemu_set_option(optarg) != 0)
3041 case QEMU_OPTION_global:
3042 if (qemu_global_option(optarg) != 0)
3045 case QEMU_OPTION_mtdblock:
3046 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
3048 case QEMU_OPTION_sd:
3049 drive_add(IF_SD, -1, optarg, SD_OPTS);
3051 case QEMU_OPTION_pflash:
3052 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
3054 case QEMU_OPTION_snapshot:
3057 case QEMU_OPTION_hdachs:
3061 cyls = strtol(p, (char **)&p, 0);
3062 if (cyls < 1 || cyls > 16383)
3067 heads = strtol(p, (char **)&p, 0);
3068 if (heads < 1 || heads > 16)
3073 secs = strtol(p, (char **)&p, 0);
3074 if (secs < 1 || secs > 63)
3078 if (!strcmp(p, "large")) {
3079 translation = BIOS_ATA_TRANSLATION_LARGE;
3080 } else if (!strcmp(p, "rechs")) {
3081 translation = BIOS_ATA_TRANSLATION_RECHS;
3082 } else if (!strcmp(p, "none")) {
3083 translation = BIOS_ATA_TRANSLATION_NONE;
3084 } else if (!strcmp(p, "lba")) {
3085 translation = BIOS_ATA_TRANSLATION_LBA;
3086 } else if (!strcmp(p, "auto")) {
3087 translation = BIOS_ATA_TRANSLATION_AUTO;
3091 } else if (*p != '\0') {
3093 fprintf(stderr, "qemu: invalid physical CHS format\n");
3096 if (hda_opts != NULL) {
3098 snprintf(num, sizeof(num), "%d", cyls);
3099 qemu_opt_set(hda_opts, "cyls", num);
3100 snprintf(num, sizeof(num), "%d", heads);
3101 qemu_opt_set(hda_opts, "heads", num);
3102 snprintf(num, sizeof(num), "%d", secs);
3103 qemu_opt_set(hda_opts, "secs", num);
3104 if (translation == BIOS_ATA_TRANSLATION_LARGE) {
3105 qemu_opt_set(hda_opts, "trans", "large");
3106 } else if (translation == BIOS_ATA_TRANSLATION_RECHS) {
3107 qemu_opt_set(hda_opts, "trans", "rechs");
3108 } else if (translation == BIOS_ATA_TRANSLATION_LBA) {
3109 qemu_opt_set(hda_opts, "trans", "lba");
3110 } else if (translation == BIOS_ATA_TRANSLATION_NONE) {
3111 qemu_opt_set(hda_opts, "trans", "none");
3116 case QEMU_OPTION_numa:
3117 opts = qemu_opts_parse(qemu_find_opts("numa"), optarg, 1);
3122 case QEMU_OPTION_display:
3123 display_type = select_display(optarg);
3125 case QEMU_OPTION_nographic:
3126 display_type = DT_NOGRAPHIC;
3128 case QEMU_OPTION_curses:
3129 #ifdef CONFIG_CURSES
3130 display_type = DT_CURSES;
3132 fprintf(stderr, "Curses support is disabled\n");
3136 case QEMU_OPTION_portrait:
3137 graphic_rotate = 90;
3139 case QEMU_OPTION_rotate:
3140 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
3141 if (graphic_rotate != 0 && graphic_rotate != 90 &&
3142 graphic_rotate != 180 && graphic_rotate != 270) {
3144 "qemu: only 90, 180, 270 deg rotation is available\n");
3148 case QEMU_OPTION_kernel:
3149 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg);
3151 case QEMU_OPTION_initrd:
3152 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg);
3154 case QEMU_OPTION_append:
3155 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg);
3157 case QEMU_OPTION_dtb:
3158 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg);
3160 case QEMU_OPTION_cdrom:
3161 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
3163 case QEMU_OPTION_boot:
3164 opts = qemu_opts_parse(qemu_find_opts("boot-opts"), optarg, 1);
3169 case QEMU_OPTION_fda:
3170 case QEMU_OPTION_fdb:
3171 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
3174 case QEMU_OPTION_no_fd_bootchk:
3177 case QEMU_OPTION_netdev:
3178 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
3182 case QEMU_OPTION_net:
3183 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
3187 #ifdef CONFIG_LIBISCSI
3188 case QEMU_OPTION_iscsi:
3189 opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0);
3196 case QEMU_OPTION_tftp:
3197 legacy_tftp_prefix = optarg;
3199 case QEMU_OPTION_bootp:
3200 legacy_bootp_filename = optarg;
3202 case QEMU_OPTION_redir:
3203 if (net_slirp_redir(optarg) < 0)
3207 case QEMU_OPTION_bt:
3208 add_device_config(DEV_BT, optarg);
3210 case QEMU_OPTION_audio_help:
3214 case QEMU_OPTION_soundhw:
3215 select_soundhw (optarg);
3220 case QEMU_OPTION_version:
3224 case QEMU_OPTION_m: {
3226 const char *mem_str;
3227 const char *maxmem_str, *slots_str;
3229 opts = qemu_opts_parse(qemu_find_opts("memory"),
3235 mem_str = qemu_opt_get(opts, "size");
3237 error_report("invalid -m option, missing 'size' option");
3241 error_report("missing 'size' option value");
3245 sz = qemu_opt_get_size(opts, "size", ram_size);
3247 /* Fix up legacy suffix-less format */
3248 if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) {
3249 uint64_t overflow_check = sz;
3252 if ((sz >> 20) != overflow_check) {
3253 error_report("too large 'size' option value");
3258 /* backward compatibility behaviour for case "-m 0" */
3260 sz = default_ram_size;
3263 sz = QEMU_ALIGN_UP(sz, 8192);
3265 if (ram_size != sz) {
3266 error_report("ram size too large");
3269 maxram_size = ram_size;
3271 maxmem_str = qemu_opt_get(opts, "maxmem");
3272 slots_str = qemu_opt_get(opts, "slots");
3273 if (maxmem_str && slots_str) {
3276 sz = qemu_opt_get_size(opts, "maxmem", 0);
3277 if (sz < ram_size) {
3278 error_report("invalid -m option value: maxmem "
3279 "(0x%" PRIx64 ") <= initial memory (0x"
3280 RAM_ADDR_FMT ")", sz, ram_size);
3284 slots = qemu_opt_get_number(opts, "slots", 0);
3285 if ((sz > ram_size) && !slots) {
3286 error_report("invalid -m option value: maxmem "
3287 "(0x%" PRIx64 ") more than initial memory (0x"
3288 RAM_ADDR_FMT ") but no hotplug slots where "
3289 "specified", sz, ram_size);
3293 if ((sz <= ram_size) && slots) {
3294 error_report("invalid -m option value: %"
3295 PRIu64 " hotplug slots where specified but "
3296 "maxmem (0x%" PRIx64 ") <= initial memory (0x"
3297 RAM_ADDR_FMT ")", slots, sz, ram_size);
3302 } else if ((!maxmem_str && slots_str) ||
3303 (maxmem_str && !slots_str)) {
3304 error_report("invalid -m option value: missing "
3305 "'%s' option", slots_str ? "maxmem" : "slots");
3311 case QEMU_OPTION_tpmdev:
3312 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
3317 case QEMU_OPTION_mempath:
3320 case QEMU_OPTION_mem_prealloc:
3330 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
3332 case QEMU_OPTION_gdb:
3333 add_device_config(DEV_GDB, optarg);
3336 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
3337 data_dir[data_dir_idx++] = optarg;
3340 case QEMU_OPTION_bios:
3341 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg);
3343 case QEMU_OPTION_singlestep:
3350 keyboard_layout = optarg;
3352 case QEMU_OPTION_localtime:
3355 case QEMU_OPTION_vga:
3364 w = strtol(p, (char **)&p, 10);
3367 fprintf(stderr, "qemu: invalid resolution or depth\n");
3373 h = strtol(p, (char **)&p, 10);
3378 depth = strtol(p, (char **)&p, 10);
3379 if (depth != 8 && depth != 15 && depth != 16 &&
3380 depth != 24 && depth != 32)
3382 } else if (*p == '\0') {
3383 depth = graphic_depth;
3390 graphic_depth = depth;
3393 case QEMU_OPTION_echr:
3396 term_escape_char = strtol(optarg, &r, 0);
3398 printf("Bad argument to echr\n");
3401 case QEMU_OPTION_monitor:
3402 default_monitor = 0;
3403 if (strncmp(optarg, "none", 4)) {
3404 monitor_parse(optarg, "readline");
3407 case QEMU_OPTION_qmp:
3408 monitor_parse(optarg, "control");
3409 default_monitor = 0;
3411 case QEMU_OPTION_mon:
3412 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
3416 default_monitor = 0;
3418 case QEMU_OPTION_chardev:
3419 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
3424 case QEMU_OPTION_fsdev:
3425 olist = qemu_find_opts("fsdev");
3427 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
3430 opts = qemu_opts_parse(olist, optarg, 1);
3435 case QEMU_OPTION_virtfs: {
3438 const char *writeout, *sock_fd, *socket;
3440 olist = qemu_find_opts("virtfs");
3442 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
3445 opts = qemu_opts_parse(olist, optarg, 1);
3450 if (qemu_opt_get(opts, "fsdriver") == NULL ||
3451 qemu_opt_get(opts, "mount_tag") == NULL) {
3452 fprintf(stderr, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
3455 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
3456 qemu_opt_get(opts, "mount_tag"),
3459 fprintf(stderr, "duplicate fsdev id: %s\n",
3460 qemu_opt_get(opts, "mount_tag"));
3464 writeout = qemu_opt_get(opts, "writeout");
3466 #ifdef CONFIG_SYNC_FILE_RANGE
3467 qemu_opt_set(fsdev, "writeout", writeout);
3469 fprintf(stderr, "writeout=immediate not supported on "
3474 qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver"));
3475 qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"));
3476 qemu_opt_set(fsdev, "security_model",
3477 qemu_opt_get(opts, "security_model"));
3478 socket = qemu_opt_get(opts, "socket");
3480 qemu_opt_set(fsdev, "socket", socket);
3482 sock_fd = qemu_opt_get(opts, "sock_fd");
3484 qemu_opt_set(fsdev, "sock_fd", sock_fd);
3487 qemu_opt_set_bool(fsdev, "readonly",
3488 qemu_opt_get_bool(opts, "readonly", 0));
3489 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3491 qemu_opt_set(device, "driver", "virtio-9p-pci");
3492 qemu_opt_set(device, "fsdev",
3493 qemu_opt_get(opts, "mount_tag"));
3494 qemu_opt_set(device, "mount_tag",
3495 qemu_opt_get(opts, "mount_tag"));
3498 case QEMU_OPTION_virtfs_synth: {
3502 fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3505 fprintf(stderr, "duplicate option: %s\n", "virtfs_synth");
3508 qemu_opt_set(fsdev, "fsdriver", "synth");
3510 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3512 qemu_opt_set(device, "driver", "virtio-9p-pci");
3513 qemu_opt_set(device, "fsdev", "v_synth");
3514 qemu_opt_set(device, "mount_tag", "v_synth");
3517 case QEMU_OPTION_serial:
3518 add_device_config(DEV_SERIAL, optarg);
3520 if (strncmp(optarg, "mon:", 4) == 0) {
3521 default_monitor = 0;
3524 case QEMU_OPTION_watchdog:
3527 "qemu: only one watchdog option may be given\n");
3532 case QEMU_OPTION_watchdog_action:
3533 if (select_watchdog_action(optarg) == -1) {
3534 fprintf(stderr, "Unknown -watchdog-action parameter\n");
3538 case QEMU_OPTION_virtiocon:
3539 add_device_config(DEV_VIRTCON, optarg);
3540 default_virtcon = 0;
3541 if (strncmp(optarg, "mon:", 4) == 0) {
3542 default_monitor = 0;
3545 case QEMU_OPTION_parallel:
3546 add_device_config(DEV_PARALLEL, optarg);
3547 default_parallel = 0;
3548 if (strncmp(optarg, "mon:", 4) == 0) {
3549 default_monitor = 0;
3552 case QEMU_OPTION_debugcon:
3553 add_device_config(DEV_DEBUGCON, optarg);
3555 case QEMU_OPTION_loadvm:
3558 case QEMU_OPTION_full_screen:
3561 case QEMU_OPTION_no_frame:
3564 case QEMU_OPTION_alt_grab:
3567 case QEMU_OPTION_ctrl_grab:
3570 case QEMU_OPTION_no_quit:
3573 case QEMU_OPTION_sdl:
3575 display_type = DT_SDL;
3578 fprintf(stderr, "SDL support is disabled\n");
3581 case QEMU_OPTION_pidfile:
3584 case QEMU_OPTION_win2k_hack:
3585 win2k_install_hack = 1;
3587 case QEMU_OPTION_rtc_td_hack: {
3588 static GlobalProperty slew_lost_ticks[] = {
3590 .driver = "mc146818rtc",
3591 .property = "lost_tick_policy",
3594 { /* end of list */ }
3597 qdev_prop_register_global_list(slew_lost_ticks);
3600 case QEMU_OPTION_acpitable:
3601 opts = qemu_opts_parse(qemu_find_opts("acpi"), optarg, 1);
3605 do_acpitable_option(opts);
3607 case QEMU_OPTION_smbios:
3608 opts = qemu_opts_parse(qemu_find_opts("smbios"), optarg, 0);
3612 do_smbios_option(opts);
3614 case QEMU_OPTION_enable_kvm:
3615 olist = qemu_find_opts("machine");
3616 qemu_opts_parse(olist, "accel=kvm", 0);
3618 case QEMU_OPTION_enable_yagl:
3619 #if defined(CONFIG_YAGL)
3620 yagl_enabled = true;
3622 fprintf(stderr, "YaGL openGLES passthrough support is disabled,"
3623 " ignoring -enable-yagl\n");
3626 case QEMU_OPTION_enable_vigs:
3627 #if defined(CONFIG_VIGS)
3628 vigs_enabled = true;
3630 fprintf(stderr, "VIGS support is disabled,"
3631 " ignoring -enable-vigs\n");
3634 case QEMU_OPTION_vigs_backend:
3635 #if defined(CONFIG_VIGS)
3636 vigs_backend = g_strdup(optarg);
3638 fprintf(stderr, "VIGS support is disabled,"
3639 " ignoring -vigs-backend\n");
3642 case QEMU_OPTION_machine:
3643 olist = qemu_find_opts("machine");
3644 opts = qemu_opts_parse(olist, optarg, 1);
3648 optarg = qemu_opt_get(opts, "type");
3650 machine_class = machine_parse(optarg);
3653 case QEMU_OPTION_no_kvm:
3654 olist = qemu_find_opts("machine");
3655 qemu_opts_parse(olist, "accel=tcg", 0);
3657 case QEMU_OPTION_no_kvm_pit: {
3658 fprintf(stderr, "Warning: KVM PIT can no longer be disabled "
3662 case QEMU_OPTION_no_kvm_pit_reinjection: {
3663 static GlobalProperty kvm_pit_lost_tick_policy[] = {
3665 .driver = "kvm-pit",
3666 .property = "lost_tick_policy",
3669 { /* end of list */ }
3672 fprintf(stderr, "Warning: option deprecated, use "
3673 "lost_tick_policy property of kvm-pit instead.\n");
3674 qdev_prop_register_global_list(kvm_pit_lost_tick_policy);
3677 case QEMU_OPTION_usb:
3678 olist = qemu_find_opts("machine");
3679 qemu_opts_parse(olist, "usb=on", 0);
3681 case QEMU_OPTION_usbdevice:
3682 olist = qemu_find_opts("machine");
3683 qemu_opts_parse(olist, "usb=on", 0);
3684 add_device_config(DEV_USB, optarg);
3686 case QEMU_OPTION_device:
3687 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
3691 case QEMU_OPTION_smp:
3692 if (!qemu_opts_parse(qemu_find_opts("smp-opts"), optarg, 1)) {
3696 case QEMU_OPTION_vnc:
3699 vnc_display = optarg;
3701 fprintf(stderr, "VNC support is disabled\n");
3705 case QEMU_OPTION_no_acpi:
3708 case QEMU_OPTION_no_hpet:
3711 case QEMU_OPTION_balloon:
3712 if (balloon_parse(optarg) < 0) {
3713 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
3717 case QEMU_OPTION_no_reboot:
3720 case QEMU_OPTION_no_shutdown:
3723 case QEMU_OPTION_show_cursor:
3726 case QEMU_OPTION_uuid:
3727 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
3728 fprintf(stderr, "Fail to parse UUID string."
3729 " Wrong format.\n");
3732 qemu_uuid_set = true;
3734 case QEMU_OPTION_option_rom:
3735 if (nb_option_roms >= MAX_OPTION_ROMS) {
3736 fprintf(stderr, "Too many option ROMs\n");
3739 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
3743 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
3744 option_rom[nb_option_roms].bootindex =
3745 qemu_opt_get_number(opts, "bootindex", -1);
3746 if (!option_rom[nb_option_roms].name) {
3747 fprintf(stderr, "Option ROM file is not specified\n");
3752 case QEMU_OPTION_semihosting:
3753 semihosting_enabled = 1;
3755 case QEMU_OPTION_tdf:
3756 fprintf(stderr, "Warning: user space PIT time drift fix "
3757 "is no longer supported.\n");
3759 case QEMU_OPTION_name:
3760 opts = qemu_opts_parse(qemu_find_opts("name"), optarg, 1);
3765 case QEMU_OPTION_prom_env:
3766 if (nb_prom_envs >= MAX_PROM_ENVS) {
3767 fprintf(stderr, "Too many prom variables\n");
3770 prom_envs[nb_prom_envs] = optarg;
3773 case QEMU_OPTION_old_param:
3776 case QEMU_OPTION_clock:
3777 /* Clock options no longer exist. Keep this option for
3778 * backward compatibility.
3781 case QEMU_OPTION_startdate:
3782 configure_rtc_date_offset(optarg, 1);
3784 case QEMU_OPTION_rtc:
3785 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
3789 configure_rtc(opts);
3791 case QEMU_OPTION_tb_size:
3792 tcg_tb_size = strtol(optarg, NULL, 0);
3793 if (tcg_tb_size < 0) {
3797 case QEMU_OPTION_icount:
3798 icount_opts = qemu_opts_parse(qemu_find_opts("icount"),
3804 case QEMU_OPTION_incoming:
3806 runstate_set(RUN_STATE_INMIGRATE);
3808 case QEMU_OPTION_nodefaults:
3811 case QEMU_OPTION_xen_domid:
3812 if (!(xen_available())) {
3813 printf("Option %s not supported for this target\n", popt->name);
3816 xen_domid = atoi(optarg);
3818 case QEMU_OPTION_xen_create:
3819 if (!(xen_available())) {
3820 printf("Option %s not supported for this target\n", popt->name);
3823 xen_mode = XEN_CREATE;
3825 case QEMU_OPTION_xen_attach:
3826 if (!(xen_available())) {
3827 printf("Option %s not supported for this target\n", popt->name);
3830 xen_mode = XEN_ATTACH;
3832 case QEMU_OPTION_trace:
3834 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
3838 trace_events = qemu_opt_get(opts, "events");
3839 trace_file = qemu_opt_get(opts, "file");
3842 case QEMU_OPTION_readconfig:
3844 int ret = qemu_read_config_file(optarg);
3846 fprintf(stderr, "read config %s: %s\n", optarg,
3852 case QEMU_OPTION_spice:
3853 olist = qemu_find_opts("spice");
3855 fprintf(stderr, "spice is not supported by this qemu build.\n");
3858 opts = qemu_opts_parse(olist, optarg, 0);
3864 case QEMU_OPTION_writeconfig:
3867 if (strcmp(optarg, "-") == 0) {
3870 fp = fopen(optarg, "w");
3872 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
3876 qemu_config_write(fp);
3882 case QEMU_OPTION_qtest:
3883 qtest_chrdev = optarg;
3885 case QEMU_OPTION_qtest_log:
3888 case QEMU_OPTION_sandbox:
3889 opts = qemu_opts_parse(qemu_find_opts("sandbox"), optarg, 1);
3894 case QEMU_OPTION_enable_hax:
3895 olist = qemu_find_opts("machine");
3896 qemu_opts_parse(olist, "accel=hax", 0);
3898 case QEMU_OPTION_add_fd:
3900 opts = qemu_opts_parse(qemu_find_opts("add-fd"), optarg, 0);
3905 error_report("File descriptor passing is disabled on this "
3910 #if defined(CONFIG_MARU) && defined(CONFIG_JAVA_UI)
3911 case QEMU_OPTION_disable_skin:
3912 skin_enabled = false;
3914 case QEMU_OPTION_enable_suspend:
3915 ecs_set_suspend_state(SUSPEND_UNLOCK);
3918 case QEMU_OPTION_object:
3919 opts = qemu_opts_parse(qemu_find_opts("object"), optarg, 1);
3924 case QEMU_OPTION_realtime:
3925 opts = qemu_opts_parse(qemu_find_opts("realtime"), optarg, 0);
3929 enable_mlock = qemu_opt_get_bool(opts, "mlock", true);
3931 case QEMU_OPTION_msg:
3932 opts = qemu_opts_parse(qemu_find_opts("msg"), optarg, 0);
3936 configure_msg(opts);
3938 case QEMU_OPTION_dump_vmstate:
3939 if (vmstate_dump_file) {
3940 fprintf(stderr, "qemu: only one '-dump-vmstate' "
3941 "option may be given\n");
3944 vmstate_dump_file = fopen(optarg, "w");
3945 if (vmstate_dump_file == NULL) {
3946 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
3951 os_parse_cmd_args(popt->index, optarg);
3959 if (qemu_init_main_loop(&main_loop_err)) {
3960 error_report("%s", error_get_pretty(main_loop_err));
3964 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 0)) {
3968 if (qemu_opts_foreach(qemu_find_opts("name"), parse_name, NULL, 1)) {
3973 if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL, 1)) {
3977 if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd, NULL, 1)) {
3982 if (machine_class == NULL) {
3983 fprintf(stderr, "No machine specified, and there is no default.\n"
3984 "Use -machine help to list supported machines!\n");
3988 current_machine = MACHINE(object_new(object_class_get_name(
3989 OBJECT_CLASS(machine_class))));
3990 object_property_add_child(object_get_root(), "machine",
3991 OBJECT(current_machine), &error_abort);
3992 cpu_exec_init_all();
3994 if (machine_class->hw_version) {
3995 qemu_set_version(machine_class->hw_version);
3998 /* Init CPU def lists, based on config
3999 * - Must be called after all the qemu_read_config_file() calls
4000 * - Must be called before list_cpus()
4001 * - Must be called before machine->init()
4005 if (cpu_model && is_help_option(cpu_model)) {
4006 list_cpus(stdout, &fprintf, cpu_model);
4010 #if defined(CONFIG_MARU)
4011 preallocated_ram_ptr = qemu_anon_ram_alloc(ram_size, NULL);
4012 if (preallocated_ram_ptr) {
4013 preallocated_ram_size = ram_size;
4016 kernel_cmdline = qemu_opt_get(qemu_get_machine_opts(), "append");
4017 // Returned variable points different address from input variable.
4018 kernel_cmdline = prepare_maru(kernel_cmdline);
4019 qemu_opt_set(qemu_get_machine_opts(), "append", kernel_cmdline);
4022 /* Open the logfile at this point, if necessary. We can't open the logfile
4023 * when encountering either of the logging options (-d or -D) because the
4024 * other one may be encountered later on the command line, changing the
4025 * location or level of logging.
4030 qemu_set_log_filename(log_file);
4033 mask = qemu_str_to_log_mask(log_mask);
4035 qemu_print_log_usage(stdout);
4041 if (!is_daemonized()) {
4042 if (!trace_init_backends(trace_events, trace_file)) {
4047 /* If no data_dir is specified then try to find it relative to the
4049 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
4050 data_dir[data_dir_idx] = os_find_datadir();
4051 if (data_dir[data_dir_idx] != NULL) {
4055 /* If all else fails use the install path specified when building. */
4056 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
4057 data_dir[data_dir_idx++] = CONFIG_QEMU_DATADIR;
4060 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
4062 machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */
4063 if (smp_cpus > machine_class->max_cpus) {
4064 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
4065 "supported by machine `%s' (%d)\n", smp_cpus,
4066 machine_class->name, machine_class->max_cpus);
4071 * Get the default machine options from the machine if it is not already
4072 * specified either by the configuration file or by the command line.
4074 if (machine_class->default_machine_opts) {
4075 qemu_opts_set_defaults(qemu_find_opts("machine"),
4076 machine_class->default_machine_opts, 0);
4079 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
4080 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
4082 if (!vga_model && !default_vga) {
4083 vga_interface_type = VGA_DEVICE;
4085 if (!has_defaults || machine_class->no_serial) {
4088 if (!has_defaults || machine_class->no_parallel) {
4089 default_parallel = 0;
4091 if (!has_defaults || !machine_class->use_virtcon) {
4092 default_virtcon = 0;
4094 if (!has_defaults || !machine_class->use_sclp) {
4097 if (!has_defaults || machine_class->no_floppy) {
4100 if (!has_defaults || machine_class->no_cdrom) {
4103 if (!has_defaults || machine_class->no_sdcard) {
4106 if (!has_defaults) {
4107 default_monitor = 0;
4112 if (is_daemonized()) {
4113 /* According to documentation and historically, -nographic redirects
4114 * serial port, parallel port and monitor to stdio, which does not work
4115 * with -daemonize. We can redirect these to null instead, but since
4116 * -nographic is legacy, let's just error out.
4117 * We disallow -nographic only if all other ports are not redirected
4118 * explicitly, to not break existing legacy setups which uses
4119 * -nographic _and_ redirects all ports explicitly - this is valid
4120 * usage, -nographic is just a no-op in this case.
4122 if (display_type == DT_NOGRAPHIC
4123 && (default_parallel || default_serial
4124 || default_monitor || default_virtcon)) {
4125 fprintf(stderr, "-nographic can not be used with -daemonize\n");
4128 #ifdef CONFIG_CURSES
4129 if (display_type == DT_CURSES) {
4130 fprintf(stderr, "curses display can not be used with -daemonize\n");
4136 if (display_type == DT_NOGRAPHIC) {
4137 if (default_parallel)
4138 add_device_config(DEV_PARALLEL, "null");
4139 if (default_serial && default_monitor) {
4140 add_device_config(DEV_SERIAL, "mon:stdio");
4141 } else if (default_virtcon && default_monitor) {
4142 add_device_config(DEV_VIRTCON, "mon:stdio");
4143 } else if (default_sclp && default_monitor) {
4144 add_device_config(DEV_SCLP, "mon:stdio");
4147 add_device_config(DEV_SERIAL, "stdio");
4148 if (default_virtcon)
4149 add_device_config(DEV_VIRTCON, "stdio");
4151 add_device_config(DEV_SCLP, "stdio");
4153 if (default_monitor)
4154 monitor_parse("stdio", "readline");
4158 add_device_config(DEV_SERIAL, "vc:80Cx24C");
4159 if (default_parallel)
4160 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
4161 if (default_monitor)
4162 monitor_parse("vc:80Cx24C", "readline");
4163 if (default_virtcon)
4164 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
4166 add_device_config(DEV_SCLP, "vc:80Cx24C");
4170 if (display_type == DT_DEFAULT && !display_remote) {
4171 #if defined(CONFIG_MARU)
4172 // If no display_type is specified,
4173 // we use DT_MARU_QT_OFFSCREEN
4174 #if defined(CONFIG_QT)
4175 display_type = DT_MARU_QT_OFFSCREEN;
4176 #elif defined(CONFIG_SDL) && defined(CONFIG_JAVA_UI)
4177 display_type = DT_MARU_SDL;
4178 #elif defined(CONFIG_USE_SHM) && defined(CONFIG_JAVA_UI)
4179 display_type = DT_MARU_SHM;
4181 #elif defined(CONFIG_GTK)
4182 display_type = DT_GTK;
4183 #elif defined(CONFIG_SDL) || defined(CONFIG_COCOA)
4184 display_type = DT_SDL;
4185 #elif defined(CONFIG_VNC)
4186 vnc_display = "localhost:0,to=99";
4189 display_type = DT_NONE;
4193 if ((no_frame || alt_grab || ctrl_grab) && display_type != DT_SDL) {
4194 fprintf(stderr, "-no-frame, -alt-grab and -ctrl-grab are only valid "
4195 "for SDL, ignoring option\n");
4197 if (no_quit && (display_type != DT_GTK && display_type != DT_SDL)) {
4198 fprintf(stderr, "-no-quit is only valid for GTK and SDL, "
4199 "ignoring option\n");
4202 #if defined(CONFIG_GTK)
4203 if (display_type == DT_GTK) {
4204 early_gtk_display_init();
4209 # if defined(CONFIG_QT)
4210 if (display_type == DT_MARU_QT_ONSCREEN) {
4211 maru_early_qt5_display_init(true);
4212 } else if (display_type == DT_MARU_QT_OFFSCREEN) {
4213 maru_early_qt5_display_init(false);
4220 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
4222 #ifdef CONFIG_VIRTFS
4223 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
4228 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
4229 fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
4233 /* store value for the future use */
4234 qemu_opt_set_number(qemu_find_opts_singleton("memory"), "size", ram_size);
4236 current_machine->ram_size = ram_size;
4238 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0)
4243 if (qemu_opts_foreach(qemu_find_opts("object"),
4244 object_create, NULL, 0) != 0) {
4248 machine_opts = qemu_get_machine_opts();
4249 if (qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
4251 object_unref(OBJECT(current_machine));
4255 configure_accelerator(current_machine);
4258 Error *local_err = NULL;
4259 qtest_init(qtest_chrdev, qtest_log, &local_err);
4261 error_report("%s", error_get_pretty(local_err));
4262 error_free(local_err);
4267 machine_opts = qemu_get_machine_opts();
4268 kernel_filename = qemu_opt_get(machine_opts, "kernel");
4269 initrd_filename = qemu_opt_get(machine_opts, "initrd");
4270 kernel_cmdline = qemu_opt_get(machine_opts, "append");
4271 bios_name = qemu_opt_get(machine_opts, "firmware");
4273 boot_order = machine_class->default_boot_order;
4274 opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
4276 char *normal_boot_order;
4277 const char *order, *once;
4279 order = qemu_opt_get(opts, "order");
4281 validate_bootdevices(order);
4285 once = qemu_opt_get(opts, "once");
4287 validate_bootdevices(once);
4288 normal_boot_order = g_strdup(boot_order);
4290 qemu_register_reset(restore_boot_order, normal_boot_order);
4293 boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu);
4294 boot_strict = qemu_opt_get_bool(opts, "strict", false);
4297 if (!kernel_cmdline) {
4298 kernel_cmdline = "";
4299 current_machine->kernel_cmdline = (char *)kernel_cmdline;
4302 linux_boot = (kernel_filename != NULL);
4304 if (!linux_boot && *kernel_cmdline != '\0') {
4305 fprintf(stderr, "-append only allowed with -kernel option\n");
4309 if (!linux_boot && initrd_filename != NULL) {
4310 fprintf(stderr, "-initrd only allowed with -kernel option\n");
4314 if (!linux_boot && qemu_opt_get(machine_opts, "dtb")) {
4315 fprintf(stderr, "-dtb only allowed with -kernel option\n");
4319 os_set_line_buffering();
4321 qemu_init_cpu_loop();
4322 qemu_mutex_lock_iothread();
4325 /* spice needs the timers to be initialized by this point */
4331 if (kvm_enabled() || xen_enabled() || hax_enabled()) {
4332 fprintf(stderr, "-icount is not allowed with kvm or xen\n");
4335 configure_icount(icount_opts, &error_abort);
4336 qemu_opts_del(icount_opts);
4339 /* clean up network at qemu process termination */
4340 atexit(&net_cleanup);
4342 if (net_init_clients() < 0) {
4347 if (tpm_init() < 0) {
4352 /* init the bluetooth world */
4353 if (foreach_device_config(DEV_BT, bt_parse))
4356 if (!xen_enabled()) {
4357 /* On 32-bit hosts, QEMU is limited by virtual address space */
4358 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
4359 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
4367 /* If the currently selected machine wishes to override the units-per-bus
4368 * property of its default HBA interface type, do so now. */
4369 if (machine_class->units_per_default_bus) {
4370 override_max_devs(machine_class->block_default_type,
4371 machine_class->units_per_default_bus);
4374 /* open the virtual block devices */
4376 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
4377 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func,
4378 &machine_class->block_default_type, 1) != 0) {
4382 default_drive(default_cdrom, snapshot, machine_class->block_default_type, 2,
4384 default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS);
4385 default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS);
4387 if (qemu_opts_foreach(qemu_find_opts("numa"), numa_init_func,
4394 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
4398 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
4400 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
4402 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
4404 if (foreach_device_config(DEV_SCLP, sclp_parse) < 0) {
4407 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
4410 /* If no default VGA is requested, the default is "none". */
4412 if (machine_class->default_display) {
4413 vga_model = machine_class->default_display;
4414 } else if (cirrus_vga_available()) {
4415 vga_model = "cirrus";
4416 } else if (vga_available()) {
4421 select_vgahw(vga_model);
4425 i = select_watchdog(watchdog);
4427 exit (i == 1 ? 1 : 0);
4430 if (machine_class->compat_props) {
4431 qdev_prop_register_global_list(machine_class->compat_props);
4435 qdev_machine_init();
4437 current_machine->maxram_size = maxram_size;
4438 current_machine->ram_slots = ram_slots;
4439 current_machine->boot_order = boot_order;
4440 current_machine->cpu_model = cpu_model;
4442 machine_class->init(current_machine);
4446 // TODO: Check about it...
4449 cpu_synchronize_all_post_init();
4453 if (hax_enabled()) {
4457 /* init USB devices */
4458 if (usb_enabled(false)) {
4459 if (foreach_device_config(DEV_USB, usb_parse) < 0)
4463 /* init generic devices */
4464 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
4467 #if defined(CONFIG_MARU)
4468 prepare_maru_after_device_init();
4471 // To support legacy VIGS options
4473 PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
4474 PCIDevice *pci_dev = pci_create(pci_bus, -1, "vigs");
4476 qdev_prop_set_string(&pci_dev->qdev, "backend", vigs_backend);
4478 qdev_prop_set_string(&pci_dev->qdev, "backend", "gl");
4480 qdev_prop_set_string(&pci_dev->qdev, "wsi", "wsi0");
4481 qdev_init_nofail(&pci_dev->qdev);
4485 // To support legacy YaGL options
4487 PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
4488 PCIDevice *pci_dev = pci_create(pci_bus, -1, "yagl");
4490 qdev_prop_set_string(&pci_dev->qdev, "wsi", "wsi0");
4492 qdev_init_nofail(&pci_dev->qdev);
4496 /* Did we create any drives that we failed to create a device for? */
4497 drive_check_orphaned();
4499 net_check_clients();
4501 ds = init_displaystate();
4503 /* init local displays */
4504 switch (display_type) {
4506 (void)ds; /* avoid warning if no display is configured */
4508 #if defined(CONFIG_CURSES)
4510 curses_display_init(ds, full_screen);
4513 #if defined(CONFIG_SDL)
4515 sdl_display_init(ds, full_screen, no_frame);
4517 #elif defined(CONFIG_COCOA)
4519 cocoa_display_init(ds, full_screen);
4522 #if defined(CONFIG_GTK)
4524 gtk_display_init(ds, full_screen, grab_on_hover);
4527 #if defined(CONFIG_MARU)
4528 #if defined(CONFIG_JAVA_UI)
4531 maru_display_init(ds, display_type, full_screen);
4532 start_skin(skin_enabled);
4535 #if defined(CONFIG_QT)
4536 case DT_MARU_QT_ONSCREEN:
4537 case DT_MARU_QT_OFFSCREEN:
4538 maru_qt5_display_init(ds, full_screen);
4546 /* must be after terminal init, SDL library changes signal handlers */
4547 os_setup_signal_handling();
4550 /* init remote displays */
4552 Error *local_err = NULL;
4553 vnc_display_init(ds);
4554 vnc_display_open(ds, vnc_display, &local_err);
4555 if (local_err != NULL) {
4556 error_report("Failed to start VNC server on `%s': %s",
4557 vnc_display, error_get_pretty(local_err));
4558 error_free(local_err);
4562 if (show_vnc_port) {
4563 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
4569 qemu_spice_display_init();
4573 if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
4577 qdev_machine_creation_done();
4579 if (rom_load_all() != 0) {
4580 fprintf(stderr, "rom loading failed\n");
4584 /* TODO: once all bus devices are qdevified, this should be done
4585 * when bus is created by qdev.c */
4586 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
4587 qemu_run_machine_init_done_notifiers();
4589 /* Done notifiers can load ROMs */
4592 qemu_system_reset(VMRESET_SILENT);
4594 if (load_vmstate(loadvm) < 0) {
4599 qdev_prop_check_globals();
4600 if (vmstate_dump_file) {
4602 dump_vmstate_json_to_file(vmstate_dump_file);
4607 Error *local_err = NULL;
4608 qemu_start_incoming_migration(incoming, &local_err);
4610 error_report("-incoming %s: %s", incoming,
4611 error_get_pretty(local_err));
4612 error_free(local_err);
4615 } else if (autostart) {
4621 if (is_daemonized()) {
4622 if (!trace_init_backends(trace_events, trace_file)) {
4628 enable_print_backtrace_at_normal_exit();