blob: f86724f83aea873a9abe1b3466e6a987e9bf5864 [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#ifdef CONFIG_SIMPLE_TRACE
51#include "trace.h"
52#endif
53
Juan Quintela71e72a12009-07-27 16:12:56 +020054#ifdef CONFIG_BSD
bellard7d3505c2004-05-12 19:32:15 +000055#include <sys/stat.h>
Aurelien Jarnoa167ba52009-11-29 18:00:41 +010056#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
bellard7d3505c2004-05-12 19:32:15 +000057#include <libutil.h>
Juergen Lock92c0e652010-03-25 22:07:12 +010058#include <sys/sysctl.h>
blueswir124646c72008-11-07 16:55:48 +000059#else
60#include <util.h>
blueswir1128ab2f2008-08-15 18:33:42 +000061#endif
Aurelien Jarnobbe813a2009-11-30 15:42:59 +010062#else
blueswir1223f0d72008-09-30 18:12:18 +000063#ifdef __linux__
bellard7d3505c2004-05-12 19:32:15 +000064#include <pty.h>
65#include <malloc.h>
thsbd494f42007-09-16 20:03:23 +000066
bellarde57a8c02005-11-10 23:58:52 +000067#include <linux/ppdev.h>
ths5867c882007-02-17 23:44:43 +000068#include <linux/parport.h>
blueswir1223f0d72008-09-30 18:12:18 +000069#endif
70#ifdef __sun__
thsd5d10bc2007-02-17 22:54:49 +000071#include <sys/stat.h>
72#include <sys/ethernet.h>
73#include <sys/sockio.h>
thsd5d10bc2007-02-17 22:54:49 +000074#include <netinet/arp.h>
thsd5d10bc2007-02-17 22:54:49 +000075#include <netinet/in_systm.h>
76#include <netinet/ip.h>
77#include <netinet/ip_icmp.h> // must come after ip.h
78#include <netinet/udp.h>
79#include <netinet/tcp.h>
80#include <net/if.h>
81#include <syslog.h>
82#include <stropts.h>
bellard67b915a2004-03-31 23:37:16 +000083#endif
bellard7d3505c2004-05-12 19:32:15 +000084#endif
bellardec530c82006-04-25 22:36:06 +000085#endif
bellard67b915a2004-03-31 23:37:16 +000086
blueswir19892fbf2008-08-24 10:34:20 +000087#if defined(__OpenBSD__)
88#include <util.h>
89#endif
90
ths8a16d272008-07-19 09:56:24 +000091#if defined(CONFIG_VDE)
92#include <libvdeplug.h>
93#endif
94
bellard67b915a2004-03-31 23:37:16 +000095#ifdef _WIN32
aliguori49dc7682009-03-08 16:26:59 +000096#include <windows.h>
bellard67b915a2004-03-31 23:37:16 +000097#endif
98
bellard73332e52004-04-04 20:22:28 +000099#ifdef CONFIG_SDL
Stefan Weil59a36a22009-06-18 20:11:03 +0200100#if defined(__APPLE__) || defined(main)
Stefan Weil66936652009-06-13 13:19:11 +0200101#include <SDL.h>
malc880fec52009-02-15 20:18:41 +0000102int qemu_main(int argc, char **argv, char **envp);
103int main(int argc, char **argv)
104{
Stefan Weil59a36a22009-06-18 20:11:03 +0200105 return qemu_main(argc, argv, NULL);
malc880fec52009-02-15 20:18:41 +0000106}
107#undef main
108#define main qemu_main
bellard96bcd4f2004-07-10 16:26:15 +0000109#endif
bellard73332e52004-04-04 20:22:28 +0000110#endif /* CONFIG_SDL */
bellard0824d6f2003-06-24 13:42:40 +0000111
bellard5b0753e2005-03-01 21:37:28 +0000112#ifdef CONFIG_COCOA
113#undef main
114#define main qemu_main
115#endif /* CONFIG_COCOA */
116
blueswir1511d2b12009-03-07 15:32:56 +0000117#include "hw/hw.h"
118#include "hw/boards.h"
119#include "hw/usb.h"
120#include "hw/pcmcia.h"
121#include "hw/pc.h"
blueswir1511d2b12009-03-07 15:32:56 +0000122#include "hw/isa.h"
123#include "hw/baum.h"
124#include "hw/bt.h"
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +0100125#include "hw/watchdog.h"
aliguorib6f6e3d2009-04-17 18:59:56 +0000126#include "hw/smbios.h"
aliguorie37630c2009-04-22 15:19:10 +0000127#include "hw/xen.h"
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +0200128#include "hw/qdev.h"
Gerd Hoffmann45a50b12009-10-01 16:42:33 +0200129#include "hw/loader.h"
aurel325ef4efa2009-03-10 21:43:35 +0000130#include "bt-host.h"
blueswir1511d2b12009-03-07 15:32:56 +0000131#include "net.h"
Mark McLoughlin68ac40d2009-11-25 18:48:54 +0000132#include "net/slirp.h"
blueswir1511d2b12009-03-07 15:32:56 +0000133#include "monitor.h"
134#include "console.h"
135#include "sysemu.h"
136#include "gdbstub.h"
137#include "qemu-timer.h"
138#include "qemu-char.h"
139#include "cache-utils.h"
140#include "block.h"
Markus Armbruster666daa62010-06-02 18:48:27 +0200141#include "blockdev.h"
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +0200142#include "block-migration.h"
blueswir1a718ace2009-03-28 08:24:44 +0000143#include "dma.h"
blueswir1511d2b12009-03-07 15:32:56 +0000144#include "audio/audio.h"
145#include "migration.h"
146#include "kvm.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"
Luiz Capitulinoe78c48e2009-12-10 17:16:04 -0200149#include "qemu-objects.h"
Jes Sorensen59a52642010-06-10 11:42:25 +0200150#include "qemu-options.h"
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -0700151#ifdef CONFIG_VIRTFS
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530152#include "fsdev/qemu-fsdev.h"
153#endif
blueswir1511d2b12009-03-07 15:32:56 +0000154
bellard0824d6f2003-06-24 13:42:40 +0000155#include "disas.h"
bellardfc01f7e2003-06-30 10:03:06 +0000156
blueswir1511d2b12009-03-07 15:32:56 +0000157#include "qemu_socket.h"
158
Jan Kiszkad918f232009-06-24 14:42:30 +0200159#include "slirp/libslirp.h"
blueswir1511d2b12009-03-07 15:32:56 +0000160
Stefan Hajnoczi94b0b5f2010-11-16 12:20:25 +0000161#include "trace.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +0000162#include "qemu-queue.h"
Blue Swirl296af7c2010-03-29 19:23:50 +0000163#include "cpus.h"
Blue Swirlad960902010-03-29 19:23:52 +0000164#include "arch_init.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +0000165
Gerd Hoffmann29b00402010-03-11 11:13:27 -0300166#include "ui/qemu-spice.h"
167
blueswir19dc63a12008-10-04 07:25:46 +0000168//#define DEBUG_NET
169//#define DEBUG_SLIRP
bellard330d0412003-07-26 18:11:40 +0000170
bellard1bfe8562004-07-08 21:17:50 +0000171#define DEFAULT_RAM_SIZE 128
bellard313aa562003-08-10 21:52:11 +0000172
Amit Shah98b19252010-01-20 00:36:52 +0530173#define MAX_VIRTIO_CONSOLES 1
174
Paul Brook5cea8592009-05-30 00:52:44 +0100175static const char *data_dir;
j_mayer1192dad2007-10-05 13:08:35 +0000176const char *bios_name = NULL;
malccb5a7aa2008-09-28 00:42:12 +0000177enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
Anthony Liguori993fbfd2009-05-21 16:54:00 -0500178DisplayType display_type = DT_DEFAULT;
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +0200179int display_remote = 0;
bellard3d11d0e2004-12-12 16:56:30 +0000180const char* keyboard_layout = NULL;
Anthony Liguoric227f092009-10-01 16:12:16 -0500181ram_addr_t ram_size;
Marcelo Tosattic9027602010-03-01 20:25:08 -0300182const char *mem_path = NULL;
183#ifdef MAP_POPULATE
184int mem_prealloc = 0; /* force preallocation of physical target memory */
185#endif
bellardc4b1fcc2004-03-14 21:44:30 +0000186int nb_nics;
bellard7c9d8e02005-11-15 22:16:05 +0000187NICInfo nd_table[MAX_NICS];
bellard8a7ddc32004-03-31 19:00:16 +0000188int vm_running;
Paolo Bonzinid399f672009-07-27 23:17:51 +0200189int autostart;
Amit Shah8e848652010-07-27 15:49:19 +0530190int incoming_expected; /* Started with -incoming and waiting for incoming */
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;
ths73fc9742006-12-22 02:09:07 +0000211const char *vnc_display;
bellard6515b202006-05-03 22:02:44 +0000212int acpi_enabled = 1;
aliguori16b29ae2008-12-17 23:28:44 +0000213int no_hpet = 0;
bellard52ca8d62006-06-14 16:03:05 +0000214int fd_bootchk = 1;
bellardd1beab82006-10-02 19:44:22 +0000215int no_reboot = 0;
aurel32b2f76162008-04-11 21:35:52 +0000216int no_shutdown = 0;
balrog9467cd42007-05-01 01:34:14 +0000217int cursor_hide = 1;
balroga171fe32007-04-30 01:48:07 +0000218int graphic_rotate = 0;
Jes Sorensen6b35e7b2009-08-06 16:25:50 +0200219uint8_t irq0override = 1;
Markus Armbruster09aaa162009-08-21 10:31:34 +0200220const char *watchdog;
Gleb Natapov2e55e842010-12-08 13:35:07 +0200221QEMUOptionRom option_rom[MAX_OPTION_ROMS];
ths9ae02552007-01-05 17:39:04 +0000222int nb_option_roms;
pbrook8e716212007-01-20 17:12:09 +0000223int semihosting_enabled = 0;
balrog2b8f2d42007-07-27 22:08:46 +0000224int old_param = 0;
thsc35734b2007-03-19 15:17:08 +0000225const char *qemu_name;
ths3780e192007-06-21 21:08:02 +0000226int alt_grab = 0;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -0500227int ctrl_grab = 0;
blueswir166508602007-05-01 14:16:52 +0000228unsigned int nb_prom_envs = 0;
229const char *prom_envs[MAX_PROM_ENVS];
Jan Kiszka95387492009-07-02 00:19:02 +0200230int boot_menu;
bellard0824d6f2003-06-24 13:42:40 +0000231
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200232typedef struct FWBootEntry FWBootEntry;
233
234struct FWBootEntry {
235 QTAILQ_ENTRY(FWBootEntry) link;
236 int32_t bootindex;
237 DeviceState *dev;
238 char *suffix;
239};
240
241QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order);
242
aliguori268a3622009-04-21 22:30:27 +0000243int nb_numa_nodes;
244uint64_t node_mem[MAX_NODES];
245uint64_t node_cpumask[MAX_NODES];
246
blueswir19043b622009-01-21 19:28:13 +0000247static QEMUTimer *nographic_timer;
balrogee5605e2007-12-03 03:01:40 +0000248
blueswir18fcb1b92008-09-18 18:29:08 +0000249uint8_t qemu_uuid[16];
250
Jan Kiszka76e30d02009-07-02 00:19:02 +0200251static QEMUBootSetHandler *boot_set_handler;
252static void *boot_set_opaque;
253
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +0200254static NotifierList exit_notifiers =
255 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
256
Gleb Natapov4cab9462010-12-08 13:35:08 +0200257static NotifierList machine_init_done_notifiers =
258 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
259
Blue Swirld745bef2010-03-29 19:23:49 +0000260int kvm_allowed = 0;
261uint32_t xen_domid;
262enum xen_mode xen_mode = XEN_EMULATE;
263
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100264static int default_serial = 1;
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +0100265static int default_parallel = 1;
Gerd Hoffmann986c5f72009-12-08 13:11:54 +0100266static int default_virtcon = 1;
Gerd Hoffmannabdeed02009-12-08 13:11:43 +0100267static int default_monitor = 1;
Gerd Hoffmann64465292009-12-08 13:11:45 +0100268static int default_vga = 1;
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +0100269static int default_floppy = 1;
270static int default_cdrom = 1;
271static int default_sdcard = 1;
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100272
273static struct {
274 const char *driver;
275 int *flag;
276} default_list[] = {
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +0100277 { .driver = "isa-serial", .flag = &default_serial },
278 { .driver = "isa-parallel", .flag = &default_parallel },
Gerd Hoffmannd8bcbab2009-12-16 14:25:40 +0100279 { .driver = "isa-fdc", .flag = &default_floppy },
280 { .driver = "ide-drive", .flag = &default_cdrom },
Amit Shah392ecf52010-01-21 16:19:23 +0530281 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
282 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
283 { .driver = "virtio-serial", .flag = &default_virtcon },
Gerd Hoffmann64465292009-12-08 13:11:45 +0100284 { .driver = "VGA", .flag = &default_vga },
Gerd Hoffmann69fd02e2009-12-16 13:35:19 +0100285 { .driver = "cirrus-vga", .flag = &default_vga },
286 { .driver = "vmware-svga", .flag = &default_vga },
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100287};
288
289static int default_driver_check(QemuOpts *opts, void *opaque)
290{
291 const char *driver = qemu_opt_get(opts, "driver");
292 int i;
293
294 if (!driver)
295 return 0;
296 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
297 if (strcmp(default_list[i].driver, driver) != 0)
298 continue;
299 *(default_list[i].flag) = 0;
300 }
301 return 0;
302}
303
bellard0824d6f2003-06-24 13:42:40 +0000304/***********************************************************/
Paolo Bonzini8f0056b2010-01-13 14:05:34 +0100305/* real time host monotonic timer */
bellard09b26c52006-04-12 21:09:08 +0000306
bellardc4b1fcc2004-03-14 21:44:30 +0000307/***********************************************************/
balrogf6503052008-02-17 11:42:19 +0000308/* host time/date access */
309void qemu_get_timedate(struct tm *tm, int offset)
310{
311 time_t ti;
312 struct tm *ret;
313
314 time(&ti);
315 ti += offset;
316 if (rtc_date_offset == -1) {
317 if (rtc_utc)
318 ret = gmtime(&ti);
319 else
320 ret = localtime(&ti);
321 } else {
322 ti -= rtc_date_offset;
323 ret = gmtime(&ti);
324 }
325
326 memcpy(tm, ret, sizeof(struct tm));
327}
328
329int qemu_timedate_diff(struct tm *tm)
330{
331 time_t seconds;
332
333 if (rtc_date_offset == -1)
334 if (rtc_utc)
335 seconds = mktimegm(tm);
336 else
337 seconds = mktime(tm);
338 else
339 seconds = mktimegm(tm) + rtc_date_offset;
340
341 return seconds - time(NULL);
342}
343
Luiz Capitulino80cd3472010-02-25 12:11:44 -0300344void rtc_change_mon_event(struct tm *tm)
345{
346 QObject *data;
347
348 data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
349 monitor_protocol_event(QEVENT_RTC_CHANGE, data);
350 qobject_decref(data);
351}
352
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200353static void configure_rtc_date_offset(const char *startdate, int legacy)
354{
355 time_t rtc_start_date;
356 struct tm tm;
357
358 if (!strcmp(startdate, "now") && legacy) {
359 rtc_date_offset = -1;
360 } else {
361 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
362 &tm.tm_year,
363 &tm.tm_mon,
364 &tm.tm_mday,
365 &tm.tm_hour,
366 &tm.tm_min,
367 &tm.tm_sec) == 6) {
368 /* OK */
369 } else if (sscanf(startdate, "%d-%d-%d",
370 &tm.tm_year,
371 &tm.tm_mon,
372 &tm.tm_mday) == 3) {
373 tm.tm_hour = 0;
374 tm.tm_min = 0;
375 tm.tm_sec = 0;
376 } else {
377 goto date_fail;
378 }
379 tm.tm_year -= 1900;
380 tm.tm_mon--;
381 rtc_start_date = mktimegm(&tm);
382 if (rtc_start_date == -1) {
383 date_fail:
384 fprintf(stderr, "Invalid date format. Valid formats are:\n"
385 "'2006-06-17T16:01:21' or '2006-06-17'\n");
386 exit(1);
387 }
388 rtc_date_offset = time(NULL) - rtc_start_date;
389 }
390}
391
392static void configure_rtc(QemuOpts *opts)
393{
394 const char *value;
395
396 value = qemu_opt_get(opts, "base");
397 if (value) {
398 if (!strcmp(value, "utc")) {
399 rtc_utc = 1;
400 } else if (!strcmp(value, "localtime")) {
401 rtc_utc = 0;
402 } else {
403 configure_rtc_date_offset(value, 0);
404 }
405 }
Jan Kiszka68752042009-09-15 13:36:04 +0200406 value = qemu_opt_get(opts, "clock");
407 if (value) {
408 if (!strcmp(value, "host")) {
409 rtc_clock = host_clock;
410 } else if (!strcmp(value, "vm")) {
411 rtc_clock = vm_clock;
412 } else {
413 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
414 exit(1);
415 }
416 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200417 value = qemu_opt_get(opts, "driftfix");
418 if (value) {
Blue Swirl7e4c0332010-03-27 21:33:46 +0000419 if (!strcmp(value, "slew")) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200420 rtc_td_hack = 1;
Blue Swirl7e4c0332010-03-27 21:33:46 +0000421 } else if (!strcmp(value, "none")) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200422 rtc_td_hack = 0;
423 } else {
424 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
425 exit(1);
426 }
427 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200428}
429
balrog1ae26a12008-09-28 23:19:47 +0000430/***********************************************************/
431/* Bluetooth support */
432static int nb_hcis;
433static int cur_hci;
434static struct HCIInfo *hci_table[MAX_NICS];
balrogdc72ac12008-11-09 00:04:26 +0000435
balrog1ae26a12008-09-28 23:19:47 +0000436static struct bt_vlan_s {
437 struct bt_scatternet_s net;
438 int id;
439 struct bt_vlan_s *next;
440} *first_bt_vlan;
441
442/* find or alloc a new bluetooth "VLAN" */
blueswir1674bb262008-09-30 18:18:27 +0000443static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
balrog1ae26a12008-09-28 23:19:47 +0000444{
445 struct bt_vlan_s **pvlan, *vlan;
446 for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) {
447 if (vlan->id == id)
448 return &vlan->net;
449 }
450 vlan = qemu_mallocz(sizeof(struct bt_vlan_s));
451 vlan->id = id;
452 pvlan = &first_bt_vlan;
453 while (*pvlan != NULL)
454 pvlan = &(*pvlan)->next;
455 *pvlan = vlan;
456 return &vlan->net;
457}
458
459static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
460{
461}
462
463static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
464{
465 return -ENOTSUP;
466}
467
468static struct HCIInfo null_hci = {
469 .cmd_send = null_hci_send,
470 .sco_send = null_hci_send,
471 .acl_send = null_hci_send,
472 .bdaddr_set = null_hci_addr_set,
473};
474
475struct HCIInfo *qemu_next_hci(void)
476{
477 if (cur_hci == nb_hcis)
478 return &null_hci;
479
480 return hci_table[cur_hci++];
481}
482
balrogdc72ac12008-11-09 00:04:26 +0000483static struct HCIInfo *hci_init(const char *str)
484{
485 char *endp;
486 struct bt_scatternet_s *vlan = 0;
487
488 if (!strcmp(str, "null"))
489 /* null */
490 return &null_hci;
491 else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':'))
492 /* host[:hciN] */
493 return bt_host_hci(str[4] ? str + 5 : "hci0");
494 else if (!strncmp(str, "hci", 3)) {
495 /* hci[,vlan=n] */
496 if (str[3]) {
497 if (!strncmp(str + 3, ",vlan=", 6)) {
498 vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0));
499 if (*endp)
500 vlan = 0;
501 }
502 } else
503 vlan = qemu_find_bt_vlan(0);
504 if (vlan)
505 return bt_new_hci(vlan);
506 }
507
508 fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
509
510 return 0;
511}
512
513static int bt_hci_parse(const char *str)
514{
515 struct HCIInfo *hci;
Anthony Liguoric227f092009-10-01 16:12:16 -0500516 bdaddr_t bdaddr;
balrogdc72ac12008-11-09 00:04:26 +0000517
518 if (nb_hcis >= MAX_NICS) {
519 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
520 return -1;
521 }
522
523 hci = hci_init(str);
524 if (!hci)
525 return -1;
526
527 bdaddr.b[0] = 0x52;
528 bdaddr.b[1] = 0x54;
529 bdaddr.b[2] = 0x00;
530 bdaddr.b[3] = 0x12;
531 bdaddr.b[4] = 0x34;
532 bdaddr.b[5] = 0x56 + nb_hcis;
533 hci->bdaddr_set(hci, bdaddr.b);
534
535 hci_table[nb_hcis++] = hci;
536
537 return 0;
538}
539
540static void bt_vhci_add(int vlan_id)
541{
542 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
543
544 if (!vlan->slave)
545 fprintf(stderr, "qemu: warning: adding a VHCI to "
546 "an empty scatternet %i\n", vlan_id);
547
548 bt_vhci_init(bt_new_hci(vlan));
549}
550
551static struct bt_device_s *bt_device_add(const char *opt)
552{
553 struct bt_scatternet_s *vlan;
554 int vlan_id = 0;
555 char *endp = strstr(opt, ",vlan=");
556 int len = (endp ? endp - opt : strlen(opt)) + 1;
557 char devname[10];
558
559 pstrcpy(devname, MIN(sizeof(devname), len), opt);
560
561 if (endp) {
562 vlan_id = strtol(endp + 6, &endp, 0);
563 if (*endp) {
564 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
565 return 0;
566 }
567 }
568
569 vlan = qemu_find_bt_vlan(vlan_id);
570
571 if (!vlan->slave)
572 fprintf(stderr, "qemu: warning: adding a slave device to "
573 "an empty scatternet %i\n", vlan_id);
574
575 if (!strcmp(devname, "keyboard"))
576 return bt_keyboard_init(vlan);
577
578 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
579 return 0;
580}
581
582static int bt_parse(const char *opt)
583{
584 const char *endp, *p;
585 int vlan;
586
587 if (strstart(opt, "hci", &endp)) {
588 if (!*endp || *endp == ',') {
589 if (*endp)
590 if (!strstart(endp, ",vlan=", 0))
591 opt = endp + 1;
592
593 return bt_hci_parse(opt);
594 }
595 } else if (strstart(opt, "vhci", &endp)) {
596 if (!*endp || *endp == ',') {
597 if (*endp) {
598 if (strstart(endp, ",vlan=", &p)) {
599 vlan = strtol(p, (char **) &endp, 0);
600 if (*endp) {
601 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
602 return 1;
603 }
604 } else {
605 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
606 return 1;
607 }
608 } else
609 vlan = 0;
610
611 bt_vhci_add(vlan);
612 return 0;
613 }
614 } else if (strstart(opt, "device:", &endp))
615 return !bt_device_add(endp);
616
617 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
618 return 1;
619}
620
balrog1ae26a12008-09-28 23:19:47 +0000621/***********************************************************/
622/* QEMU Block devices */
623
Markus Armbruster2292dda2011-01-28 11:21:41 +0100624#define HD_OPTS "media=disk"
625#define CDROM_OPTS "media=cdrom"
626#define FD_OPTS ""
627#define PFLASH_OPTS ""
628#define MTD_OPTS ""
629#define SD_OPTS ""
thse4bcb142007-12-02 04:51:10 +0000630
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200631static int drive_init_func(QemuOpts *opts, void *opaque)
632{
Markus Armbrustera803cb82010-06-02 13:31:55 +0200633 int *use_scsi = opaque;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200634 int fatal_error = 0;
635
Markus Armbrustera803cb82010-06-02 13:31:55 +0200636 if (drive_init(opts, *use_scsi, &fatal_error) == NULL) {
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200637 if (fatal_error)
638 return 1;
639 }
640 return 0;
641}
642
643static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
644{
645 if (NULL == qemu_opt_get(opts, "snapshot")) {
646 qemu_opt_set(opts, "snapshot", "on");
647 }
648 return 0;
649}
650
Markus Armbruster4e5d9b52011-01-28 11:21:45 +0100651static void default_drive(int enable, int snapshot, int use_scsi,
652 BlockInterfaceType type, int index,
653 const char *optstr)
654{
655 QemuOpts *opts;
656
657 if (type == IF_DEFAULT) {
658 type = use_scsi ? IF_SCSI : IF_IDE;
659 }
660
661 if (!enable || drive_get_by_index(type, index)) {
662 return;
663 }
664
665 opts = drive_add(type, index, NULL, optstr);
666 if (snapshot) {
667 drive_enable_snapshot(opts, NULL);
668 }
669 if (drive_init_func(opts, &use_scsi)) {
670 exit(1);
671 }
672}
673
Jan Kiszka76e30d02009-07-02 00:19:02 +0200674void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
675{
676 boot_set_handler = func;
677 boot_set_opaque = opaque;
678}
679
680int qemu_boot_set(const char *boot_devices)
681{
682 if (!boot_set_handler) {
683 return -EINVAL;
684 }
685 return boot_set_handler(boot_set_opaque, boot_devices);
686}
687
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -0300688static void validate_bootdevices(char *devices)
Jan Kiszkaef3adf62009-07-02 00:19:02 +0200689{
690 /* We just do some generic consistency checks */
691 const char *p;
692 int bitmap = 0;
693
694 for (p = devices; *p != '\0'; p++) {
695 /* Allowed boot devices are:
696 * a-b: floppy disk drives
697 * c-f: IDE disk drives
698 * g-m: machine implementation dependant drives
699 * n-p: network devices
700 * It's up to each machine implementation to check if the given boot
701 * devices match the actual hardware implementation and firmware
702 * features.
703 */
704 if (*p < 'a' || *p > 'p') {
705 fprintf(stderr, "Invalid boot device '%c'\n", *p);
706 exit(1);
707 }
708 if (bitmap & (1 << (*p - 'a'))) {
709 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
710 exit(1);
711 }
712 bitmap |= 1 << (*p - 'a');
713 }
Jan Kiszkaef3adf62009-07-02 00:19:02 +0200714}
715
Jan Kiszkae0f084b2009-07-02 00:19:02 +0200716static void restore_boot_devices(void *opaque)
717{
718 char *standard_boot_devices = opaque;
Alex Williamson37905d62010-04-30 15:21:11 -0600719 static int first = 1;
720
721 /* Restore boot order and remove ourselves after the first boot */
722 if (first) {
723 first = 0;
724 return;
725 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +0200726
727 qemu_boot_set(standard_boot_devices);
728
729 qemu_unregister_reset(restore_boot_devices, standard_boot_devices);
730 qemu_free(standard_boot_devices);
731}
732
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200733void add_boot_device_path(int32_t bootindex, DeviceState *dev,
734 const char *suffix)
735{
736 FWBootEntry *node, *i;
737
738 if (bootindex < 0) {
739 return;
740 }
741
742 assert(dev != NULL || suffix != NULL);
743
744 node = qemu_mallocz(sizeof(FWBootEntry));
745 node->bootindex = bootindex;
746 node->suffix = strdup(suffix);
747 node->dev = dev;
748
749 QTAILQ_FOREACH(i, &fw_boot_order, link) {
750 if (i->bootindex == bootindex) {
751 fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
752 exit(1);
753 } else if (i->bootindex < bootindex) {
754 continue;
755 }
756 QTAILQ_INSERT_BEFORE(i, node, link);
757 return;
758 }
759 QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
760}
761
Gleb Natapov962630f2010-12-08 13:35:09 +0200762/*
763 * This function returns null terminated string that consist of new line
764 * separated device pathes.
765 *
766 * memory pointed by "size" is assigned total length of the array in bytes
767 *
768 */
769char *get_boot_devices_list(uint32_t *size)
770{
771 FWBootEntry *i;
772 uint32_t total = 0;
773 char *list = NULL;
774
775 QTAILQ_FOREACH(i, &fw_boot_order, link) {
776 char *devpath = NULL, *bootpath;
777 int len;
778
779 if (i->dev) {
780 devpath = qdev_get_fw_dev_path(i->dev);
781 assert(devpath);
782 }
783
784 if (i->suffix && devpath) {
Blue Swirl4fd37a92010-12-19 14:05:43 +0000785 size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
786
787 bootpath = qemu_malloc(bootpathlen);
788 snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
Gleb Natapov962630f2010-12-08 13:35:09 +0200789 qemu_free(devpath);
790 } else if (devpath) {
791 bootpath = devpath;
792 } else {
793 bootpath = strdup(i->suffix);
794 assert(bootpath);
795 }
796
797 if (total) {
798 list[total-1] = '\n';
799 }
800 len = strlen(bootpath) + 1;
801 list = qemu_realloc(list, total + len);
802 memcpy(&list[total], bootpath, len);
803 total += len;
804 qemu_free(bootpath);
805 }
806
807 *size = total;
808
809 return list;
810}
811
aliguori268a3622009-04-21 22:30:27 +0000812static void numa_add(const char *optarg)
813{
814 char option[128];
815 char *endptr;
816 unsigned long long value, endvalue;
817 int nodenr;
818
819 optarg = get_opt_name(option, 128, optarg, ',') + 1;
820 if (!strcmp(option, "node")) {
821 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
822 nodenr = nb_numa_nodes;
823 } else {
824 nodenr = strtoull(option, NULL, 10);
825 }
826
827 if (get_param_value(option, 128, "mem", optarg) == 0) {
828 node_mem[nodenr] = 0;
829 } else {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +0100830 int64_t sval;
Jes Sorensen9f9b17a2010-10-21 17:15:46 +0200831 sval = strtosz(option, NULL);
832 if (sval < 0) {
833 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
834 exit(1);
aliguori268a3622009-04-21 22:30:27 +0000835 }
Jes Sorensen9f9b17a2010-10-21 17:15:46 +0200836 node_mem[nodenr] = sval;
aliguori268a3622009-04-21 22:30:27 +0000837 }
838 if (get_param_value(option, 128, "cpus", optarg) == 0) {
839 node_cpumask[nodenr] = 0;
840 } else {
841 value = strtoull(option, &endptr, 10);
842 if (value >= 64) {
843 value = 63;
844 fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n");
845 } else {
846 if (*endptr == '-') {
847 endvalue = strtoull(endptr+1, &endptr, 10);
848 if (endvalue >= 63) {
849 endvalue = 62;
850 fprintf(stderr,
851 "only 63 CPUs in NUMA mode supported.\n");
852 }
Paolo Bonzini0dfbd512010-02-04 14:31:50 +0100853 value = (2ULL << endvalue) - (1ULL << value);
aliguori268a3622009-04-21 22:30:27 +0000854 } else {
Paolo Bonzini0dfbd512010-02-04 14:31:50 +0100855 value = 1ULL << value;
aliguori268a3622009-04-21 22:30:27 +0000856 }
857 }
858 node_cpumask[nodenr] = value;
859 }
860 nb_numa_nodes++;
861 }
862 return;
863}
864
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200865static void smp_parse(const char *optarg)
866{
867 int smp, sockets = 0, threads = 0, cores = 0;
868 char *endptr;
869 char option[128];
870
871 smp = strtoul(optarg, &endptr, 10);
872 if (endptr != optarg) {
873 if (*endptr == ',') {
874 endptr++;
875 }
876 }
877 if (get_param_value(option, 128, "sockets", endptr) != 0)
878 sockets = strtoull(option, NULL, 10);
879 if (get_param_value(option, 128, "cores", endptr) != 0)
880 cores = strtoull(option, NULL, 10);
881 if (get_param_value(option, 128, "threads", endptr) != 0)
882 threads = strtoull(option, NULL, 10);
883 if (get_param_value(option, 128, "maxcpus", endptr) != 0)
884 max_cpus = strtoull(option, NULL, 10);
885
886 /* compute missing values, prefer sockets over cores over threads */
887 if (smp == 0 || sockets == 0) {
888 sockets = sockets > 0 ? sockets : 1;
889 cores = cores > 0 ? cores : 1;
890 threads = threads > 0 ? threads : 1;
891 if (smp == 0) {
892 smp = cores * threads * sockets;
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200893 }
894 } else {
895 if (cores == 0) {
896 threads = threads > 0 ? threads : 1;
897 cores = smp / (sockets * threads);
898 } else {
Joel Schoppdca98162010-07-21 15:05:17 -0500899 threads = smp / (cores * sockets);
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200900 }
901 }
902 smp_cpus = smp;
903 smp_cores = cores > 0 ? cores : 1;
904 smp_threads = threads > 0 ? threads : 1;
905 if (max_cpus == 0)
906 max_cpus = smp_cpus;
907}
908
bellard330d0412003-07-26 18:11:40 +0000909/***********************************************************/
bellarda594cfb2005-11-06 16:13:29 +0000910/* USB devices */
911
Markus Armbrusterfb080002010-05-28 15:38:44 +0200912static int usb_device_add(const char *devname)
bellarda594cfb2005-11-06 16:13:29 +0000913{
914 const char *p;
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200915 USBDevice *dev = NULL;
bellarda594cfb2005-11-06 16:13:29 +0000916
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200917 if (!usb_enabled)
bellarda594cfb2005-11-06 16:13:29 +0000918 return -1;
919
Gerd Hoffmann0958b4c2009-10-26 15:56:45 +0100920 /* drivers with .usbdevice_name entry in USBDeviceInfo */
921 dev = usbdevice_create(devname);
922 if (dev)
923 goto done;
924
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200925 /* the other ones */
bellarda594cfb2005-11-06 16:13:29 +0000926 if (strstart(devname, "host:", &p)) {
927 dev = usb_host_device_open(p);
balrogdc72ac12008-11-09 00:04:26 +0000928 } else if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
929 dev = usb_bt_init(devname[2] ? hci_init(p) :
930 bt_new_hci(qemu_find_bt_vlan(0)));
bellarda594cfb2005-11-06 16:13:29 +0000931 } else {
932 return -1;
933 }
pbrook0d92ed32006-05-21 16:30:15 +0000934 if (!dev)
935 return -1;
936
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200937done:
bellarda594cfb2005-11-06 16:13:29 +0000938 return 0;
939}
940
aliguori1f3870a2008-08-21 19:27:48 +0000941static int usb_device_del(const char *devname)
942{
943 int bus_num, addr;
944 const char *p;
945
aliguori5d0c5752008-09-14 01:07:41 +0000946 if (strstart(devname, "host:", &p))
947 return usb_host_device_close(p);
948
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200949 if (!usb_enabled)
aliguori1f3870a2008-08-21 19:27:48 +0000950 return -1;
951
952 p = strchr(devname, '.');
953 if (!p)
954 return -1;
955 bus_num = strtoul(devname, NULL, 0);
956 addr = strtoul(p + 1, NULL, 0);
957
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200958 return usb_device_delete_addr(bus_num, addr);
aliguori1f3870a2008-08-21 19:27:48 +0000959}
960
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +0200961static int usb_parse(const char *cmdline)
962{
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800963 int r;
Markus Armbrusterfb080002010-05-28 15:38:44 +0200964 r = usb_device_add(cmdline);
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800965 if (r < 0) {
966 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
967 }
968 return r;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +0200969}
970
Luiz Capitulinod54908a2009-08-28 15:27:13 -0300971void do_usb_add(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +0000972{
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800973 const char *devname = qdict_get_str(qdict, "devname");
Markus Armbrusterfb080002010-05-28 15:38:44 +0200974 if (usb_device_add(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +0100975 error_report("could not add USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800976 }
bellarda594cfb2005-11-06 16:13:29 +0000977}
978
Luiz Capitulinod54908a2009-08-28 15:27:13 -0300979void do_usb_del(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +0000980{
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800981 const char *devname = qdict_get_str(qdict, "devname");
982 if (usb_device_del(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +0100983 error_report("could not delete USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800984 }
bellarda594cfb2005-11-06 16:13:29 +0000985}
986
bellardf7cce892004-12-08 22:21:25 +0000987/***********************************************************/
balrog201a51f2007-04-30 00:51:09 +0000988/* PCMCIA/Cardbus */
989
990static struct pcmcia_socket_entry_s {
Paul Brookbc24a222009-05-10 01:44:56 +0100991 PCMCIASocket *socket;
balrog201a51f2007-04-30 00:51:09 +0000992 struct pcmcia_socket_entry_s *next;
993} *pcmcia_sockets = 0;
994
Paul Brookbc24a222009-05-10 01:44:56 +0100995void pcmcia_socket_register(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +0000996{
997 struct pcmcia_socket_entry_s *entry;
998
999 entry = qemu_malloc(sizeof(struct pcmcia_socket_entry_s));
1000 entry->socket = socket;
1001 entry->next = pcmcia_sockets;
1002 pcmcia_sockets = entry;
1003}
1004
Paul Brookbc24a222009-05-10 01:44:56 +01001005void pcmcia_socket_unregister(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +00001006{
1007 struct pcmcia_socket_entry_s *entry, **ptr;
1008
1009 ptr = &pcmcia_sockets;
1010 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1011 if (entry->socket == socket) {
1012 *ptr = entry->next;
1013 qemu_free(entry);
1014 }
1015}
1016
aliguori376253e2009-03-05 23:01:23 +00001017void pcmcia_info(Monitor *mon)
balrog201a51f2007-04-30 00:51:09 +00001018{
1019 struct pcmcia_socket_entry_s *iter;
aliguori376253e2009-03-05 23:01:23 +00001020
balrog201a51f2007-04-30 00:51:09 +00001021 if (!pcmcia_sockets)
aliguori376253e2009-03-05 23:01:23 +00001022 monitor_printf(mon, "No PCMCIA sockets\n");
balrog201a51f2007-04-30 00:51:09 +00001023
1024 for (iter = pcmcia_sockets; iter; iter = iter->next)
aliguori376253e2009-03-05 23:01:23 +00001025 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1026 iter->socket->attached ? iter->socket->card_string :
1027 "Empty");
balrog201a51f2007-04-30 00:51:09 +00001028}
1029
1030/***********************************************************/
bellard8a7ddc32004-03-31 19:00:16 +00001031/* I/O handling */
bellard0824d6f2003-06-24 13:42:40 +00001032
bellardc4b1fcc2004-03-14 21:44:30 +00001033typedef struct IOHandlerRecord {
1034 int fd;
Juan Quintela7b27a762010-03-11 17:55:39 +01001035 IOCanReadHandler *fd_read_poll;
bellard7c9d8e02005-11-15 22:16:05 +00001036 IOHandler *fd_read;
1037 IOHandler *fd_write;
thscafffd42007-02-28 21:59:44 +00001038 int deleted;
bellardc4b1fcc2004-03-14 21:44:30 +00001039 void *opaque;
1040 /* temporary data */
1041 struct pollfd *ufd;
Juan Quintela31d4ee62010-03-11 17:55:37 +01001042 QLIST_ENTRY(IOHandlerRecord) next;
bellardc4b1fcc2004-03-14 21:44:30 +00001043} IOHandlerRecord;
1044
Juan Quintela31d4ee62010-03-11 17:55:37 +01001045static QLIST_HEAD(, IOHandlerRecord) io_handlers =
1046 QLIST_HEAD_INITIALIZER(io_handlers);
1047
bellardc4b1fcc2004-03-14 21:44:30 +00001048
bellard7c9d8e02005-11-15 22:16:05 +00001049/* XXX: fd_read_poll should be suppressed, but an API change is
1050 necessary in the character devices to suppress fd_can_read(). */
ths5fafdf22007-09-16 21:08:06 +00001051int qemu_set_fd_handler2(int fd,
Juan Quintela7b27a762010-03-11 17:55:39 +01001052 IOCanReadHandler *fd_read_poll,
ths5fafdf22007-09-16 21:08:06 +00001053 IOHandler *fd_read,
1054 IOHandler *fd_write,
bellard7c9d8e02005-11-15 22:16:05 +00001055 void *opaque)
bellardb4608c02003-06-27 17:34:32 +00001056{
Juan Quintela31d4ee62010-03-11 17:55:37 +01001057 IOHandlerRecord *ioh;
bellard8a7ddc32004-03-31 19:00:16 +00001058
bellard7c9d8e02005-11-15 22:16:05 +00001059 if (!fd_read && !fd_write) {
Juan Quintela31d4ee62010-03-11 17:55:37 +01001060 QLIST_FOREACH(ioh, &io_handlers, next) {
bellard7c9d8e02005-11-15 22:16:05 +00001061 if (ioh->fd == fd) {
thscafffd42007-02-28 21:59:44 +00001062 ioh->deleted = 1;
bellard7c9d8e02005-11-15 22:16:05 +00001063 break;
1064 }
bellard8a7ddc32004-03-31 19:00:16 +00001065 }
bellard7c9d8e02005-11-15 22:16:05 +00001066 } else {
Juan Quintela31d4ee62010-03-11 17:55:37 +01001067 QLIST_FOREACH(ioh, &io_handlers, next) {
bellard7c9d8e02005-11-15 22:16:05 +00001068 if (ioh->fd == fd)
1069 goto found;
1070 }
1071 ioh = qemu_mallocz(sizeof(IOHandlerRecord));
Juan Quintela31d4ee62010-03-11 17:55:37 +01001072 QLIST_INSERT_HEAD(&io_handlers, ioh, next);
bellard7c9d8e02005-11-15 22:16:05 +00001073 found:
1074 ioh->fd = fd;
1075 ioh->fd_read_poll = fd_read_poll;
1076 ioh->fd_read = fd_read;
1077 ioh->fd_write = fd_write;
1078 ioh->opaque = opaque;
thscafffd42007-02-28 21:59:44 +00001079 ioh->deleted = 0;
bellard8a7ddc32004-03-31 19:00:16 +00001080 }
bellard7c9d8e02005-11-15 22:16:05 +00001081 return 0;
1082}
1083
ths5fafdf22007-09-16 21:08:06 +00001084int qemu_set_fd_handler(int fd,
1085 IOHandler *fd_read,
1086 IOHandler *fd_write,
bellard7c9d8e02005-11-15 22:16:05 +00001087 void *opaque)
1088{
1089 return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque);
bellardb4608c02003-06-27 17:34:32 +00001090}
1091
bellard8a7ddc32004-03-31 19:00:16 +00001092/***********************************************************/
bellardcc1daa42005-06-05 14:49:17 +00001093/* machine registration */
1094
blueswir1bdaf78e2008-10-04 07:24:27 +00001095static QEMUMachine *first_machine = NULL;
aliguori6f338c32009-02-11 15:21:54 +00001096QEMUMachine *current_machine = NULL;
bellardcc1daa42005-06-05 14:49:17 +00001097
1098int qemu_register_machine(QEMUMachine *m)
1099{
1100 QEMUMachine **pm;
1101 pm = &first_machine;
1102 while (*pm != NULL)
1103 pm = &(*pm)->next;
1104 m->next = NULL;
1105 *pm = m;
1106 return 0;
1107}
1108
pbrook9596ebb2007-11-18 01:44:38 +00001109static QEMUMachine *find_machine(const char *name)
bellardcc1daa42005-06-05 14:49:17 +00001110{
1111 QEMUMachine *m;
1112
1113 for(m = first_machine; m != NULL; m = m->next) {
1114 if (!strcmp(m->name, name))
1115 return m;
Mark McLoughlin3f6599e2009-07-22 10:02:50 +01001116 if (m->alias && !strcmp(m->alias, name))
1117 return m;
bellardcc1daa42005-06-05 14:49:17 +00001118 }
1119 return NULL;
1120}
1121
Anthony Liguori0c257432009-05-21 20:41:01 -05001122static QEMUMachine *find_default_machine(void)
1123{
1124 QEMUMachine *m;
1125
1126 for(m = first_machine; m != NULL; m = m->next) {
1127 if (m->is_default) {
1128 return m;
1129 }
1130 }
1131 return NULL;
1132}
1133
bellardcc1daa42005-06-05 14:49:17 +00001134/***********************************************************/
bellard8a7ddc32004-03-31 19:00:16 +00001135/* main execution loop */
1136
pbrook9596ebb2007-11-18 01:44:38 +00001137static void gui_update(void *opaque)
bellard8a7ddc32004-03-31 19:00:16 +00001138{
aliguori7d957bd2009-01-15 22:14:11 +00001139 uint64_t interval = GUI_REFRESH_INTERVAL;
ths740733b2007-06-08 01:57:56 +00001140 DisplayState *ds = opaque;
aliguori7d957bd2009-01-15 22:14:11 +00001141 DisplayChangeListener *dcl = ds->listeners;
1142
Sheng Yang62a27442010-01-26 19:21:16 +08001143 qemu_flush_coalesced_mmio_buffer();
aliguori7d957bd2009-01-15 22:14:11 +00001144 dpy_refresh(ds);
1145
1146 while (dcl != NULL) {
1147 if (dcl->gui_timer_interval &&
1148 dcl->gui_timer_interval < interval)
1149 interval = dcl->gui_timer_interval;
1150 dcl = dcl->next;
1151 }
1152 qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock));
bellard8a7ddc32004-03-31 19:00:16 +00001153}
1154
blueswir19043b622009-01-21 19:28:13 +00001155static void nographic_update(void *opaque)
1156{
1157 uint64_t interval = GUI_REFRESH_INTERVAL;
1158
Sheng Yang62a27442010-01-26 19:21:16 +08001159 qemu_flush_coalesced_mmio_buffer();
blueswir19043b622009-01-21 19:28:13 +00001160 qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock));
1161}
1162
bellard0bd48852005-11-11 00:00:47 +00001163struct vm_change_state_entry {
1164 VMChangeStateHandler *cb;
1165 void *opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001166 QLIST_ENTRY (vm_change_state_entry) entries;
bellard0bd48852005-11-11 00:00:47 +00001167};
1168
Blue Swirl72cf2d42009-09-12 07:36:22 +00001169static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
bellard0bd48852005-11-11 00:00:47 +00001170
1171VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1172 void *opaque)
1173{
1174 VMChangeStateEntry *e;
1175
1176 e = qemu_mallocz(sizeof (*e));
bellard0bd48852005-11-11 00:00:47 +00001177
1178 e->cb = cb;
1179 e->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001180 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
bellard0bd48852005-11-11 00:00:47 +00001181 return e;
1182}
1183
1184void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1185{
Blue Swirl72cf2d42009-09-12 07:36:22 +00001186 QLIST_REMOVE (e, entries);
bellard0bd48852005-11-11 00:00:47 +00001187 qemu_free (e);
1188}
1189
Blue Swirl296af7c2010-03-29 19:23:50 +00001190void vm_state_notify(int running, int reason)
bellard0bd48852005-11-11 00:00:47 +00001191{
1192 VMChangeStateEntry *e;
1193
Stefan Hajnoczi94b0b5f2010-11-16 12:20:25 +00001194 trace_vm_state_notify(running, reason);
1195
bellard0bd48852005-11-11 00:00:47 +00001196 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
aliguori9781e042009-01-22 17:15:29 +00001197 e->cb(e->opaque, running, reason);
bellard0bd48852005-11-11 00:00:47 +00001198 }
1199}
1200
bellard8a7ddc32004-03-31 19:00:16 +00001201void vm_start(void)
1202{
1203 if (!vm_running) {
1204 cpu_enable_ticks();
1205 vm_running = 1;
aliguori9781e042009-01-22 17:15:29 +00001206 vm_state_notify(1, 0);
aliguorid6dc3d42009-04-24 18:04:07 +00001207 resume_all_vcpus();
Luiz Capitulino6ed2c482010-04-27 20:35:59 -03001208 monitor_protocol_event(QEVENT_RESUME, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00001209 }
1210}
1211
bellardbb0c6722004-06-20 12:37:32 +00001212/* reset/shutdown handler */
1213
1214typedef struct QEMUResetEntry {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001215 QTAILQ_ENTRY(QEMUResetEntry) entry;
bellardbb0c6722004-06-20 12:37:32 +00001216 QEMUResetHandler *func;
1217 void *opaque;
bellardbb0c6722004-06-20 12:37:32 +00001218} QEMUResetEntry;
1219
Blue Swirl72cf2d42009-09-12 07:36:22 +00001220static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1221 QTAILQ_HEAD_INITIALIZER(reset_handlers);
bellardbb0c6722004-06-20 12:37:32 +00001222static int reset_requested;
1223static int shutdown_requested;
bellard34751872005-07-02 14:31:34 +00001224static int powerdown_requested;
Blue Swirl296af7c2010-03-29 19:23:50 +00001225int debug_requested;
Blue Swirl7277e022010-04-12 17:19:06 +00001226int vmstop_requested;
bellardbb0c6722004-06-20 12:37:32 +00001227
aurel32cf7a2fe2008-03-18 06:53:05 +00001228int qemu_shutdown_requested(void)
1229{
1230 int r = shutdown_requested;
1231 shutdown_requested = 0;
1232 return r;
1233}
1234
1235int qemu_reset_requested(void)
1236{
1237 int r = reset_requested;
1238 reset_requested = 0;
1239 return r;
1240}
1241
1242int qemu_powerdown_requested(void)
1243{
1244 int r = powerdown_requested;
1245 powerdown_requested = 0;
1246 return r;
1247}
1248
aliguorie5689022009-04-24 18:03:54 +00001249static int qemu_debug_requested(void)
1250{
1251 int r = debug_requested;
1252 debug_requested = 0;
1253 return r;
1254}
1255
aliguori6e29f5d2009-04-24 18:04:02 +00001256static int qemu_vmstop_requested(void)
1257{
1258 int r = vmstop_requested;
1259 vmstop_requested = 0;
1260 return r;
1261}
1262
Jan Kiszkaa08d4362009-06-27 09:25:07 +02001263void qemu_register_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001264{
Jan Kiszka55ddfe82009-07-02 00:19:02 +02001265 QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry));
bellardbb0c6722004-06-20 12:37:32 +00001266
bellardbb0c6722004-06-20 12:37:32 +00001267 re->func = func;
1268 re->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001269 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
bellardbb0c6722004-06-20 12:37:32 +00001270}
1271
Jan Kiszkadda9b292009-07-02 00:19:02 +02001272void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001273{
1274 QEMUResetEntry *re;
1275
Blue Swirl72cf2d42009-09-12 07:36:22 +00001276 QTAILQ_FOREACH(re, &reset_handlers, entry) {
Jan Kiszkadda9b292009-07-02 00:19:02 +02001277 if (re->func == func && re->opaque == opaque) {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001278 QTAILQ_REMOVE(&reset_handlers, re, entry);
Jan Kiszkadda9b292009-07-02 00:19:02 +02001279 qemu_free(re);
1280 return;
1281 }
1282 }
1283}
1284
1285void qemu_system_reset(void)
1286{
1287 QEMUResetEntry *re, *nre;
1288
1289 /* reset all devices */
Blue Swirl72cf2d42009-09-12 07:36:22 +00001290 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
bellardbb0c6722004-06-20 12:37:32 +00001291 re->func(re->opaque);
1292 }
Luiz Capitulino81d9b782010-03-10 09:06:34 -06001293 monitor_protocol_event(QEVENT_RESET, NULL);
Jan Kiszkaea375f92010-03-01 19:10:30 +01001294 cpu_synchronize_all_post_reset();
bellardbb0c6722004-06-20 12:37:32 +00001295}
1296
1297void qemu_system_reset_request(void)
1298{
bellardd1beab82006-10-02 19:44:22 +00001299 if (no_reboot) {
1300 shutdown_requested = 1;
1301 } else {
1302 reset_requested = 1;
1303 }
aliguorid9f75a42009-04-24 18:03:11 +00001304 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001305}
1306
1307void qemu_system_shutdown_request(void)
1308{
1309 shutdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001310 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001311}
1312
bellard34751872005-07-02 14:31:34 +00001313void qemu_system_powerdown_request(void)
1314{
1315 powerdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001316 qemu_notify_event();
1317}
1318
Paolo Bonzinid6f4ade2010-03-10 11:38:54 +01001319void main_loop_wait(int nonblocking)
aliguori56f3a5d2008-10-31 18:07:17 +00001320{
1321 IOHandlerRecord *ioh;
1322 fd_set rfds, wfds, xfds;
1323 int ret, nfds;
1324 struct timeval tv;
Paolo Bonzinid6f4ade2010-03-10 11:38:54 +01001325 int timeout;
aliguori56f3a5d2008-10-31 18:07:17 +00001326
Paolo Bonzinid6f4ade2010-03-10 11:38:54 +01001327 if (nonblocking)
1328 timeout = 0;
1329 else {
1330 timeout = qemu_calculate_timeout();
1331 qemu_bh_update_timeout(&timeout);
1332 }
aliguori56f3a5d2008-10-31 18:07:17 +00001333
Jes Sorensen0d93ca72010-06-10 11:42:18 +02001334 os_host_main_loop_wait(&timeout);
aliguori56f3a5d2008-10-31 18:07:17 +00001335
bellardfd1dff42006-02-01 21:29:26 +00001336 /* poll any events */
1337 /* XXX: separate device handlers from system ones */
aliguori6abfbd72008-11-05 20:49:37 +00001338 nfds = -1;
bellardfd1dff42006-02-01 21:29:26 +00001339 FD_ZERO(&rfds);
1340 FD_ZERO(&wfds);
bellarde0356492006-05-01 13:33:02 +00001341 FD_ZERO(&xfds);
Juan Quintela31d4ee62010-03-11 17:55:37 +01001342 QLIST_FOREACH(ioh, &io_handlers, next) {
thscafffd42007-02-28 21:59:44 +00001343 if (ioh->deleted)
1344 continue;
bellardfd1dff42006-02-01 21:29:26 +00001345 if (ioh->fd_read &&
1346 (!ioh->fd_read_poll ||
1347 ioh->fd_read_poll(ioh->opaque) != 0)) {
1348 FD_SET(ioh->fd, &rfds);
1349 if (ioh->fd > nfds)
1350 nfds = ioh->fd;
1351 }
1352 if (ioh->fd_write) {
1353 FD_SET(ioh->fd, &wfds);
1354 if (ioh->fd > nfds)
1355 nfds = ioh->fd;
1356 }
1357 }
ths3b46e622007-09-17 08:09:54 +00001358
aliguori56f3a5d2008-10-31 18:07:17 +00001359 tv.tv_sec = timeout / 1000;
1360 tv.tv_usec = (timeout % 1000) * 1000;
1361
Jan Kiszkad918f232009-06-24 14:42:30 +02001362 slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
1363
aliguori48708522009-04-24 18:03:49 +00001364 qemu_mutex_unlock_iothread();
bellarde0356492006-05-01 13:33:02 +00001365 ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
aliguori48708522009-04-24 18:03:49 +00001366 qemu_mutex_lock_iothread();
bellardfd1dff42006-02-01 21:29:26 +00001367 if (ret > 0) {
Juan Quintela31d4ee62010-03-11 17:55:37 +01001368 IOHandlerRecord *pioh;
thscafffd42007-02-28 21:59:44 +00001369
Juan Quintela31d4ee62010-03-11 17:55:37 +01001370 QLIST_FOREACH_SAFE(ioh, &io_handlers, next, pioh) {
Stefan Hajnoczi0290b572010-11-03 14:29:44 +00001371 if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {
1372 ioh->fd_read(ioh->opaque);
1373 }
1374 if (!ioh->deleted && ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) {
1375 ioh->fd_write(ioh->opaque);
1376 }
1377
1378 /* Do this last in case read/write handlers marked it for deletion */
thscafffd42007-02-28 21:59:44 +00001379 if (ioh->deleted) {
Juan Quintela31d4ee62010-03-11 17:55:37 +01001380 QLIST_REMOVE(ioh, next);
thscafffd42007-02-28 21:59:44 +00001381 qemu_free(ioh);
Juan Quintela31d4ee62010-03-11 17:55:37 +01001382 }
thscafffd42007-02-28 21:59:44 +00001383 }
bellardfd1dff42006-02-01 21:29:26 +00001384 }
Jan Kiszkad918f232009-06-24 14:42:30 +02001385
1386 slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));
bellardc20709a2004-04-21 23:27:19 +00001387
Paolo Bonzinib6964822010-03-10 11:38:45 +01001388 qemu_run_all_timers();
Jan Kiszka21d5d122009-09-15 13:36:04 +02001389
pbrook423f0742007-05-23 00:06:54 +00001390 /* Check bottom-halves last in case any of the earlier events triggered
1391 them. */
1392 qemu_bh_poll();
ths3b46e622007-09-17 08:09:54 +00001393
bellard5905b2e2004-08-01 21:53:26 +00001394}
1395
aliguori43b96852009-04-24 18:03:33 +00001396static int vm_can_run(void)
1397{
1398 if (powerdown_requested)
1399 return 0;
1400 if (reset_requested)
1401 return 0;
1402 if (shutdown_requested)
1403 return 0;
aliguorie5689022009-04-24 18:03:54 +00001404 if (debug_requested)
1405 return 0;
aliguori43b96852009-04-24 18:03:33 +00001406 return 1;
1407}
1408
Blue Swirld9c32312009-08-09 08:42:19 +00001409qemu_irq qemu_system_powerdown;
1410
aliguori43b96852009-04-24 18:03:33 +00001411static void main_loop(void)
1412{
aliguori6e29f5d2009-04-24 18:04:02 +00001413 int r;
aliguori43b96852009-04-24 18:03:33 +00001414
Blue Swirl7277e022010-04-12 17:19:06 +00001415 qemu_main_loop_start();
aliguorid6dc3d42009-04-24 18:04:07 +00001416
aliguori6e29f5d2009-04-24 18:04:02 +00001417 for (;;) {
aliguorie6e35b12009-04-24 18:03:57 +00001418 do {
Paolo Bonzinid6f4ade2010-03-10 11:38:54 +01001419 bool nonblocking = false;
aliguorie6e35b12009-04-24 18:03:57 +00001420#ifdef CONFIG_PROFILER
1421 int64_t ti;
1422#endif
aliguorid6dc3d42009-04-24 18:04:07 +00001423#ifndef CONFIG_IOTHREAD
Jan Kiszka472fb0c2010-06-25 16:56:55 +02001424 nonblocking = cpu_exec_all();
aliguorid6dc3d42009-04-24 18:04:07 +00001425#endif
aliguori43b96852009-04-24 18:03:33 +00001426#ifdef CONFIG_PROFILER
1427 ti = profile_getclock();
1428#endif
Paolo Bonzinid6f4ade2010-03-10 11:38:54 +01001429 main_loop_wait(nonblocking);
aliguori43b96852009-04-24 18:03:33 +00001430#ifdef CONFIG_PROFILER
1431 dev_time += profile_getclock() - ti;
1432#endif
aliguorie5689022009-04-24 18:03:54 +00001433 } while (vm_can_run());
aliguori43b96852009-04-24 18:03:33 +00001434
Blue Swirl54fc6ea2010-03-29 19:23:46 +00001435 if ((r = qemu_debug_requested())) {
1436 vm_stop(r);
Luiz Capitulinob1a15e72009-11-26 22:59:04 -02001437 }
aliguori43b96852009-04-24 18:03:33 +00001438 if (qemu_shutdown_requested()) {
Blue Swirl242cd002009-12-04 18:05:45 +00001439 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
aliguori43b96852009-04-24 18:03:33 +00001440 if (no_shutdown) {
1441 vm_stop(0);
1442 no_shutdown = 0;
1443 } else
1444 break;
1445 }
aliguorid6dc3d42009-04-24 18:04:07 +00001446 if (qemu_reset_requested()) {
1447 pause_all_vcpus();
aliguori43b96852009-04-24 18:03:33 +00001448 qemu_system_reset();
aliguorid6dc3d42009-04-24 18:04:07 +00001449 resume_all_vcpus();
1450 }
Blue Swirld9c32312009-08-09 08:42:19 +00001451 if (qemu_powerdown_requested()) {
Blue Swirl242cd002009-12-04 18:05:45 +00001452 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
Blue Swirld9c32312009-08-09 08:42:19 +00001453 qemu_irq_raise(qemu_system_powerdown);
1454 }
Luiz Capitulinob1a15e72009-11-26 22:59:04 -02001455 if ((r = qemu_vmstop_requested())) {
aliguori6e29f5d2009-04-24 18:04:02 +00001456 vm_stop(r);
Luiz Capitulinob1a15e72009-11-26 22:59:04 -02001457 }
aliguori43b96852009-04-24 18:03:33 +00001458 }
MORITA Kazutaka2bc93fe2010-05-28 11:44:57 +09001459 bdrv_close_all();
aliguorid6dc3d42009-04-24 18:04:07 +00001460 pause_all_vcpus();
bellardb4608c02003-06-27 17:34:32 +00001461}
1462
pbrook9bd7e6d2009-04-07 22:58:45 +00001463static void version(void)
1464{
Thomas Monjalonf75ca1a2010-04-28 14:42:01 +02001465 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
pbrook9bd7e6d2009-04-07 22:58:45 +00001466}
1467
ths15f82202007-06-29 23:26:08 +00001468static void help(int exitcode)
bellard0824d6f2003-06-24 13:42:40 +00001469{
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001470 const char *options_help =
Blue Swirlad960902010-03-29 19:23:52 +00001471#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1472 opt_help
blueswir15824d652009-03-28 06:44:27 +00001473#define DEFHEADING(text) stringify(text) "\n"
Jes Sorensen9f167322010-06-10 11:42:24 +02001474#include "qemu-options.def"
blueswir15824d652009-03-28 06:44:27 +00001475#undef DEF
1476#undef DEFHEADING
1477#undef GEN_DOCS
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001478 ;
1479 version();
1480 printf("usage: %s [options] [disk_image]\n"
malc3f020d72010-02-08 12:04:56 +03001481 "\n"
Thomas Monjalonf75ca1a2010-04-28 14:42:01 +02001482 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001483 "\n"
1484 "%s\n"
malc3f020d72010-02-08 12:04:56 +03001485 "During emulation, the following keys are useful:\n"
1486 "ctrl-alt-f toggle full screen\n"
1487 "ctrl-alt-n switch to virtual console 'n'\n"
1488 "ctrl-alt toggle mouse and keyboard grab\n"
1489 "\n"
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001490 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1491 "qemu",
1492 options_help);
ths15f82202007-06-29 23:26:08 +00001493 exit(exitcode);
bellard0824d6f2003-06-24 13:42:40 +00001494}
1495
bellardcd6f1162004-05-13 22:02:20 +00001496#define HAS_ARG 0x0001
1497
bellardcd6f1162004-05-13 22:02:20 +00001498typedef struct QEMUOption {
1499 const char *name;
1500 int flags;
1501 int index;
Blue Swirlad960902010-03-29 19:23:52 +00001502 uint32_t arch_mask;
bellardcd6f1162004-05-13 22:02:20 +00001503} QEMUOption;
1504
blueswir1dbed7e42008-10-01 19:38:09 +00001505static const QEMUOption qemu_options[] = {
Blue Swirlad960902010-03-29 19:23:52 +00001506 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1507#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1508 { option, opt_arg, opt_enum, arch_mask },
blueswir15824d652009-03-28 06:44:27 +00001509#define DEFHEADING(text)
Jes Sorensen9f167322010-06-10 11:42:24 +02001510#include "qemu-options.def"
blueswir15824d652009-03-28 06:44:27 +00001511#undef DEF
1512#undef DEFHEADING
1513#undef GEN_DOCS
bellardcd6f1162004-05-13 22:02:20 +00001514 { NULL },
bellardfc01f7e2003-06-30 10:03:06 +00001515};
malc3893c122008-09-28 00:42:05 +00001516static void select_vgahw (const char *p)
1517{
1518 const char *opts;
1519
Gerd Hoffmann64465292009-12-08 13:11:45 +01001520 default_vga = 0;
Zachary Amsden86176752009-07-30 00:15:02 -10001521 vga_interface_type = VGA_NONE;
malc3893c122008-09-28 00:42:05 +00001522 if (strstart(p, "std", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001523 vga_interface_type = VGA_STD;
malc3893c122008-09-28 00:42:05 +00001524 } else if (strstart(p, "cirrus", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001525 vga_interface_type = VGA_CIRRUS;
malc3893c122008-09-28 00:42:05 +00001526 } else if (strstart(p, "vmware", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001527 vga_interface_type = VGA_VMWARE;
aliguori94909d92009-04-22 15:19:53 +00001528 } else if (strstart(p, "xenfb", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001529 vga_interface_type = VGA_XENFB;
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +02001530 } else if (strstart(p, "qxl", &opts)) {
1531 vga_interface_type = VGA_QXL;
aliguori28b85ed2009-04-22 15:19:48 +00001532 } else if (!strstart(p, "none", &opts)) {
malc3893c122008-09-28 00:42:05 +00001533 invalid_vga:
1534 fprintf(stderr, "Unknown vga type: %s\n", p);
1535 exit(1);
1536 }
malccb5a7aa2008-09-28 00:42:12 +00001537 while (*opts) {
1538 const char *nextopt;
1539
1540 if (strstart(opts, ",retrace=", &nextopt)) {
1541 opts = nextopt;
1542 if (strstart(opts, "dumb", &nextopt))
1543 vga_retrace_method = VGA_RETRACE_DUMB;
1544 else if (strstart(opts, "precise", &nextopt))
1545 vga_retrace_method = VGA_RETRACE_PRECISE;
1546 else goto invalid_vga;
1547 } else goto invalid_vga;
1548 opts = nextopt;
1549 }
malc3893c122008-09-28 00:42:05 +00001550}
1551
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001552static int balloon_parse(const char *arg)
1553{
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001554 QemuOpts *opts;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001555
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001556 if (strcmp(arg, "none") == 0) {
1557 return 0;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001558 }
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001559
1560 if (!strncmp(arg, "virtio", 6)) {
1561 if (arg[6] == ',') {
1562 /* have params -> parse them */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001563 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001564 if (!opts)
1565 return -1;
1566 } else {
1567 /* create empty opts */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001568 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001569 }
1570 qemu_opt_set(opts, "driver", "virtio-balloon-pci");
1571 return 0;
1572 }
1573
1574 return -1;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001575}
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001576
Paul Brook5cea8592009-05-30 00:52:44 +01001577char *qemu_find_file(int type, const char *name)
1578{
1579 int len;
1580 const char *subdir;
1581 char *buf;
1582
1583 /* If name contains path separators then try it as a straight path. */
1584 if ((strchr(name, '/') || strchr(name, '\\'))
1585 && access(name, R_OK) == 0) {
Jean-Christophe DUBOIS73ffc802009-09-02 23:59:06 +02001586 return qemu_strdup(name);
Paul Brook5cea8592009-05-30 00:52:44 +01001587 }
1588 switch (type) {
1589 case QEMU_FILE_TYPE_BIOS:
1590 subdir = "";
1591 break;
1592 case QEMU_FILE_TYPE_KEYMAP:
1593 subdir = "keymaps/";
1594 break;
1595 default:
1596 abort();
1597 }
1598 len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
1599 buf = qemu_mallocz(len);
Blue Swirl3a417592009-06-09 19:12:21 +00001600 snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
Paul Brook5cea8592009-05-30 00:52:44 +01001601 if (access(buf, R_OK)) {
1602 qemu_free(buf);
1603 return NULL;
1604 }
1605 return buf;
1606}
1607
Markus Armbrusterff952ba2010-01-29 19:48:57 +01001608static int device_help_func(QemuOpts *opts, void *opaque)
1609{
1610 return qdev_device_help(opts);
1611}
1612
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02001613static int device_init_func(QemuOpts *opts, void *opaque)
1614{
1615 DeviceState *dev;
1616
1617 dev = qdev_device_add(opts);
1618 if (!dev)
1619 return -1;
1620 return 0;
1621}
1622
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01001623static int chardev_init_func(QemuOpts *opts, void *opaque)
1624{
1625 CharDriverState *chr;
1626
1627 chr = qemu_chr_open_opts(opts, NULL);
1628 if (!chr)
1629 return -1;
1630 return 0;
1631}
1632
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07001633#ifdef CONFIG_VIRTFS
Gautham R Shenoy74db9202010-04-29 17:44:43 +05301634static int fsdev_init_func(QemuOpts *opts, void *opaque)
1635{
1636 int ret;
1637 ret = qemu_fsdev_add(opts);
1638
1639 return ret;
1640}
1641#endif
1642
Gerd Hoffmann88589342009-12-08 13:11:50 +01001643static int mon_init_func(QemuOpts *opts, void *opaque)
1644{
1645 CharDriverState *chr;
1646 const char *chardev;
1647 const char *mode;
1648 int flags;
1649
1650 mode = qemu_opt_get(opts, "mode");
1651 if (mode == NULL) {
1652 mode = "readline";
1653 }
1654 if (strcmp(mode, "readline") == 0) {
1655 flags = MONITOR_USE_READLINE;
1656 } else if (strcmp(mode, "control") == 0) {
1657 flags = MONITOR_USE_CONTROL;
1658 } else {
1659 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
1660 exit(1);
1661 }
1662
Daniel P. Berrange39eaab92010-06-07 15:42:31 +01001663 if (qemu_opt_get_bool(opts, "pretty", 0))
1664 flags |= MONITOR_USE_PRETTY;
1665
Gerd Hoffmann88589342009-12-08 13:11:50 +01001666 if (qemu_opt_get_bool(opts, "default", 0))
1667 flags |= MONITOR_IS_DEFAULT;
1668
1669 chardev = qemu_opt_get(opts, "chardev");
1670 chr = qemu_chr_find(chardev);
1671 if (chr == NULL) {
1672 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
1673 exit(1);
1674 }
1675
1676 monitor_init(chr, flags);
1677 return 0;
1678}
1679
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01001680static void monitor_parse(const char *optarg, const char *mode)
Gerd Hoffmann88589342009-12-08 13:11:50 +01001681{
1682 static int monitor_device_index = 0;
1683 QemuOpts *opts;
1684 const char *p;
1685 char label[32];
1686 int def = 0;
1687
1688 if (strstart(optarg, "chardev:", &p)) {
1689 snprintf(label, sizeof(label), "%s", p);
1690 } else {
Jan Kiszka140e0652010-04-06 16:55:52 +02001691 snprintf(label, sizeof(label), "compat_monitor%d",
1692 monitor_device_index);
1693 if (monitor_device_index == 0) {
Gerd Hoffmann88589342009-12-08 13:11:50 +01001694 def = 1;
1695 }
1696 opts = qemu_chr_parse_compat(label, optarg);
1697 if (!opts) {
1698 fprintf(stderr, "parse error: %s\n", optarg);
1699 exit(1);
1700 }
1701 }
1702
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001703 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1);
Gerd Hoffmann88589342009-12-08 13:11:50 +01001704 if (!opts) {
1705 fprintf(stderr, "duplicate chardev: %s\n", label);
1706 exit(1);
1707 }
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01001708 qemu_opt_set(opts, "mode", mode);
Gerd Hoffmann88589342009-12-08 13:11:50 +01001709 qemu_opt_set(opts, "chardev", label);
1710 if (def)
1711 qemu_opt_set(opts, "default", "on");
1712 monitor_device_index++;
1713}
1714
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001715struct device_config {
1716 enum {
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001717 DEV_USB, /* -usbdevice */
1718 DEV_BT, /* -bt */
1719 DEV_SERIAL, /* -serial */
1720 DEV_PARALLEL, /* -parallel */
1721 DEV_VIRTCON, /* -virtioconsole */
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001722 DEV_DEBUGCON, /* -debugcon */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001723 } type;
1724 const char *cmdline;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001725 QTAILQ_ENTRY(device_config) next;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001726};
Blue Swirl72cf2d42009-09-12 07:36:22 +00001727QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001728
1729static void add_device_config(int type, const char *cmdline)
1730{
1731 struct device_config *conf;
1732
1733 conf = qemu_mallocz(sizeof(*conf));
1734 conf->type = type;
1735 conf->cmdline = cmdline;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001736 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001737}
1738
1739static int foreach_device_config(int type, int (*func)(const char *cmdline))
1740{
1741 struct device_config *conf;
1742 int rc;
1743
Blue Swirl72cf2d42009-09-12 07:36:22 +00001744 QTAILQ_FOREACH(conf, &device_configs, next) {
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001745 if (conf->type != type)
1746 continue;
1747 rc = func(conf->cmdline);
1748 if (0 != rc)
1749 return rc;
1750 }
1751 return 0;
1752}
1753
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01001754static int serial_parse(const char *devname)
1755{
1756 static int index = 0;
1757 char label[32];
1758
1759 if (strcmp(devname, "none") == 0)
1760 return 0;
1761 if (index == MAX_SERIAL_PORTS) {
1762 fprintf(stderr, "qemu: too many serial ports\n");
1763 exit(1);
1764 }
1765 snprintf(label, sizeof(label), "serial%d", index);
1766 serial_hds[index] = qemu_chr_open(label, devname, NULL);
1767 if (!serial_hds[index]) {
1768 fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
1769 devname, strerror(errno));
1770 return -1;
1771 }
1772 index++;
1773 return 0;
1774}
1775
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01001776static int parallel_parse(const char *devname)
1777{
1778 static int index = 0;
1779 char label[32];
1780
1781 if (strcmp(devname, "none") == 0)
1782 return 0;
1783 if (index == MAX_PARALLEL_PORTS) {
1784 fprintf(stderr, "qemu: too many parallel ports\n");
1785 exit(1);
1786 }
1787 snprintf(label, sizeof(label), "parallel%d", index);
1788 parallel_hds[index] = qemu_chr_open(label, devname, NULL);
1789 if (!parallel_hds[index]) {
1790 fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
1791 devname, strerror(errno));
1792 return -1;
1793 }
1794 index++;
1795 return 0;
1796}
1797
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001798static int virtcon_parse(const char *devname)
1799{
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001800 QemuOptsList *device = qemu_find_opts("device");
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001801 static int index = 0;
1802 char label[32];
Amit Shah392ecf52010-01-21 16:19:23 +05301803 QemuOpts *bus_opts, *dev_opts;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001804
1805 if (strcmp(devname, "none") == 0)
1806 return 0;
1807 if (index == MAX_VIRTIO_CONSOLES) {
1808 fprintf(stderr, "qemu: too many virtio consoles\n");
1809 exit(1);
1810 }
Amit Shah392ecf52010-01-21 16:19:23 +05301811
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001812 bus_opts = qemu_opts_create(device, NULL, 0);
Amit Shah392ecf52010-01-21 16:19:23 +05301813 qemu_opt_set(bus_opts, "driver", "virtio-serial");
1814
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001815 dev_opts = qemu_opts_create(device, NULL, 0);
Amit Shah392ecf52010-01-21 16:19:23 +05301816 qemu_opt_set(dev_opts, "driver", "virtconsole");
1817
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001818 snprintf(label, sizeof(label), "virtcon%d", index);
1819 virtcon_hds[index] = qemu_chr_open(label, devname, NULL);
1820 if (!virtcon_hds[index]) {
1821 fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
1822 devname, strerror(errno));
1823 return -1;
1824 }
Amit Shah392ecf52010-01-21 16:19:23 +05301825 qemu_opt_set(dev_opts, "chardev", label);
1826
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001827 index++;
1828 return 0;
1829}
1830
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001831static int debugcon_parse(const char *devname)
1832{
1833 QemuOpts *opts;
1834
1835 if (!qemu_chr_open("debugcon", devname, NULL)) {
1836 exit(1);
1837 }
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001838 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001839 if (!opts) {
1840 fprintf(stderr, "qemu: already have a debugcon device\n");
1841 exit(1);
1842 }
1843 qemu_opt_set(opts, "driver", "isa-debugcon");
1844 qemu_opt_set(opts, "chardev", "debugcon");
1845 return 0;
1846}
1847
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02001848void qemu_add_exit_notifier(Notifier *notify)
1849{
1850 notifier_list_add(&exit_notifiers, notify);
1851}
1852
1853void qemu_remove_exit_notifier(Notifier *notify)
1854{
1855 notifier_list_remove(&exit_notifiers, notify);
1856}
1857
1858static void qemu_run_exit_notifiers(void)
1859{
1860 notifier_list_notify(&exit_notifiers);
1861}
1862
Gleb Natapov4cab9462010-12-08 13:35:08 +02001863void qemu_add_machine_init_done_notifier(Notifier *notify)
1864{
1865 notifier_list_add(&machine_init_done_notifiers, notify);
1866}
1867
1868static void qemu_run_machine_init_done_notifiers(void)
1869{
1870 notifier_list_notify(&machine_init_done_notifiers);
1871}
1872
Anthony Liguori6530a972010-01-22 09:18:06 -06001873static const QEMUOption *lookup_opt(int argc, char **argv,
1874 const char **poptarg, int *poptind)
1875{
1876 const QEMUOption *popt;
1877 int optind = *poptind;
1878 char *r = argv[optind];
1879 const char *optarg;
1880
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001881 loc_set_cmdline(argv, optind, 1);
Anthony Liguori6530a972010-01-22 09:18:06 -06001882 optind++;
1883 /* Treat --foo the same as -foo. */
1884 if (r[1] == '-')
1885 r++;
1886 popt = qemu_options;
1887 for(;;) {
1888 if (!popt->name) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001889 error_report("invalid option");
Anthony Liguori6530a972010-01-22 09:18:06 -06001890 exit(1);
1891 }
1892 if (!strcmp(popt->name, r + 1))
1893 break;
1894 popt++;
1895 }
1896 if (popt->flags & HAS_ARG) {
1897 if (optind >= argc) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001898 error_report("requires an argument");
Anthony Liguori6530a972010-01-22 09:18:06 -06001899 exit(1);
1900 }
1901 optarg = argv[optind++];
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001902 loc_set_cmdline(argv, optind - 2, 2);
Anthony Liguori6530a972010-01-22 09:18:06 -06001903 } else {
1904 optarg = NULL;
1905 }
1906
1907 *poptarg = optarg;
1908 *poptind = optind;
1909
1910 return popt;
1911}
1912
malc902b3d52008-12-10 19:18:40 +00001913int main(int argc, char **argv, char **envp)
bellard0824d6f2003-06-24 13:42:40 +00001914{
aliguori59030a82009-04-05 18:43:41 +00001915 const char *gdbstub_dev = NULL;
thse4bcb142007-12-02 04:51:10 +00001916 int i;
Eduardo Habkostda1fcfd2010-04-06 19:22:07 -03001917 int snapshot, linux_boot;
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01001918 const char *icount_option = NULL;
bellard7f7f9872003-10-30 01:11:23 +00001919 const char *initrd_filename;
bellarda20dd502003-09-30 21:07:02 +00001920 const char *kernel_filename, *kernel_cmdline;
Anthony Liguori195325a2009-10-30 12:42:29 -05001921 char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
aliguori3023f332009-01-16 19:04:14 +00001922 DisplayState *ds;
aliguori7d957bd2009-01-15 22:14:11 +00001923 DisplayChangeListener *dcl;
bellard46d47672004-11-16 01:45:27 +00001924 int cyls, heads, secs, translation;
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02001925 QemuOpts *hda_opts = NULL, *opts;
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02001926 QemuOptsList *olist;
bellardcd6f1162004-05-13 22:02:20 +00001927 int optind;
Anthony Liguori6530a972010-01-22 09:18:06 -06001928 const char *optarg;
bellardd63d3072004-10-03 13:29:03 +00001929 const char *loadvm = NULL;
bellardcc1daa42005-06-05 14:49:17 +00001930 QEMUMachine *machine;
j_mayer94fc95c2007-03-05 19:44:02 +00001931 const char *cpu_model;
bellard26a5f132008-05-28 12:30:31 +00001932 int tb_size;
ths93815bc2007-03-19 15:58:31 +00001933 const char *pid_file = NULL;
aliguori5bb79102008-10-13 03:12:02 +00001934 const char *incoming = NULL;
Anthony Liguori993fbfd2009-05-21 16:54:00 -05001935 int show_vnc_port = 0;
Anthony Liguori292444c2010-01-21 10:57:58 -06001936 int defconfig = 1;
bellard0bd48852005-11-11 00:00:47 +00001937
Prerna Saxenaab6540d2010-08-09 11:48:32 +01001938#ifdef CONFIG_SIMPLE_TRACE
1939 const char *trace_file = NULL;
1940#endif
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02001941 atexit(qemu_run_exit_notifiers);
Markus Armbruster65abca02010-02-24 14:37:14 +01001942 error_set_progname(argv[0]);
1943
Jan Kiszka68752042009-09-15 13:36:04 +02001944 init_clocks();
1945
malc902b3d52008-12-10 19:18:40 +00001946 qemu_cache_utils_init(envp);
1947
Blue Swirl72cf2d42009-09-12 07:36:22 +00001948 QLIST_INIT (&vm_change_state_head);
Jes Sorensenfe98ac12010-06-10 11:42:21 +02001949 os_setup_early_signal_handling();
bellardbe995c22006-06-25 16:25:21 +00001950
Anthony Liguorif80f9ec2009-05-20 18:38:09 -05001951 module_call_init(MODULE_INIT_MACHINE);
Anthony Liguori0c257432009-05-21 20:41:01 -05001952 machine = find_default_machine();
j_mayer94fc95c2007-03-05 19:44:02 +00001953 cpu_model = NULL;
bellardfc01f7e2003-06-30 10:03:06 +00001954 initrd_filename = NULL;
aurel324fc5d072008-04-27 21:39:40 +00001955 ram_size = 0;
bellard33e39632003-07-06 17:15:21 +00001956 snapshot = 0;
bellarda20dd502003-09-30 21:07:02 +00001957 kernel_filename = NULL;
1958 kernel_cmdline = "";
bellardc4b1fcc2004-03-14 21:44:30 +00001959 cyls = heads = secs = 0;
bellard46d47672004-11-16 01:45:27 +00001960 translation = BIOS_ATA_TRANSLATION_AUTO;
bellardc4b1fcc2004-03-14 21:44:30 +00001961
aliguori268a3622009-04-21 22:30:27 +00001962 for (i = 0; i < MAX_NODES; i++) {
1963 node_mem[i] = 0;
1964 node_cpumask[i] = 0;
1965 }
1966
aliguori268a3622009-04-21 22:30:27 +00001967 nb_numa_nodes = 0;
bellard7c9d8e02005-11-15 22:16:05 +00001968 nb_nics = 0;
ths3b46e622007-09-17 08:09:54 +00001969
bellard26a5f132008-05-28 12:30:31 +00001970 tb_size = 0;
blueswir141bd6392008-10-05 09:56:21 +00001971 autostart= 1;
1972
Anthony Liguori292444c2010-01-21 10:57:58 -06001973 /* first pass of option parsing */
1974 optind = 1;
1975 while (optind < argc) {
1976 if (argv[optind][0] != '-') {
1977 /* disk image */
Anthony Liguori28e68d62010-01-27 10:46:00 -06001978 optind++;
Anthony Liguori292444c2010-01-21 10:57:58 -06001979 continue;
1980 } else {
1981 const QEMUOption *popt;
1982
1983 popt = lookup_opt(argc, argv, &optarg, &optind);
1984 switch (popt->index) {
1985 case QEMU_OPTION_nodefconfig:
1986 defconfig=0;
1987 break;
1988 }
1989 }
1990 }
1991
1992 if (defconfig) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01001993 int ret;
Markus Armbrustercf5a65a2010-02-18 19:48:33 +01001994
Kevin Wolfdcfb0932010-03-05 17:25:55 +01001995 ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
Kevin Wolf019e78b2010-05-17 10:36:47 +02001996 if (ret < 0 && ret != -ENOENT) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01001997 exit(1);
Anthony Liguori292444c2010-01-21 10:57:58 -06001998 }
1999
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002000 ret = qemu_read_config_file(arch_config_name);
Kevin Wolf019e78b2010-05-17 10:36:47 +02002001 if (ret < 0 && ret != -ENOENT) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002002 exit(1);
Anthony Liguori292444c2010-01-21 10:57:58 -06002003 }
2004 }
Blue Swirlde06f8d2010-03-29 19:23:50 +00002005 cpudef_init();
Anthony Liguori292444c2010-01-21 10:57:58 -06002006
2007 /* second pass of option parsing */
bellardcd6f1162004-05-13 22:02:20 +00002008 optind = 1;
bellard0824d6f2003-06-24 13:42:40 +00002009 for(;;) {
bellardcd6f1162004-05-13 22:02:20 +00002010 if (optind >= argc)
bellard0824d6f2003-06-24 13:42:40 +00002011 break;
Anthony Liguori6530a972010-01-22 09:18:06 -06002012 if (argv[optind][0] != '-') {
Markus Armbruster2292dda2011-01-28 11:21:41 +01002013 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
bellardcd6f1162004-05-13 22:02:20 +00002014 } else {
2015 const QEMUOption *popt;
2016
Anthony Liguori6530a972010-01-22 09:18:06 -06002017 popt = lookup_opt(argc, argv, &optarg, &optind);
Blue Swirlad960902010-03-29 19:23:52 +00002018 if (!(popt->arch_mask & arch_type)) {
2019 printf("Option %s not supported for this target\n", popt->name);
2020 exit(1);
2021 }
bellardcd6f1162004-05-13 22:02:20 +00002022 switch(popt->index) {
bellardcc1daa42005-06-05 14:49:17 +00002023 case QEMU_OPTION_M:
2024 machine = find_machine(optarg);
2025 if (!machine) {
2026 QEMUMachine *m;
2027 printf("Supported machines are:\n");
2028 for(m = first_machine; m != NULL; m = m->next) {
Mark McLoughlin3f6599e2009-07-22 10:02:50 +01002029 if (m->alias)
2030 printf("%-10s %s (alias of %s)\n",
2031 m->alias, m->desc, m->name);
bellardcc1daa42005-06-05 14:49:17 +00002032 printf("%-10s %s%s\n",
ths5fafdf22007-09-16 21:08:06 +00002033 m->name, m->desc,
Anthony Liguori0c257432009-05-21 20:41:01 -05002034 m->is_default ? " (default)" : "");
bellardcc1daa42005-06-05 14:49:17 +00002035 }
ths15f82202007-06-29 23:26:08 +00002036 exit(*optarg != '?');
bellardcc1daa42005-06-05 14:49:17 +00002037 }
2038 break;
j_mayer94fc95c2007-03-05 19:44:02 +00002039 case QEMU_OPTION_cpu:
2040 /* hw initialization will check this */
ths15f82202007-06-29 23:26:08 +00002041 if (*optarg == '?') {
Blue Swirl262353c2010-05-04 19:55:35 +00002042 list_cpus(stdout, &fprintf, optarg);
ths15f82202007-06-29 23:26:08 +00002043 exit(0);
j_mayer94fc95c2007-03-05 19:44:02 +00002044 } else {
2045 cpu_model = optarg;
2046 }
2047 break;
bellardcd6f1162004-05-13 22:02:20 +00002048 case QEMU_OPTION_initrd:
bellardfc01f7e2003-06-30 10:03:06 +00002049 initrd_filename = optarg;
2050 break;
bellardcd6f1162004-05-13 22:02:20 +00002051 case QEMU_OPTION_hda:
Markus Armbruster5645b0f2011-01-31 11:50:09 +01002052 {
2053 char buf[256];
2054 if (cyls == 0)
2055 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2056 else
2057 snprintf(buf, sizeof(buf),
2058 "%s,cyls=%d,heads=%d,secs=%d%s",
2059 HD_OPTS , cyls, heads, secs,
2060 translation == BIOS_ATA_TRANSLATION_LBA ?
thse4bcb142007-12-02 04:51:10 +00002061 ",trans=lba" :
Markus Armbruster5645b0f2011-01-31 11:50:09 +01002062 translation == BIOS_ATA_TRANSLATION_NONE ?
thse4bcb142007-12-02 04:51:10 +00002063 ",trans=none" : "");
Markus Armbruster5645b0f2011-01-31 11:50:09 +01002064 drive_add(IF_DEFAULT, 0, optarg, buf);
2065 break;
2066 }
bellardcd6f1162004-05-13 22:02:20 +00002067 case QEMU_OPTION_hdb:
bellardcc1daa42005-06-05 14:49:17 +00002068 case QEMU_OPTION_hdc:
2069 case QEMU_OPTION_hdd:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002070 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2071 HD_OPTS);
bellardfc01f7e2003-06-30 10:03:06 +00002072 break;
thse4bcb142007-12-02 04:51:10 +00002073 case QEMU_OPTION_drive:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002074 drive_def(optarg);
thse4bcb142007-12-02 04:51:10 +00002075 break;
Gerd Hoffmannd058fe02009-07-31 12:25:36 +02002076 case QEMU_OPTION_set:
2077 if (qemu_set_option(optarg) != 0)
2078 exit(1);
2079 break;
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01002080 case QEMU_OPTION_global:
2081 if (qemu_global_option(optarg) != 0)
2082 exit(1);
2083 break;
balrog3e3d5812007-04-30 02:09:25 +00002084 case QEMU_OPTION_mtdblock:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002085 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
balrog3e3d5812007-04-30 02:09:25 +00002086 break;
pbrooka1bb27b2007-04-06 16:49:48 +00002087 case QEMU_OPTION_sd:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002088 drive_add(IF_SD, 0, optarg, SD_OPTS);
pbrooka1bb27b2007-04-06 16:49:48 +00002089 break;
j_mayer86f55662007-04-24 06:52:59 +00002090 case QEMU_OPTION_pflash:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002091 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
j_mayer86f55662007-04-24 06:52:59 +00002092 break;
bellardcd6f1162004-05-13 22:02:20 +00002093 case QEMU_OPTION_snapshot:
bellard33e39632003-07-06 17:15:21 +00002094 snapshot = 1;
2095 break;
bellardcd6f1162004-05-13 22:02:20 +00002096 case QEMU_OPTION_hdachs:
bellard330d0412003-07-26 18:11:40 +00002097 {
bellard330d0412003-07-26 18:11:40 +00002098 const char *p;
2099 p = optarg;
2100 cyls = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002101 if (cyls < 1 || cyls > 16383)
2102 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00002103 if (*p != ',')
2104 goto chs_fail;
2105 p++;
2106 heads = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002107 if (heads < 1 || heads > 16)
2108 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00002109 if (*p != ',')
2110 goto chs_fail;
2111 p++;
2112 secs = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002113 if (secs < 1 || secs > 63)
2114 goto chs_fail;
2115 if (*p == ',') {
2116 p++;
2117 if (!strcmp(p, "none"))
2118 translation = BIOS_ATA_TRANSLATION_NONE;
2119 else if (!strcmp(p, "lba"))
2120 translation = BIOS_ATA_TRANSLATION_LBA;
2121 else if (!strcmp(p, "auto"))
2122 translation = BIOS_ATA_TRANSLATION_AUTO;
2123 else
2124 goto chs_fail;
2125 } else if (*p != '\0') {
bellardc4b1fcc2004-03-14 21:44:30 +00002126 chs_fail:
bellard46d47672004-11-16 01:45:27 +00002127 fprintf(stderr, "qemu: invalid physical CHS format\n");
2128 exit(1);
bellardc4b1fcc2004-03-14 21:44:30 +00002129 }
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02002130 if (hda_opts != NULL) {
2131 char num[16];
2132 snprintf(num, sizeof(num), "%d", cyls);
2133 qemu_opt_set(hda_opts, "cyls", num);
2134 snprintf(num, sizeof(num), "%d", heads);
2135 qemu_opt_set(hda_opts, "heads", num);
2136 snprintf(num, sizeof(num), "%d", secs);
2137 qemu_opt_set(hda_opts, "secs", num);
2138 if (translation == BIOS_ATA_TRANSLATION_LBA)
2139 qemu_opt_set(hda_opts, "trans", "lba");
2140 if (translation == BIOS_ATA_TRANSLATION_NONE)
2141 qemu_opt_set(hda_opts, "trans", "none");
2142 }
bellard330d0412003-07-26 18:11:40 +00002143 }
2144 break;
aliguori268a3622009-04-21 22:30:27 +00002145 case QEMU_OPTION_numa:
2146 if (nb_numa_nodes >= MAX_NODES) {
2147 fprintf(stderr, "qemu: too many NUMA nodes\n");
2148 exit(1);
2149 }
2150 numa_add(optarg);
2151 break;
bellardcd6f1162004-05-13 22:02:20 +00002152 case QEMU_OPTION_nographic:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002153 display_type = DT_NOGRAPHIC;
bellarda20dd502003-09-30 21:07:02 +00002154 break;
balrog4d3b6f62008-02-10 16:33:14 +00002155#ifdef CONFIG_CURSES
2156 case QEMU_OPTION_curses:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002157 display_type = DT_CURSES;
balrog4d3b6f62008-02-10 16:33:14 +00002158 break;
2159#endif
balroga171fe32007-04-30 01:48:07 +00002160 case QEMU_OPTION_portrait:
2161 graphic_rotate = 1;
2162 break;
bellardcd6f1162004-05-13 22:02:20 +00002163 case QEMU_OPTION_kernel:
bellarda20dd502003-09-30 21:07:02 +00002164 kernel_filename = optarg;
2165 break;
bellardcd6f1162004-05-13 22:02:20 +00002166 case QEMU_OPTION_append:
bellarda20dd502003-09-30 21:07:02 +00002167 kernel_cmdline = optarg;
bellard313aa562003-08-10 21:52:11 +00002168 break;
bellardcd6f1162004-05-13 22:02:20 +00002169 case QEMU_OPTION_cdrom:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002170 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
bellard36b486b2003-11-11 13:36:08 +00002171 break;
bellardcd6f1162004-05-13 22:02:20 +00002172 case QEMU_OPTION_boot:
j_mayer28c5af52007-11-11 01:50:45 +00002173 {
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002174 static const char * const params[] = {
Jan Kiszka95387492009-07-02 00:19:02 +02002175 "order", "once", "menu", NULL
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002176 };
2177 char buf[sizeof(boot_devices)];
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002178 char *standard_boot_devices;
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002179 int legacy = 0;
2180
2181 if (!strchr(optarg, '=')) {
2182 legacy = 1;
2183 pstrcpy(buf, sizeof(buf), optarg);
2184 } else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
2185 fprintf(stderr,
2186 "qemu: unknown boot parameter '%s' in '%s'\n",
2187 buf, optarg);
2188 exit(1);
2189 }
2190
2191 if (legacy ||
2192 get_param_value(buf, sizeof(buf), "order", optarg)) {
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -03002193 validate_bootdevices(buf);
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002194 pstrcpy(boot_devices, sizeof(boot_devices), buf);
j_mayer28c5af52007-11-11 01:50:45 +00002195 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002196 if (!legacy) {
2197 if (get_param_value(buf, sizeof(buf),
2198 "once", optarg)) {
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -03002199 validate_bootdevices(buf);
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002200 standard_boot_devices = qemu_strdup(boot_devices);
2201 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2202 qemu_register_reset(restore_boot_devices,
2203 standard_boot_devices);
2204 }
Jan Kiszka95387492009-07-02 00:19:02 +02002205 if (get_param_value(buf, sizeof(buf),
2206 "menu", optarg)) {
2207 if (!strcmp(buf, "on")) {
2208 boot_menu = 1;
2209 } else if (!strcmp(buf, "off")) {
2210 boot_menu = 0;
2211 } else {
2212 fprintf(stderr,
2213 "qemu: invalid option value '%s'\n",
2214 buf);
2215 exit(1);
2216 }
2217 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002218 }
bellard36b486b2003-11-11 13:36:08 +00002219 }
2220 break;
bellardcd6f1162004-05-13 22:02:20 +00002221 case QEMU_OPTION_fda:
bellardcd6f1162004-05-13 22:02:20 +00002222 case QEMU_OPTION_fdb:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002223 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2224 optarg, FD_OPTS);
bellardc45886d2004-01-05 00:02:06 +00002225 break;
bellard52ca8d62006-06-14 16:03:05 +00002226 case QEMU_OPTION_no_fd_bootchk:
2227 fd_bootchk = 0;
2228 break;
Mark McLoughlina1ea4582009-10-08 19:58:26 +01002229 case QEMU_OPTION_netdev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002230 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
Mark McLoughlina1ea4582009-10-08 19:58:26 +01002231 exit(1);
2232 }
2233 break;
bellard7c9d8e02005-11-15 22:16:05 +00002234 case QEMU_OPTION_net:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002235 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
bellardc4b1fcc2004-03-14 21:44:30 +00002236 exit(1);
2237 }
bellard702c6512004-04-02 21:21:32 +00002238 break;
bellardc7f74642004-08-24 21:57:12 +00002239#ifdef CONFIG_SLIRP
2240 case QEMU_OPTION_tftp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02002241 legacy_tftp_prefix = optarg;
bellard9bf05442004-08-25 22:12:49 +00002242 break;
ths47d5d012007-02-20 00:05:08 +00002243 case QEMU_OPTION_bootp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02002244 legacy_bootp_filename = optarg;
ths47d5d012007-02-20 00:05:08 +00002245 break;
bellard9bf05442004-08-25 22:12:49 +00002246 case QEMU_OPTION_redir:
Markus Armbruster07527062009-10-06 12:16:57 +01002247 if (net_slirp_redir(optarg) < 0)
2248 exit(1);
bellard9bf05442004-08-25 22:12:49 +00002249 break;
bellardc7f74642004-08-24 21:57:12 +00002250#endif
balrogdc72ac12008-11-09 00:04:26 +00002251 case QEMU_OPTION_bt:
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002252 add_device_config(DEV_BT, optarg);
balrogdc72ac12008-11-09 00:04:26 +00002253 break;
bellard1d14ffa2005-10-30 18:58:22 +00002254 case QEMU_OPTION_audio_help:
Blue Swirlad960902010-03-29 19:23:52 +00002255 if (!(audio_available())) {
2256 printf("Option %s not supported for this target\n", popt->name);
2257 exit(1);
2258 }
bellard1d14ffa2005-10-30 18:58:22 +00002259 AUD_help ();
2260 exit (0);
2261 break;
2262 case QEMU_OPTION_soundhw:
Blue Swirlad960902010-03-29 19:23:52 +00002263 if (!(audio_available())) {
2264 printf("Option %s not supported for this target\n", popt->name);
2265 exit(1);
2266 }
bellard1d14ffa2005-10-30 18:58:22 +00002267 select_soundhw (optarg);
2268 break;
bellardcd6f1162004-05-13 22:02:20 +00002269 case QEMU_OPTION_h:
ths15f82202007-06-29 23:26:08 +00002270 help(0);
bellardcd6f1162004-05-13 22:02:20 +00002271 break;
pbrook9bd7e6d2009-04-07 22:58:45 +00002272 case QEMU_OPTION_version:
2273 version();
2274 exit(0);
2275 break;
aurel3200f82b82008-04-27 21:12:55 +00002276 case QEMU_OPTION_m: {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +01002277 int64_t value;
aurel3200f82b82008-04-27 21:12:55 +00002278
Jes Sorensen9f9b17a2010-10-21 17:15:46 +02002279 value = strtosz(optarg, NULL);
2280 if (value < 0) {
aurel3200f82b82008-04-27 21:12:55 +00002281 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
bellardcd6f1162004-05-13 22:02:20 +00002282 exit(1);
2283 }
aurel3200f82b82008-04-27 21:12:55 +00002284
2285 /* On 32-bit hosts, QEMU is limited by virtual address space */
Anthony Liguori4a1418e2009-08-10 17:07:24 -05002286 if (value > (2047 << 20) && HOST_LONG_BITS == 32) {
aurel3200f82b82008-04-27 21:12:55 +00002287 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
2288 exit(1);
2289 }
Anthony Liguoric227f092009-10-01 16:12:16 -05002290 if (value != (uint64_t)(ram_addr_t)value) {
aurel3200f82b82008-04-27 21:12:55 +00002291 fprintf(stderr, "qemu: ram size too large\n");
2292 exit(1);
2293 }
2294 ram_size = value;
bellardcd6f1162004-05-13 22:02:20 +00002295 break;
aurel3200f82b82008-04-27 21:12:55 +00002296 }
Marcelo Tosattic9027602010-03-01 20:25:08 -03002297 case QEMU_OPTION_mempath:
2298 mem_path = optarg;
2299 break;
2300#ifdef MAP_POPULATE
2301 case QEMU_OPTION_mem_prealloc:
2302 mem_prealloc = 1;
2303 break;
2304#endif
bellardcd6f1162004-05-13 22:02:20 +00002305 case QEMU_OPTION_d:
Blue Swirlde06f8d2010-03-29 19:23:50 +00002306 set_cpu_log(optarg);
bellardcd6f1162004-05-13 22:02:20 +00002307 break;
bellardcd6f1162004-05-13 22:02:20 +00002308 case QEMU_OPTION_s:
aliguori59030a82009-04-05 18:43:41 +00002309 gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT;
bellardcd6f1162004-05-13 22:02:20 +00002310 break;
aliguori59030a82009-04-05 18:43:41 +00002311 case QEMU_OPTION_gdb:
2312 gdbstub_dev = optarg;
bellardcd6f1162004-05-13 22:02:20 +00002313 break;
bellardcd6f1162004-05-13 22:02:20 +00002314 case QEMU_OPTION_L:
Paul Brook5cea8592009-05-30 00:52:44 +01002315 data_dir = optarg;
bellardcd6f1162004-05-13 22:02:20 +00002316 break;
j_mayer1192dad2007-10-05 13:08:35 +00002317 case QEMU_OPTION_bios:
2318 bios_name = optarg;
2319 break;
aurel321b530a62009-04-05 20:08:59 +00002320 case QEMU_OPTION_singlestep:
2321 singlestep = 1;
2322 break;
bellardcd6f1162004-05-13 22:02:20 +00002323 case QEMU_OPTION_S:
pbrook3c07f8e2007-01-21 16:47:01 +00002324 autostart = 0;
bellardcd6f1162004-05-13 22:02:20 +00002325 break;
bellard3d11d0e2004-12-12 16:56:30 +00002326 case QEMU_OPTION_k:
2327 keyboard_layout = optarg;
2328 break;
bellardee22c2f2004-06-03 12:49:50 +00002329 case QEMU_OPTION_localtime:
2330 rtc_utc = 0;
2331 break;
malc3893c122008-09-28 00:42:05 +00002332 case QEMU_OPTION_vga:
2333 select_vgahw (optarg);
bellard1bfe8562004-07-08 21:17:50 +00002334 break;
bellarde9b137c2004-06-21 16:46:10 +00002335 case QEMU_OPTION_g:
2336 {
2337 const char *p;
2338 int w, h, depth;
2339 p = optarg;
2340 w = strtol(p, (char **)&p, 10);
2341 if (w <= 0) {
2342 graphic_error:
2343 fprintf(stderr, "qemu: invalid resolution or depth\n");
2344 exit(1);
2345 }
2346 if (*p != 'x')
2347 goto graphic_error;
2348 p++;
2349 h = strtol(p, (char **)&p, 10);
2350 if (h <= 0)
2351 goto graphic_error;
2352 if (*p == 'x') {
2353 p++;
2354 depth = strtol(p, (char **)&p, 10);
ths5fafdf22007-09-16 21:08:06 +00002355 if (depth != 8 && depth != 15 && depth != 16 &&
bellarde9b137c2004-06-21 16:46:10 +00002356 depth != 24 && depth != 32)
2357 goto graphic_error;
2358 } else if (*p == '\0') {
2359 depth = graphic_depth;
2360 } else {
2361 goto graphic_error;
2362 }
ths3b46e622007-09-17 08:09:54 +00002363
bellarde9b137c2004-06-21 16:46:10 +00002364 graphic_width = w;
2365 graphic_height = h;
2366 graphic_depth = depth;
2367 }
2368 break;
ths20d8a3e2007-02-18 17:04:49 +00002369 case QEMU_OPTION_echr:
2370 {
2371 char *r;
2372 term_escape_char = strtol(optarg, &r, 0);
2373 if (r == optarg)
2374 printf("Bad argument to echr\n");
2375 break;
2376 }
bellard82c643f2004-07-14 17:28:13 +00002377 case QEMU_OPTION_monitor:
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002378 monitor_parse(optarg, "readline");
2379 default_monitor = 0;
2380 break;
2381 case QEMU_OPTION_qmp:
2382 monitor_parse(optarg, "control");
Anthony Liguori2d114dc2010-03-21 14:14:38 -05002383 default_monitor = 0;
bellard82c643f2004-07-14 17:28:13 +00002384 break;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002385 case QEMU_OPTION_mon:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002386 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002387 if (!opts) {
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002388 exit(1);
2389 }
Anthony Liguori2d114dc2010-03-21 14:14:38 -05002390 default_monitor = 0;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002391 break;
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002392 case QEMU_OPTION_chardev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002393 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002394 if (!opts) {
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002395 exit(1);
2396 }
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002397 break;
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302398 case QEMU_OPTION_fsdev:
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002399 olist = qemu_find_opts("fsdev");
2400 if (!olist) {
2401 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
2402 exit(1);
2403 }
2404 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302405 if (!opts) {
2406 fprintf(stderr, "parse error: %s\n", optarg);
2407 exit(1);
2408 }
2409 break;
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302410 case QEMU_OPTION_virtfs: {
2411 char *arg_fsdev = NULL;
2412 char *arg_9p = NULL;
2413 int len = 0;
2414
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002415 olist = qemu_find_opts("virtfs");
2416 if (!olist) {
2417 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
2418 exit(1);
2419 }
2420 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302421 if (!opts) {
2422 fprintf(stderr, "parse error: %s\n", optarg);
2423 exit(1);
2424 }
2425
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07002426 if (qemu_opt_get(opts, "fstype") == NULL ||
2427 qemu_opt_get(opts, "mount_tag") == NULL ||
2428 qemu_opt_get(opts, "path") == NULL ||
2429 qemu_opt_get(opts, "security_model") == NULL) {
2430 fprintf(stderr, "Usage: -virtfs fstype,path=/share_path/,"
Aneesh Kumar K.V12848bf2010-09-02 11:09:07 +05302431 "security_model=[mapped|passthrough|none],"
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07002432 "mnt_tag=tag.\n");
2433 exit(1);
2434 }
2435
2436 len = strlen(",id=,path=,security_model=");
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302437 len += strlen(qemu_opt_get(opts, "fstype"));
2438 len += strlen(qemu_opt_get(opts, "mount_tag"));
2439 len += strlen(qemu_opt_get(opts, "path"));
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07002440 len += strlen(qemu_opt_get(opts, "security_model"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302441 arg_fsdev = qemu_malloc((len + 1) * sizeof(*arg_fsdev));
2442
Aneesh Kumar K.Vc93031e2010-09-02 21:47:59 +05302443 snprintf(arg_fsdev, (len + 1) * sizeof(*arg_fsdev),
Blue Swirlcb93bbd2010-08-31 20:16:59 +00002444 "%s,id=%s,path=%s,security_model=%s",
2445 qemu_opt_get(opts, "fstype"),
2446 qemu_opt_get(opts, "mount_tag"),
2447 qemu_opt_get(opts, "path"),
2448 qemu_opt_get(opts, "security_model"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302449
2450 len = strlen("virtio-9p-pci,fsdev=,mount_tag=");
2451 len += 2*strlen(qemu_opt_get(opts, "mount_tag"));
2452 arg_9p = qemu_malloc((len + 1) * sizeof(*arg_9p));
2453
Aneesh Kumar K.Vc93031e2010-09-02 21:47:59 +05302454 snprintf(arg_9p, (len + 1) * sizeof(*arg_9p),
Blue Swirlcb93bbd2010-08-31 20:16:59 +00002455 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2456 qemu_opt_get(opts, "mount_tag"),
2457 qemu_opt_get(opts, "mount_tag"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302458
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002459 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev, 1)) {
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302460 fprintf(stderr, "parse error [fsdev]: %s\n", optarg);
2461 exit(1);
2462 }
2463
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002464 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p, 1)) {
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302465 fprintf(stderr, "parse error [device]: %s\n", optarg);
2466 exit(1);
2467 }
2468
2469 qemu_free(arg_fsdev);
2470 qemu_free(arg_9p);
2471 break;
2472 }
bellard82c643f2004-07-14 17:28:13 +00002473 case QEMU_OPTION_serial:
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002474 add_device_config(DEV_SERIAL, optarg);
2475 default_serial = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01002476 if (strncmp(optarg, "mon:", 4) == 0) {
2477 default_monitor = 0;
2478 }
bellard82c643f2004-07-14 17:28:13 +00002479 break;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01002480 case QEMU_OPTION_watchdog:
Markus Armbruster09aaa162009-08-21 10:31:34 +02002481 if (watchdog) {
2482 fprintf(stderr,
2483 "qemu: only one watchdog option may be given\n");
2484 return 1;
2485 }
2486 watchdog = optarg;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01002487 break;
2488 case QEMU_OPTION_watchdog_action:
2489 if (select_watchdog_action(optarg) == -1) {
2490 fprintf(stderr, "Unknown -watchdog-action parameter\n");
2491 exit(1);
2492 }
2493 break;
aliguori51ecf132009-01-15 20:06:40 +00002494 case QEMU_OPTION_virtiocon:
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002495 add_device_config(DEV_VIRTCON, optarg);
2496 default_virtcon = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01002497 if (strncmp(optarg, "mon:", 4) == 0) {
2498 default_monitor = 0;
2499 }
aliguori51ecf132009-01-15 20:06:40 +00002500 break;
bellard6508fe52005-01-15 12:02:56 +00002501 case QEMU_OPTION_parallel:
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002502 add_device_config(DEV_PARALLEL, optarg);
2503 default_parallel = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01002504 if (strncmp(optarg, "mon:", 4) == 0) {
2505 default_monitor = 0;
2506 }
bellard6508fe52005-01-15 12:02:56 +00002507 break;
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002508 case QEMU_OPTION_debugcon:
2509 add_device_config(DEV_DEBUGCON, optarg);
2510 break;
bellardd63d3072004-10-03 13:29:03 +00002511 case QEMU_OPTION_loadvm:
2512 loadvm = optarg;
2513 break;
2514 case QEMU_OPTION_full_screen:
2515 full_screen = 1;
2516 break;
ths667acca2006-12-11 02:08:05 +00002517#ifdef CONFIG_SDL
ths43523e92007-02-18 18:19:32 +00002518 case QEMU_OPTION_no_frame:
2519 no_frame = 1;
2520 break;
ths3780e192007-06-21 21:08:02 +00002521 case QEMU_OPTION_alt_grab:
2522 alt_grab = 1;
2523 break;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -05002524 case QEMU_OPTION_ctrl_grab:
2525 ctrl_grab = 1;
2526 break;
ths667acca2006-12-11 02:08:05 +00002527 case QEMU_OPTION_no_quit:
2528 no_quit = 1;
2529 break;
aliguori7d957bd2009-01-15 22:14:11 +00002530 case QEMU_OPTION_sdl:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002531 display_type = DT_SDL;
aliguori7d957bd2009-01-15 22:14:11 +00002532 break;
ths667acca2006-12-11 02:08:05 +00002533#endif
bellardf7cce892004-12-08 22:21:25 +00002534 case QEMU_OPTION_pidfile:
ths93815bc2007-03-19 15:58:31 +00002535 pid_file = optarg;
bellardf7cce892004-12-08 22:21:25 +00002536 break;
bellarda09db212005-04-30 16:10:35 +00002537 case QEMU_OPTION_win2k_hack:
2538 win2k_install_hack = 1;
2539 break;
aliguori73822ec2009-01-15 20:11:34 +00002540 case QEMU_OPTION_rtc_td_hack:
2541 rtc_td_hack = 1;
2542 break;
aliguori8a92ea22009-02-27 20:12:36 +00002543 case QEMU_OPTION_acpitable:
Blue Swirlde06f8d2010-03-29 19:23:50 +00002544 do_acpitable_option(optarg);
aliguori8a92ea22009-02-27 20:12:36 +00002545 break;
aliguorib6f6e3d2009-04-17 18:59:56 +00002546 case QEMU_OPTION_smbios:
Blue Swirlde06f8d2010-03-29 19:23:50 +00002547 do_smbios_option(optarg);
aliguorib6f6e3d2009-04-17 18:59:56 +00002548 break;
aliguori7ba1e612008-11-05 16:04:33 +00002549 case QEMU_OPTION_enable_kvm:
2550 kvm_allowed = 1;
aliguori7ba1e612008-11-05 16:04:33 +00002551 break;
bellardbb36d472005-11-05 14:22:28 +00002552 case QEMU_OPTION_usb:
2553 usb_enabled = 1;
2554 break;
bellarda594cfb2005-11-06 16:13:29 +00002555 case QEMU_OPTION_usbdevice:
2556 usb_enabled = 1;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002557 add_device_config(DEV_USB, optarg);
2558 break;
2559 case QEMU_OPTION_device:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002560 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02002561 exit(1);
2562 }
bellarda594cfb2005-11-06 16:13:29 +00002563 break;
bellard6a00d602005-11-21 23:25:50 +00002564 case QEMU_OPTION_smp:
Andre Przywaradc6b1c02009-08-19 15:42:40 +02002565 smp_parse(optarg);
aliguorib2097002008-10-07 20:39:39 +00002566 if (smp_cpus < 1) {
bellard6a00d602005-11-21 23:25:50 +00002567 fprintf(stderr, "Invalid number of CPUs\n");
2568 exit(1);
2569 }
Jes Sorensen6be68d72009-07-23 17:03:42 +02002570 if (max_cpus < smp_cpus) {
2571 fprintf(stderr, "maxcpus must be equal to or greater than "
2572 "smp\n");
2573 exit(1);
2574 }
2575 if (max_cpus > 255) {
2576 fprintf(stderr, "Unsupported number of maxcpus\n");
2577 exit(1);
2578 }
bellard6a00d602005-11-21 23:25:50 +00002579 break;
bellard24236862006-04-30 21:28:36 +00002580 case QEMU_OPTION_vnc:
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02002581 display_remote++;
ths73fc9742006-12-22 02:09:07 +00002582 vnc_display = optarg;
bellard24236862006-04-30 21:28:36 +00002583 break;
bellard6515b202006-05-03 22:02:44 +00002584 case QEMU_OPTION_no_acpi:
2585 acpi_enabled = 0;
2586 break;
aliguori16b29ae2008-12-17 23:28:44 +00002587 case QEMU_OPTION_no_hpet:
2588 no_hpet = 1;
2589 break;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02002590 case QEMU_OPTION_balloon:
2591 if (balloon_parse(optarg) < 0) {
2592 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
2593 exit(1);
2594 }
Eduardo Habkostdf97b922009-06-10 16:34:08 -03002595 break;
bellardd1beab82006-10-02 19:44:22 +00002596 case QEMU_OPTION_no_reboot:
2597 no_reboot = 1;
2598 break;
aurel32b2f76162008-04-11 21:35:52 +00002599 case QEMU_OPTION_no_shutdown:
2600 no_shutdown = 1;
2601 break;
balrog9467cd42007-05-01 01:34:14 +00002602 case QEMU_OPTION_show_cursor:
2603 cursor_hide = 0;
2604 break;
blueswir18fcb1b92008-09-18 18:29:08 +00002605 case QEMU_OPTION_uuid:
2606 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
2607 fprintf(stderr, "Fail to parse UUID string."
2608 " Wrong format.\n");
2609 exit(1);
2610 }
2611 break;
ths9ae02552007-01-05 17:39:04 +00002612 case QEMU_OPTION_option_rom:
2613 if (nb_option_roms >= MAX_OPTION_ROMS) {
2614 fprintf(stderr, "Too many option ROMs\n");
2615 exit(1);
2616 }
Gleb Natapov2e55e842010-12-08 13:35:07 +02002617 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
2618 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
2619 option_rom[nb_option_roms].bootindex =
2620 qemu_opt_get_number(opts, "bootindex", -1);
2621 if (!option_rom[nb_option_roms].name) {
2622 fprintf(stderr, "Option ROM file is not specified\n");
2623 exit(1);
2624 }
ths9ae02552007-01-05 17:39:04 +00002625 nb_option_roms++;
2626 break;
pbrook8e716212007-01-20 17:12:09 +00002627 case QEMU_OPTION_semihosting:
2628 semihosting_enabled = 1;
2629 break;
thsc35734b2007-03-19 15:17:08 +00002630 case QEMU_OPTION_name:
Andi Kleen18894652009-07-02 09:34:17 +02002631 qemu_name = qemu_strdup(optarg);
2632 {
2633 char *p = strchr(qemu_name, ',');
2634 if (p != NULL) {
2635 *p++ = 0;
2636 if (strncmp(p, "process=", 8)) {
Aurelien Jarno5697f6a2010-12-27 18:29:20 +01002637 fprintf(stderr, "Unknown subargument %s to -name\n", p);
Andi Kleen18894652009-07-02 09:34:17 +02002638 exit(1);
2639 }
2640 p += 8;
Jes Sorensence798cf2010-06-10 11:42:31 +02002641 os_set_proc_name(p);
Andi Kleen18894652009-07-02 09:34:17 +02002642 }
2643 }
thsc35734b2007-03-19 15:17:08 +00002644 break;
blueswir166508602007-05-01 14:16:52 +00002645 case QEMU_OPTION_prom_env:
2646 if (nb_prom_envs >= MAX_PROM_ENVS) {
2647 fprintf(stderr, "Too many prom variables\n");
2648 exit(1);
2649 }
2650 prom_envs[nb_prom_envs] = optarg;
2651 nb_prom_envs++;
2652 break;
balrog2b8f2d42007-07-27 22:08:46 +00002653 case QEMU_OPTION_old_param:
2654 old_param = 1;
ths05ebd532008-01-08 19:32:16 +00002655 break;
thsf3dcfad2007-08-24 01:26:02 +00002656 case QEMU_OPTION_clock:
2657 configure_alarms(optarg);
2658 break;
bellard7e0af5d02007-11-07 16:24:33 +00002659 case QEMU_OPTION_startdate:
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002660 configure_rtc_date_offset(optarg, 1);
2661 break;
2662 case QEMU_OPTION_rtc:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002663 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002664 if (!opts) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002665 exit(1);
bellard7e0af5d02007-11-07 16:24:33 +00002666 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002667 configure_rtc(opts);
bellard7e0af5d02007-11-07 16:24:33 +00002668 break;
bellard26a5f132008-05-28 12:30:31 +00002669 case QEMU_OPTION_tb_size:
2670 tb_size = strtol(optarg, NULL, 0);
2671 if (tb_size < 0)
2672 tb_size = 0;
2673 break;
pbrook2e70f6e2008-06-29 01:03:05 +00002674 case QEMU_OPTION_icount:
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01002675 icount_option = optarg;
pbrook2e70f6e2008-06-29 01:03:05 +00002676 break;
aliguori5bb79102008-10-13 03:12:02 +00002677 case QEMU_OPTION_incoming:
2678 incoming = optarg;
Amit Shah8e848652010-07-27 15:49:19 +05302679 incoming_expected = true;
aliguori5bb79102008-10-13 03:12:02 +00002680 break;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01002681 case QEMU_OPTION_nodefaults:
2682 default_serial = 0;
2683 default_parallel = 0;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002684 default_virtcon = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01002685 default_monitor = 0;
2686 default_vga = 0;
Gerd Hoffmanncb4522c2009-12-08 13:11:47 +01002687 default_net = 0;
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01002688 default_floppy = 0;
2689 default_cdrom = 0;
2690 default_sdcard = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01002691 break;
aliguorie37630c2009-04-22 15:19:10 +00002692 case QEMU_OPTION_xen_domid:
Blue Swirlad960902010-03-29 19:23:52 +00002693 if (!(xen_available())) {
2694 printf("Option %s not supported for this target\n", popt->name);
2695 exit(1);
2696 }
aliguorie37630c2009-04-22 15:19:10 +00002697 xen_domid = atoi(optarg);
2698 break;
2699 case QEMU_OPTION_xen_create:
Blue Swirlad960902010-03-29 19:23:52 +00002700 if (!(xen_available())) {
2701 printf("Option %s not supported for this target\n", popt->name);
2702 exit(1);
2703 }
aliguorie37630c2009-04-22 15:19:10 +00002704 xen_mode = XEN_CREATE;
2705 break;
2706 case QEMU_OPTION_xen_attach:
Blue Swirlad960902010-03-29 19:23:52 +00002707 if (!(xen_available())) {
2708 printf("Option %s not supported for this target\n", popt->name);
2709 exit(1);
2710 }
aliguorie37630c2009-04-22 15:19:10 +00002711 xen_mode = XEN_ATTACH;
2712 break;
Prerna Saxenaab6540d2010-08-09 11:48:32 +01002713#ifdef CONFIG_SIMPLE_TRACE
2714 case QEMU_OPTION_trace:
2715 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
2716 if (opts) {
2717 trace_file = qemu_opt_get(opts, "file");
2718 }
2719 break;
2720#endif
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002721 case QEMU_OPTION_readconfig:
2722 {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002723 int ret = qemu_read_config_file(optarg);
2724 if (ret < 0) {
2725 fprintf(stderr, "read config %s: %s\n", optarg,
2726 strerror(-ret));
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002727 exit(1);
2728 }
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002729 break;
2730 }
Gerd Hoffmann29b00402010-03-11 11:13:27 -03002731 case QEMU_OPTION_spice:
2732 olist = qemu_find_opts("spice");
2733 if (!olist) {
2734 fprintf(stderr, "spice is not supported by this qemu build.\n");
2735 exit(1);
2736 }
2737 opts = qemu_opts_parse(olist, optarg, 0);
2738 if (!opts) {
2739 fprintf(stderr, "parse error: %s\n", optarg);
2740 exit(1);
2741 }
2742 break;
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002743 case QEMU_OPTION_writeconfig:
2744 {
2745 FILE *fp;
2746 if (strcmp(optarg, "-") == 0) {
2747 fp = stdout;
2748 } else {
2749 fp = fopen(optarg, "w");
2750 if (fp == NULL) {
2751 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
2752 exit(1);
2753 }
2754 }
2755 qemu_config_write(fp);
2756 fclose(fp);
2757 break;
2758 }
Jes Sorensen59a52642010-06-10 11:42:25 +02002759 default:
2760 os_parse_cmd_args(popt->index, optarg);
bellardcd6f1162004-05-13 22:02:20 +00002761 }
bellard0824d6f2003-06-24 13:42:40 +00002762 }
2763 }
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002764 loc_set_none();
bellard330d0412003-07-26 18:11:40 +00002765
Paul Brook5cea8592009-05-30 00:52:44 +01002766 /* If no data_dir is specified then try to find it relative to the
2767 executable path. */
2768 if (!data_dir) {
Jes Sorensen61705402010-06-10 11:42:23 +02002769 data_dir = os_find_datadir(argv[0]);
Paul Brook5cea8592009-05-30 00:52:44 +01002770 }
2771 /* If all else fails use the install patch specified when building. */
2772 if (!data_dir) {
Paolo Bonzini1dabe052010-05-26 16:08:25 +02002773 data_dir = CONFIG_QEMU_DATADIR;
Paul Brook5cea8592009-05-30 00:52:44 +01002774 }
2775
Prerna Saxenaab6540d2010-08-09 11:48:32 +01002776#ifdef CONFIG_SIMPLE_TRACE
2777 /*
2778 * Set the trace file name, if specified.
2779 */
2780 st_set_trace_file(trace_file);
2781#endif
Jes Sorensen6be68d72009-07-23 17:03:42 +02002782 /*
2783 * Default to max_cpus = smp_cpus, in case the user doesn't
2784 * specify a max_cpus value.
2785 */
2786 if (!max_cpus)
2787 max_cpus = smp_cpus;
2788
balrog3d878ca2008-10-28 10:59:59 +00002789 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
aliguorib2097002008-10-07 20:39:39 +00002790 if (smp_cpus > machine->max_cpus) {
2791 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
2792 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
2793 machine->max_cpus);
2794 exit(1);
2795 }
2796
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002797 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
2798 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002799
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002800 if (machine->no_serial) {
2801 default_serial = 0;
2802 }
2803 if (machine->no_parallel) {
2804 default_parallel = 0;
2805 }
2806 if (!machine->use_virtcon) {
2807 default_virtcon = 0;
2808 }
2809 if (machine->no_vga) {
2810 default_vga = 0;
2811 }
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01002812 if (machine->no_floppy) {
2813 default_floppy = 0;
2814 }
2815 if (machine->no_cdrom) {
2816 default_cdrom = 0;
2817 }
2818 if (machine->no_sdcard) {
2819 default_sdcard = 0;
2820 }
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002821
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002822 if (display_type == DT_NOGRAPHIC) {
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002823 if (default_parallel)
2824 add_device_config(DEV_PARALLEL, "null");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002825 if (default_serial && default_monitor) {
2826 add_device_config(DEV_SERIAL, "mon:stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002827 } else if (default_virtcon && default_monitor) {
2828 add_device_config(DEV_VIRTCON, "mon:stdio");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002829 } else {
2830 if (default_serial)
2831 add_device_config(DEV_SERIAL, "stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002832 if (default_virtcon)
2833 add_device_config(DEV_VIRTCON, "stdio");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002834 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002835 monitor_parse("stdio", "readline");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002836 }
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002837 } else {
2838 if (default_serial)
2839 add_device_config(DEV_SERIAL, "vc:80Cx24C");
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002840 if (default_parallel)
2841 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
Gerd Hoffmannabdeed02009-12-08 13:11:43 +01002842 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002843 monitor_parse("vc:80Cx24C", "readline");
Alexander Graf38536da2009-12-17 13:06:08 +01002844 if (default_virtcon)
2845 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
aliguoribc0129d2008-08-01 15:12:34 +00002846 }
Gerd Hoffmann64465292009-12-08 13:11:45 +01002847 if (default_vga)
2848 vga_interface_type = VGA_CIRRUS;
aliguoribc0129d2008-08-01 15:12:34 +00002849
TeLeMana5829fd2010-04-15 12:37:55 +08002850 socket_init();
2851
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002852 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002853 exit(1);
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07002854#ifdef CONFIG_VIRTFS
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002855 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302856 exit(1);
2857 }
2858#endif
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002859
Jes Sorenseneb505be2010-06-10 11:42:28 +02002860 os_daemonize();
ths71e3ceb2006-12-22 02:11:31 +00002861
thsaa26bb22007-03-25 21:33:06 +00002862 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
Jes Sorenseneb505be2010-06-10 11:42:28 +02002863 os_pidfile_error();
ths93815bc2007-03-19 15:58:31 +00002864 exit(1);
2865 }
2866
Paolo Bonzini98c85732010-04-19 18:59:30 +00002867 if (kvm_allowed) {
2868 int ret = kvm_init(smp_cpus);
Marcelo Tosatti214910a2009-09-18 02:41:23 -03002869 if (ret < 0) {
Paolo Bonzini98c85732010-04-19 18:59:30 +00002870 if (!kvm_available()) {
2871 printf("KVM not supported for this target\n");
2872 } else {
2873 fprintf(stderr, "failed to initialize KVM: %s\n", strerror(-ret));
2874 }
Marcelo Tosatti214910a2009-09-18 02:41:23 -03002875 exit(1);
2876 }
2877 }
2878
aliguori3fcf7b62009-04-24 18:03:25 +00002879 if (qemu_init_main_loop()) {
2880 fprintf(stderr, "qemu_init_main_loop failed\n");
2881 exit(1);
2882 }
bellarda20dd502003-09-30 21:07:02 +00002883 linux_boot = (kernel_filename != NULL);
balrog6c41b272007-11-17 12:12:29 +00002884
thsf8d39c02008-07-03 10:01:15 +00002885 if (!linux_boot && *kernel_cmdline != '\0') {
2886 fprintf(stderr, "-append only allowed with -kernel option\n");
2887 exit(1);
2888 }
2889
2890 if (!linux_boot && initrd_filename != NULL) {
2891 fprintf(stderr, "-initrd only allowed with -kernel option\n");
2892 exit(1);
2893 }
2894
Jes Sorensen9156d762010-06-10 11:42:30 +02002895 os_set_line_buffering();
ths3b46e622007-09-17 08:09:54 +00002896
aliguori7183b4b2008-11-05 20:40:18 +00002897 if (init_timer_alarm() < 0) {
2898 fprintf(stderr, "could not initialize alarm timer\n");
2899 exit(1);
2900 }
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01002901 configure_icount(icount_option);
pbrook634fce92006-07-15 17:40:09 +00002902
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01002903 if (net_init_clients() < 0) {
2904 exit(1);
bellard702c6512004-04-02 21:21:32 +00002905 }
bellardf1510b22003-06-25 00:07:40 +00002906
balrogdc72ac12008-11-09 00:04:26 +00002907 /* init the bluetooth world */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002908 if (foreach_device_config(DEV_BT, bt_parse))
2909 exit(1);
balrogdc72ac12008-11-09 00:04:26 +00002910
bellard0824d6f2003-06-24 13:42:40 +00002911 /* init the memory */
pbrook94a6b542009-04-11 17:15:54 +00002912 if (ram_size == 0)
2913 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
balrog7fb4fdc2008-04-24 17:59:27 +00002914
bellard26a5f132008-05-28 12:30:31 +00002915 /* init the dynamic translator */
2916 cpu_exec_init_all(tb_size * 1024 * 1024);
2917
Markus Armbrustereb852012009-10-27 18:41:44 +01002918 bdrv_init_with_whitelist();
thse4bcb142007-12-02 04:51:10 +00002919
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +02002920 blk_mig_init();
2921
ths96d30e42007-01-07 20:42:14 +00002922 /* open the virtual block devices */
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02002923 if (snapshot)
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002924 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
2925 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02002926 exit(1);
balrog3e3d5812007-04-30 02:09:25 +00002927
Markus Armbruster4e5d9b52011-01-28 11:21:45 +01002928 default_drive(default_cdrom, snapshot, machine->use_scsi,
2929 IF_DEFAULT, 2, CDROM_OPTS);
2930 default_drive(default_floppy, snapshot, machine->use_scsi,
2931 IF_FLOPPY, 0, FD_OPTS);
2932 default_drive(default_sdcard, snapshot, machine->use_scsi,
2933 IF_SD, 0, SD_OPTS);
2934
Alex Williamson97ab12d2010-06-25 11:09:50 -06002935 register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL,
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +02002936 ram_load, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00002937
aliguori268a3622009-04-21 22:30:27 +00002938 if (nb_numa_nodes > 0) {
2939 int i;
2940
2941 if (nb_numa_nodes > smp_cpus) {
2942 nb_numa_nodes = smp_cpus;
2943 }
2944
2945 /* If no memory size if given for any node, assume the default case
2946 * and distribute the available memory equally across all nodes
2947 */
2948 for (i = 0; i < nb_numa_nodes; i++) {
2949 if (node_mem[i] != 0)
2950 break;
2951 }
2952 if (i == nb_numa_nodes) {
2953 uint64_t usedmem = 0;
2954
2955 /* On Linux, the each node's border has to be 8MB aligned,
2956 * the final node gets the rest.
2957 */
2958 for (i = 0; i < nb_numa_nodes - 1; i++) {
2959 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
2960 usedmem += node_mem[i];
2961 }
2962 node_mem[i] = ram_size - usedmem;
2963 }
2964
2965 for (i = 0; i < nb_numa_nodes; i++) {
2966 if (node_cpumask[i] != 0)
2967 break;
2968 }
2969 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2970 * must cope with this anyway, because there are BIOSes out there in
2971 * real machines which also use this scheme.
2972 */
2973 if (i == nb_numa_nodes) {
2974 for (i = 0; i < smp_cpus; i++) {
2975 node_cpumask[i % nb_numa_nodes] |= 1 << i;
2976 }
2977 }
2978 }
2979
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002980 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
Jan Kiszka157b9312010-04-06 16:55:53 +02002981 exit(1);
2982 }
2983
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002984 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
2985 exit(1);
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002986 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
2987 exit(1);
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002988 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
2989 exit(1);
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002990 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
2991 exit(1);
aliguori2796dae2009-01-16 20:23:27 +00002992
Paul Brookaae94602009-05-14 22:35:06 +01002993 module_call_init(MODULE_INIT_DEVICE);
2994
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002995 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0)
Markus Armbrusterff952ba2010-01-29 19:48:57 +01002996 exit(0);
2997
Markus Armbruster09aaa162009-08-21 10:31:34 +02002998 if (watchdog) {
2999 i = select_watchdog(watchdog);
3000 if (i > 0)
3001 exit (i == 1 ? 1 : 0);
3002 }
3003
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02003004 if (machine->compat_props) {
Gerd Hoffmann458fb672009-12-08 13:11:33 +01003005 qdev_prop_register_global_list(machine->compat_props);
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02003006 }
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01003007 qemu_add_globals();
3008
Paul Brookfbe1b592009-05-13 17:56:25 +01003009 machine->init(ram_size, boot_devices,
aliguori3023f332009-01-16 19:04:14 +00003010 kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
3011
Jan Kiszkaea375f92010-03-01 19:10:30 +01003012 cpu_synchronize_all_post_init();
aliguori268a3622009-04-21 22:30:27 +00003013
Juan Quintela67b3b712009-08-28 19:25:15 +02003014 /* must be after terminal init, SDL library changes signal handlers */
Jes Sorensen8d963e62010-06-10 11:42:22 +02003015 os_setup_signal_handling();
Juan Quintela67b3b712009-08-28 19:25:15 +02003016
Blue Swirl87d0a282010-03-27 18:24:45 +00003017 set_numa_modes();
aliguori268a3622009-04-21 22:30:27 +00003018
aliguori6f338c32009-02-11 15:21:54 +00003019 current_machine = machine;
3020
aliguori3023f332009-01-16 19:04:14 +00003021 /* init USB devices */
3022 if (usb_enabled) {
Markus Armbruster07527062009-10-06 12:16:57 +01003023 if (foreach_device_config(DEV_USB, usb_parse) < 0)
3024 exit(1);
aliguori3023f332009-01-16 19:04:14 +00003025 }
3026
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003027 /* init generic devices */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003028 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003029 exit(1);
3030
Markus Armbruster668680f2010-02-11 14:44:58 +01003031 net_check_clients();
3032
aliguori3023f332009-01-16 19:04:14 +00003033 /* just use the first displaystate for the moment */
Paolo Bonzinib473df62010-02-11 00:29:55 +01003034 ds = get_displaystate();
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003035
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003036 if (using_spice)
3037 display_remote++;
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003038 if (display_type == DT_DEFAULT && !display_remote) {
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003039#if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003040 display_type = DT_SDL;
3041#else
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003042 vnc_display = "localhost:0,to=99";
3043 show_vnc_port = 1;
3044#endif
3045 }
3046
3047
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003048 /* init local displays */
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003049 switch (display_type) {
3050 case DT_NOGRAPHIC:
3051 break;
3052#if defined(CONFIG_CURSES)
3053 case DT_CURSES:
3054 curses_display_init(ds, full_screen);
3055 break;
3056#endif
bellard5b0753e2005-03-01 21:37:28 +00003057#if defined(CONFIG_SDL)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003058 case DT_SDL:
3059 sdl_display_init(ds, full_screen, no_frame);
3060 break;
bellard5b0753e2005-03-01 21:37:28 +00003061#elif defined(CONFIG_COCOA)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003062 case DT_SDL:
3063 cocoa_display_init(ds, full_screen);
3064 break;
bellard313aa562003-08-10 21:52:11 +00003065#endif
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003066 default:
3067 break;
3068 }
3069
3070 /* init remote displays */
3071 if (vnc_display) {
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003072 vnc_display_init(ds);
3073 if (vnc_display_open(ds, vnc_display) < 0)
3074 exit(1);
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003075
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003076 if (show_vnc_port) {
3077 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003078 }
bellard313aa562003-08-10 21:52:11 +00003079 }
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003080#ifdef CONFIG_SPICE
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +02003081 if (using_spice && !qxl_enabled) {
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003082 qemu_spice_display_init(ds);
3083 }
3084#endif
aliguori5b08fc12008-08-21 20:08:03 +00003085
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003086 /* display setup */
3087 dpy_resize(ds);
aliguori3023f332009-01-16 19:04:14 +00003088 dcl = ds->listeners;
3089 while (dcl != NULL) {
3090 if (dcl->dpy_refresh != NULL) {
3091 ds->gui_timer = qemu_new_timer(rt_clock, gui_update, ds);
3092 qemu_mod_timer(ds->gui_timer, qemu_get_clock(rt_clock));
Isaku Yamahata0f2ad632010-05-27 14:38:47 +09003093 break;
ths20d8a3e2007-02-18 17:04:49 +00003094 }
aliguori3023f332009-01-16 19:04:14 +00003095 dcl = dcl->next;
bellard82c643f2004-07-14 17:28:13 +00003096 }
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003097 if (ds->gui_timer == NULL) {
blueswir19043b622009-01-21 19:28:13 +00003098 nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL);
3099 qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock));
3100 }
Paolo Bonzinib473df62010-02-11 00:29:55 +01003101 text_consoles_set_display(ds);
aliguori2796dae2009-01-16 20:23:27 +00003102
aliguori59030a82009-04-05 18:43:41 +00003103 if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) {
3104 fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n",
3105 gdbstub_dev);
3106 exit(1);
balrog45669e02007-07-02 13:20:17 +00003107 }
balrog45669e02007-07-02 13:20:17 +00003108
Gerd Hoffmann3418bd22009-09-25 21:42:41 +02003109 qdev_machine_creation_done();
3110
Gerd Hoffmann15ff7702009-12-14 16:07:35 +01003111 if (rom_load_all() != 0) {
3112 fprintf(stderr, "rom loading failed\n");
3113 exit(1);
3114 }
Gerd Hoffmann45a50b12009-10-01 16:42:33 +02003115
Isaku Yamahata80376c32010-12-20 14:33:35 +09003116 /* TODO: once all bus devices are qdevified, this should be done
3117 * when bus is created by qdev.c */
3118 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
Gleb Natapov4cab9462010-12-08 13:35:08 +02003119 qemu_run_machine_init_done_notifiers();
3120
Juan Quintela504c2942009-11-12 00:39:13 +01003121 qemu_system_reset();
Juan Quintela05f24012009-08-20 19:42:22 +02003122 if (loadvm) {
Markus Armbruster03cd4652010-02-17 16:24:10 +01003123 if (load_vmstate(loadvm) < 0) {
Juan Quintela05f24012009-08-20 19:42:22 +02003124 autostart = 0;
3125 }
3126 }
bellardd63d3072004-10-03 13:29:03 +00003127
Glauber Costa2bb8c102009-07-24 16:20:23 -04003128 if (incoming) {
Juan Quintela8ca5e802010-06-09 14:10:54 +02003129 int ret = qemu_start_incoming_migration(incoming);
3130 if (ret < 0) {
3131 fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n",
3132 incoming, ret);
3133 exit(ret);
3134 }
Avi Kivity6b99dad2009-08-09 14:39:20 +03003135 } else if (autostart) {
aliguoric0f4ce72009-03-05 23:01:01 +00003136 vm_start();
Avi Kivity6b99dad2009-08-09 14:39:20 +03003137 }
thsffd843b2006-12-21 19:46:43 +00003138
Jes Sorenseneb505be2010-06-10 11:42:28 +02003139 os_setup_post();
ths71e3ceb2006-12-22 02:11:31 +00003140
bellard8a7ddc32004-03-31 19:00:16 +00003141 main_loop();
bellard40c3bac2004-04-04 12:56:28 +00003142 quit_timers();
aliguori63a01ef2008-10-31 19:10:00 +00003143 net_cleanup();
thsb46a8902007-10-21 23:20:45 +00003144
bellard0824d6f2003-06-24 13:42:40 +00003145 return 0;
3146}