blob: f4c24d30dcda372d54d9dadc3436549453926867 [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;
ths73fc9742006-12-22 02:09:07 +0000209const char *vnc_display;
bellard6515b202006-05-03 22:02:44 +0000210int acpi_enabled = 1;
aliguori16b29ae2008-12-17 23:28:44 +0000211int no_hpet = 0;
bellard52ca8d62006-06-14 16:03:05 +0000212int fd_bootchk = 1;
bellardd1beab82006-10-02 19:44:22 +0000213int no_reboot = 0;
aurel32b2f76162008-04-11 21:35:52 +0000214int no_shutdown = 0;
balrog9467cd42007-05-01 01:34:14 +0000215int cursor_hide = 1;
balroga171fe32007-04-30 01:48:07 +0000216int graphic_rotate = 0;
Jes Sorensen6b35e7b2009-08-06 16:25:50 +0200217uint8_t irq0override = 1;
Markus Armbruster09aaa162009-08-21 10:31:34 +0200218const char *watchdog;
Gleb Natapov2e55e842010-12-08 13:35:07 +0200219QEMUOptionRom option_rom[MAX_OPTION_ROMS];
ths9ae02552007-01-05 17:39:04 +0000220int nb_option_roms;
pbrook8e716212007-01-20 17:12:09 +0000221int semihosting_enabled = 0;
balrog2b8f2d42007-07-27 22:08:46 +0000222int old_param = 0;
thsc35734b2007-03-19 15:17:08 +0000223const char *qemu_name;
ths3780e192007-06-21 21:08:02 +0000224int alt_grab = 0;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -0500225int ctrl_grab = 0;
blueswir166508602007-05-01 14:16:52 +0000226unsigned int nb_prom_envs = 0;
227const char *prom_envs[MAX_PROM_ENVS];
Jan Kiszka95387492009-07-02 00:19:02 +0200228int boot_menu;
bellard0824d6f2003-06-24 13:42:40 +0000229
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200230typedef struct FWBootEntry FWBootEntry;
231
232struct FWBootEntry {
233 QTAILQ_ENTRY(FWBootEntry) link;
234 int32_t bootindex;
235 DeviceState *dev;
236 char *suffix;
237};
238
239QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order);
240
aliguori268a3622009-04-21 22:30:27 +0000241int nb_numa_nodes;
242uint64_t node_mem[MAX_NODES];
243uint64_t node_cpumask[MAX_NODES];
244
blueswir19043b622009-01-21 19:28:13 +0000245static QEMUTimer *nographic_timer;
balrogee5605e2007-12-03 03:01:40 +0000246
blueswir18fcb1b92008-09-18 18:29:08 +0000247uint8_t qemu_uuid[16];
248
Jan Kiszka76e30d02009-07-02 00:19:02 +0200249static QEMUBootSetHandler *boot_set_handler;
250static void *boot_set_opaque;
251
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +0200252static NotifierList exit_notifiers =
253 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
254
Gleb Natapov4cab9462010-12-08 13:35:08 +0200255static NotifierList machine_init_done_notifiers =
256 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
257
Blue Swirld745bef2010-03-29 19:23:49 +0000258int kvm_allowed = 0;
259uint32_t xen_domid;
260enum xen_mode xen_mode = XEN_EMULATE;
261
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100262static int default_serial = 1;
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +0100263static int default_parallel = 1;
Gerd Hoffmann986c5f72009-12-08 13:11:54 +0100264static int default_virtcon = 1;
Gerd Hoffmannabdeed02009-12-08 13:11:43 +0100265static int default_monitor = 1;
Gerd Hoffmann64465292009-12-08 13:11:45 +0100266static int default_vga = 1;
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +0100267static int default_floppy = 1;
268static int default_cdrom = 1;
269static int default_sdcard = 1;
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100270
271static struct {
272 const char *driver;
273 int *flag;
274} default_list[] = {
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +0100275 { .driver = "isa-serial", .flag = &default_serial },
276 { .driver = "isa-parallel", .flag = &default_parallel },
Gerd Hoffmannd8bcbab2009-12-16 14:25:40 +0100277 { .driver = "isa-fdc", .flag = &default_floppy },
278 { .driver = "ide-drive", .flag = &default_cdrom },
Amit Shah392ecf52010-01-21 16:19:23 +0530279 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
280 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
281 { .driver = "virtio-serial", .flag = &default_virtcon },
Gerd Hoffmann64465292009-12-08 13:11:45 +0100282 { .driver = "VGA", .flag = &default_vga },
Gerd Hoffmann69fd02e2009-12-16 13:35:19 +0100283 { .driver = "cirrus-vga", .flag = &default_vga },
284 { .driver = "vmware-svga", .flag = &default_vga },
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100285};
286
287static int default_driver_check(QemuOpts *opts, void *opaque)
288{
289 const char *driver = qemu_opt_get(opts, "driver");
290 int i;
291
292 if (!driver)
293 return 0;
294 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
295 if (strcmp(default_list[i].driver, driver) != 0)
296 continue;
297 *(default_list[i].flag) = 0;
298 }
299 return 0;
300}
301
bellard0824d6f2003-06-24 13:42:40 +0000302/***********************************************************/
Paolo Bonzini8f0056b2010-01-13 14:05:34 +0100303/* real time host monotonic timer */
bellard09b26c52006-04-12 21:09:08 +0000304
bellardc4b1fcc2004-03-14 21:44:30 +0000305/***********************************************************/
balrogf6503052008-02-17 11:42:19 +0000306/* host time/date access */
307void qemu_get_timedate(struct tm *tm, int offset)
308{
309 time_t ti;
310 struct tm *ret;
311
312 time(&ti);
313 ti += offset;
314 if (rtc_date_offset == -1) {
315 if (rtc_utc)
316 ret = gmtime(&ti);
317 else
318 ret = localtime(&ti);
319 } else {
320 ti -= rtc_date_offset;
321 ret = gmtime(&ti);
322 }
323
324 memcpy(tm, ret, sizeof(struct tm));
325}
326
327int qemu_timedate_diff(struct tm *tm)
328{
329 time_t seconds;
330
331 if (rtc_date_offset == -1)
332 if (rtc_utc)
333 seconds = mktimegm(tm);
334 else
335 seconds = mktime(tm);
336 else
337 seconds = mktimegm(tm) + rtc_date_offset;
338
339 return seconds - time(NULL);
340}
341
Luiz Capitulino80cd3472010-02-25 12:11:44 -0300342void rtc_change_mon_event(struct tm *tm)
343{
344 QObject *data;
345
346 data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
347 monitor_protocol_event(QEVENT_RTC_CHANGE, data);
348 qobject_decref(data);
349}
350
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200351static void configure_rtc_date_offset(const char *startdate, int legacy)
352{
353 time_t rtc_start_date;
354 struct tm tm;
355
356 if (!strcmp(startdate, "now") && legacy) {
357 rtc_date_offset = -1;
358 } else {
359 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
360 &tm.tm_year,
361 &tm.tm_mon,
362 &tm.tm_mday,
363 &tm.tm_hour,
364 &tm.tm_min,
365 &tm.tm_sec) == 6) {
366 /* OK */
367 } else if (sscanf(startdate, "%d-%d-%d",
368 &tm.tm_year,
369 &tm.tm_mon,
370 &tm.tm_mday) == 3) {
371 tm.tm_hour = 0;
372 tm.tm_min = 0;
373 tm.tm_sec = 0;
374 } else {
375 goto date_fail;
376 }
377 tm.tm_year -= 1900;
378 tm.tm_mon--;
379 rtc_start_date = mktimegm(&tm);
380 if (rtc_start_date == -1) {
381 date_fail:
382 fprintf(stderr, "Invalid date format. Valid formats are:\n"
383 "'2006-06-17T16:01:21' or '2006-06-17'\n");
384 exit(1);
385 }
386 rtc_date_offset = time(NULL) - rtc_start_date;
387 }
388}
389
390static void configure_rtc(QemuOpts *opts)
391{
392 const char *value;
393
394 value = qemu_opt_get(opts, "base");
395 if (value) {
396 if (!strcmp(value, "utc")) {
397 rtc_utc = 1;
398 } else if (!strcmp(value, "localtime")) {
399 rtc_utc = 0;
400 } else {
401 configure_rtc_date_offset(value, 0);
402 }
403 }
Jan Kiszka68752042009-09-15 13:36:04 +0200404 value = qemu_opt_get(opts, "clock");
405 if (value) {
406 if (!strcmp(value, "host")) {
407 rtc_clock = host_clock;
408 } else if (!strcmp(value, "vm")) {
409 rtc_clock = vm_clock;
410 } else {
411 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
412 exit(1);
413 }
414 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200415 value = qemu_opt_get(opts, "driftfix");
416 if (value) {
Blue Swirl7e4c0332010-03-27 21:33:46 +0000417 if (!strcmp(value, "slew")) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200418 rtc_td_hack = 1;
Blue Swirl7e4c0332010-03-27 21:33:46 +0000419 } else if (!strcmp(value, "none")) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200420 rtc_td_hack = 0;
421 } else {
422 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
423 exit(1);
424 }
425 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200426}
427
balrog1ae26a12008-09-28 23:19:47 +0000428/***********************************************************/
429/* Bluetooth support */
430static int nb_hcis;
431static int cur_hci;
432static struct HCIInfo *hci_table[MAX_NICS];
balrogdc72ac12008-11-09 00:04:26 +0000433
balrog1ae26a12008-09-28 23:19:47 +0000434static struct bt_vlan_s {
435 struct bt_scatternet_s net;
436 int id;
437 struct bt_vlan_s *next;
438} *first_bt_vlan;
439
440/* find or alloc a new bluetooth "VLAN" */
blueswir1674bb262008-09-30 18:18:27 +0000441static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
balrog1ae26a12008-09-28 23:19:47 +0000442{
443 struct bt_vlan_s **pvlan, *vlan;
444 for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) {
445 if (vlan->id == id)
446 return &vlan->net;
447 }
448 vlan = qemu_mallocz(sizeof(struct bt_vlan_s));
449 vlan->id = id;
450 pvlan = &first_bt_vlan;
451 while (*pvlan != NULL)
452 pvlan = &(*pvlan)->next;
453 *pvlan = vlan;
454 return &vlan->net;
455}
456
457static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
458{
459}
460
461static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
462{
463 return -ENOTSUP;
464}
465
466static struct HCIInfo null_hci = {
467 .cmd_send = null_hci_send,
468 .sco_send = null_hci_send,
469 .acl_send = null_hci_send,
470 .bdaddr_set = null_hci_addr_set,
471};
472
473struct HCIInfo *qemu_next_hci(void)
474{
475 if (cur_hci == nb_hcis)
476 return &null_hci;
477
478 return hci_table[cur_hci++];
479}
480
balrogdc72ac12008-11-09 00:04:26 +0000481static struct HCIInfo *hci_init(const char *str)
482{
483 char *endp;
484 struct bt_scatternet_s *vlan = 0;
485
486 if (!strcmp(str, "null"))
487 /* null */
488 return &null_hci;
489 else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':'))
490 /* host[:hciN] */
491 return bt_host_hci(str[4] ? str + 5 : "hci0");
492 else if (!strncmp(str, "hci", 3)) {
493 /* hci[,vlan=n] */
494 if (str[3]) {
495 if (!strncmp(str + 3, ",vlan=", 6)) {
496 vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0));
497 if (*endp)
498 vlan = 0;
499 }
500 } else
501 vlan = qemu_find_bt_vlan(0);
502 if (vlan)
503 return bt_new_hci(vlan);
504 }
505
506 fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
507
508 return 0;
509}
510
511static int bt_hci_parse(const char *str)
512{
513 struct HCIInfo *hci;
Anthony Liguoric227f092009-10-01 16:12:16 -0500514 bdaddr_t bdaddr;
balrogdc72ac12008-11-09 00:04:26 +0000515
516 if (nb_hcis >= MAX_NICS) {
517 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
518 return -1;
519 }
520
521 hci = hci_init(str);
522 if (!hci)
523 return -1;
524
525 bdaddr.b[0] = 0x52;
526 bdaddr.b[1] = 0x54;
527 bdaddr.b[2] = 0x00;
528 bdaddr.b[3] = 0x12;
529 bdaddr.b[4] = 0x34;
530 bdaddr.b[5] = 0x56 + nb_hcis;
531 hci->bdaddr_set(hci, bdaddr.b);
532
533 hci_table[nb_hcis++] = hci;
534
535 return 0;
536}
537
538static void bt_vhci_add(int vlan_id)
539{
540 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
541
542 if (!vlan->slave)
543 fprintf(stderr, "qemu: warning: adding a VHCI to "
544 "an empty scatternet %i\n", vlan_id);
545
546 bt_vhci_init(bt_new_hci(vlan));
547}
548
549static struct bt_device_s *bt_device_add(const char *opt)
550{
551 struct bt_scatternet_s *vlan;
552 int vlan_id = 0;
553 char *endp = strstr(opt, ",vlan=");
554 int len = (endp ? endp - opt : strlen(opt)) + 1;
555 char devname[10];
556
557 pstrcpy(devname, MIN(sizeof(devname), len), opt);
558
559 if (endp) {
560 vlan_id = strtol(endp + 6, &endp, 0);
561 if (*endp) {
562 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
563 return 0;
564 }
565 }
566
567 vlan = qemu_find_bt_vlan(vlan_id);
568
569 if (!vlan->slave)
570 fprintf(stderr, "qemu: warning: adding a slave device to "
571 "an empty scatternet %i\n", vlan_id);
572
573 if (!strcmp(devname, "keyboard"))
574 return bt_keyboard_init(vlan);
575
576 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
577 return 0;
578}
579
580static int bt_parse(const char *opt)
581{
582 const char *endp, *p;
583 int vlan;
584
585 if (strstart(opt, "hci", &endp)) {
586 if (!*endp || *endp == ',') {
587 if (*endp)
588 if (!strstart(endp, ",vlan=", 0))
589 opt = endp + 1;
590
591 return bt_hci_parse(opt);
592 }
593 } else if (strstart(opt, "vhci", &endp)) {
594 if (!*endp || *endp == ',') {
595 if (*endp) {
596 if (strstart(endp, ",vlan=", &p)) {
597 vlan = strtol(p, (char **) &endp, 0);
598 if (*endp) {
599 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
600 return 1;
601 }
602 } else {
603 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
604 return 1;
605 }
606 } else
607 vlan = 0;
608
609 bt_vhci_add(vlan);
610 return 0;
611 }
612 } else if (strstart(opt, "device:", &endp))
613 return !bt_device_add(endp);
614
615 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
616 return 1;
617}
618
balrog1ae26a12008-09-28 23:19:47 +0000619/***********************************************************/
620/* QEMU Block devices */
621
Markus Armbruster2292dda2011-01-28 11:21:41 +0100622#define HD_OPTS "media=disk"
623#define CDROM_OPTS "media=cdrom"
624#define FD_OPTS ""
625#define PFLASH_OPTS ""
626#define MTD_OPTS ""
627#define SD_OPTS ""
thse4bcb142007-12-02 04:51:10 +0000628
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200629static int drive_init_func(QemuOpts *opts, void *opaque)
630{
Markus Armbrustera803cb82010-06-02 13:31:55 +0200631 int *use_scsi = opaque;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200632
Markus Armbruster319ae522011-01-28 11:21:46 +0100633 return drive_init(opts, *use_scsi) == NULL;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200634}
635
636static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
637{
638 if (NULL == qemu_opt_get(opts, "snapshot")) {
639 qemu_opt_set(opts, "snapshot", "on");
640 }
641 return 0;
642}
643
Markus Armbruster4e5d9b52011-01-28 11:21:45 +0100644static void default_drive(int enable, int snapshot, int use_scsi,
645 BlockInterfaceType type, int index,
646 const char *optstr)
647{
648 QemuOpts *opts;
649
650 if (type == IF_DEFAULT) {
651 type = use_scsi ? IF_SCSI : IF_IDE;
652 }
653
654 if (!enable || drive_get_by_index(type, index)) {
655 return;
656 }
657
658 opts = drive_add(type, index, NULL, optstr);
659 if (snapshot) {
660 drive_enable_snapshot(opts, NULL);
661 }
Markus Armbruster319ae522011-01-28 11:21:46 +0100662 if (!drive_init(opts, use_scsi)) {
Markus Armbruster4e5d9b52011-01-28 11:21:45 +0100663 exit(1);
664 }
665}
666
Jan Kiszka76e30d02009-07-02 00:19:02 +0200667void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
668{
669 boot_set_handler = func;
670 boot_set_opaque = opaque;
671}
672
673int qemu_boot_set(const char *boot_devices)
674{
675 if (!boot_set_handler) {
676 return -EINVAL;
677 }
678 return boot_set_handler(boot_set_opaque, boot_devices);
679}
680
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -0300681static void validate_bootdevices(char *devices)
Jan Kiszkaef3adf62009-07-02 00:19:02 +0200682{
683 /* We just do some generic consistency checks */
684 const char *p;
685 int bitmap = 0;
686
687 for (p = devices; *p != '\0'; p++) {
688 /* Allowed boot devices are:
689 * a-b: floppy disk drives
690 * c-f: IDE disk drives
691 * g-m: machine implementation dependant drives
692 * n-p: network devices
693 * It's up to each machine implementation to check if the given boot
694 * devices match the actual hardware implementation and firmware
695 * features.
696 */
697 if (*p < 'a' || *p > 'p') {
698 fprintf(stderr, "Invalid boot device '%c'\n", *p);
699 exit(1);
700 }
701 if (bitmap & (1 << (*p - 'a'))) {
702 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
703 exit(1);
704 }
705 bitmap |= 1 << (*p - 'a');
706 }
Jan Kiszkaef3adf62009-07-02 00:19:02 +0200707}
708
Jan Kiszkae0f084b2009-07-02 00:19:02 +0200709static void restore_boot_devices(void *opaque)
710{
711 char *standard_boot_devices = opaque;
Alex Williamson37905d62010-04-30 15:21:11 -0600712 static int first = 1;
713
714 /* Restore boot order and remove ourselves after the first boot */
715 if (first) {
716 first = 0;
717 return;
718 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +0200719
720 qemu_boot_set(standard_boot_devices);
721
722 qemu_unregister_reset(restore_boot_devices, standard_boot_devices);
723 qemu_free(standard_boot_devices);
724}
725
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200726void add_boot_device_path(int32_t bootindex, DeviceState *dev,
727 const char *suffix)
728{
729 FWBootEntry *node, *i;
730
731 if (bootindex < 0) {
732 return;
733 }
734
735 assert(dev != NULL || suffix != NULL);
736
737 node = qemu_mallocz(sizeof(FWBootEntry));
738 node->bootindex = bootindex;
Gleb Natapov4fef9302011-02-02 17:34:34 +0200739 node->suffix = suffix ? qemu_strdup(suffix) : NULL;
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200740 node->dev = dev;
741
742 QTAILQ_FOREACH(i, &fw_boot_order, link) {
743 if (i->bootindex == bootindex) {
744 fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
745 exit(1);
746 } else if (i->bootindex < bootindex) {
747 continue;
748 }
749 QTAILQ_INSERT_BEFORE(i, node, link);
750 return;
751 }
752 QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
753}
754
Gleb Natapov962630f2010-12-08 13:35:09 +0200755/*
756 * This function returns null terminated string that consist of new line
757 * separated device pathes.
758 *
759 * memory pointed by "size" is assigned total length of the array in bytes
760 *
761 */
762char *get_boot_devices_list(uint32_t *size)
763{
764 FWBootEntry *i;
765 uint32_t total = 0;
766 char *list = NULL;
767
768 QTAILQ_FOREACH(i, &fw_boot_order, link) {
769 char *devpath = NULL, *bootpath;
770 int len;
771
772 if (i->dev) {
773 devpath = qdev_get_fw_dev_path(i->dev);
774 assert(devpath);
775 }
776
777 if (i->suffix && devpath) {
Blue Swirl4fd37a92010-12-19 14:05:43 +0000778 size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
779
780 bootpath = qemu_malloc(bootpathlen);
781 snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
Gleb Natapov962630f2010-12-08 13:35:09 +0200782 qemu_free(devpath);
783 } else if (devpath) {
784 bootpath = devpath;
785 } else {
Gleb Natapov4fef9302011-02-02 17:34:34 +0200786 bootpath = qemu_strdup(i->suffix);
Gleb Natapov962630f2010-12-08 13:35:09 +0200787 assert(bootpath);
788 }
789
790 if (total) {
791 list[total-1] = '\n';
792 }
793 len = strlen(bootpath) + 1;
794 list = qemu_realloc(list, total + len);
795 memcpy(&list[total], bootpath, len);
796 total += len;
797 qemu_free(bootpath);
798 }
799
800 *size = total;
801
802 return list;
803}
804
aliguori268a3622009-04-21 22:30:27 +0000805static void numa_add(const char *optarg)
806{
807 char option[128];
808 char *endptr;
809 unsigned long long value, endvalue;
810 int nodenr;
811
812 optarg = get_opt_name(option, 128, optarg, ',') + 1;
813 if (!strcmp(option, "node")) {
814 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
815 nodenr = nb_numa_nodes;
816 } else {
817 nodenr = strtoull(option, NULL, 10);
818 }
819
820 if (get_param_value(option, 128, "mem", optarg) == 0) {
821 node_mem[nodenr] = 0;
822 } else {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +0100823 int64_t sval;
Jes Sorensen9f9b17a2010-10-21 17:15:46 +0200824 sval = strtosz(option, NULL);
825 if (sval < 0) {
826 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
827 exit(1);
aliguori268a3622009-04-21 22:30:27 +0000828 }
Jes Sorensen9f9b17a2010-10-21 17:15:46 +0200829 node_mem[nodenr] = sval;
aliguori268a3622009-04-21 22:30:27 +0000830 }
831 if (get_param_value(option, 128, "cpus", optarg) == 0) {
832 node_cpumask[nodenr] = 0;
833 } else {
834 value = strtoull(option, &endptr, 10);
835 if (value >= 64) {
836 value = 63;
837 fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n");
838 } else {
839 if (*endptr == '-') {
840 endvalue = strtoull(endptr+1, &endptr, 10);
841 if (endvalue >= 63) {
842 endvalue = 62;
843 fprintf(stderr,
844 "only 63 CPUs in NUMA mode supported.\n");
845 }
Paolo Bonzini0dfbd512010-02-04 14:31:50 +0100846 value = (2ULL << endvalue) - (1ULL << value);
aliguori268a3622009-04-21 22:30:27 +0000847 } else {
Paolo Bonzini0dfbd512010-02-04 14:31:50 +0100848 value = 1ULL << value;
aliguori268a3622009-04-21 22:30:27 +0000849 }
850 }
851 node_cpumask[nodenr] = value;
852 }
853 nb_numa_nodes++;
854 }
855 return;
856}
857
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200858static void smp_parse(const char *optarg)
859{
860 int smp, sockets = 0, threads = 0, cores = 0;
861 char *endptr;
862 char option[128];
863
864 smp = strtoul(optarg, &endptr, 10);
865 if (endptr != optarg) {
866 if (*endptr == ',') {
867 endptr++;
868 }
869 }
870 if (get_param_value(option, 128, "sockets", endptr) != 0)
871 sockets = strtoull(option, NULL, 10);
872 if (get_param_value(option, 128, "cores", endptr) != 0)
873 cores = strtoull(option, NULL, 10);
874 if (get_param_value(option, 128, "threads", endptr) != 0)
875 threads = strtoull(option, NULL, 10);
876 if (get_param_value(option, 128, "maxcpus", endptr) != 0)
877 max_cpus = strtoull(option, NULL, 10);
878
879 /* compute missing values, prefer sockets over cores over threads */
880 if (smp == 0 || sockets == 0) {
881 sockets = sockets > 0 ? sockets : 1;
882 cores = cores > 0 ? cores : 1;
883 threads = threads > 0 ? threads : 1;
884 if (smp == 0) {
885 smp = cores * threads * sockets;
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200886 }
887 } else {
888 if (cores == 0) {
889 threads = threads > 0 ? threads : 1;
890 cores = smp / (sockets * threads);
891 } else {
Joel Schoppdca98162010-07-21 15:05:17 -0500892 threads = smp / (cores * sockets);
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200893 }
894 }
895 smp_cpus = smp;
896 smp_cores = cores > 0 ? cores : 1;
897 smp_threads = threads > 0 ? threads : 1;
898 if (max_cpus == 0)
899 max_cpus = smp_cpus;
900}
901
bellard330d0412003-07-26 18:11:40 +0000902/***********************************************************/
bellarda594cfb2005-11-06 16:13:29 +0000903/* USB devices */
904
Markus Armbrusterfb080002010-05-28 15:38:44 +0200905static int usb_device_add(const char *devname)
bellarda594cfb2005-11-06 16:13:29 +0000906{
907 const char *p;
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200908 USBDevice *dev = NULL;
bellarda594cfb2005-11-06 16:13:29 +0000909
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200910 if (!usb_enabled)
bellarda594cfb2005-11-06 16:13:29 +0000911 return -1;
912
Gerd Hoffmann0958b4c2009-10-26 15:56:45 +0100913 /* drivers with .usbdevice_name entry in USBDeviceInfo */
914 dev = usbdevice_create(devname);
915 if (dev)
916 goto done;
917
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200918 /* the other ones */
bellarda594cfb2005-11-06 16:13:29 +0000919 if (strstart(devname, "host:", &p)) {
920 dev = usb_host_device_open(p);
balrogdc72ac12008-11-09 00:04:26 +0000921 } else if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
922 dev = usb_bt_init(devname[2] ? hci_init(p) :
923 bt_new_hci(qemu_find_bt_vlan(0)));
bellarda594cfb2005-11-06 16:13:29 +0000924 } else {
925 return -1;
926 }
pbrook0d92ed32006-05-21 16:30:15 +0000927 if (!dev)
928 return -1;
929
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200930done:
bellarda594cfb2005-11-06 16:13:29 +0000931 return 0;
932}
933
aliguori1f3870a2008-08-21 19:27:48 +0000934static int usb_device_del(const char *devname)
935{
936 int bus_num, addr;
937 const char *p;
938
aliguori5d0c5752008-09-14 01:07:41 +0000939 if (strstart(devname, "host:", &p))
940 return usb_host_device_close(p);
941
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200942 if (!usb_enabled)
aliguori1f3870a2008-08-21 19:27:48 +0000943 return -1;
944
945 p = strchr(devname, '.');
946 if (!p)
947 return -1;
948 bus_num = strtoul(devname, NULL, 0);
949 addr = strtoul(p + 1, NULL, 0);
950
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200951 return usb_device_delete_addr(bus_num, addr);
aliguori1f3870a2008-08-21 19:27:48 +0000952}
953
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +0200954static int usb_parse(const char *cmdline)
955{
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800956 int r;
Markus Armbrusterfb080002010-05-28 15:38:44 +0200957 r = usb_device_add(cmdline);
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800958 if (r < 0) {
959 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
960 }
961 return r;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +0200962}
963
Luiz Capitulinod54908a2009-08-28 15:27:13 -0300964void do_usb_add(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +0000965{
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800966 const char *devname = qdict_get_str(qdict, "devname");
Markus Armbrusterfb080002010-05-28 15:38:44 +0200967 if (usb_device_add(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +0100968 error_report("could not add USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800969 }
bellarda594cfb2005-11-06 16:13:29 +0000970}
971
Luiz Capitulinod54908a2009-08-28 15:27:13 -0300972void do_usb_del(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +0000973{
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800974 const char *devname = qdict_get_str(qdict, "devname");
975 if (usb_device_del(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +0100976 error_report("could not delete USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800977 }
bellarda594cfb2005-11-06 16:13:29 +0000978}
979
bellardf7cce892004-12-08 22:21:25 +0000980/***********************************************************/
balrog201a51f2007-04-30 00:51:09 +0000981/* PCMCIA/Cardbus */
982
983static struct pcmcia_socket_entry_s {
Paul Brookbc24a222009-05-10 01:44:56 +0100984 PCMCIASocket *socket;
balrog201a51f2007-04-30 00:51:09 +0000985 struct pcmcia_socket_entry_s *next;
986} *pcmcia_sockets = 0;
987
Paul Brookbc24a222009-05-10 01:44:56 +0100988void pcmcia_socket_register(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +0000989{
990 struct pcmcia_socket_entry_s *entry;
991
992 entry = qemu_malloc(sizeof(struct pcmcia_socket_entry_s));
993 entry->socket = socket;
994 entry->next = pcmcia_sockets;
995 pcmcia_sockets = entry;
996}
997
Paul Brookbc24a222009-05-10 01:44:56 +0100998void pcmcia_socket_unregister(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +0000999{
1000 struct pcmcia_socket_entry_s *entry, **ptr;
1001
1002 ptr = &pcmcia_sockets;
1003 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1004 if (entry->socket == socket) {
1005 *ptr = entry->next;
1006 qemu_free(entry);
1007 }
1008}
1009
aliguori376253e2009-03-05 23:01:23 +00001010void pcmcia_info(Monitor *mon)
balrog201a51f2007-04-30 00:51:09 +00001011{
1012 struct pcmcia_socket_entry_s *iter;
aliguori376253e2009-03-05 23:01:23 +00001013
balrog201a51f2007-04-30 00:51:09 +00001014 if (!pcmcia_sockets)
aliguori376253e2009-03-05 23:01:23 +00001015 monitor_printf(mon, "No PCMCIA sockets\n");
balrog201a51f2007-04-30 00:51:09 +00001016
1017 for (iter = pcmcia_sockets; iter; iter = iter->next)
aliguori376253e2009-03-05 23:01:23 +00001018 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1019 iter->socket->attached ? iter->socket->card_string :
1020 "Empty");
balrog201a51f2007-04-30 00:51:09 +00001021}
1022
1023/***********************************************************/
bellard8a7ddc32004-03-31 19:00:16 +00001024/* I/O handling */
bellard0824d6f2003-06-24 13:42:40 +00001025
bellardc4b1fcc2004-03-14 21:44:30 +00001026typedef struct IOHandlerRecord {
1027 int fd;
Juan Quintela7b27a762010-03-11 17:55:39 +01001028 IOCanReadHandler *fd_read_poll;
bellard7c9d8e02005-11-15 22:16:05 +00001029 IOHandler *fd_read;
1030 IOHandler *fd_write;
thscafffd42007-02-28 21:59:44 +00001031 int deleted;
bellardc4b1fcc2004-03-14 21:44:30 +00001032 void *opaque;
1033 /* temporary data */
1034 struct pollfd *ufd;
Juan Quintela31d4ee62010-03-11 17:55:37 +01001035 QLIST_ENTRY(IOHandlerRecord) next;
bellardc4b1fcc2004-03-14 21:44:30 +00001036} IOHandlerRecord;
1037
Juan Quintela31d4ee62010-03-11 17:55:37 +01001038static QLIST_HEAD(, IOHandlerRecord) io_handlers =
1039 QLIST_HEAD_INITIALIZER(io_handlers);
1040
bellardc4b1fcc2004-03-14 21:44:30 +00001041
bellard7c9d8e02005-11-15 22:16:05 +00001042/* XXX: fd_read_poll should be suppressed, but an API change is
1043 necessary in the character devices to suppress fd_can_read(). */
ths5fafdf22007-09-16 21:08:06 +00001044int qemu_set_fd_handler2(int fd,
Juan Quintela7b27a762010-03-11 17:55:39 +01001045 IOCanReadHandler *fd_read_poll,
ths5fafdf22007-09-16 21:08:06 +00001046 IOHandler *fd_read,
1047 IOHandler *fd_write,
bellard7c9d8e02005-11-15 22:16:05 +00001048 void *opaque)
bellardb4608c02003-06-27 17:34:32 +00001049{
Juan Quintela31d4ee62010-03-11 17:55:37 +01001050 IOHandlerRecord *ioh;
bellard8a7ddc32004-03-31 19:00:16 +00001051
bellard7c9d8e02005-11-15 22:16:05 +00001052 if (!fd_read && !fd_write) {
Juan Quintela31d4ee62010-03-11 17:55:37 +01001053 QLIST_FOREACH(ioh, &io_handlers, next) {
bellard7c9d8e02005-11-15 22:16:05 +00001054 if (ioh->fd == fd) {
thscafffd42007-02-28 21:59:44 +00001055 ioh->deleted = 1;
bellard7c9d8e02005-11-15 22:16:05 +00001056 break;
1057 }
bellard8a7ddc32004-03-31 19:00:16 +00001058 }
bellard7c9d8e02005-11-15 22:16:05 +00001059 } else {
Juan Quintela31d4ee62010-03-11 17:55:37 +01001060 QLIST_FOREACH(ioh, &io_handlers, next) {
bellard7c9d8e02005-11-15 22:16:05 +00001061 if (ioh->fd == fd)
1062 goto found;
1063 }
1064 ioh = qemu_mallocz(sizeof(IOHandlerRecord));
Juan Quintela31d4ee62010-03-11 17:55:37 +01001065 QLIST_INSERT_HEAD(&io_handlers, ioh, next);
bellard7c9d8e02005-11-15 22:16:05 +00001066 found:
1067 ioh->fd = fd;
1068 ioh->fd_read_poll = fd_read_poll;
1069 ioh->fd_read = fd_read;
1070 ioh->fd_write = fd_write;
1071 ioh->opaque = opaque;
thscafffd42007-02-28 21:59:44 +00001072 ioh->deleted = 0;
bellard8a7ddc32004-03-31 19:00:16 +00001073 }
bellard7c9d8e02005-11-15 22:16:05 +00001074 return 0;
1075}
1076
ths5fafdf22007-09-16 21:08:06 +00001077int qemu_set_fd_handler(int fd,
1078 IOHandler *fd_read,
1079 IOHandler *fd_write,
bellard7c9d8e02005-11-15 22:16:05 +00001080 void *opaque)
1081{
1082 return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque);
bellardb4608c02003-06-27 17:34:32 +00001083}
1084
bellard8a7ddc32004-03-31 19:00:16 +00001085/***********************************************************/
bellardcc1daa42005-06-05 14:49:17 +00001086/* machine registration */
1087
blueswir1bdaf78e2008-10-04 07:24:27 +00001088static QEMUMachine *first_machine = NULL;
aliguori6f338c32009-02-11 15:21:54 +00001089QEMUMachine *current_machine = NULL;
bellardcc1daa42005-06-05 14:49:17 +00001090
1091int qemu_register_machine(QEMUMachine *m)
1092{
1093 QEMUMachine **pm;
1094 pm = &first_machine;
1095 while (*pm != NULL)
1096 pm = &(*pm)->next;
1097 m->next = NULL;
1098 *pm = m;
1099 return 0;
1100}
1101
pbrook9596ebb2007-11-18 01:44:38 +00001102static QEMUMachine *find_machine(const char *name)
bellardcc1daa42005-06-05 14:49:17 +00001103{
1104 QEMUMachine *m;
1105
1106 for(m = first_machine; m != NULL; m = m->next) {
1107 if (!strcmp(m->name, name))
1108 return m;
Mark McLoughlin3f6599e2009-07-22 10:02:50 +01001109 if (m->alias && !strcmp(m->alias, name))
1110 return m;
bellardcc1daa42005-06-05 14:49:17 +00001111 }
1112 return NULL;
1113}
1114
Anthony Liguori0c257432009-05-21 20:41:01 -05001115static QEMUMachine *find_default_machine(void)
1116{
1117 QEMUMachine *m;
1118
1119 for(m = first_machine; m != NULL; m = m->next) {
1120 if (m->is_default) {
1121 return m;
1122 }
1123 }
1124 return NULL;
1125}
1126
bellardcc1daa42005-06-05 14:49:17 +00001127/***********************************************************/
bellard8a7ddc32004-03-31 19:00:16 +00001128/* main execution loop */
1129
pbrook9596ebb2007-11-18 01:44:38 +00001130static void gui_update(void *opaque)
bellard8a7ddc32004-03-31 19:00:16 +00001131{
aliguori7d957bd2009-01-15 22:14:11 +00001132 uint64_t interval = GUI_REFRESH_INTERVAL;
ths740733b2007-06-08 01:57:56 +00001133 DisplayState *ds = opaque;
aliguori7d957bd2009-01-15 22:14:11 +00001134 DisplayChangeListener *dcl = ds->listeners;
1135
Sheng Yang62a27442010-01-26 19:21:16 +08001136 qemu_flush_coalesced_mmio_buffer();
aliguori7d957bd2009-01-15 22:14:11 +00001137 dpy_refresh(ds);
1138
1139 while (dcl != NULL) {
1140 if (dcl->gui_timer_interval &&
1141 dcl->gui_timer_interval < interval)
1142 interval = dcl->gui_timer_interval;
1143 dcl = dcl->next;
1144 }
1145 qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock));
bellard8a7ddc32004-03-31 19:00:16 +00001146}
1147
blueswir19043b622009-01-21 19:28:13 +00001148static void nographic_update(void *opaque)
1149{
1150 uint64_t interval = GUI_REFRESH_INTERVAL;
1151
Sheng Yang62a27442010-01-26 19:21:16 +08001152 qemu_flush_coalesced_mmio_buffer();
blueswir19043b622009-01-21 19:28:13 +00001153 qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock));
1154}
1155
bellard0bd48852005-11-11 00:00:47 +00001156struct vm_change_state_entry {
1157 VMChangeStateHandler *cb;
1158 void *opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001159 QLIST_ENTRY (vm_change_state_entry) entries;
bellard0bd48852005-11-11 00:00:47 +00001160};
1161
Blue Swirl72cf2d42009-09-12 07:36:22 +00001162static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
bellard0bd48852005-11-11 00:00:47 +00001163
1164VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1165 void *opaque)
1166{
1167 VMChangeStateEntry *e;
1168
1169 e = qemu_mallocz(sizeof (*e));
bellard0bd48852005-11-11 00:00:47 +00001170
1171 e->cb = cb;
1172 e->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001173 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
bellard0bd48852005-11-11 00:00:47 +00001174 return e;
1175}
1176
1177void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1178{
Blue Swirl72cf2d42009-09-12 07:36:22 +00001179 QLIST_REMOVE (e, entries);
bellard0bd48852005-11-11 00:00:47 +00001180 qemu_free (e);
1181}
1182
Blue Swirl296af7c2010-03-29 19:23:50 +00001183void vm_state_notify(int running, int reason)
bellard0bd48852005-11-11 00:00:47 +00001184{
1185 VMChangeStateEntry *e;
1186
Stefan Hajnoczi94b0b5f2010-11-16 12:20:25 +00001187 trace_vm_state_notify(running, reason);
1188
bellard0bd48852005-11-11 00:00:47 +00001189 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
aliguori9781e042009-01-22 17:15:29 +00001190 e->cb(e->opaque, running, reason);
bellard0bd48852005-11-11 00:00:47 +00001191 }
1192}
1193
bellard8a7ddc32004-03-31 19:00:16 +00001194void vm_start(void)
1195{
1196 if (!vm_running) {
1197 cpu_enable_ticks();
1198 vm_running = 1;
aliguori9781e042009-01-22 17:15:29 +00001199 vm_state_notify(1, 0);
aliguorid6dc3d42009-04-24 18:04:07 +00001200 resume_all_vcpus();
Luiz Capitulino6ed2c482010-04-27 20:35:59 -03001201 monitor_protocol_event(QEVENT_RESUME, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00001202 }
1203}
1204
bellardbb0c6722004-06-20 12:37:32 +00001205/* reset/shutdown handler */
1206
1207typedef struct QEMUResetEntry {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001208 QTAILQ_ENTRY(QEMUResetEntry) entry;
bellardbb0c6722004-06-20 12:37:32 +00001209 QEMUResetHandler *func;
1210 void *opaque;
bellardbb0c6722004-06-20 12:37:32 +00001211} QEMUResetEntry;
1212
Blue Swirl72cf2d42009-09-12 07:36:22 +00001213static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1214 QTAILQ_HEAD_INITIALIZER(reset_handlers);
bellardbb0c6722004-06-20 12:37:32 +00001215static int reset_requested;
1216static int shutdown_requested;
bellard34751872005-07-02 14:31:34 +00001217static int powerdown_requested;
Jan Kiszka8cf71712011-02-07 12:19:16 +01001218static int debug_requested;
1219static int vmstop_requested;
bellardbb0c6722004-06-20 12:37:32 +00001220
aurel32cf7a2fe2008-03-18 06:53:05 +00001221int qemu_shutdown_requested(void)
1222{
1223 int r = shutdown_requested;
1224 shutdown_requested = 0;
1225 return r;
1226}
1227
1228int qemu_reset_requested(void)
1229{
1230 int r = reset_requested;
1231 reset_requested = 0;
1232 return r;
1233}
1234
1235int qemu_powerdown_requested(void)
1236{
1237 int r = powerdown_requested;
1238 powerdown_requested = 0;
1239 return r;
1240}
1241
aliguorie5689022009-04-24 18:03:54 +00001242static int qemu_debug_requested(void)
1243{
1244 int r = debug_requested;
1245 debug_requested = 0;
1246 return r;
1247}
1248
aliguori6e29f5d2009-04-24 18:04:02 +00001249static int qemu_vmstop_requested(void)
1250{
1251 int r = vmstop_requested;
1252 vmstop_requested = 0;
1253 return r;
1254}
1255
Jan Kiszkaa08d4362009-06-27 09:25:07 +02001256void qemu_register_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001257{
Jan Kiszka55ddfe82009-07-02 00:19:02 +02001258 QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry));
bellardbb0c6722004-06-20 12:37:32 +00001259
bellardbb0c6722004-06-20 12:37:32 +00001260 re->func = func;
1261 re->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001262 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
bellardbb0c6722004-06-20 12:37:32 +00001263}
1264
Jan Kiszkadda9b292009-07-02 00:19:02 +02001265void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001266{
1267 QEMUResetEntry *re;
1268
Blue Swirl72cf2d42009-09-12 07:36:22 +00001269 QTAILQ_FOREACH(re, &reset_handlers, entry) {
Jan Kiszkadda9b292009-07-02 00:19:02 +02001270 if (re->func == func && re->opaque == opaque) {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001271 QTAILQ_REMOVE(&reset_handlers, re, entry);
Jan Kiszkadda9b292009-07-02 00:19:02 +02001272 qemu_free(re);
1273 return;
1274 }
1275 }
1276}
1277
1278void qemu_system_reset(void)
1279{
1280 QEMUResetEntry *re, *nre;
1281
1282 /* reset all devices */
Blue Swirl72cf2d42009-09-12 07:36:22 +00001283 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
bellardbb0c6722004-06-20 12:37:32 +00001284 re->func(re->opaque);
1285 }
Luiz Capitulino81d9b782010-03-10 09:06:34 -06001286 monitor_protocol_event(QEVENT_RESET, NULL);
Jan Kiszkaea375f92010-03-01 19:10:30 +01001287 cpu_synchronize_all_post_reset();
bellardbb0c6722004-06-20 12:37:32 +00001288}
1289
1290void qemu_system_reset_request(void)
1291{
bellardd1beab82006-10-02 19:44:22 +00001292 if (no_reboot) {
1293 shutdown_requested = 1;
1294 } else {
1295 reset_requested = 1;
1296 }
Jan Kiszkab4a3d962011-02-01 22:15:43 +01001297 cpu_stop_current();
aliguorid9f75a42009-04-24 18:03:11 +00001298 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001299}
1300
1301void qemu_system_shutdown_request(void)
1302{
1303 shutdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001304 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001305}
1306
bellard34751872005-07-02 14:31:34 +00001307void qemu_system_powerdown_request(void)
1308{
1309 powerdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001310 qemu_notify_event();
1311}
1312
Jan Kiszka8cf71712011-02-07 12:19:16 +01001313void qemu_system_debug_request(void)
1314{
1315 debug_requested = 1;
Jan Kiszka83f338f2011-02-07 12:19:17 +01001316 qemu_notify_event();
Jan Kiszka8cf71712011-02-07 12:19:16 +01001317}
1318
1319void qemu_system_vmstop_request(int reason)
1320{
1321 vmstop_requested = reason;
1322 qemu_notify_event();
1323}
1324
Paolo Bonzinid6f4ade2010-03-10 11:38:54 +01001325void main_loop_wait(int nonblocking)
aliguori56f3a5d2008-10-31 18:07:17 +00001326{
1327 IOHandlerRecord *ioh;
1328 fd_set rfds, wfds, xfds;
1329 int ret, nfds;
1330 struct timeval tv;
Paolo Bonzinid6f4ade2010-03-10 11:38:54 +01001331 int timeout;
aliguori56f3a5d2008-10-31 18:07:17 +00001332
Paolo Bonzinid6f4ade2010-03-10 11:38:54 +01001333 if (nonblocking)
1334 timeout = 0;
1335 else {
1336 timeout = qemu_calculate_timeout();
1337 qemu_bh_update_timeout(&timeout);
1338 }
aliguori56f3a5d2008-10-31 18:07:17 +00001339
Jes Sorensen0d93ca72010-06-10 11:42:18 +02001340 os_host_main_loop_wait(&timeout);
aliguori56f3a5d2008-10-31 18:07:17 +00001341
bellardfd1dff42006-02-01 21:29:26 +00001342 /* poll any events */
1343 /* XXX: separate device handlers from system ones */
aliguori6abfbd72008-11-05 20:49:37 +00001344 nfds = -1;
bellardfd1dff42006-02-01 21:29:26 +00001345 FD_ZERO(&rfds);
1346 FD_ZERO(&wfds);
bellarde0356492006-05-01 13:33:02 +00001347 FD_ZERO(&xfds);
Juan Quintela31d4ee62010-03-11 17:55:37 +01001348 QLIST_FOREACH(ioh, &io_handlers, next) {
thscafffd42007-02-28 21:59:44 +00001349 if (ioh->deleted)
1350 continue;
bellardfd1dff42006-02-01 21:29:26 +00001351 if (ioh->fd_read &&
1352 (!ioh->fd_read_poll ||
1353 ioh->fd_read_poll(ioh->opaque) != 0)) {
1354 FD_SET(ioh->fd, &rfds);
1355 if (ioh->fd > nfds)
1356 nfds = ioh->fd;
1357 }
1358 if (ioh->fd_write) {
1359 FD_SET(ioh->fd, &wfds);
1360 if (ioh->fd > nfds)
1361 nfds = ioh->fd;
1362 }
1363 }
ths3b46e622007-09-17 08:09:54 +00001364
aliguori56f3a5d2008-10-31 18:07:17 +00001365 tv.tv_sec = timeout / 1000;
1366 tv.tv_usec = (timeout % 1000) * 1000;
1367
Jan Kiszkad918f232009-06-24 14:42:30 +02001368 slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
1369
aliguori48708522009-04-24 18:03:49 +00001370 qemu_mutex_unlock_iothread();
bellarde0356492006-05-01 13:33:02 +00001371 ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
aliguori48708522009-04-24 18:03:49 +00001372 qemu_mutex_lock_iothread();
bellardfd1dff42006-02-01 21:29:26 +00001373 if (ret > 0) {
Juan Quintela31d4ee62010-03-11 17:55:37 +01001374 IOHandlerRecord *pioh;
thscafffd42007-02-28 21:59:44 +00001375
Juan Quintela31d4ee62010-03-11 17:55:37 +01001376 QLIST_FOREACH_SAFE(ioh, &io_handlers, next, pioh) {
Stefan Hajnoczi0290b572010-11-03 14:29:44 +00001377 if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {
1378 ioh->fd_read(ioh->opaque);
1379 }
1380 if (!ioh->deleted && ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) {
1381 ioh->fd_write(ioh->opaque);
1382 }
1383
1384 /* Do this last in case read/write handlers marked it for deletion */
thscafffd42007-02-28 21:59:44 +00001385 if (ioh->deleted) {
Juan Quintela31d4ee62010-03-11 17:55:37 +01001386 QLIST_REMOVE(ioh, next);
thscafffd42007-02-28 21:59:44 +00001387 qemu_free(ioh);
Juan Quintela31d4ee62010-03-11 17:55:37 +01001388 }
thscafffd42007-02-28 21:59:44 +00001389 }
bellardfd1dff42006-02-01 21:29:26 +00001390 }
Jan Kiszkad918f232009-06-24 14:42:30 +02001391
1392 slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));
bellardc20709a2004-04-21 23:27:19 +00001393
Paolo Bonzinib6964822010-03-10 11:38:45 +01001394 qemu_run_all_timers();
Jan Kiszka21d5d122009-09-15 13:36:04 +02001395
pbrook423f0742007-05-23 00:06:54 +00001396 /* Check bottom-halves last in case any of the earlier events triggered
1397 them. */
1398 qemu_bh_poll();
ths3b46e622007-09-17 08:09:54 +00001399
bellard5905b2e2004-08-01 21:53:26 +00001400}
1401
Jan Kiszka46481d32011-02-01 22:15:47 +01001402#ifndef CONFIG_IOTHREAD
1403static int vm_request_pending(void)
aliguori43b96852009-04-24 18:03:33 +00001404{
Jan Kiszka46481d32011-02-01 22:15:47 +01001405 return powerdown_requested ||
1406 reset_requested ||
1407 shutdown_requested ||
1408 debug_requested ||
1409 vmstop_requested;
aliguori43b96852009-04-24 18:03:33 +00001410}
Jan Kiszka46481d32011-02-01 22:15:47 +01001411#endif
aliguori43b96852009-04-24 18:03:33 +00001412
Blue Swirld9c32312009-08-09 08:42:19 +00001413qemu_irq qemu_system_powerdown;
1414
aliguori43b96852009-04-24 18:03:33 +00001415static void main_loop(void)
1416{
Jan Kiszka8e1b90e2011-02-01 22:15:46 +01001417 bool nonblocking = false;
1418#ifdef CONFIG_PROFILER
1419 int64_t ti;
1420#endif
aliguori6e29f5d2009-04-24 18:04:02 +00001421 int r;
aliguori43b96852009-04-24 18:03:33 +00001422
Blue Swirl7277e022010-04-12 17:19:06 +00001423 qemu_main_loop_start();
aliguorid6dc3d42009-04-24 18:04:07 +00001424
aliguori6e29f5d2009-04-24 18:04:02 +00001425 for (;;) {
aliguorid6dc3d42009-04-24 18:04:07 +00001426#ifndef CONFIG_IOTHREAD
Jan Kiszka46481d32011-02-01 22:15:47 +01001427 nonblocking = cpu_exec_all();
1428 if (vm_request_pending()) {
1429 nonblocking = true;
1430 }
aliguorid6dc3d42009-04-24 18:04:07 +00001431#endif
aliguori43b96852009-04-24 18:03:33 +00001432#ifdef CONFIG_PROFILER
Jan Kiszka46481d32011-02-01 22:15:47 +01001433 ti = profile_getclock();
aliguori43b96852009-04-24 18:03:33 +00001434#endif
Jan Kiszka46481d32011-02-01 22:15:47 +01001435 main_loop_wait(nonblocking);
aliguori43b96852009-04-24 18:03:33 +00001436#ifdef CONFIG_PROFILER
Jan Kiszka46481d32011-02-01 22:15:47 +01001437 dev_time += profile_getclock() - ti;
aliguori43b96852009-04-24 18:03:33 +00001438#endif
aliguori43b96852009-04-24 18:03:33 +00001439
Jan Kiszka8cf71712011-02-07 12:19:16 +01001440 if (qemu_debug_requested()) {
1441 vm_stop(VMSTOP_DEBUG);
Luiz Capitulinob1a15e72009-11-26 22:59:04 -02001442 }
aliguori43b96852009-04-24 18:03:33 +00001443 if (qemu_shutdown_requested()) {
Blue Swirl242cd002009-12-04 18:05:45 +00001444 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
aliguori43b96852009-04-24 18:03:33 +00001445 if (no_shutdown) {
Jan Kiszkae07bbac2011-02-09 16:29:40 +01001446 vm_stop(VMSTOP_SHUTDOWN);
aliguori43b96852009-04-24 18:03:33 +00001447 no_shutdown = 0;
1448 } else
1449 break;
1450 }
aliguorid6dc3d42009-04-24 18:04:07 +00001451 if (qemu_reset_requested()) {
1452 pause_all_vcpus();
Jan Kiszkaa7ada152011-03-02 08:56:11 +01001453 cpu_synchronize_all_states();
aliguori43b96852009-04-24 18:03:33 +00001454 qemu_system_reset();
aliguorid6dc3d42009-04-24 18:04:07 +00001455 resume_all_vcpus();
1456 }
Blue Swirld9c32312009-08-09 08:42:19 +00001457 if (qemu_powerdown_requested()) {
Blue Swirl242cd002009-12-04 18:05:45 +00001458 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
Blue Swirld9c32312009-08-09 08:42:19 +00001459 qemu_irq_raise(qemu_system_powerdown);
1460 }
Luiz Capitulinob1a15e72009-11-26 22:59:04 -02001461 if ((r = qemu_vmstop_requested())) {
aliguori6e29f5d2009-04-24 18:04:02 +00001462 vm_stop(r);
Luiz Capitulinob1a15e72009-11-26 22:59:04 -02001463 }
aliguori43b96852009-04-24 18:03:33 +00001464 }
MORITA Kazutaka2bc93fe2010-05-28 11:44:57 +09001465 bdrv_close_all();
aliguorid6dc3d42009-04-24 18:04:07 +00001466 pause_all_vcpus();
bellardb4608c02003-06-27 17:34:32 +00001467}
1468
pbrook9bd7e6d2009-04-07 22:58:45 +00001469static void version(void)
1470{
Thomas Monjalonf75ca1a2010-04-28 14:42:01 +02001471 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
pbrook9bd7e6d2009-04-07 22:58:45 +00001472}
1473
ths15f82202007-06-29 23:26:08 +00001474static void help(int exitcode)
bellard0824d6f2003-06-24 13:42:40 +00001475{
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001476 const char *options_help =
Blue Swirlad960902010-03-29 19:23:52 +00001477#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1478 opt_help
blueswir15824d652009-03-28 06:44:27 +00001479#define DEFHEADING(text) stringify(text) "\n"
Jes Sorensen9f167322010-06-10 11:42:24 +02001480#include "qemu-options.def"
blueswir15824d652009-03-28 06:44:27 +00001481#undef DEF
1482#undef DEFHEADING
1483#undef GEN_DOCS
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001484 ;
1485 version();
1486 printf("usage: %s [options] [disk_image]\n"
malc3f020d72010-02-08 12:04:56 +03001487 "\n"
Thomas Monjalonf75ca1a2010-04-28 14:42:01 +02001488 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001489 "\n"
1490 "%s\n"
malc3f020d72010-02-08 12:04:56 +03001491 "During emulation, the following keys are useful:\n"
1492 "ctrl-alt-f toggle full screen\n"
1493 "ctrl-alt-n switch to virtual console 'n'\n"
1494 "ctrl-alt toggle mouse and keyboard grab\n"
1495 "\n"
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001496 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1497 "qemu",
1498 options_help);
ths15f82202007-06-29 23:26:08 +00001499 exit(exitcode);
bellard0824d6f2003-06-24 13:42:40 +00001500}
1501
bellardcd6f1162004-05-13 22:02:20 +00001502#define HAS_ARG 0x0001
1503
bellardcd6f1162004-05-13 22:02:20 +00001504typedef struct QEMUOption {
1505 const char *name;
1506 int flags;
1507 int index;
Blue Swirlad960902010-03-29 19:23:52 +00001508 uint32_t arch_mask;
bellardcd6f1162004-05-13 22:02:20 +00001509} QEMUOption;
1510
blueswir1dbed7e42008-10-01 19:38:09 +00001511static const QEMUOption qemu_options[] = {
Blue Swirlad960902010-03-29 19:23:52 +00001512 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1513#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1514 { option, opt_arg, opt_enum, arch_mask },
blueswir15824d652009-03-28 06:44:27 +00001515#define DEFHEADING(text)
Jes Sorensen9f167322010-06-10 11:42:24 +02001516#include "qemu-options.def"
blueswir15824d652009-03-28 06:44:27 +00001517#undef DEF
1518#undef DEFHEADING
1519#undef GEN_DOCS
bellardcd6f1162004-05-13 22:02:20 +00001520 { NULL },
bellardfc01f7e2003-06-30 10:03:06 +00001521};
malc3893c122008-09-28 00:42:05 +00001522static void select_vgahw (const char *p)
1523{
1524 const char *opts;
1525
Gerd Hoffmann64465292009-12-08 13:11:45 +01001526 default_vga = 0;
Zachary Amsden86176752009-07-30 00:15:02 -10001527 vga_interface_type = VGA_NONE;
malc3893c122008-09-28 00:42:05 +00001528 if (strstart(p, "std", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001529 vga_interface_type = VGA_STD;
malc3893c122008-09-28 00:42:05 +00001530 } else if (strstart(p, "cirrus", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001531 vga_interface_type = VGA_CIRRUS;
malc3893c122008-09-28 00:42:05 +00001532 } else if (strstart(p, "vmware", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001533 vga_interface_type = VGA_VMWARE;
aliguori94909d92009-04-22 15:19:53 +00001534 } else if (strstart(p, "xenfb", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001535 vga_interface_type = VGA_XENFB;
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +02001536 } else if (strstart(p, "qxl", &opts)) {
1537 vga_interface_type = VGA_QXL;
aliguori28b85ed2009-04-22 15:19:48 +00001538 } else if (!strstart(p, "none", &opts)) {
malc3893c122008-09-28 00:42:05 +00001539 invalid_vga:
1540 fprintf(stderr, "Unknown vga type: %s\n", p);
1541 exit(1);
1542 }
malccb5a7aa2008-09-28 00:42:12 +00001543 while (*opts) {
1544 const char *nextopt;
1545
1546 if (strstart(opts, ",retrace=", &nextopt)) {
1547 opts = nextopt;
1548 if (strstart(opts, "dumb", &nextopt))
1549 vga_retrace_method = VGA_RETRACE_DUMB;
1550 else if (strstart(opts, "precise", &nextopt))
1551 vga_retrace_method = VGA_RETRACE_PRECISE;
1552 else goto invalid_vga;
1553 } else goto invalid_vga;
1554 opts = nextopt;
1555 }
malc3893c122008-09-28 00:42:05 +00001556}
1557
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001558static int balloon_parse(const char *arg)
1559{
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001560 QemuOpts *opts;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001561
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001562 if (strcmp(arg, "none") == 0) {
1563 return 0;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001564 }
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001565
1566 if (!strncmp(arg, "virtio", 6)) {
1567 if (arg[6] == ',') {
1568 /* have params -> parse them */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001569 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001570 if (!opts)
1571 return -1;
1572 } else {
1573 /* create empty opts */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001574 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001575 }
1576 qemu_opt_set(opts, "driver", "virtio-balloon-pci");
1577 return 0;
1578 }
1579
1580 return -1;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001581}
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001582
Paul Brook5cea8592009-05-30 00:52:44 +01001583char *qemu_find_file(int type, const char *name)
1584{
1585 int len;
1586 const char *subdir;
1587 char *buf;
1588
1589 /* If name contains path separators then try it as a straight path. */
1590 if ((strchr(name, '/') || strchr(name, '\\'))
1591 && access(name, R_OK) == 0) {
Jean-Christophe DUBOIS73ffc802009-09-02 23:59:06 +02001592 return qemu_strdup(name);
Paul Brook5cea8592009-05-30 00:52:44 +01001593 }
1594 switch (type) {
1595 case QEMU_FILE_TYPE_BIOS:
1596 subdir = "";
1597 break;
1598 case QEMU_FILE_TYPE_KEYMAP:
1599 subdir = "keymaps/";
1600 break;
1601 default:
1602 abort();
1603 }
1604 len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
1605 buf = qemu_mallocz(len);
Blue Swirl3a417592009-06-09 19:12:21 +00001606 snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
Paul Brook5cea8592009-05-30 00:52:44 +01001607 if (access(buf, R_OK)) {
1608 qemu_free(buf);
1609 return NULL;
1610 }
1611 return buf;
1612}
1613
Markus Armbrusterff952ba2010-01-29 19:48:57 +01001614static int device_help_func(QemuOpts *opts, void *opaque)
1615{
1616 return qdev_device_help(opts);
1617}
1618
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02001619static int device_init_func(QemuOpts *opts, void *opaque)
1620{
1621 DeviceState *dev;
1622
1623 dev = qdev_device_add(opts);
1624 if (!dev)
1625 return -1;
1626 return 0;
1627}
1628
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01001629static int chardev_init_func(QemuOpts *opts, void *opaque)
1630{
1631 CharDriverState *chr;
1632
1633 chr = qemu_chr_open_opts(opts, NULL);
1634 if (!chr)
1635 return -1;
1636 return 0;
1637}
1638
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07001639#ifdef CONFIG_VIRTFS
Gautham R Shenoy74db9202010-04-29 17:44:43 +05301640static int fsdev_init_func(QemuOpts *opts, void *opaque)
1641{
1642 int ret;
1643 ret = qemu_fsdev_add(opts);
1644
1645 return ret;
1646}
1647#endif
1648
Gerd Hoffmann88589342009-12-08 13:11:50 +01001649static int mon_init_func(QemuOpts *opts, void *opaque)
1650{
1651 CharDriverState *chr;
1652 const char *chardev;
1653 const char *mode;
1654 int flags;
1655
1656 mode = qemu_opt_get(opts, "mode");
1657 if (mode == NULL) {
1658 mode = "readline";
1659 }
1660 if (strcmp(mode, "readline") == 0) {
1661 flags = MONITOR_USE_READLINE;
1662 } else if (strcmp(mode, "control") == 0) {
1663 flags = MONITOR_USE_CONTROL;
1664 } else {
1665 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
1666 exit(1);
1667 }
1668
Daniel P. Berrange39eaab92010-06-07 15:42:31 +01001669 if (qemu_opt_get_bool(opts, "pretty", 0))
1670 flags |= MONITOR_USE_PRETTY;
1671
Gerd Hoffmann88589342009-12-08 13:11:50 +01001672 if (qemu_opt_get_bool(opts, "default", 0))
1673 flags |= MONITOR_IS_DEFAULT;
1674
1675 chardev = qemu_opt_get(opts, "chardev");
1676 chr = qemu_chr_find(chardev);
1677 if (chr == NULL) {
1678 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
1679 exit(1);
1680 }
1681
1682 monitor_init(chr, flags);
1683 return 0;
1684}
1685
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01001686static void monitor_parse(const char *optarg, const char *mode)
Gerd Hoffmann88589342009-12-08 13:11:50 +01001687{
1688 static int monitor_device_index = 0;
1689 QemuOpts *opts;
1690 const char *p;
1691 char label[32];
1692 int def = 0;
1693
1694 if (strstart(optarg, "chardev:", &p)) {
1695 snprintf(label, sizeof(label), "%s", p);
1696 } else {
Jan Kiszka140e0652010-04-06 16:55:52 +02001697 snprintf(label, sizeof(label), "compat_monitor%d",
1698 monitor_device_index);
1699 if (monitor_device_index == 0) {
Gerd Hoffmann88589342009-12-08 13:11:50 +01001700 def = 1;
1701 }
1702 opts = qemu_chr_parse_compat(label, optarg);
1703 if (!opts) {
1704 fprintf(stderr, "parse error: %s\n", optarg);
1705 exit(1);
1706 }
1707 }
1708
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001709 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1);
Gerd Hoffmann88589342009-12-08 13:11:50 +01001710 if (!opts) {
1711 fprintf(stderr, "duplicate chardev: %s\n", label);
1712 exit(1);
1713 }
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01001714 qemu_opt_set(opts, "mode", mode);
Gerd Hoffmann88589342009-12-08 13:11:50 +01001715 qemu_opt_set(opts, "chardev", label);
1716 if (def)
1717 qemu_opt_set(opts, "default", "on");
1718 monitor_device_index++;
1719}
1720
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001721struct device_config {
1722 enum {
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001723 DEV_USB, /* -usbdevice */
1724 DEV_BT, /* -bt */
1725 DEV_SERIAL, /* -serial */
1726 DEV_PARALLEL, /* -parallel */
1727 DEV_VIRTCON, /* -virtioconsole */
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001728 DEV_DEBUGCON, /* -debugcon */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001729 } type;
1730 const char *cmdline;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001731 QTAILQ_ENTRY(device_config) next;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001732};
Blue Swirl72cf2d42009-09-12 07:36:22 +00001733QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001734
1735static void add_device_config(int type, const char *cmdline)
1736{
1737 struct device_config *conf;
1738
1739 conf = qemu_mallocz(sizeof(*conf));
1740 conf->type = type;
1741 conf->cmdline = cmdline;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001742 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001743}
1744
1745static int foreach_device_config(int type, int (*func)(const char *cmdline))
1746{
1747 struct device_config *conf;
1748 int rc;
1749
Blue Swirl72cf2d42009-09-12 07:36:22 +00001750 QTAILQ_FOREACH(conf, &device_configs, next) {
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001751 if (conf->type != type)
1752 continue;
1753 rc = func(conf->cmdline);
1754 if (0 != rc)
1755 return rc;
1756 }
1757 return 0;
1758}
1759
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01001760static int serial_parse(const char *devname)
1761{
1762 static int index = 0;
1763 char label[32];
1764
1765 if (strcmp(devname, "none") == 0)
1766 return 0;
1767 if (index == MAX_SERIAL_PORTS) {
1768 fprintf(stderr, "qemu: too many serial ports\n");
1769 exit(1);
1770 }
1771 snprintf(label, sizeof(label), "serial%d", index);
1772 serial_hds[index] = qemu_chr_open(label, devname, NULL);
1773 if (!serial_hds[index]) {
1774 fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
1775 devname, strerror(errno));
1776 return -1;
1777 }
1778 index++;
1779 return 0;
1780}
1781
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01001782static int parallel_parse(const char *devname)
1783{
1784 static int index = 0;
1785 char label[32];
1786
1787 if (strcmp(devname, "none") == 0)
1788 return 0;
1789 if (index == MAX_PARALLEL_PORTS) {
1790 fprintf(stderr, "qemu: too many parallel ports\n");
1791 exit(1);
1792 }
1793 snprintf(label, sizeof(label), "parallel%d", index);
1794 parallel_hds[index] = qemu_chr_open(label, devname, NULL);
1795 if (!parallel_hds[index]) {
1796 fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
1797 devname, strerror(errno));
1798 return -1;
1799 }
1800 index++;
1801 return 0;
1802}
1803
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001804static int virtcon_parse(const char *devname)
1805{
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001806 QemuOptsList *device = qemu_find_opts("device");
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001807 static int index = 0;
1808 char label[32];
Amit Shah392ecf52010-01-21 16:19:23 +05301809 QemuOpts *bus_opts, *dev_opts;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001810
1811 if (strcmp(devname, "none") == 0)
1812 return 0;
1813 if (index == MAX_VIRTIO_CONSOLES) {
1814 fprintf(stderr, "qemu: too many virtio consoles\n");
1815 exit(1);
1816 }
Amit Shah392ecf52010-01-21 16:19:23 +05301817
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001818 bus_opts = qemu_opts_create(device, NULL, 0);
Amit Shah392ecf52010-01-21 16:19:23 +05301819 qemu_opt_set(bus_opts, "driver", "virtio-serial");
1820
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001821 dev_opts = qemu_opts_create(device, NULL, 0);
Amit Shah392ecf52010-01-21 16:19:23 +05301822 qemu_opt_set(dev_opts, "driver", "virtconsole");
1823
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001824 snprintf(label, sizeof(label), "virtcon%d", index);
1825 virtcon_hds[index] = qemu_chr_open(label, devname, NULL);
1826 if (!virtcon_hds[index]) {
1827 fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
1828 devname, strerror(errno));
1829 return -1;
1830 }
Amit Shah392ecf52010-01-21 16:19:23 +05301831 qemu_opt_set(dev_opts, "chardev", label);
1832
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001833 index++;
1834 return 0;
1835}
1836
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001837static int debugcon_parse(const char *devname)
1838{
1839 QemuOpts *opts;
1840
1841 if (!qemu_chr_open("debugcon", devname, NULL)) {
1842 exit(1);
1843 }
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001844 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001845 if (!opts) {
1846 fprintf(stderr, "qemu: already have a debugcon device\n");
1847 exit(1);
1848 }
1849 qemu_opt_set(opts, "driver", "isa-debugcon");
1850 qemu_opt_set(opts, "chardev", "debugcon");
1851 return 0;
1852}
1853
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02001854void qemu_add_exit_notifier(Notifier *notify)
1855{
1856 notifier_list_add(&exit_notifiers, notify);
1857}
1858
1859void qemu_remove_exit_notifier(Notifier *notify)
1860{
1861 notifier_list_remove(&exit_notifiers, notify);
1862}
1863
1864static void qemu_run_exit_notifiers(void)
1865{
1866 notifier_list_notify(&exit_notifiers);
1867}
1868
Gleb Natapov4cab9462010-12-08 13:35:08 +02001869void qemu_add_machine_init_done_notifier(Notifier *notify)
1870{
1871 notifier_list_add(&machine_init_done_notifiers, notify);
1872}
1873
1874static void qemu_run_machine_init_done_notifiers(void)
1875{
1876 notifier_list_notify(&machine_init_done_notifiers);
1877}
1878
Anthony Liguori6530a972010-01-22 09:18:06 -06001879static const QEMUOption *lookup_opt(int argc, char **argv,
1880 const char **poptarg, int *poptind)
1881{
1882 const QEMUOption *popt;
1883 int optind = *poptind;
1884 char *r = argv[optind];
1885 const char *optarg;
1886
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001887 loc_set_cmdline(argv, optind, 1);
Anthony Liguori6530a972010-01-22 09:18:06 -06001888 optind++;
1889 /* Treat --foo the same as -foo. */
1890 if (r[1] == '-')
1891 r++;
1892 popt = qemu_options;
1893 for(;;) {
1894 if (!popt->name) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001895 error_report("invalid option");
Anthony Liguori6530a972010-01-22 09:18:06 -06001896 exit(1);
1897 }
1898 if (!strcmp(popt->name, r + 1))
1899 break;
1900 popt++;
1901 }
1902 if (popt->flags & HAS_ARG) {
1903 if (optind >= argc) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001904 error_report("requires an argument");
Anthony Liguori6530a972010-01-22 09:18:06 -06001905 exit(1);
1906 }
1907 optarg = argv[optind++];
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001908 loc_set_cmdline(argv, optind - 2, 2);
Anthony Liguori6530a972010-01-22 09:18:06 -06001909 } else {
1910 optarg = NULL;
1911 }
1912
1913 *poptarg = optarg;
1914 *poptind = optind;
1915
1916 return popt;
1917}
1918
malc902b3d52008-12-10 19:18:40 +00001919int main(int argc, char **argv, char **envp)
bellard0824d6f2003-06-24 13:42:40 +00001920{
aliguori59030a82009-04-05 18:43:41 +00001921 const char *gdbstub_dev = NULL;
thse4bcb142007-12-02 04:51:10 +00001922 int i;
Eduardo Habkostda1fcfd2010-04-06 19:22:07 -03001923 int snapshot, linux_boot;
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01001924 const char *icount_option = NULL;
bellard7f7f9872003-10-30 01:11:23 +00001925 const char *initrd_filename;
bellarda20dd502003-09-30 21:07:02 +00001926 const char *kernel_filename, *kernel_cmdline;
Anthony Liguori195325a2009-10-30 12:42:29 -05001927 char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
aliguori3023f3322009-01-16 19:04:14 +00001928 DisplayState *ds;
aliguori7d957bd2009-01-15 22:14:11 +00001929 DisplayChangeListener *dcl;
bellard46d47672004-11-16 01:45:27 +00001930 int cyls, heads, secs, translation;
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02001931 QemuOpts *hda_opts = NULL, *opts;
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02001932 QemuOptsList *olist;
bellardcd6f1162004-05-13 22:02:20 +00001933 int optind;
Anthony Liguori6530a972010-01-22 09:18:06 -06001934 const char *optarg;
bellardd63d3072004-10-03 13:29:03 +00001935 const char *loadvm = NULL;
bellardcc1daa42005-06-05 14:49:17 +00001936 QEMUMachine *machine;
j_mayer94fc95c2007-03-05 19:44:02 +00001937 const char *cpu_model;
bellard26a5f132008-05-28 12:30:31 +00001938 int tb_size;
ths93815bc2007-03-19 15:58:31 +00001939 const char *pid_file = NULL;
aliguori5bb79102008-10-13 03:12:02 +00001940 const char *incoming = NULL;
Anthony Liguori993fbfd2009-05-21 16:54:00 -05001941 int show_vnc_port = 0;
Anthony Liguori292444c2010-01-21 10:57:58 -06001942 int defconfig = 1;
Prerna Saxenaab6540d2010-08-09 11:48:32 +01001943 const char *trace_file = NULL;
Stefan Hajnoczi0b5538c2011-02-26 18:38:39 +00001944
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02001945 atexit(qemu_run_exit_notifiers);
Markus Armbruster65abca02010-02-24 14:37:14 +01001946 error_set_progname(argv[0]);
1947
Jan Kiszka68752042009-09-15 13:36:04 +02001948 init_clocks();
1949
malc902b3d52008-12-10 19:18:40 +00001950 qemu_cache_utils_init(envp);
1951
Blue Swirl72cf2d42009-09-12 07:36:22 +00001952 QLIST_INIT (&vm_change_state_head);
Jes Sorensenfe98ac12010-06-10 11:42:21 +02001953 os_setup_early_signal_handling();
bellardbe995c22006-06-25 16:25:21 +00001954
Anthony Liguorif80f9ec2009-05-20 18:38:09 -05001955 module_call_init(MODULE_INIT_MACHINE);
Anthony Liguori0c257432009-05-21 20:41:01 -05001956 machine = find_default_machine();
j_mayer94fc95c2007-03-05 19:44:02 +00001957 cpu_model = NULL;
bellardfc01f7e2003-06-30 10:03:06 +00001958 initrd_filename = NULL;
aurel324fc5d072008-04-27 21:39:40 +00001959 ram_size = 0;
bellard33e39632003-07-06 17:15:21 +00001960 snapshot = 0;
bellarda20dd502003-09-30 21:07:02 +00001961 kernel_filename = NULL;
1962 kernel_cmdline = "";
bellardc4b1fcc2004-03-14 21:44:30 +00001963 cyls = heads = secs = 0;
bellard46d47672004-11-16 01:45:27 +00001964 translation = BIOS_ATA_TRANSLATION_AUTO;
bellardc4b1fcc2004-03-14 21:44:30 +00001965
aliguori268a3622009-04-21 22:30:27 +00001966 for (i = 0; i < MAX_NODES; i++) {
1967 node_mem[i] = 0;
1968 node_cpumask[i] = 0;
1969 }
1970
aliguori268a3622009-04-21 22:30:27 +00001971 nb_numa_nodes = 0;
bellard7c9d8e02005-11-15 22:16:05 +00001972 nb_nics = 0;
ths3b46e622007-09-17 08:09:54 +00001973
bellard26a5f132008-05-28 12:30:31 +00001974 tb_size = 0;
blueswir141bd6392008-10-05 09:56:21 +00001975 autostart= 1;
1976
Anthony Liguori292444c2010-01-21 10:57:58 -06001977 /* first pass of option parsing */
1978 optind = 1;
1979 while (optind < argc) {
1980 if (argv[optind][0] != '-') {
1981 /* disk image */
Anthony Liguori28e68d62010-01-27 10:46:00 -06001982 optind++;
Anthony Liguori292444c2010-01-21 10:57:58 -06001983 continue;
1984 } else {
1985 const QEMUOption *popt;
1986
1987 popt = lookup_opt(argc, argv, &optarg, &optind);
1988 switch (popt->index) {
1989 case QEMU_OPTION_nodefconfig:
1990 defconfig=0;
1991 break;
1992 }
1993 }
1994 }
1995
1996 if (defconfig) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01001997 int ret;
Markus Armbrustercf5a65a2010-02-18 19:48:33 +01001998
Kevin Wolfdcfb0932010-03-05 17:25:55 +01001999 ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
Kevin Wolf019e78b2010-05-17 10:36:47 +02002000 if (ret < 0 && ret != -ENOENT) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002001 exit(1);
Anthony Liguori292444c2010-01-21 10:57:58 -06002002 }
2003
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002004 ret = qemu_read_config_file(arch_config_name);
Kevin Wolf019e78b2010-05-17 10:36:47 +02002005 if (ret < 0 && ret != -ENOENT) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002006 exit(1);
Anthony Liguori292444c2010-01-21 10:57:58 -06002007 }
2008 }
Blue Swirlde06f8d2010-03-29 19:23:50 +00002009 cpudef_init();
Anthony Liguori292444c2010-01-21 10:57:58 -06002010
2011 /* second pass of option parsing */
bellardcd6f1162004-05-13 22:02:20 +00002012 optind = 1;
bellard0824d6f2003-06-24 13:42:40 +00002013 for(;;) {
bellardcd6f1162004-05-13 22:02:20 +00002014 if (optind >= argc)
bellard0824d6f2003-06-24 13:42:40 +00002015 break;
Anthony Liguori6530a972010-01-22 09:18:06 -06002016 if (argv[optind][0] != '-') {
Markus Armbruster2292dda2011-01-28 11:21:41 +01002017 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
bellardcd6f1162004-05-13 22:02:20 +00002018 } else {
2019 const QEMUOption *popt;
2020
Anthony Liguori6530a972010-01-22 09:18:06 -06002021 popt = lookup_opt(argc, argv, &optarg, &optind);
Blue Swirlad960902010-03-29 19:23:52 +00002022 if (!(popt->arch_mask & arch_type)) {
2023 printf("Option %s not supported for this target\n", popt->name);
2024 exit(1);
2025 }
bellardcd6f1162004-05-13 22:02:20 +00002026 switch(popt->index) {
bellardcc1daa42005-06-05 14:49:17 +00002027 case QEMU_OPTION_M:
2028 machine = find_machine(optarg);
2029 if (!machine) {
2030 QEMUMachine *m;
2031 printf("Supported machines are:\n");
2032 for(m = first_machine; m != NULL; m = m->next) {
Mark McLoughlin3f6599e2009-07-22 10:02:50 +01002033 if (m->alias)
2034 printf("%-10s %s (alias of %s)\n",
2035 m->alias, m->desc, m->name);
bellardcc1daa42005-06-05 14:49:17 +00002036 printf("%-10s %s%s\n",
ths5fafdf22007-09-16 21:08:06 +00002037 m->name, m->desc,
Anthony Liguori0c257432009-05-21 20:41:01 -05002038 m->is_default ? " (default)" : "");
bellardcc1daa42005-06-05 14:49:17 +00002039 }
ths15f82202007-06-29 23:26:08 +00002040 exit(*optarg != '?');
bellardcc1daa42005-06-05 14:49:17 +00002041 }
2042 break;
j_mayer94fc95c2007-03-05 19:44:02 +00002043 case QEMU_OPTION_cpu:
2044 /* hw initialization will check this */
ths15f82202007-06-29 23:26:08 +00002045 if (*optarg == '?') {
Blue Swirl262353c2010-05-04 19:55:35 +00002046 list_cpus(stdout, &fprintf, optarg);
ths15f82202007-06-29 23:26:08 +00002047 exit(0);
j_mayer94fc95c2007-03-05 19:44:02 +00002048 } else {
2049 cpu_model = optarg;
2050 }
2051 break;
bellardcd6f1162004-05-13 22:02:20 +00002052 case QEMU_OPTION_initrd:
bellardfc01f7e2003-06-30 10:03:06 +00002053 initrd_filename = optarg;
2054 break;
bellardcd6f1162004-05-13 22:02:20 +00002055 case QEMU_OPTION_hda:
Markus Armbruster5645b0f2011-01-31 11:50:09 +01002056 {
2057 char buf[256];
2058 if (cyls == 0)
2059 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2060 else
2061 snprintf(buf, sizeof(buf),
2062 "%s,cyls=%d,heads=%d,secs=%d%s",
2063 HD_OPTS , cyls, heads, secs,
2064 translation == BIOS_ATA_TRANSLATION_LBA ?
thse4bcb142007-12-02 04:51:10 +00002065 ",trans=lba" :
Markus Armbruster5645b0f2011-01-31 11:50:09 +01002066 translation == BIOS_ATA_TRANSLATION_NONE ?
thse4bcb142007-12-02 04:51:10 +00002067 ",trans=none" : "");
Markus Armbruster5645b0f2011-01-31 11:50:09 +01002068 drive_add(IF_DEFAULT, 0, optarg, buf);
2069 break;
2070 }
bellardcd6f1162004-05-13 22:02:20 +00002071 case QEMU_OPTION_hdb:
bellardcc1daa42005-06-05 14:49:17 +00002072 case QEMU_OPTION_hdc:
2073 case QEMU_OPTION_hdd:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002074 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2075 HD_OPTS);
bellardfc01f7e2003-06-30 10:03:06 +00002076 break;
thse4bcb142007-12-02 04:51:10 +00002077 case QEMU_OPTION_drive:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002078 drive_def(optarg);
thse4bcb142007-12-02 04:51:10 +00002079 break;
Gerd Hoffmannd058fe02009-07-31 12:25:36 +02002080 case QEMU_OPTION_set:
2081 if (qemu_set_option(optarg) != 0)
2082 exit(1);
2083 break;
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01002084 case QEMU_OPTION_global:
2085 if (qemu_global_option(optarg) != 0)
2086 exit(1);
2087 break;
balrog3e3d5812007-04-30 02:09:25 +00002088 case QEMU_OPTION_mtdblock:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002089 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
balrog3e3d5812007-04-30 02:09:25 +00002090 break;
pbrooka1bb27b2007-04-06 16:49:48 +00002091 case QEMU_OPTION_sd:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002092 drive_add(IF_SD, 0, optarg, SD_OPTS);
pbrooka1bb27b2007-04-06 16:49:48 +00002093 break;
j_mayer86f55662007-04-24 06:52:59 +00002094 case QEMU_OPTION_pflash:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002095 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
j_mayer86f55662007-04-24 06:52:59 +00002096 break;
bellardcd6f1162004-05-13 22:02:20 +00002097 case QEMU_OPTION_snapshot:
bellard33e39632003-07-06 17:15:21 +00002098 snapshot = 1;
2099 break;
bellardcd6f1162004-05-13 22:02:20 +00002100 case QEMU_OPTION_hdachs:
bellard330d0412003-07-26 18:11:40 +00002101 {
bellard330d0412003-07-26 18:11:40 +00002102 const char *p;
2103 p = optarg;
2104 cyls = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002105 if (cyls < 1 || cyls > 16383)
2106 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00002107 if (*p != ',')
2108 goto chs_fail;
2109 p++;
2110 heads = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002111 if (heads < 1 || heads > 16)
2112 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00002113 if (*p != ',')
2114 goto chs_fail;
2115 p++;
2116 secs = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002117 if (secs < 1 || secs > 63)
2118 goto chs_fail;
2119 if (*p == ',') {
2120 p++;
2121 if (!strcmp(p, "none"))
2122 translation = BIOS_ATA_TRANSLATION_NONE;
2123 else if (!strcmp(p, "lba"))
2124 translation = BIOS_ATA_TRANSLATION_LBA;
2125 else if (!strcmp(p, "auto"))
2126 translation = BIOS_ATA_TRANSLATION_AUTO;
2127 else
2128 goto chs_fail;
2129 } else if (*p != '\0') {
bellardc4b1fcc2004-03-14 21:44:30 +00002130 chs_fail:
bellard46d47672004-11-16 01:45:27 +00002131 fprintf(stderr, "qemu: invalid physical CHS format\n");
2132 exit(1);
bellardc4b1fcc2004-03-14 21:44:30 +00002133 }
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02002134 if (hda_opts != NULL) {
2135 char num[16];
2136 snprintf(num, sizeof(num), "%d", cyls);
2137 qemu_opt_set(hda_opts, "cyls", num);
2138 snprintf(num, sizeof(num), "%d", heads);
2139 qemu_opt_set(hda_opts, "heads", num);
2140 snprintf(num, sizeof(num), "%d", secs);
2141 qemu_opt_set(hda_opts, "secs", num);
2142 if (translation == BIOS_ATA_TRANSLATION_LBA)
2143 qemu_opt_set(hda_opts, "trans", "lba");
2144 if (translation == BIOS_ATA_TRANSLATION_NONE)
2145 qemu_opt_set(hda_opts, "trans", "none");
2146 }
bellard330d0412003-07-26 18:11:40 +00002147 }
2148 break;
aliguori268a3622009-04-21 22:30:27 +00002149 case QEMU_OPTION_numa:
2150 if (nb_numa_nodes >= MAX_NODES) {
2151 fprintf(stderr, "qemu: too many NUMA nodes\n");
2152 exit(1);
2153 }
2154 numa_add(optarg);
2155 break;
bellardcd6f1162004-05-13 22:02:20 +00002156 case QEMU_OPTION_nographic:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002157 display_type = DT_NOGRAPHIC;
bellarda20dd502003-09-30 21:07:02 +00002158 break;
balrog4d3b6f62008-02-10 16:33:14 +00002159#ifdef CONFIG_CURSES
2160 case QEMU_OPTION_curses:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002161 display_type = DT_CURSES;
balrog4d3b6f62008-02-10 16:33:14 +00002162 break;
2163#endif
balroga171fe32007-04-30 01:48:07 +00002164 case QEMU_OPTION_portrait:
2165 graphic_rotate = 1;
2166 break;
bellardcd6f1162004-05-13 22:02:20 +00002167 case QEMU_OPTION_kernel:
bellarda20dd502003-09-30 21:07:02 +00002168 kernel_filename = optarg;
2169 break;
bellardcd6f1162004-05-13 22:02:20 +00002170 case QEMU_OPTION_append:
bellarda20dd502003-09-30 21:07:02 +00002171 kernel_cmdline = optarg;
bellard313aa562003-08-10 21:52:11 +00002172 break;
bellardcd6f1162004-05-13 22:02:20 +00002173 case QEMU_OPTION_cdrom:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002174 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
bellard36b486b2003-11-11 13:36:08 +00002175 break;
bellardcd6f1162004-05-13 22:02:20 +00002176 case QEMU_OPTION_boot:
j_mayer28c5af52007-11-11 01:50:45 +00002177 {
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002178 static const char * const params[] = {
Jan Kiszka95387492009-07-02 00:19:02 +02002179 "order", "once", "menu", NULL
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002180 };
2181 char buf[sizeof(boot_devices)];
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002182 char *standard_boot_devices;
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002183 int legacy = 0;
2184
2185 if (!strchr(optarg, '=')) {
2186 legacy = 1;
2187 pstrcpy(buf, sizeof(buf), optarg);
2188 } else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
2189 fprintf(stderr,
2190 "qemu: unknown boot parameter '%s' in '%s'\n",
2191 buf, optarg);
2192 exit(1);
2193 }
2194
2195 if (legacy ||
2196 get_param_value(buf, sizeof(buf), "order", optarg)) {
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -03002197 validate_bootdevices(buf);
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002198 pstrcpy(boot_devices, sizeof(boot_devices), buf);
j_mayer28c5af52007-11-11 01:50:45 +00002199 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002200 if (!legacy) {
2201 if (get_param_value(buf, sizeof(buf),
2202 "once", optarg)) {
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -03002203 validate_bootdevices(buf);
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002204 standard_boot_devices = qemu_strdup(boot_devices);
2205 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2206 qemu_register_reset(restore_boot_devices,
2207 standard_boot_devices);
2208 }
Jan Kiszka95387492009-07-02 00:19:02 +02002209 if (get_param_value(buf, sizeof(buf),
2210 "menu", optarg)) {
2211 if (!strcmp(buf, "on")) {
2212 boot_menu = 1;
2213 } else if (!strcmp(buf, "off")) {
2214 boot_menu = 0;
2215 } else {
2216 fprintf(stderr,
2217 "qemu: invalid option value '%s'\n",
2218 buf);
2219 exit(1);
2220 }
2221 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002222 }
bellard36b486b2003-11-11 13:36:08 +00002223 }
2224 break;
bellardcd6f1162004-05-13 22:02:20 +00002225 case QEMU_OPTION_fda:
bellardcd6f1162004-05-13 22:02:20 +00002226 case QEMU_OPTION_fdb:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002227 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2228 optarg, FD_OPTS);
bellardc45886d2004-01-05 00:02:06 +00002229 break;
bellard52ca8d62006-06-14 16:03:05 +00002230 case QEMU_OPTION_no_fd_bootchk:
2231 fd_bootchk = 0;
2232 break;
Mark McLoughlina1ea4582009-10-08 19:58:26 +01002233 case QEMU_OPTION_netdev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002234 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
Mark McLoughlina1ea4582009-10-08 19:58:26 +01002235 exit(1);
2236 }
2237 break;
bellard7c9d8e02005-11-15 22:16:05 +00002238 case QEMU_OPTION_net:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002239 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
bellardc4b1fcc2004-03-14 21:44:30 +00002240 exit(1);
2241 }
bellard702c6512004-04-02 21:21:32 +00002242 break;
bellardc7f74642004-08-24 21:57:12 +00002243#ifdef CONFIG_SLIRP
2244 case QEMU_OPTION_tftp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02002245 legacy_tftp_prefix = optarg;
bellard9bf05442004-08-25 22:12:49 +00002246 break;
ths47d5d012007-02-20 00:05:08 +00002247 case QEMU_OPTION_bootp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02002248 legacy_bootp_filename = optarg;
ths47d5d012007-02-20 00:05:08 +00002249 break;
bellard9bf05442004-08-25 22:12:49 +00002250 case QEMU_OPTION_redir:
Markus Armbruster07527062009-10-06 12:16:57 +01002251 if (net_slirp_redir(optarg) < 0)
2252 exit(1);
bellard9bf05442004-08-25 22:12:49 +00002253 break;
bellardc7f74642004-08-24 21:57:12 +00002254#endif
balrogdc72ac12008-11-09 00:04:26 +00002255 case QEMU_OPTION_bt:
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002256 add_device_config(DEV_BT, optarg);
balrogdc72ac12008-11-09 00:04:26 +00002257 break;
bellard1d14ffa2005-10-30 18:58:22 +00002258 case QEMU_OPTION_audio_help:
Blue Swirlad960902010-03-29 19:23:52 +00002259 if (!(audio_available())) {
2260 printf("Option %s not supported for this target\n", popt->name);
2261 exit(1);
2262 }
bellard1d14ffa2005-10-30 18:58:22 +00002263 AUD_help ();
2264 exit (0);
2265 break;
2266 case QEMU_OPTION_soundhw:
Blue Swirlad960902010-03-29 19:23:52 +00002267 if (!(audio_available())) {
2268 printf("Option %s not supported for this target\n", popt->name);
2269 exit(1);
2270 }
bellard1d14ffa2005-10-30 18:58:22 +00002271 select_soundhw (optarg);
2272 break;
bellardcd6f1162004-05-13 22:02:20 +00002273 case QEMU_OPTION_h:
ths15f82202007-06-29 23:26:08 +00002274 help(0);
bellardcd6f1162004-05-13 22:02:20 +00002275 break;
pbrook9bd7e6d2009-04-07 22:58:45 +00002276 case QEMU_OPTION_version:
2277 version();
2278 exit(0);
2279 break;
aurel3200f82b82008-04-27 21:12:55 +00002280 case QEMU_OPTION_m: {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +01002281 int64_t value;
aurel3200f82b82008-04-27 21:12:55 +00002282
Jes Sorensen9f9b17a2010-10-21 17:15:46 +02002283 value = strtosz(optarg, NULL);
2284 if (value < 0) {
aurel3200f82b82008-04-27 21:12:55 +00002285 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
bellardcd6f1162004-05-13 22:02:20 +00002286 exit(1);
2287 }
aurel3200f82b82008-04-27 21:12:55 +00002288
2289 /* On 32-bit hosts, QEMU is limited by virtual address space */
Anthony Liguori4a1418e2009-08-10 17:07:24 -05002290 if (value > (2047 << 20) && HOST_LONG_BITS == 32) {
aurel3200f82b82008-04-27 21:12:55 +00002291 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
2292 exit(1);
2293 }
Anthony Liguoric227f092009-10-01 16:12:16 -05002294 if (value != (uint64_t)(ram_addr_t)value) {
aurel3200f82b82008-04-27 21:12:55 +00002295 fprintf(stderr, "qemu: ram size too large\n");
2296 exit(1);
2297 }
2298 ram_size = value;
bellardcd6f1162004-05-13 22:02:20 +00002299 break;
aurel3200f82b82008-04-27 21:12:55 +00002300 }
Marcelo Tosattic9027602010-03-01 20:25:08 -03002301 case QEMU_OPTION_mempath:
2302 mem_path = optarg;
2303 break;
2304#ifdef MAP_POPULATE
2305 case QEMU_OPTION_mem_prealloc:
2306 mem_prealloc = 1;
2307 break;
2308#endif
bellardcd6f1162004-05-13 22:02:20 +00002309 case QEMU_OPTION_d:
Blue Swirlde06f8d2010-03-29 19:23:50 +00002310 set_cpu_log(optarg);
bellardcd6f1162004-05-13 22:02:20 +00002311 break;
bellardcd6f1162004-05-13 22:02:20 +00002312 case QEMU_OPTION_s:
aliguori59030a82009-04-05 18:43:41 +00002313 gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT;
bellardcd6f1162004-05-13 22:02:20 +00002314 break;
aliguori59030a82009-04-05 18:43:41 +00002315 case QEMU_OPTION_gdb:
2316 gdbstub_dev = optarg;
bellardcd6f1162004-05-13 22:02:20 +00002317 break;
bellardcd6f1162004-05-13 22:02:20 +00002318 case QEMU_OPTION_L:
Paul Brook5cea8592009-05-30 00:52:44 +01002319 data_dir = optarg;
bellardcd6f1162004-05-13 22:02:20 +00002320 break;
j_mayer1192dad2007-10-05 13:08:35 +00002321 case QEMU_OPTION_bios:
2322 bios_name = optarg;
2323 break;
aurel321b530a62009-04-05 20:08:59 +00002324 case QEMU_OPTION_singlestep:
2325 singlestep = 1;
2326 break;
bellardcd6f1162004-05-13 22:02:20 +00002327 case QEMU_OPTION_S:
pbrook3c07f8e2007-01-21 16:47:01 +00002328 autostart = 0;
bellardcd6f1162004-05-13 22:02:20 +00002329 break;
bellard3d11d0e2004-12-12 16:56:30 +00002330 case QEMU_OPTION_k:
2331 keyboard_layout = optarg;
2332 break;
bellardee22c2f2004-06-03 12:49:50 +00002333 case QEMU_OPTION_localtime:
2334 rtc_utc = 0;
2335 break;
malc3893c122008-09-28 00:42:05 +00002336 case QEMU_OPTION_vga:
2337 select_vgahw (optarg);
bellard1bfe8562004-07-08 21:17:50 +00002338 break;
bellarde9b137c2004-06-21 16:46:10 +00002339 case QEMU_OPTION_g:
2340 {
2341 const char *p;
2342 int w, h, depth;
2343 p = optarg;
2344 w = strtol(p, (char **)&p, 10);
2345 if (w <= 0) {
2346 graphic_error:
2347 fprintf(stderr, "qemu: invalid resolution or depth\n");
2348 exit(1);
2349 }
2350 if (*p != 'x')
2351 goto graphic_error;
2352 p++;
2353 h = strtol(p, (char **)&p, 10);
2354 if (h <= 0)
2355 goto graphic_error;
2356 if (*p == 'x') {
2357 p++;
2358 depth = strtol(p, (char **)&p, 10);
ths5fafdf22007-09-16 21:08:06 +00002359 if (depth != 8 && depth != 15 && depth != 16 &&
bellarde9b137c2004-06-21 16:46:10 +00002360 depth != 24 && depth != 32)
2361 goto graphic_error;
2362 } else if (*p == '\0') {
2363 depth = graphic_depth;
2364 } else {
2365 goto graphic_error;
2366 }
ths3b46e622007-09-17 08:09:54 +00002367
bellarde9b137c2004-06-21 16:46:10 +00002368 graphic_width = w;
2369 graphic_height = h;
2370 graphic_depth = depth;
2371 }
2372 break;
ths20d8a3e2007-02-18 17:04:49 +00002373 case QEMU_OPTION_echr:
2374 {
2375 char *r;
2376 term_escape_char = strtol(optarg, &r, 0);
2377 if (r == optarg)
2378 printf("Bad argument to echr\n");
2379 break;
2380 }
bellard82c643f2004-07-14 17:28:13 +00002381 case QEMU_OPTION_monitor:
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002382 monitor_parse(optarg, "readline");
2383 default_monitor = 0;
2384 break;
2385 case QEMU_OPTION_qmp:
2386 monitor_parse(optarg, "control");
Anthony Liguori2d114dc2010-03-21 14:14:38 -05002387 default_monitor = 0;
bellard82c643f2004-07-14 17:28:13 +00002388 break;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002389 case QEMU_OPTION_mon:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002390 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002391 if (!opts) {
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002392 exit(1);
2393 }
Anthony Liguori2d114dc2010-03-21 14:14:38 -05002394 default_monitor = 0;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002395 break;
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002396 case QEMU_OPTION_chardev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002397 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002398 if (!opts) {
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002399 exit(1);
2400 }
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002401 break;
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302402 case QEMU_OPTION_fsdev:
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002403 olist = qemu_find_opts("fsdev");
2404 if (!olist) {
2405 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
2406 exit(1);
2407 }
2408 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302409 if (!opts) {
2410 fprintf(stderr, "parse error: %s\n", optarg);
2411 exit(1);
2412 }
2413 break;
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302414 case QEMU_OPTION_virtfs: {
2415 char *arg_fsdev = NULL;
2416 char *arg_9p = NULL;
2417 int len = 0;
2418
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002419 olist = qemu_find_opts("virtfs");
2420 if (!olist) {
2421 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
2422 exit(1);
2423 }
2424 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302425 if (!opts) {
2426 fprintf(stderr, "parse error: %s\n", optarg);
2427 exit(1);
2428 }
2429
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07002430 if (qemu_opt_get(opts, "fstype") == NULL ||
2431 qemu_opt_get(opts, "mount_tag") == NULL ||
2432 qemu_opt_get(opts, "path") == NULL ||
2433 qemu_opt_get(opts, "security_model") == NULL) {
2434 fprintf(stderr, "Usage: -virtfs fstype,path=/share_path/,"
Aneesh Kumar K.V12848bf2010-09-02 11:09:07 +05302435 "security_model=[mapped|passthrough|none],"
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07002436 "mnt_tag=tag.\n");
2437 exit(1);
2438 }
2439
2440 len = strlen(",id=,path=,security_model=");
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302441 len += strlen(qemu_opt_get(opts, "fstype"));
2442 len += strlen(qemu_opt_get(opts, "mount_tag"));
2443 len += strlen(qemu_opt_get(opts, "path"));
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07002444 len += strlen(qemu_opt_get(opts, "security_model"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302445 arg_fsdev = qemu_malloc((len + 1) * sizeof(*arg_fsdev));
2446
Aneesh Kumar K.Vc93031e2010-09-02 21:47:59 +05302447 snprintf(arg_fsdev, (len + 1) * sizeof(*arg_fsdev),
Blue Swirlcb93bbd2010-08-31 20:16:59 +00002448 "%s,id=%s,path=%s,security_model=%s",
2449 qemu_opt_get(opts, "fstype"),
2450 qemu_opt_get(opts, "mount_tag"),
2451 qemu_opt_get(opts, "path"),
2452 qemu_opt_get(opts, "security_model"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302453
2454 len = strlen("virtio-9p-pci,fsdev=,mount_tag=");
2455 len += 2*strlen(qemu_opt_get(opts, "mount_tag"));
2456 arg_9p = qemu_malloc((len + 1) * sizeof(*arg_9p));
2457
Aneesh Kumar K.Vc93031e2010-09-02 21:47:59 +05302458 snprintf(arg_9p, (len + 1) * sizeof(*arg_9p),
Blue Swirlcb93bbd2010-08-31 20:16:59 +00002459 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2460 qemu_opt_get(opts, "mount_tag"),
2461 qemu_opt_get(opts, "mount_tag"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302462
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002463 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev, 1)) {
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302464 fprintf(stderr, "parse error [fsdev]: %s\n", optarg);
2465 exit(1);
2466 }
2467
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002468 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p, 1)) {
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302469 fprintf(stderr, "parse error [device]: %s\n", optarg);
2470 exit(1);
2471 }
2472
2473 qemu_free(arg_fsdev);
2474 qemu_free(arg_9p);
2475 break;
2476 }
bellard82c643f2004-07-14 17:28:13 +00002477 case QEMU_OPTION_serial:
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002478 add_device_config(DEV_SERIAL, optarg);
2479 default_serial = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01002480 if (strncmp(optarg, "mon:", 4) == 0) {
2481 default_monitor = 0;
2482 }
bellard82c643f2004-07-14 17:28:13 +00002483 break;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01002484 case QEMU_OPTION_watchdog:
Markus Armbruster09aaa162009-08-21 10:31:34 +02002485 if (watchdog) {
2486 fprintf(stderr,
2487 "qemu: only one watchdog option may be given\n");
2488 return 1;
2489 }
2490 watchdog = optarg;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01002491 break;
2492 case QEMU_OPTION_watchdog_action:
2493 if (select_watchdog_action(optarg) == -1) {
2494 fprintf(stderr, "Unknown -watchdog-action parameter\n");
2495 exit(1);
2496 }
2497 break;
aliguori51ecf132009-01-15 20:06:40 +00002498 case QEMU_OPTION_virtiocon:
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002499 add_device_config(DEV_VIRTCON, optarg);
2500 default_virtcon = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01002501 if (strncmp(optarg, "mon:", 4) == 0) {
2502 default_monitor = 0;
2503 }
aliguori51ecf132009-01-15 20:06:40 +00002504 break;
bellard6508fe52005-01-15 12:02:56 +00002505 case QEMU_OPTION_parallel:
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002506 add_device_config(DEV_PARALLEL, optarg);
2507 default_parallel = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01002508 if (strncmp(optarg, "mon:", 4) == 0) {
2509 default_monitor = 0;
2510 }
bellard6508fe52005-01-15 12:02:56 +00002511 break;
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002512 case QEMU_OPTION_debugcon:
2513 add_device_config(DEV_DEBUGCON, optarg);
2514 break;
bellardd63d3072004-10-03 13:29:03 +00002515 case QEMU_OPTION_loadvm:
2516 loadvm = optarg;
2517 break;
2518 case QEMU_OPTION_full_screen:
2519 full_screen = 1;
2520 break;
ths667acca2006-12-11 02:08:05 +00002521#ifdef CONFIG_SDL
ths43523e92007-02-18 18:19:32 +00002522 case QEMU_OPTION_no_frame:
2523 no_frame = 1;
2524 break;
ths3780e192007-06-21 21:08:02 +00002525 case QEMU_OPTION_alt_grab:
2526 alt_grab = 1;
2527 break;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -05002528 case QEMU_OPTION_ctrl_grab:
2529 ctrl_grab = 1;
2530 break;
ths667acca2006-12-11 02:08:05 +00002531 case QEMU_OPTION_no_quit:
2532 no_quit = 1;
2533 break;
aliguori7d957bd2009-01-15 22:14:11 +00002534 case QEMU_OPTION_sdl:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002535 display_type = DT_SDL;
aliguori7d957bd2009-01-15 22:14:11 +00002536 break;
ths667acca2006-12-11 02:08:05 +00002537#endif
bellardf7cce892004-12-08 22:21:25 +00002538 case QEMU_OPTION_pidfile:
ths93815bc2007-03-19 15:58:31 +00002539 pid_file = optarg;
bellardf7cce892004-12-08 22:21:25 +00002540 break;
bellarda09db212005-04-30 16:10:35 +00002541 case QEMU_OPTION_win2k_hack:
2542 win2k_install_hack = 1;
2543 break;
aliguori73822ec2009-01-15 20:11:34 +00002544 case QEMU_OPTION_rtc_td_hack:
2545 rtc_td_hack = 1;
2546 break;
aliguori8a92ea22009-02-27 20:12:36 +00002547 case QEMU_OPTION_acpitable:
Blue Swirlde06f8d2010-03-29 19:23:50 +00002548 do_acpitable_option(optarg);
aliguori8a92ea22009-02-27 20:12:36 +00002549 break;
aliguorib6f6e3d2009-04-17 18:59:56 +00002550 case QEMU_OPTION_smbios:
Blue Swirlde06f8d2010-03-29 19:23:50 +00002551 do_smbios_option(optarg);
aliguorib6f6e3d2009-04-17 18:59:56 +00002552 break;
aliguori7ba1e612008-11-05 16:04:33 +00002553 case QEMU_OPTION_enable_kvm:
2554 kvm_allowed = 1;
aliguori7ba1e612008-11-05 16:04:33 +00002555 break;
bellardbb36d472005-11-05 14:22:28 +00002556 case QEMU_OPTION_usb:
2557 usb_enabled = 1;
2558 break;
bellarda594cfb2005-11-06 16:13:29 +00002559 case QEMU_OPTION_usbdevice:
2560 usb_enabled = 1;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002561 add_device_config(DEV_USB, optarg);
2562 break;
2563 case QEMU_OPTION_device:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002564 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02002565 exit(1);
2566 }
bellarda594cfb2005-11-06 16:13:29 +00002567 break;
bellard6a00d602005-11-21 23:25:50 +00002568 case QEMU_OPTION_smp:
Andre Przywaradc6b1c02009-08-19 15:42:40 +02002569 smp_parse(optarg);
aliguorib2097002008-10-07 20:39:39 +00002570 if (smp_cpus < 1) {
bellard6a00d602005-11-21 23:25:50 +00002571 fprintf(stderr, "Invalid number of CPUs\n");
2572 exit(1);
2573 }
Jes Sorensen6be68d72009-07-23 17:03:42 +02002574 if (max_cpus < smp_cpus) {
2575 fprintf(stderr, "maxcpus must be equal to or greater than "
2576 "smp\n");
2577 exit(1);
2578 }
2579 if (max_cpus > 255) {
2580 fprintf(stderr, "Unsupported number of maxcpus\n");
2581 exit(1);
2582 }
bellard6a00d602005-11-21 23:25:50 +00002583 break;
bellard24236862006-04-30 21:28:36 +00002584 case QEMU_OPTION_vnc:
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02002585 display_remote++;
ths73fc9742006-12-22 02:09:07 +00002586 vnc_display = optarg;
bellard24236862006-04-30 21:28:36 +00002587 break;
bellard6515b202006-05-03 22:02:44 +00002588 case QEMU_OPTION_no_acpi:
2589 acpi_enabled = 0;
2590 break;
aliguori16b29ae2008-12-17 23:28:44 +00002591 case QEMU_OPTION_no_hpet:
2592 no_hpet = 1;
2593 break;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02002594 case QEMU_OPTION_balloon:
2595 if (balloon_parse(optarg) < 0) {
2596 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
2597 exit(1);
2598 }
Eduardo Habkostdf97b922009-06-10 16:34:08 -03002599 break;
bellardd1beab82006-10-02 19:44:22 +00002600 case QEMU_OPTION_no_reboot:
2601 no_reboot = 1;
2602 break;
aurel32b2f76162008-04-11 21:35:52 +00002603 case QEMU_OPTION_no_shutdown:
2604 no_shutdown = 1;
2605 break;
balrog9467cd42007-05-01 01:34:14 +00002606 case QEMU_OPTION_show_cursor:
2607 cursor_hide = 0;
2608 break;
blueswir18fcb1b92008-09-18 18:29:08 +00002609 case QEMU_OPTION_uuid:
2610 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
2611 fprintf(stderr, "Fail to parse UUID string."
2612 " Wrong format.\n");
2613 exit(1);
2614 }
2615 break;
ths9ae02552007-01-05 17:39:04 +00002616 case QEMU_OPTION_option_rom:
2617 if (nb_option_roms >= MAX_OPTION_ROMS) {
2618 fprintf(stderr, "Too many option ROMs\n");
2619 exit(1);
2620 }
Gleb Natapov2e55e842010-12-08 13:35:07 +02002621 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
2622 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
2623 option_rom[nb_option_roms].bootindex =
2624 qemu_opt_get_number(opts, "bootindex", -1);
2625 if (!option_rom[nb_option_roms].name) {
2626 fprintf(stderr, "Option ROM file is not specified\n");
2627 exit(1);
2628 }
ths9ae02552007-01-05 17:39:04 +00002629 nb_option_roms++;
2630 break;
pbrook8e716212007-01-20 17:12:09 +00002631 case QEMU_OPTION_semihosting:
2632 semihosting_enabled = 1;
2633 break;
thsc35734b2007-03-19 15:17:08 +00002634 case QEMU_OPTION_name:
Andi Kleen18894652009-07-02 09:34:17 +02002635 qemu_name = qemu_strdup(optarg);
2636 {
2637 char *p = strchr(qemu_name, ',');
2638 if (p != NULL) {
2639 *p++ = 0;
2640 if (strncmp(p, "process=", 8)) {
Aurelien Jarno5697f6a2010-12-27 18:29:20 +01002641 fprintf(stderr, "Unknown subargument %s to -name\n", p);
Andi Kleen18894652009-07-02 09:34:17 +02002642 exit(1);
2643 }
2644 p += 8;
Jes Sorensence798cf2010-06-10 11:42:31 +02002645 os_set_proc_name(p);
Andi Kleen18894652009-07-02 09:34:17 +02002646 }
2647 }
thsc35734b2007-03-19 15:17:08 +00002648 break;
blueswir166508602007-05-01 14:16:52 +00002649 case QEMU_OPTION_prom_env:
2650 if (nb_prom_envs >= MAX_PROM_ENVS) {
2651 fprintf(stderr, "Too many prom variables\n");
2652 exit(1);
2653 }
2654 prom_envs[nb_prom_envs] = optarg;
2655 nb_prom_envs++;
2656 break;
balrog2b8f2d42007-07-27 22:08:46 +00002657 case QEMU_OPTION_old_param:
2658 old_param = 1;
ths05ebd532008-01-08 19:32:16 +00002659 break;
thsf3dcfad2007-08-24 01:26:02 +00002660 case QEMU_OPTION_clock:
2661 configure_alarms(optarg);
2662 break;
bellard7e0af5d02007-11-07 16:24:33 +00002663 case QEMU_OPTION_startdate:
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002664 configure_rtc_date_offset(optarg, 1);
2665 break;
2666 case QEMU_OPTION_rtc:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002667 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002668 if (!opts) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002669 exit(1);
bellard7e0af5d02007-11-07 16:24:33 +00002670 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002671 configure_rtc(opts);
bellard7e0af5d02007-11-07 16:24:33 +00002672 break;
bellard26a5f132008-05-28 12:30:31 +00002673 case QEMU_OPTION_tb_size:
2674 tb_size = strtol(optarg, NULL, 0);
2675 if (tb_size < 0)
2676 tb_size = 0;
2677 break;
pbrook2e70f6e2008-06-29 01:03:05 +00002678 case QEMU_OPTION_icount:
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01002679 icount_option = optarg;
pbrook2e70f6e2008-06-29 01:03:05 +00002680 break;
aliguori5bb79102008-10-13 03:12:02 +00002681 case QEMU_OPTION_incoming:
2682 incoming = optarg;
Amit Shah8e848652010-07-27 15:49:19 +05302683 incoming_expected = true;
aliguori5bb79102008-10-13 03:12:02 +00002684 break;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01002685 case QEMU_OPTION_nodefaults:
2686 default_serial = 0;
2687 default_parallel = 0;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002688 default_virtcon = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01002689 default_monitor = 0;
2690 default_vga = 0;
Gerd Hoffmanncb4522c2009-12-08 13:11:47 +01002691 default_net = 0;
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01002692 default_floppy = 0;
2693 default_cdrom = 0;
2694 default_sdcard = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01002695 break;
aliguorie37630c2009-04-22 15:19:10 +00002696 case QEMU_OPTION_xen_domid:
Blue Swirlad960902010-03-29 19:23:52 +00002697 if (!(xen_available())) {
2698 printf("Option %s not supported for this target\n", popt->name);
2699 exit(1);
2700 }
aliguorie37630c2009-04-22 15:19:10 +00002701 xen_domid = atoi(optarg);
2702 break;
2703 case QEMU_OPTION_xen_create:
Blue Swirlad960902010-03-29 19:23:52 +00002704 if (!(xen_available())) {
2705 printf("Option %s not supported for this target\n", popt->name);
2706 exit(1);
2707 }
aliguorie37630c2009-04-22 15:19:10 +00002708 xen_mode = XEN_CREATE;
2709 break;
2710 case QEMU_OPTION_xen_attach:
Blue Swirlad960902010-03-29 19:23:52 +00002711 if (!(xen_available())) {
2712 printf("Option %s not supported for this target\n", popt->name);
2713 exit(1);
2714 }
aliguorie37630c2009-04-22 15:19:10 +00002715 xen_mode = XEN_ATTACH;
2716 break;
Prerna Saxenaab6540d2010-08-09 11:48:32 +01002717#ifdef CONFIG_SIMPLE_TRACE
2718 case QEMU_OPTION_trace:
2719 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
2720 if (opts) {
2721 trace_file = qemu_opt_get(opts, "file");
2722 }
2723 break;
2724#endif
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002725 case QEMU_OPTION_readconfig:
2726 {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002727 int ret = qemu_read_config_file(optarg);
2728 if (ret < 0) {
2729 fprintf(stderr, "read config %s: %s\n", optarg,
2730 strerror(-ret));
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002731 exit(1);
2732 }
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002733 break;
2734 }
Gerd Hoffmann29b00402010-03-11 11:13:27 -03002735 case QEMU_OPTION_spice:
2736 olist = qemu_find_opts("spice");
2737 if (!olist) {
2738 fprintf(stderr, "spice is not supported by this qemu build.\n");
2739 exit(1);
2740 }
2741 opts = qemu_opts_parse(olist, optarg, 0);
2742 if (!opts) {
2743 fprintf(stderr, "parse error: %s\n", optarg);
2744 exit(1);
2745 }
2746 break;
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002747 case QEMU_OPTION_writeconfig:
2748 {
2749 FILE *fp;
2750 if (strcmp(optarg, "-") == 0) {
2751 fp = stdout;
2752 } else {
2753 fp = fopen(optarg, "w");
2754 if (fp == NULL) {
2755 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
2756 exit(1);
2757 }
2758 }
2759 qemu_config_write(fp);
2760 fclose(fp);
2761 break;
2762 }
Jes Sorensen59a52642010-06-10 11:42:25 +02002763 default:
2764 os_parse_cmd_args(popt->index, optarg);
bellardcd6f1162004-05-13 22:02:20 +00002765 }
bellard0824d6f2003-06-24 13:42:40 +00002766 }
2767 }
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002768 loc_set_none();
bellard330d0412003-07-26 18:11:40 +00002769
Stefan Hajnoczi0b5538c2011-02-26 18:38:39 +00002770 st_init(trace_file);
2771
Paul Brook5cea8592009-05-30 00:52:44 +01002772 /* If no data_dir is specified then try to find it relative to the
2773 executable path. */
2774 if (!data_dir) {
Jes Sorensen61705402010-06-10 11:42:23 +02002775 data_dir = os_find_datadir(argv[0]);
Paul Brook5cea8592009-05-30 00:52:44 +01002776 }
2777 /* If all else fails use the install patch specified when building. */
2778 if (!data_dir) {
Paolo Bonzini1dabe052010-05-26 16:08:25 +02002779 data_dir = CONFIG_QEMU_DATADIR;
Paul Brook5cea8592009-05-30 00:52:44 +01002780 }
2781
Jes Sorensen6be68d72009-07-23 17:03:42 +02002782 /*
2783 * Default to max_cpus = smp_cpus, in case the user doesn't
2784 * specify a max_cpus value.
2785 */
2786 if (!max_cpus)
2787 max_cpus = smp_cpus;
2788
balrog3d878ca2008-10-28 10:59:59 +00002789 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
aliguorib2097002008-10-07 20:39:39 +00002790 if (smp_cpus > machine->max_cpus) {
2791 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
2792 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
2793 machine->max_cpus);
2794 exit(1);
2795 }
2796
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002797 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
2798 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002799
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002800 if (machine->no_serial) {
2801 default_serial = 0;
2802 }
2803 if (machine->no_parallel) {
2804 default_parallel = 0;
2805 }
2806 if (!machine->use_virtcon) {
2807 default_virtcon = 0;
2808 }
2809 if (machine->no_vga) {
2810 default_vga = 0;
2811 }
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01002812 if (machine->no_floppy) {
2813 default_floppy = 0;
2814 }
2815 if (machine->no_cdrom) {
2816 default_cdrom = 0;
2817 }
2818 if (machine->no_sdcard) {
2819 default_sdcard = 0;
2820 }
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002821
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002822 if (display_type == DT_NOGRAPHIC) {
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002823 if (default_parallel)
2824 add_device_config(DEV_PARALLEL, "null");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002825 if (default_serial && default_monitor) {
2826 add_device_config(DEV_SERIAL, "mon:stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002827 } else if (default_virtcon && default_monitor) {
2828 add_device_config(DEV_VIRTCON, "mon:stdio");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002829 } else {
2830 if (default_serial)
2831 add_device_config(DEV_SERIAL, "stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002832 if (default_virtcon)
2833 add_device_config(DEV_VIRTCON, "stdio");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002834 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002835 monitor_parse("stdio", "readline");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002836 }
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002837 } else {
2838 if (default_serial)
2839 add_device_config(DEV_SERIAL, "vc:80Cx24C");
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002840 if (default_parallel)
2841 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
Gerd Hoffmannabdeed02009-12-08 13:11:43 +01002842 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002843 monitor_parse("vc:80Cx24C", "readline");
Alexander Graf38536da2009-12-17 13:06:08 +01002844 if (default_virtcon)
2845 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
aliguoribc0129d2008-08-01 15:12:34 +00002846 }
Gerd Hoffmann64465292009-12-08 13:11:45 +01002847 if (default_vga)
2848 vga_interface_type = VGA_CIRRUS;
aliguoribc0129d2008-08-01 15:12:34 +00002849
TeLeMana5829fd2010-04-15 12:37:55 +08002850 socket_init();
2851
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002852 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002853 exit(1);
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07002854#ifdef CONFIG_VIRTFS
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002855 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302856 exit(1);
2857 }
2858#endif
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002859
Jes Sorenseneb505be2010-06-10 11:42:28 +02002860 os_daemonize();
ths71e3ceb2006-12-22 02:11:31 +00002861
thsaa26bb22007-03-25 21:33:06 +00002862 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
Jes Sorenseneb505be2010-06-10 11:42:28 +02002863 os_pidfile_error();
ths93815bc2007-03-19 15:58:31 +00002864 exit(1);
2865 }
2866
Paolo Bonzini98c85732010-04-19 18:59:30 +00002867 if (kvm_allowed) {
Jan Kiszkacad1e282011-01-21 21:48:16 +01002868 int ret = kvm_init();
Marcelo Tosatti214910a2009-09-18 02:41:23 -03002869 if (ret < 0) {
Paolo Bonzini98c85732010-04-19 18:59:30 +00002870 if (!kvm_available()) {
2871 printf("KVM not supported for this target\n");
2872 } else {
2873 fprintf(stderr, "failed to initialize KVM: %s\n", strerror(-ret));
2874 }
Marcelo Tosatti214910a2009-09-18 02:41:23 -03002875 exit(1);
2876 }
2877 }
2878
aliguori3fcf7b62009-04-24 18:03:25 +00002879 if (qemu_init_main_loop()) {
2880 fprintf(stderr, "qemu_init_main_loop failed\n");
2881 exit(1);
2882 }
bellarda20dd502003-09-30 21:07:02 +00002883 linux_boot = (kernel_filename != NULL);
balrog6c41b272007-11-17 12:12:29 +00002884
thsf8d39c02008-07-03 10:01:15 +00002885 if (!linux_boot && *kernel_cmdline != '\0') {
2886 fprintf(stderr, "-append only allowed with -kernel option\n");
2887 exit(1);
2888 }
2889
2890 if (!linux_boot && initrd_filename != NULL) {
2891 fprintf(stderr, "-initrd only allowed with -kernel option\n");
2892 exit(1);
2893 }
2894
Jes Sorensen9156d762010-06-10 11:42:30 +02002895 os_set_line_buffering();
ths3b46e622007-09-17 08:09:54 +00002896
aliguori7183b4b2008-11-05 20:40:18 +00002897 if (init_timer_alarm() < 0) {
2898 fprintf(stderr, "could not initialize alarm timer\n");
2899 exit(1);
2900 }
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01002901 configure_icount(icount_option);
pbrook634fce92006-07-15 17:40:09 +00002902
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01002903 if (net_init_clients() < 0) {
2904 exit(1);
bellard702c6512004-04-02 21:21:32 +00002905 }
bellardf1510b22003-06-25 00:07:40 +00002906
balrogdc72ac12008-11-09 00:04:26 +00002907 /* init the bluetooth world */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002908 if (foreach_device_config(DEV_BT, bt_parse))
2909 exit(1);
balrogdc72ac12008-11-09 00:04:26 +00002910
bellard0824d6f2003-06-24 13:42:40 +00002911 /* init the memory */
pbrook94a6b542009-04-11 17:15:54 +00002912 if (ram_size == 0)
2913 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
balrog7fb4fdc2008-04-24 17:59:27 +00002914
bellard26a5f132008-05-28 12:30:31 +00002915 /* init the dynamic translator */
2916 cpu_exec_init_all(tb_size * 1024 * 1024);
2917
Markus Armbrustereb852012009-10-27 18:41:44 +01002918 bdrv_init_with_whitelist();
thse4bcb142007-12-02 04:51:10 +00002919
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +02002920 blk_mig_init();
2921
ths96d30e42007-01-07 20:42:14 +00002922 /* open the virtual block devices */
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02002923 if (snapshot)
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002924 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
2925 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02002926 exit(1);
balrog3e3d5812007-04-30 02:09:25 +00002927
Markus Armbruster4e5d9b52011-01-28 11:21:45 +01002928 default_drive(default_cdrom, snapshot, machine->use_scsi,
2929 IF_DEFAULT, 2, CDROM_OPTS);
2930 default_drive(default_floppy, snapshot, machine->use_scsi,
2931 IF_FLOPPY, 0, FD_OPTS);
2932 default_drive(default_sdcard, snapshot, machine->use_scsi,
2933 IF_SD, 0, SD_OPTS);
2934
Alex Williamson97ab12d2010-06-25 11:09:50 -06002935 register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL,
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +02002936 ram_load, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00002937
aliguori268a3622009-04-21 22:30:27 +00002938 if (nb_numa_nodes > 0) {
2939 int i;
2940
2941 if (nb_numa_nodes > smp_cpus) {
2942 nb_numa_nodes = smp_cpus;
2943 }
2944
2945 /* If no memory size if given for any node, assume the default case
2946 * and distribute the available memory equally across all nodes
2947 */
2948 for (i = 0; i < nb_numa_nodes; i++) {
2949 if (node_mem[i] != 0)
2950 break;
2951 }
2952 if (i == nb_numa_nodes) {
2953 uint64_t usedmem = 0;
2954
2955 /* On Linux, the each node's border has to be 8MB aligned,
2956 * the final node gets the rest.
2957 */
2958 for (i = 0; i < nb_numa_nodes - 1; i++) {
2959 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
2960 usedmem += node_mem[i];
2961 }
2962 node_mem[i] = ram_size - usedmem;
2963 }
2964
2965 for (i = 0; i < nb_numa_nodes; i++) {
2966 if (node_cpumask[i] != 0)
2967 break;
2968 }
2969 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2970 * must cope with this anyway, because there are BIOSes out there in
2971 * real machines which also use this scheme.
2972 */
2973 if (i == nb_numa_nodes) {
2974 for (i = 0; i < smp_cpus; i++) {
2975 node_cpumask[i % nb_numa_nodes] |= 1 << i;
2976 }
2977 }
2978 }
2979
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002980 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
Jan Kiszka157b9312010-04-06 16:55:53 +02002981 exit(1);
2982 }
2983
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002984 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
2985 exit(1);
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002986 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
2987 exit(1);
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002988 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
2989 exit(1);
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002990 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
2991 exit(1);
aliguori2796dae2009-01-16 20:23:27 +00002992
Paul Brookaae94602009-05-14 22:35:06 +01002993 module_call_init(MODULE_INIT_DEVICE);
2994
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002995 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0)
Markus Armbrusterff952ba2010-01-29 19:48:57 +01002996 exit(0);
2997
Markus Armbruster09aaa162009-08-21 10:31:34 +02002998 if (watchdog) {
2999 i = select_watchdog(watchdog);
3000 if (i > 0)
3001 exit (i == 1 ? 1 : 0);
3002 }
3003
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02003004 if (machine->compat_props) {
Gerd Hoffmann458fb672009-12-08 13:11:33 +01003005 qdev_prop_register_global_list(machine->compat_props);
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02003006 }
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01003007 qemu_add_globals();
3008
Paul Brookfbe1b592009-05-13 17:56:25 +01003009 machine->init(ram_size, boot_devices,
aliguori3023f3322009-01-16 19:04:14 +00003010 kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
3011
Jan Kiszkaea375f92010-03-01 19:10:30 +01003012 cpu_synchronize_all_post_init();
aliguori268a3622009-04-21 22:30:27 +00003013
Juan Quintela67b3b712009-08-28 19:25:15 +02003014 /* must be after terminal init, SDL library changes signal handlers */
Jes Sorensen8d963e62010-06-10 11:42:22 +02003015 os_setup_signal_handling();
Juan Quintela67b3b712009-08-28 19:25:15 +02003016
Blue Swirl87d0a282010-03-27 18:24:45 +00003017 set_numa_modes();
aliguori268a3622009-04-21 22:30:27 +00003018
aliguori6f338c32009-02-11 15:21:54 +00003019 current_machine = machine;
3020
aliguori3023f3322009-01-16 19:04:14 +00003021 /* init USB devices */
3022 if (usb_enabled) {
Markus Armbruster07527062009-10-06 12:16:57 +01003023 if (foreach_device_config(DEV_USB, usb_parse) < 0)
3024 exit(1);
aliguori3023f3322009-01-16 19:04:14 +00003025 }
3026
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003027 /* init generic devices */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003028 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003029 exit(1);
3030
Markus Armbruster668680f2010-02-11 14:44:58 +01003031 net_check_clients();
3032
aliguori3023f3322009-01-16 19:04:14 +00003033 /* just use the first displaystate for the moment */
Paolo Bonzinib473df62010-02-11 00:29:55 +01003034 ds = get_displaystate();
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003035
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003036 if (using_spice)
3037 display_remote++;
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003038 if (display_type == DT_DEFAULT && !display_remote) {
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003039#if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003040 display_type = DT_SDL;
3041#else
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003042 vnc_display = "localhost:0,to=99";
3043 show_vnc_port = 1;
3044#endif
3045 }
3046
3047
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003048 /* init local displays */
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003049 switch (display_type) {
3050 case DT_NOGRAPHIC:
3051 break;
3052#if defined(CONFIG_CURSES)
3053 case DT_CURSES:
3054 curses_display_init(ds, full_screen);
3055 break;
3056#endif
bellard5b0753e2005-03-01 21:37:28 +00003057#if defined(CONFIG_SDL)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003058 case DT_SDL:
3059 sdl_display_init(ds, full_screen, no_frame);
3060 break;
bellard5b0753e2005-03-01 21:37:28 +00003061#elif defined(CONFIG_COCOA)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003062 case DT_SDL:
3063 cocoa_display_init(ds, full_screen);
3064 break;
bellard313aa562003-08-10 21:52:11 +00003065#endif
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003066 default:
3067 break;
3068 }
3069
3070 /* init remote displays */
3071 if (vnc_display) {
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003072 vnc_display_init(ds);
3073 if (vnc_display_open(ds, vnc_display) < 0)
3074 exit(1);
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003075
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003076 if (show_vnc_port) {
3077 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003078 }
bellard313aa562003-08-10 21:52:11 +00003079 }
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003080#ifdef CONFIG_SPICE
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +02003081 if (using_spice && !qxl_enabled) {
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003082 qemu_spice_display_init(ds);
3083 }
3084#endif
aliguori5b08fc12008-08-21 20:08:03 +00003085
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003086 /* display setup */
3087 dpy_resize(ds);
aliguori3023f3322009-01-16 19:04:14 +00003088 dcl = ds->listeners;
3089 while (dcl != NULL) {
3090 if (dcl->dpy_refresh != NULL) {
3091 ds->gui_timer = qemu_new_timer(rt_clock, gui_update, ds);
3092 qemu_mod_timer(ds->gui_timer, qemu_get_clock(rt_clock));
Isaku Yamahata0f2ad632010-05-27 14:38:47 +09003093 break;
ths20d8a3e2007-02-18 17:04:49 +00003094 }
aliguori3023f3322009-01-16 19:04:14 +00003095 dcl = dcl->next;
bellard82c643f2004-07-14 17:28:13 +00003096 }
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003097 if (ds->gui_timer == NULL) {
blueswir19043b622009-01-21 19:28:13 +00003098 nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL);
3099 qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock));
3100 }
Paolo Bonzinib473df62010-02-11 00:29:55 +01003101 text_consoles_set_display(ds);
aliguori2796dae2009-01-16 20:23:27 +00003102
aliguori59030a82009-04-05 18:43:41 +00003103 if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) {
3104 fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n",
3105 gdbstub_dev);
3106 exit(1);
balrog45669e02007-07-02 13:20:17 +00003107 }
balrog45669e02007-07-02 13:20:17 +00003108
Gerd Hoffmann3418bd22009-09-25 21:42:41 +02003109 qdev_machine_creation_done();
3110
Gerd Hoffmann15ff7702009-12-14 16:07:35 +01003111 if (rom_load_all() != 0) {
3112 fprintf(stderr, "rom loading failed\n");
3113 exit(1);
3114 }
Gerd Hoffmann45a50b12009-10-01 16:42:33 +02003115
Isaku Yamahata80376c32010-12-20 14:33:35 +09003116 /* TODO: once all bus devices are qdevified, this should be done
3117 * when bus is created by qdev.c */
3118 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
Gleb Natapov4cab9462010-12-08 13:35:08 +02003119 qemu_run_machine_init_done_notifiers();
3120
Juan Quintela504c2942009-11-12 00:39:13 +01003121 qemu_system_reset();
Juan Quintela05f24012009-08-20 19:42:22 +02003122 if (loadvm) {
Markus Armbruster03cd4652010-02-17 16:24:10 +01003123 if (load_vmstate(loadvm) < 0) {
Juan Quintela05f24012009-08-20 19:42:22 +02003124 autostart = 0;
3125 }
3126 }
bellardd63d3072004-10-03 13:29:03 +00003127
Glauber Costa2bb8c102009-07-24 16:20:23 -04003128 if (incoming) {
Juan Quintela8ca5e802010-06-09 14:10:54 +02003129 int ret = qemu_start_incoming_migration(incoming);
3130 if (ret < 0) {
3131 fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n",
3132 incoming, ret);
3133 exit(ret);
3134 }
Avi Kivity6b99dad2009-08-09 14:39:20 +03003135 } else if (autostart) {
aliguoric0f4ce72009-03-05 23:01:01 +00003136 vm_start();
Avi Kivity6b99dad2009-08-09 14:39:20 +03003137 }
thsffd843b2006-12-21 19:46:43 +00003138
Jes Sorenseneb505be2010-06-10 11:42:28 +02003139 os_setup_post();
ths71e3ceb2006-12-22 02:11:31 +00003140
bellard8a7ddc32004-03-31 19:00:16 +00003141 main_loop();
bellard40c3bac2004-04-04 12:56:28 +00003142 quit_timers();
aliguori63a01ef2008-10-31 19:10:00 +00003143 net_cleanup();
thsb46a8902007-10-21 23:20:45 +00003144
bellard0824d6f2003-06-24 13:42:40 +00003145 return 0;
3146}