blob: de232b75e6981931c316aec74970e1725c636346 [file] [log] [blame]
bellard0824d6f2003-06-24 13:42:40 +00001/*
bellard80cabfa2004-03-14 12:20:30 +00002 * QEMU System Emulator
ths5fafdf22007-09-16 21:08:06 +00003 *
bellard68d0f702008-01-06 17:21:48 +00004 * Copyright (c) 2003-2008 Fabrice Bellard
ths5fafdf22007-09-16 21:08:06 +00005 *
bellard1df912c2003-06-25 16:20:35 +00006 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
bellard0824d6f2003-06-24 13:42:40 +000023 */
bellard0824d6f2003-06-24 13:42:40 +000024#include <unistd.h>
bellard0824d6f2003-06-24 13:42:40 +000025#include <fcntl.h>
26#include <signal.h>
27#include <time.h>
bellard0824d6f2003-06-24 13:42:40 +000028#include <errno.h>
bellard67b915a2004-03-31 23:37:16 +000029#include <sys/time.h>
bellardc88676f2006-08-06 13:36:11 +000030#include <zlib.h>
bellard67b915a2004-03-31 23:37:16 +000031
Juan Quintela71e72a12009-07-27 16:12:56 +020032/* Needed early for CONFIG_BSD etc. */
blueswir1d40cdb12009-03-07 16:52:02 +000033#include "config-host.h"
34
bellard67b915a2004-03-31 23:37:16 +000035#ifndef _WIN32
Paul Brook5cea8592009-05-30 00:52:44 +010036#include <libgen.h>
bellard67b915a2004-03-31 23:37:16 +000037#include <sys/times.h>
bellardf1510b22003-06-25 00:07:40 +000038#include <sys/wait.h>
bellard67b915a2004-03-31 23:37:16 +000039#include <termios.h>
bellard67b915a2004-03-31 23:37:16 +000040#include <sys/mman.h>
bellardf1510b22003-06-25 00:07:40 +000041#include <sys/ioctl.h>
blueswir124646c72008-11-07 16:55:48 +000042#include <sys/resource.h>
bellardf1510b22003-06-25 00:07:40 +000043#include <sys/socket.h>
bellardc94c8d62004-09-13 21:37:34 +000044#include <netinet/in.h>
blueswir124646c72008-11-07 16:55:48 +000045#include <net/if.h>
blueswir124646c72008-11-07 16:55:48 +000046#include <arpa/inet.h>
bellard9d728e82004-09-05 23:09:03 +000047#include <dirent.h>
bellard7c9d8e02005-11-15 22:16:05 +000048#include <netdb.h>
thscb4b9762007-09-13 12:39:35 +000049#include <sys/select.h>
Prerna Saxenaab6540d2010-08-09 11:48:32 +010050
Juan Quintela71e72a12009-07-27 16:12:56 +020051#ifdef CONFIG_BSD
bellard7d3505c2004-05-12 19:32:15 +000052#include <sys/stat.h>
Aurelien Jarnoa167ba52009-11-29 18:00:41 +010053#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
bellard7d3505c2004-05-12 19:32:15 +000054#include <libutil.h>
Juergen Lock92c0e652010-03-25 22:07:12 +010055#include <sys/sysctl.h>
blueswir124646c72008-11-07 16:55:48 +000056#else
57#include <util.h>
blueswir1128ab2f2008-08-15 18:33:42 +000058#endif
Aurelien Jarnobbe813a2009-11-30 15:42:59 +010059#else
blueswir1223f0d72008-09-30 18:12:18 +000060#ifdef __linux__
bellard7d3505c2004-05-12 19:32:15 +000061#include <pty.h>
62#include <malloc.h>
thsbd494f42007-09-16 20:03:23 +000063
bellarde57a8c02005-11-10 23:58:52 +000064#include <linux/ppdev.h>
ths5867c882007-02-17 23:44:43 +000065#include <linux/parport.h>
blueswir1223f0d72008-09-30 18:12:18 +000066#endif
67#ifdef __sun__
thsd5d10bc2007-02-17 22:54:49 +000068#include <sys/stat.h>
69#include <sys/ethernet.h>
70#include <sys/sockio.h>
thsd5d10bc2007-02-17 22:54:49 +000071#include <netinet/arp.h>
thsd5d10bc2007-02-17 22:54:49 +000072#include <netinet/in_systm.h>
73#include <netinet/ip.h>
74#include <netinet/ip_icmp.h> // must come after ip.h
75#include <netinet/udp.h>
76#include <netinet/tcp.h>
77#include <net/if.h>
78#include <syslog.h>
79#include <stropts.h>
bellard67b915a2004-03-31 23:37:16 +000080#endif
bellard7d3505c2004-05-12 19:32:15 +000081#endif
bellardec530c82006-04-25 22:36:06 +000082#endif
bellard67b915a2004-03-31 23:37:16 +000083
blueswir19892fbf2008-08-24 10:34:20 +000084#if defined(__OpenBSD__)
85#include <util.h>
86#endif
87
ths8a16d272008-07-19 09:56:24 +000088#if defined(CONFIG_VDE)
89#include <libvdeplug.h>
90#endif
91
bellard67b915a2004-03-31 23:37:16 +000092#ifdef _WIN32
aliguori49dc7682009-03-08 16:26:59 +000093#include <windows.h>
bellard67b915a2004-03-31 23:37:16 +000094#endif
95
bellard73332e52004-04-04 20:22:28 +000096#ifdef CONFIG_SDL
Stefan Weil59a36a22009-06-18 20:11:03 +020097#if defined(__APPLE__) || defined(main)
Stefan Weil66936652009-06-13 13:19:11 +020098#include <SDL.h>
malc880fec52009-02-15 20:18:41 +000099int qemu_main(int argc, char **argv, char **envp);
100int main(int argc, char **argv)
101{
Stefan Weil59a36a22009-06-18 20:11:03 +0200102 return qemu_main(argc, argv, NULL);
malc880fec52009-02-15 20:18:41 +0000103}
104#undef main
105#define main qemu_main
bellard96bcd4f2004-07-10 16:26:15 +0000106#endif
bellard73332e52004-04-04 20:22:28 +0000107#endif /* CONFIG_SDL */
bellard0824d6f2003-06-24 13:42:40 +0000108
bellard5b0753e2005-03-01 21:37:28 +0000109#ifdef CONFIG_COCOA
110#undef main
111#define main qemu_main
112#endif /* CONFIG_COCOA */
113
blueswir1511d2b12009-03-07 15:32:56 +0000114#include "hw/hw.h"
115#include "hw/boards.h"
116#include "hw/usb.h"
117#include "hw/pcmcia.h"
118#include "hw/pc.h"
blueswir1511d2b12009-03-07 15:32:56 +0000119#include "hw/isa.h"
120#include "hw/baum.h"
121#include "hw/bt.h"
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +0100122#include "hw/watchdog.h"
aliguorib6f6e3d2009-04-17 18:59:56 +0000123#include "hw/smbios.h"
aliguorie37630c2009-04-22 15:19:10 +0000124#include "hw/xen.h"
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +0200125#include "hw/qdev.h"
Gerd Hoffmann45a50b12009-10-01 16:42:33 +0200126#include "hw/loader.h"
aurel325ef4efa2009-03-10 21:43:35 +0000127#include "bt-host.h"
blueswir1511d2b12009-03-07 15:32:56 +0000128#include "net.h"
Mark McLoughlin68ac40d2009-11-25 18:48:54 +0000129#include "net/slirp.h"
blueswir1511d2b12009-03-07 15:32:56 +0000130#include "monitor.h"
131#include "console.h"
132#include "sysemu.h"
133#include "gdbstub.h"
134#include "qemu-timer.h"
135#include "qemu-char.h"
136#include "cache-utils.h"
137#include "block.h"
Markus Armbruster666daa62010-06-02 18:48:27 +0200138#include "blockdev.h"
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +0200139#include "block-migration.h"
blueswir1a718ace2009-03-28 08:24:44 +0000140#include "dma.h"
blueswir1511d2b12009-03-07 15:32:56 +0000141#include "audio/audio.h"
142#include "migration.h"
143#include "kvm.h"
Kevin Wolfd3f24362009-05-18 16:42:09 +0200144#include "qemu-option.h"
Gerd Hoffmann7282a032009-07-31 12:25:35 +0200145#include "qemu-config.h"
Luiz Capitulinoe78c48e2009-12-10 17:16:04 -0200146#include "qemu-objects.h"
Jes Sorensen59a52642010-06-10 11:42:25 +0200147#include "qemu-options.h"
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -0700148#ifdef CONFIG_VIRTFS
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530149#include "fsdev/qemu-fsdev.h"
150#endif
blueswir1511d2b12009-03-07 15:32:56 +0000151
bellard0824d6f2003-06-24 13:42:40 +0000152#include "disas.h"
bellardfc01f7e2003-06-30 10:03:06 +0000153
blueswir1511d2b12009-03-07 15:32:56 +0000154#include "qemu_socket.h"
155
Jan Kiszkad918f232009-06-24 14:42:30 +0200156#include "slirp/libslirp.h"
blueswir1511d2b12009-03-07 15:32:56 +0000157
Stefan Hajnoczi94b0b5f2010-11-16 12:20:25 +0000158#include "trace.h"
Stefan Hajnoczi0b5538c2011-02-26 18:38:39 +0000159#include "simpletrace.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +0000160#include "qemu-queue.h"
Blue Swirl296af7c2010-03-29 19:23:50 +0000161#include "cpus.h"
Blue Swirlad960902010-03-29 19:23:52 +0000162#include "arch_init.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +0000163
Gerd Hoffmann29b00402010-03-11 11:13:27 -0300164#include "ui/qemu-spice.h"
165
blueswir19dc63a12008-10-04 07:25:46 +0000166//#define DEBUG_NET
167//#define DEBUG_SLIRP
bellard330d0412003-07-26 18:11:40 +0000168
bellard1bfe8562004-07-08 21:17:50 +0000169#define DEFAULT_RAM_SIZE 128
bellard313aa562003-08-10 21:52:11 +0000170
Amit Shah98b19252010-01-20 00:36:52 +0530171#define MAX_VIRTIO_CONSOLES 1
172
Paul Brook5cea8592009-05-30 00:52:44 +0100173static const char *data_dir;
j_mayer1192dad2007-10-05 13:08:35 +0000174const char *bios_name = NULL;
malccb5a7aa2008-09-28 00:42:12 +0000175enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
Anthony Liguori993fbfd2009-05-21 16:54:00 -0500176DisplayType display_type = DT_DEFAULT;
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +0200177int display_remote = 0;
bellard3d11d0e2004-12-12 16:56:30 +0000178const char* keyboard_layout = NULL;
Anthony Liguoric227f092009-10-01 16:12:16 -0500179ram_addr_t ram_size;
Marcelo Tosattic9027602010-03-01 20:25:08 -0300180const char *mem_path = NULL;
181#ifdef MAP_POPULATE
182int mem_prealloc = 0; /* force preallocation of physical target memory */
183#endif
bellardc4b1fcc2004-03-14 21:44:30 +0000184int nb_nics;
bellard7c9d8e02005-11-15 22:16:05 +0000185NICInfo nd_table[MAX_NICS];
bellard8a7ddc32004-03-31 19:00:16 +0000186int vm_running;
Paolo Bonzinid399f672009-07-27 23:17:51 +0200187int autostart;
Amit Shah8e848652010-07-27 15:49:19 +0530188int incoming_expected; /* Started with -incoming and waiting for incoming */
balrogf6503052008-02-17 11:42:19 +0000189static int rtc_utc = 1;
190static int rtc_date_offset = -1; /* -1 means no change */
Jan Kiszka68752042009-09-15 13:36:04 +0200191QEMUClock *rtc_clock;
Gerd Hoffmann64465292009-12-08 13:11:45 +0100192int vga_interface_type = VGA_NONE;
blueswir1dbed7e42008-10-01 19:38:09 +0000193static int full_screen = 0;
blueswir1634a21f2008-11-16 11:34:07 +0000194#ifdef CONFIG_SDL
blueswir1dbed7e42008-10-01 19:38:09 +0000195static int no_frame = 0;
blueswir1634a21f2008-11-16 11:34:07 +0000196#endif
ths667acca2006-12-11 02:08:05 +0000197int no_quit = 0;
bellard8d11df92004-08-24 21:13:40 +0000198CharDriverState *serial_hds[MAX_SERIAL_PORTS];
bellard6508fe52005-01-15 12:02:56 +0000199CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
aliguori9ede2fd2009-01-15 20:05:25 +0000200CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
bellarda09db212005-04-30 16:10:35 +0000201int win2k_install_hack = 0;
aliguori73822ec2009-01-15 20:11:34 +0000202int rtc_td_hack = 0;
bellardbb36d472005-11-05 14:22:28 +0000203int usb_enabled = 0;
aurel321b530a62009-04-05 20:08:59 +0000204int singlestep = 0;
bellard6a00d602005-11-21 23:25:50 +0000205int smp_cpus = 1;
Jes Sorensen6be68d72009-07-23 17:03:42 +0200206int max_cpus = 0;
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200207int smp_cores = 1;
208int smp_threads = 1;
Jes Sorensen821601e2011-03-16 13:33:36 +0100209#ifdef CONFIG_VNC
ths73fc9742006-12-22 02:09:07 +0000210const char *vnc_display;
Jes Sorensen821601e2011-03-16 13:33:36 +0100211#endif
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
Markus Armbruster319ae522011-01-28 11:21:46 +0100635 return drive_init(opts, *use_scsi) == NULL;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200636}
637
638static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
639{
640 if (NULL == qemu_opt_get(opts, "snapshot")) {
641 qemu_opt_set(opts, "snapshot", "on");
642 }
643 return 0;
644}
645
Markus Armbruster4e5d9b52011-01-28 11:21:45 +0100646static void default_drive(int enable, int snapshot, int use_scsi,
647 BlockInterfaceType type, int index,
648 const char *optstr)
649{
650 QemuOpts *opts;
651
652 if (type == IF_DEFAULT) {
653 type = use_scsi ? IF_SCSI : IF_IDE;
654 }
655
656 if (!enable || drive_get_by_index(type, index)) {
657 return;
658 }
659
660 opts = drive_add(type, index, NULL, optstr);
661 if (snapshot) {
662 drive_enable_snapshot(opts, NULL);
663 }
Markus Armbruster319ae522011-01-28 11:21:46 +0100664 if (!drive_init(opts, use_scsi)) {
Markus Armbruster4e5d9b52011-01-28 11:21:45 +0100665 exit(1);
666 }
667}
668
Jan Kiszka76e30d02009-07-02 00:19:02 +0200669void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
670{
671 boot_set_handler = func;
672 boot_set_opaque = opaque;
673}
674
675int qemu_boot_set(const char *boot_devices)
676{
677 if (!boot_set_handler) {
678 return -EINVAL;
679 }
680 return boot_set_handler(boot_set_opaque, boot_devices);
681}
682
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -0300683static void validate_bootdevices(char *devices)
Jan Kiszkaef3adf62009-07-02 00:19:02 +0200684{
685 /* We just do some generic consistency checks */
686 const char *p;
687 int bitmap = 0;
688
689 for (p = devices; *p != '\0'; p++) {
690 /* Allowed boot devices are:
691 * a-b: floppy disk drives
692 * c-f: IDE disk drives
693 * g-m: machine implementation dependant drives
694 * n-p: network devices
695 * It's up to each machine implementation to check if the given boot
696 * devices match the actual hardware implementation and firmware
697 * features.
698 */
699 if (*p < 'a' || *p > 'p') {
700 fprintf(stderr, "Invalid boot device '%c'\n", *p);
701 exit(1);
702 }
703 if (bitmap & (1 << (*p - 'a'))) {
704 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
705 exit(1);
706 }
707 bitmap |= 1 << (*p - 'a');
708 }
Jan Kiszkaef3adf62009-07-02 00:19:02 +0200709}
710
Jan Kiszkae0f084b2009-07-02 00:19:02 +0200711static void restore_boot_devices(void *opaque)
712{
713 char *standard_boot_devices = opaque;
Alex Williamson37905d62010-04-30 15:21:11 -0600714 static int first = 1;
715
716 /* Restore boot order and remove ourselves after the first boot */
717 if (first) {
718 first = 0;
719 return;
720 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +0200721
722 qemu_boot_set(standard_boot_devices);
723
724 qemu_unregister_reset(restore_boot_devices, standard_boot_devices);
725 qemu_free(standard_boot_devices);
726}
727
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200728void add_boot_device_path(int32_t bootindex, DeviceState *dev,
729 const char *suffix)
730{
731 FWBootEntry *node, *i;
732
733 if (bootindex < 0) {
734 return;
735 }
736
737 assert(dev != NULL || suffix != NULL);
738
739 node = qemu_mallocz(sizeof(FWBootEntry));
740 node->bootindex = bootindex;
Gleb Natapov4fef9302011-02-02 17:34:34 +0200741 node->suffix = suffix ? qemu_strdup(suffix) : NULL;
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200742 node->dev = dev;
743
744 QTAILQ_FOREACH(i, &fw_boot_order, link) {
745 if (i->bootindex == bootindex) {
746 fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
747 exit(1);
748 } else if (i->bootindex < bootindex) {
749 continue;
750 }
751 QTAILQ_INSERT_BEFORE(i, node, link);
752 return;
753 }
754 QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
755}
756
Gleb Natapov962630f2010-12-08 13:35:09 +0200757/*
758 * This function returns null terminated string that consist of new line
759 * separated device pathes.
760 *
761 * memory pointed by "size" is assigned total length of the array in bytes
762 *
763 */
764char *get_boot_devices_list(uint32_t *size)
765{
766 FWBootEntry *i;
767 uint32_t total = 0;
768 char *list = NULL;
769
770 QTAILQ_FOREACH(i, &fw_boot_order, link) {
771 char *devpath = NULL, *bootpath;
772 int len;
773
774 if (i->dev) {
775 devpath = qdev_get_fw_dev_path(i->dev);
776 assert(devpath);
777 }
778
779 if (i->suffix && devpath) {
Blue Swirl4fd37a92010-12-19 14:05:43 +0000780 size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
781
782 bootpath = qemu_malloc(bootpathlen);
783 snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
Gleb Natapov962630f2010-12-08 13:35:09 +0200784 qemu_free(devpath);
785 } else if (devpath) {
786 bootpath = devpath;
787 } else {
Gleb Natapov4fef9302011-02-02 17:34:34 +0200788 bootpath = qemu_strdup(i->suffix);
Gleb Natapov962630f2010-12-08 13:35:09 +0200789 assert(bootpath);
790 }
791
792 if (total) {
793 list[total-1] = '\n';
794 }
795 len = strlen(bootpath) + 1;
796 list = qemu_realloc(list, total + len);
797 memcpy(&list[total], bootpath, len);
798 total += len;
799 qemu_free(bootpath);
800 }
801
802 *size = total;
803
804 return list;
805}
806
aliguori268a3622009-04-21 22:30:27 +0000807static void numa_add(const char *optarg)
808{
809 char option[128];
810 char *endptr;
811 unsigned long long value, endvalue;
812 int nodenr;
813
814 optarg = get_opt_name(option, 128, optarg, ',') + 1;
815 if (!strcmp(option, "node")) {
816 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
817 nodenr = nb_numa_nodes;
818 } else {
819 nodenr = strtoull(option, NULL, 10);
820 }
821
822 if (get_param_value(option, 128, "mem", optarg) == 0) {
823 node_mem[nodenr] = 0;
824 } else {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +0100825 int64_t sval;
Jes Sorensen9f9b17a2010-10-21 17:15:46 +0200826 sval = strtosz(option, NULL);
827 if (sval < 0) {
828 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
829 exit(1);
aliguori268a3622009-04-21 22:30:27 +0000830 }
Jes Sorensen9f9b17a2010-10-21 17:15:46 +0200831 node_mem[nodenr] = sval;
aliguori268a3622009-04-21 22:30:27 +0000832 }
833 if (get_param_value(option, 128, "cpus", optarg) == 0) {
834 node_cpumask[nodenr] = 0;
835 } else {
836 value = strtoull(option, &endptr, 10);
837 if (value >= 64) {
838 value = 63;
839 fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n");
840 } else {
841 if (*endptr == '-') {
842 endvalue = strtoull(endptr+1, &endptr, 10);
843 if (endvalue >= 63) {
844 endvalue = 62;
845 fprintf(stderr,
846 "only 63 CPUs in NUMA mode supported.\n");
847 }
Paolo Bonzini0dfbd512010-02-04 14:31:50 +0100848 value = (2ULL << endvalue) - (1ULL << value);
aliguori268a3622009-04-21 22:30:27 +0000849 } else {
Paolo Bonzini0dfbd512010-02-04 14:31:50 +0100850 value = 1ULL << value;
aliguori268a3622009-04-21 22:30:27 +0000851 }
852 }
853 node_cpumask[nodenr] = value;
854 }
855 nb_numa_nodes++;
856 }
857 return;
858}
859
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200860static void smp_parse(const char *optarg)
861{
862 int smp, sockets = 0, threads = 0, cores = 0;
863 char *endptr;
864 char option[128];
865
866 smp = strtoul(optarg, &endptr, 10);
867 if (endptr != optarg) {
868 if (*endptr == ',') {
869 endptr++;
870 }
871 }
872 if (get_param_value(option, 128, "sockets", endptr) != 0)
873 sockets = strtoull(option, NULL, 10);
874 if (get_param_value(option, 128, "cores", endptr) != 0)
875 cores = strtoull(option, NULL, 10);
876 if (get_param_value(option, 128, "threads", endptr) != 0)
877 threads = strtoull(option, NULL, 10);
878 if (get_param_value(option, 128, "maxcpus", endptr) != 0)
879 max_cpus = strtoull(option, NULL, 10);
880
881 /* compute missing values, prefer sockets over cores over threads */
882 if (smp == 0 || sockets == 0) {
883 sockets = sockets > 0 ? sockets : 1;
884 cores = cores > 0 ? cores : 1;
885 threads = threads > 0 ? threads : 1;
886 if (smp == 0) {
887 smp = cores * threads * sockets;
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200888 }
889 } else {
890 if (cores == 0) {
891 threads = threads > 0 ? threads : 1;
892 cores = smp / (sockets * threads);
893 } else {
Joel Schoppdca98162010-07-21 15:05:17 -0500894 threads = smp / (cores * sockets);
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200895 }
896 }
897 smp_cpus = smp;
898 smp_cores = cores > 0 ? cores : 1;
899 smp_threads = threads > 0 ? threads : 1;
900 if (max_cpus == 0)
901 max_cpus = smp_cpus;
902}
903
bellard330d0412003-07-26 18:11:40 +0000904/***********************************************************/
bellarda594cfb2005-11-06 16:13:29 +0000905/* USB devices */
906
Markus Armbrusterfb080002010-05-28 15:38:44 +0200907static int usb_device_add(const char *devname)
bellarda594cfb2005-11-06 16:13:29 +0000908{
909 const char *p;
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200910 USBDevice *dev = NULL;
bellarda594cfb2005-11-06 16:13:29 +0000911
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200912 if (!usb_enabled)
bellarda594cfb2005-11-06 16:13:29 +0000913 return -1;
914
Gerd Hoffmann0958b4c2009-10-26 15:56:45 +0100915 /* drivers with .usbdevice_name entry in USBDeviceInfo */
916 dev = usbdevice_create(devname);
917 if (dev)
918 goto done;
919
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200920 /* the other ones */
bellarda594cfb2005-11-06 16:13:29 +0000921 if (strstart(devname, "host:", &p)) {
922 dev = usb_host_device_open(p);
balrogdc72ac12008-11-09 00:04:26 +0000923 } else if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
924 dev = usb_bt_init(devname[2] ? hci_init(p) :
925 bt_new_hci(qemu_find_bt_vlan(0)));
bellarda594cfb2005-11-06 16:13:29 +0000926 } else {
927 return -1;
928 }
pbrook0d92ed32006-05-21 16:30:15 +0000929 if (!dev)
930 return -1;
931
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200932done:
bellarda594cfb2005-11-06 16:13:29 +0000933 return 0;
934}
935
aliguori1f3870a2008-08-21 19:27:48 +0000936static int usb_device_del(const char *devname)
937{
938 int bus_num, addr;
939 const char *p;
940
aliguori5d0c5752008-09-14 01:07:41 +0000941 if (strstart(devname, "host:", &p))
942 return usb_host_device_close(p);
943
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200944 if (!usb_enabled)
aliguori1f3870a2008-08-21 19:27:48 +0000945 return -1;
946
947 p = strchr(devname, '.');
948 if (!p)
949 return -1;
950 bus_num = strtoul(devname, NULL, 0);
951 addr = strtoul(p + 1, NULL, 0);
952
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200953 return usb_device_delete_addr(bus_num, addr);
aliguori1f3870a2008-08-21 19:27:48 +0000954}
955
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +0200956static int usb_parse(const char *cmdline)
957{
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800958 int r;
Markus Armbrusterfb080002010-05-28 15:38:44 +0200959 r = usb_device_add(cmdline);
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800960 if (r < 0) {
961 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
962 }
963 return r;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +0200964}
965
Luiz Capitulinod54908a2009-08-28 15:27:13 -0300966void do_usb_add(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +0000967{
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800968 const char *devname = qdict_get_str(qdict, "devname");
Markus Armbrusterfb080002010-05-28 15:38:44 +0200969 if (usb_device_add(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +0100970 error_report("could not add USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800971 }
bellarda594cfb2005-11-06 16:13:29 +0000972}
973
Luiz Capitulinod54908a2009-08-28 15:27:13 -0300974void do_usb_del(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +0000975{
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800976 const char *devname = qdict_get_str(qdict, "devname");
977 if (usb_device_del(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +0100978 error_report("could not delete USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800979 }
bellarda594cfb2005-11-06 16:13:29 +0000980}
981
bellardf7cce892004-12-08 22:21:25 +0000982/***********************************************************/
balrog201a51f2007-04-30 00:51:09 +0000983/* PCMCIA/Cardbus */
984
985static struct pcmcia_socket_entry_s {
Paul Brookbc24a222009-05-10 01:44:56 +0100986 PCMCIASocket *socket;
balrog201a51f2007-04-30 00:51:09 +0000987 struct pcmcia_socket_entry_s *next;
988} *pcmcia_sockets = 0;
989
Paul Brookbc24a222009-05-10 01:44:56 +0100990void pcmcia_socket_register(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +0000991{
992 struct pcmcia_socket_entry_s *entry;
993
994 entry = qemu_malloc(sizeof(struct pcmcia_socket_entry_s));
995 entry->socket = socket;
996 entry->next = pcmcia_sockets;
997 pcmcia_sockets = entry;
998}
999
Paul Brookbc24a222009-05-10 01:44:56 +01001000void pcmcia_socket_unregister(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +00001001{
1002 struct pcmcia_socket_entry_s *entry, **ptr;
1003
1004 ptr = &pcmcia_sockets;
1005 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1006 if (entry->socket == socket) {
1007 *ptr = entry->next;
1008 qemu_free(entry);
1009 }
1010}
1011
aliguori376253e2009-03-05 23:01:23 +00001012void pcmcia_info(Monitor *mon)
balrog201a51f2007-04-30 00:51:09 +00001013{
1014 struct pcmcia_socket_entry_s *iter;
aliguori376253e2009-03-05 23:01:23 +00001015
balrog201a51f2007-04-30 00:51:09 +00001016 if (!pcmcia_sockets)
aliguori376253e2009-03-05 23:01:23 +00001017 monitor_printf(mon, "No PCMCIA sockets\n");
balrog201a51f2007-04-30 00:51:09 +00001018
1019 for (iter = pcmcia_sockets; iter; iter = iter->next)
aliguori376253e2009-03-05 23:01:23 +00001020 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1021 iter->socket->attached ? iter->socket->card_string :
1022 "Empty");
balrog201a51f2007-04-30 00:51:09 +00001023}
1024
1025/***********************************************************/
bellardcc1daa42005-06-05 14:49:17 +00001026/* machine registration */
1027
blueswir1bdaf78e2008-10-04 07:24:27 +00001028static QEMUMachine *first_machine = NULL;
aliguori6f338c32009-02-11 15:21:54 +00001029QEMUMachine *current_machine = NULL;
bellardcc1daa42005-06-05 14:49:17 +00001030
1031int qemu_register_machine(QEMUMachine *m)
1032{
1033 QEMUMachine **pm;
1034 pm = &first_machine;
1035 while (*pm != NULL)
1036 pm = &(*pm)->next;
1037 m->next = NULL;
1038 *pm = m;
1039 return 0;
1040}
1041
pbrook9596ebb2007-11-18 01:44:38 +00001042static QEMUMachine *find_machine(const char *name)
bellardcc1daa42005-06-05 14:49:17 +00001043{
1044 QEMUMachine *m;
1045
1046 for(m = first_machine; m != NULL; m = m->next) {
1047 if (!strcmp(m->name, name))
1048 return m;
Mark McLoughlin3f6599e2009-07-22 10:02:50 +01001049 if (m->alias && !strcmp(m->alias, name))
1050 return m;
bellardcc1daa42005-06-05 14:49:17 +00001051 }
1052 return NULL;
1053}
1054
Anthony Liguori0c257432009-05-21 20:41:01 -05001055static QEMUMachine *find_default_machine(void)
1056{
1057 QEMUMachine *m;
1058
1059 for(m = first_machine; m != NULL; m = m->next) {
1060 if (m->is_default) {
1061 return m;
1062 }
1063 }
1064 return NULL;
1065}
1066
bellardcc1daa42005-06-05 14:49:17 +00001067/***********************************************************/
bellard8a7ddc32004-03-31 19:00:16 +00001068/* main execution loop */
1069
pbrook9596ebb2007-11-18 01:44:38 +00001070static void gui_update(void *opaque)
bellard8a7ddc32004-03-31 19:00:16 +00001071{
aliguori7d957bd2009-01-15 22:14:11 +00001072 uint64_t interval = GUI_REFRESH_INTERVAL;
ths740733b2007-06-08 01:57:56 +00001073 DisplayState *ds = opaque;
aliguori7d957bd2009-01-15 22:14:11 +00001074 DisplayChangeListener *dcl = ds->listeners;
1075
Sheng Yang62a27442010-01-26 19:21:16 +08001076 qemu_flush_coalesced_mmio_buffer();
aliguori7d957bd2009-01-15 22:14:11 +00001077 dpy_refresh(ds);
1078
1079 while (dcl != NULL) {
1080 if (dcl->gui_timer_interval &&
1081 dcl->gui_timer_interval < interval)
1082 interval = dcl->gui_timer_interval;
1083 dcl = dcl->next;
1084 }
Paolo Bonzini7bd427d2011-03-11 16:47:48 +01001085 qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock));
bellard8a7ddc32004-03-31 19:00:16 +00001086}
1087
blueswir19043b622009-01-21 19:28:13 +00001088static void nographic_update(void *opaque)
1089{
1090 uint64_t interval = GUI_REFRESH_INTERVAL;
1091
Sheng Yang62a27442010-01-26 19:21:16 +08001092 qemu_flush_coalesced_mmio_buffer();
Paolo Bonzini7bd427d2011-03-11 16:47:48 +01001093 qemu_mod_timer(nographic_timer, interval + qemu_get_clock_ms(rt_clock));
blueswir19043b622009-01-21 19:28:13 +00001094}
1095
bellard0bd48852005-11-11 00:00:47 +00001096struct vm_change_state_entry {
1097 VMChangeStateHandler *cb;
1098 void *opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001099 QLIST_ENTRY (vm_change_state_entry) entries;
bellard0bd48852005-11-11 00:00:47 +00001100};
1101
Blue Swirl72cf2d42009-09-12 07:36:22 +00001102static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
bellard0bd48852005-11-11 00:00:47 +00001103
1104VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1105 void *opaque)
1106{
1107 VMChangeStateEntry *e;
1108
1109 e = qemu_mallocz(sizeof (*e));
bellard0bd48852005-11-11 00:00:47 +00001110
1111 e->cb = cb;
1112 e->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001113 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
bellard0bd48852005-11-11 00:00:47 +00001114 return e;
1115}
1116
1117void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1118{
Blue Swirl72cf2d42009-09-12 07:36:22 +00001119 QLIST_REMOVE (e, entries);
bellard0bd48852005-11-11 00:00:47 +00001120 qemu_free (e);
1121}
1122
Blue Swirl296af7c2010-03-29 19:23:50 +00001123void vm_state_notify(int running, int reason)
bellard0bd48852005-11-11 00:00:47 +00001124{
1125 VMChangeStateEntry *e;
1126
Stefan Hajnoczi94b0b5f2010-11-16 12:20:25 +00001127 trace_vm_state_notify(running, reason);
1128
bellard0bd48852005-11-11 00:00:47 +00001129 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
aliguori9781e042009-01-22 17:15:29 +00001130 e->cb(e->opaque, running, reason);
bellard0bd48852005-11-11 00:00:47 +00001131 }
1132}
1133
bellard8a7ddc32004-03-31 19:00:16 +00001134void vm_start(void)
1135{
1136 if (!vm_running) {
1137 cpu_enable_ticks();
1138 vm_running = 1;
aliguori9781e042009-01-22 17:15:29 +00001139 vm_state_notify(1, 0);
aliguorid6dc3d42009-04-24 18:04:07 +00001140 resume_all_vcpus();
Luiz Capitulino6ed2c482010-04-27 20:35:59 -03001141 monitor_protocol_event(QEVENT_RESUME, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00001142 }
1143}
1144
bellardbb0c6722004-06-20 12:37:32 +00001145/* reset/shutdown handler */
1146
1147typedef struct QEMUResetEntry {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001148 QTAILQ_ENTRY(QEMUResetEntry) entry;
bellardbb0c6722004-06-20 12:37:32 +00001149 QEMUResetHandler *func;
1150 void *opaque;
bellardbb0c6722004-06-20 12:37:32 +00001151} QEMUResetEntry;
1152
Blue Swirl72cf2d42009-09-12 07:36:22 +00001153static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1154 QTAILQ_HEAD_INITIALIZER(reset_handlers);
bellardbb0c6722004-06-20 12:37:32 +00001155static int reset_requested;
Gleb Natapovf64622c2011-03-15 13:56:04 +02001156static int shutdown_requested, shutdown_signal = -1;
1157static pid_t shutdown_pid;
bellard34751872005-07-02 14:31:34 +00001158static int powerdown_requested;
Jan Kiszka8cf71712011-02-07 12:19:16 +01001159static int debug_requested;
1160static int vmstop_requested;
bellardbb0c6722004-06-20 12:37:32 +00001161
aurel32cf7a2fe2008-03-18 06:53:05 +00001162int qemu_shutdown_requested(void)
1163{
1164 int r = shutdown_requested;
1165 shutdown_requested = 0;
1166 return r;
1167}
1168
Gleb Natapovf64622c2011-03-15 13:56:04 +02001169void qemu_kill_report(void)
1170{
1171 if (shutdown_signal != -1) {
Peter Maydellf1d3fb02011-03-30 22:03:38 +01001172 fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal);
1173 if (shutdown_pid == 0) {
1174 /* This happens for eg ^C at the terminal, so it's worth
1175 * avoiding printing an odd message in that case.
1176 */
1177 fputc('\n', stderr);
1178 } else {
1179 fprintf(stderr, " from pid %d\n", shutdown_pid);
1180 }
Gleb Natapovf64622c2011-03-15 13:56:04 +02001181 shutdown_signal = -1;
1182 }
1183}
1184
aurel32cf7a2fe2008-03-18 06:53:05 +00001185int qemu_reset_requested(void)
1186{
1187 int r = reset_requested;
1188 reset_requested = 0;
1189 return r;
1190}
1191
1192int qemu_powerdown_requested(void)
1193{
1194 int r = powerdown_requested;
1195 powerdown_requested = 0;
1196 return r;
1197}
1198
aliguorie5689022009-04-24 18:03:54 +00001199static int qemu_debug_requested(void)
1200{
1201 int r = debug_requested;
1202 debug_requested = 0;
1203 return r;
1204}
1205
aliguori6e29f5d2009-04-24 18:04:02 +00001206static int qemu_vmstop_requested(void)
1207{
1208 int r = vmstop_requested;
1209 vmstop_requested = 0;
1210 return r;
1211}
1212
Jan Kiszkaa08d4362009-06-27 09:25:07 +02001213void qemu_register_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001214{
Jan Kiszka55ddfe82009-07-02 00:19:02 +02001215 QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry));
bellardbb0c6722004-06-20 12:37:32 +00001216
bellardbb0c6722004-06-20 12:37:32 +00001217 re->func = func;
1218 re->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001219 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
bellardbb0c6722004-06-20 12:37:32 +00001220}
1221
Jan Kiszkadda9b292009-07-02 00:19:02 +02001222void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001223{
1224 QEMUResetEntry *re;
1225
Blue Swirl72cf2d42009-09-12 07:36:22 +00001226 QTAILQ_FOREACH(re, &reset_handlers, entry) {
Jan Kiszkadda9b292009-07-02 00:19:02 +02001227 if (re->func == func && re->opaque == opaque) {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001228 QTAILQ_REMOVE(&reset_handlers, re, entry);
Jan Kiszkadda9b292009-07-02 00:19:02 +02001229 qemu_free(re);
1230 return;
1231 }
1232 }
1233}
1234
1235void qemu_system_reset(void)
1236{
1237 QEMUResetEntry *re, *nre;
1238
1239 /* reset all devices */
Blue Swirl72cf2d42009-09-12 07:36:22 +00001240 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
bellardbb0c6722004-06-20 12:37:32 +00001241 re->func(re->opaque);
1242 }
Luiz Capitulino81d9b782010-03-10 09:06:34 -06001243 monitor_protocol_event(QEVENT_RESET, NULL);
Jan Kiszkaea375f92010-03-01 19:10:30 +01001244 cpu_synchronize_all_post_reset();
bellardbb0c6722004-06-20 12:37:32 +00001245}
1246
1247void qemu_system_reset_request(void)
1248{
bellardd1beab82006-10-02 19:44:22 +00001249 if (no_reboot) {
1250 shutdown_requested = 1;
1251 } else {
1252 reset_requested = 1;
1253 }
Jan Kiszkab4a3d962011-02-01 22:15:43 +01001254 cpu_stop_current();
aliguorid9f75a42009-04-24 18:03:11 +00001255 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001256}
1257
Gleb Natapovf64622c2011-03-15 13:56:04 +02001258void qemu_system_killed(int signal, pid_t pid)
1259{
1260 shutdown_signal = signal;
1261 shutdown_pid = pid;
1262 qemu_system_shutdown_request();
1263}
1264
bellardbb0c6722004-06-20 12:37:32 +00001265void qemu_system_shutdown_request(void)
1266{
1267 shutdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001268 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001269}
1270
bellard34751872005-07-02 14:31:34 +00001271void qemu_system_powerdown_request(void)
1272{
1273 powerdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001274 qemu_notify_event();
1275}
1276
Jan Kiszka8cf71712011-02-07 12:19:16 +01001277void qemu_system_debug_request(void)
1278{
1279 debug_requested = 1;
Jan Kiszka83f338f2011-02-07 12:19:17 +01001280 qemu_notify_event();
Jan Kiszka8cf71712011-02-07 12:19:16 +01001281}
1282
1283void qemu_system_vmstop_request(int reason)
1284{
1285 vmstop_requested = reason;
1286 qemu_notify_event();
1287}
1288
Paolo Bonzinid6f4ade2010-03-10 11:38:54 +01001289void main_loop_wait(int nonblocking)
aliguori56f3a5d2008-10-31 18:07:17 +00001290{
aliguori56f3a5d2008-10-31 18:07:17 +00001291 fd_set rfds, wfds, xfds;
1292 int ret, nfds;
1293 struct timeval tv;
Paolo Bonzinid6f4ade2010-03-10 11:38:54 +01001294 int timeout;
aliguori56f3a5d2008-10-31 18:07:17 +00001295
Paolo Bonzinid6f4ade2010-03-10 11:38:54 +01001296 if (nonblocking)
1297 timeout = 0;
1298 else {
1299 timeout = qemu_calculate_timeout();
1300 qemu_bh_update_timeout(&timeout);
1301 }
aliguori56f3a5d2008-10-31 18:07:17 +00001302
Jes Sorensen0d93ca72010-06-10 11:42:18 +02001303 os_host_main_loop_wait(&timeout);
aliguori56f3a5d2008-10-31 18:07:17 +00001304
Paolo Bonzini02981412011-03-09 18:21:09 +01001305 tv.tv_sec = timeout / 1000;
1306 tv.tv_usec = (timeout % 1000) * 1000;
1307
bellardfd1dff42006-02-01 21:29:26 +00001308 /* poll any events */
1309 /* XXX: separate device handlers from system ones */
aliguori6abfbd72008-11-05 20:49:37 +00001310 nfds = -1;
bellardfd1dff42006-02-01 21:29:26 +00001311 FD_ZERO(&rfds);
1312 FD_ZERO(&wfds);
bellarde0356492006-05-01 13:33:02 +00001313 FD_ZERO(&xfds);
Paolo Bonzini02981412011-03-09 18:21:09 +01001314 qemu_iohandler_fill(&nfds, &rfds, &wfds, &xfds);
Jan Kiszkad918f232009-06-24 14:42:30 +02001315 slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
1316
aliguori48708522009-04-24 18:03:49 +00001317 qemu_mutex_unlock_iothread();
bellarde0356492006-05-01 13:33:02 +00001318 ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
aliguori48708522009-04-24 18:03:49 +00001319 qemu_mutex_lock_iothread();
thscafffd42007-02-28 21:59:44 +00001320
Paolo Bonzini02981412011-03-09 18:21:09 +01001321 qemu_iohandler_poll(&rfds, &wfds, &xfds, ret);
Jan Kiszkad918f232009-06-24 14:42:30 +02001322 slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));
bellardc20709a2004-04-21 23:27:19 +00001323
Paolo Bonzinib6964822010-03-10 11:38:45 +01001324 qemu_run_all_timers();
Jan Kiszka21d5d122009-09-15 13:36:04 +02001325
pbrook423f0742007-05-23 00:06:54 +00001326 /* Check bottom-halves last in case any of the earlier events triggered
1327 them. */
1328 qemu_bh_poll();
ths3b46e622007-09-17 08:09:54 +00001329
bellard5905b2e2004-08-01 21:53:26 +00001330}
1331
Jan Kiszka46481d32011-02-01 22:15:47 +01001332#ifndef CONFIG_IOTHREAD
1333static int vm_request_pending(void)
aliguori43b96852009-04-24 18:03:33 +00001334{
Jan Kiszka46481d32011-02-01 22:15:47 +01001335 return powerdown_requested ||
1336 reset_requested ||
1337 shutdown_requested ||
1338 debug_requested ||
1339 vmstop_requested;
aliguori43b96852009-04-24 18:03:33 +00001340}
Jan Kiszka46481d32011-02-01 22:15:47 +01001341#endif
aliguori43b96852009-04-24 18:03:33 +00001342
Blue Swirld9c32312009-08-09 08:42:19 +00001343qemu_irq qemu_system_powerdown;
1344
aliguori43b96852009-04-24 18:03:33 +00001345static void main_loop(void)
1346{
Jan Kiszka8e1b90e2011-02-01 22:15:46 +01001347 bool nonblocking = false;
1348#ifdef CONFIG_PROFILER
1349 int64_t ti;
1350#endif
aliguori6e29f5d2009-04-24 18:04:02 +00001351 int r;
aliguori43b96852009-04-24 18:03:33 +00001352
Blue Swirl7277e022010-04-12 17:19:06 +00001353 qemu_main_loop_start();
aliguorid6dc3d42009-04-24 18:04:07 +00001354
aliguori6e29f5d2009-04-24 18:04:02 +00001355 for (;;) {
aliguorid6dc3d42009-04-24 18:04:07 +00001356#ifndef CONFIG_IOTHREAD
Jan Kiszka46481d32011-02-01 22:15:47 +01001357 nonblocking = cpu_exec_all();
1358 if (vm_request_pending()) {
1359 nonblocking = true;
1360 }
aliguorid6dc3d42009-04-24 18:04:07 +00001361#endif
aliguori43b96852009-04-24 18:03:33 +00001362#ifdef CONFIG_PROFILER
Jan Kiszka46481d32011-02-01 22:15:47 +01001363 ti = profile_getclock();
aliguori43b96852009-04-24 18:03:33 +00001364#endif
Jan Kiszka46481d32011-02-01 22:15:47 +01001365 main_loop_wait(nonblocking);
aliguori43b96852009-04-24 18:03:33 +00001366#ifdef CONFIG_PROFILER
Jan Kiszka46481d32011-02-01 22:15:47 +01001367 dev_time += profile_getclock() - ti;
aliguori43b96852009-04-24 18:03:33 +00001368#endif
aliguori43b96852009-04-24 18:03:33 +00001369
Jan Kiszka8cf71712011-02-07 12:19:16 +01001370 if (qemu_debug_requested()) {
1371 vm_stop(VMSTOP_DEBUG);
Luiz Capitulinob1a15e72009-11-26 22:59:04 -02001372 }
aliguori43b96852009-04-24 18:03:33 +00001373 if (qemu_shutdown_requested()) {
Gleb Natapovf64622c2011-03-15 13:56:04 +02001374 qemu_kill_report();
Blue Swirl242cd002009-12-04 18:05:45 +00001375 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
aliguori43b96852009-04-24 18:03:33 +00001376 if (no_shutdown) {
Jan Kiszkae07bbac2011-02-09 16:29:40 +01001377 vm_stop(VMSTOP_SHUTDOWN);
aliguori43b96852009-04-24 18:03:33 +00001378 no_shutdown = 0;
1379 } else
1380 break;
1381 }
aliguorid6dc3d42009-04-24 18:04:07 +00001382 if (qemu_reset_requested()) {
1383 pause_all_vcpus();
Jan Kiszkaa7ada152011-03-02 08:56:11 +01001384 cpu_synchronize_all_states();
aliguori43b96852009-04-24 18:03:33 +00001385 qemu_system_reset();
aliguorid6dc3d42009-04-24 18:04:07 +00001386 resume_all_vcpus();
1387 }
Blue Swirld9c32312009-08-09 08:42:19 +00001388 if (qemu_powerdown_requested()) {
Blue Swirl242cd002009-12-04 18:05:45 +00001389 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
Blue Swirld9c32312009-08-09 08:42:19 +00001390 qemu_irq_raise(qemu_system_powerdown);
1391 }
Luiz Capitulinob1a15e72009-11-26 22:59:04 -02001392 if ((r = qemu_vmstop_requested())) {
aliguori6e29f5d2009-04-24 18:04:02 +00001393 vm_stop(r);
Luiz Capitulinob1a15e72009-11-26 22:59:04 -02001394 }
aliguori43b96852009-04-24 18:03:33 +00001395 }
MORITA Kazutaka2bc93fe2010-05-28 11:44:57 +09001396 bdrv_close_all();
aliguorid6dc3d42009-04-24 18:04:07 +00001397 pause_all_vcpus();
bellardb4608c02003-06-27 17:34:32 +00001398}
1399
pbrook9bd7e6d2009-04-07 22:58:45 +00001400static void version(void)
1401{
Thomas Monjalonf75ca1a2010-04-28 14:42:01 +02001402 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
pbrook9bd7e6d2009-04-07 22:58:45 +00001403}
1404
ths15f82202007-06-29 23:26:08 +00001405static void help(int exitcode)
bellard0824d6f2003-06-24 13:42:40 +00001406{
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001407 const char *options_help =
Blue Swirlad960902010-03-29 19:23:52 +00001408#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1409 opt_help
blueswir15824d652009-03-28 06:44:27 +00001410#define DEFHEADING(text) stringify(text) "\n"
Jes Sorensen9f167322010-06-10 11:42:24 +02001411#include "qemu-options.def"
blueswir15824d652009-03-28 06:44:27 +00001412#undef DEF
1413#undef DEFHEADING
1414#undef GEN_DOCS
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001415 ;
1416 version();
1417 printf("usage: %s [options] [disk_image]\n"
malc3f020d72010-02-08 12:04:56 +03001418 "\n"
Thomas Monjalonf75ca1a2010-04-28 14:42:01 +02001419 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001420 "\n"
1421 "%s\n"
malc3f020d72010-02-08 12:04:56 +03001422 "During emulation, the following keys are useful:\n"
1423 "ctrl-alt-f toggle full screen\n"
1424 "ctrl-alt-n switch to virtual console 'n'\n"
1425 "ctrl-alt toggle mouse and keyboard grab\n"
1426 "\n"
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001427 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1428 "qemu",
1429 options_help);
ths15f82202007-06-29 23:26:08 +00001430 exit(exitcode);
bellard0824d6f2003-06-24 13:42:40 +00001431}
1432
bellardcd6f1162004-05-13 22:02:20 +00001433#define HAS_ARG 0x0001
1434
bellardcd6f1162004-05-13 22:02:20 +00001435typedef struct QEMUOption {
1436 const char *name;
1437 int flags;
1438 int index;
Blue Swirlad960902010-03-29 19:23:52 +00001439 uint32_t arch_mask;
bellardcd6f1162004-05-13 22:02:20 +00001440} QEMUOption;
1441
blueswir1dbed7e42008-10-01 19:38:09 +00001442static const QEMUOption qemu_options[] = {
Blue Swirlad960902010-03-29 19:23:52 +00001443 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1444#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1445 { option, opt_arg, opt_enum, arch_mask },
blueswir15824d652009-03-28 06:44:27 +00001446#define DEFHEADING(text)
Jes Sorensen9f167322010-06-10 11:42:24 +02001447#include "qemu-options.def"
blueswir15824d652009-03-28 06:44:27 +00001448#undef DEF
1449#undef DEFHEADING
1450#undef GEN_DOCS
bellardcd6f1162004-05-13 22:02:20 +00001451 { NULL },
bellardfc01f7e2003-06-30 10:03:06 +00001452};
malc3893c122008-09-28 00:42:05 +00001453static void select_vgahw (const char *p)
1454{
1455 const char *opts;
1456
Gerd Hoffmann64465292009-12-08 13:11:45 +01001457 default_vga = 0;
Zachary Amsden86176752009-07-30 00:15:02 -10001458 vga_interface_type = VGA_NONE;
malc3893c122008-09-28 00:42:05 +00001459 if (strstart(p, "std", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001460 vga_interface_type = VGA_STD;
malc3893c122008-09-28 00:42:05 +00001461 } else if (strstart(p, "cirrus", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001462 vga_interface_type = VGA_CIRRUS;
malc3893c122008-09-28 00:42:05 +00001463 } else if (strstart(p, "vmware", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001464 vga_interface_type = VGA_VMWARE;
aliguori94909d92009-04-22 15:19:53 +00001465 } else if (strstart(p, "xenfb", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001466 vga_interface_type = VGA_XENFB;
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +02001467 } else if (strstart(p, "qxl", &opts)) {
1468 vga_interface_type = VGA_QXL;
aliguori28b85ed2009-04-22 15:19:48 +00001469 } else if (!strstart(p, "none", &opts)) {
malc3893c122008-09-28 00:42:05 +00001470 invalid_vga:
1471 fprintf(stderr, "Unknown vga type: %s\n", p);
1472 exit(1);
1473 }
malccb5a7aa2008-09-28 00:42:12 +00001474 while (*opts) {
1475 const char *nextopt;
1476
1477 if (strstart(opts, ",retrace=", &nextopt)) {
1478 opts = nextopt;
1479 if (strstart(opts, "dumb", &nextopt))
1480 vga_retrace_method = VGA_RETRACE_DUMB;
1481 else if (strstart(opts, "precise", &nextopt))
1482 vga_retrace_method = VGA_RETRACE_PRECISE;
1483 else goto invalid_vga;
1484 } else goto invalid_vga;
1485 opts = nextopt;
1486 }
malc3893c122008-09-28 00:42:05 +00001487}
1488
Jes Sorensen1472a952011-03-16 13:33:31 +01001489static DisplayType select_display(const char *p)
1490{
1491 const char *opts;
1492 DisplayType display = DT_DEFAULT;
1493
1494 if (strstart(p, "sdl", &opts)) {
1495#ifdef CONFIG_SDL
1496 display = DT_SDL;
1497 while (*opts) {
1498 const char *nextopt;
1499
1500 if (strstart(opts, ",frame=", &nextopt)) {
1501 opts = nextopt;
1502 if (strstart(opts, "on", &nextopt)) {
1503 no_frame = 0;
1504 } else if (strstart(opts, "off", &nextopt)) {
1505 no_frame = 1;
1506 } else {
Peter Maydell05175532011-03-23 03:40:57 +00001507 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01001508 }
1509 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
1510 opts = nextopt;
1511 if (strstart(opts, "on", &nextopt)) {
1512 alt_grab = 1;
1513 } else if (strstart(opts, "off", &nextopt)) {
1514 alt_grab = 0;
1515 } else {
Peter Maydell05175532011-03-23 03:40:57 +00001516 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01001517 }
1518 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
1519 opts = nextopt;
1520 if (strstart(opts, "on", &nextopt)) {
1521 ctrl_grab = 1;
1522 } else if (strstart(opts, "off", &nextopt)) {
1523 ctrl_grab = 0;
1524 } else {
Peter Maydell05175532011-03-23 03:40:57 +00001525 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01001526 }
1527 } else if (strstart(opts, ",window_close=", &nextopt)) {
1528 opts = nextopt;
1529 if (strstart(opts, "on", &nextopt)) {
1530 no_quit = 0;
1531 } else if (strstart(opts, "off", &nextopt)) {
1532 no_quit = 1;
1533 } else {
Peter Maydell05175532011-03-23 03:40:57 +00001534 goto invalid_sdl_args;
Jes Sorensen1472a952011-03-16 13:33:31 +01001535 }
1536 } else {
Peter Maydell05175532011-03-23 03:40:57 +00001537 invalid_sdl_args:
1538 fprintf(stderr, "Invalid SDL option string: %s\n", p);
1539 exit(1);
Jes Sorensen1472a952011-03-16 13:33:31 +01001540 }
1541 opts = nextopt;
1542 }
1543#else
1544 fprintf(stderr, "SDL support is disabled\n");
1545 exit(1);
1546#endif
Jes Sorensen3264ff12011-03-16 13:33:33 +01001547 } else if (strstart(p, "vnc", &opts)) {
Jes Sorensen821601e2011-03-16 13:33:36 +01001548#ifdef CONFIG_VNC
Jes Sorensen3264ff12011-03-16 13:33:33 +01001549 display_remote++;
1550
1551 if (*opts) {
1552 const char *nextopt;
1553
1554 if (strstart(opts, "=", &nextopt)) {
1555 vnc_display = nextopt;
1556 }
1557 }
1558 if (!vnc_display) {
1559 fprintf(stderr, "VNC requires a display argument vnc=<display>\n");
1560 exit(1);
1561 }
Jes Sorensen821601e2011-03-16 13:33:36 +01001562#else
1563 fprintf(stderr, "VNC support is disabled\n");
1564 exit(1);
1565#endif
Jes Sorensen1472a952011-03-16 13:33:31 +01001566 } else if (strstart(p, "curses", &opts)) {
1567#ifdef CONFIG_CURSES
1568 display = DT_CURSES;
1569#else
1570 fprintf(stderr, "Curses support is disabled\n");
1571 exit(1);
1572#endif
Jes Sorensen4171d322011-03-16 13:33:32 +01001573 } else if (strstart(p, "none", &opts)) {
1574 display = DT_NONE;
Jes Sorensen1472a952011-03-16 13:33:31 +01001575 } else {
Jes Sorensen1472a952011-03-16 13:33:31 +01001576 fprintf(stderr, "Unknown display type: %s\n", p);
1577 exit(1);
1578 }
1579
1580 return display;
1581}
1582
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001583static int balloon_parse(const char *arg)
1584{
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001585 QemuOpts *opts;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001586
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001587 if (strcmp(arg, "none") == 0) {
1588 return 0;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001589 }
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001590
1591 if (!strncmp(arg, "virtio", 6)) {
1592 if (arg[6] == ',') {
1593 /* have params -> parse them */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001594 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001595 if (!opts)
1596 return -1;
1597 } else {
1598 /* create empty opts */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001599 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001600 }
Alexander Graf29f82b32011-03-29 15:29:29 +02001601 qemu_opt_set(opts, "driver", "virtio-balloon");
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001602 return 0;
1603 }
1604
1605 return -1;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001606}
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001607
Paul Brook5cea8592009-05-30 00:52:44 +01001608char *qemu_find_file(int type, const char *name)
1609{
1610 int len;
1611 const char *subdir;
1612 char *buf;
1613
1614 /* If name contains path separators then try it as a straight path. */
1615 if ((strchr(name, '/') || strchr(name, '\\'))
1616 && access(name, R_OK) == 0) {
Jean-Christophe DUBOIS73ffc802009-09-02 23:59:06 +02001617 return qemu_strdup(name);
Paul Brook5cea8592009-05-30 00:52:44 +01001618 }
1619 switch (type) {
1620 case QEMU_FILE_TYPE_BIOS:
1621 subdir = "";
1622 break;
1623 case QEMU_FILE_TYPE_KEYMAP:
1624 subdir = "keymaps/";
1625 break;
1626 default:
1627 abort();
1628 }
1629 len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
1630 buf = qemu_mallocz(len);
Blue Swirl3a417592009-06-09 19:12:21 +00001631 snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
Paul Brook5cea8592009-05-30 00:52:44 +01001632 if (access(buf, R_OK)) {
1633 qemu_free(buf);
1634 return NULL;
1635 }
1636 return buf;
1637}
1638
Markus Armbrusterff952ba2010-01-29 19:48:57 +01001639static int device_help_func(QemuOpts *opts, void *opaque)
1640{
1641 return qdev_device_help(opts);
1642}
1643
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02001644static int device_init_func(QemuOpts *opts, void *opaque)
1645{
1646 DeviceState *dev;
1647
1648 dev = qdev_device_add(opts);
1649 if (!dev)
1650 return -1;
1651 return 0;
1652}
1653
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01001654static int chardev_init_func(QemuOpts *opts, void *opaque)
1655{
1656 CharDriverState *chr;
1657
1658 chr = qemu_chr_open_opts(opts, NULL);
1659 if (!chr)
1660 return -1;
1661 return 0;
1662}
1663
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07001664#ifdef CONFIG_VIRTFS
Gautham R Shenoy74db9202010-04-29 17:44:43 +05301665static int fsdev_init_func(QemuOpts *opts, void *opaque)
1666{
1667 int ret;
1668 ret = qemu_fsdev_add(opts);
1669
1670 return ret;
1671}
1672#endif
1673
Gerd Hoffmann88589342009-12-08 13:11:50 +01001674static int mon_init_func(QemuOpts *opts, void *opaque)
1675{
1676 CharDriverState *chr;
1677 const char *chardev;
1678 const char *mode;
1679 int flags;
1680
1681 mode = qemu_opt_get(opts, "mode");
1682 if (mode == NULL) {
1683 mode = "readline";
1684 }
1685 if (strcmp(mode, "readline") == 0) {
1686 flags = MONITOR_USE_READLINE;
1687 } else if (strcmp(mode, "control") == 0) {
1688 flags = MONITOR_USE_CONTROL;
1689 } else {
1690 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
1691 exit(1);
1692 }
1693
Daniel P. Berrange39eaab92010-06-07 15:42:31 +01001694 if (qemu_opt_get_bool(opts, "pretty", 0))
1695 flags |= MONITOR_USE_PRETTY;
1696
Gerd Hoffmann88589342009-12-08 13:11:50 +01001697 if (qemu_opt_get_bool(opts, "default", 0))
1698 flags |= MONITOR_IS_DEFAULT;
1699
1700 chardev = qemu_opt_get(opts, "chardev");
1701 chr = qemu_chr_find(chardev);
1702 if (chr == NULL) {
1703 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
1704 exit(1);
1705 }
1706
1707 monitor_init(chr, flags);
1708 return 0;
1709}
1710
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01001711static void monitor_parse(const char *optarg, const char *mode)
Gerd Hoffmann88589342009-12-08 13:11:50 +01001712{
1713 static int monitor_device_index = 0;
1714 QemuOpts *opts;
1715 const char *p;
1716 char label[32];
1717 int def = 0;
1718
1719 if (strstart(optarg, "chardev:", &p)) {
1720 snprintf(label, sizeof(label), "%s", p);
1721 } else {
Jan Kiszka140e0652010-04-06 16:55:52 +02001722 snprintf(label, sizeof(label), "compat_monitor%d",
1723 monitor_device_index);
1724 if (monitor_device_index == 0) {
Gerd Hoffmann88589342009-12-08 13:11:50 +01001725 def = 1;
1726 }
1727 opts = qemu_chr_parse_compat(label, optarg);
1728 if (!opts) {
1729 fprintf(stderr, "parse error: %s\n", optarg);
1730 exit(1);
1731 }
1732 }
1733
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001734 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1);
Gerd Hoffmann88589342009-12-08 13:11:50 +01001735 if (!opts) {
1736 fprintf(stderr, "duplicate chardev: %s\n", label);
1737 exit(1);
1738 }
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01001739 qemu_opt_set(opts, "mode", mode);
Gerd Hoffmann88589342009-12-08 13:11:50 +01001740 qemu_opt_set(opts, "chardev", label);
1741 if (def)
1742 qemu_opt_set(opts, "default", "on");
1743 monitor_device_index++;
1744}
1745
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001746struct device_config {
1747 enum {
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001748 DEV_USB, /* -usbdevice */
1749 DEV_BT, /* -bt */
1750 DEV_SERIAL, /* -serial */
1751 DEV_PARALLEL, /* -parallel */
1752 DEV_VIRTCON, /* -virtioconsole */
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001753 DEV_DEBUGCON, /* -debugcon */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001754 } type;
1755 const char *cmdline;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001756 QTAILQ_ENTRY(device_config) next;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001757};
Blue Swirl72cf2d42009-09-12 07:36:22 +00001758QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001759
1760static void add_device_config(int type, const char *cmdline)
1761{
1762 struct device_config *conf;
1763
1764 conf = qemu_mallocz(sizeof(*conf));
1765 conf->type = type;
1766 conf->cmdline = cmdline;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001767 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001768}
1769
1770static int foreach_device_config(int type, int (*func)(const char *cmdline))
1771{
1772 struct device_config *conf;
1773 int rc;
1774
Blue Swirl72cf2d42009-09-12 07:36:22 +00001775 QTAILQ_FOREACH(conf, &device_configs, next) {
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001776 if (conf->type != type)
1777 continue;
1778 rc = func(conf->cmdline);
1779 if (0 != rc)
1780 return rc;
1781 }
1782 return 0;
1783}
1784
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01001785static int serial_parse(const char *devname)
1786{
1787 static int index = 0;
1788 char label[32];
1789
1790 if (strcmp(devname, "none") == 0)
1791 return 0;
1792 if (index == MAX_SERIAL_PORTS) {
1793 fprintf(stderr, "qemu: too many serial ports\n");
1794 exit(1);
1795 }
1796 snprintf(label, sizeof(label), "serial%d", index);
1797 serial_hds[index] = qemu_chr_open(label, devname, NULL);
1798 if (!serial_hds[index]) {
1799 fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
1800 devname, strerror(errno));
1801 return -1;
1802 }
1803 index++;
1804 return 0;
1805}
1806
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01001807static int parallel_parse(const char *devname)
1808{
1809 static int index = 0;
1810 char label[32];
1811
1812 if (strcmp(devname, "none") == 0)
1813 return 0;
1814 if (index == MAX_PARALLEL_PORTS) {
1815 fprintf(stderr, "qemu: too many parallel ports\n");
1816 exit(1);
1817 }
1818 snprintf(label, sizeof(label), "parallel%d", index);
1819 parallel_hds[index] = qemu_chr_open(label, devname, NULL);
1820 if (!parallel_hds[index]) {
1821 fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
1822 devname, strerror(errno));
1823 return -1;
1824 }
1825 index++;
1826 return 0;
1827}
1828
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001829static int virtcon_parse(const char *devname)
1830{
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001831 QemuOptsList *device = qemu_find_opts("device");
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001832 static int index = 0;
1833 char label[32];
Amit Shah392ecf52010-01-21 16:19:23 +05301834 QemuOpts *bus_opts, *dev_opts;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001835
1836 if (strcmp(devname, "none") == 0)
1837 return 0;
1838 if (index == MAX_VIRTIO_CONSOLES) {
1839 fprintf(stderr, "qemu: too many virtio consoles\n");
1840 exit(1);
1841 }
Amit Shah392ecf52010-01-21 16:19:23 +05301842
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001843 bus_opts = qemu_opts_create(device, NULL, 0);
Amit Shah392ecf52010-01-21 16:19:23 +05301844 qemu_opt_set(bus_opts, "driver", "virtio-serial");
1845
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001846 dev_opts = qemu_opts_create(device, NULL, 0);
Amit Shah392ecf52010-01-21 16:19:23 +05301847 qemu_opt_set(dev_opts, "driver", "virtconsole");
1848
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001849 snprintf(label, sizeof(label), "virtcon%d", index);
1850 virtcon_hds[index] = qemu_chr_open(label, devname, NULL);
1851 if (!virtcon_hds[index]) {
1852 fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
1853 devname, strerror(errno));
1854 return -1;
1855 }
Amit Shah392ecf52010-01-21 16:19:23 +05301856 qemu_opt_set(dev_opts, "chardev", label);
1857
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001858 index++;
1859 return 0;
1860}
1861
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001862static int debugcon_parse(const char *devname)
1863{
1864 QemuOpts *opts;
1865
1866 if (!qemu_chr_open("debugcon", devname, NULL)) {
1867 exit(1);
1868 }
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001869 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001870 if (!opts) {
1871 fprintf(stderr, "qemu: already have a debugcon device\n");
1872 exit(1);
1873 }
1874 qemu_opt_set(opts, "driver", "isa-debugcon");
1875 qemu_opt_set(opts, "chardev", "debugcon");
1876 return 0;
1877}
1878
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02001879void qemu_add_exit_notifier(Notifier *notify)
1880{
1881 notifier_list_add(&exit_notifiers, notify);
1882}
1883
1884void qemu_remove_exit_notifier(Notifier *notify)
1885{
1886 notifier_list_remove(&exit_notifiers, notify);
1887}
1888
1889static void qemu_run_exit_notifiers(void)
1890{
1891 notifier_list_notify(&exit_notifiers);
1892}
1893
Gleb Natapov4cab9462010-12-08 13:35:08 +02001894void qemu_add_machine_init_done_notifier(Notifier *notify)
1895{
1896 notifier_list_add(&machine_init_done_notifiers, notify);
1897}
1898
1899static void qemu_run_machine_init_done_notifiers(void)
1900{
1901 notifier_list_notify(&machine_init_done_notifiers);
1902}
1903
Anthony Liguori6530a972010-01-22 09:18:06 -06001904static const QEMUOption *lookup_opt(int argc, char **argv,
1905 const char **poptarg, int *poptind)
1906{
1907 const QEMUOption *popt;
1908 int optind = *poptind;
1909 char *r = argv[optind];
1910 const char *optarg;
1911
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001912 loc_set_cmdline(argv, optind, 1);
Anthony Liguori6530a972010-01-22 09:18:06 -06001913 optind++;
1914 /* Treat --foo the same as -foo. */
1915 if (r[1] == '-')
1916 r++;
1917 popt = qemu_options;
1918 for(;;) {
1919 if (!popt->name) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001920 error_report("invalid option");
Anthony Liguori6530a972010-01-22 09:18:06 -06001921 exit(1);
1922 }
1923 if (!strcmp(popt->name, r + 1))
1924 break;
1925 popt++;
1926 }
1927 if (popt->flags & HAS_ARG) {
1928 if (optind >= argc) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001929 error_report("requires an argument");
Anthony Liguori6530a972010-01-22 09:18:06 -06001930 exit(1);
1931 }
1932 optarg = argv[optind++];
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001933 loc_set_cmdline(argv, optind - 2, 2);
Anthony Liguori6530a972010-01-22 09:18:06 -06001934 } else {
1935 optarg = NULL;
1936 }
1937
1938 *poptarg = optarg;
1939 *poptind = optind;
1940
1941 return popt;
1942}
1943
malc902b3d52008-12-10 19:18:40 +00001944int main(int argc, char **argv, char **envp)
bellard0824d6f2003-06-24 13:42:40 +00001945{
aliguori59030a82009-04-05 18:43:41 +00001946 const char *gdbstub_dev = NULL;
thse4bcb142007-12-02 04:51:10 +00001947 int i;
Eduardo Habkostda1fcfd2010-04-06 19:22:07 -03001948 int snapshot, linux_boot;
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01001949 const char *icount_option = NULL;
bellard7f7f9872003-10-30 01:11:23 +00001950 const char *initrd_filename;
bellarda20dd502003-09-30 21:07:02 +00001951 const char *kernel_filename, *kernel_cmdline;
Anthony Liguori195325a2009-10-30 12:42:29 -05001952 char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
aliguori3023f332009-01-16 19:04:14 +00001953 DisplayState *ds;
aliguori7d957bd2009-01-15 22:14:11 +00001954 DisplayChangeListener *dcl;
bellard46d47672004-11-16 01:45:27 +00001955 int cyls, heads, secs, translation;
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02001956 QemuOpts *hda_opts = NULL, *opts;
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02001957 QemuOptsList *olist;
bellardcd6f1162004-05-13 22:02:20 +00001958 int optind;
Anthony Liguori6530a972010-01-22 09:18:06 -06001959 const char *optarg;
bellardd63d3072004-10-03 13:29:03 +00001960 const char *loadvm = NULL;
bellardcc1daa42005-06-05 14:49:17 +00001961 QEMUMachine *machine;
j_mayer94fc95c2007-03-05 19:44:02 +00001962 const char *cpu_model;
bellard26a5f132008-05-28 12:30:31 +00001963 int tb_size;
ths93815bc2007-03-19 15:58:31 +00001964 const char *pid_file = NULL;
aliguori5bb79102008-10-13 03:12:02 +00001965 const char *incoming = NULL;
Jes Sorensen821601e2011-03-16 13:33:36 +01001966#ifdef CONFIG_VNC
Anthony Liguori993fbfd2009-05-21 16:54:00 -05001967 int show_vnc_port = 0;
Jes Sorensen821601e2011-03-16 13:33:36 +01001968#endif
Anthony Liguori292444c2010-01-21 10:57:58 -06001969 int defconfig = 1;
Prerna Saxenaab6540d2010-08-09 11:48:32 +01001970 const char *trace_file = NULL;
Stefan Hajnoczi0b5538c2011-02-26 18:38:39 +00001971
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02001972 atexit(qemu_run_exit_notifiers);
Markus Armbruster65abca02010-02-24 14:37:14 +01001973 error_set_progname(argv[0]);
1974
Jan Kiszka68752042009-09-15 13:36:04 +02001975 init_clocks();
1976
malc902b3d52008-12-10 19:18:40 +00001977 qemu_cache_utils_init(envp);
1978
Blue Swirl72cf2d42009-09-12 07:36:22 +00001979 QLIST_INIT (&vm_change_state_head);
Jes Sorensenfe98ac12010-06-10 11:42:21 +02001980 os_setup_early_signal_handling();
bellardbe995c22006-06-25 16:25:21 +00001981
Anthony Liguorif80f9ec2009-05-20 18:38:09 -05001982 module_call_init(MODULE_INIT_MACHINE);
Anthony Liguori0c257432009-05-21 20:41:01 -05001983 machine = find_default_machine();
j_mayer94fc95c2007-03-05 19:44:02 +00001984 cpu_model = NULL;
bellardfc01f7e2003-06-30 10:03:06 +00001985 initrd_filename = NULL;
aurel324fc5d072008-04-27 21:39:40 +00001986 ram_size = 0;
bellard33e39632003-07-06 17:15:21 +00001987 snapshot = 0;
bellarda20dd502003-09-30 21:07:02 +00001988 kernel_filename = NULL;
1989 kernel_cmdline = "";
bellardc4b1fcc2004-03-14 21:44:30 +00001990 cyls = heads = secs = 0;
bellard46d47672004-11-16 01:45:27 +00001991 translation = BIOS_ATA_TRANSLATION_AUTO;
bellardc4b1fcc2004-03-14 21:44:30 +00001992
aliguori268a3622009-04-21 22:30:27 +00001993 for (i = 0; i < MAX_NODES; i++) {
1994 node_mem[i] = 0;
1995 node_cpumask[i] = 0;
1996 }
1997
aliguori268a3622009-04-21 22:30:27 +00001998 nb_numa_nodes = 0;
bellard7c9d8e02005-11-15 22:16:05 +00001999 nb_nics = 0;
ths3b46e622007-09-17 08:09:54 +00002000
bellard26a5f132008-05-28 12:30:31 +00002001 tb_size = 0;
blueswir141bd6392008-10-05 09:56:21 +00002002 autostart= 1;
2003
Anthony Liguori292444c2010-01-21 10:57:58 -06002004 /* first pass of option parsing */
2005 optind = 1;
2006 while (optind < argc) {
2007 if (argv[optind][0] != '-') {
2008 /* disk image */
Anthony Liguori28e68d62010-01-27 10:46:00 -06002009 optind++;
Anthony Liguori292444c2010-01-21 10:57:58 -06002010 continue;
2011 } else {
2012 const QEMUOption *popt;
2013
2014 popt = lookup_opt(argc, argv, &optarg, &optind);
2015 switch (popt->index) {
2016 case QEMU_OPTION_nodefconfig:
2017 defconfig=0;
2018 break;
2019 }
2020 }
2021 }
2022
2023 if (defconfig) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002024 int ret;
Markus Armbrustercf5a65a2010-02-18 19:48:33 +01002025
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002026 ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
Kevin Wolf019e78b2010-05-17 10:36:47 +02002027 if (ret < 0 && ret != -ENOENT) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002028 exit(1);
Anthony Liguori292444c2010-01-21 10:57:58 -06002029 }
2030
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002031 ret = qemu_read_config_file(arch_config_name);
Kevin Wolf019e78b2010-05-17 10:36:47 +02002032 if (ret < 0 && ret != -ENOENT) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002033 exit(1);
Anthony Liguori292444c2010-01-21 10:57:58 -06002034 }
2035 }
Blue Swirlde06f8d2010-03-29 19:23:50 +00002036 cpudef_init();
Anthony Liguori292444c2010-01-21 10:57:58 -06002037
2038 /* second pass of option parsing */
bellardcd6f1162004-05-13 22:02:20 +00002039 optind = 1;
bellard0824d6f2003-06-24 13:42:40 +00002040 for(;;) {
bellardcd6f1162004-05-13 22:02:20 +00002041 if (optind >= argc)
bellard0824d6f2003-06-24 13:42:40 +00002042 break;
Anthony Liguori6530a972010-01-22 09:18:06 -06002043 if (argv[optind][0] != '-') {
Markus Armbruster2292dda2011-01-28 11:21:41 +01002044 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
bellardcd6f1162004-05-13 22:02:20 +00002045 } else {
2046 const QEMUOption *popt;
2047
Anthony Liguori6530a972010-01-22 09:18:06 -06002048 popt = lookup_opt(argc, argv, &optarg, &optind);
Blue Swirlad960902010-03-29 19:23:52 +00002049 if (!(popt->arch_mask & arch_type)) {
2050 printf("Option %s not supported for this target\n", popt->name);
2051 exit(1);
2052 }
bellardcd6f1162004-05-13 22:02:20 +00002053 switch(popt->index) {
bellardcc1daa42005-06-05 14:49:17 +00002054 case QEMU_OPTION_M:
2055 machine = find_machine(optarg);
2056 if (!machine) {
2057 QEMUMachine *m;
2058 printf("Supported machines are:\n");
2059 for(m = first_machine; m != NULL; m = m->next) {
Mark McLoughlin3f6599e2009-07-22 10:02:50 +01002060 if (m->alias)
2061 printf("%-10s %s (alias of %s)\n",
2062 m->alias, m->desc, m->name);
bellardcc1daa42005-06-05 14:49:17 +00002063 printf("%-10s %s%s\n",
ths5fafdf22007-09-16 21:08:06 +00002064 m->name, m->desc,
Anthony Liguori0c257432009-05-21 20:41:01 -05002065 m->is_default ? " (default)" : "");
bellardcc1daa42005-06-05 14:49:17 +00002066 }
ths15f82202007-06-29 23:26:08 +00002067 exit(*optarg != '?');
bellardcc1daa42005-06-05 14:49:17 +00002068 }
2069 break;
j_mayer94fc95c2007-03-05 19:44:02 +00002070 case QEMU_OPTION_cpu:
2071 /* hw initialization will check this */
ths15f82202007-06-29 23:26:08 +00002072 if (*optarg == '?') {
Blue Swirl262353c2010-05-04 19:55:35 +00002073 list_cpus(stdout, &fprintf, optarg);
ths15f82202007-06-29 23:26:08 +00002074 exit(0);
j_mayer94fc95c2007-03-05 19:44:02 +00002075 } else {
2076 cpu_model = optarg;
2077 }
2078 break;
bellardcd6f1162004-05-13 22:02:20 +00002079 case QEMU_OPTION_initrd:
bellardfc01f7e2003-06-30 10:03:06 +00002080 initrd_filename = optarg;
2081 break;
bellardcd6f1162004-05-13 22:02:20 +00002082 case QEMU_OPTION_hda:
Markus Armbruster5645b0f2011-01-31 11:50:09 +01002083 {
2084 char buf[256];
2085 if (cyls == 0)
2086 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2087 else
2088 snprintf(buf, sizeof(buf),
2089 "%s,cyls=%d,heads=%d,secs=%d%s",
2090 HD_OPTS , cyls, heads, secs,
2091 translation == BIOS_ATA_TRANSLATION_LBA ?
thse4bcb142007-12-02 04:51:10 +00002092 ",trans=lba" :
Markus Armbruster5645b0f2011-01-31 11:50:09 +01002093 translation == BIOS_ATA_TRANSLATION_NONE ?
thse4bcb142007-12-02 04:51:10 +00002094 ",trans=none" : "");
Markus Armbruster5645b0f2011-01-31 11:50:09 +01002095 drive_add(IF_DEFAULT, 0, optarg, buf);
2096 break;
2097 }
bellardcd6f1162004-05-13 22:02:20 +00002098 case QEMU_OPTION_hdb:
bellardcc1daa42005-06-05 14:49:17 +00002099 case QEMU_OPTION_hdc:
2100 case QEMU_OPTION_hdd:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002101 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2102 HD_OPTS);
bellardfc01f7e2003-06-30 10:03:06 +00002103 break;
thse4bcb142007-12-02 04:51:10 +00002104 case QEMU_OPTION_drive:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002105 drive_def(optarg);
thse4bcb142007-12-02 04:51:10 +00002106 break;
Gerd Hoffmannd058fe02009-07-31 12:25:36 +02002107 case QEMU_OPTION_set:
2108 if (qemu_set_option(optarg) != 0)
2109 exit(1);
2110 break;
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01002111 case QEMU_OPTION_global:
2112 if (qemu_global_option(optarg) != 0)
2113 exit(1);
2114 break;
balrog3e3d5812007-04-30 02:09:25 +00002115 case QEMU_OPTION_mtdblock:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002116 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
balrog3e3d5812007-04-30 02:09:25 +00002117 break;
pbrooka1bb27b2007-04-06 16:49:48 +00002118 case QEMU_OPTION_sd:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002119 drive_add(IF_SD, 0, optarg, SD_OPTS);
pbrooka1bb27b2007-04-06 16:49:48 +00002120 break;
j_mayer86f55662007-04-24 06:52:59 +00002121 case QEMU_OPTION_pflash:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002122 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
j_mayer86f55662007-04-24 06:52:59 +00002123 break;
bellardcd6f1162004-05-13 22:02:20 +00002124 case QEMU_OPTION_snapshot:
bellard33e39632003-07-06 17:15:21 +00002125 snapshot = 1;
2126 break;
bellardcd6f1162004-05-13 22:02:20 +00002127 case QEMU_OPTION_hdachs:
bellard330d0412003-07-26 18:11:40 +00002128 {
bellard330d0412003-07-26 18:11:40 +00002129 const char *p;
2130 p = optarg;
2131 cyls = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002132 if (cyls < 1 || cyls > 16383)
2133 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00002134 if (*p != ',')
2135 goto chs_fail;
2136 p++;
2137 heads = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002138 if (heads < 1 || heads > 16)
2139 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00002140 if (*p != ',')
2141 goto chs_fail;
2142 p++;
2143 secs = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002144 if (secs < 1 || secs > 63)
2145 goto chs_fail;
2146 if (*p == ',') {
2147 p++;
2148 if (!strcmp(p, "none"))
2149 translation = BIOS_ATA_TRANSLATION_NONE;
2150 else if (!strcmp(p, "lba"))
2151 translation = BIOS_ATA_TRANSLATION_LBA;
2152 else if (!strcmp(p, "auto"))
2153 translation = BIOS_ATA_TRANSLATION_AUTO;
2154 else
2155 goto chs_fail;
2156 } else if (*p != '\0') {
bellardc4b1fcc2004-03-14 21:44:30 +00002157 chs_fail:
bellard46d47672004-11-16 01:45:27 +00002158 fprintf(stderr, "qemu: invalid physical CHS format\n");
2159 exit(1);
bellardc4b1fcc2004-03-14 21:44:30 +00002160 }
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02002161 if (hda_opts != NULL) {
2162 char num[16];
2163 snprintf(num, sizeof(num), "%d", cyls);
2164 qemu_opt_set(hda_opts, "cyls", num);
2165 snprintf(num, sizeof(num), "%d", heads);
2166 qemu_opt_set(hda_opts, "heads", num);
2167 snprintf(num, sizeof(num), "%d", secs);
2168 qemu_opt_set(hda_opts, "secs", num);
2169 if (translation == BIOS_ATA_TRANSLATION_LBA)
2170 qemu_opt_set(hda_opts, "trans", "lba");
2171 if (translation == BIOS_ATA_TRANSLATION_NONE)
2172 qemu_opt_set(hda_opts, "trans", "none");
2173 }
bellard330d0412003-07-26 18:11:40 +00002174 }
2175 break;
aliguori268a3622009-04-21 22:30:27 +00002176 case QEMU_OPTION_numa:
2177 if (nb_numa_nodes >= MAX_NODES) {
2178 fprintf(stderr, "qemu: too many NUMA nodes\n");
2179 exit(1);
2180 }
2181 numa_add(optarg);
2182 break;
Jes Sorensen1472a952011-03-16 13:33:31 +01002183 case QEMU_OPTION_display:
2184 display_type = select_display(optarg);
2185 break;
bellardcd6f1162004-05-13 22:02:20 +00002186 case QEMU_OPTION_nographic:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002187 display_type = DT_NOGRAPHIC;
bellarda20dd502003-09-30 21:07:02 +00002188 break;
balrog4d3b6f62008-02-10 16:33:14 +00002189 case QEMU_OPTION_curses:
Jes Sorensen47b05362011-03-16 13:33:35 +01002190#ifdef CONFIG_CURSES
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002191 display_type = DT_CURSES;
Jes Sorensen47b05362011-03-16 13:33:35 +01002192#else
2193 fprintf(stderr, "Curses support is disabled\n");
2194 exit(1);
balrog4d3b6f62008-02-10 16:33:14 +00002195#endif
Jes Sorensen47b05362011-03-16 13:33:35 +01002196 break;
balroga171fe32007-04-30 01:48:07 +00002197 case QEMU_OPTION_portrait:
2198 graphic_rotate = 1;
2199 break;
bellardcd6f1162004-05-13 22:02:20 +00002200 case QEMU_OPTION_kernel:
bellarda20dd502003-09-30 21:07:02 +00002201 kernel_filename = optarg;
2202 break;
bellardcd6f1162004-05-13 22:02:20 +00002203 case QEMU_OPTION_append:
bellarda20dd502003-09-30 21:07:02 +00002204 kernel_cmdline = optarg;
bellard313aa562003-08-10 21:52:11 +00002205 break;
bellardcd6f1162004-05-13 22:02:20 +00002206 case QEMU_OPTION_cdrom:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002207 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
bellard36b486b2003-11-11 13:36:08 +00002208 break;
bellardcd6f1162004-05-13 22:02:20 +00002209 case QEMU_OPTION_boot:
j_mayer28c5af52007-11-11 01:50:45 +00002210 {
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002211 static const char * const params[] = {
Jan Kiszka95387492009-07-02 00:19:02 +02002212 "order", "once", "menu", NULL
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002213 };
2214 char buf[sizeof(boot_devices)];
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002215 char *standard_boot_devices;
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002216 int legacy = 0;
2217
2218 if (!strchr(optarg, '=')) {
2219 legacy = 1;
2220 pstrcpy(buf, sizeof(buf), optarg);
2221 } else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
2222 fprintf(stderr,
2223 "qemu: unknown boot parameter '%s' in '%s'\n",
2224 buf, optarg);
2225 exit(1);
2226 }
2227
2228 if (legacy ||
2229 get_param_value(buf, sizeof(buf), "order", optarg)) {
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -03002230 validate_bootdevices(buf);
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002231 pstrcpy(boot_devices, sizeof(boot_devices), buf);
j_mayer28c5af52007-11-11 01:50:45 +00002232 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002233 if (!legacy) {
2234 if (get_param_value(buf, sizeof(buf),
2235 "once", optarg)) {
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -03002236 validate_bootdevices(buf);
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002237 standard_boot_devices = qemu_strdup(boot_devices);
2238 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2239 qemu_register_reset(restore_boot_devices,
2240 standard_boot_devices);
2241 }
Jan Kiszka95387492009-07-02 00:19:02 +02002242 if (get_param_value(buf, sizeof(buf),
2243 "menu", optarg)) {
2244 if (!strcmp(buf, "on")) {
2245 boot_menu = 1;
2246 } else if (!strcmp(buf, "off")) {
2247 boot_menu = 0;
2248 } else {
2249 fprintf(stderr,
2250 "qemu: invalid option value '%s'\n",
2251 buf);
2252 exit(1);
2253 }
2254 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002255 }
bellard36b486b2003-11-11 13:36:08 +00002256 }
2257 break;
bellardcd6f1162004-05-13 22:02:20 +00002258 case QEMU_OPTION_fda:
bellardcd6f1162004-05-13 22:02:20 +00002259 case QEMU_OPTION_fdb:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002260 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2261 optarg, FD_OPTS);
bellardc45886d2004-01-05 00:02:06 +00002262 break;
bellard52ca8d62006-06-14 16:03:05 +00002263 case QEMU_OPTION_no_fd_bootchk:
2264 fd_bootchk = 0;
2265 break;
Mark McLoughlina1ea4582009-10-08 19:58:26 +01002266 case QEMU_OPTION_netdev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002267 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
Mark McLoughlina1ea4582009-10-08 19:58:26 +01002268 exit(1);
2269 }
2270 break;
bellard7c9d8e02005-11-15 22:16:05 +00002271 case QEMU_OPTION_net:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002272 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
bellardc4b1fcc2004-03-14 21:44:30 +00002273 exit(1);
2274 }
bellard702c6512004-04-02 21:21:32 +00002275 break;
bellardc7f74642004-08-24 21:57:12 +00002276#ifdef CONFIG_SLIRP
2277 case QEMU_OPTION_tftp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02002278 legacy_tftp_prefix = optarg;
bellard9bf05442004-08-25 22:12:49 +00002279 break;
ths47d5d012007-02-20 00:05:08 +00002280 case QEMU_OPTION_bootp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02002281 legacy_bootp_filename = optarg;
ths47d5d012007-02-20 00:05:08 +00002282 break;
bellard9bf05442004-08-25 22:12:49 +00002283 case QEMU_OPTION_redir:
Markus Armbruster07527062009-10-06 12:16:57 +01002284 if (net_slirp_redir(optarg) < 0)
2285 exit(1);
bellard9bf05442004-08-25 22:12:49 +00002286 break;
bellardc7f74642004-08-24 21:57:12 +00002287#endif
balrogdc72ac12008-11-09 00:04:26 +00002288 case QEMU_OPTION_bt:
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002289 add_device_config(DEV_BT, optarg);
balrogdc72ac12008-11-09 00:04:26 +00002290 break;
bellard1d14ffa2005-10-30 18:58:22 +00002291 case QEMU_OPTION_audio_help:
Blue Swirlad960902010-03-29 19:23:52 +00002292 if (!(audio_available())) {
2293 printf("Option %s not supported for this target\n", popt->name);
2294 exit(1);
2295 }
bellard1d14ffa2005-10-30 18:58:22 +00002296 AUD_help ();
2297 exit (0);
2298 break;
2299 case QEMU_OPTION_soundhw:
Blue Swirlad960902010-03-29 19:23:52 +00002300 if (!(audio_available())) {
2301 printf("Option %s not supported for this target\n", popt->name);
2302 exit(1);
2303 }
bellard1d14ffa2005-10-30 18:58:22 +00002304 select_soundhw (optarg);
2305 break;
bellardcd6f1162004-05-13 22:02:20 +00002306 case QEMU_OPTION_h:
ths15f82202007-06-29 23:26:08 +00002307 help(0);
bellardcd6f1162004-05-13 22:02:20 +00002308 break;
pbrook9bd7e6d2009-04-07 22:58:45 +00002309 case QEMU_OPTION_version:
2310 version();
2311 exit(0);
2312 break;
aurel3200f82b82008-04-27 21:12:55 +00002313 case QEMU_OPTION_m: {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +01002314 int64_t value;
aurel3200f82b82008-04-27 21:12:55 +00002315
Jes Sorensen9f9b17a2010-10-21 17:15:46 +02002316 value = strtosz(optarg, NULL);
2317 if (value < 0) {
aurel3200f82b82008-04-27 21:12:55 +00002318 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
bellardcd6f1162004-05-13 22:02:20 +00002319 exit(1);
2320 }
aurel3200f82b82008-04-27 21:12:55 +00002321
2322 /* On 32-bit hosts, QEMU is limited by virtual address space */
Anthony Liguori4a1418e2009-08-10 17:07:24 -05002323 if (value > (2047 << 20) && HOST_LONG_BITS == 32) {
aurel3200f82b82008-04-27 21:12:55 +00002324 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
2325 exit(1);
2326 }
Anthony Liguoric227f092009-10-01 16:12:16 -05002327 if (value != (uint64_t)(ram_addr_t)value) {
aurel3200f82b82008-04-27 21:12:55 +00002328 fprintf(stderr, "qemu: ram size too large\n");
2329 exit(1);
2330 }
2331 ram_size = value;
bellardcd6f1162004-05-13 22:02:20 +00002332 break;
aurel3200f82b82008-04-27 21:12:55 +00002333 }
Marcelo Tosattic9027602010-03-01 20:25:08 -03002334 case QEMU_OPTION_mempath:
2335 mem_path = optarg;
2336 break;
2337#ifdef MAP_POPULATE
2338 case QEMU_OPTION_mem_prealloc:
2339 mem_prealloc = 1;
2340 break;
2341#endif
bellardcd6f1162004-05-13 22:02:20 +00002342 case QEMU_OPTION_d:
Blue Swirlde06f8d2010-03-29 19:23:50 +00002343 set_cpu_log(optarg);
bellardcd6f1162004-05-13 22:02:20 +00002344 break;
bellardcd6f1162004-05-13 22:02:20 +00002345 case QEMU_OPTION_s:
aliguori59030a82009-04-05 18:43:41 +00002346 gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT;
bellardcd6f1162004-05-13 22:02:20 +00002347 break;
aliguori59030a82009-04-05 18:43:41 +00002348 case QEMU_OPTION_gdb:
2349 gdbstub_dev = optarg;
bellardcd6f1162004-05-13 22:02:20 +00002350 break;
bellardcd6f1162004-05-13 22:02:20 +00002351 case QEMU_OPTION_L:
Paul Brook5cea8592009-05-30 00:52:44 +01002352 data_dir = optarg;
bellardcd6f1162004-05-13 22:02:20 +00002353 break;
j_mayer1192dad2007-10-05 13:08:35 +00002354 case QEMU_OPTION_bios:
2355 bios_name = optarg;
2356 break;
aurel321b530a62009-04-05 20:08:59 +00002357 case QEMU_OPTION_singlestep:
2358 singlestep = 1;
2359 break;
bellardcd6f1162004-05-13 22:02:20 +00002360 case QEMU_OPTION_S:
pbrook3c07f8e2007-01-21 16:47:01 +00002361 autostart = 0;
bellardcd6f1162004-05-13 22:02:20 +00002362 break;
bellard3d11d0e2004-12-12 16:56:30 +00002363 case QEMU_OPTION_k:
2364 keyboard_layout = optarg;
2365 break;
bellardee22c2f2004-06-03 12:49:50 +00002366 case QEMU_OPTION_localtime:
2367 rtc_utc = 0;
2368 break;
malc3893c122008-09-28 00:42:05 +00002369 case QEMU_OPTION_vga:
2370 select_vgahw (optarg);
bellard1bfe8562004-07-08 21:17:50 +00002371 break;
bellarde9b137c2004-06-21 16:46:10 +00002372 case QEMU_OPTION_g:
2373 {
2374 const char *p;
2375 int w, h, depth;
2376 p = optarg;
2377 w = strtol(p, (char **)&p, 10);
2378 if (w <= 0) {
2379 graphic_error:
2380 fprintf(stderr, "qemu: invalid resolution or depth\n");
2381 exit(1);
2382 }
2383 if (*p != 'x')
2384 goto graphic_error;
2385 p++;
2386 h = strtol(p, (char **)&p, 10);
2387 if (h <= 0)
2388 goto graphic_error;
2389 if (*p == 'x') {
2390 p++;
2391 depth = strtol(p, (char **)&p, 10);
ths5fafdf22007-09-16 21:08:06 +00002392 if (depth != 8 && depth != 15 && depth != 16 &&
bellarde9b137c2004-06-21 16:46:10 +00002393 depth != 24 && depth != 32)
2394 goto graphic_error;
2395 } else if (*p == '\0') {
2396 depth = graphic_depth;
2397 } else {
2398 goto graphic_error;
2399 }
ths3b46e622007-09-17 08:09:54 +00002400
bellarde9b137c2004-06-21 16:46:10 +00002401 graphic_width = w;
2402 graphic_height = h;
2403 graphic_depth = depth;
2404 }
2405 break;
ths20d8a3e2007-02-18 17:04:49 +00002406 case QEMU_OPTION_echr:
2407 {
2408 char *r;
2409 term_escape_char = strtol(optarg, &r, 0);
2410 if (r == optarg)
2411 printf("Bad argument to echr\n");
2412 break;
2413 }
bellard82c643f2004-07-14 17:28:13 +00002414 case QEMU_OPTION_monitor:
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002415 monitor_parse(optarg, "readline");
2416 default_monitor = 0;
2417 break;
2418 case QEMU_OPTION_qmp:
2419 monitor_parse(optarg, "control");
Anthony Liguori2d114dc2010-03-21 14:14:38 -05002420 default_monitor = 0;
bellard82c643f2004-07-14 17:28:13 +00002421 break;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002422 case QEMU_OPTION_mon:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002423 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002424 if (!opts) {
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002425 exit(1);
2426 }
Anthony Liguori2d114dc2010-03-21 14:14:38 -05002427 default_monitor = 0;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002428 break;
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002429 case QEMU_OPTION_chardev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002430 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002431 if (!opts) {
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002432 exit(1);
2433 }
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002434 break;
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302435 case QEMU_OPTION_fsdev:
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002436 olist = qemu_find_opts("fsdev");
2437 if (!olist) {
2438 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
2439 exit(1);
2440 }
2441 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302442 if (!opts) {
2443 fprintf(stderr, "parse error: %s\n", optarg);
2444 exit(1);
2445 }
2446 break;
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302447 case QEMU_OPTION_virtfs: {
2448 char *arg_fsdev = NULL;
2449 char *arg_9p = NULL;
2450 int len = 0;
2451
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002452 olist = qemu_find_opts("virtfs");
2453 if (!olist) {
2454 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
2455 exit(1);
2456 }
2457 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302458 if (!opts) {
2459 fprintf(stderr, "parse error: %s\n", optarg);
2460 exit(1);
2461 }
2462
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07002463 if (qemu_opt_get(opts, "fstype") == NULL ||
2464 qemu_opt_get(opts, "mount_tag") == NULL ||
2465 qemu_opt_get(opts, "path") == NULL ||
2466 qemu_opt_get(opts, "security_model") == NULL) {
2467 fprintf(stderr, "Usage: -virtfs fstype,path=/share_path/,"
Aneesh Kumar K.V12848bf2010-09-02 11:09:07 +05302468 "security_model=[mapped|passthrough|none],"
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07002469 "mnt_tag=tag.\n");
2470 exit(1);
2471 }
2472
2473 len = strlen(",id=,path=,security_model=");
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302474 len += strlen(qemu_opt_get(opts, "fstype"));
2475 len += strlen(qemu_opt_get(opts, "mount_tag"));
2476 len += strlen(qemu_opt_get(opts, "path"));
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07002477 len += strlen(qemu_opt_get(opts, "security_model"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302478 arg_fsdev = qemu_malloc((len + 1) * sizeof(*arg_fsdev));
2479
Aneesh Kumar K.Vc93031e2010-09-02 21:47:59 +05302480 snprintf(arg_fsdev, (len + 1) * sizeof(*arg_fsdev),
Blue Swirlcb93bbd2010-08-31 20:16:59 +00002481 "%s,id=%s,path=%s,security_model=%s",
2482 qemu_opt_get(opts, "fstype"),
2483 qemu_opt_get(opts, "mount_tag"),
2484 qemu_opt_get(opts, "path"),
2485 qemu_opt_get(opts, "security_model"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302486
Alexander Graf29f82b32011-03-29 15:29:29 +02002487 len = strlen("virtio-9p,fsdev=,mount_tag=");
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302488 len += 2*strlen(qemu_opt_get(opts, "mount_tag"));
2489 arg_9p = qemu_malloc((len + 1) * sizeof(*arg_9p));
2490
Aneesh Kumar K.Vc93031e2010-09-02 21:47:59 +05302491 snprintf(arg_9p, (len + 1) * sizeof(*arg_9p),
Alexander Graf29f82b32011-03-29 15:29:29 +02002492 "virtio-9p,fsdev=%s,mount_tag=%s",
Blue Swirlcb93bbd2010-08-31 20:16:59 +00002493 qemu_opt_get(opts, "mount_tag"),
2494 qemu_opt_get(opts, "mount_tag"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302495
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002496 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev, 1)) {
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302497 fprintf(stderr, "parse error [fsdev]: %s\n", optarg);
2498 exit(1);
2499 }
2500
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002501 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p, 1)) {
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302502 fprintf(stderr, "parse error [device]: %s\n", optarg);
2503 exit(1);
2504 }
2505
2506 qemu_free(arg_fsdev);
2507 qemu_free(arg_9p);
2508 break;
2509 }
bellard82c643f2004-07-14 17:28:13 +00002510 case QEMU_OPTION_serial:
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002511 add_device_config(DEV_SERIAL, optarg);
2512 default_serial = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01002513 if (strncmp(optarg, "mon:", 4) == 0) {
2514 default_monitor = 0;
2515 }
bellard82c643f2004-07-14 17:28:13 +00002516 break;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01002517 case QEMU_OPTION_watchdog:
Markus Armbruster09aaa162009-08-21 10:31:34 +02002518 if (watchdog) {
2519 fprintf(stderr,
2520 "qemu: only one watchdog option may be given\n");
2521 return 1;
2522 }
2523 watchdog = optarg;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01002524 break;
2525 case QEMU_OPTION_watchdog_action:
2526 if (select_watchdog_action(optarg) == -1) {
2527 fprintf(stderr, "Unknown -watchdog-action parameter\n");
2528 exit(1);
2529 }
2530 break;
aliguori51ecf132009-01-15 20:06:40 +00002531 case QEMU_OPTION_virtiocon:
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002532 add_device_config(DEV_VIRTCON, optarg);
2533 default_virtcon = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01002534 if (strncmp(optarg, "mon:", 4) == 0) {
2535 default_monitor = 0;
2536 }
aliguori51ecf132009-01-15 20:06:40 +00002537 break;
bellard6508fe52005-01-15 12:02:56 +00002538 case QEMU_OPTION_parallel:
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002539 add_device_config(DEV_PARALLEL, optarg);
2540 default_parallel = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01002541 if (strncmp(optarg, "mon:", 4) == 0) {
2542 default_monitor = 0;
2543 }
bellard6508fe52005-01-15 12:02:56 +00002544 break;
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002545 case QEMU_OPTION_debugcon:
2546 add_device_config(DEV_DEBUGCON, optarg);
2547 break;
bellardd63d3072004-10-03 13:29:03 +00002548 case QEMU_OPTION_loadvm:
2549 loadvm = optarg;
2550 break;
2551 case QEMU_OPTION_full_screen:
2552 full_screen = 1;
2553 break;
ths667acca2006-12-11 02:08:05 +00002554#ifdef CONFIG_SDL
ths43523e92007-02-18 18:19:32 +00002555 case QEMU_OPTION_no_frame:
2556 no_frame = 1;
2557 break;
ths3780e192007-06-21 21:08:02 +00002558 case QEMU_OPTION_alt_grab:
2559 alt_grab = 1;
2560 break;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -05002561 case QEMU_OPTION_ctrl_grab:
2562 ctrl_grab = 1;
2563 break;
ths667acca2006-12-11 02:08:05 +00002564 case QEMU_OPTION_no_quit:
2565 no_quit = 1;
2566 break;
aliguori7d957bd2009-01-15 22:14:11 +00002567 case QEMU_OPTION_sdl:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002568 display_type = DT_SDL;
aliguori7d957bd2009-01-15 22:14:11 +00002569 break;
Jes Sorensen58fc0962011-03-16 13:33:34 +01002570#else
2571 case QEMU_OPTION_no_frame:
2572 case QEMU_OPTION_alt_grab:
2573 case QEMU_OPTION_ctrl_grab:
2574 case QEMU_OPTION_no_quit:
2575 case QEMU_OPTION_sdl:
2576 fprintf(stderr, "SDL support is disabled\n");
2577 exit(1);
ths667acca2006-12-11 02:08:05 +00002578#endif
bellardf7cce892004-12-08 22:21:25 +00002579 case QEMU_OPTION_pidfile:
ths93815bc2007-03-19 15:58:31 +00002580 pid_file = optarg;
bellardf7cce892004-12-08 22:21:25 +00002581 break;
bellarda09db212005-04-30 16:10:35 +00002582 case QEMU_OPTION_win2k_hack:
2583 win2k_install_hack = 1;
2584 break;
aliguori73822ec2009-01-15 20:11:34 +00002585 case QEMU_OPTION_rtc_td_hack:
2586 rtc_td_hack = 1;
2587 break;
aliguori8a92ea22009-02-27 20:12:36 +00002588 case QEMU_OPTION_acpitable:
Blue Swirlde06f8d2010-03-29 19:23:50 +00002589 do_acpitable_option(optarg);
aliguori8a92ea22009-02-27 20:12:36 +00002590 break;
aliguorib6f6e3d2009-04-17 18:59:56 +00002591 case QEMU_OPTION_smbios:
Blue Swirlde06f8d2010-03-29 19:23:50 +00002592 do_smbios_option(optarg);
aliguorib6f6e3d2009-04-17 18:59:56 +00002593 break;
aliguori7ba1e612008-11-05 16:04:33 +00002594 case QEMU_OPTION_enable_kvm:
2595 kvm_allowed = 1;
aliguori7ba1e612008-11-05 16:04:33 +00002596 break;
bellardbb36d472005-11-05 14:22:28 +00002597 case QEMU_OPTION_usb:
2598 usb_enabled = 1;
2599 break;
bellarda594cfb2005-11-06 16:13:29 +00002600 case QEMU_OPTION_usbdevice:
2601 usb_enabled = 1;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002602 add_device_config(DEV_USB, optarg);
2603 break;
2604 case QEMU_OPTION_device:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002605 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02002606 exit(1);
2607 }
bellarda594cfb2005-11-06 16:13:29 +00002608 break;
bellard6a00d602005-11-21 23:25:50 +00002609 case QEMU_OPTION_smp:
Andre Przywaradc6b1c02009-08-19 15:42:40 +02002610 smp_parse(optarg);
aliguorib2097002008-10-07 20:39:39 +00002611 if (smp_cpus < 1) {
bellard6a00d602005-11-21 23:25:50 +00002612 fprintf(stderr, "Invalid number of CPUs\n");
2613 exit(1);
2614 }
Jes Sorensen6be68d72009-07-23 17:03:42 +02002615 if (max_cpus < smp_cpus) {
2616 fprintf(stderr, "maxcpus must be equal to or greater than "
2617 "smp\n");
2618 exit(1);
2619 }
2620 if (max_cpus > 255) {
2621 fprintf(stderr, "Unsupported number of maxcpus\n");
2622 exit(1);
2623 }
bellard6a00d602005-11-21 23:25:50 +00002624 break;
bellard24236862006-04-30 21:28:36 +00002625 case QEMU_OPTION_vnc:
Jes Sorensen821601e2011-03-16 13:33:36 +01002626#ifdef CONFIG_VNC
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02002627 display_remote++;
Jes Sorensen821601e2011-03-16 13:33:36 +01002628 vnc_display = optarg;
2629#else
2630 fprintf(stderr, "VNC support is disabled\n");
2631 exit(1);
2632#endif
2633 break;
bellard6515b202006-05-03 22:02:44 +00002634 case QEMU_OPTION_no_acpi:
2635 acpi_enabled = 0;
2636 break;
aliguori16b29ae2008-12-17 23:28:44 +00002637 case QEMU_OPTION_no_hpet:
2638 no_hpet = 1;
2639 break;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02002640 case QEMU_OPTION_balloon:
2641 if (balloon_parse(optarg) < 0) {
2642 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
2643 exit(1);
2644 }
Eduardo Habkostdf97b922009-06-10 16:34:08 -03002645 break;
bellardd1beab82006-10-02 19:44:22 +00002646 case QEMU_OPTION_no_reboot:
2647 no_reboot = 1;
2648 break;
aurel32b2f76162008-04-11 21:35:52 +00002649 case QEMU_OPTION_no_shutdown:
2650 no_shutdown = 1;
2651 break;
balrog9467cd42007-05-01 01:34:14 +00002652 case QEMU_OPTION_show_cursor:
2653 cursor_hide = 0;
2654 break;
blueswir18fcb1b92008-09-18 18:29:08 +00002655 case QEMU_OPTION_uuid:
2656 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
2657 fprintf(stderr, "Fail to parse UUID string."
2658 " Wrong format.\n");
2659 exit(1);
2660 }
2661 break;
ths9ae02552007-01-05 17:39:04 +00002662 case QEMU_OPTION_option_rom:
2663 if (nb_option_roms >= MAX_OPTION_ROMS) {
2664 fprintf(stderr, "Too many option ROMs\n");
2665 exit(1);
2666 }
Gleb Natapov2e55e842010-12-08 13:35:07 +02002667 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
2668 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
2669 option_rom[nb_option_roms].bootindex =
2670 qemu_opt_get_number(opts, "bootindex", -1);
2671 if (!option_rom[nb_option_roms].name) {
2672 fprintf(stderr, "Option ROM file is not specified\n");
2673 exit(1);
2674 }
ths9ae02552007-01-05 17:39:04 +00002675 nb_option_roms++;
2676 break;
pbrook8e716212007-01-20 17:12:09 +00002677 case QEMU_OPTION_semihosting:
2678 semihosting_enabled = 1;
2679 break;
thsc35734b2007-03-19 15:17:08 +00002680 case QEMU_OPTION_name:
Andi Kleen18894652009-07-02 09:34:17 +02002681 qemu_name = qemu_strdup(optarg);
2682 {
2683 char *p = strchr(qemu_name, ',');
2684 if (p != NULL) {
2685 *p++ = 0;
2686 if (strncmp(p, "process=", 8)) {
Aurelien Jarno5697f6a2010-12-27 18:29:20 +01002687 fprintf(stderr, "Unknown subargument %s to -name\n", p);
Andi Kleen18894652009-07-02 09:34:17 +02002688 exit(1);
2689 }
2690 p += 8;
Jes Sorensence798cf2010-06-10 11:42:31 +02002691 os_set_proc_name(p);
Andi Kleen18894652009-07-02 09:34:17 +02002692 }
2693 }
thsc35734b2007-03-19 15:17:08 +00002694 break;
blueswir166508602007-05-01 14:16:52 +00002695 case QEMU_OPTION_prom_env:
2696 if (nb_prom_envs >= MAX_PROM_ENVS) {
2697 fprintf(stderr, "Too many prom variables\n");
2698 exit(1);
2699 }
2700 prom_envs[nb_prom_envs] = optarg;
2701 nb_prom_envs++;
2702 break;
balrog2b8f2d42007-07-27 22:08:46 +00002703 case QEMU_OPTION_old_param:
2704 old_param = 1;
ths05ebd532008-01-08 19:32:16 +00002705 break;
thsf3dcfad2007-08-24 01:26:02 +00002706 case QEMU_OPTION_clock:
2707 configure_alarms(optarg);
2708 break;
bellard7e0af5d02007-11-07 16:24:33 +00002709 case QEMU_OPTION_startdate:
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002710 configure_rtc_date_offset(optarg, 1);
2711 break;
2712 case QEMU_OPTION_rtc:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002713 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002714 if (!opts) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002715 exit(1);
bellard7e0af5d02007-11-07 16:24:33 +00002716 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002717 configure_rtc(opts);
bellard7e0af5d02007-11-07 16:24:33 +00002718 break;
bellard26a5f132008-05-28 12:30:31 +00002719 case QEMU_OPTION_tb_size:
2720 tb_size = strtol(optarg, NULL, 0);
2721 if (tb_size < 0)
2722 tb_size = 0;
2723 break;
pbrook2e70f6e2008-06-29 01:03:05 +00002724 case QEMU_OPTION_icount:
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01002725 icount_option = optarg;
pbrook2e70f6e2008-06-29 01:03:05 +00002726 break;
aliguori5bb79102008-10-13 03:12:02 +00002727 case QEMU_OPTION_incoming:
2728 incoming = optarg;
Amit Shah8e848652010-07-27 15:49:19 +05302729 incoming_expected = true;
aliguori5bb79102008-10-13 03:12:02 +00002730 break;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01002731 case QEMU_OPTION_nodefaults:
2732 default_serial = 0;
2733 default_parallel = 0;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002734 default_virtcon = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01002735 default_monitor = 0;
2736 default_vga = 0;
Gerd Hoffmanncb4522c2009-12-08 13:11:47 +01002737 default_net = 0;
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01002738 default_floppy = 0;
2739 default_cdrom = 0;
2740 default_sdcard = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01002741 break;
aliguorie37630c2009-04-22 15:19:10 +00002742 case QEMU_OPTION_xen_domid:
Blue Swirlad960902010-03-29 19:23:52 +00002743 if (!(xen_available())) {
2744 printf("Option %s not supported for this target\n", popt->name);
2745 exit(1);
2746 }
aliguorie37630c2009-04-22 15:19:10 +00002747 xen_domid = atoi(optarg);
2748 break;
2749 case QEMU_OPTION_xen_create:
Blue Swirlad960902010-03-29 19:23:52 +00002750 if (!(xen_available())) {
2751 printf("Option %s not supported for this target\n", popt->name);
2752 exit(1);
2753 }
aliguorie37630c2009-04-22 15:19:10 +00002754 xen_mode = XEN_CREATE;
2755 break;
2756 case QEMU_OPTION_xen_attach:
Blue Swirlad960902010-03-29 19:23:52 +00002757 if (!(xen_available())) {
2758 printf("Option %s not supported for this target\n", popt->name);
2759 exit(1);
2760 }
aliguorie37630c2009-04-22 15:19:10 +00002761 xen_mode = XEN_ATTACH;
2762 break;
Prerna Saxenaab6540d2010-08-09 11:48:32 +01002763#ifdef CONFIG_SIMPLE_TRACE
2764 case QEMU_OPTION_trace:
2765 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
2766 if (opts) {
2767 trace_file = qemu_opt_get(opts, "file");
2768 }
2769 break;
2770#endif
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002771 case QEMU_OPTION_readconfig:
2772 {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002773 int ret = qemu_read_config_file(optarg);
2774 if (ret < 0) {
2775 fprintf(stderr, "read config %s: %s\n", optarg,
2776 strerror(-ret));
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002777 exit(1);
2778 }
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002779 break;
2780 }
Gerd Hoffmann29b00402010-03-11 11:13:27 -03002781 case QEMU_OPTION_spice:
2782 olist = qemu_find_opts("spice");
2783 if (!olist) {
2784 fprintf(stderr, "spice is not supported by this qemu build.\n");
2785 exit(1);
2786 }
2787 opts = qemu_opts_parse(olist, optarg, 0);
2788 if (!opts) {
2789 fprintf(stderr, "parse error: %s\n", optarg);
2790 exit(1);
2791 }
2792 break;
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002793 case QEMU_OPTION_writeconfig:
2794 {
2795 FILE *fp;
2796 if (strcmp(optarg, "-") == 0) {
2797 fp = stdout;
2798 } else {
2799 fp = fopen(optarg, "w");
2800 if (fp == NULL) {
2801 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
2802 exit(1);
2803 }
2804 }
2805 qemu_config_write(fp);
2806 fclose(fp);
2807 break;
2808 }
Jes Sorensen59a52642010-06-10 11:42:25 +02002809 default:
2810 os_parse_cmd_args(popt->index, optarg);
bellardcd6f1162004-05-13 22:02:20 +00002811 }
bellard0824d6f2003-06-24 13:42:40 +00002812 }
2813 }
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002814 loc_set_none();
bellard330d0412003-07-26 18:11:40 +00002815
Stefan Hajnoczi31d3c9b2011-03-13 20:14:30 +00002816 if (!st_init(trace_file)) {
2817 fprintf(stderr, "warning: unable to initialize simple trace backend\n");
2818 }
Stefan Hajnoczi0b5538c2011-02-26 18:38:39 +00002819
Paul Brook5cea8592009-05-30 00:52:44 +01002820 /* If no data_dir is specified then try to find it relative to the
2821 executable path. */
2822 if (!data_dir) {
Jes Sorensen61705402010-06-10 11:42:23 +02002823 data_dir = os_find_datadir(argv[0]);
Paul Brook5cea8592009-05-30 00:52:44 +01002824 }
2825 /* If all else fails use the install patch specified when building. */
2826 if (!data_dir) {
Paolo Bonzini1dabe052010-05-26 16:08:25 +02002827 data_dir = CONFIG_QEMU_DATADIR;
Paul Brook5cea8592009-05-30 00:52:44 +01002828 }
2829
Jes Sorensen6be68d72009-07-23 17:03:42 +02002830 /*
2831 * Default to max_cpus = smp_cpus, in case the user doesn't
2832 * specify a max_cpus value.
2833 */
2834 if (!max_cpus)
2835 max_cpus = smp_cpus;
2836
balrog3d878ca2008-10-28 10:59:59 +00002837 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
aliguorib2097002008-10-07 20:39:39 +00002838 if (smp_cpus > machine->max_cpus) {
2839 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
2840 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
2841 machine->max_cpus);
2842 exit(1);
2843 }
2844
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002845 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
2846 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002847
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002848 if (machine->no_serial) {
2849 default_serial = 0;
2850 }
2851 if (machine->no_parallel) {
2852 default_parallel = 0;
2853 }
2854 if (!machine->use_virtcon) {
2855 default_virtcon = 0;
2856 }
2857 if (machine->no_vga) {
2858 default_vga = 0;
2859 }
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01002860 if (machine->no_floppy) {
2861 default_floppy = 0;
2862 }
2863 if (machine->no_cdrom) {
2864 default_cdrom = 0;
2865 }
2866 if (machine->no_sdcard) {
2867 default_sdcard = 0;
2868 }
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002869
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002870 if (display_type == DT_NOGRAPHIC) {
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002871 if (default_parallel)
2872 add_device_config(DEV_PARALLEL, "null");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002873 if (default_serial && default_monitor) {
2874 add_device_config(DEV_SERIAL, "mon:stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002875 } else if (default_virtcon && default_monitor) {
2876 add_device_config(DEV_VIRTCON, "mon:stdio");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002877 } else {
2878 if (default_serial)
2879 add_device_config(DEV_SERIAL, "stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002880 if (default_virtcon)
2881 add_device_config(DEV_VIRTCON, "stdio");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002882 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002883 monitor_parse("stdio", "readline");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002884 }
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002885 } else {
2886 if (default_serial)
2887 add_device_config(DEV_SERIAL, "vc:80Cx24C");
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002888 if (default_parallel)
2889 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
Gerd Hoffmannabdeed02009-12-08 13:11:43 +01002890 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002891 monitor_parse("vc:80Cx24C", "readline");
Alexander Graf38536da2009-12-17 13:06:08 +01002892 if (default_virtcon)
2893 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
aliguoribc0129d2008-08-01 15:12:34 +00002894 }
Gerd Hoffmann64465292009-12-08 13:11:45 +01002895 if (default_vga)
2896 vga_interface_type = VGA_CIRRUS;
aliguoribc0129d2008-08-01 15:12:34 +00002897
TeLeMana5829fd2010-04-15 12:37:55 +08002898 socket_init();
2899
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002900 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002901 exit(1);
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07002902#ifdef CONFIG_VIRTFS
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002903 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302904 exit(1);
2905 }
2906#endif
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002907
Jes Sorenseneb505be2010-06-10 11:42:28 +02002908 os_daemonize();
ths71e3ceb2006-12-22 02:11:31 +00002909
thsaa26bb22007-03-25 21:33:06 +00002910 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
Jes Sorenseneb505be2010-06-10 11:42:28 +02002911 os_pidfile_error();
ths93815bc2007-03-19 15:58:31 +00002912 exit(1);
2913 }
2914
Paolo Bonzini98c85732010-04-19 18:59:30 +00002915 if (kvm_allowed) {
Jan Kiszkacad1e282011-01-21 21:48:16 +01002916 int ret = kvm_init();
Marcelo Tosatti214910a2009-09-18 02:41:23 -03002917 if (ret < 0) {
Paolo Bonzini98c85732010-04-19 18:59:30 +00002918 if (!kvm_available()) {
2919 printf("KVM not supported for this target\n");
2920 } else {
2921 fprintf(stderr, "failed to initialize KVM: %s\n", strerror(-ret));
2922 }
Marcelo Tosatti214910a2009-09-18 02:41:23 -03002923 exit(1);
2924 }
2925 }
2926
aliguori3fcf7b62009-04-24 18:03:25 +00002927 if (qemu_init_main_loop()) {
2928 fprintf(stderr, "qemu_init_main_loop failed\n");
2929 exit(1);
2930 }
bellarda20dd502003-09-30 21:07:02 +00002931 linux_boot = (kernel_filename != NULL);
balrog6c41b272007-11-17 12:12:29 +00002932
thsf8d39c02008-07-03 10:01:15 +00002933 if (!linux_boot && *kernel_cmdline != '\0') {
2934 fprintf(stderr, "-append only allowed with -kernel option\n");
2935 exit(1);
2936 }
2937
2938 if (!linux_boot && initrd_filename != NULL) {
2939 fprintf(stderr, "-initrd only allowed with -kernel option\n");
2940 exit(1);
2941 }
2942
Jes Sorensen9156d762010-06-10 11:42:30 +02002943 os_set_line_buffering();
ths3b46e622007-09-17 08:09:54 +00002944
aliguori7183b4b2008-11-05 20:40:18 +00002945 if (init_timer_alarm() < 0) {
2946 fprintf(stderr, "could not initialize alarm timer\n");
2947 exit(1);
2948 }
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01002949 configure_icount(icount_option);
pbrook634fce92006-07-15 17:40:09 +00002950
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01002951 if (net_init_clients() < 0) {
2952 exit(1);
bellard702c6512004-04-02 21:21:32 +00002953 }
bellardf1510b22003-06-25 00:07:40 +00002954
balrogdc72ac12008-11-09 00:04:26 +00002955 /* init the bluetooth world */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002956 if (foreach_device_config(DEV_BT, bt_parse))
2957 exit(1);
balrogdc72ac12008-11-09 00:04:26 +00002958
bellard0824d6f2003-06-24 13:42:40 +00002959 /* init the memory */
pbrook94a6b542009-04-11 17:15:54 +00002960 if (ram_size == 0)
2961 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
balrog7fb4fdc2008-04-24 17:59:27 +00002962
bellard26a5f132008-05-28 12:30:31 +00002963 /* init the dynamic translator */
2964 cpu_exec_init_all(tb_size * 1024 * 1024);
2965
Markus Armbrustereb852012009-10-27 18:41:44 +01002966 bdrv_init_with_whitelist();
thse4bcb142007-12-02 04:51:10 +00002967
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +02002968 blk_mig_init();
2969
ths96d30e42007-01-07 20:42:14 +00002970 /* open the virtual block devices */
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02002971 if (snapshot)
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002972 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
2973 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02002974 exit(1);
balrog3e3d5812007-04-30 02:09:25 +00002975
Markus Armbruster4e5d9b52011-01-28 11:21:45 +01002976 default_drive(default_cdrom, snapshot, machine->use_scsi,
2977 IF_DEFAULT, 2, CDROM_OPTS);
2978 default_drive(default_floppy, snapshot, machine->use_scsi,
2979 IF_FLOPPY, 0, FD_OPTS);
2980 default_drive(default_sdcard, snapshot, machine->use_scsi,
2981 IF_SD, 0, SD_OPTS);
2982
Alex Williamson97ab12d2010-06-25 11:09:50 -06002983 register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL,
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +02002984 ram_load, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00002985
aliguori268a3622009-04-21 22:30:27 +00002986 if (nb_numa_nodes > 0) {
2987 int i;
2988
2989 if (nb_numa_nodes > smp_cpus) {
2990 nb_numa_nodes = smp_cpus;
2991 }
2992
2993 /* If no memory size if given for any node, assume the default case
2994 * and distribute the available memory equally across all nodes
2995 */
2996 for (i = 0; i < nb_numa_nodes; i++) {
2997 if (node_mem[i] != 0)
2998 break;
2999 }
3000 if (i == nb_numa_nodes) {
3001 uint64_t usedmem = 0;
3002
3003 /* On Linux, the each node's border has to be 8MB aligned,
3004 * the final node gets the rest.
3005 */
3006 for (i = 0; i < nb_numa_nodes - 1; i++) {
3007 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
3008 usedmem += node_mem[i];
3009 }
3010 node_mem[i] = ram_size - usedmem;
3011 }
3012
3013 for (i = 0; i < nb_numa_nodes; i++) {
3014 if (node_cpumask[i] != 0)
3015 break;
3016 }
3017 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3018 * must cope with this anyway, because there are BIOSes out there in
3019 * real machines which also use this scheme.
3020 */
3021 if (i == nb_numa_nodes) {
3022 for (i = 0; i < smp_cpus; i++) {
3023 node_cpumask[i % nb_numa_nodes] |= 1 << i;
3024 }
3025 }
3026 }
3027
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003028 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
Jan Kiszka157b9312010-04-06 16:55:53 +02003029 exit(1);
3030 }
3031
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01003032 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
3033 exit(1);
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01003034 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
3035 exit(1);
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01003036 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
3037 exit(1);
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08003038 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
3039 exit(1);
aliguori2796dae2009-01-16 20:23:27 +00003040
Paul Brookaae94602009-05-14 22:35:06 +01003041 module_call_init(MODULE_INIT_DEVICE);
3042
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003043 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0)
Markus Armbrusterff952ba2010-01-29 19:48:57 +01003044 exit(0);
3045
Markus Armbruster09aaa162009-08-21 10:31:34 +02003046 if (watchdog) {
3047 i = select_watchdog(watchdog);
3048 if (i > 0)
3049 exit (i == 1 ? 1 : 0);
3050 }
3051
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02003052 if (machine->compat_props) {
Gerd Hoffmann458fb672009-12-08 13:11:33 +01003053 qdev_prop_register_global_list(machine->compat_props);
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02003054 }
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01003055 qemu_add_globals();
3056
Paul Brookfbe1b592009-05-13 17:56:25 +01003057 machine->init(ram_size, boot_devices,
aliguori3023f332009-01-16 19:04:14 +00003058 kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
3059
Jan Kiszkaea375f92010-03-01 19:10:30 +01003060 cpu_synchronize_all_post_init();
aliguori268a3622009-04-21 22:30:27 +00003061
Blue Swirl87d0a282010-03-27 18:24:45 +00003062 set_numa_modes();
aliguori268a3622009-04-21 22:30:27 +00003063
aliguori6f338c32009-02-11 15:21:54 +00003064 current_machine = machine;
3065
aliguori3023f332009-01-16 19:04:14 +00003066 /* init USB devices */
3067 if (usb_enabled) {
Markus Armbruster07527062009-10-06 12:16:57 +01003068 if (foreach_device_config(DEV_USB, usb_parse) < 0)
3069 exit(1);
aliguori3023f332009-01-16 19:04:14 +00003070 }
3071
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003072 /* init generic devices */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003073 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003074 exit(1);
3075
Markus Armbruster668680f2010-02-11 14:44:58 +01003076 net_check_clients();
3077
aliguori3023f332009-01-16 19:04:14 +00003078 /* just use the first displaystate for the moment */
Paolo Bonzinib473df62010-02-11 00:29:55 +01003079 ds = get_displaystate();
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003080
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003081 if (using_spice)
3082 display_remote++;
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003083 if (display_type == DT_DEFAULT && !display_remote) {
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003084#if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003085 display_type = DT_SDL;
Jes Sorensen821601e2011-03-16 13:33:36 +01003086#elif defined(CONFIG_VNC)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003087 vnc_display = "localhost:0,to=99";
3088 show_vnc_port = 1;
Jes Sorensen821601e2011-03-16 13:33:36 +01003089#else
3090 display_type = DT_NONE;
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003091#endif
3092 }
Jes Sorensen821601e2011-03-16 13:33:36 +01003093
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003094
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003095 /* init local displays */
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003096 switch (display_type) {
3097 case DT_NOGRAPHIC:
3098 break;
3099#if defined(CONFIG_CURSES)
3100 case DT_CURSES:
3101 curses_display_init(ds, full_screen);
3102 break;
3103#endif
bellard5b0753e2005-03-01 21:37:28 +00003104#if defined(CONFIG_SDL)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003105 case DT_SDL:
3106 sdl_display_init(ds, full_screen, no_frame);
3107 break;
bellard5b0753e2005-03-01 21:37:28 +00003108#elif defined(CONFIG_COCOA)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003109 case DT_SDL:
3110 cocoa_display_init(ds, full_screen);
3111 break;
bellard313aa562003-08-10 21:52:11 +00003112#endif
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003113 default:
3114 break;
3115 }
3116
Gleb Natapov0ce235a2011-03-31 11:27:23 +02003117 /* must be after terminal init, SDL library changes signal handlers */
3118 os_setup_signal_handling();
3119
Jes Sorensen821601e2011-03-16 13:33:36 +01003120#ifdef CONFIG_VNC
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003121 /* init remote displays */
3122 if (vnc_display) {
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003123 vnc_display_init(ds);
3124 if (vnc_display_open(ds, vnc_display) < 0)
3125 exit(1);
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003126
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003127 if (show_vnc_port) {
3128 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003129 }
bellard313aa562003-08-10 21:52:11 +00003130 }
Jes Sorensen821601e2011-03-16 13:33:36 +01003131#endif
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003132#ifdef CONFIG_SPICE
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +02003133 if (using_spice && !qxl_enabled) {
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003134 qemu_spice_display_init(ds);
3135 }
3136#endif
aliguori5b08fc12008-08-21 20:08:03 +00003137
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003138 /* display setup */
3139 dpy_resize(ds);
aliguori3023f332009-01-16 19:04:14 +00003140 dcl = ds->listeners;
3141 while (dcl != NULL) {
3142 if (dcl->dpy_refresh != NULL) {
Paolo Bonzini7bd427d2011-03-11 16:47:48 +01003143 ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds);
3144 qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock));
Isaku Yamahata0f2ad632010-05-27 14:38:47 +09003145 break;
ths20d8a3e2007-02-18 17:04:49 +00003146 }
aliguori3023f332009-01-16 19:04:14 +00003147 dcl = dcl->next;
bellard82c643f2004-07-14 17:28:13 +00003148 }
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003149 if (ds->gui_timer == NULL) {
Paolo Bonzini7bd427d2011-03-11 16:47:48 +01003150 nographic_timer = qemu_new_timer_ms(rt_clock, nographic_update, NULL);
3151 qemu_mod_timer(nographic_timer, qemu_get_clock_ms(rt_clock));
blueswir19043b622009-01-21 19:28:13 +00003152 }
Paolo Bonzinib473df62010-02-11 00:29:55 +01003153 text_consoles_set_display(ds);
aliguori2796dae2009-01-16 20:23:27 +00003154
aliguori59030a82009-04-05 18:43:41 +00003155 if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) {
3156 fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n",
3157 gdbstub_dev);
3158 exit(1);
balrog45669e02007-07-02 13:20:17 +00003159 }
balrog45669e02007-07-02 13:20:17 +00003160
Gerd Hoffmann3418bd22009-09-25 21:42:41 +02003161 qdev_machine_creation_done();
3162
Gerd Hoffmann15ff7702009-12-14 16:07:35 +01003163 if (rom_load_all() != 0) {
3164 fprintf(stderr, "rom loading failed\n");
3165 exit(1);
3166 }
Gerd Hoffmann45a50b12009-10-01 16:42:33 +02003167
Isaku Yamahata80376c32010-12-20 14:33:35 +09003168 /* TODO: once all bus devices are qdevified, this should be done
3169 * when bus is created by qdev.c */
3170 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
Gleb Natapov4cab9462010-12-08 13:35:08 +02003171 qemu_run_machine_init_done_notifiers();
3172
Juan Quintela504c2942009-11-12 00:39:13 +01003173 qemu_system_reset();
Juan Quintela05f24012009-08-20 19:42:22 +02003174 if (loadvm) {
Markus Armbruster03cd4652010-02-17 16:24:10 +01003175 if (load_vmstate(loadvm) < 0) {
Juan Quintela05f24012009-08-20 19:42:22 +02003176 autostart = 0;
3177 }
3178 }
bellardd63d3072004-10-03 13:29:03 +00003179
Glauber Costa2bb8c102009-07-24 16:20:23 -04003180 if (incoming) {
Juan Quintela8ca5e802010-06-09 14:10:54 +02003181 int ret = qemu_start_incoming_migration(incoming);
3182 if (ret < 0) {
3183 fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n",
3184 incoming, ret);
3185 exit(ret);
3186 }
Avi Kivity6b99dad2009-08-09 14:39:20 +03003187 } else if (autostart) {
aliguoric0f4ce72009-03-05 23:01:01 +00003188 vm_start();
Avi Kivity6b99dad2009-08-09 14:39:20 +03003189 }
thsffd843b2006-12-21 19:46:43 +00003190
Jes Sorenseneb505be2010-06-10 11:42:28 +02003191 os_setup_post();
ths71e3ceb2006-12-22 02:11:31 +00003192
bellard8a7ddc32004-03-31 19:00:16 +00003193 main_loop();
bellard40c3bac2004-04-04 12:56:28 +00003194 quit_timers();
aliguori63a01ef2008-10-31 19:10:00 +00003195 net_cleanup();
thsb46a8902007-10-21 23:20:45 +00003196
bellard0824d6f2003-06-24 13:42:40 +00003197 return 0;
3198}