blob: 7511e7036c1f3a932b5510d599d5e9ba93a63ff8 [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;
Marcelo Tosattic9027602010-03-01 20:25:08 -0300191int mem_prealloc = 0; /* force preallocation of physical target memory */
bellardc4b1fcc2004-03-14 21:44:30 +0000192int nb_nics;
bellard7c9d8e02005-11-15 22:16:05 +0000193NICInfo nd_table[MAX_NICS];
Paolo Bonzinid399f672009-07-27 23:17:51 +0200194int autostart;
balrogf6503052008-02-17 11:42:19 +0000195static int rtc_utc = 1;
196static int rtc_date_offset = -1; /* -1 means no change */
Alex Bligh884f17c2013-08-21 16:03:04 +0100197QEMUClockType rtc_clock;
Gerd Hoffmann64465292009-12-08 13:11:45 +0100198int vga_interface_type = VGA_NONE;
blueswir1dbed7e42008-10-01 19:38:09 +0000199static int full_screen = 0;
200static int no_frame = 0;
ths667acca2006-12-11 02:08:05 +0000201int no_quit = 0;
bellard8d11df92004-08-24 21:13:40 +0000202CharDriverState *serial_hds[MAX_SERIAL_PORTS];
bellard6508fe52005-01-15 12:02:56 +0000203CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
aliguori9ede2fd2009-01-15 20:05:25 +0000204CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
Alexander Graf3ef669e2013-01-24 12:18:52 +0100205CharDriverState *sclp_hds[MAX_SCLP_CONSOLES];
bellarda09db212005-04-30 16:10:35 +0000206int win2k_install_hack = 0;
aurel321b530a62009-04-05 20:08:59 +0000207int singlestep = 0;
bellard6a00d602005-11-21 23:25:50 +0000208int smp_cpus = 1;
Jes Sorensen6be68d72009-07-23 17:03:42 +0200209int max_cpus = 0;
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200210int smp_cores = 1;
211int smp_threads = 1;
Jes Sorensen821601e2011-03-16 13:33:36 +0100212#ifdef CONFIG_VNC
ths73fc9742006-12-22 02:09:07 +0000213const char *vnc_display;
Jes Sorensen821601e2011-03-16 13:33:36 +0100214#endif
bellard6515b202006-05-03 22:02:44 +0000215int acpi_enabled = 1;
aliguori16b29ae2008-12-17 23:28:44 +0000216int no_hpet = 0;
bellard52ca8d62006-06-14 16:03:05 +0000217int fd_bootchk = 1;
Blue Swirl4fdcac02012-10-28 11:04:47 +0000218static int no_reboot;
aurel32b2f76162008-04-11 21:35:52 +0000219int no_shutdown = 0;
balrog9467cd42007-05-01 01:34:14 +0000220int cursor_hide = 1;
balroga171fe32007-04-30 01:48:07 +0000221int graphic_rotate = 0;
Markus Armbruster09aaa162009-08-21 10:31:34 +0200222const char *watchdog;
Gleb Natapov2e55e842010-12-08 13:35:07 +0200223QEMUOptionRom option_rom[MAX_OPTION_ROMS];
ths9ae02552007-01-05 17:39:04 +0000224int nb_option_roms;
pbrook8e716212007-01-20 17:12:09 +0000225int semihosting_enabled = 0;
balrog2b8f2d42007-07-27 22:08:46 +0000226int old_param = 0;
thsc35734b2007-03-19 15:17:08 +0000227const char *qemu_name;
ths3780e192007-06-21 21:08:02 +0000228int alt_grab = 0;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -0500229int ctrl_grab = 0;
blueswir166508602007-05-01 14:16:52 +0000230unsigned int nb_prom_envs = 0;
231const char *prom_envs[MAX_PROM_ENVS];
Jan Kiszka95387492009-07-02 00:19:02 +0200232int boot_menu;
Amos Kongc8a6ae82013-03-19 14:23:27 +0800233bool boot_strict;
wayne3d3b8302011-07-27 18:04:55 +0800234uint8_t *boot_splash_filedata;
Markus Armbrusterd09acb92013-01-23 18:25:08 +0100235size_t boot_splash_filedata_size;
wayne3d3b8302011-07-27 18:04:55 +0800236uint8_t qemu_extra_params_fw[2];
bellard0824d6f2003-06-24 13:42:40 +0000237
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200238typedef struct FWBootEntry FWBootEntry;
239
240struct FWBootEntry {
241 QTAILQ_ENTRY(FWBootEntry) link;
242 int32_t bootindex;
243 DeviceState *dev;
244 char *suffix;
245};
246
Blue Swirl4fdcac02012-10-28 11:04:47 +0000247static QTAILQ_HEAD(, FWBootEntry) fw_boot_order =
248 QTAILQ_HEAD_INITIALIZER(fw_boot_order);
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200249
aliguori268a3622009-04-21 22:30:27 +0000250int nb_numa_nodes;
251uint64_t node_mem[MAX_NODES];
Chegu Vinodee785fe2012-07-16 21:31:30 -0700252unsigned long *node_cpumask[MAX_NODES];
aliguori268a3622009-04-21 22:30:27 +0000253
blueswir18fcb1b92008-09-18 18:29:08 +0000254uint8_t qemu_uuid[16];
Markus Armbrusterfc3b3292013-08-16 15:18:31 +0200255bool qemu_uuid_set;
blueswir18fcb1b92008-09-18 18:29:08 +0000256
Jan Kiszka76e30d02009-07-02 00:19:02 +0200257static QEMUBootSetHandler *boot_set_handler;
258static void *boot_set_opaque;
259
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +0200260static NotifierList exit_notifiers =
261 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
262
Gleb Natapov4cab9462010-12-08 13:35:08 +0200263static NotifierList machine_init_done_notifiers =
264 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
265
liguangd5286af2013-01-24 13:03:27 +0800266static bool tcg_allowed = true;
liguangd5286af2013-01-24 13:03:27 +0800267bool xen_allowed;
Blue Swirld745bef2010-03-29 19:23:49 +0000268uint32_t xen_domid;
269enum xen_mode xen_mode = XEN_EMULATE;
Jan Kiszkad5ab9712011-08-02 16:10:21 +0200270static int tcg_tb_size;
Blue Swirld745bef2010-03-29 19:23:49 +0000271
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100272static int default_serial = 1;
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +0100273static int default_parallel = 1;
Gerd Hoffmann986c5f72009-12-08 13:11:54 +0100274static int default_virtcon = 1;
Alexander Graf3ef669e2013-01-24 12:18:52 +0100275static int default_sclp = 1;
Gerd Hoffmannabdeed02009-12-08 13:11:43 +0100276static int default_monitor = 1;
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +0100277static int default_floppy = 1;
278static int default_cdrom = 1;
279static int default_sdcard = 1;
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +0200280static int default_vga = 1;
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100281
282static struct {
283 const char *driver;
284 int *flag;
285} default_list[] = {
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +0100286 { .driver = "isa-serial", .flag = &default_serial },
287 { .driver = "isa-parallel", .flag = &default_parallel },
Gerd Hoffmannd8bcbab2009-12-16 14:25:40 +0100288 { .driver = "isa-fdc", .flag = &default_floppy },
Markus Armbrusteraf6bf132011-05-18 18:31:02 +0200289 { .driver = "ide-cd", .flag = &default_cdrom },
290 { .driver = "ide-hd", .flag = &default_cdrom },
Gerd Hoffmannd8bcbab2009-12-16 14:25:40 +0100291 { .driver = "ide-drive", .flag = &default_cdrom },
Markus Armbrusteraf6bf132011-05-18 18:31:02 +0200292 { .driver = "scsi-cd", .flag = &default_cdrom },
Amit Shah392ecf52010-01-21 16:19:23 +0530293 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
294 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
295 { .driver = "virtio-serial", .flag = &default_virtcon },
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +0200296 { .driver = "VGA", .flag = &default_vga },
297 { .driver = "isa-vga", .flag = &default_vga },
298 { .driver = "cirrus-vga", .flag = &default_vga },
299 { .driver = "isa-cirrus-vga", .flag = &default_vga },
300 { .driver = "vmware-svga", .flag = &default_vga },
301 { .driver = "qxl-vga", .flag = &default_vga },
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100302};
303
Paolo Bonzini4d454572012-11-26 16:03:42 +0100304static QemuOptsList qemu_rtc_opts = {
305 .name = "rtc",
306 .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head),
307 .desc = {
308 {
309 .name = "base",
310 .type = QEMU_OPT_STRING,
311 },{
312 .name = "clock",
313 .type = QEMU_OPT_STRING,
314 },{
315 .name = "driftfix",
316 .type = QEMU_OPT_STRING,
317 },
318 { /* end of list */ }
319 },
320};
321
322static QemuOptsList qemu_sandbox_opts = {
323 .name = "sandbox",
324 .implied_opt_name = "enable",
325 .head = QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts.head),
326 .desc = {
327 {
328 .name = "enable",
329 .type = QEMU_OPT_BOOL,
330 },
331 { /* end of list */ }
332 },
333};
334
335static QemuOptsList qemu_trace_opts = {
336 .name = "trace",
337 .implied_opt_name = "trace",
338 .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
339 .desc = {
340 {
341 .name = "events",
342 .type = QEMU_OPT_STRING,
343 },{
344 .name = "file",
345 .type = QEMU_OPT_STRING,
346 },
347 { /* end of list */ }
348 },
349};
350
351static QemuOptsList qemu_option_rom_opts = {
352 .name = "option-rom",
353 .implied_opt_name = "romfile",
354 .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head),
355 .desc = {
356 {
357 .name = "bootindex",
358 .type = QEMU_OPT_NUMBER,
359 }, {
360 .name = "romfile",
361 .type = QEMU_OPT_STRING,
362 },
363 { /* end of list */ }
364 },
365};
366
367static QemuOptsList qemu_machine_opts = {
368 .name = "machine",
369 .implied_opt_name = "type",
370 .merge_lists = true,
371 .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
372 .desc = {
373 {
374 .name = "type",
375 .type = QEMU_OPT_STRING,
376 .help = "emulated machine"
377 }, {
378 .name = "accel",
379 .type = QEMU_OPT_STRING,
380 .help = "accelerator list",
381 }, {
382 .name = "kernel_irqchip",
383 .type = QEMU_OPT_BOOL,
384 .help = "use KVM in-kernel irqchip",
385 }, {
386 .name = "kvm_shadow_mem",
387 .type = QEMU_OPT_SIZE,
388 .help = "KVM shadow MMU size",
389 }, {
390 .name = "kernel",
391 .type = QEMU_OPT_STRING,
392 .help = "Linux kernel image file",
393 }, {
394 .name = "initrd",
395 .type = QEMU_OPT_STRING,
396 .help = "Linux initial ramdisk file",
397 }, {
398 .name = "append",
399 .type = QEMU_OPT_STRING,
400 .help = "Linux kernel command line",
401 }, {
402 .name = "dtb",
403 .type = QEMU_OPT_STRING,
404 .help = "Linux kernel device tree file",
405 }, {
406 .name = "dumpdtb",
407 .type = QEMU_OPT_STRING,
408 .help = "Dump current dtb to a file and quit",
409 }, {
410 .name = "phandle_start",
Markus Armbrusterc1b71b02013-07-04 15:09:23 +0200411 .type = QEMU_OPT_NUMBER,
Paolo Bonzini4d454572012-11-26 16:03:42 +0100412 .help = "The first phandle ID we may generate dynamically",
413 }, {
414 .name = "dt_compatible",
415 .type = QEMU_OPT_STRING,
416 .help = "Overrides the \"compatible\" property of the dt root node",
417 }, {
418 .name = "dump-guest-core",
419 .type = QEMU_OPT_BOOL,
420 .help = "Include guest memory in a core dump",
421 }, {
422 .name = "mem-merge",
423 .type = QEMU_OPT_BOOL,
424 .help = "enable/disable memory merge support",
425 },{
426 .name = "usb",
427 .type = QEMU_OPT_BOOL,
428 .help = "Set on/off to enable/disable usb",
Gerd Hoffmann1442d3e2013-10-15 16:57:45 +0200429 },{
430 .name = "firmware",
431 .type = QEMU_OPT_STRING,
432 .help = "firmware image",
Paolo Bonzini4d454572012-11-26 16:03:42 +0100433 },
434 { /* End of list */ }
435 },
436};
437
438static QemuOptsList qemu_boot_opts = {
439 .name = "boot-opts",
Markus Armbruster6ef47162013-06-14 13:15:01 +0200440 .implied_opt_name = "order",
441 .merge_lists = true,
Paolo Bonzini4d454572012-11-26 16:03:42 +0100442 .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head),
443 .desc = {
Paolo Bonzini4d454572012-11-26 16:03:42 +0100444 {
445 .name = "order",
446 .type = QEMU_OPT_STRING,
447 }, {
448 .name = "once",
449 .type = QEMU_OPT_STRING,
450 }, {
451 .name = "menu",
Markus Armbruster6ef47162013-06-14 13:15:01 +0200452 .type = QEMU_OPT_BOOL,
Paolo Bonzini4d454572012-11-26 16:03:42 +0100453 }, {
454 .name = "splash",
455 .type = QEMU_OPT_STRING,
456 }, {
457 .name = "splash-time",
458 .type = QEMU_OPT_STRING,
459 }, {
460 .name = "reboot-timeout",
461 .type = QEMU_OPT_STRING,
Amos Kongc8a6ae82013-03-19 14:23:27 +0800462 }, {
463 .name = "strict",
464 .type = QEMU_OPT_STRING,
Paolo Bonzini4d454572012-11-26 16:03:42 +0100465 },
466 { /*End of list */ }
467 },
468};
469
470static QemuOptsList qemu_add_fd_opts = {
471 .name = "add-fd",
472 .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head),
473 .desc = {
474 {
475 .name = "fd",
476 .type = QEMU_OPT_NUMBER,
477 .help = "file descriptor of which a duplicate is added to fd set",
478 },{
479 .name = "set",
480 .type = QEMU_OPT_NUMBER,
481 .help = "ID of the fd set to add fd to",
482 },{
483 .name = "opaque",
484 .type = QEMU_OPT_STRING,
485 .help = "free-form string used to describe fd",
486 },
487 { /* end of list */ }
488 },
489};
490
491static QemuOptsList qemu_object_opts = {
492 .name = "object",
493 .implied_opt_name = "qom-type",
494 .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
495 .desc = {
496 { }
497 },
498};
499
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500500static QemuOptsList qemu_tpmdev_opts = {
501 .name = "tpmdev",
502 .implied_opt_name = "type",
503 .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head),
504 .desc = {
Stefan Bergerbb716232013-04-22 10:41:39 -0400505 /* options are defined in the TPM backends */
Stefan Bergerd1a0cf72013-02-27 12:47:49 -0500506 { /* end of list */ }
507 },
508};
509
Satoru Moriya888a6bc2013-04-19 16:42:06 +0200510static QemuOptsList qemu_realtime_opts = {
511 .name = "realtime",
512 .head = QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts.head),
513 .desc = {
514 {
515 .name = "mlock",
516 .type = QEMU_OPT_BOOL,
517 },
518 { /* end of list */ }
519 },
520};
521
Seiji Aguchi5e2ac512013-07-03 23:02:46 -0400522static QemuOptsList qemu_msg_opts = {
523 .name = "msg",
524 .head = QTAILQ_HEAD_INITIALIZER(qemu_msg_opts.head),
525 .desc = {
526 {
527 .name = "timestamp",
528 .type = QEMU_OPT_BOOL,
529 },
530 { /* end of list */ }
531 },
532};
533
Markus Armbruster7f9d6e52013-07-04 15:09:19 +0200534/**
535 * Get machine options
536 *
537 * Returns: machine options (never null).
538 */
539QemuOpts *qemu_get_machine_opts(void)
540{
541 QemuOptsList *list;
542 QemuOpts *opts;
543
544 list = qemu_find_opts("machine");
545 assert(list);
546 opts = qemu_opts_find(list, NULL);
547 if (!opts) {
548 opts = qemu_opts_create_nofail(list);
549 }
550 return opts;
551}
552
Ronnie Sahlberg31459f42012-08-06 18:24:55 +1000553const char *qemu_get_vm_name(void)
554{
555 return qemu_name;
556}
557
wayne3d3b8302011-07-27 18:04:55 +0800558static void res_free(void)
559{
560 if (boot_splash_filedata != NULL) {
Anthony Liguori7267c092011-08-20 22:09:37 -0500561 g_free(boot_splash_filedata);
wayne3d3b8302011-07-27 18:04:55 +0800562 boot_splash_filedata = NULL;
563 }
564}
565
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100566static int default_driver_check(QemuOpts *opts, void *opaque)
567{
568 const char *driver = qemu_opt_get(opts, "driver");
569 int i;
570
571 if (!driver)
572 return 0;
573 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
574 if (strcmp(default_list[i].driver, driver) != 0)
575 continue;
576 *(default_list[i].flag) = 0;
577 }
578 return 0;
579}
580
bellard0824d6f2003-06-24 13:42:40 +0000581/***********************************************************/
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300582/* QEMU state */
583
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300584static RunState current_run_state = RUN_STATE_PRELAUNCH;
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300585
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300586typedef struct {
587 RunState from;
588 RunState to;
589} RunStateTransition;
590
591static const RunStateTransition runstate_transitions_def[] = {
592 /* from -> to */
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300593 { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300594
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300595 { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },
Paolo Bonzini29ed72f2012-10-19 16:45:24 +0200596 { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300597
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300598 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300599 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300600
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300601 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300602 { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300603
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300604 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300605 { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300606
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300607 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300608 { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300609
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300610 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300611 { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300612 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300613
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300614 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
615 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300616
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300617 { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300618
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300619 { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
620 { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
621 { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
622 { RUN_STATE_RUNNING, RUN_STATE_PAUSED },
623 { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE },
624 { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM },
625 { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM },
626 { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
627 { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
Hu Taoede085b2013-04-26 11:24:40 +0800628 { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300629
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300630 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300631
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300632 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300633 { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300634
Luiz Capitulinoad02b962012-04-27 13:33:36 -0300635 { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
636 { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
637 { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },
638 { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
639
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300640 { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300641 { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300642
Paolo Bonzinidf390762013-11-04 14:30:47 +0100643 { RUN_STATE_GUEST_PANICKED, RUN_STATE_RUNNING },
Hu Taofd2a2e12013-05-20 12:46:20 +0200644 { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE },
Hu Taoede085b2013-04-26 11:24:40 +0800645
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300646 { RUN_STATE_MAX, RUN_STATE_MAX },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300647};
648
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300649static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX];
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300650
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300651bool runstate_check(RunState state)
652{
653 return current_run_state == state;
654}
655
Blue Swirl4fdcac02012-10-28 11:04:47 +0000656static void runstate_init(void)
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300657{
658 const RunStateTransition *p;
659
660 memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions));
661
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300662 for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) {
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300663 runstate_valid_transitions[p->from][p->to] = true;
664 }
665}
666
667/* This function will abort() on invalid state transitions */
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300668void runstate_set(RunState new_state)
669{
Luiz Capitulino207c5cd2011-10-13 10:59:07 -0300670 assert(new_state < RUN_STATE_MAX);
671
672 if (!runstate_valid_transitions[current_run_state][new_state]) {
673 fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
674 RunState_lookup[current_run_state],
675 RunState_lookup[new_state]);
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300676 abort();
677 }
Kazuya Saito7e866002013-03-22 17:26:59 +0900678 trace_runstate_set(new_state);
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300679 current_run_state = new_state;
680}
681
Luiz Capitulino13548692011-07-29 15:36:43 -0300682int runstate_is_running(void)
683{
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300684 return runstate_check(RUN_STATE_RUNNING);
Luiz Capitulino13548692011-07-29 15:36:43 -0300685}
686
Hu Taoede085b2013-04-26 11:24:40 +0800687bool runstate_needs_reset(void)
688{
689 return runstate_check(RUN_STATE_INTERNAL_ERROR) ||
Paolo Bonzinidf390762013-11-04 14:30:47 +0100690 runstate_check(RUN_STATE_SHUTDOWN);
Hu Taoede085b2013-04-26 11:24:40 +0800691}
692
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -0300693StatusInfo *qmp_query_status(Error **errp)
694{
695 StatusInfo *info = g_malloc0(sizeof(*info));
696
697 info->running = runstate_is_running();
698 info->singlestep = singlestep;
699 info->status = current_run_state;
700
701 return info;
702}
703
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300704/***********************************************************/
Paolo Bonzini8f0056b2010-01-13 14:05:34 +0100705/* real time host monotonic timer */
bellard09b26c52006-04-12 21:09:08 +0000706
bellardc4b1fcc2004-03-14 21:44:30 +0000707/***********************************************************/
balrogf6503052008-02-17 11:42:19 +0000708/* host time/date access */
709void qemu_get_timedate(struct tm *tm, int offset)
710{
711 time_t ti;
balrogf6503052008-02-17 11:42:19 +0000712
713 time(&ti);
714 ti += offset;
715 if (rtc_date_offset == -1) {
716 if (rtc_utc)
Stefan Weileb7ff6f2013-01-07 23:08:13 +0100717 gmtime_r(&ti, tm);
balrogf6503052008-02-17 11:42:19 +0000718 else
Stefan Weileb7ff6f2013-01-07 23:08:13 +0100719 localtime_r(&ti, tm);
balrogf6503052008-02-17 11:42:19 +0000720 } else {
721 ti -= rtc_date_offset;
Stefan Weileb7ff6f2013-01-07 23:08:13 +0100722 gmtime_r(&ti, tm);
balrogf6503052008-02-17 11:42:19 +0000723 }
balrogf6503052008-02-17 11:42:19 +0000724}
725
726int qemu_timedate_diff(struct tm *tm)
727{
728 time_t seconds;
729
730 if (rtc_date_offset == -1)
731 if (rtc_utc)
732 seconds = mktimegm(tm);
Gleb Natapovf54c5562011-11-06 18:00:22 +0200733 else {
734 struct tm tmp = *tm;
735 tmp.tm_isdst = -1; /* use timezone to figure it out */
736 seconds = mktime(&tmp);
737 }
balrogf6503052008-02-17 11:42:19 +0000738 else
739 seconds = mktimegm(tm) + rtc_date_offset;
740
741 return seconds - time(NULL);
742}
743
Luiz Capitulino80cd3472010-02-25 12:11:44 -0300744void rtc_change_mon_event(struct tm *tm)
745{
746 QObject *data;
747
748 data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
749 monitor_protocol_event(QEVENT_RTC_CHANGE, data);
750 qobject_decref(data);
751}
752
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200753static void configure_rtc_date_offset(const char *startdate, int legacy)
754{
755 time_t rtc_start_date;
756 struct tm tm;
757
758 if (!strcmp(startdate, "now") && legacy) {
759 rtc_date_offset = -1;
760 } else {
761 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
762 &tm.tm_year,
763 &tm.tm_mon,
764 &tm.tm_mday,
765 &tm.tm_hour,
766 &tm.tm_min,
767 &tm.tm_sec) == 6) {
768 /* OK */
769 } else if (sscanf(startdate, "%d-%d-%d",
770 &tm.tm_year,
771 &tm.tm_mon,
772 &tm.tm_mday) == 3) {
773 tm.tm_hour = 0;
774 tm.tm_min = 0;
775 tm.tm_sec = 0;
776 } else {
777 goto date_fail;
778 }
779 tm.tm_year -= 1900;
780 tm.tm_mon--;
781 rtc_start_date = mktimegm(&tm);
782 if (rtc_start_date == -1) {
783 date_fail:
784 fprintf(stderr, "Invalid date format. Valid formats are:\n"
785 "'2006-06-17T16:01:21' or '2006-06-17'\n");
786 exit(1);
787 }
788 rtc_date_offset = time(NULL) - rtc_start_date;
789 }
790}
791
792static void configure_rtc(QemuOpts *opts)
793{
794 const char *value;
795
796 value = qemu_opt_get(opts, "base");
797 if (value) {
798 if (!strcmp(value, "utc")) {
799 rtc_utc = 1;
800 } else if (!strcmp(value, "localtime")) {
801 rtc_utc = 0;
802 } else {
803 configure_rtc_date_offset(value, 0);
804 }
805 }
Jan Kiszka68752042009-09-15 13:36:04 +0200806 value = qemu_opt_get(opts, "clock");
807 if (value) {
808 if (!strcmp(value, "host")) {
Alex Bligh884f17c2013-08-21 16:03:04 +0100809 rtc_clock = QEMU_CLOCK_HOST;
Paolo Bonzini78808142012-03-30 10:31:21 +0000810 } else if (!strcmp(value, "rt")) {
Alex Bligh884f17c2013-08-21 16:03:04 +0100811 rtc_clock = QEMU_CLOCK_REALTIME;
Jan Kiszka68752042009-09-15 13:36:04 +0200812 } else if (!strcmp(value, "vm")) {
Alex Bligh884f17c2013-08-21 16:03:04 +0100813 rtc_clock = QEMU_CLOCK_VIRTUAL;
Jan Kiszka68752042009-09-15 13:36:04 +0200814 } else {
815 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
816 exit(1);
817 }
818 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200819 value = qemu_opt_get(opts, "driftfix");
820 if (value) {
Blue Swirl7e4c0332010-03-27 21:33:46 +0000821 if (!strcmp(value, "slew")) {
Jan Kiszka433acf02012-01-23 20:15:12 +0100822 static GlobalProperty slew_lost_ticks[] = {
823 {
824 .driver = "mc146818rtc",
825 .property = "lost_tick_policy",
826 .value = "slew",
827 },
828 { /* end of list */ }
829 };
830
831 qdev_prop_register_global_list(slew_lost_ticks);
Blue Swirl7e4c0332010-03-27 21:33:46 +0000832 } else if (!strcmp(value, "none")) {
Jan Kiszka433acf02012-01-23 20:15:12 +0100833 /* discard is default */
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200834 } else {
835 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
836 exit(1);
837 }
838 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200839}
840
balrog1ae26a12008-09-28 23:19:47 +0000841/***********************************************************/
842/* Bluetooth support */
843static int nb_hcis;
844static int cur_hci;
845static struct HCIInfo *hci_table[MAX_NICS];
balrogdc72ac12008-11-09 00:04:26 +0000846
balrog1ae26a12008-09-28 23:19:47 +0000847struct HCIInfo *qemu_next_hci(void)
848{
849 if (cur_hci == nb_hcis)
850 return &null_hci;
851
852 return hci_table[cur_hci++];
853}
854
balrogdc72ac12008-11-09 00:04:26 +0000855static int bt_hci_parse(const char *str)
856{
857 struct HCIInfo *hci;
Anthony Liguoric227f092009-10-01 16:12:16 -0500858 bdaddr_t bdaddr;
balrogdc72ac12008-11-09 00:04:26 +0000859
860 if (nb_hcis >= MAX_NICS) {
861 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
862 return -1;
863 }
864
865 hci = hci_init(str);
866 if (!hci)
867 return -1;
868
869 bdaddr.b[0] = 0x52;
870 bdaddr.b[1] = 0x54;
871 bdaddr.b[2] = 0x00;
872 bdaddr.b[3] = 0x12;
873 bdaddr.b[4] = 0x34;
874 bdaddr.b[5] = 0x56 + nb_hcis;
875 hci->bdaddr_set(hci, bdaddr.b);
876
877 hci_table[nb_hcis++] = hci;
878
879 return 0;
880}
881
882static void bt_vhci_add(int vlan_id)
883{
884 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
885
886 if (!vlan->slave)
887 fprintf(stderr, "qemu: warning: adding a VHCI to "
888 "an empty scatternet %i\n", vlan_id);
889
890 bt_vhci_init(bt_new_hci(vlan));
891}
892
893static struct bt_device_s *bt_device_add(const char *opt)
894{
895 struct bt_scatternet_s *vlan;
896 int vlan_id = 0;
897 char *endp = strstr(opt, ",vlan=");
898 int len = (endp ? endp - opt : strlen(opt)) + 1;
899 char devname[10];
900
901 pstrcpy(devname, MIN(sizeof(devname), len), opt);
902
903 if (endp) {
904 vlan_id = strtol(endp + 6, &endp, 0);
905 if (*endp) {
906 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
907 return 0;
908 }
909 }
910
911 vlan = qemu_find_bt_vlan(vlan_id);
912
913 if (!vlan->slave)
914 fprintf(stderr, "qemu: warning: adding a slave device to "
915 "an empty scatternet %i\n", vlan_id);
916
917 if (!strcmp(devname, "keyboard"))
918 return bt_keyboard_init(vlan);
919
920 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
921 return 0;
922}
923
924static int bt_parse(const char *opt)
925{
926 const char *endp, *p;
927 int vlan;
928
929 if (strstart(opt, "hci", &endp)) {
930 if (!*endp || *endp == ',') {
931 if (*endp)
932 if (!strstart(endp, ",vlan=", 0))
933 opt = endp + 1;
934
935 return bt_hci_parse(opt);
936 }
937 } else if (strstart(opt, "vhci", &endp)) {
938 if (!*endp || *endp == ',') {
939 if (*endp) {
940 if (strstart(endp, ",vlan=", &p)) {
941 vlan = strtol(p, (char **) &endp, 0);
942 if (*endp) {
943 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
944 return 1;
945 }
946 } else {
947 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
948 return 1;
949 }
950 } else
951 vlan = 0;
952
953 bt_vhci_add(vlan);
954 return 0;
955 }
956 } else if (strstart(opt, "device:", &endp))
957 return !bt_device_add(endp);
958
959 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
960 return 1;
961}
962
Eduardo Otubo7d76ad42012-08-14 18:44:08 -0300963static int parse_sandbox(QemuOpts *opts, void *opaque)
964{
965 /* FIXME: change this to true for 1.3 */
966 if (qemu_opt_get_bool(opts, "enable", false)) {
967#ifdef CONFIG_SECCOMP
968 if (seccomp_start() < 0) {
969 qerror_report(ERROR_CLASS_GENERIC_ERROR,
970 "failed to install seccomp syscall filter in the kernel");
971 return -1;
972 }
973#else
974 qerror_report(ERROR_CLASS_GENERIC_ERROR,
975 "sandboxing request but seccomp is not compiled into this build");
976 return -1;
977#endif
978 }
979
980 return 0;
981}
982
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +0000983bool usb_enabled(bool default_usb)
984{
Markus Armbruster2ff3de62013-07-04 15:09:22 +0200985 return qemu_opt_get_bool(qemu_get_machine_opts(), "usb", default_usb);
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +0000986}
987
Corey Bryant587ed6b2012-10-18 15:19:34 -0400988#ifndef _WIN32
989static int parse_add_fd(QemuOpts *opts, void *opaque)
990{
991 int fd, dupfd, flags;
992 int64_t fdset_id;
993 const char *fd_opaque = NULL;
994
995 fd = qemu_opt_get_number(opts, "fd", -1);
996 fdset_id = qemu_opt_get_number(opts, "set", -1);
997 fd_opaque = qemu_opt_get(opts, "opaque");
998
999 if (fd < 0) {
1000 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1001 "fd option is required and must be non-negative");
1002 return -1;
1003 }
1004
1005 if (fd <= STDERR_FILENO) {
1006 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1007 "fd cannot be a standard I/O stream");
1008 return -1;
1009 }
1010
1011 /*
1012 * All fds inherited across exec() necessarily have FD_CLOEXEC
1013 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1014 */
1015 flags = fcntl(fd, F_GETFD);
1016 if (flags == -1 || (flags & FD_CLOEXEC)) {
1017 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1018 "fd is not valid or already in use");
1019 return -1;
1020 }
1021
1022 if (fdset_id < 0) {
1023 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1024 "set option is required and must be non-negative");
1025 return -1;
1026 }
1027
1028#ifdef F_DUPFD_CLOEXEC
1029 dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
1030#else
1031 dupfd = dup(fd);
1032 if (dupfd != -1) {
1033 qemu_set_cloexec(dupfd);
1034 }
1035#endif
1036 if (dupfd == -1) {
1037 qerror_report(ERROR_CLASS_GENERIC_ERROR,
1038 "Error duplicating fd: %s", strerror(errno));
1039 return -1;
1040 }
1041
1042 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1043 monitor_fdset_add_fd(dupfd, true, fdset_id, fd_opaque ? true : false,
1044 fd_opaque, NULL);
1045
1046 return 0;
1047}
1048
1049static int cleanup_add_fd(QemuOpts *opts, void *opaque)
1050{
1051 int fd;
1052
1053 fd = qemu_opt_get_number(opts, "fd", -1);
1054 close(fd);
1055
1056 return 0;
1057}
1058#endif
1059
balrog1ae26a12008-09-28 23:19:47 +00001060/***********************************************************/
1061/* QEMU Block devices */
1062
Markus Armbruster2292dda2011-01-28 11:21:41 +01001063#define HD_OPTS "media=disk"
1064#define CDROM_OPTS "media=cdrom"
1065#define FD_OPTS ""
1066#define PFLASH_OPTS ""
1067#define MTD_OPTS ""
1068#define SD_OPTS ""
thse4bcb142007-12-02 04:51:10 +00001069
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02001070static int drive_init_func(QemuOpts *opts, void *opaque)
1071{
Christian Borntraeger2d0d2832012-11-20 15:30:34 +01001072 BlockInterfaceType *block_default_type = opaque;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02001073
Christian Borntraeger2d0d2832012-11-20 15:30:34 +01001074 return drive_init(opts, *block_default_type) == NULL;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02001075}
1076
1077static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
1078{
1079 if (NULL == qemu_opt_get(opts, "snapshot")) {
1080 qemu_opt_set(opts, "snapshot", "on");
1081 }
1082 return 0;
1083}
1084
Christian Borntraeger3c42ea62012-11-22 21:02:55 +01001085static void default_drive(int enable, int snapshot, BlockInterfaceType type,
1086 int index, const char *optstr)
Markus Armbruster4e5d9b52011-01-28 11:21:45 +01001087{
1088 QemuOpts *opts;
1089
Markus Armbruster4e5d9b52011-01-28 11:21:45 +01001090 if (!enable || drive_get_by_index(type, index)) {
1091 return;
1092 }
1093
1094 opts = drive_add(type, index, NULL, optstr);
1095 if (snapshot) {
1096 drive_enable_snapshot(opts, NULL);
1097 }
Christian Borntraeger2d0d2832012-11-20 15:30:34 +01001098 if (!drive_init(opts, type)) {
Markus Armbruster4e5d9b52011-01-28 11:21:45 +01001099 exit(1);
1100 }
1101}
1102
Jan Kiszka76e30d02009-07-02 00:19:02 +02001103void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
1104{
1105 boot_set_handler = func;
1106 boot_set_opaque = opaque;
1107}
1108
Markus Armbruster083b79c2013-06-14 13:15:04 +02001109int qemu_boot_set(const char *boot_order)
Jan Kiszka76e30d02009-07-02 00:19:02 +02001110{
1111 if (!boot_set_handler) {
1112 return -EINVAL;
1113 }
Markus Armbruster083b79c2013-06-14 13:15:04 +02001114 return boot_set_handler(boot_set_opaque, boot_order);
Jan Kiszka76e30d02009-07-02 00:19:02 +02001115}
1116
Markus Armbruster6ef47162013-06-14 13:15:01 +02001117static void validate_bootdevices(const char *devices)
Jan Kiszkaef3adf62009-07-02 00:19:02 +02001118{
1119 /* We just do some generic consistency checks */
1120 const char *p;
1121 int bitmap = 0;
1122
1123 for (p = devices; *p != '\0'; p++) {
1124 /* Allowed boot devices are:
1125 * a-b: floppy disk drives
1126 * c-f: IDE disk drives
Dong Xu Wang07f35072011-11-22 18:06:26 +08001127 * g-m: machine implementation dependent drives
Jan Kiszkaef3adf62009-07-02 00:19:02 +02001128 * n-p: network devices
1129 * It's up to each machine implementation to check if the given boot
1130 * devices match the actual hardware implementation and firmware
1131 * features.
1132 */
1133 if (*p < 'a' || *p > 'p') {
1134 fprintf(stderr, "Invalid boot device '%c'\n", *p);
1135 exit(1);
1136 }
1137 if (bitmap & (1 << (*p - 'a'))) {
1138 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
1139 exit(1);
1140 }
1141 bitmap |= 1 << (*p - 'a');
1142 }
Jan Kiszkaef3adf62009-07-02 00:19:02 +02001143}
1144
Markus Armbruster083b79c2013-06-14 13:15:04 +02001145static void restore_boot_order(void *opaque)
Jan Kiszkae0f084b2009-07-02 00:19:02 +02001146{
Markus Armbruster083b79c2013-06-14 13:15:04 +02001147 char *normal_boot_order = opaque;
Alex Williamson37905d62010-04-30 15:21:11 -06001148 static int first = 1;
1149
1150 /* Restore boot order and remove ourselves after the first boot */
1151 if (first) {
1152 first = 0;
1153 return;
1154 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +02001155
Markus Armbruster083b79c2013-06-14 13:15:04 +02001156 qemu_boot_set(normal_boot_order);
Jan Kiszkae0f084b2009-07-02 00:19:02 +02001157
Markus Armbruster083b79c2013-06-14 13:15:04 +02001158 qemu_unregister_reset(restore_boot_order, normal_boot_order);
1159 g_free(normal_boot_order);
Jan Kiszkae0f084b2009-07-02 00:19:02 +02001160}
1161
Gleb Natapov1ca4d092010-12-08 13:35:05 +02001162void add_boot_device_path(int32_t bootindex, DeviceState *dev,
1163 const char *suffix)
1164{
1165 FWBootEntry *node, *i;
1166
1167 if (bootindex < 0) {
1168 return;
1169 }
1170
1171 assert(dev != NULL || suffix != NULL);
1172
Anthony Liguori7267c092011-08-20 22:09:37 -05001173 node = g_malloc0(sizeof(FWBootEntry));
Gleb Natapov1ca4d092010-12-08 13:35:05 +02001174 node->bootindex = bootindex;
Dong Xu Wang7f303ad2013-05-09 15:53:49 +08001175 node->suffix = g_strdup(suffix);
Gleb Natapov1ca4d092010-12-08 13:35:05 +02001176 node->dev = dev;
1177
1178 QTAILQ_FOREACH(i, &fw_boot_order, link) {
1179 if (i->bootindex == bootindex) {
1180 fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
1181 exit(1);
1182 } else if (i->bootindex < bootindex) {
1183 continue;
1184 }
1185 QTAILQ_INSERT_BEFORE(i, node, link);
1186 return;
1187 }
1188 QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
1189}
1190
Dominik Dingel7dc5af52013-04-26 02:12:49 +00001191DeviceState *get_boot_device(uint32_t position)
1192{
1193 uint32_t counter = 0;
1194 FWBootEntry *i = NULL;
1195 DeviceState *res = NULL;
1196
1197 if (!QTAILQ_EMPTY(&fw_boot_order)) {
1198 QTAILQ_FOREACH(i, &fw_boot_order, link) {
1199 if (counter == position) {
1200 res = i->dev;
1201 break;
1202 }
1203 counter++;
1204 }
1205 }
1206 return res;
1207}
1208
Gleb Natapov962630f2010-12-08 13:35:09 +02001209/*
1210 * This function returns null terminated string that consist of new line
Brad Hards71785ab2011-04-23 21:50:06 +10001211 * separated device paths.
Gleb Natapov962630f2010-12-08 13:35:09 +02001212 *
1213 * memory pointed by "size" is assigned total length of the array in bytes
1214 *
1215 */
Markus Armbruster0e7a7592013-01-16 14:50:29 +01001216char *get_boot_devices_list(size_t *size)
Gleb Natapov962630f2010-12-08 13:35:09 +02001217{
1218 FWBootEntry *i;
Markus Armbruster0e7a7592013-01-16 14:50:29 +01001219 size_t total = 0;
Gleb Natapov962630f2010-12-08 13:35:09 +02001220 char *list = NULL;
1221
1222 QTAILQ_FOREACH(i, &fw_boot_order, link) {
1223 char *devpath = NULL, *bootpath;
Markus Armbruster0e7a7592013-01-16 14:50:29 +01001224 size_t len;
Gleb Natapov962630f2010-12-08 13:35:09 +02001225
1226 if (i->dev) {
1227 devpath = qdev_get_fw_dev_path(i->dev);
1228 assert(devpath);
1229 }
1230
1231 if (i->suffix && devpath) {
Blue Swirl4fd37a92010-12-19 14:05:43 +00001232 size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
1233
Anthony Liguori7267c092011-08-20 22:09:37 -05001234 bootpath = g_malloc(bootpathlen);
Blue Swirl4fd37a92010-12-19 14:05:43 +00001235 snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
Anthony Liguori7267c092011-08-20 22:09:37 -05001236 g_free(devpath);
Gleb Natapov962630f2010-12-08 13:35:09 +02001237 } else if (devpath) {
1238 bootpath = devpath;
1239 } else {
Markus Armbruster1bf6ccd2011-11-08 10:58:00 +01001240 assert(i->suffix);
Anthony Liguori7267c092011-08-20 22:09:37 -05001241 bootpath = g_strdup(i->suffix);
Gleb Natapov962630f2010-12-08 13:35:09 +02001242 }
1243
1244 if (total) {
1245 list[total-1] = '\n';
1246 }
1247 len = strlen(bootpath) + 1;
Anthony Liguori7267c092011-08-20 22:09:37 -05001248 list = g_realloc(list, total + len);
Gleb Natapov962630f2010-12-08 13:35:09 +02001249 memcpy(&list[total], bootpath, len);
1250 total += len;
Anthony Liguori7267c092011-08-20 22:09:37 -05001251 g_free(bootpath);
Gleb Natapov962630f2010-12-08 13:35:09 +02001252 }
1253
1254 *size = total;
1255
Amos Kongc8a6ae82013-03-19 14:23:27 +08001256 if (boot_strict && *size > 0) {
1257 list[total-1] = '\n';
Amos Kong46905792013-03-20 18:16:34 +08001258 list = g_realloc(list, total + 5);
1259 memcpy(&list[total], "HALT", 5);
1260 *size = total + 5;
Amos Kongc8a6ae82013-03-19 14:23:27 +08001261 }
Gleb Natapov962630f2010-12-08 13:35:09 +02001262 return list;
1263}
1264
Eduardo Habkost845e5bf2013-02-04 16:27:51 -02001265static void numa_node_parse_cpus(int nodenr, const char *cpus)
1266{
1267 char *endptr;
1268 unsigned long long value, endvalue;
1269
Eduardo Habkostc881e202013-02-04 16:27:52 -02001270 /* Empty CPU range strings will be considered valid, they will simply
1271 * not set any bit in the CPU bitmap.
1272 */
1273 if (!*cpus) {
1274 return;
Eduardo Habkost845e5bf2013-02-04 16:27:51 -02001275 }
1276
Eduardo Habkostc881e202013-02-04 16:27:52 -02001277 if (parse_uint(cpus, &value, &endptr, 10) < 0) {
1278 goto error;
1279 }
1280 if (*endptr == '-') {
1281 if (parse_uint_full(endptr + 1, &endvalue, 10) < 0) {
1282 goto error;
1283 }
1284 } else if (*endptr == '\0') {
1285 endvalue = value;
1286 } else {
1287 goto error;
1288 }
1289
1290 if (endvalue >= MAX_CPUMASK_BITS) {
Eduardo Habkost845e5bf2013-02-04 16:27:51 -02001291 endvalue = MAX_CPUMASK_BITS - 1;
1292 fprintf(stderr,
Eduardo Habkostc881e202013-02-04 16:27:52 -02001293 "qemu: NUMA: A max of %d VCPUs are supported\n",
Eduardo Habkost845e5bf2013-02-04 16:27:51 -02001294 MAX_CPUMASK_BITS);
1295 }
1296
Eduardo Habkostc881e202013-02-04 16:27:52 -02001297 if (endvalue < value) {
1298 goto error;
1299 }
1300
Eduardo Habkost845e5bf2013-02-04 16:27:51 -02001301 bitmap_set(node_cpumask[nodenr], value, endvalue-value+1);
Eduardo Habkostc881e202013-02-04 16:27:52 -02001302 return;
1303
1304error:
1305 fprintf(stderr, "qemu: Invalid NUMA CPU range: %s\n", cpus);
1306 exit(1);
Eduardo Habkost845e5bf2013-02-04 16:27:51 -02001307}
1308
aliguori268a3622009-04-21 22:30:27 +00001309static void numa_add(const char *optarg)
1310{
1311 char option[128];
1312 char *endptr;
Eduardo Habkoste4ce85b2013-02-04 16:27:49 -02001313 unsigned long long nodenr;
aliguori268a3622009-04-21 22:30:27 +00001314
Eduardo Habkost8f302cb2013-02-04 16:27:46 -02001315 optarg = get_opt_name(option, 128, optarg, ',');
1316 if (*optarg == ',') {
1317 optarg++;
1318 }
aliguori268a3622009-04-21 22:30:27 +00001319 if (!strcmp(option, "node")) {
Eduardo Habkostca4c6d32013-02-04 16:27:48 -02001320
1321 if (nb_numa_nodes >= MAX_NODES) {
1322 fprintf(stderr, "qemu: too many NUMA nodes\n");
1323 exit(1);
1324 }
1325
aliguori268a3622009-04-21 22:30:27 +00001326 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
1327 nodenr = nb_numa_nodes;
1328 } else {
Eduardo Habkost5f139962013-02-04 16:27:50 -02001329 if (parse_uint_full(option, &nodenr, 10) < 0) {
1330 fprintf(stderr, "qemu: Invalid NUMA nodeid: %s\n", option);
1331 exit(1);
1332 }
aliguori268a3622009-04-21 22:30:27 +00001333 }
1334
Eduardo Habkoste4ce85b2013-02-04 16:27:49 -02001335 if (nodenr >= MAX_NODES) {
1336 fprintf(stderr, "qemu: invalid NUMA nodeid: %llu\n", nodenr);
1337 exit(1);
1338 }
1339
aliguori268a3622009-04-21 22:30:27 +00001340 if (get_param_value(option, 128, "mem", optarg) == 0) {
1341 node_mem[nodenr] = 0;
1342 } else {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +01001343 int64_t sval;
Markus Armbrusterc03417b2011-11-22 09:46:02 +01001344 sval = strtosz(option, &endptr);
1345 if (sval < 0 || *endptr) {
Jes Sorensen9f9b17a2010-10-21 17:15:46 +02001346 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
1347 exit(1);
aliguori268a3622009-04-21 22:30:27 +00001348 }
Jes Sorensen9f9b17a2010-10-21 17:15:46 +02001349 node_mem[nodenr] = sval;
aliguori268a3622009-04-21 22:30:27 +00001350 }
Chegu Vinodee785fe2012-07-16 21:31:30 -07001351 if (get_param_value(option, 128, "cpus", optarg) != 0) {
Eduardo Habkost845e5bf2013-02-04 16:27:51 -02001352 numa_node_parse_cpus(nodenr, option);
aliguori268a3622009-04-21 22:30:27 +00001353 }
1354 nb_numa_nodes++;
Eduardo Habkost12e53a92013-02-04 16:27:47 -02001355 } else {
1356 fprintf(stderr, "Invalid -numa option: %s\n", option);
1357 exit(1);
aliguori268a3622009-04-21 22:30:27 +00001358 }
aliguori268a3622009-04-21 22:30:27 +00001359}
1360
Michael Tokarev12b7f572013-06-24 15:06:52 +04001361static QemuOptsList qemu_smp_opts = {
1362 .name = "smp-opts",
1363 .implied_opt_name = "cpus",
1364 .merge_lists = true,
1365 .head = QTAILQ_HEAD_INITIALIZER(qemu_smp_opts.head),
1366 .desc = {
1367 {
1368 .name = "cpus",
1369 .type = QEMU_OPT_NUMBER,
1370 }, {
1371 .name = "sockets",
1372 .type = QEMU_OPT_NUMBER,
1373 }, {
1374 .name = "cores",
1375 .type = QEMU_OPT_NUMBER,
1376 }, {
1377 .name = "threads",
1378 .type = QEMU_OPT_NUMBER,
1379 }, {
1380 .name = "maxcpus",
1381 .type = QEMU_OPT_NUMBER,
1382 },
1383 { /*End of list */ }
1384 },
1385};
1386
1387static void smp_parse(QemuOpts *opts)
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001388{
Michael Tokarev12b7f572013-06-24 15:06:52 +04001389 if (opts) {
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001390
Michael Tokarev12b7f572013-06-24 15:06:52 +04001391 unsigned cpus = qemu_opt_get_number(opts, "cpus", 0);
1392 unsigned sockets = qemu_opt_get_number(opts, "sockets", 0);
1393 unsigned cores = qemu_opt_get_number(opts, "cores", 0);
1394 unsigned threads = qemu_opt_get_number(opts, "threads", 0);
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001395
Michael Tokarev12b7f572013-06-24 15:06:52 +04001396 /* compute missing values, prefer sockets over cores over threads */
1397 if (cpus == 0 || sockets == 0) {
1398 sockets = sockets > 0 ? sockets : 1;
1399 cores = cores > 0 ? cores : 1;
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001400 threads = threads > 0 ? threads : 1;
Michael Tokarev12b7f572013-06-24 15:06:52 +04001401 if (cpus == 0) {
1402 cpus = cores * threads * sockets;
1403 }
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001404 } else {
Michael Tokarev12b7f572013-06-24 15:06:52 +04001405 if (cores == 0) {
1406 threads = threads > 0 ? threads : 1;
1407 cores = cpus / (sockets * threads);
1408 } else {
1409 threads = cpus / (cores * sockets);
1410 }
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001411 }
Michael Tokarev12b7f572013-06-24 15:06:52 +04001412
1413 max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
1414
1415 smp_cpus = cpus;
1416 smp_cores = cores > 0 ? cores : 1;
1417 smp_threads = threads > 0 ? threads : 1;
1418
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001419 }
Michael Tokarev12b7f572013-06-24 15:06:52 +04001420
1421 if (max_cpus == 0) {
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001422 max_cpus = smp_cpus;
Michael Tokarev12b7f572013-06-24 15:06:52 +04001423 }
1424
1425 if (max_cpus > 255) {
1426 fprintf(stderr, "Unsupported number of maxcpus\n");
1427 exit(1);
1428 }
1429 if (max_cpus < smp_cpus) {
1430 fprintf(stderr, "maxcpus must be equal to or greater than smp\n");
1431 exit(1);
1432 }
1433
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001434}
1435
Satoru Moriya888a6bc2013-04-19 16:42:06 +02001436static void configure_realtime(QemuOpts *opts)
1437{
1438 bool enable_mlock;
1439
1440 enable_mlock = qemu_opt_get_bool(opts, "mlock", true);
1441
1442 if (enable_mlock) {
1443 if (os_mlock() < 0) {
1444 fprintf(stderr, "qemu: locking memory failed\n");
1445 exit(1);
1446 }
1447 }
1448}
1449
Seiji Aguchi5e2ac512013-07-03 23:02:46 -04001450
1451static void configure_msg(QemuOpts *opts)
1452{
1453 enable_timestamp_msg = qemu_opt_get_bool(opts, "timestamp", true);
1454}
1455
bellard330d0412003-07-26 18:11:40 +00001456/***********************************************************/
bellarda594cfb2005-11-06 16:13:29 +00001457/* USB devices */
1458
Markus Armbrusterfb080002010-05-28 15:38:44 +02001459static int usb_device_add(const char *devname)
bellarda594cfb2005-11-06 16:13:29 +00001460{
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001461 USBDevice *dev = NULL;
Miroslav Rezanina615fe4d2013-09-03 11:23:09 +02001462#ifndef CONFIG_LINUX
1463 const char *p;
1464#endif
bellarda594cfb2005-11-06 16:13:29 +00001465
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00001466 if (!usb_enabled(false)) {
bellarda594cfb2005-11-06 16:13:29 +00001467 return -1;
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00001468 }
bellarda594cfb2005-11-06 16:13:29 +00001469
Gerd Hoffmann0958b4c2009-10-26 15:56:45 +01001470 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1471 dev = usbdevice_create(devname);
1472 if (dev)
1473 goto done;
1474
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001475 /* the other ones */
Gerd Hoffmanne447fc62011-06-01 14:41:59 +02001476#ifndef CONFIG_LINUX
1477 /* only the linux version is qdev-ified, usb-bsd still needs this */
bellarda594cfb2005-11-06 16:13:29 +00001478 if (strstart(devname, "host:", &p)) {
Jan Kiszka37417152012-02-27 15:18:47 +01001479 dev = usb_host_device_open(usb_bus_find(-1), p);
bellarda594cfb2005-11-06 16:13:29 +00001480 }
Miroslav Rezanina615fe4d2013-09-03 11:23:09 +02001481#endif
pbrook0d92ed32006-05-21 16:30:15 +00001482 if (!dev)
1483 return -1;
1484
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001485done:
bellarda594cfb2005-11-06 16:13:29 +00001486 return 0;
1487}
1488
aliguori1f3870a2008-08-21 19:27:48 +00001489static int usb_device_del(const char *devname)
1490{
1491 int bus_num, addr;
1492 const char *p;
1493
Gerd Hoffmann1a3973b2012-11-30 13:02:47 +01001494 if (strstart(devname, "host:", &p)) {
1495 return -1;
1496 }
aliguori5d0c5752008-09-14 01:07:41 +00001497
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00001498 if (!usb_enabled(false)) {
aliguori1f3870a2008-08-21 19:27:48 +00001499 return -1;
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00001500 }
aliguori1f3870a2008-08-21 19:27:48 +00001501
1502 p = strchr(devname, '.');
1503 if (!p)
1504 return -1;
1505 bus_num = strtoul(devname, NULL, 0);
1506 addr = strtoul(p + 1, NULL, 0);
1507
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001508 return usb_device_delete_addr(bus_num, addr);
aliguori1f3870a2008-08-21 19:27:48 +00001509}
1510
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001511static int usb_parse(const char *cmdline)
1512{
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001513 int r;
Markus Armbrusterfb080002010-05-28 15:38:44 +02001514 r = usb_device_add(cmdline);
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001515 if (r < 0) {
1516 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
1517 }
1518 return r;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001519}
1520
Luiz Capitulinod54908a2009-08-28 15:27:13 -03001521void do_usb_add(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +00001522{
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001523 const char *devname = qdict_get_str(qdict, "devname");
Markus Armbrusterfb080002010-05-28 15:38:44 +02001524 if (usb_device_add(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +01001525 error_report("could not add USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001526 }
bellarda594cfb2005-11-06 16:13:29 +00001527}
1528
Luiz Capitulinod54908a2009-08-28 15:27:13 -03001529void do_usb_del(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +00001530{
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001531 const char *devname = qdict_get_str(qdict, "devname");
1532 if (usb_device_del(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +01001533 error_report("could not delete USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001534 }
bellarda594cfb2005-11-06 16:13:29 +00001535}
1536
bellardf7cce892004-12-08 22:21:25 +00001537/***********************************************************/
balrog201a51f2007-04-30 00:51:09 +00001538/* PCMCIA/Cardbus */
1539
1540static struct pcmcia_socket_entry_s {
Paul Brookbc24a222009-05-10 01:44:56 +01001541 PCMCIASocket *socket;
balrog201a51f2007-04-30 00:51:09 +00001542 struct pcmcia_socket_entry_s *next;
1543} *pcmcia_sockets = 0;
1544
Paul Brookbc24a222009-05-10 01:44:56 +01001545void pcmcia_socket_register(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +00001546{
1547 struct pcmcia_socket_entry_s *entry;
1548
Anthony Liguori7267c092011-08-20 22:09:37 -05001549 entry = g_malloc(sizeof(struct pcmcia_socket_entry_s));
balrog201a51f2007-04-30 00:51:09 +00001550 entry->socket = socket;
1551 entry->next = pcmcia_sockets;
1552 pcmcia_sockets = entry;
1553}
1554
Paul Brookbc24a222009-05-10 01:44:56 +01001555void pcmcia_socket_unregister(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +00001556{
1557 struct pcmcia_socket_entry_s *entry, **ptr;
1558
1559 ptr = &pcmcia_sockets;
1560 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1561 if (entry->socket == socket) {
1562 *ptr = entry->next;
Anthony Liguori7267c092011-08-20 22:09:37 -05001563 g_free(entry);
balrog201a51f2007-04-30 00:51:09 +00001564 }
1565}
1566
Wenchao Xia84f2d0e2013-01-14 14:06:25 +08001567void pcmcia_info(Monitor *mon, const QDict *qdict)
balrog201a51f2007-04-30 00:51:09 +00001568{
1569 struct pcmcia_socket_entry_s *iter;
aliguori376253e2009-03-05 23:01:23 +00001570
balrog201a51f2007-04-30 00:51:09 +00001571 if (!pcmcia_sockets)
aliguori376253e2009-03-05 23:01:23 +00001572 monitor_printf(mon, "No PCMCIA sockets\n");
balrog201a51f2007-04-30 00:51:09 +00001573
1574 for (iter = pcmcia_sockets; iter; iter = iter->next)
aliguori376253e2009-03-05 23:01:23 +00001575 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1576 iter->socket->attached ? iter->socket->card_string :
1577 "Empty");
balrog201a51f2007-04-30 00:51:09 +00001578}
1579
1580/***********************************************************/
bellardcc1daa42005-06-05 14:49:17 +00001581/* machine registration */
1582
blueswir1bdaf78e2008-10-04 07:24:27 +00001583static QEMUMachine *first_machine = NULL;
aliguori6f338c32009-02-11 15:21:54 +00001584QEMUMachine *current_machine = NULL;
bellardcc1daa42005-06-05 14:49:17 +00001585
1586int qemu_register_machine(QEMUMachine *m)
1587{
1588 QEMUMachine **pm;
1589 pm = &first_machine;
1590 while (*pm != NULL)
1591 pm = &(*pm)->next;
1592 m->next = NULL;
1593 *pm = m;
1594 return 0;
1595}
1596
pbrook9596ebb2007-11-18 01:44:38 +00001597static QEMUMachine *find_machine(const char *name)
bellardcc1daa42005-06-05 14:49:17 +00001598{
1599 QEMUMachine *m;
1600
1601 for(m = first_machine; m != NULL; m = m->next) {
1602 if (!strcmp(m->name, name))
1603 return m;
Mark McLoughlin3f6599e2009-07-22 10:02:50 +01001604 if (m->alias && !strcmp(m->alias, name))
1605 return m;
bellardcc1daa42005-06-05 14:49:17 +00001606 }
1607 return NULL;
1608}
1609
Jordan Justen2c8cffa2012-02-21 23:18:50 -08001610QEMUMachine *find_default_machine(void)
Anthony Liguori0c257432009-05-21 20:41:01 -05001611{
1612 QEMUMachine *m;
1613
1614 for(m = first_machine; m != NULL; m = m->next) {
1615 if (m->is_default) {
1616 return m;
1617 }
1618 }
1619 return NULL;
1620}
1621
Anthony Liguori01d3c802012-08-10 11:04:11 -05001622MachineInfoList *qmp_query_machines(Error **errp)
1623{
1624 MachineInfoList *mach_list = NULL;
1625 QEMUMachine *m;
1626
1627 for (m = first_machine; m; m = m->next) {
1628 MachineInfoList *entry;
1629 MachineInfo *info;
1630
1631 info = g_malloc0(sizeof(*info));
1632 if (m->is_default) {
1633 info->has_is_default = true;
1634 info->is_default = true;
1635 }
1636
1637 if (m->alias) {
1638 info->has_alias = true;
1639 info->alias = g_strdup(m->alias);
1640 }
1641
1642 info->name = g_strdup(m->name);
Michal Novotnyc72e7682013-04-08 18:21:02 +02001643 info->cpu_max = !m->max_cpus ? 1 : m->max_cpus;
Anthony Liguori01d3c802012-08-10 11:04:11 -05001644
1645 entry = g_malloc0(sizeof(*entry));
1646 entry->value = info;
1647 entry->next = mach_list;
1648 mach_list = entry;
1649 }
1650
1651 return mach_list;
1652}
1653
bellardcc1daa42005-06-05 14:49:17 +00001654/***********************************************************/
bellard8a7ddc32004-03-31 19:00:16 +00001655/* main execution loop */
1656
bellard0bd48852005-11-11 00:00:47 +00001657struct vm_change_state_entry {
1658 VMChangeStateHandler *cb;
1659 void *opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001660 QLIST_ENTRY (vm_change_state_entry) entries;
bellard0bd48852005-11-11 00:00:47 +00001661};
1662
Blue Swirl72cf2d42009-09-12 07:36:22 +00001663static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
bellard0bd48852005-11-11 00:00:47 +00001664
1665VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1666 void *opaque)
1667{
1668 VMChangeStateEntry *e;
1669
Anthony Liguori7267c092011-08-20 22:09:37 -05001670 e = g_malloc0(sizeof (*e));
bellard0bd48852005-11-11 00:00:47 +00001671
1672 e->cb = cb;
1673 e->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001674 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
bellard0bd48852005-11-11 00:00:47 +00001675 return e;
1676}
1677
1678void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1679{
Blue Swirl72cf2d42009-09-12 07:36:22 +00001680 QLIST_REMOVE (e, entries);
Anthony Liguori7267c092011-08-20 22:09:37 -05001681 g_free (e);
bellard0bd48852005-11-11 00:00:47 +00001682}
1683
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001684void vm_state_notify(int running, RunState state)
bellard0bd48852005-11-11 00:00:47 +00001685{
1686 VMChangeStateEntry *e;
1687
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001688 trace_vm_state_notify(running, state);
Stefan Hajnoczi94b0b5f2010-11-16 12:20:25 +00001689
bellard0bd48852005-11-11 00:00:47 +00001690 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001691 e->cb(e->opaque, running, state);
bellard0bd48852005-11-11 00:00:47 +00001692 }
1693}
1694
bellard8a7ddc32004-03-31 19:00:16 +00001695void vm_start(void)
1696{
Luiz Capitulino13548692011-07-29 15:36:43 -03001697 if (!runstate_is_running()) {
bellard8a7ddc32004-03-31 19:00:16 +00001698 cpu_enable_ticks();
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001699 runstate_set(RUN_STATE_RUNNING);
1700 vm_state_notify(1, RUN_STATE_RUNNING);
aliguorid6dc3d42009-04-24 18:04:07 +00001701 resume_all_vcpus();
Luiz Capitulino6ed2c482010-04-27 20:35:59 -03001702 monitor_protocol_event(QEVENT_RESUME, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00001703 }
1704}
1705
bellardbb0c6722004-06-20 12:37:32 +00001706/* reset/shutdown handler */
1707
1708typedef struct QEMUResetEntry {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001709 QTAILQ_ENTRY(QEMUResetEntry) entry;
bellardbb0c6722004-06-20 12:37:32 +00001710 QEMUResetHandler *func;
1711 void *opaque;
bellardbb0c6722004-06-20 12:37:32 +00001712} QEMUResetEntry;
1713
Blue Swirl72cf2d42009-09-12 07:36:22 +00001714static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1715 QTAILQ_HEAD_INITIALIZER(reset_handlers);
bellardbb0c6722004-06-20 12:37:32 +00001716static int reset_requested;
Gleb Natapovf64622c2011-03-15 13:56:04 +02001717static int shutdown_requested, shutdown_signal = -1;
1718static pid_t shutdown_pid;
bellard34751872005-07-02 14:31:34 +00001719static int powerdown_requested;
Jan Kiszka8cf71712011-02-07 12:19:16 +01001720static int debug_requested;
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001721static int suspend_requested;
Liu, Jinsong4bc78a82013-09-25 16:38:29 +00001722static WakeupReason wakeup_reason;
Igor Mammedova9552c82012-09-05 23:06:21 +02001723static NotifierList powerdown_notifiers =
1724 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001725static NotifierList suspend_notifiers =
1726 NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
1727static NotifierList wakeup_notifiers =
1728 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
Liu, Jinsong4bc78a82013-09-25 16:38:29 +00001729static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE);
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001730static RunState vmstop_requested = RUN_STATE_MAX;
bellardbb0c6722004-06-20 12:37:32 +00001731
Anthony PERARD1291eb32010-07-22 15:52:48 +01001732int qemu_shutdown_requested_get(void)
1733{
1734 return shutdown_requested;
1735}
1736
1737int qemu_reset_requested_get(void)
1738{
1739 return reset_requested;
1740}
1741
Blue Swirl4fdcac02012-10-28 11:04:47 +00001742static int qemu_shutdown_requested(void)
aurel32cf7a2fe2008-03-18 06:53:05 +00001743{
1744 int r = shutdown_requested;
1745 shutdown_requested = 0;
1746 return r;
1747}
1748
Blue Swirl4fdcac02012-10-28 11:04:47 +00001749static void qemu_kill_report(void)
Gleb Natapovf64622c2011-03-15 13:56:04 +02001750{
Anthony Liguoric7f0f3b2012-03-28 15:42:02 +02001751 if (!qtest_enabled() && shutdown_signal != -1) {
Peter Maydellf1d3fb02011-03-30 22:03:38 +01001752 fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal);
1753 if (shutdown_pid == 0) {
1754 /* This happens for eg ^C at the terminal, so it's worth
1755 * avoiding printing an odd message in that case.
1756 */
1757 fputc('\n', stderr);
1758 } else {
Andreas Färber953ffe02011-06-02 19:58:06 +02001759 fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid);
Peter Maydellf1d3fb02011-03-30 22:03:38 +01001760 }
Gleb Natapovf64622c2011-03-15 13:56:04 +02001761 shutdown_signal = -1;
1762 }
1763}
1764
Blue Swirl4fdcac02012-10-28 11:04:47 +00001765static int qemu_reset_requested(void)
aurel32cf7a2fe2008-03-18 06:53:05 +00001766{
1767 int r = reset_requested;
1768 reset_requested = 0;
1769 return r;
1770}
1771
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001772static int qemu_suspend_requested(void)
1773{
1774 int r = suspend_requested;
1775 suspend_requested = 0;
1776 return r;
1777}
1778
Liu, Jinsong4bc78a82013-09-25 16:38:29 +00001779static WakeupReason qemu_wakeup_requested(void)
Luiz Capitulino14058192012-08-08 17:29:17 -03001780{
Liu, Jinsong4bc78a82013-09-25 16:38:29 +00001781 return wakeup_reason;
Luiz Capitulino14058192012-08-08 17:29:17 -03001782}
1783
Blue Swirl4fdcac02012-10-28 11:04:47 +00001784static int qemu_powerdown_requested(void)
aurel32cf7a2fe2008-03-18 06:53:05 +00001785{
1786 int r = powerdown_requested;
1787 powerdown_requested = 0;
1788 return r;
1789}
1790
aliguorie5689022009-04-24 18:03:54 +00001791static int qemu_debug_requested(void)
1792{
1793 int r = debug_requested;
1794 debug_requested = 0;
1795 return r;
1796}
1797
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001798/* We use RUN_STATE_MAX but any invalid value will do */
Luiz Capitulino0d45b702011-09-30 14:27:11 -03001799static bool qemu_vmstop_requested(RunState *r)
aliguori6e29f5d2009-04-24 18:04:02 +00001800{
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001801 if (vmstop_requested < RUN_STATE_MAX) {
Luiz Capitulino0d45b702011-09-30 14:27:11 -03001802 *r = vmstop_requested;
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001803 vmstop_requested = RUN_STATE_MAX;
Luiz Capitulino0d45b702011-09-30 14:27:11 -03001804 return true;
1805 }
1806
1807 return false;
aliguori6e29f5d2009-04-24 18:04:02 +00001808}
1809
Jan Kiszkaa08d4362009-06-27 09:25:07 +02001810void qemu_register_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001811{
Anthony Liguori7267c092011-08-20 22:09:37 -05001812 QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
bellardbb0c6722004-06-20 12:37:32 +00001813
bellardbb0c6722004-06-20 12:37:32 +00001814 re->func = func;
1815 re->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001816 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
bellardbb0c6722004-06-20 12:37:32 +00001817}
1818
Jan Kiszkadda9b292009-07-02 00:19:02 +02001819void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001820{
1821 QEMUResetEntry *re;
1822
Blue Swirl72cf2d42009-09-12 07:36:22 +00001823 QTAILQ_FOREACH(re, &reset_handlers, entry) {
Jan Kiszkadda9b292009-07-02 00:19:02 +02001824 if (re->func == func && re->opaque == opaque) {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001825 QTAILQ_REMOVE(&reset_handlers, re, entry);
Anthony Liguori7267c092011-08-20 22:09:37 -05001826 g_free(re);
Jan Kiszkadda9b292009-07-02 00:19:02 +02001827 return;
1828 }
1829 }
1830}
1831
David Gibsonbe522022012-08-07 16:41:51 +10001832void qemu_devices_reset(void)
Jan Kiszkadda9b292009-07-02 00:19:02 +02001833{
1834 QEMUResetEntry *re, *nre;
1835
1836 /* reset all devices */
Blue Swirl72cf2d42009-09-12 07:36:22 +00001837 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
bellardbb0c6722004-06-20 12:37:32 +00001838 re->func(re->opaque);
1839 }
David Gibsonbe522022012-08-07 16:41:51 +10001840}
1841
1842void qemu_system_reset(bool report)
1843{
1844 if (current_machine && current_machine->reset) {
1845 current_machine->reset();
1846 } else {
1847 qemu_devices_reset();
1848 }
Jan Kiszkae063eb12011-06-14 18:29:43 +02001849 if (report) {
1850 monitor_protocol_event(QEVENT_RESET, NULL);
1851 }
Jan Kiszkaea375f92010-03-01 19:10:30 +01001852 cpu_synchronize_all_post_reset();
bellardbb0c6722004-06-20 12:37:32 +00001853}
1854
1855void qemu_system_reset_request(void)
1856{
bellardd1beab82006-10-02 19:44:22 +00001857 if (no_reboot) {
1858 shutdown_requested = 1;
1859 } else {
1860 reset_requested = 1;
1861 }
Jan Kiszkab4a3d962011-02-01 22:15:43 +01001862 cpu_stop_current();
aliguorid9f75a42009-04-24 18:03:11 +00001863 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001864}
1865
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001866static void qemu_system_suspend(void)
1867{
1868 pause_all_vcpus();
1869 notifier_list_notify(&suspend_notifiers, NULL);
Luiz Capitulinoad02b962012-04-27 13:33:36 -03001870 runstate_set(RUN_STATE_SUSPENDED);
Gerd Hoffmann53370b72012-02-23 13:45:26 +01001871 monitor_protocol_event(QEVENT_SUSPEND, NULL);
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001872}
1873
1874void qemu_system_suspend_request(void)
1875{
Luiz Capitulino9abc62f2012-04-27 14:31:12 -03001876 if (runstate_check(RUN_STATE_SUSPENDED)) {
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001877 return;
1878 }
1879 suspend_requested = 1;
1880 cpu_stop_current();
1881 qemu_notify_event();
1882}
1883
1884void qemu_register_suspend_notifier(Notifier *notifier)
1885{
1886 notifier_list_add(&suspend_notifiers, notifier);
1887}
1888
1889void qemu_system_wakeup_request(WakeupReason reason)
1890{
Luiz Capitulino9abc62f2012-04-27 14:31:12 -03001891 if (!runstate_check(RUN_STATE_SUSPENDED)) {
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001892 return;
1893 }
1894 if (!(wakeup_reason_mask & (1 << reason))) {
1895 return;
1896 }
Luiz Capitulinoad02b962012-04-27 13:33:36 -03001897 runstate_set(RUN_STATE_RUNNING);
Liu, Jinsong4bc78a82013-09-25 16:38:29 +00001898 wakeup_reason = reason;
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001899 qemu_notify_event();
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001900}
1901
1902void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
1903{
1904 if (enabled) {
1905 wakeup_reason_mask |= (1 << reason);
1906 } else {
1907 wakeup_reason_mask &= ~(1 << reason);
1908 }
1909}
1910
1911void qemu_register_wakeup_notifier(Notifier *notifier)
1912{
1913 notifier_list_add(&wakeup_notifiers, notifier);
1914}
1915
Gleb Natapovf64622c2011-03-15 13:56:04 +02001916void qemu_system_killed(int signal, pid_t pid)
1917{
1918 shutdown_signal = signal;
1919 shutdown_pid = pid;
Kevin Wolfd9389b92011-09-14 15:38:40 +02001920 no_shutdown = 0;
Gleb Natapovf64622c2011-03-15 13:56:04 +02001921 qemu_system_shutdown_request();
1922}
1923
bellardbb0c6722004-06-20 12:37:32 +00001924void qemu_system_shutdown_request(void)
1925{
1926 shutdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001927 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001928}
1929
Igor Mammedov013c2f12012-09-05 23:06:25 +02001930static void qemu_system_powerdown(void)
1931{
1932 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
1933 notifier_list_notify(&powerdown_notifiers, NULL);
1934}
1935
bellard34751872005-07-02 14:31:34 +00001936void qemu_system_powerdown_request(void)
1937{
1938 powerdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001939 qemu_notify_event();
1940}
1941
Igor Mammedova9552c82012-09-05 23:06:21 +02001942void qemu_register_powerdown_notifier(Notifier *notifier)
1943{
1944 notifier_list_add(&powerdown_notifiers, notifier);
1945}
1946
Jan Kiszka8cf71712011-02-07 12:19:16 +01001947void qemu_system_debug_request(void)
1948{
1949 debug_requested = 1;
Jan Kiszka83f338f2011-02-07 12:19:17 +01001950 qemu_notify_event();
Jan Kiszka8cf71712011-02-07 12:19:16 +01001951}
1952
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001953void qemu_system_vmstop_request(RunState state)
Jan Kiszka8cf71712011-02-07 12:19:16 +01001954{
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001955 vmstop_requested = state;
Jan Kiszka8cf71712011-02-07 12:19:16 +01001956 qemu_notify_event();
1957}
1958
Paolo Bonzini99435902011-09-12 14:03:13 +02001959static bool main_loop_should_exit(void)
1960{
1961 RunState r;
1962 if (qemu_debug_requested()) {
1963 vm_stop(RUN_STATE_DEBUG);
1964 }
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001965 if (qemu_suspend_requested()) {
1966 qemu_system_suspend();
1967 }
Paolo Bonzini99435902011-09-12 14:03:13 +02001968 if (qemu_shutdown_requested()) {
1969 qemu_kill_report();
1970 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
1971 if (no_shutdown) {
1972 vm_stop(RUN_STATE_SHUTDOWN);
1973 } else {
1974 return true;
1975 }
1976 }
1977 if (qemu_reset_requested()) {
1978 pause_all_vcpus();
1979 cpu_synchronize_all_states();
1980 qemu_system_reset(VMRESET_REPORT);
1981 resume_all_vcpus();
Hu Taoede085b2013-04-26 11:24:40 +08001982 if (runstate_needs_reset()) {
Paolo Bonzini99435902011-09-12 14:03:13 +02001983 runstate_set(RUN_STATE_PAUSED);
1984 }
1985 }
Luiz Capitulino14058192012-08-08 17:29:17 -03001986 if (qemu_wakeup_requested()) {
1987 pause_all_vcpus();
1988 cpu_synchronize_all_states();
1989 qemu_system_reset(VMRESET_SILENT);
Liu, Jinsong4bc78a82013-09-25 16:38:29 +00001990 notifier_list_notify(&wakeup_notifiers, &wakeup_reason);
1991 wakeup_reason = QEMU_WAKEUP_REASON_NONE;
Luiz Capitulino14058192012-08-08 17:29:17 -03001992 resume_all_vcpus();
Luiz Capitulino17c86602012-08-09 11:27:30 -03001993 monitor_protocol_event(QEVENT_WAKEUP, NULL);
Luiz Capitulino14058192012-08-08 17:29:17 -03001994 }
Paolo Bonzini99435902011-09-12 14:03:13 +02001995 if (qemu_powerdown_requested()) {
Igor Mammedov013c2f12012-09-05 23:06:25 +02001996 qemu_system_powerdown();
Paolo Bonzini99435902011-09-12 14:03:13 +02001997 }
1998 if (qemu_vmstop_requested(&r)) {
1999 vm_stop(r);
2000 }
2001 return false;
2002}
2003
aliguori43b96852009-04-24 18:03:33 +00002004static void main_loop(void)
2005{
Jan Kiszkac9f711a2011-08-22 17:46:02 +02002006 bool nonblocking;
Paolo Bonzini99435902011-09-12 14:03:13 +02002007 int last_io = 0;
Jan Kiszka8e1b90e2011-02-01 22:15:46 +01002008#ifdef CONFIG_PROFILER
2009 int64_t ti;
2010#endif
Paolo Bonzini99435902011-09-12 14:03:13 +02002011 do {
Stefano Stabellinia7d42072013-06-03 15:38:43 +00002012 nonblocking = !kvm_enabled() && !xen_enabled() && last_io > 0;
aliguori43b96852009-04-24 18:03:33 +00002013#ifdef CONFIG_PROFILER
Jan Kiszka46481d32011-02-01 22:15:47 +01002014 ti = profile_getclock();
aliguori43b96852009-04-24 18:03:33 +00002015#endif
Jan Kiszkac9f711a2011-08-22 17:46:02 +02002016 last_io = main_loop_wait(nonblocking);
aliguori43b96852009-04-24 18:03:33 +00002017#ifdef CONFIG_PROFILER
Jan Kiszka46481d32011-02-01 22:15:47 +01002018 dev_time += profile_getclock() - ti;
aliguori43b96852009-04-24 18:03:33 +00002019#endif
Paolo Bonzini99435902011-09-12 14:03:13 +02002020 } while (!main_loop_should_exit());
bellardb4608c02003-06-27 17:34:32 +00002021}
2022
pbrook9bd7e6d2009-04-07 22:58:45 +00002023static void version(void)
2024{
Thomas Monjalonf75ca1a2010-04-28 14:42:01 +02002025 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
pbrook9bd7e6d2009-04-07 22:58:45 +00002026}
2027
ths15f82202007-06-29 23:26:08 +00002028static void help(int exitcode)
bellard0824d6f2003-06-24 13:42:40 +00002029{
Michael Ellermana3adb7a2011-12-19 17:19:31 +11002030 version();
2031 printf("usage: %s [options] [disk_image]\n\n"
2032 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
2033 error_get_progname());
2034
Michael Ellerman77bd1112011-12-19 17:19:30 +11002035#define QEMU_OPTIONS_GENERATE_HELP
2036#include "qemu-options-wrapper.h"
Michael Ellermana3adb7a2011-12-19 17:19:31 +11002037
2038 printf("\nDuring emulation, the following keys are useful:\n"
malc3f020d72010-02-08 12:04:56 +03002039 "ctrl-alt-f toggle full screen\n"
2040 "ctrl-alt-n switch to virtual console 'n'\n"
2041 "ctrl-alt toggle mouse and keyboard grab\n"
2042 "\n"
Michael Ellermana3adb7a2011-12-19 17:19:31 +11002043 "When using -nographic, press 'ctrl-a h' to get some help.\n");
2044
ths15f82202007-06-29 23:26:08 +00002045 exit(exitcode);
bellard0824d6f2003-06-24 13:42:40 +00002046}
2047
bellardcd6f1162004-05-13 22:02:20 +00002048#define HAS_ARG 0x0001
2049
bellardcd6f1162004-05-13 22:02:20 +00002050typedef struct QEMUOption {
2051 const char *name;
2052 int flags;
2053 int index;
Blue Swirlad960902010-03-29 19:23:52 +00002054 uint32_t arch_mask;
bellardcd6f1162004-05-13 22:02:20 +00002055} QEMUOption;
2056
blueswir1dbed7e42008-10-01 19:38:09 +00002057static const QEMUOption qemu_options[] = {
Blue Swirlad960902010-03-29 19:23:52 +00002058 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
Michael Ellerman77bd1112011-12-19 17:19:30 +11002059#define QEMU_OPTIONS_GENERATE_OPTIONS
2060#include "qemu-options-wrapper.h"
bellardcd6f1162004-05-13 22:02:20 +00002061 { NULL },
bellardfc01f7e2003-06-30 10:03:06 +00002062};
Blue Swirla369da52011-09-27 19:15:42 +00002063
2064static bool vga_available(void)
2065{
Aurelien Jarno36b7f272012-09-08 16:01:20 +02002066 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
Blue Swirla369da52011-09-27 19:15:42 +00002067}
2068
2069static bool cirrus_vga_available(void)
2070{
Aurelien Jarno36b7f272012-09-08 16:01:20 +02002071 return object_class_by_name("cirrus-vga")
2072 || object_class_by_name("isa-cirrus-vga");
Blue Swirla369da52011-09-27 19:15:42 +00002073}
2074
2075static bool vmware_vga_available(void)
2076{
Aurelien Jarno36b7f272012-09-08 16:01:20 +02002077 return object_class_by_name("vmware-svga");
Blue Swirla369da52011-09-27 19:15:42 +00002078}
2079
Aurelien Jarno879049a2012-09-08 12:01:06 +02002080static bool qxl_vga_available(void)
2081{
2082 return object_class_by_name("qxl-vga");
2083}
2084
malc3893c122008-09-28 00:42:05 +00002085static void select_vgahw (const char *p)
2086{
2087 const char *opts;
2088
Zachary Amsden86176752009-07-30 00:15:02 -10002089 vga_interface_type = VGA_NONE;
malc3893c122008-09-28 00:42:05 +00002090 if (strstart(p, "std", &opts)) {
Blue Swirla369da52011-09-27 19:15:42 +00002091 if (vga_available()) {
2092 vga_interface_type = VGA_STD;
2093 } else {
2094 fprintf(stderr, "Error: standard VGA not available\n");
2095 exit(0);
2096 }
malc3893c122008-09-28 00:42:05 +00002097 } else if (strstart(p, "cirrus", &opts)) {
Blue Swirla369da52011-09-27 19:15:42 +00002098 if (cirrus_vga_available()) {
2099 vga_interface_type = VGA_CIRRUS;
2100 } else {
2101 fprintf(stderr, "Error: Cirrus VGA not available\n");
2102 exit(0);
2103 }
malc3893c122008-09-28 00:42:05 +00002104 } else if (strstart(p, "vmware", &opts)) {
Blue Swirla369da52011-09-27 19:15:42 +00002105 if (vmware_vga_available()) {
2106 vga_interface_type = VGA_VMWARE;
2107 } else {
2108 fprintf(stderr, "Error: VMWare SVGA not available\n");
2109 exit(0);
2110 }
aliguori94909d92009-04-22 15:19:53 +00002111 } else if (strstart(p, "xenfb", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10002112 vga_interface_type = VGA_XENFB;
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +02002113 } else if (strstart(p, "qxl", &opts)) {
Aurelien Jarno879049a2012-09-08 12:01:06 +02002114 if (qxl_vga_available()) {
2115 vga_interface_type = VGA_QXL;
2116 } else {
2117 fprintf(stderr, "Error: QXL VGA not available\n");
2118 exit(0);
2119 }
aliguori28b85ed2009-04-22 15:19:48 +00002120 } else if (!strstart(p, "none", &opts)) {
malc3893c122008-09-28 00:42:05 +00002121 invalid_vga:
2122 fprintf(stderr, "Unknown vga type: %s\n", p);
2123 exit(1);
2124 }
malccb5a7aa2008-09-28 00:42:12 +00002125 while (*opts) {
2126 const char *nextopt;
2127
2128 if (strstart(opts, ",retrace=", &nextopt)) {
2129 opts = nextopt;
2130 if (strstart(opts, "dumb", &nextopt))
2131 vga_retrace_method = VGA_RETRACE_DUMB;
2132 else if (strstart(opts, "precise", &nextopt))
2133 vga_retrace_method = VGA_RETRACE_PRECISE;
2134 else goto invalid_vga;
2135 } else goto invalid_vga;
2136 opts = nextopt;
2137 }
malc3893c122008-09-28 00:42:05 +00002138}
2139
Jes Sorensen1472a952011-03-16 13:33:31 +01002140static DisplayType select_display(const char *p)
2141{
2142 const char *opts;
2143 DisplayType display = DT_DEFAULT;
2144
2145 if (strstart(p, "sdl", &opts)) {
2146#ifdef CONFIG_SDL
2147 display = DT_SDL;
2148 while (*opts) {
2149 const char *nextopt;
2150
2151 if (strstart(opts, ",frame=", &nextopt)) {
2152 opts = nextopt;
2153 if (strstart(opts, "on", &nextopt)) {
2154 no_frame = 0;
2155 } else if (strstart(opts, "off", &nextopt)) {
2156 no_frame = 1;
2157 } else {
Peter Maydell05175532011-03-23 03:40:57 +00002158 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01002159 }
2160 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
2161 opts = nextopt;
2162 if (strstart(opts, "on", &nextopt)) {
2163 alt_grab = 1;
2164 } else if (strstart(opts, "off", &nextopt)) {
2165 alt_grab = 0;
2166 } else {
Peter Maydell05175532011-03-23 03:40:57 +00002167 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01002168 }
2169 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
2170 opts = nextopt;
2171 if (strstart(opts, "on", &nextopt)) {
2172 ctrl_grab = 1;
2173 } else if (strstart(opts, "off", &nextopt)) {
2174 ctrl_grab = 0;
2175 } else {
Peter Maydell05175532011-03-23 03:40:57 +00002176 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01002177 }
2178 } else if (strstart(opts, ",window_close=", &nextopt)) {
2179 opts = nextopt;
2180 if (strstart(opts, "on", &nextopt)) {
2181 no_quit = 0;
2182 } else if (strstart(opts, "off", &nextopt)) {
2183 no_quit = 1;
2184 } else {
Peter Maydell05175532011-03-23 03:40:57 +00002185 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01002186 }
2187 } else {
Peter Maydell05175532011-03-23 03:40:57 +00002188 invalid_sdl_args:
2189 fprintf(stderr, "Invalid SDL option string: %s\n", p);
2190 exit(1);
Jes Sorensen1472a952011-03-16 13:33:31 +01002191 }
2192 opts = nextopt;
2193 }
2194#else
2195 fprintf(stderr, "SDL support is disabled\n");
2196 exit(1);
2197#endif
Jes Sorensen3264ff12011-03-16 13:33:33 +01002198 } else if (strstart(p, "vnc", &opts)) {
Jes Sorensen821601e2011-03-16 13:33:36 +01002199#ifdef CONFIG_VNC
Jes Sorensen3264ff12011-03-16 13:33:33 +01002200 display_remote++;
2201
2202 if (*opts) {
2203 const char *nextopt;
2204
2205 if (strstart(opts, "=", &nextopt)) {
2206 vnc_display = nextopt;
2207 }
2208 }
2209 if (!vnc_display) {
2210 fprintf(stderr, "VNC requires a display argument vnc=<display>\n");
2211 exit(1);
2212 }
Jes Sorensen821601e2011-03-16 13:33:36 +01002213#else
2214 fprintf(stderr, "VNC support is disabled\n");
2215 exit(1);
2216#endif
Jes Sorensen1472a952011-03-16 13:33:31 +01002217 } else if (strstart(p, "curses", &opts)) {
2218#ifdef CONFIG_CURSES
2219 display = DT_CURSES;
2220#else
2221 fprintf(stderr, "Curses support is disabled\n");
2222 exit(1);
2223#endif
Anthony Liguori15546422013-02-20 07:43:25 -06002224 } else if (strstart(p, "gtk", &opts)) {
2225#ifdef CONFIG_GTK
2226 display = DT_GTK;
2227#else
2228 fprintf(stderr, "GTK support is disabled\n");
2229 exit(1);
2230#endif
Jes Sorensen4171d322011-03-16 13:33:32 +01002231 } else if (strstart(p, "none", &opts)) {
2232 display = DT_NONE;
Jes Sorensen1472a952011-03-16 13:33:31 +01002233 } else {
Jes Sorensen1472a952011-03-16 13:33:31 +01002234 fprintf(stderr, "Unknown display type: %s\n", p);
2235 exit(1);
2236 }
2237
2238 return display;
2239}
2240
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02002241static int balloon_parse(const char *arg)
2242{
Gerd Hoffmann382f0742009-08-14 10:34:22 +02002243 QemuOpts *opts;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02002244
Gerd Hoffmann382f0742009-08-14 10:34:22 +02002245 if (strcmp(arg, "none") == 0) {
2246 return 0;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02002247 }
Gerd Hoffmann382f0742009-08-14 10:34:22 +02002248
2249 if (!strncmp(arg, "virtio", 6)) {
2250 if (arg[6] == ',') {
2251 /* have params -> parse them */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002252 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
Gerd Hoffmann382f0742009-08-14 10:34:22 +02002253 if (!opts)
2254 return -1;
2255 } else {
2256 /* create empty opts */
Dong Xu Wange478b442012-12-06 14:47:22 +08002257 opts = qemu_opts_create_nofail(qemu_find_opts("device"));
Gerd Hoffmann382f0742009-08-14 10:34:22 +02002258 }
Alexander Graf29f82b32011-03-29 15:29:29 +02002259 qemu_opt_set(opts, "driver", "virtio-balloon");
Gerd Hoffmann382f0742009-08-14 10:34:22 +02002260 return 0;
2261 }
2262
2263 return -1;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02002264}
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02002265
Paul Brook5cea8592009-05-30 00:52:44 +01002266char *qemu_find_file(int type, const char *name)
2267{
Gerd Hoffmann45240512013-03-08 11:42:24 +01002268 int i;
Paul Brook5cea8592009-05-30 00:52:44 +01002269 const char *subdir;
2270 char *buf;
2271
Peter Maydell31783202012-05-25 13:07:01 +01002272 /* Try the name as a straight path first */
2273 if (access(name, R_OK) == 0) {
Gerd Hoffmann45240512013-03-08 11:42:24 +01002274 trace_load_file(name, name);
Anthony Liguori7267c092011-08-20 22:09:37 -05002275 return g_strdup(name);
Paul Brook5cea8592009-05-30 00:52:44 +01002276 }
Gerd Hoffmann45240512013-03-08 11:42:24 +01002277
Paul Brook5cea8592009-05-30 00:52:44 +01002278 switch (type) {
2279 case QEMU_FILE_TYPE_BIOS:
2280 subdir = "";
2281 break;
2282 case QEMU_FILE_TYPE_KEYMAP:
2283 subdir = "keymaps/";
2284 break;
2285 default:
2286 abort();
2287 }
Gerd Hoffmann45240512013-03-08 11:42:24 +01002288
2289 for (i = 0; i < data_dir_idx; i++) {
2290 buf = g_strdup_printf("%s/%s%s", data_dir[i], subdir, name);
2291 if (access(buf, R_OK) == 0) {
2292 trace_load_file(name, buf);
2293 return buf;
2294 }
Anthony Liguori7267c092011-08-20 22:09:37 -05002295 g_free(buf);
Paul Brook5cea8592009-05-30 00:52:44 +01002296 }
Gerd Hoffmann45240512013-03-08 11:42:24 +01002297 return NULL;
Paul Brook5cea8592009-05-30 00:52:44 +01002298}
2299
Markus Armbrusterff952ba2010-01-29 19:48:57 +01002300static int device_help_func(QemuOpts *opts, void *opaque)
2301{
2302 return qdev_device_help(opts);
2303}
2304
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02002305static int device_init_func(QemuOpts *opts, void *opaque)
2306{
2307 DeviceState *dev;
2308
2309 dev = qdev_device_add(opts);
2310 if (!dev)
2311 return -1;
Paolo Bonzinib09995a2013-01-25 14:12:37 +01002312 object_unref(OBJECT(dev));
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02002313 return 0;
2314}
2315
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002316static int chardev_init_func(QemuOpts *opts, void *opaque)
2317{
Gerd Hoffmannbd2d80b2012-10-15 09:28:05 +02002318 Error *local_err = NULL;
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002319
Gerd Hoffmannbd2d80b2012-10-15 09:28:05 +02002320 qemu_chr_new_from_opts(opts, NULL, &local_err);
2321 if (error_is_set(&local_err)) {
Seiji Aguchi4a44d852013-08-05 15:40:44 -04002322 error_report("%s", error_get_pretty(local_err));
Gerd Hoffmannbd2d80b2012-10-15 09:28:05 +02002323 error_free(local_err);
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002324 return -1;
Gerd Hoffmannbd2d80b2012-10-15 09:28:05 +02002325 }
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002326 return 0;
2327}
2328
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07002329#ifdef CONFIG_VIRTFS
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302330static int fsdev_init_func(QemuOpts *opts, void *opaque)
2331{
2332 int ret;
2333 ret = qemu_fsdev_add(opts);
2334
2335 return ret;
2336}
2337#endif
2338
Gerd Hoffmann88589342009-12-08 13:11:50 +01002339static int mon_init_func(QemuOpts *opts, void *opaque)
2340{
2341 CharDriverState *chr;
2342 const char *chardev;
2343 const char *mode;
2344 int flags;
2345
2346 mode = qemu_opt_get(opts, "mode");
2347 if (mode == NULL) {
2348 mode = "readline";
2349 }
2350 if (strcmp(mode, "readline") == 0) {
2351 flags = MONITOR_USE_READLINE;
2352 } else if (strcmp(mode, "control") == 0) {
2353 flags = MONITOR_USE_CONTROL;
2354 } else {
2355 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
2356 exit(1);
2357 }
2358
Daniel P. Berrange39eaab92010-06-07 15:42:31 +01002359 if (qemu_opt_get_bool(opts, "pretty", 0))
2360 flags |= MONITOR_USE_PRETTY;
2361
Gerd Hoffmann88589342009-12-08 13:11:50 +01002362 if (qemu_opt_get_bool(opts, "default", 0))
2363 flags |= MONITOR_IS_DEFAULT;
2364
2365 chardev = qemu_opt_get(opts, "chardev");
2366 chr = qemu_chr_find(chardev);
2367 if (chr == NULL) {
2368 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
2369 exit(1);
2370 }
2371
Hans de Goede456d6062013-03-27 20:29:40 +01002372 qemu_chr_fe_claim_no_fail(chr);
Gerd Hoffmann88589342009-12-08 13:11:50 +01002373 monitor_init(chr, flags);
2374 return 0;
2375}
2376
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002377static void monitor_parse(const char *optarg, const char *mode)
Gerd Hoffmann88589342009-12-08 13:11:50 +01002378{
2379 static int monitor_device_index = 0;
2380 QemuOpts *opts;
2381 const char *p;
2382 char label[32];
2383 int def = 0;
2384
2385 if (strstart(optarg, "chardev:", &p)) {
2386 snprintf(label, sizeof(label), "%s", p);
2387 } else {
Jan Kiszka140e0652010-04-06 16:55:52 +02002388 snprintf(label, sizeof(label), "compat_monitor%d",
2389 monitor_device_index);
2390 if (monitor_device_index == 0) {
Gerd Hoffmann88589342009-12-08 13:11:50 +01002391 def = 1;
2392 }
2393 opts = qemu_chr_parse_compat(label, optarg);
2394 if (!opts) {
2395 fprintf(stderr, "parse error: %s\n", optarg);
2396 exit(1);
2397 }
2398 }
2399
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03002400 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, NULL);
Gerd Hoffmann88589342009-12-08 13:11:50 +01002401 if (!opts) {
2402 fprintf(stderr, "duplicate chardev: %s\n", label);
2403 exit(1);
2404 }
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002405 qemu_opt_set(opts, "mode", mode);
Gerd Hoffmann88589342009-12-08 13:11:50 +01002406 qemu_opt_set(opts, "chardev", label);
2407 if (def)
2408 qemu_opt_set(opts, "default", "on");
2409 monitor_device_index++;
2410}
2411
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002412struct device_config {
2413 enum {
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002414 DEV_USB, /* -usbdevice */
2415 DEV_BT, /* -bt */
2416 DEV_SERIAL, /* -serial */
2417 DEV_PARALLEL, /* -parallel */
2418 DEV_VIRTCON, /* -virtioconsole */
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002419 DEV_DEBUGCON, /* -debugcon */
Markus Armbrusteref0c4a02012-02-07 15:09:13 +01002420 DEV_GDB, /* -gdb, -s */
Alexander Graf3ef669e2013-01-24 12:18:52 +01002421 DEV_SCLP, /* s390 sclp */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002422 } type;
2423 const char *cmdline;
Markus Armbrusterd9a59542012-02-07 15:09:12 +01002424 Location loc;
Blue Swirl72cf2d42009-09-12 07:36:22 +00002425 QTAILQ_ENTRY(device_config) next;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002426};
Blue Swirl4fdcac02012-10-28 11:04:47 +00002427
2428static QTAILQ_HEAD(, device_config) device_configs =
2429 QTAILQ_HEAD_INITIALIZER(device_configs);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002430
2431static void add_device_config(int type, const char *cmdline)
2432{
2433 struct device_config *conf;
2434
Anthony Liguori7267c092011-08-20 22:09:37 -05002435 conf = g_malloc0(sizeof(*conf));
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002436 conf->type = type;
2437 conf->cmdline = cmdline;
Markus Armbrusterd9a59542012-02-07 15:09:12 +01002438 loc_save(&conf->loc);
Blue Swirl72cf2d42009-09-12 07:36:22 +00002439 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002440}
2441
2442static int foreach_device_config(int type, int (*func)(const char *cmdline))
2443{
2444 struct device_config *conf;
2445 int rc;
2446
Blue Swirl72cf2d42009-09-12 07:36:22 +00002447 QTAILQ_FOREACH(conf, &device_configs, next) {
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002448 if (conf->type != type)
2449 continue;
Markus Armbrusterd9a59542012-02-07 15:09:12 +01002450 loc_push_restore(&conf->loc);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002451 rc = func(conf->cmdline);
Markus Armbrusterd9a59542012-02-07 15:09:12 +01002452 loc_pop(&conf->loc);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002453 if (0 != rc)
2454 return rc;
2455 }
2456 return 0;
2457}
2458
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002459static int serial_parse(const char *devname)
2460{
2461 static int index = 0;
2462 char label[32];
2463
2464 if (strcmp(devname, "none") == 0)
2465 return 0;
2466 if (index == MAX_SERIAL_PORTS) {
2467 fprintf(stderr, "qemu: too many serial ports\n");
2468 exit(1);
2469 }
2470 snprintf(label, sizeof(label), "serial%d", index);
Anthony Liguori27143a42011-08-15 11:17:36 -05002471 serial_hds[index] = qemu_chr_new(label, devname, NULL);
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002472 if (!serial_hds[index]) {
Peter Maydell52d06132012-07-09 04:28:30 +00002473 fprintf(stderr, "qemu: could not connect serial device"
2474 " to character backend '%s'\n", devname);
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002475 return -1;
2476 }
2477 index++;
2478 return 0;
2479}
2480
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002481static int parallel_parse(const char *devname)
2482{
2483 static int index = 0;
2484 char label[32];
2485
2486 if (strcmp(devname, "none") == 0)
2487 return 0;
2488 if (index == MAX_PARALLEL_PORTS) {
2489 fprintf(stderr, "qemu: too many parallel ports\n");
2490 exit(1);
2491 }
2492 snprintf(label, sizeof(label), "parallel%d", index);
Anthony Liguori27143a42011-08-15 11:17:36 -05002493 parallel_hds[index] = qemu_chr_new(label, devname, NULL);
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002494 if (!parallel_hds[index]) {
Peter Maydell52d06132012-07-09 04:28:30 +00002495 fprintf(stderr, "qemu: could not connect parallel device"
2496 " to character backend '%s'\n", devname);
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002497 return -1;
2498 }
2499 index++;
2500 return 0;
2501}
2502
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002503static int virtcon_parse(const char *devname)
2504{
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002505 QemuOptsList *device = qemu_find_opts("device");
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002506 static int index = 0;
2507 char label[32];
Amit Shah392ecf52010-01-21 16:19:23 +05302508 QemuOpts *bus_opts, *dev_opts;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002509
2510 if (strcmp(devname, "none") == 0)
2511 return 0;
2512 if (index == MAX_VIRTIO_CONSOLES) {
2513 fprintf(stderr, "qemu: too many virtio consoles\n");
2514 exit(1);
2515 }
Amit Shah392ecf52010-01-21 16:19:23 +05302516
Dong Xu Wange478b442012-12-06 14:47:22 +08002517 bus_opts = qemu_opts_create_nofail(device);
Anthony Liguorie87f7fc2012-02-06 11:07:18 -06002518 if (arch_type == QEMU_ARCH_S390X) {
2519 qemu_opt_set(bus_opts, "driver", "virtio-serial-s390");
2520 } else {
2521 qemu_opt_set(bus_opts, "driver", "virtio-serial-pci");
Laszlo Ersek4d8b3c62013-03-21 00:23:13 +01002522 }
Amit Shah392ecf52010-01-21 16:19:23 +05302523
Dong Xu Wange478b442012-12-06 14:47:22 +08002524 dev_opts = qemu_opts_create_nofail(device);
Amit Shah392ecf52010-01-21 16:19:23 +05302525 qemu_opt_set(dev_opts, "driver", "virtconsole");
2526
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002527 snprintf(label, sizeof(label), "virtcon%d", index);
Anthony Liguori27143a42011-08-15 11:17:36 -05002528 virtcon_hds[index] = qemu_chr_new(label, devname, NULL);
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002529 if (!virtcon_hds[index]) {
Peter Maydell52d06132012-07-09 04:28:30 +00002530 fprintf(stderr, "qemu: could not connect virtio console"
2531 " to character backend '%s'\n", devname);
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002532 return -1;
2533 }
Amit Shah392ecf52010-01-21 16:19:23 +05302534 qemu_opt_set(dev_opts, "chardev", label);
2535
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002536 index++;
2537 return 0;
2538}
2539
Alexander Graf3ef669e2013-01-24 12:18:52 +01002540static int sclp_parse(const char *devname)
2541{
2542 QemuOptsList *device = qemu_find_opts("device");
2543 static int index = 0;
2544 char label[32];
2545 QemuOpts *dev_opts;
2546
2547 if (strcmp(devname, "none") == 0) {
2548 return 0;
2549 }
2550 if (index == MAX_SCLP_CONSOLES) {
2551 fprintf(stderr, "qemu: too many sclp consoles\n");
2552 exit(1);
2553 }
2554
2555 assert(arch_type == QEMU_ARCH_S390X);
2556
2557 dev_opts = qemu_opts_create(device, NULL, 0, NULL);
2558 qemu_opt_set(dev_opts, "driver", "sclpconsole");
2559
2560 snprintf(label, sizeof(label), "sclpcon%d", index);
2561 sclp_hds[index] = qemu_chr_new(label, devname, NULL);
2562 if (!sclp_hds[index]) {
2563 fprintf(stderr, "qemu: could not connect sclp console"
2564 " to character backend '%s'\n", devname);
2565 return -1;
2566 }
2567 qemu_opt_set(dev_opts, "chardev", label);
2568
2569 index++;
2570 return 0;
2571}
2572
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002573static int debugcon_parse(const char *devname)
Laszlo Ersek4d8b3c62013-03-21 00:23:13 +01002574{
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002575 QemuOpts *opts;
2576
Anthony Liguori27143a42011-08-15 11:17:36 -05002577 if (!qemu_chr_new("debugcon", devname, NULL)) {
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002578 exit(1);
2579 }
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03002580 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL);
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002581 if (!opts) {
2582 fprintf(stderr, "qemu: already have a debugcon device\n");
2583 exit(1);
2584 }
2585 qemu_opt_set(opts, "driver", "isa-debugcon");
2586 qemu_opt_set(opts, "chardev", "debugcon");
2587 return 0;
2588}
2589
Jan Kiszka9052ea62011-07-23 12:38:37 +02002590static QEMUMachine *machine_parse(const char *name)
2591{
2592 QEMUMachine *m, *machine = NULL;
2593
2594 if (name) {
2595 machine = find_machine(name);
2596 }
2597 if (machine) {
2598 return machine;
2599 }
2600 printf("Supported machines are:\n");
2601 for (m = first_machine; m != NULL; m = m->next) {
2602 if (m->alias) {
Peter Maydell3b264862012-02-22 22:13:11 +00002603 printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name);
Jan Kiszka9052ea62011-07-23 12:38:37 +02002604 }
Peter Maydell3b264862012-02-22 22:13:11 +00002605 printf("%-20s %s%s\n", m->name, m->desc,
Jan Kiszka9052ea62011-07-23 12:38:37 +02002606 m->is_default ? " (default)" : "");
2607 }
Peter Maydellc8057f92012-08-02 13:45:54 +01002608 exit(!name || !is_help_option(name));
Jan Kiszka9052ea62011-07-23 12:38:37 +02002609}
2610
Anthony PERARD303d4e82010-09-21 20:05:31 +01002611static int tcg_init(void)
2612{
Jan Kiszkad5ab9712011-08-02 16:10:21 +02002613 tcg_exec_init(tcg_tb_size * 1024 * 1024);
Anthony PERARD303d4e82010-09-21 20:05:31 +01002614 return 0;
2615}
2616
2617static struct {
2618 const char *opt_name;
2619 const char *name;
2620 int (*available)(void);
2621 int (*init)(void);
liguangd5286af2013-01-24 13:03:27 +08002622 bool *allowed;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002623} accel_list[] = {
2624 { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
Anthony PERARD3285cf42010-08-19 12:27:56 +01002625 { "xen", "Xen", xen_available, xen_init, &xen_allowed },
Anthony PERARD303d4e82010-09-21 20:05:31 +01002626 { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
Paolo Bonzinid4fce242013-10-18 13:51:11 +02002627 { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed },
Anthony PERARD303d4e82010-09-21 20:05:31 +01002628};
2629
2630static int configure_accelerator(void)
2631{
Markus Armbruster36ad0e92013-07-04 15:09:20 +02002632 const char *p;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002633 char buf[10];
2634 int i, ret;
liguang217e21b2013-01-24 13:03:26 +08002635 bool accel_initialised = false;
2636 bool init_failed = false;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002637
Markus Armbruster36ad0e92013-07-04 15:09:20 +02002638 p = qemu_opt_get(qemu_get_machine_opts(), "accel");
Anthony PERARD303d4e82010-09-21 20:05:31 +01002639 if (p == NULL) {
2640 /* Use the default "accelerator", tcg */
2641 p = "tcg";
2642 }
2643
Peter Maydell1b785a92012-02-07 20:57:27 +00002644 while (!accel_initialised && *p != '\0') {
Anthony PERARD303d4e82010-09-21 20:05:31 +01002645 if (*p == ':') {
2646 p++;
2647 }
2648 p = get_opt_name(buf, sizeof (buf), p, ':');
2649 for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
2650 if (strcmp(accel_list[i].opt_name, buf) == 0) {
liguange3c66d92013-01-24 13:03:25 +08002651 if (!accel_list[i].available()) {
2652 printf("%s not supported for this target\n",
2653 accel_list[i].name);
2654 continue;
2655 }
liguangd5286af2013-01-24 13:03:27 +08002656 *(accel_list[i].allowed) = true;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002657 ret = accel_list[i].init();
2658 if (ret < 0) {
liguang217e21b2013-01-24 13:03:26 +08002659 init_failed = true;
liguange3c66d92013-01-24 13:03:25 +08002660 fprintf(stderr, "failed to initialize %s: %s\n",
2661 accel_list[i].name,
2662 strerror(-ret));
liguangd5286af2013-01-24 13:03:27 +08002663 *(accel_list[i].allowed) = false;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002664 } else {
liguang217e21b2013-01-24 13:03:26 +08002665 accel_initialised = true;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002666 }
2667 break;
2668 }
2669 }
2670 if (i == ARRAY_SIZE(accel_list)) {
2671 fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
2672 }
2673 }
2674
Peter Maydell1b785a92012-02-07 20:57:27 +00002675 if (!accel_initialised) {
liguang217e21b2013-01-24 13:03:26 +08002676 if (!init_failed) {
2677 fprintf(stderr, "No accelerator found!\n");
2678 }
Anthony PERARD303d4e82010-09-21 20:05:31 +01002679 exit(1);
2680 }
2681
2682 if (init_failed) {
2683 fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
2684 }
2685
Peter Maydell1b785a92012-02-07 20:57:27 +00002686 return !accel_initialised;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002687}
2688
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02002689void qemu_add_exit_notifier(Notifier *notify)
2690{
2691 notifier_list_add(&exit_notifiers, notify);
2692}
2693
2694void qemu_remove_exit_notifier(Notifier *notify)
2695{
Paolo Bonzini31552522012-01-13 17:34:01 +01002696 notifier_remove(notify);
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02002697}
2698
2699static void qemu_run_exit_notifiers(void)
2700{
Jan Kiszka9e8dd452011-06-20 14:06:26 +02002701 notifier_list_notify(&exit_notifiers, NULL);
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02002702}
2703
Gleb Natapov4cab9462010-12-08 13:35:08 +02002704void qemu_add_machine_init_done_notifier(Notifier *notify)
2705{
2706 notifier_list_add(&machine_init_done_notifiers, notify);
2707}
2708
2709static void qemu_run_machine_init_done_notifiers(void)
2710{
Jan Kiszka9e8dd452011-06-20 14:06:26 +02002711 notifier_list_notify(&machine_init_done_notifiers, NULL);
Gleb Natapov4cab9462010-12-08 13:35:08 +02002712}
2713
Anthony Liguori6530a972010-01-22 09:18:06 -06002714static const QEMUOption *lookup_opt(int argc, char **argv,
2715 const char **poptarg, int *poptind)
2716{
2717 const QEMUOption *popt;
2718 int optind = *poptind;
2719 char *r = argv[optind];
2720 const char *optarg;
2721
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002722 loc_set_cmdline(argv, optind, 1);
Anthony Liguori6530a972010-01-22 09:18:06 -06002723 optind++;
2724 /* Treat --foo the same as -foo. */
2725 if (r[1] == '-')
2726 r++;
2727 popt = qemu_options;
2728 for(;;) {
2729 if (!popt->name) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002730 error_report("invalid option");
Anthony Liguori6530a972010-01-22 09:18:06 -06002731 exit(1);
2732 }
2733 if (!strcmp(popt->name, r + 1))
2734 break;
2735 popt++;
2736 }
2737 if (popt->flags & HAS_ARG) {
2738 if (optind >= argc) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002739 error_report("requires an argument");
Anthony Liguori6530a972010-01-22 09:18:06 -06002740 exit(1);
2741 }
2742 optarg = argv[optind++];
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002743 loc_set_cmdline(argv, optind - 2, 2);
Anthony Liguori6530a972010-01-22 09:18:06 -06002744 } else {
2745 optarg = NULL;
2746 }
2747
2748 *poptarg = optarg;
2749 *poptind = optind;
2750
2751 return popt;
2752}
2753
Anthony Liguori07501122011-08-20 22:38:31 -05002754static gpointer malloc_and_trace(gsize n_bytes)
2755{
2756 void *ptr = malloc(n_bytes);
Frediano Ziglioa74cd8c2011-08-31 09:25:35 +02002757 trace_g_malloc(n_bytes, ptr);
Anthony Liguori07501122011-08-20 22:38:31 -05002758 return ptr;
2759}
2760
2761static gpointer realloc_and_trace(gpointer mem, gsize n_bytes)
2762{
2763 void *ptr = realloc(mem, n_bytes);
Frediano Ziglioa74cd8c2011-08-31 09:25:35 +02002764 trace_g_realloc(mem, n_bytes, ptr);
Anthony Liguori07501122011-08-20 22:38:31 -05002765 return ptr;
2766}
2767
2768static void free_and_trace(gpointer mem)
2769{
Frediano Ziglioa74cd8c2011-08-31 09:25:35 +02002770 trace_g_free(mem);
Anthony Liguori07501122011-08-20 22:38:31 -05002771 free(mem);
2772}
2773
Anthony Liguori68d98d32012-06-25 14:36:33 -05002774static int object_set_property(const char *name, const char *value, void *opaque)
2775{
2776 Object *obj = OBJECT(opaque);
2777 StringInputVisitor *siv;
2778 Error *local_err = NULL;
2779
2780 if (strcmp(name, "qom-type") == 0 || strcmp(name, "id") == 0) {
2781 return 0;
2782 }
2783
2784 siv = string_input_visitor_new(value);
2785 object_property_set(obj, string_input_get_visitor(siv), name, &local_err);
2786 string_input_visitor_cleanup(siv);
2787
2788 if (local_err) {
2789 qerror_report_err(local_err);
2790 error_free(local_err);
2791 return -1;
2792 }
2793
2794 return 0;
2795}
2796
2797static int object_create(QemuOpts *opts, void *opaque)
2798{
2799 const char *type = qemu_opt_get(opts, "qom-type");
2800 const char *id = qemu_opts_id(opts);
2801 Object *obj;
2802
2803 g_assert(type != NULL);
2804
2805 if (id == NULL) {
2806 qerror_report(QERR_MISSING_PARAMETER, "id");
2807 return -1;
2808 }
2809
2810 obj = object_new(type);
2811 if (qemu_opt_foreach(opts, object_set_property, obj, 1) < 0) {
2812 return -1;
2813 }
2814
2815 object_property_add_child(container_get(object_get_root(), "/objects"),
2816 id, obj, NULL);
2817
2818 return 0;
2819}
2820
malc902b3d52008-12-10 19:18:40 +00002821int main(int argc, char **argv, char **envp)
bellard0824d6f2003-06-24 13:42:40 +00002822{
thse4bcb142007-12-02 04:51:10 +00002823 int i;
Eduardo Habkostda1fcfd2010-04-06 19:22:07 -03002824 int snapshot, linux_boot;
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01002825 const char *icount_option = NULL;
bellard7f7f9872003-10-30 01:11:23 +00002826 const char *initrd_filename;
bellarda20dd502003-09-30 21:07:02 +00002827 const char *kernel_filename, *kernel_cmdline;
Markus Armbrustere3fdc532013-10-01 13:47:22 +02002828 const char *boot_order;
aliguori3023f332009-01-16 19:04:14 +00002829 DisplayState *ds;
malc9f227bc2012-08-27 18:33:22 +04002830 int cyls, heads, secs, translation;
2831 QemuOpts *hda_opts = NULL, *opts, *machine_opts;
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002832 QemuOptsList *olist;
bellardcd6f1162004-05-13 22:02:20 +00002833 int optind;
Anthony Liguori6530a972010-01-22 09:18:06 -06002834 const char *optarg;
bellardd63d3072004-10-03 13:29:03 +00002835 const char *loadvm = NULL;
bellardcc1daa42005-06-05 14:49:17 +00002836 QEMUMachine *machine;
j_mayer94fc95c2007-03-05 19:44:02 +00002837 const char *cpu_model;
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +02002838 const char *vga_model = "none";
Paolo Bonzinid4fce242013-10-18 13:51:11 +02002839 const char *qtest_chrdev = NULL;
2840 const char *qtest_log = NULL;
ths93815bc2007-03-19 15:58:31 +00002841 const char *pid_file = NULL;
aliguori5bb79102008-10-13 03:12:02 +00002842 const char *incoming = NULL;
Jes Sorensen821601e2011-03-16 13:33:36 +01002843#ifdef CONFIG_VNC
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002844 int show_vnc_port = 0;
Jes Sorensen821601e2011-03-16 13:33:36 +01002845#endif
Eduardo Habkost3ed2d9e2012-05-02 13:07:28 -03002846 bool defconfig = true;
Eduardo Habkostf29a5612012-05-02 13:07:29 -03002847 bool userconfig = true;
Matthew Fernandezc235d732011-06-07 16:32:40 +00002848 const char *log_mask = NULL;
2849 const char *log_file = NULL;
Anthony Liguori07501122011-08-20 22:38:31 -05002850 GMemVTable mem_trace = {
2851 .malloc = malloc_and_trace,
2852 .realloc = realloc_and_trace,
2853 .free = free_and_trace,
2854 };
Lluís23d15e82011-08-31 20:31:31 +02002855 const char *trace_events = NULL;
Lluíse4858972011-08-31 20:31:03 +02002856 const char *trace_file = NULL;
Stefan Hajnoczi0b5538c2011-02-26 18:38:39 +00002857
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02002858 atexit(qemu_run_exit_notifiers);
Markus Armbruster65abca02010-02-24 14:37:14 +01002859 error_set_progname(argv[0]);
2860
Anthony Liguori07501122011-08-20 22:38:31 -05002861 g_mem_set_vtable(&mem_trace);
Andreas Färberdb529aa2011-10-31 19:14:56 +01002862 if (!g_thread_supported()) {
Alon Levy42ed3722011-12-20 13:41:04 +02002863#if !GLIB_CHECK_VERSION(2, 31, 0)
Andreas Färberdb529aa2011-10-31 19:14:56 +01002864 g_thread_init(NULL);
Alon Levy42ed3722011-12-20 13:41:04 +02002865#else
2866 fprintf(stderr, "glib threading failed to initialize.\n");
2867 exit(1);
2868#endif
Andreas Färberdb529aa2011-10-31 19:14:56 +01002869 }
Anthony Liguori07501122011-08-20 22:38:31 -05002870
Andreas Färber1b71f7c2012-03-04 21:32:35 +01002871 module_call_init(MODULE_INIT_QOM);
2872
Paolo Bonzini4d454572012-11-26 16:03:42 +01002873 qemu_add_opts(&qemu_drive_opts);
Amos Kong968854c2013-11-09 12:15:47 +08002874 qemu_add_drive_opts(&qemu_legacy_drive_opts);
2875 qemu_add_drive_opts(&qemu_common_drive_opts);
2876 qemu_add_drive_opts(&qemu_drive_opts);
Paolo Bonzini4d454572012-11-26 16:03:42 +01002877 qemu_add_opts(&qemu_chardev_opts);
2878 qemu_add_opts(&qemu_device_opts);
2879 qemu_add_opts(&qemu_netdev_opts);
2880 qemu_add_opts(&qemu_net_opts);
2881 qemu_add_opts(&qemu_rtc_opts);
2882 qemu_add_opts(&qemu_global_opts);
2883 qemu_add_opts(&qemu_mon_opts);
2884 qemu_add_opts(&qemu_trace_opts);
2885 qemu_add_opts(&qemu_option_rom_opts);
2886 qemu_add_opts(&qemu_machine_opts);
Michael Tokarev12b7f572013-06-24 15:06:52 +04002887 qemu_add_opts(&qemu_smp_opts);
Paolo Bonzini4d454572012-11-26 16:03:42 +01002888 qemu_add_opts(&qemu_boot_opts);
2889 qemu_add_opts(&qemu_sandbox_opts);
2890 qemu_add_opts(&qemu_add_fd_opts);
2891 qemu_add_opts(&qemu_object_opts);
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05002892 qemu_add_opts(&qemu_tpmdev_opts);
Satoru Moriya888a6bc2013-04-19 16:42:06 +02002893 qemu_add_opts(&qemu_realtime_opts);
Seiji Aguchi5e2ac512013-07-03 23:02:46 -04002894 qemu_add_opts(&qemu_msg_opts);
Paolo Bonzini4d454572012-11-26 16:03:42 +01002895
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -03002896 runstate_init();
2897
Jan Kiszka68752042009-09-15 13:36:04 +02002898 init_clocks();
Alex Bligh884f17c2013-08-21 16:03:04 +01002899 rtc_clock = QEMU_CLOCK_HOST;
Jan Kiszka68752042009-09-15 13:36:04 +02002900
Richard Hendersonb6a3e692013-06-04 11:24:49 -07002901 qemu_init_auxval(envp);
Richard Henderson664d2c42013-06-10 09:05:09 -07002902 qemu_cache_utils_init();
malc902b3d52008-12-10 19:18:40 +00002903
Blue Swirl72cf2d42009-09-12 07:36:22 +00002904 QLIST_INIT (&vm_change_state_head);
Jes Sorensenfe98ac12010-06-10 11:42:21 +02002905 os_setup_early_signal_handling();
bellardbe995c22006-06-25 16:25:21 +00002906
Anthony Liguorif80f9ec2009-05-20 18:38:09 -05002907 module_call_init(MODULE_INIT_MACHINE);
Anthony Liguori0c257432009-05-21 20:41:01 -05002908 machine = find_default_machine();
j_mayer94fc95c2007-03-05 19:44:02 +00002909 cpu_model = NULL;
aurel324fc5d072008-04-27 21:39:40 +00002910 ram_size = 0;
bellard33e39632003-07-06 17:15:21 +00002911 snapshot = 0;
malc9f227bc2012-08-27 18:33:22 +04002912 cyls = heads = secs = 0;
2913 translation = BIOS_ATA_TRANSLATION_AUTO;
bellardc4b1fcc2004-03-14 21:44:30 +00002914
aliguori268a3622009-04-21 22:30:27 +00002915 for (i = 0; i < MAX_NODES; i++) {
2916 node_mem[i] = 0;
Chegu Vinodee785fe2012-07-16 21:31:30 -07002917 node_cpumask[i] = bitmap_new(MAX_CPUMASK_BITS);
aliguori268a3622009-04-21 22:30:27 +00002918 }
2919
aliguori268a3622009-04-21 22:30:27 +00002920 nb_numa_nodes = 0;
bellard7c9d8e02005-11-15 22:16:05 +00002921 nb_nics = 0;
ths3b46e622007-09-17 08:09:54 +00002922
Peter Lieven142c6b12013-03-21 13:07:10 +01002923 bdrv_init_with_whitelist();
2924
blueswir141bd6392008-10-05 09:56:21 +00002925 autostart= 1;
2926
Anthony Liguori292444c2010-01-21 10:57:58 -06002927 /* first pass of option parsing */
2928 optind = 1;
2929 while (optind < argc) {
2930 if (argv[optind][0] != '-') {
2931 /* disk image */
Anthony Liguori28e68d62010-01-27 10:46:00 -06002932 optind++;
Anthony Liguori292444c2010-01-21 10:57:58 -06002933 continue;
2934 } else {
2935 const QEMUOption *popt;
2936
2937 popt = lookup_opt(argc, argv, &optarg, &optind);
2938 switch (popt->index) {
2939 case QEMU_OPTION_nodefconfig:
Eduardo Habkost3ed2d9e2012-05-02 13:07:28 -03002940 defconfig = false;
Anthony Liguori292444c2010-01-21 10:57:58 -06002941 break;
Eduardo Habkostf29a5612012-05-02 13:07:29 -03002942 case QEMU_OPTION_nouserconfig:
2943 userconfig = false;
2944 break;
Anthony Liguori292444c2010-01-21 10:57:58 -06002945 }
2946 }
2947 }
2948
2949 if (defconfig) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002950 int ret;
Eduardo Habkostf29a5612012-05-02 13:07:29 -03002951 ret = qemu_read_default_config_files(userconfig);
Eduardo Habkostb5a8fe52012-05-02 13:07:25 -03002952 if (ret < 0) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002953 exit(1);
Anthony Liguori292444c2010-01-21 10:57:58 -06002954 }
2955 }
2956
2957 /* second pass of option parsing */
bellardcd6f1162004-05-13 22:02:20 +00002958 optind = 1;
bellard0824d6f2003-06-24 13:42:40 +00002959 for(;;) {
bellardcd6f1162004-05-13 22:02:20 +00002960 if (optind >= argc)
bellard0824d6f2003-06-24 13:42:40 +00002961 break;
Anthony Liguori6530a972010-01-22 09:18:06 -06002962 if (argv[optind][0] != '-') {
malc9f227bc2012-08-27 18:33:22 +04002963 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
bellardcd6f1162004-05-13 22:02:20 +00002964 } else {
2965 const QEMUOption *popt;
2966
Anthony Liguori6530a972010-01-22 09:18:06 -06002967 popt = lookup_opt(argc, argv, &optarg, &optind);
Blue Swirlad960902010-03-29 19:23:52 +00002968 if (!(popt->arch_mask & arch_type)) {
2969 printf("Option %s not supported for this target\n", popt->name);
2970 exit(1);
2971 }
bellardcd6f1162004-05-13 22:02:20 +00002972 switch(popt->index) {
bellardcc1daa42005-06-05 14:49:17 +00002973 case QEMU_OPTION_M:
Jan Kiszka9052ea62011-07-23 12:38:37 +02002974 machine = machine_parse(optarg);
bellardcc1daa42005-06-05 14:49:17 +00002975 break;
Jan Kiszkae43d5942012-10-05 14:51:40 -03002976 case QEMU_OPTION_no_kvm_irqchip: {
2977 olist = qemu_find_opts("machine");
2978 qemu_opts_parse(olist, "kernel_irqchip=off", 0);
2979 break;
2980 }
j_mayer94fc95c2007-03-05 19:44:02 +00002981 case QEMU_OPTION_cpu:
2982 /* hw initialization will check this */
Eduardo Habkostecf40be2012-03-09 16:19:07 -03002983 cpu_model = optarg;
j_mayer94fc95c2007-03-05 19:44:02 +00002984 break;
bellardcd6f1162004-05-13 22:02:20 +00002985 case QEMU_OPTION_hda:
malc9f227bc2012-08-27 18:33:22 +04002986 {
2987 char buf[256];
2988 if (cyls == 0)
2989 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2990 else
2991 snprintf(buf, sizeof(buf),
2992 "%s,cyls=%d,heads=%d,secs=%d%s",
2993 HD_OPTS , cyls, heads, secs,
2994 translation == BIOS_ATA_TRANSLATION_LBA ?
2995 ",trans=lba" :
2996 translation == BIOS_ATA_TRANSLATION_NONE ?
2997 ",trans=none" : "");
2998 drive_add(IF_DEFAULT, 0, optarg, buf);
2999 break;
3000 }
bellardcd6f1162004-05-13 22:02:20 +00003001 case QEMU_OPTION_hdb:
bellardcc1daa42005-06-05 14:49:17 +00003002 case QEMU_OPTION_hdc:
3003 case QEMU_OPTION_hdd:
Markus Armbruster2292dda2011-01-28 11:21:41 +01003004 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
3005 HD_OPTS);
bellardfc01f7e2003-06-30 10:03:06 +00003006 break;
thse4bcb142007-12-02 04:51:10 +00003007 case QEMU_OPTION_drive:
Michael Tokareve2982c32011-03-30 16:31:05 +04003008 if (drive_def(optarg) == NULL) {
3009 exit(1);
3010 }
thse4bcb142007-12-02 04:51:10 +00003011 break;
Gerd Hoffmannd058fe02009-07-31 12:25:36 +02003012 case QEMU_OPTION_set:
3013 if (qemu_set_option(optarg) != 0)
3014 exit(1);
3015 break;
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01003016 case QEMU_OPTION_global:
3017 if (qemu_global_option(optarg) != 0)
3018 exit(1);
3019 break;
balrog3e3d5812007-04-30 02:09:25 +00003020 case QEMU_OPTION_mtdblock:
Markus Armbruster2292dda2011-01-28 11:21:41 +01003021 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
balrog3e3d5812007-04-30 02:09:25 +00003022 break;
pbrooka1bb27b2007-04-06 16:49:48 +00003023 case QEMU_OPTION_sd:
Peter Crosthwaite80f4d9f2013-02-28 18:23:14 +00003024 drive_add(IF_SD, -1, optarg, SD_OPTS);
pbrooka1bb27b2007-04-06 16:49:48 +00003025 break;
j_mayer86f55662007-04-24 06:52:59 +00003026 case QEMU_OPTION_pflash:
Markus Armbruster2292dda2011-01-28 11:21:41 +01003027 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
j_mayer86f55662007-04-24 06:52:59 +00003028 break;
bellardcd6f1162004-05-13 22:02:20 +00003029 case QEMU_OPTION_snapshot:
bellard33e39632003-07-06 17:15:21 +00003030 snapshot = 1;
3031 break;
bellardcd6f1162004-05-13 22:02:20 +00003032 case QEMU_OPTION_hdachs:
bellard330d0412003-07-26 18:11:40 +00003033 {
bellard330d0412003-07-26 18:11:40 +00003034 const char *p;
3035 p = optarg;
3036 cyls = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00003037 if (cyls < 1 || cyls > 16383)
3038 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00003039 if (*p != ',')
3040 goto chs_fail;
3041 p++;
3042 heads = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00003043 if (heads < 1 || heads > 16)
3044 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00003045 if (*p != ',')
3046 goto chs_fail;
3047 p++;
3048 secs = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00003049 if (secs < 1 || secs > 63)
3050 goto chs_fail;
3051 if (*p == ',') {
3052 p++;
3053 if (!strcmp(p, "none"))
3054 translation = BIOS_ATA_TRANSLATION_NONE;
3055 else if (!strcmp(p, "lba"))
3056 translation = BIOS_ATA_TRANSLATION_LBA;
3057 else if (!strcmp(p, "auto"))
3058 translation = BIOS_ATA_TRANSLATION_AUTO;
3059 else
3060 goto chs_fail;
3061 } else if (*p != '\0') {
bellardc4b1fcc2004-03-14 21:44:30 +00003062 chs_fail:
bellard46d47672004-11-16 01:45:27 +00003063 fprintf(stderr, "qemu: invalid physical CHS format\n");
3064 exit(1);
bellardc4b1fcc2004-03-14 21:44:30 +00003065 }
malc9f227bc2012-08-27 18:33:22 +04003066 if (hda_opts != NULL) {
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02003067 char num[16];
3068 snprintf(num, sizeof(num), "%d", cyls);
3069 qemu_opt_set(hda_opts, "cyls", num);
3070 snprintf(num, sizeof(num), "%d", heads);
3071 qemu_opt_set(hda_opts, "heads", num);
3072 snprintf(num, sizeof(num), "%d", secs);
3073 qemu_opt_set(hda_opts, "secs", num);
3074 if (translation == BIOS_ATA_TRANSLATION_LBA)
3075 qemu_opt_set(hda_opts, "trans", "lba");
3076 if (translation == BIOS_ATA_TRANSLATION_NONE)
3077 qemu_opt_set(hda_opts, "trans", "none");
3078 }
bellard330d0412003-07-26 18:11:40 +00003079 }
3080 break;
aliguori268a3622009-04-21 22:30:27 +00003081 case QEMU_OPTION_numa:
aliguori268a3622009-04-21 22:30:27 +00003082 numa_add(optarg);
3083 break;
Jes Sorensen1472a952011-03-16 13:33:31 +01003084 case QEMU_OPTION_display:
3085 display_type = select_display(optarg);
3086 break;
bellardcd6f1162004-05-13 22:02:20 +00003087 case QEMU_OPTION_nographic:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003088 display_type = DT_NOGRAPHIC;
bellarda20dd502003-09-30 21:07:02 +00003089 break;
balrog4d3b6f62008-02-10 16:33:14 +00003090 case QEMU_OPTION_curses:
Jes Sorensen47b05362011-03-16 13:33:35 +01003091#ifdef CONFIG_CURSES
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003092 display_type = DT_CURSES;
Jes Sorensen47b05362011-03-16 13:33:35 +01003093#else
3094 fprintf(stderr, "Curses support is disabled\n");
3095 exit(1);
balrog4d3b6f62008-02-10 16:33:14 +00003096#endif
Jes Sorensen47b05362011-03-16 13:33:35 +01003097 break;
balroga171fe32007-04-30 01:48:07 +00003098 case QEMU_OPTION_portrait:
Vasily Khoruzhick93128052011-06-17 13:04:36 +03003099 graphic_rotate = 90;
3100 break;
3101 case QEMU_OPTION_rotate:
3102 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
3103 if (graphic_rotate != 0 && graphic_rotate != 90 &&
3104 graphic_rotate != 180 && graphic_rotate != 270) {
3105 fprintf(stderr,
3106 "qemu: only 90, 180, 270 deg rotation is available\n");
3107 exit(1);
3108 }
balroga171fe32007-04-30 01:48:07 +00003109 break;
bellardcd6f1162004-05-13 22:02:20 +00003110 case QEMU_OPTION_kernel:
Peter Maydella0abe472012-02-08 05:41:39 +00003111 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg);
3112 break;
3113 case QEMU_OPTION_initrd:
3114 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg);
bellarda20dd502003-09-30 21:07:02 +00003115 break;
bellardcd6f1162004-05-13 22:02:20 +00003116 case QEMU_OPTION_append:
Peter Maydella0abe472012-02-08 05:41:39 +00003117 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg);
bellard313aa562003-08-10 21:52:11 +00003118 break;
Grant Likely412beee2012-03-02 11:56:38 +00003119 case QEMU_OPTION_dtb:
3120 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg);
3121 break;
bellardcd6f1162004-05-13 22:02:20 +00003122 case QEMU_OPTION_cdrom:
Markus Armbruster2292dda2011-01-28 11:21:41 +01003123 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
bellard36b486b2003-11-11 13:36:08 +00003124 break;
bellardcd6f1162004-05-13 22:02:20 +00003125 case QEMU_OPTION_boot:
Markus Armbruster8281abd2013-06-14 13:15:03 +02003126 opts = qemu_opts_parse(qemu_find_opts("boot-opts"), optarg, 1);
3127 if (!opts) {
3128 exit(1);
bellard36b486b2003-11-11 13:36:08 +00003129 }
3130 break;
bellardcd6f1162004-05-13 22:02:20 +00003131 case QEMU_OPTION_fda:
bellardcd6f1162004-05-13 22:02:20 +00003132 case QEMU_OPTION_fdb:
Markus Armbruster2292dda2011-01-28 11:21:41 +01003133 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
3134 optarg, FD_OPTS);
bellardc45886d2004-01-05 00:02:06 +00003135 break;
bellard52ca8d62006-06-14 16:03:05 +00003136 case QEMU_OPTION_no_fd_bootchk:
3137 fd_bootchk = 0;
3138 break;
Mark McLoughlina1ea4582009-10-08 19:58:26 +01003139 case QEMU_OPTION_netdev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003140 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
Mark McLoughlina1ea4582009-10-08 19:58:26 +01003141 exit(1);
3142 }
3143 break;
bellard7c9d8e02005-11-15 22:16:05 +00003144 case QEMU_OPTION_net:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003145 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
bellardc4b1fcc2004-03-14 21:44:30 +00003146 exit(1);
3147 }
bellard702c6512004-04-02 21:21:32 +00003148 break;
Ronnie Sahlbergf9dadc92012-01-26 09:39:02 +11003149#ifdef CONFIG_LIBISCSI
3150 case QEMU_OPTION_iscsi:
3151 opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0);
3152 if (!opts) {
3153 exit(1);
3154 }
3155 break;
3156#endif
bellardc7f74642004-08-24 21:57:12 +00003157#ifdef CONFIG_SLIRP
3158 case QEMU_OPTION_tftp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02003159 legacy_tftp_prefix = optarg;
bellard9bf05442004-08-25 22:12:49 +00003160 break;
ths47d5d012007-02-20 00:05:08 +00003161 case QEMU_OPTION_bootp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02003162 legacy_bootp_filename = optarg;
ths47d5d012007-02-20 00:05:08 +00003163 break;
bellard9bf05442004-08-25 22:12:49 +00003164 case QEMU_OPTION_redir:
Markus Armbruster07527062009-10-06 12:16:57 +01003165 if (net_slirp_redir(optarg) < 0)
3166 exit(1);
bellard9bf05442004-08-25 22:12:49 +00003167 break;
bellardc7f74642004-08-24 21:57:12 +00003168#endif
balrogdc72ac12008-11-09 00:04:26 +00003169 case QEMU_OPTION_bt:
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003170 add_device_config(DEV_BT, optarg);
balrogdc72ac12008-11-09 00:04:26 +00003171 break;
bellard1d14ffa2005-10-30 18:58:22 +00003172 case QEMU_OPTION_audio_help:
3173 AUD_help ();
3174 exit (0);
3175 break;
3176 case QEMU_OPTION_soundhw:
3177 select_soundhw (optarg);
3178 break;
bellardcd6f1162004-05-13 22:02:20 +00003179 case QEMU_OPTION_h:
ths15f82202007-06-29 23:26:08 +00003180 help(0);
bellardcd6f1162004-05-13 22:02:20 +00003181 break;
pbrook9bd7e6d2009-04-07 22:58:45 +00003182 case QEMU_OPTION_version:
3183 version();
3184 exit(0);
3185 break;
aurel3200f82b82008-04-27 21:12:55 +00003186 case QEMU_OPTION_m: {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +01003187 int64_t value;
Markus Armbrusterff961012012-08-15 13:12:19 +02003188 uint64_t sz;
Markus Armbruster961b42b2011-11-22 09:46:03 +01003189 char *end;
aurel3200f82b82008-04-27 21:12:55 +00003190
Markus Armbruster961b42b2011-11-22 09:46:03 +01003191 value = strtosz(optarg, &end);
3192 if (value < 0 || *end) {
aurel3200f82b82008-04-27 21:12:55 +00003193 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
bellardcd6f1162004-05-13 22:02:20 +00003194 exit(1);
3195 }
Markus Armbrusterff961012012-08-15 13:12:19 +02003196 sz = QEMU_ALIGN_UP((uint64_t)value, 8192);
3197 ram_size = sz;
3198 if (ram_size != sz) {
aurel3200f82b82008-04-27 21:12:55 +00003199 fprintf(stderr, "qemu: ram size too large\n");
3200 exit(1);
3201 }
bellardcd6f1162004-05-13 22:02:20 +00003202 break;
aurel3200f82b82008-04-27 21:12:55 +00003203 }
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05003204#ifdef CONFIG_TPM
3205 case QEMU_OPTION_tpmdev:
3206 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
3207 exit(1);
3208 }
3209 break;
3210#endif
Marcelo Tosattic9027602010-03-01 20:25:08 -03003211 case QEMU_OPTION_mempath:
3212 mem_path = optarg;
3213 break;
Marcelo Tosattic9027602010-03-01 20:25:08 -03003214 case QEMU_OPTION_mem_prealloc:
3215 mem_prealloc = 1;
3216 break;
bellardcd6f1162004-05-13 22:02:20 +00003217 case QEMU_OPTION_d:
Matthew Fernandezc235d732011-06-07 16:32:40 +00003218 log_mask = optarg;
3219 break;
3220 case QEMU_OPTION_D:
3221 log_file = optarg;
bellardcd6f1162004-05-13 22:02:20 +00003222 break;
bellardcd6f1162004-05-13 22:02:20 +00003223 case QEMU_OPTION_s:
Markus Armbrusteref0c4a02012-02-07 15:09:13 +01003224 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
bellardcd6f1162004-05-13 22:02:20 +00003225 break;
aliguori59030a82009-04-05 18:43:41 +00003226 case QEMU_OPTION_gdb:
Markus Armbrusteref0c4a02012-02-07 15:09:13 +01003227 add_device_config(DEV_GDB, optarg);
bellardcd6f1162004-05-13 22:02:20 +00003228 break;
bellardcd6f1162004-05-13 22:02:20 +00003229 case QEMU_OPTION_L:
Gerd Hoffmann45240512013-03-08 11:42:24 +01003230 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
3231 data_dir[data_dir_idx++] = optarg;
3232 }
bellardcd6f1162004-05-13 22:02:20 +00003233 break;
j_mayer1192dad2007-10-05 13:08:35 +00003234 case QEMU_OPTION_bios:
Gerd Hoffmann1442d3e2013-10-15 16:57:45 +02003235 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg);
j_mayer1192dad2007-10-05 13:08:35 +00003236 break;
aurel321b530a62009-04-05 20:08:59 +00003237 case QEMU_OPTION_singlestep:
3238 singlestep = 1;
3239 break;
bellardcd6f1162004-05-13 22:02:20 +00003240 case QEMU_OPTION_S:
pbrook3c07f8e2007-01-21 16:47:01 +00003241 autostart = 0;
bellardcd6f1162004-05-13 22:02:20 +00003242 break;
bellard3d11d0e2004-12-12 16:56:30 +00003243 case QEMU_OPTION_k:
3244 keyboard_layout = optarg;
3245 break;
bellardee22c2f2004-06-03 12:49:50 +00003246 case QEMU_OPTION_localtime:
3247 rtc_utc = 0;
3248 break;
malc3893c122008-09-28 00:42:05 +00003249 case QEMU_OPTION_vga:
Blue Swirla369da52011-09-27 19:15:42 +00003250 vga_model = optarg;
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +02003251 default_vga = 0;
bellard1bfe8562004-07-08 21:17:50 +00003252 break;
bellarde9b137c2004-06-21 16:46:10 +00003253 case QEMU_OPTION_g:
3254 {
3255 const char *p;
3256 int w, h, depth;
3257 p = optarg;
3258 w = strtol(p, (char **)&p, 10);
3259 if (w <= 0) {
3260 graphic_error:
3261 fprintf(stderr, "qemu: invalid resolution or depth\n");
3262 exit(1);
3263 }
3264 if (*p != 'x')
3265 goto graphic_error;
3266 p++;
3267 h = strtol(p, (char **)&p, 10);
3268 if (h <= 0)
3269 goto graphic_error;
3270 if (*p == 'x') {
3271 p++;
3272 depth = strtol(p, (char **)&p, 10);
ths5fafdf22007-09-16 21:08:06 +00003273 if (depth != 8 && depth != 15 && depth != 16 &&
bellarde9b137c2004-06-21 16:46:10 +00003274 depth != 24 && depth != 32)
3275 goto graphic_error;
3276 } else if (*p == '\0') {
3277 depth = graphic_depth;
3278 } else {
3279 goto graphic_error;
3280 }
ths3b46e622007-09-17 08:09:54 +00003281
bellarde9b137c2004-06-21 16:46:10 +00003282 graphic_width = w;
3283 graphic_height = h;
3284 graphic_depth = depth;
3285 }
3286 break;
ths20d8a3e2007-02-18 17:04:49 +00003287 case QEMU_OPTION_echr:
3288 {
3289 char *r;
3290 term_escape_char = strtol(optarg, &r, 0);
3291 if (r == optarg)
3292 printf("Bad argument to echr\n");
3293 break;
3294 }
bellard82c643f2004-07-14 17:28:13 +00003295 case QEMU_OPTION_monitor:
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01003296 default_monitor = 0;
Luiz Capitulino70e098a2013-05-16 12:02:55 -04003297 if (strncmp(optarg, "none", 4)) {
3298 monitor_parse(optarg, "readline");
3299 }
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01003300 break;
3301 case QEMU_OPTION_qmp:
3302 monitor_parse(optarg, "control");
Anthony Liguori2d114dc2010-03-21 14:14:38 -05003303 default_monitor = 0;
bellard82c643f2004-07-14 17:28:13 +00003304 break;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01003305 case QEMU_OPTION_mon:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003306 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01003307 if (!opts) {
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01003308 exit(1);
3309 }
Anthony Liguori2d114dc2010-03-21 14:14:38 -05003310 default_monitor = 0;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01003311 break;
Gerd Hoffmann191bc012009-09-10 10:58:35 +02003312 case QEMU_OPTION_chardev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003313 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
Gerd Hoffmann191bc012009-09-10 10:58:35 +02003314 if (!opts) {
Gerd Hoffmann191bc012009-09-10 10:58:35 +02003315 exit(1);
3316 }
Gerd Hoffmann191bc012009-09-10 10:58:35 +02003317 break;
Gautham R Shenoy74db9202010-04-29 17:44:43 +05303318 case QEMU_OPTION_fsdev:
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02003319 olist = qemu_find_opts("fsdev");
3320 if (!olist) {
3321 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
3322 exit(1);
3323 }
3324 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy74db9202010-04-29 17:44:43 +05303325 if (!opts) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +05303326 exit(1);
3327 }
3328 break;
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303329 case QEMU_OPTION_virtfs: {
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00003330 QemuOpts *fsdev;
3331 QemuOpts *device;
M. Mohan Kumar84a87cc2011-12-14 13:58:47 +05303332 const char *writeout, *sock_fd, *socket;
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303333
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02003334 olist = qemu_find_opts("virtfs");
3335 if (!olist) {
3336 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
3337 exit(1);
3338 }
3339 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303340 if (!opts) {
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303341 exit(1);
3342 }
3343
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +05303344 if (qemu_opt_get(opts, "fsdriver") == NULL ||
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +05303345 qemu_opt_get(opts, "mount_tag") == NULL) {
3346 fprintf(stderr, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07003347 exit(1);
3348 }
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00003349 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03003350 qemu_opt_get(opts, "mount_tag"),
3351 1, NULL);
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00003352 if (!fsdev) {
3353 fprintf(stderr, "duplicate fsdev id: %s\n",
3354 qemu_opt_get(opts, "mount_tag"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303355 exit(1);
3356 }
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +05303357
3358 writeout = qemu_opt_get(opts, "writeout");
3359 if (writeout) {
3360#ifdef CONFIG_SYNC_FILE_RANGE
3361 qemu_opt_set(fsdev, "writeout", writeout);
3362#else
3363 fprintf(stderr, "writeout=immediate not supported on "
3364 "this platform\n");
3365 exit(1);
3366#endif
3367 }
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +05303368 qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver"));
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00003369 qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"));
3370 qemu_opt_set(fsdev, "security_model",
3371 qemu_opt_get(opts, "security_model"));
M. Mohan Kumar84a87cc2011-12-14 13:58:47 +05303372 socket = qemu_opt_get(opts, "socket");
3373 if (socket) {
3374 qemu_opt_set(fsdev, "socket", socket);
3375 }
M. Mohan Kumar4c793dd2011-12-14 13:49:28 +05303376 sock_fd = qemu_opt_get(opts, "sock_fd");
3377 if (sock_fd) {
3378 qemu_opt_set(fsdev, "sock_fd", sock_fd);
3379 }
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303380
M. Mohan Kumar2c74c2c2011-10-25 12:10:39 +05303381 qemu_opt_set_bool(fsdev, "readonly",
3382 qemu_opt_get_bool(opts, "readonly", 0));
Dong Xu Wange478b442012-12-06 14:47:22 +08003383 device = qemu_opts_create_nofail(qemu_find_opts("device"));
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00003384 qemu_opt_set(device, "driver", "virtio-9p-pci");
3385 qemu_opt_set(device, "fsdev",
3386 qemu_opt_get(opts, "mount_tag"));
3387 qemu_opt_set(device, "mount_tag",
3388 qemu_opt_get(opts, "mount_tag"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303389 break;
3390 }
Aneesh Kumar K.V9db221a2011-10-25 12:10:40 +05303391 case QEMU_OPTION_virtfs_synth: {
3392 QemuOpts *fsdev;
3393 QemuOpts *device;
3394
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03003395 fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3396 1, NULL);
Aneesh Kumar K.V9db221a2011-10-25 12:10:40 +05303397 if (!fsdev) {
3398 fprintf(stderr, "duplicate option: %s\n", "virtfs_synth");
3399 exit(1);
3400 }
3401 qemu_opt_set(fsdev, "fsdriver", "synth");
Aneesh Kumar K.V9db221a2011-10-25 12:10:40 +05303402
Dong Xu Wange478b442012-12-06 14:47:22 +08003403 device = qemu_opts_create_nofail(qemu_find_opts("device"));
Aneesh Kumar K.V9db221a2011-10-25 12:10:40 +05303404 qemu_opt_set(device, "driver", "virtio-9p-pci");
3405 qemu_opt_set(device, "fsdev", "v_synth");
3406 qemu_opt_set(device, "mount_tag", "v_synth");
3407 break;
3408 }
bellard82c643f2004-07-14 17:28:13 +00003409 case QEMU_OPTION_serial:
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01003410 add_device_config(DEV_SERIAL, optarg);
3411 default_serial = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01003412 if (strncmp(optarg, "mon:", 4) == 0) {
3413 default_monitor = 0;
3414 }
bellard82c643f2004-07-14 17:28:13 +00003415 break;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01003416 case QEMU_OPTION_watchdog:
Markus Armbruster09aaa162009-08-21 10:31:34 +02003417 if (watchdog) {
3418 fprintf(stderr,
3419 "qemu: only one watchdog option may be given\n");
3420 return 1;
3421 }
3422 watchdog = optarg;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01003423 break;
3424 case QEMU_OPTION_watchdog_action:
3425 if (select_watchdog_action(optarg) == -1) {
3426 fprintf(stderr, "Unknown -watchdog-action parameter\n");
3427 exit(1);
3428 }
3429 break;
aliguori51ecf132009-01-15 20:06:40 +00003430 case QEMU_OPTION_virtiocon:
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01003431 add_device_config(DEV_VIRTCON, optarg);
3432 default_virtcon = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01003433 if (strncmp(optarg, "mon:", 4) == 0) {
3434 default_monitor = 0;
3435 }
aliguori51ecf132009-01-15 20:06:40 +00003436 break;
bellard6508fe52005-01-15 12:02:56 +00003437 case QEMU_OPTION_parallel:
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01003438 add_device_config(DEV_PARALLEL, optarg);
3439 default_parallel = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01003440 if (strncmp(optarg, "mon:", 4) == 0) {
3441 default_monitor = 0;
3442 }
bellard6508fe52005-01-15 12:02:56 +00003443 break;
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08003444 case QEMU_OPTION_debugcon:
3445 add_device_config(DEV_DEBUGCON, optarg);
3446 break;
bellardd63d3072004-10-03 13:29:03 +00003447 case QEMU_OPTION_loadvm:
3448 loadvm = optarg;
3449 break;
3450 case QEMU_OPTION_full_screen:
3451 full_screen = 1;
3452 break;
ths43523e92007-02-18 18:19:32 +00003453 case QEMU_OPTION_no_frame:
3454 no_frame = 1;
3455 break;
ths3780e192007-06-21 21:08:02 +00003456 case QEMU_OPTION_alt_grab:
3457 alt_grab = 1;
3458 break;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -05003459 case QEMU_OPTION_ctrl_grab:
3460 ctrl_grab = 1;
3461 break;
ths667acca2006-12-11 02:08:05 +00003462 case QEMU_OPTION_no_quit:
3463 no_quit = 1;
3464 break;
aliguori7d957bd2009-01-15 22:14:11 +00003465 case QEMU_OPTION_sdl:
Michael Tokarev24f6ff82013-06-15 14:44:20 +04003466#ifdef CONFIG_SDL
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003467 display_type = DT_SDL;
aliguori7d957bd2009-01-15 22:14:11 +00003468 break;
Jes Sorensen58fc0962011-03-16 13:33:34 +01003469#else
Jes Sorensen58fc0962011-03-16 13:33:34 +01003470 fprintf(stderr, "SDL support is disabled\n");
3471 exit(1);
ths667acca2006-12-11 02:08:05 +00003472#endif
bellardf7cce892004-12-08 22:21:25 +00003473 case QEMU_OPTION_pidfile:
ths93815bc2007-03-19 15:58:31 +00003474 pid_file = optarg;
bellardf7cce892004-12-08 22:21:25 +00003475 break;
bellarda09db212005-04-30 16:10:35 +00003476 case QEMU_OPTION_win2k_hack:
3477 win2k_install_hack = 1;
3478 break;
Jan Kiszka433acf02012-01-23 20:15:12 +01003479 case QEMU_OPTION_rtc_td_hack: {
3480 static GlobalProperty slew_lost_ticks[] = {
3481 {
3482 .driver = "mc146818rtc",
3483 .property = "lost_tick_policy",
3484 .value = "slew",
3485 },
3486 { /* end of list */ }
3487 };
3488
3489 qdev_prop_register_global_list(slew_lost_ticks);
aliguori73822ec2009-01-15 20:11:34 +00003490 break;
Jan Kiszka433acf02012-01-23 20:15:12 +01003491 }
aliguori8a92ea22009-02-27 20:12:36 +00003492 case QEMU_OPTION_acpitable:
Laszlo Ersek0c764a92013-03-21 00:23:17 +01003493 opts = qemu_opts_parse(qemu_find_opts("acpi"), optarg, 1);
Laszlo Ersekf46e7202013-11-28 18:12:59 +01003494 if (!opts) {
3495 exit(1);
3496 }
Laszlo Ersek0c764a92013-03-21 00:23:17 +01003497 do_acpitable_option(opts);
aliguori8a92ea22009-02-27 20:12:36 +00003498 break;
aliguorib6f6e3d2009-04-17 18:59:56 +00003499 case QEMU_OPTION_smbios:
Markus Armbruster4f953d22013-08-16 15:18:29 +02003500 opts = qemu_opts_parse(qemu_find_opts("smbios"), optarg, 0);
Laszlo Ersekf46e7202013-11-28 18:12:59 +01003501 if (!opts) {
3502 exit(1);
3503 }
Markus Armbruster4f953d22013-08-16 15:18:29 +02003504 do_smbios_option(opts);
aliguorib6f6e3d2009-04-17 18:59:56 +00003505 break;
aliguori7ba1e612008-11-05 16:04:33 +00003506 case QEMU_OPTION_enable_kvm:
Anthony PERARD303d4e82010-09-21 20:05:31 +01003507 olist = qemu_find_opts("machine");
Anthony PERARD303d4e82010-09-21 20:05:31 +01003508 qemu_opts_parse(olist, "accel=kvm", 0);
3509 break;
3510 case QEMU_OPTION_machine:
3511 olist = qemu_find_opts("machine");
Jan Kiszka9052ea62011-07-23 12:38:37 +02003512 opts = qemu_opts_parse(olist, optarg, 1);
Anthony PERARD303d4e82010-09-21 20:05:31 +01003513 if (!opts) {
Anthony PERARD303d4e82010-09-21 20:05:31 +01003514 exit(1);
3515 }
Jan Kiszka2645c6d2011-07-25 18:11:20 +02003516 optarg = qemu_opt_get(opts, "type");
3517 if (optarg) {
3518 machine = machine_parse(optarg);
3519 }
aliguori7ba1e612008-11-05 16:04:33 +00003520 break;
Jan Kiszkaa0dac022012-10-05 14:51:45 -03003521 case QEMU_OPTION_no_kvm:
3522 olist = qemu_find_opts("machine");
3523 qemu_opts_parse(olist, "accel=tcg", 0);
3524 break;
Jan Kiszka4086bde2012-10-05 14:51:41 -03003525 case QEMU_OPTION_no_kvm_pit: {
3526 fprintf(stderr, "Warning: KVM PIT can no longer be disabled "
3527 "separately.\n");
3528 break;
3529 }
Jan Kiszkac21fb4f2012-10-05 14:51:42 -03003530 case QEMU_OPTION_no_kvm_pit_reinjection: {
3531 static GlobalProperty kvm_pit_lost_tick_policy[] = {
3532 {
3533 .driver = "kvm-pit",
3534 .property = "lost_tick_policy",
3535 .value = "discard",
3536 },
3537 { /* end of list */ }
3538 };
3539
3540 fprintf(stderr, "Warning: option deprecated, use "
3541 "lost_tick_policy property of kvm-pit instead.\n");
3542 qdev_prop_register_global_list(kvm_pit_lost_tick_policy);
3543 break;
3544 }
bellardbb36d472005-11-05 14:22:28 +00003545 case QEMU_OPTION_usb:
Peter Maydellfa5358c2012-11-22 16:48:45 +00003546 olist = qemu_find_opts("machine");
3547 qemu_opts_parse(olist, "usb=on", 0);
bellardbb36d472005-11-05 14:22:28 +00003548 break;
bellarda594cfb2005-11-06 16:13:29 +00003549 case QEMU_OPTION_usbdevice:
Peter Maydellfa5358c2012-11-22 16:48:45 +00003550 olist = qemu_find_opts("machine");
3551 qemu_opts_parse(olist, "usb=on", 0);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003552 add_device_config(DEV_USB, optarg);
3553 break;
3554 case QEMU_OPTION_device:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003555 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02003556 exit(1);
3557 }
bellarda594cfb2005-11-06 16:13:29 +00003558 break;
bellard6a00d602005-11-21 23:25:50 +00003559 case QEMU_OPTION_smp:
Michael Tokarev12b7f572013-06-24 15:06:52 +04003560 if (!qemu_opts_parse(qemu_find_opts("smp-opts"), optarg, 1)) {
Jes Sorensen6be68d72009-07-23 17:03:42 +02003561 exit(1);
3562 }
bellard6a00d602005-11-21 23:25:50 +00003563 break;
bellard24236862006-04-30 21:28:36 +00003564 case QEMU_OPTION_vnc:
Jes Sorensen821601e2011-03-16 13:33:36 +01003565#ifdef CONFIG_VNC
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003566 display_remote++;
Jes Sorensen821601e2011-03-16 13:33:36 +01003567 vnc_display = optarg;
3568#else
3569 fprintf(stderr, "VNC support is disabled\n");
3570 exit(1);
3571#endif
3572 break;
bellard6515b202006-05-03 22:02:44 +00003573 case QEMU_OPTION_no_acpi:
3574 acpi_enabled = 0;
3575 break;
aliguori16b29ae2008-12-17 23:28:44 +00003576 case QEMU_OPTION_no_hpet:
3577 no_hpet = 1;
3578 break;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02003579 case QEMU_OPTION_balloon:
3580 if (balloon_parse(optarg) < 0) {
3581 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
3582 exit(1);
3583 }
Eduardo Habkostdf97b922009-06-10 16:34:08 -03003584 break;
bellardd1beab82006-10-02 19:44:22 +00003585 case QEMU_OPTION_no_reboot:
3586 no_reboot = 1;
3587 break;
aurel32b2f76162008-04-11 21:35:52 +00003588 case QEMU_OPTION_no_shutdown:
3589 no_shutdown = 1;
3590 break;
balrog9467cd42007-05-01 01:34:14 +00003591 case QEMU_OPTION_show_cursor:
3592 cursor_hide = 0;
3593 break;
blueswir18fcb1b92008-09-18 18:29:08 +00003594 case QEMU_OPTION_uuid:
3595 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
3596 fprintf(stderr, "Fail to parse UUID string."
3597 " Wrong format.\n");
3598 exit(1);
3599 }
Markus Armbrusterfc3b3292013-08-16 15:18:31 +02003600 qemu_uuid_set = true;
blueswir18fcb1b92008-09-18 18:29:08 +00003601 break;
ths9ae02552007-01-05 17:39:04 +00003602 case QEMU_OPTION_option_rom:
3603 if (nb_option_roms >= MAX_OPTION_ROMS) {
3604 fprintf(stderr, "Too many option ROMs\n");
3605 exit(1);
3606 }
Gleb Natapov2e55e842010-12-08 13:35:07 +02003607 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
Markus Armbruster49295eb2013-02-08 21:22:19 +01003608 if (!opts) {
3609 exit(1);
3610 }
Gleb Natapov2e55e842010-12-08 13:35:07 +02003611 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
3612 option_rom[nb_option_roms].bootindex =
3613 qemu_opt_get_number(opts, "bootindex", -1);
3614 if (!option_rom[nb_option_roms].name) {
3615 fprintf(stderr, "Option ROM file is not specified\n");
3616 exit(1);
3617 }
ths9ae02552007-01-05 17:39:04 +00003618 nb_option_roms++;
3619 break;
pbrook8e716212007-01-20 17:12:09 +00003620 case QEMU_OPTION_semihosting:
3621 semihosting_enabled = 1;
3622 break;
Jan Kiszka88eed342012-10-05 14:51:44 -03003623 case QEMU_OPTION_tdf:
3624 fprintf(stderr, "Warning: user space PIT time drift fix "
3625 "is no longer supported.\n");
3626 break;
thsc35734b2007-03-19 15:17:08 +00003627 case QEMU_OPTION_name:
Anthony Liguori7267c092011-08-20 22:09:37 -05003628 qemu_name = g_strdup(optarg);
Andi Kleen18894652009-07-02 09:34:17 +02003629 {
3630 char *p = strchr(qemu_name, ',');
3631 if (p != NULL) {
3632 *p++ = 0;
3633 if (strncmp(p, "process=", 8)) {
Aurelien Jarno5697f6a2010-12-27 18:29:20 +01003634 fprintf(stderr, "Unknown subargument %s to -name\n", p);
Andi Kleen18894652009-07-02 09:34:17 +02003635 exit(1);
3636 }
3637 p += 8;
Jes Sorensence798cf2010-06-10 11:42:31 +02003638 os_set_proc_name(p);
Laszlo Ersek4d8b3c62013-03-21 00:23:13 +01003639 }
3640 }
thsc35734b2007-03-19 15:17:08 +00003641 break;
blueswir166508602007-05-01 14:16:52 +00003642 case QEMU_OPTION_prom_env:
3643 if (nb_prom_envs >= MAX_PROM_ENVS) {
3644 fprintf(stderr, "Too many prom variables\n");
3645 exit(1);
3646 }
3647 prom_envs[nb_prom_envs] = optarg;
3648 nb_prom_envs++;
3649 break;
balrog2b8f2d42007-07-27 22:08:46 +00003650 case QEMU_OPTION_old_param:
3651 old_param = 1;
ths05ebd532008-01-08 19:32:16 +00003652 break;
thsf3dcfad2007-08-24 01:26:02 +00003653 case QEMU_OPTION_clock:
Alex Bligh6d327172013-08-21 16:02:59 +01003654 /* Clock options no longer exist. Keep this option for
3655 * backward compatibility.
3656 */
thsf3dcfad2007-08-24 01:26:02 +00003657 break;
bellard7e0af5d02007-11-07 16:24:33 +00003658 case QEMU_OPTION_startdate:
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02003659 configure_rtc_date_offset(optarg, 1);
3660 break;
3661 case QEMU_OPTION_rtc:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003662 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02003663 if (!opts) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02003664 exit(1);
bellard7e0af5d02007-11-07 16:24:33 +00003665 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02003666 configure_rtc(opts);
bellard7e0af5d02007-11-07 16:24:33 +00003667 break;
bellard26a5f132008-05-28 12:30:31 +00003668 case QEMU_OPTION_tb_size:
Jan Kiszkad5ab9712011-08-02 16:10:21 +02003669 tcg_tb_size = strtol(optarg, NULL, 0);
3670 if (tcg_tb_size < 0) {
3671 tcg_tb_size = 0;
3672 }
bellard26a5f132008-05-28 12:30:31 +00003673 break;
pbrook2e70f6e2008-06-29 01:03:05 +00003674 case QEMU_OPTION_icount:
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01003675 icount_option = optarg;
pbrook2e70f6e2008-06-29 01:03:05 +00003676 break;
aliguori5bb79102008-10-13 03:12:02 +00003677 case QEMU_OPTION_incoming:
3678 incoming = optarg;
Stefano Stabellini81323a62012-01-18 12:23:13 +00003679 runstate_set(RUN_STATE_INMIGRATE);
aliguori5bb79102008-10-13 03:12:02 +00003680 break;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01003681 case QEMU_OPTION_nodefaults:
3682 default_serial = 0;
3683 default_parallel = 0;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01003684 default_virtcon = 0;
Christian Borntraeger2e788492013-01-25 06:00:19 +00003685 default_sclp = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01003686 default_monitor = 0;
Gerd Hoffmanncb4522c2009-12-08 13:11:47 +01003687 default_net = 0;
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01003688 default_floppy = 0;
3689 default_cdrom = 0;
3690 default_sdcard = 0;
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +02003691 default_vga = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01003692 break;
aliguorie37630c2009-04-22 15:19:10 +00003693 case QEMU_OPTION_xen_domid:
Blue Swirlad960902010-03-29 19:23:52 +00003694 if (!(xen_available())) {
3695 printf("Option %s not supported for this target\n", popt->name);
3696 exit(1);
3697 }
aliguorie37630c2009-04-22 15:19:10 +00003698 xen_domid = atoi(optarg);
3699 break;
3700 case QEMU_OPTION_xen_create:
Blue Swirlad960902010-03-29 19:23:52 +00003701 if (!(xen_available())) {
3702 printf("Option %s not supported for this target\n", popt->name);
3703 exit(1);
3704 }
aliguorie37630c2009-04-22 15:19:10 +00003705 xen_mode = XEN_CREATE;
3706 break;
3707 case QEMU_OPTION_xen_attach:
Blue Swirlad960902010-03-29 19:23:52 +00003708 if (!(xen_available())) {
3709 printf("Option %s not supported for this target\n", popt->name);
3710 exit(1);
3711 }
aliguorie37630c2009-04-22 15:19:10 +00003712 xen_mode = XEN_ATTACH;
3713 break;
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003714 case QEMU_OPTION_trace:
Lluíse4858972011-08-31 20:31:03 +02003715 {
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003716 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
Lluíse4858972011-08-31 20:31:03 +02003717 if (!opts) {
3718 exit(1);
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003719 }
Lluís23d15e82011-08-31 20:31:31 +02003720 trace_events = qemu_opt_get(opts, "events");
Lluíse4858972011-08-31 20:31:03 +02003721 trace_file = qemu_opt_get(opts, "file");
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003722 break;
Lluíse4858972011-08-31 20:31:03 +02003723 }
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003724 case QEMU_OPTION_readconfig:
3725 {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01003726 int ret = qemu_read_config_file(optarg);
3727 if (ret < 0) {
3728 fprintf(stderr, "read config %s: %s\n", optarg,
3729 strerror(-ret));
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003730 exit(1);
3731 }
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003732 break;
3733 }
Gerd Hoffmann29b00402010-03-11 11:13:27 -03003734 case QEMU_OPTION_spice:
3735 olist = qemu_find_opts("spice");
3736 if (!olist) {
3737 fprintf(stderr, "spice is not supported by this qemu build.\n");
3738 exit(1);
3739 }
3740 opts = qemu_opts_parse(olist, optarg, 0);
3741 if (!opts) {
Gerd Hoffmann29b00402010-03-11 11:13:27 -03003742 exit(1);
3743 }
Gerd Hoffmannf963e4d2013-02-25 16:02:30 +01003744 display_remote++;
Gerd Hoffmann29b00402010-03-11 11:13:27 -03003745 break;
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003746 case QEMU_OPTION_writeconfig:
3747 {
3748 FILE *fp;
3749 if (strcmp(optarg, "-") == 0) {
3750 fp = stdout;
3751 } else {
3752 fp = fopen(optarg, "w");
3753 if (fp == NULL) {
3754 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
3755 exit(1);
3756 }
3757 }
3758 qemu_config_write(fp);
3759 fclose(fp);
3760 break;
3761 }
Anthony Liguoric7f0f3b2012-03-28 15:42:02 +02003762 case QEMU_OPTION_qtest:
3763 qtest_chrdev = optarg;
3764 break;
3765 case QEMU_OPTION_qtest_log:
3766 qtest_log = optarg;
3767 break;
Eduardo Otubo7d76ad42012-08-14 18:44:08 -03003768 case QEMU_OPTION_sandbox:
3769 opts = qemu_opts_parse(qemu_find_opts("sandbox"), optarg, 1);
3770 if (!opts) {
Markus Armbruster49295eb2013-02-08 21:22:19 +01003771 exit(1);
Eduardo Otubo7d76ad42012-08-14 18:44:08 -03003772 }
3773 break;
Corey Bryant587ed6b2012-10-18 15:19:34 -04003774 case QEMU_OPTION_add_fd:
3775#ifndef _WIN32
3776 opts = qemu_opts_parse(qemu_find_opts("add-fd"), optarg, 0);
3777 if (!opts) {
Markus Armbruster49295eb2013-02-08 21:22:19 +01003778 exit(1);
Corey Bryant587ed6b2012-10-18 15:19:34 -04003779 }
3780#else
3781 error_report("File descriptor passing is disabled on this "
3782 "platform");
3783 exit(1);
3784#endif
3785 break;
Anthony Liguori68d98d32012-06-25 14:36:33 -05003786 case QEMU_OPTION_object:
3787 opts = qemu_opts_parse(qemu_find_opts("object"), optarg, 1);
Markus Armbruster49295eb2013-02-08 21:22:19 +01003788 if (!opts) {
3789 exit(1);
3790 }
Anthony Liguori68d98d32012-06-25 14:36:33 -05003791 break;
Satoru Moriya888a6bc2013-04-19 16:42:06 +02003792 case QEMU_OPTION_realtime:
3793 opts = qemu_opts_parse(qemu_find_opts("realtime"), optarg, 0);
3794 if (!opts) {
3795 exit(1);
3796 }
3797 configure_realtime(opts);
3798 break;
Seiji Aguchi5e2ac512013-07-03 23:02:46 -04003799 case QEMU_OPTION_msg:
3800 opts = qemu_opts_parse(qemu_find_opts("msg"), optarg, 0);
3801 if (!opts) {
3802 exit(1);
3803 }
3804 configure_msg(opts);
3805 break;
Jes Sorensen59a52642010-06-10 11:42:25 +02003806 default:
3807 os_parse_cmd_args(popt->index, optarg);
bellardcd6f1162004-05-13 22:02:20 +00003808 }
bellard0824d6f2003-06-24 13:42:40 +00003809 }
3810 }
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01003811 loc_set_none();
bellard330d0412003-07-26 18:11:40 +00003812
Paolo Bonzini1c537862012-10-30 00:17:12 +01003813 if (qemu_init_main_loop()) {
3814 fprintf(stderr, "qemu_init_main_loop failed\n");
3815 exit(1);
3816 }
3817
Eduardo Otubo7d76ad42012-08-14 18:44:08 -03003818 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 0)) {
3819 exit(1);
3820 }
3821
Corey Bryant587ed6b2012-10-18 15:19:34 -04003822#ifndef _WIN32
3823 if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL, 1)) {
3824 exit(1);
3825 }
3826
3827 if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd, NULL, 1)) {
3828 exit(1);
3829 }
3830#endif
3831
Dunrong Huangfb7c2692012-07-24 00:42:20 +08003832 if (machine == NULL) {
3833 fprintf(stderr, "No machine found.\n");
3834 exit(1);
3835 }
3836
Crístian Viana93bfef42012-05-30 00:35:51 -03003837 if (machine->hw_version) {
3838 qemu_set_version(machine->hw_version);
3839 }
3840
Anthony Liguori68d98d32012-06-25 14:36:33 -05003841 if (qemu_opts_foreach(qemu_find_opts("object"),
3842 object_create, NULL, 0) != 0) {
3843 exit(1);
3844 }
3845
Eduardo Habkostecf40be2012-03-09 16:19:07 -03003846 /* Init CPU def lists, based on config
3847 * - Must be called after all the qemu_read_config_file() calls
3848 * - Must be called before list_cpus()
3849 * - Must be called before machine->init()
3850 */
3851 cpudef_init();
3852
Peter Maydellc8057f92012-08-02 13:45:54 +01003853 if (cpu_model && is_help_option(cpu_model)) {
Eduardo Habkost1d6528a2012-03-21 09:33:40 -03003854 list_cpus(stdout, &fprintf, cpu_model);
Eduardo Habkostecf40be2012-03-09 16:19:07 -03003855 exit(0);
3856 }
3857
Matthew Fernandezc235d732011-06-07 16:32:40 +00003858 /* Open the logfile at this point, if necessary. We can't open the logfile
3859 * when encountering either of the logging options (-d or -D) because the
3860 * other one may be encountered later on the command line, changing the
3861 * location or level of logging.
3862 */
3863 if (log_mask) {
Peter Maydellb946bff2013-02-11 16:41:24 +00003864 int mask;
Matthew Fernandezc235d732011-06-07 16:32:40 +00003865 if (log_file) {
Peter Maydell9a7e5422013-02-11 16:41:20 +00003866 qemu_set_log_filename(log_file);
Matthew Fernandezc235d732011-06-07 16:32:40 +00003867 }
Peter Maydellb946bff2013-02-11 16:41:24 +00003868
3869 mask = qemu_str_to_log_mask(log_mask);
3870 if (!mask) {
3871 qemu_print_log_usage(stdout);
3872 exit(1);
3873 }
3874 qemu_set_log(mask);
Matthew Fernandezc235d732011-06-07 16:32:40 +00003875 }
3876
Lluís23d15e82011-08-31 20:31:31 +02003877 if (!trace_backend_init(trace_events, trace_file)) {
Lluíse4858972011-08-31 20:31:03 +02003878 exit(1);
Stefan Hajnoczi31d3c9b2011-03-13 20:14:30 +00003879 }
Stefan Hajnoczi0b5538c2011-02-26 18:38:39 +00003880
Paul Brook5cea8592009-05-30 00:52:44 +01003881 /* If no data_dir is specified then try to find it relative to the
3882 executable path. */
Gerd Hoffmann45240512013-03-08 11:42:24 +01003883 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
3884 data_dir[data_dir_idx] = os_find_datadir(argv[0]);
3885 if (data_dir[data_dir_idx] != NULL) {
3886 data_dir_idx++;
3887 }
Paul Brook5cea8592009-05-30 00:52:44 +01003888 }
Stefan Weil60474fb2011-09-04 15:17:46 +02003889 /* If all else fails use the install path specified when building. */
Gerd Hoffmann45240512013-03-08 11:42:24 +01003890 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
3891 data_dir[data_dir_idx++] = CONFIG_QEMU_DATADIR;
Paul Brook5cea8592009-05-30 00:52:44 +01003892 }
3893
Michael Tokarev12b7f572013-06-24 15:06:52 +04003894 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
Jes Sorensen6be68d72009-07-23 17:03:42 +02003895
balrog3d878ca2008-10-28 10:59:59 +00003896 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
aliguorib2097002008-10-07 20:39:39 +00003897 if (smp_cpus > machine->max_cpus) {
3898 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
3899 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
3900 machine->max_cpus);
3901 exit(1);
3902 }
3903
Anthony PERARD67b724e2010-11-22 15:44:15 +00003904 /*
3905 * Get the default machine options from the machine if it is not already
3906 * specified either by the configuration file or by the command line.
3907 */
3908 if (machine->default_machine_opts) {
Jan Kiszka25de5932012-01-27 19:55:43 +01003909 qemu_opts_set_defaults(qemu_find_opts("machine"),
3910 machine->default_machine_opts, 0);
Anthony PERARD67b724e2010-11-22 15:44:15 +00003911 }
3912
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003913 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
3914 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01003915
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003916 if (machine->no_serial) {
3917 default_serial = 0;
3918 }
3919 if (machine->no_parallel) {
3920 default_parallel = 0;
3921 }
3922 if (!machine->use_virtcon) {
3923 default_virtcon = 0;
3924 }
Alexander Graf3ef669e2013-01-24 12:18:52 +01003925 if (!machine->use_sclp) {
3926 default_sclp = 0;
3927 }
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01003928 if (machine->no_floppy) {
3929 default_floppy = 0;
3930 }
3931 if (machine->no_cdrom) {
3932 default_cdrom = 0;
3933 }
3934 if (machine->no_sdcard) {
3935 default_sdcard = 0;
3936 }
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003937
Michael Tokarevab51b1d2012-12-30 12:48:14 +04003938 if (is_daemonized()) {
3939 /* According to documentation and historically, -nographic redirects
3940 * serial port, parallel port and monitor to stdio, which does not work
3941 * with -daemonize. We can redirect these to null instead, but since
3942 * -nographic is legacy, let's just error out.
3943 * We disallow -nographic only if all other ports are not redirected
3944 * explicitly, to not break existing legacy setups which uses
3945 * -nographic _and_ redirects all ports explicitly - this is valid
3946 * usage, -nographic is just a no-op in this case.
3947 */
3948 if (display_type == DT_NOGRAPHIC
3949 && (default_parallel || default_serial
3950 || default_monitor || default_virtcon)) {
3951 fprintf(stderr, "-nographic can not be used with -daemonize\n");
3952 exit(1);
3953 }
3954#ifdef CONFIG_CURSES
3955 if (display_type == DT_CURSES) {
3956 fprintf(stderr, "curses display can not be used with -daemonize\n");
3957 exit(1);
3958 }
3959#endif
3960 }
3961
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003962 if (display_type == DT_NOGRAPHIC) {
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01003963 if (default_parallel)
3964 add_device_config(DEV_PARALLEL, "null");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003965 if (default_serial && default_monitor) {
3966 add_device_config(DEV_SERIAL, "mon:stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003967 } else if (default_virtcon && default_monitor) {
3968 add_device_config(DEV_VIRTCON, "mon:stdio");
Alexander Graf3ef669e2013-01-24 12:18:52 +01003969 } else if (default_sclp && default_monitor) {
3970 add_device_config(DEV_SCLP, "mon:stdio");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003971 } else {
3972 if (default_serial)
3973 add_device_config(DEV_SERIAL, "stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003974 if (default_virtcon)
3975 add_device_config(DEV_VIRTCON, "stdio");
Alexander Graf3ef669e2013-01-24 12:18:52 +01003976 if (default_sclp) {
3977 add_device_config(DEV_SCLP, "stdio");
3978 }
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003979 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01003980 monitor_parse("stdio", "readline");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003981 }
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01003982 } else {
3983 if (default_serial)
3984 add_device_config(DEV_SERIAL, "vc:80Cx24C");
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01003985 if (default_parallel)
3986 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
Gerd Hoffmannabdeed02009-12-08 13:11:43 +01003987 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01003988 monitor_parse("vc:80Cx24C", "readline");
Alexander Graf38536da2009-12-17 13:06:08 +01003989 if (default_virtcon)
3990 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
Alexander Graf3ef669e2013-01-24 12:18:52 +01003991 if (default_sclp) {
3992 add_device_config(DEV_SCLP, "vc:80Cx24C");
3993 }
aliguoribc0129d2008-08-01 15:12:34 +00003994 }
3995
Anthony Liguori15546422013-02-20 07:43:25 -06003996 if (display_type == DT_DEFAULT && !display_remote) {
3997#if defined(CONFIG_GTK)
3998 display_type = DT_GTK;
3999#elif defined(CONFIG_SDL) || defined(CONFIG_COCOA)
4000 display_type = DT_SDL;
4001#elif defined(CONFIG_VNC)
4002 vnc_display = "localhost:0,to=99";
4003 show_vnc_port = 1;
4004#else
4005 display_type = DT_NONE;
4006#endif
4007 }
4008
Peter Wu047d4e12013-06-11 10:55:08 +02004009 if ((no_frame || alt_grab || ctrl_grab) && display_type != DT_SDL) {
4010 fprintf(stderr, "-no-frame, -alt-grab and -ctrl-grab are only valid "
4011 "for SDL, ignoring option\n");
4012 }
4013 if (no_quit && (display_type != DT_GTK && display_type != DT_SDL)) {
4014 fprintf(stderr, "-no-quit is only valid for GTK and SDL, "
4015 "ignoring option\n");
4016 }
4017
Anthony Liguori15546422013-02-20 07:43:25 -06004018#if defined(CONFIG_GTK)
4019 if (display_type == DT_GTK) {
4020 early_gtk_display_init();
4021 }
4022#endif
4023
TeLeMana5829fd2010-04-15 12:37:55 +08004024 socket_init();
4025
Gerd Hoffmann3329f072010-08-20 13:52:01 +02004026 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01004027 exit(1);
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07004028#ifdef CONFIG_VIRTFS
Gerd Hoffmann3329f072010-08-20 13:52:01 +02004029 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +05304030 exit(1);
4031 }
4032#endif
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01004033
Jes Sorenseneb505be2010-06-10 11:42:28 +02004034 os_daemonize();
ths71e3ceb2006-12-22 02:11:31 +00004035
thsaa26bb22007-03-25 21:33:06 +00004036 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
Jes Sorenseneb505be2010-06-10 11:42:28 +02004037 os_pidfile_error();
ths93815bc2007-03-19 15:58:31 +00004038 exit(1);
4039 }
4040
Jan Kiszka0ac543d2011-08-15 16:18:57 -07004041 /* init the memory */
4042 if (ram_size == 0) {
4043 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
4044 }
4045
Bruce Rogers3d1d9652012-08-09 12:47:40 -06004046 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0)
4047 != 0) {
4048 exit(0);
4049 }
4050
Anthony PERARD303d4e82010-09-21 20:05:31 +01004051 configure_accelerator();
Marcelo Tosatti214910a2009-09-18 02:41:23 -03004052
Paolo Bonzinid4fce242013-10-18 13:51:11 +02004053 if (qtest_chrdev) {
4054 qtest_init(qtest_chrdev, qtest_log);
Edgar E. Iglesiasa907cf52013-04-15 21:28:17 +02004055 }
4056
Markus Armbruster2ff3de62013-07-04 15:09:22 +02004057 machine_opts = qemu_get_machine_opts();
4058 kernel_filename = qemu_opt_get(machine_opts, "kernel");
4059 initrd_filename = qemu_opt_get(machine_opts, "initrd");
4060 kernel_cmdline = qemu_opt_get(machine_opts, "append");
Gerd Hoffmann1442d3e2013-10-15 16:57:45 +02004061 bios_name = qemu_opt_get(machine_opts, "firmware");
Peter Maydell967c0da2012-02-22 22:40:00 +00004062
Markus Armbrustere3fdc532013-10-01 13:47:22 +02004063 boot_order = machine->default_boot_order;
Markus Armbruster8281abd2013-06-14 13:15:03 +02004064 opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
4065 if (opts) {
4066 char *normal_boot_order;
4067 const char *order, *once;
4068
4069 order = qemu_opt_get(opts, "order");
4070 if (order) {
4071 validate_bootdevices(order);
4072 boot_order = order;
4073 }
4074
4075 once = qemu_opt_get(opts, "once");
4076 if (once) {
4077 validate_bootdevices(once);
4078 normal_boot_order = g_strdup(boot_order);
4079 boot_order = once;
Markus Armbruster083b79c2013-06-14 13:15:04 +02004080 qemu_register_reset(restore_boot_order, normal_boot_order);
Markus Armbruster8281abd2013-06-14 13:15:03 +02004081 }
4082
4083 boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu);
4084 }
4085
Peter Maydella0abe472012-02-08 05:41:39 +00004086 if (!kernel_cmdline) {
4087 kernel_cmdline = "";
4088 }
4089
bellarda20dd502003-09-30 21:07:02 +00004090 linux_boot = (kernel_filename != NULL);
balrog6c41b272007-11-17 12:12:29 +00004091
thsf8d39c02008-07-03 10:01:15 +00004092 if (!linux_boot && *kernel_cmdline != '\0') {
4093 fprintf(stderr, "-append only allowed with -kernel option\n");
4094 exit(1);
4095 }
4096
4097 if (!linux_boot && initrd_filename != NULL) {
4098 fprintf(stderr, "-initrd only allowed with -kernel option\n");
4099 exit(1);
4100 }
4101
Markus Armbruster2ff3de62013-07-04 15:09:22 +02004102 if (!linux_boot && qemu_opt_get(machine_opts, "dtb")) {
Grant Likely412beee2012-03-02 11:56:38 +00004103 fprintf(stderr, "-dtb only allowed with -kernel option\n");
4104 exit(1);
4105 }
4106
Jes Sorensen9156d762010-06-10 11:42:30 +02004107 os_set_line_buffering();
ths3b46e622007-09-17 08:09:54 +00004108
Paolo Bonzini49cf5722012-11-02 15:43:24 +01004109 qemu_init_cpu_loop();
4110 qemu_mutex_lock_iothread();
4111
Alon Levyad1be892012-03-14 20:33:37 +02004112#ifdef CONFIG_SPICE
4113 /* spice needs the timers to be initialized by this point */
4114 qemu_spice_init();
4115#endif
4116
Max Filippov0abe9052011-11-10 15:38:42 +04004117 if (icount_option && (kvm_enabled() || xen_enabled())) {
4118 fprintf(stderr, "-icount is not allowed with kvm or xen\n");
4119 exit(1);
4120 }
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01004121 configure_icount(icount_option);
pbrook634fce92006-07-15 17:40:09 +00004122
Amos Kongf30dbae2012-12-11 22:20:15 +08004123 /* clean up network at qemu process termination */
4124 atexit(&net_cleanup);
4125
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01004126 if (net_init_clients() < 0) {
4127 exit(1);
bellard702c6512004-04-02 21:21:32 +00004128 }
bellardf1510b22003-06-25 00:07:40 +00004129
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05004130#ifdef CONFIG_TPM
4131 if (tpm_init() < 0) {
4132 exit(1);
4133 }
4134#endif
4135
balrogdc72ac12008-11-09 00:04:26 +00004136 /* init the bluetooth world */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02004137 if (foreach_device_config(DEV_BT, bt_parse))
4138 exit(1);
balrogdc72ac12008-11-09 00:04:26 +00004139
Anthony PERARD834e76e2011-07-20 08:17:44 +00004140 if (!xen_enabled()) {
4141 /* On 32-bit hosts, QEMU is limited by virtual address space */
4142 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
4143 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
4144 exit(1);
4145 }
4146 }
balrog7fb4fdc2008-04-24 17:59:27 +00004147
Jan Kiszkad5ab9712011-08-02 16:10:21 +02004148 cpu_exec_init_all();
bellard26a5f132008-05-28 12:30:31 +00004149
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +02004150 blk_mig_init();
4151
ths96d30e42007-01-07 20:42:14 +00004152 /* open the virtual block devices */
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02004153 if (snapshot)
Gerd Hoffmann3329f072010-08-20 13:52:01 +02004154 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
Christian Borntraeger2d0d2832012-11-20 15:30:34 +01004155 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func,
4156 &machine->block_default_type, 1) != 0) {
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02004157 exit(1);
Christian Borntraeger2d0d2832012-11-20 15:30:34 +01004158 }
balrog3e3d5812007-04-30 02:09:25 +00004159
Christian Borntraeger3c42ea62012-11-22 21:02:55 +01004160 default_drive(default_cdrom, snapshot, machine->block_default_type, 2,
4161 CDROM_OPTS);
4162 default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS);
4163 default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS);
Markus Armbruster4e5d9b52011-01-28 11:21:45 +01004164
Juan Quintela7908c782012-06-26 18:46:10 +02004165 register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00004166
aliguori268a3622009-04-21 22:30:27 +00004167 if (nb_numa_nodes > 0) {
4168 int i;
4169
Sasha Levinea0e5412011-06-29 23:29:39 -04004170 if (nb_numa_nodes > MAX_NODES) {
4171 nb_numa_nodes = MAX_NODES;
aliguori268a3622009-04-21 22:30:27 +00004172 }
4173
4174 /* If no memory size if given for any node, assume the default case
4175 * and distribute the available memory equally across all nodes
4176 */
4177 for (i = 0; i < nb_numa_nodes; i++) {
4178 if (node_mem[i] != 0)
4179 break;
4180 }
4181 if (i == nb_numa_nodes) {
4182 uint64_t usedmem = 0;
4183
4184 /* On Linux, the each node's border has to be 8MB aligned,
4185 * the final node gets the rest.
4186 */
4187 for (i = 0; i < nb_numa_nodes - 1; i++) {
4188 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
4189 usedmem += node_mem[i];
4190 }
4191 node_mem[i] = ram_size - usedmem;
4192 }
4193
4194 for (i = 0; i < nb_numa_nodes; i++) {
Chegu Vinodee785fe2012-07-16 21:31:30 -07004195 if (!bitmap_empty(node_cpumask[i], MAX_CPUMASK_BITS)) {
aliguori268a3622009-04-21 22:30:27 +00004196 break;
Chegu Vinodee785fe2012-07-16 21:31:30 -07004197 }
aliguori268a3622009-04-21 22:30:27 +00004198 }
4199 /* assigning the VCPUs round-robin is easier to implement, guest OSes
4200 * must cope with this anyway, because there are BIOSes out there in
4201 * real machines which also use this scheme.
4202 */
4203 if (i == nb_numa_nodes) {
Vasilis Liaskovitis991dfef2011-10-26 14:19:00 +02004204 for (i = 0; i < max_cpus; i++) {
Chegu Vinodee785fe2012-07-16 21:31:30 -07004205 set_bit(i, node_cpumask[i % nb_numa_nodes]);
aliguori268a3622009-04-21 22:30:27 +00004206 }
4207 }
4208 }
4209
Gerd Hoffmann3329f072010-08-20 13:52:01 +02004210 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
Jan Kiszka157b9312010-04-06 16:55:53 +02004211 exit(1);
4212 }
4213
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01004214 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
4215 exit(1);
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01004216 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
4217 exit(1);
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01004218 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
4219 exit(1);
Alexander Graf3ef669e2013-01-24 12:18:52 +01004220 if (foreach_device_config(DEV_SCLP, sclp_parse) < 0) {
4221 exit(1);
4222 }
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08004223 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
4224 exit(1);
aliguori2796dae2009-01-16 20:23:27 +00004225
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +02004226 /* If no default VGA is requested, the default is "none". */
Aurelien Jarno3605ded2012-09-10 01:01:44 +02004227 if (default_vga) {
4228 if (cirrus_vga_available()) {
4229 vga_model = "cirrus";
4230 } else if (vga_available()) {
4231 vga_model = "std";
4232 }
Blue Swirla369da52011-09-27 19:15:42 +00004233 }
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +02004234 select_vgahw(vga_model);
Blue Swirla369da52011-09-27 19:15:42 +00004235
Markus Armbruster09aaa162009-08-21 10:31:34 +02004236 if (watchdog) {
4237 i = select_watchdog(watchdog);
4238 if (i > 0)
4239 exit (i == 1 ? 1 : 0);
4240 }
4241
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02004242 if (machine->compat_props) {
Gerd Hoffmann458fb672009-12-08 13:11:33 +01004243 qdev_prop_register_global_list(machine->compat_props);
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02004244 }
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01004245 qemu_add_globals();
4246
Anthony Liguori1de81d22011-12-19 16:37:46 -06004247 qdev_machine_init();
4248
Markus Armbrustere689f7c2013-10-30 13:56:39 +01004249 QEMUMachineInitArgs args = { .machine = machine,
4250 .ram_size = ram_size,
Markus Armbrusterc1654732013-08-16 13:13:50 +02004251 .boot_order = boot_order,
Eduardo Habkost5f072e12012-10-15 17:22:02 -03004252 .kernel_filename = kernel_filename,
4253 .kernel_cmdline = kernel_cmdline,
4254 .initrd_filename = initrd_filename,
4255 .cpu_model = cpu_model };
4256 machine->init(&args);
aliguori3023f332009-01-16 19:04:14 +00004257
Paolo Bonzinib3e6d592013-04-18 18:44:04 +02004258 audio_init();
4259
Jan Kiszkaea375f92010-03-01 19:10:30 +01004260 cpu_synchronize_all_post_init();
aliguori268a3622009-04-21 22:30:27 +00004261
Blue Swirl87d0a282010-03-27 18:24:45 +00004262 set_numa_modes();
aliguori268a3622009-04-21 22:30:27 +00004263
aliguori6f338c32009-02-11 15:21:54 +00004264 current_machine = machine;
4265
aliguori3023f332009-01-16 19:04:14 +00004266 /* init USB devices */
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00004267 if (usb_enabled(false)) {
Markus Armbruster07527062009-10-06 12:16:57 +01004268 if (foreach_device_config(DEV_USB, usb_parse) < 0)
4269 exit(1);
aliguori3023f332009-01-16 19:04:14 +00004270 }
4271
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02004272 /* init generic devices */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02004273 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02004274 exit(1);
4275
Markus Armbruster668680f2010-02-11 14:44:58 +01004276 net_check_clients();
4277
Gerd Hoffmann64840c62013-03-07 17:08:29 +01004278 ds = init_displaystate();
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004279
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02004280 /* init local displays */
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004281 switch (display_type) {
4282 case DT_NOGRAPHIC:
Antony Pavlov8111d022013-10-29 08:36:31 +04004283 (void)ds; /* avoid warning if no display is configured */
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004284 break;
4285#if defined(CONFIG_CURSES)
4286 case DT_CURSES:
Michael Tokarevab51b1d2012-12-30 12:48:14 +04004287 curses_display_init(ds, full_screen);
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004288 break;
4289#endif
bellard5b0753e2005-03-01 21:37:28 +00004290#if defined(CONFIG_SDL)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004291 case DT_SDL:
4292 sdl_display_init(ds, full_screen, no_frame);
4293 break;
bellard5b0753e2005-03-01 21:37:28 +00004294#elif defined(CONFIG_COCOA)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004295 case DT_SDL:
4296 cocoa_display_init(ds, full_screen);
4297 break;
bellard313aa562003-08-10 21:52:11 +00004298#endif
Anthony Liguori15546422013-02-20 07:43:25 -06004299#if defined(CONFIG_GTK)
4300 case DT_GTK:
Peter Wu787ba4f2013-06-10 20:04:43 +02004301 gtk_display_init(ds, full_screen);
Anthony Liguori15546422013-02-20 07:43:25 -06004302 break;
4303#endif
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02004304 default:
4305 break;
4306 }
4307
Gleb Natapov0ce235a2011-03-31 11:27:23 +02004308 /* must be after terminal init, SDL library changes signal handlers */
4309 os_setup_signal_handling();
4310
Jes Sorensen821601e2011-03-16 13:33:36 +01004311#ifdef CONFIG_VNC
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02004312 /* init remote displays */
4313 if (vnc_display) {
Paolo Bonzini2d55f0e2012-10-02 10:17:21 +02004314 Error *local_err = NULL;
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004315 vnc_display_init(ds);
Paolo Bonzini2d55f0e2012-10-02 10:17:21 +02004316 vnc_display_open(ds, vnc_display, &local_err);
4317 if (local_err != NULL) {
Seiji Aguchi4a44d852013-08-05 15:40:44 -04004318 error_report("Failed to start VNC server on `%s': %s",
4319 vnc_display, error_get_pretty(local_err));
Paolo Bonzini2d55f0e2012-10-02 10:17:21 +02004320 error_free(local_err);
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004321 exit(1);
Amos Kong94b204c2012-06-30 10:02:20 +08004322 }
Anthony Liguorif92f8af2009-05-20 13:01:02 -05004323
Anthony Liguori993fbfd2009-05-21 16:54:00 -05004324 if (show_vnc_port) {
4325 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
Anthony Liguorif92f8af2009-05-20 13:01:02 -05004326 }
bellard313aa562003-08-10 21:52:11 +00004327 }
Jes Sorensen821601e2011-03-16 13:33:36 +01004328#endif
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02004329#ifdef CONFIG_SPICE
Gerd Hoffmann9fa03282013-10-11 22:39:59 +02004330 if (using_spice) {
4331 qemu_spice_display_init();
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02004332 }
4333#endif
aliguori5b08fc12008-08-21 20:08:03 +00004334
Markus Armbrusteref0c4a02012-02-07 15:09:13 +01004335 if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
aliguori59030a82009-04-05 18:43:41 +00004336 exit(1);
balrog45669e02007-07-02 13:20:17 +00004337 }
balrog45669e02007-07-02 13:20:17 +00004338
Gerd Hoffmann3418bd22009-09-25 21:42:41 +02004339 qdev_machine_creation_done();
4340
Gerd Hoffmann15ff7702009-12-14 16:07:35 +01004341 if (rom_load_all() != 0) {
4342 fprintf(stderr, "rom loading failed\n");
4343 exit(1);
4344 }
Gerd Hoffmann45a50b12009-10-01 16:42:33 +02004345
Isaku Yamahata80376c32010-12-20 14:33:35 +09004346 /* TODO: once all bus devices are qdevified, this should be done
4347 * when bus is created by qdev.c */
4348 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
Gleb Natapov4cab9462010-12-08 13:35:08 +02004349 qemu_run_machine_init_done_notifiers();
4350
Michael S. Tsirkind916b462013-07-24 18:56:08 +03004351 /* Done notifiers can load ROMs */
4352 rom_load_done();
4353
Jan Kiszkae063eb12011-06-14 18:29:43 +02004354 qemu_system_reset(VMRESET_SILENT);
Juan Quintela05f24012009-08-20 19:42:22 +02004355 if (loadvm) {
Markus Armbruster03cd4652010-02-17 16:24:10 +01004356 if (load_vmstate(loadvm) < 0) {
Juan Quintela05f24012009-08-20 19:42:22 +02004357 autostart = 0;
4358 }
4359 }
bellardd63d3072004-10-03 13:29:03 +00004360
Glauber Costa2bb8c102009-07-24 16:20:23 -04004361 if (incoming) {
Paolo Bonzini43eaae22012-10-02 18:21:18 +02004362 Error *local_err = NULL;
4363 qemu_start_incoming_migration(incoming, &local_err);
4364 if (local_err) {
Seiji Aguchi4a44d852013-08-05 15:40:44 -04004365 error_report("-incoming %s: %s", incoming,
4366 error_get_pretty(local_err));
Paolo Bonzini43eaae22012-10-02 18:21:18 +02004367 error_free(local_err);
4368 exit(1);
Juan Quintela8ca5e802010-06-09 14:10:54 +02004369 }
Avi Kivity6b99dad2009-08-09 14:39:20 +03004370 } else if (autostart) {
aliguoric0f4ce72009-03-05 23:01:01 +00004371 vm_start();
Avi Kivity6b99dad2009-08-09 14:39:20 +03004372 }
thsffd843b2006-12-21 19:46:43 +00004373
Jes Sorenseneb505be2010-06-10 11:42:28 +02004374 os_setup_post();
ths71e3ceb2006-12-22 02:11:31 +00004375
bellard8a7ddc32004-03-31 19:00:16 +00004376 main_loop();
Paolo Bonzini99435902011-09-12 14:03:13 +02004377 bdrv_close_all();
4378 pause_all_vcpus();
wayne3d3b8302011-07-27 18:04:55 +08004379 res_free();
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05004380#ifdef CONFIG_TPM
4381 tpm_cleanup();
4382#endif
thsb46a8902007-10-21 23:20:45 +00004383
bellard0824d6f2003-06-24 13:42:40 +00004384 return 0;
4385}