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)
44 int qemu_main(int argc
, char **argv
, char **envp
);
45 int main(int argc
, char **argv
)
47 return qemu_main(argc
, argv
, NULL
);
50 #define main qemu_main
52 #endif /* CONFIG_SDL */
56 #define main qemu_main
57 #endif /* CONFIG_COCOA */
61 #include "qemu/sockets.h"
63 #include "hw/boards.h"
64 #include "sysemu/accel.h"
66 #include "hw/i386/pc.h"
67 #include "hw/isa/isa.h"
69 #include "sysemu/watchdog.h"
70 #include "hw/i386/smbios.h"
71 #include "hw/xen/xen.h"
73 #include "hw/loader.h"
74 #include "monitor/qdev.h"
75 #include "sysemu/bt.h"
77 #include "net/slirp.h"
78 #include "monitor/monitor.h"
79 #include "ui/console.h"
80 #include "sysemu/sysemu.h"
81 #include "sysemu/numa.h"
82 #include "exec/gdbstub.h"
83 #include "qemu/timer.h"
84 #include "sysemu/char.h"
85 #include "qemu/bitmap.h"
86 #include "sysemu/blockdev.h"
87 #include "hw/block/block.h"
88 #include "migration/block.h"
89 #include "sysemu/tpm.h"
90 #include "sysemu/dma.h"
91 #include "audio/audio.h"
92 #include "migration/migration.h"
93 #include "sysemu/kvm.h"
94 #include "qapi/qmp/qjson.h"
95 #include "qemu/option.h"
96 #include "qemu/config-file.h"
97 #include "qemu-options.h"
98 #include "qmp-commands.h"
99 #include "qemu/main-loop.h"
101 #include "fsdev/qemu-fsdev.h"
103 #include "sysemu/qtest.h"
105 #include "disas/disas.h"
108 #include "slirp/libslirp.h"
111 #include "trace/control.h"
112 #include "qemu/queue.h"
113 #include "sysemu/cpus.h"
114 #include "sysemu/arch_init.h"
115 #include "qemu/osdep.h"
117 #include "ui/qemu-spice.h"
118 #include "qapi/string-input-visitor.h"
119 #include "qapi/opts-visitor.h"
120 #include "qom/object_interfaces.h"
121 #include "qapi-event.h"
123 #define DEFAULT_RAM_SIZE 128
125 #define MAX_VIRTIO_CONSOLES 1
126 #define MAX_SCLP_CONSOLES 1
128 static const char *data_dir
[16];
129 static int data_dir_idx
;
130 const char *bios_name
= NULL
;
131 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
132 DisplayType display_type
= DT_DEFAULT
;
133 int request_opengl
= -1;
135 static int display_remote
;
136 const char* keyboard_layout
= NULL
;
138 const char *mem_path
= NULL
;
139 int mem_prealloc
= 0; /* force preallocation of physical target memory */
140 bool enable_mlock
= false;
142 NICInfo nd_table
[MAX_NICS
];
144 static int rtc_utc
= 1;
145 static int rtc_date_offset
= -1; /* -1 means no change */
146 QEMUClockType rtc_clock
;
147 int vga_interface_type
= VGA_NONE
;
148 static int full_screen
= 0;
149 static int no_frame
= 0;
152 static bool grab_on_hover
;
154 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
155 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
156 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
157 CharDriverState
*sclp_hds
[MAX_SCLP_CONSOLES
];
158 int win2k_install_hack
= 0;
164 int acpi_enabled
= 1;
167 static int no_reboot
;
170 int graphic_rotate
= 0;
171 const char *watchdog
;
172 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
174 int semihosting_enabled
= 0;
176 const char *qemu_name
;
179 unsigned int nb_prom_envs
= 0;
180 const char *prom_envs
[MAX_PROM_ENVS
];
183 uint8_t *boot_splash_filedata
;
184 size_t boot_splash_filedata_size
;
185 uint8_t qemu_extra_params_fw
[2];
187 int icount_align_option
;
189 /* The bytes in qemu_uuid[] are in the order specified by RFC4122, _not_ in the
190 * little-endian "wire format" described in the SMBIOS 2.6 specification.
192 uint8_t qemu_uuid
[16];
195 static NotifierList exit_notifiers
=
196 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
198 static NotifierList machine_init_done_notifiers
=
199 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
203 enum xen_mode xen_mode
= XEN_EMULATE
;
205 static int has_defaults
= 1;
206 static int default_serial
= 1;
207 static int default_parallel
= 1;
208 static int default_virtcon
= 1;
209 static int default_sclp
= 1;
210 static int default_monitor
= 1;
211 static int default_floppy
= 1;
212 static int default_cdrom
= 1;
213 static int default_sdcard
= 1;
214 static int default_vga
= 1;
220 { .driver
= "isa-serial", .flag
= &default_serial
},
221 { .driver
= "isa-parallel", .flag
= &default_parallel
},
222 { .driver
= "isa-fdc", .flag
= &default_floppy
},
223 { .driver
= "ide-cd", .flag
= &default_cdrom
},
224 { .driver
= "ide-hd", .flag
= &default_cdrom
},
225 { .driver
= "ide-drive", .flag
= &default_cdrom
},
226 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
227 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
228 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
229 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
230 { .driver
= "VGA", .flag
= &default_vga
},
231 { .driver
= "isa-vga", .flag
= &default_vga
},
232 { .driver
= "cirrus-vga", .flag
= &default_vga
},
233 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
234 { .driver
= "vmware-svga", .flag
= &default_vga
},
235 { .driver
= "qxl-vga", .flag
= &default_vga
},
238 static QemuOptsList qemu_rtc_opts
= {
240 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
244 .type
= QEMU_OPT_STRING
,
247 .type
= QEMU_OPT_STRING
,
250 .type
= QEMU_OPT_STRING
,
252 { /* end of list */ }
256 static QemuOptsList qemu_sandbox_opts
= {
258 .implied_opt_name
= "enable",
259 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
263 .type
= QEMU_OPT_BOOL
,
265 { /* end of list */ }
269 static QemuOptsList qemu_trace_opts
= {
271 .implied_opt_name
= "trace",
272 .head
= QTAILQ_HEAD_INITIALIZER(qemu_trace_opts
.head
),
276 .type
= QEMU_OPT_STRING
,
279 .type
= QEMU_OPT_STRING
,
281 { /* end of list */ }
285 static QemuOptsList qemu_option_rom_opts
= {
286 .name
= "option-rom",
287 .implied_opt_name
= "romfile",
288 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
292 .type
= QEMU_OPT_NUMBER
,
295 .type
= QEMU_OPT_STRING
,
297 { /* end of list */ }
301 static QemuOptsList qemu_machine_opts
= {
303 .implied_opt_name
= "type",
305 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
308 * no elements => accept any
309 * sanity checking will happen later
310 * when setting machine properties
316 static QemuOptsList qemu_boot_opts
= {
318 .implied_opt_name
= "order",
320 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
324 .type
= QEMU_OPT_STRING
,
327 .type
= QEMU_OPT_STRING
,
330 .type
= QEMU_OPT_BOOL
,
333 .type
= QEMU_OPT_STRING
,
335 .name
= "splash-time",
336 .type
= QEMU_OPT_STRING
,
338 .name
= "reboot-timeout",
339 .type
= QEMU_OPT_STRING
,
342 .type
= QEMU_OPT_BOOL
,
348 static QemuOptsList qemu_add_fd_opts
= {
350 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
354 .type
= QEMU_OPT_NUMBER
,
355 .help
= "file descriptor of which a duplicate is added to fd set",
358 .type
= QEMU_OPT_NUMBER
,
359 .help
= "ID of the fd set to add fd to",
362 .type
= QEMU_OPT_STRING
,
363 .help
= "free-form string used to describe fd",
365 { /* end of list */ }
369 static QemuOptsList qemu_object_opts
= {
371 .implied_opt_name
= "qom-type",
372 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
378 static QemuOptsList qemu_tpmdev_opts
= {
380 .implied_opt_name
= "type",
381 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
383 /* options are defined in the TPM backends */
384 { /* end of list */ }
388 static QemuOptsList qemu_realtime_opts
= {
390 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
394 .type
= QEMU_OPT_BOOL
,
396 { /* end of list */ }
400 static QemuOptsList qemu_msg_opts
= {
402 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
406 .type
= QEMU_OPT_BOOL
,
408 { /* end of list */ }
412 static QemuOptsList qemu_name_opts
= {
414 .implied_opt_name
= "guest",
416 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
420 .type
= QEMU_OPT_STRING
,
421 .help
= "Sets the name of the guest.\n"
422 "This name will be displayed in the SDL window caption.\n"
423 "The name will also be used for the VNC server",
426 .type
= QEMU_OPT_STRING
,
427 .help
= "Sets the name of the QEMU process, as shown in top etc",
429 .name
= "debug-threads",
430 .type
= QEMU_OPT_BOOL
,
431 .help
= "When enabled, name the individual threads; defaults off.\n"
432 "NOTE: The thread names are for debugging and not a\n"
435 { /* End of list */ }
439 static QemuOptsList qemu_mem_opts
= {
441 .implied_opt_name
= "size",
442 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
447 .type
= QEMU_OPT_SIZE
,
451 .type
= QEMU_OPT_NUMBER
,
455 .type
= QEMU_OPT_SIZE
,
457 { /* end of list */ }
461 static QemuOptsList qemu_icount_opts
= {
463 .implied_opt_name
= "shift",
465 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
469 .type
= QEMU_OPT_STRING
,
472 .type
= QEMU_OPT_BOOL
,
474 { /* end of list */ }
478 static QemuOptsList qemu_semihosting_config_opts
= {
479 .name
= "semihosting-config",
480 .implied_opt_name
= "enable",
481 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
485 .type
= QEMU_OPT_BOOL
,
488 .type
= QEMU_OPT_STRING
,
490 { /* end of list */ }
495 * Get machine options
497 * Returns: machine options (never null).
499 QemuOpts
*qemu_get_machine_opts(void)
501 return qemu_find_opts_singleton("machine");
504 const char *qemu_get_vm_name(void)
509 static void res_free(void)
511 if (boot_splash_filedata
!= NULL
) {
512 g_free(boot_splash_filedata
);
513 boot_splash_filedata
= NULL
;
517 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
519 const char *driver
= qemu_opt_get(opts
, "driver");
524 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
525 if (strcmp(default_list
[i
].driver
, driver
) != 0)
527 *(default_list
[i
].flag
) = 0;
532 /***********************************************************/
535 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
537 /* We use RUN_STATE_MAX but any invalid value will do */
538 static RunState vmstop_requested
= RUN_STATE_MAX
;
539 static QemuMutex vmstop_lock
;
544 } RunStateTransition
;
546 static const RunStateTransition runstate_transitions_def
[] = {
548 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
549 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
551 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
552 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
554 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
555 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
557 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
558 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
560 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
561 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
563 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
564 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
566 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
567 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
568 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
570 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
571 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
573 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
575 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
576 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
577 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
578 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
579 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
580 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
581 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
582 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
583 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
584 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
586 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
588 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
589 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
591 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
592 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
593 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
594 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
596 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
597 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
599 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
600 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
602 { RUN_STATE_MAX
, RUN_STATE_MAX
},
605 static bool runstate_valid_transitions
[RUN_STATE_MAX
][RUN_STATE_MAX
];
607 bool runstate_check(RunState state
)
609 return current_run_state
== state
;
612 static void runstate_init(void)
614 const RunStateTransition
*p
;
616 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
617 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE_MAX
; p
++) {
618 runstate_valid_transitions
[p
->from
][p
->to
] = true;
621 qemu_mutex_init(&vmstop_lock
);
624 /* This function will abort() on invalid state transitions */
625 void runstate_set(RunState new_state
)
627 assert(new_state
< RUN_STATE_MAX
);
629 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
630 fprintf(stderr
, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
631 RunState_lookup
[current_run_state
],
632 RunState_lookup
[new_state
]);
635 trace_runstate_set(new_state
);
636 current_run_state
= new_state
;
639 int runstate_is_running(void)
641 return runstate_check(RUN_STATE_RUNNING
);
644 bool runstate_needs_reset(void)
646 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
647 runstate_check(RUN_STATE_SHUTDOWN
);
650 StatusInfo
*qmp_query_status(Error
**errp
)
652 StatusInfo
*info
= g_malloc0(sizeof(*info
));
654 info
->running
= runstate_is_running();
655 info
->singlestep
= singlestep
;
656 info
->status
= current_run_state
;
661 static bool qemu_vmstop_requested(RunState
*r
)
663 qemu_mutex_lock(&vmstop_lock
);
664 *r
= vmstop_requested
;
665 vmstop_requested
= RUN_STATE_MAX
;
666 qemu_mutex_unlock(&vmstop_lock
);
667 return *r
< RUN_STATE_MAX
;
670 void qemu_system_vmstop_request_prepare(void)
672 qemu_mutex_lock(&vmstop_lock
);
675 void qemu_system_vmstop_request(RunState state
)
677 vmstop_requested
= state
;
678 qemu_mutex_unlock(&vmstop_lock
);
686 qemu_vmstop_requested(&requested
);
687 if (runstate_is_running() && requested
== RUN_STATE_MAX
) {
691 /* Ensure that a STOP/RESUME pair of events is emitted if a
692 * vmstop request was pending. The BLOCK_IO_ERROR event, for
693 * example, according to documentation is always followed by
696 if (runstate_is_running()) {
697 qapi_event_send_stop(&error_abort
);
700 runstate_set(RUN_STATE_RUNNING
);
701 vm_state_notify(1, RUN_STATE_RUNNING
);
705 qapi_event_send_resume(&error_abort
);
709 /***********************************************************/
710 /* real time host monotonic timer */
712 static time_t qemu_time(void)
714 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
717 /***********************************************************/
718 /* host time/date access */
719 void qemu_get_timedate(struct tm
*tm
, int offset
)
721 time_t ti
= qemu_time();
724 if (rtc_date_offset
== -1) {
728 localtime_r(&ti
, tm
);
730 ti
-= rtc_date_offset
;
735 int qemu_timedate_diff(struct tm
*tm
)
739 if (rtc_date_offset
== -1)
741 seconds
= mktimegm(tm
);
744 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
745 seconds
= mktime(&tmp
);
748 seconds
= mktimegm(tm
) + rtc_date_offset
;
750 return seconds
- qemu_time();
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
= qemu_time() - 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
= QEMU_CLOCK_HOST
;
810 } else if (!strcmp(value
, "rt")) {
811 rtc_clock
= QEMU_CLOCK_REALTIME
;
812 } else if (!strcmp(value
, "vm")) {
813 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
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 struct HCIInfo
*qemu_next_hci(void)
849 if (cur_hci
== nb_hcis
)
852 return hci_table
[cur_hci
++];
855 static int bt_hci_parse(const char *str
)
860 if (nb_hcis
>= MAX_NICS
) {
861 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
874 bdaddr
.b
[5] = 0x56 + nb_hcis
;
875 hci
->bdaddr_set(hci
, bdaddr
.b
);
877 hci_table
[nb_hcis
++] = hci
;
882 static void bt_vhci_add(int vlan_id
)
884 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
887 fprintf(stderr
, "qemu: warning: adding a VHCI to "
888 "an empty scatternet %i\n", vlan_id
);
890 bt_vhci_init(bt_new_hci(vlan
));
893 static struct bt_device_s
*bt_device_add(const char *opt
)
895 struct bt_scatternet_s
*vlan
;
897 char *endp
= strstr(opt
, ",vlan=");
898 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
901 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
904 vlan_id
= strtol(endp
+ 6, &endp
, 0);
906 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
911 vlan
= qemu_find_bt_vlan(vlan_id
);
914 fprintf(stderr
, "qemu: warning: adding a slave device to "
915 "an empty scatternet %i\n", vlan_id
);
917 if (!strcmp(devname
, "keyboard"))
918 return bt_keyboard_init(vlan
);
920 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
924 static int bt_parse(const char *opt
)
926 const char *endp
, *p
;
929 if (strstart(opt
, "hci", &endp
)) {
930 if (!*endp
|| *endp
== ',') {
932 if (!strstart(endp
, ",vlan=", 0))
935 return bt_hci_parse(opt
);
937 } else if (strstart(opt
, "vhci", &endp
)) {
938 if (!*endp
|| *endp
== ',') {
940 if (strstart(endp
, ",vlan=", &p
)) {
941 vlan
= strtol(p
, (char **) &endp
, 0);
943 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
947 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
956 } else if (strstart(opt
, "device:", &endp
))
957 return !bt_device_add(endp
);
959 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
963 static int parse_sandbox(QemuOpts
*opts
, void *opaque
)
965 /* FIXME: change this to true for 1.3 */
966 if (qemu_opt_get_bool(opts
, "enable", false)) {
967 #ifdef CONFIG_SECCOMP
968 if (seccomp_start() < 0) {
969 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
970 "failed to install seccomp syscall filter in the kernel");
974 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
975 "sandboxing request but seccomp is not compiled into this build");
983 static int parse_name(QemuOpts
*opts
, void *opaque
)
985 const char *proc_name
;
987 if (qemu_opt_get(opts
, "debug-threads")) {
988 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
990 qemu_name
= qemu_opt_get(opts
, "guest");
992 proc_name
= qemu_opt_get(opts
, "process");
994 os_set_proc_name(proc_name
);
1000 bool defaults_enabled(void)
1002 return has_defaults
;
1005 bool usb_enabled(void)
1007 return machine_usb(current_machine
);
1011 static int parse_add_fd(QemuOpts
*opts
, void *opaque
)
1013 int fd
, dupfd
, flags
;
1015 const char *fd_opaque
= NULL
;
1018 fd
= qemu_opt_get_number(opts
, "fd", -1);
1019 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1020 fd_opaque
= qemu_opt_get(opts
, "opaque");
1023 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1024 "fd option is required and must be non-negative");
1028 if (fd
<= STDERR_FILENO
) {
1029 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1030 "fd cannot be a standard I/O stream");
1035 * All fds inherited across exec() necessarily have FD_CLOEXEC
1036 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1038 flags
= fcntl(fd
, F_GETFD
);
1039 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1040 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1041 "fd is not valid or already in use");
1046 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1047 "set option is required and must be non-negative");
1051 #ifdef F_DUPFD_CLOEXEC
1052 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1056 qemu_set_cloexec(dupfd
);
1060 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1061 "Error duplicating fd: %s", strerror(errno
));
1065 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1066 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1073 static int cleanup_add_fd(QemuOpts
*opts
, void *opaque
)
1077 fd
= qemu_opt_get_number(opts
, "fd", -1);
1084 /***********************************************************/
1085 /* QEMU Block devices */
1087 #define HD_OPTS "media=disk"
1088 #define CDROM_OPTS "media=cdrom"
1090 #define PFLASH_OPTS ""
1094 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
1096 BlockInterfaceType
*block_default_type
= opaque
;
1098 return drive_new(opts
, *block_default_type
) == NULL
;
1101 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
1103 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1104 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1109 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1110 int index
, const char *optstr
)
1115 if (!enable
|| drive_get_by_index(type
, index
)) {
1119 opts
= drive_add(type
, index
, NULL
, optstr
);
1121 drive_enable_snapshot(opts
, NULL
);
1124 dinfo
= drive_new(opts
, type
);
1128 dinfo
->is_default
= true;
1132 static QemuOptsList qemu_smp_opts
= {
1134 .implied_opt_name
= "cpus",
1135 .merge_lists
= true,
1136 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1140 .type
= QEMU_OPT_NUMBER
,
1143 .type
= QEMU_OPT_NUMBER
,
1146 .type
= QEMU_OPT_NUMBER
,
1149 .type
= QEMU_OPT_NUMBER
,
1152 .type
= QEMU_OPT_NUMBER
,
1154 { /*End of list */ }
1158 static void smp_parse(QemuOpts
*opts
)
1162 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1163 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1164 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1165 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1167 /* compute missing values, prefer sockets over cores over threads */
1168 if (cpus
== 0 || sockets
== 0) {
1169 sockets
= sockets
> 0 ? sockets
: 1;
1170 cores
= cores
> 0 ? cores
: 1;
1171 threads
= threads
> 0 ? threads
: 1;
1173 cpus
= cores
* threads
* sockets
;
1175 } else if (cores
== 0) {
1176 threads
= threads
> 0 ? threads
: 1;
1177 cores
= cpus
/ (sockets
* threads
);
1178 } else if (threads
== 0) {
1179 threads
= cpus
/ (cores
* sockets
);
1180 } else if (sockets
* cores
* threads
< cpus
) {
1181 fprintf(stderr
, "cpu topology: error: "
1182 "sockets (%u) * cores (%u) * threads (%u) < "
1184 sockets
, cores
, threads
, cpus
);
1188 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", 0);
1191 smp_cores
= cores
> 0 ? cores
: 1;
1192 smp_threads
= threads
> 0 ? threads
: 1;
1196 if (max_cpus
== 0) {
1197 max_cpus
= smp_cpus
;
1200 if (max_cpus
> MAX_CPUMASK_BITS
) {
1201 fprintf(stderr
, "Unsupported number of maxcpus\n");
1204 if (max_cpus
< smp_cpus
) {
1205 fprintf(stderr
, "maxcpus must be equal to or greater than smp\n");
1211 static void realtime_init(void)
1214 if (os_mlock() < 0) {
1215 fprintf(stderr
, "qemu: locking memory failed\n");
1222 static void configure_msg(QemuOpts
*opts
)
1224 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1227 /***********************************************************/
1230 static int usb_device_add(const char *devname
)
1232 USBDevice
*dev
= NULL
;
1233 #ifndef CONFIG_LINUX
1237 if (!usb_enabled()) {
1241 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1242 dev
= usbdevice_create(devname
);
1246 /* the other ones */
1247 #ifndef CONFIG_LINUX
1248 /* only the linux version is qdev-ified, usb-bsd still needs this */
1249 if (strstart(devname
, "host:", &p
)) {
1250 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1260 static int usb_device_del(const char *devname
)
1265 if (strstart(devname
, "host:", &p
)) {
1269 if (!usb_enabled()) {
1273 p
= strchr(devname
, '.');
1276 bus_num
= strtoul(devname
, NULL
, 0);
1277 addr
= strtoul(p
+ 1, NULL
, 0);
1279 return usb_device_delete_addr(bus_num
, addr
);
1282 static int usb_parse(const char *cmdline
)
1285 r
= usb_device_add(cmdline
);
1287 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
1292 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1294 const char *devname
= qdict_get_str(qdict
, "devname");
1295 if (usb_device_add(devname
) < 0) {
1296 error_report("could not add USB device '%s'", devname
);
1300 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1302 const char *devname
= qdict_get_str(qdict
, "devname");
1303 if (usb_device_del(devname
) < 0) {
1304 error_report("could not delete USB device '%s'", devname
);
1308 /***********************************************************/
1309 /* machine registration */
1311 MachineState
*current_machine
;
1313 static void machine_class_init(ObjectClass
*oc
, void *data
)
1315 MachineClass
*mc
= MACHINE_CLASS(oc
);
1316 QEMUMachine
*qm
= data
;
1318 mc
->family
= qm
->family
;
1319 mc
->name
= qm
->name
;
1320 mc
->alias
= qm
->alias
;
1321 mc
->desc
= qm
->desc
;
1322 mc
->init
= qm
->init
;
1323 mc
->reset
= qm
->reset
;
1324 mc
->hot_add_cpu
= qm
->hot_add_cpu
;
1325 mc
->kvm_type
= qm
->kvm_type
;
1326 mc
->block_default_type
= qm
->block_default_type
;
1327 mc
->units_per_default_bus
= qm
->units_per_default_bus
;
1328 mc
->max_cpus
= qm
->max_cpus
;
1329 mc
->no_serial
= qm
->no_serial
;
1330 mc
->no_parallel
= qm
->no_parallel
;
1331 mc
->use_virtcon
= qm
->use_virtcon
;
1332 mc
->use_sclp
= qm
->use_sclp
;
1333 mc
->no_floppy
= qm
->no_floppy
;
1334 mc
->no_cdrom
= qm
->no_cdrom
;
1335 mc
->no_sdcard
= qm
->no_sdcard
;
1336 mc
->has_dynamic_sysbus
= qm
->has_dynamic_sysbus
;
1337 mc
->is_default
= qm
->is_default
;
1338 mc
->default_machine_opts
= qm
->default_machine_opts
;
1339 mc
->default_boot_order
= qm
->default_boot_order
;
1340 mc
->default_display
= qm
->default_display
;
1341 mc
->compat_props
= qm
->compat_props
;
1342 mc
->hw_version
= qm
->hw_version
;
1345 int qemu_register_machine(QEMUMachine
*m
)
1347 char *name
= g_strconcat(m
->name
, TYPE_MACHINE_SUFFIX
, NULL
);
1350 .parent
= TYPE_MACHINE
,
1351 .class_init
= machine_class_init
,
1352 .class_data
= (void *)m
,
1361 static MachineClass
*find_machine(const char *name
)
1363 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1364 MachineClass
*mc
= NULL
;
1366 for (el
= machines
; el
; el
= el
->next
) {
1367 MachineClass
*temp
= el
->data
;
1369 if (!strcmp(temp
->name
, name
)) {
1374 !strcmp(temp
->alias
, name
)) {
1380 g_slist_free(machines
);
1384 MachineClass
*find_default_machine(void)
1386 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1387 MachineClass
*mc
= NULL
;
1389 for (el
= machines
; el
; el
= el
->next
) {
1390 MachineClass
*temp
= el
->data
;
1392 if (temp
->is_default
) {
1398 g_slist_free(machines
);
1402 MachineInfoList
*qmp_query_machines(Error
**errp
)
1404 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1405 MachineInfoList
*mach_list
= NULL
;
1407 for (el
= machines
; el
; el
= el
->next
) {
1408 MachineClass
*mc
= el
->data
;
1409 MachineInfoList
*entry
;
1412 info
= g_malloc0(sizeof(*info
));
1413 if (mc
->is_default
) {
1414 info
->has_is_default
= true;
1415 info
->is_default
= true;
1419 info
->has_alias
= true;
1420 info
->alias
= g_strdup(mc
->alias
);
1423 info
->name
= g_strdup(mc
->name
);
1424 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1426 entry
= g_malloc0(sizeof(*entry
));
1427 entry
->value
= info
;
1428 entry
->next
= mach_list
;
1432 g_slist_free(machines
);
1436 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1438 ObjectProperty
*prop
;
1440 if (!qemu_opt_has_help_opt(opts
)) {
1444 QTAILQ_FOREACH(prop
, &OBJECT(machine
)->properties
, node
) {
1449 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1450 prop
->name
, prop
->type
);
1451 if (prop
->description
) {
1452 error_printf(" (%s)\n", prop
->description
);
1461 /***********************************************************/
1462 /* main execution loop */
1464 struct vm_change_state_entry
{
1465 VMChangeStateHandler
*cb
;
1467 QLIST_ENTRY (vm_change_state_entry
) entries
;
1470 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1472 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1475 VMChangeStateEntry
*e
;
1477 e
= g_malloc0(sizeof (*e
));
1481 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1485 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1487 QLIST_REMOVE (e
, entries
);
1491 void vm_state_notify(int running
, RunState state
)
1493 VMChangeStateEntry
*e
, *next
;
1495 trace_vm_state_notify(running
, state
);
1497 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1498 e
->cb(e
->opaque
, running
, state
);
1502 /* reset/shutdown handler */
1504 typedef struct QEMUResetEntry
{
1505 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1506 QEMUResetHandler
*func
;
1510 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1511 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1512 static int reset_requested
;
1513 static int shutdown_requested
, shutdown_signal
= -1;
1514 static pid_t shutdown_pid
;
1515 static int powerdown_requested
;
1516 static int debug_requested
;
1517 static int suspend_requested
;
1518 static WakeupReason wakeup_reason
;
1519 static NotifierList powerdown_notifiers
=
1520 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1521 static NotifierList suspend_notifiers
=
1522 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1523 static NotifierList wakeup_notifiers
=
1524 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1525 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1527 int qemu_shutdown_requested_get(void)
1529 return shutdown_requested
;
1532 int qemu_reset_requested_get(void)
1534 return reset_requested
;
1537 static int qemu_shutdown_requested(void)
1539 return atomic_xchg(&shutdown_requested
, 0);
1542 static void qemu_kill_report(void)
1544 if (!qtest_driver() && shutdown_signal
!= -1) {
1545 fprintf(stderr
, "qemu: terminating on signal %d", shutdown_signal
);
1546 if (shutdown_pid
== 0) {
1547 /* This happens for eg ^C at the terminal, so it's worth
1548 * avoiding printing an odd message in that case.
1550 fputc('\n', stderr
);
1552 fprintf(stderr
, " from pid " FMT_pid
"\n", shutdown_pid
);
1554 shutdown_signal
= -1;
1558 static int qemu_reset_requested(void)
1560 int r
= reset_requested
;
1561 reset_requested
= 0;
1565 static int qemu_suspend_requested(void)
1567 int r
= suspend_requested
;
1568 suspend_requested
= 0;
1572 static WakeupReason
qemu_wakeup_requested(void)
1574 return wakeup_reason
;
1577 static int qemu_powerdown_requested(void)
1579 int r
= powerdown_requested
;
1580 powerdown_requested
= 0;
1584 static int qemu_debug_requested(void)
1586 int r
= debug_requested
;
1587 debug_requested
= 0;
1591 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1593 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1596 re
->opaque
= opaque
;
1597 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1600 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1604 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1605 if (re
->func
== func
&& re
->opaque
== opaque
) {
1606 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1613 void qemu_devices_reset(void)
1615 QEMUResetEntry
*re
, *nre
;
1617 /* reset all devices */
1618 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1619 re
->func(re
->opaque
);
1623 void qemu_system_reset(bool report
)
1627 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1629 if (mc
&& mc
->reset
) {
1632 qemu_devices_reset();
1635 qapi_event_send_reset(&error_abort
);
1637 cpu_synchronize_all_post_reset();
1640 void qemu_system_reset_request(void)
1643 shutdown_requested
= 1;
1645 reset_requested
= 1;
1648 qemu_notify_event();
1651 static void qemu_system_suspend(void)
1654 notifier_list_notify(&suspend_notifiers
, NULL
);
1655 runstate_set(RUN_STATE_SUSPENDED
);
1656 qapi_event_send_suspend(&error_abort
);
1659 void qemu_system_suspend_request(void)
1661 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1664 suspend_requested
= 1;
1666 qemu_notify_event();
1669 void qemu_register_suspend_notifier(Notifier
*notifier
)
1671 notifier_list_add(&suspend_notifiers
, notifier
);
1674 void qemu_system_wakeup_request(WakeupReason reason
)
1676 trace_system_wakeup_request(reason
);
1678 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1681 if (!(wakeup_reason_mask
& (1 << reason
))) {
1684 runstate_set(RUN_STATE_RUNNING
);
1685 wakeup_reason
= reason
;
1686 qemu_notify_event();
1689 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1692 wakeup_reason_mask
|= (1 << reason
);
1694 wakeup_reason_mask
&= ~(1 << reason
);
1698 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1700 notifier_list_add(&wakeup_notifiers
, notifier
);
1703 void qemu_system_killed(int signal
, pid_t pid
)
1705 shutdown_signal
= signal
;
1708 qemu_system_shutdown_request();
1711 void qemu_system_shutdown_request(void)
1713 trace_qemu_system_shutdown_request();
1714 shutdown_requested
= 1;
1715 qemu_notify_event();
1718 static void qemu_system_powerdown(void)
1720 qapi_event_send_powerdown(&error_abort
);
1721 notifier_list_notify(&powerdown_notifiers
, NULL
);
1724 void qemu_system_powerdown_request(void)
1726 trace_qemu_system_powerdown_request();
1727 powerdown_requested
= 1;
1728 qemu_notify_event();
1731 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1733 notifier_list_add(&powerdown_notifiers
, notifier
);
1736 void qemu_system_debug_request(void)
1738 debug_requested
= 1;
1739 qemu_notify_event();
1742 static bool main_loop_should_exit(void)
1745 if (qemu_debug_requested()) {
1746 vm_stop(RUN_STATE_DEBUG
);
1748 if (qemu_suspend_requested()) {
1749 qemu_system_suspend();
1751 if (qemu_shutdown_requested()) {
1753 qapi_event_send_shutdown(&error_abort
);
1755 vm_stop(RUN_STATE_SHUTDOWN
);
1760 if (qemu_reset_requested()) {
1762 cpu_synchronize_all_states();
1763 qemu_system_reset(VMRESET_REPORT
);
1765 if (runstate_needs_reset()) {
1766 runstate_set(RUN_STATE_PAUSED
);
1769 if (qemu_wakeup_requested()) {
1771 cpu_synchronize_all_states();
1772 qemu_system_reset(VMRESET_SILENT
);
1773 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1774 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1776 qapi_event_send_wakeup(&error_abort
);
1778 if (qemu_powerdown_requested()) {
1779 qemu_system_powerdown();
1781 if (qemu_vmstop_requested(&r
)) {
1787 static void main_loop(void)
1791 #ifdef CONFIG_PROFILER
1795 nonblocking
= !kvm_enabled() && !xen_enabled() && last_io
> 0;
1796 #ifdef CONFIG_PROFILER
1797 ti
= profile_getclock();
1799 last_io
= main_loop_wait(nonblocking
);
1800 #ifdef CONFIG_PROFILER
1801 dev_time
+= profile_getclock() - ti
;
1803 } while (!main_loop_should_exit());
1806 static void version(void)
1808 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1811 static void help(int exitcode
)
1814 printf("usage: %s [options] [disk_image]\n\n"
1815 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1816 error_get_progname());
1818 #define QEMU_OPTIONS_GENERATE_HELP
1819 #include "qemu-options-wrapper.h"
1821 printf("\nDuring emulation, the following keys are useful:\n"
1822 "ctrl-alt-f toggle full screen\n"
1823 "ctrl-alt-n switch to virtual console 'n'\n"
1824 "ctrl-alt toggle mouse and keyboard grab\n"
1826 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1831 #define HAS_ARG 0x0001
1833 typedef struct QEMUOption
{
1840 static const QEMUOption qemu_options
[] = {
1841 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1842 #define QEMU_OPTIONS_GENERATE_OPTIONS
1843 #include "qemu-options-wrapper.h"
1847 static bool vga_available(void)
1849 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
1852 static bool cirrus_vga_available(void)
1854 return object_class_by_name("cirrus-vga")
1855 || object_class_by_name("isa-cirrus-vga");
1858 static bool vmware_vga_available(void)
1860 return object_class_by_name("vmware-svga");
1863 static bool qxl_vga_available(void)
1865 return object_class_by_name("qxl-vga");
1868 static bool tcx_vga_available(void)
1870 return object_class_by_name("SUNW,tcx");
1873 static bool cg3_vga_available(void)
1875 return object_class_by_name("cgthree");
1878 static void select_vgahw (const char *p
)
1882 assert(vga_interface_type
== VGA_NONE
);
1883 if (strstart(p
, "std", &opts
)) {
1884 if (vga_available()) {
1885 vga_interface_type
= VGA_STD
;
1887 fprintf(stderr
, "Error: standard VGA not available\n");
1890 } else if (strstart(p
, "cirrus", &opts
)) {
1891 if (cirrus_vga_available()) {
1892 vga_interface_type
= VGA_CIRRUS
;
1894 fprintf(stderr
, "Error: Cirrus VGA not available\n");
1897 } else if (strstart(p
, "vmware", &opts
)) {
1898 if (vmware_vga_available()) {
1899 vga_interface_type
= VGA_VMWARE
;
1901 fprintf(stderr
, "Error: VMWare SVGA not available\n");
1904 } else if (strstart(p
, "xenfb", &opts
)) {
1905 vga_interface_type
= VGA_XENFB
;
1906 } else if (strstart(p
, "qxl", &opts
)) {
1907 if (qxl_vga_available()) {
1908 vga_interface_type
= VGA_QXL
;
1910 fprintf(stderr
, "Error: QXL VGA not available\n");
1913 } else if (strstart(p
, "tcx", &opts
)) {
1914 if (tcx_vga_available()) {
1915 vga_interface_type
= VGA_TCX
;
1917 fprintf(stderr
, "Error: TCX framebuffer not available\n");
1920 } else if (strstart(p
, "cg3", &opts
)) {
1921 if (cg3_vga_available()) {
1922 vga_interface_type
= VGA_CG3
;
1924 fprintf(stderr
, "Error: CG3 framebuffer not available\n");
1927 } else if (!strstart(p
, "none", &opts
)) {
1929 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1933 const char *nextopt
;
1935 if (strstart(opts
, ",retrace=", &nextopt
)) {
1937 if (strstart(opts
, "dumb", &nextopt
))
1938 vga_retrace_method
= VGA_RETRACE_DUMB
;
1939 else if (strstart(opts
, "precise", &nextopt
))
1940 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1941 else goto invalid_vga
;
1942 } else goto invalid_vga
;
1947 static DisplayType
select_display(const char *p
)
1950 DisplayType display
= DT_DEFAULT
;
1952 if (strstart(p
, "sdl", &opts
)) {
1956 const char *nextopt
;
1958 if (strstart(opts
, ",frame=", &nextopt
)) {
1960 if (strstart(opts
, "on", &nextopt
)) {
1962 } else if (strstart(opts
, "off", &nextopt
)) {
1965 goto invalid_sdl_args
;
1967 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1969 if (strstart(opts
, "on", &nextopt
)) {
1971 } else if (strstart(opts
, "off", &nextopt
)) {
1974 goto invalid_sdl_args
;
1976 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1978 if (strstart(opts
, "on", &nextopt
)) {
1980 } else if (strstart(opts
, "off", &nextopt
)) {
1983 goto invalid_sdl_args
;
1985 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
1987 if (strstart(opts
, "on", &nextopt
)) {
1989 } else if (strstart(opts
, "off", &nextopt
)) {
1992 goto invalid_sdl_args
;
1994 } else if (strstart(opts
, ",gl=", &nextopt
)) {
1996 if (strstart(opts
, "on", &nextopt
)) {
1998 } else if (strstart(opts
, "off", &nextopt
)) {
2001 goto invalid_sdl_args
;
2005 fprintf(stderr
, "Invalid SDL option string: %s\n", p
);
2011 fprintf(stderr
, "SDL support is disabled\n");
2014 } else if (strstart(p
, "vnc", &opts
)) {
2017 if (vnc_parse_func(opts
+1) == NULL
) {
2021 fprintf(stderr
, "VNC requires a display argument vnc=<display>\n");
2025 fprintf(stderr
, "VNC support is disabled\n");
2028 } else if (strstart(p
, "curses", &opts
)) {
2029 #ifdef CONFIG_CURSES
2030 display
= DT_CURSES
;
2032 fprintf(stderr
, "Curses support is disabled\n");
2035 } else if (strstart(p
, "gtk", &opts
)) {
2039 const char *nextopt
;
2041 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2043 if (strstart(opts
, "on", &nextopt
)) {
2044 grab_on_hover
= true;
2045 } else if (strstart(opts
, "off", &nextopt
)) {
2046 grab_on_hover
= false;
2048 goto invalid_gtk_args
;
2050 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2052 if (strstart(opts
, "on", &nextopt
)) {
2054 } else if (strstart(opts
, "off", &nextopt
)) {
2057 goto invalid_gtk_args
;
2061 fprintf(stderr
, "Invalid GTK option string: %s\n", p
);
2067 fprintf(stderr
, "GTK support is disabled\n");
2070 } else if (strstart(p
, "none", &opts
)) {
2073 fprintf(stderr
, "Unknown display type: %s\n", p
);
2080 static int balloon_parse(const char *arg
)
2084 if (strcmp(arg
, "none") == 0) {
2088 if (!strncmp(arg
, "virtio", 6)) {
2089 if (arg
[6] == ',') {
2090 /* have params -> parse them */
2091 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
2095 /* create empty opts */
2096 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2099 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2106 char *qemu_find_file(int type
, const char *name
)
2112 /* Try the name as a straight path first */
2113 if (access(name
, R_OK
) == 0) {
2114 trace_load_file(name
, name
);
2115 return g_strdup(name
);
2119 case QEMU_FILE_TYPE_BIOS
:
2122 case QEMU_FILE_TYPE_KEYMAP
:
2123 subdir
= "keymaps/";
2129 for (i
= 0; i
< data_dir_idx
; i
++) {
2130 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2131 if (access(buf
, R_OK
) == 0) {
2132 trace_load_file(name
, buf
);
2140 static int device_help_func(QemuOpts
*opts
, void *opaque
)
2142 return qdev_device_help(opts
);
2145 static int device_init_func(QemuOpts
*opts
, void *opaque
)
2149 dev
= qdev_device_add(opts
);
2152 object_unref(OBJECT(dev
));
2156 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
2158 Error
*local_err
= NULL
;
2160 qemu_chr_new_from_opts(opts
, NULL
, &local_err
);
2162 error_report_err(local_err
);
2168 #ifdef CONFIG_VIRTFS
2169 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
2172 ret
= qemu_fsdev_add(opts
);
2178 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
2180 CharDriverState
*chr
;
2181 const char *chardev
;
2185 mode
= qemu_opt_get(opts
, "mode");
2189 if (strcmp(mode
, "readline") == 0) {
2190 flags
= MONITOR_USE_READLINE
;
2191 } else if (strcmp(mode
, "control") == 0) {
2192 flags
= MONITOR_USE_CONTROL
;
2194 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
2198 if (qemu_opt_get_bool(opts
, "pretty", 0))
2199 flags
|= MONITOR_USE_PRETTY
;
2201 if (qemu_opt_get_bool(opts
, "default", 0))
2202 flags
|= MONITOR_IS_DEFAULT
;
2204 chardev
= qemu_opt_get(opts
, "chardev");
2205 chr
= qemu_chr_find(chardev
);
2207 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
2211 qemu_chr_fe_claim_no_fail(chr
);
2212 monitor_init(chr
, flags
);
2216 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2218 static int monitor_device_index
= 0;
2219 Error
*local_err
= NULL
;
2225 if (strstart(optarg
, "chardev:", &p
)) {
2226 snprintf(label
, sizeof(label
), "%s", p
);
2228 snprintf(label
, sizeof(label
), "compat_monitor%d",
2229 monitor_device_index
);
2230 if (monitor_device_index
== 0) {
2233 opts
= qemu_chr_parse_compat(label
, optarg
);
2235 fprintf(stderr
, "parse error: %s\n", optarg
);
2240 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &local_err
);
2242 error_report_err(local_err
);
2245 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2246 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2247 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2249 qemu_opt_set(opts
, "default", "on", &error_abort
);
2250 monitor_device_index
++;
2253 struct device_config
{
2255 DEV_USB
, /* -usbdevice */
2257 DEV_SERIAL
, /* -serial */
2258 DEV_PARALLEL
, /* -parallel */
2259 DEV_VIRTCON
, /* -virtioconsole */
2260 DEV_DEBUGCON
, /* -debugcon */
2261 DEV_GDB
, /* -gdb, -s */
2262 DEV_SCLP
, /* s390 sclp */
2264 const char *cmdline
;
2266 QTAILQ_ENTRY(device_config
) next
;
2269 static QTAILQ_HEAD(, device_config
) device_configs
=
2270 QTAILQ_HEAD_INITIALIZER(device_configs
);
2272 static void add_device_config(int type
, const char *cmdline
)
2274 struct device_config
*conf
;
2276 conf
= g_malloc0(sizeof(*conf
));
2278 conf
->cmdline
= cmdline
;
2279 loc_save(&conf
->loc
);
2280 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2283 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2285 struct device_config
*conf
;
2288 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2289 if (conf
->type
!= type
)
2291 loc_push_restore(&conf
->loc
);
2292 rc
= func(conf
->cmdline
);
2293 loc_pop(&conf
->loc
);
2301 static int serial_parse(const char *devname
)
2303 static int index
= 0;
2306 if (strcmp(devname
, "none") == 0)
2308 if (index
== MAX_SERIAL_PORTS
) {
2309 fprintf(stderr
, "qemu: too many serial ports\n");
2312 snprintf(label
, sizeof(label
), "serial%d", index
);
2313 serial_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2314 if (!serial_hds
[index
]) {
2315 fprintf(stderr
, "qemu: could not connect serial device"
2316 " to character backend '%s'\n", devname
);
2323 static int parallel_parse(const char *devname
)
2325 static int index
= 0;
2328 if (strcmp(devname
, "none") == 0)
2330 if (index
== MAX_PARALLEL_PORTS
) {
2331 fprintf(stderr
, "qemu: too many parallel ports\n");
2334 snprintf(label
, sizeof(label
), "parallel%d", index
);
2335 parallel_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2336 if (!parallel_hds
[index
]) {
2337 fprintf(stderr
, "qemu: could not connect parallel device"
2338 " to character backend '%s'\n", devname
);
2345 static int virtcon_parse(const char *devname
)
2347 QemuOptsList
*device
= qemu_find_opts("device");
2348 static int index
= 0;
2350 QemuOpts
*bus_opts
, *dev_opts
;
2352 if (strcmp(devname
, "none") == 0)
2354 if (index
== MAX_VIRTIO_CONSOLES
) {
2355 fprintf(stderr
, "qemu: too many virtio consoles\n");
2359 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2360 if (arch_type
== QEMU_ARCH_S390X
) {
2361 qemu_opt_set(bus_opts
, "driver", "virtio-serial-s390", &error_abort
);
2363 qemu_opt_set(bus_opts
, "driver", "virtio-serial-pci", &error_abort
);
2366 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2367 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2369 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2370 virtcon_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2371 if (!virtcon_hds
[index
]) {
2372 fprintf(stderr
, "qemu: could not connect virtio console"
2373 " to character backend '%s'\n", devname
);
2376 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2382 static int sclp_parse(const char *devname
)
2384 QemuOptsList
*device
= qemu_find_opts("device");
2385 static int index
= 0;
2389 if (strcmp(devname
, "none") == 0) {
2392 if (index
== MAX_SCLP_CONSOLES
) {
2393 fprintf(stderr
, "qemu: too many sclp consoles\n");
2397 assert(arch_type
== QEMU_ARCH_S390X
);
2399 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2400 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2402 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2403 sclp_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2404 if (!sclp_hds
[index
]) {
2405 fprintf(stderr
, "qemu: could not connect sclp console"
2406 " to character backend '%s'\n", devname
);
2409 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2415 static int debugcon_parse(const char *devname
)
2419 if (!qemu_chr_new("debugcon", devname
, NULL
)) {
2422 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2424 fprintf(stderr
, "qemu: already have a debugcon device\n");
2427 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2428 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2432 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2434 const MachineClass
*mc1
= a
, *mc2
= b
;
2437 if (mc1
->family
== NULL
) {
2438 if (mc2
->family
== NULL
) {
2439 /* Compare standalone machine types against each other; they sort
2440 * in increasing order.
2442 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2443 object_class_get_name(OBJECT_CLASS(mc2
)));
2446 /* Standalone machine types sort after families. */
2450 if (mc2
->family
== NULL
) {
2451 /* Families sort before standalone machine types. */
2455 /* Families sort between each other alphabetically increasingly. */
2456 res
= strcmp(mc1
->family
, mc2
->family
);
2461 /* Within the same family, machine types sort in decreasing order. */
2462 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2463 object_class_get_name(OBJECT_CLASS(mc1
)));
2466 static MachineClass
*machine_parse(const char *name
)
2468 MachineClass
*mc
= NULL
;
2469 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2472 mc
= find_machine(name
);
2475 g_slist_free(machines
);
2478 if (name
&& !is_help_option(name
)) {
2479 error_report("Unsupported machine type");
2480 error_printf("Use -machine help to list supported machines!\n");
2482 printf("Supported machines are:\n");
2483 machines
= g_slist_sort(machines
, machine_class_cmp
);
2484 for (el
= machines
; el
; el
= el
->next
) {
2485 MachineClass
*mc
= el
->data
;
2487 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2489 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2490 mc
->is_default
? " (default)" : "");
2494 g_slist_free(machines
);
2495 exit(!name
|| !is_help_option(name
));
2498 void qemu_add_exit_notifier(Notifier
*notify
)
2500 notifier_list_add(&exit_notifiers
, notify
);
2503 void qemu_remove_exit_notifier(Notifier
*notify
)
2505 notifier_remove(notify
);
2508 static void qemu_run_exit_notifiers(void)
2510 notifier_list_notify(&exit_notifiers
, NULL
);
2513 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2515 notifier_list_add(&machine_init_done_notifiers
, notify
);
2518 static void qemu_run_machine_init_done_notifiers(void)
2520 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2523 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2524 const char **poptarg
, int *poptind
)
2526 const QEMUOption
*popt
;
2527 int optind
= *poptind
;
2528 char *r
= argv
[optind
];
2531 loc_set_cmdline(argv
, optind
, 1);
2533 /* Treat --foo the same as -foo. */
2536 popt
= qemu_options
;
2539 error_report("invalid option");
2542 if (!strcmp(popt
->name
, r
+ 1))
2546 if (popt
->flags
& HAS_ARG
) {
2547 if (optind
>= argc
) {
2548 error_report("requires an argument");
2551 optarg
= argv
[optind
++];
2552 loc_set_cmdline(argv
, optind
- 2, 2);
2563 static gpointer
malloc_and_trace(gsize n_bytes
)
2565 void *ptr
= malloc(n_bytes
);
2566 trace_g_malloc(n_bytes
, ptr
);
2570 static gpointer
realloc_and_trace(gpointer mem
, gsize n_bytes
)
2572 void *ptr
= realloc(mem
, n_bytes
);
2573 trace_g_realloc(mem
, n_bytes
, ptr
);
2577 static void free_and_trace(gpointer mem
)
2583 static int machine_set_property(const char *name
, const char *value
,
2586 Object
*obj
= OBJECT(opaque
);
2587 Error
*local_err
= NULL
;
2590 if (strcmp(name
, "type") == 0) {
2594 qom_name
= g_strdup(name
);
2602 object_property_parse(obj
, value
, qom_name
, &local_err
);
2606 error_report_err(local_err
);
2613 static int object_create(QemuOpts
*opts
, void *opaque
)
2622 ov
= opts_visitor_new(opts
);
2623 pdict
= qemu_opts_to_qdict(opts
, NULL
);
2625 visit_start_struct(opts_get_visitor(ov
), &dummy
, NULL
, NULL
, 0, &err
);
2630 qdict_del(pdict
, "qom-type");
2631 visit_type_str(opts_get_visitor(ov
), &type
, "qom-type", &err
);
2636 qdict_del(pdict
, "id");
2637 visit_type_str(opts_get_visitor(ov
), &id
, "id", &err
);
2642 object_add(type
, id
, pdict
, opts_get_visitor(ov
), &err
);
2646 visit_end_struct(opts_get_visitor(ov
), &err
);
2648 qmp_object_del(id
, NULL
);
2652 opts_visitor_cleanup(ov
);
2659 error_report_err(err
);
2665 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
)
2668 const char *mem_str
;
2669 const char *maxmem_str
, *slots_str
;
2670 const ram_addr_t default_ram_size
= (ram_addr_t
)DEFAULT_RAM_SIZE
*
2672 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2675 mem_str
= qemu_opt_get(opts
, "size");
2678 error_report("missing 'size' option value");
2682 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2684 /* Fix up legacy suffix-less format */
2685 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2686 uint64_t overflow_check
= sz
;
2689 if ((sz
>> 20) != overflow_check
) {
2690 error_report("too large 'size' option value");
2696 /* backward compatibility behaviour for case "-m 0" */
2698 sz
= default_ram_size
;
2701 sz
= QEMU_ALIGN_UP(sz
, 8192);
2703 if (ram_size
!= sz
) {
2704 error_report("ram size too large");
2708 /* store value for the future use */
2709 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2710 *maxram_size
= ram_size
;
2712 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2713 slots_str
= qemu_opt_get(opts
, "slots");
2714 if (maxmem_str
&& slots_str
) {
2717 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2718 slots
= qemu_opt_get_number(opts
, "slots", 0);
2719 if (sz
< ram_size
) {
2720 error_report("invalid value of -m option maxmem: "
2721 "maximum memory size (0x%" PRIx64
") must be at least "
2722 "the initial memory size (0x" RAM_ADDR_FMT
")",
2725 } else if (sz
> ram_size
) {
2727 error_report("invalid value of -m option: maxmem was "
2728 "specified, but no hotplug slots were specified");
2732 error_report("invalid value of -m option maxmem: "
2733 "memory slots were specified but maximum memory size "
2734 "(0x%" PRIx64
") is equal to the initial memory size "
2735 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2741 } else if ((!maxmem_str
&& slots_str
) ||
2742 (maxmem_str
&& !slots_str
)) {
2743 error_report("invalid -m option value: missing "
2744 "'%s' option", slots_str
? "maxmem" : "slots");
2749 int main(int argc
, char **argv
, char **envp
)
2752 int snapshot
, linux_boot
;
2753 const char *initrd_filename
;
2754 const char *kernel_filename
, *kernel_cmdline
;
2755 const char *boot_order
= NULL
;
2756 const char *boot_once
= NULL
;
2758 int cyls
, heads
, secs
, translation
;
2759 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
2760 QemuOptsList
*olist
;
2763 const char *loadvm
= NULL
;
2764 MachineClass
*machine_class
;
2765 const char *cpu_model
;
2766 const char *vga_model
= NULL
;
2767 const char *qtest_chrdev
= NULL
;
2768 const char *qtest_log
= NULL
;
2769 const char *pid_file
= NULL
;
2770 const char *incoming
= NULL
;
2772 int show_vnc_port
= 0;
2774 bool defconfig
= true;
2775 bool userconfig
= true;
2776 const char *log_mask
= NULL
;
2777 const char *log_file
= NULL
;
2778 GMemVTable mem_trace
= {
2779 .malloc
= malloc_and_trace
,
2780 .realloc
= realloc_and_trace
,
2781 .free
= free_and_trace
,
2783 const char *trace_events
= NULL
;
2784 const char *trace_file
= NULL
;
2785 ram_addr_t maxram_size
;
2786 uint64_t ram_slots
= 0;
2787 FILE *vmstate_dump_file
= NULL
;
2788 Error
*main_loop_err
= NULL
;
2790 qemu_init_cpu_loop();
2791 qemu_mutex_lock_iothread();
2793 atexit(qemu_run_exit_notifiers
);
2794 error_set_progname(argv
[0]);
2795 qemu_init_exec_dir(argv
[0]);
2797 g_mem_set_vtable(&mem_trace
);
2799 module_call_init(MODULE_INIT_QOM
);
2801 qemu_add_opts(&qemu_drive_opts
);
2802 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2803 qemu_add_drive_opts(&qemu_common_drive_opts
);
2804 qemu_add_drive_opts(&qemu_drive_opts
);
2805 qemu_add_opts(&qemu_chardev_opts
);
2806 qemu_add_opts(&qemu_device_opts
);
2807 qemu_add_opts(&qemu_netdev_opts
);
2808 qemu_add_opts(&qemu_net_opts
);
2809 qemu_add_opts(&qemu_rtc_opts
);
2810 qemu_add_opts(&qemu_global_opts
);
2811 qemu_add_opts(&qemu_mon_opts
);
2812 qemu_add_opts(&qemu_trace_opts
);
2813 qemu_add_opts(&qemu_option_rom_opts
);
2814 qemu_add_opts(&qemu_machine_opts
);
2815 qemu_add_opts(&qemu_mem_opts
);
2816 qemu_add_opts(&qemu_smp_opts
);
2817 qemu_add_opts(&qemu_boot_opts
);
2818 qemu_add_opts(&qemu_sandbox_opts
);
2819 qemu_add_opts(&qemu_add_fd_opts
);
2820 qemu_add_opts(&qemu_object_opts
);
2821 qemu_add_opts(&qemu_tpmdev_opts
);
2822 qemu_add_opts(&qemu_realtime_opts
);
2823 qemu_add_opts(&qemu_msg_opts
);
2824 qemu_add_opts(&qemu_name_opts
);
2825 qemu_add_opts(&qemu_numa_opts
);
2826 qemu_add_opts(&qemu_icount_opts
);
2827 qemu_add_opts(&qemu_semihosting_config_opts
);
2831 rtc_clock
= QEMU_CLOCK_HOST
;
2833 QLIST_INIT (&vm_change_state_head
);
2834 os_setup_early_signal_handling();
2836 module_call_init(MODULE_INIT_MACHINE
);
2837 machine_class
= find_default_machine();
2840 cyls
= heads
= secs
= 0;
2841 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2845 bdrv_init_with_whitelist();
2849 /* first pass of option parsing */
2851 while (optind
< argc
) {
2852 if (argv
[optind
][0] != '-') {
2856 const QEMUOption
*popt
;
2858 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2859 switch (popt
->index
) {
2860 case QEMU_OPTION_nodefconfig
:
2863 case QEMU_OPTION_nouserconfig
:
2872 ret
= qemu_read_default_config_files(userconfig
);
2878 /* second pass of option parsing */
2883 if (argv
[optind
][0] != '-') {
2884 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2886 const QEMUOption
*popt
;
2888 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2889 if (!(popt
->arch_mask
& arch_type
)) {
2890 printf("Option %s not supported for this target\n", popt
->name
);
2893 switch(popt
->index
) {
2894 case QEMU_OPTION_no_kvm_irqchip
: {
2895 olist
= qemu_find_opts("machine");
2896 qemu_opts_parse(olist
, "kernel_irqchip=off", 0);
2899 case QEMU_OPTION_cpu
:
2900 /* hw initialization will check this */
2903 case QEMU_OPTION_hda
:
2907 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
2909 snprintf(buf
, sizeof(buf
),
2910 "%s,cyls=%d,heads=%d,secs=%d%s",
2911 HD_OPTS
, cyls
, heads
, secs
,
2912 translation
== BIOS_ATA_TRANSLATION_LBA
?
2914 translation
== BIOS_ATA_TRANSLATION_NONE
?
2915 ",trans=none" : "");
2916 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
2919 case QEMU_OPTION_hdb
:
2920 case QEMU_OPTION_hdc
:
2921 case QEMU_OPTION_hdd
:
2922 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2925 case QEMU_OPTION_drive
:
2926 if (drive_def(optarg
) == NULL
) {
2930 case QEMU_OPTION_set
:
2931 if (qemu_set_option(optarg
) != 0)
2934 case QEMU_OPTION_global
:
2935 if (qemu_global_option(optarg
) != 0)
2938 case QEMU_OPTION_mtdblock
:
2939 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2941 case QEMU_OPTION_sd
:
2942 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2944 case QEMU_OPTION_pflash
:
2945 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2947 case QEMU_OPTION_snapshot
:
2950 case QEMU_OPTION_hdachs
:
2954 cyls
= strtol(p
, (char **)&p
, 0);
2955 if (cyls
< 1 || cyls
> 16383)
2960 heads
= strtol(p
, (char **)&p
, 0);
2961 if (heads
< 1 || heads
> 16)
2966 secs
= strtol(p
, (char **)&p
, 0);
2967 if (secs
< 1 || secs
> 63)
2971 if (!strcmp(p
, "large")) {
2972 translation
= BIOS_ATA_TRANSLATION_LARGE
;
2973 } else if (!strcmp(p
, "rechs")) {
2974 translation
= BIOS_ATA_TRANSLATION_RECHS
;
2975 } else if (!strcmp(p
, "none")) {
2976 translation
= BIOS_ATA_TRANSLATION_NONE
;
2977 } else if (!strcmp(p
, "lba")) {
2978 translation
= BIOS_ATA_TRANSLATION_LBA
;
2979 } else if (!strcmp(p
, "auto")) {
2980 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2984 } else if (*p
!= '\0') {
2986 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2989 if (hda_opts
!= NULL
) {
2990 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
2992 qemu_opt_set_number(hda_opts
, "heads", heads
,
2994 qemu_opt_set_number(hda_opts
, "secs", secs
,
2996 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
2997 qemu_opt_set(hda_opts
, "trans", "large",
2999 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3000 qemu_opt_set(hda_opts
, "trans", "rechs",
3002 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3003 qemu_opt_set(hda_opts
, "trans", "lba",
3005 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3006 qemu_opt_set(hda_opts
, "trans", "none",
3012 case QEMU_OPTION_numa
:
3013 opts
= qemu_opts_parse(qemu_find_opts("numa"), optarg
, 1);
3018 case QEMU_OPTION_display
:
3019 display_type
= select_display(optarg
);
3021 case QEMU_OPTION_nographic
:
3022 display_type
= DT_NOGRAPHIC
;
3024 case QEMU_OPTION_curses
:
3025 #ifdef CONFIG_CURSES
3026 display_type
= DT_CURSES
;
3028 fprintf(stderr
, "Curses support is disabled\n");
3032 case QEMU_OPTION_portrait
:
3033 graphic_rotate
= 90;
3035 case QEMU_OPTION_rotate
:
3036 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3037 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3038 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3040 "qemu: only 90, 180, 270 deg rotation is available\n");
3044 case QEMU_OPTION_kernel
:
3045 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3048 case QEMU_OPTION_initrd
:
3049 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3052 case QEMU_OPTION_append
:
3053 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3056 case QEMU_OPTION_dtb
:
3057 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3060 case QEMU_OPTION_cdrom
:
3061 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3063 case QEMU_OPTION_boot
:
3064 opts
= qemu_opts_parse(qemu_find_opts("boot-opts"), optarg
, 1);
3069 case QEMU_OPTION_fda
:
3070 case QEMU_OPTION_fdb
:
3071 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3074 case QEMU_OPTION_no_fd_bootchk
:
3077 case QEMU_OPTION_netdev
:
3078 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3082 case QEMU_OPTION_net
:
3083 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3087 #ifdef CONFIG_LIBISCSI
3088 case QEMU_OPTION_iscsi
:
3089 opts
= qemu_opts_parse(qemu_find_opts("iscsi"), optarg
, 0);
3096 case QEMU_OPTION_tftp
:
3097 legacy_tftp_prefix
= optarg
;
3099 case QEMU_OPTION_bootp
:
3100 legacy_bootp_filename
= optarg
;
3102 case QEMU_OPTION_redir
:
3103 if (net_slirp_redir(optarg
) < 0)
3107 case QEMU_OPTION_bt
:
3108 add_device_config(DEV_BT
, optarg
);
3110 case QEMU_OPTION_audio_help
:
3114 case QEMU_OPTION_soundhw
:
3115 select_soundhw (optarg
);
3120 case QEMU_OPTION_version
:
3125 opts
= qemu_opts_parse(qemu_find_opts("memory"),
3132 case QEMU_OPTION_tpmdev
:
3133 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3138 case QEMU_OPTION_mempath
:
3141 case QEMU_OPTION_mem_prealloc
:
3151 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3153 case QEMU_OPTION_gdb
:
3154 add_device_config(DEV_GDB
, optarg
);
3157 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3158 data_dir
[data_dir_idx
++] = optarg
;
3161 case QEMU_OPTION_bios
:
3162 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3165 case QEMU_OPTION_singlestep
:
3172 keyboard_layout
= optarg
;
3174 case QEMU_OPTION_localtime
:
3177 case QEMU_OPTION_vga
:
3186 w
= strtol(p
, (char **)&p
, 10);
3189 fprintf(stderr
, "qemu: invalid resolution or depth\n");
3195 h
= strtol(p
, (char **)&p
, 10);
3200 depth
= strtol(p
, (char **)&p
, 10);
3201 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3202 depth
!= 24 && depth
!= 32)
3204 } else if (*p
== '\0') {
3205 depth
= graphic_depth
;
3212 graphic_depth
= depth
;
3215 case QEMU_OPTION_echr
:
3218 term_escape_char
= strtol(optarg
, &r
, 0);
3220 printf("Bad argument to echr\n");
3223 case QEMU_OPTION_monitor
:
3224 default_monitor
= 0;
3225 if (strncmp(optarg
, "none", 4)) {
3226 monitor_parse(optarg
, "readline", false);
3229 case QEMU_OPTION_qmp
:
3230 monitor_parse(optarg
, "control", false);
3231 default_monitor
= 0;
3233 case QEMU_OPTION_qmp_pretty
:
3234 monitor_parse(optarg
, "control", true);
3235 default_monitor
= 0;
3237 case QEMU_OPTION_mon
:
3238 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
3242 default_monitor
= 0;
3244 case QEMU_OPTION_chardev
:
3245 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
3250 case QEMU_OPTION_fsdev
:
3251 olist
= qemu_find_opts("fsdev");
3253 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
3256 opts
= qemu_opts_parse(olist
, optarg
, 1);
3261 case QEMU_OPTION_virtfs
: {
3264 const char *writeout
, *sock_fd
, *socket
;
3266 olist
= qemu_find_opts("virtfs");
3268 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
3271 opts
= qemu_opts_parse(olist
, optarg
, 1);
3276 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3277 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3278 fprintf(stderr
, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
3281 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3282 qemu_opt_get(opts
, "mount_tag"),
3285 fprintf(stderr
, "duplicate fsdev id: %s\n",
3286 qemu_opt_get(opts
, "mount_tag"));
3290 writeout
= qemu_opt_get(opts
, "writeout");
3292 #ifdef CONFIG_SYNC_FILE_RANGE
3293 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3295 fprintf(stderr
, "writeout=immediate not supported on "
3300 qemu_opt_set(fsdev
, "fsdriver",
3301 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3302 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3304 qemu_opt_set(fsdev
, "security_model",
3305 qemu_opt_get(opts
, "security_model"),
3307 socket
= qemu_opt_get(opts
, "socket");
3309 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3311 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3313 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3316 qemu_opt_set_bool(fsdev
, "readonly",
3317 qemu_opt_get_bool(opts
, "readonly", 0),
3319 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3321 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3322 qemu_opt_set(device
, "fsdev",
3323 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3324 qemu_opt_set(device
, "mount_tag",
3325 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3328 case QEMU_OPTION_virtfs_synth
: {
3332 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3335 fprintf(stderr
, "duplicate option: %s\n", "virtfs_synth");
3338 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3340 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3342 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3343 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3344 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3347 case QEMU_OPTION_serial
:
3348 add_device_config(DEV_SERIAL
, optarg
);
3350 if (strncmp(optarg
, "mon:", 4) == 0) {
3351 default_monitor
= 0;
3354 case QEMU_OPTION_watchdog
:
3357 "qemu: only one watchdog option may be given\n");
3362 case QEMU_OPTION_watchdog_action
:
3363 if (select_watchdog_action(optarg
) == -1) {
3364 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
3368 case QEMU_OPTION_virtiocon
:
3369 add_device_config(DEV_VIRTCON
, optarg
);
3370 default_virtcon
= 0;
3371 if (strncmp(optarg
, "mon:", 4) == 0) {
3372 default_monitor
= 0;
3375 case QEMU_OPTION_parallel
:
3376 add_device_config(DEV_PARALLEL
, optarg
);
3377 default_parallel
= 0;
3378 if (strncmp(optarg
, "mon:", 4) == 0) {
3379 default_monitor
= 0;
3382 case QEMU_OPTION_debugcon
:
3383 add_device_config(DEV_DEBUGCON
, optarg
);
3385 case QEMU_OPTION_loadvm
:
3388 case QEMU_OPTION_full_screen
:
3391 case QEMU_OPTION_no_frame
:
3394 case QEMU_OPTION_alt_grab
:
3397 case QEMU_OPTION_ctrl_grab
:
3400 case QEMU_OPTION_no_quit
:
3403 case QEMU_OPTION_sdl
:
3405 display_type
= DT_SDL
;
3408 fprintf(stderr
, "SDL support is disabled\n");
3411 case QEMU_OPTION_pidfile
:
3414 case QEMU_OPTION_win2k_hack
:
3415 win2k_install_hack
= 1;
3417 case QEMU_OPTION_rtc_td_hack
: {
3418 static GlobalProperty slew_lost_ticks
[] = {
3420 .driver
= "mc146818rtc",
3421 .property
= "lost_tick_policy",
3424 { /* end of list */ }
3427 qdev_prop_register_global_list(slew_lost_ticks
);
3430 case QEMU_OPTION_acpitable
:
3431 opts
= qemu_opts_parse(qemu_find_opts("acpi"), optarg
, 1);
3435 do_acpitable_option(opts
);
3437 case QEMU_OPTION_smbios
:
3438 opts
= qemu_opts_parse(qemu_find_opts("smbios"), optarg
, 0);
3442 do_smbios_option(opts
);
3444 case QEMU_OPTION_enable_kvm
:
3445 olist
= qemu_find_opts("machine");
3446 qemu_opts_parse(olist
, "accel=kvm", 0);
3449 case QEMU_OPTION_machine
:
3450 olist
= qemu_find_opts("machine");
3451 opts
= qemu_opts_parse(olist
, optarg
, 1);
3456 case QEMU_OPTION_no_kvm
:
3457 olist
= qemu_find_opts("machine");
3458 qemu_opts_parse(olist
, "accel=tcg", 0);
3460 case QEMU_OPTION_no_kvm_pit
: {
3461 fprintf(stderr
, "Warning: KVM PIT can no longer be disabled "
3465 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3466 static GlobalProperty kvm_pit_lost_tick_policy
[] = {
3468 .driver
= "kvm-pit",
3469 .property
= "lost_tick_policy",
3472 { /* end of list */ }
3475 fprintf(stderr
, "Warning: option deprecated, use "
3476 "lost_tick_policy property of kvm-pit instead.\n");
3477 qdev_prop_register_global_list(kvm_pit_lost_tick_policy
);
3480 case QEMU_OPTION_usb
:
3481 olist
= qemu_find_opts("machine");
3482 qemu_opts_parse(olist
, "usb=on", 0);
3484 case QEMU_OPTION_usbdevice
:
3485 olist
= qemu_find_opts("machine");
3486 qemu_opts_parse(olist
, "usb=on", 0);
3487 add_device_config(DEV_USB
, optarg
);
3489 case QEMU_OPTION_device
:
3490 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
3494 case QEMU_OPTION_smp
:
3495 if (!qemu_opts_parse(qemu_find_opts("smp-opts"), optarg
, 1)) {
3499 case QEMU_OPTION_vnc
:
3501 if (vnc_parse_func(optarg
) == NULL
) {
3505 fprintf(stderr
, "VNC support is disabled\n");
3509 case QEMU_OPTION_no_acpi
:
3512 case QEMU_OPTION_no_hpet
:
3515 case QEMU_OPTION_balloon
:
3516 if (balloon_parse(optarg
) < 0) {
3517 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
3521 case QEMU_OPTION_no_reboot
:
3524 case QEMU_OPTION_no_shutdown
:
3527 case QEMU_OPTION_show_cursor
:
3530 case QEMU_OPTION_uuid
:
3531 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
3532 fprintf(stderr
, "Fail to parse UUID string."
3533 " Wrong format.\n");
3536 qemu_uuid_set
= true;
3538 case QEMU_OPTION_option_rom
:
3539 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3540 fprintf(stderr
, "Too many option ROMs\n");
3543 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
3547 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3548 option_rom
[nb_option_roms
].bootindex
=
3549 qemu_opt_get_number(opts
, "bootindex", -1);
3550 if (!option_rom
[nb_option_roms
].name
) {
3551 fprintf(stderr
, "Option ROM file is not specified\n");
3556 case QEMU_OPTION_semihosting
:
3557 semihosting_enabled
= 1;
3558 semihosting_target
= SEMIHOSTING_TARGET_AUTO
;
3560 case QEMU_OPTION_semihosting_config
:
3561 semihosting_enabled
= 1;
3562 opts
= qemu_opts_parse(qemu_find_opts("semihosting-config"),
3565 semihosting_enabled
= qemu_opt_get_bool(opts
, "enable",
3567 const char *target
= qemu_opt_get(opts
, "target");
3568 if (target
!= NULL
) {
3569 if (strcmp("native", target
) == 0) {
3570 semihosting_target
= SEMIHOSTING_TARGET_NATIVE
;
3571 } else if (strcmp("gdb", target
) == 0) {
3572 semihosting_target
= SEMIHOSTING_TARGET_GDB
;
3573 } else if (strcmp("auto", target
) == 0) {
3574 semihosting_target
= SEMIHOSTING_TARGET_AUTO
;
3576 fprintf(stderr
, "Unsupported semihosting-config"
3582 semihosting_target
= SEMIHOSTING_TARGET_AUTO
;
3585 fprintf(stderr
, "Unsupported semihosting-config %s\n",
3590 case QEMU_OPTION_tdf
:
3591 fprintf(stderr
, "Warning: user space PIT time drift fix "
3592 "is no longer supported.\n");
3594 case QEMU_OPTION_name
:
3595 opts
= qemu_opts_parse(qemu_find_opts("name"), optarg
, 1);
3600 case QEMU_OPTION_prom_env
:
3601 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3602 fprintf(stderr
, "Too many prom variables\n");
3605 prom_envs
[nb_prom_envs
] = optarg
;
3608 case QEMU_OPTION_old_param
:
3611 case QEMU_OPTION_clock
:
3612 /* Clock options no longer exist. Keep this option for
3613 * backward compatibility.
3616 case QEMU_OPTION_startdate
:
3617 configure_rtc_date_offset(optarg
, 1);
3619 case QEMU_OPTION_rtc
:
3620 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
3624 configure_rtc(opts
);
3626 case QEMU_OPTION_tb_size
:
3627 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3628 if (tcg_tb_size
< 0) {
3632 case QEMU_OPTION_icount
:
3633 icount_opts
= qemu_opts_parse(qemu_find_opts("icount"),
3639 case QEMU_OPTION_incoming
:
3641 runstate_set(RUN_STATE_INMIGRATE
);
3645 case QEMU_OPTION_nodefaults
:
3648 case QEMU_OPTION_xen_domid
:
3649 if (!(xen_available())) {
3650 printf("Option %s not supported for this target\n", popt
->name
);
3653 xen_domid
= atoi(optarg
);
3655 case QEMU_OPTION_xen_create
:
3656 if (!(xen_available())) {
3657 printf("Option %s not supported for this target\n", popt
->name
);
3660 xen_mode
= XEN_CREATE
;
3662 case QEMU_OPTION_xen_attach
:
3663 if (!(xen_available())) {
3664 printf("Option %s not supported for this target\n", popt
->name
);
3667 xen_mode
= XEN_ATTACH
;
3669 case QEMU_OPTION_trace
:
3671 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
3675 trace_events
= qemu_opt_get(opts
, "events");
3676 trace_file
= qemu_opt_get(opts
, "file");
3679 case QEMU_OPTION_readconfig
:
3681 int ret
= qemu_read_config_file(optarg
);
3683 fprintf(stderr
, "read config %s: %s\n", optarg
,
3689 case QEMU_OPTION_spice
:
3690 olist
= qemu_find_opts("spice");
3692 fprintf(stderr
, "spice is not supported by this qemu build.\n");
3695 opts
= qemu_opts_parse(olist
, optarg
, 0);
3701 case QEMU_OPTION_writeconfig
:
3704 if (strcmp(optarg
, "-") == 0) {
3707 fp
= fopen(optarg
, "w");
3709 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
3713 qemu_config_write(fp
);
3719 case QEMU_OPTION_qtest
:
3720 qtest_chrdev
= optarg
;
3722 case QEMU_OPTION_qtest_log
:
3725 case QEMU_OPTION_sandbox
:
3726 opts
= qemu_opts_parse(qemu_find_opts("sandbox"), optarg
, 1);
3731 case QEMU_OPTION_add_fd
:
3733 opts
= qemu_opts_parse(qemu_find_opts("add-fd"), optarg
, 0);
3738 error_report("File descriptor passing is disabled on this "
3743 case QEMU_OPTION_object
:
3744 opts
= qemu_opts_parse(qemu_find_opts("object"), optarg
, 1);
3749 case QEMU_OPTION_realtime
:
3750 opts
= qemu_opts_parse(qemu_find_opts("realtime"), optarg
, 0);
3754 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
3756 case QEMU_OPTION_msg
:
3757 opts
= qemu_opts_parse(qemu_find_opts("msg"), optarg
, 0);
3761 configure_msg(opts
);
3763 case QEMU_OPTION_dump_vmstate
:
3764 if (vmstate_dump_file
) {
3765 fprintf(stderr
, "qemu: only one '-dump-vmstate' "
3766 "option may be given\n");
3769 vmstate_dump_file
= fopen(optarg
, "w");
3770 if (vmstate_dump_file
== NULL
) {
3771 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
3776 os_parse_cmd_args(popt
->index
, optarg
);
3781 opts
= qemu_get_machine_opts();
3782 optarg
= qemu_opt_get(opts
, "type");
3784 machine_class
= machine_parse(optarg
);
3787 set_memory_options(&ram_slots
, &maxram_size
);
3793 if (qemu_init_main_loop(&main_loop_err
)) {
3794 error_report_err(main_loop_err
);
3798 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox
, NULL
, 0)) {
3802 if (qemu_opts_foreach(qemu_find_opts("name"), parse_name
, NULL
, 1)) {
3807 if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd
, NULL
, 1)) {
3811 if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd
, NULL
, 1)) {
3816 if (machine_class
== NULL
) {
3817 fprintf(stderr
, "No machine specified, and there is no default.\n"
3818 "Use -machine help to list supported machines!\n");
3822 current_machine
= MACHINE(object_new(object_class_get_name(
3823 OBJECT_CLASS(machine_class
))));
3824 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
3827 object_property_add_child(object_get_root(), "machine",
3828 OBJECT(current_machine
), &error_abort
);
3829 cpu_exec_init_all();
3831 if (machine_class
->hw_version
) {
3832 qemu_set_version(machine_class
->hw_version
);
3835 /* Init CPU def lists, based on config
3836 * - Must be called after all the qemu_read_config_file() calls
3837 * - Must be called before list_cpus()
3838 * - Must be called before machine->init()
3842 if (cpu_model
&& is_help_option(cpu_model
)) {
3843 list_cpus(stdout
, &fprintf
, cpu_model
);
3847 /* Open the logfile at this point, if necessary. We can't open the logfile
3848 * when encountering either of the logging options (-d or -D) because the
3849 * other one may be encountered later on the command line, changing the
3850 * location or level of logging.
3855 qemu_set_log_filename(log_file
);
3858 mask
= qemu_str_to_log_mask(log_mask
);
3860 qemu_print_log_usage(stdout
);
3866 if (!is_daemonized()) {
3867 if (!trace_init_backends(trace_events
, trace_file
)) {
3872 /* If no data_dir is specified then try to find it relative to the
3874 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3875 data_dir
[data_dir_idx
] = os_find_datadir();
3876 if (data_dir
[data_dir_idx
] != NULL
) {
3880 /* If all else fails use the install path specified when building. */
3881 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3882 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
3885 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
3887 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
3888 if (max_cpus
> machine_class
->max_cpus
) {
3889 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
3890 "supported by machine `%s' (%d)\n", max_cpus
,
3891 machine_class
->name
, machine_class
->max_cpus
);
3896 * Get the default machine options from the machine if it is not already
3897 * specified either by the configuration file or by the command line.
3899 if (machine_class
->default_machine_opts
) {
3900 qemu_opts_set_defaults(qemu_find_opts("machine"),
3901 machine_class
->default_machine_opts
, 0);
3904 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
3905 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
3907 if (!vga_model
&& !default_vga
) {
3908 vga_interface_type
= VGA_DEVICE
;
3910 if (!has_defaults
|| machine_class
->no_serial
) {
3913 if (!has_defaults
|| machine_class
->no_parallel
) {
3914 default_parallel
= 0;
3916 if (!has_defaults
|| !machine_class
->use_virtcon
) {
3917 default_virtcon
= 0;
3919 if (!has_defaults
|| !machine_class
->use_sclp
) {
3922 if (!has_defaults
|| machine_class
->no_floppy
) {
3925 if (!has_defaults
|| machine_class
->no_cdrom
) {
3928 if (!has_defaults
|| machine_class
->no_sdcard
) {
3931 if (!has_defaults
) {
3932 default_monitor
= 0;
3937 if (is_daemonized()) {
3938 /* According to documentation and historically, -nographic redirects
3939 * serial port, parallel port and monitor to stdio, which does not work
3940 * with -daemonize. We can redirect these to null instead, but since
3941 * -nographic is legacy, let's just error out.
3942 * We disallow -nographic only if all other ports are not redirected
3943 * explicitly, to not break existing legacy setups which uses
3944 * -nographic _and_ redirects all ports explicitly - this is valid
3945 * usage, -nographic is just a no-op in this case.
3947 if (display_type
== DT_NOGRAPHIC
3948 && (default_parallel
|| default_serial
3949 || default_monitor
|| default_virtcon
)) {
3950 fprintf(stderr
, "-nographic can not be used with -daemonize\n");
3953 #ifdef CONFIG_CURSES
3954 if (display_type
== DT_CURSES
) {
3955 fprintf(stderr
, "curses display can not be used with -daemonize\n");
3961 if (display_type
== DT_NOGRAPHIC
) {
3962 if (default_parallel
)
3963 add_device_config(DEV_PARALLEL
, "null");
3964 if (default_serial
&& default_monitor
) {
3965 add_device_config(DEV_SERIAL
, "mon:stdio");
3966 } else if (default_virtcon
&& default_monitor
) {
3967 add_device_config(DEV_VIRTCON
, "mon:stdio");
3968 } else if (default_sclp
&& default_monitor
) {
3969 add_device_config(DEV_SCLP
, "mon:stdio");
3972 add_device_config(DEV_SERIAL
, "stdio");
3973 if (default_virtcon
)
3974 add_device_config(DEV_VIRTCON
, "stdio");
3976 add_device_config(DEV_SCLP
, "stdio");
3978 if (default_monitor
)
3979 monitor_parse("stdio", "readline", false);
3983 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
3984 if (default_parallel
)
3985 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
3986 if (default_monitor
)
3987 monitor_parse("vc:80Cx24C", "readline", false);
3988 if (default_virtcon
)
3989 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
3991 add_device_config(DEV_SCLP
, "vc:80Cx24C");
3995 #if defined(CONFIG_VNC)
3996 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4000 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4001 #if defined(CONFIG_GTK)
4002 display_type
= DT_GTK
;
4003 #elif defined(CONFIG_SDL) || defined(CONFIG_COCOA)
4004 display_type
= DT_SDL
;
4005 #elif defined(CONFIG_VNC)
4006 vnc_parse_func("localhost:0,to=99,id=default");
4009 display_type
= DT_NONE
;
4013 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4014 fprintf(stderr
, "-no-frame, -alt-grab and -ctrl-grab are only valid "
4015 "for SDL, ignoring option\n");
4017 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4018 fprintf(stderr
, "-no-quit is only valid for GTK and SDL, "
4019 "ignoring option\n");
4022 #if defined(CONFIG_GTK)
4023 if (display_type
== DT_GTK
) {
4024 early_gtk_display_init(request_opengl
);
4027 #if defined(CONFIG_SDL)
4028 if (display_type
== DT_SDL
) {
4029 sdl_display_early_init(request_opengl
);
4032 if (request_opengl
== 1 && display_opengl
== 0) {
4033 #if defined(CONFIG_OPENGL)
4034 fprintf(stderr
, "OpenGL is not supported by the display.\n");
4036 fprintf(stderr
, "QEMU was built without opengl support.\n");
4043 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
4045 #ifdef CONFIG_VIRTFS
4046 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
4051 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4052 fprintf(stderr
, "Could not acquire pid file: %s\n", strerror(errno
));
4056 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0)
4061 if (qemu_opts_foreach(qemu_find_opts("object"),
4062 object_create
, NULL
, 0) != 0) {
4066 machine_opts
= qemu_get_machine_opts();
4067 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4069 object_unref(OBJECT(current_machine
));
4073 configure_accelerator(current_machine
);
4076 Error
*local_err
= NULL
;
4077 qtest_init(qtest_chrdev
, qtest_log
, &local_err
);
4079 error_report_err(local_err
);
4084 machine_opts
= qemu_get_machine_opts();
4085 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4086 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4087 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4088 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4090 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4092 Error
*local_err
= NULL
;
4094 boot_order
= qemu_opt_get(opts
, "order");
4096 validate_bootdevices(boot_order
, &local_err
);
4098 error_report_err(local_err
);
4103 boot_once
= qemu_opt_get(opts
, "once");
4105 validate_bootdevices(boot_once
, &local_err
);
4107 error_report_err(local_err
);
4112 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4113 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4117 boot_order
= machine_class
->default_boot_order
;
4120 if (!kernel_cmdline
) {
4121 kernel_cmdline
= "";
4122 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4125 linux_boot
= (kernel_filename
!= NULL
);
4127 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4128 fprintf(stderr
, "-append only allowed with -kernel option\n");
4132 if (!linux_boot
&& initrd_filename
!= NULL
) {
4133 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
4137 if (!linux_boot
&& qemu_opt_get(machine_opts
, "dtb")) {
4138 fprintf(stderr
, "-dtb only allowed with -kernel option\n");
4142 os_set_line_buffering();
4145 /* spice needs the timers to be initialized by this point */
4151 if (kvm_enabled() || xen_enabled()) {
4152 fprintf(stderr
, "-icount is not allowed with kvm or xen\n");
4155 configure_icount(icount_opts
, &error_abort
);
4156 qemu_opts_del(icount_opts
);
4159 /* clean up network at qemu process termination */
4160 atexit(&net_cleanup
);
4162 if (net_init_clients() < 0) {
4167 if (tpm_init() < 0) {
4172 /* init the bluetooth world */
4173 if (foreach_device_config(DEV_BT
, bt_parse
))
4176 if (!xen_enabled()) {
4177 /* On 32-bit hosts, QEMU is limited by virtual address space */
4178 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4179 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
4187 /* If the currently selected machine wishes to override the units-per-bus
4188 * property of its default HBA interface type, do so now. */
4189 if (machine_class
->units_per_default_bus
) {
4190 override_max_devs(machine_class
->block_default_type
,
4191 machine_class
->units_per_default_bus
);
4194 /* open the virtual block devices */
4196 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
4197 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4198 &machine_class
->block_default_type
, 1) != 0) {
4202 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4204 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4205 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4207 parse_numa_opts(machine_class
);
4209 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
4213 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4215 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4217 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4219 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4222 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4225 /* If no default VGA is requested, the default is "none". */
4227 if (machine_class
->default_display
) {
4228 vga_model
= machine_class
->default_display
;
4229 } else if (cirrus_vga_available()) {
4230 vga_model
= "cirrus";
4231 } else if (vga_available()) {
4236 select_vgahw(vga_model
);
4240 i
= select_watchdog(watchdog
);
4242 exit (i
== 1 ? 1 : 0);
4245 if (machine_class
->compat_props
) {
4246 qdev_prop_register_global_list(machine_class
->compat_props
);
4250 qdev_machine_init();
4252 current_machine
->ram_size
= ram_size
;
4253 current_machine
->maxram_size
= maxram_size
;
4254 current_machine
->ram_slots
= ram_slots
;
4255 current_machine
->boot_order
= boot_order
;
4256 current_machine
->cpu_model
= cpu_model
;
4258 machine_class
->init(current_machine
);
4264 cpu_synchronize_all_post_init();
4266 numa_post_machine_init();
4268 /* init USB devices */
4269 if (usb_enabled()) {
4270 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4274 /* init generic devices */
4275 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
4278 /* Did we create any drives that we failed to create a device for? */
4279 drive_check_orphaned();
4281 net_check_clients();
4284 Error
*local_err
= NULL
;
4285 qemu_boot_set(boot_once
, &local_err
);
4287 error_report("%s", error_get_pretty(local_err
));
4290 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4293 ds
= init_displaystate();
4295 /* init local displays */
4296 switch (display_type
) {
4298 (void)ds
; /* avoid warning if no display is configured */
4300 #if defined(CONFIG_CURSES)
4302 curses_display_init(ds
, full_screen
);
4305 #if defined(CONFIG_SDL)
4307 sdl_display_init(ds
, full_screen
, no_frame
);
4309 #elif defined(CONFIG_COCOA)
4311 cocoa_display_init(ds
, full_screen
);
4314 #if defined(CONFIG_GTK)
4316 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4323 /* must be after terminal init, SDL library changes signal handlers */
4324 os_setup_signal_handling();
4327 /* init remote displays */
4328 qemu_opts_foreach(qemu_find_opts("vnc"), vnc_init_func
, NULL
, 0);
4329 if (show_vnc_port
) {
4330 printf("VNC server running on `%s'\n",
4331 vnc_display_local_addr("default"));
4336 qemu_spice_display_init();
4340 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4344 qdev_machine_creation_done();
4346 if (rom_load_all() != 0) {
4347 fprintf(stderr
, "rom loading failed\n");
4351 /* TODO: once all bus devices are qdevified, this should be done
4352 * when bus is created by qdev.c */
4353 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4354 qemu_run_machine_init_done_notifiers();
4356 /* Done notifiers can load ROMs */
4359 qemu_system_reset(VMRESET_SILENT
);
4361 if (load_vmstate(loadvm
) < 0) {
4366 qdev_prop_check_globals();
4367 if (vmstate_dump_file
) {
4369 dump_vmstate_json_to_file(vmstate_dump_file
);
4374 Error
*local_err
= NULL
;
4375 qemu_start_incoming_migration(incoming
, &local_err
);
4377 error_report("-incoming %s: %s", incoming
,
4378 error_get_pretty(local_err
));
4379 error_free(local_err
);
4382 } else if (autostart
) {
4388 if (is_daemonized()) {
4389 if (!trace_init_backends(trace_events
, trace_file
)) {