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 "qemu/bitmap.h"
33 /* Needed early for CONFIG_BSD etc. */
34 #include "config-host.h"
38 #include <sys/times.h>
42 #include <sys/ioctl.h>
43 #include <sys/resource.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
47 #include <arpa/inet.h>
50 #include <sys/select.h>
54 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
55 #include <sys/sysctl.h>
63 #include <linux/ppdev.h>
64 #include <linux/parport.h>
68 #include "sysemu/seccomp.h"
73 #include <sys/ethernet.h>
74 #include <sys/sockio.h>
75 #include <netinet/arp.h>
76 #include <netinet/in_systm.h>
77 #include <netinet/ip.h>
78 #include <netinet/ip_icmp.h> // must come after ip.h
79 #include <netinet/udp.h>
80 #include <netinet/tcp.h>
88 #if defined(CONFIG_VDE)
89 #include <libvdeplug.h>
97 #if defined(__APPLE__) || defined(main)
100 int qemu_main(int argc, char **argv, char **envp);
101 int main(int argc, char **argv)
103 return qemu_main(argc, argv, NULL);
106 #define main qemu_main
109 #endif /* CONFIG_SDL */
113 #define main qemu_main
114 #endif /* CONFIG_COCOA */
120 int qemu_main(int argc, char **argv, char **envp);
121 #define main qemu_main
127 #include "hw/boards.h"
129 #include "hw/pcmcia.h"
130 #include "hw/i386/pc.h"
131 #include "hw/isa/isa.h"
133 #include "sysemu/watchdog.h"
134 #include "hw/i386/smbios.h"
135 #include "hw/xen/xen.h"
137 #include "hw/loader.h"
138 #include "monitor/qdev.h"
139 #include "sysemu/bt.h"
141 #include "net/slirp.h"
142 #include "monitor/monitor.h"
143 #include "ui/console.h"
144 #include "sysemu/sysemu.h"
145 #include "exec/gdbstub.h"
146 #include "qemu/timer.h"
147 #include "sysemu/char.h"
148 #include "qemu/cache-utils.h"
149 #include "sysemu/blockdev.h"
150 #include "hw/block/block.h"
151 #include "migration/block.h"
152 #include "sysemu/tpm.h"
153 #include "sysemu/dma.h"
154 #include "audio/audio.h"
155 #include "migration/migration.h"
156 #include "sysemu/kvm.h"
157 #include "sysemu/hax.h"
158 #include "qapi/qmp/qjson.h"
159 #include "qemu/option.h"
160 #include "qemu/config-file.h"
161 #include "qemu-options.h"
162 #include "qmp-commands.h"
163 #include "qemu/main-loop.h"
165 #include "fsdev/qemu-fsdev.h"
167 #include "sysemu/qtest.h"
169 #include "disas/disas.h"
171 #include "qemu/sockets.h"
173 #include "slirp/libslirp.h"
176 #include "trace/control.h"
177 #include "qemu/queue.h"
178 #include "sysemu/cpus.h"
179 #include "sysemu/arch_init.h"
180 #include "qemu/osdep.h"
182 #include "ui/qemu-spice.h"
183 #include "qapi/string-input-visitor.h"
186 #include "tizen/src/maru_common.h"
187 #include "tizen/src/emulator.h"
188 #include "tizen/src/maru_err_table.h"
189 #include "tizen/src/emul_state.h"
190 #include "tizen/src/maru_display.h"
191 #include "tizen/src/skin/maruskin_operation.h"
195 //#define DEBUG_SLIRP
197 #define DEFAULT_RAM_SIZE 128
199 #define MAX_VIRTIO_CONSOLES 1
200 #define MAX_SCLP_CONSOLES 1
203 int skin_disabled = 0;
205 extern int enable_gl;
206 extern int enable_yagl;
209 static const char *data_dir[16];
210 static int data_dir_idx;
211 const char *bios_name = NULL;
212 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
213 DisplayType display_type = DT_DEFAULT;
214 static int display_remote;
215 const char* keyboard_layout = NULL;
217 const char *mem_path = NULL;
219 int mem_prealloc = 0; /* force preallocation of physical target memory */
222 NICInfo nd_table[MAX_NICS];
224 static int rtc_utc = 1;
225 static int rtc_date_offset = -1; /* -1 means no change */
226 QEMUClock *rtc_clock;
227 int vga_interface_type = VGA_NONE;
228 static int full_screen = 0;
230 static int no_frame = 0;
233 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
234 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
235 CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
236 CharDriverState *sclp_hds[MAX_SCLP_CONSOLES];
237 int win2k_install_hack = 0;
244 const char *vnc_display;
246 int acpi_enabled = 1;
249 static int no_reboot;
252 int graphic_rotate = 0;
253 const char *watchdog;
254 QEMUOptionRom option_rom[MAX_OPTION_ROMS];
256 int semihosting_enabled = 0;
258 const char *qemu_name;
261 unsigned int nb_prom_envs = 0;
262 const char *prom_envs[MAX_PROM_ENVS];
265 uint8_t *boot_splash_filedata;
266 size_t boot_splash_filedata_size;
267 uint8_t qemu_extra_params_fw[2];
270 typedef struct FWBootEntry FWBootEntry;
273 QTAILQ_ENTRY(FWBootEntry) link;
279 static QTAILQ_HEAD(, FWBootEntry) fw_boot_order =
280 QTAILQ_HEAD_INITIALIZER(fw_boot_order);
283 uint64_t node_mem[MAX_NODES];
284 unsigned long *node_cpumask[MAX_NODES];
286 uint8_t qemu_uuid[16];
288 static QEMUBootSetHandler *boot_set_handler;
289 static void *boot_set_opaque;
291 static NotifierList exit_notifiers =
292 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
294 static NotifierList machine_init_done_notifiers =
295 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
297 static bool tcg_allowed = true;
303 enum xen_mode xen_mode = XEN_EMULATE;
304 static int tcg_tb_size;
306 static int default_serial = 1;
307 static int default_parallel = 1;
308 static int default_virtcon = 1;
309 static int default_sclp = 1;
310 static int default_monitor = 1;
311 static int default_floppy = 1;
312 static int default_cdrom = 1;
313 static int default_sdcard = 1;
314 static int default_vga = 1;
320 { .driver = "isa-serial", .flag = &default_serial },
321 { .driver = "isa-parallel", .flag = &default_parallel },
322 { .driver = "isa-fdc", .flag = &default_floppy },
323 { .driver = "ide-cd", .flag = &default_cdrom },
324 { .driver = "ide-hd", .flag = &default_cdrom },
325 { .driver = "ide-drive", .flag = &default_cdrom },
326 { .driver = "scsi-cd", .flag = &default_cdrom },
327 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
328 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
329 { .driver = "virtio-serial", .flag = &default_virtcon },
330 { .driver = "VGA", .flag = &default_vga },
331 { .driver = "isa-vga", .flag = &default_vga },
332 { .driver = "cirrus-vga", .flag = &default_vga },
333 { .driver = "isa-cirrus-vga", .flag = &default_vga },
334 { .driver = "vmware-svga", .flag = &default_vga },
335 { .driver = "qxl-vga", .flag = &default_vga },
338 static QemuOptsList qemu_rtc_opts = {
340 .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head),
344 .type = QEMU_OPT_STRING,
347 .type = QEMU_OPT_STRING,
350 .type = QEMU_OPT_STRING,
352 { /* end of list */ }
356 static QemuOptsList qemu_sandbox_opts = {
358 .implied_opt_name = "enable",
359 .head = QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts.head),
363 .type = QEMU_OPT_BOOL,
365 { /* end of list */ }
369 static QemuOptsList qemu_trace_opts = {
371 .implied_opt_name = "trace",
372 .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
376 .type = QEMU_OPT_STRING,
379 .type = QEMU_OPT_STRING,
381 { /* end of list */ }
385 static QemuOptsList qemu_option_rom_opts = {
386 .name = "option-rom",
387 .implied_opt_name = "romfile",
388 .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head),
392 .type = QEMU_OPT_NUMBER,
395 .type = QEMU_OPT_STRING,
397 { /* end of list */ }
401 static QemuOptsList qemu_machine_opts = {
403 .implied_opt_name = "type",
405 .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
409 .type = QEMU_OPT_STRING,
410 .help = "emulated machine"
413 .type = QEMU_OPT_STRING,
414 .help = "accelerator list",
416 .name = "kernel_irqchip",
417 .type = QEMU_OPT_BOOL,
418 .help = "use KVM in-kernel irqchip",
420 .name = "kvm_shadow_mem",
421 .type = QEMU_OPT_SIZE,
422 .help = "KVM shadow MMU size",
425 .type = QEMU_OPT_STRING,
426 .help = "Linux kernel image file",
429 .type = QEMU_OPT_STRING,
430 .help = "Linux initial ramdisk file",
433 .type = QEMU_OPT_STRING,
434 .help = "Linux kernel command line",
437 .type = QEMU_OPT_STRING,
438 .help = "Linux kernel device tree file",
441 .type = QEMU_OPT_STRING,
442 .help = "Dump current dtb to a file and quit",
444 .name = "phandle_start",
445 .type = QEMU_OPT_STRING,
446 .help = "The first phandle ID we may generate dynamically",
448 .name = "dt_compatible",
449 .type = QEMU_OPT_STRING,
450 .help = "Overrides the \"compatible\" property of the dt root node",
452 .name = "dump-guest-core",
453 .type = QEMU_OPT_BOOL,
454 .help = "Include guest memory in a core dump",
457 .type = QEMU_OPT_BOOL,
458 .help = "enable/disable memory merge support",
461 .type = QEMU_OPT_BOOL,
462 .help = "Set on/off to enable/disable usb",
464 { /* End of list */ }
468 static QemuOptsList qemu_boot_opts = {
470 .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head),
472 /* the three names below are not used now */
475 .type = QEMU_OPT_STRING,
478 .type = QEMU_OPT_STRING,
481 .type = QEMU_OPT_STRING,
482 /* following are really used */
485 .type = QEMU_OPT_STRING,
487 .name = "splash-time",
488 .type = QEMU_OPT_STRING,
490 .name = "reboot-timeout",
491 .type = QEMU_OPT_STRING,
494 .type = QEMU_OPT_STRING,
500 static QemuOptsList qemu_add_fd_opts = {
502 .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head),
506 .type = QEMU_OPT_NUMBER,
507 .help = "file descriptor of which a duplicate is added to fd set",
510 .type = QEMU_OPT_NUMBER,
511 .help = "ID of the fd set to add fd to",
514 .type = QEMU_OPT_STRING,
515 .help = "free-form string used to describe fd",
517 { /* end of list */ }
521 static QemuOptsList qemu_object_opts = {
523 .implied_opt_name = "qom-type",
524 .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
530 static QemuOptsList qemu_tpmdev_opts = {
532 .implied_opt_name = "type",
533 .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head),
535 /* options are defined in the TPM backends */
536 { /* end of list */ }
540 static QemuOptsList qemu_realtime_opts = {
542 .head = QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts.head),
546 .type = QEMU_OPT_BOOL,
548 { /* end of list */ }
552 const char *qemu_get_vm_name(void)
557 static void res_free(void)
559 if (boot_splash_filedata != NULL) {
560 g_free(boot_splash_filedata);
561 boot_splash_filedata = NULL;
565 static int default_driver_check(QemuOpts *opts, void *opaque)
567 const char *driver = qemu_opt_get(opts, "driver");
572 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
573 if (strcmp(default_list[i].driver, driver) != 0)
575 *(default_list[i].flag) = 0;
580 /***********************************************************/
583 static RunState current_run_state = RUN_STATE_PRELAUNCH;
588 } RunStateTransition;
590 static const RunStateTransition runstate_transitions_def[] = {
592 { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
594 { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },
595 { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED },
597 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
598 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
600 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
601 { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE },
603 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
604 { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
606 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
607 { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
609 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
610 { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
611 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
613 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
614 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
616 { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
618 { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
619 { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
620 { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
621 { RUN_STATE_RUNNING, RUN_STATE_PAUSED },
622 { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE },
623 { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM },
624 { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM },
625 { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
626 { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
627 { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED },
629 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
631 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
632 { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
634 { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
635 { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
636 { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },
637 { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
639 { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
640 { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
642 { RUN_STATE_GUEST_PANICKED, RUN_STATE_PAUSED },
643 { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE },
645 { RUN_STATE_MAX, RUN_STATE_MAX },
648 static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX];
650 bool runstate_check(RunState state)
652 return current_run_state == state;
655 static void runstate_init(void)
657 const RunStateTransition *p;
659 memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions));
661 for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) {
662 runstate_valid_transitions[p->from][p->to] = true;
666 /* This function will abort() on invalid state transitions */
667 void runstate_set(RunState new_state)
669 assert(new_state < RUN_STATE_MAX);
671 if (!runstate_valid_transitions[current_run_state][new_state]) {
672 fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
673 RunState_lookup[current_run_state],
674 RunState_lookup[new_state]);
677 trace_runstate_set(new_state);
678 current_run_state = new_state;
681 int runstate_is_running(void)
683 return runstate_check(RUN_STATE_RUNNING);
686 bool runstate_needs_reset(void)
688 return runstate_check(RUN_STATE_INTERNAL_ERROR) ||
689 runstate_check(RUN_STATE_SHUTDOWN) ||
690 runstate_check(RUN_STATE_GUEST_PANICKED);
693 StatusInfo *qmp_query_status(Error **errp)
695 StatusInfo *info = g_malloc0(sizeof(*info));
697 info->running = runstate_is_running();
698 info->singlestep = singlestep;
699 info->status = current_run_state;
704 /***********************************************************/
705 /* real time host monotonic timer */
707 /***********************************************************/
708 /* host time/date access */
709 void qemu_get_timedate(struct tm *tm, int offset)
715 if (rtc_date_offset == -1) {
719 localtime_r(&ti, tm);
721 ti -= rtc_date_offset;
726 int qemu_timedate_diff(struct tm *tm)
730 if (rtc_date_offset == -1)
732 seconds = mktimegm(tm);
735 tmp.tm_isdst = -1; /* use timezone to figure it out */
736 seconds = mktime(&tmp);
739 seconds = mktimegm(tm) + rtc_date_offset;
741 return seconds - time(NULL);
744 void rtc_change_mon_event(struct tm *tm)
748 data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
749 monitor_protocol_event(QEVENT_RTC_CHANGE, data);
750 qobject_decref(data);
753 static void configure_rtc_date_offset(const char *startdate, int legacy)
755 time_t rtc_start_date;
758 if (!strcmp(startdate, "now") && legacy) {
759 rtc_date_offset = -1;
761 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
769 } else if (sscanf(startdate, "%d-%d-%d",
781 rtc_start_date = mktimegm(&tm);
782 if (rtc_start_date == -1) {
784 fprintf(stderr, "Invalid date format. Valid formats are:\n"
785 "'2006-06-17T16:01:21' or '2006-06-17'\n");
788 rtc_date_offset = time(NULL) - rtc_start_date;
792 static void configure_rtc(QemuOpts *opts)
796 value = qemu_opt_get(opts, "base");
798 if (!strcmp(value, "utc")) {
800 } else if (!strcmp(value, "localtime")) {
803 configure_rtc_date_offset(value, 0);
806 value = qemu_opt_get(opts, "clock");
808 if (!strcmp(value, "host")) {
809 rtc_clock = host_clock;
810 } else if (!strcmp(value, "rt")) {
811 rtc_clock = rt_clock;
812 } else if (!strcmp(value, "vm")) {
813 rtc_clock = vm_clock;
815 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
819 value = qemu_opt_get(opts, "driftfix");
821 if (!strcmp(value, "slew")) {
822 static GlobalProperty slew_lost_ticks[] = {
824 .driver = "mc146818rtc",
825 .property = "lost_tick_policy",
828 { /* end of list */ }
831 qdev_prop_register_global_list(slew_lost_ticks);
832 } else if (!strcmp(value, "none")) {
833 /* discard is default */
835 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
841 /***********************************************************/
842 /* Bluetooth support */
845 static struct HCIInfo *hci_table[MAX_NICS];
847 static struct bt_vlan_s {
848 struct bt_scatternet_s net;
850 struct bt_vlan_s *next;
853 /* find or alloc a new bluetooth "VLAN" */
854 static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
856 struct bt_vlan_s **pvlan, *vlan;
857 for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) {
861 vlan = g_malloc0(sizeof(struct bt_vlan_s));
863 pvlan = &first_bt_vlan;
864 while (*pvlan != NULL)
865 pvlan = &(*pvlan)->next;
870 static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
874 static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
879 static struct HCIInfo null_hci = {
880 .cmd_send = null_hci_send,
881 .sco_send = null_hci_send,
882 .acl_send = null_hci_send,
883 .bdaddr_set = null_hci_addr_set,
886 struct HCIInfo *qemu_next_hci(void)
888 if (cur_hci == nb_hcis)
891 return hci_table[cur_hci++];
894 static struct HCIInfo *hci_init(const char *str)
897 struct bt_scatternet_s *vlan = 0;
899 if (!strcmp(str, "null"))
902 else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':'))
904 return bt_host_hci(str[4] ? str + 5 : "hci0");
905 else if (!strncmp(str, "hci", 3)) {
908 if (!strncmp(str + 3, ",vlan=", 6)) {
909 vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0));
914 vlan = qemu_find_bt_vlan(0);
916 return bt_new_hci(vlan);
919 fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
924 static int bt_hci_parse(const char *str)
929 if (nb_hcis >= MAX_NICS) {
930 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
943 bdaddr.b[5] = 0x56 + nb_hcis;
944 hci->bdaddr_set(hci, bdaddr.b);
946 hci_table[nb_hcis++] = hci;
951 static void bt_vhci_add(int vlan_id)
953 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
956 fprintf(stderr, "qemu: warning: adding a VHCI to "
957 "an empty scatternet %i\n", vlan_id);
959 bt_vhci_init(bt_new_hci(vlan));
962 static struct bt_device_s *bt_device_add(const char *opt)
964 struct bt_scatternet_s *vlan;
966 char *endp = strstr(opt, ",vlan=");
967 int len = (endp ? endp - opt : strlen(opt)) + 1;
970 pstrcpy(devname, MIN(sizeof(devname), len), opt);
973 vlan_id = strtol(endp + 6, &endp, 0);
975 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
980 vlan = qemu_find_bt_vlan(vlan_id);
983 fprintf(stderr, "qemu: warning: adding a slave device to "
984 "an empty scatternet %i\n", vlan_id);
986 if (!strcmp(devname, "keyboard"))
987 return bt_keyboard_init(vlan);
989 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
993 static int bt_parse(const char *opt)
995 const char *endp, *p;
998 if (strstart(opt, "hci", &endp)) {
999 if (!*endp || *endp == ',') {
1001 if (!strstart(endp, ",vlan=", 0))
1004 return bt_hci_parse(opt);
1006 } else if (strstart(opt, "vhci", &endp)) {
1007 if (!*endp || *endp == ',') {
1009 if (strstart(endp, ",vlan=", &p)) {
1010 vlan = strtol(p, (char **) &endp, 0);
1012 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
1016 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
1025 } else if (strstart(opt, "device:", &endp))
1026 return !bt_device_add(endp);
1028 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
1032 static int parse_sandbox(QemuOpts *opts, void *opaque)
1034 /* FIXME: change this to true for 1.3 */
1035 if (qemu_opt_get_bool(opts, "enable", false)) {
1036 #ifdef CONFIG_SECCOMP
1037 if (seccomp_start() < 0) {
1038 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1039 "failed to install seccomp syscall filter in the kernel");
1043 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1044 "sandboxing request but seccomp is not compiled into this build");
1052 /*********QEMU USB setting******/
1053 bool usb_enabled(bool default_usb)
1055 QemuOpts *mach_opts;
1056 mach_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
1058 return qemu_opt_get_bool(mach_opts, "usb", default_usb);
1064 static int parse_add_fd(QemuOpts *opts, void *opaque)
1066 int fd, dupfd, flags;
1068 const char *fd_opaque = NULL;
1070 fd = qemu_opt_get_number(opts, "fd", -1);
1071 fdset_id = qemu_opt_get_number(opts, "set", -1);
1072 fd_opaque = qemu_opt_get(opts, "opaque");
1075 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1076 "fd option is required and must be non-negative");
1080 if (fd <= STDERR_FILENO) {
1081 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1082 "fd cannot be a standard I/O stream");
1087 * All fds inherited across exec() necessarily have FD_CLOEXEC
1088 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1090 flags = fcntl(fd, F_GETFD);
1091 if (flags == -1 || (flags & FD_CLOEXEC)) {
1092 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1093 "fd is not valid or already in use");
1098 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1099 "set option is required and must be non-negative");
1103 #ifdef F_DUPFD_CLOEXEC
1104 dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
1108 qemu_set_cloexec(dupfd);
1112 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1113 "Error duplicating fd: %s", strerror(errno));
1117 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1118 monitor_fdset_add_fd(dupfd, true, fdset_id, fd_opaque ? true : false,
1124 static int cleanup_add_fd(QemuOpts *opts, void *opaque)
1128 fd = qemu_opt_get_number(opts, "fd", -1);
1135 /***********************************************************/
1136 /* QEMU Block devices */
1138 #define HD_OPTS "media=disk"
1139 #define CDROM_OPTS "media=cdrom"
1141 #define PFLASH_OPTS ""
1145 static int drive_init_func(QemuOpts *opts, void *opaque)
1147 BlockInterfaceType *block_default_type = opaque;
1149 return drive_init(opts, *block_default_type) == NULL;
1152 static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
1154 if (NULL == qemu_opt_get(opts, "snapshot")) {
1155 qemu_opt_set(opts, "snapshot", "on");
1160 static void default_drive(int enable, int snapshot, BlockInterfaceType type,
1161 int index, const char *optstr)
1165 if (!enable || drive_get_by_index(type, index)) {
1169 opts = drive_add(type, index, NULL, optstr);
1171 drive_enable_snapshot(opts, NULL);
1173 if (!drive_init(opts, type)) {
1178 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
1180 boot_set_handler = func;
1181 boot_set_opaque = opaque;
1184 int qemu_boot_set(const char *boot_devices)
1186 if (!boot_set_handler) {
1189 return boot_set_handler(boot_set_opaque, boot_devices);
1192 static void validate_bootdevices(char *devices)
1194 /* We just do some generic consistency checks */
1198 for (p = devices; *p != '\0'; p++) {
1199 /* Allowed boot devices are:
1200 * a-b: floppy disk drives
1201 * c-f: IDE disk drives
1202 * g-m: machine implementation dependent drives
1203 * n-p: network devices
1204 * It's up to each machine implementation to check if the given boot
1205 * devices match the actual hardware implementation and firmware
1208 if (*p < 'a' || *p > 'p') {
1209 fprintf(stderr, "Invalid boot device '%c'\n", *p);
1212 if (bitmap & (1 << (*p - 'a'))) {
1213 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
1216 bitmap |= 1 << (*p - 'a');
1220 static void restore_boot_devices(void *opaque)
1222 char *standard_boot_devices = opaque;
1223 static int first = 1;
1225 /* Restore boot order and remove ourselves after the first boot */
1231 qemu_boot_set(standard_boot_devices);
1233 qemu_unregister_reset(restore_boot_devices, standard_boot_devices);
1234 g_free(standard_boot_devices);
1237 void add_boot_device_path(int32_t bootindex, DeviceState *dev,
1240 FWBootEntry *node, *i;
1242 if (bootindex < 0) {
1246 assert(dev != NULL || suffix != NULL);
1248 node = g_malloc0(sizeof(FWBootEntry));
1249 node->bootindex = bootindex;
1250 node->suffix = g_strdup(suffix);
1253 QTAILQ_FOREACH(i, &fw_boot_order, link) {
1254 if (i->bootindex == bootindex) {
1255 fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
1257 } else if (i->bootindex < bootindex) {
1260 QTAILQ_INSERT_BEFORE(i, node, link);
1263 QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
1266 DeviceState *get_boot_device(uint32_t position)
1268 uint32_t counter = 0;
1269 FWBootEntry *i = NULL;
1270 DeviceState *res = NULL;
1272 if (!QTAILQ_EMPTY(&fw_boot_order)) {
1273 QTAILQ_FOREACH(i, &fw_boot_order, link) {
1274 if (counter == position) {
1285 * This function returns null terminated string that consist of new line
1286 * separated device paths.
1288 * memory pointed by "size" is assigned total length of the array in bytes
1291 char *get_boot_devices_list(size_t *size)
1297 QTAILQ_FOREACH(i, &fw_boot_order, link) {
1298 char *devpath = NULL, *bootpath;
1302 devpath = qdev_get_fw_dev_path(i->dev);
1306 if (i->suffix && devpath) {
1307 size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
1309 bootpath = g_malloc(bootpathlen);
1310 snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
1312 } else if (devpath) {
1316 bootpath = g_strdup(i->suffix);
1320 list[total-1] = '\n';
1322 len = strlen(bootpath) + 1;
1323 list = g_realloc(list, total + len);
1324 memcpy(&list[total], bootpath, len);
1331 if (boot_strict && *size > 0) {
1332 list[total-1] = '\n';
1333 list = g_realloc(list, total + 5);
1334 memcpy(&list[total], "HALT", 5);
1340 static void numa_node_parse_cpus(int nodenr, const char *cpus)
1343 unsigned long long value, endvalue;
1345 /* Empty CPU range strings will be considered valid, they will simply
1346 * not set any bit in the CPU bitmap.
1352 if (parse_uint(cpus, &value, &endptr, 10) < 0) {
1355 if (*endptr == '-') {
1356 if (parse_uint_full(endptr + 1, &endvalue, 10) < 0) {
1359 } else if (*endptr == '\0') {
1365 if (endvalue >= MAX_CPUMASK_BITS) {
1366 endvalue = MAX_CPUMASK_BITS - 1;
1368 "qemu: NUMA: A max of %d VCPUs are supported\n",
1372 if (endvalue < value) {
1376 bitmap_set(node_cpumask[nodenr], value, endvalue-value+1);
1380 fprintf(stderr, "qemu: Invalid NUMA CPU range: %s\n", cpus);
1384 static void numa_add(const char *optarg)
1388 unsigned long long nodenr;
1390 optarg = get_opt_name(option, 128, optarg, ',');
1391 if (*optarg == ',') {
1394 if (!strcmp(option, "node")) {
1396 if (nb_numa_nodes >= MAX_NODES) {
1397 fprintf(stderr, "qemu: too many NUMA nodes\n");
1401 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
1402 nodenr = nb_numa_nodes;
1404 if (parse_uint_full(option, &nodenr, 10) < 0) {
1405 fprintf(stderr, "qemu: Invalid NUMA nodeid: %s\n", option);
1410 if (nodenr >= MAX_NODES) {
1411 fprintf(stderr, "qemu: invalid NUMA nodeid: %llu\n", nodenr);
1415 if (get_param_value(option, 128, "mem", optarg) == 0) {
1416 node_mem[nodenr] = 0;
1419 sval = strtosz(option, &endptr);
1420 if (sval < 0 || *endptr) {
1421 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
1424 node_mem[nodenr] = sval;
1426 if (get_param_value(option, 128, "cpus", optarg) != 0) {
1427 numa_node_parse_cpus(nodenr, option);
1431 fprintf(stderr, "Invalid -numa option: %s\n", option);
1436 static void smp_parse(const char *optarg)
1438 int smp, sockets = 0, threads = 0, cores = 0;
1442 smp = strtoul(optarg, &endptr, 10);
1443 if (endptr != optarg) {
1444 if (*endptr == ',') {
1448 if (get_param_value(option, 128, "sockets", endptr) != 0)
1449 sockets = strtoull(option, NULL, 10);
1450 if (get_param_value(option, 128, "cores", endptr) != 0)
1451 cores = strtoull(option, NULL, 10);
1452 if (get_param_value(option, 128, "threads", endptr) != 0)
1453 threads = strtoull(option, NULL, 10);
1454 if (get_param_value(option, 128, "maxcpus", endptr) != 0)
1455 max_cpus = strtoull(option, NULL, 10);
1457 /* compute missing values, prefer sockets over cores over threads */
1458 if (smp == 0 || sockets == 0) {
1459 sockets = sockets > 0 ? sockets : 1;
1460 cores = cores > 0 ? cores : 1;
1461 threads = threads > 0 ? threads : 1;
1463 smp = cores * threads * sockets;
1467 threads = threads > 0 ? threads : 1;
1468 cores = smp / (sockets * threads);
1470 threads = smp / (cores * sockets);
1474 smp_cores = cores > 0 ? cores : 1;
1475 smp_threads = threads > 0 ? threads : 1;
1477 max_cpus = smp_cpus;
1480 static void configure_realtime(QemuOpts *opts)
1484 enable_mlock = qemu_opt_get_bool(opts, "mlock", true);
1487 if (os_mlock() < 0) {
1488 fprintf(stderr, "qemu: locking memory failed\n");
1494 /***********************************************************/
1497 static int usb_device_add(const char *devname)
1500 USBDevice *dev = NULL;
1502 if (!usb_enabled(false)) {
1506 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1507 dev = usbdevice_create(devname);
1511 /* the other ones */
1512 #ifndef CONFIG_LINUX
1513 /* only the linux version is qdev-ified, usb-bsd still needs this */
1514 if (strstart(devname, "host:", &p)) {
1515 dev = usb_host_device_open(usb_bus_find(-1), p);
1518 if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
1519 dev = usb_bt_init(usb_bus_find(-1),
1520 devname[2] ? hci_init(p)
1521 : bt_new_hci(qemu_find_bt_vlan(0)));
1532 static int usb_device_del(const char *devname)
1537 if (strstart(devname, "host:", &p)) {
1541 if (!usb_enabled(false)) {
1545 p = strchr(devname, '.');
1548 bus_num = strtoul(devname, NULL, 0);
1549 addr = strtoul(p + 1, NULL, 0);
1551 return usb_device_delete_addr(bus_num, addr);
1554 static int usb_parse(const char *cmdline)
1557 r = usb_device_add(cmdline);
1559 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
1564 void do_usb_add(Monitor *mon, const QDict *qdict)
1566 const char *devname = qdict_get_str(qdict, "devname");
1567 if (usb_device_add(devname) < 0) {
1568 error_report("could not add USB device '%s'", devname);
1572 void do_usb_del(Monitor *mon, const QDict *qdict)
1574 const char *devname = qdict_get_str(qdict, "devname");
1575 if (usb_device_del(devname) < 0) {
1576 error_report("could not delete USB device '%s'", devname);
1580 /***********************************************************/
1581 /* PCMCIA/Cardbus */
1583 static struct pcmcia_socket_entry_s {
1584 PCMCIASocket *socket;
1585 struct pcmcia_socket_entry_s *next;
1586 } *pcmcia_sockets = 0;
1588 void pcmcia_socket_register(PCMCIASocket *socket)
1590 struct pcmcia_socket_entry_s *entry;
1592 entry = g_malloc(sizeof(struct pcmcia_socket_entry_s));
1593 entry->socket = socket;
1594 entry->next = pcmcia_sockets;
1595 pcmcia_sockets = entry;
1598 void pcmcia_socket_unregister(PCMCIASocket *socket)
1600 struct pcmcia_socket_entry_s *entry, **ptr;
1602 ptr = &pcmcia_sockets;
1603 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1604 if (entry->socket == socket) {
1610 void pcmcia_info(Monitor *mon, const QDict *qdict)
1612 struct pcmcia_socket_entry_s *iter;
1614 if (!pcmcia_sockets)
1615 monitor_printf(mon, "No PCMCIA sockets\n");
1617 for (iter = pcmcia_sockets; iter; iter = iter->next)
1618 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1619 iter->socket->attached ? iter->socket->card_string :
1623 /***********************************************************/
1624 /* machine registration */
1626 static QEMUMachine *first_machine = NULL;
1627 QEMUMachine *current_machine = NULL;
1629 int qemu_register_machine(QEMUMachine *m)
1632 pm = &first_machine;
1640 static QEMUMachine *find_machine(const char *name)
1644 for(m = first_machine; m != NULL; m = m->next) {
1645 if (!strcmp(m->name, name))
1647 if (m->alias && !strcmp(m->alias, name))
1653 QEMUMachine *find_default_machine(void)
1657 for(m = first_machine; m != NULL; m = m->next) {
1658 if (m->is_default) {
1665 MachineInfoList *qmp_query_machines(Error **errp)
1667 MachineInfoList *mach_list = NULL;
1670 for (m = first_machine; m; m = m->next) {
1671 MachineInfoList *entry;
1674 info = g_malloc0(sizeof(*info));
1675 if (m->is_default) {
1676 info->has_is_default = true;
1677 info->is_default = true;
1681 info->has_alias = true;
1682 info->alias = g_strdup(m->alias);
1685 info->name = g_strdup(m->name);
1686 info->cpu_max = !m->max_cpus ? 1 : m->max_cpus;
1688 entry = g_malloc0(sizeof(*entry));
1689 entry->value = info;
1690 entry->next = mach_list;
1697 /***********************************************************/
1698 /* main execution loop */
1700 struct vm_change_state_entry {
1701 VMChangeStateHandler *cb;
1703 QLIST_ENTRY (vm_change_state_entry) entries;
1706 static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
1708 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1711 VMChangeStateEntry *e;
1713 e = g_malloc0(sizeof (*e));
1717 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
1721 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1723 QLIST_REMOVE (e, entries);
1727 void vm_state_notify(int running, RunState state)
1729 VMChangeStateEntry *e;
1731 trace_vm_state_notify(running, state);
1733 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
1734 e->cb(e->opaque, running, state);
1740 if (!runstate_is_running()) {
1742 runstate_set(RUN_STATE_RUNNING);
1743 vm_state_notify(1, RUN_STATE_RUNNING);
1745 monitor_protocol_event(QEVENT_RESUME, NULL);
1749 /* reset/shutdown handler */
1751 typedef struct QEMUResetEntry {
1752 QTAILQ_ENTRY(QEMUResetEntry) entry;
1753 QEMUResetHandler *func;
1757 static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1758 QTAILQ_HEAD_INITIALIZER(reset_handlers);
1759 static int reset_requested;
1760 static int shutdown_requested, shutdown_signal = -1;
1761 static pid_t shutdown_pid;
1762 static int powerdown_requested;
1763 static int debug_requested;
1764 static int suspend_requested;
1765 static int wakeup_requested;
1766 static NotifierList powerdown_notifiers =
1767 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
1768 static NotifierList suspend_notifiers =
1769 NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
1770 static NotifierList wakeup_notifiers =
1771 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
1772 static uint32_t wakeup_reason_mask = ~0;
1773 static RunState vmstop_requested = RUN_STATE_MAX;
1775 int qemu_shutdown_requested_get(void)
1777 return shutdown_requested;
1780 int qemu_reset_requested_get(void)
1782 return reset_requested;
1785 static int qemu_shutdown_requested(void)
1787 int r = shutdown_requested;
1788 shutdown_requested = 0;
1792 static void qemu_kill_report(void)
1794 if (!qtest_enabled() && shutdown_signal != -1) {
1795 fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal);
1796 if (shutdown_pid == 0) {
1797 /* This happens for eg ^C at the terminal, so it's worth
1798 * avoiding printing an odd message in that case.
1800 fputc('\n', stderr);
1802 fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid);
1804 shutdown_signal = -1;
1808 static int qemu_reset_requested(void)
1810 int r = reset_requested;
1811 reset_requested = 0;
1815 static int qemu_suspend_requested(void)
1817 int r = suspend_requested;
1818 suspend_requested = 0;
1822 static int qemu_wakeup_requested(void)
1824 int r = wakeup_requested;
1825 wakeup_requested = 0;
1829 static int qemu_powerdown_requested(void)
1831 int r = powerdown_requested;
1832 powerdown_requested = 0;
1836 static int qemu_debug_requested(void)
1838 int r = debug_requested;
1839 debug_requested = 0;
1843 /* We use RUN_STATE_MAX but any invalid value will do */
1844 static bool qemu_vmstop_requested(RunState *r)
1846 if (vmstop_requested < RUN_STATE_MAX) {
1847 *r = vmstop_requested;
1848 vmstop_requested = RUN_STATE_MAX;
1855 void qemu_register_reset(QEMUResetHandler *func, void *opaque)
1857 QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
1860 re->opaque = opaque;
1861 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
1864 void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
1868 QTAILQ_FOREACH(re, &reset_handlers, entry) {
1869 if (re->func == func && re->opaque == opaque) {
1870 QTAILQ_REMOVE(&reset_handlers, re, entry);
1877 void qemu_devices_reset(void)
1879 QEMUResetEntry *re, *nre;
1881 /* reset all devices */
1882 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
1883 re->func(re->opaque);
1887 void qemu_system_reset(bool report)
1889 if (current_machine && current_machine->reset) {
1890 current_machine->reset();
1892 qemu_devices_reset();
1895 monitor_protocol_event(QEVENT_RESET, NULL);
1897 cpu_synchronize_all_post_reset();
1900 void qemu_system_reset_request(void)
1903 shutdown_requested = 1;
1905 reset_requested = 1;
1908 qemu_notify_event();
1911 static void qemu_system_suspend(void)
1914 notifier_list_notify(&suspend_notifiers, NULL);
1915 runstate_set(RUN_STATE_SUSPENDED);
1916 monitor_protocol_event(QEVENT_SUSPEND, NULL);
1919 void qemu_system_suspend_request(void)
1921 if (runstate_check(RUN_STATE_SUSPENDED)) {
1924 suspend_requested = 1;
1926 qemu_notify_event();
1929 void qemu_register_suspend_notifier(Notifier *notifier)
1931 notifier_list_add(&suspend_notifiers, notifier);
1934 void qemu_system_wakeup_request(WakeupReason reason)
1936 if (!runstate_check(RUN_STATE_SUSPENDED)) {
1939 if (!(wakeup_reason_mask & (1 << reason))) {
1942 runstate_set(RUN_STATE_RUNNING);
1943 notifier_list_notify(&wakeup_notifiers, &reason);
1944 wakeup_requested = 1;
1945 qemu_notify_event();
1948 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
1951 wakeup_reason_mask |= (1 << reason);
1953 wakeup_reason_mask &= ~(1 << reason);
1957 void qemu_register_wakeup_notifier(Notifier *notifier)
1959 notifier_list_add(&wakeup_notifiers, notifier);
1962 void qemu_system_killed(int signal, pid_t pid)
1964 shutdown_signal = signal;
1969 shutdown_qemu_gracefully();
1971 qemu_system_shutdown_request();
1975 void qemu_system_shutdown_request(void)
1977 shutdown_requested = 1;
1978 qemu_notify_event();
1981 static void qemu_system_powerdown(void)
1983 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
1984 notifier_list_notify(&powerdown_notifiers, NULL);
1987 void qemu_system_powerdown_request(void)
1989 powerdown_requested = 1;
1990 qemu_notify_event();
1993 void qemu_register_powerdown_notifier(Notifier *notifier)
1995 notifier_list_add(&powerdown_notifiers, notifier);
1998 void qemu_system_debug_request(void)
2000 debug_requested = 1;
2001 qemu_notify_event();
2004 void qemu_system_vmstop_request(RunState state)
2006 vmstop_requested = state;
2007 qemu_notify_event();
2010 static bool main_loop_should_exit(void)
2013 if (qemu_debug_requested()) {
2014 vm_stop(RUN_STATE_DEBUG);
2016 if (qemu_suspend_requested()) {
2017 qemu_system_suspend();
2019 if (qemu_shutdown_requested()) {
2021 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
2023 vm_stop(RUN_STATE_SHUTDOWN);
2028 if (qemu_reset_requested()) {
2030 cpu_synchronize_all_states();
2031 qemu_system_reset(VMRESET_REPORT);
2033 if (runstate_needs_reset()) {
2034 runstate_set(RUN_STATE_PAUSED);
2037 if (qemu_wakeup_requested()) {
2039 cpu_synchronize_all_states();
2040 qemu_system_reset(VMRESET_SILENT);
2042 monitor_protocol_event(QEVENT_WAKEUP, NULL);
2044 if (qemu_powerdown_requested()) {
2045 qemu_system_powerdown();
2047 if (qemu_vmstop_requested(&r)) {
2053 static void main_loop(void)
2057 #ifdef CONFIG_PROFILER
2064 nonblocking = !kvm_enabled() && !xen_enabled() && !hax_enabled() && last_io > 0;
2065 #ifdef CONFIG_PROFILER
2066 ti = profile_getclock();
2068 last_io = main_loop_wait(nonblocking);
2069 #ifdef CONFIG_PROFILER
2070 dev_time += profile_getclock() - ti;
2072 } while (!main_loop_should_exit());
2075 static void version(void)
2077 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
2080 static void help(int exitcode)
2083 printf("usage: %s [options] [disk_image]\n\n"
2084 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
2085 error_get_progname());
2087 #define QEMU_OPTIONS_GENERATE_HELP
2088 #include "qemu-options-wrapper.h"
2090 printf("\nDuring emulation, the following keys are useful:\n"
2091 "ctrl-alt-f toggle full screen\n"
2092 "ctrl-alt-n switch to virtual console 'n'\n"
2093 "ctrl-alt toggle mouse and keyboard grab\n"
2095 "When using -nographic, press 'ctrl-a h' to get some help.\n");
2100 #define HAS_ARG 0x0001
2102 typedef struct QEMUOption {
2109 static const QEMUOption qemu_options[] = {
2110 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
2111 #define QEMU_OPTIONS_GENERATE_OPTIONS
2112 #include "qemu-options-wrapper.h"
2116 static bool vga_available(void)
2118 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
2121 static bool cirrus_vga_available(void)
2123 return object_class_by_name("cirrus-vga")
2124 || object_class_by_name("isa-cirrus-vga");
2127 static bool vmware_vga_available(void)
2129 return object_class_by_name("vmware-svga");
2132 static bool qxl_vga_available(void)
2134 return object_class_by_name("qxl-vga");
2138 static bool maru_vga_available(void)
2140 return object_class_by_name("MARU_VGA");
2144 static void select_vgahw (const char *p)
2148 vga_interface_type = VGA_NONE;
2149 if (strstart(p, "std", &opts)) {
2150 if (vga_available()) {
2151 vga_interface_type = VGA_STD;
2153 fprintf(stderr, "Error: standard VGA not available\n");
2156 } else if (strstart(p, "cirrus", &opts)) {
2157 if (cirrus_vga_available()) {
2158 vga_interface_type = VGA_CIRRUS;
2160 fprintf(stderr, "Error: Cirrus VGA not available\n");
2163 } else if (strstart(p, "vmware", &opts)) {
2164 if (vmware_vga_available()) {
2165 vga_interface_type = VGA_VMWARE;
2167 fprintf(stderr, "Error: VMWare SVGA not available\n");
2170 } else if (strstart(p, "xenfb", &opts)) {
2171 vga_interface_type = VGA_XENFB;
2172 } else if (strstart(p, "qxl", &opts)) {
2173 if (qxl_vga_available()) {
2174 vga_interface_type = VGA_QXL;
2176 fprintf(stderr, "Error: QXL VGA not available\n");
2180 } else if (strstart(p, "maru", &opts)) {
2181 if (maru_vga_available()) {
2182 vga_interface_type = VGA_MARU;
2184 fprintf(stderr, "Error: MARU VGA not available\n");
2188 } else if (!strstart(p, "none", &opts)) {
2190 fprintf(stderr, "Unknown vga type: %s\n", p);
2194 const char *nextopt;
2196 if (strstart(opts, ",retrace=", &nextopt)) {
2198 if (strstart(opts, "dumb", &nextopt))
2199 vga_retrace_method = VGA_RETRACE_DUMB;
2200 else if (strstart(opts, "precise", &nextopt))
2201 vga_retrace_method = VGA_RETRACE_PRECISE;
2202 else goto invalid_vga;
2203 } else goto invalid_vga;
2208 static DisplayType select_display(const char *p)
2211 DisplayType display = DT_DEFAULT;
2213 if (strstart(p, "sdl", &opts)) {
2217 const char *nextopt;
2219 if (strstart(opts, ",frame=", &nextopt)) {
2221 if (strstart(opts, "on", &nextopt)) {
2223 } else if (strstart(opts, "off", &nextopt)) {
2226 goto invalid_sdl_args;
2228 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
2230 if (strstart(opts, "on", &nextopt)) {
2232 } else if (strstart(opts, "off", &nextopt)) {
2235 goto invalid_sdl_args;
2237 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
2239 if (strstart(opts, "on", &nextopt)) {
2241 } else if (strstart(opts, "off", &nextopt)) {
2244 goto invalid_sdl_args;
2246 } else if (strstart(opts, ",window_close=", &nextopt)) {
2248 if (strstart(opts, "on", &nextopt)) {
2250 } else if (strstart(opts, "off", &nextopt)) {
2253 goto invalid_sdl_args;
2257 fprintf(stderr, "Invalid SDL option string: %s\n", p);
2263 fprintf(stderr, "SDL support is disabled\n");
2266 } else if (strstart(p, "vnc", &opts)) {
2271 const char *nextopt;
2273 if (strstart(opts, "=", &nextopt)) {
2274 vnc_display = nextopt;
2278 fprintf(stderr, "VNC requires a display argument vnc=<display>\n");
2282 fprintf(stderr, "VNC support is disabled\n");
2285 } else if (strstart(p, "curses", &opts)) {
2286 #ifdef CONFIG_CURSES
2287 display = DT_CURSES;
2289 fprintf(stderr, "Curses support is disabled\n");
2292 } else if (strstart(p, "gtk", &opts)) {
2296 fprintf(stderr, "GTK support is disabled\n");
2299 } else if (strstart(p, "none", &opts)) {
2302 fprintf(stderr, "Unknown display type: %s\n", p);
2309 static int balloon_parse(const char *arg)
2313 if (strcmp(arg, "none") == 0) {
2317 if (!strncmp(arg, "virtio", 6)) {
2318 if (arg[6] == ',') {
2319 /* have params -> parse them */
2320 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
2324 /* create empty opts */
2325 opts = qemu_opts_create_nofail(qemu_find_opts("device"));
2327 qemu_opt_set(opts, "driver", "virtio-balloon");
2334 char *qemu_find_file(int type, const char *name)
2340 /* Try the name as a straight path first */
2341 if (access(name, R_OK) == 0) {
2342 trace_load_file(name, name);
2343 return g_strdup(name);
2347 case QEMU_FILE_TYPE_BIOS:
2350 case QEMU_FILE_TYPE_KEYMAP:
2351 subdir = "keymaps/";
2357 for (i = 0; i < data_dir_idx; i++) {
2358 buf = g_strdup_printf("%s/%s%s", data_dir[i], subdir, name);
2359 if (access(buf, R_OK) == 0) {
2360 trace_load_file(name, buf);
2368 static int device_help_func(QemuOpts *opts, void *opaque)
2370 return qdev_device_help(opts);
2373 static int device_init_func(QemuOpts *opts, void *opaque)
2378 if(maru_device_check(opts) == -1) {
2383 dev = qdev_device_add(opts);
2386 object_unref(OBJECT(dev));
2390 static int chardev_init_func(QemuOpts *opts, void *opaque)
2392 Error *local_err = NULL;
2394 qemu_chr_new_from_opts(opts, NULL, &local_err);
2395 if (error_is_set(&local_err)) {
2396 fprintf(stderr, "%s\n", error_get_pretty(local_err));
2397 error_free(local_err);
2403 #ifdef CONFIG_VIRTFS
2404 static int fsdev_init_func(QemuOpts *opts, void *opaque)
2407 ret = qemu_fsdev_add(opts);
2413 static int mon_init_func(QemuOpts *opts, void *opaque)
2415 CharDriverState *chr;
2416 const char *chardev;
2420 mode = qemu_opt_get(opts, "mode");
2424 if (strcmp(mode, "readline") == 0) {
2425 flags = MONITOR_USE_READLINE;
2426 } else if (strcmp(mode, "control") == 0) {
2427 flags = MONITOR_USE_CONTROL;
2429 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
2433 if (qemu_opt_get_bool(opts, "pretty", 0))
2434 flags |= MONITOR_USE_PRETTY;
2436 if (qemu_opt_get_bool(opts, "default", 0))
2437 flags |= MONITOR_IS_DEFAULT;
2439 chardev = qemu_opt_get(opts, "chardev");
2440 chr = qemu_chr_find(chardev);
2442 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
2446 qemu_chr_fe_claim_no_fail(chr);
2447 monitor_init(chr, flags);
2451 static void monitor_parse(const char *optarg, const char *mode)
2453 static int monitor_device_index = 0;
2459 if (strstart(optarg, "chardev:", &p)) {
2460 snprintf(label, sizeof(label), "%s", p);
2462 snprintf(label, sizeof(label), "compat_monitor%d",
2463 monitor_device_index);
2464 if (monitor_device_index == 0) {
2467 opts = qemu_chr_parse_compat(label, optarg);
2469 fprintf(stderr, "parse error: %s\n", optarg);
2474 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, NULL);
2476 fprintf(stderr, "duplicate chardev: %s\n", label);
2479 qemu_opt_set(opts, "mode", mode);
2480 qemu_opt_set(opts, "chardev", label);
2482 qemu_opt_set(opts, "default", "on");
2483 monitor_device_index++;
2486 struct device_config {
2488 DEV_USB, /* -usbdevice */
2490 DEV_SERIAL, /* -serial */
2491 DEV_PARALLEL, /* -parallel */
2492 DEV_VIRTCON, /* -virtioconsole */
2493 DEV_DEBUGCON, /* -debugcon */
2494 DEV_GDB, /* -gdb, -s */
2495 DEV_SCLP, /* s390 sclp */
2497 const char *cmdline;
2499 QTAILQ_ENTRY(device_config) next;
2502 static QTAILQ_HEAD(, device_config) device_configs =
2503 QTAILQ_HEAD_INITIALIZER(device_configs);
2505 static void add_device_config(int type, const char *cmdline)
2507 struct device_config *conf;
2509 conf = g_malloc0(sizeof(*conf));
2511 conf->cmdline = cmdline;
2512 loc_save(&conf->loc);
2513 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
2516 static int foreach_device_config(int type, int (*func)(const char *cmdline))
2518 struct device_config *conf;
2521 QTAILQ_FOREACH(conf, &device_configs, next) {
2522 if (conf->type != type)
2524 loc_push_restore(&conf->loc);
2525 rc = func(conf->cmdline);
2526 loc_pop(&conf->loc);
2533 static int serial_parse(const char *devname)
2535 static int index = 0;
2538 if (strcmp(devname, "none") == 0)
2540 if (index == MAX_SERIAL_PORTS) {
2541 fprintf(stderr, "qemu: too many serial ports\n");
2544 snprintf(label, sizeof(label), "serial%d", index);
2545 serial_hds[index] = qemu_chr_new(label, devname, NULL);
2546 if (!serial_hds[index]) {
2547 fprintf(stderr, "qemu: could not connect serial device"
2548 " to character backend '%s'\n", devname);
2555 static int parallel_parse(const char *devname)
2557 static int index = 0;
2560 if (strcmp(devname, "none") == 0)
2562 if (index == MAX_PARALLEL_PORTS) {
2563 fprintf(stderr, "qemu: too many parallel ports\n");
2566 snprintf(label, sizeof(label), "parallel%d", index);
2567 parallel_hds[index] = qemu_chr_new(label, devname, NULL);
2568 if (!parallel_hds[index]) {
2569 fprintf(stderr, "qemu: could not connect parallel device"
2570 " to character backend '%s'\n", devname);
2577 static int virtcon_parse(const char *devname)
2579 QemuOptsList *device = qemu_find_opts("device");
2580 static int index = 0;
2582 QemuOpts *bus_opts, *dev_opts;
2584 if (strcmp(devname, "none") == 0)
2586 if (index == MAX_VIRTIO_CONSOLES) {
2587 fprintf(stderr, "qemu: too many virtio consoles\n");
2591 bus_opts = qemu_opts_create_nofail(device);
2592 if (arch_type == QEMU_ARCH_S390X) {
2593 qemu_opt_set(bus_opts, "driver", "virtio-serial-s390");
2595 qemu_opt_set(bus_opts, "driver", "virtio-serial-pci");
2598 dev_opts = qemu_opts_create_nofail(device);
2599 qemu_opt_set(dev_opts, "driver", "virtconsole");
2601 snprintf(label, sizeof(label), "virtcon%d", index);
2602 virtcon_hds[index] = qemu_chr_new(label, devname, NULL);
2603 if (!virtcon_hds[index]) {
2604 fprintf(stderr, "qemu: could not connect virtio console"
2605 " to character backend '%s'\n", devname);
2608 qemu_opt_set(dev_opts, "chardev", label);
2614 static int sclp_parse(const char *devname)
2616 QemuOptsList *device = qemu_find_opts("device");
2617 static int index = 0;
2621 if (strcmp(devname, "none") == 0) {
2624 if (index == MAX_SCLP_CONSOLES) {
2625 fprintf(stderr, "qemu: too many sclp consoles\n");
2629 assert(arch_type == QEMU_ARCH_S390X);
2631 dev_opts = qemu_opts_create(device, NULL, 0, NULL);
2632 qemu_opt_set(dev_opts, "driver", "sclpconsole");
2634 snprintf(label, sizeof(label), "sclpcon%d", index);
2635 sclp_hds[index] = qemu_chr_new(label, devname, NULL);
2636 if (!sclp_hds[index]) {
2637 fprintf(stderr, "qemu: could not connect sclp console"
2638 " to character backend '%s'\n", devname);
2641 qemu_opt_set(dev_opts, "chardev", label);
2647 static int debugcon_parse(const char *devname)
2651 if (!qemu_chr_new("debugcon", devname, NULL)) {
2654 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL);
2656 fprintf(stderr, "qemu: already have a debugcon device\n");
2659 qemu_opt_set(opts, "driver", "isa-debugcon");
2660 qemu_opt_set(opts, "chardev", "debugcon");
2664 static QEMUMachine *machine_parse(const char *name)
2666 QEMUMachine *m, *machine = NULL;
2669 machine = find_machine(name);
2674 printf("Supported machines are:\n");
2675 for (m = first_machine; m != NULL; m = m->next) {
2677 printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name);
2679 printf("%-20s %s%s\n", m->name, m->desc,
2680 m->is_default ? " (default)" : "");
2682 exit(!name || !is_help_option(name));
2685 static int tcg_init(void)
2688 tcg_exec_init(tcg_tb_size * 1024 * 1024);
2689 ret = hax_accel_init();
2694 const char *opt_name;
2696 int (*available)(void);
2700 { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
2701 { "xen", "Xen", xen_available, xen_init, &xen_allowed },
2702 { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
2703 { "qtest", "QTest", qtest_available, qtest_init, &qtest_allowed },
2706 static int configure_accelerator(void)
2708 const char *p = NULL;
2711 bool accel_initialised = false;
2712 bool init_failed = false;
2714 QemuOptsList *list = qemu_find_opts("machine");
2715 if (!QTAILQ_EMPTY(&list->head)) {
2716 p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel");
2720 /* Use the default "accelerator", tcg */
2724 while (!accel_initialised && *p != '\0') {
2728 p = get_opt_name(buf, sizeof (buf), p, ':');
2729 for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
2730 if (strcmp(accel_list[i].opt_name, buf) == 0) {
2731 if (!accel_list[i].available()) {
2732 printf("%s not supported for this target\n",
2733 accel_list[i].name);
2736 *(accel_list[i].allowed) = true;
2737 ret = accel_list[i].init();
2740 fprintf(stderr, "failed to initialize %s: %s\n",
2743 *(accel_list[i].allowed) = false;
2745 accel_initialised = true;
2750 if (i == ARRAY_SIZE(accel_list)) {
2751 fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
2755 if (!accel_initialised) {
2757 fprintf(stderr, "No accelerator found!\n");
2760 maru_register_exit_msg(MARU_EXIT_UNKNOWN, "No accelerator found.");
2766 fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
2769 return !accel_initialised;
2772 void qemu_add_exit_notifier(Notifier *notify)
2774 notifier_list_add(&exit_notifiers, notify);
2777 void qemu_remove_exit_notifier(Notifier *notify)
2779 notifier_remove(notify);
2782 static void qemu_run_exit_notifiers(void)
2784 notifier_list_notify(&exit_notifiers, NULL);
2787 void qemu_add_machine_init_done_notifier(Notifier *notify)
2789 notifier_list_add(&machine_init_done_notifiers, notify);
2792 static void qemu_run_machine_init_done_notifiers(void)
2794 notifier_list_notify(&machine_init_done_notifiers, NULL);
2797 static const QEMUOption *lookup_opt(int argc, char **argv,
2798 const char **poptarg, int *poptind)
2800 const QEMUOption *popt;
2801 int optind = *poptind;
2802 char *r = argv[optind];
2805 loc_set_cmdline(argv, optind, 1);
2807 /* Treat --foo the same as -foo. */
2810 popt = qemu_options;
2813 error_report("invalid option");
2815 maru_register_exit_msg(MARU_EXIT_UNKNOWN, "invalid option.");
2819 if (!strcmp(popt->name, r + 1))
2823 if (popt->flags & HAS_ARG) {
2824 if (optind >= argc) {
2825 error_report("requires an argument");
2827 maru_register_exit_msg(MARU_EXIT_UNKNOWN, "requires an argument.");
2831 optarg = argv[optind++];
2832 loc_set_cmdline(argv, optind - 2, 2);
2843 static gpointer malloc_and_trace(gsize n_bytes)
2845 void *ptr = malloc(n_bytes);
2846 trace_g_malloc(n_bytes, ptr);
2850 static gpointer realloc_and_trace(gpointer mem, gsize n_bytes)
2852 void *ptr = realloc(mem, n_bytes);
2853 trace_g_realloc(mem, n_bytes, ptr);
2857 static void free_and_trace(gpointer mem)
2863 static int object_set_property(const char *name, const char *value, void *opaque)
2865 Object *obj = OBJECT(opaque);
2866 StringInputVisitor *siv;
2867 Error *local_err = NULL;
2869 if (strcmp(name, "qom-type") == 0 || strcmp(name, "id") == 0) {
2873 siv = string_input_visitor_new(value);
2874 object_property_set(obj, string_input_get_visitor(siv), name, &local_err);
2875 string_input_visitor_cleanup(siv);
2878 qerror_report_err(local_err);
2879 error_free(local_err);
2886 static int object_create(QemuOpts *opts, void *opaque)
2888 const char *type = qemu_opt_get(opts, "qom-type");
2889 const char *id = qemu_opts_id(opts);
2892 g_assert(type != NULL);
2895 qerror_report(QERR_MISSING_PARAMETER, "id");
2899 obj = object_new(type);
2900 if (qemu_opt_foreach(opts, object_set_property, obj, 1) < 0) {
2904 object_property_add_child(container_get(object_get_root(), "/objects"),
2911 int use_qemu_display = 0; //0:use tizen qemu sdl, 1:use original qemu sdl
2912 // W/A for preserve larger continuous heap for RAM.
2913 void *preallocated_ptr = 0;
2916 int main(int argc, char **argv, char **envp)
2919 int snapshot, linux_boot;
2920 const char *icount_option = NULL;
2921 const char *initrd_filename;
2922 const char *kernel_filename, *kernel_cmdline;
2923 char boot_devices[33] = "";
2925 int cyls, heads, secs, translation;
2926 QemuOpts *hda_opts = NULL, *opts, *machine_opts;
2927 QemuOptsList *olist;
2930 const char *loadvm = NULL;
2931 QEMUMachine *machine;
2932 const char *cpu_model;
2933 const char *vga_model = "none";
2934 const char *pid_file = NULL;
2935 const char *incoming = NULL;
2937 int show_vnc_port = 0;
2939 bool defconfig = true;
2940 bool userconfig = true;
2941 const char *log_mask = NULL;
2942 const char *log_file = NULL;
2943 GMemVTable mem_trace = {
2944 .malloc = malloc_and_trace,
2945 .realloc = realloc_and_trace,
2946 .free = free_and_trace,
2948 const char *trace_events = NULL;
2949 const char *trace_file = NULL;
2951 atexit(qemu_run_exit_notifiers);
2952 error_set_progname(argv[0]);
2954 g_mem_set_vtable(&mem_trace);
2955 if (!g_thread_supported()) {
2956 #if !GLIB_CHECK_VERSION(2, 31, 0)
2957 g_thread_init(NULL);
2959 fprintf(stderr, "glib threading failed to initialize.\n");
2964 module_call_init(MODULE_INIT_QOM);
2966 qemu_add_opts(&qemu_drive_opts);
2967 qemu_add_opts(&qemu_chardev_opts);
2968 qemu_add_opts(&qemu_device_opts);
2969 qemu_add_opts(&qemu_netdev_opts);
2970 qemu_add_opts(&qemu_net_opts);
2971 qemu_add_opts(&qemu_rtc_opts);
2972 qemu_add_opts(&qemu_global_opts);
2973 qemu_add_opts(&qemu_mon_opts);
2974 qemu_add_opts(&qemu_trace_opts);
2975 qemu_add_opts(&qemu_option_rom_opts);
2976 qemu_add_opts(&qemu_machine_opts);
2977 qemu_add_opts(&qemu_boot_opts);
2978 qemu_add_opts(&qemu_sandbox_opts);
2979 qemu_add_opts(&qemu_add_fd_opts);
2980 qemu_add_opts(&qemu_object_opts);
2981 qemu_add_opts(&qemu_tpmdev_opts);
2982 qemu_add_opts(&qemu_realtime_opts);
2987 rtc_clock = host_clock;
2989 qemu_cache_utils_init(envp);
2991 QLIST_INIT (&vm_change_state_head);
2992 os_setup_early_signal_handling();
2994 module_call_init(MODULE_INIT_MACHINE);
2995 machine = find_default_machine();
2999 cyls = heads = secs = 0;
3000 translation = BIOS_ATA_TRANSLATION_AUTO;
3002 for (i = 0; i < MAX_NODES; i++) {
3004 node_cpumask[i] = bitmap_new(MAX_CPUMASK_BITS);
3010 bdrv_init_with_whitelist();
3014 /* first pass of option parsing */
3016 while (optind < argc) {
3017 if (argv[optind][0] != '-') {
3022 const QEMUOption *popt;
3024 popt = lookup_opt(argc, argv, &optarg, &optind);
3025 switch (popt->index) {
3026 case QEMU_OPTION_nodefconfig:
3029 case QEMU_OPTION_nouserconfig:
3038 ret = qemu_read_default_config_files(userconfig);
3044 /* second pass of option parsing */
3049 if (argv[optind][0] != '-') {
3050 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
3052 const QEMUOption *popt;
3054 popt = lookup_opt(argc, argv, &optarg, &optind);
3055 if (!(popt->arch_mask & arch_type)) {
3056 printf("Option %s not supported for this target\n", popt->name);
3059 switch(popt->index) {
3061 machine = machine_parse(optarg);
3063 case QEMU_OPTION_no_kvm_irqchip: {
3064 olist = qemu_find_opts("machine");
3065 qemu_opts_parse(olist, "kernel_irqchip=off", 0);
3068 case QEMU_OPTION_cpu:
3069 /* hw initialization will check this */
3072 case QEMU_OPTION_hda:
3076 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
3078 snprintf(buf, sizeof(buf),
3079 "%s,cyls=%d,heads=%d,secs=%d%s",
3080 HD_OPTS , cyls, heads, secs,
3081 translation == BIOS_ATA_TRANSLATION_LBA ?
3083 translation == BIOS_ATA_TRANSLATION_NONE ?
3084 ",trans=none" : "");
3085 drive_add(IF_DEFAULT, 0, optarg, buf);
3088 case QEMU_OPTION_hdb:
3089 case QEMU_OPTION_hdc:
3090 case QEMU_OPTION_hdd:
3091 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
3094 case QEMU_OPTION_drive:
3095 if (drive_def(optarg) == NULL) {
3099 case QEMU_OPTION_set:
3100 if (qemu_set_option(optarg) != 0)
3103 case QEMU_OPTION_global:
3104 if (qemu_global_option(optarg) != 0)
3107 case QEMU_OPTION_mtdblock:
3108 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
3110 case QEMU_OPTION_sd:
3111 drive_add(IF_SD, -1, optarg, SD_OPTS);
3113 case QEMU_OPTION_pflash:
3114 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
3116 case QEMU_OPTION_snapshot:
3119 case QEMU_OPTION_hdachs:
3123 cyls = strtol(p, (char **)&p, 0);
3124 if (cyls < 1 || cyls > 16383)
3129 heads = strtol(p, (char **)&p, 0);
3130 if (heads < 1 || heads > 16)
3135 secs = strtol(p, (char **)&p, 0);
3136 if (secs < 1 || secs > 63)
3140 if (!strcmp(p, "none"))
3141 translation = BIOS_ATA_TRANSLATION_NONE;
3142 else if (!strcmp(p, "lba"))
3143 translation = BIOS_ATA_TRANSLATION_LBA;
3144 else if (!strcmp(p, "auto"))
3145 translation = BIOS_ATA_TRANSLATION_AUTO;
3148 } else if (*p != '\0') {
3150 fprintf(stderr, "qemu: invalid physical CHS format\n");
3153 if (hda_opts != NULL) {
3155 snprintf(num, sizeof(num), "%d", cyls);
3156 qemu_opt_set(hda_opts, "cyls", num);
3157 snprintf(num, sizeof(num), "%d", heads);
3158 qemu_opt_set(hda_opts, "heads", num);
3159 snprintf(num, sizeof(num), "%d", secs);
3160 qemu_opt_set(hda_opts, "secs", num);
3161 if (translation == BIOS_ATA_TRANSLATION_LBA)
3162 qemu_opt_set(hda_opts, "trans", "lba");
3163 if (translation == BIOS_ATA_TRANSLATION_NONE)
3164 qemu_opt_set(hda_opts, "trans", "none");
3168 case QEMU_OPTION_numa:
3171 case QEMU_OPTION_display:
3172 display_type = select_display(optarg);
3174 case QEMU_OPTION_nographic:
3175 display_type = DT_NOGRAPHIC;
3177 case QEMU_OPTION_curses:
3178 #ifdef CONFIG_CURSES
3179 display_type = DT_CURSES;
3181 fprintf(stderr, "Curses support is disabled\n");
3185 case QEMU_OPTION_portrait:
3186 graphic_rotate = 90;
3188 case QEMU_OPTION_rotate:
3189 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
3190 if (graphic_rotate != 0 && graphic_rotate != 90 &&
3191 graphic_rotate != 180 && graphic_rotate != 270) {
3193 "qemu: only 90, 180, 270 deg rotation is available\n");
3197 case QEMU_OPTION_kernel:
3198 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg);
3200 case QEMU_OPTION_initrd:
3201 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg);
3203 case QEMU_OPTION_append:
3204 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg);
3206 case QEMU_OPTION_dtb:
3207 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg);
3209 case QEMU_OPTION_cdrom:
3210 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
3212 case QEMU_OPTION_boot:
3214 static const char * const params[] = {
3215 "order", "once", "menu",
3216 "splash", "splash-time",
3217 "reboot-timeout", "strict", NULL
3219 char buf[sizeof(boot_devices)];
3220 char *standard_boot_devices;
3223 if (!strchr(optarg, '=')) {
3225 pstrcpy(buf, sizeof(buf), optarg);
3226 } else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
3228 "qemu: unknown boot parameter '%s' in '%s'\n",
3234 get_param_value(buf, sizeof(buf), "order", optarg)) {
3235 validate_bootdevices(buf);
3236 pstrcpy(boot_devices, sizeof(boot_devices), buf);
3239 if (get_param_value(buf, sizeof(buf),
3241 validate_bootdevices(buf);
3242 standard_boot_devices = g_strdup(boot_devices);
3243 pstrcpy(boot_devices, sizeof(boot_devices), buf);
3244 qemu_register_reset(restore_boot_devices,
3245 standard_boot_devices);
3247 if (get_param_value(buf, sizeof(buf),
3249 if (!strcmp(buf, "on")) {
3251 } else if (!strcmp(buf, "off")) {
3255 "qemu: invalid option value '%s'\n",
3260 if (get_param_value(buf, sizeof(buf),
3261 "strict", optarg)) {
3262 if (!strcmp(buf, "on")) {
3264 } else if (!strcmp(buf, "off")) {
3265 boot_strict = false;
3268 "qemu: invalid option value '%s'\n",
3273 if (!qemu_opts_parse(qemu_find_opts("boot-opts"),
3280 case QEMU_OPTION_fda:
3281 case QEMU_OPTION_fdb:
3282 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
3285 case QEMU_OPTION_no_fd_bootchk:
3288 case QEMU_OPTION_netdev:
3289 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
3293 case QEMU_OPTION_net:
3294 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
3298 #ifdef CONFIG_LIBISCSI
3299 case QEMU_OPTION_iscsi:
3300 opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0);
3307 case QEMU_OPTION_tftp:
3308 legacy_tftp_prefix = optarg;
3310 case QEMU_OPTION_bootp:
3311 legacy_bootp_filename = optarg;
3313 case QEMU_OPTION_redir:
3314 if (net_slirp_redir(optarg) < 0)
3318 case QEMU_OPTION_bt:
3319 add_device_config(DEV_BT, optarg);
3321 case QEMU_OPTION_audio_help:
3325 case QEMU_OPTION_soundhw:
3326 select_soundhw (optarg);
3331 case QEMU_OPTION_version:
3335 case QEMU_OPTION_m: {
3340 value = strtosz(optarg, &end);
3341 if (value < 0 || *end) {
3342 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
3345 sz = QEMU_ALIGN_UP((uint64_t)value, 8192);
3347 if (ram_size != sz) {
3348 fprintf(stderr, "qemu: ram size too large\n");
3354 case QEMU_OPTION_tpmdev:
3355 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
3360 case QEMU_OPTION_mempath:
3364 case QEMU_OPTION_mem_prealloc:
3375 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
3377 case QEMU_OPTION_gdb:
3378 add_device_config(DEV_GDB, optarg);
3381 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
3382 data_dir[data_dir_idx++] = optarg;
3385 case QEMU_OPTION_bios:
3388 case QEMU_OPTION_singlestep:
3395 keyboard_layout = optarg;
3397 case QEMU_OPTION_localtime:
3400 case QEMU_OPTION_vga:
3409 w = strtol(p, (char **)&p, 10);
3412 fprintf(stderr, "qemu: invalid resolution or depth\n");
3418 h = strtol(p, (char **)&p, 10);
3423 depth = strtol(p, (char **)&p, 10);
3424 if (depth != 8 && depth != 15 && depth != 16 &&
3425 depth != 24 && depth != 32)
3427 } else if (*p == '\0') {
3428 depth = graphic_depth;
3435 graphic_depth = depth;
3438 case QEMU_OPTION_echr:
3441 term_escape_char = strtol(optarg, &r, 0);
3443 printf("Bad argument to echr\n");
3446 case QEMU_OPTION_monitor:
3447 monitor_parse(optarg, "readline");
3448 default_monitor = 0;
3450 case QEMU_OPTION_qmp:
3451 monitor_parse(optarg, "control");
3452 default_monitor = 0;
3454 case QEMU_OPTION_mon:
3455 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
3459 default_monitor = 0;
3461 case QEMU_OPTION_chardev:
3462 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
3467 case QEMU_OPTION_fsdev:
3468 olist = qemu_find_opts("fsdev");
3470 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
3473 opts = qemu_opts_parse(olist, optarg, 1);
3478 case QEMU_OPTION_virtfs: {
3481 const char *writeout, *sock_fd, *socket;
3483 olist = qemu_find_opts("virtfs");
3485 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
3488 opts = qemu_opts_parse(olist, optarg, 1);
3493 if (qemu_opt_get(opts, "fsdriver") == NULL ||
3494 qemu_opt_get(opts, "mount_tag") == NULL) {
3495 fprintf(stderr, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
3498 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
3499 qemu_opt_get(opts, "mount_tag"),
3502 fprintf(stderr, "duplicate fsdev id: %s\n",
3503 qemu_opt_get(opts, "mount_tag"));
3507 writeout = qemu_opt_get(opts, "writeout");
3509 #ifdef CONFIG_SYNC_FILE_RANGE
3510 qemu_opt_set(fsdev, "writeout", writeout);
3512 fprintf(stderr, "writeout=immediate not supported on "
3517 qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver"));
3518 qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"));
3519 qemu_opt_set(fsdev, "security_model",
3520 qemu_opt_get(opts, "security_model"));
3521 socket = qemu_opt_get(opts, "socket");
3523 qemu_opt_set(fsdev, "socket", socket);
3525 sock_fd = qemu_opt_get(opts, "sock_fd");
3527 qemu_opt_set(fsdev, "sock_fd", sock_fd);
3530 qemu_opt_set_bool(fsdev, "readonly",
3531 qemu_opt_get_bool(opts, "readonly", 0));
3532 device = qemu_opts_create_nofail(qemu_find_opts("device"));
3533 qemu_opt_set(device, "driver", "virtio-9p-pci");
3534 qemu_opt_set(device, "fsdev",
3535 qemu_opt_get(opts, "mount_tag"));
3536 qemu_opt_set(device, "mount_tag",
3537 qemu_opt_get(opts, "mount_tag"));
3540 case QEMU_OPTION_virtfs_synth: {
3544 fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3547 fprintf(stderr, "duplicate option: %s\n", "virtfs_synth");
3550 qemu_opt_set(fsdev, "fsdriver", "synth");
3552 device = qemu_opts_create_nofail(qemu_find_opts("device"));
3553 qemu_opt_set(device, "driver", "virtio-9p-pci");
3554 qemu_opt_set(device, "fsdev", "v_synth");
3555 qemu_opt_set(device, "mount_tag", "v_synth");
3558 case QEMU_OPTION_serial:
3559 add_device_config(DEV_SERIAL, optarg);
3561 if (strncmp(optarg, "mon:", 4) == 0) {
3562 default_monitor = 0;
3565 case QEMU_OPTION_watchdog:
3568 "qemu: only one watchdog option may be given\n");
3573 case QEMU_OPTION_watchdog_action:
3574 if (select_watchdog_action(optarg) == -1) {
3575 fprintf(stderr, "Unknown -watchdog-action parameter\n");
3579 case QEMU_OPTION_virtiocon:
3580 add_device_config(DEV_VIRTCON, optarg);
3581 default_virtcon = 0;
3582 if (strncmp(optarg, "mon:", 4) == 0) {
3583 default_monitor = 0;
3586 case QEMU_OPTION_parallel:
3587 add_device_config(DEV_PARALLEL, optarg);
3588 default_parallel = 0;
3589 if (strncmp(optarg, "mon:", 4) == 0) {
3590 default_monitor = 0;
3593 case QEMU_OPTION_debugcon:
3594 add_device_config(DEV_DEBUGCON, optarg);
3596 case QEMU_OPTION_loadvm:
3599 case QEMU_OPTION_full_screen:
3603 case QEMU_OPTION_no_frame:
3606 case QEMU_OPTION_alt_grab:
3609 case QEMU_OPTION_ctrl_grab:
3612 case QEMU_OPTION_no_quit:
3615 case QEMU_OPTION_sdl:
3616 display_type = DT_SDL;
3619 case QEMU_OPTION_no_frame:
3620 case QEMU_OPTION_alt_grab:
3621 case QEMU_OPTION_ctrl_grab:
3622 case QEMU_OPTION_no_quit:
3623 case QEMU_OPTION_sdl:
3624 fprintf(stderr, "SDL support is disabled\n");
3627 case QEMU_OPTION_pidfile:
3630 case QEMU_OPTION_win2k_hack:
3631 win2k_install_hack = 1;
3633 case QEMU_OPTION_rtc_td_hack: {
3634 static GlobalProperty slew_lost_ticks[] = {
3636 .driver = "mc146818rtc",
3637 .property = "lost_tick_policy",
3640 { /* end of list */ }
3643 qdev_prop_register_global_list(slew_lost_ticks);
3646 case QEMU_OPTION_acpitable:
3647 opts = qemu_opts_parse(qemu_find_opts("acpi"), optarg, 1);
3648 g_assert(opts != NULL);
3649 do_acpitable_option(opts);
3651 case QEMU_OPTION_smbios:
3652 do_smbios_option(optarg);
3654 case QEMU_OPTION_enable_kvm:
3655 olist = qemu_find_opts("machine");
3656 qemu_opts_parse(olist, "accel=kvm", 0);
3658 case QEMU_OPTION_enable_gl:
3659 #if defined(CONFIG_MARU) && defined(CONFIG_GL_BACKEND)
3662 fprintf(stderr, "Virtio GL support is disabled, ignoring -enable-gl\n");
3665 case QEMU_OPTION_enable_yagl:
3666 #if defined(CONFIG_YAGL) && !defined(CONFIG_DARWIN)
3669 fprintf(stderr, "YaGL openGLES passthrough support is disabled,"
3670 " ignoring -enable-yagl\n");
3673 case QEMU_OPTION_machine:
3674 olist = qemu_find_opts("machine");
3675 opts = qemu_opts_parse(olist, optarg, 1);
3679 optarg = qemu_opt_get(opts, "type");
3681 machine = machine_parse(optarg);
3684 case QEMU_OPTION_no_kvm:
3685 olist = qemu_find_opts("machine");
3686 qemu_opts_parse(olist, "accel=tcg", 0);
3688 case QEMU_OPTION_no_kvm_pit: {
3689 fprintf(stderr, "Warning: KVM PIT can no longer be disabled "
3693 case QEMU_OPTION_no_kvm_pit_reinjection: {
3694 static GlobalProperty kvm_pit_lost_tick_policy[] = {
3696 .driver = "kvm-pit",
3697 .property = "lost_tick_policy",
3700 { /* end of list */ }
3703 fprintf(stderr, "Warning: option deprecated, use "
3704 "lost_tick_policy property of kvm-pit instead.\n");
3705 qdev_prop_register_global_list(kvm_pit_lost_tick_policy);
3708 case QEMU_OPTION_usb:
3709 olist = qemu_find_opts("machine");
3710 qemu_opts_parse(olist, "usb=on", 0);
3712 case QEMU_OPTION_usbdevice:
3713 olist = qemu_find_opts("machine");
3714 qemu_opts_parse(olist, "usb=on", 0);
3715 add_device_config(DEV_USB, optarg);
3717 case QEMU_OPTION_device:
3718 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
3722 case QEMU_OPTION_smp:
3725 fprintf(stderr, "Invalid number of CPUs\n");
3728 if (max_cpus < smp_cpus) {
3729 fprintf(stderr, "maxcpus must be equal to or greater than "
3733 if (max_cpus > 255) {
3734 fprintf(stderr, "Unsupported number of maxcpus\n");
3738 case QEMU_OPTION_vnc:
3741 vnc_display = optarg;
3743 fprintf(stderr, "VNC support is disabled\n");
3747 case QEMU_OPTION_no_acpi:
3750 case QEMU_OPTION_no_hpet:
3753 case QEMU_OPTION_balloon:
3754 if (balloon_parse(optarg) < 0) {
3755 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
3759 case QEMU_OPTION_no_reboot:
3762 case QEMU_OPTION_no_shutdown:
3765 case QEMU_OPTION_show_cursor:
3768 case QEMU_OPTION_uuid:
3769 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
3770 fprintf(stderr, "Fail to parse UUID string."
3771 " Wrong format.\n");
3775 case QEMU_OPTION_option_rom:
3776 if (nb_option_roms >= MAX_OPTION_ROMS) {
3777 fprintf(stderr, "Too many option ROMs\n");
3780 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
3784 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
3785 option_rom[nb_option_roms].bootindex =
3786 qemu_opt_get_number(opts, "bootindex", -1);
3787 if (!option_rom[nb_option_roms].name) {
3788 fprintf(stderr, "Option ROM file is not specified\n");
3793 case QEMU_OPTION_semihosting:
3794 semihosting_enabled = 1;
3796 case QEMU_OPTION_tdf:
3797 fprintf(stderr, "Warning: user space PIT time drift fix "
3798 "is no longer supported.\n");
3800 case QEMU_OPTION_name:
3801 qemu_name = g_strdup(optarg);
3803 char *p = strchr(qemu_name, ',');
3806 if (strncmp(p, "process=", 8)) {
3807 fprintf(stderr, "Unknown subargument %s to -name\n", p);
3811 os_set_proc_name(p);
3815 case QEMU_OPTION_prom_env:
3816 if (nb_prom_envs >= MAX_PROM_ENVS) {
3817 fprintf(stderr, "Too many prom variables\n");
3820 prom_envs[nb_prom_envs] = optarg;
3823 case QEMU_OPTION_old_param:
3826 case QEMU_OPTION_clock:
3827 configure_alarms(optarg);
3829 case QEMU_OPTION_startdate:
3830 configure_rtc_date_offset(optarg, 1);
3832 case QEMU_OPTION_rtc:
3833 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
3837 configure_rtc(opts);
3839 case QEMU_OPTION_tb_size:
3840 tcg_tb_size = strtol(optarg, NULL, 0);
3841 if (tcg_tb_size < 0) {
3845 case QEMU_OPTION_icount:
3846 icount_option = optarg;
3848 case QEMU_OPTION_incoming:
3850 runstate_set(RUN_STATE_INMIGRATE);
3852 case QEMU_OPTION_nodefaults:
3854 default_parallel = 0;
3855 default_virtcon = 0;
3857 default_monitor = 0;
3864 case QEMU_OPTION_xen_domid:
3865 if (!(xen_available())) {
3866 printf("Option %s not supported for this target\n", popt->name);
3869 xen_domid = atoi(optarg);
3871 case QEMU_OPTION_xen_create:
3872 if (!(xen_available())) {
3873 printf("Option %s not supported for this target\n", popt->name);
3876 xen_mode = XEN_CREATE;
3878 case QEMU_OPTION_xen_attach:
3879 if (!(xen_available())) {
3880 printf("Option %s not supported for this target\n", popt->name);
3883 xen_mode = XEN_ATTACH;
3885 case QEMU_OPTION_trace:
3887 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
3891 trace_events = qemu_opt_get(opts, "events");
3892 trace_file = qemu_opt_get(opts, "file");
3895 case QEMU_OPTION_readconfig:
3897 int ret = qemu_read_config_file(optarg);
3899 fprintf(stderr, "read config %s: %s\n", optarg,
3905 case QEMU_OPTION_spice:
3906 olist = qemu_find_opts("spice");
3908 fprintf(stderr, "spice is not supported by this qemu build.\n");
3911 opts = qemu_opts_parse(olist, optarg, 0);
3917 case QEMU_OPTION_writeconfig:
3920 if (strcmp(optarg, "-") == 0) {
3923 fp = fopen(optarg, "w");
3925 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
3929 qemu_config_write(fp);
3933 case QEMU_OPTION_qtest:
3934 qtest_chrdev = optarg;
3936 case QEMU_OPTION_qtest_log:
3939 case QEMU_OPTION_sandbox:
3940 opts = qemu_opts_parse(qemu_find_opts("sandbox"), optarg, 1);
3945 case QEMU_OPTION_enable_hax:
3946 #ifdef CONFIG_HAX_BACKEND
3947 olist = qemu_find_opts("machine");
3948 //qemu_opts_reset(olist);
3950 //qemu_opts_parse(olist, "accel=hax", 0);
3953 "HAX support is disabled, ignoring -enable-hax\n");
3957 case QEMU_OPTION_max_touch_point:
3959 int cnt = atoi(optarg);
3960 fprintf(stderr, "maxTouchPoint:%d\n", cnt);
3961 set_emul_max_touch_point(cnt);
3964 case QEMU_OPTION_disable_skin:
3968 case QEMU_OPTION_add_fd:
3970 opts = qemu_opts_parse(qemu_find_opts("add-fd"), optarg, 0);
3975 error_report("File descriptor passing is disabled on this "
3980 case QEMU_OPTION_object:
3981 opts = qemu_opts_parse(qemu_find_opts("object"), optarg, 1);
3986 case QEMU_OPTION_realtime:
3987 opts = qemu_opts_parse(qemu_find_opts("realtime"), optarg, 0);
3991 configure_realtime(opts);
3994 os_parse_cmd_args(popt->index, optarg);
4000 if (qemu_init_main_loop()) {
4001 fprintf(stderr, "qemu_init_main_loop failed\n");
4005 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 0)) {
4010 if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL, 1)) {
4014 if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd, NULL, 1)) {
4019 if (machine == NULL) {
4020 fprintf(stderr, "No machine found.\n");
4024 if (machine->hw_version) {
4025 qemu_set_version(machine->hw_version);
4028 if (qemu_opts_foreach(qemu_find_opts("object"),
4029 object_create, NULL, 0) != 0) {
4033 /* Init CPU def lists, based on config
4034 * - Must be called after all the qemu_read_config_file() calls
4035 * - Must be called before list_cpus()
4036 * - Must be called before machine->init()
4040 if (cpu_model && is_help_option(cpu_model)) {
4041 list_cpus(stdout, &fprintf, cpu_model);
4045 /* Open the logfile at this point, if necessary. We can't open the logfile
4046 * when encountering either of the logging options (-d or -D) because the
4047 * other one may be encountered later on the command line, changing the
4048 * location or level of logging.
4053 qemu_set_log_filename(log_file);
4056 mask = qemu_str_to_log_mask(log_mask);
4058 qemu_print_log_usage(stdout);
4064 if (!trace_backend_init(trace_events, trace_file)) {
4068 /* If no data_dir is specified then try to find it relative to the
4070 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
4071 data_dir[data_dir_idx] = os_find_datadir(argv[0]);
4072 if (data_dir[data_dir_idx] != NULL) {
4076 /* If all else fails use the install path specified when building. */
4077 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
4078 data_dir[data_dir_idx++] = CONFIG_QEMU_DATADIR;
4082 * Default to max_cpus = smp_cpus, in case the user doesn't
4083 * specify a max_cpus value.
4086 max_cpus = smp_cpus;
4088 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
4089 if (smp_cpus > machine->max_cpus) {
4090 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
4091 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
4097 * Get the default machine options from the machine if it is not already
4098 * specified either by the configuration file or by the command line.
4100 if (machine->default_machine_opts) {
4101 qemu_opts_set_defaults(qemu_find_opts("machine"),
4102 machine->default_machine_opts, 0);
4105 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
4106 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
4108 if (machine->no_serial) {
4111 if (machine->no_parallel) {
4112 default_parallel = 0;
4114 if (!machine->use_virtcon) {
4115 default_virtcon = 0;
4117 if (!machine->use_sclp) {
4120 if (machine->no_floppy) {
4123 if (machine->no_cdrom) {
4126 if (machine->no_sdcard) {
4130 if (is_daemonized()) {
4131 /* According to documentation and historically, -nographic redirects
4132 * serial port, parallel port and monitor to stdio, which does not work
4133 * with -daemonize. We can redirect these to null instead, but since
4134 * -nographic is legacy, let's just error out.
4135 * We disallow -nographic only if all other ports are not redirected
4136 * explicitly, to not break existing legacy setups which uses
4137 * -nographic _and_ redirects all ports explicitly - this is valid
4138 * usage, -nographic is just a no-op in this case.
4140 if (display_type == DT_NOGRAPHIC
4141 && (default_parallel || default_serial
4142 || default_monitor || default_virtcon)) {
4143 fprintf(stderr, "-nographic can not be used with -daemonize\n");
4146 #ifdef CONFIG_CURSES
4147 if (display_type == DT_CURSES) {
4148 fprintf(stderr, "curses display can not be used with -daemonize\n");
4154 if (display_type == DT_NOGRAPHIC) {
4155 if (default_parallel)
4156 add_device_config(DEV_PARALLEL, "null");
4157 if (default_serial && default_monitor) {
4158 add_device_config(DEV_SERIAL, "mon:stdio");
4159 } else if (default_virtcon && default_monitor) {
4160 add_device_config(DEV_VIRTCON, "mon:stdio");
4161 } else if (default_sclp && default_monitor) {
4162 add_device_config(DEV_SCLP, "mon:stdio");
4165 add_device_config(DEV_SERIAL, "stdio");
4166 if (default_virtcon)
4167 add_device_config(DEV_VIRTCON, "stdio");
4169 add_device_config(DEV_SCLP, "stdio");
4171 if (default_monitor)
4172 monitor_parse("stdio", "readline");
4176 add_device_config(DEV_SERIAL, "vc:80Cx24C");
4177 if (default_parallel)
4178 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
4179 if (default_monitor)
4180 monitor_parse("vc:80Cx24C", "readline");
4181 if (default_virtcon)
4182 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
4184 add_device_config(DEV_SCLP, "vc:80Cx24C");
4188 if (display_type == DT_DEFAULT && !display_remote) {
4189 #if defined(CONFIG_GTK)
4190 display_type = DT_GTK;
4191 #elif defined(CONFIG_SDL) || defined(CONFIG_COCOA)
4192 display_type = DT_SDL;
4193 #elif defined(CONFIG_VNC)
4194 vnc_display = "localhost:0,to=99";
4196 #elif defined(CONFIG_MARU) && defined (__APPLE__)
4197 display_type = DT_MARU;
4199 display_type = DT_NONE;
4203 #if defined(CONFIG_GTK)
4204 if (display_type == DT_GTK) {
4205 early_gtk_display_init();
4213 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
4215 #ifdef CONFIG_VIRTFS
4216 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
4223 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
4228 /* init the memory */
4229 if (ram_size == 0) {
4230 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
4233 // W/A for preserve larger continuous heap for RAM.
4234 preallocated_ptr = g_malloc0(ram_size);
4237 hax_pre_init(ram_size);
4239 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0)
4244 configure_accelerator();
4246 if (!qtest_enabled() && qtest_chrdev) {
4250 machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
4252 kernel_filename = qemu_opt_get(machine_opts, "kernel");
4253 initrd_filename = qemu_opt_get(machine_opts, "initrd");
4254 kernel_cmdline = qemu_opt_get(machine_opts, "append");
4256 kernel_filename = initrd_filename = kernel_cmdline = NULL;
4259 if (!kernel_cmdline) {
4260 kernel_cmdline = "";
4263 linux_boot = (kernel_filename != NULL);
4265 if (!linux_boot && *kernel_cmdline != '\0') {
4266 fprintf(stderr, "-append only allowed with -kernel option\n");
4270 if (!linux_boot && initrd_filename != NULL) {
4271 fprintf(stderr, "-initrd only allowed with -kernel option\n");
4275 if (!linux_boot && machine_opts && qemu_opt_get(machine_opts, "dtb")) {
4276 fprintf(stderr, "-dtb only allowed with -kernel option\n");
4280 os_set_line_buffering();
4282 qemu_init_cpu_loop();
4283 qemu_mutex_lock_iothread();
4286 /* spice needs the timers to be initialized by this point */
4290 if (icount_option && (kvm_enabled() || xen_enabled() || hax_enabled())) {
4291 fprintf(stderr, "-icount is not allowed with kvm or xen\n");
4294 configure_icount(icount_option);
4296 /* clean up network at qemu process termination */
4297 atexit(&net_cleanup);
4299 if (net_init_clients() < 0) {
4304 if (tpm_init() < 0) {
4309 /* init the bluetooth world */
4310 if (foreach_device_config(DEV_BT, bt_parse))
4313 if (!xen_enabled()) {
4314 /* On 32-bit hosts, QEMU is limited by virtual address space */
4315 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
4316 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
4321 cpu_exec_init_all();
4325 /* open the virtual block devices */
4327 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
4328 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func,
4329 &machine->block_default_type, 1) != 0) {
4333 default_drive(default_cdrom, snapshot, machine->block_default_type, 2,
4335 default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS);
4336 default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS);
4338 register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL);
4340 if (nb_numa_nodes > 0) {
4343 if (nb_numa_nodes > MAX_NODES) {
4344 nb_numa_nodes = MAX_NODES;
4347 /* If no memory size if given for any node, assume the default case
4348 * and distribute the available memory equally across all nodes
4350 for (i = 0; i < nb_numa_nodes; i++) {
4351 if (node_mem[i] != 0)
4354 if (i == nb_numa_nodes) {
4355 uint64_t usedmem = 0;
4357 /* On Linux, the each node's border has to be 8MB aligned,
4358 * the final node gets the rest.
4360 for (i = 0; i < nb_numa_nodes - 1; i++) {
4361 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
4362 usedmem += node_mem[i];
4364 node_mem[i] = ram_size - usedmem;
4367 for (i = 0; i < nb_numa_nodes; i++) {
4368 if (!bitmap_empty(node_cpumask[i], MAX_CPUMASK_BITS)) {
4372 /* assigning the VCPUs round-robin is easier to implement, guest OSes
4373 * must cope with this anyway, because there are BIOSes out there in
4374 * real machines which also use this scheme.
4376 if (i == nb_numa_nodes) {
4377 for (i = 0; i < max_cpus; i++) {
4378 set_bit(i, node_cpumask[i % nb_numa_nodes]);
4383 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
4387 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
4389 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
4391 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
4393 if (foreach_device_config(DEV_SCLP, sclp_parse) < 0) {
4396 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
4399 /* If no default VGA is requested, the default is "none". */
4401 if (cirrus_vga_available()) {
4402 vga_model = "cirrus";
4403 } else if (vga_available()) {
4407 select_vgahw(vga_model);
4410 i = select_watchdog(watchdog);
4412 exit (i == 1 ? 1 : 0);
4415 if (machine->compat_props) {
4416 qdev_prop_register_global_list(machine->compat_props);
4420 qdev_machine_init();
4423 // Returned variable points different address from input variable.
4424 kernel_cmdline = prepare_maru_devices(kernel_cmdline);
4426 QEMUMachineInitArgs args = { .ram_size = ram_size,
4427 .boot_device = (boot_devices[0] == '\0') ?
4428 machine->boot_order :
4430 .kernel_filename = kernel_filename,
4431 .kernel_cmdline = kernel_cmdline,
4432 .initrd_filename = initrd_filename,
4433 .cpu_model = cpu_model };
4434 machine->init(&args);
4436 // TODO: Check about it...
4439 cpu_synchronize_all_post_init();
4443 current_machine = machine;
4445 if (hax_enabled()) {
4449 /* init USB devices */
4450 if (usb_enabled(false)) {
4451 if (foreach_device_config(DEV_USB, usb_parse) < 0)
4455 /* init generic devices */
4456 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
4459 net_check_clients();
4461 ds = init_displaystate();
4463 /* init local displays */
4464 switch (display_type) {
4467 #if defined(CONFIG_CURSES)
4469 curses_display_init(ds, full_screen);
4472 #if defined(CONFIG_SDL)
4474 #if defined(CONFIG_MARU)
4475 /* use tizen qemu sdl */
4476 maru_display_init(ds);
4477 if (skin_disabled == 1) {
4478 //do not start skin client process
4479 set_emul_skin_enable(0);
4481 set_emul_skin_enable(1);
4484 sdl_display_init(ds, full_screen, no_frame);
4487 #elif defined(CONFIG_COCOA)
4489 cocoa_display_init(ds, full_screen);
4492 #if defined(CONFIG_MARU) && defined(__APPLE__)
4494 maru_display_init(ds);
4495 if (skin_disabled == 1) {
4496 //do not start skin client process
4497 set_emul_skin_enable(0);
4499 set_emul_skin_enable(1);
4503 #if defined(CONFIG_GTK)
4505 gtk_display_init(ds);
4512 /* must be after terminal init, SDL library changes signal handlers */
4513 os_setup_signal_handling();
4516 /* init remote displays */
4518 Error *local_err = NULL;
4519 vnc_display_init(ds);
4520 vnc_display_open(ds, vnc_display, &local_err);
4521 if (local_err != NULL) {
4522 fprintf(stderr, "Failed to start VNC server on `%s': %s\n",
4523 vnc_display, error_get_pretty(local_err));
4524 error_free(local_err);
4528 if (show_vnc_port) {
4529 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
4534 if (using_spice && !qxl_enabled) {
4535 qemu_spice_display_init(ds);
4539 if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
4543 qdev_machine_creation_done();
4545 if (rom_load_all() != 0) {
4546 fprintf(stderr, "rom loading failed\n");
4550 /* TODO: once all bus devices are qdevified, this should be done
4551 * when bus is created by qdev.c */
4552 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
4553 qemu_run_machine_init_done_notifiers();
4555 qemu_system_reset(VMRESET_SILENT);
4557 if (load_vmstate(loadvm) < 0) {
4563 Error *local_err = NULL;
4564 qemu_start_incoming_migration(incoming, &local_err);
4566 fprintf(stderr, "-incoming %s: %s\n", incoming, error_get_pretty(local_err));
4567 error_free(local_err);
4570 } else if (autostart) {