blob: 0a8f056cc2668bcbc34c1ab415c707e7ada8b9a3 [file] [log] [blame]
bellard0824d6f2003-06-24 13:42:40 +00001/*
bellard80cabfa2004-03-14 12:20:30 +00002 * QEMU System Emulator
ths5fafdf22007-09-16 21:08:06 +00003 *
bellard68d0f702008-01-06 17:21:48 +00004 * Copyright (c) 2003-2008 Fabrice Bellard
ths5fafdf22007-09-16 21:08:06 +00005 *
bellard1df912c2003-06-25 16:20:35 +00006 * 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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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
22 * THE SOFTWARE.
bellard0824d6f2003-06-24 13:42:40 +000023 */
bellard0824d6f2003-06-24 13:42:40 +000024#include <unistd.h>
bellard0824d6f2003-06-24 13:42:40 +000025#include <fcntl.h>
26#include <signal.h>
27#include <time.h>
bellard0824d6f2003-06-24 13:42:40 +000028#include <errno.h>
bellard67b915a2004-03-31 23:37:16 +000029#include <sys/time.h>
bellardc88676f2006-08-06 13:36:11 +000030#include <zlib.h>
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010031#include "qemu/bitmap.h"
bellard67b915a2004-03-31 23:37:16 +000032
Juan Quintela71e72a12009-07-27 16:12:56 +020033/* Needed early for CONFIG_BSD etc. */
blueswir1d40cdb12009-03-07 16:52:02 +000034#include "config-host.h"
35
bellard67b915a2004-03-31 23:37:16 +000036#ifndef _WIN32
Paul Brook5cea8592009-05-30 00:52:44 +010037#include <libgen.h>
bellard67b915a2004-03-31 23:37:16 +000038#include <sys/times.h>
bellardf1510b22003-06-25 00:07:40 +000039#include <sys/wait.h>
bellard67b915a2004-03-31 23:37:16 +000040#include <termios.h>
bellard67b915a2004-03-31 23:37:16 +000041#include <sys/mman.h>
bellardf1510b22003-06-25 00:07:40 +000042#include <sys/ioctl.h>
blueswir124646c72008-11-07 16:55:48 +000043#include <sys/resource.h>
bellardf1510b22003-06-25 00:07:40 +000044#include <sys/socket.h>
bellardc94c8d62004-09-13 21:37:34 +000045#include <netinet/in.h>
blueswir124646c72008-11-07 16:55:48 +000046#include <net/if.h>
blueswir124646c72008-11-07 16:55:48 +000047#include <arpa/inet.h>
bellard9d728e82004-09-05 23:09:03 +000048#include <dirent.h>
bellard7c9d8e02005-11-15 22:16:05 +000049#include <netdb.h>
thscb4b9762007-09-13 12:39:35 +000050#include <sys/select.h>
Prerna Saxenaab6540d2010-08-09 11:48:32 +010051
Juan Quintela71e72a12009-07-27 16:12:56 +020052#ifdef CONFIG_BSD
bellard7d3505c2004-05-12 19:32:15 +000053#include <sys/stat.h>
Aurelien Jarnoa167ba52009-11-29 18:00:41 +010054#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
Juergen Lock92c0e652010-03-25 22:07:12 +010055#include <sys/sysctl.h>
blueswir124646c72008-11-07 16:55:48 +000056#else
57#include <util.h>
blueswir1128ab2f2008-08-15 18:33:42 +000058#endif
Aurelien Jarnobbe813a2009-11-30 15:42:59 +010059#else
blueswir1223f0d72008-09-30 18:12:18 +000060#ifdef __linux__
bellard7d3505c2004-05-12 19:32:15 +000061#include <malloc.h>
thsbd494f42007-09-16 20:03:23 +000062
bellarde57a8c02005-11-10 23:58:52 +000063#include <linux/ppdev.h>
ths5867c882007-02-17 23:44:43 +000064#include <linux/parport.h>
blueswir1223f0d72008-09-30 18:12:18 +000065#endif
Eduardo Otubo452dfbe2012-08-14 18:44:07 -030066
67#ifdef CONFIG_SECCOMP
Paolo Bonzini9c17d612012-12-17 18:20:04 +010068#include "sysemu/seccomp.h"
Eduardo Otubo452dfbe2012-08-14 18:44:07 -030069#endif
70
blueswir1223f0d72008-09-30 18:12:18 +000071#ifdef __sun__
thsd5d10bc2007-02-17 22:54:49 +000072#include <sys/stat.h>
73#include <sys/ethernet.h>
74#include <sys/sockio.h>
thsd5d10bc2007-02-17 22:54:49 +000075#include <netinet/arp.h>
thsd5d10bc2007-02-17 22:54:49 +000076#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>
81#include <net/if.h>
82#include <syslog.h>
83#include <stropts.h>
bellard67b915a2004-03-31 23:37:16 +000084#endif
bellard7d3505c2004-05-12 19:32:15 +000085#endif
bellardec530c82006-04-25 22:36:06 +000086#endif
bellard67b915a2004-03-31 23:37:16 +000087
ths8a16d272008-07-19 09:56:24 +000088#if defined(CONFIG_VDE)
89#include <libvdeplug.h>
90#endif
91
bellard67b915a2004-03-31 23:37:16 +000092#ifdef _WIN32
aliguori49dc7682009-03-08 16:26:59 +000093#include <windows.h>
bellard67b915a2004-03-31 23:37:16 +000094#endif
95
bellard73332e52004-04-04 20:22:28 +000096#ifdef CONFIG_SDL
Stefan Weil59a36a22009-06-18 20:11:03 +020097#if defined(__APPLE__) || defined(main)
Stefan Weil66936652009-06-13 13:19:11 +020098#include <SDL.h>
malc880fec52009-02-15 20:18:41 +000099int qemu_main(int argc, char **argv, char **envp);
100int main(int argc, char **argv)
101{
Stefan Weil59a36a22009-06-18 20:11:03 +0200102 return qemu_main(argc, argv, NULL);
malc880fec52009-02-15 20:18:41 +0000103}
104#undef main
105#define main qemu_main
bellard96bcd4f2004-07-10 16:26:15 +0000106#endif
bellard73332e52004-04-04 20:22:28 +0000107#endif /* CONFIG_SDL */
bellard0824d6f2003-06-24 13:42:40 +0000108
bellard5b0753e2005-03-01 21:37:28 +0000109#ifdef CONFIG_COCOA
110#undef main
111#define main qemu_main
112#endif /* CONFIG_COCOA */
113
Anthony Liguori69e5bb62011-08-22 08:12:52 -0500114#include <glib.h>
115
blueswir1511d2b12009-03-07 15:32:56 +0000116#include "hw/hw.h"
117#include "hw/boards.h"
118#include "hw/usb.h"
119#include "hw/pcmcia.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +0100120#include "hw/i386/pc.h"
121#include "hw/isa/isa.h"
blueswir1511d2b12009-03-07 15:32:56 +0000122#include "hw/bt.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +0100123#include "sysemu/watchdog.h"
124#include "hw/i386/smbios.h"
125#include "hw/xen/xen.h"
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +0200126#include "hw/qdev.h"
Gerd Hoffmann45a50b12009-10-01 16:42:33 +0200127#include "hw/loader.h"
Paolo Bonzinib4a42f82013-02-04 11:37:52 +0100128#include "monitor/qdev.h"
Paolo Bonzinidccfcd02013-04-08 16:55:25 +0200129#include "sysemu/bt.h"
Paolo Bonzini1422e322012-10-24 08:43:34 +0200130#include "net/net.h"
Mark McLoughlin68ac40d2009-11-25 18:48:54 +0000131#include "net/slirp.h"
Paolo Bonzini83c90892012-12-17 18:19:49 +0100132#include "monitor/monitor.h"
Paolo Bonzini28ecbae2012-11-28 12:06:30 +0100133#include "ui/console.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +0100134#include "sysemu/sysemu.h"
Paolo Bonzini022c62c2012-12-17 18:19:49 +0100135#include "exec/gdbstub.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +0100136#include "qemu/timer.h"
Paolo Bonzinidccfcd02013-04-08 16:55:25 +0200137#include "sysemu/char.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +0100138#include "qemu/cache-utils.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +0100139#include "sysemu/blockdev.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +0100140#include "hw/block/block.h"
Paolo Bonzinicaf71f82012-12-17 18:19:50 +0100141#include "migration/block.h"
Paolo Bonzinibdee56f2013-04-02 18:28:41 +0200142#include "sysemu/tpm.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +0100143#include "sysemu/dma.h"
blueswir1511d2b12009-03-07 15:32:56 +0000144#include "audio/audio.h"
Paolo Bonzinicaf71f82012-12-17 18:19:50 +0100145#include "migration/migration.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +0100146#include "sysemu/kvm.h"
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +0100147#include "qapi/qmp/qjson.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +0100148#include "qemu/option.h"
149#include "qemu/config-file.h"
Jes Sorensen59a52642010-06-10 11:42:25 +0200150#include "qemu-options.h"
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -0300151#include "qmp-commands.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +0100152#include "qemu/main-loop.h"
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -0700153#ifdef CONFIG_VIRTFS
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530154#include "fsdev/qemu-fsdev.h"
155#endif
Paolo Bonzini9c17d612012-12-17 18:20:04 +0100156#include "sysemu/qtest.h"
blueswir1511d2b12009-03-07 15:32:56 +0000157
Paolo Bonzini76cad712012-10-24 11:12:21 +0200158#include "disas/disas.h"
bellardfc01f7e2003-06-30 10:03:06 +0000159
Paolo Bonzini1de7afc2012-12-17 18:20:00 +0100160#include "qemu/sockets.h"
blueswir1511d2b12009-03-07 15:32:56 +0000161
Jan Kiszkad918f232009-06-24 14:42:30 +0200162#include "slirp/libslirp.h"
blueswir1511d2b12009-03-07 15:32:56 +0000163
Stefan Hajnoczi94b0b5f2010-11-16 12:20:25 +0000164#include "trace.h"
Lluíse4858972011-08-31 20:31:03 +0200165#include "trace/control.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +0100166#include "qemu/queue.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +0100167#include "sysemu/cpus.h"
168#include "sysemu/arch_init.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +0100169#include "qemu/osdep.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +0000170
Gerd Hoffmann29b00402010-03-11 11:13:27 -0300171#include "ui/qemu-spice.h"
Anthony Liguori68d98d32012-06-25 14:36:33 -0500172#include "qapi/string-input-visitor.h"
Gerd Hoffmann29b00402010-03-11 11:13:27 -0300173
blueswir19dc63a12008-10-04 07:25:46 +0000174//#define DEBUG_NET
175//#define DEBUG_SLIRP
bellard330d0412003-07-26 18:11:40 +0000176
bellard1bfe8562004-07-08 21:17:50 +0000177#define DEFAULT_RAM_SIZE 128
bellard313aa562003-08-10 21:52:11 +0000178
Amit Shah98b19252010-01-20 00:36:52 +0530179#define MAX_VIRTIO_CONSOLES 1
Alexander Graf3ef669e2013-01-24 12:18:52 +0100180#define MAX_SCLP_CONSOLES 1
Amit Shah98b19252010-01-20 00:36:52 +0530181
Gerd Hoffmann45240512013-03-08 11:42:24 +0100182static const char *data_dir[16];
183static int data_dir_idx;
j_mayer1192dad2007-10-05 13:08:35 +0000184const char *bios_name = NULL;
malccb5a7aa2008-09-28 00:42:12 +0000185enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
Anthony Liguori993fbfd2009-05-21 16:54:00 -0500186DisplayType display_type = DT_DEFAULT;
Blue Swirl4fdcac02012-10-28 11:04:47 +0000187static int display_remote;
bellard3d11d0e2004-12-12 16:56:30 +0000188const char* keyboard_layout = NULL;
Anthony Liguoric227f092009-10-01 16:12:16 -0500189ram_addr_t ram_size;
Marcelo Tosattic9027602010-03-01 20:25:08 -0300190const char *mem_path = NULL;
191#ifdef MAP_POPULATE
192int mem_prealloc = 0; /* force preallocation of physical target memory */
193#endif
bellardc4b1fcc2004-03-14 21:44:30 +0000194int nb_nics;
bellard7c9d8e02005-11-15 22:16:05 +0000195NICInfo nd_table[MAX_NICS];
Paolo Bonzinid399f672009-07-27 23:17:51 +0200196int autostart;
balrogf6503052008-02-17 11:42:19 +0000197static int rtc_utc = 1;
198static int rtc_date_offset = -1; /* -1 means no change */
Jan Kiszka68752042009-09-15 13:36:04 +0200199QEMUClock *rtc_clock;
Gerd Hoffmann64465292009-12-08 13:11:45 +0100200int vga_interface_type = VGA_NONE;
blueswir1dbed7e42008-10-01 19:38:09 +0000201static int full_screen = 0;
202static int no_frame = 0;
ths667acca2006-12-11 02:08:05 +0000203int no_quit = 0;
bellard8d11df92004-08-24 21:13:40 +0000204CharDriverState *serial_hds[MAX_SERIAL_PORTS];
bellard6508fe52005-01-15 12:02:56 +0000205CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
aliguori9ede2fd2009-01-15 20:05:25 +0000206CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
Alexander Graf3ef669e2013-01-24 12:18:52 +0100207CharDriverState *sclp_hds[MAX_SCLP_CONSOLES];
bellarda09db212005-04-30 16:10:35 +0000208int win2k_install_hack = 0;
aurel321b530a62009-04-05 20:08:59 +0000209int singlestep = 0;
bellard6a00d602005-11-21 23:25:50 +0000210int smp_cpus = 1;
Jes Sorensen6be68d72009-07-23 17:03:42 +0200211int max_cpus = 0;
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200212int smp_cores = 1;
213int smp_threads = 1;
Jes Sorensen821601e2011-03-16 13:33:36 +0100214#ifdef CONFIG_VNC
ths73fc9742006-12-22 02:09:07 +0000215const char *vnc_display;
Jes Sorensen821601e2011-03-16 13:33:36 +0100216#endif
bellard6515b202006-05-03 22:02:44 +0000217int acpi_enabled = 1;
aliguori16b29ae2008-12-17 23:28:44 +0000218int no_hpet = 0;
bellard52ca8d62006-06-14 16:03:05 +0000219int fd_bootchk = 1;
Blue Swirl4fdcac02012-10-28 11:04:47 +0000220static int no_reboot;
aurel32b2f76162008-04-11 21:35:52 +0000221int no_shutdown = 0;
balrog9467cd42007-05-01 01:34:14 +0000222int cursor_hide = 1;
balroga171fe32007-04-30 01:48:07 +0000223int graphic_rotate = 0;
Markus Armbruster09aaa162009-08-21 10:31:34 +0200224const char *watchdog;
Gleb Natapov2e55e842010-12-08 13:35:07 +0200225QEMUOptionRom option_rom[MAX_OPTION_ROMS];
ths9ae02552007-01-05 17:39:04 +0000226int nb_option_roms;
pbrook8e716212007-01-20 17:12:09 +0000227int semihosting_enabled = 0;
balrog2b8f2d42007-07-27 22:08:46 +0000228int old_param = 0;
thsc35734b2007-03-19 15:17:08 +0000229const char *qemu_name;
ths3780e192007-06-21 21:08:02 +0000230int alt_grab = 0;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -0500231int ctrl_grab = 0;
blueswir166508602007-05-01 14:16:52 +0000232unsigned int nb_prom_envs = 0;
233const char *prom_envs[MAX_PROM_ENVS];
Jan Kiszka95387492009-07-02 00:19:02 +0200234int boot_menu;
Amos Kongc8a6ae82013-03-19 14:23:27 +0800235bool boot_strict;
wayne3d3b8302011-07-27 18:04:55 +0800236uint8_t *boot_splash_filedata;
Markus Armbrusterd09acb92013-01-23 18:25:08 +0100237size_t boot_splash_filedata_size;
wayne3d3b8302011-07-27 18:04:55 +0800238uint8_t qemu_extra_params_fw[2];
bellard0824d6f2003-06-24 13:42:40 +0000239
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200240typedef struct FWBootEntry FWBootEntry;
241
242struct FWBootEntry {
243 QTAILQ_ENTRY(FWBootEntry) link;
244 int32_t bootindex;
245 DeviceState *dev;
246 char *suffix;
247};
248
Blue Swirl4fdcac02012-10-28 11:04:47 +0000249static QTAILQ_HEAD(, FWBootEntry) fw_boot_order =
250 QTAILQ_HEAD_INITIALIZER(fw_boot_order);
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200251
aliguori268a3622009-04-21 22:30:27 +0000252int nb_numa_nodes;
253uint64_t node_mem[MAX_NODES];
Chegu Vinodee785fe2012-07-16 21:31:30 -0700254unsigned long *node_cpumask[MAX_NODES];
aliguori268a3622009-04-21 22:30:27 +0000255
blueswir18fcb1b92008-09-18 18:29:08 +0000256uint8_t qemu_uuid[16];
257
Jan Kiszka76e30d02009-07-02 00:19:02 +0200258static QEMUBootSetHandler *boot_set_handler;
259static void *boot_set_opaque;
260
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +0200261static NotifierList exit_notifiers =
262 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
263
Gleb Natapov4cab9462010-12-08 13:35:08 +0200264static NotifierList machine_init_done_notifiers =
265 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
266
liguangd5286af2013-01-24 13:03:27 +0800267static bool tcg_allowed = true;
liguangd5286af2013-01-24 13:03:27 +0800268bool xen_allowed;
Blue Swirld745bef2010-03-29 19:23:49 +0000269uint32_t xen_domid;
270enum xen_mode xen_mode = XEN_EMULATE;
Jan Kiszkad5ab9712011-08-02 16:10:21 +0200271static int tcg_tb_size;
Blue Swirld745bef2010-03-29 19:23:49 +0000272
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100273static int default_serial = 1;
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +0100274static int default_parallel = 1;
Gerd Hoffmann986c5f72009-12-08 13:11:54 +0100275static int default_virtcon = 1;
Alexander Graf3ef669e2013-01-24 12:18:52 +0100276static int default_sclp = 1;
Gerd Hoffmannabdeed02009-12-08 13:11:43 +0100277static int default_monitor = 1;
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +0100278static int default_floppy = 1;
279static int default_cdrom = 1;
280static int default_sdcard = 1;
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +0200281static int default_vga = 1;
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100282
283static struct {
284 const char *driver;
285 int *flag;
286} default_list[] = {
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +0100287 { .driver = "isa-serial", .flag = &default_serial },
288 { .driver = "isa-parallel", .flag = &default_parallel },
Gerd Hoffmannd8bcbab2009-12-16 14:25:40 +0100289 { .driver = "isa-fdc", .flag = &default_floppy },
Markus Armbrusteraf6bf132011-05-18 18:31:02 +0200290 { .driver = "ide-cd", .flag = &default_cdrom },
291 { .driver = "ide-hd", .flag = &default_cdrom },
Gerd Hoffmannd8bcbab2009-12-16 14:25:40 +0100292 { .driver = "ide-drive", .flag = &default_cdrom },
Markus Armbrusteraf6bf132011-05-18 18:31:02 +0200293 { .driver = "scsi-cd", .flag = &default_cdrom },
Amit Shah392ecf52010-01-21 16:19:23 +0530294 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
295 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
296 { .driver = "virtio-serial", .flag = &default_virtcon },
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +0200297 { .driver = "VGA", .flag = &default_vga },
298 { .driver = "isa-vga", .flag = &default_vga },
299 { .driver = "cirrus-vga", .flag = &default_vga },
300 { .driver = "isa-cirrus-vga", .flag = &default_vga },
301 { .driver = "vmware-svga", .flag = &default_vga },
302 { .driver = "qxl-vga", .flag = &default_vga },
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100303};
304
Paolo Bonzini4d454572012-11-26 16:03:42 +0100305static QemuOptsList qemu_rtc_opts = {
306 .name = "rtc",
307 .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head),
308 .desc = {
309 {
310 .name = "base",
311 .type = QEMU_OPT_STRING,
312 },{
313 .name = "clock",
314 .type = QEMU_OPT_STRING,
315 },{
316 .name = "driftfix",
317 .type = QEMU_OPT_STRING,
318 },
319 { /* end of list */ }
320 },
321};
322
323static QemuOptsList qemu_sandbox_opts = {
324 .name = "sandbox",
325 .implied_opt_name = "enable",
326 .head = QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts.head),
327 .desc = {
328 {
329 .name = "enable",
330 .type = QEMU_OPT_BOOL,
331 },
332 { /* end of list */ }
333 },
334};
335
336static QemuOptsList qemu_trace_opts = {
337 .name = "trace",
338 .implied_opt_name = "trace",
339 .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
340 .desc = {
341 {
342 .name = "events",
343 .type = QEMU_OPT_STRING,
344 },{
345 .name = "file",
346 .type = QEMU_OPT_STRING,
347 },
348 { /* end of list */ }
349 },
350};
351
352static QemuOptsList qemu_option_rom_opts = {
353 .name = "option-rom",
354 .implied_opt_name = "romfile",
355 .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head),
356 .desc = {
357 {
358 .name = "bootindex",
359 .type = QEMU_OPT_NUMBER,
360 }, {
361 .name = "romfile",
362 .type = QEMU_OPT_STRING,
363 },
364 { /* end of list */ }
365 },
366};
367
368static QemuOptsList qemu_machine_opts = {
369 .name = "machine",
370 .implied_opt_name = "type",
371 .merge_lists = true,
372 .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
373 .desc = {
374 {
375 .name = "type",
376 .type = QEMU_OPT_STRING,
377 .help = "emulated machine"
378 }, {
379 .name = "accel",
380 .type = QEMU_OPT_STRING,
381 .help = "accelerator list",
382 }, {
383 .name = "kernel_irqchip",
384 .type = QEMU_OPT_BOOL,
385 .help = "use KVM in-kernel irqchip",
386 }, {
387 .name = "kvm_shadow_mem",
388 .type = QEMU_OPT_SIZE,
389 .help = "KVM shadow MMU size",
390 }, {
391 .name = "kernel",
392 .type = QEMU_OPT_STRING,
393 .help = "Linux kernel image file",
394 }, {
395 .name = "initrd",
396 .type = QEMU_OPT_STRING,
397 .help = "Linux initial ramdisk file",
398 }, {
399 .name = "append",
400 .type = QEMU_OPT_STRING,
401 .help = "Linux kernel command line",
402 }, {
403 .name = "dtb",
404 .type = QEMU_OPT_STRING,
405 .help = "Linux kernel device tree file",
406 }, {
407 .name = "dumpdtb",
408 .type = QEMU_OPT_STRING,
409 .help = "Dump current dtb to a file and quit",
410 }, {
411 .name = "phandle_start",
412 .type = QEMU_OPT_STRING,
413 .help = "The first phandle ID we may generate dynamically",
414 }, {
415 .name = "dt_compatible",
416 .type = QEMU_OPT_STRING,
417 .help = "Overrides the \"compatible\" property of the dt root node",
418 }, {
419 .name = "dump-guest-core",
420 .type = QEMU_OPT_BOOL,
421 .help = "Include guest memory in a core dump",
422 }, {
423 .name = "mem-merge",
424 .type = QEMU_OPT_BOOL,
425 .help = "enable/disable memory merge support",
426 },{
427 .name = "usb",
428 .type = QEMU_OPT_BOOL,
429 .help = "Set on/off to enable/disable usb",
430 },
431 { /* End of list */ }
432 },
433};
434
435static QemuOptsList qemu_boot_opts = {
436 .name = "boot-opts",
Markus Armbruster6ef47162013-06-14 13:15:01 +0200437 .implied_opt_name = "order",
438 .merge_lists = true,
Paolo Bonzini4d454572012-11-26 16:03:42 +0100439 .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head),
440 .desc = {
Paolo Bonzini4d454572012-11-26 16:03:42 +0100441 {
442 .name = "order",
443 .type = QEMU_OPT_STRING,
444 }, {
445 .name = "once",
446 .type = QEMU_OPT_STRING,
447 }, {
448 .name = "menu",
Markus Armbruster6ef47162013-06-14 13:15:01 +0200449 .type = QEMU_OPT_BOOL,
Paolo Bonzini4d454572012-11-26 16:03:42 +0100450 }, {
451 .name = "splash",
452 .type = QEMU_OPT_STRING,
453 }, {
454 .name = "splash-time",
455 .type = QEMU_OPT_STRING,
456 }, {
457 .name = "reboot-timeout",
458 .type = QEMU_OPT_STRING,
Amos Kongc8a6ae82013-03-19 14:23:27 +0800459 }, {
460 .name = "strict",
461 .type = QEMU_OPT_STRING,
Paolo Bonzini4d454572012-11-26 16:03:42 +0100462 },
463 { /*End of list */ }
464 },
465};
466
467static QemuOptsList qemu_add_fd_opts = {
468 .name = "add-fd",
469 .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head),
470 .desc = {
471 {
472 .name = "fd",
473 .type = QEMU_OPT_NUMBER,
474 .help = "file descriptor of which a duplicate is added to fd set",
475 },{
476 .name = "set",
477 .type = QEMU_OPT_NUMBER,
478 .help = "ID of the fd set to add fd to",
479 },{
480 .name = "opaque",
481 .type = QEMU_OPT_STRING,
482 .help = "free-form string used to describe fd",
483 },
484 { /* end of list */ }
485 },
486};
487
488static QemuOptsList qemu_object_opts = {
489 .name = "object",
490 .implied_opt_name = "qom-type",
491 .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
492 .desc = {
493 { }
494 },
495};
496
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500497static QemuOptsList qemu_tpmdev_opts = {
498 .name = "tpmdev",
499 .implied_opt_name = "type",
500 .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head),
501 .desc = {
Stefan Bergerbb716232013-04-22 10:41:39 -0400502 /* options are defined in the TPM backends */
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500503 { /* end of list */ }
504 },
505};
506
Satoru Moriya888a6bc2013-04-19 16:42:06 +0200507static QemuOptsList qemu_realtime_opts = {
508 .name = "realtime",
509 .head = QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts.head),
510 .desc = {
511 {
512 .name = "mlock",
513 .type = QEMU_OPT_BOOL,
514 },
515 { /* end of list */ }
516 },
517};
518
Ronnie Sahlberg31459f42012-08-06 18:24:55 +1000519const char *qemu_get_vm_name(void)
520{
521 return qemu_name;
522}
523
wayne3d3b8302011-07-27 18:04:55 +0800524static void res_free(void)
525{
526 if (boot_splash_filedata != NULL) {
Anthony Liguori7267c092011-08-20 22:09:37 -0500527 g_free(boot_splash_filedata);
wayne3d3b8302011-07-27 18:04:55 +0800528 boot_splash_filedata = NULL;
529 }
530}
531
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100532static int default_driver_check(QemuOpts *opts, void *opaque)
533{
534 const char *driver = qemu_opt_get(opts, "driver");
535 int i;
536
537 if (!driver)
538 return 0;
539 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
540 if (strcmp(default_list[i].driver, driver) != 0)
541 continue;
542 *(default_list[i].flag) = 0;
543 }
544 return 0;
545}
546
bellard0824d6f2003-06-24 13:42:40 +0000547/***********************************************************/
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300548/* QEMU state */
549
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300550static RunState current_run_state = RUN_STATE_PRELAUNCH;
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300551
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300552typedef struct {
553 RunState from;
554 RunState to;
555} RunStateTransition;
556
557static const RunStateTransition runstate_transitions_def[] = {
558 /* from -> to */
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300559 { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300560
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300561 { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },
Paolo Bonzini29ed72f2012-10-19 16:45:24 +0200562 { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300563
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300564 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300565 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300566
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300567 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300568 { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300569
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300570 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300571 { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300572
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300573 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300574 { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300575
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300576 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300577 { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300578 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300579
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300580 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
581 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300582
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300583 { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300584
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300585 { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
586 { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
587 { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
588 { RUN_STATE_RUNNING, RUN_STATE_PAUSED },
589 { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE },
590 { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM },
591 { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM },
592 { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
593 { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
Hu Taoede085b2013-04-26 11:24:40 +0800594 { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300595
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300596 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300597
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300598 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300599 { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300600
Luiz Capitulinoad02b962012-04-27 13:33:36 -0300601 { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
602 { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
603 { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },
604 { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
605
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300606 { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300607 { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300608
Hu Taoede085b2013-04-26 11:24:40 +0800609 { RUN_STATE_GUEST_PANICKED, RUN_STATE_PAUSED },
Hu Taofd2a2e12013-05-20 12:46:20 +0200610 { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE },
Paolo Bonzinibc7d0e62013-06-03 17:06:55 +0200611 { RUN_STATE_GUEST_PANICKED, RUN_STATE_DEBUG },
Hu Taoede085b2013-04-26 11:24:40 +0800612
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300613 { RUN_STATE_MAX, RUN_STATE_MAX },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300614};
615
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300616static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX];
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300617
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300618bool runstate_check(RunState state)
619{
620 return current_run_state == state;
621}
622
Blue Swirl4fdcac02012-10-28 11:04:47 +0000623static void runstate_init(void)
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300624{
625 const RunStateTransition *p;
626
627 memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions));
628
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300629 for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) {
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300630 runstate_valid_transitions[p->from][p->to] = true;
631 }
632}
633
634/* This function will abort() on invalid state transitions */
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300635void runstate_set(RunState new_state)
636{
Luiz Capitulino207c5cd2011-10-13 10:59:07 -0300637 assert(new_state < RUN_STATE_MAX);
638
639 if (!runstate_valid_transitions[current_run_state][new_state]) {
640 fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
641 RunState_lookup[current_run_state],
642 RunState_lookup[new_state]);
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300643 abort();
644 }
Kazuya Saito7e866002013-03-22 17:26:59 +0900645 trace_runstate_set(new_state);
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300646 current_run_state = new_state;
647}
648
Luiz Capitulino13548692011-07-29 15:36:43 -0300649int runstate_is_running(void)
650{
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300651 return runstate_check(RUN_STATE_RUNNING);
Luiz Capitulino13548692011-07-29 15:36:43 -0300652}
653
Hu Taoede085b2013-04-26 11:24:40 +0800654bool runstate_needs_reset(void)
655{
656 return runstate_check(RUN_STATE_INTERNAL_ERROR) ||
657 runstate_check(RUN_STATE_SHUTDOWN) ||
658 runstate_check(RUN_STATE_GUEST_PANICKED);
659}
660
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -0300661StatusInfo *qmp_query_status(Error **errp)
662{
663 StatusInfo *info = g_malloc0(sizeof(*info));
664
665 info->running = runstate_is_running();
666 info->singlestep = singlestep;
667 info->status = current_run_state;
668
669 return info;
670}
671
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300672/***********************************************************/
Paolo Bonzini8f0056b2010-01-13 14:05:34 +0100673/* real time host monotonic timer */
bellard09b26c52006-04-12 21:09:08 +0000674
bellardc4b1fcc2004-03-14 21:44:30 +0000675/***********************************************************/
balrogf6503052008-02-17 11:42:19 +0000676/* host time/date access */
677void qemu_get_timedate(struct tm *tm, int offset)
678{
679 time_t ti;
balrogf6503052008-02-17 11:42:19 +0000680
681 time(&ti);
682 ti += offset;
683 if (rtc_date_offset == -1) {
684 if (rtc_utc)
Stefan Weileb7ff6f2013-01-07 23:08:13 +0100685 gmtime_r(&ti, tm);
balrogf6503052008-02-17 11:42:19 +0000686 else
Stefan Weileb7ff6f2013-01-07 23:08:13 +0100687 localtime_r(&ti, tm);
balrogf6503052008-02-17 11:42:19 +0000688 } else {
689 ti -= rtc_date_offset;
Stefan Weileb7ff6f2013-01-07 23:08:13 +0100690 gmtime_r(&ti, tm);
balrogf6503052008-02-17 11:42:19 +0000691 }
balrogf6503052008-02-17 11:42:19 +0000692}
693
694int qemu_timedate_diff(struct tm *tm)
695{
696 time_t seconds;
697
698 if (rtc_date_offset == -1)
699 if (rtc_utc)
700 seconds = mktimegm(tm);
Gleb Natapovf54c5562011-11-06 18:00:22 +0200701 else {
702 struct tm tmp = *tm;
703 tmp.tm_isdst = -1; /* use timezone to figure it out */
704 seconds = mktime(&tmp);
705 }
balrogf6503052008-02-17 11:42:19 +0000706 else
707 seconds = mktimegm(tm) + rtc_date_offset;
708
709 return seconds - time(NULL);
710}
711
Luiz Capitulino80cd3472010-02-25 12:11:44 -0300712void rtc_change_mon_event(struct tm *tm)
713{
714 QObject *data;
715
716 data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
717 monitor_protocol_event(QEVENT_RTC_CHANGE, data);
718 qobject_decref(data);
719}
720
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200721static void configure_rtc_date_offset(const char *startdate, int legacy)
722{
723 time_t rtc_start_date;
724 struct tm tm;
725
726 if (!strcmp(startdate, "now") && legacy) {
727 rtc_date_offset = -1;
728 } else {
729 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
730 &tm.tm_year,
731 &tm.tm_mon,
732 &tm.tm_mday,
733 &tm.tm_hour,
734 &tm.tm_min,
735 &tm.tm_sec) == 6) {
736 /* OK */
737 } else if (sscanf(startdate, "%d-%d-%d",
738 &tm.tm_year,
739 &tm.tm_mon,
740 &tm.tm_mday) == 3) {
741 tm.tm_hour = 0;
742 tm.tm_min = 0;
743 tm.tm_sec = 0;
744 } else {
745 goto date_fail;
746 }
747 tm.tm_year -= 1900;
748 tm.tm_mon--;
749 rtc_start_date = mktimegm(&tm);
750 if (rtc_start_date == -1) {
751 date_fail:
752 fprintf(stderr, "Invalid date format. Valid formats are:\n"
753 "'2006-06-17T16:01:21' or '2006-06-17'\n");
754 exit(1);
755 }
756 rtc_date_offset = time(NULL) - rtc_start_date;
757 }
758}
759
760static void configure_rtc(QemuOpts *opts)
761{
762 const char *value;
763
764 value = qemu_opt_get(opts, "base");
765 if (value) {
766 if (!strcmp(value, "utc")) {
767 rtc_utc = 1;
768 } else if (!strcmp(value, "localtime")) {
769 rtc_utc = 0;
770 } else {
771 configure_rtc_date_offset(value, 0);
772 }
773 }
Jan Kiszka68752042009-09-15 13:36:04 +0200774 value = qemu_opt_get(opts, "clock");
775 if (value) {
776 if (!strcmp(value, "host")) {
777 rtc_clock = host_clock;
Paolo Bonzini78808142012-03-30 10:31:21 +0000778 } else if (!strcmp(value, "rt")) {
779 rtc_clock = rt_clock;
Jan Kiszka68752042009-09-15 13:36:04 +0200780 } else if (!strcmp(value, "vm")) {
781 rtc_clock = vm_clock;
782 } else {
783 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
784 exit(1);
785 }
786 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200787 value = qemu_opt_get(opts, "driftfix");
788 if (value) {
Blue Swirl7e4c0332010-03-27 21:33:46 +0000789 if (!strcmp(value, "slew")) {
Jan Kiszka433acf02012-01-23 20:15:12 +0100790 static GlobalProperty slew_lost_ticks[] = {
791 {
792 .driver = "mc146818rtc",
793 .property = "lost_tick_policy",
794 .value = "slew",
795 },
796 { /* end of list */ }
797 };
798
799 qdev_prop_register_global_list(slew_lost_ticks);
Blue Swirl7e4c0332010-03-27 21:33:46 +0000800 } else if (!strcmp(value, "none")) {
Jan Kiszka433acf02012-01-23 20:15:12 +0100801 /* discard is default */
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200802 } else {
803 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
804 exit(1);
805 }
806 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200807}
808
balrog1ae26a12008-09-28 23:19:47 +0000809/***********************************************************/
810/* Bluetooth support */
811static int nb_hcis;
812static int cur_hci;
813static struct HCIInfo *hci_table[MAX_NICS];
balrogdc72ac12008-11-09 00:04:26 +0000814
balrog1ae26a12008-09-28 23:19:47 +0000815static struct bt_vlan_s {
816 struct bt_scatternet_s net;
817 int id;
818 struct bt_vlan_s *next;
819} *first_bt_vlan;
820
821/* find or alloc a new bluetooth "VLAN" */
blueswir1674bb262008-09-30 18:18:27 +0000822static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
balrog1ae26a12008-09-28 23:19:47 +0000823{
824 struct bt_vlan_s **pvlan, *vlan;
825 for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) {
826 if (vlan->id == id)
827 return &vlan->net;
828 }
Anthony Liguori7267c092011-08-20 22:09:37 -0500829 vlan = g_malloc0(sizeof(struct bt_vlan_s));
balrog1ae26a12008-09-28 23:19:47 +0000830 vlan->id = id;
831 pvlan = &first_bt_vlan;
832 while (*pvlan != NULL)
833 pvlan = &(*pvlan)->next;
834 *pvlan = vlan;
835 return &vlan->net;
836}
837
838static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
839{
840}
841
842static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
843{
844 return -ENOTSUP;
845}
846
847static struct HCIInfo null_hci = {
848 .cmd_send = null_hci_send,
849 .sco_send = null_hci_send,
850 .acl_send = null_hci_send,
851 .bdaddr_set = null_hci_addr_set,
852};
853
854struct HCIInfo *qemu_next_hci(void)
855{
856 if (cur_hci == nb_hcis)
857 return &null_hci;
858
859 return hci_table[cur_hci++];
860}
861
balrogdc72ac12008-11-09 00:04:26 +0000862static struct HCIInfo *hci_init(const char *str)
863{
864 char *endp;
865 struct bt_scatternet_s *vlan = 0;
866
867 if (!strcmp(str, "null"))
868 /* null */
869 return &null_hci;
870 else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':'))
871 /* host[:hciN] */
872 return bt_host_hci(str[4] ? str + 5 : "hci0");
873 else if (!strncmp(str, "hci", 3)) {
874 /* hci[,vlan=n] */
875 if (str[3]) {
876 if (!strncmp(str + 3, ",vlan=", 6)) {
877 vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0));
878 if (*endp)
879 vlan = 0;
880 }
881 } else
882 vlan = qemu_find_bt_vlan(0);
883 if (vlan)
884 return bt_new_hci(vlan);
885 }
886
887 fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
888
889 return 0;
890}
891
892static int bt_hci_parse(const char *str)
893{
894 struct HCIInfo *hci;
Anthony Liguoric227f092009-10-01 16:12:16 -0500895 bdaddr_t bdaddr;
balrogdc72ac12008-11-09 00:04:26 +0000896
897 if (nb_hcis >= MAX_NICS) {
898 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
899 return -1;
900 }
901
902 hci = hci_init(str);
903 if (!hci)
904 return -1;
905
906 bdaddr.b[0] = 0x52;
907 bdaddr.b[1] = 0x54;
908 bdaddr.b[2] = 0x00;
909 bdaddr.b[3] = 0x12;
910 bdaddr.b[4] = 0x34;
911 bdaddr.b[5] = 0x56 + nb_hcis;
912 hci->bdaddr_set(hci, bdaddr.b);
913
914 hci_table[nb_hcis++] = hci;
915
916 return 0;
917}
918
919static void bt_vhci_add(int vlan_id)
920{
921 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
922
923 if (!vlan->slave)
924 fprintf(stderr, "qemu: warning: adding a VHCI to "
925 "an empty scatternet %i\n", vlan_id);
926
927 bt_vhci_init(bt_new_hci(vlan));
928}
929
930static struct bt_device_s *bt_device_add(const char *opt)
931{
932 struct bt_scatternet_s *vlan;
933 int vlan_id = 0;
934 char *endp = strstr(opt, ",vlan=");
935 int len = (endp ? endp - opt : strlen(opt)) + 1;
936 char devname[10];
937
938 pstrcpy(devname, MIN(sizeof(devname), len), opt);
939
940 if (endp) {
941 vlan_id = strtol(endp + 6, &endp, 0);
942 if (*endp) {
943 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
944 return 0;
945 }
946 }
947
948 vlan = qemu_find_bt_vlan(vlan_id);
949
950 if (!vlan->slave)
951 fprintf(stderr, "qemu: warning: adding a slave device to "
952 "an empty scatternet %i\n", vlan_id);
953
954 if (!strcmp(devname, "keyboard"))
955 return bt_keyboard_init(vlan);
956
957 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
958 return 0;
959}
960
961static int bt_parse(const char *opt)
962{
963 const char *endp, *p;
964 int vlan;
965
966 if (strstart(opt, "hci", &endp)) {
967 if (!*endp || *endp == ',') {
968 if (*endp)
969 if (!strstart(endp, ",vlan=", 0))
970 opt = endp + 1;
971
972 return bt_hci_parse(opt);
973 }
974 } else if (strstart(opt, "vhci", &endp)) {
975 if (!*endp || *endp == ',') {
976 if (*endp) {
977 if (strstart(endp, ",vlan=", &p)) {
978 vlan = strtol(p, (char **) &endp, 0);
979 if (*endp) {
980 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
981 return 1;
982 }
983 } else {
984 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
985 return 1;
986 }
987 } else
988 vlan = 0;
989
990 bt_vhci_add(vlan);
991 return 0;
992 }
993 } else if (strstart(opt, "device:", &endp))
994 return !bt_device_add(endp);
995
996 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
997 return 1;
998}
999
Eduardo Otubo7d76ad42012-08-14 18:44:08 -03001000static int parse_sandbox(QemuOpts *opts, void *opaque)
1001{
1002 /* FIXME: change this to true for 1.3 */
1003 if (qemu_opt_get_bool(opts, "enable", false)) {
1004#ifdef CONFIG_SECCOMP
1005 if (seccomp_start() < 0) {
1006 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1007 "failed to install seccomp syscall filter in the kernel");
1008 return -1;
1009 }
1010#else
1011 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1012 "sandboxing request but seccomp is not compiled into this build");
1013 return -1;
1014#endif
1015 }
1016
1017 return 0;
1018}
1019
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00001020/*********QEMU USB setting******/
1021bool usb_enabled(bool default_usb)
1022{
1023 QemuOpts *mach_opts;
1024 mach_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
1025 if (mach_opts) {
1026 return qemu_opt_get_bool(mach_opts, "usb", default_usb);
1027 }
1028 return default_usb;
1029}
1030
Corey Bryant587ed6b2012-10-18 15:19:34 -04001031#ifndef _WIN32
1032static int parse_add_fd(QemuOpts *opts, void *opaque)
1033{
1034 int fd, dupfd, flags;
1035 int64_t fdset_id;
1036 const char *fd_opaque = NULL;
1037
1038 fd = qemu_opt_get_number(opts, "fd", -1);
1039 fdset_id = qemu_opt_get_number(opts, "set", -1);
1040 fd_opaque = qemu_opt_get(opts, "opaque");
1041
1042 if (fd < 0) {
1043 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1044 "fd option is required and must be non-negative");
1045 return -1;
1046 }
1047
1048 if (fd <= STDERR_FILENO) {
1049 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1050 "fd cannot be a standard I/O stream");
1051 return -1;
1052 }
1053
1054 /*
1055 * All fds inherited across exec() necessarily have FD_CLOEXEC
1056 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1057 */
1058 flags = fcntl(fd, F_GETFD);
1059 if (flags == -1 || (flags & FD_CLOEXEC)) {
1060 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1061 "fd is not valid or already in use");
1062 return -1;
1063 }
1064
1065 if (fdset_id < 0) {
1066 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1067 "set option is required and must be non-negative");
1068 return -1;
1069 }
1070
1071#ifdef F_DUPFD_CLOEXEC
1072 dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
1073#else
1074 dupfd = dup(fd);
1075 if (dupfd != -1) {
1076 qemu_set_cloexec(dupfd);
1077 }
1078#endif
1079 if (dupfd == -1) {
1080 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1081 "Error duplicating fd: %s", strerror(errno));
1082 return -1;
1083 }
1084
1085 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1086 monitor_fdset_add_fd(dupfd, true, fdset_id, fd_opaque ? true : false,
1087 fd_opaque, NULL);
1088
1089 return 0;
1090}
1091
1092static int cleanup_add_fd(QemuOpts *opts, void *opaque)
1093{
1094 int fd;
1095
1096 fd = qemu_opt_get_number(opts, "fd", -1);
1097 close(fd);
1098
1099 return 0;
1100}
1101#endif
1102
balrog1ae26a12008-09-28 23:19:47 +00001103/***********************************************************/
1104/* QEMU Block devices */
1105
Markus Armbruster2292dda2011-01-28 11:21:41 +01001106#define HD_OPTS "media=disk"
1107#define CDROM_OPTS "media=cdrom"
1108#define FD_OPTS ""
1109#define PFLASH_OPTS ""
1110#define MTD_OPTS ""
1111#define SD_OPTS ""
thse4bcb142007-12-02 04:51:10 +00001112
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02001113static int drive_init_func(QemuOpts *opts, void *opaque)
1114{
Christian Borntraeger2d0d2832012-11-20 15:30:34 +01001115 BlockInterfaceType *block_default_type = opaque;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02001116
Christian Borntraeger2d0d2832012-11-20 15:30:34 +01001117 return drive_init(opts, *block_default_type) == NULL;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02001118}
1119
1120static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
1121{
1122 if (NULL == qemu_opt_get(opts, "snapshot")) {
1123 qemu_opt_set(opts, "snapshot", "on");
1124 }
1125 return 0;
1126}
1127
Christian Borntraeger3c42ea62012-11-22 21:02:55 +01001128static void default_drive(int enable, int snapshot, BlockInterfaceType type,
1129 int index, const char *optstr)
Markus Armbruster4e5d9b52011-01-28 11:21:45 +01001130{
1131 QemuOpts *opts;
1132
Markus Armbruster4e5d9b52011-01-28 11:21:45 +01001133 if (!enable || drive_get_by_index(type, index)) {
1134 return;
1135 }
1136
1137 opts = drive_add(type, index, NULL, optstr);
1138 if (snapshot) {
1139 drive_enable_snapshot(opts, NULL);
1140 }
Christian Borntraeger2d0d2832012-11-20 15:30:34 +01001141 if (!drive_init(opts, type)) {
Markus Armbruster4e5d9b52011-01-28 11:21:45 +01001142 exit(1);
1143 }
1144}
1145
Jan Kiszka76e30d02009-07-02 00:19:02 +02001146void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
1147{
1148 boot_set_handler = func;
1149 boot_set_opaque = opaque;
1150}
1151
Markus Armbruster083b79c2013-06-14 13:15:04 +02001152int qemu_boot_set(const char *boot_order)
Jan Kiszka76e30d02009-07-02 00:19:02 +02001153{
1154 if (!boot_set_handler) {
1155 return -EINVAL;
1156 }
Markus Armbruster083b79c2013-06-14 13:15:04 +02001157 return boot_set_handler(boot_set_opaque, boot_order);
Jan Kiszka76e30d02009-07-02 00:19:02 +02001158}
1159
Markus Armbruster6ef47162013-06-14 13:15:01 +02001160static void validate_bootdevices(const char *devices)
Jan Kiszkaef3adf62009-07-02 00:19:02 +02001161{
1162 /* We just do some generic consistency checks */
1163 const char *p;
1164 int bitmap = 0;
1165
1166 for (p = devices; *p != '\0'; p++) {
1167 /* Allowed boot devices are:
1168 * a-b: floppy disk drives
1169 * c-f: IDE disk drives
Dong Xu Wang07f35072011-11-22 18:06:26 +08001170 * g-m: machine implementation dependent drives
Jan Kiszkaef3adf62009-07-02 00:19:02 +02001171 * n-p: network devices
1172 * It's up to each machine implementation to check if the given boot
1173 * devices match the actual hardware implementation and firmware
1174 * features.
1175 */
1176 if (*p < 'a' || *p > 'p') {
1177 fprintf(stderr, "Invalid boot device '%c'\n", *p);
1178 exit(1);
1179 }
1180 if (bitmap & (1 << (*p - 'a'))) {
1181 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
1182 exit(1);
1183 }
1184 bitmap |= 1 << (*p - 'a');
1185 }
Jan Kiszkaef3adf62009-07-02 00:19:02 +02001186}
1187
Markus Armbruster083b79c2013-06-14 13:15:04 +02001188static void restore_boot_order(void *opaque)
Jan Kiszkae0f084b2009-07-02 00:19:02 +02001189{
Markus Armbruster083b79c2013-06-14 13:15:04 +02001190 char *normal_boot_order = opaque;
Alex Williamson37905d62010-04-30 15:21:11 -06001191 static int first = 1;
1192
1193 /* Restore boot order and remove ourselves after the first boot */
1194 if (first) {
1195 first = 0;
1196 return;
1197 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +02001198
Markus Armbruster083b79c2013-06-14 13:15:04 +02001199 qemu_boot_set(normal_boot_order);
Jan Kiszkae0f084b2009-07-02 00:19:02 +02001200
Markus Armbruster083b79c2013-06-14 13:15:04 +02001201 qemu_unregister_reset(restore_boot_order, normal_boot_order);
1202 g_free(normal_boot_order);
Jan Kiszkae0f084b2009-07-02 00:19:02 +02001203}
1204
Gleb Natapov1ca4d092010-12-08 13:35:05 +02001205void add_boot_device_path(int32_t bootindex, DeviceState *dev,
1206 const char *suffix)
1207{
1208 FWBootEntry *node, *i;
1209
1210 if (bootindex < 0) {
1211 return;
1212 }
1213
1214 assert(dev != NULL || suffix != NULL);
1215
Anthony Liguori7267c092011-08-20 22:09:37 -05001216 node = g_malloc0(sizeof(FWBootEntry));
Gleb Natapov1ca4d092010-12-08 13:35:05 +02001217 node->bootindex = bootindex;
Dong Xu Wang7f303ad2013-05-09 15:53:49 +08001218 node->suffix = g_strdup(suffix);
Gleb Natapov1ca4d092010-12-08 13:35:05 +02001219 node->dev = dev;
1220
1221 QTAILQ_FOREACH(i, &fw_boot_order, link) {
1222 if (i->bootindex == bootindex) {
1223 fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
1224 exit(1);
1225 } else if (i->bootindex < bootindex) {
1226 continue;
1227 }
1228 QTAILQ_INSERT_BEFORE(i, node, link);
1229 return;
1230 }
1231 QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
1232}
1233
Dominik Dingel7dc5af52013-04-26 02:12:49 +00001234DeviceState *get_boot_device(uint32_t position)
1235{
1236 uint32_t counter = 0;
1237 FWBootEntry *i = NULL;
1238 DeviceState *res = NULL;
1239
1240 if (!QTAILQ_EMPTY(&fw_boot_order)) {
1241 QTAILQ_FOREACH(i, &fw_boot_order, link) {
1242 if (counter == position) {
1243 res = i->dev;
1244 break;
1245 }
1246 counter++;
1247 }
1248 }
1249 return res;
1250}
1251
Gleb Natapov962630f2010-12-08 13:35:09 +02001252/*
1253 * This function returns null terminated string that consist of new line
Brad Hards71785ab2011-04-23 21:50:06 +10001254 * separated device paths.
Gleb Natapov962630f2010-12-08 13:35:09 +02001255 *
1256 * memory pointed by "size" is assigned total length of the array in bytes
1257 *
1258 */
Markus Armbruster0e7a7592013-01-16 14:50:29 +01001259char *get_boot_devices_list(size_t *size)
Gleb Natapov962630f2010-12-08 13:35:09 +02001260{
1261 FWBootEntry *i;
Markus Armbruster0e7a7592013-01-16 14:50:29 +01001262 size_t total = 0;
Gleb Natapov962630f2010-12-08 13:35:09 +02001263 char *list = NULL;
1264
1265 QTAILQ_FOREACH(i, &fw_boot_order, link) {
1266 char *devpath = NULL, *bootpath;
Markus Armbruster0e7a7592013-01-16 14:50:29 +01001267 size_t len;
Gleb Natapov962630f2010-12-08 13:35:09 +02001268
1269 if (i->dev) {
1270 devpath = qdev_get_fw_dev_path(i->dev);
1271 assert(devpath);
1272 }
1273
1274 if (i->suffix && devpath) {
Blue Swirl4fd37a92010-12-19 14:05:43 +00001275 size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
1276
Anthony Liguori7267c092011-08-20 22:09:37 -05001277 bootpath = g_malloc(bootpathlen);
Blue Swirl4fd37a92010-12-19 14:05:43 +00001278 snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
Anthony Liguori7267c092011-08-20 22:09:37 -05001279 g_free(devpath);
Gleb Natapov962630f2010-12-08 13:35:09 +02001280 } else if (devpath) {
1281 bootpath = devpath;
1282 } else {
Markus Armbruster1bf6ccd2011-11-08 10:58:00 +01001283 assert(i->suffix);
Anthony Liguori7267c092011-08-20 22:09:37 -05001284 bootpath = g_strdup(i->suffix);
Gleb Natapov962630f2010-12-08 13:35:09 +02001285 }
1286
1287 if (total) {
1288 list[total-1] = '\n';
1289 }
1290 len = strlen(bootpath) + 1;
Anthony Liguori7267c092011-08-20 22:09:37 -05001291 list = g_realloc(list, total + len);
Gleb Natapov962630f2010-12-08 13:35:09 +02001292 memcpy(&list[total], bootpath, len);
1293 total += len;
Anthony Liguori7267c092011-08-20 22:09:37 -05001294 g_free(bootpath);
Gleb Natapov962630f2010-12-08 13:35:09 +02001295 }
1296
1297 *size = total;
1298
Amos Kongc8a6ae82013-03-19 14:23:27 +08001299 if (boot_strict && *size > 0) {
1300 list[total-1] = '\n';
Amos Kong46905792013-03-20 18:16:34 +08001301 list = g_realloc(list, total + 5);
1302 memcpy(&list[total], "HALT", 5);
1303 *size = total + 5;
Amos Kongc8a6ae82013-03-19 14:23:27 +08001304 }
Gleb Natapov962630f2010-12-08 13:35:09 +02001305 return list;
1306}
1307
Eduardo Habkost845e5bf2013-02-04 16:27:51 -02001308static void numa_node_parse_cpus(int nodenr, const char *cpus)
1309{
1310 char *endptr;
1311 unsigned long long value, endvalue;
1312
Eduardo Habkostc881e202013-02-04 16:27:52 -02001313 /* Empty CPU range strings will be considered valid, they will simply
1314 * not set any bit in the CPU bitmap.
1315 */
1316 if (!*cpus) {
1317 return;
Eduardo Habkost845e5bf2013-02-04 16:27:51 -02001318 }
1319
Eduardo Habkostc881e202013-02-04 16:27:52 -02001320 if (parse_uint(cpus, &value, &endptr, 10) < 0) {
1321 goto error;
1322 }
1323 if (*endptr == '-') {
1324 if (parse_uint_full(endptr + 1, &endvalue, 10) < 0) {
1325 goto error;
1326 }
1327 } else if (*endptr == '\0') {
1328 endvalue = value;
1329 } else {
1330 goto error;
1331 }
1332
1333 if (endvalue >= MAX_CPUMASK_BITS) {
Eduardo Habkost845e5bf2013-02-04 16:27:51 -02001334 endvalue = MAX_CPUMASK_BITS - 1;
1335 fprintf(stderr,
Eduardo Habkostc881e202013-02-04 16:27:52 -02001336 "qemu: NUMA: A max of %d VCPUs are supported\n",
Eduardo Habkost845e5bf2013-02-04 16:27:51 -02001337 MAX_CPUMASK_BITS);
1338 }
1339
Eduardo Habkostc881e202013-02-04 16:27:52 -02001340 if (endvalue < value) {
1341 goto error;
1342 }
1343
Eduardo Habkost845e5bf2013-02-04 16:27:51 -02001344 bitmap_set(node_cpumask[nodenr], value, endvalue-value+1);
Eduardo Habkostc881e202013-02-04 16:27:52 -02001345 return;
1346
1347error:
1348 fprintf(stderr, "qemu: Invalid NUMA CPU range: %s\n", cpus);
1349 exit(1);
Eduardo Habkost845e5bf2013-02-04 16:27:51 -02001350}
1351
aliguori268a3622009-04-21 22:30:27 +00001352static void numa_add(const char *optarg)
1353{
1354 char option[128];
1355 char *endptr;
Eduardo Habkoste4ce85b2013-02-04 16:27:49 -02001356 unsigned long long nodenr;
aliguori268a3622009-04-21 22:30:27 +00001357
Eduardo Habkost8f302cb2013-02-04 16:27:46 -02001358 optarg = get_opt_name(option, 128, optarg, ',');
1359 if (*optarg == ',') {
1360 optarg++;
1361 }
aliguori268a3622009-04-21 22:30:27 +00001362 if (!strcmp(option, "node")) {
Eduardo Habkostca4c6d32013-02-04 16:27:48 -02001363
1364 if (nb_numa_nodes >= MAX_NODES) {
1365 fprintf(stderr, "qemu: too many NUMA nodes\n");
1366 exit(1);
1367 }
1368
aliguori268a3622009-04-21 22:30:27 +00001369 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
1370 nodenr = nb_numa_nodes;
1371 } else {
Eduardo Habkost5f139962013-02-04 16:27:50 -02001372 if (parse_uint_full(option, &nodenr, 10) < 0) {
1373 fprintf(stderr, "qemu: Invalid NUMA nodeid: %s\n", option);
1374 exit(1);
1375 }
aliguori268a3622009-04-21 22:30:27 +00001376 }
1377
Eduardo Habkoste4ce85b2013-02-04 16:27:49 -02001378 if (nodenr >= MAX_NODES) {
1379 fprintf(stderr, "qemu: invalid NUMA nodeid: %llu\n", nodenr);
1380 exit(1);
1381 }
1382
aliguori268a3622009-04-21 22:30:27 +00001383 if (get_param_value(option, 128, "mem", optarg) == 0) {
1384 node_mem[nodenr] = 0;
1385 } else {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +01001386 int64_t sval;
Markus Armbrusterc03417b2011-11-22 09:46:02 +01001387 sval = strtosz(option, &endptr);
1388 if (sval < 0 || *endptr) {
Jes Sorensen9f9b17a2010-10-21 17:15:46 +02001389 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
1390 exit(1);
aliguori268a3622009-04-21 22:30:27 +00001391 }
Jes Sorensen9f9b17a2010-10-21 17:15:46 +02001392 node_mem[nodenr] = sval;
aliguori268a3622009-04-21 22:30:27 +00001393 }
Chegu Vinodee785fe2012-07-16 21:31:30 -07001394 if (get_param_value(option, 128, "cpus", optarg) != 0) {
Eduardo Habkost845e5bf2013-02-04 16:27:51 -02001395 numa_node_parse_cpus(nodenr, option);
aliguori268a3622009-04-21 22:30:27 +00001396 }
1397 nb_numa_nodes++;
Eduardo Habkost12e53a92013-02-04 16:27:47 -02001398 } else {
1399 fprintf(stderr, "Invalid -numa option: %s\n", option);
1400 exit(1);
aliguori268a3622009-04-21 22:30:27 +00001401 }
aliguori268a3622009-04-21 22:30:27 +00001402}
1403
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001404static void smp_parse(const char *optarg)
1405{
1406 int smp, sockets = 0, threads = 0, cores = 0;
1407 char *endptr;
1408 char option[128];
1409
1410 smp = strtoul(optarg, &endptr, 10);
1411 if (endptr != optarg) {
1412 if (*endptr == ',') {
1413 endptr++;
1414 }
1415 }
1416 if (get_param_value(option, 128, "sockets", endptr) != 0)
1417 sockets = strtoull(option, NULL, 10);
1418 if (get_param_value(option, 128, "cores", endptr) != 0)
1419 cores = strtoull(option, NULL, 10);
1420 if (get_param_value(option, 128, "threads", endptr) != 0)
1421 threads = strtoull(option, NULL, 10);
1422 if (get_param_value(option, 128, "maxcpus", endptr) != 0)
1423 max_cpus = strtoull(option, NULL, 10);
1424
1425 /* compute missing values, prefer sockets over cores over threads */
1426 if (smp == 0 || sockets == 0) {
1427 sockets = sockets > 0 ? sockets : 1;
1428 cores = cores > 0 ? cores : 1;
1429 threads = threads > 0 ? threads : 1;
1430 if (smp == 0) {
1431 smp = cores * threads * sockets;
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001432 }
1433 } else {
1434 if (cores == 0) {
1435 threads = threads > 0 ? threads : 1;
1436 cores = smp / (sockets * threads);
1437 } else {
Joel Schoppdca98162010-07-21 15:05:17 -05001438 threads = smp / (cores * sockets);
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001439 }
1440 }
1441 smp_cpus = smp;
1442 smp_cores = cores > 0 ? cores : 1;
1443 smp_threads = threads > 0 ? threads : 1;
1444 if (max_cpus == 0)
1445 max_cpus = smp_cpus;
1446}
1447
Satoru Moriya888a6bc2013-04-19 16:42:06 +02001448static void configure_realtime(QemuOpts *opts)
1449{
1450 bool enable_mlock;
1451
1452 enable_mlock = qemu_opt_get_bool(opts, "mlock", true);
1453
1454 if (enable_mlock) {
1455 if (os_mlock() < 0) {
1456 fprintf(stderr, "qemu: locking memory failed\n");
1457 exit(1);
1458 }
1459 }
1460}
1461
bellard330d0412003-07-26 18:11:40 +00001462/***********************************************************/
bellarda594cfb2005-11-06 16:13:29 +00001463/* USB devices */
1464
Markus Armbrusterfb080002010-05-28 15:38:44 +02001465static int usb_device_add(const char *devname)
bellarda594cfb2005-11-06 16:13:29 +00001466{
1467 const char *p;
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001468 USBDevice *dev = NULL;
bellarda594cfb2005-11-06 16:13:29 +00001469
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00001470 if (!usb_enabled(false)) {
bellarda594cfb2005-11-06 16:13:29 +00001471 return -1;
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00001472 }
bellarda594cfb2005-11-06 16:13:29 +00001473
Gerd Hoffmann0958b4c2009-10-26 15:56:45 +01001474 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1475 dev = usbdevice_create(devname);
1476 if (dev)
1477 goto done;
1478
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001479 /* the other ones */
Gerd Hoffmanne447fc62011-06-01 14:41:59 +02001480#ifndef CONFIG_LINUX
1481 /* only the linux version is qdev-ified, usb-bsd still needs this */
bellarda594cfb2005-11-06 16:13:29 +00001482 if (strstart(devname, "host:", &p)) {
Jan Kiszka37417152012-02-27 15:18:47 +01001483 dev = usb_host_device_open(usb_bus_find(-1), p);
Gerd Hoffmanne447fc62011-06-01 14:41:59 +02001484 } else
1485#endif
1486 if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
Jan Kiszka37417152012-02-27 15:18:47 +01001487 dev = usb_bt_init(usb_bus_find(-1),
1488 devname[2] ? hci_init(p)
1489 : bt_new_hci(qemu_find_bt_vlan(0)));
bellarda594cfb2005-11-06 16:13:29 +00001490 } else {
1491 return -1;
1492 }
pbrook0d92ed32006-05-21 16:30:15 +00001493 if (!dev)
1494 return -1;
1495
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001496done:
bellarda594cfb2005-11-06 16:13:29 +00001497 return 0;
1498}
1499
aliguori1f3870a2008-08-21 19:27:48 +00001500static int usb_device_del(const char *devname)
1501{
1502 int bus_num, addr;
1503 const char *p;
1504
Gerd Hoffmann1a3973b2012-11-30 13:02:47 +01001505 if (strstart(devname, "host:", &p)) {
1506 return -1;
1507 }
aliguori5d0c5752008-09-14 01:07:41 +00001508
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00001509 if (!usb_enabled(false)) {
aliguori1f3870a2008-08-21 19:27:48 +00001510 return -1;
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00001511 }
aliguori1f3870a2008-08-21 19:27:48 +00001512
1513 p = strchr(devname, '.');
1514 if (!p)
1515 return -1;
1516 bus_num = strtoul(devname, NULL, 0);
1517 addr = strtoul(p + 1, NULL, 0);
1518
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001519 return usb_device_delete_addr(bus_num, addr);
aliguori1f3870a2008-08-21 19:27:48 +00001520}
1521
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001522static int usb_parse(const char *cmdline)
1523{
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001524 int r;
Markus Armbrusterfb080002010-05-28 15:38:44 +02001525 r = usb_device_add(cmdline);
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001526 if (r < 0) {
1527 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
1528 }
1529 return r;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001530}
1531
Luiz Capitulinod54908a2009-08-28 15:27:13 -03001532void do_usb_add(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +00001533{
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001534 const char *devname = qdict_get_str(qdict, "devname");
Markus Armbrusterfb080002010-05-28 15:38:44 +02001535 if (usb_device_add(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +01001536 error_report("could not add USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001537 }
bellarda594cfb2005-11-06 16:13:29 +00001538}
1539
Luiz Capitulinod54908a2009-08-28 15:27:13 -03001540void do_usb_del(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +00001541{
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001542 const char *devname = qdict_get_str(qdict, "devname");
1543 if (usb_device_del(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +01001544 error_report("could not delete USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001545 }
bellarda594cfb2005-11-06 16:13:29 +00001546}
1547
bellardf7cce892004-12-08 22:21:25 +00001548/***********************************************************/
balrog201a51f2007-04-30 00:51:09 +00001549/* PCMCIA/Cardbus */
1550
1551static struct pcmcia_socket_entry_s {
Paul Brookbc24a222009-05-10 01:44:56 +01001552 PCMCIASocket *socket;
balrog201a51f2007-04-30 00:51:09 +00001553 struct pcmcia_socket_entry_s *next;
1554} *pcmcia_sockets = 0;
1555
Paul Brookbc24a222009-05-10 01:44:56 +01001556void pcmcia_socket_register(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +00001557{
1558 struct pcmcia_socket_entry_s *entry;
1559
Anthony Liguori7267c092011-08-20 22:09:37 -05001560 entry = g_malloc(sizeof(struct pcmcia_socket_entry_s));
balrog201a51f2007-04-30 00:51:09 +00001561 entry->socket = socket;
1562 entry->next = pcmcia_sockets;
1563 pcmcia_sockets = entry;
1564}
1565
Paul Brookbc24a222009-05-10 01:44:56 +01001566void pcmcia_socket_unregister(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +00001567{
1568 struct pcmcia_socket_entry_s *entry, **ptr;
1569
1570 ptr = &pcmcia_sockets;
1571 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1572 if (entry->socket == socket) {
1573 *ptr = entry->next;
Anthony Liguori7267c092011-08-20 22:09:37 -05001574 g_free(entry);
balrog201a51f2007-04-30 00:51:09 +00001575 }
1576}
1577
Wenchao Xia84f2d0e2013-01-14 14:06:25 +08001578void pcmcia_info(Monitor *mon, const QDict *qdict)
balrog201a51f2007-04-30 00:51:09 +00001579{
1580 struct pcmcia_socket_entry_s *iter;
aliguori376253e2009-03-05 23:01:23 +00001581
balrog201a51f2007-04-30 00:51:09 +00001582 if (!pcmcia_sockets)
aliguori376253e2009-03-05 23:01:23 +00001583 monitor_printf(mon, "No PCMCIA sockets\n");
balrog201a51f2007-04-30 00:51:09 +00001584
1585 for (iter = pcmcia_sockets; iter; iter = iter->next)
aliguori376253e2009-03-05 23:01:23 +00001586 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1587 iter->socket->attached ? iter->socket->card_string :
1588 "Empty");
balrog201a51f2007-04-30 00:51:09 +00001589}
1590
1591/***********************************************************/
bellardcc1daa42005-06-05 14:49:17 +00001592/* machine registration */
1593
blueswir1bdaf78e2008-10-04 07:24:27 +00001594static QEMUMachine *first_machine = NULL;
aliguori6f338c32009-02-11 15:21:54 +00001595QEMUMachine *current_machine = NULL;
bellardcc1daa42005-06-05 14:49:17 +00001596
1597int qemu_register_machine(QEMUMachine *m)
1598{
1599 QEMUMachine **pm;
1600 pm = &first_machine;
1601 while (*pm != NULL)
1602 pm = &(*pm)->next;
1603 m->next = NULL;
1604 *pm = m;
1605 return 0;
1606}
1607
pbrook9596ebb2007-11-18 01:44:38 +00001608static QEMUMachine *find_machine(const char *name)
bellardcc1daa42005-06-05 14:49:17 +00001609{
1610 QEMUMachine *m;
1611
1612 for(m = first_machine; m != NULL; m = m->next) {
1613 if (!strcmp(m->name, name))
1614 return m;
Mark McLoughlin3f6599e2009-07-22 10:02:50 +01001615 if (m->alias && !strcmp(m->alias, name))
1616 return m;
bellardcc1daa42005-06-05 14:49:17 +00001617 }
1618 return NULL;
1619}
1620
Jordan Justen2c8cffa2012-02-21 23:18:50 -08001621QEMUMachine *find_default_machine(void)
Anthony Liguori0c257432009-05-21 20:41:01 -05001622{
1623 QEMUMachine *m;
1624
1625 for(m = first_machine; m != NULL; m = m->next) {
1626 if (m->is_default) {
1627 return m;
1628 }
1629 }
1630 return NULL;
1631}
1632
Anthony Liguori01d3c802012-08-10 11:04:11 -05001633MachineInfoList *qmp_query_machines(Error **errp)
1634{
1635 MachineInfoList *mach_list = NULL;
1636 QEMUMachine *m;
1637
1638 for (m = first_machine; m; m = m->next) {
1639 MachineInfoList *entry;
1640 MachineInfo *info;
1641
1642 info = g_malloc0(sizeof(*info));
1643 if (m->is_default) {
1644 info->has_is_default = true;
1645 info->is_default = true;
1646 }
1647
1648 if (m->alias) {
1649 info->has_alias = true;
1650 info->alias = g_strdup(m->alias);
1651 }
1652
1653 info->name = g_strdup(m->name);
Michal Novotnyc72e7682013-04-08 18:21:02 +02001654 info->cpu_max = !m->max_cpus ? 1 : m->max_cpus;
Anthony Liguori01d3c802012-08-10 11:04:11 -05001655
1656 entry = g_malloc0(sizeof(*entry));
1657 entry->value = info;
1658 entry->next = mach_list;
1659 mach_list = entry;
1660 }
1661
1662 return mach_list;
1663}
1664
bellardcc1daa42005-06-05 14:49:17 +00001665/***********************************************************/
bellard8a7ddc32004-03-31 19:00:16 +00001666/* main execution loop */
1667
bellard0bd48852005-11-11 00:00:47 +00001668struct vm_change_state_entry {
1669 VMChangeStateHandler *cb;
1670 void *opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001671 QLIST_ENTRY (vm_change_state_entry) entries;
bellard0bd48852005-11-11 00:00:47 +00001672};
1673
Blue Swirl72cf2d42009-09-12 07:36:22 +00001674static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
bellard0bd48852005-11-11 00:00:47 +00001675
1676VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1677 void *opaque)
1678{
1679 VMChangeStateEntry *e;
1680
Anthony Liguori7267c092011-08-20 22:09:37 -05001681 e = g_malloc0(sizeof (*e));
bellard0bd48852005-11-11 00:00:47 +00001682
1683 e->cb = cb;
1684 e->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001685 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
bellard0bd48852005-11-11 00:00:47 +00001686 return e;
1687}
1688
1689void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1690{
Blue Swirl72cf2d42009-09-12 07:36:22 +00001691 QLIST_REMOVE (e, entries);
Anthony Liguori7267c092011-08-20 22:09:37 -05001692 g_free (e);
bellard0bd48852005-11-11 00:00:47 +00001693}
1694
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001695void vm_state_notify(int running, RunState state)
bellard0bd48852005-11-11 00:00:47 +00001696{
1697 VMChangeStateEntry *e;
1698
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001699 trace_vm_state_notify(running, state);
Stefan Hajnoczi94b0b5f2010-11-16 12:20:25 +00001700
bellard0bd48852005-11-11 00:00:47 +00001701 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001702 e->cb(e->opaque, running, state);
bellard0bd48852005-11-11 00:00:47 +00001703 }
1704}
1705
bellard8a7ddc32004-03-31 19:00:16 +00001706void vm_start(void)
1707{
Luiz Capitulino13548692011-07-29 15:36:43 -03001708 if (!runstate_is_running()) {
bellard8a7ddc32004-03-31 19:00:16 +00001709 cpu_enable_ticks();
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001710 runstate_set(RUN_STATE_RUNNING);
1711 vm_state_notify(1, RUN_STATE_RUNNING);
aliguorid6dc3d42009-04-24 18:04:07 +00001712 resume_all_vcpus();
Luiz Capitulino6ed2c482010-04-27 20:35:59 -03001713 monitor_protocol_event(QEVENT_RESUME, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00001714 }
1715}
1716
bellardbb0c6722004-06-20 12:37:32 +00001717/* reset/shutdown handler */
1718
1719typedef struct QEMUResetEntry {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001720 QTAILQ_ENTRY(QEMUResetEntry) entry;
bellardbb0c6722004-06-20 12:37:32 +00001721 QEMUResetHandler *func;
1722 void *opaque;
bellardbb0c6722004-06-20 12:37:32 +00001723} QEMUResetEntry;
1724
Blue Swirl72cf2d42009-09-12 07:36:22 +00001725static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1726 QTAILQ_HEAD_INITIALIZER(reset_handlers);
bellardbb0c6722004-06-20 12:37:32 +00001727static int reset_requested;
Gleb Natapovf64622c2011-03-15 13:56:04 +02001728static int shutdown_requested, shutdown_signal = -1;
1729static pid_t shutdown_pid;
bellard34751872005-07-02 14:31:34 +00001730static int powerdown_requested;
Jan Kiszka8cf71712011-02-07 12:19:16 +01001731static int debug_requested;
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001732static int suspend_requested;
Luiz Capitulino14058192012-08-08 17:29:17 -03001733static int wakeup_requested;
Igor Mammedova9552c82012-09-05 23:06:21 +02001734static NotifierList powerdown_notifiers =
1735 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001736static NotifierList suspend_notifiers =
1737 NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
1738static NotifierList wakeup_notifiers =
1739 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
1740static uint32_t wakeup_reason_mask = ~0;
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001741static RunState vmstop_requested = RUN_STATE_MAX;
bellardbb0c6722004-06-20 12:37:32 +00001742
Anthony PERARD1291eb32010-07-22 15:52:48 +01001743int qemu_shutdown_requested_get(void)
1744{
1745 return shutdown_requested;
1746}
1747
1748int qemu_reset_requested_get(void)
1749{
1750 return reset_requested;
1751}
1752
Blue Swirl4fdcac02012-10-28 11:04:47 +00001753static int qemu_shutdown_requested(void)
aurel32cf7a2fe2008-03-18 06:53:05 +00001754{
1755 int r = shutdown_requested;
1756 shutdown_requested = 0;
1757 return r;
1758}
1759
Blue Swirl4fdcac02012-10-28 11:04:47 +00001760static void qemu_kill_report(void)
Gleb Natapovf64622c2011-03-15 13:56:04 +02001761{
Anthony Liguoric7f0f3b2012-03-28 15:42:02 +02001762 if (!qtest_enabled() && shutdown_signal != -1) {
Peter Maydellf1d3fb02011-03-30 22:03:38 +01001763 fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal);
1764 if (shutdown_pid == 0) {
1765 /* This happens for eg ^C at the terminal, so it's worth
1766 * avoiding printing an odd message in that case.
1767 */
1768 fputc('\n', stderr);
1769 } else {
Andreas Färber953ffe02011-06-02 19:58:06 +02001770 fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid);
Peter Maydellf1d3fb02011-03-30 22:03:38 +01001771 }
Gleb Natapovf64622c2011-03-15 13:56:04 +02001772 shutdown_signal = -1;
1773 }
1774}
1775
Blue Swirl4fdcac02012-10-28 11:04:47 +00001776static int qemu_reset_requested(void)
aurel32cf7a2fe2008-03-18 06:53:05 +00001777{
1778 int r = reset_requested;
1779 reset_requested = 0;
1780 return r;
1781}
1782
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001783static int qemu_suspend_requested(void)
1784{
1785 int r = suspend_requested;
1786 suspend_requested = 0;
1787 return r;
1788}
1789
Luiz Capitulino14058192012-08-08 17:29:17 -03001790static int qemu_wakeup_requested(void)
1791{
1792 int r = wakeup_requested;
1793 wakeup_requested = 0;
1794 return r;
1795}
1796
Blue Swirl4fdcac02012-10-28 11:04:47 +00001797static int qemu_powerdown_requested(void)
aurel32cf7a2fe2008-03-18 06:53:05 +00001798{
1799 int r = powerdown_requested;
1800 powerdown_requested = 0;
1801 return r;
1802}
1803
aliguorie5689022009-04-24 18:03:54 +00001804static int qemu_debug_requested(void)
1805{
1806 int r = debug_requested;
1807 debug_requested = 0;
1808 return r;
1809}
1810
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001811/* We use RUN_STATE_MAX but any invalid value will do */
Luiz Capitulino0d45b702011-09-30 14:27:11 -03001812static bool qemu_vmstop_requested(RunState *r)
aliguori6e29f5d2009-04-24 18:04:02 +00001813{
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001814 if (vmstop_requested < RUN_STATE_MAX) {
Luiz Capitulino0d45b702011-09-30 14:27:11 -03001815 *r = vmstop_requested;
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001816 vmstop_requested = RUN_STATE_MAX;
Luiz Capitulino0d45b702011-09-30 14:27:11 -03001817 return true;
1818 }
1819
1820 return false;
aliguori6e29f5d2009-04-24 18:04:02 +00001821}
1822
Jan Kiszkaa08d4362009-06-27 09:25:07 +02001823void qemu_register_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001824{
Anthony Liguori7267c092011-08-20 22:09:37 -05001825 QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
bellardbb0c6722004-06-20 12:37:32 +00001826
bellardbb0c6722004-06-20 12:37:32 +00001827 re->func = func;
1828 re->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001829 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
bellardbb0c6722004-06-20 12:37:32 +00001830}
1831
Jan Kiszkadda9b292009-07-02 00:19:02 +02001832void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001833{
1834 QEMUResetEntry *re;
1835
Blue Swirl72cf2d42009-09-12 07:36:22 +00001836 QTAILQ_FOREACH(re, &reset_handlers, entry) {
Jan Kiszkadda9b292009-07-02 00:19:02 +02001837 if (re->func == func && re->opaque == opaque) {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001838 QTAILQ_REMOVE(&reset_handlers, re, entry);
Anthony Liguori7267c092011-08-20 22:09:37 -05001839 g_free(re);
Jan Kiszkadda9b292009-07-02 00:19:02 +02001840 return;
1841 }
1842 }
1843}
1844
David Gibsonbe522022012-08-07 16:41:51 +10001845void qemu_devices_reset(void)
Jan Kiszkadda9b292009-07-02 00:19:02 +02001846{
1847 QEMUResetEntry *re, *nre;
1848
1849 /* reset all devices */
Blue Swirl72cf2d42009-09-12 07:36:22 +00001850 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
bellardbb0c6722004-06-20 12:37:32 +00001851 re->func(re->opaque);
1852 }
David Gibsonbe522022012-08-07 16:41:51 +10001853}
1854
1855void qemu_system_reset(bool report)
1856{
1857 if (current_machine && current_machine->reset) {
1858 current_machine->reset();
1859 } else {
1860 qemu_devices_reset();
1861 }
Jan Kiszkae063eb12011-06-14 18:29:43 +02001862 if (report) {
1863 monitor_protocol_event(QEVENT_RESET, NULL);
1864 }
Jan Kiszkaea375f92010-03-01 19:10:30 +01001865 cpu_synchronize_all_post_reset();
bellardbb0c6722004-06-20 12:37:32 +00001866}
1867
1868void qemu_system_reset_request(void)
1869{
bellardd1beab82006-10-02 19:44:22 +00001870 if (no_reboot) {
1871 shutdown_requested = 1;
1872 } else {
1873 reset_requested = 1;
1874 }
Jan Kiszkab4a3d962011-02-01 22:15:43 +01001875 cpu_stop_current();
aliguorid9f75a42009-04-24 18:03:11 +00001876 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001877}
1878
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001879static void qemu_system_suspend(void)
1880{
1881 pause_all_vcpus();
1882 notifier_list_notify(&suspend_notifiers, NULL);
Luiz Capitulinoad02b962012-04-27 13:33:36 -03001883 runstate_set(RUN_STATE_SUSPENDED);
Gerd Hoffmann53370b72012-02-23 13:45:26 +01001884 monitor_protocol_event(QEVENT_SUSPEND, NULL);
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001885}
1886
1887void qemu_system_suspend_request(void)
1888{
Luiz Capitulino9abc62f2012-04-27 14:31:12 -03001889 if (runstate_check(RUN_STATE_SUSPENDED)) {
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001890 return;
1891 }
1892 suspend_requested = 1;
1893 cpu_stop_current();
1894 qemu_notify_event();
1895}
1896
1897void qemu_register_suspend_notifier(Notifier *notifier)
1898{
1899 notifier_list_add(&suspend_notifiers, notifier);
1900}
1901
1902void qemu_system_wakeup_request(WakeupReason reason)
1903{
Luiz Capitulino9abc62f2012-04-27 14:31:12 -03001904 if (!runstate_check(RUN_STATE_SUSPENDED)) {
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001905 return;
1906 }
1907 if (!(wakeup_reason_mask & (1 << reason))) {
1908 return;
1909 }
Luiz Capitulinoad02b962012-04-27 13:33:36 -03001910 runstate_set(RUN_STATE_RUNNING);
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001911 notifier_list_notify(&wakeup_notifiers, &reason);
Luiz Capitulino14058192012-08-08 17:29:17 -03001912 wakeup_requested = 1;
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001913 qemu_notify_event();
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001914}
1915
1916void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
1917{
1918 if (enabled) {
1919 wakeup_reason_mask |= (1 << reason);
1920 } else {
1921 wakeup_reason_mask &= ~(1 << reason);
1922 }
1923}
1924
1925void qemu_register_wakeup_notifier(Notifier *notifier)
1926{
1927 notifier_list_add(&wakeup_notifiers, notifier);
1928}
1929
Gleb Natapovf64622c2011-03-15 13:56:04 +02001930void qemu_system_killed(int signal, pid_t pid)
1931{
1932 shutdown_signal = signal;
1933 shutdown_pid = pid;
Kevin Wolfd9389b92011-09-14 15:38:40 +02001934 no_shutdown = 0;
Gleb Natapovf64622c2011-03-15 13:56:04 +02001935 qemu_system_shutdown_request();
1936}
1937
bellardbb0c6722004-06-20 12:37:32 +00001938void qemu_system_shutdown_request(void)
1939{
1940 shutdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001941 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001942}
1943
Igor Mammedov013c2f12012-09-05 23:06:25 +02001944static void qemu_system_powerdown(void)
1945{
1946 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
1947 notifier_list_notify(&powerdown_notifiers, NULL);
1948}
1949
bellard34751872005-07-02 14:31:34 +00001950void qemu_system_powerdown_request(void)
1951{
1952 powerdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001953 qemu_notify_event();
1954}
1955
Igor Mammedova9552c82012-09-05 23:06:21 +02001956void qemu_register_powerdown_notifier(Notifier *notifier)
1957{
1958 notifier_list_add(&powerdown_notifiers, notifier);
1959}
1960
Jan Kiszka8cf71712011-02-07 12:19:16 +01001961void qemu_system_debug_request(void)
1962{
1963 debug_requested = 1;
Jan Kiszka83f338f2011-02-07 12:19:17 +01001964 qemu_notify_event();
Jan Kiszka8cf71712011-02-07 12:19:16 +01001965}
1966
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001967void qemu_system_vmstop_request(RunState state)
Jan Kiszka8cf71712011-02-07 12:19:16 +01001968{
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001969 vmstop_requested = state;
Jan Kiszka8cf71712011-02-07 12:19:16 +01001970 qemu_notify_event();
1971}
1972
Paolo Bonzini99435902011-09-12 14:03:13 +02001973static bool main_loop_should_exit(void)
1974{
1975 RunState r;
1976 if (qemu_debug_requested()) {
1977 vm_stop(RUN_STATE_DEBUG);
1978 }
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001979 if (qemu_suspend_requested()) {
1980 qemu_system_suspend();
1981 }
Paolo Bonzini99435902011-09-12 14:03:13 +02001982 if (qemu_shutdown_requested()) {
1983 qemu_kill_report();
1984 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
1985 if (no_shutdown) {
1986 vm_stop(RUN_STATE_SHUTDOWN);
1987 } else {
1988 return true;
1989 }
1990 }
1991 if (qemu_reset_requested()) {
1992 pause_all_vcpus();
1993 cpu_synchronize_all_states();
1994 qemu_system_reset(VMRESET_REPORT);
1995 resume_all_vcpus();
Hu Taoede085b2013-04-26 11:24:40 +08001996 if (runstate_needs_reset()) {
Paolo Bonzini99435902011-09-12 14:03:13 +02001997 runstate_set(RUN_STATE_PAUSED);
1998 }
1999 }
Luiz Capitulino14058192012-08-08 17:29:17 -03002000 if (qemu_wakeup_requested()) {
2001 pause_all_vcpus();
2002 cpu_synchronize_all_states();
2003 qemu_system_reset(VMRESET_SILENT);
2004 resume_all_vcpus();
Luiz Capitulino17c86602012-08-09 11:27:30 -03002005 monitor_protocol_event(QEVENT_WAKEUP, NULL);
Luiz Capitulino14058192012-08-08 17:29:17 -03002006 }
Paolo Bonzini99435902011-09-12 14:03:13 +02002007 if (qemu_powerdown_requested()) {
Igor Mammedov013c2f12012-09-05 23:06:25 +02002008 qemu_system_powerdown();
Paolo Bonzini99435902011-09-12 14:03:13 +02002009 }
2010 if (qemu_vmstop_requested(&r)) {
2011 vm_stop(r);
2012 }
2013 return false;
2014}
2015
aliguori43b96852009-04-24 18:03:33 +00002016static void main_loop(void)
2017{
Jan Kiszkac9f711a2011-08-22 17:46:02 +02002018 bool nonblocking;
Paolo Bonzini99435902011-09-12 14:03:13 +02002019 int last_io = 0;
Jan Kiszka8e1b90e2011-02-01 22:15:46 +01002020#ifdef CONFIG_PROFILER
2021 int64_t ti;
2022#endif
Paolo Bonzini99435902011-09-12 14:03:13 +02002023 do {
Stefano Stabellinia7d42072013-06-03 15:38:43 +00002024 nonblocking = !kvm_enabled() && !xen_enabled() && last_io > 0;
aliguori43b96852009-04-24 18:03:33 +00002025#ifdef CONFIG_PROFILER
Jan Kiszka46481d32011-02-01 22:15:47 +01002026 ti = profile_getclock();
aliguori43b96852009-04-24 18:03:33 +00002027#endif
Jan Kiszkac9f711a2011-08-22 17:46:02 +02002028 last_io = main_loop_wait(nonblocking);
aliguori43b96852009-04-24 18:03:33 +00002029#ifdef CONFIG_PROFILER
Jan Kiszka46481d32011-02-01 22:15:47 +01002030 dev_time += profile_getclock() - ti;
aliguori43b96852009-04-24 18:03:33 +00002031#endif
Paolo Bonzini99435902011-09-12 14:03:13 +02002032 } while (!main_loop_should_exit());
bellardb4608c02003-06-27 17:34:32 +00002033}
2034
pbrook9bd7e6d2009-04-07 22:58:45 +00002035static void version(void)
2036{
Thomas Monjalonf75ca1a2010-04-28 14:42:01 +02002037 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
pbrook9bd7e6d2009-04-07 22:58:45 +00002038}
2039
ths15f82202007-06-29 23:26:08 +00002040static void help(int exitcode)
bellard0824d6f2003-06-24 13:42:40 +00002041{
Michael Ellermana3adb7a2011-12-19 17:19:31 +11002042 version();
2043 printf("usage: %s [options] [disk_image]\n\n"
2044 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
2045 error_get_progname());
2046
Michael Ellerman77bd1112011-12-19 17:19:30 +11002047#define QEMU_OPTIONS_GENERATE_HELP
2048#include "qemu-options-wrapper.h"
Michael Ellermana3adb7a2011-12-19 17:19:31 +11002049
2050 printf("\nDuring emulation, the following keys are useful:\n"
malc3f020d72010-02-08 12:04:56 +03002051 "ctrl-alt-f toggle full screen\n"
2052 "ctrl-alt-n switch to virtual console 'n'\n"
2053 "ctrl-alt toggle mouse and keyboard grab\n"
2054 "\n"
Michael Ellermana3adb7a2011-12-19 17:19:31 +11002055 "When using -nographic, press 'ctrl-a h' to get some help.\n");
2056
ths15f82202007-06-29 23:26:08 +00002057 exit(exitcode);
bellard0824d6f2003-06-24 13:42:40 +00002058}
2059
bellardcd6f1162004-05-13 22:02:20 +00002060#define HAS_ARG 0x0001
2061
bellardcd6f1162004-05-13 22:02:20 +00002062typedef struct QEMUOption {
2063 const char *name;
2064 int flags;
2065 int index;
Blue Swirlad960902010-03-29 19:23:52 +00002066 uint32_t arch_mask;
bellardcd6f1162004-05-13 22:02:20 +00002067} QEMUOption;
2068
blueswir1dbed7e42008-10-01 19:38:09 +00002069static const QEMUOption qemu_options[] = {
Blue Swirlad960902010-03-29 19:23:52 +00002070 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
Michael Ellerman77bd1112011-12-19 17:19:30 +11002071#define QEMU_OPTIONS_GENERATE_OPTIONS
2072#include "qemu-options-wrapper.h"
bellardcd6f1162004-05-13 22:02:20 +00002073 { NULL },
bellardfc01f7e2003-06-30 10:03:06 +00002074};
Blue Swirla369da52011-09-27 19:15:42 +00002075
2076static bool vga_available(void)
2077{
Aurelien Jarno36b7f272012-09-08 16:01:20 +02002078 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
Blue Swirla369da52011-09-27 19:15:42 +00002079}
2080
2081static bool cirrus_vga_available(void)
2082{
Aurelien Jarno36b7f272012-09-08 16:01:20 +02002083 return object_class_by_name("cirrus-vga")
2084 || object_class_by_name("isa-cirrus-vga");
Blue Swirla369da52011-09-27 19:15:42 +00002085}
2086
2087static bool vmware_vga_available(void)
2088{
Aurelien Jarno36b7f272012-09-08 16:01:20 +02002089 return object_class_by_name("vmware-svga");
Blue Swirla369da52011-09-27 19:15:42 +00002090}
2091
Aurelien Jarno879049a2012-09-08 12:01:06 +02002092static bool qxl_vga_available(void)
2093{
2094 return object_class_by_name("qxl-vga");
2095}
2096
malc3893c122008-09-28 00:42:05 +00002097static void select_vgahw (const char *p)
2098{
2099 const char *opts;
2100
Zachary Amsden86176752009-07-30 00:15:02 -10002101 vga_interface_type = VGA_NONE;
malc3893c122008-09-28 00:42:05 +00002102 if (strstart(p, "std", &opts)) {
Blue Swirla369da52011-09-27 19:15:42 +00002103 if (vga_available()) {
2104 vga_interface_type = VGA_STD;
2105 } else {
2106 fprintf(stderr, "Error: standard VGA not available\n");
2107 exit(0);
2108 }
malc3893c122008-09-28 00:42:05 +00002109 } else if (strstart(p, "cirrus", &opts)) {
Blue Swirla369da52011-09-27 19:15:42 +00002110 if (cirrus_vga_available()) {
2111 vga_interface_type = VGA_CIRRUS;
2112 } else {
2113 fprintf(stderr, "Error: Cirrus VGA not available\n");
2114 exit(0);
2115 }
malc3893c122008-09-28 00:42:05 +00002116 } else if (strstart(p, "vmware", &opts)) {
Blue Swirla369da52011-09-27 19:15:42 +00002117 if (vmware_vga_available()) {
2118 vga_interface_type = VGA_VMWARE;
2119 } else {
2120 fprintf(stderr, "Error: VMWare SVGA not available\n");
2121 exit(0);
2122 }
aliguori94909d92009-04-22 15:19:53 +00002123 } else if (strstart(p, "xenfb", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10002124 vga_interface_type = VGA_XENFB;
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +02002125 } else if (strstart(p, "qxl", &opts)) {
Aurelien Jarno879049a2012-09-08 12:01:06 +02002126 if (qxl_vga_available()) {
2127 vga_interface_type = VGA_QXL;
2128 } else {
2129 fprintf(stderr, "Error: QXL VGA not available\n");
2130 exit(0);
2131 }
aliguori28b85ed2009-04-22 15:19:48 +00002132 } else if (!strstart(p, "none", &opts)) {
malc3893c122008-09-28 00:42:05 +00002133 invalid_vga:
2134 fprintf(stderr, "Unknown vga type: %s\n", p);
2135 exit(1);
2136 }
malccb5a7aa2008-09-28 00:42:12 +00002137 while (*opts) {
2138 const char *nextopt;
2139
2140 if (strstart(opts, ",retrace=", &nextopt)) {
2141 opts = nextopt;
2142 if (strstart(opts, "dumb", &nextopt))
2143 vga_retrace_method = VGA_RETRACE_DUMB;
2144 else if (strstart(opts, "precise", &nextopt))
2145 vga_retrace_method = VGA_RETRACE_PRECISE;
2146 else goto invalid_vga;
2147 } else goto invalid_vga;
2148 opts = nextopt;
2149 }
malc3893c122008-09-28 00:42:05 +00002150}
2151
Jes Sorensen1472a952011-03-16 13:33:31 +01002152static DisplayType select_display(const char *p)
2153{
2154 const char *opts;
2155 DisplayType display = DT_DEFAULT;
2156
2157 if (strstart(p, "sdl", &opts)) {
2158#ifdef CONFIG_SDL
2159 display = DT_SDL;
2160 while (*opts) {
2161 const char *nextopt;
2162
2163 if (strstart(opts, ",frame=", &nextopt)) {
2164 opts = nextopt;
2165 if (strstart(opts, "on", &nextopt)) {
2166 no_frame = 0;
2167 } else if (strstart(opts, "off", &nextopt)) {
2168 no_frame = 1;
2169 } else {
Peter Maydell05175532011-03-23 03:40:57 +00002170 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01002171 }
2172 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
2173 opts = nextopt;
2174 if (strstart(opts, "on", &nextopt)) {
2175 alt_grab = 1;
2176 } else if (strstart(opts, "off", &nextopt)) {
2177 alt_grab = 0;
2178 } else {
Peter Maydell05175532011-03-23 03:40:57 +00002179 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01002180 }
2181 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
2182 opts = nextopt;
2183 if (strstart(opts, "on", &nextopt)) {
2184 ctrl_grab = 1;
2185 } else if (strstart(opts, "off", &nextopt)) {
2186 ctrl_grab = 0;
2187 } else {
Peter Maydell05175532011-03-23 03:40:57 +00002188 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01002189 }
2190 } else if (strstart(opts, ",window_close=", &nextopt)) {
2191 opts = nextopt;
2192 if (strstart(opts, "on", &nextopt)) {
2193 no_quit = 0;
2194 } else if (strstart(opts, "off", &nextopt)) {
2195 no_quit = 1;
2196 } else {
Peter Maydell05175532011-03-23 03:40:57 +00002197 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01002198 }
2199 } else {
Peter Maydell05175532011-03-23 03:40:57 +00002200 invalid_sdl_args:
2201 fprintf(stderr, "Invalid SDL option string: %s\n", p);
2202 exit(1);
Jes Sorensen1472a952011-03-16 13:33:31 +01002203 }
2204 opts = nextopt;
2205 }
2206#else
2207 fprintf(stderr, "SDL support is disabled\n");
2208 exit(1);
2209#endif
Jes Sorensen3264ff12011-03-16 13:33:33 +01002210 } else if (strstart(p, "vnc", &opts)) {
Jes Sorensen821601e2011-03-16 13:33:36 +01002211#ifdef CONFIG_VNC
Jes Sorensen3264ff12011-03-16 13:33:33 +01002212 display_remote++;
2213
2214 if (*opts) {
2215 const char *nextopt;
2216
2217 if (strstart(opts, "=", &nextopt)) {
2218 vnc_display = nextopt;
2219 }
2220 }
2221 if (!vnc_display) {
2222 fprintf(stderr, "VNC requires a display argument vnc=<display>\n");
2223 exit(1);
2224 }
Jes Sorensen821601e2011-03-16 13:33:36 +01002225#else
2226 fprintf(stderr, "VNC support is disabled\n");
2227 exit(1);
2228#endif
Jes Sorensen1472a952011-03-16 13:33:31 +01002229 } else if (strstart(p, "curses", &opts)) {
2230#ifdef CONFIG_CURSES
2231 display = DT_CURSES;
2232#else
2233 fprintf(stderr, "Curses support is disabled\n");
2234 exit(1);
2235#endif
Anthony Liguori15546422013-02-20 07:43:25 -06002236 } else if (strstart(p, "gtk", &opts)) {
2237#ifdef CONFIG_GTK
2238 display = DT_GTK;
2239#else
2240 fprintf(stderr, "GTK support is disabled\n");
2241 exit(1);
2242#endif
Jes Sorensen4171d322011-03-16 13:33:32 +01002243 } else if (strstart(p, "none", &opts)) {
2244 display = DT_NONE;
Jes Sorensen1472a952011-03-16 13:33:31 +01002245 } else {
Jes Sorensen1472a952011-03-16 13:33:31 +01002246 fprintf(stderr, "Unknown display type: %s\n", p);
2247 exit(1);
2248 }
2249
2250 return display;
2251}
2252
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02002253static int balloon_parse(const char *arg)
2254{
Gerd Hoffmann382f0742009-08-14 10:34:22 +02002255 QemuOpts *opts;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02002256
Gerd Hoffmann382f0742009-08-14 10:34:22 +02002257 if (strcmp(arg, "none") == 0) {
2258 return 0;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02002259 }
Gerd Hoffmann382f0742009-08-14 10:34:22 +02002260
2261 if (!strncmp(arg, "virtio", 6)) {
2262 if (arg[6] == ',') {
2263 /* have params -> parse them */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002264 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
Gerd Hoffmann382f0742009-08-14 10:34:22 +02002265 if (!opts)
2266 return -1;
2267 } else {
2268 /* create empty opts */
Dong Xu Wange478b442012-12-06 14:47:22 +08002269 opts = qemu_opts_create_nofail(qemu_find_opts("device"));
Gerd Hoffmann382f0742009-08-14 10:34:22 +02002270 }
Alexander Graf29f82b32011-03-29 15:29:29 +02002271 qemu_opt_set(opts, "driver", "virtio-balloon");
Gerd Hoffmann382f0742009-08-14 10:34:22 +02002272 return 0;
2273 }
2274
2275 return -1;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02002276}
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02002277
Paul Brook5cea8592009-05-30 00:52:44 +01002278char *qemu_find_file(int type, const char *name)
2279{
Gerd Hoffmann45240512013-03-08 11:42:24 +01002280 int i;
Paul Brook5cea8592009-05-30 00:52:44 +01002281 const char *subdir;
2282 char *buf;
2283
Peter Maydell31783202012-05-25 13:07:01 +01002284 /* Try the name as a straight path first */
2285 if (access(name, R_OK) == 0) {
Gerd Hoffmann45240512013-03-08 11:42:24 +01002286 trace_load_file(name, name);
Anthony Liguori7267c092011-08-20 22:09:37 -05002287 return g_strdup(name);
Paul Brook5cea8592009-05-30 00:52:44 +01002288 }
Gerd Hoffmann45240512013-03-08 11:42:24 +01002289
Paul Brook5cea8592009-05-30 00:52:44 +01002290 switch (type) {
2291 case QEMU_FILE_TYPE_BIOS:
2292 subdir = "";
2293 break;
2294 case QEMU_FILE_TYPE_KEYMAP:
2295 subdir = "keymaps/";
2296 break;
2297 default:
2298 abort();
2299 }
Gerd Hoffmann45240512013-03-08 11:42:24 +01002300
2301 for (i = 0; i < data_dir_idx; i++) {
2302 buf = g_strdup_printf("%s/%s%s", data_dir[i], subdir, name);
2303 if (access(buf, R_OK) == 0) {
2304 trace_load_file(name, buf);
2305 return buf;
2306 }
Anthony Liguori7267c092011-08-20 22:09:37 -05002307 g_free(buf);
Paul Brook5cea8592009-05-30 00:52:44 +01002308 }
Gerd Hoffmann45240512013-03-08 11:42:24 +01002309 return NULL;
Paul Brook5cea8592009-05-30 00:52:44 +01002310}
2311
Markus Armbrusterff952ba2010-01-29 19:48:57 +01002312static int device_help_func(QemuOpts *opts, void *opaque)
2313{
2314 return qdev_device_help(opts);
2315}
2316
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02002317static int device_init_func(QemuOpts *opts, void *opaque)
2318{
2319 DeviceState *dev;
2320
2321 dev = qdev_device_add(opts);
2322 if (!dev)
2323 return -1;
Paolo Bonzinib09995a2013-01-25 14:12:37 +01002324 object_unref(OBJECT(dev));
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02002325 return 0;
2326}
2327
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002328static int chardev_init_func(QemuOpts *opts, void *opaque)
2329{
Gerd Hoffmannbd2d80b2012-10-15 09:28:05 +02002330 Error *local_err = NULL;
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002331
Gerd Hoffmannbd2d80b2012-10-15 09:28:05 +02002332 qemu_chr_new_from_opts(opts, NULL, &local_err);
2333 if (error_is_set(&local_err)) {
2334 fprintf(stderr, "%s\n", error_get_pretty(local_err));
2335 error_free(local_err);
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002336 return -1;
Gerd Hoffmannbd2d80b2012-10-15 09:28:05 +02002337 }
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002338 return 0;
2339}
2340
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07002341#ifdef CONFIG_VIRTFS
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302342static int fsdev_init_func(QemuOpts *opts, void *opaque)
2343{
2344 int ret;
2345 ret = qemu_fsdev_add(opts);
2346
2347 return ret;
2348}
2349#endif
2350
Gerd Hoffmann88589342009-12-08 13:11:50 +01002351static int mon_init_func(QemuOpts *opts, void *opaque)
2352{
2353 CharDriverState *chr;
2354 const char *chardev;
2355 const char *mode;
2356 int flags;
2357
2358 mode = qemu_opt_get(opts, "mode");
2359 if (mode == NULL) {
2360 mode = "readline";
2361 }
2362 if (strcmp(mode, "readline") == 0) {
2363 flags = MONITOR_USE_READLINE;
2364 } else if (strcmp(mode, "control") == 0) {
2365 flags = MONITOR_USE_CONTROL;
2366 } else {
2367 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
2368 exit(1);
2369 }
2370
Daniel P. Berrange39eaab92010-06-07 15:42:31 +01002371 if (qemu_opt_get_bool(opts, "pretty", 0))
2372 flags |= MONITOR_USE_PRETTY;
2373
Gerd Hoffmann88589342009-12-08 13:11:50 +01002374 if (qemu_opt_get_bool(opts, "default", 0))
2375 flags |= MONITOR_IS_DEFAULT;
2376
2377 chardev = qemu_opt_get(opts, "chardev");
2378 chr = qemu_chr_find(chardev);
2379 if (chr == NULL) {
2380 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
2381 exit(1);
2382 }
2383
Hans de Goede456d6062013-03-27 20:29:40 +01002384 qemu_chr_fe_claim_no_fail(chr);
Gerd Hoffmann88589342009-12-08 13:11:50 +01002385 monitor_init(chr, flags);
2386 return 0;
2387}
2388
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002389static void monitor_parse(const char *optarg, const char *mode)
Gerd Hoffmann88589342009-12-08 13:11:50 +01002390{
2391 static int monitor_device_index = 0;
2392 QemuOpts *opts;
2393 const char *p;
2394 char label[32];
2395 int def = 0;
2396
2397 if (strstart(optarg, "chardev:", &p)) {
2398 snprintf(label, sizeof(label), "%s", p);
2399 } else {
Jan Kiszka140e0652010-04-06 16:55:52 +02002400 snprintf(label, sizeof(label), "compat_monitor%d",
2401 monitor_device_index);
2402 if (monitor_device_index == 0) {
Gerd Hoffmann88589342009-12-08 13:11:50 +01002403 def = 1;
2404 }
2405 opts = qemu_chr_parse_compat(label, optarg);
2406 if (!opts) {
2407 fprintf(stderr, "parse error: %s\n", optarg);
2408 exit(1);
2409 }
2410 }
2411
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03002412 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, NULL);
Gerd Hoffmann88589342009-12-08 13:11:50 +01002413 if (!opts) {
2414 fprintf(stderr, "duplicate chardev: %s\n", label);
2415 exit(1);
2416 }
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002417 qemu_opt_set(opts, "mode", mode);
Gerd Hoffmann88589342009-12-08 13:11:50 +01002418 qemu_opt_set(opts, "chardev", label);
2419 if (def)
2420 qemu_opt_set(opts, "default", "on");
2421 monitor_device_index++;
2422}
2423
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002424struct device_config {
2425 enum {
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002426 DEV_USB, /* -usbdevice */
2427 DEV_BT, /* -bt */
2428 DEV_SERIAL, /* -serial */
2429 DEV_PARALLEL, /* -parallel */
2430 DEV_VIRTCON, /* -virtioconsole */
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002431 DEV_DEBUGCON, /* -debugcon */
Markus Armbrusteref0c4a02012-02-07 15:09:13 +01002432 DEV_GDB, /* -gdb, -s */
Alexander Graf3ef669e2013-01-24 12:18:52 +01002433 DEV_SCLP, /* s390 sclp */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002434 } type;
2435 const char *cmdline;
Markus Armbrusterd9a59542012-02-07 15:09:12 +01002436 Location loc;
Blue Swirl72cf2d42009-09-12 07:36:22 +00002437 QTAILQ_ENTRY(device_config) next;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002438};
Blue Swirl4fdcac02012-10-28 11:04:47 +00002439
2440static QTAILQ_HEAD(, device_config) device_configs =
2441 QTAILQ_HEAD_INITIALIZER(device_configs);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002442
2443static void add_device_config(int type, const char *cmdline)
2444{
2445 struct device_config *conf;
2446
Anthony Liguori7267c092011-08-20 22:09:37 -05002447 conf = g_malloc0(sizeof(*conf));
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002448 conf->type = type;
2449 conf->cmdline = cmdline;
Markus Armbrusterd9a59542012-02-07 15:09:12 +01002450 loc_save(&conf->loc);
Blue Swirl72cf2d42009-09-12 07:36:22 +00002451 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002452}
2453
2454static int foreach_device_config(int type, int (*func)(const char *cmdline))
2455{
2456 struct device_config *conf;
2457 int rc;
2458
Blue Swirl72cf2d42009-09-12 07:36:22 +00002459 QTAILQ_FOREACH(conf, &device_configs, next) {
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002460 if (conf->type != type)
2461 continue;
Markus Armbrusterd9a59542012-02-07 15:09:12 +01002462 loc_push_restore(&conf->loc);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002463 rc = func(conf->cmdline);
Markus Armbrusterd9a59542012-02-07 15:09:12 +01002464 loc_pop(&conf->loc);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002465 if (0 != rc)
2466 return rc;
2467 }
2468 return 0;
2469}
2470
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002471static int serial_parse(const char *devname)
2472{
2473 static int index = 0;
2474 char label[32];
2475
2476 if (strcmp(devname, "none") == 0)
2477 return 0;
2478 if (index == MAX_SERIAL_PORTS) {
2479 fprintf(stderr, "qemu: too many serial ports\n");
2480 exit(1);
2481 }
2482 snprintf(label, sizeof(label), "serial%d", index);
Anthony Liguori27143a42011-08-15 11:17:36 -05002483 serial_hds[index] = qemu_chr_new(label, devname, NULL);
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002484 if (!serial_hds[index]) {
Peter Maydell52d06132012-07-09 04:28:30 +00002485 fprintf(stderr, "qemu: could not connect serial device"
2486 " to character backend '%s'\n", devname);
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002487 return -1;
2488 }
2489 index++;
2490 return 0;
2491}
2492
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002493static int parallel_parse(const char *devname)
2494{
2495 static int index = 0;
2496 char label[32];
2497
2498 if (strcmp(devname, "none") == 0)
2499 return 0;
2500 if (index == MAX_PARALLEL_PORTS) {
2501 fprintf(stderr, "qemu: too many parallel ports\n");
2502 exit(1);
2503 }
2504 snprintf(label, sizeof(label), "parallel%d", index);
Anthony Liguori27143a42011-08-15 11:17:36 -05002505 parallel_hds[index] = qemu_chr_new(label, devname, NULL);
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002506 if (!parallel_hds[index]) {
Peter Maydell52d06132012-07-09 04:28:30 +00002507 fprintf(stderr, "qemu: could not connect parallel device"
2508 " to character backend '%s'\n", devname);
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002509 return -1;
2510 }
2511 index++;
2512 return 0;
2513}
2514
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002515static int virtcon_parse(const char *devname)
2516{
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002517 QemuOptsList *device = qemu_find_opts("device");
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002518 static int index = 0;
2519 char label[32];
Amit Shah392ecf52010-01-21 16:19:23 +05302520 QemuOpts *bus_opts, *dev_opts;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002521
2522 if (strcmp(devname, "none") == 0)
2523 return 0;
2524 if (index == MAX_VIRTIO_CONSOLES) {
2525 fprintf(stderr, "qemu: too many virtio consoles\n");
2526 exit(1);
2527 }
Amit Shah392ecf52010-01-21 16:19:23 +05302528
Dong Xu Wange478b442012-12-06 14:47:22 +08002529 bus_opts = qemu_opts_create_nofail(device);
Anthony Liguorie87f7fc2012-02-06 11:07:18 -06002530 if (arch_type == QEMU_ARCH_S390X) {
2531 qemu_opt_set(bus_opts, "driver", "virtio-serial-s390");
2532 } else {
2533 qemu_opt_set(bus_opts, "driver", "virtio-serial-pci");
Laszlo Ersek4d8b3c62013-03-21 00:23:13 +01002534 }
Amit Shah392ecf52010-01-21 16:19:23 +05302535
Dong Xu Wange478b442012-12-06 14:47:22 +08002536 dev_opts = qemu_opts_create_nofail(device);
Amit Shah392ecf52010-01-21 16:19:23 +05302537 qemu_opt_set(dev_opts, "driver", "virtconsole");
2538
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002539 snprintf(label, sizeof(label), "virtcon%d", index);
Anthony Liguori27143a42011-08-15 11:17:36 -05002540 virtcon_hds[index] = qemu_chr_new(label, devname, NULL);
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002541 if (!virtcon_hds[index]) {
Peter Maydell52d06132012-07-09 04:28:30 +00002542 fprintf(stderr, "qemu: could not connect virtio console"
2543 " to character backend '%s'\n", devname);
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002544 return -1;
2545 }
Amit Shah392ecf52010-01-21 16:19:23 +05302546 qemu_opt_set(dev_opts, "chardev", label);
2547
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002548 index++;
2549 return 0;
2550}
2551
Alexander Graf3ef669e2013-01-24 12:18:52 +01002552static int sclp_parse(const char *devname)
2553{
2554 QemuOptsList *device = qemu_find_opts("device");
2555 static int index = 0;
2556 char label[32];
2557 QemuOpts *dev_opts;
2558
2559 if (strcmp(devname, "none") == 0) {
2560 return 0;
2561 }
2562 if (index == MAX_SCLP_CONSOLES) {
2563 fprintf(stderr, "qemu: too many sclp consoles\n");
2564 exit(1);
2565 }
2566
2567 assert(arch_type == QEMU_ARCH_S390X);
2568
2569 dev_opts = qemu_opts_create(device, NULL, 0, NULL);
2570 qemu_opt_set(dev_opts, "driver", "sclpconsole");
2571
2572 snprintf(label, sizeof(label), "sclpcon%d", index);
2573 sclp_hds[index] = qemu_chr_new(label, devname, NULL);
2574 if (!sclp_hds[index]) {
2575 fprintf(stderr, "qemu: could not connect sclp console"
2576 " to character backend '%s'\n", devname);
2577 return -1;
2578 }
2579 qemu_opt_set(dev_opts, "chardev", label);
2580
2581 index++;
2582 return 0;
2583}
2584
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002585static int debugcon_parse(const char *devname)
Laszlo Ersek4d8b3c62013-03-21 00:23:13 +01002586{
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002587 QemuOpts *opts;
2588
Anthony Liguori27143a42011-08-15 11:17:36 -05002589 if (!qemu_chr_new("debugcon", devname, NULL)) {
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002590 exit(1);
2591 }
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03002592 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL);
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002593 if (!opts) {
2594 fprintf(stderr, "qemu: already have a debugcon device\n");
2595 exit(1);
2596 }
2597 qemu_opt_set(opts, "driver", "isa-debugcon");
2598 qemu_opt_set(opts, "chardev", "debugcon");
2599 return 0;
2600}
2601
Jan Kiszka9052ea62011-07-23 12:38:37 +02002602static QEMUMachine *machine_parse(const char *name)
2603{
2604 QEMUMachine *m, *machine = NULL;
2605
2606 if (name) {
2607 machine = find_machine(name);
2608 }
2609 if (machine) {
2610 return machine;
2611 }
2612 printf("Supported machines are:\n");
2613 for (m = first_machine; m != NULL; m = m->next) {
2614 if (m->alias) {
Peter Maydell3b264862012-02-22 22:13:11 +00002615 printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name);
Jan Kiszka9052ea62011-07-23 12:38:37 +02002616 }
Peter Maydell3b264862012-02-22 22:13:11 +00002617 printf("%-20s %s%s\n", m->name, m->desc,
Jan Kiszka9052ea62011-07-23 12:38:37 +02002618 m->is_default ? " (default)" : "");
2619 }
Peter Maydellc8057f92012-08-02 13:45:54 +01002620 exit(!name || !is_help_option(name));
Jan Kiszka9052ea62011-07-23 12:38:37 +02002621}
2622
Anthony PERARD303d4e82010-09-21 20:05:31 +01002623static int tcg_init(void)
2624{
Jan Kiszkad5ab9712011-08-02 16:10:21 +02002625 tcg_exec_init(tcg_tb_size * 1024 * 1024);
Anthony PERARD303d4e82010-09-21 20:05:31 +01002626 return 0;
2627}
2628
2629static struct {
2630 const char *opt_name;
2631 const char *name;
2632 int (*available)(void);
2633 int (*init)(void);
liguangd5286af2013-01-24 13:03:27 +08002634 bool *allowed;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002635} accel_list[] = {
2636 { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
Anthony PERARD3285cf42010-08-19 12:27:56 +01002637 { "xen", "Xen", xen_available, xen_init, &xen_allowed },
Anthony PERARD303d4e82010-09-21 20:05:31 +01002638 { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
Anthony Liguoric7f0f3b2012-03-28 15:42:02 +02002639 { "qtest", "QTest", qtest_available, qtest_init, &qtest_allowed },
Anthony PERARD303d4e82010-09-21 20:05:31 +01002640};
2641
2642static int configure_accelerator(void)
2643{
2644 const char *p = NULL;
2645 char buf[10];
2646 int i, ret;
liguang217e21b2013-01-24 13:03:26 +08002647 bool accel_initialised = false;
2648 bool init_failed = false;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002649
2650 QemuOptsList *list = qemu_find_opts("machine");
2651 if (!QTAILQ_EMPTY(&list->head)) {
2652 p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel");
2653 }
2654
2655 if (p == NULL) {
2656 /* Use the default "accelerator", tcg */
2657 p = "tcg";
2658 }
2659
Peter Maydell1b785a92012-02-07 20:57:27 +00002660 while (!accel_initialised && *p != '\0') {
Anthony PERARD303d4e82010-09-21 20:05:31 +01002661 if (*p == ':') {
2662 p++;
2663 }
2664 p = get_opt_name(buf, sizeof (buf), p, ':');
2665 for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
2666 if (strcmp(accel_list[i].opt_name, buf) == 0) {
liguange3c66d92013-01-24 13:03:25 +08002667 if (!accel_list[i].available()) {
2668 printf("%s not supported for this target\n",
2669 accel_list[i].name);
2670 continue;
2671 }
liguangd5286af2013-01-24 13:03:27 +08002672 *(accel_list[i].allowed) = true;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002673 ret = accel_list[i].init();
2674 if (ret < 0) {
liguang217e21b2013-01-24 13:03:26 +08002675 init_failed = true;
liguange3c66d92013-01-24 13:03:25 +08002676 fprintf(stderr, "failed to initialize %s: %s\n",
2677 accel_list[i].name,
2678 strerror(-ret));
liguangd5286af2013-01-24 13:03:27 +08002679 *(accel_list[i].allowed) = false;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002680 } else {
liguang217e21b2013-01-24 13:03:26 +08002681 accel_initialised = true;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002682 }
2683 break;
2684 }
2685 }
2686 if (i == ARRAY_SIZE(accel_list)) {
2687 fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
2688 }
2689 }
2690
Peter Maydell1b785a92012-02-07 20:57:27 +00002691 if (!accel_initialised) {
liguang217e21b2013-01-24 13:03:26 +08002692 if (!init_failed) {
2693 fprintf(stderr, "No accelerator found!\n");
2694 }
Anthony PERARD303d4e82010-09-21 20:05:31 +01002695 exit(1);
2696 }
2697
2698 if (init_failed) {
2699 fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
2700 }
2701
Peter Maydell1b785a92012-02-07 20:57:27 +00002702 return !accel_initialised;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002703}
2704
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02002705void qemu_add_exit_notifier(Notifier *notify)
2706{
2707 notifier_list_add(&exit_notifiers, notify);
2708}
2709
2710void qemu_remove_exit_notifier(Notifier *notify)
2711{
Paolo Bonzini31552522012-01-13 17:34:01 +01002712 notifier_remove(notify);
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02002713}
2714
2715static void qemu_run_exit_notifiers(void)
2716{
Jan Kiszka9e8dd452011-06-20 14:06:26 +02002717 notifier_list_notify(&exit_notifiers, NULL);
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02002718}
2719
Gleb Natapov4cab9462010-12-08 13:35:08 +02002720void qemu_add_machine_init_done_notifier(Notifier *notify)
2721{
2722 notifier_list_add(&machine_init_done_notifiers, notify);
2723}
2724
2725static void qemu_run_machine_init_done_notifiers(void)
2726{
Jan Kiszka9e8dd452011-06-20 14:06:26 +02002727 notifier_list_notify(&machine_init_done_notifiers, NULL);
Gleb Natapov4cab9462010-12-08 13:35:08 +02002728}
2729
Anthony Liguori6530a972010-01-22 09:18:06 -06002730static const QEMUOption *lookup_opt(int argc, char **argv,
2731 const char **poptarg, int *poptind)
2732{
2733 const QEMUOption *popt;
2734 int optind = *poptind;
2735 char *r = argv[optind];
2736 const char *optarg;
2737
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002738 loc_set_cmdline(argv, optind, 1);
Anthony Liguori6530a972010-01-22 09:18:06 -06002739 optind++;
2740 /* Treat --foo the same as -foo. */
2741 if (r[1] == '-')
2742 r++;
2743 popt = qemu_options;
2744 for(;;) {
2745 if (!popt->name) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002746 error_report("invalid option");
Anthony Liguori6530a972010-01-22 09:18:06 -06002747 exit(1);
2748 }
2749 if (!strcmp(popt->name, r + 1))
2750 break;
2751 popt++;
2752 }
2753 if (popt->flags & HAS_ARG) {
2754 if (optind >= argc) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002755 error_report("requires an argument");
Anthony Liguori6530a972010-01-22 09:18:06 -06002756 exit(1);
2757 }
2758 optarg = argv[optind++];
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002759 loc_set_cmdline(argv, optind - 2, 2);
Anthony Liguori6530a972010-01-22 09:18:06 -06002760 } else {
2761 optarg = NULL;
2762 }
2763
2764 *poptarg = optarg;
2765 *poptind = optind;
2766
2767 return popt;
2768}
2769
Anthony Liguori07501122011-08-20 22:38:31 -05002770static gpointer malloc_and_trace(gsize n_bytes)
2771{
2772 void *ptr = malloc(n_bytes);
Frediano Ziglioa74cd8c2011-08-31 09:25:35 +02002773 trace_g_malloc(n_bytes, ptr);
Anthony Liguori07501122011-08-20 22:38:31 -05002774 return ptr;
2775}
2776
2777static gpointer realloc_and_trace(gpointer mem, gsize n_bytes)
2778{
2779 void *ptr = realloc(mem, n_bytes);
Frediano Ziglioa74cd8c2011-08-31 09:25:35 +02002780 trace_g_realloc(mem, n_bytes, ptr);
Anthony Liguori07501122011-08-20 22:38:31 -05002781 return ptr;
2782}
2783
2784static void free_and_trace(gpointer mem)
2785{
Frediano Ziglioa74cd8c2011-08-31 09:25:35 +02002786 trace_g_free(mem);
Anthony Liguori07501122011-08-20 22:38:31 -05002787 free(mem);
2788}
2789
Anthony Liguori68d98d32012-06-25 14:36:33 -05002790static int object_set_property(const char *name, const char *value, void *opaque)
2791{
2792 Object *obj = OBJECT(opaque);
2793 StringInputVisitor *siv;
2794 Error *local_err = NULL;
2795
2796 if (strcmp(name, "qom-type") == 0 || strcmp(name, "id") == 0) {
2797 return 0;
2798 }
2799
2800 siv = string_input_visitor_new(value);
2801 object_property_set(obj, string_input_get_visitor(siv), name, &local_err);
2802 string_input_visitor_cleanup(siv);
2803
2804 if (local_err) {
2805 qerror_report_err(local_err);
2806 error_free(local_err);
2807 return -1;
2808 }
2809
2810 return 0;
2811}
2812
2813static int object_create(QemuOpts *opts, void *opaque)
2814{
2815 const char *type = qemu_opt_get(opts, "qom-type");
2816 const char *id = qemu_opts_id(opts);
2817 Object *obj;
2818
2819 g_assert(type != NULL);
2820
2821 if (id == NULL) {
2822 qerror_report(QERR_MISSING_PARAMETER, "id");
2823 return -1;
2824 }
2825
2826 obj = object_new(type);
2827 if (qemu_opt_foreach(opts, object_set_property, obj, 1) < 0) {
2828 return -1;
2829 }
2830
2831 object_property_add_child(container_get(object_get_root(), "/objects"),
2832 id, obj, NULL);
2833
2834 return 0;
2835}
2836
malc902b3d52008-12-10 19:18:40 +00002837int main(int argc, char **argv, char **envp)
bellard0824d6f2003-06-24 13:42:40 +00002838{
thse4bcb142007-12-02 04:51:10 +00002839 int i;
Eduardo Habkostda1fcfd2010-04-06 19:22:07 -03002840 int snapshot, linux_boot;
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01002841 const char *icount_option = NULL;
bellard7f7f9872003-10-30 01:11:23 +00002842 const char *initrd_filename;
bellarda20dd502003-09-30 21:07:02 +00002843 const char *kernel_filename, *kernel_cmdline;
Markus Armbruster8281abd2013-06-14 13:15:03 +02002844 const char *boot_order = NULL;
aliguori3023f332009-01-16 19:04:14 +00002845 DisplayState *ds;
malc9f227bc2012-08-27 18:33:22 +04002846 int cyls, heads, secs, translation;
2847 QemuOpts *hda_opts = NULL, *opts, *machine_opts;
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002848 QemuOptsList *olist;
bellardcd6f1162004-05-13 22:02:20 +00002849 int optind;
Anthony Liguori6530a972010-01-22 09:18:06 -06002850 const char *optarg;
bellardd63d3072004-10-03 13:29:03 +00002851 const char *loadvm = NULL;
bellardcc1daa42005-06-05 14:49:17 +00002852 QEMUMachine *machine;
j_mayer94fc95c2007-03-05 19:44:02 +00002853 const char *cpu_model;
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +02002854 const char *vga_model = "none";
ths93815bc2007-03-19 15:58:31 +00002855 const char *pid_file = NULL;
aliguori5bb79102008-10-13 03:12:02 +00002856 const char *incoming = NULL;
Jes Sorensen821601e2011-03-16 13:33:36 +01002857#ifdef CONFIG_VNC
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002858 int show_vnc_port = 0;
Jes Sorensen821601e2011-03-16 13:33:36 +01002859#endif
Eduardo Habkost3ed2d9e2012-05-02 13:07:28 -03002860 bool defconfig = true;
Eduardo Habkostf29a5612012-05-02 13:07:29 -03002861 bool userconfig = true;
Matthew Fernandezc235d732011-06-07 16:32:40 +00002862 const char *log_mask = NULL;
2863 const char *log_file = NULL;
Anthony Liguori07501122011-08-20 22:38:31 -05002864 GMemVTable mem_trace = {
2865 .malloc = malloc_and_trace,
2866 .realloc = realloc_and_trace,
2867 .free = free_and_trace,
2868 };
Lluís23d15e82011-08-31 20:31:31 +02002869 const char *trace_events = NULL;
Lluíse4858972011-08-31 20:31:03 +02002870 const char *trace_file = NULL;
Stefan Hajnoczi0b5538c2011-02-26 18:38:39 +00002871
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02002872 atexit(qemu_run_exit_notifiers);
Markus Armbruster65abca02010-02-24 14:37:14 +01002873 error_set_progname(argv[0]);
2874
Anthony Liguori07501122011-08-20 22:38:31 -05002875 g_mem_set_vtable(&mem_trace);
Andreas Färberdb529aa2011-10-31 19:14:56 +01002876 if (!g_thread_supported()) {
Alon Levy42ed3722011-12-20 13:41:04 +02002877#if !GLIB_CHECK_VERSION(2, 31, 0)
Andreas Färberdb529aa2011-10-31 19:14:56 +01002878 g_thread_init(NULL);
Alon Levy42ed3722011-12-20 13:41:04 +02002879#else
2880 fprintf(stderr, "glib threading failed to initialize.\n");
2881 exit(1);
2882#endif
Andreas Färberdb529aa2011-10-31 19:14:56 +01002883 }
Anthony Liguori07501122011-08-20 22:38:31 -05002884
Andreas Färber1b71f7c2012-03-04 21:32:35 +01002885 module_call_init(MODULE_INIT_QOM);
2886
Paolo Bonzini4d454572012-11-26 16:03:42 +01002887 qemu_add_opts(&qemu_drive_opts);
2888 qemu_add_opts(&qemu_chardev_opts);
2889 qemu_add_opts(&qemu_device_opts);
2890 qemu_add_opts(&qemu_netdev_opts);
2891 qemu_add_opts(&qemu_net_opts);
2892 qemu_add_opts(&qemu_rtc_opts);
2893 qemu_add_opts(&qemu_global_opts);
2894 qemu_add_opts(&qemu_mon_opts);
2895 qemu_add_opts(&qemu_trace_opts);
2896 qemu_add_opts(&qemu_option_rom_opts);
2897 qemu_add_opts(&qemu_machine_opts);
2898 qemu_add_opts(&qemu_boot_opts);
2899 qemu_add_opts(&qemu_sandbox_opts);
2900 qemu_add_opts(&qemu_add_fd_opts);
2901 qemu_add_opts(&qemu_object_opts);
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05002902 qemu_add_opts(&qemu_tpmdev_opts);
Satoru Moriya888a6bc2013-04-19 16:42:06 +02002903 qemu_add_opts(&qemu_realtime_opts);
Paolo Bonzini4d454572012-11-26 16:03:42 +01002904
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -03002905 runstate_init();
2906
Jan Kiszka68752042009-09-15 13:36:04 +02002907 init_clocks();
Paolo Bonzini2ff68d02011-09-12 16:21:44 +02002908 rtc_clock = host_clock;
Jan Kiszka68752042009-09-15 13:36:04 +02002909
malc902b3d52008-12-10 19:18:40 +00002910 qemu_cache_utils_init(envp);
2911
Blue Swirl72cf2d42009-09-12 07:36:22 +00002912 QLIST_INIT (&vm_change_state_head);
Jes Sorensenfe98ac12010-06-10 11:42:21 +02002913 os_setup_early_signal_handling();
bellardbe995c22006-06-25 16:25:21 +00002914
Anthony Liguorif80f9ec2009-05-20 18:38:09 -05002915 module_call_init(MODULE_INIT_MACHINE);
Anthony Liguori0c257432009-05-21 20:41:01 -05002916 machine = find_default_machine();
j_mayer94fc95c2007-03-05 19:44:02 +00002917 cpu_model = NULL;
aurel324fc5d072008-04-27 21:39:40 +00002918 ram_size = 0;
bellard33e39632003-07-06 17:15:21 +00002919 snapshot = 0;
malc9f227bc2012-08-27 18:33:22 +04002920 cyls = heads = secs = 0;
2921 translation = BIOS_ATA_TRANSLATION_AUTO;
bellardc4b1fcc2004-03-14 21:44:30 +00002922
aliguori268a3622009-04-21 22:30:27 +00002923 for (i = 0; i < MAX_NODES; i++) {
2924 node_mem[i] = 0;
Chegu Vinodee785fe2012-07-16 21:31:30 -07002925 node_cpumask[i] = bitmap_new(MAX_CPUMASK_BITS);
aliguori268a3622009-04-21 22:30:27 +00002926 }
2927
aliguori268a3622009-04-21 22:30:27 +00002928 nb_numa_nodes = 0;
bellard7c9d8e02005-11-15 22:16:05 +00002929 nb_nics = 0;
ths3b46e622007-09-17 08:09:54 +00002930
Peter Lieven142c6b12013-03-21 13:07:10 +01002931 bdrv_init_with_whitelist();
2932
blueswir141bd6392008-10-05 09:56:21 +00002933 autostart= 1;
2934
Anthony Liguori292444c2010-01-21 10:57:58 -06002935 /* first pass of option parsing */
2936 optind = 1;
2937 while (optind < argc) {
2938 if (argv[optind][0] != '-') {
2939 /* disk image */
Anthony Liguori28e68d62010-01-27 10:46:00 -06002940 optind++;
Anthony Liguori292444c2010-01-21 10:57:58 -06002941 continue;
2942 } else {
2943 const QEMUOption *popt;
2944
2945 popt = lookup_opt(argc, argv, &optarg, &optind);
2946 switch (popt->index) {
2947 case QEMU_OPTION_nodefconfig:
Eduardo Habkost3ed2d9e2012-05-02 13:07:28 -03002948 defconfig = false;
Anthony Liguori292444c2010-01-21 10:57:58 -06002949 break;
Eduardo Habkostf29a5612012-05-02 13:07:29 -03002950 case QEMU_OPTION_nouserconfig:
2951 userconfig = false;
2952 break;
Anthony Liguori292444c2010-01-21 10:57:58 -06002953 }
2954 }
2955 }
2956
2957 if (defconfig) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002958 int ret;
Eduardo Habkostf29a5612012-05-02 13:07:29 -03002959 ret = qemu_read_default_config_files(userconfig);
Eduardo Habkostb5a8fe52012-05-02 13:07:25 -03002960 if (ret < 0) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002961 exit(1);
Anthony Liguori292444c2010-01-21 10:57:58 -06002962 }
2963 }
2964
2965 /* second pass of option parsing */
bellardcd6f1162004-05-13 22:02:20 +00002966 optind = 1;
bellard0824d6f2003-06-24 13:42:40 +00002967 for(;;) {
bellardcd6f1162004-05-13 22:02:20 +00002968 if (optind >= argc)
bellard0824d6f2003-06-24 13:42:40 +00002969 break;
Anthony Liguori6530a972010-01-22 09:18:06 -06002970 if (argv[optind][0] != '-') {
malc9f227bc2012-08-27 18:33:22 +04002971 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
bellardcd6f1162004-05-13 22:02:20 +00002972 } else {
2973 const QEMUOption *popt;
2974
Anthony Liguori6530a972010-01-22 09:18:06 -06002975 popt = lookup_opt(argc, argv, &optarg, &optind);
Blue Swirlad960902010-03-29 19:23:52 +00002976 if (!(popt->arch_mask & arch_type)) {
2977 printf("Option %s not supported for this target\n", popt->name);
2978 exit(1);
2979 }
bellardcd6f1162004-05-13 22:02:20 +00002980 switch(popt->index) {
bellardcc1daa42005-06-05 14:49:17 +00002981 case QEMU_OPTION_M:
Jan Kiszka9052ea62011-07-23 12:38:37 +02002982 machine = machine_parse(optarg);
bellardcc1daa42005-06-05 14:49:17 +00002983 break;
Jan Kiszkae43d5942012-10-05 14:51:40 -03002984 case QEMU_OPTION_no_kvm_irqchip: {
2985 olist = qemu_find_opts("machine");
2986 qemu_opts_parse(olist, "kernel_irqchip=off", 0);
2987 break;
2988 }
j_mayer94fc95c2007-03-05 19:44:02 +00002989 case QEMU_OPTION_cpu:
2990 /* hw initialization will check this */
Eduardo Habkostecf40be2012-03-09 16:19:07 -03002991 cpu_model = optarg;
j_mayer94fc95c2007-03-05 19:44:02 +00002992 break;
bellardcd6f1162004-05-13 22:02:20 +00002993 case QEMU_OPTION_hda:
malc9f227bc2012-08-27 18:33:22 +04002994 {
2995 char buf[256];
2996 if (cyls == 0)
2997 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2998 else
2999 snprintf(buf, sizeof(buf),
3000 "%s,cyls=%d,heads=%d,secs=%d%s",
3001 HD_OPTS , cyls, heads, secs,
3002 translation == BIOS_ATA_TRANSLATION_LBA ?
3003 ",trans=lba" :
3004 translation == BIOS_ATA_TRANSLATION_NONE ?
3005 ",trans=none" : "");
3006 drive_add(IF_DEFAULT, 0, optarg, buf);
3007 break;
3008 }
bellardcd6f1162004-05-13 22:02:20 +00003009 case QEMU_OPTION_hdb:
bellardcc1daa42005-06-05 14:49:17 +00003010 case QEMU_OPTION_hdc:
3011 case QEMU_OPTION_hdd:
Markus Armbruster2292dda2011-01-28 11:21:41 +01003012 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
3013 HD_OPTS);
bellardfc01f7e2003-06-30 10:03:06 +00003014 break;
thse4bcb142007-12-02 04:51:10 +00003015 case QEMU_OPTION_drive:
Michael Tokareve2982c32011-03-30 16:31:05 +04003016 if (drive_def(optarg) == NULL) {
3017 exit(1);
3018 }
thse4bcb142007-12-02 04:51:10 +00003019 break;
Gerd Hoffmannd058fe02009-07-31 12:25:36 +02003020 case QEMU_OPTION_set:
3021 if (qemu_set_option(optarg) != 0)
3022 exit(1);
3023 break;
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01003024 case QEMU_OPTION_global:
3025 if (qemu_global_option(optarg) != 0)
3026 exit(1);
3027 break;
balrog3e3d5812007-04-30 02:09:25 +00003028 case QEMU_OPTION_mtdblock:
Markus Armbruster2292dda2011-01-28 11:21:41 +01003029 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
balrog3e3d5812007-04-30 02:09:25 +00003030 break;
pbrooka1bb27b2007-04-06 16:49:48 +00003031 case QEMU_OPTION_sd:
Peter Crosthwaite80f4d9f2013-02-28 18:23:14 +00003032 drive_add(IF_SD, -1, optarg, SD_OPTS);
pbrooka1bb27b2007-04-06 16:49:48 +00003033 break;
j_mayer86f55662007-04-24 06:52:59 +00003034 case QEMU_OPTION_pflash:
Markus Armbruster2292dda2011-01-28 11:21:41 +01003035 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
j_mayer86f55662007-04-24 06:52:59 +00003036 break;
bellardcd6f1162004-05-13 22:02:20 +00003037 case QEMU_OPTION_snapshot:
bellard33e39632003-07-06 17:15:21 +00003038 snapshot = 1;
3039 break;
bellardcd6f1162004-05-13 22:02:20 +00003040 case QEMU_OPTION_hdachs:
bellard330d0412003-07-26 18:11:40 +00003041 {
bellard330d0412003-07-26 18:11:40 +00003042 const char *p;
3043 p = optarg;
3044 cyls = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00003045 if (cyls < 1 || cyls > 16383)
3046 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00003047 if (*p != ',')
3048 goto chs_fail;
3049 p++;
3050 heads = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00003051 if (heads < 1 || heads > 16)
3052 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00003053 if (*p != ',')
3054 goto chs_fail;
3055 p++;
3056 secs = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00003057 if (secs < 1 || secs > 63)
3058 goto chs_fail;
3059 if (*p == ',') {
3060 p++;
3061 if (!strcmp(p, "none"))
3062 translation = BIOS_ATA_TRANSLATION_NONE;
3063 else if (!strcmp(p, "lba"))
3064 translation = BIOS_ATA_TRANSLATION_LBA;
3065 else if (!strcmp(p, "auto"))
3066 translation = BIOS_ATA_TRANSLATION_AUTO;
3067 else
3068 goto chs_fail;
3069 } else if (*p != '\0') {
bellardc4b1fcc2004-03-14 21:44:30 +00003070 chs_fail:
bellard46d47672004-11-16 01:45:27 +00003071 fprintf(stderr, "qemu: invalid physical CHS format\n");
3072 exit(1);
bellardc4b1fcc2004-03-14 21:44:30 +00003073 }
malc9f227bc2012-08-27 18:33:22 +04003074 if (hda_opts != NULL) {
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02003075 char num[16];
3076 snprintf(num, sizeof(num), "%d", cyls);
3077 qemu_opt_set(hda_opts, "cyls", num);
3078 snprintf(num, sizeof(num), "%d", heads);
3079 qemu_opt_set(hda_opts, "heads", num);
3080 snprintf(num, sizeof(num), "%d", secs);
3081 qemu_opt_set(hda_opts, "secs", num);
3082 if (translation == BIOS_ATA_TRANSLATION_LBA)
3083 qemu_opt_set(hda_opts, "trans", "lba");
3084 if (translation == BIOS_ATA_TRANSLATION_NONE)
3085 qemu_opt_set(hda_opts, "trans", "none");
3086 }
bellard330d0412003-07-26 18:11:40 +00003087 }
3088 break;
aliguori268a3622009-04-21 22:30:27 +00003089 case QEMU_OPTION_numa:
aliguori268a3622009-04-21 22:30:27 +00003090 numa_add(optarg);
3091 break;
Jes Sorensen1472a952011-03-16 13:33:31 +01003092 case QEMU_OPTION_display:
3093 display_type = select_display(optarg);
3094 break;
bellardcd6f1162004-05-13 22:02:20 +00003095 case QEMU_OPTION_nographic:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003096 display_type = DT_NOGRAPHIC;
bellarda20dd502003-09-30 21:07:02 +00003097 break;
balrog4d3b6f62008-02-10 16:33:14 +00003098 case QEMU_OPTION_curses:
Jes Sorensen47b05362011-03-16 13:33:35 +01003099#ifdef CONFIG_CURSES
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003100 display_type = DT_CURSES;
Jes Sorensen47b05362011-03-16 13:33:35 +01003101#else
3102 fprintf(stderr, "Curses support is disabled\n");
3103 exit(1);
balrog4d3b6f62008-02-10 16:33:14 +00003104#endif
Jes Sorensen47b05362011-03-16 13:33:35 +01003105 break;
balroga171fe32007-04-30 01:48:07 +00003106 case QEMU_OPTION_portrait:
Vasily Khoruzhick93128052011-06-17 13:04:36 +03003107 graphic_rotate = 90;
3108 break;
3109 case QEMU_OPTION_rotate:
3110 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
3111 if (graphic_rotate != 0 && graphic_rotate != 90 &&
3112 graphic_rotate != 180 && graphic_rotate != 270) {
3113 fprintf(stderr,
3114 "qemu: only 90, 180, 270 deg rotation is available\n");
3115 exit(1);
3116 }
balroga171fe32007-04-30 01:48:07 +00003117 break;
bellardcd6f1162004-05-13 22:02:20 +00003118 case QEMU_OPTION_kernel:
Peter Maydella0abe472012-02-08 05:41:39 +00003119 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg);
3120 break;
3121 case QEMU_OPTION_initrd:
3122 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg);
bellarda20dd502003-09-30 21:07:02 +00003123 break;
bellardcd6f1162004-05-13 22:02:20 +00003124 case QEMU_OPTION_append:
Peter Maydella0abe472012-02-08 05:41:39 +00003125 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg);
bellard313aa562003-08-10 21:52:11 +00003126 break;
Grant Likely412beee2012-03-02 11:56:38 +00003127 case QEMU_OPTION_dtb:
3128 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg);
3129 break;
bellardcd6f1162004-05-13 22:02:20 +00003130 case QEMU_OPTION_cdrom:
Markus Armbruster2292dda2011-01-28 11:21:41 +01003131 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
bellard36b486b2003-11-11 13:36:08 +00003132 break;
bellardcd6f1162004-05-13 22:02:20 +00003133 case QEMU_OPTION_boot:
Markus Armbruster8281abd2013-06-14 13:15:03 +02003134 opts = qemu_opts_parse(qemu_find_opts("boot-opts"), optarg, 1);
3135 if (!opts) {
3136 exit(1);
bellard36b486b2003-11-11 13:36:08 +00003137 }
3138 break;
bellardcd6f1162004-05-13 22:02:20 +00003139 case QEMU_OPTION_fda:
bellardcd6f1162004-05-13 22:02:20 +00003140 case QEMU_OPTION_fdb:
Markus Armbruster2292dda2011-01-28 11:21:41 +01003141 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
3142 optarg, FD_OPTS);
bellardc45886d2004-01-05 00:02:06 +00003143 break;
bellard52ca8d62006-06-14 16:03:05 +00003144 case QEMU_OPTION_no_fd_bootchk:
3145 fd_bootchk = 0;
3146 break;
Mark McLoughlina1ea4582009-10-08 19:58:26 +01003147 case QEMU_OPTION_netdev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003148 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
Mark McLoughlina1ea4582009-10-08 19:58:26 +01003149 exit(1);
3150 }
3151 break;
bellard7c9d8e02005-11-15 22:16:05 +00003152 case QEMU_OPTION_net:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003153 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
bellardc4b1fcc2004-03-14 21:44:30 +00003154 exit(1);
3155 }
bellard702c6512004-04-02 21:21:32 +00003156 break;
Ronnie Sahlbergf9dadc92012-01-26 09:39:02 +11003157#ifdef CONFIG_LIBISCSI
3158 case QEMU_OPTION_iscsi:
3159 opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0);
3160 if (!opts) {
3161 exit(1);
3162 }
3163 break;
3164#endif
bellardc7f74642004-08-24 21:57:12 +00003165#ifdef CONFIG_SLIRP
3166 case QEMU_OPTION_tftp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02003167 legacy_tftp_prefix = optarg;
bellard9bf05442004-08-25 22:12:49 +00003168 break;
ths47d5d012007-02-20 00:05:08 +00003169 case QEMU_OPTION_bootp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02003170 legacy_bootp_filename = optarg;
ths47d5d012007-02-20 00:05:08 +00003171 break;
bellard9bf05442004-08-25 22:12:49 +00003172 case QEMU_OPTION_redir:
Markus Armbruster07527062009-10-06 12:16:57 +01003173 if (net_slirp_redir(optarg) < 0)
3174 exit(1);
bellard9bf05442004-08-25 22:12:49 +00003175 break;
bellardc7f74642004-08-24 21:57:12 +00003176#endif
balrogdc72ac12008-11-09 00:04:26 +00003177 case QEMU_OPTION_bt:
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003178 add_device_config(DEV_BT, optarg);
balrogdc72ac12008-11-09 00:04:26 +00003179 break;
bellard1d14ffa2005-10-30 18:58:22 +00003180 case QEMU_OPTION_audio_help:
3181 AUD_help ();
3182 exit (0);
3183 break;
3184 case QEMU_OPTION_soundhw:
3185 select_soundhw (optarg);
3186 break;
bellardcd6f1162004-05-13 22:02:20 +00003187 case QEMU_OPTION_h:
ths15f82202007-06-29 23:26:08 +00003188 help(0);
bellardcd6f1162004-05-13 22:02:20 +00003189 break;
pbrook9bd7e6d2009-04-07 22:58:45 +00003190 case QEMU_OPTION_version:
3191 version();
3192 exit(0);
3193 break;
aurel3200f82b82008-04-27 21:12:55 +00003194 case QEMU_OPTION_m: {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +01003195 int64_t value;
Markus Armbrusterff961012012-08-15 13:12:19 +02003196 uint64_t sz;
Markus Armbruster961b42b2011-11-22 09:46:03 +01003197 char *end;
aurel3200f82b82008-04-27 21:12:55 +00003198
Markus Armbruster961b42b2011-11-22 09:46:03 +01003199 value = strtosz(optarg, &end);
3200 if (value < 0 || *end) {
aurel3200f82b82008-04-27 21:12:55 +00003201 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
bellardcd6f1162004-05-13 22:02:20 +00003202 exit(1);
3203 }
Markus Armbrusterff961012012-08-15 13:12:19 +02003204 sz = QEMU_ALIGN_UP((uint64_t)value, 8192);
3205 ram_size = sz;
3206 if (ram_size != sz) {
aurel3200f82b82008-04-27 21:12:55 +00003207 fprintf(stderr, "qemu: ram size too large\n");
3208 exit(1);
3209 }
bellardcd6f1162004-05-13 22:02:20 +00003210 break;
aurel3200f82b82008-04-27 21:12:55 +00003211 }
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05003212#ifdef CONFIG_TPM
3213 case QEMU_OPTION_tpmdev:
3214 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
3215 exit(1);
3216 }
3217 break;
3218#endif
Marcelo Tosattic9027602010-03-01 20:25:08 -03003219 case QEMU_OPTION_mempath:
3220 mem_path = optarg;
3221 break;
3222#ifdef MAP_POPULATE
3223 case QEMU_OPTION_mem_prealloc:
3224 mem_prealloc = 1;
3225 break;
3226#endif
bellardcd6f1162004-05-13 22:02:20 +00003227 case QEMU_OPTION_d:
Matthew Fernandezc235d732011-06-07 16:32:40 +00003228 log_mask = optarg;
3229 break;
3230 case QEMU_OPTION_D:
3231 log_file = optarg;
bellardcd6f1162004-05-13 22:02:20 +00003232 break;
bellardcd6f1162004-05-13 22:02:20 +00003233 case QEMU_OPTION_s:
Markus Armbrusteref0c4a02012-02-07 15:09:13 +01003234 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
bellardcd6f1162004-05-13 22:02:20 +00003235 break;
aliguori59030a82009-04-05 18:43:41 +00003236 case QEMU_OPTION_gdb:
Markus Armbrusteref0c4a02012-02-07 15:09:13 +01003237 add_device_config(DEV_GDB, optarg);
bellardcd6f1162004-05-13 22:02:20 +00003238 break;
bellardcd6f1162004-05-13 22:02:20 +00003239 case QEMU_OPTION_L:
Gerd Hoffmann45240512013-03-08 11:42:24 +01003240 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
3241 data_dir[data_dir_idx++] = optarg;
3242 }
bellardcd6f1162004-05-13 22:02:20 +00003243 break;
j_mayer1192dad2007-10-05 13:08:35 +00003244 case QEMU_OPTION_bios:
3245 bios_name = optarg;
3246 break;
aurel321b530a62009-04-05 20:08:59 +00003247 case QEMU_OPTION_singlestep:
3248 singlestep = 1;
3249 break;
bellardcd6f1162004-05-13 22:02:20 +00003250 case QEMU_OPTION_S:
pbrook3c07f8e2007-01-21 16:47:01 +00003251 autostart = 0;
bellardcd6f1162004-05-13 22:02:20 +00003252 break;
bellard3d11d0e2004-12-12 16:56:30 +00003253 case QEMU_OPTION_k:
3254 keyboard_layout = optarg;
3255 break;
bellardee22c2f2004-06-03 12:49:50 +00003256 case QEMU_OPTION_localtime:
3257 rtc_utc = 0;
3258 break;
malc3893c122008-09-28 00:42:05 +00003259 case QEMU_OPTION_vga:
Blue Swirla369da52011-09-27 19:15:42 +00003260 vga_model = optarg;
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +02003261 default_vga = 0;
bellard1bfe8562004-07-08 21:17:50 +00003262 break;
bellarde9b137c2004-06-21 16:46:10 +00003263 case QEMU_OPTION_g:
3264 {
3265 const char *p;
3266 int w, h, depth;
3267 p = optarg;
3268 w = strtol(p, (char **)&p, 10);
3269 if (w <= 0) {
3270 graphic_error:
3271 fprintf(stderr, "qemu: invalid resolution or depth\n");
3272 exit(1);
3273 }
3274 if (*p != 'x')
3275 goto graphic_error;
3276 p++;
3277 h = strtol(p, (char **)&p, 10);
3278 if (h <= 0)
3279 goto graphic_error;
3280 if (*p == 'x') {
3281 p++;
3282 depth = strtol(p, (char **)&p, 10);
ths5fafdf22007-09-16 21:08:06 +00003283 if (depth != 8 && depth != 15 && depth != 16 &&
bellarde9b137c2004-06-21 16:46:10 +00003284 depth != 24 && depth != 32)
3285 goto graphic_error;
3286 } else if (*p == '\0') {
3287 depth = graphic_depth;
3288 } else {
3289 goto graphic_error;
3290 }
ths3b46e622007-09-17 08:09:54 +00003291
bellarde9b137c2004-06-21 16:46:10 +00003292 graphic_width = w;
3293 graphic_height = h;
3294 graphic_depth = depth;
3295 }
3296 break;
ths20d8a3e2007-02-18 17:04:49 +00003297 case QEMU_OPTION_echr:
3298 {
3299 char *r;
3300 term_escape_char = strtol(optarg, &r, 0);
3301 if (r == optarg)
3302 printf("Bad argument to echr\n");
3303 break;
3304 }
bellard82c643f2004-07-14 17:28:13 +00003305 case QEMU_OPTION_monitor:
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01003306 default_monitor = 0;
Luiz Capitulino70e098a2013-05-16 12:02:55 -04003307 if (strncmp(optarg, "none", 4)) {
3308 monitor_parse(optarg, "readline");
3309 }
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01003310 break;
3311 case QEMU_OPTION_qmp:
3312 monitor_parse(optarg, "control");
Anthony Liguori2d114dc2010-03-21 14:14:38 -05003313 default_monitor = 0;
bellard82c643f2004-07-14 17:28:13 +00003314 break;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01003315 case QEMU_OPTION_mon:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003316 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01003317 if (!opts) {
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01003318 exit(1);
3319 }
Anthony Liguori2d114dc2010-03-21 14:14:38 -05003320 default_monitor = 0;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01003321 break;
Gerd Hoffmann191bc012009-09-10 10:58:35 +02003322 case QEMU_OPTION_chardev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003323 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
Gerd Hoffmann191bc012009-09-10 10:58:35 +02003324 if (!opts) {
Gerd Hoffmann191bc012009-09-10 10:58:35 +02003325 exit(1);
3326 }
Gerd Hoffmann191bc012009-09-10 10:58:35 +02003327 break;
Gautham R Shenoy74db9202010-04-29 17:44:43 +05303328 case QEMU_OPTION_fsdev:
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02003329 olist = qemu_find_opts("fsdev");
3330 if (!olist) {
3331 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
3332 exit(1);
3333 }
3334 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy74db9202010-04-29 17:44:43 +05303335 if (!opts) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +05303336 exit(1);
3337 }
3338 break;
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303339 case QEMU_OPTION_virtfs: {
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00003340 QemuOpts *fsdev;
3341 QemuOpts *device;
M. Mohan Kumar84a87cc2011-12-14 13:58:47 +05303342 const char *writeout, *sock_fd, *socket;
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303343
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02003344 olist = qemu_find_opts("virtfs");
3345 if (!olist) {
3346 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
3347 exit(1);
3348 }
3349 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303350 if (!opts) {
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303351 exit(1);
3352 }
3353
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +05303354 if (qemu_opt_get(opts, "fsdriver") == NULL ||
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +05303355 qemu_opt_get(opts, "mount_tag") == NULL) {
3356 fprintf(stderr, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07003357 exit(1);
3358 }
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00003359 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03003360 qemu_opt_get(opts, "mount_tag"),
3361 1, NULL);
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00003362 if (!fsdev) {
3363 fprintf(stderr, "duplicate fsdev id: %s\n",
3364 qemu_opt_get(opts, "mount_tag"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303365 exit(1);
3366 }
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +05303367
3368 writeout = qemu_opt_get(opts, "writeout");
3369 if (writeout) {
3370#ifdef CONFIG_SYNC_FILE_RANGE
3371 qemu_opt_set(fsdev, "writeout", writeout);
3372#else
3373 fprintf(stderr, "writeout=immediate not supported on "
3374 "this platform\n");
3375 exit(1);
3376#endif
3377 }
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +05303378 qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver"));
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00003379 qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"));
3380 qemu_opt_set(fsdev, "security_model",
3381 qemu_opt_get(opts, "security_model"));
M. Mohan Kumar84a87cc2011-12-14 13:58:47 +05303382 socket = qemu_opt_get(opts, "socket");
3383 if (socket) {
3384 qemu_opt_set(fsdev, "socket", socket);
3385 }
M. Mohan Kumar4c793dd2011-12-14 13:49:28 +05303386 sock_fd = qemu_opt_get(opts, "sock_fd");
3387 if (sock_fd) {
3388 qemu_opt_set(fsdev, "sock_fd", sock_fd);
3389 }
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303390
M. Mohan Kumar2c74c2c2011-10-25 12:10:39 +05303391 qemu_opt_set_bool(fsdev, "readonly",
3392 qemu_opt_get_bool(opts, "readonly", 0));
Dong Xu Wange478b442012-12-06 14:47:22 +08003393 device = qemu_opts_create_nofail(qemu_find_opts("device"));
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00003394 qemu_opt_set(device, "driver", "virtio-9p-pci");
3395 qemu_opt_set(device, "fsdev",
3396 qemu_opt_get(opts, "mount_tag"));
3397 qemu_opt_set(device, "mount_tag",
3398 qemu_opt_get(opts, "mount_tag"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303399 break;
3400 }
Aneesh Kumar K.V9db221a2011-10-25 12:10:40 +05303401 case QEMU_OPTION_virtfs_synth: {
3402 QemuOpts *fsdev;
3403 QemuOpts *device;
3404
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03003405 fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3406 1, NULL);
Aneesh Kumar K.V9db221a2011-10-25 12:10:40 +05303407 if (!fsdev) {
3408 fprintf(stderr, "duplicate option: %s\n", "virtfs_synth");
3409 exit(1);
3410 }
3411 qemu_opt_set(fsdev, "fsdriver", "synth");
Aneesh Kumar K.V9db221a2011-10-25 12:10:40 +05303412
Dong Xu Wange478b442012-12-06 14:47:22 +08003413 device = qemu_opts_create_nofail(qemu_find_opts("device"));
Aneesh Kumar K.V9db221a2011-10-25 12:10:40 +05303414 qemu_opt_set(device, "driver", "virtio-9p-pci");
3415 qemu_opt_set(device, "fsdev", "v_synth");
3416 qemu_opt_set(device, "mount_tag", "v_synth");
3417 break;
3418 }
bellard82c643f2004-07-14 17:28:13 +00003419 case QEMU_OPTION_serial:
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01003420 add_device_config(DEV_SERIAL, optarg);
3421 default_serial = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01003422 if (strncmp(optarg, "mon:", 4) == 0) {
3423 default_monitor = 0;
3424 }
bellard82c643f2004-07-14 17:28:13 +00003425 break;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01003426 case QEMU_OPTION_watchdog:
Markus Armbruster09aaa162009-08-21 10:31:34 +02003427 if (watchdog) {
3428 fprintf(stderr,
3429 "qemu: only one watchdog option may be given\n");
3430 return 1;
3431 }
3432 watchdog = optarg;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01003433 break;
3434 case QEMU_OPTION_watchdog_action:
3435 if (select_watchdog_action(optarg) == -1) {
3436 fprintf(stderr, "Unknown -watchdog-action parameter\n");
3437 exit(1);
3438 }
3439 break;
aliguori51ecf132009-01-15 20:06:40 +00003440 case QEMU_OPTION_virtiocon:
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01003441 add_device_config(DEV_VIRTCON, optarg);
3442 default_virtcon = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01003443 if (strncmp(optarg, "mon:", 4) == 0) {
3444 default_monitor = 0;
3445 }
aliguori51ecf132009-01-15 20:06:40 +00003446 break;
bellard6508fe52005-01-15 12:02:56 +00003447 case QEMU_OPTION_parallel:
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01003448 add_device_config(DEV_PARALLEL, optarg);
3449 default_parallel = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01003450 if (strncmp(optarg, "mon:", 4) == 0) {
3451 default_monitor = 0;
3452 }
bellard6508fe52005-01-15 12:02:56 +00003453 break;
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08003454 case QEMU_OPTION_debugcon:
3455 add_device_config(DEV_DEBUGCON, optarg);
3456 break;
bellardd63d3072004-10-03 13:29:03 +00003457 case QEMU_OPTION_loadvm:
3458 loadvm = optarg;
3459 break;
3460 case QEMU_OPTION_full_screen:
3461 full_screen = 1;
3462 break;
ths43523e92007-02-18 18:19:32 +00003463 case QEMU_OPTION_no_frame:
3464 no_frame = 1;
3465 break;
ths3780e192007-06-21 21:08:02 +00003466 case QEMU_OPTION_alt_grab:
3467 alt_grab = 1;
3468 break;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -05003469 case QEMU_OPTION_ctrl_grab:
3470 ctrl_grab = 1;
3471 break;
ths667acca2006-12-11 02:08:05 +00003472 case QEMU_OPTION_no_quit:
3473 no_quit = 1;
3474 break;
aliguori7d957bd2009-01-15 22:14:11 +00003475 case QEMU_OPTION_sdl:
Michael Tokarev24f6ff82013-06-15 14:44:20 +04003476#ifdef CONFIG_SDL
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003477 display_type = DT_SDL;
aliguori7d957bd2009-01-15 22:14:11 +00003478 break;
Jes Sorensen58fc0962011-03-16 13:33:34 +01003479#else
Jes Sorensen58fc0962011-03-16 13:33:34 +01003480 fprintf(stderr, "SDL support is disabled\n");
3481 exit(1);
ths667acca2006-12-11 02:08:05 +00003482#endif
bellardf7cce892004-12-08 22:21:25 +00003483 case QEMU_OPTION_pidfile:
ths93815bc2007-03-19 15:58:31 +00003484 pid_file = optarg;
bellardf7cce892004-12-08 22:21:25 +00003485 break;
bellarda09db212005-04-30 16:10:35 +00003486 case QEMU_OPTION_win2k_hack:
3487 win2k_install_hack = 1;
3488 break;
Jan Kiszka433acf02012-01-23 20:15:12 +01003489 case QEMU_OPTION_rtc_td_hack: {
3490 static GlobalProperty slew_lost_ticks[] = {
3491 {
3492 .driver = "mc146818rtc",
3493 .property = "lost_tick_policy",
3494 .value = "slew",
3495 },
3496 { /* end of list */ }
3497 };
3498
3499 qdev_prop_register_global_list(slew_lost_ticks);
aliguori73822ec2009-01-15 20:11:34 +00003500 break;
Jan Kiszka433acf02012-01-23 20:15:12 +01003501 }
aliguori8a92ea22009-02-27 20:12:36 +00003502 case QEMU_OPTION_acpitable:
Laszlo Ersek0c764a92013-03-21 00:23:17 +01003503 opts = qemu_opts_parse(qemu_find_opts("acpi"), optarg, 1);
3504 g_assert(opts != NULL);
3505 do_acpitable_option(opts);
aliguori8a92ea22009-02-27 20:12:36 +00003506 break;
aliguorib6f6e3d2009-04-17 18:59:56 +00003507 case QEMU_OPTION_smbios:
Blue Swirlde06f8d2010-03-29 19:23:50 +00003508 do_smbios_option(optarg);
aliguorib6f6e3d2009-04-17 18:59:56 +00003509 break;
aliguori7ba1e612008-11-05 16:04:33 +00003510 case QEMU_OPTION_enable_kvm:
Anthony PERARD303d4e82010-09-21 20:05:31 +01003511 olist = qemu_find_opts("machine");
Anthony PERARD303d4e82010-09-21 20:05:31 +01003512 qemu_opts_parse(olist, "accel=kvm", 0);
3513 break;
3514 case QEMU_OPTION_machine:
3515 olist = qemu_find_opts("machine");
Jan Kiszka9052ea62011-07-23 12:38:37 +02003516 opts = qemu_opts_parse(olist, optarg, 1);
Anthony PERARD303d4e82010-09-21 20:05:31 +01003517 if (!opts) {
Anthony PERARD303d4e82010-09-21 20:05:31 +01003518 exit(1);
3519 }
Jan Kiszka2645c6d2011-07-25 18:11:20 +02003520 optarg = qemu_opt_get(opts, "type");
3521 if (optarg) {
3522 machine = machine_parse(optarg);
3523 }
aliguori7ba1e612008-11-05 16:04:33 +00003524 break;
Jan Kiszkaa0dac022012-10-05 14:51:45 -03003525 case QEMU_OPTION_no_kvm:
3526 olist = qemu_find_opts("machine");
3527 qemu_opts_parse(olist, "accel=tcg", 0);
3528 break;
Jan Kiszka4086bde2012-10-05 14:51:41 -03003529 case QEMU_OPTION_no_kvm_pit: {
3530 fprintf(stderr, "Warning: KVM PIT can no longer be disabled "
3531 "separately.\n");
3532 break;
3533 }
Jan Kiszkac21fb4f2012-10-05 14:51:42 -03003534 case QEMU_OPTION_no_kvm_pit_reinjection: {
3535 static GlobalProperty kvm_pit_lost_tick_policy[] = {
3536 {
3537 .driver = "kvm-pit",
3538 .property = "lost_tick_policy",
3539 .value = "discard",
3540 },
3541 { /* end of list */ }
3542 };
3543
3544 fprintf(stderr, "Warning: option deprecated, use "
3545 "lost_tick_policy property of kvm-pit instead.\n");
3546 qdev_prop_register_global_list(kvm_pit_lost_tick_policy);
3547 break;
3548 }
bellardbb36d472005-11-05 14:22:28 +00003549 case QEMU_OPTION_usb:
Peter Maydellfa5358c2012-11-22 16:48:45 +00003550 olist = qemu_find_opts("machine");
3551 qemu_opts_parse(olist, "usb=on", 0);
bellardbb36d472005-11-05 14:22:28 +00003552 break;
bellarda594cfb2005-11-06 16:13:29 +00003553 case QEMU_OPTION_usbdevice:
Peter Maydellfa5358c2012-11-22 16:48:45 +00003554 olist = qemu_find_opts("machine");
3555 qemu_opts_parse(olist, "usb=on", 0);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003556 add_device_config(DEV_USB, optarg);
3557 break;
3558 case QEMU_OPTION_device:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003559 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02003560 exit(1);
3561 }
bellarda594cfb2005-11-06 16:13:29 +00003562 break;
bellard6a00d602005-11-21 23:25:50 +00003563 case QEMU_OPTION_smp:
Andre Przywaradc6b1c02009-08-19 15:42:40 +02003564 smp_parse(optarg);
aliguorib2097002008-10-07 20:39:39 +00003565 if (smp_cpus < 1) {
bellard6a00d602005-11-21 23:25:50 +00003566 fprintf(stderr, "Invalid number of CPUs\n");
3567 exit(1);
3568 }
Jes Sorensen6be68d72009-07-23 17:03:42 +02003569 if (max_cpus < smp_cpus) {
3570 fprintf(stderr, "maxcpus must be equal to or greater than "
3571 "smp\n");
3572 exit(1);
3573 }
3574 if (max_cpus > 255) {
3575 fprintf(stderr, "Unsupported number of maxcpus\n");
3576 exit(1);
3577 }
bellard6a00d602005-11-21 23:25:50 +00003578 break;
bellard24236862006-04-30 21:28:36 +00003579 case QEMU_OPTION_vnc:
Jes Sorensen821601e2011-03-16 13:33:36 +01003580#ifdef CONFIG_VNC
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003581 display_remote++;
Jes Sorensen821601e2011-03-16 13:33:36 +01003582 vnc_display = optarg;
3583#else
3584 fprintf(stderr, "VNC support is disabled\n");
3585 exit(1);
3586#endif
3587 break;
bellard6515b202006-05-03 22:02:44 +00003588 case QEMU_OPTION_no_acpi:
3589 acpi_enabled = 0;
3590 break;
aliguori16b29ae2008-12-17 23:28:44 +00003591 case QEMU_OPTION_no_hpet:
3592 no_hpet = 1;
3593 break;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02003594 case QEMU_OPTION_balloon:
3595 if (balloon_parse(optarg) < 0) {
3596 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
3597 exit(1);
3598 }
Eduardo Habkostdf97b922009-06-10 16:34:08 -03003599 break;
bellardd1beab82006-10-02 19:44:22 +00003600 case QEMU_OPTION_no_reboot:
3601 no_reboot = 1;
3602 break;
aurel32b2f76162008-04-11 21:35:52 +00003603 case QEMU_OPTION_no_shutdown:
3604 no_shutdown = 1;
3605 break;
balrog9467cd42007-05-01 01:34:14 +00003606 case QEMU_OPTION_show_cursor:
3607 cursor_hide = 0;
3608 break;
blueswir18fcb1b92008-09-18 18:29:08 +00003609 case QEMU_OPTION_uuid:
3610 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
3611 fprintf(stderr, "Fail to parse UUID string."
3612 " Wrong format.\n");
3613 exit(1);
3614 }
3615 break;
ths9ae02552007-01-05 17:39:04 +00003616 case QEMU_OPTION_option_rom:
3617 if (nb_option_roms >= MAX_OPTION_ROMS) {
3618 fprintf(stderr, "Too many option ROMs\n");
3619 exit(1);
3620 }
Gleb Natapov2e55e842010-12-08 13:35:07 +02003621 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
Markus Armbruster49295eb2013-02-08 21:22:19 +01003622 if (!opts) {
3623 exit(1);
3624 }
Gleb Natapov2e55e842010-12-08 13:35:07 +02003625 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
3626 option_rom[nb_option_roms].bootindex =
3627 qemu_opt_get_number(opts, "bootindex", -1);
3628 if (!option_rom[nb_option_roms].name) {
3629 fprintf(stderr, "Option ROM file is not specified\n");
3630 exit(1);
3631 }
ths9ae02552007-01-05 17:39:04 +00003632 nb_option_roms++;
3633 break;
pbrook8e716212007-01-20 17:12:09 +00003634 case QEMU_OPTION_semihosting:
3635 semihosting_enabled = 1;
3636 break;
Jan Kiszka88eed342012-10-05 14:51:44 -03003637 case QEMU_OPTION_tdf:
3638 fprintf(stderr, "Warning: user space PIT time drift fix "
3639 "is no longer supported.\n");
3640 break;
thsc35734b2007-03-19 15:17:08 +00003641 case QEMU_OPTION_name:
Anthony Liguori7267c092011-08-20 22:09:37 -05003642 qemu_name = g_strdup(optarg);
Andi Kleen18894652009-07-02 09:34:17 +02003643 {
3644 char *p = strchr(qemu_name, ',');
3645 if (p != NULL) {
3646 *p++ = 0;
3647 if (strncmp(p, "process=", 8)) {
Aurelien Jarno5697f6a2010-12-27 18:29:20 +01003648 fprintf(stderr, "Unknown subargument %s to -name\n", p);
Andi Kleen18894652009-07-02 09:34:17 +02003649 exit(1);
3650 }
3651 p += 8;
Jes Sorensence798cf2010-06-10 11:42:31 +02003652 os_set_proc_name(p);
Laszlo Ersek4d8b3c62013-03-21 00:23:13 +01003653 }
3654 }
thsc35734b2007-03-19 15:17:08 +00003655 break;
blueswir166508602007-05-01 14:16:52 +00003656 case QEMU_OPTION_prom_env:
3657 if (nb_prom_envs >= MAX_PROM_ENVS) {
3658 fprintf(stderr, "Too many prom variables\n");
3659 exit(1);
3660 }
3661 prom_envs[nb_prom_envs] = optarg;
3662 nb_prom_envs++;
3663 break;
balrog2b8f2d42007-07-27 22:08:46 +00003664 case QEMU_OPTION_old_param:
3665 old_param = 1;
ths05ebd532008-01-08 19:32:16 +00003666 break;
thsf3dcfad2007-08-24 01:26:02 +00003667 case QEMU_OPTION_clock:
3668 configure_alarms(optarg);
3669 break;
bellard7e0af5d02007-11-07 16:24:33 +00003670 case QEMU_OPTION_startdate:
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02003671 configure_rtc_date_offset(optarg, 1);
3672 break;
3673 case QEMU_OPTION_rtc:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003674 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02003675 if (!opts) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02003676 exit(1);
bellard7e0af5d02007-11-07 16:24:33 +00003677 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02003678 configure_rtc(opts);
bellard7e0af5d02007-11-07 16:24:33 +00003679 break;
bellard26a5f132008-05-28 12:30:31 +00003680 case QEMU_OPTION_tb_size:
Jan Kiszkad5ab9712011-08-02 16:10:21 +02003681 tcg_tb_size = strtol(optarg, NULL, 0);
3682 if (tcg_tb_size < 0) {
3683 tcg_tb_size = 0;
3684 }
bellard26a5f132008-05-28 12:30:31 +00003685 break;
pbrook2e70f6e2008-06-29 01:03:05 +00003686 case QEMU_OPTION_icount:
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01003687 icount_option = optarg;
pbrook2e70f6e2008-06-29 01:03:05 +00003688 break;
aliguori5bb79102008-10-13 03:12:02 +00003689 case QEMU_OPTION_incoming:
3690 incoming = optarg;
Stefano Stabellini81323a62012-01-18 12:23:13 +00003691 runstate_set(RUN_STATE_INMIGRATE);
aliguori5bb79102008-10-13 03:12:02 +00003692 break;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01003693 case QEMU_OPTION_nodefaults:
3694 default_serial = 0;
3695 default_parallel = 0;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01003696 default_virtcon = 0;
Christian Borntraeger2e788492013-01-25 06:00:19 +00003697 default_sclp = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01003698 default_monitor = 0;
Gerd Hoffmanncb4522c2009-12-08 13:11:47 +01003699 default_net = 0;
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01003700 default_floppy = 0;
3701 default_cdrom = 0;
3702 default_sdcard = 0;
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +02003703 default_vga = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01003704 break;
aliguorie37630c2009-04-22 15:19:10 +00003705 case QEMU_OPTION_xen_domid:
Blue Swirlad960902010-03-29 19:23:52 +00003706 if (!(xen_available())) {
3707 printf("Option %s not supported for this target\n", popt->name);
3708 exit(1);
3709 }
aliguorie37630c2009-04-22 15:19:10 +00003710 xen_domid = atoi(optarg);
3711 break;
3712 case QEMU_OPTION_xen_create:
Blue Swirlad960902010-03-29 19:23:52 +00003713 if (!(xen_available())) {
3714 printf("Option %s not supported for this target\n", popt->name);
3715 exit(1);
3716 }
aliguorie37630c2009-04-22 15:19:10 +00003717 xen_mode = XEN_CREATE;
3718 break;
3719 case QEMU_OPTION_xen_attach:
Blue Swirlad960902010-03-29 19:23:52 +00003720 if (!(xen_available())) {
3721 printf("Option %s not supported for this target\n", popt->name);
3722 exit(1);
3723 }
aliguorie37630c2009-04-22 15:19:10 +00003724 xen_mode = XEN_ATTACH;
3725 break;
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003726 case QEMU_OPTION_trace:
Lluíse4858972011-08-31 20:31:03 +02003727 {
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003728 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
Lluíse4858972011-08-31 20:31:03 +02003729 if (!opts) {
3730 exit(1);
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003731 }
Lluís23d15e82011-08-31 20:31:31 +02003732 trace_events = qemu_opt_get(opts, "events");
Lluíse4858972011-08-31 20:31:03 +02003733 trace_file = qemu_opt_get(opts, "file");
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003734 break;
Lluíse4858972011-08-31 20:31:03 +02003735 }
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003736 case QEMU_OPTION_readconfig:
3737 {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01003738 int ret = qemu_read_config_file(optarg);
3739 if (ret < 0) {
3740 fprintf(stderr, "read config %s: %s\n", optarg,
3741 strerror(-ret));
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003742 exit(1);
3743 }
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003744 break;
3745 }
Gerd Hoffmann29b00402010-03-11 11:13:27 -03003746 case QEMU_OPTION_spice:
3747 olist = qemu_find_opts("spice");
3748 if (!olist) {
3749 fprintf(stderr, "spice is not supported by this qemu build.\n");
3750 exit(1);
3751 }
3752 opts = qemu_opts_parse(olist, optarg, 0);
3753 if (!opts) {
Gerd Hoffmann29b00402010-03-11 11:13:27 -03003754 exit(1);
3755 }
Gerd Hoffmannf963e4d2013-02-25 16:02:30 +01003756 display_remote++;
Gerd Hoffmann29b00402010-03-11 11:13:27 -03003757 break;
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003758 case QEMU_OPTION_writeconfig:
3759 {
3760 FILE *fp;
3761 if (strcmp(optarg, "-") == 0) {
3762 fp = stdout;
3763 } else {
3764 fp = fopen(optarg, "w");
3765 if (fp == NULL) {
3766 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
3767 exit(1);
3768 }
3769 }
3770 qemu_config_write(fp);
3771 fclose(fp);
3772 break;
3773 }
Anthony Liguoric7f0f3b2012-03-28 15:42:02 +02003774 case QEMU_OPTION_qtest:
3775 qtest_chrdev = optarg;
3776 break;
3777 case QEMU_OPTION_qtest_log:
3778 qtest_log = optarg;
3779 break;
Eduardo Otubo7d76ad42012-08-14 18:44:08 -03003780 case QEMU_OPTION_sandbox:
3781 opts = qemu_opts_parse(qemu_find_opts("sandbox"), optarg, 1);
3782 if (!opts) {
Markus Armbruster49295eb2013-02-08 21:22:19 +01003783 exit(1);
Eduardo Otubo7d76ad42012-08-14 18:44:08 -03003784 }
3785 break;
Corey Bryant587ed6b2012-10-18 15:19:34 -04003786 case QEMU_OPTION_add_fd:
3787#ifndef _WIN32
3788 opts = qemu_opts_parse(qemu_find_opts("add-fd"), optarg, 0);
3789 if (!opts) {
Markus Armbruster49295eb2013-02-08 21:22:19 +01003790 exit(1);
Corey Bryant587ed6b2012-10-18 15:19:34 -04003791 }
3792#else
3793 error_report("File descriptor passing is disabled on this "
3794 "platform");
3795 exit(1);
3796#endif
3797 break;
Anthony Liguori68d98d32012-06-25 14:36:33 -05003798 case QEMU_OPTION_object:
3799 opts = qemu_opts_parse(qemu_find_opts("object"), optarg, 1);
Markus Armbruster49295eb2013-02-08 21:22:19 +01003800 if (!opts) {
3801 exit(1);
3802 }
Anthony Liguori68d98d32012-06-25 14:36:33 -05003803 break;
Satoru Moriya888a6bc2013-04-19 16:42:06 +02003804 case QEMU_OPTION_realtime:
3805 opts = qemu_opts_parse(qemu_find_opts("realtime"), optarg, 0);
3806 if (!opts) {
3807 exit(1);
3808 }
3809 configure_realtime(opts);
3810 break;
Jes Sorensen59a52642010-06-10 11:42:25 +02003811 default:
3812 os_parse_cmd_args(popt->index, optarg);
bellardcd6f1162004-05-13 22:02:20 +00003813 }
bellard0824d6f2003-06-24 13:42:40 +00003814 }
3815 }
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01003816 loc_set_none();
bellard330d0412003-07-26 18:11:40 +00003817
Paolo Bonzini1c537862012-10-30 00:17:12 +01003818 if (qemu_init_main_loop()) {
3819 fprintf(stderr, "qemu_init_main_loop failed\n");
3820 exit(1);
3821 }
3822
Eduardo Otubo7d76ad42012-08-14 18:44:08 -03003823 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 0)) {
3824 exit(1);
3825 }
3826
Corey Bryant587ed6b2012-10-18 15:19:34 -04003827#ifndef _WIN32
3828 if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL, 1)) {
3829 exit(1);
3830 }
3831
3832 if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd, NULL, 1)) {
3833 exit(1);
3834 }
3835#endif
3836
Dunrong Huangfb7c2692012-07-24 00:42:20 +08003837 if (machine == NULL) {
3838 fprintf(stderr, "No machine found.\n");
3839 exit(1);
3840 }
3841
Crístian Viana93bfef42012-05-30 00:35:51 -03003842 if (machine->hw_version) {
3843 qemu_set_version(machine->hw_version);
3844 }
3845
Anthony Liguori68d98d32012-06-25 14:36:33 -05003846 if (qemu_opts_foreach(qemu_find_opts("object"),
3847 object_create, NULL, 0) != 0) {
3848 exit(1);
3849 }
3850
Eduardo Habkostecf40be2012-03-09 16:19:07 -03003851 /* Init CPU def lists, based on config
3852 * - Must be called after all the qemu_read_config_file() calls
3853 * - Must be called before list_cpus()
3854 * - Must be called before machine->init()
3855 */
3856 cpudef_init();
3857
Peter Maydellc8057f92012-08-02 13:45:54 +01003858 if (cpu_model && is_help_option(cpu_model)) {
Eduardo Habkost1d6528a2012-03-21 09:33:40 -03003859 list_cpus(stdout, &fprintf, cpu_model);
Eduardo Habkostecf40be2012-03-09 16:19:07 -03003860 exit(0);
3861 }
3862
Matthew Fernandezc235d732011-06-07 16:32:40 +00003863 /* Open the logfile at this point, if necessary. We can't open the logfile
3864 * when encountering either of the logging options (-d or -D) because the
3865 * other one may be encountered later on the command line, changing the
3866 * location or level of logging.
3867 */
3868 if (log_mask) {
Peter Maydellb946bff2013-02-11 16:41:24 +00003869 int mask;
Matthew Fernandezc235d732011-06-07 16:32:40 +00003870 if (log_file) {
Peter Maydell9a7e5422013-02-11 16:41:20 +00003871 qemu_set_log_filename(log_file);
Matthew Fernandezc235d732011-06-07 16:32:40 +00003872 }
Peter Maydellb946bff2013-02-11 16:41:24 +00003873
3874 mask = qemu_str_to_log_mask(log_mask);
3875 if (!mask) {
3876 qemu_print_log_usage(stdout);
3877 exit(1);
3878 }
3879 qemu_set_log(mask);
Matthew Fernandezc235d732011-06-07 16:32:40 +00003880 }
3881
Lluís23d15e82011-08-31 20:31:31 +02003882 if (!trace_backend_init(trace_events, trace_file)) {
Lluíse4858972011-08-31 20:31:03 +02003883 exit(1);
Stefan Hajnoczi31d3c9b2011-03-13 20:14:30 +00003884 }
Stefan Hajnoczi0b5538c2011-02-26 18:38:39 +00003885
Paul Brook5cea8592009-05-30 00:52:44 +01003886 /* If no data_dir is specified then try to find it relative to the
3887 executable path. */
Gerd Hoffmann45240512013-03-08 11:42:24 +01003888 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
3889 data_dir[data_dir_idx] = os_find_datadir(argv[0]);
3890 if (data_dir[data_dir_idx] != NULL) {
3891 data_dir_idx++;
3892 }
Paul Brook5cea8592009-05-30 00:52:44 +01003893 }
Stefan Weil60474fb2011-09-04 15:17:46 +02003894 /* If all else fails use the install path specified when building. */
Gerd Hoffmann45240512013-03-08 11:42:24 +01003895 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
3896 data_dir[data_dir_idx++] = CONFIG_QEMU_DATADIR;
Paul Brook5cea8592009-05-30 00:52:44 +01003897 }
3898
Jes Sorensen6be68d72009-07-23 17:03:42 +02003899 /*
3900 * Default to max_cpus = smp_cpus, in case the user doesn't
3901 * specify a max_cpus value.
3902 */
3903 if (!max_cpus)
3904 max_cpus = smp_cpus;
3905
balrog3d878ca2008-10-28 10:59:59 +00003906 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
aliguorib2097002008-10-07 20:39:39 +00003907 if (smp_cpus > machine->max_cpus) {
3908 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
3909 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
3910 machine->max_cpus);
3911 exit(1);
3912 }
3913
Anthony PERARD67b724e2010-11-22 15:44:15 +00003914 /*
3915 * Get the default machine options from the machine if it is not already
3916 * specified either by the configuration file or by the command line.
3917 */
3918 if (machine->default_machine_opts) {
Jan Kiszka25de5932012-01-27 19:55:43 +01003919 qemu_opts_set_defaults(qemu_find_opts("machine"),
3920 machine->default_machine_opts, 0);
Anthony PERARD67b724e2010-11-22 15:44:15 +00003921 }
3922
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003923 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
3924 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01003925
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003926 if (machine->no_serial) {
3927 default_serial = 0;
3928 }
3929 if (machine->no_parallel) {
3930 default_parallel = 0;
3931 }
3932 if (!machine->use_virtcon) {
3933 default_virtcon = 0;
3934 }
Alexander Graf3ef669e2013-01-24 12:18:52 +01003935 if (!machine->use_sclp) {
3936 default_sclp = 0;
3937 }
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01003938 if (machine->no_floppy) {
3939 default_floppy = 0;
3940 }
3941 if (machine->no_cdrom) {
3942 default_cdrom = 0;
3943 }
3944 if (machine->no_sdcard) {
3945 default_sdcard = 0;
3946 }
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003947
Michael Tokarevab51b1d2012-12-30 12:48:14 +04003948 if (is_daemonized()) {
3949 /* According to documentation and historically, -nographic redirects
3950 * serial port, parallel port and monitor to stdio, which does not work
3951 * with -daemonize. We can redirect these to null instead, but since
3952 * -nographic is legacy, let's just error out.
3953 * We disallow -nographic only if all other ports are not redirected
3954 * explicitly, to not break existing legacy setups which uses
3955 * -nographic _and_ redirects all ports explicitly - this is valid
3956 * usage, -nographic is just a no-op in this case.
3957 */
3958 if (display_type == DT_NOGRAPHIC
3959 && (default_parallel || default_serial
3960 || default_monitor || default_virtcon)) {
3961 fprintf(stderr, "-nographic can not be used with -daemonize\n");
3962 exit(1);
3963 }
3964#ifdef CONFIG_CURSES
3965 if (display_type == DT_CURSES) {
3966 fprintf(stderr, "curses display can not be used with -daemonize\n");
3967 exit(1);
3968 }
3969#endif
3970 }
3971
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003972 if (display_type == DT_NOGRAPHIC) {
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01003973 if (default_parallel)
3974 add_device_config(DEV_PARALLEL, "null");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003975 if (default_serial && default_monitor) {
3976 add_device_config(DEV_SERIAL, "mon:stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003977 } else if (default_virtcon && default_monitor) {
3978 add_device_config(DEV_VIRTCON, "mon:stdio");
Alexander Graf3ef669e2013-01-24 12:18:52 +01003979 } else if (default_sclp && default_monitor) {
3980 add_device_config(DEV_SCLP, "mon:stdio");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003981 } else {
3982 if (default_serial)
3983 add_device_config(DEV_SERIAL, "stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003984 if (default_virtcon)
3985 add_device_config(DEV_VIRTCON, "stdio");
Alexander Graf3ef669e2013-01-24 12:18:52 +01003986 if (default_sclp) {
3987 add_device_config(DEV_SCLP, "stdio");
3988 }
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003989 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01003990 monitor_parse("stdio", "readline");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003991 }
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01003992 } else {
3993 if (default_serial)
3994 add_device_config(DEV_SERIAL, "vc:80Cx24C");
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01003995 if (default_parallel)
3996 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
Gerd Hoffmannabdeed02009-12-08 13:11:43 +01003997 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01003998 monitor_parse("vc:80Cx24C", "readline");
Alexander Graf38536da2009-12-17 13:06:08 +01003999 if (default_virtcon)
4000 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
Alexander Graf3ef669e2013-01-24 12:18:52 +01004001 if (default_sclp) {
4002 add_device_config(DEV_SCLP, "vc:80Cx24C");
4003 }
aliguoribc0129d2008-08-01 15:12:34 +00004004 }
4005
Anthony Liguori15546422013-02-20 07:43:25 -06004006 if (display_type == DT_DEFAULT && !display_remote) {
4007#if defined(CONFIG_GTK)
4008 display_type = DT_GTK;
4009#elif defined(CONFIG_SDL) || defined(CONFIG_COCOA)
4010 display_type = DT_SDL;
4011#elif defined(CONFIG_VNC)
4012 vnc_display = "localhost:0,to=99";
4013 show_vnc_port = 1;
4014#else
4015 display_type = DT_NONE;
4016#endif
4017 }
4018
Peter Wu047d4e12013-06-11 10:55:08 +02004019 if ((no_frame || alt_grab || ctrl_grab) && display_type != DT_SDL) {
4020 fprintf(stderr, "-no-frame, -alt-grab and -ctrl-grab are only valid "
4021 "for SDL, ignoring option\n");
4022 }
4023 if (no_quit && (display_type != DT_GTK && display_type != DT_SDL)) {
4024 fprintf(stderr, "-no-quit is only valid for GTK and SDL, "
4025 "ignoring option\n");
4026 }
4027
Anthony Liguori15546422013-02-20 07:43:25 -06004028#if defined(CONFIG_GTK)
4029 if (display_type == DT_GTK) {
4030 early_gtk_display_init();
4031 }
4032#endif
4033
TeLeMana5829fd2010-04-15 12:37:55 +08004034 socket_init();
4035
Gerd Hoffmann3329f072010-08-20 13:52:01 +02004036 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01004037 exit(1);
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07004038#ifdef CONFIG_VIRTFS
Gerd Hoffmann3329f072010-08-20 13:52:01 +02004039 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +05304040 exit(1);
4041 }
4042#endif
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01004043
Jes Sorenseneb505be2010-06-10 11:42:28 +02004044 os_daemonize();
ths71e3ceb2006-12-22 02:11:31 +00004045
thsaa26bb22007-03-25 21:33:06 +00004046 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
Jes Sorenseneb505be2010-06-10 11:42:28 +02004047 os_pidfile_error();
ths93815bc2007-03-19 15:58:31 +00004048 exit(1);
4049 }
4050
Jan Kiszka0ac543d2011-08-15 16:18:57 -07004051 /* init the memory */
4052 if (ram_size == 0) {
4053 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
4054 }
4055
Bruce Rogers3d1d9652012-08-09 12:47:40 -06004056 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0)
4057 != 0) {
4058 exit(0);
4059 }
4060
Anthony PERARD303d4e82010-09-21 20:05:31 +01004061 configure_accelerator();
Marcelo Tosatti214910a2009-09-18 02:41:23 -03004062
Edgar E. Iglesiasa907cf52013-04-15 21:28:17 +02004063 if (!qtest_enabled() && qtest_chrdev) {
4064 qtest_init();
4065 }
4066
Peter Maydell967c0da2012-02-22 22:40:00 +00004067 machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
4068 if (machine_opts) {
4069 kernel_filename = qemu_opt_get(machine_opts, "kernel");
4070 initrd_filename = qemu_opt_get(machine_opts, "initrd");
4071 kernel_cmdline = qemu_opt_get(machine_opts, "append");
4072 } else {
4073 kernel_filename = initrd_filename = kernel_cmdline = NULL;
4074 }
4075
Markus Armbruster8281abd2013-06-14 13:15:03 +02004076 if (!boot_order) {
4077 boot_order = machine->boot_order;
4078 }
4079 opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
4080 if (opts) {
4081 char *normal_boot_order;
4082 const char *order, *once;
4083
4084 order = qemu_opt_get(opts, "order");
4085 if (order) {
4086 validate_bootdevices(order);
4087 boot_order = order;
4088 }
4089
4090 once = qemu_opt_get(opts, "once");
4091 if (once) {
4092 validate_bootdevices(once);
4093 normal_boot_order = g_strdup(boot_order);
4094 boot_order = once;
Markus Armbruster083b79c2013-06-14 13:15:04 +02004095 qemu_register_reset(restore_boot_order, normal_boot_order);
Markus Armbruster8281abd2013-06-14 13:15:03 +02004096 }
4097
4098 boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu);
4099 }
4100
Peter Maydella0abe472012-02-08 05:41:39 +00004101 if (!kernel_cmdline) {
4102 kernel_cmdline = "";
4103 }
4104
bellarda20dd502003-09-30 21:07:02 +00004105 linux_boot = (kernel_filename != NULL);
balrog6c41b272007-11-17 12:12:29 +00004106
thsf8d39c02008-07-03 10:01:15 +00004107 if (!linux_boot && *kernel_cmdline != '\0') {
4108 fprintf(stderr, "-append only allowed with -kernel option\n");
4109 exit(1);
4110 }
4111
4112 if (!linux_boot && initrd_filename != NULL) {
4113 fprintf(stderr, "-initrd only allowed with -kernel option\n");
4114 exit(1);
4115 }
4116
Grant Likely412beee2012-03-02 11:56:38 +00004117 if (!linux_boot && machine_opts && qemu_opt_get(machine_opts, "dtb")) {
4118 fprintf(stderr, "-dtb only allowed with -kernel option\n");
4119 exit(1);
4120 }
4121
Jes Sorensen9156d762010-06-10 11:42:30 +02004122 os_set_line_buffering();
ths3b46e622007-09-17 08:09:54 +00004123
Paolo Bonzini49cf5722012-11-02 15:43:24 +01004124 qemu_init_cpu_loop();
4125 qemu_mutex_lock_iothread();
4126
Alon Levyad1be892012-03-14 20:33:37 +02004127#ifdef CONFIG_SPICE
4128 /* spice needs the timers to be initialized by this point */
4129 qemu_spice_init();
4130#endif
4131
Max Filippov0abe9052011-11-10 15:38:42 +04004132 if (icount_option && (kvm_enabled() || xen_enabled())) {
4133 fprintf(stderr, "-icount is not allowed with kvm or xen\n");
4134 exit(1);
4135 }
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01004136 configure_icount(icount_option);
pbrook634fce92006-07-15 17:40:09 +00004137
Amos Kongf30dbae2012-12-11 22:20:15 +08004138 /* clean up network at qemu process termination */
4139 atexit(&net_cleanup);
4140
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01004141 if (net_init_clients() < 0) {
4142 exit(1);
bellard702c6512004-04-02 21:21:32 +00004143 }
bellardf1510b22003-06-25 00:07:40 +00004144
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05004145#ifdef CONFIG_TPM
4146 if (tpm_init() < 0) {
4147 exit(1);
4148 }
4149#endif
4150
balrogdc72ac12008-11-09 00:04:26 +00004151 /* init the bluetooth world */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02004152 if (foreach_device_config(DEV_BT, bt_parse))
4153 exit(1);
balrogdc72ac12008-11-09 00:04:26 +00004154
Anthony PERARD834e76e2011-07-20 08:17:44 +00004155 if (!xen_enabled()) {
4156 /* On 32-bit hosts, QEMU is limited by virtual address space */
4157 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
4158 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
4159 exit(1);
4160 }
4161 }
balrog7fb4fdc2008-04-24 17:59:27 +00004162
Jan Kiszkad5ab9712011-08-02 16:10:21 +02004163 cpu_exec_init_all();
bellard26a5f132008-05-28 12:30:31 +00004164
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +02004165 blk_mig_init();
4166
ths96d30e42007-01-07 20:42:14 +00004167 /* open the virtual block devices */
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02004168 if (snapshot)
Gerd Hoffmann3329f072010-08-20 13:52:01 +02004169 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
Christian Borntraeger2d0d2832012-11-20 15:30:34 +01004170 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func,
4171 &machine->block_default_type, 1) != 0) {
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02004172 exit(1);
Christian Borntraeger2d0d2832012-11-20 15:30:34 +01004173 }
balrog3e3d5812007-04-30 02:09:25 +00004174
Christian Borntraeger3c42ea62012-11-22 21:02:55 +01004175 default_drive(default_cdrom, snapshot, machine->block_default_type, 2,
4176 CDROM_OPTS);
4177 default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS);
4178 default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS);
Markus Armbruster4e5d9b52011-01-28 11:21:45 +01004179
Juan Quintela7908c782012-06-26 18:46:10 +02004180 register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00004181
aliguori268a3622009-04-21 22:30:27 +00004182 if (nb_numa_nodes > 0) {
4183 int i;
4184
Sasha Levinea0e5412011-06-29 23:29:39 -04004185 if (nb_numa_nodes > MAX_NODES) {
4186 nb_numa_nodes = MAX_NODES;
aliguori268a3622009-04-21 22:30:27 +00004187 }
4188
4189 /* If no memory size if given for any node, assume the default case
4190 * and distribute the available memory equally across all nodes
4191 */
4192 for (i = 0; i < nb_numa_nodes; i++) {
4193 if (node_mem[i] != 0)
4194 break;
4195 }
4196 if (i == nb_numa_nodes) {
4197 uint64_t usedmem = 0;
4198
4199 /* On Linux, the each node's border has to be 8MB aligned,
4200 * the final node gets the rest.
4201 */
4202 for (i = 0; i < nb_numa_nodes - 1; i++) {
4203 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
4204 usedmem += node_mem[i];
4205 }
4206 node_mem[i] = ram_size - usedmem;
4207 }
4208
4209 for (i = 0; i < nb_numa_nodes; i++) {
Chegu Vinodee785fe2012-07-16 21:31:30 -07004210 if (!bitmap_empty(node_cpumask[i], MAX_CPUMASK_BITS)) {
aliguori268a3622009-04-21 22:30:27 +00004211 break;
Chegu Vinodee785fe2012-07-16 21:31:30 -07004212 }
aliguori268a3622009-04-21 22:30:27 +00004213 }
4214 /* assigning the VCPUs round-robin is easier to implement, guest OSes
4215 * must cope with this anyway, because there are BIOSes out there in
4216 * real machines which also use this scheme.
4217 */
4218 if (i == nb_numa_nodes) {
Vasilis Liaskovitis991dfef2011-10-26 14:19:00 +02004219 for (i = 0; i < max_cpus; i++) {
Chegu Vinodee785fe2012-07-16 21:31:30 -07004220 set_bit(i, node_cpumask[i % nb_numa_nodes]);
aliguori268a3622009-04-21 22:30:27 +00004221 }
4222 }
4223 }
4224
Gerd Hoffmann3329f072010-08-20 13:52:01 +02004225 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
Jan Kiszka157b9312010-04-06 16:55:53 +02004226 exit(1);
4227 }
4228
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01004229 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
4230 exit(1);
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01004231 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
4232 exit(1);
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01004233 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
4234 exit(1);
Alexander Graf3ef669e2013-01-24 12:18:52 +01004235 if (foreach_device_config(DEV_SCLP, sclp_parse) < 0) {
4236 exit(1);
4237 }
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08004238 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
4239 exit(1);
aliguori2796dae2009-01-16 20:23:27 +00004240
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +02004241 /* If no default VGA is requested, the default is "none". */
Aurelien Jarno3605ded2012-09-10 01:01:44 +02004242 if (default_vga) {
4243 if (cirrus_vga_available()) {
4244 vga_model = "cirrus";
4245 } else if (vga_available()) {
4246 vga_model = "std";
4247 }
Blue Swirla369da52011-09-27 19:15:42 +00004248 }
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +02004249 select_vgahw(vga_model);
Blue Swirla369da52011-09-27 19:15:42 +00004250
Markus Armbruster09aaa162009-08-21 10:31:34 +02004251 if (watchdog) {
4252 i = select_watchdog(watchdog);
4253 if (i > 0)
4254 exit (i == 1 ? 1 : 0);
4255 }
4256
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02004257 if (machine->compat_props) {
Gerd Hoffmann458fb672009-12-08 13:11:33 +01004258 qdev_prop_register_global_list(machine->compat_props);
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02004259 }
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01004260 qemu_add_globals();
4261
Anthony Liguori1de81d22011-12-19 16:37:46 -06004262 qdev_machine_init();
4263
Eduardo Habkost5f072e12012-10-15 17:22:02 -03004264 QEMUMachineInitArgs args = { .ram_size = ram_size,
Markus Armbruster8281abd2013-06-14 13:15:03 +02004265 .boot_device = boot_order,
Eduardo Habkost5f072e12012-10-15 17:22:02 -03004266 .kernel_filename = kernel_filename,
4267 .kernel_cmdline = kernel_cmdline,
4268 .initrd_filename = initrd_filename,
4269 .cpu_model = cpu_model };
4270 machine->init(&args);
aliguori3023f332009-01-16 19:04:14 +00004271
Paolo Bonzinib3e6d592013-04-18 18:44:04 +02004272 audio_init();
4273
Jan Kiszkaea375f92010-03-01 19:10:30 +01004274 cpu_synchronize_all_post_init();
aliguori268a3622009-04-21 22:30:27 +00004275
Blue Swirl87d0a282010-03-27 18:24:45 +00004276 set_numa_modes();
aliguori268a3622009-04-21 22:30:27 +00004277
aliguori6f338c32009-02-11 15:21:54 +00004278 current_machine = machine;
4279
aliguori3023f332009-01-16 19:04:14 +00004280 /* init USB devices */
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00004281 if (usb_enabled(false)) {
Markus Armbruster07527062009-10-06 12:16:57 +01004282 if (foreach_device_config(DEV_USB, usb_parse) < 0)
4283 exit(1);
aliguori3023f332009-01-16 19:04:14 +00004284 }
4285
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02004286 /* init generic devices */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02004287 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02004288 exit(1);
4289
Markus Armbruster668680f2010-02-11 14:44:58 +01004290 net_check_clients();
4291
Gerd Hoffmann64840c62013-03-07 17:08:29 +01004292 ds = init_displaystate();
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004293
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02004294 /* init local displays */
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004295 switch (display_type) {
4296 case DT_NOGRAPHIC:
4297 break;
4298#if defined(CONFIG_CURSES)
4299 case DT_CURSES:
Michael Tokarevab51b1d2012-12-30 12:48:14 +04004300 curses_display_init(ds, full_screen);
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004301 break;
4302#endif
bellard5b0753e2005-03-01 21:37:28 +00004303#if defined(CONFIG_SDL)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004304 case DT_SDL:
4305 sdl_display_init(ds, full_screen, no_frame);
4306 break;
bellard5b0753e2005-03-01 21:37:28 +00004307#elif defined(CONFIG_COCOA)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004308 case DT_SDL:
4309 cocoa_display_init(ds, full_screen);
4310 break;
bellard313aa562003-08-10 21:52:11 +00004311#endif
Anthony Liguori15546422013-02-20 07:43:25 -06004312#if defined(CONFIG_GTK)
4313 case DT_GTK:
Peter Wu787ba4f2013-06-10 20:04:43 +02004314 gtk_display_init(ds, full_screen);
Anthony Liguori15546422013-02-20 07:43:25 -06004315 break;
4316#endif
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02004317 default:
4318 break;
4319 }
4320
Gleb Natapov0ce235a2011-03-31 11:27:23 +02004321 /* must be after terminal init, SDL library changes signal handlers */
4322 os_setup_signal_handling();
4323
Jes Sorensen821601e2011-03-16 13:33:36 +01004324#ifdef CONFIG_VNC
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02004325 /* init remote displays */
4326 if (vnc_display) {
Paolo Bonzini2d55f0e2012-10-02 10:17:21 +02004327 Error *local_err = NULL;
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004328 vnc_display_init(ds);
Paolo Bonzini2d55f0e2012-10-02 10:17:21 +02004329 vnc_display_open(ds, vnc_display, &local_err);
4330 if (local_err != NULL) {
4331 fprintf(stderr, "Failed to start VNC server on `%s': %s\n",
4332 vnc_display, error_get_pretty(local_err));
4333 error_free(local_err);
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004334 exit(1);
Amos Kong94b204c2012-06-30 10:02:20 +08004335 }
Anthony Liguorif92f8af2009-05-20 13:01:02 -05004336
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004337 if (show_vnc_port) {
4338 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
Anthony Liguorif92f8af2009-05-20 13:01:02 -05004339 }
bellard313aa562003-08-10 21:52:11 +00004340 }
Jes Sorensen821601e2011-03-16 13:33:36 +01004341#endif
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02004342#ifdef CONFIG_SPICE
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +02004343 if (using_spice && !qxl_enabled) {
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02004344 qemu_spice_display_init(ds);
4345 }
4346#endif
aliguori5b08fc12008-08-21 20:08:03 +00004347
Markus Armbrusteref0c4a02012-02-07 15:09:13 +01004348 if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
aliguori59030a82009-04-05 18:43:41 +00004349 exit(1);
balrog45669e02007-07-02 13:20:17 +00004350 }
balrog45669e02007-07-02 13:20:17 +00004351
Gerd Hoffmann3418bd22009-09-25 21:42:41 +02004352 qdev_machine_creation_done();
4353
Gerd Hoffmann15ff7702009-12-14 16:07:35 +01004354 if (rom_load_all() != 0) {
4355 fprintf(stderr, "rom loading failed\n");
4356 exit(1);
4357 }
Gerd Hoffmann45a50b12009-10-01 16:42:33 +02004358
Isaku Yamahata80376c32010-12-20 14:33:35 +09004359 /* TODO: once all bus devices are qdevified, this should be done
4360 * when bus is created by qdev.c */
4361 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
Gleb Natapov4cab9462010-12-08 13:35:08 +02004362 qemu_run_machine_init_done_notifiers();
4363
Jan Kiszkae063eb12011-06-14 18:29:43 +02004364 qemu_system_reset(VMRESET_SILENT);
Juan Quintela05f24012009-08-20 19:42:22 +02004365 if (loadvm) {
Markus Armbruster03cd4652010-02-17 16:24:10 +01004366 if (load_vmstate(loadvm) < 0) {
Juan Quintela05f24012009-08-20 19:42:22 +02004367 autostart = 0;
4368 }
4369 }
bellardd63d3072004-10-03 13:29:03 +00004370
Glauber Costa2bb8c102009-07-24 16:20:23 -04004371 if (incoming) {
Paolo Bonzini43eaae22012-10-02 18:21:18 +02004372 Error *local_err = NULL;
4373 qemu_start_incoming_migration(incoming, &local_err);
4374 if (local_err) {
4375 fprintf(stderr, "-incoming %s: %s\n", incoming, error_get_pretty(local_err));
4376 error_free(local_err);
4377 exit(1);
Juan Quintela8ca5e802010-06-09 14:10:54 +02004378 }
Avi Kivity6b99dad2009-08-09 14:39:20 +03004379 } else if (autostart) {
aliguoric0f4ce72009-03-05 23:01:01 +00004380 vm_start();
Avi Kivity6b99dad2009-08-09 14:39:20 +03004381 }
thsffd843b2006-12-21 19:46:43 +00004382
Jes Sorenseneb505be2010-06-10 11:42:28 +02004383 os_setup_post();
ths71e3ceb2006-12-22 02:11:31 +00004384
bellard8a7ddc32004-03-31 19:00:16 +00004385 main_loop();
Paolo Bonzini99435902011-09-12 14:03:13 +02004386 bdrv_close_all();
4387 pause_all_vcpus();
wayne3d3b8302011-07-27 18:04:55 +08004388 res_free();
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05004389#ifdef CONFIG_TPM
4390 tpm_cleanup();
4391#endif
thsb46a8902007-10-21 23:20:45 +00004392
bellard0824d6f2003-06-24 13:42:40 +00004393 return 0;
4394}