blob: 16fa222f1a56f675cf28bef93406bf56162b8302 [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>
bellard67b915a2004-03-31 23:37:16 +000031
Juan Quintela71e72a12009-07-27 16:12:56 +020032/* Needed early for CONFIG_BSD etc. */
blueswir1d40cdb12009-03-07 16:52:02 +000033#include "config-host.h"
34
bellard67b915a2004-03-31 23:37:16 +000035#ifndef _WIN32
Paul Brook5cea8592009-05-30 00:52:44 +010036#include <libgen.h>
bellard67b915a2004-03-31 23:37:16 +000037#include <sys/times.h>
bellardf1510b22003-06-25 00:07:40 +000038#include <sys/wait.h>
bellard67b915a2004-03-31 23:37:16 +000039#include <termios.h>
bellard67b915a2004-03-31 23:37:16 +000040#include <sys/mman.h>
bellardf1510b22003-06-25 00:07:40 +000041#include <sys/ioctl.h>
blueswir124646c72008-11-07 16:55:48 +000042#include <sys/resource.h>
bellardf1510b22003-06-25 00:07:40 +000043#include <sys/socket.h>
bellardc94c8d62004-09-13 21:37:34 +000044#include <netinet/in.h>
blueswir124646c72008-11-07 16:55:48 +000045#include <net/if.h>
blueswir124646c72008-11-07 16:55:48 +000046#include <arpa/inet.h>
bellard9d728e82004-09-05 23:09:03 +000047#include <dirent.h>
bellard7c9d8e02005-11-15 22:16:05 +000048#include <netdb.h>
thscb4b9762007-09-13 12:39:35 +000049#include <sys/select.h>
Prerna Saxenaab6540d2010-08-09 11:48:32 +010050
Juan Quintela71e72a12009-07-27 16:12:56 +020051#ifdef CONFIG_BSD
bellard7d3505c2004-05-12 19:32:15 +000052#include <sys/stat.h>
Aurelien Jarnoa167ba52009-11-29 18:00:41 +010053#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
bellard7d3505c2004-05-12 19:32:15 +000054#include <libutil.h>
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 <pty.h>
62#include <malloc.h>
thsbd494f42007-09-16 20:03:23 +000063
bellarde57a8c02005-11-10 23:58:52 +000064#include <linux/ppdev.h>
ths5867c882007-02-17 23:44:43 +000065#include <linux/parport.h>
blueswir1223f0d72008-09-30 18:12:18 +000066#endif
67#ifdef __sun__
thsd5d10bc2007-02-17 22:54:49 +000068#include <sys/stat.h>
69#include <sys/ethernet.h>
70#include <sys/sockio.h>
thsd5d10bc2007-02-17 22:54:49 +000071#include <netinet/arp.h>
thsd5d10bc2007-02-17 22:54:49 +000072#include <netinet/in_systm.h>
73#include <netinet/ip.h>
74#include <netinet/ip_icmp.h> // must come after ip.h
75#include <netinet/udp.h>
76#include <netinet/tcp.h>
77#include <net/if.h>
78#include <syslog.h>
79#include <stropts.h>
bellard67b915a2004-03-31 23:37:16 +000080#endif
bellard7d3505c2004-05-12 19:32:15 +000081#endif
bellardec530c82006-04-25 22:36:06 +000082#endif
bellard67b915a2004-03-31 23:37:16 +000083
blueswir19892fbf2008-08-24 10:34:20 +000084#if defined(__OpenBSD__)
85#include <util.h>
86#endif
87
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"
139#include "block.h"
Markus Armbruster666daa62010-06-02 18:48:27 +0200140#include "blockdev.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
blueswir1511d2b12009-03-07 15:32:56 +0000155
bellard0824d6f2003-06-24 13:42:40 +0000156#include "disas.h"
bellardfc01f7e2003-06-30 10:03:06 +0000157
blueswir1511d2b12009-03-07 15:32:56 +0000158#include "qemu_socket.h"
159
Jan Kiszkad918f232009-06-24 14:42:30 +0200160#include "slirp/libslirp.h"
blueswir1511d2b12009-03-07 15:32:56 +0000161
Stefan Hajnoczi94b0b5f2010-11-16 12:20:25 +0000162#include "trace.h"
Lluíse4858972011-08-31 20:31:03 +0200163#include "trace/control.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +0000164#include "qemu-queue.h"
Blue Swirl296af7c2010-03-29 19:23:50 +0000165#include "cpus.h"
Blue Swirlad960902010-03-29 19:23:52 +0000166#include "arch_init.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +0000167
Gerd Hoffmann29b00402010-03-11 11:13:27 -0300168#include "ui/qemu-spice.h"
169
blueswir19dc63a12008-10-04 07:25:46 +0000170//#define DEBUG_NET
171//#define DEBUG_SLIRP
bellard330d0412003-07-26 18:11:40 +0000172
bellard1bfe8562004-07-08 21:17:50 +0000173#define DEFAULT_RAM_SIZE 128
bellard313aa562003-08-10 21:52:11 +0000174
Amit Shah98b19252010-01-20 00:36:52 +0530175#define MAX_VIRTIO_CONSOLES 1
176
Paul Brook5cea8592009-05-30 00:52:44 +0100177static const char *data_dir;
j_mayer1192dad2007-10-05 13:08:35 +0000178const char *bios_name = NULL;
malccb5a7aa2008-09-28 00:42:12 +0000179enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
Anthony Liguori993fbfd2009-05-21 16:54:00 -0500180DisplayType display_type = DT_DEFAULT;
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +0200181int display_remote = 0;
bellard3d11d0e2004-12-12 16:56:30 +0000182const char* keyboard_layout = NULL;
Anthony Liguoric227f092009-10-01 16:12:16 -0500183ram_addr_t ram_size;
Marcelo Tosattic9027602010-03-01 20:25:08 -0300184const char *mem_path = NULL;
185#ifdef MAP_POPULATE
186int mem_prealloc = 0; /* force preallocation of physical target memory */
187#endif
bellardc4b1fcc2004-03-14 21:44:30 +0000188int nb_nics;
bellard7c9d8e02005-11-15 22:16:05 +0000189NICInfo nd_table[MAX_NICS];
Paolo Bonzinid399f672009-07-27 23:17:51 +0200190int autostart;
balrogf6503052008-02-17 11:42:19 +0000191static int rtc_utc = 1;
192static int rtc_date_offset = -1; /* -1 means no change */
Jan Kiszka68752042009-09-15 13:36:04 +0200193QEMUClock *rtc_clock;
Gerd Hoffmann64465292009-12-08 13:11:45 +0100194int vga_interface_type = VGA_NONE;
blueswir1dbed7e42008-10-01 19:38:09 +0000195static int full_screen = 0;
blueswir1634a21f2008-11-16 11:34:07 +0000196#ifdef CONFIG_SDL
blueswir1dbed7e42008-10-01 19:38:09 +0000197static int no_frame = 0;
blueswir1634a21f2008-11-16 11:34:07 +0000198#endif
ths667acca2006-12-11 02:08:05 +0000199int no_quit = 0;
bellard8d11df92004-08-24 21:13:40 +0000200CharDriverState *serial_hds[MAX_SERIAL_PORTS];
bellard6508fe52005-01-15 12:02:56 +0000201CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
aliguori9ede2fd2009-01-15 20:05:25 +0000202CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
bellarda09db212005-04-30 16:10:35 +0000203int win2k_install_hack = 0;
aliguori73822ec2009-01-15 20:11:34 +0000204int rtc_td_hack = 0;
bellardbb36d472005-11-05 14:22:28 +0000205int usb_enabled = 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;
Jes Sorensen6b35e7b2009-08-06 16:25:50 +0200221uint8_t irq0override = 1;
Markus Armbruster09aaa162009-08-21 10:31:34 +0200222const char *watchdog;
Gleb Natapov2e55e842010-12-08 13:35:07 +0200223QEMUOptionRom option_rom[MAX_OPTION_ROMS];
ths9ae02552007-01-05 17:39:04 +0000224int nb_option_roms;
pbrook8e716212007-01-20 17:12:09 +0000225int semihosting_enabled = 0;
balrog2b8f2d42007-07-27 22:08:46 +0000226int old_param = 0;
thsc35734b2007-03-19 15:17:08 +0000227const char *qemu_name;
ths3780e192007-06-21 21:08:02 +0000228int alt_grab = 0;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -0500229int ctrl_grab = 0;
blueswir166508602007-05-01 14:16:52 +0000230unsigned int nb_prom_envs = 0;
231const char *prom_envs[MAX_PROM_ENVS];
Jan Kiszka95387492009-07-02 00:19:02 +0200232int boot_menu;
wayne3d3b8302011-07-27 18:04:55 +0800233uint8_t *boot_splash_filedata;
234int boot_splash_filedata_size;
235uint8_t qemu_extra_params_fw[2];
bellard0824d6f2003-06-24 13:42:40 +0000236
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200237typedef struct FWBootEntry FWBootEntry;
238
239struct FWBootEntry {
240 QTAILQ_ENTRY(FWBootEntry) link;
241 int32_t bootindex;
242 DeviceState *dev;
243 char *suffix;
244};
245
246QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order);
247
aliguori268a3622009-04-21 22:30:27 +0000248int nb_numa_nodes;
249uint64_t node_mem[MAX_NODES];
250uint64_t node_cpumask[MAX_NODES];
251
blueswir18fcb1b92008-09-18 18:29:08 +0000252uint8_t qemu_uuid[16];
253
Jan Kiszka76e30d02009-07-02 00:19:02 +0200254static QEMUBootSetHandler *boot_set_handler;
255static void *boot_set_opaque;
256
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +0200257static NotifierList exit_notifiers =
258 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
259
Gleb Natapov4cab9462010-12-08 13:35:08 +0200260static NotifierList machine_init_done_notifiers =
261 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
262
Anthony PERARD303d4e82010-09-21 20:05:31 +0100263static int tcg_allowed = 1;
Blue Swirld745bef2010-03-29 19:23:49 +0000264int kvm_allowed = 0;
Anthony PERARD3285cf42010-08-19 12:27:56 +0100265int xen_allowed = 0;
Blue Swirld745bef2010-03-29 19:23:49 +0000266uint32_t xen_domid;
267enum xen_mode xen_mode = XEN_EMULATE;
Jan Kiszkad5ab9712011-08-02 16:10:21 +0200268static int tcg_tb_size;
Blue Swirld745bef2010-03-29 19:23:49 +0000269
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100270static int default_serial = 1;
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +0100271static int default_parallel = 1;
Gerd Hoffmann986c5f72009-12-08 13:11:54 +0100272static int default_virtcon = 1;
Gerd Hoffmannabdeed02009-12-08 13:11:43 +0100273static int default_monitor = 1;
Gerd Hoffmann64465292009-12-08 13:11:45 +0100274static int default_vga = 1;
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +0100275static int default_floppy = 1;
276static int default_cdrom = 1;
277static int default_sdcard = 1;
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100278
279static struct {
280 const char *driver;
281 int *flag;
282} default_list[] = {
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +0100283 { .driver = "isa-serial", .flag = &default_serial },
284 { .driver = "isa-parallel", .flag = &default_parallel },
Gerd Hoffmannd8bcbab2009-12-16 14:25:40 +0100285 { .driver = "isa-fdc", .flag = &default_floppy },
Markus Armbrusteraf6bf132011-05-18 18:31:02 +0200286 { .driver = "ide-cd", .flag = &default_cdrom },
287 { .driver = "ide-hd", .flag = &default_cdrom },
Gerd Hoffmannd8bcbab2009-12-16 14:25:40 +0100288 { .driver = "ide-drive", .flag = &default_cdrom },
Markus Armbrusteraf6bf132011-05-18 18:31:02 +0200289 { .driver = "scsi-cd", .flag = &default_cdrom },
Amit Shah392ecf52010-01-21 16:19:23 +0530290 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
291 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
292 { .driver = "virtio-serial", .flag = &default_virtcon },
Gerd Hoffmann64465292009-12-08 13:11:45 +0100293 { .driver = "VGA", .flag = &default_vga },
Gerd Hoffmann69fd02e2009-12-16 13:35:19 +0100294 { .driver = "cirrus-vga", .flag = &default_vga },
295 { .driver = "vmware-svga", .flag = &default_vga },
Markus Armbruster0826c712011-06-07 10:34:30 +0200296 { .driver = "isa-vga", .flag = &default_vga },
Gerd Hoffmann42138042011-05-16 09:28:58 +0200297 { .driver = "qxl-vga", .flag = &default_vga },
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100298};
299
wayne3d3b8302011-07-27 18:04:55 +0800300static void res_free(void)
301{
302 if (boot_splash_filedata != NULL) {
Anthony Liguori7267c092011-08-20 22:09:37 -0500303 g_free(boot_splash_filedata);
wayne3d3b8302011-07-27 18:04:55 +0800304 boot_splash_filedata = NULL;
305 }
306}
307
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100308static int default_driver_check(QemuOpts *opts, void *opaque)
309{
310 const char *driver = qemu_opt_get(opts, "driver");
311 int i;
312
313 if (!driver)
314 return 0;
315 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
316 if (strcmp(default_list[i].driver, driver) != 0)
317 continue;
318 *(default_list[i].flag) = 0;
319 }
320 return 0;
321}
322
bellard0824d6f2003-06-24 13:42:40 +0000323/***********************************************************/
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300324/* QEMU state */
325
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300326static RunState current_run_state = RUN_STATE_PRELAUNCH;
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300327
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300328typedef struct {
329 RunState from;
330 RunState to;
331} RunStateTransition;
332
333static const RunStateTransition runstate_transitions_def[] = {
334 /* from -> to */
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300335 { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300336
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300337 { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },
338 { RUN_STATE_INMIGRATE, RUN_STATE_PRELAUNCH },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300339
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300340 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300341 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300342
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300343 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300344 { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300345
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300346 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300347 { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300348
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300349 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300350 { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300351
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300352 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300353 { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300354 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300355
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300356 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
357 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300358
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300359 { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300360
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300361 { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
362 { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
363 { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
364 { RUN_STATE_RUNNING, RUN_STATE_PAUSED },
365 { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE },
366 { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM },
367 { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM },
368 { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
369 { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300370
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300371 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300372
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300373 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300374 { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300375
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300376 { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
Luiz Capitulino8a9236f2011-10-14 11:18:09 -0300377 { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300378
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300379 { RUN_STATE_MAX, RUN_STATE_MAX },
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300380};
381
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300382static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX];
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300383
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300384bool runstate_check(RunState state)
385{
386 return current_run_state == state;
387}
388
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300389void runstate_init(void)
390{
391 const RunStateTransition *p;
392
393 memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions));
394
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300395 for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) {
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300396 runstate_valid_transitions[p->from][p->to] = true;
397 }
398}
399
400/* This function will abort() on invalid state transitions */
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300401void runstate_set(RunState new_state)
402{
Luiz Capitulino207c5cd2011-10-13 10:59:07 -0300403 assert(new_state < RUN_STATE_MAX);
404
405 if (!runstate_valid_transitions[current_run_state][new_state]) {
406 fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
407 RunState_lookup[current_run_state],
408 RunState_lookup[new_state]);
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -0300409 abort();
410 }
411
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300412 current_run_state = new_state;
413}
414
Luiz Capitulino13548692011-07-29 15:36:43 -0300415int runstate_is_running(void)
416{
Luiz Capitulino0461d5a2011-09-30 14:45:27 -0300417 return runstate_check(RUN_STATE_RUNNING);
Luiz Capitulino13548692011-07-29 15:36:43 -0300418}
419
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -0300420StatusInfo *qmp_query_status(Error **errp)
421{
422 StatusInfo *info = g_malloc0(sizeof(*info));
423
424 info->running = runstate_is_running();
425 info->singlestep = singlestep;
426 info->status = current_run_state;
427
428 return info;
429}
430
Luiz Capitulinof5bbfba2011-07-29 15:04:45 -0300431/***********************************************************/
Paolo Bonzini8f0056b2010-01-13 14:05:34 +0100432/* real time host monotonic timer */
bellard09b26c52006-04-12 21:09:08 +0000433
bellardc4b1fcc2004-03-14 21:44:30 +0000434/***********************************************************/
balrogf6503052008-02-17 11:42:19 +0000435/* host time/date access */
436void qemu_get_timedate(struct tm *tm, int offset)
437{
438 time_t ti;
439 struct tm *ret;
440
441 time(&ti);
442 ti += offset;
443 if (rtc_date_offset == -1) {
444 if (rtc_utc)
445 ret = gmtime(&ti);
446 else
447 ret = localtime(&ti);
448 } else {
449 ti -= rtc_date_offset;
450 ret = gmtime(&ti);
451 }
452
453 memcpy(tm, ret, sizeof(struct tm));
454}
455
456int qemu_timedate_diff(struct tm *tm)
457{
458 time_t seconds;
459
460 if (rtc_date_offset == -1)
461 if (rtc_utc)
462 seconds = mktimegm(tm);
Gleb Natapovf54c5562011-11-06 18:00:22 +0200463 else {
464 struct tm tmp = *tm;
465 tmp.tm_isdst = -1; /* use timezone to figure it out */
466 seconds = mktime(&tmp);
467 }
balrogf6503052008-02-17 11:42:19 +0000468 else
469 seconds = mktimegm(tm) + rtc_date_offset;
470
471 return seconds - time(NULL);
472}
473
Luiz Capitulino80cd3472010-02-25 12:11:44 -0300474void rtc_change_mon_event(struct tm *tm)
475{
476 QObject *data;
477
478 data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
479 monitor_protocol_event(QEVENT_RTC_CHANGE, data);
480 qobject_decref(data);
481}
482
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200483static void configure_rtc_date_offset(const char *startdate, int legacy)
484{
485 time_t rtc_start_date;
486 struct tm tm;
487
488 if (!strcmp(startdate, "now") && legacy) {
489 rtc_date_offset = -1;
490 } else {
491 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
492 &tm.tm_year,
493 &tm.tm_mon,
494 &tm.tm_mday,
495 &tm.tm_hour,
496 &tm.tm_min,
497 &tm.tm_sec) == 6) {
498 /* OK */
499 } else if (sscanf(startdate, "%d-%d-%d",
500 &tm.tm_year,
501 &tm.tm_mon,
502 &tm.tm_mday) == 3) {
503 tm.tm_hour = 0;
504 tm.tm_min = 0;
505 tm.tm_sec = 0;
506 } else {
507 goto date_fail;
508 }
509 tm.tm_year -= 1900;
510 tm.tm_mon--;
511 rtc_start_date = mktimegm(&tm);
512 if (rtc_start_date == -1) {
513 date_fail:
514 fprintf(stderr, "Invalid date format. Valid formats are:\n"
515 "'2006-06-17T16:01:21' or '2006-06-17'\n");
516 exit(1);
517 }
518 rtc_date_offset = time(NULL) - rtc_start_date;
519 }
520}
521
522static void configure_rtc(QemuOpts *opts)
523{
524 const char *value;
525
526 value = qemu_opt_get(opts, "base");
527 if (value) {
528 if (!strcmp(value, "utc")) {
529 rtc_utc = 1;
530 } else if (!strcmp(value, "localtime")) {
531 rtc_utc = 0;
532 } else {
533 configure_rtc_date_offset(value, 0);
534 }
535 }
Jan Kiszka68752042009-09-15 13:36:04 +0200536 value = qemu_opt_get(opts, "clock");
537 if (value) {
538 if (!strcmp(value, "host")) {
539 rtc_clock = host_clock;
540 } else if (!strcmp(value, "vm")) {
541 rtc_clock = vm_clock;
542 } else {
543 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
544 exit(1);
545 }
546 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200547 value = qemu_opt_get(opts, "driftfix");
548 if (value) {
Blue Swirl7e4c0332010-03-27 21:33:46 +0000549 if (!strcmp(value, "slew")) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200550 rtc_td_hack = 1;
Blue Swirl7e4c0332010-03-27 21:33:46 +0000551 } else if (!strcmp(value, "none")) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200552 rtc_td_hack = 0;
553 } else {
554 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
555 exit(1);
556 }
557 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200558}
559
balrog1ae26a12008-09-28 23:19:47 +0000560/***********************************************************/
561/* Bluetooth support */
562static int nb_hcis;
563static int cur_hci;
564static struct HCIInfo *hci_table[MAX_NICS];
balrogdc72ac12008-11-09 00:04:26 +0000565
balrog1ae26a12008-09-28 23:19:47 +0000566static struct bt_vlan_s {
567 struct bt_scatternet_s net;
568 int id;
569 struct bt_vlan_s *next;
570} *first_bt_vlan;
571
572/* find or alloc a new bluetooth "VLAN" */
blueswir1674bb262008-09-30 18:18:27 +0000573static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
balrog1ae26a12008-09-28 23:19:47 +0000574{
575 struct bt_vlan_s **pvlan, *vlan;
576 for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) {
577 if (vlan->id == id)
578 return &vlan->net;
579 }
Anthony Liguori7267c092011-08-20 22:09:37 -0500580 vlan = g_malloc0(sizeof(struct bt_vlan_s));
balrog1ae26a12008-09-28 23:19:47 +0000581 vlan->id = id;
582 pvlan = &first_bt_vlan;
583 while (*pvlan != NULL)
584 pvlan = &(*pvlan)->next;
585 *pvlan = vlan;
586 return &vlan->net;
587}
588
589static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
590{
591}
592
593static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
594{
595 return -ENOTSUP;
596}
597
598static struct HCIInfo null_hci = {
599 .cmd_send = null_hci_send,
600 .sco_send = null_hci_send,
601 .acl_send = null_hci_send,
602 .bdaddr_set = null_hci_addr_set,
603};
604
605struct HCIInfo *qemu_next_hci(void)
606{
607 if (cur_hci == nb_hcis)
608 return &null_hci;
609
610 return hci_table[cur_hci++];
611}
612
balrogdc72ac12008-11-09 00:04:26 +0000613static struct HCIInfo *hci_init(const char *str)
614{
615 char *endp;
616 struct bt_scatternet_s *vlan = 0;
617
618 if (!strcmp(str, "null"))
619 /* null */
620 return &null_hci;
621 else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':'))
622 /* host[:hciN] */
623 return bt_host_hci(str[4] ? str + 5 : "hci0");
624 else if (!strncmp(str, "hci", 3)) {
625 /* hci[,vlan=n] */
626 if (str[3]) {
627 if (!strncmp(str + 3, ",vlan=", 6)) {
628 vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0));
629 if (*endp)
630 vlan = 0;
631 }
632 } else
633 vlan = qemu_find_bt_vlan(0);
634 if (vlan)
635 return bt_new_hci(vlan);
636 }
637
638 fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
639
640 return 0;
641}
642
643static int bt_hci_parse(const char *str)
644{
645 struct HCIInfo *hci;
Anthony Liguoric227f092009-10-01 16:12:16 -0500646 bdaddr_t bdaddr;
balrogdc72ac12008-11-09 00:04:26 +0000647
648 if (nb_hcis >= MAX_NICS) {
649 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
650 return -1;
651 }
652
653 hci = hci_init(str);
654 if (!hci)
655 return -1;
656
657 bdaddr.b[0] = 0x52;
658 bdaddr.b[1] = 0x54;
659 bdaddr.b[2] = 0x00;
660 bdaddr.b[3] = 0x12;
661 bdaddr.b[4] = 0x34;
662 bdaddr.b[5] = 0x56 + nb_hcis;
663 hci->bdaddr_set(hci, bdaddr.b);
664
665 hci_table[nb_hcis++] = hci;
666
667 return 0;
668}
669
670static void bt_vhci_add(int vlan_id)
671{
672 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
673
674 if (!vlan->slave)
675 fprintf(stderr, "qemu: warning: adding a VHCI to "
676 "an empty scatternet %i\n", vlan_id);
677
678 bt_vhci_init(bt_new_hci(vlan));
679}
680
681static struct bt_device_s *bt_device_add(const char *opt)
682{
683 struct bt_scatternet_s *vlan;
684 int vlan_id = 0;
685 char *endp = strstr(opt, ",vlan=");
686 int len = (endp ? endp - opt : strlen(opt)) + 1;
687 char devname[10];
688
689 pstrcpy(devname, MIN(sizeof(devname), len), opt);
690
691 if (endp) {
692 vlan_id = strtol(endp + 6, &endp, 0);
693 if (*endp) {
694 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
695 return 0;
696 }
697 }
698
699 vlan = qemu_find_bt_vlan(vlan_id);
700
701 if (!vlan->slave)
702 fprintf(stderr, "qemu: warning: adding a slave device to "
703 "an empty scatternet %i\n", vlan_id);
704
705 if (!strcmp(devname, "keyboard"))
706 return bt_keyboard_init(vlan);
707
708 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
709 return 0;
710}
711
712static int bt_parse(const char *opt)
713{
714 const char *endp, *p;
715 int vlan;
716
717 if (strstart(opt, "hci", &endp)) {
718 if (!*endp || *endp == ',') {
719 if (*endp)
720 if (!strstart(endp, ",vlan=", 0))
721 opt = endp + 1;
722
723 return bt_hci_parse(opt);
724 }
725 } else if (strstart(opt, "vhci", &endp)) {
726 if (!*endp || *endp == ',') {
727 if (*endp) {
728 if (strstart(endp, ",vlan=", &p)) {
729 vlan = strtol(p, (char **) &endp, 0);
730 if (*endp) {
731 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
732 return 1;
733 }
734 } else {
735 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
736 return 1;
737 }
738 } else
739 vlan = 0;
740
741 bt_vhci_add(vlan);
742 return 0;
743 }
744 } else if (strstart(opt, "device:", &endp))
745 return !bt_device_add(endp);
746
747 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
748 return 1;
749}
750
balrog1ae26a12008-09-28 23:19:47 +0000751/***********************************************************/
752/* QEMU Block devices */
753
Markus Armbruster2292dda2011-01-28 11:21:41 +0100754#define HD_OPTS "media=disk"
755#define CDROM_OPTS "media=cdrom"
756#define FD_OPTS ""
757#define PFLASH_OPTS ""
758#define MTD_OPTS ""
759#define SD_OPTS ""
thse4bcb142007-12-02 04:51:10 +0000760
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200761static int drive_init_func(QemuOpts *opts, void *opaque)
762{
Markus Armbrustera803cb82010-06-02 13:31:55 +0200763 int *use_scsi = opaque;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200764
Markus Armbruster319ae522011-01-28 11:21:46 +0100765 return drive_init(opts, *use_scsi) == NULL;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200766}
767
768static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
769{
770 if (NULL == qemu_opt_get(opts, "snapshot")) {
771 qemu_opt_set(opts, "snapshot", "on");
772 }
773 return 0;
774}
775
Markus Armbruster4e5d9b52011-01-28 11:21:45 +0100776static void default_drive(int enable, int snapshot, int use_scsi,
777 BlockInterfaceType type, int index,
778 const char *optstr)
779{
780 QemuOpts *opts;
781
782 if (type == IF_DEFAULT) {
783 type = use_scsi ? IF_SCSI : IF_IDE;
784 }
785
786 if (!enable || drive_get_by_index(type, index)) {
787 return;
788 }
789
790 opts = drive_add(type, index, NULL, optstr);
791 if (snapshot) {
792 drive_enable_snapshot(opts, NULL);
793 }
Markus Armbruster319ae522011-01-28 11:21:46 +0100794 if (!drive_init(opts, use_scsi)) {
Markus Armbruster4e5d9b52011-01-28 11:21:45 +0100795 exit(1);
796 }
797}
798
Jan Kiszka76e30d02009-07-02 00:19:02 +0200799void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
800{
801 boot_set_handler = func;
802 boot_set_opaque = opaque;
803}
804
805int qemu_boot_set(const char *boot_devices)
806{
807 if (!boot_set_handler) {
808 return -EINVAL;
809 }
810 return boot_set_handler(boot_set_opaque, boot_devices);
811}
812
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -0300813static void validate_bootdevices(char *devices)
Jan Kiszkaef3adf62009-07-02 00:19:02 +0200814{
815 /* We just do some generic consistency checks */
816 const char *p;
817 int bitmap = 0;
818
819 for (p = devices; *p != '\0'; p++) {
820 /* Allowed boot devices are:
821 * a-b: floppy disk drives
822 * c-f: IDE disk drives
823 * g-m: machine implementation dependant drives
824 * n-p: network devices
825 * It's up to each machine implementation to check if the given boot
826 * devices match the actual hardware implementation and firmware
827 * features.
828 */
829 if (*p < 'a' || *p > 'p') {
830 fprintf(stderr, "Invalid boot device '%c'\n", *p);
831 exit(1);
832 }
833 if (bitmap & (1 << (*p - 'a'))) {
834 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
835 exit(1);
836 }
837 bitmap |= 1 << (*p - 'a');
838 }
Jan Kiszkaef3adf62009-07-02 00:19:02 +0200839}
840
Jan Kiszkae0f084b2009-07-02 00:19:02 +0200841static void restore_boot_devices(void *opaque)
842{
843 char *standard_boot_devices = opaque;
Alex Williamson37905d62010-04-30 15:21:11 -0600844 static int first = 1;
845
846 /* Restore boot order and remove ourselves after the first boot */
847 if (first) {
848 first = 0;
849 return;
850 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +0200851
852 qemu_boot_set(standard_boot_devices);
853
854 qemu_unregister_reset(restore_boot_devices, standard_boot_devices);
Anthony Liguori7267c092011-08-20 22:09:37 -0500855 g_free(standard_boot_devices);
Jan Kiszkae0f084b2009-07-02 00:19:02 +0200856}
857
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200858void add_boot_device_path(int32_t bootindex, DeviceState *dev,
859 const char *suffix)
860{
861 FWBootEntry *node, *i;
862
863 if (bootindex < 0) {
864 return;
865 }
866
867 assert(dev != NULL || suffix != NULL);
868
Anthony Liguori7267c092011-08-20 22:09:37 -0500869 node = g_malloc0(sizeof(FWBootEntry));
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200870 node->bootindex = bootindex;
Anthony Liguori7267c092011-08-20 22:09:37 -0500871 node->suffix = suffix ? g_strdup(suffix) : NULL;
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200872 node->dev = dev;
873
874 QTAILQ_FOREACH(i, &fw_boot_order, link) {
875 if (i->bootindex == bootindex) {
876 fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
877 exit(1);
878 } else if (i->bootindex < bootindex) {
879 continue;
880 }
881 QTAILQ_INSERT_BEFORE(i, node, link);
882 return;
883 }
884 QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
885}
886
Gleb Natapov962630f2010-12-08 13:35:09 +0200887/*
888 * This function returns null terminated string that consist of new line
Brad Hards71785ab2011-04-23 21:50:06 +1000889 * separated device paths.
Gleb Natapov962630f2010-12-08 13:35:09 +0200890 *
891 * memory pointed by "size" is assigned total length of the array in bytes
892 *
893 */
894char *get_boot_devices_list(uint32_t *size)
895{
896 FWBootEntry *i;
897 uint32_t total = 0;
898 char *list = NULL;
899
900 QTAILQ_FOREACH(i, &fw_boot_order, link) {
901 char *devpath = NULL, *bootpath;
902 int len;
903
904 if (i->dev) {
905 devpath = qdev_get_fw_dev_path(i->dev);
906 assert(devpath);
907 }
908
909 if (i->suffix && devpath) {
Blue Swirl4fd37a92010-12-19 14:05:43 +0000910 size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
911
Anthony Liguori7267c092011-08-20 22:09:37 -0500912 bootpath = g_malloc(bootpathlen);
Blue Swirl4fd37a92010-12-19 14:05:43 +0000913 snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
Anthony Liguori7267c092011-08-20 22:09:37 -0500914 g_free(devpath);
Gleb Natapov962630f2010-12-08 13:35:09 +0200915 } else if (devpath) {
916 bootpath = devpath;
917 } else {
Markus Armbruster1bf6ccd2011-11-08 10:58:00 +0100918 assert(i->suffix);
Anthony Liguori7267c092011-08-20 22:09:37 -0500919 bootpath = g_strdup(i->suffix);
Gleb Natapov962630f2010-12-08 13:35:09 +0200920 }
921
922 if (total) {
923 list[total-1] = '\n';
924 }
925 len = strlen(bootpath) + 1;
Anthony Liguori7267c092011-08-20 22:09:37 -0500926 list = g_realloc(list, total + len);
Gleb Natapov962630f2010-12-08 13:35:09 +0200927 memcpy(&list[total], bootpath, len);
928 total += len;
Anthony Liguori7267c092011-08-20 22:09:37 -0500929 g_free(bootpath);
Gleb Natapov962630f2010-12-08 13:35:09 +0200930 }
931
932 *size = total;
933
934 return list;
935}
936
aliguori268a3622009-04-21 22:30:27 +0000937static void numa_add(const char *optarg)
938{
939 char option[128];
940 char *endptr;
941 unsigned long long value, endvalue;
942 int nodenr;
943
944 optarg = get_opt_name(option, 128, optarg, ',') + 1;
945 if (!strcmp(option, "node")) {
946 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
947 nodenr = nb_numa_nodes;
948 } else {
949 nodenr = strtoull(option, NULL, 10);
950 }
951
952 if (get_param_value(option, 128, "mem", optarg) == 0) {
953 node_mem[nodenr] = 0;
954 } else {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +0100955 int64_t sval;
Jes Sorensen9f9b17a2010-10-21 17:15:46 +0200956 sval = strtosz(option, NULL);
957 if (sval < 0) {
958 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
959 exit(1);
aliguori268a3622009-04-21 22:30:27 +0000960 }
Jes Sorensen9f9b17a2010-10-21 17:15:46 +0200961 node_mem[nodenr] = sval;
aliguori268a3622009-04-21 22:30:27 +0000962 }
963 if (get_param_value(option, 128, "cpus", optarg) == 0) {
964 node_cpumask[nodenr] = 0;
965 } else {
966 value = strtoull(option, &endptr, 10);
967 if (value >= 64) {
968 value = 63;
969 fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n");
970 } else {
971 if (*endptr == '-') {
972 endvalue = strtoull(endptr+1, &endptr, 10);
973 if (endvalue >= 63) {
974 endvalue = 62;
975 fprintf(stderr,
976 "only 63 CPUs in NUMA mode supported.\n");
977 }
Paolo Bonzini0dfbd512010-02-04 14:31:50 +0100978 value = (2ULL << endvalue) - (1ULL << value);
aliguori268a3622009-04-21 22:30:27 +0000979 } else {
Paolo Bonzini0dfbd512010-02-04 14:31:50 +0100980 value = 1ULL << value;
aliguori268a3622009-04-21 22:30:27 +0000981 }
982 }
983 node_cpumask[nodenr] = value;
984 }
985 nb_numa_nodes++;
986 }
987 return;
988}
989
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200990static void smp_parse(const char *optarg)
991{
992 int smp, sockets = 0, threads = 0, cores = 0;
993 char *endptr;
994 char option[128];
995
996 smp = strtoul(optarg, &endptr, 10);
997 if (endptr != optarg) {
998 if (*endptr == ',') {
999 endptr++;
1000 }
1001 }
1002 if (get_param_value(option, 128, "sockets", endptr) != 0)
1003 sockets = strtoull(option, NULL, 10);
1004 if (get_param_value(option, 128, "cores", endptr) != 0)
1005 cores = strtoull(option, NULL, 10);
1006 if (get_param_value(option, 128, "threads", endptr) != 0)
1007 threads = strtoull(option, NULL, 10);
1008 if (get_param_value(option, 128, "maxcpus", endptr) != 0)
1009 max_cpus = strtoull(option, NULL, 10);
1010
1011 /* compute missing values, prefer sockets over cores over threads */
1012 if (smp == 0 || sockets == 0) {
1013 sockets = sockets > 0 ? sockets : 1;
1014 cores = cores > 0 ? cores : 1;
1015 threads = threads > 0 ? threads : 1;
1016 if (smp == 0) {
1017 smp = cores * threads * sockets;
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001018 }
1019 } else {
1020 if (cores == 0) {
1021 threads = threads > 0 ? threads : 1;
1022 cores = smp / (sockets * threads);
1023 } else {
Joel Schoppdca98162010-07-21 15:05:17 -05001024 threads = smp / (cores * sockets);
Andre Przywaradc6b1c02009-08-19 15:42:40 +02001025 }
1026 }
1027 smp_cpus = smp;
1028 smp_cores = cores > 0 ? cores : 1;
1029 smp_threads = threads > 0 ? threads : 1;
1030 if (max_cpus == 0)
1031 max_cpus = smp_cpus;
1032}
1033
bellard330d0412003-07-26 18:11:40 +00001034/***********************************************************/
bellarda594cfb2005-11-06 16:13:29 +00001035/* USB devices */
1036
Markus Armbrusterfb080002010-05-28 15:38:44 +02001037static int usb_device_add(const char *devname)
bellarda594cfb2005-11-06 16:13:29 +00001038{
1039 const char *p;
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001040 USBDevice *dev = NULL;
bellarda594cfb2005-11-06 16:13:29 +00001041
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001042 if (!usb_enabled)
bellarda594cfb2005-11-06 16:13:29 +00001043 return -1;
1044
Gerd Hoffmann0958b4c2009-10-26 15:56:45 +01001045 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1046 dev = usbdevice_create(devname);
1047 if (dev)
1048 goto done;
1049
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001050 /* the other ones */
Gerd Hoffmanne447fc62011-06-01 14:41:59 +02001051#ifndef CONFIG_LINUX
1052 /* only the linux version is qdev-ified, usb-bsd still needs this */
bellarda594cfb2005-11-06 16:13:29 +00001053 if (strstart(devname, "host:", &p)) {
1054 dev = usb_host_device_open(p);
Gerd Hoffmanne447fc62011-06-01 14:41:59 +02001055 } else
1056#endif
1057 if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
balrogdc72ac12008-11-09 00:04:26 +00001058 dev = usb_bt_init(devname[2] ? hci_init(p) :
1059 bt_new_hci(qemu_find_bt_vlan(0)));
bellarda594cfb2005-11-06 16:13:29 +00001060 } else {
1061 return -1;
1062 }
pbrook0d92ed32006-05-21 16:30:15 +00001063 if (!dev)
1064 return -1;
1065
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001066done:
bellarda594cfb2005-11-06 16:13:29 +00001067 return 0;
1068}
1069
aliguori1f3870a2008-08-21 19:27:48 +00001070static int usb_device_del(const char *devname)
1071{
1072 int bus_num, addr;
1073 const char *p;
1074
aliguori5d0c5752008-09-14 01:07:41 +00001075 if (strstart(devname, "host:", &p))
1076 return usb_host_device_close(p);
1077
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001078 if (!usb_enabled)
aliguori1f3870a2008-08-21 19:27:48 +00001079 return -1;
1080
1081 p = strchr(devname, '.');
1082 if (!p)
1083 return -1;
1084 bus_num = strtoul(devname, NULL, 0);
1085 addr = strtoul(p + 1, NULL, 0);
1086
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +02001087 return usb_device_delete_addr(bus_num, addr);
aliguori1f3870a2008-08-21 19:27:48 +00001088}
1089
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001090static int usb_parse(const char *cmdline)
1091{
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001092 int r;
Markus Armbrusterfb080002010-05-28 15:38:44 +02001093 r = usb_device_add(cmdline);
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001094 if (r < 0) {
1095 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
1096 }
1097 return r;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001098}
1099
Luiz Capitulinod54908a2009-08-28 15:27:13 -03001100void do_usb_add(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +00001101{
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001102 const char *devname = qdict_get_str(qdict, "devname");
Markus Armbrusterfb080002010-05-28 15:38:44 +02001103 if (usb_device_add(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +01001104 error_report("could not add USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001105 }
bellarda594cfb2005-11-06 16:13:29 +00001106}
1107
Luiz Capitulinod54908a2009-08-28 15:27:13 -03001108void do_usb_del(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +00001109{
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001110 const char *devname = qdict_get_str(qdict, "devname");
1111 if (usb_device_del(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +01001112 error_report("could not delete USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +08001113 }
bellarda594cfb2005-11-06 16:13:29 +00001114}
1115
bellardf7cce892004-12-08 22:21:25 +00001116/***********************************************************/
balrog201a51f2007-04-30 00:51:09 +00001117/* PCMCIA/Cardbus */
1118
1119static struct pcmcia_socket_entry_s {
Paul Brookbc24a222009-05-10 01:44:56 +01001120 PCMCIASocket *socket;
balrog201a51f2007-04-30 00:51:09 +00001121 struct pcmcia_socket_entry_s *next;
1122} *pcmcia_sockets = 0;
1123
Paul Brookbc24a222009-05-10 01:44:56 +01001124void pcmcia_socket_register(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +00001125{
1126 struct pcmcia_socket_entry_s *entry;
1127
Anthony Liguori7267c092011-08-20 22:09:37 -05001128 entry = g_malloc(sizeof(struct pcmcia_socket_entry_s));
balrog201a51f2007-04-30 00:51:09 +00001129 entry->socket = socket;
1130 entry->next = pcmcia_sockets;
1131 pcmcia_sockets = entry;
1132}
1133
Paul Brookbc24a222009-05-10 01:44:56 +01001134void pcmcia_socket_unregister(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +00001135{
1136 struct pcmcia_socket_entry_s *entry, **ptr;
1137
1138 ptr = &pcmcia_sockets;
1139 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1140 if (entry->socket == socket) {
1141 *ptr = entry->next;
Anthony Liguori7267c092011-08-20 22:09:37 -05001142 g_free(entry);
balrog201a51f2007-04-30 00:51:09 +00001143 }
1144}
1145
aliguori376253e2009-03-05 23:01:23 +00001146void pcmcia_info(Monitor *mon)
balrog201a51f2007-04-30 00:51:09 +00001147{
1148 struct pcmcia_socket_entry_s *iter;
aliguori376253e2009-03-05 23:01:23 +00001149
balrog201a51f2007-04-30 00:51:09 +00001150 if (!pcmcia_sockets)
aliguori376253e2009-03-05 23:01:23 +00001151 monitor_printf(mon, "No PCMCIA sockets\n");
balrog201a51f2007-04-30 00:51:09 +00001152
1153 for (iter = pcmcia_sockets; iter; iter = iter->next)
aliguori376253e2009-03-05 23:01:23 +00001154 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1155 iter->socket->attached ? iter->socket->card_string :
1156 "Empty");
balrog201a51f2007-04-30 00:51:09 +00001157}
1158
1159/***********************************************************/
bellardcc1daa42005-06-05 14:49:17 +00001160/* machine registration */
1161
blueswir1bdaf78e2008-10-04 07:24:27 +00001162static QEMUMachine *first_machine = NULL;
aliguori6f338c32009-02-11 15:21:54 +00001163QEMUMachine *current_machine = NULL;
bellardcc1daa42005-06-05 14:49:17 +00001164
1165int qemu_register_machine(QEMUMachine *m)
1166{
1167 QEMUMachine **pm;
1168 pm = &first_machine;
1169 while (*pm != NULL)
1170 pm = &(*pm)->next;
1171 m->next = NULL;
1172 *pm = m;
1173 return 0;
1174}
1175
pbrook9596ebb2007-11-18 01:44:38 +00001176static QEMUMachine *find_machine(const char *name)
bellardcc1daa42005-06-05 14:49:17 +00001177{
1178 QEMUMachine *m;
1179
1180 for(m = first_machine; m != NULL; m = m->next) {
1181 if (!strcmp(m->name, name))
1182 return m;
Mark McLoughlin3f6599e2009-07-22 10:02:50 +01001183 if (m->alias && !strcmp(m->alias, name))
1184 return m;
bellardcc1daa42005-06-05 14:49:17 +00001185 }
1186 return NULL;
1187}
1188
Anthony Liguori0c257432009-05-21 20:41:01 -05001189static QEMUMachine *find_default_machine(void)
1190{
1191 QEMUMachine *m;
1192
1193 for(m = first_machine; m != NULL; m = m->next) {
1194 if (m->is_default) {
1195 return m;
1196 }
1197 }
1198 return NULL;
1199}
1200
bellardcc1daa42005-06-05 14:49:17 +00001201/***********************************************************/
bellard8a7ddc32004-03-31 19:00:16 +00001202/* main execution loop */
1203
pbrook9596ebb2007-11-18 01:44:38 +00001204static void gui_update(void *opaque)
bellard8a7ddc32004-03-31 19:00:16 +00001205{
aliguori7d957bd2009-01-15 22:14:11 +00001206 uint64_t interval = GUI_REFRESH_INTERVAL;
ths740733b2007-06-08 01:57:56 +00001207 DisplayState *ds = opaque;
aliguori7d957bd2009-01-15 22:14:11 +00001208 DisplayChangeListener *dcl = ds->listeners;
1209
1210 dpy_refresh(ds);
1211
1212 while (dcl != NULL) {
1213 if (dcl->gui_timer_interval &&
1214 dcl->gui_timer_interval < interval)
1215 interval = dcl->gui_timer_interval;
1216 dcl = dcl->next;
1217 }
Paolo Bonzini7bd427d2011-03-11 16:47:48 +01001218 qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock));
bellard8a7ddc32004-03-31 19:00:16 +00001219}
1220
bellard0bd48852005-11-11 00:00:47 +00001221struct vm_change_state_entry {
1222 VMChangeStateHandler *cb;
1223 void *opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001224 QLIST_ENTRY (vm_change_state_entry) entries;
bellard0bd48852005-11-11 00:00:47 +00001225};
1226
Blue Swirl72cf2d42009-09-12 07:36:22 +00001227static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
bellard0bd48852005-11-11 00:00:47 +00001228
1229VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1230 void *opaque)
1231{
1232 VMChangeStateEntry *e;
1233
Anthony Liguori7267c092011-08-20 22:09:37 -05001234 e = g_malloc0(sizeof (*e));
bellard0bd48852005-11-11 00:00:47 +00001235
1236 e->cb = cb;
1237 e->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001238 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
bellard0bd48852005-11-11 00:00:47 +00001239 return e;
1240}
1241
1242void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1243{
Blue Swirl72cf2d42009-09-12 07:36:22 +00001244 QLIST_REMOVE (e, entries);
Anthony Liguori7267c092011-08-20 22:09:37 -05001245 g_free (e);
bellard0bd48852005-11-11 00:00:47 +00001246}
1247
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001248void vm_state_notify(int running, RunState state)
bellard0bd48852005-11-11 00:00:47 +00001249{
1250 VMChangeStateEntry *e;
1251
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001252 trace_vm_state_notify(running, state);
Stefan Hajnoczi94b0b5f2010-11-16 12:20:25 +00001253
bellard0bd48852005-11-11 00:00:47 +00001254 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001255 e->cb(e->opaque, running, state);
bellard0bd48852005-11-11 00:00:47 +00001256 }
1257}
1258
bellard8a7ddc32004-03-31 19:00:16 +00001259void vm_start(void)
1260{
Luiz Capitulino13548692011-07-29 15:36:43 -03001261 if (!runstate_is_running()) {
bellard8a7ddc32004-03-31 19:00:16 +00001262 cpu_enable_ticks();
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001263 runstate_set(RUN_STATE_RUNNING);
1264 vm_state_notify(1, RUN_STATE_RUNNING);
aliguorid6dc3d42009-04-24 18:04:07 +00001265 resume_all_vcpus();
Luiz Capitulino6ed2c482010-04-27 20:35:59 -03001266 monitor_protocol_event(QEVENT_RESUME, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00001267 }
1268}
1269
bellardbb0c6722004-06-20 12:37:32 +00001270/* reset/shutdown handler */
1271
1272typedef struct QEMUResetEntry {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001273 QTAILQ_ENTRY(QEMUResetEntry) entry;
bellardbb0c6722004-06-20 12:37:32 +00001274 QEMUResetHandler *func;
1275 void *opaque;
bellardbb0c6722004-06-20 12:37:32 +00001276} QEMUResetEntry;
1277
Blue Swirl72cf2d42009-09-12 07:36:22 +00001278static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1279 QTAILQ_HEAD_INITIALIZER(reset_handlers);
bellardbb0c6722004-06-20 12:37:32 +00001280static int reset_requested;
Gleb Natapovf64622c2011-03-15 13:56:04 +02001281static int shutdown_requested, shutdown_signal = -1;
1282static pid_t shutdown_pid;
bellard34751872005-07-02 14:31:34 +00001283static int powerdown_requested;
Jan Kiszka8cf71712011-02-07 12:19:16 +01001284static int debug_requested;
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001285static RunState vmstop_requested = RUN_STATE_MAX;
bellardbb0c6722004-06-20 12:37:32 +00001286
Anthony PERARD1291eb32010-07-22 15:52:48 +01001287int qemu_shutdown_requested_get(void)
1288{
1289 return shutdown_requested;
1290}
1291
1292int qemu_reset_requested_get(void)
1293{
1294 return reset_requested;
1295}
1296
aurel32cf7a2fe2008-03-18 06:53:05 +00001297int qemu_shutdown_requested(void)
1298{
1299 int r = shutdown_requested;
1300 shutdown_requested = 0;
1301 return r;
1302}
1303
Gleb Natapovf64622c2011-03-15 13:56:04 +02001304void qemu_kill_report(void)
1305{
1306 if (shutdown_signal != -1) {
Peter Maydellf1d3fb02011-03-30 22:03:38 +01001307 fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal);
1308 if (shutdown_pid == 0) {
1309 /* This happens for eg ^C at the terminal, so it's worth
1310 * avoiding printing an odd message in that case.
1311 */
1312 fputc('\n', stderr);
1313 } else {
Andreas Färber953ffe02011-06-02 19:58:06 +02001314 fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid);
Peter Maydellf1d3fb02011-03-30 22:03:38 +01001315 }
Gleb Natapovf64622c2011-03-15 13:56:04 +02001316 shutdown_signal = -1;
1317 }
1318}
1319
aurel32cf7a2fe2008-03-18 06:53:05 +00001320int qemu_reset_requested(void)
1321{
1322 int r = reset_requested;
1323 reset_requested = 0;
1324 return r;
1325}
1326
1327int qemu_powerdown_requested(void)
1328{
1329 int r = powerdown_requested;
1330 powerdown_requested = 0;
1331 return r;
1332}
1333
aliguorie5689022009-04-24 18:03:54 +00001334static int qemu_debug_requested(void)
1335{
1336 int r = debug_requested;
1337 debug_requested = 0;
1338 return r;
1339}
1340
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001341/* We use RUN_STATE_MAX but any invalid value will do */
Luiz Capitulino0d45b702011-09-30 14:27:11 -03001342static bool qemu_vmstop_requested(RunState *r)
aliguori6e29f5d2009-04-24 18:04:02 +00001343{
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001344 if (vmstop_requested < RUN_STATE_MAX) {
Luiz Capitulino0d45b702011-09-30 14:27:11 -03001345 *r = vmstop_requested;
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03001346 vmstop_requested = RUN_STATE_MAX;
Luiz Capitulino0d45b702011-09-30 14:27:11 -03001347 return true;
1348 }
1349
1350 return false;
aliguori6e29f5d2009-04-24 18:04:02 +00001351}
1352
Jan Kiszkaa08d4362009-06-27 09:25:07 +02001353void qemu_register_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001354{
Anthony Liguori7267c092011-08-20 22:09:37 -05001355 QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
bellardbb0c6722004-06-20 12:37:32 +00001356
bellardbb0c6722004-06-20 12:37:32 +00001357 re->func = func;
1358 re->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001359 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
bellardbb0c6722004-06-20 12:37:32 +00001360}
1361
Jan Kiszkadda9b292009-07-02 00:19:02 +02001362void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001363{
1364 QEMUResetEntry *re;
1365
Blue Swirl72cf2d42009-09-12 07:36:22 +00001366 QTAILQ_FOREACH(re, &reset_handlers, entry) {
Jan Kiszkadda9b292009-07-02 00:19:02 +02001367 if (re->func == func && re->opaque == opaque) {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001368 QTAILQ_REMOVE(&reset_handlers, re, entry);
Anthony Liguori7267c092011-08-20 22:09:37 -05001369 g_free(re);
Jan Kiszkadda9b292009-07-02 00:19:02 +02001370 return;
1371 }
1372 }
1373}
1374
Jan Kiszkae063eb12011-06-14 18:29:43 +02001375void qemu_system_reset(bool report)
Jan Kiszkadda9b292009-07-02 00:19:02 +02001376{
1377 QEMUResetEntry *re, *nre;
1378
1379 /* reset all devices */
Blue Swirl72cf2d42009-09-12 07:36:22 +00001380 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
bellardbb0c6722004-06-20 12:37:32 +00001381 re->func(re->opaque);
1382 }
Jan Kiszkae063eb12011-06-14 18:29:43 +02001383 if (report) {
1384 monitor_protocol_event(QEVENT_RESET, NULL);
1385 }
Jan Kiszkaea375f92010-03-01 19:10:30 +01001386 cpu_synchronize_all_post_reset();
bellardbb0c6722004-06-20 12:37:32 +00001387}
1388
1389void qemu_system_reset_request(void)
1390{
bellardd1beab82006-10-02 19:44:22 +00001391 if (no_reboot) {
1392 shutdown_requested = 1;
1393 } else {
1394 reset_requested = 1;
1395 }
Jan Kiszkab4a3d962011-02-01 22:15:43 +01001396 cpu_stop_current();
aliguorid9f75a42009-04-24 18:03:11 +00001397 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001398}
1399
Gleb Natapovf64622c2011-03-15 13:56:04 +02001400void qemu_system_killed(int signal, pid_t pid)
1401{
1402 shutdown_signal = signal;
1403 shutdown_pid = pid;
Kevin Wolfd9389b92011-09-14 15:38:40 +02001404 no_shutdown = 0;
Gleb Natapovf64622c2011-03-15 13:56:04 +02001405 qemu_system_shutdown_request();
1406}
1407
bellardbb0c6722004-06-20 12:37:32 +00001408void qemu_system_shutdown_request(void)
1409{
1410 shutdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001411 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001412}
1413
bellard34751872005-07-02 14:31:34 +00001414void qemu_system_powerdown_request(void)
1415{
1416 powerdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001417 qemu_notify_event();
1418}
1419
Jan Kiszka8cf71712011-02-07 12:19:16 +01001420void qemu_system_debug_request(void)
1421{
1422 debug_requested = 1;
Jan Kiszka83f338f2011-02-07 12:19:17 +01001423 qemu_notify_event();
Jan Kiszka8cf71712011-02-07 12:19:16 +01001424}
1425
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001426void qemu_system_vmstop_request(RunState state)
Jan Kiszka8cf71712011-02-07 12:19:16 +01001427{
Luiz Capitulino1dfb4dd2011-07-29 14:26:33 -03001428 vmstop_requested = state;
Jan Kiszka8cf71712011-02-07 12:19:16 +01001429 qemu_notify_event();
1430}
1431
Blue Swirld9c32312009-08-09 08:42:19 +00001432qemu_irq qemu_system_powerdown;
1433
Paolo Bonzini99435902011-09-12 14:03:13 +02001434static bool main_loop_should_exit(void)
1435{
1436 RunState r;
1437 if (qemu_debug_requested()) {
1438 vm_stop(RUN_STATE_DEBUG);
1439 }
1440 if (qemu_shutdown_requested()) {
1441 qemu_kill_report();
1442 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
1443 if (no_shutdown) {
1444 vm_stop(RUN_STATE_SHUTDOWN);
1445 } else {
1446 return true;
1447 }
1448 }
1449 if (qemu_reset_requested()) {
1450 pause_all_vcpus();
1451 cpu_synchronize_all_states();
1452 qemu_system_reset(VMRESET_REPORT);
1453 resume_all_vcpus();
1454 if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
1455 runstate_check(RUN_STATE_SHUTDOWN)) {
1456 runstate_set(RUN_STATE_PAUSED);
1457 }
1458 }
1459 if (qemu_powerdown_requested()) {
1460 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
1461 qemu_irq_raise(qemu_system_powerdown);
1462 }
1463 if (qemu_vmstop_requested(&r)) {
1464 vm_stop(r);
1465 }
1466 return false;
1467}
1468
aliguori43b96852009-04-24 18:03:33 +00001469static void main_loop(void)
1470{
Jan Kiszkac9f711a2011-08-22 17:46:02 +02001471 bool nonblocking;
Paolo Bonzini99435902011-09-12 14:03:13 +02001472 int last_io = 0;
Jan Kiszka8e1b90e2011-02-01 22:15:46 +01001473#ifdef CONFIG_PROFILER
1474 int64_t ti;
1475#endif
Paolo Bonzini99435902011-09-12 14:03:13 +02001476 do {
Jan Kiszkac9f711a2011-08-22 17:46:02 +02001477 nonblocking = !kvm_enabled() && last_io > 0;
aliguori43b96852009-04-24 18:03:33 +00001478#ifdef CONFIG_PROFILER
Jan Kiszka46481d32011-02-01 22:15:47 +01001479 ti = profile_getclock();
aliguori43b96852009-04-24 18:03:33 +00001480#endif
Jan Kiszkac9f711a2011-08-22 17:46:02 +02001481 last_io = main_loop_wait(nonblocking);
aliguori43b96852009-04-24 18:03:33 +00001482#ifdef CONFIG_PROFILER
Jan Kiszka46481d32011-02-01 22:15:47 +01001483 dev_time += profile_getclock() - ti;
aliguori43b96852009-04-24 18:03:33 +00001484#endif
Paolo Bonzini99435902011-09-12 14:03:13 +02001485 } while (!main_loop_should_exit());
bellardb4608c02003-06-27 17:34:32 +00001486}
1487
pbrook9bd7e6d2009-04-07 22:58:45 +00001488static void version(void)
1489{
Thomas Monjalonf75ca1a2010-04-28 14:42:01 +02001490 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
pbrook9bd7e6d2009-04-07 22:58:45 +00001491}
1492
ths15f82202007-06-29 23:26:08 +00001493static void help(int exitcode)
bellard0824d6f2003-06-24 13:42:40 +00001494{
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001495 const char *options_help =
Blue Swirlad960902010-03-29 19:23:52 +00001496#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1497 opt_help
blueswir15824d652009-03-28 06:44:27 +00001498#define DEFHEADING(text) stringify(text) "\n"
Jes Sorensen9f167322010-06-10 11:42:24 +02001499#include "qemu-options.def"
blueswir15824d652009-03-28 06:44:27 +00001500#undef DEF
1501#undef DEFHEADING
1502#undef GEN_DOCS
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001503 ;
1504 version();
1505 printf("usage: %s [options] [disk_image]\n"
malc3f020d72010-02-08 12:04:56 +03001506 "\n"
Thomas Monjalonf75ca1a2010-04-28 14:42:01 +02001507 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001508 "\n"
1509 "%s\n"
malc3f020d72010-02-08 12:04:56 +03001510 "During emulation, the following keys are useful:\n"
1511 "ctrl-alt-f toggle full screen\n"
1512 "ctrl-alt-n switch to virtual console 'n'\n"
1513 "ctrl-alt toggle mouse and keyboard grab\n"
1514 "\n"
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001515 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1516 "qemu",
1517 options_help);
ths15f82202007-06-29 23:26:08 +00001518 exit(exitcode);
bellard0824d6f2003-06-24 13:42:40 +00001519}
1520
bellardcd6f1162004-05-13 22:02:20 +00001521#define HAS_ARG 0x0001
1522
bellardcd6f1162004-05-13 22:02:20 +00001523typedef struct QEMUOption {
1524 const char *name;
1525 int flags;
1526 int index;
Blue Swirlad960902010-03-29 19:23:52 +00001527 uint32_t arch_mask;
bellardcd6f1162004-05-13 22:02:20 +00001528} QEMUOption;
1529
blueswir1dbed7e42008-10-01 19:38:09 +00001530static const QEMUOption qemu_options[] = {
Blue Swirlad960902010-03-29 19:23:52 +00001531 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1532#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1533 { option, opt_arg, opt_enum, arch_mask },
blueswir15824d652009-03-28 06:44:27 +00001534#define DEFHEADING(text)
Jes Sorensen9f167322010-06-10 11:42:24 +02001535#include "qemu-options.def"
blueswir15824d652009-03-28 06:44:27 +00001536#undef DEF
1537#undef DEFHEADING
1538#undef GEN_DOCS
bellardcd6f1162004-05-13 22:02:20 +00001539 { NULL },
bellardfc01f7e2003-06-30 10:03:06 +00001540};
malc3893c122008-09-28 00:42:05 +00001541static void select_vgahw (const char *p)
1542{
1543 const char *opts;
1544
Gerd Hoffmann64465292009-12-08 13:11:45 +01001545 default_vga = 0;
Zachary Amsden86176752009-07-30 00:15:02 -10001546 vga_interface_type = VGA_NONE;
malc3893c122008-09-28 00:42:05 +00001547 if (strstart(p, "std", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001548 vga_interface_type = VGA_STD;
malc3893c122008-09-28 00:42:05 +00001549 } else if (strstart(p, "cirrus", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001550 vga_interface_type = VGA_CIRRUS;
malc3893c122008-09-28 00:42:05 +00001551 } else if (strstart(p, "vmware", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001552 vga_interface_type = VGA_VMWARE;
aliguori94909d92009-04-22 15:19:53 +00001553 } else if (strstart(p, "xenfb", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001554 vga_interface_type = VGA_XENFB;
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +02001555 } else if (strstart(p, "qxl", &opts)) {
1556 vga_interface_type = VGA_QXL;
aliguori28b85ed2009-04-22 15:19:48 +00001557 } else if (!strstart(p, "none", &opts)) {
malc3893c122008-09-28 00:42:05 +00001558 invalid_vga:
1559 fprintf(stderr, "Unknown vga type: %s\n", p);
1560 exit(1);
1561 }
malccb5a7aa2008-09-28 00:42:12 +00001562 while (*opts) {
1563 const char *nextopt;
1564
1565 if (strstart(opts, ",retrace=", &nextopt)) {
1566 opts = nextopt;
1567 if (strstart(opts, "dumb", &nextopt))
1568 vga_retrace_method = VGA_RETRACE_DUMB;
1569 else if (strstart(opts, "precise", &nextopt))
1570 vga_retrace_method = VGA_RETRACE_PRECISE;
1571 else goto invalid_vga;
1572 } else goto invalid_vga;
1573 opts = nextopt;
1574 }
malc3893c122008-09-28 00:42:05 +00001575}
1576
Jes Sorensen1472a952011-03-16 13:33:31 +01001577static DisplayType select_display(const char *p)
1578{
1579 const char *opts;
1580 DisplayType display = DT_DEFAULT;
1581
1582 if (strstart(p, "sdl", &opts)) {
1583#ifdef CONFIG_SDL
1584 display = DT_SDL;
1585 while (*opts) {
1586 const char *nextopt;
1587
1588 if (strstart(opts, ",frame=", &nextopt)) {
1589 opts = nextopt;
1590 if (strstart(opts, "on", &nextopt)) {
1591 no_frame = 0;
1592 } else if (strstart(opts, "off", &nextopt)) {
1593 no_frame = 1;
1594 } else {
Peter Maydell05175532011-03-23 03:40:57 +00001595 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01001596 }
1597 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
1598 opts = nextopt;
1599 if (strstart(opts, "on", &nextopt)) {
1600 alt_grab = 1;
1601 } else if (strstart(opts, "off", &nextopt)) {
1602 alt_grab = 0;
1603 } else {
Peter Maydell05175532011-03-23 03:40:57 +00001604 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01001605 }
1606 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
1607 opts = nextopt;
1608 if (strstart(opts, "on", &nextopt)) {
1609 ctrl_grab = 1;
1610 } else if (strstart(opts, "off", &nextopt)) {
1611 ctrl_grab = 0;
1612 } else {
Peter Maydell05175532011-03-23 03:40:57 +00001613 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01001614 }
1615 } else if (strstart(opts, ",window_close=", &nextopt)) {
1616 opts = nextopt;
1617 if (strstart(opts, "on", &nextopt)) {
1618 no_quit = 0;
1619 } else if (strstart(opts, "off", &nextopt)) {
1620 no_quit = 1;
1621 } else {
Peter Maydell05175532011-03-23 03:40:57 +00001622 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01001623 }
1624 } else {
Peter Maydell05175532011-03-23 03:40:57 +00001625 invalid_sdl_args:
1626 fprintf(stderr, "Invalid SDL option string: %s\n", p);
1627 exit(1);
Jes Sorensen1472a952011-03-16 13:33:31 +01001628 }
1629 opts = nextopt;
1630 }
1631#else
1632 fprintf(stderr, "SDL support is disabled\n");
1633 exit(1);
1634#endif
Jes Sorensen3264ff12011-03-16 13:33:33 +01001635 } else if (strstart(p, "vnc", &opts)) {
Jes Sorensen821601e2011-03-16 13:33:36 +01001636#ifdef CONFIG_VNC
Jes Sorensen3264ff12011-03-16 13:33:33 +01001637 display_remote++;
1638
1639 if (*opts) {
1640 const char *nextopt;
1641
1642 if (strstart(opts, "=", &nextopt)) {
1643 vnc_display = nextopt;
1644 }
1645 }
1646 if (!vnc_display) {
1647 fprintf(stderr, "VNC requires a display argument vnc=<display>\n");
1648 exit(1);
1649 }
Jes Sorensen821601e2011-03-16 13:33:36 +01001650#else
1651 fprintf(stderr, "VNC support is disabled\n");
1652 exit(1);
1653#endif
Jes Sorensen1472a952011-03-16 13:33:31 +01001654 } else if (strstart(p, "curses", &opts)) {
1655#ifdef CONFIG_CURSES
1656 display = DT_CURSES;
1657#else
1658 fprintf(stderr, "Curses support is disabled\n");
1659 exit(1);
1660#endif
Jes Sorensen4171d322011-03-16 13:33:32 +01001661 } else if (strstart(p, "none", &opts)) {
1662 display = DT_NONE;
Jes Sorensen1472a952011-03-16 13:33:31 +01001663 } else {
Jes Sorensen1472a952011-03-16 13:33:31 +01001664 fprintf(stderr, "Unknown display type: %s\n", p);
1665 exit(1);
1666 }
1667
1668 return display;
1669}
1670
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001671static int balloon_parse(const char *arg)
1672{
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001673 QemuOpts *opts;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001674
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001675 if (strcmp(arg, "none") == 0) {
1676 return 0;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001677 }
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001678
1679 if (!strncmp(arg, "virtio", 6)) {
1680 if (arg[6] == ',') {
1681 /* have params -> parse them */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001682 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001683 if (!opts)
1684 return -1;
1685 } else {
1686 /* create empty opts */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001687 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001688 }
Alexander Graf29f82b32011-03-29 15:29:29 +02001689 qemu_opt_set(opts, "driver", "virtio-balloon");
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001690 return 0;
1691 }
1692
1693 return -1;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001694}
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001695
Paul Brook5cea8592009-05-30 00:52:44 +01001696char *qemu_find_file(int type, const char *name)
1697{
1698 int len;
1699 const char *subdir;
1700 char *buf;
1701
1702 /* If name contains path separators then try it as a straight path. */
1703 if ((strchr(name, '/') || strchr(name, '\\'))
1704 && access(name, R_OK) == 0) {
Anthony Liguori7267c092011-08-20 22:09:37 -05001705 return g_strdup(name);
Paul Brook5cea8592009-05-30 00:52:44 +01001706 }
1707 switch (type) {
1708 case QEMU_FILE_TYPE_BIOS:
1709 subdir = "";
1710 break;
1711 case QEMU_FILE_TYPE_KEYMAP:
1712 subdir = "keymaps/";
1713 break;
1714 default:
1715 abort();
1716 }
1717 len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
Anthony Liguori7267c092011-08-20 22:09:37 -05001718 buf = g_malloc0(len);
Blue Swirl3a417592009-06-09 19:12:21 +00001719 snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
Paul Brook5cea8592009-05-30 00:52:44 +01001720 if (access(buf, R_OK)) {
Anthony Liguori7267c092011-08-20 22:09:37 -05001721 g_free(buf);
Paul Brook5cea8592009-05-30 00:52:44 +01001722 return NULL;
1723 }
1724 return buf;
1725}
1726
Markus Armbrusterff952ba2010-01-29 19:48:57 +01001727static int device_help_func(QemuOpts *opts, void *opaque)
1728{
1729 return qdev_device_help(opts);
1730}
1731
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02001732static int device_init_func(QemuOpts *opts, void *opaque)
1733{
1734 DeviceState *dev;
1735
1736 dev = qdev_device_add(opts);
1737 if (!dev)
1738 return -1;
1739 return 0;
1740}
1741
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01001742static int chardev_init_func(QemuOpts *opts, void *opaque)
1743{
1744 CharDriverState *chr;
1745
Anthony Liguorif69554b2011-08-15 11:17:37 -05001746 chr = qemu_chr_new_from_opts(opts, NULL);
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01001747 if (!chr)
1748 return -1;
1749 return 0;
1750}
1751
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07001752#ifdef CONFIG_VIRTFS
Gautham R Shenoy74db9202010-04-29 17:44:43 +05301753static int fsdev_init_func(QemuOpts *opts, void *opaque)
1754{
1755 int ret;
1756 ret = qemu_fsdev_add(opts);
1757
1758 return ret;
1759}
1760#endif
1761
Gerd Hoffmann88589342009-12-08 13:11:50 +01001762static int mon_init_func(QemuOpts *opts, void *opaque)
1763{
1764 CharDriverState *chr;
1765 const char *chardev;
1766 const char *mode;
1767 int flags;
1768
1769 mode = qemu_opt_get(opts, "mode");
1770 if (mode == NULL) {
1771 mode = "readline";
1772 }
1773 if (strcmp(mode, "readline") == 0) {
1774 flags = MONITOR_USE_READLINE;
1775 } else if (strcmp(mode, "control") == 0) {
1776 flags = MONITOR_USE_CONTROL;
1777 } else {
1778 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
1779 exit(1);
1780 }
1781
Daniel P. Berrange39eaab92010-06-07 15:42:31 +01001782 if (qemu_opt_get_bool(opts, "pretty", 0))
1783 flags |= MONITOR_USE_PRETTY;
1784
Gerd Hoffmann88589342009-12-08 13:11:50 +01001785 if (qemu_opt_get_bool(opts, "default", 0))
1786 flags |= MONITOR_IS_DEFAULT;
1787
1788 chardev = qemu_opt_get(opts, "chardev");
1789 chr = qemu_chr_find(chardev);
1790 if (chr == NULL) {
1791 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
1792 exit(1);
1793 }
1794
1795 monitor_init(chr, flags);
1796 return 0;
1797}
1798
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01001799static void monitor_parse(const char *optarg, const char *mode)
Gerd Hoffmann88589342009-12-08 13:11:50 +01001800{
1801 static int monitor_device_index = 0;
1802 QemuOpts *opts;
1803 const char *p;
1804 char label[32];
1805 int def = 0;
1806
1807 if (strstart(optarg, "chardev:", &p)) {
1808 snprintf(label, sizeof(label), "%s", p);
1809 } else {
Jan Kiszka140e0652010-04-06 16:55:52 +02001810 snprintf(label, sizeof(label), "compat_monitor%d",
1811 monitor_device_index);
1812 if (monitor_device_index == 0) {
Gerd Hoffmann88589342009-12-08 13:11:50 +01001813 def = 1;
1814 }
1815 opts = qemu_chr_parse_compat(label, optarg);
1816 if (!opts) {
1817 fprintf(stderr, "parse error: %s\n", optarg);
1818 exit(1);
1819 }
1820 }
1821
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001822 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1);
Gerd Hoffmann88589342009-12-08 13:11:50 +01001823 if (!opts) {
1824 fprintf(stderr, "duplicate chardev: %s\n", label);
1825 exit(1);
1826 }
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01001827 qemu_opt_set(opts, "mode", mode);
Gerd Hoffmann88589342009-12-08 13:11:50 +01001828 qemu_opt_set(opts, "chardev", label);
1829 if (def)
1830 qemu_opt_set(opts, "default", "on");
1831 monitor_device_index++;
1832}
1833
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001834struct device_config {
1835 enum {
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001836 DEV_USB, /* -usbdevice */
1837 DEV_BT, /* -bt */
1838 DEV_SERIAL, /* -serial */
1839 DEV_PARALLEL, /* -parallel */
1840 DEV_VIRTCON, /* -virtioconsole */
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001841 DEV_DEBUGCON, /* -debugcon */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001842 } type;
1843 const char *cmdline;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001844 QTAILQ_ENTRY(device_config) next;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001845};
Blue Swirl72cf2d42009-09-12 07:36:22 +00001846QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001847
1848static void add_device_config(int type, const char *cmdline)
1849{
1850 struct device_config *conf;
1851
Anthony Liguori7267c092011-08-20 22:09:37 -05001852 conf = g_malloc0(sizeof(*conf));
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001853 conf->type = type;
1854 conf->cmdline = cmdline;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001855 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001856}
1857
1858static int foreach_device_config(int type, int (*func)(const char *cmdline))
1859{
1860 struct device_config *conf;
1861 int rc;
1862
Blue Swirl72cf2d42009-09-12 07:36:22 +00001863 QTAILQ_FOREACH(conf, &device_configs, next) {
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001864 if (conf->type != type)
1865 continue;
1866 rc = func(conf->cmdline);
1867 if (0 != rc)
1868 return rc;
1869 }
1870 return 0;
1871}
1872
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01001873static int serial_parse(const char *devname)
1874{
1875 static int index = 0;
1876 char label[32];
1877
1878 if (strcmp(devname, "none") == 0)
1879 return 0;
1880 if (index == MAX_SERIAL_PORTS) {
1881 fprintf(stderr, "qemu: too many serial ports\n");
1882 exit(1);
1883 }
1884 snprintf(label, sizeof(label), "serial%d", index);
Anthony Liguori27143a42011-08-15 11:17:36 -05001885 serial_hds[index] = qemu_chr_new(label, devname, NULL);
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01001886 if (!serial_hds[index]) {
1887 fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
1888 devname, strerror(errno));
1889 return -1;
1890 }
1891 index++;
1892 return 0;
1893}
1894
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01001895static int parallel_parse(const char *devname)
1896{
1897 static int index = 0;
1898 char label[32];
1899
1900 if (strcmp(devname, "none") == 0)
1901 return 0;
1902 if (index == MAX_PARALLEL_PORTS) {
1903 fprintf(stderr, "qemu: too many parallel ports\n");
1904 exit(1);
1905 }
1906 snprintf(label, sizeof(label), "parallel%d", index);
Anthony Liguori27143a42011-08-15 11:17:36 -05001907 parallel_hds[index] = qemu_chr_new(label, devname, NULL);
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01001908 if (!parallel_hds[index]) {
1909 fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
1910 devname, strerror(errno));
1911 return -1;
1912 }
1913 index++;
1914 return 0;
1915}
1916
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001917static int virtcon_parse(const char *devname)
1918{
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001919 QemuOptsList *device = qemu_find_opts("device");
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001920 static int index = 0;
1921 char label[32];
Amit Shah392ecf52010-01-21 16:19:23 +05301922 QemuOpts *bus_opts, *dev_opts;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001923
1924 if (strcmp(devname, "none") == 0)
1925 return 0;
1926 if (index == MAX_VIRTIO_CONSOLES) {
1927 fprintf(stderr, "qemu: too many virtio consoles\n");
1928 exit(1);
1929 }
Amit Shah392ecf52010-01-21 16:19:23 +05301930
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001931 bus_opts = qemu_opts_create(device, NULL, 0);
Amit Shah392ecf52010-01-21 16:19:23 +05301932 qemu_opt_set(bus_opts, "driver", "virtio-serial");
1933
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001934 dev_opts = qemu_opts_create(device, NULL, 0);
Amit Shah392ecf52010-01-21 16:19:23 +05301935 qemu_opt_set(dev_opts, "driver", "virtconsole");
1936
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001937 snprintf(label, sizeof(label), "virtcon%d", index);
Anthony Liguori27143a42011-08-15 11:17:36 -05001938 virtcon_hds[index] = qemu_chr_new(label, devname, NULL);
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001939 if (!virtcon_hds[index]) {
1940 fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
1941 devname, strerror(errno));
1942 return -1;
1943 }
Amit Shah392ecf52010-01-21 16:19:23 +05301944 qemu_opt_set(dev_opts, "chardev", label);
1945
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001946 index++;
1947 return 0;
1948}
1949
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001950static int debugcon_parse(const char *devname)
1951{
1952 QemuOpts *opts;
1953
Anthony Liguori27143a42011-08-15 11:17:36 -05001954 if (!qemu_chr_new("debugcon", devname, NULL)) {
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001955 exit(1);
1956 }
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001957 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001958 if (!opts) {
1959 fprintf(stderr, "qemu: already have a debugcon device\n");
1960 exit(1);
1961 }
1962 qemu_opt_set(opts, "driver", "isa-debugcon");
1963 qemu_opt_set(opts, "chardev", "debugcon");
1964 return 0;
1965}
1966
Jan Kiszka9052ea62011-07-23 12:38:37 +02001967static QEMUMachine *machine_parse(const char *name)
1968{
1969 QEMUMachine *m, *machine = NULL;
1970
1971 if (name) {
1972 machine = find_machine(name);
1973 }
1974 if (machine) {
1975 return machine;
1976 }
1977 printf("Supported machines are:\n");
1978 for (m = first_machine; m != NULL; m = m->next) {
1979 if (m->alias) {
1980 printf("%-10s %s (alias of %s)\n", m->alias, m->desc, m->name);
1981 }
1982 printf("%-10s %s%s\n", m->name, m->desc,
1983 m->is_default ? " (default)" : "");
1984 }
1985 exit(!name || *name != '?');
1986}
1987
Anthony PERARD303d4e82010-09-21 20:05:31 +01001988static int tcg_init(void)
1989{
Jan Kiszkad5ab9712011-08-02 16:10:21 +02001990 tcg_exec_init(tcg_tb_size * 1024 * 1024);
Anthony PERARD303d4e82010-09-21 20:05:31 +01001991 return 0;
1992}
1993
1994static struct {
1995 const char *opt_name;
1996 const char *name;
1997 int (*available)(void);
1998 int (*init)(void);
1999 int *allowed;
2000} accel_list[] = {
2001 { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
Anthony PERARD3285cf42010-08-19 12:27:56 +01002002 { "xen", "Xen", xen_available, xen_init, &xen_allowed },
Anthony PERARD303d4e82010-09-21 20:05:31 +01002003 { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
2004};
2005
2006static int configure_accelerator(void)
2007{
2008 const char *p = NULL;
2009 char buf[10];
2010 int i, ret;
2011 bool accel_initalised = 0;
2012 bool init_failed = 0;
2013
2014 QemuOptsList *list = qemu_find_opts("machine");
2015 if (!QTAILQ_EMPTY(&list->head)) {
2016 p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel");
2017 }
2018
2019 if (p == NULL) {
2020 /* Use the default "accelerator", tcg */
2021 p = "tcg";
2022 }
2023
2024 while (!accel_initalised && *p != '\0') {
2025 if (*p == ':') {
2026 p++;
2027 }
2028 p = get_opt_name(buf, sizeof (buf), p, ':');
2029 for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
2030 if (strcmp(accel_list[i].opt_name, buf) == 0) {
Anthony Liguoria16c53b2011-06-06 08:25:06 -05002031 *(accel_list[i].allowed) = 1;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002032 ret = accel_list[i].init();
2033 if (ret < 0) {
2034 init_failed = 1;
2035 if (!accel_list[i].available()) {
2036 printf("%s not supported for this target\n",
2037 accel_list[i].name);
2038 } else {
2039 fprintf(stderr, "failed to initialize %s: %s\n",
2040 accel_list[i].name,
2041 strerror(-ret));
2042 }
Anthony Liguoria16c53b2011-06-06 08:25:06 -05002043 *(accel_list[i].allowed) = 0;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002044 } else {
2045 accel_initalised = 1;
Anthony PERARD303d4e82010-09-21 20:05:31 +01002046 }
2047 break;
2048 }
2049 }
2050 if (i == ARRAY_SIZE(accel_list)) {
2051 fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
2052 }
2053 }
2054
2055 if (!accel_initalised) {
2056 fprintf(stderr, "No accelerator found!\n");
2057 exit(1);
2058 }
2059
2060 if (init_failed) {
2061 fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
2062 }
2063
2064 return !accel_initalised;
2065}
2066
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02002067void qemu_add_exit_notifier(Notifier *notify)
2068{
2069 notifier_list_add(&exit_notifiers, notify);
2070}
2071
2072void qemu_remove_exit_notifier(Notifier *notify)
2073{
2074 notifier_list_remove(&exit_notifiers, notify);
2075}
2076
2077static void qemu_run_exit_notifiers(void)
2078{
Jan Kiszka9e8dd452011-06-20 14:06:26 +02002079 notifier_list_notify(&exit_notifiers, NULL);
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02002080}
2081
Gleb Natapov4cab9462010-12-08 13:35:08 +02002082void qemu_add_machine_init_done_notifier(Notifier *notify)
2083{
2084 notifier_list_add(&machine_init_done_notifiers, notify);
2085}
2086
2087static void qemu_run_machine_init_done_notifiers(void)
2088{
Jan Kiszka9e8dd452011-06-20 14:06:26 +02002089 notifier_list_notify(&machine_init_done_notifiers, NULL);
Gleb Natapov4cab9462010-12-08 13:35:08 +02002090}
2091
Anthony Liguori6530a972010-01-22 09:18:06 -06002092static const QEMUOption *lookup_opt(int argc, char **argv,
2093 const char **poptarg, int *poptind)
2094{
2095 const QEMUOption *popt;
2096 int optind = *poptind;
2097 char *r = argv[optind];
2098 const char *optarg;
2099
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002100 loc_set_cmdline(argv, optind, 1);
Anthony Liguori6530a972010-01-22 09:18:06 -06002101 optind++;
2102 /* Treat --foo the same as -foo. */
2103 if (r[1] == '-')
2104 r++;
2105 popt = qemu_options;
2106 for(;;) {
2107 if (!popt->name) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002108 error_report("invalid option");
Anthony Liguori6530a972010-01-22 09:18:06 -06002109 exit(1);
2110 }
2111 if (!strcmp(popt->name, r + 1))
2112 break;
2113 popt++;
2114 }
2115 if (popt->flags & HAS_ARG) {
2116 if (optind >= argc) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002117 error_report("requires an argument");
Anthony Liguori6530a972010-01-22 09:18:06 -06002118 exit(1);
2119 }
2120 optarg = argv[optind++];
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002121 loc_set_cmdline(argv, optind - 2, 2);
Anthony Liguori6530a972010-01-22 09:18:06 -06002122 } else {
2123 optarg = NULL;
2124 }
2125
2126 *poptarg = optarg;
2127 *poptind = optind;
2128
2129 return popt;
2130}
2131
Anthony Liguori07501122011-08-20 22:38:31 -05002132static gpointer malloc_and_trace(gsize n_bytes)
2133{
2134 void *ptr = malloc(n_bytes);
Frediano Ziglioa74cd8c2011-08-31 09:25:35 +02002135 trace_g_malloc(n_bytes, ptr);
Anthony Liguori07501122011-08-20 22:38:31 -05002136 return ptr;
2137}
2138
2139static gpointer realloc_and_trace(gpointer mem, gsize n_bytes)
2140{
2141 void *ptr = realloc(mem, n_bytes);
Frediano Ziglioa74cd8c2011-08-31 09:25:35 +02002142 trace_g_realloc(mem, n_bytes, ptr);
Anthony Liguori07501122011-08-20 22:38:31 -05002143 return ptr;
2144}
2145
2146static void free_and_trace(gpointer mem)
2147{
Frediano Ziglioa74cd8c2011-08-31 09:25:35 +02002148 trace_g_free(mem);
Anthony Liguori07501122011-08-20 22:38:31 -05002149 free(mem);
2150}
2151
malc902b3d52008-12-10 19:18:40 +00002152int main(int argc, char **argv, char **envp)
bellard0824d6f2003-06-24 13:42:40 +00002153{
aliguori59030a82009-04-05 18:43:41 +00002154 const char *gdbstub_dev = NULL;
thse4bcb142007-12-02 04:51:10 +00002155 int i;
Eduardo Habkostda1fcfd2010-04-06 19:22:07 -03002156 int snapshot, linux_boot;
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01002157 const char *icount_option = NULL;
bellard7f7f9872003-10-30 01:11:23 +00002158 const char *initrd_filename;
bellarda20dd502003-09-30 21:07:02 +00002159 const char *kernel_filename, *kernel_cmdline;
Anthony Liguori195325a2009-10-30 12:42:29 -05002160 char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
aliguori3023f332009-01-16 19:04:14 +00002161 DisplayState *ds;
aliguori7d957bd2009-01-15 22:14:11 +00002162 DisplayChangeListener *dcl;
bellard46d47672004-11-16 01:45:27 +00002163 int cyls, heads, secs, translation;
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02002164 QemuOpts *hda_opts = NULL, *opts;
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002165 QemuOptsList *olist;
bellardcd6f1162004-05-13 22:02:20 +00002166 int optind;
Anthony Liguori6530a972010-01-22 09:18:06 -06002167 const char *optarg;
bellardd63d3072004-10-03 13:29:03 +00002168 const char *loadvm = NULL;
bellardcc1daa42005-06-05 14:49:17 +00002169 QEMUMachine *machine;
j_mayer94fc95c2007-03-05 19:44:02 +00002170 const char *cpu_model;
ths93815bc2007-03-19 15:58:31 +00002171 const char *pid_file = NULL;
aliguori5bb79102008-10-13 03:12:02 +00002172 const char *incoming = NULL;
Jes Sorensen821601e2011-03-16 13:33:36 +01002173#ifdef CONFIG_VNC
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002174 int show_vnc_port = 0;
Jes Sorensen821601e2011-03-16 13:33:36 +01002175#endif
Anthony Liguori292444c2010-01-21 10:57:58 -06002176 int defconfig = 1;
Matthew Fernandezc235d732011-06-07 16:32:40 +00002177 const char *log_mask = NULL;
2178 const char *log_file = NULL;
Anthony Liguori07501122011-08-20 22:38:31 -05002179 GMemVTable mem_trace = {
2180 .malloc = malloc_and_trace,
2181 .realloc = realloc_and_trace,
2182 .free = free_and_trace,
2183 };
Lluís23d15e82011-08-31 20:31:31 +02002184 const char *trace_events = NULL;
Lluíse4858972011-08-31 20:31:03 +02002185 const char *trace_file = NULL;
Stefan Hajnoczi0b5538c2011-02-26 18:38:39 +00002186
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02002187 atexit(qemu_run_exit_notifiers);
Markus Armbruster65abca02010-02-24 14:37:14 +01002188 error_set_progname(argv[0]);
2189
Anthony Liguori07501122011-08-20 22:38:31 -05002190 g_mem_set_vtable(&mem_trace);
Andreas Färberdb529aa2011-10-31 19:14:56 +01002191 if (!g_thread_supported()) {
2192 g_thread_init(NULL);
2193 }
Anthony Liguori07501122011-08-20 22:38:31 -05002194
Luiz Capitulino5db9d4d2011-09-05 16:36:31 -03002195 runstate_init();
2196
Jan Kiszka68752042009-09-15 13:36:04 +02002197 init_clocks();
Paolo Bonzini2ff68d02011-09-12 16:21:44 +02002198 rtc_clock = host_clock;
Jan Kiszka68752042009-09-15 13:36:04 +02002199
malc902b3d52008-12-10 19:18:40 +00002200 qemu_cache_utils_init(envp);
2201
Blue Swirl72cf2d42009-09-12 07:36:22 +00002202 QLIST_INIT (&vm_change_state_head);
Jes Sorensenfe98ac12010-06-10 11:42:21 +02002203 os_setup_early_signal_handling();
bellardbe995c22006-06-25 16:25:21 +00002204
Anthony Liguorif80f9ec2009-05-20 18:38:09 -05002205 module_call_init(MODULE_INIT_MACHINE);
Anthony Liguori0c257432009-05-21 20:41:01 -05002206 machine = find_default_machine();
j_mayer94fc95c2007-03-05 19:44:02 +00002207 cpu_model = NULL;
bellardfc01f7e2003-06-30 10:03:06 +00002208 initrd_filename = NULL;
aurel324fc5d072008-04-27 21:39:40 +00002209 ram_size = 0;
bellard33e39632003-07-06 17:15:21 +00002210 snapshot = 0;
bellarda20dd502003-09-30 21:07:02 +00002211 kernel_filename = NULL;
2212 kernel_cmdline = "";
bellardc4b1fcc2004-03-14 21:44:30 +00002213 cyls = heads = secs = 0;
bellard46d47672004-11-16 01:45:27 +00002214 translation = BIOS_ATA_TRANSLATION_AUTO;
bellardc4b1fcc2004-03-14 21:44:30 +00002215
aliguori268a3622009-04-21 22:30:27 +00002216 for (i = 0; i < MAX_NODES; i++) {
2217 node_mem[i] = 0;
2218 node_cpumask[i] = 0;
2219 }
2220
aliguori268a3622009-04-21 22:30:27 +00002221 nb_numa_nodes = 0;
bellard7c9d8e02005-11-15 22:16:05 +00002222 nb_nics = 0;
ths3b46e622007-09-17 08:09:54 +00002223
blueswir141bd6392008-10-05 09:56:21 +00002224 autostart= 1;
2225
Anthony Liguori292444c2010-01-21 10:57:58 -06002226 /* first pass of option parsing */
2227 optind = 1;
2228 while (optind < argc) {
2229 if (argv[optind][0] != '-') {
2230 /* disk image */
Anthony Liguori28e68d62010-01-27 10:46:00 -06002231 optind++;
Anthony Liguori292444c2010-01-21 10:57:58 -06002232 continue;
2233 } else {
2234 const QEMUOption *popt;
2235
2236 popt = lookup_opt(argc, argv, &optarg, &optind);
2237 switch (popt->index) {
2238 case QEMU_OPTION_nodefconfig:
2239 defconfig=0;
2240 break;
2241 }
2242 }
2243 }
2244
2245 if (defconfig) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002246 int ret;
Markus Armbrustercf5a65a2010-02-18 19:48:33 +01002247
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002248 ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
Kevin Wolf019e78b2010-05-17 10:36:47 +02002249 if (ret < 0 && ret != -ENOENT) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002250 exit(1);
Anthony Liguori292444c2010-01-21 10:57:58 -06002251 }
2252
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002253 ret = qemu_read_config_file(arch_config_name);
Kevin Wolf019e78b2010-05-17 10:36:47 +02002254 if (ret < 0 && ret != -ENOENT) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002255 exit(1);
Anthony Liguori292444c2010-01-21 10:57:58 -06002256 }
2257 }
Blue Swirlde06f8d2010-03-29 19:23:50 +00002258 cpudef_init();
Anthony Liguori292444c2010-01-21 10:57:58 -06002259
2260 /* second pass of option parsing */
bellardcd6f1162004-05-13 22:02:20 +00002261 optind = 1;
bellard0824d6f2003-06-24 13:42:40 +00002262 for(;;) {
bellardcd6f1162004-05-13 22:02:20 +00002263 if (optind >= argc)
bellard0824d6f2003-06-24 13:42:40 +00002264 break;
Anthony Liguori6530a972010-01-22 09:18:06 -06002265 if (argv[optind][0] != '-') {
Markus Armbruster2292dda2011-01-28 11:21:41 +01002266 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
bellardcd6f1162004-05-13 22:02:20 +00002267 } else {
2268 const QEMUOption *popt;
2269
Anthony Liguori6530a972010-01-22 09:18:06 -06002270 popt = lookup_opt(argc, argv, &optarg, &optind);
Blue Swirlad960902010-03-29 19:23:52 +00002271 if (!(popt->arch_mask & arch_type)) {
2272 printf("Option %s not supported for this target\n", popt->name);
2273 exit(1);
2274 }
bellardcd6f1162004-05-13 22:02:20 +00002275 switch(popt->index) {
bellardcc1daa42005-06-05 14:49:17 +00002276 case QEMU_OPTION_M:
Jan Kiszka9052ea62011-07-23 12:38:37 +02002277 machine = machine_parse(optarg);
bellardcc1daa42005-06-05 14:49:17 +00002278 break;
j_mayer94fc95c2007-03-05 19:44:02 +00002279 case QEMU_OPTION_cpu:
2280 /* hw initialization will check this */
ths15f82202007-06-29 23:26:08 +00002281 if (*optarg == '?') {
Blue Swirl262353c2010-05-04 19:55:35 +00002282 list_cpus(stdout, &fprintf, optarg);
ths15f82202007-06-29 23:26:08 +00002283 exit(0);
j_mayer94fc95c2007-03-05 19:44:02 +00002284 } else {
2285 cpu_model = optarg;
2286 }
2287 break;
bellardcd6f1162004-05-13 22:02:20 +00002288 case QEMU_OPTION_initrd:
bellardfc01f7e2003-06-30 10:03:06 +00002289 initrd_filename = optarg;
2290 break;
bellardcd6f1162004-05-13 22:02:20 +00002291 case QEMU_OPTION_hda:
Markus Armbruster5645b0f2011-01-31 11:50:09 +01002292 {
2293 char buf[256];
2294 if (cyls == 0)
2295 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2296 else
2297 snprintf(buf, sizeof(buf),
2298 "%s,cyls=%d,heads=%d,secs=%d%s",
2299 HD_OPTS , cyls, heads, secs,
2300 translation == BIOS_ATA_TRANSLATION_LBA ?
thse4bcb142007-12-02 04:51:10 +00002301 ",trans=lba" :
Markus Armbruster5645b0f2011-01-31 11:50:09 +01002302 translation == BIOS_ATA_TRANSLATION_NONE ?
thse4bcb142007-12-02 04:51:10 +00002303 ",trans=none" : "");
Markus Armbruster5645b0f2011-01-31 11:50:09 +01002304 drive_add(IF_DEFAULT, 0, optarg, buf);
2305 break;
2306 }
bellardcd6f1162004-05-13 22:02:20 +00002307 case QEMU_OPTION_hdb:
bellardcc1daa42005-06-05 14:49:17 +00002308 case QEMU_OPTION_hdc:
2309 case QEMU_OPTION_hdd:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002310 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2311 HD_OPTS);
bellardfc01f7e2003-06-30 10:03:06 +00002312 break;
thse4bcb142007-12-02 04:51:10 +00002313 case QEMU_OPTION_drive:
Michael Tokareve2982c32011-03-30 16:31:05 +04002314 if (drive_def(optarg) == NULL) {
2315 exit(1);
2316 }
thse4bcb142007-12-02 04:51:10 +00002317 break;
Gerd Hoffmannd058fe02009-07-31 12:25:36 +02002318 case QEMU_OPTION_set:
2319 if (qemu_set_option(optarg) != 0)
2320 exit(1);
2321 break;
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01002322 case QEMU_OPTION_global:
2323 if (qemu_global_option(optarg) != 0)
2324 exit(1);
2325 break;
balrog3e3d5812007-04-30 02:09:25 +00002326 case QEMU_OPTION_mtdblock:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002327 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
balrog3e3d5812007-04-30 02:09:25 +00002328 break;
pbrooka1bb27b2007-04-06 16:49:48 +00002329 case QEMU_OPTION_sd:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002330 drive_add(IF_SD, 0, optarg, SD_OPTS);
pbrooka1bb27b2007-04-06 16:49:48 +00002331 break;
j_mayer86f55662007-04-24 06:52:59 +00002332 case QEMU_OPTION_pflash:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002333 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
j_mayer86f55662007-04-24 06:52:59 +00002334 break;
bellardcd6f1162004-05-13 22:02:20 +00002335 case QEMU_OPTION_snapshot:
bellard33e39632003-07-06 17:15:21 +00002336 snapshot = 1;
2337 break;
bellardcd6f1162004-05-13 22:02:20 +00002338 case QEMU_OPTION_hdachs:
bellard330d0412003-07-26 18:11:40 +00002339 {
bellard330d0412003-07-26 18:11:40 +00002340 const char *p;
2341 p = optarg;
2342 cyls = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002343 if (cyls < 1 || cyls > 16383)
2344 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00002345 if (*p != ',')
2346 goto chs_fail;
2347 p++;
2348 heads = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002349 if (heads < 1 || heads > 16)
2350 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00002351 if (*p != ',')
2352 goto chs_fail;
2353 p++;
2354 secs = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002355 if (secs < 1 || secs > 63)
2356 goto chs_fail;
2357 if (*p == ',') {
2358 p++;
2359 if (!strcmp(p, "none"))
2360 translation = BIOS_ATA_TRANSLATION_NONE;
2361 else if (!strcmp(p, "lba"))
2362 translation = BIOS_ATA_TRANSLATION_LBA;
2363 else if (!strcmp(p, "auto"))
2364 translation = BIOS_ATA_TRANSLATION_AUTO;
2365 else
2366 goto chs_fail;
2367 } else if (*p != '\0') {
bellardc4b1fcc2004-03-14 21:44:30 +00002368 chs_fail:
bellard46d47672004-11-16 01:45:27 +00002369 fprintf(stderr, "qemu: invalid physical CHS format\n");
2370 exit(1);
bellardc4b1fcc2004-03-14 21:44:30 +00002371 }
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02002372 if (hda_opts != NULL) {
2373 char num[16];
2374 snprintf(num, sizeof(num), "%d", cyls);
2375 qemu_opt_set(hda_opts, "cyls", num);
2376 snprintf(num, sizeof(num), "%d", heads);
2377 qemu_opt_set(hda_opts, "heads", num);
2378 snprintf(num, sizeof(num), "%d", secs);
2379 qemu_opt_set(hda_opts, "secs", num);
2380 if (translation == BIOS_ATA_TRANSLATION_LBA)
2381 qemu_opt_set(hda_opts, "trans", "lba");
2382 if (translation == BIOS_ATA_TRANSLATION_NONE)
2383 qemu_opt_set(hda_opts, "trans", "none");
2384 }
bellard330d0412003-07-26 18:11:40 +00002385 }
2386 break;
aliguori268a3622009-04-21 22:30:27 +00002387 case QEMU_OPTION_numa:
2388 if (nb_numa_nodes >= MAX_NODES) {
2389 fprintf(stderr, "qemu: too many NUMA nodes\n");
2390 exit(1);
2391 }
2392 numa_add(optarg);
2393 break;
Jes Sorensen1472a952011-03-16 13:33:31 +01002394 case QEMU_OPTION_display:
2395 display_type = select_display(optarg);
2396 break;
bellardcd6f1162004-05-13 22:02:20 +00002397 case QEMU_OPTION_nographic:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002398 display_type = DT_NOGRAPHIC;
bellarda20dd502003-09-30 21:07:02 +00002399 break;
balrog4d3b6f62008-02-10 16:33:14 +00002400 case QEMU_OPTION_curses:
Jes Sorensen47b05362011-03-16 13:33:35 +01002401#ifdef CONFIG_CURSES
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002402 display_type = DT_CURSES;
Jes Sorensen47b05362011-03-16 13:33:35 +01002403#else
2404 fprintf(stderr, "Curses support is disabled\n");
2405 exit(1);
balrog4d3b6f62008-02-10 16:33:14 +00002406#endif
Jes Sorensen47b05362011-03-16 13:33:35 +01002407 break;
balroga171fe32007-04-30 01:48:07 +00002408 case QEMU_OPTION_portrait:
Vasily Khoruzhick93128052011-06-17 13:04:36 +03002409 graphic_rotate = 90;
2410 break;
2411 case QEMU_OPTION_rotate:
2412 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
2413 if (graphic_rotate != 0 && graphic_rotate != 90 &&
2414 graphic_rotate != 180 && graphic_rotate != 270) {
2415 fprintf(stderr,
2416 "qemu: only 90, 180, 270 deg rotation is available\n");
2417 exit(1);
2418 }
balroga171fe32007-04-30 01:48:07 +00002419 break;
bellardcd6f1162004-05-13 22:02:20 +00002420 case QEMU_OPTION_kernel:
bellarda20dd502003-09-30 21:07:02 +00002421 kernel_filename = optarg;
2422 break;
bellardcd6f1162004-05-13 22:02:20 +00002423 case QEMU_OPTION_append:
bellarda20dd502003-09-30 21:07:02 +00002424 kernel_cmdline = optarg;
bellard313aa562003-08-10 21:52:11 +00002425 break;
bellardcd6f1162004-05-13 22:02:20 +00002426 case QEMU_OPTION_cdrom:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002427 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
bellard36b486b2003-11-11 13:36:08 +00002428 break;
bellardcd6f1162004-05-13 22:02:20 +00002429 case QEMU_OPTION_boot:
j_mayer28c5af52007-11-11 01:50:45 +00002430 {
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002431 static const char * const params[] = {
wayne3d3b8302011-07-27 18:04:55 +08002432 "order", "once", "menu",
2433 "splash", "splash-time", NULL
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002434 };
2435 char buf[sizeof(boot_devices)];
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002436 char *standard_boot_devices;
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002437 int legacy = 0;
2438
2439 if (!strchr(optarg, '=')) {
2440 legacy = 1;
2441 pstrcpy(buf, sizeof(buf), optarg);
2442 } else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
2443 fprintf(stderr,
2444 "qemu: unknown boot parameter '%s' in '%s'\n",
2445 buf, optarg);
2446 exit(1);
2447 }
2448
2449 if (legacy ||
2450 get_param_value(buf, sizeof(buf), "order", optarg)) {
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -03002451 validate_bootdevices(buf);
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002452 pstrcpy(boot_devices, sizeof(boot_devices), buf);
j_mayer28c5af52007-11-11 01:50:45 +00002453 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002454 if (!legacy) {
2455 if (get_param_value(buf, sizeof(buf),
2456 "once", optarg)) {
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -03002457 validate_bootdevices(buf);
Anthony Liguori7267c092011-08-20 22:09:37 -05002458 standard_boot_devices = g_strdup(boot_devices);
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002459 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2460 qemu_register_reset(restore_boot_devices,
2461 standard_boot_devices);
2462 }
Jan Kiszka95387492009-07-02 00:19:02 +02002463 if (get_param_value(buf, sizeof(buf),
2464 "menu", optarg)) {
2465 if (!strcmp(buf, "on")) {
2466 boot_menu = 1;
2467 } else if (!strcmp(buf, "off")) {
2468 boot_menu = 0;
2469 } else {
2470 fprintf(stderr,
2471 "qemu: invalid option value '%s'\n",
2472 buf);
2473 exit(1);
2474 }
2475 }
wayne3d3b8302011-07-27 18:04:55 +08002476 qemu_opts_parse(qemu_find_opts("boot-opts"),
2477 optarg, 0);
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002478 }
bellard36b486b2003-11-11 13:36:08 +00002479 }
2480 break;
bellardcd6f1162004-05-13 22:02:20 +00002481 case QEMU_OPTION_fda:
bellardcd6f1162004-05-13 22:02:20 +00002482 case QEMU_OPTION_fdb:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002483 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2484 optarg, FD_OPTS);
bellardc45886d2004-01-05 00:02:06 +00002485 break;
bellard52ca8d62006-06-14 16:03:05 +00002486 case QEMU_OPTION_no_fd_bootchk:
2487 fd_bootchk = 0;
2488 break;
Mark McLoughlina1ea4582009-10-08 19:58:26 +01002489 case QEMU_OPTION_netdev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002490 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
Mark McLoughlina1ea4582009-10-08 19:58:26 +01002491 exit(1);
2492 }
2493 break;
bellard7c9d8e02005-11-15 22:16:05 +00002494 case QEMU_OPTION_net:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002495 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
bellardc4b1fcc2004-03-14 21:44:30 +00002496 exit(1);
2497 }
bellard702c6512004-04-02 21:21:32 +00002498 break;
bellardc7f74642004-08-24 21:57:12 +00002499#ifdef CONFIG_SLIRP
2500 case QEMU_OPTION_tftp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02002501 legacy_tftp_prefix = optarg;
bellard9bf05442004-08-25 22:12:49 +00002502 break;
ths47d5d012007-02-20 00:05:08 +00002503 case QEMU_OPTION_bootp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02002504 legacy_bootp_filename = optarg;
ths47d5d012007-02-20 00:05:08 +00002505 break;
bellard9bf05442004-08-25 22:12:49 +00002506 case QEMU_OPTION_redir:
Markus Armbruster07527062009-10-06 12:16:57 +01002507 if (net_slirp_redir(optarg) < 0)
2508 exit(1);
bellard9bf05442004-08-25 22:12:49 +00002509 break;
bellardc7f74642004-08-24 21:57:12 +00002510#endif
balrogdc72ac12008-11-09 00:04:26 +00002511 case QEMU_OPTION_bt:
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002512 add_device_config(DEV_BT, optarg);
balrogdc72ac12008-11-09 00:04:26 +00002513 break;
bellard1d14ffa2005-10-30 18:58:22 +00002514 case QEMU_OPTION_audio_help:
Blue Swirlad960902010-03-29 19:23:52 +00002515 if (!(audio_available())) {
2516 printf("Option %s not supported for this target\n", popt->name);
2517 exit(1);
2518 }
bellard1d14ffa2005-10-30 18:58:22 +00002519 AUD_help ();
2520 exit (0);
2521 break;
2522 case QEMU_OPTION_soundhw:
Blue Swirlad960902010-03-29 19:23:52 +00002523 if (!(audio_available())) {
2524 printf("Option %s not supported for this target\n", popt->name);
2525 exit(1);
2526 }
bellard1d14ffa2005-10-30 18:58:22 +00002527 select_soundhw (optarg);
2528 break;
bellardcd6f1162004-05-13 22:02:20 +00002529 case QEMU_OPTION_h:
ths15f82202007-06-29 23:26:08 +00002530 help(0);
bellardcd6f1162004-05-13 22:02:20 +00002531 break;
pbrook9bd7e6d2009-04-07 22:58:45 +00002532 case QEMU_OPTION_version:
2533 version();
2534 exit(0);
2535 break;
aurel3200f82b82008-04-27 21:12:55 +00002536 case QEMU_OPTION_m: {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +01002537 int64_t value;
aurel3200f82b82008-04-27 21:12:55 +00002538
Jes Sorensen9f9b17a2010-10-21 17:15:46 +02002539 value = strtosz(optarg, NULL);
2540 if (value < 0) {
aurel3200f82b82008-04-27 21:12:55 +00002541 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
bellardcd6f1162004-05-13 22:02:20 +00002542 exit(1);
2543 }
aurel3200f82b82008-04-27 21:12:55 +00002544
Anthony Liguoric227f092009-10-01 16:12:16 -05002545 if (value != (uint64_t)(ram_addr_t)value) {
aurel3200f82b82008-04-27 21:12:55 +00002546 fprintf(stderr, "qemu: ram size too large\n");
2547 exit(1);
2548 }
2549 ram_size = value;
bellardcd6f1162004-05-13 22:02:20 +00002550 break;
aurel3200f82b82008-04-27 21:12:55 +00002551 }
Marcelo Tosattic9027602010-03-01 20:25:08 -03002552 case QEMU_OPTION_mempath:
2553 mem_path = optarg;
2554 break;
2555#ifdef MAP_POPULATE
2556 case QEMU_OPTION_mem_prealloc:
2557 mem_prealloc = 1;
2558 break;
2559#endif
bellardcd6f1162004-05-13 22:02:20 +00002560 case QEMU_OPTION_d:
Matthew Fernandezc235d732011-06-07 16:32:40 +00002561 log_mask = optarg;
2562 break;
2563 case QEMU_OPTION_D:
2564 log_file = optarg;
bellardcd6f1162004-05-13 22:02:20 +00002565 break;
bellardcd6f1162004-05-13 22:02:20 +00002566 case QEMU_OPTION_s:
aliguori59030a82009-04-05 18:43:41 +00002567 gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT;
bellardcd6f1162004-05-13 22:02:20 +00002568 break;
aliguori59030a82009-04-05 18:43:41 +00002569 case QEMU_OPTION_gdb:
2570 gdbstub_dev = optarg;
bellardcd6f1162004-05-13 22:02:20 +00002571 break;
bellardcd6f1162004-05-13 22:02:20 +00002572 case QEMU_OPTION_L:
Paul Brook5cea8592009-05-30 00:52:44 +01002573 data_dir = optarg;
bellardcd6f1162004-05-13 22:02:20 +00002574 break;
j_mayer1192dad2007-10-05 13:08:35 +00002575 case QEMU_OPTION_bios:
2576 bios_name = optarg;
2577 break;
aurel321b530a62009-04-05 20:08:59 +00002578 case QEMU_OPTION_singlestep:
2579 singlestep = 1;
2580 break;
bellardcd6f1162004-05-13 22:02:20 +00002581 case QEMU_OPTION_S:
pbrook3c07f8e2007-01-21 16:47:01 +00002582 autostart = 0;
bellardcd6f1162004-05-13 22:02:20 +00002583 break;
bellard3d11d0e2004-12-12 16:56:30 +00002584 case QEMU_OPTION_k:
2585 keyboard_layout = optarg;
2586 break;
bellardee22c2f2004-06-03 12:49:50 +00002587 case QEMU_OPTION_localtime:
2588 rtc_utc = 0;
2589 break;
malc3893c122008-09-28 00:42:05 +00002590 case QEMU_OPTION_vga:
2591 select_vgahw (optarg);
bellard1bfe8562004-07-08 21:17:50 +00002592 break;
bellarde9b137c2004-06-21 16:46:10 +00002593 case QEMU_OPTION_g:
2594 {
2595 const char *p;
2596 int w, h, depth;
2597 p = optarg;
2598 w = strtol(p, (char **)&p, 10);
2599 if (w <= 0) {
2600 graphic_error:
2601 fprintf(stderr, "qemu: invalid resolution or depth\n");
2602 exit(1);
2603 }
2604 if (*p != 'x')
2605 goto graphic_error;
2606 p++;
2607 h = strtol(p, (char **)&p, 10);
2608 if (h <= 0)
2609 goto graphic_error;
2610 if (*p == 'x') {
2611 p++;
2612 depth = strtol(p, (char **)&p, 10);
ths5fafdf22007-09-16 21:08:06 +00002613 if (depth != 8 && depth != 15 && depth != 16 &&
bellarde9b137c2004-06-21 16:46:10 +00002614 depth != 24 && depth != 32)
2615 goto graphic_error;
2616 } else if (*p == '\0') {
2617 depth = graphic_depth;
2618 } else {
2619 goto graphic_error;
2620 }
ths3b46e622007-09-17 08:09:54 +00002621
bellarde9b137c2004-06-21 16:46:10 +00002622 graphic_width = w;
2623 graphic_height = h;
2624 graphic_depth = depth;
2625 }
2626 break;
ths20d8a3e2007-02-18 17:04:49 +00002627 case QEMU_OPTION_echr:
2628 {
2629 char *r;
2630 term_escape_char = strtol(optarg, &r, 0);
2631 if (r == optarg)
2632 printf("Bad argument to echr\n");
2633 break;
2634 }
bellard82c643f2004-07-14 17:28:13 +00002635 case QEMU_OPTION_monitor:
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002636 monitor_parse(optarg, "readline");
2637 default_monitor = 0;
2638 break;
2639 case QEMU_OPTION_qmp:
2640 monitor_parse(optarg, "control");
Anthony Liguori2d114dc2010-03-21 14:14:38 -05002641 default_monitor = 0;
bellard82c643f2004-07-14 17:28:13 +00002642 break;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002643 case QEMU_OPTION_mon:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002644 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002645 if (!opts) {
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002646 exit(1);
2647 }
Anthony Liguori2d114dc2010-03-21 14:14:38 -05002648 default_monitor = 0;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002649 break;
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002650 case QEMU_OPTION_chardev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002651 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002652 if (!opts) {
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002653 exit(1);
2654 }
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002655 break;
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302656 case QEMU_OPTION_fsdev:
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002657 olist = qemu_find_opts("fsdev");
2658 if (!olist) {
2659 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
2660 exit(1);
2661 }
2662 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302663 if (!opts) {
2664 fprintf(stderr, "parse error: %s\n", optarg);
2665 exit(1);
2666 }
2667 break;
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302668 case QEMU_OPTION_virtfs: {
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00002669 QemuOpts *fsdev;
2670 QemuOpts *device;
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +05302671 const char *writeout;
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302672
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002673 olist = qemu_find_opts("virtfs");
2674 if (!olist) {
2675 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
2676 exit(1);
2677 }
2678 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302679 if (!opts) {
2680 fprintf(stderr, "parse error: %s\n", optarg);
2681 exit(1);
2682 }
2683
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +05302684 if (qemu_opt_get(opts, "fsdriver") == NULL ||
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07002685 qemu_opt_get(opts, "mount_tag") == NULL ||
M. Mohan Kumard9b36a62011-10-14 12:59:37 +05302686 qemu_opt_get(opts, "path") == NULL) {
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +05302687 fprintf(stderr, "Usage: -virtfs fsdriver,path=/share_path/,"
M. Mohan Kumard9b36a62011-10-14 12:59:37 +05302688 "[security_model={mapped|passthrough|none}],"
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00002689 "mount_tag=tag.\n");
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07002690 exit(1);
2691 }
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00002692 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
2693 qemu_opt_get(opts, "mount_tag"), 1);
2694 if (!fsdev) {
2695 fprintf(stderr, "duplicate fsdev id: %s\n",
2696 qemu_opt_get(opts, "mount_tag"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302697 exit(1);
2698 }
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +05302699
2700 writeout = qemu_opt_get(opts, "writeout");
2701 if (writeout) {
2702#ifdef CONFIG_SYNC_FILE_RANGE
2703 qemu_opt_set(fsdev, "writeout", writeout);
2704#else
2705 fprintf(stderr, "writeout=immediate not supported on "
2706 "this platform\n");
2707 exit(1);
2708#endif
2709 }
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +05302710 qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver"));
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00002711 qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"));
2712 qemu_opt_set(fsdev, "security_model",
2713 qemu_opt_get(opts, "security_model"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302714
M. Mohan Kumar2c74c2c2011-10-25 12:10:39 +05302715 qemu_opt_set_bool(fsdev, "readonly",
2716 qemu_opt_get_bool(opts, "readonly", 0));
Stefan Hajnoczie14ea472011-03-16 08:31:43 +00002717 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
2718 qemu_opt_set(device, "driver", "virtio-9p-pci");
2719 qemu_opt_set(device, "fsdev",
2720 qemu_opt_get(opts, "mount_tag"));
2721 qemu_opt_set(device, "mount_tag",
2722 qemu_opt_get(opts, "mount_tag"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302723 break;
2724 }
Aneesh Kumar K.V9db221a2011-10-25 12:10:40 +05302725 case QEMU_OPTION_virtfs_synth: {
2726 QemuOpts *fsdev;
2727 QemuOpts *device;
2728
2729 fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth", 1);
2730 if (!fsdev) {
2731 fprintf(stderr, "duplicate option: %s\n", "virtfs_synth");
2732 exit(1);
2733 }
2734 qemu_opt_set(fsdev, "fsdriver", "synth");
2735 qemu_opt_set(fsdev, "path", "/"); /* ignored */
2736
2737 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
2738 qemu_opt_set(device, "driver", "virtio-9p-pci");
2739 qemu_opt_set(device, "fsdev", "v_synth");
2740 qemu_opt_set(device, "mount_tag", "v_synth");
2741 break;
2742 }
bellard82c643f2004-07-14 17:28:13 +00002743 case QEMU_OPTION_serial:
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002744 add_device_config(DEV_SERIAL, optarg);
2745 default_serial = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01002746 if (strncmp(optarg, "mon:", 4) == 0) {
2747 default_monitor = 0;
2748 }
bellard82c643f2004-07-14 17:28:13 +00002749 break;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01002750 case QEMU_OPTION_watchdog:
Markus Armbruster09aaa162009-08-21 10:31:34 +02002751 if (watchdog) {
2752 fprintf(stderr,
2753 "qemu: only one watchdog option may be given\n");
2754 return 1;
2755 }
2756 watchdog = optarg;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01002757 break;
2758 case QEMU_OPTION_watchdog_action:
2759 if (select_watchdog_action(optarg) == -1) {
2760 fprintf(stderr, "Unknown -watchdog-action parameter\n");
2761 exit(1);
2762 }
2763 break;
aliguori51ecf132009-01-15 20:06:40 +00002764 case QEMU_OPTION_virtiocon:
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002765 add_device_config(DEV_VIRTCON, optarg);
2766 default_virtcon = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01002767 if (strncmp(optarg, "mon:", 4) == 0) {
2768 default_monitor = 0;
2769 }
aliguori51ecf132009-01-15 20:06:40 +00002770 break;
bellard6508fe52005-01-15 12:02:56 +00002771 case QEMU_OPTION_parallel:
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002772 add_device_config(DEV_PARALLEL, optarg);
2773 default_parallel = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01002774 if (strncmp(optarg, "mon:", 4) == 0) {
2775 default_monitor = 0;
2776 }
bellard6508fe52005-01-15 12:02:56 +00002777 break;
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002778 case QEMU_OPTION_debugcon:
2779 add_device_config(DEV_DEBUGCON, optarg);
2780 break;
bellardd63d3072004-10-03 13:29:03 +00002781 case QEMU_OPTION_loadvm:
2782 loadvm = optarg;
2783 break;
2784 case QEMU_OPTION_full_screen:
2785 full_screen = 1;
2786 break;
ths667acca2006-12-11 02:08:05 +00002787#ifdef CONFIG_SDL
ths43523e92007-02-18 18:19:32 +00002788 case QEMU_OPTION_no_frame:
2789 no_frame = 1;
2790 break;
ths3780e192007-06-21 21:08:02 +00002791 case QEMU_OPTION_alt_grab:
2792 alt_grab = 1;
2793 break;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -05002794 case QEMU_OPTION_ctrl_grab:
2795 ctrl_grab = 1;
2796 break;
ths667acca2006-12-11 02:08:05 +00002797 case QEMU_OPTION_no_quit:
2798 no_quit = 1;
2799 break;
aliguori7d957bd2009-01-15 22:14:11 +00002800 case QEMU_OPTION_sdl:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002801 display_type = DT_SDL;
aliguori7d957bd2009-01-15 22:14:11 +00002802 break;
Jes Sorensen58fc0962011-03-16 13:33:34 +01002803#else
2804 case QEMU_OPTION_no_frame:
2805 case QEMU_OPTION_alt_grab:
2806 case QEMU_OPTION_ctrl_grab:
2807 case QEMU_OPTION_no_quit:
2808 case QEMU_OPTION_sdl:
2809 fprintf(stderr, "SDL support is disabled\n");
2810 exit(1);
ths667acca2006-12-11 02:08:05 +00002811#endif
bellardf7cce892004-12-08 22:21:25 +00002812 case QEMU_OPTION_pidfile:
ths93815bc2007-03-19 15:58:31 +00002813 pid_file = optarg;
bellardf7cce892004-12-08 22:21:25 +00002814 break;
bellarda09db212005-04-30 16:10:35 +00002815 case QEMU_OPTION_win2k_hack:
2816 win2k_install_hack = 1;
2817 break;
aliguori73822ec2009-01-15 20:11:34 +00002818 case QEMU_OPTION_rtc_td_hack:
2819 rtc_td_hack = 1;
2820 break;
aliguori8a92ea22009-02-27 20:12:36 +00002821 case QEMU_OPTION_acpitable:
Blue Swirlde06f8d2010-03-29 19:23:50 +00002822 do_acpitable_option(optarg);
aliguori8a92ea22009-02-27 20:12:36 +00002823 break;
aliguorib6f6e3d2009-04-17 18:59:56 +00002824 case QEMU_OPTION_smbios:
Blue Swirlde06f8d2010-03-29 19:23:50 +00002825 do_smbios_option(optarg);
aliguorib6f6e3d2009-04-17 18:59:56 +00002826 break;
aliguori7ba1e612008-11-05 16:04:33 +00002827 case QEMU_OPTION_enable_kvm:
Anthony PERARD303d4e82010-09-21 20:05:31 +01002828 olist = qemu_find_opts("machine");
2829 qemu_opts_reset(olist);
2830 qemu_opts_parse(olist, "accel=kvm", 0);
2831 break;
2832 case QEMU_OPTION_machine:
2833 olist = qemu_find_opts("machine");
2834 qemu_opts_reset(olist);
Jan Kiszka9052ea62011-07-23 12:38:37 +02002835 opts = qemu_opts_parse(olist, optarg, 1);
Anthony PERARD303d4e82010-09-21 20:05:31 +01002836 if (!opts) {
2837 fprintf(stderr, "parse error: %s\n", optarg);
2838 exit(1);
2839 }
Jan Kiszka2645c6d2011-07-25 18:11:20 +02002840 optarg = qemu_opt_get(opts, "type");
2841 if (optarg) {
2842 machine = machine_parse(optarg);
2843 }
aliguori7ba1e612008-11-05 16:04:33 +00002844 break;
bellardbb36d472005-11-05 14:22:28 +00002845 case QEMU_OPTION_usb:
2846 usb_enabled = 1;
2847 break;
bellarda594cfb2005-11-06 16:13:29 +00002848 case QEMU_OPTION_usbdevice:
2849 usb_enabled = 1;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002850 add_device_config(DEV_USB, optarg);
2851 break;
2852 case QEMU_OPTION_device:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002853 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02002854 exit(1);
2855 }
bellarda594cfb2005-11-06 16:13:29 +00002856 break;
bellard6a00d602005-11-21 23:25:50 +00002857 case QEMU_OPTION_smp:
Andre Przywaradc6b1c02009-08-19 15:42:40 +02002858 smp_parse(optarg);
aliguorib2097002008-10-07 20:39:39 +00002859 if (smp_cpus < 1) {
bellard6a00d602005-11-21 23:25:50 +00002860 fprintf(stderr, "Invalid number of CPUs\n");
2861 exit(1);
2862 }
Jes Sorensen6be68d72009-07-23 17:03:42 +02002863 if (max_cpus < smp_cpus) {
2864 fprintf(stderr, "maxcpus must be equal to or greater than "
2865 "smp\n");
2866 exit(1);
2867 }
2868 if (max_cpus > 255) {
2869 fprintf(stderr, "Unsupported number of maxcpus\n");
2870 exit(1);
2871 }
bellard6a00d602005-11-21 23:25:50 +00002872 break;
bellard24236862006-04-30 21:28:36 +00002873 case QEMU_OPTION_vnc:
Jes Sorensen821601e2011-03-16 13:33:36 +01002874#ifdef CONFIG_VNC
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02002875 display_remote++;
Jes Sorensen821601e2011-03-16 13:33:36 +01002876 vnc_display = optarg;
2877#else
2878 fprintf(stderr, "VNC support is disabled\n");
2879 exit(1);
2880#endif
2881 break;
bellard6515b202006-05-03 22:02:44 +00002882 case QEMU_OPTION_no_acpi:
2883 acpi_enabled = 0;
2884 break;
aliguori16b29ae2008-12-17 23:28:44 +00002885 case QEMU_OPTION_no_hpet:
2886 no_hpet = 1;
2887 break;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02002888 case QEMU_OPTION_balloon:
2889 if (balloon_parse(optarg) < 0) {
2890 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
2891 exit(1);
2892 }
Eduardo Habkostdf97b922009-06-10 16:34:08 -03002893 break;
bellardd1beab82006-10-02 19:44:22 +00002894 case QEMU_OPTION_no_reboot:
2895 no_reboot = 1;
2896 break;
aurel32b2f76162008-04-11 21:35:52 +00002897 case QEMU_OPTION_no_shutdown:
2898 no_shutdown = 1;
2899 break;
balrog9467cd42007-05-01 01:34:14 +00002900 case QEMU_OPTION_show_cursor:
2901 cursor_hide = 0;
2902 break;
blueswir18fcb1b92008-09-18 18:29:08 +00002903 case QEMU_OPTION_uuid:
2904 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
2905 fprintf(stderr, "Fail to parse UUID string."
2906 " Wrong format.\n");
2907 exit(1);
2908 }
2909 break;
ths9ae02552007-01-05 17:39:04 +00002910 case QEMU_OPTION_option_rom:
2911 if (nb_option_roms >= MAX_OPTION_ROMS) {
2912 fprintf(stderr, "Too many option ROMs\n");
2913 exit(1);
2914 }
Gleb Natapov2e55e842010-12-08 13:35:07 +02002915 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
2916 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
2917 option_rom[nb_option_roms].bootindex =
2918 qemu_opt_get_number(opts, "bootindex", -1);
2919 if (!option_rom[nb_option_roms].name) {
2920 fprintf(stderr, "Option ROM file is not specified\n");
2921 exit(1);
2922 }
ths9ae02552007-01-05 17:39:04 +00002923 nb_option_roms++;
2924 break;
pbrook8e716212007-01-20 17:12:09 +00002925 case QEMU_OPTION_semihosting:
2926 semihosting_enabled = 1;
2927 break;
thsc35734b2007-03-19 15:17:08 +00002928 case QEMU_OPTION_name:
Anthony Liguori7267c092011-08-20 22:09:37 -05002929 qemu_name = g_strdup(optarg);
Andi Kleen18894652009-07-02 09:34:17 +02002930 {
2931 char *p = strchr(qemu_name, ',');
2932 if (p != NULL) {
2933 *p++ = 0;
2934 if (strncmp(p, "process=", 8)) {
Aurelien Jarno5697f6a2010-12-27 18:29:20 +01002935 fprintf(stderr, "Unknown subargument %s to -name\n", p);
Andi Kleen18894652009-07-02 09:34:17 +02002936 exit(1);
2937 }
2938 p += 8;
Jes Sorensence798cf2010-06-10 11:42:31 +02002939 os_set_proc_name(p);
Andi Kleen18894652009-07-02 09:34:17 +02002940 }
2941 }
thsc35734b2007-03-19 15:17:08 +00002942 break;
blueswir166508602007-05-01 14:16:52 +00002943 case QEMU_OPTION_prom_env:
2944 if (nb_prom_envs >= MAX_PROM_ENVS) {
2945 fprintf(stderr, "Too many prom variables\n");
2946 exit(1);
2947 }
2948 prom_envs[nb_prom_envs] = optarg;
2949 nb_prom_envs++;
2950 break;
balrog2b8f2d42007-07-27 22:08:46 +00002951 case QEMU_OPTION_old_param:
2952 old_param = 1;
ths05ebd532008-01-08 19:32:16 +00002953 break;
thsf3dcfad2007-08-24 01:26:02 +00002954 case QEMU_OPTION_clock:
2955 configure_alarms(optarg);
2956 break;
bellard7e0af5d02007-11-07 16:24:33 +00002957 case QEMU_OPTION_startdate:
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002958 configure_rtc_date_offset(optarg, 1);
2959 break;
2960 case QEMU_OPTION_rtc:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002961 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002962 if (!opts) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002963 exit(1);
bellard7e0af5d02007-11-07 16:24:33 +00002964 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002965 configure_rtc(opts);
bellard7e0af5d02007-11-07 16:24:33 +00002966 break;
bellard26a5f132008-05-28 12:30:31 +00002967 case QEMU_OPTION_tb_size:
Jan Kiszkad5ab9712011-08-02 16:10:21 +02002968 tcg_tb_size = strtol(optarg, NULL, 0);
2969 if (tcg_tb_size < 0) {
2970 tcg_tb_size = 0;
2971 }
bellard26a5f132008-05-28 12:30:31 +00002972 break;
pbrook2e70f6e2008-06-29 01:03:05 +00002973 case QEMU_OPTION_icount:
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01002974 icount_option = optarg;
pbrook2e70f6e2008-06-29 01:03:05 +00002975 break;
aliguori5bb79102008-10-13 03:12:02 +00002976 case QEMU_OPTION_incoming:
2977 incoming = optarg;
2978 break;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01002979 case QEMU_OPTION_nodefaults:
2980 default_serial = 0;
2981 default_parallel = 0;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002982 default_virtcon = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01002983 default_monitor = 0;
2984 default_vga = 0;
Gerd Hoffmanncb4522c2009-12-08 13:11:47 +01002985 default_net = 0;
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01002986 default_floppy = 0;
2987 default_cdrom = 0;
2988 default_sdcard = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01002989 break;
aliguorie37630c2009-04-22 15:19:10 +00002990 case QEMU_OPTION_xen_domid:
Blue Swirlad960902010-03-29 19:23:52 +00002991 if (!(xen_available())) {
2992 printf("Option %s not supported for this target\n", popt->name);
2993 exit(1);
2994 }
aliguorie37630c2009-04-22 15:19:10 +00002995 xen_domid = atoi(optarg);
2996 break;
2997 case QEMU_OPTION_xen_create:
Blue Swirlad960902010-03-29 19:23:52 +00002998 if (!(xen_available())) {
2999 printf("Option %s not supported for this target\n", popt->name);
3000 exit(1);
3001 }
aliguorie37630c2009-04-22 15:19:10 +00003002 xen_mode = XEN_CREATE;
3003 break;
3004 case QEMU_OPTION_xen_attach:
Blue Swirlad960902010-03-29 19:23:52 +00003005 if (!(xen_available())) {
3006 printf("Option %s not supported for this target\n", popt->name);
3007 exit(1);
3008 }
aliguorie37630c2009-04-22 15:19:10 +00003009 xen_mode = XEN_ATTACH;
3010 break;
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003011 case QEMU_OPTION_trace:
Lluíse4858972011-08-31 20:31:03 +02003012 {
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003013 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
Lluíse4858972011-08-31 20:31:03 +02003014 if (!opts) {
3015 exit(1);
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003016 }
Lluís23d15e82011-08-31 20:31:31 +02003017 trace_events = qemu_opt_get(opts, "events");
Lluíse4858972011-08-31 20:31:03 +02003018 trace_file = qemu_opt_get(opts, "file");
Prerna Saxenaab6540d2010-08-09 11:48:32 +01003019 break;
Lluíse4858972011-08-31 20:31:03 +02003020 }
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003021 case QEMU_OPTION_readconfig:
3022 {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01003023 int ret = qemu_read_config_file(optarg);
3024 if (ret < 0) {
3025 fprintf(stderr, "read config %s: %s\n", optarg,
3026 strerror(-ret));
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003027 exit(1);
3028 }
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003029 break;
3030 }
Gerd Hoffmann29b00402010-03-11 11:13:27 -03003031 case QEMU_OPTION_spice:
3032 olist = qemu_find_opts("spice");
3033 if (!olist) {
3034 fprintf(stderr, "spice is not supported by this qemu build.\n");
3035 exit(1);
3036 }
3037 opts = qemu_opts_parse(olist, optarg, 0);
3038 if (!opts) {
3039 fprintf(stderr, "parse error: %s\n", optarg);
3040 exit(1);
3041 }
3042 break;
Gerd Hoffmann715a6642009-10-14 10:39:28 +02003043 case QEMU_OPTION_writeconfig:
3044 {
3045 FILE *fp;
3046 if (strcmp(optarg, "-") == 0) {
3047 fp = stdout;
3048 } else {
3049 fp = fopen(optarg, "w");
3050 if (fp == NULL) {
3051 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
3052 exit(1);
3053 }
3054 }
3055 qemu_config_write(fp);
3056 fclose(fp);
3057 break;
3058 }
Jes Sorensen59a52642010-06-10 11:42:25 +02003059 default:
3060 os_parse_cmd_args(popt->index, optarg);
bellardcd6f1162004-05-13 22:02:20 +00003061 }
bellard0824d6f2003-06-24 13:42:40 +00003062 }
3063 }
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01003064 loc_set_none();
bellard330d0412003-07-26 18:11:40 +00003065
Matthew Fernandezc235d732011-06-07 16:32:40 +00003066 /* Open the logfile at this point, if necessary. We can't open the logfile
3067 * when encountering either of the logging options (-d or -D) because the
3068 * other one may be encountered later on the command line, changing the
3069 * location or level of logging.
3070 */
3071 if (log_mask) {
3072 if (log_file) {
3073 set_cpu_log_filename(log_file);
3074 }
3075 set_cpu_log(log_mask);
3076 }
3077
Lluís23d15e82011-08-31 20:31:31 +02003078 if (!trace_backend_init(trace_events, trace_file)) {
Lluíse4858972011-08-31 20:31:03 +02003079 exit(1);
Stefan Hajnoczi31d3c9b2011-03-13 20:14:30 +00003080 }
Stefan Hajnoczi0b5538c2011-02-26 18:38:39 +00003081
Paul Brook5cea8592009-05-30 00:52:44 +01003082 /* If no data_dir is specified then try to find it relative to the
3083 executable path. */
3084 if (!data_dir) {
Jes Sorensen61705402010-06-10 11:42:23 +02003085 data_dir = os_find_datadir(argv[0]);
Paul Brook5cea8592009-05-30 00:52:44 +01003086 }
Stefan Weil60474fb2011-09-04 15:17:46 +02003087 /* If all else fails use the install path specified when building. */
Paul Brook5cea8592009-05-30 00:52:44 +01003088 if (!data_dir) {
Paolo Bonzini1dabe052010-05-26 16:08:25 +02003089 data_dir = CONFIG_QEMU_DATADIR;
Paul Brook5cea8592009-05-30 00:52:44 +01003090 }
3091
Andreas Färberd4236752011-11-10 16:35:32 +01003092 if (machine == NULL) {
3093 fprintf(stderr, "No machine found.\n");
3094 exit(1);
3095 }
3096
Jes Sorensen6be68d72009-07-23 17:03:42 +02003097 /*
3098 * Default to max_cpus = smp_cpus, in case the user doesn't
3099 * specify a max_cpus value.
3100 */
3101 if (!max_cpus)
3102 max_cpus = smp_cpus;
3103
balrog3d878ca2008-10-28 10:59:59 +00003104 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
aliguorib2097002008-10-07 20:39:39 +00003105 if (smp_cpus > machine->max_cpus) {
3106 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
3107 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
3108 machine->max_cpus);
3109 exit(1);
3110 }
3111
Anthony PERARD67b724e2010-11-22 15:44:15 +00003112 /*
3113 * Get the default machine options from the machine if it is not already
3114 * specified either by the configuration file or by the command line.
3115 */
3116 if (machine->default_machine_opts) {
3117 QemuOptsList *list = qemu_find_opts("machine");
3118 const char *p = NULL;
3119
3120 if (!QTAILQ_EMPTY(&list->head)) {
3121 p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel");
3122 }
3123 if (p == NULL) {
Jan Kiszka9052ea62011-07-23 12:38:37 +02003124 qemu_opts_reset(list);
3125 opts = qemu_opts_parse(list, machine->default_machine_opts, 0);
Anthony PERARD67b724e2010-11-22 15:44:15 +00003126 if (!opts) {
3127 fprintf(stderr, "parse error for machine %s: %s\n",
3128 machine->name, machine->default_machine_opts);
3129 exit(1);
3130 }
3131 }
3132 }
3133
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003134 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
3135 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01003136
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003137 if (machine->no_serial) {
3138 default_serial = 0;
3139 }
3140 if (machine->no_parallel) {
3141 default_parallel = 0;
3142 }
3143 if (!machine->use_virtcon) {
3144 default_virtcon = 0;
3145 }
3146 if (machine->no_vga) {
3147 default_vga = 0;
3148 }
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01003149 if (machine->no_floppy) {
3150 default_floppy = 0;
3151 }
3152 if (machine->no_cdrom) {
3153 default_cdrom = 0;
3154 }
3155 if (machine->no_sdcard) {
3156 default_sdcard = 0;
3157 }
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003158
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003159 if (display_type == DT_NOGRAPHIC) {
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01003160 if (default_parallel)
3161 add_device_config(DEV_PARALLEL, "null");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003162 if (default_serial && default_monitor) {
3163 add_device_config(DEV_SERIAL, "mon:stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003164 } else if (default_virtcon && default_monitor) {
3165 add_device_config(DEV_VIRTCON, "mon:stdio");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003166 } else {
3167 if (default_serial)
3168 add_device_config(DEV_SERIAL, "stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01003169 if (default_virtcon)
3170 add_device_config(DEV_VIRTCON, "stdio");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003171 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01003172 monitor_parse("stdio", "readline");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01003173 }
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01003174 } else {
3175 if (default_serial)
3176 add_device_config(DEV_SERIAL, "vc:80Cx24C");
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01003177 if (default_parallel)
3178 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
Gerd Hoffmannabdeed02009-12-08 13:11:43 +01003179 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01003180 monitor_parse("vc:80Cx24C", "readline");
Alexander Graf38536da2009-12-17 13:06:08 +01003181 if (default_virtcon)
3182 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
aliguoribc0129d2008-08-01 15:12:34 +00003183 }
Gerd Hoffmann64465292009-12-08 13:11:45 +01003184 if (default_vga)
3185 vga_interface_type = VGA_CIRRUS;
aliguoribc0129d2008-08-01 15:12:34 +00003186
TeLeMana5829fd2010-04-15 12:37:55 +08003187 socket_init();
3188
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003189 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01003190 exit(1);
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07003191#ifdef CONFIG_VIRTFS
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003192 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +05303193 exit(1);
3194 }
3195#endif
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01003196
Jes Sorenseneb505be2010-06-10 11:42:28 +02003197 os_daemonize();
ths71e3ceb2006-12-22 02:11:31 +00003198
thsaa26bb22007-03-25 21:33:06 +00003199 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
Jes Sorenseneb505be2010-06-10 11:42:28 +02003200 os_pidfile_error();
ths93815bc2007-03-19 15:58:31 +00003201 exit(1);
3202 }
3203
Jan Kiszka0ac543d2011-08-15 16:18:57 -07003204 /* init the memory */
3205 if (ram_size == 0) {
3206 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
3207 }
3208
Anthony PERARD303d4e82010-09-21 20:05:31 +01003209 configure_accelerator();
Marcelo Tosatti214910a2009-09-18 02:41:23 -03003210
Paolo Bonzinid3b12f52011-09-13 10:30:52 +02003211 qemu_init_cpu_loop();
aliguori3fcf7b62009-04-24 18:03:25 +00003212 if (qemu_init_main_loop()) {
3213 fprintf(stderr, "qemu_init_main_loop failed\n");
3214 exit(1);
3215 }
bellarda20dd502003-09-30 21:07:02 +00003216 linux_boot = (kernel_filename != NULL);
balrog6c41b272007-11-17 12:12:29 +00003217
thsf8d39c02008-07-03 10:01:15 +00003218 if (!linux_boot && *kernel_cmdline != '\0') {
3219 fprintf(stderr, "-append only allowed with -kernel option\n");
3220 exit(1);
3221 }
3222
3223 if (!linux_boot && initrd_filename != NULL) {
3224 fprintf(stderr, "-initrd only allowed with -kernel option\n");
3225 exit(1);
3226 }
3227
Jes Sorensen9156d762010-06-10 11:42:30 +02003228 os_set_line_buffering();
ths3b46e622007-09-17 08:09:54 +00003229
aliguori7183b4b2008-11-05 20:40:18 +00003230 if (init_timer_alarm() < 0) {
3231 fprintf(stderr, "could not initialize alarm timer\n");
3232 exit(1);
3233 }
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01003234 configure_icount(icount_option);
pbrook634fce92006-07-15 17:40:09 +00003235
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01003236 if (net_init_clients() < 0) {
3237 exit(1);
bellard702c6512004-04-02 21:21:32 +00003238 }
bellardf1510b22003-06-25 00:07:40 +00003239
balrogdc72ac12008-11-09 00:04:26 +00003240 /* init the bluetooth world */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003241 if (foreach_device_config(DEV_BT, bt_parse))
3242 exit(1);
balrogdc72ac12008-11-09 00:04:26 +00003243
Anthony PERARD834e76e2011-07-20 08:17:44 +00003244 if (!xen_enabled()) {
3245 /* On 32-bit hosts, QEMU is limited by virtual address space */
3246 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
3247 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
3248 exit(1);
3249 }
3250 }
balrog7fb4fdc2008-04-24 17:59:27 +00003251
Jan Kiszkad5ab9712011-08-02 16:10:21 +02003252 cpu_exec_init_all();
bellard26a5f132008-05-28 12:30:31 +00003253
Markus Armbrustereb852012009-10-27 18:41:44 +01003254 bdrv_init_with_whitelist();
thse4bcb142007-12-02 04:51:10 +00003255
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +02003256 blk_mig_init();
3257
ths96d30e42007-01-07 20:42:14 +00003258 /* open the virtual block devices */
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02003259 if (snapshot)
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003260 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
3261 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02003262 exit(1);
balrog3e3d5812007-04-30 02:09:25 +00003263
Markus Armbruster4e5d9b52011-01-28 11:21:45 +01003264 default_drive(default_cdrom, snapshot, machine->use_scsi,
3265 IF_DEFAULT, 2, CDROM_OPTS);
3266 default_drive(default_floppy, snapshot, machine->use_scsi,
3267 IF_FLOPPY, 0, FD_OPTS);
3268 default_drive(default_sdcard, snapshot, machine->use_scsi,
3269 IF_SD, 0, SD_OPTS);
3270
Alex Williamson97ab12d2010-06-25 11:09:50 -06003271 register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL,
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +02003272 ram_load, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00003273
aliguori268a3622009-04-21 22:30:27 +00003274 if (nb_numa_nodes > 0) {
3275 int i;
3276
Sasha Levinea0e5412011-06-29 23:29:39 -04003277 if (nb_numa_nodes > MAX_NODES) {
3278 nb_numa_nodes = MAX_NODES;
aliguori268a3622009-04-21 22:30:27 +00003279 }
3280
3281 /* If no memory size if given for any node, assume the default case
3282 * and distribute the available memory equally across all nodes
3283 */
3284 for (i = 0; i < nb_numa_nodes; i++) {
3285 if (node_mem[i] != 0)
3286 break;
3287 }
3288 if (i == nb_numa_nodes) {
3289 uint64_t usedmem = 0;
3290
3291 /* On Linux, the each node's border has to be 8MB aligned,
3292 * the final node gets the rest.
3293 */
3294 for (i = 0; i < nb_numa_nodes - 1; i++) {
3295 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
3296 usedmem += node_mem[i];
3297 }
3298 node_mem[i] = ram_size - usedmem;
3299 }
3300
3301 for (i = 0; i < nb_numa_nodes; i++) {
3302 if (node_cpumask[i] != 0)
3303 break;
3304 }
3305 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3306 * must cope with this anyway, because there are BIOSes out there in
3307 * real machines which also use this scheme.
3308 */
3309 if (i == nb_numa_nodes) {
3310 for (i = 0; i < smp_cpus; i++) {
3311 node_cpumask[i % nb_numa_nodes] |= 1 << i;
3312 }
3313 }
3314 }
3315
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003316 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
Jan Kiszka157b9312010-04-06 16:55:53 +02003317 exit(1);
3318 }
3319
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01003320 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
3321 exit(1);
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01003322 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
3323 exit(1);
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01003324 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
3325 exit(1);
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08003326 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
3327 exit(1);
aliguori2796dae2009-01-16 20:23:27 +00003328
Paul Brookaae94602009-05-14 22:35:06 +01003329 module_call_init(MODULE_INIT_DEVICE);
3330
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003331 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0)
Markus Armbrusterff952ba2010-01-29 19:48:57 +01003332 exit(0);
3333
Markus Armbruster09aaa162009-08-21 10:31:34 +02003334 if (watchdog) {
3335 i = select_watchdog(watchdog);
3336 if (i > 0)
3337 exit (i == 1 ? 1 : 0);
3338 }
3339
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02003340 if (machine->compat_props) {
Gerd Hoffmann458fb672009-12-08 13:11:33 +01003341 qdev_prop_register_global_list(machine->compat_props);
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02003342 }
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01003343 qemu_add_globals();
3344
Paul Brookfbe1b592009-05-13 17:56:25 +01003345 machine->init(ram_size, boot_devices,
aliguori3023f332009-01-16 19:04:14 +00003346 kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
3347
Jan Kiszkaea375f92010-03-01 19:10:30 +01003348 cpu_synchronize_all_post_init();
aliguori268a3622009-04-21 22:30:27 +00003349
Blue Swirl87d0a282010-03-27 18:24:45 +00003350 set_numa_modes();
aliguori268a3622009-04-21 22:30:27 +00003351
aliguori6f338c32009-02-11 15:21:54 +00003352 current_machine = machine;
3353
aliguori3023f332009-01-16 19:04:14 +00003354 /* init USB devices */
3355 if (usb_enabled) {
Markus Armbruster07527062009-10-06 12:16:57 +01003356 if (foreach_device_config(DEV_USB, usb_parse) < 0)
3357 exit(1);
aliguori3023f332009-01-16 19:04:14 +00003358 }
3359
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003360 /* init generic devices */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003361 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003362 exit(1);
3363
Markus Armbruster668680f2010-02-11 14:44:58 +01003364 net_check_clients();
3365
aliguori3023f332009-01-16 19:04:14 +00003366 /* just use the first displaystate for the moment */
Paolo Bonzinib473df62010-02-11 00:29:55 +01003367 ds = get_displaystate();
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003368
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003369 if (using_spice)
3370 display_remote++;
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003371 if (display_type == DT_DEFAULT && !display_remote) {
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003372#if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003373 display_type = DT_SDL;
Jes Sorensen821601e2011-03-16 13:33:36 +01003374#elif defined(CONFIG_VNC)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003375 vnc_display = "localhost:0,to=99";
3376 show_vnc_port = 1;
Jes Sorensen821601e2011-03-16 13:33:36 +01003377#else
3378 display_type = DT_NONE;
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003379#endif
3380 }
Jes Sorensen821601e2011-03-16 13:33:36 +01003381
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003382
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003383 /* init local displays */
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003384 switch (display_type) {
3385 case DT_NOGRAPHIC:
3386 break;
3387#if defined(CONFIG_CURSES)
3388 case DT_CURSES:
3389 curses_display_init(ds, full_screen);
3390 break;
3391#endif
bellard5b0753e2005-03-01 21:37:28 +00003392#if defined(CONFIG_SDL)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003393 case DT_SDL:
3394 sdl_display_init(ds, full_screen, no_frame);
3395 break;
bellard5b0753e2005-03-01 21:37:28 +00003396#elif defined(CONFIG_COCOA)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003397 case DT_SDL:
3398 cocoa_display_init(ds, full_screen);
3399 break;
bellard313aa562003-08-10 21:52:11 +00003400#endif
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003401 default:
3402 break;
3403 }
3404
Gleb Natapov0ce235a2011-03-31 11:27:23 +02003405 /* must be after terminal init, SDL library changes signal handlers */
3406 os_setup_signal_handling();
3407
Jes Sorensen821601e2011-03-16 13:33:36 +01003408#ifdef CONFIG_VNC
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003409 /* init remote displays */
3410 if (vnc_display) {
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003411 vnc_display_init(ds);
3412 if (vnc_display_open(ds, vnc_display) < 0)
3413 exit(1);
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003414
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003415 if (show_vnc_port) {
3416 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003417 }
bellard313aa562003-08-10 21:52:11 +00003418 }
Jes Sorensen821601e2011-03-16 13:33:36 +01003419#endif
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003420#ifdef CONFIG_SPICE
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +02003421 if (using_spice && !qxl_enabled) {
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003422 qemu_spice_display_init(ds);
3423 }
3424#endif
aliguori5b08fc12008-08-21 20:08:03 +00003425
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003426 /* display setup */
3427 dpy_resize(ds);
aliguori3023f332009-01-16 19:04:14 +00003428 dcl = ds->listeners;
3429 while (dcl != NULL) {
3430 if (dcl->dpy_refresh != NULL) {
Paolo Bonzini7bd427d2011-03-11 16:47:48 +01003431 ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds);
3432 qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock));
Isaku Yamahata0f2ad632010-05-27 14:38:47 +09003433 break;
ths20d8a3e2007-02-18 17:04:49 +00003434 }
aliguori3023f332009-01-16 19:04:14 +00003435 dcl = dcl->next;
bellard82c643f2004-07-14 17:28:13 +00003436 }
Paolo Bonzinib473df62010-02-11 00:29:55 +01003437 text_consoles_set_display(ds);
aliguori2796dae2009-01-16 20:23:27 +00003438
aliguori59030a82009-04-05 18:43:41 +00003439 if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) {
3440 fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n",
3441 gdbstub_dev);
3442 exit(1);
balrog45669e02007-07-02 13:20:17 +00003443 }
balrog45669e02007-07-02 13:20:17 +00003444
Gerd Hoffmann3418bd22009-09-25 21:42:41 +02003445 qdev_machine_creation_done();
3446
Gerd Hoffmann15ff7702009-12-14 16:07:35 +01003447 if (rom_load_all() != 0) {
3448 fprintf(stderr, "rom loading failed\n");
3449 exit(1);
3450 }
Gerd Hoffmann45a50b12009-10-01 16:42:33 +02003451
Isaku Yamahata80376c32010-12-20 14:33:35 +09003452 /* TODO: once all bus devices are qdevified, this should be done
3453 * when bus is created by qdev.c */
3454 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
Gleb Natapov4cab9462010-12-08 13:35:08 +02003455 qemu_run_machine_init_done_notifiers();
3456
Jan Kiszkae063eb12011-06-14 18:29:43 +02003457 qemu_system_reset(VMRESET_SILENT);
Juan Quintela05f24012009-08-20 19:42:22 +02003458 if (loadvm) {
Markus Armbruster03cd4652010-02-17 16:24:10 +01003459 if (load_vmstate(loadvm) < 0) {
Juan Quintela05f24012009-08-20 19:42:22 +02003460 autostart = 0;
3461 }
3462 }
bellardd63d3072004-10-03 13:29:03 +00003463
Glauber Costa2bb8c102009-07-24 16:20:23 -04003464 if (incoming) {
Luiz Capitulino0461d5a2011-09-30 14:45:27 -03003465 runstate_set(RUN_STATE_INMIGRATE);
Juan Quintela8ca5e802010-06-09 14:10:54 +02003466 int ret = qemu_start_incoming_migration(incoming);
3467 if (ret < 0) {
3468 fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n",
3469 incoming, ret);
3470 exit(ret);
3471 }
Avi Kivity6b99dad2009-08-09 14:39:20 +03003472 } else if (autostart) {
aliguoric0f4ce72009-03-05 23:01:01 +00003473 vm_start();
Avi Kivity6b99dad2009-08-09 14:39:20 +03003474 }
thsffd843b2006-12-21 19:46:43 +00003475
Jes Sorenseneb505be2010-06-10 11:42:28 +02003476 os_setup_post();
ths71e3ceb2006-12-22 02:11:31 +00003477
Paolo Bonzini99435902011-09-12 14:03:13 +02003478 resume_all_vcpus();
bellard8a7ddc32004-03-31 19:00:16 +00003479 main_loop();
Paolo Bonzini99435902011-09-12 14:03:13 +02003480 bdrv_close_all();
3481 pause_all_vcpus();
aliguori63a01ef2008-10-31 19:10:00 +00003482 net_cleanup();
wayne3d3b8302011-07-27 18:04:55 +08003483 res_free();
thsb46a8902007-10-21 23:20:45 +00003484
bellard0824d6f2003-06-24 13:42:40 +00003485 return 0;
3486}