blob: 6d2d1d344f252b53b6da92f50e280f36b6dd3c1f [file] [log] [blame]
bellard0824d6f2003-06-24 13:42:40 +00001/*
bellard80cabfa2004-03-14 12:20:30 +00002 * QEMU System Emulator
ths5fafdf22007-09-16 21:08:06 +00003 *
bellard68d0f702008-01-06 17:21:48 +00004 * Copyright (c) 2003-2008 Fabrice Bellard
ths5fafdf22007-09-16 21:08:06 +00005 *
bellard1df912c2003-06-25 16:20:35 +00006 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
bellard0824d6f2003-06-24 13:42:40 +000023 */
bellard0824d6f2003-06-24 13:42:40 +000024#include <unistd.h>
bellard0824d6f2003-06-24 13:42:40 +000025#include <fcntl.h>
26#include <signal.h>
27#include <time.h>
bellard0824d6f2003-06-24 13:42:40 +000028#include <errno.h>
bellard67b915a2004-03-31 23:37:16 +000029#include <sys/time.h>
bellardc88676f2006-08-06 13:36:11 +000030#include <zlib.h>
bellard67b915a2004-03-31 23:37:16 +000031
Juan Quintela71e72a12009-07-27 16:12:56 +020032/* Needed early for CONFIG_BSD etc. */
blueswir1d40cdb12009-03-07 16:52:02 +000033#include "config-host.h"
34
bellard67b915a2004-03-31 23:37:16 +000035#ifndef _WIN32
Paul Brook5cea8592009-05-30 00:52:44 +010036#include <libgen.h>
bellard67b915a2004-03-31 23:37:16 +000037#include <sys/times.h>
bellardf1510b22003-06-25 00:07:40 +000038#include <sys/wait.h>
bellard67b915a2004-03-31 23:37:16 +000039#include <termios.h>
bellard67b915a2004-03-31 23:37:16 +000040#include <sys/mman.h>
bellardf1510b22003-06-25 00:07:40 +000041#include <sys/ioctl.h>
blueswir124646c72008-11-07 16:55:48 +000042#include <sys/resource.h>
bellardf1510b22003-06-25 00:07:40 +000043#include <sys/socket.h>
bellardc94c8d62004-09-13 21:37:34 +000044#include <netinet/in.h>
blueswir124646c72008-11-07 16:55:48 +000045#include <net/if.h>
blueswir124646c72008-11-07 16:55:48 +000046#include <arpa/inet.h>
bellard9d728e82004-09-05 23:09:03 +000047#include <dirent.h>
bellard7c9d8e02005-11-15 22:16:05 +000048#include <netdb.h>
thscb4b9762007-09-13 12:39:35 +000049#include <sys/select.h>
Prerna Saxenaab6540d2010-08-09 11:48:32 +010050#ifdef CONFIG_SIMPLE_TRACE
51#include "trace.h"
52#endif
53
Juan Quintela71e72a12009-07-27 16:12:56 +020054#ifdef CONFIG_BSD
bellard7d3505c2004-05-12 19:32:15 +000055#include <sys/stat.h>
Aurelien Jarnoa167ba52009-11-29 18:00:41 +010056#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
bellard7d3505c2004-05-12 19:32:15 +000057#include <libutil.h>
Juergen Lock92c0e652010-03-25 22:07:12 +010058#include <sys/sysctl.h>
blueswir124646c72008-11-07 16:55:48 +000059#else
60#include <util.h>
blueswir1128ab2f2008-08-15 18:33:42 +000061#endif
Aurelien Jarnobbe813a2009-11-30 15:42:59 +010062#else
blueswir1223f0d72008-09-30 18:12:18 +000063#ifdef __linux__
bellard7d3505c2004-05-12 19:32:15 +000064#include <pty.h>
65#include <malloc.h>
thsbd494f42007-09-16 20:03:23 +000066
bellarde57a8c02005-11-10 23:58:52 +000067#include <linux/ppdev.h>
ths5867c882007-02-17 23:44:43 +000068#include <linux/parport.h>
blueswir1223f0d72008-09-30 18:12:18 +000069#endif
70#ifdef __sun__
thsd5d10bc2007-02-17 22:54:49 +000071#include <sys/stat.h>
72#include <sys/ethernet.h>
73#include <sys/sockio.h>
thsd5d10bc2007-02-17 22:54:49 +000074#include <netinet/arp.h>
thsd5d10bc2007-02-17 22:54:49 +000075#include <netinet/in_systm.h>
76#include <netinet/ip.h>
77#include <netinet/ip_icmp.h> // must come after ip.h
78#include <netinet/udp.h>
79#include <netinet/tcp.h>
80#include <net/if.h>
81#include <syslog.h>
82#include <stropts.h>
bellard67b915a2004-03-31 23:37:16 +000083#endif
bellard7d3505c2004-05-12 19:32:15 +000084#endif
bellardec530c82006-04-25 22:36:06 +000085#endif
bellard67b915a2004-03-31 23:37:16 +000086
blueswir19892fbf2008-08-24 10:34:20 +000087#if defined(__OpenBSD__)
88#include <util.h>
89#endif
90
ths8a16d272008-07-19 09:56:24 +000091#if defined(CONFIG_VDE)
92#include <libvdeplug.h>
93#endif
94
bellard67b915a2004-03-31 23:37:16 +000095#ifdef _WIN32
aliguori49dc7682009-03-08 16:26:59 +000096#include <windows.h>
bellard67b915a2004-03-31 23:37:16 +000097#endif
98
bellard73332e52004-04-04 20:22:28 +000099#ifdef CONFIG_SDL
Stefan Weil59a36a22009-06-18 20:11:03 +0200100#if defined(__APPLE__) || defined(main)
Stefan Weil66936652009-06-13 13:19:11 +0200101#include <SDL.h>
malc880fec52009-02-15 20:18:41 +0000102int qemu_main(int argc, char **argv, char **envp);
103int main(int argc, char **argv)
104{
Stefan Weil59a36a22009-06-18 20:11:03 +0200105 return qemu_main(argc, argv, NULL);
malc880fec52009-02-15 20:18:41 +0000106}
107#undef main
108#define main qemu_main
bellard96bcd4f2004-07-10 16:26:15 +0000109#endif
bellard73332e52004-04-04 20:22:28 +0000110#endif /* CONFIG_SDL */
bellard0824d6f2003-06-24 13:42:40 +0000111
bellard5b0753e2005-03-01 21:37:28 +0000112#ifdef CONFIG_COCOA
113#undef main
114#define main qemu_main
115#endif /* CONFIG_COCOA */
116
blueswir1511d2b12009-03-07 15:32:56 +0000117#include "hw/hw.h"
118#include "hw/boards.h"
119#include "hw/usb.h"
120#include "hw/pcmcia.h"
121#include "hw/pc.h"
blueswir1511d2b12009-03-07 15:32:56 +0000122#include "hw/isa.h"
123#include "hw/baum.h"
124#include "hw/bt.h"
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +0100125#include "hw/watchdog.h"
aliguorib6f6e3d2009-04-17 18:59:56 +0000126#include "hw/smbios.h"
aliguorie37630c2009-04-22 15:19:10 +0000127#include "hw/xen.h"
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +0200128#include "hw/qdev.h"
Gerd Hoffmann45a50b12009-10-01 16:42:33 +0200129#include "hw/loader.h"
aurel325ef4efa2009-03-10 21:43:35 +0000130#include "bt-host.h"
blueswir1511d2b12009-03-07 15:32:56 +0000131#include "net.h"
Mark McLoughlin68ac40d2009-11-25 18:48:54 +0000132#include "net/slirp.h"
blueswir1511d2b12009-03-07 15:32:56 +0000133#include "monitor.h"
134#include "console.h"
135#include "sysemu.h"
136#include "gdbstub.h"
137#include "qemu-timer.h"
138#include "qemu-char.h"
139#include "cache-utils.h"
140#include "block.h"
Markus Armbruster666daa62010-06-02 18:48:27 +0200141#include "blockdev.h"
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +0200142#include "block-migration.h"
blueswir1a718ace2009-03-28 08:24:44 +0000143#include "dma.h"
blueswir1511d2b12009-03-07 15:32:56 +0000144#include "audio/audio.h"
145#include "migration.h"
146#include "kvm.h"
Kevin Wolfd3f24362009-05-18 16:42:09 +0200147#include "qemu-option.h"
Gerd Hoffmann7282a032009-07-31 12:25:35 +0200148#include "qemu-config.h"
Luiz Capitulinoe78c48e2009-12-10 17:16:04 -0200149#include "qemu-objects.h"
Jes Sorensen59a52642010-06-10 11:42:25 +0200150#include "qemu-options.h"
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -0700151#ifdef CONFIG_VIRTFS
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530152#include "fsdev/qemu-fsdev.h"
153#endif
blueswir1511d2b12009-03-07 15:32:56 +0000154
bellard0824d6f2003-06-24 13:42:40 +0000155#include "disas.h"
bellardfc01f7e2003-06-30 10:03:06 +0000156
blueswir1511d2b12009-03-07 15:32:56 +0000157#include "qemu_socket.h"
158
Jan Kiszkad918f232009-06-24 14:42:30 +0200159#include "slirp/libslirp.h"
blueswir1511d2b12009-03-07 15:32:56 +0000160
Stefan Hajnoczi94b0b5f2010-11-16 12:20:25 +0000161#include "trace.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +0000162#include "qemu-queue.h"
Blue Swirl296af7c2010-03-29 19:23:50 +0000163#include "cpus.h"
Blue Swirlad960902010-03-29 19:23:52 +0000164#include "arch_init.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +0000165
Gerd Hoffmann29b00402010-03-11 11:13:27 -0300166#include "ui/qemu-spice.h"
167
blueswir19dc63a12008-10-04 07:25:46 +0000168//#define DEBUG_NET
169//#define DEBUG_SLIRP
bellard330d0412003-07-26 18:11:40 +0000170
bellard1bfe8562004-07-08 21:17:50 +0000171#define DEFAULT_RAM_SIZE 128
bellard313aa562003-08-10 21:52:11 +0000172
Amit Shah98b19252010-01-20 00:36:52 +0530173#define MAX_VIRTIO_CONSOLES 1
174
Paul Brook5cea8592009-05-30 00:52:44 +0100175static const char *data_dir;
j_mayer1192dad2007-10-05 13:08:35 +0000176const char *bios_name = NULL;
malccb5a7aa2008-09-28 00:42:12 +0000177enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
Anthony Liguori993fbfd2009-05-21 16:54:00 -0500178DisplayType display_type = DT_DEFAULT;
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +0200179int display_remote = 0;
bellard3d11d0e2004-12-12 16:56:30 +0000180const char* keyboard_layout = NULL;
Anthony Liguoric227f092009-10-01 16:12:16 -0500181ram_addr_t ram_size;
Marcelo Tosattic9027602010-03-01 20:25:08 -0300182const char *mem_path = NULL;
183#ifdef MAP_POPULATE
184int mem_prealloc = 0; /* force preallocation of physical target memory */
185#endif
bellardc4b1fcc2004-03-14 21:44:30 +0000186int nb_nics;
bellard7c9d8e02005-11-15 22:16:05 +0000187NICInfo nd_table[MAX_NICS];
bellard8a7ddc32004-03-31 19:00:16 +0000188int vm_running;
Paolo Bonzinid399f672009-07-27 23:17:51 +0200189int autostart;
Amit Shah8e848652010-07-27 15:49:19 +0530190int incoming_expected; /* Started with -incoming and waiting for incoming */
balrogf6503052008-02-17 11:42:19 +0000191static int rtc_utc = 1;
192static int rtc_date_offset = -1; /* -1 means no change */
Jan Kiszka68752042009-09-15 13:36:04 +0200193QEMUClock *rtc_clock;
Gerd Hoffmann64465292009-12-08 13:11:45 +0100194int vga_interface_type = VGA_NONE;
blueswir1dbed7e42008-10-01 19:38:09 +0000195static int full_screen = 0;
blueswir1634a21f2008-11-16 11:34:07 +0000196#ifdef CONFIG_SDL
blueswir1dbed7e42008-10-01 19:38:09 +0000197static int no_frame = 0;
blueswir1634a21f2008-11-16 11:34:07 +0000198#endif
ths667acca2006-12-11 02:08:05 +0000199int no_quit = 0;
bellard8d11df92004-08-24 21:13:40 +0000200CharDriverState *serial_hds[MAX_SERIAL_PORTS];
bellard6508fe52005-01-15 12:02:56 +0000201CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
aliguori9ede2fd2009-01-15 20:05:25 +0000202CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
bellarda09db212005-04-30 16:10:35 +0000203int win2k_install_hack = 0;
aliguori73822ec2009-01-15 20:11:34 +0000204int rtc_td_hack = 0;
bellardbb36d472005-11-05 14:22:28 +0000205int usb_enabled = 0;
aurel321b530a62009-04-05 20:08:59 +0000206int singlestep = 0;
bellard6a00d602005-11-21 23:25:50 +0000207int smp_cpus = 1;
Jes Sorensen6be68d72009-07-23 17:03:42 +0200208int max_cpus = 0;
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200209int smp_cores = 1;
210int smp_threads = 1;
ths73fc9742006-12-22 02:09:07 +0000211const char *vnc_display;
bellard6515b202006-05-03 22:02:44 +0000212int acpi_enabled = 1;
aliguori16b29ae2008-12-17 23:28:44 +0000213int no_hpet = 0;
bellard52ca8d62006-06-14 16:03:05 +0000214int fd_bootchk = 1;
bellardd1beab82006-10-02 19:44:22 +0000215int no_reboot = 0;
aurel32b2f76162008-04-11 21:35:52 +0000216int no_shutdown = 0;
balrog9467cd42007-05-01 01:34:14 +0000217int cursor_hide = 1;
balroga171fe32007-04-30 01:48:07 +0000218int graphic_rotate = 0;
Jes Sorensen6b35e7b2009-08-06 16:25:50 +0200219uint8_t irq0override = 1;
Markus Armbruster09aaa162009-08-21 10:31:34 +0200220const char *watchdog;
Gleb Natapov2e55e842010-12-08 13:35:07 +0200221QEMUOptionRom option_rom[MAX_OPTION_ROMS];
ths9ae02552007-01-05 17:39:04 +0000222int nb_option_roms;
pbrook8e716212007-01-20 17:12:09 +0000223int semihosting_enabled = 0;
balrog2b8f2d42007-07-27 22:08:46 +0000224int old_param = 0;
thsc35734b2007-03-19 15:17:08 +0000225const char *qemu_name;
ths3780e192007-06-21 21:08:02 +0000226int alt_grab = 0;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -0500227int ctrl_grab = 0;
blueswir166508602007-05-01 14:16:52 +0000228unsigned int nb_prom_envs = 0;
229const char *prom_envs[MAX_PROM_ENVS];
Jan Kiszka95387492009-07-02 00:19:02 +0200230int boot_menu;
bellard0824d6f2003-06-24 13:42:40 +0000231
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200232typedef struct FWBootEntry FWBootEntry;
233
234struct FWBootEntry {
235 QTAILQ_ENTRY(FWBootEntry) link;
236 int32_t bootindex;
237 DeviceState *dev;
238 char *suffix;
239};
240
241QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order);
242
aliguori268a3622009-04-21 22:30:27 +0000243int nb_numa_nodes;
244uint64_t node_mem[MAX_NODES];
245uint64_t node_cpumask[MAX_NODES];
246
blueswir19043b622009-01-21 19:28:13 +0000247static QEMUTimer *nographic_timer;
balrogee5605e2007-12-03 03:01:40 +0000248
blueswir18fcb1b92008-09-18 18:29:08 +0000249uint8_t qemu_uuid[16];
250
Jan Kiszka76e30d02009-07-02 00:19:02 +0200251static QEMUBootSetHandler *boot_set_handler;
252static void *boot_set_opaque;
253
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +0200254static NotifierList exit_notifiers =
255 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
256
Gleb Natapov4cab9462010-12-08 13:35:08 +0200257static NotifierList machine_init_done_notifiers =
258 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
259
Blue Swirld745bef2010-03-29 19:23:49 +0000260int kvm_allowed = 0;
261uint32_t xen_domid;
262enum xen_mode xen_mode = XEN_EMULATE;
263
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100264static int default_serial = 1;
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +0100265static int default_parallel = 1;
Gerd Hoffmann986c5f72009-12-08 13:11:54 +0100266static int default_virtcon = 1;
Gerd Hoffmannabdeed02009-12-08 13:11:43 +0100267static int default_monitor = 1;
Gerd Hoffmann64465292009-12-08 13:11:45 +0100268static int default_vga = 1;
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +0100269static int default_floppy = 1;
270static int default_cdrom = 1;
271static int default_sdcard = 1;
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100272
273static struct {
274 const char *driver;
275 int *flag;
276} default_list[] = {
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +0100277 { .driver = "isa-serial", .flag = &default_serial },
278 { .driver = "isa-parallel", .flag = &default_parallel },
Gerd Hoffmannd8bcbab2009-12-16 14:25:40 +0100279 { .driver = "isa-fdc", .flag = &default_floppy },
280 { .driver = "ide-drive", .flag = &default_cdrom },
Amit Shah392ecf52010-01-21 16:19:23 +0530281 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
282 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
283 { .driver = "virtio-serial", .flag = &default_virtcon },
Gerd Hoffmann64465292009-12-08 13:11:45 +0100284 { .driver = "VGA", .flag = &default_vga },
Gerd Hoffmann69fd02e2009-12-16 13:35:19 +0100285 { .driver = "cirrus-vga", .flag = &default_vga },
286 { .driver = "vmware-svga", .flag = &default_vga },
Gerd Hoffmann998bbd72009-12-08 13:11:41 +0100287};
288
289static int default_driver_check(QemuOpts *opts, void *opaque)
290{
291 const char *driver = qemu_opt_get(opts, "driver");
292 int i;
293
294 if (!driver)
295 return 0;
296 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
297 if (strcmp(default_list[i].driver, driver) != 0)
298 continue;
299 *(default_list[i].flag) = 0;
300 }
301 return 0;
302}
303
bellard0824d6f2003-06-24 13:42:40 +0000304/***********************************************************/
Paolo Bonzini8f0056b2010-01-13 14:05:34 +0100305/* real time host monotonic timer */
bellard09b26c52006-04-12 21:09:08 +0000306
bellardc4b1fcc2004-03-14 21:44:30 +0000307/***********************************************************/
balrogf6503052008-02-17 11:42:19 +0000308/* host time/date access */
309void qemu_get_timedate(struct tm *tm, int offset)
310{
311 time_t ti;
312 struct tm *ret;
313
314 time(&ti);
315 ti += offset;
316 if (rtc_date_offset == -1) {
317 if (rtc_utc)
318 ret = gmtime(&ti);
319 else
320 ret = localtime(&ti);
321 } else {
322 ti -= rtc_date_offset;
323 ret = gmtime(&ti);
324 }
325
326 memcpy(tm, ret, sizeof(struct tm));
327}
328
329int qemu_timedate_diff(struct tm *tm)
330{
331 time_t seconds;
332
333 if (rtc_date_offset == -1)
334 if (rtc_utc)
335 seconds = mktimegm(tm);
336 else
337 seconds = mktime(tm);
338 else
339 seconds = mktimegm(tm) + rtc_date_offset;
340
341 return seconds - time(NULL);
342}
343
Luiz Capitulino80cd3472010-02-25 12:11:44 -0300344void rtc_change_mon_event(struct tm *tm)
345{
346 QObject *data;
347
348 data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
349 monitor_protocol_event(QEVENT_RTC_CHANGE, data);
350 qobject_decref(data);
351}
352
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200353static void configure_rtc_date_offset(const char *startdate, int legacy)
354{
355 time_t rtc_start_date;
356 struct tm tm;
357
358 if (!strcmp(startdate, "now") && legacy) {
359 rtc_date_offset = -1;
360 } else {
361 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
362 &tm.tm_year,
363 &tm.tm_mon,
364 &tm.tm_mday,
365 &tm.tm_hour,
366 &tm.tm_min,
367 &tm.tm_sec) == 6) {
368 /* OK */
369 } else if (sscanf(startdate, "%d-%d-%d",
370 &tm.tm_year,
371 &tm.tm_mon,
372 &tm.tm_mday) == 3) {
373 tm.tm_hour = 0;
374 tm.tm_min = 0;
375 tm.tm_sec = 0;
376 } else {
377 goto date_fail;
378 }
379 tm.tm_year -= 1900;
380 tm.tm_mon--;
381 rtc_start_date = mktimegm(&tm);
382 if (rtc_start_date == -1) {
383 date_fail:
384 fprintf(stderr, "Invalid date format. Valid formats are:\n"
385 "'2006-06-17T16:01:21' or '2006-06-17'\n");
386 exit(1);
387 }
388 rtc_date_offset = time(NULL) - rtc_start_date;
389 }
390}
391
392static void configure_rtc(QemuOpts *opts)
393{
394 const char *value;
395
396 value = qemu_opt_get(opts, "base");
397 if (value) {
398 if (!strcmp(value, "utc")) {
399 rtc_utc = 1;
400 } else if (!strcmp(value, "localtime")) {
401 rtc_utc = 0;
402 } else {
403 configure_rtc_date_offset(value, 0);
404 }
405 }
Jan Kiszka68752042009-09-15 13:36:04 +0200406 value = qemu_opt_get(opts, "clock");
407 if (value) {
408 if (!strcmp(value, "host")) {
409 rtc_clock = host_clock;
410 } else if (!strcmp(value, "vm")) {
411 rtc_clock = vm_clock;
412 } else {
413 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
414 exit(1);
415 }
416 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200417 value = qemu_opt_get(opts, "driftfix");
418 if (value) {
Blue Swirl7e4c0332010-03-27 21:33:46 +0000419 if (!strcmp(value, "slew")) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200420 rtc_td_hack = 1;
Blue Swirl7e4c0332010-03-27 21:33:46 +0000421 } else if (!strcmp(value, "none")) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200422 rtc_td_hack = 0;
423 } else {
424 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
425 exit(1);
426 }
427 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +0200428}
429
balrog1ae26a12008-09-28 23:19:47 +0000430/***********************************************************/
431/* Bluetooth support */
432static int nb_hcis;
433static int cur_hci;
434static struct HCIInfo *hci_table[MAX_NICS];
balrogdc72ac12008-11-09 00:04:26 +0000435
balrog1ae26a12008-09-28 23:19:47 +0000436static struct bt_vlan_s {
437 struct bt_scatternet_s net;
438 int id;
439 struct bt_vlan_s *next;
440} *first_bt_vlan;
441
442/* find or alloc a new bluetooth "VLAN" */
blueswir1674bb262008-09-30 18:18:27 +0000443static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
balrog1ae26a12008-09-28 23:19:47 +0000444{
445 struct bt_vlan_s **pvlan, *vlan;
446 for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) {
447 if (vlan->id == id)
448 return &vlan->net;
449 }
450 vlan = qemu_mallocz(sizeof(struct bt_vlan_s));
451 vlan->id = id;
452 pvlan = &first_bt_vlan;
453 while (*pvlan != NULL)
454 pvlan = &(*pvlan)->next;
455 *pvlan = vlan;
456 return &vlan->net;
457}
458
459static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
460{
461}
462
463static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
464{
465 return -ENOTSUP;
466}
467
468static struct HCIInfo null_hci = {
469 .cmd_send = null_hci_send,
470 .sco_send = null_hci_send,
471 .acl_send = null_hci_send,
472 .bdaddr_set = null_hci_addr_set,
473};
474
475struct HCIInfo *qemu_next_hci(void)
476{
477 if (cur_hci == nb_hcis)
478 return &null_hci;
479
480 return hci_table[cur_hci++];
481}
482
balrogdc72ac12008-11-09 00:04:26 +0000483static struct HCIInfo *hci_init(const char *str)
484{
485 char *endp;
486 struct bt_scatternet_s *vlan = 0;
487
488 if (!strcmp(str, "null"))
489 /* null */
490 return &null_hci;
491 else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':'))
492 /* host[:hciN] */
493 return bt_host_hci(str[4] ? str + 5 : "hci0");
494 else if (!strncmp(str, "hci", 3)) {
495 /* hci[,vlan=n] */
496 if (str[3]) {
497 if (!strncmp(str + 3, ",vlan=", 6)) {
498 vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0));
499 if (*endp)
500 vlan = 0;
501 }
502 } else
503 vlan = qemu_find_bt_vlan(0);
504 if (vlan)
505 return bt_new_hci(vlan);
506 }
507
508 fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
509
510 return 0;
511}
512
513static int bt_hci_parse(const char *str)
514{
515 struct HCIInfo *hci;
Anthony Liguoric227f092009-10-01 16:12:16 -0500516 bdaddr_t bdaddr;
balrogdc72ac12008-11-09 00:04:26 +0000517
518 if (nb_hcis >= MAX_NICS) {
519 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
520 return -1;
521 }
522
523 hci = hci_init(str);
524 if (!hci)
525 return -1;
526
527 bdaddr.b[0] = 0x52;
528 bdaddr.b[1] = 0x54;
529 bdaddr.b[2] = 0x00;
530 bdaddr.b[3] = 0x12;
531 bdaddr.b[4] = 0x34;
532 bdaddr.b[5] = 0x56 + nb_hcis;
533 hci->bdaddr_set(hci, bdaddr.b);
534
535 hci_table[nb_hcis++] = hci;
536
537 return 0;
538}
539
540static void bt_vhci_add(int vlan_id)
541{
542 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
543
544 if (!vlan->slave)
545 fprintf(stderr, "qemu: warning: adding a VHCI to "
546 "an empty scatternet %i\n", vlan_id);
547
548 bt_vhci_init(bt_new_hci(vlan));
549}
550
551static struct bt_device_s *bt_device_add(const char *opt)
552{
553 struct bt_scatternet_s *vlan;
554 int vlan_id = 0;
555 char *endp = strstr(opt, ",vlan=");
556 int len = (endp ? endp - opt : strlen(opt)) + 1;
557 char devname[10];
558
559 pstrcpy(devname, MIN(sizeof(devname), len), opt);
560
561 if (endp) {
562 vlan_id = strtol(endp + 6, &endp, 0);
563 if (*endp) {
564 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
565 return 0;
566 }
567 }
568
569 vlan = qemu_find_bt_vlan(vlan_id);
570
571 if (!vlan->slave)
572 fprintf(stderr, "qemu: warning: adding a slave device to "
573 "an empty scatternet %i\n", vlan_id);
574
575 if (!strcmp(devname, "keyboard"))
576 return bt_keyboard_init(vlan);
577
578 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
579 return 0;
580}
581
582static int bt_parse(const char *opt)
583{
584 const char *endp, *p;
585 int vlan;
586
587 if (strstart(opt, "hci", &endp)) {
588 if (!*endp || *endp == ',') {
589 if (*endp)
590 if (!strstart(endp, ",vlan=", 0))
591 opt = endp + 1;
592
593 return bt_hci_parse(opt);
594 }
595 } else if (strstart(opt, "vhci", &endp)) {
596 if (!*endp || *endp == ',') {
597 if (*endp) {
598 if (strstart(endp, ",vlan=", &p)) {
599 vlan = strtol(p, (char **) &endp, 0);
600 if (*endp) {
601 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
602 return 1;
603 }
604 } else {
605 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
606 return 1;
607 }
608 } else
609 vlan = 0;
610
611 bt_vhci_add(vlan);
612 return 0;
613 }
614 } else if (strstart(opt, "device:", &endp))
615 return !bt_device_add(endp);
616
617 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
618 return 1;
619}
620
balrog1ae26a12008-09-28 23:19:47 +0000621/***********************************************************/
622/* QEMU Block devices */
623
Markus Armbruster2292dda2011-01-28 11:21:41 +0100624#define HD_OPTS "media=disk"
625#define CDROM_OPTS "media=cdrom"
626#define FD_OPTS ""
627#define PFLASH_OPTS ""
628#define MTD_OPTS ""
629#define SD_OPTS ""
thse4bcb142007-12-02 04:51:10 +0000630
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200631static int drive_init_func(QemuOpts *opts, void *opaque)
632{
Markus Armbrustera803cb82010-06-02 13:31:55 +0200633 int *use_scsi = opaque;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200634
Markus Armbruster319ae522011-01-28 11:21:46 +0100635 return drive_init(opts, *use_scsi) == NULL;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200636}
637
638static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
639{
640 if (NULL == qemu_opt_get(opts, "snapshot")) {
641 qemu_opt_set(opts, "snapshot", "on");
642 }
643 return 0;
644}
645
Markus Armbruster4e5d9b52011-01-28 11:21:45 +0100646static void default_drive(int enable, int snapshot, int use_scsi,
647 BlockInterfaceType type, int index,
648 const char *optstr)
649{
650 QemuOpts *opts;
651
652 if (type == IF_DEFAULT) {
653 type = use_scsi ? IF_SCSI : IF_IDE;
654 }
655
656 if (!enable || drive_get_by_index(type, index)) {
657 return;
658 }
659
660 opts = drive_add(type, index, NULL, optstr);
661 if (snapshot) {
662 drive_enable_snapshot(opts, NULL);
663 }
Markus Armbruster319ae522011-01-28 11:21:46 +0100664 if (!drive_init(opts, use_scsi)) {
Markus Armbruster4e5d9b52011-01-28 11:21:45 +0100665 exit(1);
666 }
667}
668
Jan Kiszka76e30d02009-07-02 00:19:02 +0200669void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
670{
671 boot_set_handler = func;
672 boot_set_opaque = opaque;
673}
674
675int qemu_boot_set(const char *boot_devices)
676{
677 if (!boot_set_handler) {
678 return -EINVAL;
679 }
680 return boot_set_handler(boot_set_opaque, boot_devices);
681}
682
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -0300683static void validate_bootdevices(char *devices)
Jan Kiszkaef3adf62009-07-02 00:19:02 +0200684{
685 /* We just do some generic consistency checks */
686 const char *p;
687 int bitmap = 0;
688
689 for (p = devices; *p != '\0'; p++) {
690 /* Allowed boot devices are:
691 * a-b: floppy disk drives
692 * c-f: IDE disk drives
693 * g-m: machine implementation dependant drives
694 * n-p: network devices
695 * It's up to each machine implementation to check if the given boot
696 * devices match the actual hardware implementation and firmware
697 * features.
698 */
699 if (*p < 'a' || *p > 'p') {
700 fprintf(stderr, "Invalid boot device '%c'\n", *p);
701 exit(1);
702 }
703 if (bitmap & (1 << (*p - 'a'))) {
704 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
705 exit(1);
706 }
707 bitmap |= 1 << (*p - 'a');
708 }
Jan Kiszkaef3adf62009-07-02 00:19:02 +0200709}
710
Jan Kiszkae0f084b2009-07-02 00:19:02 +0200711static void restore_boot_devices(void *opaque)
712{
713 char *standard_boot_devices = opaque;
Alex Williamson37905d62010-04-30 15:21:11 -0600714 static int first = 1;
715
716 /* Restore boot order and remove ourselves after the first boot */
717 if (first) {
718 first = 0;
719 return;
720 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +0200721
722 qemu_boot_set(standard_boot_devices);
723
724 qemu_unregister_reset(restore_boot_devices, standard_boot_devices);
725 qemu_free(standard_boot_devices);
726}
727
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200728void add_boot_device_path(int32_t bootindex, DeviceState *dev,
729 const char *suffix)
730{
731 FWBootEntry *node, *i;
732
733 if (bootindex < 0) {
734 return;
735 }
736
737 assert(dev != NULL || suffix != NULL);
738
739 node = qemu_mallocz(sizeof(FWBootEntry));
740 node->bootindex = bootindex;
Gleb Natapov4fef9302011-02-02 17:34:34 +0200741 node->suffix = suffix ? qemu_strdup(suffix) : NULL;
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200742 node->dev = dev;
743
744 QTAILQ_FOREACH(i, &fw_boot_order, link) {
745 if (i->bootindex == bootindex) {
746 fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
747 exit(1);
748 } else if (i->bootindex < bootindex) {
749 continue;
750 }
751 QTAILQ_INSERT_BEFORE(i, node, link);
752 return;
753 }
754 QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
755}
756
Gleb Natapov962630f2010-12-08 13:35:09 +0200757/*
758 * This function returns null terminated string that consist of new line
759 * separated device pathes.
760 *
761 * memory pointed by "size" is assigned total length of the array in bytes
762 *
763 */
764char *get_boot_devices_list(uint32_t *size)
765{
766 FWBootEntry *i;
767 uint32_t total = 0;
768 char *list = NULL;
769
770 QTAILQ_FOREACH(i, &fw_boot_order, link) {
771 char *devpath = NULL, *bootpath;
772 int len;
773
774 if (i->dev) {
775 devpath = qdev_get_fw_dev_path(i->dev);
776 assert(devpath);
777 }
778
779 if (i->suffix && devpath) {
Blue Swirl4fd37a92010-12-19 14:05:43 +0000780 size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
781
782 bootpath = qemu_malloc(bootpathlen);
783 snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
Gleb Natapov962630f2010-12-08 13:35:09 +0200784 qemu_free(devpath);
785 } else if (devpath) {
786 bootpath = devpath;
787 } else {
Gleb Natapov4fef9302011-02-02 17:34:34 +0200788 bootpath = qemu_strdup(i->suffix);
Gleb Natapov962630f2010-12-08 13:35:09 +0200789 assert(bootpath);
790 }
791
792 if (total) {
793 list[total-1] = '\n';
794 }
795 len = strlen(bootpath) + 1;
796 list = qemu_realloc(list, total + len);
797 memcpy(&list[total], bootpath, len);
798 total += len;
799 qemu_free(bootpath);
800 }
801
802 *size = total;
803
804 return list;
805}
806
aliguori268a3622009-04-21 22:30:27 +0000807static void numa_add(const char *optarg)
808{
809 char option[128];
810 char *endptr;
811 unsigned long long value, endvalue;
812 int nodenr;
813
814 optarg = get_opt_name(option, 128, optarg, ',') + 1;
815 if (!strcmp(option, "node")) {
816 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
817 nodenr = nb_numa_nodes;
818 } else {
819 nodenr = strtoull(option, NULL, 10);
820 }
821
822 if (get_param_value(option, 128, "mem", optarg) == 0) {
823 node_mem[nodenr] = 0;
824 } else {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +0100825 int64_t sval;
Jes Sorensen9f9b17a2010-10-21 17:15:46 +0200826 sval = strtosz(option, NULL);
827 if (sval < 0) {
828 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
829 exit(1);
aliguori268a3622009-04-21 22:30:27 +0000830 }
Jes Sorensen9f9b17a2010-10-21 17:15:46 +0200831 node_mem[nodenr] = sval;
aliguori268a3622009-04-21 22:30:27 +0000832 }
833 if (get_param_value(option, 128, "cpus", optarg) == 0) {
834 node_cpumask[nodenr] = 0;
835 } else {
836 value = strtoull(option, &endptr, 10);
837 if (value >= 64) {
838 value = 63;
839 fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n");
840 } else {
841 if (*endptr == '-') {
842 endvalue = strtoull(endptr+1, &endptr, 10);
843 if (endvalue >= 63) {
844 endvalue = 62;
845 fprintf(stderr,
846 "only 63 CPUs in NUMA mode supported.\n");
847 }
Paolo Bonzini0dfbd512010-02-04 14:31:50 +0100848 value = (2ULL << endvalue) - (1ULL << value);
aliguori268a3622009-04-21 22:30:27 +0000849 } else {
Paolo Bonzini0dfbd512010-02-04 14:31:50 +0100850 value = 1ULL << value;
aliguori268a3622009-04-21 22:30:27 +0000851 }
852 }
853 node_cpumask[nodenr] = value;
854 }
855 nb_numa_nodes++;
856 }
857 return;
858}
859
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200860static void smp_parse(const char *optarg)
861{
862 int smp, sockets = 0, threads = 0, cores = 0;
863 char *endptr;
864 char option[128];
865
866 smp = strtoul(optarg, &endptr, 10);
867 if (endptr != optarg) {
868 if (*endptr == ',') {
869 endptr++;
870 }
871 }
872 if (get_param_value(option, 128, "sockets", endptr) != 0)
873 sockets = strtoull(option, NULL, 10);
874 if (get_param_value(option, 128, "cores", endptr) != 0)
875 cores = strtoull(option, NULL, 10);
876 if (get_param_value(option, 128, "threads", endptr) != 0)
877 threads = strtoull(option, NULL, 10);
878 if (get_param_value(option, 128, "maxcpus", endptr) != 0)
879 max_cpus = strtoull(option, NULL, 10);
880
881 /* compute missing values, prefer sockets over cores over threads */
882 if (smp == 0 || sockets == 0) {
883 sockets = sockets > 0 ? sockets : 1;
884 cores = cores > 0 ? cores : 1;
885 threads = threads > 0 ? threads : 1;
886 if (smp == 0) {
887 smp = cores * threads * sockets;
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200888 }
889 } else {
890 if (cores == 0) {
891 threads = threads > 0 ? threads : 1;
892 cores = smp / (sockets * threads);
893 } else {
Joel Schoppdca98162010-07-21 15:05:17 -0500894 threads = smp / (cores * sockets);
Andre Przywaradc6b1c02009-08-19 15:42:40 +0200895 }
896 }
897 smp_cpus = smp;
898 smp_cores = cores > 0 ? cores : 1;
899 smp_threads = threads > 0 ? threads : 1;
900 if (max_cpus == 0)
901 max_cpus = smp_cpus;
902}
903
bellard330d0412003-07-26 18:11:40 +0000904/***********************************************************/
bellarda594cfb2005-11-06 16:13:29 +0000905/* USB devices */
906
Markus Armbrusterfb080002010-05-28 15:38:44 +0200907static int usb_device_add(const char *devname)
bellarda594cfb2005-11-06 16:13:29 +0000908{
909 const char *p;
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200910 USBDevice *dev = NULL;
bellarda594cfb2005-11-06 16:13:29 +0000911
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200912 if (!usb_enabled)
bellarda594cfb2005-11-06 16:13:29 +0000913 return -1;
914
Gerd Hoffmann0958b4c2009-10-26 15:56:45 +0100915 /* drivers with .usbdevice_name entry in USBDeviceInfo */
916 dev = usbdevice_create(devname);
917 if (dev)
918 goto done;
919
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200920 /* the other ones */
bellarda594cfb2005-11-06 16:13:29 +0000921 if (strstart(devname, "host:", &p)) {
922 dev = usb_host_device_open(p);
balrogdc72ac12008-11-09 00:04:26 +0000923 } else if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
924 dev = usb_bt_init(devname[2] ? hci_init(p) :
925 bt_new_hci(qemu_find_bt_vlan(0)));
bellarda594cfb2005-11-06 16:13:29 +0000926 } else {
927 return -1;
928 }
pbrook0d92ed32006-05-21 16:30:15 +0000929 if (!dev)
930 return -1;
931
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200932done:
bellarda594cfb2005-11-06 16:13:29 +0000933 return 0;
934}
935
aliguori1f3870a2008-08-21 19:27:48 +0000936static int usb_device_del(const char *devname)
937{
938 int bus_num, addr;
939 const char *p;
940
aliguori5d0c5752008-09-14 01:07:41 +0000941 if (strstart(devname, "host:", &p))
942 return usb_host_device_close(p);
943
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200944 if (!usb_enabled)
aliguori1f3870a2008-08-21 19:27:48 +0000945 return -1;
946
947 p = strchr(devname, '.');
948 if (!p)
949 return -1;
950 bus_num = strtoul(devname, NULL, 0);
951 addr = strtoul(p + 1, NULL, 0);
952
Gerd Hoffmanna5d2f722009-08-31 14:24:00 +0200953 return usb_device_delete_addr(bus_num, addr);
aliguori1f3870a2008-08-21 19:27:48 +0000954}
955
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +0200956static int usb_parse(const char *cmdline)
957{
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800958 int r;
Markus Armbrusterfb080002010-05-28 15:38:44 +0200959 r = usb_device_add(cmdline);
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800960 if (r < 0) {
961 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
962 }
963 return r;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +0200964}
965
Luiz Capitulinod54908a2009-08-28 15:27:13 -0300966void do_usb_add(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +0000967{
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800968 const char *devname = qdict_get_str(qdict, "devname");
Markus Armbrusterfb080002010-05-28 15:38:44 +0200969 if (usb_device_add(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +0100970 error_report("could not add USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800971 }
bellarda594cfb2005-11-06 16:13:29 +0000972}
973
Luiz Capitulinod54908a2009-08-28 15:27:13 -0300974void do_usb_del(Monitor *mon, const QDict *qdict)
bellarda594cfb2005-11-06 16:13:29 +0000975{
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800976 const char *devname = qdict_get_str(qdict, "devname");
977 if (usb_device_del(devname) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +0100978 error_report("could not delete USB device '%s'", devname);
Scott Tsai59d1c1c2009-12-23 04:30:18 +0800979 }
bellarda594cfb2005-11-06 16:13:29 +0000980}
981
bellardf7cce892004-12-08 22:21:25 +0000982/***********************************************************/
balrog201a51f2007-04-30 00:51:09 +0000983/* PCMCIA/Cardbus */
984
985static struct pcmcia_socket_entry_s {
Paul Brookbc24a222009-05-10 01:44:56 +0100986 PCMCIASocket *socket;
balrog201a51f2007-04-30 00:51:09 +0000987 struct pcmcia_socket_entry_s *next;
988} *pcmcia_sockets = 0;
989
Paul Brookbc24a222009-05-10 01:44:56 +0100990void pcmcia_socket_register(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +0000991{
992 struct pcmcia_socket_entry_s *entry;
993
994 entry = qemu_malloc(sizeof(struct pcmcia_socket_entry_s));
995 entry->socket = socket;
996 entry->next = pcmcia_sockets;
997 pcmcia_sockets = entry;
998}
999
Paul Brookbc24a222009-05-10 01:44:56 +01001000void pcmcia_socket_unregister(PCMCIASocket *socket)
balrog201a51f2007-04-30 00:51:09 +00001001{
1002 struct pcmcia_socket_entry_s *entry, **ptr;
1003
1004 ptr = &pcmcia_sockets;
1005 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1006 if (entry->socket == socket) {
1007 *ptr = entry->next;
1008 qemu_free(entry);
1009 }
1010}
1011
aliguori376253e2009-03-05 23:01:23 +00001012void pcmcia_info(Monitor *mon)
balrog201a51f2007-04-30 00:51:09 +00001013{
1014 struct pcmcia_socket_entry_s *iter;
aliguori376253e2009-03-05 23:01:23 +00001015
balrog201a51f2007-04-30 00:51:09 +00001016 if (!pcmcia_sockets)
aliguori376253e2009-03-05 23:01:23 +00001017 monitor_printf(mon, "No PCMCIA sockets\n");
balrog201a51f2007-04-30 00:51:09 +00001018
1019 for (iter = pcmcia_sockets; iter; iter = iter->next)
aliguori376253e2009-03-05 23:01:23 +00001020 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1021 iter->socket->attached ? iter->socket->card_string :
1022 "Empty");
balrog201a51f2007-04-30 00:51:09 +00001023}
1024
1025/***********************************************************/
bellard8a7ddc32004-03-31 19:00:16 +00001026/* I/O handling */
bellard0824d6f2003-06-24 13:42:40 +00001027
bellardc4b1fcc2004-03-14 21:44:30 +00001028typedef struct IOHandlerRecord {
1029 int fd;
Juan Quintela7b27a762010-03-11 17:55:39 +01001030 IOCanReadHandler *fd_read_poll;
bellard7c9d8e02005-11-15 22:16:05 +00001031 IOHandler *fd_read;
1032 IOHandler *fd_write;
thscafffd42007-02-28 21:59:44 +00001033 int deleted;
bellardc4b1fcc2004-03-14 21:44:30 +00001034 void *opaque;
1035 /* temporary data */
1036 struct pollfd *ufd;
Juan Quintela31d4ee62010-03-11 17:55:37 +01001037 QLIST_ENTRY(IOHandlerRecord) next;
bellardc4b1fcc2004-03-14 21:44:30 +00001038} IOHandlerRecord;
1039
Juan Quintela31d4ee62010-03-11 17:55:37 +01001040static QLIST_HEAD(, IOHandlerRecord) io_handlers =
1041 QLIST_HEAD_INITIALIZER(io_handlers);
1042
bellardc4b1fcc2004-03-14 21:44:30 +00001043
bellard7c9d8e02005-11-15 22:16:05 +00001044/* XXX: fd_read_poll should be suppressed, but an API change is
1045 necessary in the character devices to suppress fd_can_read(). */
ths5fafdf22007-09-16 21:08:06 +00001046int qemu_set_fd_handler2(int fd,
Juan Quintela7b27a762010-03-11 17:55:39 +01001047 IOCanReadHandler *fd_read_poll,
ths5fafdf22007-09-16 21:08:06 +00001048 IOHandler *fd_read,
1049 IOHandler *fd_write,
bellard7c9d8e02005-11-15 22:16:05 +00001050 void *opaque)
bellardb4608c02003-06-27 17:34:32 +00001051{
Juan Quintela31d4ee62010-03-11 17:55:37 +01001052 IOHandlerRecord *ioh;
bellard8a7ddc32004-03-31 19:00:16 +00001053
bellard7c9d8e02005-11-15 22:16:05 +00001054 if (!fd_read && !fd_write) {
Juan Quintela31d4ee62010-03-11 17:55:37 +01001055 QLIST_FOREACH(ioh, &io_handlers, next) {
bellard7c9d8e02005-11-15 22:16:05 +00001056 if (ioh->fd == fd) {
thscafffd42007-02-28 21:59:44 +00001057 ioh->deleted = 1;
bellard7c9d8e02005-11-15 22:16:05 +00001058 break;
1059 }
bellard8a7ddc32004-03-31 19:00:16 +00001060 }
bellard7c9d8e02005-11-15 22:16:05 +00001061 } else {
Juan Quintela31d4ee62010-03-11 17:55:37 +01001062 QLIST_FOREACH(ioh, &io_handlers, next) {
bellard7c9d8e02005-11-15 22:16:05 +00001063 if (ioh->fd == fd)
1064 goto found;
1065 }
1066 ioh = qemu_mallocz(sizeof(IOHandlerRecord));
Juan Quintela31d4ee62010-03-11 17:55:37 +01001067 QLIST_INSERT_HEAD(&io_handlers, ioh, next);
bellard7c9d8e02005-11-15 22:16:05 +00001068 found:
1069 ioh->fd = fd;
1070 ioh->fd_read_poll = fd_read_poll;
1071 ioh->fd_read = fd_read;
1072 ioh->fd_write = fd_write;
1073 ioh->opaque = opaque;
thscafffd42007-02-28 21:59:44 +00001074 ioh->deleted = 0;
bellard8a7ddc32004-03-31 19:00:16 +00001075 }
bellard7c9d8e02005-11-15 22:16:05 +00001076 return 0;
1077}
1078
ths5fafdf22007-09-16 21:08:06 +00001079int qemu_set_fd_handler(int fd,
1080 IOHandler *fd_read,
1081 IOHandler *fd_write,
bellard7c9d8e02005-11-15 22:16:05 +00001082 void *opaque)
1083{
1084 return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque);
bellardb4608c02003-06-27 17:34:32 +00001085}
1086
bellard8a7ddc32004-03-31 19:00:16 +00001087/***********************************************************/
bellardcc1daa42005-06-05 14:49:17 +00001088/* machine registration */
1089
blueswir1bdaf78e2008-10-04 07:24:27 +00001090static QEMUMachine *first_machine = NULL;
aliguori6f338c32009-02-11 15:21:54 +00001091QEMUMachine *current_machine = NULL;
bellardcc1daa42005-06-05 14:49:17 +00001092
1093int qemu_register_machine(QEMUMachine *m)
1094{
1095 QEMUMachine **pm;
1096 pm = &first_machine;
1097 while (*pm != NULL)
1098 pm = &(*pm)->next;
1099 m->next = NULL;
1100 *pm = m;
1101 return 0;
1102}
1103
pbrook9596ebb2007-11-18 01:44:38 +00001104static QEMUMachine *find_machine(const char *name)
bellardcc1daa42005-06-05 14:49:17 +00001105{
1106 QEMUMachine *m;
1107
1108 for(m = first_machine; m != NULL; m = m->next) {
1109 if (!strcmp(m->name, name))
1110 return m;
Mark McLoughlin3f6599e2009-07-22 10:02:50 +01001111 if (m->alias && !strcmp(m->alias, name))
1112 return m;
bellardcc1daa42005-06-05 14:49:17 +00001113 }
1114 return NULL;
1115}
1116
Anthony Liguori0c257432009-05-21 20:41:01 -05001117static QEMUMachine *find_default_machine(void)
1118{
1119 QEMUMachine *m;
1120
1121 for(m = first_machine; m != NULL; m = m->next) {
1122 if (m->is_default) {
1123 return m;
1124 }
1125 }
1126 return NULL;
1127}
1128
bellardcc1daa42005-06-05 14:49:17 +00001129/***********************************************************/
bellard8a7ddc32004-03-31 19:00:16 +00001130/* main execution loop */
1131
pbrook9596ebb2007-11-18 01:44:38 +00001132static void gui_update(void *opaque)
bellard8a7ddc32004-03-31 19:00:16 +00001133{
aliguori7d957bd2009-01-15 22:14:11 +00001134 uint64_t interval = GUI_REFRESH_INTERVAL;
ths740733b2007-06-08 01:57:56 +00001135 DisplayState *ds = opaque;
aliguori7d957bd2009-01-15 22:14:11 +00001136 DisplayChangeListener *dcl = ds->listeners;
1137
Sheng Yang62a27442010-01-26 19:21:16 +08001138 qemu_flush_coalesced_mmio_buffer();
aliguori7d957bd2009-01-15 22:14:11 +00001139 dpy_refresh(ds);
1140
1141 while (dcl != NULL) {
1142 if (dcl->gui_timer_interval &&
1143 dcl->gui_timer_interval < interval)
1144 interval = dcl->gui_timer_interval;
1145 dcl = dcl->next;
1146 }
1147 qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock));
bellard8a7ddc32004-03-31 19:00:16 +00001148}
1149
blueswir19043b622009-01-21 19:28:13 +00001150static void nographic_update(void *opaque)
1151{
1152 uint64_t interval = GUI_REFRESH_INTERVAL;
1153
Sheng Yang62a27442010-01-26 19:21:16 +08001154 qemu_flush_coalesced_mmio_buffer();
blueswir19043b622009-01-21 19:28:13 +00001155 qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock));
1156}
1157
bellard0bd48852005-11-11 00:00:47 +00001158struct vm_change_state_entry {
1159 VMChangeStateHandler *cb;
1160 void *opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001161 QLIST_ENTRY (vm_change_state_entry) entries;
bellard0bd48852005-11-11 00:00:47 +00001162};
1163
Blue Swirl72cf2d42009-09-12 07:36:22 +00001164static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
bellard0bd48852005-11-11 00:00:47 +00001165
1166VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1167 void *opaque)
1168{
1169 VMChangeStateEntry *e;
1170
1171 e = qemu_mallocz(sizeof (*e));
bellard0bd48852005-11-11 00:00:47 +00001172
1173 e->cb = cb;
1174 e->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001175 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
bellard0bd48852005-11-11 00:00:47 +00001176 return e;
1177}
1178
1179void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1180{
Blue Swirl72cf2d42009-09-12 07:36:22 +00001181 QLIST_REMOVE (e, entries);
bellard0bd48852005-11-11 00:00:47 +00001182 qemu_free (e);
1183}
1184
Blue Swirl296af7c2010-03-29 19:23:50 +00001185void vm_state_notify(int running, int reason)
bellard0bd48852005-11-11 00:00:47 +00001186{
1187 VMChangeStateEntry *e;
1188
Stefan Hajnoczi94b0b5f2010-11-16 12:20:25 +00001189 trace_vm_state_notify(running, reason);
1190
bellard0bd48852005-11-11 00:00:47 +00001191 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
aliguori9781e042009-01-22 17:15:29 +00001192 e->cb(e->opaque, running, reason);
bellard0bd48852005-11-11 00:00:47 +00001193 }
1194}
1195
bellard8a7ddc32004-03-31 19:00:16 +00001196void vm_start(void)
1197{
1198 if (!vm_running) {
1199 cpu_enable_ticks();
1200 vm_running = 1;
aliguori9781e042009-01-22 17:15:29 +00001201 vm_state_notify(1, 0);
aliguorid6dc3d42009-04-24 18:04:07 +00001202 resume_all_vcpus();
Luiz Capitulino6ed2c482010-04-27 20:35:59 -03001203 monitor_protocol_event(QEVENT_RESUME, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00001204 }
1205}
1206
bellardbb0c6722004-06-20 12:37:32 +00001207/* reset/shutdown handler */
1208
1209typedef struct QEMUResetEntry {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001210 QTAILQ_ENTRY(QEMUResetEntry) entry;
bellardbb0c6722004-06-20 12:37:32 +00001211 QEMUResetHandler *func;
1212 void *opaque;
bellardbb0c6722004-06-20 12:37:32 +00001213} QEMUResetEntry;
1214
Blue Swirl72cf2d42009-09-12 07:36:22 +00001215static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1216 QTAILQ_HEAD_INITIALIZER(reset_handlers);
bellardbb0c6722004-06-20 12:37:32 +00001217static int reset_requested;
1218static int shutdown_requested;
bellard34751872005-07-02 14:31:34 +00001219static int powerdown_requested;
Blue Swirl296af7c2010-03-29 19:23:50 +00001220int debug_requested;
Blue Swirl7277e022010-04-12 17:19:06 +00001221int vmstop_requested;
bellardbb0c6722004-06-20 12:37:32 +00001222
aurel32cf7a2fe2008-03-18 06:53:05 +00001223int qemu_shutdown_requested(void)
1224{
1225 int r = shutdown_requested;
1226 shutdown_requested = 0;
1227 return r;
1228}
1229
1230int qemu_reset_requested(void)
1231{
1232 int r = reset_requested;
1233 reset_requested = 0;
1234 return r;
1235}
1236
1237int qemu_powerdown_requested(void)
1238{
1239 int r = powerdown_requested;
1240 powerdown_requested = 0;
1241 return r;
1242}
1243
aliguorie5689022009-04-24 18:03:54 +00001244static int qemu_debug_requested(void)
1245{
1246 int r = debug_requested;
1247 debug_requested = 0;
1248 return r;
1249}
1250
aliguori6e29f5d2009-04-24 18:04:02 +00001251static int qemu_vmstop_requested(void)
1252{
1253 int r = vmstop_requested;
1254 vmstop_requested = 0;
1255 return r;
1256}
1257
Jan Kiszkaa08d4362009-06-27 09:25:07 +02001258void qemu_register_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001259{
Jan Kiszka55ddfe82009-07-02 00:19:02 +02001260 QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry));
bellardbb0c6722004-06-20 12:37:32 +00001261
bellardbb0c6722004-06-20 12:37:32 +00001262 re->func = func;
1263 re->opaque = opaque;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001264 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
bellardbb0c6722004-06-20 12:37:32 +00001265}
1266
Jan Kiszkadda9b292009-07-02 00:19:02 +02001267void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
bellardbb0c6722004-06-20 12:37:32 +00001268{
1269 QEMUResetEntry *re;
1270
Blue Swirl72cf2d42009-09-12 07:36:22 +00001271 QTAILQ_FOREACH(re, &reset_handlers, entry) {
Jan Kiszkadda9b292009-07-02 00:19:02 +02001272 if (re->func == func && re->opaque == opaque) {
Blue Swirl72cf2d42009-09-12 07:36:22 +00001273 QTAILQ_REMOVE(&reset_handlers, re, entry);
Jan Kiszkadda9b292009-07-02 00:19:02 +02001274 qemu_free(re);
1275 return;
1276 }
1277 }
1278}
1279
1280void qemu_system_reset(void)
1281{
1282 QEMUResetEntry *re, *nre;
1283
1284 /* reset all devices */
Blue Swirl72cf2d42009-09-12 07:36:22 +00001285 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
bellardbb0c6722004-06-20 12:37:32 +00001286 re->func(re->opaque);
1287 }
Luiz Capitulino81d9b782010-03-10 09:06:34 -06001288 monitor_protocol_event(QEVENT_RESET, NULL);
Jan Kiszkaea375f92010-03-01 19:10:30 +01001289 cpu_synchronize_all_post_reset();
bellardbb0c6722004-06-20 12:37:32 +00001290}
1291
1292void qemu_system_reset_request(void)
1293{
bellardd1beab82006-10-02 19:44:22 +00001294 if (no_reboot) {
1295 shutdown_requested = 1;
1296 } else {
1297 reset_requested = 1;
1298 }
Jan Kiszkab4a3d962011-02-01 22:15:43 +01001299 cpu_stop_current();
aliguorid9f75a42009-04-24 18:03:11 +00001300 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001301}
1302
1303void qemu_system_shutdown_request(void)
1304{
1305 shutdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001306 qemu_notify_event();
bellardbb0c6722004-06-20 12:37:32 +00001307}
1308
bellard34751872005-07-02 14:31:34 +00001309void qemu_system_powerdown_request(void)
1310{
1311 powerdown_requested = 1;
aliguorid9f75a42009-04-24 18:03:11 +00001312 qemu_notify_event();
1313}
1314
Paolo Bonzinid6f4ade2010-03-10 11:38:54 +01001315void main_loop_wait(int nonblocking)
aliguori56f3a5d2008-10-31 18:07:17 +00001316{
1317 IOHandlerRecord *ioh;
1318 fd_set rfds, wfds, xfds;
1319 int ret, nfds;
1320 struct timeval tv;
Paolo Bonzinid6f4ade2010-03-10 11:38:54 +01001321 int timeout;
aliguori56f3a5d2008-10-31 18:07:17 +00001322
Paolo Bonzinid6f4ade2010-03-10 11:38:54 +01001323 if (nonblocking)
1324 timeout = 0;
1325 else {
1326 timeout = qemu_calculate_timeout();
1327 qemu_bh_update_timeout(&timeout);
1328 }
aliguori56f3a5d2008-10-31 18:07:17 +00001329
Jes Sorensen0d93ca72010-06-10 11:42:18 +02001330 os_host_main_loop_wait(&timeout);
aliguori56f3a5d2008-10-31 18:07:17 +00001331
bellardfd1dff42006-02-01 21:29:26 +00001332 /* poll any events */
1333 /* XXX: separate device handlers from system ones */
aliguori6abfbd72008-11-05 20:49:37 +00001334 nfds = -1;
bellardfd1dff42006-02-01 21:29:26 +00001335 FD_ZERO(&rfds);
1336 FD_ZERO(&wfds);
bellarde0356492006-05-01 13:33:02 +00001337 FD_ZERO(&xfds);
Juan Quintela31d4ee62010-03-11 17:55:37 +01001338 QLIST_FOREACH(ioh, &io_handlers, next) {
thscafffd42007-02-28 21:59:44 +00001339 if (ioh->deleted)
1340 continue;
bellardfd1dff42006-02-01 21:29:26 +00001341 if (ioh->fd_read &&
1342 (!ioh->fd_read_poll ||
1343 ioh->fd_read_poll(ioh->opaque) != 0)) {
1344 FD_SET(ioh->fd, &rfds);
1345 if (ioh->fd > nfds)
1346 nfds = ioh->fd;
1347 }
1348 if (ioh->fd_write) {
1349 FD_SET(ioh->fd, &wfds);
1350 if (ioh->fd > nfds)
1351 nfds = ioh->fd;
1352 }
1353 }
ths3b46e622007-09-17 08:09:54 +00001354
aliguori56f3a5d2008-10-31 18:07:17 +00001355 tv.tv_sec = timeout / 1000;
1356 tv.tv_usec = (timeout % 1000) * 1000;
1357
Jan Kiszkad918f232009-06-24 14:42:30 +02001358 slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
1359
aliguori48708522009-04-24 18:03:49 +00001360 qemu_mutex_unlock_iothread();
bellarde0356492006-05-01 13:33:02 +00001361 ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
aliguori48708522009-04-24 18:03:49 +00001362 qemu_mutex_lock_iothread();
bellardfd1dff42006-02-01 21:29:26 +00001363 if (ret > 0) {
Juan Quintela31d4ee62010-03-11 17:55:37 +01001364 IOHandlerRecord *pioh;
thscafffd42007-02-28 21:59:44 +00001365
Juan Quintela31d4ee62010-03-11 17:55:37 +01001366 QLIST_FOREACH_SAFE(ioh, &io_handlers, next, pioh) {
Stefan Hajnoczi0290b572010-11-03 14:29:44 +00001367 if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {
1368 ioh->fd_read(ioh->opaque);
1369 }
1370 if (!ioh->deleted && ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) {
1371 ioh->fd_write(ioh->opaque);
1372 }
1373
1374 /* Do this last in case read/write handlers marked it for deletion */
thscafffd42007-02-28 21:59:44 +00001375 if (ioh->deleted) {
Juan Quintela31d4ee62010-03-11 17:55:37 +01001376 QLIST_REMOVE(ioh, next);
thscafffd42007-02-28 21:59:44 +00001377 qemu_free(ioh);
Juan Quintela31d4ee62010-03-11 17:55:37 +01001378 }
thscafffd42007-02-28 21:59:44 +00001379 }
bellardfd1dff42006-02-01 21:29:26 +00001380 }
Jan Kiszkad918f232009-06-24 14:42:30 +02001381
1382 slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));
bellardc20709a2004-04-21 23:27:19 +00001383
Paolo Bonzinib6964822010-03-10 11:38:45 +01001384 qemu_run_all_timers();
Jan Kiszka21d5d122009-09-15 13:36:04 +02001385
pbrook423f0742007-05-23 00:06:54 +00001386 /* Check bottom-halves last in case any of the earlier events triggered
1387 them. */
1388 qemu_bh_poll();
ths3b46e622007-09-17 08:09:54 +00001389
bellard5905b2e2004-08-01 21:53:26 +00001390}
1391
Jan Kiszka46481d32011-02-01 22:15:47 +01001392#ifndef CONFIG_IOTHREAD
1393static int vm_request_pending(void)
aliguori43b96852009-04-24 18:03:33 +00001394{
Jan Kiszka46481d32011-02-01 22:15:47 +01001395 return powerdown_requested ||
1396 reset_requested ||
1397 shutdown_requested ||
1398 debug_requested ||
1399 vmstop_requested;
aliguori43b96852009-04-24 18:03:33 +00001400}
Jan Kiszka46481d32011-02-01 22:15:47 +01001401#endif
aliguori43b96852009-04-24 18:03:33 +00001402
Blue Swirld9c32312009-08-09 08:42:19 +00001403qemu_irq qemu_system_powerdown;
1404
aliguori43b96852009-04-24 18:03:33 +00001405static void main_loop(void)
1406{
Jan Kiszka8e1b90e2011-02-01 22:15:46 +01001407 bool nonblocking = false;
1408#ifdef CONFIG_PROFILER
1409 int64_t ti;
1410#endif
aliguori6e29f5d2009-04-24 18:04:02 +00001411 int r;
aliguori43b96852009-04-24 18:03:33 +00001412
Blue Swirl7277e022010-04-12 17:19:06 +00001413 qemu_main_loop_start();
aliguorid6dc3d42009-04-24 18:04:07 +00001414
aliguori6e29f5d2009-04-24 18:04:02 +00001415 for (;;) {
aliguorid6dc3d42009-04-24 18:04:07 +00001416#ifndef CONFIG_IOTHREAD
Jan Kiszka46481d32011-02-01 22:15:47 +01001417 nonblocking = cpu_exec_all();
1418 if (vm_request_pending()) {
1419 nonblocking = true;
1420 }
aliguorid6dc3d42009-04-24 18:04:07 +00001421#endif
aliguori43b96852009-04-24 18:03:33 +00001422#ifdef CONFIG_PROFILER
Jan Kiszka46481d32011-02-01 22:15:47 +01001423 ti = profile_getclock();
aliguori43b96852009-04-24 18:03:33 +00001424#endif
Jan Kiszka46481d32011-02-01 22:15:47 +01001425 main_loop_wait(nonblocking);
aliguori43b96852009-04-24 18:03:33 +00001426#ifdef CONFIG_PROFILER
Jan Kiszka46481d32011-02-01 22:15:47 +01001427 dev_time += profile_getclock() - ti;
aliguori43b96852009-04-24 18:03:33 +00001428#endif
aliguori43b96852009-04-24 18:03:33 +00001429
Blue Swirl54fc6ea2010-03-29 19:23:46 +00001430 if ((r = qemu_debug_requested())) {
1431 vm_stop(r);
Luiz Capitulinob1a15e72009-11-26 22:59:04 -02001432 }
aliguori43b96852009-04-24 18:03:33 +00001433 if (qemu_shutdown_requested()) {
Blue Swirl242cd002009-12-04 18:05:45 +00001434 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
aliguori43b96852009-04-24 18:03:33 +00001435 if (no_shutdown) {
Jan Kiszkae07bbac2011-02-09 16:29:40 +01001436 vm_stop(VMSTOP_SHUTDOWN);
aliguori43b96852009-04-24 18:03:33 +00001437 no_shutdown = 0;
1438 } else
1439 break;
1440 }
aliguorid6dc3d42009-04-24 18:04:07 +00001441 if (qemu_reset_requested()) {
1442 pause_all_vcpus();
aliguori43b96852009-04-24 18:03:33 +00001443 qemu_system_reset();
aliguorid6dc3d42009-04-24 18:04:07 +00001444 resume_all_vcpus();
1445 }
Blue Swirld9c32312009-08-09 08:42:19 +00001446 if (qemu_powerdown_requested()) {
Blue Swirl242cd002009-12-04 18:05:45 +00001447 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
Blue Swirld9c32312009-08-09 08:42:19 +00001448 qemu_irq_raise(qemu_system_powerdown);
1449 }
Luiz Capitulinob1a15e72009-11-26 22:59:04 -02001450 if ((r = qemu_vmstop_requested())) {
aliguori6e29f5d2009-04-24 18:04:02 +00001451 vm_stop(r);
Luiz Capitulinob1a15e72009-11-26 22:59:04 -02001452 }
aliguori43b96852009-04-24 18:03:33 +00001453 }
MORITA Kazutaka2bc93fe2010-05-28 11:44:57 +09001454 bdrv_close_all();
aliguorid6dc3d42009-04-24 18:04:07 +00001455 pause_all_vcpus();
bellardb4608c02003-06-27 17:34:32 +00001456}
1457
pbrook9bd7e6d2009-04-07 22:58:45 +00001458static void version(void)
1459{
Thomas Monjalonf75ca1a2010-04-28 14:42:01 +02001460 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
pbrook9bd7e6d2009-04-07 22:58:45 +00001461}
1462
ths15f82202007-06-29 23:26:08 +00001463static void help(int exitcode)
bellard0824d6f2003-06-24 13:42:40 +00001464{
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001465 const char *options_help =
Blue Swirlad960902010-03-29 19:23:52 +00001466#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1467 opt_help
blueswir15824d652009-03-28 06:44:27 +00001468#define DEFHEADING(text) stringify(text) "\n"
Jes Sorensen9f167322010-06-10 11:42:24 +02001469#include "qemu-options.def"
blueswir15824d652009-03-28 06:44:27 +00001470#undef DEF
1471#undef DEFHEADING
1472#undef GEN_DOCS
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001473 ;
1474 version();
1475 printf("usage: %s [options] [disk_image]\n"
malc3f020d72010-02-08 12:04:56 +03001476 "\n"
Thomas Monjalonf75ca1a2010-04-28 14:42:01 +02001477 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001478 "\n"
1479 "%s\n"
malc3f020d72010-02-08 12:04:56 +03001480 "During emulation, the following keys are useful:\n"
1481 "ctrl-alt-f toggle full screen\n"
1482 "ctrl-alt-n switch to virtual console 'n'\n"
1483 "ctrl-alt toggle mouse and keyboard grab\n"
1484 "\n"
Paolo Bonzinie8105eb2010-02-04 16:49:59 +01001485 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1486 "qemu",
1487 options_help);
ths15f82202007-06-29 23:26:08 +00001488 exit(exitcode);
bellard0824d6f2003-06-24 13:42:40 +00001489}
1490
bellardcd6f1162004-05-13 22:02:20 +00001491#define HAS_ARG 0x0001
1492
bellardcd6f1162004-05-13 22:02:20 +00001493typedef struct QEMUOption {
1494 const char *name;
1495 int flags;
1496 int index;
Blue Swirlad960902010-03-29 19:23:52 +00001497 uint32_t arch_mask;
bellardcd6f1162004-05-13 22:02:20 +00001498} QEMUOption;
1499
blueswir1dbed7e42008-10-01 19:38:09 +00001500static const QEMUOption qemu_options[] = {
Blue Swirlad960902010-03-29 19:23:52 +00001501 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1502#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1503 { option, opt_arg, opt_enum, arch_mask },
blueswir15824d652009-03-28 06:44:27 +00001504#define DEFHEADING(text)
Jes Sorensen9f167322010-06-10 11:42:24 +02001505#include "qemu-options.def"
blueswir15824d652009-03-28 06:44:27 +00001506#undef DEF
1507#undef DEFHEADING
1508#undef GEN_DOCS
bellardcd6f1162004-05-13 22:02:20 +00001509 { NULL },
bellardfc01f7e2003-06-30 10:03:06 +00001510};
malc3893c122008-09-28 00:42:05 +00001511static void select_vgahw (const char *p)
1512{
1513 const char *opts;
1514
Gerd Hoffmann64465292009-12-08 13:11:45 +01001515 default_vga = 0;
Zachary Amsden86176752009-07-30 00:15:02 -10001516 vga_interface_type = VGA_NONE;
malc3893c122008-09-28 00:42:05 +00001517 if (strstart(p, "std", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001518 vga_interface_type = VGA_STD;
malc3893c122008-09-28 00:42:05 +00001519 } else if (strstart(p, "cirrus", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001520 vga_interface_type = VGA_CIRRUS;
malc3893c122008-09-28 00:42:05 +00001521 } else if (strstart(p, "vmware", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001522 vga_interface_type = VGA_VMWARE;
aliguori94909d92009-04-22 15:19:53 +00001523 } else if (strstart(p, "xenfb", &opts)) {
Zachary Amsden86176752009-07-30 00:15:02 -10001524 vga_interface_type = VGA_XENFB;
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +02001525 } else if (strstart(p, "qxl", &opts)) {
1526 vga_interface_type = VGA_QXL;
aliguori28b85ed2009-04-22 15:19:48 +00001527 } else if (!strstart(p, "none", &opts)) {
malc3893c122008-09-28 00:42:05 +00001528 invalid_vga:
1529 fprintf(stderr, "Unknown vga type: %s\n", p);
1530 exit(1);
1531 }
malccb5a7aa2008-09-28 00:42:12 +00001532 while (*opts) {
1533 const char *nextopt;
1534
1535 if (strstart(opts, ",retrace=", &nextopt)) {
1536 opts = nextopt;
1537 if (strstart(opts, "dumb", &nextopt))
1538 vga_retrace_method = VGA_RETRACE_DUMB;
1539 else if (strstart(opts, "precise", &nextopt))
1540 vga_retrace_method = VGA_RETRACE_PRECISE;
1541 else goto invalid_vga;
1542 } else goto invalid_vga;
1543 opts = nextopt;
1544 }
malc3893c122008-09-28 00:42:05 +00001545}
1546
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001547static int balloon_parse(const char *arg)
1548{
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001549 QemuOpts *opts;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001550
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001551 if (strcmp(arg, "none") == 0) {
1552 return 0;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001553 }
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001554
1555 if (!strncmp(arg, "virtio", 6)) {
1556 if (arg[6] == ',') {
1557 /* have params -> parse them */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001558 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001559 if (!opts)
1560 return -1;
1561 } else {
1562 /* create empty opts */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001563 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
Gerd Hoffmann382f0742009-08-14 10:34:22 +02001564 }
1565 qemu_opt_set(opts, "driver", "virtio-balloon-pci");
1566 return 0;
1567 }
1568
1569 return -1;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001570}
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02001571
Paul Brook5cea8592009-05-30 00:52:44 +01001572char *qemu_find_file(int type, const char *name)
1573{
1574 int len;
1575 const char *subdir;
1576 char *buf;
1577
1578 /* If name contains path separators then try it as a straight path. */
1579 if ((strchr(name, '/') || strchr(name, '\\'))
1580 && access(name, R_OK) == 0) {
Jean-Christophe DUBOIS73ffc802009-09-02 23:59:06 +02001581 return qemu_strdup(name);
Paul Brook5cea8592009-05-30 00:52:44 +01001582 }
1583 switch (type) {
1584 case QEMU_FILE_TYPE_BIOS:
1585 subdir = "";
1586 break;
1587 case QEMU_FILE_TYPE_KEYMAP:
1588 subdir = "keymaps/";
1589 break;
1590 default:
1591 abort();
1592 }
1593 len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
1594 buf = qemu_mallocz(len);
Blue Swirl3a417592009-06-09 19:12:21 +00001595 snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
Paul Brook5cea8592009-05-30 00:52:44 +01001596 if (access(buf, R_OK)) {
1597 qemu_free(buf);
1598 return NULL;
1599 }
1600 return buf;
1601}
1602
Markus Armbrusterff952ba2010-01-29 19:48:57 +01001603static int device_help_func(QemuOpts *opts, void *opaque)
1604{
1605 return qdev_device_help(opts);
1606}
1607
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02001608static int device_init_func(QemuOpts *opts, void *opaque)
1609{
1610 DeviceState *dev;
1611
1612 dev = qdev_device_add(opts);
1613 if (!dev)
1614 return -1;
1615 return 0;
1616}
1617
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01001618static int chardev_init_func(QemuOpts *opts, void *opaque)
1619{
1620 CharDriverState *chr;
1621
1622 chr = qemu_chr_open_opts(opts, NULL);
1623 if (!chr)
1624 return -1;
1625 return 0;
1626}
1627
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07001628#ifdef CONFIG_VIRTFS
Gautham R Shenoy74db9202010-04-29 17:44:43 +05301629static int fsdev_init_func(QemuOpts *opts, void *opaque)
1630{
1631 int ret;
1632 ret = qemu_fsdev_add(opts);
1633
1634 return ret;
1635}
1636#endif
1637
Gerd Hoffmann88589342009-12-08 13:11:50 +01001638static int mon_init_func(QemuOpts *opts, void *opaque)
1639{
1640 CharDriverState *chr;
1641 const char *chardev;
1642 const char *mode;
1643 int flags;
1644
1645 mode = qemu_opt_get(opts, "mode");
1646 if (mode == NULL) {
1647 mode = "readline";
1648 }
1649 if (strcmp(mode, "readline") == 0) {
1650 flags = MONITOR_USE_READLINE;
1651 } else if (strcmp(mode, "control") == 0) {
1652 flags = MONITOR_USE_CONTROL;
1653 } else {
1654 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
1655 exit(1);
1656 }
1657
Daniel P. Berrange39eaab92010-06-07 15:42:31 +01001658 if (qemu_opt_get_bool(opts, "pretty", 0))
1659 flags |= MONITOR_USE_PRETTY;
1660
Gerd Hoffmann88589342009-12-08 13:11:50 +01001661 if (qemu_opt_get_bool(opts, "default", 0))
1662 flags |= MONITOR_IS_DEFAULT;
1663
1664 chardev = qemu_opt_get(opts, "chardev");
1665 chr = qemu_chr_find(chardev);
1666 if (chr == NULL) {
1667 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
1668 exit(1);
1669 }
1670
1671 monitor_init(chr, flags);
1672 return 0;
1673}
1674
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01001675static void monitor_parse(const char *optarg, const char *mode)
Gerd Hoffmann88589342009-12-08 13:11:50 +01001676{
1677 static int monitor_device_index = 0;
1678 QemuOpts *opts;
1679 const char *p;
1680 char label[32];
1681 int def = 0;
1682
1683 if (strstart(optarg, "chardev:", &p)) {
1684 snprintf(label, sizeof(label), "%s", p);
1685 } else {
Jan Kiszka140e0652010-04-06 16:55:52 +02001686 snprintf(label, sizeof(label), "compat_monitor%d",
1687 monitor_device_index);
1688 if (monitor_device_index == 0) {
Gerd Hoffmann88589342009-12-08 13:11:50 +01001689 def = 1;
1690 }
1691 opts = qemu_chr_parse_compat(label, optarg);
1692 if (!opts) {
1693 fprintf(stderr, "parse error: %s\n", optarg);
1694 exit(1);
1695 }
1696 }
1697
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001698 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1);
Gerd Hoffmann88589342009-12-08 13:11:50 +01001699 if (!opts) {
1700 fprintf(stderr, "duplicate chardev: %s\n", label);
1701 exit(1);
1702 }
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01001703 qemu_opt_set(opts, "mode", mode);
Gerd Hoffmann88589342009-12-08 13:11:50 +01001704 qemu_opt_set(opts, "chardev", label);
1705 if (def)
1706 qemu_opt_set(opts, "default", "on");
1707 monitor_device_index++;
1708}
1709
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001710struct device_config {
1711 enum {
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001712 DEV_USB, /* -usbdevice */
1713 DEV_BT, /* -bt */
1714 DEV_SERIAL, /* -serial */
1715 DEV_PARALLEL, /* -parallel */
1716 DEV_VIRTCON, /* -virtioconsole */
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001717 DEV_DEBUGCON, /* -debugcon */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001718 } type;
1719 const char *cmdline;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001720 QTAILQ_ENTRY(device_config) next;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001721};
Blue Swirl72cf2d42009-09-12 07:36:22 +00001722QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001723
1724static void add_device_config(int type, const char *cmdline)
1725{
1726 struct device_config *conf;
1727
1728 conf = qemu_mallocz(sizeof(*conf));
1729 conf->type = type;
1730 conf->cmdline = cmdline;
Blue Swirl72cf2d42009-09-12 07:36:22 +00001731 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001732}
1733
1734static int foreach_device_config(int type, int (*func)(const char *cmdline))
1735{
1736 struct device_config *conf;
1737 int rc;
1738
Blue Swirl72cf2d42009-09-12 07:36:22 +00001739 QTAILQ_FOREACH(conf, &device_configs, next) {
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02001740 if (conf->type != type)
1741 continue;
1742 rc = func(conf->cmdline);
1743 if (0 != rc)
1744 return rc;
1745 }
1746 return 0;
1747}
1748
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01001749static int serial_parse(const char *devname)
1750{
1751 static int index = 0;
1752 char label[32];
1753
1754 if (strcmp(devname, "none") == 0)
1755 return 0;
1756 if (index == MAX_SERIAL_PORTS) {
1757 fprintf(stderr, "qemu: too many serial ports\n");
1758 exit(1);
1759 }
1760 snprintf(label, sizeof(label), "serial%d", index);
1761 serial_hds[index] = qemu_chr_open(label, devname, NULL);
1762 if (!serial_hds[index]) {
1763 fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
1764 devname, strerror(errno));
1765 return -1;
1766 }
1767 index++;
1768 return 0;
1769}
1770
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01001771static int parallel_parse(const char *devname)
1772{
1773 static int index = 0;
1774 char label[32];
1775
1776 if (strcmp(devname, "none") == 0)
1777 return 0;
1778 if (index == MAX_PARALLEL_PORTS) {
1779 fprintf(stderr, "qemu: too many parallel ports\n");
1780 exit(1);
1781 }
1782 snprintf(label, sizeof(label), "parallel%d", index);
1783 parallel_hds[index] = qemu_chr_open(label, devname, NULL);
1784 if (!parallel_hds[index]) {
1785 fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
1786 devname, strerror(errno));
1787 return -1;
1788 }
1789 index++;
1790 return 0;
1791}
1792
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001793static int virtcon_parse(const char *devname)
1794{
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001795 QemuOptsList *device = qemu_find_opts("device");
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001796 static int index = 0;
1797 char label[32];
Amit Shah392ecf52010-01-21 16:19:23 +05301798 QemuOpts *bus_opts, *dev_opts;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001799
1800 if (strcmp(devname, "none") == 0)
1801 return 0;
1802 if (index == MAX_VIRTIO_CONSOLES) {
1803 fprintf(stderr, "qemu: too many virtio consoles\n");
1804 exit(1);
1805 }
Amit Shah392ecf52010-01-21 16:19:23 +05301806
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001807 bus_opts = qemu_opts_create(device, NULL, 0);
Amit Shah392ecf52010-01-21 16:19:23 +05301808 qemu_opt_set(bus_opts, "driver", "virtio-serial");
1809
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001810 dev_opts = qemu_opts_create(device, NULL, 0);
Amit Shah392ecf52010-01-21 16:19:23 +05301811 qemu_opt_set(dev_opts, "driver", "virtconsole");
1812
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001813 snprintf(label, sizeof(label), "virtcon%d", index);
1814 virtcon_hds[index] = qemu_chr_open(label, devname, NULL);
1815 if (!virtcon_hds[index]) {
1816 fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
1817 devname, strerror(errno));
1818 return -1;
1819 }
Amit Shah392ecf52010-01-21 16:19:23 +05301820 qemu_opt_set(dev_opts, "chardev", label);
1821
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01001822 index++;
1823 return 0;
1824}
1825
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001826static int debugcon_parse(const char *devname)
1827{
1828 QemuOpts *opts;
1829
1830 if (!qemu_chr_open("debugcon", devname, NULL)) {
1831 exit(1);
1832 }
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001833 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08001834 if (!opts) {
1835 fprintf(stderr, "qemu: already have a debugcon device\n");
1836 exit(1);
1837 }
1838 qemu_opt_set(opts, "driver", "isa-debugcon");
1839 qemu_opt_set(opts, "chardev", "debugcon");
1840 return 0;
1841}
1842
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02001843void qemu_add_exit_notifier(Notifier *notify)
1844{
1845 notifier_list_add(&exit_notifiers, notify);
1846}
1847
1848void qemu_remove_exit_notifier(Notifier *notify)
1849{
1850 notifier_list_remove(&exit_notifiers, notify);
1851}
1852
1853static void qemu_run_exit_notifiers(void)
1854{
1855 notifier_list_notify(&exit_notifiers);
1856}
1857
Gleb Natapov4cab9462010-12-08 13:35:08 +02001858void qemu_add_machine_init_done_notifier(Notifier *notify)
1859{
1860 notifier_list_add(&machine_init_done_notifiers, notify);
1861}
1862
1863static void qemu_run_machine_init_done_notifiers(void)
1864{
1865 notifier_list_notify(&machine_init_done_notifiers);
1866}
1867
Anthony Liguori6530a972010-01-22 09:18:06 -06001868static const QEMUOption *lookup_opt(int argc, char **argv,
1869 const char **poptarg, int *poptind)
1870{
1871 const QEMUOption *popt;
1872 int optind = *poptind;
1873 char *r = argv[optind];
1874 const char *optarg;
1875
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001876 loc_set_cmdline(argv, optind, 1);
Anthony Liguori6530a972010-01-22 09:18:06 -06001877 optind++;
1878 /* Treat --foo the same as -foo. */
1879 if (r[1] == '-')
1880 r++;
1881 popt = qemu_options;
1882 for(;;) {
1883 if (!popt->name) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001884 error_report("invalid option");
Anthony Liguori6530a972010-01-22 09:18:06 -06001885 exit(1);
1886 }
1887 if (!strcmp(popt->name, r + 1))
1888 break;
1889 popt++;
1890 }
1891 if (popt->flags & HAS_ARG) {
1892 if (optind >= argc) {
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001893 error_report("requires an argument");
Anthony Liguori6530a972010-01-22 09:18:06 -06001894 exit(1);
1895 }
1896 optarg = argv[optind++];
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01001897 loc_set_cmdline(argv, optind - 2, 2);
Anthony Liguori6530a972010-01-22 09:18:06 -06001898 } else {
1899 optarg = NULL;
1900 }
1901
1902 *poptarg = optarg;
1903 *poptind = optind;
1904
1905 return popt;
1906}
1907
malc902b3d52008-12-10 19:18:40 +00001908int main(int argc, char **argv, char **envp)
bellard0824d6f2003-06-24 13:42:40 +00001909{
aliguori59030a82009-04-05 18:43:41 +00001910 const char *gdbstub_dev = NULL;
thse4bcb142007-12-02 04:51:10 +00001911 int i;
Eduardo Habkostda1fcfd2010-04-06 19:22:07 -03001912 int snapshot, linux_boot;
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01001913 const char *icount_option = NULL;
bellard7f7f9872003-10-30 01:11:23 +00001914 const char *initrd_filename;
bellarda20dd502003-09-30 21:07:02 +00001915 const char *kernel_filename, *kernel_cmdline;
Anthony Liguori195325a2009-10-30 12:42:29 -05001916 char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
aliguori3023f3322009-01-16 19:04:14 +00001917 DisplayState *ds;
aliguori7d957bd2009-01-15 22:14:11 +00001918 DisplayChangeListener *dcl;
bellard46d47672004-11-16 01:45:27 +00001919 int cyls, heads, secs, translation;
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02001920 QemuOpts *hda_opts = NULL, *opts;
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02001921 QemuOptsList *olist;
bellardcd6f1162004-05-13 22:02:20 +00001922 int optind;
Anthony Liguori6530a972010-01-22 09:18:06 -06001923 const char *optarg;
bellardd63d3072004-10-03 13:29:03 +00001924 const char *loadvm = NULL;
bellardcc1daa42005-06-05 14:49:17 +00001925 QEMUMachine *machine;
j_mayer94fc95c2007-03-05 19:44:02 +00001926 const char *cpu_model;
bellard26a5f132008-05-28 12:30:31 +00001927 int tb_size;
ths93815bc2007-03-19 15:58:31 +00001928 const char *pid_file = NULL;
aliguori5bb79102008-10-13 03:12:02 +00001929 const char *incoming = NULL;
Anthony Liguori993fbfd2009-05-21 16:54:00 -05001930 int show_vnc_port = 0;
Anthony Liguori292444c2010-01-21 10:57:58 -06001931 int defconfig = 1;
bellard0bd48852005-11-11 00:00:47 +00001932
Prerna Saxenaab6540d2010-08-09 11:48:32 +01001933#ifdef CONFIG_SIMPLE_TRACE
1934 const char *trace_file = NULL;
1935#endif
Gerd Hoffmannfd42dee2010-06-04 14:08:07 +02001936 atexit(qemu_run_exit_notifiers);
Markus Armbruster65abca02010-02-24 14:37:14 +01001937 error_set_progname(argv[0]);
1938
Jan Kiszka68752042009-09-15 13:36:04 +02001939 init_clocks();
1940
malc902b3d52008-12-10 19:18:40 +00001941 qemu_cache_utils_init(envp);
1942
Blue Swirl72cf2d42009-09-12 07:36:22 +00001943 QLIST_INIT (&vm_change_state_head);
Jes Sorensenfe98ac12010-06-10 11:42:21 +02001944 os_setup_early_signal_handling();
bellardbe995c22006-06-25 16:25:21 +00001945
Anthony Liguorif80f9ec2009-05-20 18:38:09 -05001946 module_call_init(MODULE_INIT_MACHINE);
Anthony Liguori0c257432009-05-21 20:41:01 -05001947 machine = find_default_machine();
j_mayer94fc95c2007-03-05 19:44:02 +00001948 cpu_model = NULL;
bellardfc01f7e2003-06-30 10:03:06 +00001949 initrd_filename = NULL;
aurel324fc5d072008-04-27 21:39:40 +00001950 ram_size = 0;
bellard33e39632003-07-06 17:15:21 +00001951 snapshot = 0;
bellarda20dd502003-09-30 21:07:02 +00001952 kernel_filename = NULL;
1953 kernel_cmdline = "";
bellardc4b1fcc2004-03-14 21:44:30 +00001954 cyls = heads = secs = 0;
bellard46d47672004-11-16 01:45:27 +00001955 translation = BIOS_ATA_TRANSLATION_AUTO;
bellardc4b1fcc2004-03-14 21:44:30 +00001956
aliguori268a3622009-04-21 22:30:27 +00001957 for (i = 0; i < MAX_NODES; i++) {
1958 node_mem[i] = 0;
1959 node_cpumask[i] = 0;
1960 }
1961
aliguori268a3622009-04-21 22:30:27 +00001962 nb_numa_nodes = 0;
bellard7c9d8e02005-11-15 22:16:05 +00001963 nb_nics = 0;
ths3b46e622007-09-17 08:09:54 +00001964
bellard26a5f132008-05-28 12:30:31 +00001965 tb_size = 0;
blueswir141bd6392008-10-05 09:56:21 +00001966 autostart= 1;
1967
Anthony Liguori292444c2010-01-21 10:57:58 -06001968 /* first pass of option parsing */
1969 optind = 1;
1970 while (optind < argc) {
1971 if (argv[optind][0] != '-') {
1972 /* disk image */
Anthony Liguori28e68d62010-01-27 10:46:00 -06001973 optind++;
Anthony Liguori292444c2010-01-21 10:57:58 -06001974 continue;
1975 } else {
1976 const QEMUOption *popt;
1977
1978 popt = lookup_opt(argc, argv, &optarg, &optind);
1979 switch (popt->index) {
1980 case QEMU_OPTION_nodefconfig:
1981 defconfig=0;
1982 break;
1983 }
1984 }
1985 }
1986
1987 if (defconfig) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01001988 int ret;
Markus Armbrustercf5a65a2010-02-18 19:48:33 +01001989
Kevin Wolfdcfb0932010-03-05 17:25:55 +01001990 ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
Kevin Wolf019e78b2010-05-17 10:36:47 +02001991 if (ret < 0 && ret != -ENOENT) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01001992 exit(1);
Anthony Liguori292444c2010-01-21 10:57:58 -06001993 }
1994
Kevin Wolfdcfb0932010-03-05 17:25:55 +01001995 ret = qemu_read_config_file(arch_config_name);
Kevin Wolf019e78b2010-05-17 10:36:47 +02001996 if (ret < 0 && ret != -ENOENT) {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01001997 exit(1);
Anthony Liguori292444c2010-01-21 10:57:58 -06001998 }
1999 }
Blue Swirlde06f8d2010-03-29 19:23:50 +00002000 cpudef_init();
Anthony Liguori292444c2010-01-21 10:57:58 -06002001
2002 /* second pass of option parsing */
bellardcd6f1162004-05-13 22:02:20 +00002003 optind = 1;
bellard0824d6f2003-06-24 13:42:40 +00002004 for(;;) {
bellardcd6f1162004-05-13 22:02:20 +00002005 if (optind >= argc)
bellard0824d6f2003-06-24 13:42:40 +00002006 break;
Anthony Liguori6530a972010-01-22 09:18:06 -06002007 if (argv[optind][0] != '-') {
Markus Armbruster2292dda2011-01-28 11:21:41 +01002008 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
bellardcd6f1162004-05-13 22:02:20 +00002009 } else {
2010 const QEMUOption *popt;
2011
Anthony Liguori6530a972010-01-22 09:18:06 -06002012 popt = lookup_opt(argc, argv, &optarg, &optind);
Blue Swirlad960902010-03-29 19:23:52 +00002013 if (!(popt->arch_mask & arch_type)) {
2014 printf("Option %s not supported for this target\n", popt->name);
2015 exit(1);
2016 }
bellardcd6f1162004-05-13 22:02:20 +00002017 switch(popt->index) {
bellardcc1daa42005-06-05 14:49:17 +00002018 case QEMU_OPTION_M:
2019 machine = find_machine(optarg);
2020 if (!machine) {
2021 QEMUMachine *m;
2022 printf("Supported machines are:\n");
2023 for(m = first_machine; m != NULL; m = m->next) {
Mark McLoughlin3f6599e2009-07-22 10:02:50 +01002024 if (m->alias)
2025 printf("%-10s %s (alias of %s)\n",
2026 m->alias, m->desc, m->name);
bellardcc1daa42005-06-05 14:49:17 +00002027 printf("%-10s %s%s\n",
ths5fafdf22007-09-16 21:08:06 +00002028 m->name, m->desc,
Anthony Liguori0c257432009-05-21 20:41:01 -05002029 m->is_default ? " (default)" : "");
bellardcc1daa42005-06-05 14:49:17 +00002030 }
ths15f82202007-06-29 23:26:08 +00002031 exit(*optarg != '?');
bellardcc1daa42005-06-05 14:49:17 +00002032 }
2033 break;
j_mayer94fc95c2007-03-05 19:44:02 +00002034 case QEMU_OPTION_cpu:
2035 /* hw initialization will check this */
ths15f82202007-06-29 23:26:08 +00002036 if (*optarg == '?') {
Blue Swirl262353c2010-05-04 19:55:35 +00002037 list_cpus(stdout, &fprintf, optarg);
ths15f82202007-06-29 23:26:08 +00002038 exit(0);
j_mayer94fc95c2007-03-05 19:44:02 +00002039 } else {
2040 cpu_model = optarg;
2041 }
2042 break;
bellardcd6f1162004-05-13 22:02:20 +00002043 case QEMU_OPTION_initrd:
bellardfc01f7e2003-06-30 10:03:06 +00002044 initrd_filename = optarg;
2045 break;
bellardcd6f1162004-05-13 22:02:20 +00002046 case QEMU_OPTION_hda:
Markus Armbruster5645b0f2011-01-31 11:50:09 +01002047 {
2048 char buf[256];
2049 if (cyls == 0)
2050 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2051 else
2052 snprintf(buf, sizeof(buf),
2053 "%s,cyls=%d,heads=%d,secs=%d%s",
2054 HD_OPTS , cyls, heads, secs,
2055 translation == BIOS_ATA_TRANSLATION_LBA ?
thse4bcb142007-12-02 04:51:10 +00002056 ",trans=lba" :
Markus Armbruster5645b0f2011-01-31 11:50:09 +01002057 translation == BIOS_ATA_TRANSLATION_NONE ?
thse4bcb142007-12-02 04:51:10 +00002058 ",trans=none" : "");
Markus Armbruster5645b0f2011-01-31 11:50:09 +01002059 drive_add(IF_DEFAULT, 0, optarg, buf);
2060 break;
2061 }
bellardcd6f1162004-05-13 22:02:20 +00002062 case QEMU_OPTION_hdb:
bellardcc1daa42005-06-05 14:49:17 +00002063 case QEMU_OPTION_hdc:
2064 case QEMU_OPTION_hdd:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002065 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2066 HD_OPTS);
bellardfc01f7e2003-06-30 10:03:06 +00002067 break;
thse4bcb142007-12-02 04:51:10 +00002068 case QEMU_OPTION_drive:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002069 drive_def(optarg);
thse4bcb142007-12-02 04:51:10 +00002070 break;
Gerd Hoffmannd058fe02009-07-31 12:25:36 +02002071 case QEMU_OPTION_set:
2072 if (qemu_set_option(optarg) != 0)
2073 exit(1);
2074 break;
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01002075 case QEMU_OPTION_global:
2076 if (qemu_global_option(optarg) != 0)
2077 exit(1);
2078 break;
balrog3e3d5812007-04-30 02:09:25 +00002079 case QEMU_OPTION_mtdblock:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002080 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
balrog3e3d5812007-04-30 02:09:25 +00002081 break;
pbrooka1bb27b2007-04-06 16:49:48 +00002082 case QEMU_OPTION_sd:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002083 drive_add(IF_SD, 0, optarg, SD_OPTS);
pbrooka1bb27b2007-04-06 16:49:48 +00002084 break;
j_mayer86f55662007-04-24 06:52:59 +00002085 case QEMU_OPTION_pflash:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002086 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
j_mayer86f55662007-04-24 06:52:59 +00002087 break;
bellardcd6f1162004-05-13 22:02:20 +00002088 case QEMU_OPTION_snapshot:
bellard33e39632003-07-06 17:15:21 +00002089 snapshot = 1;
2090 break;
bellardcd6f1162004-05-13 22:02:20 +00002091 case QEMU_OPTION_hdachs:
bellard330d0412003-07-26 18:11:40 +00002092 {
bellard330d0412003-07-26 18:11:40 +00002093 const char *p;
2094 p = optarg;
2095 cyls = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002096 if (cyls < 1 || cyls > 16383)
2097 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00002098 if (*p != ',')
2099 goto chs_fail;
2100 p++;
2101 heads = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002102 if (heads < 1 || heads > 16)
2103 goto chs_fail;
bellard330d0412003-07-26 18:11:40 +00002104 if (*p != ',')
2105 goto chs_fail;
2106 p++;
2107 secs = strtol(p, (char **)&p, 0);
bellard46d47672004-11-16 01:45:27 +00002108 if (secs < 1 || secs > 63)
2109 goto chs_fail;
2110 if (*p == ',') {
2111 p++;
2112 if (!strcmp(p, "none"))
2113 translation = BIOS_ATA_TRANSLATION_NONE;
2114 else if (!strcmp(p, "lba"))
2115 translation = BIOS_ATA_TRANSLATION_LBA;
2116 else if (!strcmp(p, "auto"))
2117 translation = BIOS_ATA_TRANSLATION_AUTO;
2118 else
2119 goto chs_fail;
2120 } else if (*p != '\0') {
bellardc4b1fcc2004-03-14 21:44:30 +00002121 chs_fail:
bellard46d47672004-11-16 01:45:27 +00002122 fprintf(stderr, "qemu: invalid physical CHS format\n");
2123 exit(1);
bellardc4b1fcc2004-03-14 21:44:30 +00002124 }
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02002125 if (hda_opts != NULL) {
2126 char num[16];
2127 snprintf(num, sizeof(num), "%d", cyls);
2128 qemu_opt_set(hda_opts, "cyls", num);
2129 snprintf(num, sizeof(num), "%d", heads);
2130 qemu_opt_set(hda_opts, "heads", num);
2131 snprintf(num, sizeof(num), "%d", secs);
2132 qemu_opt_set(hda_opts, "secs", num);
2133 if (translation == BIOS_ATA_TRANSLATION_LBA)
2134 qemu_opt_set(hda_opts, "trans", "lba");
2135 if (translation == BIOS_ATA_TRANSLATION_NONE)
2136 qemu_opt_set(hda_opts, "trans", "none");
2137 }
bellard330d0412003-07-26 18:11:40 +00002138 }
2139 break;
aliguori268a3622009-04-21 22:30:27 +00002140 case QEMU_OPTION_numa:
2141 if (nb_numa_nodes >= MAX_NODES) {
2142 fprintf(stderr, "qemu: too many NUMA nodes\n");
2143 exit(1);
2144 }
2145 numa_add(optarg);
2146 break;
bellardcd6f1162004-05-13 22:02:20 +00002147 case QEMU_OPTION_nographic:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002148 display_type = DT_NOGRAPHIC;
bellarda20dd502003-09-30 21:07:02 +00002149 break;
balrog4d3b6f62008-02-10 16:33:14 +00002150#ifdef CONFIG_CURSES
2151 case QEMU_OPTION_curses:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002152 display_type = DT_CURSES;
balrog4d3b6f62008-02-10 16:33:14 +00002153 break;
2154#endif
balroga171fe32007-04-30 01:48:07 +00002155 case QEMU_OPTION_portrait:
2156 graphic_rotate = 1;
2157 break;
bellardcd6f1162004-05-13 22:02:20 +00002158 case QEMU_OPTION_kernel:
bellarda20dd502003-09-30 21:07:02 +00002159 kernel_filename = optarg;
2160 break;
bellardcd6f1162004-05-13 22:02:20 +00002161 case QEMU_OPTION_append:
bellarda20dd502003-09-30 21:07:02 +00002162 kernel_cmdline = optarg;
bellard313aa562003-08-10 21:52:11 +00002163 break;
bellardcd6f1162004-05-13 22:02:20 +00002164 case QEMU_OPTION_cdrom:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002165 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
bellard36b486b2003-11-11 13:36:08 +00002166 break;
bellardcd6f1162004-05-13 22:02:20 +00002167 case QEMU_OPTION_boot:
j_mayer28c5af52007-11-11 01:50:45 +00002168 {
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002169 static const char * const params[] = {
Jan Kiszka95387492009-07-02 00:19:02 +02002170 "order", "once", "menu", NULL
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002171 };
2172 char buf[sizeof(boot_devices)];
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002173 char *standard_boot_devices;
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002174 int legacy = 0;
2175
2176 if (!strchr(optarg, '=')) {
2177 legacy = 1;
2178 pstrcpy(buf, sizeof(buf), optarg);
2179 } else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
2180 fprintf(stderr,
2181 "qemu: unknown boot parameter '%s' in '%s'\n",
2182 buf, optarg);
2183 exit(1);
2184 }
2185
2186 if (legacy ||
2187 get_param_value(buf, sizeof(buf), "order", optarg)) {
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -03002188 validate_bootdevices(buf);
Jan Kiszkaef3adf62009-07-02 00:19:02 +02002189 pstrcpy(boot_devices, sizeof(boot_devices), buf);
j_mayer28c5af52007-11-11 01:50:45 +00002190 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002191 if (!legacy) {
2192 if (get_param_value(buf, sizeof(buf),
2193 "once", optarg)) {
Eduardo Habkost4e9e9d62010-04-06 19:22:08 -03002194 validate_bootdevices(buf);
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002195 standard_boot_devices = qemu_strdup(boot_devices);
2196 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2197 qemu_register_reset(restore_boot_devices,
2198 standard_boot_devices);
2199 }
Jan Kiszka95387492009-07-02 00:19:02 +02002200 if (get_param_value(buf, sizeof(buf),
2201 "menu", optarg)) {
2202 if (!strcmp(buf, "on")) {
2203 boot_menu = 1;
2204 } else if (!strcmp(buf, "off")) {
2205 boot_menu = 0;
2206 } else {
2207 fprintf(stderr,
2208 "qemu: invalid option value '%s'\n",
2209 buf);
2210 exit(1);
2211 }
2212 }
Jan Kiszkae0f084b2009-07-02 00:19:02 +02002213 }
bellard36b486b2003-11-11 13:36:08 +00002214 }
2215 break;
bellardcd6f1162004-05-13 22:02:20 +00002216 case QEMU_OPTION_fda:
bellardcd6f1162004-05-13 22:02:20 +00002217 case QEMU_OPTION_fdb:
Markus Armbruster2292dda2011-01-28 11:21:41 +01002218 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2219 optarg, FD_OPTS);
bellardc45886d2004-01-05 00:02:06 +00002220 break;
bellard52ca8d62006-06-14 16:03:05 +00002221 case QEMU_OPTION_no_fd_bootchk:
2222 fd_bootchk = 0;
2223 break;
Mark McLoughlina1ea4582009-10-08 19:58:26 +01002224 case QEMU_OPTION_netdev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002225 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
Mark McLoughlina1ea4582009-10-08 19:58:26 +01002226 exit(1);
2227 }
2228 break;
bellard7c9d8e02005-11-15 22:16:05 +00002229 case QEMU_OPTION_net:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002230 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
bellardc4b1fcc2004-03-14 21:44:30 +00002231 exit(1);
2232 }
bellard702c6512004-04-02 21:21:32 +00002233 break;
bellardc7f74642004-08-24 21:57:12 +00002234#ifdef CONFIG_SLIRP
2235 case QEMU_OPTION_tftp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02002236 legacy_tftp_prefix = optarg;
bellard9bf05442004-08-25 22:12:49 +00002237 break;
ths47d5d012007-02-20 00:05:08 +00002238 case QEMU_OPTION_bootp:
Jan Kiszkaad196a92009-06-24 14:42:28 +02002239 legacy_bootp_filename = optarg;
ths47d5d012007-02-20 00:05:08 +00002240 break;
bellard9bf05442004-08-25 22:12:49 +00002241 case QEMU_OPTION_redir:
Markus Armbruster07527062009-10-06 12:16:57 +01002242 if (net_slirp_redir(optarg) < 0)
2243 exit(1);
bellard9bf05442004-08-25 22:12:49 +00002244 break;
bellardc7f74642004-08-24 21:57:12 +00002245#endif
balrogdc72ac12008-11-09 00:04:26 +00002246 case QEMU_OPTION_bt:
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002247 add_device_config(DEV_BT, optarg);
balrogdc72ac12008-11-09 00:04:26 +00002248 break;
bellard1d14ffa2005-10-30 18:58:22 +00002249 case QEMU_OPTION_audio_help:
Blue Swirlad960902010-03-29 19:23:52 +00002250 if (!(audio_available())) {
2251 printf("Option %s not supported for this target\n", popt->name);
2252 exit(1);
2253 }
bellard1d14ffa2005-10-30 18:58:22 +00002254 AUD_help ();
2255 exit (0);
2256 break;
2257 case QEMU_OPTION_soundhw:
Blue Swirlad960902010-03-29 19:23:52 +00002258 if (!(audio_available())) {
2259 printf("Option %s not supported for this target\n", popt->name);
2260 exit(1);
2261 }
bellard1d14ffa2005-10-30 18:58:22 +00002262 select_soundhw (optarg);
2263 break;
bellardcd6f1162004-05-13 22:02:20 +00002264 case QEMU_OPTION_h:
ths15f82202007-06-29 23:26:08 +00002265 help(0);
bellardcd6f1162004-05-13 22:02:20 +00002266 break;
pbrook9bd7e6d2009-04-07 22:58:45 +00002267 case QEMU_OPTION_version:
2268 version();
2269 exit(0);
2270 break;
aurel3200f82b82008-04-27 21:12:55 +00002271 case QEMU_OPTION_m: {
Jes Sorensen70b4f4b2011-01-05 11:41:02 +01002272 int64_t value;
aurel3200f82b82008-04-27 21:12:55 +00002273
Jes Sorensen9f9b17a2010-10-21 17:15:46 +02002274 value = strtosz(optarg, NULL);
2275 if (value < 0) {
aurel3200f82b82008-04-27 21:12:55 +00002276 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
bellardcd6f1162004-05-13 22:02:20 +00002277 exit(1);
2278 }
aurel3200f82b82008-04-27 21:12:55 +00002279
2280 /* On 32-bit hosts, QEMU is limited by virtual address space */
Anthony Liguori4a1418e2009-08-10 17:07:24 -05002281 if (value > (2047 << 20) && HOST_LONG_BITS == 32) {
aurel3200f82b82008-04-27 21:12:55 +00002282 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
2283 exit(1);
2284 }
Anthony Liguoric227f092009-10-01 16:12:16 -05002285 if (value != (uint64_t)(ram_addr_t)value) {
aurel3200f82b82008-04-27 21:12:55 +00002286 fprintf(stderr, "qemu: ram size too large\n");
2287 exit(1);
2288 }
2289 ram_size = value;
bellardcd6f1162004-05-13 22:02:20 +00002290 break;
aurel3200f82b82008-04-27 21:12:55 +00002291 }
Marcelo Tosattic9027602010-03-01 20:25:08 -03002292 case QEMU_OPTION_mempath:
2293 mem_path = optarg;
2294 break;
2295#ifdef MAP_POPULATE
2296 case QEMU_OPTION_mem_prealloc:
2297 mem_prealloc = 1;
2298 break;
2299#endif
bellardcd6f1162004-05-13 22:02:20 +00002300 case QEMU_OPTION_d:
Blue Swirlde06f8d2010-03-29 19:23:50 +00002301 set_cpu_log(optarg);
bellardcd6f1162004-05-13 22:02:20 +00002302 break;
bellardcd6f1162004-05-13 22:02:20 +00002303 case QEMU_OPTION_s:
aliguori59030a82009-04-05 18:43:41 +00002304 gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT;
bellardcd6f1162004-05-13 22:02:20 +00002305 break;
aliguori59030a82009-04-05 18:43:41 +00002306 case QEMU_OPTION_gdb:
2307 gdbstub_dev = optarg;
bellardcd6f1162004-05-13 22:02:20 +00002308 break;
bellardcd6f1162004-05-13 22:02:20 +00002309 case QEMU_OPTION_L:
Paul Brook5cea8592009-05-30 00:52:44 +01002310 data_dir = optarg;
bellardcd6f1162004-05-13 22:02:20 +00002311 break;
j_mayer1192dad2007-10-05 13:08:35 +00002312 case QEMU_OPTION_bios:
2313 bios_name = optarg;
2314 break;
aurel321b530a62009-04-05 20:08:59 +00002315 case QEMU_OPTION_singlestep:
2316 singlestep = 1;
2317 break;
bellardcd6f1162004-05-13 22:02:20 +00002318 case QEMU_OPTION_S:
pbrook3c07f8e2007-01-21 16:47:01 +00002319 autostart = 0;
bellardcd6f1162004-05-13 22:02:20 +00002320 break;
bellard3d11d0e2004-12-12 16:56:30 +00002321 case QEMU_OPTION_k:
2322 keyboard_layout = optarg;
2323 break;
bellardee22c2f2004-06-03 12:49:50 +00002324 case QEMU_OPTION_localtime:
2325 rtc_utc = 0;
2326 break;
malc3893c122008-09-28 00:42:05 +00002327 case QEMU_OPTION_vga:
2328 select_vgahw (optarg);
bellard1bfe8562004-07-08 21:17:50 +00002329 break;
bellarde9b137c2004-06-21 16:46:10 +00002330 case QEMU_OPTION_g:
2331 {
2332 const char *p;
2333 int w, h, depth;
2334 p = optarg;
2335 w = strtol(p, (char **)&p, 10);
2336 if (w <= 0) {
2337 graphic_error:
2338 fprintf(stderr, "qemu: invalid resolution or depth\n");
2339 exit(1);
2340 }
2341 if (*p != 'x')
2342 goto graphic_error;
2343 p++;
2344 h = strtol(p, (char **)&p, 10);
2345 if (h <= 0)
2346 goto graphic_error;
2347 if (*p == 'x') {
2348 p++;
2349 depth = strtol(p, (char **)&p, 10);
ths5fafdf22007-09-16 21:08:06 +00002350 if (depth != 8 && depth != 15 && depth != 16 &&
bellarde9b137c2004-06-21 16:46:10 +00002351 depth != 24 && depth != 32)
2352 goto graphic_error;
2353 } else if (*p == '\0') {
2354 depth = graphic_depth;
2355 } else {
2356 goto graphic_error;
2357 }
ths3b46e622007-09-17 08:09:54 +00002358
bellarde9b137c2004-06-21 16:46:10 +00002359 graphic_width = w;
2360 graphic_height = h;
2361 graphic_depth = depth;
2362 }
2363 break;
ths20d8a3e2007-02-18 17:04:49 +00002364 case QEMU_OPTION_echr:
2365 {
2366 char *r;
2367 term_escape_char = strtol(optarg, &r, 0);
2368 if (r == optarg)
2369 printf("Bad argument to echr\n");
2370 break;
2371 }
bellard82c643f2004-07-14 17:28:13 +00002372 case QEMU_OPTION_monitor:
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002373 monitor_parse(optarg, "readline");
2374 default_monitor = 0;
2375 break;
2376 case QEMU_OPTION_qmp:
2377 monitor_parse(optarg, "control");
Anthony Liguori2d114dc2010-03-21 14:14:38 -05002378 default_monitor = 0;
bellard82c643f2004-07-14 17:28:13 +00002379 break;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002380 case QEMU_OPTION_mon:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002381 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002382 if (!opts) {
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002383 exit(1);
2384 }
Anthony Liguori2d114dc2010-03-21 14:14:38 -05002385 default_monitor = 0;
Gerd Hoffmann22a0e042009-12-08 13:11:51 +01002386 break;
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002387 case QEMU_OPTION_chardev:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002388 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002389 if (!opts) {
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002390 exit(1);
2391 }
Gerd Hoffmann191bc012009-09-10 10:58:35 +02002392 break;
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302393 case QEMU_OPTION_fsdev:
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002394 olist = qemu_find_opts("fsdev");
2395 if (!olist) {
2396 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
2397 exit(1);
2398 }
2399 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302400 if (!opts) {
2401 fprintf(stderr, "parse error: %s\n", optarg);
2402 exit(1);
2403 }
2404 break;
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302405 case QEMU_OPTION_virtfs: {
2406 char *arg_fsdev = NULL;
2407 char *arg_9p = NULL;
2408 int len = 0;
2409
Gerd Hoffmann03b0ba72010-08-20 13:52:02 +02002410 olist = qemu_find_opts("virtfs");
2411 if (!olist) {
2412 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
2413 exit(1);
2414 }
2415 opts = qemu_opts_parse(olist, optarg, 1);
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302416 if (!opts) {
2417 fprintf(stderr, "parse error: %s\n", optarg);
2418 exit(1);
2419 }
2420
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07002421 if (qemu_opt_get(opts, "fstype") == NULL ||
2422 qemu_opt_get(opts, "mount_tag") == NULL ||
2423 qemu_opt_get(opts, "path") == NULL ||
2424 qemu_opt_get(opts, "security_model") == NULL) {
2425 fprintf(stderr, "Usage: -virtfs fstype,path=/share_path/,"
Aneesh Kumar K.V12848bf2010-09-02 11:09:07 +05302426 "security_model=[mapped|passthrough|none],"
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07002427 "mnt_tag=tag.\n");
2428 exit(1);
2429 }
2430
2431 len = strlen(",id=,path=,security_model=");
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302432 len += strlen(qemu_opt_get(opts, "fstype"));
2433 len += strlen(qemu_opt_get(opts, "mount_tag"));
2434 len += strlen(qemu_opt_get(opts, "path"));
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -07002435 len += strlen(qemu_opt_get(opts, "security_model"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302436 arg_fsdev = qemu_malloc((len + 1) * sizeof(*arg_fsdev));
2437
Aneesh Kumar K.Vc93031e2010-09-02 21:47:59 +05302438 snprintf(arg_fsdev, (len + 1) * sizeof(*arg_fsdev),
Blue Swirlcb93bbd2010-08-31 20:16:59 +00002439 "%s,id=%s,path=%s,security_model=%s",
2440 qemu_opt_get(opts, "fstype"),
2441 qemu_opt_get(opts, "mount_tag"),
2442 qemu_opt_get(opts, "path"),
2443 qemu_opt_get(opts, "security_model"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302444
2445 len = strlen("virtio-9p-pci,fsdev=,mount_tag=");
2446 len += 2*strlen(qemu_opt_get(opts, "mount_tag"));
2447 arg_9p = qemu_malloc((len + 1) * sizeof(*arg_9p));
2448
Aneesh Kumar K.Vc93031e2010-09-02 21:47:59 +05302449 snprintf(arg_9p, (len + 1) * sizeof(*arg_9p),
Blue Swirlcb93bbd2010-08-31 20:16:59 +00002450 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2451 qemu_opt_get(opts, "mount_tag"),
2452 qemu_opt_get(opts, "mount_tag"));
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302453
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002454 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev, 1)) {
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302455 fprintf(stderr, "parse error [fsdev]: %s\n", optarg);
2456 exit(1);
2457 }
2458
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002459 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p, 1)) {
Gautham R Shenoy3d54abc2010-04-29 17:45:03 +05302460 fprintf(stderr, "parse error [device]: %s\n", optarg);
2461 exit(1);
2462 }
2463
2464 qemu_free(arg_fsdev);
2465 qemu_free(arg_9p);
2466 break;
2467 }
bellard82c643f2004-07-14 17:28:13 +00002468 case QEMU_OPTION_serial:
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002469 add_device_config(DEV_SERIAL, optarg);
2470 default_serial = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01002471 if (strncmp(optarg, "mon:", 4) == 0) {
2472 default_monitor = 0;
2473 }
bellard82c643f2004-07-14 17:28:13 +00002474 break;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01002475 case QEMU_OPTION_watchdog:
Markus Armbruster09aaa162009-08-21 10:31:34 +02002476 if (watchdog) {
2477 fprintf(stderr,
2478 "qemu: only one watchdog option may be given\n");
2479 return 1;
2480 }
2481 watchdog = optarg;
Richard W.M. Jones9dd986c2009-04-25 13:56:19 +01002482 break;
2483 case QEMU_OPTION_watchdog_action:
2484 if (select_watchdog_action(optarg) == -1) {
2485 fprintf(stderr, "Unknown -watchdog-action parameter\n");
2486 exit(1);
2487 }
2488 break;
aliguori51ecf132009-01-15 20:06:40 +00002489 case QEMU_OPTION_virtiocon:
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002490 add_device_config(DEV_VIRTCON, optarg);
2491 default_virtcon = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01002492 if (strncmp(optarg, "mon:", 4) == 0) {
2493 default_monitor = 0;
2494 }
aliguori51ecf132009-01-15 20:06:40 +00002495 break;
bellard6508fe52005-01-15 12:02:56 +00002496 case QEMU_OPTION_parallel:
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002497 add_device_config(DEV_PARALLEL, optarg);
2498 default_parallel = 0;
Jan Kiszka18141ed2010-03-07 11:28:40 +01002499 if (strncmp(optarg, "mon:", 4) == 0) {
2500 default_monitor = 0;
2501 }
bellard6508fe52005-01-15 12:02:56 +00002502 break;
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002503 case QEMU_OPTION_debugcon:
2504 add_device_config(DEV_DEBUGCON, optarg);
2505 break;
bellardd63d3072004-10-03 13:29:03 +00002506 case QEMU_OPTION_loadvm:
2507 loadvm = optarg;
2508 break;
2509 case QEMU_OPTION_full_screen:
2510 full_screen = 1;
2511 break;
ths667acca2006-12-11 02:08:05 +00002512#ifdef CONFIG_SDL
ths43523e92007-02-18 18:19:32 +00002513 case QEMU_OPTION_no_frame:
2514 no_frame = 1;
2515 break;
ths3780e192007-06-21 21:08:02 +00002516 case QEMU_OPTION_alt_grab:
2517 alt_grab = 1;
2518 break;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -05002519 case QEMU_OPTION_ctrl_grab:
2520 ctrl_grab = 1;
2521 break;
ths667acca2006-12-11 02:08:05 +00002522 case QEMU_OPTION_no_quit:
2523 no_quit = 1;
2524 break;
aliguori7d957bd2009-01-15 22:14:11 +00002525 case QEMU_OPTION_sdl:
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002526 display_type = DT_SDL;
aliguori7d957bd2009-01-15 22:14:11 +00002527 break;
ths667acca2006-12-11 02:08:05 +00002528#endif
bellardf7cce892004-12-08 22:21:25 +00002529 case QEMU_OPTION_pidfile:
ths93815bc2007-03-19 15:58:31 +00002530 pid_file = optarg;
bellardf7cce892004-12-08 22:21:25 +00002531 break;
bellarda09db212005-04-30 16:10:35 +00002532 case QEMU_OPTION_win2k_hack:
2533 win2k_install_hack = 1;
2534 break;
aliguori73822ec2009-01-15 20:11:34 +00002535 case QEMU_OPTION_rtc_td_hack:
2536 rtc_td_hack = 1;
2537 break;
aliguori8a92ea22009-02-27 20:12:36 +00002538 case QEMU_OPTION_acpitable:
Blue Swirlde06f8d2010-03-29 19:23:50 +00002539 do_acpitable_option(optarg);
aliguori8a92ea22009-02-27 20:12:36 +00002540 break;
aliguorib6f6e3d2009-04-17 18:59:56 +00002541 case QEMU_OPTION_smbios:
Blue Swirlde06f8d2010-03-29 19:23:50 +00002542 do_smbios_option(optarg);
aliguorib6f6e3d2009-04-17 18:59:56 +00002543 break;
aliguori7ba1e612008-11-05 16:04:33 +00002544 case QEMU_OPTION_enable_kvm:
2545 kvm_allowed = 1;
aliguori7ba1e612008-11-05 16:04:33 +00002546 break;
bellardbb36d472005-11-05 14:22:28 +00002547 case QEMU_OPTION_usb:
2548 usb_enabled = 1;
2549 break;
bellarda594cfb2005-11-06 16:13:29 +00002550 case QEMU_OPTION_usbdevice:
2551 usb_enabled = 1;
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002552 add_device_config(DEV_USB, optarg);
2553 break;
2554 case QEMU_OPTION_device:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002555 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
Gerd Hoffmannf31d07d2009-07-31 12:25:37 +02002556 exit(1);
2557 }
bellarda594cfb2005-11-06 16:13:29 +00002558 break;
bellard6a00d602005-11-21 23:25:50 +00002559 case QEMU_OPTION_smp:
Andre Przywaradc6b1c02009-08-19 15:42:40 +02002560 smp_parse(optarg);
aliguorib2097002008-10-07 20:39:39 +00002561 if (smp_cpus < 1) {
bellard6a00d602005-11-21 23:25:50 +00002562 fprintf(stderr, "Invalid number of CPUs\n");
2563 exit(1);
2564 }
Jes Sorensen6be68d72009-07-23 17:03:42 +02002565 if (max_cpus < smp_cpus) {
2566 fprintf(stderr, "maxcpus must be equal to or greater than "
2567 "smp\n");
2568 exit(1);
2569 }
2570 if (max_cpus > 255) {
2571 fprintf(stderr, "Unsupported number of maxcpus\n");
2572 exit(1);
2573 }
bellard6a00d602005-11-21 23:25:50 +00002574 break;
bellard24236862006-04-30 21:28:36 +00002575 case QEMU_OPTION_vnc:
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02002576 display_remote++;
ths73fc9742006-12-22 02:09:07 +00002577 vnc_display = optarg;
bellard24236862006-04-30 21:28:36 +00002578 break;
bellard6515b202006-05-03 22:02:44 +00002579 case QEMU_OPTION_no_acpi:
2580 acpi_enabled = 0;
2581 break;
aliguori16b29ae2008-12-17 23:28:44 +00002582 case QEMU_OPTION_no_hpet:
2583 no_hpet = 1;
2584 break;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +02002585 case QEMU_OPTION_balloon:
2586 if (balloon_parse(optarg) < 0) {
2587 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
2588 exit(1);
2589 }
Eduardo Habkostdf97b922009-06-10 16:34:08 -03002590 break;
bellardd1beab82006-10-02 19:44:22 +00002591 case QEMU_OPTION_no_reboot:
2592 no_reboot = 1;
2593 break;
aurel32b2f76162008-04-11 21:35:52 +00002594 case QEMU_OPTION_no_shutdown:
2595 no_shutdown = 1;
2596 break;
balrog9467cd42007-05-01 01:34:14 +00002597 case QEMU_OPTION_show_cursor:
2598 cursor_hide = 0;
2599 break;
blueswir18fcb1b92008-09-18 18:29:08 +00002600 case QEMU_OPTION_uuid:
2601 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
2602 fprintf(stderr, "Fail to parse UUID string."
2603 " Wrong format.\n");
2604 exit(1);
2605 }
2606 break;
ths9ae02552007-01-05 17:39:04 +00002607 case QEMU_OPTION_option_rom:
2608 if (nb_option_roms >= MAX_OPTION_ROMS) {
2609 fprintf(stderr, "Too many option ROMs\n");
2610 exit(1);
2611 }
Gleb Natapov2e55e842010-12-08 13:35:07 +02002612 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
2613 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
2614 option_rom[nb_option_roms].bootindex =
2615 qemu_opt_get_number(opts, "bootindex", -1);
2616 if (!option_rom[nb_option_roms].name) {
2617 fprintf(stderr, "Option ROM file is not specified\n");
2618 exit(1);
2619 }
ths9ae02552007-01-05 17:39:04 +00002620 nb_option_roms++;
2621 break;
pbrook8e716212007-01-20 17:12:09 +00002622 case QEMU_OPTION_semihosting:
2623 semihosting_enabled = 1;
2624 break;
thsc35734b2007-03-19 15:17:08 +00002625 case QEMU_OPTION_name:
Andi Kleen18894652009-07-02 09:34:17 +02002626 qemu_name = qemu_strdup(optarg);
2627 {
2628 char *p = strchr(qemu_name, ',');
2629 if (p != NULL) {
2630 *p++ = 0;
2631 if (strncmp(p, "process=", 8)) {
Aurelien Jarno5697f6a2010-12-27 18:29:20 +01002632 fprintf(stderr, "Unknown subargument %s to -name\n", p);
Andi Kleen18894652009-07-02 09:34:17 +02002633 exit(1);
2634 }
2635 p += 8;
Jes Sorensence798cf2010-06-10 11:42:31 +02002636 os_set_proc_name(p);
Andi Kleen18894652009-07-02 09:34:17 +02002637 }
2638 }
thsc35734b2007-03-19 15:17:08 +00002639 break;
blueswir166508602007-05-01 14:16:52 +00002640 case QEMU_OPTION_prom_env:
2641 if (nb_prom_envs >= MAX_PROM_ENVS) {
2642 fprintf(stderr, "Too many prom variables\n");
2643 exit(1);
2644 }
2645 prom_envs[nb_prom_envs] = optarg;
2646 nb_prom_envs++;
2647 break;
balrog2b8f2d42007-07-27 22:08:46 +00002648 case QEMU_OPTION_old_param:
2649 old_param = 1;
ths05ebd532008-01-08 19:32:16 +00002650 break;
thsf3dcfad2007-08-24 01:26:02 +00002651 case QEMU_OPTION_clock:
2652 configure_alarms(optarg);
2653 break;
bellard7e0af5d02007-11-07 16:24:33 +00002654 case QEMU_OPTION_startdate:
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002655 configure_rtc_date_offset(optarg, 1);
2656 break;
2657 case QEMU_OPTION_rtc:
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002658 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002659 if (!opts) {
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002660 exit(1);
bellard7e0af5d02007-11-07 16:24:33 +00002661 }
Jan Kiszka1ed2fc12009-09-15 13:36:04 +02002662 configure_rtc(opts);
bellard7e0af5d02007-11-07 16:24:33 +00002663 break;
bellard26a5f132008-05-28 12:30:31 +00002664 case QEMU_OPTION_tb_size:
2665 tb_size = strtol(optarg, NULL, 0);
2666 if (tb_size < 0)
2667 tb_size = 0;
2668 break;
pbrook2e70f6e2008-06-29 01:03:05 +00002669 case QEMU_OPTION_icount:
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01002670 icount_option = optarg;
pbrook2e70f6e2008-06-29 01:03:05 +00002671 break;
aliguori5bb79102008-10-13 03:12:02 +00002672 case QEMU_OPTION_incoming:
2673 incoming = optarg;
Amit Shah8e848652010-07-27 15:49:19 +05302674 incoming_expected = true;
aliguori5bb79102008-10-13 03:12:02 +00002675 break;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01002676 case QEMU_OPTION_nodefaults:
2677 default_serial = 0;
2678 default_parallel = 0;
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002679 default_virtcon = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01002680 default_monitor = 0;
2681 default_vga = 0;
Gerd Hoffmanncb4522c2009-12-08 13:11:47 +01002682 default_net = 0;
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01002683 default_floppy = 0;
2684 default_cdrom = 0;
2685 default_sdcard = 0;
Gerd Hoffmannd8c208d2009-12-08 13:11:46 +01002686 break;
aliguorie37630c2009-04-22 15:19:10 +00002687 case QEMU_OPTION_xen_domid:
Blue Swirlad960902010-03-29 19:23:52 +00002688 if (!(xen_available())) {
2689 printf("Option %s not supported for this target\n", popt->name);
2690 exit(1);
2691 }
aliguorie37630c2009-04-22 15:19:10 +00002692 xen_domid = atoi(optarg);
2693 break;
2694 case QEMU_OPTION_xen_create:
Blue Swirlad960902010-03-29 19:23:52 +00002695 if (!(xen_available())) {
2696 printf("Option %s not supported for this target\n", popt->name);
2697 exit(1);
2698 }
aliguorie37630c2009-04-22 15:19:10 +00002699 xen_mode = XEN_CREATE;
2700 break;
2701 case QEMU_OPTION_xen_attach:
Blue Swirlad960902010-03-29 19:23:52 +00002702 if (!(xen_available())) {
2703 printf("Option %s not supported for this target\n", popt->name);
2704 exit(1);
2705 }
aliguorie37630c2009-04-22 15:19:10 +00002706 xen_mode = XEN_ATTACH;
2707 break;
Prerna Saxenaab6540d2010-08-09 11:48:32 +01002708#ifdef CONFIG_SIMPLE_TRACE
2709 case QEMU_OPTION_trace:
2710 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
2711 if (opts) {
2712 trace_file = qemu_opt_get(opts, "file");
2713 }
2714 break;
2715#endif
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002716 case QEMU_OPTION_readconfig:
2717 {
Kevin Wolfdcfb0932010-03-05 17:25:55 +01002718 int ret = qemu_read_config_file(optarg);
2719 if (ret < 0) {
2720 fprintf(stderr, "read config %s: %s\n", optarg,
2721 strerror(-ret));
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002722 exit(1);
2723 }
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002724 break;
2725 }
Gerd Hoffmann29b00402010-03-11 11:13:27 -03002726 case QEMU_OPTION_spice:
2727 olist = qemu_find_opts("spice");
2728 if (!olist) {
2729 fprintf(stderr, "spice is not supported by this qemu build.\n");
2730 exit(1);
2731 }
2732 opts = qemu_opts_parse(olist, optarg, 0);
2733 if (!opts) {
2734 fprintf(stderr, "parse error: %s\n", optarg);
2735 exit(1);
2736 }
2737 break;
Gerd Hoffmann715a6642009-10-14 10:39:28 +02002738 case QEMU_OPTION_writeconfig:
2739 {
2740 FILE *fp;
2741 if (strcmp(optarg, "-") == 0) {
2742 fp = stdout;
2743 } else {
2744 fp = fopen(optarg, "w");
2745 if (fp == NULL) {
2746 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
2747 exit(1);
2748 }
2749 }
2750 qemu_config_write(fp);
2751 fclose(fp);
2752 break;
2753 }
Jes Sorensen59a52642010-06-10 11:42:25 +02002754 default:
2755 os_parse_cmd_args(popt->index, optarg);
bellardcd6f1162004-05-13 22:02:20 +00002756 }
bellard0824d6f2003-06-24 13:42:40 +00002757 }
2758 }
Markus Armbruster0f0bc3f2010-02-18 20:13:51 +01002759 loc_set_none();
bellard330d0412003-07-26 18:11:40 +00002760
Paul Brook5cea8592009-05-30 00:52:44 +01002761 /* If no data_dir is specified then try to find it relative to the
2762 executable path. */
2763 if (!data_dir) {
Jes Sorensen61705402010-06-10 11:42:23 +02002764 data_dir = os_find_datadir(argv[0]);
Paul Brook5cea8592009-05-30 00:52:44 +01002765 }
2766 /* If all else fails use the install patch specified when building. */
2767 if (!data_dir) {
Paolo Bonzini1dabe052010-05-26 16:08:25 +02002768 data_dir = CONFIG_QEMU_DATADIR;
Paul Brook5cea8592009-05-30 00:52:44 +01002769 }
2770
Prerna Saxenaab6540d2010-08-09 11:48:32 +01002771#ifdef CONFIG_SIMPLE_TRACE
2772 /*
2773 * Set the trace file name, if specified.
2774 */
2775 st_set_trace_file(trace_file);
2776#endif
Jes Sorensen6be68d72009-07-23 17:03:42 +02002777 /*
2778 * Default to max_cpus = smp_cpus, in case the user doesn't
2779 * specify a max_cpus value.
2780 */
2781 if (!max_cpus)
2782 max_cpus = smp_cpus;
2783
balrog3d878ca2008-10-28 10:59:59 +00002784 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
aliguorib2097002008-10-07 20:39:39 +00002785 if (smp_cpus > machine->max_cpus) {
2786 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
2787 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
2788 machine->max_cpus);
2789 exit(1);
2790 }
2791
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002792 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
2793 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002794
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002795 if (machine->no_serial) {
2796 default_serial = 0;
2797 }
2798 if (machine->no_parallel) {
2799 default_parallel = 0;
2800 }
2801 if (!machine->use_virtcon) {
2802 default_virtcon = 0;
2803 }
2804 if (machine->no_vga) {
2805 default_vga = 0;
2806 }
Gerd Hoffmannac33f8f2009-12-16 14:25:39 +01002807 if (machine->no_floppy) {
2808 default_floppy = 0;
2809 }
2810 if (machine->no_cdrom) {
2811 default_cdrom = 0;
2812 }
2813 if (machine->no_sdcard) {
2814 default_sdcard = 0;
2815 }
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002816
Anthony Liguori993fbfd2009-05-21 16:54:00 -05002817 if (display_type == DT_NOGRAPHIC) {
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002818 if (default_parallel)
2819 add_device_config(DEV_PARALLEL, "null");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002820 if (default_serial && default_monitor) {
2821 add_device_config(DEV_SERIAL, "mon:stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002822 } else if (default_virtcon && default_monitor) {
2823 add_device_config(DEV_VIRTCON, "mon:stdio");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002824 } else {
2825 if (default_serial)
2826 add_device_config(DEV_SERIAL, "stdio");
Gerd Hoffmann986c5f72009-12-08 13:11:54 +01002827 if (default_virtcon)
2828 add_device_config(DEV_VIRTCON, "stdio");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002829 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002830 monitor_parse("stdio", "readline");
Gerd Hoffmanne1c09172009-12-08 13:11:44 +01002831 }
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002832 } else {
2833 if (default_serial)
2834 add_device_config(DEV_SERIAL, "vc:80Cx24C");
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002835 if (default_parallel)
2836 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
Gerd Hoffmannabdeed02009-12-08 13:11:43 +01002837 if (default_monitor)
Gerd Hoffmann6ca55822009-12-08 13:11:52 +01002838 monitor_parse("vc:80Cx24C", "readline");
Alexander Graf38536da2009-12-17 13:06:08 +01002839 if (default_virtcon)
2840 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
aliguoribc0129d2008-08-01 15:12:34 +00002841 }
Gerd Hoffmann64465292009-12-08 13:11:45 +01002842 if (default_vga)
2843 vga_interface_type = VGA_CIRRUS;
aliguoribc0129d2008-08-01 15:12:34 +00002844
TeLeMana5829fd2010-04-15 12:37:55 +08002845 socket_init();
2846
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002847 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002848 exit(1);
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -07002849#ifdef CONFIG_VIRTFS
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002850 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +05302851 exit(1);
2852 }
2853#endif
Gerd Hoffmann1a688d32009-12-08 13:11:36 +01002854
Jes Sorenseneb505be2010-06-10 11:42:28 +02002855 os_daemonize();
ths71e3ceb2006-12-22 02:11:31 +00002856
thsaa26bb22007-03-25 21:33:06 +00002857 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
Jes Sorenseneb505be2010-06-10 11:42:28 +02002858 os_pidfile_error();
ths93815bc2007-03-19 15:58:31 +00002859 exit(1);
2860 }
2861
Paolo Bonzini98c85732010-04-19 18:59:30 +00002862 if (kvm_allowed) {
Jan Kiszkacad1e282011-01-21 21:48:16 +01002863 int ret = kvm_init();
Marcelo Tosatti214910a2009-09-18 02:41:23 -03002864 if (ret < 0) {
Paolo Bonzini98c85732010-04-19 18:59:30 +00002865 if (!kvm_available()) {
2866 printf("KVM not supported for this target\n");
2867 } else {
2868 fprintf(stderr, "failed to initialize KVM: %s\n", strerror(-ret));
2869 }
Marcelo Tosatti214910a2009-09-18 02:41:23 -03002870 exit(1);
2871 }
2872 }
2873
aliguori3fcf7b62009-04-24 18:03:25 +00002874 if (qemu_init_main_loop()) {
2875 fprintf(stderr, "qemu_init_main_loop failed\n");
2876 exit(1);
2877 }
bellarda20dd502003-09-30 21:07:02 +00002878 linux_boot = (kernel_filename != NULL);
balrog6c41b272007-11-17 12:12:29 +00002879
thsf8d39c02008-07-03 10:01:15 +00002880 if (!linux_boot && *kernel_cmdline != '\0') {
2881 fprintf(stderr, "-append only allowed with -kernel option\n");
2882 exit(1);
2883 }
2884
2885 if (!linux_boot && initrd_filename != NULL) {
2886 fprintf(stderr, "-initrd only allowed with -kernel option\n");
2887 exit(1);
2888 }
2889
Jes Sorensen9156d762010-06-10 11:42:30 +02002890 os_set_line_buffering();
ths3b46e622007-09-17 08:09:54 +00002891
aliguori7183b4b2008-11-05 20:40:18 +00002892 if (init_timer_alarm() < 0) {
2893 fprintf(stderr, "could not initialize alarm timer\n");
2894 exit(1);
2895 }
Paolo Bonzini4e3de9e2010-03-10 11:38:48 +01002896 configure_icount(icount_option);
pbrook634fce92006-07-15 17:40:09 +00002897
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01002898 if (net_init_clients() < 0) {
2899 exit(1);
bellard702c6512004-04-02 21:21:32 +00002900 }
bellardf1510b22003-06-25 00:07:40 +00002901
balrogdc72ac12008-11-09 00:04:26 +00002902 /* init the bluetooth world */
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02002903 if (foreach_device_config(DEV_BT, bt_parse))
2904 exit(1);
balrogdc72ac12008-11-09 00:04:26 +00002905
bellard0824d6f2003-06-24 13:42:40 +00002906 /* init the memory */
pbrook94a6b542009-04-11 17:15:54 +00002907 if (ram_size == 0)
2908 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
balrog7fb4fdc2008-04-24 17:59:27 +00002909
bellard26a5f132008-05-28 12:30:31 +00002910 /* init the dynamic translator */
2911 cpu_exec_init_all(tb_size * 1024 * 1024);
2912
Markus Armbrustereb852012009-10-27 18:41:44 +01002913 bdrv_init_with_whitelist();
thse4bcb142007-12-02 04:51:10 +00002914
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +02002915 blk_mig_init();
2916
ths96d30e42007-01-07 20:42:14 +00002917 /* open the virtual block devices */
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02002918 if (snapshot)
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002919 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
2920 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +02002921 exit(1);
balrog3e3d5812007-04-30 02:09:25 +00002922
Markus Armbruster4e5d9b52011-01-28 11:21:45 +01002923 default_drive(default_cdrom, snapshot, machine->use_scsi,
2924 IF_DEFAULT, 2, CDROM_OPTS);
2925 default_drive(default_floppy, snapshot, machine->use_scsi,
2926 IF_FLOPPY, 0, FD_OPTS);
2927 default_drive(default_sdcard, snapshot, machine->use_scsi,
2928 IF_SD, 0, SD_OPTS);
2929
Alex Williamson97ab12d2010-06-25 11:09:50 -06002930 register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL,
lirans@il.ibm.comc163b5c2009-11-02 15:40:58 +02002931 ram_load, NULL);
bellard8a7ddc32004-03-31 19:00:16 +00002932
aliguori268a3622009-04-21 22:30:27 +00002933 if (nb_numa_nodes > 0) {
2934 int i;
2935
2936 if (nb_numa_nodes > smp_cpus) {
2937 nb_numa_nodes = smp_cpus;
2938 }
2939
2940 /* If no memory size if given for any node, assume the default case
2941 * and distribute the available memory equally across all nodes
2942 */
2943 for (i = 0; i < nb_numa_nodes; i++) {
2944 if (node_mem[i] != 0)
2945 break;
2946 }
2947 if (i == nb_numa_nodes) {
2948 uint64_t usedmem = 0;
2949
2950 /* On Linux, the each node's border has to be 8MB aligned,
2951 * the final node gets the rest.
2952 */
2953 for (i = 0; i < nb_numa_nodes - 1; i++) {
2954 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
2955 usedmem += node_mem[i];
2956 }
2957 node_mem[i] = ram_size - usedmem;
2958 }
2959
2960 for (i = 0; i < nb_numa_nodes; i++) {
2961 if (node_cpumask[i] != 0)
2962 break;
2963 }
2964 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2965 * must cope with this anyway, because there are BIOSes out there in
2966 * real machines which also use this scheme.
2967 */
2968 if (i == nb_numa_nodes) {
2969 for (i = 0; i < smp_cpus; i++) {
2970 node_cpumask[i % nb_numa_nodes] |= 1 << i;
2971 }
2972 }
2973 }
2974
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002975 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
Jan Kiszka157b9312010-04-06 16:55:53 +02002976 exit(1);
2977 }
2978
Gerd Hoffmann998bbd72009-12-08 13:11:41 +01002979 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
2980 exit(1);
Gerd Hoffmann6a5e8b02009-12-08 13:11:42 +01002981 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
2982 exit(1);
Gerd Hoffmannaee1b932009-12-08 13:11:53 +01002983 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
2984 exit(1);
H. Peter Anvinc9f398e2009-12-29 13:51:36 -08002985 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
2986 exit(1);
aliguori2796dae2009-01-16 20:23:27 +00002987
Paul Brookaae94602009-05-14 22:35:06 +01002988 module_call_init(MODULE_INIT_DEVICE);
2989
Gerd Hoffmann3329f072010-08-20 13:52:01 +02002990 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0)
Markus Armbrusterff952ba2010-01-29 19:48:57 +01002991 exit(0);
2992
Markus Armbruster09aaa162009-08-21 10:31:34 +02002993 if (watchdog) {
2994 i = select_watchdog(watchdog);
2995 if (i > 0)
2996 exit (i == 1 ? 1 : 0);
2997 }
2998
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02002999 if (machine->compat_props) {
Gerd Hoffmann458fb672009-12-08 13:11:33 +01003000 qdev_prop_register_global_list(machine->compat_props);
Gerd Hoffmannb6b61142009-07-15 13:48:21 +02003001 }
Gerd Hoffmannd0fef6f2009-12-08 13:11:34 +01003002 qemu_add_globals();
3003
Paul Brookfbe1b592009-05-13 17:56:25 +01003004 machine->init(ram_size, boot_devices,
aliguori3023f3322009-01-16 19:04:14 +00003005 kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
3006
Jan Kiszkaea375f92010-03-01 19:10:30 +01003007 cpu_synchronize_all_post_init();
aliguori268a3622009-04-21 22:30:27 +00003008
Juan Quintela67b3b712009-08-28 19:25:15 +02003009 /* must be after terminal init, SDL library changes signal handlers */
Jes Sorensen8d963e62010-06-10 11:42:22 +02003010 os_setup_signal_handling();
Juan Quintela67b3b712009-08-28 19:25:15 +02003011
Blue Swirl87d0a282010-03-27 18:24:45 +00003012 set_numa_modes();
aliguori268a3622009-04-21 22:30:27 +00003013
aliguori6f338c32009-02-11 15:21:54 +00003014 current_machine = machine;
3015
aliguori3023f3322009-01-16 19:04:14 +00003016 /* init USB devices */
3017 if (usb_enabled) {
Markus Armbruster07527062009-10-06 12:16:57 +01003018 if (foreach_device_config(DEV_USB, usb_parse) < 0)
3019 exit(1);
aliguori3023f3322009-01-16 19:04:14 +00003020 }
3021
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003022 /* init generic devices */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02003023 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
Gerd Hoffmannbd3c9482009-07-15 13:59:26 +02003024 exit(1);
3025
Markus Armbruster668680f2010-02-11 14:44:58 +01003026 net_check_clients();
3027
aliguori3023f3322009-01-16 19:04:14 +00003028 /* just use the first displaystate for the moment */
Paolo Bonzinib473df62010-02-11 00:29:55 +01003029 ds = get_displaystate();
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003030
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003031 if (using_spice)
3032 display_remote++;
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003033 if (display_type == DT_DEFAULT && !display_remote) {
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003034#if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003035 display_type = DT_SDL;
3036#else
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003037 vnc_display = "localhost:0,to=99";
3038 show_vnc_port = 1;
3039#endif
3040 }
3041
3042
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003043 /* init local displays */
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003044 switch (display_type) {
3045 case DT_NOGRAPHIC:
3046 break;
3047#if defined(CONFIG_CURSES)
3048 case DT_CURSES:
3049 curses_display_init(ds, full_screen);
3050 break;
3051#endif
bellard5b0753e2005-03-01 21:37:28 +00003052#if defined(CONFIG_SDL)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003053 case DT_SDL:
3054 sdl_display_init(ds, full_screen, no_frame);
3055 break;
bellard5b0753e2005-03-01 21:37:28 +00003056#elif defined(CONFIG_COCOA)
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003057 case DT_SDL:
3058 cocoa_display_init(ds, full_screen);
3059 break;
bellard313aa562003-08-10 21:52:11 +00003060#endif
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003061 default:
3062 break;
3063 }
3064
3065 /* init remote displays */
3066 if (vnc_display) {
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003067 vnc_display_init(ds);
3068 if (vnc_display_open(ds, vnc_display) < 0)
3069 exit(1);
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003070
Anthony Liguori993fbfd2009-05-21 16:54:00 -05003071 if (show_vnc_port) {
3072 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
Anthony Liguorif92f8af2009-05-20 13:01:02 -05003073 }
bellard313aa562003-08-10 21:52:11 +00003074 }
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003075#ifdef CONFIG_SPICE
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +02003076 if (using_spice && !qxl_enabled) {
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02003077 qemu_spice_display_init(ds);
3078 }
3079#endif
aliguori5b08fc12008-08-21 20:08:03 +00003080
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003081 /* display setup */
3082 dpy_resize(ds);
aliguori3023f3322009-01-16 19:04:14 +00003083 dcl = ds->listeners;
3084 while (dcl != NULL) {
3085 if (dcl->dpy_refresh != NULL) {
3086 ds->gui_timer = qemu_new_timer(rt_clock, gui_update, ds);
3087 qemu_mod_timer(ds->gui_timer, qemu_get_clock(rt_clock));
Isaku Yamahata0f2ad632010-05-27 14:38:47 +09003088 break;
ths20d8a3e2007-02-18 17:04:49 +00003089 }
aliguori3023f3322009-01-16 19:04:14 +00003090 dcl = dcl->next;
bellard82c643f2004-07-14 17:28:13 +00003091 }
Gerd Hoffmann6b62dc22010-08-25 10:51:06 +02003092 if (ds->gui_timer == NULL) {
blueswir19043b622009-01-21 19:28:13 +00003093 nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL);
3094 qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock));
3095 }
Paolo Bonzinib473df62010-02-11 00:29:55 +01003096 text_consoles_set_display(ds);
aliguori2796dae2009-01-16 20:23:27 +00003097
aliguori59030a82009-04-05 18:43:41 +00003098 if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) {
3099 fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n",
3100 gdbstub_dev);
3101 exit(1);
balrog45669e02007-07-02 13:20:17 +00003102 }
balrog45669e02007-07-02 13:20:17 +00003103
Gerd Hoffmann3418bd22009-09-25 21:42:41 +02003104 qdev_machine_creation_done();
3105
Gerd Hoffmann15ff7702009-12-14 16:07:35 +01003106 if (rom_load_all() != 0) {
3107 fprintf(stderr, "rom loading failed\n");
3108 exit(1);
3109 }
Gerd Hoffmann45a50b12009-10-01 16:42:33 +02003110
Isaku Yamahata80376c32010-12-20 14:33:35 +09003111 /* TODO: once all bus devices are qdevified, this should be done
3112 * when bus is created by qdev.c */
3113 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
Gleb Natapov4cab9462010-12-08 13:35:08 +02003114 qemu_run_machine_init_done_notifiers();
3115
Juan Quintela504c2942009-11-12 00:39:13 +01003116 qemu_system_reset();
Juan Quintela05f24012009-08-20 19:42:22 +02003117 if (loadvm) {
Markus Armbruster03cd4652010-02-17 16:24:10 +01003118 if (load_vmstate(loadvm) < 0) {
Juan Quintela05f24012009-08-20 19:42:22 +02003119 autostart = 0;
3120 }
3121 }
bellardd63d3072004-10-03 13:29:03 +00003122
Glauber Costa2bb8c102009-07-24 16:20:23 -04003123 if (incoming) {
Juan Quintela8ca5e802010-06-09 14:10:54 +02003124 int ret = qemu_start_incoming_migration(incoming);
3125 if (ret < 0) {
3126 fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n",
3127 incoming, ret);
3128 exit(ret);
3129 }
Avi Kivity6b99dad2009-08-09 14:39:20 +03003130 } else if (autostart) {
aliguoric0f4ce72009-03-05 23:01:01 +00003131 vm_start();
Avi Kivity6b99dad2009-08-09 14:39:20 +03003132 }
thsffd843b2006-12-21 19:46:43 +00003133
Jes Sorenseneb505be2010-06-10 11:42:28 +02003134 os_setup_post();
ths71e3ceb2006-12-22 02:11:31 +00003135
bellard8a7ddc32004-03-31 19:00:16 +00003136 main_loop();
bellard40c3bac2004-04-04 12:56:28 +00003137 quit_timers();
aliguori63a01ef2008-10-31 19:10:00 +00003138 net_cleanup();
thsb46a8902007-10-21 23:20:45 +00003139
bellard0824d6f2003-06-24 13:42:40 +00003140 return 0;
3141}