bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 1 | /* |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 2 | * QEMU System Emulator |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
bellard | 68d0f70 | 2008-01-06 17:21:48 +0000 | [diff] [blame] | 4 | * Copyright (c) 2003-2008 Fabrice Bellard |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 5 | * |
bellard | 1df912c | 2003-06-25 16:20:35 +0000 | [diff] [blame] | 6 | * 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. |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 23 | */ |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 24 | #include <unistd.h> |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 25 | #include <fcntl.h> |
| 26 | #include <signal.h> |
| 27 | #include <time.h> |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 28 | #include <errno.h> |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 29 | #include <sys/time.h> |
bellard | c88676f | 2006-08-06 13:36:11 +0000 | [diff] [blame] | 30 | #include <zlib.h> |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 31 | |
Juan Quintela | 71e72a1 | 2009-07-27 16:12:56 +0200 | [diff] [blame] | 32 | /* Needed early for CONFIG_BSD etc. */ |
blueswir1 | d40cdb1 | 2009-03-07 16:52:02 +0000 | [diff] [blame] | 33 | #include "config-host.h" |
| 34 | |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 35 | #ifndef _WIN32 |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 36 | #include <libgen.h> |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 37 | #include <sys/times.h> |
bellard | f1510b2 | 2003-06-25 00:07:40 +0000 | [diff] [blame] | 38 | #include <sys/wait.h> |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 39 | #include <termios.h> |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 40 | #include <sys/mman.h> |
bellard | f1510b2 | 2003-06-25 00:07:40 +0000 | [diff] [blame] | 41 | #include <sys/ioctl.h> |
blueswir1 | 24646c7 | 2008-11-07 16:55:48 +0000 | [diff] [blame] | 42 | #include <sys/resource.h> |
bellard | f1510b2 | 2003-06-25 00:07:40 +0000 | [diff] [blame] | 43 | #include <sys/socket.h> |
bellard | c94c8d6 | 2004-09-13 21:37:34 +0000 | [diff] [blame] | 44 | #include <netinet/in.h> |
blueswir1 | 24646c7 | 2008-11-07 16:55:48 +0000 | [diff] [blame] | 45 | #include <net/if.h> |
blueswir1 | 24646c7 | 2008-11-07 16:55:48 +0000 | [diff] [blame] | 46 | #include <arpa/inet.h> |
bellard | 9d728e8 | 2004-09-05 23:09:03 +0000 | [diff] [blame] | 47 | #include <dirent.h> |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 48 | #include <netdb.h> |
ths | cb4b976 | 2007-09-13 12:39:35 +0000 | [diff] [blame] | 49 | #include <sys/select.h> |
Prerna Saxena | ab6540d | 2010-08-09 11:48:32 +0100 | [diff] [blame] | 50 | |
Juan Quintela | 71e72a1 | 2009-07-27 16:12:56 +0200 | [diff] [blame] | 51 | #ifdef CONFIG_BSD |
bellard | 7d3505c | 2004-05-12 19:32:15 +0000 | [diff] [blame] | 52 | #include <sys/stat.h> |
Aurelien Jarno | a167ba5 | 2009-11-29 18:00:41 +0100 | [diff] [blame] | 53 | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
bellard | 7d3505c | 2004-05-12 19:32:15 +0000 | [diff] [blame] | 54 | #include <libutil.h> |
Juergen Lock | 92c0e65 | 2010-03-25 22:07:12 +0100 | [diff] [blame] | 55 | #include <sys/sysctl.h> |
blueswir1 | 24646c7 | 2008-11-07 16:55:48 +0000 | [diff] [blame] | 56 | #else |
| 57 | #include <util.h> |
blueswir1 | 128ab2f | 2008-08-15 18:33:42 +0000 | [diff] [blame] | 58 | #endif |
Aurelien Jarno | bbe813a | 2009-11-30 15:42:59 +0100 | [diff] [blame] | 59 | #else |
blueswir1 | 223f0d7 | 2008-09-30 18:12:18 +0000 | [diff] [blame] | 60 | #ifdef __linux__ |
bellard | 7d3505c | 2004-05-12 19:32:15 +0000 | [diff] [blame] | 61 | #include <pty.h> |
| 62 | #include <malloc.h> |
ths | bd494f4 | 2007-09-16 20:03:23 +0000 | [diff] [blame] | 63 | |
bellard | e57a8c0 | 2005-11-10 23:58:52 +0000 | [diff] [blame] | 64 | #include <linux/ppdev.h> |
ths | 5867c88 | 2007-02-17 23:44:43 +0000 | [diff] [blame] | 65 | #include <linux/parport.h> |
blueswir1 | 223f0d7 | 2008-09-30 18:12:18 +0000 | [diff] [blame] | 66 | #endif |
| 67 | #ifdef __sun__ |
ths | d5d10bc | 2007-02-17 22:54:49 +0000 | [diff] [blame] | 68 | #include <sys/stat.h> |
| 69 | #include <sys/ethernet.h> |
| 70 | #include <sys/sockio.h> |
ths | d5d10bc | 2007-02-17 22:54:49 +0000 | [diff] [blame] | 71 | #include <netinet/arp.h> |
ths | d5d10bc | 2007-02-17 22:54:49 +0000 | [diff] [blame] | 72 | #include <netinet/in_systm.h> |
| 73 | #include <netinet/ip.h> |
| 74 | #include <netinet/ip_icmp.h> // must come after ip.h |
| 75 | #include <netinet/udp.h> |
| 76 | #include <netinet/tcp.h> |
| 77 | #include <net/if.h> |
| 78 | #include <syslog.h> |
| 79 | #include <stropts.h> |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 80 | #endif |
bellard | 7d3505c | 2004-05-12 19:32:15 +0000 | [diff] [blame] | 81 | #endif |
bellard | ec530c8 | 2006-04-25 22:36:06 +0000 | [diff] [blame] | 82 | #endif |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 83 | |
blueswir1 | 9892fbf | 2008-08-24 10:34:20 +0000 | [diff] [blame] | 84 | #if defined(__OpenBSD__) |
| 85 | #include <util.h> |
| 86 | #endif |
| 87 | |
ths | 8a16d27 | 2008-07-19 09:56:24 +0000 | [diff] [blame] | 88 | #if defined(CONFIG_VDE) |
| 89 | #include <libvdeplug.h> |
| 90 | #endif |
| 91 | |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 92 | #ifdef _WIN32 |
aliguori | 49dc768 | 2009-03-08 16:26:59 +0000 | [diff] [blame] | 93 | #include <windows.h> |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 94 | #endif |
| 95 | |
bellard | 73332e5 | 2004-04-04 20:22:28 +0000 | [diff] [blame] | 96 | #ifdef CONFIG_SDL |
Stefan Weil | 59a36a2 | 2009-06-18 20:11:03 +0200 | [diff] [blame] | 97 | #if defined(__APPLE__) || defined(main) |
Stefan Weil | 6693665 | 2009-06-13 13:19:11 +0200 | [diff] [blame] | 98 | #include <SDL.h> |
malc | 880fec5 | 2009-02-15 20:18:41 +0000 | [diff] [blame] | 99 | int qemu_main(int argc, char **argv, char **envp); |
| 100 | int main(int argc, char **argv) |
| 101 | { |
Stefan Weil | 59a36a2 | 2009-06-18 20:11:03 +0200 | [diff] [blame] | 102 | return qemu_main(argc, argv, NULL); |
malc | 880fec5 | 2009-02-15 20:18:41 +0000 | [diff] [blame] | 103 | } |
| 104 | #undef main |
| 105 | #define main qemu_main |
bellard | 96bcd4f | 2004-07-10 16:26:15 +0000 | [diff] [blame] | 106 | #endif |
bellard | 73332e5 | 2004-04-04 20:22:28 +0000 | [diff] [blame] | 107 | #endif /* CONFIG_SDL */ |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 108 | |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 109 | #ifdef CONFIG_COCOA |
| 110 | #undef main |
| 111 | #define main qemu_main |
| 112 | #endif /* CONFIG_COCOA */ |
| 113 | |
Anthony Liguori | 69e5bb6 | 2011-08-22 08:12:52 -0500 | [diff] [blame] | 114 | #include <glib.h> |
| 115 | |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 116 | #include "hw/hw.h" |
| 117 | #include "hw/boards.h" |
| 118 | #include "hw/usb.h" |
| 119 | #include "hw/pcmcia.h" |
| 120 | #include "hw/pc.h" |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 121 | #include "hw/isa.h" |
| 122 | #include "hw/baum.h" |
| 123 | #include "hw/bt.h" |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 124 | #include "hw/watchdog.h" |
aliguori | b6f6e3d | 2009-04-17 18:59:56 +0000 | [diff] [blame] | 125 | #include "hw/smbios.h" |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 126 | #include "hw/xen.h" |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 127 | #include "hw/qdev.h" |
Gerd Hoffmann | 45a50b1 | 2009-10-01 16:42:33 +0200 | [diff] [blame] | 128 | #include "hw/loader.h" |
aurel32 | 5ef4efa | 2009-03-10 21:43:35 +0000 | [diff] [blame] | 129 | #include "bt-host.h" |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 130 | #include "net.h" |
Mark McLoughlin | 68ac40d | 2009-11-25 18:48:54 +0000 | [diff] [blame] | 131 | #include "net/slirp.h" |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 132 | #include "monitor.h" |
| 133 | #include "console.h" |
| 134 | #include "sysemu.h" |
| 135 | #include "gdbstub.h" |
| 136 | #include "qemu-timer.h" |
| 137 | #include "qemu-char.h" |
| 138 | #include "cache-utils.h" |
| 139 | #include "block.h" |
Markus Armbruster | 666daa6 | 2010-06-02 18:48:27 +0200 | [diff] [blame] | 140 | #include "blockdev.h" |
lirans@il.ibm.com | c163b5c | 2009-11-02 15:40:58 +0200 | [diff] [blame] | 141 | #include "block-migration.h" |
blueswir1 | a718ace | 2009-03-28 08:24:44 +0000 | [diff] [blame] | 142 | #include "dma.h" |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 143 | #include "audio/audio.h" |
| 144 | #include "migration.h" |
| 145 | #include "kvm.h" |
Luiz Capitulino | f795e74 | 2011-10-21 16:05:43 -0200 | [diff] [blame] | 146 | #include "qjson.h" |
Kevin Wolf | d3f2436 | 2009-05-18 16:42:09 +0200 | [diff] [blame] | 147 | #include "qemu-option.h" |
Gerd Hoffmann | 7282a03 | 2009-07-31 12:25:35 +0200 | [diff] [blame] | 148 | #include "qemu-config.h" |
Jes Sorensen | 59a5264 | 2010-06-10 11:42:25 +0200 | [diff] [blame] | 149 | #include "qemu-options.h" |
Luiz Capitulino | 1fa9a5e | 2011-09-12 17:54:20 -0300 | [diff] [blame] | 150 | #include "qmp-commands.h" |
Paolo Bonzini | 44a9b35 | 2011-09-12 16:44:30 +0200 | [diff] [blame] | 151 | #include "main-loop.h" |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 152 | #ifdef CONFIG_VIRTFS |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 153 | #include "fsdev/qemu-fsdev.h" |
| 154 | #endif |
Anthony Liguori | c7f0f3b | 2012-03-28 15:42:02 +0200 | [diff] [blame] | 155 | #include "qtest.h" |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 156 | |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 157 | #include "disas.h" |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 158 | |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 159 | #include "qemu_socket.h" |
| 160 | |
Jan Kiszka | d918f23 | 2009-06-24 14:42:30 +0200 | [diff] [blame] | 161 | #include "slirp/libslirp.h" |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 162 | |
Stefan Hajnoczi | 94b0b5f | 2010-11-16 12:20:25 +0000 | [diff] [blame] | 163 | #include "trace.h" |
LluÃs | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 164 | #include "trace/control.h" |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 165 | #include "qemu-queue.h" |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 166 | #include "cpus.h" |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 167 | #include "arch_init.h" |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 168 | |
Gerd Hoffmann | 29b0040 | 2010-03-11 11:13:27 -0300 | [diff] [blame] | 169 | #include "ui/qemu-spice.h" |
| 170 | |
blueswir1 | 9dc63a1 | 2008-10-04 07:25:46 +0000 | [diff] [blame] | 171 | //#define DEBUG_NET |
| 172 | //#define DEBUG_SLIRP |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 173 | |
bellard | 1bfe856 | 2004-07-08 21:17:50 +0000 | [diff] [blame] | 174 | #define DEFAULT_RAM_SIZE 128 |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 175 | |
Amit Shah | 98b1925 | 2010-01-20 00:36:52 +0530 | [diff] [blame] | 176 | #define MAX_VIRTIO_CONSOLES 1 |
| 177 | |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 178 | static const char *data_dir; |
j_mayer | 1192dad | 2007-10-05 13:08:35 +0000 | [diff] [blame] | 179 | const char *bios_name = NULL; |
malc | cb5a7aa | 2008-09-28 00:42:12 +0000 | [diff] [blame] | 180 | enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 181 | DisplayType display_type = DT_DEFAULT; |
Gerd Hoffmann | 6b62dc2 | 2010-08-25 10:51:06 +0200 | [diff] [blame] | 182 | int display_remote = 0; |
bellard | 3d11d0e | 2004-12-12 16:56:30 +0000 | [diff] [blame] | 183 | const char* keyboard_layout = NULL; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 184 | ram_addr_t ram_size; |
Marcelo Tosatti | c902760 | 2010-03-01 20:25:08 -0300 | [diff] [blame] | 185 | const char *mem_path = NULL; |
| 186 | #ifdef MAP_POPULATE |
| 187 | int mem_prealloc = 0; /* force preallocation of physical target memory */ |
| 188 | #endif |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 189 | int nb_nics; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 190 | NICInfo nd_table[MAX_NICS]; |
Paolo Bonzini | d399f67 | 2009-07-27 23:17:51 +0200 | [diff] [blame] | 191 | int autostart; |
balrog | f650305 | 2008-02-17 11:42:19 +0000 | [diff] [blame] | 192 | static int rtc_utc = 1; |
| 193 | static int rtc_date_offset = -1; /* -1 means no change */ |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 194 | QEMUClock *rtc_clock; |
Gerd Hoffmann | 6446529 | 2009-12-08 13:11:45 +0100 | [diff] [blame] | 195 | int vga_interface_type = VGA_NONE; |
blueswir1 | dbed7e4 | 2008-10-01 19:38:09 +0000 | [diff] [blame] | 196 | static int full_screen = 0; |
blueswir1 | 634a21f | 2008-11-16 11:34:07 +0000 | [diff] [blame] | 197 | #ifdef CONFIG_SDL |
blueswir1 | dbed7e4 | 2008-10-01 19:38:09 +0000 | [diff] [blame] | 198 | static int no_frame = 0; |
blueswir1 | 634a21f | 2008-11-16 11:34:07 +0000 | [diff] [blame] | 199 | #endif |
ths | 667acca | 2006-12-11 02:08:05 +0000 | [diff] [blame] | 200 | int no_quit = 0; |
bellard | 8d11df9 | 2004-08-24 21:13:40 +0000 | [diff] [blame] | 201 | CharDriverState *serial_hds[MAX_SERIAL_PORTS]; |
bellard | 6508fe5 | 2005-01-15 12:02:56 +0000 | [diff] [blame] | 202 | CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; |
aliguori | 9ede2fd | 2009-01-15 20:05:25 +0000 | [diff] [blame] | 203 | CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES]; |
bellard | a09db21 | 2005-04-30 16:10:35 +0000 | [diff] [blame] | 204 | int win2k_install_hack = 0; |
bellard | bb36d47 | 2005-11-05 14:22:28 +0000 | [diff] [blame] | 205 | int usb_enabled = 0; |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 206 | int singlestep = 0; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 207 | int smp_cpus = 1; |
Jes Sorensen | 6be68d7 | 2009-07-23 17:03:42 +0200 | [diff] [blame] | 208 | int max_cpus = 0; |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 209 | int smp_cores = 1; |
| 210 | int smp_threads = 1; |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 211 | #ifdef CONFIG_VNC |
ths | 73fc974 | 2006-12-22 02:09:07 +0000 | [diff] [blame] | 212 | const char *vnc_display; |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 213 | #endif |
bellard | 6515b20 | 2006-05-03 22:02:44 +0000 | [diff] [blame] | 214 | int acpi_enabled = 1; |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 215 | int no_hpet = 0; |
bellard | 52ca8d6 | 2006-06-14 16:03:05 +0000 | [diff] [blame] | 216 | int fd_bootchk = 1; |
bellard | d1beab8 | 2006-10-02 19:44:22 +0000 | [diff] [blame] | 217 | int no_reboot = 0; |
aurel32 | b2f7616 | 2008-04-11 21:35:52 +0000 | [diff] [blame] | 218 | int no_shutdown = 0; |
balrog | 9467cd4 | 2007-05-01 01:34:14 +0000 | [diff] [blame] | 219 | int cursor_hide = 1; |
balrog | a171fe3 | 2007-04-30 01:48:07 +0000 | [diff] [blame] | 220 | int graphic_rotate = 0; |
Markus Armbruster | 09aaa16 | 2009-08-21 10:31:34 +0200 | [diff] [blame] | 221 | const char *watchdog; |
Gleb Natapov | 2e55e84 | 2010-12-08 13:35:07 +0200 | [diff] [blame] | 222 | QEMUOptionRom option_rom[MAX_OPTION_ROMS]; |
ths | 9ae0255 | 2007-01-05 17:39:04 +0000 | [diff] [blame] | 223 | int nb_option_roms; |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 224 | int semihosting_enabled = 0; |
balrog | 2b8f2d4 | 2007-07-27 22:08:46 +0000 | [diff] [blame] | 225 | int old_param = 0; |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 226 | const char *qemu_name; |
ths | 3780e19 | 2007-06-21 21:08:02 +0000 | [diff] [blame] | 227 | int alt_grab = 0; |
Dustin Kirkland | 0ca9f8a | 2009-09-17 15:48:04 -0500 | [diff] [blame] | 228 | int ctrl_grab = 0; |
blueswir1 | 6650860 | 2007-05-01 14:16:52 +0000 | [diff] [blame] | 229 | unsigned int nb_prom_envs = 0; |
| 230 | const char *prom_envs[MAX_PROM_ENVS]; |
Jan Kiszka | 9538749 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 231 | int boot_menu; |
wayne | 3d3b830 | 2011-07-27 18:04:55 +0800 | [diff] [blame] | 232 | uint8_t *boot_splash_filedata; |
| 233 | int boot_splash_filedata_size; |
| 234 | uint8_t qemu_extra_params_fw[2]; |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 235 | |
Gleb Natapov | 1ca4d09 | 2010-12-08 13:35:05 +0200 | [diff] [blame] | 236 | typedef struct FWBootEntry FWBootEntry; |
| 237 | |
| 238 | struct FWBootEntry { |
| 239 | QTAILQ_ENTRY(FWBootEntry) link; |
| 240 | int32_t bootindex; |
| 241 | DeviceState *dev; |
| 242 | char *suffix; |
| 243 | }; |
| 244 | |
| 245 | QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order); |
| 246 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 247 | int nb_numa_nodes; |
| 248 | uint64_t node_mem[MAX_NODES]; |
| 249 | uint64_t node_cpumask[MAX_NODES]; |
| 250 | |
blueswir1 | 8fcb1b9 | 2008-09-18 18:29:08 +0000 | [diff] [blame] | 251 | uint8_t qemu_uuid[16]; |
| 252 | |
Jan Kiszka | 76e30d0 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 253 | static QEMUBootSetHandler *boot_set_handler; |
| 254 | static void *boot_set_opaque; |
| 255 | |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame] | 256 | static NotifierList exit_notifiers = |
| 257 | NOTIFIER_LIST_INITIALIZER(exit_notifiers); |
| 258 | |
Gleb Natapov | 4cab946 | 2010-12-08 13:35:08 +0200 | [diff] [blame] | 259 | static NotifierList machine_init_done_notifiers = |
| 260 | NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers); |
| 261 | |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 262 | static int tcg_allowed = 1; |
Blue Swirl | d745bef | 2010-03-29 19:23:49 +0000 | [diff] [blame] | 263 | int kvm_allowed = 0; |
Anthony PERARD | 3285cf4 | 2010-08-19 12:27:56 +0100 | [diff] [blame] | 264 | int xen_allowed = 0; |
Blue Swirl | d745bef | 2010-03-29 19:23:49 +0000 | [diff] [blame] | 265 | uint32_t xen_domid; |
| 266 | enum xen_mode xen_mode = XEN_EMULATE; |
Jan Kiszka | d5ab971 | 2011-08-02 16:10:21 +0200 | [diff] [blame] | 267 | static int tcg_tb_size; |
Blue Swirl | d745bef | 2010-03-29 19:23:49 +0000 | [diff] [blame] | 268 | |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 269 | static int default_serial = 1; |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 270 | static int default_parallel = 1; |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 271 | static int default_virtcon = 1; |
Gerd Hoffmann | abdeed0 | 2009-12-08 13:11:43 +0100 | [diff] [blame] | 272 | static int default_monitor = 1; |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 273 | static int default_floppy = 1; |
| 274 | static int default_cdrom = 1; |
| 275 | static int default_sdcard = 1; |
Paolo Bonzini | 7f1b17f | 2012-05-10 09:39:17 +0200 | [diff] [blame] | 276 | static int default_vga = 1; |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 277 | |
| 278 | static struct { |
| 279 | const char *driver; |
| 280 | int *flag; |
| 281 | } default_list[] = { |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 282 | { .driver = "isa-serial", .flag = &default_serial }, |
| 283 | { .driver = "isa-parallel", .flag = &default_parallel }, |
Gerd Hoffmann | d8bcbab | 2009-12-16 14:25:40 +0100 | [diff] [blame] | 284 | { .driver = "isa-fdc", .flag = &default_floppy }, |
Markus Armbruster | af6bf13 | 2011-05-18 18:31:02 +0200 | [diff] [blame] | 285 | { .driver = "ide-cd", .flag = &default_cdrom }, |
| 286 | { .driver = "ide-hd", .flag = &default_cdrom }, |
Gerd Hoffmann | d8bcbab | 2009-12-16 14:25:40 +0100 | [diff] [blame] | 287 | { .driver = "ide-drive", .flag = &default_cdrom }, |
Markus Armbruster | af6bf13 | 2011-05-18 18:31:02 +0200 | [diff] [blame] | 288 | { .driver = "scsi-cd", .flag = &default_cdrom }, |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 289 | { .driver = "virtio-serial-pci", .flag = &default_virtcon }, |
| 290 | { .driver = "virtio-serial-s390", .flag = &default_virtcon }, |
| 291 | { .driver = "virtio-serial", .flag = &default_virtcon }, |
Paolo Bonzini | 7f1b17f | 2012-05-10 09:39:17 +0200 | [diff] [blame] | 292 | { .driver = "VGA", .flag = &default_vga }, |
| 293 | { .driver = "isa-vga", .flag = &default_vga }, |
| 294 | { .driver = "cirrus-vga", .flag = &default_vga }, |
| 295 | { .driver = "isa-cirrus-vga", .flag = &default_vga }, |
| 296 | { .driver = "vmware-svga", .flag = &default_vga }, |
| 297 | { .driver = "qxl-vga", .flag = &default_vga }, |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 298 | }; |
| 299 | |
wayne | 3d3b830 | 2011-07-27 18:04:55 +0800 | [diff] [blame] | 300 | static void res_free(void) |
| 301 | { |
| 302 | if (boot_splash_filedata != NULL) { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 303 | g_free(boot_splash_filedata); |
wayne | 3d3b830 | 2011-07-27 18:04:55 +0800 | [diff] [blame] | 304 | boot_splash_filedata = NULL; |
| 305 | } |
| 306 | } |
| 307 | |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 308 | static int default_driver_check(QemuOpts *opts, void *opaque) |
| 309 | { |
| 310 | const char *driver = qemu_opt_get(opts, "driver"); |
| 311 | int i; |
| 312 | |
| 313 | if (!driver) |
| 314 | return 0; |
| 315 | for (i = 0; i < ARRAY_SIZE(default_list); i++) { |
| 316 | if (strcmp(default_list[i].driver, driver) != 0) |
| 317 | continue; |
| 318 | *(default_list[i].flag) = 0; |
| 319 | } |
| 320 | return 0; |
| 321 | } |
| 322 | |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 323 | /***********************************************************/ |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 324 | /* QEMU state */ |
| 325 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 326 | static RunState current_run_state = RUN_STATE_PRELAUNCH; |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 327 | |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 328 | typedef struct { |
| 329 | RunState from; |
| 330 | RunState to; |
| 331 | } RunStateTransition; |
| 332 | |
| 333 | static const RunStateTransition runstate_transitions_def[] = { |
| 334 | /* from -> to */ |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 335 | { RUN_STATE_DEBUG, RUN_STATE_RUNNING }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 336 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 337 | { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING }, |
| 338 | { RUN_STATE_INMIGRATE, RUN_STATE_PRELAUNCH }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 339 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 340 | { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED }, |
Luiz Capitulino | 8a9236f | 2011-10-14 11:18:09 -0300 | [diff] [blame] | 341 | { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 342 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 343 | { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING }, |
Luiz Capitulino | 8a9236f | 2011-10-14 11:18:09 -0300 | [diff] [blame] | 344 | { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 345 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 346 | { RUN_STATE_PAUSED, RUN_STATE_RUNNING }, |
Luiz Capitulino | 8a9236f | 2011-10-14 11:18:09 -0300 | [diff] [blame] | 347 | { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 348 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 349 | { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING }, |
Luiz Capitulino | 8a9236f | 2011-10-14 11:18:09 -0300 | [diff] [blame] | 350 | { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 351 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 352 | { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING }, |
Luiz Capitulino | 8a9236f | 2011-10-14 11:18:09 -0300 | [diff] [blame] | 353 | { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE }, |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 354 | { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 355 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 356 | { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING }, |
| 357 | { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 358 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 359 | { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 360 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 361 | { RUN_STATE_RUNNING, RUN_STATE_DEBUG }, |
| 362 | { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR }, |
| 363 | { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR }, |
| 364 | { RUN_STATE_RUNNING, RUN_STATE_PAUSED }, |
| 365 | { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE }, |
| 366 | { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM }, |
| 367 | { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM }, |
| 368 | { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN }, |
| 369 | { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 370 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 371 | { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 372 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 373 | { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED }, |
Luiz Capitulino | 8a9236f | 2011-10-14 11:18:09 -0300 | [diff] [blame] | 374 | { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 375 | |
Luiz Capitulino | ad02b96 | 2012-04-27 13:33:36 -0300 | [diff] [blame] | 376 | { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED }, |
| 377 | { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED }, |
| 378 | { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING }, |
| 379 | { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE }, |
| 380 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 381 | { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING }, |
Luiz Capitulino | 8a9236f | 2011-10-14 11:18:09 -0300 | [diff] [blame] | 382 | { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 383 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 384 | { RUN_STATE_MAX, RUN_STATE_MAX }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 385 | }; |
| 386 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 387 | static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX]; |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 388 | |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 389 | bool runstate_check(RunState state) |
| 390 | { |
| 391 | return current_run_state == state; |
| 392 | } |
| 393 | |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 394 | void runstate_init(void) |
| 395 | { |
| 396 | const RunStateTransition *p; |
| 397 | |
| 398 | memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions)); |
| 399 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 400 | for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) { |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 401 | runstate_valid_transitions[p->from][p->to] = true; |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | /* This function will abort() on invalid state transitions */ |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 406 | void runstate_set(RunState new_state) |
| 407 | { |
Luiz Capitulino | 207c5cd | 2011-10-13 10:59:07 -0300 | [diff] [blame] | 408 | assert(new_state < RUN_STATE_MAX); |
| 409 | |
| 410 | if (!runstate_valid_transitions[current_run_state][new_state]) { |
| 411 | fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n", |
| 412 | RunState_lookup[current_run_state], |
| 413 | RunState_lookup[new_state]); |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 414 | abort(); |
| 415 | } |
| 416 | |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 417 | current_run_state = new_state; |
| 418 | } |
| 419 | |
Luiz Capitulino | 1354869 | 2011-07-29 15:36:43 -0300 | [diff] [blame] | 420 | int runstate_is_running(void) |
| 421 | { |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 422 | return runstate_check(RUN_STATE_RUNNING); |
Luiz Capitulino | 1354869 | 2011-07-29 15:36:43 -0300 | [diff] [blame] | 423 | } |
| 424 | |
Luiz Capitulino | 1fa9a5e | 2011-09-12 17:54:20 -0300 | [diff] [blame] | 425 | StatusInfo *qmp_query_status(Error **errp) |
| 426 | { |
| 427 | StatusInfo *info = g_malloc0(sizeof(*info)); |
| 428 | |
| 429 | info->running = runstate_is_running(); |
| 430 | info->singlestep = singlestep; |
| 431 | info->status = current_run_state; |
| 432 | |
| 433 | return info; |
| 434 | } |
| 435 | |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 436 | /***********************************************************/ |
Paolo Bonzini | 8f0056b | 2010-01-13 14:05:34 +0100 | [diff] [blame] | 437 | /* real time host monotonic timer */ |
bellard | 09b26c5 | 2006-04-12 21:09:08 +0000 | [diff] [blame] | 438 | |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 439 | /***********************************************************/ |
balrog | f650305 | 2008-02-17 11:42:19 +0000 | [diff] [blame] | 440 | /* host time/date access */ |
| 441 | void qemu_get_timedate(struct tm *tm, int offset) |
| 442 | { |
| 443 | time_t ti; |
| 444 | struct tm *ret; |
| 445 | |
| 446 | time(&ti); |
| 447 | ti += offset; |
| 448 | if (rtc_date_offset == -1) { |
| 449 | if (rtc_utc) |
| 450 | ret = gmtime(&ti); |
| 451 | else |
| 452 | ret = localtime(&ti); |
| 453 | } else { |
| 454 | ti -= rtc_date_offset; |
| 455 | ret = gmtime(&ti); |
| 456 | } |
| 457 | |
| 458 | memcpy(tm, ret, sizeof(struct tm)); |
| 459 | } |
| 460 | |
| 461 | int qemu_timedate_diff(struct tm *tm) |
| 462 | { |
| 463 | time_t seconds; |
| 464 | |
| 465 | if (rtc_date_offset == -1) |
| 466 | if (rtc_utc) |
| 467 | seconds = mktimegm(tm); |
Gleb Natapov | f54c556 | 2011-11-06 18:00:22 +0200 | [diff] [blame] | 468 | else { |
| 469 | struct tm tmp = *tm; |
| 470 | tmp.tm_isdst = -1; /* use timezone to figure it out */ |
| 471 | seconds = mktime(&tmp); |
| 472 | } |
balrog | f650305 | 2008-02-17 11:42:19 +0000 | [diff] [blame] | 473 | else |
| 474 | seconds = mktimegm(tm) + rtc_date_offset; |
| 475 | |
| 476 | return seconds - time(NULL); |
| 477 | } |
| 478 | |
Luiz Capitulino | 80cd347 | 2010-02-25 12:11:44 -0300 | [diff] [blame] | 479 | void rtc_change_mon_event(struct tm *tm) |
| 480 | { |
| 481 | QObject *data; |
| 482 | |
| 483 | data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm)); |
| 484 | monitor_protocol_event(QEVENT_RTC_CHANGE, data); |
| 485 | qobject_decref(data); |
| 486 | } |
| 487 | |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 488 | static void configure_rtc_date_offset(const char *startdate, int legacy) |
| 489 | { |
| 490 | time_t rtc_start_date; |
| 491 | struct tm tm; |
| 492 | |
| 493 | if (!strcmp(startdate, "now") && legacy) { |
| 494 | rtc_date_offset = -1; |
| 495 | } else { |
| 496 | if (sscanf(startdate, "%d-%d-%dT%d:%d:%d", |
| 497 | &tm.tm_year, |
| 498 | &tm.tm_mon, |
| 499 | &tm.tm_mday, |
| 500 | &tm.tm_hour, |
| 501 | &tm.tm_min, |
| 502 | &tm.tm_sec) == 6) { |
| 503 | /* OK */ |
| 504 | } else if (sscanf(startdate, "%d-%d-%d", |
| 505 | &tm.tm_year, |
| 506 | &tm.tm_mon, |
| 507 | &tm.tm_mday) == 3) { |
| 508 | tm.tm_hour = 0; |
| 509 | tm.tm_min = 0; |
| 510 | tm.tm_sec = 0; |
| 511 | } else { |
| 512 | goto date_fail; |
| 513 | } |
| 514 | tm.tm_year -= 1900; |
| 515 | tm.tm_mon--; |
| 516 | rtc_start_date = mktimegm(&tm); |
| 517 | if (rtc_start_date == -1) { |
| 518 | date_fail: |
| 519 | fprintf(stderr, "Invalid date format. Valid formats are:\n" |
| 520 | "'2006-06-17T16:01:21' or '2006-06-17'\n"); |
| 521 | exit(1); |
| 522 | } |
| 523 | rtc_date_offset = time(NULL) - rtc_start_date; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | static void configure_rtc(QemuOpts *opts) |
| 528 | { |
| 529 | const char *value; |
| 530 | |
| 531 | value = qemu_opt_get(opts, "base"); |
| 532 | if (value) { |
| 533 | if (!strcmp(value, "utc")) { |
| 534 | rtc_utc = 1; |
| 535 | } else if (!strcmp(value, "localtime")) { |
| 536 | rtc_utc = 0; |
| 537 | } else { |
| 538 | configure_rtc_date_offset(value, 0); |
| 539 | } |
| 540 | } |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 541 | value = qemu_opt_get(opts, "clock"); |
| 542 | if (value) { |
| 543 | if (!strcmp(value, "host")) { |
| 544 | rtc_clock = host_clock; |
Paolo Bonzini | 7880814 | 2012-03-30 10:31:21 +0000 | [diff] [blame] | 545 | } else if (!strcmp(value, "rt")) { |
| 546 | rtc_clock = rt_clock; |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 547 | } else if (!strcmp(value, "vm")) { |
| 548 | rtc_clock = vm_clock; |
| 549 | } else { |
| 550 | fprintf(stderr, "qemu: invalid option value '%s'\n", value); |
| 551 | exit(1); |
| 552 | } |
| 553 | } |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 554 | value = qemu_opt_get(opts, "driftfix"); |
| 555 | if (value) { |
Blue Swirl | 7e4c033 | 2010-03-27 21:33:46 +0000 | [diff] [blame] | 556 | if (!strcmp(value, "slew")) { |
Jan Kiszka | 433acf0 | 2012-01-23 20:15:12 +0100 | [diff] [blame] | 557 | static GlobalProperty slew_lost_ticks[] = { |
| 558 | { |
| 559 | .driver = "mc146818rtc", |
| 560 | .property = "lost_tick_policy", |
| 561 | .value = "slew", |
| 562 | }, |
| 563 | { /* end of list */ } |
| 564 | }; |
| 565 | |
| 566 | qdev_prop_register_global_list(slew_lost_ticks); |
Blue Swirl | 7e4c033 | 2010-03-27 21:33:46 +0000 | [diff] [blame] | 567 | } else if (!strcmp(value, "none")) { |
Jan Kiszka | 433acf0 | 2012-01-23 20:15:12 +0100 | [diff] [blame] | 568 | /* discard is default */ |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 569 | } else { |
| 570 | fprintf(stderr, "qemu: invalid option value '%s'\n", value); |
| 571 | exit(1); |
| 572 | } |
| 573 | } |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 574 | } |
| 575 | |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 576 | /***********************************************************/ |
| 577 | /* Bluetooth support */ |
| 578 | static int nb_hcis; |
| 579 | static int cur_hci; |
| 580 | static struct HCIInfo *hci_table[MAX_NICS]; |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 581 | |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 582 | static struct bt_vlan_s { |
| 583 | struct bt_scatternet_s net; |
| 584 | int id; |
| 585 | struct bt_vlan_s *next; |
| 586 | } *first_bt_vlan; |
| 587 | |
| 588 | /* find or alloc a new bluetooth "VLAN" */ |
blueswir1 | 674bb26 | 2008-09-30 18:18:27 +0000 | [diff] [blame] | 589 | static struct bt_scatternet_s *qemu_find_bt_vlan(int id) |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 590 | { |
| 591 | struct bt_vlan_s **pvlan, *vlan; |
| 592 | for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) { |
| 593 | if (vlan->id == id) |
| 594 | return &vlan->net; |
| 595 | } |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 596 | vlan = g_malloc0(sizeof(struct bt_vlan_s)); |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 597 | vlan->id = id; |
| 598 | pvlan = &first_bt_vlan; |
| 599 | while (*pvlan != NULL) |
| 600 | pvlan = &(*pvlan)->next; |
| 601 | *pvlan = vlan; |
| 602 | return &vlan->net; |
| 603 | } |
| 604 | |
| 605 | static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len) |
| 606 | { |
| 607 | } |
| 608 | |
| 609 | static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr) |
| 610 | { |
| 611 | return -ENOTSUP; |
| 612 | } |
| 613 | |
| 614 | static struct HCIInfo null_hci = { |
| 615 | .cmd_send = null_hci_send, |
| 616 | .sco_send = null_hci_send, |
| 617 | .acl_send = null_hci_send, |
| 618 | .bdaddr_set = null_hci_addr_set, |
| 619 | }; |
| 620 | |
| 621 | struct HCIInfo *qemu_next_hci(void) |
| 622 | { |
| 623 | if (cur_hci == nb_hcis) |
| 624 | return &null_hci; |
| 625 | |
| 626 | return hci_table[cur_hci++]; |
| 627 | } |
| 628 | |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 629 | static struct HCIInfo *hci_init(const char *str) |
| 630 | { |
| 631 | char *endp; |
| 632 | struct bt_scatternet_s *vlan = 0; |
| 633 | |
| 634 | if (!strcmp(str, "null")) |
| 635 | /* null */ |
| 636 | return &null_hci; |
| 637 | else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':')) |
| 638 | /* host[:hciN] */ |
| 639 | return bt_host_hci(str[4] ? str + 5 : "hci0"); |
| 640 | else if (!strncmp(str, "hci", 3)) { |
| 641 | /* hci[,vlan=n] */ |
| 642 | if (str[3]) { |
| 643 | if (!strncmp(str + 3, ",vlan=", 6)) { |
| 644 | vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0)); |
| 645 | if (*endp) |
| 646 | vlan = 0; |
| 647 | } |
| 648 | } else |
| 649 | vlan = qemu_find_bt_vlan(0); |
| 650 | if (vlan) |
| 651 | return bt_new_hci(vlan); |
| 652 | } |
| 653 | |
| 654 | fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str); |
| 655 | |
| 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | static int bt_hci_parse(const char *str) |
| 660 | { |
| 661 | struct HCIInfo *hci; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 662 | bdaddr_t bdaddr; |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 663 | |
| 664 | if (nb_hcis >= MAX_NICS) { |
| 665 | fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS); |
| 666 | return -1; |
| 667 | } |
| 668 | |
| 669 | hci = hci_init(str); |
| 670 | if (!hci) |
| 671 | return -1; |
| 672 | |
| 673 | bdaddr.b[0] = 0x52; |
| 674 | bdaddr.b[1] = 0x54; |
| 675 | bdaddr.b[2] = 0x00; |
| 676 | bdaddr.b[3] = 0x12; |
| 677 | bdaddr.b[4] = 0x34; |
| 678 | bdaddr.b[5] = 0x56 + nb_hcis; |
| 679 | hci->bdaddr_set(hci, bdaddr.b); |
| 680 | |
| 681 | hci_table[nb_hcis++] = hci; |
| 682 | |
| 683 | return 0; |
| 684 | } |
| 685 | |
| 686 | static void bt_vhci_add(int vlan_id) |
| 687 | { |
| 688 | struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id); |
| 689 | |
| 690 | if (!vlan->slave) |
| 691 | fprintf(stderr, "qemu: warning: adding a VHCI to " |
| 692 | "an empty scatternet %i\n", vlan_id); |
| 693 | |
| 694 | bt_vhci_init(bt_new_hci(vlan)); |
| 695 | } |
| 696 | |
| 697 | static struct bt_device_s *bt_device_add(const char *opt) |
| 698 | { |
| 699 | struct bt_scatternet_s *vlan; |
| 700 | int vlan_id = 0; |
| 701 | char *endp = strstr(opt, ",vlan="); |
| 702 | int len = (endp ? endp - opt : strlen(opt)) + 1; |
| 703 | char devname[10]; |
| 704 | |
| 705 | pstrcpy(devname, MIN(sizeof(devname), len), opt); |
| 706 | |
| 707 | if (endp) { |
| 708 | vlan_id = strtol(endp + 6, &endp, 0); |
| 709 | if (*endp) { |
| 710 | fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n"); |
| 711 | return 0; |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | vlan = qemu_find_bt_vlan(vlan_id); |
| 716 | |
| 717 | if (!vlan->slave) |
| 718 | fprintf(stderr, "qemu: warning: adding a slave device to " |
| 719 | "an empty scatternet %i\n", vlan_id); |
| 720 | |
| 721 | if (!strcmp(devname, "keyboard")) |
| 722 | return bt_keyboard_init(vlan); |
| 723 | |
| 724 | fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname); |
| 725 | return 0; |
| 726 | } |
| 727 | |
| 728 | static int bt_parse(const char *opt) |
| 729 | { |
| 730 | const char *endp, *p; |
| 731 | int vlan; |
| 732 | |
| 733 | if (strstart(opt, "hci", &endp)) { |
| 734 | if (!*endp || *endp == ',') { |
| 735 | if (*endp) |
| 736 | if (!strstart(endp, ",vlan=", 0)) |
| 737 | opt = endp + 1; |
| 738 | |
| 739 | return bt_hci_parse(opt); |
| 740 | } |
| 741 | } else if (strstart(opt, "vhci", &endp)) { |
| 742 | if (!*endp || *endp == ',') { |
| 743 | if (*endp) { |
| 744 | if (strstart(endp, ",vlan=", &p)) { |
| 745 | vlan = strtol(p, (char **) &endp, 0); |
| 746 | if (*endp) { |
| 747 | fprintf(stderr, "qemu: bad scatternet '%s'\n", p); |
| 748 | return 1; |
| 749 | } |
| 750 | } else { |
| 751 | fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1); |
| 752 | return 1; |
| 753 | } |
| 754 | } else |
| 755 | vlan = 0; |
| 756 | |
| 757 | bt_vhci_add(vlan); |
| 758 | return 0; |
| 759 | } |
| 760 | } else if (strstart(opt, "device:", &endp)) |
| 761 | return !bt_device_add(endp); |
| 762 | |
| 763 | fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt); |
| 764 | return 1; |
| 765 | } |
| 766 | |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 767 | /***********************************************************/ |
| 768 | /* QEMU Block devices */ |
| 769 | |
Markus Armbruster | 2292dda | 2011-01-28 11:21:41 +0100 | [diff] [blame] | 770 | #define HD_OPTS "media=disk" |
| 771 | #define CDROM_OPTS "media=cdrom" |
| 772 | #define FD_OPTS "" |
| 773 | #define PFLASH_OPTS "" |
| 774 | #define MTD_OPTS "" |
| 775 | #define SD_OPTS "" |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 776 | |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 777 | static int drive_init_func(QemuOpts *opts, void *opaque) |
| 778 | { |
Markus Armbruster | a803cb8 | 2010-06-02 13:31:55 +0200 | [diff] [blame] | 779 | int *use_scsi = opaque; |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 780 | |
Markus Armbruster | 319ae52 | 2011-01-28 11:21:46 +0100 | [diff] [blame] | 781 | return drive_init(opts, *use_scsi) == NULL; |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | static int drive_enable_snapshot(QemuOpts *opts, void *opaque) |
| 785 | { |
| 786 | if (NULL == qemu_opt_get(opts, "snapshot")) { |
| 787 | qemu_opt_set(opts, "snapshot", "on"); |
| 788 | } |
| 789 | return 0; |
| 790 | } |
| 791 | |
Markus Armbruster | 4e5d9b5 | 2011-01-28 11:21:45 +0100 | [diff] [blame] | 792 | static void default_drive(int enable, int snapshot, int use_scsi, |
| 793 | BlockInterfaceType type, int index, |
| 794 | const char *optstr) |
| 795 | { |
| 796 | QemuOpts *opts; |
| 797 | |
| 798 | if (type == IF_DEFAULT) { |
| 799 | type = use_scsi ? IF_SCSI : IF_IDE; |
| 800 | } |
| 801 | |
| 802 | if (!enable || drive_get_by_index(type, index)) { |
| 803 | return; |
| 804 | } |
| 805 | |
| 806 | opts = drive_add(type, index, NULL, optstr); |
| 807 | if (snapshot) { |
| 808 | drive_enable_snapshot(opts, NULL); |
| 809 | } |
Markus Armbruster | 319ae52 | 2011-01-28 11:21:46 +0100 | [diff] [blame] | 810 | if (!drive_init(opts, use_scsi)) { |
Markus Armbruster | 4e5d9b5 | 2011-01-28 11:21:45 +0100 | [diff] [blame] | 811 | exit(1); |
| 812 | } |
| 813 | } |
| 814 | |
Jan Kiszka | 76e30d0 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 815 | void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque) |
| 816 | { |
| 817 | boot_set_handler = func; |
| 818 | boot_set_opaque = opaque; |
| 819 | } |
| 820 | |
| 821 | int qemu_boot_set(const char *boot_devices) |
| 822 | { |
| 823 | if (!boot_set_handler) { |
| 824 | return -EINVAL; |
| 825 | } |
| 826 | return boot_set_handler(boot_set_opaque, boot_devices); |
| 827 | } |
| 828 | |
Eduardo Habkost | 4e9e9d6 | 2010-04-06 19:22:08 -0300 | [diff] [blame] | 829 | static void validate_bootdevices(char *devices) |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 830 | { |
| 831 | /* We just do some generic consistency checks */ |
| 832 | const char *p; |
| 833 | int bitmap = 0; |
| 834 | |
| 835 | for (p = devices; *p != '\0'; p++) { |
| 836 | /* Allowed boot devices are: |
| 837 | * a-b: floppy disk drives |
| 838 | * c-f: IDE disk drives |
Dong Xu Wang | 07f3507 | 2011-11-22 18:06:26 +0800 | [diff] [blame] | 839 | * g-m: machine implementation dependent drives |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 840 | * n-p: network devices |
| 841 | * It's up to each machine implementation to check if the given boot |
| 842 | * devices match the actual hardware implementation and firmware |
| 843 | * features. |
| 844 | */ |
| 845 | if (*p < 'a' || *p > 'p') { |
| 846 | fprintf(stderr, "Invalid boot device '%c'\n", *p); |
| 847 | exit(1); |
| 848 | } |
| 849 | if (bitmap & (1 << (*p - 'a'))) { |
| 850 | fprintf(stderr, "Boot device '%c' was given twice\n", *p); |
| 851 | exit(1); |
| 852 | } |
| 853 | bitmap |= 1 << (*p - 'a'); |
| 854 | } |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 855 | } |
| 856 | |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 857 | static void restore_boot_devices(void *opaque) |
| 858 | { |
| 859 | char *standard_boot_devices = opaque; |
Alex Williamson | 37905d6 | 2010-04-30 15:21:11 -0600 | [diff] [blame] | 860 | static int first = 1; |
| 861 | |
| 862 | /* Restore boot order and remove ourselves after the first boot */ |
| 863 | if (first) { |
| 864 | first = 0; |
| 865 | return; |
| 866 | } |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 867 | |
| 868 | qemu_boot_set(standard_boot_devices); |
| 869 | |
| 870 | qemu_unregister_reset(restore_boot_devices, standard_boot_devices); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 871 | g_free(standard_boot_devices); |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 872 | } |
| 873 | |
Gleb Natapov | 1ca4d09 | 2010-12-08 13:35:05 +0200 | [diff] [blame] | 874 | void add_boot_device_path(int32_t bootindex, DeviceState *dev, |
| 875 | const char *suffix) |
| 876 | { |
| 877 | FWBootEntry *node, *i; |
| 878 | |
| 879 | if (bootindex < 0) { |
| 880 | return; |
| 881 | } |
| 882 | |
| 883 | assert(dev != NULL || suffix != NULL); |
| 884 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 885 | node = g_malloc0(sizeof(FWBootEntry)); |
Gleb Natapov | 1ca4d09 | 2010-12-08 13:35:05 +0200 | [diff] [blame] | 886 | node->bootindex = bootindex; |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 887 | node->suffix = suffix ? g_strdup(suffix) : NULL; |
Gleb Natapov | 1ca4d09 | 2010-12-08 13:35:05 +0200 | [diff] [blame] | 888 | node->dev = dev; |
| 889 | |
| 890 | QTAILQ_FOREACH(i, &fw_boot_order, link) { |
| 891 | if (i->bootindex == bootindex) { |
| 892 | fprintf(stderr, "Two devices with same boot index %d\n", bootindex); |
| 893 | exit(1); |
| 894 | } else if (i->bootindex < bootindex) { |
| 895 | continue; |
| 896 | } |
| 897 | QTAILQ_INSERT_BEFORE(i, node, link); |
| 898 | return; |
| 899 | } |
| 900 | QTAILQ_INSERT_TAIL(&fw_boot_order, node, link); |
| 901 | } |
| 902 | |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 903 | /* |
| 904 | * This function returns null terminated string that consist of new line |
Brad Hards | 71785ab | 2011-04-23 21:50:06 +1000 | [diff] [blame] | 905 | * separated device paths. |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 906 | * |
| 907 | * memory pointed by "size" is assigned total length of the array in bytes |
| 908 | * |
| 909 | */ |
| 910 | char *get_boot_devices_list(uint32_t *size) |
| 911 | { |
| 912 | FWBootEntry *i; |
| 913 | uint32_t total = 0; |
| 914 | char *list = NULL; |
| 915 | |
| 916 | QTAILQ_FOREACH(i, &fw_boot_order, link) { |
| 917 | char *devpath = NULL, *bootpath; |
| 918 | int len; |
| 919 | |
| 920 | if (i->dev) { |
| 921 | devpath = qdev_get_fw_dev_path(i->dev); |
| 922 | assert(devpath); |
| 923 | } |
| 924 | |
| 925 | if (i->suffix && devpath) { |
Blue Swirl | 4fd37a9 | 2010-12-19 14:05:43 +0000 | [diff] [blame] | 926 | size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1; |
| 927 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 928 | bootpath = g_malloc(bootpathlen); |
Blue Swirl | 4fd37a9 | 2010-12-19 14:05:43 +0000 | [diff] [blame] | 929 | snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 930 | g_free(devpath); |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 931 | } else if (devpath) { |
| 932 | bootpath = devpath; |
| 933 | } else { |
Markus Armbruster | 1bf6ccd | 2011-11-08 10:58:00 +0100 | [diff] [blame] | 934 | assert(i->suffix); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 935 | bootpath = g_strdup(i->suffix); |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | if (total) { |
| 939 | list[total-1] = '\n'; |
| 940 | } |
| 941 | len = strlen(bootpath) + 1; |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 942 | list = g_realloc(list, total + len); |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 943 | memcpy(&list[total], bootpath, len); |
| 944 | total += len; |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 945 | g_free(bootpath); |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | *size = total; |
| 949 | |
| 950 | return list; |
| 951 | } |
| 952 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 953 | static void numa_add(const char *optarg) |
| 954 | { |
| 955 | char option[128]; |
| 956 | char *endptr; |
| 957 | unsigned long long value, endvalue; |
| 958 | int nodenr; |
| 959 | |
| 960 | optarg = get_opt_name(option, 128, optarg, ',') + 1; |
| 961 | if (!strcmp(option, "node")) { |
| 962 | if (get_param_value(option, 128, "nodeid", optarg) == 0) { |
| 963 | nodenr = nb_numa_nodes; |
| 964 | } else { |
| 965 | nodenr = strtoull(option, NULL, 10); |
| 966 | } |
| 967 | |
| 968 | if (get_param_value(option, 128, "mem", optarg) == 0) { |
| 969 | node_mem[nodenr] = 0; |
| 970 | } else { |
Jes Sorensen | 70b4f4b | 2011-01-05 11:41:02 +0100 | [diff] [blame] | 971 | int64_t sval; |
Markus Armbruster | c03417b | 2011-11-22 09:46:02 +0100 | [diff] [blame] | 972 | sval = strtosz(option, &endptr); |
| 973 | if (sval < 0 || *endptr) { |
Jes Sorensen | 9f9b17a | 2010-10-21 17:15:46 +0200 | [diff] [blame] | 974 | fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg); |
| 975 | exit(1); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 976 | } |
Jes Sorensen | 9f9b17a | 2010-10-21 17:15:46 +0200 | [diff] [blame] | 977 | node_mem[nodenr] = sval; |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 978 | } |
| 979 | if (get_param_value(option, 128, "cpus", optarg) == 0) { |
| 980 | node_cpumask[nodenr] = 0; |
| 981 | } else { |
| 982 | value = strtoull(option, &endptr, 10); |
| 983 | if (value >= 64) { |
| 984 | value = 63; |
| 985 | fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n"); |
| 986 | } else { |
| 987 | if (*endptr == '-') { |
| 988 | endvalue = strtoull(endptr+1, &endptr, 10); |
| 989 | if (endvalue >= 63) { |
| 990 | endvalue = 62; |
| 991 | fprintf(stderr, |
| 992 | "only 63 CPUs in NUMA mode supported.\n"); |
| 993 | } |
Paolo Bonzini | 0dfbd51 | 2010-02-04 14:31:50 +0100 | [diff] [blame] | 994 | value = (2ULL << endvalue) - (1ULL << value); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 995 | } else { |
Paolo Bonzini | 0dfbd51 | 2010-02-04 14:31:50 +0100 | [diff] [blame] | 996 | value = 1ULL << value; |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 997 | } |
| 998 | } |
| 999 | node_cpumask[nodenr] = value; |
| 1000 | } |
| 1001 | nb_numa_nodes++; |
| 1002 | } |
| 1003 | return; |
| 1004 | } |
| 1005 | |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 1006 | static void smp_parse(const char *optarg) |
| 1007 | { |
| 1008 | int smp, sockets = 0, threads = 0, cores = 0; |
| 1009 | char *endptr; |
| 1010 | char option[128]; |
| 1011 | |
| 1012 | smp = strtoul(optarg, &endptr, 10); |
| 1013 | if (endptr != optarg) { |
| 1014 | if (*endptr == ',') { |
| 1015 | endptr++; |
| 1016 | } |
| 1017 | } |
| 1018 | if (get_param_value(option, 128, "sockets", endptr) != 0) |
| 1019 | sockets = strtoull(option, NULL, 10); |
| 1020 | if (get_param_value(option, 128, "cores", endptr) != 0) |
| 1021 | cores = strtoull(option, NULL, 10); |
| 1022 | if (get_param_value(option, 128, "threads", endptr) != 0) |
| 1023 | threads = strtoull(option, NULL, 10); |
| 1024 | if (get_param_value(option, 128, "maxcpus", endptr) != 0) |
| 1025 | max_cpus = strtoull(option, NULL, 10); |
| 1026 | |
| 1027 | /* compute missing values, prefer sockets over cores over threads */ |
| 1028 | if (smp == 0 || sockets == 0) { |
| 1029 | sockets = sockets > 0 ? sockets : 1; |
| 1030 | cores = cores > 0 ? cores : 1; |
| 1031 | threads = threads > 0 ? threads : 1; |
| 1032 | if (smp == 0) { |
| 1033 | smp = cores * threads * sockets; |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 1034 | } |
| 1035 | } else { |
| 1036 | if (cores == 0) { |
| 1037 | threads = threads > 0 ? threads : 1; |
| 1038 | cores = smp / (sockets * threads); |
| 1039 | } else { |
Joel Schopp | dca9816 | 2010-07-21 15:05:17 -0500 | [diff] [blame] | 1040 | threads = smp / (cores * sockets); |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | smp_cpus = smp; |
| 1044 | smp_cores = cores > 0 ? cores : 1; |
| 1045 | smp_threads = threads > 0 ? threads : 1; |
| 1046 | if (max_cpus == 0) |
| 1047 | max_cpus = smp_cpus; |
| 1048 | } |
| 1049 | |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 1050 | /***********************************************************/ |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1051 | /* USB devices */ |
| 1052 | |
Markus Armbruster | fb08000 | 2010-05-28 15:38:44 +0200 | [diff] [blame] | 1053 | static int usb_device_add(const char *devname) |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1054 | { |
| 1055 | const char *p; |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 1056 | USBDevice *dev = NULL; |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1057 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 1058 | if (!usb_enabled) |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1059 | return -1; |
| 1060 | |
Gerd Hoffmann | 0958b4c | 2009-10-26 15:56:45 +0100 | [diff] [blame] | 1061 | /* drivers with .usbdevice_name entry in USBDeviceInfo */ |
| 1062 | dev = usbdevice_create(devname); |
| 1063 | if (dev) |
| 1064 | goto done; |
| 1065 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 1066 | /* the other ones */ |
Gerd Hoffmann | e447fc6 | 2011-06-01 14:41:59 +0200 | [diff] [blame] | 1067 | #ifndef CONFIG_LINUX |
| 1068 | /* only the linux version is qdev-ified, usb-bsd still needs this */ |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1069 | if (strstart(devname, "host:", &p)) { |
Jan Kiszka | 3741715 | 2012-02-27 15:18:47 +0100 | [diff] [blame] | 1070 | dev = usb_host_device_open(usb_bus_find(-1), p); |
Gerd Hoffmann | e447fc6 | 2011-06-01 14:41:59 +0200 | [diff] [blame] | 1071 | } else |
| 1072 | #endif |
| 1073 | if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) { |
Jan Kiszka | 3741715 | 2012-02-27 15:18:47 +0100 | [diff] [blame] | 1074 | dev = usb_bt_init(usb_bus_find(-1), |
| 1075 | devname[2] ? hci_init(p) |
| 1076 | : bt_new_hci(qemu_find_bt_vlan(0))); |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1077 | } else { |
| 1078 | return -1; |
| 1079 | } |
pbrook | 0d92ed3 | 2006-05-21 16:30:15 +0000 | [diff] [blame] | 1080 | if (!dev) |
| 1081 | return -1; |
| 1082 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 1083 | done: |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1084 | return 0; |
| 1085 | } |
| 1086 | |
aliguori | 1f3870a | 2008-08-21 19:27:48 +0000 | [diff] [blame] | 1087 | static int usb_device_del(const char *devname) |
| 1088 | { |
| 1089 | int bus_num, addr; |
| 1090 | const char *p; |
| 1091 | |
aliguori | 5d0c575 | 2008-09-14 01:07:41 +0000 | [diff] [blame] | 1092 | if (strstart(devname, "host:", &p)) |
| 1093 | return usb_host_device_close(p); |
| 1094 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 1095 | if (!usb_enabled) |
aliguori | 1f3870a | 2008-08-21 19:27:48 +0000 | [diff] [blame] | 1096 | return -1; |
| 1097 | |
| 1098 | p = strchr(devname, '.'); |
| 1099 | if (!p) |
| 1100 | return -1; |
| 1101 | bus_num = strtoul(devname, NULL, 0); |
| 1102 | addr = strtoul(p + 1, NULL, 0); |
| 1103 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 1104 | return usb_device_delete_addr(bus_num, addr); |
aliguori | 1f3870a | 2008-08-21 19:27:48 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1107 | static int usb_parse(const char *cmdline) |
| 1108 | { |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 1109 | int r; |
Markus Armbruster | fb08000 | 2010-05-28 15:38:44 +0200 | [diff] [blame] | 1110 | r = usb_device_add(cmdline); |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 1111 | if (r < 0) { |
| 1112 | fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline); |
| 1113 | } |
| 1114 | return r; |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1115 | } |
| 1116 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1117 | void do_usb_add(Monitor *mon, const QDict *qdict) |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1118 | { |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 1119 | const char *devname = qdict_get_str(qdict, "devname"); |
Markus Armbruster | fb08000 | 2010-05-28 15:38:44 +0200 | [diff] [blame] | 1120 | if (usb_device_add(devname) < 0) { |
Markus Armbruster | 1ecda02 | 2010-02-18 17:25:24 +0100 | [diff] [blame] | 1121 | error_report("could not add USB device '%s'", devname); |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 1122 | } |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1125 | void do_usb_del(Monitor *mon, const QDict *qdict) |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1126 | { |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 1127 | const char *devname = qdict_get_str(qdict, "devname"); |
| 1128 | if (usb_device_del(devname) < 0) { |
Markus Armbruster | 1ecda02 | 2010-02-18 17:25:24 +0100 | [diff] [blame] | 1129 | error_report("could not delete USB device '%s'", devname); |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 1130 | } |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
bellard | f7cce89 | 2004-12-08 22:21:25 +0000 | [diff] [blame] | 1133 | /***********************************************************/ |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1134 | /* PCMCIA/Cardbus */ |
| 1135 | |
| 1136 | static struct pcmcia_socket_entry_s { |
Paul Brook | bc24a22 | 2009-05-10 01:44:56 +0100 | [diff] [blame] | 1137 | PCMCIASocket *socket; |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1138 | struct pcmcia_socket_entry_s *next; |
| 1139 | } *pcmcia_sockets = 0; |
| 1140 | |
Paul Brook | bc24a22 | 2009-05-10 01:44:56 +0100 | [diff] [blame] | 1141 | void pcmcia_socket_register(PCMCIASocket *socket) |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1142 | { |
| 1143 | struct pcmcia_socket_entry_s *entry; |
| 1144 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1145 | entry = g_malloc(sizeof(struct pcmcia_socket_entry_s)); |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1146 | entry->socket = socket; |
| 1147 | entry->next = pcmcia_sockets; |
| 1148 | pcmcia_sockets = entry; |
| 1149 | } |
| 1150 | |
Paul Brook | bc24a22 | 2009-05-10 01:44:56 +0100 | [diff] [blame] | 1151 | void pcmcia_socket_unregister(PCMCIASocket *socket) |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1152 | { |
| 1153 | struct pcmcia_socket_entry_s *entry, **ptr; |
| 1154 | |
| 1155 | ptr = &pcmcia_sockets; |
| 1156 | for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr) |
| 1157 | if (entry->socket == socket) { |
| 1158 | *ptr = entry->next; |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1159 | g_free(entry); |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1163 | void pcmcia_info(Monitor *mon) |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1164 | { |
| 1165 | struct pcmcia_socket_entry_s *iter; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1166 | |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1167 | if (!pcmcia_sockets) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1168 | monitor_printf(mon, "No PCMCIA sockets\n"); |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1169 | |
| 1170 | for (iter = pcmcia_sockets; iter; iter = iter->next) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1171 | monitor_printf(mon, "%s: %s\n", iter->socket->slot_string, |
| 1172 | iter->socket->attached ? iter->socket->card_string : |
| 1173 | "Empty"); |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | /***********************************************************/ |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1177 | /* machine registration */ |
| 1178 | |
blueswir1 | bdaf78e | 2008-10-04 07:24:27 +0000 | [diff] [blame] | 1179 | static QEMUMachine *first_machine = NULL; |
aliguori | 6f338c3 | 2009-02-11 15:21:54 +0000 | [diff] [blame] | 1180 | QEMUMachine *current_machine = NULL; |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1181 | |
| 1182 | int qemu_register_machine(QEMUMachine *m) |
| 1183 | { |
| 1184 | QEMUMachine **pm; |
| 1185 | pm = &first_machine; |
| 1186 | while (*pm != NULL) |
| 1187 | pm = &(*pm)->next; |
| 1188 | m->next = NULL; |
| 1189 | *pm = m; |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
pbrook | 9596ebb | 2007-11-18 01:44:38 +0000 | [diff] [blame] | 1193 | static QEMUMachine *find_machine(const char *name) |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1194 | { |
| 1195 | QEMUMachine *m; |
| 1196 | |
| 1197 | for(m = first_machine; m != NULL; m = m->next) { |
| 1198 | if (!strcmp(m->name, name)) |
| 1199 | return m; |
Mark McLoughlin | 3f6599e | 2009-07-22 10:02:50 +0100 | [diff] [blame] | 1200 | if (m->alias && !strcmp(m->alias, name)) |
| 1201 | return m; |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1202 | } |
| 1203 | return NULL; |
| 1204 | } |
| 1205 | |
Jordan Justen | 2c8cffa | 2012-02-21 23:18:50 -0800 | [diff] [blame] | 1206 | QEMUMachine *find_default_machine(void) |
Anthony Liguori | 0c25743 | 2009-05-21 20:41:01 -0500 | [diff] [blame] | 1207 | { |
| 1208 | QEMUMachine *m; |
| 1209 | |
| 1210 | for(m = first_machine; m != NULL; m = m->next) { |
| 1211 | if (m->is_default) { |
| 1212 | return m; |
| 1213 | } |
| 1214 | } |
| 1215 | return NULL; |
| 1216 | } |
| 1217 | |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1218 | /***********************************************************/ |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1219 | /* main execution loop */ |
| 1220 | |
pbrook | 9596ebb | 2007-11-18 01:44:38 +0000 | [diff] [blame] | 1221 | static void gui_update(void *opaque) |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1222 | { |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 1223 | uint64_t interval = GUI_REFRESH_INTERVAL; |
ths | 740733b | 2007-06-08 01:57:56 +0000 | [diff] [blame] | 1224 | DisplayState *ds = opaque; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 1225 | DisplayChangeListener *dcl = ds->listeners; |
| 1226 | |
| 1227 | dpy_refresh(ds); |
| 1228 | |
| 1229 | while (dcl != NULL) { |
| 1230 | if (dcl->gui_timer_interval && |
| 1231 | dcl->gui_timer_interval < interval) |
| 1232 | interval = dcl->gui_timer_interval; |
| 1233 | dcl = dcl->next; |
| 1234 | } |
Paolo Bonzini | 7bd427d | 2011-03-11 16:47:48 +0100 | [diff] [blame] | 1235 | qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock)); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1238 | struct vm_change_state_entry { |
| 1239 | VMChangeStateHandler *cb; |
| 1240 | void *opaque; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1241 | QLIST_ENTRY (vm_change_state_entry) entries; |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1242 | }; |
| 1243 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1244 | static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head; |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1245 | |
| 1246 | VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, |
| 1247 | void *opaque) |
| 1248 | { |
| 1249 | VMChangeStateEntry *e; |
| 1250 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1251 | e = g_malloc0(sizeof (*e)); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1252 | |
| 1253 | e->cb = cb; |
| 1254 | e->opaque = opaque; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1255 | QLIST_INSERT_HEAD(&vm_change_state_head, e, entries); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1256 | return e; |
| 1257 | } |
| 1258 | |
| 1259 | void qemu_del_vm_change_state_handler(VMChangeStateEntry *e) |
| 1260 | { |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1261 | QLIST_REMOVE (e, entries); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1262 | g_free (e); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
Luiz Capitulino | 1dfb4dd | 2011-07-29 14:26:33 -0300 | [diff] [blame] | 1265 | void vm_state_notify(int running, RunState state) |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1266 | { |
| 1267 | VMChangeStateEntry *e; |
| 1268 | |
Luiz Capitulino | 1dfb4dd | 2011-07-29 14:26:33 -0300 | [diff] [blame] | 1269 | trace_vm_state_notify(running, state); |
Stefan Hajnoczi | 94b0b5f | 2010-11-16 12:20:25 +0000 | [diff] [blame] | 1270 | |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1271 | for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) { |
Luiz Capitulino | 1dfb4dd | 2011-07-29 14:26:33 -0300 | [diff] [blame] | 1272 | e->cb(e->opaque, running, state); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1273 | } |
| 1274 | } |
| 1275 | |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1276 | void vm_start(void) |
| 1277 | { |
Luiz Capitulino | 1354869 | 2011-07-29 15:36:43 -0300 | [diff] [blame] | 1278 | if (!runstate_is_running()) { |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1279 | cpu_enable_ticks(); |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 1280 | runstate_set(RUN_STATE_RUNNING); |
| 1281 | vm_state_notify(1, RUN_STATE_RUNNING); |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1282 | resume_all_vcpus(); |
Luiz Capitulino | 6ed2c48 | 2010-04-27 20:35:59 -0300 | [diff] [blame] | 1283 | monitor_protocol_event(QEVENT_RESUME, NULL); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1284 | } |
| 1285 | } |
| 1286 | |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1287 | /* reset/shutdown handler */ |
| 1288 | |
| 1289 | typedef struct QEMUResetEntry { |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1290 | QTAILQ_ENTRY(QEMUResetEntry) entry; |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1291 | QEMUResetHandler *func; |
| 1292 | void *opaque; |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1293 | } QEMUResetEntry; |
| 1294 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1295 | static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers = |
| 1296 | QTAILQ_HEAD_INITIALIZER(reset_handlers); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1297 | static int reset_requested; |
Gleb Natapov | f64622c | 2011-03-15 13:56:04 +0200 | [diff] [blame] | 1298 | static int shutdown_requested, shutdown_signal = -1; |
| 1299 | static pid_t shutdown_pid; |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 1300 | static int powerdown_requested; |
Jan Kiszka | 8cf7171 | 2011-02-07 12:19:16 +0100 | [diff] [blame] | 1301 | static int debug_requested; |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1302 | static int suspend_requested; |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1303 | static NotifierList suspend_notifiers = |
| 1304 | NOTIFIER_LIST_INITIALIZER(suspend_notifiers); |
| 1305 | static NotifierList wakeup_notifiers = |
| 1306 | NOTIFIER_LIST_INITIALIZER(wakeup_notifiers); |
| 1307 | static uint32_t wakeup_reason_mask = ~0; |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 1308 | static RunState vmstop_requested = RUN_STATE_MAX; |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1309 | |
Anthony PERARD | 1291eb3 | 2010-07-22 15:52:48 +0100 | [diff] [blame] | 1310 | int qemu_shutdown_requested_get(void) |
| 1311 | { |
| 1312 | return shutdown_requested; |
| 1313 | } |
| 1314 | |
| 1315 | int qemu_reset_requested_get(void) |
| 1316 | { |
| 1317 | return reset_requested; |
| 1318 | } |
| 1319 | |
aurel32 | cf7a2fe | 2008-03-18 06:53:05 +0000 | [diff] [blame] | 1320 | int qemu_shutdown_requested(void) |
| 1321 | { |
| 1322 | int r = shutdown_requested; |
| 1323 | shutdown_requested = 0; |
| 1324 | return r; |
| 1325 | } |
| 1326 | |
Gleb Natapov | f64622c | 2011-03-15 13:56:04 +0200 | [diff] [blame] | 1327 | void qemu_kill_report(void) |
| 1328 | { |
Anthony Liguori | c7f0f3b | 2012-03-28 15:42:02 +0200 | [diff] [blame] | 1329 | if (!qtest_enabled() && shutdown_signal != -1) { |
Peter Maydell | f1d3fb0 | 2011-03-30 22:03:38 +0100 | [diff] [blame] | 1330 | fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal); |
| 1331 | if (shutdown_pid == 0) { |
| 1332 | /* This happens for eg ^C at the terminal, so it's worth |
| 1333 | * avoiding printing an odd message in that case. |
| 1334 | */ |
| 1335 | fputc('\n', stderr); |
| 1336 | } else { |
Andreas Färber | 953ffe0 | 2011-06-02 19:58:06 +0200 | [diff] [blame] | 1337 | fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid); |
Peter Maydell | f1d3fb0 | 2011-03-30 22:03:38 +0100 | [diff] [blame] | 1338 | } |
Gleb Natapov | f64622c | 2011-03-15 13:56:04 +0200 | [diff] [blame] | 1339 | shutdown_signal = -1; |
| 1340 | } |
| 1341 | } |
| 1342 | |
aurel32 | cf7a2fe | 2008-03-18 06:53:05 +0000 | [diff] [blame] | 1343 | int qemu_reset_requested(void) |
| 1344 | { |
| 1345 | int r = reset_requested; |
| 1346 | reset_requested = 0; |
| 1347 | return r; |
| 1348 | } |
| 1349 | |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1350 | static int qemu_suspend_requested(void) |
| 1351 | { |
| 1352 | int r = suspend_requested; |
| 1353 | suspend_requested = 0; |
| 1354 | return r; |
| 1355 | } |
| 1356 | |
aurel32 | cf7a2fe | 2008-03-18 06:53:05 +0000 | [diff] [blame] | 1357 | int qemu_powerdown_requested(void) |
| 1358 | { |
| 1359 | int r = powerdown_requested; |
| 1360 | powerdown_requested = 0; |
| 1361 | return r; |
| 1362 | } |
| 1363 | |
aliguori | e568902 | 2009-04-24 18:03:54 +0000 | [diff] [blame] | 1364 | static int qemu_debug_requested(void) |
| 1365 | { |
| 1366 | int r = debug_requested; |
| 1367 | debug_requested = 0; |
| 1368 | return r; |
| 1369 | } |
| 1370 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 1371 | /* We use RUN_STATE_MAX but any invalid value will do */ |
Luiz Capitulino | 0d45b70 | 2011-09-30 14:27:11 -0300 | [diff] [blame] | 1372 | static bool qemu_vmstop_requested(RunState *r) |
aliguori | 6e29f5d | 2009-04-24 18:04:02 +0000 | [diff] [blame] | 1373 | { |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 1374 | if (vmstop_requested < RUN_STATE_MAX) { |
Luiz Capitulino | 0d45b70 | 2011-09-30 14:27:11 -0300 | [diff] [blame] | 1375 | *r = vmstop_requested; |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 1376 | vmstop_requested = RUN_STATE_MAX; |
Luiz Capitulino | 0d45b70 | 2011-09-30 14:27:11 -0300 | [diff] [blame] | 1377 | return true; |
| 1378 | } |
| 1379 | |
| 1380 | return false; |
aliguori | 6e29f5d | 2009-04-24 18:04:02 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
Jan Kiszka | a08d436 | 2009-06-27 09:25:07 +0200 | [diff] [blame] | 1383 | void qemu_register_reset(QEMUResetHandler *func, void *opaque) |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1384 | { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1385 | QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry)); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1386 | |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1387 | re->func = func; |
| 1388 | re->opaque = opaque; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1389 | QTAILQ_INSERT_TAIL(&reset_handlers, re, entry); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
Jan Kiszka | dda9b29 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1392 | void qemu_unregister_reset(QEMUResetHandler *func, void *opaque) |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1393 | { |
| 1394 | QEMUResetEntry *re; |
| 1395 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1396 | QTAILQ_FOREACH(re, &reset_handlers, entry) { |
Jan Kiszka | dda9b29 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1397 | if (re->func == func && re->opaque == opaque) { |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1398 | QTAILQ_REMOVE(&reset_handlers, re, entry); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1399 | g_free(re); |
Jan Kiszka | dda9b29 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1400 | return; |
| 1401 | } |
| 1402 | } |
| 1403 | } |
| 1404 | |
Jan Kiszka | e063eb1 | 2011-06-14 18:29:43 +0200 | [diff] [blame] | 1405 | void qemu_system_reset(bool report) |
Jan Kiszka | dda9b29 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1406 | { |
| 1407 | QEMUResetEntry *re, *nre; |
| 1408 | |
| 1409 | /* reset all devices */ |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1410 | QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) { |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1411 | re->func(re->opaque); |
| 1412 | } |
Jan Kiszka | e063eb1 | 2011-06-14 18:29:43 +0200 | [diff] [blame] | 1413 | if (report) { |
| 1414 | monitor_protocol_event(QEVENT_RESET, NULL); |
| 1415 | } |
Jan Kiszka | ea375f9 | 2010-03-01 19:10:30 +0100 | [diff] [blame] | 1416 | cpu_synchronize_all_post_reset(); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | void qemu_system_reset_request(void) |
| 1420 | { |
bellard | d1beab8 | 2006-10-02 19:44:22 +0000 | [diff] [blame] | 1421 | if (no_reboot) { |
| 1422 | shutdown_requested = 1; |
| 1423 | } else { |
| 1424 | reset_requested = 1; |
| 1425 | } |
Jan Kiszka | b4a3d96 | 2011-02-01 22:15:43 +0100 | [diff] [blame] | 1426 | cpu_stop_current(); |
aliguori | d9f75a4 | 2009-04-24 18:03:11 +0000 | [diff] [blame] | 1427 | qemu_notify_event(); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1428 | } |
| 1429 | |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1430 | static void qemu_system_suspend(void) |
| 1431 | { |
| 1432 | pause_all_vcpus(); |
| 1433 | notifier_list_notify(&suspend_notifiers, NULL); |
Luiz Capitulino | ad02b96 | 2012-04-27 13:33:36 -0300 | [diff] [blame] | 1434 | runstate_set(RUN_STATE_SUSPENDED); |
Gerd Hoffmann | 53370b7 | 2012-02-23 13:45:26 +0100 | [diff] [blame] | 1435 | monitor_protocol_event(QEVENT_SUSPEND, NULL); |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | void qemu_system_suspend_request(void) |
| 1439 | { |
Luiz Capitulino | 9abc62f | 2012-04-27 14:31:12 -0300 | [diff] [blame] | 1440 | if (runstate_check(RUN_STATE_SUSPENDED)) { |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1441 | return; |
| 1442 | } |
| 1443 | suspend_requested = 1; |
| 1444 | cpu_stop_current(); |
| 1445 | qemu_notify_event(); |
| 1446 | } |
| 1447 | |
| 1448 | void qemu_register_suspend_notifier(Notifier *notifier) |
| 1449 | { |
| 1450 | notifier_list_add(&suspend_notifiers, notifier); |
| 1451 | } |
| 1452 | |
| 1453 | void qemu_system_wakeup_request(WakeupReason reason) |
| 1454 | { |
Luiz Capitulino | 9abc62f | 2012-04-27 14:31:12 -0300 | [diff] [blame] | 1455 | if (!runstate_check(RUN_STATE_SUSPENDED)) { |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1456 | return; |
| 1457 | } |
| 1458 | if (!(wakeup_reason_mask & (1 << reason))) { |
| 1459 | return; |
| 1460 | } |
Luiz Capitulino | ad02b96 | 2012-04-27 13:33:36 -0300 | [diff] [blame] | 1461 | runstate_set(RUN_STATE_RUNNING); |
Gerd Hoffmann | 53370b7 | 2012-02-23 13:45:26 +0100 | [diff] [blame] | 1462 | monitor_protocol_event(QEVENT_WAKEUP, NULL); |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1463 | notifier_list_notify(&wakeup_notifiers, &reason); |
| 1464 | reset_requested = 1; |
| 1465 | qemu_notify_event(); |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | void qemu_system_wakeup_enable(WakeupReason reason, bool enabled) |
| 1469 | { |
| 1470 | if (enabled) { |
| 1471 | wakeup_reason_mask |= (1 << reason); |
| 1472 | } else { |
| 1473 | wakeup_reason_mask &= ~(1 << reason); |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | void qemu_register_wakeup_notifier(Notifier *notifier) |
| 1478 | { |
| 1479 | notifier_list_add(&wakeup_notifiers, notifier); |
| 1480 | } |
| 1481 | |
Gleb Natapov | f64622c | 2011-03-15 13:56:04 +0200 | [diff] [blame] | 1482 | void qemu_system_killed(int signal, pid_t pid) |
| 1483 | { |
| 1484 | shutdown_signal = signal; |
| 1485 | shutdown_pid = pid; |
Kevin Wolf | d9389b9 | 2011-09-14 15:38:40 +0200 | [diff] [blame] | 1486 | no_shutdown = 0; |
Gleb Natapov | f64622c | 2011-03-15 13:56:04 +0200 | [diff] [blame] | 1487 | qemu_system_shutdown_request(); |
| 1488 | } |
| 1489 | |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1490 | void qemu_system_shutdown_request(void) |
| 1491 | { |
| 1492 | shutdown_requested = 1; |
aliguori | d9f75a4 | 2009-04-24 18:03:11 +0000 | [diff] [blame] | 1493 | qemu_notify_event(); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 1496 | void qemu_system_powerdown_request(void) |
| 1497 | { |
| 1498 | powerdown_requested = 1; |
aliguori | d9f75a4 | 2009-04-24 18:03:11 +0000 | [diff] [blame] | 1499 | qemu_notify_event(); |
| 1500 | } |
| 1501 | |
Jan Kiszka | 8cf7171 | 2011-02-07 12:19:16 +0100 | [diff] [blame] | 1502 | void qemu_system_debug_request(void) |
| 1503 | { |
| 1504 | debug_requested = 1; |
Jan Kiszka | 83f338f | 2011-02-07 12:19:17 +0100 | [diff] [blame] | 1505 | qemu_notify_event(); |
Jan Kiszka | 8cf7171 | 2011-02-07 12:19:16 +0100 | [diff] [blame] | 1506 | } |
| 1507 | |
Luiz Capitulino | 1dfb4dd | 2011-07-29 14:26:33 -0300 | [diff] [blame] | 1508 | void qemu_system_vmstop_request(RunState state) |
Jan Kiszka | 8cf7171 | 2011-02-07 12:19:16 +0100 | [diff] [blame] | 1509 | { |
Luiz Capitulino | 1dfb4dd | 2011-07-29 14:26:33 -0300 | [diff] [blame] | 1510 | vmstop_requested = state; |
Jan Kiszka | 8cf7171 | 2011-02-07 12:19:16 +0100 | [diff] [blame] | 1511 | qemu_notify_event(); |
| 1512 | } |
| 1513 | |
Blue Swirl | d9c3231 | 2009-08-09 08:42:19 +0000 | [diff] [blame] | 1514 | qemu_irq qemu_system_powerdown; |
| 1515 | |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 1516 | static bool main_loop_should_exit(void) |
| 1517 | { |
| 1518 | RunState r; |
| 1519 | if (qemu_debug_requested()) { |
| 1520 | vm_stop(RUN_STATE_DEBUG); |
| 1521 | } |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1522 | if (qemu_suspend_requested()) { |
| 1523 | qemu_system_suspend(); |
| 1524 | } |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 1525 | if (qemu_shutdown_requested()) { |
| 1526 | qemu_kill_report(); |
| 1527 | monitor_protocol_event(QEVENT_SHUTDOWN, NULL); |
| 1528 | if (no_shutdown) { |
| 1529 | vm_stop(RUN_STATE_SHUTDOWN); |
| 1530 | } else { |
| 1531 | return true; |
| 1532 | } |
| 1533 | } |
| 1534 | if (qemu_reset_requested()) { |
| 1535 | pause_all_vcpus(); |
| 1536 | cpu_synchronize_all_states(); |
| 1537 | qemu_system_reset(VMRESET_REPORT); |
| 1538 | resume_all_vcpus(); |
| 1539 | if (runstate_check(RUN_STATE_INTERNAL_ERROR) || |
| 1540 | runstate_check(RUN_STATE_SHUTDOWN)) { |
| 1541 | runstate_set(RUN_STATE_PAUSED); |
| 1542 | } |
| 1543 | } |
| 1544 | if (qemu_powerdown_requested()) { |
| 1545 | monitor_protocol_event(QEVENT_POWERDOWN, NULL); |
| 1546 | qemu_irq_raise(qemu_system_powerdown); |
| 1547 | } |
| 1548 | if (qemu_vmstop_requested(&r)) { |
| 1549 | vm_stop(r); |
| 1550 | } |
| 1551 | return false; |
| 1552 | } |
| 1553 | |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1554 | static void main_loop(void) |
| 1555 | { |
Jan Kiszka | c9f711a | 2011-08-22 17:46:02 +0200 | [diff] [blame] | 1556 | bool nonblocking; |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 1557 | int last_io = 0; |
Jan Kiszka | 8e1b90e | 2011-02-01 22:15:46 +0100 | [diff] [blame] | 1558 | #ifdef CONFIG_PROFILER |
| 1559 | int64_t ti; |
| 1560 | #endif |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 1561 | do { |
Jan Kiszka | c9f711a | 2011-08-22 17:46:02 +0200 | [diff] [blame] | 1562 | nonblocking = !kvm_enabled() && last_io > 0; |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1563 | #ifdef CONFIG_PROFILER |
Jan Kiszka | 46481d3 | 2011-02-01 22:15:47 +0100 | [diff] [blame] | 1564 | ti = profile_getclock(); |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1565 | #endif |
Jan Kiszka | c9f711a | 2011-08-22 17:46:02 +0200 | [diff] [blame] | 1566 | last_io = main_loop_wait(nonblocking); |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1567 | #ifdef CONFIG_PROFILER |
Jan Kiszka | 46481d3 | 2011-02-01 22:15:47 +0100 | [diff] [blame] | 1568 | dev_time += profile_getclock() - ti; |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1569 | #endif |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 1570 | } while (!main_loop_should_exit()); |
bellard | b4608c0 | 2003-06-27 17:34:32 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
pbrook | 9bd7e6d | 2009-04-07 22:58:45 +0000 | [diff] [blame] | 1573 | static void version(void) |
| 1574 | { |
Thomas Monjalon | f75ca1a | 2010-04-28 14:42:01 +0200 | [diff] [blame] | 1575 | printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n"); |
pbrook | 9bd7e6d | 2009-04-07 22:58:45 +0000 | [diff] [blame] | 1576 | } |
| 1577 | |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 1578 | static void help(int exitcode) |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 1579 | { |
Michael Ellerman | a3adb7a | 2011-12-19 17:19:31 +1100 | [diff] [blame] | 1580 | version(); |
| 1581 | printf("usage: %s [options] [disk_image]\n\n" |
| 1582 | "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n", |
| 1583 | error_get_progname()); |
| 1584 | |
Michael Ellerman | 77bd111 | 2011-12-19 17:19:30 +1100 | [diff] [blame] | 1585 | #define QEMU_OPTIONS_GENERATE_HELP |
| 1586 | #include "qemu-options-wrapper.h" |
Michael Ellerman | a3adb7a | 2011-12-19 17:19:31 +1100 | [diff] [blame] | 1587 | |
| 1588 | printf("\nDuring emulation, the following keys are useful:\n" |
malc | 3f020d7 | 2010-02-08 12:04:56 +0300 | [diff] [blame] | 1589 | "ctrl-alt-f toggle full screen\n" |
| 1590 | "ctrl-alt-n switch to virtual console 'n'\n" |
| 1591 | "ctrl-alt toggle mouse and keyboard grab\n" |
| 1592 | "\n" |
Michael Ellerman | a3adb7a | 2011-12-19 17:19:31 +1100 | [diff] [blame] | 1593 | "When using -nographic, press 'ctrl-a h' to get some help.\n"); |
| 1594 | |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 1595 | exit(exitcode); |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1598 | #define HAS_ARG 0x0001 |
| 1599 | |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1600 | typedef struct QEMUOption { |
| 1601 | const char *name; |
| 1602 | int flags; |
| 1603 | int index; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1604 | uint32_t arch_mask; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1605 | } QEMUOption; |
| 1606 | |
blueswir1 | dbed7e4 | 2008-10-01 19:38:09 +0000 | [diff] [blame] | 1607 | static const QEMUOption qemu_options[] = { |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1608 | { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL }, |
Michael Ellerman | 77bd111 | 2011-12-19 17:19:30 +1100 | [diff] [blame] | 1609 | #define QEMU_OPTIONS_GENERATE_OPTIONS |
| 1610 | #include "qemu-options-wrapper.h" |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1611 | { NULL }, |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 1612 | }; |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 1613 | |
| 1614 | static bool vga_available(void) |
| 1615 | { |
| 1616 | return qdev_exists("VGA") || qdev_exists("isa-vga"); |
| 1617 | } |
| 1618 | |
| 1619 | static bool cirrus_vga_available(void) |
| 1620 | { |
| 1621 | return qdev_exists("cirrus-vga") || qdev_exists("isa-cirrus-vga"); |
| 1622 | } |
| 1623 | |
| 1624 | static bool vmware_vga_available(void) |
| 1625 | { |
| 1626 | return qdev_exists("vmware-svga"); |
| 1627 | } |
| 1628 | |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1629 | static void select_vgahw (const char *p) |
| 1630 | { |
| 1631 | const char *opts; |
| 1632 | |
Zachary Amsden | 8617675 | 2009-07-30 00:15:02 -1000 | [diff] [blame] | 1633 | vga_interface_type = VGA_NONE; |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1634 | if (strstart(p, "std", &opts)) { |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 1635 | if (vga_available()) { |
| 1636 | vga_interface_type = VGA_STD; |
| 1637 | } else { |
| 1638 | fprintf(stderr, "Error: standard VGA not available\n"); |
| 1639 | exit(0); |
| 1640 | } |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1641 | } else if (strstart(p, "cirrus", &opts)) { |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 1642 | if (cirrus_vga_available()) { |
| 1643 | vga_interface_type = VGA_CIRRUS; |
| 1644 | } else { |
| 1645 | fprintf(stderr, "Error: Cirrus VGA not available\n"); |
| 1646 | exit(0); |
| 1647 | } |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1648 | } else if (strstart(p, "vmware", &opts)) { |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 1649 | if (vmware_vga_available()) { |
| 1650 | vga_interface_type = VGA_VMWARE; |
| 1651 | } else { |
| 1652 | fprintf(stderr, "Error: VMWare SVGA not available\n"); |
| 1653 | exit(0); |
| 1654 | } |
aliguori | 94909d9 | 2009-04-22 15:19:53 +0000 | [diff] [blame] | 1655 | } else if (strstart(p, "xenfb", &opts)) { |
Zachary Amsden | 8617675 | 2009-07-30 00:15:02 -1000 | [diff] [blame] | 1656 | vga_interface_type = VGA_XENFB; |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 1657 | } else if (strstart(p, "qxl", &opts)) { |
| 1658 | vga_interface_type = VGA_QXL; |
aliguori | 28b85ed | 2009-04-22 15:19:48 +0000 | [diff] [blame] | 1659 | } else if (!strstart(p, "none", &opts)) { |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1660 | invalid_vga: |
| 1661 | fprintf(stderr, "Unknown vga type: %s\n", p); |
| 1662 | exit(1); |
| 1663 | } |
malc | cb5a7aa | 2008-09-28 00:42:12 +0000 | [diff] [blame] | 1664 | while (*opts) { |
| 1665 | const char *nextopt; |
| 1666 | |
| 1667 | if (strstart(opts, ",retrace=", &nextopt)) { |
| 1668 | opts = nextopt; |
| 1669 | if (strstart(opts, "dumb", &nextopt)) |
| 1670 | vga_retrace_method = VGA_RETRACE_DUMB; |
| 1671 | else if (strstart(opts, "precise", &nextopt)) |
| 1672 | vga_retrace_method = VGA_RETRACE_PRECISE; |
| 1673 | else goto invalid_vga; |
| 1674 | } else goto invalid_vga; |
| 1675 | opts = nextopt; |
| 1676 | } |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1677 | } |
| 1678 | |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 1679 | static DisplayType select_display(const char *p) |
| 1680 | { |
| 1681 | const char *opts; |
| 1682 | DisplayType display = DT_DEFAULT; |
| 1683 | |
| 1684 | if (strstart(p, "sdl", &opts)) { |
| 1685 | #ifdef CONFIG_SDL |
| 1686 | display = DT_SDL; |
| 1687 | while (*opts) { |
| 1688 | const char *nextopt; |
| 1689 | |
| 1690 | if (strstart(opts, ",frame=", &nextopt)) { |
| 1691 | opts = nextopt; |
| 1692 | if (strstart(opts, "on", &nextopt)) { |
| 1693 | no_frame = 0; |
| 1694 | } else if (strstart(opts, "off", &nextopt)) { |
| 1695 | no_frame = 1; |
| 1696 | } else { |
Peter Maydell | 0517553 | 2011-03-23 03:40:57 +0000 | [diff] [blame] | 1697 | goto invalid_sdl_args; |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 1698 | } |
| 1699 | } else if (strstart(opts, ",alt_grab=", &nextopt)) { |
| 1700 | opts = nextopt; |
| 1701 | if (strstart(opts, "on", &nextopt)) { |
| 1702 | alt_grab = 1; |
| 1703 | } else if (strstart(opts, "off", &nextopt)) { |
| 1704 | alt_grab = 0; |
| 1705 | } else { |
Peter Maydell | 0517553 | 2011-03-23 03:40:57 +0000 | [diff] [blame] | 1706 | goto invalid_sdl_args; |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 1707 | } |
| 1708 | } else if (strstart(opts, ",ctrl_grab=", &nextopt)) { |
| 1709 | opts = nextopt; |
| 1710 | if (strstart(opts, "on", &nextopt)) { |
| 1711 | ctrl_grab = 1; |
| 1712 | } else if (strstart(opts, "off", &nextopt)) { |
| 1713 | ctrl_grab = 0; |
| 1714 | } else { |
Peter Maydell | 0517553 | 2011-03-23 03:40:57 +0000 | [diff] [blame] | 1715 | goto invalid_sdl_args; |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 1716 | } |
| 1717 | } else if (strstart(opts, ",window_close=", &nextopt)) { |
| 1718 | opts = nextopt; |
| 1719 | if (strstart(opts, "on", &nextopt)) { |
| 1720 | no_quit = 0; |
| 1721 | } else if (strstart(opts, "off", &nextopt)) { |
| 1722 | no_quit = 1; |
| 1723 | } else { |
Peter Maydell | 0517553 | 2011-03-23 03:40:57 +0000 | [diff] [blame] | 1724 | goto invalid_sdl_args; |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 1725 | } |
| 1726 | } else { |
Peter Maydell | 0517553 | 2011-03-23 03:40:57 +0000 | [diff] [blame] | 1727 | invalid_sdl_args: |
| 1728 | fprintf(stderr, "Invalid SDL option string: %s\n", p); |
| 1729 | exit(1); |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 1730 | } |
| 1731 | opts = nextopt; |
| 1732 | } |
| 1733 | #else |
| 1734 | fprintf(stderr, "SDL support is disabled\n"); |
| 1735 | exit(1); |
| 1736 | #endif |
Jes Sorensen | 3264ff1 | 2011-03-16 13:33:33 +0100 | [diff] [blame] | 1737 | } else if (strstart(p, "vnc", &opts)) { |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 1738 | #ifdef CONFIG_VNC |
Jes Sorensen | 3264ff1 | 2011-03-16 13:33:33 +0100 | [diff] [blame] | 1739 | display_remote++; |
| 1740 | |
| 1741 | if (*opts) { |
| 1742 | const char *nextopt; |
| 1743 | |
| 1744 | if (strstart(opts, "=", &nextopt)) { |
| 1745 | vnc_display = nextopt; |
| 1746 | } |
| 1747 | } |
| 1748 | if (!vnc_display) { |
| 1749 | fprintf(stderr, "VNC requires a display argument vnc=<display>\n"); |
| 1750 | exit(1); |
| 1751 | } |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 1752 | #else |
| 1753 | fprintf(stderr, "VNC support is disabled\n"); |
| 1754 | exit(1); |
| 1755 | #endif |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 1756 | } else if (strstart(p, "curses", &opts)) { |
| 1757 | #ifdef CONFIG_CURSES |
| 1758 | display = DT_CURSES; |
| 1759 | #else |
| 1760 | fprintf(stderr, "Curses support is disabled\n"); |
| 1761 | exit(1); |
| 1762 | #endif |
Jes Sorensen | 4171d32 | 2011-03-16 13:33:32 +0100 | [diff] [blame] | 1763 | } else if (strstart(p, "none", &opts)) { |
| 1764 | display = DT_NONE; |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 1765 | } else { |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 1766 | fprintf(stderr, "Unknown display type: %s\n", p); |
| 1767 | exit(1); |
| 1768 | } |
| 1769 | |
| 1770 | return display; |
| 1771 | } |
| 1772 | |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 1773 | static int balloon_parse(const char *arg) |
| 1774 | { |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 1775 | QemuOpts *opts; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 1776 | |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 1777 | if (strcmp(arg, "none") == 0) { |
| 1778 | return 0; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 1779 | } |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 1780 | |
| 1781 | if (!strncmp(arg, "virtio", 6)) { |
| 1782 | if (arg[6] == ',') { |
| 1783 | /* have params -> parse them */ |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 1784 | opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0); |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 1785 | if (!opts) |
| 1786 | return -1; |
| 1787 | } else { |
| 1788 | /* create empty opts */ |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 1789 | opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0); |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 1790 | } |
Alexander Graf | 29f82b3 | 2011-03-29 15:29:29 +0200 | [diff] [blame] | 1791 | qemu_opt_set(opts, "driver", "virtio-balloon"); |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 1792 | return 0; |
| 1793 | } |
| 1794 | |
| 1795 | return -1; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 1796 | } |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 1797 | |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 1798 | char *qemu_find_file(int type, const char *name) |
| 1799 | { |
| 1800 | int len; |
| 1801 | const char *subdir; |
| 1802 | char *buf; |
| 1803 | |
| 1804 | /* If name contains path separators then try it as a straight path. */ |
| 1805 | if ((strchr(name, '/') || strchr(name, '\\')) |
| 1806 | && access(name, R_OK) == 0) { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1807 | return g_strdup(name); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 1808 | } |
| 1809 | switch (type) { |
| 1810 | case QEMU_FILE_TYPE_BIOS: |
| 1811 | subdir = ""; |
| 1812 | break; |
| 1813 | case QEMU_FILE_TYPE_KEYMAP: |
| 1814 | subdir = "keymaps/"; |
| 1815 | break; |
| 1816 | default: |
| 1817 | abort(); |
| 1818 | } |
| 1819 | len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2; |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1820 | buf = g_malloc0(len); |
Blue Swirl | 3a41759 | 2009-06-09 19:12:21 +0000 | [diff] [blame] | 1821 | snprintf(buf, len, "%s/%s%s", data_dir, subdir, name); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 1822 | if (access(buf, R_OK)) { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1823 | g_free(buf); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 1824 | return NULL; |
| 1825 | } |
| 1826 | return buf; |
| 1827 | } |
| 1828 | |
Markus Armbruster | ff952ba | 2010-01-29 19:48:57 +0100 | [diff] [blame] | 1829 | static int device_help_func(QemuOpts *opts, void *opaque) |
| 1830 | { |
| 1831 | return qdev_device_help(opts); |
| 1832 | } |
| 1833 | |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 1834 | static int device_init_func(QemuOpts *opts, void *opaque) |
| 1835 | { |
| 1836 | DeviceState *dev; |
| 1837 | |
| 1838 | dev = qdev_device_add(opts); |
| 1839 | if (!dev) |
| 1840 | return -1; |
| 1841 | return 0; |
| 1842 | } |
| 1843 | |
Gerd Hoffmann | 1a688d3 | 2009-12-08 13:11:36 +0100 | [diff] [blame] | 1844 | static int chardev_init_func(QemuOpts *opts, void *opaque) |
| 1845 | { |
| 1846 | CharDriverState *chr; |
| 1847 | |
Anthony Liguori | f69554b | 2011-08-15 11:17:37 -0500 | [diff] [blame] | 1848 | chr = qemu_chr_new_from_opts(opts, NULL); |
Gerd Hoffmann | 1a688d3 | 2009-12-08 13:11:36 +0100 | [diff] [blame] | 1849 | if (!chr) |
| 1850 | return -1; |
| 1851 | return 0; |
| 1852 | } |
| 1853 | |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 1854 | #ifdef CONFIG_VIRTFS |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 1855 | static int fsdev_init_func(QemuOpts *opts, void *opaque) |
| 1856 | { |
| 1857 | int ret; |
| 1858 | ret = qemu_fsdev_add(opts); |
| 1859 | |
| 1860 | return ret; |
| 1861 | } |
| 1862 | #endif |
| 1863 | |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 1864 | static int mon_init_func(QemuOpts *opts, void *opaque) |
| 1865 | { |
| 1866 | CharDriverState *chr; |
| 1867 | const char *chardev; |
| 1868 | const char *mode; |
| 1869 | int flags; |
| 1870 | |
| 1871 | mode = qemu_opt_get(opts, "mode"); |
| 1872 | if (mode == NULL) { |
| 1873 | mode = "readline"; |
| 1874 | } |
| 1875 | if (strcmp(mode, "readline") == 0) { |
| 1876 | flags = MONITOR_USE_READLINE; |
| 1877 | } else if (strcmp(mode, "control") == 0) { |
| 1878 | flags = MONITOR_USE_CONTROL; |
| 1879 | } else { |
| 1880 | fprintf(stderr, "unknown monitor mode \"%s\"\n", mode); |
| 1881 | exit(1); |
| 1882 | } |
| 1883 | |
Daniel P. Berrange | 39eaab9 | 2010-06-07 15:42:31 +0100 | [diff] [blame] | 1884 | if (qemu_opt_get_bool(opts, "pretty", 0)) |
| 1885 | flags |= MONITOR_USE_PRETTY; |
| 1886 | |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 1887 | if (qemu_opt_get_bool(opts, "default", 0)) |
| 1888 | flags |= MONITOR_IS_DEFAULT; |
| 1889 | |
| 1890 | chardev = qemu_opt_get(opts, "chardev"); |
| 1891 | chr = qemu_chr_find(chardev); |
| 1892 | if (chr == NULL) { |
| 1893 | fprintf(stderr, "chardev \"%s\" not found\n", chardev); |
| 1894 | exit(1); |
| 1895 | } |
| 1896 | |
| 1897 | monitor_init(chr, flags); |
| 1898 | return 0; |
| 1899 | } |
| 1900 | |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 1901 | static void monitor_parse(const char *optarg, const char *mode) |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 1902 | { |
| 1903 | static int monitor_device_index = 0; |
| 1904 | QemuOpts *opts; |
| 1905 | const char *p; |
| 1906 | char label[32]; |
| 1907 | int def = 0; |
| 1908 | |
| 1909 | if (strstart(optarg, "chardev:", &p)) { |
| 1910 | snprintf(label, sizeof(label), "%s", p); |
| 1911 | } else { |
Jan Kiszka | 140e065 | 2010-04-06 16:55:52 +0200 | [diff] [blame] | 1912 | snprintf(label, sizeof(label), "compat_monitor%d", |
| 1913 | monitor_device_index); |
| 1914 | if (monitor_device_index == 0) { |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 1915 | def = 1; |
| 1916 | } |
| 1917 | opts = qemu_chr_parse_compat(label, optarg); |
| 1918 | if (!opts) { |
| 1919 | fprintf(stderr, "parse error: %s\n", optarg); |
| 1920 | exit(1); |
| 1921 | } |
| 1922 | } |
| 1923 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 1924 | opts = qemu_opts_create(qemu_find_opts("mon"), label, 1); |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 1925 | if (!opts) { |
| 1926 | fprintf(stderr, "duplicate chardev: %s\n", label); |
| 1927 | exit(1); |
| 1928 | } |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 1929 | qemu_opt_set(opts, "mode", mode); |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 1930 | qemu_opt_set(opts, "chardev", label); |
| 1931 | if (def) |
| 1932 | qemu_opt_set(opts, "default", "on"); |
| 1933 | monitor_device_index++; |
| 1934 | } |
| 1935 | |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1936 | struct device_config { |
| 1937 | enum { |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 1938 | DEV_USB, /* -usbdevice */ |
| 1939 | DEV_BT, /* -bt */ |
| 1940 | DEV_SERIAL, /* -serial */ |
| 1941 | DEV_PARALLEL, /* -parallel */ |
| 1942 | DEV_VIRTCON, /* -virtioconsole */ |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 1943 | DEV_DEBUGCON, /* -debugcon */ |
Markus Armbruster | ef0c4a0 | 2012-02-07 15:09:13 +0100 | [diff] [blame] | 1944 | DEV_GDB, /* -gdb, -s */ |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1945 | } type; |
| 1946 | const char *cmdline; |
Markus Armbruster | d9a5954 | 2012-02-07 15:09:12 +0100 | [diff] [blame] | 1947 | Location loc; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1948 | QTAILQ_ENTRY(device_config) next; |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1949 | }; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1950 | QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs); |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1951 | |
| 1952 | static void add_device_config(int type, const char *cmdline) |
| 1953 | { |
| 1954 | struct device_config *conf; |
| 1955 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1956 | conf = g_malloc0(sizeof(*conf)); |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1957 | conf->type = type; |
| 1958 | conf->cmdline = cmdline; |
Markus Armbruster | d9a5954 | 2012-02-07 15:09:12 +0100 | [diff] [blame] | 1959 | loc_save(&conf->loc); |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1960 | QTAILQ_INSERT_TAIL(&device_configs, conf, next); |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | static int foreach_device_config(int type, int (*func)(const char *cmdline)) |
| 1964 | { |
| 1965 | struct device_config *conf; |
| 1966 | int rc; |
| 1967 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1968 | QTAILQ_FOREACH(conf, &device_configs, next) { |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1969 | if (conf->type != type) |
| 1970 | continue; |
Markus Armbruster | d9a5954 | 2012-02-07 15:09:12 +0100 | [diff] [blame] | 1971 | loc_push_restore(&conf->loc); |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1972 | rc = func(conf->cmdline); |
Markus Armbruster | d9a5954 | 2012-02-07 15:09:12 +0100 | [diff] [blame] | 1973 | loc_pop(&conf->loc); |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1974 | if (0 != rc) |
| 1975 | return rc; |
| 1976 | } |
| 1977 | return 0; |
| 1978 | } |
| 1979 | |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 1980 | static int serial_parse(const char *devname) |
| 1981 | { |
| 1982 | static int index = 0; |
| 1983 | char label[32]; |
| 1984 | |
| 1985 | if (strcmp(devname, "none") == 0) |
| 1986 | return 0; |
| 1987 | if (index == MAX_SERIAL_PORTS) { |
| 1988 | fprintf(stderr, "qemu: too many serial ports\n"); |
| 1989 | exit(1); |
| 1990 | } |
| 1991 | snprintf(label, sizeof(label), "serial%d", index); |
Anthony Liguori | 27143a4 | 2011-08-15 11:17:36 -0500 | [diff] [blame] | 1992 | serial_hds[index] = qemu_chr_new(label, devname, NULL); |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 1993 | if (!serial_hds[index]) { |
| 1994 | fprintf(stderr, "qemu: could not open serial device '%s': %s\n", |
| 1995 | devname, strerror(errno)); |
| 1996 | return -1; |
| 1997 | } |
| 1998 | index++; |
| 1999 | return 0; |
| 2000 | } |
| 2001 | |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 2002 | static int parallel_parse(const char *devname) |
| 2003 | { |
| 2004 | static int index = 0; |
| 2005 | char label[32]; |
| 2006 | |
| 2007 | if (strcmp(devname, "none") == 0) |
| 2008 | return 0; |
| 2009 | if (index == MAX_PARALLEL_PORTS) { |
| 2010 | fprintf(stderr, "qemu: too many parallel ports\n"); |
| 2011 | exit(1); |
| 2012 | } |
| 2013 | snprintf(label, sizeof(label), "parallel%d", index); |
Anthony Liguori | 27143a4 | 2011-08-15 11:17:36 -0500 | [diff] [blame] | 2014 | parallel_hds[index] = qemu_chr_new(label, devname, NULL); |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 2015 | if (!parallel_hds[index]) { |
| 2016 | fprintf(stderr, "qemu: could not open parallel device '%s': %s\n", |
| 2017 | devname, strerror(errno)); |
| 2018 | return -1; |
| 2019 | } |
| 2020 | index++; |
| 2021 | return 0; |
| 2022 | } |
| 2023 | |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2024 | static int virtcon_parse(const char *devname) |
| 2025 | { |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2026 | QemuOptsList *device = qemu_find_opts("device"); |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2027 | static int index = 0; |
| 2028 | char label[32]; |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 2029 | QemuOpts *bus_opts, *dev_opts; |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2030 | |
| 2031 | if (strcmp(devname, "none") == 0) |
| 2032 | return 0; |
| 2033 | if (index == MAX_VIRTIO_CONSOLES) { |
| 2034 | fprintf(stderr, "qemu: too many virtio consoles\n"); |
| 2035 | exit(1); |
| 2036 | } |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 2037 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2038 | bus_opts = qemu_opts_create(device, NULL, 0); |
Anthony Liguori | e87f7fc | 2012-02-06 11:07:18 -0600 | [diff] [blame] | 2039 | if (arch_type == QEMU_ARCH_S390X) { |
| 2040 | qemu_opt_set(bus_opts, "driver", "virtio-serial-s390"); |
| 2041 | } else { |
| 2042 | qemu_opt_set(bus_opts, "driver", "virtio-serial-pci"); |
| 2043 | } |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 2044 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2045 | dev_opts = qemu_opts_create(device, NULL, 0); |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 2046 | qemu_opt_set(dev_opts, "driver", "virtconsole"); |
| 2047 | |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2048 | snprintf(label, sizeof(label), "virtcon%d", index); |
Anthony Liguori | 27143a4 | 2011-08-15 11:17:36 -0500 | [diff] [blame] | 2049 | virtcon_hds[index] = qemu_chr_new(label, devname, NULL); |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2050 | if (!virtcon_hds[index]) { |
| 2051 | fprintf(stderr, "qemu: could not open virtio console '%s': %s\n", |
| 2052 | devname, strerror(errno)); |
| 2053 | return -1; |
| 2054 | } |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 2055 | qemu_opt_set(dev_opts, "chardev", label); |
| 2056 | |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2057 | index++; |
| 2058 | return 0; |
| 2059 | } |
| 2060 | |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 2061 | static int debugcon_parse(const char *devname) |
| 2062 | { |
| 2063 | QemuOpts *opts; |
| 2064 | |
Anthony Liguori | 27143a4 | 2011-08-15 11:17:36 -0500 | [diff] [blame] | 2065 | if (!qemu_chr_new("debugcon", devname, NULL)) { |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 2066 | exit(1); |
| 2067 | } |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2068 | opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1); |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 2069 | if (!opts) { |
| 2070 | fprintf(stderr, "qemu: already have a debugcon device\n"); |
| 2071 | exit(1); |
| 2072 | } |
| 2073 | qemu_opt_set(opts, "driver", "isa-debugcon"); |
| 2074 | qemu_opt_set(opts, "chardev", "debugcon"); |
| 2075 | return 0; |
| 2076 | } |
| 2077 | |
Jan Kiszka | 9052ea6 | 2011-07-23 12:38:37 +0200 | [diff] [blame] | 2078 | static QEMUMachine *machine_parse(const char *name) |
| 2079 | { |
| 2080 | QEMUMachine *m, *machine = NULL; |
| 2081 | |
| 2082 | if (name) { |
| 2083 | machine = find_machine(name); |
| 2084 | } |
| 2085 | if (machine) { |
| 2086 | return machine; |
| 2087 | } |
| 2088 | printf("Supported machines are:\n"); |
| 2089 | for (m = first_machine; m != NULL; m = m->next) { |
| 2090 | if (m->alias) { |
Peter Maydell | 3b26486 | 2012-02-22 22:13:11 +0000 | [diff] [blame] | 2091 | printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name); |
Jan Kiszka | 9052ea6 | 2011-07-23 12:38:37 +0200 | [diff] [blame] | 2092 | } |
Peter Maydell | 3b26486 | 2012-02-22 22:13:11 +0000 | [diff] [blame] | 2093 | printf("%-20s %s%s\n", m->name, m->desc, |
Jan Kiszka | 9052ea6 | 2011-07-23 12:38:37 +0200 | [diff] [blame] | 2094 | m->is_default ? " (default)" : ""); |
| 2095 | } |
| 2096 | exit(!name || *name != '?'); |
| 2097 | } |
| 2098 | |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2099 | static int tcg_init(void) |
| 2100 | { |
Jan Kiszka | d5ab971 | 2011-08-02 16:10:21 +0200 | [diff] [blame] | 2101 | tcg_exec_init(tcg_tb_size * 1024 * 1024); |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2102 | return 0; |
| 2103 | } |
| 2104 | |
| 2105 | static struct { |
| 2106 | const char *opt_name; |
| 2107 | const char *name; |
| 2108 | int (*available)(void); |
| 2109 | int (*init)(void); |
| 2110 | int *allowed; |
| 2111 | } accel_list[] = { |
| 2112 | { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed }, |
Anthony PERARD | 3285cf4 | 2010-08-19 12:27:56 +0100 | [diff] [blame] | 2113 | { "xen", "Xen", xen_available, xen_init, &xen_allowed }, |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2114 | { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed }, |
Anthony Liguori | c7f0f3b | 2012-03-28 15:42:02 +0200 | [diff] [blame] | 2115 | { "qtest", "QTest", qtest_available, qtest_init, &qtest_allowed }, |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2116 | }; |
| 2117 | |
| 2118 | static int configure_accelerator(void) |
| 2119 | { |
| 2120 | const char *p = NULL; |
| 2121 | char buf[10]; |
| 2122 | int i, ret; |
Peter Maydell | 1b785a9 | 2012-02-07 20:57:27 +0000 | [diff] [blame] | 2123 | bool accel_initialised = 0; |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2124 | bool init_failed = 0; |
| 2125 | |
| 2126 | QemuOptsList *list = qemu_find_opts("machine"); |
| 2127 | if (!QTAILQ_EMPTY(&list->head)) { |
| 2128 | p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel"); |
| 2129 | } |
| 2130 | |
| 2131 | if (p == NULL) { |
| 2132 | /* Use the default "accelerator", tcg */ |
| 2133 | p = "tcg"; |
| 2134 | } |
| 2135 | |
Peter Maydell | 1b785a9 | 2012-02-07 20:57:27 +0000 | [diff] [blame] | 2136 | while (!accel_initialised && *p != '\0') { |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2137 | if (*p == ':') { |
| 2138 | p++; |
| 2139 | } |
| 2140 | p = get_opt_name(buf, sizeof (buf), p, ':'); |
| 2141 | for (i = 0; i < ARRAY_SIZE(accel_list); i++) { |
| 2142 | if (strcmp(accel_list[i].opt_name, buf) == 0) { |
Anthony Liguori | a16c53b | 2011-06-06 08:25:06 -0500 | [diff] [blame] | 2143 | *(accel_list[i].allowed) = 1; |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2144 | ret = accel_list[i].init(); |
| 2145 | if (ret < 0) { |
| 2146 | init_failed = 1; |
| 2147 | if (!accel_list[i].available()) { |
| 2148 | printf("%s not supported for this target\n", |
| 2149 | accel_list[i].name); |
| 2150 | } else { |
| 2151 | fprintf(stderr, "failed to initialize %s: %s\n", |
| 2152 | accel_list[i].name, |
| 2153 | strerror(-ret)); |
| 2154 | } |
Anthony Liguori | a16c53b | 2011-06-06 08:25:06 -0500 | [diff] [blame] | 2155 | *(accel_list[i].allowed) = 0; |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2156 | } else { |
Peter Maydell | 1b785a9 | 2012-02-07 20:57:27 +0000 | [diff] [blame] | 2157 | accel_initialised = 1; |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2158 | } |
| 2159 | break; |
| 2160 | } |
| 2161 | } |
| 2162 | if (i == ARRAY_SIZE(accel_list)) { |
| 2163 | fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf); |
| 2164 | } |
| 2165 | } |
| 2166 | |
Peter Maydell | 1b785a9 | 2012-02-07 20:57:27 +0000 | [diff] [blame] | 2167 | if (!accel_initialised) { |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2168 | fprintf(stderr, "No accelerator found!\n"); |
| 2169 | exit(1); |
| 2170 | } |
| 2171 | |
| 2172 | if (init_failed) { |
| 2173 | fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name); |
| 2174 | } |
| 2175 | |
Peter Maydell | 1b785a9 | 2012-02-07 20:57:27 +0000 | [diff] [blame] | 2176 | return !accel_initialised; |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2177 | } |
| 2178 | |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame] | 2179 | void qemu_add_exit_notifier(Notifier *notify) |
| 2180 | { |
| 2181 | notifier_list_add(&exit_notifiers, notify); |
| 2182 | } |
| 2183 | |
| 2184 | void qemu_remove_exit_notifier(Notifier *notify) |
| 2185 | { |
Paolo Bonzini | 3155252 | 2012-01-13 17:34:01 +0100 | [diff] [blame] | 2186 | notifier_remove(notify); |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | static void qemu_run_exit_notifiers(void) |
| 2190 | { |
Jan Kiszka | 9e8dd45 | 2011-06-20 14:06:26 +0200 | [diff] [blame] | 2191 | notifier_list_notify(&exit_notifiers, NULL); |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame] | 2192 | } |
| 2193 | |
Gleb Natapov | 4cab946 | 2010-12-08 13:35:08 +0200 | [diff] [blame] | 2194 | void qemu_add_machine_init_done_notifier(Notifier *notify) |
| 2195 | { |
| 2196 | notifier_list_add(&machine_init_done_notifiers, notify); |
| 2197 | } |
| 2198 | |
| 2199 | static void qemu_run_machine_init_done_notifiers(void) |
| 2200 | { |
Jan Kiszka | 9e8dd45 | 2011-06-20 14:06:26 +0200 | [diff] [blame] | 2201 | notifier_list_notify(&machine_init_done_notifiers, NULL); |
Gleb Natapov | 4cab946 | 2010-12-08 13:35:08 +0200 | [diff] [blame] | 2202 | } |
| 2203 | |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 2204 | static const QEMUOption *lookup_opt(int argc, char **argv, |
| 2205 | const char **poptarg, int *poptind) |
| 2206 | { |
| 2207 | const QEMUOption *popt; |
| 2208 | int optind = *poptind; |
| 2209 | char *r = argv[optind]; |
| 2210 | const char *optarg; |
| 2211 | |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 2212 | loc_set_cmdline(argv, optind, 1); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 2213 | optind++; |
| 2214 | /* Treat --foo the same as -foo. */ |
| 2215 | if (r[1] == '-') |
| 2216 | r++; |
| 2217 | popt = qemu_options; |
| 2218 | for(;;) { |
| 2219 | if (!popt->name) { |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 2220 | error_report("invalid option"); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 2221 | exit(1); |
| 2222 | } |
| 2223 | if (!strcmp(popt->name, r + 1)) |
| 2224 | break; |
| 2225 | popt++; |
| 2226 | } |
| 2227 | if (popt->flags & HAS_ARG) { |
| 2228 | if (optind >= argc) { |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 2229 | error_report("requires an argument"); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 2230 | exit(1); |
| 2231 | } |
| 2232 | optarg = argv[optind++]; |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 2233 | loc_set_cmdline(argv, optind - 2, 2); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 2234 | } else { |
| 2235 | optarg = NULL; |
| 2236 | } |
| 2237 | |
| 2238 | *poptarg = optarg; |
| 2239 | *poptind = optind; |
| 2240 | |
| 2241 | return popt; |
| 2242 | } |
| 2243 | |
Anthony Liguori | 0750112 | 2011-08-20 22:38:31 -0500 | [diff] [blame] | 2244 | static gpointer malloc_and_trace(gsize n_bytes) |
| 2245 | { |
| 2246 | void *ptr = malloc(n_bytes); |
Frediano Ziglio | a74cd8c | 2011-08-31 09:25:35 +0200 | [diff] [blame] | 2247 | trace_g_malloc(n_bytes, ptr); |
Anthony Liguori | 0750112 | 2011-08-20 22:38:31 -0500 | [diff] [blame] | 2248 | return ptr; |
| 2249 | } |
| 2250 | |
| 2251 | static gpointer realloc_and_trace(gpointer mem, gsize n_bytes) |
| 2252 | { |
| 2253 | void *ptr = realloc(mem, n_bytes); |
Frediano Ziglio | a74cd8c | 2011-08-31 09:25:35 +0200 | [diff] [blame] | 2254 | trace_g_realloc(mem, n_bytes, ptr); |
Anthony Liguori | 0750112 | 2011-08-20 22:38:31 -0500 | [diff] [blame] | 2255 | return ptr; |
| 2256 | } |
| 2257 | |
| 2258 | static void free_and_trace(gpointer mem) |
| 2259 | { |
Frediano Ziglio | a74cd8c | 2011-08-31 09:25:35 +0200 | [diff] [blame] | 2260 | trace_g_free(mem); |
Anthony Liguori | 0750112 | 2011-08-20 22:38:31 -0500 | [diff] [blame] | 2261 | free(mem); |
| 2262 | } |
| 2263 | |
Michael Roth | d34e8f6 | 2012-01-21 11:13:53 -0600 | [diff] [blame] | 2264 | int qemu_init_main_loop(void) |
| 2265 | { |
| 2266 | return main_loop_init(); |
| 2267 | } |
| 2268 | |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 2269 | int main(int argc, char **argv, char **envp) |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 2270 | { |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 2271 | int i; |
Eduardo Habkost | da1fcfd | 2010-04-06 19:22:07 -0300 | [diff] [blame] | 2272 | int snapshot, linux_boot; |
Paolo Bonzini | 4e3de9e | 2010-03-10 11:38:48 +0100 | [diff] [blame] | 2273 | const char *icount_option = NULL; |
bellard | 7f7f987 | 2003-10-30 01:11:23 +0000 | [diff] [blame] | 2274 | const char *initrd_filename; |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 2275 | const char *kernel_filename, *kernel_cmdline; |
Anthony Liguori | 195325a | 2009-10-30 12:42:29 -0500 | [diff] [blame] | 2276 | char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */ |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2277 | DisplayState *ds; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 2278 | DisplayChangeListener *dcl; |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 2279 | int cyls, heads, secs, translation; |
Peter Maydell | 967c0da | 2012-02-22 22:40:00 +0000 | [diff] [blame] | 2280 | QemuOpts *hda_opts = NULL, *opts, *machine_opts; |
Gerd Hoffmann | 03b0ba7 | 2010-08-20 13:52:02 +0200 | [diff] [blame] | 2281 | QemuOptsList *olist; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2282 | int optind; |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 2283 | const char *optarg; |
bellard | d63d307 | 2004-10-03 13:29:03 +0000 | [diff] [blame] | 2284 | const char *loadvm = NULL; |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 2285 | QEMUMachine *machine; |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 2286 | const char *cpu_model; |
Paolo Bonzini | 7f1b17f | 2012-05-10 09:39:17 +0200 | [diff] [blame] | 2287 | const char *vga_model = "none"; |
ths | 93815bc | 2007-03-19 15:58:31 +0000 | [diff] [blame] | 2288 | const char *pid_file = NULL; |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 2289 | const char *incoming = NULL; |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 2290 | #ifdef CONFIG_VNC |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2291 | int show_vnc_port = 0; |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 2292 | #endif |
Eduardo Habkost | 3ed2d9e | 2012-05-02 13:07:28 -0300 | [diff] [blame] | 2293 | bool defconfig = true; |
Eduardo Habkost | f29a561 | 2012-05-02 13:07:29 -0300 | [diff] [blame] | 2294 | bool userconfig = true; |
Matthew Fernandez | c235d73 | 2011-06-07 16:32:40 +0000 | [diff] [blame] | 2295 | const char *log_mask = NULL; |
| 2296 | const char *log_file = NULL; |
Anthony Liguori | 0750112 | 2011-08-20 22:38:31 -0500 | [diff] [blame] | 2297 | GMemVTable mem_trace = { |
| 2298 | .malloc = malloc_and_trace, |
| 2299 | .realloc = realloc_and_trace, |
| 2300 | .free = free_and_trace, |
| 2301 | }; |
LluÃs | 23d15e8 | 2011-08-31 20:31:31 +0200 | [diff] [blame] | 2302 | const char *trace_events = NULL; |
LluÃs | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 2303 | const char *trace_file = NULL; |
Stefan Hajnoczi | 0b5538c | 2011-02-26 18:38:39 +0000 | [diff] [blame] | 2304 | |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame] | 2305 | atexit(qemu_run_exit_notifiers); |
Markus Armbruster | 65abca0 | 2010-02-24 14:37:14 +0100 | [diff] [blame] | 2306 | error_set_progname(argv[0]); |
| 2307 | |
Anthony Liguori | 0750112 | 2011-08-20 22:38:31 -0500 | [diff] [blame] | 2308 | g_mem_set_vtable(&mem_trace); |
Andreas Färber | db529aa | 2011-10-31 19:14:56 +0100 | [diff] [blame] | 2309 | if (!g_thread_supported()) { |
Alon Levy | 42ed372 | 2011-12-20 13:41:04 +0200 | [diff] [blame] | 2310 | #if !GLIB_CHECK_VERSION(2, 31, 0) |
Andreas Färber | db529aa | 2011-10-31 19:14:56 +0100 | [diff] [blame] | 2311 | g_thread_init(NULL); |
Alon Levy | 42ed372 | 2011-12-20 13:41:04 +0200 | [diff] [blame] | 2312 | #else |
| 2313 | fprintf(stderr, "glib threading failed to initialize.\n"); |
| 2314 | exit(1); |
| 2315 | #endif |
Andreas Färber | db529aa | 2011-10-31 19:14:56 +0100 | [diff] [blame] | 2316 | } |
Anthony Liguori | 0750112 | 2011-08-20 22:38:31 -0500 | [diff] [blame] | 2317 | |
Andreas Färber | 1b71f7c | 2012-03-04 21:32:35 +0100 | [diff] [blame] | 2318 | module_call_init(MODULE_INIT_QOM); |
| 2319 | |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 2320 | runstate_init(); |
| 2321 | |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 2322 | init_clocks(); |
Paolo Bonzini | 2ff68d0 | 2011-09-12 16:21:44 +0200 | [diff] [blame] | 2323 | rtc_clock = host_clock; |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 2324 | |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 2325 | qemu_cache_utils_init(envp); |
| 2326 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2327 | QLIST_INIT (&vm_change_state_head); |
Jes Sorensen | fe98ac1 | 2010-06-10 11:42:21 +0200 | [diff] [blame] | 2328 | os_setup_early_signal_handling(); |
bellard | be995c2 | 2006-06-25 16:25:21 +0000 | [diff] [blame] | 2329 | |
Anthony Liguori | f80f9ec | 2009-05-20 18:38:09 -0500 | [diff] [blame] | 2330 | module_call_init(MODULE_INIT_MACHINE); |
Anthony Liguori | 0c25743 | 2009-05-21 20:41:01 -0500 | [diff] [blame] | 2331 | machine = find_default_machine(); |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 2332 | cpu_model = NULL; |
aurel32 | 4fc5d07 | 2008-04-27 21:39:40 +0000 | [diff] [blame] | 2333 | ram_size = 0; |
bellard | 33e3963 | 2003-07-06 17:15:21 +0000 | [diff] [blame] | 2334 | snapshot = 0; |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 2335 | cyls = heads = secs = 0; |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 2336 | translation = BIOS_ATA_TRANSLATION_AUTO; |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 2337 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 2338 | for (i = 0; i < MAX_NODES; i++) { |
| 2339 | node_mem[i] = 0; |
| 2340 | node_cpumask[i] = 0; |
| 2341 | } |
| 2342 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 2343 | nb_numa_nodes = 0; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 2344 | nb_nics = 0; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2345 | |
blueswir1 | 41bd639 | 2008-10-05 09:56:21 +0000 | [diff] [blame] | 2346 | autostart= 1; |
| 2347 | |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 2348 | /* first pass of option parsing */ |
| 2349 | optind = 1; |
| 2350 | while (optind < argc) { |
| 2351 | if (argv[optind][0] != '-') { |
| 2352 | /* disk image */ |
Anthony Liguori | 28e68d6 | 2010-01-27 10:46:00 -0600 | [diff] [blame] | 2353 | optind++; |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 2354 | continue; |
| 2355 | } else { |
| 2356 | const QEMUOption *popt; |
| 2357 | |
| 2358 | popt = lookup_opt(argc, argv, &optarg, &optind); |
| 2359 | switch (popt->index) { |
| 2360 | case QEMU_OPTION_nodefconfig: |
Eduardo Habkost | 3ed2d9e | 2012-05-02 13:07:28 -0300 | [diff] [blame] | 2361 | defconfig = false; |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 2362 | break; |
Eduardo Habkost | f29a561 | 2012-05-02 13:07:29 -0300 | [diff] [blame] | 2363 | case QEMU_OPTION_nouserconfig: |
| 2364 | userconfig = false; |
| 2365 | break; |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 2366 | } |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | if (defconfig) { |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 2371 | int ret; |
Eduardo Habkost | f29a561 | 2012-05-02 13:07:29 -0300 | [diff] [blame] | 2372 | ret = qemu_read_default_config_files(userconfig); |
Eduardo Habkost | b5a8fe5 | 2012-05-02 13:07:25 -0300 | [diff] [blame] | 2373 | if (ret < 0) { |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 2374 | exit(1); |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | /* second pass of option parsing */ |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2379 | optind = 1; |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 2380 | for(;;) { |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2381 | if (optind >= argc) |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 2382 | break; |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 2383 | if (argv[optind][0] != '-') { |
Markus Armbruster | 2292dda | 2011-01-28 11:21:41 +0100 | [diff] [blame] | 2384 | hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2385 | } else { |
| 2386 | const QEMUOption *popt; |
| 2387 | |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 2388 | popt = lookup_opt(argc, argv, &optarg, &optind); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 2389 | if (!(popt->arch_mask & arch_type)) { |
| 2390 | printf("Option %s not supported for this target\n", popt->name); |
| 2391 | exit(1); |
| 2392 | } |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2393 | switch(popt->index) { |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 2394 | case QEMU_OPTION_M: |
Jan Kiszka | 9052ea6 | 2011-07-23 12:38:37 +0200 | [diff] [blame] | 2395 | machine = machine_parse(optarg); |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 2396 | break; |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 2397 | case QEMU_OPTION_cpu: |
| 2398 | /* hw initialization will check this */ |
Eduardo Habkost | ecf40be | 2012-03-09 16:19:07 -0300 | [diff] [blame] | 2399 | cpu_model = optarg; |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 2400 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2401 | case QEMU_OPTION_hda: |
Markus Armbruster | 5645b0f | 2011-01-31 11:50:09 +0100 | [diff] [blame] | 2402 | { |
| 2403 | char buf[256]; |
| 2404 | if (cyls == 0) |
| 2405 | snprintf(buf, sizeof(buf), "%s", HD_OPTS); |
| 2406 | else |
| 2407 | snprintf(buf, sizeof(buf), |
| 2408 | "%s,cyls=%d,heads=%d,secs=%d%s", |
| 2409 | HD_OPTS , cyls, heads, secs, |
| 2410 | translation == BIOS_ATA_TRANSLATION_LBA ? |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 2411 | ",trans=lba" : |
Markus Armbruster | 5645b0f | 2011-01-31 11:50:09 +0100 | [diff] [blame] | 2412 | translation == BIOS_ATA_TRANSLATION_NONE ? |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 2413 | ",trans=none" : ""); |
Markus Armbruster | 5645b0f | 2011-01-31 11:50:09 +0100 | [diff] [blame] | 2414 | drive_add(IF_DEFAULT, 0, optarg, buf); |
| 2415 | break; |
| 2416 | } |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2417 | case QEMU_OPTION_hdb: |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 2418 | case QEMU_OPTION_hdc: |
| 2419 | case QEMU_OPTION_hdd: |
Markus Armbruster | 2292dda | 2011-01-28 11:21:41 +0100 | [diff] [blame] | 2420 | drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg, |
| 2421 | HD_OPTS); |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 2422 | break; |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 2423 | case QEMU_OPTION_drive: |
Michael Tokarev | e2982c3 | 2011-03-30 16:31:05 +0400 | [diff] [blame] | 2424 | if (drive_def(optarg) == NULL) { |
| 2425 | exit(1); |
| 2426 | } |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 2427 | break; |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 2428 | case QEMU_OPTION_set: |
| 2429 | if (qemu_set_option(optarg) != 0) |
| 2430 | exit(1); |
| 2431 | break; |
Gerd Hoffmann | d0fef6f | 2009-12-08 13:11:34 +0100 | [diff] [blame] | 2432 | case QEMU_OPTION_global: |
| 2433 | if (qemu_global_option(optarg) != 0) |
| 2434 | exit(1); |
| 2435 | break; |
balrog | 3e3d581 | 2007-04-30 02:09:25 +0000 | [diff] [blame] | 2436 | case QEMU_OPTION_mtdblock: |
Markus Armbruster | 2292dda | 2011-01-28 11:21:41 +0100 | [diff] [blame] | 2437 | drive_add(IF_MTD, -1, optarg, MTD_OPTS); |
balrog | 3e3d581 | 2007-04-30 02:09:25 +0000 | [diff] [blame] | 2438 | break; |
pbrook | a1bb27b | 2007-04-06 16:49:48 +0000 | [diff] [blame] | 2439 | case QEMU_OPTION_sd: |
Markus Armbruster | 2292dda | 2011-01-28 11:21:41 +0100 | [diff] [blame] | 2440 | drive_add(IF_SD, 0, optarg, SD_OPTS); |
pbrook | a1bb27b | 2007-04-06 16:49:48 +0000 | [diff] [blame] | 2441 | break; |
j_mayer | 86f5566 | 2007-04-24 06:52:59 +0000 | [diff] [blame] | 2442 | case QEMU_OPTION_pflash: |
Markus Armbruster | 2292dda | 2011-01-28 11:21:41 +0100 | [diff] [blame] | 2443 | drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS); |
j_mayer | 86f5566 | 2007-04-24 06:52:59 +0000 | [diff] [blame] | 2444 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2445 | case QEMU_OPTION_snapshot: |
bellard | 33e3963 | 2003-07-06 17:15:21 +0000 | [diff] [blame] | 2446 | snapshot = 1; |
| 2447 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2448 | case QEMU_OPTION_hdachs: |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 2449 | { |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 2450 | const char *p; |
| 2451 | p = optarg; |
| 2452 | cyls = strtol(p, (char **)&p, 0); |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 2453 | if (cyls < 1 || cyls > 16383) |
| 2454 | goto chs_fail; |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 2455 | if (*p != ',') |
| 2456 | goto chs_fail; |
| 2457 | p++; |
| 2458 | heads = strtol(p, (char **)&p, 0); |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 2459 | if (heads < 1 || heads > 16) |
| 2460 | goto chs_fail; |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 2461 | if (*p != ',') |
| 2462 | goto chs_fail; |
| 2463 | p++; |
| 2464 | secs = strtol(p, (char **)&p, 0); |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 2465 | if (secs < 1 || secs > 63) |
| 2466 | goto chs_fail; |
| 2467 | if (*p == ',') { |
| 2468 | p++; |
| 2469 | if (!strcmp(p, "none")) |
| 2470 | translation = BIOS_ATA_TRANSLATION_NONE; |
| 2471 | else if (!strcmp(p, "lba")) |
| 2472 | translation = BIOS_ATA_TRANSLATION_LBA; |
| 2473 | else if (!strcmp(p, "auto")) |
| 2474 | translation = BIOS_ATA_TRANSLATION_AUTO; |
| 2475 | else |
| 2476 | goto chs_fail; |
| 2477 | } else if (*p != '\0') { |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 2478 | chs_fail: |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 2479 | fprintf(stderr, "qemu: invalid physical CHS format\n"); |
| 2480 | exit(1); |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 2481 | } |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 2482 | if (hda_opts != NULL) { |
| 2483 | char num[16]; |
| 2484 | snprintf(num, sizeof(num), "%d", cyls); |
| 2485 | qemu_opt_set(hda_opts, "cyls", num); |
| 2486 | snprintf(num, sizeof(num), "%d", heads); |
| 2487 | qemu_opt_set(hda_opts, "heads", num); |
| 2488 | snprintf(num, sizeof(num), "%d", secs); |
| 2489 | qemu_opt_set(hda_opts, "secs", num); |
| 2490 | if (translation == BIOS_ATA_TRANSLATION_LBA) |
| 2491 | qemu_opt_set(hda_opts, "trans", "lba"); |
| 2492 | if (translation == BIOS_ATA_TRANSLATION_NONE) |
| 2493 | qemu_opt_set(hda_opts, "trans", "none"); |
| 2494 | } |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 2495 | } |
| 2496 | break; |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 2497 | case QEMU_OPTION_numa: |
| 2498 | if (nb_numa_nodes >= MAX_NODES) { |
| 2499 | fprintf(stderr, "qemu: too many NUMA nodes\n"); |
| 2500 | exit(1); |
| 2501 | } |
| 2502 | numa_add(optarg); |
| 2503 | break; |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 2504 | case QEMU_OPTION_display: |
| 2505 | display_type = select_display(optarg); |
| 2506 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2507 | case QEMU_OPTION_nographic: |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2508 | display_type = DT_NOGRAPHIC; |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 2509 | break; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 2510 | case QEMU_OPTION_curses: |
Jes Sorensen | 47b0536 | 2011-03-16 13:33:35 +0100 | [diff] [blame] | 2511 | #ifdef CONFIG_CURSES |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2512 | display_type = DT_CURSES; |
Jes Sorensen | 47b0536 | 2011-03-16 13:33:35 +0100 | [diff] [blame] | 2513 | #else |
| 2514 | fprintf(stderr, "Curses support is disabled\n"); |
| 2515 | exit(1); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 2516 | #endif |
Jes Sorensen | 47b0536 | 2011-03-16 13:33:35 +0100 | [diff] [blame] | 2517 | break; |
balrog | a171fe3 | 2007-04-30 01:48:07 +0000 | [diff] [blame] | 2518 | case QEMU_OPTION_portrait: |
Vasily Khoruzhick | 9312805 | 2011-06-17 13:04:36 +0300 | [diff] [blame] | 2519 | graphic_rotate = 90; |
| 2520 | break; |
| 2521 | case QEMU_OPTION_rotate: |
| 2522 | graphic_rotate = strtol(optarg, (char **) &optarg, 10); |
| 2523 | if (graphic_rotate != 0 && graphic_rotate != 90 && |
| 2524 | graphic_rotate != 180 && graphic_rotate != 270) { |
| 2525 | fprintf(stderr, |
| 2526 | "qemu: only 90, 180, 270 deg rotation is available\n"); |
| 2527 | exit(1); |
| 2528 | } |
balrog | a171fe3 | 2007-04-30 01:48:07 +0000 | [diff] [blame] | 2529 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2530 | case QEMU_OPTION_kernel: |
Peter Maydell | a0abe47 | 2012-02-08 05:41:39 +0000 | [diff] [blame] | 2531 | qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg); |
| 2532 | break; |
| 2533 | case QEMU_OPTION_initrd: |
| 2534 | qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg); |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 2535 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2536 | case QEMU_OPTION_append: |
Peter Maydell | a0abe47 | 2012-02-08 05:41:39 +0000 | [diff] [blame] | 2537 | qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg); |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 2538 | break; |
Grant Likely | 412beee | 2012-03-02 11:56:38 +0000 | [diff] [blame] | 2539 | case QEMU_OPTION_dtb: |
| 2540 | qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg); |
| 2541 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2542 | case QEMU_OPTION_cdrom: |
Markus Armbruster | 2292dda | 2011-01-28 11:21:41 +0100 | [diff] [blame] | 2543 | drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS); |
bellard | 36b486b | 2003-11-11 13:36:08 +0000 | [diff] [blame] | 2544 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2545 | case QEMU_OPTION_boot: |
j_mayer | 28c5af5 | 2007-11-11 01:50:45 +0000 | [diff] [blame] | 2546 | { |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2547 | static const char * const params[] = { |
wayne | 3d3b830 | 2011-07-27 18:04:55 +0800 | [diff] [blame] | 2548 | "order", "once", "menu", |
| 2549 | "splash", "splash-time", NULL |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2550 | }; |
| 2551 | char buf[sizeof(boot_devices)]; |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2552 | char *standard_boot_devices; |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2553 | int legacy = 0; |
| 2554 | |
| 2555 | if (!strchr(optarg, '=')) { |
| 2556 | legacy = 1; |
| 2557 | pstrcpy(buf, sizeof(buf), optarg); |
| 2558 | } else if (check_params(buf, sizeof(buf), params, optarg) < 0) { |
| 2559 | fprintf(stderr, |
| 2560 | "qemu: unknown boot parameter '%s' in '%s'\n", |
| 2561 | buf, optarg); |
| 2562 | exit(1); |
| 2563 | } |
| 2564 | |
| 2565 | if (legacy || |
| 2566 | get_param_value(buf, sizeof(buf), "order", optarg)) { |
Eduardo Habkost | 4e9e9d6 | 2010-04-06 19:22:08 -0300 | [diff] [blame] | 2567 | validate_bootdevices(buf); |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2568 | pstrcpy(boot_devices, sizeof(boot_devices), buf); |
j_mayer | 28c5af5 | 2007-11-11 01:50:45 +0000 | [diff] [blame] | 2569 | } |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2570 | if (!legacy) { |
| 2571 | if (get_param_value(buf, sizeof(buf), |
| 2572 | "once", optarg)) { |
Eduardo Habkost | 4e9e9d6 | 2010-04-06 19:22:08 -0300 | [diff] [blame] | 2573 | validate_bootdevices(buf); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 2574 | standard_boot_devices = g_strdup(boot_devices); |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2575 | pstrcpy(boot_devices, sizeof(boot_devices), buf); |
| 2576 | qemu_register_reset(restore_boot_devices, |
| 2577 | standard_boot_devices); |
| 2578 | } |
Jan Kiszka | 9538749 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2579 | if (get_param_value(buf, sizeof(buf), |
| 2580 | "menu", optarg)) { |
| 2581 | if (!strcmp(buf, "on")) { |
| 2582 | boot_menu = 1; |
| 2583 | } else if (!strcmp(buf, "off")) { |
| 2584 | boot_menu = 0; |
| 2585 | } else { |
| 2586 | fprintf(stderr, |
| 2587 | "qemu: invalid option value '%s'\n", |
| 2588 | buf); |
| 2589 | exit(1); |
| 2590 | } |
| 2591 | } |
wayne | 3d3b830 | 2011-07-27 18:04:55 +0800 | [diff] [blame] | 2592 | qemu_opts_parse(qemu_find_opts("boot-opts"), |
| 2593 | optarg, 0); |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2594 | } |
bellard | 36b486b | 2003-11-11 13:36:08 +0000 | [diff] [blame] | 2595 | } |
| 2596 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2597 | case QEMU_OPTION_fda: |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2598 | case QEMU_OPTION_fdb: |
Markus Armbruster | 2292dda | 2011-01-28 11:21:41 +0100 | [diff] [blame] | 2599 | drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda, |
| 2600 | optarg, FD_OPTS); |
bellard | c45886d | 2004-01-05 00:02:06 +0000 | [diff] [blame] | 2601 | break; |
bellard | 52ca8d6 | 2006-06-14 16:03:05 +0000 | [diff] [blame] | 2602 | case QEMU_OPTION_no_fd_bootchk: |
| 2603 | fd_bootchk = 0; |
| 2604 | break; |
Mark McLoughlin | a1ea458 | 2009-10-08 19:58:26 +0100 | [diff] [blame] | 2605 | case QEMU_OPTION_netdev: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2606 | if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) { |
Mark McLoughlin | a1ea458 | 2009-10-08 19:58:26 +0100 | [diff] [blame] | 2607 | exit(1); |
| 2608 | } |
| 2609 | break; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 2610 | case QEMU_OPTION_net: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2611 | if (net_client_parse(qemu_find_opts("net"), optarg) == -1) { |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 2612 | exit(1); |
| 2613 | } |
bellard | 702c651 | 2004-04-02 21:21:32 +0000 | [diff] [blame] | 2614 | break; |
Ronnie Sahlberg | f9dadc9 | 2012-01-26 09:39:02 +1100 | [diff] [blame] | 2615 | #ifdef CONFIG_LIBISCSI |
| 2616 | case QEMU_OPTION_iscsi: |
| 2617 | opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0); |
| 2618 | if (!opts) { |
| 2619 | exit(1); |
| 2620 | } |
| 2621 | break; |
| 2622 | #endif |
bellard | c7f7464 | 2004-08-24 21:57:12 +0000 | [diff] [blame] | 2623 | #ifdef CONFIG_SLIRP |
| 2624 | case QEMU_OPTION_tftp: |
Jan Kiszka | ad196a9 | 2009-06-24 14:42:28 +0200 | [diff] [blame] | 2625 | legacy_tftp_prefix = optarg; |
bellard | 9bf0544 | 2004-08-25 22:12:49 +0000 | [diff] [blame] | 2626 | break; |
ths | 47d5d01 | 2007-02-20 00:05:08 +0000 | [diff] [blame] | 2627 | case QEMU_OPTION_bootp: |
Jan Kiszka | ad196a9 | 2009-06-24 14:42:28 +0200 | [diff] [blame] | 2628 | legacy_bootp_filename = optarg; |
ths | 47d5d01 | 2007-02-20 00:05:08 +0000 | [diff] [blame] | 2629 | break; |
bellard | 9bf0544 | 2004-08-25 22:12:49 +0000 | [diff] [blame] | 2630 | case QEMU_OPTION_redir: |
Markus Armbruster | 0752706 | 2009-10-06 12:16:57 +0100 | [diff] [blame] | 2631 | if (net_slirp_redir(optarg) < 0) |
| 2632 | exit(1); |
bellard | 9bf0544 | 2004-08-25 22:12:49 +0000 | [diff] [blame] | 2633 | break; |
bellard | c7f7464 | 2004-08-24 21:57:12 +0000 | [diff] [blame] | 2634 | #endif |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 2635 | case QEMU_OPTION_bt: |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2636 | add_device_config(DEV_BT, optarg); |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 2637 | break; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 2638 | case QEMU_OPTION_audio_help: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 2639 | if (!(audio_available())) { |
| 2640 | printf("Option %s not supported for this target\n", popt->name); |
| 2641 | exit(1); |
| 2642 | } |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 2643 | AUD_help (); |
| 2644 | exit (0); |
| 2645 | break; |
| 2646 | case QEMU_OPTION_soundhw: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 2647 | if (!(audio_available())) { |
| 2648 | printf("Option %s not supported for this target\n", popt->name); |
| 2649 | exit(1); |
| 2650 | } |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 2651 | select_soundhw (optarg); |
| 2652 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2653 | case QEMU_OPTION_h: |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 2654 | help(0); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2655 | break; |
pbrook | 9bd7e6d | 2009-04-07 22:58:45 +0000 | [diff] [blame] | 2656 | case QEMU_OPTION_version: |
| 2657 | version(); |
| 2658 | exit(0); |
| 2659 | break; |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2660 | case QEMU_OPTION_m: { |
Jes Sorensen | 70b4f4b | 2011-01-05 11:41:02 +0100 | [diff] [blame] | 2661 | int64_t value; |
Markus Armbruster | 961b42b | 2011-11-22 09:46:03 +0100 | [diff] [blame] | 2662 | char *end; |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2663 | |
Markus Armbruster | 961b42b | 2011-11-22 09:46:03 +0100 | [diff] [blame] | 2664 | value = strtosz(optarg, &end); |
| 2665 | if (value < 0 || *end) { |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2666 | fprintf(stderr, "qemu: invalid ram size: %s\n", optarg); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2667 | exit(1); |
| 2668 | } |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2669 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2670 | if (value != (uint64_t)(ram_addr_t)value) { |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2671 | fprintf(stderr, "qemu: ram size too large\n"); |
| 2672 | exit(1); |
| 2673 | } |
| 2674 | ram_size = value; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2675 | break; |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2676 | } |
Marcelo Tosatti | c902760 | 2010-03-01 20:25:08 -0300 | [diff] [blame] | 2677 | case QEMU_OPTION_mempath: |
| 2678 | mem_path = optarg; |
| 2679 | break; |
| 2680 | #ifdef MAP_POPULATE |
| 2681 | case QEMU_OPTION_mem_prealloc: |
| 2682 | mem_prealloc = 1; |
| 2683 | break; |
| 2684 | #endif |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2685 | case QEMU_OPTION_d: |
Matthew Fernandez | c235d73 | 2011-06-07 16:32:40 +0000 | [diff] [blame] | 2686 | log_mask = optarg; |
| 2687 | break; |
| 2688 | case QEMU_OPTION_D: |
| 2689 | log_file = optarg; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2690 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2691 | case QEMU_OPTION_s: |
Markus Armbruster | ef0c4a0 | 2012-02-07 15:09:13 +0100 | [diff] [blame] | 2692 | add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2693 | break; |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 2694 | case QEMU_OPTION_gdb: |
Markus Armbruster | ef0c4a0 | 2012-02-07 15:09:13 +0100 | [diff] [blame] | 2695 | add_device_config(DEV_GDB, optarg); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2696 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2697 | case QEMU_OPTION_L: |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 2698 | data_dir = optarg; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2699 | break; |
j_mayer | 1192dad | 2007-10-05 13:08:35 +0000 | [diff] [blame] | 2700 | case QEMU_OPTION_bios: |
| 2701 | bios_name = optarg; |
| 2702 | break; |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 2703 | case QEMU_OPTION_singlestep: |
| 2704 | singlestep = 1; |
| 2705 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2706 | case QEMU_OPTION_S: |
pbrook | 3c07f8e | 2007-01-21 16:47:01 +0000 | [diff] [blame] | 2707 | autostart = 0; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2708 | break; |
bellard | 3d11d0e | 2004-12-12 16:56:30 +0000 | [diff] [blame] | 2709 | case QEMU_OPTION_k: |
| 2710 | keyboard_layout = optarg; |
| 2711 | break; |
bellard | ee22c2f | 2004-06-03 12:49:50 +0000 | [diff] [blame] | 2712 | case QEMU_OPTION_localtime: |
| 2713 | rtc_utc = 0; |
| 2714 | break; |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 2715 | case QEMU_OPTION_vga: |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 2716 | vga_model = optarg; |
Paolo Bonzini | 7f1b17f | 2012-05-10 09:39:17 +0200 | [diff] [blame] | 2717 | default_vga = 0; |
bellard | 1bfe856 | 2004-07-08 21:17:50 +0000 | [diff] [blame] | 2718 | break; |
bellard | e9b137c | 2004-06-21 16:46:10 +0000 | [diff] [blame] | 2719 | case QEMU_OPTION_g: |
| 2720 | { |
| 2721 | const char *p; |
| 2722 | int w, h, depth; |
| 2723 | p = optarg; |
| 2724 | w = strtol(p, (char **)&p, 10); |
| 2725 | if (w <= 0) { |
| 2726 | graphic_error: |
| 2727 | fprintf(stderr, "qemu: invalid resolution or depth\n"); |
| 2728 | exit(1); |
| 2729 | } |
| 2730 | if (*p != 'x') |
| 2731 | goto graphic_error; |
| 2732 | p++; |
| 2733 | h = strtol(p, (char **)&p, 10); |
| 2734 | if (h <= 0) |
| 2735 | goto graphic_error; |
| 2736 | if (*p == 'x') { |
| 2737 | p++; |
| 2738 | depth = strtol(p, (char **)&p, 10); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 2739 | if (depth != 8 && depth != 15 && depth != 16 && |
bellard | e9b137c | 2004-06-21 16:46:10 +0000 | [diff] [blame] | 2740 | depth != 24 && depth != 32) |
| 2741 | goto graphic_error; |
| 2742 | } else if (*p == '\0') { |
| 2743 | depth = graphic_depth; |
| 2744 | } else { |
| 2745 | goto graphic_error; |
| 2746 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2747 | |
bellard | e9b137c | 2004-06-21 16:46:10 +0000 | [diff] [blame] | 2748 | graphic_width = w; |
| 2749 | graphic_height = h; |
| 2750 | graphic_depth = depth; |
| 2751 | } |
| 2752 | break; |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 2753 | case QEMU_OPTION_echr: |
| 2754 | { |
| 2755 | char *r; |
| 2756 | term_escape_char = strtol(optarg, &r, 0); |
| 2757 | if (r == optarg) |
| 2758 | printf("Bad argument to echr\n"); |
| 2759 | break; |
| 2760 | } |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 2761 | case QEMU_OPTION_monitor: |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 2762 | monitor_parse(optarg, "readline"); |
| 2763 | default_monitor = 0; |
| 2764 | break; |
| 2765 | case QEMU_OPTION_qmp: |
| 2766 | monitor_parse(optarg, "control"); |
Anthony Liguori | 2d114dc | 2010-03-21 14:14:38 -0500 | [diff] [blame] | 2767 | default_monitor = 0; |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 2768 | break; |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 2769 | case QEMU_OPTION_mon: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2770 | opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1); |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 2771 | if (!opts) { |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 2772 | exit(1); |
| 2773 | } |
Anthony Liguori | 2d114dc | 2010-03-21 14:14:38 -0500 | [diff] [blame] | 2774 | default_monitor = 0; |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 2775 | break; |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 2776 | case QEMU_OPTION_chardev: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2777 | opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1); |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 2778 | if (!opts) { |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 2779 | exit(1); |
| 2780 | } |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 2781 | break; |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 2782 | case QEMU_OPTION_fsdev: |
Gerd Hoffmann | 03b0ba7 | 2010-08-20 13:52:02 +0200 | [diff] [blame] | 2783 | olist = qemu_find_opts("fsdev"); |
| 2784 | if (!olist) { |
| 2785 | fprintf(stderr, "fsdev is not supported by this qemu build.\n"); |
| 2786 | exit(1); |
| 2787 | } |
| 2788 | opts = qemu_opts_parse(olist, optarg, 1); |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 2789 | if (!opts) { |
| 2790 | fprintf(stderr, "parse error: %s\n", optarg); |
| 2791 | exit(1); |
| 2792 | } |
| 2793 | break; |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2794 | case QEMU_OPTION_virtfs: { |
Stefan Hajnoczi | e14ea47 | 2011-03-16 08:31:43 +0000 | [diff] [blame] | 2795 | QemuOpts *fsdev; |
| 2796 | QemuOpts *device; |
M. Mohan Kumar | 84a87cc | 2011-12-14 13:58:47 +0530 | [diff] [blame] | 2797 | const char *writeout, *sock_fd, *socket; |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2798 | |
Gerd Hoffmann | 03b0ba7 | 2010-08-20 13:52:02 +0200 | [diff] [blame] | 2799 | olist = qemu_find_opts("virtfs"); |
| 2800 | if (!olist) { |
| 2801 | fprintf(stderr, "virtfs is not supported by this qemu build.\n"); |
| 2802 | exit(1); |
| 2803 | } |
| 2804 | opts = qemu_opts_parse(olist, optarg, 1); |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2805 | if (!opts) { |
| 2806 | fprintf(stderr, "parse error: %s\n", optarg); |
| 2807 | exit(1); |
| 2808 | } |
| 2809 | |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame] | 2810 | if (qemu_opt_get(opts, "fsdriver") == NULL || |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 2811 | qemu_opt_get(opts, "mount_tag") == NULL) { |
| 2812 | fprintf(stderr, "Usage: -virtfs fsdriver,mount_tag=tag.\n"); |
Venkateswararao Jujjuri (JV) | 9ce56db | 2010-06-14 13:34:40 -0700 | [diff] [blame] | 2813 | exit(1); |
| 2814 | } |
Stefan Hajnoczi | e14ea47 | 2011-03-16 08:31:43 +0000 | [diff] [blame] | 2815 | fsdev = qemu_opts_create(qemu_find_opts("fsdev"), |
| 2816 | qemu_opt_get(opts, "mount_tag"), 1); |
| 2817 | if (!fsdev) { |
| 2818 | fprintf(stderr, "duplicate fsdev id: %s\n", |
| 2819 | qemu_opt_get(opts, "mount_tag")); |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2820 | exit(1); |
| 2821 | } |
Aneesh Kumar K.V | d3ab98e | 2011-10-12 19:11:23 +0530 | [diff] [blame] | 2822 | |
| 2823 | writeout = qemu_opt_get(opts, "writeout"); |
| 2824 | if (writeout) { |
| 2825 | #ifdef CONFIG_SYNC_FILE_RANGE |
| 2826 | qemu_opt_set(fsdev, "writeout", writeout); |
| 2827 | #else |
| 2828 | fprintf(stderr, "writeout=immediate not supported on " |
| 2829 | "this platform\n"); |
| 2830 | exit(1); |
| 2831 | #endif |
| 2832 | } |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame] | 2833 | qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver")); |
Stefan Hajnoczi | e14ea47 | 2011-03-16 08:31:43 +0000 | [diff] [blame] | 2834 | qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path")); |
| 2835 | qemu_opt_set(fsdev, "security_model", |
| 2836 | qemu_opt_get(opts, "security_model")); |
M. Mohan Kumar | 84a87cc | 2011-12-14 13:58:47 +0530 | [diff] [blame] | 2837 | socket = qemu_opt_get(opts, "socket"); |
| 2838 | if (socket) { |
| 2839 | qemu_opt_set(fsdev, "socket", socket); |
| 2840 | } |
M. Mohan Kumar | 4c793dd | 2011-12-14 13:49:28 +0530 | [diff] [blame] | 2841 | sock_fd = qemu_opt_get(opts, "sock_fd"); |
| 2842 | if (sock_fd) { |
| 2843 | qemu_opt_set(fsdev, "sock_fd", sock_fd); |
| 2844 | } |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2845 | |
M. Mohan Kumar | 2c74c2c | 2011-10-25 12:10:39 +0530 | [diff] [blame] | 2846 | qemu_opt_set_bool(fsdev, "readonly", |
| 2847 | qemu_opt_get_bool(opts, "readonly", 0)); |
Stefan Hajnoczi | e14ea47 | 2011-03-16 08:31:43 +0000 | [diff] [blame] | 2848 | device = qemu_opts_create(qemu_find_opts("device"), NULL, 0); |
| 2849 | qemu_opt_set(device, "driver", "virtio-9p-pci"); |
| 2850 | qemu_opt_set(device, "fsdev", |
| 2851 | qemu_opt_get(opts, "mount_tag")); |
| 2852 | qemu_opt_set(device, "mount_tag", |
| 2853 | qemu_opt_get(opts, "mount_tag")); |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2854 | break; |
| 2855 | } |
Aneesh Kumar K.V | 9db221a | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 2856 | case QEMU_OPTION_virtfs_synth: { |
| 2857 | QemuOpts *fsdev; |
| 2858 | QemuOpts *device; |
| 2859 | |
| 2860 | fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth", 1); |
| 2861 | if (!fsdev) { |
| 2862 | fprintf(stderr, "duplicate option: %s\n", "virtfs_synth"); |
| 2863 | exit(1); |
| 2864 | } |
| 2865 | qemu_opt_set(fsdev, "fsdriver", "synth"); |
Aneesh Kumar K.V | 9db221a | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 2866 | |
| 2867 | device = qemu_opts_create(qemu_find_opts("device"), NULL, 0); |
| 2868 | qemu_opt_set(device, "driver", "virtio-9p-pci"); |
| 2869 | qemu_opt_set(device, "fsdev", "v_synth"); |
| 2870 | qemu_opt_set(device, "mount_tag", "v_synth"); |
| 2871 | break; |
| 2872 | } |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 2873 | case QEMU_OPTION_serial: |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 2874 | add_device_config(DEV_SERIAL, optarg); |
| 2875 | default_serial = 0; |
Jan Kiszka | 18141ed | 2010-03-07 11:28:40 +0100 | [diff] [blame] | 2876 | if (strncmp(optarg, "mon:", 4) == 0) { |
| 2877 | default_monitor = 0; |
| 2878 | } |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 2879 | break; |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 2880 | case QEMU_OPTION_watchdog: |
Markus Armbruster | 09aaa16 | 2009-08-21 10:31:34 +0200 | [diff] [blame] | 2881 | if (watchdog) { |
| 2882 | fprintf(stderr, |
| 2883 | "qemu: only one watchdog option may be given\n"); |
| 2884 | return 1; |
| 2885 | } |
| 2886 | watchdog = optarg; |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 2887 | break; |
| 2888 | case QEMU_OPTION_watchdog_action: |
| 2889 | if (select_watchdog_action(optarg) == -1) { |
| 2890 | fprintf(stderr, "Unknown -watchdog-action parameter\n"); |
| 2891 | exit(1); |
| 2892 | } |
| 2893 | break; |
aliguori | 51ecf13 | 2009-01-15 20:06:40 +0000 | [diff] [blame] | 2894 | case QEMU_OPTION_virtiocon: |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2895 | add_device_config(DEV_VIRTCON, optarg); |
| 2896 | default_virtcon = 0; |
Jan Kiszka | 18141ed | 2010-03-07 11:28:40 +0100 | [diff] [blame] | 2897 | if (strncmp(optarg, "mon:", 4) == 0) { |
| 2898 | default_monitor = 0; |
| 2899 | } |
aliguori | 51ecf13 | 2009-01-15 20:06:40 +0000 | [diff] [blame] | 2900 | break; |
bellard | 6508fe5 | 2005-01-15 12:02:56 +0000 | [diff] [blame] | 2901 | case QEMU_OPTION_parallel: |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 2902 | add_device_config(DEV_PARALLEL, optarg); |
| 2903 | default_parallel = 0; |
Jan Kiszka | 18141ed | 2010-03-07 11:28:40 +0100 | [diff] [blame] | 2904 | if (strncmp(optarg, "mon:", 4) == 0) { |
| 2905 | default_monitor = 0; |
| 2906 | } |
bellard | 6508fe5 | 2005-01-15 12:02:56 +0000 | [diff] [blame] | 2907 | break; |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 2908 | case QEMU_OPTION_debugcon: |
| 2909 | add_device_config(DEV_DEBUGCON, optarg); |
| 2910 | break; |
bellard | d63d307 | 2004-10-03 13:29:03 +0000 | [diff] [blame] | 2911 | case QEMU_OPTION_loadvm: |
| 2912 | loadvm = optarg; |
| 2913 | break; |
| 2914 | case QEMU_OPTION_full_screen: |
| 2915 | full_screen = 1; |
| 2916 | break; |
ths | 667acca | 2006-12-11 02:08:05 +0000 | [diff] [blame] | 2917 | #ifdef CONFIG_SDL |
ths | 43523e9 | 2007-02-18 18:19:32 +0000 | [diff] [blame] | 2918 | case QEMU_OPTION_no_frame: |
| 2919 | no_frame = 1; |
| 2920 | break; |
ths | 3780e19 | 2007-06-21 21:08:02 +0000 | [diff] [blame] | 2921 | case QEMU_OPTION_alt_grab: |
| 2922 | alt_grab = 1; |
| 2923 | break; |
Dustin Kirkland | 0ca9f8a | 2009-09-17 15:48:04 -0500 | [diff] [blame] | 2924 | case QEMU_OPTION_ctrl_grab: |
| 2925 | ctrl_grab = 1; |
| 2926 | break; |
ths | 667acca | 2006-12-11 02:08:05 +0000 | [diff] [blame] | 2927 | case QEMU_OPTION_no_quit: |
| 2928 | no_quit = 1; |
| 2929 | break; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 2930 | case QEMU_OPTION_sdl: |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2931 | display_type = DT_SDL; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 2932 | break; |
Jes Sorensen | 58fc096 | 2011-03-16 13:33:34 +0100 | [diff] [blame] | 2933 | #else |
| 2934 | case QEMU_OPTION_no_frame: |
| 2935 | case QEMU_OPTION_alt_grab: |
| 2936 | case QEMU_OPTION_ctrl_grab: |
| 2937 | case QEMU_OPTION_no_quit: |
| 2938 | case QEMU_OPTION_sdl: |
| 2939 | fprintf(stderr, "SDL support is disabled\n"); |
| 2940 | exit(1); |
ths | 667acca | 2006-12-11 02:08:05 +0000 | [diff] [blame] | 2941 | #endif |
bellard | f7cce89 | 2004-12-08 22:21:25 +0000 | [diff] [blame] | 2942 | case QEMU_OPTION_pidfile: |
ths | 93815bc | 2007-03-19 15:58:31 +0000 | [diff] [blame] | 2943 | pid_file = optarg; |
bellard | f7cce89 | 2004-12-08 22:21:25 +0000 | [diff] [blame] | 2944 | break; |
bellard | a09db21 | 2005-04-30 16:10:35 +0000 | [diff] [blame] | 2945 | case QEMU_OPTION_win2k_hack: |
| 2946 | win2k_install_hack = 1; |
| 2947 | break; |
Jan Kiszka | 433acf0 | 2012-01-23 20:15:12 +0100 | [diff] [blame] | 2948 | case QEMU_OPTION_rtc_td_hack: { |
| 2949 | static GlobalProperty slew_lost_ticks[] = { |
| 2950 | { |
| 2951 | .driver = "mc146818rtc", |
| 2952 | .property = "lost_tick_policy", |
| 2953 | .value = "slew", |
| 2954 | }, |
| 2955 | { /* end of list */ } |
| 2956 | }; |
| 2957 | |
| 2958 | qdev_prop_register_global_list(slew_lost_ticks); |
aliguori | 73822ec | 2009-01-15 20:11:34 +0000 | [diff] [blame] | 2959 | break; |
Jan Kiszka | 433acf0 | 2012-01-23 20:15:12 +0100 | [diff] [blame] | 2960 | } |
aliguori | 8a92ea2 | 2009-02-27 20:12:36 +0000 | [diff] [blame] | 2961 | case QEMU_OPTION_acpitable: |
Blue Swirl | de06f8d | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 2962 | do_acpitable_option(optarg); |
aliguori | 8a92ea2 | 2009-02-27 20:12:36 +0000 | [diff] [blame] | 2963 | break; |
aliguori | b6f6e3d | 2009-04-17 18:59:56 +0000 | [diff] [blame] | 2964 | case QEMU_OPTION_smbios: |
Blue Swirl | de06f8d | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 2965 | do_smbios_option(optarg); |
aliguori | b6f6e3d | 2009-04-17 18:59:56 +0000 | [diff] [blame] | 2966 | break; |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 2967 | case QEMU_OPTION_enable_kvm: |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2968 | olist = qemu_find_opts("machine"); |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2969 | qemu_opts_parse(olist, "accel=kvm", 0); |
| 2970 | break; |
| 2971 | case QEMU_OPTION_machine: |
| 2972 | olist = qemu_find_opts("machine"); |
Jan Kiszka | 9052ea6 | 2011-07-23 12:38:37 +0200 | [diff] [blame] | 2973 | opts = qemu_opts_parse(olist, optarg, 1); |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2974 | if (!opts) { |
| 2975 | fprintf(stderr, "parse error: %s\n", optarg); |
| 2976 | exit(1); |
| 2977 | } |
Jan Kiszka | 2645c6d | 2011-07-25 18:11:20 +0200 | [diff] [blame] | 2978 | optarg = qemu_opt_get(opts, "type"); |
| 2979 | if (optarg) { |
| 2980 | machine = machine_parse(optarg); |
| 2981 | } |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 2982 | break; |
bellard | bb36d47 | 2005-11-05 14:22:28 +0000 | [diff] [blame] | 2983 | case QEMU_OPTION_usb: |
| 2984 | usb_enabled = 1; |
| 2985 | break; |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 2986 | case QEMU_OPTION_usbdevice: |
| 2987 | usb_enabled = 1; |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2988 | add_device_config(DEV_USB, optarg); |
| 2989 | break; |
| 2990 | case QEMU_OPTION_device: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2991 | if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) { |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 2992 | exit(1); |
| 2993 | } |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 2994 | break; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2995 | case QEMU_OPTION_smp: |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 2996 | smp_parse(optarg); |
aliguori | b209700 | 2008-10-07 20:39:39 +0000 | [diff] [blame] | 2997 | if (smp_cpus < 1) { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2998 | fprintf(stderr, "Invalid number of CPUs\n"); |
| 2999 | exit(1); |
| 3000 | } |
Jes Sorensen | 6be68d7 | 2009-07-23 17:03:42 +0200 | [diff] [blame] | 3001 | if (max_cpus < smp_cpus) { |
| 3002 | fprintf(stderr, "maxcpus must be equal to or greater than " |
| 3003 | "smp\n"); |
| 3004 | exit(1); |
| 3005 | } |
| 3006 | if (max_cpus > 255) { |
| 3007 | fprintf(stderr, "Unsupported number of maxcpus\n"); |
| 3008 | exit(1); |
| 3009 | } |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3010 | break; |
bellard | 2423686 | 2006-04-30 21:28:36 +0000 | [diff] [blame] | 3011 | case QEMU_OPTION_vnc: |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 3012 | #ifdef CONFIG_VNC |
Gerd Hoffmann | 6b62dc2 | 2010-08-25 10:51:06 +0200 | [diff] [blame] | 3013 | display_remote++; |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 3014 | vnc_display = optarg; |
| 3015 | #else |
| 3016 | fprintf(stderr, "VNC support is disabled\n"); |
| 3017 | exit(1); |
| 3018 | #endif |
| 3019 | break; |
bellard | 6515b20 | 2006-05-03 22:02:44 +0000 | [diff] [blame] | 3020 | case QEMU_OPTION_no_acpi: |
| 3021 | acpi_enabled = 0; |
| 3022 | break; |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 3023 | case QEMU_OPTION_no_hpet: |
| 3024 | no_hpet = 1; |
| 3025 | break; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 3026 | case QEMU_OPTION_balloon: |
| 3027 | if (balloon_parse(optarg) < 0) { |
| 3028 | fprintf(stderr, "Unknown -balloon argument %s\n", optarg); |
| 3029 | exit(1); |
| 3030 | } |
Eduardo Habkost | df97b92 | 2009-06-10 16:34:08 -0300 | [diff] [blame] | 3031 | break; |
bellard | d1beab8 | 2006-10-02 19:44:22 +0000 | [diff] [blame] | 3032 | case QEMU_OPTION_no_reboot: |
| 3033 | no_reboot = 1; |
| 3034 | break; |
aurel32 | b2f7616 | 2008-04-11 21:35:52 +0000 | [diff] [blame] | 3035 | case QEMU_OPTION_no_shutdown: |
| 3036 | no_shutdown = 1; |
| 3037 | break; |
balrog | 9467cd4 | 2007-05-01 01:34:14 +0000 | [diff] [blame] | 3038 | case QEMU_OPTION_show_cursor: |
| 3039 | cursor_hide = 0; |
| 3040 | break; |
blueswir1 | 8fcb1b9 | 2008-09-18 18:29:08 +0000 | [diff] [blame] | 3041 | case QEMU_OPTION_uuid: |
| 3042 | if(qemu_uuid_parse(optarg, qemu_uuid) < 0) { |
| 3043 | fprintf(stderr, "Fail to parse UUID string." |
| 3044 | " Wrong format.\n"); |
| 3045 | exit(1); |
| 3046 | } |
| 3047 | break; |
ths | 9ae0255 | 2007-01-05 17:39:04 +0000 | [diff] [blame] | 3048 | case QEMU_OPTION_option_rom: |
| 3049 | if (nb_option_roms >= MAX_OPTION_ROMS) { |
| 3050 | fprintf(stderr, "Too many option ROMs\n"); |
| 3051 | exit(1); |
| 3052 | } |
Gleb Natapov | 2e55e84 | 2010-12-08 13:35:07 +0200 | [diff] [blame] | 3053 | opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1); |
| 3054 | option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile"); |
| 3055 | option_rom[nb_option_roms].bootindex = |
| 3056 | qemu_opt_get_number(opts, "bootindex", -1); |
| 3057 | if (!option_rom[nb_option_roms].name) { |
| 3058 | fprintf(stderr, "Option ROM file is not specified\n"); |
| 3059 | exit(1); |
| 3060 | } |
ths | 9ae0255 | 2007-01-05 17:39:04 +0000 | [diff] [blame] | 3061 | nb_option_roms++; |
| 3062 | break; |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 3063 | case QEMU_OPTION_semihosting: |
| 3064 | semihosting_enabled = 1; |
| 3065 | break; |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 3066 | case QEMU_OPTION_name: |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 3067 | qemu_name = g_strdup(optarg); |
Andi Kleen | 1889465 | 2009-07-02 09:34:17 +0200 | [diff] [blame] | 3068 | { |
| 3069 | char *p = strchr(qemu_name, ','); |
| 3070 | if (p != NULL) { |
| 3071 | *p++ = 0; |
| 3072 | if (strncmp(p, "process=", 8)) { |
Aurelien Jarno | 5697f6a | 2010-12-27 18:29:20 +0100 | [diff] [blame] | 3073 | fprintf(stderr, "Unknown subargument %s to -name\n", p); |
Andi Kleen | 1889465 | 2009-07-02 09:34:17 +0200 | [diff] [blame] | 3074 | exit(1); |
| 3075 | } |
| 3076 | p += 8; |
Jes Sorensen | ce798cf | 2010-06-10 11:42:31 +0200 | [diff] [blame] | 3077 | os_set_proc_name(p); |
Andi Kleen | 1889465 | 2009-07-02 09:34:17 +0200 | [diff] [blame] | 3078 | } |
| 3079 | } |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 3080 | break; |
blueswir1 | 6650860 | 2007-05-01 14:16:52 +0000 | [diff] [blame] | 3081 | case QEMU_OPTION_prom_env: |
| 3082 | if (nb_prom_envs >= MAX_PROM_ENVS) { |
| 3083 | fprintf(stderr, "Too many prom variables\n"); |
| 3084 | exit(1); |
| 3085 | } |
| 3086 | prom_envs[nb_prom_envs] = optarg; |
| 3087 | nb_prom_envs++; |
| 3088 | break; |
balrog | 2b8f2d4 | 2007-07-27 22:08:46 +0000 | [diff] [blame] | 3089 | case QEMU_OPTION_old_param: |
| 3090 | old_param = 1; |
ths | 05ebd53 | 2008-01-08 19:32:16 +0000 | [diff] [blame] | 3091 | break; |
ths | f3dcfad | 2007-08-24 01:26:02 +0000 | [diff] [blame] | 3092 | case QEMU_OPTION_clock: |
| 3093 | configure_alarms(optarg); |
| 3094 | break; |
bellard | 7e0af5d0 | 2007-11-07 16:24:33 +0000 | [diff] [blame] | 3095 | case QEMU_OPTION_startdate: |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 3096 | configure_rtc_date_offset(optarg, 1); |
| 3097 | break; |
| 3098 | case QEMU_OPTION_rtc: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 3099 | opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0); |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 3100 | if (!opts) { |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 3101 | exit(1); |
bellard | 7e0af5d0 | 2007-11-07 16:24:33 +0000 | [diff] [blame] | 3102 | } |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 3103 | configure_rtc(opts); |
bellard | 7e0af5d0 | 2007-11-07 16:24:33 +0000 | [diff] [blame] | 3104 | break; |
bellard | 26a5f13 | 2008-05-28 12:30:31 +0000 | [diff] [blame] | 3105 | case QEMU_OPTION_tb_size: |
Jan Kiszka | d5ab971 | 2011-08-02 16:10:21 +0200 | [diff] [blame] | 3106 | tcg_tb_size = strtol(optarg, NULL, 0); |
| 3107 | if (tcg_tb_size < 0) { |
| 3108 | tcg_tb_size = 0; |
| 3109 | } |
bellard | 26a5f13 | 2008-05-28 12:30:31 +0000 | [diff] [blame] | 3110 | break; |
pbrook | 2e70f6e | 2008-06-29 01:03:05 +0000 | [diff] [blame] | 3111 | case QEMU_OPTION_icount: |
Paolo Bonzini | 4e3de9e | 2010-03-10 11:38:48 +0100 | [diff] [blame] | 3112 | icount_option = optarg; |
pbrook | 2e70f6e | 2008-06-29 01:03:05 +0000 | [diff] [blame] | 3113 | break; |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 3114 | case QEMU_OPTION_incoming: |
| 3115 | incoming = optarg; |
Stefano Stabellini | 81323a6 | 2012-01-18 12:23:13 +0000 | [diff] [blame] | 3116 | runstate_set(RUN_STATE_INMIGRATE); |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 3117 | break; |
Gerd Hoffmann | d8c208d | 2009-12-08 13:11:46 +0100 | [diff] [blame] | 3118 | case QEMU_OPTION_nodefaults: |
| 3119 | default_serial = 0; |
| 3120 | default_parallel = 0; |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 3121 | default_virtcon = 0; |
Gerd Hoffmann | d8c208d | 2009-12-08 13:11:46 +0100 | [diff] [blame] | 3122 | default_monitor = 0; |
Gerd Hoffmann | cb4522c | 2009-12-08 13:11:47 +0100 | [diff] [blame] | 3123 | default_net = 0; |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 3124 | default_floppy = 0; |
| 3125 | default_cdrom = 0; |
| 3126 | default_sdcard = 0; |
Paolo Bonzini | 7f1b17f | 2012-05-10 09:39:17 +0200 | [diff] [blame] | 3127 | default_vga = 0; |
Gerd Hoffmann | d8c208d | 2009-12-08 13:11:46 +0100 | [diff] [blame] | 3128 | break; |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 3129 | case QEMU_OPTION_xen_domid: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 3130 | if (!(xen_available())) { |
| 3131 | printf("Option %s not supported for this target\n", popt->name); |
| 3132 | exit(1); |
| 3133 | } |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 3134 | xen_domid = atoi(optarg); |
| 3135 | break; |
| 3136 | case QEMU_OPTION_xen_create: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 3137 | if (!(xen_available())) { |
| 3138 | printf("Option %s not supported for this target\n", popt->name); |
| 3139 | exit(1); |
| 3140 | } |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 3141 | xen_mode = XEN_CREATE; |
| 3142 | break; |
| 3143 | case QEMU_OPTION_xen_attach: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 3144 | if (!(xen_available())) { |
| 3145 | printf("Option %s not supported for this target\n", popt->name); |
| 3146 | exit(1); |
| 3147 | } |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 3148 | xen_mode = XEN_ATTACH; |
| 3149 | break; |
Prerna Saxena | ab6540d | 2010-08-09 11:48:32 +0100 | [diff] [blame] | 3150 | case QEMU_OPTION_trace: |
LluÃs | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 3151 | { |
Prerna Saxena | ab6540d | 2010-08-09 11:48:32 +0100 | [diff] [blame] | 3152 | opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0); |
LluÃs | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 3153 | if (!opts) { |
| 3154 | exit(1); |
Prerna Saxena | ab6540d | 2010-08-09 11:48:32 +0100 | [diff] [blame] | 3155 | } |
LluÃs | 23d15e8 | 2011-08-31 20:31:31 +0200 | [diff] [blame] | 3156 | trace_events = qemu_opt_get(opts, "events"); |
LluÃs | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 3157 | trace_file = qemu_opt_get(opts, "file"); |
Prerna Saxena | ab6540d | 2010-08-09 11:48:32 +0100 | [diff] [blame] | 3158 | break; |
LluÃs | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 3159 | } |
Gerd Hoffmann | 715a664 | 2009-10-14 10:39:28 +0200 | [diff] [blame] | 3160 | case QEMU_OPTION_readconfig: |
| 3161 | { |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 3162 | int ret = qemu_read_config_file(optarg); |
| 3163 | if (ret < 0) { |
| 3164 | fprintf(stderr, "read config %s: %s\n", optarg, |
| 3165 | strerror(-ret)); |
Gerd Hoffmann | 715a664 | 2009-10-14 10:39:28 +0200 | [diff] [blame] | 3166 | exit(1); |
| 3167 | } |
Gerd Hoffmann | 715a664 | 2009-10-14 10:39:28 +0200 | [diff] [blame] | 3168 | break; |
| 3169 | } |
Gerd Hoffmann | 29b0040 | 2010-03-11 11:13:27 -0300 | [diff] [blame] | 3170 | case QEMU_OPTION_spice: |
| 3171 | olist = qemu_find_opts("spice"); |
| 3172 | if (!olist) { |
| 3173 | fprintf(stderr, "spice is not supported by this qemu build.\n"); |
| 3174 | exit(1); |
| 3175 | } |
| 3176 | opts = qemu_opts_parse(olist, optarg, 0); |
| 3177 | if (!opts) { |
| 3178 | fprintf(stderr, "parse error: %s\n", optarg); |
| 3179 | exit(1); |
| 3180 | } |
| 3181 | break; |
Gerd Hoffmann | 715a664 | 2009-10-14 10:39:28 +0200 | [diff] [blame] | 3182 | case QEMU_OPTION_writeconfig: |
| 3183 | { |
| 3184 | FILE *fp; |
| 3185 | if (strcmp(optarg, "-") == 0) { |
| 3186 | fp = stdout; |
| 3187 | } else { |
| 3188 | fp = fopen(optarg, "w"); |
| 3189 | if (fp == NULL) { |
| 3190 | fprintf(stderr, "open %s: %s\n", optarg, strerror(errno)); |
| 3191 | exit(1); |
| 3192 | } |
| 3193 | } |
| 3194 | qemu_config_write(fp); |
| 3195 | fclose(fp); |
| 3196 | break; |
| 3197 | } |
Anthony Liguori | c7f0f3b | 2012-03-28 15:42:02 +0200 | [diff] [blame] | 3198 | case QEMU_OPTION_qtest: |
| 3199 | qtest_chrdev = optarg; |
| 3200 | break; |
| 3201 | case QEMU_OPTION_qtest_log: |
| 3202 | qtest_log = optarg; |
| 3203 | break; |
Jes Sorensen | 59a5264 | 2010-06-10 11:42:25 +0200 | [diff] [blame] | 3204 | default: |
| 3205 | os_parse_cmd_args(popt->index, optarg); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3206 | } |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 3207 | } |
| 3208 | } |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 3209 | loc_set_none(); |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 3210 | |
Eduardo Habkost | ecf40be | 2012-03-09 16:19:07 -0300 | [diff] [blame] | 3211 | /* Init CPU def lists, based on config |
| 3212 | * - Must be called after all the qemu_read_config_file() calls |
| 3213 | * - Must be called before list_cpus() |
| 3214 | * - Must be called before machine->init() |
| 3215 | */ |
| 3216 | cpudef_init(); |
| 3217 | |
| 3218 | if (cpu_model && *cpu_model == '?') { |
Eduardo Habkost | 1d6528a | 2012-03-21 09:33:40 -0300 | [diff] [blame] | 3219 | list_cpus(stdout, &fprintf, cpu_model); |
Eduardo Habkost | ecf40be | 2012-03-09 16:19:07 -0300 | [diff] [blame] | 3220 | exit(0); |
| 3221 | } |
| 3222 | |
Matthew Fernandez | c235d73 | 2011-06-07 16:32:40 +0000 | [diff] [blame] | 3223 | /* Open the logfile at this point, if necessary. We can't open the logfile |
| 3224 | * when encountering either of the logging options (-d or -D) because the |
| 3225 | * other one may be encountered later on the command line, changing the |
| 3226 | * location or level of logging. |
| 3227 | */ |
| 3228 | if (log_mask) { |
| 3229 | if (log_file) { |
| 3230 | set_cpu_log_filename(log_file); |
| 3231 | } |
| 3232 | set_cpu_log(log_mask); |
| 3233 | } |
| 3234 | |
LluÃs | 23d15e8 | 2011-08-31 20:31:31 +0200 | [diff] [blame] | 3235 | if (!trace_backend_init(trace_events, trace_file)) { |
LluÃs | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 3236 | exit(1); |
Stefan Hajnoczi | 31d3c9b | 2011-03-13 20:14:30 +0000 | [diff] [blame] | 3237 | } |
Stefan Hajnoczi | 0b5538c | 2011-02-26 18:38:39 +0000 | [diff] [blame] | 3238 | |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 3239 | /* If no data_dir is specified then try to find it relative to the |
| 3240 | executable path. */ |
| 3241 | if (!data_dir) { |
Jes Sorensen | 6170540 | 2010-06-10 11:42:23 +0200 | [diff] [blame] | 3242 | data_dir = os_find_datadir(argv[0]); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 3243 | } |
Stefan Weil | 60474fb | 2011-09-04 15:17:46 +0200 | [diff] [blame] | 3244 | /* If all else fails use the install path specified when building. */ |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 3245 | if (!data_dir) { |
Paolo Bonzini | 1dabe05 | 2010-05-26 16:08:25 +0200 | [diff] [blame] | 3246 | data_dir = CONFIG_QEMU_DATADIR; |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 3247 | } |
| 3248 | |
Andreas Färber | d423675 | 2011-11-10 16:35:32 +0100 | [diff] [blame] | 3249 | if (machine == NULL) { |
| 3250 | fprintf(stderr, "No machine found.\n"); |
| 3251 | exit(1); |
| 3252 | } |
| 3253 | |
Jes Sorensen | 6be68d7 | 2009-07-23 17:03:42 +0200 | [diff] [blame] | 3254 | /* |
| 3255 | * Default to max_cpus = smp_cpus, in case the user doesn't |
| 3256 | * specify a max_cpus value. |
| 3257 | */ |
| 3258 | if (!max_cpus) |
| 3259 | max_cpus = smp_cpus; |
| 3260 | |
balrog | 3d878ca | 2008-10-28 10:59:59 +0000 | [diff] [blame] | 3261 | machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */ |
aliguori | b209700 | 2008-10-07 20:39:39 +0000 | [diff] [blame] | 3262 | if (smp_cpus > machine->max_cpus) { |
| 3263 | fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus " |
| 3264 | "supported by machine `%s' (%d)\n", smp_cpus, machine->name, |
| 3265 | machine->max_cpus); |
| 3266 | exit(1); |
| 3267 | } |
| 3268 | |
Anthony PERARD | 67b724e | 2010-11-22 15:44:15 +0000 | [diff] [blame] | 3269 | /* |
| 3270 | * Get the default machine options from the machine if it is not already |
| 3271 | * specified either by the configuration file or by the command line. |
| 3272 | */ |
| 3273 | if (machine->default_machine_opts) { |
Jan Kiszka | 25de593 | 2012-01-27 19:55:43 +0100 | [diff] [blame] | 3274 | qemu_opts_set_defaults(qemu_find_opts("machine"), |
| 3275 | machine->default_machine_opts, 0); |
Anthony PERARD | 67b724e | 2010-11-22 15:44:15 +0000 | [diff] [blame] | 3276 | } |
| 3277 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 3278 | qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0); |
| 3279 | qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0); |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 3280 | |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 3281 | if (machine->no_serial) { |
| 3282 | default_serial = 0; |
| 3283 | } |
| 3284 | if (machine->no_parallel) { |
| 3285 | default_parallel = 0; |
| 3286 | } |
| 3287 | if (!machine->use_virtcon) { |
| 3288 | default_virtcon = 0; |
| 3289 | } |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 3290 | if (machine->no_floppy) { |
| 3291 | default_floppy = 0; |
| 3292 | } |
| 3293 | if (machine->no_cdrom) { |
| 3294 | default_cdrom = 0; |
| 3295 | } |
| 3296 | if (machine->no_sdcard) { |
| 3297 | default_sdcard = 0; |
| 3298 | } |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 3299 | |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 3300 | if (display_type == DT_NOGRAPHIC) { |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 3301 | if (default_parallel) |
| 3302 | add_device_config(DEV_PARALLEL, "null"); |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 3303 | if (default_serial && default_monitor) { |
| 3304 | add_device_config(DEV_SERIAL, "mon:stdio"); |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 3305 | } else if (default_virtcon && default_monitor) { |
| 3306 | add_device_config(DEV_VIRTCON, "mon:stdio"); |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 3307 | } else { |
| 3308 | if (default_serial) |
| 3309 | add_device_config(DEV_SERIAL, "stdio"); |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 3310 | if (default_virtcon) |
| 3311 | add_device_config(DEV_VIRTCON, "stdio"); |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 3312 | if (default_monitor) |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 3313 | monitor_parse("stdio", "readline"); |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 3314 | } |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 3315 | } else { |
| 3316 | if (default_serial) |
| 3317 | add_device_config(DEV_SERIAL, "vc:80Cx24C"); |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 3318 | if (default_parallel) |
| 3319 | add_device_config(DEV_PARALLEL, "vc:80Cx24C"); |
Gerd Hoffmann | abdeed0 | 2009-12-08 13:11:43 +0100 | [diff] [blame] | 3320 | if (default_monitor) |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 3321 | monitor_parse("vc:80Cx24C", "readline"); |
Alexander Graf | 38536da | 2009-12-17 13:06:08 +0100 | [diff] [blame] | 3322 | if (default_virtcon) |
| 3323 | add_device_config(DEV_VIRTCON, "vc:80Cx24C"); |
aliguori | bc0129d | 2008-08-01 15:12:34 +0000 | [diff] [blame] | 3324 | } |
| 3325 | |
TeLeMan | a5829fd | 2010-04-15 12:37:55 +0800 | [diff] [blame] | 3326 | socket_init(); |
| 3327 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 3328 | if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0) |
Gerd Hoffmann | 1a688d3 | 2009-12-08 13:11:36 +0100 | [diff] [blame] | 3329 | exit(1); |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 3330 | #ifdef CONFIG_VIRTFS |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 3331 | if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) { |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 3332 | exit(1); |
| 3333 | } |
| 3334 | #endif |
Gerd Hoffmann | 1a688d3 | 2009-12-08 13:11:36 +0100 | [diff] [blame] | 3335 | |
Jes Sorensen | eb505be | 2010-06-10 11:42:28 +0200 | [diff] [blame] | 3336 | os_daemonize(); |
ths | 71e3ceb | 2006-12-22 02:11:31 +0000 | [diff] [blame] | 3337 | |
ths | aa26bb2 | 2007-03-25 21:33:06 +0000 | [diff] [blame] | 3338 | if (pid_file && qemu_create_pidfile(pid_file) != 0) { |
Jes Sorensen | eb505be | 2010-06-10 11:42:28 +0200 | [diff] [blame] | 3339 | os_pidfile_error(); |
ths | 93815bc | 2007-03-19 15:58:31 +0000 | [diff] [blame] | 3340 | exit(1); |
| 3341 | } |
| 3342 | |
Jan Kiszka | 0ac543d | 2011-08-15 16:18:57 -0700 | [diff] [blame] | 3343 | /* init the memory */ |
| 3344 | if (ram_size == 0) { |
| 3345 | ram_size = DEFAULT_RAM_SIZE * 1024 * 1024; |
| 3346 | } |
| 3347 | |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 3348 | configure_accelerator(); |
Marcelo Tosatti | 214910a | 2009-09-18 02:41:23 -0300 | [diff] [blame] | 3349 | |
Paolo Bonzini | d3b12f5 | 2011-09-13 10:30:52 +0200 | [diff] [blame] | 3350 | qemu_init_cpu_loop(); |
aliguori | 3fcf7b6 | 2009-04-24 18:03:25 +0000 | [diff] [blame] | 3351 | if (qemu_init_main_loop()) { |
| 3352 | fprintf(stderr, "qemu_init_main_loop failed\n"); |
| 3353 | exit(1); |
| 3354 | } |
Peter Maydell | a0abe47 | 2012-02-08 05:41:39 +0000 | [diff] [blame] | 3355 | |
Peter Maydell | 967c0da | 2012-02-22 22:40:00 +0000 | [diff] [blame] | 3356 | machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0); |
| 3357 | if (machine_opts) { |
| 3358 | kernel_filename = qemu_opt_get(machine_opts, "kernel"); |
| 3359 | initrd_filename = qemu_opt_get(machine_opts, "initrd"); |
| 3360 | kernel_cmdline = qemu_opt_get(machine_opts, "append"); |
| 3361 | } else { |
| 3362 | kernel_filename = initrd_filename = kernel_cmdline = NULL; |
| 3363 | } |
| 3364 | |
Peter Maydell | a0abe47 | 2012-02-08 05:41:39 +0000 | [diff] [blame] | 3365 | if (!kernel_cmdline) { |
| 3366 | kernel_cmdline = ""; |
| 3367 | } |
| 3368 | |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 3369 | linux_boot = (kernel_filename != NULL); |
balrog | 6c41b27 | 2007-11-17 12:12:29 +0000 | [diff] [blame] | 3370 | |
ths | f8d39c0 | 2008-07-03 10:01:15 +0000 | [diff] [blame] | 3371 | if (!linux_boot && *kernel_cmdline != '\0') { |
| 3372 | fprintf(stderr, "-append only allowed with -kernel option\n"); |
| 3373 | exit(1); |
| 3374 | } |
| 3375 | |
| 3376 | if (!linux_boot && initrd_filename != NULL) { |
| 3377 | fprintf(stderr, "-initrd only allowed with -kernel option\n"); |
| 3378 | exit(1); |
| 3379 | } |
| 3380 | |
Grant Likely | 412beee | 2012-03-02 11:56:38 +0000 | [diff] [blame] | 3381 | if (!linux_boot && machine_opts && qemu_opt_get(machine_opts, "dtb")) { |
| 3382 | fprintf(stderr, "-dtb only allowed with -kernel option\n"); |
| 3383 | exit(1); |
| 3384 | } |
| 3385 | |
Jes Sorensen | 9156d76 | 2010-06-10 11:42:30 +0200 | [diff] [blame] | 3386 | os_set_line_buffering(); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3387 | |
aliguori | 7183b4b | 2008-11-05 20:40:18 +0000 | [diff] [blame] | 3388 | if (init_timer_alarm() < 0) { |
| 3389 | fprintf(stderr, "could not initialize alarm timer\n"); |
| 3390 | exit(1); |
| 3391 | } |
Max Filippov | 0abe905 | 2011-11-10 15:38:42 +0400 | [diff] [blame] | 3392 | |
Alon Levy | ad1be89 | 2012-03-14 20:33:37 +0200 | [diff] [blame] | 3393 | #ifdef CONFIG_SPICE |
| 3394 | /* spice needs the timers to be initialized by this point */ |
| 3395 | qemu_spice_init(); |
| 3396 | #endif |
| 3397 | |
Max Filippov | 0abe905 | 2011-11-10 15:38:42 +0400 | [diff] [blame] | 3398 | if (icount_option && (kvm_enabled() || xen_enabled())) { |
| 3399 | fprintf(stderr, "-icount is not allowed with kvm or xen\n"); |
| 3400 | exit(1); |
| 3401 | } |
Paolo Bonzini | 4e3de9e | 2010-03-10 11:38:48 +0100 | [diff] [blame] | 3402 | configure_icount(icount_option); |
pbrook | 634fce9 | 2006-07-15 17:40:09 +0000 | [diff] [blame] | 3403 | |
Mark McLoughlin | dc1c9fe | 2009-10-06 12:17:16 +0100 | [diff] [blame] | 3404 | if (net_init_clients() < 0) { |
| 3405 | exit(1); |
bellard | 702c651 | 2004-04-02 21:21:32 +0000 | [diff] [blame] | 3406 | } |
bellard | f1510b2 | 2003-06-25 00:07:40 +0000 | [diff] [blame] | 3407 | |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 3408 | /* init the bluetooth world */ |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 3409 | if (foreach_device_config(DEV_BT, bt_parse)) |
| 3410 | exit(1); |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 3411 | |
Anthony PERARD | 834e76e | 2011-07-20 08:17:44 +0000 | [diff] [blame] | 3412 | if (!xen_enabled()) { |
| 3413 | /* On 32-bit hosts, QEMU is limited by virtual address space */ |
| 3414 | if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) { |
| 3415 | fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n"); |
| 3416 | exit(1); |
| 3417 | } |
| 3418 | } |
balrog | 7fb4fdc | 2008-04-24 17:59:27 +0000 | [diff] [blame] | 3419 | |
Jan Kiszka | d5ab971 | 2011-08-02 16:10:21 +0200 | [diff] [blame] | 3420 | cpu_exec_init_all(); |
bellard | 26a5f13 | 2008-05-28 12:30:31 +0000 | [diff] [blame] | 3421 | |
Markus Armbruster | eb85201 | 2009-10-27 18:41:44 +0100 | [diff] [blame] | 3422 | bdrv_init_with_whitelist(); |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 3423 | |
lirans@il.ibm.com | c163b5c | 2009-11-02 15:40:58 +0200 | [diff] [blame] | 3424 | blk_mig_init(); |
| 3425 | |
ths | 96d30e4 | 2007-01-07 20:42:14 +0000 | [diff] [blame] | 3426 | /* open the virtual block devices */ |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 3427 | if (snapshot) |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 3428 | qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0); |
| 3429 | if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0) |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 3430 | exit(1); |
balrog | 3e3d581 | 2007-04-30 02:09:25 +0000 | [diff] [blame] | 3431 | |
Markus Armbruster | 4e5d9b5 | 2011-01-28 11:21:45 +0100 | [diff] [blame] | 3432 | default_drive(default_cdrom, snapshot, machine->use_scsi, |
| 3433 | IF_DEFAULT, 2, CDROM_OPTS); |
| 3434 | default_drive(default_floppy, snapshot, machine->use_scsi, |
| 3435 | IF_FLOPPY, 0, FD_OPTS); |
| 3436 | default_drive(default_sdcard, snapshot, machine->use_scsi, |
| 3437 | IF_SD, 0, SD_OPTS); |
| 3438 | |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 3439 | register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL, |
lirans@il.ibm.com | c163b5c | 2009-11-02 15:40:58 +0200 | [diff] [blame] | 3440 | ram_load, NULL); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 3441 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 3442 | if (nb_numa_nodes > 0) { |
| 3443 | int i; |
| 3444 | |
Sasha Levin | ea0e541 | 2011-06-29 23:29:39 -0400 | [diff] [blame] | 3445 | if (nb_numa_nodes > MAX_NODES) { |
| 3446 | nb_numa_nodes = MAX_NODES; |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 3447 | } |
| 3448 | |
| 3449 | /* If no memory size if given for any node, assume the default case |
| 3450 | * and distribute the available memory equally across all nodes |
| 3451 | */ |
| 3452 | for (i = 0; i < nb_numa_nodes; i++) { |
| 3453 | if (node_mem[i] != 0) |
| 3454 | break; |
| 3455 | } |
| 3456 | if (i == nb_numa_nodes) { |
| 3457 | uint64_t usedmem = 0; |
| 3458 | |
| 3459 | /* On Linux, the each node's border has to be 8MB aligned, |
| 3460 | * the final node gets the rest. |
| 3461 | */ |
| 3462 | for (i = 0; i < nb_numa_nodes - 1; i++) { |
| 3463 | node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1); |
| 3464 | usedmem += node_mem[i]; |
| 3465 | } |
| 3466 | node_mem[i] = ram_size - usedmem; |
| 3467 | } |
| 3468 | |
| 3469 | for (i = 0; i < nb_numa_nodes; i++) { |
| 3470 | if (node_cpumask[i] != 0) |
| 3471 | break; |
| 3472 | } |
| 3473 | /* assigning the VCPUs round-robin is easier to implement, guest OSes |
| 3474 | * must cope with this anyway, because there are BIOSes out there in |
| 3475 | * real machines which also use this scheme. |
| 3476 | */ |
| 3477 | if (i == nb_numa_nodes) { |
Vasilis Liaskovitis | 991dfef | 2011-10-26 14:19:00 +0200 | [diff] [blame] | 3478 | for (i = 0; i < max_cpus; i++) { |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 3479 | node_cpumask[i % nb_numa_nodes] |= 1 << i; |
| 3480 | } |
| 3481 | } |
| 3482 | } |
| 3483 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 3484 | if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) { |
Jan Kiszka | 157b931 | 2010-04-06 16:55:53 +0200 | [diff] [blame] | 3485 | exit(1); |
| 3486 | } |
| 3487 | |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 3488 | if (foreach_device_config(DEV_SERIAL, serial_parse) < 0) |
| 3489 | exit(1); |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 3490 | if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) |
| 3491 | exit(1); |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 3492 | if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0) |
| 3493 | exit(1); |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 3494 | if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0) |
| 3495 | exit(1); |
aliguori | 2796dae | 2009-01-16 20:23:27 +0000 | [diff] [blame] | 3496 | |
Paolo Bonzini | 7f1b17f | 2012-05-10 09:39:17 +0200 | [diff] [blame] | 3497 | /* If no default VGA is requested, the default is "none". */ |
| 3498 | if (default_vga && cirrus_vga_available()) { |
| 3499 | vga_model = "cirrus"; |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 3500 | } |
Paolo Bonzini | 7f1b17f | 2012-05-10 09:39:17 +0200 | [diff] [blame] | 3501 | select_vgahw(vga_model); |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 3502 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 3503 | if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0) |
Markus Armbruster | ff952ba | 2010-01-29 19:48:57 +0100 | [diff] [blame] | 3504 | exit(0); |
| 3505 | |
Markus Armbruster | 09aaa16 | 2009-08-21 10:31:34 +0200 | [diff] [blame] | 3506 | if (watchdog) { |
| 3507 | i = select_watchdog(watchdog); |
| 3508 | if (i > 0) |
| 3509 | exit (i == 1 ? 1 : 0); |
| 3510 | } |
| 3511 | |
Gerd Hoffmann | b6b6114 | 2009-07-15 13:48:21 +0200 | [diff] [blame] | 3512 | if (machine->compat_props) { |
Gerd Hoffmann | 458fb67 | 2009-12-08 13:11:33 +0100 | [diff] [blame] | 3513 | qdev_prop_register_global_list(machine->compat_props); |
Gerd Hoffmann | b6b6114 | 2009-07-15 13:48:21 +0200 | [diff] [blame] | 3514 | } |
Gerd Hoffmann | d0fef6f | 2009-12-08 13:11:34 +0100 | [diff] [blame] | 3515 | qemu_add_globals(); |
| 3516 | |
Anthony Liguori | 1de81d2 | 2011-12-19 16:37:46 -0600 | [diff] [blame] | 3517 | qdev_machine_init(); |
| 3518 | |
Paul Brook | fbe1b59 | 2009-05-13 17:56:25 +0100 | [diff] [blame] | 3519 | machine->init(ram_size, boot_devices, |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 3520 | kernel_filename, kernel_cmdline, initrd_filename, cpu_model); |
| 3521 | |
Jan Kiszka | ea375f9 | 2010-03-01 19:10:30 +0100 | [diff] [blame] | 3522 | cpu_synchronize_all_post_init(); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 3523 | |
Blue Swirl | 87d0a28 | 2010-03-27 18:24:45 +0000 | [diff] [blame] | 3524 | set_numa_modes(); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 3525 | |
aliguori | 6f338c3 | 2009-02-11 15:21:54 +0000 | [diff] [blame] | 3526 | current_machine = machine; |
| 3527 | |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 3528 | /* init USB devices */ |
| 3529 | if (usb_enabled) { |
Markus Armbruster | 0752706 | 2009-10-06 12:16:57 +0100 | [diff] [blame] | 3530 | if (foreach_device_config(DEV_USB, usb_parse) < 0) |
| 3531 | exit(1); |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 3532 | } |
| 3533 | |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 3534 | /* init generic devices */ |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 3535 | if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0) |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 3536 | exit(1); |
| 3537 | |
Markus Armbruster | 668680f | 2010-02-11 14:44:58 +0100 | [diff] [blame] | 3538 | net_check_clients(); |
| 3539 | |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 3540 | /* just use the first displaystate for the moment */ |
Paolo Bonzini | b473df6 | 2010-02-11 00:29:55 +0100 | [diff] [blame] | 3541 | ds = get_displaystate(); |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 3542 | |
Gerd Hoffmann | a3e2226 | 2010-08-25 15:32:06 +0200 | [diff] [blame] | 3543 | if (using_spice) |
| 3544 | display_remote++; |
Gerd Hoffmann | 6b62dc2 | 2010-08-25 10:51:06 +0200 | [diff] [blame] | 3545 | if (display_type == DT_DEFAULT && !display_remote) { |
Anthony Liguori | f92f8af | 2009-05-20 13:01:02 -0500 | [diff] [blame] | 3546 | #if defined(CONFIG_SDL) || defined(CONFIG_COCOA) |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 3547 | display_type = DT_SDL; |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 3548 | #elif defined(CONFIG_VNC) |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 3549 | vnc_display = "localhost:0,to=99"; |
| 3550 | show_vnc_port = 1; |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 3551 | #else |
| 3552 | display_type = DT_NONE; |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 3553 | #endif |
| 3554 | } |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 3555 | |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 3556 | |
Gerd Hoffmann | 6b62dc2 | 2010-08-25 10:51:06 +0200 | [diff] [blame] | 3557 | /* init local displays */ |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 3558 | switch (display_type) { |
| 3559 | case DT_NOGRAPHIC: |
| 3560 | break; |
| 3561 | #if defined(CONFIG_CURSES) |
| 3562 | case DT_CURSES: |
| 3563 | curses_display_init(ds, full_screen); |
| 3564 | break; |
| 3565 | #endif |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 3566 | #if defined(CONFIG_SDL) |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 3567 | case DT_SDL: |
| 3568 | sdl_display_init(ds, full_screen, no_frame); |
| 3569 | break; |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 3570 | #elif defined(CONFIG_COCOA) |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 3571 | case DT_SDL: |
| 3572 | cocoa_display_init(ds, full_screen); |
| 3573 | break; |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 3574 | #endif |
Gerd Hoffmann | 6b62dc2 | 2010-08-25 10:51:06 +0200 | [diff] [blame] | 3575 | default: |
| 3576 | break; |
| 3577 | } |
| 3578 | |
Gleb Natapov | 0ce235a | 2011-03-31 11:27:23 +0200 | [diff] [blame] | 3579 | /* must be after terminal init, SDL library changes signal handlers */ |
| 3580 | os_setup_signal_handling(); |
| 3581 | |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 3582 | #ifdef CONFIG_VNC |
Gerd Hoffmann | 6b62dc2 | 2010-08-25 10:51:06 +0200 | [diff] [blame] | 3583 | /* init remote displays */ |
| 3584 | if (vnc_display) { |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 3585 | vnc_display_init(ds); |
| 3586 | if (vnc_display_open(ds, vnc_display) < 0) |
| 3587 | exit(1); |
Anthony Liguori | f92f8af | 2009-05-20 13:01:02 -0500 | [diff] [blame] | 3588 | |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 3589 | if (show_vnc_port) { |
| 3590 | printf("VNC server running on `%s'\n", vnc_display_local_addr(ds)); |
Anthony Liguori | f92f8af | 2009-05-20 13:01:02 -0500 | [diff] [blame] | 3591 | } |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 3592 | } |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 3593 | #endif |
Gerd Hoffmann | a3e2226 | 2010-08-25 15:32:06 +0200 | [diff] [blame] | 3594 | #ifdef CONFIG_SPICE |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 3595 | if (using_spice && !qxl_enabled) { |
Gerd Hoffmann | a3e2226 | 2010-08-25 15:32:06 +0200 | [diff] [blame] | 3596 | qemu_spice_display_init(ds); |
| 3597 | } |
| 3598 | #endif |
aliguori | 5b08fc1 | 2008-08-21 20:08:03 +0000 | [diff] [blame] | 3599 | |
Gerd Hoffmann | 6b62dc2 | 2010-08-25 10:51:06 +0200 | [diff] [blame] | 3600 | /* display setup */ |
| 3601 | dpy_resize(ds); |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 3602 | dcl = ds->listeners; |
| 3603 | while (dcl != NULL) { |
| 3604 | if (dcl->dpy_refresh != NULL) { |
Paolo Bonzini | 7bd427d | 2011-03-11 16:47:48 +0100 | [diff] [blame] | 3605 | ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds); |
| 3606 | qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock)); |
Isaku Yamahata | 0f2ad63 | 2010-05-27 14:38:47 +0900 | [diff] [blame] | 3607 | break; |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 3608 | } |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 3609 | dcl = dcl->next; |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 3610 | } |
Paolo Bonzini | b473df6 | 2010-02-11 00:29:55 +0100 | [diff] [blame] | 3611 | text_consoles_set_display(ds); |
aliguori | 2796dae | 2009-01-16 20:23:27 +0000 | [diff] [blame] | 3612 | |
Markus Armbruster | ef0c4a0 | 2012-02-07 15:09:13 +0100 | [diff] [blame] | 3613 | if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) { |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 3614 | exit(1); |
balrog | 45669e0 | 2007-07-02 13:20:17 +0000 | [diff] [blame] | 3615 | } |
balrog | 45669e0 | 2007-07-02 13:20:17 +0000 | [diff] [blame] | 3616 | |
Gerd Hoffmann | 3418bd2 | 2009-09-25 21:42:41 +0200 | [diff] [blame] | 3617 | qdev_machine_creation_done(); |
| 3618 | |
Gerd Hoffmann | 15ff770 | 2009-12-14 16:07:35 +0100 | [diff] [blame] | 3619 | if (rom_load_all() != 0) { |
| 3620 | fprintf(stderr, "rom loading failed\n"); |
| 3621 | exit(1); |
| 3622 | } |
Gerd Hoffmann | 45a50b1 | 2009-10-01 16:42:33 +0200 | [diff] [blame] | 3623 | |
Isaku Yamahata | 80376c3 | 2010-12-20 14:33:35 +0900 | [diff] [blame] | 3624 | /* TODO: once all bus devices are qdevified, this should be done |
| 3625 | * when bus is created by qdev.c */ |
| 3626 | qemu_register_reset(qbus_reset_all_fn, sysbus_get_default()); |
Gleb Natapov | 4cab946 | 2010-12-08 13:35:08 +0200 | [diff] [blame] | 3627 | qemu_run_machine_init_done_notifiers(); |
| 3628 | |
Jan Kiszka | e063eb1 | 2011-06-14 18:29:43 +0200 | [diff] [blame] | 3629 | qemu_system_reset(VMRESET_SILENT); |
Juan Quintela | 05f2401 | 2009-08-20 19:42:22 +0200 | [diff] [blame] | 3630 | if (loadvm) { |
Markus Armbruster | 03cd465 | 2010-02-17 16:24:10 +0100 | [diff] [blame] | 3631 | if (load_vmstate(loadvm) < 0) { |
Juan Quintela | 05f2401 | 2009-08-20 19:42:22 +0200 | [diff] [blame] | 3632 | autostart = 0; |
| 3633 | } |
| 3634 | } |
bellard | d63d307 | 2004-10-03 13:29:03 +0000 | [diff] [blame] | 3635 | |
Glauber Costa | 2bb8c10 | 2009-07-24 16:20:23 -0400 | [diff] [blame] | 3636 | if (incoming) { |
Amos Kong | d5c5dac | 2012-05-11 00:28:35 +0800 | [diff] [blame] | 3637 | Error *errp = NULL; |
| 3638 | int ret = qemu_start_incoming_migration(incoming, &errp); |
Juan Quintela | 8ca5e80 | 2010-06-09 14:10:54 +0200 | [diff] [blame] | 3639 | if (ret < 0) { |
Amos Kong | d5c5dac | 2012-05-11 00:28:35 +0800 | [diff] [blame] | 3640 | if (error_is_set(&errp)) { |
| 3641 | fprintf(stderr, "Migrate: %s\n", error_get_pretty(errp)); |
| 3642 | error_free(errp); |
| 3643 | } |
Juan Quintela | 8ca5e80 | 2010-06-09 14:10:54 +0200 | [diff] [blame] | 3644 | fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n", |
| 3645 | incoming, ret); |
| 3646 | exit(ret); |
| 3647 | } |
Avi Kivity | 6b99dad | 2009-08-09 14:39:20 +0300 | [diff] [blame] | 3648 | } else if (autostart) { |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 3649 | vm_start(); |
Avi Kivity | 6b99dad | 2009-08-09 14:39:20 +0300 | [diff] [blame] | 3650 | } |
ths | ffd843b | 2006-12-21 19:46:43 +0000 | [diff] [blame] | 3651 | |
Jes Sorensen | eb505be | 2010-06-10 11:42:28 +0200 | [diff] [blame] | 3652 | os_setup_post(); |
ths | 71e3ceb | 2006-12-22 02:11:31 +0000 | [diff] [blame] | 3653 | |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 3654 | resume_all_vcpus(); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 3655 | main_loop(); |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 3656 | bdrv_close_all(); |
| 3657 | pause_all_vcpus(); |
aliguori | 63a01ef | 2008-10-31 19:10:00 +0000 | [diff] [blame] | 3658 | net_cleanup(); |
wayne | 3d3b830 | 2011-07-27 18:04:55 +0800 | [diff] [blame] | 3659 | res_free(); |
ths | b46a890 | 2007-10-21 23:20:45 +0000 | [diff] [blame] | 3660 | |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 3661 | return 0; |
| 3662 | } |