blob: 7d0708afcdc527ec99796fba318fa28a526c7908 [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>
Chegu Vinodee785fe2012-07-16 21:31:30 -070031#include "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
68#include "qemu-seccomp.h"
69#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"
120#include "hw/pc.h"
blueswir1511d2b12009-03-07 15:32:56 +0000121#include "hw/isa.h"
122#include "hw/baum.h"
123#include "hw/bt.h"
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +0100124#include "hw/watchdog.h"
aliguorib6f6e3d2009-04-17 18:59:56 +0000125#include "hw/smbios.h"
aliguorie37630c2009-04-22 15:19:10 +0000126#include "hw/xen.h"
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +0200127#include "hw/qdev.h"
Gerd Hoffmann45a50b12009-10-01 16:42:33 +0200128#include "hw/loader.h"
aurel325ef4efa2009-03-10 21:43:35 +0000129#include "bt-host.h"
blueswir1511d2b12009-03-07 15:32:56 +0000130#include "net.h"
Mark McLoughlin68ac40d2009-11-25 18:48:54 +0000131#include "net/slirp.h"
blueswir1511d2b12009-03-07 15:32:56 +0000132#include "monitor.h"
133#include "console.h"
134#include "sysemu.h"
135#include "gdbstub.h"
136#include "qemu-timer.h"
137#include "qemu-char.h"
138#include "cache-utils.h"
Markus Armbruster666daa62010-06-02 18:48:27 +0200139#include "blockdev.h"
Markus Armbruster2b584952012-07-10 11:12:50 +0200140#include "hw/block-common.h"
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +0200141#include "block-migration.h"
blueswir1a718ace2009-03-28 08:24:44 +0000142#include "dma.h"
blueswir1511d2b12009-03-07 15:32:56 +0000143#include "audio/audio.h"
144#include "migration.h"
145#include "kvm.h"
Luiz Capitulinof795e742011-10-21 16:05:43 -0200146#include "qjson.h"
Kevin Wolfd3f24362009-05-18 16:42:09 +0200147#include "qemu-option.h"
Gerd Hoffmann7282a032009-07-31 12:25:35 +0200148#include "qemu-config.h"
Jes Sorensen59a52642010-06-10 11:42:25 +0200149#include "qemu-options.h"
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -0300150#include "qmp-commands.h"
Paolo Bonzini44a9b352011-09-12 16:44:30 +0200151#include "main-loop.h"
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -0700152#ifdef CONFIG_VIRTFS
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530153#include "fsdev/qemu-fsdev.h"
154#endif
Anthony Liguoric7f0f3b2012-03-28 15:42:02 +0200155#include "qtest.h"
blueswir1511d2b12009-03-07 15:32:56 +0000156
bellard0824d6f2003-06-24 13:42:40 +0000157#include "disas.h"
bellardfc01f7e2003-06-30 10:03:06 +0000158
blueswir1511d2b12009-03-07 15:32:56 +0000159#include "qemu_socket.h"
160
Jan Kiszkad918f232009-06-24 14:42:30 +0200161#include "slirp/libslirp.h"
blueswir1511d2b12009-03-07 15:32:56 +0000162
Stefan Hajnoczi94b0b5f2010-11-16 12:20:25 +0000163#include "trace.h"
Lluíse4858972011-08-31 20:31:03 +0200164#include "trace/control.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +0000165#include "qemu-queue.h"
Blue Swirl296af7c2010-03-29 19:23:50 +0000166#include "cpus.h"
Blue Swirlad960902010-03-29 19:23:52 +0000167#include "arch_init.h"
Paul Moore0f669982012-08-03 14:39:21 -0400168#include "osdep.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +0000169
Gerd Hoffmann29b00402010-03-11 11:13:27 -0300170#include "ui/qemu-spice.h"
171
blueswir19dc63a12008-10-04 07:25:46 +0000172//#define DEBUG_NET
173//#define DEBUG_SLIRP
bellard330d0412003-07-26 18:11:40 +0000174
bellard1bfe8562004-07-08 21:17:50 +0000175#define DEFAULT_RAM_SIZE 128
bellard313aa562003-08-10 21:52:11 +0000176
Amit Shah98b19252010-01-20 00:36:52 +0530177#define MAX_VIRTIO_CONSOLES 1
178
Paul Brook5cea8592009-05-30 00:52:44 +0100179static const char *data_dir;
j_mayer1192dad2007-10-05 13:08:35 +0000180const char *bios_name = NULL;
malccb5a7aa2008-09-28 00:42:12 +0000181enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
Anthony Liguori993fbfd2009-05-21 16:54:00 -0500182DisplayType display_type = DT_DEFAULT;
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +0200183int display_remote = 0;
bellard3d11d0e2004-12-12 16:56:30 +0000184const char* keyboard_layout = NULL;
Anthony Liguoric227f092009-10-01 16:12:16 -0500185ram_addr_t ram_size;
Marcelo Tosattic9027602010-03-01 20:25:08 -0300186const char *mem_path = NULL;
187#ifdef MAP_POPULATE
188int mem_prealloc = 0; /* force preallocation of physical target memory */
189#endif
bellardc4b1fcc2004-03-14 21:44:30 +0000190int nb_nics;
bellard7c9d8e02005-11-15 22:16:05 +0000191NICInfo nd_table[MAX_NICS];
Paolo Bonzinid399f672009-07-27 23:17:51 +0200192int autostart;
balrogf6503052008-02-17 11:42:19 +0000193static int rtc_utc = 1;
194static int rtc_date_offset = -1; /* -1 means no change */
Jan Kiszka68752042009-09-15 13:36:04 +0200195QEMUClock *rtc_clock;
Gerd Hoffmann64465292009-12-08 13:11:45 +0100196int vga_interface_type = VGA_NONE;
blueswir1dbed7e42008-10-01 19:38:09 +0000197static int full_screen = 0;
blueswir1634a21f2008-11-16 11:34:07 +0000198#ifdef CONFIG_SDL
blueswir1dbed7e42008-10-01 19:38:09 +0000199static int no_frame = 0;
blueswir1634a21f2008-11-16 11:34:07 +0000200#endif
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];
bellarda09db212005-04-30 16:10:35 +0000205int win2k_install_hack = 0;
aurel321b530a62009-04-05 20:08:59 +0000206int singlestep = 0;
bellard6a00d602005-11-21 23:25:50 +0000207int smp_cpus = 1;
Jes Sorensen6be68d72009-07-23 17:03:42 +0200208int max_cpus = 0;
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200209int smp_cores = 1;
210int smp_threads = 1;
Jes Sorensen821601e2011-03-16 13:33:36 +0100211#ifdef CONFIG_VNC
ths73fc9742006-12-22 02:09:07 +0000212const char *vnc_display;
Jes Sorensen821601e2011-03-16 13:33:36 +0100213#endif
bellard6515b202006-05-03 22:02:44 +0000214int acpi_enabled = 1;
aliguori16b29ae2008-12-17 23:28:44 +0000215int no_hpet = 0;
bellard52ca8d62006-06-14 16:03:05 +0000216int fd_bootchk = 1;
bellardd1beab82006-10-02 19:44:22 +0000217int no_reboot = 0;
aurel32b2f76162008-04-11 21:35:52 +0000218int no_shutdown = 0;
balrog9467cd42007-05-01 01:34:14 +0000219int cursor_hide = 1;
balroga171fe32007-04-30 01:48:07 +0000220int graphic_rotate = 0;
Markus Armbruster09aaa162009-08-21 10:31:34 +0200221const char *watchdog;
Gleb Natapov2e55e842010-12-08 13:35:07 +0200222QEMUOptionRom option_rom[MAX_OPTION_ROMS];
ths9ae02552007-01-05 17:39:04 +0000223int nb_option_roms;
pbrook8e716212007-01-20 17:12:09 +0000224int semihosting_enabled = 0;
balrog2b8f2d42007-07-27 22:08:46 +0000225int old_param = 0;
thsc35734b2007-03-19 15:17:08 +0000226const char *qemu_name;
ths3780e192007-06-21 21:08:02 +0000227int alt_grab = 0;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -0500228int ctrl_grab = 0;
blueswir166508602007-05-01 14:16:52 +0000229unsigned int nb_prom_envs = 0;
230const char *prom_envs[MAX_PROM_ENVS];
Jan Kiszka95387492009-07-02 00:19:02 +0200231int boot_menu;
wayne3d3b8302011-07-27 18:04:55 +0800232uint8_t *boot_splash_filedata;
233int boot_splash_filedata_size;
234uint8_t qemu_extra_params_fw[2];
bellard0824d6f2003-06-24 13:42:40 +0000235
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200236typedef struct FWBootEntry FWBootEntry;
237
238struct FWBootEntry {
239 QTAILQ_ENTRY(FWBootEntry) link;
240 int32_t bootindex;
241 DeviceState *dev;
242 char *suffix;
243};
244
245QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order);
246
aliguori268a3622009-04-21 22:30:27 +0000247int nb_numa_nodes;
248uint64_t node_mem[MAX_NODES];
Chegu Vinodee785fe2012-07-16 21:31:30 -0700249unsigned long *node_cpumask[MAX_NODES];
aliguori268a3622009-04-21 22:30:27 +0000250
blueswir18fcb1b92008-09-18 18:29:08 +0000251uint8_t qemu_uuid[16];
252
Jan Kiszka76e30d02009-07-02 00:19:02 +0200253static QEMUBootSetHandler *boot_set_handler;
254static void *boot_set_opaque;
255
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +0200256static NotifierList exit_notifiers =
257 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
258
Gleb Natapov4cab9462010-12-08 13:35:08 +0200259static NotifierList machine_init_done_notifiers =
260 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
261
Anthony PERARD303d4e82010-09-21 20:05:31 +0100262static int tcg_allowed = 1;
Blue Swirld745bef2010-03-29 19:23:49 +0000263int kvm_allowed = 0;
Anthony PERARD3285cf42010-08-19 12:27:56 +0100264int xen_allowed = 0;
Blue Swirld745bef2010-03-29 19:23:49 +0000265uint32_t xen_domid;
266enum xen_mode xen_mode = XEN_EMULATE;
Jan Kiszkad5ab9712011-08-02 16:10:21 +0200267static int tcg_tb_size;
Blue Swirld745bef2010-03-29 19:23:49 +0000268
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100269static int default_serial = 1;
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +0100270static int default_parallel = 1;
Gerd Hoffmann986c5f72009-12-08 13:11:54 +0100271static int default_virtcon = 1;
Gerd Hoffmannabdeed02009-12-08 13:11:43 +0100272static int default_monitor = 1;
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +0100273static int default_floppy = 1;
274static int default_cdrom = 1;
275static int default_sdcard = 1;
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +0200276static int default_vga = 1;
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100277
278static struct {
279 const char *driver;
280 int *flag;
281} default_list[] = {
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +0100282 { .driver = "isa-serial", .flag = &default_serial },
283 { .driver = "isa-parallel", .flag = &default_parallel },
Gerd Hoffmannd8bcbab2009-12-16 14:25:40 +0100284 { .driver = "isa-fdc", .flag = &default_floppy },
Markus Armbrusteraf6bf132011-05-18 18:31:02 +0200285 { .driver = "ide-cd", .flag = &default_cdrom },
286 { .driver = "ide-hd", .flag = &default_cdrom },
Gerd Hoffmannd8bcbab2009-12-16 14:25:40 +0100287 { .driver = "ide-drive", .flag = &default_cdrom },
Markus Armbrusteraf6bf132011-05-18 18:31:02 +0200288 { .driver = "scsi-cd", .flag = &default_cdrom },
Amit Shah392ecf52010-01-21 16:19:23 +0530289 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
290 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
291 { .driver = "virtio-serial", .flag = &default_virtcon },
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +0200292 { .driver = "VGA", .flag = &default_vga },
293 { .driver = "isa-vga", .flag = &default_vga },
294 { .driver = "cirrus-vga", .flag = &default_vga },
295 { .driver = "isa-cirrus-vga", .flag = &default_vga },
296 { .driver = "vmware-svga", .flag = &default_vga },
297 { .driver = "qxl-vga", .flag = &default_vga },
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100298};
299
Ronnie Sahlberg31459f42012-08-06 18:24:55 +1000300const char *qemu_get_vm_name(void)
301{
302 return qemu_name;
303}
304
wayne3d3b8302011-07-27 18:04:55 +0800305static void res_free(void)
306{
307 if (boot_splash_filedata != NULL) {
Anthony Liguori7267c092011-08-20 22:09:37 -0500308 g_free(boot_splash_filedata);
wayne3d3b8302011-07-27 18:04:55 +0800309 boot_splash_filedata = NULL;
310 }
311}
312
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100313static int default_driver_check(QemuOpts *opts, void *opaque)
314{
315 const char *driver = qemu_opt_get(opts, "driver");
316 int i;
317
318 if (!driver)
319 return 0;
320 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
321 if (strcmp(default_list[i].driver, driver) != 0)
322 continue;
323 *(default_list[i].flag) = 0;
324 }
325 return 0;
326}
327
bellard0824d6f2003-06-24 13:42:40 +0000328/***********************************************************/
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300329/* QEMU state */
330
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300331static RunState current_run_state = RUN_STATE_PRELAUNCH;
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300332
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300333typedef struct {
334 RunState from;
335 RunState to;
336} RunStateTransition;
337
338static const RunStateTransition runstate_transitions_def[] = {
339 /* from -> to */
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300340 { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300341
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300342 { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },
Paolo Bonzini29ed72f2012-10-19 16:45:24 +0200343 { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300344
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300345 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300346 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300347
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300348 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300349 { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300350
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300351 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300352 { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300353
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300354 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300355 { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300356
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300357 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300358 { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300359 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300360
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300361 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
362 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300363
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300364 { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300365
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300366 { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
367 { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
368 { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
369 { RUN_STATE_RUNNING, RUN_STATE_PAUSED },
370 { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE },
371 { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM },
372 { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM },
373 { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
374 { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300375
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300376 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300377
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300378 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300379 { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300380
Luiz Capitulinoad02b962012-04-27 13:33:36 -0300381 { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
382 { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
383 { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },
384 { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
385
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300386 { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300387 { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300388
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300389 { RUN_STATE_MAX, RUN_STATE_MAX },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300390};
391
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300392static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX];
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300393
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300394bool runstate_check(RunState state)
395{
396 return current_run_state == state;
397}
398
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300399void runstate_init(void)
400{
401 const RunStateTransition *p;
402
403 memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions));
404
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300405 for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) {
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300406 runstate_valid_transitions[p->from][p->to] = true;
407 }
408}
409
410/* This function will abort() on invalid state transitions */
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300411void runstate_set(RunState new_state)
412{
Luiz Capitulino207c5cd2011-10-13 10:59:07 -0300413 assert(new_state < RUN_STATE_MAX);
414
415 if (!runstate_valid_transitions[current_run_state][new_state]) {
416 fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
417 RunState_lookup[current_run_state],
418 RunState_lookup[new_state]);
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300419 abort();
420 }
421
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300422 current_run_state = new_state;
423}
424
Luiz Capitulino13548692011-07-29 15:36:43 -0300425int runstate_is_running(void)
426{
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300427 return runstate_check(RUN_STATE_RUNNING);
Luiz Capitulino13548692011-07-29 15:36:43 -0300428}
429
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -0300430StatusInfo *qmp_query_status(Error **errp)
431{
432 StatusInfo *info = g_malloc0(sizeof(*info));
433
434 info->running = runstate_is_running();
435 info->singlestep = singlestep;
436 info->status = current_run_state;
437
438 return info;
439}
440
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300441/***********************************************************/
Paolo Bonzini8f0056b2010-01-13 14:05:34 +0100442/* real time host monotonic timer */
bellard09b26c52006-04-12 21:09:08 +0000443
bellardc4b1fcc2004-03-14 21:44:30 +0000444/***********************************************************/
balrogf6503052008-02-17 11:42:19 +0000445/* host time/date access */
446void qemu_get_timedate(struct tm *tm, int offset)
447{
448 time_t ti;
449 struct tm *ret;
450
451 time(&ti);
452 ti += offset;
453 if (rtc_date_offset == -1) {
454 if (rtc_utc)
455 ret = gmtime(&ti);
456 else
457 ret = localtime(&ti);
458 } else {
459 ti -= rtc_date_offset;
460 ret = gmtime(&ti);
461 }
462
463 memcpy(tm, ret, sizeof(struct tm));
464}
465
466int qemu_timedate_diff(struct tm *tm)
467{
468 time_t seconds;
469
470 if (rtc_date_offset == -1)
471 if (rtc_utc)
472 seconds = mktimegm(tm);
Gleb Natapovf54c5562011-11-06 18:00:22 +0200473 else {
474 struct tm tmp = *tm;
475 tmp.tm_isdst = -1; /* use timezone to figure it out */
476 seconds = mktime(&tmp);
477 }
balrogf6503052008-02-17 11:42:19 +0000478 else
479 seconds = mktimegm(tm) + rtc_date_offset;
480
481 return seconds - time(NULL);
482}
483
Luiz Capitulino80cd3472010-02-25 12:11:44 -0300484void rtc_change_mon_event(struct tm *tm)
485{
486 QObject *data;
487
488 data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
489 monitor_protocol_event(QEVENT_RTC_CHANGE, data);
490 qobject_decref(data);
491}
492
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200493static void configure_rtc_date_offset(const char *startdate, int legacy)
494{
495 time_t rtc_start_date;
496 struct tm tm;
497
498 if (!strcmp(startdate, "now") && legacy) {
499 rtc_date_offset = -1;
500 } else {
501 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
502 &tm.tm_year,
503 &tm.tm_mon,
504 &tm.tm_mday,
505 &tm.tm_hour,
506 &tm.tm_min,
507 &tm.tm_sec) == 6) {
508 /* OK */
509 } else if (sscanf(startdate, "%d-%d-%d",
510 &tm.tm_year,
511 &tm.tm_mon,
512 &tm.tm_mday) == 3) {
513 tm.tm_hour = 0;
514 tm.tm_min = 0;
515 tm.tm_sec = 0;
516 } else {
517 goto date_fail;
518 }
519 tm.tm_year -= 1900;
520 tm.tm_mon--;
521 rtc_start_date = mktimegm(&tm);
522 if (rtc_start_date == -1) {
523 date_fail:
524 fprintf(stderr, "Invalid date format. Valid formats are:\n"
525 "'2006-06-17T16:01:21' or '2006-06-17'\n");
526 exit(1);
527 }
528 rtc_date_offset = time(NULL) - rtc_start_date;
529 }
530}
531
532static void configure_rtc(QemuOpts *opts)
533{
534 const char *value;
535
536 value = qemu_opt_get(opts, "base");
537 if (value) {
538 if (!strcmp(value, "utc")) {
539 rtc_utc = 1;
540 } else if (!strcmp(value, "localtime")) {
541 rtc_utc = 0;
542 } else {
543 configure_rtc_date_offset(value, 0);
544 }
545 }
Jan Kiszka68752042009-09-15 13:36:04 +0200546 value = qemu_opt_get(opts, "clock");
547 if (value) {
548 if (!strcmp(value, "host")) {
549 rtc_clock = host_clock;
Paolo Bonzini78808142012-03-30 10:31:21 +0000550 } else if (!strcmp(value, "rt")) {
551 rtc_clock = rt_clock;
Jan Kiszka68752042009-09-15 13:36:04 +0200552 } else if (!strcmp(value, "vm")) {
553 rtc_clock = vm_clock;
554 } else {
555 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
556 exit(1);
557 }
558 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200559 value = qemu_opt_get(opts, "driftfix");
560 if (value) {
Blue Swirl7e4c0332010-03-27 21:33:46 +0000561 if (!strcmp(value, "slew")) {
Jan Kiszka433acf02012-01-23 20:15:12 +0100562 static GlobalProperty slew_lost_ticks[] = {
563 {
564 .driver = "mc146818rtc",
565 .property = "lost_tick_policy",
566 .value = "slew",
567 },
568 { /* end of list */ }
569 };
570
571 qdev_prop_register_global_list(slew_lost_ticks);
Blue Swirl7e4c0332010-03-27 21:33:46 +0000572 } else if (!strcmp(value, "none")) {
Jan Kiszka433acf02012-01-23 20:15:12 +0100573 /* discard is default */
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200574 } else {
575 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
576 exit(1);
577 }
578 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200579}
580
balrog1ae26a12008-09-28 23:19:47 +0000581/***********************************************************/
582/* Bluetooth support */
583static int nb_hcis;
584static int cur_hci;
585static struct HCIInfo *hci_table[MAX_NICS];
balrogdc72ac12008-11-09 00:04:26 +0000586
balrog1ae26a12008-09-28 23:19:47 +0000587static struct bt_vlan_s {
588 struct bt_scatternet_s net;
589 int id;
590 struct bt_vlan_s *next;
591} *first_bt_vlan;
592
593/* find or alloc a new bluetooth "VLAN" */
blueswir1674bb262008-09-30 18:18:27 +0000594static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
balrog1ae26a12008-09-28 23:19:47 +0000595{
596 struct bt_vlan_s **pvlan, *vlan;
597 for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) {
598 if (vlan->id == id)
599 return &vlan->net;
600 }
Anthony Liguori7267c092011-08-20 22:09:37 -0500601 vlan = g_malloc0(sizeof(struct bt_vlan_s));
balrog1ae26a12008-09-28 23:19:47 +0000602 vlan->id = id;
603 pvlan = &first_bt_vlan;
604 while (*pvlan != NULL)
605 pvlan = &(*pvlan)->next;
606 *pvlan = vlan;
607 return &vlan->net;
608}
609
610static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
611{
612}
613
614static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
615{
616 return -ENOTSUP;
617}
618
619static struct HCIInfo null_hci = {
620 .cmd_send = null_hci_send,
621 .sco_send = null_hci_send,
622 .acl_send = null_hci_send,
623 .bdaddr_set = null_hci_addr_set,
624};
625
626struct HCIInfo *qemu_next_hci(void)
627{
628 if (cur_hci == nb_hcis)
629 return &null_hci;
630
631 return hci_table[cur_hci++];
632}
633
balrogdc72ac12008-11-09 00:04:26 +0000634static struct HCIInfo *hci_init(const char *str)
635{
636 char *endp;
637 struct bt_scatternet_s *vlan = 0;
638
639 if (!strcmp(str, "null"))
640 /* null */
641 return &null_hci;
642 else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':'))
643 /* host[:hciN] */
644 return bt_host_hci(str[4] ? str + 5 : "hci0");
645 else if (!strncmp(str, "hci", 3)) {
646 /* hci[,vlan=n] */
647 if (str[3]) {
648 if (!strncmp(str + 3, ",vlan=", 6)) {
649 vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0));
650 if (*endp)
651 vlan = 0;
652 }
653 } else
654 vlan = qemu_find_bt_vlan(0);
655 if (vlan)
656 return bt_new_hci(vlan);
657 }
658
659 fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
660
661 return 0;
662}
663
664static int bt_hci_parse(const char *str)
665{
666 struct HCIInfo *hci;
Anthony Liguoric227f092009-10-01 16:12:16 -0500667 bdaddr_t bdaddr;
balrogdc72ac12008-11-09 00:04:26 +0000668
669 if (nb_hcis >= MAX_NICS) {
670 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
671 return -1;
672 }
673
674 hci = hci_init(str);
675 if (!hci)
676 return -1;
677
678 bdaddr.b[0] = 0x52;
679 bdaddr.b[1] = 0x54;
680 bdaddr.b[2] = 0x00;
681 bdaddr.b[3] = 0x12;
682 bdaddr.b[4] = 0x34;
683 bdaddr.b[5] = 0x56 + nb_hcis;
684 hci->bdaddr_set(hci, bdaddr.b);
685
686 hci_table[nb_hcis++] = hci;
687
688 return 0;
689}
690
691static void bt_vhci_add(int vlan_id)
692{
693 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
694
695 if (!vlan->slave)
696 fprintf(stderr, "qemu: warning: adding a VHCI to "
697 "an empty scatternet %i\n", vlan_id);
698
699 bt_vhci_init(bt_new_hci(vlan));
700}
701
702static struct bt_device_s *bt_device_add(const char *opt)
703{
704 struct bt_scatternet_s *vlan;
705 int vlan_id = 0;
706 char *endp = strstr(opt, ",vlan=");
707 int len = (endp ? endp - opt : strlen(opt)) + 1;
708 char devname[10];
709
710 pstrcpy(devname, MIN(sizeof(devname), len), opt);
711
712 if (endp) {
713 vlan_id = strtol(endp + 6, &endp, 0);
714 if (*endp) {
715 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
716 return 0;
717 }
718 }
719
720 vlan = qemu_find_bt_vlan(vlan_id);
721
722 if (!vlan->slave)
723 fprintf(stderr, "qemu: warning: adding a slave device to "
724 "an empty scatternet %i\n", vlan_id);
725
726 if (!strcmp(devname, "keyboard"))
727 return bt_keyboard_init(vlan);
728
729 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
730 return 0;
731}
732
733static int bt_parse(const char *opt)
734{
735 const char *endp, *p;
736 int vlan;
737
738 if (strstart(opt, "hci", &endp)) {
739 if (!*endp || *endp == ',') {
740 if (*endp)
741 if (!strstart(endp, ",vlan=", 0))
742 opt = endp + 1;
743
744 return bt_hci_parse(opt);
745 }
746 } else if (strstart(opt, "vhci", &endp)) {
747 if (!*endp || *endp == ',') {
748 if (*endp) {
749 if (strstart(endp, ",vlan=", &p)) {
750 vlan = strtol(p, (char **) &endp, 0);
751 if (*endp) {
752 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
753 return 1;
754 }
755 } else {
756 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
757 return 1;
758 }
759 } else
760 vlan = 0;
761
762 bt_vhci_add(vlan);
763 return 0;
764 }
765 } else if (strstart(opt, "device:", &endp))
766 return !bt_device_add(endp);
767
768 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
769 return 1;
770}
771
Eduardo Otubo7d76ad42012-08-14 18:44:08 -0300772static int parse_sandbox(QemuOpts *opts, void *opaque)
773{
774 /* FIXME: change this to true for 1.3 */
775 if (qemu_opt_get_bool(opts, "enable", false)) {
776#ifdef CONFIG_SECCOMP
777 if (seccomp_start() < 0) {
778 qerror_report(ERROR_CLASS_GENERIC_ERROR,
779 "failed to install seccomp syscall filter in the kernel");
780 return -1;
781 }
782#else
783 qerror_report(ERROR_CLASS_GENERIC_ERROR,
784 "sandboxing request but seccomp is not compiled into this build");
785 return -1;
786#endif
787 }
788
789 return 0;
790}
791
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +0000792/*********QEMU USB setting******/
793bool usb_enabled(bool default_usb)
794{
795 QemuOpts *mach_opts;
796 mach_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
797 if (mach_opts) {
798 return qemu_opt_get_bool(mach_opts, "usb", default_usb);
799 }
800 return default_usb;
801}
802
Corey Bryant587ed6b2012-10-18 15:19:34 -0400803#ifndef _WIN32
804static int parse_add_fd(QemuOpts *opts, void *opaque)
805{
806 int fd, dupfd, flags;
807 int64_t fdset_id;
808 const char *fd_opaque = NULL;
809
810 fd = qemu_opt_get_number(opts, "fd", -1);
811 fdset_id = qemu_opt_get_number(opts, "set", -1);
812 fd_opaque = qemu_opt_get(opts, "opaque");
813
814 if (fd < 0) {
815 qerror_report(ERROR_CLASS_GENERIC_ERROR,
816 "fd option is required and must be non-negative");
817 return -1;
818 }
819
820 if (fd <= STDERR_FILENO) {
821 qerror_report(ERROR_CLASS_GENERIC_ERROR,
822 "fd cannot be a standard I/O stream");
823 return -1;
824 }
825
826 /*
827 * All fds inherited across exec() necessarily have FD_CLOEXEC
828 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
829 */
830 flags = fcntl(fd, F_GETFD);
831 if (flags == -1 || (flags & FD_CLOEXEC)) {
832 qerror_report(ERROR_CLASS_GENERIC_ERROR,
833 "fd is not valid or already in use");
834 return -1;
835 }
836
837 if (fdset_id < 0) {
838 qerror_report(ERROR_CLASS_GENERIC_ERROR,
839 "set option is required and must be non-negative");
840 return -1;
841 }
842
843#ifdef F_DUPFD_CLOEXEC
844 dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
845#else
846 dupfd = dup(fd);
847 if (dupfd != -1) {
848 qemu_set_cloexec(dupfd);
849 }
850#endif
851 if (dupfd == -1) {
852 qerror_report(ERROR_CLASS_GENERIC_ERROR,
853 "Error duplicating fd: %s", strerror(errno));
854 return -1;
855 }
856
857 /* add the duplicate fd, and optionally the opaque string, to the fd set */
858 monitor_fdset_add_fd(dupfd, true, fdset_id, fd_opaque ? true : false,
859 fd_opaque, NULL);
860
861 return 0;
862}
863
864static int cleanup_add_fd(QemuOpts *opts, void *opaque)
865{
866 int fd;
867
868 fd = qemu_opt_get_number(opts, "fd", -1);
869 close(fd);
870
871 return 0;
872}
873#endif
874
balrog1ae26a12008-09-28 23:19:47 +0000875/***********************************************************/
876/* QEMU Block devices */
877
Markus Armbruster2292dda2011-01-28 11:21:41 +0100878#define HD_OPTS "media=disk"
879#define CDROM_OPTS "media=cdrom"
880#define FD_OPTS ""
881#define PFLASH_OPTS ""
882#define MTD_OPTS ""
883#define SD_OPTS ""
thse4bcb142007-12-02 04:51:10 +0000884
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200885static int drive_init_func(QemuOpts *opts, void *opaque)
886{
Markus Armbrustera803cb82010-06-02 13:31:55 +0200887 int *use_scsi = opaque;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200888
Markus Armbruster319ae522011-01-28 11:21:46 +0100889 return drive_init(opts, *use_scsi) == NULL;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200890}
891
892static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
893{
894 if (NULL == qemu_opt_get(opts, "snapshot")) {
895 qemu_opt_set(opts, "snapshot", "on");
896 }
897 return 0;
898}
899
Markus Armbruster4e5d9b52011-01-28 11:21:45 +0100900static void default_drive(int enable, int snapshot, int use_scsi,
901 BlockInterfaceType type, int index,
902 const char *optstr)
903{
904 QemuOpts *opts;
905
906 if (type == IF_DEFAULT) {
907 type = use_scsi ? IF_SCSI : IF_IDE;
908 }
909
910 if (!enable || drive_get_by_index(type, index)) {
911 return;
912 }
913
914 opts = drive_add(type, index, NULL, optstr);
915 if (snapshot) {
916 drive_enable_snapshot(opts, NULL);
917 }
Markus Armbruster319ae522011-01-28 11:21:46 +0100918 if (!drive_init(opts, use_scsi)) {
Markus Armbruster4e5d9b52011-01-28 11:21:45 +0100919 exit(1);
920 }
921}
922
Jan Kiszka76e30d02009-07-02 00:19:02 +0200923void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
924{
925 boot_set_handler = func;
926 boot_set_opaque = opaque;
927}
928
929int qemu_boot_set(const char *boot_devices)
930{
931 if (!boot_set_handler) {
932 return -EINVAL;
933 }
934 return boot_set_handler(boot_set_opaque, boot_devices);
935}
936
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -0300937static void validate_bootdevices(char *devices)
Jan Kiszkaef3adf62009-07-02 00:19:02 +0200938{
939 /* We just do some generic consistency checks */
940 const char *p;
941 int bitmap = 0;
942
943 for (p = devices; *p != '\0'; p++) {
944 /* Allowed boot devices are:
945 * a-b: floppy disk drives
946 * c-f: IDE disk drives
Dong Xu Wang07f35072011-11-22 18:06:26 +0800947 * g-m: machine implementation dependent drives
Jan Kiszkaef3adf62009-07-02 00:19:02 +0200948 * n-p: network devices
949 * It's up to each machine implementation to check if the given boot
950 * devices match the actual hardware implementation and firmware
951 * features.
952 */
953 if (*p < 'a' || *p > 'p') {
954 fprintf(stderr, "Invalid boot device '%c'\n", *p);
955 exit(1);
956 }
957 if (bitmap & (1 << (*p - 'a'))) {
958 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
959 exit(1);
960 }
961 bitmap |= 1 << (*p - 'a');
962 }
Jan Kiszkaef3adf62009-07-02 00:19:02 +0200963}
964
Jan Kiszkae0f084b2009-07-02 00:19:02 +0200965static void restore_boot_devices(void *opaque)
966{
967 char *standard_boot_devices = opaque;
Alex Williamson37905d62010-04-30 15:21:11 -0600968 static int first = 1;
969
970 /* Restore boot order and remove ourselves after the first boot */
971 if (first) {
972 first = 0;
973 return;
974 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +0200975
976 qemu_boot_set(standard_boot_devices);
977
978 qemu_unregister_reset(restore_boot_devices, standard_boot_devices);
Anthony Liguori7267c092011-08-20 22:09:37 -0500979 g_free(standard_boot_devices);
Jan Kiszkae0f084b2009-07-02 00:19:02 +0200980}
981
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200982void add_boot_device_path(int32_t bootindex, DeviceState *dev,
983 const char *suffix)
984{
985 FWBootEntry *node, *i;
986
987 if (bootindex < 0) {
988 return;
989 }
990
991 assert(dev != NULL || suffix != NULL);
992
Anthony Liguori7267c092011-08-20 22:09:37 -0500993 node = g_malloc0(sizeof(FWBootEntry));
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200994 node->bootindex = bootindex;
Anthony Liguori7267c092011-08-20 22:09:37 -0500995 node->suffix = suffix ? g_strdup(suffix) : NULL;
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200996 node->dev = dev;
997
998 QTAILQ_FOREACH(i, &fw_boot_order, link) {
999 if (i->bootindex == bootindex) {
1000 fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
1001 exit(1);
1002 } else if (i->bootindex < bootindex) {
1003 continue;
1004 }
1005 QTAILQ_INSERT_BEFORE(i, node, link);
1006 return;
1007 }
1008 QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
1009}
1010
Gleb Natapov962630f2010-12-08 13:35:09 +02001011/*
1012 * This function returns null terminated string that consist of new line
Brad Hards71785ab2011-04-23 21:50:06 +10001013 * separated device paths.
Gleb Natapov962630f2010-12-08 13:35:09 +02001014 *
1015 * memory pointed by "size" is assigned total length of the array in bytes
1016 *
1017 */
1018char *get_boot_devices_list(uint32_t *size)
1019{
1020 FWBootEntry *i;
1021 uint32_t total = 0;
1022 char *list = NULL;
1023
1024 QTAILQ_FOREACH(i, &fw_boot_order, link) {
1025 char *devpath = NULL, *bootpath;
1026 int len;
1027
1028 if (i->dev) {
1029 devpath = qdev_get_fw_dev_path(i->dev);
1030 assert(devpath);
1031 }
1032
1033 if (i->suffix && devpath) {
Blue Swirl4fd37a92010-12-19 14:05:43 +00001034 size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
1035
Anthony Liguori7267c092011-08-20 22:09:37 -05001036 bootpath = g_malloc(bootpathlen);
Blue Swirl4fd37a92010-12-19 14:05:43 +00001037 snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
Anthony Liguori7267c092011-08-20 22:09:37 -05001038 g_free(devpath);
Gleb Natapov962630f2010-12-08 13:35:09 +02001039 } else if (devpath) {
1040 bootpath = devpath;
1041 } else {
Markus Armbruster1bf6ccd2011-11-08 10:58:00 +01001042 assert(i->suffix);
Anthony Liguori7267c092011-08-20 22:09:37 -05001043 bootpath = g_strdup(i->suffix);
Gleb Natapov962630f2010-12-08 13:35:09 +02001044 }
1045
1046 if (total) {
1047 list[total-1] = '\n';
1048 }
1049 len = strlen(bootpath) + 1;
Anthony Liguori7267c092011-08-20 22:09:37 -05001050 list = g_realloc(list, total + len);
Gleb Natapov962630f2010-12-08 13:35:09 +02001051 memcpy(&list[total], bootpath, len);
1052 total += len;
Anthony Liguori7267c092011-08-20 22:09:37 -05001053 g_free(bootpath);
Gleb Natapov962630f2010-12-08 13:35:09 +02001054 }
1055
1056 *size = total;
1057
1058 return list;
1059}
1060
aliguori268a3622009-04-21 22:30:27 +00001061static void numa_add(const char *optarg)
1062{
1063 char option[128];
1064 char *endptr;
1065 unsigned long long value, endvalue;
1066 int nodenr;
1067
Chegu Vinodee785fe2012-07-16 21:31:30 -07001068 value = endvalue = 0ULL;
1069
aliguori268a3622009-04-21 22:30:27 +00001070 optarg = get_opt_name(option, 128, optarg, ',') + 1;
1071 if (!strcmp(option, "node")) {
1072 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
1073 nodenr = nb_numa_nodes;
1074 } else {
1075 nodenr = strtoull(option, NULL, 10);
1076 }
1077
1078 if (get_param_value(option, 128, "mem", optarg) == 0) {
1079 node_mem[nodenr] = 0;
1080 } else {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +01001081 int64_t sval;
Markus Armbrusterc03417b2011-11-22 09:46:02 +01001082 sval = strtosz(option, &endptr);
1083 if (sval < 0 || *endptr) {
Jes Sorensen9f9b17a2010-10-21 17:15:46 +02001084 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
1085 exit(1);
aliguori268a3622009-04-21 22:30:27 +00001086 }
Jes Sorensen9f9b17a2010-10-21 17:15:46 +02001087 node_mem[nodenr] = sval;
aliguori268a3622009-04-21 22:30:27 +00001088 }
Chegu Vinodee785fe2012-07-16 21:31:30 -07001089 if (get_param_value(option, 128, "cpus", optarg) != 0) {
aliguori268a3622009-04-21 22:30:27 +00001090 value = strtoull(option, &endptr, 10);
Chegu Vinodee785fe2012-07-16 21:31:30 -07001091 if (*endptr == '-') {
1092 endvalue = strtoull(endptr+1, &endptr, 10);
aliguori268a3622009-04-21 22:30:27 +00001093 } else {
Chegu Vinodee785fe2012-07-16 21:31:30 -07001094 endvalue = value;
aliguori268a3622009-04-21 22:30:27 +00001095 }
Chegu Vinodee785fe2012-07-16 21:31:30 -07001096
1097 if (!(endvalue < MAX_CPUMASK_BITS)) {
1098 endvalue = MAX_CPUMASK_BITS - 1;
1099 fprintf(stderr,
1100 "A max of %d CPUs are supported in a guest\n",
1101 MAX_CPUMASK_BITS);
1102 }
1103
1104 bitmap_set(node_cpumask[nodenr], value, endvalue-value+1);
aliguori268a3622009-04-21 22:30:27 +00001105 }
1106 nb_numa_nodes++;
1107 }
aliguori268a3622009-04-21 22:30:27 +00001108}
1109
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001110static void smp_parse(const char *optarg)
1111{
1112 int smp, sockets = 0, threads = 0, cores = 0;
1113 char *endptr;
1114 char option[128];
1115
1116 smp = strtoul(optarg, &endptr, 10);
1117 if (endptr != optarg) {
1118 if (*endptr == ',') {
1119 endptr++;
1120 }
1121 }
1122 if (get_param_value(option, 128, "sockets", endptr) != 0)
1123 sockets = strtoull(option, NULL, 10);
1124 if (get_param_value(option, 128, "cores", endptr) != 0)
1125 cores = strtoull(option, NULL, 10);
1126 if (get_param_value(option, 128, "threads", endptr) != 0)
1127 threads = strtoull(option, NULL, 10);
1128 if (get_param_value(option, 128, "maxcpus", endptr) != 0)
1129 max_cpus = strtoull(option, NULL, 10);
1130
1131 /* compute missing values, prefer sockets over cores over threads */
1132 if (smp == 0 || sockets == 0) {
1133 sockets = sockets > 0 ? sockets : 1;
1134 cores = cores > 0 ? cores : 1;
1135 threads = threads > 0 ? threads : 1;
1136 if (smp == 0) {
1137 smp = cores * threads * sockets;
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001138 }
1139 } else {
1140 if (cores == 0) {
1141 threads = threads > 0 ? threads : 1;
1142 cores = smp / (sockets * threads);
1143 } else {
Joel Schoppdca98162010-07-21 15:05:17 -05001144 threads = smp / (cores * sockets);
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001145 }
1146 }
1147 smp_cpus = smp;
1148 smp_cores = cores > 0 ? cores : 1;
1149 smp_threads = threads > 0 ? threads : 1;
1150 if (max_cpus == 0)
1151 max_cpus = smp_cpus;
1152}
1153
bellard330d0412003-07-26 18:11:40 +00001154/***********************************************************/
bellarda594cfb2005-11-06 16:13:29 +00001155/* USB devices */
1156
Markus Armbrusterfb080002010-05-28 15:38:44 +02001157static int usb_device_add(const char *devname)
bellarda594cfb2005-11-06 16:13:29 +00001158{
1159 const char *p;
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001160 USBDevice *dev = NULL;
bellarda594cfb2005-11-06 16:13:29 +00001161
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00001162 if (!usb_enabled(false)) {
bellarda594cfb2005-11-06 16:13:29 +00001163 return -1;
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00001164 }
bellarda594cfb2005-11-06 16:13:29 +00001165
Gerd Hoffmann0958b4c2009-10-26 15:56:45 +01001166 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1167 dev = usbdevice_create(devname);
1168 if (dev)
1169 goto done;
1170
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001171 /* the other ones */
Gerd Hoffmanne447fc62011-06-01 14:41:59 +02001172#ifndef CONFIG_LINUX
1173 /* only the linux version is qdev-ified, usb-bsd still needs this */
bellarda594cfb2005-11-06 16:13:29 +00001174 if (strstart(devname, "host:", &p)) {
Jan Kiszka37417152012-02-27 15:18:47 +01001175 dev = usb_host_device_open(usb_bus_find(-1), p);
Gerd Hoffmanne447fc62011-06-01 14:41:59 +02001176 } else
1177#endif
1178 if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
Jan Kiszka37417152012-02-27 15:18:47 +01001179 dev = usb_bt_init(usb_bus_find(-1),
1180 devname[2] ? hci_init(p)
1181 : bt_new_hci(qemu_find_bt_vlan(0)));
bellarda594cfb2005-11-06 16:13:29 +00001182 } else {
1183 return -1;
1184 }
pbrook0d92ed32006-05-21 16:30:15 +00001185 if (!dev)
1186 return -1;
1187
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001188done:
bellarda594cfb2005-11-06 16:13:29 +00001189 return 0;
1190}
1191
aliguori1f3870a2008-08-21 19:27:48 +00001192static int usb_device_del(const char *devname)
1193{
1194 int bus_num, addr;
1195 const char *p;
1196
aliguori5d0c5752008-09-14 01:07:41 +00001197 if (strstart(devname, "host:", &p))
1198 return usb_host_device_close(p);
1199
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00001200 if (!usb_enabled(false)) {
aliguori1f3870a2008-08-21 19:27:48 +00001201 return -1;
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00001202 }
aliguori1f3870a2008-08-21 19:27:48 +00001203
1204 p = strchr(devname, '.');
1205 if (!p)
1206 return -1;
1207 bus_num = strtoul(devname, NULL, 0);
1208 addr = strtoul(p + 1, NULL, 0);
1209
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001210 return usb_device_delete_addr(bus_num, addr);
aliguori1f3870a2008-08-21 19:27:48 +00001211}
1212
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001213static int usb_parse(const char *cmdline)
1214{
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001215 int r;
Markus Armbrusterfb080002010-05-28 15:38:44 +02001216 r = usb_device_add(cmdline);
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001217 if (r < 0) {
1218 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
1219 }
1220 return r;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001221}
1222
Luiz Capitulinod54908a2009-08-28 15:27:13 -03001223void do_usb_add(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +00001224{
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001225 const char *devname = qdict_get_str(qdict, "devname");
Markus Armbrusterfb080002010-05-28 15:38:44 +02001226 if (usb_device_add(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +01001227 error_report("could not add USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001228 }
bellarda594cfb2005-11-06 16:13:29 +00001229}
1230
Luiz Capitulinod54908a2009-08-28 15:27:13 -03001231void do_usb_del(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +00001232{
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001233 const char *devname = qdict_get_str(qdict, "devname");
1234 if (usb_device_del(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +01001235 error_report("could not delete USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001236 }
bellarda594cfb2005-11-06 16:13:29 +00001237}
1238
bellardf7cce892004-12-08 22:21:25 +00001239/***********************************************************/
balrog201a51f2007-04-30 00:51:09 +00001240/* PCMCIA/Cardbus */
1241
1242static struct pcmcia_socket_entry_s {
Paul Brookbc24a222009-05-10 01:44:56 +01001243 PCMCIASocket *socket;
balrog201a51f2007-04-30 00:51:09 +00001244 struct pcmcia_socket_entry_s *next;
1245} *pcmcia_sockets = 0;
1246
Paul Brookbc24a222009-05-10 01:44:56 +01001247void pcmcia_socket_register(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +00001248{
1249 struct pcmcia_socket_entry_s *entry;
1250
Anthony Liguori7267c092011-08-20 22:09:37 -05001251 entry = g_malloc(sizeof(struct pcmcia_socket_entry_s));
balrog201a51f2007-04-30 00:51:09 +00001252 entry->socket = socket;
1253 entry->next = pcmcia_sockets;
1254 pcmcia_sockets = entry;
1255}
1256
Paul Brookbc24a222009-05-10 01:44:56 +01001257void pcmcia_socket_unregister(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +00001258{
1259 struct pcmcia_socket_entry_s *entry, **ptr;
1260
1261 ptr = &pcmcia_sockets;
1262 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1263 if (entry->socket == socket) {
1264 *ptr = entry->next;
Anthony Liguori7267c092011-08-20 22:09:37 -05001265 g_free(entry);
balrog201a51f2007-04-30 00:51:09 +00001266 }
1267}
1268
aliguori376253e2009-03-05 23:01:23 +00001269void pcmcia_info(Monitor *mon)
balrog201a51f2007-04-30 00:51:09 +00001270{
1271 struct pcmcia_socket_entry_s *iter;
aliguori376253e2009-03-05 23:01:23 +00001272
balrog201a51f2007-04-30 00:51:09 +00001273 if (!pcmcia_sockets)
aliguori376253e2009-03-05 23:01:23 +00001274 monitor_printf(mon, "No PCMCIA sockets\n");
balrog201a51f2007-04-30 00:51:09 +00001275
1276 for (iter = pcmcia_sockets; iter; iter = iter->next)
aliguori376253e2009-03-05 23:01:23 +00001277 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1278 iter->socket->attached ? iter->socket->card_string :
1279 "Empty");
balrog201a51f2007-04-30 00:51:09 +00001280}
1281
1282/***********************************************************/
bellardcc1daa42005-06-05 14:49:17 +00001283/* machine registration */
1284
blueswir1bdaf78e2008-10-04 07:24:27 +00001285static QEMUMachine *first_machine = NULL;
aliguori6f338c32009-02-11 15:21:54 +00001286QEMUMachine *current_machine = NULL;
bellardcc1daa42005-06-05 14:49:17 +00001287
1288int qemu_register_machine(QEMUMachine *m)
1289{
1290 QEMUMachine **pm;
1291 pm = &first_machine;
1292 while (*pm != NULL)
1293 pm = &(*pm)->next;
1294 m->next = NULL;
1295 *pm = m;
1296 return 0;
1297}
1298
pbrook9596ebb2007-11-18 01:44:38 +00001299static QEMUMachine *find_machine(const char *name)
bellardcc1daa42005-06-05 14:49:17 +00001300{
1301 QEMUMachine *m;
1302
1303 for(m = first_machine; m != NULL; m = m->next) {
1304 if (!strcmp(m->name, name))
1305 return m;
Mark McLoughlin3f6599e2009-07-22 10:02:50 +01001306 if (m->alias && !strcmp(m->alias, name))
1307 return m;
bellardcc1daa42005-06-05 14:49:17 +00001308 }
1309 return NULL;
1310}
1311
Jordan Justen2c8cffa2012-02-21 23:18:50 -08001312QEMUMachine *find_default_machine(void)
Anthony Liguori0c257432009-05-21 20:41:01 -05001313{
1314 QEMUMachine *m;
1315
1316 for(m = first_machine; m != NULL; m = m->next) {
1317 if (m->is_default) {
1318 return m;
1319 }
1320 }
1321 return NULL;
1322}
1323
Anthony Liguori01d3c802012-08-10 11:04:11 -05001324MachineInfoList *qmp_query_machines(Error **errp)
1325{
1326 MachineInfoList *mach_list = NULL;
1327 QEMUMachine *m;
1328
1329 for (m = first_machine; m; m = m->next) {
1330 MachineInfoList *entry;
1331 MachineInfo *info;
1332
1333 info = g_malloc0(sizeof(*info));
1334 if (m->is_default) {
1335 info->has_is_default = true;
1336 info->is_default = true;
1337 }
1338
1339 if (m->alias) {
1340 info->has_alias = true;
1341 info->alias = g_strdup(m->alias);
1342 }
1343
1344 info->name = g_strdup(m->name);
1345
1346 entry = g_malloc0(sizeof(*entry));
1347 entry->value = info;
1348 entry->next = mach_list;
1349 mach_list = entry;
1350 }
1351
1352 return mach_list;
1353}
1354
bellardcc1daa42005-06-05 14:49:17 +00001355/***********************************************************/
bellard8a7ddc32004-03-31 19:00:16 +00001356/* main execution loop */
1357
pbrook9596ebb2007-11-18 01:44:38 +00001358static void gui_update(void *opaque)
bellard8a7ddc32004-03-31 19:00:16 +00001359{
aliguori7d957bd2009-01-15 22:14:11 +00001360 uint64_t interval = GUI_REFRESH_INTERVAL;
ths740733b2007-06-08 01:57:56 +00001361 DisplayState *ds = opaque;
aliguori7d957bd2009-01-15 22:14:11 +00001362 DisplayChangeListener *dcl = ds->listeners;
1363
1364 dpy_refresh(ds);
1365
1366 while (dcl != NULL) {
1367 if (dcl->gui_timer_interval &&
1368 dcl->gui_timer_interval < interval)
1369 interval = dcl->gui_timer_interval;
1370 dcl = dcl->next;
1371 }
Paolo Bonzini7bd427d2011-03-11 16:47:48 +01001372 qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock));
bellard8a7ddc32004-03-31 19:00:16 +00001373}
1374
bellard0bd48852005-11-11 00:00:47 +00001375struct vm_change_state_entry {
1376 VMChangeStateHandler *cb;
1377 void *opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001378 QLIST_ENTRY (vm_change_state_entry) entries;
bellard0bd48852005-11-11 00:00:47 +00001379};
1380
Blue Swirl72cf2d42009-09-12 07:36:22 +00001381static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
bellard0bd48852005-11-11 00:00:47 +00001382
1383VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1384 void *opaque)
1385{
1386 VMChangeStateEntry *e;
1387
Anthony Liguori7267c092011-08-20 22:09:37 -05001388 e = g_malloc0(sizeof (*e));
bellard0bd48852005-11-11 00:00:47 +00001389
1390 e->cb = cb;
1391 e->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001392 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
bellard0bd48852005-11-11 00:00:47 +00001393 return e;
1394}
1395
1396void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1397{
Blue Swirl72cf2d42009-09-12 07:36:22 +00001398 QLIST_REMOVE (e, entries);
Anthony Liguori7267c092011-08-20 22:09:37 -05001399 g_free (e);
bellard0bd48852005-11-11 00:00:47 +00001400}
1401
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001402void vm_state_notify(int running, RunState state)
bellard0bd48852005-11-11 00:00:47 +00001403{
1404 VMChangeStateEntry *e;
1405
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001406 trace_vm_state_notify(running, state);
Stefan Hajnoczi94b0b5f2010-11-16 12:20:25 +00001407
bellard0bd48852005-11-11 00:00:47 +00001408 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001409 e->cb(e->opaque, running, state);
bellard0bd48852005-11-11 00:00:47 +00001410 }
1411}
1412
bellard8a7ddc32004-03-31 19:00:16 +00001413void vm_start(void)
1414{
Luiz Capitulino13548692011-07-29 15:36:43 -03001415 if (!runstate_is_running()) {
bellard8a7ddc32004-03-31 19:00:16 +00001416 cpu_enable_ticks();
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001417 runstate_set(RUN_STATE_RUNNING);
1418 vm_state_notify(1, RUN_STATE_RUNNING);
aliguorid6dc3d42009-04-24 18:04:07 +00001419 resume_all_vcpus();
Luiz Capitulino6ed2c482010-04-27 20:35:59 -03001420 monitor_protocol_event(QEVENT_RESUME, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00001421 }
1422}
1423
bellardbb0c6722004-06-20 12:37:32 +00001424/* reset/shutdown handler */
1425
1426typedef struct QEMUResetEntry {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001427 QTAILQ_ENTRY(QEMUResetEntry) entry;
bellardbb0c6722004-06-20 12:37:32 +00001428 QEMUResetHandler *func;
1429 void *opaque;
bellardbb0c6722004-06-20 12:37:32 +00001430} QEMUResetEntry;
1431
Blue Swirl72cf2d42009-09-12 07:36:22 +00001432static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1433 QTAILQ_HEAD_INITIALIZER(reset_handlers);
bellardbb0c6722004-06-20 12:37:32 +00001434static int reset_requested;
Gleb Natapovf64622c2011-03-15 13:56:04 +02001435static int shutdown_requested, shutdown_signal = -1;
1436static pid_t shutdown_pid;
bellard34751872005-07-02 14:31:34 +00001437static int powerdown_requested;
Jan Kiszka8cf71712011-02-07 12:19:16 +01001438static int debug_requested;
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001439static int suspend_requested;
Luiz Capitulino14058192012-08-08 17:29:17 -03001440static int wakeup_requested;
Igor Mammedova9552c82012-09-05 23:06:21 +02001441static NotifierList powerdown_notifiers =
1442 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001443static NotifierList suspend_notifiers =
1444 NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
1445static NotifierList wakeup_notifiers =
1446 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
1447static uint32_t wakeup_reason_mask = ~0;
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001448static RunState vmstop_requested = RUN_STATE_MAX;
bellardbb0c6722004-06-20 12:37:32 +00001449
Anthony PERARD1291eb32010-07-22 15:52:48 +01001450int qemu_shutdown_requested_get(void)
1451{
1452 return shutdown_requested;
1453}
1454
1455int qemu_reset_requested_get(void)
1456{
1457 return reset_requested;
1458}
1459
aurel32cf7a2fe2008-03-18 06:53:05 +00001460int qemu_shutdown_requested(void)
1461{
1462 int r = shutdown_requested;
1463 shutdown_requested = 0;
1464 return r;
1465}
1466
Gleb Natapovf64622c2011-03-15 13:56:04 +02001467void qemu_kill_report(void)
1468{
Anthony Liguoric7f0f3b2012-03-28 15:42:02 +02001469 if (!qtest_enabled() && shutdown_signal != -1) {
Peter Maydellf1d3fb02011-03-30 22:03:38 +01001470 fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal);
1471 if (shutdown_pid == 0) {
1472 /* This happens for eg ^C at the terminal, so it's worth
1473 * avoiding printing an odd message in that case.
1474 */
1475 fputc('\n', stderr);
1476 } else {
Andreas Färber953ffe02011-06-02 19:58:06 +02001477 fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid);
Peter Maydellf1d3fb02011-03-30 22:03:38 +01001478 }
Gleb Natapovf64622c2011-03-15 13:56:04 +02001479 shutdown_signal = -1;
1480 }
1481}
1482
aurel32cf7a2fe2008-03-18 06:53:05 +00001483int qemu_reset_requested(void)
1484{
1485 int r = reset_requested;
1486 reset_requested = 0;
1487 return r;
1488}
1489
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001490static int qemu_suspend_requested(void)
1491{
1492 int r = suspend_requested;
1493 suspend_requested = 0;
1494 return r;
1495}
1496
Luiz Capitulino14058192012-08-08 17:29:17 -03001497static int qemu_wakeup_requested(void)
1498{
1499 int r = wakeup_requested;
1500 wakeup_requested = 0;
1501 return r;
1502}
1503
aurel32cf7a2fe2008-03-18 06:53:05 +00001504int qemu_powerdown_requested(void)
1505{
1506 int r = powerdown_requested;
1507 powerdown_requested = 0;
1508 return r;
1509}
1510
aliguorie5689022009-04-24 18:03:54 +00001511static int qemu_debug_requested(void)
1512{
1513 int r = debug_requested;
1514 debug_requested = 0;
1515 return r;
1516}
1517
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001518/* We use RUN_STATE_MAX but any invalid value will do */
Luiz Capitulino0d45b702011-09-30 14:27:11 -03001519static bool qemu_vmstop_requested(RunState *r)
aliguori6e29f5d2009-04-24 18:04:02 +00001520{
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001521 if (vmstop_requested < RUN_STATE_MAX) {
Luiz Capitulino0d45b702011-09-30 14:27:11 -03001522 *r = vmstop_requested;
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001523 vmstop_requested = RUN_STATE_MAX;
Luiz Capitulino0d45b702011-09-30 14:27:11 -03001524 return true;
1525 }
1526
1527 return false;
aliguori6e29f5d2009-04-24 18:04:02 +00001528}
1529
Jan Kiszkaa08d4362009-06-27 09:25:07 +02001530void qemu_register_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001531{
Anthony Liguori7267c092011-08-20 22:09:37 -05001532 QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
bellardbb0c6722004-06-20 12:37:32 +00001533
bellardbb0c6722004-06-20 12:37:32 +00001534 re->func = func;
1535 re->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001536 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
bellardbb0c6722004-06-20 12:37:32 +00001537}
1538
Jan Kiszkadda9b292009-07-02 00:19:02 +02001539void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001540{
1541 QEMUResetEntry *re;
1542
Blue Swirl72cf2d42009-09-12 07:36:22 +00001543 QTAILQ_FOREACH(re, &reset_handlers, entry) {
Jan Kiszkadda9b292009-07-02 00:19:02 +02001544 if (re->func == func && re->opaque == opaque) {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001545 QTAILQ_REMOVE(&reset_handlers, re, entry);
Anthony Liguori7267c092011-08-20 22:09:37 -05001546 g_free(re);
Jan Kiszkadda9b292009-07-02 00:19:02 +02001547 return;
1548 }
1549 }
1550}
1551
David Gibsonbe522022012-08-07 16:41:51 +10001552void qemu_devices_reset(void)
Jan Kiszkadda9b292009-07-02 00:19:02 +02001553{
1554 QEMUResetEntry *re, *nre;
1555
1556 /* reset all devices */
Blue Swirl72cf2d42009-09-12 07:36:22 +00001557 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
bellardbb0c6722004-06-20 12:37:32 +00001558 re->func(re->opaque);
1559 }
David Gibsonbe522022012-08-07 16:41:51 +10001560}
1561
1562void qemu_system_reset(bool report)
1563{
1564 if (current_machine && current_machine->reset) {
1565 current_machine->reset();
1566 } else {
1567 qemu_devices_reset();
1568 }
Jan Kiszkae063eb12011-06-14 18:29:43 +02001569 if (report) {
1570 monitor_protocol_event(QEVENT_RESET, NULL);
1571 }
Jan Kiszkaea375f92010-03-01 19:10:30 +01001572 cpu_synchronize_all_post_reset();
bellardbb0c6722004-06-20 12:37:32 +00001573}
1574
1575void qemu_system_reset_request(void)
1576{
bellardd1beab82006-10-02 19:44:22 +00001577 if (no_reboot) {
1578 shutdown_requested = 1;
1579 } else {
1580 reset_requested = 1;
1581 }
Jan Kiszkab4a3d962011-02-01 22:15:43 +01001582 cpu_stop_current();
aliguorid9f75a42009-04-24 18:03:11 +00001583 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001584}
1585
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001586static void qemu_system_suspend(void)
1587{
1588 pause_all_vcpus();
1589 notifier_list_notify(&suspend_notifiers, NULL);
Luiz Capitulinoad02b962012-04-27 13:33:36 -03001590 runstate_set(RUN_STATE_SUSPENDED);
Gerd Hoffmann53370b72012-02-23 13:45:26 +01001591 monitor_protocol_event(QEVENT_SUSPEND, NULL);
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001592}
1593
1594void qemu_system_suspend_request(void)
1595{
Luiz Capitulino9abc62f2012-04-27 14:31:12 -03001596 if (runstate_check(RUN_STATE_SUSPENDED)) {
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001597 return;
1598 }
1599 suspend_requested = 1;
1600 cpu_stop_current();
1601 qemu_notify_event();
1602}
1603
1604void qemu_register_suspend_notifier(Notifier *notifier)
1605{
1606 notifier_list_add(&suspend_notifiers, notifier);
1607}
1608
1609void qemu_system_wakeup_request(WakeupReason reason)
1610{
Luiz Capitulino9abc62f2012-04-27 14:31:12 -03001611 if (!runstate_check(RUN_STATE_SUSPENDED)) {
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001612 return;
1613 }
1614 if (!(wakeup_reason_mask & (1 << reason))) {
1615 return;
1616 }
Luiz Capitulinoad02b962012-04-27 13:33:36 -03001617 runstate_set(RUN_STATE_RUNNING);
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001618 notifier_list_notify(&wakeup_notifiers, &reason);
Luiz Capitulino14058192012-08-08 17:29:17 -03001619 wakeup_requested = 1;
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001620 qemu_notify_event();
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001621}
1622
1623void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
1624{
1625 if (enabled) {
1626 wakeup_reason_mask |= (1 << reason);
1627 } else {
1628 wakeup_reason_mask &= ~(1 << reason);
1629 }
1630}
1631
1632void qemu_register_wakeup_notifier(Notifier *notifier)
1633{
1634 notifier_list_add(&wakeup_notifiers, notifier);
1635}
1636
Gleb Natapovf64622c2011-03-15 13:56:04 +02001637void qemu_system_killed(int signal, pid_t pid)
1638{
1639 shutdown_signal = signal;
1640 shutdown_pid = pid;
Kevin Wolfd9389b92011-09-14 15:38:40 +02001641 no_shutdown = 0;
Gleb Natapovf64622c2011-03-15 13:56:04 +02001642 qemu_system_shutdown_request();
1643}
1644
bellardbb0c6722004-06-20 12:37:32 +00001645void qemu_system_shutdown_request(void)
1646{
1647 shutdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001648 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001649}
1650
Igor Mammedov013c2f12012-09-05 23:06:25 +02001651static void qemu_system_powerdown(void)
1652{
1653 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
1654 notifier_list_notify(&powerdown_notifiers, NULL);
1655}
1656
bellard34751872005-07-02 14:31:34 +00001657void qemu_system_powerdown_request(void)
1658{
1659 powerdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001660 qemu_notify_event();
1661}
1662
Igor Mammedova9552c82012-09-05 23:06:21 +02001663void qemu_register_powerdown_notifier(Notifier *notifier)
1664{
1665 notifier_list_add(&powerdown_notifiers, notifier);
1666}
1667
Jan Kiszka8cf71712011-02-07 12:19:16 +01001668void qemu_system_debug_request(void)
1669{
1670 debug_requested = 1;
Jan Kiszka83f338f2011-02-07 12:19:17 +01001671 qemu_notify_event();
Jan Kiszka8cf71712011-02-07 12:19:16 +01001672}
1673
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001674void qemu_system_vmstop_request(RunState state)
Jan Kiszka8cf71712011-02-07 12:19:16 +01001675{
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001676 vmstop_requested = state;
Jan Kiszka8cf71712011-02-07 12:19:16 +01001677 qemu_notify_event();
1678}
1679
Paolo Bonzini99435902011-09-12 14:03:13 +02001680static bool main_loop_should_exit(void)
1681{
1682 RunState r;
1683 if (qemu_debug_requested()) {
1684 vm_stop(RUN_STATE_DEBUG);
1685 }
Gerd Hoffmann95b363b2012-02-23 13:45:19 +01001686 if (qemu_suspend_requested()) {
1687 qemu_system_suspend();
1688 }
Paolo Bonzini99435902011-09-12 14:03:13 +02001689 if (qemu_shutdown_requested()) {
1690 qemu_kill_report();
1691 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
1692 if (no_shutdown) {
1693 vm_stop(RUN_STATE_SHUTDOWN);
1694 } else {
1695 return true;
1696 }
1697 }
1698 if (qemu_reset_requested()) {
1699 pause_all_vcpus();
1700 cpu_synchronize_all_states();
1701 qemu_system_reset(VMRESET_REPORT);
1702 resume_all_vcpus();
1703 if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
1704 runstate_check(RUN_STATE_SHUTDOWN)) {
1705 runstate_set(RUN_STATE_PAUSED);
1706 }
1707 }
Luiz Capitulino14058192012-08-08 17:29:17 -03001708 if (qemu_wakeup_requested()) {
1709 pause_all_vcpus();
1710 cpu_synchronize_all_states();
1711 qemu_system_reset(VMRESET_SILENT);
1712 resume_all_vcpus();
Luiz Capitulino17c86602012-08-09 11:27:30 -03001713 monitor_protocol_event(QEVENT_WAKEUP, NULL);
Luiz Capitulino14058192012-08-08 17:29:17 -03001714 }
Paolo Bonzini99435902011-09-12 14:03:13 +02001715 if (qemu_powerdown_requested()) {
Igor Mammedov013c2f12012-09-05 23:06:25 +02001716 qemu_system_powerdown();
Paolo Bonzini99435902011-09-12 14:03:13 +02001717 }
1718 if (qemu_vmstop_requested(&r)) {
1719 vm_stop(r);
1720 }
1721 return false;
1722}
1723
aliguori43b96852009-04-24 18:03:33 +00001724static void main_loop(void)
1725{
Jan Kiszkac9f711a2011-08-22 17:46:02 +02001726 bool nonblocking;
Paolo Bonzini99435902011-09-12 14:03:13 +02001727 int last_io = 0;
Jan Kiszka8e1b90e2011-02-01 22:15:46 +01001728#ifdef CONFIG_PROFILER
1729 int64_t ti;
1730#endif
Paolo Bonzini99435902011-09-12 14:03:13 +02001731 do {
Jan Kiszkac9f711a2011-08-22 17:46:02 +02001732 nonblocking = !kvm_enabled() && last_io > 0;
aliguori43b96852009-04-24 18:03:33 +00001733#ifdef CONFIG_PROFILER
Jan Kiszka46481d32011-02-01 22:15:47 +01001734 ti = profile_getclock();
aliguori43b96852009-04-24 18:03:33 +00001735#endif
Jan Kiszkac9f711a2011-08-22 17:46:02 +02001736 last_io = main_loop_wait(nonblocking);
aliguori43b96852009-04-24 18:03:33 +00001737#ifdef CONFIG_PROFILER
Jan Kiszka46481d32011-02-01 22:15:47 +01001738 dev_time += profile_getclock() - ti;
aliguori43b96852009-04-24 18:03:33 +00001739#endif
Paolo Bonzini99435902011-09-12 14:03:13 +02001740 } while (!main_loop_should_exit());
bellardb4608c02003-06-27 17:34:32 +00001741}
1742
pbrook9bd7e6d2009-04-07 22:58:45 +00001743static void version(void)
1744{
Thomas Monjalonf75ca1a2010-04-28 14:42:01 +02001745 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
pbrook9bd7e6d2009-04-07 22:58:45 +00001746}
1747
ths15f82202007-06-29 23:26:08 +00001748static void help(int exitcode)
bellard0824d6f2003-06-24 13:42:40 +00001749{
Michael Ellermana3adb7a2011-12-19 17:19:31 +11001750 version();
1751 printf("usage: %s [options] [disk_image]\n\n"
1752 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1753 error_get_progname());
1754
Michael Ellerman77bd1112011-12-19 17:19:30 +11001755#define QEMU_OPTIONS_GENERATE_HELP
1756#include "qemu-options-wrapper.h"
Michael Ellermana3adb7a2011-12-19 17:19:31 +11001757
1758 printf("\nDuring emulation, the following keys are useful:\n"
malc3f020d72010-02-08 12:04:56 +03001759 "ctrl-alt-f toggle full screen\n"
1760 "ctrl-alt-n switch to virtual console 'n'\n"
1761 "ctrl-alt toggle mouse and keyboard grab\n"
1762 "\n"
Michael Ellermana3adb7a2011-12-19 17:19:31 +11001763 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1764
ths15f82202007-06-29 23:26:08 +00001765 exit(exitcode);
bellard0824d6f2003-06-24 13:42:40 +00001766}
1767
bellardcd6f1162004-05-13 22:02:20 +00001768#define HAS_ARG 0x0001
1769
bellardcd6f1162004-05-13 22:02:20 +00001770typedef struct QEMUOption {
1771 const char *name;
1772 int flags;
1773 int index;
Blue Swirlad960902010-03-29 19:23:52 +00001774 uint32_t arch_mask;
bellardcd6f1162004-05-13 22:02:20 +00001775} QEMUOption;
1776
blueswir1dbed7e42008-10-01 19:38:09 +00001777static const QEMUOption qemu_options[] = {
Blue Swirlad960902010-03-29 19:23:52 +00001778 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
Michael Ellerman77bd1112011-12-19 17:19:30 +11001779#define QEMU_OPTIONS_GENERATE_OPTIONS
1780#include "qemu-options-wrapper.h"
bellardcd6f1162004-05-13 22:02:20 +00001781 { NULL },
bellardfc01f7e2003-06-30 10:03:06 +00001782};
Blue Swirla369da52011-09-27 19:15:42 +00001783
1784static bool vga_available(void)
1785{
Aurelien Jarno36b7f272012-09-08 16:01:20 +02001786 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
Blue Swirla369da52011-09-27 19:15:42 +00001787}
1788
1789static bool cirrus_vga_available(void)
1790{
Aurelien Jarno36b7f272012-09-08 16:01:20 +02001791 return object_class_by_name("cirrus-vga")
1792 || object_class_by_name("isa-cirrus-vga");
Blue Swirla369da52011-09-27 19:15:42 +00001793}
1794
1795static bool vmware_vga_available(void)
1796{
Aurelien Jarno36b7f272012-09-08 16:01:20 +02001797 return object_class_by_name("vmware-svga");
Blue Swirla369da52011-09-27 19:15:42 +00001798}
1799
Aurelien Jarno879049a2012-09-08 12:01:06 +02001800static bool qxl_vga_available(void)
1801{
1802 return object_class_by_name("qxl-vga");
1803}
1804
malc3893c122008-09-28 00:42:05 +00001805static void select_vgahw (const char *p)
1806{
1807 const char *opts;
1808
Zachary Amsden86176752009-07-30 00:15:02 -10001809 vga_interface_type = VGA_NONE;
malc3893c122008-09-28 00:42:05 +00001810 if (strstart(p, "std", &opts)) {
Blue Swirla369da52011-09-27 19:15:42 +00001811 if (vga_available()) {
1812 vga_interface_type = VGA_STD;
1813 } else {
1814 fprintf(stderr, "Error: standard VGA not available\n");
1815 exit(0);
1816 }
malc3893c122008-09-28 00:42:05 +00001817 } else if (strstart(p, "cirrus", &opts)) {
Blue Swirla369da52011-09-27 19:15:42 +00001818 if (cirrus_vga_available()) {
1819 vga_interface_type = VGA_CIRRUS;
1820 } else {
1821 fprintf(stderr, "Error: Cirrus VGA not available\n");
1822 exit(0);
1823 }
malc3893c122008-09-28 00:42:05 +00001824 } else if (strstart(p, "vmware", &opts)) {
Blue Swirla369da52011-09-27 19:15:42 +00001825 if (vmware_vga_available()) {
1826 vga_interface_type = VGA_VMWARE;
1827 } else {
1828 fprintf(stderr, "Error: VMWare SVGA not available\n");
1829 exit(0);
1830 }
aliguori94909d92009-04-22 15:19:53 +00001831 } else if (strstart(p, "xenfb", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001832 vga_interface_type = VGA_XENFB;
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +02001833 } else if (strstart(p, "qxl", &opts)) {
Aurelien Jarno879049a2012-09-08 12:01:06 +02001834 if (qxl_vga_available()) {
1835 vga_interface_type = VGA_QXL;
1836 } else {
1837 fprintf(stderr, "Error: QXL VGA not available\n");
1838 exit(0);
1839 }
aliguori28b85ed2009-04-22 15:19:48 +00001840 } else if (!strstart(p, "none", &opts)) {
malc3893c122008-09-28 00:42:05 +00001841 invalid_vga:
1842 fprintf(stderr, "Unknown vga type: %s\n", p);
1843 exit(1);
1844 }
malccb5a7aa2008-09-28 00:42:12 +00001845 while (*opts) {
1846 const char *nextopt;
1847
1848 if (strstart(opts, ",retrace=", &nextopt)) {
1849 opts = nextopt;
1850 if (strstart(opts, "dumb", &nextopt))
1851 vga_retrace_method = VGA_RETRACE_DUMB;
1852 else if (strstart(opts, "precise", &nextopt))
1853 vga_retrace_method = VGA_RETRACE_PRECISE;
1854 else goto invalid_vga;
1855 } else goto invalid_vga;
1856 opts = nextopt;
1857 }
malc3893c122008-09-28 00:42:05 +00001858}
1859
Jes Sorensen1472a952011-03-16 13:33:31 +01001860static DisplayType select_display(const char *p)
1861{
1862 const char *opts;
1863 DisplayType display = DT_DEFAULT;
1864
1865 if (strstart(p, "sdl", &opts)) {
1866#ifdef CONFIG_SDL
1867 display = DT_SDL;
1868 while (*opts) {
1869 const char *nextopt;
1870
1871 if (strstart(opts, ",frame=", &nextopt)) {
1872 opts = nextopt;
1873 if (strstart(opts, "on", &nextopt)) {
1874 no_frame = 0;
1875 } else if (strstart(opts, "off", &nextopt)) {
1876 no_frame = 1;
1877 } else {
Peter Maydell05175532011-03-23 03:40:57 +00001878 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01001879 }
1880 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
1881 opts = nextopt;
1882 if (strstart(opts, "on", &nextopt)) {
1883 alt_grab = 1;
1884 } else if (strstart(opts, "off", &nextopt)) {
1885 alt_grab = 0;
1886 } else {
Peter Maydell05175532011-03-23 03:40:57 +00001887 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01001888 }
1889 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
1890 opts = nextopt;
1891 if (strstart(opts, "on", &nextopt)) {
1892 ctrl_grab = 1;
1893 } else if (strstart(opts, "off", &nextopt)) {
1894 ctrl_grab = 0;
1895 } else {
Peter Maydell05175532011-03-23 03:40:57 +00001896 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01001897 }
1898 } else if (strstart(opts, ",window_close=", &nextopt)) {
1899 opts = nextopt;
1900 if (strstart(opts, "on", &nextopt)) {
1901 no_quit = 0;
1902 } else if (strstart(opts, "off", &nextopt)) {
1903 no_quit = 1;
1904 } else {
Peter Maydell05175532011-03-23 03:40:57 +00001905 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01001906 }
1907 } else {
Peter Maydell05175532011-03-23 03:40:57 +00001908 invalid_sdl_args:
1909 fprintf(stderr, "Invalid SDL option string: %s\n", p);
1910 exit(1);
Jes Sorensen1472a952011-03-16 13:33:31 +01001911 }
1912 opts = nextopt;
1913 }
1914#else
1915 fprintf(stderr, "SDL support is disabled\n");
1916 exit(1);
1917#endif
Jes Sorensen3264ff12011-03-16 13:33:33 +01001918 } else if (strstart(p, "vnc", &opts)) {
Jes Sorensen821601e2011-03-16 13:33:36 +01001919#ifdef CONFIG_VNC
Jes Sorensen3264ff12011-03-16 13:33:33 +01001920 display_remote++;
1921
1922 if (*opts) {
1923 const char *nextopt;
1924
1925 if (strstart(opts, "=", &nextopt)) {
1926 vnc_display = nextopt;
1927 }
1928 }
1929 if (!vnc_display) {
1930 fprintf(stderr, "VNC requires a display argument vnc=<display>\n");
1931 exit(1);
1932 }
Jes Sorensen821601e2011-03-16 13:33:36 +01001933#else
1934 fprintf(stderr, "VNC support is disabled\n");
1935 exit(1);
1936#endif
Jes Sorensen1472a952011-03-16 13:33:31 +01001937 } else if (strstart(p, "curses", &opts)) {
1938#ifdef CONFIG_CURSES
1939 display = DT_CURSES;
1940#else
1941 fprintf(stderr, "Curses support is disabled\n");
1942 exit(1);
1943#endif
Jes Sorensen4171d322011-03-16 13:33:32 +01001944 } else if (strstart(p, "none", &opts)) {
1945 display = DT_NONE;
Jes Sorensen1472a952011-03-16 13:33:31 +01001946 } else {
Jes Sorensen1472a952011-03-16 13:33:31 +01001947 fprintf(stderr, "Unknown display type: %s\n", p);
1948 exit(1);
1949 }
1950
1951 return display;
1952}
1953
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001954static int balloon_parse(const char *arg)
1955{
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001956 QemuOpts *opts;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001957
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001958 if (strcmp(arg, "none") == 0) {
1959 return 0;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001960 }
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001961
1962 if (!strncmp(arg, "virtio", 6)) {
1963 if (arg[6] == ',') {
1964 /* have params -> parse them */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001965 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001966 if (!opts)
1967 return -1;
1968 } else {
1969 /* create empty opts */
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03001970 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, NULL);
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001971 }
Alexander Graf29f82b32011-03-29 15:29:29 +02001972 qemu_opt_set(opts, "driver", "virtio-balloon");
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001973 return 0;
1974 }
1975
1976 return -1;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001977}
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001978
Paul Brook5cea8592009-05-30 00:52:44 +01001979char *qemu_find_file(int type, const char *name)
1980{
1981 int len;
1982 const char *subdir;
1983 char *buf;
1984
Peter Maydell31783202012-05-25 13:07:01 +01001985 /* Try the name as a straight path first */
1986 if (access(name, R_OK) == 0) {
Anthony Liguori7267c092011-08-20 22:09:37 -05001987 return g_strdup(name);
Paul Brook5cea8592009-05-30 00:52:44 +01001988 }
1989 switch (type) {
1990 case QEMU_FILE_TYPE_BIOS:
1991 subdir = "";
1992 break;
1993 case QEMU_FILE_TYPE_KEYMAP:
1994 subdir = "keymaps/";
1995 break;
1996 default:
1997 abort();
1998 }
1999 len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
Anthony Liguori7267c092011-08-20 22:09:37 -05002000 buf = g_malloc0(len);
Blue Swirl3a417592009-06-09 19:12:21 +00002001 snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
Paul Brook5cea8592009-05-30 00:52:44 +01002002 if (access(buf, R_OK)) {
Anthony Liguori7267c092011-08-20 22:09:37 -05002003 g_free(buf);
Paul Brook5cea8592009-05-30 00:52:44 +01002004 return NULL;
2005 }
2006 return buf;
2007}
2008
Markus Armbrusterff952ba2010-01-29 19:48:57 +01002009static int device_help_func(QemuOpts *opts, void *opaque)
2010{
2011 return qdev_device_help(opts);
2012}
2013
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02002014static int device_init_func(QemuOpts *opts, void *opaque)
2015{
2016 DeviceState *dev;
2017
2018 dev = qdev_device_add(opts);
2019 if (!dev)
2020 return -1;
2021 return 0;
2022}
2023
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002024static int chardev_init_func(QemuOpts *opts, void *opaque)
2025{
2026 CharDriverState *chr;
2027
Anthony Liguorif69554b2011-08-15 11:17:37 -05002028 chr = qemu_chr_new_from_opts(opts, NULL);
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002029 if (!chr)
2030 return -1;
2031 return 0;
2032}
2033
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07002034#ifdef CONFIG_VIRTFS
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302035static int fsdev_init_func(QemuOpts *opts, void *opaque)
2036{
2037 int ret;
2038 ret = qemu_fsdev_add(opts);
2039
2040 return ret;
2041}
2042#endif
2043
Gerd Hoffmann88589342009-12-08 13:11:50 +01002044static int mon_init_func(QemuOpts *opts, void *opaque)
2045{
2046 CharDriverState *chr;
2047 const char *chardev;
2048 const char *mode;
2049 int flags;
2050
2051 mode = qemu_opt_get(opts, "mode");
2052 if (mode == NULL) {
2053 mode = "readline";
2054 }
2055 if (strcmp(mode, "readline") == 0) {
2056 flags = MONITOR_USE_READLINE;
2057 } else if (strcmp(mode, "control") == 0) {
2058 flags = MONITOR_USE_CONTROL;
2059 } else {
2060 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
2061 exit(1);
2062 }
2063
Daniel P. Berrange39eaab92010-06-07 15:42:31 +01002064 if (qemu_opt_get_bool(opts, "pretty", 0))
2065 flags |= MONITOR_USE_PRETTY;
2066
Gerd Hoffmann88589342009-12-08 13:11:50 +01002067 if (qemu_opt_get_bool(opts, "default", 0))
2068 flags |= MONITOR_IS_DEFAULT;
2069
2070 chardev = qemu_opt_get(opts, "chardev");
2071 chr = qemu_chr_find(chardev);
2072 if (chr == NULL) {
2073 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
2074 exit(1);
2075 }
2076
2077 monitor_init(chr, flags);
2078 return 0;
2079}
2080
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002081static void monitor_parse(const char *optarg, const char *mode)
Gerd Hoffmann88589342009-12-08 13:11:50 +01002082{
2083 static int monitor_device_index = 0;
2084 QemuOpts *opts;
2085 const char *p;
2086 char label[32];
2087 int def = 0;
2088
2089 if (strstart(optarg, "chardev:", &p)) {
2090 snprintf(label, sizeof(label), "%s", p);
2091 } else {
Jan Kiszka140e0652010-04-06 16:55:52 +02002092 snprintf(label, sizeof(label), "compat_monitor%d",
2093 monitor_device_index);
2094 if (monitor_device_index == 0) {
Gerd Hoffmann88589342009-12-08 13:11:50 +01002095 def = 1;
2096 }
2097 opts = qemu_chr_parse_compat(label, optarg);
2098 if (!opts) {
2099 fprintf(stderr, "parse error: %s\n", optarg);
2100 exit(1);
2101 }
2102 }
2103
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03002104 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, NULL);
Gerd Hoffmann88589342009-12-08 13:11:50 +01002105 if (!opts) {
2106 fprintf(stderr, "duplicate chardev: %s\n", label);
2107 exit(1);
2108 }
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002109 qemu_opt_set(opts, "mode", mode);
Gerd Hoffmann88589342009-12-08 13:11:50 +01002110 qemu_opt_set(opts, "chardev", label);
2111 if (def)
2112 qemu_opt_set(opts, "default", "on");
2113 monitor_device_index++;
2114}
2115
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002116struct device_config {
2117 enum {
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002118 DEV_USB, /* -usbdevice */
2119 DEV_BT, /* -bt */
2120 DEV_SERIAL, /* -serial */
2121 DEV_PARALLEL, /* -parallel */
2122 DEV_VIRTCON, /* -virtioconsole */
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002123 DEV_DEBUGCON, /* -debugcon */
Markus Armbrusteref0c4a02012-02-07 15:09:13 +01002124 DEV_GDB, /* -gdb, -s */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002125 } type;
2126 const char *cmdline;
Markus Armbrusterd9a59542012-02-07 15:09:12 +01002127 Location loc;
Blue Swirl72cf2d42009-09-12 07:36:22 +00002128 QTAILQ_ENTRY(device_config) next;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002129};
Blue Swirl72cf2d42009-09-12 07:36:22 +00002130QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002131
2132static void add_device_config(int type, const char *cmdline)
2133{
2134 struct device_config *conf;
2135
Anthony Liguori7267c092011-08-20 22:09:37 -05002136 conf = g_malloc0(sizeof(*conf));
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002137 conf->type = type;
2138 conf->cmdline = cmdline;
Markus Armbrusterd9a59542012-02-07 15:09:12 +01002139 loc_save(&conf->loc);
Blue Swirl72cf2d42009-09-12 07:36:22 +00002140 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002141}
2142
2143static int foreach_device_config(int type, int (*func)(const char *cmdline))
2144{
2145 struct device_config *conf;
2146 int rc;
2147
Blue Swirl72cf2d42009-09-12 07:36:22 +00002148 QTAILQ_FOREACH(conf, &device_configs, next) {
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002149 if (conf->type != type)
2150 continue;
Markus Armbrusterd9a59542012-02-07 15:09:12 +01002151 loc_push_restore(&conf->loc);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002152 rc = func(conf->cmdline);
Markus Armbrusterd9a59542012-02-07 15:09:12 +01002153 loc_pop(&conf->loc);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002154 if (0 != rc)
2155 return rc;
2156 }
2157 return 0;
2158}
2159
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002160static int serial_parse(const char *devname)
2161{
2162 static int index = 0;
2163 char label[32];
2164
2165 if (strcmp(devname, "none") == 0)
2166 return 0;
2167 if (index == MAX_SERIAL_PORTS) {
2168 fprintf(stderr, "qemu: too many serial ports\n");
2169 exit(1);
2170 }
2171 snprintf(label, sizeof(label), "serial%d", index);
Anthony Liguori27143a42011-08-15 11:17:36 -05002172 serial_hds[index] = qemu_chr_new(label, devname, NULL);
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002173 if (!serial_hds[index]) {
Peter Maydell52d06132012-07-09 04:28:30 +00002174 fprintf(stderr, "qemu: could not connect serial device"
2175 " to character backend '%s'\n", devname);
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002176 return -1;
2177 }
2178 index++;
2179 return 0;
2180}
2181
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002182static int parallel_parse(const char *devname)
2183{
2184 static int index = 0;
2185 char label[32];
2186
2187 if (strcmp(devname, "none") == 0)
2188 return 0;
2189 if (index == MAX_PARALLEL_PORTS) {
2190 fprintf(stderr, "qemu: too many parallel ports\n");
2191 exit(1);
2192 }
2193 snprintf(label, sizeof(label), "parallel%d", index);
Anthony Liguori27143a42011-08-15 11:17:36 -05002194 parallel_hds[index] = qemu_chr_new(label, devname, NULL);
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002195 if (!parallel_hds[index]) {
Peter Maydell52d06132012-07-09 04:28:30 +00002196 fprintf(stderr, "qemu: could not connect parallel device"
2197 " to character backend '%s'\n", devname);
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002198 return -1;
2199 }
2200 index++;
2201 return 0;
2202}
2203
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002204static int virtcon_parse(const char *devname)
2205{
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002206 QemuOptsList *device = qemu_find_opts("device");
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002207 static int index = 0;
2208 char label[32];
Amit Shah392ecf52010-01-21 16:19:23 +05302209 QemuOpts *bus_opts, *dev_opts;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002210
2211 if (strcmp(devname, "none") == 0)
2212 return 0;
2213 if (index == MAX_VIRTIO_CONSOLES) {
2214 fprintf(stderr, "qemu: too many virtio consoles\n");
2215 exit(1);
2216 }
Amit Shah392ecf52010-01-21 16:19:23 +05302217
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03002218 bus_opts = qemu_opts_create(device, NULL, 0, NULL);
Anthony Liguorie87f7fc2012-02-06 11:07:18 -06002219 if (arch_type == QEMU_ARCH_S390X) {
2220 qemu_opt_set(bus_opts, "driver", "virtio-serial-s390");
2221 } else {
2222 qemu_opt_set(bus_opts, "driver", "virtio-serial-pci");
2223 }
Amit Shah392ecf52010-01-21 16:19:23 +05302224
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03002225 dev_opts = qemu_opts_create(device, NULL, 0, NULL);
Amit Shah392ecf52010-01-21 16:19:23 +05302226 qemu_opt_set(dev_opts, "driver", "virtconsole");
2227
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002228 snprintf(label, sizeof(label), "virtcon%d", index);
Anthony Liguori27143a42011-08-15 11:17:36 -05002229 virtcon_hds[index] = qemu_chr_new(label, devname, NULL);
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002230 if (!virtcon_hds[index]) {
Peter Maydell52d06132012-07-09 04:28:30 +00002231 fprintf(stderr, "qemu: could not connect virtio console"
2232 " to character backend '%s'\n", devname);
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002233 return -1;
2234 }
Amit Shah392ecf52010-01-21 16:19:23 +05302235 qemu_opt_set(dev_opts, "chardev", label);
2236
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002237 index++;
2238 return 0;
2239}
2240
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002241static int debugcon_parse(const char *devname)
2242{
2243 QemuOpts *opts;
2244
Anthony Liguori27143a42011-08-15 11:17:36 -05002245 if (!qemu_chr_new("debugcon", devname, NULL)) {
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002246 exit(1);
2247 }
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03002248 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL);
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002249 if (!opts) {
2250 fprintf(stderr, "qemu: already have a debugcon device\n");
2251 exit(1);
2252 }
2253 qemu_opt_set(opts, "driver", "isa-debugcon");
2254 qemu_opt_set(opts, "chardev", "debugcon");
2255 return 0;
2256}
2257
Jan Kiszka9052ea62011-07-23 12:38:37 +02002258static QEMUMachine *machine_parse(const char *name)
2259{
2260 QEMUMachine *m, *machine = NULL;
2261
2262 if (name) {
2263 machine = find_machine(name);
2264 }
2265 if (machine) {
2266 return machine;
2267 }
2268 printf("Supported machines are:\n");
2269 for (m = first_machine; m != NULL; m = m->next) {
2270 if (m->alias) {
Peter Maydell3b264862012-02-22 22:13:11 +00002271 printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name);
Jan Kiszka9052ea62011-07-23 12:38:37 +02002272 }
Peter Maydell3b264862012-02-22 22:13:11 +00002273 printf("%-20s %s%s\n", m->name, m->desc,
Jan Kiszka9052ea62011-07-23 12:38:37 +02002274 m->is_default ? " (default)" : "");
2275 }
Peter Maydellc8057f92012-08-02 13:45:54 +01002276 exit(!name || !is_help_option(name));
Jan Kiszka9052ea62011-07-23 12:38:37 +02002277}
2278
Anthony PERARD303d4e82010-09-21 20:05:31 +01002279static int tcg_init(void)
2280{
Jan Kiszkad5ab9712011-08-02 16:10:21 +02002281 tcg_exec_init(tcg_tb_size * 1024 * 1024);
Anthony PERARD303d4e82010-09-21 20:05:31 +01002282 return 0;
2283}
2284
2285static struct {
2286 const char *opt_name;
2287 const char *name;
2288 int (*available)(void);
2289 int (*init)(void);
2290 int *allowed;
2291} accel_list[] = {
2292 { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
Anthony PERARD3285cf42010-08-19 12:27:56 +01002293 { "xen", "Xen", xen_available, xen_init, &xen_allowed },
Anthony PERARD303d4e82010-09-21 20:05:31 +01002294 { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
Anthony Liguoric7f0f3b2012-03-28 15:42:02 +02002295 { "qtest", "QTest", qtest_available, qtest_init, &qtest_allowed },
Anthony PERARD303d4e82010-09-21 20:05:31 +01002296};
2297
2298static int configure_accelerator(void)
2299{
2300 const char *p = NULL;
2301 char buf[10];
2302 int i, ret;
Peter Maydell1b785a92012-02-07 20:57:27 +00002303 bool accel_initialised = 0;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002304 bool init_failed = 0;
2305
2306 QemuOptsList *list = qemu_find_opts("machine");
2307 if (!QTAILQ_EMPTY(&list->head)) {
2308 p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel");
2309 }
2310
2311 if (p == NULL) {
2312 /* Use the default "accelerator", tcg */
2313 p = "tcg";
2314 }
2315
Peter Maydell1b785a92012-02-07 20:57:27 +00002316 while (!accel_initialised && *p != '\0') {
Anthony PERARD303d4e82010-09-21 20:05:31 +01002317 if (*p == ':') {
2318 p++;
2319 }
2320 p = get_opt_name(buf, sizeof (buf), p, ':');
2321 for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
2322 if (strcmp(accel_list[i].opt_name, buf) == 0) {
Anthony Liguoria16c53b2011-06-06 08:25:06 -05002323 *(accel_list[i].allowed) = 1;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002324 ret = accel_list[i].init();
2325 if (ret < 0) {
2326 init_failed = 1;
2327 if (!accel_list[i].available()) {
2328 printf("%s not supported for this target\n",
2329 accel_list[i].name);
2330 } else {
2331 fprintf(stderr, "failed to initialize %s: %s\n",
2332 accel_list[i].name,
2333 strerror(-ret));
2334 }
Anthony Liguoria16c53b2011-06-06 08:25:06 -05002335 *(accel_list[i].allowed) = 0;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002336 } else {
Peter Maydell1b785a92012-02-07 20:57:27 +00002337 accel_initialised = 1;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002338 }
2339 break;
2340 }
2341 }
2342 if (i == ARRAY_SIZE(accel_list)) {
2343 fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
2344 }
2345 }
2346
Peter Maydell1b785a92012-02-07 20:57:27 +00002347 if (!accel_initialised) {
Anthony PERARD303d4e82010-09-21 20:05:31 +01002348 fprintf(stderr, "No accelerator found!\n");
2349 exit(1);
2350 }
2351
2352 if (init_failed) {
2353 fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
2354 }
2355
Peter Maydell1b785a92012-02-07 20:57:27 +00002356 return !accel_initialised;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002357}
2358
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02002359void qemu_add_exit_notifier(Notifier *notify)
2360{
2361 notifier_list_add(&exit_notifiers, notify);
2362}
2363
2364void qemu_remove_exit_notifier(Notifier *notify)
2365{
Paolo Bonzini31552522012-01-13 17:34:01 +01002366 notifier_remove(notify);
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02002367}
2368
2369static void qemu_run_exit_notifiers(void)
2370{
Jan Kiszka9e8dd452011-06-20 14:06:26 +02002371 notifier_list_notify(&exit_notifiers, NULL);
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02002372}
2373
Gleb Natapov4cab9462010-12-08 13:35:08 +02002374void qemu_add_machine_init_done_notifier(Notifier *notify)
2375{
2376 notifier_list_add(&machine_init_done_notifiers, notify);
2377}
2378
2379static void qemu_run_machine_init_done_notifiers(void)
2380{
Jan Kiszka9e8dd452011-06-20 14:06:26 +02002381 notifier_list_notify(&machine_init_done_notifiers, NULL);
Gleb Natapov4cab9462010-12-08 13:35:08 +02002382}
2383
Anthony Liguori6530a972010-01-22 09:18:06 -06002384static const QEMUOption *lookup_opt(int argc, char **argv,
2385 const char **poptarg, int *poptind)
2386{
2387 const QEMUOption *popt;
2388 int optind = *poptind;
2389 char *r = argv[optind];
2390 const char *optarg;
2391
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002392 loc_set_cmdline(argv, optind, 1);
Anthony Liguori6530a972010-01-22 09:18:06 -06002393 optind++;
2394 /* Treat --foo the same as -foo. */
2395 if (r[1] == '-')
2396 r++;
2397 popt = qemu_options;
2398 for(;;) {
2399 if (!popt->name) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002400 error_report("invalid option");
Anthony Liguori6530a972010-01-22 09:18:06 -06002401 exit(1);
2402 }
2403 if (!strcmp(popt->name, r + 1))
2404 break;
2405 popt++;
2406 }
2407 if (popt->flags & HAS_ARG) {
2408 if (optind >= argc) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002409 error_report("requires an argument");
Anthony Liguori6530a972010-01-22 09:18:06 -06002410 exit(1);
2411 }
2412 optarg = argv[optind++];
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002413 loc_set_cmdline(argv, optind - 2, 2);
Anthony Liguori6530a972010-01-22 09:18:06 -06002414 } else {
2415 optarg = NULL;
2416 }
2417
2418 *poptarg = optarg;
2419 *poptind = optind;
2420
2421 return popt;
2422}
2423
Anthony Liguori07501122011-08-20 22:38:31 -05002424static gpointer malloc_and_trace(gsize n_bytes)
2425{
2426 void *ptr = malloc(n_bytes);
Frediano Ziglioa74cd8c2011-08-31 09:25:35 +02002427 trace_g_malloc(n_bytes, ptr);
Anthony Liguori07501122011-08-20 22:38:31 -05002428 return ptr;
2429}
2430
2431static gpointer realloc_and_trace(gpointer mem, gsize n_bytes)
2432{
2433 void *ptr = realloc(mem, n_bytes);
Frediano Ziglioa74cd8c2011-08-31 09:25:35 +02002434 trace_g_realloc(mem, n_bytes, ptr);
Anthony Liguori07501122011-08-20 22:38:31 -05002435 return ptr;
2436}
2437
2438static void free_and_trace(gpointer mem)
2439{
Frediano Ziglioa74cd8c2011-08-31 09:25:35 +02002440 trace_g_free(mem);
Anthony Liguori07501122011-08-20 22:38:31 -05002441 free(mem);
2442}
2443
Michael Rothd34e8f62012-01-21 11:13:53 -06002444int qemu_init_main_loop(void)
2445{
2446 return main_loop_init();
2447}
2448
malc902b3d52008-12-10 19:18:40 +00002449int main(int argc, char **argv, char **envp)
bellard0824d6f2003-06-24 13:42:40 +00002450{
thse4bcb142007-12-02 04:51:10 +00002451 int i;
Eduardo Habkostda1fcfd2010-04-06 19:22:07 -03002452 int snapshot, linux_boot;
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01002453 const char *icount_option = NULL;
bellard7f7f9872003-10-30 01:11:23 +00002454 const char *initrd_filename;
bellarda20dd502003-09-30 21:07:02 +00002455 const char *kernel_filename, *kernel_cmdline;
Anthony Liguori195325a2009-10-30 12:42:29 -05002456 char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
aliguori3023f332009-01-16 19:04:14 +00002457 DisplayState *ds;
aliguori7d957bd2009-01-15 22:14:11 +00002458 DisplayChangeListener *dcl;
malc9f227bc2012-08-27 18:33:22 +04002459 int cyls, heads, secs, translation;
2460 QemuOpts *hda_opts = NULL, *opts, *machine_opts;
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002461 QemuOptsList *olist;
bellardcd6f1162004-05-13 22:02:20 +00002462 int optind;
Anthony Liguori6530a972010-01-22 09:18:06 -06002463 const char *optarg;
bellardd63d3072004-10-03 13:29:03 +00002464 const char *loadvm = NULL;
bellardcc1daa42005-06-05 14:49:17 +00002465 QEMUMachine *machine;
j_mayer94fc95c2007-03-05 19:44:02 +00002466 const char *cpu_model;
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +02002467 const char *vga_model = "none";
ths93815bc2007-03-19 15:58:31 +00002468 const char *pid_file = NULL;
aliguori5bb79102008-10-13 03:12:02 +00002469 const char *incoming = NULL;
Jes Sorensen821601e2011-03-16 13:33:36 +01002470#ifdef CONFIG_VNC
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002471 int show_vnc_port = 0;
Jes Sorensen821601e2011-03-16 13:33:36 +01002472#endif
Eduardo Habkost3ed2d9e2012-05-02 13:07:28 -03002473 bool defconfig = true;
Eduardo Habkostf29a5612012-05-02 13:07:29 -03002474 bool userconfig = true;
Matthew Fernandezc235d732011-06-07 16:32:40 +00002475 const char *log_mask = NULL;
2476 const char *log_file = NULL;
Anthony Liguori07501122011-08-20 22:38:31 -05002477 GMemVTable mem_trace = {
2478 .malloc = malloc_and_trace,
2479 .realloc = realloc_and_trace,
2480 .free = free_and_trace,
2481 };
Lluís23d15e82011-08-31 20:31:31 +02002482 const char *trace_events = NULL;
Lluíse4858972011-08-31 20:31:03 +02002483 const char *trace_file = NULL;
Stefan Hajnoczi0b5538c2011-02-26 18:38:39 +00002484
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02002485 atexit(qemu_run_exit_notifiers);
Markus Armbruster65abca02010-02-24 14:37:14 +01002486 error_set_progname(argv[0]);
2487
Anthony Liguori07501122011-08-20 22:38:31 -05002488 g_mem_set_vtable(&mem_trace);
Andreas Färberdb529aa2011-10-31 19:14:56 +01002489 if (!g_thread_supported()) {
Alon Levy42ed3722011-12-20 13:41:04 +02002490#if !GLIB_CHECK_VERSION(2, 31, 0)
Andreas Färberdb529aa2011-10-31 19:14:56 +01002491 g_thread_init(NULL);
Alon Levy42ed3722011-12-20 13:41:04 +02002492#else
2493 fprintf(stderr, "glib threading failed to initialize.\n");
2494 exit(1);
2495#endif
Andreas Färberdb529aa2011-10-31 19:14:56 +01002496 }
Anthony Liguori07501122011-08-20 22:38:31 -05002497
Andreas Färber1b71f7c2012-03-04 21:32:35 +01002498 module_call_init(MODULE_INIT_QOM);
2499
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -03002500 runstate_init();
2501
Jan Kiszka68752042009-09-15 13:36:04 +02002502 init_clocks();
Paolo Bonzini2ff68d02011-09-12 16:21:44 +02002503 rtc_clock = host_clock;
Jan Kiszka68752042009-09-15 13:36:04 +02002504
malc902b3d52008-12-10 19:18:40 +00002505 qemu_cache_utils_init(envp);
2506
Blue Swirl72cf2d42009-09-12 07:36:22 +00002507 QLIST_INIT (&vm_change_state_head);
Jes Sorensenfe98ac12010-06-10 11:42:21 +02002508 os_setup_early_signal_handling();
bellardbe995c22006-06-25 16:25:21 +00002509
Anthony Liguorif80f9ec2009-05-20 18:38:09 -05002510 module_call_init(MODULE_INIT_MACHINE);
Anthony Liguori0c257432009-05-21 20:41:01 -05002511 machine = find_default_machine();
j_mayer94fc95c2007-03-05 19:44:02 +00002512 cpu_model = NULL;
aurel324fc5d072008-04-27 21:39:40 +00002513 ram_size = 0;
bellard33e39632003-07-06 17:15:21 +00002514 snapshot = 0;
malc9f227bc2012-08-27 18:33:22 +04002515 cyls = heads = secs = 0;
2516 translation = BIOS_ATA_TRANSLATION_AUTO;
bellardc4b1fcc2004-03-14 21:44:30 +00002517
aliguori268a3622009-04-21 22:30:27 +00002518 for (i = 0; i < MAX_NODES; i++) {
2519 node_mem[i] = 0;
Chegu Vinodee785fe2012-07-16 21:31:30 -07002520 node_cpumask[i] = bitmap_new(MAX_CPUMASK_BITS);
aliguori268a3622009-04-21 22:30:27 +00002521 }
2522
aliguori268a3622009-04-21 22:30:27 +00002523 nb_numa_nodes = 0;
bellard7c9d8e02005-11-15 22:16:05 +00002524 nb_nics = 0;
ths3b46e622007-09-17 08:09:54 +00002525
blueswir141bd6392008-10-05 09:56:21 +00002526 autostart= 1;
2527
Anthony Liguori292444c2010-01-21 10:57:58 -06002528 /* first pass of option parsing */
2529 optind = 1;
2530 while (optind < argc) {
2531 if (argv[optind][0] != '-') {
2532 /* disk image */
Anthony Liguori28e68d62010-01-27 10:46:00 -06002533 optind++;
Anthony Liguori292444c2010-01-21 10:57:58 -06002534 continue;
2535 } else {
2536 const QEMUOption *popt;
2537
2538 popt = lookup_opt(argc, argv, &optarg, &optind);
2539 switch (popt->index) {
2540 case QEMU_OPTION_nodefconfig:
Eduardo Habkost3ed2d9e2012-05-02 13:07:28 -03002541 defconfig = false;
Anthony Liguori292444c2010-01-21 10:57:58 -06002542 break;
Eduardo Habkostf29a5612012-05-02 13:07:29 -03002543 case QEMU_OPTION_nouserconfig:
2544 userconfig = false;
2545 break;
Anthony Liguori292444c2010-01-21 10:57:58 -06002546 }
2547 }
2548 }
2549
2550 if (defconfig) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002551 int ret;
Eduardo Habkostf29a5612012-05-02 13:07:29 -03002552 ret = qemu_read_default_config_files(userconfig);
Eduardo Habkostb5a8fe52012-05-02 13:07:25 -03002553 if (ret < 0) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002554 exit(1);
Anthony Liguori292444c2010-01-21 10:57:58 -06002555 }
2556 }
2557
2558 /* second pass of option parsing */
bellardcd6f1162004-05-13 22:02:20 +00002559 optind = 1;
bellard0824d6f2003-06-24 13:42:40 +00002560 for(;;) {
bellardcd6f1162004-05-13 22:02:20 +00002561 if (optind >= argc)
bellard0824d6f2003-06-24 13:42:40 +00002562 break;
Anthony Liguori6530a972010-01-22 09:18:06 -06002563 if (argv[optind][0] != '-') {
malc9f227bc2012-08-27 18:33:22 +04002564 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
bellardcd6f1162004-05-13 22:02:20 +00002565 } else {
2566 const QEMUOption *popt;
2567
Anthony Liguori6530a972010-01-22 09:18:06 -06002568 popt = lookup_opt(argc, argv, &optarg, &optind);
Blue Swirlad960902010-03-29 19:23:52 +00002569 if (!(popt->arch_mask & arch_type)) {
2570 printf("Option %s not supported for this target\n", popt->name);
2571 exit(1);
2572 }
bellardcd6f1162004-05-13 22:02:20 +00002573 switch(popt->index) {
bellardcc1daa42005-06-05 14:49:17 +00002574 case QEMU_OPTION_M:
Jan Kiszka9052ea62011-07-23 12:38:37 +02002575 machine = machine_parse(optarg);
bellardcc1daa42005-06-05 14:49:17 +00002576 break;
Jan Kiszkae43d5942012-10-05 14:51:40 -03002577 case QEMU_OPTION_no_kvm_irqchip: {
2578 olist = qemu_find_opts("machine");
2579 qemu_opts_parse(olist, "kernel_irqchip=off", 0);
2580 break;
2581 }
j_mayer94fc95c2007-03-05 19:44:02 +00002582 case QEMU_OPTION_cpu:
2583 /* hw initialization will check this */
Eduardo Habkostecf40be2012-03-09 16:19:07 -03002584 cpu_model = optarg;
j_mayer94fc95c2007-03-05 19:44:02 +00002585 break;
bellardcd6f1162004-05-13 22:02:20 +00002586 case QEMU_OPTION_hda:
malc9f227bc2012-08-27 18:33:22 +04002587 {
2588 char buf[256];
2589 if (cyls == 0)
2590 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2591 else
2592 snprintf(buf, sizeof(buf),
2593 "%s,cyls=%d,heads=%d,secs=%d%s",
2594 HD_OPTS , cyls, heads, secs,
2595 translation == BIOS_ATA_TRANSLATION_LBA ?
2596 ",trans=lba" :
2597 translation == BIOS_ATA_TRANSLATION_NONE ?
2598 ",trans=none" : "");
2599 drive_add(IF_DEFAULT, 0, optarg, buf);
2600 break;
2601 }
bellardcd6f1162004-05-13 22:02:20 +00002602 case QEMU_OPTION_hdb:
bellardcc1daa42005-06-05 14:49:17 +00002603 case QEMU_OPTION_hdc:
2604 case QEMU_OPTION_hdd:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002605 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2606 HD_OPTS);
bellardfc01f7e2003-06-30 10:03:06 +00002607 break;
thse4bcb142007-12-02 04:51:10 +00002608 case QEMU_OPTION_drive:
Michael Tokareve2982c32011-03-30 16:31:05 +04002609 if (drive_def(optarg) == NULL) {
2610 exit(1);
2611 }
thse4bcb142007-12-02 04:51:10 +00002612 break;
Gerd Hoffmannd058fe02009-07-31 12:25:36 +02002613 case QEMU_OPTION_set:
2614 if (qemu_set_option(optarg) != 0)
2615 exit(1);
2616 break;
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01002617 case QEMU_OPTION_global:
2618 if (qemu_global_option(optarg) != 0)
2619 exit(1);
2620 break;
balrog3e3d5812007-04-30 02:09:25 +00002621 case QEMU_OPTION_mtdblock:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002622 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
balrog3e3d5812007-04-30 02:09:25 +00002623 break;
pbrooka1bb27b2007-04-06 16:49:48 +00002624 case QEMU_OPTION_sd:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002625 drive_add(IF_SD, 0, optarg, SD_OPTS);
pbrooka1bb27b2007-04-06 16:49:48 +00002626 break;
j_mayer86f55662007-04-24 06:52:59 +00002627 case QEMU_OPTION_pflash:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002628 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
j_mayer86f55662007-04-24 06:52:59 +00002629 break;
bellardcd6f1162004-05-13 22:02:20 +00002630 case QEMU_OPTION_snapshot:
bellard33e39632003-07-06 17:15:21 +00002631 snapshot = 1;
2632 break;
bellardcd6f1162004-05-13 22:02:20 +00002633 case QEMU_OPTION_hdachs:
bellard330d0412003-07-26 18:11:40 +00002634 {
bellard330d0412003-07-26 18:11:40 +00002635 const char *p;
2636 p = optarg;
2637 cyls = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002638 if (cyls < 1 || cyls > 16383)
2639 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00002640 if (*p != ',')
2641 goto chs_fail;
2642 p++;
2643 heads = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002644 if (heads < 1 || heads > 16)
2645 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00002646 if (*p != ',')
2647 goto chs_fail;
2648 p++;
2649 secs = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002650 if (secs < 1 || secs > 63)
2651 goto chs_fail;
2652 if (*p == ',') {
2653 p++;
2654 if (!strcmp(p, "none"))
2655 translation = BIOS_ATA_TRANSLATION_NONE;
2656 else if (!strcmp(p, "lba"))
2657 translation = BIOS_ATA_TRANSLATION_LBA;
2658 else if (!strcmp(p, "auto"))
2659 translation = BIOS_ATA_TRANSLATION_AUTO;
2660 else
2661 goto chs_fail;
2662 } else if (*p != '\0') {
bellardc4b1fcc2004-03-14 21:44:30 +00002663 chs_fail:
bellard46d47672004-11-16 01:45:27 +00002664 fprintf(stderr, "qemu: invalid physical CHS format\n");
2665 exit(1);
bellardc4b1fcc2004-03-14 21:44:30 +00002666 }
malc9f227bc2012-08-27 18:33:22 +04002667 if (hda_opts != NULL) {
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02002668 char num[16];
2669 snprintf(num, sizeof(num), "%d", cyls);
2670 qemu_opt_set(hda_opts, "cyls", num);
2671 snprintf(num, sizeof(num), "%d", heads);
2672 qemu_opt_set(hda_opts, "heads", num);
2673 snprintf(num, sizeof(num), "%d", secs);
2674 qemu_opt_set(hda_opts, "secs", num);
2675 if (translation == BIOS_ATA_TRANSLATION_LBA)
2676 qemu_opt_set(hda_opts, "trans", "lba");
2677 if (translation == BIOS_ATA_TRANSLATION_NONE)
2678 qemu_opt_set(hda_opts, "trans", "none");
2679 }
bellard330d0412003-07-26 18:11:40 +00002680 }
2681 break;
aliguori268a3622009-04-21 22:30:27 +00002682 case QEMU_OPTION_numa:
2683 if (nb_numa_nodes >= MAX_NODES) {
2684 fprintf(stderr, "qemu: too many NUMA nodes\n");
2685 exit(1);
2686 }
2687 numa_add(optarg);
2688 break;
Jes Sorensen1472a952011-03-16 13:33:31 +01002689 case QEMU_OPTION_display:
2690 display_type = select_display(optarg);
2691 break;
bellardcd6f1162004-05-13 22:02:20 +00002692 case QEMU_OPTION_nographic:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002693 display_type = DT_NOGRAPHIC;
bellarda20dd502003-09-30 21:07:02 +00002694 break;
balrog4d3b6f62008-02-10 16:33:14 +00002695 case QEMU_OPTION_curses:
Jes Sorensen47b05362011-03-16 13:33:35 +01002696#ifdef CONFIG_CURSES
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002697 display_type = DT_CURSES;
Jes Sorensen47b05362011-03-16 13:33:35 +01002698#else
2699 fprintf(stderr, "Curses support is disabled\n");
2700 exit(1);
balrog4d3b6f62008-02-10 16:33:14 +00002701#endif
Jes Sorensen47b05362011-03-16 13:33:35 +01002702 break;
balroga171fe32007-04-30 01:48:07 +00002703 case QEMU_OPTION_portrait:
Vasily Khoruzhick93128052011-06-17 13:04:36 +03002704 graphic_rotate = 90;
2705 break;
2706 case QEMU_OPTION_rotate:
2707 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
2708 if (graphic_rotate != 0 && graphic_rotate != 90 &&
2709 graphic_rotate != 180 && graphic_rotate != 270) {
2710 fprintf(stderr,
2711 "qemu: only 90, 180, 270 deg rotation is available\n");
2712 exit(1);
2713 }
balroga171fe32007-04-30 01:48:07 +00002714 break;
bellardcd6f1162004-05-13 22:02:20 +00002715 case QEMU_OPTION_kernel:
Peter Maydella0abe472012-02-08 05:41:39 +00002716 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg);
2717 break;
2718 case QEMU_OPTION_initrd:
2719 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg);
bellarda20dd502003-09-30 21:07:02 +00002720 break;
bellardcd6f1162004-05-13 22:02:20 +00002721 case QEMU_OPTION_append:
Peter Maydella0abe472012-02-08 05:41:39 +00002722 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg);
bellard313aa562003-08-10 21:52:11 +00002723 break;
Grant Likely412beee2012-03-02 11:56:38 +00002724 case QEMU_OPTION_dtb:
2725 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg);
2726 break;
bellardcd6f1162004-05-13 22:02:20 +00002727 case QEMU_OPTION_cdrom:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002728 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
bellard36b486b2003-11-11 13:36:08 +00002729 break;
bellardcd6f1162004-05-13 22:02:20 +00002730 case QEMU_OPTION_boot:
j_mayer28c5af52007-11-11 01:50:45 +00002731 {
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002732 static const char * const params[] = {
wayne3d3b8302011-07-27 18:04:55 +08002733 "order", "once", "menu",
Amos Kongac05f342012-09-07 11:11:03 +08002734 "splash", "splash-time",
2735 "reboot-timeout", NULL
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002736 };
2737 char buf[sizeof(boot_devices)];
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002738 char *standard_boot_devices;
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002739 int legacy = 0;
2740
2741 if (!strchr(optarg, '=')) {
2742 legacy = 1;
2743 pstrcpy(buf, sizeof(buf), optarg);
2744 } else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
2745 fprintf(stderr,
2746 "qemu: unknown boot parameter '%s' in '%s'\n",
2747 buf, optarg);
2748 exit(1);
2749 }
2750
2751 if (legacy ||
2752 get_param_value(buf, sizeof(buf), "order", optarg)) {
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -03002753 validate_bootdevices(buf);
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002754 pstrcpy(boot_devices, sizeof(boot_devices), buf);
j_mayer28c5af52007-11-11 01:50:45 +00002755 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002756 if (!legacy) {
2757 if (get_param_value(buf, sizeof(buf),
2758 "once", optarg)) {
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -03002759 validate_bootdevices(buf);
Anthony Liguori7267c092011-08-20 22:09:37 -05002760 standard_boot_devices = g_strdup(boot_devices);
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002761 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2762 qemu_register_reset(restore_boot_devices,
2763 standard_boot_devices);
2764 }
Jan Kiszka95387492009-07-02 00:19:02 +02002765 if (get_param_value(buf, sizeof(buf),
2766 "menu", optarg)) {
2767 if (!strcmp(buf, "on")) {
2768 boot_menu = 1;
2769 } else if (!strcmp(buf, "off")) {
2770 boot_menu = 0;
2771 } else {
2772 fprintf(stderr,
2773 "qemu: invalid option value '%s'\n",
2774 buf);
2775 exit(1);
2776 }
2777 }
wayne3d3b8302011-07-27 18:04:55 +08002778 qemu_opts_parse(qemu_find_opts("boot-opts"),
2779 optarg, 0);
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002780 }
bellard36b486b2003-11-11 13:36:08 +00002781 }
2782 break;
bellardcd6f1162004-05-13 22:02:20 +00002783 case QEMU_OPTION_fda:
bellardcd6f1162004-05-13 22:02:20 +00002784 case QEMU_OPTION_fdb:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002785 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2786 optarg, FD_OPTS);
bellardc45886d2004-01-05 00:02:06 +00002787 break;
bellard52ca8d62006-06-14 16:03:05 +00002788 case QEMU_OPTION_no_fd_bootchk:
2789 fd_bootchk = 0;
2790 break;
Mark McLoughlina1ea4582009-10-08 19:58:26 +01002791 case QEMU_OPTION_netdev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002792 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
Mark McLoughlina1ea4582009-10-08 19:58:26 +01002793 exit(1);
2794 }
2795 break;
bellard7c9d8e02005-11-15 22:16:05 +00002796 case QEMU_OPTION_net:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002797 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
bellardc4b1fcc2004-03-14 21:44:30 +00002798 exit(1);
2799 }
bellard702c6512004-04-02 21:21:32 +00002800 break;
Ronnie Sahlbergf9dadc92012-01-26 09:39:02 +11002801#ifdef CONFIG_LIBISCSI
2802 case QEMU_OPTION_iscsi:
2803 opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0);
2804 if (!opts) {
2805 exit(1);
2806 }
2807 break;
2808#endif
bellardc7f74642004-08-24 21:57:12 +00002809#ifdef CONFIG_SLIRP
2810 case QEMU_OPTION_tftp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02002811 legacy_tftp_prefix = optarg;
bellard9bf05442004-08-25 22:12:49 +00002812 break;
ths47d5d012007-02-20 00:05:08 +00002813 case QEMU_OPTION_bootp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02002814 legacy_bootp_filename = optarg;
ths47d5d012007-02-20 00:05:08 +00002815 break;
bellard9bf05442004-08-25 22:12:49 +00002816 case QEMU_OPTION_redir:
Markus Armbruster07527062009-10-06 12:16:57 +01002817 if (net_slirp_redir(optarg) < 0)
2818 exit(1);
bellard9bf05442004-08-25 22:12:49 +00002819 break;
bellardc7f74642004-08-24 21:57:12 +00002820#endif
balrogdc72ac12008-11-09 00:04:26 +00002821 case QEMU_OPTION_bt:
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002822 add_device_config(DEV_BT, optarg);
balrogdc72ac12008-11-09 00:04:26 +00002823 break;
bellard1d14ffa2005-10-30 18:58:22 +00002824 case QEMU_OPTION_audio_help:
Blue Swirlad960902010-03-29 19:23:52 +00002825 if (!(audio_available())) {
2826 printf("Option %s not supported for this target\n", popt->name);
2827 exit(1);
2828 }
bellard1d14ffa2005-10-30 18:58:22 +00002829 AUD_help ();
2830 exit (0);
2831 break;
2832 case QEMU_OPTION_soundhw:
Blue Swirlad960902010-03-29 19:23:52 +00002833 if (!(audio_available())) {
2834 printf("Option %s not supported for this target\n", popt->name);
2835 exit(1);
2836 }
bellard1d14ffa2005-10-30 18:58:22 +00002837 select_soundhw (optarg);
2838 break;
bellardcd6f1162004-05-13 22:02:20 +00002839 case QEMU_OPTION_h:
ths15f82202007-06-29 23:26:08 +00002840 help(0);
bellardcd6f1162004-05-13 22:02:20 +00002841 break;
pbrook9bd7e6d2009-04-07 22:58:45 +00002842 case QEMU_OPTION_version:
2843 version();
2844 exit(0);
2845 break;
aurel3200f82b82008-04-27 21:12:55 +00002846 case QEMU_OPTION_m: {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +01002847 int64_t value;
Markus Armbrusterff961012012-08-15 13:12:19 +02002848 uint64_t sz;
Markus Armbruster961b42b2011-11-22 09:46:03 +01002849 char *end;
aurel3200f82b82008-04-27 21:12:55 +00002850
Markus Armbruster961b42b2011-11-22 09:46:03 +01002851 value = strtosz(optarg, &end);
2852 if (value < 0 || *end) {
aurel3200f82b82008-04-27 21:12:55 +00002853 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
bellardcd6f1162004-05-13 22:02:20 +00002854 exit(1);
2855 }
Markus Armbrusterff961012012-08-15 13:12:19 +02002856 sz = QEMU_ALIGN_UP((uint64_t)value, 8192);
2857 ram_size = sz;
2858 if (ram_size != sz) {
aurel3200f82b82008-04-27 21:12:55 +00002859 fprintf(stderr, "qemu: ram size too large\n");
2860 exit(1);
2861 }
bellardcd6f1162004-05-13 22:02:20 +00002862 break;
aurel3200f82b82008-04-27 21:12:55 +00002863 }
Marcelo Tosattic9027602010-03-01 20:25:08 -03002864 case QEMU_OPTION_mempath:
2865 mem_path = optarg;
2866 break;
2867#ifdef MAP_POPULATE
2868 case QEMU_OPTION_mem_prealloc:
2869 mem_prealloc = 1;
2870 break;
2871#endif
bellardcd6f1162004-05-13 22:02:20 +00002872 case QEMU_OPTION_d:
Matthew Fernandezc235d732011-06-07 16:32:40 +00002873 log_mask = optarg;
2874 break;
2875 case QEMU_OPTION_D:
2876 log_file = optarg;
bellardcd6f1162004-05-13 22:02:20 +00002877 break;
bellardcd6f1162004-05-13 22:02:20 +00002878 case QEMU_OPTION_s:
Markus Armbrusteref0c4a02012-02-07 15:09:13 +01002879 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
bellardcd6f1162004-05-13 22:02:20 +00002880 break;
aliguori59030a82009-04-05 18:43:41 +00002881 case QEMU_OPTION_gdb:
Markus Armbrusteref0c4a02012-02-07 15:09:13 +01002882 add_device_config(DEV_GDB, optarg);
bellardcd6f1162004-05-13 22:02:20 +00002883 break;
bellardcd6f1162004-05-13 22:02:20 +00002884 case QEMU_OPTION_L:
Paul Brook5cea8592009-05-30 00:52:44 +01002885 data_dir = optarg;
bellardcd6f1162004-05-13 22:02:20 +00002886 break;
j_mayer1192dad2007-10-05 13:08:35 +00002887 case QEMU_OPTION_bios:
2888 bios_name = optarg;
2889 break;
aurel321b530a62009-04-05 20:08:59 +00002890 case QEMU_OPTION_singlestep:
2891 singlestep = 1;
2892 break;
bellardcd6f1162004-05-13 22:02:20 +00002893 case QEMU_OPTION_S:
pbrook3c07f8e2007-01-21 16:47:01 +00002894 autostart = 0;
bellardcd6f1162004-05-13 22:02:20 +00002895 break;
bellard3d11d0e2004-12-12 16:56:30 +00002896 case QEMU_OPTION_k:
2897 keyboard_layout = optarg;
2898 break;
bellardee22c2f2004-06-03 12:49:50 +00002899 case QEMU_OPTION_localtime:
2900 rtc_utc = 0;
2901 break;
malc3893c122008-09-28 00:42:05 +00002902 case QEMU_OPTION_vga:
Blue Swirla369da52011-09-27 19:15:42 +00002903 vga_model = optarg;
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +02002904 default_vga = 0;
bellard1bfe8562004-07-08 21:17:50 +00002905 break;
bellarde9b137c2004-06-21 16:46:10 +00002906 case QEMU_OPTION_g:
2907 {
2908 const char *p;
2909 int w, h, depth;
2910 p = optarg;
2911 w = strtol(p, (char **)&p, 10);
2912 if (w <= 0) {
2913 graphic_error:
2914 fprintf(stderr, "qemu: invalid resolution or depth\n");
2915 exit(1);
2916 }
2917 if (*p != 'x')
2918 goto graphic_error;
2919 p++;
2920 h = strtol(p, (char **)&p, 10);
2921 if (h <= 0)
2922 goto graphic_error;
2923 if (*p == 'x') {
2924 p++;
2925 depth = strtol(p, (char **)&p, 10);
ths5fafdf22007-09-16 21:08:06 +00002926 if (depth != 8 && depth != 15 && depth != 16 &&
bellarde9b137c2004-06-21 16:46:10 +00002927 depth != 24 && depth != 32)
2928 goto graphic_error;
2929 } else if (*p == '\0') {
2930 depth = graphic_depth;
2931 } else {
2932 goto graphic_error;
2933 }
ths3b46e622007-09-17 08:09:54 +00002934
bellarde9b137c2004-06-21 16:46:10 +00002935 graphic_width = w;
2936 graphic_height = h;
2937 graphic_depth = depth;
2938 }
2939 break;
ths20d8a3e2007-02-18 17:04:49 +00002940 case QEMU_OPTION_echr:
2941 {
2942 char *r;
2943 term_escape_char = strtol(optarg, &r, 0);
2944 if (r == optarg)
2945 printf("Bad argument to echr\n");
2946 break;
2947 }
bellard82c643f2004-07-14 17:28:13 +00002948 case QEMU_OPTION_monitor:
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002949 monitor_parse(optarg, "readline");
2950 default_monitor = 0;
2951 break;
2952 case QEMU_OPTION_qmp:
2953 monitor_parse(optarg, "control");
Anthony Liguori2d114dc2010-03-21 14:14:38 -05002954 default_monitor = 0;
bellard82c643f2004-07-14 17:28:13 +00002955 break;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002956 case QEMU_OPTION_mon:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002957 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002958 if (!opts) {
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002959 exit(1);
2960 }
Anthony Liguori2d114dc2010-03-21 14:14:38 -05002961 default_monitor = 0;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002962 break;
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002963 case QEMU_OPTION_chardev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002964 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002965 if (!opts) {
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002966 exit(1);
2967 }
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002968 break;
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302969 case QEMU_OPTION_fsdev:
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002970 olist = qemu_find_opts("fsdev");
2971 if (!olist) {
2972 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
2973 exit(1);
2974 }
2975 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302976 if (!opts) {
2977 fprintf(stderr, "parse error: %s\n", optarg);
2978 exit(1);
2979 }
2980 break;
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302981 case QEMU_OPTION_virtfs: {
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00002982 QemuOpts *fsdev;
2983 QemuOpts *device;
M. Mohan Kumar84a87cc2011-12-14 13:58:47 +05302984 const char *writeout, *sock_fd, *socket;
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302985
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002986 olist = qemu_find_opts("virtfs");
2987 if (!olist) {
2988 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
2989 exit(1);
2990 }
2991 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302992 if (!opts) {
2993 fprintf(stderr, "parse error: %s\n", optarg);
2994 exit(1);
2995 }
2996
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +05302997 if (qemu_opt_get(opts, "fsdriver") == NULL ||
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +05302998 qemu_opt_get(opts, "mount_tag") == NULL) {
2999 fprintf(stderr, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07003000 exit(1);
3001 }
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00003002 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03003003 qemu_opt_get(opts, "mount_tag"),
3004 1, NULL);
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00003005 if (!fsdev) {
3006 fprintf(stderr, "duplicate fsdev id: %s\n",
3007 qemu_opt_get(opts, "mount_tag"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303008 exit(1);
3009 }
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +05303010
3011 writeout = qemu_opt_get(opts, "writeout");
3012 if (writeout) {
3013#ifdef CONFIG_SYNC_FILE_RANGE
3014 qemu_opt_set(fsdev, "writeout", writeout);
3015#else
3016 fprintf(stderr, "writeout=immediate not supported on "
3017 "this platform\n");
3018 exit(1);
3019#endif
3020 }
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +05303021 qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver"));
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00003022 qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"));
3023 qemu_opt_set(fsdev, "security_model",
3024 qemu_opt_get(opts, "security_model"));
M. Mohan Kumar84a87cc2011-12-14 13:58:47 +05303025 socket = qemu_opt_get(opts, "socket");
3026 if (socket) {
3027 qemu_opt_set(fsdev, "socket", socket);
3028 }
M. Mohan Kumar4c793dd2011-12-14 13:49:28 +05303029 sock_fd = qemu_opt_get(opts, "sock_fd");
3030 if (sock_fd) {
3031 qemu_opt_set(fsdev, "sock_fd", sock_fd);
3032 }
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303033
M. Mohan Kumar2c74c2c2011-10-25 12:10:39 +05303034 qemu_opt_set_bool(fsdev, "readonly",
3035 qemu_opt_get_bool(opts, "readonly", 0));
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03003036 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3037 NULL);
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00003038 qemu_opt_set(device, "driver", "virtio-9p-pci");
3039 qemu_opt_set(device, "fsdev",
3040 qemu_opt_get(opts, "mount_tag"));
3041 qemu_opt_set(device, "mount_tag",
3042 qemu_opt_get(opts, "mount_tag"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05303043 break;
3044 }
Aneesh Kumar K.V9db221a2011-10-25 12:10:40 +05303045 case QEMU_OPTION_virtfs_synth: {
3046 QemuOpts *fsdev;
3047 QemuOpts *device;
3048
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03003049 fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3050 1, NULL);
Aneesh Kumar K.V9db221a2011-10-25 12:10:40 +05303051 if (!fsdev) {
3052 fprintf(stderr, "duplicate option: %s\n", "virtfs_synth");
3053 exit(1);
3054 }
3055 qemu_opt_set(fsdev, "fsdriver", "synth");
Aneesh Kumar K.V9db221a2011-10-25 12:10:40 +05303056
Luiz Capitulino8be7e7e2012-03-20 15:51:57 -03003057 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3058 NULL);
Aneesh Kumar K.V9db221a2011-10-25 12:10:40 +05303059 qemu_opt_set(device, "driver", "virtio-9p-pci");
3060 qemu_opt_set(device, "fsdev", "v_synth");
3061 qemu_opt_set(device, "mount_tag", "v_synth");
3062 break;
3063 }
bellard82c643f2004-07-14 17:28:13 +00003064 case QEMU_OPTION_serial:
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01003065 add_device_config(DEV_SERIAL, optarg);
3066 default_serial = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01003067 if (strncmp(optarg, "mon:", 4) == 0) {
3068 default_monitor = 0;
3069 }
bellard82c643f2004-07-14 17:28:13 +00003070 break;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01003071 case QEMU_OPTION_watchdog:
Markus Armbruster09aaa162009-08-21 10:31:34 +02003072 if (watchdog) {
3073 fprintf(stderr,
3074 "qemu: only one watchdog option may be given\n");
3075 return 1;
3076 }
3077 watchdog = optarg;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01003078 break;
3079 case QEMU_OPTION_watchdog_action:
3080 if (select_watchdog_action(optarg) == -1) {
3081 fprintf(stderr, "Unknown -watchdog-action parameter\n");
3082 exit(1);
3083 }
3084 break;
aliguori51ecf132009-01-15 20:06:40 +00003085 case QEMU_OPTION_virtiocon:
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01003086 add_device_config(DEV_VIRTCON, optarg);
3087 default_virtcon = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01003088 if (strncmp(optarg, "mon:", 4) == 0) {
3089 default_monitor = 0;
3090 }
aliguori51ecf132009-01-15 20:06:40 +00003091 break;
bellard6508fe52005-01-15 12:02:56 +00003092 case QEMU_OPTION_parallel:
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01003093 add_device_config(DEV_PARALLEL, optarg);
3094 default_parallel = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01003095 if (strncmp(optarg, "mon:", 4) == 0) {
3096 default_monitor = 0;
3097 }
bellard6508fe52005-01-15 12:02:56 +00003098 break;
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08003099 case QEMU_OPTION_debugcon:
3100 add_device_config(DEV_DEBUGCON, optarg);
3101 break;
bellardd63d3072004-10-03 13:29:03 +00003102 case QEMU_OPTION_loadvm:
3103 loadvm = optarg;
3104 break;
3105 case QEMU_OPTION_full_screen:
3106 full_screen = 1;
3107 break;
ths667acca2006-12-11 02:08:05 +00003108#ifdef CONFIG_SDL
ths43523e92007-02-18 18:19:32 +00003109 case QEMU_OPTION_no_frame:
3110 no_frame = 1;
3111 break;
ths3780e192007-06-21 21:08:02 +00003112 case QEMU_OPTION_alt_grab:
3113 alt_grab = 1;
3114 break;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -05003115 case QEMU_OPTION_ctrl_grab:
3116 ctrl_grab = 1;
3117 break;
ths667acca2006-12-11 02:08:05 +00003118 case QEMU_OPTION_no_quit:
3119 no_quit = 1;
3120 break;
aliguori7d957bd2009-01-15 22:14:11 +00003121 case QEMU_OPTION_sdl:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003122 display_type = DT_SDL;
aliguori7d957bd2009-01-15 22:14:11 +00003123 break;
Jes Sorensen58fc0962011-03-16 13:33:34 +01003124#else
3125 case QEMU_OPTION_no_frame:
3126 case QEMU_OPTION_alt_grab:
3127 case QEMU_OPTION_ctrl_grab:
3128 case QEMU_OPTION_no_quit:
3129 case QEMU_OPTION_sdl:
3130 fprintf(stderr, "SDL support is disabled\n");
3131 exit(1);
ths667acca2006-12-11 02:08:05 +00003132#endif
bellardf7cce892004-12-08 22:21:25 +00003133 case QEMU_OPTION_pidfile:
ths93815bc2007-03-19 15:58:31 +00003134 pid_file = optarg;
bellardf7cce892004-12-08 22:21:25 +00003135 break;
bellarda09db212005-04-30 16:10:35 +00003136 case QEMU_OPTION_win2k_hack:
3137 win2k_install_hack = 1;
3138 break;
Jan Kiszka433acf02012-01-23 20:15:12 +01003139 case QEMU_OPTION_rtc_td_hack: {
3140 static GlobalProperty slew_lost_ticks[] = {
3141 {
3142 .driver = "mc146818rtc",
3143 .property = "lost_tick_policy",
3144 .value = "slew",
3145 },
3146 { /* end of list */ }
3147 };
3148
3149 qdev_prop_register_global_list(slew_lost_ticks);
aliguori73822ec2009-01-15 20:11:34 +00003150 break;
Jan Kiszka433acf02012-01-23 20:15:12 +01003151 }
aliguori8a92ea22009-02-27 20:12:36 +00003152 case QEMU_OPTION_acpitable:
Blue Swirlde06f8d2010-03-29 19:23:50 +00003153 do_acpitable_option(optarg);
aliguori8a92ea22009-02-27 20:12:36 +00003154 break;
aliguorib6f6e3d2009-04-17 18:59:56 +00003155 case QEMU_OPTION_smbios:
Blue Swirlde06f8d2010-03-29 19:23:50 +00003156 do_smbios_option(optarg);
aliguorib6f6e3d2009-04-17 18:59:56 +00003157 break;
aliguori7ba1e612008-11-05 16:04:33 +00003158 case QEMU_OPTION_enable_kvm:
Anthony PERARD303d4e82010-09-21 20:05:31 +01003159 olist = qemu_find_opts("machine");
Anthony PERARD303d4e82010-09-21 20:05:31 +01003160 qemu_opts_parse(olist, "accel=kvm", 0);
3161 break;
3162 case QEMU_OPTION_machine:
3163 olist = qemu_find_opts("machine");
Jan Kiszka9052ea62011-07-23 12:38:37 +02003164 opts = qemu_opts_parse(olist, optarg, 1);
Anthony PERARD303d4e82010-09-21 20:05:31 +01003165 if (!opts) {
3166 fprintf(stderr, "parse error: %s\n", optarg);
3167 exit(1);
3168 }
Jan Kiszka2645c6d2011-07-25 18:11:20 +02003169 optarg = qemu_opt_get(opts, "type");
3170 if (optarg) {
3171 machine = machine_parse(optarg);
3172 }
aliguori7ba1e612008-11-05 16:04:33 +00003173 break;
bellardbb36d472005-11-05 14:22:28 +00003174 case QEMU_OPTION_usb:
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00003175 machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
3176 if (machine_opts) {
3177 qemu_opt_set_bool(machine_opts, "usb", true);
3178 }
bellardbb36d472005-11-05 14:22:28 +00003179 break;
bellarda594cfb2005-11-06 16:13:29 +00003180 case QEMU_OPTION_usbdevice:
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00003181 machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
3182 if (machine_opts) {
3183 qemu_opt_set_bool(machine_opts, "usb", true);
3184 }
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003185 add_device_config(DEV_USB, optarg);
3186 break;
3187 case QEMU_OPTION_device:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003188 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02003189 exit(1);
3190 }
bellarda594cfb2005-11-06 16:13:29 +00003191 break;
bellard6a00d602005-11-21 23:25:50 +00003192 case QEMU_OPTION_smp:
Andre Przywaradc6b1c02009-08-19 15:42:40 +02003193 smp_parse(optarg);
aliguorib2097002008-10-07 20:39:39 +00003194 if (smp_cpus < 1) {
bellard6a00d602005-11-21 23:25:50 +00003195 fprintf(stderr, "Invalid number of CPUs\n");
3196 exit(1);
3197 }
Jes Sorensen6be68d72009-07-23 17:03:42 +02003198 if (max_cpus < smp_cpus) {
3199 fprintf(stderr, "maxcpus must be equal to or greater than "
3200 "smp\n");
3201 exit(1);
3202 }
3203 if (max_cpus > 255) {
3204 fprintf(stderr, "Unsupported number of maxcpus\n");
3205 exit(1);
3206 }
bellard6a00d602005-11-21 23:25:50 +00003207 break;
bellard24236862006-04-30 21:28:36 +00003208 case QEMU_OPTION_vnc:
Jes Sorensen821601e2011-03-16 13:33:36 +01003209#ifdef CONFIG_VNC
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003210 display_remote++;
Jes Sorensen821601e2011-03-16 13:33:36 +01003211 vnc_display = optarg;
3212#else
3213 fprintf(stderr, "VNC support is disabled\n");
3214 exit(1);
3215#endif
3216 break;
bellard6515b202006-05-03 22:02:44 +00003217 case QEMU_OPTION_no_acpi:
3218 acpi_enabled = 0;
3219 break;
aliguori16b29ae2008-12-17 23:28:44 +00003220 case QEMU_OPTION_no_hpet:
3221 no_hpet = 1;
3222 break;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02003223 case QEMU_OPTION_balloon:
3224 if (balloon_parse(optarg) < 0) {
3225 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
3226 exit(1);
3227 }
Eduardo Habkostdf97b922009-06-10 16:34:08 -03003228 break;
bellardd1beab82006-10-02 19:44:22 +00003229 case QEMU_OPTION_no_reboot:
3230 no_reboot = 1;
3231 break;
aurel32b2f76162008-04-11 21:35:52 +00003232 case QEMU_OPTION_no_shutdown:
3233 no_shutdown = 1;
3234 break;
balrog9467cd42007-05-01 01:34:14 +00003235 case QEMU_OPTION_show_cursor:
3236 cursor_hide = 0;
3237 break;
blueswir18fcb1b92008-09-18 18:29:08 +00003238 case QEMU_OPTION_uuid:
3239 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
3240 fprintf(stderr, "Fail to parse UUID string."
3241 " Wrong format.\n");
3242 exit(1);
3243 }
3244 break;
ths9ae02552007-01-05 17:39:04 +00003245 case QEMU_OPTION_option_rom:
3246 if (nb_option_roms >= MAX_OPTION_ROMS) {
3247 fprintf(stderr, "Too many option ROMs\n");
3248 exit(1);
3249 }
Gleb Natapov2e55e842010-12-08 13:35:07 +02003250 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
3251 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
3252 option_rom[nb_option_roms].bootindex =
3253 qemu_opt_get_number(opts, "bootindex", -1);
3254 if (!option_rom[nb_option_roms].name) {
3255 fprintf(stderr, "Option ROM file is not specified\n");
3256 exit(1);
3257 }
ths9ae02552007-01-05 17:39:04 +00003258 nb_option_roms++;
3259 break;
pbrook8e716212007-01-20 17:12:09 +00003260 case QEMU_OPTION_semihosting:
3261 semihosting_enabled = 1;
3262 break;
thsc35734b2007-03-19 15:17:08 +00003263 case QEMU_OPTION_name:
Anthony Liguori7267c092011-08-20 22:09:37 -05003264 qemu_name = g_strdup(optarg);
Andi Kleen18894652009-07-02 09:34:17 +02003265 {
3266 char *p = strchr(qemu_name, ',');
3267 if (p != NULL) {
3268 *p++ = 0;
3269 if (strncmp(p, "process=", 8)) {
Aurelien Jarno5697f6a2010-12-27 18:29:20 +01003270 fprintf(stderr, "Unknown subargument %s to -name\n", p);
Andi Kleen18894652009-07-02 09:34:17 +02003271 exit(1);
3272 }
3273 p += 8;
Jes Sorensence798cf2010-06-10 11:42:31 +02003274 os_set_proc_name(p);
Andi Kleen18894652009-07-02 09:34:17 +02003275 }
3276 }
thsc35734b2007-03-19 15:17:08 +00003277 break;
blueswir166508602007-05-01 14:16:52 +00003278 case QEMU_OPTION_prom_env:
3279 if (nb_prom_envs >= MAX_PROM_ENVS) {
3280 fprintf(stderr, "Too many prom variables\n");
3281 exit(1);
3282 }
3283 prom_envs[nb_prom_envs] = optarg;
3284 nb_prom_envs++;
3285 break;
balrog2b8f2d42007-07-27 22:08:46 +00003286 case QEMU_OPTION_old_param:
3287 old_param = 1;
ths05ebd532008-01-08 19:32:16 +00003288 break;
thsf3dcfad2007-08-24 01:26:02 +00003289 case QEMU_OPTION_clock:
3290 configure_alarms(optarg);
3291 break;
bellard7e0af5d02007-11-07 16:24:33 +00003292 case QEMU_OPTION_startdate:
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02003293 configure_rtc_date_offset(optarg, 1);
3294 break;
3295 case QEMU_OPTION_rtc:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003296 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02003297 if (!opts) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02003298 exit(1);
bellard7e0af5d02007-11-07 16:24:33 +00003299 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02003300 configure_rtc(opts);
bellard7e0af5d02007-11-07 16:24:33 +00003301 break;
bellard26a5f132008-05-28 12:30:31 +00003302 case QEMU_OPTION_tb_size:
Jan Kiszkad5ab9712011-08-02 16:10:21 +02003303 tcg_tb_size = strtol(optarg, NULL, 0);
3304 if (tcg_tb_size < 0) {
3305 tcg_tb_size = 0;
3306 }
bellard26a5f132008-05-28 12:30:31 +00003307 break;
pbrook2e70f6e2008-06-29 01:03:05 +00003308 case QEMU_OPTION_icount:
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01003309 icount_option = optarg;
pbrook2e70f6e2008-06-29 01:03:05 +00003310 break;
aliguori5bb79102008-10-13 03:12:02 +00003311 case QEMU_OPTION_incoming:
3312 incoming = optarg;
Stefano Stabellini81323a62012-01-18 12:23:13 +00003313 runstate_set(RUN_STATE_INMIGRATE);
aliguori5bb79102008-10-13 03:12:02 +00003314 break;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01003315 case QEMU_OPTION_nodefaults:
3316 default_serial = 0;
3317 default_parallel = 0;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01003318 default_virtcon = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01003319 default_monitor = 0;
Gerd Hoffmanncb4522c2009-12-08 13:11:47 +01003320 default_net = 0;
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01003321 default_floppy = 0;
3322 default_cdrom = 0;
3323 default_sdcard = 0;
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +02003324 default_vga = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01003325 break;
aliguorie37630c2009-04-22 15:19:10 +00003326 case QEMU_OPTION_xen_domid:
Blue Swirlad960902010-03-29 19:23:52 +00003327 if (!(xen_available())) {
3328 printf("Option %s not supported for this target\n", popt->name);
3329 exit(1);
3330 }
aliguorie37630c2009-04-22 15:19:10 +00003331 xen_domid = atoi(optarg);
3332 break;
3333 case QEMU_OPTION_xen_create:
Blue Swirlad960902010-03-29 19:23:52 +00003334 if (!(xen_available())) {
3335 printf("Option %s not supported for this target\n", popt->name);
3336 exit(1);
3337 }
aliguorie37630c2009-04-22 15:19:10 +00003338 xen_mode = XEN_CREATE;
3339 break;
3340 case QEMU_OPTION_xen_attach:
Blue Swirlad960902010-03-29 19:23:52 +00003341 if (!(xen_available())) {
3342 printf("Option %s not supported for this target\n", popt->name);
3343 exit(1);
3344 }
aliguorie37630c2009-04-22 15:19:10 +00003345 xen_mode = XEN_ATTACH;
3346 break;
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003347 case QEMU_OPTION_trace:
Lluíse4858972011-08-31 20:31:03 +02003348 {
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003349 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
Lluíse4858972011-08-31 20:31:03 +02003350 if (!opts) {
3351 exit(1);
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003352 }
Lluís23d15e82011-08-31 20:31:31 +02003353 trace_events = qemu_opt_get(opts, "events");
Lluíse4858972011-08-31 20:31:03 +02003354 trace_file = qemu_opt_get(opts, "file");
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003355 break;
Lluíse4858972011-08-31 20:31:03 +02003356 }
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003357 case QEMU_OPTION_readconfig:
3358 {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01003359 int ret = qemu_read_config_file(optarg);
3360 if (ret < 0) {
3361 fprintf(stderr, "read config %s: %s\n", optarg,
3362 strerror(-ret));
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003363 exit(1);
3364 }
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003365 break;
3366 }
Gerd Hoffmann29b00402010-03-11 11:13:27 -03003367 case QEMU_OPTION_spice:
3368 olist = qemu_find_opts("spice");
3369 if (!olist) {
3370 fprintf(stderr, "spice is not supported by this qemu build.\n");
3371 exit(1);
3372 }
3373 opts = qemu_opts_parse(olist, optarg, 0);
3374 if (!opts) {
3375 fprintf(stderr, "parse error: %s\n", optarg);
3376 exit(1);
3377 }
3378 break;
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003379 case QEMU_OPTION_writeconfig:
3380 {
3381 FILE *fp;
3382 if (strcmp(optarg, "-") == 0) {
3383 fp = stdout;
3384 } else {
3385 fp = fopen(optarg, "w");
3386 if (fp == NULL) {
3387 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
3388 exit(1);
3389 }
3390 }
3391 qemu_config_write(fp);
3392 fclose(fp);
3393 break;
3394 }
Anthony Liguoric7f0f3b2012-03-28 15:42:02 +02003395 case QEMU_OPTION_qtest:
3396 qtest_chrdev = optarg;
3397 break;
3398 case QEMU_OPTION_qtest_log:
3399 qtest_log = optarg;
3400 break;
Eduardo Otubo7d76ad42012-08-14 18:44:08 -03003401 case QEMU_OPTION_sandbox:
3402 opts = qemu_opts_parse(qemu_find_opts("sandbox"), optarg, 1);
3403 if (!opts) {
3404 exit(0);
3405 }
3406 break;
Corey Bryant587ed6b2012-10-18 15:19:34 -04003407 case QEMU_OPTION_add_fd:
3408#ifndef _WIN32
3409 opts = qemu_opts_parse(qemu_find_opts("add-fd"), optarg, 0);
3410 if (!opts) {
3411 exit(0);
3412 }
3413#else
3414 error_report("File descriptor passing is disabled on this "
3415 "platform");
3416 exit(1);
3417#endif
3418 break;
Jes Sorensen59a52642010-06-10 11:42:25 +02003419 default:
3420 os_parse_cmd_args(popt->index, optarg);
bellardcd6f1162004-05-13 22:02:20 +00003421 }
bellard0824d6f2003-06-24 13:42:40 +00003422 }
3423 }
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01003424 loc_set_none();
bellard330d0412003-07-26 18:11:40 +00003425
Eduardo Otubo7d76ad42012-08-14 18:44:08 -03003426 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 0)) {
3427 exit(1);
3428 }
3429
Corey Bryant587ed6b2012-10-18 15:19:34 -04003430#ifndef _WIN32
3431 if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL, 1)) {
3432 exit(1);
3433 }
3434
3435 if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd, NULL, 1)) {
3436 exit(1);
3437 }
3438#endif
3439
Dunrong Huangfb7c2692012-07-24 00:42:20 +08003440 if (machine == NULL) {
3441 fprintf(stderr, "No machine found.\n");
3442 exit(1);
3443 }
3444
Crístian Viana93bfef42012-05-30 00:35:51 -03003445 if (machine->hw_version) {
3446 qemu_set_version(machine->hw_version);
3447 }
3448
Eduardo Habkostecf40be2012-03-09 16:19:07 -03003449 /* Init CPU def lists, based on config
3450 * - Must be called after all the qemu_read_config_file() calls
3451 * - Must be called before list_cpus()
3452 * - Must be called before machine->init()
3453 */
3454 cpudef_init();
3455
Peter Maydellc8057f92012-08-02 13:45:54 +01003456 if (cpu_model && is_help_option(cpu_model)) {
Eduardo Habkost1d6528a2012-03-21 09:33:40 -03003457 list_cpus(stdout, &fprintf, cpu_model);
Eduardo Habkostecf40be2012-03-09 16:19:07 -03003458 exit(0);
3459 }
3460
Matthew Fernandezc235d732011-06-07 16:32:40 +00003461 /* Open the logfile at this point, if necessary. We can't open the logfile
3462 * when encountering either of the logging options (-d or -D) because the
3463 * other one may be encountered later on the command line, changing the
3464 * location or level of logging.
3465 */
3466 if (log_mask) {
3467 if (log_file) {
3468 set_cpu_log_filename(log_file);
3469 }
3470 set_cpu_log(log_mask);
3471 }
3472
Lluís23d15e82011-08-31 20:31:31 +02003473 if (!trace_backend_init(trace_events, trace_file)) {
Lluíse4858972011-08-31 20:31:03 +02003474 exit(1);
Stefan Hajnoczi31d3c9b2011-03-13 20:14:30 +00003475 }
Stefan Hajnoczi0b5538c2011-02-26 18:38:39 +00003476
Paul Brook5cea8592009-05-30 00:52:44 +01003477 /* If no data_dir is specified then try to find it relative to the
3478 executable path. */
3479 if (!data_dir) {
Jes Sorensen61705402010-06-10 11:42:23 +02003480 data_dir = os_find_datadir(argv[0]);
Paul Brook5cea8592009-05-30 00:52:44 +01003481 }
Stefan Weil60474fb2011-09-04 15:17:46 +02003482 /* If all else fails use the install path specified when building. */
Paul Brook5cea8592009-05-30 00:52:44 +01003483 if (!data_dir) {
Paolo Bonzini1dabe052010-05-26 16:08:25 +02003484 data_dir = CONFIG_QEMU_DATADIR;
Paul Brook5cea8592009-05-30 00:52:44 +01003485 }
3486
Jes Sorensen6be68d72009-07-23 17:03:42 +02003487 /*
3488 * Default to max_cpus = smp_cpus, in case the user doesn't
3489 * specify a max_cpus value.
3490 */
3491 if (!max_cpus)
3492 max_cpus = smp_cpus;
3493
balrog3d878ca2008-10-28 10:59:59 +00003494 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
aliguorib2097002008-10-07 20:39:39 +00003495 if (smp_cpus > machine->max_cpus) {
3496 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
3497 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
3498 machine->max_cpus);
3499 exit(1);
3500 }
3501
Anthony PERARD67b724e2010-11-22 15:44:15 +00003502 /*
3503 * Get the default machine options from the machine if it is not already
3504 * specified either by the configuration file or by the command line.
3505 */
3506 if (machine->default_machine_opts) {
Jan Kiszka25de5932012-01-27 19:55:43 +01003507 qemu_opts_set_defaults(qemu_find_opts("machine"),
3508 machine->default_machine_opts, 0);
Anthony PERARD67b724e2010-11-22 15:44:15 +00003509 }
3510
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003511 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
3512 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01003513
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003514 if (machine->no_serial) {
3515 default_serial = 0;
3516 }
3517 if (machine->no_parallel) {
3518 default_parallel = 0;
3519 }
3520 if (!machine->use_virtcon) {
3521 default_virtcon = 0;
3522 }
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01003523 if (machine->no_floppy) {
3524 default_floppy = 0;
3525 }
3526 if (machine->no_cdrom) {
3527 default_cdrom = 0;
3528 }
3529 if (machine->no_sdcard) {
3530 default_sdcard = 0;
3531 }
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003532
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003533 if (display_type == DT_NOGRAPHIC) {
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01003534 if (default_parallel)
3535 add_device_config(DEV_PARALLEL, "null");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003536 if (default_serial && default_monitor) {
3537 add_device_config(DEV_SERIAL, "mon:stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003538 } else if (default_virtcon && default_monitor) {
3539 add_device_config(DEV_VIRTCON, "mon:stdio");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003540 } else {
3541 if (default_serial)
3542 add_device_config(DEV_SERIAL, "stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003543 if (default_virtcon)
3544 add_device_config(DEV_VIRTCON, "stdio");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003545 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01003546 monitor_parse("stdio", "readline");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003547 }
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01003548 } else {
3549 if (default_serial)
3550 add_device_config(DEV_SERIAL, "vc:80Cx24C");
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01003551 if (default_parallel)
3552 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
Gerd Hoffmannabdeed02009-12-08 13:11:43 +01003553 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01003554 monitor_parse("vc:80Cx24C", "readline");
Alexander Graf38536da2009-12-17 13:06:08 +01003555 if (default_virtcon)
3556 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
aliguoribc0129d2008-08-01 15:12:34 +00003557 }
3558
TeLeMana5829fd2010-04-15 12:37:55 +08003559 socket_init();
3560
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003561 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01003562 exit(1);
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07003563#ifdef CONFIG_VIRTFS
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003564 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +05303565 exit(1);
3566 }
3567#endif
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01003568
Jes Sorenseneb505be2010-06-10 11:42:28 +02003569 os_daemonize();
ths71e3ceb2006-12-22 02:11:31 +00003570
thsaa26bb22007-03-25 21:33:06 +00003571 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
Jes Sorenseneb505be2010-06-10 11:42:28 +02003572 os_pidfile_error();
ths93815bc2007-03-19 15:58:31 +00003573 exit(1);
3574 }
3575
Jan Kiszka0ac543d2011-08-15 16:18:57 -07003576 /* init the memory */
3577 if (ram_size == 0) {
3578 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
3579 }
3580
Bruce Rogers3d1d9652012-08-09 12:47:40 -06003581 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0)
3582 != 0) {
3583 exit(0);
3584 }
3585
Anthony PERARD303d4e82010-09-21 20:05:31 +01003586 configure_accelerator();
Marcelo Tosatti214910a2009-09-18 02:41:23 -03003587
Paolo Bonzinid3b12f52011-09-13 10:30:52 +02003588 qemu_init_cpu_loop();
aliguori3fcf7b62009-04-24 18:03:25 +00003589 if (qemu_init_main_loop()) {
3590 fprintf(stderr, "qemu_init_main_loop failed\n");
3591 exit(1);
3592 }
Peter Maydella0abe472012-02-08 05:41:39 +00003593
Peter Maydell967c0da2012-02-22 22:40:00 +00003594 machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
3595 if (machine_opts) {
3596 kernel_filename = qemu_opt_get(machine_opts, "kernel");
3597 initrd_filename = qemu_opt_get(machine_opts, "initrd");
3598 kernel_cmdline = qemu_opt_get(machine_opts, "append");
3599 } else {
3600 kernel_filename = initrd_filename = kernel_cmdline = NULL;
3601 }
3602
Peter Maydella0abe472012-02-08 05:41:39 +00003603 if (!kernel_cmdline) {
3604 kernel_cmdline = "";
3605 }
3606
bellarda20dd502003-09-30 21:07:02 +00003607 linux_boot = (kernel_filename != NULL);
balrog6c41b272007-11-17 12:12:29 +00003608
thsf8d39c02008-07-03 10:01:15 +00003609 if (!linux_boot && *kernel_cmdline != '\0') {
3610 fprintf(stderr, "-append only allowed with -kernel option\n");
3611 exit(1);
3612 }
3613
3614 if (!linux_boot && initrd_filename != NULL) {
3615 fprintf(stderr, "-initrd only allowed with -kernel option\n");
3616 exit(1);
3617 }
3618
Grant Likely412beee2012-03-02 11:56:38 +00003619 if (!linux_boot && machine_opts && qemu_opt_get(machine_opts, "dtb")) {
3620 fprintf(stderr, "-dtb only allowed with -kernel option\n");
3621 exit(1);
3622 }
3623
Jes Sorensen9156d762010-06-10 11:42:30 +02003624 os_set_line_buffering();
ths3b46e622007-09-17 08:09:54 +00003625
aliguori7183b4b2008-11-05 20:40:18 +00003626 if (init_timer_alarm() < 0) {
3627 fprintf(stderr, "could not initialize alarm timer\n");
3628 exit(1);
3629 }
Max Filippov0abe9052011-11-10 15:38:42 +04003630
Alon Levyad1be892012-03-14 20:33:37 +02003631#ifdef CONFIG_SPICE
3632 /* spice needs the timers to be initialized by this point */
3633 qemu_spice_init();
3634#endif
3635
Max Filippov0abe9052011-11-10 15:38:42 +04003636 if (icount_option && (kvm_enabled() || xen_enabled())) {
3637 fprintf(stderr, "-icount is not allowed with kvm or xen\n");
3638 exit(1);
3639 }
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01003640 configure_icount(icount_option);
pbrook634fce92006-07-15 17:40:09 +00003641
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01003642 if (net_init_clients() < 0) {
3643 exit(1);
bellard702c6512004-04-02 21:21:32 +00003644 }
bellardf1510b22003-06-25 00:07:40 +00003645
balrogdc72ac12008-11-09 00:04:26 +00003646 /* init the bluetooth world */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003647 if (foreach_device_config(DEV_BT, bt_parse))
3648 exit(1);
balrogdc72ac12008-11-09 00:04:26 +00003649
Anthony PERARD834e76e2011-07-20 08:17:44 +00003650 if (!xen_enabled()) {
3651 /* On 32-bit hosts, QEMU is limited by virtual address space */
3652 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
3653 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
3654 exit(1);
3655 }
3656 }
balrog7fb4fdc2008-04-24 17:59:27 +00003657
Jan Kiszkad5ab9712011-08-02 16:10:21 +02003658 cpu_exec_init_all();
bellard26a5f132008-05-28 12:30:31 +00003659
Markus Armbrustereb852012009-10-27 18:41:44 +01003660 bdrv_init_with_whitelist();
thse4bcb142007-12-02 04:51:10 +00003661
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +02003662 blk_mig_init();
3663
ths96d30e42007-01-07 20:42:14 +00003664 /* open the virtual block devices */
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02003665 if (snapshot)
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003666 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
3667 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02003668 exit(1);
balrog3e3d5812007-04-30 02:09:25 +00003669
Markus Armbruster4e5d9b52011-01-28 11:21:45 +01003670 default_drive(default_cdrom, snapshot, machine->use_scsi,
3671 IF_DEFAULT, 2, CDROM_OPTS);
3672 default_drive(default_floppy, snapshot, machine->use_scsi,
3673 IF_FLOPPY, 0, FD_OPTS);
3674 default_drive(default_sdcard, snapshot, machine->use_scsi,
3675 IF_SD, 0, SD_OPTS);
3676
Juan Quintela7908c782012-06-26 18:46:10 +02003677 register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00003678
aliguori268a3622009-04-21 22:30:27 +00003679 if (nb_numa_nodes > 0) {
3680 int i;
3681
Sasha Levinea0e5412011-06-29 23:29:39 -04003682 if (nb_numa_nodes > MAX_NODES) {
3683 nb_numa_nodes = MAX_NODES;
aliguori268a3622009-04-21 22:30:27 +00003684 }
3685
3686 /* If no memory size if given for any node, assume the default case
3687 * and distribute the available memory equally across all nodes
3688 */
3689 for (i = 0; i < nb_numa_nodes; i++) {
3690 if (node_mem[i] != 0)
3691 break;
3692 }
3693 if (i == nb_numa_nodes) {
3694 uint64_t usedmem = 0;
3695
3696 /* On Linux, the each node's border has to be 8MB aligned,
3697 * the final node gets the rest.
3698 */
3699 for (i = 0; i < nb_numa_nodes - 1; i++) {
3700 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
3701 usedmem += node_mem[i];
3702 }
3703 node_mem[i] = ram_size - usedmem;
3704 }
3705
3706 for (i = 0; i < nb_numa_nodes; i++) {
Chegu Vinodee785fe2012-07-16 21:31:30 -07003707 if (!bitmap_empty(node_cpumask[i], MAX_CPUMASK_BITS)) {
aliguori268a3622009-04-21 22:30:27 +00003708 break;
Chegu Vinodee785fe2012-07-16 21:31:30 -07003709 }
aliguori268a3622009-04-21 22:30:27 +00003710 }
3711 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3712 * must cope with this anyway, because there are BIOSes out there in
3713 * real machines which also use this scheme.
3714 */
3715 if (i == nb_numa_nodes) {
Vasilis Liaskovitis991dfef2011-10-26 14:19:00 +02003716 for (i = 0; i < max_cpus; i++) {
Chegu Vinodee785fe2012-07-16 21:31:30 -07003717 set_bit(i, node_cpumask[i % nb_numa_nodes]);
aliguori268a3622009-04-21 22:30:27 +00003718 }
3719 }
3720 }
3721
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003722 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
Jan Kiszka157b9312010-04-06 16:55:53 +02003723 exit(1);
3724 }
3725
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01003726 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
3727 exit(1);
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01003728 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
3729 exit(1);
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01003730 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
3731 exit(1);
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08003732 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
3733 exit(1);
aliguori2796dae2009-01-16 20:23:27 +00003734
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +02003735 /* If no default VGA is requested, the default is "none". */
Aurelien Jarno3605ded2012-09-10 01:01:44 +02003736 if (default_vga) {
3737 if (cirrus_vga_available()) {
3738 vga_model = "cirrus";
3739 } else if (vga_available()) {
3740 vga_model = "std";
3741 }
Blue Swirla369da52011-09-27 19:15:42 +00003742 }
Paolo Bonzini7f1b17f2012-05-10 09:39:17 +02003743 select_vgahw(vga_model);
Blue Swirla369da52011-09-27 19:15:42 +00003744
Markus Armbruster09aaa162009-08-21 10:31:34 +02003745 if (watchdog) {
3746 i = select_watchdog(watchdog);
3747 if (i > 0)
3748 exit (i == 1 ? 1 : 0);
3749 }
3750
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02003751 if (machine->compat_props) {
Gerd Hoffmann458fb672009-12-08 13:11:33 +01003752 qdev_prop_register_global_list(machine->compat_props);
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02003753 }
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01003754 qemu_add_globals();
3755
Anthony Liguori1de81d22011-12-19 16:37:46 -06003756 qdev_machine_init();
3757
Eduardo Habkost5f072e12012-10-15 17:22:02 -03003758 QEMUMachineInitArgs args = { .ram_size = ram_size,
3759 .boot_device = boot_devices,
3760 .kernel_filename = kernel_filename,
3761 .kernel_cmdline = kernel_cmdline,
3762 .initrd_filename = initrd_filename,
3763 .cpu_model = cpu_model };
3764 machine->init(&args);
aliguori3023f332009-01-16 19:04:14 +00003765
Jan Kiszkaea375f92010-03-01 19:10:30 +01003766 cpu_synchronize_all_post_init();
aliguori268a3622009-04-21 22:30:27 +00003767
Blue Swirl87d0a282010-03-27 18:24:45 +00003768 set_numa_modes();
aliguori268a3622009-04-21 22:30:27 +00003769
aliguori6f338c32009-02-11 15:21:54 +00003770 current_machine = machine;
3771
aliguori3023f332009-01-16 19:04:14 +00003772 /* init USB devices */
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +00003773 if (usb_enabled(false)) {
Markus Armbruster07527062009-10-06 12:16:57 +01003774 if (foreach_device_config(DEV_USB, usb_parse) < 0)
3775 exit(1);
aliguori3023f332009-01-16 19:04:14 +00003776 }
3777
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003778 /* init generic devices */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003779 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003780 exit(1);
3781
Markus Armbruster668680f2010-02-11 14:44:58 +01003782 net_check_clients();
3783
aliguori3023f332009-01-16 19:04:14 +00003784 /* just use the first displaystate for the moment */
Paolo Bonzinib473df62010-02-11 00:29:55 +01003785 ds = get_displaystate();
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003786
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003787 if (using_spice)
3788 display_remote++;
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003789 if (display_type == DT_DEFAULT && !display_remote) {
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003790#if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003791 display_type = DT_SDL;
Jes Sorensen821601e2011-03-16 13:33:36 +01003792#elif defined(CONFIG_VNC)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003793 vnc_display = "localhost:0,to=99";
3794 show_vnc_port = 1;
Jes Sorensen821601e2011-03-16 13:33:36 +01003795#else
3796 display_type = DT_NONE;
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003797#endif
3798 }
Jes Sorensen821601e2011-03-16 13:33:36 +01003799
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003800
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003801 /* init local displays */
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003802 switch (display_type) {
3803 case DT_NOGRAPHIC:
3804 break;
3805#if defined(CONFIG_CURSES)
3806 case DT_CURSES:
Hitoshi Mitake995ee2b2012-09-15 01:15:41 +09003807 if (!is_daemonized()) {
3808 curses_display_init(ds, full_screen);
3809 }
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003810 break;
3811#endif
bellard5b0753e2005-03-01 21:37:28 +00003812#if defined(CONFIG_SDL)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003813 case DT_SDL:
3814 sdl_display_init(ds, full_screen, no_frame);
3815 break;
bellard5b0753e2005-03-01 21:37:28 +00003816#elif defined(CONFIG_COCOA)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003817 case DT_SDL:
3818 cocoa_display_init(ds, full_screen);
3819 break;
bellard313aa562003-08-10 21:52:11 +00003820#endif
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003821 default:
3822 break;
3823 }
3824
Gleb Natapov0ce235a2011-03-31 11:27:23 +02003825 /* must be after terminal init, SDL library changes signal handlers */
3826 os_setup_signal_handling();
3827
Jes Sorensen821601e2011-03-16 13:33:36 +01003828#ifdef CONFIG_VNC
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003829 /* init remote displays */
3830 if (vnc_display) {
Paolo Bonzini2d55f0e2012-10-02 10:17:21 +02003831 Error *local_err = NULL;
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003832 vnc_display_init(ds);
Paolo Bonzini2d55f0e2012-10-02 10:17:21 +02003833 vnc_display_open(ds, vnc_display, &local_err);
3834 if (local_err != NULL) {
3835 fprintf(stderr, "Failed to start VNC server on `%s': %s\n",
3836 vnc_display, error_get_pretty(local_err));
3837 error_free(local_err);
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003838 exit(1);
Amos Kong94b204c2012-06-30 10:02:20 +08003839 }
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003840
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003841 if (show_vnc_port) {
3842 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003843 }
bellard313aa562003-08-10 21:52:11 +00003844 }
Jes Sorensen821601e2011-03-16 13:33:36 +01003845#endif
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003846#ifdef CONFIG_SPICE
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +02003847 if (using_spice && !qxl_enabled) {
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003848 qemu_spice_display_init(ds);
3849 }
3850#endif
aliguori5b08fc12008-08-21 20:08:03 +00003851
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003852 /* display setup */
3853 dpy_resize(ds);
aliguori3023f332009-01-16 19:04:14 +00003854 dcl = ds->listeners;
3855 while (dcl != NULL) {
3856 if (dcl->dpy_refresh != NULL) {
Paolo Bonzini7bd427d2011-03-11 16:47:48 +01003857 ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds);
3858 qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock));
Isaku Yamahata0f2ad632010-05-27 14:38:47 +09003859 break;
ths20d8a3e2007-02-18 17:04:49 +00003860 }
aliguori3023f332009-01-16 19:04:14 +00003861 dcl = dcl->next;
bellard82c643f2004-07-14 17:28:13 +00003862 }
Paolo Bonzinib473df62010-02-11 00:29:55 +01003863 text_consoles_set_display(ds);
aliguori2796dae2009-01-16 20:23:27 +00003864
Markus Armbrusteref0c4a02012-02-07 15:09:13 +01003865 if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
aliguori59030a82009-04-05 18:43:41 +00003866 exit(1);
balrog45669e02007-07-02 13:20:17 +00003867 }
balrog45669e02007-07-02 13:20:17 +00003868
Gerd Hoffmann3418bd22009-09-25 21:42:41 +02003869 qdev_machine_creation_done();
3870
Gerd Hoffmann15ff7702009-12-14 16:07:35 +01003871 if (rom_load_all() != 0) {
3872 fprintf(stderr, "rom loading failed\n");
3873 exit(1);
3874 }
Gerd Hoffmann45a50b12009-10-01 16:42:33 +02003875
Isaku Yamahata80376c32010-12-20 14:33:35 +09003876 /* TODO: once all bus devices are qdevified, this should be done
3877 * when bus is created by qdev.c */
3878 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
Gleb Natapov4cab9462010-12-08 13:35:08 +02003879 qemu_run_machine_init_done_notifiers();
3880
Jan Kiszkae063eb12011-06-14 18:29:43 +02003881 qemu_system_reset(VMRESET_SILENT);
Juan Quintela05f24012009-08-20 19:42:22 +02003882 if (loadvm) {
Markus Armbruster03cd4652010-02-17 16:24:10 +01003883 if (load_vmstate(loadvm) < 0) {
Juan Quintela05f24012009-08-20 19:42:22 +02003884 autostart = 0;
3885 }
3886 }
bellardd63d3072004-10-03 13:29:03 +00003887
Glauber Costa2bb8c102009-07-24 16:20:23 -04003888 if (incoming) {
Paolo Bonzini43eaae22012-10-02 18:21:18 +02003889 Error *local_err = NULL;
3890 qemu_start_incoming_migration(incoming, &local_err);
3891 if (local_err) {
3892 fprintf(stderr, "-incoming %s: %s\n", incoming, error_get_pretty(local_err));
3893 error_free(local_err);
3894 exit(1);
Juan Quintela8ca5e802010-06-09 14:10:54 +02003895 }
Avi Kivity6b99dad2009-08-09 14:39:20 +03003896 } else if (autostart) {
aliguoric0f4ce72009-03-05 23:01:01 +00003897 vm_start();
Avi Kivity6b99dad2009-08-09 14:39:20 +03003898 }
thsffd843b2006-12-21 19:46:43 +00003899
Jes Sorenseneb505be2010-06-10 11:42:28 +02003900 os_setup_post();
ths71e3ceb2006-12-22 02:11:31 +00003901
Paolo Bonzini99435902011-09-12 14:03:13 +02003902 resume_all_vcpus();
bellard8a7ddc32004-03-31 19:00:16 +00003903 main_loop();
Paolo Bonzini99435902011-09-12 14:03:13 +02003904 bdrv_close_all();
3905 pause_all_vcpus();
aliguori63a01ef2008-10-31 19:10:00 +00003906 net_cleanup();
wayne3d3b8302011-07-27 18:04:55 +08003907 res_free();
thsb46a8902007-10-21 23:20:45 +00003908
bellard0824d6f2003-06-24 13:42:40 +00003909 return 0;
3910}